Post Reply 
erfi, erfw (w(z)) functions
11-01-2017, 06:03 PM
Post: #1
erfi, erfw (w(z)) functions
hi everybody,
Luckily Prime has inside its CAS two useful functions to magare problems connected to error treatment and statistics: the error function, erf() and the complementary error function, erfc().

If one want to "complete" that series, could think to implement also other two "sisters": the imaginary error function, erfi() and a function that I call "erfw", otherwise w(z) that handles every complex number.
See here for theory.

The code:
erfi()
Code:

#cas
erfi(x):=
return -i*erf(i*x)
#end

erfw()
Code:

// complex error function
#cas
erfw(x):=
return (e^-(x^2))*erfc(-i*x)
#end

Enjoy with the Prime!

Salvo Micciché

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
08-22-2020, 04:10 PM (This post was last modified: 07-21-2021 10:53 AM by Albert Chan.)
Post: #2
RE: erfi, erfw (w(z)) functions
A mnemonic I find useful
swap -1 and i, and swap the function (erf ↔ erfi, sin ↔ sinh, cos ↔ cosh, tan ↔ tanh)

Code:
erf (-x) = - erf(x)    → erf (ix) = i erfi(x)
erfi(-x) = - erfi(x)   → erfi(ix) = i erf(x)

sin (-x) = - sin(x)    → sin (ix) = i sinh(x)
sinh(-x) = - sinh(x)   → sinh(ix) = i sin(x)

cos (-x) =   cos(x)    → cos (ix) =   cosh(x)
cosh(-x) =   cosh(x)   → cosh(ix) =   cos(x)

tan (-x) = - tan(x)    → tan (ix) = i tanh(x)
tanh(-x) = - tanh(x)   → tanh(ix) = i tan(x)

Update: we could replace i by 1/i, and get a new set of identities

cosh(x) = cos(i*x) = cos(-i*x) = cos(x/i)
atan(x) = atanh(ix)/i = atanh(-ix)/(-i) = atanh(x/i)*i
...

Update2: A better mnemonic maybe to turn function even

sin(x)/x = sinh(±i*x)/(±i*x) = 1 − x^2/6 + x^4/120 − ...
sinh(x)/x = sin(±i*x)/(±i*x) = 1 + x^2/6 + x^4/120 + ...
Find all posts by this user
Quote this message in a reply
09-03-2021, 10:39 AM
Post: #3
RE: erfi, erfw (w(z)) functions
For odd functions (erf ↔ erfi, sin ↔ sinh, tan ↔ tanh, and their inverse), we can swap the parts.

Let swap(x + y*i) = y + x*i

sinh(z) = swap(sin(swap(z)))
sin(z) = swap(sinh(swap(z)))
...

>>> from cmath import *
>>> sin(3+4j)
(3.8537380379193773-27.016813258003932j)
>>> sinh(4+3j)
(-27.016813258003932+3.8537380379193773j)

This is easier to remember, without worrying signs of ×/÷ i
Code is likely simpler, since ×/÷ i is usually implemented by swap parts, then fix sign.

From HP-71B cpr.a, http://www.jeffcalc.hp41.eu/emu71/mathrom.html
Code:
* ************************
* mpyi
* multiply (x,y) in (A,B) (R0,R1) by i
* i*(x+i*y)=-y+i*x
* result is (-y,x)
m733F
mpyi    GOSUB  Exab1  m734B    swap x<>y
        A=-A-1 S               negate y
        RTN

* ************************
* mpymi
* multiply (x,y) in (A,B) (R0,R1) by -i
* -i*(x+i*y)=y-i*x
* result is (y,-x)
m7348
mpymi   A=-A-1 S               negate x
m734B
Exab1   GOLONG exab1  m76D7    swap x<>y

Proof is trivial, since swap(z) = i*conj(z)

sinh(z) = sin(i*z) / i
conj(sinh(z)) = sinh(conj(z)) = sin(i*conj(z)) / i

Multiply-by-i, and replace i*conj() by swap()

swap(sinh(z)) = sin(swap(z))
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)