Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x.subs(1/x,y) behavior differs when x is symbol and when x is a function solution by creating test_symbol_inverse.py #26446 #26475

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions sympy/core/tests/test_symbol_inverse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from sympy import symbols, Function

def mask_inverse_subs(expr, old, new):
"""
Substitutes the inverse of `old` with `new` in `expr`.

Args:
expr: The expression to modify.
old: The symbol or function to replace.
new: The new symbol or function.

Returns:
The modified expression.
"""
if isinstance(old, Function):
# For functions, apply the inverse to the argument
inverse_old = old.inv()
return expr.subs(old(x), inverse_old(new))
else:
return expr.subs(1 / old, new)

def slotscheck():
"""
Function to check if slots are available.
"""
print("Checking available slots...")
# Your code for checking available slots goes here
print("Slots checked.")

# Test the module and function
if __name__ == "__main__":
x, y = symbols('x y')
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)

# Test slotscheck function
slotscheck()