diff options
Diffstat (limited to 'stdlib/source/library/lux/math/modular.lux')
-rw-r--r-- | stdlib/source/library/lux/math/modular.lux | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/stdlib/source/library/lux/math/modular.lux b/stdlib/source/library/lux/math/modular.lux index c12f2111d..183679ce8 100644 --- a/stdlib/source/library/lux/math/modular.lux +++ b/stdlib/source/library/lux/math/modular.lux @@ -31,13 +31,13 @@ [#modulus (Modulus m) #value Int]) - (def: .public (modular modulus value) + (def .public (modular modulus value) (All (_ %) (-> (Modulus %) Int (Mod %))) (abstraction [#modulus modulus #value (i.mod (//.divisor modulus) value)])) (with_template [<name> <type> <side>] - [(def: .public <name> + [(def .public <name> (All (_ %) (-> (Mod %) <type>)) (|>> representation <side>))] @@ -51,25 +51,25 @@ "Expected" (i#encoded (//.divisor modulus)) "Actual" (i#encoded parsed))) - (def: separator + (def separator " mod ") - (def: intL + (def intL (Parser Int) (<>.codec i.decimal (<text>.and (<text>.one_of "-+") (<text>.many <text>.decimal)))) - (def: .public (codec expected) + (def .public (codec expected) (All (_ %) (-> (Modulus %) (Codec Text (Mod %)))) (implementation - (def: (encoded modular) + (def (encoded modular) (let [[_ value] (representation modular)] (all text#composite (i#encoded value) ..separator (i#encoded (//.divisor expected))))) - (def: decoded + (def decoded (<text>.result (do <>.monad [[value _ actual] (all <>.and intL (<text>.this ..separator) intL) @@ -78,7 +78,7 @@ (in (..modular expected value))))))) (with_template [<name> <op>] - [(def: .public (<name> reference subject) + [(def .public (<name> reference subject) (All (_ %) (-> (Mod %) (Mod %) Bit)) (let [[_ reference] (representation reference) [_ subject] (representation subject)] @@ -91,19 +91,19 @@ [>= i.>=] ) - (def: .public equivalence + (def .public equivalence (All (_ %) (Equivalence (Mod %))) (implementation - (def: = ..=))) + (def = ..=))) - (def: .public order + (def .public order (All (_ %) (Order (Mod %))) (implementation - (def: equivalence ..equivalence) - (def: < ..<))) + (def equivalence ..equivalence) + (def < ..<))) (with_template [<name> <op>] - [(def: .public (<name> param subject) + [(def .public (<name> param subject) (All (_ %) (-> (Mod %) (Mod %) (Mod %))) (let [[modulus param] (representation param) [_ subject] (representation subject)] @@ -118,19 +118,19 @@ ) (with_template [<composition> <identity> <monoid>] - [(def: .public (<monoid> modulus) + [(def .public (<monoid> modulus) (All (_ %) (-> (Modulus %) (Monoid (Mod %)))) (implementation - (def: identity + (def identity (..modular modulus <identity>)) - (def: composite + (def composite <composition>)))] [..+ +0 addition] [..* +1 multiplication] ) - (def: .public (inverse modular) + (def .public (inverse modular) (All (_ %) (-> (Mod %) (Maybe (Mod %)))) (let [[modulus value] (representation modular) [[vk mk] gcd] (i.extended_gcd value (//.divisor modulus))] @@ -145,7 +145,7 @@ "Reference" (i#encoded (//.divisor reference)) "Subject" (i#encoded (//.divisor subject)))) -(def: .public (adapter reference subject) +(def .public (adapter reference subject) (All (_ r% s%) (-> (Modulus r%) (Modulus s%) (Try (-> (Mod s%) (Mod r%))))) |