-
Notifications
You must be signed in to change notification settings - Fork 156
Add boolean builtins in Nat
#1262
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
Conversation
| infixl 0 _UsingEq | ||
| infixl 0 _i0:>_UsingEqP | ||
|
|
||
| _UsingEq : (a : A) → singl a |
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.
Add a comment showing how this can be used
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.
Is the comment I just added enough?
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.
It looke like this has exactly the same use case as inspect. Is this not redundant?
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.
Thank you, I completely missed it. Do you know exactly how should I use it?
Right now I'm trying to case-split on inspect (_≡ᵇ n) m in the proof of discreteness of ℕ, but this doesn't seem to work, since it only gives me the path, but not each boolean case.
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.
Nevermind, I got it.
Is this what you meant?
discreteℕ : Discrete ℕ
discreteℕ zero zero = yes refl
discreteℕ zero (suc n) = no znots
discreteℕ (suc m) zero = no snotz
discreteℕ (suc m) (suc n) with m ≡ᵇ n | inspect (m ≡ᵇ_) n
... | false | [ p ]ᵢ = no (subst Bool→Type p ∘ ≡→≡ᵇ)
... | true | [ p ]ᵢ = yes (≡ᵇ→≡ (subst Bool→Type (sym p) tt))
|
@LorenzoMolena since thowse will be heavily used and critical for performance of various definition, to be safe, I would double check performance benchmark for every variant when you are making changes. |
|
@felixwellen I just tried the approach suggested by @anshwad10, i.e. using However, I find whilst the corrent definition on the PR is a bit more concise. I’d prefer to keep |
|
You can keep |
This PR refactors the definitions of
min,max,discreteℕ,<-split, and_≟_to use boolean builtins, improving the performance of their computation.
For
minandmax, this improvement applies unconditionally, while for the otherfunctions it depends on whether proof terms are ignored
(e.g., when defining functions by cases via
_≟_).The main changes are:
Nat.Base: imports the previously missing boolean builtins.Nat.PropertiesandNat.Order: update the implementations of the functions listed above.Prelude: adds aliases forisContrSingl ... .fstandisContrSinglP ... .fstto support with-abstraction without losing information about the orginal terms
(a workaround for the "with-abstraction equality" available in standard Agda but missing in Cubical).
DirectSum.Equiv-DSHIT-DSFun,Instances.NatMax, andTruncation.Properties:adjusted for compatibility with the updated definitions.
Some notes:
_≟_remains in the file under the name_≟'_.Please let me know if this structure and approach are appropriate.