rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

factor does not work on radical expression #1356

Open rtoy opened 3 weeks ago

rtoy commented 3 weeks ago

Imported from SourceForge on 2024-07-04 09:56:38 Created by zmth on 2021-08-30 19:29:54 Original: https://sourceforge.net/p/maxima/bugs/3843


(algebraic:true,t:((a^2-b^2)x+2absqrt(x(1-x))+b^2)((b^2-a^2)x+2absqrt(x*(1-x))+a^2),disp(["t",t]),t:expand(t) ,disp(["expanded t",t,"and next see it doesn't factor(t)",factor(t)]))

same thing with algebraic:false.Or what do i need do to make it factor it?

rtoy commented 3 weeks ago

Imported from SourceForge on 2024-07-04 09:56:39 Created by macrakis on 2021-08-30 19:54:55 Original: https://sourceforge.net/p/maxima/bugs/3843/#9760


Please use code entry mode (inline: backquote EXPRESSION backquote; block mode: three tildes CODE three tildes) to enter Maxima expressions -- otherwise the multiplication signs (*) get interpreted as italics, so we can't cut and paste your code into Maxima for testing.

Here is a times b times c without backquotes: abc and with backquotes: a*b*c. Here it is on a line by itself abc and with code markup:

a*b*c
rtoy commented 3 weeks ago

Imported from SourceForge on 2024-07-04 09:56:43 Created by macrakis on 2021-08-30 20:07:16 Original: https://sourceforge.net/p/maxima/bugs/3843/#25c3


It would be useful, too, if you'd let us know what you expect that expression to factor into.

rtoy commented 3 weeks ago

Imported from SourceForge on 2024-07-04 09:56:46 Created by macrakis on 2021-09-08 15:28:14 Original: https://sourceforge.net/p/maxima/bugs/3843/#0ed0


Looking at the source of your message, I see that you are talking about this expression:

t:((a^2-b^2)*x+2*a*b*sqrt(x*(1-x))+b^2)*((b^2-a^2)*x+2*a*b*sqrt(x*(1-x))+a^2));

You seem to expect factor(expand(t)) to return t. But factor only works on polynomials, so much simpler cases like factor(expand((1+sqrt(x))^2)) also do not factor.

Do you also expect factor(expand((1-sqrt(x))*(1+sqrt(x)))) to "recover" the factors?

One technique which may be useful if you expect x^(1/n) in the result is something like this:

t:expand((1+sqrt(x))^2) => x+2*sqrt(x)+1
assume(x2>=0)$ subst(x2^2,x,t)$ => x2^2+2*x2+1
factor(%);
subst(x^(1/2),x2,%) => (sqrt(x)+1)^2

For your original example, you could do this:

t:((a^2-b^2)*x+2*a*b*sqrt(x*(1-x))+b^2)*((b^2-a^2)*x+2*a*b*sqrt(x*(1-x))+a^2);
assume(xx22>=0)$
ratsubst(xx22^2,x*(1-x),expand(t));
factor(%);
subst((x*(1-x))^(1/2),xx22,%);

which gives the rather nice result:

(b^2*sqrt((1-x)*x)+a^2*sqrt((1-x)*x)+a*b)^2

...which shows that t is a square and thus always positive when the sqrt is real (== 0<x<1). Also showing, by the way, that factorization is not unique in cases like this, so it shouldn't be a surprise that factor doesn't do what you expected.

rtoy commented 3 weeks ago

Imported from SourceForge on 2024-07-04 09:56:49 Created by macrakis on 2021-09-08 15:30:02 Original: https://sourceforge.net/p/maxima/bugs/3843/#6bf0