Skip to content

Commit 033c753

Browse files
committed
1 parent 7b126fc commit 033c753

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

LeanTeXMathlib/Basic.lean

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ latex_pp_app_rules (const := Set.image)
3131
return ← f.protectRight funAppBP ++ X.brackets |>.mergeBP (lbp := .NonAssoc funAppBP) (rbp := .NonAssoc funAppBP)
3232
|>.maybeWithTooltip s!"image of \\({X.latex.1}\\) under \\({f.latex.1}\\)"
3333

34+
-- Use the type itself as the universe
35+
latex_pp_app_rules (const := Finset.univ)
36+
| _, #[ty, _] => latexPP ty
37+
3438
latex_pp_app_rules (const := Finset.prod)
3539
| _, #[_α, _β, _inst, s, f] => do
3640
let set ← withExtraSmallness 2 <| latexPP s
@@ -49,7 +53,80 @@ latex_pp_app_rules (const := Finset.sum)
4953
let psum := (← (LatexData.atomString "\\sum" |>.bigger 1).sub (s!"{name.toLatex} \\in " ++ set) |>.maybeWithTooltip "Finset.sum") ++ pbody
5054
return psum |>.resetBP (lbp := .Infinity) |>.mergeBP (rbp := .NonAssoc 65)
5155

56+
-- Suppress casts
57+
latex_pp_app_rules (const := Nat.cast)
58+
| _, #[_, _, n] => latexPP n
59+
latex_pp_app_rules (const := Int.cast)
60+
| _, #[_, _, n] => latexPP n
61+
5262
latex_pp_const_rule Rat := (LatexData.atomString "\\mathbb{Q}").maybeWithTooltip "Rat"
5363

5464
latex_pp_const_rule Real := (LatexData.atomString "\\mathbb{R}").maybeWithTooltip "Real"
5565
latex_pp_const_rule Real.pi := LatexData.atomString "\\pi" |>.maybeWithTooltip "real.pi"
66+
67+
latex_pp_app_rules (const := Real.sqrt)
68+
| _, #[x] => do
69+
let v ← latexPP x
70+
let (latex, bigness) := v.latex
71+
-- Note: using an atom, but subscripts are incompatible with the square root symbol.
72+
-- Assuming subscripts will never happen.
73+
return .Atom ("\\sqrt{" ++ latex ++ "}") bigness none none
74+
75+
macro "latex_pp_trig_rule" c:ident tex:str : command =>
76+
`(
77+
latex_pp_app_rules (const := $c)
78+
| _, #[x] => do
79+
let v ← latexPP x
80+
return LatexData.atomString $tex ++ " " ++ v.protect (funAppBP - 1)
81+
|>.mergeBP (lbp := .NonAssoc funAppBP) (rbp := .NonAssoc funAppBP)
82+
)
83+
84+
latex_pp_trig_rule Real.sin "\\sin"
85+
latex_pp_trig_rule Real.cos "\\cos"
86+
latex_pp_trig_rule Real.tan "\\tan"
87+
latex_pp_trig_rule Real.arcsin "\\sin^{-1}"
88+
latex_pp_trig_rule Real.arccos "\\cos^{-1}"
89+
latex_pp_trig_rule Real.arctan "\\tan^{-1}"
90+
91+
latex_pp_app_rules (const := Finset.Icc)
92+
| _, #[_, _, _, lo, hi] => do
93+
let lo ← latexPP lo
94+
let hi ← latexPP hi
95+
return "[" ++ lo ++ ", " ++ hi ++ "]" |>.resetBP .Infinity .Infinity
96+
latex_pp_app_rules (const := Finset.Ico)
97+
| _, #[_, _, _, lo, hi] => do
98+
let lo ← latexPP lo
99+
let hi ← latexPP hi
100+
return "[" ++ lo ++ ", " ++ hi ++ ")" |>.resetBP .Infinity .Infinity
101+
latex_pp_app_rules (const := Finset.Ioc)
102+
| _, #[_, _, _, lo, hi] => do
103+
let lo ← latexPP lo
104+
let hi ← latexPP hi
105+
return "(" ++ lo ++ ", " ++ hi ++ "]" |>.resetBP .Infinity .Infinity
106+
latex_pp_app_rules (const := Finset.Ioo)
107+
| _, #[_, _, _, lo, hi] => do
108+
let lo ← latexPP lo
109+
let hi ← latexPP hi
110+
return "(" ++ lo ++ ", " ++ hi ++ ")" |>.resetBP .Infinity .Infinity
111+
latex_pp_app_rules (const := Finset.Iic)
112+
| _, #[_, _, _, hi] => do
113+
let hi ← latexPP hi
114+
-- using infty is not technically correct. for example, ℕ would be starting from 0
115+
return "(-\\infty, " ++ hi ++ "]" |>.resetBP .Infinity .Infinity
116+
latex_pp_app_rules (const := Finset.Iio)
117+
| _, #[_, _, _, hi] => do
118+
let hi ← latexPP hi
119+
return "(-\\infty, " ++ hi ++ ")" |>.resetBP .Infinity .Infinity
120+
latex_pp_app_rules (const := Finset.Ici)
121+
| _, #[_, _, _, lo] => do
122+
let lo ← latexPP lo
123+
return "[" ++ lo ++ ", \\infty)" |>.resetBP .Infinity .Infinity
124+
latex_pp_app_rules (const := Finset.Ioi)
125+
| _, #[_, _, _, lo] => do
126+
let lo ← latexPP lo
127+
return "(" ++ lo ++ ", \\infty)" |>.resetBP .Infinity .Infinity
128+
129+
latex_pp_app_rules (const := Finset.range)
130+
| _, #[hi] => do
131+
let hi ← latexPP hi
132+
return "[0, " ++ hi ++ ")" |>.resetBP .Infinity .Infinity

test/basic.lean

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def f : Nat → Nat → Nat := λ x y => x + y
1111

1212
def g : Unit → Nat := λ _ => 22
1313

14+
section
1415
variable (b : Nat) (s : Finset Nat) (t : Nat → Finset Nat) (c : Nat → Real → Real) (x : Real)
1516

1617
/-- info: \sum_{x \in s}(x + 1) -/
@@ -56,3 +57,26 @@ latex_pp_app_rules (kind := any) (paramKinds := params)
5657
#texify s.sum (λ x => x + 1) * s.sum (λ x => 2 * x)
5758
#texify λ (c : Nat) => c * s.sum (λ x => (t x).sum (λ y => x * y))
5859
#texify s.sum id
60+
61+
#texify Real.arcsin (Real.cos 2)
62+
63+
end
64+
65+
-- https://github.com/ldct/LeanGT/blob/main/LeanGT/TexifyDemo.lean
66+
67+
example (a b c : ℝ)
68+
(ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (h : a*b*c = 1) :
69+
3 ≤ Real.sqrt ((a + b) / (a + 1)) + Real.sqrt ((b + c) / (b + 1)) + Real.sqrt ((c + a) / (c + 1)) := by
70+
texify
71+
sorry
72+
73+
example (n : ℕ) : ∑ i ∈ Finset.range n, i = n * (n - 1) / 2 := by
74+
texify
75+
sorry
76+
77+
theorem imo1966_p4 (n : ℕ) (x : ℝ)
78+
(hx : ∀ t : ℕ, ∀ k : ℤ, x ≠ k * Real.pi / 2^t) :
79+
∑ i ∈ Finset.range n, 1 / Real.sin (2^(i + 1) * x) =
80+
1 / Real.tan x - 1 / Real.tan (2^n * x) := by
81+
texify
82+
sorry

0 commit comments

Comments
 (0)