aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/math
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/math.lux56
-rw-r--r--stdlib/source/lux/math/logic/continuous.lux2
-rw-r--r--stdlib/source/lux/math/logic/fuzzy.lux44
-rw-r--r--stdlib/source/lux/math/random.lux100
4 files changed, 101 insertions, 101 deletions
diff --git a/stdlib/source/lux/math.lux b/stdlib/source/lux/math.lux
index 4f4270c74..c8cfe89df 100644
--- a/stdlib/source/lux/math.lux
+++ b/stdlib/source/lux/math.lux
@@ -1,4 +1,4 @@
-(;module: {#;doc "Common mathematical constants and functions."}
+(.module: {#.doc "Common mathematical constants and functions."}
lux
(lux (control monad
["p" parser "p/" Functor<Parser>])
@@ -11,7 +11,7 @@
## [Values]
(do-template [<name> <value> <doc>]
[(def: #export <name>
- {#;doc <doc>}
+ {#.doc <doc>}
Frac
<value>)]
@@ -75,14 +75,14 @@
(pow 2.0 catB))))
(def: #export (gcd a b)
- {#;doc "Greatest Common Divisor."}
+ {#.doc "Greatest Common Divisor."}
(-> Nat Nat Nat)
(case b
+0 a
_ (gcd b (n/% b a))))
(def: #export (lcm x y)
- {#;doc "Least Common Multiple."}
+ {#.doc "Least Common Multiple."}
(-> Nat Nat Nat)
(case [x y]
(^or [_ +0] [+0 _])
@@ -101,37 +101,37 @@
(def: infix^
(Syntax Infix)
- (<| p;rec (function [infix^])
- ($_ p;alt
- ($_ p;either
- (p/map code;bool s;bool)
- (p/map code;nat s;nat)
- (p/map code;int s;int)
- (p/map code;deg s;deg)
- (p/map code;frac s;frac)
- (p/map code;text s;text)
- (p/map code;symbol s;symbol)
- (p/map code;tag s;tag))
- (s;form (p;many s;any))
- (s;tuple (p;seq s;any infix^))
- (s;tuple ($_ p;either
- (do p;Monad<Parser>
- [_ (s;this (' #and))
+ (<| p.rec (function [infix^])
+ ($_ p.alt
+ ($_ p.either
+ (p/map code.bool s.bool)
+ (p/map code.nat s.nat)
+ (p/map code.int s.int)
+ (p/map code.deg s.deg)
+ (p/map code.frac s.frac)
+ (p/map code.text s.text)
+ (p/map code.symbol s.symbol)
+ (p/map code.tag s.tag))
+ (s.form (p.many s.any))
+ (s.tuple (p.seq s.any infix^))
+ (s.tuple ($_ p.either
+ (do p.Monad<Parser>
+ [_ (s.this (' #and))
init-subject infix^
- init-op s;any
+ init-op s.any
init-param infix^
- steps (p;some (p;seq s;any infix^))]
- (wrap (product;right (L/fold (function [[op param] [subject [_subject _op _param]]]
+ steps (p.some (p.seq s.any infix^))]
+ (wrap (product.right (L/fold (function [[op param] [subject [_subject _op _param]]]
[param [(#Binary _subject _op _param)
(` and)
(#Binary subject op param)]])
[init-param [init-subject init-op init-param]]
steps))))
- (do p;Monad<Parser>
+ (do p.Monad<Parser>
[init-subject infix^
- init-op s;any
+ init-op s.any
init-param infix^
- steps (p;some (p;seq s;any infix^))]
+ steps (p.some (p.seq s.any infix^))]
(wrap (L/fold (function [[op param] [_subject _op _param]]
[(#Binary _subject _op _param) op param])
[init-subject init-op init-param]
@@ -146,7 +146,7 @@
value
(#Call parts)
- (code;form parts)
+ (code.form parts)
(#Unary op subject)
(` ((~ op) (~ (infix-to-prefix subject))))
@@ -156,7 +156,7 @@
))
(syntax: #export (infix [expr infix^])
- {#;doc (doc "Infix math syntax."
+ {#.doc (doc "Infix math syntax."
(infix [x i/* 10])
(infix [[x i/+ y] i/* [x i/- y]])
(infix [sin [x i/+ y]])
diff --git a/stdlib/source/lux/math/logic/continuous.lux b/stdlib/source/lux/math/logic/continuous.lux
index 0b385dae2..6e9de446a 100644
--- a/stdlib/source/lux/math/logic/continuous.lux
+++ b/stdlib/source/lux/math/logic/continuous.lux
@@ -1,4 +1,4 @@
-(;module:
+(.module:
lux
(lux (data [number "Deg/" Interval<Deg>])))
diff --git a/stdlib/source/lux/math/logic/fuzzy.lux b/stdlib/source/lux/math/logic/fuzzy.lux
index ba8da7d40..ca1ad0512 100644
--- a/stdlib/source/lux/math/logic/fuzzy.lux
+++ b/stdlib/source/lux/math/logic/fuzzy.lux
@@ -1,4 +1,4 @@
-(;module:
+(.module:
lux
(lux (data [number "Deg/" Interval<Deg>]
(coll [list]
@@ -17,46 +17,46 @@
(def: #export (union left right)
(All [a] (-> (Fuzzy a) (Fuzzy a) (Fuzzy a)))
(function [elem]
- (&;~or (membership elem left)
+ (&.~or (membership elem left)
(membership elem right))))
(def: #export (intersection left right)
(All [a] (-> (Fuzzy a) (Fuzzy a) (Fuzzy a)))
(function [elem]
- (&;~and (membership elem left)
+ (&.~and (membership elem left)
(membership elem right))))
(def: #export (complement set)
(All [a] (-> (Fuzzy a) (Fuzzy a)))
(function [elem]
- (&;~not (membership elem set))))
+ (&.~not (membership elem set))))
(def: #export (difference sub base)
(All [a] (-> (Fuzzy a) (Fuzzy a) (Fuzzy a)))
(function [elem]
- (&;~and (membership elem base)
- (&;~not (membership elem sub)))))
+ (&.~and (membership elem base)
+ (&.~not (membership elem sub)))))
(def: #export (from-predicate predicate)
(All [a] (-> (-> a Bool) (Fuzzy a)))
(function [elem]
(if (predicate elem)
- &;~true
- &;~false)))
+ &.~true
+ &.~false)))
(def: #export (from-set set)
- (All [a] (-> (set;Set a) (Fuzzy a)))
- (from-predicate (set;member? set)))
+ (All [a] (-> (set.Set a) (Fuzzy a)))
+ (from-predicate (set.member? set)))
(do-template [<ascending> <descending> <gradient> <type> <lt> <gt> <lte> <gte> <sub> <div> <post>]
[(def: (<ascending> from to)
(-> <type> <type> (Fuzzy <type>))
(function [elem]
(cond (<lte> from elem)
- &;~false
+ &.~false
(<gte> to elem)
- &;~true
+ &.~true
## in the middle...
(<post> (<div> (<sub> from to)
@@ -66,10 +66,10 @@
(-> <type> <type> (Fuzzy <type>))
(function [elem]
(cond (<lte> from elem)
- &;~true
+ &.~true
(<gte> to elem)
- &;~false
+ &.~false
## in the middle...
(<post> (<div> (<sub> from to)
@@ -88,7 +88,7 @@
(do-template [<triangle> <trapezoid> <type> <ascending> <descending> <lt>]
[(def: #export (<triangle> bottom middle top)
(-> <type> <type> <type> (Fuzzy <type>))
- (case (list;sort <lt> (list bottom middle top))
+ (case (list.sort <lt> (list bottom middle top))
(^ (list bottom middle top))
(intersection (<ascending> bottom middle)
(<descending> middle top))
@@ -98,7 +98,7 @@
(def: #export (<trapezoid> bottom middle-bottom middle-top top)
(-> <type> <type> <type> <type> (Fuzzy <type>))
- (case (list;sort <lt> (list bottom middle-bottom middle-top top))
+ (case (list.sort <lt> (list bottom middle-bottom middle-top top))
(^ (list bottom middle-bottom middle-top top))
(intersection (<ascending> bottom middle-bottom)
(<descending> middle-top top))
@@ -113,15 +113,15 @@
(def: #export (gaussian deviation center)
(-> Frac Frac (Fuzzy Frac))
(function [elem]
- (let [scale (|> deviation (math;pow 2.0) (f/* 2.0))
+ (let [scale (|> deviation (math.pow 2.0) (f/* 2.0))
membership (|> elem
(f/- center)
- (math;pow 2.0)
+ (math.pow 2.0)
(f/* -1.0)
(f// scale)
- math;exp)]
+ math.exp)]
(if (f/= 1.0 membership)
- &;~true
+ &.~true
(frac-to-deg membership)))))
(def: #export (cut treshold set)
@@ -129,8 +129,8 @@
(function [elem]
(let [membership (set elem)]
(if (d/> treshold membership)
- (|> membership (d/- treshold) (d/* &;~true))
- &;~false))))
+ (|> membership (d/- treshold) (d/* &.~true))
+ &.~false))))
(def: #export (to-predicate treshold set)
(All [a] (-> Deg (Fuzzy a) (-> a Bool)))
diff --git a/stdlib/source/lux/math/random.lux b/stdlib/source/lux/math/random.lux
index e8b552b1c..e3c7fd751 100644
--- a/stdlib/source/lux/math/random.lux
+++ b/stdlib/source/lux/math/random.lux
@@ -1,4 +1,4 @@
-(;module: {#;doc "Pseudo-random number generation (PRNG) algorithms."}
+(.module: {#.doc "Pseudo-random number generation (PRNG) algorithms."}
[lux #- list]
(lux (control [functor #+ Functor]
[applicative #+ Applicative]
@@ -21,11 +21,11 @@
))
(type: #export #rec PRNG
- {#;doc "An abstract way to represent any PRNG."}
+ {#.doc "An abstract way to represent any PRNG."}
(-> Unit [PRNG Nat]))
(type: #export (Random a)
- {#;doc "A producer of random values based on a PRNG."}
+ {#.doc "A producer of random values based on a PRNG."}
(-> PRNG [PRNG a]))
(struct: #export _ (Functor Random)
@@ -56,7 +56,7 @@
(fa state')))))
(def: #export (filter pred gen)
- {#;doc "Retries the generator until the output satisfies a predicate."}
+ {#.doc "Retries the generator until the output satisfies a predicate."}
(All [a] (-> (-> a Bool) (Random a) (Random a)))
(do Monad<Random>
[sample gen]
@@ -69,7 +69,7 @@
(function [prng]
(let [[prng left] (prng [])
[prng right] (prng [])]
- [prng (n/+ (bit;shift-left +32 left)
+ [prng (n/+ (bit.shift-left +32 left)
right)])))
(def: #export int
@@ -77,20 +77,20 @@
(function [prng]
(let [[prng left] (prng [])
[prng right] (prng [])]
- [prng (nat-to-int (n/+ (bit;shift-left +32 left)
+ [prng (nat-to-int (n/+ (bit.shift-left +32 left)
right))])))
(def: #export bool
(Random Bool)
(function [prng]
(let [[prng output] (prng [])]
- [prng (|> output (bit;and +1) (n/= +1))])))
+ [prng (|> output (bit.and +1) (n/= +1))])))
(def: (bits n)
(-> Nat (Random Nat))
(function [prng]
(let [[prng output] (prng [])]
- [prng (bit;shift-right (n/- n +64) output)])))
+ [prng (bit.shift-right (n/- n +64) output)])))
(def: #export frac
(Random Frac)
@@ -98,10 +98,10 @@
[left (bits +26)
right (bits +27)]
(wrap (|> right
- (n/+ (bit;shift-left +27 left))
+ (n/+ (bit.shift-left +27 left))
nat-to-int
int-to-frac
- (f// (|> +1 (bit;shift-left +53) nat-to-int int-to-frac))))))
+ (f// (|> +1 (bit.shift-left +53) nat-to-int int-to-frac))))))
(def: #export deg
(Random Deg)
@@ -114,7 +114,7 @@
(do Monad<Random>
[x char-gen
xs (text' char-gen (n/dec size))]
- (wrap (text/compose (text;from-code x) xs)))))
+ (wrap (text/compose (text.from-code x) xs)))))
(type: Char-Range [Nat Nat])
@@ -137,13 +137,13 @@
(-> Char-Range Nat Bool)
(and (n/>= from char) (n/<= to char)))
-(def: unicode-ceiling (n/inc (product;right CJK-Compatibility-Ideographs-Supplement)))
+(def: unicode-ceiling (n/inc (product.right CJK-Compatibility-Ideographs-Supplement)))
(def: #export unicode
(Random Nat)
- (|> ;;nat
+ (|> ..nat
(:: Monad<Random> map (n/% unicode-ceiling))
- (;;filter (function [raw]
+ (..filter (function [raw]
## From "Basic Latin" to "Syriac"
(or (n/<= (hex "+074F") raw)
(within? Thaana raw)
@@ -208,12 +208,12 @@
right <gen>]
(wrap (<ctor> left right))))]
- [ratio r;Ratio r;ratio nat]
- [complex c;Complex c;complex frac]
+ [ratio r.Ratio r.ratio nat]
+ [complex c.Complex c.complex frac]
)
(def: #export (seq left right)
- {#;doc "Sequencing combinator."}
+ {#.doc "Sequencing combinator."}
(All [a b] (-> (Random a) (Random b) (Random [a b])))
(do Monad<Random>
[=left left
@@ -221,7 +221,7 @@
(wrap [=left =right])))
(def: #export (alt left right)
- {#;doc "Heterogeneous alternative combinator."}
+ {#.doc "Heterogeneous alternative combinator."}
(All [a b] (-> (Random a) (Random b) (Random (| a b))))
(do Monad<Random>
[? bool]
@@ -234,7 +234,7 @@
(wrap (+1 =right))))))
(def: #export (either left right)
- {#;doc "Homogeneous alternative combinator."}
+ {#.doc "Homogeneous alternative combinator."}
(All [a] (-> (Random a) (Random a) (Random a)))
(do Monad<Random>
[? bool]
@@ -243,7 +243,7 @@
right)))
(def: #export (rec gen)
- {#;doc "A combinator for producing recursive random generators."}
+ {#.doc "A combinator for producing recursive random generators."}
(All [a] (-> (-> (Random a) (Random a)) (Random a)))
(function [state]
(let [gen' (gen (rec gen))]
@@ -256,8 +256,8 @@
(if some?
(do @
[value value-gen]
- (wrap (#;Some value)))
- (wrap #;None))))
+ (wrap (#.Some value)))
+ (wrap #.None))))
(do-template [<name> <type> <zero> <plus>]
[(def: #export (<name> size value-gen)
@@ -269,8 +269,8 @@
(wrap (<plus> x xs)))
(:: Monad<Random> wrap <zero>)))]
- [list List (;list) #;Cons]
- [sequence Sequence sequence;empty sequence;add]
+ [list List (.list) #.Cons]
+ [sequence Sequence sequence.empty sequence.add]
)
(do-template [<name> <type> <ctor>]
@@ -280,9 +280,9 @@
[values (list size value-gen)]
(wrap (|> values <ctor>))))]
- [array Array array;from-list]
- [queue Queue queue;from-list]
- [stack Stack (list/fold stack;push stack;empty)]
+ [array Array array.from-list]
+ [queue Queue queue.from-list]
+ [stack Stack (list/fold stack.push stack.empty)]
)
(def: #export (set Hash<a> size value-gen)
@@ -293,11 +293,11 @@
(loop [_ []]
(do @
[x value-gen
- #let [xs+ (set;add x xs)]]
- (if (n/= size (set;size xs+))
+ #let [xs+ (set.add x xs)]]
+ (if (n/= size (set.size xs+))
(wrap xs+)
(recur [])))))
- (:: Monad<Random> wrap (set;new Hash<a>))))
+ (:: Monad<Random> wrap (set.new Hash<a>))))
(def: #export (dict Hash<a> size key-gen value-gen)
(All [k v] (-> (Hash k) Nat (Random k) (Random v) (Random (Dict k v))))
@@ -308,11 +308,11 @@
(do @
[k key-gen
v value-gen
- #let [kv+ (dict;put k v kv)]]
- (if (n/= size (dict;size kv+))
+ #let [kv+ (dict.put k v kv)]]
+ (if (n/= size (dict.size kv+))
(wrap kv+)
(recur [])))))
- (:: Monad<Random> wrap (dict;new Hash<a>))))
+ (:: Monad<Random> wrap (dict.new Hash<a>))))
(def: #export (run prng calc)
(All [a] (-> PRNG (Random a) [PRNG a]))
@@ -321,49 +321,49 @@
(def: pcg-32-magic-mult Nat +6364136223846793005)
(def: #export (pcg-32 [inc seed])
- {#;doc "An implementation of the PCG32 algorithm.
+ {#.doc "An implementation of the PCG32 algorithm.
For more information, please see: http://www.pcg-random.org/"}
(-> [Nat Nat] PRNG)
(function [_]
(let [seed' (|> seed (n/* pcg-32-magic-mult) (n/+ inc))
- xor-shifted (|> seed (bit;shift-right +18) (bit;xor seed) (bit;shift-right +27))
- rot (|> seed (bit;shift-right +59))]
- [(pcg-32 [inc seed']) (bit;rotate-right rot xor-shifted)]
+ xor-shifted (|> seed (bit.shift-right +18) (bit.xor seed) (bit.shift-right +27))
+ rot (|> seed (bit.shift-right +59))]
+ [(pcg-32 [inc seed']) (bit.rotate-right rot xor-shifted)]
)))
(def: #export (xoroshiro-128+ [s0 s1])
- {#;doc "An implementation of the Xoroshiro128+ algorithm.
+ {#.doc "An implementation of the Xoroshiro128+ algorithm.
For more information, please see: http://xoroshiro.di.unimi.it/"}
(-> [Nat Nat] PRNG)
(function [_]
(let [result (n/+ s0 s1)
- s01 (bit;xor s0 s1)
- s0' (|> (bit;rotate-left +55 s0)
- (bit;xor s01)
- (bit;xor (bit;shift-left +14 s01)))
- s1' (bit;rotate-left +36 s01)]
+ s01 (bit.xor s0 s1)
+ s0' (|> (bit.rotate-left +55 s0)
+ (bit.xor s01)
+ (bit.xor (bit.shift-left +14 s01)))
+ s1' (bit.rotate-left +36 s01)]
[(xoroshiro-128+ [s0' s1']) result])
))
(def: (swap from to vec)
(All [a] (-> Nat Nat (Sequence a) (Sequence a)))
(|> vec
- (sequence;put to (maybe;assume (sequence;nth from vec)))
- (sequence;put from (maybe;assume (sequence;nth to vec)))))
+ (sequence.put to (maybe.assume (sequence.nth from vec)))
+ (sequence.put from (maybe.assume (sequence.nth to vec)))))
(def: #export (shuffle seed sequence)
- {#;doc "Shuffle a sequence randomly based on a seed value."}
+ {#.doc "Shuffle a sequence randomly based on a seed value."}
(All [a] (-> Nat (Sequence a) (Sequence a)))
- (let [_size (sequence;size sequence)
- _shuffle (monad;fold Monad<Random>
+ (let [_size (sequence.size sequence)
+ _shuffle (monad.fold Monad<Random>
(function [idx vec]
(do Monad<Random>
[rand nat]
(wrap (swap idx (n/% _size rand) vec))))
sequence
- (list;n/range +0 (n/dec _size)))]
+ (list.n/range +0 (n/dec _size)))]
(|> _shuffle
(run (pcg-32 [+123 seed]))
- product;right)))
+ product.right)))