Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 2a32596

Browse files
vihdzpurkud
andcommitted
feat(data/finsupp/basic): graph of a finitely supported function (#15197)
We define the graph of a finitely supported function, i.e. the finset of input/output pairs, and prove basic results. Co-authored-by: Yury G. Kudryashov <urkud@urkud.name>
1 parent c6014bd commit 2a32596

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

src/data/finsupp/basic.lean

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ non-pointwise multiplication.
4545
* `finsupp.update`: Changes one value of a `finsupp`.
4646
* `finsupp.erase`: Replaces one value of a `finsupp` by `0`.
4747
* `finsupp.on_finset`: The restriction of a function to a `finset` as a `finsupp`.
48-
* `finsupp.map_range`: Composition of a `zero_hom` with a`finsupp`.
48+
* `finsupp.map_range`: Composition of a `zero_hom` with a `finsupp`.
4949
* `finsupp.emb_domain`: Maps the domain of a `finsupp` by an embedding.
5050
* `finsupp.map_domain`: Maps the domain of a `finsupp` by a function and by summing.
5151
* `finsupp.comap_domain`: Postcomposition of a `finsupp` with a function injective on the preimage
@@ -722,6 +722,60 @@ by rw [← support_eq_empty, support_erase, support_zero, erase_empty]
722722

723723
end erase
724724

725+
/-! ### Declarations about `graph` -/
726+
727+
section graph
728+
729+
variable [has_zero M]
730+
731+
/-- The graph of a finitely supported function over its support, i.e. the finset of input and output
732+
pairs with non-zero outputs. -/
733+
def graph (f : α →₀ M) : finset (α × M) :=
734+
f.support.map ⟨λ a, prod.mk a (f a), λ x y h, (prod.mk.inj h).1
735+
736+
lemma mk_mem_graph_iff {a : α} {m : M} {f : α →₀ M} : (a, m) ∈ f.graph ↔ f a = m ∧ m ≠ 0 :=
737+
begin
738+
simp_rw [graph, mem_map, mem_support_iff],
739+
split,
740+
{ rintro ⟨b, ha, rfl, -⟩,
741+
exact ⟨rfl, ha⟩ },
742+
{ rintro ⟨rfl, ha⟩,
743+
exact ⟨a, ha, rfl⟩ }
744+
end
745+
746+
@[simp] lemma mem_graph_iff {c : α × M} {f : α →₀ M} : c ∈ f.graph ↔ f c.1 = c.2 ∧ c.20 :=
747+
by { cases c, exact mk_mem_graph_iff }
748+
749+
lemma mk_mem_graph (f : α →₀ M) {a : α} (ha : a ∈ f.support) : (a, f a) ∈ f.graph :=
750+
mk_mem_graph_iff.2 ⟨rfl, mem_support_iff.1 ha⟩
751+
752+
lemma apply_eq_of_mem_graph {a : α} {m : M} {f : α →₀ M} (h : (a, m) ∈ f.graph) : f a = m :=
753+
(mem_graph_iff.1 h).1
754+
755+
@[simp] lemma not_mem_graph_snd_zero (a : α) (f : α →₀ M) : (a, (0 : M)) ∉ f.graph :=
756+
λ h, (mem_graph_iff.1 h).2.irrefl
757+
758+
@[simp] lemma image_fst_graph (f : α →₀ M) : f.graph.image prod.fst = f.support :=
759+
by simp only [graph, map_eq_image, image_image, embedding.coe_fn_mk, (∘), image_id']
760+
761+
lemma graph_injective (α M) [has_zero M] : injective (@graph α M _) :=
762+
begin
763+
intros f g h,
764+
have hsup : f.support = g.support, by rw [← image_fst_graph, h, image_fst_graph],
765+
refine ext_iff'.2 ⟨hsup, λ x hx, apply_eq_of_mem_graph $ h.symm ▸ _⟩,
766+
exact mk_mem_graph _ (hsup ▸ hx)
767+
end
768+
769+
@[simp] lemma graph_inj {f g : α →₀ M} : f.graph = g.graph ↔ f = g :=
770+
(graph_injective α M).eq_iff
771+
772+
@[simp] lemma graph_zero : graph (0 : α →₀ M) = ∅ := by simp [graph]
773+
774+
@[simp] lemma graph_eq_empty {f : α →₀ M} : f.graph = ∅ ↔ f = 0 :=
775+
(graph_injective α M).eq_iff' graph_zero
776+
777+
end graph
778+
725779
/-!
726780
### Declarations about `sum` and `prod`
727781

0 commit comments

Comments
 (0)