The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

HP Prime vs TI : Factoring ?
Message #1 Posted by HP Pioneer on 29 Oct 2013, 11:59 a.m.

factor(5x^4 + 20x^3 - 62x^2 - 8x +24)

TI 200 returns (x-2)(x+6)(5x^2-2)

HP Prime returns (x-2)(x+sqroot(10)/5)(x+6)(5x-sqroot(10))

Anyway to have the Prime avoid the sqroots?

      
Re: HP Prime vs TI : Factoring ?
Message #2 Posted by From Hong Kong on 29 Oct 2013, 12:10 p.m.,
in response to message #1 by HP Pioneer

Uncheck 'Use ¡Ô ' in the CAS settings before doing the above factorisation.

Edited: 29 Oct 2013, 12:11 p.m.

      
Re: HP Prime vs TI : Factoring ?
Message #3 Posted by CR Haeger on 29 Oct 2013, 12:14 p.m.,
in response to message #1 by HP Pioneer

Worked okay for me if CAS Settings set to:

"Use sqrt to factor polynomials" set to UNCHECKED and "Simplify" set to NONE or MINIMUM.

Best, Carl

      
Re: HP Prime vs TI : Factoring ? [Collect vs factor! :-) ]
Message #4 Posted by Tim Wessman on 29 Oct 2013, 12:16 p.m.,
in response to message #1 by HP Pioneer

Here is a perfect example for the recent "collect vs factor" discussion! :-)

Collect will return the same result as the TI, while factor will completely factor it as far as possible due to having more capable factoring capabilities.

TW

Edited: 29 Oct 2013, 12:19 p.m.

            
Re: HP Prime vs TI : Factoring ? [Collect vs factor! :-) ]
Message #5 Posted by CR Haeger on 29 Oct 2013, 12:49 p.m.,
in response to message #4 by Tim Wessman

Thanks Tim! It looks like you can also control the "extent" of terms COLLECTION by adjusting the CAS Simplify settings? Cool.

            
Re: HP Prime vs TI : Factoring ? [Collect vs factor! :-) ]
Message #6 Posted by CompSystems on 29 Oct 2013, 12:54 p.m.,
in response to message #4 by Tim Wessman

Quote:
Here is a perfect example for the recent "collect vs factor" discussion! :-)

Collect will return the same result as the TI, while factor will completely factor it as far as possible due to having more capable factoring capabilities.

TW


collect == factor =( Collect (HP-Prime) this factoring in most cases and is not doing what it says catalog help.

[ HP-PRIME CAS MODE & APPROX MODE ]

collect( (-3*a*x^2 +7*a*x^1 -2*a-3*b*x^2 + 7*b*x^1 -2*b+3*x^3 -7*x^2 + 2*x^1)/3 ) ; [ENTER] => -1.*(x-2.)*(x-0.333333333333)*(a-x+b)

factor( (-3*a*x^2 +7*a*x^1 -2*a-3*b*x^2 + 7*b*x^1 -2*b+3*x^3 -7*x^2 + 2*x^1)/3 ) ; [ENTER] => -1.*(x-2.)*(x-0.333333333333)*(a-x+b)

[ HP-PRIME CAS MODE & EXACT MODE ]

collect( (-3*a*x^2 +7*a*x^1 -2*a-3*b*x^2 + 7*b*x^1 -2*b+3*x^3 -7*x^2 + 2*x^1)/3 ) ; [ENTER] => (x-2)*(3*x-1)*(x-a-b)/3

factor( (-3*a*x^2 +7*a*x^1 -2*a-3*b*x^2 + 7*b*x^1 -2*b+3*x^3 -7*x^2 + 2*x^1)/3 ) ; [ENTER] => (x-2)*(3*x-1)*(x-a-b)/3

My collect

collectPolTerms( (-3*a*x^2 +7*a*x^1 -2*a-3*b*x^2 + 7*b*x^1 -2*b+3*x^3 -7*x^2 + 2*x^1)/3, x ) ; =>

x^3 + ((-3*a-3*b-7)/3)*x² +((7*a+7*b+2)/3)*x + (-2*a-2*b)/3*x^0 // :) OK

more info

http://www.adictoshp.org/topic/473-casplus-library-for-hp-prime

source code cas+ with real collect poly

main( ):=
BEGIN
	CONJUGATE() := BEGIN true; END;
	SYMBOLIC() := BEGIN true; END;
	RETURN( OK );
END;

collectPolTerms( Poly, Var ):= BEGIN LOCAL FlagBadArg; FlagBadArg:= "false";

IF NOT( POS( { "AlgExpression", "Equation", "Identifier", "RealNumber", "IntegerNumber", "AlgComplexNumber", "RationalNumber", "RatComplexNumber" }, getType( Poly ) ) ) THEN FlagBadArg := "true"; IF NOT( MSGBOX( "collectPolTerms:Invalid Data Type for 1 arg", true ) ) THEN kill; END; END;

IF NOT( getType( Var ) == "Identifier" ) THEN FlagBadArg := "true"; IF NOT( MSGBOX( "collectPolTerms:Invalid Data Type for 2 arg", true ) ) THEN kill; ELSE kill; END; END;

IF FlagBadArg == "false" THEN IF isEquation( Poly ) == "true" THEN Poly := toEq( eqToExpr ); END; RETURN( sum( coeff( Poly, Var ) .* seq( Var^k, k, degree( Poly, Var ), 0, 1 ) )); ELSE RETURN( "Invalid Data Type" ); END; END;

getType( Data0 ):= BEGIN LOCAL TypeN, TypeID, RealType, ObjStr;

TypeID := type( Data0 );

IFERR TYPE( Data0 ) THEN RealType := "ERROR"; ObjStr := "ERROR"; ELSE TypeN := TYPE( Data0 ); ObjStr := STRING( Data0 ); END;

CASE IF TypeID == DOM_FLOAT THEN RealType := "RealNumber"; END;

IF TypeID == DOM_INT THEN RealType := "IntegerNumber"; END;

IF TypeID == DOM_COMPLEX THEN IF inString( ObjStr,"(" ) >= 1 THEN RealType := "CooComplexNumber"; ELSE RealType := "AlgComplexNumber"; END; END;

IF TypeID == DOM_RAT THEN IF inString( ObjStr, string( i ) ) >= 1 THEN RealType := "RatComplexNumber"; ELSE RealType := "RationalNumber"; END; END;

IF TypeID == DOM_SYMBOLIC THEN IF inString( string( Data0 ), "=" ) >= 1 THEN RealType := "Equation"; ELSE RealType := "AlgExpression"; END; END;

IF TypeID == DOM_IDENT THEN RealType := "Identifier"; END;

IF TypeID == DOM_STRING THEN RealType := "String"; END;

IF TypeID == DOM_FUNC THEN RealType := "Function"; END;

IF TypeID == DOM_LIST THEN CASE IF inString( ObjStr, "poly1[" ) >= 1 THEN RealType := "PolynomialCoeff"; END;

IF inString( ObjStr, "set[" )>= 1 THEN RealType := "Set"; END;

IF inString( ObjStr, "[[" ) >= 1 THEN RealType := "Matrix"; END;

IF inString( ObjStr, "[" ) >= 1 THEN RealType := "Vector"; END;

IF inString( ObjStr, "{" ) >= 1 OR inString( ObjStr, "{[" ) >= 1 THEN RealType := "List"; END;

DEFAULT RealType := "Other Type LIST";

END; END;

IF TypeN == 8 THEN RealType := "Unit"; END;

IF TypeID == 21 THEN RealType := "HMS"; END;

IF TypeN == 1 THEN

CASE IF inString( ObjStr, "d" ) >= 1 THEN RealType := "DecNumber"; END;

IF inString( ObjStr, "b" ) >= 1 THEN RealType := "BinNumber"; END;

IF inString( ObjStr, "h" ) >= 1 THEN RealType := "HexNumber"; END;

IF inString( ObjStr, "o" ) >= 1 THEN RealType := "OctNumber"; END;

DEFAULT RealType := "Other Base";

END;

END;

DEFAULT RealType := "Other";

END;

RETURN( RealType );

END;

partString( Str0, StrP ):= BEGIN LOCAL FlagBadArg; FlagBadArg:= "false";

IF NOT( ( getType( Str0 ) == "String" ) AND ( NOT( Str0 == "" ) ) ) THEN FlagBadArg := "true"; IF NOT( MSGBOX( "partString: Invalid Data Type for 1 Arg", true ) ) THEN kill; END; END;

IF NOT( ( getType( StrP ) == "String" ) AND ( NOT( StrP == "" ) ) ) THEN FlagBadArg := "true"; IF NOT( MSGBOX( "partString: Invalid Data Type for 2 Arg", true ) ) THEN kill; ELSE kill; END; END;

IF FlagBadArg == "false" THEN RETURN( convertToRealBoolean( inString( Str0, StrP ) ) ); ELSE RETURN( "Invalid Data Type" ); END;

END;

convertToRealBoolean( Object0 ):= BEGIN IF isBooleanDataType( Object0 ) == "true" THEN

IF getType( Object0 ) == "String" THEN Object0 := expr( Object0 ); END; IF Object0 <= 0 THEN RETURN( "false" ); ELSE RETURN( "true" ); END;

ELSE IF NOT( MSGBOX( "convertToRealBoolean: Invalid Data Type", true ) ) THEN kill; ELSE kill; END; END;

END;

isBooleanDataType( Object ):= BEGIN LOCAL FlagBadArg, ObjectType; FlagBadArg:= "false";

ObjectType := getType( Object ); IF NOT( POS( { "RealNumber", "IntegerNumber", "RationalNumber", "String" }, ObjectType ) ) THEN FlagBadArg := "true"; END;

IF FlagBadArg == "true" THEN RETURN( "false" ); ELSE IF ObjectType == "String" THEN ObjectType:= expr( Object ); IF isNumber( ObjectType ) == "true" THEN RETURN( "true" ); ELSE RETURN( "false" ); END; ELSE RETURN( "true" ); END; END; END;

isNumber( Object ):= BEGIN LOCAL ObjectType; ObjectType:= getType( Object );

IF POS( { "RealNumber", "IntegerNumber", "RationalNumber" }, ObjectType ) THEN RETURN( "true" ); ELSE RETURN( "false" ); END; END;

isComplexNumber( Object ):= BEGIN LOCAL ObjectType; ObjectType:= getType( Object );

IF POS( { "CooComplexNumber", "AlgComplexNumber", "RatComplexNumber" }, ObjectType ) THEN RETURN( "true" ); ELSE RETURN( "false" ); END; END;

isEquation( Object ):= BEGIN LOCAL FitObject; IFERR EVAL( Object ); THEN FitObject := Object; ELSE FitObject := EVAL( Object ); END;

IF getType( FitObject ) == "Equation" THEN RETURN( "true" ); ELSE RETURN( "false" ); END; END;

eqToExpr( Eq ):= BEGIN IF isEquation( Eq ) == "true" THEN RETURN( expr( replace( string( Eq ), "=" , "-(" ) + ")" ) ); ELSE RETURN( Eq ); END; END;

transpose2( Array, Test0 ):= BEGIN LOCAL FlagBadArg; FlagBadArg:= "false";

IF NOT( POS( { "Vector", "Matrix" }, getType( Array ) ) ) THEN FlagBadArg := "true"; IF NOT( MSGBOX( "transpose2: Invalid Data Type for 1 arg", true ) ) THEN kill; END; END;

IF NOT( isBooleanDataType( Test0 ) == "true" ) THEN FlagBadArg := "true"; IF NOT( MSGBOX( "transpose2: Invalid Data Type for 2 arg", true ) ) THEN kill; ELSE kill; END; ELSE Test0 := convertToRealBoolean( Test0 ); END;

IF FlagBadArg == "false" THEN IF Test0 == "true" THEN RETURN( TRN( Array ) ); ELSE RETURN( transpose( Array ) ); END; ELSE RETURN( "Invalid Data Type" ); END;

END;

toPoly1var( Object, Var, Test ):= BEGIN LOCAL FlagBadArg, FitPoly, ObjectType; FlagBadArg:= "false";

ObjectType := getType( Object );

IF NOT( POS( { "AlgExpression", "Equation", "Identifier", "RealNumber", "IntegerNumber", "AlgComplexNumber", "RatComplexNumber", "RationalNumber", "PolynomialCoeff", "Vector" }, ObjectType ) ) THEN FlagBadArg := "true"; IF NOT( MSGBOX( "toPoly1var: Invalid Data Type for 1 arg", true ) ) THEN kill; END; END;

IF NOT( getType( Var ) == "Identifier" ) THEN FlagBadArg := "true"; IF NOT( MSGBOX( "toPoly1var: Invalid Data Type for 2 arg", true ) ) THEN kill; END; END;

IF NOT( isBooleanDataType( Test ) == "true" ) THEN FlagBadArg := "true"; IF NOT( MSGBOX( "toPoly1var: Invalid Data Type for 3 arg", true ) ) THEN kill; ELSE kill; END; ELSE Test := convertToRealBoolean( Test ); END;

IF FlagBadArg == "false" THEN CASE

IF ObjectType == "PolynomialCoeff" THEN IF Test == "true" THEN RETURN( poly2symb( ObjectType, Var ) ); ELSE RETURN( ObjectType ); END; END;

IF ObjectType == "Vector" THEN FitPoly := expr( "poly1" + Object ); IF Test == "true" THEN RETURN( poly2symb( FitPoly, Var ) ); ELSE RETURN( FitPoly ); END; END;

IF isEquation( Object ) == "true" THEN FitPoly := eqToExpr( Object ); IF Test == "false" THEN RETURN( symb2poly( FitPoly, Var ) ); ELSE RETURN( FitPoly ); END; END;

DEFAULT IF Test == "false" THEN RETURN( symb2poly( Object, Var ) ); ELSE RETURN( Object ); END; END;

ELSE RETURN( "Invalid Data Type" ); END; END;

polyCoeffToArray( Poly ):= BEGIN LOCAL FlagBadArg; FlagBadArg:= "false";

IF NOT( POS( { PolynomialCoeff }, getType( Poly ) ) ) THEN FlagBadArg := "true"; IF NOT( MSGBOX( "polyCoeffToArray: Invalid Data Type for 1 arg", true ) ) THEN kill; END; END;

IF FlagBadArg == "false" THEN RETURN := expr( replace( string( Poly ), "poly1" , "" ) ); ELSE RETURN( "Invalid Data Type" ); END;

END;

randPoly2( Pdim, Il, Sl, Var, Test ):= BEGIN LOCAL Rp; Rp := randPoly( Pdim, expr( Il + ".." + Sl ) ); RETURN( toPoly1var( Rp, Var, Test )); END;

polyToCoeff( Poly, Var ):= BEGIN LOCAL PolyFnt, Out, Cnt0, Temp0; purge( Pol );

IF isEquation( Poly ) == "true" THEN Poly := eqToExpr( Poly ); END; expr( Pol(Var)+":="+string( Poly ) ); Out := MAKELIST( 0, Cnt1, degree( Poly ), 0, 1 ); Cnt0:=0; WHILE Pol(Var) <> 0 DO Temp0 := Pol(Var) / (Cnt0!) ; Out[ Cnt0 ] := ( Temp0 | Var=0 ); Cnt0 := Cnt0 + 1;

Pol(Var) := diff( Pol(Var), Var);

END; Out := expr( "poly1[" + string( REVERSE(Out) ) + "]"); RETURN( Out ); END;

Edited: 29 Oct 2013, 4:36 p.m. after one or more responses were posted

                  
Re: HP Prime vs TI : Factoring ? [Collect vs factor! :-) ]
Message #7 Posted by CR Haeger on 29 Oct 2013, 1:27 p.m.,
in response to message #6 by CompSystems

Thanks Tim! It looks like you can control the "extent" of terms COLLECTION(or FACTORING) by adjusting the CAS Simplify settings? Again, Cool

      
Re: HP Prime vs TI : Factoring ?
Message #8 Posted by CompSystems on 29 Oct 2013, 2:00 p.m.,
in response to message #1 by HP Pioneer

Re: HP-Prime vs TI-CAS (calculators): Factoring

TI-CAS: TI92(+)/TI89(TITANIUM)/TIvoyage200/TInspire[CX]CAS/...

HP-CAS: HP-Prime/HP50G

[TI-CAS: EXACT MODE]

factor(5*x^4+20*x^3-62*x^2-8*x+24,x) [ENTER] RETURN

(x-2)*(x+6)*(5*x^2-2)

[TI-CAS: APPROXIMATE MODE]

factor(5*x^4+20*x^3-62*x^2-8*x+24,x) [ENTER] RETURN

5.*(x-2.)*(x-0.632455532034)*(x+0.632455532034)*(x+6.)

[TI-CAS: AUTOMATIC MODE]

factor(5*x^4+20*x^3-62*x^2-8*x+24,x) [ENTER] RETURN

(x-2)*(x+6)*(5*x^2-2)

////////////

[HP-CAS: EXACT MODE & NONE SIMPLIFY]

factor(5*x^4+20*x^3-62*x^2-8*x+24,x) [ENTER] RETURN

(x-2)*(x+6)*(5*x^2-2)

[HP-CAS: APPROXIMATE MODE & NONE SIMPLIFY]

factor(5*x^4+20*x^3-62*x^2-8*x+24,x); [ENTER] RETURN

5.*(x-2.)*(x-0.632455532034)*(x+0.632455532034)*(x+6.)

[HP-CAS: EXACT MODE & MAX SIMPLIFY]

factor(5*x^4+20*x^3-62*x^2-8*x+24,x); [ENTER] RETURN

5*x^4+20*x^3-62*x²-8*x+24 BUG

IF MAX_SIMPLIFY == ON THEN SKIP FLAG...

...

factor(y^3+(a+b+c)*y²+(a*b+b*c+c*a)*y+a*b*c,y); => (y+c)*(y+b )*(y+a)

factor(y²+(a+b )*y+a*b,y);(y+b )*(y+a)

cfactor(x^3-y^3,y) ? //

Edited: 29 Oct 2013, 3:47 p.m.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall