-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add faster rat semantics for testing, and show equivalence against slow semantics #35
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
base: main
Are you sure you want to change the base?
Conversation
| /-- The upper approximant of 'v'. | ||
| Returns the smallest 'x : X' such that 'r ≤ v x'. -/ | ||
| def upper (e s : Nat) (r : ExtRat) : PackedFloat e s := | ||
| (lower e s r.neg).neg | ||
|
|
||
| /-- Lower half, return 'true' iff we are strictly in the lower half. -/ | ||
| def lh (e s : Nat) (r : ExtRat) : Bool := | ||
| (r - (lower e s r).toExtRat) < (upper e s r).toExtRat - r | ||
|
|
||
| /-- Tiebreak, return 'true' iff we are exactly in the middle of the lower and upper approximants. -/ | ||
| def tb (e s : Nat) (r : ExtRat) : Bool := | ||
| r - (lower e s r).toExtRat = (upper e s r).toExtRat - r | ||
| /-- Upper half, return 'true' iff we are strictly in the upper half. -/ | ||
| def uh (e s : Nat) (r : ExtRat) : Bool := | ||
| (r - (lower e s r).toExtRat) > (upper e s r).toExtRat - r | ||
|
|
||
| /-- Check if 'X' is even. -/ | ||
| def ev (e s : Nat) (x : PackedFloat e s) : Bool := | ||
| match x.toExtRat with | ||
| | .Number n => | ||
| let den := n.den | ||
| let num := n.num | ||
| num = 0 ∨ (den = 1 ∧ num.natAbs % 2 = 0) | ||
| | _ => false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These differ from the definition in the paper...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what you mean --- the paper just says "let there exist an integer such that 2 * integer equals the rat", and this should be the computational version of this?
|
While the slow / reference implementation works, the fast one doesn't seem to. Debugging what's going on... |
| if _hz : r = .Number 0 then rsz e s sign | ||
| else | ||
| if _hlh : lh e s r | ||
| then lower e s | ||
| else | ||
| if _htb : tb e s r | ||
| then | ||
| if _heven : ev e s (lower e s r) | ||
| then lower e s | ||
| else upper e s | ||
| else | ||
| -- not tie break, not lower, so we are in upper half. | ||
| -- have : uh r v := by | ||
| -- have := trichotomy_lh_tb_uh r v | ||
| -- grind | ||
| upper e s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you flatten the ites to mirror the paper? Don't worry about introducing redundancies in the conditions.
The fast semantics should be closer to the 'round' implementation, which will help. inspired by @abdoo8080 , who suggested that we have this for fast execution.