Zulip Chat Archive

Stream: general

Topic: coercions from polynomials


Kevin Buzzard (Jan 15 2020 at 16:27):

import data.mv_polynomial

open mv_polynomial

variables {k : Type*} [comm_ring k]

variable {n : Type*}

instance : has_coe_to_fun (mv_polynomial n k) :=
{ F := λ f, (n  k)  k,
  coe := λ f x, eval x f}

def 𝕍 (S : set (mv_polynomial n k)) : set (n  k) :=
-- {x : n → k | ∀ s ∈ S, s x = 0} -- doesn't work
-- {x : n → k | ∀ s ∈ S, s.eval x = 0} -- also doesn't work
{x : n  k |  s  S, eval x s = 0} -- works BUT VARIABLES IN STUPID ORDER!

Kevin Buzzard (Jan 15 2020 at 16:27):

If s is a polynomial and x is some assignment of the variables, I want to write s(x) to be the evaluation of the polynomial at the assignment of the variables. As does every mathematician. Why am I failing in the above?

Chris Hughes (Jan 15 2020 at 16:29):

eval x is a ring hom. That's why they're in the current order.

Kevin Buzzard (Jan 15 2020 at 16:30):

I don't understand why s.eval x = 0 fails. Is this an issue with the elaborator?

Johan Commelin (Jan 15 2020 at 17:52):

It's because of ∀ s ∈ S, I think.

Johan Commelin (Jan 15 2020 at 17:52):

If you would write ∀ f, f ∈ S → f.eval x = 0, I think it would work

Johan Commelin (Jan 15 2020 at 17:52):

But of course that is ugly

Johan Commelin (Jan 15 2020 at 17:53):

At least∀ f : mv_polynomial n k, f ∈ S → f.eval x = 0 should work

Kevin Buzzard (Jan 15 2020 at 18:33):

If you would write ∀ f, f ∈ S → f.eval x = 0, I think it would work

It doesn't work for me:

import data.mv_polynomial

open mv_polynomial

variables {k : Type*} [comm_ring k]

variable {n : Type*}

instance : has_coe_to_fun (mv_polynomial n k) :=
{ F := λ f, (n  k)  k,
  coe := λ f x, eval x f}

def 𝕍 (S : set (mv_polynomial n k)) : set (n  k) :=
-- {x : n → k | ∀ f, f ∈ S →  f x = 0} -- doesn't work
-- {x : n → k | ∀ f, f ∈ S → f.eval x = 0} -- also doesn't work
-- {x : n → k | ∀ f ∈ S, eval x f = 0} -- works BUT VARIABLES IN STUPID ORDER!
{x : n  k |  f, f  S  eval x f = 0} -- works BUT VARIABLES IN STUPID ORDER!

Reid Barton (Jan 15 2020 at 19:11):

oh yeah, inference with has_mem is super annoying

Mario Carneiro (Jan 15 2020 at 19:35):

When using "forall in" so that I can't write the type, I usually do something like this:

 {x : n  k |  f  S, (f : mv_polynomial n k).eval x = 0}

Johan Commelin (Jan 15 2020 at 19:36):

:thumbs_up: But it is still 3.1415 miles away from what mathematicians would write...

Johan Commelin (Jan 15 2020 at 19:42):

Are there examples of has_mem X Y in mathlib where X is not uniquely determined by Y? More precisely, can someone point me to two instances with types has_mem X_1 Y and has_mem X_2 Y such that X_1 differs from X_2?

Johan Commelin (Jan 15 2020 at 19:44):

(The dual case is clear: has_mem X (set X) and has_mem X (finset X), etc... all exist and are desirable.)

Reid Barton (Jan 15 2020 at 19:44):

X is an out_param so I think the case you suggest is not supposed to happen, but I never really understood whether out_param behaves like I would expect from Haskell

Reid Barton (Jan 15 2020 at 19:45):

Like here we definitely know that S : set (mv_polynomial n k), so there should be no problem inferring f : mv_polynomial n k and yet here we are

Johan Commelin (Jan 15 2020 at 19:46):

class has_mem' (Y : Type u) :=
(T : Type u)
(mem : T  Y  Prop)

Reid Barton (Jan 15 2020 at 19:46):

Also I think it would be better if ∈ was not overloaded at all, but only had type a -> set a -> Prop. The other cases you refer to could be handled using coercions.

Reid Barton (Jan 15 2020 at 19:47):

after all, a set S is exactly determined by its membership predicate so there is no loss of information this way

Johan Commelin (Jan 15 2020 at 19:49):

Also I think it would be better if ∈ was not overloaded at all, but only had type a -> set a -> Prop. The other cases you refer to could be handled using coercions.

But you run the risk that you have to explicitly tell Lean that you want to coerce...

Johan Commelin (Jan 15 2020 at 19:51):

Suppose I write ∀ f ∈ S, and S : finset X. Then Lean doesn't know the type of f yet. It will want to coerce S to set m_1?, but probably isn't smart enough to figure out that finset X only coerces to set X.

Reid Barton (Jan 15 2020 at 19:51):

oh this might be an issue, yes, but isn't that already broken?

Johan Commelin (Jan 15 2020 at 19:51):

So you end up writing ∀ f ∈ (S : set (mv_polynomial k n)), which is what we want to avoid.

Reid Barton (Jan 15 2020 at 19:52):

Anyways that's the same as the coercion to function issue which will hopefully be fixed in :four_leaf_clover:

Johan Commelin (Jan 15 2020 at 19:52):

Well, not if you allow multiple has_mems, I think

Johan Commelin (Jan 15 2020 at 19:52):

What do you think of my has_mem'?

Johan Commelin (Jan 15 2020 at 19:52):

It's probably broken as well... I dunno

Reid Barton (Jan 15 2020 at 19:53):

I think this encoding might get annoying in practice because Lean will naturally synthesize a type like (@set.has_mem a).T and then it will need to be reduced to a and it might not happen automatically in the right places

Reid Barton (Jan 15 2020 at 19:53):

Other than that, I think it would work

Johan Commelin (Jan 15 2020 at 19:54):

I think the problem with out_param was that it kicks in too late. My version would hopefully kick in at the right time

Patrick Massot (Jan 15 2020 at 19:56):

Do whatever you want as long as we don't loose sets being members of a filter.

Johan Commelin (Jan 15 2020 at 19:58):

Patrick, as long as nothing else can be member of a filter, that should be fine.

Johan Commelin (Jan 15 2020 at 19:59):

I wish we could register lookup tables in the parser and/or elaborator. Where you say: Oh, you've got ∀ f ∈ S? Figure out the type of S, and I'll look in the table what the type of f must be.

Johan Commelin (Jan 15 2020 at 20:00):

But that is a very ad hoc thing to do, I guess

Patrick Massot (Jan 15 2020 at 20:00):

Isn't it covered by unification hints?

Johan Commelin (Jan 15 2020 at 20:00):

Je ne sais pas

Patrick Massot (Jan 15 2020 at 20:03):

I don't know either, I'm only trolling.


Last updated: Dec 20 2023 at 11:08 UTC