-
Notifications
You must be signed in to change notification settings - Fork 11
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
Predicate support #656
Merged
Merged
Predicate support #656
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0a7092b
chore: update to nightly-2024-09-25
tobiasgrosser e8354ea
chore: predicate support in FSM
tobiasgrosser 77d89e6
Add types
tobiasgrosser 7e2a2ab
Format
tobiasgrosser 1c11c84
Connect termEvalEq
tobiasgrosser d3b4310
Merge remote-tracking branch 'origin/main' into predicate_support
tobiasgrosser 16342fd
Update SSA/Experimental/Bits/Fast/FiniteStateMachine.lean
tobiasgrosser 74b9b9e
chore: progress
bollu 674e094
WIP: start repeatBit implementation
alexkeizer d4f6360
Merge branch 'predicate_support' of github.com:opencompl/lean-mlir in…
alexkeizer cd16f5c
repeatBit combinator
alexkeizer c3ecbf3
chore: define and, or.
bollu 74d8de7
remove sorry from corec
40d1330
simplify proof
a49220f
simpify proof
9d1d2b2
chore: fix sorry, now allow project to build. We fail on guard_msgs d…
bollu b5e09db
chore: allow project to compile by updating guard messages with sorry
bollu 92ff7c0
chore: cleanup
bollu 49405aa
chore: duplicate Defs, Lemmas into Fast
bollu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,45 @@ section Lemmas | |
theorem ext {x y : BitStream} (h : ∀ i, x i = y i) : x = y := by | ||
funext i; exact h i | ||
|
||
/-- | ||
The field projection `.1` distributes over function composition, so we can compute | ||
the first field of the result of the composition by repeatedly composing the first projection. | ||
-/ | ||
theorem compose_first {α: Type u₁} (i : Nat) (a : α) | ||
(f : α → α × Bool) : | ||
(f ((Prod.fst ∘ f)^[i] a)).1 = (Prod.fst ∘ f)^[i] (f a).1 := | ||
match i with | ||
| 0 => by simp | ||
| i + 1 => by simp [compose_first i ((f a).1) f] | ||
|
||
/-- | ||
Coinduction principle for `corec`. | ||
To show that `corec f a = corec g b`, | ||
we must show that: | ||
- The relation `R a b` is inhabited ["base case"] | ||
- Given that `R a b` holds, then `R (f a) (g b)` holds [coinductive case] | ||
-/ | ||
theorem corec_eq_corec {a : α} {b : β} {f g} | ||
(R : α → β → Prop) | ||
(thing : R a b) | ||
(h : ∀ a b, R a b → | ||
let x := f a | ||
let y := g b | ||
R x.fst y.fst ∧ x.snd = y.snd) : | ||
corec f a = corec g b := by | ||
ext i | ||
have lem : R ((Prod.fst ∘ f)^[i] (f a).1) ((Prod.fst ∘ g)^[i] (g b).1) ∧ corec f a i = corec g b i := by | ||
induction' i with i ih | ||
<;> simp only [Function.iterate_succ, Function.comp_apply, corec] | ||
· apply h | ||
exact thing | ||
· have m := h ((Prod.fst ∘ f)^[i] (f a).1) ((Prod.fst ∘ g)^[i] (g b).1) (ih.1) | ||
cases' m with l r | ||
rw [r, ← compose_first, ← @compose_first β] | ||
simp [l] | ||
cases lem | ||
assumption | ||
|
||
end Lemmas | ||
|
||
end Basic | ||
|
@@ -276,6 +315,16 @@ instance : Add BitStream := ⟨add⟩ | |
instance : Neg BitStream := ⟨neg⟩ | ||
instance : Sub BitStream := ⟨sub⟩ | ||
|
||
/-- `repeatBit xs` will repeat the first bit of `xs` which is `true`. | ||
That is, it will be all-zeros iff `xs` is all-zeroes, | ||
otherwise, there's some number `k` so that after dropping the `k` least | ||
significant bits, `repeatBit xs` is all-ones. -/ | ||
def repeatBit (xs : BitStream) : BitStream := | ||
corec (b := (false, xs)) fun (carry, xs) => | ||
Comment on lines
+318
to
+323
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we wanted to change this name? I like |
||
let carry := carry || xs 0 | ||
let xs := xs.tail | ||
((carry, xs), carry) | ||
|
||
/-! | ||
TODO: We should define addition and `carry` in terms of `mapAccum`. | ||
For example: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I would call this bisimulation, rather than coinduction