-
Notifications
You must be signed in to change notification settings - Fork 689
feat: add non-branching boolean operations #11035
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: master
Are you sure you want to change the base?
Conversation
|
Mathlib CI status (docs):
|
|
Reference manual CI status:
|
|
I thought about making decidable equality non-branching as well. But that had unexpected effect that |
|
Probably needs benching. |
| * `land true true = true` | ||
| -/ | ||
| @[expose, extern "lean_bool_land"] | ||
| def land (x y : Bool) : Bool := x && y |
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 there a name that makes it easier to understand the difference between this and Bool.and at a glance? Maybe something like strictAnd?
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.
strictAnd already exists. It ensures that both arguments get evaluated but still has a branching implementation.
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.
Maybe bitAnd? I can't think of anything other than land that is commonly used for this.
|
I'm not sure this is a good idea; doesn't this mostly make some boolean functions opaque to the compiler? Especially match !a with
| true => x
| false => ywon't be optimized to match a with
| false => x
| true => yby the Lean compiler itself. |
|
I agree about
No, this is not a valid optimization in C. It's only possible in Lean because |
This PR adds non-branching runtime implementations for operations for
Bool.Bool.landthe non-branching version of&&.Bool.lorthe non-branching version of||.Bool.lnotthe non-branching version of!.Bool.xoris now non-branching (the branching version is!=).Bool.toNatnow simply converts an untagged value to a tagged value.Closes RFC #10835