CAS command question
|
01-04-2017, 08:37 PM
Post: #21
|
|||
|
|||
RE: CAS command question
(01-04-2017 04:01 PM)Han Wrote: Regarding your comment on the second case... I'm not sure I follow. The example I gave shows how to use strings and still not have it evaluate anything -- just add ' to the start and end of the string. Second point by way of Example. Here is a linear programming problem: p=3x+2y ==> Objective Function s.t. 2x+3y<=12 2x+y<=8 ==> Constraints Then as part of a program, the user is asked to key in each of those expressions. The program's input structure receives the above as a list of string objects: L9:={"p=3x+2y","2x+3y<=12","2x+y<=8 "}; I was referring to: CAS("left(CAS(L9(I)))"); where I is a loop variable, as being a straight forward way to parse left sides of each expression in the list, IF left() could be depended upon to yield the left side, which it can't, when the inequality sign is "<". I think you were referring to: The second case uses evaluation. left(CAS(" 'x+y<4' ")) will return x+y. The distinction being the additional requirement for the single quotes. (Apologies for the confusion). Both of Arno K's comments are fitting, but I was referring to his first, "left is left, and right is right" comment. That says it all. The user solving the example problem would not need to be concerned about the intrinsic system level details, and can input the expressions as found, no need to worry about evaluation, format, or other internal concerns. Even more so, if tasked with creating a program solver for this example. |
|||
01-04-2017, 11:09 PM
Post: #22
|
|||
|
|||
RE: CAS command question
(01-03-2017 07:24 AM)parisse Wrote: This is not a bug and has nothing to do with left and right, it's because evaluation rewrites inequation with >= or >. If you enter x<2, it is evaled as 2>x. My 2 cents. 1. When you do left(x+y>=4) or left(x+y>4) -> x+y (no quote) 2.When you do left(x+y)<=4 or left(x+y<4) -> 4 (with quote returns x+y) Why does it do what you say only for < and <=, but not for > and >= ? Thank you. |
|||
01-04-2017, 11:56 PM
Post: #23
|
|||
|
|||
RE: CAS command question
First I did not want to bother about this topic anymore after my first comment (left is left...) was smashed back by Bernard in a quite rude way
Quote: This is not a bug and has nothing to do with left and right, it's because evaluation rewrites inequation with >= or >. If you enter x<2, it is evaled as 2>x., I read it like : this is not a bug and you are simply unable to understand it, something Dale may have thought reading parisse's answer somewhere else. I will not say that I can write a program like this CAS, but I am earning my money in another way where I teach students and pupils maths and so using a tool like a calculator, too, I can convince them to buy a specific device of which here Parisse is one of the main actors, and thus he also depends on me. But I have written programs of all kinds since 1982, most of the time the commands did what they should, so something called "left" delivered left. Perhaps he should have written that the help-file only deals with equations and intervals and for other objects it will provide some kind of answer and then have explained the special behaviour in case of inequations. But still then I would think that this has to be explained in the help ( how I liked the advanced users guide of my 32S and 48). This had to be said. Now I read that at least three others members agree to this being a bug, at least some kind of wrong naming. Here are my 2 pence: The commands left and right should provide an error when used with inequations and two new commands should be implemented which leave the expression as it is and provide the desired part of the entered expression (without any longer thought: exleft and exright). This then would meet the needs for any problem concerning parts of an expression. Arno |
|||
01-05-2017, 02:07 AM
(This post was last modified: 01-05-2017 02:40 AM by Han.)
Post: #24
|
|||
|
|||
RE: CAS command question
(01-04-2017 08:37 PM)DrD Wrote: Both of Arno K's comments are fitting, but I was referring to his first, "left is left, and right is right" comment. That says it all. The user solving the example problem would not need to be concerned about the intrinsic system level details, and can input the expressions as found, no need to worry about evaluation, format, or other internal concerns. Even more so, if tasked with creating a program solver for this example. And this is the biggest pitfall for any CAS user. Mathematica uses f[x] for functions whereas Maple uses f(x). But then writing f(x)=x^2 in Maple doesn't actually create a function. In fact, functions are represented as name := (var) -> expression (like the Prime). Some systems use 0-based indexing and others use 1 as the starting index (and this varies even from country to country; I think the EU normally starts sequences at 0 whereas there is not a consistent convention in the US). This is why I make it a point to teach my own students that the first thing to using a CAS is knowing how it represents its objects. This is especially important when programming with a CAS. When a user types f(2), should this be literally f(2) unevaluated? Or should the system return 4 if f was previously defined as f(x):=x^2? Being able to properly deal with symbolic input that has many equivalent forms is not trivial from a programming point of view, even though it is quite trivial mathematically. More relevant to our discussion, if x:=(a+b<c) then should x be treated literally as the symbol 'x' or should it be treated as equivalent to a+b<c? This is a simple yet important question because left(x) -- as you prefer it -- could either return a+b or give an error because the symbol x itself contains only a single letter and no "left hand side" (or "right hand side"). From a user point of view, it seems almost obvious that when we type left(x) we mean for x to be replaced by a+b<c. Except it is completely non-obvious from a programming point of view. For what it's worth, Maple's lhs and rhs commands behave almost exactly this way (at least in Maple 17, anyway) except they prefer < and <= over > and >=. From their documentation: Quote:There are three internal data types for inequalities, corresponding to the operators <>, <, and <=. Inequalities involving the operators > and >= are converted to the latter two cases for purposes of representation. An inequality has two operands, the left-hand side and the right-hand side. The names <>, <, <= are known to the type function. The real problem here is not really about left/right -- in fact, the more I play around with them, the more I lean toward thinking that they are perfectly consistent in behavior and even properly named (see earlier post on how expressions are represented). The "only" problem I see here is that in the lack of documentation. The Prime's CAS documentation (and even non-CAS documentation) is unfortunately always lagging behind the feature-set. For parisse: I honestly do not know of a good documentation system this late in the game, and one that comes to mind may be a bit too late: doxygen. Comments are turned into online documentation and one can embed mathematics code such as LaTeX. You probably know about it, but for those who don't -- it basically strips comments from source code and turns it into documentation. That way programmers can keep everything in a file and not have to write documentation in a separate file. I suppose one could go back and add in comments into the source code. EDIT: forget what I said about doxygen; I misread what you mean for documentation. Graph 3D | QPI | SolveSys |
|||
01-05-2017, 07:46 AM
Post: #25
|
|||
|
|||
RE: CAS command question
To Arno K: I want to stress that English is not my native language, my first post was not intented to be rude, it was just factual.
To the subject: I think you can make a parallel with RPN : when people first use a RPN calculator they must learn a little how it works. This is the same for CAS, except the rules are different, in RPN you have much more control over evaluation than in algebraic mode ... but it's much harder to program (and maintain a program). For that reason, you shouldn't try to go against the system (even if you can quote arguments) because at some point your expression will be evaluated. Here is a CAS program that extracts the information of any inequation condition for a simplex program Code:
I really believe that it is worth the effort to learn a little bit how CAS work because you can make more powerful programs. |
|||
01-05-2017, 08:54 AM
Post: #26
|
|||
|
|||
RE: CAS command question
Bernard, vous etes correcte en disant que l'Anglais n'est pas votre langue maternelle.
I understand your point of view, learn the CAS better and you understand better, that is clear, I can learn to solve differential equations without decent knowledge of Analysis, but I won't understand the main parts. Nevertheless I use the calculator as a tool which then has to do what I want, so the command right used with any expression is expected to provide the right side of that expression. So take a look at my idea of implementing the error-condition and two new commands. Arno |
|||
01-05-2017, 11:38 AM
Post: #27
|
|||
|
|||
RE: CAS command question
The topic is pretty well covered now, and my own parting thoughts are that the CAS left/right commands are just not fully implemented.
Parisse has alluded to the fact that in the left(), right(), string objects are part of giac, but not the prime, that inequality relations are not part of the command features, (as per help guides), and that consistency requires evaluation which turns the expressions around whenever "<" operators are embedded. Support for the status quo can be found in some other CAS products, and support for the counter-approach (left returns left, etc.) can be found as well, in still other CAS products. Separate commands for left and right, (currently unavailable), could offer a compromise, for those who feel low-level (near machine language) programming is more important than a high-level (interpreted) environment. As for me, I would prefer a closer analog with the literal language interpretation, as Arno K presented: left returns left for ANY relational operation, etc. This could be an ENHANCEMENT for the existing commands, by taking the existing command's "evaluated" expressions, and TURN them BACK around, (from what has been described as "natural order"). Much less desirable, would be to amend the Help doc's to warn users away from expressions with inequality relational operators. Thanks, everyone. Evolution isn't so easy, but the end result, hopefully, is worth the pursuit! I appreciate your point of view, and that you took the time to respond. -Dale- |
|||
01-05-2017, 12:46 PM
Post: #28
|
|||
|
|||
RE: CAS command question
Sorry my native language is not english
The RIGHT & LEFT functions can be programmed with the PART command, but you have to enter the expressions in quotation marks, so that the expression is taken as written PHP Code: testpartcas( ):= Related to the manipulation of expressions. The programs that I want to made are step by step, if the expressions are rewritten, the logic of the algorithm is lost, with QUOTES, I solve this, but I have to ask the user, that input the expression in quotation marks, (Unnatural notation). I repeat a previous question My question for Parisse: how is it done within a program to convert the input inside a quotation mark? I try the following, but it does not work PHP Code: #cas so we would need a new CAS command called RECALL PHP Code: id1 := quote( RECALL (id0) ); Another solution would be to interpret as a QUOTE EXPRESSION, if the arguments are within quotes, PHP Code: helpquote( 'id0' ):= |
|||
01-05-2017, 02:28 PM
Post: #29
|
|||
|
|||
RE: CAS command question
part(Expr, Integer) isn't a viable replacement. It requires advance awareness of the nth number of sub-expressions, an extra handling process.
The discussion isn't about finding a way to accomplish this task. There are a variety of ways the CONCEPT of left() or right() "COULD" be made to work. Unfortunately, it seems there isn't a 'single' command, that simply returns it's namesake, without complication; hence the whole point of this discussion. It might be better to start a new topic on the consequences of evaluation first, or of single quoting expressions, etc., if you would care to pursue the alternatives. |
|||
01-05-2017, 04:49 PM
(This post was last modified: 01-05-2017 04:50 PM by Han.)
Post: #30
|
|||
|
|||
RE: CAS command question
If you want a non-CAS program that does lhs and rhs:
Code: EXPORT lhs(s) lhs("x+y<4") returns x+y as desired Graph 3D | QPI | SolveSys |
|||
01-05-2017, 07:31 PM
Post: #31
|
|||
|
|||
RE: CAS command question
Not sure if I understand compsystem, perhaps he is asking the unquote command that is available in Xcas but not on the Prime.
y:=3; x:=5; a:='x+unquote(y)' |
|||
01-05-2017, 08:08 PM
(This post was last modified: 01-05-2017 08:13 PM by compsystems.)
Post: #32
|
|||
|
|||
RE: CAS command question
In other words, I want to extract the numerator from the input a/b
How can you do this in hp-prime using CAS commands? Without converting the entry into a text string purge(x,y); numer(x/y); ⇒ x // ok numer(10/2) ⇒ 5 // =( ⇒ 10 part(x/y,1); ⇒ x // ok part(10/2,1) ⇒ 5 // =( ⇒ 10 PHP Code: #cas |
|||
01-05-2017, 09:07 PM
Post: #33
|
|||
|
|||
RE: CAS command question
(01-05-2017 08:08 PM)compsystems Wrote: In other words, I want to extract the numerator from the input a/b If you use the lhs and rhs above, it works as you need it (but requires the input to be a string): lhs("10/2"); --> 10 Graph 3D | QPI | SolveSys |
|||
01-05-2017, 09:20 PM
Post: #34
|
|||
|
|||
RE: CAS command question
(01-05-2017 07:31 PM)parisse Wrote: Not sure if I understand compsystem, perhaps he is asking the unquote command that is available in Xcas but not on the Prime. If I'm not mistaken, I believe what he wants is equivalent to Maple's "uneval": Code: f := proc(x::uneval) x^2 end proc: Graph 3D | QPI | SolveSys |
|||
01-05-2017, 10:02 PM
Post: #35
|
|||
|
|||
RE: CAS command question
Most likely my comment doesn't add anything new (compare DrD reference to TI's left) but left works on lists as:
Code: left({1,2,3,4,5},3)={1,2,3} This use is not documented (not on the HP Prime "help" or on the user manual. (I suppose that inequalities like x+y<1 are stored as lists {1,x+y} ?) Also, there are two "right" commands: RIGHT() and right(). Cannot tell the difference. |
|||
01-05-2017, 10:46 PM
(This post was last modified: 01-05-2017 11:16 PM by compsystems.)
Post: #36
|
|||
|
|||
RE: CAS command question
left( '(x+y) ≤ 4' ); ⇢ x+y // If the algebraic expression is between ' ', it will not be rewritten.
left( x+y ≤ 4 ); ⇢ left( 4 ≥ x+y ); ⇢ "4" left( STRING( (x+y) ≤ 4), 1 ); ⇢ left( "4≥x+y", 1 ); ⇢ "4" LEFT( STRING( (x+y) ≤ 4), 1 ); ⇢ LEFT( "4≥x+y", 1 ); ⇢ "4" // With LEFT the firts argument must always be a string left( "(x+y) ≤ 4",1 ); ⇢ "(" RIGHT( STRING( (x+y) ≤ 4), 3 ); ⇢ "x+y" right( STRING(x+y ≤ 4), 3 ); ⇢ "x+y" ================ Quote:....I believe what he wants is equivalent to Maple's "uneval": Similar, do not evaluate the input parameters of the functions I do not program in MAPLE, the following is affirmative? PHP Code: f := proc(x::uneval) numerator(x) end proc: |
|||
01-05-2017, 11:05 PM
Post: #37
|
|||
|
|||
RE: CAS command question
(01-05-2017 10:46 PM)compsystems Wrote: [...] My Prime doesn't do that: Code: RIGHT(STRING(x+y<=4),3); -> "+y)" (which is consistent with storing inequalities as lists, in "decreasing" order, after enclosing each term in parenthesis). |
|||
01-05-2017, 11:53 PM
(This post was last modified: 01-05-2017 11:56 PM by Han.)
Post: #38
|
|||
|
|||
RE: CAS command question
(01-05-2017 10:46 PM)compsystems Wrote: No, it returns 5, which is what I would expect it to do since it calls numerator() (the Maple command is actually numer()), which is a function that evaluates the input. Graph 3D | QPI | SolveSys |
|||
01-06-2017, 05:59 PM
(This post was last modified: 01-06-2017 06:02 PM by DrD.)
Post: #39
|
|||
|
|||
RE: CAS command question
Unfortunately, this approach fails to return the (lhs or rhs), unless the input is constrained to coefficients with approximate numbers:
Example: s:="(1/3)x+(1/6)y<=80"; // lhs(s) ==> Error: Invalid input (Extra credit challenge: Convert the exact(coefficients) to approximate) (01-05-2017 04:49 PM)Han Wrote: If you want a non-CAS program that does lhs and rhs: |
|||
01-06-2017, 06:57 PM
Post: #40
|
|||
|
|||
RE: CAS command question
This works:
lhs("(1/3)*x+(1/6)*y<=80") Prime G2, 15C CE |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 8 Guest(s)