Post Reply 
newRPL: [UPDATED April 27-2017] Firmware for testing available for download
05-26-2016, 04:47 PM (This post was last modified: 05-26-2016 06:51 PM by compsystems.)
Post: #272
RE: newRPL: [UPDATED May-06-16] Firmware for testing available for download
Hi I have managed create the same function PART (TI89, HPPRIME) for HP48/49/50 calculators, this function to extract each part of an expression, very useful to analyze the algebraic expression, It requires that obj-> function is available in NEWRPL

sOURCE cODE
Code:

« 0 0 { } -> EXPRESSION XPART NPARTS OPERATOR OBJECTS
  « EXPRESSION EVAL
    IFERR OBJ->
    THEN ->STR 'OPERATOR' STO 0 'NPARTS' STO OPERATOR 1 ->LIST 'OBJECTS' STO
    ELSE ->STR 'OPERATOR' STO 'NPARTS' STO NPARTS ->LIST 'OBJECTS' STO NPARTS OPERATOR OBJECTS 3 ->LIST DROP
      IF XPART NPARTS <= NOT
      THEN "EXPRESSION " EXPRESSION + " CONTAINS ONLY " + NPARTS + " PARTS" + KILL
      END
      IF XPART 0 ==
      THEN OPERATOR
      ELSE
        IF XPART -1 ==
        THEN NPARTS
        ELSE OBJECTS XPART GET
        END
      END
    END
  »
»
'PART' STO


Syntax:
part(Expr, Integer)

Returns the nth sub expression of an expression. If the second argument is empty (-1 for hp48/49/50), returns the number of parts.
If the second argument is ZERO, returns the operator if any, otherwise returns the same expression as string


Examples:
TI89/TIVOYAGE200PLT AND HPPRIME

part(sin(x)+cos(y)) → 2 // two parts sin(x) & cos(y)
part(sin(x)+cos(y),1) → sin(x) // first part
part(sin(x)+cos(y),2) → cos(y) // second part
part(sin(x)+cos(y),3) → "nonexistent part in the expression"
part(sin(x)+cos(y),0) → "+" // operator between parts

part( part(sin(x)+cos(y),1)) → 1 // number of parts of the first part
part( part(sin(x)+cos(y),2)) → 1 // number of parts of the second part

part( part(sin(x)+cos(y),1),1) → x // firts part of the firts part, sin(x)→ x
part( part(sin(x)+cos(y),2),1) → y // firts part of the second part, cos(y)→ y

part( part(sin(x)+cos(y),1),0) → "sin" // operator of the firts part, sin(x)→ "sin"
part( part(sin(x)+cos(y),2),0) → "cos" // operator of the second part, cos(x)→ "cos"


part(sin(x)) → 1 // one part
part(sin(x),1) → x // first part
part(sin(x),0) → "sin" // operator "sin"

part(part(exp(x)*sin(x) + cos(x),1),2) → sin(x) // second part of the first part exp(x)*sin(x) → sin(x)
part(part(exp(x)*sin(x) + cos(x),1),0) → "*" // operator of the first part exp(x)*sin(x) → "*"
part(part(exp(x)*sin(x) + cos(x),2),0) → "cos" // operator of the second part cos(x)→ "cos"
part(part(exp(x)*sin(x) + cos(x),2),1) → "x"
part(part(exp(x)*sin(x) + cos(x),1)) → 2
part(part(exp(x)*sin(x) + cos(x),1),1) → exp(x)
part(part(part(e^x*sin(x) + cos(x),1),1),1) → x
part(part(part(e^x*sin(x) + cos(x),1),1),0) → "exp"

special cases

part(-X) → 1 // one parts
part(-X,1) → 1 // firts part, X
part(-X,0) → 1 // operator "-"

part(X1) → 0 // No parts
part(X1,0) → "X1"

part(-1) → 0 // No parts
part(-X,0) → 1 // "-1"
--------------

hp48/49/50 SERIES

'sin(x)+cos(x))' -1 → 2 // 2 parts
'sin(x)+cos(x)' 0 → "+" // operator
'sin(x)+cos(x)' 1 → 'sin(x)' // part1
'sin(x)+cos(x)' 2 → 'cos(x)' // part2
'sin(x)+cos(x)' 3 → "nonexistent part in the expression"


application of the PART function

TI89 Code
Code:
difstep(f,x)
Func
  //f(x),x
  Local op
  //diff(x,x)
  If getType(f)="VAR"
    Return when(f=x,1,0,0)
  part(f,0)->op
  //diff(k,x)
  If part(f)=0
    Return 0
  //diff(­f,x)
  If op="­"
    Return ­1*difstep(part(f,1),x)
  //diff(x^n,x)
  If op="^"
    Return part(f,2)*part(f,1)^(part(f,2)-1)
  //diff(v(x),x)
  If op="sqroot"
    Return 1/(2*sqroo(part(f,1)))
  //diff(f+g,x)
  If op="+"
    Return difstep(part(f,1),x)+difstep(part(f,2),x)
  //diff(f-g,x)
  If op="-"
    Return difstep(part(f,1),x)-difstep(part(f,2),x)
  //diff(f*g,x)
  If op="*"
    Return part(f,1)*difstep(part(f,2),x)+part(f,2)*difstep(part(f,1),x)
  //diff(f/g,x)
  If op="/"
    Return (part(f,2)*difstep(part(f,1),x)-part(f,1)*difstep(part(f,2),x))/part(f,2)^2
...
  Return undef
EndFunc
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: newRPL: [UPDATED May-06-16] Firmware for testing available for download - compsystems - 05-26-2016 04:47 PM



User(s) browsing this thread: 2 Guest(s)