Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

WIP: coe_to_fun domain codomain #1838

Closed

Conversation

shlevy
Copy link

@shlevy shlevy commented Oct 1, 2017

Similar to #1837 , but for coe_to_fun. WIP as I work through remaining issues.

class has_coe_to_fun (a : Sort u) : Sort (max u (v+1)) :=
(F : a → Sort v) (coe : Π x, F x)
class has_coe_to_fun (a : Sort u) : Sort (max u (v+1) (w+1)) :=
(domain : a → Sort v) (codomain : Π {x}, domain x → Sort w) (coe : Π x, Π (m : domain x), codomain m)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue 1: I can't make domain and codomain implicit, despite them being inferrable much of the time, because then I can't nicely specify them when they aren't inferrable. Why can't we specify implicit fields?

@@ -488,7 +488,8 @@ meta def add_coinductive_predicate
let (bs, eqs) := compact_relation r.loc_args $ pd.locals.zip r.insts,
eqs ← eqs.mmap (λ⟨l, i⟩, do
sort u ← infer_type l.local_type,
return $ (const `eq [u] : expr) l.local_type i l),
let final : expr tt := (const `eq [u] : expr) l.local_type i l,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue 2: Despite the relevant has_coe_to_fun instance being found and in principle completely reducible, it's only with this type annotation that the type of this expression actually gets reduced. Why?

@@ -1,6 +1,7 @@
⇑f 0 1 : ℕ
f 0 1 : ℕ
⇑f 0 1 : ℕ
@coe_fn.{1 1} (Functor.{0} nat) (coe_functor_to_fn.{0} nat) f (@has_zero.zero.{0} nat nat.has_zero)
@coe_fn.{1 1 1} (Functor.{0} nat) (coe_functor_to_fn.{0} nat) f
(@has_zero.zero.{0} (@has_coe_to_fun.domain.{1 1 1} (Functor.{0} nat) (coe_functor_to_fn.{0} nat) f) nat.has_zero)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue 3: How can I tell the pretty printer to please reduce has_coe_to_fun.domain etc.?

@@ -21,6 +21,6 @@ local postfix `⁻¹` := equiv.inv
def equiv.trans (f : α ≃ β) (g : β ≃ γ) : α ≃ γ :=
⟨g ∘ f, f⁻¹ ∘ g⁻¹⟩

example (f : α ≃ β) := function.bijective f
example (f : α ≃ β) := function.bijective.{u+1 v+1} f
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue 4: Why can't lean infer these universes? Or can it, because see:
Issue 5: Why can't lean unify Π (m : has_coe_to_fun.domain f), has_coe_to_fun.codomain m with ?m_1 → ?m_2, when the domain and codomain functions are readily known to be constants and reduce in this context to α and β, respectively?

@fpvandoorn
Copy link
Contributor

I think #1402 is related to (at least) issue 5. Coercion resolution is not great right now, and more information is currently needed than (hopefully) in the future. Currently it's required that the type you are coercion from doesn't contain any metavariables, and that might include the universe metavariables u+1 and v+1 which are implicit in α ≃ β

@shlevy
Copy link
Author

shlevy commented Oct 2, 2017

@fpvandoorn Hmm, when I turn on implicit pretty-printing I get:

type mismatch at application
  @function.bijective ?m_1 ?m_2 ⇑f
term
  ⇑f
has type
  Π (m : @has_coe_to_fun.domain (α ≃ β) (@equiv.has_coe_to_fun α β) f),
    @has_coe_to_fun.codomain (α ≃ β) (@equiv.has_coe_to_fun α β) f m
but is expected to have type
  ?m_1 → ?m_2

which suggests to me that the coercion and typeclass has fully been resolved?

@shlevy
Copy link
Author

shlevy commented Oct 2, 2017

Anyway explicitly specifying alpha and beta and removing the universe levels works. Pretty annoying though.

@shlevy shlevy force-pushed the has_coe_to_fun-domain-codomain branch from ad19353 to 69e7ca3 Compare October 2, 2017 08:40
Copy link
Author

@shlevy shlevy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue 7: in u_eq_max_u_v.lean, the proof of semigroup_morphism_composition fails to go through, despite the coercion apparently being resolved:

u_eq_max_u_v.lean:49:6: error: simplify tactic failed to simplify
state:
α β γ δ : Type u,
s_f : semigroup.{u} α,
s_g : semigroup.{u} β,
t_f : semigroup.{u} γ,
t_g : semigroup.{u} δ,
f : semigroup_morphism.{u} s_f t_f,
g : semigroup_morphism.{u} s_g t_g,
x y : α × β
⊢ (f.map ((x * y).fst), g.map ((x * y).snd)) = (f.map (x.fst) * f.map (y.fst), g.map (x.snd) * g.map (y.snd))

@@ -21,6 +21,6 @@ local postfix `⁻¹` := equiv.inv
def equiv.trans (f : α ≃ β) (g : β ≃ γ) : α ≃ γ :=
⟨g ∘ f, f⁻¹ ∘ g⁻¹⟩

example (f : α ≃ β) := function.bijective f
example (f : α ≃ β) := @function.bijective α β f
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue 6: Why do I need to fill these in explicitly? If I don't I get an error that seems to be related to the lack of reduction of domain and codomain

@shlevy
Copy link
Author

shlevy commented Oct 2, 2017

Made a bit more progress. Still having issues, many of which seem to stem from this lack of reduction.

@fpvandoorn
Copy link
Contributor

implicit pretty-printing

set_option pp.implicit true doesn't give all implicit information in the term, only the implicit arguments. set_option pp.all true gives all the implicit information, and set_option pp.universes true shows just the universe variables (try autocompletion after set_option pp. to see the other options)

@leodemoura
Copy link
Member

I will not merge this PR. As pointed above, we have an open issue for coercion resolution. Moreover, the redundant information that this PR tries to remove is a workaround. I don't have time to discuss why the workaround is need nor help with the PR. Please see: https://github.com/leanprover/lean/blob/master/.github/CONTRIBUTING.md#opening-pull-requests

I will close the other PR related with coercion resolution.

@leodemoura leodemoura closed this Oct 6, 2017
@shlevy
Copy link
Author

shlevy commented Oct 6, 2017

Hi @leodemoura, what is the best way to determine if some feature is wanted or not? For reference, the other PR was discussed in the gitter chat before I opened it.

@leodemoura
Copy link
Member

Hi @leodemoura, what is the best way to determine if some feature is wanted or not?

The best way is to open an issue and describe your plan.
To be honest, right now, only new features that do not change any existing line of code and do not affect/modify any existing core component are welcome.

For reference, the other PR was discussed in the gitter chat before I opened it.

When I wrote wanted in the .md file above, I meant the "developers want it".
I don't go to gitter. I dislike synchronous forms of communication.

@shlevy
Copy link
Author

shlevy commented Oct 6, 2017

I see. While I have no strong attachment to this specific feature, and of course you're free to run your project however you like, I feel I should point out that the way this was handled and the policies you have make me much less inclined to contribute to lean or become an active member of the community, and in general I would expect this approach to stifle the growth and longer-term viability of the project. There are ways to decline contributions, and ensure your time is respected, without turning away new contributors.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants