aboutsummaryrefslogtreecommitdiff
path: root/src/algebra
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2013-05-26 08:26:06 +0000
committerdos-reis <gdr@axiomatics.org>2013-05-26 08:26:06 +0000
commit3d124313d289fd42013e52f600283c99f8d0211a (patch)
tree247fcfab11b70dfa40b711b1653d539673577f3e /src/algebra
parentcbd17230112800448956940165f541d7c49d0dc5 (diff)
downloadopen-axiom-3d124313d289fd42013e52f600283c99f8d0211a.tar.gz
Define lexicographical ordering on Bits in Spad
Diffstat (limited to 'src/algebra')
-rw-r--r--src/algebra/boolean.spad.pamphlet11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/algebra/boolean.spad.pamphlet b/src/algebra/boolean.spad.pamphlet
index de430f03..14abe29e 100644
--- a/src/algebra/boolean.spad.pamphlet
+++ b/src/algebra/boolean.spad.pamphlet
@@ -137,7 +137,6 @@ IndexedBits(mn:Integer): BitAggregate()
import %bitvecref: (%,Integer) -> NonNegativeInteger
from Foreign Builtin
import %bitveceq: (%,%) -> Boolean from Foreign Builtin
- import %bitveclt: (%,%) -> Boolean from Foreign Builtin
import %bitvecnot: % -> % from Foreign Builtin
import %bitvecand: (%,%) -> % from Foreign Builtin
import %bitvecor: (%,%) -> % from Foreign Builtin
@@ -165,7 +164,15 @@ IndexedBits(mn:Integer): BitAggregate()
copy v == %bitveccopy v
#v == %bitveclength v
v = u == %bitveceq(v,u)
- v < u == %bitveclt(v,u)
+ u < v == -- lexicographic
+ nu := #u
+ nv := #v
+ for i in 0.. repeat
+ i >= nu => return or/[%bitvecref(v,j) = 1 for j in i..nv-1]
+ i >= nv => return false
+ %bitvecref(u,i) < %bitvecref(v,i) => return true
+ %bitvecref(u,i) > %bitvecref(v,i) => return false
+
u and v == (#v=#u => %bitvecand(v,u); map("and",v,u))
u or v == (#v=#u => %bitvecor(v,u); map("or", v,u))
xor(v,u) == (#v=#u => %bitvecxor(v,u); map("xor",v,u))