A workaround for the inefficient SUBST command
#1

For all HP 50g users,

The SUBST command works only correct for substituting names, but not for expressions, like "X=SIN(R*T)" when you have additonal names "R" or "T" in the expression where you want to substitute the "X".

A little program is able to overcome that behavier. I wrote this because of a thread in the hp own calculator forum with that topic.

Thank you pin224466 (that person who started the thread) for clarifying that problem. I have to post here, because I left the hp own forum some time ago. I hope that is okay to go that way.


<< EQ-> 2 ->LIST -> MATCHLST
<< WHILE MATCHLST "UP"MATCH
REPEAT END
>>
>>

'CHGEX' STO

As Input you have same syntax like for SUBST, but ist works now fine without isolating to other names. And even better it can be used with placeholders as "&A"!

For example:

STACK 2:  'COS(3*X+7*SIN(X^2 - R*T))'
STACK 1: 'X=R/T'

CHGEX

STACK 1: 'COS(3*R/T+7*SIN((R/T)^2-R*T))'


Greetings
peacecalc

#2

Well done ...

But I think


 \<< EQ\-> 2 \->LIST \|^MATCH DROP \>>

is sufficiant ?

#3

Hello Gilles,

your solution is more elegant and shorter and it has the same functionalty. Thank you, for improving the code.

My fault was to think, that the MATCH command only works subtituting the pattern founded on the same level (that make sense for outputting the result code zero or one). But MATCH works in one run even for nested expressions. It seems to be a recurrence program.

Greetings
peacecalc

#4

The MATCH command is very powerfull. Here is an example to extend the capacity of the CAS with some "sum" functions :

@ Exact mode
@ The system flag 3 must be '->symb'

DIR

EEVAL
\<<
{
'\GS(&A=&B;&C;&D+&E)'
'\GS(&A=&B;&C;&D)+\GS(&A=&B;&C;&E)'
}
\|^MATCH DROP

{
'\GS(&A=&B;&C;&D/&A!)'
'\GS(&A=&B;&C;&D/&A!*1^&A)'
}
\|^MATCH DROP

{
'\GS(&A=&B;&C;&D/&A!*&E^&A)'
'&D*e^&E-1*Somme(&A,&B,&D/&A!*&E^&A)'
'IFTE(&B>=0 AND &C== \oo AND NOT(Dép?(&D,&A)) AND NOT(Dép?(&E,&A)),1.,0.)'
}
\|^MATCH DROP

EVAL
\>>

Dép?
\<<
\-> f v
\<<
f LNAME NIP IF DUP TYPE 5. <> THEN AXL END
v POS
\>>
\>>

Somme
\<<
\-> n b f
\<<
0
IF 'b>0' THEN
0 b 1 - FOR bb f n bb = SUBST + EVAL NEXT
END
\>>
\>>
END

If you use EEVAL instead of EVAL, the 50G now knows that :

'\GS(n=0, +\oo, (5/n!)*sin(x)^n)'
->
'5.e^sin(x)'

'\GS(n=0,+\oo,b/n!*X^n+1/(n+1)^2)'
->
'(6*b*EXP(X)+PI^2)/6'

'\GS(n=3,+\oo,1/n!*SIN(X)^n)'
->
'-((EXP(2*LN(SIN(X)))-(2*EXP(SIN(X))-(2*SIN(X)+2)))/2)'

'\GS(n=5,+\oo,b/n!*X^n+1/(n+1)^2)' EEVAL EXPAND
->
'-((1800*b^2*X^2+600*b^2*X^3+150*b^2*X^4-(3600*b*EXP(X)+600*‡^2-(3600*b^2*X+3600*b^2+5269)))/3600)'

'\GS(n=0, +\oo, (5/n!)*sin(n)^n)'
-> ?

Edited: 3 July 2013, 5:22 p.m.



Possibly Related Threads…
Thread Author Replies Views Last Post
  [HP-Prime CAS] "Warning, ^ (Command) Is ambiguous on non square matrices"?? CompSystems 1 2,141 12-07-2013, 07:15 PM
Last Post: CompSystems
  Programming workaround for "prepend" HP PRIME Marek Russ 4 1,983 11-29-2013, 05:46 AM
Last Post: Marek Russ
  HP Prime - most favorite command bluesun08 2 1,442 11-12-2013, 11:29 AM
Last Post: bluesun08
  hp prime - command syntax bluesun08 6 2,336 11-10-2013, 11:57 AM
Last Post: bluesun08
  HP PRIME: command to read the SERIAL ? Joseph Ec 9 5,704 11-01-2013, 12:43 AM
Last Post: Joe Horn
  Connectivty Kit for HP Prime needs an "Import Program" Command Eddie W. Shore 3 1,874 10-23-2013, 03:37 PM
Last Post: Eddie W. Shore
  HP Prime MOUSE command SanS 3 1,647 10-15-2013, 12:15 PM
Last Post: Han
  [HP-Prime] randPoly command CompSystems 0 1,000 09-26-2013, 08:49 AM
Last Post: CompSystems
  [HP-Prime xCAS] BUG: string command =( CompSystems 6 2,099 09-10-2013, 06:38 PM
Last Post: CompSystems
  [HP_Prime] definition of functions, APPLY command and BUGs CompSystems 1 1,277 09-05-2013, 03:59 PM
Last Post: CompSystems

Forum Jump: