HP Forums
subst command in RPN mode (bug ?) - 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: subst command in RPN mode (bug ?) (/thread-4518.html)



subst command in RPN mode (bug ?) - Philippe - 08-12-2015 05:15 PM

Hello,

I would like to report the following behavior :

In home view and in textbook entry, subst('2*Q', 'Q=2') gives 4 as expected.
However, in RPN entry :

'2*Q' Enter
'Q=2' Enter
subst(2) Enter

Returns
"subst(2*Q, (Q==2)) Error: Bad argument type"

Do I miss something? Do you confirms it's a bug ?
Thanks
Philippe


RE: subst command in RPN mode (bug ?) - Tim Wessman - 08-12-2015 05:29 PM

Guessing it has something to do with how the arguments are being fed into the CAS. Probably something interacting with auto-evalation on the CAS side. In the list.

Thanks.

Note that the | (where) operator works fine here though without issue.


RE: subst command in RPN mode (bug ?) - Fortin - 08-12-2015 07:20 PM

This behavior changed from =(Q,2) to Q==2 pretty recently. I forget the specific release number though. This was also the release that changed the = behavior in Adv Graphing to == ... 7820 maybe? ...don't know if that helps...


RE: subst command in RPN mode (bug ?) - Didier Lachieze - 08-12-2015 07:56 PM

(08-12-2015 05:15 PM)Philippe Wrote:  In home view and in textbook entry, subst('2*Q', 'Q=2') gives 4 as expected.
However, in RPN entry :

'2*Q' Enter
'Q=2' Enter
subst(2) Enter
The single quotes are lost when you press enter, on the stack you don't have '2*Q' but just 2*Q.
So you need to add another set of single quotes or double
quotes around the parameters to make it work , for example :

"'2*Q'" Enter
"'(Q=2)'" Enter
subst(2)


RE: subst command in RPN mode (bug ?) - Marcelo Vanti - 08-12-2015 08:55 PM

(08-12-2015 07:56 PM)Didier Lachieze Wrote:  "'2*Q'" Enter
"'(Q=2)'" Enter
subst(2)

it works here, indeed, if I use q (lowercase letter) rather than Q:
"2*q"
"q=2"
CAS.subst(2) ==> 4


RE: subst command in RPN mode (bug ?) - Didier Lachieze - 08-12-2015 10:15 PM

(08-12-2015 08:55 PM)Marcelo Vanti Wrote:  
(08-12-2015 07:56 PM)Didier Lachieze Wrote:  "'2*Q'" Enter
"'(Q=2)'" Enter
subst(2)

it works here, indeed, if I use q (lowercase letter) rather than Q:
"2*q"
"q=2"
CAS.subst(2) ==> 4
It works as long as q is not defined. But if you create q, for ex by storing 0 to q then the subst command will return 0 as 2*q will be evaluated to 0 before the substitution can be done. To pass 2*q to the CAS for the substitution you need the single quotes inside the double quotes, or two levels of single quotes.


RE: subst command in RPN mode (bug ?) - Didier Lachieze - 08-12-2015 10:24 PM

(08-12-2015 08:55 PM)Marcelo Vanti Wrote:  
(08-12-2015 07:56 PM)Didier Lachieze Wrote:  "'2*Q'" Enter
"'(Q=2)'" Enter
subst(2)

it works here, indeed, if I use q (lowercase letter) rather than Q:
"2*q"
"q=2"
CAS.subst(2) ==> 4
It works as long as q is not defined. But if you create q, for ex by storing 0 to q then the subst command will return 0 as 2*q will be evaluated to 0 before the substitution can be done. To pass 2*q to the CAS for the substitution you need the single quotes inside the double quotes, or two levels of single quotes.


RE: subst command in RPN mode (bug ?) - Marcelo Vanti - 08-13-2015 12:36 PM

(08-12-2015 10:24 PM)Didier Lachieze Wrote:  It works as long as q is not defined. But if you create q, for ex by storing 0 to q then the subst command will return 0 as 2*q will be evaluated to 0 before the substitution can be done. To pass 2*q to the CAS for the substitution you need the single quotes inside the double quotes, or two levels of single quotes.

You're right. I did not know the possibility of working with single quotes within double quotes, for replacement. Thanks for the tip.


RE: subst command in RPN mode (bug ?) - Philippe - 08-14-2015 12:46 PM

Hello, 

To summarize, let :

Form1: subst(2*q , q=2)
Form2: subst(' 2*q ' , ' q=2 ')
Form3: subst(" 2*q " , "  q=2  ")
Form4: subst(" ' 2*q' " , " ' q=2 ' ")

BAT = Bad Argument Type error
SYN = Syntax error
n.a = not applicable

Then, we have :

1) In textbook entry, if q is not defined 

            |   Home   |    CAS
---------------------------------------------
Form1     |   SYN    |    4
Form2     |   SYN    |    4
Form3     |   4       |    BAT
Form4     |   4       |    BAT
---------------------------------------------

2) In textbook entry, if q is defined (0 in this case)

            |   Home                |    CAS
---------------------------------------------
Form1     |   BAT                 |    Warning, then 0
Form2     |   4                    |    4
Form3     |   0   (no warning)   |    BAT       
Form4     |   4                    |    BAT
---------------------------------------------

3) In RPN mode (forms are of course adapted), if q is not defined

            |   Home      |   
---------------------------------------------
Form1     |   n.a        |    
Form2     |   SYN       |    can't push '2*q' on stack
Form3     |   4          |    
Form4     |   4          |    
---------------------------------------------

4) In RPN mode, if q is defined (0 in this case)

            |   Home      |   
---------------------------------------------
Form1     |   n.a        |   
Form2     |   0          |    
Form3     |   0          |    
Form4     |   4          |    
---------------------------------------------

- In RPN, we cannot push expression that contains undefined variable:
  'q' Enter produce a syntax error. We already know that this is a big regression compared to hp50...hp28. No more comment.

- The Form2 seems (at least to me !) the most suited to have a homogeneous and clean syntax between Home view and CAS, RPN and algebraic notations.

- The warning "Warning, replacing 0 by 2, a substitution variable should perhaps be purged." is useful

- May be the electronic help should be updated (in order to explain simple/double quotes)

Cheers,
Philippe