Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: analysis delaborator for
LinearIndependent
(#8602)
This is an experimental delaborator that works by analyzing the expression and tagging it with `pp.analysis`-style hints. This causes pretty printing `LinearIndependent` like `LinearIndependent K fun (b : ↑s) ↦ ↑b` rather than `LinearIndependent K fun b ↦ ↑b` and `LinearIndependent (ι := { x // x ∈ s }) K Subtype.val` rather than `LinearIndependent K Subtype.val`. Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
- Loading branch information
1 parent
84c26b2
commit c26fbb1
Showing
5 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/- | ||
Copyright (c) 2023 Kyle Miller. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Kyle Miller | ||
-/ | ||
import Mathlib.Lean.Expr.Basic | ||
import Mathlib.Data.Set.Basic | ||
|
||
/-! | ||
# Additional Expr recognizers needing theory imports | ||
-/ | ||
|
||
namespace Lean.Expr | ||
|
||
/-- If `e` is a coercion of a set to a type, return the set. | ||
Succeeds either for `Set.Elem s` terms or `{x // x ∈ s}` subtype terms. -/ | ||
def coeTypeSet? (e : Expr) : Option Expr := do | ||
if e.isAppOfArity ``Set.Elem 2 then | ||
return e.appArg! | ||
else if e.isAppOfArity ``Subtype 2 then | ||
let .lam _ _ body _ := e.appArg! | failure | ||
guard <| body.isAppOfArity ``Membership.mem 5 | ||
let #[_, _, inst, .bvar 0, s] := body.getAppArgs | failure | ||
guard <| inst.isAppOfArity ``Set.instMembershipSet 1 | ||
return s | ||
else | ||
failure | ||
|
||
end Lean.Expr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Mathlib.LinearAlgebra.LinearIndependent | ||
|
||
set_option pp.unicode.fun true | ||
|
||
variable {K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] {s : Set V} {x : V} | ||
|
||
variable (h : LinearIndependent K (fun b => b : s → V)) in | ||
/-- info: h : LinearIndependent K fun (b : ↑s) ↦ ↑b -/ | ||
#guard_msgs in #check h | ||
|
||
variable (h : LinearIndependent K (Subtype.val : s → V)) in | ||
/-- info: h : LinearIndependent (ι := { x // x ∈ s }) K Subtype.val -/ | ||
#guard_msgs in #check h | ||
|
||
variable (h : LinearIndependent K (by exact Subtype.val : s → V)) in | ||
/-- info: h : LinearIndependent (ι := ↑s) K Subtype.val -/ | ||
#guard_msgs in #check h | ||
|
||
variable (h : LinearIndependent K (fun b => (fun b => b : s → V) b)) in | ||
/-- info: h : LinearIndependent K fun (b : ↑s) ↦ (fun b ↦ ↑b) b -/ | ||
#guard_msgs in #check h |