Theorem: SimpleGraph.adjMatrix_pow_apply_eq_card_walk
File: Mathlib/Combinatorics/SimpleGraph/AdjMatrix.lean

tactic: rw [card_set_walk_length_eq]
state_before: V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
n : ℕ
u v : V
⊢ (adjMatrix α G ^ n) u v = ↑(Fintype.card ↑{p | Walk.length p = n})

tactic: induction' n with n ih generalizing u v
state_before: V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
n : ℕ
u v : V
⊢ (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))

tactic: obtain rfl | h := eq_or_ne u v <;> simp [finsetWalkLength, *]
state_before: case zero
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ u v : V
⊢ (adjMatrix α G ^ Nat.zero) u v = ↑(card (finsetWalkLength G Nat.zero u v))

tactic: nth_rw 1 [Nat.succ_eq_one_add]
state_before: case succ
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ : V
n : ℕ
ih : ∀ (u v : V), (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))
u v : V
⊢ (adjMatrix α G ^ Nat.succ n) u v = ↑(card (finsetWalkLength G (Nat.succ n) u v))

tactic: simp only [pow_add, pow_one, finsetWalkLength, ih, mul_eq_mul, adjMatrix_mul_apply]
state_before: case succ
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ : V
n : ℕ
ih : ∀ (u v : V), (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))
u v : V
⊢ (adjMatrix α G ^ (1 + n)) u v = ↑(card (finsetWalkLength G (Nat.succ n) u v))

tactic: rw [Finset.card_biUnion]
state_before: case succ
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ : V
n : ℕ
ih : ∀ (u v : V), (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))
u v : V
⊢ ∑ x in neighborFinset G u, ↑(card (finsetWalkLength G n x v)) =
    ↑(card
        (Finset.biUnion univ fun w =>
          Finset.map
            { toFun := fun p => Walk.cons (_ : ↑w ∈ neighborSet G u) p,
              inj' :=
                (_ :
                  ∀ (x x_1 : Walk G (↑w) v),
                    Walk.cons (_ : ↑w ∈ neighborSet G u) x = Walk.cons (_ : ↑w ∈ neighborSet G u) x_1 → x = x_1) }
            (finsetWalkLength G n (↑w) v)))

tactic: norm_cast
state_before: case succ
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ : V
n : ℕ
ih : ∀ (u v : V), (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))
u v : V
⊢ ∑ x in neighborFinset G u, ↑(card (finsetWalkLength G n x v)) =
    ↑(∑ u_1 : ↑(neighborSet G u),
        card
          (Finset.map
            { toFun := fun p => Walk.cons (_ : ↑u_1 ∈ neighborSet G u) p,
              inj' :=
                (_ :
                  ∀ (x x_1 : Walk G (↑u_1) v),
                    Walk.cons (_ : ↑u_1 ∈ neighborSet G u) x = Walk.cons (_ : ↑u_1 ∈ neighborSet G u) x_1 → x = x_1) }
            (finsetWalkLength G n (↑u_1) v)))

tactic: simp only [Nat.cast_sum, card_map, neighborFinset_def]
state_before: case succ
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ : V
n : ℕ
ih : ∀ (u v : V), (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))
u v : V
⊢ ↑(∑ x in neighborFinset G u, card (finsetWalkLength G n x v)) =
    ↑(∑ u_1 : ↑(neighborSet G u),
        card
          (Finset.map
            { toFun := fun p => Walk.cons (_ : ↑u_1 ∈ neighborSet G u) p,
              inj' :=
                (_ :
                  ∀ (x x_1 : Walk G (↑u_1) v),
                    Walk.cons (_ : ↑u_1 ∈ neighborSet G u) x = Walk.cons (_ : ↑u_1 ∈ neighborSet G u) x_1 → x = x_1) }
            (finsetWalkLength G n (↑u_1) v)))

tactic: apply Finset.sum_toFinset_eq_subtype
state_before: case succ
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ : V
n : ℕ
ih : ∀ (u v : V), (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))
u v : V
⊢ ∑ x in Set.toFinset (neighborSet G u), ↑(card (finsetWalkLength G n x v)) =
    ∑ x : ↑(neighborSet G u), ↑(card (finsetWalkLength G n (↑x) v))

tactic: rintro ⟨x, hx⟩ - ⟨y, hy⟩ - hxy
state_before: case succ
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ : V
n : ℕ
ih : ∀ (u v : V), (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))
u v : V
⊢ ∀ (x : ↑(neighborSet G u)),
    x ∈ univ →
      ∀ (y : ↑(neighborSet G u)),
        y ∈ univ →
          x ≠ y →
            Disjoint
              (Finset.map
                { toFun := fun p => Walk.cons (_ : ↑x ∈ neighborSet G u) p,
                  inj' :=
                    (_ :
                      ∀ (x_1 x_2 : Walk G (↑x) v),
                        Walk.cons (_ : ↑x ∈ neighborSet G u) x_1 = Walk.cons (_ : ↑x ∈ neighborSet G u) x_2 →
                          x_1 = x_2) }
                (finsetWalkLength G n (↑x) v))
              (Finset.map
                { toFun := fun p => Walk.cons (_ : ↑y ∈ neighborSet G u) p,
                  inj' :=
                    (_ :
                      ∀ (x x_1 : Walk G (↑y) v),
                        Walk.cons (_ : ↑y ∈ neighborSet G u) x = Walk.cons (_ : ↑y ∈ neighborSet G u) x_1 → x = x_1) }
                (finsetWalkLength G n (↑y) v))

tactic: rw [disjoint_iff_inf_le]
state_before: case succ.mk.mk
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ : V
n : ℕ
ih : ∀ (u v : V), (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))
u v x : V
hx : x ∈ neighborSet G u
y : V
hy : y ∈ neighborSet G u
hxy : { val := x, property := hx } ≠ { val := y, property := hy }
⊢ Disjoint
    (Finset.map
      { toFun := fun p => Walk.cons (_ : ↑{ val := x, property := hx } ∈ neighborSet G u) p,
        inj' :=
          (_ :
            ∀ (x_1 x_2 : Walk G (↑{ val := x, property := hx }) v),
              Walk.cons (_ : ↑{ val := x, property := hx } ∈ neighborSet G u) x_1 =
                  Walk.cons (_ : ↑{ val := x, property := hx } ∈ neighborSet G u) x_2 →
                x_1 = x_2) }
      (finsetWalkLength G n (↑{ val := x, property := hx }) v))
    (Finset.map
      { toFun := fun p => Walk.cons (_ : ↑{ val := y, property := hy } ∈ neighborSet G u) p,
        inj' :=
          (_ :
            ∀ (x x_1 : Walk G (↑{ val := y, property := hy }) v),
              Walk.cons (_ : ↑{ val := y, property := hy } ∈ neighborSet G u) x =
                  Walk.cons (_ : ↑{ val := y, property := hy } ∈ neighborSet G u) x_1 →
                x = x_1) }
      (finsetWalkLength G n (↑{ val := y, property := hy }) v))

tactic: intro p hp
state_before: case succ.mk.mk
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ : V
n : ℕ
ih : ∀ (u v : V), (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))
u v x : V
hx : x ∈ neighborSet G u
y : V
hy : y ∈ neighborSet G u
hxy : { val := x, property := hx } ≠ { val := y, property := hy }
⊢ Finset.map
        { toFun := fun p => Walk.cons (_ : ↑{ val := x, property := hx } ∈ neighborSet G u) p,
          inj' :=
            (_ :
              ∀ (x_1 x_2 : Walk G (↑{ val := x, property := hx }) v),
                Walk.cons (_ : ↑{ val := x, property := hx } ∈ neighborSet G u) x_1 =
                    Walk.cons (_ : ↑{ val := x, property := hx } ∈ neighborSet G u) x_2 →
                  x_1 = x_2) }
        (finsetWalkLength G n (↑{ val := x, property := hx }) v) ⊓
      Finset.map
        { toFun := fun p => Walk.cons (_ : ↑{ val := y, property := hy } ∈ neighborSet G u) p,
          inj' :=
            (_ :
              ∀ (x x_1 : Walk G (↑{ val := y, property := hy }) v),
                Walk.cons (_ : ↑{ val := y, property := hy } ∈ neighborSet G u) x =
                    Walk.cons (_ : ↑{ val := y, property := hy } ∈ neighborSet G u) x_1 →
                  x = x_1) }
        (finsetWalkLength G n (↑{ val := y, property := hy }) v) ≤
    ⊥

tactic: simp only [inf_eq_inter, mem_inter, mem_map, Function.Embedding.coeFn_mk, exists_prop] at hp
state_before: case succ.mk.mk
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ : V
n : ℕ
ih : ∀ (u v : V), (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))
u v x : V
hx : x ∈ neighborSet G u
y : V
hy : y ∈ neighborSet G u
hxy : { val := x, property := hx } ≠ { val := y, property := hy }
p : Walk G u v
hp :
  p ∈
    Finset.map
        { toFun := fun p => Walk.cons (_ : ↑{ val := x, property := hx } ∈ neighborSet G u) p,
          inj' :=
            (_ :
              ∀ (x_1 x_2 : Walk G (↑{ val := x, property := hx }) v),
                Walk.cons (_ : ↑{ val := x, property := hx } ∈ neighborSet G u) x_1 =
                    Walk.cons (_ : ↑{ val := x, property := hx } ∈ neighborSet G u) x_2 →
                  x_1 = x_2) }
        (finsetWalkLength G n (↑{ val := x, property := hx }) v) ⊓
      Finset.map
        { toFun := fun p => Walk.cons (_ : ↑{ val := y, property := hy } ∈ neighborSet G u) p,
          inj' :=
            (_ :
              ∀ (x x_1 : Walk G (↑{ val := y, property := hy }) v),
                Walk.cons (_ : ↑{ val := y, property := hy } ∈ neighborSet G u) x =
                    Walk.cons (_ : ↑{ val := y, property := hy } ∈ neighborSet G u) x_1 →
                  x = x_1) }
        (finsetWalkLength G n (↑{ val := y, property := hy }) v)
⊢ p ∈ ⊥

tactic: obtain ⟨⟨px, _, rfl⟩, ⟨py, hpy, hp⟩⟩ := hp
state_before: case succ.mk.mk
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ : V
n : ℕ
ih : ∀ (u v : V), (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))
u v x : V
hx : x ∈ neighborSet G u
y : V
hy : y ∈ neighborSet G u
hxy : { val := x, property := hx } ≠ { val := y, property := hy }
p : Walk G u v
hp :
  (∃ a, a ∈ finsetWalkLength G n x v ∧ Walk.cons (_ : ↑{ val := x, property := hx } ∈ neighborSet G u) a = p) ∧
    ∃ a, a ∈ finsetWalkLength G n y v ∧ Walk.cons (_ : ↑{ val := y, property := hy } ∈ neighborSet G u) a = p
⊢ p ∈ ⊥

tactic: cases hp
state_before: case succ.mk.mk.intro.intro.intro.intro.intro
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ : V
n : ℕ
ih : ∀ (u v : V), (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))
u v x : V
hx : x ∈ neighborSet G u
y : V
hy : y ∈ neighborSet G u
hxy : { val := x, property := hx } ≠ { val := y, property := hy }
px : Walk G x v
left✝ : px ∈ finsetWalkLength G n x v
py : Walk G y v
hpy : py ∈ finsetWalkLength G n y v
hp :
  Walk.cons (_ : ↑{ val := y, property := hy } ∈ neighborSet G u) py =
    Walk.cons (_ : ↑{ val := x, property := hx } ∈ neighborSet G u) px
⊢ Walk.cons (_ : ↑{ val := x, property := hx } ∈ neighborSet G u) px ∈ ⊥

tactic: simp at hxy
state_before: case succ.mk.mk.intro.intro.intro.intro.intro.refl
V : Type u_1
α : Type u_2
β : Type ?u.68771
G : SimpleGraph V
inst✝³ : DecidableRel G.Adj
inst✝² : Fintype V
inst✝¹ : DecidableEq V
inst✝ : Semiring α
u✝ v✝ : V
n : ℕ
ih : ∀ (u v : V), (adjMatrix α G ^ n) u v = ↑(card (finsetWalkLength G n u v))
u v x : V
hx : x ∈ neighborSet G u
px : Walk G x v
left✝ : px ∈ finsetWalkLength G n x v
hy : x ∈ neighborSet G u
hxy : { val := x, property := hx } ≠ { val := x, property := hy }
hpy : px ∈ finsetWalkLength G n x v
⊢ Walk.cons (_ : ↑{ val := x, property := hx } ∈ neighborSet G u) px ∈ ⊥