Map make filter Map flatten find?
Cedar.Thm.map_make_filterMap_flatten_find?
Plain-language statement
For simplifying Factory.app on a UDF with a table of the form make (m.toList.filterMap f).flatten.
Exact Lean statement
theorem map_make_filterMap_flatten_find?
[BEq α] [BEq β] [LawfulBEq α] [LawfulBEq β]
[DecidableEq γ] [LT γ] [DecidableLT γ] [StrictLT γ]
{m : Map α β}
{k : α} {v : β} {k' : γ} {v' : κ}
{f : α × β → Option (List (γ × κ))}
(hfind : m.find? k = .some v)
(hkv : ∃ l, f (k, v) = .some l ∧ l.find? (λ x => x.1 == k') = .some (k', v'))
(hf : ∀ kv, (∃ l, f kv = .some l ∧ (l.find? (λ x => x.1 == k')).isSome) → kv.1 = k) :
(Map.make (m.toList.filterMap f).flatten).find? k' = .some v'Formal artifact
Lean source
theorem map_make_filterMap_flatten_find? [BEq α] [BEq β] [LawfulBEq α] [LawfulBEq β] [DecidableEq γ] [LT γ] [DecidableLT γ] [StrictLT γ] {m : Map α β} {k : α} {v : β} {k' : γ} {v' : κ} {f : α × β → Option (List (γ × κ))} (hfind : m.find? k = .some v) (hkv : ∃ l, f (k, v) = .some l ∧ l.find? (λ x => x.1 == k') = .some (k', v')) (hf : ∀ kv, (∃ l, f kv = .some l ∧ (l.find? (λ x => x.1 == k')).isSome) → kv.1 = k) : (Map.make (m.toList.filterMap f).flatten).find? k' = .some v':= by rw [← Map.list_find?_iff_make_find?] simp only [List.find?_flatten] cases m with | mk l => simp only [List.find?_isSome, beq_iff_eq, Prod.exists, exists_and_right, exists_eq_right, forall_exists_index, and_imp, Prod.forall, Map.find?, Map.toList_mk_id] at * split at hfind rotate_left; contradiction rename_i heq simp only [Option.some.injEq] at hfind simp only [hfind] at heq have := List.find?_some heq simp only [beq_iff_eq] at this simp only [this] at heq induction l with | nil => contradiction | cons hd tl ih => simp only [List.find?] at heq split at heq · simp only [Option.some.injEq] at heq have ⟨fkv, hfkv, hfind_fkv⟩ := hkv simp only [List.filterMap, heq, hfkv] simp only [List.findSome?, hfind_fkv] · rename_i hne_hd_key simp only [List.filterMap] split · exact ih heq · rename_i l' hhd simp only [beq_eq_false_iff_ne, ne_eq] at hne_hd_key have := hf hd.fst hd.snd have : (∃ l, f hd = some l ∧ (List.find? (fun x => x.fst == k') l).isSome = true) → False := by intros h replace ⟨l, h, h'⟩ := h apply hne_hd_key apply this l h simp_all only [forall_const, Option.some.injEq, imp_false, forall_eq', List.find?_isSome, beq_iff_eq, Prod.exists, exists_and_right, exists_eq_right, exists_false] rw [List.find?_isSome] at h' simp_all simp only [ imp_false, not_exists, not_and, ] at this have hfind_l' := this l' hhd simp only [List.findSome?] split · rename_i heq simp only [heq] at hfind_l' simp at hfind_l' · exact ih heq- Project
- Cedar Specification
- License
- Apache-2.0
- Commit
- 3f093947b8ae
- Source
- cedar-lean/Cedar/Thm/SymCC/Term/UDF.lean:124-184
Reuse this declaration
Bring the exact result into your workflow
The import identifies the source module. Your project still needs the pinned package dependency shown on this page.
What this badge means
This completion status comes from the project or community source. It has not yet been represented here as an independent rebuild and axiom audit.
Continue in this project
Related declarations
Find? ext
Cedar.Data.Map.find?_ext
Plain-language statement
Two well-formed maps are equal if they have the same find? for every key.
Source project: Cedar Specification
Person-level attribution pending.
Find? notmem keys
Cedar.Data.Map.find?_notmem_keys
Plain-language statement
Inverse of find?_mem_toList, except that this requires wf
Source project: Cedar Specification
Person-level attribution pending.
Find? some iff in values
Cedar.Data.Map.find?_some_iff_in_values
Plain-language statement
The mp direction of this does not need the wf precondition and, in fact, is available separately as find?_some_implies_in_values above
Source project: Cedar Specification
Person-level attribution pending.