Documentation

CslibFrontier.Tactic.ENNRealToReal

Reading a finite ℝ≥0∞ statement in ℝ #

Probabilities take values in ℝ≥0∞, while error bounds are stated and combined in ℝ, where linarith, nlinarith, field_simp and norm_num work. Crossing over by hand takes three steps: choose the bridge lemma (ENNReal.toReal_mono, ENNReal.toReal_le_toReal, ENNReal.toReal_eq_toReal_iff', ENNReal.ofReal_le_iff_le_toReal), prove each side finite with a term that mirrors its shape, and push ENNReal.toReal through the arithmetic with ENNReal.toReal_add, ENNReal.toReal_ofReal and their relatives, which ask for the same finiteness facts again.

ennreal_to_real does the three steps. For a goal or hypothesis a R b in ℝ≥0∞, with R one of ≤, <, =, ≠, it proves the needed sides finite with finiteness, replaces the statement by a.toReal R b.toReal (ENNReal.ofReal r ≤ b drops ofReal directly without requiring 0 ≤ r), and pushes toReal to the leaves with the simp set ennreal_toReal. On a statement that is already real it only pushes toReal.

Main definitions #

Implementation notes #

A side condition that is not found leaves its toReal in place and the rest is still rewritten, so a missing fact shows in the resulting goal. Side conditions are dispatched on their shape: x ≠ ∞ goes to finiteness and an inequality to local hypotheses (including quantified ones via bounded solve_by_elim), positivity and norm_cast. A failing finiteness call is the expensive case (most of a second on a term with three unknown atoms), which the dispatch keeps off the inequalities.

Push ENNReal.toReal inside if … then … else ….

Discharges a side condition of the simp set ennreal_toReal, for ennreal_to_real: x ≠ ∞, also under binders as in ∀ i ∈ s, f i ≠ ∞, by finiteness; 0 ≤ r and b ≤ a from a hypothesis, also up to casts as in (c : ℝ≥0∞) ≤ 1 from c ≤ 1, and 0 ≤ r also by positivity. It fails with an ordinary error when the condition is not found.

ennreal_to_real reads a statement about finite elements of ℝ≥0∞ in ℝ.

For a goal a R b with a b : ℝ≥0∞ and R one of ≤, <, =, ≠, it proves the sides finite with finiteness, replaces the goal by a.toReal R b.toReal (ENNReal.ofReal r ≤ b drops ofReal without requiring 0 ≤ r), and pushes toReal to the leaves with the simp set ennreal_toReal: through +, *, ∑, ∏, ∑', natural and real ^, ⁻¹, /, if … then … else …, numerals, casts and ENNReal.ofReal. A goal that is already real only has its toReals pushed.

  • ennreal_to_real at h₁ h₂ ⊢ does the same at hypotheses. A hypothesis a ≤ b or a < b needs only b finite, a = b needs nothing, and a ≠ b needs both a and b finite.
  • ennreal_to_real using e transfers the goal and the fact e, then closes the goal with e. The term e is elaborated on its own, without the goal as expected type.
example (p q : PMF α) (s : Set α) {ε : ℝ} (hε : 0 ≤ ε)
    (h : p.toOuterMeasure s ≤ q.toOuterMeasure s + ENNReal.ofReal ε) :
    (p.toOuterMeasure s).toReal ≤ (q.toOuterMeasure s).toReal + ε := by
  ennreal_to_real using h

The tactic fails, naming the term, when finiteness cannot show a side finite; give the missing fact as a hypothesis or register it as a finiteness rule. A subterm whose side condition is not found is left under toReal: (a - b).toReal needs b ≤ a as a hypothesis, and (ENNReal.ofReal r).toReal needs 0 ≤ r from a hypothesis or positivity. Under ∑' each term must be finite by its shape, so push toReal through an outer ∑' before unfolding a probability inside it into another ∑'. The rewriting is a fixed simp only, so the tactic may be used in the middle of a proof.

ennreal_to_real reads a statement about finite elements of ℝ≥0∞ in ℝ.

For a goal a R b with a b : ℝ≥0∞ and R one of ≤, <, =, ≠, it proves the sides finite with finiteness, replaces the goal by a.toReal R b.toReal (ENNReal.ofReal r ≤ b drops ofReal without requiring 0 ≤ r), and pushes toReal to the leaves with the simp set ennreal_toReal: through +, *, ∑, ∏, ∑', natural and real ^, ⁻¹, /, if … then … else …, numerals, casts and ENNReal.ofReal. A goal that is already real only has its toReals pushed.

  • ennreal_to_real at h₁ h₂ ⊢ does the same at hypotheses. A hypothesis a ≤ b or a < b needs only b finite, a = b needs nothing, and a ≠ b needs both a and b finite.
  • ennreal_to_real using e transfers the goal and the fact e, then closes the goal with e. The term e is elaborated on its own, without the goal as expected type.
example (p q : PMF α) (s : Set α) {ε : ℝ} (hε : 0 ≤ ε)
    (h : p.toOuterMeasure s ≤ q.toOuterMeasure s + ENNReal.ofReal ε) :
    (p.toOuterMeasure s).toReal ≤ (q.toOuterMeasure s).toReal + ε := by
  ennreal_to_real using h

The tactic fails, naming the term, when finiteness cannot show a side finite; give the missing fact as a hypothesis or register it as a finiteness rule. A subterm whose side condition is not found is left under toReal: (a - b).toReal needs b ≤ a as a hypothesis, and (ENNReal.ofReal r).toReal needs 0 ≤ r from a hypothesis or positivity. Under ∑' each term must be finite by its shape, so push toReal through an outer ∑' before unfolding a probability inside it into another ∑'. The rewriting is a fixed simp only, so the tactic may be used in the middle of a proof.