News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Exponentiation

Started by JK, July 31, 2022, 06:18:09 AM

Previous topic - Next topic

JK

Hey jj,

it is not so easy as it seems at first glance, i remember having to deal with such things in school (and i wasn´t that bad in math), but this is decades ago and my knowledge became rusty over the years.

@all,

thanks for your contributions, i think, i´m going to repeat a few math lessons ... and come back later

JK

FORTRANS

Hi,

   Just for fun, I output the values produced by the base of -2.4
and the range of the exponent from 3.0 to 4.0 by 0.01.

  -2.400   0.000   3.000   0.000 -13.824   0.000
  -2.400   0.000   3.010   0.000 -13.939  -0.438
  -2.400   0.000   3.020   0.000 -14.040  -0.883
  -2.400   0.000   3.030   0.000 -14.129  -1.336
  -2.400   0.000   3.040   0.000 -14.204  -1.794
  -2.400   0.000   3.050   0.000 -14.265  -2.259
  -2.400   0.000   3.060   0.000 -14.311  -2.730
  -2.400   0.000   3.070   0.000 -14.344  -3.206
  -2.400   0.000   3.080   0.000 -14.361  -3.687
  -2.400   0.000   3.090   0.000 -14.363  -4.173
  -2.400   0.000   3.100   0.000 -14.350  -4.663
  -2.400   0.000   3.110   0.000 -14.322  -5.156
  -2.400   0.000   3.120   0.000 -14.277  -5.653
  -2.400   0.000   3.130   0.000 -14.216  -6.152
  -2.400   0.000   3.140   0.000 -14.139  -6.653
  -2.400   0.000   3.150   0.000 -14.046  -7.157
  -2.400   0.000   3.160   0.000 -13.936  -7.661
  -2.400   0.000   3.170   0.000 -13.808  -8.166
  -2.400   0.000   3.180   0.000 -13.664  -8.672
  -2.400   0.000   3.190   0.000 -13.503  -9.176
  -2.400   0.000   3.200   0.000 -13.324  -9.680
  -2.400   0.000   3.210   0.000 -13.128 -10.183
  -2.400   0.000   3.220   0.000 -12.914 -10.683
  -2.400   0.000   3.230   0.000 -12.683 -11.181
  -2.400   0.000   3.240   0.000 -12.433 -11.676
  -2.400   0.000   3.250   0.000 -12.167 -12.167
  -2.400   0.000   3.260   0.000 -11.882 -12.653
  -2.400   0.000   3.270   0.000 -11.580 -13.135
  -2.400   0.000   3.280   0.000 -11.260 -13.610
  -2.400   0.000   3.290   0.000 -10.922 -14.080
  -2.400   0.000   3.300   0.000 -10.566 -14.543
  -2.400   0.000   3.310   0.000 -10.193 -14.998
  -2.400   0.000   3.320   0.000  -9.802 -15.446
  -2.400   0.000   3.330   0.000  -9.394 -15.885
  -2.400   0.000   3.340   0.000  -8.969 -16.314
  -2.400   0.000   3.350   0.000  -8.526 -16.734
  -2.400   0.000   3.360   0.000  -8.067 -17.143
  -2.400   0.000   3.370   0.000  -7.590 -17.540
  -2.400   0.000   3.380   0.000  -7.098 -17.926
  -2.400   0.000   3.390   0.000  -6.588 -18.300
  -2.400   0.000   3.400   0.000  -6.063 -18.661
  -2.400   0.000   3.410   0.000  -5.522 -19.007
  -2.400   0.000   3.420   0.000  -4.966 -19.340
  -2.400   0.000   3.430   0.000  -4.394 -19.658
  -2.400   0.000   3.440   0.000  -3.808 -19.960
  -2.400   0.000   3.450   0.000  -3.207 -20.246
  -2.400   0.000   3.460   0.000  -2.592 -20.516
  -2.400   0.000   3.470   0.000  -1.963 -20.768
  -2.400   0.000   3.480   0.000  -1.321 -21.003
  -2.400   0.000   3.490   0.000  -0.667 -21.219
  -2.400   0.000   3.500   0.000   0.000 -21.416
  -2.400   0.000   3.510   0.000   0.679 -21.594
  -2.400   0.000   3.520   0.000   1.368 -21.751
  -2.400   0.000   3.530   0.000   2.069 -21.888
  -2.400   0.000   3.540   0.000   2.780 -22.004
  -2.400   0.000   3.550   0.000   3.500 -22.099
  -2.400   0.000   3.560   0.000   4.229 -22.171
  -2.400   0.000   3.570   0.000   4.967 -22.221
  -2.400   0.000   3.580   0.000   5.712 -22.248
  -2.400   0.000   3.590   0.000   6.465 -22.252
  -2.400   0.000   3.600   0.000   7.223 -22.231
  -2.400   0.000   3.610   0.000   7.988 -22.187
  -2.400   0.000   3.620   0.000   8.757 -22.118
  -2.400   0.000   3.630   0.000   9.531 -22.024
  -2.400   0.000   3.640   0.000  10.308 -21.905
  -2.400   0.000   3.650   0.000  11.087 -21.760
  -2.400   0.000   3.660   0.000  11.869 -21.589
  -2.400   0.000   3.670   0.000  12.651 -21.392
  -2.400   0.000   3.680   0.000  13.434 -21.168
  -2.400   0.000   3.690   0.000  14.216 -20.918
  -2.400   0.000   3.700   0.000  14.997 -20.641
  -2.400   0.000   3.710   0.000  15.775 -20.337
  -2.400   0.000   3.720   0.000  16.551 -20.006
  -2.400   0.000   3.730   0.000  17.322 -19.648
  -2.400   0.000   3.740   0.000  18.088 -19.262
  -2.400   0.000   3.750   0.000  18.849 -18.849
  -2.400   0.000   3.760   0.000  19.602 -18.408
  -2.400   0.000   3.770   0.000  20.348 -17.939
  -2.400   0.000   3.780   0.000  21.085 -17.443
  -2.400   0.000   3.790   0.000  21.813 -16.920
  -2.400   0.000   3.800   0.000  22.530 -16.369
  -2.400   0.000   3.810   0.000  23.236 -15.791
  -2.400   0.000   3.820   0.000  23.929 -15.186
  -2.400   0.000   3.830   0.000  24.608 -14.553
  -2.400   0.000   3.840   0.000  25.274 -13.894
  -2.400   0.000   3.850   0.000  25.924 -13.209
  -2.400   0.000   3.860   0.000  26.557 -12.497
  -2.400   0.000   3.870   0.000  27.173 -11.759
  -2.400   0.000   3.880   0.000  27.771 -10.995
  -2.400   0.000   3.890   0.000  28.350 -10.207
  -2.400   0.000   3.900   0.000  28.909  -9.393
  -2.400   0.000   3.910   0.000  29.446  -8.555
  -2.400   0.000   3.920   0.000  29.962  -7.693
  -2.400   0.000   3.930   0.000  30.454  -6.807
  -2.400   0.000   3.940   0.000  30.922  -5.899
  -2.400   0.000   3.950   0.000  31.366  -4.968
  -2.400   0.000   3.960   0.000  31.783  -4.015
  -2.400   0.000   3.970   0.000  32.174  -3.041
  -2.400   0.000   3.980   0.000  32.537  -2.047
  -2.400   0.000   3.990   0.000  32.872  -1.033
  -2.400   0.000   4.000   0.000  33.178   0.000


Regards,

Steve N.

HSE

Quote from: daydreamer on August 01, 2022, 01:22:34 AM

.data
align 16
numbers real4 -2.4,-2.3,-2.1,-2.5
result real4 0.0,0.0,0.0,0.0
.code
mov ecx,1000000/4 ;1/4 for packed loop,1/1 for scalar loop
@@L1:
movaps xmm0,numbers
movaps xmm1,xmm0

mulps xmm0,xmm1;x^2
mulps xmm0,xmm1;x^3
mulps xmm0,xmm1;x^4
movaps result,xmm0
sub ecx,1
jne @@L1


      33.18      27.98      19.45      39.06

Press any key to continue...


:thumbsup:


Now -2.4^3.99  :biggrin:
Equations in Assembly: SmplMath

daydreamer

Quote from: HSE on August 01, 2022, 04:31:47 AM
Quote from: daydreamer on August 01, 2022, 01:22:34 AM

.data
align 16
numbers real4 -2.4,-2.3,-2.1,-2.5
result real4 0.0,0.0,0.0,0.0
.code
mov ecx,1000000/4 ;1/4 for packed loop,1/1 for scalar loop
@@L1:
movaps xmm0,numbers
movaps xmm1,xmm0

mulps xmm0,xmm1;x^2
mulps xmm0,xmm1;x^3
mulps xmm0,xmm1;x^4
movaps result,xmm0
sub ecx,1
jne @@L1


      33.18      27.98      19.45      39.06

Press any key to continue...


:thumbsup:


Now -2.4^3.99  :biggrin:
thanks Hector :thumbsup:
something similar to taylor series e^x maybe?
e^x=1+x+x^2/2!+x^3/3!+x^4/4!...

64bit might be worth it to check caps for avx 256bit SIMD
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

NoCforMe

Sorry, JK, to take this discussion away from the practical problem you asked about. But the issues raised here demand discussion and clarification.

There's a lot of what seems to be outright misinformation floating around here, concerning the sign of the result of exponentiation and the issue of complex numbers.

"FORTRANS" said:
QuoteI disagree, a negative number to a non integer exponent will normally require complex numbers to be accurate.

This goes against everything I ever learned about math. Whether the exponent is an integer or not makes no difference to the result. Why would it?  Exponentiation operates on any real numbers, integer or not. And it certainly does not introduce complex numbers to the equation.

To review, a complex number is defined by i = sqrt (-1). Since we're not taking the square root of negative numbers, no complex numbers.

And I have to take extreme issue with something JJ mentioned up there, which was that someone in the Intertubes had apparently "redefined" mathematics to declare that multiplying a negative number by a negative number yielded ... a negative number! (If I'm stating the case correctly: please correct me if I'm wrong.) This is just wrong, wrong, wrong, wrong, wrong! A negative number multiplied by a negative number always yields a positive number. And you can't just "declare" a "new paradigm" or whatever.
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on August 01, 2022, 05:07:16 AMa complex number is defined by i = sqrt (-1). Since we're not taking the square root of negative numbers, no complex numbers.

Sure? i = (-1)^0.5 :cool:

QuoteAnd I have to take extreme issue with something JJ mentioned up there, which was that someone in the Intertubes had apparently "redefined" mathematics to declare that multiplying a negative number by a negative number yielded ... a negative number!

Hmmmm... so what is (-2.4)^1.8? Is that multiplying a negative number by a negative number, or is it "something else"?

avcaballero

I'd say that

(-2.4)^3.999 = (-2.4)^(4-0.001) = (-2.4)^4/(-2.4)^0.001 = (-2.4)^4/((-2.4)^(1/1000)) = (-2.4)^4 / (sqr(1000)(-2.4))

Since 1000 is an even number, sqr(1000)(-2.4) is not real, but complex, hence (-2.4)^3.999 cannot be represented by a real number.

Bear in mind that sqr(3)(-1) = -1 because (-1)*(-1)*(-1) = -1, but sqr(2)(-1) = i, imaginary number.


In the case of (2.4)^3.999 = (2.4)^4 / (sqr(1000)(2.4)) = 33,1776 / 1,0008758520719666033451730665834 = 33,148566759121300335443929072659


Ie, a^(b/c) can only be calculated (as a real number) when sqr(c)(a) is a real number <=> c is an odd number, which is not the case of 1000


BTW: (-1)^0.5 = (-1)^(1/2) = sqrt(-1) = i

NoCforMe

Quote from: jj2007 on August 01, 2022, 05:36:32 AM
Quote from: NoCforMe on August 01, 2022, 05:07:16 AMa complex number is defined by i = sqrt (-1). Since we're not taking the square root of negative numbers, no complex numbers.

Sure? i = (-1)^0.5 :cool:

Yes I'm sure; that's just a restatement of "square root" (the 1/2 power).
Quote

QuoteAnd I have to take extreme issue with something JJ mentioned up there, which was that someone in the Intertubes had apparently "redefined" mathematics to declare that multiplying a negative number by a negative number yielded ... a negative number!

Hmmmm... so what is (-2.4)^1.8? Is that multiplying a negative number by a negative number, or is it "something else"?

I would say that this function "breaks" at integer values:

-x^1: negative
-x^2: positive
-x^3: negative
-x^4: positive, etc.

So for exponent values between 1 and 2, the result would be negative. For values between 2 and 3, positive, etc.

I think ...
Assembly language programming should be fun. That's why I do it.

NoCforMe

Quote from: caballero on August 01, 2022, 05:51:58 AM
I'd say that

(-2.4)^3.999 = (-2.4)^(4-0.001) = (-2.4)^4/(-2.4)^0.001 = (-2.4)^4/((-2.4)^(1/1000)) = (-2.4)^4 / (sqr(1000)(-2.4))

Since 1000 is an even number, sqr(1000)(-2.4) is not real, but complex, hence (-2.4)^3.999 cannot be represented by a real number.

Again, no. How do you get complex numbers out of this? We're not taking (even) roots of negative numbers, so there are no complex numbers.

Please explain how you arrive at this conclusion, that goes against everything I know about math.
Assembly language programming should be fun. That's why I do it.

JK

Please stop arguing, it´s me who is to blame for forgetting some basics of exponentiation

After some research, i found this one (https://www.rhetos.de/html/lex/gebrochener_exponent.htm), which puts it short and nice and easy to understand. Unfortunately it´s in German, but the diagram on the right side is all you need. Translation of the text in this diagram: (a must be a real number)
Quotea > 0

m must be an integer
n must be a natural number (integer > 0)

a < 0

m must be an integer
n must be a natural uneven number (integer > 0, e.g. 1,3,5,7,...)
the fraction m/n must be shortened as far as possible

So, this means for positve numbers there is no restriction, for negative numbers, it depends...
It depends on the exponent, for some exponents we will get a valid real result, for some other exponents the result is undefined in the range of real number. In fact you need complex numbers. E.g (-2)^0.5 (radix of minus 2), which is undefined in the range of real numbers.

There is no problem for negative numbers and integer exponents, fractional or real exponents might work or might not work (as described above) - this isn´t going to make coding easier  :sad: 

JK

HSE

Quote from: jj2007 on July 31, 2022, 08:58:38 AM
Windows calculator:
-2.4^3.999999999999= -33.1776
-2.4^4= +33.1776


Entering -2.4^ 3.999999999999 in Windows calculator result in "Entrada no válida"

You have to enter 2.4 and make it negative with "+/-"  :thumbsup:

Equations in Assembly: SmplMath

avcaballero

> How do you get complex numbers out of this?

Are nth roots of unity familiar to you?

https://en.wikipedia.org/wiki/Root_of_unity


The complex plane is basically R2. The real roots are those that rest on the abscissa axis, where the real values are. The one on the ordinates is for the imaginary part.

Obviously, sqr(1000)(-2.4) is not a real number. Therefore, we are dealing with a complex number and, therefore, not representable on the real line.


sqrt(-1) = i,  sqrt(-2) = sqrt(2*(-1)) = sqrt(2)*sqrt(-1) = sqrt(2)*i


FORTRANS

Quote from: NoCforMe on August 01, 2022, 05:07:16 AM

"FORTRANS" said:
QuoteI disagree, a negative number to a non integer exponent will normally require complex numbers to be accurate.

This goes against everything I ever learned about math. Whether the exponent is an integer or not makes no difference to the result. Why would it?  Exponentiation operates on any real numbers, integer or not. And it certainly does not introduce complex numbers to the equation.

To review, a complex number is defined by i = sqrt (-1). Since we're not taking the square root of negative numbers, no complex numbers.

   If you look at the numbers in Reply #31 that I posted and look
for the line with -2.400^3.500.  -2.4 can be factored to (2.4)*(-1).
The exponent is 3.500, which can be factored to (7)*(1/2).  Take
the square root of -1 and raise it to the seventh power.  You get i^7,
which is -i.  Take the square root of 2.4 and raise it to the seventh
power and you get 21.41604+.  Multiply those and you get -21.416i
as shown.

   caballero in Reply #27 pointed out that "a^(m/n)"..."is defined for
when the nth root of a is real number."  Arbitrary fractions as an
exponent rarely works that way with negative numbers.

Steve N.

P.S.
   Further posts while I was composing this make this simplistic maybe?
SRN

avcaballero

> Arbitrary fractions as an exponent rarely works that way with negative numbers

Maybe not so, there are infinite numerable odd numbers.

a^(b/(2n+1)) where n is a natural number, 2n+1 is always odd.

NoCforMe

Quote from: JK on August 01, 2022, 06:07:42 AM
So, this means for positve numbers there is no restriction, for negative numbers, it depends...
It depends on the exponent, for some exponents we will get a valid real result, for some other exponents the result is undefined in the range of real number. In fact you need complex numbers. E.g (-2)^0.5 (radix of minus 2), which is undefined in the range of real numbers.

OK, now we seem to be getting somewhere.

So what is the test of which exponents yield a valid (i.e., real) result and which don't? Or is it not so simple?
Assembly language programming should be fun. That's why I do it.