Post Reply 
[CAS] PART FUNCTION on sum of n terms
07-09-2016, 02:10 AM (This post was last modified: 03-02-2018 01:48 PM by compsystems.)
Post: #3
RE: [CAS] PART FUNCTION on sum of n terms
HP48 to HP50 also grouped the terms of addition and multiplication by twos


PHP Code:
« 0 0 { } -> EXPRESSION XPART NPARTS OPERATOR OBJECTS
  « EXPRESSION
    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
    END
      
IF XPART NPARTS <= XPART ->= AND NOT
      THEN 
"EXPRESSION " EXPRESSION " CONTAINS ONLY " NPARTS " PARTS" +
      ELSE
        IF 
XPART 0 ==
        
THEN OPERATOR
        
ELSE
          IF 
XPART -==
          
THEN NPARTS
          
ELSE OBJECTS XPART GET
          END
        END
      END
  »
»
'PART' STO 

'x^3-6*x^2+11*x-6' -1 PART @ returns 2 (parts)
'x^3-6*x^2+11*x-6' 0 PART @ returns "-"
'x^3-6*x^2+11*x-6' 1 PART @ returns '(x^3-6*x^2+11*x)'
'x^3-6*x^2+11*x-6' 2 PART @ returns 6
'x^3-6*x^2+11*x-6' 3 PART @ returns "EXPRESSION 'x^3-6*x^2+11*x-6' CONTAINS ONLY 2 PARTS"
'x^3-6*x^2+11*x-6' -3 PART @ returns "EXPRESSION 'x^3-6*x^2+11*x-6' CONTAINS ONLY 2 PARTS"

'X' -1 PART @ returns 0 (parts)
'X' OBJ->@ returns "ERROR" =(
'X^1' EVAL OBJ-> @ returns"ERROR" =(
'X^1' EVAL -1 PART @ returns 0 (parts)

'-X' -1 PART @ returns 1
'-X' 0 PART @ returns "NEG"
'-X' 1 PART @ returns 'X'

e -1 PART @ returns 0
e 0 PART @ returns "e"

pi -1 PART @ returns 0
pi 0 PART @ returns "pi"


'1/1 + -1/2 + 1/3 + -1/4 + 1/5 + -1/6 + 1/7 + -1/8 + 1/9 + -1/10 ' -1 PART @ returns 2
'1/1 + -1/2 + 1/3 + -1/4 + 1/5 + -1/6 + 1/7 + -1/8 + 1/9 + -1/10 ' 0 PART @ returns "+"
'1/1 + -1/2 + 1/3 + -1/4 + 1/5 + -1/6 + 1/7 + -1/8 + 1/9 + -1/10 ' 1 PART @ '-1/10 '
'1/1 + -1/2 + 1/3 + -1/4 + 1/5 + -1/6 + 1/7 + -1/8 + 1/9 + -1/10 ' 2 PART @ '1/1 + -1/2 + 1/3 + -1/4 + 1/5 + -1/6 + 1/7 + -1/8 + 1/9'
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [CAS] PART FUNCTION on sum of n terms - compsystems - 07-09-2016 02:10 AM



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