[HP Prime CAS] Request: TRUE & FALSE



#10

Sorry google translator

The HP-Prime have 2 new constants, true and false =)

you can try

EVAL(true) => 1

EVAL(false) => 0

Request 0: Evaluate first to TRUE or FALSE all CAS commands than return 1/0, including comparisons ==, >, < etc, Return TRUE or FALSE is more didactic

Example1:

type(3+4*i) == DOM_COMPLEX [Enter] 1 // Current

type(3+4*i) == DOM_COMPLEX [Enter] TRUE // best

eval(ans) => 1

Example2:

x+4=6 | x=2 [Enter] return 6=6

EVAL(x+4=6 | x=2) [Enter] 1 // Current

EVAL(x+4=6 | x=2) [Enter] TRUE // best

Example3:

x+4=6 | x=2.0001 [Enter] return 6.0001=6

EVAL(x+4=6 | x=2.0001) [Enter] FALSE

...

5 > 4 => true

The following program evaluates the accuracy of the answer given by the SOLVE command

errors, why?

prg version 0.2

Quote:
Export Prg1

Begin

Local eq, eq1, eq2, eq3, var, var1, var2 sol, sol1, sol2, test1, test2;

eq1 := x+4=6; // x = 2

eq2 := 2^(2*x+1) = -1+ 32*2^x; // x = -4.99... OR x = 3.99...

eq3 := x^4=4; // x = v¬2 or x -v¬2

eq4 := { 4*x+3*y=10, 5*x-2*y=1 } // x = 1 AND x = 2

eq : eq1

var1 := x;

var2 : y;

var : var1

//purge( rcl(var1), rcl(var2) ); => purge ( x, y ) ?

sol := solve( eq, var ); // for eq1/2/3

//sol := solve( eq, {var1, var2} ); // for eq4

sol1:= ( var = sol(1) ) // for eq1...4

//sol2:= ( var = sol(2) ) // only for eq2, eq3, eq4

// sol12:= ( { var1, var2 } = sol ); // for eq2/3/4: [ sol ] => [ vars = sol ]

test1 := ( eq | sol1 );

//test2 := ( eq | sol2 );

If ( EVAL(test1) == true ) // Accuracy Solve Command

Then

msgBox( "case true => " + sol1 + " " + test1 );

Else

msgBox( "case false => " + sol1 + " " + test1 );

EndIf;

If ( EVAL(test1) == true ) // Accuracy Solve Command

Then

msgBox( "case true => " + sol2 + " " + test2 );

Else

msgBox( "case false => " + sol2 + " " + test2 );

EndIf;

End;


Edited: 4 Aug 2013, 11:02 a.m. after one or more responses were posted


#11

Quiz: What should '6=6' ->NUM yield?

RPL and Prime (in its CAS) use == for comparisons, not =. The = sign is used only for EQUATIONS, not COMPARISONS. x+4=6|x=2 means "Substitute 2 into x in the equation x+4=6" which yields the equation 6=6, as instructed. 6=6 is different from 6==6. 6=6 evaluates to 0 (because = is handled as subtraction) whereas 6==6 evaluates to 1 (because it's true).

If 6=6 evaluating to 0 seems like a bug, try it on the HP 50g: '6=6' ->NUM --> 0. That doesn't mean 6=6 is false; it means 6-6=0. Similarly, '6=5' ->NUM --> 1 does not mean 6=5 is true; it means 6-5=1. That's why '6=4' ->NUM --> 2. This behavior is required by the solvers; it allows every input (equation or not) to be solved by setting it equal to zero. Thus X^2=4 is internally considered to be X^2-4=0.

If you want a comparison to yield true or false, use ==, not =.

Therefore, what I think you intended to do is x+4==6|x=2 --> 1, which means "Is x+4 equal to 6 when x=2? Yes, it is."

If I missed your point, please clarify it. If there are other points being made here (I can't tell), please clarify them too. Thanks in advance.

-Joe-

Edited: 3 Aug 2013, 1:02 p.m.


#12

Thanks Joe, my problem is that I was writing lowercase EVAL and the computer software "Emulator" not interpreted, I used to write mostly in lowercase

The EVAL command works fine. But why not return TRUE or FALSE? is more didactic or not, then a second [EVAL] return 1/0, for those who want to see 1/0 as output


Edited: 3 Aug 2013, 8:22 p.m. after one or more responses were posted


#13

I don't understand your point here.
See Advanced User Reference (I think it's on HP site)

->NUM : Evaluate to Number Command. Evaluates a symbolic argument object (other than a list) and returns the numerical result.

On the 50G, I use NUM-> like APPROX

As say Joe, for boolean results use ==, = is for equations

6 6 == -> 1

'a' 'a' == -> 1

'6==6' EVAL -> 1

'2x3==6' EVAL -> 1

EDIT : OUps...you change your message when i was responding.
My answer was about your 50G remarks
You edited and changed totally your 2 posts ... It would be fine to create a new posts in this case :(

Edited: 3 Aug 2013, 5:31 p.m.

#14

Quote:
x+4=6 | x=2 [Enter] return 6=6, [EVAL] 1

I don't understand. It's an equation not a test.


#15

Quote:
x+4=6 | x=2 [Enter] return 6=6, [EVAL] 1

I don't understand. It's an equation not a test.


yes, but EVAL allows an correct interpretation of #=# as test, while the ->NUM HP50 command other

if EVAL(x+4=6 | x=2.0001) == true then ... else ...


[HP-PRIME CAS] x+4=6 | x=2 [Enter] return 6=6

[HP-PRIME CAS] EVAL(6=6) [Enter] return 1 (TRUE), perfect =)

[HP-PRIME CAS] EVAL(6=6.01) [Enter] return 0 (FALSE), perfect =)

but, would be much better that returns a word

[HP-PRIME CAS] EVAL(6=6) [Enter] return TRUE

[HP-PRIME CAS] EVAL(6=6.01) [Enter] return FALSE

Edited: 3 Aug 2013, 8:31 p.m.

#16

Do you simply want EVAL to return symbolic True or False rather than 1 or 0? Then an EVAL of True or False would return the numeric equivalents?

If so, then you have given us way too much information. :)


#17

>> Do you simply want EVAL to return symbolic True or False rather than 1 or 0?

Not only EVAL, all commands that return a value of 1/0

Examples

ABC == ABC [Enter] TRUE

6 == 6 [Enter] TRUE

type(3+4*i) == DOM_COMPLEX [Enter] TRUE

type(3*x+2*y+4=0) == DOM_SYMBOLIC [Enter] TRUE

x:=5; type(x) == DOM_IDENTIFIER [Enter] FALSE

purge(x); type(x) == DOM_IDENTIFIER [Enter] TRUE

EVAL(x+4=6 | x=2.0001) [Enter] FALSE

if EVAL(x+4=6 | x=2.0001) == true then ...


Edited: 3 Aug 2013, 7:57 p.m.


#18

Would it be possible not to alter the posts after replies were made?
Editing posts after answers can often invalidate the whole thread.


Possibly Related Threads...
Thread Author Replies Views Last Post
  HP Prime: CAS taylor Alberto Candel 5 367 12-13-2013, 09:45 PM
Last Post: Alberto Candel
  HP Prime CAS curiosity bluesun08 11 564 12-10-2013, 01:03 PM
Last Post: Han
  [HP-Prime CAS] "Warning, ^ (Command) Is ambiguous on non square matrices"?? CompSystems 1 225 12-07-2013, 07:15 PM
Last Post: CompSystems
  HP Prime: complex numbers in CAS. Alberto Candel 1 185 12-06-2013, 02:36 PM
Last Post: parisse
  HP Prime: Proper Use of Home View and CAS View James Williams 9 500 12-05-2013, 02:44 PM
Last Post: James Williams
  [HP Prime] plotfunc() bug in CAS Chris Pem10 2 222 12-04-2013, 02:46 PM
Last Post: Chris Pem10
  HP Prime: Home/CAS? Alasdair McAndrew 11 558 11-26-2013, 02:48 PM
Last Post: Alberto Candel
  HP Prime numerical precision in CAS and HOME Javier Goizueta 5 335 11-16-2013, 03:51 AM
Last Post: Paul Dale
  Need CAS help Michael de Estrada 6 349 11-13-2013, 01:29 AM
Last Post: cyrille de Brébisson
  HP Prime - CAS functions in Spreadsheet App CR Haeger 6 368 11-11-2013, 12:37 AM
Last Post: Michael de Estrada

Forum Jump: