Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline Patrick Ps  
#1 Posted : 01 July 2018 15:54:10(UTC)
Patrick Ps

Rank: Newbie

Groups: Registered
Joined: 25/04/2017(UTC)
Posts: 6
Greece

Was thanked: 2 time(s) in 1 post(s)
Mod function is not working correctly when certain numbers are added to it.

mod.gif

Most values to be added work ok. But there are certain values that lead to wrong result. Note that the error occurs only when those values are assigned to a variable first, and then added. When they are added directly as numbers the are also OK. What could be the problem?

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Jean Giraud  
#2 Posted : 01 July 2018 19:44:06(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Originally Posted by: Patrick Ps Go to Quoted Post
Most values to be added work ok. But there are certain values that lead to wrong result.


No rational number are exactly represented
4.34000000000001
is exactly equal to 3.40000000000000000000000000000000000000000000000 ...
Confirmed NO bug.

mod.sm (32kb) downloaded 17 time(s).
thanks 2 users thanked Jean Giraud for this useful post.
on 02/07/2018(UTC),  on 04/07/2018(UTC)
Offline Patrick Ps  
#3 Posted : 02 July 2018 13:14:14(UTC)
Patrick Ps

Rank: Newbie

Groups: Registered
Joined: 25/04/2017(UTC)
Posts: 6
Greece

Was thanked: 2 time(s) in 1 post(s)
Thank you for your reply Jean, but I don't understand.

All of the above results are rationals, but only that value is represented as 4.340000...001

And, it is represented like that only when we add some values through a variable.

In any case, it's definetely not equal to 4.34, since problems occur with operations that follow. For example, b - d doesn't give an integer as a result and thus, if you put it as an argument in a function that needs integers as an argument, like Random(), you get an error

Edited by user 02 July 2018 13:17:12(UTC)  | Reason: Not specified

Offline Jean Giraud  
#4 Posted : 02 July 2018 21:28:22(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Originally Posted by: Patrick Ps Go to Quoted Post
Thank you for your reply Jean, but I don't understand.

All of the above results are rationals, but only that value is represented as 4.340000...001

And, it is represented like that only when we add some values through a variable.


Patrick,

You will find infinitely many of such inexact numerical evaluations.
Only integer arithmetic is considered exact.
In numerical maths, not a single function exists, they are all approximations
... approximations wrt the 4 arithmetic operations [+, -, *, /].
In the first IBM MainFrame(s), only few functions could be implemented
... ln(x), SQRT(x), Trig ... They existed from high demanding maths,
in the form of Continued Fractions. Continued fractions origin from the
Mesopotamians, certainly doing something intelligible for Them.

In the post period to IBM MaiFrame typical but most probably the French
Bull system [remember Kennedy/De Gaulle war about Honeywell to purchase Bull],
Normalized Rational Fractions were implemented [Padé, recently passed away at 94 ?].
A normalized rational fraction has the form Pn(x)/[1+ Qn(x)] Qn or Q(n-1)
Thus, it enables parallel computation. The form, normalized [1+ Qn(x)] of the
denominator adds numerical stability ... That's not all, it starts here:

Many of the numerical math functions are built-in the processors,
... ln(x), exp(x), SQRT(x), Y^X [Power Fnct], trig ...
as implemented, they have theoretical 21 decimals accuracy, but uncertain in the
range 18 ... 21 D of which only 15 will be displayed to take care of multi-functions
computation and in full agreement to 15 D standard tables.
Inside calculations are all carried in full floating point accuracy.
In Engineering, results of 15 D is superfluous. They have no more meaning than 12 D
or much less Decimals as nothing is exact from whatever agreed formualtion.

Ah ! Your processor and mine disagree.

modPatrick.PNG

25 decimals are possible on some bigger processors. They are no more normalized
rational fractions. They are ChebyShev, extremely stable but more demanding in
numerical processing and don't allow parallel computation.
Higher accuracy were possible in Mathcad/Matsoft from their built-in Big-Engine.

Cheers Patrick ... Jean


thanks 2 users thanked Jean Giraud for this useful post.
on 02/07/2018(UTC),  on 04/07/2018(UTC)
Offline Jean Giraud  
#5 Posted : 03 July 2018 01:48:28(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
You will find infinitely many of such inexact numerical evaluations.


Hart = 0.506915154862825
MCD ≡ 0.506915154862789

Who's right/wrong ? Abramowitz & Stegun

The 12th decimal is pretty small, as small as the leg of a fly 1 mm long
that you chop 1000, chop again 1000, chop again 1000.

1. A typical Normalized Rational Fraction [Bessel]
2. Typical "mod" RGB

Jean

Bessel JY.sm (65kb) downloaded 14 time(s).

Pattern Mandelbrot RGB.sm (694kb) downloaded 13 time(s).
thanks 1 user thanked Jean Giraud for this useful post.
on 04/07/2018(UTC)
Offline Patrick Ps  
#6 Posted : 04 July 2018 12:12:24(UTC)
Patrick Ps

Rank: Newbie

Groups: Registered
Joined: 25/04/2017(UTC)
Posts: 6
Greece

Was thanked: 2 time(s) in 1 post(s)
Thanks again Jean, I think I get it now! Clap

I'll check whether my problem is fixed if I ask my sheet to use less decimals accuracy. Dry
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.