Post Reply 
Absolute value: sometimes CAS is very clever, sometimes not!
09-06-2018, 06:14 PM
Post: #1
Absolute value: sometimes CAS is very clever, sometimes not!
For simplifications, CAS is generally very impressive and it helps a lot to get simplified results. But sometimes, obvious simplifications are missed, and it is very difficult to overcome the difficulty.

For example:
|a| - a ---> |a| - a
It makes sense because the result depends on the sign of a. No simplification is possible. Now if we assume a>0 and make the same expression, we get:
assume(a>0) ---> a
|a| - a ---> 0
This is very nice because in that case |a| = a and the result is actually zero. Great! This sophisticated simplification can be combined:
|a+1| - a ---> 1
This is still very good. But now, if we consider another positive variable, suddenly, CAS becomes stupid. For example if we continue:
assume(b>0) ---> b
|a+b| - a - b ---> |a+b| - a - b
This is not very clever because in fact we can simplify: |a+b| - a - b = 0 if both a and b are positive. The "simplify" command does not change anything.

I know that any CAS cannot be perfect. This is not a bug, but the fact that HP prime CAS cannot see this simplification is practically very annoying. In my field (I am a professor of physical-chemistry in a French university), I would like students to be able to use HP prime or Xcas for simple cases in order to show them how CAS can help to solve problems in physics and chemistry. It sometimes works, but when it doesn't work, most often it's simply because HP prime cannot simplify the absolute value of the sum of positive variables: |a+b| = a+b when a and b are positive.

As a result, HP prime (and Xcas) do not seem to be very useful in solving many physics and chemistry problems. On the other hand, I checked that Mathematica and Maple can do the simplication without any problems.

This problem (the fact that HP prime cannot simplify |a+b|=a+b if both a and b are positive) occurs in many science questions because in physics and chemistry, second-order equations are often solved together with Taylor expansions, which results in this type of simplification. I saw this absolute value problem which strongly limits the interest of HP prime (and Xcas) in science many times e.g. in electrostatics, kinetics, electrochemistry...

Does anyone know if we can overcome this difficulty? I know that there are specific simplification commands in the CAS. Maybe one of them allows us to do that?

With many thanks!
Find all posts by this user
Quote this message in a reply
09-07-2018, 12:23 AM (This post was last modified: 09-07-2018 12:37 AM by Tim Wessman.)
Post: #2
RE: Absolute value: sometimes CAS is very clever, sometimes not!
The best way is to work directly with Dr Parisse to express interest and show the need for changes. His general philosophy (not without merit) is that doing "simple" stuff is not the scope of what a CAS should do and so focus should be spent on the more difficult/high end things.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
09-07-2018, 02:27 AM
Post: #3
RE: Absolute value: sometimes CAS is very clever, sometimes not!
(09-07-2018 12:23 AM)Tim Wessman Wrote:  The best way is to work directly with Dr Parisse to express interest and show the need for changes. His general philosophy (not without merit) is that doing "simple" stuff is not the scope of what a CAS should do and so focus should be spent on the more difficult/high end things.

If you can't trust the calculator's answers for simple stuff, how are you going to trust it for more difficult problems? Confidence in a calculator's answers (whether simple or complex) is crucial to the success of the calculator in the market.

If I hire a person to paint a picnic table and he does a lousy job, will I hire him to paint my whole house? Not likely! Even if the analogy doesn't hold up well, it's how most people think. To sell calculators to us non-mathematicians (who probably make up the bulk of potential buyers), you can't think like a mathematician!

Tom L

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
09-07-2018, 05:33 AM (This post was last modified: 09-07-2018 05:50 AM by parisse.)
Post: #4
RE: Absolute value: sometimes CAS is very clever, sometimes not!
It works in Xcas for PC, not in Xcas for Firefox, not on the Prime. If my recollection is correct, this is because on these architectures where we have less computation power, essentially nothing is done for expression with more than one variable, because that would hang for some more complex expressions.
If there are important uses like you describe, I can probably add some code for simple multivariate expressions, where you can deduce the sign without advanced math algorithms. You can contact me directly in French by email or on the Xcas forum to discuss use of Xcas and calculator ports for science teaching.

To toml_12953: speak is easy. There is no bug here, it's just that implementation may be hard if you want to be able to run in all cases.
Find all posts by this user
Quote this message in a reply
09-07-2018, 05:55 AM
Post: #5
RE: Absolute value: sometimes CAS is very clever, sometimes not!
(09-06-2018 06:14 PM)jfdHP Wrote:  For simplifications, CAS is generally very impressive and it helps a lot to get simplified results. But sometimes, obvious simplifications are missed, and it is very difficult to overcome the difficulty.

For example:
|a| - a ---> |a| - a
It makes sense because the result depends on the sign of a. No simplification is possible. Now if we assume a>0 and make the same expression, we get:
assume(a>0) ---> a
|a| - a ---> 0
This is very nice because in that case |a| = a and the result is actually zero. Great! This sophisticated simplification can be combined:
|a+1| - a ---> 1
This is still very good. But now, if we consider another positive variable, suddenly, CAS becomes stupid. For example if we continue:
assume(b>0) ---> b
|a+b| - a - b ---> |a+b| - a - b
This is not very clever because in fact we can simplify: |a+b| - a - b = 0 if both a and b are positive. The "simplify" command does not change anything.

I know that any CAS cannot be perfect. This is not a bug, but the fact that HP prime CAS cannot see this simplification is practically very annoying. In my field (I am a professor of physical-chemistry in a French university), I would like students to be able to use HP prime or Xcas for simple cases in order to show them how CAS can help to solve problems in physics and chemistry. It sometimes works, but when it doesn't work, most often it's simply because HP prime cannot simplify the absolute value of the sum of positive variables: |a+b| = a+b when a and b are positive.

As a result, HP prime (and Xcas) do not seem to be very useful in solving many physics and chemistry problems. On the other hand, I checked that Mathematica and Maple can do the simplication without any problems.

This problem (the fact that HP prime cannot simplify |a+b|=a+b if both a and b are positive) occurs in many science questions because in physics and chemistry, second-order equations are often solved together with Taylor expansions, which results in this type of simplification. I saw this absolute value problem which strongly limits the interest of HP prime (and Xcas) in science many times e.g. in electrostatics, kinetics, electrochemistry...

Does anyone know if we can overcome this difficulty? I know that there are specific simplification commands in the CAS. Maybe one of them allows us to do that?

With many thanks!

I tried with assume(a>0) [Enter] additionally(b>0) [Enter]
CAS flags
Simplify: Maximum
Exact: [V] Complex: [ ]
Use V: [V] Use i: [ ]
Principal: [V] Increasing: [ ]

And still the CAS didn't try to group 'a' and 'b' inside the ABS
as well as the 'a' and 'b' outside of the ABS to cancel them out
|a+b| - a - b
nor
simplify(|a+b| - (a+b))
No
It just couldn't do it....so much for competing with Maple/etc Real CAS
In many ways xCAS has taken me with surprise, but you've found it's weakness.

Parisse?
Find all posts by this user
Quote this message in a reply
09-07-2018, 07:06 AM (This post was last modified: 09-07-2018 07:07 AM by parisse.)
Post: #6
RE: Absolute value: sometimes CAS is very clever, sometimes not!
Read my post above, Xcas (desktop version) does it. As far as I know, Maple or MMA are not ported on calculators, comparing a PC with the Prime is not fair, if you want to make CAS comparisons, do it on a desktop.
For the Prime, I can add code for simple situations like this one. But I can not enable the full Xcas code for several reasons (if the Prime was running linux, it would be different).
Find all posts by this user
Quote this message in a reply
09-07-2018, 08:57 AM (This post was last modified: 09-07-2018 03:21 PM by ijabbott.)
Post: #7
RE: Absolute value: sometimes CAS is very clever, sometimes not!
For what it's worth, \(\big\lvert a+b \big\rvert-a-b \mid a\ge 0 \ \mathrm{and}\ b\ge 0\) simplifies to \(0\) on TI Nspire CAS.

[Image: BSKrivm.png]

UPDATE:

Not surprisingly, the TI-89 Titanium behaves the same:

[Image: lIoTQd7.png]

Has anyone tried it on older HP (pre-Prime) CAS calculators yet?

— Ian Abbott
Find all posts by this user
Quote this message in a reply
09-07-2018, 09:06 AM (This post was last modified: 09-07-2018 11:15 AM by jfdHP.)
Post: #8
RE: Absolute value: sometimes CAS is very clever, sometimes not!
Thank you very much for your responses.

TW: In fact in my experience "simple" stuffs are generally solved by HP Prime. Simple problems that are not solved are generally very specific problems. I understand very well the philosophy that these specific problems are not a priority for a CAS.

Please note that even if the example I gave was quite simple, the original problems are in fact much more complicated. I only pinpointed the problematic stage in the calculation. I checked that if we overcome the difficulty by doing the absolute value simplification by hands, HP prime can solve the entire (complicated) physical problem.

toml_12953: There is no bug in the calculator. You still can trust the calculator's answer. The trouble is that there is a set of interesting problems in physic and chemistry where HP cannot help a lot because of the impossibility of simplifying theses absolute values.

parisse: Thanks for the response ; I sent you an email
Find all posts by this user
Quote this message in a reply
09-07-2018, 11:26 AM
Post: #9
RE: Absolute value: sometimes CAS is very clever, sometimes not!
(09-07-2018 07:06 AM)parisse Wrote:  Read my post above, Xcas (desktop version) does it. As far as I know, Maple or MMA are not ported on calculators, comparing a PC with the Prime is not fair, if you want to make CAS comparisons, do it on a desktop.
For the Prime, I can add code for simple situations like this one. But I can not enable the full Xcas code for several reasons (if the Prime was running linux, it would be different).
I admit I compared to desktop version and it's most unfair
since the full version is not available - not even on HW 2 with more RAM.
and
Another quick fix for the simple cases of ABS.
Note: the TI Nspire CAS could do it - as pointed out by a member in a post.
Yet again the HP Prime excels with it's limited version of xCAS

Thank you, Monsieur Parisse!
Find all posts by this user
Quote this message in a reply
09-07-2018, 04:30 PM (This post was last modified: 09-07-2018 04:38 PM by Komanguy.)
Post: #10
RE: Absolute value: sometimes CAS is very clever, sometimes not!
It works well on hp 50g, sorry for bad quality picture
[Image: 3_E4_E1921-824_F-4411-_B91_B-19_DA1_F4_E989_F.jpg]

As you may notice, the 50g replaces A>0 with A>=0

For your information, Dr Parisse is also the author of the hp 50g cas system!

Guy R. KOMAN, hp 50G, hp Prime Rev. C
Find all posts by this user
Quote this message in a reply
09-07-2018, 06:34 PM (This post was last modified: 09-07-2018 06:50 PM by compsystems.)
Post: #11
RE: Absolute value: sometimes CAS is very clever, sometimes not!
One problem with xcas is that it often assumes ( = ) as a comparison operator ( == ). I suggest that this feature be activated or not by means of a flag.

https://xcas.univ-grenoble-alpes.fr/foru...=19&t=2105

goto advanced graphing app
X, Y RETURNS [0,0] // ok, X and Y by default are in zeros
V1(X,Y):=X-2*Y=7; V2(X,Y):=5*X-3*Y=2; returns [0,0] // although the output is zero [0,0], the definition is correct. press [symb] key // V1:X-2*Y=7
right(V1) returns 0
0-2*0=7, 5*0-3*0=2
0=7, 0=2 // should not be evaluated, the symbolic expression should be left
0 => FALSE, 0 => FALSE

another problem is that he interprets expressions as if they were literal comparison

Simplify flag: maximum
assume(x,symbol);
answer:=domain((1/(x+1)),x); returns 1 // of true // x ≠ -1
answer:=domain((1/(x+1)),x); returns x ≠ -1
Find all posts by this user
Quote this message in a reply
09-07-2018, 06:37 PM
Post: #12
RE: Absolute value: sometimes CAS is very clever, sometimes not!
(09-07-2018 06:34 PM)compsystems Wrote:  One problem with xcas is that it often assumes ( = ) as a comparison operator ( == ). I suggest that this feature be activated or not by means of a flag.

https://xcas.univ-grenoble-alpes.fr/foru...=19&t=2105

another problem is that he interprets expressions as if they were literal comparison

Simplify flag: maximum
assume(x,symbol);
answer:=domain((1/(x+1)),x); returns 1 // of true // x ≠ -1
answer:=domain((1/(x+1)),x); returns x ≠ -1 // x

Didn't understand. Care to explain more, please!
Find all posts by this user
Quote this message in a reply
09-07-2018, 06:46 PM
Post: #13
RE: Absolute value: sometimes CAS is very clever, sometimes not!
sorry for my bad English

x ≠ -1 should not make a literal comparison x ≠ -1 => 1 synonyms of true, this should leave the symbolic expression, please try the sequence

go to [CAS/settings] Simplify flag: maximum
assume(x,symbol); [enter]
answer:=domain((1/(x+1)),x); returns 1 // the correct output is x ≠ -1
Find all posts by this user
Quote this message in a reply
09-08-2018, 03:37 AM
Post: #14
RE: Absolute value: sometimes CAS is very clever, sometimes not!
(09-07-2018 06:46 PM)compsystems Wrote:  sorry for my bad English

x ≠ -1 should not make a literal comparison x ≠ -1 => 1 synonyms of true, this should leave the symbolic expression, please try the sequence

go to [CAS/settings] Simplify flag: maximum
assume(x,symbol); [enter]
answer:=domain((1/(x+1)),x); returns 1 // the correct output is x ≠ -1

So if I understand correctly, you want to be able to store a symbolic value (of type DOM_SYMBOLIC) in a variable? That would be a nice feature. I haven't studied Xcas/Giac as much as you, but I think the closest you can get to your desired result at the moment is to store it as a string (type DOM_STRING) by using the cat() function. E.g.: answer:=cat(domain((1/(x+1)),x)). But I don't know how to convert it back to a symbolic value.

— Ian Abbott
Find all posts by this user
Quote this message in a reply
09-08-2018, 04:38 AM
Post: #15
RE: Absolute value: sometimes CAS is very clever, sometimes not!
(09-08-2018 03:37 AM)ijabbott Wrote:  So if I understand correctly, you want to be able to store a symbolic value (of type DOM_SYMBOLIC) in a variable? That would be a nice feature. I haven't studied Xcas/Giac as much as you, but I think the closest you can get to your desired result at the moment is to store it as a string (type DOM_STRING) by using the cat() function. E.g.: answer:=cat(domain((1/(x+1)),x)). But I don't know how to convert it back to a symbolic value.

You can store any object type into any CAS variable:

[Image: symb.png]

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
09-08-2018, 05:32 AM
Post: #16
RE: Absolute value: sometimes CAS is very clever, sometimes not!
(09-08-2018 04:38 AM)Joe Horn Wrote:  
(09-08-2018 03:37 AM)ijabbott Wrote:  So if I understand correctly, you want to be able to store a symbolic value (of type DOM_SYMBOLIC) in a variable? That would be a nice feature. I haven't studied Xcas/Giac as much as you, but I think the closest you can get to your desired result at the moment is to store it as a string (type DOM_STRING) by using the cat() function. E.g.: answer:=cat(domain((1/(x+1)),x)). But I don't know how to convert it back to a symbolic value.

You can store any object type into any CAS variable:

[Image: symb.png]

Hi Joe,

But can you store a symbolic value such as the return value of the domain() function into a variable without the return value being evaluated? E.g. domain((1/(1+x),x) returns 'x ≠ -1', but if you try to store it, it gets evaluated as 1 or 'true' (assuming 'x' is purged or symbolic).

— Ian Abbott
Find all posts by this user
Quote this message in a reply
09-08-2018, 06:05 AM
Post: #17
RE: Absolute value: sometimes CAS is very clever, sometimes not!
If you want to play with evaluation, make sure that Simplification is set to None in CAS Settings.
Then a:=domain(1/(x+1),x); followed by eval(a,1) will return x!=-1.
Find all posts by this user
Quote this message in a reply
09-08-2018, 09:43 AM (This post was last modified: 09-08-2018 09:44 AM by ijabbott.)
Post: #18
RE: Absolute value: sometimes CAS is very clever, sometimes not!
Perhaps the problem is the domain() function itself. Since the only sorts of sets supported by the CAS are discrete, finite sets of integers, it has no way to return the domain of a function in a way that cannot be subjected to misevaluation by the simplification rules.

— Ian Abbott
Find all posts by this user
Quote this message in a reply
09-08-2018, 10:43 AM
Post: #19
RE: Absolute value: sometimes CAS is very clever, sometimes not!
Back to compsystem's point, why does 'x ≠ -1' get simplified to a boolean 'true' if x is unknown?

— Ian Abbott
Find all posts by this user
Quote this message in a reply
09-08-2018, 10:52 AM
Post: #20
RE: Absolute value: sometimes CAS is very clever, sometimes not!
Because x (identifier) is different from 1 (integer), like for == which does not mean "mathematically equivalent".
Find all posts by this user
Quote this message in a reply
Post Reply 




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