aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
authorEduardo Julian2017-01-25 07:03:10 -0400
committerEduardo Julian2017-01-25 07:03:10 -0400
commit79eef70a52ae4aa8f09979e9be15d091b4fdefa4 (patch)
tree6317627854abad1349863122d645eb090ec4717f /stdlib/source
parentf8c2389db4a9b3239b00b9d209237d5116e12e3c (diff)
- Added a module for continuous logic.
Diffstat (limited to 'stdlib/source')
-rw-r--r--stdlib/source/lux/math/logic/continuous.lux44
1 files changed, 44 insertions, 0 deletions
diff --git a/stdlib/source/lux/math/logic/continuous.lux b/stdlib/source/lux/math/logic/continuous.lux
new file mode 100644
index 000000000..ccd5795d7
--- /dev/null
+++ b/stdlib/source/lux/math/logic/continuous.lux
@@ -0,0 +1,44 @@
+## Copyright (c) Eduardo Julian. All rights reserved.
+## This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+## If a copy of the MPL was not distributed with this file,
+## You can obtain one at http://mozilla.org/MPL/2.0/.
+
+(;module:
+ lux
+ (lux (data [number "Deg/" Bounded<Deg> Number<Deg>])))
+
+(def: #export TRUE Deg Deg/top)
+(def: #export FALSE Deg Deg/bottom)
+
+(do-template [<name> <chooser>]
+ [(def: #export <name>
+ (-> Deg Deg Deg)
+ <chooser>)]
+
+ [and~ d.min]
+ [or~ d.max]
+ )
+
+(def: #export not~
+ (-> Deg Deg)
+ Deg/negate)
+
+(def: #export (implies~ consequent antecedent)
+ (-> Deg Deg Deg)
+ (or~ (not~ antecedent)
+ consequent))
+
+(def: #export (includes~ sub super)
+ (-> Deg Deg Deg)
+ (let [-sub (not~ sub)
+ sum (d.+ -sub super)
+ no-overflow? (and (d.>= -sub sum)
+ (d.>= super sum))]
+ (if no-overflow?
+ sum
+ TRUE)))
+
+(def: #export (=~ left right)
+ (-> Deg Deg Deg)
+ (and~ (or~ (not~ left) right)
+ (or~ left (not~ right))))