Skip to content
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

feat: fix BitVec.abs, prove toInt produces the expected value #26

Closed
wants to merge 14 commits into from

Conversation

bollu
Copy link

@bollu bollu commented Oct 15, 2024

Abs has the interesting wrinkle where if we feed it intMin, it stays intMin:

100 -- 4#3

If we compute -x, i.e. !x + 1, we get:

 011
+001
 ---
 100

In this PR, we show that abs of intMin produces intMin again, and abs of every other number gives .toInt.abs. We also define Int.abs to phrase lemmas naturally.

kmill and others added 6 commits October 20, 2024 18:40
…rover#5688)

This replaces `export Lean (Name NameMap)` and `export System
(SearchPath FilePath)` with the relevant `open` commands. This fixes
docgen output so that it can refer to, for example, `Lean.Name` instead
of `Lake.Name`.

The reason for these `export`s was convenience: by doing `open Lake` you
could get these aliases for free. However, aliases affect pretty
printing, and the Lake aliases took precedence. We don't want to disable
pretty printing re-exported names because this can be a valid pattern
(names could incrementally get re-exported from namespace to parent
namespace).

In the future we might implement a feature to be able to `scoped open`
some names.

Breaking change: Lakefiles that refer to `FilePath` may need to change
this to `System.FilePath` or otherwise add `open System (FilePath)`.

Closes leanprover#2524
This PR simplifies the signature of `Array.mapIdx`, to take a function
`f : Nat \to \a \to \b` rather than a function `f : Fin as.size \to \a
\to \b`.

Lean doesn't actually use the extra generality anywhere (so in fact this
change *simplifies* all the call sites of `Array.mapIdx`, since we no
longer need to throw away the proof).

This change would make the function signature equivalent to
`List.mapIdx`, hence making it easier to write verification lemmas.

We keep the original behaviour as `Array.mapFinIdx`.
More cleanup of Array API. More to come.
@bollu bollu force-pushed the lean4-toint-abs branch 2 times, most recently from 1405f9c to 6d9cce7 Compare October 21, 2024 07:10
@bollu bollu changed the title feat: fix BitVec.abs, prove toInt produces the expected value. feat: fix BitVec.abs, prove toInt produces the expected value Oct 21, 2024
@bollu bollu force-pushed the lean4-toint-abs branch 4 times, most recently from 843182c to eabe2c1 Compare October 21, 2024 07:34
@bollu bollu force-pushed the lean4-toint-abs branch 7 times, most recently from 7a37773 to 4a7b7ae Compare October 21, 2024 08:23
…eanprover#5679)

Previously `RecursorVal.getInduct` would return the prefix of the
recursor’s name, which is unlikely the right value for the “derived”
recursors in nested recursion. The code using `RecursorVal.getInduct`
seems to expect the name of the inductive type of major argument here.

If we return that name, this fixes leanprover#5661.

This bug becomes more visible now that we have structural mutual
recursion.

Also, to avoid confusion, renames the function to ``getMajorInduct`.
bollu added 2 commits October 22, 2024 17:52
We implement `toInt_abs`.
A subtle wrinkle is to note that `abs (intMin w) = intMin w`,
which complicates our proof.
@bollu
Copy link
Author

bollu commented Nov 21, 2024

Upstreamed, closing.

@bollu bollu closed this Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants