From 79eef70a52ae4aa8f09979e9be15d091b4fdefa4 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 25 Jan 2017 07:03:10 -0400 Subject: - Added a module for continuous logic. --- stdlib/source/lux/math/logic/continuous.lux | 44 ++++++++++++++++++++++++++ stdlib/test/test/lux/math/logic/continuous.lux | 38 ++++++++++++++++++++++ stdlib/test/tests.lux | 3 +- 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 stdlib/source/lux/math/logic/continuous.lux create mode 100644 stdlib/test/test/lux/math/logic/continuous.lux 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 Number]))) + +(def: #export TRUE Deg Deg/top) +(def: #export FALSE Deg Deg/bottom) + +(do-template [ ] + [(def: #export + (-> Deg Deg Deg) + )] + + [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)))) diff --git a/stdlib/test/test/lux/math/logic/continuous.lux b/stdlib/test/test/lux/math/logic/continuous.lux new file mode 100644 index 000000000..883d54a06 --- /dev/null +++ b/stdlib/test/test/lux/math/logic/continuous.lux @@ -0,0 +1,38 @@ +## 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 (codata [io]) + (control monad) + (codata function) + ["R" random] + pipe + ["&" math/logic/continuous]) + lux/test) + +(test: "Operations" + [left R;deg + right R;deg] + ($_ seq + (assert "AND is the minimum." + (let [result (&;and~ left right)] + (and (d.<= left result) + (d.<= right result)))) + + (assert "OR is the maximum." + (let [result (&;or~ left right)] + (and (d.>= left result) + (d.>= right result)))) + + (assert "Double negation results in the original value." + (d.= left (&;not~ (&;not~ left)))) + + (assert "Every value is equivalent to itself." + (and (d.>= left + (&;=~ left left)) + (d.>= right + (&;=~ right right)))) + )) diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index 8e0c165c1..fdcf01457 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -56,7 +56,8 @@ (math ["_;" ratio] ["_;" complex] ## ["_;" random] - ["_;" simple]) + ["_;" simple] + (logic ["_;" continuous])) ## ["_;" macro] (macro ["_;" ast] ["_;" syntax] -- cgit v1.2.3