Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update implementation of eq! #269

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 2 additions & 25 deletions src/stdlib.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,28 @@
;; ~-prefix denotes normalized-functions (i.e. output is 0/1)
(defpurefun (and a b) (* a b))
(defpurefun ((~and :binary@bool) a b) (~ (and a b)))
;; WARNING: the "and!" function is unsafe when a and b can be
;; arbirarily large. Unfortunately, Corset has not mechanism for
;; checking this.
(defpurefun ((and! :@loob) a b) (+ a b))
(defpurefun ((~and! :binary@loob) a b) (~ (and! a b)))

;; WARNING: the "or" function is unsafe when a and b can be
;; arbirarily large. Unfortunately, Corset has not mechanism for
;; checking this.
(defpurefun (or a b) (+ a b))
(defpurefun ((~or :binary@bool) a b) (~ (or a b)))
(defpurefun ((or! :@loob) a b) (* a b))
(defpurefun ((~or! :binary@loob) a b) (~ (or! a b)))

(defpurefun ((not :binary@bool :force) (x :binary)) (- 1 x))

(defpurefun ((eq! :@loob :force) x y) (~ (- x y)))
(defpurefun ((eq! :@loob) x y) (- x y))
(defpurefun ((neq! :binary@loob :force) x y) (not (~ (eq! x y))))
(defunalias = eq!)

(defpurefun ((eq :binary@bool :force) (x :binary) (y :binary)) (^ (- x y) 2))
(defpurefun ((eq :binary@bool :force) x y) (- 1 (~ (eq! x y))))
(defpurefun ((neq :binary@bool :force) x y) (eq! x y))


;; Variadic versions of and/or

;; WARNING: the "any" function is unsafe when a and b can be
;; arbirarily large. Unfortunately, Corset has not mechanism for
;; checking this.
(defunalias any +)
;; Variadic variations on and/or
(defunalias any! *)
(defunalias all *)
;; WARNING: the "all" function is unsafe when a and b can be
;; arbirarily large. Unfortunately, Corset has not mechanism for
;; checking this.
(defunalias all! +)

;; Boolean functions
(defpurefun ((is-not-zero :binary@bool) x) (~ x))
(defpurefun ((is-not-zero! :binary@loob :force) x) (- 1 (is-not-zero x)))
(defpurefun ((is-zero :binary@bool :force) x) (- 1 (~ x)))



;; Chronological functions
(defpurefun (next X) (shift X 1))
(defpurefun (prev X) (shift X -1))
Expand Down
2 changes: 1 addition & 1 deletion tests/issue241_a.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

(defconstraint constraint-1 () (is-not-zero! (if (is-zero 1) 1 1)))
(defconstraint constraint-2 () (eq! (is-not-zero! (if (is-zero X) 1 X)) 0))
(defconstraint constraint-3 () (eq! (~and! (is-not-zero! (if (is-zero 0) 1 0)) 0) 0))
(defconstraint constraint-3 () (eq! (or! (is-not-zero! (if (is-zero 0) 1 0)) 0) 0))
(defconstraint constraint-4 () (is-not-zero! (if (is-zero 0) 1 0)))
(defconstraint constraint-5 () (is-not-zero! (if (is-zero X) 1 X)))
4 changes: 2 additions & 2 deletions tests/issue241_c.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
(if-not-zero ST (vanishes!
(if (is-zero (if (is-zero 1) 0 0))
X
(~and! 1 1)))))
(or! 1 1)))))

(defconstraint c1 () (if-not-zero ST (vanishes! (if (is-zero 0) X (~and! 1 1)))))
(defconstraint c1 () (if-not-zero ST (vanishes! (if (is-zero 0) X (or! 1 1)))))

(defconstraint c2 () (if-not-zero ST (vanishes! X)))
4 changes: 2 additions & 2 deletions tests/issue241_d.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

(defconstraint c0 ()
(if-not-zero ST (vanishes!
(if (is-zero (if (is-zero 1) 0 0)) X (~and! 1 1)))))
(if (is-zero (if (is-zero 1) 0 0)) X (or! 1 1)))))

(defconstraint c1 ()
(if-not-zero ST (vanishes! (if (is-zero 0) X (~and! 1 1)))))
(if-not-zero ST (vanishes! (if (is-zero 0) X (or! 1 1)))))

(defconstraint c2 () (if-not-zero ST (vanishes! X)))
2 changes: 1 addition & 1 deletion tests/issue241_e.lisp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(defcolumns ST)
(defconstraint c0 () (is-not-zero! (~and! (if (is-zero 1) 1 1) (if (is-zero 1) 1 1))))
(defconstraint c0 () (is-not-zero! (or! (if (is-zero 1) 1 1) (if (is-zero 1) 1 1))))
Loading