diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/test/lux/math/number/complex.lux | 288 |
1 files changed, 144 insertions, 144 deletions
diff --git a/stdlib/source/test/lux/math/number/complex.lux b/stdlib/source/test/lux/math/number/complex.lux index a705bbb0e..d2e2d152a 100644 --- a/stdlib/source/test/lux/math/number/complex.lux +++ b/stdlib/source/test/lux/math/number/complex.lux @@ -50,20 +50,20 @@ [real ..dimension imaginary ..dimension] (all _.and - (_.cover [/.complex] - (and (let [r+i (/.complex real imaginary)] - (and (f.= real (the /.#real r+i)) - (f.= imaginary (the /.#imaginary r+i)))) - (let [r+i (/.complex real)] - (and (f.= real (the /.#real r+i)) - (f.= +0.0 (the /.#imaginary r+i)))))) - (_.cover [/.approximately?] - (/.approximately? ..margin_of_error - (/.complex real imaginary) - (/.complex real imaginary))) - (_.cover [/.not_a_number?] - (and (/.not_a_number? (/.complex f.not_a_number imaginary)) - (/.not_a_number? (/.complex real f.not_a_number)))) + (_.coverage [/.complex] + (and (let [r+i (/.complex real imaginary)] + (and (f.= real (the /.#real r+i)) + (f.= imaginary (the /.#imaginary r+i)))) + (let [r+i (/.complex real)] + (and (f.= real (the /.#real r+i)) + (f.= +0.0 (the /.#imaginary r+i)))))) + (_.coverage [/.approximately?] + (/.approximately? ..margin_of_error + (/.complex real imaginary) + (/.complex real imaginary))) + (_.coverage [/.not_a_number?] + (and (/.not_a_number? (/.complex f.not_a_number imaginary)) + (/.not_a_number? (/.complex real f.not_a_number)))) ))) (def: constant @@ -72,20 +72,20 @@ [sample ..random dimension ..dimension] (all _.and - (_.cover [/.zero] - (/.= /.zero (/.* /.zero sample))) - (_.cover [/.+one] - (/.= sample (/.* /.+one sample))) - (_.cover [/.-one] - (and (/.= /.zero - (/.+ sample - (/.* /.-one sample))) - (/.= sample (/.* /.-one (/.* /.-one sample))))) - (_.cover [/.i] - (and (/.= (/.complex +0.0 dimension) - (/.* /.i (/.complex dimension))) - (/.= (/.* /.-one sample) - (/.* /.i (/.* /.i sample))))) + (_.coverage [/.zero] + (/.= /.zero (/.* /.zero sample))) + (_.coverage [/.+one] + (/.= sample (/.* /.+one sample))) + (_.coverage [/.-one] + (and (/.= /.zero + (/.+ sample + (/.* /.-one sample))) + (/.= sample (/.* /.-one (/.* /.-one sample))))) + (_.coverage [/.i] + (and (/.= (/.complex +0.0 dimension) + (/.* /.i (/.complex dimension))) + (/.= (/.* /.-one sample) + (/.* /.i (/.* /.i sample))))) ))) (def: absolute_value&argument @@ -94,32 +94,32 @@ [real ..dimension imaginary ..dimension] (all _.and - (_.cover [/.abs] - (let [normal! - (let [r+i (/.complex real imaginary)] - (and (f.>= (f.abs real) (/.abs r+i)) - (f.>= (f.abs imaginary) (/.abs r+i)))) + (_.coverage [/.abs] + (let [normal! + (let [r+i (/.complex real imaginary)] + (and (f.>= (f.abs real) (/.abs r+i)) + (f.>= (f.abs imaginary) (/.abs r+i)))) - not_a_number! - (and (f.not_a_number? (/.abs (/.complex f.not_a_number imaginary))) - (f.not_a_number? (/.abs (/.complex real f.not_a_number)))) + not_a_number! + (and (f.not_a_number? (/.abs (/.complex f.not_a_number imaginary))) + (f.not_a_number? (/.abs (/.complex real f.not_a_number)))) - infinity! - (and (f.= f.positive_infinity (/.abs (/.complex f.positive_infinity imaginary))) - (f.= f.positive_infinity (/.abs (/.complex real f.positive_infinity))) - (f.= f.positive_infinity (/.abs (/.complex f.negative_infinity imaginary))) - (f.= f.positive_infinity (/.abs (/.complex real f.negative_infinity))))] - (and normal! - not_a_number! - infinity!))) + infinity! + (and (f.= f.positive_infinity (/.abs (/.complex f.positive_infinity imaginary))) + (f.= f.positive_infinity (/.abs (/.complex real f.positive_infinity))) + (f.= f.positive_infinity (/.abs (/.complex f.negative_infinity imaginary))) + (f.= f.positive_infinity (/.abs (/.complex real f.negative_infinity))))] + (and normal! + not_a_number! + infinity!))) ... https://en.wikipedia.org/wiki/Argument_(complex_analysis)#Identities - (_.cover [/.argument] - (let [sample (/.complex real imaginary)] - (or (/.= /.zero sample) - (/.approximately? ..margin_of_error - sample - (/.*' (/.abs sample) - (/.exp (/.* /.i (/.complex (/.argument sample))))))))) + (_.coverage [/.argument] + (let [sample (/.complex real imaginary)] + (or (/.= /.zero sample) + (/.approximately? ..margin_of_error + sample + (/.*' (/.abs sample) + (/.exp (/.* /.i (/.complex (/.argument sample))))))))) ))) (def: number @@ -129,40 +129,40 @@ y ..random factor ..dimension] (all _.and - (_.cover [/.+] - (let [z (/.+ y x)] - (and (/.= z - (/.complex (f.+ (the /.#real y) - (the /.#real x)) - (f.+ (the /.#imaginary y) - (the /.#imaginary x))))))) - (_.cover [/.-] - (let [normal! - (let [z (/.- y x)] - (and (/.= z - (/.complex (f.- (the /.#real y) - (the /.#real x)) - (f.- (the /.#imaginary y) - (the /.#imaginary x)))))) + (_.coverage [/.+] + (let [z (/.+ y x)] + (and (/.= z + (/.complex (f.+ (the /.#real y) + (the /.#real x)) + (f.+ (the /.#imaginary y) + (the /.#imaginary x))))))) + (_.coverage [/.-] + (let [normal! + (let [z (/.- y x)] + (and (/.= z + (/.complex (f.- (the /.#real y) + (the /.#real x)) + (f.- (the /.#imaginary y) + (the /.#imaginary x)))))) - inverse! - (and (|> x (/.+ y) (/.- y) (/.approximately? ..margin_of_error x)) - (|> x (/.- y) (/.+ y) (/.approximately? ..margin_of_error x)))] - (and normal! - inverse!))) - (_.cover [/.* /./] - (|> x (/.* y) (/./ y) (/.approximately? ..margin_of_error x))) - (_.cover [/.*' /./'] - (|> x (/.*' factor) (/./' factor) (/.approximately? ..margin_of_error x))) - (_.cover [/.%] - (let [rem (/.% y x) - quotient (|> x (/.- rem) (/./ y)) - floored (|> quotient - (revised /.#real f.floor) - (revised /.#imaginary f.floor))] - (/.approximately? +0.000000000001 - x - (|> quotient (/.* y) (/.+ rem))))) + inverse! + (and (|> x (/.+ y) (/.- y) (/.approximately? ..margin_of_error x)) + (|> x (/.- y) (/.+ y) (/.approximately? ..margin_of_error x)))] + (and normal! + inverse!))) + (_.coverage [/.* /./] + (|> x (/.* y) (/./ y) (/.approximately? ..margin_of_error x))) + (_.coverage [/.*' /./'] + (|> x (/.*' factor) (/./' factor) (/.approximately? ..margin_of_error x))) + (_.coverage [/.%] + (let [rem (/.% y x) + quotient (|> x (/.- rem) (/./ y)) + floored (|> quotient + (revised /.#real f.floor) + (revised /.#imaginary f.floor))] + (/.approximately? +0.000000000001 + x + (|> quotient (/.* y) (/.+ rem))))) ))) (def: conjugate&reciprocal&signum&negation @@ -170,38 +170,38 @@ (do random.monad [x ..random] (all _.and - (_.cover [/.conjugate] - (let [cx (/.conjugate x)] - (and (f.= (the /.#real x) - (the /.#real cx)) - (f.= (f.opposite (the /.#imaginary x)) - (the /.#imaginary cx))))) - (_.cover [/.reciprocal] - (let [reciprocal! - (|> x (/.* (/.reciprocal x)) (/.approximately? ..margin_of_error /.+one)) - - own_inverse! - (|> x /.reciprocal /.reciprocal (/.approximately? ..margin_of_error x))] - (and reciprocal! - own_inverse!))) - (_.cover [/.signum] - ... Absolute value of signum is always root_2(2), 1 or 0. - (let [signum_abs (|> x /.signum /.abs)] - (or (f.= +0.0 signum_abs) - (f.= +1.0 signum_abs) - (f.= (f.pow +0.5 +2.0) signum_abs)))) - (_.cover [/.opposite] - (let [own_inverse! - (let [there (/.opposite x) - back_again (/.opposite there)] - (and (not (/.= there x)) - (/.= back_again x))) + (_.coverage [/.conjugate] + (let [cx (/.conjugate x)] + (and (f.= (the /.#real x) + (the /.#real cx)) + (f.= (f.opposite (the /.#imaginary x)) + (the /.#imaginary cx))))) + (_.coverage [/.reciprocal] + (let [reciprocal! + (|> x (/.* (/.reciprocal x)) (/.approximately? ..margin_of_error /.+one)) + + own_inverse! + (|> x /.reciprocal /.reciprocal (/.approximately? ..margin_of_error x))] + (and reciprocal! + own_inverse!))) + (_.coverage [/.signum] + ... Absolute value of signum is always root_2(2), 1 or 0. + (let [signum_abs (|> x /.signum /.abs)] + (or (f.= +0.0 signum_abs) + (f.= +1.0 signum_abs) + (f.= (f.pow +0.5 +2.0) signum_abs)))) + (_.coverage [/.opposite] + (let [own_inverse! + (let [there (/.opposite x) + back_again (/.opposite there)] + (and (not (/.= there x)) + (/.= back_again x))) - absolute! - (f.= (/.abs x) - (/.abs (/.opposite x)))] - (and own_inverse! - absolute!))) + absolute! + (f.= (/.abs x) + (/.abs (/.opposite x)))] + (and own_inverse! + absolute!))) ))) (def: (trigonometric_symmetry forward backward angle) @@ -214,30 +214,30 @@ (do [! random.monad] [angle ..angle] (all _.and - (_.cover [/.sin /.asin] - (trigonometric_symmetry /.sin /.asin angle)) - (_.cover [/.cos /.acos] - (trigonometric_symmetry /.cos /.acos angle)) - (_.cover [/.tan /.atan] - (trigonometric_symmetry /.tan /.atan angle))))) + (_.coverage [/.sin /.asin] + (trigonometric_symmetry /.sin /.asin angle)) + (_.coverage [/.cos /.acos] + (trigonometric_symmetry /.cos /.acos angle)) + (_.coverage [/.tan /.atan] + (trigonometric_symmetry /.tan /.atan angle))))) (def: hyperbolic Test (do [! random.monad] [angle ..angle] (all _.and - (_.cover [/.sinh] - (/.approximately? ..margin_of_error - (|> angle (/.* /.i) /.sin (/.* /.i) (/.* /.-one)) - (/.sinh angle))) - (_.cover [/.cosh] - (/.approximately? ..margin_of_error - (|> angle (/.* /.i) /.cos) - (/.cosh angle))) - (_.cover [/.tanh] - (/.approximately? ..margin_of_error - (|> angle (/.* /.i) /.tan (/.* /.i) (/.* /.-one)) - (/.tanh angle))) + (_.coverage [/.sinh] + (/.approximately? ..margin_of_error + (|> angle (/.* /.i) /.sin (/.* /.i) (/.* /.-one)) + (/.sinh angle))) + (_.coverage [/.cosh] + (/.approximately? ..margin_of_error + (|> angle (/.* /.i) /.cos) + (/.cosh angle))) + (_.coverage [/.tanh] + (/.approximately? ..margin_of_error + (|> angle (/.* /.i) /.tan (/.* /.i) (/.* /.-one)) + (/.tanh angle))) ))) (def: exponentiation&logarithm @@ -245,12 +245,12 @@ (do random.monad [x ..random] (all _.and - (_.cover [/.pow /.root_2] - (|> x (/.pow (/.complex +2.0)) /.root_2 (/.approximately? ..margin_of_error x))) - (_.cover [/.pow'] - (|> x (/.pow' +2.0) (/.pow' +0.5) (/.approximately? ..margin_of_error x))) - (_.cover [/.log /.exp] - (|> x /.log /.exp (/.approximately? ..margin_of_error x))) + (_.coverage [/.pow /.root_2] + (|> x (/.pow (/.complex +2.0)) /.root_2 (/.approximately? ..margin_of_error x))) + (_.coverage [/.pow'] + (|> x (/.pow' +2.0) (/.pow' +0.5) (/.approximately? ..margin_of_error x))) + (_.coverage [/.log /.exp] + (|> x /.log /.exp (/.approximately? ..margin_of_error x))) ))) (def: root @@ -258,11 +258,11 @@ (do [! random.monad] [sample ..random degree (|> random.nat (# ! each (|>> (n.max 1) (n.% 5))))] - (_.cover [/.roots] - (|> sample - (/.roots degree) - (list#each (/.pow' (|> degree .int int.frac))) - (list.every? (/.approximately? ..margin_of_error sample)))))) + (_.coverage [/.roots] + (|> sample + (/.roots degree) + (list#each (/.pow' (|> degree .int int.frac))) + (list.every? (/.approximately? ..margin_of_error sample)))))) (def: .public test Test |