Post Reply 
[Request] Control of algebraic expressions CAS
06-08-2016, 11:48 AM (This post was last modified: 06-08-2016 08:56 PM by compsystems.)
Post: #1
[Request] Control of algebraic expressions CAS
1: In the first version of the CAS of hpprime, I suggested control the exit (simplify none, minimum, maximum), my request was accepted, to port some good programs that I have, I need also the output controlled from a program

simplifyFlag (arg);

arg = 0 -> none
arg = 1 -> minimum
arg = 2 -> maximum

2: also I need entries are not rewritten or simplified

for example, the followings line of code, the logic says must be true and not false

getOperator:=0;

_________________________
part(x^(1/2),getOperator)=="^"; -> true ok
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
_________________________
part(√(x),getOperator)=="√"; -> false ?
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
_________________________
part(1/x),getOperator)=="/"; -> false ?
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
_________________________
part(inv(x),getOperator)=="inv"; -> true ok
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
_________________________
part(cot(x)),getOperator)=="cot"; -> false ?
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
_________________________
part(sec(x)),getOperator)=="sec"; -> false ? sec(x)=1/cos(x)
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
_________________________
part(asec(x)),getOperator)=="asec"; -> false ?
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
_________________________
part(acos((1/x)),getOperator)=="acos"; -> true ok
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
_________________________
part((x^3/x^2),0))=="/"; -> false ?
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Find all posts by this user
Quote this message in a reply
06-08-2016, 12:58 PM
Post: #2
RE: [Request] Control of algebraic expressions CAS
sqrt(x) is evaled to pow(x,1/2) and 1/x to inv(x)
Find all posts by this user
Quote this message in a reply
06-08-2016, 01:50 PM (This post was last modified: 06-08-2016 02:33 PM by compsystems.)
Post: #3
RE: [Request] Control of algebraic expressions CAS
expressions rewrite alters the domains of expressions in many cases, rewrite the expressions is difficult to identify entry

fabulous if you can include a flag, so that the entries are not evaluated, at least in xcas

for example I want to know what the numerator and denominator of the following expression 'x^3/x^2', to make a symbolic derivation step as didactic project from my university, unfortunately this is evaluated as X =(

the following code will never be executed, the CAS hpprime is good, but does not allow me to do I want, with simple improvements could be the best CAS on calculators, the hp48/50 calculator retains the inputs to run obj-> that is similar to PART function (see PART FUNCTION on HP48/50) http://www.hpmuseum.org/forum/thread-6377.html)

if (operator=="/") then
Return (part2*diff_table(part1,var)-part1*diff_table(part2,var))/(part2^2);
end;

∂(x^3/x^2,x) -> ((x^2*∂(x^3,x))-(x^3*∂(x^2,x)))/x^2^2 -> 1

Code:
    
// version 0.2 Jun 6 2016 by COMPSYSTEMS COPYLEFT inv(©)
#cas
diff_table(xpr,var):=
BEGIN
    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);
    end;
    // number of parts of the expression
    nparts:=part(xpr);
    //operator
    operator:=part(xpr,0);

if (operator=="/") then
  Return (part2*diff_table(part1,var)-part1*diff_table(part2,var))/(part2^2);
    end;

...
Find all posts by this user
Quote this message in a reply
06-08-2016, 07:18 PM
Post: #4
RE: [Request] Control of algebraic expressions CAS
quote() prevents evaluation.
Find all posts by this user
Quote this message in a reply
06-08-2016, 08:55 PM (This post was last modified: 06-08-2016 09:10 PM by compsystems.)
Post: #5
RE: [Request] Control of algebraic expressions CAS
very well

but It requires placing parenthesis '()' IT IS A PROBLEM OF HISTORY VIEW?

please follow the following...

simplify maximum, '' = [()] KEY
_________________________
x^3/x^2 input returns x^3/x^2 , outpu returns x OK
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
_________________________
'x^3/x^2' returns ERROR
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

with '()'
_________________________
'(x^3/x^2)' input returns 'x^3/x^2' OK
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
also if I write quote (x^3/x^2) [enter], then under the input, to entry line also generates an error


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
06-08-2016, 09:10 PM
Post: #6
RE: [Request] Control of algebraic expressions CAS
(06-08-2016 08:55 PM)compsystems Wrote:  but It requires placing parenthesis '()' IT IS A PROBLEM OF HISTORY VIEW?

No, it is a problem of ' being used for "stop evaluation by quoting the object" (legacy HP usage) and ' being used for taking a derivative (CAS useage).

It works fine provided you aren't touching your ' directly. Add a space before/after and your are fine.

Other simple solution is to not alloy x^2' as syntax for a derivative... :-|

TW

Although I work for the HP calculator group, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
06-08-2016, 09:13 PM (This post was last modified: 06-08-2016 09:27 PM by compsystems.)
Post: #7
RE: [Request] Control of algebraic expressions CAS
try again
quote (x^3 / x^2) [enter] '(x^3/x^2)' ok
then up to history and copy the entry into the input line [enter] -> ERROR SINTAX '(x^3/x^2')

this moving a quotation mark (right) outside the brackets '(x^3/x^2')

your agree with the problem?
Find all posts by this user
Quote this message in a reply
06-08-2016, 09:31 PM
Post: #8
RE: [Request] Control of algebraic expressions CAS
including a space at the beginning works, but to copy the expression to the input line fails

' + [SPC] + x^3/x^2 + ' [ENTER] '(x^3/x^2)' ok

then up to history and copy the entry into the input line [enter] -> ERROR SINTAX '(x^3/x^2')
Find all posts by this user
Quote this message in a reply
06-08-2016, 10:12 PM (This post was last modified: 06-08-2016 10:20 PM by compsystems.)
Post: #9
RE: [Request] Control of algebraic expressions CAS
for Bernard

getOperator:=0;
part1:=1;
part2:=2;

part(x^3/x^2); -> part(x^3 * 1/x^2) -> returns 2 OK
part(x^3/x^2,getOperator); -> part(x^3 * 1/x^2,0) -> returns "*" OK
part(x^3/x^2,part1); -> part(x^3 * 1/x^2, 1) -> returns x^3 OK
part(x^3/x^2,part2); -> part(x^3 * 1/x^2, 2) -> returns 1/x^2 OK

now

part(quote(x^3/x^2)); -> part( '(x^3 / x^2)' ); -> returns 2 OK
part(quote(x^3/x^2),getOperator); -> part( '(x^3 / x^2)', 0 ); -> returns "/" OK OK
part(quote(x^3/x^2),part1); -> part( '(x^3 / x^2)', 1 ); -> returns x^3 OK
part(quote(x^3/x^2),part2); -> part( '(x^3 / x^2)', 2 ); -> returns x^2 OK

but

expr1:=quote(x^3/x^2) ;

part(expr1); -> part( '(x^3 / x^2)' ) -> returns 2 OK
part(expr1,getOperator); -> part( '(x^3 / x^2)', 0 ); -> returns "*" ???????????
part(expr1,part1); -> part( '(x^3 / x^2)', 1 ); -> returns x^3 OK
part(expr1,part2); -> part( '(x^3 / x^2)', 2 ); -> returns 1/x^2 ???????????
Find all posts by this user
Quote this message in a reply
06-09-2016, 05:44 AM
Post: #10
RE: [Request] Control of algebraic expressions CAS
Evaluation replaces division by *inv()
For quoting, you can use the quote() function to avoid confusion with ' derivative
Find all posts by this user
Quote this message in a reply
06-09-2016, 10:45 AM (This post was last modified: 06-09-2016 10:46 AM by compsystems.)
Post: #11
RE: [Request] Control of algebraic expressions CAS
quote apparently is not working
Try this again and tells me

within a program ...
getOperator:=0;
part1:=1;
part2:=2;
expr1:=quote(x^3/x^2) ;

part(expr1); ->returns 2 OK
part(expr1,getOperator); -> returns "*" ??? must be "/"
part(expr1,part1); -> returns x^3 OK
part(expr1,part2); -> returns 1/x^2 ??? ??? must be x^2
Find all posts by this user
Quote this message in a reply
06-09-2016, 10:58 AM
Post: #12
RE: [Request] Control of algebraic expressions CAS
That's because part does not quote it's arguments, they are evaluated.
Find all posts by this user
Quote this message in a reply
06-09-2016, 11:04 AM (This post was last modified: 06-09-2016 11:55 AM by compsystems.)
Post: #13
RE: [Request] Control of algebraic expressions CAS
but this makes useless the QUOTE command, the expression must be preserved, which proposes solution to code my problem?, it is possible with the CAS language of HPprime or not?

the idea is to store the math expressions as identifiers, they are part of the arguments of a function, also as inserted an expression into an argument if this can change
Find all posts by this user
Quote this message in a reply
06-09-2016, 11:59 AM
Post: #14
RE: [Request] Control of algebraic expressions CAS
You should not try to prevent evaluation and live with the fact that some operations are rewritten differently after evaluation. Think of *inv() as a division, +neg() as a substraction and pow(.,1/2) as a sqrt. This should not change much a derivation program, in fact there are a little less rules to write.
Find all posts by this user
Quote this message in a reply
06-09-2016, 12:20 PM (This post was last modified: 06-09-2016 12:42 PM by compsystems.)
Post: #15
RE: [Request] Control of algebraic expressions CAS
sorry for my bad English, I hope you can understand

in fact there are a little less rules to write.
>> it is true, it is possible for many cases, the idea is to show step by step the partial derivation for program educational, not intend to show the final answer, the only way is keeping the entry as entered, for example: ∂(x^3/x^2,x) -> "((x^2*∂(x^3,x))-(x^3*∂(x^2,x)))/x^2^2" y not "1"

the QUOTE instruction loses all his power, when the argument is an identifier that contains a symbolic expression.

[challenge] please can improve your command at least xcas?

QUOTE (expr) -> 'expr'

I think adding a new data type

type ('expr') -> DOM_unmodifiedSYMBOLIC

I think that would be the only "cas" that allow you to manipulate expressions, ideal for developing programs step by step, I want to write programs similar to those that are in http://www.tinspireapps.com but free


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
06-09-2016, 02:23 PM
Post: #16
RE: [Request] Control of algebraic expressions CAS
But you can already write that kind of programs. It will just require adaptations, if you want to recognize a quotient for example you must first find a root node * then look in the arguments for an inv, and if you find one (or more) collect them into what will be your denominator. For sqrt, you don't have anything special to do, the rule for pow is OK (it is also for *inv() but this will not be exactly the rule that is usually teached, at least in France).
Find all posts by this user
Quote this message in a reply
06-09-2016, 06:32 PM
Post: #17
RE: [Request] Control of algebraic expressions CAS
What am I doing wrong so that the following code does not work?

Code:
#cas
prg_cas(xpr):=
    BEGIN
        local getOperator, part1, part2, expr1;
        getOperator:=0;
        part1:=1;
        part2:=2;
        print("original input: " + xpr); wait; // x^3/x^2 // OK
        print("with '': " + quote(xpr)); wait;
        expr1:=quote(xpr);
        print("with '' and stored in ID: " + expr1); wait;
        
        print("operator: "+ part(quote(xpr),getOperator) ); wait;
        print("operator: "+ part(quote(expr1),0) ); wait;
        print("part1: "+ part(quote(expr1),part1) ); wait;
        print("part1: "+ part(quote(xpr),part1) ); wait;
        print("part2: "+ part(quote(xpr),part2) ); wait;
    END;
#end

prg_cas((x^3/x^2)) [ENTER]
Find all posts by this user
Quote this message in a reply
06-10-2016, 04:46 AM
Post: #18
RE: [Request] Control of algebraic expressions CAS
you can't use quote on a variable name you want to evaluate.
Find all posts by this user
Quote this message in a reply
06-10-2016, 06:33 AM
Post: #19
RE: [Request] Control of algebraic expressions CAS
You shoud use part(eval(.,1),.)
for example
a:=quote(sqrt(x));
part(eval(a,1),0);
will return sqrt
Find all posts by this user
Quote this message in a reply
06-10-2016, 03:27 PM (This post was last modified: 06-10-2016 07:30 PM by compsystems.)
Post: #20
RE: [Request] Control of algebraic expressions CAS
I can not find documentation of the EVAL command, which means the second argument of EVAL
part( eval(a,1), 0);


The following code, why not call QUOTE to xpr ID or argument of p1(xpr)?
Code:

#cas
p1(xpr):=
    BEGIN
        local getOperator, part1, part2, expr1;
        getOperator:=0;
        part1:=1;
        part2:=2;
        print( "original input: " + xpr ); wait; // retunrs x^3/x^2, PRINT recall xpr ID, OK
        print( ": " + 3*xpr*6 ); wait; // returns 3*x^3/x^2*6, PRINT also recall xpr ID, OK
        print( ": " + collect(3*xpr*6) ); wait; // returns 18*x, OK
        print( "with '': " + quote(xpr) ); wait; // returns xpr ??, why not call QUOTE to xpr ID?
        print( "with ' ' and eval external: " + eval(quote(xpr)) ); wait; // returns x^3/x^2 OK
        print( "with ' ' and eval internal:'': " + quote(eval(xpr)) ); wait; // returns eval(xpr) ??
    END;
#end
Find all posts by this user
Quote this message in a reply
Post Reply 




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