Skip to content

Commit

Permalink
Create mask_inverse_subs.py
Browse files Browse the repository at this point in the history
  • Loading branch information
diya5722 committed Apr 2, 2024
1 parent d91b8ad commit 46ee69e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sympy/core/mask_inverse_subs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from sympy import symbols, Function

x, y = symbols('x y')

def mask_inverse_subs(expr, old, new):
if isinstance(old, Function): # Check if old is a function
inverse_old = 1 / old(x) # Compute the functional inverse
return expr.subs(inverse_old, new)
else:
return expr.subs(1/old, new)

# Test the function
expr1 = 2*x + 1/x
result1 = mask_inverse_subs(expr1, x, y)
print(result1) # Output: 2*y + 1/x

def f(x):
return x**2

expr2 = 2*f(x) + 1/f(x)
result2 = mask_inverse_subs(expr2, f, y)
print(result2) # Output: 2*y + 1/f(x)

0 comments on commit 46ee69e

Please sign in to comment.