HP Forums
About HP Prime factorization - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: About HP Prime factorization (/thread-15825.html)



About HP Prime factorization - dah145 - 11-02-2020 06:28 AM

Sorry if this had been specifically asked before, I searched but couldn't find anything.
Suppose I want to factorize the expression: a*s^(2) + b*s + c for the variable s. In other CAS systems this could be done simply by specifying it inside the factor(expression,var) function, in calculators such as the TI 89, see image attached. I haven't found a way to achieve this on the HP Prime as its factor function doesn't work the same way.


RE: About HP Prime factorization - parisse - 11-02-2020 07:58 AM

factor factors over the field of coefficients of the arguments. If you want to extend this field, you must give a 2nd argument specifying the extension.
For example
Code:
P:=a*s^2+b*s+c;
l:=solve(P=0,s);
factor(P,l[0])



RE: About HP Prime factorization - dah145 - 11-02-2020 05:40 PM

[quote='parisse' pid='138432' dateline='1604303926']
factor factors over the field of coefficients of the arguments. If you want to extend this field, you must give a 2nd argument specifying the extension.
For example
Code:
P:=a*s^2+b*s+c;
l:=solve(P=0,s);
factor(P,l[0])

Thank you very much, never would have guessed that, but it makes sense.

Now, just another question, let's say I want to factor the expression: a^2 -2*a*b+b^2+s^2, it's easy to see that it is equivalent to: s^2 + (a-b)^2. I know I can get to the second expression in the HP Prime by applying the factor function like this: factor(a^2 -2*a*b+b^2)+s^2, but the point if it is possible for it to be done automatically with a function. This is particularly useful, for example, to getting the simplified expressions of typical laplace transforms with symbolic coefficients, such as the ones attached.


RE: About HP Prime factorization - Albert Chan - 11-02-2020 07:32 PM

Hi, dah145

You can isolate the terms to be factorize, like this.

XCas> factor2(mess,s) := poly2symb(factor(symb2poly(mess,s)),s)

XCas> factor2(a^2 - 2*a*b + b^2 + s^2, a)       → b^2+s^2+a*(a-2*b)
XCas> factor2(a^2 - 2*a*b + b^2 + s^2, s)       → s^2+(a-b)^2


RE: About HP Prime factorization - dah145 - 11-03-2020 03:46 AM

(11-02-2020 07:32 PM)Albert Chan Wrote:  Hi, dah145

You can isolate the terms to be factorize, like this.

XCas> factor2(mess,s) := poly2symb(factor(symb2poly(mess,s)),s)

XCas> factor2(a^2 - 2*a*b + b^2 + s^2, a)       → b^2+s^2+a*(a-2*b)
XCas> factor2(a^2 - 2*a*b + b^2 + s^2, s)       → s^2+(a-b)^2

Yes thanks, this definitely is what I was looking for. Now I wonder if it is possible to obtain the expressions in form of a product, say: (a^2 - 2*a*b + b^2 + s^2)*(a^2 - 2*a*b + b^2 + s^2) = (s^2+(a-b)^2)*(s^2+(a-b)^2), as using your custom function outputs a not so friendly expression: s^2*(2*(a^2 + b^2) + s^2)+(a+b)^2*(a-b)^2.


RE: About HP Prime factorization - dah145 - 11-19-2020 04:12 PM

(11-03-2020 03:46 AM)dah145 Wrote:  
(11-02-2020 07:32 PM)Albert Chan Wrote:  Hi, dah145

You can isolate the terms to be factorize, like this.

XCas> factor2(mess,s) := poly2symb(factor(symb2poly(mess,s)),s)

XCas> factor2(a^2 - 2*a*b + b^2 + s^2, a)       → b^2+s^2+a*(a-2*b)
XCas> factor2(a^2 - 2*a*b + b^2 + s^2, s)       → s^2+(a-b)^2

Yes thanks, this definitely is what I was looking for. Now I wonder if it is possible to obtain the expressions in form of a product, say: (a^2 - 2*a*b + b^2 + s^2)*(a^2 - 2*a*b + b^2 + s^2) = (s^2+(a-b)^2)*(s^2+(a-b)^2), as using your custom function outputs a not so friendly expression: s^2*(2*(a^2 + b^2) + s^2)+(a+b)^2*(a-b)^2.

Just wanted to update, I wrote a little program that factorizes polynomials to a more friendly expression than the built in factor function, I attached an example. A is the expression and B is the variable to factorize.

PHP Code:
#cas
facto(A,B):=

BEGIN
LOCAL fac
coepolapolb;
fac:=factors(A);
coe:={0};
polb:=[0];

FOR 
N FROM 1 TO SIZE(fac)/DO
coe[N]:=coeff(fac[2*N-1],B);
END;

pola:=factor(coe);

FOR 
N FROM 1 TO SIZE(fac)/DO
polb[N]:=poly2symb(pola[N],B);
END;

RETURN 
regroup(product(polb[n]^(fac[2*n]),n,1,SIZE(polb)));

END;
#end