fact stringlengths 6 3.84k | type stringclasses 11
values | library stringclasses 32
values | imports listlengths 1 14 | filename stringlengths 20 95 | symbolic_name stringlengths 1 90 | docstring stringlengths 7 20k ⌀ |
|---|---|---|---|---|---|---|
MaybeFunctionData.get (fData : MaybeFunctionData) : MetaM Expr :=
match fData with
| .letE f | .lam f => pure f
| .data d => d.toExpr | def | Tactic | [
"Qq",
"Mathlib.Tactic.FunProp.Mor",
"Mathlib.Tactic.FunProp.ToBatteries"
] | Mathlib/Tactic/FunProp/FunctionData.lean | MaybeFunctionData.get | Turn `MaybeFunctionData` to the function. |
getFunctionData? (f : Expr)
(unfoldPred : Name → Bool := fun _ => false) :
MetaM MaybeFunctionData := do
withConfig (fun cfg => { cfg with zeta := false, zetaDelta := false }) do
let unfold := fun e : Expr => do
if let some n := e.getAppFn'.constName? then
pure ((unfoldPred n) || (← isReducible n)... | def | Tactic | [
"Qq",
"Mathlib.Tactic.FunProp.Mor",
"Mathlib.Tactic.FunProp.ToBatteries"
] | Mathlib/Tactic/FunProp/FunctionData.lean | getFunctionData | Get `FunctionData` for `f`. |
FunctionData.unfoldHeadFVar? (fData : FunctionData) : MetaM (Option Expr) := do
let .fvar id := fData.fn | return none
let some val ← id.getValue? | return none
let f ← withLCtx fData.lctx fData.insts do
mkLambdaFVars #[fData.mainVar] (headBetaThroughLet (Mor.mkAppN val fData.args))
return f | def | Tactic | [
"Qq",
"Mathlib.Tactic.FunProp.Mor",
"Mathlib.Tactic.FunProp.ToBatteries"
] | Mathlib/Tactic/FunProp/FunctionData.lean | FunctionData.unfoldHeadFVar | If head function is a let-fvar unfold it and return resulting function.
Return `none` otherwise. |
MorApplication where
/-- Of the form `⇑f` i.e. missing argument. -/
| underApplied
/-- Of the form `⇑f x` i.e. morphism and one argument is provided. -/
| exact
/-- Of the form `⇑f x y ...` i.e. additional applied arguments `y ...`. -/
| overApplied
/-- Not a morphism application. -/
| none
deriving I... | inductive | Tactic | [
"Qq",
"Mathlib.Tactic.FunProp.Mor",
"Mathlib.Tactic.FunProp.ToBatteries"
] | Mathlib/Tactic/FunProp/FunctionData.lean | MorApplication | Type of morphism application. |
FunctionData.isMorApplication (f : FunctionData) : MetaM MorApplication := do
if let some name := f.fn.constName? then
if ← Mor.isCoeFunName name then
let info ← getConstInfo name
let arity := info.type.getNumHeadForalls
match compare arity f.args.size with
| .eq => return .exact
| .... | def | Tactic | [
"Qq",
"Mathlib.Tactic.FunProp.Mor",
"Mathlib.Tactic.FunProp.ToBatteries"
] | Mathlib/Tactic/FunProp/FunctionData.lean | FunctionData.isMorApplication | Is function body of `f` a morphism application? What kind? |
FunctionData.peeloffArgDecomposition (fData : FunctionData) : MetaM (Option (Expr × Expr)) := do
unless fData.args.size > 0 do return none
withLCtx fData.lctx fData.insts do
let n := fData.args.size
let x := fData.mainVar
let yₙ := fData.args[n-1]!
if yₙ.expr.containsFVar x.fvarId! then
return... | def | Tactic | [
"Qq",
"Mathlib.Tactic.FunProp.Mor",
"Mathlib.Tactic.FunProp.ToBatteries"
] | Mathlib/Tactic/FunProp/FunctionData.lean | FunctionData.peeloffArgDecomposition | Decomposes `fun x => f y₁ ... yₙ` into `(fun g => g yₙ) ∘ (fun x y => f y₁ ... yₙ₋₁ y)`
Returns none if:
- `n=0`
- `yₙ` contains `x`
- `n=1` and `(fun x y => f y)` is identity function i.e. `x=f` |
FunctionData.nontrivialDecomposition (fData : FunctionData) : MetaM (Option (Expr × Expr)) := do
let mut lctx := fData.lctx
let insts := fData.insts
let x := fData.mainVar
let xId := x.fvarId!
let xName ← withLCtx lctx insts xId.getUserName
let fn := fData.fn
let mut args := fData.args
i... | def | Tactic | [
"Qq",
"Mathlib.Tactic.FunProp.Mor",
"Mathlib.Tactic.FunProp.ToBatteries"
] | Mathlib/Tactic/FunProp/FunctionData.lean | FunctionData.nontrivialDecomposition | Decompose function `f = (← fData.toExpr)` into composition of two functions.
Returns none if the decomposition would produce composition with identity function. |
FunctionData.decompositionOverArgs (fData : FunctionData) (args : Array Nat) :
MetaM (Option (Expr × Expr)) := do
unless isOrderedSubsetOf fData.mainArgs args do return none
unless ¬(fData.fn.containsFVar fData.mainVar.fvarId!) do return none
withLCtx fData.lctx fData.insts do
let gxs := args.map (fun i => ... | def | Tactic | [
"Qq",
"Mathlib.Tactic.FunProp.Mor",
"Mathlib.Tactic.FunProp.ToBatteries"
] | Mathlib/Tactic/FunProp/FunctionData.lean | FunctionData.decompositionOverArgs | Decompose function `fun x => f y₁ ... yₙ` over specified argument indices `#[i, j, ...]`.
The result is:
```
(fun (yᵢ',yⱼ',...) => f y₁ .. yᵢ' .. yⱼ' .. yₙ) ∘ (fun x => (yᵢ, yⱼ, ...))
```
This is not possible if `yₗ` for `l ∉ #[i,j,...]` still contains `x`.
In such case `none` is returned. |
isCoeFunName (name : Name) : CoreM Bool := do
let some info ← getCoeFnInfo? name | return false
return info.type == .coeFun | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/Mor.lean | isCoeFunName | Is `name` a coercion from some function space to functions? |
isCoeFun (e : Expr) : MetaM Bool := do
let some (name, _) := e.getAppFn.const? | return false
let some info ← getCoeFnInfo? name | return false
return e.getAppNumArgs' + 1 == info.numArgs | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/Mor.lean | isCoeFun | Is `e` a coercion from some function space to functions? |
App where
/-- morphism coercion -/
coe : Expr
/-- bundled morphism -/
fn : Expr
/-- morphism argument -/
arg : Expr | structure | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/Mor.lean | App | Morphism application |
isMorApp? (e : Expr) : MetaM (Option App) := do
let .app (.app coe f) x := e | return none
if ← isCoeFun coe then
return some { coe := coe, fn := f, arg := x }
else
return none | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/Mor.lean | isMorApp | Is `e` morphism application? |
partial whnfPred (e : Expr) (pred : Expr → MetaM Bool) :
MetaM Expr := do
whnfEasyCases e fun e => do
let e ← whnfCore e
if let some ⟨coe,f,x⟩ ← isMorApp? e then
let f ← whnfPred f pred
if (← getConfig).zeta then
return (coe.app f).app x
else
return ← mapLetTelescope f fu... | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/Mor.lean | whnfPred | Weak normal head form of an expression involving morphism applications. Additionally, `pred`
can specify which when to unfold definitions.
For example calling this on `coe (f a) b` will put `f` in weak normal head form instead of `coe`. |
whnf (e : Expr) : MetaM Expr :=
whnfPred e (fun _ => return false) | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/Mor.lean | whnf | Weak normal head form of an expression involving morphism applications.
For example calling this on `coe (f a) b` will put `f` in weak normal head form instead of `coe`. |
Arg where
/-- argument of type `α` -/
expr : Expr
/-- coercion `F → α → β` -/
coe : Option Expr := none
deriving Inhabited | structure | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/Mor.lean | Arg | Argument of morphism application that stores corresponding coercion if necessary |
app (f : Expr) (arg : Arg) : Expr :=
match arg.coe with
| none => f.app arg.expr
| some coe => (coe.app f).app arg.expr | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/Mor.lean | app | Morphism application |
partial withApp {α} (e : Expr) (k : Expr → Array Arg → MetaM α) : MetaM α :=
go e #[]
where
/-- -/
go : Expr → Array Arg → MetaM α
| .mdata _ b, as => go b as
| .app (.app c f) x, as => do
if ← isCoeFun c then
go f (as.push { coe := c, expr := x})
else
go (.app c f) (as.push {... | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/Mor.lean | withApp | Given `e = f a₁ a₂ ... aₙ`, returns `k f #[a₁, ..., aₙ]` where `f` can be bundled morphism. |
getAppFn (e : Expr) : MetaM Expr :=
match e with
| .mdata _ b => getAppFn b
| .app (.app c f) _ => do
if ← isCoeFun c then
getAppFn f
else
getAppFn (.app c f)
| .app f _ =>
getAppFn f
| e => return e | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/Mor.lean | getAppFn | If the given expression is a sequence of morphism applications `f a₁ .. aₙ`, return `f`.
Otherwise return the input expression. |
getAppArgs (e : Expr) : MetaM (Array Arg) := withApp e fun _ xs => return xs | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/Mor.lean | getAppArgs | Given `f a₁ a₂ ... aₙ`, returns `#[a₁, ..., aₙ]` where `f` can be bundled morphism. |
mkAppN (f : Expr) (xs : Array Arg) : Expr :=
xs.foldl (init := f) (fun f x =>
match x with
| ⟨x, .none⟩ => (f.app x)
| ⟨x, some coe⟩ => (coe.app f).app x) | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/Mor.lean | mkAppN | `mkAppN f #[a₀, ..., aₙ]` ==> `f a₀ a₁ .. aₙ` where `f` can be bundled morphism. |
LambdaTheoremArgs
/-- Identity theorem e.g. `Continuous fun x => x` -/
| id
/-- Constant theorem e.g. `Continuous fun x => y` -/
| const
/-- Apply theorem e.g. `Continuous fun (f : (x : X) → Y x => f x)` -/
| apply
/-- Composition theorem e.g. `Continuous f → Continuous g → Continuous fun x => f (g x)`
... | inductive | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | LambdaTheoremArgs | Tag for one of the 5 basic lambda theorems, that also hold extra data for composition theorem |
LambdaTheoremType
/-- Identity theorem e.g. `Continuous fun x => x` -/
| id
/-- Constant theorem e.g. `Continuous fun x => y` -/
| const
/-- Apply theorem e.g. `Continuous fun (f : (x : X) → Y x => f x)` -/
| apply
/-- Composition theorem e.g. `Continuous f → Continuous g → Continuous fun x => f (g x)` -/... | inductive | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | LambdaTheoremType | Tag for one of the 5 basic lambda theorems |
LambdaTheoremArgs.type (t : LambdaTheoremArgs) : LambdaTheoremType :=
match t with
| .id => .id
| .const => .const
| .comp .. => .comp
| .apply => .apply
| .pi => .pi | def | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | LambdaTheoremArgs.type | Convert `LambdaTheoremArgs` to `LambdaTheoremType`. |
detectLambdaTheoremArgs (f : Expr) (ctxVars : Array Expr) :
MetaM (Option LambdaTheoremArgs) := do
let f ← forallTelescope (← inferType f) fun xs _ =>
mkLambdaFVars xs (mkAppN f xs).headBeta
match f with
| .lam _ _ xBody _ =>
unless xBody.hasLooseBVars do return some .const
match xBody with
| ... | def | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | detectLambdaTheoremArgs | Decides whether `f` is a function corresponding to one of the lambda theorems. |
LambdaTheorem where
/-- Name of function property -/
funPropName : Name
/-- Name of lambda theorem -/
thmName : Name
/-- Type and important argument of the theorem. -/
thmArgs : LambdaTheoremArgs
deriving Inhabited, BEq | structure | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | LambdaTheorem | Structure holding information about lambda theorem. |
LambdaTheorems where
/-- map: function property name × theorem type → lambda theorem -/
theorems : Std.HashMap (Name × LambdaTheoremType) (Array LambdaTheorem) := {}
deriving Inhabited | structure | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | LambdaTheorems | Collection of lambda theorems |
LambdaTheorem.getProof (thm : LambdaTheorem) : MetaM Expr := do
mkConstWithFreshMVarLevels thm.thmName | def | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | LambdaTheorem.getProof | Return proof of lambda theorem |
LambdaTheoremsExt := SimpleScopedEnvExtension LambdaTheorem LambdaTheorems | abbrev | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | LambdaTheoremsExt | Environment extension storing lambda theorems. |
getLambdaTheorems (funPropName : Name) (type : LambdaTheoremType) :
CoreM (Array LambdaTheorem) := do
return (lambdaTheoremsExt.getState (← getEnv)).theorems.getD (funPropName,type) #[] | def | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | getLambdaTheorems | Environment extension storing all lambda theorems. -/
initialize lambdaTheoremsExt : LambdaTheoremsExt ←
registerSimpleScopedEnvExtension {
name := by exact decl_name%
initial := {}
addEntry := fun d e =>
{d with theorems :=
let es := d.theorems.getD (e.funPropName, e.thmArgs.type) #[]
... |
TheoremForm where
| uncurried | comp
deriving Inhabited, BEq, Repr | inductive | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | TheoremForm | Function theorems are stated in uncurried or compositional form.
uncurried
```
theorem Continuous_add : Continuous (fun x => x.1 + x.2)
```
compositional
```
theorem Continuous_add (hf : Continuous f) (hg : Continuous g) : Continuous (fun x => (f x) + (g x))
``` |
FunctionTheorem where
/-- function property name -/
funPropName : Name
/-- theorem name -/
thmOrigin : Origin
/-- function name -/
funOrigin : Origin
/-- array of argument indices about which this theorem is about -/
mainArgs : Array Nat
/-- total number of arguments applied to the function -/
... | structure | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | FunctionTheorem | TheoremForm to string -/
instance : ToString TheoremForm :=
⟨fun x => match x with | .uncurried => "simple" | .comp => "compositional"⟩
/-- theorem about specific function (either declared constant or free variable) |
FunctionTheorems where
/-- map: function name → function property → function theorem -/
theorems :
TreeMap Name (TreeMap Name (Array FunctionTheorem) compare) compare := {}
deriving Inhabited | structure | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | FunctionTheorems | null |
FunctionTheorem.getProof (thm : FunctionTheorem) : MetaM Expr := do
match thm.thmOrigin with
| .decl name => mkConstWithFreshMVarLevels name
| .fvar id => return .fvar id
set_option linter.style.docString.empty false in | def | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | FunctionTheorem.getProof | return proof of function theorem |
FunctionTheoremsExt := SimpleScopedEnvExtension FunctionTheorem FunctionTheorems | abbrev | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | FunctionTheoremsExt | null |
getTheoremsForFunction (funName : Name) (funPropName : Name) :
CoreM (Array FunctionTheorem) := do
return (functionTheoremsExt.getState (← getEnv)).theorems.getD funName {}
|>.getD funPropName #[] | def | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | getTheoremsForFunction | Extension storing all function theorems. -/
initialize functionTheoremsExt : FunctionTheoremsExt ←
registerSimpleScopedEnvExtension {
name := by exact decl_name%
initial := {}
addEntry := fun d e =>
{d with
theorems :=
d.theorems.alter e.funOrigin.name fun funProperties =>
... |
GeneralTheorem.getProof (thm : GeneralTheorem) : MetaM Expr := do
mkConstWithFreshMVarLevels thm.thmName | def | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | GeneralTheorem.getProof | Get proof of a theorem. |
GeneralTheoremsExt := SimpleScopedEnvExtension GeneralTheorem GeneralTheorems | abbrev | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | GeneralTheoremsExt | Extensions for transition or morphism theorems |
getTransitionTheorems (e : Expr) : FunPropM (Array GeneralTheorem) := do
let thms := (← get).transitionTheorems.theorems
let (candidates, thms) ← withConfig (fun cfg => { cfg with iota := false, zeta := false }) <|
thms.getMatch e false true
modify ({ · with transitionTheorems := ⟨thms⟩ })
return (← MonadEx... | def | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | getTransitionTheorems | Environment extension for transition theorems. -/
initialize transitionTheoremsExt : GeneralTheoremsExt ←
registerSimpleScopedEnvExtension {
name := by exact decl_name%
initial := {}
addEntry := fun d e =>
{d with theorems := e.keys.foldl (fun thms (key, entry) =>
RefinedDiscrTree.inser... |
getMorphismTheorems (e : Expr) : FunPropM (Array GeneralTheorem) := do
let thms := (← get).morTheorems.theorems
let (candidates, thms) ← withConfig (fun cfg => { cfg with iota := false, zeta := false }) <|
thms.getMatch e false true
modify ({ · with morTheorems := ⟨thms⟩ })
return (← MonadExcept.ofExcept ca... | def | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | getMorphismTheorems | Environment extension for morphism theorems. -/
initialize morTheoremsExt : GeneralTheoremsExt ←
registerSimpleScopedEnvExtension {
name := by exact decl_name%
initial := {}
addEntry := fun d e =>
{d with theorems := e.keys.foldl (fun thms (key, entry) =>
RefinedDiscrTree.insert thms ke... |
Theorem where
| lam (thm : LambdaTheorem)
| function (thm : FunctionTheorem)
| mor (thm : GeneralTheorem)
| transition (thm : GeneralTheorem) | inductive | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | Theorem | There are four types of theorems:
- lam - theorem about basic lambda calculus terms
- function - theorem about a specific function(declared or free variable) in specific arguments
- mor - special theorems talking about bundled morphisms/DFunLike.coe
- transition - theorems inferring one function property from another
... |
getTheoremFromConst (declName : Name) (prio : Nat := eval_prio default) : MetaM Theorem := do
let info ← getConstInfo declName
forallTelescope info.type fun xs b => do
let some (decl,f) ← getFunProp? b
| throwError "unrecognized function property `{← ppExpr b}`"
let funPropName := decl.funPropName
... | def | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | getTheoremFromConst | For a theorem declaration `declName` return `fun_prop` theorem. It correctly detects which
type of theorem it is. |
addTheorem (declName : Name) (attrKind : AttributeKind := .global)
(prio : Nat := eval_prio default) : MetaM Unit := do
match (← getTheoremFromConst declName prio) with
| .lam thm =>
trace[Meta.Tactic.fun_prop.attr] "\
lambda theorem: {thm.thmName}
function property: {thm.funPropName}
type: {repr thm.thmArg... | def | Tactic | [
"Mathlib.Tactic.FunProp.Decl",
"Mathlib.Tactic.FunProp.Types",
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Initialize",
"Mathlib.Lean.Meta.RefinedDiscrTree.Lookup"
] | Mathlib/Tactic/FunProp/Theorems.lean | addTheorem | Register theorem `declName` with `fun_prop`. |
isOrderedSubsetOf {α} [Inhabited α] [DecidableEq α] (a b : Array α) : Bool :=
Id.run do
if a.size > b.size then
return false
let mut i := 0
for h' : j in [0:b.size] do
if i = a.size then
break
if a[i]! = b[j] then
i := i+1
if i = a.size then
return true
else
return false | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/ToBatteries.lean | isOrderedSubsetOf | Check if `a` can be obtained by removing elements from `b`. |
_root_.Lean.Expr.swapBVars (e : Expr) (i j : Nat) : Expr :=
let swapBVarArray : Array Expr := Id.run do
let mut a : Array Expr := .mkEmpty e.looseBVarRange
for k in [0:e.looseBVarRange] do
a := a.push (.bvar (if k = i then j else if k = j then i else k))
a
e.instantiate swapBVarArray | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/ToBatteries.lean | _root_.Lean.Expr.swapBVars | Swaps bvars indices `i` and `j`
NOTE: the indices `i` and `j` do not correspond to the `n` in `bvar n`. Rather
they behave like indices in `Expr.lowerLooseBVars`, `Expr.liftLooseBVars`, etc.
TODO: This has to have a better implementation, but I'm still beyond confused with how bvar
indices work |
mkProdElem (xs : Array Expr) : MetaM Expr := do
match h : xs.size with
| 0 => return default
| 1 => return xs[0]
| n + 1 =>
xs[0:n].foldrM (init := xs[n]) fun x p => mkAppM ``Prod.mk #[x,p] | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/ToBatteries.lean | mkProdElem | For `#[x₁, .., xₙ]` create `(x₁, .., xₙ)`. |
mkProdProj (x : Expr) (i : Nat) (n : Nat) : MetaM Expr := do
match i, n with
| _, 0 => pure x
| _, 1 => pure x
| 0, _ => mkAppM ``Prod.fst #[x]
| i'+1, n'+1 => mkProdProj (← withTransparency .all <| mkAppM ``Prod.snd #[x]) i' n' | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/ToBatteries.lean | mkProdProj | For `(x₀, .., xₙ₋₁)` return `xᵢ` but as a product projection.
We need to know the total size of the product to be considered.
For example for `xyz : X × Y × Z`
- `mkProdProj xyz 1 3` returns `xyz.snd.fst`.
- `mkProdProj xyz 1 2` returns `xyz.snd`. |
mkProdSplitElem (xs : Expr) (n : Nat) : MetaM (Array Expr) :=
(Array.range n)
|>.mapM (fun i ↦ mkProdProj xs i n) | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/ToBatteries.lean | mkProdSplitElem | For an element of a product type(of size`n`) `xs` create an array of all possible projections
i.e. `#[xs.1, xs.2.1, xs.2.2.1, ..., xs.2..2]` |
mkUncurryFun (n : Nat) (f : Expr) : MetaM Expr := do
if n ≤ 1 then
return f
forallBoundedTelescope (← inferType f) n fun xs _ ↦ do
let xProdName : String ← xs.foldlM (init:="") fun n x ↦
do return (n ++ toString (← x.fvarId!.getUserName).eraseMacroScopes)
let xProdType ← inferType (← mkProdElem xs... | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/ToBatteries.lean | mkUncurryFun | Uncurry function `f` in `n` arguments. |
etaExpand1 (f : Expr) : MetaM Expr := do
let f := f.eta
if f.isLambda then
return f
else
withDefault do forallBoundedTelescope (← inferType f) (.some 1) fun xs _ => do
mkLambdaFVars xs (mkAppN f xs) | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/ToBatteries.lean | etaExpand1 | Eta expand `f` in only one variable and reduce in others.
Examples:
```
f ==> fun x => f x
fun x y => f x y ==> fun x => f x
HAdd.hAdd y ==> fun x => HAdd.hAdd y x
HAdd.hAdd ==> fun x => HAdd.hAdd x
``` |
private betaThroughLetAux (f : Expr) (args : List Expr) : Expr :=
match f, args with
| f, [] => f
| .lam _ _ b _, a :: as => (betaThroughLetAux (b.instantiate1 a) as)
| .letE n t v b nondep, args => .letE n t v (betaThroughLetAux b args) nondep
| .mdata _ b, args => betaThroughLetAux b args
| f, args => mkA... | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/ToBatteries.lean | betaThroughLetAux | Implementation of `betaThroughLet` |
betaThroughLet (f : Expr) (args : Array Expr) : Expr :=
betaThroughLetAux f args.toList | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/ToBatteries.lean | betaThroughLet | Apply the given arguments to `f`, beta-reducing if `f` is a lambda expression. This variant
does beta-reduction through let bindings without inlining them.
Example
```
beta' (fun x => let y := x * x; fun z => x + y + z) #[a,b]
==>
let y := a * a; a + y + b
``` |
headBetaThroughLet (e : Expr) : Expr :=
let f := e.getAppFn
if f.isHeadBetaTargetFn true then betaThroughLet f e.getAppArgs else e | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/FunProp/ToBatteries.lean | headBetaThroughLet | Beta reduces head of an expression, `(fun x => e) a` ==> `e[x/a]`. This version applies
arguments through let bindings without inlining them.
Example
```
headBeta' ((fun x => let y := x * x; fun z => x + y + z) a b)
==>
let y := a * a; a + y + b
``` |
Origin where
/-- It is a constant defined in the environment. -/
| decl (name : Name)
/-- It is a free variable in the local context. -/
| fvar (fvarId : FVarId)
deriving Inhabited, BEq | inductive | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | Origin | Indicated origin of a function or a statement. |
Origin.name (origin : Origin) : Name :=
match origin with
| .decl name => name
| .fvar id => id.name | def | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | Origin.name | Name of the origin. |
Origin.getValue (origin : Origin) : MetaM Expr := do
match origin with
| .decl name => mkConstWithFreshMVarLevels name
| .fvar id => pure (.fvar id) | def | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | Origin.getValue | Get the expression specified by `origin`. |
ppOrigin {m} [Monad m] [MonadEnv m] [MonadError m] : Origin → m MessageData
| .decl n => return m!"{← mkConstWithLevelParams n}"
| .fvar n => return mkFVar n | def | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | ppOrigin | Pretty print `FunProp.Origin`. |
ppOrigin' (origin : Origin) : MetaM String := do
match origin with
| .fvar id => return s!"{← ppExpr (.fvar id)} : {← ppExpr (← inferType (.fvar id))}"
| _ => pure (toString origin.name) | def | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | ppOrigin' | Pretty print `FunProp.Origin`. Returns string unlike `ppOrigin`. |
FunctionData.getFnOrigin (fData : FunctionData) : Origin :=
match fData.fn with
| .fvar id => .fvar id
| .const name _ => .decl name
| _ => .decl Name.anonymous | def | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | FunctionData.getFnOrigin | Get origin of the head function. |
defaultNamesToUnfold : Array Name :=
#[`id, `Function.comp, `Function.HasUncurry.uncurry, `Function.uncurry] | def | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | defaultNamesToUnfold | Default names to be considered reducible by `fun_prop` |
Config where
/-- Maximum number of transitions between function properties. For example inferring continuity
from differentiability and then differentiability from smoothness (`ContDiff ℝ ∞`) requires
`maxTransitionDepth = 2`. The default value of one expects that transition theorems are
transitively closed e.g... | structure | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | Config | `fun_prop` configuration |
Context where
/-- fun_prop config -/
config : Config := {}
/-- Name to unfold -/
constToUnfold : TreeSet Name Name.quickCmp :=
.ofArray defaultNamesToUnfold _
/-- Custom discharger to satisfy theorem hypotheses. -/
disch : Expr → MetaM (Option Expr) := fun _ => pure none
/-- current transition depth -... | structure | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | Context | `fun_prop` context |
GeneralTheorem where
/-- function property name -/
funPropName : Name
/-- theorem name -/
thmName : Name
/-- discrimination tree keys used to index this theorem -/
keys : List (RefinedDiscrTree.Key × RefinedDiscrTree.LazyEntry)
/-- priority -/
priority : Nat := eval_prio default
deriving Inhabited | structure | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | GeneralTheorem | General theorem about a function property used for transition and morphism theorems |
GeneralTheorems where
/-- Discrimination tree indexing theorems. -/
theorems : RefinedDiscrTree GeneralTheorem := {}
deriving Inhabited | structure | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | GeneralTheorems | Structure holding transition or morphism theorems for `fun_prop` tactic. |
State where
/-- Simp's cache is used as the `fun_prop` tactic is designed to be used inside of simp and
utilize its cache. It holds successful goals. -/
cache : Simp.Cache := {}
/-- Cache storing failed goals such that they are not tried again. -/
failureCache : ExprSet := {}
/-- Count the number of steps a... | structure | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | State | `fun_prop` state |
Context.increaseTransitionDepth (ctx : Context) : Context :=
{ctx with transitionDepth := ctx.transitionDepth + 1} | def | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | Context.increaseTransitionDepth | Increase depth |
FunPropM := ReaderT FunProp.Context <| StateT FunProp.State MetaM
set_option linter.style.docString.empty false in | abbrev | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | FunPropM | Monad to run `fun_prop` tactic in. |
Result where
/-- -/
proof : Expr | structure | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | Result | Result of `funProp`, it is a proof of function property `P f` |
defaultUnfoldPred : Name → Bool :=
defaultNamesToUnfold.contains | def | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | defaultUnfoldPred | Default names to unfold |
unfoldNamePred : FunPropM (Name → Bool) := do
let toUnfold := (← read).constToUnfold
return fun n => toUnfold.contains n | def | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | unfoldNamePred | Get predicate on names indicating whether they should be unfolded. |
increaseSteps : FunPropM Unit := do
let numSteps := (← get).numSteps
let maxSteps := (← read).config.maxSteps
if numSteps > maxSteps then
throwError s!"fun_prop failed, maximum number({maxSteps}) of steps exceeded"
modify (fun s => {s with numSteps := s.numSteps + 1}) | def | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | increaseSteps | Increase heartbeat, throws error when `maxSteps` was reached |
withIncreasedTransitionDepth {α} (go : FunPropM (Option α)) : FunPropM (Option α) := do
let maxDepth := (← read).config.maxTransitionDepth
let newDepth := (← read).transitionDepth + 1
if newDepth > maxDepth then
trace[Meta.Tactic.fun_prop]
"maximum transition depth ({maxDepth}) reached
if you want `fu... | def | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | withIncreasedTransitionDepth | Increase transition depth. Return `none` if maximum transition depth has been reached. |
logError (msg : String) : FunPropM Unit := do
if (← read).transitionDepth = 0 then
modify fun s =>
{s with msgLog :=
if s.msgLog.contains msg then
s.msgLog
else
msg::s.msgLog} | def | Tactic | [
"Mathlib.Tactic.FunProp.FunctionData",
"Mathlib.Lean.Meta.RefinedDiscrTree.Basic"
] | Mathlib/Tactic/FunProp/Types.lean | logError | Log error message that will displayed to the user at the end.
Messages are logged only when `transitionDepth = 0` i.e. when `fun_prop` is **not** trying to infer
function property like continuity from another property like differentiability.
The main reason is that if the user forgets to add a continuity theorem for f... |
mul_le_mul_of_nonneg_left [Mul α] [Zero α] [Preorder α] [PosMulMono α]
{a b c : α} (h : b ≤ c) (a0 : 0 ≤ a) :
a * b ≤ a * c | theorem | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | mul_le_mul_of_nonneg_left | null |
mul_le_mul_of_nonneg_right [Mul α] [Zero α] [Preorder α] [MulPosMono α]
{a b c : α} (h : b ≤ c) (a0 : 0 ≤ a) :
b * a ≤ c * a | theorem | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | mul_le_mul_of_nonneg_right | null |
mul_le_mul [MulZeroClass α] [Preorder α] [PosMulMono α] [MulPosMono α]
{a b c d : α} (h₁ : a ≤ b) (h₂ : c ≤ d) (c0 : 0 ≤ c) (b0 : 0 ≤ b) :
a * c ≤ b * d
```
The advantage of this approach is that the lemmas with fewer "varying" input pairs typically require
fewer side conditions, so the tactic becomes more usef... | theorem | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | mul_le_mul | null |
mul_le_mul' [Mul α] [Preorder α] [MulLeftMono α]
[MulRightMono α] {a b c d : α} (h₁ : a ≤ b) (h₂ : c ≤ d) :
a * c ≤ b * d
``` | theorem | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | mul_le_mul' | null |
GCongr.Finset.sum_le_sum [OrderedAddCommMonoid N] {f g : ι → N} {s : Finset ι}
(h : ∀ (i : ι), i ∈ s → f i ≤ g i) :
s.sum f ≤ s.sum g
```
The tactic automatically introduces the variable `i✝ : ι` and hypothesis `hi✝ : i✝ ∈ s` in the
subgoal `∀ (i : ι), i ∈ s → f i ≤ g i` generated by applying this lemma. By de... | theorem | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | GCongr.Finset.sum_le_sum | null |
GCongrKey where
/-- The name of the relation. For example, `a + b ≤ a + c` has ``relName := `LE.le``. -/
relName : Name
/-- The name of the head function. For example, `a + b ≤ a + c` has ``head := `HAdd.hAdd``. -/
head : Name
/-- The number of arguments that `head` is applied to.
For example, `a + b ≤ a + ... | structure | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | GCongrKey | `GCongrKey` is the key used in the hashmap for looking up `gcongr` lemmas. |
GCongrLemma where
/-- The key under which the lemma is stored. -/
key : GCongrKey
/-- The name of the lemma. -/
declName : Name
/-- `mainSubgoals` are the subgoals on which `gcongr` will be recursively called. They store
- the index of the hypothesis
- the index of the arguments in the conclusion
- the ... | structure | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | GCongrLemma | Structure recording the data for a "generalized congruence" (`gcongr`) lemma. |
GCongrLemmas := Std.HashMap GCongrKey (List GCongrLemma) | abbrev | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | GCongrLemmas | A collection of `GCongrLemma`, to be stored in the environment extension. |
GCongrLemma.prioLE (a b : GCongrLemma) : Bool :=
(compare a.prio b.prio).then (compare b.numVarying a.numVarying) |>.isLE | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | GCongrLemma.prioLE | Return `true` if the priority of `a` is less than or equal to the priority of `b`. |
addGCongrLemmaEntry (m : GCongrLemmas) (l : GCongrLemma) : GCongrLemmas :=
match m[l.key]? with
| none => m.insert l.key [l]
| some es => m.insert l.key <| insert l es
where
/--- Insert a `GCongrLemma` in the correct place in a list of lemmas. -/
insert (l : GCongrLemma) : List GCongrLemma → List GCongrLem... | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | addGCongrLemmaEntry | Insert a `GCongrLemma` in a collection of lemmas, making sure that the lemmas are sorted. |
getCongrAppFnArgs (e : Expr) : Option (Name × Array Expr) :=
match e.cleanupAnnotations with
| .forallE n d b bi =>
if b.hasLooseBVars then
some (`_Forall, #[.lam n d b bi])
else
some (`_Implies, #[d, b])
| e => e.withApp fun f args => f.constName?.map (·, args) | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | getCongrAppFnArgs | Environment extension for "generalized congruence" (`gcongr`) lemmas. -/
initialize gcongrExt : SimpleScopedEnvExtension GCongrLemma
(Std.HashMap GCongrKey (List GCongrLemma)) ←
registerSimpleScopedEnvExtension {
addEntry := addGCongrLemmaEntry
initial := {}
}
/-- Given an application `f a₁ .. aₙ`, ret... |
getRel (e : Expr) : Option (Name × Expr × Expr) :=
match e with
| .app (.app rel lhs) rhs => rel.getAppFn.constName?.map (·, lhs, rhs)
| .forallE _ lhs rhs _ =>
if !rhs.hasLooseBVars then
some (`_Implies, lhs, rhs)
else
none
| _ => none | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | getRel | If `e` is of the form `r a b`, return `(r, a, b)`. |
makeGCongrLemma (declName : Name) (declTy : Expr) (numHyps prio : Nat) : MetaM GCongrLemma := do
withReducible <| forallBoundedTelescope declTy numHyps fun xs targetTy => do
let fail {α} (m : MessageData) : MetaM α := throwError "\
@[gcongr] attribute only applies to lemmas proving f x₁ ... xₙ ∼ f x₁' ... x... | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | makeGCongrLemma | Construct the `GCongrLemma` data from a given lemma. |
gcongrDischarger (goal : MVarId) : MetaM Unit := Elab.Term.TermElabM.run' do
trace[Meta.gcongr] "Attempting to discharge side goal {goal}"
let [] ← Elab.Tactic.run goal <|
Elab.Tactic.evalTactic (Unhygienic.run `(tactic| gcongr_discharger))
| failure
open Elab Tactic | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | gcongrDischarger | Attribute marking "generalized congruence" (`gcongr`) lemmas. Such lemmas must have a
conclusion of a form such as `f x₁ y z₁ ∼ f x₂ y z₂`; that is, a relation between the application of
a function to two argument lists, in which the "varying argument" pairs (here `x₁`/`x₂` and
`z₁`/`z₂`) are all free variables.
The ... |
@[gcongr_forward] exactRefl : ForwardExt where
eval h goal := do
let m ← mkFreshExprMVar none
goal.assignIfDefEq (← mkAppOptM ``Eq.subst #[h, m])
goal.applyRfl | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | exactRefl | See if the term is `a = b` and the goal is `a ∼ b` or `b ∼ a`, with `∼` reflexive. |
@[gcongr_forward] symmExact : ForwardExt where
eval h goal := do (← goal.applySymm).assignIfDefEq h
@[gcongr_forward] def exact : ForwardExt where
eval e m := m.assignIfDefEq e | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | symmExact | See if the term is `a ∼ b` with `∼` symmetric and the goal is `b ∼ a`. |
_root_.Lean.MVarId.gcongrForward (hs : Array Expr) (g : MVarId) : MetaM Unit :=
withReducible do
let s ← saveState
withTraceNode `Meta.gcongr (fun _ => return m!"gcongr_forward: ⊢ {← g.getType}") do
let tacs := (forwardExt.getState (← getEnv)).2
for h in hs do
try
tacs.firstM fun (n, tac... | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | _root_.Lean.MVarId.gcongrForward | Attempt to resolve an (implicitly) relational goal by one of a provided list of hypotheses,
either with such a hypothesis directly or by a limited palette of relational forward-reasoning from
these hypotheses. |
gcongrForwardDischarger (goal : MVarId) : MetaM Unit := Elab.Term.TermElabM.run' do
let mut hs := #[]
for h in ← getLCtx do
if !h.isImplementationDetail then
hs := hs.push (.fvar h.fvarId)
goal.gcongrForward hs | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | gcongrForwardDischarger | This is used as the default main-goal discharger,
consisting of running `Lean.MVarId.gcongrForward` (trying a term together with limited
forward-reasoning on that term) on each nontrivial hypothesis. |
containsHole (template : Expr) : MetaM Bool := do
let mctx ← getMCtx
let hasMVar := template.findMVar? fun mvarId =>
if let some mdecl := mctx.findDecl? mvarId then
mdecl.kind matches .syntheticOpaque
else
false
return hasMVar.isSome | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | containsHole | Determine whether `template` contains a `?_`.
This guides the `gcongr` tactic when it is given a template. |
rel_imp_rel (h₁ : r c a) (h₂ : r b d) : r a b → r c d :=
fun h => IsTrans.trans c b d (IsTrans.trans c a b h₁ h) h₂ | lemma | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | rel_imp_rel | null |
relImpRelLemma (arity : Nat) : List GCongrLemma :=
if arity < 2 then [] else [{
declName := ``rel_imp_rel
mainSubgoals := #[(7, arity - 2, 0), (8, arity - 1, 0)]
numHyps := 9
key := default, prio := default, numVarying := default
}] | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | relImpRelLemma | Construct a `GCongrLemma` for `gcongr` goals of the form `a ≺ b → c ≺ d`.
This will be tried if there is no other available `@[gcongr]` lemma.
For example, the relation `a ≡ b [ZMOD n]` has an instance of `IsTrans`, so a congruence of the form
`a ≡ b [ZMOD n] → c ≡ d [ZMOD n]` can be solved with `rel_imp_rel`, `rel_tra... |
_root_.Lean.MVarId.applyWithArity (mvarId : MVarId) (e : Expr) (arity : Nat)
(cfg : ApplyConfig := {}) (term? : Option MessageData := none) : MetaM (List MVarId) :=
mvarId.withContext do
mvarId.checkNotAssigned `apply
let targetType ← mvarId.getType
let eType ← inferType e
let (newMVars, bind... | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | _root_.Lean.MVarId.applyWithArity | `Lean.MVarId.applyWithArity` is a copy of `Lean.MVarId.apply`, where the arity of the
applied function is given explicitly instead of being inferred.
TODO: make `Lean.MVarId.apply` take a configuration argument to do this itself |
partial _root_.Lean.MVarId.gcongr
(g : MVarId) (template : Option Expr) (names : List (TSyntax ``binderIdent))
(depth : Nat := 1000000)
(grewriteHole : Option MVarId := none)
(mainGoalDischarger : MVarId → MetaM Unit := gcongrForwardDischarger)
(sideGoalDischarger : MVarId → MetaM Unit := gcongrDisc... | def | Tactic | [
"Lean",
"Batteries.Lean.Except",
"Batteries.Tactic.Exact",
"Mathlib.Lean.Elab.Term",
"Mathlib.Tactic.GCongr.ForwardAttr",
"Mathlib.Order.Defs.Unbundled"
] | Mathlib/Tactic/GCongr/Core.lean | _root_.Lean.MVarId.gcongr | The core of the `gcongr` tactic. Parse a goal into the form `(f _ ... _) ∼ (f _ ... _)`,
look up any relevant `@[gcongr]` lemmas, try to apply them, recursively run the tactic itself on
"main" goals which are generated, and run the discharger on side goals which are generated. If there
is a user-provided template, fir... |
imp_trans (h : a → b) : (b → c) → a → c := fun g ha => g (h ha) | lemma | Tactic | [
"Mathlib.Tactic.GCongr.Core"
] | Mathlib/Tactic/GCongr/CoreAttrs.lean | imp_trans | null |
imp_right_mono (h : a → b → c) : (a → b) → a → c :=
fun h' ha => h ha (h' ha) | lemma | Tactic | [
"Mathlib.Tactic.GCongr.Core"
] | Mathlib/Tactic/GCongr/CoreAttrs.lean | imp_right_mono | null |
and_right_mono (h : a → b → c) : (a ∧ b) → a ∧ c :=
fun ⟨ha, hb⟩ => ⟨ha, h ha hb⟩
attribute [gcongr] mt
Or.imp Or.imp_left Or.imp_right
And.imp And.imp_left GCongr.and_right_mono
imp_imp_imp GCongr.imp_trans GCongr.imp_right_mono
forall_imp Exists.imp
List.Sublist.append List.Sublist.append_left List.Sublis... | lemma | Tactic | [
"Mathlib.Tactic.GCongr.Core"
] | Mathlib/Tactic/GCongr/CoreAttrs.lean | and_right_mono | null |
ForwardExt where
eval (h : Expr) (goal : MVarId) : MetaM Unit | structure | Tactic | [
"Mathlib.Init",
"Batteries.Tactic.Basic"
] | Mathlib/Tactic/GCongr/ForwardAttr.lean | ForwardExt | An extension for `gcongr_forward`. |
mkForwardExt (n : Name) : ImportM ForwardExt := do
let { env, opts, .. } ← read
IO.ofExcept <| unsafe env.evalConstCheck ForwardExt opts ``ForwardExt n | def | Tactic | [
"Mathlib.Init",
"Batteries.Tactic.Basic"
] | Mathlib/Tactic/GCongr/ForwardAttr.lean | mkForwardExt | Read a `gcongr_forward` extension from a declaration of the right type. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.