diff options
-rw-r--r-- | std/Math/Rational.bruijn | 7 | ||||
-rw-r--r-- | std/Math/Real.bruijn | 38 |
2 files changed, 35 insertions, 10 deletions
diff --git a/std/Math/Rational.bruijn b/std/Math/Rational.bruijn index 1f8a8ec..e3842e7 100644 --- a/std/Math/Rational.bruijn +++ b/std/Math/Rational.bruijn @@ -90,3 +90,10 @@ div [[1 ⋅ ~0]] ⧗ Rational → Rational → Rational :test ((+8.0) / (+4.0) =? (+2.0)) (true) :test ((+18.0) / (+12.0) =? (+1.5)) (true) + +# TODO: Regression? Importing this into . won't find Q.eq? anymore + +:import std/List L + +# rational^number +pow-n [L.…!!… (L.iterate (mul 0) (+1.0))] ⧗ Rational → Number → Rational diff --git a/std/Math/Real.bruijn b/std/Math/Real.bruijn index 437a947..59a32e3 100644 --- a/std/Math/Real.bruijn +++ b/std/Math/Real.bruijn @@ -79,39 +79,57 @@ compress b Q.compress ⧗ Real → Real # --- -:import std/List . +:import std/List L # ∑(1/n^2) # converges to 1.6449... -frac-1/n² [^(0 &[[(Q.add 1 op) : N.++0]] start)] ⧗ Real +unary-1/n² [0 &[[(Q.add 1 op) : N.++0]] start [[0]]] ⧗ Real op (+1) : N.--(N.mul 0 0) start (+0.0f) : (+1) # ∑(x^n/n!) = e^x # inefficient Taylor expansion -frac-slow-exp [[^(0 &[[(Q.add 1 op) : N.++0]] start)]] ⧗ Number → Real +unary-slow-exp [[0 &[[(Q.add 1 op) : N.++0]] start [[0]]]] ⧗ Number → Real op (N.pow 3 0) : N.--(N.fac 0) start (+0.0f) : (+1) # ∑(x^n/n!) = e^x # more efficient Taylor expansion -frac-exp [[(0 &[[[[[[[2 1 0 (Q.add 4 op) N.++3]] pow fac]]]]] start) [[[[1]]]]]] ⧗ Number → Real +unary-exp [[0 &[[[[[[[2 1 0 (Q.add 4 op) N.++3]] pow fac]]]]] start [[[[1]]]]]] ⧗ Number → Real pow N.mul 6 4 fac N.mul 1 3 op 1 : N.--0 start [0 (+1) (+1) (+1.0f) (+1)] +# equivalent to unary-exp but with ternary index using infinite list iteration +iter-exp [0 [[[[1]]]]] ∘∘ [L.…!!… (L.iterate &[[[[op]]]] start)] ⧗ Number → Real + start [0 (+1) (+1) (+1.0f) (+1)] + op [[[2 1 0 (Q.add 4 (1 : N.--0)) N.++3]] pow fac] + pow N.mul 5 4 + fac N.mul 1 3 + # real^number -pow-n […!!… (iterate (mul 0) (+1.0r))] ⧗ Real → Number → Real +pow-n [L.…!!… (L.iterate (mul 0) (+1.0r))] ⧗ Real → Number → Real + +lim-exp [[pow-n [(N.add 2 1) : N.--1] 0]] + +iter-slow-ln [0 [[[[1]]]]] ∘∘ [L.…!!… (L.iterate &[[[[op]]]] start)] ⧗ Number → Real + start [0 (+1) (+1) (+0.0f) (+0)] + op [[[2 1 0 (Q.add 4 go) N.++3]] 4 3] + go Q.mul l r + l (+2) : (N.mul (+2) 3) + r Q.pow-n (N.--7 : 7) N.++(N.mul (+2) 3) -exp [y [[[[rec]]]] (+1) (+1.0r) (+1.0r)] - rec (1 / 0) + (3 N.++2 (1 ⋅ 4) (0 ⋅ (number→real 2))) +iter-ln [0 [[[1]]]] ∘∘ [L.…!!… (L.iterate &[[[op]]] start)] ⧗ Number → Real + start [0 (N.--1 : 1) (+0.0f) (+0)] + op [0 pow (Q.add 2 go) N.++1] + pow Q.mul 3 (Q.pow-n (N.--4 : 4) (+2)) + go Q.mul ((+2) : (N.mul (+2) 1)) 3 -ln [y [[[rec]]] (+1) 0] - rec (N.=²?1 -‣ [0] (0 / (number→real 1))) + (2 N.++1 (3 ⋅ 0)) +derive [[[[((3 (0 + 1)) - (3 0)) / 1]] [(+1) : 1] 0]] ⧗ (Real → Real) → (Real → Real) # power function -pow [[exp (0 ⋅ (ln 1))]] ⧗ Real → Real → Real +pow [[iter-exp (0 ⋅ (iter-ln 1))]] ⧗ Real → Real → Real …**… pow |