Elemental arithmetics; about Sqr(x^2)

For everything that's not in any way related to PureBasic. General chat etc...
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Elemental arithmetics; about Sqr(x^2)

Post by Psychophanta »

There are bibliographies that say that Sqr(x^2) = |x| , and others that Sqr(x^2) = +-x

It is a discussion that seems to have no end but that some of us see it clearly, that it depends on the strength with which the so-called "hierarchy of operations" is applied.

If you feel like spending time on it, then please reason out the answer about your position in the dilemma.

Code: Select all

v.f=-2.0
r.f=Sqr(Pow(v,2.0))
r2.f=Sqr(v*v)
r3.f=Pow(v,2.0/2.0); <- NOTICE that Sqr(X) is in fact X^(1/2)
debug r
debug r2
debug r3
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Elemental arithmetics; about Sqr(x^2)

Post by Lord »

Shouldn't it be
r3.f=Pow(v, 1.0/2.0); <- NOTICE that Sqr(X) is in fact X^(1/2)
in order to get the root?
The result ist the correct answer: NaN
Image
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Elemental arithmetics; about Sqr(x^2)

Post by juergenkulow »

PureBasic does not have complex arithmetic.

Code: Select all

// r2.f=Sqr(v*v)
double p0=(double)((double)v_v*v_v);
double rr2=PB_Sqr_DOUBLE(p0);
wolframalpha sqr(-x^2)
User avatar
STARGÅTE
Addict
Addict
Posts: 2232
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Elemental arithmetics; about Sqr(x^2)

Post by STARGÅTE »

@Psychophanta
What? I don't understand what you want to say.

If you evaluate the root of a number, it gives always the principal root, the positive number.
That's how functions like Sqr() or Pow() are defined in a programming language.
Similar, ASin(0.0) gives only the principal period value of the sine function, although also Sin(2*#Pi) is 0.0.

The option of receiving multiple results is only possible when you solve an equation (not directly possible in Pure Basic). Then, you get a solution space of no solution, one solution or multiple solutions.

Your simplification of Sqr(x^2) = (x^2)^(1/2) = x^(2/2) = x^1 = x is in general not allowed!
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Piero
Addict
Addict
Posts: 923
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Elemental arithmetics; about Sqr(x^2)

Post by Piero »

Also,
Psychophanta wrote: Mon Sep 11, 2023 8:08 am There are bibliographies that say that
i^2 = −1
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Elemental arithmetics; about Sqr(x^2)

Post by Psychophanta »

@STARGÅTE
The thread is not about program language neither computing. It is just aritmetics. And that is whoy it is posted in 'offtopic' :)
You say
Your simplification of Sqr(x^2) = (x^2)^(1/2) = x^(2/2) = x^1 = x is in general not allowed!
why is it not correct?

@Piero and @juergenkulow, yes, i know, and well? What you say is not to do with this, because this is only for real numbers (sorry i forgot to say it)

@Lord , sorry to say you have not see the dilemma.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
STARGÅTE
Addict
Addict
Posts: 2232
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Elemental arithmetics; about Sqr(x^2)

Post by STARGÅTE »

Psychophanta wrote: Tue Sep 12, 2023 7:51 am @STARGÅTE
The thread is not about program language neither computing. It is just aritmetics. And that is whoy it is posted in 'offtopic' :)
You say
Your simplification of Sqr(x^2) = (x^2)^(1/2) = x^(2/2) = x^1 = x is in general not allowed!
why is it not correct?
I linked the reason.
The rule (x^a)^b = x^(a*b) applies only for integers in a and b, or, if x is positive, for real numbers.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Elemental arithmetics; about Sqr(x^2)

Post by Psychophanta »

STARGÅTE wrote: Tue Sep 12, 2023 9:34 am I linked the reason.
The rule (x^a)^b = x^(a*b) applies only for integers in a and b, or, if x is positive, for real numbers.
Right.
There is a trouble: in arithmetics (bad called 'mathematics') and in nature study (well called 'physics') the exception breaks a rule, so, a rule cannot be validated capriciously for some values ​​and not for others.

About that wiki link and others, we must say there are not in consensus with other bibliographies.
My position is not with rules which are valid only for some specific cases, but a rule should be valid for ALL cases.

How to stay in the real world: x^t = x · |x|^(t-1) 🤩
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
STARGÅTE
Addict
Addict
Posts: 2232
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Elemental arithmetics; about Sqr(x^2)

Post by STARGÅTE »

Psychophanta wrote: Tue Sep 12, 2023 1:49 pm My position is not with rules which are valid only for some specific cases, but a rule should be valid for ALL cases.
This is nonsense. Every rule always has its scope, some times smaller, sometimes larger. There are no rule for all cases.
Even a simple "rule" like x · y = y · x is only valid for real and complex numbers but not for Quaternions, used for 3D-rotations.
In computer science it is even worse, because here the "rule" a · (b + c) = a · b + a · c is not true any more when using floats or doubles:

Code: Select all

Define a.d = 5
Define b.d = 0.4
Define c.d = 0.8

If a*(b+c) = a*b + a*c
	Debug "The world is fine."
Else
	Debug "Opps, "+StrD(a)+"*("+StrD(b)+"+"+StrD(c)+") ≠ "+StrD(a)+"*"+StrD(b)+" + "+StrD(a)+"*"+StrD(c)
	Debug a*(b+c)
	Debug a*b + a*c
EndIf
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Elemental arithmetics; about Sqr(x^2)

Post by Psychophanta »

Cmon, the example you have posted is due to the imprecission of the modern computing, and you know it.

In computing you can manage a line with a 0 width, or a plane of 0 width, but only if you previously ideal preparing the algorithms, because 0 width is an ideal used as a tool for real things.

And yes, vectorial product, quat product, etc, don't pass, for example, the conmutative product rule, JUST BECAUSE vector, quaternions, etc, ARE COMPOSED by scalars (real numbers), so they are not real numbers itself.
But, when dealing with real numbers, every serious rule should catch ALL of them, i think this is sense = not notsense :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Little John
Addict
Addict
Posts: 4789
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Elemental arithmetics; about Sqr(x^2)

Post by Little John »

STARGÅTE wrote: Tue Sep 12, 2023 2:28 pm
Psychophanta wrote: Tue Sep 12, 2023 1:49 pm My position is not with rules which are valid only for some specific cases, but a rule should be valid for ALL cases.
This is nonsense. Every rule always has its scope, some times smaller, sometimes larger. There are no rule for all cases.
Exactly like that!
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Elemental arithmetics; about Sqr(x^2)

Post by Lord »

42
Image
User avatar
Piero
Addict
Addict
Posts: 923
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Elemental arithmetics; about Sqr(x^2)

Post by Piero »

Code: Select all

Define b.d = 0.4
Define c.d = 0.8

Debug b+c
1.2000000000000001776356839

:shock: :shock: :shock: :x :o :?
User avatar
NicTheQuick
Addict
Addict
Posts: 1519
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Elemental arithmetics; about Sqr(x^2)

Post by NicTheQuick »

Piero wrote: Wed Sep 13, 2023 1:38 pm

Code: Select all

Define b.d = 0.4
Define c.d = 0.8

Debug b+c
1.2000000000000001776356839

:shock: :shock: :shock: :x :o :?
That's not shocking. That's normal in every programming language that uses floats. See https://en.wikipedia.org/wiki/Floating- ... y_problems
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Piero
Addict
Addict
Posts: 923
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Elemental arithmetics; about Sqr(x^2)

Post by Piero »

NicTheQuick wrote: Wed Sep 13, 2023 2:12 pm That's not shocking. That's normal in every programming language that uses floats. See https://en.wikipedia.org/wiki/Floating- ... y_problems
Yeah, I just had forgotten that it happens, being how floats/doubles are "stored"... anyway some languages "fix" that, or have math libraries to avoid the problem
Post Reply