-
Notifications
You must be signed in to change notification settings - Fork 299
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
feat(data/mv_polynomial): add partial derivatives #2298
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! This is looking very good!
src/data/mv_polynomial.lean
Outdated
@@ -195,6 +211,21 @@ finsupp.induction p | |||
(by have : M (C 0) := h_C 0; rwa [C_0] at this) | |||
(assume s a p hsp ha hp, h_add _ _ (this s a) hp) | |||
|
|||
theorem induction_on' {M : mv_polynomial σ α → Prop} (p : mv_polynomial σ α) : | |||
(∀ (u : σ →₀ ℕ) (a : α), M (monomial u a)) → | |||
(∀ (p q : mv_polynomial σ α), M p → M q → M (p + q)) → M p := |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Someone who understands induction better than me might want to advise on whether this needs an @[elab_as_eliminator]
tag. Note also [recursor 5]
on line 193 and see also https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/.5Brecursor.205.5D . Is [recursor 5]
deprecated? Does anyone know?
The linter seems to be complaining about |
This was fixed in #2291. Merging master into this branch should fix that. |
Thanks. How can that even happen? |
The linter is now complaining that |
Unfortunately, this would introduce a new
It's not obvious to me how to slice this proof up, but we probably should. |
Could you explain why you've used def pderivative (v : S) (p : mv_polynomial S R) : mv_polynomial S R :=
p.sum (λ A B, monomial (A - single v 1) (B * (A v))) might have been simpler. |
I'm not 100% sure to be honest. I think I tried that but lean complained about not having I'm gonna check that though. |
Proof slicing: I guess one could prove lemmas of the form "if v is not in the support of u then |
Scott -- natural number subtraction (which Shing used) is bad enough -- your proposal uses subtraction on an object which is not a ring (so subtraction is poorly behaved) and is not nat either (so there is no automation which can deal with it). There will be no lemmas to deal with it. Shing's approach constrains the bad subtraction to the simplest type on which it occurs so I think is better for formalising given what we have. |
Can I suggest a different approach. Have a look at this framework: /-- `pderivative v p` is the partial derivative of `p` with respect to `v` -/
def pderivative (v : S) (p : mv_polynomial S R) : mv_polynomial S R :=
p.sum (λ A B, monomial (A - single v 1) (B * (A v)))
-- TODO move earlier
@[simp]
lemma sum_monomial {A : Type*} [add_comm_monoid A]
{u : S →₀ ℕ} {r : R} {b : (S →₀ ℕ) → R → A} (w : b u 0 = 0) :
sum (monomial u r) b = b u r :=
sum_single_index w
@[simp]
lemma pderivative_monomial {v : S} {u : S →₀ ℕ} {a : R} :
pderivative v (monomial u a) = monomial (u - single v 1) (a * (u v)) :=
begin
simp [pderivative],
end
-- this one is not actually necessary, but good to check that everything is flowing in the right direction
lemma pderivative_monomial_single {a : R} {v : S} {n : ℕ} :
pderivative v (monomial (single v n) a) = monomial (single v (n-1)) (a * n) :=
begin
simp,
-- TODO add missing `single_sub` lemma earlier, and verify this proof then works by simp
sorry
end
-- Before we proceed, go edit `monomial_add` and `monomial_mul` above,
-- and reverse the direction of the equalities.
-- Nothing breaks, and everything gets easier here.
lemma pderivative_monomial_mul {v : S} {u u' : S →₀ ℕ} {r r' : R} :
pderivative v (monomial u r * monomial u' r') =
pderivative v (monomial u r) * monomial u' r' + monomial u r * pderivative v (monomial u' r') :=
begin
simp,
-- fails, but tells us the two preparatory lemmas we need
end
lemma foo_prep {v : S} {u u' : S →₀ ℕ} (h : u v ≠ 0) :
u - single v 1 + u' = u + u' - single v 1 :=
sorry
@[simp]
lemma foo {v : S} {u u' : S →₀ ℕ} {r r' : R} :
monomial (u - single v 1 + u') (r * (u v) * r') =
monomial (u + u' - single v 1) (r * (u v) * r') :=
by sorry -- prove `by_cases u v = 0`
lemma bar_prep {v : S} {u u' : S →₀ ℕ} (h : u' v ≠ 0) :
u + (u' - single v 1) = u + u' - single v 1 :=
sorry
@[simp]
lemma bar {v : S} {u u' : S →₀ ℕ} {r r' : R} :
monomial (u + (u' - single v 1)) (r * (r' * (u' v))) =
monomial (u + u' - single v 1) (r * (r' * (u' v))) :=
by sorry -- prove `by_cases u' v = 0`
lemma pderivative_monomial_mul_take_2 {v : S} {u u' : S →₀ ℕ} {r r' : R} :
pderivative v (monomial u r * monomial u' r') =
pderivative v (monomial u r) * monomial u' r' + monomial u r * pderivative v (monomial u' r') :=
begin
simp,
congr,
ring,
end |
I agree |
|
I've had a look at what you've put there and filled in the proofs on my local copy, and it does seem to be much shorter than what I had, especially for
Upon further investigation, As a side note, |
Sounds great! Looking forward to seeing the update. Did you get |
I think so? I just derived that lemma foo_prep {v : S} {u u' : S →₀ ℕ} (h : u v ≠ 0) :
u - single v 1 + u' = u + u' - single v 1 :=
begin
ext f,
rw [add_apply, nat_sub_apply, nat_sub_apply, add_apply],
by_cases h : v = f,
{ rw [←h, single_eq_same], cases (u v), {contradiction},
rw nat.succ_sub_one, rw nat.succ_add, rw nat.succ_sub_one,
},
rw single_eq_of_ne h, simp
end Also if I'm to go ahead with this, I'd need to either rename |
|
Sorry, I didn't see your comment at the time. I just labelled it |
Also, would something like lemma pderivative_eq_zero_of_not_mem_vars {v : S} {f : mv_polynomial S R} (h : v ∉ f.vars) :
pderivative v f = 0 := sorry be nice to have? I managed to prove it in the case when |
Yes, that seems like a useful lemma to me. |
Yes, that's always painful... I don't know how to fix this off the top of my head. |
Can you just rewrite the polynomial |
To do this, you'll need to write a wrapper around |
There is a lemma |
I've taken a look at |
Co-Authored-By: Bryan Gin-ge Chen <bryangingechen@gmail.com>
|
I've tidied up the I'll try to write a |
Presumably you'll see this on zulip, but just in case: https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/pderivative |
…ty#2298) * feat(data/mv_polynomial): add partial derivatives * Added suggestions from PR. * trying to placate simp linter * Updated implementation of `pderivative` * formatting suggestions from Bryan Co-Authored-By: Bryan Gin-ge Chen <bryangingechen@gmail.com> * Suggestions from review. * rearrange aux lemmas Co-authored-by: Kevin Buzzard <k.buzzard@imperial.ac.uk> Co-authored-by: Scott Morrison <scott@tqft.net> Co-authored-by: Bryan Gin-ge Chen <bryangingechen@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@anu.edu.au> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…ty#2298) * feat(data/mv_polynomial): add partial derivatives * Added suggestions from PR. * trying to placate simp linter * Updated implementation of `pderivative` * formatting suggestions from Bryan Co-Authored-By: Bryan Gin-ge Chen <bryangingechen@gmail.com> * Suggestions from review. * rearrange aux lemmas Co-authored-by: Kevin Buzzard <k.buzzard@imperial.ac.uk> Co-authored-by: Scott Morrison <scott@tqft.net> Co-authored-by: Bryan Gin-ge Chen <bryangingechen@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@anu.edu.au> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…ty#2298) * feat(data/mv_polynomial): add partial derivatives * Added suggestions from PR. * trying to placate simp linter * Updated implementation of `pderivative` * formatting suggestions from Bryan Co-Authored-By: Bryan Gin-ge Chen <bryangingechen@gmail.com> * Suggestions from review. * rearrange aux lemmas Co-authored-by: Kevin Buzzard <k.buzzard@imperial.ac.uk> Co-authored-by: Scott Morrison <scott@tqft.net> Co-authored-by: Bryan Gin-ge Chen <bryangingechen@gmail.com> Co-authored-by: Scott Morrison <scott.morrison@anu.edu.au> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This adds partial derivatives to
data/mv_polynomial.lean
tactic.omega
is used in lines 1419 and 1420 to deal with arithmetic.data/polynomial.lean
. These lemmas may not all be necessary.