factoring square roots

109 views
Skip to first unread message

Atharv Sampath

unread,
Feb 24, 2023, 4:58:37 AM2/24/23
to sympy
Lack of ability to factor out square roots seems to be a particular cause for simplification issues like #23641. For example, one might expect factor(sqrt(x)+x) to return sqrt(x)*(1+sqrt(x)), but it does not do anything. In this specific case, we may be able to avoid simplification issues by using radsimp. However, in the more general scenario, it would be very beneficial to be able to factor out radicals "naturally".

One potential issue I see with this is that there are many expressions that would factor 'indefinitely' if we were able to factor using radicals. For instance, factor_rad(x+1) might return (sqrt(x)+I)*(sqrt(x)-I). However, there are many other factorizations of this expression into different radicals.
 
The simplest fix for this would be to implement a way to specify a "irreducible degree" with default setting 1. For instance, in the above examples, we would choose 1/2.

I would attempt to implement this right away, but I am new to both open-source and SymPy, so I need some guidance. In particular, I don't quite understand how _symbolic_factor works, and how exactly formal mode is implemented for factor.

Chris Smith

unread,
Feb 24, 2023, 9:53:13 PM2/24/23
to sympy
This sort of problem can be solved by identifying the generator with the smallest power. In this case `g = x**1/2` so `sqrt(x) + x -> y + y**2` which factors as `y*(1 + y) -> sqrt(x)*(1 + sqrt(x))`.

/c

Chris Smith

unread,
Feb 24, 2023, 9:54:55 PM2/24/23
to sympy
cf https://github.com/sympy/sympy/pull/23936

On Friday, February 24, 2023 at 3:58:37 AM UTC-6 atharv....@gmail.com wrote:

Atharv Sampath

unread,
Feb 25, 2023, 2:43:57 AM2/25/23
to sympy
I did notice another bug, which is that factor doesn't recognize float exponents (or rather, there are generally several issues with float exponents). For example, factor(x**3.0 + x) doesn't get factored. Am I correct in assuming that this will not get fixed by switching generators? If it is alright, I think I would be able to work on this.

Is there a way to test the code from the pull request using my own tests? I am new to open source and I am unsure about how to do this. I am able to checkout the PR locally, but unsure of how to conduct my own tests using it.

Thanks.

emanuel.c...@gmail.com

unread,
Feb 26, 2023, 5:01:21 AM2/26/23
to sympy
Dear list

Le samedi 25 février 2023 à 08:43:57 UTC+1, atharv....@gmail.com a écrit :
I did notice another bug, which is that factor doesn't recognize float exponents (or rather, there are generally several issues with float exponents).

(Python) floats are numerical approximations. Float exponents in ana expression make said expression an exponential, mathematically different from a power. You are leaving the algebra realm for analysis marshes...

Therefore, this should be considered a feature, not a bug.
Reply all
Reply to author
Forward
0 new messages