-
Notifications
You must be signed in to change notification settings - Fork 759
Experiment the addition of sealed/defined attributes #19029
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
Changes from all commits
6cb44b4
c248044
ccba976
7c379f1
8471db8
9e63d70
603a7f8
a21cd6a
aaa4c5a
d2411ee
aa4cada
3cebc64
3d16d75
a35abec
b4ae67e
2dda694
99f69d6
dc4ce6f
b23f8e8
afb1376
3076d12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
|
|
||
| - **Added:** | ||
| New attributes :attr:`sealed` and :attr:`defined` allow to change | ||
| the default opacity (now called sealing to prevent the confusion | ||
| with the notion of opacity implemented by the command :cmd:`Opaque`) | ||
| of a definition or theorem | ||
| (`#19029 <https://github.com/coq/coq/pull/19029>`_, | ||
| by Hugo Herbelin). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| let declare_definition ~poly name sigma body = | ||
| let cinfo = Declare.CInfo.make ~name ~typ:None () in | ||
| let cinfo = Declare.CInfo.make ~name ~typ:None ~opaque:(Some (Attributes.Defined Conv_oracle.transparent)) () in | ||
| let info = Declare.Info.make ~poly () in | ||
| Declare.declare_definition ~info ~cinfo ~opaque:false ~body sigma | ||
| Declare.declare_definition ~info ~cinfo ~body sigma |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,8 +142,11 @@ or :term:`constants <constant>` defined in the :term:`global environment` with t | |
| E[Γ] ⊢ c~\triangleright_δ~t | ||
|
|
||
| :term:`Delta-reduction <delta-reduction>` only unfolds :term:`constants <constant>` that are | ||
| marked :gdef:`transparent`. :gdef:`Opaque <opaque>` is the opposite of | ||
| transparent; :term:`delta-reduction` doesn't unfold opaque constants. | ||
| marked :gdef:`transparent`. A constant that is not transparent is | ||
| either :gdef:`sealed`, meaning that it is never unfolded, or | ||
| :gdef:`opaque` meaning that it is transparent for the purpose | ||
| of validating the correctness of proofs and types but non-unfoldable | ||
| for the purpose of tactics and unification. | ||
|
Comment on lines
+145
to
+149
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be described as one of three choices, not as a binary choice with one of the choices having an additional binary choice.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this paragraph should mention only the main binary choice. To think more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either, we want to have two separate notions: transparent vs opaque / defined vs sealed. Or we think that this is a continuum worth presenting as such. Then no need for the word
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| ι-reduction | ||
| ~~~~~~~~~~~ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,22 @@ | ||
| Definitions | ||
| =========== | ||
| Definitions and theorems | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, though the subtitle just above the Theorem command is "Assertions and proofs". Maybe make that title "Theorems and proofs"?? Always good to have clear relationships between main titles and subtitles that minimize the need to think. Off topic: the Type Cast section doesn't belong in this chapter.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Theorems and proofs": done. |
||
| ======================== | ||
|
|
||
| Definitions associate a specified term with a given name. The name can later | ||
| be replaced with its definition through :term:`δ-reduction`. Definitions can | ||
| be local (defined with :g:`let`) or global | ||
| (e.g. defined with :cmd:`Definition` and related forms such as :cmd:`Fixpoint` | ||
| and :cmd:`CoFixpoint`). | ||
|
|
||
| On its side, a theorem is a statement with a proof. One can view | ||
| the name of a theorem as a way to abbreviate the given proof, in the | ||
| same way as the name of a definition abbreviates a term. That is, in | ||
| the case of definitions (and related forms such as :cmd:`Fixpoint` or | ||
| :cmd:`CoFixpoint`), the term is the body of the definition and the | ||
| type is the type of the body. In the case of a theorem, lemma, | ||
| corollary, etc. the term is the proof and the type is the statement. | ||
|
|
||
| Moreover, definitions can be local (defined with :g:`let`) or global | ||
| (defined at top-level). | ||
|
|
||
| .. index:: let ... := ... (term) | ||
|
|
||
|
|
@@ -66,10 +83,7 @@ If a scope is :ref:`bound <LocalInterpretationRulesForNotations>` to | |
| Top-level definitions | ||
| --------------------- | ||
|
|
||
| Definitions extend the global environment by associating names to terms. | ||
| A definition can be seen as a way to give a meaning to a name or as a | ||
| way to abbreviate a term. In any case, the name can later be replaced at | ||
| any time by its definition. | ||
| Top-level definitions extend the global environment by associating names with terms. | ||
|
|
||
| The operation of unfolding a name into its definition is called | ||
| :term:`delta-reduction`. | ||
|
|
@@ -92,30 +106,27 @@ Section :ref:`typing-rules`. | |
| | {* @binder } : @type | ||
| reduce ::= Eval @red_expr in | ||
|
|
||
| These commands bind :n:`@term` to the name :n:`@ident` in the global environment, | ||
| provided that :n:`@term` is well-typed. They can take the :attr:`local` :term:`attribute`, | ||
| which makes the defined :n:`@ident` accessible only through their fully | ||
| qualified names, even if :cmd:`Import` or its variants has been used on the | ||
| current :cmd:`Module`. | ||
| This binds :n:`@term` to the name :n:`@ident` in the global environment, | ||
| provided that :n:`@term` is well-typed. | ||
|
|
||
| If :n:`@type` is specified, the command checks that the type of :n:`@term` | ||
| is definitionally equal to :n:`@type`. | ||
|
|
||
| If :n:`@binder` is specified, it distributes over :n:`@term` and :n:`@type` as if they had | ||
| respectively been :n:`fun {* @binder } => @term` and :n:`forall {* @binder }, @type`. | ||
|
|
||
| If :n:`@reduce` is present then :n:`@ident` is bound to the result of the specified | ||
| computation on :n:`@term`. | ||
|
|
||
| These commands also support the :attr:`universes(polymorphic)`, | ||
| :attr:`program` (see :ref:`program_definition`), :attr:`canonical`, | ||
| :attr:`bypass_check(universes)`, :attr:`bypass_check(guard)`, :attr:`deprecated`, | ||
| :attr:`warn` and :attr:`using` attributes. | ||
|
|
||
| If :n:`@term` is omitted, :n:`@type` is required and Rocq enters proof mode. | ||
| This can be used to define a term incrementally, in particular by relying on the :tacn:`refine` tactic. | ||
| In this case, the proof should be terminated with :cmd:`Defined` in order to define a :term:`constant` | ||
| for which the computational behavior is relevant. See :ref:`proof-editing-mode`. | ||
|
|
||
| The form :n:`Definition @ident : @type := @term` checks that the type of :n:`@term` | ||
| is definitionally equal to :n:`@type`, and registers :n:`@ident` as being of type | ||
| :n:`@type`, and bound to value :n:`@term`. | ||
| In this case, the proof should normally be terminated with :cmd:`Defined`. See :ref:`proof-editing-mode`. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe state when you would not want to terminate with
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the new attribute, the idea is that it should always be
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If "Qed" was good enough for Euclid, it's good enough for us. No doubt that ancient Greeks would use an abbreviated Latin phrase :-). Seriously though, users will continue to use Qed unless we force them to change. And I don't see any reason we'd want to do so.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but we are talking here about definitions and
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| The form :n:`Definition @ident {* @binder } : @type := @term` is equivalent to | ||
| :n:`Definition @ident : forall {* @binder }, @type := fun {* @binder } => @term`. | ||
| The attributes :attr:`local`, :attr:`universes(polymorphic)`, | ||
| :attr:`program` (see :ref:`program_definition`), :attr:`canonical`, | ||
| :attr:`bypass_check(universes)`, :attr:`bypass_check(guard)`, :attr:`deprecated`, | ||
| :attr:`warn` and :attr:`using` as well as the exclusive attributes :attr:`sealed`, | ||
| :attr:`opaque` and :attr:`transparent`. | ||
|
|
||
| .. seealso:: :cmd:`Opaque`, :cmd:`Transparent`, :tacn:`unfold`. | ||
|
|
||
|
|
@@ -128,10 +139,10 @@ Section :ref:`typing-rules`. | |
|
|
||
| .. _Assertions: | ||
|
|
||
| Assertions and proofs | ||
| --------------------- | ||
| Theorems and proofs | ||
| ------------------- | ||
|
|
||
| An assertion states a proposition (or a type) for which the proof (or an | ||
| Assertions, such as :cmd:`Theorem`s, state a proposition (or a type) for which the proof (or an | ||
| inhabitant of the type) is interactively built using :term:`tactics <tactic>`. | ||
| Assertions cause Rocq to enter :term:`proof mode` (see :ref:`proofhandling`). | ||
| Common tactics are described in the :ref:`writing-proofs` chapter. | ||
|
|
@@ -152,20 +163,19 @@ The basic assertion command is: | |
| | Property | ||
|
|
||
| After the statement is asserted, Rocq needs a proof. Once a proof of | ||
| :n:`@type` under the assumptions represented by :n:`@binder`\s is given and | ||
| validated, the proof is generalized into a proof of :n:`forall {* @binder }, @type` and | ||
| :n:`@type` is given, | ||
| the theorem is bound to the name :n:`@ident` in the global environment. | ||
|
|
||
| These commands accept the :attr:`program` attribute. See :ref:`program_lemma`. | ||
| If :n:`@binder` is specified, this behaves as if :n:`@type` had been | ||
| :n:`forall {* @binder }, @type` and the proof starts in the context :n:`{* @binder }`. | ||
|
|
||
| Forms using the :n:`with` clause are useful for theorems that are proved by simultaneous induction | ||
| over a mutually inductive assumption, or that assert mutually dependent | ||
| statements in some mutual coinductive type. It is equivalent to | ||
| over a mutually inductive assumption, or that assert mutually dependent coinductive | ||
| statements. It is equivalent to | ||
| :cmd:`Fixpoint` or :cmd:`CoFixpoint` but using tactics to build the proof of | ||
| the statements (or the :term:`body` of the specification, depending on the point of | ||
| view). The inductive or coinductive types on which the induction or | ||
| coinduction has to be done is assumed to be unambiguous and is guessed by | ||
| the system. | ||
| coinduction has to be done is guessed by the system. | ||
|
|
||
| Like in a :cmd:`Fixpoint` or :cmd:`CoFixpoint` definition, the induction hypotheses | ||
| have to be used on *structurally smaller* arguments (for a :cmd:`Fixpoint`) or | ||
|
|
@@ -175,8 +185,10 @@ The basic assertion command is: | |
| correct at some time of the interactive development of a proof, use the | ||
| command :cmd:`Guarded`. | ||
|
|
||
| This command accepts the :attr:`bypass_check(universes)`, | ||
| :attr:`bypass_check(guard)`, :attr:`deprecated`, :attr:`warn`, and :attr:`using` attributes. | ||
| The attributes :attr:`local`, :attr:`universes(polymorphic)`, | ||
| :attr:`program` (see :ref:`program_lemma`), | ||
| :attr:`bypass_check(universes)`, :attr:`bypass_check(guard)`, :attr:`deprecated`, | ||
| :attr:`warn` and :attr:`using` are accepted. | ||
|
|
||
| .. exn:: The term @term has type @type which should be Set, Prop or Type. | ||
| :undocumented: | ||
|
|
@@ -200,7 +212,14 @@ tactics (see :ref:`writing-proofs`). The user may also enter | |
| commands to manage the proof mode (see :ref:`proofhandling`). | ||
|
|
||
| When the proof is complete, use the :cmd:`Qed` command so the kernel verifies | ||
| the proof and adds it to the global environment. | ||
| the proof and adds it to the global environment. By default, proofs | ||
| that end with :cmd:`Qed` are sealed, that is that their content cannot | ||
| be unfolded (see :ref:`applyingconversionrules`), thus realizing | ||
| *proof irrelevance*, that is that only provability matters, | ||
| and not the exact proof. Proofs can be made unfoldable, as | ||
| definitions are, by using the :attr:`transparent` attribute or by ending | ||
| the proof with :cmd:`Defined` in place of :cmd:`Qed`. We | ||
| recommend using the attribute. | ||
|
|
||
| .. note:: | ||
|
|
||
|
|
@@ -213,13 +232,40 @@ the proof and adds it to the global environment. | |
| statements still to be proved. Nonetheless, this practice is discouraged | ||
| and may stop working in future versions. | ||
|
|
||
| #. Proofs ended by :cmd:`Qed` are declared :term:`opaque`. Their content cannot be | ||
| unfolded (see :ref:`applyingconversionrules`), thus | ||
| realizing some form of *proof-irrelevance*. | ||
| Proofs that end with :cmd:`Defined` can be unfolded. | ||
|
|
||
| #. :cmd:`Proof` is recommended but can currently be omitted. On the opposite | ||
| side, :cmd:`Qed` (or :cmd:`Defined`) is mandatory to validate a proof. | ||
|
|
||
| #. One can also use :cmd:`Admitted` in place of :cmd:`Qed` to turn the | ||
| current asserted statement into an axiom and exit proof mode. | ||
|
|
||
| Sealing, transparency and opacity | ||
| --------------------------------- | ||
|
|
||
| Definitions and theorems can be sealed, transparent or opaque. Sealed | ||
| means that the body of the definition or the proof of the theorem are | ||
| abstract and cannot be unfolded. Transparent means that it can be | ||
| freely unfolded. Opaque means that it is unfoldable for type-checking | ||
| but kept abstract for reduction (see | ||
| e.g. :tacn:`unfold`). Transparency and opacity can be changed at any | ||
| time using the commands :cmd:`Transparent` and :cmd:`Opaque`. On the | ||
| other side, a sealed constant cannot be changed later to transparent | ||
| or opaque, nor a transparent or opaque constant be changed to sealed. | ||
|
|
||
| By default, definitions not built by tactics are | ||
| transparent. Definitions built interactively and ended with | ||
| :n:`Defined` are transparent. Theorems built interactively and ended | ||
| with :n:`Qed` are sealed. In the other cases, one of the following | ||
| attribute is expected: | ||
|
|
||
| .. attr:: sealed | ||
|
|
||
| .. attr:: transparent | ||
|
|
||
| .. attr:: opaque | ||
|
|
||
| Note that these attributes can be added either before the declaration | ||
| (e.g. :n:`#[sealed] Definition @ident := @term`) or before the name of | ||
| the constant (e.g. :n:`Definition #[sealed] @ident := @term`). When | ||
| several constants are declared at once (using :n:`with`), the | ||
| attribute given before the declaration is used as the default for all | ||
| names not themselves prefixed by an attribute. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1507,13 +1507,13 @@ legacy_attr: [ | |
| sentence: [ ] (* productions defined below *) | ||
|
|
||
| fix_definition: [ | ||
| | REPLACE ident_decl binders_fixannot type_cstr OPT [ ":=" lconstr ] decl_notations | ||
| | WITH ident_decl binders_fixannot type_cstr OPT [ ":=" lconstr ] decl_notations | ||
| | REPLACE quoted_attributes ident_decl binders_fixannot type_cstr OPT [ ":=" lconstr ] decl_notations | ||
| | WITH quoted_attributes ident_decl binders_fixannot type_cstr OPT [ ":=" lconstr ] decl_notations | ||
|
Comment on lines
+1510
to
+1511
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| ] | ||
|
|
||
| cofix_definition: [ | ||
| | REPLACE ident_decl binders type_cstr OPT [ ":=" lconstr ] decl_notations | ||
| | WITH ident_decl binders type_cstr OPT [ ":=" lconstr ] decl_notations | ||
| | REPLACE quoted_attributes ident_decl binders type_cstr OPT [ ":=" lconstr ] decl_notations | ||
| | WITH quoted_attributes ident_decl binders type_cstr OPT [ ":=" lconstr ] decl_notations | ||
| ] | ||
|
Comment on lines
1509
to
1517
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These replacements are no-ops (as they are prior to your changes). You can drop both of these edits entirely.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, will do.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
|
||
| type_cstr: [ | ||
|
|
||
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.
Some of the wording was not idiomatic
Also "the confusion with the notion of opacity" doesn't tell you what the difference in notions is, so vague