• Welcome to the new Internet Infidels Discussion Board, formerly Talk Freethought.

Python

I did a lot of searching, and I found out How does C compute sin() and other math functions? - Stack Overflow

That led me to sourceware.org Git - glibc.git/tree - sysdeps/ieee754/dbl-64/

The source code was hard for me to interpret, but I recognized the use of Taylor series in various places. It could have used a *lot* of comments to give an overall picture of what is going on it it.

sourceware.org Git - glibc.git/tree - math/ - look at files names s_c<function>_template.c

sourceware.org Git - glibc.git/blob - math/s_cexp_template.c - has the algorithm that one would expect:

\( e^{x + i y} = e^x \cos y + i e^x \sin y \)

Similarly for the other complex math functions.
 
The source code was hard for me to interpret, but I recognized the use of Taylor series in various places
Taylor series is used only for very small angles. For the bulk of argument tables are used.
Tables?

Indeed it uses tables for some trig-function values, and finds in-between values with those values and with Taylor-series values, using trigonometric addition identities to combine them.
 
And strictly speaking all operation use tables in practice, multiplication-division, even addition-subtraction.
 
Last edited:
Phasors. The utility of the exponential form and the identity is multiplying and dividing vectors without the messy arithmetic in rectangular form.
Phasors are not about what you think they are about.
I am stunned.
Vector multiplication normally understood as cross-product of two vectors in 3 dimensional space, has nothing to do with "phasors"
phasors are not really vectors, even though they are represented as vectors in 2d space,
They are complex numbers, or 2x2 matrices of special form over real numbers.
 
Demonstrate how logarithms are used with scalars instead of complex numbers. Converting multiplication and division to addition and subtraction.


# 2*3 and 2/3 using base e logs
x = math.log(2)
y = math.log(3)
zm = x + y #multiply x * y
zd = x - y #divide x / y
print(pow(math.e,zm))
print(pow(math.e,zd))


5.999999999999999
0.6666666666666666
You do realize that in order to calculate logarithm/exponent you will need an actual multiplication/division?
Have no idea what you mean.

Using logarithms to multiply and divide is as old as the hills learned it in high school, it is how slide rules worked.

There used to be books of tables of logarithms, random nu,mbers, and trig functions. Replaced first by scientific calculators then PCs.

In high school and Navy technical schools I used a slide rule. They are based on logarithms.

I read numerical methods books in the 80s as background information. It all reduces to series solutions or other approximations.

Arithmetic operations on complex numbers are defined. Anyone in electronics even at technician level know how to do it by hand.

{\displaystyle e^{ix}=\cos x+i\sin x}


When expressed as an exponential complex numbers can be multiplied and divided in accordance with the laws of exponents.

What is e^2 * e^3 = ?


z1 = 1 + i2
z2 = 3 + 4i
z3 = z1 * z2

hwat is the magbitde and phase of z3?
 
Phasors. The utility of the exponential form and the identity is multiplying and dividing vectors without the messy arithmetic in rectangular form.
Phasors are not about what you think they are about.
I am stunned.
Vector multiplication normally understood as cross-product of two vectors in 3 dimensional space, has nothing to do with "phasors"
phasors are not really vectors, even though they are represented as vectors in 2d space,
They are complex numbers, or 2x2 matrices of special form over real numbers.
Phasors are rotating vectors. Commonly used in elecrtoncs and rotating mechanicall systems.



You seem to be quoting from from the net withiut experience and compresion.

A scalar has nagbitude but no direction. 10 apples is a scaler. A vector has both magnitide and directon.

Force is a vector, magntide and direcion.

Ploted on a unit circle comex numers are vectors.

z = 1 + 1i


Magnite is sqrt(1^2 + 1^2) = sqrt(2)
Phase(or direction of the vector) = atan(1/1) = 45 dehgrees

Look for a pdf on the net on 'mechanucs statics' if you want to learn vectors.

For vectors appied to l;ectromagnetcs I posted a link to a pdf of a book Engineering Electromagetcs' on the natural science forum.
 
Phasors are rotating vectors. Commonly used in elecrtoncs and rotating mechanicall systems.
Yeah, I learned them in High School. They were not called phasors in Russia and to my knowledge are NOT used in rotating mechanical systems.
You seem to be quoting from from the net withiut experience and compresion.
Dude, I have PhD in physics.
It is you who is coping shit from the net without experience.
 
Dude, I have PhD in physics.
See, I used to just take your word for this. But then I read your comments about the Russian invasion of Ukraine, and now I just assume that nothing you post here is reliable or factual at all.

So now I am highly skeptical even of this mundane claim, which I previously accepted without question.

The sad fact is that trust takes a long time to earn, but can be destroyed in an instant, and you have ceased to be a trustworthy source in my opinion. I am no longer even confident that you are a single individual, and not a team of propagandists.
 
blby, mistrust is mutual. I know for the fact that I am right and you are wrong and just trolling here.
 
Python has the error function but not the inverse error function.


A table of 1000 precalculated series coefficients were created in C and imported to Python. Runs faster. See the series solution to the inverse error function in the link.

Code:
int coefpy(void){

    int ind = 0,i,j,k,m,nc = 1000;
    double c[nc];
    for(k=0;k<nc;k++)c[k] = 0;
     c[0] = 1;
     for(k=1;k<nc;k++)
        for(m=0;m<k;m++)
            c[k]+= (c[m]*c[k-1-m])/((m+1)*(2*m + 1));

    FILE *p = fopen("coef.py","w");
    fprintf(p,"c = [\n");
    for(j=0;j<nc-1;j++){
            fprintf(p,"%20.4f,\n",c[j]);
            }
    fprintf(p,"%20.4f]",c[nc-1]);
    fclose(p);
    cout<<"done  "<<ind<<endl;
    return 0;
}


Code:
# erf
import math as ma
import cmath as cm
import coef  #table of coefficients
import random as rn
import statistics as st

def ierf(x):
    nc = 1000
    c = n*[0]
    q = ma.sqrt(ma.pi)*x/2.
    einv = 0
    
##    c[0] = 1
##    for k in range(nc):
##        for m in range(k):
##            c[k] += (c[m]*c[k-1-m])/((m+1)*(2*m + 1))

    for k in range(nc):
        einv += ((coef.c[k])/(2*k+1))*pow(q,(2*k+1))
    return einv

# testing ierf()
n = 21
x = n*[0]
y = n*[0]
yi = n*[0]

 
dx = .1
xsum = -1.
for i in range(n):
        x[i] = xsum
        y[i] = ma.erf(xsum)
        yi[i] = ierf(y[i])
        xsum += dx

for i in range(n):
    print("%3.8f    %3.8f   %3.8f" %(x[i],y[i],yi[i]))

Code:
To test ierf(),  as an inverse erf(ierf(x) = x

x,  erf(x),   ierf(x) 
-1.00000000    -0.84270079   -1.00000119
-0.90000000    -0.79690821   -0.90000094
-0.80000000    -0.74210096   -0.80000068
-0.70000000    -0.67780119   -0.70000045
-0.60000000    -0.60385609   -0.60000026
-0.50000000    -0.52049988   -0.50000013
-0.40000000    -0.42839236   -0.40000005
-0.30000000    -0.32862676   -0.30000001
-0.20000000    -0.22270259   -0.20000000
-0.10000000    -0.11246292   -0.10000000
-0.00000000    -0.00000000   -0.00000000
0.10000000       0.11246292    0.10000000
0.20000000       0.22270259    0.20000000
0.30000000       0.32862676    0.30000001
0.40000000       0.42839236    0.40000005
0.50000000       0.52049988    0.50000013
0.60000000       0.60385609    0.60000026
0.70000000       0.67780119    0.70000045
0.80000000       0.74210096    0.80000068
0.90000000       0.79690821    0.90000094
1.00000000       0.84270079    1.00000119



One use of the inverse error function is to generate a random normal distribution with mean u and standard deviation sigma. The quartile function of the distribution.


Code:
# testing normal distribution generator

def norm_dist(n,y,u,sigma):
   for i in range(n):
        k = ma.sqrt(2)*sigma
        # p>0, <1
        p = 0
        while(p == 0):
            p = rn.random()
        p = 2.*p-1.;
        y[i] = u + ierf(p)*k # quantile from link

nr = 1000
yn = nr*[0]
u = 100
sigma = 20
norm_dist(nr,yn,u,sigma)
av = st. mean(yn)
mx = max(yn)
mn = min(yn)
sp = (mx-mn)/sigma



md = st.median(yn)
sd = st.stdev(yn)
print("target mean, stnd dev   ",u,"  ",sigma)
print("mean  ",av)
print("std dev  ", sd)
print("median  ",md)
print("data spead in  standard deviations   ", sp)

target mean, stand dev 100 20
Generated distribution values:
mean 100.94653703824117
std dev 20.505710939916575
median 101.5811817381178
data spread in standard deviations 6.542315406064051

The distribution spread from low to high values varies from 6 to 7 standard deviations. 6 standard deviations or 6 sigma is taken as approximate 99.999.. percent of the distribution.

It matches the Scilab normal distribution generator
 
Have no idea what you mean.
It means you can't use your method in computers, that is if your goal to somehow implement multiplication operation through logarithm.
HeeHee, I demonstrated it in Python.

Binary base2 math works the same ways as base10. For human level inputs and outputs base2 is converted to base10 representation and vice versa.

Computer digital computation 101, get yourself a book on numerical methods, many good ones. You won't pick it up from bits and pieces on the net. Same with what vectors are and the associated math.
 
Have no idea what you mean.
It means you can't use your method in computers, that is if your goal to somehow implement multiplication operation through logarithm.
HeeHee, I demonstrated it in Python.

Binary base2 math works the same ways as base10. For human level inputs and outputs base2 is converted to base10 representation and vice versa.

Computer digital computation 101, get yourself a book on numerical methods, many good ones. You won't pick it up from bits and pieces on the net. Same with what vectors are and the associated math.
Sorry man, you are talking utter nonsense.
 
Phasors are rotating vectors. Commonly used in elecrtoncs and rotating mechanicall systems.
Yeah, I learned them in High School. They were not called phasors in Russia and to my knowledge are NOT used in rotating mechanical systems.
You seem to be quoting from from the net withiut experience and compresion.
Dude, I have PhD in physics.
It is you who is coping shit from the net without experience.
I go by what you post. Authority from alleged academic credentials does not work with me.

A degree at any level just means you passed the classes and wrote a few papers. It says nothing about experience and comperension.

I certainly knew engineers who liked to spout theory but were useless.

Apparently you did not grasp the most basic definition of a vector, magnitude and direction. Cross and dot products apply vectors in certain situations.

Imagine 3 point charges fixed in 3 space. The force on any one charge is the vector sum of forces exerted by the other two. The magnitude of the force in Neatens on any one charge has a direction, the path the charge would take if it was not constrained. Electrostatics as opposed to elctrodynamics.

In mechanics statics is the study of the distubution of forces in a static mechanical structure. Dynamcs is mechancal oblects in motion. You can read Hartog's Mechanics I linked to on science. It dates from the 40s but I kept a copy at work as aefrfernce.

It is beyond me, above the commn 3d vectors are n dimensional tensors.

BTW, are you familiar with the right hand rule for cross products?


The direction of the cross product may be found by application of the right-hand rule as follows: The index finger points in the direction of the velocity vector v. The middle finger points in the direction of the magnetic field vector B. The thumb points in the direction of the cross product F.
 
I go by what you post.
I did not post much here to go by.
But you did. And I can safely say you are in no position to judge anything, let alone my credentials.
Let me dumb it down for you. You need to (at least) have my credentials to judge mine.
Apparently you did not grasp the most basic definition of a vector, magnitude and direction
Dude, I passed through General Relativity course. Can't say I was great at it , Professor was not any good, so I studied it afterwards (and before) by myself, to a certain degree of course.
So I think I have a good grasp of vectors. And I had a course of functions of complex variables as well in University. Learned these "phasors" in freaking High School. So please, shut the fuck up!
Complex numbers are not vectors. They are homomorphic to special matrices or better tensors. But I understand why people with less than basic knowledge might think they are vectors, after all they ARE represented by vectors on complex plane and can be added as vectors.
Multiplication however, has nothing in common with any vectors, instead it has everything in common with rotations which is what matrices are for!
So shut the fuck up!
 
Last edited:
Back
Top Bottom