[HP Prime CAS] Request: TRUE & FALSE - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: [HP Prime CAS] Request: TRUE & FALSE (/thread-247701.html) |
[HP Prime CAS] Request: TRUE & FALSE - CompSystems - 08-03-2013 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:
Edited: 4 Aug 2013, 11:02 a.m. after one or more responses were posted
Re: [HP Prime CAS] Request: TRUE & FALSE CONSTANTS - Joe Horn - 08-03-2013 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.
Re: [HP Prime CAS] Request: TRUE & FALSE CONSTANTS - CompSystems - 08-03-2013 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
Re: [HP Prime CAS] Request: TRUE & FALSE CONSTANTS - Gilles Carpentier - 08-03-2013 I don't understand your point here. ->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.
Edited: 3 Aug 2013, 5:31 p.m.
Re: [HP Prime CAS] Request: TRUE & FALSE CONSTANTS - Gilles Carpentier - 08-03-2013
Quote:
I don't understand. It's an equation not a test.
Re: [HP Prime CAS] Request: TRUE & FALSE CONSTANTS - CompSystems - 08-03-2013 Quote: 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] 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.
Re: [HP Prime CAS] Request: TRUE & FALSE - Howard Owen - 08-03-2013 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. :)
Re: [HP Prime CAS] Request: TRUE & FALSE - CompSystems - 08-03-2013 >> 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.
Re: [HP Prime CAS] Request: TRUE & FALSE - Raymond Del Tondo - 08-03-2013 Would it be possible not to alter the posts after replies were made? |