block({ include(`complex-prg.txt'): let(complexpi,4*atan(1)): func(realoddroot,{sgn([x])*(abs([x])^(1/[y]))}): print_`Real powers and complex functions\n\n': print_`1. Non-integer powers with positive real bases\n': print_`9^0.5 = ' (9^0.5) `\n': print_`2^1.5 = ' (2^1.5) `\n': print_`27^(1/3) = ' (27^(1/3)) `\n': print_`These calculations have real results and use ordinary floating point.\n\n': print_`2. Complex representation and arithmetic\n': print_` represents a + b*i; I from the module is <0,1>.\n': let(z,<3,4>): let(w,<1,-2>): print_`z = ' [z] `\n': print_`w = ' [w] `\n': print_`z + w = ' cadd([z],[w]) `\n': print_`z - w = ' csub([z],[w]) `\n': print_`z * w = ' cmul([z],[w]) `\n': print_`z / w = ' cdiv([z],[w]) `\n': print_`conjugate(z) = ' conj([z]) `\n': print_`abs(z) = ' cmag([z]) `\n': print_`i*i = ' cmul([I],[I]) `\n': print_`Vector *, / and ^ act componentwise. Use cmul, cdiv and cpow for complex arithmetic.\n\n': print_`3. Polar coordinates\n': print_`cpol(z) returns ; angles are in radians.\n': print_`cpol(<3,4>) = ' cpol([z]) `\n': print_`pcart(cpol(z)) = ' pcart(cpol([z])) `\n\n': print_`4. Fractional powers of negative real numbers\n': print_`Scalar (-4)^0.5 raises an error; it does not promote to complex arithmetic.\n': print_`cpow(<-4,0>,0.5) = ' cpow(<-4,0>,0.5) `\n': print_`csqrt(<-1,0>) = ' csqrt(<-1,0>) `\n': print_`cpow(z,p) uses a real exponent and the principal angle of z.\n': print_`Principal cube root of -8 = ' cpow(<-8,0>,1/3) `\n': print_`Real cube root of -8 = ' quote(realoddroot(-8,3)) `\n': print_`realoddroot(x,n) assumes a positive odd integer n.\n': print_`A negative real number can have a real odd root as well as other complex roots.\n\n': print_`5. Enumerating roots\n': print_`csqrt, croot and croots are provided by complex-prg.txt.\n': print_`croot(z,n,k) adds 2*pi*k to the angle before dividing by n.\n': print_`Use positive integer n and branch k from 0 to n-1.\n': print_`All cube roots of -8 = ' croots(<-8,0>,3) `\n': print_`All fourth roots of 1 = ' croots(<1,0>,4) `\n\n': print_`6. Complex exponents and logarithms\n': print_`cpow2(z,w) accepts a complex exponent w and returns a principal value.\n': print_`i^i = ' cpow2([I],[I]) `\n': print_`exp(-pi/2) = ' eul(-[complexpi]/2) `\n': print_`(2+3i)^(0.5-0.25i) = ' cpow2(<2,3>,<0.5,-0.25>) `\n': print_`clog(z) = ' clog([z]) `\n': print_`clog(<-1,0>) = ' clog(<-1,0>) `\n': print_`Logarithms and general powers in these examples use nonzero bases.\n\n': print_`7. Complex exponential and trigonometric functions\n': print_`cexp, csin, ccos and ctan are provided by complex-prg.txt.\n': print_`cexp() = exp(a)*\n': print_`exp(i*pi) = ' cexp(<0,[complexpi]>) `\n': print_`exp(log(z)) = ' cexp(clog([z])) `\n': print_`sin(i) = ' csin([I]) `\n': print_`cos(i) = ' ccos([I]) `\n': print_`tan(i) = ' ctan([I]) `\n': print_`cos(z)^2+sin(z)^2 = ' cadd(cmul(ccos([z]),ccos([z])),cmul(csin([z]),csin([z]))) `\n\n': print_`8. Differentiating a complex function\n': print_`cderiv(function,point,step) uses a centered finite difference.\n': print_`d(exp)/dz at i = ' cderiv(cexp,[I],<0.00001,0>) `\n': print_`exp(i) = ' cexp([I]) })