Hi everyone,
I'm Pushkar, and this is my first time contributing to SymPy. I'm still learning my way around the codebase and contribution process, so please let me know if anything I’m doing is not quite right.
I came across SymPy issue #28213, where calling solveset_real on an expression involving Abs and trigonometric functions raises a ValueError, even though all variables are declared real.
Here’s a minimal reproducible example that fails:
```
from sympy import Abs, sin, cos, symbols
from sympy.solvers.solveset import solveset_real
t1, t2, t3, u1, u2, u3 = symbols('t1 t2 t3 u1 u2 u3', real=True)
expr = sin(t1)*cos(t3) + sin(t2)*sin(t3)*cos(t1) - (
sin(t2)*sin(u3)*cos(t1)*cos(t2)/Abs(cos(t2)) + cos(u3)*Abs(sin(t1))
)
solveset_real(expr, u3)
```
This raises:
```
ValueError: Absolute values cannot be inverted in the complex domain.
```
I looked into it and noticed that _solve_trig1 in solveset_real is falling back to solveset_complex in cases involving Abs, even though the domain is real. To fix this, I modified _solve_abs so that instead of raising a ValueError when inequalities fail, it now returns a ConditionSet fallback.
My Fix:
I modified _solve_abs to handle NotImplementedError during inequality solving by wrapping the fallback in a ConditionSet, like this:
```
def _solve_abs(f, symbol, domain):
...
if not (f_p.is_zero or f_q.is_zero):
...
try:
q_pos_cond = solve_univariate_inequality(...)
...
return Union(sols_q_pos, sols_q_neg)
except NotImplementedError:
return ConditionSet(symbol, Eq(f, 0), domain)
else:
return ConditionSet(symbol, Eq(f, 0), domain)
```
Test Results:
After applying the patch, I ran:
and got the following:
180 tests passed
2 failed (but they are unrelated to this patch — test_solve_trig and test_issue_19050)
2 skipped, 1 deselected, 13 xfailed (as expected)
I'm happy to open a PR if this approach seems reasonable. But since I’m new, I wanted to get feedback here first. Would love any suggestions or corrections.
Thanks,
Pushkar