-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
polynom division with refine #17634
Comments
You can do this if x is positive using factor: In [21]: x = Symbol('x', positive=True)
In [22]: sqrt(1-x**2)/sqrt(1-x)
Out[22]:
________
╱ 2
╲╱ 1 - x
───────────
_______
╲╱ 1 - x
In [23]: factor(_)
Out[23]:
_______
╲╱ x + 1 I'm not sure why x being positive makes this work. In general I think there should be a function for doing In [38]: e = x**y/z**y
In [39]: e
Out[39]:
y -y
x ⋅z
In [40]: powsimp(e)
Out[40]:
y -y
x ⋅z
In [41]: powsimp(e, force=True)
Out[41]:
y
⎛x⎞
⎜─⎟
⎝z⎠ However if In [42]: e2 = e.subs(y, S(1)/2)
In [43]: e2
Out[43]:
√x
──
√z
In [45]: powsimp(e2)
Out[45]:
√x
──
√z
In [46]: powsimp(e2, force=True)
Out[46]:
√x
──
√z |
It seems that In [8]: powsimp(z**-S.Half, force=True)
Out[8]:
1
──
√z
In [9]: powsimp(z**-y, force=True)
Out[9]:
y
⎛1⎞
⎜─⎟
⎝z⎠ Maybe it should be changed so that we have: In [8]: powsimp(z**-S.Half, force=True)
Out[8]:
___
╱ 1
╱ ─
╲╱ z I.e. |
Looks like the difference is here: sympy/sympy/simplify/powsimp.py Lines 395 to 397 in 58e7820
since we have: In [1]: (-y).as_coeff_Mul()
Out[1]: (-1, y)
In [2]: (-S.Half).as_coeff_Mul()
Out[2]: (-1/2, 1) |
This makes it possible to use powsimp: diff --git a/sympy/simplify/powsimp.py b/sympy/simplify/powsimp.py
index baed0aac83..e0208e17a5 100644
--- a/sympy/simplify/powsimp.py
+++ b/sympy/simplify/powsimp.py
@@ -393,6 +393,8 @@ def update(b):
if not (all(x.is_nonnegative for x in b.as_numer_denom()) or e.is_integer or force or b.is_polar):
continue
exp_c, exp_t = e.as_coeff_Mul(rational=True)
+ if exp_t is S.One and exp_c.is_negative:
+ exp_c, exp_t = -exp_t, -exp_c
if exp_c is not S.One and exp_t is not S.One:
c_powers[i] = [Pow(b, exp_c), exp_t] Then we have: In [2]: powsimp(sqrt(1-x**2)/sqrt(1-x), force=True)
Out[2]:
________
╱ 2
╱ 1 - x
╱ ──────
╲╱ 1 - x However I don't see how to simplify it from there... In [3]: factor(_)
Out[3]:
___________________
╱ -(x - 1)⋅(x + 1)
╱ ─────────────────
╲╱ 1 - x
In [4]: cancel(_)
Out[4]:
_________________
╱ 2
╱ x 1
╱ - ───── + ─────
╲╱ 1 - x 1 - x
In [6]: simplify(_)
Out[6]:
________
╱ 2
╱ x - 1
╱ ──────
╲╱ x - 1 |
Okay here it is (using the diff above): In [1]: powsimp(sqrt(1-x**2)/sqrt(1-x), force=True)
Out[1]:
________
╱ 2
╱ 1 - x
╱ ──────
╲╱ 1 - x
In [2]: factor(_, deep=True)
Out[2]:
_______
╲╱ x + 1 If anyone wants to add that diff (plus tests) as a PR then go ahead. |
I'll add the diff and tests |
Can I get this issue assigned ? |
We don't assign issues but you can work on this if you want to. There already is a PR #17666 which you could use as a starting point. |
If no one is working on this issue and the issue is still open. Can I start working on it? |
The issue still persists on |
I tried to do some simplification (on live.sympy.org) with
refine
, but couldn't get it to work. It seems to boil down to this:gives back
(1-x**2)/(1-x)
,while
correctly simplifies it to
x+1
.Maybe I'm just not understanding this correctly, as I'm relatively new to sympy - but shouldn't refine also simplify that expression?
I want to use
refine
because I actually have expressions of the formwhere I don't think I can use
simplify
, because I can't tell sympy, that the root is positive.The text was updated successfully, but these errors were encountered: