File: Mathlib/Tactic/Linarith/Parsing.lean

full_name: List.findDefeq
code: /--
`findDefeq red m e` looks for a key in `m` that is defeq to `e` (up to transparency `red`),
and returns the value associated with this key if it exists.
Otherwise, it fails.
-/
def List.findDefeq {v : Type} (red : TransparencyMode) (m : List (Expr × v)) (e : Expr) :
    MetaM v 
goal: Lean.MetaM v

full_name: instAddRBMapOfZeroOfDecidableEq
code: /--
We introduce a local instance allowing addition of `RBMap`s,
removing any keys with value zero.
We don't need to prove anything about this addition, as it is only used in meta code.
-/
local instance {α β : Type*} {c : α → α → Ordering} [Add β] [Zero β] [DecidableEq β] :
    Add (RBMap α β c) 
goal: Add (Batteries.RBMap α β c)

full_name: Linarith.Map
code: /-- A local abbreviation for `RBMap` so we don't need to write `Ord.compare` each time. -/
abbrev Map (α β) [Ord α] 
goal: Type (max u_1 u_2)

full_name: Linarith.Monom
code: /-- Variables (represented by natural numbers) map to their power. -/
abbrev Monom : Type 
goal: Type

full_name: Linarith.Monom.one
code: /-- `1` is represented by the empty monomial, the product of no variables. -/
def Monom.one : Monom 
goal: Linarith.Monom

full_name: Linarith.Monom.lt
code: /-- Compare monomials by first comparing their keys and then their powers. -/
def Monom.lt : Monom → Monom → Bool 
goal: Linarith.Monom → Linarith.Monom → Bool

full_name: Linarith.instOrdMonom
code: instance : Ord Monom 
goal: Ord Linarith.Monom

full_name: Linarith.Sum
code: /-- Linear combinations of monomials are represented by mapping monomials to coefficients. -/
abbrev Sum : Type 
goal: Type

full_name: Linarith.Sum.one
code: /-- `1` is represented as the singleton sum of the monomial `Monom.one` with coefficient 1. -/
def Sum.one : Sum 
goal: Linarith.Sum

full_name: Linarith.Sum.scaleByMonom
code: /-- `Sum.scaleByMonom s m` multiplies every monomial in `s` by `m`. -/
def Sum.scaleByMonom (s : Sum) (m : Monom) : Sum 
goal: Linarith.Sum

full_name: Linarith.Sum.mul
code: /-- `sum.mul s1 s2` distributes the multiplication of two sums. -/
def Sum.mul (s1 s2 : Sum) : Sum 
goal: Linarith.Sum

full_name: Linarith.Sum.pow
code: /-- The `n`th power of `s : Sum` is the `n`-fold product of `s`, with `s.pow 0 = Sum.one`. -/
partial def Sum.pow (s : Sum) : ℕ → Sum
  
goal: ℕ → Linarith.Sum

full_name: Linarith.SumOfMonom
code: /-- `SumOfMonom m` lifts `m` to a sum with coefficient `1`. -/
def SumOfMonom (m : Monom) : Sum 
goal: Linarith.Sum

full_name: Linarith.one
code: /-- The unit monomial `one` is represented by the empty RBMap. -/
def one : Monom 
goal: Linarith.Monom

full_name: Linarith.scalar
code: /-- A scalar `z` is represented by a `Sum` with coefficient `z` and monomial `one` -/
def scalar (z : ℤ) : Sum 
goal: Linarith.Sum

full_name: Linarith.var
code: /-- A single variable `n` is represented by a sum with coefficient `1` and monomial `n`. -/
def var (n : ℕ) : Sum 
goal: Linarith.Sum

full_name: Linarith.ExprMap
code: /--
`ExprMap` is used to record atomic expressions which have been seen while processing inequality
expressions.
-/
-- The natural number is just the index in the list,
-- and we could reimplement to just use `List Expr` if desired.
abbrev ExprMap 
goal: Type

full_name: Linarith.linearFormOfAtom
code: /--
`linearFormOfAtom red map e` is the atomic case for `linear_form_of_expr`.
If `e` appears with index `k` in `map`, it returns the singleton sum `var k`.
Otherwise it updates `map`, adding `e` with index `n`, and returns the singleton sum `var n`.
-/
def linearFormOfAtom (red : TransparencyMode) (m : ExprMap) (e : Expr) : MetaM (ExprMap × Sum) 
goal: Lean.MetaM (Linarith.ExprMap × Linarith.Sum)

full_name: Linarith.linearFormOfExpr
code: /--
`linearFormOfExpr red map e` computes the linear form of `e`.

`map` is a lookup map from atomic expressions to variable numbers.
If a new atomic expression is encountered, it is added to the map with a new number.
It matches atomic expressions up to reducibility given by `red`.

Because it matches up to definitional equality, this function must be in the `MetaM` monad,
and forces some functions that call it into `MetaM` as well.
-/

partial def linearFormOfExpr (red : TransparencyMode) (m : ExprMap) (e : Expr) :
    MetaM (ExprMap × Sum) 
goal: Lean.MetaM (Linarith.ExprMap × Linarith.Sum)

full_name: Linarith.elimMonom
code: /--
`elimMonom s map` eliminates the monomial level of the `Sum` `s`.

`map` is a lookup map from monomials to variable numbers.
The output `RBMap ℕ ℤ` has the same structure as `s : Sum`,
but each monomial key is replaced with its index according to `map`.
If any new monomials are encountered, they are assigned variable numbers and `map` is updated.
 -/
def elimMonom (s : Sum) (m : Map Monom ℕ) : Map Monom ℕ × Map ℕ ℤ 
goal: Linarith.Map Linarith.Monom ℕ × Linarith.Map ℕ ℤ

full_name: Linarith.toComp
code: /--
`toComp red e e_map monom_map` converts an expression of the form `t < 0`, `t ≤ 0`, or `t = 0`
into a `comp` object.

`e_map` maps atomic expressions to indices; `monom_map` maps monomials to indices.
Both of these are updated during processing and returned.
-/
def toComp (red : TransparencyMode) (e : Expr) (e_map : ExprMap) (monom_map : Map Monom ℕ) :
    MetaM (Comp × ExprMap × Map Monom ℕ) 
goal: Lean.MetaM (Linarith.Comp × Linarith.ExprMap × Linarith.Map Linarith.Monom ℕ)

full_name: Linarith.toCompFold
code: /--
`toCompFold red e_map exprs monom_map` folds `toComp` over `exprs`,
updating `e_map` and `monom_map` as it goes.
 -/
def toCompFold (red : TransparencyMode) : ExprMap → List Expr → Map Monom ℕ →
    MetaM (List Comp × ExprMap × Map Monom ℕ)

goal: Linarith.ExprMap →
  List Lean.Expr →
    Linarith.Map Linarith.Monom ℕ → Lean.MetaM (List Linarith.Comp × Linarith.ExprMap × Linarith.Map Linarith.Monom ℕ)

full_name: Linarith.linearFormsAndMaxVar
code: /--
`linearFormsAndMaxVar red pfs` is the main interface for computing the linear forms of a list
of expressions. Given a list `pfs` of proofs of comparisons, it produces a list `c` of `Comp`s of
the same length, such that `c[i]` represents the linear form of the type of `pfs[i]`.

It also returns the largest variable index that appears in comparisons in `c`.
-/
def linearFormsAndMaxVar (red : TransparencyMode) (pfs : List Expr) :
    MetaM (List Comp × ℕ) 
goal: Lean.MetaM (List Linarith.Comp × ℕ)