[Request] Control of algebraic expressions CAS - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: [Request] Control of algebraic expressions CAS (/thread-6379.html) Pages: 1 2 |
[Request] Control of algebraic expressions CAS - compsystems - 06-08-2016 11:48 AM 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 ? ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ RE: [Request] Control of algebraic expressions CAS - parisse - 06-08-2016 12:58 PM sqrt(x) is evaled to pow(x,1/2) and 1/x to inv(x) RE: [Request] Control of algebraic expressions CAS - compsystems - 06-08-2016 01:50 PM 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: RE: [Request] Control of algebraic expressions CAS - parisse - 06-08-2016 07:18 PM quote() prevents evaluation. RE: [Request] Control of algebraic expressions CAS - compsystems - 06-08-2016 08:55 PM 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 RE: [Request] Control of algebraic expressions CAS - Tim Wessman - 06-08-2016 09:10 PM (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... :-| RE: [Request] Control of algebraic expressions CAS - compsystems - 06-08-2016 09:13 PM 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? RE: [Request] Control of algebraic expressions CAS - compsystems - 06-08-2016 09:31 PM 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') RE: [Request] Control of algebraic expressions CAS - compsystems - 06-08-2016 10:12 PM 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 ??????????? RE: [Request] Control of algebraic expressions CAS - parisse - 06-09-2016 05:44 AM Evaluation replaces division by *inv() For quoting, you can use the quote() function to avoid confusion with ' derivative RE: [Request] Control of algebraic expressions CAS - compsystems - 06-09-2016 10:45 AM 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 RE: [Request] Control of algebraic expressions CAS - parisse - 06-09-2016 10:58 AM That's because part does not quote it's arguments, they are evaluated. RE: [Request] Control of algebraic expressions CAS - compsystems - 06-09-2016 11:04 AM 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 RE: [Request] Control of algebraic expressions CAS - parisse - 06-09-2016 11:59 AM 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. RE: [Request] Control of algebraic expressions CAS - compsystems - 06-09-2016 12:20 PM 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 RE: [Request] Control of algebraic expressions CAS - parisse - 06-09-2016 02:23 PM 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). RE: [Request] Control of algebraic expressions CAS - compsystems - 06-09-2016 06:32 PM What am I doing wrong so that the following code does not work? Code: #cas prg_cas((x^3/x^2)) [ENTER] RE: [Request] Control of algebraic expressions CAS - parisse - 06-10-2016 04:46 AM you can't use quote on a variable name you want to evaluate. RE: [Request] Control of algebraic expressions CAS - parisse - 06-10-2016 06:33 AM You shoud use part(eval(.,1),.) for example a:=quote(sqrt(x)); part(eval(a,1),0); will return sqrt RE: [Request] Control of algebraic expressions CAS - compsystems - 06-10-2016 03:27 PM 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:
|