Zulip Chat Archive
Stream: general
Topic: ancestor attribute
Chris Hughes (May 27 2020 at 12:20):
I'm trying to remove the unnecessary axioms for a group, ring etc. I'm seeing the ancestor attribute everywhere. What does it do, and how should I use it?
Mario Carneiro (May 27 2020 at 12:27):
it records the content of the extends
clause of an old_structure_cmd
for posterity
Kevin Buzzard (May 27 2020 at 12:28):
There is no more old structure command?
Johan Commelin (May 27 2020 at 12:28):
@Mario Carneiro By now, we could hack lean to do this for us, right?
Mario Carneiro (May 27 2020 at 12:28):
sure
Johan Commelin (May 27 2020 at 12:29):
Kevin Buzzard said:
There is no more old structure command?
There is... we're just logging what it does. For tactics.
Chris Hughes (May 27 2020 at 12:29):
If I'm changing the attributes, then for example monoid
will be an ancestor of comm_monoid
, but will have some extra axioms. So should ancestors that don't come from extends
be marked as ancestors?
Mario Carneiro (May 27 2020 at 12:29):
no
Chris Hughes (May 27 2020 at 12:30):
Will I break all the tactics?
Mario Carneiro (May 27 2020 at 12:30):
I don't think so
Kevin Buzzard (May 27 2020 at 12:30):
What we really want here is a way of inserting into the constructor a way of saying "I'm making a group and the user supplied only some of the fields, so make the rest using this construction" rather than redefining the type
Mario Carneiro (May 27 2020 at 12:31):
in any case, the main consumer is to_additive
and so you will know right away if it breaks
Mario Carneiro (May 27 2020 at 12:32):
this exists, it is called auto params
Kevin Buzzard (May 27 2020 at 12:33):
It doesn't exist
Kevin Buzzard (May 27 2020 at 12:34):
Let's take comm_group as an example
Kevin Buzzard (May 27 2020 at 12:35):
It probably extends group, but now you don't want to ask for mul_one and one_mul, however because it's extending group there's no way of retrofitting the autoparam
Kevin Buzzard (May 27 2020 at 12:36):
What we want is the ability not only to retrofit but also to ensure that when a hole command is used that we don't even show the autoparamed fields
Mario Carneiro (May 27 2020 at 12:37):
I know, I thought Chris already had a PR that does this
Mario Carneiro (May 27 2020 at 12:38):
you don't have to convince me that this is a good idea. Ideally this would get some lean support but as it is you just have to make a separate structure with an instance
Mario Carneiro (May 27 2020 at 12:41):
I will certainly grant that autoparams only solve some of the issues, and there are a lot more elaborate mechanisms I would like than what autoparams will give you. For example, defining a complete lattice where you only give the Sup, or only give the Inf, or only give the le
Mario Carneiro (May 27 2020 at 12:41):
or a group with left inverse and left unit, or right inverse and right unit
Mario Carneiro (May 27 2020 at 12:45):
It would be (relatively) easy to write a tactic that gets all these fields and has a store of constructor candidates containing a subset of all the fields and constructing the rest, and applies the first one where the input subset matches
Mario Carneiro (May 27 2020 at 12:46):
but since structure literals are implemented in C++ inextensibly it's tricky to do something like this
Mario Carneiro (May 27 2020 at 12:48):
and it would be nice as a library author to be able to provide all these constructor candidates
Mario Carneiro (May 27 2020 at 12:49):
right now they are these terrible mk'
theorems with 14 hypotheses and no syntax support
Kevin Buzzard (May 27 2020 at 12:51):
Right, it would be lovely to see the back of those. It's embarrassing showing undergraduates the official definition of a comm_group in Lean but at least syntax support would help
Mario Carneiro (May 27 2020 at 12:52):
Kevin Buzzard said:
It probably extends group, but now you don't want to ask for mul_one and one_mul, however because it's extending group there's no way of retrofitting the autoparam
Actually you can retrofit autoparams. You just add the field in the child structure a second time with the same name and a default definition
Kevin Buzzard (May 27 2020 at 12:53):
Ha! Does this really work? With old structure command on?
Mario Carneiro (May 27 2020 at 12:54):
yeah, I think it is used in monad
for example
Johan Commelin (May 27 2020 at 12:54):
@Chris Hughes Are you aware of this :up:
Mario Carneiro (May 27 2020 at 12:54):
class monad (m : Type u → Type v) extends applicative m, has_bind m : Type (max (u+1) v) :=
(map := λ α β f x, x >>= pure ∘ f)
(seq := λ α β f x, f >>= (<$> x))
Gabriel Ebner (May 27 2020 at 12:54):
These are default values, not auto params.
Mario Carneiro (May 27 2020 at 12:54):
both map
and seq
are coming from superclasses
Mario Carneiro (May 27 2020 at 12:55):
true, I think I mean opt param not auto param
Gabriel Ebner (May 27 2020 at 12:55):
And the fact that you can declare the default values afterwards requires workarounds which then cause lean#197. (EDIT: wrong issue number, thanks @Scott Morrison)
Mario Carneiro (May 27 2020 at 12:56):
Oh, I had no idea that was related
Mario Carneiro (May 27 2020 at 12:56):
have you diagnosed that issue?
Gabriel Ebner (May 27 2020 at 12:59):
Yes, it goes as follows: since default values may be declared at any point, we can't elaborate the fields from left to right. Instead, they are elaborated in some sort of dependency order: a field may only be elaborated when its type no longer contains any metavariables. In order to reduce the metavariables (this is crucial for new-style structures), projections are reduced. And this is why typeclass notation vanishes.
Scott Morrison (May 27 2020 at 13:01):
Oh, this sounds like it could also be related to lean#197.
Mario Carneiro (May 27 2020 at 13:02):
This is not at all how I expected opt params to be handled
Mario Carneiro (May 27 2020 at 13:03):
Why not eagerly remove auto_param
and opt_param
markers from the types first (and store them in an internal data structure)? They aren't supposed to be part of the type system proper, they are just annotations that live in expr because everything does
Gabriel Ebner (May 27 2020 at 13:04):
Oh, they are stored in an internal data structure. (Check out #print prefix monad.map
)
Gabriel Ebner (May 27 2020 at 13:05):
To be clear, default values for structures are stored as separate declations. auto params are not, and optional arguments of definitions are not either.
Mario Carneiro (May 27 2020 at 13:07):
Here's an idea: always elaborate elements of a structure in left to right order of use in the literal
Mario Carneiro (May 27 2020 at 13:08):
no this is not backward compatible, but it is simple and easy to reason about
Gabriel Ebner (May 27 2020 at 13:08):
When should default values and auto param fields be elaborated?
Mario Carneiro (May 27 2020 at 13:10):
default values don't need to be elaborated, auto params go at the end
Mario Carneiro (May 27 2020 at 13:11):
I don't think it would be a good idea to have an invisible auto param providing data that is later referenced by a user-provided dependent argument
Gabriel Ebner (May 27 2020 at 13:12):
default values don't need to be elaborated
I'm not sure if that's how it's implemented.
Mario Carneiro (May 27 2020 at 13:13):
I mean you already have an elaborated expr corresponding to the default value. You just need to substitute the values of the other fields in it
Mario Carneiro (May 27 2020 at 13:14):
but it can be used by later fields, so its effective elaboration order would be just before first use in a dependent arg
Gabriel Ebner (May 27 2020 at 13:15):
I had something like this implemented already (elaborating fields left-to-right), and it choked on default arguments in monad
. Let me see again what's going wrong.
Mario Carneiro (May 27 2020 at 13:16):
In particular that means that if you have a monad instance with map_comp
and map := x >>= pure ∘ f
then you can't write map_comp := ...
before pure := ...
and bind := ...
unless you have also provided map := ...
Kevin Buzzard (May 27 2020 at 13:31):
Mario Carneiro said:
true, I think I mean opt param not auto param
in which case, so did I
Gabriel Ebner (May 27 2020 at 15:15):
Last updated: Dec 20 2023 at 11:08 UTC