Documentation

Mathlib.Tactic.Rify

rify tactic #

The rify tactic is used to shift propositions from , , or ℝ≥0 to .

Although less useful than its cousins zify and qify, it can be useful when your goal or context already involves real numbers.

In the example below, assumption hn is about natural numbers, hk is about integers and involves casting a natural number to , and the conclusion is about real numbers. The proof uses rify to lift both assumptions to before calling linarith.

import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Rify

example {n : ℕ} {k : ℤ} (hn : 8 ≤ n) (hk : 2 * k ≤ n + 2) :
    (0 : ℝ) < n - k - 1 := by
  rify at hn hk
  linarith

TODO: Investigate whether we should generalize this to other fields.

rify rewrites the main goal by shifting propositions from , , or ℝ≥0 to . Although less useful than its cousins zify and qify, it can be useful when your goal or context already involves real numbers.

rify makes use of the @[zify_simps], @[qify_simps] and @[rify_simps] attributes to insert casts into propositions, and the push_cast tactic to simplify the -valued expressions.

rify is in some sense dual to the lift tactic. lift (r : ℝ) to ℚ will change the type of a real number r (in the supertype) to (the subtype), given a proof that r is rational; propositions concerning r will still be over . rify changes propositions about , , or ℝ≥0 (the subtype) to propositions about (the supertype), without changing the type of any variable.

  • rify at l1 l2 ... rewrites at the given locations.
  • rify [h₁, ..., hₙ] uses the expressions h₁, ..., hₙ as extra lemmas for simplification. This is especially useful in the presence of nat subtraction or of division: passing arguments of type · ≤ · or · ∣ · will allow push_cast to do more work.

Examples:

/--
import Mathlib

open Real
Here, the assumption `hn` is about natural numbers, `hk` is about integers
and involves casting a natural number to `ℤ`, and the conclusion is about real numbers.
-/
example {n : ℕ} {k : ℤ} (hn : 8 ≤ n) (hk : 2 * k ≤ n + 2) :
    (0 : ℝ) < n - k - 1 := by
  rify at hn hk /- Now have hn : 8 ≤ (n : ℝ)   hk : 2 * (k : ℝ) ≤ (n : ℝ) + 2 -/
  linarith

-- Extra hypotheses allow `push_cast` to do more work.
example (a b c : ℕ) (h : a - b < c) (hab : b ≤ a) : a < b + c := by
  rify [hab] at h ⊢ -- Here `zify` or `qify` would have also worked.
  linarith

example (a b : ℕ) (ha : π ≤ a) : 3 ≤ a + b := by
  rify
  linarith [pi_gt_three]
Equations
  • One or more equations did not get rendered due to their size.
Instances For

    The Simp.Context generated by rify (with no optional arguments or local context).

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      Translate a proof and the proposition into rified form.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Mathlib.Tactic.Rify.ratCast_eq (a b : ) :
        a = b a = b
        theorem Mathlib.Tactic.Rify.ratCast_le (a b : ) :
        a b a b
        theorem Mathlib.Tactic.Rify.ratCast_lt (a b : ) :
        a < b a < b
        theorem Mathlib.Tactic.Rify.ratCast_ne (a b : ) :
        a b a b