To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
Hi Martin,
In the first tacit version of gftpr, (4&* + $:@<:) is a fork, called monadically, so 4&* is used as monad.
In the last version of gftpr, (4&+ $:@<:) is a *hook*, used monadically. This means 4&+ is called dyadically, which is equivalent to (4&+@])^:[ which happens to be equivalent to 4&* + ] .
e.g.:
2 (4&+) 0
8
(4&*+]) 5
25
(4&+]) 5
25
5 (4&+) 5
25
5 (4&+@]^:[) 5
25
+/5,5#4
25
Dyadic bonded verbs are a bit of an oddball in J that might bite you if you're not sure whether verbs are used monadically or dyadically in a sentence.
Hope this helps,
Jan-Pieter
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
Hi Martin,
In the first tacit version of gftpr, (4&* + $:@<:) is a fork, called monadically, so 4&* is used as monad.
In the last version of gftpr, (4&+ $:@<:) is a *hook*, used monadically. This means 4&+ is called dyadically, which is equivalent to (4&+@])^:[ which happens to be equivalent to 4&* + ] .
e.g.:Â
  2 (4&+) 0
8
  (4&*+]) 5
25
  (4&+]) 5
25
  5 (4&+) 5
25
  5 (4&+@]^:[) 5
25
  +/5,5#4
25
Dyadic bonded verbs are a bit of an oddball in J that might bite you if you're not sure whether verbs are used monadically or dyadically in a sentence.
Hope this helps,
Jan-Pieter
On Thu, 1 Aug 2024, 08:28 Martin Kreuzer, <in...@airkreuzer.com> wrote:
- Dear all -
- As an exercise I wrote a simple verb which uses recursion:
- gftpr=: monad define ("0)
- Â select. y
-  case. 0 do. 0
-  case.   do. (y*4) + gftpr y-1
- Â end.
- )
- This is what I came up with translating it to tacit:
- gftpr=: 0:`(4&*+$:@<:)@.(1&<:)"0 M.
- Â Â gftpr i.10
- 0 4 12 24 40 60 84 112 144 180
- By mere accident I found, that /this/ verb (having dropped Times (*))
- gftpr=: 0:`(4&+$:@<:)@.(1&<:)"0 M.
- gives me the /same/ result.
- And this I do not understand.
- Â Â jver''
- j9.6.0-beta14/j64avx2/windows/commercial/ www.jsoftware.com/2024-07-19T02:38:13/clang-18-1-6/SLEEF=1
- Any hint welcome.
- Thanks.
- -Martin
- To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
- Dear all -
- jver''
- j9.6.0-beta14/j64avx2/windows/commercial/ www.jsoftware.com/2024-07-19T02:38:13/clang-18-1-6/SLEEF=1
- Any hint welcome.
- Thanks.
- -Martin
- To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
Devon McCormick, CFA
Flâneur
]M=: 0.8 0.6 ,: 0.2 0.4
mp=: +/ . *
]I=:=i.2
M mp M mp M
3 M&mp I
and then ask leading questions about higher powers etc.NB. The number 42 is, in The Hitchhiker's Guide to the Galaxy, the
NB. "Answer to the Ultimate Question of Life, the Universe, and Everything".
NB. After first iteration of sin or cos we are in [-1 ; 1], so any other real number can be chosen as a starting point in simple iteration.
NB. Let's take 1 as a starting point this time.
load 'trig'
NB. Adverb Iter is defined using modifier trains.
NB. u Iter is a verb which calculates for each atom of y a pair of boxes:
NB. fixed point of u found by iteration from input starting point ; number of performed iterations.
Iter =: ({: ; #)@(^:a:)"0
NB. Let's begin with simpler example (cos instead of sin).
NB. Root of f(x) = x - cos x.
NB. Newton-Raphson method.
NB. Quadratic convergence.
(] - (] - cos) % 1 + sin) Iter 1
┌────────┬─â”
│0.739085│5│
└────────┴─┘
NB. Banach's method (simple iteration).
NB. Linear convergence.
cos Iter 1
┌────────┬──â”
│0.739085│77│
└────────┴──┘
NB. And go back to original case with sin.
NB. Root of f(x) = x - sin x.
NB. The root is 0, but the following result is a number close to 0 due to the floating-point arithmetic.
NB. Newton-Raphson method.
NB. Linear (not quadratic!) convergence, because f'(0) = 1 - cos 0 = 0.
(] - (] - sin) % 1 - cos) Iter 1
┌──────────┬──â”
│7.29388e_9│45│
└──────────┴──┘
Playing with J...
  plot ((0.975j_0.1 * ]) + 0.025j0.1 * cos) ^: (i.666) 1
 Â
  plot ((0.9j0.4 * ]) + 0.1j_0.4 * 2&o.) ^: (i.55) 1
 Â
  ( Y=. (((0.9j0.4 * ]) + 0.1j_0.4 * 2&o.)^:_) 1 )
_2.4868857j_1.80936134
  (-: cos)  Y
1
  (-: cos) +Y
1
Two cosine fixed points in the complex plane of an apparently infinite number.
On Sat, Aug 3, 2024 at 10:23 AM Marcin Żołek < marcin...@students.mimuw.edu.pl> wrote:
- It's worth mentioning that you can find cool illustrations of both of these fixed-point iterations on Wikipedia.
- But the coolest thing is that drawing them in J is easy!
- Â Â load 'plot trig'
- Â Â
- Â Â illustrate =: 3 : 0
- 'r f k x0' =. y
- pd 'reset'
- pd r ; f
- pd (}:@(2&#) ; 0&,@(2&#)@}.) f~^:(< k) x0
- pd r ; ']'
- pd 'show'
- )
- Â Â
- Â Â illustrate (0 , -: pi) ; 'cos' ; 50 ; 1
- Â Â illustrate (0 , -: pi) ; 'sin' ; 50 ; 1
- Â Â
- Marcin
- On Aug 2, 2024, at 10:46 PM, Marcin Żołek < marcin...@students.mimuw.edu.pl> wrote:
- Â Â NB. The number 42 is, in The Hitchhiker's Guide to the Galaxy, the
- Â Â NB. "Answer to the Ultimate Question of Life, the Universe, and Everything".
- Â Â NB. After first iteration of sin or cos we are in [-1 ; 1], so any other real number can be chosen as a starting point in simple iteration.
- Â Â NB. Let's take 1 as a starting point this time.
- Â Â load 'trig'
- Â Â NB. Adverb Iter is defined using modifier trains.
- Â Â NB. u Iter is a verb which calculates for each atom of y a pair of boxes:
- Â Â NB. fixed point of u found by iteration from input starting point ; number of performed iterations.
- Â Â Iter =: ({: ; #)@(^:a:)"0
- Â Â NB. Let's begin with simpler example (cos instead of sin).
- Â Â NB. Root of f(x) = x - cos x.
- Â Â NB. Newton-Raphson method.
- Â Â NB. Quadratic convergence.
- Â Â (] - (] - cos) % 1 + sin) Iter 1
- ┌────────┬─â”
- │0.739085│5│
- └────────┴─┘
- Â Â NB. Banach's method (simple iteration).
- Â Â NB. Linear convergence.
- Â Â cos Iter 1
- ┌────────┬──â”
- │0.739085│77│
- └────────┴──┘
- Â Â NB. And go back to original case with sin.
- Â Â NB. Root of f(x) = x - sin x.
- Â Â NB. The root is 0, but the following result is a number close to 0 due to the floating-point arithmetic.
- Â Â
- Â Â NB. Newton-Raphson method.
- Â Â NB. Linear (not quadratic!)Â convergence, because f'(0) = 1 - cos 0 = 0.
- Â Â (] - (] - sin) % 1 - cos) Iter 1
- ┌──────────┬──â”
- │7.29388e_9│45│
- └──────────┴──┘
- Â Â NB. Simple iteration method.
- Â Â NB. The following has slow convergence, because sin x = x - x^3 / 3! + x^5 / 5! - ...
- Â Â NB. In other words lim (x -> 0) sin x / x = 1.
- Â Â NB. sin Iter 1
- Â Â NB. In the book Asymptotic methods in analysis by N. G. de Bruijn there is a proof that
- Â Â NB. x_n - x_{n+1} = 0.5 * sqrt(3) * n^(-3/2) + O(n^(-5/2) log n) where x_n is sin^:n x_0 in J notation and 0 < x_0 < PI.
- Â Â NB. x_0 is 1 in our case.
- Â Â NB. Let's compare the formula from the book with calculations:
- Â Â (%: ^&3 <: 1e6) %~ 0.5 * %: 3
- 8.66027e_10
- Â Â -/ _2&{. sin^:(< 1e6) 1
- 8.66014e_10
- Â Â NB. It may be interesting to check the number of iterations in above methods for double-doubles (use 11&c. in J9.6) or change comparison tolerance (9!:19).
- Marcin
- On Aug 2, 2024, at 5:21 PM, Martin Kreuzer <in...@airkreuzer.com> wrote:
- Hi Marcin -
- Thanks for the thorough explanation (regarding dyadic bonded verb).
- About your two root finding examples:
- I tried some finite numbers (on the left) to understand what they do,
- and (with sin) experienced the slow convergence toward zero.
- I have never come across a construct as _ sin 42 before.
- - Is that Newton-Raphson in disguise ?
- - Any specific reason for argument 42 ?
- -Martin
- At 2024-08-01 08:15, you wrote:
- This bite can lead to possibly infinite calculations when performing fixed-point iteration (I did it by mistake last week), for example:
- Â load 'trig'
- Â Â cos
- 2&o.
- Â Â _ cos 42 NB. linear convergence for all real numbers (solution of the equation cos x = x)
- 0.739085
- Â Â _ sin 42 NB. very slow convergence to 0 (solution of the equation sin x = x)
- Convergence to 0 can be seen by for example:
- Â Â |. (< 1000) sin 42
- This unintuitive trick in J led me to the above discoveries!
- Marcin
- On Aug 1, 2024, at 9:11 AM, Jan-Pieter Jacobs < janpiete...@gmail.com> wrote:
- Hi Martin,
- In the first tacit version of gftpr, (4&* + $:@<:) is a fork, called monadically, so 4&* is used as monad.
- In the last version of gftpr, (4&+ $:@<:) is a *hook*, used monadically. This means 4&+ is called dyadically, which is equivalent to (4&+@])^:[ which happens to be equivalent to 4&* + ] .
- e.g.:
- Â Â 2 (4&+) 0
- 8
- Â Â (4&*+]) 5
- 25
- Â Â (4&+]) 5
- 25
- Â Â 5 (4&+) 5
- 25
- Â Â 5 (4&+@]^:[) 5
- 25
- Â Â +/5,5#4
- 25
- Dyadic bonded verbs are a bit of an oddball in J that might bite you if you're not sure whether verbs are used monadically or dyadically in a sentence.
- Hope this helps,
- Jan-Pieter
- On Thu, 1 Aug 2024, 08:28 Martin Kreuzer, <in...@airkreuzer.com> wrote:
- Dear all -
- As an exercise I wrote a simple verb which uses recursion:
- gftpr=: monad define ("0)
- Â select. y
-  case. 0 do. 0
-  case.   do. (y*4) + gftpr y-1
- Â end.
- )
- This is what I came up with translating it to tacit:
- gftpr=: 0:`(4&*+$:@<:)@.(1&<:)"0 M.
- Â Â gftpr i.10
- 0 4 12 24 40 60 84 112 144 180
- By mere accident I found, that /this/ verb (having dropped Times (*))
- gftpr=: 0:`(4&+$:@<:)@.(1&<:)"0 M.
- gives me the /same/ result.
- And this I do not understand.
- Â Â jver''
- j9.6.0-beta14/j64avx2/windows/commercial/ www.jsoftware.com/2024-07-19T02:38:13/clang-18-1-6/SLEEF=1
- Any hint welcome.
- Thanks.
- -Martin
- To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
- To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
- To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
- To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
- To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
It's worth mentioning that you can find cool illustrations of both of these fixed-point iterations on Wikipedia.
https://en.wikipedia.org/wiki/Fixed-point_iteration
But the coolest thing is that drawing them in J is easy!
load 'plot trig'
illustrate =: 3 : 0
'r f k x0' =. y
pd 'reset'
pd r ; f
pd (}:@(2&#) ; 0&,@(2&#)@}.) f~^:(< k) x0
pd r ; ']'
pd 'show'
)
illustrate (0 , -: pi) ; 'cos' ; 50 ; 1
illustrate (0 , -: pi) ; 'sin' ; 50 ; 1
Marcin
On Aug 2, 2024, at 10:46 PM, Marcin Żołek < marcin...@students.mimuw.edu.pl> wrote:
NB. The number 42 is, in The Hitchhiker's Guide to the Galaxy, the
NB. "Answer to the Ultimate Question of Life, the Universe, and Everything".
NB. After first iteration of sin or cos we are in [-1 ; 1], so any other real number can be chosen as a starting point in simple iteration.
NB. Let's take 1 as a starting point this time.
load 'trig'
NB. Adverb Iter is defined using modifier trains.
NB. u Iter is a verb which calculates for each atom of y a pair of boxes:
NB. fixed point of u found by iteration from input starting point ; number of performed iterations.
Iter =: ({: ; #)@(^:a:)"0
NB. Let's begin with simpler example (cos instead of sin).
NB. Root of f(x) = x - cos x.
NB. Newton-Raphson method.
NB. Quadratic convergence.
(] - (] - cos) % 1 + sin) Iter 1
┌────────┬─â”
│0.739085│5│
└────────┴─┘
NB. Banach's method (simple iteration).
NB. Linear convergence.
cos Iter 1
┌────────┬──â”
│0.739085│77│
└────────┴──┘
NB. And go back to original case with sin.
NB. Root of f(x) = x - sin x.
NB. The root is 0, but the following result is a number close to 0 due to the floating-point arithmetic.
NB. Newton-Raphson method.
NB. Linear (not quadratic!) convergence, because f'(0) = 1 - cos 0 = 0.
(] - (] - sin) % 1 - cos) Iter 1
┌──────────┬──â”
│7.29388e_9│45│
└──────────┴──┘
The question 'How many roads must a man walk down?' has also been suggested as having that number as its answer. Having that in mind,
  uu (^:a:)(({: ; #)@)("0)
({: ; #)@(uu^:a:)"0
On Tue, Aug 20, 2024 at 6:49 AM Martin Kreuzer <in...@airkreuzer.com> wrote:
- Hi Marcin -
- Regarding 42 : Â It's been quite some time ago and therefore I didn't readily make the connection -- which means you made me re-read chapter 27 (and 28, for that matter) to meet Deep Thought again, until 'end of the tape'.
- Your 'iter' adverb has been gratefully accepted and made it into my startup script.
- As suggested, I experimented with double-double precision;
- - in case of f(x) = x - cos x there was no difference (still 5 steps),
- - in case of f(x) = x - sin x , after about double the number of iterations
- it showed a result about double the order of magnitude closer to zero ...
- (I then even managed to unearth the de Bruijn book and looked up the formula you mentioned.)
- Thanks for the hints and discussion.
- -Martin
- At 2024-08-02 20:46, you wrote:
- Â Â NB. The number 42 is, in The Hitchhiker's Guide to the Galaxy, the
- Â Â NB. "Answer to the Ultimate Question of Life, the Universe, and Everything".
- Â Â NB. After first iteration of sin or cos we are in [-1 ; 1], so any other real number can be chosen as a starting point in simple iteration.
- Â Â NB. Let's take 1 as a starting point this time.
- Â Â load 'trig'
- Â Â NB. Adverb Iter is defined using modifier trains.
- Â Â NB. u Iter is a verb which calculates for each atom of y a pair of boxes:
- Â Â NB. fixed point of u found by iteration from input starting point ; number of performed iterations.
- Â Â Iter =: ({: ; #)@(^:a:)"0
- Â Â NB. Let's begin with simpler example (cos instead of sin).
- Â Â NB. Root of f(x) = x - cos x.
- Â Â NB. Newton-Raphson method.
- Â Â NB. Quadratic convergence.
- Â Â (] - (] - cos) % 1 + sin) Iter 1
- ↌ↀↀ€â†€Ã¢â€ €Ã¢â€ €Ã¢â‚¬Ã¢â€ €Ã¢â€ €Ã¢â€ €Ã¢â€¬Ã¢â€ ¬â†€Ã¢â€
- ↂ0.739085ↂ5ↆ‚
- ↆↀↀ¬â†€Ã¢â€ €Ã¢â€ €Ã¢â‚¬Ã¢â€ €Ã¢â€ €Ã¢â€ €Ã¢â‚¬Ã¢â€ ´â†€Ã¢â€ ˜
- Â Â NB. Banach's method (simple iteration).
- Â Â NB. Linear convergence.
- Â Â cos Iter 1
- ↌ↀↀ€â†€Ã¢â€ €Ã¢â€ €Ã¢â‚¬Ã¢â€ €Ã¢â€ €Ã¢â€ €Ã¢â€¬Ã¢â€ ¬â†€Ã¢â€ €Ã¢â€ ↂ0.739085ↂ77ↆ‚
- ↆↀↀ¬â†€Ã¢â€ €Ã¢â€ €Ã¢â‚¬Ã¢â€ €Ã¢â€ €Ã¢â€ €Ã¢â‚¬Ã¢â€ ´â†€Ã¢â€ €Ã¢â€ †˜
- Â Â NB. And go back to original case with sin.
- Â Â NB. Root of f(x) = x - sin x.
- Â Â NB. The root is 0, but the following result is a number close to 0 due to the floating-point arithmetic.
- Â Â
- Â Â NB. Newton-Raphson method.
- Â Â NB. Linear (not quadratic!) convergence, because f'(0) = 1 - cos 0 = 0.
- Â Â (] - (] - sin) % 1 - cos) Iter 1
- ↌ↀↀ€â†€Ã¢â€ €Ã¢â€ €Ã¢â‚¬Ã¢â€ €Ã¢â€ €Ã¢â€ €Ã¢â€¬Ã¢â€ €Ã¢â€ €Ã¢â€ ¬â††€â†€Ã¢â€
- ↂ7.29388e_9ↂ45ↆ‚
- ↆↀↀ¬â†€Ã¢â€ €Ã¢â€ €Ã¢â‚¬Ã¢â€ €Ã¢â€ €Ã¢â€ €Ã¢â‚¬Ã¢â€ €Ã¢â€ €Ã¢â€ ´â††€Ã¢â€ €Ã¢â€ ˜
- r>
- Â Â NB. Simple iteration method.
- Â Â NB. The following has slow convergence, because sin x = x - x^3 / 3! + x^5 / 5! - ...
- Â Â NB. In other words lim (x -> 0) sin x / x = 1.
- Â Â NB. sin Iter 1
- Â Â NB. In the book Asymptotic methods in analysis by N. G. de Bruijn there is a proof that
- Â Â NB. x_n - x_{n+1} = 0.5 * sqrt(3) * n^(-3/2) + O(n^(-5/2) log n) where x_n is sin^:n x_0 in J notation and 0 < x_0 < PI.
- Â Â NB. x_0 is 1 in our case.
- Â Â NB. Let's compare the formula from the book with calculations:
- Â Â (%: ^&3 <: 1e6) %~ 0.5 * %: 3
- 8.66027e_10
- Â Â -/ _2&{. sin^:(< 1e6) 1
- 8.66014e_10
- Â Â NB. It may be interesting to check the number of iterations in above methods for double-doubles (use 11&c. in J9.6) or change comparison tolerance (9!:19).
- Marcin
- On Aug 2, 2024, at 5:21 PM, Martin Kreuzer <in...@airkreuzer.com> wrote:
- Hi Marcin -
- Thanks for the thorough explanation (regarding dyadic bonded verb).
- About your two root finding examples:
- I tried some finite numbers (on the left) to understand what they do,
- and (with sin) experienced the slow convergence toward zero.
- I have never come across a construct as _ sin 42 before.
- - Is that Newton-Raphson in disguise ?
- - Any specific reason for argument 42 ?
- -Martin
- At 2024-08-01 08:15, you wrote:
- This bite can lead to possibly infinite calculations when performing fixed-point iteration (I did it by mistake last week), for example:
- Â load 'trig'
- Â Â cos
- 2&o.
- Â Â _ cos 42 NB. linear convergence for all real numbers (solution of the equation cos x = x)
- 0.739085
- Â Â _ sin 42 NB. very slow convergence to 0 (solution of the equation sin x = x)
- Convergence to 0 can be seen by for example:
- Â Â |. (< 1000) sin 42
- This unintuitive trick in J led me to the above discoveries!
- Marcin
- On Aug 1, 2024, at 9:11 AM, Jan-Pieter Jacobs < janpiete...@gmail.com> wrote:
- Hi Martin,
- In the first tacit version of gftpr, (4&* + $:@<:) is a fork, called monadically, so 4&* is used as monad.
- In the last version of gftpr, (4&+ $:@<:) is a *hook*, used monadically. This means 4&+ is called dyadically, which is equivalent to (4&+@])^:[ which happens to be equivalent to 4&* + ] .
- e.g.:
- Â Â 2 (4&+) 0
- 8
- Â Â (4&*+]) 5
- 25
- Â Â (4&+]) 5
- 25
- Â Â 5 (4&+) 5
- 25
- Â Â 5 (4&+@]^:[) 5
- 25
- Â Â +/5,5#4
- 25
- Dyadic bonded verbs are a bit of an oddball in J that might bite you if you're not sure whether verbs are used monadically or dyadically in a sentence.
- Hope this helps,
- Jan-Pieter
- On Thu, 1 Aug 2024, 08:28 Martin Kreuzer, <in...@airkreuzer.com> wrote:
- Dear all -
- As an exercise I wrote a simple verb which uses recursion:
- gftpr=: monad define ("0)
- Â select. y
-  case. 0 do. 0
-  case.   do. (y*4) + gftpr y-1
- Â end.
- )
- This is what I came up with translating it to tacit:
- gftpr=: 0:`(4&*+$:@<:)@.(1&<:)"0 M.
- Â Â gftpr i.10
- 0 4 12 24 40 60 84 112 144 180
- By mere accident I found, that /this/ verb (having dropped Times (*))
- gftpr=: 0:`(4&+$:@<:)@.(1&<:)"0 M.
- gives me the /same/ result.
- And this I do not understand.
- Â Â jver''
- j9.6.0-beta14/j64avx2/windows/commercial/ www.jso