HP Forums

Full Version: Is it bug? CAS solve function.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
HelloSmile
I got new HP prime a month ago.

I write 'solve ([a+5.6=6.6 -a+3b-1.2=-2.2], [a b])' in CAS mode.
Answer is a=1, b=3.88578058619E-16. But, It is inaccurate. actually i think a=1, b=0.

This happend same in Solve App.

There is something I missed?

about my prime
Hardware Version C
Software Version 2018 02 12
CAS 1.4.9
If you want exact results from CAS, you must use exact inputs (no decimal points allowed). Try this version of your problem (obviously equivalent but using exact numbers) and you'll get the exact answers you expected.

solve([a+56/10=66/10, -a+3b-12/10=-22/10], [a b])
Note that your numbers are correct as well!

0.000000000000000388578058619 is what it found.... which is basically 0

When solving using numerical methods, the computer changes the values by smaller and smaller amounts and attempts to converge onto a single number. However, it is very common that it can't "perfectly" find a number that works because computer numbers are not perfect! They have error built in, and algorithms can't be perfect in all situations. A human can look at a number and say "that should be 0" but that isn't always the case and a computer can't know it!

Much of the work in making good math libraries is figuring out how to reduce or cancel as much of the error as possible. For example, what is 1/3 ? Well, if you are using exact, CAS type systems then it is the "concept of 1 divided by 3" or a "ratio of 1 over 3". You CANNOT numerically represent .333333....... as it repeats infinitely however.

In this case, the generic "solve a number using a repetitive numerical calculation" algorithm in use can't perfectly converge down to 0. It does "almost" get there however. Smile
You can also use the EXACT command to convert your equations from approximate to exact. Here I used within the solve command in the CAS environment (see one of the pictures below. The equation is outlined in red). You get the exact answers of 1 and 0 in this case.

You can also use the Solve APP to get the answers (In two more pictures below). This solver only uses approximate answers so your 0 will just be a really small number. Extremely useful APP.
Why Xcas returns [[1,0]] if hp-prime & Xcas use the same math engine?

solve([a+56/10=66/10, -a+3*b-12/10=-22/10],[a,b]) => [[1,0]]

list2exp(solve([a+56/10=66/10, -a+3*b-12/10=-22/10],[a,b]),[a,b]) => a=1 and b=0

exp2list(ans(-1)) => [[1,0]]
(04-19-2018 03:55 PM)compsystems Wrote: [ -> ]Why Xcas returns [[1,0]] if hp-prime & Xcas use the same math engine?

solve([a+56/10=66/10, -a+3*b-12/10=-22/10],[a,b]) => [[1,0]]

list2exp(solve([a+56/10=66/10, -a+3*b-12/10=-22/10],[a,b]),[a,b]) => a=1 and b=0

exp2list(ans(-1)) => [[1,0]]

Joe already answered your question. If the user wants exact values, then exact inputs are needed (i.e. no decimals).
in the following example if you see two different results.

HP-prime
solve(x^3-1.1*x^2-65.4*x+229.5=0,x) {-9.,5.00000000001,5.09999999999}

Xcas
solve(x^3-1.1*x^2-65.4*x+229.5=0,x) list[-9.0,5.0,5.1]
(04-19-2018 04:22 PM)compsystems Wrote: [ -> ]in the following example if you see two different results.

HP-prime
solve(x^3-1.1*x^2-65.4*x+229.5=0,x) {-9.,5.00000000001,5.09999999999}

Xcas
solve(x^3-1.1*x^2-65.4*x+229.5=0,x) list[-9.0,5.0,5.1]

Prime's CAS uses a 48-bit binary mantissa for floating-point numbers. Hence:
format(1.1,"d17") --> "1.099999999999994"
format(65.4,"d17") --> "-65.39999999999963"
format(229.5,"d17") --> "229.4999999999999"

So it's no great surprise that inexact inputs result in inexact outputs.

What does Xcas use for its internal representation of floating-point numbers?
It's the same representation and you get the same answer (change the default value of Digits to 13 or 14 to see non rounded values).
All replies are helpful.
Thank you.
in the configuration of the hp-prime only allows up to 12 digits, in the Xcas which is the highest number of digits?
but in the hpprime it only allows up to 12 digits on home view
HDigits := 13 returns "HDigits(13) Error: Bad Argument Value"

on cas view

Digits := 1000; approx(π); returns 3.14159265359 Bug?
Digits := 13; solve(x^3-1.1*x^2-65.4*x+229.5=0,x) returns {-9.,5.00000000001,5.09999999999}


/!\ Digits command does not appear in the catalog
(04-21-2018 05:24 PM)moonbeam Wrote: [ -> ]With regards to floating point in CAS, see post #9 above.
doesn't work
Digits := 13; solve(x^3-1.1*x^2-65.4*x+229.5=0,x) returns {-9.,5.00000000001,5.09999999999}
(04-18-2018 04:17 PM)Tim Wessman Wrote: [ -> ]You CANNOT numerically represent .333333....... as it repeats infinitely however.
..If I'm not misunderstood (I'm not mathematician) this is true only in number bases like 2 or 10, but in base 3 (or other bases divisible by 3) it is exact. However in base 3 system the fractions like the 1/2 repeats infinitely. All of our common bases just happen to be the multiples of 2 and not 3.

Nitpicking. Smile

PS. Hopefully my understanding is correct.
(04-21-2018 10:45 PM)moonbeam Wrote: [ -> ]
(04-21-2018 08:44 PM)Vtile Wrote: [ -> ]PS. Hopefully my understanding is correct.

It is. Too bad we have ten instead of twelve fingers :-)

I use either octal or hex so I'd like eight fingers on each hand! Smile
(04-22-2018 03:00 AM)toml_12953 Wrote: [ -> ]I use either octal or hex so I'd like eight fingers on each hand! Smile

As Tom Lehrer once said, "Base-8 is just like base-10 really --- if you're missing two fingers."

https://www.youtube.com/watch?v=W6OaYPVueW4
Reference URL's