Author Topic: Canonical Logarithm  (Read 5003 times)

0 Members and 1 Guest are viewing this topic.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Canonical Logarithm
« on: February 08, 2022, 09:13:32 am »
Code: [Select]
defdbl a-z
dim shared pi as double
pi = 4*atn(1)

sw = 800
sh = 600

screen _newimage(sw, sh, 32)

zoom = 100

a = 0.5
k = 0.09

sx = 2
sy = 1

tx = a*exp(k*16)*cos(16) + sx
ty = a*exp(k*16)*sin(16) + sy

x = a*exp(k*0)*cos(0) + sx - tx
y = a*exp(k*0)*sin(0) + sy - ty

r = sqr(x*x + y*y)
arg = _atan2(y, x)

for tt = r to 0 step -1
xl = tt*cos(arg)
yl = tt*sin(arg)

for yy=0 to sh
for xx=0 to sw
u = (xx - sw/2)/zoom
v = (sh/2 - yy)/zoom

cdiv uu, vv, u - xl, v - yl, u + xl, v + yl
clog uu, vv, uu, vv

mm = sqr(uu*uu + vv*vv)
aa = (pi + _atan2(vv, uu))/(2*pi)
pset (xx, yy), hrgb(aa, mm)
next
next

sleep
next

dim pp(5)
pp(5) = 0
pp(4) = 7
pp(3) = 10
pp(2) = 12
pp(1) = 15
pp(0) = 15.9

for ttt= 0 to 5
tt = pp(ttt)
for yy=0 to sh
for xx=0 to sw
u = (xx - sw/2)/zoom
v = (sh/2 - yy)/zoom

uu = 0
vv = 0
for t=tt to 16 step 0.1
x = a*exp(k*t)*cos(t) + sx - tx
y = a*exp(k*t)*sin(t) + sy - ty

cdiv p, q, 1, 0, x - u, y - v

dx = a*exp(k*t)*(k*cos(t) - sin(t))
dy = a*exp(k*t)*(k*sin(t) + cos(t))

cmul p, q, p, q, dx, dy

uu = uu + 0.1*p
vv = vv + 0.1*q
next

for t=16 - 0.1 to tt step -0.1
x =-a*exp(k*t)*cos(t) - sx + tx
y =-a*exp(k*t)*sin(t) - sy + ty

cdiv p, q, 1, 0, x - u, y - v

dx = a*exp(k*t)*(k*cos(t) - sin(t))
dy = a*exp(k*t)*(k*sin(t) + cos(t))

cmul p, q, p, q, dx, dy

uu = uu + 0.1*p
vv = vv + 0.1*q
next

cmul uu, vv, uu, vv, 0, -1/(2*pi)

mm = sqr(uu*uu + vv*vv)
aa = (pi + _atan2(vv, uu))/(2*pi)
pset (xx, yy), hrgb(aa, mm)
next
next

sleep
next

sleep
system

function hrgb&(h, m)
r =  0.5 - 0.5*sin(2*pi*h - pi/2)
    g = (0.5 + 0.5*sin(2*pi*h*1.5 - pi/2)) * -(h < 0.66)
    b = (0.5 + 0.5*sin(2*pi*h*1.5 + pi/2)) * -(h > 0.33)

    n = 128

    mm = m*10000 mod 500
p = abs((h*n) - int(h*n))

rr = 200*r - 0.15*mm - 35*p
gg = 200*g - 0.15*mm - 35*p
bb = 200*b - 0.15*mm - 35*p

if rr < 0 then rr = 0
if gg < 0 then gg = 0
if bb < 0 then bb = 0

hrgb& = _rgb(rr, gg, bb)
end function

function cosh#(x as double)
    cosh# = 0.5*(exp(x) + exp(-x))
end function

function sinh#(x as double)
    sinh# = 0.5*(exp(x) - exp(-x))
end function

'u + iv = (x + iy)^(a + ib)
sub cexp(u, v, xx, yy, aa, bb)
x = xx
y = yy
a = aa
b = bb
   
    lnz = x*x + y*y
   
    if lnz = 0 then
        u = 0
        v = 0
    else
        lnz = 0.5*log(lnz)
        argz = atan2(y, x)
       
        mag = exp(a*lnz - b*argz)
        ang = a*argz + b*lnz
       
        u = mag*cos(ang)
        v = mag*sin(ang)
    end if
end sub

'u + iv = (x + iy)*(a + ib)
sub cmul(u, v, xx, yy, aa, bb)
x = xx
y = yy
a = aa
b = bb
    u = x*a - y*b
    v = x*b + y*a
end sub

'u + iv = (x + iy)/(a + ib)
sub cdiv(u, v, xx, yy, aa, bb)
x = xx
y = yy
a = aa
b = bb

    d = a*a + b*b
    u = (x*a + y*b)/d
    v = (y*a - x*b)/d
end sub

sub clog(u, v, xx, yy)
x = xx
y = yy

    lnz = x*x + y*y
   
    if lnz = 0 then
        u = 0
        v = 0
    else
u = 0.5*log(lnz)
v = _atan2(y, x)
end if
end sub

FellippeHeitor

  • Guest
Re: Canonical Logarithm
« Reply #1 on: February 08, 2022, 11:38:31 am »
That's really trippy.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Canonical Logarithm
« Reply #2 on: February 08, 2022, 12:32:19 pm »
Anybody care to explain "Canonical Logarithm"?  That word "Canonical" crops up in places (I seem to remember 'doing' Canonical Distribution in Statistical Physics).  I suspect that its use derives from the fact that pre-industrial mathematicians in Western Culture derived their learning from religion-based teaching.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Canonical Logarithm
« Reply #3 on: February 08, 2022, 12:39:43 pm »
Logarithmic pair - Wikipedia https://en.wikipedia.org › wiki › Logarithmic_pair
The log canonical divisor of a log pair (X,D) is K+D where K is the canonical divisor of X. A logarithmic 1-form on a log pair (X,D) is allowed to have ...

math stuff...

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Canonical Logarithm
« Reply #4 on: February 08, 2022, 01:57:46 pm »
Fascinating. My optical sensory system has experienced trauma from hyper-stimulaion.

A quote from a 1838 novel (Oliver Twist), by Charles Dickens, then later performed as a musical on 30th June 1960, "Please Sir, may I have some more?"
Logic is the beginning of wisdom.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Canonical Logarithm
« Reply #5 on: February 08, 2022, 02:04:24 pm »
In other words: "What the dickens was he talking about?"!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Canonical Logarithm
« Reply #6 on: February 08, 2022, 06:39:20 pm »
Amazing, of course I pressed the keys to see if there was anything extra and it kept changing to different pictures. Here is one it made. It reminds me of the infinite Mandelbrot Fractal.

CanonicalLogarithmPicture-by-Vince.jpg
* CanonicalLogarithmPicture-by-Vince.jpg (Filesize: 200.76 KB, Dimensions: 802x625, Views: 158)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Canonical Logarithm
« Reply #7 on: February 08, 2022, 07:19:40 pm »
Anybody care to explain "Canonical Logarithm"?

Canonical means, "as related to being shot from a cannon".
Logarithm means, "in relation to the rhythm a log makes traveling over waves".

Put those together and it's obviously referring to the rhythm a log makes as it flips end over end as it travels trough the air after being shot from a cannon!

(And vince's pictures here must obviously be the wind tunnel representation of the aerial disturbance that canonical logarithm is making!)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Canonical Logarithm
« Reply #8 on: February 08, 2022, 08:30:06 pm »
Disturbance yes...

Thanks to Ken's comment I learned this wasn't just the first screen I saw that came up, there was more!

And here is more still, Canonical Logarithm Explorer: The Movie
Code: QB64: [Select]
  1. _Title "Canonical Logarithm Explorer: The Movie" ' b+ mod of another coding masterpiece by vince
  2. ' ref  https://qb64forum.alephc.xyz/index.php?topic=4646.msg140513#msg140513
  3.  
  4. DefDbl A-Z
  5. pi = 4 * Atn(1)
  6.  
  7. sw = 800
  8. sh = 600
  9.  
  10. Screen _NewImage(sw, sh, 32)
  11.  
  12. zoom = 100
  13.  
  14. a = 0.5
  15. k = 0.09
  16.  
  17. sx = 2
  18. sy = 1
  19.  
  20. tx = a * Exp(k * 16) * Cos(16) + sx
  21. ty = a * Exp(k * 16) * Sin(16) + sy
  22.  
  23. x = a * Exp(k * 0) * Cos(0) + sx - tx
  24. y = a * Exp(k * 0) * Sin(0) + sy - ty
  25.  
  26. r = Sqr(x * x + y * y)
  27. arg = _Atan2(y, x)
  28.  
  29. For tt = r To 0 Step -1
  30.     xl = tt * Cos(arg)
  31.     yl = tt * Sin(arg)
  32.  
  33.     For yy = 0 To sh
  34.         For xx = 0 To sw
  35.             u = (xx - sw / 2) / zoom
  36.             v = (sh / 2 - yy) / zoom
  37.  
  38.             cdiv uu, vv, u - xl, v - yl, u + xl, v + yl
  39.             clog uu, vv, uu, vv
  40.  
  41.             mm = Sqr(uu * uu + vv * vv)
  42.             aa = (pi + _Atan2(vv, uu)) / (2 * pi)
  43.             PSet (xx, yy), hrgb(aa, mm)
  44.         Next
  45.     Next
  46.  
  47.     _Delay 1
  48.  
  49. Dim pp(5)
  50. pp(5) = 0
  51. pp(4) = 7
  52. pp(3) = 10
  53. pp(2) = 12
  54. pp(1) = 15
  55. pp(0) = 15.9
  56.  
  57. For ttt = 0 To 0
  58.     tt = pp(ttt)
  59.     For yy = 0 To sh
  60.         For xx = 0 To sw
  61.             u = (xx - sw / 2) / zoom
  62.             v = (sh / 2 - yy) / zoom
  63.  
  64.             uu = 0
  65.             vv = 0
  66.             For t = tt To 16 Step 0.1
  67.                 x = a * Exp(k * t) * Cos(t) + sx - tx
  68.                 y = a * Exp(k * t) * Sin(t) + sy - ty
  69.  
  70.                 cdiv p, q, 1, 0, x - u, y - v
  71.  
  72.                 dx = a * Exp(k * t) * (k * Cos(t) - Sin(t))
  73.                 dy = a * Exp(k * t) * (k * Sin(t) + Cos(t))
  74.  
  75.                 cmul p, q, p, q, dx, dy
  76.  
  77.                 uu = uu + 0.1 * p
  78.                 vv = vv + 0.1 * q
  79.             Next
  80.  
  81.             For t = 16 - 0.1 To tt Step -0.1
  82.                 x = -a * Exp(k * t) * Cos(t) - sx + tx
  83.                 y = -a * Exp(k * t) * Sin(t) - sy + ty
  84.  
  85.                 cdiv p, q, 1, 0, x - u, y - v
  86.  
  87.                 dx = a * Exp(k * t) * (k * Cos(t) - Sin(t))
  88.                 dy = a * Exp(k * t) * (k * Sin(t) + Cos(t))
  89.  
  90.                 cmul p, q, p, q, dx, dy
  91.  
  92.                 uu = uu + 0.1 * p
  93.                 vv = vv + 0.1 * q
  94.             Next
  95.  
  96.             cmul uu, vv, uu, vv, 0, -1 / (2 * pi)
  97.  
  98.             mm = Sqr(uu * uu + vv * vv)
  99.             aa = (pi + _Atan2(vv, uu)) / (2 * pi)
  100.             PSet (xx, yy), hrgb(aa, mm)
  101.         Next
  102.     Next
  103.  
  104.     _Delay 5
  105.     pp(5) = Rnd * 50 - 25
  106.     pp(4) = Rnd * 50 - 25
  107.     pp(3) = Rnd * 50 - 25
  108.     pp(2) = Rnd * 50 - 25
  109.     pp(1) = Rnd * 50 - 25
  110.     pp(0) = Rnd * 50 - 25
  111.  
  112.     For ttt = 0 To 1
  113.         tt = pp(ttt)
  114.         For yy = 0 To sh
  115.             For xx = 0 To sw
  116.                 u = (xx - sw / 2) / zoom
  117.                 v = (sh / 2 - yy) / zoom
  118.  
  119.                 uu = 0
  120.                 vv = 0
  121.                 For t = tt To 16 Step 0.1
  122.                     x = a * Exp(k * t) * Cos(t) + sx - tx
  123.                     y = a * Exp(k * t) * Sin(t) + sy - ty
  124.  
  125.                     cdiv p, q, 1, 0, x - u, y - v
  126.  
  127.                     dx = a * Exp(k * t) * (k * Cos(t) - Sin(t))
  128.                     dy = a * Exp(k * t) * (k * Sin(t) + Cos(t))
  129.  
  130.                     cmul p, q, p, q, dx, dy
  131.  
  132.                     uu = uu + 0.1 * p
  133.                     vv = vv + 0.1 * q
  134.                 Next
  135.  
  136.                 For t = 16 - 0.1 To tt Step -0.1
  137.                     x = -a * Exp(k * t) * Cos(t) - sx + tx
  138.                     y = -a * Exp(k * t) * Sin(t) - sy + ty
  139.  
  140.                     cdiv p, q, 1, 0, x - u, y - v
  141.  
  142.                     dx = a * Exp(k * t) * (k * Cos(t) - Sin(t))
  143.                     dy = a * Exp(k * t) * (k * Sin(t) + Cos(t))
  144.  
  145.                     cmul p, q, p, q, dx, dy
  146.  
  147.                     uu = uu + 0.1 * p
  148.                     vv = vv + 0.1 * q
  149.                 Next
  150.  
  151.                 cmul uu, vv, uu, vv, 0, -1 / (2 * pi)
  152.  
  153.                 mm = Sqr(uu * uu + vv * vv)
  154.                 aa = (pi + _Atan2(vv, uu)) / (2 * pi)
  155.                 PSet (xx, yy), hrgb(aa, mm)
  156.             Next
  157.         Next
  158.  
  159.         _Delay 5
  160.     Next
  161.  
  162.  
  163. Function hrgb& (h, m)
  164.     r = 0.5 - 0.5 * Sin(2 * pi * h - pi / 2)
  165.     g = (0.5 + 0.5 * Sin(2 * pi * h * 1.5 - pi / 2)) * -(h < 0.66)
  166.     b = (0.5 + 0.5 * Sin(2 * pi * h * 1.5 + pi / 2)) * -(h > 0.33)
  167.  
  168.     n = 128
  169.  
  170.     mm = m * 10000 Mod 500
  171.     p = Abs((h * n) - Int(h * n))
  172.  
  173.     rr = 200 * r - 0.15 * mm - 35 * p
  174.     gg = 200 * g - 0.15 * mm - 35 * p
  175.     bb = 200 * b - 0.15 * mm - 35 * p
  176.  
  177.     If rr < 0 Then rr = 0
  178.     If gg < 0 Then gg = 0
  179.     If bb < 0 Then bb = 0
  180.  
  181.     hrgb& = _RGB(rr, gg, bb)
  182.  
  183. Function cosh# (x As Double)
  184.     cosh# = 0.5 * (Exp(x) + Exp(-x))
  185.  
  186. Function sinh# (x As Double)
  187.     sinh# = 0.5 * (Exp(x) - Exp(-x))
  188.  
  189. 'u + iv = (x + iy)^(a + ib)
  190. Sub cexp (u, v, xx, yy, aa, bb)
  191.     x = xx
  192.     y = yy
  193.     a = aa
  194.     b = bb
  195.  
  196.     lnz = x * x + y * y
  197.  
  198.     If lnz = 0 Then
  199.         u = 0
  200.         v = 0
  201.     Else
  202.         lnz = 0.5 * Log(lnz)
  203.         argz = atan2(y, x)
  204.  
  205.         mag = Exp(a * lnz - b * argz)
  206.         ang = a * argz + b * lnz
  207.  
  208.         u = mag * Cos(ang)
  209.         v = mag * Sin(ang)
  210.     End If
  211.  
  212. 'u + iv = (x + iy)*(a + ib)
  213. Sub cmul (u, v, xx, yy, aa, bb)
  214.     x = xx
  215.     y = yy
  216.     a = aa
  217.     b = bb
  218.     u = x * a - y * b
  219.     v = x * b + y * a
  220.  
  221. 'u + iv = (x + iy)/(a + ib)
  222. Sub cdiv (u, v, xx, yy, aa, bb)
  223.     x = xx
  224.     y = yy
  225.     a = aa
  226.     b = bb
  227.  
  228.     d = a * a + b * b
  229.     u = (x * a + y * b) / d
  230.     v = (y * a - x * b) / d
  231.  
  232. Sub clog (u, v, xx, yy)
  233.     x = xx
  234.     y = yy
  235.  
  236.     lnz = x * x + y * y
  237.  
  238.     If lnz = 0 Then
  239.         u = 0
  240.         v = 0
  241.     Else
  242.         u = 0.5 * Log(lnz)
  243.         v = _Atan2(y, x)
  244.     End If
  245.  
  246.  

So far it's been a variation on a theme:
 
Canonical Logarithm the Movie.PNG