• Back to MAIN


  • K4/Q displays (PART 2) from various fields of math, finance and physics

    47(a) Gauss Algorithm (real numbers, assuming no pivot = 0), L/R decomposition

    L::()
    k)f:{L::L,,l:(v:1_u)%c:*u:x[;0];+1_(+1_x)-l*/:*x}
    k)z:-1_1f {(+/(x*-1f*1_y)%*y),x}/|*:'u:(-1+#s) f\s
    /L,R decomposition
    k)L:+((!#w)#'0f),'w:1f,'L,,()
    k)R:((!#u)#'0f),'*:'u

    Example:

    16u - 11v + 39w - 10x + 17y = 2383
    29u - 19v + 66w - 90x - 111y = -16941
    -94u - 18v -101w + 65x - y = -3246
    35u - 36v + 37w - 38x + 19y = 3379
    -91u +108v - 47w + 99x - 97y = -9572

    s:0f+(16 -11 39 -10 17 -2383f;29 -19 66 90 -111 16941f;-94 18 -101 65 -1 3246f;35 -36 37 -38 19 -3379f;-91 108 -47 99 -97 9572f)

    returns solutions -84 18 44 -107 67f and L,R

    48(a) polynomial multiplication (with real coefficients)

    k)pm:{m:0f+x*\:y;{(x,0f)+(z#0f),y}/[*m;1_m;1+!-1+#x]}

    pm[2 0 -2 4;1 0 0 4 0 -3] .. 2 0 -2 12 0 -14 16 6 -12f

    (2x3 - 2x + 4)(x5 + 4x2 - 3) = 2x8-2x6+12x5-14x3+16x2+6x-12

    49(a) polynomial division (with real coefficients)

    f1:{(q;x-y*q:(first x)%first y)};pdiv:{s,:first r:f1[0f+x;0f+p2];(1_last r),0f+y}
    k)s:`float$();pdiv2:{l:#y;-1_(l#x) pdiv/ l_x,0}

    Sample A ........................................... :

    p1:6 -6 -7 145 -317 308 -344 187f
    p2:2 -6 17 -11
    s:`float$();pdiv2[p1;p2] .. 0 0 0 (no rest)

    s .. 3 6 -11 5 -17f
    ie

    (6x7 - 6x6 - 7x5 + 145x4 - 317x3 + 308x2 - 344x + 187) % (2x3 - 6x2 + 17x -11) = 3x4 + 6x3 - 11x2 + 5x - 17

    Sample B ........................................... :

    p1:4 3 8 6 -12
    p2:1 0 1
    s:`float$();pdiv2[p1;p2] .. 3 -16f (with rest) and s .. 4 3 4f

    ie

    (4x4 + 3x3 +8x2 + 6x - 12) % (x2 + 1) = 4x2 + 3x + 4 .. with REST 3x - 16

    50 Tower of Hanoi .. just a playful K-way

    d:{(~x~e) & (y~e)|(*x)<*y}
    /move right
    mr:{((1_x);(*x),y)}
    /move left
    ml:{(((*y),x);1_y)}
    /function field: move left, move right , no move
    m:(ml,mr,{x;y})

    o:(0 1;0 2;1 2)
    k:0

    s:(,1 2 3 4 5 6),a:(e;e:`int$())

    /for an even number of discs only ..
    th:{k+:1;x {@[x;y;:;(m@(2*a~j)+"i"$d . j) . j:x@y]}/ o}

    k:0;r:21 th\ s

    /PS: for an odd number of discs the number of solutions is not 0 modulo 3


    r ...

    left middle right comment
    1 2 3 4 5 6 `int$() `int$() initial state
    3 4 5 6 `int$() 1 2 step 3
    1 4 5 6 2 3 `int$() step 6
    5 6 2 3 1 4 step 9
    1 2 5 6 `int$() 3 4 step 12
    5 6 `int$() 1 2 3 4 step 15
    5 6 `int$() 1 2 3 4 step 15
    1 6 2 5 3 4 step 18
    3 6 2 5 1 4 step 21
    1 2 3 6 4 5 `int$() step 24
    3 6 4 5 1 2 step 27
    1 6 2 3 4 5 `int$() step 30
    `int$() 2 3 4 5 1 6 step 33
    1 2 4 5 3 6 step 36
    `int$() 4 5 1 2 3 6 step 39
    1 4 2 5 3 6 step 42
    3 4 2 5 1 6 step 45
    1 2 3 4 `int$() 5 6 step 48
    3 4 `int$() 1 2 5 6 step 51
    1 4 2 3 5 6 step 54
    `int$() 2 3 1 4 5 6 step 57
    1 2 `int$() 3 4 5 6 step 60
    `int$() `int$() 1 2 3 4 5 6 step 63


    51 Power Series ... some thoughts

    Let be z a complex number. A power series (PSE) is a sum of the form: Σnan(z-z0)n and n ≥ 0. If this sum is converging for any z = ζ then this convergence is absolute for all z satisfying |z - z0| < |ζ - z0|. Any an(z-z0)n is an analytic function and the sum of analytic funtions is also analytic. Using Cauchy's integral formula: 2πi×f(α) = ∫C f(z)/(z - α) dz we can show that our power series is the Taylor series expansion of f(z) around z0.

    One nice example: f(z) = 1/(1 - z) → f(N-1)(z) = (N-1)!/(1-z)N (we are looking for a PSE around z = 0)

    As f(z) = 1 + z + z2 + z3 + ... + zN-2 + zN-1 + zN + zN+1 + ... + zM. Its (N-1)th derivative has the following coefficients:

    (N-1) - (N-1) for z0: (N-1)!
    (N-0) - (N-1) for z1: N!/1!
    (N+1) - (N-1) for z2:(N+1)!/2!
    (N+2) - (N-1) for z3:(N+2)!/3!

    For zn must hold: M - (N-1) = n → M = N + n - 1

    In other words:

    (1 - z)-N = Σnanzn and where an = (N + n - 1)!/[(N - 1)! n!] .. in other words we bypassed the binomial theorem

    Power series multiplication Σnbnzn × Σncnzn = Σnanzn follows a simple pattern: Σnanzn and where ak = Σ0 ≤ s ≤ k bscs-k
    A possible k4 expression:
    powerm:{+/'(x@r)*y@|:'r:(1+s)#\:s:!z}

    Example 1:

    f(z) = ez cos z ... up to grade 4:

    powerm[p1;p2;5] ... 1 1 0 -0.3333333 -0.1666667 i.e. 1 + z - z3/3 - z4/6
    ... and where p1:1 1 0.5 0.1666667 0.04166667 and p2 = 1 0 -0.5 0 0.04166667

    The process can be inverted .. P1(z) / P2(z) ... power series division

    A possible k4 expression:
    {(u*y-+/x*(#x)#1_b),x}/[(*a)%e;1_a] ... and where u:%e:*b

    a corresponds to the factors of P1(z), b corresponds to the factors of P2(z)


    Example 2:

    f(z) = ez / cosh z ... up to grade 5:

    -6#{(u*y-+/x*(#x)#1_b),x}/[(*a)%e;1_a]
    /b:(7#1 0)*a:1f,%*\1_!7

    ... returns: 0.1333333 0 -0.3333333 0 1 1 ... in other words the (1st 6 terms) Maclaurin expansion of f(z) yields f(z) ∼ 1 + z - z3/3 - 2z5/15 and |z| < 1


    Example 3:

    f(z) = z / (ez - 1)

    .. leads to one fundamental definition of the Bernoulli numbers Bn we ran into earlier:
    f(z) = Σ (Bn / n!) zn and because f(z) + 0.5z = 0.5z · coth z/2 it follows that B2n+1 = 0 ∀ n > 0.
    b:%s:*\1_!20
    a:1f,18#0.0
    flat'(1,-1_s)*|{(u*y-+/x*(#x)#1_b),x}/[1f;1_a] ... 1 -0.5 0.1666667 0 -0.03333333 0 0.02380952 0 -0.03333333 0 0.07575758 0 -0.2531136 0 1.166667 0 -7.092157 0 54.97118

    So, B16 = -7.092157 and B18 = 54.97118 ... Note: |z| < sqrt (|B16 / B18|(18 * 17)) ~ 6.283221 is very close to 2π, and indeed, the series Σ (Bn / n!) zn is converging for |z| < 2π
    (flat:{$[1e-011>abs x;:0f;:x]} is just a decorative utility) .. Be aware that lim f(z) for z → 1 exists ... and 0 is a removable singularity, however 2πi is a real (and next) singularity, therefore we can optimistically confirm |z| < 2π


    Example 4:

    g(z) = 1 / cosh z

    .. leads to one fundamental definition of the Euler numbers En: .. g(z) = Σ (En / n!) zn
    c:(#b:1f,%s:*\1_!20)#1 0
    b*:c;a:1f,18#0.0
    flat'(1,-1_s)*|{(u*y-+/x*(#x)#1_b),x}/[1f;1_a] ... 1 0 -1 0 5 0 -61 0 1385 0 -50521 0 2702765 0 -1.99361e+008 0 1.939151e+010 0 -2.40488e+012

    So, E16 = 1.939151e+010 and E18 = -2.40488e+012 ... Note: |z| < sqrt (|E16 / E18|(18 * 17)) ~ 1.570796 is very close to π/2, and indeed, the series Σ (En / n!) zn is converging for |z| < π/2


    .. .. to be continued .. ..

  • Back to MAIN



  • ©++ MILAN ONDRUS