blob: 245f45f389f66d72efb674c953f241e6a528d0c0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
:import std/Pair .
:import std/Combinator .
:import std/Number/Unary .
qadd &[[&[[p : q]]]] ⧗ Rational → Rational → Rational
p (3 ⋅ ++0) + (1 ⋅ ++2)
q (2 ⋅ 0) + (2 + 0)
fac [[1 [[0 (1 [[2 1 (1 0)]])]] [1] i]] ⧗ Unary → Unary
# challenge: smallest, yet fastest converging, π ratio calculation
# naive
v1-pi/2 [0 &[[op]] start [[1]]]
start ((+0u) : (+0u)) : (+0u)
op (qadd 1 (enum : --denom)) : ++0
enum (0 (+2u)) ⋅ ((+2u) (fac 0))
denom fac ++((+2u) ⋅ 0)
dfac [[1 [[0 (1 [[2 1 (1 (1 0))]])]] [1] i]] ⧗ Unary → Unary
# double factorial
# dfac and fac could be shared!
v2-pi/2 [0 &[[op]] start [[1]]]
start ((+0u) : (+0u)) : (+0u)
op (qadd 1 (enum : --denom)) : ++0
enum fac 0
denom dfac ++0
|