Division and fixed pred

This commit is contained in:
2026-08-30 09:56:22 -05:00
parent 079643e2b7
commit dfcaf14404
2 changed files with 88 additions and 12 deletions

View File

@@ -178,18 +178,15 @@ andLazy? = (a bK :
pred = y (self : triage
0
(_ : 0)
0
(bit rest :
matchBool
(matchBool
ifLazy
bit
(_ : matchBool
(t t rest)
0
(pair 0 rest)
(equal? rest 0))
(matchBool
0
(pair 1 (self rest))
(equal? rest 0))
bit))
rest)
(_ : t (t t) (self rest))))
isZero? = triage true (_ : false) (_ _ : false)
@@ -231,6 +228,24 @@ mul = y (self a b :
(_ : 0)
(_ : add a (self a (pred b))))
div = y (self a b :
ifLazy
(isZero? b)
(_ : 0)
(_ : ifLazy
(lt? a b)
(_ : 0)
(_ : succ (self (sub a b) b))))
mod = y (self a b :
ifLazy
(isZero? b)
(_ : 0)
(_ : ifLazy
(lt? a b)
(_ : a)
(_ : self (sub a b) b)))
-- ---------------------------------------------------------------------------
-- Result combinators
-- ---------------------------------------------------------------------------