Re: A workaround for the inefficient SUBST command Message #4 Posted by Gilles Carpentier on 3 July 2013, 5:17 p.m., in response to message #3 by peacecalc
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^&E1*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.
