• Back to MAIN


  • K4 and Kdb+ are trademarks of Kx - Systems

    q command by sample .. last update 30-Aug-2011 21:17
    .Q locale(static).Q.a(lower alpha),.Q.A(upper alpha),.Q.n (digits),.Q.k (version)
    acosacos -1f .. 3.141593
    acot *nyi*acot:{acos x%sqrt 1+x*x}
    + [addition]4h+0xaabb .. 174 191,4h+9j .. 13j
    allall 11111b .. 1b
    and0011b and 1010b .. 0010b
    anyany 10001b .. 1b
    @ [apply]"denubolar "@4 6 7 0 1 9 8 3 2 2 1 8 .. "blade runner"
    arcosh *nyi*{log x+sqrt (x*x)-1f} where x >= 1 (see also under section "COMPLEX OPERATORS")
    arcoth *nyi*{0.5*log (x+1f)%x-1f} where |x| > 1 (see also under section "COMPLEX OPERATORS")
    arsinh *nyi*{log x+sqrt 1f+x*x} (see also under section "COMPLEX OPERATORS")
    artanh *nyi*{0.5*log (1f+x)%1f-x} where |x| < 1 (see also under section "COMPLEX OPERATORS")
    ascasc "cool" .. `s#"cloo"
    asin(180*asin 0.5)%acos -1f .. 30f
    association("silver"!0x0a114dab762e)@"liver" .. 0x4d11ab762e
    atan(acos -1f) ~4*atan 1 .. 1b (for arccot see `acot)
    avgavg 10 20 30 40 .. 25f
    bid/ask notation"F"$("1 19/64";"2 3/4") .. 1.296875 2.75
    bin7 8 9 10 11 12 13 19 bin 19 9 .. 7 2
    cast99^9 0 0n 0 7 0n 4f .. 9 0 99 0 7 99 4f
    @[f;x;msg] [catch]{@[{x+2};x;`error]} each (4;`4;"m";8j) .. (6;`error;`error;10j)
    protected file read: {@[read0;x;`unavailable]}@`:F.txt
    -3! character representation-3!(`karl`marx;4 3 2 1;001b) .. "(`karl`marx;4 3 2 1;001b)"
    commands\t .. timer
    \t f x .. time
    \P .. precision
    \p .. port (\p -n reset port)
    \ .. OS command
    \v .. variables
    \d .. dictionary
    \l .. load script
    \S .. random seed .. -314159 default
    \c .. console setting 25 x 80 (default)
    \C .. browser setting 36 x 2000 (default)
    \\ .. good bye
    $ [condition]$[1b;`right;`wrong] .. `right
    coscos (acos -1)%3 .. 0.5
    cosh *nyi*{0.5*(1%c)+c:exp neg x}
    countcount (`aa`bb;`cc`dd) .. 2
    cross`E1`E2`E3 cross `M1`M2 .. (`E1`M1;`E1`M2;`E2`M1;`E2`M2;`E3`M1;`E3`M2)
    csv","
    cut3 cut/:("delta";"airlines") .. (("del";"ta");("air";"lin";"es"))
    date arithmetics (m)2001.01m+key 6 .. 2001.01 2001.02 2001.03 2001.04 2001.05 2001.06m
    date arithmetics (m)2002.03m-2001.01m+key 6 .. 14 13 12 11 10 9
    date arithmetics (d)2006.01.20-til 5 .. 2006.01.20 2006.01.19 2006.01.18 2006.01.17 2006.01.16
    date arithmetics (d)2011.01.20-2006.01.20-til 5 .. 1826 1827 1828 1829 1830
    date arithmetics (ts)2006.01.22T21:06:22.062+1 .. 2006.01.23T21:06:22.062
    date arithmetics (ts)2006.01.22T21:06:23.062+1%86400000 .. 2006.01.22T21:06:23.063
    date projectionsr:2006.01.22T21:13:36.531
    r.date .. 2006.01.22
    r.week .. 2006.01.16
    r.time .. 21:13:36.531
    r.month .. 2006.01m
    r.minute .. 21:13
    r.second .. 21:13:36
    r.year .. 2006
    r.ss .. 36
    r.hh .. 21
    r.mm .. 1
    r.dd .. 22

    r:.z.Z
    `int$r.time mod 1000 .. reading the milliseconds
    `int$t.timestamp mod 1000000000 .. 2011.03.15D22:32:22.109921000 (micro-seconds)
    date casting (I)`hh`mm`ss$r.second .. 21 13 36
    date casting (II)`year`month`dd`week$r .. (2006;2006.01m;22;2006.01.16)
    date boundaries &
    date casting (III)
    9999.12.31-`date$.z.Z .. (`date$.z.Z)-1000.01.01
    date system command
    \z is 0(=default) or 1
    \z 1 .. "D"$("22/09/2009";"31/12/2000";"01/06/2008") .. returns 2009.09.22 2000.12.31 2008.06.01
    \z 0 "D"$("2009/09/22";"2000/12/31";"2008/06/01") or "D"$("2009-09-22";"2000-12-31";"2008-06-01") returns ..
    2009.09.22 2000.12.31 2008.06.01
    [delimiter suppression]
    by quote intervals
    show ("******";",") 0: enlist ("******";",") 0: enlist "Ian,Racz,\"Edmonton,Alberta\",Canada,\"114St,88Ave\",manager"
    Ian
    Racz
    Edmonton,Alberta
    Canada
    114St,88Ave
    manager
    deltasdeltas (til 5) xexp 2 .. 0 1 3 5 7f
    denormalizingflip exec (exec distinct n from T)#n!v by k from T.
    T:([n:`a`a`a`b`b`c`d;k:`m1`m2`m3`m1`m3`m2`m4] v:9 8 7 6 5 4 3)
    dependenciesTview :: T
    descdesc 1 5 5 7 6 3 3 .. 7 6 5 5 3 3 1 (desc "abcd" .. "dcba")
    dictionary a dictionary maps lists into lists:
    a:`list1`list2`list3!(`l`e`f`t;4 5 6 7;0101b)
    we can use the dot notation: a.list2:4 5 6 7
    creation of a Kdb+ table: T:flip a
    differdiffer 1 5 5 7 6 3 3 .. 1101110b
    distinctdistinct "mississippi" .. "misp"
    divinteger part of a division .. 19 div' 4 6 7 8 .. 4 3 2 2
    j div i .. (j can be 64-bit integer) example: 87726636552j div 873 .. 100488701j
    dodo[n;..;..;]
    _ [drop]-4 _ "applegate" .. "apple"
    encryptionmd5 "birdflu" .. 0x3292dfabfffba27383d72cab3c4413b5
    enlistenlist 6 .. ,6
    = [equal]`cb=`cx`cs`cb`cbb .. 0010b
    except"icewater" except "weird" .. "cat"
    expexp til 5 .. 1 2.718282 7.389056 20.08554 54.59815
    fillsfills "mis is ip i" .. "mississippi"
    ? [find first]"Czechoslovakia"?"o" .. 5
    firstfirst "miami" .. "m"
    flipflip (`aa`bb;`cc`dd) .. (`aa`cc;`bb`dd)
    floorfloor 2.77 3.99 -3.99 .. 2 3 -4 (integer again)
    $ [formats][a] IP address to decimal.. "I"$"10.23.23.11" .. 169285387
    [b]"Z"$"20060303-10:13:59.099" unix timestamp to q .. 2006.03.03T10:13:59.099
    [c]"I*c"$(("34";"88";"299");("mao";"tse";"tung");0x4a4b4c) .. (34 88 299;("mao";"tse";"tung");"JKL")
    the * lets the characters unchanged
    [d]"ISc"$(("34";"88";"299");("mao";"tse";"tung");0x4a4b4c) .. (34 88 299;`mao`tse`tung;"JKL") [e]"IS*"$(("34";"88";"299");("mao";"tse";"tung");0x4a4b4c) .. (34 88 299;`mao`tse`tung;0x4a4b4c)
    the * lets the bytes unchanged
    [f] bijection of bytes into ASCII:all ("c"$j)="x"$j:key 256 .. 1b. BUT ("c"$j)~"x"$j:key 256 is 0b
    getenvgetenv `TEMP
    >= [gte]"o">="moscow" .. 110110b
    > [greater than]"o">"moscow" .. 100100b
    hclosehclose h .. closing file-communication
    hcounthcount `:file .. # of bytes
    hdelhdel file .. erase file
    hopenhopen `:xy/yx.txt .. h "whatever"
    iasc [index ascending]v@iasc v:1 5 5 7 6 3 3 .. 1 3 3 5 5 6 7
    ~ [identity]`e ~ /: (5;`e;"nhl 2006";`roland;"e";`e;0x34) .. 0100010b
    idesc [index descending]v@idesc v:1 5 5 7 6 3 3 .. 7 6 5 5 3 3 1
    ifif[true;..;..;]
    in"se" in "russia" .. 10b
    infinitiesinf:(1b,0xff,0Wh,0W,0Wj,0we,0w) # -1 + inf .. (0;254;32766;2147483646;9223372036854775806j;0w;0w)
    and 0Wd 0Wz 0Wt (infinities related to date/datetime/time)
    inter"birds"inter"parrots" .. "rs"
    invinv 1f*(4 1 3;-1 1 2;6 7 17) .. (1.5 2 -0.5;14.5 25 -5.5;-6.5 -11 2.5) /set \P 10
    eq.system: 15x + 8y = 3 and x - 10y = 95 .. (inv (15 8f;1 -10f)) mmu (3 95f) .. 5 -9f ;x = 5 , y = -9
    , [join]"Czecho","slovakia" .. "Czechoslovakia"
    keykey 5 .. 0 1 2 3 4 # key "silver"!0x0a114dab762e .. "silver"
    keyed tablesT:([n:`t`a`w;m:7 6 5] a:`A`a`c;b:`ll`jj`dd)
    lastlast "miami" .. "i"
    <[less than]"miriam" < "m" .. 010110b
    like"panama" like/: ("*am*";"pan*") .. 11b;("tr*nce";"france") like "*[*]*" .. 10b
    ljleft join
    loglog 7 8 2.71828 -3 0 .. 1.94591 2.079442 0.9999993 0n -0w
    lower"GLOBAL LIMIT SYSTEM" .. "global limit system"
    lsq [least squares]1 1.8 1.5 2.5 lsq flip (1 1f;2 1f;3 1f;5 1f) .. 0.3314286 0.7885714
    <= [lte]"o"<"moscow" .. 001001b
    ltrimdeleting leading blanks: ltrim " zurich" .. "zurich"
    x$m [matrix multiply](2 3f;-1 4f)$(9 2f;4 2f) .. (30 10f;7 6f)
    For (1 x n) . (n x 1) matrices we can take: (c,c:count v)#prd flip v cross v
    resp. we do: (flip enlist v)$enlist v
    mavg3 mavg 1 3 5 7 9f .. 1 2 3 5 7f
    maxmax "texas" .. "x"
    maxsmaxs 2 4 2 2 8 7 2 7 .. 2 4 4 4 8 8 8 8, "fox"~maxs"fox" .. 1b
    mcount5 mcount "alabama" .. 0 1 2 3 4 5 5 5
    med [median]med 8 7 6 5 6 7 9 .. 7f
    minmin 5 -1 8 2 .. -1
    minsmins 67 8 11 4 6 .. 67 8 8 4 4, "volga"~mins"volga" .. 1b
    mmax3 mmax "DEEPTHOUGHT" .. "DEEPTTTUUUT"
    mmin3 mmin 9 8 7 56 17 87 13 .. 9 8 7 7 7 17 13
    mmu .. see matrix multiply
    mod(key 23) mod 11 .. 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 0
    j mod i (j can be 64-bit integer) example: 87726636552j mod 873 .. 579j
    msum3 msum 1 5 7 9 11 .. 1 6 13 21 27
    * [multiply]3*4 5j .. 12 15j
    negneg (4;9j;7h;0x77;0N;01b) .. (-4;-9j;-7h;-119;0N;0 -1)
    nextnext "perth" .. "erth "
    notnot 1100b .. 0011b, not 1 1 0 0 .. 0011b
    nullnull 0N 9 8 7 0N .. 10001b
    odbch:.odbc.open `filedsn`usr`pwd (db2 connect)
    or1100b or 0101b .. 1101b (works also for Int/Long/Short+Bytes)
    peach [parallel each]peach[>;3 13 76 111 223 227 224 701] .. 11111101b
    prdprd 1+til 5 .. 120f
    prdsprds -1 2 -3 4 .. -1 -2 6 24
    k)s)q) [prefixing]k) k4 s) jdbc/odbc sql93 .. q) talking to q server
    prevprev key 5 .. 0N 0 1 2 3
    protected executionsee under `catch
    randrand each 6#50 .. 19 39 49 17 2 28
    ? [random]5?10 .. 6 5 7 7 7, -5?10 .. 4 3 7 1 6 or 7?" " returns 7 random chars out of "a-z"
    rankrank 11 12 22 12 98 112 .. 0 1 3 2 4 5
    ratiosratios (til 6) xexp 3 .. 0 0w 8 3.375 2.37037 1.953125
    razeraze (1 3;4 5 6 7;1) .. 1 3 4 5 6 7 1
    read0read0 `:text.txt
    read1read1 `:bytes
    reciprocalreciprocal 2 4 8f .. 0.5 0.25 0.125
    (n,m)#v [reshape]2 10#til 20 .. works only for 2-dim, 2 3 4# .. length error
    reversereverse "flurry" .. "yrrulf"
    rotate4 rotate "techno" .. "notech"
    rounding .. round:{floor 0.5+x}, roundto:{y*floor 0.5+x%y} -> roundto[34.7873 11.3787 38.6767;0.25 0.2 0.125] .. 34.75 11.4 38.625
    i [rownumber]select i,..
    rtrim .. rtrim "geneva " .. "geneva" .. deleting trailing blanks
    selectbe aware that .. T:select a,b,a from U ..then cols`T is `a`b`a1
    select ?[t;a;b;c]?[M;enlist (>;`b;2);0b;()] ..
    select from M where b>2

    ?[M;((>;`b;2);(like;`c;"*r*"));0b;()] ..
    select from M where (b>2) and c like "*r*"

    ?[M;((>;`b;2);(like;`c;"*r*"));0b;(enlist `a)!enlist (sum;`a)] ..
    select sum a from M where (b>2) and c like "*r*"

    ?[M;((>;`b;2);(like;`c;"*r*"));0b;(`a`c)!((sum;`a);(last;`c))] ..
    select sum a,last c from M where (b>2) and c like "*r*"

    ?[M;enlist (>;`b;2);(enlist `d)!enlist `d;(enlist `a)!enlist (sum;`a)]
    select sum a by d from M where b>2
    .z.s [self referent]fac2:{$[x<2;1;$[x<3;x;x*.z.s x-2]]} .. double factorial !!n
    serialized tables (set+get) let be - M:([] a:`u`d`x`w; b:9 8 76 1)
    `:somedir/T set M or .[`:somedir/T;();:;M] saving as T
    M:get`:somedir/T reading .. we can also use \l somedir/T
    `:somedir/T insert N .. inserting
    `:somedir/T insert `a`b!(`I;8777)

    ..keyed tables..K:([k:`a`b`c]s:`km`lk`ol;v:98 99 88)

    .[`:somedir/L;();:;K] or `:somedir/L set K for saving
    .[`:somedir/L;();,;] N or `:somedir/L insert N for inserting
    signumsignum 8 0 5 -3j .. 1 0 1 -1
    sinsin (acos -1)%6 .. 0.5
    sinh *nyi*{0.5*(1%c)-c:exp neg x}
    socketsh:hopen `:host:port (hclose h)
    sqrtsqrt sums 1+2*til 7 .. 1 2 3 4 5 6 7f
    ss [string search] "quantitative easing" ss "ti" .. 4 8
    ssr [string replacement]ssr["sandman";"andm";"ham"] .. "shaman"
    stringstring (`abc;878;9j;"anc") .. ("abc";"878";,"9";(,"a";,"n";,"c"))
    sublist(2;5) sublist "waterland" .. "terla"
    sumssums -1 2 -3 4 .. -1 1 -2 2
    sv1 100 1000 sv 5 8 9 .. 508009
    systemshell execution ..
    tablestables ` .. listing
    # [take]4#9 .. 9 9 9 9, -5#"adam" .. "madam", 4#9 8 7h .. 9 8 7 9h
    tan1f~tan (acos neg 1)%4 .. 1b
    tanh *nyi*{(d-c)%(d:1f%c)+c:exp neg x}
    tiltil 5 .. 0 1 2 3 4, til 6h .. 'type, til 6j .. 'type
    trimtrim " ghost riders in the sky " .. "ghost riders in the sky" .. deleting leading/trailing blanks(not in-between excess blanks)
    typebool = 1;byte = 4;short = 5;int = 6;long = 7;real = 8;float = 9; char = 10; symb = 11;month = 13;
    date = 14;datetime = 15;minute = 17;second = 18;time = 19;enum = 20;
    table = 98;dict = 99;lambda = 100;assignment = 101 (t: ::, type t = 101); projection = 104;composition = 105;
    f' = 106;f / = 107;f \ = 108;f': = 109;f /: = 110; f \: = 111; dynamic load = 112
    ujunion join (self-explaining)
    <> [unequal]"strawberry" <>"r" .. 1101111001b
    union1 3 4 union (3;`a) .. (1;3;4;`a)
    upperupper"global limit system" .. "GLOBAL LIMIT SYSTEM"
    value [execute/assoc.algebra]value "silver"!0x0a114dab762e .. 0x0a114dab762e
    vector conditional?[11010b;76 12 23 11 32;-4 -5 -9 0 3] .. 76 12 -9 11 3
    viewsviews ` .. listing
    vs0x0 vs/:16 32 64 128 255 .. (0x00000010;0x00000020;0x00000040;0x00000080;0x000000ff)
    0b vs/: 1 2 4 ..

    00000000000000000000000000000001b
    00000000000000000000000000000010b
    00000000000000000000000000000100b
    wavg2 3 4 wavg 7 8 22 .. 14f
    wherewhere "i"="mississippi" .. 1 4 7 10
    whilewhile[true;..;..;..;]
    within"pqy" within "dw" .. 110b
    wsum4 3 2 1 wsum 1 3 5 7 .. 30f
    xbarselect max amts,min amts by 10000 xbar amts from M
    (select max amts,.., by 10000f xbar .. will result in a type error)
    i xbar j (where j can be 64-bit integer) .. example: 70000 xbar 3762 87722 144544j .. 0 70000 140000j
    xlog2.71828 10 xlog/: 1e3 1e-7 2.71828 -4.. (6.90776 3;-16.11811 -7;1 0.4342942;0n 0n)
    xor *nyi*{xwi[x;y] or xwi[y;x]}
    xprev2 xprev 3 4 8 7 .. 0N 0N 3 4, -2 xprev 100 200 300 400 .. 0N 0N 300 400
    xwi *nyi*{x and not y}
    .Q local.Q.host 1381711022 .. `host174-60.pool8291.interbusiness.it (.Q.host "I"$"85.114.2.6" .. `cobra.obit.ru)
    .z local(h) host,(u) user,(K) version time, (k) version, (a) IP,(f) script,(z) GMT,(Z) timestamp (s) self referent
    z1,z2,z = (re,im), {re,im} are realsome COMPLEX OPERATORS (in K4).. if relevant, then always referring to the principal branch
    π/2 , π , 2π
    pih:0.25*pi2:2*pi:acos -1
    cpi(z=i) , cp1(z=1), cpni(z=-i)
    cpn1(z=-1) , cp2(z=1-i) , cp3(z=-1+i)
    cp4(z=1+i) , cp5(z=-1-i)
    cpi:0 1f;cp1:1 0f;cpni:0 -1f;cpn1:-1 0f;cp2:1 -1f;cp3:-1 1f;cp4:1 1f;cp5:-1 -1f
    cp0(z=0) , oo0(z=π/2+0i))
    oo1(z=- π/2+0i)
    oo1:-1f*oo0:(pih,0f);cp0:0 0f
    ep1(z=-0.5+i31/2) , ep2(z=-0.5-i31/2)
    ep2:1 -1*ep1:0.5*(-1,sqrt 3)
    flat (just decorative)flat:{$[1e-011>abs x;:0f;:x]}
    ap (utility)ap:{0f+x,'cp0}
    signum signum:{(x>0)-x<0} (available under q)
    sinh x, x realsinh:{0.5*(1%c)-c:exp@-x}
    cosh x, x realcosh:{0.5*(1%c)+c:exp@-x}
    tanh x, x realtanh:{(sinh x)%cosh x}
    arsinh x, x realarsinh:{log x+sqrt 1f+x*x}
    arcosh x, x ≥ 1, realarcosh:{log x+sqrt (x*x)-1f}
    artanh x, |x| < 1,realartanh:{0.5*log (1+x)%1-x}
    cis x = (cos x; sin x), x is real
    cis:{(cos x;sin x)}
    flat@/:/:cis 0.5*pi*key 5 .. (1 0 -1 0 1f;0 1 0 -1 0f)
    means cis(0,π/2,π,3π/2,2π) is 1,i,-1,-i,1
    absq(z) , squared absolute value
    f(z) = |z|2
    absq:{+/x*x}
    absq (24 3;10 4) is (676 25f), so
    |24+10i|2=676, |3+4i|2=25
    absz(z) , absolute value
    f(z) = |z|
    absz:{sqrt absq x}
    absz(3 6;4 8) returns 5 10f ..
    |3+4i|=5, |6+8i|=10
    deg(x), x real ;(degrees)
    deg:{x*180f%pi}
    deg asin 0.5*sqrt 0 1 2 3 4 returns 0 30 45 60 90f
    arc(x), x real ;(arcus)
    arc:{x*pi%180f}
    arc 0 45 90 135 180 360 .. 0 0.7853982 1.570796 2.356194 3.141593 6.283185
    arg(z) , argument of z ,
    (-π < arg z ≤ π)
    φ = arctan y/x
    arg:{(pi*c&d)+(u*~(a=0f)&d:b=0f)-pi*(c:a<0f)*signum u:atan 0w^(b:x@1)%a:x@0}
    or just nicer:
    arg:{(1+c*1-c:signum y)*acos x%absz(x;y)}
    in case of a [0,2π)-based definition:
    arg2:{(pi2*l<0f)+l:(1+c*1-c:signum y)*acos x%absz(x;y)}
    arg[1 0 -1 -1 0 -1 1f;0 1 1 0 -1 -1 -1f] .. 0 1.570796 2.356194 3.141593 -1.570796 -2.356194 -0.7853982;
    φ(1)=0,φ(i)=π/2,φ(-1+i)=3π/4,φ(-1)=π,φ(-i)=-π/2,φ(-1-i)=-3π/4,φ(1-i)=-π/4
    arootz(z;n) n positive integer
    f(z) = |z|1/neiφ/n
    arootz:{(cis (arg a)%n)*\:(+/a*a:0f+*x) xexp 1f%2f*n:last x}
    arootz((-236 621;-115 -478);3) .. (4 9f;-5 -2f)
    (-236-115i)1/3=4-5i ,(621-478i)1/3=9-2i
    arootz((9 82368 -47068;40 94024 -1900);2 6 5) .. (5 7 7f;4 1 -5f)
    (9+40i)1/2=5+4i ,(-47068+94024i)1/6=7+i , ,(-47068-1900i)1/5=7-5i
    dymz(z1;z2) ,
    dyadic multiplication(1)
    dymz:{(-/m*n;+/(m:x@0)*|n:x@1)}
    dymz((1 4 7 -2;2 -3 -1 5);(3 -2 -4 6;8 1 -3 -7)) .. (-13 -5 -31 23;14 10 -17 44)
    (1+2i)(3+8i)=-13+23i ,(4-3i)(-2+i)=-5+10i , (7-i)(-4-3i)=-31-17i , (-2+5i)(6-7i) = 23+44i
    dymz2(z0;z) ,
    dyadic multiplication(2)
    dymz2:{((-/a*m);+/(a:*x)*|m:last x)}
    dymz2(2 5;(3 6 7;-2 5 -4)) .. (16 -13 34;11 40 27)
    (2+5i)(3-2i)=16+11i ,(2+5i)(6+5i)=-13+40i , (2+5i)(7-4i)=34+27i
    sqrz(z) , square
    f(z) = z2
    sqrz:{dymz(x;x)}
    sqrz(3 -8 5;9 -2 -3) .. (-72 60 16;54 32 -30f)) ..
    (3+9i)2=-72+54i;(-8-2i)2=60+32i;(5-3i)2=16-30i
    cubz(z) , cube
    f(z) = z3
    cubz:{dymz(x;dymz(x;x))}
    cubz (6 5;4 3) .. (-72 -10;368 198) ..
    (6+4i)3=-72+368i;(5+3i)3=-10+198i
    conj(z) , conjugated
    f(z) = z_
    conj:{(*x;-last x)}
    conj(3 8;1 -2)..(3 8;-1 2f);
    3+i → 3-i and 8-2i → 8+2i
    invz(z) , inverse
    f(z) = z-1
    invz:{(conj x)%\:+/x*x}
    invz(3 6;4 8) .. (0.12 0.06;-0.16 -0.08)
    (3+4i)-1 = 0.12-0.16i , (6+8i)-1 = 0.06-0.08i
    expz(z) ; exponencial
    f(z) = ez
    expz:{{(exp@*x)*/:cis last x}}
    expz(0.5 3;0.5 4) .. (1.446889 -13.12878;0.7904391 -15.20078)
    e0.5+0.5i=1.446889+0.7904391i , e3+4i=-13.12878-15.20078i
    sqrtz(z) , square root
    f(z)= z1/2
    sqrtz:{(-c),'c:aroot(x;2)}
    sqrtz(54 -520 60;-30 -138 32) .. (-7.608343 -3 -8 7.608343 3 8;1.97152 23 -2 -1.97152 -23 2)
    (54-30i)0.5 = ±(-7.608343+1.97152i) , (60+32i)0.5 = ±(-8+2i) , (-520-138i)0.5 = ±(-3+23i)
    curtz(z) , cubic root
    f(z)= z1/3
    curtz:{(c,'dymz2(ep1;c)),'dymz2(ep2;c:aroot(x;3))}
    curtz (-72 -10;368 198) ..
    (6 5 -6.464102 -5.098076 0.4641016 0.09807621;4 3 3.196152 2.830127 -7.196152 -5.830127)
    (-72+368i)1/3 = [6+4i , -6.464102+3.196152i , 0.4641016+(-7.196152)i]
    (-10+198i)1/3 = [5+3i , -5.098076+2.830127i , 0.09807621-5.830127i]
    prdz(z) ,product
    f(z) = Π(z)
    prdz:{(*/absz x)*cis +/arg x}
    prdz(1 2 4 0.1;3 -5 -3 0.5) .. 30.6 30.8;
    (1+3i)(2-5i)(4-3i)(0.1+0.5i) = 30.6+30.8i
    prdz 5#'(4;7) .. 17684 -29113f ,
    (4+7i)5 = 17684-29113i (but using "pownz" below is the better deal in this case)
    pownz(z;n) power, n ≥ 0 and integer, n vector or scalar
    f(z) = zn
    pownz:{((absz c) xexp e)*/:cis (e:last x)*arg c:*x}
    pownz ((4 3 0.5 7 0;7 9 1.5 2 1);1 2 3 4 5) .. (4 -72 -3.25 1241 3.061617e-016;7 54 -2.25 2520 1)
    (4+7i)1 = 4+7i,(3+9i)2 = -72+54i,(0.5+1.5i)3 = -3.25-2.25i, (7+2i)4 = 1241+2520i, i5=i
    pownz((1 -3 -1;1 0 2);4) .. (-4 81 -7f;4.898587e-016 -3.967856e-014 24)
    (1+i)4 = -4 , (-3)4 = 81 , (-1+2i)4 = -7+24i
    rootn(z;n) , n positive scalar integer
    f(z)=z1/n
    rootn:{,/'((absz c) xexp 1%e)*/:/:cis ((arg c:*x)+/:pi2*!e)%e:last x}
    rootn((-72 -10;368 198);3) ..
    (6 5 -6.464102 -5.098076 0.4641016 0.09807621;4 3 3.196152 2.830127 -7.196152 -5.830127) .. so:
    (-72+368i)1/3 = [6+4i , -6.464102+3.196152i , 0.4641016+(-7.196152)i]
    (-10+198i)1/3 = [5+3i , -5.098076+2.830127i , 0.09807621-5.830127i]
    hornz(coeff); horner schema
    complex polynomial evaluation
    hornz:{y+(-/c*x;+/c*|x)}
    c:3 -4;p:+(6 9 1 0;1 -2 0 -11);last hornz\[*p;1_p] .. -766 -598f; so:
    p(z)=(6+i)z3+(9-2i)z2+z-11i, then p(3-4i) = -766-598i
    fs1(z) .. special functions
    f(z)=(1+z2)1/2
    fs1:{sqrtz cp1 + sqrz x}
    fs1 (3 4;-1 -9) .. (-3.147749 -4.020744 3.147749 4.020744;0.9530619 8.953568 -0.9530619 -8.953568)
    f(3-i)=[-3.147749+0.9530619i,3.147749-0.9530619i];f(4-9i)=[-4.020744+8.953568i,4.020744-8.953568i]
    fs2(z)
    f(z)=(1-z2)1/2
    fs2:{sqrtz cp1 - sqrz x}
    fs3(z)
    f(z)=(z2-1)1/2
    fs3:{sqrtz cpn1 + sqrz x}
    fs4(z)
    f(z)=iz
    fs4:{cp3*|x}
    fs5(z)
    f(z)=-iz
    fs5:{cp2*|x}
    fs6(z)
    f(z)=(i+z)/(i-z)
    fs6:{c:dymz(b+x;invz (b:cpi)-x:ap x);c[;&|/|/(0w,-0w)=\:x]:cpn1;if[1=#*c:-1_'c;c:*:'c];:c}
    fs6 (2 0 0;1 1 0w) .. (-1 0n -1;-1 0n 0)
    f(2+i)=-1-i , f(i) is undefined(singularity) , f(INF) = -1
    fs6(-1 -6) .. -0.72 0.04, so
    f(-1-6i)=-0.72+0.04i
    fs7(z)
    f(z)=(1+z)/(1-z)
    fs7:{c:dymz(b+x;invz (b:cp1)-x:ap x);c[;&|/|/(0w,-0w)=\:x]:cpn1;if[1=#*c:-1_'c;c:*:'c];:c}
    fs7(0 1 4f;1 1 -5f) .. (0 -1 -1.176471;1 2 -0.2941176)
    f(i)=i , f(1+i)=-1+2i , f(4-5i)=-1.176471-0.2941176i
    sinz z
    f(z) = sin z
    sinz:{((sin a)*cosh b;(cos a:x@0)*sinh b:x@1)}
    sinz (1 0 0.8660254;-2 -1 0.5) .. (3.165779 0 0.8589803;-1.959601 -1.175201 0.3375965)
    sin(1-2i)=3.165779-1.959601i , sin(-i)=-1.175201i , sin((0.5*31/2)+0.5i)=0.8589803+0.3375965i
    cosz z
    f(z) = cos z
    cosz:{((cos a)*cosh b;-(sin a:x@0)*sinh b:x@1)}
    cosz(2 1 3.3;1 1 -1.7) .. (-0.6421481 0.83373 -2.792904;-1.068607 -0.9888977 -0.417337)
    cos(2+i)=-0.6421481-1.068607i , cos(1+i)=0.83373-0.9888977i , cos(3.3-1.7i)=-2.792904-0.417337i
    tanz z
    f(z) = tan z
    tanz:{dymz (sinz x;invz cosz x)}
    tanz ((17*pi%8),1,4,(sqrt 3);0 16 0.5 1) .. (0.4142136 2.292611e-014 0.7079078 -0.1126422;0 1 0.8408826 1.288976)
    tan(17π/8)=-1+21/2;tan(1+16i)~i;tan(4-0.25i)=0.7079078+0.8408826i;tan(31/2+i) = -0.1126422+1.288976i
    cotanz z
    f(z) = cotg z
    cotanz:{dymz (cosz x;invz sinz x)}
    cotanz (4 2 0 1;0 1 1 -4) .. (0.8636912 -0.1713836 0 0.0006099003;-0 -0.8213298 -1.313035 0.9997206)
    cotg(4)=0.8636912;cotg(2+i)=-0.1713836-0.8213298i;cotg(i)=-1.313035i;cotg(1-4i) = 0.0006099003+0.9997206i
    sinhz z
    f(z)=sinh z
    sinhz:{0f^fs5 sinz fs4 x}
    sinhz (0 0 0 2 ;6,0,(pih),-11) .. (0 0 0 0.01605139;-0.2794155 0 1 3.762159)
    sinh(6i)=-0.2794155i , sinh(0)=0 , sinh(iπ/2)=i , sinh(2-11i)=0.01605139+3.762159i
    coshz z
    f(z)=cosh z
    coshz:{0f^cosz fs4 x}
    coshz (0 6.2 -4 0w;(40*pi),7.3,0f,0f) .. (1 129.6126 27.30823 0w;-0 209.5251 -0 0)
    cosh(40πi)=1 , cosh(6.2+7.3i)=129.6126+209.5251i , cosh(-4)=27.30823 , cosh(INF)=INF
    tanhz z
    f(z)=tanh z
    tanhz:{l:300f;c:fs5 tanz fs4 x:ap x;c[;&lb]:cpn1;if[1=#*c:-1_'c;c:*:'c];:c};
    tanhz(-3 0 0.25 0w -0w;0 3 -7.1 0 0f ) .. (-0.9950548 0 0.4893675 1 -1;0 -0.1425465 -0.9372601 0 0)
    tanh(-3)=-0.9950548;tanh(3i)=-0.1425465i;tanh(0.25-7.1i)=0.4893675-0.9372601;tanh(± INF) = ± 1
    logz z = log |z| + i arg z
    f(z) = log z
    logz:{(0.5*log absq x;arg x)}
    logz (-1 -10 -1;-1,0,sqrt 3) .. (0.3465736 2.302585 0.6931472;-2.356194 3.141593 2.094395)
    log(-1-i) = 0.3465736-2.356194i , log(-10) = 2.302585+3.141593i , log(-1+31/2i) = 0.6931472+2.094395i
    asinz = -i log(iz + (1 - z2)1/2)
    f(z) = arcsin z
    asinz:{fs5 logz (fs2 x)+(2*#*x)#'fs4 x}
    asinz (2 1.732051 0;0 1 1f) ..
    (1.570796 2.153461 3.141593 1.570796 0.9881321 0;1.316958 -1.358838 -0.8813736 -1.316958 1.358838 0.8813736)
    arcsin(2)=1.570796 ± 1.316958i ; arcsin(31/2+i)=0.9881318+1.358838i,2.153461-1.358838i ; arcsin(i)=0.8813736i,π - 0.8813736i
    acosz =-i log(z + i(1 - z2)1/2)
    f(z) = arccos z
    acosz:{oo0-asinz x}
    acosz (3 0;4 1) ..
    (-0.9368125 -1.570796 0.9368125 1.570796;2.305509 0.8813736 -2.305509 -0.8813736)
    arccos(3+4i)=± (0.9368125-2.305509i), arccos(i)=± (1.570796-0.8813736i)
    atanz = 0.5i log [(i + z)/(i - z)]
    f(z) = arctan z
    atanz:{c:0.5*fs4 logz fs6 x:ap x;l:last x;c[;&(0w=s:*x)|l in 0w,-0w]:oo0;c[;&-0w=s]:oo1;c[;&(0f=s)&1f< l]*:cp3;if[1=#*c:-1_'c;c:*:'c];:c}
    atanz (-5 0 -0w;8 -2 3) .. (-1.514221 -1.570796 -1.570796;0.0898435 -0.5493061 -0)
    arctan(-5+8i)=-1.514221+0.0898435i, arctan(-2i)=((-π/2)-0.5493061i) , arctan((-INF)+3i) = -π/2
    arsinhz = log (z + (z2 + 1)1/2)
    f(z)=arsinh z
    arsinhz:{logz (fs1 x)+(2*#*x)#'x}
    arsinhz (-100 0 0;5 0 100 ) ..
    (5.299591 0 -5.298292 -5.299591 0 5.298292;3.091637 3.141593 1.570796 0.04995591 0 1.570796)
    arsinh(-100+5i) = ± 5.299591+3.091637i ,arsinh(0) = 0 or πi, arsinh(100i) = ± 5.298292+πi/2
    arcoshz = log (z + (z2 - 1)1/2)
    f(z)=arcosh z
    arcoshz:{logz (fs3 x)+(2*#*x)#'x}
    arcoshz (-100 0 0;5 0 100 ) ..
    (5.299541 0 -5.298342 -5.299541 0 5.298342;3.091632 -1.570796 -1.570796 -3.091632 1.570796 1.570796)
    arcosh(-100+5i) = ±(5.299591+3.091637i) ,arcosh(0) = 0 ± πi/2, arcosh(100i) = ±(5.298292+πi/2)
    artanhz = 0.5 log [(1+z)/(1-z)]
    f(z) = artanh z
    artanhz:{c:0.5*logz fs7 x:ap x;c[;&(0f<*x)&0f=last x]*:cp2;if[1=#*c:-1_'c;c:*:'c];:c}
    artanhz (1 0 1 2f;1 0 -3 0f) .. (0.4023595 0 0.0919312 0.5493061;1.017222 0 -1.276795 -1.570796)
    artanh(1+i) = 0.4023595+1.017222i , artanh(0) = 0 , artanh(1-3i) = 0.0919312-1.276795i , artanh(2) = 0.5493061-1.570796i
    complex matrix operations
    a 1st word
    Let be M a complex matrix. We can represent M as Re(M) + i*Im(M) (Form 1) or in the more visible form just as M where each element of M is a pair of real numbers (r,c) (Form 2)
    Form 1 to Form 2: tp12:{x,''y}
    Form 2 to Form 1: rm:{*:''x} (real part) and cm:{last''x} (complex part)
    k)cmult (A;B) , A,B of Form 2
    complex matrix multiplication
    cmult:{a:(rm x;cm x);b:(rm y;cm y);tp12[((r1 mmu r2)-c1 mmu c2);((r1:a@0) mmu c2:b@1)+(c1:a@1) mmu r2:b@0]}
    example:
    A:2 2#0f+(2 -1;-3 1;5 3;6 -1) .. ie A[0;0] is 2-i etc.
    B:2 2#0f+(3 2;9 -1;6 -3;-1 -1)
    A,B are Form 2 matrices. Then C:cmult[A;B] will return the 2x2 matrix 2 2#(-7 16;21 -9;42 -5;41 17) .. ie C[0;0] is -7+16i etc
    k)invc M , M of Form 2
    complex matrix inversion
    invc:{C:(c:#x)#!:0f+((rm x),'cm x),((-1f*cm x),'rm x);:tp12[C[;i];C[;c+i:!c]]}
    example:
    M:2 2#(2 1;-1 9;7 1;-5 -11) .. ie M is a 2 x 2 complex matrix with M[0;0] = 2+i
    Then L:invc M represents M-1 .. L is then (rounded to 4 decimals) 2 2#(0.1089 -0.0770;0.0996 -0.0078;-0.0037 -0.0780;-0.0067 0.0238) .. ie L[0;0] is 0.1089-0.077i etc


  • Back to MAIN