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
partial copyMetaData (cfg : Config) (src tgt : Name) (argInfo : ArgInfo) : CoreM (Array Name) := do if let some eqns := eqnsAttribute.find? (← getEnv) src then unless (eqnsAttribute.find? (← getEnv) tgt).isSome do for eqn in eqns do _ ← addToAdditiveAttr eqn cfg eqnsAttribute.add tgt (eqns.map (fi...
def
Tactic
[ "Batteries.Tactic.Trans", "Lean.Compiler.NoncomputableAttr", "Lean.Elab.Tactic.Ext", "Lean.Meta.Tactic.Rfl", "Lean.Meta.Tactic.Symm", "Lean.Meta.Tactic.TryThis", "Mathlib.Data.Array.Defs", "Mathlib.Data.Nat.Notation", "Mathlib.Lean.Expr.ReplaceRec", "Mathlib.Lean.Meta.Simp", "Mathlib.Lean.Name",...
Mathlib/Tactic/ToAdditive/Frontend.lean
copyMetaData
Copies equation lemmas and attributes from `src` to `tgt`
partial transformDecl (cfg : Config) (src tgt : Name) (argInfo : ArgInfo := {}) : CoreM (Array Name) := do transformDeclAux cfg src tgt src copyMetaData cfg src tgt argInfo
def
Tactic
[ "Batteries.Tactic.Trans", "Lean.Compiler.NoncomputableAttr", "Lean.Elab.Tactic.Ext", "Lean.Meta.Tactic.Rfl", "Lean.Meta.Tactic.Symm", "Lean.Meta.Tactic.TryThis", "Mathlib.Data.Array.Defs", "Mathlib.Data.Nat.Notation", "Mathlib.Lean.Expr.ReplaceRec", "Mathlib.Lean.Meta.Simp", "Mathlib.Lean.Name",...
Mathlib/Tactic/ToAdditive/Frontend.lean
transformDecl
Make a new copy of a declaration, replacing fragments of the names of identifiers in the type and the body using the `translations` dictionary. This is used to implement `@[to_additive]`.
partial checkExistingType (src tgt : Name) (reorder : List (List Nat)) (dont : List Ident) : MetaM Unit := do let mut srcDecl ← getConstInfo src let tgtDecl ← getConstInfo tgt if 0 ∈ reorder.flatten then srcDecl := srcDecl.updateLevelParams srcDecl.levelParams.swapFirstTwo unless srcDecl.levelParams.len...
def
Tactic
[ "Batteries.Tactic.Trans", "Lean.Compiler.NoncomputableAttr", "Lean.Elab.Tactic.Ext", "Lean.Meta.Tactic.Rfl", "Lean.Meta.Tactic.Symm", "Lean.Meta.Tactic.TryThis", "Mathlib.Data.Array.Defs", "Mathlib.Data.Nat.Notation", "Mathlib.Lean.Expr.ReplaceRec", "Mathlib.Lean.Meta.Simp", "Mathlib.Lean.Name",...
Mathlib/Tactic/ToAdditive/Frontend.lean
checkExistingType
Verify that the type of given `srcDecl` translates to that of `tgtDecl`.
partial addToAdditiveAttr (src : Name) (cfg : Config) (kind := AttributeKind.global) : AttrM (Array Name) := do if (kind != AttributeKind.global) then throwError "`to_additive` can only be used as a global attribute" withOptions (· |>.updateBool `trace.to_additive (cfg.trace || ·)) <| do if let some tgt :...
def
Tactic
[ "Batteries.Tactic.Trans", "Lean.Compiler.NoncomputableAttr", "Lean.Elab.Tactic.Ext", "Lean.Meta.Tactic.Rfl", "Lean.Meta.Tactic.Symm", "Lean.Meta.Tactic.TryThis", "Mathlib.Data.Array.Defs", "Mathlib.Data.Nat.Notation", "Mathlib.Lean.Expr.ReplaceRec", "Mathlib.Lean.Meta.Simp", "Mathlib.Lean.Name",...
Mathlib/Tactic/ToAdditive/Frontend.lean
addToAdditiveAttr
`addToAdditiveAttr src cfg` adds a `@[to_additive]` attribute to `src` with configuration `cfg`. See the attribute implementation for more details. It returns an array with names of additive declarations (usually 1, but more if there are nested `to_additive` calls.
endCapitalNames : TreeMap String (List String) compare := .ofList [("LE", [""]), ("LT", [""]), ("WF", [""]), ("Coe", ["TC", "T", "HTCT"])] open String in
def
Tactic
[ "Std.Data.TreeMap.Basic", "Mathlib.Data.String.Defs" ]
Mathlib/Tactic/ToAdditive/GuessName.lean
endCapitalNames
A set of strings of names that end in a capital letter. * If the string contains a lowercase letter, the string should be split between the first occurrence of a lower-case letter followed by an upper-case letter. * If multiple strings have the same prefix, they should be grouped by prefix * In this case, the second ...
partial _root_.String.splitCase (s : String) (i₀ : Pos := 0) (r : List String := []) : List String := Id.run do let i₁ := s.next i₀ if s.atEnd i₁ then let r := s::r return r.reverse /- We split the string in three cases * We split on both sides of `_` to keep them there when rejoining the string; ...
def
Tactic
[ "Std.Data.TreeMap.Basic", "Mathlib.Data.String.Defs" ]
Mathlib/Tactic/ToAdditive/GuessName.lean
_root_.String.splitCase
This function takes a String and splits it into separate parts based on the following [naming conventions](https://github.com/leanprover-community/mathlib4/wiki#naming-convention). E.g. `#eval "InvHMulLEConjugate₂SMul_ne_top".splitCase` yields `["Inv", "HMul", "LE", "Conjugate₂", "SMul", "_", "ne", "_", "top"]`.
partial capitalizeLikeAux (s : String) (i : String.Pos := 0) (p : String) : String := if p.atEnd i || s.atEnd i then p else let j := p.next i if (s.get i).isLower then capitalizeLikeAux s j <| p.set i (p.get i |>.toLower) else if (s.get i).isUpper then capitalizeLikeAux s j <| p.set i (p...
def
Tactic
[ "Std.Data.TreeMap.Basic", "Mathlib.Data.String.Defs" ]
Mathlib/Tactic/ToAdditive/GuessName.lean
capitalizeLikeAux
Helper for `capitalizeLike`.
capitalizeLike (r : String) (s : String) := capitalizeLikeAux r 0 s
def
Tactic
[ "Std.Data.TreeMap.Basic", "Mathlib.Data.String.Defs" ]
Mathlib/Tactic/ToAdditive/GuessName.lean
capitalizeLike
Capitalizes `s` char-by-char like `r`. If `s` is longer, it leaves the tail untouched.
capitalizeFirstLike (s : String) : List String → List String | x :: r => capitalizeLike s x :: r | [] => []
def
Tactic
[ "Std.Data.TreeMap.Basic", "Mathlib.Data.String.Defs" ]
Mathlib/Tactic/ToAdditive/GuessName.lean
capitalizeFirstLike
Capitalize First element of a list like `s`. Note that we need to capitalize multiple characters in some cases, in examples like `HMul` or `hAdd`.
nameDict : String → List String | "one" => ["zero"] | "mul" => ["add"] | "smul" => ["vadd"] | "inv" => ["neg"] | "div" => ["sub"] | "prod" => ["sum"] | "hmul" => ["hadd"] | "hsmul" => ["hvadd"] | "hdiv" => ["hsub"] |...
def
Tactic
[ "Std.Data.TreeMap.Basic", "Mathlib.Data.String.Defs" ]
Mathlib/Tactic/ToAdditive/GuessName.lean
nameDict
Dictionary used by `guessName` to autogenerate names. Note: `guessName` capitalizes first element of the output according to capitalization of the input. Input and first element should therefore be lower-case, 2nd element should be capitalized properly.
applyNameDict : List String → List String | x :: s => (capitalizeFirstLike x (nameDict x.toLower)) ++ applyNameDict s | [] => []
def
Tactic
[ "Std.Data.TreeMap.Basic", "Mathlib.Data.String.Defs" ]
Mathlib/Tactic/ToAdditive/GuessName.lean
applyNameDict
Turn each element to lower-case, apply the `nameDict` and capitalize the output like the input.
fixAbbreviation : List String → List String | "is" :: "Cancel" :: "Add" :: s => "isCancelAdd" :: fixAbbreviation s | "Is" :: "Cancel" :: "Add" :: s => "IsCancelAdd" :: fixAbbreviation s | "is" :: "Left" :: "Cancel" :: "Add" :: s => "isLeftCancelAdd" :: fixAbbreviation s | "Is" :: "Left" :: "Cancel" :: "A...
def
Tactic
[ "Std.Data.TreeMap.Basic", "Mathlib.Data.String.Defs" ]
Mathlib/Tactic/ToAdditive/GuessName.lean
fixAbbreviation
There are a few abbreviations we use. For example "Nonneg" instead of "ZeroLE" or "addComm" instead of "commAdd". Note: The input to this function is case sensitive! Todo: A lot of abbreviations here are manual fixes and there might be room to improve the naming logic to reduce the size of `fixAbbreviation`.
guessName : String → String := String.mapTokens '\'' <| fun s => String.join <| fixAbbreviation <| applyNameDict <| s.splitCase
def
Tactic
[ "Std.Data.TreeMap.Basic", "Mathlib.Data.String.Defs" ]
Mathlib/Tactic/ToAdditive/GuessName.lean
guessName
Autogenerate additive name. This runs in several steps: 1) Split according to capitalisation rule and at `_`. 2) Apply word-by-word translation rules. 3) Fix up abbreviations that are not word-by-word translations, like "addComm" or "Nonneg".
@[tactic_code_action calcTactic] createCalc : TacticCodeAction := fun _params _snap ctx _stack node => do let .node (.ofTacticInfo info) _ := node | return #[] if info.goalsBefore.isEmpty then return #[] let eager := { title := s!"Generate a calc block." kind? := "quickfix" } let doc ← readDoc retur...
def
Tactic
[ "Lean.Elab.Tactic.Calc", "Lean.Meta.Tactic.TryThis", "Mathlib.Data.String.Defs", "Mathlib.Tactic.Widget.SelectPanelUtils", "Batteries.CodeAction.Attr", "Batteries.Lean.Position" ]
Mathlib/Tactic/Widget/Calc.lean
createCalc
Code action to create a `calc` tactic from the current goal.
CalcParams extends SelectInsertParams where /-- Is this the first calc step? -/ isFirst : Bool /-- indentation level of the calc block. -/ indent : Nat deriving SelectInsertParamsClass, RpcEncodable
structure
Tactic
[ "Lean.Elab.Tactic.Calc", "Lean.Meta.Tactic.TryThis", "Mathlib.Data.String.Defs", "Mathlib.Tactic.Widget.SelectPanelUtils", "Batteries.CodeAction.Attr", "Batteries.Lean.Position" ]
Mathlib/Tactic/Widget/Calc.lean
CalcParams
Parameters for the calc widget.
suggestSteps (pos : Array Lean.SubExpr.GoalsLocation) (goalType : Expr) (params : CalcParams) : MetaM (String × String × Option (String.Pos × String.Pos)) := do let subexprPos := getGoalLocations pos let some (rel, lhs, rhs) ← Lean.Elab.Term.getCalcRelation? goalType | throwError "invalid 'calc' step, rel...
def
Tactic
[ "Lean.Elab.Tactic.Calc", "Lean.Meta.Tactic.TryThis", "Mathlib.Data.String.Defs", "Mathlib.Tactic.Widget.SelectPanelUtils", "Batteries.CodeAction.Attr", "Batteries.Lean.Position" ]
Mathlib/Tactic/Widget/Calc.lean
suggestSteps
Return the link text and inserted text above and below of the calc widget.
@[server_rpc_method] CalcPanel.rpc := mkSelectionPanelRPC suggestSteps "Please select subterms using Shift-click." "Calc 🔍"
def
Tactic
[ "Lean.Elab.Tactic.Calc", "Lean.Meta.Tactic.TryThis", "Mathlib.Data.String.Defs", "Mathlib.Tactic.Widget.SelectPanelUtils", "Batteries.CodeAction.Attr", "Batteries.Lean.Position" ]
Mathlib/Tactic/Widget/Calc.lean
CalcPanel.rpc
Rpc function for the calc widget.
@[widget_module] CalcPanel : Component CalcParams := mk_rpc_widget% CalcPanel.rpc
def
Tactic
[ "Lean.Elab.Tactic.Calc", "Lean.Meta.Tactic.TryThis", "Mathlib.Data.String.Defs", "Mathlib.Tactic.Widget.SelectPanelUtils", "Batteries.CodeAction.Attr", "Batteries.Lean.Position" ]
Mathlib/Tactic/Widget/Calc.lean
CalcPanel
The calc widget.
@[inline] _root_.Lean.Expr.app7? (e : Expr) (fName : Name) : Option (Expr × Expr × Expr × Expr × Expr × Expr × Expr) := if e.isAppOfArity fName 7 then some ( e.appFn!.appFn!.appFn!.appFn!.appFn!.appFn!.appArg!, e.appFn!.appFn!.appFn!.appFn!.appFn!.appArg!, e.appFn!.appFn!.appFn!.appFn!.appAr...
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Presentation.Expr", "Mathlib.CategoryTheory.Category.Basic" ]
Mathlib/Tactic/Widget/CommDiag.lean
_root_.Lean.Expr.app7
If the expression is a function application of `fName` with 7 arguments, return those arguments. Otherwise return `none`.
homType? (e : Expr) : Option (Expr × Expr) := do let some (_, _, A, B) := e.app4? ``Quiver.Hom | none return (A, B)
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Presentation.Expr", "Mathlib.CategoryTheory.Category.Basic" ]
Mathlib/Tactic/Widget/CommDiag.lean
homType
Given a Hom type `α ⟶ β`, return `(α, β)`. Otherwise `none`.
homComp? (f : Expr) : Option (Expr × Expr) := do let some (_, _, _, _, _, f, g) := f.app7? ``CategoryStruct.comp | none return (f, g)
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Presentation.Expr", "Mathlib.CategoryTheory.Category.Basic" ]
Mathlib/Tactic/Widget/CommDiag.lean
homComp
Given composed homs `g ≫ h`, return `(g, h)`. Otherwise `none`.
ExprEmbeds := Array (String × Expr) /-! ## Widget for general commutative diagrams -/ open scoped Jsx in
abbrev
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Presentation.Expr", "Mathlib.CategoryTheory.Category.Basic" ]
Mathlib/Tactic/Widget/CommDiag.lean
ExprEmbeds
Expressions to display as labels in a diagram.
mkCommDiag (sub : String) (embeds : ExprEmbeds) : MetaM Html := do let embeds ← embeds.mapM fun (s, h) => return (s, <InteractiveCode fmt={← Widget.ppExprTagged h} />) return ( <PenroseDiagram embeds={embeds} dsl={include_str ".."/".."/".."/"widget"/"src"/"penrose"/"commutative.dsl"} sty...
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Presentation.Expr", "Mathlib.CategoryTheory.Category.Basic" ]
Mathlib/Tactic/Widget/CommDiag.lean
mkCommDiag
Construct a commutative diagram from a Penrose `sub`stance program and expressions `embeds` to display as labels in the diagram.
subTriangle := include_str ".."/".."/".."/"widget"/"src"/"penrose"/"triangle.sub"
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Presentation.Expr", "Mathlib.CategoryTheory.Category.Basic" ]
Mathlib/Tactic/Widget/CommDiag.lean
subTriangle
Triangle with `homs = [f,g,h]` and `objs = [A,B,C]` ``` A f B h g C ```
commTriangleM? (e : Expr) : MetaM (Option Html) := do let e ← instantiateMVars e let some (_, lhs, rhs) := e.eq? | return none if let some (f, g) := homComp? lhs then let some (A, C) := homType? (← inferType rhs) | return none let some (_, B) := homType? (← inferType f) | return none return some <| ← ...
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Presentation.Expr", "Mathlib.CategoryTheory.Category.Basic" ]
Mathlib/Tactic/Widget/CommDiag.lean
commTriangleM
Given a commutative triangle `f ≫ g = h` or `e ≡ h = f ≫ g`, return a triangle diagram. Otherwise `none`.
@[expr_presenter] commutativeTrianglePresenter : ExprPresenter where userName := "Commutative triangle" layoutKind := .block present type := do if let some d ← commTriangleM? type then return d throwError "Couldn't find a commutative triangle." /-! ## Commutative squares -/
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Presentation.Expr", "Mathlib.CategoryTheory.Category.Basic" ]
Mathlib/Tactic/Widget/CommDiag.lean
commutativeTrianglePresenter
Presenter for a commutative triangle
subSquare := include_str ".."/".."/".."/"widget"/"src"/"penrose"/"square.sub"
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Presentation.Expr", "Mathlib.CategoryTheory.Category.Basic" ]
Mathlib/Tactic/Widget/CommDiag.lean
subSquare
Square with `homs = [f,g,h,i]` and `objs = [A,B,C,D]` ``` A f B i g D h C ```
commSquareM? (e : Expr) : MetaM (Option Html) := do let e ← instantiateMVars e let some (_, lhs, rhs) := e.eq? | return none let some (f, g) := homComp? lhs | return none let some (i, h) := homComp? rhs | return none let some (A, B) := homType? (← inferType f) | return none let some (D, C) := homType? (← in...
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Presentation.Expr", "Mathlib.CategoryTheory.Category.Basic" ]
Mathlib/Tactic/Widget/CommDiag.lean
commSquareM
Given a commutative square `f ≫ g = i ≫ h`, return a square diagram. Otherwise `none`.
@[expr_presenter] commutativeSquarePresenter : ExprPresenter where userName := "Commutative square" layoutKind := .block present type := do if let some d ← commSquareM? type then return d throwError "Couldn't find a commutative square."
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Presentation.Expr", "Mathlib.CategoryTheory.Category.Basic" ]
Mathlib/Tactic/Widget/CommDiag.lean
commutativeSquarePresenter
Presenter for a commutative square
@[nolint unusedArguments] makeCongrMString (pos : Array Lean.SubExpr.GoalsLocation) (goalType : Expr) (_ : SelectInsertParams) : MetaM (String × String × Option (String.Pos × String.Pos)) := do let subexprPos := getGoalLocations pos unless goalType.isAppOf ``Eq || goalType.isAppOf ``Iff do throwError "The g...
def
Tactic
[ "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Tactic.CongrM", "Batteries.Lean.Position" ]
Mathlib/Tactic/Widget/CongrM.lean
makeCongrMString
Return the link text and inserted text above and below of the congrm widget.
@[server_rpc_method] CongrMSelectionPanel.rpc := mkSelectionPanelRPC makeCongrMString "Use shift-click to select sub-expressions in the goal that should become holes in congrm." "CongrM 🔍"
def
Tactic
[ "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Tactic.CongrM", "Batteries.Lean.Position" ]
Mathlib/Tactic/Widget/CongrM.lean
CongrMSelectionPanel.rpc
Rpc function for the congrm widget.
@[widget_module] CongrMSelectionPanel : Component SelectInsertParams := mk_rpc_widget% CongrMSelectionPanel.rpc open scoped Json in
def
Tactic
[ "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Tactic.CongrM", "Batteries.Lean.Position" ]
Mathlib/Tactic/Widget/CongrM.lean
CongrMSelectionPanel
The congrm widget.
private SolveReturn where expr : Expr val? : Option String listRest : List Nat
structure
Tactic
[ "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Data.String.Defs", "Batteries.Tactic.Lint", "Batteries.Lean.Position" ]
Mathlib/Tactic/Widget/Conv.lean
SolveReturn
null
private solveLevel (expr : Expr) (path : List Nat) : MetaM SolveReturn := match expr with | Expr.app _ _ => do let mut descExp := expr let mut count := 0 let mut explicitList := [] while descExp.isApp do if (← Lean.Meta.inferType descExp.appFn!).bindingInfo!.isExplicit then explicitList ...
def
Tactic
[ "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Data.String.Defs", "Batteries.Tactic.Lint", "Batteries.Lean.Position" ]
Mathlib/Tactic/Widget/Conv.lean
solveLevel
null
@[nolint unusedArguments] insertEnter (locations : Array Lean.SubExpr.GoalsLocation) (goalType : Expr) (params : SelectInsertParams) : MetaM (String × String × Option (String.Pos × String.Pos)) := do let some pos := locations[0]? | throwError "You must select something." let (fvar, subexprPos) ← match pos with ...
def
Tactic
[ "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Data.String.Defs", "Batteries.Tactic.Lint", "Batteries.Lean.Position" ]
Mathlib/Tactic/Widget/Conv.lean
insertEnter
Return the link text and inserted text above and below of the conv widget.
@[server_rpc_method] ConvSelectionPanel.rpc := mkSelectionPanelRPC insertEnter "Use shift-click to select one sub-expression in the goal that you want to zoom on." "Conv 🔍" (onlyGoal := false) (onlyOne := true)
def
Tactic
[ "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Data.String.Defs", "Batteries.Tactic.Lint", "Batteries.Lean.Position" ]
Mathlib/Tactic/Widget/Conv.lean
ConvSelectionPanel.rpc
Rpc function for the conv widget.
@[widget_module] ConvSelectionPanel : Component SelectInsertParams := mk_rpc_widget% ConvSelectionPanel.rpc open scoped Json in
def
Tactic
[ "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Data.String.Defs", "Batteries.Tactic.Lint", "Batteries.Lean.Position" ]
Mathlib/Tactic/Widget/Conv.lean
ConvSelectionPanel
The conv widget.
@[nolint unusedArguments] makeGCongrString (pos : Array Lean.SubExpr.GoalsLocation) (goalType : Expr) (_ : SelectInsertParams) : MetaM (String × String × Option (String.Pos × String.Pos)) := do let subexprPos := getGoalLocations pos unless goalType.isAppOf ``LE.le || goalType.isAppOf ``LT.lt || goalType.isAppOf `In...
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Tactic.GCongr" ]
Mathlib/Tactic/Widget/GCongr.lean
makeGCongrString
Return the link text and inserted text above and below of the gcongr widget.
@[server_rpc_method] GCongrSelectionPanel.rpc := mkSelectionPanelRPC makeGCongrString "Use shift-click to select sub-expressions in the goal that should become holes in gcongr." "GCongr 🔍"
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Tactic.GCongr" ]
Mathlib/Tactic/Widget/GCongr.lean
GCongrSelectionPanel.rpc
Rpc function for the gcongr widget.
@[widget_module] GCongrSelectionPanel : Component SelectInsertParams := mk_rpc_widget% GCongrSelectionPanel.rpc open scoped Json in
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Tactic.GCongr" ]
Mathlib/Tactic/Widget/GCongr.lean
GCongrSelectionPanel
The gcongr widget.
unfoldProjDefaultInst? (e : Expr) : MetaM (Option Expr) := do let .const declName _ := e.getAppFn | return none let some { fromClass := true, ctorName, .. } ← getProjectionFnInfo? declName | return none let some (ConstantInfo.ctorInfo ci) := (← getEnv).find? ctorName | return none let defaults ← getDefaultInsta...
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.NthRewrite", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Lean.GoalsLocation", "Mathlib.Lean.Meta.KAbstractPositions" ]
Mathlib/Tactic/Widget/InteractiveUnfold.lean
unfoldProjDefaultInst
Unfold a class projection if the instance is tagged with `@[default_instance]`. This is used in the `unfold?` tactic in order to not show these unfolds to the user. Similar to `Lean.Meta.unfoldProjInst?`.
partial unfolds (e : Expr) : MetaM (Array Expr) := do let e' ← whnfCore e go e' (if e == e' then #[] else #[e']) where /-- Append the unfoldings of `e` to `acc`. Assume `e` is in `whnfCore` form. -/ go (e : Expr) (acc : Array Expr) : MetaM (Array Expr) := tryCatchRuntimeEx (withIncRecDepth do ...
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.NthRewrite", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Lean.GoalsLocation", "Mathlib.Lean.Meta.KAbstractPositions" ]
Mathlib/Tactic/Widget/InteractiveUnfold.lean
unfolds
Return the consecutive unfoldings of `e`.
isUserFriendly (e : Expr) : Bool := !e.foldConsts (init := false) (fun name => (· || name.isInternalDetail))
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.NthRewrite", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Lean.GoalsLocation", "Mathlib.Lean.Meta.KAbstractPositions" ]
Mathlib/Tactic/Widget/InteractiveUnfold.lean
isUserFriendly
Determine whether `e` contains no internal names.
filteredUnfolds (e : Expr) : MetaM (Array Expr) := return (← unfolds e).filter isUserFriendly
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.NthRewrite", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Lean.GoalsLocation", "Mathlib.Lean.Meta.KAbstractPositions" ]
Mathlib/Tactic/Widget/InteractiveUnfold.lean
filteredUnfolds
Return the consecutive unfoldings of `e` that are user friendly.
mkRewrite (occ : Option Nat) (symm : Bool) (e : Term) (loc : Option Name) : CoreM (TSyntax `tactic) := do let loc ← loc.mapM fun h => `(Lean.Parser.Tactic.location| at $(mkIdent h):term) let rule ← if symm then `(Parser.Tactic.rwRule| ← $e) else `(Parser.Tactic.rwRule| $e:term) match occ with | some n => `(...
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.NthRewrite", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Lean.GoalsLocation", "Mathlib.Lean.Meta.KAbstractPositions" ]
Mathlib/Tactic/Widget/InteractiveUnfold.lean
mkRewrite
Return syntax for the rewrite tactic `rw [e]`.
tacticPasteString (tac : TSyntax `tactic) (range : Lsp.Range) : CoreM String := do let column := range.start.character let indent := column return (← PrettyPrinter.ppTactic tac).pretty 100 indent column
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.NthRewrite", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Lean.GoalsLocation", "Mathlib.Lean.Meta.KAbstractPositions" ]
Mathlib/Tactic/Widget/InteractiveUnfold.lean
tacticPasteString
Given tactic syntax `tac` that we want to paste into the editor, return it as a string. This function respects the 100 character limit for long lines.
tacticSyntax (e eNew : Expr) (occ : Option Nat) (loc : Option Name) : MetaM (TSyntax `tactic) := do let e ← PrettyPrinter.delab e let eNew ← PrettyPrinter.delab eNew let fromRfl ← `(show $e = $eNew from $(mkIdent `rfl)) mkRewrite occ false fromRfl loc
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.NthRewrite", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Lean.GoalsLocation", "Mathlib.Lean.Meta.KAbstractPositions" ]
Mathlib/Tactic/Widget/InteractiveUnfold.lean
tacticSyntax
Return the tactic string that does the unfolding.
renderUnfolds (e : Expr) (occ : Option Nat) (loc : Option Name) (range : Lsp.Range) (doc : FileWorker.EditableDocument) : MetaM (Option Html) := do let results ← filteredUnfolds e if results.isEmpty then return none let core ← results.mapM fun unfold => do let tactic ← tacticSyntax e unfold occ loc ...
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.NthRewrite", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Lean.GoalsLocation", "Mathlib.Lean.Meta.KAbstractPositions" ]
Mathlib/Tactic/Widget/InteractiveUnfold.lean
renderUnfolds
Render the unfolds of `e` as given by `filteredUnfolds`, with buttons at each suggestion for pasting the rewrite tactic. Return `none` when there are no unfolds.
private rpc (props : SelectInsertParams) : RequestM (RequestTask Html) := RequestM.asTask do let doc ← RequestM.readDoc let some loc := props.selectedLocations.back? | return .text "unfold?: Please shift-click an expression." if loc.loc matches .hypValue .. then return .text "unfold? doesn't work on the...
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.NthRewrite", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Lean.GoalsLocation", "Mathlib.Lean.Meta.KAbstractPositions" ]
Mathlib/Tactic/Widget/InteractiveUnfold.lean
rpc
null
@[widget_module] UnfoldComponent : Component SelectInsertParams := mk_rpc_widget% InteractiveUnfold.rpc
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.NthRewrite", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Lean.GoalsLocation", "Mathlib.Lean.Meta.KAbstractPositions" ]
Mathlib/Tactic/Widget/InteractiveUnfold.lean
UnfoldComponent
The component called by the `unfold?` tactic
@[command_elab unfoldCommand] elabUnfoldCommand : Command.CommandElab := fun stx => withoutModifyingEnv <| Command.runTermElabM fun _ => Term.withDeclName `_unfold do let e ← Term.elabTerm stx[1] none Term.synthesizeSyntheticMVarsNoPostponing let e ← Term.levelMVarToParam (← instantiateMVars e) let e ← i...
def
Tactic
[ "Batteries.Lean.Position", "Mathlib.Tactic.NthRewrite", "Mathlib.Tactic.Widget.SelectPanelUtils", "Mathlib.Lean.GoalsLocation", "Mathlib.Lean.Meta.KAbstractPositions" ]
Mathlib/Tactic/Widget/InteractiveUnfold.lean
elabUnfoldCommand
Replace the selected expression with a definitional unfolding. - After each unfolding, we apply `whnfCore` to simplify the expression. - Explicit natural number expressions are evaluated. - Unfolds of class projections of instances marked with `@[default_instance]` are not shown. This is relevant for notational type ...
RewriteLemma where /-- The name of the lemma -/ name : Name /-- `symm` is `true` when rewriting from right to left -/ symm : Bool deriving BEq, Inhabited
structure
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
RewriteLemma
The structure for rewrite lemmas stored in the `RefinedDiscrTree`.
isMVarSwap (t s : Expr) : Bool := go t s {} |>.isSome where /-- The main loop of `isMVarSwap`. Returning `none` corresponds to a failure. -/ go (t s : Expr) (swaps : List (MVarId × MVarId)) : Option (List (MVarId × MVarId)) := do let isTricky e := e.hasExprMVar || e.hasLevelParam if isTricky t then guard ...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
isMVarSwap
Return `true` if `s` and `t` are equal up to changing the `MVarId`s.
@[inline] eqOrIff? (e : Expr) : Option (Expr × Expr) := match e.eq? with | some (_, lhs, rhs) => some (lhs, rhs) | none => e.iff?
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
eqOrIff
Extract the left and right-hand sides of an equality or iff statement.
addRewriteEntry (name : Name) (cinfo : ConstantInfo) : MetaM (List (RewriteLemma × List (Key × LazyEntry))) := do let .const head _ := cinfo.type.getForallBody.getAppFn | return [] unless head == ``Eq || head == ``Iff do return [] setMCtx {} -- recall that the metavariable context is not guaranteed to be empt...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
addRewriteEntry
Try adding the lemma to the `RefinedDiscrTree`.
addLocalRewriteEntry (decl : LocalDecl) : MetaM (List ((FVarId × Bool) × List (Key × LazyEntry))) := withReducible do let (_, _, eqn) ← forallMetaTelescope decl.type let some (lhs, rhs) := eqOrIff? eqn | return [] let result := ((decl.fvarId, false), ← initializeLazyEntryWithEta lhs) return [result, ((dec...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
addLocalRewriteEntry
Try adding the local hypothesis to the `RefinedDiscrTree`.
private ExtState := IO.Ref (Option (RefinedDiscrTree RewriteLemma)) private initialize ExtState.default : ExtState ← IO.mkRef none
abbrev
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
ExtState
null
getImportCandidates (e : Expr) : MetaM (Array (Array RewriteLemma)) := do let matchResult ← findImportMatches importedRewriteLemmasExt addRewriteEntry /- 5000 constants seems to be approximately the right number of tasks Too many means the tasks are too long. Too few means less cache can be reused and...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
getImportCandidates
Get all potential rewrite lemmas from the imported environment. By setting the `librarySearch.excludedModules` option, all lemmas from certain modules can be excluded.
getModuleCandidates (e : Expr) : MetaM (Array (Array RewriteLemma)) := do let moduleTreeRef ← createModuleTreeRef addRewriteEntry let matchResult ← findModuleMatches moduleTreeRef e return matchResult.flatten
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
getModuleCandidates
Get all potential rewrite lemmas from the current file. Exclude lemmas from modules in the `librarySearch.excludedModules` option.
Rewrite where /-- `symm` is `true` when rewriting from right to left -/ symm : Bool /-- The proof of the rewrite -/ proof : Expr /-- The replacement expression obtained from the rewrite -/ replacement : Expr /-- The size of the replacement when printed -/ stringLength : Nat /-- The extra goals created...
structure
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
Rewrite
A rewrite lemma that has been applied to an expression.
checkRewrite (thm e : Expr) (symm : Bool) : MetaM (Option Rewrite) := do withTraceNodeBefore `rw?? (return m! "rewriting {e} by {if symm then "← " else ""}{thm}") do let (mvars, binderInfos, eqn) ← forallMetaTelescope (← inferType thm) let some (lhs, rhs) := eqOrIff? eqn | return none let (lhs, rhs) := if s...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
checkRewrite
If `thm` can be used to rewrite `e`, return the rewrite.
checkAndSortRewriteLemmas (e : Expr) (rewrites : Array RewriteLemma) : MetaM (Array (Rewrite × Name)) := do let rewrites ← rewrites.filterMapM fun rw => tryCatchRuntimeEx do let thm ← mkConstWithFreshMVarLevels rw.name Option.map (·, rw.name) <$> checkRewrite thm e rw.symm fun _ => ...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
checkAndSortRewriteLemmas
Try to rewrite `e` with each of the rewrite lemmas, and sort the resulting rewrites.
getImportRewrites (e : Expr) : MetaM (Array (Array (Rewrite × Name))) := do (← getImportCandidates e).mapM (checkAndSortRewriteLemmas e)
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
getImportRewrites
Return all applicable library rewrites of `e`. Note that the result may contain duplicate rewrites. These can be removed with `filterRewrites`.
getModuleRewrites (e : Expr) : MetaM (Array (Array (Rewrite × Name))) := do (← getModuleCandidates e).mapM (checkAndSortRewriteLemmas e) /-! ### Rewriting by hypotheses -/
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
getModuleRewrites
Same as `getImportRewrites`, but for lemmas from the current file.
getHypotheses (except : Option FVarId) : MetaM (RefinedDiscrTree (FVarId × Bool)) := do let mut tree : PreDiscrTree (FVarId × Bool) := {} for decl in ← getLCtx do if !decl.isImplementationDetail && except.all (· != decl.fvarId) then for (val, entries) in ← addLocalRewriteEntry decl do for (key, en...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
getHypotheses
Construct the `RefinedDiscrTree` of all local hypotheses.
getHypothesisRewrites (e : Expr) (except : Option FVarId) : MetaM (Array (Array (Rewrite × FVarId))) := do let (candidates, _) ← (← getHypotheses except).getMatch e (unify := false) (matchRootStar := true) let candidates := (← MonadExcept.ofExcept candidates).flatten candidates.mapM <| Array.filterMapM fun (f...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
getHypothesisRewrites
Return all applicable hypothesis rewrites of `e`. Similar to `getImportRewrites`.
getBinderInfos (fn : Expr) (args : Array Expr) : MetaM (Array BinderInfo) := do let mut fnType ← inferType fn let mut result := Array.mkEmpty args.size let mut j := 0 for i in [:args.size] do unless fnType.isForall do fnType ← whnfD (fnType.instantiateRevRange j i args) j := i let .forallE _...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
getBinderInfos
Get the `BinderInfo`s for the arguments of `mkAppN fn args`.
partial isExplicitEq (t s : Expr) : MetaM Bool := do if t == s then return true unless t.getAppNumArgs == s.getAppNumArgs && t.getAppFn == s.getAppFn do return false let tArgs := t.getAppArgs let sArgs := s.getAppArgs let bis ← getBinderInfos t.getAppFn tArgs t.getAppNumArgs.allM fun i _ => if b...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
isExplicitEq
Determine whether the explicit parts of two expressions are equal, and the implicit parts are definitionally equal.
@[specialize] filterRewrites {α} (e : Expr) (rewrites : Array α) (replacement : α → Expr) (makesNewMVars : α → Bool) : MetaM (Array α) := withNewMCtxDepth do let mut filtered := #[] for rw in rewrites do if makesNewMVars rw then continue if ← isExplicitEq (replacement rw) e then trace[rw??] "dis...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
filterRewrites
Filter out duplicate rewrites, reflexive rewrites or rewrites that have metavariables in the replacement expression.
tacticSyntax (rw : Rewrite) (occ : Option Nat) (loc : Option Name) : MetaM (TSyntax `tactic) := withoutModifyingMCtx do for (mvarId, _) in rw.extraGoals do mvarId.setTag .anonymous let proof ← withOptions (pp.mvars.anonymous.set · false) (PrettyPrinter.delab rw.proof) mkRewrite occ rw.symm proof loc open Widg...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
tacticSyntax
Return the rewrite tactic that performs the rewrite.
RewriteInterface where /-- `symm` is `true` when rewriting from right to left -/ symm : Bool /-- The rewrite tactic string that performs the rewrite -/ tactic : String /-- The replacement expression obtained from the rewrite -/ replacement : Expr /-- The replacement expression obtained from the rewrite -/...
structure
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
RewriteInterface
The structure with all data necessary for rendering a rewrite suggestion
Rewrite.toInterface (rw : Rewrite) (name : Name ⊕ FVarId) (occ : Option Nat) (loc : Option Name) (range : Lsp.Range) : MetaM RewriteInterface := do let tactic ← tacticSyntax rw occ loc let tactic ← tacticPasteString tactic range let replacementString := Format.pretty (← ppExpr rw.replacement) let mut extraG...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
Rewrite.toInterface
Construct the `RewriteInterface` from a `Rewrite`.
Kind where /-- A rewrite with a local hypothesis -/ | hypothesis /-- A rewrite with a lemma from the current file -/ | fromFile /-- A rewrite with a lemma from an imported file -/ | fromCache
inductive
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
Kind
The kind of rewrite
getRewriteInterfaces (e : Expr) (occ : Option Nat) (loc : Option Name) (except : Option FVarId) (range : Lsp.Range) : MetaM (Array (Array RewriteInterface × Kind) × Array (Array RewriteInterface × Kind)) := do let mut filtr := #[] let mut all := #[] for rewrites in ← getHypothesisRewrites e except do ...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
getRewriteInterfaces
Return the Interfaces for rewriting `e`, both filtered and unfiltered.
pattern {α} (type : Expr) (symm : Bool) (k : Expr → MetaM α) : MetaM α := do forallTelescope type fun _ e => do let some (lhs, rhs) := eqOrIff? e | throwError "Expected equation, not {indentExpr e}" k (if symm then rhs else lhs)
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
pattern
Render the matching side of the rewrite lemma. This is shown at the header of each section of rewrite results.
renderRewrites (e : Expr) (results : Array (Array RewriteInterface × Kind)) (init : Option Html) (range : Lsp.Range) (doc : FileWorker.EditableDocument) (showNames : Bool) : MetaM Html := do let htmls ← results.filterMapM (renderSection showNames) let htmls := match init with | some html => #[html] ++ h...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
renderRewrites
Render the given rewrite results.
private rpc (props : SelectInsertParams) : RequestM (RequestTask Html) := RequestM.asTask do let doc ← RequestM.readDoc let some loc := props.selectedLocations.back? | return .text "rw??: Please shift-click an expression." if loc.loc matches .hypValue .. then return .text "rw??: cannot rewrite in the va...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
rpc
null
@[widget_module] LibraryRewriteComponent : Component SelectInsertParams := mk_rpc_widget% LibraryRewrite.rpc
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
LibraryRewriteComponent
The component called by the `rw??` tactic
Rewrite.toMessageData (rw : Rewrite) (name : Name) : MetaM MessageData := do let extraGoals ← rw.extraGoals.filterMapM fun (mvarId, bi) => do if bi.isExplicit then return some m! "⊢ {← mvarId.getType}" return none let list := [m! "{rw.replacement}"] ++ extraGoals.toList ++ [m! "{name}"] ...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
Rewrite.toMessageData
`rw??` is an interactive tactic that suggests rewrites for any expression selected by the user. To use it, shift-click an expression in the goal or a hypothesis that you want to rewrite. Clicking on one of the rewrite suggestions will paste the relevant rewrite tactic into the editor. The rewrite suggestions are group...
SectionToMessageData (sec : Array (Rewrite × Name) × Bool) : MetaM (Option MessageData) := do let rewrites ← sec.1.toList.mapM fun (rw, name) => rw.toMessageData name let rewrites : MessageData := .group (.joinSep rewrites "\n") let some (rw, name) := sec.1[0]? | return none let head ← pattern (← getConstInfo n...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
SectionToMessageData
Represent a section of rewrites as `MessageData`.
@[command_elab rw??Command] elabrw??Command : Command.CommandElab := fun stx => withoutModifyingEnv <| Command.runTermElabM fun _ => do let e ← Term.elabTerm stx[2] none Term.synthesizeSyntheticMVarsNoPostponing let e ← Term.levelMVarToParam (← instantiateMVars e) let filter := stx[1].isNone let mut rewrite...
def
Tactic
[ "Mathlib.Lean.Meta.RefinedDiscrTree", "Mathlib.Tactic.Widget.InteractiveUnfold", "ProofWidgets.Component.FilterDetails" ]
Mathlib/Tactic/Widget/LibraryRewrite.lean
elabrw
`#rw?? e` gives all possible rewrites of `e`. It is a testing command for the `rw??` tactic -/ syntax (name := rw??Command) "#rw??" (&"all")? term : command open Elab /-- Elaborate a `#rw??` command.
SelectInsertParamsClass (α : Type) where /-- Cursor position in the file at which the widget is being displayed. -/ pos : α → Lsp.Position /-- The current tactic-mode goals. -/ goals : α → Array Widget.InteractiveGoal /-- Locations currently selected in the goal state. -/ selectedLocations : α → Array SubEx...
class
Tactic
[ "Mathlib.Init", "Lean.Widget.InteractiveGoal", "Lean.Elab.Deriving.Basic" ]
Mathlib/Tactic/Widget/SelectInsertParamsClass.lean
SelectInsertParamsClass
Structures providing parameters for a Select and insert widget.
private mkSelectInsertParamsInstance (declName : Name) : TermElabM Syntax.Command := `(command|instance : SelectInsertParamsClass (@$(mkCIdent declName)) := ⟨fun prop => prop.pos, fun prop => prop.goals, fun prop => prop.selectedLocations, fun prop => prop.replaceRange⟩)
def
Tactic
[ "Mathlib.Init", "Lean.Widget.InteractiveGoal", "Lean.Elab.Deriving.Basic" ]
Mathlib/Tactic/Widget/SelectInsertParamsClass.lean
mkSelectInsertParamsInstance
null
mkSelectInsertParamsInstanceHandler (declNames : Array Name) : CommandElabM Bool := do if (← declNames.allM isInductive) then for declName in declNames do elabCommand (← liftTermElabM do mkSelectInsertParamsInstance declName) return true else return false initialize registerDerivingHandler ``Selec...
def
Tactic
[ "Mathlib.Init", "Lean.Widget.InteractiveGoal", "Lean.Elab.Deriving.Basic" ]
Mathlib/Tactic/Widget/SelectInsertParamsClass.lean
mkSelectInsertParamsInstanceHandler
Handler deriving a `SelectInsertParamsClass` instance.
getGoalLocations (locations : Array GoalsLocation) : Array SubExpr.Pos := Id.run do let mut res := #[] for location in locations do if let .target pos := location.loc then res := res.push pos return res
def
Tactic
[ "Lean.Meta.ExprLens", "ProofWidgets.Component.MakeEditLink", "ProofWidgets.Component.OfRpcMethod -- needed in all files using this one.", "Mathlib.Tactic.Widget.SelectInsertParamsClass" ]
Mathlib/Tactic/Widget/SelectPanelUtils.lean
getGoalLocations
Given a `Array GoalsLocation` return the array of `SubExpr.Pos` for all locations in the targets of the relevant goals.
insertMetaVar (e : Expr) (pos : SubExpr.Pos) : MetaM Expr := replaceSubexpr (fun _ ↦ do mkFreshExprMVar none .synthetic) pos e
def
Tactic
[ "Lean.Meta.ExprLens", "ProofWidgets.Component.MakeEditLink", "ProofWidgets.Component.OfRpcMethod -- needed in all files using this one.", "Mathlib.Tactic.Widget.SelectInsertParamsClass" ]
Mathlib/Tactic/Widget/SelectPanelUtils.lean
insertMetaVar
Replace the sub-expression at the given position by a fresh meta-variable.
String.renameMetaVar (s : String) : String := match s.splitOn "?m." with | [] => "" | [s] => s | head::tail => head ++ "?_" ++ "?_".intercalate (tail.map fun s ↦ s.dropWhile Char.isDigit) open ProofWidgets
def
Tactic
[ "Lean.Meta.ExprLens", "ProofWidgets.Component.MakeEditLink", "ProofWidgets.Component.OfRpcMethod -- needed in all files using this one.", "Mathlib.Tactic.Widget.SelectInsertParamsClass" ]
Mathlib/Tactic/Widget/SelectPanelUtils.lean
String.renameMetaVar
Replace all meta-variable names by "?_".
SelectInsertParams where /-- Cursor position in the file at which the widget is being displayed. -/ pos : Lsp.Position /-- The current tactic-mode goals. -/ goals : Array Widget.InteractiveGoal /-- Locations currently selected in the goal state. -/ selectedLocations : Array SubExpr.GoalsLocation /-- The r...
structure
Tactic
[ "Lean.Meta.ExprLens", "ProofWidgets.Component.MakeEditLink", "ProofWidgets.Component.OfRpcMethod -- needed in all files using this one.", "Mathlib.Tactic.Widget.SelectInsertParamsClass" ]
Mathlib/Tactic/Widget/SelectPanelUtils.lean
SelectInsertParams
Structures providing parameters for a Select and insert widget.
mkSelectionPanelRPC {Params : Type} [SelectInsertParamsClass Params] (mkCmdStr : (pos : Array GoalsLocation) → (goalType : Expr) → Params → MetaM (String × String × Option (String.Pos × String.Pos))) (helpMsg : String) (title : String) (onlyGoal := true) (onlyOne := false) : (params : Params) → RequestM...
def
Tactic
[ "Lean.Meta.ExprLens", "ProofWidgets.Component.MakeEditLink", "ProofWidgets.Component.OfRpcMethod -- needed in all files using this one.", "Mathlib.Tactic.Widget.SelectInsertParamsClass" ]
Mathlib/Tactic/Widget/SelectPanelUtils.lean
mkSelectionPanelRPC
Helper function to create a widget allowing to select parts of the main goal and then display a link that will insert some tactic call. The main argument is `mkCmdStr` which is a function creating the link text and the tactic call text. The `helpMsg` argument is displayed when nothing is selected and `title` is used a...
AtomNode : Type where /-- The vertical position of the node in the string diagram. -/ vPos : ℕ /-- The horizontal position of the node in the string diagram, counting strings in domains. -/ hPosSrc : ℕ /-- The horizontal position of the node in the string diagram, counting strings in codomains. -/ hPosTar :...
structure
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Component.Panel.Basic", "ProofWidgets.Presentation.Expr", "ProofWidgets.Component.HtmlDisplay", "Mathlib.Tactic.CategoryTheory.Bicategory.Normalize", "Mathlib.Tactic.CategoryTheory.Monoidal.Normalize" ]
Mathlib/Tactic/Widget/StringDiagram.lean
AtomNode
Nodes for 2-morphisms in a string diagram.
IdNode : Type where /-- The vertical position of the node in the string diagram. -/ vPos : ℕ /-- The horizontal position of the node in the string diagram, counting strings in domains. -/ hPosSrc : ℕ /-- The horizontal position of the node in the string diagram, counting strings in codomains. -/ hPosTar : ℕ...
structure
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Component.Panel.Basic", "ProofWidgets.Presentation.Expr", "ProofWidgets.Component.HtmlDisplay", "Mathlib.Tactic.CategoryTheory.Bicategory.Normalize", "Mathlib.Tactic.CategoryTheory.Monoidal.Normalize" ]
Mathlib/Tactic/Widget/StringDiagram.lean
IdNode
Nodes for identity 2-morphisms in a string diagram.
Node : Type | atom : AtomNode → Node | id : IdNode → Node
inductive
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Component.Panel.Basic", "ProofWidgets.Presentation.Expr", "ProofWidgets.Component.HtmlDisplay", "Mathlib.Tactic.CategoryTheory.Bicategory.Normalize", "Mathlib.Tactic.CategoryTheory.Monoidal.Normalize" ]
Mathlib/Tactic/Widget/StringDiagram.lean
Node
Nodes in a string diagram.
Node.e : Node → Expr | Node.atom n => n.atom.e | Node.id n => n.id.e
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Component.Panel.Basic", "ProofWidgets.Presentation.Expr", "ProofWidgets.Component.HtmlDisplay", "Mathlib.Tactic.CategoryTheory.Bicategory.Normalize", "Mathlib.Tactic.CategoryTheory.Monoidal.Normalize" ]
Mathlib/Tactic/Widget/StringDiagram.lean
Node.e
The underlying expression of a node.
Node.srcList : Node → List (Node × Atom₁) | Node.atom n => n.atom.src.toList.map (fun f ↦ (.atom n, f)) | Node.id n => [(.id n, n.id)]
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Component.Panel.Basic", "ProofWidgets.Presentation.Expr", "ProofWidgets.Component.HtmlDisplay", "Mathlib.Tactic.CategoryTheory.Bicategory.Normalize", "Mathlib.Tactic.CategoryTheory.Monoidal.Normalize" ]
Mathlib/Tactic/Widget/StringDiagram.lean
Node.srcList
The domain of the 2-morphism associated with a node as a list (the first component is the node itself).
Node.tarList : Node → List (Node × Atom₁) | Node.atom n => n.atom.tgt.toList.map (fun f ↦ (.atom n, f)) | Node.id n => [(.id n, n.id)]
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Component.Panel.Basic", "ProofWidgets.Presentation.Expr", "ProofWidgets.Component.HtmlDisplay", "Mathlib.Tactic.CategoryTheory.Bicategory.Normalize", "Mathlib.Tactic.CategoryTheory.Monoidal.Normalize" ]
Mathlib/Tactic/Widget/StringDiagram.lean
Node.tarList
The codomain of the 2-morphism associated with a node as a list (the first component is the node itself).
Node.vPos : Node → ℕ | Node.atom n => n.vPos | Node.id n => n.vPos
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Component.Panel.Basic", "ProofWidgets.Presentation.Expr", "ProofWidgets.Component.HtmlDisplay", "Mathlib.Tactic.CategoryTheory.Bicategory.Normalize", "Mathlib.Tactic.CategoryTheory.Monoidal.Normalize" ]
Mathlib/Tactic/Widget/StringDiagram.lean
Node.vPos
The vertical position of a node in a string diagram.
Node.hPosSrc : Node → ℕ | Node.atom n => n.hPosSrc | Node.id n => n.hPosSrc
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Component.Panel.Basic", "ProofWidgets.Presentation.Expr", "ProofWidgets.Component.HtmlDisplay", "Mathlib.Tactic.CategoryTheory.Bicategory.Normalize", "Mathlib.Tactic.CategoryTheory.Monoidal.Normalize" ]
Mathlib/Tactic/Widget/StringDiagram.lean
Node.hPosSrc
The horizontal position of a node in a string diagram, counting strings in domains.
Node.hPosTar : Node → ℕ | Node.atom n => n.hPosTar | Node.id n => n.hPosTar
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Component.Panel.Basic", "ProofWidgets.Presentation.Expr", "ProofWidgets.Component.HtmlDisplay", "Mathlib.Tactic.CategoryTheory.Bicategory.Normalize", "Mathlib.Tactic.CategoryTheory.Monoidal.Normalize" ]
Mathlib/Tactic/Widget/StringDiagram.lean
Node.hPosTar
The horizontal position of a node in a string diagram, counting strings in codomains.
Strand : Type where /-- The horizontal position of the strand in the string diagram. -/ hPos : ℕ /-- The start point of the strand in the string diagram. -/ startPoint : Node /-- The end point of the strand in the string diagram. -/ endPoint : Node /-- The underlying expression of the strand. -/ atom₁ :...
structure
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Component.Panel.Basic", "ProofWidgets.Presentation.Expr", "ProofWidgets.Component.HtmlDisplay", "Mathlib.Tactic.CategoryTheory.Bicategory.Normalize", "Mathlib.Tactic.CategoryTheory.Monoidal.Normalize" ]
Mathlib/Tactic/Widget/StringDiagram.lean
Strand
Strings in a string diagram.
Strand.vPos (s : Strand) : ℕ := s.startPoint.vPos
def
Tactic
[ "ProofWidgets.Component.PenroseDiagram", "ProofWidgets.Component.Panel.Basic", "ProofWidgets.Presentation.Expr", "ProofWidgets.Component.HtmlDisplay", "Mathlib.Tactic.CategoryTheory.Bicategory.Normalize", "Mathlib.Tactic.CategoryTheory.Monoidal.Normalize" ]
Mathlib/Tactic/Widget/StringDiagram.lean
Strand.vPos
The vertical position of a strand in a string diagram.