Post Reply 
[HELP] The most powerful function of CAS: PART
06-07-2016, 02:52 AM (This post was last modified: 06-07-2016 02:58 AM by compsystems.)
Post: #1
[HELP] The most powerful function of CAS: PART
Hi, I'm implementing a symbolic differentiation in the hpprime, link (, the code is based on an example of the catalog of the tivoyage200, Please images attached,

PART function on hp-prime works fine, but when the argument is an addition or multiplication of terms (x+y+z+w+... or x*y*z*...), returns the n terms, this makes impossible continue to codifying my prg =(, the PART function of ti69k extracted parts of 2 in 2 for this case: part(x+y+z+w) -> part((x+y)+(z+w)) = 2 and not 4

someone can help me solve this problem

if operator="+" then
return diff_table(part1,var)+diff_table(part2,var);

if operator="*" then
return diff_table(part1,var)*diff_table(part2,var);


// version 0.2 Jun 6 2016 by COMPSYSTEMS COPYLEFT inv(©)
    LOCAL nparts, operator, part1, part2;
    LOCAL xprSameVar;
    //CASE 1: if the expression is a variable name or identifier
    if (type(xpr)==DOM_IDENT) then
        // CASE 2: if the expression is equal to the variable, example diff(x,x)=1, otherwise diff(x,y)=0
        return when(xpr==var,1,0);
    // number of parts of the expression
    //CASE 3: diff(k,v)=0
    //print(nparts); print(operator); wait;
    if (nparts==0) then
        return 0; // xpr=pi, i, numbers
    if (nparts>1) then
        //print(part1); wait;
    xprSameVar:= (string(part1)==string(var));
    //CASE 4: diff(-f(v),v)=0 // NEG(xpr)
    if (operator=="-") then
        return -1*diff_table(part1,var);
    //CASE 5: diff(k*f(v),v)=0 // NEG(xpr)
    if (operator="*" and type(part1)==DOM_INT) then
        return part1*diff_table(part2,var);
    //CASE 6: diff(|f(v)|,v) with f(v)=v
    if (operator=="abs" and xprSameVar) then
        return sign(var); // assuming a function from R -> R
        //return var/abs(var); // Alternate Form
    //CASE 7: diff(|f(v)|,v)
    if (operator=="abs" and !(xprSameVar)) then
        return sign(var)*diff_table(part1,var);
    //         //CASE 8: diff(√(f(v)),v)
    //         if operator=="√" and xprSameVar then
    //             return 1/(2*√(var));
    //         end;
    //         //CASE 9: diff(√(v),v)
    //         if operator=="√" and !(xprSameVar) then
    //             return diff_table(part1,var)/(2*√(var));
    //         end;
    //CASE 8: diff(ln(v),v)
    if (operator=="ln" and xprSameVar) then
        return 1/var;
    //CASE 9: diff(ln(f(v)),v)
    if (operator=="ln" and !(xprSameVar)) then
        return diff_table(part1,var)/part1;
    //CASE 10: diff(sin(v),v)
    if (operator="sin" and xprSameVar) then
        return cos(var);
    //CASE 11: diff(sin(f(v)),v)
    if (operator="sin" and !(xprSameVar)) then
        return cos(part1)*diff_table(p1,var);
    //CASE 12: diff(cos(v),v)
    if (operator="cos" and xprSameVar) then
        return ­sin(var);
    //CASE 13: diff(cos(f(v)),v)
    if (operator="cos" and !(xprSameVar)) then
        return ­sin(part1)*diff_table(part1,var);
    //CASE 14: diff(tan(v),v)
    if (operator="tan" and xprSameVar) then
        return sec(var)^2 ; // alternate form (1/cos(x))^2
    //CASE 15: diff(tan(f(v)),v)
    if (operator="tan" and !(xprSameVar)) then
        return sec(part1)^2*diff_table(part1,var);
    //CASE 16: diff(sin^-1(v),v)
    if (operator=="asin" and xprSameVar) then
        return 1/√(1-var^2);
    //CASE 17: diff(sin^-1(f(v)),v)
    if (operator=="asin" and !(xprSameVar)) then
        return diff_table(part1,var)/√(1-part1^2);
    //CASE 18: diff(cos^-1(v),v)
    if (operator=="acos" and xprSameVar) then
        return ­1/√(1-var^2);
    //CASE 19: diff(cos^-1(f(v)),v)
    // acos(-x) -> ((π+2*asin(x))/2)
    //     if (operator=="acos" and !(xprSameVar)) then
    //         return -1*diff_table(part1,var)/√(1-part1^2);
    //     end;
    //CASE 20: diff(atan^-1(v),v)
    if (operator=="atan" and xprSameVar) then
        return 1/(1+var^2);
    //CASE 21: diff(atan^-1(f(v)),v)
    if (operator=="atan" and !(xprSameVar)) then
        return diff_table(part1,var)/(1+part1^2);
    //CASE  : diff(f+g,v)
    if operator="+" then
        return diff_table(part1,var)+diff_table(part2,var);
    // codifying
    // ...
    return Done;

Attached File(s) Thumbnail(s)
Find all posts by this user
Quote this message in a reply
Post Reply 

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