[CAS] PART FUNCTION on sum of n terms
07-04-2016, 01:18 AM (This post was last modified: 03-02-2018 01:46 PM by compsystems.)
Post: #1
 compsystems Senior Member Posts: 1,179 Joined: Dec 2013
[CAS] PART FUNCTION on sum of n terms
Hello, the part function works fine, but there is a problem. If the expression is a sum of n terms (a+b+c+d+e+f+.... n), returns the number of terms, that make within a program, the expression parser will be dificultier

part( a + b + c + d + e + f +.... n) returns n

the TI68k calculators return in a group of two terms

PHP Code:
part( a + b + c + d + e + f +.... n)  => part( (a) +(b+c+d+e+f+.... n) ) returns 2part( a + b + c + d + e + f +.... n, 1 )  => part( (a) +(b+c+d+e+f+.... n), 1 ) returns (a)part( a + b + c + d + e + f +.... n, 2 )  => part( (a) +(b+c+d+e+f+.... n), 2 ) returns (b+c+d+e+f+.... n)
when nested part (hp-prime), the sums expressions are difficult to control.

Is possible to reprogram the PART function that groups of two terms in a sum? as the ti68k

hp-prime
part( quote( 1/1 + -1/2 + 1/3 + -1/4 + 1/5 + -1/6 + 1/7 + -1/8 + 1/9 + -1/10 ) )
RETURNS 10

part( quote( 1/1 + -1/2 + 1/3 + -1/4 + 1/5 + -1/6 + 1/7 + -1/8 + 1/9 + -1/10 ), 2 )
RETURNS -1/2

TI89
part( quote( 1/1 + -1/2 + 1/3 + -1/4 + 1/5 + -1/6 + 1/7 + -1/8 + 1/9 + -1/10 ) ) =>
part(quote( (1/1) + (-1/2 + 1/3 + -1/4 + 1/5 + -1/6 + 1/7 + -1/8 + 1/9 + -1/10) ))
RETURNS 2

part( quote( 1/1 + -1/2 + 1/3 + -1/4 + 1/5 + -1/6 + 1/7 + -1/8 + 1/9 + -1/10 ), 1 )
RETURNS 1/1
part( quote( 1/1 + -1/2 + 1/3 + -1/4 + 1/5 + -1/6 + 1/7 + -1/8 + 1/9 + -1/10 ) , 2 )
RETURNS (-1/2 + 1/3 + -1/4 + 1/5 + -1/6 + 1/7 + -1/8 + 1/9 + -1/10)

Thanks
07-04-2016, 11:00 AM
Post: #2
 parisse Senior Member Posts: 1,027 Joined: Dec 2013
RE: [CAS] PART FUNCTION on sum of n terms
In short: no.
It's much better to have all arguments of + or * at the same level with a n-ary operator than to embedd some of them sometimes very deeply if + or * are binary, it reflects much better the structure of the expression (for example you can exchange two arguments easily).
07-09-2016, 02:10 AM (This post was last modified: 03-02-2018 01:48 PM by compsystems.)
Post: #3
 compsystems Senior Member Posts: 1,179 Joined: Dec 2013
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 -1 >= AND NOT      THEN "EXPRESSION " EXPRESSION + " CONTAINS ONLY " + NPARTS + " PARTS" +      ELSE        IF XPART 0 ==        THEN OPERATOR        ELSE          IF XPART -1 ==          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'
07-09-2016, 08:03 AM
Post: #4
 parisse Senior Member Posts: 1,027 Joined: Dec 2013
RE: [CAS] PART FUNCTION on sum of n terms
Correct. That's precisely because I knew the limitations of having binary + and * that I designed Giac with n-ary + and *. One of the limitation (that is perhaps not obvious on a calc) is to be able to handle sums with a very large number of arguments (for example 1 million). With binary + the last argument would be so much embedded that many symbolic operations would segfault because of stack overflow during recursion.
07-09-2016, 10:13 AM
Post: #5
 Claudio L. Senior Member Posts: 1,628 Joined: Dec 2013
RE: [CAS] PART FUNCTION on sum of n terms
(07-09-2016 08:03 AM)parisse Wrote:  Correct. That's precisely because I knew the limitations of having binary + and * that I designed Giac with n-ary + and *. One of the limitation (that is perhaps not obvious on a calc) is to be able to handle sums with a very large number of arguments (for example 1 million). With binary + the last argument would be so much embedded that many symbolic operations would segfault because of stack overflow during recursion.

I agree. Symbolics in newRPL also have n-ary + and * (there's no CAS yet, but the expression format and compiler/decompiler is finished). Much easier to scan for terms or factors in a flattened tree than a binary tree.
 « Next Oldest | Next Newest »

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