Easy question - 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: Easy question (/thread-17416.html) Pages: 1 2 Easy question - boggiano - 09-01-2021 10:10 AM Hello, I am new to my HP Prime and I am just starting to use it. I just bumped into this problem and I don't get it: -1^(-1/3) = -1 but if I use brackets around the -1 I get: Error (-1)^(-1/3) Sorry, for the newbie question but this is my first HP calculator and I'm trying to understand how it works. Thanks! RE: Easy question - roadrunner - 09-01-2021 11:54 AM In home settings make sure the "Allow complex output from real input" box is checked: [attachment=9770] -road RE: Easy question - rawi - 09-01-2021 04:02 PM roadrunner wrote: Quote:In home settings make sure the "Allow complex output from real input" box is checked Yes, this works. But you get a different answer: (-1)^(-1/3) has the result 0.5-0.866025i and -1^(-1/3) has the result -1 as boggiani wrote. It seems that the calculator interpretes -1^(-1/3) as -(1^(-1/3)). If there are no brackets it should work from left to right. RE: Easy question - toml_12953 - 09-01-2021 04:11 PM (09-01-2021 04:02 PM)rawi Wrote:  roadrunner wrote: Quote:In home settings make sure the "Allow complex output from real input" box is checked Yes, this works. But you get a different answer: (-1)^(-1/3) has the result 0.5-0.866025i and -1^(-1/3) has the result -1 as boggiani wrote. It seems that the calculator interpretes -1^(-1/3) as -(1^(-1/3)). If there are no brackets it should work from left to right. Look at your list of priority of operations on page 26 of the User's Guide. ^ comes before unary minus. Only operations that are at the same level are evaluated left to right. Algebraic precedence The HP Prime calculator calculates according to the following order of precedence. Functions at the same level of precedence are evaluated in order from left to right. 1. Expressions within parentheses. Nested parentheses are evaluated from inner to outer. 2. !, √, reciprocal, square 3. nth root 4. Power, 10n 5. Negation, multiplication, division, and modulo 6. Addition and subtraction 7. Relational operators (<, >, ≤, ≥, ==, ≠, =) 8. AND and NOT 9. OR and XOR 10. Left argument of | (where) 11. Assign to variable (:=) RE: Easy question - jte - 09-06-2021 12:36 AM (09-01-2021 04:11 PM)toml_12953 Wrote:  ⋮ Look at your list of priority of operations on page 26 of the User’s Guide. ^ comes before unary minus. Only operations that are at the same level are evaluated left to right. Algebraic precedence The HP Prime calculator calculates according to the following order of precedence. Functions at the same level of precedence are evaluated in order from left to right. 1. Expressions within parentheses. Nested parentheses are evaluated from inner to outer. 2. !, √, reciprocal, square 3. nth root 4. Power, 10n ⋮ One wrinkle with the “left to right” rule the guide lays out is that the power operation is evaluated from right to left. RE: Easy question - Albert Chan - 09-06-2021 01:17 AM (09-01-2021 04:11 PM)toml_12953 Wrote:  8. AND and NOT 9. OR and XOR This is not what is observed in CAS (or XCAS) ... perhaps a bug ? HOME> true OR false AND false ﻿ ﻿ ﻿ ﻿ ﻿ → 1 CAS> ﻿ ﻿ ﻿ true OR false AND false ﻿ ﻿ ﻿ ﻿ ﻿ → false RE: Easy question - ijabbott - 09-06-2021 12:41 PM (09-06-2021 01:17 AM)Albert Chan Wrote:   (09-01-2021 04:11 PM)toml_12953 Wrote:  8. AND and NOT 9. OR and XOR This is not what is observed in CAS (or XCAS) ... perhaps a bug ? HOME> true OR false AND false ﻿ ﻿ ﻿ ﻿ ﻿ → 1 CAS> ﻿ ﻿ ﻿ true OR false AND false ﻿ ﻿ ﻿ ﻿ ﻿ → false It wouldn't be the first inconsistency between HOME and CAS environments! The Xcas documentation doesn't seem to describe the precedence of operators in the Giac/Xcas language, but all the boolean operators are described in the same section, so I guess 'and', 'or', and 'xor' are evaluated at the same precedence in left-to-right order. Changing the compatibility mode doesn't seem to make a difference to the operator precedence. RE: Easy question - jte - 09-06-2021 05:39 PM (09-06-2021 01:17 AM)Albert Chan Wrote:   (09-01-2021 04:11 PM)toml_12953 Wrote:  8. AND and NOT 9. OR and XOR This is not what is observed in CAS (or XCAS) … perhaps a bug ? HOME> true OR false AND false ﻿ ﻿ ﻿ ﻿ ﻿ → 1 CAS> ﻿ ﻿ ﻿ true OR false AND false ﻿ ﻿ ﻿ ﻿ ﻿ → false Good note! I tried three of the other evaluation environments (the interval byte code evaluator of the Advanced Graphing app, the BCD byte code evaluator of the Function app, and the Python terminal). ADV_GR> V1: X^2+Y^2<1 OR X>0 AND Y>0 → AND higher prec. than OR FUNCT> F1(X)= true OR false AND false → 1 (AND higher prec. than OR) PYTH> True or False and False → True (AND higher prec. than OR) Getting a consistent evaluation order also involves internal conversions between formats. Error propagation / short-circuiting is another consideration with logical operations. (The BCD byte code evaluator is more of a “push” evaluator than a “pull” evaluator, so error propagation matching the PPL evaluator’s didn’t just immediately occur naturally during implementation. That said, converting the BCD evaluator to a “pull” approach is something I have on my list of “desirable changes”.) RE: Easy question - jte - 09-06-2021 10:31 PM (09-06-2021 12:41 PM)ijabbott Wrote:  ⋮ The Xcas documentation doesn’t seem to describe the precedence of operators in the Giac/Xcas language, but all the boolean operators are described in the same section, so I guess ‘and’, ‘or’, and ‘xor’ are evaluated at the same precedence in left-to-right order. ⋮ Seems like a reasonable guess! When I just mentioned the “T ∨ F ∧ F“ to my daughter, she suggested another possibility: perhaps OR is higher precedence than AND in the CAS. So, as an experiment, I tried flipping the expression around and tried “False AND False OR True” in CAS view. “True” is the result. Not a bad illustration of some of the benefits of precedence rules — that, with associative and commutative operations like AND and OR, one may rearrange arguments to the higher precedence operation or to the lower precedence operation (without changing the final result). Since I mentioned trying the evaluation in Python, I thought I’d also try it using Python syntax in the CAS. There, “True or False and False” evaluates to “False”. RE: Easy question - Albert Chan - 09-07-2021 01:09 AM (09-06-2021 10:31 PM)jte Wrote:  I tried flipping the expression around and tried “False AND False OR True” in CAS view. “True” is the result. This showed CAS OR does not have higher precedence: 0×(0+1) = 0 But, it does not illustrate precedence rule, result is same as left to right: 0×0+1 = 1 Quote:I thought I’d also try it using Python syntax in the CAS. There, “True or False and False” evaluates to “False”. This showed CAS AND does not have higher precedence: 1+0×0 = 1 CAS only does left to right: (1+0)×0 = 0 see Maths in a minute: Boolean algebra RE: Easy question - boggiano - 09-09-2021 10:44 AM (09-01-2021 04:11 PM)toml_12953 Wrote:  Algebraic precedence The HP Prime calculator calculates according to the following order of precedence. Functions at the same level of precedence are evaluated in order from left to right. 1. Expressions within parentheses. Nested parentheses are evaluated from inner to outer. 2. !, √, reciprocal, square 3. nth root 4. Power, 10n 5. Negation, multiplication, division, and modulo 6. Addition and subtraction 7. Relational operators (<, >, ≤, ≥, ==, ≠, =) 8. AND and NOT 9. OR and XOR 10. Left argument of | (where) 11. Assign to variable (:=) Ok, so how I have to write an expression like this? (x+1)^(4/5) Thank you RE: Easy question - Joe Horn - 09-09-2021 05:40 PM (09-09-2021 10:44 AM)boggiano Wrote:  Ok, so how I have to write an expression like this? (x+1)^(4/5) Exactly like that, especially if you use Algebraic Entry mode (Home Settings). If you use Textbook Entry mode instead, then you can omit the second pair of parentheses, because the 4/5 will all be in the exponent field: $$(x+1)^{\frac{4}{5}}$$ RE: Easy question - jte - 09-09-2021 05:55 PM (09-07-2021 01:09 AM)Albert Chan Wrote:  ⋮ (09-06-2021 10:31 PM)jte Wrote:  I thought I’d also try it using Python syntax in the CAS. There, “True or False and False” evaluates to “False”. This showed CAS AND does not have higher precedence: 1+0×0 = 1 CAS only does left to right: (1+0)×0 = 0 ⋮ Yes, or to be more explicit: this seems to be true (in the CAS) whether or not Python syntax is being used. The following function, defined using Python syntax, flows into (A / True) when using the Prime’s Python evaluator and into (B / False) when using the CAS with Python syntax. Code: def eval_test():   if True or False and False:     # (A / True)   else:     # (B / False) My first test routine, eval_test2(), shown below, was actually to simply return the result of “True or False and False”, and then print it, but it seems there might be an issue with booleans in Python-syntax CAS functions on the Prime as eval_test2() returns “(null)” when run as a Python-syntax CAS function. Code: def eval_test2():   return True or False and False “On the Prime” as eval_test2() in Xcas (1.7.0-29), with “Xcas syntax” selected, returns “false”. (Well, Xcas did crash on me once, but I’m thinking that that could’ve been caused by my playing around with things like print_test() — print_test() reliably crashes both Xcas and the Prime CAS. [It is flagged as a syntax error when tried as Python, either in Xcas or in the Prime’s Python.] I’ll send in a bug report.) Code: def print_test():   print "%s %s" % True or False and False, False RE: Easy question - boggiano - 09-09-2021 06:05 PM (09-09-2021 05:40 PM)Joe Horn Wrote:   (09-09-2021 10:44 AM)boggiano Wrote:  Ok, so how I have to write an expression like this? (x+1)^(4/5) Exactly like that, especially if you use Algebraic Entry mode (Home Settings). If you use Textbook Entry mode instead, then you can omit the second pair of parentheses, because the 4/5 will all be in the exponent field: $$(x+1)^{\frac{4}{5}}$$ Sorry John, but I don't get it. $$(x+1)^{\frac{4}{5}}$$ with X=-2 I get an irrational number. Instead, if I use the " classic notation" (sqrt function + power) I get the right result: 1. I would like to continue to use this notation (it is faster to insert) RE: Easy question - toml_12953 - 09-09-2021 10:10 PM (09-09-2021 06:05 PM)boggiano Wrote:   (09-09-2021 05:40 PM)Joe Horn Wrote:  Exactly like that, especially if you use Algebraic Entry mode (Home Settings). If you use Textbook Entry mode instead, then you can omit the second pair of parentheses, because the 4/5 will all be in the exponent field: $$(x+1)^{\frac{4}{5}}$$ Sorry John, but I don't get it. $$(x+1)^{\frac{4}{5}}$$ with X=-2 I get an irrational number. Instead, if I use the " classic notation" (sqrt function + power) I get the right result: 1. I would like to continue to use this notation (it is faster to insert) I don't see how you get an irrational number. Here's a screenshot: RE: Easy question - boggiano - 09-09-2021 10:32 PM (09-09-2021 10:10 PM)toml_12953 Wrote:   (09-09-2021 06:05 PM)boggiano Wrote:  Sorry John, but I don't get it. $$(x+1)^{\frac{4}{5}}$$ with X=-2 I get an irrational number. Instead, if I use the " classic notation" (sqrt function + power) I get the right result: 1. I would like to continue to use this notation (it is faster to insert) I don't see how you get an irrational number. Here's a screenshot: And here the mine: (Sorry, I don't know how to take a screenshot!) RE: Easy question - ijabbott - 09-09-2021 11:59 PM The result of (-1)^(4/5) will depend on whether or not you have the "Allow complex output from real input" option turned on or off in the settings. If turned off, you will get the real result -1. If turned on, you will get the complex result -0.809016994375+0.587785252292*i. Also, I think the CAS mode always approximates to the complex result. Since -1 is e^(i*π), (-1)^(4/5) is (e^(i*π))^(4/5), which is e^(i*π*4/5) in exponential form, or 1∡(π*4/5) in polar form (radians mode), or cos(π*4/5)+sin(π*4/5)*i in rectangular form (radians mode). In CAS mode, pow2exp((-1)^(4/5)) produces e^((4/5)*i*π). RE: Easy question - Albert Chan - 09-10-2021 05:23 PM (09-09-2021 11:59 PM)ijabbott Wrote:  The result of (-1)^(4/5) will depend on whether or not you have the "Allow complex output from real input" option turned on or off in the settings. If turned off, you will get the real result -1. If turned on, you will get the complex result -0.809016994375+0.587785252292*i. Also, I think the CAS mode always approximates to the complex result. HP Prime emulator, 2.1.14181 (2018_10_16), just after a hard reset. From Symbolic Setup, if I pick Complex: Off, (-1)^(4/5) gives -0.809016994375+0.587785252292*i. If I pick Complex: System, or On, (-1)^(4/5) give "Error: (X<0)^(∉Z)" I was unable to setup calculator to give real root for (-1)^(4/5) = 1.0 RE: Easy question - ijabbott - 09-10-2021 06:09 PM (09-10-2021 05:23 PM)Albert Chan Wrote:   (09-09-2021 11:59 PM)ijabbott Wrote:  The result of (-1)^(4/5) will depend on whether or not you have the "Allow complex output from real input" option turned on or off in the settings. If turned off, you will get the real result -1. If turned on, you will get the complex result -0.809016994375+0.587785252292*i. Also, I think the CAS mode always approximates to the complex result. HP Prime emulator, 2.1.14181 (2018_10_16), just after a hard reset. From Symbolic Setup, if I pick Complex: Off, (-1)^(4/5) gives -0.809016994375+0.587785252292*i. If I pick Complex: System, or On, (-1)^(4/5) give "Error: (X<0)^(∉Z)" I was unable to setup calculator to give real root for (-1)^(4/5) = 1.0 On my real HP Prime G1 2.1.14588 (2021_05_05), setting Complex: On in Home Symbolic Settings produces a real result = 1, and setting Complex: Off produces the aforementioned complex result. That seems to be opposite of what I expected. It may be a bug? The "Intelligent Math" option in Home Settings needs to be turned off for all of the above. Setting Complex: On and evaluating (-1)^.8 produces the domain error that Albert mentions. RE: Easy question - boggiano - 09-11-2021 12:16 AM Just upgrade the Prime OS from 2.0.0.13865 to 2.1.14588 Now with: Home->Settings-> "Allow complex output from real input" OFF I get (X+1)^4/5 = 1 In CAS mode still getting the same complex result.