AFTD Auto-Formalizing Theoretical Domains

two_level_environment_trace

theoremverified

For d ≥ 2 and 0 ≤ p ≤ 1 and every real t, the trace of two_level_environment d p t is 1.

Statement

theorem two_level_environment_trace (d : ℕ) (hd : 2 ≤ d) (p t : ℝ) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) :
    (two_level_environment d p t).trace = 1
Source
Sanity lemma for two_level_environment, serving OP-2466: it has trace one.
Verified
27 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 1
  • two_level_environmentWith d : ℕ and real numbers p, t, returns the complex d×d matrix (1 − t)·I/d + t·|ψ⟩⟨ψ|, where ψ : Fin d → ℝ has ψ j = √p when the…

The proof, explained

The trace of the d × d matrix two_level_environment d p t is computed as the sum of its diagonal entries. Because d ≥ 2, we write d = n + 2 and peel off the first two diagonal entries from the remaining n entries. For the first two entries, the rank-one perturbation contributes t * (√p)^2 = t * p and t * (√(1 - p))^2 = t * (1 - p), while on all other entries it vanishes, leaving only the constant term (1 - t)/(n + 2). Summing all components gives (n + 2) * (1 - t)/(n + 2) + t * (p + 1 - p) = (1 - t) + t = 1.

  1. The dimension d can be written as n + 2 for some natural number n.

    Since d ≥ 2, Nat.exists_eq_add_of_le yields some n with d = 2 + n, which by basic linear arithmetic (omega) is n + 2. We substitute this form for d.

    lines 3–5

    uses Nat.exists_eq_add_of_le

      obtain ⟨n, rfl⟩ : ∃ n, d = n + 2 := by
        obtain ⟨n, rfl⟩ := Nat.exists_eq_add_of_le hd
        exact ⟨n, by omega⟩
  2. The trace decomposes into the j = 0 and j = 1 diagonal terms plus the sum over the remaining n indices.

    By definition, the trace is the sum of the diagonal entries over Fin (n + 2). Applying Fin.sum_univ_succ twice splits off the j = 0 term and then the j = 1 term, leaving the sum over the remaining n indices.

    lines 6–9

    uses Fin.sum_univ_succ

      change ∑ j : Fin (n + 2), two_level_environment (n + 2) p t j j = 1
      rw [Fin.sum_univ_succ, Fin.sum_univ_succ]
      have h1 : (Fin.succ (0 : Fin (n + 1)) : Fin (n + 2)) = 1 := rfl
      rw [h1]
  3. Unfolding the definition, the trace expression evaluates to ((1 - t)/(n + 2) + t * (√p)^2) + ((1 - t)/(n + 2) + t * (√(1 - p))^2) + n * ((1 - t)/(n + 2)).

    Unfolding two_level_environment, the rank-one component has value √p at index 0, √(1 - p) at index 1, and 0 at all indices j ≥ 2. Simplifying the zero products with mul_zero and add_zero, the remaining sum is a constant (1 - t)/(n + 2) over an n-element set, which by Finset.sum_const, Finset.card_univ, Fintype.card_fin, and nsmul_eq_mul evaluates to n * ((1 - t)/(n + 2)).

    lines 10–12

    uses mul_zero, add_zero, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul

      dsimp [two_level_environment]
      simp only [mul_zero, add_zero]
      simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]
  4. In the complex numbers, (√p)^2 = p and (√(1 - p))^2 = 1 - p.

    Since p ≥ 0 and 1 - p ≥ 0 (the latter by linarith from p ≤ 1), Real.mul_self_sqrt gives √p * √p = p and √(1 - p) * √(1 - p) = 1 - p in the reals, which cast to the complex numbers via norm_cast.

    lines 13–18

    uses Real.mul_self_sqrt

      have hp : (√p : ℂ) * (√p : ℂ) = (p : ℂ) := by
        norm_cast
        exact Real.mul_self_sqrt hp0
      have hp' : (√(1 - p) : ℂ) * (√(1 - p) : ℂ) = (1 - p : ℂ) := by
        norm_cast
        exact Real.mul_self_sqrt (by linarith)
  5. The trace expression simplifies to (1 - t)/(n + 2) + t * p + (1 - t)/(n + 2) + t * (1 - p) + n * ((1 - t)/(n + 2)) = 1.

    Reassociating the products using mul_assoc, we substitute the squared square roots with p and 1 - p, and push the complex casts through the expression.

    lines 19–20

    uses mul_assoc

      rw [mul_assoc (t : ℂ), hp, mul_assoc (t : ℂ), hp']
      push_cast
  6. The trace is equal to 1.

    Since n + 2 ≠ 0 in ℂ, field_simp clears denominators, reducing the equation to a polynomial identity in n, t, and p, which holds by standard ring arithmetic (ring).

    lines 21–23

      have hn : ((n : ℂ) + 2) ≠ 0 := by norm_cast
      field_simp
      ring
Nat.exists_eq_add_of_le
If m ≤ n, then n = m + k for some natural number k.
Fin.sum_univ_succ
A sum over Fin (n + 1) splits into the term at 0 plus the sum of the remaining terms over Fin n.
mul_zero
Multiplying by zero on the right gives zero (a * 0 = 0).
add_zero
Adding zero on the right leaves an element unchanged (a + 0 = a).
Finset.sum_const
The sum of a constant b over a finite set s is equal to |s| • b.
Finset.card_univ
The cardinality of the universal finset univ of a finite type is the cardinality of that type.
Fintype.card_fin
The cardinality of Fin n is n.
nsmul_eq_mul
Natural-number scalar multiplication n • a equals the product n * a in a ring.
Real.mul_self_sqrt
For any non-negative real x ≥ 0, √x * √x = x.
mul_assoc
Multiplication is associative: (a * b) * c = a * (b * c).

Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.

Lean source view module on GitHub

theorem two_level_environment_trace (d : ℕ) (hd : 2 ≤ d) (p t : ℝ) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) :    (two_level_environment d p t).trace = 1 := by  obtain ⟨n, rfl⟩ : ∃ n, d = n + 2 := by    obtain ⟨n, rfl⟩ := Nat.exists_eq_add_of_le hd    exact ⟨n, by omega⟩  change ∑ j : Fin (n + 2), two_level_environment (n + 2) p t j j = 1  rw [Fin.sum_univ_succ, Fin.sum_univ_succ]  have h1 : (Fin.succ (0 : Fin (n + 1)) : Fin (n + 2)) = 1 := rfl  rw [h1]  dsimp [two_level_environment]  simp only [mul_zero, add_zero]  simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]  have hp : (√p : ℂ) * (√p : ℂ) = (p : ℂ) := by    norm_cast    exact Real.mul_self_sqrt hp0  have hp' : (√(1 - p) : ℂ) * (√(1 - p) : ℂ) = (1 - p : ℂ) := by    norm_cast    exact Real.mul_self_sqrt (by linarith)  rw [mul_assoc (t : ℂ), hp, mul_assoc (t : ℂ), hp']  push_cast  have hn : ((n : ℂ) + 2) ≠ 0 := by norm_cast  field_simp  ring
See it in the graphDiscuss this resultChallenge it