Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - fix: Fix Polynomial.repr #3442

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 18 additions & 4 deletions Mathlib/Data/Polynomial/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1221,10 +1221,10 @@ section repr
variable [Semiring R]

protected instance repr [Repr R] [DecidableEq R] : Repr R[X] :=
⟨fun p prec =>
⟨fun p _ =>
if p.support = ∅ then "0"
else
Repr.addAppParen
Lean.Format.paren
semorrison marked this conversation as resolved.
Show resolved Hide resolved
(Lean.Format.fill
(Lean.Format.joinSep
(List.map
Expand All @@ -1235,10 +1235,24 @@ protected instance repr [Repr R] [DecidableEq R] : Repr R[X] :=
if coeff p n = 1 then "X ^ " ++ Nat.repr n
else "C " ++ reprArg (coeff p n) ++ " * X ^ " ++ Nat.repr n)
(p.support.sort (· ≤ ·)))
(" +" ++ Lean.Format.line)))
prec⟩
(" +" ++ Lean.Format.line)))⟩
#align polynomial.has_repr Polynomial.repr

example : reprStr
(⟨⟨{}, Pi.single 0 0,
by intro; simp [Pi.single, Function.update_apply]⟩⟩ : ℕ[X]) =
"0" := by native_decide

example : reprStr
(⟨⟨{1}, Pi.single 1 37,
by intro; simp [Pi.single, Function.update_apply]⟩⟩ : ℕ[X]) =
"(C 37 * X)" := by native_decide

example : reprStr
(⟨⟨{0, 2}, Pi.single 0 57 + Pi.single 2 22,
by intro; simp [Pi.single, Function.update_apply]; tauto⟩⟩ : ℕ[X]) =
"(C 57 + C 22 * X ^ 2)" := by native_decide

end repr

end Polynomial