aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--.gitlab-ci.yml4
-rw-r--r--Makefile.build6
-rw-r--r--Makefile.common4
-rw-r--r--Makefile.make2
-rw-r--r--checker/checkInductive.ml2
-rw-r--r--clib/cList.ml20
-rw-r--r--clib/cString.ml4
-rw-r--r--clib/cString.mli3
-rw-r--r--coqpp/coqpp_main.ml4
-rw-r--r--default.nix10
-rw-r--r--dev/bench/gitlab-bench.yml12
-rwxr-xr-xdev/bench/gitlab.sh28
-rwxr-xr-xdev/build/windows/makecoq_mingw.sh2
-rw-r--r--dev/ci/ci-common.sh72
-rw-r--r--dev/ci/docker/bionic_coq/Dockerfile4
-rw-r--r--dev/ci/user-overlays/08743-ejgallego-zarith.sh6
-rw-r--r--dev/ci/user-overlays/10390-SkySkimmer-uip.sh30
-rw-r--r--dev/ci/user-overlays/11566-ejgallego-exninfo+coercion.sh6
-rw-r--r--dev/ci/user-overlays/11604-persistent-arrays.sh18
-rw-r--r--dev/ci/user-overlays/11836-ejgallego-obligations+functional.sh18
-rw-r--r--dev/ci/user-overlays/11922-ppedrot-rm-local-reductionops.sh9
-rw-r--r--dev/ci/user-overlays/11948-proux01-hexadecimal.sh12
-rw-r--r--dev/ci/user-overlays/12218-proux01-numeral-notations-non-inductive.sh18
-rw-r--r--dev/ci/user-overlays/12267-gares-elpi-1.11.sh6
-rw-r--r--dev/ci/user-overlays/12372-ejgallego-proof+info.sh24
-rw-r--r--dev/ci/user-overlays/12449-SkySkimmer-minim-prop-toset.sh6
-rw-r--r--dev/ci/user-overlays/12505-ppedrot-factor-hint-flags.sh6
-rw-r--r--dev/ci/user-overlays/12523-term-notation-custom.sh6
-rw-r--r--dev/ci/user-overlays/12565-ppedrot-fix-tc-search-opacity.sh6
-rw-r--r--dev/ci/user-overlays/12599-ppedrot-rm-deprecated-refiner.sh6
-rw-r--r--dev/ci/user-overlays/12650-SkySkimmer-rebuild-record.sh6
-rw-r--r--dev/ci/user-overlays/12709-ppedrot-hint-pattern-out.sh6
-rw-r--r--dev/ci/user-overlays/12720-ppedrot-factor-class-hint-clenv.sh6
-rw-r--r--dev/ci/user-overlays/12756-jashug-dont-refresh-argument-names.sh9
-rw-r--r--dev/ci/user-overlays/12801-VincentSe-CyclicSet.sh8
-rw-r--r--dev/ci/user-overlays/12875-herbelin-master+about-print-all-arguments-names.sh6
-rw-r--r--dev/ci/user-overlays/12892-SkySkimmer-update-s-univs.sh9
-rw-r--r--dev/ci/user-overlays/12968-maximedenes-delay-frozen-evarconv.sh6
-rw-r--r--dev/ci/user-overlays/12977-ppedrot-static-hint-poly.sh9
-rw-r--r--dev/ci/user-overlays/13028-herbelin-master+fix-quotations-printing.sh6
-rw-r--r--dev/ci/user-overlays/13075-ppedrot-explicit-names-quotient.sh9
-rw-r--r--dev/ci/user-overlays/13128-SkySkimmer-noinstance.sh3
-rw-r--r--dev/ci/user-overlays/13139-ppedrot-clean-hint-constr.sh9
-rw-r--r--dev/ci/user-overlays/13166-herbelin-master+fixes13165-missing-impargs-defined-fields.sh6
-rw-r--r--dev/ci/user-overlays/8808-herbelin-master+support-binder+term-in-abbrev.sh6
-rw-r--r--dev/ci/user-overlays/8855-herbelin-master+more-search-options.sh9
-rw-r--r--dev/ci/user-overlays/README.md22
-rw-r--r--dev/doc/changes.md28
-rw-r--r--dev/doc/parsing.md6
-rw-r--r--dev/doc/shield-icon.pngbin2512 -> 8582 bytes
-rwxr-xr-xdev/tools/create_overlays.sh3
-rw-r--r--doc/changelog/01-kernel/12738-fix-sr-cumul-inds.rst5
-rw-r--r--doc/changelog/02-specification-language/10331-minim-prop-toset.rst5
-rw-r--r--doc/changelog/02-specification-language/12768-master+warn-non-underscore-catch-all-pattern-matching.rst7
-rw-r--r--doc/changelog/02-specification-language/13166-master+fixes13165-missing-impargs-defined-fields.rst5
-rw-r--r--doc/changelog/02-specification-language/13183-using-att.rst6
-rw-r--r--doc/changelog/03-notations/12099-master+constraining-terms-occurring-also-as-pattern-in-notations.rst4
-rw-r--r--doc/changelog/03-notations/12218-numeral-notations-non-inductive.rst19
-rw-r--r--doc/changelog/03-notations/12946-master+fix12908-part1-collision-lonely-notation-printing.rst6
-rw-r--r--doc/changelog/03-notations/12950-master+reorganization-notations-only-parsing-only-printing.rst10
-rw-r--r--doc/changelog/03-notations/13026-master+fix-printing-custom-no-level-8.2.rst7
-rw-r--r--doc/changelog/03-notations/13067-master+fix-display-parentheses-default-coqide.rst5
-rw-r--r--doc/changelog/03-notations/13092-master+fix-13078-no-binder-in-pattern-notation.rst5
-rw-r--r--doc/changelog/04-tactics/12648-zify-int63.rst3
-rw-r--r--doc/changelog/04-tactics/12816-master+fix12787-K-redex-injection-anomaly.rst6
-rw-r--r--doc/changelog/04-tactics/12847-master+inversion-works-with-eq-in-type.rst6
-rw-r--r--doc/changelog/05-tactic-language/13232-ltac2-if-then-else.rst5
-rw-r--r--doc/changelog/06-ssreflect/12857-changelog-for-12857.rst8
-rw-r--r--doc/changelog/07-commands-and-options/13139-clean-hint-constr.rst6
-rw-r--r--doc/changelog/07-commands-and-options/13255-master+fix13244-use-coercions-in-search.rst7
-rw-r--r--doc/changelog/08-tools/12754-master+fix-coqdoc-index-escaping.rst6
-rw-r--r--doc/changelog/08-tools/12772-fix-details.rst5
-rw-r--r--doc/changelog/08-tools/13063-fix-no-output-sync-make-file.rst6
-rw-r--r--doc/changelog/09-coqide/00000-title.rst2
-rw-r--r--doc/changelog/09-coqide/12874-show_proof_diffs.rst5
-rw-r--r--doc/changelog/09-coqide/13145-master+coqide-printing-goal-names-support.rst4
-rw-r--r--doc/changelog/11-infrastructure-and-dependencies/12864-fix-approve-output.rst5
-rw-r--r--doc/changelog/11-infrastructure-and-dependencies/12972-ocaml+4_11.rst4
-rw-r--r--doc/changelog/11-infrastructure-and-dependencies/13011-sphinx-3.rst5
-rw-r--r--doc/sphinx/_static/coqdoc.css4
-rw-r--r--doc/sphinx/_static/diffs-show-proof.pngbin0 -> 13641 bytes
-rw-r--r--doc/sphinx/addendum/extraction.rst112
-rw-r--r--doc/sphinx/addendum/generalized-rewriting.rst76
-rw-r--r--doc/sphinx/addendum/implicit-coercions.rst64
-rw-r--r--doc/sphinx/addendum/micromega.rst95
-rw-r--r--doc/sphinx/addendum/miscellaneous-extensions.rst6
-rw-r--r--doc/sphinx/addendum/nsatz.rst78
-rw-r--r--doc/sphinx/addendum/omega.rst6
-rw-r--r--doc/sphinx/addendum/program.rst134
-rw-r--r--doc/sphinx/addendum/ring.rst149
-rw-r--r--doc/sphinx/addendum/type-classes.rst215
-rw-r--r--doc/sphinx/addendum/universe-polymorphism.rst27
-rw-r--r--doc/sphinx/appendix/history-and-changes/index.rst6
-rw-r--r--doc/sphinx/changes.rst493
-rwxr-xr-xdoc/sphinx/conf.py2
-rw-r--r--doc/sphinx/history.rst34
-rw-r--r--doc/sphinx/introduction.rst30
-rw-r--r--doc/sphinx/language/core/assumptions.rst10
-rw-r--r--doc/sphinx/language/core/basic.rst20
-rw-r--r--doc/sphinx/language/core/coinductive.rst10
-rw-r--r--doc/sphinx/language/core/definitions.rst14
-rw-r--r--doc/sphinx/language/core/index.rst2
-rw-r--r--doc/sphinx/language/core/inductive.rst26
-rw-r--r--doc/sphinx/language/core/modules.rst8
-rw-r--r--doc/sphinx/language/core/primitive.rst28
-rw-r--r--doc/sphinx/language/core/records.rst23
-rw-r--r--doc/sphinx/language/core/sections.rst2
-rw-r--r--doc/sphinx/language/core/variants.rst1
-rw-r--r--doc/sphinx/language/extensions/arguments-command.rst9
-rw-r--r--doc/sphinx/language/extensions/canonical.rst4
-rw-r--r--doc/sphinx/language/extensions/evars.rst2
-rw-r--r--doc/sphinx/language/extensions/implicit-arguments.rst2
-rw-r--r--doc/sphinx/language/extensions/index.rst2
-rw-r--r--doc/sphinx/language/extensions/match.rst39
-rw-r--r--doc/sphinx/practical-tools/coq-commands.rst20
-rw-r--r--doc/sphinx/practical-tools/coqide.rst18
-rw-r--r--doc/sphinx/practical-tools/utilities.rst48
-rw-r--r--doc/sphinx/proof-engine/ltac.rst29
-rw-r--r--doc/sphinx/proof-engine/ltac2.rst90
-rw-r--r--doc/sphinx/proof-engine/proof-handling.rst890
-rw-r--r--doc/sphinx/proof-engine/ssreflect-proof-language.rst12
-rw-r--r--doc/sphinx/proof-engine/tactics.rst2121
-rw-r--r--doc/sphinx/proof-engine/vernacular-commands.rst38
-rw-r--r--doc/sphinx/proofs/automatic-tactics/auto.rst672
-rw-r--r--doc/sphinx/proofs/automatic-tactics/index.rst10
-rw-r--r--doc/sphinx/proofs/automatic-tactics/logic.rst294
-rw-r--r--doc/sphinx/proofs/creating-tactics/index.rst10
-rw-r--r--doc/sphinx/proofs/writing-proofs/index.rst11
-rw-r--r--doc/sphinx/proofs/writing-proofs/proof-mode.rst1037
-rw-r--r--doc/sphinx/proofs/writing-proofs/rewriting.rst857
-rw-r--r--doc/sphinx/user-extensions/proof-schemes.rst83
-rw-r--r--doc/sphinx/user-extensions/syntax-extensions.rst505
-rw-r--r--doc/sphinx/using/libraries/funind.rst94
-rw-r--r--doc/sphinx/using/libraries/index.rst6
-rw-r--r--doc/sphinx/using/libraries/writing.rst10
-rw-r--r--doc/sphinx/using/tools/coqdoc.rst6
-rw-r--r--doc/sphinx/using/tools/index.rst8
-rw-r--r--doc/stdlib/hidden-files2
-rw-r--r--doc/stdlib/index-list.html.template4
-rw-r--r--doc/tools/docgram/README.md2
-rw-r--r--doc/tools/docgram/common.edit_mlg743
-rw-r--r--doc/tools/docgram/doc_grammar.ml87
-rw-r--r--doc/tools/docgram/fullGrammar596
-rw-r--r--doc/tools/docgram/orderedGrammar229
-rw-r--r--engine/eConstr.ml14
-rw-r--r--engine/eConstr.mli1
-rw-r--r--engine/termops.ml18
-rw-r--r--engine/uState.ml6
-rw-r--r--engine/univMinim.ml11
-rw-r--r--gramlib/.merlin.in3
-rw-r--r--ide/.merlin.in10
-rw-r--r--ide/coqide/coq.ml8
-rw-r--r--ide/coqide/coq.mli5
-rw-r--r--ide/coqide/coqOps.ml22
-rw-r--r--ide/coqide/coqOps.mli2
-rw-r--r--ide/coqide/coqide.ml33
-rw-r--r--ide/coqide/coqide_ui.ml2
-rw-r--r--ide/coqide/fake_ide.ml30
-rw-r--r--ide/coqide/idetop.ml25
-rw-r--r--ide/coqide/protocol/interface.ml5
-rw-r--r--ide/coqide/protocol/serialize.ml5
-rw-r--r--ide/coqide/protocol/serialize.mli1
-rw-r--r--ide/coqide/protocol/xmlprotocol.ml49
-rw-r--r--ide/coqide/protocol/xmlprotocol.mli1
-rw-r--r--ide/coqide/wg_ProofView.ml28
-rw-r--r--interp/constrexpr.ml4
-rw-r--r--interp/constrexpr_ops.ml10
-rw-r--r--interp/constrextern.ml22
-rw-r--r--interp/constrintern.ml237
-rw-r--r--interp/constrintern.mli6
-rw-r--r--interp/implicit_quantifiers.ml57
-rw-r--r--interp/notation.ml655
-rw-r--r--interp/notation.mli66
-rw-r--r--interp/notation_ops.ml37
-rw-r--r--interp/numTok.mli30
-rw-r--r--interp/reserve.ml2
-rw-r--r--interp/smartlocate.ml38
-rw-r--r--interp/smartlocate.mli12
-rw-r--r--interp/stdarg.ml6
-rw-r--r--interp/stdarg.mli3
-rw-r--r--interp/syntax_def.ml6
-rw-r--r--interp/syntax_def.mli2
-rw-r--r--kernel/cClosure.ml21
-rw-r--r--kernel/cPrimitives.ml9
-rw-r--r--kernel/cPrimitives.mli1
-rw-r--r--kernel/constr.ml34
-rw-r--r--kernel/cooking.ml8
-rw-r--r--kernel/declareops.ml6
-rw-r--r--kernel/dune7
-rw-r--r--kernel/environ.ml78
-rw-r--r--kernel/environ.mli28
-rw-r--r--kernel/float64_31.ml35
-rw-r--r--kernel/float64_63.ml35
-rw-r--r--kernel/float64_common.ml (renamed from kernel/float64.ml)24
-rw-r--r--kernel/float64_common.mli95
-rw-r--r--kernel/indTyping.ml2
-rw-r--r--kernel/inductive.ml16
-rw-r--r--kernel/kernel.mllib1
-rw-r--r--kernel/mod_typing.ml10
-rw-r--r--kernel/names.ml269
-rw-r--r--kernel/names.mli209
-rw-r--r--kernel/nativecode.ml36
-rw-r--r--kernel/nativeconv.ml12
-rw-r--r--kernel/nativelambda.ml4
-rw-r--r--kernel/nativelib.ml21
-rw-r--r--kernel/nativevalues.ml13
-rw-r--r--kernel/nativevalues.mli4
-rw-r--r--kernel/parray.ml97
-rw-r--r--kernel/parray.mli1
-rw-r--r--kernel/primred.ml9
-rw-r--r--kernel/reduction.ml95
-rw-r--r--kernel/reduction.mli6
-rw-r--r--kernel/safe_typing.ml10
-rw-r--r--kernel/subtyping.ml4
-rw-r--r--kernel/typeops.ml2
-rw-r--r--kernel/typeops.mli2
-rw-r--r--kernel/uGraph.ml32
-rw-r--r--kernel/uGraph.mli12
-rw-r--r--kernel/univ.ml42
-rw-r--r--kernel/vars.ml3
-rw-r--r--kernel/vconv.ml8
-rw-r--r--kernel/vmbytecodes.ml6
-rw-r--r--kernel/vmbytegen.ml1
-rw-r--r--kernel/vmemitcodes.ml10
-rw-r--r--kernel/vmsymtable.ml4
-rw-r--r--kernel/vmvalues.ml9
-rw-r--r--kernel/vmvalues.mli1
-rw-r--r--lib/control.ml10
-rw-r--r--lib/explore.ml2
-rw-r--r--lib/flags.ml1
-rw-r--r--lib/flags.mli1
-rw-r--r--lib/genarg.mli2
-rw-r--r--lib/pp.ml20
-rw-r--r--lib/pp.mli4
-rw-r--r--lib/pp_diff.ml14
-rw-r--r--library/coqlib.ml4
-rw-r--r--library/globnames.ml6
-rw-r--r--library/lib.ml4
-rw-r--r--parsing/cLexer.ml8
-rw-r--r--parsing/cLexer.mli4
-rw-r--r--parsing/g_constr.mlg142
-rw-r--r--parsing/g_prim.mlg15
-rw-r--r--parsing/pcoq.ml16
-rw-r--r--parsing/pcoq.mli13
-rw-r--r--parsing/ppextend.ml4
-rw-r--r--parsing/ppextend.mli2
-rw-r--r--plugins/btauto/refl_btauto.ml2
-rw-r--r--plugins/cc/ccalgo.ml4
-rw-r--r--plugins/extraction/extraction.ml2
-rw-r--r--plugins/extraction/mlutil.ml2
-rw-r--r--plugins/extraction/scheme.ml2
-rw-r--r--plugins/extraction/table.ml2
-rw-r--r--plugins/firstorder/instances.ml2
-rw-r--r--plugins/firstorder/sequent.ml2
-rw-r--r--plugins/funind/functional_principles_proofs.ml2
-rw-r--r--plugins/funind/functional_principles_types.ml4
-rw-r--r--plugins/funind/g_indfun.mlg18
-rw-r--r--plugins/funind/gen_principle.ml13
-rw-r--r--plugins/funind/glob_term_to_relation.ml5
-rw-r--r--plugins/funind/glob_termops.ml6
-rw-r--r--plugins/funind/invfun.ml3
-rw-r--r--plugins/ltac/coretactics.mlg2
-rw-r--r--plugins/ltac/extraargs.mlg6
-rw-r--r--plugins/ltac/extratactics.mlg4
-rw-r--r--plugins/ltac/g_auto.mlg2
-rw-r--r--plugins/ltac/g_class.mlg12
-rw-r--r--plugins/ltac/g_ltac.mlg179
-rw-r--r--plugins/ltac/g_obligations.mlg2
-rw-r--r--plugins/ltac/g_rewrite.mlg23
-rw-r--r--plugins/ltac/g_tactic.mlg16
-rw-r--r--plugins/ltac/pltac.ml6
-rw-r--r--plugins/ltac/pltac.mli4
-rw-r--r--plugins/ltac/pptactic.ml10
-rw-r--r--plugins/ltac/pptactic.mli2
-rw-r--r--plugins/ltac/profile_ltac.ml4
-rw-r--r--plugins/ltac/rewrite.ml88
-rw-r--r--plugins/ltac/rewrite.mli2
-rw-r--r--plugins/ltac/taccoerce.ml37
-rw-r--r--plugins/ltac/tacentries.ml118
-rw-r--r--plugins/ltac/tacentries.mli3
-rw-r--r--plugins/ltac/tacintern.ml34
-rw-r--r--plugins/ltac/tacintern.mli3
-rw-r--r--plugins/ltac/tacinterp.ml51
-rw-r--r--plugins/ltac/tacinterp.mli9
-rw-r--r--plugins/ltac/tacsubst.ml2
-rw-r--r--plugins/micromega/coq_micromega.ml2228
-rw-r--r--plugins/micromega/zify.ml85
-rw-r--r--plugins/rtauto/refl_tauto.ml6
-rw-r--r--plugins/ssr/ssrcommon.ml2
-rw-r--r--plugins/ssr/ssrequality.ml2
-rw-r--r--plugins/ssr/ssrparser.mlg57
-rw-r--r--plugins/ssr/ssrprinters.ml9
-rw-r--r--plugins/ssr/ssrvernac.mlg18
-rw-r--r--plugins/ssr/ssrvernac.mli2
-rw-r--r--plugins/ssrmatching/ssrmatching.ml9
-rw-r--r--plugins/ssrsearch/g_search.mlg4
-rw-r--r--plugins/syntax/dune24
-rw-r--r--plugins/syntax/g_number_string.mlg110
-rw-r--r--plugins/syntax/g_numeral.mlg51
-rw-r--r--plugins/syntax/g_string.mlg25
-rw-r--r--plugins/syntax/int63_syntax.ml3
-rw-r--r--plugins/syntax/number.ml505
-rw-r--r--plugins/syntax/number.mli31
-rw-r--r--plugins/syntax/number_string_notation_plugin.mlpack3
-rw-r--r--plugins/syntax/numeral.ml217
-rw-r--r--plugins/syntax/numeral.mli19
-rw-r--r--plugins/syntax/numeral_notation_plugin.mlpack2
-rw-r--r--plugins/syntax/r_syntax.ml214
-rw-r--r--plugins/syntax/r_syntax_plugin.mlpack1
-rw-r--r--plugins/syntax/string_notation.ml27
-rw-r--r--plugins/syntax/string_notation.mli4
-rw-r--r--plugins/syntax/string_notation_plugin.mlpack2
-rw-r--r--pretyping/cases.ml53
-rw-r--r--pretyping/cases.mli3
-rw-r--r--pretyping/coercion.ml10
-rw-r--r--pretyping/coercionops.ml2
-rw-r--r--pretyping/constr_matching.ml16
-rw-r--r--pretyping/detyping.ml17
-rw-r--r--pretyping/evarconv.ml16
-rw-r--r--pretyping/evardefine.ml26
-rw-r--r--pretyping/evardefine.mli8
-rw-r--r--pretyping/glob_ops.ml9
-rw-r--r--pretyping/glob_term.ml2
-rw-r--r--pretyping/indrec.ml2
-rw-r--r--pretyping/keys.ml6
-rw-r--r--pretyping/patternops.ml6
-rw-r--r--pretyping/pretype_errors.ml2
-rw-r--r--pretyping/pretype_errors.mli4
-rw-r--r--pretyping/pretyping.ml55
-rw-r--r--pretyping/pretyping.mli2
-rw-r--r--pretyping/reductionops.ml14
-rw-r--r--pretyping/tacred.ml8
-rw-r--r--pretyping/typeclasses.ml6
-rw-r--r--pretyping/typeclasses.mli6
-rw-r--r--pretyping/typing.ml25
-rw-r--r--pretyping/unification.ml27
-rw-r--r--pretyping/vnorm.ml3
-rw-r--r--printing/ppconstr.ml76
-rw-r--r--printing/ppconstr.mli3
-rw-r--r--printing/printer.ml10
-rw-r--r--printing/printer.mli3
-rw-r--r--printing/proof_diffs.ml28
-rw-r--r--printing/proof_diffs.mli6
-rw-r--r--proofs/clenv.ml2
-rw-r--r--stm/asyncTaskQueue.ml5
-rw-r--r--stm/asyncTaskQueue.mli3
-rw-r--r--stm/partac.ml178
-rw-r--r--stm/partac.mli (renamed from plugins/syntax/r_syntax.mli)4
-rw-r--r--stm/stm.ml265
-rw-r--r--stm/stm.mli1
-rw-r--r--stm/stm.mllib1
-rw-r--r--stm/vernac_classifier.ml21
-rw-r--r--tactics/btermdn.ml2
-rw-r--r--tactics/cbn.ml8
-rw-r--r--tactics/class_tactics.ml3
-rw-r--r--tactics/elim.ml2
-rw-r--r--tactics/equality.ml2
-rw-r--r--tactics/hints.ml9
-rw-r--r--tactics/hints.mli13
-rw-r--r--tactics/tactics.ml2
-rw-r--r--tactics/term_dnet.ml4
-rw-r--r--test-suite/bugs/closed/bug_10972.v9
-rw-r--r--test-suite/bugs/closed/bug_12414.v13
-rw-r--r--test-suite/bugs/closed/bug_12623.v18
-rw-r--r--test-suite/bugs/closed/bug_12895.v20
-rw-r--r--test-suite/bugs/closed/bug_12947.v9
-rw-r--r--test-suite/bugs/closed/bug_12970.v4
-rw-r--r--test-suite/bugs/closed/bug_13078.v10
-rw-r--r--test-suite/bugs/closed/bug_13086.v11
-rw-r--r--test-suite/bugs/closed/bug_13117.v23
-rw-r--r--test-suite/bugs/closed/bug_13129.v58
-rw-r--r--test-suite/bugs/closed/bug_13131.v6
-rw-r--r--test-suite/bugs/closed/bug_13162.v7
-rw-r--r--test-suite/bugs/closed/bug_13169.v14
-rw-r--r--test-suite/bugs/closed/bug_13171.v10
-rw-r--r--test-suite/bugs/closed/bug_13178.v3
-rw-r--r--test-suite/bugs/closed/bug_13276.v9
-rw-r--r--test-suite/bugs/closed/bug_5197.v6
-rw-r--r--test-suite/bugs/opened/bug_3395.v232
-rw-r--r--test-suite/ide/proof-diffs.fake10
-rw-r--r--test-suite/micromega/int63.v24
-rw-r--r--test-suite/misc/quotation_token/src/quotation.mlg4
-rw-r--r--test-suite/output/Cases.out3
-rw-r--r--test-suite/output/Cases.v12
-rw-r--r--test-suite/output/DependentInductionErrors.out4
-rw-r--r--test-suite/output/DependentInductionErrors.v17
-rw-r--r--test-suite/output/ErrorLocation_13241_1.out3
-rw-r--r--test-suite/output/ErrorLocation_13241_1.v5
-rw-r--r--test-suite/output/ErrorLocation_13241_2.out3
-rw-r--r--test-suite/output/ErrorLocation_13241_2.v5
-rw-r--r--test-suite/output/Notations3.out17
-rw-r--r--test-suite/output/Notations4.out58
-rw-r--r--test-suite/output/Notations4.v105
-rw-r--r--test-suite/output/NumberNotations.out291
-rw-r--r--test-suite/output/NumberNotations.v579
-rw-r--r--test-suite/output/QArithSyntax.out90
-rw-r--r--test-suite/output/QArithSyntax.v34
-rw-r--r--test-suite/output/RealSyntax.out101
-rw-r--r--test-suite/output/RealSyntax.v44
-rw-r--r--test-suite/output/Record.out40
-rw-r--r--test-suite/output/Record.v31
-rw-r--r--test-suite/output/Search.out108
-rw-r--r--test-suite/output/Search.v7
-rw-r--r--test-suite/output/SearchHead.out6
-rw-r--r--test-suite/output/SearchPattern.out8
-rw-r--r--test-suite/output/Search_bug13298.out1
-rw-r--r--test-suite/output/Search_bug13298.v3
-rw-r--r--test-suite/output/StringSyntax.out22
-rw-r--r--test-suite/output/StringSyntax.v65
-rw-r--r--test-suite/output/ZSyntax.v2
-rw-r--r--test-suite/output/bug_12159.v6
-rw-r--r--test-suite/output/bug_12908.out5
-rw-r--r--test-suite/output/bug_12908.v7
-rw-r--r--test-suite/output/bug_13004.out4
-rw-r--r--test-suite/output/bug_13112.out4
-rw-r--r--test-suite/output/bug_13112.v5
-rw-r--r--test-suite/output/bug_13238.out4
-rw-r--r--test-suite/output/bug_13238.v13
-rw-r--r--test-suite/output/bug_13244.out9
-rw-r--r--test-suite/output/bug_13244.v3
-rw-r--r--test-suite/output/bug_9180.out3
-rw-r--r--test-suite/output/bug_9682.out9
-rw-r--r--test-suite/output/bug_9682.v10
-rw-r--r--test-suite/output/goal_output.out74
-rw-r--r--test-suite/output/goal_output.v28
-rw-r--r--test-suite/output/locate.out5
-rw-r--r--test-suite/output/prim_array.out9
-rw-r--r--test-suite/output/prim_array.v10
-rw-r--r--test-suite/primitive/arrays/reroot.v22
-rw-r--r--test-suite/success/Nsatz.v56
-rw-r--r--test-suite/success/NumberNotationsNoLocal.v (renamed from test-suite/success/NumeralNotationsNoLocal.v)2
-rw-r--r--test-suite/success/Record.v15
-rw-r--r--test-suite/success/definition_using.v68
-rw-r--r--test-suite/success/polymorphism.v7
-rw-r--r--test-suite/success/rewrite_strat.v9
-rw-r--r--test-suite/success/sprop_uip.v27
-rw-r--r--theories/Array/PArray.v19
-rw-r--r--theories/FSets/FMapPositive.v4
-rw-r--r--theories/Init/Byte.v2
-rw-r--r--theories/Init/Decimal.v6
-rw-r--r--theories/Init/Hexadecimal.v38
-rw-r--r--theories/Init/Nat.v20
-rw-r--r--theories/Init/Number.v45
-rw-r--r--theories/Init/Numeral.v67
-rw-r--r--theories/Init/Prelude.v15
-rw-r--r--theories/Init/Tactics.v9
-rw-r--r--theories/NArith/BinNatDef.v16
-rw-r--r--theories/Numbers/AltBinNotations.v2
-rw-r--r--theories/Numbers/DecimalFacts.v607
-rw-r--r--theories/Numbers/DecimalN.v4
-rw-r--r--theories/Numbers/DecimalNat.v4
-rw-r--r--theories/Numbers/DecimalQ.v894
-rw-r--r--theories/Numbers/DecimalR.v312
-rw-r--r--theories/Numbers/DecimalZ.v27
-rw-r--r--theories/Numbers/HexadecimalFacts.v627
-rw-r--r--theories/Numbers/HexadecimalN.v4
-rw-r--r--theories/Numbers/HexadecimalNat.v4
-rw-r--r--theories/Numbers/HexadecimalQ.v880
-rw-r--r--theories/Numbers/HexadecimalR.v302
-rw-r--r--theories/Numbers/HexadecimalZ.v27
-rw-r--r--theories/PArith/BinPosDef.v16
-rw-r--r--theories/QArith/QArith_base.v285
-rw-r--r--theories/QArith/Qreals.v2
-rw-r--r--theories/Reals/RIneq.v60
-rw-r--r--theories/Reals/Rdefinitions.v167
-rw-r--r--theories/Reals/Rregisternames.v4
-rw-r--r--theories/Strings/ByteVector.v2
-rw-r--r--theories/Structures/OrdersEx.v8
-rw-r--r--theories/ZArith/BinIntDef.v14
-rw-r--r--theories/dune4
-rw-r--r--theories/extraction/ExtrOCamlPArray.v1
-rw-r--r--theories/micromega/RingMicromega.v4
-rw-r--r--theories/micromega/Zify.v15
-rw-r--r--theories/micromega/ZifyInt63.v178
-rw-r--r--theories/omega/PreOmega.v2
-rw-r--r--theories/ssr/ssrbool.v13
-rw-r--r--topbin/coqtacticworker_bin.ml2
-rw-r--r--toplevel/coqargs.ml1
-rw-r--r--toplevel/coqinit.ml67
-rw-r--r--toplevel/coqinit.mli4
-rw-r--r--toplevel/coqloop.ml44
-rw-r--r--toplevel/g_toplevel.mlg5
-rw-r--r--toplevel/usage.ml1
-rw-r--r--user-contrib/Ltac2/g_ltac2.mlg131
-rw-r--r--user-contrib/Ltac2/tac2core.ml4
-rw-r--r--user-contrib/Ltac2/tac2entries.ml29
-rw-r--r--user-contrib/Ltac2/tac2entries.mli4
-rw-r--r--user-contrib/Ltac2/tac2expr.mli1
-rw-r--r--user-contrib/Ltac2/tac2intern.ml20
-rw-r--r--user-contrib/Ltac2/tac2quote.ml2
-rw-r--r--vernac/attributes.ml8
-rw-r--r--vernac/attributes.mli1
-rw-r--r--vernac/auto_ind_decl.ml9
-rw-r--r--vernac/classes.ml30
-rw-r--r--vernac/comAssumption.ml10
-rw-r--r--vernac/comAssumption.mli9
-rw-r--r--vernac/comDefinition.ml41
-rw-r--r--vernac/comDefinition.mli13
-rw-r--r--vernac/comFixpoint.ml23
-rw-r--r--vernac/comFixpoint.mli4
-rw-r--r--vernac/comHints.ml30
-rw-r--r--vernac/comProgramFixpoint.ml30
-rw-r--r--vernac/comProgramFixpoint.mli2
-rw-r--r--vernac/comSearch.ml11
-rw-r--r--vernac/comTactic.ml82
-rw-r--r--vernac/comTactic.mli50
-rw-r--r--vernac/declare.ml191
-rw-r--r--vernac/declare.mli8
-rw-r--r--vernac/egramcoq.ml8
-rw-r--r--vernac/g_vernac.mlg105
-rw-r--r--vernac/himsg.ml14
-rw-r--r--vernac/indschemes.ml2
-rw-r--r--vernac/metasyntax.ml99
-rw-r--r--vernac/ppvernac.ml11
-rw-r--r--vernac/prettyp.ml2
-rw-r--r--vernac/proof_using.ml26
-rw-r--r--vernac/proof_using.mli5
-rw-r--r--vernac/pvernac.ml3
-rw-r--r--vernac/pvernac.mli2
-rw-r--r--vernac/recLemmas.ml4
-rw-r--r--vernac/record.ml75
-rw-r--r--vernac/search.ml20
-rw-r--r--vernac/vernac.mllib1
-rw-r--r--vernac/vernacentries.ml113
-rw-r--r--vernac/vernacexpr.ml4
-rw-r--r--vernac/vernacextend.ml3
-rw-r--r--vernac/vernacextend.mli1
528 files changed, 16458 insertions, 11557 deletions
diff --git a/.gitignore b/.gitignore
index bdd692420f..aab1d1ede7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -155,6 +155,7 @@ kernel/byterun/coq_jumptbl.h
kernel/genOpcodeFiles.exe
kernel/vmopcodes.ml
kernel/uint63.ml
+kernel/float64.ml
ide/coqide/default.bindings
ide/coqide/default_bindings_src.exe
ide/coqide/index_urls.txt
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 9b208f5a24..18ea50d77b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -19,7 +19,7 @@ stages:
variables:
# Format: $IMAGE-V$DATE [Cache is not used as of today but kept here
# for reference]
- CACHEKEY: "bionic_coq-V2020-09-17-V88"
+ CACHEKEY: "bionic_coq-V2020-10-12-V89"
IMAGE: "$CI_REGISTRY_IMAGE:$CACHEKEY"
# By default, jobs run in the base switch; override to select another switch
OPAM_SWITCH: "base"
@@ -461,7 +461,7 @@ pkg:nix:deploy:channel:
script:
- echo "$CACHIX_DEPLOYMENT_KEY" | tr -d '\r' | ssh-add - > /dev/null
# Remove all pr branches because they could be missing when we run git fetch --unshallow
- - git branch --list 'pr-*' | xargs -r git branch -d
+ - git branch --list 'pr-*' | xargs -r git branch -D
- git fetch --unshallow
- git branch -v
- git push git@github.com:coq/coq-on-cachix "${CI_COMMIT_SHA}":"refs/heads/${CI_COMMIT_REF_NAME}"
diff --git a/Makefile.build b/Makefile.build
index eed3c2813a..526a8c5831 100644
--- a/Makefile.build
+++ b/Makefile.build
@@ -401,6 +401,12 @@ kernel/uint63.ml: kernel/uint63_$(OCAML_INT_SIZE).ml
rm -f $@ && cp $< $@ && chmod a-w $@
###########################################################################
+# Specific rules for Float64
+###########################################################################
+kernel/float64.ml: kernel/float64_$(OCAML_INT_SIZE).ml
+ rm -f $@ && cp $< $@ && chmod a-w $@
+
+###########################################################################
# Main targets (coqtop.opt, coqtop.byte)
###########################################################################
diff --git a/Makefile.common b/Makefile.common
index a482b9b963..caf1821ce5 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -149,11 +149,9 @@ CCCMO:=plugins/cc/cc_plugin.cmo
BTAUTOCMO:=plugins/btauto/btauto_plugin.cmo
RTAUTOCMO:=plugins/rtauto/rtauto_plugin.cmo
SYNTAXCMO:=$(addprefix plugins/syntax/, \
- r_syntax_plugin.cmo \
int63_syntax_plugin.cmo \
float_syntax_plugin.cmo \
- numeral_notation_plugin.cmo \
- string_notation_plugin.cmo)
+ number_string_notation_plugin.cmo)
DERIVECMO:=plugins/derive/derive_plugin.cmo
LTACCMO:=plugins/ltac/ltac_plugin.cmo plugins/ltac/tauto_plugin.cmo
SSRMATCHINGCMO:=plugins/ssrmatching/ssrmatching_plugin.cmo
diff --git a/Makefile.make b/Makefile.make
index 51d6d1c3c1..34f5707ae8 100644
--- a/Makefile.make
+++ b/Makefile.make
@@ -107,7 +107,7 @@ GRAMMLIFILES := $(addsuffix .mli, $(GRAMFILES))
GENGRAMMLFILES := $(GRAMMLFILES) gramlib/.pack/gramlib.ml # why is gramlib.ml not in GRAMMLFILES?
GENMLGFILES:= $(MLGFILES:.mlg=.ml)
-GENMLFILES:=$(LEXFILES:.mll=.ml) $(YACCFILES:.mly=.ml) $(GENMLGFILES) $(GENGRAMMLFILES) ide/coqide/coqide_os_specific.ml kernel/vmopcodes.ml kernel/uint63.ml
+GENMLFILES:=$(LEXFILES:.mll=.ml) $(YACCFILES:.mly=.ml) $(GENMLGFILES) $(GENGRAMMLFILES) ide/coqide/coqide_os_specific.ml kernel/vmopcodes.ml kernel/uint63.ml kernel/float64.ml
GENMLIFILES:=$(GRAMMLIFILES)
GENHFILES:=kernel/byterun/coq_instruct.h kernel/byterun/coq_jumptbl.h
GENFILES:=$(GENMLFILES) $(GENMLIFILES) $(GENHFILES) kernel/genOpcodeFiles.exe
diff --git a/checker/checkInductive.ml b/checker/checkInductive.ml
index ef606c9a75..7bb714aa17 100644
--- a/checker/checkInductive.ml
+++ b/checker/checkInductive.ml
@@ -104,7 +104,7 @@ let check_kelim k1 k2 = Sorts.family_leq k1 k2
let eq_nested_types ty1 ty2 = match ty1, ty2 with
| NestedInd ind1, NestedInd ind2 -> eq_ind_chk ind1 ind2
| NestedInd _, _ -> false
-| NestedPrimitive c1, NestedPrimitive c2 -> Names.Constant.equal c1 c2
+| NestedPrimitive c1, NestedPrimitive c2 -> Names.Constant.CanOrd.equal c1 c2
| NestedPrimitive _, _ -> false
let eq_recarg a1 a2 = match a1, a2 with
diff --git a/clib/cList.ml b/clib/cList.ml
index 057200f83e..6b13fac48c 100644
--- a/clib/cList.ml
+++ b/clib/cList.ml
@@ -1019,20 +1019,12 @@ let rec factorize_left cmp = function
module Smart =
struct
- let rec map_loop f p = function
- | [] -> ()
- | x :: l' as l ->
- let x' = f x in
- map_loop f p l';
- if x' == x && !p == l' then p := l else p := x' :: !p
-
- let map f = function
- | [] -> []
- | x :: l' as l ->
- let p = ref [] in
- let x' = f x in
- map_loop f p l';
- if x' == x && !p == l' then l else x' :: !p
+ let rec map f l = match l with
+ | [] -> l
+ | h :: tl ->
+ let h' = f h in
+ let tl' = map f tl in
+ if h' == h && tl' == tl then l else h' :: tl'
end
diff --git a/clib/cString.ml b/clib/cString.ml
index dcada4c18f..9d2c3729b2 100644
--- a/clib/cString.ml
+++ b/clib/cString.ml
@@ -25,6 +25,7 @@ sig
val ordinal : int -> string
val is_sub : string -> string -> int -> bool
val is_prefix : string -> string -> bool
+ val is_suffix : string -> string -> bool
module Set : Set.S with type elt = t
module Map : CMap.ExtS with type key = t and module Set := Set
module List : CList.MonoS with type elt = t
@@ -105,6 +106,9 @@ let is_sub p s off =
let is_prefix p s =
is_sub p s 0
+let is_suffix p s =
+ is_sub p s (String.length s - String.length p)
+
let plural n s = if n<>1 then s^"s" else s
let conjugate_verb_to_be n = if n<>1 then "are" else "is"
diff --git a/clib/cString.mli b/clib/cString.mli
index 0f78e66573..be8a202b64 100644
--- a/clib/cString.mli
+++ b/clib/cString.mli
@@ -54,6 +54,9 @@ sig
val is_prefix : string -> string -> bool
(** [is_prefix p s] tests whether [p] is a prefix of [s]. *)
+ val is_suffix : string -> string -> bool
+ (** [is_suffix suf s] tests whether [suf] is a suffix of [s]. *)
+
(** {6 Generic operations} **)
module Set : Set.S with type elt = t
diff --git a/coqpp/coqpp_main.ml b/coqpp/coqpp_main.ml
index 5e3199e8a6..8affe58824 100644
--- a/coqpp/coqpp_main.ml
+++ b/coqpp/coqpp_main.ml
@@ -454,7 +454,7 @@ struct
let terminal s =
let p =
- if s <> "" && s.[0] >= '0' && s.[0] <= '9' then "CLexer.terminal_numeral"
+ if s <> "" && s.[0] >= '0' && s.[0] <= '9' then "CLexer.terminal_number"
else "CLexer.terminal" in
let c = Printf.sprintf "Pcoq.Symbol.token (%s \"%s\")" p s in
SymbQuote c
@@ -469,7 +469,7 @@ let rec parse_symb self = function
| Uentryl (e, l) ->
assert (e = "tactic");
if l = 5 then SymbEntry ("Pltac.binder_tactic", None)
- else SymbEntry ("Pltac.tactic_expr", Some (string_of_int l))
+ else SymbEntry ("Pltac.ltac_expr", Some (string_of_int l))
let parse_token self = function
| ExtTerminal s -> (terminal s, None)
diff --git a/default.nix b/default.nix
index ffee77f1f7..7f9e62b28c 100644
--- a/default.nix
+++ b/default.nix
@@ -43,7 +43,6 @@ stdenv.mkDerivation rec {
hostname
python3 time # coq-makefile timing tools
]
- ++ (with ocamlPackages; [ ocaml findlib ])
++ optionals buildIde [
ocamlPackages.lablgtk3-sourceview3
glib gnome3.defaultIconTheme wrapGAppsHook
@@ -69,10 +68,13 @@ stdenv.mkDerivation rec {
++ [ dune_2 ] # Maybe the next build system
);
- # Since #12604, ocamlfind looks for num when building plugins
+ # OCaml and findlib are needed so that native_compute works
+ # This follows a similar change in the nixpkgs repo (cf. NixOS/nixpkgs#101058)
+ # ocamlfind looks for zarith when building plugins
# This follows a similar change in the nixpkgs repo (cf. NixOS/nixpkgs#94230)
- # Same for zarith which is needed since its introduction as a dependency of Coq
- propagatedBuildInputs = with ocamlPackages; [ zarith ];
+ propagatedBuildInputs = with ocamlPackages; [ ocaml findlib zarith ];
+
+ propagatedUserEnvPkgs = with ocamlPackages; [ ocaml findlib ];
src =
if shell then null
diff --git a/dev/bench/gitlab-bench.yml b/dev/bench/gitlab-bench.yml
index 4275e3d121..25545cf565 100644
--- a/dev/bench/gitlab-bench.yml
+++ b/dev/bench/gitlab-bench.yml
@@ -11,18 +11,6 @@ bench:
- timing
variables:
GIT_DEPTH: ""
- coq_pr_number: ""
- coq_pr_comment_id: ""
- new_ocaml_switch: "ocaml-base-compiler.4.07.1"
- old_ocaml_switch: "ocaml-base-compiler.4.07.1"
- new_coq_repository: "https://gitlab.com/coq/coq.git"
- old_coq_repository: "https://gitlab.com/coq/coq.git"
- new_coq_opam_archive_git_uri: "https://github.com/coq/opam-coq-archive.git"
- old_coq_opam_archive_git_uri: "https://github.com/coq/opam-coq-archive.git"
- new_coq_opam_archive_git_branch: "master"
- old_coq_opam_archive_git_branch: "master"
- num_of_iterations: 1
- coq_opam_packages: "coq-performance-tests-lite coq-engine-bench-lite coq-hott coq-bignums coq-mathcomp-ssreflect coq-mathcomp-fingroup coq-mathcomp-algebra coq-mathcomp-solvable coq-mathcomp-field coq-mathcomp-character coq-mathcomp-odd-order coq-math-classes coq-corn coq-flocq coq-compcert coq-geocoq coq-color coq-coqprime coq-coqutil coq-bedrock2 coq-rewriter coq-fiat-core coq-fiat-parsers coq-fiat-crypto coq-unimath coq-sf-plf coq-coquelicot coq-lambda-rust coq-verdi coq-verdi-raft coq-fourcolor coq-rewriter-perf-SuperFast"
artifacts:
name: "$CI_JOB_NAME"
paths:
diff --git a/dev/bench/gitlab.sh b/dev/bench/gitlab.sh
index 7625e4e7f7..d2e150be9a 100755
--- a/dev/bench/gitlab.sh
+++ b/dev/bench/gitlab.sh
@@ -40,18 +40,19 @@ echo $PWD
#check_variable "JOB_NAME"
#check_variable "JENKINS_URL"
check_variable "CI_JOB_URL"
-check_variable "coq_pr_number"
-check_variable "coq_pr_comment_id"
-check_variable "new_ocaml_switch"
-check_variable "new_coq_repository"
-check_variable "new_coq_opam_archive_git_uri"
-check_variable "new_coq_opam_archive_git_branch"
-check_variable "old_ocaml_switch"
-check_variable "old_coq_repository"
-check_variable "old_coq_opam_archive_git_uri"
-check_variable "old_coq_opam_archive_git_branch"
-check_variable "num_of_iterations"
-check_variable "coq_opam_packages"
+
+: "${coq_pr_number:=}"
+: "${coq_pr_comment_id:=}"
+: "${new_ocaml_switch:=ocaml-base-compiler.4.07.1}"
+: "${old_ocaml_switch:=ocaml-base-compiler.4.07.1}"
+: "${new_coq_repository:=https://gitlab.com/coq/coq.git}"
+: "${old_coq_repository:=https://gitlab.com/coq/coq.git}"
+: "${new_coq_opam_archive_git_uri:=https://github.com/coq/opam-coq-archive.git}"
+: "${old_coq_opam_archive_git_uri:=https://github.com/coq/opam-coq-archive.git}"
+: "${new_coq_opam_archive_git_branch:=master}"
+: "${old_coq_opam_archive_git_branch:=master}"
+: "${num_of_iterations:=1}"
+: "${coq_opam_packages:=coq-performance-tests-lite coq-engine-bench-lite coq-hott coq-bignums coq-mathcomp-ssreflect coq-mathcomp-fingroup coq-mathcomp-algebra coq-mathcomp-solvable coq-mathcomp-field coq-mathcomp-character coq-mathcomp-odd-order coq-math-classes coq-corn coq-flocq coq-compcert coq-geocoq coq-color coq-coqprime coq-coqutil coq-bedrock2 coq-rewriter coq-fiat-core coq-fiat-parsers coq-fiat-crypto coq-unimath coq-sf-plf coq-coquelicot coq-lambda-rust coq-verdi coq-verdi-raft coq-fourcolor coq-rewriter-perf-SuperFast}"
new_coq_commit=$(git rev-parse HEAD^2)
old_coq_commit=$(git merge-base HEAD^1 $new_coq_commit)
@@ -428,6 +429,9 @@ for coq_opam_package in $sorted_coq_opam_packages; do
new_base_path=$new_ocaml_switch/.opam-switch/build/$coq_opam_package.dev*/
old_base_path=$old_ocaml_switch/.opam-switch/build/$coq_opam_package.dev*/
for vo in `cd $new_opam_root/$new_base_path/; find -name '*.vo'`; do
+ if [ -e $old_opam_root/$old_base_path/$vo ]; then
+ echo "$coq_opam_package/$vo $(stat -c%s $old_opam_root/$old_base_path/$vo) $(stat -c%s $new_opam_root/$new_base_path/$vo)" >> "$log_dir/vosize.log"
+ fi
if [ -e $old_opam_root/$old_base_path/${vo%%o}.timing -a \
-e $new_opam_root/$new_base_path/${vo%%o}.timing ]; then
mkdir -p $working_dir/html/$coq_opam_package/`dirname $vo`/
diff --git a/dev/build/windows/makecoq_mingw.sh b/dev/build/windows/makecoq_mingw.sh
index fcc585117b..fc8921e63d 100755
--- a/dev/build/windows/makecoq_mingw.sh
+++ b/dev/build/windows/makecoq_mingw.sh
@@ -1204,7 +1204,7 @@ function make_elpi {
make_dune
make_re
- if build_prep https://github.com/LPCIC/elpi/archive v1.11.0 tar.gz 1 elpi; then
+ if build_prep https://github.com/LPCIC/elpi/archive v1.11.4 tar.gz 1 elpi; then
log2 dune build -p elpi
log2 dune install elpi
diff --git a/dev/ci/ci-common.sh b/dev/ci/ci-common.sh
index f9187d53a6..b85261d7fc 100644
--- a/dev/ci/ci-common.sh
+++ b/dev/ci/ci-common.sh
@@ -44,6 +44,18 @@ CI_BUILD_DIR="$PWD/_build_ci"
ls -l "$CI_BUILD_DIR" || true
+declare -A overlays
+
+overlay()
+{
+ local project=$1
+ local ov_url=$2
+ local ov_ref=$3
+
+ overlays[${project}_URL]=$ov_url
+ overlays[${project}_REF]=$ov_ref
+}
+
set +x
for overlay in "${ci_dir}"/user-overlays/*.sh; do
# shellcheck source=/dev/null
@@ -62,32 +74,44 @@ set -x
# (local build), it uses git clone to perform the download.
git_download()
{
- local PROJECT=$1
- local DEST="$CI_BUILD_DIR/$PROJECT"
- local GITURL_VAR="${PROJECT}_CI_GITURL"
- local GITURL="${!GITURL_VAR}"
- local REF_VAR="${PROJECT}_CI_REF"
- local REF="${!REF_VAR}"
-
- if [ -d "$DEST" ]; then
- echo "Warning: download and unpacking of $PROJECT skipped because $DEST already exists."
- elif [ "$FORCE_GIT" = "1" ] || [ "$CI" = "" ]; then
- git clone "$GITURL" "$DEST"
- cd "$DEST"
- git checkout "$REF"
+ local project=$1
+ local dest="$CI_BUILD_DIR/$project"
+
+ local giturl_var="${project}_CI_GITURL"
+ local giturl="${!giturl_var}"
+ local ref_var="${project}_CI_REF"
+ local ref="${!ref_var}"
+
+ local ov_url=${overlays[${project}_URL]}
+ local ov_ref=${overlays[${project}_REF]}
+
+ if [ -d "$dest" ]; then
+ echo "Warning: download and unpacking of $project skipped because $dest already exists."
+ elif [[ $ov_url ]] || [ "$FORCE_GIT" = "1" ] || [ "$CI" = "" ]; then
+ git clone "$giturl" "$dest"
+ cd "$dest"
+ git checkout "$ref"
+ git log -n 1
+ if [[ $ov_url ]]; then
+ git -c pull.rebase=false -c user.email=nobody@example.invalid -c user.name=Nobody \
+ pull --no-ff "$ov_url" "$ov_ref"
+ git log -n 1 HEAD^2
+ git log -n 1
+ fi
else # When possible, we download tarballs to reduce bandwidth and latency
- local ARCHIVEURL_VAR="${PROJECT}_CI_ARCHIVEURL"
- local ARCHIVEURL="${!ARCHIVEURL_VAR}"
- mkdir -p "$DEST"
- cd "$DEST"
- local COMMIT=$(git ls-remote "$GITURL" "refs/heads/$REF" | cut -f 1)
- if [[ "$COMMIT" == "" ]]; then
- # $REF must have been a tag or hash, not a branch
- COMMIT="$REF"
+ local archiveurl_var="${project}_CI_ARCHIVEURL"
+ local archiveurl="${!archiveurl_var}"
+ mkdir -p "$dest"
+ cd "$dest"
+ local commit
+ commit=$(git ls-remote "$giturl" "refs/heads/$ref" | cut -f 1)
+ if [[ "$commit" == "" ]]; then
+ # $ref must have been a tag or hash, not a branch
+ commit="$ref"
fi
- wget "$ARCHIVEURL/$COMMIT.tar.gz"
- tar xfz "$COMMIT.tar.gz" --strip-components=1
- rm -f "$COMMIT.tar.gz"
+ wget "$archiveurl/$commit.tar.gz"
+ tar xfz "$commit.tar.gz" --strip-components=1
+ rm -f "$commit.tar.gz"
fi
}
diff --git a/dev/ci/docker/bionic_coq/Dockerfile b/dev/ci/docker/bionic_coq/Dockerfile
index f672ead807..c17ec502e7 100644
--- a/dev/ci/docker/bionic_coq/Dockerfile
+++ b/dev/ci/docker/bionic_coq/Dockerfile
@@ -1,4 +1,4 @@
-# CACHEKEY: "bionic_coq-V2020-09-17-V88"
+# CACHEKEY: "bionic_coq-V2020-10-12-V89"
# ^^ Update when modifying this file.
FROM ubuntu:bionic
@@ -43,7 +43,7 @@ ENV COMPILER="4.05.0"
# Common OPAM packages
ENV BASE_OPAM="zarith.1.10 ocamlfind.1.8.1 ounit2.2.2.3 odoc.1.5.1" \
CI_OPAM="menhir.20190626 ocamlgraph.1.8.8" \
- BASE_ONLY_OPAM="elpi.1.11.0"
+ BASE_ONLY_OPAM="elpi.1.11.4"
# BASE switch; CI_OPAM contains Coq's CI dependencies.
ENV COQIDE_OPAM="cairo2.0.6.1 lablgtk3-sourceview3.3.1.0"
diff --git a/dev/ci/user-overlays/08743-ejgallego-zarith.sh b/dev/ci/user-overlays/08743-ejgallego-zarith.sh
deleted file mode 100644
index da1d30c1e9..0000000000
--- a/dev/ci/user-overlays/08743-ejgallego-zarith.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "11742" ] || [ "$CI_BRANCH" = "zarith+core" ]; then
-
- bignums_CI_REF=zarith
- bignums_CI_GITURL=https://github.com/ejgallego/bignums
-
-fi
diff --git a/dev/ci/user-overlays/10390-SkySkimmer-uip.sh b/dev/ci/user-overlays/10390-SkySkimmer-uip.sh
deleted file mode 100644
index 80107ac9c5..0000000000
--- a/dev/ci/user-overlays/10390-SkySkimmer-uip.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "10390" ] || [ "$CI_BRANCH" = "uip" ]; then
-
- unicoq_CI_REF=uip
- unicoq_CI_GITURL=https://github.com/SkySkimmer/unicoq
-
- mtac2_CI_REF=uip
- mtac2_CI_GITURL=https://github.com/SkySkimmer/Mtac2
-
- elpi_CI_REF=uip
- elpi_CI_GITURL=https://github.com/SkySkimmer/coq-elpi
-
- equations_CI_REF=uip
- equations_CI_GITURL=https://github.com/SkySkimmer/Coq-Equations
-
- paramcoq_CI_REF=uip
- paramcoq_CI_GITURL=https://github.com/SkySkimmer/paramcoq
-
- relation_algebra_CI_REF=uip
- relation_algebra_CI_GITURL=https://github.com/SkySkimmer/relation-algebra
-
- coq_dpdgraph_CI_REF=uip
- coq_dpdgraph_CI_GITURL=https://github.com/SkySkimmer/coq-dpdgraph
-
- coqhammer_CI_REF=uip
- coqhammer_CI_GITURL=https://github.com/SkySkimmer/coqhammer
-
- metacoq_CI_REF=uip
- metacoq_CI_GITURL=https://github.com/SkySkimmer/metacoq
-
-fi
diff --git a/dev/ci/user-overlays/11566-ejgallego-exninfo+coercion.sh b/dev/ci/user-overlays/11566-ejgallego-exninfo+coercion.sh
deleted file mode 100644
index 05192facbe..0000000000
--- a/dev/ci/user-overlays/11566-ejgallego-exninfo+coercion.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "11566" ] || [ "$CI_BRANCH" = "exninfo+coercion" ]; then
-
- mtac2_CI_REF=exninfo+coercion
- mtac2_CI_GITURL=https://github.com/ejgallego/Mtac2
-
-fi
diff --git a/dev/ci/user-overlays/11604-persistent-arrays.sh b/dev/ci/user-overlays/11604-persistent-arrays.sh
deleted file mode 100644
index aec5c4fa3d..0000000000
--- a/dev/ci/user-overlays/11604-persistent-arrays.sh
+++ /dev/null
@@ -1,18 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "11604" ] || [ "$CI_BRANCH" = "persistent-arrays" ]; then
-
- unicoq_CI_REF=persistent-arrays
- unicoq_CI_GITURL=https://github.com/maximedenes/unicoq
-
- elpi_CI_REF=persistent-arrays
- elpi_CI_GITURL=https://github.com/maximedenes/coq-elpi
-
- #relation_algebra_CI_REF=persistent-arrays
- #relation_algebra_CI_GITURL=https://github.com/maximedenes/relation-algebra
-
- coqhammer_CI_REF=persistent-arrays
- coqhammer_CI_GITURL=https://github.com/maximedenes/coqhammer
-
- metacoq_CI_REF=persistent-arrays
- metacoq_CI_GITURL=https://github.com/maximedenes/metacoq
-
-fi
diff --git a/dev/ci/user-overlays/11836-ejgallego-obligations+functional.sh b/dev/ci/user-overlays/11836-ejgallego-obligations+functional.sh
deleted file mode 100644
index 72ec55a37c..0000000000
--- a/dev/ci/user-overlays/11836-ejgallego-obligations+functional.sh
+++ /dev/null
@@ -1,18 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "11836" ] || [ "$CI_BRANCH" = "obligations+functional" ]; then
-
- mtac2_CI_REF=obligations+functional
- mtac2_CI_GITURL=https://github.com/ejgallego/Mtac2
-
- paramcoq_CI_REF=obligations+functional
- paramcoq_CI_GITURL=https://github.com/ejgallego/paramcoq
-
- equations_CI_REF=obligations+functional
- equations_CI_GITURL=https://github.com/ejgallego/Coq-Equations
-
- metacoq_CI_REF=obligations+functional
- metacoq_CI_GITURL=https://github.com/ejgallego/metacoq
-
- rewriter_CI_REF=obligations+functional
- rewriter_CI_GITURL=https://github.com/ejgallego/rewriter
-
-fi
diff --git a/dev/ci/user-overlays/11922-ppedrot-rm-local-reductionops.sh b/dev/ci/user-overlays/11922-ppedrot-rm-local-reductionops.sh
deleted file mode 100644
index c9ddb3fb9f..0000000000
--- a/dev/ci/user-overlays/11922-ppedrot-rm-local-reductionops.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "11922" ] || [ "$CI_BRANCH" = "rm-local-reductionops" ]; then
-
- equations_CI_REF="rm-local-reductionops"
- equations_CI_GITURL=https://github.com/ppedrot/Coq-Equations
-
- unicoq_CI_REF="rm-local-reductionops"
- unicoq_CI_GITURL=https://github.com/ppedrot/unicoq
-
-fi
diff --git a/dev/ci/user-overlays/11948-proux01-hexadecimal.sh b/dev/ci/user-overlays/11948-proux01-hexadecimal.sh
deleted file mode 100644
index 0b3133d1f1..0000000000
--- a/dev/ci/user-overlays/11948-proux01-hexadecimal.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "11948" ] || [ "$CI_BRANCH" = "hexadecimal" ]; then
-
- stdlib2_CI_REF=hexadecimal
- stdlib2_CI_GITURL=https://github.com/proux01/stdlib2
-
- paramcoq_CI_REF=hexadecimal
- paramcoq_CI_GITURL=https://github.com/proux01/paramcoq
-
- metacoq_CI_REF=hexadecimal
- metacoq_CI_GITURL=https://github.com/proux01/metacoq
-
-fi
diff --git a/dev/ci/user-overlays/12218-proux01-numeral-notations-non-inductive.sh b/dev/ci/user-overlays/12218-proux01-numeral-notations-non-inductive.sh
new file mode 100644
index 0000000000..d9b49ad0d1
--- /dev/null
+++ b/dev/ci/user-overlays/12218-proux01-numeral-notations-non-inductive.sh
@@ -0,0 +1,18 @@
+if [ "$CI_PULL_REQUEST" = "12218" ] || [ "$CI_BRANCH" = "numeral-notations-non-inductive" ]; then
+
+ stdlib2_CI_REF=numeral-notations-non-inductive
+ stdlib2_CI_GITURL=https://github.com/proux01/stdlib2
+
+ hott_CI_REF=numeral-notations-non-inductive
+ hott_CI_GITURL=https://github.com/proux01/HoTT
+
+ paramcoq_CI_REF=numeral-notations-non-inductive
+ paramcoq_CI_GITURL=https://github.com/proux01/paramcoq
+
+ quickchick_CI_REF=numeral-notations-non-inductive
+ quickchick_CI_GITURL=https://github.com/proux01/QuickChick
+
+ metacoq_CI_REF=numeral-notations-non-inductive
+ metacoq_CI_GITURL=https://github.com/proux01/metacoq
+
+fi
diff --git a/dev/ci/user-overlays/12267-gares-elpi-1.11.sh b/dev/ci/user-overlays/12267-gares-elpi-1.11.sh
deleted file mode 100644
index ceb7afe3d1..0000000000
--- a/dev/ci/user-overlays/12267-gares-elpi-1.11.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12267" ] || [ "$CI_BRANCH" = "elpi-1.11" ]; then
-
- elpi_CI_REF="coq-master+elpi-1.11"
- elpi_hb_CI_REF="coq-master+elpi.11"
-
-fi
diff --git a/dev/ci/user-overlays/12372-ejgallego-proof+info.sh b/dev/ci/user-overlays/12372-ejgallego-proof+info.sh
deleted file mode 100644
index b9fdc338b5..0000000000
--- a/dev/ci/user-overlays/12372-ejgallego-proof+info.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12372" ] || [ "$CI_BRANCH" = "proof+info" ]; then
-
- rewriter_CI_REF=proof+info
- rewriter_CI_GITURL=https://github.com/ejgallego/rewriter
-
- paramcoq_CI_REF=proof+info
- paramcoq_CI_GITURL=https://github.com/ejgallego/paramcoq
-
- mtac2_CI_REF=proof+info
- mtac2_CI_GITURL=https://github.com/ejgallego/Mtac2
-
- equations_CI_REF=proof+info
- equations_CI_GITURL=https://github.com/ejgallego/Coq-Equations
-
- elpi_CI_REF=proof+info
- elpi_CI_GITURL=https://github.com/ejgallego/coq-elpi
-
- aac_tactics_CI_REF=proof+info
- aac_tactics_CI_GITURL=https://github.com/ejgallego/aac-tactics
-
- metacoq_CI_REF=proof+info
- metacoq_CI_GITURL=https://github.com/ejgallego/metacoq
-
-fi
diff --git a/dev/ci/user-overlays/12449-SkySkimmer-minim-prop-toset.sh b/dev/ci/user-overlays/12449-SkySkimmer-minim-prop-toset.sh
new file mode 100644
index 0000000000..fb5947d218
--- /dev/null
+++ b/dev/ci/user-overlays/12449-SkySkimmer-minim-prop-toset.sh
@@ -0,0 +1,6 @@
+if [ "$CI_PULL_REQUEST" = "12449" ] || [ "$CI_BRANCH" = "minim-prop-toset" ]; then
+
+ mtac2_CI_REF=janno/coq-12449
+ mtac2_CI_GITURL=https://github.com/mtac2/mtac2
+
+fi
diff --git a/dev/ci/user-overlays/12505-ppedrot-factor-hint-flags.sh b/dev/ci/user-overlays/12505-ppedrot-factor-hint-flags.sh
deleted file mode 100644
index ced0d95945..0000000000
--- a/dev/ci/user-overlays/12505-ppedrot-factor-hint-flags.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12505" ] || [ "$CI_BRANCH" = "factor-hint-flags" ]; then
-
- fiat_parsers_CI_REF="factor-hint-flags"
- fiat_parsers_CI_GITURL=https://github.com/ppedrot/fiat
-
-fi
diff --git a/dev/ci/user-overlays/12523-term-notation-custom.sh b/dev/ci/user-overlays/12523-term-notation-custom.sh
deleted file mode 100644
index 6217312a2a..0000000000
--- a/dev/ci/user-overlays/12523-term-notation-custom.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12523" ] || [ "$CI_BRANCH" = "fix-11121" ]; then
-
- equations_CI_REF=fix-11121
- equations_CI_GITURL=https://github.com/maximedenes/Coq-Equations
-
-fi
diff --git a/dev/ci/user-overlays/12565-ppedrot-fix-tc-search-opacity.sh b/dev/ci/user-overlays/12565-ppedrot-fix-tc-search-opacity.sh
deleted file mode 100644
index 7c04608403..0000000000
--- a/dev/ci/user-overlays/12565-ppedrot-fix-tc-search-opacity.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12565" ] || [ "$CI_BRANCH" = "fix-tc-search-opacity" ]; then
-
- coqhammer_CI_REF=fix-tc-search-opacity
- coqhammer_CI_GITURL=https://github.com/ppedrot/coqhammer
-
-fi
diff --git a/dev/ci/user-overlays/12599-ppedrot-rm-deprecated-refiner.sh b/dev/ci/user-overlays/12599-ppedrot-rm-deprecated-refiner.sh
deleted file mode 100644
index c8c5b3ed5a..0000000000
--- a/dev/ci/user-overlays/12599-ppedrot-rm-deprecated-refiner.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12599" ] || [ "$CI_BRANCH" = "rm-deprecated-refiner" ]; then
-
- equations_CI_REF=rm-deprecated-refiner
- equations_CI_GITURL=https://github.com/ppedrot/Coq-Equations
-
-fi
diff --git a/dev/ci/user-overlays/12650-SkySkimmer-rebuild-record.sh b/dev/ci/user-overlays/12650-SkySkimmer-rebuild-record.sh
deleted file mode 100644
index d4c67b03b5..0000000000
--- a/dev/ci/user-overlays/12650-SkySkimmer-rebuild-record.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12650" ] || [ "$CI_BRANCH" = "rebuild-record" ]; then
-
- elpi_CI_REF=rebuild-record
- elpi_CI_GITURL=https://github.com/SkySkimmer/coq-elpi
-
-fi
diff --git a/dev/ci/user-overlays/12709-ppedrot-hint-pattern-out.sh b/dev/ci/user-overlays/12709-ppedrot-hint-pattern-out.sh
deleted file mode 100644
index 56a69abbf7..0000000000
--- a/dev/ci/user-overlays/12709-ppedrot-hint-pattern-out.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12709" ] || [ "$CI_BRANCH" = "hint-pattern-out" ]; then
-
- coqhammer_CI_REF=hint-pattern-out
- coqhammer_CI_GITURL=https://github.com/ppedrot/coqhammer
-
-fi
diff --git a/dev/ci/user-overlays/12720-ppedrot-factor-class-hint-clenv.sh b/dev/ci/user-overlays/12720-ppedrot-factor-class-hint-clenv.sh
deleted file mode 100644
index e57f95ef19..0000000000
--- a/dev/ci/user-overlays/12720-ppedrot-factor-class-hint-clenv.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12720" ] || [ "$CI_BRANCH" = "factor-class-hint-clenv" ]; then
-
- coqhammer_CI_REF=factor-class-hint-clenv
- coqhammer_CI_GITURL=https://github.com/ppedrot/coqhammer
-
-fi
diff --git a/dev/ci/user-overlays/12756-jashug-dont-refresh-argument-names.sh b/dev/ci/user-overlays/12756-jashug-dont-refresh-argument-names.sh
deleted file mode 100644
index 54fdd87566..0000000000
--- a/dev/ci/user-overlays/12756-jashug-dont-refresh-argument-names.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12756" ] || [ "$CI_BRANCH" = "dont-refresh-argument-names" ]; then
-
- mathcomp_CI_REF=dont-refresh-argument-names-overlay
- mathcomp_CI_GITURL=https://github.com/jashug/math-comp
-
- oddorder_CI_REF=dont-refresh-argument-names-overlay
- oddorder_CI_GITURL=https://github.com/jashug/odd-order
-
-fi
diff --git a/dev/ci/user-overlays/12801-VincentSe-CyclicSet.sh b/dev/ci/user-overlays/12801-VincentSe-CyclicSet.sh
deleted file mode 100644
index 6a9cf78687..0000000000
--- a/dev/ci/user-overlays/12801-VincentSe-CyclicSet.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12801" ] || [ "$CI_BRANCH" = "CyclicSet" ]; then
-
- bignums_CI_REF=CyclicSet
- bignums_CI_GITURL=https://github.com/VincentSe/bignums
-
- coqprime_CI_REF=CyclicSet
- coqprime_CI_GITURL=https://github.com/VincentSe/coqprime
-fi
diff --git a/dev/ci/user-overlays/12875-herbelin-master+about-print-all-arguments-names.sh b/dev/ci/user-overlays/12875-herbelin-master+about-print-all-arguments-names.sh
deleted file mode 100644
index bb08c13ef3..0000000000
--- a/dev/ci/user-overlays/12875-herbelin-master+about-print-all-arguments-names.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12875" ] || [ "$CI_BRANCH" = "master+about-print-all-arguments-names" ]; then
-
- elpi_CI_REF=coq-master+adapt-coq12875-arguments-pass-name-impargs
- elpi_CI_GITURL=https://github.com/herbelin/coq-elpi
-
-fi
diff --git a/dev/ci/user-overlays/12892-SkySkimmer-update-s-univs.sh b/dev/ci/user-overlays/12892-SkySkimmer-update-s-univs.sh
deleted file mode 100644
index f0878202d3..0000000000
--- a/dev/ci/user-overlays/12892-SkySkimmer-update-s-univs.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12892" ] || [ "$CI_BRANCH" = "update-s-univs" ]; then
-
- elpi_CI_REF=update-s-univs
- elpi_CI_GITURL=https://github.com/SkySkimmer/coq-elpi
-
- equations_CI_REF=update-s-univs
- equations_CI_GITURL=https://github.com/SkySkimmer/Coq-Equations
-
-fi
diff --git a/dev/ci/user-overlays/12968-maximedenes-delay-frozen-evarconv.sh b/dev/ci/user-overlays/12968-maximedenes-delay-frozen-evarconv.sh
deleted file mode 100644
index ee75944a52..0000000000
--- a/dev/ci/user-overlays/12968-maximedenes-delay-frozen-evarconv.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12968" ] || [ "$CI_BRANCH" = "delay-frozen-evarconv" ]; then
-
- equations_CI_REF=delay-frozen-evarconv
- equations_CI_GITURL=https://github.com/maximedenes/Coq-Equations
-
-fi
diff --git a/dev/ci/user-overlays/12977-ppedrot-static-hint-poly.sh b/dev/ci/user-overlays/12977-ppedrot-static-hint-poly.sh
deleted file mode 100644
index 7bed43afe1..0000000000
--- a/dev/ci/user-overlays/12977-ppedrot-static-hint-poly.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "12977" ] || [ "$CI_BRANCH" = "static-hint-poly" ]; then
-
- equations_CI_REF=static-hint-poly
- equations_CI_GITURL=https://github.com/ppedrot/Coq-Equations
-
- fiat_parsers_CI_REF=static-hint-poly
- fiat_parsers_CI_GITURL=https://github.com/ppedrot/fiat
-
-fi
diff --git a/dev/ci/user-overlays/13028-herbelin-master+fix-quotations-printing.sh b/dev/ci/user-overlays/13028-herbelin-master+fix-quotations-printing.sh
deleted file mode 100644
index 3407c2db39..0000000000
--- a/dev/ci/user-overlays/13028-herbelin-master+fix-quotations-printing.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "13028" ] || [ "$CI_BRANCH" = "master+fix-quotations-printing" ]; then
-
- equations_CI_REF=master+adapt-coq-pr13028-quotation-qualifier-printing
- equations_CI_GITURL=https://github.com/herbelin/Coq-Equations
-
-fi
diff --git a/dev/ci/user-overlays/13075-ppedrot-explicit-names-quotient.sh b/dev/ci/user-overlays/13075-ppedrot-explicit-names-quotient.sh
new file mode 100644
index 0000000000..8b223719ea
--- /dev/null
+++ b/dev/ci/user-overlays/13075-ppedrot-explicit-names-quotient.sh
@@ -0,0 +1,9 @@
+if [ "$CI_PULL_REQUEST" = "13075" ] || [ "$CI_BRANCH" = "explicit-names-quotient" ]; then
+
+ elpi_CI_REF=explicit-names-quotient
+ elpi_CI_GITURL=https://github.com/ppedrot/coq-elpi
+
+ coq_dpdgraph_CI_REF=explicit-names-quotient
+ coq_dpdgraph_CI_GITURL=https://github.com/ppedrot/coq-dpdgraph
+
+fi
diff --git a/dev/ci/user-overlays/13128-SkySkimmer-noinstance.sh b/dev/ci/user-overlays/13128-SkySkimmer-noinstance.sh
index 654d95f205..f16cf1497e 100644
--- a/dev/ci/user-overlays/13128-SkySkimmer-noinstance.sh
+++ b/dev/ci/user-overlays/13128-SkySkimmer-noinstance.sh
@@ -1,6 +1,5 @@
if [ "$CI_PULL_REQUEST" = "13128" ] || [ "$CI_BRANCH" = "noinstance" ]; then
- elpi_CI_REF=noinstance
- elpi_CI_GITURL=https://github.com/SkySkimmer/coq-elpi
+ overlay elpi https://github.com/SkySkimmer/coq-elpi noinstance
fi
diff --git a/dev/ci/user-overlays/13139-ppedrot-clean-hint-constr.sh b/dev/ci/user-overlays/13139-ppedrot-clean-hint-constr.sh
new file mode 100644
index 0000000000..2f70f43a2b
--- /dev/null
+++ b/dev/ci/user-overlays/13139-ppedrot-clean-hint-constr.sh
@@ -0,0 +1,9 @@
+if [ "$CI_PULL_REQUEST" = "13139" ] || [ "$CI_BRANCH" = "clean-hint-constr" ]; then
+
+ equations_CI_REF=clean-hint-constr
+ equations_CI_GITURL=https://github.com/ppedrot/Coq-Equations
+
+ fiat_parsers_CI_REF=clean-hint-constr
+ fiat_parsers_CI_GITURL=https://github.com/ppedrot/fiat
+
+fi
diff --git a/dev/ci/user-overlays/13166-herbelin-master+fixes13165-missing-impargs-defined-fields.sh b/dev/ci/user-overlays/13166-herbelin-master+fixes13165-missing-impargs-defined-fields.sh
new file mode 100644
index 0000000000..7d55cf6883
--- /dev/null
+++ b/dev/ci/user-overlays/13166-herbelin-master+fixes13165-missing-impargs-defined-fields.sh
@@ -0,0 +1,6 @@
+if [ "$CI_PULL_REQUEST" = "13166" ] || [ "$CI_BRANCH" = "master+fixes13165-missing-impargs-defined-fields" ]; then
+
+ elpi_CI_REF=coq-master+adapt-coq-pr13166-impargs-record-fields
+ elpi_CI_GITURL=https://github.com/herbelin/coq-elpi
+
+fi
diff --git a/dev/ci/user-overlays/8808-herbelin-master+support-binder+term-in-abbrev.sh b/dev/ci/user-overlays/8808-herbelin-master+support-binder+term-in-abbrev.sh
deleted file mode 100644
index 50eaf0b109..0000000000
--- a/dev/ci/user-overlays/8808-herbelin-master+support-binder+term-in-abbrev.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "8808" ] || [ "$CI_BRANCH" = "master+support-binder+term-in-abbrev" ]; then
-
- elpi_CI_REF=master+adapt-coq8808-syndef-same-expressiveness-notation
- elpi_CI_GITURL=https://github.com/herbelin/coq-elpi
-
-fi
diff --git a/dev/ci/user-overlays/8855-herbelin-master+more-search-options.sh b/dev/ci/user-overlays/8855-herbelin-master+more-search-options.sh
deleted file mode 100644
index 3b3b20baf1..0000000000
--- a/dev/ci/user-overlays/8855-herbelin-master+more-search-options.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "8855" ] || [ "$CI_BRANCH" = "master+more-search-options" ]; then
-
- coqhammer_CI_REF=master+adapt-pr8855-search-api
- coqhammer_CI_GITURL=https://github.com/herbelin/coqhammer
-
- coq_dpdgraph_CI_REF=coq-master+adapt-pr8855-search-api
- coq_dpdgraph_CI_GITURL=https://github.com/herbelin/coq-dpdgraph
-
-fi
diff --git a/dev/ci/user-overlays/README.md b/dev/ci/user-overlays/README.md
index 4c2f264a74..3f9ad5e878 100644
--- a/dev/ci/user-overlays/README.md
+++ b/dev/ci/user-overlays/README.md
@@ -4,15 +4,12 @@ When your pull request breaks an external project we test in our CI and you
have prepared a branch with the fix, you can add an "overlay" to your pull
request to test it with the adapted version of the external project.
-An overlay is a file which defines where to look for the patched version so that
-testing is possible. It redefines some variables from
-[`ci-basic-overlay.sh`](../ci-basic-overlay.sh):
-give the name of your branch / commit using a `_CI_REF` variable and the
-location of your fork using a `_CI_GITURL` variable.
-The `_CI_GITURL` variable should be the URL of the repository without a
-trailing `.git`.
-If the fork is not on the same platform (e.g. GitHub instead of GitLab), it is
-necessary to redefine the `_CI_ARCHIVEURL` variable as well.
+An overlay is a file which defines where to look for the patched
+version so that testing is possible. This is done by calling the
+`overlay` command for each project with the project name (as used in
+the variables in [`ci-basic-overlay.sh`](../ci-basic-overlay.sh)), the
+location of your fork and the branch containing the patch on your
+fork.
Moreover, the file contains very simple logic to test the pull request number
or branch name and apply it only in this case.
@@ -21,13 +18,12 @@ The name of your overlay file should start with a five-digit pull request
number, followed by a dash, anything (for instance your GitHub nickname
and the branch name), then a `.sh` extension (`[0-9]{5}-[a-zA-Z0-9-_]+.sh`).
-Example: `10185-SkySkimmer-instance-no-bang.sh` containing
+Example: `13128-SkySkimmer-noinstance.sh` containing
```
-if [ "$CI_PULL_REQUEST" = "10185" ] || [ "$CI_BRANCH" = "instance-no-bang" ]; then
+if [ "$CI_PULL_REQUEST" = "13128" ] || [ "$CI_BRANCH" = "noinstance" ]; then
- quickchick_CI_REF=instance-no-bang
- quickchick_CI_GITURL=https://github.com/SkySkimmer/QuickChick
+ overlay elpi https://github.com/SkySkimmer/coq-elpi noinstance
fi
```
diff --git a/dev/doc/changes.md b/dev/doc/changes.md
index 59c1623a2d..6a6318f97a 100644
--- a/dev/doc/changes.md
+++ b/dev/doc/changes.md
@@ -1,15 +1,35 @@
## Changes between Coq 8.12 and Coq 8.13
-- Tactic language: TacGeneric now takes an argument to tell if it
- comes from a notation. Use `None` if not and `Some foo` to tell to
- print such TacGeneric surrounded with `foo:( )`.
-
### Code formatting
- The automatic code formatting tool `ocamlformat` has been disabled and its
git hook removed. If desired, automatic formatting can be achieved by calling
the `fmt` target of the dune build system.
+### ML API
+
+Abstract syntax of tactic:
+
+- TacGeneric now takes an argument to tell if it comes from a
+ notation. Use `None` if not and `Some foo` to tell to print such
+ TacGeneric surrounded with `foo:( )`.
+
+Printing functions:
+
+- `Pp.h` does not take a `int` argument anymore (the argument was
+ not used). In general, where `h n` for `n` non zero was used, `hv n`
+ was instead intended. If cancelling the breaking role of cuts in the
+ box was intended, turn `h n c` into `h c`.
+
+Grammar entries:
+
+- `Prim.pattern_identref` is deprecated, use `Prim.pattern_ident`
+ which now returns a located identifier.
+
+Generic arguments:
+
+- Generic arguments: `wit_var` is deprecated, use `wit_hyp`.
+
## Changes between Coq 8.11 and Coq 8.12
### Code formatting
diff --git a/dev/doc/parsing.md b/dev/doc/parsing.md
index 4982e3e94d..4956b91d01 100644
--- a/dev/doc/parsing.md
+++ b/dev/doc/parsing.md
@@ -210,7 +210,7 @@ command. The first square bracket around a nonterminal definition is for groupi
level definitions, which are separated with `|`, for example:
```
- tactic_expr:
+ ltac_expr:
[ "5" RIGHTA
[ te = binder_tactic -> { te } ]
| "4" LEFTA
@@ -220,8 +220,8 @@ level definitions, which are separated with `|`, for example:
Grammar extensions can specify what level they are modifying, for example:
```
- tactic_expr: LEVEL "1" [ RIGHTA
- [ tac = tactic_expr; intros = ssrintros_ne -> { tclintros_expr ~loc tac intros }
+ ltac_expr: LEVEL "1" [ RIGHTA
+ [ tac = ltac_expr; intros = ssrintros_ne -> { tclintros_expr ~loc tac intros }
] ];
```
diff --git a/dev/doc/shield-icon.png b/dev/doc/shield-icon.png
index 629e51a819..f4a5b6ff5e 100644
--- a/dev/doc/shield-icon.png
+++ b/dev/doc/shield-icon.png
Binary files differ
diff --git a/dev/tools/create_overlays.sh b/dev/tools/create_overlays.sh
index ad60b1115f..78ed27ba03 100755
--- a/dev/tools/create_overlays.sh
+++ b/dev/tools/create_overlays.sh
@@ -66,8 +66,7 @@ do
make ci-$_CONTRIB_NAME || true
setup_contrib_git $_CONTRIB_DIR $_CONTRIB_GITPUSHURL
- echo " ${_CONTRIB_NAME}_CI_REF=$OVERLAY_BRANCH" >> $OVERLAY_FILE
- echo " ${_CONTRIB_NAME}_CI_GITURL=$_CONTRIB_GITURL" >> $OVERLAY_FILE
+ echo " overlay ${_CONTRIB_NAME} $_CONTRIB_GITURL $OVERLAY_BRANCH" >> $OVERLAY_FILE
echo "" >> $OVERLAY_FILE
shift
done
diff --git a/doc/changelog/01-kernel/12738-fix-sr-cumul-inds.rst b/doc/changelog/01-kernel/12738-fix-sr-cumul-inds.rst
deleted file mode 100644
index 1bf62de3fd..0000000000
--- a/doc/changelog/01-kernel/12738-fix-sr-cumul-inds.rst
+++ /dev/null
@@ -1,5 +0,0 @@
-- **Fixed:** Incompleteness of conversion checking on problems
- involving :ref:`eta-expansion` and :ref:`cumulative universe
- polymorphic inductive types <cumulative>` (`#12738
- <https://github.com/coq/coq/pull/12738>`_, fixes `#7015
- <https://github.com/coq/coq/issues/7015>`_, by Gaëtan Gilbert).
diff --git a/doc/changelog/02-specification-language/10331-minim-prop-toset.rst b/doc/changelog/02-specification-language/10331-minim-prop-toset.rst
new file mode 100644
index 0000000000..6c442ca1aa
--- /dev/null
+++ b/doc/changelog/02-specification-language/10331-minim-prop-toset.rst
@@ -0,0 +1,5 @@
+- **Changed:** Heuristics for universe minimization to :g:`Set`: also
+ use constraints ``Prop <= i`` (`#10331
+ <https://github.com/coq/coq/pull/10331>`_, by Gaëtan Gilbert with
+ help from Maxime Dénès and Matthieu Sozeau, fixes `#12414
+ <https://github.com/coq/coq/issues/12414>`_).
diff --git a/doc/changelog/02-specification-language/12768-master+warn-non-underscore-catch-all-pattern-matching.rst b/doc/changelog/02-specification-language/12768-master+warn-non-underscore-catch-all-pattern-matching.rst
new file mode 100644
index 0000000000..c9e941743c
--- /dev/null
+++ b/doc/changelog/02-specification-language/12768-master+warn-non-underscore-catch-all-pattern-matching.rst
@@ -0,0 +1,7 @@
+- **Added:**
+ Warning on unused variables in pattern-matching branches of
+ :n:`match` serving as catch-all branches for at least two distinct
+ patterns.
+ (`#12768 <https://github.com/coq/coq/pull/12768>`_,
+ fixes `#12762 <https://github.com/coq/coq/issues/12762>`_,
+ by Hugo Herbelin).
diff --git a/doc/changelog/02-specification-language/13166-master+fixes13165-missing-impargs-defined-fields.rst b/doc/changelog/02-specification-language/13166-master+fixes13165-missing-impargs-defined-fields.rst
new file mode 100644
index 0000000000..006989e6b3
--- /dev/null
+++ b/doc/changelog/02-specification-language/13166-master+fixes13165-missing-impargs-defined-fields.rst
@@ -0,0 +1,5 @@
+- **Fixed:**
+ Implicit arguments taken into account in defined fields of a record type declaration
+ (`#13166 <https://github.com/coq/coq/pull/13166>`_,
+ fixes `#13165 <https://github.com/coq/coq/issues/13165>`_,
+ by Hugo Herbelin).
diff --git a/doc/changelog/02-specification-language/13183-using-att.rst b/doc/changelog/02-specification-language/13183-using-att.rst
new file mode 100644
index 0000000000..c380d932ed
--- /dev/null
+++ b/doc/changelog/02-specification-language/13183-using-att.rst
@@ -0,0 +1,6 @@
+- **Added:**
+ Definition and (Co)Fixpoint now support the :attr:`using` attribute.
+ It has the same effect as :cmd:`Proof using`, which is only available in
+ interactive mode.
+ (`#13183 <https://github.com/coq/coq/pull/13183>`_,
+ by Enrico Tassi).
diff --git a/doc/changelog/03-notations/12099-master+constraining-terms-occurring-also-as-pattern-in-notations.rst b/doc/changelog/03-notations/12099-master+constraining-terms-occurring-also-as-pattern-in-notations.rst
new file mode 100644
index 0000000000..e9b02aed6d
--- /dev/null
+++ b/doc/changelog/03-notations/12099-master+constraining-terms-occurring-also-as-pattern-in-notations.rst
@@ -0,0 +1,4 @@
+- **Changed:**
+ Improved support for notations/abbreviations with mixed terms and patterns (such as the forcing modality)
+ (`#12099 <https://github.com/coq/coq/pull/12099>`_,
+ by Hugo Herbelin).
diff --git a/doc/changelog/03-notations/12218-numeral-notations-non-inductive.rst b/doc/changelog/03-notations/12218-numeral-notations-non-inductive.rst
new file mode 100644
index 0000000000..5ea37e7494
--- /dev/null
+++ b/doc/changelog/03-notations/12218-numeral-notations-non-inductive.rst
@@ -0,0 +1,19 @@
+- **Deprecated**
+ ``Numeral.v`` is deprecated, please use ``Number.v`` instead.
+- **Changed**
+ Rational and real constants are parsed differently.
+ The exponent is now encoded separately from the fractional part
+ using ``Z.pow_pos``. This way, parsing large exponents can no longer
+ blow up and constants are printed in a form closer to the one they
+ were parsed (i.e., ``102e-2`` is reprinted as such and not ``1.02``).
+- **Removed**
+ OCaml parser and printer for real constants have been removed.
+ Real constants are now handled with proven Coq code.
+- **Added:**
+ :ref:`Number Notation <number-notations>` and :ref:`String Notation
+ <string-notations>` commands now
+ support parameterized inductive and non inductive types
+ (`#12218 <https://github.com/coq/coq/pull/12218>`_,
+ fixes `#12035 <https://github.com/coq/coq/issues/12035>`_,
+ by Pierre Roux, review by Jason Gross and Jim Fehrle for the
+ reference manual).
diff --git a/doc/changelog/03-notations/12946-master+fix12908-part1-collision-lonely-notation-printing.rst b/doc/changelog/03-notations/12946-master+fix12908-part1-collision-lonely-notation-printing.rst
deleted file mode 100644
index 95a9093272..0000000000
--- a/doc/changelog/03-notations/12946-master+fix12908-part1-collision-lonely-notation-printing.rst
+++ /dev/null
@@ -1,6 +0,0 @@
-- **Fixed:**
- Undetected collision between a lonely notation and a notation in
- scope at printing time
- (`#12946 <https://github.com/coq/coq/pull/12946>`_,
- fixes the first part of `#12908 <https://github.com/coq/coq/issues/12908>`_,
- by Hugo Herbelin).
diff --git a/doc/changelog/03-notations/12950-master+reorganization-notations-only-parsing-only-printing.rst b/doc/changelog/03-notations/12950-master+reorganization-notations-only-parsing-only-printing.rst
new file mode 100644
index 0000000000..16fc91f911
--- /dev/null
+++ b/doc/changelog/03-notations/12950-master+reorganization-notations-only-parsing-only-printing.rst
@@ -0,0 +1,10 @@
+- **Changed:**
+ New model for ``only parsing`` and ``only printing`` notations with
+ support for at most one parsing-and-printing or only-parsing
+ notation per notation and scope, but an arbitrary number of
+ only-printing notations
+ (`#12950 <https://github.com/coq/coq/pull/12950>`_,
+ fixes `#4738 <https://github.com/coq/coq/issues/4738>`_
+ and `#9682 <https://github.com/coq/coq/issues/9682>`_
+ and part 2 of `#12908 <https://github.com/coq/coq/issues/12908>`_,
+ by Hugo Herbelin).
diff --git a/doc/changelog/03-notations/13026-master+fix-printing-custom-no-level-8.2.rst b/doc/changelog/03-notations/13026-master+fix-printing-custom-no-level-8.2.rst
deleted file mode 100644
index 42b62eed75..0000000000
--- a/doc/changelog/03-notations/13026-master+fix-printing-custom-no-level-8.2.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-- **Fixed:**
- Fixing printing of notations in custom entries with
- variables not mentioning an explicit level
- (`#13026 <https://github.com/coq/coq/pull/13026>`_,
- fixes `#12775 <https://github.com/coq/coq/issues/12775>`_
- and `#13018 <https://github.com/coq/coq/issues/13018>`_,
- by Hugo Herbelin).
diff --git a/doc/changelog/03-notations/13067-master+fix-display-parentheses-default-coqide.rst b/doc/changelog/03-notations/13067-master+fix-display-parentheses-default-coqide.rst
deleted file mode 100644
index 50aa4a9052..0000000000
--- a/doc/changelog/03-notations/13067-master+fix-display-parentheses-default-coqide.rst
+++ /dev/null
@@ -1,5 +0,0 @@
-- **Fixed:**
- Repairing option :g:`Display parentheses` in CoqIDE
- (`#12794 <https://github.com/coq/coq/pull/12794>`_ and `#13067 <https://github.com/coq/coq/pull/13067>`_,
- fixes `#12793 <https://github.com/coq/coq/issues/12793>`_,
- by Jean-Christophe Léchenet and Hugo Herbelin).
diff --git a/doc/changelog/03-notations/13092-master+fix-13078-no-binder-in-pattern-notation.rst b/doc/changelog/03-notations/13092-master+fix-13078-no-binder-in-pattern-notation.rst
new file mode 100644
index 0000000000..fb12c91729
--- /dev/null
+++ b/doc/changelog/03-notations/13092-master+fix-13078-no-binder-in-pattern-notation.rst
@@ -0,0 +1,5 @@
+- **Fixed:**
+ Preventing notations for constructors to involve binders
+ (`#13092 <https://github.com/coq/coq/pull/13092>`_,
+ fixes `#13078 <https://github.com/coq/coq/issues/13078>`_,
+ by Hugo Herbelin).
diff --git a/doc/changelog/04-tactics/12648-zify-int63.rst b/doc/changelog/04-tactics/12648-zify-int63.rst
new file mode 100644
index 0000000000..ec7a1273e4
--- /dev/null
+++ b/doc/changelog/04-tactics/12648-zify-int63.rst
@@ -0,0 +1,3 @@
+- **Added:**
+ The :tacn:`zify` tactic provides support for primitive integers (module :g:`ZifyInt63`).
+ (`#12648 <https://github.com/coq/coq/pull/12648>`_, by Frédéric Besson).
diff --git a/doc/changelog/04-tactics/12816-master+fix12787-K-redex-injection-anomaly.rst b/doc/changelog/04-tactics/12816-master+fix12787-K-redex-injection-anomaly.rst
deleted file mode 100644
index 289d17167d..0000000000
--- a/doc/changelog/04-tactics/12816-master+fix12787-K-redex-injection-anomaly.rst
+++ /dev/null
@@ -1,6 +0,0 @@
-- **Fixed:**
- Anomaly with :tacn:`injection` involving artificial
- dependencies disappearing by reduction
- (`#12816 <https://github.com/coq/coq/pull/12816>`_,
- fixes `#12787 <https://github.com/coq/coq/issues/12787>`_,
- by Hugo Herbelin).
diff --git a/doc/changelog/04-tactics/12847-master+inversion-works-with-eq-in-type.rst b/doc/changelog/04-tactics/12847-master+inversion-works-with-eq-in-type.rst
deleted file mode 100644
index b444a2f436..0000000000
--- a/doc/changelog/04-tactics/12847-master+inversion-works-with-eq-in-type.rst
+++ /dev/null
@@ -1,6 +0,0 @@
-- **Added:**
- :tacn:`replace` and :tacn:`inversion` support registration of a
- :g:`core.identity`-like equality in :g:`Type`, such as HoTT's :g:`path`
- (`#12847 <https://github.com/coq/coq/pull/12847>`_,
- partially fixes `#12846 <https://github.com/coq/coq/issues/12846>`_,
- by Hugo Herbelin).
diff --git a/doc/changelog/05-tactic-language/13232-ltac2-if-then-else.rst b/doc/changelog/05-tactic-language/13232-ltac2-if-then-else.rst
new file mode 100644
index 0000000000..d105561a23
--- /dev/null
+++ b/doc/changelog/05-tactic-language/13232-ltac2-if-then-else.rst
@@ -0,0 +1,5 @@
+- **Added:**
+ An if-then-else syntax to Ltac2
+ (`#13232 <https://github.com/coq/coq/pull/13232>`_,
+ fixes `#10110 <https://github.com/coq/coq/issues/10110>`_,
+ by Pierre-Marie Pédrot).
diff --git a/doc/changelog/06-ssreflect/12857-changelog-for-12857.rst b/doc/changelog/06-ssreflect/12857-changelog-for-12857.rst
deleted file mode 100644
index 4350fd0238..0000000000
--- a/doc/changelog/06-ssreflect/12857-changelog-for-12857.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-- **Fixed:**
- Regression in error reporting after :tacn:`case <case (ssreflect)>`.
- A generic error message "Could not fill dependent hole in apply" was
- reported for any error following :tacn:`case <case (ssreflect)>` or
- :tacn:`elim <elim (ssreflect)>`
- (`#12857 <https://github.com/coq/coq/pull/12857>`_,
- fixes `#12837 <https://github.com/coq/coq/issues/12837>`_,
- by Enrico Tassi).
diff --git a/doc/changelog/07-commands-and-options/13139-clean-hint-constr.rst b/doc/changelog/07-commands-and-options/13139-clean-hint-constr.rst
new file mode 100644
index 0000000000..1a6bc88c6c
--- /dev/null
+++ b/doc/changelog/07-commands-and-options/13139-clean-hint-constr.rst
@@ -0,0 +1,6 @@
+- **Changed:**
+ When declaring arbitrary terms as hints, unsolved
+ evars are not abstracted implicitly anymore and instead
+ raise an error
+ (`#13139 <https://github.com/coq/coq/pull/13139>`_,
+ by Pierre-Marie Pédrot).
diff --git a/doc/changelog/07-commands-and-options/13255-master+fix13244-use-coercions-in-search.rst b/doc/changelog/07-commands-and-options/13255-master+fix13244-use-coercions-in-search.rst
new file mode 100644
index 0000000000..03be92f897
--- /dev/null
+++ b/doc/changelog/07-commands-and-options/13255-master+fix13244-use-coercions-in-search.rst
@@ -0,0 +1,7 @@
+- **Added:**
+ Added support for automatic insertion of coercions in :cmd:`Search`
+ patterns. Additionally, head patterns are now automatically
+ interpreted as types
+ (`#13255 <https://github.com/coq/coq/pull/13255>`_,
+ fixes `#13244 <https://github.com/coq/coq/issues/13244>`_,
+ by Hugo Herbelin).
diff --git a/doc/changelog/08-tools/12754-master+fix-coqdoc-index-escaping.rst b/doc/changelog/08-tools/12754-master+fix-coqdoc-index-escaping.rst
deleted file mode 100644
index a05829b720..0000000000
--- a/doc/changelog/08-tools/12754-master+fix-coqdoc-index-escaping.rst
+++ /dev/null
@@ -1,6 +0,0 @@
-- **Fixed:**
- Special symbols now escaped in the index produced by coqdoc,
- avoiding collision with the syntax of the output format
- (`#12754 <https://github.com/coq/coq/pull/12754>`_,
- fixes `#12752 <https://github.com/coq/coq/issues/12752>`_,
- by Hugo Herbelin).
diff --git a/doc/changelog/08-tools/12772-fix-details.rst b/doc/changelog/08-tools/12772-fix-details.rst
deleted file mode 100644
index 67ee061285..0000000000
--- a/doc/changelog/08-tools/12772-fix-details.rst
+++ /dev/null
@@ -1,5 +0,0 @@
-- **Fixed:**
- The `details` environment added in the 8.12 release can now be used
- as advertised in the reference manual
- (`#12772 <https://github.com/coq/coq/pull/12772>`_,
- by Thomas Letan).
diff --git a/doc/changelog/08-tools/13063-fix-no-output-sync-make-file.rst b/doc/changelog/08-tools/13063-fix-no-output-sync-make-file.rst
deleted file mode 100644
index 75b1e26248..0000000000
--- a/doc/changelog/08-tools/13063-fix-no-output-sync-make-file.rst
+++ /dev/null
@@ -1,6 +0,0 @@
-- **Fixed:**
- Targets such as ``print-pretty-timed`` in ``coq_makefile``-made
- ``Makefile``\s no longer error in rare cases where ``--output-sync`` is not
- passed to make and the timing output gets interleaved in just the wrong way
- (`#13063 <https://github.com/coq/coq/pull/13063>`_, fixes `#13062
- <https://github.com/coq/coq/issues/13062>`_, by Jason Gross).
diff --git a/doc/changelog/09-coqide/00000-title.rst b/doc/changelog/09-coqide/00000-title.rst
index 0fc27cf380..c95e2133d6 100644
--- a/doc/changelog/09-coqide/00000-title.rst
+++ b/doc/changelog/09-coqide/00000-title.rst
@@ -1,3 +1,3 @@
-**CoqIDE**
+**|CoqIDE|**
diff --git a/doc/changelog/09-coqide/12874-show_proof_diffs.rst b/doc/changelog/09-coqide/12874-show_proof_diffs.rst
new file mode 100644
index 0000000000..51bebad9be
--- /dev/null
+++ b/doc/changelog/09-coqide/12874-show_proof_diffs.rst
@@ -0,0 +1,5 @@
+- **Added:**
+ Support showing diffs for :cmd:`Show Proof` in CoqIDE from the :n:`View` menu.
+ See :ref:`showing_proof_diffs`.
+ (`#12874 <https://github.com/coq/coq/pull/12874>`_,
+ by Jim Fehrle and Enrico Tassi)
diff --git a/doc/changelog/09-coqide/13145-master+coqide-printing-goal-names-support.rst b/doc/changelog/09-coqide/13145-master+coqide-printing-goal-names-support.rst
new file mode 100644
index 0000000000..f7446cc5aa
--- /dev/null
+++ b/doc/changelog/09-coqide/13145-master+coqide-printing-goal-names-support.rst
@@ -0,0 +1,4 @@
+- **Added:**
+ Support for flag :flag:`Printing Goal Names` in View menu
+ (`#13145 <https://github.com/coq/coq/pull/13145>`_,
+ by Hugo Herbelin).
diff --git a/doc/changelog/11-infrastructure-and-dependencies/12864-fix-approve-output.rst b/doc/changelog/11-infrastructure-and-dependencies/12864-fix-approve-output.rst
deleted file mode 100644
index c754826e62..0000000000
--- a/doc/changelog/11-infrastructure-and-dependencies/12864-fix-approve-output.rst
+++ /dev/null
@@ -1,5 +0,0 @@
-- **Fixed:**
- ``make approve-output`` in the test-suite now correctly handles
- ``output-coqtop`` and ``output-coqchk`` tests (`#12864
- <https://github.com/coq/coq/pull/12864>`_, fixes `#12863
- <https://github.com/coq/coq/issues/12863>`_, by Jason Gross).
diff --git a/doc/changelog/11-infrastructure-and-dependencies/12972-ocaml+4_11.rst b/doc/changelog/11-infrastructure-and-dependencies/12972-ocaml+4_11.rst
deleted file mode 100644
index 855aa360f1..0000000000
--- a/doc/changelog/11-infrastructure-and-dependencies/12972-ocaml+4_11.rst
+++ /dev/null
@@ -1,4 +0,0 @@
-- **Added:**
- Coq is now tested against OCaml 4.11.1
- (`#12972 <https://github.com/coq/coq/pull/12972>`_,
- by Emilio Jesus Gallego Arias).
diff --git a/doc/changelog/11-infrastructure-and-dependencies/13011-sphinx-3.rst b/doc/changelog/11-infrastructure-and-dependencies/13011-sphinx-3.rst
deleted file mode 100644
index d17a2dff6b..0000000000
--- a/doc/changelog/11-infrastructure-and-dependencies/13011-sphinx-3.rst
+++ /dev/null
@@ -1,5 +0,0 @@
-- **Fixed:**
- The reference manual can now build with Sphinx 3
- (`#13011 <https://github.com/coq/coq/pull/13011>`_,
- fixes `#12332 <https://github.com/coq/coq/issues/12332>`_,
- by Théo Zimmermann and Jim Fehrle).
diff --git a/doc/sphinx/_static/coqdoc.css b/doc/sphinx/_static/coqdoc.css
index 32cb0a7a15..c0b4ee4a9f 100644
--- a/doc/sphinx/_static/coqdoc.css
+++ b/doc/sphinx/_static/coqdoc.css
@@ -66,3 +66,7 @@
.coqdoc-tactic {
font-weight: bold;
}
+
+.smallcaps {
+ font-variant: small-caps;
+}
diff --git a/doc/sphinx/_static/diffs-show-proof.png b/doc/sphinx/_static/diffs-show-proof.png
new file mode 100644
index 0000000000..62bd9cccd0
--- /dev/null
+++ b/doc/sphinx/_static/diffs-show-proof.png
Binary files differ
diff --git a/doc/sphinx/addendum/extraction.rst b/doc/sphinx/addendum/extraction.rst
index c2249b8e57..96e115fc3d 100644
--- a/doc/sphinx/addendum/extraction.rst
+++ b/doc/sphinx/addendum/extraction.rst
@@ -16,7 +16,7 @@ Before using any of the commands or options described in this chapter,
the extraction framework should first be loaded explicitly
via ``Require Extraction``, or via the more robust
``From Coq Require Extraction``.
-Note that in earlier versions of Coq, these commands and options were
+Note that in earlier versions of |Coq|, these commands and options were
directly available without any preliminary ``Require``.
.. coqtop:: in
@@ -72,10 +72,10 @@ produce one monolithic file or one file per |Coq| library.
Recursive extraction of all the mentioned objects and all
their dependencies, just as :n:`Extraction @string {+ @qualid }`,
but instead of producing one monolithic file, this command splits
- the produced code in separate ML files, one per corresponding Coq
+ the produced code in separate ML files, one per corresponding |Coq|
``.v`` file. This command is hence quite similar to
:cmd:`Recursive Extraction Library`, except that only the needed
- parts of Coq libraries are extracted instead of the whole.
+ parts of |Coq| libraries are extracted instead of the whole.
The naming convention in case of name clash is the same one as
:cmd:`Extraction Library`: identifiers are here renamed using prefixes
``coq_`` or ``Coq_``.
@@ -99,10 +99,18 @@ Extraction Options
Setting the target language
~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.. cmd:: Extraction Language {| OCaml | Haskell | Scheme | JSON }
+.. cmd:: Extraction Language @language
:name: Extraction Language
- The ability to fix target language is the first and more important
+ .. insertprodn language language
+
+ .. prodn::
+ language ::= OCaml
+ | Haskell
+ | Scheme
+ | JSON
+
+ The ability to fix target language is the first and most important
of the extraction options. Default is ``OCaml``.
The JSON output is mostly for development or debugging:
@@ -138,7 +146,7 @@ and commands:
Default is on. This controls all type-preserving optimizations made on
the ML terms (mostly reduction of dummy beta/iota redexes, but also
simplifications on Cases, etc). Turn this flag off if you want a
- ML term as close as possible to the Coq term.
+ ML term as close as possible to the |Coq| term.
.. flag:: Extraction Conservative Types
@@ -215,14 +223,15 @@ code elimination performed during extraction, in a way which
is independent but complementary to the main elimination
principles of extraction (logical parts and types).
-.. cmd:: Extraction Implicit @qualid [ {+ @ident } ]
+.. cmd:: Extraction Implicit @qualid [ {* {| @ident | @integer } } ]
- This experimental command allows declaring some arguments of
- :token:`qualid` as implicit, i.e. useless in extracted code and hence to
- be removed by extraction. Here :token:`qualid` can be any function or
- inductive constructor, and the given :token:`ident` are the names of
- the concerned arguments. In fact, an argument can also be referred
- by a number indicating its position, starting from 1.
+ Declares some arguments of
+ :token:`qualid` as implicit, meaning that they are useless in extracted code.
+ The extracted code will omit these arguments.
+ Here :token:`qualid` can be
+ any function or inductive constructor, and the :token:`ident`\s are
+ the names of the useless arguments. Arguments can can also be
+ identified positionally by :token:`integer`\s starting from 1.
When an actual extraction takes place, an error is normally raised if the
:cmd:`Extraction Implicit` declarations cannot be honored, that is
@@ -254,12 +263,24 @@ a closed term, and of course the system cannot guess the program which
realizes an axiom. Therefore, it is possible to tell the system
what ML term corresponds to a given axiom.
-.. cmd:: Extract Constant @qualid => @string
+.. cmd:: Extract Constant @qualid {* @string__tv } => {| @ident | @string }
Give an ML extraction for the given constant.
- The :token:`string` may be an identifier or a quoted string.
-.. cmd:: Extract Inlined Constant @qualid => @string
+ :n:`@string__tv`
+ If the type scheme axiom is an arity (a sequence of products followed
+ by a sort), then some type
+ variables have to be given (as quoted strings).
+
+ The number of type variables is checked by the system. For example:
+
+ .. coqtop:: in
+
+ Axiom Y : Set -> Set -> Set.
+ Extract Constant Y "'a" "'b" => " 'a * 'b ".
+
+
+.. cmd:: Extract Inlined Constant @qualid => {| @ident | @string }
Same as the previous one, except that the given ML terms will
be inlined everywhere instead of being declared via a ``let``.
@@ -282,20 +303,6 @@ what ML term corresponds to a given axiom.
Extract Constant X => "int".
Extract Constant x => "0".
-Notice that in the case of type scheme axiom (i.e. whose type is an
-arity, that is a sequence of product finished by a sort), then some type
-variables have to be given (as quoted strings). The syntax is then:
-
-.. cmdv:: Extract Constant @qualid {+ @string } => @string
- :undocumented:
-
-The number of type variables is checked by the system. For example:
-
-.. coqtop:: in
-
- Axiom Y : Set -> Set -> Set.
- Extract Constant Y "'a" "'b" => " 'a * 'b ".
-
Realizing an axiom via :cmd:`Extract Constant` is only useful in the
case of an informative axiom (of sort ``Type`` or ``Set``). A logical axiom
has no computational content and hence will not appear in extracted
@@ -316,36 +323,35 @@ The system also provides a mechanism to specify ML terms for inductive
types and constructors. For instance, the user may want to use the ML
native boolean type instead of the |Coq| one. The syntax is the following:
-.. cmd:: Extract Inductive @qualid => @string__1 [ {+ @string } ]
+.. cmd:: Extract Inductive @qualid => {| @ident | @string } [ {* {| @ident | @string } } ] {? @string__match }
Give an ML extraction for the given inductive type. You must specify
- extractions for the type itself (:n:`@string__1`) and all its
- constructors (all the :n:`@string` between square brackets). In this form,
+ extractions for the type itself (the initial :n:`{| @ident | @string }`) and all its
+ constructors (the :n:`[ {* {| @ident | @string } } ]`). In this form,
the ML extraction must be an ML inductive datatype, and the native
pattern matching of the language will be used.
- When :n:`@string__1` matches the name of the type of characters or strings
+ When the initial :n:`{| @ident | @string }` matches the name of the type of characters or strings
(``char`` and ``string`` for OCaml, ``Prelude.Char`` and ``Prelude.String``
for Haskell), extraction of literals is handled in a specialized way, so as
to generate literals in the target language. This feature requires the type
designated by :n:`@qualid` to be registered as the standard char or string type,
using the :cmd:`Register` command.
-.. cmdv:: Extract Inductive @qualid => @string [ {+ @string } ] @string
-
- Same as before, with a final extra :token:`string` that indicates how to
- perform pattern matching over this inductive type. In this form,
- the ML extraction could be an arbitrary type.
- For an inductive type with :math:`k` constructors, the function used to
- emulate the pattern matching should expect :math:`k+1` arguments, first the :math:`k`
- branches in functional form, and then the inductive element to
- destruct. For instance, the match branch ``| S n => foo`` gives the
- functional form ``(fun n -> foo)``. Note that a constructor with no
- arguments is considered to have one unit argument, in order to block
- early evaluation of the branch: ``| O => bar`` leads to the functional
- form ``(fun () -> bar)``. For instance, when extracting :g:`nat`
- into |OCaml| ``int``, the code to be provided has type:
- ``(unit->'a)->(int->'a)->int->'a``.
+ :n:`@string__match`
+ Indicates how to
+ perform pattern matching over this inductive type. In this form,
+ the ML extraction could be an arbitrary type.
+ For an inductive type with :math:`k` constructors, the function used to
+ emulate the pattern matching should expect :math:`k+1` arguments, first the :math:`k`
+ branches in functional form, and then the inductive element to
+ destruct. For instance, the match branch ``| S n => foo`` gives the
+ functional form ``(fun n -> foo)``. Note that a constructor with no
+ arguments is considered to have one unit argument, in order to block
+ early evaluation of the branch: ``| O => bar`` leads to the functional
+ form ``(fun () -> bar)``. For instance, when extracting :g:`nat`
+ into |OCaml| ``int``, the code to be provided has type:
+ ``(unit->'a)->(int->'a)->int->'a``.
.. caution:: As for :cmd:`Extract Constant`, this command should be used with care:
@@ -434,7 +440,7 @@ Additional settings
Controls which optimizations are used during extraction, providing a finer-grained
control than :flag:`Extraction Optimize`. The bits of :token:`natural` are used as a bit mask.
- Keeping an option off keeps the extracted ML more similar to the Coq term.
+ Keeping an option off keeps the extracted ML more similar to the |Coq| term.
Values are:
+-----+-------+----------------------------------------------------------------+
@@ -465,7 +471,7 @@ Additional settings
.. flag:: Extraction TypeExpand
- If set, fully expand Coq types in ML. See the Coq source code to learn more.
+ If set, fully expand |Coq| types in ML. See the |Coq| source code to learn more.
Differences between |Coq| and ML type systems
----------------------------------------------
@@ -515,7 +521,7 @@ In |OCaml|, we must cast any argument of the constructor dummy
Even with those unsafe castings, you should never get error like
``segmentation fault``. In fact even if your program may seem
ill-typed to the |OCaml| type checker, it can't go wrong : it comes
-from a Coq well-typed terms, so for example inductive types will always
+from a |Coq| well-typed terms, so for example inductive types will always
have the correct number of arguments, etc. Of course, when launching
manually some extracted function, you should apply it to arguments
of the right shape (from the |Coq| point-of-view).
@@ -524,7 +530,7 @@ More details about the correctness of the extracted programs can be
found in :cite:`Let02`.
We have to say, though, that in most "realistic" programs, these problems do not
-occur. For example all the programs of Coq library are accepted by the |OCaml|
+occur. For example all the programs of |Coq| library are accepted by the |OCaml|
type checker without any ``Obj.magic`` (see examples below).
Some examples
diff --git a/doc/sphinx/addendum/generalized-rewriting.rst b/doc/sphinx/addendum/generalized-rewriting.rst
index 759f630b85..407a38378f 100644
--- a/doc/sphinx/addendum/generalized-rewriting.rst
+++ b/doc/sphinx/addendum/generalized-rewriting.rst
@@ -35,7 +35,7 @@ the previous implementation in several ways:
the new implementation, if one provides the proper morphisms. Again,
most of the work is handled in the tactics.
+ First-class morphisms and signatures. Signatures and morphisms are
- ordinary Coq terms, hence they can be manipulated inside Coq, put
+ ordinary |Coq| terms, hence they can be manipulated inside |Coq|, put
inside structures and lemmas about them can be proved inside the
system. Higher-order morphisms are also allowed.
+ Performance. The implementation is based on a depth-first search for
@@ -103,7 +103,7 @@ argument.
Morphisms can also be contravariant in one or more of their arguments.
A morphism is contravariant on an argument associated to the relation
instance :math:`R` if it is covariant on the same argument when the inverse
-relation :math:`R^{−1}` (``inverse R`` in Coq) is considered. The special arrow ``-->``
+relation :math:`R^{−1}` (``inverse R`` in |Coq|) is considered. The special arrow ``-->``
is used in signatures for contravariant morphisms.
Functions having arguments related by symmetric relations instances
@@ -144,7 +144,7 @@ always the intended equality for a given structure.
In the next section we will describe the commands to register terms as
parametric relations and morphisms. Several tactics that deal with
-equality in Coq can also work with the registered relations. The exact
+equality in |Coq| can also work with the registered relations. The exact
list of tactics will be given :ref:`in this section <tactics-enabled-on-user-provided-relations>`.
For instance, the tactic reflexivity can be used to solve a goal ``R n n`` whenever ``R``
is an instance of a registered reflexive relation. However, the
@@ -170,10 +170,17 @@ compatibility constraints.
Adding new relations and morphisms
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.. cmd:: Add Parametric Relation {* @binder } : (A t1 ... tn) (Aeq t′1 ... t′m) {? reflexivity proved by @term} {? symmetry proved by @term} {? transitivity proved by @term} as @ident
+.. cmd:: Add Parametric Relation {* @binder } : @one_term__A @one_term__Aeq {? reflexivity proved by @one_term } {? symmetry proved by @one_term } {? transitivity proved by @one_term } as @ident
- This command declares a parametric relation :g:`Aeq: forall (y1 : β1 ... ym : βm)`,
- :g:`relation (A t1 ... tn)` over :g:`(A : αi -> ... αn -> Type)`.
+ Declares a parametric relation of :n:`@one_term__A`, which is a `Type`, say `T`, with
+ :n:`@one_term__Aeq`, which is a relation on `T`, i.e. of type `(T -> T -> Prop)`.
+ Thus, if :n:`@one_term__A` is
+ :n:`A: forall α__1 … α__n, Type` then :n:`@one_term__Aeq` is
+ :n:`Aeq: forall α__1 … α__n, (A α__1 … α__n) -> (A α__1 … α__n) -> Prop`,
+ or equivalently, :n:`Aeq: forall α__1 … α__n, relation (A α__1 … α__n)`.
+
+ :n:`@one_term__A` and :n:`@one_term__Aeq` must be typeable under the context
+ :token:`binder`\s. In practice, the :token:`binder`\s usually correspond to the :n:`α`\s
The final :token:`ident` gives a unique name to the morphism and it is used
by the command to generate fresh names for automatically provided
@@ -189,16 +196,16 @@ Adding new relations and morphisms
To use this command, you need to first import the module ``Setoid`` using
the command ``Require Import Setoid``.
-.. cmd:: Add Relation
+.. cmd:: Add Relation @one_term @one_term {? reflexivity proved by @one_term } {? symmetry proved by @one_term } {? transitivity proved by @one_term } as @ident
- In case the carrier and relations are not parametric, one can use this command
+ If the carrier and relations are not parametric, use this command
instead, whose syntax is the same except there is no local context.
The proofs of reflexivity, symmetry and transitivity can be omitted if
the relation is not an equivalence relation. The proofs must be
instances of the corresponding relation definitions: e.g. the proof of
reflexivity must have a type convertible to
- :g:`reflexive (A t1 ... tn) (Aeq t′ 1 …t′ n)`.
+ :g:`reflexive (A t1 … tn) (Aeq t′ 1 … t′ n)`.
Each proof may refer to the introduced variables as well.
.. example:: Parametric relation
@@ -219,10 +226,10 @@ replace terms with related ones only in contexts that are syntactic
compositions of parametric morphism instances declared with the
following command.
-.. cmd:: Add Parametric Morphism {* @binder } : (@ident {+ @term__1}) with signature @term__2 as @ident
+.. cmd:: Add Parametric Morphism {* @binder } : @one_term with signature @term as @ident
- This command declares a parametric morphism :n:`@ident {+ @term__1}` of
- signature :n:`@term__2`. The final identifier :token:`ident` gives a unique
+ Declares a parametric morphism :n:`@one_term` of
+ signature :n:`@term`. The final identifier :token:`ident` gives a unique
name to the morphism and it is used as the base name of the typeclass
instance definition and as the name of the lemma that proves the
well-definedness of the morphism. The parameters of the morphism as well as
@@ -525,12 +532,13 @@ counterparts when the relation involved is not Leibniz equality.
Notice, however, that using the prefixed tactics it is possible to
pass additional arguments such as ``using relation``.
-.. tacv:: setoid_reflexivity
- setoid_symmetry {? in @ident}
- setoid_transitivity
- setoid_rewrite {? @orientation} @term {? at @occurrences} {? in @ident}
- setoid_replace @term with @term {? using relation @term} {? in @ident} {? by @ltac_expr3}
- :name: setoid_reflexivity; setoid_symmetry; setoid_transitivity; setoid_rewrite; setoid_replace
+.. tacn:: setoid_reflexivity
+ setoid_symmetry {? in @ident }
+ setoid_transitivity @one_term
+ setoid_rewrite {? {| -> | <- } } @one_term {? with @bindings } {? at @occurrences } {? in @ident }
+ setoid_rewrite {? {| -> | <- } } @one_term {? with @bindings } in @ident at @occurrences
+ setoid_replace @one_term with @one_term {? using relation @one_term } {? in @ident } {? at {+ @int_or_var } } {? by @ltac_expr3 }
+ :name: setoid_reflexivity; setoid_symmetry; setoid_transitivity; setoid_rewrite; _; setoid_replace
The ``using relation`` arguments cannot be passed to the unprefixed form.
The latter argument tells the tactic what parametric relation should
@@ -553,34 +561,35 @@ system up to user defined equalities.
Printing relations and morphisms
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.. cmd:: Print Instances
+Use the :cmd:`Print Instances` command with the class names ``Reflexive``, ``Symmetric``
+or ``Transitive`` to print registered reflexive, symmetric or transitive relations and
+with the class name ``Proper`` to print morphisms.
- This command can be used to show the list of currently
- registered ``Reflexive`` (using ``Print Instances Reflexive``), ``Symmetric``
- or ``Transitive`` relations, Equivalences, PreOrders, PERs, and Morphisms
- (implemented as ``Proper`` instances). When the rewriting tactics refuse
- to replace a term in a context because the latter is not a composition
- of morphisms, the :cmd:`Print Instances` command can be useful to understand
- what additional morphisms should be registered.
+When rewriting tactics refuse
+to replace a term in a context because the latter is not a composition
+of morphisms, this command can be useful to understand
+what additional morphisms should be registered.
.. _deprecated_syntax_for_generalized_rewriting:
Deprecated syntax and backward incompatibilities
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.. cmd:: Add Setoid @qualid__1 @qualid__2 @qualid__3 as @ident
+.. cmd:: Add Setoid @one_term__carrier @one_term__congruence @one_term__proofs as @ident
This command for declaring setoids and morphisms is also accepted due
to backward compatibility reasons.
- Here :n:`@qualid__2` is a congruence relation without parameters, :n:`@qualid__1` is its carrier
- and :n:`@qualid__3` is an object of type (:n:`Setoid_Theory @qualid__1 @qualid__2`) (i.e. a record
+ Here :n:`@one_term__congruence` is a congruence relation without parameters,
+ :n:`@one_term__carrier` is its carrier and :n:`@one_term__proofs` is an object
+ of type (:n:`Setoid_Theory @one_term__carrier @one_term__congruence`) (i.e. a record
packing together the reflexivity, symmetry and transitivity lemmas).
Notice that the syntax is not completely backward compatible since the
identifier was not required.
-.. cmd:: Add Morphism @ident : @ident
- :name: Add Morphism
+.. cmd:: Add Morphism @one_term : @ident
+ Add Morphism @one_term with signature @term as @ident
+ :name: Add Morphism; _
This command is restricted to the declaration of morphisms
without parameters. It is not fully backward compatible since the
@@ -590,11 +599,10 @@ Deprecated syntax and backward incompatibilities
bi-implication in place of a simple implication. In practice, porting
an old development to the new semantics is usually quite simple.
-.. cmd:: Declare Morphism @ident : @ident
+.. cmd:: Declare Morphism @one_term : @ident
:name: Declare Morphism
- This commands is to be used in a module type to declare a parameter that
- is a morphism.
+ Declares a parameter in a module type that is a morphism.
Notice that several limitations of the old implementation have been
lifted. In particular, it is now possible to declare several relations
diff --git a/doc/sphinx/addendum/implicit-coercions.rst b/doc/sphinx/addendum/implicit-coercions.rst
index dafa510ade..b81212ad0d 100644
--- a/doc/sphinx/addendum/implicit-coercions.rst
+++ b/doc/sphinx/addendum/implicit-coercions.rst
@@ -125,10 +125,16 @@ term consists of the successive application of its coercions.
Declaring Coercions
-------------------------
-.. cmd:: Coercion @qualid : @class >-> @class
+.. cmd:: Coercion @reference : @class >-> @class
+ Coercion @ident {? @univ_decl } @def_body
- Declares the construction denoted by :token:`qualid` as a coercion between
- the two given classes.
+ :name: Coercion; _
+
+ The first form declares the construction denoted by :token:`reference` as a coercion between
+ the two given classes. The second form defines :token:`ident`
+ just like :cmd:`Definition` :n:`@ident {? @univ_decl } @def_body`
+ and then declares :token:`ident` as a coercion between it source and its target.
+ Both forms support the :attr:`local` attribute, which makes the coercion local to the current section.
.. exn:: @qualid not declared.
:undocumented:
@@ -174,21 +180,6 @@ Declaring Coercions
circular. When a new circular coercion path is not convertible with the
identity function, it will be reported as ambiguous.
- .. cmdv:: Local Coercion @qualid : @class >-> @class
-
- Declares the construction denoted by :token:`qualid` as a coercion local to
- the current section.
-
- .. cmdv:: Coercion @ident := @term {? @type }
-
- This defines :token:`ident` just like :n:`Definition @ident := term {? @type }`,
- and then declares :token:`ident` as a coercion between it source and its target.
-
- .. cmdv:: Local Coercion @ident := @term {? @type }
-
- This defines :token:`ident` just like :n:`Let @ident := @term {? @type }`,
- and then declares :token:`ident` as a coercion between it source and its target.
-
Some objects can be declared as coercions when they are defined.
This applies to :ref:`assumptions<gallina-assumptions>` and
constructors of :ref:`inductive types and record fields<gallina-inductive-definitions>`.
@@ -205,13 +196,11 @@ Use :n:`:>` instead of :n:`:` before the
function with type :g:`forall (x₁:T₁)..(xₙ:Tₙ)(y:C x₁..xₙ),D t₁..tₘ`,
and we declare it as an identity coercion between ``C`` and ``D``.
+ This command supports the :attr:`local` attribute, which makes the coercion local to the current section.
+
.. exn:: @class must be a transparent constant.
:undocumented:
- .. cmdv:: Local Identity Coercion @ident : @ident >-> @ident
-
- Same as :cmd:`Identity Coercion` but locally to the current section.
-
.. cmd:: SubClass @ident_decl @def_body
:name: SubClass
@@ -223,9 +212,7 @@ Use :n:`:>` instead of :n:`:` before the
:n:`Definition @ident := @type.`
:n:`Identity Coercion Id_@ident_@ident' : @ident >-> @ident'`.
- .. cmdv:: Local SubClass @ident_decl @def_body
-
- Same as before but locally to the current section.
+ This command supports the :attr:`local` attribute, which makes the coercion local to the current section.
Displaying Available Coercions
@@ -268,24 +255,15 @@ Classes as Records
.. index:: :> (coercion)
-We allow the definition of *Structures with Inheritance* (or classes as records)
-by extending the existing :cmd:`Record` macro. Its new syntax is:
-
-.. cmdv:: {| Record | Structure } {? >} @ident {* @binder } : @sort := {? @ident} { {+; @ident :{? >} @term } }
-
- The first identifier :token:`ident` is the name of the defined record and
- :token:`sort` is its type. The optional identifier after ``:=`` is the name
- of the constructor (it will be :n:`Build_@ident` if not given).
- The other identifiers are the names of the fields, and :token:`term`
- are their respective types. If ``:>`` is used instead of ``:`` in
- the declaration of a field, then the name of this field is automatically
- declared as a coercion from the record name to the class of this
- field type. Note that the fields always verify the uniform
- inheritance condition. If the optional ``>`` is given before the
- record name, then the constructor name is automatically declared as
- a coercion from the class of the last field type to the record name
- (this may fail if the uniform inheritance condition is not
- satisfied).
+*Structures with Inheritance* may be defined using the :cmd:`Record` command.
+
+Use `>` before the record name to declare the constructor name as
+a coercion from the class of the last field type to the record name
+(this may fail if the uniform inheritance condition is not
+satisfied). See :token:`record_definition`.
+
+Use `:>` in the field type to declare the field as a coercion from the record name
+to the class of the field type. See :token:`of_type`.
Coercions and Sections
----------------------
diff --git a/doc/sphinx/addendum/micromega.rst b/doc/sphinx/addendum/micromega.rst
index ba5bac6489..2c7b637a42 100644
--- a/doc/sphinx/addendum/micromega.rst
+++ b/doc/sphinx/addendum/micromega.rst
@@ -1,6 +1,6 @@
.. _micromega:
-Micromega: tactics for solving arithmetic goals over ordered rings
+Micromega: solvers for arithmetic goals over ordered rings
==================================================================
:Authors: Frédéric Besson and Evgeny Makarov
@@ -25,8 +25,8 @@ tactics for solving arithmetic goals over :math:`\mathbb{Q}`,
``n`` is an optional integer limiting the proof search depth,
is an incomplete proof procedure for non-linear arithmetic.
It is based on John Harrison’s HOL Light
- driver to the external prover `csdp` [#csdp]_. Note that the `csdp` driver is
- generating a *proof cache* which makes it possible to rerun scripts
+ driver to the external prover `csdp` [#csdp]_. Note that the `csdp` driver
+ generates a *proof cache* which makes it possible to rerun scripts
even without `csdp`.
.. flag:: Simplex
@@ -250,7 +250,7 @@ proof by abstracting monomials by variables.
`psatz`: a proof procedure for non-linear arithmetic
----------------------------------------------------
-.. tacn:: psatz
+.. tacn:: psatz @one_term {? @int_or_var }
:name: psatz
This tactic explores the *Cone* by increasing degrees – hence the
@@ -260,7 +260,7 @@ proof by abstracting monomials by variables.
that might miss a refutation.
To illustrate the working of the tactic, consider we wish to prove the
- following Coq goal:
+ following |Coq| goal:
.. needs csdp
.. coqdoc::
@@ -283,60 +283,103 @@ obtain :math:`-1`. By Theorem :ref:`Psatz <psatz_thm>`, the goal is valid.
.. tacn:: zify
:name: zify
- This tactic is internally called by :tacn:`lia` to support additional types e.g., :g:`nat`, :g:`positive` and :g:`N`.
- By requiring the module ``ZifyBool``, the boolean type :g:`bool` and some comparison operators are also supported.
+ This tactic is internally called by :tacn:`lia` to support additional types, e.g., :g:`nat`, :g:`positive` and :g:`N`.
+ Additional support is provided by the following modules:
+
+ + For boolean operators (e.g., :g:`Nat.leb`), require the module :g:`ZifyBool`.
+ + For comparison operators (e.g., :g:`Z.compare`), require the module :g:`ZifyComparison`.
+ + For native 63 bit integers, require the module :g:`ZifyInt63`.
+
:tacn:`zify` can also be extended by rebinding the tactics `Zify.zify_pre_hook` and `Zify.zify_post_hook` that are
respectively run in the first and the last steps of :tacn:`zify`.
+ To support :g:`Z.div` and :g:`Z.modulo`: ``Ltac Zify.zify_post_hook ::= Z.div_mod_to_equations``.
+ To support :g:`Z.quot` and :g:`Z.rem`: ``Ltac Zify.zify_post_hook ::= Z.quot_rem_to_equations``.
- + To support :g:`Z.div`, :g:`Z.modulo`, :g:`Z.quot`, and :g:`Z.rem`: ``Ltac Zify.zify_post_hook ::= Z.to_euclidean_division_equations``.
+ + To support :g:`Z.div`, :g:`Z.modulo`, :g:`Z.quot` and :g:`Z.rem`: either ``Ltac Zify.zify_post_hook ::= Z.to_euclidean_division_equations`` or ``Ltac Zify.zify_convert_to_euclidean_division_equations_flag ::= constr:(true)``.
The :tacn:`zify` tactic can be extended with new types and operators by declaring and registering new typeclass instances using the following commands.
The typeclass declarations can be found in the module ``ZifyClasses`` and the default instances can be found in the module ``ZifyInst``.
-.. cmd:: Add Zify {| InjTyp | BinOp | UnOp |CstOp | BinRel | UnOpSpec | BinOpSpec } @qualid
+.. cmd:: Add Zify @add_zify @one_term
- This command registers an instance of one of the typeclasses among ``InjTyp``, ``BinOp``, ``UnOp``, ``CstOp``, ``BinRel``,
- ``UnOpSpec``, ``BinOpSpec``.
+ .. insertprodn add_zify add_zify
+
+ .. prodn::
+ add_zify ::= {| InjTyp | BinOp | UnOp | CstOp | BinRel | UnOpSpec | BinOpSpec }
+ | {| PropOp | PropBinOp | PropUOp | Saturate }
-.. cmd:: Show Zify {| InjTyp | BinOp | UnOp |CstOp | BinRel | UnOpSpec | BinOpSpec }
+ Registers an instance of the specified typeclass.
- The command prints the typeclass instances of one the typeclasses
- among ``InjTyp``, ``BinOp``, ``UnOp``, ``CstOp``, ``BinRel``,
- ``UnOpSpec``, ``BinOpSpec``. For instance, :cmd:`Show Zify` ``InjTyp``
+.. cmd:: Show Zify @show_zify
+
+ .. insertprodn show_zify show_zify
+
+ .. prodn::
+ show_zify ::= {| InjTyp | BinOp | UnOp | CstOp | BinRel | UnOpSpec | BinOpSpec | Spec }
+
+ Prints instances for the specified typeclass. For instance, :cmd:`Show Zify` ``InjTyp``
prints the list of types that supported by :tacn:`zify` i.e.,
:g:`Z`, :g:`nat`, :g:`positive` and :g:`N`.
.. cmd:: Show Zify Spec
.. deprecated:: 8.13
- Use instead either :cmd:`Show Zify` ``UnOpSpec`` or :cmd:`Show Zify` ``BinOpSpec``.
+ Use :cmd:`Show Zify` ``UnOpSpec`` or :cmd:`Show Zify` ``BinOpSpec`` instead.
+
+.. cmd:: Add InjTyp @one_term
+
+ .. deprecated:: 8.13
+ Use :cmd:`Add Zify` ``InjTyp`` instead.
+
+.. cmd:: Add BinOp @one_term
+
+ .. deprecated:: 8.13
+ Use :cmd:`Add Zify` ``BinOp`` instead.
+
+.. cmd:: Add BinOpSpec @one_term
+
+ .. deprecated:: 8.13
+ Use :cmd:`Add Zify` ``BinOpSpec`` instead.
+
+.. cmd:: Add UnOp @one_term
+
+ .. deprecated:: 8.13
+ Use :cmd:`Add Zify` ``UnOp`` instead.
+
+.. cmd:: Add UnOpSpec @one_term
+
+ .. deprecated:: 8.13
+ Use :cmd:`Add Zify` ``UnOpSpec`` instead.
+
+.. cmd:: Add CstOp @one_term
+
+ .. deprecated:: 8.13
+ Use :cmd:`Add Zify` ``CstOp`` instead.
-.. cmd:: Add InjTyp
+.. cmd:: Add BinRel @one_term
.. deprecated:: 8.13
- Use instead either :cmd:`Add Zify` ``InjTyp``.
+ Use :cmd:`Add Zify` ``BinRel`` instead.
-.. cmd:: Add BinOp
+.. cmd:: Add PropOp @one_term
.. deprecated:: 8.13
- Use instead either :cmd:`Add Zify` ``BinOp``.
+ Use :cmd:`Add Zify` ``PropOp`` instead.
-.. cmd:: Add UnOp
+.. cmd:: Add PropBinOp @one_term
.. deprecated:: 8.13
- Use instead either :cmd:`Add Zify` ``UnOp``.
+ Use :cmd:`Add Zify` ``PropBinOp`` instead.
-.. cmd:: Add CstOp
+.. cmd:: Add PropUOp @one_term
.. deprecated:: 8.13
- Use instead either :cmd:`Add Zify` ``CstOp``.
+ Use :cmd:`Add Zify` ``PropUOp`` instead.
-.. cmd:: Add BinRel
+.. cmd:: Add Saturate @one_term
.. deprecated:: 8.13
- Use instead either :cmd:`Add Zify` ``BinRel``.
+ Use :cmd:`Add Zify` ``Saturate`` instead.
diff --git a/doc/sphinx/addendum/miscellaneous-extensions.rst b/doc/sphinx/addendum/miscellaneous-extensions.rst
index 0e8660cb0e..3944a34cdc 100644
--- a/doc/sphinx/addendum/miscellaneous-extensions.rst
+++ b/doc/sphinx/addendum/miscellaneous-extensions.rst
@@ -7,10 +7,10 @@ of program refinements. To use the Derive extension it must first be
required with ``Require Coq.derive.Derive``. When the extension is loaded,
it provides the following command:
-.. cmd:: Derive @ident__1 SuchThat @type As @ident__2
+.. cmd:: Derive @ident__1 SuchThat @one_term As @ident__2
- :n:`@ident__1` can appear in :n:`@type`. This command opens a new proof
- presenting the user with a goal for :n:`@type` in which the name :n:`@ident__1` is
+ :n:`@ident__1` can appear in :n:`@one_term`. This command opens a new proof
+ presenting the user with a goal for :n:`@one_term` in which the name :n:`@ident__1` is
bound to an existential variable :g:`?x` (formally, there are other goals
standing for the existential variables but they are shelved, as
described in :tacn:`shelve`).
diff --git a/doc/sphinx/addendum/nsatz.rst b/doc/sphinx/addendum/nsatz.rst
index 8a64a7ed4b..7a2be3dcef 100644
--- a/doc/sphinx/addendum/nsatz.rst
+++ b/doc/sphinx/addendum/nsatz.rst
@@ -1,12 +1,20 @@
.. _nsatz_chapter:
-Nsatz: tactics for proving equalities in integral domains
+Nsatz: a solver for equalities in integral domains
===========================================================
:Author: Loïc Pottier
-.. tacn:: nsatz
- :name: nsatz
+
+To use the tactics described in this section, load the ``Nsatz`` module with the
+command ``Require Import Nsatz``. Alternatively, if you prefer not to transitively depend on the
+files that declare the axioms used to define the real numbers, you can
+``Require Import NsatzTactic`` instead; this will still allow
+:tacn:`nsatz` to solve goals defined about :math:`\mathbb{Z}`,
+:math:`\mathbb{Q}` and any user-registered rings.
+
+
+.. tacn:: nsatz {? with radicalmax := @one_term strategy := @one_term parameters := @one_term variables := @one_term }
This tactic is for solving goals of the form
@@ -32,13 +40,36 @@ Nsatz: tactics for proving equalities in integral domains
doing automatic introductions.
- You can load the ``Nsatz`` module with the command ``Require Import Nsatz``.
+ `radicalmax`
+ bound when searching for r such that
+ :math:`c (P−Q) r = \sum_{i=1..s} S_i (P i − Q i)`.
+ This argument must be of type `N` (binary natural numbers).
- Alternatively, if you prefer not to transitively depend on the
- files declaring the axioms used to define the real numbers, you can
- ``Require Import NsatzTactic`` instead; this will still allow
- :tacn:`nsatz` to solve goals defined about :math:`\mathbb{Z}`,
- :math:`\mathbb{Q}` and any user-registered rings.
+ `strategy`
+ gives the order on variables :math:`X_1,\ldots,X_n` and the strategy
+ used in Buchberger algorithm (see :cite:`sugar` for details):
+
+ * `strategy := 0%Z`: reverse lexicographic order and newest s-polynomial.
+ * `strategy := 1%Z`: reverse lexicographic order and sugar strategy.
+ * `strategy := 2%Z`: pure lexicographic order and newest s-polynomial.
+ * `strategy := 3%Z`: pure lexicographic order and sugar strategy.
+
+ `parameters`
+ a list of parameters of type `R`, containing the variables :math:`X_{i_1},\ldots,X_{i_k}` among
+ :math:`X_1,\ldots,X_n`. Computation will be performed with
+ rational fractions in these parameters, i.e. polynomials have
+ coefficients in :math:`R(X_{i_1},\ldots,X_{i_k})`. In this case, the coefficient
+ :math:`c` can be a nonconstant polynomial in :math:`X_{i_1},\ldots,X_{i_k}`, and the tactic
+ produces a goal which states that :math:`c` is not zero.
+
+ `variables`
+ a list of variables of type `R` in the decreasing order in
+ which they will be used in the Buchberger algorithm. If the list is empty,
+ then `lvar` is replaced by all the variables which are not in
+ `parameters`.
+
+ See the file `Nsatz.v <https://github.com/coq/coq/blob/master/test-suite/success/Nsatz.v>`_
+ for examples, especially in geometry.
More about `nsatz`
---------------------
@@ -63,32 +94,3 @@ Buchberger algorithm.
This computation is done after a step of *reification*, which is
performed using :ref:`typeclasses`.
-
-.. tacv:: nsatz with radicalmax:=@natural%N strategy:=@natural%Z parameters:=[{*, @ident}] variables:=[{*, @ident}]
-
- Most complete syntax for `nsatz`.
-
- * `radicalmax` is a bound when searching for r such that
- :math:`c (P−Q) r = \sum_{i=1..s} S_i (P i − Q i)`
-
- * `strategy` gives the order on variables :math:`X_1,\ldots,X_n` and the strategy
- used in Buchberger algorithm (see :cite:`sugar` for details):
-
- * strategy = 0: reverse lexicographic order and newest s-polynomial.
- * strategy = 1: reverse lexicographic order and sugar strategy.
- * strategy = 2: pure lexicographic order and newest s-polynomial.
- * strategy = 3: pure lexicographic order and sugar strategy.
-
- * `parameters` is the list of variables :math:`X_{i_1},\ldots,X_{i_k}` among
- :math:`X_1,\ldots,X_n` which are considered as parameters: computation will be performed with
- rational fractions in these variables, i.e. polynomials are considered
- with coefficients in :math:`R(X_{i_1},\ldots,X_{i_k})`. In this case, the coefficient
- :math:`c` can be a non constant polynomial in :math:`X_{i_1},\ldots,X_{i_k}`, and the tactic
- produces a goal which states that :math:`c` is not zero.
-
- * `variables` is the list of the variables in the decreasing order in
- which they will be used in the Buchberger algorithm. If `variables` = :g:`(@nil R)`,
- then `lvar` is replaced by all the variables which are not in
- `parameters`.
-
-See the test-suite file `Nsatz.v <https://github.com/coq/coq/blob/master/test-suite/success/Nsatz.v>`_ for many examples, especially in geometry.
diff --git a/doc/sphinx/addendum/omega.rst b/doc/sphinx/addendum/omega.rst
index e1b1ee8e8d..5c08bc44df 100644
--- a/doc/sphinx/addendum/omega.rst
+++ b/doc/sphinx/addendum/omega.rst
@@ -1,6 +1,6 @@
.. _omega_chapter:
-Omega: a solver for quantifier-free problems in Presburger Arithmetic
+Omega: a (deprecated) solver for arithmetic
=====================================================================
:Author: Pierre Crégut
@@ -9,7 +9,7 @@ Omega: a solver for quantifier-free problems in Presburger Arithmetic
The :tacn:`omega` tactic is deprecated in favor of the :tacn:`lia`
tactic. The goal is to consolidate the arithmetic solving
- capabilities of Coq into a single engine; moreover, :tacn:`lia` is
+ capabilities of |Coq| into a single engine; moreover, :tacn:`lia` is
in general more powerful than :tacn:`omega` (it is a complete
Presburger arithmetic solver while :tacn:`omega` was known to be
incomplete).
@@ -143,7 +143,7 @@ Options
.. deprecated:: 8.5
- This deprecated flag (on by default) is for compatibility with Coq pre 8.5. It
+ This deprecated flag (on by default) is for compatibility with |Coq| pre 8.5. It
resets internal name counters to make executions of :tacn:`omega` independent.
.. flag:: Omega UseLocalDefs
diff --git a/doc/sphinx/addendum/program.rst b/doc/sphinx/addendum/program.rst
index c6a4b4fe1a..5da1ac3f46 100644
--- a/doc/sphinx/addendum/program.rst
+++ b/doc/sphinx/addendum/program.rst
@@ -22,7 +22,7 @@ complete |Coq| term. |Program| replaces the |Program| tactic by Catherine
Parent :cite:`Parent95b` which had a similar goal but is no longer maintained.
The languages available as input are currently restricted to |Coq|’s
-term language, but may be extended to OCaml, Haskell and
+term language, but may be extended to |OCaml|, Haskell and
others in the future. We use the same syntax as |Coq| and permit to use
implicit arguments and the existing coercion mechanism. Input terms
and types are typed in an extended system (Russell) and interpreted
@@ -33,7 +33,7 @@ obligations which need to be resolved to create the final term.
.. _elaborating-programs:
Elaborating programs
----------------------
+--------------------
The main difference from |Coq| is that an object in a type :g:`T : Set` can
be considered as an object of type :g:`{x : T | P}` for any well-formed
@@ -83,7 +83,7 @@ coercions.
.. flag:: Program Cases
- This controls the special treatment of pattern matching generating equalities
+ Controls the special treatment of pattern matching generating equalities
and disequalities when using |Program| (it is on by default). All
pattern-matches and let-patterns are handled using the standard algorithm
of |Coq| (see :ref:`extendedpatternmatching`) when this flag is
@@ -91,7 +91,7 @@ coercions.
.. flag:: Program Generalized Coercion
- This controls the coercion of general inductive types when using |Program|
+ Controls the coercion of general inductive types when using |Program|
(the flag is on by default). Coercion of subset types and pairs is still
active in this case.
@@ -104,16 +104,16 @@ coercions.
typechecking.
.. attr:: program
+ :name: program; Program
- This attribute allows to use the Program mode on a specific
+ Allows using the Program mode on a specific
definition. An alternative syntax is to use the legacy ``Program``
- prefix (cf. :n:`@legacy_attr`) as documented in the rest of this
- chapter.
+ prefix (cf. :n:`@legacy_attr`) as it is elsewhere in this chapter.
.. _syntactic_control:
Syntactic control over equalities
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To give more control over the generation of equalities, the
type checker will fall back directly to |Coq|’s usual typing of dependent
@@ -158,36 +158,20 @@ prove some goals to construct the final definitions.
Program Definition
~~~~~~~~~~~~~~~~~~
-.. cmd:: Program Definition @ident := @term
-
- This command types the value term in Russell and generates proof
- obligations. Once solved using the commands shown below, it binds the
- final |Coq| term to the name :n:`@ident` in the environment.
-
- .. exn:: @ident already exists.
- :name: @ident already exists. (Program Definition)
- :undocumented:
-
- .. cmdv:: Program Definition @ident : @type := @term
-
- It interprets the type :n:`@type`, potentially generating proof
- obligations to be resolved. Once done with them, we have a |Coq|
- type :n:`@type__0`. It then elaborates the preterm :n:`@term` into a |Coq|
- term :n:`@term__0`, checking that the type of :n:`@term__0` is coercible to
- :n:`@type__0`, and registers :n:`@ident` as being of type :n:`@type__0` once the
- set of obligations generated during the interpretation of :n:`@term__0`
- and the aforementioned coercion derivation are solved.
-
- .. exn:: In environment … the term: @term does not have type @type. Actually, it has type ...
- :undocumented:
+A :cmd:`Definition` command with the :attr:`program` attribute types
+the value term in Russell and generates proof
+obligations. Once solved using the commands shown below, it binds the
+final |Coq| term to the name :n:`@ident` in the environment.
- .. cmdv:: Program Definition @ident {* @binder } : @type := @term
+:n:`Program Definition @ident : @type := @term`
- This is equivalent to:
-
- :n:`Program Definition @ident : forall {* @binder }, @type := fun {* @binder } => @term`.
-
- .. TODO refer to production in alias
+Interprets the type :n:`@type`, potentially generating proof
+obligations to be resolved. Once done with them, we have a |Coq|
+type :n:`@type__0`. It then elaborates the preterm :n:`@term` into a |Coq|
+term :n:`@term__0`, checking that the type of :n:`@term__0` is coercible to
+:n:`@type__0`, and registers :n:`@ident` as being of type :n:`@type__0` once the
+set of obligations generated during the interpretation of :n:`@term__0`
+and the aforementioned coercion derivation are solved.
.. seealso:: Sections :ref:`vernac-controlling-the-reduction-strategies`, :tacn:`unfold`
@@ -196,20 +180,8 @@ Program Definition
Program Fixpoint
~~~~~~~~~~~~~~~~
-.. cmd:: Program Fixpoint @fix_definition {* with @fix_definition }
-
- The optional :n:`@fixannot` annotation can be one of:
-
- + :g:`measure f R` where :g:`f` is a value of type :g:`X` computed on
- any subset of the arguments and the optional term
- :g:`R` is a relation on :g:`X`. :g:`X` defaults to :g:`nat` and :g:`R`
- to :g:`lt`.
-
- + :g:`wf R x` which is equivalent to :g:`measure x R`.
-
- The structural fixpoint operator behaves just like the one of |Coq| (see
- :cmd:`Fixpoint`), except it may also generate obligations. It works
- with mutually recursive definitions too.
+A :cmd:`Fixpoint` command with the :attr:`program` attribute may also generate obligations. It works
+with mutually recursive definitions too. For example:
.. coqtop:: reset in
@@ -223,6 +195,17 @@ Program Fixpoint
| _ => O
end.
+The :cmd:`Fixpoint` command may include an optional :n:`@fixannot` annotation, which can be:
+
++ :g:`measure f R` where :g:`f` is a value of type :g:`X` computed on
+ any subset of the arguments and the optional term
+ :g:`R` is a relation on :g:`X`. :g:`X` defaults to :g:`nat` and :g:`R`
+ to :g:`lt`.
+
++ :g:`wf R x` which is equivalent to :g:`measure x R`.
+
+.. todo see https://github.com/coq/coq/pull/12936#discussion_r492747830
+
Here we have one obligation for each branch (branches for :g:`0` and
``(S 0)`` are automatically generated by the pattern matching
compilation algorithm).
@@ -246,8 +229,6 @@ using the syntax:
| _ => O
end.
-
-
.. caution:: When defining structurally recursive functions, the generated
obligations should have the prototype of the currently defined
functional in their context. In this case, the obligations should be
@@ -266,67 +247,70 @@ using the syntax:
Program Lemma
~~~~~~~~~~~~~
-.. cmd:: Program Lemma @ident : @type
-
- The Russell language can also be used to type statements of logical
- properties. It will generate obligations, try to solve them
- automatically and fail if some unsolved obligations remain. In this
- case, one can first define the lemma’s statement using :g:`Program
- Definition` and use it as the goal afterwards. Otherwise the proof
- will be started with the elaborated version as a goal. The
- :g:`Program` prefix can similarly be used as a prefix for
- :g:`Variable`, :g:`Hypothesis`, :g:`Axiom` etc.
+A :cmd:`Lemma` command with the :attr:`program` attribute uses the Russell
+language to type statements of logical
+properties. It generates obligations, tries to solve them
+automatically and fails if some unsolved obligations remain. In this
+case, one can first define the lemma’s statement using :cmd:`Definition`
+and use it as the goal afterwards. Otherwise the proof
+will be started with the elaborated version as a goal. The
+:attr:`Program` attribute can similarly be used with
+:cmd:`Variable`, :cmd:`Hypothesis`, :cmd:`Axiom` etc.
.. _solving_obligations:
Solving obligations
---------------------
+-------------------
The following commands are available to manipulate obligations. The
optional identifier is used when multiple functions have unsolved
obligations (e.g. when defining mutually recursive blocks). The
optional tactic is replaced by the default one if not specified.
-.. cmd:: {? {| Local | Global } } Obligation Tactic := @ltac_expr
+.. cmd:: Obligation Tactic := @ltac_expr
:name: Obligation Tactic
Sets the default obligation solving tactic applied to all obligations
automatically, whether to solve them or when starting to prove one,
- e.g. using :g:`Next`. :g:`Local` makes the setting last only for the current
- module. Inside sections, local is the default.
+ e.g. using :cmd:`Next Obligation`.
+
+ This command supports the :attr:`local` and :attr:`global` attributes.
+ :attr:`local` makes the setting last only for the current
+ module. :attr:`local` is the default inside sections while :attr:`global`
+ otherwise.
.. cmd:: Show Obligation Tactic
Displays the current default tactic.
-.. cmd:: Obligations {? of @ident}
+.. cmd:: Obligations {? of @ident }
Displays all remaining obligations.
-.. cmd:: Obligation @natural {? of @ident}
+.. cmd:: Obligation @natural {? of @ident } {? : @type {? with @ltac_expr } }
Start the proof of obligation :token:`natural`.
-.. cmd:: Next Obligation {? of @ident}
+.. cmd:: Next Obligation {? of @ident } {? with @ltac_expr }
Start the proof of the next unsolved obligation.
-.. cmd:: Solve Obligations {? {? of @ident} with @ltac_expr}
+.. cmd:: Solve Obligations {? of @ident } {? with @ltac_expr }
- Tries to solve each obligation of ``ident`` using the given ``tactic`` or the default one.
+ Tries to solve each obligation of :token:`ident` using the given :token:`ltac_expr` or the default one.
-.. cmd:: Solve All Obligations {? with @ltac_expr}
+.. cmd:: Solve All Obligations {? with @ltac_expr }
Tries to solve each obligation of every program using the given
tactic or the default one (useful for mutually recursive definitions).
-.. cmd:: Admit Obligations {? of @ident}
+.. cmd:: Admit Obligations {? of @ident }
- Admits all obligations (of ``ident``).
+ Admits all obligations (of :token:`ident`).
.. note:: Does not work with structurally recursive programs.
-.. cmd:: Preterm {? of @ident}
+.. cmd:: Preterm {? of @ident }
Shows the term that will be fed to the kernel once the obligations
are solved. Useful for debugging.
diff --git a/doc/sphinx/addendum/ring.rst b/doc/sphinx/addendum/ring.rst
index cda8a1b679..027db9f47a 100644
--- a/doc/sphinx/addendum/ring.rst
+++ b/doc/sphinx/addendum/ring.rst
@@ -10,8 +10,8 @@
.. _theringandfieldtacticfamilies:
-The ring and field tactic families
-====================================
+ring and field: solvers for polynomial and rational equations
+=============================================================
:Author: Bruno Barras, Benjamin Grégoire, Assia Mahboubi, Laurent Théry [#f1]_
@@ -99,10 +99,10 @@ Yes, building the variables map and doing the substitution after
normalizing is automatically done by the tactic. So you can just
forget this paragraph and use the tactic according to your intuition.
-Concrete usage in Coq
+Concrete usage in |Coq|
--------------------------
-.. tacn:: ring {? [ {+ @term } ] }
+.. tacn:: ring {? [ {+ @one_term } ] }
Solves polynomical equations of a ring
(or semiring) structure. It proceeds by normalizing both sides
@@ -110,14 +110,35 @@ Concrete usage in Coq
distributivity, constant propagation, rewriting of monomials) and
syntactically comparing the results.
-.. tacn:: ring_simplify {? [ {+ @term } ] } {+ @term } {? in @ident }
+ :n:`[ {+ @one_term } ]`
+ If specified, the tactic decides the equality of two terms modulo ring operations and
+ the equalities defined by the :token:`one_term`\s.
+ Each :token:`one_term` has to be a proof of some equality :g:`m = p`, where :g:`m`
+ is a monomial (after “abstraction”), :g:`p` a polynomial and :g:`=` is the
+ corresponding equality of the ring structure.
+
+.. tacn:: ring_simplify {? [ {+ @one_term } ] } {+ @one_term } {? in @ident }
Applies the normalization procedure described above to
- the given terms. The tactic then replaces all occurrences of the terms
- given in the conclusion of the goal by their normal forms. If no term
+ the given :token:`one_term`\s. The tactic then replaces all occurrences of the :token:`one_term`\s
+ given in the conclusion of the goal by their normal forms. If no :token:`one_term`
is given, then the conclusion should be an equation and both
sides are normalized. The tactic can also be applied in a hypothesis.
+ :n:`in @ident`
+ If specified, the tactic performs the simplification in the hypothesis named :token:`ident`.
+
+ .. note::
+
+ :n:`ring_simplify @one_term__1; ring_simplify @one_term__2` is not equivalent to
+ :n:`ring_simplify @one_term__1 @one_term__2`.
+
+ In the latter case the variables map is shared between the two :token:`one_term`\s, and
+ common subterm :g:`t` of :n:`@one_term__1` and :n:`@one_term__2`
+ will have the same associated variable number. So the first
+ alternative should be avoided for :token:`one_term`\s belonging to the same ring
+ theory.
+
The tactic must be loaded by ``Require Import Ring``. The ring structures
must be declared with the ``Add Ring`` command (see below). The ring of
booleans is predefined; if one wants to use the tactic on |nat| one must
@@ -147,31 +168,6 @@ Concrete usage in Coq
Abort.
-.. tacv:: ring [{* @term }]
-
- This tactic decides the equality of two terms modulo ring operations and
- the equalities defined by the :token:`term`\ s.
- Each :token:`term` has to be a proof of some equality :g:`m = p`, where :g:`m`
- is a monomial (after “abstraction”), :g:`p` a polynomial and :g:`=` the
- corresponding equality of the ring structure.
-
-.. tacv:: ring_simplify [{* @term }] {* @term } in @ident
-
- This tactic performs the simplification in the hypothesis named :token:`ident`.
-
-
-.. note::
-
- :n:`ring_simplify @term__1; ring_simplify @term__2` is not equivalent to
- :n:`ring_simplify @term__1 @term__2`.
-
- In the latter case the variables map is shared between the two terms, and
- common subterm :g:`t` of :n:`@term__1` and :n:`@term__2`
- will have the same associated variable number. So the first
- alternative should be avoided for terms belonging to the same ring
- theory.
-
-
Error messages:
@@ -433,10 +429,10 @@ How does it work?
The code of ``ring`` is a good example of a tactic written using *reflection*.
What is reflection? Basically, using it means that a part of a tactic is written
-in Gallina, Coq's language of terms, rather than |Ltac| or |OCaml|. From the
+in Gallina, |Coq|'s language of terms, rather than |Ltac| or |OCaml|. From the
philosophical point of view, reflection is using the ability of the Calculus of
Constructions to speak and reason about itself. For the ``ring`` tactic we used
-Coq as a programming language and also as a proof environment to build a tactic
+|Coq| as a programming language and also as a proof environment to build a tactic
and to prove its correctness.
The interested reader is strongly advised to have a look at the
@@ -515,15 +511,27 @@ application of the main correctness theorem to well-chosen arguments.
Dealing with fields
------------------------
-.. tacn:: field {? [ {+ @term } ] }
+.. tacn:: field {? [ {+ @one_term } ] }
- This tactic is an extension of the :tacn:`ring` tactic that deals with rational
+ An extension of the :tacn:`ring` tactic that deals with rational
expressions. Given a rational expression :math:`F = 0`. It first reduces the
expression `F` to a common denominator :math:`N/D = 0` where `N` and `D`
are two ring expressions. For example, if we take :math:`F = (1 − 1/x) x − x + 1`, this
gives :math:`N = (x − 1) x − x^2 + x` and :math:`D = x`. It then calls ring to solve
:math:`N = 0`.
+ :n:`[ {+ @one_term } ]`
+ If specified, the tactic decides the equality of two terms modulo
+ field operations and the equalities defined
+ by the :token:`one_term`\s. Each :token:`one_term` has to be a proof of some equality
+ :g:`m = p`, where :g:`m` is a monomial (after “abstraction”), :g:`p` a polynomial
+ and :g:`=` the corresponding equality of the field structure.
+
+ .. note::
+
+ Rewriting works with the equality :g:`m = p` only if :g:`p` is a polynomial since
+ rewriting is handled by the underlying ring tactic.
+
Note that :n:`field` also generates nonzero conditions for all the
denominators it encounters in the reduction. In our example, it
generates the condition :math:`x \neq 0`. These conditions appear as one subgoal
@@ -559,71 +567,36 @@ Dealing with fields
intros x y H H1; field [H1]; auto.
Abort.
-.. tacv:: field [{* @term}]
-
- This tactic decides the equality of two terms modulo
- field operations and the equalities defined
- by the :token:`term`\s. Each :token:`term` has to be a proof of some equality
- :g:`m = p`, where :g:`m` is a monomial (after “abstraction”), :g:`p` a polynomial
- and :g:`=` the corresponding equality of the field structure.
-
-.. note::
-
- Rewriting works with the equality :g:`m = p` only if :g:`p` is a polynomial since
- rewriting is handled by the underlying ring tactic.
-
-.. tacn:: field_simplify {? [ {+ @term } ] } {+ @term } {? in @ident }
+.. tacn:: field_simplify {? [ {+ @one_term__eq } ] } {+ @one_term } {? in @ident }
- performs the simplification in the conclusion of the
+ Performs the simplification in the conclusion of the
goal, :math:`F_1 = F_2` becomes :math:`N_1 / D_1 = N_2 / D_2`. A normalization step
(the same as the one for rings) is then applied to :math:`N_1`, :math:`D_1`,
:math:`N_2` and :math:`D_2`. This way, polynomials remain in factorized form during
fraction simplification. This yields smaller expressions when
reducing to the same denominator since common factors can be canceled.
-.. tacv:: field_simplify [{* @term }]
-
- This variant performs the simplification in the conclusion of the goal using the equalities
- defined by the :token:`term`\s.
-
-.. tacv:: field_simplify [{* @term }] {* @term }
-
- This variant performs the simplification in the terms :token:`term`\s of the conclusion of the goal
- using the equalities defined by :token:`term`\s inside the brackets.
-
-.. tacv:: field_simplify in @ident
-
- This variant performs the simplification in the assumption :token:`ident`.
-
-.. tacv:: field_simplify [{* @term }] in @ident
-
- This variant performs the simplification
- in the assumption :token:`ident` using the equalities defined by the :token:`term`\s.
-
-.. tacv:: field_simplify [{* @term }] {* @term } in @ident
-
- This variant performs the simplification in the :token:`term`\s of the
- assumption :token:`ident` using the
- equalities defined by the :token:`term`\s inside the brackets.
-
-.. tacn:: field_simplify_eq {? [ {+ @term } ] } {? in @ident }
-
- performs the simplification in the conclusion of
- the goal removing the denominator. :math:`F_1 = F_2` becomes :math:`N_1 D_2 = N_2 D_1`.
+ :n:`[ {+ @one_term__eq } ]`
+ Do simplification in the conclusion of the goal using the equalities
+ defined by these :token:`one_term`\s.
-.. tacv:: field_simplify_eq [ {* @term }]
+ :n:`{+ @one_term }`
+ Terms to simplify in the conclusion.
- This variant performs the simplification in
- the conclusion of the goal using the equalities defined by :token:`term`\s.
+ :n:`in @ident`
+ If specified, substitute in the hypothesis :n:`@ident` instead of the conclusion.
-.. tacv:: field_simplify_eq in @ident
+.. tacn:: field_simplify_eq {? [ {+ @one_term } ] } {? in @ident }
- This variant performs the simplification in the assumption :token:`ident`.
+ Performs the simplification in the conclusion of
+ the goal, removing the denominator. :math:`F_1 = F_2` becomes :math:`N_1 D_2 = N_2 D_1`.
-.. tacv:: field_simplify_eq [{* @term}] in @ident
+ :n:`[ {+ @one_term } ]`
+ Do simplification in the conclusion of the goal using the equalities
+ defined by these :token:`one_term`\s.
- This variant performs the simplification in the assumption :token:`ident`
- using the equalities defined by :token:`term`\s and removing the denominator.
+ :n:`in @ident`
+ If specified, simplify in the hypothesis :n:`@ident` instead of the conclusion.
Adding a new field structure
diff --git a/doc/sphinx/addendum/type-classes.rst b/doc/sphinx/addendum/type-classes.rst
index d533470f22..7638fce010 100644
--- a/doc/sphinx/addendum/type-classes.rst
+++ b/doc/sphinx/addendum/type-classes.rst
@@ -13,7 +13,7 @@ Class and Instance declarations
-------------------------------
The syntax for class and instance declarations is the same as the record
-syntax of Coq:
+syntax of |Coq|:
.. coqdoc::
@@ -61,7 +61,7 @@ Note that if you finish the proof with :cmd:`Qed` the entire instance
will be opaque, including the fields given in the initial term.
Alternatively, in :flag:`Program Mode` if one does not give all the
-members in the Instance declaration, Coq generates obligations for the
+members in the Instance declaration, |Coq| generates obligations for the
remaining fields, e.g.:
.. coqtop:: in
@@ -242,7 +242,7 @@ binders. For example:
Definition lt `{eqa : EqDec A, ! Ord eqa} (x y : A) := andb (le x y) (neqb x y).
The ``!`` modifier switches the way a binder is parsed back to the usual
-interpretation of Coq. In particular, it uses the implicit arguments
+interpretation of |Coq|. In particular, it uses the implicit arguments
mechanism if available, as shown in the example.
Substructures
@@ -295,10 +295,29 @@ the Existing Instance command to achieve the same effect.
Summary of the commands
-----------------------
-.. cmd:: Class @inductive_definition {* with @inductive_definition }
+.. cmd:: Class @record_definition
+ Class @singleton_class_definition
- The :cmd:`Class` command is used to declare a typeclass with parameters
- :n:`{* @binder }` and fields the declared record fields.
+ .. insertprodn singleton_class_definition singleton_class_definition
+
+ .. prodn::
+ singleton_class_definition ::= {? > } @ident_decl {* @binder } {? : @sort } := @constructor
+
+ The first form declares a record and makes the record a typeclass with parameters
+ :n:`{* @binder }` and the listed record fields.
+
+ .. _singleton-class:
+
+ The second form declares a *singleton* class with a single method. This
+ singleton class is a so-called definitional class, represented simply
+ as a definition ``ident binders := term`` and whose instances are
+ themselves objects of this type. Definitional classes are not wrapped
+ inside records, and the trivial projection of an instance of such a
+ class is convertible to the instance itself. This can be useful to
+ make instances of existing objects easily and to reduce proof size by
+ not inserting useless projections. The class constant itself is
+ declared rigid during resolution so that the class abstraction is
+ maintained.
Like any command declaring a record, this command supports the
:attr:`universes(polymorphic)`, :attr:`universes(monomorphic)`,
@@ -306,22 +325,7 @@ Summary of the commands
:attr:`universes(cumulative)`, :attr:`universes(noncumulative)` and
:attr:`private(matching)` attributes.
- .. _singleton-class:
-
- .. cmdv:: Class @ident {* @binder } : {? @sort} := @ident : @term
-
- This variant declares a *singleton* class with a single method. This
- singleton class is a so-called definitional class, represented simply
- as a definition ``ident binders := term`` and whose instances are
- themselves objects of this type. Definitional classes are not wrapped
- inside records, and the trivial projection of an instance of such a
- class is convertible to the instance itself. This can be useful to
- make instances of existing objects easily and to reduce proof size by
- not inserting useless projections. The class constant itself is
- declared rigid during resolution so that the class abstraction is
- maintained.
-
- .. cmdv:: Existing Class @ident
+ .. cmd:: Existing Class @qualid
This variant declares a class from a previously declared constant or
inductive definition. No methods or instances are defined.
@@ -330,27 +334,31 @@ Summary of the commands
This command has no effect when used on a typeclass.
-.. cmd:: Instance @ident {* @binder } : @term__0 {+ @term} {? | @natural} := { {*; @field_def} }
+.. cmd:: Instance {? @ident_decl {* @binder } } : @type {? @hint_info } {? {| := %{ {* @field_def } %} | := @term } }
+
+ .. insertprodn hint_info hint_info
- This command is used to declare a typeclass instance named
- :token:`ident` of the class :n:`@term__0` with parameters :token:`term` and
+ .. prodn::
+ hint_info ::= %| {? @natural } {? @one_term }
+
+ Declares a typeclass instance named
+ :token:`ident_decl` of the class :n:`@type` with the specified parameters and with
fields defined by :token:`field_def`, where each field must be a declared field of
the class.
- An arbitrary context of :n:`{* @binder }` can be put after the name of the
- instance and before the colon to declare a parameterized instance. An
- optional priority can be declared, 0 being the highest priority as for
- :tacn:`auto` hints. If the priority :token:`natural` is not specified, it defaults to the number
+ Add one or more :token:`binder`\s to declare a parameterized instance. :token:`hint_info`
+ specifies the hint priority, where 0 is the highest priority as for
+ :tacn:`auto` hints. If the priority is not specified, the default is the number
of non-dependent binders of the instance.
This command supports the :attr:`global` attribute that can be
used on instances declared in a section so that their
- generalization is automatically redeclared after the section is
+ generalization is automatically redeclared when the section is
closed.
Like :cmd:`Definition`, it also supports the :attr:`program`
attribute to switch the type checking to `Program` (chapter
- :ref:`programs`) and use the obligation mechanism to manage missing
+ :ref:`programs`) and to use the obligation mechanism to manage missing
fields.
Finally, it supports the lighter :attr:`refine` attribute:
@@ -362,67 +370,43 @@ Summary of the commands
to fill them. It works exactly as if no body had been given and
the :tacn:`refine` tactic has been used first.
- .. cmdv:: Instance @ident {* @binder } : forall {* @binder }, @term__0 {+ @term} {? | @natural } := @term
-
- This syntax is used for declaration of singleton class instances or
- for directly giving an explicit term of type :n:`forall {* @binder }, @term__0
- {+ @term}`. One need not even mention the unique field name for
- singleton classes.
-
- .. cmdv:: Declare Instance
- :name: Declare Instance
+ .. cmd:: Declare Instance @ident_decl {* @binder } : @term {? @hint_info }
- In a :cmd:`Module Type`, this command states that a corresponding concrete
+ In a :cmd:`Module Type`, declares that a corresponding concrete
instance should exist in any implementation of this :cmd:`Module Type`. This
is similar to the distinction between :cmd:`Parameter` vs. :cmd:`Definition`, or
between :cmd:`Declare Module` and :cmd:`Module`.
-Besides the :cmd:`Class` and :cmd:`Instance` vernacular commands, there are a
-few other commands related to typeclasses.
+ .. cmd:: Existing Instance @qualid {? @hint_info }
+ Existing Instances {+ @qualid } {? %| @natural }
+
+ Adds a constant whose type ends with
+ an applied typeclass to the instance database with an optional
+ priority :token:`natural`. It can be used for redeclaring instances at the end of
+ sections, or declaring structure projections as instances. This is
+ equivalent to ``Hint Resolve ident : typeclass_instances``, except it
+ registers instances for :cmd:`Print Instances`.
+
+.. cmd:: Print Instances @reference
-.. cmd:: Existing Instance {+ @ident} {? | @natural}
+ Shows the list of instances associated with the typeclass :token:`reference`.
- This command adds an arbitrary list of constants whose type ends with
- an applied typeclass to the instance database with an optional
- priority :token:`natural`. It can be used for redeclaring instances at the end of
- sections, or declaring structure projections as instances. This is
- equivalent to ``Hint Resolve ident : typeclass_instances``, except it
- registers instances for :cmd:`Print Instances`.
-.. tacn:: typeclasses eauto
- :name: typeclasses eauto
+.. tacn:: typeclasses eauto {? bfs } {? @int_or_var } {? with {+ @ident } }
- This proof search tactic implements the resolution engine that is run
+ This proof search tactic uses the resolution engine that is run
implicitly during type checking. This tactic uses a different resolution
engine than :tacn:`eauto` and :tacn:`auto`. The main differences are the
following:
- + Contrary to :tacn:`eauto` and :tacn:`auto`, the resolution is done entirely in
- the new proof engine (as of Coq 8.6), meaning that backtracking is
+ + Unlike :tacn:`eauto` and :tacn:`auto`, the resolution is done entirely in
+ the proof engine, meaning that backtracking is
available among dependent subgoals, and shelving goals is supported.
``typeclasses eauto`` is a multi-goal tactic. It analyses the dependencies
between subgoals to avoid backtracking on subgoals that are entirely
independent.
- + When called with no arguments, ``typeclasses eauto`` uses
- the ``typeclass_instances`` database by default (instead of core).
- Dependent subgoals are automatically shelved, and shelved goals can
- remain after resolution ends (following the behavior of Coq 8.5).
-
- .. note::
- As of Coq 8.6, ``all:once (typeclasses eauto)`` faithfully
- mimics what happens during typeclass resolution when it is called
- during refinement/type inference, except that *only* declared class
- subgoals are considered at the start of resolution during type
- inference, while ``all`` can select non-class subgoals as well. It might
- move to ``all:typeclasses eauto`` in future versions when the
- refinement engine will be able to backtrack.
-
- + When called with specific databases (e.g. with), ``typeclasses eauto``
- allows shelved goals to remain at any point during search and treat
- typeclass goals like any other.
-
+ The transparency information of databases is used consistently for
all hints declared in them. It is always used when calling the
unifier. When considering local hypotheses, we use the transparent
@@ -446,26 +430,44 @@ few other commands related to typeclasses.
+ When considering local hypotheses, we use the union of all the modes
declared in the given databases.
- .. tacv:: typeclasses eauto @natural
+ + Use the :cmd:`Typeclasses eauto` command to customize the behavior of
+ this tactic.
- .. warning::
- The semantics for the limit :n:`@natural`
- is different than for auto. By default, if no limit is given, the
- search is unbounded. Contrary to :tacn:`auto`, introduction steps are
- counted, which might result in larger limits being necessary when
- searching with ``typeclasses eauto`` than with :tacn:`auto`.
+ :n:`@int_or_var`
+ Specifies the maximum depth of the search.
- .. tacv:: typeclasses eauto with {+ @ident}
+ .. warning::
+ The semantics for the limit :n:`@int_or_var`
+ are different than for :tacn:`auto`. By default, if no limit is given, the
+ search is unbounded. Unlike :tacn:`auto`, introduction steps count against
+ the limit, which might result in larger limits being necessary when
+ searching with :tacn:`typeclasses eauto` than with :tacn:`auto`.
+
+ :n:`with {+ @ident }`
+ Runs resolution with the specified hint databases. It treats
+ typeclass subgoals the same as other subgoals (no shelving of
+ non-typeclass goals in particular), while allowing shelved goals
+ to remain at any point during search.
+
+ When :n:`with` is not specified, :tacn:`typeclasses eauto` uses
+ the ``typeclass_instances`` database by default (instead of ``core``).
+ Dependent subgoals are automatically shelved, and shelved goals can
+ remain after resolution ends (following the behavior of Coq 8.5).
- This variant runs resolution with the given hint databases. It treats
- typeclass subgoals the same as other subgoals (no shelving of
- non-typeclass goals in particular).
+ .. note::
+ ``all:once (typeclasses eauto)`` faithfully
+ mimics what happens during typeclass resolution when it is called
+ during refinement/type inference, except that *only* declared class
+ subgoals are considered at the start of resolution during type
+ inference, while ``all`` can select non-class subgoals as well. It might
+ move to ``all:typeclasses eauto`` in future versions when the
+ refinement engine will be able to backtrack.
-.. tacn:: autoapply @term with @ident
+.. tacn:: autoapply @one_term with @ident
:name: autoapply
- The tactic ``autoapply`` applies a term using the transparency information
- of the hint database ident, and does *no* typeclass resolution. This can
+ The tactic ``autoapply`` applies :token:`one_term` using the transparency information
+ of the hint database :token:`ident`, and does *no* typeclass resolution. This can
be used in :cmd:`Hint Extern`’s for typeclass instances (in the hint
database ``typeclass_instances``) to allow backtracking on the typeclass
subgoals created by the lemma application, rather than doing typeclass
@@ -476,16 +478,16 @@ few other commands related to typeclasses.
Typeclasses Transparent, Typeclasses Opaque
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.. cmd:: Typeclasses Transparent {+ @ident}
+.. cmd:: Typeclasses Transparent {+ @qualid }
- This command makes the identifiers transparent during typeclass
+ Makes :token:`qualid` transparent during typeclass
resolution.
- Shortcut for :n:`Hint Transparent {+ @ident } : typeclass_instances`.
+ A shortcut for :cmd:`Hint Transparent` :n:`{+ @qualid } : typeclass_instances`
-.. cmd:: Typeclasses Opaque {+ @ident}
+.. cmd:: Typeclasses Opaque {+ @qualid }
- Make the identifiers opaque for typeclass search.
- Shortcut for :n:`Hint Opaque {+ @ident } : typeclass_instances`.
+ Make :token:`qualid` opaque for typeclass search.
+ A shortcut for :cmd:`Hint Opaque` :n:`{+ @qualid } : typeclass_instances`.
It is useful when some constants prevent some unifications and make
resolution fail. It is also useful to declare constants which
@@ -511,13 +513,13 @@ Settings
This flag (off by default) respects the dependency order
between subgoals, meaning that subgoals on which other subgoals depend
come first, while the non-dependent subgoals were put before
- the dependent ones previously (Coq 8.5 and below). This can result in
+ the dependent ones previously (|Coq| 8.5 and below). This can result in
quite different performance behaviors of proof search.
.. flag:: Typeclasses Filtered Unification
- This flag, available since Coq 8.6 and off by default, switches the
+ This flag, which is off by default, switches the
hint application procedure to a filter-then-unify strategy. To apply a
hint, we first check that the goal *matches* syntactically the
inferred or specified pattern of the hint, and only then try to
@@ -601,22 +603,25 @@ Settings
of goals. Setting this option to 1 or 2 turns on the :flag:`Typeclasses Debug` flag; setting this
option to 0 turns that flag off.
-Typeclasses eauto `:=`
-~~~~~~~~~~~~~~~~~~~~~~
+Typeclasses eauto
+~~~~~~~~~~~~~~~~~
-.. cmd:: Typeclasses eauto := {? debug} {? {| (dfs) | (bfs) } } @natural
+.. cmd:: Typeclasses eauto := {? debug } {? ( {| bfs | dfs } ) } {? @natural }
:name: Typeclasses eauto
- This command allows more global customization of the typeclass
- resolution tactic. The semantics of the options are:
+ Allows more global customization of the :tacn:`typeclasses eauto` tactic.
+ The options are:
- + ``debug`` This sets the debug mode. In debug mode, the trace of
- successfully applied tactics is printed. The debug mode can also
+ ``debug``
+ Sets debug mode. In debug mode, a trace of
+ successfully applied tactics is printed. Debug mode can also
be set with :flag:`Typeclasses Debug`.
- + ``(dfs)``, ``(bfs)`` This sets the search strategy to depth-first
+ ``dfs``, ``bfs``
+ Sets the search strategy to depth-first
search (the default) or breadth-first search. The search strategy
can also be set with :flag:`Typeclasses Iterative Deepening`.
- + :token:`natural` This sets the depth limit of the search. The depth
- limit can also be set with :opt:`Typeclasses Depth`.
+ :token:`natural`
+ Sets the depth limit for the search. The limit can also be set with
+ :opt:`Typeclasses Depth`.
diff --git a/doc/sphinx/addendum/universe-polymorphism.rst b/doc/sphinx/addendum/universe-polymorphism.rst
index b0ef792bd1..dd26534ec7 100644
--- a/doc/sphinx/addendum/universe-polymorphism.rst
+++ b/doc/sphinx/addendum/universe-polymorphism.rst
@@ -123,6 +123,7 @@ Polymorphic, Monomorphic
-------------------------
.. attr:: universes(polymorphic)
+ :name: universes(polymorphic); Polymorphic
This attribute can be used to declare universe polymorphic
definitions and inductive types. There is also a legacy syntax
@@ -136,6 +137,7 @@ Polymorphic, Monomorphic
used.
.. attr:: universes(monomorphic)
+ :name: universes(monomorphic); Monomorphic
This attribute can be used to declare universe monomorphic
definitions and inductive types (i.e. global universe constraints
@@ -170,6 +172,7 @@ Cumulative, NonCumulative
-------------------------
.. attr:: universes(cumulative)
+ :name: universes(cumulative); Cumulative
Polymorphic inductive types, coinductive types, variants and
records can be declared cumulative using this attribute or the
@@ -200,6 +203,7 @@ Cumulative, NonCumulative
effect on *monomorphic* inductive definitions.
.. attr:: universes(noncumulative)
+ :name: universes(noncumulative); NonCumulative
Declares the inductive type as non-cumulative even if the
:flag:`Polymorphic Inductive Cumulativity` flag is on. There is
@@ -384,29 +388,26 @@ Explicit Universes
The syntax has been extended to allow users to explicitly bind names
to universes and explicitly instantiate polymorphic definitions.
-.. cmd:: Universe @ident
- Polymorphic Universe @ident
+.. cmd:: Universe {+ @ident }
- In the monorphic case, this command declares a new global universe
- named :token:`ident`, which can be referred to using its qualified name
- as well. Global universe names live in a separate namespace. The
- command supports the :attr:`universes(polymorphic)` attribute (or
- the ``Polymorphic`` prefix) only in sections, meaning the universe
- quantification will be discharged on each section definition
+ In the monomorphic case, declares new global universes
+ with the given names. Global universe names live in a separate namespace.
+ The command supports the :attr:`universes(polymorphic)` attribute (or
+ the ``Polymorphic`` legacy attribute) only in sections, meaning the universe
+ quantification will be discharged for each section definition
independently.
.. exn:: Polymorphic universes can only be declared inside sections, use Monomorphic Universe instead.
:undocumented:
-.. cmd:: Constraint @univ_constraint
- Polymorphic Constraint @univ_constraint
+.. cmd:: Constraint {+, @univ_constraint }
- This command declares a new constraint between named universes.
+ Declares new constraints between named universes.
- If consistent, the constraint is then enforced in the global
+ If consistent, the constraints are then enforced in the global
environment. Like :cmd:`Universe`, it can be used with the
:attr:`universes(polymorphic)` attribute (or the ``Polymorphic``
- prefix) in sections only to declare constraints discharged at
+ legacy attribute) in sections only to declare constraints discharged at
section closing time. One cannot declare a global constraint on
polymorphic universes.
diff --git a/doc/sphinx/appendix/history-and-changes/index.rst b/doc/sphinx/appendix/history-and-changes/index.rst
index 50ffec8e3f..b00a7cdb08 100644
--- a/doc/sphinx/appendix/history-and-changes/index.rst
+++ b/doc/sphinx/appendix/history-and-changes/index.rst
@@ -5,10 +5,10 @@ History and recent changes
==========================
This chapter is divided in two parts. The first one is about the
-:ref:`early history of Coq <history>` and is presented in
+:ref:`early history of |Coq| <history>` and is presented in
chronological order. The second one provides :ref:`release notes
-about recent versions of Coq <changes>` and is presented in reverse
-chronological order. When updating your copy of Coq to a new version
+about recent versions of |Coq| <changes>` and is presented in reverse
+chronological order. When updating your copy of |Coq| to a new version
(especially a new major version), it is strongly recommended that you
read the corresponding release notes. They may contain advice that
will help you understand the differences with the previous version and
diff --git a/doc/sphinx/changes.rst b/doc/sphinx/changes.rst
index af66efa95e..79f00a4a5a 100644
--- a/doc/sphinx/changes.rst
+++ b/doc/sphinx/changes.rst
@@ -34,10 +34,10 @@ The main changes include:
this takes precedence over the now deprecated :ref:`ssreflect search<812SSRSearch>`.
- Many additions and improvements of the :ref:`standard library<812Stdlib>`.
- Improvements to the :ref:`reference manual<812Refman>` include a more logical organization
- of chapters along with updated syntax descriptions that match Coq's grammar
+ of chapters along with updated syntax descriptions that match |Coq|'s grammar
in most but not all chapters.
-Additionally, the :tacn:`omega` tactic is deprecated in this version of Coq,
+Additionally, the :tacn:`omega` tactic is deprecated in this version of |Coq|,
and we recommend users to switch to :tacn:`lia` in new proof scripts (see
also the warning message in the :ref:`corresponding chapter
<omega_chapter>`).
@@ -46,7 +46,7 @@ See the `Changes in 8.12+beta1`_ section and following sections for the
detailed list of changes, including potentially breaking changes marked
with **Changed**.
-Coq's documentation is available at https://coq.github.io/doc/v8.12/refman (reference
+|Coq|'s documentation is available at https://coq.github.io/doc/v8.12/refman (reference
manual), and https://coq.github.io/doc/v8.12/stdlib (documentation of
the standard library). Developer documentation of the ML API is available
at https://coq.github.io/doc/v8.12/api.
@@ -55,8 +55,8 @@ Maxime Dénès, Emilio Jesús Gallego Arias, Gaëtan Gilbert, Michael
Soegtrop and Théo Zimmermann worked on maintaining and improving the
continuous integration system and package building infrastructure.
-Erik Martin-Dorel has maintained the `Coq Docker images
-<https://hub.docker.com/r/coqorg/coq>`_ that are used in many Coq
+Erik Martin-Dorel has maintained the `|Coq| Docker images
+<https://hub.docker.com/r/coqorg/coq>`_ that are used in many |Coq|
projects for continuous integration.
The OPAM repository for |Coq| packages has been maintained by
@@ -64,7 +64,7 @@ Guillaume Claret, Karl Palmskog, Matthieu Sozeau and Enrico Tassi with
contributions from many users. A list of packages is available at
https://coq.inria.fr/opam/www/.
-Previously, most components of Coq had a single principal maintainer.
+Previously, most components of |Coq| had a single principal maintainer.
This was changed in 8.12 (`#11295
<https://github.com/coq/coq/pull/11295>`_) so that every component now has
a team of maintainers, who are in charge of reviewing and
@@ -99,12 +99,12 @@ Nickolai Zeldovich and Théo Zimmermann.
Many power users helped to improve the design of this new version via
the GitHub issue and pull request system, the |Coq| development mailing list
coqdev@inria.fr, the coq-club@inria.fr mailing list, the `Discourse forum
-<https://coq.discourse.group/>`_ and the new `Coq Zulip chat <http://coq.zulipchat.com>`_
+<https://coq.discourse.group/>`_ and the new `|Coq| Zulip chat <http://coq.zulipchat.com>`_
(thanks to Cyril Cohen for organizing the move from Gitter).
Version 8.12's development spanned 6 months from the release of
|Coq| 8.11.0. Emilio Jesus Gallego Arias and Théo Zimmermann are
-the release managers of Coq 8.12. This release is the result of
+the release managers of |Coq| 8.12. This release is the result of
~500 PRs merged, closing ~100 issues.
| Nantes, June 2020,
@@ -131,7 +131,7 @@ Specification language, type inference
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- **Changed:**
- The deprecation warning raised since Coq 8.10 when a trailing
+ The deprecation warning raised since |Coq| 8.10 when a trailing
implicit is declared to be non-maximally inserted (with the command
:cmd:`Arguments`) has been turned into an error
(`#11368 <https://github.com/coq/coq/pull/11368>`_,
@@ -432,7 +432,7 @@ Tactics
fixes `#12210 <https://github.com/coq/coq/issues/12210>`_).
- **Fixed:**
:tacn:`zify` now handles :g:`Z.pow_pos` by default.
- In Coq 8.11, this was the case only when loading module
+ In |Coq| 8.11, this was the case only when loading module
:g:`ZifyPow` because this triggered a regression of :tacn:`lia`.
The regression is now fixed, and the module kept only for compatibility
(`#11362 <https://github.com/coq/coq/pull/11362>`_,
@@ -532,7 +532,7 @@ Flags, options and attributes
by Emilio Jesus Gallego Arias).
- **Removed:**
Unqualified ``polymorphic``, ``monomorphic``, ``template``,
- ``notemplate`` attributes (they were deprecated since Coq 8.10).
+ ``notemplate`` attributes (they were deprecated since |Coq| 8.10).
Use :attr:`universes(polymorphic)`, :attr:`universes(monomorphic)`,
:attr:`universes(template)` and :attr:`universes(notemplate)` instead
(`#11663 <https://github.com/coq/coq/pull/11663>`_, by Théo Zimmermann).
@@ -676,7 +676,7 @@ Tools
involving ``%``) (`#12126
<https://github.com/coq/coq/pull/12126>`_, by Jason Gross).
- **Changed:**
- When passing ``TIMED=1`` to ``make`` with either Coq's own makefile
+ When passing ``TIMED=1`` to ``make`` with either |Coq|'s own makefile
or a ``coq_makefile``\-made makefile, timing information is now
printed for OCaml files as well (`#12211
<https://github.com/coq/coq/pull/12211>`_, by Jason Gross).
@@ -701,7 +701,7 @@ Tools
<https://github.com/coq/coq/pull/12034>`_, by Gaëtan Gilbert).
- **Added:**
A new documentation environment ``details`` to make certain portion
- of a Coq document foldable. See :ref:`coqdoc-hide-show`
+ of a |Coq| document foldable. See :ref:`coqdoc-hide-show`
(`#10592 <https://github.com/coq/coq/pull/10592>`_,
by Thomas Letan).
- **Added:**
@@ -726,7 +726,7 @@ Tools
``--user``) to ``make`` (`#11302
<https://github.com/coq/coq/pull/11302>`_, by Jason Gross).
- **Added:**
- Coq's build system now supports both ``TIMING_FUZZ``,
+ |Coq|'s build system now supports both ``TIMING_FUZZ``,
``TIMING_SORT_BY``, and ``TIMING_REAL`` just like a ``Makefile``
made by ``coq_makefile`` (`#11302
<https://github.com/coq/coq/pull/11302>`_, by Jason Gross).
@@ -742,7 +742,7 @@ Tools
``TIMING_SORT_BY_MEM=1`` (to pass ``--sort-by-mem``) to ``make``
(`#11606 <https://github.com/coq/coq/pull/11606>`_, by Jason Gross).
- **Added:**
- Coq's build system now supports both ``TIMING_INCLUDE_MEM`` and
+ |Coq|'s build system now supports both ``TIMING_INCLUDE_MEM`` and
``TIMING_SORT_BY_MEM`` just like a ``Makefile`` made by
``coq_makefile`` (`#11606 <https://github.com/coq/coq/pull/11606>`_,
by Jason Gross).
@@ -765,7 +765,7 @@ Tools
(`#12091 <https://github.com/coq/coq/pull/12091>`_,
by Hugo Herbelin).
- **Fixed:**
- The various timing targets for Coq's standard library now correctly
+ The various timing targets for |Coq|'s standard library now correctly
display and label the "before" and "after" columns, rather than
mixing them up (`#11302 <https://github.com/coq/coq/pull/11302>`_
fixes `#11301 <https://github.com/coq/coq/issues/11301>`_, by Jason
@@ -799,15 +799,15 @@ Tools
<https://github.com/coq/coq/pull/12388>`_, fixes `#12387
<https://github.com/coq/coq/pull/12387>`_, by Jason Gross).
-CoqIDE
-^^^^^^
+|CoqIDE|
+^^^^^^^^
- **Removed:**
- "Tactic" menu from CoqIDE which had been unmaintained for a number of years
+ "Tactic" menu from |CoqIDE| which had been unmaintained for a number of years
(`#11414 <https://github.com/coq/coq/pull/11414>`_,
by Pierre-Marie Pédrot).
- **Removed:**
- "Revert all buffers" command from CoqIDE which had been broken for a long time
+ "Revert all buffers" command from |CoqIDE| which had been broken for a long time
(`#11415 <https://github.com/coq/coq/pull/11415>`_,
by Pierre-Marie Pédrot).
@@ -1038,7 +1038,7 @@ Extraction
- **Added:**
Support for better extraction of strings in OCaml and Haskell:
- `ExtOcamlNativeString` provides bindings from the Coq `String` type to
+ `ExtOcamlNativeString` provides bindings from the |Coq| `String` type to
the OCaml `string` type, and string literals can be extracted to literals,
both in OCaml and Haskell (`#10486
<https://github.com/coq/coq/pull/10486>`_, by Xavier Leroy, with help from
@@ -1063,7 +1063,7 @@ Reference manual
organization. In the new version, there are fewer top-level
chapters, and, in the HTML format, chapters are split into smaller
pages. This is still a work in progress and further restructuring
- is expected in the next versions of Coq
+ is expected in the next versions of |Coq|
(`CEP#43 <https://github.com/coq/ceps/pull/43>`_, implemented in
`#11601 <https://github.com/coq/coq/pull/11601>`_,
`#11871 <https://github.com/coq/coq/pull/11871>`_,
@@ -1076,7 +1076,7 @@ Reference manual
help and reviews of Jim Fehrle, Clément Pit-Claudel and others).
- **Changed:**
Most of the grammar is now presented using the notation mechanism
- that has been used to present commands and tactics since Coq 8.8 and
+ that has been used to present commands and tactics since |Coq| 8.8 and
which is documented in :ref:`syntax-conventions`
(`#11183 <https://github.com/coq/coq/pull/11183>`_,
`#11314 <https://github.com/coq/coq/pull/11314>`_,
@@ -1141,9 +1141,6 @@ Infrastructure and dependencies
Changes in 8.12.0
~~~~~~~~~~~~~~~~~~~~~
-.. contents::
- :local:
-
**Notations**
- **Added:**
@@ -1201,9 +1198,9 @@ Changes in 8.12.0
fixes `#11970 <https://github.com/coq/coq/issues/11970>`_,
by Pierre-Marie Pédrot).
-**CoqIDE**
+**|CoqIDE|**
-- **Fixed:** CoqIDE no longer exits when trying to open a file whose name is not a valid identifier
+- **Fixed:** |CoqIDE| no longer exits when trying to open a file whose name is not a valid identifier
(`#12562 <https://github.com/coq/coq/pull/12562>`_,
fixes `#10988 <https://github.com/coq/coq/issues/10988>`_,
by Vincent Laporte).
@@ -1216,6 +1213,116 @@ Changes in 8.12.0
modified in the meantime (`#12583 <https://github.com/coq/coq/pull/12583>`_,
fixes `#12582 <https://github.com/coq/coq/issues/12582>`_, by Jason Gross).
+Changes in 8.12.1
+~~~~~~~~~~~~~~~~~~~~~
+
+**Kernel**
+
+- **Fixed:** Incompleteness of conversion checking on problems
+ involving :ref:`eta-expansion` and :ref:`cumulative universe
+ polymorphic inductive types <cumulative>` (`#12738
+ <https://github.com/coq/coq/pull/12738>`_, fixes `#7015
+ <https://github.com/coq/coq/issues/7015>`_, by Gaëtan Gilbert).
+
+**Notations**
+
+- **Fixed:**
+ Undetected collision between a lonely notation and a notation in
+ scope at printing time
+ (`#12946 <https://github.com/coq/coq/pull/12946>`_,
+ fixes the first part of `#12908 <https://github.com/coq/coq/issues/12908>`_,
+ by Hugo Herbelin).
+- **Fixed:**
+ Printing of notations in custom entries with
+ variables not mentioning an explicit level
+ (`#13026 <https://github.com/coq/coq/pull/13026>`_,
+ fixes `#12775 <https://github.com/coq/coq/issues/12775>`_
+ and `#13018 <https://github.com/coq/coq/issues/13018>`_,
+ by Hugo Herbelin).
+
+**Tactics**
+
+- **Added:**
+ :tacn:`replace` and :tacn:`inversion` support registration of a
+ :g:`core.identity`\-like equality in :g:`Type`, such as HoTT's :g:`path`
+ (`#12847 <https://github.com/coq/coq/pull/12847>`_,
+ partially fixes `#12846 <https://github.com/coq/coq/issues/12846>`_,
+ by Hugo Herbelin).
+- **Fixed:**
+ Anomaly with :tacn:`injection` involving artificial
+ dependencies disappearing by reduction
+ (`#12816 <https://github.com/coq/coq/pull/12816>`_,
+ fixes `#12787 <https://github.com/coq/coq/issues/12787>`_,
+ by Hugo Herbelin).
+
+**Tactic language**
+
+- **Fixed:**
+ Miscellaneous issues with locating tactic errors
+ (`#13247 <https://github.com/coq/coq/pull/13247>`_,
+ fixes `#12773 <https://github.com/coq/coq/issues/12773>`_
+ and `#12992 <https://github.com/coq/coq/issues/12992>`_,
+ by Hugo Herbelin).
+
+**SSReflect**
+
+- **Fixed:**
+ Regression in error reporting after :tacn:`case <case (ssreflect)>`.
+ A generic error message "Could not fill dependent hole in apply" was
+ reported for any error following :tacn:`case <case (ssreflect)>` or
+ :tacn:`elim <elim (ssreflect)>`
+ (`#12857 <https://github.com/coq/coq/pull/12857>`_,
+ fixes `#12837 <https://github.com/coq/coq/issues/12837>`_,
+ by Enrico Tassi).
+
+**Commands and options**
+
+- **Fixed:**
+ Failures of :cmd:`Search` in the presence of primitive projections
+ (`#13301 <https://github.com/coq/coq/pull/13301>`_,
+ fixes `#13298 <https://github.com/coq/coq/issues/13298>`_,
+ by Hugo Herbelin).
+
+**Tools**
+
+- **Fixed:**
+ Special symbols now escaped in the index produced by coqdoc,
+ avoiding collision with the syntax of the output format
+ (`#12754 <https://github.com/coq/coq/pull/12754>`_,
+ fixes `#12752 <https://github.com/coq/coq/issues/12752>`_,
+ by Hugo Herbelin).
+- **Fixed:**
+ The `details` environment added in the 8.12 release can now be used
+ as advertised in the reference manual
+ (`#12772 <https://github.com/coq/coq/pull/12772>`_,
+ by Thomas Letan).
+- **Fixed:**
+ Targets such as ``print-pretty-timed`` in ``coq_makefile``\-made
+ ``Makefile``\s no longer error in rare cases where ``--output-sync`` is not
+ passed to make and the timing output gets interleaved in just the wrong way
+ (`#13063 <https://github.com/coq/coq/pull/13063>`_, fixes `#13062
+ <https://github.com/coq/coq/issues/13062>`_, by Jason Gross).
+
+**CoqIDE**
+
+- **Fixed:**
+ View menu "Display parentheses"
+ (`#12794 <https://github.com/coq/coq/pull/12794>`_ and `#13067 <https://github.com/coq/coq/pull/13067>`_,
+ fixes `#12793 <https://github.com/coq/coq/issues/12793>`_,
+ by Jean-Christophe Léchenet and Hugo Herbelin).
+
+**Infrastructure and dependencies**
+
+- **Added:**
+ Coq is now tested against OCaml 4.11.1
+ (`#12972 <https://github.com/coq/coq/pull/12972>`_,
+ by Emilio Jesus Gallego Arias).
+- **Fixed:**
+ The reference manual can now build with Sphinx 3
+ (`#13011 <https://github.com/coq/coq/pull/13011>`_,
+ fixes `#12332 <https://github.com/coq/coq/issues/12332>`_,
+ by Théo Zimmermann and Jim Fehrle).
+
Version 8.11
------------
@@ -1250,7 +1357,7 @@ The main changes brought by |Coq| version 8.11 are:
instances of the constructive and classical real numbers.
Additionally, while the :tacn:`omega` tactic is not yet deprecated in
-this version of Coq, it should soon be the case and we already
+this version of |Coq|, it should soon be the case and we already
recommend users to switch to :tacn:`lia` in new proof scripts (see
also the warning message in the :ref:`corresponding chapter
<omega_chapter>`).
@@ -1260,7 +1367,7 @@ of |Coq| and affected releases. See the `Changes in 8.11+beta1`_
section and following sections for the detailed list of changes,
including potentially breaking changes marked with **Changed**.
-Coq's documentation is available at https://coq.github.io/doc/v8.11/api (documentation of
+|Coq|'s documentation is available at https://coq.github.io/doc/v8.11/api (documentation of
the ML API), https://coq.github.io/doc/v8.11/refman (reference
manual), and https://coq.github.io/doc/v8.11/stdlib (documentation of
the standard library).
@@ -1322,7 +1429,7 @@ Changes in 8.11+beta1
computation. Primitive floats are added in the language of terms,
following the binary64 format of the IEEE 754 standard, and the
related operations are implemented for the different reduction
- engines of Coq by using the corresponding processor operators in
+ engines of |Coq| by using the corresponding processor operators in
rounding-to-nearest-even. The properties of these operators are
axiomatized in the theory :g:`Coq.Floats.FloatAxioms` which is part
of the library :g:`Coq.Floats.Floats`.
@@ -1415,7 +1522,7 @@ Changes in 8.11+beta1
Output of the :cmd:`Print` and :cmd:`About` commands.
Arguments meta-data is now displayed as the corresponding
:cmd:`Arguments` command instead of the
- human-targeted prose used in previous Coq versions. (`#10985
+ human-targeted prose used in previous |Coq| versions. (`#10985
<https://github.com/coq/coq/pull/10985>`_, by Gaëtan Gilbert).
.. _811RefineInstance:
@@ -1463,8 +1570,8 @@ Changes in 8.11+beta1
A simplification of parsing rules could cause a slight change of
parsing precedences for the very rare users who defined notations
with `constr` at level strictly between 100 and 200 and used these
- notations on the right-hand side of a cast operator (`:`, `:>`,
- `:>>`) (`#10963 <https://github.com/coq/coq/pull/10963>`_, by Théo
+ notations on the right-hand side of a cast operator (`:`, `<:`,
+ `<<:`) (`#10963 <https://github.com/coq/coq/pull/10963>`_, by Théo
Zimmermann, simplification initially noticed by Jim Fehrle).
**Tactics**
@@ -1514,7 +1621,7 @@ Changes in 8.11+beta1
- **Added:**
Ltac2, a new version of the tactic language Ltac, that doesn't
- preserve backward compatibility, has been integrated in the main Coq
+ preserve backward compatibility, has been integrated in the main |Coq|
distribution. It is still experimental, but we already recommend
users of advanced Ltac to start using it and report bugs or request
enhancements. See its documentation in the :ref:`dedicated chapter
@@ -1543,14 +1650,14 @@ Changes in 8.11+beta1
Generalize tactics :tacn:`under` and :tacn:`over` for any registered
relation. More precisely, assume the given context lemma has type
`forall f1 f2, .. -> (forall i, R1 (f1 i) (f2 i)) -> R2 f1 f2`. The
- first step performed by :tacn:`under` (since Coq 8.10) amounts to
+ first step performed by :tacn:`under` (since |Coq| 8.10) amounts to
calling the tactic :tacn:`rewrite <rewrite (ssreflect)>`, which
itself relies on :tacn:`setoid_rewrite` if need be. So this step was
already compatible with a double implication or setoid equality for
the conclusion head symbol `R2`. But a further step consists in
tagging the generated subgoal `R1 (f1 i) (?f2 i)` to protect it from
unwanted evar instantiation, and get `Under_rel _ R1 (f1 i) (?f2 i)`
- that is displayed as ``'Under[ f1 i ]``. In Coq 8.10, this second
+ that is displayed as ``'Under[ f1 i ]``. In |Coq| 8.10, this second
(convenience) step was only performed when `R1` was Leibniz' `eq` or
`iff`. Now, it is also performed for any relation `R1` which has a
``RewriteRelation`` instance (a `RelationClasses.Reflexive` instance
@@ -1612,7 +1719,7 @@ Changes in 8.11+beta1
.. warning::
This is a common source of incompatibilities in projects
- migrating to Coq 8.11.
+ migrating to |Coq| 8.11.
- **Changed:**
Output generated by :flag:`Printing Dependent Evars Line` flag
@@ -1643,7 +1750,7 @@ Changes in 8.11+beta1
`coqc` now provides the ability to generate compiled interfaces.
Use `coqc -vos foo.v` to skip all opaque proofs during the
compilation of `foo.v`, and output a file called `foo.vos`.
- This feature is experimental. It enables working on a Coq file without the need to
+ This feature is experimental. It enables working on a |Coq| file without the need to
first compile the proofs contained in its dependencies
(`#8642 <https://github.com/coq/coq/pull/8642>`_ by Arthur Charguéraud, review by
Maxime Dénès and Emilio Gallego).
@@ -1715,7 +1822,7 @@ Changes in 8.11+beta1
**Infrastructure and dependencies**
- **Changed:**
- Coq now officially supports OCaml 4.08.
+ |Coq| now officially supports OCaml 4.08.
See `INSTALL` file for details
(`#10471 <https://github.com/coq/coq/pull/10471>`_,
by Emilio Jesús Gallego Arias).
@@ -1793,7 +1900,7 @@ Changes in 8.11.0
**Tactic language**
- **Fixed:**
- Syntax of tactic `cofix ... with ...` was broken since Coq 8.10
+ Syntax of tactic `cofix ... with ...` was broken since |Coq| 8.10
(`#11241 <https://github.com/coq/coq/pull/11241>`_,
by Hugo Herbelin).
@@ -1826,9 +1933,9 @@ Changes in 8.11.0
fixes `#11353 <https://github.com/coq/coq/issues/11353>`_,
by Karl Palmskog).
-**CoqIDE**
+**|CoqIDE|**
-- **Changed:** CoqIDE now uses the GtkSourceView native implementation
+- **Changed:** |CoqIDE| now uses the GtkSourceView native implementation
of the autocomplete mechanism (`#11400
<https://github.com/coq/coq/pull/11400>`_, by Pierre-Marie Pédrot).
@@ -1874,7 +1981,7 @@ Changes in 8.11.1
(`#11859 <https://github.com/coq/coq/pull/11859>`_,
by Pierre Roux).
-**CoqIDE**
+**|CoqIDE|**
- **Fixed:**
Compiling file paths containing spaces
@@ -1932,21 +2039,21 @@ Changes in 8.11.2
(`#12070 <https://github.com/coq/coq/pull/12070>`_,
by Pierre Roux).
-**CoqIDE**
+**|CoqIDE|**
- **Changed:**
- CoqIDE now uses native window frames by default on Windows.
+ |CoqIDE| now uses native window frames by default on Windows.
The GTK window frames can be restored by setting the `GTK_CSD` environment variable to `1`
(`#12060 <https://github.com/coq/coq/pull/12060>`_,
fixes `#11080 <https://github.com/coq/coq/issues/11080>`_,
by Attila Gáspár).
- **Fixed:**
- New patch presumably fixing the random Coq 8.11 segfault issue with CoqIDE completion
+ New patch presumably fixing the random |Coq| 8.11 segfault issue with |CoqIDE| completion
(`#12068 <https://github.com/coq/coq/pull/12068>`_,
by Hugo Herbelin, presumably fixing
`#11943 <https://github.com/coq/coq/pull/11943>`_).
- **Fixed:**
- Highlighting style consistently applied to all three buffers of CoqIDE
+ Highlighting style consistently applied to all three buffers of |CoqIDE|
(`#12106 <https://github.com/coq/coq/pull/12106>`_,
by Hugo Herbelin; fixes
`#11506 <https://github.com/coq/coq/pull/11506>`_).
@@ -2058,15 +2165,15 @@ reference manual. Here are the most important user-visible changes:
:math:`\Type`. It used to be limited to sort `Prop`
(`#7634 <https://github.com/coq/coq/pull/7634>`_, by Théo Winterhalter).
-- A new registration mechanism for reference from ML code to Coq
+- A new registration mechanism for reference from ML code to |Coq|
constructs has been added
(`#186 <https://github.com/coq/coq/pull/186>`_,
by Emilio Jesús Gallego Arias, Maxime Dénès and Vincent Laporte).
-- CoqIDE:
+- |CoqIDE|:
- - CoqIDE now depends on gtk+3 and lablgtk3 instead of gtk+2 and lablgtk2.
- The INSTALL file available in the Coq sources has been updated to list
+ - |CoqIDE| now depends on gtk+3 and lablgtk3 instead of gtk+2 and lablgtk2.
+ The INSTALL file available in the |Coq| sources has been updated to list
the new dependencies
(`#9279 <https://github.com/coq/coq/pull/9279>`_,
by Hugo Herbelin, with help from Jacques Garrigue,
@@ -2081,15 +2188,15 @@ reference manual. Here are the most important user-visible changes:
- Infrastructure and dependencies:
- - Coq 8.10 requires OCaml >= 4.05.0, bumped from 4.02.3 See the
+ - |Coq| 8.10 requires OCaml >= 4.05.0, bumped from 4.02.3 See the
`INSTALL` file for more information on dependencies
(`#7522 <https://github.com/coq/coq/pull/7522>`_, by Emilio Jesús Gallego Arías).
- - Coq 8.10 doesn't need Camlp5 to build anymore. It now includes a
- fork of the core parsing library that Coq uses, which is a small
+ - |Coq| 8.10 doesn't need Camlp5 to build anymore. It now includes a
+ fork of the core parsing library that |Coq| uses, which is a small
subset of the whole Camlp5 distribution. In particular, this subset
doesn't depend on the OCaml AST, allowing easier compilation and
- testing on experimental OCaml versions. Coq also ships a new parser
+ testing on experimental OCaml versions. |Coq| also ships a new parser
`coqpp` that plugin authors must switch to
(`#7902 <https://github.com/coq/coq/pull/7902>`_,
`#7979 <https://github.com/coq/coq/pull/7979>`_,
@@ -2098,19 +2205,19 @@ reference manual. Here are the most important user-visible changes:
and `#8945 <https://github.com/coq/coq/pull/8945>`_,
by Pierre-Marie Pédrot and Emilio Jesús Gallego Arias).
- The Coq developers would like to thank Daniel de Rauglaudre for many
+ The |Coq| developers would like to thank Daniel de Rauglaudre for many
years of continued support.
- - Coq now supports building with Dune, in addition to the traditional
+ - |Coq| now supports building with Dune, in addition to the traditional
Makefile which is scheduled for deprecation
(`#6857 <https://github.com/coq/coq/pull/6857>`_,
by Emilio Jesús Gallego Arias, with help from Rudi Grinberg).
- Experimental support for building Coq projects has been integrated
+ Experimental support for building |Coq| projects has been integrated
in Dune at the same time, providing an `improved experience
<https://coq.discourse.group/t/a-guide-to-building-your-coq-libraries-and-plugins-with-dune/>`_
for plugin developers. We thank the Dune team for their work
- supporting Coq.
+ supporting |Coq|.
Version 8.10 also comes with a bunch of smaller-scale changes and
improvements regarding the different components of the system, including
@@ -2129,10 +2236,10 @@ contributions from Gaëtan Gilbert, Pierre-Marie Pédrot, and Maxime Dénès.
Maxime Dénès, Emilio Jesús Gallego Arias, Gaëtan Gilbert, Michael
Soegtrop, Théo Zimmermann worked on maintaining and improving the
continuous integration system and package building infrastructure.
-Coq is now continuously tested against OCaml trunk, in addition to the
+|Coq| is now continuously tested against the |OCaml| trunk, in addition to the
oldest supported and latest OCaml releases.
-Coq's documentation for the development branch is now deployed
+|Coq|'s documentation for the development branch is now deployed
continuously at https://coq.github.io/doc/master/api (documentation of
the ML API), https://coq.github.io/doc/master/refman (reference
manual), and https://coq.github.io/doc/master/stdlib (documentation of
@@ -2191,13 +2298,13 @@ Other changes in 8.10+beta1
(*à la* ``-top``) based on the filename passed, taking into account the
proper ``-R``/``-Q`` options. For example, given ``-R Foo foolib`` using
``-topfile foolib/bar.v`` will set the module name to ``Foo.Bar``.
- CoqIDE now properly sets the module name for a given file based on
+ |CoqIDE| now properly sets the module name for a given file based on
its path
(`#8991 <https://github.com/coq/coq/pull/8991>`_,
closes `#8989 <https://github.com/coq/coq/issues/8989>`_,
by Gaëtan Gilbert).
- - Experimental: Coq flags and options can now be set on the
+ - Experimental: |Coq| flags and options can now be set on the
command-line, e.g. ``-set "Universe Polymorphism=true"``
(`#9876 <https://github.com/coq/coq/pull/9876>`_, by Gaëtan Gilbert).
@@ -2295,7 +2402,7 @@ Other changes in 8.10+beta1
- Deprecated compatibility notations have actually been
removed. Uses of these notations are generally easy to fix thanks
- to the hint contained in the deprecation warning emitted by Coq
+ to the hint contained in the deprecation warning emitted by |Coq|
8.8 and 8.9. For projects that require more than a handful of
such fixes, there is `a script
<https://gist.github.com/JasonGross/9770653967de3679d131c59d42de6d17#file-replace-notations-py>`_
@@ -2310,7 +2417,7 @@ Other changes in 8.10+beta1
- The `quote plugin
<https://coq.inria.fr/distrib/V8.9.0/refman/proof-engine/detailed-tactic-examples.html#quote>`_
was removed. If some users are interested in maintaining this plugin
- externally, the Coq development team can provide assistance for
+ externally, the |Coq| development team can provide assistance for
extracting the plugin and setting up a new repository
(`#7894 <https://github.com/coq/coq/pull/7894>`_, by Maxime Dénès).
@@ -2537,7 +2644,7 @@ Other changes in 8.10+beta1
- Changelog has been moved from a specific file `CHANGES.md` to the
reference manual; former Credits chapter of the reference manual has
been split in two parts: a History chapter which was enriched with
- additional historical information about Coq versions 1 to 5, and a
+ additional historical information about |Coq| versions 1 to 5, and a
Changes chapter which was enriched with the content formerly in
`CHANGES.md` and `COMPATIBILITY`
(`#9133 <https://github.com/coq/coq/pull/9133>`_,
@@ -2580,15 +2687,15 @@ Many bug fixes and documentation improvements, in particular:
fixes `#9336 <https://github.com/coq/coq/issues/9336>`_,
by Andreas Lynge, review by Enrico Tassi)
-**CoqIDE**
+**|CoqIDE|**
-- Fix CoqIDE instability on Windows after the update to gtk3
+- Fix |CoqIDE| instability on Windows after the update to gtk3
(`#10360 <https://github.com/coq/coq/pull/10360>`_, by Michael Soegtrop,
closes `#9885 <https://github.com/coq/coq/issues/9885>`_).
**Miscellaneous**
-- Proof General can now display Coq-generated diffs between proof steps
+- Proof General can now display |Coq|-generated diffs between proof steps
in color
(`#10019 <https://github.com/coq/coq/pull/10019>`_ and
(in Proof General) `#421 <https://github.com/ProofGeneral/PG/pull/421>`_,
@@ -2696,7 +2803,7 @@ A few bug fixes and documentation improvements, in particular:
fixes `#10894 <https://github.com/coq/coq/issues/10894>`_,
by Hugo Herbelin).
-**CoqIDE**
+**|CoqIDE|**
- Fix handling of unicode input before space
(`#10852 <https://github.com/coq/coq/pull/10852>`_,
@@ -2736,9 +2843,9 @@ Changes in 8.10.2
(`#11090 <https://github.com/coq/coq/pull/11090>`_,
fixes `#11033 <https://github.com/coq/coq/issues/11033>`_, by Hugo Herbelin).
-**CoqIDE**
+**|CoqIDE|**
-- Fixed uneven dimensions of CoqIDE panels when window has been resized
+- Fixed uneven dimensions of |CoqIDE| panels when window has been resized
(`#11070 <https://github.com/coq/coq/pull/11070>`_,
fixes 8.10-regression `#10956 <https://github.com/coq/coq/issues/10956>`_,
by Guillaume Melquiond).
@@ -2853,7 +2960,7 @@ important ones are documented in the next subsection file.
On the implementation side, the ``dev/doc/changes.md`` file documents
the numerous changes to the implementation and improvements of
interfaces. The file provides guidelines on porting a plugin to the new
-version and a plugin development tutorial kept in sync with Coq was
+version and a plugin development tutorial kept in sync with |Coq| was
introduced by Yves Bertot http://github.com/ybertot/plugin_tutorials.
The new ``dev/doc/critical-bugs`` file documents the known critical bugs
of |Coq| and affected releases.
@@ -2917,7 +3024,7 @@ Notations
entries" (see chapter "Syntax extensions" of the reference manual).
- Deprecated compatibility notations will actually be removed in the
- next version of Coq. Uses of these notations are generally easy to
+ next version of |Coq|. Uses of these notations are generally easy to
fix thanks to the hint contained in the deprecation warnings. For
projects that require more than a handful of such fixes, there is `a
script
@@ -3018,7 +3125,7 @@ Standard Library
- Numeral syntax for `nat` is no longer available without loading the
entire prelude (`Require Import Coq.Init.Prelude`). This only
- impacts users running Coq without the init library (`-nois` or
+ impacts users running |Coq| without the init library (`-nois` or
`-noinit`) and also issuing `Require Import Coq.Init.Datatypes`.
Tools
@@ -3028,10 +3135,10 @@ Tools
`COQFLAGS` is now entirely separate from `COQLIBS`, so in custom Makefiles
`$(COQFLAGS)` should be replaced by `$(COQFLAGS) $(COQLIBS)`.
-- Removed the `gallina` utility (extracts specification from Coq vernacular files).
+- Removed the `gallina` utility (extracts specification from |Coq| vernacular files).
If you would like to maintain this tool externally, please contact us.
-- Removed the Emacs modes distributed with Coq. You are advised to
+- Removed the Emacs modes distributed with |Coq|. You are advised to
use `Proof-General <https://proofgeneral.github.io/>`_ (and optionally
`Company-Coq <https://github.com/cpitclaudel/company-coq>`_) instead.
If your use case is not covered by these alternative Emacs modes,
@@ -3060,15 +3167,15 @@ Vernacular Commands
NoTCResolution`.
- Multiple sections with the same name are allowed.
-Coq binaries and process model
+|Coq| binaries and process model
-- Before 8.9, Coq distributed a single `coqtop` binary and a set of
+- Before 8.9, |Coq| distributed a single `coqtop` binary and a set of
dynamically loadable plugins that used to take over the main loop
for tasks such as IDE language server or parallel proof checking.
These plugins have been turned into full-fledged binaries so each
different process has associated a particular binary now, in
- particular `coqidetop` is the CoqIDE language server, and
+ particular `coqidetop` is the |CoqIDE| language server, and
`coq{proof,tactic,query}worker` are in charge of task-specific and
parallel proof checking.
@@ -3126,7 +3233,7 @@ Changes in 8.8.1
- Some quality-of-life fixes.
- Numerous improvements to the documentation.
- Fix a critical bug related to primitive projections and :tacn:`native_compute`.
-- Ship several additional Coq libraries with the Windows installer.
+- Ship several additional |Coq| libraries with the Windows installer.
Version 8.8
-----------
@@ -3232,7 +3339,7 @@ of everybody who to some extent influenced the development.
The |Coq| consortium, an organization directed towards users and
supporters of the system, is now running and employs Maxime Dénès.
-The contacts of the Coq Consortium are Yves Bertot and Maxime Dénès.
+The contacts of the |Coq| Consortium are Yves Bertot and Maxime Dénès.
| Santiago de Chile, March 2018,
| Matthieu Sozeau for the |Coq| development team
@@ -3354,7 +3461,7 @@ Universes
Tools
-- Coq can now be run with the option -mangle-names to change the auto-generated
+- |Coq| can now be run with the option -mangle-names to change the auto-generated
name scheme. This is intended to function as a linter for developments that
want to be robust to changes in auto-generated names. This feature is experimental,
and may change or disappear without warning.
@@ -3364,7 +3471,7 @@ Checker
- The checker now accepts filenames in addition to logical paths.
-CoqIDE
+|CoqIDE|
- Find and Replace All report the number of occurrences found; Find indicates
when it wraps.
@@ -3377,7 +3484,7 @@ coqdep
Documentation
-- The Coq FAQ, formerly located at https://coq.inria.fr/faq, has been
+- The |Coq| FAQ, formerly located at https://coq.inria.fr/faq, has been
moved to the GitHub wiki section of this repository; the main entry
page is https://github.com/coq/coq/wiki/The-Coq-FAQ.
- Documentation: a large community effort resulted in the migration
@@ -3427,7 +3534,7 @@ Details of changes in 8.8.0
Tools
- Asynchronous proof delegation policy was fixed. Since version 8.7
- Coq was ignoring previous runs and the `-async-proofs-delegation-threshold`
+ |Coq| was ignoring previous runs and the `-async-proofs-delegation-threshold`
option did not have the expected behavior.
Tactic language
@@ -3700,7 +3807,7 @@ Vernacular Commands
- Possibility to unset the printing of notations in a more fine grained
fashion than `Unset Printing Notations` is provided without any
user-syntax. The goal is that someone creates a plugin to experiment
- such a user-syntax, to be later integrated in Coq when stabilized.
+ such a user-syntax, to be later integrated in |Coq| when stabilized.
- `About` now tells if a reference is a coercion.
- The deprecated `Save` vernacular and its form `Save Theorem id` to
close proofs have been removed from the syntax. Please use `Qed`.
@@ -3718,7 +3825,7 @@ Standard Library
- New lemmas about iff and about orders on positive and Z.
- New lemmas on powerRZ.
- Strengthened statement of JMeq_eq_dep (closes bug #4912).
-- The BigN, BigZ, BigZ libraries are no longer part of the Coq standard
+- The BigN, BigZ, BigZ libraries are no longer part of the |Coq| standard
library, they are now provided by a separate repository
https://github.com/coq/bignums
The split has been done just after the Int31 library.
@@ -3732,12 +3839,12 @@ Standard Library
Plugins
-- The Ssreflect plugin is now distributed with Coq. Its documentation has
+- The Ssreflect plugin is now distributed with |Coq|. Its documentation has
been integrated as a chapter of the reference manual. This chapter is
work in progress so feedback is welcome.
- The mathematical proof language (also known as declarative mode) was removed.
- A new command Extraction TestCompile has been introduced, not meant
- for the general user but instead for Coq's test-suite.
+ for the general user but instead for |Coq|'s test-suite.
- The extraction plugin is no longer loaded by default. It must be
explicitly loaded with [Require Extraction], which is backwards
compatible.
@@ -3756,7 +3863,7 @@ Tools
the extensibility of generated Makefiles, and to make _CoqProject files
more palatable to IDEs. Overview:
- * _CoqProject files contain only Coq specific data (i.e. the list of
+ * _CoqProject files contain only |Coq| specific data (i.e. the list of
files, -R options, ...)
* coq_makefile translates _CoqProject to Makefile.conf and copies in the
desired location a standard Makefile (that reads Makefile.conf)
@@ -3814,15 +3921,15 @@ Details of changes in 8.7+beta2
Tools
-- In CoqIDE, the "Compile Buffer" command takes account of flags in
+- In |CoqIDE|, the "Compile Buffer" command takes account of flags in
_CoqProject or other project file.
Improvements around some error messages.
Many bug fixes including two important ones:
-- Bug #5730: CoqIDE becomes unresponsive on file open.
-- coq_makefile: make sure compile flags for Coq and coq_makefile are in sync
+- Bug #5730: |CoqIDE| becomes unresponsive on file open.
+- coq_makefile: make sure compile flags for |Coq| and coq_makefile are in sync
(in particular, make sure the `-safe-string` option is used to compile plugins).
Details of changes in 8.7.0
@@ -3833,7 +3940,7 @@ OCaml
- Users can pass specific flags to the OCaml optimizing compiler by
-using the flambda-opts configure-time option.
- Beware that compiling Coq with a flambda-enabled compiler is
+ Beware that compiling |Coq| with a flambda-enabled compiler is
experimental and may require large amounts of RAM and CPU, see
INSTALL for more details.
@@ -3863,7 +3970,7 @@ Version 8.6
Summary of changes
~~~~~~~~~~~~~~~~~~
-Coq version 8.6 contains the result of refinements, stabilization of
+|Coq| version 8.6 contains the result of refinements, stabilization of
8.5’s features and cleanups of the internals of the system. Over the
year of (now time-based) development, about 450 bugs were resolved and
over 100 contributions integrated. The main user visible changes are:
@@ -3897,7 +4004,7 @@ over 100 contributions integrated. The main user visible changes are:
- Integration of LtacProf, a profiler for Ltac by Jason Gross, Paul
Steckler, Enrico Tassi and Tobias Tebbi.
-Coq 8.6 also comes with a bunch of smaller-scale changes and
+|Coq| 8.6 also comes with a bunch of smaller-scale changes and
improvements regarding the different components of the system. We shall
only list a few of them.
@@ -3983,13 +4090,13 @@ development.
Version 8.6 is the first release of |Coq| developed on a time-based
development cycle. Its development spanned 10 months from the release of
-Coq 8.5 and was based on a public roadmap. To date, it contains more
+|Coq| 8.5 and was based on a public roadmap. To date, it contains more
external contributions than any previous |Coq| system. Code reviews were
systematically done before integration of new features, with an
important focus given to compatibility and performance issues, resulting
in a hopefully more robust release than |Coq| 8.5.
-Coq Enhancement Proposals (CEPs for short) were introduced by Enrico
+|Coq| Enhancement Proposals (CEPs for short) were introduced by Enrico
Tassi to provide more visibility and a discussion period on new
features, they are publicly available https://github.com/coq/ceps.
@@ -4134,13 +4241,13 @@ General infrastructure
- New configurable warning system which can be controlled with the vernacular
command "Set Warnings", or, under coqc/coqtop, with the flag "-w". In
particular, the default is now that warnings are printed by coqc.
-- In asynchronous mode, Coq is now capable of recovering from errors and
+- In asynchronous mode, |Coq| is now capable of recovering from errors and
continue processing the document.
Tools
- coqc accepts a -o option to specify the output file name
-- coqtop accepts --print-version to print Coq and OCaml versions in
+- coqtop accepts --print-version to print |Coq| and |OCaml| versions in
easy to parse format
- Setting [Printing Dependent Evars Line] can be unset to disable the
computation associated with printing the "dependent evars: " line in
@@ -4169,7 +4276,7 @@ Other bug fixes in universes, type class shelving,...
Details of changes in 8.6.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- Fix #5380: Default colors for CoqIDE are actually applied.
+- Fix #5380: Default colors for |CoqIDE| are actually applied.
- Fix plugin warnings
- Document named evars (including Show ident)
- Fix Bug #5574, document function scope
@@ -4221,7 +4328,7 @@ Version 8.5
Summary of changes
~~~~~~~~~~~~~~~~~~
-Coq version 8.5 contains the result of five specific long-term projects:
+|Coq| version 8.5 contains the result of five specific long-term projects:
- A new asynchronous evaluation and compilation mode by Enrico Tassi
with help from Bruno Barras and Carst Tankink.
@@ -4312,7 +4419,7 @@ conversion test and normal form computation using the OCaml native
compiler. It complements the virtual machine conversion offering much
faster computation for expensive functions.
-Coq 8.5 also comes with a bunch of many various smaller-scale changes
+|Coq| 8.5 also comes with a bunch of many various smaller-scale changes
and improvements regarding the different components of the system. We
shall only list a few of them.
@@ -4375,8 +4482,8 @@ Tankink. Maxime Dénès coordinated the release process.
Potential sources of incompatibilities
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-List of typical changes to be done to adapt files from Coq 8.4
-to Coq 8.5 when not using compatibility option ``-compat 8.4``.
+List of typical changes to be done to adapt files from |Coq| 8.4
+to |Coq| 8.5 when not using compatibility option ``-compat 8.4``.
- Symptom: "The reference omega was not found in the current environment".
@@ -4511,7 +4618,7 @@ Logic
logic inconsistent).
- The guard condition for fixpoints is now a bit stricter. Propagation
of subterm value through pattern matching is restricted according to
- the return predicate. Restores compatibility of Coq's logic with the
+ the return predicate. Restores compatibility of |Coq|'s logic with the
propositional extensionality axiom. May create incompatibilities in
recursive programs heavily using dependent types.
- Trivial inductive types are no longer defined in Type but in Prop, which
@@ -4551,7 +4658,7 @@ Vernacular commands
- A new Print Strategies command allows visualizing the opacity status
of the whole engine.
- The "Locate" command now searches through all sorts of qualified namespaces of
- Coq: terms, modules, tactics, etc. The old behavior of the command can be
+ |Coq|: terms, modules, tactics, etc. The old behavior of the command can be
retrieved using the "Locate Term" command.
- New "Derive" command to help writing program by derivation.
- New "Refine Instance Mode" option that allows to deactivate the generation of
@@ -4879,24 +4986,24 @@ Tools
files from the quickly generated proofs.
- The XML plugin was discontinued and removed from the source.
- A new utility called coqworkmgr can be used to limit the number of
- concurrent workers started by independent processes, like make and CoqIDE.
+ concurrent workers started by independent processes, like make and |CoqIDE|.
This is of interest for users of the par: goal selector.
Interfaces
-- CoqIDE supports asynchronous edition of the document, ongoing tasks and
+- |CoqIDE| supports asynchronous edition of the document, ongoing tasks and
errors are reported in the bottom right window. The number of workers
taking care of processing proofs can be selected with -async-proofs-j.
-- CoqIDE highlights in yellow "unsafe" commands such as axiom
+- |CoqIDE| highlights in yellow "unsafe" commands such as axiom
declarations, and tactics like "give_up".
-- CoqIDE supports Proof General like key bindings;
+- |CoqIDE| supports Proof General like key bindings;
to activate the PG mode go to Edit -> Preferences -> Editor.
For the documentation see Help -> Help for PG mode.
-- CoqIDE automatically retracts the locked area when one edits the
+- |CoqIDE| automatically retracts the locked area when one edits the
locked text.
-- CoqIDE search and replace got regular expressions power. See the
+- |CoqIDE| search and replace got regular expressions power. See the
documentation of OCaml's Str module for the supported syntax.
-- Many CoqIDE windows, including the query one, are now detachable to
+- Many |CoqIDE| windows, including the query one, are now detachable to
improve usability on multi screen work stations.
- Coqtop/coqc outputs highlighted syntax. Colors can be configured thanks
to the COQ_COLORS environment variable, and their current state can
@@ -4907,7 +5014,7 @@ Interfaces
Internal Infrastructure
- Many reorganizations in the ocaml source files. For instance,
- many internal a.s.t. of Coq are now placed in mli files in
+ many internal a.s.t. of |Coq| are now placed in mli files in
a new directory intf/, for instance constrexpr.mli or glob_term.mli.
More details in dev/doc/changes.
@@ -4959,7 +5066,7 @@ Tactics
Extraction
- Definitions extracted to Haskell GHC should no longer randomly
- segfault when some Coq types cannot be represented by Haskell types.
+ segfault when some |Coq| types cannot be represented by Haskell types.
- Definitions can now be extracted to Json for post-processing.
Tools
@@ -5057,8 +5164,8 @@ Tools
Standard Library
- There is now a Coq.Compat.Coq84 library, which sets the various compatibility
- options and does a few redefinitions to make Coq behave more like Coq v8.4.
- The standard way of putting Coq in v8.4 compatibility mode is to pass the command
+ options and does a few redefinitions to make |Coq| behave more like |Coq| v8.4.
+ The standard way of putting |Coq| in v8.4 compatibility mode is to pass the command
line flags "-require Coq.Compat.Coq84 -compat 8.4".
Details of changes in 8.5
@@ -5067,7 +5174,7 @@ Details of changes in 8.5
Tools
- Flag "-compat 8.4" now loads Coq.Compat.Coq84. The standard way of
- putting Coq in v8.4 compatibility mode is to pass the command line flag
+ putting |Coq| in v8.4 compatibility mode is to pass the command line flag
"-compat 8.4". It can be followed by "-require Coq.Compat.AdmitAxiom"
if the 8.4 behavior of admit is needed, in which case it uses an axiom.
@@ -5108,7 +5215,7 @@ Various performance improvements (time, space used by .vo files)
Other bugfixes
- Fix order of arguments to Big.compare_case in ExtrOcamlZBigInt.v
-- Added compatibility coercions from Specif.v which were present in Coq 8.4.
+- Added compatibility coercions from Specif.v which were present in |Coq| 8.4.
- Fixing a source of inefficiency and an artificial dependency in the printer in the congruence tactic.
- Allow to unset the refinement mode of Instance in ML
- Fixing an incorrect use of prod_appvect on a term which was not a product in setoid_rewrite.
@@ -5123,7 +5230,7 @@ Other bugfixes
- #4623: set tactic too weak with universes (regression)
- Fix incorrect behavior of CS resolution
- #4591: Uncaught exception in directory browsing.
-- CoqIDE is more resilient to initialization errors.
+- |CoqIDE| is more resilient to initialization errors.
- #4614: "Fully check the document" is uninterruptible.
- Try eta-expansion of records only on non-recursive ones
- Fix bug when a sort is ascribed to a Record
@@ -5133,23 +5240,23 @@ Other bugfixes
- Fix strategy of Keyed Unification
- #4608: Anomaly "output_value: abstract value (outside heap)".
- #4607: do not read native code files if native compiler was disabled.
-- #4105: poor escaping in the protocol between CoqIDE and coqtop.
+- #4105: poor escaping in the protocol between |CoqIDE| and coqtop.
- #4596: [rewrite] broke in the past few weeks.
- #4533 (partial): respect declared global transparency of projections in unification.ml
- #4544: Backtrack on using full betaiota reduction during keyed unification.
-- #4540: CoqIDE bottom progress bar does not update.
+- #4540: |CoqIDE| bottom progress bar does not update.
- Fix regression from 8.4 in reflexivity
- #4580: [Set Refine Instance Mode] also used for Program Instance.
- #4582: cannot override notation [ x ]. MAY CREATE INCOMPATIBILITIES, see #4683.
- STM: Print/Extraction have to be skipped if -quick
-- #4542: CoqIDE: STOP button also stops workers
+- #4542: |CoqIDE|: STOP button also stops workers
- STM: classify some variants of Instance as regular `` `Fork `` nodes.
- #4574: Anomaly: Uncaught exception Invalid_argument("splay_arity").
- Do not give a name to anonymous evars anymore. See bug #4547.
- STM: always stock in vio files the first node (state) of a proof
- STM: not delegate proofs that contain Vernac(Module|Require|Import), #4530
- Don't fail fatally if PATH is not set.
-- #4537: Coq 8.5 is slower in typeclass resolution.
+- #4537: |Coq| 8.5 is slower in typeclass resolution.
- #4522: Incorrect "Warning..." on windows.
- #4373: coqdep does not know about .vio files.
- #3826: "Incompatible module types" is uninformative.
@@ -5158,7 +5265,7 @@ Other bugfixes
- #4503: mixing universe polymorphic and monomorphic variables and definitions in sections is unsupported.
- #4519: oops, global shadowed local universe level bindings.
- #4506: Anomaly: File "pretyping/indrec.ml", line 169, characters 14-20: Assertion failed.
-- #4548: Coqide crashes when going back one command
+- #4548: |CoqIDE| crashes when going back one command
Details of changes in 8.5pl2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -5179,8 +5286,8 @@ Other bugfixes
- #4644: a regression in unification.
- #4725: Function (Error: Conversion test raised an anomaly) and Program
(Error: Cannot infer this placeholder of type)
-- #4747: Problem building Coq 8.5pl1 with OCaml 4.03.0: Fatal warnings
-- #4752: CoqIDE crash on files not ended by ".v".
+- #4747: Problem building |Coq| 8.5pl1 with OCaml 4.03.0: Fatal warnings
+- #4752: |CoqIDE| crash on files not ended by ".v".
- #4777: printing inefficiency with implicit arguments
- #4818: "Admitted" fails due to undefined universe anomaly after calling
"destruct"
@@ -5194,7 +5301,7 @@ Other bugfixes
- #4881: synchronizing "Declare Implicit Tactic" with backtrack.
- #4882: anomaly with Declare Implicit Tactic on hole of type with evars
- Fix use of "Declare Implicit Tactic" in refine.
- triggered by CoqIDE
+ triggered by |CoqIDE|
- #4069, #4718: congruence fails when universes are involved.
Universes
@@ -5257,7 +5364,7 @@ Other bugfixes
- #5097: status of evars refined by "clear" in ltac: closed wrt evars.
- #5150: Missing dependency of the test-suite subsystems in prerequisite.
- Fix a bug in error printing of unif constraints
-- #3941: Do not stop propagation of signals when Coq is busy.
+- #3941: Do not stop propagation of signals when |Coq| is busy.
- #4822: Incorrect assertion in cbn.
- #3479 parsing of "{" and "}" when a keyword starts with "{" or "}".
- #5127: Memory corruption with the VM.
@@ -5271,7 +5378,7 @@ Version 8.4
Summary of changes
~~~~~~~~~~~~~~~~~~
-Coq version 8.4 contains the result of three long-term projects: a new
+|Coq| version 8.4 contains the result of three long-term projects: a new
modular library of arithmetic by Pierre Letouzey, a new proof engine by
Arnaud Spiwack and a new communication protocol for |CoqIDE| by Vincent
Gross.
@@ -5304,7 +5411,7 @@ sessions in parallel. Relying on the infrastructure work made by Vincent
Gross, Pierre Letouzey, Pierre Boutillier and Pierre-Marie Pédrot
contributed many various refinements of |CoqIDE|.
-Coq 8.4 also comes with a bunch of various smaller-scale changes
+|Coq| 8.4 also comes with a bunch of various smaller-scale changes
and improvements regarding the different components of the system.
The underlying logic has been extended with :math:`\eta`-conversion
@@ -5382,14 +5489,14 @@ Julien Forest maintained the Function command.
Matthieu Sozeau maintained the setoid rewriting mechanism.
-Coq related tools have been upgraded too. In particular, coq\_makefile
+|Coq| related tools have been upgraded too. In particular, coq\_makefile
has been largely revised by Pierre Boutillier. Also, patches from Adam
Chlipala for coqdoc have been integrated by Pierre Boutillier.
Bruno Barras and Pierre Letouzey maintained the `coqchk` checker.
Pierre Courtieu and Arnaud Spiwack contributed new features for using
-Coq through Proof General.
+|Coq| through Proof General.
The Dp plugin has been removed. Use the plugin provided with Why 3
instead (http://why3.lri.fr/).
@@ -5641,7 +5748,7 @@ Libraries
* "<?" "<=?" "=?" for boolean tests such as Z.ltb Z.leb Z.eqb.
* "÷" for the alternative integer division Z.quot implementing the Truncate
- convention (former ZOdiv), while the notation for the Coq usual division
+ convention (former ZOdiv), while the notation for the |Coq| usual division
Z.div implementing the Flooring convention remains "/". Their corresponding
modulo functions are Z.rem (no notations) for Z.quot and Z.modulo (infix
"mod" notation) for Z.div.
@@ -5701,31 +5808,31 @@ Extraction
universe polymorphism it cannot handle yet (the pair (I,I) being Prop).
- Support of anonymous fields in record (#2555).
-CoqIDE
+|CoqIDE|
-- Coqide now runs coqtop as separated process, making it more robust:
+- |CoqIDE| now runs coqtop as separated process, making it more robust:
coqtop subprocess can be interrupted, or even killed and relaunched
(cf button "Restart Coq", ex-"Go to Start"). For allowing such
interrupts, the Windows version of coqide now requires Windows >= XP
SP1.
-- The communication between CoqIDE and Coqtop is now done via a dialect
+- The communication between |CoqIDE| and coqtop is now done via a dialect
of XML (DOC TODO).
-- The backtrack engine of CoqIDE has been reworked, it now uses the
+- The backtrack engine of |CoqIDE| has been reworked, it now uses the
"Backtrack" command similarly to Proof General.
-- The Coqide parsing of sentences has be reworked and now supports
+- The |CoqIDE| parsing of sentences has be reworked and now supports
tactic delimitation via { }.
-- Coqide now accepts the Abort command (wish #2357).
-- Coqide can read coq_makefile files as "project file" and use it to
+- |CoqIDE| now accepts the Abort command (wish #2357).
+- |CoqIDE| can read coq_makefile files as "project file" and use it to
set automatically options to send to coqtop.
- Preference files have moved to $XDG_CONFIG_HOME/coq and accelerators
are not stored as a list anymore.
Tools
-- Coq now searches directories specified in COQPATH, $XDG_DATA_HOME/coq,
+- |Coq| now searches directories specified in COQPATH, $XDG_DATA_HOME/coq,
$XDG_DATA_DIRS/coq, and user-contribs before the standard library.
-- Coq rc file has moved to $XDG_CONFIG_HOME/coq.
+- |Coq| rc file has moved to $XDG_CONFIG_HOME/coq.
- Major changes to coq_makefile:
@@ -5783,9 +5890,9 @@ Module System
namespace from ordinary definitions: "Definition E:=0. Module E. End E."
is now accepted.
-CoqIDE
+|CoqIDE|
-- Coqide now supports the "Restart" command, and "Undo" (with a warning).
+- |CoqIDE| now supports the "Restart" command, and "Undo" (with a warning).
Better support for "Abort".
Details of changes in 8.4
@@ -5802,9 +5909,9 @@ Vernacular commands
Notations
- Most compatibility notations of the standard library are now tagged as
- (compat xyz), where xyz is a former Coq version, for instance "8.3".
+ (compat xyz), where xyz is a former |Coq| version, for instance "8.3".
These notations behave as (only parsing) notations, except that they may
- triggers warnings (or errors) when used while Coq is not in a corresponding
+ triggers warnings (or errors) when used while |Coq| is not in a corresponding
-compat mode.
- To activate these compatibility warnings, use "Set Verbose Compat Notations"
or the command-line flag -verbose-compat-notations.
@@ -5834,7 +5941,7 @@ Version 8.3
Summary of changes
~~~~~~~~~~~~~~~~~~
-Coq version 8.3 is before all a transition version with refinements or
+|Coq| version 8.3 is before all a transition version with refinements or
extensions of the existing features and libraries and a new tactic nsatz
based on Hilbert’s Nullstellensatz for deciding systems of equations
over rings.
@@ -5873,7 +5980,7 @@ been done by Matthieu Sozeau, Hugo Herbelin and Pierre Letouzey.
Matthieu Sozeau extended and refined the typeclasses and Program
features (the Russell language). Pierre Letouzey maintained and improved
the extraction mechanism. Bruno Barras and Élie Soubiran maintained the
-Coq checker, Julien Forest maintained the Function mechanism for
+|Coq| checker, Julien Forest maintained the Function mechanism for
reasoning over recursively defined functions. Matthieu Sozeau, Hugo
Herbelin and Jean-Marc Notin maintained coqdoc. Frédéric Besson
maintained the Micromega platform for deciding systems of inequalities.
@@ -6037,12 +6144,12 @@ Module system
"Inline" annotation in the type of its argument(s) (for examples of
use of the new features, see libraries Structures and Numbers).
- Coercions are now active only when modules are imported (use "Set Automatic
- Coercions Import" to get the behavior of the previous versions of Coq).
+ Coercions Import" to get the behavior of the previous versions of |Coq|).
Extraction
- When using (Recursive) Extraction Library, the filenames are directly the
- Coq ones with new appropriate extensions : we do not force anymore
+ |Coq| ones with new appropriate extensions : we do not force anymore
uncapital first letters for Ocaml and capital ones for Haskell.
- The extraction now tries harder to avoid code transformations that can be
dangerous for the complexity. In particular many eta-expansions at the top
@@ -6125,7 +6232,7 @@ Vernacular commands
Library
-- Use "standard" Coq names for the properties of eq and identity
+- Use "standard" |Coq| names for the properties of eq and identity
(e.g. refl_equal is now eq_refl). Support for compatibility is provided.
- The function Compare_dec.nat_compare is now defined directly,
@@ -6176,7 +6283,7 @@ Library
- MSets library: an important evolution of the FSets library.
"MSets" stands for Modular (Finite) Sets, by contrast with a forthcoming
library of Class (Finite) Sets contributed by S. Lescuyer which will be
- integrated with the next release of Coq. The main features of MSets are:
+ integrated with the next release of |Coq|. The main features of MSets are:
+ The use of Equivalence, Proper and other Type Classes features
easing the handling of setoid equalities.
@@ -6191,7 +6298,7 @@ Library
Note: No Maps yet in MSets. The FSets library is still provided
for compatibility, but will probably be considered as deprecated in the
- next release of Coq.
+ next release of |Coq|.
- Numbers library:
@@ -6207,12 +6314,12 @@ Library
Tools
-- Option -R now supports binding Coq root read-only.
+- Option -R now supports binding |Coq| root read-only.
- New coqtop/coqc option -beautify to reformat .v files (usable
e.g. to globally update notations).
- New tool beautify-archive to beautify a full archive of developments.
- New coqtop/coqc option -compat X.Y to simulate the general behavior
- of previous versions of Coq (provides e.g. support for 8.2 compatibility).
+ of previous versions of |Coq| (provides e.g. support for 8.2 compatibility).
Coqdoc
@@ -6228,7 +6335,7 @@ Coqdoc
- New option "--parse-comments" to allow parsing of regular ``(* *)``
comments.
- New option "--plain-comments" to disable interpretation inside comments.
-- New option "--interpolate" to try and typeset identifiers in Coq escapings
+- New option "--interpolate" to try and typeset identifiers in |Coq| escapings
using the available globalization information.
- New option "--external url root" to refer to external libraries.
- Links to section variables and notations now supported.
@@ -6242,7 +6349,7 @@ Internal infrastructure
- An experimental build mechanism via ocamlbuild is provided.
From the top of the archive, run ./configure as usual, and
then ./build. Feedback about this build mechanism is most welcome.
- Compiling Coq on platforms such as Windows might be simpler
+ Compiling |Coq| on platforms such as Windows might be simpler
this way, but this remains to be tested.
- The Makefile system has been simplified and factorized with
the ocamlbuild system. In particular "make" takes advantage
@@ -6255,7 +6362,7 @@ Version 8.2
Summary of changes
~~~~~~~~~~~~~~~~~~
-Coq version 8.2 adds new features, new libraries and improves on many
+|Coq| version 8.2 adds new features, new libraries and improves on many
various aspects.
Regarding the language of |Coq|, the main novelty is the introduction by
@@ -6410,7 +6517,7 @@ Vernacular commands
qualified names (this holds also for coqtop/coqc option -R).
- SearchAbout supports negated search criteria, reference to logical objects
by their notation, and more generally search of subterms.
-- "Declare ML Module" now allows to import .cmxs files when Coq is
+- "Declare ML Module" now allows to import .cmxs files when |Coq| is
compiled in native code with a version of OCaml that supports native
Dynlink (>= 3.11).
- Specific sort constraints on Record now taken into account.
@@ -6451,7 +6558,7 @@ Libraries
version should be fairly good, but some adaptations may be required.
* Interfaces of unordered ("weak") and ordered sets have been factorized
- thanks to new features of Coq modules (in particular Include), see
+ thanks to new features of |Coq| modules (in particular Include), see
FSetInterface. Same for maps. Hints in these interfaces have been
reworked (they are now placed in a "set" database).
* To allow full subtyping between weak and ordered sets, a field
@@ -6482,7 +6589,7 @@ Libraries
initial Ocaml code and written via the Function framework.
- Library IntMap, subsumed by FSets/FMaps, has been removed from
- Coq Standard Library and moved into a user contribution Cachan/IntMap
+ |Coq| Standard Library and moved into a user contribution Cachan/IntMap
- Better computational behavior of some constants (eq_nat_dec and
le_lt_dec more efficient, Z_lt_le_dec and Positive_as_OT.compare
@@ -6687,7 +6794,7 @@ Tactics
- New tactic "specialize H with a" or "specialize (H a)" allows to transform
in-place a universally-quantified hypothesis (H : forall x, T x) into its
instantiated form (H : T a). Nota: "specialize" was in fact there in earlier
- versions of Coq, but was undocumented, and had a slightly different behavior.
+ versions of |Coq|, but was undocumented, and had a slightly different behavior.
- New tactic "contradict H" can be used to solve any kind of goal as long as
the user can provide afterwards a proof of the negation of the hypothesis H.
@@ -6731,7 +6838,7 @@ Program
- Program Lemma, Axiom etc... now permit to have obligations in the statement
iff they can be automatically solved by the default tactic.
- Renamed "Obligations Tactic" command to "Obligation Tactic".
-- New command "Preterm [ of id ]" to see the actual term fed to Coq for
+- New command "Preterm [ of id ]" to see the actual term fed to |Coq| for
debugging purposes.
- New option "Transparent Obligations" to control the declaration of
obligations as transparent or opaque. All obligations are now transparent
@@ -6823,7 +6930,7 @@ Extraction
not happen anymore.
- The command Extract Inductive has now a syntax for infix notations. This
- allows in particular to map Coq lists and pairs onto Caml ones:
+ allows in particular to map |Coq| lists and pairs onto |OCaml| ones:
+ Extract Inductive list => list [ "[]" "(::)" ].
+ Extract Inductive prod => "(*)" [ "(,)" ].
@@ -6837,16 +6944,16 @@ Extraction
conflits with existing code, for instance when extracting module List
to Ocaml.
-CoqIDE
+|CoqIDE|
-- CoqIDE font defaults to monospace so as indentation to be meaningful.
-- CoqIDE supports nested goals and any other kind of declaration in the middle
+- |CoqIDE| font defaults to monospace so as indentation to be meaningful.
+- |CoqIDE| supports nested goals and any other kind of declaration in the middle
of a proof.
-- Undoing non-tactic commands in CoqIDE works faster.
-- New CoqIDE menu for activating display of various implicit informations.
+- Undoing non-tactic commands in |CoqIDE| works faster.
+- New |CoqIDE| menu for activating display of various implicit informations.
- Added the possibility to choose the location of tabs in coqide:
(in Edit->Preferences->Misc)
-- New Open and Save As dialogs in CoqIDE which filter ``*.v`` files.
+- New Open and Save As dialogs in |CoqIDE| which filter ``*.v`` files.
Tools
@@ -6855,22 +6962,22 @@ Tools
- New coqtop/coqc option -exclude-dir to exclude subdirs for option -R.
- The binary "parser" has been renamed to "coq-parser".
- Improved coqdoc and dump of globalization information to give more
- meta-information on identifiers. All categories of Coq definitions are
+ meta-information on identifiers. All categories of |Coq| definitions are
supported, which makes typesetting trivial in the generated documentation.
Support for hyperlinking and indexing developments in the tex output
has been implemented as well.
Miscellaneous
-- Coq installation provides enough files so that Ocaml's extensions need not
- the Coq sources to be compiled (this assumes O'Caml 3.10 and Camlp5).
+- |Coq| installation provides enough files so that Ocaml's extensions need not
+ the |Coq| sources to be compiled (this assumes O'Caml 3.10 and Camlp5).
- New commands "Set Whelp Server" and "Set Whelp Getter" to customize the
Whelp search tool.
- Syntax of "Test Printing Let ref" and "Test Printing If ref" changed into
"Test Printing Let for ref" and "Test Printing If for ref".
- An overhauled build system (new Makefiles); see dev/doc/build-system.txt.
- Add -browser option to configure script.
-- Build a shared library for the C part of Coq, and use it by default on
+- Build a shared library for the C part of |Coq|, and use it by default on
non-(Windows or MacOS) systems. Bytecode executables are now pure. The
behaviour is configurable with -coqrunbyteflags, -coqtoolsbyteflags and
-custom configure options.
@@ -6883,7 +6990,7 @@ Version 8.1
Summary of changes
~~~~~~~~~~~~~~~~~~
-Coq version 8.1 adds various new functionalities.
+|Coq| version 8.1 adds various new functionalities.
Benjamin Grégoire implemented an alternative algorithm to check the
convertibility of terms in the |Coq| type checker. This alternative
@@ -6991,7 +7098,7 @@ Vernacular commands
Ltac and tactic syntactic extensions
-- New primitive "external" for communication with tool external to Coq
+- New primitive "external" for communication with tool external to |Coq|
- New semantics for "match t with": if a clause returns a
tactic, it is now applied to the current goal. If it fails, the next
clause or next matching subterm is tried (i.e. it behaves as "match
@@ -7016,7 +7123,7 @@ Tactics
- New conversion tactic "vm_compute": evaluates the goal (or an hypothesis)
with a call-by-value strategy, using the compiled version of terms.
-- When rewriting H where H is not directly a Coq equality, search first H for
+- When rewriting H where H is not directly a |Coq| equality, search first H for
a registered setoid equality before starting to reduce in H. This is unlikely
to break any script. Should this happen nonetheless, one can insert manually
some "unfold ... in H" before rewriting.
@@ -7061,7 +7168,7 @@ Tactics
- New tactic "pose proof" that generalizes "assert (id:=p)" with intro patterns.
-- New introduction pattern "?" for letting Coq choose a name.
+- New introduction pattern "?" for letting |Coq| choose a name.
- Introduction patterns now support side hypotheses (e.g. intros [|] on
"(nat -> nat) -> nat" works).
@@ -7147,7 +7254,7 @@ Libraries
Zlt_square_simpl removed; fixed names mentioning letter O instead of
digit 0; weaken premises in Z_lt_induction).
- Restructuration of Eqdep_dec.v and Eqdep.v: more lemmas in Type.
-- Znumtheory now contains a gcd function that can compute within Coq.
+- Znumtheory now contains a gcd function that can compute within |Coq|.
- More lemmas stated on Type in Wf.v, removal of redundant Acc_iter and
Acc_iter2.
- Change of the internal names of lemmas in OmegaLemmas.
@@ -7180,7 +7287,7 @@ Tools
- Tool coq_makefile now removes custom targets that are file names in
"make clean"
- New environment variable COQREMOTEBROWSER to set the command invoked
- to start the remote browser both in Coq and coqide. Standard syntax:
+ to start the remote browser both in |Coq| and |CoqIDE|. Standard syntax:
"%s" is the placeholder for the URL.
Details of changes in 8.1gamma
@@ -7256,7 +7363,7 @@ Version 8.0
Summary of changes
~~~~~~~~~~~~~~~~~~
-Coq version 8 is a major revision of the |Coq| proof assistant. First, the
+|Coq| version 8 is a major revision of the |Coq| proof assistant. First, the
underlying logic is slightly different. The so-called *impredicativity*
of the sort Set has been dropped. The main reason is that it is
inconsistent with the principle of description which is quite a useful
@@ -7294,7 +7401,7 @@ purpose here is a better uniformity making the tactics and commands
easier to use and to remember.
Thirdly, a restructuring and uniformization of the standard library of
-Coq has been performed. There is now just one Leibniz equality usable
+|Coq| has been performed. There is now just one Leibniz equality usable
for all the different kinds of |Coq| objects. Also, the set of real
numbers now lies at the same level as the sets of natural and integer
numbers. Finally, the names of the standard properties of numbers now
@@ -7511,19 +7618,19 @@ Miscellaneous
Incompatibilities
-- Persistence of true_sub (4 incompatibilities in Coq user contributions)
+- Persistence of true_sub (4 incompatibilities in |Coq| user contributions)
- Variable names of some constants changed for a better uniformity (2 changes
- in Coq user contributions)
+ in |Coq| user contributions)
- Naming of quantified names in goal now avoid global names (2 occurrences)
- NewInduction naming for inductive types with functional arguments
- (no incompatibility in Coq user contributions)
+ (no incompatibility in |Coq| user contributions)
- Contradiction now solve more goals (source of 2 incompatibilities)
- Merge of eq and eqT may exceptionally result in subgoals now
solved automatically
- Redundant pairs of ZArith lemmas may have different names: it may
cause "Apply/Rewrite with" to fail if using the first name of a pair
of redundant lemmas (this is solved by renaming the variables bound by
- "with"; 3 incompatibilities in Coq user contribs)
+ "with"; 3 incompatibilities in |Coq| user contribs)
- ML programs referring to constants from fast_integer.v must use
"Coqlib.gen_constant_modules Coqlib.zarith_base_modules" instead
@@ -7559,7 +7666,7 @@ Revision of the standard library
"Zmult_le_compat_r", "SUPERIEUR" -> "Gt", "ZERO" -> "Z0")
- Order and names of arguments of basic lemmas on nat, Z, positive and R
have been made uniform.
-- Notions of Coq initial state are declared with (strict) implicit arguments
+- Notions of |Coq| initial state are declared with (strict) implicit arguments
- eq merged with eqT: old eq disappear, new eq (written =) is old eqT
and new eqT is syntactic sugar for new eq (notation == is an alias
for = and is written as it, exceptional source of incompatibilities)
@@ -7590,7 +7697,7 @@ Known problems of the automatic translation
- iso-latin-1 characters are no longer supported: move your files to
7-bits ASCII or unicode before translation (switch to unicode is
automatically done if a file is loaded and saved again by coqide)
-- Renaming in ZArith: incompatibilities in Coq user contribs due to
+- Renaming in ZArith: incompatibilities in |Coq| user contribs due to
merging names INZ, from Reals, and inject_nat.
- Renaming and new lemmas in ZArith: may clash with names used by users
- Restructuration of ZArith: replace requirement of specific modules
@@ -7640,7 +7747,7 @@ Tactics and the tactic Language
Executables and tools
- Added option -top to change the name of the toplevel module "Top"
-- Coqdoc updated to new syntax and now part of Coq sources
+- Coqdoc updated to new syntax and now part of |Coq| sources
- XML exportation tool now exports the structure of vernacular files
(cf chapter 13 in the reference manual)
diff --git a/doc/sphinx/conf.py b/doc/sphinx/conf.py
index a8a574c861..75ac2a76cd 100755
--- a/doc/sphinx/conf.py
+++ b/doc/sphinx/conf.py
@@ -183,9 +183,7 @@ todo_include_todos = False
nitpicky = True
nitpick_ignore = [ ('token', token) for token in [
- 'collection',
'tactic',
- 'bindings',
'induction_clause',
'conversion',
'where',
diff --git a/doc/sphinx/history.rst b/doc/sphinx/history.rst
index 02821613cc..bab9bfcadb 100644
--- a/doc/sphinx/history.rst
+++ b/doc/sphinx/history.rst
@@ -1,16 +1,16 @@
.. _history:
---------------------
-Early history of Coq
---------------------
+----------------------
+Early history of |Coq|
+----------------------
Historical roots
----------------
-Coq is a proof assistant for higher-order logic, allowing the
+|Coq| is a proof assistant for higher-order logic, allowing the
development of computer programs consistent with their formal
specification. It is the result of about ten years [#years]_ of research
-of the Coq project. We shall briefly survey here three main aspects: the
+of the |Coq| project. We shall briefly survey here three main aspects: the
*logical language* in which we write our axiomatizations and
specifications, the *proof assistant* which allows the development of
verified mathematical proofs, and the *program extractor* which
@@ -153,7 +153,7 @@ by A. Felty. It allowed operation of the theorem-prover through the
manipulation of windows, menus, mouse-sensitive buttons, and other
widgets. This system (Version 5.6) was released in 1991.
-Coq was ported to the new implementation Caml-light of X. Leroy and D.
+|Coq| was ported to the new implementation Caml-light of X. Leroy and D.
Doligez by D. de Rauglaudre (Version 5.7) in 1992. A new version of |Coq|
was then coordinated by C. Murthy, with new tools designed by C. Parent
to prove properties of ML programs (this methodology is dual to program
@@ -477,7 +477,7 @@ C. Paulin-Mohring. *Inductively defined types* :cite:`CP90`.
This led to the Calculus of Inductive Constructions, logical formalism
implemented in Versions 5 upward of the system, and documented in:
-C. Paulin-Mohring. *Inductive Definitions in the System Coq - Rules
+C. Paulin-Mohring. *Inductive Definitions in the System |Coq| - Rules
and Properties* :cite:`P93`.
The last version of CONSTR is Version 4.11, which was last distributed
@@ -489,7 +489,7 @@ Version 5
~~~~~~~~~
At the end of 1989, Version 5.1 was started, and renamed as the system
-Coq for the Calculus of Inductive Constructions. It was then ported to
+|Coq| for the Calculus of Inductive Constructions. It was then ported to
the new stand-alone implementation of ML called Caml-light.
In 1990 many changes occurred. Thierry Coquand left for Chalmers
@@ -497,7 +497,7 @@ University in Göteborg. Christine Paulin-Mohring took a CNRS
researcher position at the LIP laboratory of École Normale Supérieure
de Lyon. Project Formel was terminated, and gave rise to two teams:
Cristal at INRIA-Roquencourt, that continued developments in
-functional programming with Caml-light then OCaml, and Coq, continuing
+functional programming with Caml-light then OCaml, and |Coq|, continuing
the type theory research, with a joint team headed by Gérard Huet at
INRIA-Rocquencourt and Christine Paulin-Mohring at the LIP laboratory
of CNRS-ENS Lyon.
@@ -736,7 +736,7 @@ Notes:
Main novelties
^^^^^^^^^^^^^^
-References are to Coq 7.1 reference manual
+References are to |Coq| 7.1 reference manual
- New primitive let-in construct (see sections 1.2.8 and )
- Long names (see sections 2.6 and 2.7)
@@ -770,7 +770,7 @@ Language: long names
name, the name of the module in which they are defined (Top if in
coqtop), and possibly an arbitrary long sequence of directory (e.g.
"Coq.Lists.PolyList.flat_map" where "Coq" means that "flat_map" is part
- of Coq standard library, "Lists" means it is defined in the Lists
+ of |Coq| standard library, "Lists" means it is defined in the Lists
library and "PolyList" means it is in the file Polylist) (+)
- Constructions can be referred by their base name, or, in case of
@@ -829,7 +829,7 @@ Reduction
- Constants declared as opaque (using Qed) can no longer become
transparent (a constant intended to be alternatively opaque and
transparent must be declared as transparent (using Defined)); a risk
- exists (until next Coq version) that Simpl and Hnf reduces opaque
+ exists (until next |Coq| version) that Simpl and Hnf reduces opaque
constants (*)
@@ -1171,7 +1171,7 @@ Incompatibilities
- New naming strategy for NewInduction/NewDestruct may affect 7.1 compatibility
- Extra parentheses may exceptionally be needed in tactic definitions.
-- Coq extensions written in Ocaml need to be updated (see dev/changements.txt
+- |Coq| extensions written in |OCaml| need to be updated (see dev/changements.txt
for a description of the main changes in the interface files of V7.2)
- New behaviour of Intuition/Tauto may exceptionally lead to incompatibilities
@@ -1205,7 +1205,7 @@ Tactics
product if needed (source of incompatibilities)
- "Match Context" now matching more recent hypotheses first and failing only
on user errors and Fail tactic (possible source of incompatibilities)
-- Tactic Definition's without arguments now allowed in Coq states
+- Tactic Definition's without arguments now allowed in |Coq| states
- Better simplification and discrimination made by Inversion (source
of incompatibilities)
@@ -1239,7 +1239,7 @@ User Contributions
- CongruenceClosure (congruence closure decision procedure)
[Pierre Corbineau, ENS Cachan]
- MapleMode (an interface to embed Maple simplification procedures over
- rational fractions in Coq)
+ rational fractions in |Coq|)
[David Delahaye, Micaela Mayero, Chalmers University]
- Presburger: A formalization of Presburger's algorithm
[Laurent Thery, INRIA Sophia Antipolis]
@@ -1283,7 +1283,7 @@ Bug fixes
Misc
- - Ocaml version >= 3.06 is needed to compile Coq from sources
+ - Ocaml version >= 3.06 is needed to compile |Coq| from sources
- Simplification of fresh names creation strategy for Assert, Pose and
LetTac (#1402)
@@ -1398,7 +1398,7 @@ Extraction (See details in plugins/extraction/CHANGES and README):
- An experimental Scheme extraction is provided.
- Concerning OCaml, extracted code is now ensured to always type check,
thanks to automatic inserting of Obj.magic.
-- Experimental extraction of Coq new modules to Ocaml modules.
+- Experimental extraction of |Coq| new modules to Ocaml modules.
Proof rendering in natural language
diff --git a/doc/sphinx/introduction.rst b/doc/sphinx/introduction.rst
index b059fb4069..dc16897d42 100644
--- a/doc/sphinx/introduction.rst
+++ b/doc/sphinx/introduction.rst
@@ -1,8 +1,8 @@
-This is the reference manual of |Coq|. Coq is an interactive theorem
+This is the reference manual of |Coq|. |Coq| is an interactive theorem
prover. It lets you formalize mathematical concepts and then helps
you interactively generate machine-checked proofs of theorems.
Machine checking gives users much more confidence that the proofs are
-correct compared to human-generated and -checked proofs. Coq has been
+correct compared to human-generated and -checked proofs. |Coq| has been
used in a number of flagship verification projects, including the
`CompCert verified C compiler <http://compcert.inria.fr/>`_, and has
served to verify the proof of the `four color theorem
@@ -18,49 +18,49 @@ arithmetic). :ref:`Ltac <ltac>` and its planned replacement,
combining existing tactics with looping and conditional constructs.
These permit automation of large parts of proofs and sometimes entire
proofs. Furthermore, users can add novel tactics or functionality by
-creating Coq plugins using OCaml.
+creating |Coq| plugins using |OCaml|.
-The Coq kernel, a small part of Coq, does the final verification that
+The |Coq| kernel, a small part of |Coq|, does the final verification that
the tactic-generated proof is valid. Usually the tactic-generated
proof is indeed correct, but delegating proof verification to the
kernel means that even if a tactic is buggy, it won't be able to
introduce an incorrect proof into the system.
-Finally, Coq also supports extraction of verified programs to
-programming languages such as OCaml and Haskell. This provides a way
-of executing Coq code efficiently and can be used to create verified
+Finally, |Coq| also supports extraction of verified programs to
+programming languages such as |OCaml| and Haskell. This provides a way
+of executing |Coq| code efficiently and can be used to create verified
software libraries.
-To learn Coq, beginners are advised to first start with a tutorial /
+To learn |Coq|, beginners are advised to first start with a tutorial /
book. Several such tutorials / books are listed at
https://coq.inria.fr/documentation.
This manual is organized in three main parts, plus an appendix:
-- **The first part presents the specification language of Coq**, that
+- **The first part presents the specification language of |Coq|**, that
allows to define programs and state mathematical theorems.
- :ref:`core-language` presents the language that the kernel of Coq
+ :ref:`core-language` presents the language that the kernel of |Coq|
understands. :ref:`extensions` presents the richer language, with
notations, implicits, etc. that a user can use and which is
translated down to the language of the kernel by means of an
"elaboration process".
- **The second part presents the interactive proof mode**, the central
- feature of Coq. :ref:`writing-proofs` introduces this interactive
+ feature of |Coq|. :ref:`writing-proofs` introduces this interactive
proof mode and the available proof languages.
:ref:`automatic-tactics` presents some more advanced tactics, while
:ref:`writing-tactics` is about the languages that allow a user to
combine tactics together and develop new ones.
-- **The third part shows how to use Coq in practice.**
+- **The third part shows how to use |Coq| in practice.**
:ref:`libraries` presents some of the essential reusable blocks from
the ecosystem and some particularly important extensions such as the
program extraction mechanism. :ref:`tools` documents important
- tools that a user needs to build a Coq project.
+ tools that a user needs to build a |Coq| project.
- In the appendix, :ref:`history-and-changes` presents the history of
- Coq and changes in recent releases. This is an important reference
- if you upgrade the version of Coq that you use. The various
+ |Coq| and changes in recent releases. This is an important reference
+ if you upgrade the version of |Coq| that you use. The various
:ref:`indexes <indexes>` are very useful to **quickly browse the
manual and find what you are looking for.** They are often the main
entry point to the manual.
diff --git a/doc/sphinx/language/core/assumptions.rst b/doc/sphinx/language/core/assumptions.rst
index 41e1c30f0d..a38282d41a 100644
--- a/doc/sphinx/language/core/assumptions.rst
+++ b/doc/sphinx/language/core/assumptions.rst
@@ -117,7 +117,7 @@ Assumptions
Assumptions extend the environment with axioms, parameters, hypotheses
or variables. An assumption binds an :n:`@ident` to a :n:`@type`. It is accepted
-by Coq if and only if this :n:`@type` is a correct type in the environment
+by |Coq| if and only if this :n:`@type` is a correct type in the environment
preexisting the declaration and if :n:`@ident` was not previously defined in
the same module. This :n:`@type` is considered to be the type (or
specification, or statement) assumed by :n:`@ident` and we say that :n:`@ident`
@@ -141,8 +141,8 @@ has type :n:`@type`.
of_type ::= {| : | :> } @type
These commands bind one or more :n:`@ident`\(s) to specified :n:`@type`\(s) as their specifications in
- the global context. The fact asserted by the :n:`@type` (or, equivalently, the existence
- of an object of this type) is accepted as a postulate.
+ the global context. The fact asserted by :n:`@type` (or, equivalently, the existence
+ of an object of this type) is accepted as a postulate. They accept the :attr:`program` attribute.
:cmd:`Axiom`, :cmd:`Conjecture`, :cmd:`Parameter` and their plural forms
are equivalent. They can take the :attr:`local` :term:`attribute`,
@@ -155,6 +155,10 @@ has type :n:`@type`.
is closed, the :n:`@ident`\(s) become undefined and every object depending on them will be explicitly
parameterized (i.e., the variables are *discharged*). See Section :ref:`section-mechanism`.
+ :n:`:>`
+ If specified, :token:`ident_decl` is automatically
+ declared as a coercion to the class of its type. See :ref:`coercions`.
+
The :n:`Inline` clause is only relevant inside functors. See :cmd:`Module`.
.. example:: Simple assumptions
diff --git a/doc/sphinx/language/core/basic.rst b/doc/sphinx/language/core/basic.rst
index 45bdc019ac..dfa2aaf8ff 100644
--- a/doc/sphinx/language/core/basic.rst
+++ b/doc/sphinx/language/core/basic.rst
@@ -113,7 +113,7 @@ Identifiers
Numbers
Numbers are sequences of digits with an optional fractional part
- and exponent, optionally preceded by a minus sign. Hexadecimal numerals
+ and exponent, optionally preceded by a minus sign. Hexadecimal numbers
start with ``0x`` or ``0X``. :n:`@bigint` are integers;
numbers without fractional nor exponent parts. :n:`@bignat` are non-negative
integers. Underscores embedded in the digits are ignored, for example
@@ -134,7 +134,7 @@ Numbers
hexdigit ::= {| 0 .. 9 | a .. f | A .. F }
:n:`@integer` and :n:`@natural` are limited to the range that fits
- into an OCaml integer (63-bit integers on most architectures).
+ into an |OCaml| integer (63-bit integers on most architectures).
:n:`@bigint` and :n:`@bignat` have no range limitation.
The :ref:`standard library <thecoqlibrary>` provides some
@@ -152,8 +152,8 @@ Strings
:token:`string`.
Keywords
- The following character sequences are keywords defined in the main Coq grammar
- that cannot be used as identifiers (even when starting Coq with the `-noinit`
+ The following character sequences are keywords defined in the main |Coq| grammar
+ that cannot be used as identifiers (even when starting |Coq| with the `-noinit`
command-line flag)::
_ Axiom CoFixpoint Definition Fixpoint Hypothesis Parameter Prop
@@ -168,11 +168,11 @@ Keywords
keywords.
Other tokens
- The following character sequences are tokens defined in the main Coq grammar
- (even when starting Coq with the `-noinit` command-line flag)::
+ The following character sequences are tokens defined in the main |Coq| grammar
+ (even when starting |Coq| with the `-noinit` command-line flag)::
! #[ % & ' ( () ) * + , - ->
- . .( .. ... / : ::= := :> :>> ; < <+ <- <:
+ . .( .. ... / : ::= := :> ; < <+ <- <:
<<: <= = => > >-> >= ? @ @{ [ ] _
`( `{ { {| | }
@@ -325,10 +325,10 @@ rest of the |Coq| manual: :term:`terms <term>` and :term:`types
boldface label "Command:". Commands are listed in the
:ref:`command_index`. Example:
- .. cmd:: Comments {* @string }
+ .. cmd:: Comments {* {| @one_term | @string | @natural } }
- This command prints "Comments ok" and does not change anything
- to the state of the document.
+ Prints "Comments ok" and does not change
+ the state of the document.
tactic
diff --git a/doc/sphinx/language/core/coinductive.rst b/doc/sphinx/language/core/coinductive.rst
index c034b7f302..2e5dff42ac 100644
--- a/doc/sphinx/language/core/coinductive.rst
+++ b/doc/sphinx/language/core/coinductive.rst
@@ -28,8 +28,8 @@ More information on co-inductive definitions can be found in
This command supports the :attr:`universes(polymorphic)`,
:attr:`universes(monomorphic)`, :attr:`universes(template)`,
:attr:`universes(notemplate)`, :attr:`universes(cumulative)`,
- :attr:`universes(noncumulative)` and :attr:`private(matching)`
- attributes.
+ :attr:`universes(noncumulative)`, :attr:`private(matching)`
+ and :attr:`using` attributes.
.. example::
@@ -76,7 +76,7 @@ propositional η-equality, which itself would require full η-conversion for
subject reduction to hold, but full η-conversion is not acceptable as it would
make type checking undecidable.
-Since the introduction of primitive records in Coq 8.5, an alternative
+Since the introduction of primitive records in |Coq| 8.5, an alternative
presentation is available, called *negative co-inductive types*. This consists
in defining a co-inductive type as a primitive record type through its
projections. Such a technique is akin to the *co-pattern* style that can be
@@ -115,7 +115,7 @@ equality:
Axiom Stream_ext : forall (s1 s2: Stream), EqSt s1 s2 -> s1 = s2.
-As of Coq 8.9, it is now advised to use negative co-inductive types rather than
+As of |Coq| 8.9, it is now advised to use negative co-inductive types rather than
their positive counterparts.
.. seealso::
@@ -195,7 +195,7 @@ Top-level definitions of co-recursive functions
As in the :cmd:`Fixpoint` command, the :n:`with` clause allows simultaneously
defining several mutual cofixpoints.
- If :n:`@term` is omitted, :n:`@type` is required and Coq enters proof editing mode.
+ If :n:`@term` is omitted, :n:`@type` is required and |Coq| enters proof editing 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 constant
for which the computational behavior is relevant. See :ref:`proof-editing-mode`.
diff --git a/doc/sphinx/language/core/definitions.rst b/doc/sphinx/language/core/definitions.rst
index 42203d9d65..1681eee6e7 100644
--- a/doc/sphinx/language/core/definitions.rst
+++ b/doc/sphinx/language/core/definitions.rst
@@ -87,10 +87,10 @@ Section :ref:`typing-rules`.
computation on :n:`@term`.
These commands also support the :attr:`universes(polymorphic)`,
- :attr:`universes(monomorphic)`, :attr:`program` and
- :attr:`canonical` attributes.
+ :attr:`universes(monomorphic)`, :attr:`program` (see :ref:`program_definition`),
+ :attr:`canonical` and :attr:`using` attributes.
- If :n:`@term` is omitted, :n:`@type` is required and Coq enters proof editing mode.
+ If :n:`@term` is omitted, :n:`@type` is required and |Coq| enters proof editing 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 constant
for which the computational behavior is relevant. See :ref:`proof-editing-mode`.
@@ -135,11 +135,13 @@ Chapter :ref:`Tactics`. The basic assertion command is:
| Proposition
| Property
- After the statement is asserted, Coq needs a proof. Once a proof of
+ After the statement is asserted, |Coq| 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
the theorem is bound to the name :n:`@ident` in the environment.
+ These commands accept the :attr:`program` attribute. See :ref:`program_lemma`.
+
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 co-inductive type. It is equivalent to
@@ -157,6 +159,8 @@ Chapter :ref:`Tactics`. 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:`using` attribute.
+
.. exn:: The term @term has type @type which should be Set, Prop or Type.
:undocumented:
@@ -172,7 +176,7 @@ Chapter :ref:`Tactics`. The basic assertion command is:
This feature, called nested proofs, is disabled by default.
To activate it, turn the :flag:`Nested Proofs Allowed` flag on.
-Proofs start with the keyword :cmd:`Proof`. Then Coq enters the proof editing mode
+Proofs start with the keyword :cmd:`Proof`. Then |Coq| enters the proof editing mode
until the proof is completed. In proof editing mode, the user primarily enters
tactics, which are described in chapter :ref:`Tactics`. The user may also enter
commands to manage the proof editing mode. They are described in Chapter
diff --git a/doc/sphinx/language/core/index.rst b/doc/sphinx/language/core/index.rst
index de780db267..c7b1df28db 100644
--- a/doc/sphinx/language/core/index.rst
+++ b/doc/sphinx/language/core/index.rst
@@ -4,7 +4,7 @@
Core language
=============
-At the heart of the Coq proof assistant is the Coq kernel. While
+At the heart of the |Coq| proof assistant is the |Coq| kernel. While
users have access to a language with many convenient features such as
:ref:`notations <syntax-extensions-and-notation-scopes>`,
:ref:`implicit arguments <ImplicitArguments>`, etc. (presented in the
diff --git a/doc/sphinx/language/core/inductive.rst b/doc/sphinx/language/core/inductive.rst
index 4cdfba146a..1642482bb1 100644
--- a/doc/sphinx/language/core/inductive.rst
+++ b/doc/sphinx/language/core/inductive.rst
@@ -13,11 +13,11 @@ Inductive types
.. prodn::
inductive_definition ::= {? > } @ident_decl {* @binder } {? %| {* @binder } } {? : @type } {? := {? @constructors_or_record } } {? @decl_notations }
constructors_or_record ::= {? %| } {+| @constructor }
- | {? @ident } %{ {*; @record_field } %}
+ | {? @ident } %{ {*; @record_field } {? ; } %}
constructor ::= @ident {* @binder } {? @of_type }
This command defines one or more
- inductive types and its constructors. Coq generates destructors
+ inductive types and its constructors. |Coq| generates destructors
depending on the universe that the inductive type belongs to.
The destructors are named :n:`@ident`\ ``_rect``, :n:`@ident`\ ``_ind``,
@@ -342,9 +342,9 @@ Recursive functions: fix
.. insertprodn term_fix fixannot
.. prodn::
- term_fix ::= let fix @fix_body in @term
- | fix @fix_body {? {+ with @fix_body } for @ident }
- fix_body ::= @ident {* @binder } {? @fixannot } {? : @type } := @term
+ term_fix ::= let fix @fix_decl in @term
+ | fix @fix_decl {? {+ with @fix_decl } for @ident }
+ fix_decl ::= @ident {* @binder } {? @fixannot } {? : @type } := @term
fixannot ::= %{ struct @ident %}
| %{ wf @one_term @ident %}
| %{ measure @one_term {? @ident } {? @one_term } %}
@@ -361,7 +361,11 @@ syntax: :n:`let fix @ident {* @binder } := @term in` stands for
Some options of :n:`@fixannot` are only supported in specific constructs. :n:`fix` and :n:`let fix`
only support the :n:`struct` option, while :n:`wf` and :n:`measure` are only supported in
-commands such as :cmd:`Function` and :cmd:`Program Fixpoint`.
+commands such as :cmd:`Fixpoint` (with the :attr:`program` attribute) and :cmd:`Function`.
+
+.. todo explanation of struct: see text above at the Fixpoint command, also
+ see https://github.com/coq/coq/pull/12936#discussion_r510716268 and above.
+ Consider whether to move the grammar for fixannot elsewhere
.. _Fixpoint:
@@ -379,7 +383,7 @@ constructions.
.. prodn::
fix_definition ::= @ident_decl {* @binder } {? @fixannot } {? : @type } {? := @term } {? @decl_notations }
- This command allows defining functions by pattern matching over inductive
+ Allows defining functions by pattern matching over inductive
objects using a fixed point construction. The meaning of this declaration is
to define :n:`@ident` as a recursive function with arguments specified by
the :n:`@binder`\s such that :n:`@ident` applied to arguments
@@ -388,6 +392,8 @@ constructions.
consequently :n:`forall {* @binder }, @type` and its value is equivalent
to :n:`fun {* @binder } => @term`.
+ This command accepts the :attr:`program` attribute.
+
To be accepted, a :cmd:`Fixpoint` definition has to satisfy syntactical
constraints on a special argument called the decreasing argument. They
are needed to ensure that the :cmd:`Fixpoint` definition always terminates.
@@ -399,17 +405,19 @@ constructions.
that satisfies the decreasing condition.
:cmd:`Fixpoint` without the :attr:`program` attribute does not support the
- :n:`wf` or :n:`measure` clauses of :n:`@fixannot`.
+ :n:`wf` or :n:`measure` clauses of :n:`@fixannot`. See :ref:`program_fixpoint`.
The :n:`with` clause allows simultaneously defining several mutual fixpoints.
It is especially useful when defining functions over mutually defined
inductive types. Example: :ref:`Mutual Fixpoints<example_mutual_fixpoints>`.
- If :n:`@term` is omitted, :n:`@type` is required and Coq enters proof editing mode.
+ If :n:`@term` is omitted, :n:`@type` is required and |Coq| enters proof editing 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 constant
for which the computational behavior is relevant. See :ref:`proof-editing-mode`.
+ This command accepts the :attr:`using` attribute.
+
.. note::
+ Some fixpoints may have several arguments that fit as decreasing
diff --git a/doc/sphinx/language/core/modules.rst b/doc/sphinx/language/core/modules.rst
index 866104d5d1..1309a47ff4 100644
--- a/doc/sphinx/language/core/modules.rst
+++ b/doc/sphinx/language/core/modules.rst
@@ -1001,12 +1001,12 @@ of the ``Require`` command can be used to bypass the implicit shortening
by providing an absolute root to the required file (see :ref:`compiled-files`).
There also exists another independent loadpath mechanism attached to
-OCaml object files (``.cmo`` or ``.cmxs``) rather than |Coq| object
-files as described above. The OCaml loadpath is managed using
-the option ``-I`` `path` (in the OCaml world, there is neither a
+|OCaml| object files (``.cmo`` or ``.cmxs``) rather than |Coq| object
+files as described above. The |OCaml| loadpath is managed using
+the option ``-I`` `path` (in the |OCaml| world, there is neither a
notion of logical name prefix nor a way to access files in
subdirectories of path). See the command :cmd:`Declare ML Module` in
-:ref:`compiled-files` to understand the need of the OCaml loadpath.
+:ref:`compiled-files` to understand the need of the |OCaml| loadpath.
See :ref:`command-line-options` for a more general view over the |Coq| command
line options.
diff --git a/doc/sphinx/language/core/primitive.rst b/doc/sphinx/language/core/primitive.rst
index 48647deeff..17f569ca2a 100644
--- a/doc/sphinx/language/core/primitive.rst
+++ b/doc/sphinx/language/core/primitive.rst
@@ -45,13 +45,13 @@ applications of these primitive operations.
The extraction of these primitives can be customized similarly to the extraction
of regular axioms (see :ref:`extraction`). Nonetheless, the :g:`ExtrOCamlInt63`
-module can be used when extracting to OCaml: it maps the Coq primitives to types
-and functions of a :g:`Uint63` module. Said OCaml module is not produced by
+module can be used when extracting to |OCaml|: it maps the |Coq| primitives to types
+and functions of a :g:`Uint63` module. That |OCaml| module is not produced by
extraction. Instead, it has to be provided by the user (if they want to compile
or execute the extracted code). For instance, an implementation of this module
-can be taken from the kernel of Coq.
+can be taken from the kernel of |Coq|.
-Literal values (at type :g:`Int63.int`) are extracted to literal OCaml values
+Literal values (at type :g:`Int63.int`) are extracted to literal |OCaml| values
wrapped into the :g:`Uint63.of_int` (resp. :g:`Uint63.of_int64`) constructor on
64-bit (resp. 32-bit) platforms. Currently, this cannot be customized (see the
function :g:`Uint63.compile` from the kernel).
@@ -94,13 +94,13 @@ to comply with the IEEE 754 standard for floating-point arithmetic.
The extraction of these primitives can be customized similarly to the extraction
of regular axioms (see :ref:`extraction`). Nonetheless, the :g:`ExtrOCamlFloats`
-module can be used when extracting to OCaml: it maps the Coq primitives to types
-and functions of a :g:`Float64` module. Said OCaml module is not produced by
+module can be used when extracting to |OCaml|: it maps the |Coq| primitives to types
+and functions of a :g:`Float64` module. Said |OCaml| module is not produced by
extraction. Instead, it has to be provided by the user (if they want to compile
or execute the extracted code). For instance, an implementation of this module
-can be taken from the kernel of Coq.
+can be taken from the kernel of |Coq|.
-Literal values (of type :g:`Float64.t`) are extracted to literal OCaml
+Literal values (of type :g:`Float64.t`) are extracted to literal |OCaml|
values (of type :g:`float`) written in hexadecimal notation and
wrapped into the :g:`Float64.of_float` constructor, e.g.:
:g:`Float64.of_float (0x1p+0)`.
@@ -144,19 +144,19 @@ operations.
The extraction of these primitives can be customized similarly to the extraction
of regular axioms (see :ref:`extraction`). Nonetheless, the :g:`ExtrOCamlPArray`
-module can be used when extracting to OCaml: it maps the Coq primitives to types
-and functions of a :g:`Parray` module. Said OCaml module is not produced by
+module can be used when extracting to |OCaml|: it maps the |Coq| primitives to types
+and functions of a :g:`Parray` module. Said |OCaml| module is not produced by
extraction. Instead, it has to be provided by the user (if they want to compile
or execute the extracted code). For instance, an implementation of this module
-can be taken from the kernel of Coq (see ``kernel/parray.ml``).
+can be taken from the kernel of |Coq| (see ``kernel/parray.ml``).
-Coq's primitive arrays are persistent data structures. Semantically, a set operation
+|Coq|'s primitive arrays are persistent data structures. Semantically, a set operation
``t.[i <- a]`` represents a new array that has the same values as ``t``, except
at position ``i`` where its value is ``a``. The array ``t`` still exists, can
still be used and its values were not modified. Operationally, the implementation
-of Coq's primitive arrays is optimized so that the new array ``t.[i <- a]`` does not
+of |Coq|'s primitive arrays is optimized so that the new array ``t.[i <- a]`` does not
copy all of ``t``. The details are in section 2.3 of :cite:`ConchonFilliatre07wml`.
-In short, the implementation keeps one version of ``t`` as an OCaml native array and
+In short, the implementation keeps one version of ``t`` as an |OCaml| native array and
other versions as lists of modifications to ``t``. Accesses to the native array
version are constant time operations. However, accesses to versions where all the cells of
the array are modified have O(n) access time, the same as a list. The version that is kept as the native array
diff --git a/doc/sphinx/language/core/records.rst b/doc/sphinx/language/core/records.rst
index cd44d06e67..e6df3ee9f5 100644
--- a/doc/sphinx/language/core/records.rst
+++ b/doc/sphinx/language/core/records.rst
@@ -18,27 +18,36 @@ expressions. In this sense, the :cmd:`Record` construction allows defining
.. insertprodn record_definition field_def
.. prodn::
- record_definition ::= {? > } @ident_decl {* @binder } {? : @type } {? @ident } %{ {*; @record_field } %} {? @decl_notations }
+ record_definition ::= {? > } @ident_decl {* @binder } {? : @sort } {? := {? @ident } %{ {*; @record_field } {? ; } %} }
record_field ::= {* #[ {*, @attribute } ] } @name {? @field_body } {? %| @natural } {? @decl_notations }
field_body ::= {* @binder } @of_type
| {* @binder } @of_type := @term
| {* @binder } := @term
- term_record ::= %{%| {* @field_def } %|%}
+ term_record ::= %{%| {*; @field_def } {? ; } %|%}
field_def ::= @qualid {* @binder } := @term
-
Each :n:`@record_definition` defines a record named by :n:`@ident_decl`.
The constructor name is given by :n:`@ident`.
If the constructor name is not specified, then the default name :n:`Build_@ident` is used,
where :n:`@ident` is the record name.
- If :n:`@type` is
- omitted, the default type is :math:`\Type`. The identifiers inside the brackets are the field names.
- The type of each field :n:`@ident` is :n:`forall {* @binder }, @type`.
+ If :token:`sort` is omitted, the default sort is Type.
Notice that the type of an identifier can depend on a previously-given identifier. Thus the
order of the fields is important. :n:`@binder` parameters may be applied to the record as a whole
or to individual fields.
+ .. todo
+ "Record foo2:Prop := { a }." gives the error "Cannot infer this placeholder of type "Type",
+ while "Record foo2:Prop := { a:Type }." gives the output "foo2 is defined.
+ a cannot be defined because it is informative and foo2 is not."
+ Your thoughts?
+
+ :n:`{? > }`
+ If provided, the constructor name is automatically declared as
+ a coercion from the class of the last field type to the record name
+ (this may fail if the uniform inheritance condition is not
+ satisfied). See :ref:`coercions`.
+
Notations can be attached to fields using the :n:`@decl_notations` annotation.
:cmd:`Record` and :cmd:`Structure` are synonyms.
@@ -76,7 +85,7 @@ Let us now see the work done by the ``Record`` macro. First the macro
generates a variant type definition with just one constructor:
:n:`Variant @ident {* @binder } : @sort := @ident__0 {* @binder }`.
-To build an object of type :token:`ident`, one should provide the constructor
+To build an object of type :token:`ident`, provide the constructor
:n:`@ident__0` with the appropriate number of terms filling the fields of the record.
.. example::
diff --git a/doc/sphinx/language/core/sections.rst b/doc/sphinx/language/core/sections.rst
index df50dbafe3..c70f7a347b 100644
--- a/doc/sphinx/language/core/sections.rst
+++ b/doc/sphinx/language/core/sections.rst
@@ -84,7 +84,7 @@ Sections create local contexts which can be shared across multiple definitions.
will be wrapped with a :n:`@term_let` with the same declaration.
As for :cmd:`Definition`, :cmd:`Fixpoint` and :cmd:`CoFixpoint`,
- if :n:`@term` is omitted, :n:`@type` is required and Coq enters proof editing mode.
+ if :n:`@term` is omitted, :n:`@type` is required and |Coq| enters proof editing 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 constant
for which the computational behavior is relevant. See :ref:`proof-editing-mode`.
diff --git a/doc/sphinx/language/core/variants.rst b/doc/sphinx/language/core/variants.rst
index 2904250e41..645986be9c 100644
--- a/doc/sphinx/language/core/variants.rst
+++ b/doc/sphinx/language/core/variants.rst
@@ -29,6 +29,7 @@ Private (matching) inductive types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. attr:: private(matching)
+ :name: private(matching); Private
This attribute can be used to forbid the use of the :g:`match`
construct on objects of this inductive type outside of the module
diff --git a/doc/sphinx/language/extensions/arguments-command.rst b/doc/sphinx/language/extensions/arguments-command.rst
index 0ae9fab7ab..f8c0e23696 100644
--- a/doc/sphinx/language/extensions/arguments-command.rst
+++ b/doc/sphinx/language/extensions/arguments-command.rst
@@ -86,6 +86,7 @@ Setting properties of a function's arguments
the parameter name used in the function definition). Unless `rename` is specified,
the list of :n:`@name`\s must be a prefix of the formal parameters, including all implicit
arguments. `_` can be used to skip over a formal parameter.
+ The construct :n:`@name {? % @scope }` declares :n:`@name` as non-implicit if `clear implicits` is specified or at least one other name is declared implicit in the same list of :n:`@name`\s.
:token:`scope` can be either a scope name or its delimiting key. See :ref:`binding_to_scope`.
`clear implicits`
@@ -377,7 +378,7 @@ Effects of :cmd:`Arguments` on unfolding
Bidirectionality hints
~~~~~~~~~~~~~~~~~~~~~~
-When type-checking an application, Coq normally does not use information from
+When type-checking an application, |Coq| normally does not use information from
the context to infer the types of the arguments. It only checks after the fact
that the type inferred for the application is coherent with the expected type.
Bidirectionality hints make it possible to specify that after type-checking the
@@ -394,7 +395,7 @@ the context to help inferring the types of the remaining arguments.
* *type inference*, with is inferring the type of a construct by analyzing the construct.
Methods that combine these approaches are known as *bidirectional typing*.
- Coq normally uses only the first approach to infer the types of arguments,
+ |Coq| normally uses only the first approach to infer the types of arguments,
then later verifies that the inferred type is consistent with the expected type.
*Bidirectionality hints* specify to use both methods: after type checking the
first arguments of an application (appearing before the `&` in :cmd:`Arguments`),
@@ -416,7 +417,7 @@ type check the remaining arguments (in :n:`@arg_specs__2`).
Definition b2n (b : bool) := if b then 1 else 0.
Coercion b2n : bool >-> nat.
- Coq cannot automatically coerce existential statements over ``bool`` to
+ |Coq| cannot automatically coerce existential statements over ``bool`` to
statements over ``nat``, because the need for inserting a coercion is known
only from the expected type of a subterm:
@@ -431,7 +432,7 @@ type check the remaining arguments (in :n:`@arg_specs__2`).
Arguments ex_intro _ _ & _ _.
Check (ex_intro _ true _ : exists n : nat, n > 0).
-Coq will attempt to produce a term which uses the arguments you
+|Coq| will attempt to produce a term which uses the arguments you
provided, but in some cases involving Program mode the arguments after
the bidirectionality starts may be replaced by convertible but
syntactically different terms.
diff --git a/doc/sphinx/language/extensions/canonical.rst b/doc/sphinx/language/extensions/canonical.rst
index bfda8befff..38c9fa336d 100644
--- a/doc/sphinx/language/extensions/canonical.rst
+++ b/doc/sphinx/language/extensions/canonical.rst
@@ -159,7 +159,7 @@ of the terms that are compared.
End theory.
End EQ.
-We use Coq modules as namespaces. This allows us to follow the same
+We use |Coq| modules as namespaces. This allows us to follow the same
pattern and naming convention for the rest of the chapter. The base
namespace contains the definitions of the algebraic structure. To
keep the example small, the algebraic structure ``EQ.type`` we are
@@ -224,7 +224,7 @@ example work:
Fail Check forall (e : EQ.type) (a b : EQ.obj e), (a, b) == (a, b).
The error message is telling that |Coq| has no idea on how to compare
-pairs of objects. The following construction is telling Coq exactly
+pairs of objects. The following construction is telling |Coq| exactly
how to do that.
.. coqtop:: all
diff --git a/doc/sphinx/language/extensions/evars.rst b/doc/sphinx/language/extensions/evars.rst
index 20f4310d13..dc208a63a0 100644
--- a/doc/sphinx/language/extensions/evars.rst
+++ b/doc/sphinx/language/extensions/evars.rst
@@ -68,7 +68,7 @@ Inferable subterms
~~~~~~~~~~~~~~~~~~
Expressions often contain redundant pieces of information. Subterms that can be
-automatically inferred by Coq can be replaced by the symbol ``_`` and Coq will
+automatically inferred by |Coq| can be replaced by the symbol ``_`` and |Coq| will
guess the missing piece of information.
.. extracted from Gallina extensions chapter
diff --git a/doc/sphinx/language/extensions/implicit-arguments.rst b/doc/sphinx/language/extensions/implicit-arguments.rst
index f8375e93ce..9457505feb 100644
--- a/doc/sphinx/language/extensions/implicit-arguments.rst
+++ b/doc/sphinx/language/extensions/implicit-arguments.rst
@@ -115,7 +115,7 @@ application will include that argument. Otherwise, the argument is
*non-maximally inserted* and the partial application will not include that argument.
Each implicit argument can be declared to be inserted maximally or non
-maximally. In Coq, maximally inserted implicit arguments are written between curly braces
+maximally. In |Coq|, maximally inserted implicit arguments are written between curly braces
"{ }" and non-maximally inserted implicit arguments are written in square brackets "[ ]".
.. seealso:: :flag:`Maximal Implicit Insertion`
diff --git a/doc/sphinx/language/extensions/index.rst b/doc/sphinx/language/extensions/index.rst
index ed207ca743..ea7271179e 100644
--- a/doc/sphinx/language/extensions/index.rst
+++ b/doc/sphinx/language/extensions/index.rst
@@ -4,7 +4,7 @@
Language extensions
===================
-Elaboration extends the language accepted by the Coq kernel to make it
+Elaboration extends the language accepted by the |Coq| kernel to make it
easier to use. For example, this lets the user omit most type
annotations because they can be inferred, call functions with implicit
arguments which will be inferred as well, extend the syntax with
diff --git a/doc/sphinx/language/extensions/match.rst b/doc/sphinx/language/extensions/match.rst
index c36b9deef3..3c1983ee97 100644
--- a/doc/sphinx/language/extensions/match.rst
+++ b/doc/sphinx/language/extensions/match.rst
@@ -290,6 +290,43 @@ This example emphasizes what the printing settings offer.
Print snd.
+Conventions about unused pattern-matching variables
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Pattern-matching variables that are not used on the right-hand side of ``=>`` are
+considered the sign of a potential error. For instance, it could
+result from an undetected mispelled constant constructor. By default,
+a warning is issued in such situations.
+
+.. warn:: Unused variable @ident catches more than one case.
+
+ This indicates that an unused pattern variable :token:`ident`
+ occurs in a pattern-matching clause used to complete at least two
+ cases of the pattern-matching problem.
+
+ The warning can be deactivated by using a variable name starting
+ with ``_`` or by setting ``Set Warnings
+ "-unused-pattern-matching-variable"``.
+
+ Here is an example where the warning is activated.
+
+ .. example::
+
+ .. coqtop:: none
+
+ Set Warnings "-unused-pattern-matching-variable".
+
+ .. coqtop:: all
+
+ Definition is_zero (o : option nat) := match o with
+ | Some 0 => true
+ | x => false
+ end.
+
+ .. coqtop:: none
+
+ Set Warnings "+unused-pattern-matching-variable".
+
Patterns
--------
@@ -639,7 +676,7 @@ Dependent pattern matching
~~~~~~~~~~~~~~~~~~~~~~~~~~
The examples given so far do not need an explicit elimination
-predicate because all the |rhs| have the same type and Coq
+predicate because all the |rhs| have the same type and |Coq|
succeeds to synthesize it. Unfortunately when dealing with dependent
patterns it often happens that we need to write cases where the types
of the |rhs| are different instances of the elimination predicate. The
diff --git a/doc/sphinx/practical-tools/coq-commands.rst b/doc/sphinx/practical-tools/coq-commands.rst
index ec182ce08f..59e1c65a49 100644
--- a/doc/sphinx/practical-tools/coq-commands.rst
+++ b/doc/sphinx/practical-tools/coq-commands.rst
@@ -24,13 +24,13 @@ develop his theories and proofs step by step. The |Coq| toplevel is run
by the command ``coqtop``.
There are two different binary images of |Coq|: the byte-code one and the
-native-code one (if OCaml provides a native-code compiler for
+native-code one (if |OCaml| provides a native-code compiler for
your platform, which is supposed in the following). By default,
``coqtop`` executes the native-code version; run ``coqtop.byte`` to get
the byte-code version.
-The byte-code toplevel is based on an OCaml toplevel (to
-allow dynamic linking of tactics). You can switch to the OCaml toplevel
+The byte-code toplevel is based on an |OCaml| toplevel (to
+allow dynamic linking of tactics). You can switch to the |OCaml| toplevel
with the command ``Drop.``, and come back to the |Coq|
toplevel with the command ``Coqloop.loop();;``.
@@ -61,7 +61,7 @@ By resource file
When |Coq| is launched, with either ``coqtop`` or ``coqc``, the
resource file ``$XDG_CONFIG_HOME/coq/coqrc.xxx``, if it exists, will
-be implicitly prepended to any document read by Coq, whether it is an
+be implicitly prepended to any document read by |Coq|, whether it is an
interactive session or a file to compile. Here, ``$XDG_CONFIG_HOME``
is the configuration directory of the user (by default it's ``~/.config``)
and ``xxx`` is the version number (e.g. 8.8). If
@@ -133,7 +133,7 @@ The following command-line options are recognized by the commands ``coqc``
and ``coqtop``, unless stated otherwise:
:-I *directory*, -include *directory*: Add physical path *directory*
- to the OCaml loadpath.
+ to the |OCaml| loadpath.
.. seealso::
@@ -253,8 +253,8 @@ and ``coqtop``, unless stated otherwise:
.. warning:: This makes the logic inconsistent.
:-mangle-names *ident*: *Experimental.* Do not depend on this option. Replace
- Coq's auto-generated name scheme with names of the form *ident0*, *ident1*,
- etc. Within Coq, the :flag:`Mangle Names` flag turns this behavior on,
+ |Coq|'s auto-generated name scheme with names of the form *ident0*, *ident1*,
+ etc. Within |Coq|, the :flag:`Mangle Names` flag turns this behavior on,
and the :opt:`Mangle Names Prefix` option sets the prefix to use. This feature
is intended to be used as a linter for developments that want to be robust to
changes in the auto-generated name scheme. The options are provided to
@@ -264,7 +264,7 @@ and ``coqtop``, unless stated otherwise:
type of the option. For flags :n:`@setting_name` is equivalent to
:n:`@setting_name=true`. For instance ``-set "Universe Polymorphism"``
will enable :flag:`Universe Polymorphism`. Note that the quotes are
- shell syntax, Coq does not see them.
+ shell syntax, |Coq| does not see them.
See the :ref:`note above <interleave-command-line>` regarding the order
of command-line options.
:-unset *string*: As ``-set`` but used to disable options and flags.
@@ -304,7 +304,7 @@ and ``coqtop``, unless stated otherwise:
Compiled interfaces (produced using ``-vos``)
----------------------------------------------
-Compiled interfaces help saving time while developing Coq formalizations,
+Compiled interfaces help saving time while developing |Coq| formalizations,
by compiling the formal statements exported by a library independently of
the proofs that it contains.
@@ -473,7 +473,7 @@ set of reflexive transitive dependencies of set :math:`S`. Then:
context without type checking. Basic integrity checks (checksums) are
nonetheless performed.
-As a rule of thumb, -admit can be used to tell Coq that some libraries
+As a rule of thumb, -admit can be used to tell |Coq| that some libraries
have already been checked. So ``coqchk A B`` can be split in ``coqchk A`` &&
``coqchk B -admit A`` without type checking any definition twice. Of
course, the latter is slightly slower since it makes more disk access.
diff --git a/doc/sphinx/practical-tools/coqide.rst b/doc/sphinx/practical-tools/coqide.rst
index 42e752841d..64b433115c 100644
--- a/doc/sphinx/practical-tools/coqide.rst
+++ b/doc/sphinx/practical-tools/coqide.rst
@@ -5,9 +5,9 @@
|Coq| Integrated Development Environment
========================================
-The Coq Integrated Development Environment is a graphical tool, to be
+The |Coq| Integrated Development Environment is a graphical tool, to be
used as a user-friendly replacement to `coqtop`. Its main purpose is to
-allow the user to navigate forward and backward into a Coq vernacular
+allow the user to navigate forward and backward into a |Coq| vernacular
file, executing corresponding commands or undoing them respectively.
|CoqIDE| is run by typing the command `coqide` on the command line.
@@ -23,7 +23,7 @@ no meaning for |CoqIDE| being ignored.
:alt: |CoqIDE| main screen
A sample |CoqIDE| main screen, while navigating into a file `Fermat.v`,
-is shown in the figure :ref:`CoqIDE main screen <coqide_mainscreen>`.
+is shown in the figure :ref:`|CoqIDE| main screen <coqide_mainscreen>`.
At the top is a menu bar, and a tool bar
below it. The large window on the left is displaying the various
*script buffers*. The upper right window is the *goal window*, where
@@ -39,7 +39,7 @@ The *File* menu allows you to open files or create some, save them,
print or export them into various formats. Among all these buffers,
there is always one which is the current *running buffer*, whose name
is displayed on a background in the *processed* color (green by default), which
-is the one where Coq commands are currently executed.
+is the one where |Coq| commands are currently executed.
Buffers may be edited as in any text editor, and classical basic
editing commands (Copy/Paste, …) are available in the *Edit* menu.
@@ -47,7 +47,7 @@ editing commands (Copy/Paste, …) are available in the *Edit* menu.
editing commands, you may launch your favorite text editor on the
current buffer, using the *Edit/External Editor* menu.
-Interactive navigation into Coq scripts
+Interactive navigation into |Coq| scripts
--------------------------------------------
The running buffer is the one where navigation takes place. The toolbar offers
@@ -58,7 +58,7 @@ processed color. If that command fails, the error message is displayed in the
message window, and the location of the error is emphasized by an underline in
the error foreground color (red by default).
-In the figure :ref:`CoqIDE main screen <coqide_mainscreen>`,
+In the figure :ref:`|CoqIDE| main screen <coqide_mainscreen>`,
the running buffer is `Fermat.v`, all commands until
the ``Theorem`` have been already executed, and the user tried to go
forward executing ``Induction n``. That command failed because no such
@@ -153,7 +153,7 @@ as standard |GtkSourceView| styles are available. Other styles can be
added e.g. in ``$HOME/.local/share/gtksourceview-3.0/styles/`` (see
the general documentation about |GtkSourceView| for the various
possibilities). Note that the style of the rest of graphical part of
-Coqide is not under the control of |GtkSourceView| but of GTK+ and
+|CoqIDE| is not under the control of |GtkSourceView| but of GTK+ and
governed by files such as ``settings.ini`` and ``gtk.css`` in
``$XDG_CONFIG_HOME/gtk-3.0`` or files in
``$HOME/.themes/NameOfTheme/gtk-3.0``, as well as the environment
@@ -219,7 +219,7 @@ mathematical symbols ∀ and ∃, you may define:
: type_scope.
There exists a small set of such notations already defined, in the
-file `utf8.v` of Coq library, so you may enable them just by
+file `utf8.v` of |Coq| library, so you may enable them just by
``Require Import Unicode.Utf8`` inside |CoqIDE|, or equivalently,
by starting |CoqIDE| with ``coqide -l utf8``.
@@ -237,7 +237,7 @@ use antialiased fonts or not, by setting the environment variable
Bindings for input of Unicode symbols
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-CoqIDE supports a builtin mechanism to input non-ASCII symbols.
+|CoqIDE| supports a builtin mechanism to input non-ASCII symbols.
For example, to input ``π``, it suffices to type ``\pi`` then press the
combination of key ``Shift+Space`` (default key binding). Often, it
suffices to type a prefix of the latex token, e.g. typing ``\p``
diff --git a/doc/sphinx/practical-tools/utilities.rst b/doc/sphinx/practical-tools/utilities.rst
index daae46ad11..c3286199e8 100644
--- a/doc/sphinx/practical-tools/utilities.rst
+++ b/doc/sphinx/practical-tools/utilities.rst
@@ -8,8 +8,8 @@ The distribution provides utilities to simplify some tedious works
beside proof development, tactics writing or documentation.
-Using Coq as a library
-----------------------
+Using |Coq| as a library
+------------------------
In previous versions, ``coqmktop`` was used to build custom
toplevels - for example for better debugging or custom static
@@ -37,10 +37,10 @@ and similarly for other plugins.
Building a |Coq| project
------------------------
-As of today it is possible to build Coq projects using two tools:
+As of today it is possible to build |Coq| projects using two tools:
-- coq_makefile, which is distributed by Coq and is based on generating a makefile,
-- Dune, the standard OCaml build tool, which, since version 1.9, supports building Coq libraries.
+- coq_makefile, which is distributed by |Coq| and is based on generating a makefile,
+- Dune, the standard |OCaml| build tool, which, since version 1.9, supports building |Coq| libraries.
.. _coq_makefile:
@@ -142,7 +142,7 @@ Here we describe only few of them.
:CAMLPKGS:
can be used to specify third party findlib packages, and is
- passed to the OCaml compiler on building or linking of modules. Eg:
+ passed to the |OCaml| compiler on building or linking of modules. Eg:
``-package yojson``.
:CAMLFLAGS:
can be used to specify additional flags to the |OCaml|
@@ -150,15 +150,15 @@ Here we describe only few of them.
:OCAMLWARN:
it contains a default of ``-warn-error +a-3``, useful to modify
this setting; beware this is not recommended for projects in
- Coq's CI.
+ |Coq|'s CI.
:COQC, COQDEP, COQDOC:
can be set in order to use alternative binaries
(e.g. wrappers)
:COQ_SRC_SUBDIRS:
can be extended by including other paths in which ``*.cm*`` files
are searched. For example ``COQ_SRC_SUBDIRS+=user-contrib/Unicoq``
- lets you build a plugin containing OCaml code that depends on the
- OCaml code of ``Unicoq``
+ lets you build a plugin containing |OCaml| code that depends on the
+ |OCaml| code of ``Unicoq``
:COQFLAGS:
override the flags passed to ``coqc``. By default ``-q``.
:COQEXTRAFLAGS:
@@ -172,7 +172,7 @@ Here we describe only few of them.
:COQDOCEXTRAFLAGS:
extend the flags passed to ``coqdoc``
:COQLIBINSTALL, COQDOCINSTALL:
- specify where the Coq libraries and documentation will be installed.
+ specify where the |Coq| libraries and documentation will be installed.
By default a combination of ``$(DESTDIR)`` (if defined) with
``$(COQLIB)/user-contrib`` and ``$(DOCDIR)/user-contrib``.
@@ -560,22 +560,22 @@ Building a |Coq| project with Dune
.. note::
- Dune's Coq support is still experimental; we strongly recommend
+ Dune's |Coq| support is still experimental; we strongly recommend
using Dune 2.3 or later.
.. note::
- The canonical documentation for the Coq Dune extension is
+ The canonical documentation for the |Coq| Dune extension is
maintained upstream; please refer to the `Dune manual
<https://dune.readthedocs.io/>`_ for up-to-date information. This
documentation is up to date for Dune 2.3.
-Building a Coq project with Dune requires setting up a Dune project
+Building a |Coq| project with Dune requires setting up a Dune project
for your files. This involves adding a ``dune-project`` and
``pkg.opam`` file to the root (``pkg.opam`` can be empty or generated
by Dune itself), and then providing ``dune`` files in the directories
your ``.v`` files are placed. For the experimental version "0.1" of
-the Coq Dune language, |Coq| library stanzas look like:
+the |Coq| Dune language, |Coq| library stanzas look like:
.. code:: scheme
@@ -592,12 +592,12 @@ the library under ``<module_prefix>``. If you declare an
``<opam_package>``, an ``.install`` file for the library will be
generated; the optional ``(modules <ordered_set_lang>)`` field allows
you to filter the list of modules, and ``(libraries
-<ocaml_libraries>)`` allows the Coq theory depend on ML plugins. For
-the moment, Dune relies on Coq's standard mechanisms (such as
-``COQPATH``) to locate installed Coq libraries.
+<ocaml_libraries>)`` allows the |Coq| theory depend on ML plugins. For
+the moment, Dune relies on |Coq|'s standard mechanisms (such as
+``COQPATH``) to locate installed |Coq| libraries.
By default Dune will skip ``.v`` files present in subdirectories. In
-order to enable the usual recursive organization of Coq projects add
+order to enable the usual recursive organization of |Coq| projects add
.. code:: scheme
@@ -611,7 +611,7 @@ of your project.
.. example::
- A typical stanza for a Coq plugin is split into two parts. An OCaml build directive, which is standard Dune:
+ A typical stanza for a |Coq| plugin is split into two parts. An |OCaml| build directive, which is standard Dune:
.. code:: scheme
@@ -623,7 +623,7 @@ of your project.
(coq.pp (modules g_equations))
- And a Coq-specific part that depends on it via the ``libraries`` field:
+ And a |Coq|-specific part that depends on it via the ``libraries`` field:
.. code:: scheme
@@ -656,10 +656,10 @@ command ``Declare ML Module``.
See the man page of ``coqdep`` for more details and options.
Both Dune and ``coq_makefile`` use ``coqdep`` to compute the
-dependencies among the files part of a Coq project.
+dependencies among the files part of a |Coq| project.
-Embedded Coq phrases inside |Latex| documents
----------------------------------------------
+Embedded |Coq| phrases inside |Latex| documents
+-----------------------------------------------
When writing documentation about a proof development, one may want
to insert |Coq| phrases inside a |Latex| document, possibly together
@@ -670,7 +670,7 @@ evaluates them, and insert the outcome of the evaluation after each
phrase.
Starting with a file ``file.tex`` containing |Coq| phrases, the ``coq-tex``
-filter produces a file named ``file.v.tex`` with the Coq outcome.
+filter produces a file named ``file.v.tex`` with the |Coq| outcome.
There are options to produce the |Coq| parts in smaller font, italic,
between horizontal rules, etc. See the man page of ``coq-tex`` for more
diff --git a/doc/sphinx/proof-engine/ltac.rst b/doc/sphinx/proof-engine/ltac.rst
index f18569c7fd..8663ac646b 100644
--- a/doc/sphinx/proof-engine/ltac.rst
+++ b/doc/sphinx/proof-engine/ltac.rst
@@ -8,7 +8,7 @@ This chapter documents the tactic language |Ltac|.
We start by giving the syntax followed by the informal
semantics. To learn more about the language and
especially about its foundations, please refer to :cite:`Del00`.
-(Note the examples in the paper won't work as-is; Coq has evolved
+(Note the examples in the paper won't work as-is; |Coq| has evolved
since the paper was written.)
.. example:: Basic tactic macros
@@ -41,7 +41,7 @@ higher precedence than `+`. Usually `a/b/c` is given the :gdef:`left associativ
interpretation `(a/b)/c` rather than the :gdef:`right associative` interpretation
`a/(b/c)`.
-In Coq, the expression :n:`try repeat @tactic__1 || @tactic__2; @tactic__3; @tactic__4`
+In |Coq|, the expression :n:`try repeat @tactic__1 || @tactic__2; @tactic__3; @tactic__4`
is interpreted as :n:`(try (repeat (@tactic__1 || @tactic__2)); @tactic__3); @tactic__4`
because `||` is part of :token:`ltac_expr2`, which has higher precedence than
:tacn:`try` and :tacn:`repeat` (at the level of :token:`ltac_expr3`), which
@@ -161,7 +161,7 @@ Syntactic values
Provides a way to use the syntax and semantics of a grammar nonterminal as a
value in an :token:`ltac_expr`. The table below describes the most useful of
these. You can see the others by running ":cmd:`Print Grammar` `tactic`" and
-examining the part at the end under "Entry tactic:tactic_arg".
+examining the part at the end under "Entry tactic:tactic_value".
:token:`ident`
name of a grammar nonterminal listed in the table
@@ -784,7 +784,7 @@ single success:
Checking for a single success: exactly_once
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Coq provides an experimental way to check that a tactic has *exactly
+|Coq| provides an experimental way to check that a tactic has *exactly
one* success:
.. tacn:: exactly_once @ltac_expr3
@@ -813,7 +813,7 @@ one* success:
Checking for failure: assert_fails
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Coq defines an |Ltac| tactic in `Init.Tactics` to check that a tactic *fails*:
+|Coq| defines an |Ltac| tactic in `Init.Tactics` to check that a tactic *fails*:
.. tacn:: assert_fails @ltac_expr3
:name: assert_fails
@@ -859,7 +859,7 @@ Coq defines an |Ltac| tactic in `Init.Tactics` to check that a tactic *fails*:
Checking for success: assert_succeeds
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Coq defines an |Ltac| tactic in `Init.Tactics` to check that a tactic has *at least one*
+|Coq| defines an |Ltac| tactic in `Init.Tactics` to check that a tactic has *at least one*
success:
.. tacn:: assert_succeeds @ltac_expr3
@@ -879,7 +879,8 @@ Print/identity tactic: idtac
.. tacn:: idtac {* {| @ident | @string | @natural } }
:name: idtac
- Leaves the proof unchanged and prints the given tokens. Strings and integers are printed
+ Leaves the proof unchanged and prints the given tokens. :token:`String<string>`\s
+ and :token:`natural`\s are printed
literally. If :token:`ident` is an |Ltac| variable, its contents are printed; if not, it
is an error.
@@ -888,7 +889,7 @@ Print/identity tactic: idtac
Failing
~~~~~~~
-.. tacn:: {| fail | gfail } {? @int_or_var } {* {| @ident | @string | @integer } }
+.. tacn:: {| fail | gfail } {? @int_or_var } {* {| @ident | @string | @natural } }
:name: fail; gfail
:tacn:`fail` is the always-failing tactic: it does not solve any
@@ -904,7 +905,7 @@ Failing
See the example for a comparison of the two constructs.
- Note that if Coq terms have to be
+ Note that if |Coq| terms have to be
printed as part of the failure, term construction always forces the
tactic into the goals, meaning that if there are no goals when it is
evaluated, a tactic call like :tacn:`let` :n:`x := H in` :tacn:`fail` `0 x` will succeed.
@@ -919,7 +920,7 @@ Failing
the call to :tacn:`fail` :n:`@natural` is not enclosed in a :n:`+` construct,
respecting the algebraic identity.
- :n:`{* {| @ident | @string | @integer } }`
+ :n:`{* {| @ident | @string | @natural } }`
The given tokens are used for printing the failure message. If :token:`ident`
is an |Ltac| variable, its contents are printed; if not, it is an error.
@@ -937,7 +938,7 @@ Failing
.. todo the example is too long; could show the Goal True. Proof. once and hide the Aborts
to shorten it. And add a line of text before each subexample. Perhaps add some very short
- explanations/generalizations (eg gfail always fails; "tac; fail" succeeds but "fail." alone
+ explanations/generalizations (e.g. gfail always fails; "tac; fail" succeeds but "fail." alone
fails.
.. coqtop:: reset all fail
@@ -989,7 +990,7 @@ amount of time:
timeout with some other tacticals. This tactical is hence proposed only
for convenience during debugging or other development phases, we strongly
advise you to not leave any timeout in final scripts. Note also that
- this tactical isn’t available on the native Windows port of Coq.
+ this tactical isn’t available on the native Windows port of |Coq|.
Timing a tactic
~~~~~~~~~~~~~~~
@@ -1488,7 +1489,7 @@ Examples:
match_context_rule ::= [ {*, @match_hyp } |- @match_pattern ] => @ltac_expr
match_hyp ::= | @name := {? [ @match_pattern ] : } @match_pattern
-.. todo PR The following items (up to numgoals) are part of "value_tactic". I'd like to make
+.. todo The following items (up to numgoals) are part of "value_tactic". I'd like to make
this a subsection and explain that they all return values. How do I get a 5th-level section title?
Filling a term context
@@ -1884,7 +1885,7 @@ Proving that a list is a permutation of a second list
From Section :ref:`ltac-syntax` we know that Ltac has a primitive
notion of integers, but they are only used as arguments for
primitive tactics and we cannot make computations with them. Thus,
- instead, we use Coq's natural number type :g:`nat`.
+ instead, we use |Coq|'s natural number type :g:`nat`.
.. coqtop:: in
diff --git a/doc/sphinx/proof-engine/ltac2.rst b/doc/sphinx/proof-engine/ltac2.rst
index 773e393eb6..41f376c43d 100644
--- a/doc/sphinx/proof-engine/ltac2.rst
+++ b/doc/sphinx/proof-engine/ltac2.rst
@@ -3,8 +3,8 @@
Ltac2
=====
-The Ltac tactic language is probably one of the ingredients of the success of
-Coq, yet it is at the same time its Achilles' heel. Indeed, Ltac:
+The |Ltac| tactic language is probably one of the ingredients of the success of
+|Coq|, yet it is at the same time its Achilles' heel. Indeed, |Ltac|:
- has often unclear semantics
- is very non-uniform due to organic growth
@@ -30,7 +30,7 @@ as Ltac1.
Current limitations include:
- There are a number of tactics that are not yet supported in Ltac2 because
- the interface OCaml and/or Ltac2 notations haven't been written. See
+ the interface |OCaml| and/or Ltac2 notations haven't been written. See
:ref:`defining_tactics`.
- Missing usability features such as:
@@ -38,7 +38,6 @@ Current limitations include:
- Printing functions are limited and awkward to use. Only a few data types are
printable.
- Deep pattern matching and matching on tuples don't work.
- - If statements on Ltac2 boolean values
- A convenient way to build terms with casts through the low-level API. Because the
cast type is opaque, building terms with casts currently requires an awkward construction like the
following, which also incurs extra overhead to repeat typechecking for each
@@ -90,7 +89,7 @@ In particular, Ltac2 is:
* together with the Hindley-Milner type system
- a language featuring meta-programming facilities for the manipulation of
- Coq-side terms
+ |Coq|-side terms
- a language featuring notation facilities to help write palatable scripts
We describe these in more detail in the remainder of this document.
@@ -108,14 +107,14 @@ that ML constitutes a sweet spot in PL design, as it is relatively expressive
while not being either too lax (unlike dynamic typing) nor too strict
(unlike, say, dependent types).
-The main goal of Ltac2 is to serve as a meta-language for Coq. As such, it
+The main goal of Ltac2 is to serve as a meta-language for |Coq|. As such, it
naturally fits in the ML lineage, just as the historical ML was designed as
the tactic language for the LCF prover. It can also be seen as a general-purpose
-language, by simply forgetting about the Coq-specific features.
+language, by simply forgetting about the |Coq|-specific features.
Sticking to a standard ML type system can be considered somewhat weak for a
-meta-language designed to manipulate Coq terms. In particular, there is no
-way to statically guarantee that a Coq term resulting from an Ltac2
+meta-language designed to manipulate |Coq| terms. In particular, there is no
+way to statically guarantee that a |Coq| term resulting from an Ltac2
computation will be well-typed. This is actually a design choice, motivated
by backward compatibility with Ltac1. Instead, well-typedness is deferred to
dynamic checks, allowing many primitive functions to fail whenever they are
@@ -138,7 +137,7 @@ Type Syntax
~~~~~~~~~~~
At the level of terms, we simply elaborate on Ltac1 syntax, which is quite
-close to OCaml. Types follow the simply-typed syntax of OCaml.
+close to |OCaml|. Types follow the simply-typed syntax of |OCaml|.
.. insertprodn ltac2_type ltac2_typevar
@@ -160,7 +159,7 @@ declarations such as algebraic datatypes and records.
Built-in types include:
-- ``int``, machine integers (size not specified, in practice inherited from OCaml)
+- ``int``, machine integers (size not specified, in practice inherited from |OCaml|)
- ``string``, mutable strings
- ``'a array``, mutable arrays
- ``exn``, exceptions
@@ -201,7 +200,7 @@ One can define new types with the following commands.
:token:`tac2typ_knd` should be in the form :n:`[ {? {? %| } {+| @tac2alg_constructor } } ]`.
Without :n:`{| := | ::= }`
- Defines an abstract type for use representing data from OCaml. Not for
+ Defines an abstract type for use representing data from |OCaml|. Not for
end users.
:n:`with @tac2typ_def`
@@ -227,9 +226,9 @@ One can define new types with the following commands.
.. cmd:: Ltac2 @ external @ident : @ltac2_type := @string @string
:name: Ltac2 external
- Declares abstract terms. Frequently, these declare OCaml functions
+ Declares abstract terms. Frequently, these declare |OCaml| functions
defined in |Coq| and give their type information. They can also declare
- data structures from OCaml. This command has no use for the end user.
+ data structures from |OCaml|. This command has no use for the end user.
APIs
~~~~
@@ -345,12 +344,10 @@ Ltac2 Definitions
.. coqtop:: all
- Ltac2 mutable rec f b := match b with true => 0 | _ => f true end.
- Ltac2 Set f := fun b =>
- match b with true => 1 | _ => f true end.
+ Ltac2 mutable rec f b := if b then 0 else f true.
+ Ltac2 Set f := fun b => if b then 1 else f true.
Ltac2 Eval (f false).
- Ltac2 Set f as oldf := fun b =>
- match b with true => 2 | _ => oldf false end.
+ Ltac2 Set f as oldf := fun b => if b then 2 else oldf false.
Ltac2 Eval (f false).
In the definition, the `f` in the body is resolved statically
@@ -363,7 +360,7 @@ Reduction
~~~~~~~~~
We use the usual ML call-by-value reduction, with an otherwise unspecified
-evaluation order. This is a design choice making it compatible with OCaml,
+evaluation order. This is a design choice making it compatible with |OCaml|,
if ever we implement native compilation. The expected equations are as follows::
(fun x => t) V ≡ t{x := V} (βv)
@@ -407,7 +404,7 @@ standard IO monad as the ambient effectful world, Ltac2 is has a
tactic monad.
Note that the order of evaluation of application is *not* specified and is
-implementation-dependent, as in OCaml.
+implementation-dependent, as in |OCaml|.
We recall that the `Proofview.tactic` monad is essentially a IO monad together
with backtracking state representing the proof state.
@@ -537,8 +534,8 @@ aware of bound variables and must use heuristics to decide whether a variable
is a proper one or referring to something in the Ltac context.
Likewise, in Ltac1, constr parsing is implicit, so that ``foo 0`` is
-not ``foo`` applied to the Ltac integer expression ``0`` (Ltac does have a
-notion of integers, though it is not first-class), but rather the Coq term
+not ``foo`` applied to the Ltac integer expression ``0`` (|Ltac| does have a
+notion of integers, though it is not first-class), but rather the |Coq| term
:g:`Datatypes.O`.
The implicit parsing is confusing to users and often gives unexpected results.
@@ -570,11 +567,11 @@ Built-in quotations
The current implementation recognizes the following built-in quotations:
- ``ident``, which parses identifiers (type ``Init.ident``).
-- ``constr``, which parses Coq terms and produces an-evar free term at runtime
+- ``constr``, which parses |Coq| terms and produces an-evar free term at runtime
(type ``Init.constr``).
-- ``open_constr``, which parses Coq terms and produces a term potentially with
+- ``open_constr``, which parses |Coq| terms and produces a term potentially with
holes at runtime (type ``Init.constr`` as well).
-- ``pattern``, which parses Coq patterns and produces a pattern used for term
+- ``pattern``, which parses |Coq| patterns and produces a pattern used for term
matching (type ``Init.pattern``).
- ``reference`` Qualified names
are globalized at internalization into the corresponding global reference,
@@ -617,7 +614,7 @@ Term Antiquotations
Syntax
++++++
-One can also insert Ltac2 code into Coq terms, similar to what is possible in
+One can also insert Ltac2 code into |Coq| terms, similar to what is possible in
Ltac1.
.. prodn::
@@ -629,7 +626,7 @@ for their side-effects.
Semantics
+++++++++
-A quoted Coq term is interpreted in two phases, internalization and
+A quoted |Coq| term is interpreted in two phases, internalization and
evaluation.
- Internalization is part of the static semantics, that is, it is done at Ltac2
@@ -637,17 +634,17 @@ evaluation.
- Evaluation is part of the dynamic semantics, that is, it is done when
a term gets effectively computed by Ltac2.
-Note that typing of Coq terms is a *dynamic* process occurring at Ltac2
+Note that typing of |Coq| terms is a *dynamic* process occurring at Ltac2
evaluation time, and not at Ltac2 typing time.
Static semantics
****************
-During internalization, Coq variables are resolved and antiquotations are
-type checked as Ltac2 terms, effectively producing a ``glob_constr`` in Coq
+During internalization, |Coq| variables are resolved and antiquotations are
+type checked as Ltac2 terms, effectively producing a ``glob_constr`` in |Coq|
implementation terminology. Note that although it went through the
type checking of **Ltac2**, the resulting term has not been fully computed and
-is potentially ill-typed as a runtime **Coq** term.
+is potentially ill-typed as a runtime **|Coq|** term.
.. example::
@@ -669,7 +666,7 @@ of the corresponding term expression.
let x := '0 in constr:(1 + ltac2:(exact x))
Beware that the typing environment of antiquotations is **not**
-expanded by the Coq binders from the term.
+expanded by the |Coq| binders from the term.
.. example::
@@ -692,17 +689,17 @@ as follows.
`constr:(fun x : nat => ltac2:(exact (hyp @x)))`
-This pattern is so common that we provide dedicated Ltac2 and Coq term notations
+This pattern is so common that we provide dedicated Ltac2 and |Coq| term notations
for it.
- `&x` as an Ltac2 expression expands to `hyp @x`.
-- `&x` as a Coq constr expression expands to
+- `&x` as a |Coq| constr expression expands to
`ltac2:(Control.refine (fun () => hyp @x))`.
-In the special case where Ltac2 antiquotations appear inside a Coq term
+In the special case where Ltac2 antiquotations appear inside a |Coq| term
notation, the notation variables are systematically bound in the body
of the tactic expression with type `Ltac2.Init.preterm`. Such a type represents
-untyped syntactic Coq expressions, which can by typed in the
+untyped syntactic |Coq| expressions, which can by typed in the
current context using the `Ltac2.Constr.pretype` function.
.. example::
@@ -748,9 +745,9 @@ the notation section.
.. prodn:: term += $@lident
-In a Coq term, writing :g:`$x` is semantically equivalent to
+In a |Coq| term, writing :g:`$x` is semantically equivalent to
:g:`ltac2:(Control.refine (fun () => x))`, up to re-typechecking. It allows to
-insert in a concise way an Ltac2 variable of type :n:`constr` into a Coq term.
+insert in a concise way an Ltac2 variable of type :n:`constr` into a |Coq| term.
Match over terms
~~~~~~~~~~~~~~~~
@@ -1129,7 +1126,7 @@ Match on values
.. tacn:: match @ltac2_expr5 with {? @ltac2_branches } end
:name: match (Ltac2)
- Matches a value, akin to the OCaml `match` construct. By itself, it doesn't cause backtracking
+ Matches a value, akin to the |OCaml| `match` construct. By itself, it doesn't cause backtracking
as do the `*match*!` and `*match*! goal` constructs.
.. insertprodn ltac2_branches atomic_tac2pat
@@ -1149,6 +1146,13 @@ Match on values
| @tac2pat1 , {*, @tac2pat1 }
| @tac2pat1
+.. tacn:: if @ltac2_expr5__test then @ltac2_expr5__then else @ltac2_expr5__else
+ :name: if-then-else (Ltac2)
+
+ Equivalent to a :tacn:`match <match (Ltac2)>` on a boolean value. If the
+ :n:`@ltac2_expr5__test` evaluates to true, :n:`@ltac2_expr5__then`
+ is evaluated. Otherwise :n:`@ltac2_expr5__else` is evaluated.
+
.. note::
For now, deep pattern matching is not implemented.
@@ -1254,7 +1258,7 @@ Abbreviations
Introduces a special kind of notation, called an abbreviation,
that does not add any parsing rules. It is similar in
- spirit to Coq abbreviations (see :cmd:`Notation (abbreviation)`,
+ spirit to |Coq| abbreviations (see :cmd:`Notation (abbreviation)`,
insofar as its main purpose is to give an
absolute name to a piece of pure syntax, which can be transparently referred to
by this name as if it were a proper definition.
@@ -1281,7 +1285,7 @@ Abbreviations
Defining tactics
~~~~~~~~~~~~~~~~
-Built-in tactics (those defined in OCaml code in the |Coq| executable) and Ltac1 tactics,
+Built-in tactics (those defined in |OCaml| code in the |Coq| executable) and Ltac1 tactics,
which are defined in `.v` files, must be defined through notations. (Ltac2 tactics can be
defined with :cmd:`Ltac2`.
@@ -1795,7 +1799,7 @@ Transition from Ltac1
Owing to the use of a lot of notations, the transition should not be too
difficult. In particular, it should be possible to do it incrementally. That
said, we do *not* guarantee it will be a blissful walk either.
-Hopefully, owing to the fact Ltac2 is typed, the interactive dialogue with Coq
+Hopefully, owing to the fact Ltac2 is typed, the interactive dialogue with |Coq|
will help you.
We list the major changes and the transition strategies hereafter.
diff --git a/doc/sphinx/proof-engine/proof-handling.rst b/doc/sphinx/proof-engine/proof-handling.rst
index f90ebadb3a..7f5aacbfdb 100644
--- a/doc/sphinx/proof-engine/proof-handling.rst
+++ b/doc/sphinx/proof-engine/proof-handling.rst
@@ -1,889 +1,5 @@
-.. _proofhandling:
+:orphan:
--------------------
- Proof handling
--------------------
+.. raw:: html
-In |Coq|’s proof editing mode all top-level commands documented in
-Chapter :ref:`vernacularcommands` remain available and the user has access to specialized
-commands dealing with proof development pragmas documented in this
-section. They can also use some other specialized commands called
-*tactics*. They are the very tools allowing the user to deal with
-logical reasoning. They are documented in Chapter :ref:`tactics`.
-
-Coq user interfaces usually have a way of marking whether the user has
-switched to proof editing mode. For instance, in coqtop the prompt ``Coq <``   is changed into
-:n:`@ident <`   where :token:`ident` is the declared name of the theorem currently edited.
-
-At each stage of a proof development, one has a list of goals to
-prove. Initially, the list consists only in the theorem itself. After
-having applied some tactics, the list of goals contains the subgoals
-generated by the tactics.
-
-To each subgoal is associated a number of hypotheses called the *local context*
-of the goal. Initially, the local context contains the local variables and
-hypotheses of the current section (see Section :ref:`gallina-assumptions`) and
-the local variables and hypotheses of the theorem statement. It is enriched by
-the use of certain tactics (see e.g. :tacn:`intro`).
-
-When a proof is completed, the message ``Proof completed`` is displayed.
-One can then register this proof as a defined constant in the
-environment. Because there exists a correspondence between proofs and
-terms of λ-calculus, known as the *Curry-Howard isomorphism*
-:cite:`How80,Bar81,Gir89,H89`, |Coq| stores proofs as terms of |Cic|. Those
-terms are called *proof terms*.
-
-
-.. exn:: No focused proof.
-
- Coq raises this error message when one attempts to use a proof editing command
- out of the proof editing mode.
-
-.. _proof-editing-mode:
-
-Entering and leaving proof editing mode
----------------------------------------
-
-The proof editing mode is entered by asserting a statement, which typically is
-the assertion of a theorem using an assertion command like :cmd:`Theorem`. The
-list of assertion commands is given in :ref:`Assertions`. The command
-:cmd:`Goal` can also be used.
-
-.. cmd:: Goal @form
-
- This is intended for quick assertion of statements, without knowing in
- advance which name to give to the assertion, typically for quick
- testing of the provability of a statement. If the proof of the
- statement is eventually completed and validated, the statement is then
- bound to the name ``Unnamed_thm`` (or a variant of this name not already
- used for another statement).
-
-.. cmd:: Qed
-
- This command is available in interactive editing proof mode when the
- proof is completed. Then :cmd:`Qed` extracts a proof term from the proof
- script, switches back to Coq top-level and attaches the extracted
- proof term to the declared name of the original goal. This name is
- added to the environment as an opaque constant.
-
- .. exn:: Attempt to save an incomplete proof.
- :undocumented:
-
- .. note::
-
- Sometimes an error occurs when building the proof term, because
- tactics do not enforce completely the term construction
- constraints.
-
- The user should also be aware of the fact that since the
- proof term is completely rechecked at this point, one may have to wait
- a while when the proof is large. In some exceptional cases one may
- even incur a memory overflow.
-
-.. cmd:: Defined
-
- Same as :cmd:`Qed`, except the proof is made *transparent*, which means
- that its content can be explicitly used for type checking and that it can be
- unfolded in conversion tactics (see :ref:`performingcomputations`,
- :cmd:`Opaque`, :cmd:`Transparent`).
-
-.. cmd:: Save @ident
- :name: Save
-
- Saves a completed proof with the name :token:`ident`.
-
-.. cmd:: Admitted
-
- This command is available in interactive editing mode to give up
- the current proof and declare the initial goal as an axiom.
-
-.. cmd:: Abort
-
- This command cancels the current proof development, switching back to
- the previous proof development, or to the |Coq| toplevel if no other
- proof was edited.
-
- .. exn:: No focused proof (No proof-editing in progress).
- :undocumented:
-
- .. cmdv:: Abort @ident
-
- Aborts the editing of the proof named :token:`ident` (in case you have
- nested proofs).
-
- .. seealso:: :flag:`Nested Proofs Allowed`
-
- .. cmdv:: Abort All
-
- Aborts all current goals.
-
-.. cmd:: Proof @term
- :name: Proof `term`
-
- This command applies in proof editing mode. It is equivalent to
- :n:`exact @term. Qed.`
- That is, you have to give the full proof in one gulp, as a
- proof term (see Section :ref:`applyingtheorems`).
-
- .. warning::
-
- Use of this command is discouraged. In particular, it
- doesn't work in Proof General because it must
- immediately follow the command that opened proof mode, but
- Proof General inserts :cmd:`Unset` :flag:`Silent` before it (see
- `Proof General issue #498
- <https://github.com/ProofGeneral/PG/issues/498>`_).
-
-.. cmd:: Proof
-
- Is a no-op which is useful to delimit the sequence of tactic commands
- which start a proof, after a :cmd:`Theorem` command. It is a good practice to
- use :cmd:`Proof` as an opening parenthesis, closed in the script with a
- closing :cmd:`Qed`.
-
- .. seealso:: :cmd:`Proof with`
-
-.. cmd:: Proof using {+ @ident }
-
- This command applies in proof editing mode. It declares the set of
- section variables (see :ref:`gallina-assumptions`) used by the proof.
- At :cmd:`Qed` time, the
- system will assert that the set of section variables actually used in
- the proof is a subset of the declared one.
-
- The set of declared variables is closed under type dependency. For
- example, if ``T`` is a variable and ``a`` is a variable of type
- ``T``, then the commands ``Proof using a`` and ``Proof using T a``
- are equivalent.
-
- The set of declared variables always includes the variables used by
- the statement. In other words ``Proof using e`` is equivalent to
- ``Proof using Type + e`` for any declaration expression ``e``.
-
- .. cmdv:: Proof using {+ @ident } with @tactic
-
- Combines in a single line :cmd:`Proof with` and :cmd:`Proof using`.
-
- .. seealso:: :ref:`tactics-implicit-automation`
-
- .. cmdv:: Proof using All
-
- Use all section variables.
-
- .. cmdv:: Proof using {? Type }
-
- Use only section variables occurring in the statement.
-
- .. cmdv:: Proof using Type*
-
- The ``*`` operator computes the forward transitive closure. E.g. if the
- variable ``H`` has type ``p < 5`` then ``H`` is in ``p*`` since ``p`` occurs in the type
- of ``H``. ``Type*`` is the forward transitive closure of the entire set of
- section variables occurring in the statement.
-
- .. cmdv:: Proof using -({+ @ident })
-
- Use all section variables except the list of :token:`ident`.
-
- .. cmdv:: Proof using @collection__1 + @collection__2
-
- Use section variables from the union of both collections.
- See :ref:`nameaset` to know how to form a named collection.
-
- .. cmdv:: Proof using @collection__1 - @collection__2
-
- Use section variables which are in the first collection but not in the
- second one.
-
- .. cmdv:: Proof using @collection - ({+ @ident })
-
- Use section variables which are in the first collection but not in the
- list of :token:`ident`.
-
- .. cmdv:: Proof using @collection *
-
- Use section variables in the forward transitive closure of the collection.
- The ``*`` operator binds stronger than ``+`` and ``-``.
-
-
-Proof using options
-```````````````````
-
-The following options modify the behavior of ``Proof using``.
-
-
-.. opt:: Default Proof Using "@collection"
- :name: Default Proof Using
-
- Use :n:`@collection` as the default ``Proof using`` value. E.g. ``Set Default
- Proof Using "a b"`` will complete all ``Proof`` commands not followed by a
- ``using`` part with ``using a b``.
-
-
-.. flag:: Suggest Proof Using
-
- When :cmd:`Qed` is performed, suggest a ``using`` annotation if the user did not
- provide one.
-
-.. _`nameaset`:
-
-Name a set of section hypotheses for ``Proof using``
-````````````````````````````````````````````````````
-
-.. cmd:: Collection @ident := @collection
-
- This can be used to name a set of section
- hypotheses, with the purpose of making ``Proof using`` annotations more
- compact.
-
- .. example::
-
- Define the collection named ``Some`` containing ``x``, ``y`` and ``z``::
-
- Collection Some := x y z.
-
- Define the collection named ``Fewer`` containing only ``x`` and ``y``::
-
- Collection Fewer := Some - z
-
- Define the collection named ``Many`` containing the set union or set
- difference of ``Fewer`` and ``Some``::
-
- Collection Many := Fewer + Some
- Collection Many := Fewer - Some
-
- Define the collection named ``Many`` containing the set difference of
- ``Fewer`` and the unnamed collection ``x y``::
-
- Collection Many := Fewer - (x y)
-
-
-
-.. cmd:: Existential @natural := @term
-
- This command instantiates an existential variable. :token:`natural` is an index in
- the list of uninstantiated existential variables displayed by :cmd:`Show Existentials`.
-
- This command is intended to be used to instantiate existential
- variables when the proof is completed but some uninstantiated
- existential variables remain. To instantiate existential variables
- during proof edition, you should use the tactic :tacn:`instantiate`.
-
-.. cmd:: Grab Existential Variables
-
- This command can be run when a proof has no more goal to be solved but
- has remaining uninstantiated existential variables. It takes every
- uninstantiated existential variable and turns it into a goal.
-
-Proof modes
-```````````
-
-When entering proof mode through commands such as :cmd:`Goal` and :cmd:`Proof`,
-|Coq| picks by default the |Ltac| mode. Nonetheless, there exist other proof modes
-shipped in the standard |Coq| installation, and furthermore some plugins define
-their own proof modes. The default proof mode used when opening a proof can
-be changed using the following option.
-
-.. opt:: Default Proof Mode @string
- :name: Default Proof Mode
-
- Select the proof mode to use when starting a proof. Depending on the proof
- mode, various syntactic constructs are allowed when writing an interactive
- proof. The possible option values are listed below.
-
- - "Classic": this is the default. It activates the |Ltac| language to interact
- with the proof, and also allows vernacular commands.
-
- - "Noedit": this proof mode only allows vernacular commands. No tactic
- language is activated at all. This is the default when the prelude is not
- loaded, e.g. through the `-noinit` option for `coqc`.
-
- - "Ltac2": this proof mode is made available when requiring the Ltac2
- library, and is set to be the default when it is imported. It allows
- to use the Ltac2 language, as well as vernacular commands.
-
- - Some external plugins also define their own proof mode, which can be
- activated via this command.
-
-Navigation in the proof tree
---------------------------------
-
-.. cmd:: Undo
-
- This command cancels the effect of the last command. Thus, it
- backtracks one step.
-
-.. cmdv:: Undo @natural
-
- Repeats Undo :token:`natural` times.
-
-.. cmdv:: Restart
- :name: Restart
-
- This command restores the proof editing process to the original goal.
-
- .. exn:: No focused proof to restart.
- :undocumented:
-
-.. cmd:: Focus
-
- This focuses the attention on the first subgoal to prove and the
- printing of the other subgoals is suspended until the focused subgoal
- is solved or unfocused. This is useful when there are many current
- subgoals which clutter your screen.
-
- .. deprecated:: 8.8
-
- Prefer the use of bullets or focusing brackets (see below).
-
-.. cmdv:: Focus @natural
-
- This focuses the attention on the :token:`natural` th subgoal to prove.
-
- .. deprecated:: 8.8
-
- Prefer the use of focusing brackets with a goal selector (see below).
-
-.. cmd:: Unfocus
-
- This command restores to focus the goal that were suspended by the
- last :cmd:`Focus` command.
-
- .. deprecated:: 8.8
-
-.. cmd:: Unfocused
-
- Succeeds if the proof is fully unfocused, fails if there are some
- goals out of focus.
-
-.. _curly-braces:
-
-.. index:: {
- }
-
-.. cmd:: {| %{ | %} }
-
- The command ``{`` (without a terminating period) focuses on the first
- goal, much like :cmd:`Focus` does, however, the subproof can only be
- unfocused when it has been fully solved ( *i.e.* when there is no
- focused goal left). Unfocusing is then handled by ``}`` (again, without a
- terminating period). See also an example in the next section.
-
- Note that when a focused goal is proved a message is displayed
- together with a suggestion about the right bullet or ``}`` to unfocus it
- or focus the next one.
-
- .. cmdv:: @natural: %{
-
- This focuses on the :token:`natural`\-th subgoal to prove.
-
- .. cmdv:: [@ident]: %{
-
- This focuses on the named goal :token:`ident`.
-
- .. note::
-
- Goals are just existential variables and existential variables do not
- get a name by default. You can give a name to a goal by using :n:`refine ?[@ident]`.
- You may also wrap this in an Ltac-definition like:
-
- .. coqtop:: in
-
- Ltac name_goal name := refine ?[name].
-
- .. seealso:: :ref:`existential-variables`
-
- .. example::
-
- This first example uses the Ltac definition above, and the named goals
- only serve for documentation.
-
- .. coqtop:: all
-
- Goal forall n, n + 0 = n.
- Proof.
- induction n; [ name_goal base | name_goal step ].
- [base]: {
-
- .. coqtop:: all
-
- reflexivity.
-
- .. coqtop:: in
-
- }
-
- .. coqtop:: all
-
- [step]: {
-
- .. coqtop:: all
-
- simpl.
- f_equal.
- assumption.
- }
- Qed.
-
- This can also be a way of focusing on a shelved goal, for instance:
-
- .. coqtop:: all
-
- Goal exists n : nat, n = n.
- eexists ?[x].
- reflexivity.
- [x]: exact 0.
- Qed.
-
- .. exn:: This proof is focused, but cannot be unfocused this way.
-
- You are trying to use ``}`` but the current subproof has not been fully solved.
-
- .. exn:: No such goal (@natural).
- :undocumented:
-
- .. exn:: No such goal (@ident).
- :undocumented:
-
- .. exn:: Brackets do not support multi-goal selectors.
-
- Brackets are used to focus on a single goal given either by its position
- or by its name if it has one.
-
- .. seealso:: The error messages about bullets below.
-
-.. _bullets:
-
-Bullets
-```````
-
-Alternatively to ``{`` and ``}``, proofs can be structured with bullets. The
-use of a bullet ``b`` for the first time focuses on the first goal ``g``, the
-same bullet cannot be used again until the proof of ``g`` is completed,
-then it is mandatory to focus the next goal with ``b``. The consequence is
-that ``g`` and all goals present when ``g`` was focused are focused with the
-same bullet ``b``. See the example below.
-
-Different bullets can be used to nest levels. The scope of bullet does
-not go beyond enclosing ``{`` and ``}``, so bullets can be reused as further
-nesting levels provided they are delimited by these. Bullets are made of
-repeated ``-``, ``+`` or ``*`` symbols:
-
-.. prodn:: bullet ::= {| {+ - } | {+ + } | {+ * } }
-
-Note again that when a focused goal is proved a message is displayed
-together with a suggestion about the right bullet or ``}`` to unfocus it
-or focus the next one.
-
-.. note::
-
- In Proof General (``Emacs`` interface to |Coq|), you must use
- bullets with the priority ordering shown above to have a correct
- indentation. For example ``-`` must be the outer bullet and ``**`` the inner
- one in the example below.
-
-The following example script illustrates all these features:
-
-.. example::
-
- .. coqtop:: all
-
- Goal (((True /\ True) /\ True) /\ True) /\ True.
- Proof.
- split.
- - split.
- + split.
- ** { split.
- - trivial.
- - trivial.
- }
- ** trivial.
- + trivial.
- - assert True.
- { trivial. }
- assumption.
- Qed.
-
-.. exn:: Wrong bullet @bullet__1: Current bullet @bullet__2 is not finished.
-
- Before using bullet :n:`@bullet__1` again, you should first finish proving
- the current focused goal.
- Note that :n:`@bullet__1` and :n:`@bullet__2` may be the same.
-
-.. exn:: Wrong bullet @bullet__1: Bullet @bullet__2 is mandatory here.
-
- You must put :n:`@bullet__2` to focus on the next goal. No other bullet is
- allowed here.
-
-.. exn:: No such goal. Focus next goal with bullet @bullet.
-
- You tried to apply a tactic but no goals were under focus.
- Using :n:`@bullet` is mandatory here.
-
-.. FIXME: the :noindex: below works around a Sphinx issue.
- (https://github.com/sphinx-doc/sphinx/issues/4979)
- It should be removed once that issue is fixed.
-
-.. exn:: No such goal. Try unfocusing with %}.
- :noindex:
-
- You just finished a goal focused by ``{``, you must unfocus it with ``}``.
-
-Mandatory Bullets
-`````````````````
-
-Using :opt:`Default Goal Selector` with the ``!`` selector forces
-tactic scripts to keep focus to exactly one goal (e.g. using bullets)
-or use explicit goal selectors.
-
-Set Bullet Behavior
-```````````````````
-.. opt:: Bullet Behavior {| "None" | "Strict Subproofs" }
- :name: Bullet Behavior
-
- This option controls the bullet behavior and can take two possible values:
-
- - "None": this makes bullets inactive.
- - "Strict Subproofs": this makes bullets active (this is the default behavior).
-
-.. _requestinginformation:
-
-Requesting information
-----------------------
-
-
-.. cmd:: Show
-
- This command displays the current goals.
-
- .. exn:: No focused proof.
- :undocumented:
-
- .. cmdv:: Show @natural
-
- Displays only the :token:`natural`\-th subgoal.
-
- .. exn:: No such goal.
- :undocumented:
-
- .. cmdv:: Show @ident
-
- Displays the named goal :token:`ident`. This is useful in
- particular to display a shelved goal but only works if the
- corresponding existential variable has been named by the user
- (see :ref:`existential-variables`) as in the following example.
-
- .. example::
-
- .. coqtop:: all abort
-
- Goal exists n, n = 0.
- eexists ?[n].
- Show n.
-
- .. cmdv:: Show Proof {? Diffs {? removed } }
- :name: Show Proof
-
- Displays the proof term generated by the tactics
- that have been applied so far. If the proof is incomplete, the term
- will contain holes, which correspond to subterms which are still to be
- constructed. Each hole is an existential variable, which appears as a
- question mark followed by an identifier.
-
- Experimental: Specifying “Diffs” highlights the difference between the
- current and previous proof step. By default, the command shows the
- output once with additions highlighted. Including “removed” shows
- the output twice: once showing removals and once showing additions.
- It does not examine the :opt:`Diffs` option. See :ref:`showing_diffs`.
-
- .. cmdv:: Show Conjectures
- :name: Show Conjectures
-
- It prints the list of the names of all the
- theorems that are currently being proved. As it is possible to start
- proving a previous lemma during the proof of a theorem, this list may
- contain several names.
-
- .. cmdv:: Show Intro
- :name: Show Intro
-
- If the current goal begins by at least one product,
- this command prints the name of the first product, as it would be
- generated by an anonymous :tacn:`intro`. The aim of this command is to ease
- the writing of more robust scripts. For example, with an appropriate
- Proof General macro, it is possible to transform any anonymous :tacn:`intro`
- into a qualified one such as ``intro y13``. In the case of a non-product
- goal, it prints nothing.
-
- .. cmdv:: Show Intros
- :name: Show Intros
-
- This command is similar to the previous one, it
- simulates the naming process of an :tacn:`intros`.
-
- .. cmdv:: Show Existentials
- :name: Show Existentials
-
- Displays all open goals / existential variables in the current proof
- along with the type and the context of each variable.
-
- .. cmdv:: Show Match @ident
-
- This variant displays a template of the Gallina
- ``match`` construct with a branch for each constructor of the type
- :token:`ident`
-
- .. example::
-
- .. coqtop:: all
-
- Show Match nat.
-
- .. exn:: Unknown inductive type.
- :undocumented:
-
- .. cmdv:: Show Universes
- :name: Show Universes
-
- It displays the set of all universe constraints and
- its normalized form at the current stage of the proof, useful for
- debugging universe inconsistencies.
-
- .. cmdv:: Show Goal @natural at @natural
- :name: Show Goal
-
- This command is only available in coqtop. Displays a goal at a
- proof state using the goal ID number and the proof state ID number.
- It is primarily for use by tools such as Prooftree that need to fetch
- goal history in this way. Prooftree is a tool for visualizing a proof
- as a tree that runs in Proof General.
-
-.. cmd:: Guarded
-
- Some tactics (e.g. :tacn:`refine`) allow to build proofs using
- fixpoint or co-fixpoint constructions. Due to the incremental nature
- of interactive proof construction, the check of the termination (or
- guardedness) of the recursive calls in the fixpoint or cofixpoint
- constructions is postponed to the time of the completion of the proof.
-
- The command :cmd:`Guarded` allows checking if the guard condition for
- fixpoint and cofixpoint is violated at some time of the construction
- of the proof without having to wait the completion of the proof.
-
-.. _showing_diffs:
-
-Showing differences between proof steps
----------------------------------------
-
-
-Coq can automatically highlight the differences between successive proof steps
-and between values in some error messages. Also, as an experimental feature,
-Coq can also highlight differences between proof steps shown in the :cmd:`Show Proof`
-command, but only, for now, when using coqtop and Proof General.
-
-For example, the following screenshots of CoqIDE and coqtop show the application
-of the same :tacn:`intros` tactic. The tactic creates two new hypotheses, highlighted in green.
-The conclusion is entirely in pale green because although it’s changed, no tokens were added
-to it. The second screenshot uses the "removed" option, so it shows the conclusion a
-second time with the old text, with deletions marked in red. Also, since the hypotheses are
-new, no line of old text is shown for them.
-
-.. comment screenshot produced with:
- Inductive ev : nat -> Prop :=
- | ev_0 : ev 0
- | ev_SS : forall n : nat, ev n -> ev (S (S n)).
-
- Fixpoint double (n:nat) :=
- match n with
- | O => O
- | S n' => S (S (double n'))
- end.
-
- Goal forall n, ev n -> exists k, n = double k.
- intros n E.
-
-..
-
- .. image:: ../_static/diffs-coqide-on.png
- :alt: |CoqIDE| with Set Diffs on
-
-..
-
- .. image:: ../_static/diffs-coqide-removed.png
- :alt: |CoqIDE| with Set Diffs removed
-
-..
-
- .. image:: ../_static/diffs-coqtop-on3.png
- :alt: coqtop with Set Diffs on
-
-This image shows an error message with diff highlighting in CoqIDE:
-
-..
-
- .. image:: ../_static/diffs-error-message.png
- :alt: |CoqIDE| error message with diffs
-
-How to enable diffs
-```````````````````
-
-.. opt:: Diffs {| "on" | "off" | "removed" }
- :name: Diffs
-
- The “on” setting highlights added tokens in green, while the “removed” setting
- additionally reprints items with removed tokens in red. Unchanged tokens in
- modified items are shown with pale green or red. Diffs in error messages
- use red and green for the compared values; they appear regardless of the setting.
- (Colors are user-configurable.)
-
-For coqtop, showing diffs can be enabled when starting coqtop with the
-``-diffs on|off|removed`` command-line option or by setting the :opt:`Diffs` option
-within Coq. You will need to provide the ``-color on|auto`` command-line option when
-you start coqtop in either case.
-
-Colors for coqtop can be configured by setting the ``COQ_COLORS`` environment
-variable. See section :ref:`customization-by-environment-variables`. Diffs
-use the tags ``diff.added``, ``diff.added.bg``, ``diff.removed`` and ``diff.removed.bg``.
-
-In CoqIDE, diffs should be enabled from the ``View`` menu. Don’t use the ``Set Diffs``
-command in CoqIDE. You can change the background colors shown for diffs from the
-``Edit | Preferences | Tags`` panel by changing the settings for the ``diff.added``,
-``diff.added.bg``, ``diff.removed`` and ``diff.removed.bg`` tags. This panel also
-lets you control other attributes of the highlights, such as the foreground
-color, bold, italic, underline and strikeout.
-
-As of June 2019, Proof General can also display Coq-generated proof diffs automatically.
-Please see the PG documentation section
-"`Showing Proof Diffs" <https://proofgeneral.github.io/doc/master/userman/Coq-Proof-General#Showing-Proof-Diffs>`_)
-for details.
-
-How diffs are calculated
-````````````````````````
-
-Diffs are calculated as follows:
-
-1. Select the old proof state to compare to, which is the proof state before
- the last tactic that changed the proof. Changes that only affect the view
- of the proof, such as ``all: swap 1 2``, are ignored.
-
-2. For each goal in the new proof state, determine what old goal to compare
- it to—the one it is derived from or is the same as. Match the hypotheses by
- name (order is ignored), handling compacted items specially.
-
-3. For each hypothesis and conclusion (the “items”) in each goal, pass
- them as strings to the lexer to break them into tokens. Then apply the
- Myers diff algorithm :cite:`Myers` on the tokens and add appropriate highlighting.
-
-Notes:
-
-* Aside from the highlights, output for the "on" option should be identical
- to the undiffed output.
-* Goals completed in the last proof step will not be shown even with the
- "removed" setting.
-
-.. comment The following screenshots show diffs working with multiple goals and with compacted
- hypotheses. In the first one, notice that the goal ``P 1`` is not highlighted at
- all after the split because it has not changed.
-
- .. todo: Use this script and remove the screenshots when COQ_COLORS
- works for coqtop in sphinx
- .. coqtop:: none
-
- Set Diffs "on".
- Parameter P : nat -> Prop.
- Goal P 1 /\ P 2 /\ P 3.
-
- .. coqtop:: out
-
- split.
-
- .. coqtop:: all abort
-
- 2: split.
-
- ..
-
- .. coqtop:: none
-
- Set Diffs "on".
- Goal forall n m : nat, n + m = m + n.
- Set Diffs "on".
-
- .. coqtop:: out
-
- intros n.
-
- .. coqtop:: all abort
-
- intros m.
-
-This screen shot shows the result of applying a :tacn:`split` tactic that replaces one goal
-with 2 goals. Notice that the goal ``P 1`` is not highlighted at all after
-the split because it has not changed.
-
-..
-
- .. image:: ../_static/diffs-coqide-multigoal.png
- :alt: coqide with Set Diffs on with multiple goals
-
-This is how diffs may appear after applying a :tacn:`intro` tactic that results
-in compacted hypotheses:
-
-..
-
- .. image:: ../_static/diffs-coqide-compacted.png
- :alt: coqide with Set Diffs on with compacted hypotheses
-
-Controlling the effect of proof editing commands
-------------------------------------------------
-
-
-.. opt:: Hyps Limit @natural
- :name: Hyps Limit
-
- This option controls the maximum number of hypotheses displayed in goals
- after the application of a tactic. All the hypotheses remain usable
- in the proof development.
- When unset, it goes back to the default mode which is to print all
- available hypotheses.
-
-
-.. flag:: Nested Proofs Allowed
-
- When turned on (it is off by default), this flag enables support for nested
- proofs: a new assertion command can be inserted before the current proof is
- finished, in which case Coq will temporarily switch to the proof of this
- *nested lemma*. When the proof of the nested lemma is finished (with :cmd:`Qed`
- or :cmd:`Defined`), its statement will be made available (as if it had been
- proved before starting the previous proof) and Coq will switch back to the
- proof of the previous assertion.
-
-
-Controlling memory usage
-------------------------
-
-.. cmd:: Print Debug GC
-
- Prints heap usage statistics, which are values from the `stat` type of the `Gc` module
- described
- `here <https://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html#TYPEstat>`_
- in the OCaml documentation.
- The `live_words`, `heap_words` and `top_heap_words` values give the basic information.
- Words are 8 bytes or 4 bytes, respectively, for 64- and 32-bit executables.
-
-When experiencing high memory usage the following commands can be used
-to force |Coq| to optimize some of its internal data structures.
-
-.. cmd:: Optimize Proof
-
- Shrink the data structure used to represent the current proof.
-
-
-.. cmd:: Optimize Heap
-
- Perform a heap compaction. This is generally an expensive operation.
- See: `OCaml Gc.compact <http://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html#VALcompact>`_
- There is also an analogous tactic :tacn:`optimize_heap`.
-
-Memory usage parameters can be set through the :ref:`OCAMLRUNPARAM <OCAMLRUNPARAM>`
-environment variable.
+ <meta http-equiv="refresh" content="0;URL=../proofs/writing-proofs/proof-mode.html">
diff --git a/doc/sphinx/proof-engine/ssreflect-proof-language.rst b/doc/sphinx/proof-engine/ssreflect-proof-language.rst
index ca50a02562..cdbae8ade1 100644
--- a/doc/sphinx/proof-engine/ssreflect-proof-language.rst
+++ b/doc/sphinx/proof-engine/ssreflect-proof-language.rst
@@ -158,23 +158,23 @@ compatible with the rest of |Coq|, up to a few discrepancies:
generalized form, turn off the |SSR| Boolean ``if`` notation using the command:
``Close Scope boolean_if_scope``.
+ The following flags can be unset to make |SSR| more compatible with
- parts of Coq:
+ parts of |Coq|:
.. flag:: SsrRewrite
Controls whether the incompatible rewrite syntax is enabled (the default).
- Disabling the flag makes the syntax compatible with other parts of Coq.
+ Disabling the flag makes the syntax compatible with other parts of |Coq|.
.. flag:: SsrIdents
Controls whether tactics can refer to |SSR|-generated variables that are
in the form _xxx_. Scripts with explicit references to such variables
are fragile; they are prone to failure if the proof is later modified or
- if the details of variable name generation change in future releases of Coq.
+ if the details of variable name generation change in future releases of |Coq|.
The default is on, which gives an error message when the user tries to
create such identifiers. Disabling the flag generates a warning instead,
- increasing compatibility with other parts of Coq.
+ increasing compatibility with other parts of |Coq|.
|Gallina| extensions
--------------------
@@ -5724,11 +5724,11 @@ respectively.
local function definition
-.. tacv:: pose fix @fix_body
+.. tacv:: pose fix @fix_decl
local fix definition
-.. tacv:: pose cofix @fix_body
+.. tacv:: pose cofix @fix_decl
local cofix definition
diff --git a/doc/sphinx/proof-engine/tactics.rst b/doc/sphinx/proof-engine/tactics.rst
index 4b1f312105..c665026500 100644
--- a/doc/sphinx/proof-engine/tactics.rst
+++ b/doc/sphinx/proof-engine/tactics.rst
@@ -86,42 +86,36 @@ specified, the default selector is used.
Although other selectors are available, only ``all``, ``!`` or a
single natural number are valid default goal selectors.
-.. _bindingslist:
+.. _bindings:
-Bindings list
-~~~~~~~~~~~~~
+Bindings
+~~~~~~~~
-Tactics that take a term as an argument may also support a bindings list
+Tactics that take a term as an argument may also accept :token:`bindings`
to instantiate some parameters of the term by name or position.
-The general form of a term with a bindings list is
-:n:`@term with @bindings_list` where :token:`bindings_list` can take two different forms:
+The general form of a term with :token:`bindings` is
+:n:`@term__tac with @bindings` where :token:`bindings` can take two different forms:
-.. _bindings_list_grammar:
+ .. insertprodn bindings bindings
.. prodn::
- ref ::= @ident
- | @natural
- bindings_list ::= {+ (@ref := @term) }
- | {+ @term }
-
-+ In a bindings list of the form :n:`{+ (@ref:= @term)}`, :n:`@ref` is either an
- :n:`@ident` or a :n:`@natural`. The references are determined according to the type of
- :n:`@term`. If :n:`@ref` is an identifier, this identifier has to be bound in the
- type of :n:`@term` and the binding provides the tactic with an instance for the
- parameter of this name. If :n:`@ref` is a number ``n``, it refers to
- the ``n``-th non dependent premise of the :n:`@term`, as determined by the type
- of :n:`@term`.
+ bindings ::= {+ ( {| @ident | @natural } := @term ) }
+ | {+ @one_term }
+
++ In the first form, if an :token:`ident` is specified, it must be bound in the
+ type of :n:`@term` and provides the tactic with an instance for the
+ parameter of this name. If a :token:`natural` is specified, it refers to
+ the ``n``-th non dependent premise of :n:`@term__tac`.
.. exn:: No such binder.
:undocumented:
-+ A bindings list can also be a simple list of terms :n:`{* @term}`.
- In that case the references to which these terms correspond are
- determined by the tactic. In case of :tacn:`induction`, :tacn:`destruct`, :tacn:`elim`
- and :tacn:`case`, the terms have to
- provide instances for all the dependent products in the type of term while in
++ In the second form, the interpretation of the :token:`one_term`\s depend on which
+ tactic they appear in. For :tacn:`induction`, :tacn:`destruct`, :tacn:`elim`
+ and :tacn:`case`, the :token:`one_term`\s
+ provide instances for all the dependent products in the type of :n:`@term__tac` while in
the case of :tacn:`apply`, or of :tacn:`constructor` and its variants, only instances
- for the dependent products that are not bound in the conclusion of the type
+ for the dependent products that are not bound in the conclusion of :n:`@term__tac`
are required.
.. exn:: Not the right number of missing arguments.
@@ -173,11 +167,11 @@ The :n:`eqn:` construct in various tactics uses :n:`@naming_intropattern`.
Use these elementary patterns to specify a name:
* :n:`@ident` — use the specified name
-* :n:`?` — let Coq choose a name
+* :n:`?` — let |Coq| choose a name
* :n:`?@ident` — generate a name that begins with :n:`@ident`
* :n:`_` — discard the matched part (unless it is required for another
hypothesis)
-* if a disjunction pattern omits a name, such as :g:`[|H2]`, Coq will choose a name
+* if a disjunction pattern omits a name, such as :g:`[|H2]`, |Coq| will choose a name
**Splitting patterns**
@@ -682,11 +676,11 @@ Applying theorems
.. exn:: Not the right number of missing arguments.
:undocumented:
- .. tacv:: apply @term with @bindings_list
+ .. tacv:: apply @term with @bindings
This also provides apply with values for instantiating premises. Here, variables
are referred by names and non-dependent products by increasing numbers (see
- :ref:`bindings list <bindingslist>`).
+ :ref:`bindings`).
.. tacv:: apply {+, @term}
@@ -747,8 +741,8 @@ Applying theorems
tactics that backtrack often. Moreover, it does not traverse tuples as :tacn:`apply`
does.
- .. tacv:: {? simple} apply {+, @term {? with @bindings_list}}
- {? simple} eapply {+, @term {? with @bindings_list}}
+ .. tacv:: {? simple} apply {+, @term {? with @bindings}}
+ {? simple} eapply {+, @term {? with @bindings}}
:name: simple apply; simple eapply
This summarizes the different syntaxes for :tacn:`apply` and :tacn:`eapply`.
@@ -849,7 +843,7 @@ Applying theorems
.. flag:: Universal Lemma Under Conjunction
- This flag, which preserves compatibility with versions of Coq prior to
+ This flag, which preserves compatibility with versions of |Coq| prior to
8.4 is also available for :n:`apply @term in @ident` (see :tacn:`apply … in`).
.. tacn:: apply @term in @ident
@@ -888,18 +882,18 @@ Applying theorems
This applies each :token:`term` in sequence in :token:`ident`.
- .. tacv:: apply {+, @term with @bindings_list} in @ident
+ .. tacv:: apply {+, @term with @bindings} in @ident
This does the same but uses the bindings in each :n:`(@ident := @term)` to
instantiate the parameters of the corresponding type of :token:`term`
- (see :ref:`bindings list <bindingslist>`).
+ (see :ref:`bindings`).
- .. tacv:: eapply {+, @term {? with @bindings_list } } in @ident
+ .. tacv:: eapply {+, @term {? with @bindings } } in @ident
This works as :tacn:`apply … in` but turns unresolved bindings into
existential variables, if any, instead of failing.
- .. tacv:: apply {+, @term {? with @bindings_list } } in @ident as @simple_intropattern
+ .. tacv:: apply {+, @term {? with @bindings } } in @ident as @simple_intropattern
:name: apply … in … as
This works as :tacn:`apply … in` then applies the :token:`simple_intropattern`
@@ -911,8 +905,8 @@ Applying theorems
only on subterms that contain no variables to instantiate and does not
traverse tuples. See :ref:`the corresponding example <simple_apply_ex>`.
- .. tacv:: {? simple} apply {+, @term {? with @bindings_list}} in @ident {? as @simple_intropattern}
- {? simple} eapply {+, @term {? with @bindings_list}} in @ident {? as @simple_intropattern}
+ .. tacv:: {? simple} apply {+, @term {? with @bindings}} in @ident {? as @simple_intropattern}
+ {? simple} eapply {+, @term {? with @bindings}} in @ident {? as @simple_intropattern}
This summarizes the different syntactic variants of :n:`apply @term in @ident`
and :n:`eapply @term in @ident`.
@@ -938,48 +932,48 @@ Applying theorems
:g:`constructor n` where ``n`` is the number of constructors of the head
of the goal.
- .. tacv:: constructor @natural with @bindings_list
+ .. tacv:: constructor @natural with @bindings
Let ``c`` be the i-th constructor of :g:`I`, then
- :n:`constructor i with @bindings_list` is equivalent to
- :n:`intros; apply c with @bindings_list`.
+ :n:`constructor i with @bindings` is equivalent to
+ :n:`intros; apply c with @bindings`.
.. warning::
- The terms in the :token:`bindings_list` are checked in the context
+ The terms in :token:`bindings` are checked in the context
where constructor is executed and not in the context where :tacn:`apply`
is executed (the introductions are not taken into account).
- .. tacv:: split {? with @bindings_list }
+ .. tacv:: split {? with @bindings }
:name: split
This applies only if :g:`I` has a single constructor. It is then
- equivalent to :n:`constructor 1 {? with @bindings_list }`. It is
+ equivalent to :n:`constructor 1 {? with @bindings }`. It is
typically used in the case of a conjunction :math:`A \wedge B`.
- .. tacv:: exists @bindings_list
+ .. tacv:: exists @bindings
:name: exists
This applies only if :g:`I` has a single constructor. It is then equivalent
- to :n:`intros; constructor 1 with @bindings_list.` It is typically used in
+ to :n:`intros; constructor 1 with @bindings.` It is typically used in
the case of an existential quantification :math:`\exists x, P(x).`
- .. tacv:: exists {+, @bindings_list }
+ .. tacv:: exists {+, @bindings }
- This iteratively applies :n:`exists @bindings_list`.
+ This iteratively applies :n:`exists @bindings`.
.. exn:: Not an inductive goal with 1 constructor.
:undocumented:
- .. tacv:: left {? with @bindings_list }
- right {? with @bindings_list }
+ .. tacv:: left {? with @bindings }
+ right {? with @bindings }
:name: left; right
These tactics apply only if :g:`I` has two constructors, for
instance in the case of a disjunction :math:`A \vee B`.
Then, they are respectively equivalent to
- :n:`constructor 1 {? with @bindings_list }` and
- :n:`constructor 2 {? with @bindings_list }`.
+ :n:`constructor 1 {? with @bindings }` and
+ :n:`constructor 2 {? with @bindings }`.
.. exn:: Not an inductive goal with 2 constructors.
:undocumented:
@@ -1299,7 +1293,7 @@ Managing the local context
.. tacv:: set @term {? in @goal_occurrences }
This behaves as :n:`set (@ident := @term) {? in @goal_occurrences }`
- but :token:`ident` is generated by Coq.
+ but :token:`ident` is generated by |Coq|.
.. tacv:: eset (@ident {* @binder } := @term) {? in @goal_occurrences }
eset @term {? in @goal_occurrences }
@@ -1344,7 +1338,7 @@ Managing the local context
.. tacv:: pose @term
This behaves as :n:`pose (@ident := @term)` but :token:`ident` is
- generated by Coq.
+ generated by |Coq|.
.. tacv:: epose (@ident {* @binder } := @term)
epose @term
@@ -1406,7 +1400,7 @@ Controlling the proof flow
.. tacv:: assert @type
This behaves as :n:`assert (@ident : @type)` but :n:`@ident` is
- generated by Coq.
+ generated by |Coq|.
.. tacv:: assert @type by @tactic
@@ -1486,7 +1480,7 @@ Controlling the proof flow
.. tacv:: enough @type
This behaves like :n:`enough (@ident : @type)` with the name :token:`ident` of
- the hypothesis generated by Coq.
+ the hypothesis generated by |Coq|.
.. tacv:: enough @type as @simple_intropattern
@@ -1518,13 +1512,13 @@ Controlling the proof flow
list of remaining subgoal to prove.
.. tacv:: specialize (@ident {* @term}) {? as @simple_intropattern}
- specialize @ident with @bindings_list {? as @simple_intropattern}
+ specialize @ident with @bindings {? as @simple_intropattern}
:name: specialize; _
This tactic works on local hypothesis :n:`@ident`. The
premises of this hypothesis (either universal quantifications or
non-dependent implications) are instantiated by concrete terms coming either
- from arguments :n:`{* @term}` or from a :ref:`bindings list <bindingslist>`.
+ from arguments :n:`{* @term}` or from :ref:`bindings`.
In the first form the application to :n:`{* @term}` can be partial. The
first form is equivalent to :n:`assert (@ident := @ident {* @term})`. In the
second form, instantiation elements can also be partial. In this case the
@@ -1611,7 +1605,7 @@ name of the variable (here :g:`n`) is chosen based on :g:`T`.
must have given the name explicitly (see :ref:`Existential-Variables`).
.. note:: When you are referring to hypotheses which you did not name
- explicitly, be aware that Coq may make a different decision on how to
+ explicitly, be aware that |Coq| may make a different decision on how to
name the variable in the current goal and in the context of the
existential variable. This can lead to surprising behaviors.
@@ -1765,9 +1759,9 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
between :token:`term` and the value that it takes in each of the
possible cases. The name of the equation is specified
by :token:`naming_intropattern` (see :tacn:`intros`),
- in particular ``?`` can be used to let Coq generate a fresh name.
+ in particular ``?`` can be used to let |Coq| generate a fresh name.
- .. tacv:: destruct @term with @bindings_list
+ .. tacv:: destruct @term with @bindings
This behaves like :n:`destruct @term` providing explicit instances for
the dependent premises of the type of :token:`term`.
@@ -1781,9 +1775,9 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
are left as existential variables to be inferred later, in the same way
as :tacn:`eapply` does.
- .. tacv:: destruct @term using @term {? with @bindings_list }
+ .. tacv:: destruct @term using @term {? with @bindings }
- This is synonym of :n:`induction @term using @term {? with @bindings_list }`.
+ This is synonym of :n:`induction @term using @term {? with @bindings }`.
.. tacv:: destruct @term in @goal_occurrences
@@ -1792,8 +1786,8 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
clause is an occurrence clause whose syntax and behavior is described
in :ref:`occurrences sets <occurrencessets>`.
- .. tacv:: destruct @term {? with @bindings_list } {? as @or_and_intropattern_loc } {? eqn:@naming_intropattern } {? using @term {? with @bindings_list } } {? in @goal_occurrences }
- edestruct @term {? with @bindings_list } {? as @or_and_intropattern_loc } {? eqn:@naming_intropattern } {? using @term {? with @bindings_list } } {? in @goal_occurrences }
+ .. tacv:: destruct @term {? with @bindings } {? as @or_and_intropattern_loc } {? eqn:@naming_intropattern } {? using @term {? with @bindings } } {? in @goal_occurrences }
+ edestruct @term {? with @bindings } {? as @or_and_intropattern_loc } {? eqn:@naming_intropattern } {? using @term {? with @bindings } } {? in @goal_occurrences }
These are the general forms of :tacn:`destruct` and :tacn:`edestruct`.
They combine the effects of the ``with``, ``as``, ``eqn:``, ``using``,
@@ -1806,15 +1800,15 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
recursion. It behaves as :n:`elim @term` but using a case-analysis
elimination principle and not a recursive one.
-.. tacv:: case @term with @bindings_list
+.. tacv:: case @term with @bindings
- Analogous to :n:`elim @term with @bindings_list` above.
+ Analogous to :n:`elim @term with @bindings` above.
-.. tacv:: ecase @term {? with @bindings_list }
+.. tacv:: ecase @term {? with @bindings }
:name: ecase
In case the type of :n:`@term` has dependent premises, or dependent premises
- whose values are not inferable from the :n:`with @bindings_list` clause,
+ whose values are not inferable from the :n:`with @bindings` clause,
:n:`ecase` turns them into existential variables to be resolved later on.
.. tacv:: simple destruct @ident
@@ -1906,10 +1900,10 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
:n:`(p`:sub:`1` :n:`, ... , p`:sub:`n` :n:`)` can be used instead of
:n:`[ p`:sub:`1` :n:`... p`:sub:`n` :n:`]`.
-.. tacv:: induction @term with @bindings_list
+.. tacv:: induction @term with @bindings
This behaves like :tacn:`induction` providing explicit instances for the
- premises of the type of :n:`term` (see :ref:`bindings list <bindingslist>`).
+ premises of the type of :n:`term` (see :ref:`bindings`).
.. tacv:: einduction @term
:name: einduction
@@ -1926,7 +1920,7 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
It does not expect the conclusion of the type of the first :n:`@term` to be
inductive.
-.. tacv:: induction @term using @term with @bindings_list
+.. tacv:: induction @term using @term with @bindings
This behaves as :tacn:`induction … using …` but also providing instances
for the premises of the type of the second :n:`@term`.
@@ -1954,8 +1948,8 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
induction y in x |- *.
Show 2.
-.. tacv:: induction @term with @bindings_list as @or_and_intropattern_loc using @term with @bindings_list in @goal_occurrences
- einduction @term with @bindings_list as @or_and_intropattern_loc using @term with @bindings_list in @goal_occurrences
+.. tacv:: induction @term with @bindings as @or_and_intropattern_loc using @term with @bindings in @goal_occurrences
+ einduction @term with @bindings as @or_and_intropattern_loc using @term with @bindings in @goal_occurrences
These are the most general forms of :tacn:`induction` and :tacn:`einduction`. It combines the
effects of the with, as, using, and in clauses.
@@ -1978,11 +1972,11 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
products, the tactic tries to find an instance for which the elimination
lemma applies and fails otherwise.
-.. tacv:: elim @term with @bindings_list
+.. tacv:: elim @term with @bindings
:name: elim … with
Allows to give explicit instances to the premises of the type of :n:`@term`
- (see :ref:`bindings list <bindingslist>`).
+ (see :ref:`bindings`).
.. tacv:: eelim @term
:name: eelim
@@ -1991,15 +1985,15 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
existential variables to be resolved later on.
.. tacv:: elim @term using @term
- elim @term using @term with @bindings_list
+ elim @term using @term with @bindings
Allows the user to give explicitly an induction principle :n:`@term` that
is not the standard one for the underlying inductive type of :n:`@term`. The
- :n:`@bindings_list` clause allows instantiating premises of the type of
+ :n:`@bindings` clause allows instantiating premises of the type of
:n:`@term`.
-.. tacv:: elim @term with @bindings_list using @term with @bindings_list
- eelim @term with @bindings_list using @term with @bindings_list
+.. tacv:: elim @term with @bindings using @term with @bindings
+ eelim @term with @bindings using @term with @bindings
These are the most general forms of :tacn:`elim` and :tacn:`eelim`. It combines the
effects of the ``using`` clause and of the two uses of the ``with`` clause.
@@ -2148,13 +2142,13 @@ and an explanation of the underlying technique.
:n:`discriminate @ident` where :n:`@ident` is the identifier for the last
introduced hypothesis.
-.. tacv:: discriminate @term with @bindings_list
+.. tacv:: discriminate @term with @bindings
This does the same thing as :n:`discriminate @term` but using the given
bindings to instantiate parameters or hypotheses of :n:`@term`.
.. tacv:: ediscriminate @natural
- ediscriminate @term {? with @bindings_list}
+ ediscriminate @term {? with @bindings}
:name: ediscriminate; _
This works the same as :tacn:`discriminate` but if the type of :token:`term`, or the
@@ -2212,7 +2206,7 @@ and an explanation of the underlying technique.
different types :g:`(P t`:sub:`1` :g:`... t`:sub:`n` :g:`)` and
:g:`(P u`:sub:`1` :g:`... u`:sub:`n` :sub:`)`. If :g:`t`:sub:`1` and
:g:`u`:sub:`1` are the same and have for type an inductive type for which a decidable
- equality has been declared using the command :cmd:`Scheme Equality`
+ equality has been declared using :cmd:`Scheme` :n:`Equality ...`
(see :ref:`proofschemes-induction-principles`),
the use of a sigma type is avoided.
@@ -2237,13 +2231,13 @@ and an explanation of the underlying technique.
:n:`injection @ident` where :n:`@ident` is the identifier for the last
introduced hypothesis.
- .. tacv:: injection @term with @bindings_list
+ .. tacv:: injection @term with @bindings
This does the same as :n:`injection @term` but using the given bindings to
instantiate parameters or hypotheses of :n:`@term`.
.. tacv:: einjection @natural
- einjection @term {? with @bindings_list}
+ einjection @term {? with @bindings}
:name: einjection; _
This works the same as :n:`injection` but if the type of :n:`@term`, or the
@@ -2258,10 +2252,10 @@ and an explanation of the underlying technique.
.. exn:: goal does not satisfy the expected preconditions.
:undocumented:
- .. tacv:: injection @term {? with @bindings_list} as {+ @simple_intropattern}
+ .. tacv:: injection @term {? with @bindings} as {+ @simple_intropattern}
injection @natural as {+ @simple_intropattern}
injection as {+ @simple_intropattern}
- einjection @term {? with @bindings_list} as {+ @simple_intropattern}
+ einjection @term {? with @bindings} as {+ @simple_intropattern}
einjection @natural as {+ @simple_intropattern}
einjection as {+ @simple_intropattern}
@@ -2273,10 +2267,10 @@ and an explanation of the underlying technique.
to the number of new equalities. The original equality is erased if it
corresponds to a hypothesis.
- .. tacv:: injection @term {? with @bindings_list} as @injection_intropattern
+ .. tacv:: injection @term {? with @bindings} as @injection_intropattern
injection @natural as @injection_intropattern
injection as @injection_intropattern
- einjection @term {? with @bindings_list} as @injection_intropattern
+ einjection @term {? with @bindings} as @injection_intropattern
einjection @natural as @injection_intropattern
einjection as @injection_intropattern
@@ -2359,7 +2353,7 @@ and an explanation of the underlying technique.
``inversion`` generally behaves in a slightly more expectable way than
``inversion`` (no artificial duplication of some hypotheses referring to
other hypotheses). To take benefit of these improvements, it is enough to use
- ``inversion ... as []``, letting the names being finally chosen by Coq.
+ ``inversion ... as []``, letting the names being finally chosen by |Coq|.
.. example::
@@ -2669,1760 +2663,6 @@ and an explanation of the underlying technique.
simultaneously proved are respectively :g:`forall binder ... binder, type`
The identifiers :n:`@ident` are the names of the coinduction hypotheses.
-.. _rewritingexpressions:
-
-Rewriting expressions
----------------------
-
-These tactics use the equality :g:`eq:forall A:Type, A->A->Prop` defined in
-file ``Logic.v`` (see :ref:`coq-library-logic`). The notation for :g:`eq T t u` is
-simply :g:`t=u` dropping the implicit type of :g:`t` and :g:`u`.
-
-.. tacn:: rewrite @term
- :name: rewrite
-
- This tactic applies to any goal. The type of :token:`term` must have the form
-
- ``forall (x``:sub:`1` ``:A``:sub:`1` ``) ... (x``:sub:`n` ``:A``:sub:`n` ``), eq term``:sub:`1` ``term``:sub:`2` ``.``
-
- where :g:`eq` is the Leibniz equality or a registered setoid equality.
-
- Then :n:`rewrite @term` finds the first subterm matching `term`\ :sub:`1` in the goal,
- resulting in instances `term`:sub:`1`' and `term`:sub:`2`' and then
- replaces every occurrence of `term`:subscript:`1`' by `term`:subscript:`2`'.
- Hence, some of the variables :g:`x`\ :sub:`i` are solved by unification,
- and some of the types :g:`A`\ :sub:`1`:g:`, ..., A`\ :sub:`n` become new
- subgoals.
-
- .. exn:: The @term provided does not end with an equation.
- :undocumented:
-
- .. exn:: Tactic generated a subgoal identical to the original goal. This happens if @term does not occur in the goal.
- :undocumented:
-
- .. tacv:: rewrite -> @term
-
- Is equivalent to :n:`rewrite @term`
-
- .. tacv:: rewrite <- @term
-
- Uses the equality :n:`@term`:sub:`1` :n:`= @term` :sub:`2` from right to left
-
- .. tacv:: rewrite @term in @goal_occurrences
-
- Analogous to :n:`rewrite @term` but rewriting is done following
- the clause :token:`goal_occurrences`. For instance:
-
- + :n:`rewrite H in H'` will rewrite `H` in the hypothesis
- ``H'`` instead of the current goal.
- + :n:`rewrite H in H' at 1, H'' at - 2 |- *` means
- :n:`rewrite H; rewrite H in H' at 1; rewrite H in H'' at - 2.`
- In particular a failure will happen if any of these three simpler tactics
- fails.
- + :n:`rewrite H in * |-` will do :n:`rewrite H in H'` for all hypotheses
- :g:`H'` different from :g:`H`.
- A success will happen as soon as at least one of these simpler tactics succeeds.
- + :n:`rewrite H in *` is a combination of :n:`rewrite H` and :n:`rewrite H in * |-`
- that succeeds if at least one of these two tactics succeeds.
-
- Orientation :g:`->` or :g:`<-` can be inserted before the :token:`term` to rewrite.
-
- .. tacv:: rewrite @term at @occurrences
-
- Rewrite only the given :token:`occurrences` of :token:`term`. Occurrences are
- specified from left to right as for pattern (:tacn:`pattern`). The rewrite is
- always performed using setoid rewriting, even for Leibniz’s equality, so one
- has to ``Import Setoid`` to use this variant.
-
- .. tacv:: rewrite @term by @tactic
-
- Use tactic to completely solve the side-conditions arising from the
- :tacn:`rewrite`.
-
- .. tacv:: rewrite {+, @orientation @term} {? in @ident }
-
- Is equivalent to the `n` successive tactics :n:`{+; rewrite @term}`, each one
- working on the first subgoal generated by the previous one. An :production:`orientation`
- ``->`` or ``<-`` can be inserted before each :token:`term` to rewrite. One
- unique clause can be added at the end after the keyword in; it will then
- affect all rewrite operations.
-
- In all forms of rewrite described above, a :token:`term` to rewrite can be
- immediately prefixed by one of the following modifiers:
-
- + `?` : the tactic :n:`rewrite ?@term` performs the rewrite of :token:`term` as many
- times as possible (perhaps zero time). This form never fails.
- + :n:`@natural?` : works similarly, except that it will do at most :token:`natural` rewrites.
- + `!` : works as `?`, except that at least one rewrite should succeed, otherwise
- the tactic fails.
- + :n:`@natural!` (or simply :n:`@natural`) : precisely :token:`natural` rewrites of :token:`term` will be done,
- leading to failure if these :token:`natural` rewrites are not possible.
-
- .. tacv:: erewrite @term
- :name: erewrite
-
- This tactic works as :n:`rewrite @term` but turning
- unresolved bindings into existential variables, if any, instead of
- failing. It has the same variants as :tacn:`rewrite` has.
-
- .. flag:: Keyed Unification
-
- Makes higher-order unification used by :tacn:`rewrite` rely on a set of keys to drive
- unification. The subterms, considered as rewriting candidates, must start with
- the same key as the left- or right-hand side of the lemma given to rewrite, and the arguments
- are then unified up to full reduction.
-
-.. tacn:: replace @term with @term’
- :name: replace
-
- This tactic applies to any goal. It replaces all free occurrences of :n:`@term`
- in the current goal with :n:`@term’` and generates an equality :n:`@term = @term’`
- as a subgoal. This equality is automatically solved if it occurs among
- the assumptions, or if its symmetric form occurs. It is equivalent to
- :n:`cut @term = @term’; [intro H`:sub:`n` :n:`; rewrite <- H`:sub:`n` :n:`; clear H`:sub:`n`:n:`|| assumption || symmetry; try assumption]`.
-
- .. exn:: Terms do not have convertible types.
- :undocumented:
-
- .. tacv:: replace @term with @term’ by @tactic
-
- This acts as :n:`replace @term with @term’` but applies :token:`tactic` to solve the generated
- subgoal :n:`@term = @term’`.
-
- .. tacv:: replace @term
-
- Replaces :n:`@term` with :n:`@term’` using the first assumption whose type has
- the form :n:`@term = @term’` or :n:`@term’ = @term`.
-
- .. tacv:: replace -> @term
-
- Replaces :n:`@term` with :n:`@term’` using the first assumption whose type has
- the form :n:`@term = @term’`
-
- .. tacv:: replace <- @term
-
- Replaces :n:`@term` with :n:`@term’` using the first assumption whose type has
- the form :n:`@term’ = @term`
-
- .. tacv:: replace @term {? with @term} in @goal_occurrences {? by @tactic}
- replace -> @term in @goal_occurrences
- replace <- @term in @goal_occurrences
-
- Acts as before but the replacements take place in the specified clauses
- (:token:`goal_occurrences`) (see :ref:`performingcomputations`) and not
- only in the conclusion of the goal. The clause argument must not contain
- any ``type of`` nor ``value of``.
-
-.. tacn:: subst @ident
- :name: subst
-
- This tactic applies to a goal that has :n:`@ident` in its context and (at
- least) one hypothesis, say :g:`H`, of type :n:`@ident = t` or :n:`t = @ident`
- with :n:`@ident` not occurring in :g:`t`. Then it replaces :n:`@ident` by
- :g:`t` everywhere in the goal (in the hypotheses and in the conclusion) and
- clears :n:`@ident` and :g:`H` from the context.
-
- If :n:`@ident` is a local definition of the form :n:`@ident := t`, it is also
- unfolded and cleared.
-
- If :n:`@ident` is a section variable it is expected to have no
- indirect occurrences in the goal, i.e. that no global declarations
- implicitly depending on the section variable must be present in the
- goal.
-
- .. note::
- + When several hypotheses have the form :n:`@ident = t` or :n:`t = @ident`, the
- first one is used.
-
- + If :g:`H` is itself dependent in the goal, it is replaced by the proof of
- reflexivity of equality.
-
- .. tacv:: subst {+ @ident}
-
- This is equivalent to :n:`subst @ident`:sub:`1`:n:`; ...; subst @ident`:sub:`n`.
-
- .. tacv:: subst
-
- This applies :tacn:`subst` repeatedly from top to bottom to all hypotheses of the
- context for which an equality of the form :n:`@ident = t` or :n:`t = @ident`
- or :n:`@ident := t` exists, with :n:`@ident` not occurring in
- ``t`` and :n:`@ident` not a section variable with indirect
- dependencies in the goal.
-
- .. flag:: Regular Subst Tactic
-
- This flag controls the behavior of :tacn:`subst`. When it is
- activated (it is by default), :tacn:`subst` also deals with the following corner cases:
-
- + A context with ordered hypotheses :n:`@ident`:sub:`1` :n:`= @ident`:sub:`2`
- and :n:`@ident`:sub:`1` :n:`= t`, or :n:`t′ = @ident`:sub:`1`` with `t′` not
- a variable, and no other hypotheses of the form :n:`@ident`:sub:`2` :n:`= u`
- or :n:`u = @ident`:sub:`2`; without the flag, a second call to
- subst would be necessary to replace :n:`@ident`:sub:`2` by `t` or
- `t′` respectively.
- + The presence of a recursive equation which without the flag would
- be a cause of failure of :tacn:`subst`.
- + A context with cyclic dependencies as with hypotheses :n:`@ident`:sub:`1` :n:`= f @ident`:sub:`2`
- and :n:`@ident`:sub:`2` :n:`= g @ident`:sub:`1` which without the
- flag would be a cause of failure of :tacn:`subst`.
-
- Additionally, it prevents a local definition such as :n:`@ident := t` to be
- unfolded which otherwise it would exceptionally unfold in configurations
- containing hypotheses of the form :n:`@ident = u`, or :n:`u′ = @ident`
- with `u′` not a variable. Finally, it preserves the initial order of
- hypotheses, which without the flag it may break.
- default.
-
- .. exn:: Cannot find any non-recursive equality over :n:`@ident`.
- :undocumented:
-
- .. exn:: Section variable :n:`@ident` occurs implicitly in global declaration :n:`@qualid` present in hypothesis :n:`@ident`.
- Section variable :n:`@ident` occurs implicitly in global declaration :n:`@qualid` present in the conclusion.
-
- Raised when the variable is a section variable with indirect
- dependencies in the goal.
-
-
-.. tacn:: stepl @term
- :name: stepl
-
- This tactic is for chaining rewriting steps. It assumes a goal of the
- form :n:`R @term @term` where ``R`` is a binary relation and relies on a
- database of lemmas of the form :g:`forall x y z, R x y -> eq x z -> R z y`
- where `eq` is typically a setoid equality. The application of :n:`stepl @term`
- then replaces the goal by :n:`R @term @term` and adds a new goal stating
- :n:`eq @term @term`.
-
- .. cmd:: Declare Left Step @term
-
- Adds :n:`@term` to the database used by :tacn:`stepl`.
-
- This tactic is especially useful for parametric setoids which are not accepted
- as regular setoids for :tacn:`rewrite` and :tacn:`setoid_replace` (see
- :ref:`Generalizedrewriting`).
-
- .. tacv:: stepl @term by @tactic
-
- This applies :n:`stepl @term` then applies :token:`tactic` to the second goal.
-
- .. tacv:: stepr @term by @tactic
- :name: stepr
-
- This behaves as :tacn:`stepl` but on the right-hand-side of the binary
- relation. Lemmas are expected to be of the form
- :g:`forall x y z, R x y -> eq y z -> R x z`.
-
- .. cmd:: Declare Right Step @term
-
- Adds :n:`@term` to the database used by :tacn:`stepr`.
-
-
-.. tacn:: change @term
- :name: change
-
- This tactic applies to any goal. It implements the rule ``Conv`` given in
- :ref:`subtyping-rules`. :g:`change U` replaces the current goal `T`
- with `U` providing that `U` is well-formed and that `T` and `U` are
- convertible.
-
- .. exn:: Not convertible.
- :undocumented:
-
- .. tacv:: change @term with @term’
-
- This replaces the occurrences of :n:`@term` by :n:`@term’` in the current goal.
- The term :n:`@term` and :n:`@term’` must be convertible.
-
- .. tacv:: change @term at {+ @natural} with @term’
-
- This replaces the occurrences numbered :n:`{+ @natural}` of :n:`@term` by :n:`@term’`
- in the current goal. The terms :n:`@term` and :n:`@term’` must be convertible.
-
- .. exn:: Too few occurrences.
- :undocumented:
-
- .. tacv:: change @term {? {? at {+ @natural}} with @term} in @ident
-
- This applies the :tacn:`change` tactic not to the goal but to the hypothesis :n:`@ident`.
-
- .. tacv:: now_show @term
-
- This is a synonym of :n:`change @term`. It can be used to
- make some proof steps explicit when refactoring a proof script
- to make it readable.
-
- .. seealso:: :ref:`Performing computations <performingcomputations>`
-
-.. _performingcomputations:
-
-Performing computations
----------------------------
-
-.. insertprodn red_expr pattern_occ
-
-.. prodn::
- red_expr ::= red
- | hnf
- | simpl {? @delta_flag } {? @ref_or_pattern_occ }
- | cbv {? @strategy_flag }
- | cbn {? @strategy_flag }
- | lazy {? @strategy_flag }
- | compute {? @delta_flag }
- | vm_compute {? @ref_or_pattern_occ }
- | native_compute {? @ref_or_pattern_occ }
- | unfold {+, @unfold_occ }
- | fold {+ @one_term }
- | pattern {+, @pattern_occ }
- | @ident
- delta_flag ::= {? - } [ {+ @reference } ]
- strategy_flag ::= {+ @red_flag }
- | @delta_flag
- red_flag ::= beta
- | iota
- | match
- | fix
- | cofix
- | zeta
- | delta {? @delta_flag }
- ref_or_pattern_occ ::= @reference {? at @occs_nums }
- | @one_term {? at @occs_nums }
- occs_nums ::= {+ {| @natural | @ident } }
- | - {| @natural | @ident } {* @int_or_var }
- int_or_var ::= @integer
- | @ident
- unfold_occ ::= @reference {? at @occs_nums }
- pattern_occ ::= @one_term {? at @occs_nums }
-
-This set of tactics implements different specialized usages of the
-tactic :tacn:`change`.
-
-All conversion tactics (including :tacn:`change`) can be parameterized by the
-parts of the goal where the conversion can occur. This is done using
-*goal clauses* which consists in a list of hypotheses and, optionally,
-of a reference to the conclusion of the goal. For defined hypothesis
-it is possible to specify if the conversion should occur on the type
-part, the body part or both (default).
-
-Goal clauses are written after a conversion tactic (tactics :tacn:`set`,
-:tacn:`rewrite`, :tacn:`replace` and :tacn:`autorewrite` also use goal
-clauses) and are introduced by the keyword `in`. If no goal clause is
-provided, the default is to perform the conversion only in the
-conclusion.
-
-The syntax and description of the various goal clauses is the
-following:
-
-+ :n:`in {+ @ident} |-` only in hypotheses :n:`{+ @ident}`
-+ :n:`in {+ @ident} |- *` in hypotheses :n:`{+ @ident}` and in the
- conclusion
-+ :n:`in * |-` in every hypothesis
-+ :n:`in *` (equivalent to in :n:`* |- *`) everywhere
-+ :n:`in (type of @ident) (value of @ident) ... |-` in type part of
- :n:`@ident`, in the value part of :n:`@ident`, etc.
-
-For backward compatibility, the notation :n:`in {+ @ident}` performs
-the conversion in hypotheses :n:`{+ @ident}`.
-
-.. tacn:: cbv {? @strategy_flag }
- lazy {? @strategy_flag }
- :name: cbv; lazy
-
- These parameterized reduction tactics apply to any goal and perform
- the normalization of the goal according to the specified flags. In
- correspondence with the kinds of reduction considered in Coq namely
- :math:`\beta` (reduction of functional application), :math:`\delta`
- (unfolding of transparent constants, see :ref:`vernac-controlling-the-reduction-strategies`),
- :math:`\iota` (reduction of
- pattern matching over a constructed term, and unfolding of :g:`fix` and
- :g:`cofix` expressions) and :math:`\zeta` (contraction of local definitions), the
- flags are either ``beta``, ``delta``, ``match``, ``fix``, ``cofix``,
- ``iota`` or ``zeta``. The ``iota`` flag is a shorthand for ``match``, ``fix``
- and ``cofix``. The ``delta`` flag itself can be refined into
- :n:`delta [ {+ @qualid} ]` or :n:`delta - [ {+ @qualid} ]`, restricting in the first
- case the constants to unfold to the constants listed, and restricting in the
- second case the constant to unfold to all but the ones explicitly mentioned.
- Notice that the ``delta`` flag does not apply to variables bound by a let-in
- construction inside the :n:`@term` itself (use here the ``zeta`` flag). In
- any cases, opaque constants are not unfolded (see :ref:`vernac-controlling-the-reduction-strategies`).
-
- Normalization according to the flags is done by first evaluating the
- head of the expression into a *weak-head* normal form, i.e. until the
- evaluation is blocked by a variable (or an opaque constant, or an
- axiom), as e.g. in :g:`x u1 ... un` , or :g:`match x with ... end`, or
- :g:`(fix f x {struct x} := ...) x`, or is a constructed form (a
- :math:`\lambda`-expression, a constructor, a cofixpoint, an inductive type, a
- product type, a sort), or is a redex that the flags prevent to reduce. Once a
- weak-head normal form is obtained, subterms are recursively reduced using the
- same strategy.
-
- Reduction to weak-head normal form can be done using two strategies:
- *lazy* (``lazy`` tactic), or *call-by-value* (``cbv`` tactic). The lazy
- strategy is a call-by-need strategy, with sharing of reductions: the
- arguments of a function call are weakly evaluated only when necessary,
- and if an argument is used several times then it is weakly computed
- only once. This reduction is efficient for reducing expressions with
- dead code. For instance, the proofs of a proposition :g:`exists x. P(x)`
- reduce to a pair of a witness :g:`t`, and a proof that :g:`t` satisfies the
- predicate :g:`P`. Most of the time, :g:`t` may be computed without computing
- the proof of :g:`P(t)`, thanks to the lazy strategy.
-
- The call-by-value strategy is the one used in ML languages: the
- arguments of a function call are systematically weakly evaluated
- first. Despite the lazy strategy always performs fewer reductions than
- the call-by-value strategy, the latter is generally more efficient for
- evaluating purely computational expressions (i.e. with little dead code).
-
-.. tacv:: compute
- cbv
- :name: compute; _
-
- These are synonyms for ``cbv beta delta iota zeta``.
-
-.. tacv:: lazy
-
- This is a synonym for ``lazy beta delta iota zeta``.
-
-.. tacv:: compute [ {+ @qualid} ]
- cbv [ {+ @qualid} ]
-
- These are synonyms of :n:`cbv beta delta {+ @qualid} iota zeta`.
-
-.. tacv:: compute - [ {+ @qualid} ]
- cbv - [ {+ @qualid} ]
-
- These are synonyms of :n:`cbv beta delta -{+ @qualid} iota zeta`.
-
-.. tacv:: lazy [ {+ @qualid} ]
- lazy - [ {+ @qualid} ]
-
- These are respectively synonyms of :n:`lazy beta delta {+ @qualid} iota zeta`
- and :n:`lazy beta delta -{+ @qualid} iota zeta`.
-
-.. tacv:: vm_compute
- :name: vm_compute
-
- This tactic evaluates the goal using the optimized call-by-value evaluation
- bytecode-based virtual machine described in :cite:`CompiledStrongReduction`.
- This algorithm is dramatically more efficient than the algorithm used for the
- :tacn:`cbv` tactic, but it cannot be fine-tuned. It is especially interesting for
- full evaluation of algebraic objects. This includes the case of
- reflection-based tactics.
-
-.. tacv:: native_compute
- :name: native_compute
-
- This tactic evaluates the goal by compilation to OCaml as described
- in :cite:`FullReduction`. If Coq is running in native code, it can be
- typically two to five times faster than :tacn:`vm_compute`. Note however that the
- compilation cost is higher, so it is worth using only for intensive
- computations.
-
- .. flag:: NativeCompute Timing
-
- This flag causes all calls to the native compiler to print
- timing information for the conversion to native code,
- compilation, execution, and reification phases of native
- compilation. Timing is printed in units of seconds of
- wall-clock time.
-
- .. flag:: NativeCompute Profiling
-
- On Linux, if you have the ``perf`` profiler installed, this flag makes
- it possible to profile :tacn:`native_compute` evaluations.
-
- .. opt:: NativeCompute Profile Filename @string
- :name: NativeCompute Profile Filename
-
- This option specifies the profile output; the default is
- ``native_compute_profile.data``. The actual filename used
- will contain extra characters to avoid overwriting an existing file; that
- filename is reported to the user.
- That means you can individually profile multiple uses of
- :tacn:`native_compute` in a script. From the Linux command line, run ``perf report``
- on the profile file to see the results. Consult the ``perf`` documentation
- for more details.
-
-.. flag:: Debug Cbv
-
- This flag makes :tacn:`cbv` (and its derivative :tacn:`compute`) print
- information about the constants it encounters and the unfolding decisions it
- makes.
-
-.. tacn:: red
- :name: red
-
- This tactic applies to a goal that has the form::
-
- forall (x:T1) ... (xk:Tk), T
-
- with :g:`T` :math:`\beta`:math:`\iota`:math:`\zeta`-reducing to :g:`c t`:sub:`1` :g:`... t`:sub:`n` and :g:`c` a
- constant. If :g:`c` is transparent then it replaces :g:`c` with its
- definition (say :g:`t`) and then reduces
- :g:`(t t`:sub:`1` :g:`... t`:sub:`n` :g:`)` according to :math:`\beta`:math:`\iota`:math:`\zeta`-reduction rules.
-
-.. exn:: Not reducible.
- :undocumented:
-
-.. exn:: No head constant to reduce.
- :undocumented:
-
-.. tacn:: hnf
- :name: hnf
-
- This tactic applies to any goal. It replaces the current goal with its
- head normal form according to the :math:`\beta`:math:`\delta`:math:`\iota`:math:`\zeta`-reduction rules, i.e. it
- reduces the head of the goal until it becomes a product or an
- irreducible term. All inner :math:`\beta`:math:`\iota`-redexes are also reduced.
- The behavior of both :tacn:`hnf` can be tuned using the :cmd:`Arguments` command.
-
- Example: The term :g:`fun n : nat => S n + S n` is not reduced by :n:`hnf`.
-
-.. note::
- The :math:`\delta` rule only applies to transparent constants (see :ref:`vernac-controlling-the-reduction-strategies`
- on transparency and opacity).
-
-.. tacn:: cbn
- simpl
- :name: cbn; simpl
-
- These tactics apply to any goal. They try to reduce a term to
- something still readable instead of fully normalizing it. They perform
- a sort of strong normalization with two key differences:
-
- + They unfold a constant if and only if it leads to a :math:`\iota`-reduction,
- i.e. reducing a match or unfolding a fixpoint.
- + While reducing a constant unfolding to (co)fixpoints, the tactics
- use the name of the constant the (co)fixpoint comes from instead of
- the (co)fixpoint definition in recursive calls.
-
- The :tacn:`cbn` tactic is claimed to be a more principled, faster and more
- predictable replacement for :tacn:`simpl`.
-
- The :tacn:`cbn` tactic accepts the same flags as :tacn:`cbv` and
- :tacn:`lazy`. The behavior of both :tacn:`simpl` and :tacn:`cbn`
- can be tuned using the :cmd:`Arguments` command.
-
- .. todo add "See <subsection about controlling the behavior of reduction strategies>"
- to TBA section
-
- Notice that only transparent constants whose name can be reused in the
- recursive calls are possibly unfolded by :tacn:`simpl`. For instance a
- constant defined by :g:`plus' := plus` is possibly unfolded and reused in
- the recursive calls, but a constant such as :g:`succ := plus (S O)` is
- never unfolded. This is the main difference between :tacn:`simpl` and :tacn:`cbn`.
- The tactic :tacn:`cbn` reduces whenever it will be able to reuse it or not:
- :g:`succ t` is reduced to :g:`S t`.
-
-.. tacv:: cbn [ {+ @qualid} ]
- cbn - [ {+ @qualid} ]
-
- These are respectively synonyms of :n:`cbn beta delta [ {+ @qualid} ] iota zeta`
- and :n:`cbn beta delta - [ {+ @qualid} ] iota zeta` (see :tacn:`cbn`).
-
-.. tacv:: simpl @pattern
-
- This applies :tacn:`simpl` only to the subterms matching
- :n:`@pattern` in the current goal.
-
-.. tacv:: simpl @pattern at {+ @natural}
-
- This applies :tacn:`simpl` only to the :n:`{+ @natural}` occurrences of the subterms
- matching :n:`@pattern` in the current goal.
-
- .. exn:: Too few occurrences.
- :undocumented:
-
-.. tacv:: simpl @qualid
- simpl @string
-
- This applies :tacn:`simpl` only to the applicative subterms whose head occurrence
- is the unfoldable constant :n:`@qualid` (the constant can be referred to by
- its notation using :n:`@string` if such a notation exists).
-
-.. tacv:: simpl @qualid at {+ @natural}
- simpl @string at {+ @natural}
-
- This applies :tacn:`simpl` only to the :n:`{+ @natural}` applicative subterms whose
- head occurrence is :n:`@qualid` (or :n:`@string`).
-
-.. flag:: Debug RAKAM
-
- This flag makes :tacn:`cbn` print various debugging information.
- ``RAKAM`` is the Refolding Algebraic Krivine Abstract Machine.
-
-.. tacn:: unfold @qualid
- :name: unfold
-
- This tactic applies to any goal. The argument qualid must denote a
- defined transparent constant or local definition (see
- :ref:`gallina-definitions` and
- :ref:`vernac-controlling-the-reduction-strategies`). The tactic
- :tacn:`unfold` applies the :math:`\delta` rule to each occurrence
- of the constant to which :n:`@qualid` refers in the current goal
- and then replaces it with its :math:`\beta\iota\zeta`-normal form.
- Use the general reduction tactics if you want to avoid this final
- reduction, for instance :n:`cbv delta [@qualid]`.
-
- .. exn:: Cannot coerce @qualid to an evaluable reference.
-
- This error is frequent when trying to unfold something that has
- defined as an inductive type (or constructor) and not as a
- definition.
-
- .. example::
-
- .. coqtop:: abort all fail
-
- Goal 0 <= 1.
- unfold le.
-
- This error can also be raised if you are trying to unfold
- something that has been marked as opaque.
-
- .. example::
-
- .. coqtop:: abort all fail
-
- Opaque Nat.add.
- Goal 1 + 0 = 1.
- unfold Nat.add.
-
- .. tacv:: unfold @qualid in @goal_occurrences
-
- Replaces :n:`@qualid` in hypothesis (or hypotheses) designated
- by :token:`goal_occurrences` with its definition and replaces
- the hypothesis with its :math:`\beta`:math:`\iota` normal form.
-
- .. tacv:: unfold {+, @qualid}
-
- Replaces :n:`{+, @qualid}` with their definitions and replaces
- the current goal with its :math:`\beta`:math:`\iota` normal
- form.
-
- .. tacv:: unfold {+, @qualid at @occurrences }
-
- The list :token:`occurrences` specify the occurrences of
- :n:`@qualid` to be unfolded. Occurrences are located from left
- to right.
-
- .. exn:: Bad occurrence number of @qualid.
- :undocumented:
-
- .. exn:: @qualid does not occur.
- :undocumented:
-
- .. tacv:: unfold @string
-
- If :n:`@string` denotes the discriminating symbol of a notation
- (e.g. "+") or an expression defining a notation (e.g. `"_ +
- _"`), and this notation denotes an application whose head symbol
- is an unfoldable constant, then the tactic unfolds it.
-
- .. tacv:: unfold @string%@ident
-
- This is variant of :n:`unfold @string` where :n:`@string` gets
- its interpretation from the scope bound to the delimiting key
- :token:`ident` instead of its default interpretation (see
- :ref:`Localinterpretationrulesfornotations`).
-
- .. tacv:: unfold {+, {| @qualid | @string{? %@ident } } {? at @occurrences } } {? in @goal_occurrences }
-
- This is the most general form.
-
-.. tacn:: fold @term
- :name: fold
-
- This tactic applies to any goal. The term :n:`@term` is reduced using the
- :tacn:`red` tactic. Every occurrence of the resulting :n:`@term` in the goal is
- then replaced by :n:`@term`. This tactic is particularly useful when a fixpoint
- definition has been wrongfully unfolded, making the goal very hard to read.
- On the other hand, when an unfolded function applied to its argument has been
- reduced, the :tacn:`fold` tactic won't do anything.
-
- .. example::
-
- .. coqtop:: all abort
-
- Goal ~0=0.
- unfold not.
- Fail progress fold not.
- pattern (0 = 0).
- fold not.
-
- .. tacv:: fold {+ @term}
-
- Equivalent to :n:`fold @term ; ... ; fold @term`.
-
-.. tacn:: pattern @term
- :name: pattern
-
- This command applies to any goal. The argument :n:`@term` must be a free
- subterm of the current goal. The command pattern performs :math:`\beta`-expansion
- (the inverse of :math:`\beta`-reduction) of the current goal (say :g:`T`) by
-
- + replacing all occurrences of :n:`@term` in :g:`T` with a fresh variable
- + abstracting this variable
- + applying the abstracted goal to :n:`@term`
-
- For instance, if the current goal :g:`T` is expressible as
- :math:`\varphi`:g:`(t)` where the notation captures all the instances of :g:`t`
- in :math:`\varphi`:g:`(t)`, then :n:`pattern t` transforms it into
- :g:`(fun x:A =>` :math:`\varphi`:g:`(x)) t`. This tactic can be used, for
- instance, when the tactic ``apply`` fails on matching.
-
-.. tacv:: pattern @term at {+ @natural}
-
- Only the occurrences :n:`{+ @natural}` of :n:`@term` are considered for
- :math:`\beta`-expansion. Occurrences are located from left to right.
-
-.. tacv:: pattern @term at - {+ @natural}
-
- All occurrences except the occurrences of indexes :n:`{+ @natural }`
- of :n:`@term` are considered for :math:`\beta`-expansion. Occurrences are located from
- left to right.
-
-.. tacv:: pattern {+, @term}
-
- Starting from a goal :math:`\varphi`:g:`(t`:sub:`1` :g:`... t`:sub:`m`:g:`)`,
- the tactic :n:`pattern t`:sub:`1`:n:`, ..., t`:sub:`m` generates the
- equivalent goal
- :g:`(fun (x`:sub:`1`:g:`:A`:sub:`1`:g:`) ... (x`:sub:`m` :g:`:A`:sub:`m` :g:`) =>`:math:`\varphi`:g:`(x`:sub:`1` :g:`... x`:sub:`m` :g:`)) t`:sub:`1` :g:`... t`:sub:`m`.
- If :g:`t`:sub:`i` occurs in one of the generated types :g:`A`:sub:`j` these
- occurrences will also be considered and possibly abstracted.
-
-.. tacv:: pattern {+, @term at {+ @natural}}
-
- This behaves as above but processing only the occurrences :n:`{+ @natural}` of
- :n:`@term` starting from :n:`@term`.
-
-.. tacv:: pattern {+, @term {? at {? -} {+, @natural}}}
-
- This is the most general syntax that combines the different variants.
-
-.. tacn:: with_strategy @strategy_level_or_var [ {+ @reference } ] @ltac_expr3
- :name: with_strategy
-
- Executes :token:`ltac_expr3`, applying the alternate unfolding
- behavior that the :cmd:`Strategy` command controls, but only for
- :token:`ltac_expr3`. This can be useful for guarding calls to
- reduction in tactic automation to ensure that certain constants are
- never unfolded by tactics like :tacn:`simpl` and :tacn:`cbn` or to
- ensure that unfolding does not fail.
-
- .. example::
-
- .. coqtop:: all reset abort
-
- Opaque id.
- Goal id 10 = 10.
- Fail unfold id.
- with_strategy transparent [id] unfold id.
-
- .. warning::
-
- Use this tactic with care, as effects do not persist past the
- end of the proof script. Notably, this fine-tuning of the
- conversion strategy is not in effect during :cmd:`Qed` nor
- :cmd:`Defined`, so this tactic is most useful either in
- combination with :tacn:`abstract`, which will check the proof
- early while the fine-tuning is still in effect, or to guard
- calls to conversion in tactic automation to ensure that, e.g.,
- :tacn:`unfold` does not fail just because the user made a
- constant :cmd:`Opaque`.
-
- This can be illustrated with the following example involving the
- factorial function.
-
- .. coqtop:: in reset
-
- Fixpoint fact (n : nat) : nat :=
- match n with
- | 0 => 1
- | S n' => n * fact n'
- end.
-
- Suppose now that, for whatever reason, we want in general to
- unfold the :g:`id` function very late during conversion:
-
- .. coqtop:: in
-
- Strategy 1000 [id].
-
- If we try to prove :g:`id (fact n) = fact n` by
- :tacn:`reflexivity`, it will now take time proportional to
- :math:`n!`, because |Coq| will keep unfolding :g:`fact` and
- :g:`*` and :g:`+` before it unfolds :g:`id`, resulting in a full
- computation of :g:`fact n` (in unary, because we are using
- :g:`nat`), which takes time :math:`n!`. We can see this cross
- the relevant threshold at around :math:`n = 9`:
-
- .. coqtop:: all abort
-
- Goal True.
- Time assert (id (fact 8) = fact 8) by reflexivity.
- Time assert (id (fact 9) = fact 9) by reflexivity.
-
- Note that behavior will be the same if you mark :g:`id` as
- :g:`Opaque` because while most reduction tactics refuse to
- unfold :g:`Opaque` constants, conversion treats :g:`Opaque` as
- merely a hint to unfold this constant last.
-
- We can get around this issue by using :tacn:`with_strategy`:
-
- .. coqtop:: all
-
- Goal True.
- Fail Timeout 1 assert (id (fact 100) = fact 100) by reflexivity.
- Time assert (id (fact 100) = fact 100) by with_strategy -1 [id] reflexivity.
-
- However, when we go to close the proof, we will run into
- trouble, because the reduction strategy changes are local to the
- tactic passed to :tacn:`with_strategy`.
-
- .. coqtop:: all abort fail
-
- exact I.
- Timeout 1 Defined.
-
- We can fix this issue by using :tacn:`abstract`:
-
- .. coqtop:: all
-
- Goal True.
- Time assert (id (fact 100) = fact 100) by with_strategy -1 [id] abstract reflexivity.
- exact I.
- Time Defined.
-
- On small examples this sort of behavior doesn't matter, but
- because |Coq| is a super-linear performance domain in so many
- places, unless great care is taken, tactic automation using
- :tacn:`with_strategy` may not be robustly performant when
- scaling the size of the input.
-
- .. warning::
-
- In much the same way this tactic does not play well with
- :cmd:`Qed` and :cmd:`Defined` without using :tacn:`abstract` as
- an intermediary, this tactic does not play well with ``coqchk``,
- even when used with :tacn:`abstract`, due to the inability of
- tactics to persist information about conversion hints in the
- proof term. See `#12200
- <https://github.com/coq/coq/issues/12200>`_ for more details.
-
-Conversion tactics applied to hypotheses
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-.. tacn:: @tactic in {+, @ident}
-
- Applies :token:`tactic` (any of the conversion tactics listed in this
- section) to the hypotheses :n:`{+ @ident}`.
-
- If :token:`ident` is a local definition, then :token:`ident` can be replaced by
- :n:`type of @ident` to address not the body but the type of the local
- definition.
-
- Example: :n:`unfold not in (type of H1) (type of H3)`.
-
-.. exn:: No such hypothesis: @ident.
- :undocumented:
-
-
-.. _automation:
-
-Automation
-----------
-
-.. tacn:: auto
- :name: auto
-
- This tactic implements a Prolog-like resolution procedure to solve the
- current goal. It first tries to solve the goal using the :tacn:`assumption`
- tactic, then it reduces the goal to an atomic one using :tacn:`intros` and
- introduces the newly generated hypotheses as hints. Then it looks at
- the list of tactics associated to the head symbol of the goal and
- tries to apply one of them (starting from the tactics with lower
- cost). This process is recursively applied to the generated subgoals.
-
- By default, :tacn:`auto` only uses the hypotheses of the current goal and
- the hints of the database named ``core``.
-
- .. warning::
-
- :tacn:`auto` uses a weaker version of :tacn:`apply` that is closer to
- :tacn:`simple apply` so it is expected that sometimes :tacn:`auto` will
- fail even if applying manually one of the hints would succeed.
-
- .. tacv:: auto @natural
-
- Forces the search depth to be :token:`natural`. The maximal search depth
- is 5 by default.
-
- .. tacv:: auto with {+ @ident}
-
- Uses the hint databases :n:`{+ @ident}` in addition to the database ``core``.
-
- .. note::
-
- Use the fake database `nocore` if you want to *not* use the `core`
- database.
-
- .. tacv:: auto with *
-
- Uses all existing hint databases. Using this variant is highly discouraged
- in finished scripts since it is both slower and less robust than the variant
- where the required databases are explicitly listed.
-
- .. seealso::
- :ref:`The Hints Databases for auto and eauto <thehintsdatabasesforautoandeauto>` for the list of
- pre-defined databases and the way to create or extend a database.
-
- .. tacv:: auto using {+ @qualid__i} {? with {+ @ident } }
-
- Uses lemmas :n:`@qualid__i` in addition to hints. If :n:`@qualid` is an
- inductive type, it is the collection of its constructors which are added
- as hints.
-
- .. note::
-
- The hints passed through the `using` clause are used in the same
- way as if they were passed through a hint database. Consequently,
- they use a weaker version of :tacn:`apply` and :n:`auto using @qualid`
- may fail where :n:`apply @qualid` succeeds.
-
- Given that this can be seen as counter-intuitive, it could be useful
- to have an option to use full-blown :tacn:`apply` for lemmas passed
- through the `using` clause. Contributions welcome!
-
- .. tacv:: info_auto
-
- Behaves like :tacn:`auto` but shows the tactics it uses to solve the goal. This
- variant is very useful for getting a better understanding of automation, or
- to know what lemmas/assumptions were used.
-
- .. tacv:: debug auto
- :name: debug auto
-
- Behaves like :tacn:`auto` but shows the tactics it tries to solve the goal,
- including failing paths.
-
- .. tacv:: {? info_}auto {? @natural} {? using {+ @qualid}} {? with {+ @ident}}
-
- This is the most general form, combining the various options.
-
-.. tacv:: trivial
- :name: trivial
-
- This tactic is a restriction of :tacn:`auto` that is not recursive
- and tries only hints that cost `0`. Typically it solves trivial
- equalities like :g:`X=X`.
-
- .. tacv:: trivial with {+ @ident}
- trivial with *
- trivial using {+ @qualid}
- debug trivial
- info_trivial
- {? info_}trivial {? using {+ @qualid}} {? with {+ @ident}}
- :name: _; _; _; debug trivial; info_trivial; _
- :undocumented:
-
-.. note::
- :tacn:`auto` and :tacn:`trivial` either solve completely the goal or
- else succeed without changing the goal. Use :g:`solve [ auto ]` and
- :g:`solve [ trivial ]` if you would prefer these tactics to fail when
- they do not manage to solve the goal.
-
-.. flag:: Info Auto
- Debug Auto
- Info Trivial
- Debug Trivial
-
- These flags enable printing of informative or debug information for
- the :tacn:`auto` and :tacn:`trivial` tactics.
-
-.. tacn:: eauto
- :name: eauto
-
- This tactic generalizes :tacn:`auto`. While :tacn:`auto` does not try
- resolution hints which would leave existential variables in the goal,
- :tacn:`eauto` does try them (informally speaking, it internally uses a tactic
- close to :tacn:`simple eapply` instead of a tactic close to :tacn:`simple apply`
- in the case of :tacn:`auto`). As a consequence, :tacn:`eauto`
- can solve such a goal:
-
- .. example::
-
- .. coqtop:: all
-
- Hint Resolve ex_intro : core.
- Goal forall P:nat -> Prop, P 0 -> exists n, P n.
- eauto.
-
- Note that ``ex_intro`` should be declared as a hint.
-
-
- .. tacv:: {? info_}eauto {? @natural} {? using {+ @qualid}} {? with {+ @ident}}
-
- The various options for :tacn:`eauto` are the same as for :tacn:`auto`.
-
- :tacn:`eauto` also obeys the following flags:
-
- .. flag:: Info Eauto
- Debug Eauto
- :undocumented:
-
- .. seealso:: :ref:`The Hints Databases for auto and eauto <thehintsdatabasesforautoandeauto>`
-
-
-.. tacn:: autounfold with {+ @ident}
- :name: autounfold
-
- This tactic unfolds constants that were declared through a :cmd:`Hint Unfold`
- in the given databases.
-
-.. tacv:: autounfold with {+ @ident} in @goal_occurrences
-
- Performs the unfolding in the given clause (:token:`goal_occurrences`).
-
-.. tacv:: autounfold with *
-
- Uses the unfold hints declared in all the hint databases.
-
-.. tacn:: autorewrite with {+ @ident}
- :name: autorewrite
-
- This tactic carries out rewritings according to the rewriting rule
- bases :n:`{+ @ident}`.
-
- Each rewriting rule from the base :n:`@ident` is applied to the main subgoal until
- it fails. Once all the rules have been processed, if the main subgoal has
- progressed (e.g., if it is distinct from the initial main goal) then the rules
- of this base are processed again. If the main subgoal has not progressed then
- the next base is processed. For the bases, the behavior is exactly similar to
- the processing of the rewriting rules.
-
- The rewriting rule bases are built with the :cmd:`Hint Rewrite`
- command.
-
-.. warning::
-
- This tactic may loop if you build non terminating rewriting systems.
-
-.. tacv:: autorewrite with {+ @ident} using @tactic
-
- Performs, in the same way, all the rewritings of the bases :n:`{+ @ident}`
- applying tactic to the main subgoal after each rewriting step.
-
-.. tacv:: autorewrite with {+ @ident} in @qualid
-
- Performs all the rewritings in hypothesis :n:`@qualid`.
-
-.. tacv:: autorewrite with {+ @ident} in @qualid using @tactic
-
- Performs all the rewritings in hypothesis :n:`@qualid` applying :n:`@tactic`
- to the main subgoal after each rewriting step.
-
-.. tacv:: autorewrite with {+ @ident} in @goal_occurrences
-
- Performs all the rewriting in the clause :n:`@goal_occurrences`.
-
-.. seealso::
-
- :ref:`Hint-Rewrite <hintrewrite>` for feeding the database of lemmas used by
- :tacn:`autorewrite` and :tacn:`autorewrite` for examples showing the use of this tactic.
-
-.. tacn:: easy
- :name: easy
-
- This tactic tries to solve the current goal by a number of standard closing steps.
- In particular, it tries to close the current goal using the closing tactics
- :tacn:`trivial`, :tacn:`reflexivity`, :tacn:`symmetry`, :tacn:`contradiction`
- and :tacn:`inversion` of hypothesis.
- If this fails, it tries introducing variables and splitting and-hypotheses,
- using the closing tactics afterwards, and splitting the goal using
- :tacn:`split` and recursing.
-
- This tactic solves goals that belong to many common classes; in particular, many cases of
- unsatisfiable hypotheses, and simple equality goals are usually solved by this tactic.
-
-.. tacv:: now @tactic
- :name: now
-
- Run :n:`@tactic` followed by :tacn:`easy`. This is a notation for :n:`@tactic; easy`.
-
-Controlling automation
---------------------------
-
-.. _thehintsdatabasesforautoandeauto:
-
-The hints databases for auto and eauto
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-The hints for :tacn:`auto` and :tacn:`eauto` are stored in databases. Each database
-maps head symbols to a list of hints.
-
-.. cmd:: Print Hint @ident
-
- Use this command
- to display the hints associated to the head symbol :n:`@ident`
- (see :ref:`Print Hint <printhint>`). Each hint has a cost that is a nonnegative
- integer, and an optional pattern. The hints with lower cost are tried first. A
- hint is tried by :tacn:`auto` when the conclusion of the current goal matches its
- pattern or when it has no pattern.
-
-Creating Hint databases
-```````````````````````
-
-One can optionally declare a hint database using the command
-:cmd:`Create HintDb`. If a hint is added to an unknown database, it will be
-automatically created.
-
-.. cmd:: Create HintDb @ident {? discriminated}
-
- This command creates a new database named :n:`@ident`. The database is
- implemented by a Discrimination Tree (DT) that serves as an index of
- all the lemmas. The DT can use transparency information to decide if a
- constant should be indexed or not
- (c.f. :ref:`The hints databases for auto and eauto <thehintsdatabasesforautoandeauto>`),
- making the retrieval more efficient. The legacy implementation (the default one
- for new databases) uses the DT only on goals without existentials (i.e., :tacn:`auto`
- goals), for non-Immediate hints and does not make use of transparency
- hints, putting more work on the unification that is run after
- retrieval (it keeps a list of the lemmas in case the DT is not used).
- The new implementation enabled by the discriminated option makes use
- of DTs in all cases and takes transparency information into account.
- However, the order in which hints are retrieved from the DT may differ
- from the order in which they were inserted, making this implementation
- observationally different from the legacy one.
-
-.. cmd:: Hint @hint_definition : {+ @ident}
-
- The general command to add a hint to some databases :n:`{+ @ident}`.
-
- This command supports the :attr:`local`, :attr:`global` and :attr:`export`
- locality attributes. When no locality is explictly given, the
- command is :attr:`local` inside a section and :attr:`global` otherwise.
-
- + :attr:`local` hints are never visible from other modules, even if they
- require or import the current module. Inside a section, the :attr:`local`
- attribute is useless since hints do not survive anyway to the closure of
- sections.
-
- + :attr:`export` are visible from other modules when they import the current
- module. Requiring it is not enough. This attribute is only effective for
- the :cmd:`Hint Resolve`, :cmd:`Hint Immediate`, :cmd:`Hint Unfold` and
- :cmd:`Hint Extern` variants of the command.
-
- + :attr:`global` hints are made available by merely requiring the current
- module.
-
- The various possible :production:`hint_definition`\s are given below.
-
- .. cmdv:: Hint @hint_definition
-
- No database name is given: the hint is registered in the ``core`` database.
-
- .. deprecated:: 8.10
-
- .. cmdv:: Hint Resolve @qualid {? | {? @natural} {? @pattern}} : @ident
- :name: Hint Resolve
-
- This command adds :n:`simple apply @qualid` to the hint list with the head
- symbol of the type of :n:`@qualid`. The cost of that hint is the number of
- subgoals generated by :n:`simple apply @qualid` or :n:`@natural` if specified. The
- associated :n:`@pattern` is inferred from the conclusion of the type of
- :n:`@qualid` or the given :n:`@pattern` if specified. In case the inferred type
- of :n:`@qualid` does not start with a product the tactic added in the hint list
- is :n:`exact @qualid`. In case this type can however be reduced to a type
- starting with a product, the tactic :n:`simple apply @qualid` is also stored in
- the hints list. If the inferred type of :n:`@qualid` contains a dependent
- quantification on a variable which occurs only in the premisses of the type
- and not in its conclusion, no instance could be inferred for the variable by
- unification with the goal. In this case, the hint is added to the hint list
- of :tacn:`eauto` instead of the hint list of auto and a warning is printed. A
- typical example of a hint that is used only by :tacn:`eauto` is a transitivity
- lemma.
-
- .. exn:: @qualid cannot be used as a hint
-
- The head symbol of the type of :n:`@qualid` is a bound variable
- such that this tactic cannot be associated to a constant.
-
- .. cmdv:: Hint Resolve {+ @qualid} : @ident
-
- Adds each :n:`Hint Resolve @qualid`.
-
- .. cmdv:: Hint Resolve -> @qualid : @ident
-
- Adds the left-to-right implication of an equivalence as a hint (informally
- the hint will be used as :n:`apply <- @qualid`, although as mentioned
- before, the tactic actually used is a restricted version of
- :tacn:`apply`).
-
- .. cmdv:: Hint Resolve <- @qualid
-
- Adds the right-to-left implication of an equivalence as a hint.
-
- .. cmdv:: Hint Immediate @qualid : @ident
- :name: Hint Immediate
-
- This command adds :n:`simple apply @qualid; trivial` to the hint list associated
- with the head symbol of the type of :n:`@ident` in the given database. This
- tactic will fail if all the subgoals generated by :n:`simple apply @qualid` are
- not solved immediately by the :tacn:`trivial` tactic (which only tries tactics
- with cost 0).This command is useful for theorems such as the symmetry of
- equality or :g:`n+1=m+1 -> n=m` that we may like to introduce with a limited
- use in order to avoid useless proof-search. The cost of this tactic (which
- never generates subgoals) is always 1, so that it is not used by :tacn:`trivial`
- itself.
-
- .. exn:: @qualid cannot be used as a hint
- :undocumented:
-
- .. cmdv:: Hint Immediate {+ @qualid} : @ident
-
- Adds each :n:`Hint Immediate @qualid`.
-
- .. cmdv:: Hint Constructors @qualid : @ident
- :name: Hint Constructors
-
- If :token:`qualid` is an inductive type, this command adds all its constructors as
- hints of type ``Resolve``. Then, when the conclusion of current goal has the form
- :n:`(@qualid ...)`, :tacn:`auto` will try to apply each constructor.
-
- .. exn:: @qualid is not an inductive type
- :undocumented:
-
- .. cmdv:: Hint Constructors {+ @qualid} : @ident
-
- Extends the previous command for several inductive types.
-
- .. cmdv:: Hint Unfold @qualid : @ident
- :name: Hint Unfold
-
- This adds the tactic :n:`unfold @qualid` to the hint list that will only be
- used when the head constant of the goal is :token:`qualid`.
- Its cost is 4.
-
- .. cmdv:: Hint Unfold {+ @qualid}
-
- Extends the previous command for several defined constants.
-
- .. cmdv:: Hint Transparent {+ @qualid} : @ident
- Hint Opaque {+ @qualid} : @ident
- :name: Hint Transparent; Hint Opaque
-
- This adds transparency hints to the database, making :n:`@qualid`
- transparent or opaque constants during resolution. This information is used
- during unification of the goal with any lemma in the database and inside the
- discrimination network to relax or constrain it in the case of discriminated
- databases.
-
- .. cmdv:: Hint Variables {| Transparent | Opaque } : @ident
- Hint Constants {| Transparent | Opaque } : @ident
- :name: Hint Variables; Hint Constants
-
- This sets the transparency flag used during unification of
- hints in the database for all constants or all variables,
- overwriting the existing settings of opacity. It is advised
- to use this just after a :cmd:`Create HintDb` command.
-
- .. cmdv:: Hint Extern @natural {? @pattern} => @tactic : @ident
- :name: Hint Extern
-
- This hint type is to extend :tacn:`auto` with tactics other than :tacn:`apply` and
- :tacn:`unfold`. For that, we must specify a cost, an optional :n:`@pattern` and a
- :n:`@tactic` to execute.
-
- .. example::
-
- .. coqtop:: in
-
- Hint Extern 4 (~(_ = _)) => discriminate : core.
-
- Now, when the head of the goal is a disequality, ``auto`` will try
- discriminate if it does not manage to solve the goal with hints with a
- cost less than 4.
-
- One can even use some sub-patterns of the pattern in
- the tactic script. A sub-pattern is a question mark followed by an
- identifier, like ``?X1`` or ``?X2``. Here is an example:
-
- .. example::
-
- .. coqtop:: reset all
-
- Require Import List.
- Hint Extern 5 ({?X1 = ?X2} + {?X1 <> ?X2}) => generalize X1, X2; decide equality : eqdec.
- Goal forall a b:list (nat * nat), {a = b} + {a <> b}.
- Info 1 auto with eqdec.
-
- .. cmdv:: Hint Cut @regexp : @ident
- :name: Hint Cut
-
- .. warning::
-
- These hints currently only apply to typeclass proof search and the
- :tacn:`typeclasses eauto` tactic.
-
- This command can be used to cut the proof-search tree according to a regular
- expression matching paths to be cut. The grammar for regular expressions is
- the following. Beware, there is no operator precedence during parsing, one can
- check with :cmd:`Print HintDb` to verify the current cut expression:
-
- .. prodn::
- regexp ::= @ident (hint or instance identifier)
- | _ (any hint)
- | @regexp | @regexp (disjunction)
- | @regexp @regexp (sequence)
- | @regexp * (Kleene star)
- | emp (empty)
- | eps (epsilon)
- | ( @regexp )
-
- The `emp` regexp does not match any search path while `eps`
- matches the empty path. During proof search, the path of
- successive successful hints on a search branch is recorded, as a
- list of identifiers for the hints (note that :cmd:`Hint Extern`\’s do not have
- an associated identifier).
- Before applying any hint :n:`@ident` the current path `p` extended with
- :n:`@ident` is matched against the current cut expression `c` associated to
- the hint database. If matching succeeds, the hint is *not* applied. The
- semantics of :n:`Hint Cut @regexp` is to set the cut expression
- to :n:`c | regexp`, the initial cut expression being `emp`.
-
- .. cmdv:: Hint Mode @qualid {* {| + | ! | - } } : @ident
- :name: Hint Mode
-
- This sets an optional mode of use of the identifier :n:`@qualid`. When
- proof-search faces a goal that ends in an application of :n:`@qualid` to
- arguments :n:`@term ... @term`, the mode tells if the hints associated to
- :n:`@qualid` can be applied or not. A mode specification is a list of n ``+``,
- ``!`` or ``-`` items that specify if an argument of the identifier is to be
- treated as an input (``+``), if its head only is an input (``!``) or an output
- (``-``) of the identifier. For a mode to match a list of arguments, input
- terms and input heads *must not* contain existential variables or be
- existential variables respectively, while outputs can be any term. Multiple
- modes can be declared for a single identifier, in that case only one mode
- needs to match the arguments for the hints to be applied. The head of a term
- is understood here as the applicative head, or the match or projection
- scrutinee’s head, recursively, casts being ignored. :cmd:`Hint Mode` is
- especially useful for typeclasses, when one does not want to support default
- instances and avoid ambiguity in general. Setting a parameter of a class as an
- input forces proof-search to be driven by that index of the class, with ``!``
- giving more flexibility by allowing existentials to still appear deeper in the
- index but not at its head.
-
- .. note::
-
- + One can use a :cmd:`Hint Extern` with no pattern to do
- pattern matching on hypotheses using ``match goal with``
- inside the tactic.
-
- + If you want to add hints such as :cmd:`Hint Transparent`,
- :cmd:`Hint Cut`, or :cmd:`Hint Mode`, for typeclass
- resolution, do not forget to put them in the
- ``typeclass_instances`` hint database.
-
-
-Hint databases defined in the Coq standard library
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Several hint databases are defined in the Coq standard library. The
-actual content of a database is the collection of hints declared
-to belong to this database in each of the various modules currently
-loaded. Especially, requiring new modules may extend the database.
-At Coq startup, only the core database is nonempty and can be used.
-
-:core: This special database is automatically used by ``auto``, except when
- pseudo-database ``nocore`` is given to ``auto``. The core database
- contains only basic lemmas about negation, conjunction, and so on.
- Most of the hints in this database come from the Init and Logic directories.
-
-:arith: This database contains all lemmas about Peano’s arithmetic proved in the
- directories Init and Arith.
-
-:zarith: contains lemmas about binary signed integers from the
- directories theories/ZArith. The database also contains
- high-cost hints that call :tacn:`lia` on equations and
- inequalities in ``nat`` or ``Z``.
-
-:bool: contains lemmas about booleans, mostly from directory theories/Bool.
-
-:datatypes: is for lemmas about lists, streams and so on that are mainly proved
- in the Lists subdirectory.
-
-:sets: contains lemmas about sets and relations from the directories Sets and
- Relations.
-
-:typeclass_instances: contains all the typeclass instances declared in the
- environment, including those used for ``setoid_rewrite``,
- from the Classes directory.
-
-:fset: internal database for the implementation of the ``FSets`` library.
-
-:ordered_type: lemmas about ordered types (as defined in the legacy ``OrderedType`` module),
- mainly used in the ``FSets`` and ``FMaps`` libraries.
-
-You are advised not to put your own hints in the core database, but
-use one or several databases specific to your development.
-
-.. _removehints:
-
-.. cmd:: Remove Hints {+ @term} : {+ @ident}
-
- This command removes the hints associated to terms :n:`{+ @term}` in databases
- :n:`{+ @ident}`.
-
-.. _printhint:
-
-.. cmd:: Print Hint
-
- This command displays all hints that apply to the current goal. It
- fails if no proof is being edited, while the two variants can be used
- at every moment.
-
-**Variants:**
-
-
-.. cmd:: Print Hint @ident
-
- This command displays only tactics associated with :n:`@ident` in the hints
- list. This is independent of the goal being edited, so this command will not
- fail if no goal is being edited.
-
-.. cmd:: Print Hint *
-
- This command displays all declared hints.
-
-.. cmd:: Print HintDb @ident
-
- This command displays all hints from database :n:`@ident`.
-
-.. _hintrewrite:
-
-.. cmd:: Hint Rewrite {+ @term} : {+ @ident}
-
- This vernacular command adds the terms :n:`{+ @term}` (their types must be
- equalities) in the rewriting bases :n:`{+ @ident}` with the default orientation
- (left to right). Notice that the rewriting bases are distinct from the :tacn:`auto`
- hint bases and that :tacn:`auto` does not take them into account.
-
- This command is synchronous with the section mechanism (see :ref:`section-mechanism`):
- when closing a section, all aliases created by ``Hint Rewrite`` in that
- section are lost. Conversely, when loading a module, all ``Hint Rewrite``
- declarations at the global level of that module are loaded.
-
-**Variants:**
-
-.. cmd:: Hint Rewrite -> {+ @term} : {+ @ident}
-
- This is strictly equivalent to the command above (we only make explicit the
- orientation which otherwise defaults to ->).
-
-.. cmd:: Hint Rewrite <- {+ @term} : {+ @ident}
-
- Adds the rewriting rules :n:`{+ @term}` with a right-to-left orientation in
- the bases :n:`{+ @ident}`.
-
-.. cmd:: Hint Rewrite {+ @term} using @tactic : {+ @ident}
-
- When the rewriting rules :n:`{+ @term}` in :n:`{+ @ident}` will be used, the
- tactic ``tactic`` will be applied to the generated subgoals, the main subgoal
- excluded.
-
-.. cmd:: Print Rewrite HintDb @ident
-
- This command displays all rewrite hints contained in :n:`@ident`.
-
-Hint locality
-~~~~~~~~~~~~~
-
-Hints provided by the ``Hint`` commands are erased when closing a section.
-Conversely, all hints of a module ``A`` that are not defined inside a
-section (and not defined with option ``Local``) become available when the
-module ``A`` is required (using e.g. ``Require A.``).
-
-As of today, hints only have a binary behavior regarding locality, as
-described above: either they disappear at the end of a section scope,
-or they remain global forever. This causes a scalability issue,
-because hints coming from an unrelated part of the code may badly
-influence another development. It can be mitigated to some extent
-thanks to the :cmd:`Remove Hints` command,
-but this is a mere workaround and has some limitations (for instance, external
-hints cannot be removed).
-
-A proper way to fix this issue is to bind the hints to their module scope, as
-for most of the other objects Coq uses. Hints should only be made available when
-the module they are defined in is imported, not just required. It is very
-difficult to change the historical behavior, as it would break a lot of scripts.
-We propose a smooth transitional path by providing the :opt:`Loose Hint Behavior`
-option which accepts three flags allowing for a fine-grained handling of
-non-imported hints.
-
-.. opt:: Loose Hint Behavior {| "Lax" | "Warn" | "Strict" }
- :name: Loose Hint Behavior
-
- This option accepts three values, which control the behavior of hints w.r.t.
- :cmd:`Import`:
-
- - "Lax": this is the default, and corresponds to the historical behavior,
- that is, hints defined outside of a section have a global scope.
-
- - "Warn": outputs a warning when a non-imported hint is used. Note that this
- is an over-approximation, because a hint may be triggered by a run that
- will eventually fail and backtrack, resulting in the hint not being
- actually useful for the proof.
-
- - "Strict": changes the behavior of an unloaded hint to a immediate fail
- tactic, allowing to emulate an import-scoped hint mechanism.
-
-.. _tactics-implicit-automation:
-
-Setting implicit automation tactics
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-.. cmd:: Proof with @tactic
-
- This command may be used to start a proof. It defines a default tactic
- to be used each time a tactic command ``tactic``:sub:`1` is ended by ``...``.
- In this case the tactic command typed by the user is equivalent to
- ``tactic``:sub:`1` ``;tactic``.
-
- .. seealso:: :cmd:`Proof` in :ref:`proof-editing-mode`.
-
-
- .. cmdv:: Proof with @tactic using {+ @ident}
-
- Combines in a single line ``Proof with`` and ``Proof using``, see :ref:`proof-editing-mode`
-
- .. cmdv:: Proof using {+ @ident} with @tactic
-
- Combines in a single line ``Proof with`` and ``Proof using``, see :ref:`proof-editing-mode`
-
-.. _decisionprocedures:
-
-Decision procedures
--------------------
-
-.. tacn:: tauto
- :name: tauto
-
- This tactic implements a decision procedure for intuitionistic propositional
- calculus based on the contraction-free sequent calculi LJT* of Roy Dyckhoff
- :cite:`Dyc92`. Note that :tacn:`tauto` succeeds on any instance of an
- intuitionistic tautological proposition. :tacn:`tauto` unfolds negations and
- logical equivalence but does not unfold any other definition.
-
-.. example::
-
- The following goal can be proved by :tacn:`tauto` whereas :tacn:`auto` would
- fail:
-
- .. coqtop:: reset all
-
- Goal forall (x:nat) (P:nat -> Prop), x = 0 \/ P x -> x <> 0 -> P x.
- intros.
- tauto.
-
-Moreover, if it has nothing else to do, :tacn:`tauto` performs introductions.
-Therefore, the use of :tacn:`intros` in the previous proof is unnecessary.
-:tacn:`tauto` can for instance for:
-
-.. example::
-
- .. coqtop:: reset all
-
- Goal forall (A:Prop) (P:nat -> Prop), A \/ (forall x:nat, ~ A -> P x) -> forall x:nat, ~ A -> P x.
- tauto.
-
-.. note::
- In contrast, :tacn:`tauto` cannot solve the following goal
- :g:`Goal forall (A:Prop) (P:nat -> Prop), A \/ (forall x:nat, ~ A -> P x) ->`
- :g:`forall x:nat, ~ ~ (A \/ P x).`
- because :g:`(forall x:nat, ~ A -> P x)` cannot be treated as atomic and
- an instantiation of `x` is necessary.
-
-.. tacv:: dtauto
- :name: dtauto
-
- While :tacn:`tauto` recognizes inductively defined connectives isomorphic to
- the standard connectives ``and``, ``prod``, ``or``, ``sum``, ``False``,
- ``Empty_set``, ``unit``, ``True``, :tacn:`dtauto` also recognizes all inductive
- types with one constructor and no indices, i.e. record-style connectives.
-
-.. tacn:: intuition @tactic
- :name: intuition
-
- The tactic :tacn:`intuition` takes advantage of the search-tree built by the
- decision procedure involved in the tactic :tacn:`tauto`. It uses this
- information to generate a set of subgoals equivalent to the original one (but
- simpler than it) and applies the tactic :n:`@tactic` to them :cite:`Mun94`. If
- this tactic fails on some goals then :tacn:`intuition` fails. In fact,
- :tacn:`tauto` is simply :g:`intuition fail`.
-
- .. example::
-
- For instance, the tactic :g:`intuition auto` applied to the goal::
-
- (forall (x:nat), P x) /\ B -> (forall (y:nat), P y) /\ P O \/ B /\ P O
-
- internally replaces it by the equivalent one::
-
- (forall (x:nat), P x), B |- P O
-
- and then uses :tacn:`auto` which completes the proof.
-
-Originally due to César Muñoz, these tactics (:tacn:`tauto` and
-:tacn:`intuition`) have been completely re-engineered by David Delahaye using
-mainly the tactic language (see :ref:`ltac`). The code is
-now much shorter and a significant increase in performance has been noticed.
-The general behavior with respect to dependent types, unfolding and
-introductions has slightly changed to get clearer semantics. This may lead to
-some incompatibilities.
-
-.. tacv:: intuition
-
- Is equivalent to :g:`intuition auto with *`.
-
-.. tacv:: dintuition
- :name: dintuition
-
- While :tacn:`intuition` recognizes inductively defined connectives
- isomorphic to the standard connectives ``and``, ``prod``, ``or``, ``sum``, ``False``,
- ``Empty_set``, ``unit``, ``True``, :tacn:`dintuition` also recognizes all inductive
- types with one constructor and no indices, i.e. record-style connectives.
-
-.. flag:: Intuition Negation Unfolding
-
- Controls whether :tacn:`intuition` unfolds inner negations which do not need
- to be unfolded. This flag is on by default.
-
-.. tacn:: rtauto
- :name: rtauto
-
- The :tacn:`rtauto` tactic solves propositional tautologies similarly to what
- :tacn:`tauto` does. The main difference is that the proof term is built using a
- reflection scheme applied to a sequent calculus proof of the goal. The search
- procedure is also implemented using a different technique.
-
- Users should be aware that this difference may result in faster proof-search
- but slower proof-checking, and :tacn:`rtauto` might not solve goals that
- :tacn:`tauto` would be able to solve (e.g. goals involving universal
- quantifiers).
-
- Note that this tactic is only available after a ``Require Import Rtauto``.
-
-.. tacn:: firstorder
- :name: firstorder
-
- The tactic :tacn:`firstorder` is an experimental extension of :tacn:`tauto` to
- first- order reasoning, written by Pierre Corbineau. It is not restricted to
- usual logical connectives but instead may reason about any first-order class
- inductive definition.
-
-.. opt:: Firstorder Solver @tactic
- :name: Firstorder Solver
-
- The default tactic used by :tacn:`firstorder` when no rule applies is
- :g:`auto with core`, it can be reset locally or globally using this option.
-
- .. cmd:: Print Firstorder Solver
-
- Prints the default tactic used by :tacn:`firstorder` when no rule applies.
-
-.. tacv:: firstorder @tactic
-
- Tries to solve the goal with :n:`@tactic` when no logical rule may apply.
-
-.. tacv:: firstorder using {+ @qualid}
-
- .. deprecated:: 8.3
-
- Use the syntax below instead (with commas).
-
-.. tacv:: firstorder using {+, @qualid}
-
- Adds lemmas :n:`{+, @qualid}` to the proof-search environment. If :n:`@qualid`
- refers to an inductive type, it is the collection of its constructors which are
- added to the proof-search environment.
-
-.. tacv:: firstorder with {+ @ident}
-
- Adds lemmas from :tacn:`auto` hint bases :n:`{+ @ident}` to the proof-search
- environment.
-
-.. tacv:: firstorder @tactic using {+, @qualid} with {+ @ident}
-
- This combines the effects of the different variants of :tacn:`firstorder`.
-
-.. opt:: Firstorder Depth @natural
- :name: Firstorder Depth
-
- This option controls the proof-search depth bound.
-
-.. tacn:: congruence
- :name: congruence
-
- The tactic :tacn:`congruence`, by Pierre Corbineau, implements the standard
- Nelson and Oppen congruence closure algorithm, which is a decision procedure
- for ground equalities with uninterpreted symbols. It also includes
- constructor theory (see :tacn:`injection` and :tacn:`discriminate`). If the goal
- is a non-quantified equality, congruence tries to prove it with non-quantified
- equalities in the context. Otherwise it tries to infer a discriminable equality
- from those in the context. Alternatively, congruence tries to prove that a
- hypothesis is equal to the goal or to the negation of another hypothesis.
-
- :tacn:`congruence` is also able to take advantage of hypotheses stating
- quantified equalities, but you have to provide a bound for the number of extra
- equalities generated that way. Please note that one of the sides of the
- equality must contain all the quantified variables in order for congruence to
- match against it.
-
-.. example::
-
- .. coqtop:: reset all
-
- Theorem T (A:Type) (f:A -> A) (g: A -> A -> A) a b: a=(f a) -> (g b (f a))=(f (f a)) -> (g a b)=(f (g b a)) -> (g a b)=a.
- intros.
- congruence.
- Qed.
-
- Theorem inj (A:Type) (f:A -> A * A) (a c d: A) : f = pair a -> Some (f c) = Some (f d) -> c=d.
- intros.
- congruence.
- Qed.
-
-.. tacv:: congruence @natural
-
- Tries to add at most :token:`natural` instances of hypotheses stating quantified equalities
- to the problem in order to solve it. A bigger value of :token:`natural` does not make
- success slower, only failure. You might consider adding some lemmas as
- hypotheses using assert in order for :tacn:`congruence` to use them.
-
-.. tacv:: congruence with {+ @term}
- :name: congruence with
-
- Adds :n:`{+ @term}` to the pool of terms used by :tacn:`congruence`. This helps
- in case you have partially applied constructors in your goal.
-
-.. exn:: I don’t know how to handle dependent equality.
-
- The decision procedure managed to find a proof of the goal or of a
- discriminable equality but this proof could not be built in Coq because of
- dependently-typed functions.
-
-.. exn:: Goal is solvable by congruence but some arguments are missing. Try congruence with {+ @term}, replacing metavariables by arbitrary terms.
-
- The decision procedure could solve the goal with the provision that additional
- arguments are supplied for some partially applied constructors. Any term of an
- appropriate type will allow the tactic to successfully solve the goal. Those
- additional arguments can be given to congruence by filling in the holes in the
- terms given in the error message, using the :tacn:`congruence with` variant described above.
-
-.. flag:: Congruence Verbose
-
- This flag makes :tacn:`congruence` print debug information.
-
Checking properties of terms
----------------------------
@@ -4600,13 +2840,13 @@ symbol :g:`=`.
:n:`simplify_eq @ident` where :n:`@ident` is the identifier for the last
introduced hypothesis.
-.. tacv:: simplify_eq @term with @bindings_list
+.. tacv:: simplify_eq @term with @bindings
This does the same as :n:`simplify_eq @term` but using the given bindings to
instantiate parameters or hypotheses of :n:`@term`.
.. tacv:: esimplify_eq @natural
- esimplify_eq @term {? with @bindings_list}
+ esimplify_eq @term {? with @bindings}
:name: esimplify_eq; _
This works the same as :tacn:`simplify_eq` but if the type of :n:`@term`, or the
@@ -4653,189 +2893,6 @@ using the ``Require Import`` command.
Use :tacn:`classical_right` to prove the right part of the disjunction with
the assumption that the negation of left part holds.
-.. _tactics-automating:
-
-Automating
-------------
-
-
-.. tacn:: btauto
- :name: btauto
-
- The tactic :tacn:`btauto` implements a reflexive solver for boolean
- tautologies. It solves goals of the form :g:`t = u` where `t` and `u` are
- constructed over the following grammar:
-
- .. prodn::
- btauto_term ::= @ident
- | true
- | false
- | orb @btauto_term @btauto_term
- | andb @btauto_term @btauto_term
- | xorb @btauto_term @btauto_term
- | negb @btauto_term
- | if @btauto_term then @btauto_term else @btauto_term
-
- Whenever the formula supplied is not a tautology, it also provides a
- counter-example.
-
- Internally, it uses a system very similar to the one of the ring
- tactic.
-
- Note that this tactic is only available after a ``Require Import Btauto``.
-
- .. exn:: Cannot recognize a boolean equality.
-
- The goal is not of the form :g:`t = u`. Especially note that :tacn:`btauto`
- doesn't introduce variables into the context on its own.
-
-.. tacv:: field
- field_simplify {* @term}
- field_simplify_eq
-
- The field tactic is built on the same ideas as ring: this is a
- reflexive tactic that solves or simplifies equations in a field
- structure. The main idea is to reduce a field expression (which is an
- extension of ring expressions with the inverse and division
- operations) to a fraction made of two polynomial expressions.
-
- Tactic :n:`field` is used to solve subgoals, whereas :n:`field_simplify {+ @term}`
- replaces the provided terms by their reduced fraction.
- :n:`field_simplify_eq` applies when the conclusion is an equation: it
- simplifies both hand sides and multiplies so as to cancel
- denominators. So it produces an equation without division nor inverse.
-
- All of these 3 tactics may generate a subgoal in order to prove that
- denominators are different from zero.
-
- See :ref:`Theringandfieldtacticfamilies` for more information on the tactic and how to
- declare new field structures. All declared field structures can be
- printed with the Print Fields command.
-
-.. example::
-
- .. coqtop:: reset all
-
- Require Import Reals.
- Goal forall x y:R,
- (x * y > 0)%R ->
- (x * (1 / x + x / (x + y)))%R =
- ((- 1 / y) * y * (- x * (x / (x + y)) - 1))%R.
-
- intros; field.
-
-.. seealso::
-
- File plugins/ring/RealField.v for an example of instantiation,
- theory theories/Reals for many examples of use of field.
-
-Non-logical tactics
-------------------------
-
-
-.. tacn:: cycle @integer
- :name: cycle
-
- Reorders the selected goals so that the first :n:`@integer` goals appear after the
- other selected goals.
- If :n:`@integer` is negative, it puts the last :n:`@integer` goals at the
- beginning of the list.
- The tactic is only useful with a goal selector, most commonly `all:`.
- Note that other selectors reorder goals; `1,3: cycle 1` is not equivalent
- to `all: cycle 1`. See :tacn:`… : … (goal selector)`.
-
-.. example::
-
- .. coqtop:: none reset
-
- Parameter P : nat -> Prop.
-
- .. coqtop:: all abort
-
- Goal P 1 /\ P 2 /\ P 3 /\ P 4 /\ P 5.
- repeat split.
- all: cycle 2.
- all: cycle -3.
-
-.. tacn:: swap @integer @integer
- :name: swap
-
- Exchanges the position of the specified goals.
- Negative values for :n:`@integer` indicate counting goals
- backward from the end of the list of selected goals. Goals are indexed from 1.
- The tactic is only useful with a goal selector, most commonly `all:`.
- Note that other selectors reorder goals; `1,3: swap 1 3` is not equivalent
- to `all: swap 1 3`. See :tacn:`… : … (goal selector)`.
-
-.. example::
-
- .. coqtop:: all abort
-
- Goal P 1 /\ P 2 /\ P 3 /\ P 4 /\ P 5.
- repeat split.
- all: swap 1 3.
- all: swap 1 -1.
-
-.. tacn:: revgoals
- :name: revgoals
-
- Reverses the order of the selected goals. The tactic is only useful with a goal
- selector, most commonly `all :`. Note that other selectors reorder goals;
- `1,3: revgoals` is not equivalent to `all: revgoals`. See :tacn:`… : … (goal selector)`.
-
- .. example::
-
- .. coqtop:: all abort
-
- Goal P 1 /\ P 2 /\ P 3 /\ P 4 /\ P 5.
- repeat split.
- all: revgoals.
-
-.. tacn:: shelve
- :name: shelve
-
- This tactic moves all goals under focus to a shelf. While on the
- shelf, goals will not be focused on. They can be solved by
- unification, or they can be called back into focus with the command
- :cmd:`Unshelve`.
-
- .. tacv:: shelve_unifiable
- :name: shelve_unifiable
-
- Shelves only the goals under focus that are mentioned in other goals.
- Goals that appear in the type of other goals can be solved by unification.
-
- .. example::
-
- .. coqtop:: all abort
-
- Goal exists n, n=0.
- refine (ex_intro _ _ _).
- all: shelve_unifiable.
- reflexivity.
-
-.. cmd:: Unshelve
-
- This command moves all the goals on the shelf (see :tacn:`shelve`)
- from the shelf into focus, by appending them to the end of the current
- list of focused goals.
-
-.. tacn:: unshelve @tactic
- :name: unshelve
-
- Performs :n:`@tactic`, then unshelves existential variables added to the
- shelf by the execution of :n:`@tactic`, prepending them to the current goal.
-
-.. tacn:: give_up
- :name: give_up
-
- This tactic removes the focused goals from the proof. They are not
- solved, and cannot be solved later in the proof. As the goals are not
- solved, the proof cannot be closed.
-
- The ``give_up`` tactic can be used while editing a proof, to choose to
- write the proof script in a non-sequential order.
-
Delaying solving unification constraints
----------------------------------------
@@ -4855,14 +2912,14 @@ Proof maintenance
*Experimental.* Many tactics, such as :tacn:`intros`, can automatically generate names, such
as "H0" or "H1" for a new hypothesis introduced from a goal. Subsequent proof steps
-may explicitly refer to these names. However, future versions of Coq may not assign
+may explicitly refer to these names. However, future versions of |Coq| may not assign
names exactly the same way, which could cause the proof to fail because the
new names don't match the explicit references in the proof.
The following "Mangle Names" settings let users find all the
places where proofs rely on automatically generated names, which can
then be named explicitly to avoid any incompatibility. These
-settings cause Coq to generate different names, producing errors for
+settings cause |Coq| to generate different names, producing errors for
references to automatically generated names.
.. flag:: Mangle Names
@@ -4884,7 +2941,7 @@ Performance-oriented tactic variants
For advanced usage. Similar to :tacn:`change` :n:`@term`, but as an optimization,
it skips checking that :n:`@term` is convertible to the goal.
- Recall that the Coq kernel typechecks proofs again when they are concluded to
+ Recall that the |Coq| kernel typechecks proofs again when they are concluded to
ensure safety. Hence, using :tacn:`change` checks convertibility twice
overall, while :tacn:`change_no_check` can produce ill-typed terms,
but checks convertibility only once.
diff --git a/doc/sphinx/proof-engine/vernacular-commands.rst b/doc/sphinx/proof-engine/vernacular-commands.rst
index 6c07253bce..dd0b12f8ec 100644
--- a/doc/sphinx/proof-engine/vernacular-commands.rst
+++ b/doc/sphinx/proof-engine/vernacular-commands.rst
@@ -637,10 +637,10 @@ file is a particular case of a module called a *library file*.
.. cmd:: Declare ML Module {+ @string }
- This commands dynamically loads OCaml compiled code from
+ This commands dynamically loads |OCaml| compiled code from
a :n:`.mllib` file.
It is used to load plugins dynamically. The
- files must be accessible in the current OCaml loadpath (see the
+ files must be accessible in the current |OCaml| loadpath (see the
command :cmd:`Add ML Path`). The :n:`.mllib` suffix may be omitted.
This command is reserved for plugin developers, who should provide
@@ -656,7 +656,7 @@ file is a particular case of a module called a *library file*.
.. cmd:: Print ML Modules
- This prints the name of all OCaml modules loaded with :cmd:`Declare ML Module`.
+ This prints the name of all |OCaml| modules loaded with :cmd:`Declare ML Module`.
To know from where these module were loaded, the user
should use the command :cmd:`Locate File`.
@@ -719,13 +719,13 @@ the toplevel, and using them in source files is discouraged.
.. cmd:: Add ML Path @string
- This command adds the path :n:`@string` to the current OCaml
+ This command adds the path :n:`@string` to the current |OCaml|
loadpath (cf. :cmd:`Declare ML Module`).
.. cmd:: Print ML Path
- This command displays the current OCaml loadpath. This
+ This command displays the current |OCaml| loadpath. This
command makes sense only under the bytecode version of ``coqtop``, i.e.
using option ``-byte``
(cf. :cmd:`Declare ML Module`).
@@ -794,10 +794,10 @@ Quitting and debugging
.. cmd:: Drop
- This command temporarily enters the OCaml toplevel.
+ This command temporarily enters the |OCaml| toplevel.
It is a debug facility used by |Coq|’s implementers. Valid only in the
bytecode version of coqtop.
- The OCaml command:
+ The |OCaml| command:
::
@@ -980,7 +980,7 @@ described first.
This command has an effect on unfoldable constants, i.e. on constants
defined by :cmd:`Definition` or :cmd:`Let` (with an explicit body), or by a command
- assimilated to a definition such as :cmd:`Fixpoint`, :cmd:`Program Definition`, etc,
+ associated with a definition such as :cmd:`Fixpoint`, etc,
or by a proof ended by :cmd:`Defined`. The command tells not to unfold the
constants in the :n:`@reference` sequence in tactics using δ-conversion (unfolding
a constant is replacing it by its definition).
@@ -990,11 +990,6 @@ described first.
has to check the conversion (see Section :ref:`conversion-rules`) of two distinct
applied constants.
- .. seealso::
-
- Sections :ref:`performingcomputations`, :ref:`tactics-automating`,
- :ref:`proof-editing-mode`
-
.. cmd:: Transparent {+ @reference }
This command accepts the :attr:`global` attribute. By default, the scope
@@ -1015,10 +1010,7 @@ described first.
There is no constant named :n:`@qualid` in the environment.
- .. seealso::
-
- Sections :ref:`performingcomputations`,
- :ref:`tactics-automating`, :ref:`proof-editing-mode`
+.. seealso:: :ref:`performingcomputations` and :ref:`proof-editing-mode`
.. _vernac-strategy:
@@ -1230,15 +1222,15 @@ in support libraries of plug-ins.
.. _exposing-constants-to-ocaml-libraries:
-Exposing constants to OCaml libraries
-`````````````````````````````````````
+Exposing constants to |OCaml| libraries
+```````````````````````````````````````
.. cmd:: Register @qualid__1 as @qualid__2
- Makes the constant :n:`@qualid__1` accessible to OCaml libraries under
+ Makes the constant :n:`@qualid__1` accessible to |OCaml| libraries under
the name :n:`@qualid__2`. The constant can then be dynamically located
- in OCaml code by
- calling :n:`Coqlib.lib_ref "@qualid__2"`. The OCaml code doesn't need
+ in |OCaml| code by
+ calling :n:`Coqlib.lib_ref "@qualid__2"`. The |OCaml| code doesn't need
to know where the constant is defined (what file, module, library, etc.).
As a special case, when the first segment of :n:`@qualid__2` is :g:`kernel`,
@@ -1267,7 +1259,7 @@ Registering primitive operations
.. cmd:: Primitive @ident_decl {? : @term } := #@ident
- Makes the primitive type or primitive operator :n:`#@ident` defined in OCaml
+ Makes the primitive type or primitive operator :n:`#@ident` defined in |OCaml|
accessible in |Coq| commands and tactics.
For internal use by implementors of |Coq|'s standard library or standard library
replacements. No space is allowed after the `#`. Invalid values give a syntax
diff --git a/doc/sphinx/proofs/automatic-tactics/auto.rst b/doc/sphinx/proofs/automatic-tactics/auto.rst
new file mode 100644
index 0000000000..cc8af976d2
--- /dev/null
+++ b/doc/sphinx/proofs/automatic-tactics/auto.rst
@@ -0,0 +1,672 @@
+.. _automation:
+
+=========================
+Programmable proof search
+=========================
+
+.. tacn:: auto
+ :name: auto
+
+ This tactic implements a Prolog-like resolution procedure to solve the
+ current goal. It first tries to solve the goal using the :tacn:`assumption`
+ tactic, then it reduces the goal to an atomic one using :tacn:`intros` and
+ introduces the newly generated hypotheses as hints. Then it looks at
+ the list of tactics associated to the head symbol of the goal and
+ tries to apply one of them (starting from the tactics with lower
+ cost). This process is recursively applied to the generated subgoals.
+
+ By default, :tacn:`auto` only uses the hypotheses of the current goal and
+ the hints of the database named ``core``.
+
+ .. warning::
+
+ :tacn:`auto` uses a weaker version of :tacn:`apply` that is closer to
+ :tacn:`simple apply` so it is expected that sometimes :tacn:`auto` will
+ fail even if applying manually one of the hints would succeed.
+
+ .. tacv:: auto @natural
+
+ Forces the search depth to be :token:`natural`. The maximal search depth
+ is 5 by default.
+
+ .. tacv:: auto with {+ @ident}
+
+ Uses the hint databases :n:`{+ @ident}` in addition to the database ``core``.
+
+ .. note::
+
+ Use the fake database `nocore` if you want to *not* use the `core`
+ database.
+
+ .. tacv:: auto with *
+
+ Uses all existing hint databases. Using this variant is highly discouraged
+ in finished scripts since it is both slower and less robust than the variant
+ where the required databases are explicitly listed.
+
+ .. seealso::
+ :ref:`The Hints Databases for auto and eauto <thehintsdatabasesforautoandeauto>` for the list of
+ pre-defined databases and the way to create or extend a database.
+
+ .. tacv:: auto using {+ @qualid__i} {? with {+ @ident } }
+
+ Uses lemmas :n:`@qualid__i` in addition to hints. If :n:`@qualid` is an
+ inductive type, it is the collection of its constructors which are added
+ as hints.
+
+ .. note::
+
+ The hints passed through the `using` clause are used in the same
+ way as if they were passed through a hint database. Consequently,
+ they use a weaker version of :tacn:`apply` and :n:`auto using @qualid`
+ may fail where :n:`apply @qualid` succeeds.
+
+ Given that this can be seen as counter-intuitive, it could be useful
+ to have an option to use full-blown :tacn:`apply` for lemmas passed
+ through the `using` clause. Contributions welcome!
+
+ .. tacv:: info_auto
+
+ Behaves like :tacn:`auto` but shows the tactics it uses to solve the goal. This
+ variant is very useful for getting a better understanding of automation, or
+ to know what lemmas/assumptions were used.
+
+ .. tacv:: debug auto
+ :name: debug auto
+
+ Behaves like :tacn:`auto` but shows the tactics it tries to solve the goal,
+ including failing paths.
+
+ .. tacv:: {? info_}auto {? @natural} {? using {+ @qualid}} {? with {+ @ident}}
+
+ This is the most general form, combining the various options.
+
+.. tacv:: trivial
+ :name: trivial
+
+ This tactic is a restriction of :tacn:`auto` that is not recursive
+ and tries only hints that cost `0`. Typically it solves trivial
+ equalities like :g:`X=X`.
+
+ .. tacv:: trivial with {+ @ident}
+ trivial with *
+ trivial using {+ @qualid}
+ debug trivial
+ info_trivial
+ {? info_}trivial {? using {+ @qualid}} {? with {+ @ident}}
+ :name: _; _; _; debug trivial; info_trivial; _
+ :undocumented:
+
+.. note::
+ :tacn:`auto` and :tacn:`trivial` either solve completely the goal or
+ else succeed without changing the goal. Use :g:`solve [ auto ]` and
+ :g:`solve [ trivial ]` if you would prefer these tactics to fail when
+ they do not manage to solve the goal.
+
+.. flag:: Info Auto
+ Debug Auto
+ Info Trivial
+ Debug Trivial
+
+ These flags enable printing of informative or debug information for
+ the :tacn:`auto` and :tacn:`trivial` tactics.
+
+.. tacn:: eauto
+ :name: eauto
+
+ This tactic generalizes :tacn:`auto`. While :tacn:`auto` does not try
+ resolution hints which would leave existential variables in the goal,
+ :tacn:`eauto` does try them (informally speaking, it internally uses a tactic
+ close to :tacn:`simple eapply` instead of a tactic close to :tacn:`simple apply`
+ in the case of :tacn:`auto`). As a consequence, :tacn:`eauto`
+ can solve such a goal:
+
+ .. example::
+
+ .. coqtop:: all
+
+ Hint Resolve ex_intro : core.
+ Goal forall P:nat -> Prop, P 0 -> exists n, P n.
+ eauto.
+
+ Note that ``ex_intro`` should be declared as a hint.
+
+
+ .. tacv:: {? info_}eauto {? @natural} {? using {+ @qualid}} {? with {+ @ident}}
+
+ The various options for :tacn:`eauto` are the same as for :tacn:`auto`.
+
+ :tacn:`eauto` also obeys the following flags:
+
+ .. flag:: Info Eauto
+ Debug Eauto
+ :undocumented:
+
+ .. seealso:: :ref:`The Hints Databases for auto and eauto <thehintsdatabasesforautoandeauto>`
+
+
+.. tacn:: autounfold with {+ @ident}
+ :name: autounfold
+
+ This tactic unfolds constants that were declared through a :cmd:`Hint Unfold`
+ in the given databases.
+
+.. tacv:: autounfold with {+ @ident} in @goal_occurrences
+
+ Performs the unfolding in the given clause (:token:`goal_occurrences`).
+
+.. tacv:: autounfold with *
+
+ Uses the unfold hints declared in all the hint databases.
+
+.. tacn:: autorewrite with {+ @ident}
+ :name: autorewrite
+
+ This tactic carries out rewritings according to the rewriting rule
+ bases :n:`{+ @ident}`.
+
+ Each rewriting rule from the base :n:`@ident` is applied to the main subgoal until
+ it fails. Once all the rules have been processed, if the main subgoal has
+ progressed (e.g., if it is distinct from the initial main goal) then the rules
+ of this base are processed again. If the main subgoal has not progressed then
+ the next base is processed. For the bases, the behavior is exactly similar to
+ the processing of the rewriting rules.
+
+ The rewriting rule bases are built with the :cmd:`Hint Rewrite`
+ command.
+
+.. warning::
+
+ This tactic may loop if you build non terminating rewriting systems.
+
+.. tacv:: autorewrite with {+ @ident} using @tactic
+
+ Performs, in the same way, all the rewritings of the bases :n:`{+ @ident}`
+ applying tactic to the main subgoal after each rewriting step.
+
+.. tacv:: autorewrite with {+ @ident} in @qualid
+
+ Performs all the rewritings in hypothesis :n:`@qualid`.
+
+.. tacv:: autorewrite with {+ @ident} in @qualid using @tactic
+
+ Performs all the rewritings in hypothesis :n:`@qualid` applying :n:`@tactic`
+ to the main subgoal after each rewriting step.
+
+.. tacv:: autorewrite with {+ @ident} in @goal_occurrences
+
+ Performs all the rewriting in the clause :n:`@goal_occurrences`.
+
+.. seealso::
+
+ :ref:`Hint-Rewrite <hintrewrite>` for feeding the database of lemmas used by
+ :tacn:`autorewrite` and :tacn:`autorewrite` for examples showing the use of this tactic.
+
+.. tacn:: easy
+ :name: easy
+
+ This tactic tries to solve the current goal by a number of standard closing steps.
+ In particular, it tries to close the current goal using the closing tactics
+ :tacn:`trivial`, :tacn:`reflexivity`, :tacn:`symmetry`, :tacn:`contradiction`
+ and :tacn:`inversion` of hypothesis.
+ If this fails, it tries introducing variables and splitting and-hypotheses,
+ using the closing tactics afterwards, and splitting the goal using
+ :tacn:`split` and recursing.
+
+ This tactic solves goals that belong to many common classes; in particular, many cases of
+ unsatisfiable hypotheses, and simple equality goals are usually solved by this tactic.
+
+.. tacv:: now @tactic
+ :name: now
+
+ Run :n:`@tactic` followed by :tacn:`easy`. This is a notation for :n:`@tactic; easy`.
+
+Controlling automation
+--------------------------
+
+.. _thehintsdatabasesforautoandeauto:
+
+The hints databases for auto and eauto
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The hints for :tacn:`auto` and :tacn:`eauto` are stored in databases. Each database
+maps head symbols to a list of hints.
+
+.. cmd:: Print Hint @ident
+
+ Use this command
+ to display the hints associated to the head symbol :n:`@ident`
+ (see :ref:`Print Hint <printhint>`). Each hint has a cost that is a nonnegative
+ integer, and an optional pattern. The hints with lower cost are tried first. A
+ hint is tried by :tacn:`auto` when the conclusion of the current goal matches its
+ pattern or when it has no pattern.
+
+Creating Hint databases
+```````````````````````
+
+One can optionally declare a hint database using the command
+:cmd:`Create HintDb`. If a hint is added to an unknown database, it will be
+automatically created.
+
+.. cmd:: Create HintDb @ident {? discriminated}
+
+ This command creates a new database named :n:`@ident`. The database is
+ implemented by a Discrimination Tree (DT) that serves as an index of
+ all the lemmas. The DT can use transparency information to decide if a
+ constant should be indexed or not
+ (c.f. :ref:`The hints databases for auto and eauto <thehintsdatabasesforautoandeauto>`),
+ making the retrieval more efficient. The legacy implementation (the default one
+ for new databases) uses the DT only on goals without existentials (i.e., :tacn:`auto`
+ goals), for non-Immediate hints and does not make use of transparency
+ hints, putting more work on the unification that is run after
+ retrieval (it keeps a list of the lemmas in case the DT is not used).
+ The new implementation enabled by the discriminated option makes use
+ of DTs in all cases and takes transparency information into account.
+ However, the order in which hints are retrieved from the DT may differ
+ from the order in which they were inserted, making this implementation
+ observationally different from the legacy one.
+
+.. cmd:: Hint @hint_definition : {+ @ident}
+
+ The general command to add a hint to some databases :n:`{+ @ident}`.
+
+ This command supports the :attr:`local`, :attr:`global` and :attr:`export`
+ locality attributes. When no locality is explictly given, the
+ command is :attr:`local` inside a section and :attr:`global` otherwise.
+
+ + :attr:`local` hints are never visible from other modules, even if they
+ require or import the current module. Inside a section, the :attr:`local`
+ attribute is useless since hints do not survive anyway to the closure of
+ sections.
+
+ + :attr:`export` are visible from other modules when they import the current
+ module. Requiring it is not enough. This attribute is only effective for
+ the :cmd:`Hint Resolve`, :cmd:`Hint Immediate`, :cmd:`Hint Unfold` and
+ :cmd:`Hint Extern` variants of the command.
+
+ + :attr:`global` hints are made available by merely requiring the current
+ module.
+
+ The various possible :production:`hint_definition`\s are given below.
+
+ .. cmdv:: Hint @hint_definition
+
+ No database name is given: the hint is registered in the ``core`` database.
+
+ .. deprecated:: 8.10
+
+ .. cmdv:: Hint Resolve @qualid {? | {? @natural} {? @pattern}} : @ident
+ :name: Hint Resolve
+
+ This command adds :n:`simple apply @qualid` to the hint list with the head
+ symbol of the type of :n:`@qualid`. The cost of that hint is the number of
+ subgoals generated by :n:`simple apply @qualid` or :n:`@natural` if specified. The
+ associated :n:`@pattern` is inferred from the conclusion of the type of
+ :n:`@qualid` or the given :n:`@pattern` if specified. In case the inferred type
+ of :n:`@qualid` does not start with a product the tactic added in the hint list
+ is :n:`exact @qualid`. In case this type can however be reduced to a type
+ starting with a product, the tactic :n:`simple apply @qualid` is also stored in
+ the hints list. If the inferred type of :n:`@qualid` contains a dependent
+ quantification on a variable which occurs only in the premisses of the type
+ and not in its conclusion, no instance could be inferred for the variable by
+ unification with the goal. In this case, the hint is added to the hint list
+ of :tacn:`eauto` instead of the hint list of auto and a warning is printed. A
+ typical example of a hint that is used only by :tacn:`eauto` is a transitivity
+ lemma.
+
+ .. exn:: @qualid cannot be used as a hint
+
+ The head symbol of the type of :n:`@qualid` is a bound variable
+ such that this tactic cannot be associated to a constant.
+
+ .. cmdv:: Hint Resolve {+ @qualid} : @ident
+
+ Adds each :n:`Hint Resolve @qualid`.
+
+ .. cmdv:: Hint Resolve -> @qualid : @ident
+
+ Adds the left-to-right implication of an equivalence as a hint (informally
+ the hint will be used as :n:`apply <- @qualid`, although as mentioned
+ before, the tactic actually used is a restricted version of
+ :tacn:`apply`).
+
+ .. cmdv:: Hint Resolve <- @qualid
+
+ Adds the right-to-left implication of an equivalence as a hint.
+
+ .. cmdv:: Hint Immediate @qualid : @ident
+ :name: Hint Immediate
+
+ This command adds :n:`simple apply @qualid; trivial` to the hint list associated
+ with the head symbol of the type of :n:`@ident` in the given database. This
+ tactic will fail if all the subgoals generated by :n:`simple apply @qualid` are
+ not solved immediately by the :tacn:`trivial` tactic (which only tries tactics
+ with cost 0).This command is useful for theorems such as the symmetry of
+ equality or :g:`n+1=m+1 -> n=m` that we may like to introduce with a limited
+ use in order to avoid useless proof-search. The cost of this tactic (which
+ never generates subgoals) is always 1, so that it is not used by :tacn:`trivial`
+ itself.
+
+ .. exn:: @qualid cannot be used as a hint
+ :undocumented:
+
+ .. cmdv:: Hint Immediate {+ @qualid} : @ident
+
+ Adds each :n:`Hint Immediate @qualid`.
+
+ .. cmdv:: Hint Constructors @qualid : @ident
+ :name: Hint Constructors
+
+ If :token:`qualid` is an inductive type, this command adds all its constructors as
+ hints of type ``Resolve``. Then, when the conclusion of current goal has the form
+ :n:`(@qualid ...)`, :tacn:`auto` will try to apply each constructor.
+
+ .. exn:: @qualid is not an inductive type
+ :undocumented:
+
+ .. cmdv:: Hint Constructors {+ @qualid} : @ident
+
+ Extends the previous command for several inductive types.
+
+ .. cmdv:: Hint Unfold @qualid : @ident
+ :name: Hint Unfold
+
+ This adds the tactic :n:`unfold @qualid` to the hint list that will only be
+ used when the head constant of the goal is :token:`qualid`.
+ Its cost is 4.
+
+ .. cmdv:: Hint Unfold {+ @qualid}
+
+ Extends the previous command for several defined constants.
+
+ .. cmdv:: Hint Transparent {+ @qualid} : @ident
+ Hint Opaque {+ @qualid} : @ident
+ :name: Hint Transparent; Hint Opaque
+
+ This adds transparency hints to the database, making :n:`@qualid`
+ transparent or opaque constants during resolution. This information is used
+ during unification of the goal with any lemma in the database and inside the
+ discrimination network to relax or constrain it in the case of discriminated
+ databases.
+
+ .. cmdv:: Hint Variables {| Transparent | Opaque } : @ident
+ Hint Constants {| Transparent | Opaque } : @ident
+ :name: Hint Variables; Hint Constants
+
+ This sets the transparency flag used during unification of
+ hints in the database for all constants or all variables,
+ overwriting the existing settings of opacity. It is advised
+ to use this just after a :cmd:`Create HintDb` command.
+
+ .. cmdv:: Hint Extern @natural {? @pattern} => @tactic : @ident
+ :name: Hint Extern
+
+ This hint type is to extend :tacn:`auto` with tactics other than :tacn:`apply` and
+ :tacn:`unfold`. For that, we must specify a cost, an optional :n:`@pattern` and a
+ :n:`@tactic` to execute.
+
+ .. example::
+
+ .. coqtop:: in
+
+ Hint Extern 4 (~(_ = _)) => discriminate : core.
+
+ Now, when the head of the goal is a disequality, ``auto`` will try
+ discriminate if it does not manage to solve the goal with hints with a
+ cost less than 4.
+
+ One can even use some sub-patterns of the pattern in
+ the tactic script. A sub-pattern is a question mark followed by an
+ identifier, like ``?X1`` or ``?X2``. Here is an example:
+
+ .. example::
+
+ .. coqtop:: reset all
+
+ Require Import List.
+ Hint Extern 5 ({?X1 = ?X2} + {?X1 <> ?X2}) => generalize X1, X2; decide equality : eqdec.
+ Goal forall a b:list (nat * nat), {a = b} + {a <> b}.
+ Info 1 auto with eqdec.
+
+ .. cmdv:: Hint Cut @regexp : @ident
+ :name: Hint Cut
+
+ .. warning::
+
+ These hints currently only apply to typeclass proof search and the
+ :tacn:`typeclasses eauto` tactic.
+
+ This command can be used to cut the proof-search tree according to a regular
+ expression matching paths to be cut. The grammar for regular expressions is
+ the following. Beware, there is no operator precedence during parsing, one can
+ check with :cmd:`Print HintDb` to verify the current cut expression:
+
+ .. prodn::
+ regexp ::= @ident (hint or instance identifier)
+ | _ (any hint)
+ | @regexp | @regexp (disjunction)
+ | @regexp @regexp (sequence)
+ | @regexp * (Kleene star)
+ | emp (empty)
+ | eps (epsilon)
+ | ( @regexp )
+
+ The `emp` regexp does not match any search path while `eps`
+ matches the empty path. During proof search, the path of
+ successive successful hints on a search branch is recorded, as a
+ list of identifiers for the hints (note that :cmd:`Hint Extern`\’s do not have
+ an associated identifier).
+ Before applying any hint :n:`@ident` the current path `p` extended with
+ :n:`@ident` is matched against the current cut expression `c` associated to
+ the hint database. If matching succeeds, the hint is *not* applied. The
+ semantics of :n:`Hint Cut @regexp` is to set the cut expression
+ to :n:`c | regexp`, the initial cut expression being `emp`.
+
+ .. cmdv:: Hint Mode @qualid {* {| + | ! | - } } : @ident
+ :name: Hint Mode
+
+ This sets an optional mode of use of the identifier :n:`@qualid`. When
+ proof-search faces a goal that ends in an application of :n:`@qualid` to
+ arguments :n:`@term ... @term`, the mode tells if the hints associated to
+ :n:`@qualid` can be applied or not. A mode specification is a list of n ``+``,
+ ``!`` or ``-`` items that specify if an argument of the identifier is to be
+ treated as an input (``+``), if its head only is an input (``!``) or an output
+ (``-``) of the identifier. For a mode to match a list of arguments, input
+ terms and input heads *must not* contain existential variables or be
+ existential variables respectively, while outputs can be any term. Multiple
+ modes can be declared for a single identifier, in that case only one mode
+ needs to match the arguments for the hints to be applied. The head of a term
+ is understood here as the applicative head, or the match or projection
+ scrutinee’s head, recursively, casts being ignored. :cmd:`Hint Mode` is
+ especially useful for typeclasses, when one does not want to support default
+ instances and avoid ambiguity in general. Setting a parameter of a class as an
+ input forces proof-search to be driven by that index of the class, with ``!``
+ giving more flexibility by allowing existentials to still appear deeper in the
+ index but not at its head.
+
+ .. note::
+
+ + One can use a :cmd:`Hint Extern` with no pattern to do
+ pattern matching on hypotheses using ``match goal with``
+ inside the tactic.
+
+ + If you want to add hints such as :cmd:`Hint Transparent`,
+ :cmd:`Hint Cut`, or :cmd:`Hint Mode`, for typeclass
+ resolution, do not forget to put them in the
+ ``typeclass_instances`` hint database.
+
+
+Hint databases defined in the |Coq| standard library
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Several hint databases are defined in the |Coq| standard library. The
+actual content of a database is the collection of hints declared
+to belong to this database in each of the various modules currently
+loaded. Especially, requiring new modules may extend the database.
+At |Coq| startup, only the core database is nonempty and can be used.
+
+:core: This special database is automatically used by ``auto``, except when
+ pseudo-database ``nocore`` is given to ``auto``. The core database
+ contains only basic lemmas about negation, conjunction, and so on.
+ Most of the hints in this database come from the Init and Logic directories.
+
+:arith: This database contains all lemmas about Peano’s arithmetic proved in the
+ directories Init and Arith.
+
+:zarith: contains lemmas about binary signed integers from the
+ directories theories/ZArith. The database also contains
+ high-cost hints that call :tacn:`lia` on equations and
+ inequalities in ``nat`` or ``Z``.
+
+:bool: contains lemmas about booleans, mostly from directory theories/Bool.
+
+:datatypes: is for lemmas about lists, streams and so on that are mainly proved
+ in the Lists subdirectory.
+
+:sets: contains lemmas about sets and relations from the directories Sets and
+ Relations.
+
+:typeclass_instances: contains all the typeclass instances declared in the
+ environment, including those used for ``setoid_rewrite``,
+ from the Classes directory.
+
+:fset: internal database for the implementation of the ``FSets`` library.
+
+:ordered_type: lemmas about ordered types (as defined in the legacy ``OrderedType`` module),
+ mainly used in the ``FSets`` and ``FMaps`` libraries.
+
+You are advised not to put your own hints in the core database, but
+use one or several databases specific to your development.
+
+.. _removehints:
+
+.. cmd:: Remove Hints {+ @term} : {+ @ident}
+
+ This command removes the hints associated to terms :n:`{+ @term}` in databases
+ :n:`{+ @ident}`.
+
+.. _printhint:
+
+.. cmd:: Print Hint
+
+ This command displays all hints that apply to the current goal. It
+ fails if no proof is being edited, while the two variants can be used
+ at every moment.
+
+**Variants:**
+
+
+.. cmd:: Print Hint @ident
+
+ This command displays only tactics associated with :n:`@ident` in the hints
+ list. This is independent of the goal being edited, so this command will not
+ fail if no goal is being edited.
+
+.. cmd:: Print Hint *
+
+ This command displays all declared hints.
+
+.. cmd:: Print HintDb @ident
+
+ This command displays all hints from database :n:`@ident`.
+
+.. _hintrewrite:
+
+.. cmd:: Hint Rewrite {+ @term} : {+ @ident}
+
+ This vernacular command adds the terms :n:`{+ @term}` (their types must be
+ equalities) in the rewriting bases :n:`{+ @ident}` with the default orientation
+ (left to right). Notice that the rewriting bases are distinct from the :tacn:`auto`
+ hint bases and that :tacn:`auto` does not take them into account.
+
+ This command is synchronous with the section mechanism (see :ref:`section-mechanism`):
+ when closing a section, all aliases created by ``Hint Rewrite`` in that
+ section are lost. Conversely, when loading a module, all ``Hint Rewrite``
+ declarations at the global level of that module are loaded.
+
+**Variants:**
+
+.. cmd:: Hint Rewrite -> {+ @term} : {+ @ident}
+
+ This is strictly equivalent to the command above (we only make explicit the
+ orientation which otherwise defaults to ->).
+
+.. cmd:: Hint Rewrite <- {+ @term} : {+ @ident}
+
+ Adds the rewriting rules :n:`{+ @term}` with a right-to-left orientation in
+ the bases :n:`{+ @ident}`.
+
+.. cmd:: Hint Rewrite {? {| -> | <- } } {+ @one_term } {? using @ltac_expr } {? : {* @ident } }
+
+ When the rewriting rules :n:`{+ @term}` in :n:`{+ @ident}` will be used, the
+ tactic ``tactic`` will be applied to the generated subgoals, the main subgoal
+ excluded.
+
+.. cmd:: Print Rewrite HintDb @ident
+
+ This command displays all rewrite hints contained in :n:`@ident`.
+
+Hint locality
+~~~~~~~~~~~~~
+
+Hints provided by the ``Hint`` commands are erased when closing a section.
+Conversely, all hints of a module ``A`` that are not defined inside a
+section (and not defined with option ``Local``) become available when the
+module ``A`` is required (using e.g. ``Require A.``).
+
+As of today, hints only have a binary behavior regarding locality, as
+described above: either they disappear at the end of a section scope,
+or they remain global forever. This causes a scalability issue,
+because hints coming from an unrelated part of the code may badly
+influence another development. It can be mitigated to some extent
+thanks to the :cmd:`Remove Hints` command,
+but this is a mere workaround and has some limitations (for instance, external
+hints cannot be removed).
+
+A proper way to fix this issue is to bind the hints to their module scope, as
+for most of the other objects |Coq| uses. Hints should only be made available when
+the module they are defined in is imported, not just required. It is very
+difficult to change the historical behavior, as it would break a lot of scripts.
+We propose a smooth transitional path by providing the :opt:`Loose Hint Behavior`
+option which accepts three flags allowing for a fine-grained handling of
+non-imported hints.
+
+.. opt:: Loose Hint Behavior {| "Lax" | "Warn" | "Strict" }
+ :name: Loose Hint Behavior
+
+ This option accepts three values, which control the behavior of hints w.r.t.
+ :cmd:`Import`:
+
+ - "Lax": this is the default, and corresponds to the historical behavior,
+ that is, hints defined outside of a section have a global scope.
+
+ - "Warn": outputs a warning when a non-imported hint is used. Note that this
+ is an over-approximation, because a hint may be triggered by a run that
+ will eventually fail and backtrack, resulting in the hint not being
+ actually useful for the proof.
+
+ - "Strict": changes the behavior of an unloaded hint to a immediate fail
+ tactic, allowing to emulate an import-scoped hint mechanism.
+
+.. _tactics-implicit-automation:
+
+Setting implicit automation tactics
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. cmd:: Proof with @tactic
+
+ This command may be used to start a proof. It defines a default tactic
+ to be used each time a tactic command ``tactic``:sub:`1` is ended by ``...``.
+ In this case the tactic command typed by the user is equivalent to
+ ``tactic``:sub:`1` ``;tactic``.
+
+ .. seealso:: :cmd:`Proof` in :ref:`proof-editing-mode`.
+
+
+ .. cmdv:: Proof with @tactic using {+ @ident}
+
+ Combines in a single line ``Proof with`` and ``Proof using``, see :ref:`proof-editing-mode`
+
+ .. cmdv:: Proof using {+ @ident} with @tactic
+
+ Combines in a single line ``Proof with`` and ``Proof using``, see :ref:`proof-editing-mode`
diff --git a/doc/sphinx/proofs/automatic-tactics/index.rst b/doc/sphinx/proofs/automatic-tactics/index.rst
index a219770c69..c3712b109d 100644
--- a/doc/sphinx/proofs/automatic-tactics/index.rst
+++ b/doc/sphinx/proofs/automatic-tactics/index.rst
@@ -1,20 +1,22 @@
.. _automatic-tactics:
=====================================================
-Built-in decision procedures and programmable tactics
+Automatic solvers and programmable tactics
=====================================================
Some tactics are largely automated and are able to solve complex
-goals. This chapter presents both some decision procedures that can
-be used to solve some specific categories of goals, and some
-programmable tactics, that the user can instrument to handle some
+goals. This chapter presents both built-in solvers that can
+be used on specific categories of goals and
+programmable tactics that the user can instrument to handle
complex goals in new domains.
.. toctree::
:maxdepth: 1
+ logic
../../addendum/omega
../../addendum/micromega
../../addendum/ring
../../addendum/nsatz
+ auto
../../addendum/generalized-rewriting
diff --git a/doc/sphinx/proofs/automatic-tactics/logic.rst b/doc/sphinx/proofs/automatic-tactics/logic.rst
new file mode 100644
index 0000000000..acf64ae437
--- /dev/null
+++ b/doc/sphinx/proofs/automatic-tactics/logic.rst
@@ -0,0 +1,294 @@
+.. _decisionprocedures:
+
+==============================
+Solvers for logic and equality
+==============================
+
+.. tacn:: tauto
+ :name: tauto
+
+ This tactic implements a decision procedure for intuitionistic propositional
+ calculus based on the contraction-free sequent calculi LJT* of Roy Dyckhoff
+ :cite:`Dyc92`. Note that :tacn:`tauto` succeeds on any instance of an
+ intuitionistic tautological proposition. :tacn:`tauto` unfolds negations and
+ logical equivalence but does not unfold any other definition.
+
+.. example::
+
+ The following goal can be proved by :tacn:`tauto` whereas :tacn:`auto` would
+ fail:
+
+ .. coqtop:: reset all
+
+ Goal forall (x:nat) (P:nat -> Prop), x = 0 \/ P x -> x <> 0 -> P x.
+ intros.
+ tauto.
+
+Moreover, if it has nothing else to do, :tacn:`tauto` performs introductions.
+Therefore, the use of :tacn:`intros` in the previous proof is unnecessary.
+:tacn:`tauto` can for instance for:
+
+.. example::
+
+ .. coqtop:: reset all
+
+ Goal forall (A:Prop) (P:nat -> Prop), A \/ (forall x:nat, ~ A -> P x) -> forall x:nat, ~ A -> P x.
+ tauto.
+
+.. note::
+ In contrast, :tacn:`tauto` cannot solve the following goal
+ :g:`Goal forall (A:Prop) (P:nat -> Prop), A \/ (forall x:nat, ~ A -> P x) ->`
+ :g:`forall x:nat, ~ ~ (A \/ P x).`
+ because :g:`(forall x:nat, ~ A -> P x)` cannot be treated as atomic and
+ an instantiation of `x` is necessary.
+
+.. tacv:: dtauto
+ :name: dtauto
+
+ While :tacn:`tauto` recognizes inductively defined connectives isomorphic to
+ the standard connectives ``and``, ``prod``, ``or``, ``sum``, ``False``,
+ ``Empty_set``, ``unit``, ``True``, :tacn:`dtauto` also recognizes all inductive
+ types with one constructor and no indices, i.e. record-style connectives.
+
+.. tacn:: intuition @tactic
+ :name: intuition
+
+ The tactic :tacn:`intuition` takes advantage of the search-tree built by the
+ decision procedure involved in the tactic :tacn:`tauto`. It uses this
+ information to generate a set of subgoals equivalent to the original one (but
+ simpler than it) and applies the tactic :n:`@tactic` to them :cite:`Mun94`. If
+ this tactic fails on some goals then :tacn:`intuition` fails. In fact,
+ :tacn:`tauto` is simply :g:`intuition fail`.
+
+ .. example::
+
+ For instance, the tactic :g:`intuition auto` applied to the goal::
+
+ (forall (x:nat), P x) /\ B -> (forall (y:nat), P y) /\ P O \/ B /\ P O
+
+ internally replaces it by the equivalent one::
+
+ (forall (x:nat), P x), B |- P O
+
+ and then uses :tacn:`auto` which completes the proof.
+
+Originally due to César Muñoz, these tactics (:tacn:`tauto` and
+:tacn:`intuition`) have been completely re-engineered by David Delahaye using
+mainly the tactic language (see :ref:`ltac`). The code is
+now much shorter and a significant increase in performance has been noticed.
+The general behavior with respect to dependent types, unfolding and
+introductions has slightly changed to get clearer semantics. This may lead to
+some incompatibilities.
+
+.. tacv:: intuition
+
+ Is equivalent to :g:`intuition auto with *`.
+
+.. tacv:: dintuition
+ :name: dintuition
+
+ While :tacn:`intuition` recognizes inductively defined connectives
+ isomorphic to the standard connectives ``and``, ``prod``, ``or``, ``sum``, ``False``,
+ ``Empty_set``, ``unit``, ``True``, :tacn:`dintuition` also recognizes all inductive
+ types with one constructor and no indices, i.e. record-style connectives.
+
+.. flag:: Intuition Negation Unfolding
+
+ Controls whether :tacn:`intuition` unfolds inner negations which do not need
+ to be unfolded. This flag is on by default.
+
+.. tacn:: rtauto
+ :name: rtauto
+
+ The :tacn:`rtauto` tactic solves propositional tautologies similarly to what
+ :tacn:`tauto` does. The main difference is that the proof term is built using a
+ reflection scheme applied to a sequent calculus proof of the goal. The search
+ procedure is also implemented using a different technique.
+
+ Users should be aware that this difference may result in faster proof-search
+ but slower proof-checking, and :tacn:`rtauto` might not solve goals that
+ :tacn:`tauto` would be able to solve (e.g. goals involving universal
+ quantifiers).
+
+ Note that this tactic is only available after a ``Require Import Rtauto``.
+
+.. tacn:: firstorder
+ :name: firstorder
+
+ The tactic :tacn:`firstorder` is an experimental extension of :tacn:`tauto` to
+ first- order reasoning, written by Pierre Corbineau. It is not restricted to
+ usual logical connectives but instead may reason about any first-order class
+ inductive definition.
+
+.. opt:: Firstorder Solver @tactic
+ :name: Firstorder Solver
+
+ The default tactic used by :tacn:`firstorder` when no rule applies is
+ :g:`auto with core`, it can be reset locally or globally using this option.
+
+ .. cmd:: Print Firstorder Solver
+
+ Prints the default tactic used by :tacn:`firstorder` when no rule applies.
+
+.. tacv:: firstorder @tactic
+
+ Tries to solve the goal with :n:`@tactic` when no logical rule may apply.
+
+.. tacv:: firstorder using {+ @qualid}
+
+ .. deprecated:: 8.3
+
+ Use the syntax below instead (with commas).
+
+.. tacv:: firstorder using {+, @qualid}
+
+ Adds lemmas :n:`{+, @qualid}` to the proof-search environment. If :n:`@qualid`
+ refers to an inductive type, it is the collection of its constructors which are
+ added to the proof-search environment.
+
+.. tacv:: firstorder with {+ @ident}
+
+ Adds lemmas from :tacn:`auto` hint bases :n:`{+ @ident}` to the proof-search
+ environment.
+
+.. tacv:: firstorder @tactic using {+, @qualid} with {+ @ident}
+
+ This combines the effects of the different variants of :tacn:`firstorder`.
+
+.. opt:: Firstorder Depth @natural
+ :name: Firstorder Depth
+
+ This option controls the proof-search depth bound.
+
+.. tacn:: congruence
+ :name: congruence
+
+ The tactic :tacn:`congruence`, by Pierre Corbineau, implements the standard
+ Nelson and Oppen congruence closure algorithm, which is a decision procedure
+ for ground equalities with uninterpreted symbols. It also includes
+ constructor theory (see :tacn:`injection` and :tacn:`discriminate`). If the goal
+ is a non-quantified equality, congruence tries to prove it with non-quantified
+ equalities in the context. Otherwise it tries to infer a discriminable equality
+ from those in the context. Alternatively, congruence tries to prove that a
+ hypothesis is equal to the goal or to the negation of another hypothesis.
+
+ :tacn:`congruence` is also able to take advantage of hypotheses stating
+ quantified equalities, but you have to provide a bound for the number of extra
+ equalities generated that way. Please note that one of the sides of the
+ equality must contain all the quantified variables in order for congruence to
+ match against it.
+
+.. example::
+
+ .. coqtop:: reset all
+
+ Theorem T (A:Type) (f:A -> A) (g: A -> A -> A) a b: a=(f a) -> (g b (f a))=(f (f a)) -> (g a b)=(f (g b a)) -> (g a b)=a.
+ intros.
+ congruence.
+ Qed.
+
+ Theorem inj (A:Type) (f:A -> A * A) (a c d: A) : f = pair a -> Some (f c) = Some (f d) -> c=d.
+ intros.
+ congruence.
+ Qed.
+
+.. tacv:: congruence @natural
+
+ Tries to add at most :token:`natural` instances of hypotheses stating quantified equalities
+ to the problem in order to solve it. A bigger value of :token:`natural` does not make
+ success slower, only failure. You might consider adding some lemmas as
+ hypotheses using assert in order for :tacn:`congruence` to use them.
+
+.. tacv:: congruence with {+ @term}
+ :name: congruence with
+
+ Adds :n:`{+ @term}` to the pool of terms used by :tacn:`congruence`. This helps
+ in case you have partially applied constructors in your goal.
+
+.. exn:: I don’t know how to handle dependent equality.
+
+ The decision procedure managed to find a proof of the goal or of a
+ discriminable equality but this proof could not be built in |Coq| because of
+ dependently-typed functions.
+
+.. exn:: Goal is solvable by congruence but some arguments are missing. Try congruence with {+ @term}, replacing metavariables by arbitrary terms.
+
+ The decision procedure could solve the goal with the provision that additional
+ arguments are supplied for some partially applied constructors. Any term of an
+ appropriate type will allow the tactic to successfully solve the goal. Those
+ additional arguments can be given to congruence by filling in the holes in the
+ terms given in the error message, using the :tacn:`congruence with` variant described above.
+
+.. flag:: Congruence Verbose
+
+ This flag makes :tacn:`congruence` print debug information.
+
+.. tacn:: btauto
+ :name: btauto
+
+ The tactic :tacn:`btauto` implements a reflexive solver for boolean
+ tautologies. It solves goals of the form :g:`t = u` where `t` and `u` are
+ constructed over the following grammar:
+
+ .. prodn::
+ btauto_term ::= @ident
+ | true
+ | false
+ | orb @btauto_term @btauto_term
+ | andb @btauto_term @btauto_term
+ | xorb @btauto_term @btauto_term
+ | negb @btauto_term
+ | if @btauto_term then @btauto_term else @btauto_term
+
+ Whenever the formula supplied is not a tautology, it also provides a
+ counter-example.
+
+ Internally, it uses a system very similar to the one of the ring
+ tactic.
+
+ Note that this tactic is only available after a ``Require Import Btauto``.
+
+ .. exn:: Cannot recognize a boolean equality.
+
+ The goal is not of the form :g:`t = u`. Especially note that :tacn:`btauto`
+ doesn't introduce variables into the context on its own.
+
+.. tacv:: field
+ field_simplify {* @term}
+ field_simplify_eq
+
+ The field tactic is built on the same ideas as ring: this is a
+ reflexive tactic that solves or simplifies equations in a field
+ structure. The main idea is to reduce a field expression (which is an
+ extension of ring expressions with the inverse and division
+ operations) to a fraction made of two polynomial expressions.
+
+ Tactic :n:`field` is used to solve subgoals, whereas :n:`field_simplify {+ @term}`
+ replaces the provided terms by their reduced fraction.
+ :n:`field_simplify_eq` applies when the conclusion is an equation: it
+ simplifies both hand sides and multiplies so as to cancel
+ denominators. So it produces an equation without division nor inverse.
+
+ All of these 3 tactics may generate a subgoal in order to prove that
+ denominators are different from zero.
+
+ See :ref:`Theringandfieldtacticfamilies` for more information on the tactic and how to
+ declare new field structures. All declared field structures can be
+ printed with the Print Fields command.
+
+.. example::
+
+ .. coqtop:: reset all
+
+ Require Import Reals.
+ Goal forall x y:R,
+ (x * y > 0)%R ->
+ (x * (1 / x + x / (x + y)))%R =
+ ((- 1 / y) * y * (- x * (x / (x + y)) - 1))%R.
+
+ intros; field.
+
+.. seealso::
+
+ File plugins/ring/RealField.v for an example of instantiation,
+ theory theories/Reals for many examples of use of field.
diff --git a/doc/sphinx/proofs/creating-tactics/index.rst b/doc/sphinx/proofs/creating-tactics/index.rst
index 1af1b0b726..f1d4fa789d 100644
--- a/doc/sphinx/proofs/creating-tactics/index.rst
+++ b/doc/sphinx/proofs/creating-tactics/index.rst
@@ -18,13 +18,13 @@ new tactics:
- `Mtac2 <https://github.com/Mtac2/Mtac2>`_ is an external plugin
which provides another typed tactic language. While Ltac2 belongs
- to the ML language family, Mtac2 reuses the language of Coq itself
- as the language to build Coq tactics.
+ to the ML language family, Mtac2 reuses the language of |Coq| itself
+ as the language to build |Coq| tactics.
- The most traditional way of building new complex tactics is to write
- a Coq plugin in OCaml. Beware that this also requires much more
- effort and commitment. A tutorial for writing Coq plugins is
- available in the Coq repository in `doc/plugin_tutorial
+ a |Coq| plugin in |OCaml|. Beware that this also requires much more
+ effort and commitment. A tutorial for writing |Coq| plugins is
+ available in the |Coq| repository in `doc/plugin_tutorial
<https://github.com/coq/coq/tree/master/doc/plugin_tutorial>`_.
.. toctree::
diff --git a/doc/sphinx/proofs/writing-proofs/index.rst b/doc/sphinx/proofs/writing-proofs/index.rst
index a279a5957f..1c7fd050f1 100644
--- a/doc/sphinx/proofs/writing-proofs/index.rst
+++ b/doc/sphinx/proofs/writing-proofs/index.rst
@@ -1,10 +1,10 @@
.. _writing-proofs:
-==============
-Writing proofs
-==============
+===================
+Basic proof writing
+===================
-Coq is an interactive theorem prover, or proof assistant, which means
+|Coq| is an interactive theorem prover, or proof assistant, which means
that proofs can be constructed interactively through a dialog between
the user and the assistant. The building blocks for this dialog are
tactics which the user will use to represent steps in the proof of a
@@ -27,8 +27,9 @@ flavors of tactics, including the SSReflect proof language.
.. toctree::
:maxdepth: 1
- ../../proof-engine/proof-handling
+ proof-mode
../../proof-engine/tactics
+ rewriting
../../proof-engine/ssreflect-proof-language
../../proof-engine/detailed-tactic-examples
../../user-extensions/proof-schemes
diff --git a/doc/sphinx/proofs/writing-proofs/proof-mode.rst b/doc/sphinx/proofs/writing-proofs/proof-mode.rst
new file mode 100644
index 0000000000..b74c9d3a23
--- /dev/null
+++ b/doc/sphinx/proofs/writing-proofs/proof-mode.rst
@@ -0,0 +1,1037 @@
+.. _proofhandling:
+
+-------------------
+ Proof handling
+-------------------
+
+In |Coq|’s proof editing mode all top-level commands documented in
+Chapter :ref:`vernacularcommands` remain available and the user has access to specialized
+commands dealing with proof development pragmas documented in this
+section. They can also use some other specialized commands called
+*tactics*. They are the very tools allowing the user to deal with
+logical reasoning. They are documented in Chapter :ref:`tactics`.
+
+|Coq| user interfaces usually have a way of marking whether the user has
+switched to proof editing mode. For instance, in coqtop the prompt ``Coq <``   is changed into
+:n:`@ident <`   where :token:`ident` is the declared name of the theorem currently edited.
+
+At each stage of a proof development, one has a list of goals to
+prove. Initially, the list consists only in the theorem itself. After
+having applied some tactics, the list of goals contains the subgoals
+generated by the tactics.
+
+To each subgoal is associated a number of hypotheses called the *local context*
+of the goal. Initially, the local context contains the local variables and
+hypotheses of the current section (see Section :ref:`gallina-assumptions`) and
+the local variables and hypotheses of the theorem statement. It is enriched by
+the use of certain tactics (see e.g. :tacn:`intro`).
+
+When a proof is completed, the message ``Proof completed`` is displayed.
+One can then register this proof as a defined constant in the
+environment. Because there exists a correspondence between proofs and
+terms of λ-calculus, known as the *Curry-Howard isomorphism*
+:cite:`How80,Bar81,Gir89,H89`, |Coq| stores proofs as terms of |Cic|. Those
+terms are called *proof terms*.
+
+
+.. exn:: No focused proof.
+
+ |Coq| raises this error message when one attempts to use a proof editing command
+ out of the proof editing mode.
+
+.. _proof-editing-mode:
+
+Entering and leaving proof editing mode
+---------------------------------------
+
+The proof editing mode is entered by asserting a statement, which typically is
+the assertion of a theorem using an assertion command like :cmd:`Theorem`. The
+list of assertion commands is given in :ref:`Assertions`. The command
+:cmd:`Goal` can also be used.
+
+.. cmd:: Goal @type
+
+ This is intended for quick assertion of statements, without knowing in
+ advance which name to give to the assertion, typically for quick
+ testing of the provability of a statement. If the proof of the
+ statement is eventually completed and validated, the statement is then
+ bound to the name ``Unnamed_thm`` (or a variant of this name not already
+ used for another statement).
+
+.. cmd:: Qed
+
+ This command is available in interactive editing proof mode when the
+ proof is completed. Then :cmd:`Qed` extracts a proof term from the proof
+ script, switches back to |Coq| top-level and attaches the extracted
+ proof term to the declared name of the original goal. The name is
+ added to the environment as an opaque constant.
+
+ .. exn:: Attempt to save an incomplete proof.
+ :undocumented:
+
+ .. note::
+
+ Sometimes an error occurs when building the proof term, because
+ tactics do not enforce completely the term construction
+ constraints.
+
+ The user should also be aware of the fact that since the
+ proof term is completely rechecked at this point, one may have to wait
+ a while when the proof is large. In some exceptional cases one may
+ even incur a memory overflow.
+
+.. cmd:: Save @ident
+ :name: Save
+
+ Saves a completed proof with the name :token:`ident`, which
+ overrides any name provided by the :cmd:`Theorem` command or
+ its variants.
+
+.. cmd:: Defined {? @ident }
+
+ Similar to :cmd:`Qed` and :cmd:`Save`, except the proof is made *transparent*, which means
+ that its content can be explicitly used for type checking and that it can be
+ unfolded in conversion tactics (see :ref:`performingcomputations`,
+ :cmd:`Opaque`, :cmd:`Transparent`). If :token:`ident` is specified,
+ the proof is defined with the given name, which overrides any name
+ provided by the :cmd:`Theorem` command or its variants.
+
+.. cmd:: Admitted
+
+ This command is available in interactive editing mode to give up
+ the current proof and declare the initial goal as an axiom.
+
+.. cmd:: Abort {? {| All | @ident } }
+
+ Cancels the current proof development, switching back to
+ the previous proof development, or to the |Coq| toplevel if no other
+ proof was being edited.
+
+ :n:`@ident`
+ Aborts editing the proof named :n:`@ident` for use when you have
+ nested proofs. See also :flag:`Nested Proofs Allowed`.
+
+ :n:`All`
+ Aborts all current proofs.
+
+ .. exn:: No focused proof (No proof-editing in progress).
+ :undocumented:
+
+.. cmd:: Proof @term
+ :name: Proof `term`
+
+ This command applies in proof editing mode. It is equivalent to
+ :n:`exact @term. Qed.`
+ That is, you have to give the full proof in one gulp, as a
+ proof term (see Section :ref:`applyingtheorems`).
+
+ .. warning::
+
+ Use of this command is discouraged. In particular, it
+ doesn't work in Proof General because it must
+ immediately follow the command that opened proof mode, but
+ Proof General inserts :cmd:`Unset` :flag:`Silent` before it (see
+ `Proof General issue #498
+ <https://github.com/ProofGeneral/PG/issues/498>`_).
+
+.. cmd:: Proof
+
+ Is a no-op which is useful to delimit the sequence of tactic commands
+ which start a proof, after a :cmd:`Theorem` command. It is a good practice to
+ use :cmd:`Proof` as an opening parenthesis, closed in the script with a
+ closing :cmd:`Qed`.
+
+ .. seealso:: :cmd:`Proof with`
+
+.. cmd:: Proof using @section_var_expr {? with @ltac_expr }
+
+ .. insertprodn section_var_expr starred_ident_ref
+
+ .. prodn::
+ section_var_expr ::= {* @starred_ident_ref }
+ | {? - } @section_var_expr50
+ section_var_expr50 ::= @section_var_expr0 - @section_var_expr0
+ | @section_var_expr0 + @section_var_expr0
+ | @section_var_expr0
+ section_var_expr0 ::= @starred_ident_ref
+ | ( @section_var_expr ) {? * }
+ starred_ident_ref ::= @ident {? * }
+ | Type {? * }
+ | All
+
+ Opens proof editing mode, declaring the set of
+ section variables (see :ref:`gallina-assumptions`) used by the proof.
+ At :cmd:`Qed` time, the
+ system verifies that the set of section variables used in
+ the proof is a subset of the declared one.
+
+ The set of declared variables is closed under type dependency. For
+ example, if ``T`` is a variable and ``a`` is a variable of type
+ ``T``, then the commands ``Proof using a`` and ``Proof using T a``
+ are equivalent.
+
+ The set of declared variables always includes the variables used by
+ the statement. In other words ``Proof using e`` is equivalent to
+ ``Proof using Type + e`` for any declaration expression ``e``.
+
+ :n:`- @section_var_expr50`
+ Use all section variables except those specified by :n:`@section_var_expr50`
+
+ :n:`@section_var_expr0 + @section_var_expr0`
+ Use section variables from the union of both collections.
+ See :ref:`nameaset` to see how to form a named collection.
+
+ :n:`@section_var_expr0 - @section_var_expr0`
+ Use section variables which are in the first collection but not in the
+ second one.
+
+ :n:`{? * }`
+ Use the transitive closure of the specified collection.
+
+ :n:`Type`
+ Use only section variables occurring in the statement. Specifying :n:`*`
+ uses the forward transitive closure of all the section variables occurring
+ in the statement. For example, if the variable ``H`` has type ``p < 5`` then
+ ``H`` is in ``p*`` since ``p`` occurs in the type of ``H``.
+
+ :n:`All`
+ Use all section variables.
+
+ .. seealso:: :ref:`tactics-implicit-automation`
+
+.. attr:: using
+
+ This attribute can be applied to the :cmd:`Definition`, :cmd:`Example`,
+ :cmd:`Fixpoint` and :cmd:`CoFixpoint` commands as well as to :cmd:`Lemma` and
+ its variants. It takes
+ a :n:`@section_var_expr`, in quotes, as its value. This is equivalent to
+ specifying the same :n:`@section_var_expr` in
+ :cmd:`Proof using`.
+
+ .. example::
+
+ .. coqtop:: all
+
+ Section Test.
+ Variable n : nat.
+ Hypothesis Hn : n <> 0.
+
+ #[using="Hn"]
+ Lemma example : 0 < n.
+
+ .. coqtop:: in
+
+ Abort.
+ End Test.
+
+
+Proof using options
+```````````````````
+
+The following options modify the behavior of ``Proof using``.
+
+
+.. opt:: Default Proof Using "@section_var_expr"
+ :name: Default Proof Using
+
+ Use :n:`@section_var_expr` as the default ``Proof using`` value. E.g. ``Set Default
+ Proof Using "a b"`` will complete all ``Proof`` commands not followed by a
+ ``using`` part with ``using a b``.
+
+
+.. flag:: Suggest Proof Using
+
+ When :cmd:`Qed` is performed, suggest a ``using`` annotation if the user did not
+ provide one.
+
+.. _`nameaset`:
+
+Name a set of section hypotheses for ``Proof using``
+````````````````````````````````````````````````````
+
+.. cmd:: Collection @ident := @section_var_expr
+
+ This can be used to name a set of section
+ hypotheses, with the purpose of making ``Proof using`` annotations more
+ compact.
+
+ .. example::
+
+ Define the collection named ``Some`` containing ``x``, ``y`` and ``z``::
+
+ Collection Some := x y z.
+
+ Define the collection named ``Fewer`` containing only ``x`` and ``y``::
+
+ Collection Fewer := Some - z
+
+ Define the collection named ``Many`` containing the set union or set
+ difference of ``Fewer`` and ``Some``::
+
+ Collection Many := Fewer + Some
+ Collection Many := Fewer - Some
+
+ Define the collection named ``Many`` containing the set difference of
+ ``Fewer`` and the unnamed collection ``x y``::
+
+ Collection Many := Fewer - (x y)
+
+
+
+.. cmd:: Existential @natural {? : @type } := @term
+
+ This command instantiates an existential variable. :token:`natural` is an index in
+ the list of uninstantiated existential variables displayed by :cmd:`Show Existentials`.
+
+ This command is intended to be used to instantiate existential
+ variables when the proof is completed but some uninstantiated
+ existential variables remain. To instantiate existential variables
+ during proof edition, you should use the tactic :tacn:`instantiate`.
+
+.. cmd:: Grab Existential Variables
+
+ This command can be run when a proof has no more goal to be solved but
+ has remaining uninstantiated existential variables. It takes every
+ uninstantiated existential variable and turns it into a goal.
+
+Proof modes
+```````````
+
+When entering proof mode through commands such as :cmd:`Goal` and :cmd:`Proof`,
+|Coq| picks by default the |Ltac| mode. Nonetheless, there exist other proof modes
+shipped in the standard |Coq| installation, and furthermore some plugins define
+their own proof modes. The default proof mode used when opening a proof can
+be changed using the following option.
+
+.. opt:: Default Proof Mode @string
+
+ Select the proof mode to use when starting a proof. Depending on the proof
+ mode, various syntactic constructs are allowed when writing an interactive
+ proof. All proof modes support vernacular commands; the proof mode determines
+ which tactic language and set of tactic definitions are available. The
+ possible option values are:
+
+ `"Classic"`
+ Activates the |Ltac| language and the tactics with the syntax documented
+ in this manual.
+ Some tactics are not available until the associated plugin is loaded,
+ such as `SSR` or `micromega`.
+ This proof mode is set when the :term:`prelude` is loaded.
+
+ `"Noedit"`
+ No tactic
+ language is activated at all. This is the default when the :term:`prelude`
+ is not loaded, e.g. through the `-noinit` option for `coqc`.
+
+ `"Ltac2"`
+ Activates the Ltac2 language and the Ltac2-specific variants of the documented
+ tactics.
+ This value is only available after :cmd:`Requiring <Require>` Ltac2.
+ :cmd:`Importing <Import>` Ltac2 sets this mode.
+
+ Some external plugins also define their own proof mode, which can be
+ activated with this command.
+
+Navigation in the proof tree
+--------------------------------
+
+.. cmd:: Undo {? {? To } @natural }
+
+ Cancels the effect of the last :token:`natural` commands or tactics.
+ The :n:`To @natural` form goes back to the specified state number.
+ If :token:`natural` is not specified, the command goes back one command or tactic.
+
+.. cmd:: Restart
+
+ Restores the proof editing process to the original goal.
+
+ .. exn:: No focused proof to restart.
+ :undocumented:
+
+.. cmd:: Focus {? @natural }
+
+ Focuses the attention on the first subgoal to prove or, if :token:`natural` is
+ specified, the :token:`natural`\-th. The
+ printing of the other subgoals is suspended until the focused subgoal
+ is solved or unfocused.
+
+ .. deprecated:: 8.8
+
+ Prefer the use of bullets or focusing brackets with a goal selector (see below).
+
+.. cmd:: Unfocus
+
+ This command restores to focus the goal that were suspended by the
+ last :cmd:`Focus` command.
+
+ .. deprecated:: 8.8
+
+.. cmd:: Unfocused
+
+ Succeeds if the proof is fully unfocused, fails if there are some
+ goals out of focus.
+
+.. _curly-braces:
+
+.. index:: {
+ }
+
+.. todo: :name: "{"; "}" doesn't work, nor does :name: left curly bracket; right curly bracket,
+ hence the verbose names
+
+.. tacn:: {? {| @natural | [ @ident ] } : } %{
+ %}
+
+ .. todo
+ See https://github.com/coq/coq/issues/12004 and
+ https://github.com/coq/coq/issues/12825.
+
+ ``{`` (without a terminating period) focuses on the first
+ goal. The subproof can only be
+ unfocused when it has been fully solved (*i.e.*, when there is no
+ focused goal left). Unfocusing is then handled by ``}`` (again, without a
+ terminating period). See also an example in the next section.
+
+ Note that when a focused goal is proved a message is displayed
+ together with a suggestion about the right bullet or ``}`` to unfocus it
+ or focus the next one.
+
+ :n:`@natural:`
+ Focuses on the :token:`natural`\-th subgoal to prove.
+
+ :n:`[ @ident ]: %{`
+ Focuses on the named goal :token:`ident`.
+
+ .. note::
+
+ Goals are just existential variables and existential variables do not
+ get a name by default. You can give a name to a goal by using :n:`refine ?[@ident]`.
+ You may also wrap this in an Ltac-definition like:
+
+ .. coqtop:: in
+
+ Ltac name_goal name := refine ?[name].
+
+ .. seealso:: :ref:`existential-variables`
+
+ .. example::
+
+ This first example uses the Ltac definition above, and the named goals
+ only serve for documentation.
+
+ .. coqtop:: all
+
+ Goal forall n, n + 0 = n.
+ Proof.
+ induction n; [ name_goal base | name_goal step ].
+ [base]: {
+
+ .. coqtop:: all
+
+ reflexivity.
+
+ .. coqtop:: in
+
+ }
+
+ .. coqtop:: all
+
+ [step]: {
+
+ .. coqtop:: all
+
+ simpl.
+ f_equal.
+ assumption.
+ }
+ Qed.
+
+ This can also be a way of focusing on a shelved goal, for instance:
+
+ .. coqtop:: all
+
+ Goal exists n : nat, n = n.
+ eexists ?[x].
+ reflexivity.
+ [x]: exact 0.
+ Qed.
+
+ .. exn:: This proof is focused, but cannot be unfocused this way.
+
+ You are trying to use ``}`` but the current subproof has not been fully solved.
+
+ .. exn:: No such goal (@natural).
+ :undocumented:
+
+ .. exn:: No such goal (@ident).
+ :undocumented:
+
+ .. exn:: Brackets do not support multi-goal selectors.
+
+ Brackets are used to focus on a single goal given either by its position
+ or by its name if it has one.
+
+ .. seealso:: The error messages for bullets below.
+
+.. _bullets:
+
+Bullets
+```````
+
+Alternatively, proofs can be structured with bullets instead of ``{`` and ``}``. The
+use of a bullet ``b`` for the first time focuses on the first goal ``g``, the
+same bullet cannot be used again until the proof of ``g`` is completed,
+then it is mandatory to focus the next goal with ``b``. The consequence is
+that ``g`` and all goals present when ``g`` was focused are focused with the
+same bullet ``b``. See the example below.
+
+Different bullets can be used to nest levels. The scope of bullet does
+not go beyond enclosing ``{`` and ``}``, so bullets can be reused as further
+nesting levels provided they are delimited by these. Bullets are made of
+repeated ``-``, ``+`` or ``*`` symbols:
+
+.. prodn:: bullet ::= {| {+ - } | {+ + } | {+ * } }
+
+Note again that when a focused goal is proved a message is displayed
+together with a suggestion about the right bullet or ``}`` to unfocus it
+or focus the next one.
+
+.. note::
+
+ In Proof General (``Emacs`` interface to |Coq|), you must use
+ bullets with the priority ordering shown above to have a correct
+ indentation. For example ``-`` must be the outer bullet and ``**`` the inner
+ one in the example below.
+
+The following example script illustrates all these features:
+
+.. example::
+
+ .. coqtop:: all
+
+ Goal (((True /\ True) /\ True) /\ True) /\ True.
+ Proof.
+ split.
+ - split.
+ + split.
+ ** { split.
+ - trivial.
+ - trivial.
+ }
+ ** trivial.
+ + trivial.
+ - assert True.
+ { trivial. }
+ assumption.
+ Qed.
+
+.. exn:: Wrong bullet @bullet__1: Current bullet @bullet__2 is not finished.
+
+ Before using bullet :n:`@bullet__1` again, you should first finish proving
+ the current focused goal.
+ Note that :n:`@bullet__1` and :n:`@bullet__2` may be the same.
+
+.. exn:: Wrong bullet @bullet__1: Bullet @bullet__2 is mandatory here.
+
+ You must put :n:`@bullet__2` to focus on the next goal. No other bullet is
+ allowed here.
+
+.. exn:: No such goal. Focus next goal with bullet @bullet.
+
+ You tried to apply a tactic but no goals were under focus.
+ Using :n:`@bullet` is mandatory here.
+
+.. FIXME: the :noindex: below works around a Sphinx issue.
+ (https://github.com/sphinx-doc/sphinx/issues/4979)
+ It should be removed once that issue is fixed.
+
+.. exn:: No such goal. Try unfocusing with %}.
+ :noindex:
+
+ You just finished a goal focused by ``{``, you must unfocus it with ``}``.
+
+Mandatory Bullets
+~~~~~~~~~~~~~~~~~
+
+Using :opt:`Default Goal Selector` with the ``!`` selector forces
+tactic scripts to keep focus to exactly one goal (e.g. using bullets)
+or use explicit goal selectors.
+
+Set Bullet Behavior
+~~~~~~~~~~~~~~~~~~~
+
+.. opt:: Bullet Behavior {| "None" | "Strict Subproofs" }
+ :name: Bullet Behavior
+
+ This option controls the bullet behavior and can take two possible values:
+
+ - "None": this makes bullets inactive.
+ - "Strict Subproofs": this makes bullets active (this is the default behavior).
+
+Modifying the order of goals
+````````````````````````````
+
+.. tacn:: cycle @integer
+ :name: cycle
+
+ Reorders the selected goals so that the first :n:`@integer` goals appear after the
+ other selected goals.
+ If :n:`@integer` is negative, it puts the last :n:`@integer` goals at the
+ beginning of the list.
+ The tactic is only useful with a goal selector, most commonly `all:`.
+ Note that other selectors reorder goals; `1,3: cycle 1` is not equivalent
+ to `all: cycle 1`. See :tacn:`… : … (goal selector)`.
+
+.. example::
+
+ .. coqtop:: none reset
+
+ Parameter P : nat -> Prop.
+
+ .. coqtop:: all abort
+
+ Goal P 1 /\ P 2 /\ P 3 /\ P 4 /\ P 5.
+ repeat split.
+ all: cycle 2.
+ all: cycle -3.
+
+.. tacn:: swap @integer @integer
+ :name: swap
+
+ Exchanges the position of the specified goals.
+ Negative values for :n:`@integer` indicate counting goals
+ backward from the end of the list of selected goals. Goals are indexed from 1.
+ The tactic is only useful with a goal selector, most commonly `all:`.
+ Note that other selectors reorder goals; `1,3: swap 1 3` is not equivalent
+ to `all: swap 1 3`. See :tacn:`… : … (goal selector)`.
+
+.. example::
+
+ .. coqtop:: all abort
+
+ Goal P 1 /\ P 2 /\ P 3 /\ P 4 /\ P 5.
+ repeat split.
+ all: swap 1 3.
+ all: swap 1 -1.
+
+.. tacn:: revgoals
+ :name: revgoals
+
+ Reverses the order of the selected goals. The tactic is only useful with a goal
+ selector, most commonly `all :`. Note that other selectors reorder goals;
+ `1,3: revgoals` is not equivalent to `all: revgoals`. See :tacn:`… : … (goal selector)`.
+
+ .. example::
+
+ .. coqtop:: all abort
+
+ Goal P 1 /\ P 2 /\ P 3 /\ P 4 /\ P 5.
+ repeat split.
+ all: revgoals.
+
+Postponing the proof of some goals
+``````````````````````````````````
+
+.. tacn:: shelve
+ :name: shelve
+
+ This tactic moves all goals under focus to a shelf. While on the
+ shelf, goals will not be focused on. They can be solved by
+ unification, or they can be called back into focus with the command
+ :cmd:`Unshelve`.
+
+ .. tacv:: shelve_unifiable
+ :name: shelve_unifiable
+
+ Shelves only the goals under focus that are mentioned in other goals.
+ Goals that appear in the type of other goals can be solved by unification.
+
+ .. example::
+
+ .. coqtop:: all abort
+
+ Goal exists n, n=0.
+ refine (ex_intro _ _ _).
+ all: shelve_unifiable.
+ reflexivity.
+
+.. cmd:: Unshelve
+
+ This command moves all the goals on the shelf (see :tacn:`shelve`)
+ from the shelf into focus, by appending them to the end of the current
+ list of focused goals.
+
+.. tacn:: unshelve @tactic
+ :name: unshelve
+
+ Performs :n:`@tactic`, then unshelves existential variables added to the
+ shelf by the execution of :n:`@tactic`, prepending them to the current goal.
+
+.. tacn:: give_up
+ :name: give_up
+
+ This tactic removes the focused goals from the proof. They are not
+ solved, and cannot be solved later in the proof. As the goals are not
+ solved, the proof cannot be closed.
+
+ The ``give_up`` tactic can be used while editing a proof, to choose to
+ write the proof script in a non-sequential order.
+
+.. _requestinginformation:
+
+Requesting information
+----------------------
+
+
+.. cmd:: Show {? {| @ident | @natural } }
+
+ Displays the current goals.
+
+ :n:`@natural`
+ Display only the :token:`natural`\-th subgoal.
+
+ :n:`@ident`
+ Displays the named goal :token:`ident`. This is useful in
+ particular to display a shelved goal but only works if the
+ corresponding existential variable has been named by the user
+ (see :ref:`existential-variables`) as in the following example.
+
+ .. example::
+
+ .. coqtop:: all abort
+
+ Goal exists n, n = 0.
+ eexists ?[n].
+ Show n.
+
+ .. exn:: No focused proof.
+ :undocumented:
+
+ .. exn:: No such goal.
+ :undocumented:
+
+.. cmd:: Show Proof {? Diffs {? removed } }
+
+ Displays the proof term generated by the tactics
+ that have been applied so far. If the proof is incomplete, the term
+ will contain holes, which correspond to subterms which are still to be
+ constructed. Each hole is an existential variable, which appears as a
+ question mark followed by an identifier.
+
+ Specifying “Diffs” highlights the difference between the
+ current and previous proof step. By default, the command shows the
+ output once with additions highlighted. Including “removed” shows
+ the output twice: once showing removals and once showing additions.
+ It does not examine the :opt:`Diffs` option. See :ref:`showing_proof_diffs`.
+
+.. cmd:: Show Conjectures
+
+ Prints the names of all the
+ theorems that are currently being proved. As it is possible to start
+ proving a previous lemma during the proof of a theorem, there may
+ be multiple names.
+
+.. cmd:: Show Intro
+
+ If the current goal begins by at least one product,
+ prints the name of the first product as it would be
+ generated by an anonymous :tacn:`intro`. The aim of this command is to ease
+ the writing of more robust scripts. For example, with an appropriate
+ Proof General macro, it is possible to transform any anonymous :tacn:`intro`
+ into a qualified one such as ``intro y13``. In the case of a non-product
+ goal, it prints nothing.
+
+.. cmd:: Show Intros
+
+ Similar to the previous command.
+ Simulates the naming process of :tacn:`intros`.
+
+.. cmd:: Show Existentials
+
+ Displays all open goals / existential variables in the current proof
+ along with the type and the context of each variable.
+
+.. cmd:: Show Match @qualid
+
+ Displays a template of the Gallina :token:`match<term_match>`
+ construct with a branch for each constructor of the type
+ :token:`qualid`. This is used internally by
+ `company-coq <https://github.com/cpitclaudel/company-coq>`_.
+
+ .. example::
+
+ .. coqtop:: all
+
+ Show Match nat.
+
+ .. exn:: Unknown inductive type.
+ :undocumented:
+
+.. cmd:: Show Universes
+
+ Displays the set of all universe constraints and
+ its normalized form at the current stage of the proof, useful for
+ debugging universe inconsistencies.
+
+.. cmd:: Show Goal @natural at @natural
+
+ Available in coqtop. Displays a goal at a
+ proof state using the goal ID number and the proof state ID number.
+ It is primarily for use by tools such as Prooftree that need to fetch
+ goal history in this way. Prooftree is a tool for visualizing a proof
+ as a tree that runs in Proof General.
+
+.. cmd:: Guarded
+
+ Some tactics (e.g. :tacn:`refine`) allow to build proofs using
+ fixpoint or co-fixpoint constructions. Due to the incremental nature
+ of interactive proof construction, the check of the termination (or
+ guardedness) of the recursive calls in the fixpoint or cofixpoint
+ constructions is postponed to the time of the completion of the proof.
+
+ The command :cmd:`Guarded` allows checking if the guard condition for
+ fixpoint and cofixpoint is violated at some time of the construction
+ of the proof without having to wait the completion of the proof.
+
+.. _showing_diffs:
+
+Showing differences between proof steps
+---------------------------------------
+
+|Coq| can automatically highlight the differences between successive proof steps
+and between values in some error messages. |Coq| can also highlight differences
+in the proof term.
+For example, the following screenshots of |CoqIDE| and coqtop show the application
+of the same :tacn:`intros` tactic. The tactic creates two new hypotheses, highlighted in green.
+The conclusion is entirely in pale green because although it’s changed, no tokens were added
+to it. The second screenshot uses the "removed" option, so it shows the conclusion a
+second time with the old text, with deletions marked in red. Also, since the hypotheses are
+new, no line of old text is shown for them.
+
+.. comment screenshot produced with:
+ Inductive ev : nat -> Prop :=
+ | ev_0 : ev 0
+ | ev_SS : forall n : nat, ev n -> ev (S (S n)).
+
+ Fixpoint double (n:nat) :=
+ match n with
+ | O => O
+ | S n' => S (S (double n'))
+ end.
+
+ Goal forall n, ev n -> exists k, n = double k.
+ intros n E.
+
+..
+
+ .. image:: ../../_static/diffs-coqide-on.png
+ :alt: |CoqIDE| with Set Diffs on
+
+..
+
+ .. image:: ../../_static/diffs-coqide-removed.png
+ :alt: |CoqIDE| with Set Diffs removed
+
+..
+
+ .. image:: ../../_static/diffs-coqtop-on3.png
+ :alt: coqtop with Set Diffs on
+
+This image shows an error message with diff highlighting in |CoqIDE|:
+
+..
+
+ .. image:: ../../_static/diffs-error-message.png
+ :alt: |CoqIDE| error message with diffs
+
+How to enable diffs
+```````````````````
+
+.. opt:: Diffs {| "on" | "off" | "removed" }
+ :name: Diffs
+
+ The “on” setting highlights added tokens in green, while the “removed” setting
+ additionally reprints items with removed tokens in red. Unchanged tokens in
+ modified items are shown with pale green or red. Diffs in error messages
+ use red and green for the compared values; they appear regardless of the setting.
+ (Colors are user-configurable.)
+
+For coqtop, showing diffs can be enabled when starting coqtop with the
+``-diffs on|off|removed`` command-line option or by setting the :opt:`Diffs` option
+within |Coq|. You will need to provide the ``-color on|auto`` command-line option when
+you start coqtop in either case.
+
+Colors for coqtop can be configured by setting the ``COQ_COLORS`` environment
+variable. See section :ref:`customization-by-environment-variables`. Diffs
+use the tags ``diff.added``, ``diff.added.bg``, ``diff.removed`` and ``diff.removed.bg``.
+
+In |CoqIDE|, diffs should be enabled from the ``View`` menu. Don’t use the ``Set Diffs``
+command in |CoqIDE|. You can change the background colors shown for diffs from the
+``Edit | Preferences | Tags`` panel by changing the settings for the ``diff.added``,
+``diff.added.bg``, ``diff.removed`` and ``diff.removed.bg`` tags. This panel also
+lets you control other attributes of the highlights, such as the foreground
+color, bold, italic, underline and strikeout.
+
+Proof General can also display |Coq|-generated proof diffs automatically.
+Please see the PG documentation section
+"`Showing Proof Diffs" <https://proofgeneral.github.io/doc/master/userman/Coq-Proof-General#Showing-Proof-Diffs>`_)
+for details.
+
+How diffs are calculated
+````````````````````````
+
+Diffs are calculated as follows:
+
+1. Select the old proof state to compare to, which is the proof state before
+ the last tactic that changed the proof. Changes that only affect the view
+ of the proof, such as ``all: swap 1 2``, are ignored.
+
+2. For each goal in the new proof state, determine what old goal to compare
+ it to—the one it is derived from or is the same as. Match the hypotheses by
+ name (order is ignored), handling compacted items specially.
+
+3. For each hypothesis and conclusion (the “items”) in each goal, pass
+ them as strings to the lexer to break them into tokens. Then apply the
+ Myers diff algorithm :cite:`Myers` on the tokens and add appropriate highlighting.
+
+Notes:
+
+* Aside from the highlights, output for the "on" option should be identical
+ to the undiffed output.
+* Goals completed in the last proof step will not be shown even with the
+ "removed" setting.
+
+.. comment The following screenshots show diffs working with multiple goals and with compacted
+ hypotheses. In the first one, notice that the goal ``P 1`` is not highlighted at
+ all after the split because it has not changed.
+
+ .. todo: Use this script and remove the screenshots when COQ_COLORS
+ works for coqtop in sphinx
+ .. coqtop:: none
+
+ Set Diffs "on".
+ Parameter P : nat -> Prop.
+ Goal P 1 /\ P 2 /\ P 3.
+
+ .. coqtop:: out
+
+ split.
+
+ .. coqtop:: all abort
+
+ 2: split.
+
+ ..
+
+ .. coqtop:: none
+
+ Set Diffs "on".
+ Goal forall n m : nat, n + m = m + n.
+ Set Diffs "on".
+
+ .. coqtop:: out
+
+ intros n.
+
+ .. coqtop:: all abort
+
+ intros m.
+
+This screen shot shows the result of applying a :tacn:`split` tactic that replaces one goal
+with 2 goals. Notice that the goal ``P 1`` is not highlighted at all after
+the split because it has not changed.
+
+..
+
+ .. image:: ../../_static/diffs-coqide-multigoal.png
+ :alt: coqide with Set Diffs on with multiple goals
+
+Diffs may appear like this after applying a :tacn:`intro` tactic that results
+in a compacted hypotheses:
+
+..
+
+ .. image:: ../../_static/diffs-coqide-compacted.png
+ :alt: coqide with Set Diffs on with compacted hypotheses
+
+.. _showing_proof_diffs:
+
+"Show Proof" differences
+````````````````````````
+
+To show differences in the proof term:
+
+- In coqtop and Proof General, use the :cmd:`Show Proof` `Diffs` command.
+
+- In |CoqIDE|, position the cursor on or just after a tactic to compare the proof term
+ after the tactic with the proof term before the tactic, then select
+ `View / Show Proof` from the menu or enter the associated key binding.
+ Differences will be shown applying the current `Show Diffs` setting
+ from the `View` menu. If the current setting is `Don't show diffs`, diffs
+ will not be shown.
+
+ Output with the "added and removed" option looks like this:
+
+ ..
+
+ .. image:: ../../_static/diffs-show-proof.png
+ :alt: coqide with Set Diffs on with compacted hypotheses
+
+Controlling the effect of proof editing commands
+------------------------------------------------
+
+
+.. opt:: Hyps Limit @natural
+ :name: Hyps Limit
+
+ This option controls the maximum number of hypotheses displayed in goals
+ after the application of a tactic. All the hypotheses remain usable
+ in the proof development.
+ When unset, it goes back to the default mode which is to print all
+ available hypotheses.
+
+
+.. flag:: Nested Proofs Allowed
+
+ When turned on (it is off by default), this flag enables support for nested
+ proofs: a new assertion command can be inserted before the current proof is
+ finished, in which case |Coq| will temporarily switch to the proof of this
+ *nested lemma*. When the proof of the nested lemma is finished (with :cmd:`Qed`
+ or :cmd:`Defined`), its statement will be made available (as if it had been
+ proved before starting the previous proof) and |Coq| will switch back to the
+ proof of the previous assertion.
+
+.. flag:: Printing Goal Names
+
+ When turned on, the name of the goal is printed in interactive
+ proof mode, which can be useful in cases of cross references
+ between goals.
+
+Controlling memory usage
+------------------------
+
+.. cmd:: Print Debug GC
+
+ Prints heap usage statistics, which are values from the `stat` type of the `Gc` module
+ described
+ `here <https://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html#TYPEstat>`_
+ in the |OCaml| documentation.
+ The `live_words`, `heap_words` and `top_heap_words` values give the basic information.
+ Words are 8 bytes or 4 bytes, respectively, for 64- and 32-bit executables.
+
+When experiencing high memory usage the following commands can be used
+to force |Coq| to optimize some of its internal data structures.
+
+.. cmd:: Optimize Proof
+
+ Shrink the data structure used to represent the current proof.
+
+
+.. cmd:: Optimize Heap
+
+ Perform a heap compaction. This is generally an expensive operation.
+ See: `|OCaml| Gc.compact <http://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html#VALcompact>`_
+ There is also an analogous tactic :tacn:`optimize_heap`.
+
+Memory usage parameters can be set through the :ref:`OCAMLRUNPARAM <OCAMLRUNPARAM>`
+environment variable.
diff --git a/doc/sphinx/proofs/writing-proofs/rewriting.rst b/doc/sphinx/proofs/writing-proofs/rewriting.rst
new file mode 100644
index 0000000000..1358aad432
--- /dev/null
+++ b/doc/sphinx/proofs/writing-proofs/rewriting.rst
@@ -0,0 +1,857 @@
+=================================
+Term rewriting and simplification
+=================================
+
+.. _rewritingexpressions:
+
+Rewriting expressions
+---------------------
+
+These tactics use the equality :g:`eq:forall A:Type, A->A->Prop` defined in
+file ``Logic.v`` (see :ref:`coq-library-logic`). The notation for :g:`eq T t u` is
+simply :g:`t=u` dropping the implicit type of :g:`t` and :g:`u`.
+
+.. tacn:: rewrite @term
+ :name: rewrite
+
+ This tactic applies to any goal. The type of :token:`term` must have the form
+
+ ``forall (x``:sub:`1` ``:A``:sub:`1` ``) ... (x``:sub:`n` ``:A``:sub:`n` ``), eq term``:sub:`1` ``term``:sub:`2` ``.``
+
+ where :g:`eq` is the Leibniz equality or a registered setoid equality.
+
+ Then :n:`rewrite @term` finds the first subterm matching `term`\ :sub:`1` in the goal,
+ resulting in instances `term`:sub:`1`' and `term`:sub:`2`' and then
+ replaces every occurrence of `term`:subscript:`1`' by `term`:subscript:`2`'.
+ Hence, some of the variables :g:`x`\ :sub:`i` are solved by unification,
+ and some of the types :g:`A`\ :sub:`1`:g:`, ..., A`\ :sub:`n` become new
+ subgoals.
+
+ .. exn:: The @term provided does not end with an equation.
+ :undocumented:
+
+ .. exn:: Tactic generated a subgoal identical to the original goal. This happens if @term does not occur in the goal.
+ :undocumented:
+
+ .. tacv:: rewrite -> @term
+
+ Is equivalent to :n:`rewrite @term`
+
+ .. tacv:: rewrite <- @term
+
+ Uses the equality :n:`@term`:sub:`1` :n:`= @term` :sub:`2` from right to left
+
+ .. tacv:: rewrite @term in @goal_occurrences
+
+ Analogous to :n:`rewrite @term` but rewriting is done following
+ the clause :token:`goal_occurrences`. For instance:
+
+ + :n:`rewrite H in H'` will rewrite `H` in the hypothesis
+ ``H'`` instead of the current goal.
+ + :n:`rewrite H in H' at 1, H'' at - 2 |- *` means
+ :n:`rewrite H; rewrite H in H' at 1; rewrite H in H'' at - 2.`
+ In particular a failure will happen if any of these three simpler tactics
+ fails.
+ + :n:`rewrite H in * |-` will do :n:`rewrite H in H'` for all hypotheses
+ :g:`H'` different from :g:`H`.
+ A success will happen as soon as at least one of these simpler tactics succeeds.
+ + :n:`rewrite H in *` is a combination of :n:`rewrite H` and :n:`rewrite H in * |-`
+ that succeeds if at least one of these two tactics succeeds.
+
+ Orientation :g:`->` or :g:`<-` can be inserted before the :token:`term` to rewrite.
+
+ .. tacv:: rewrite @term at @occurrences
+
+ Rewrite only the given :token:`occurrences` of :token:`term`. Occurrences are
+ specified from left to right as for pattern (:tacn:`pattern`). The rewrite is
+ always performed using setoid rewriting, even for Leibniz’s equality, so one
+ has to ``Import Setoid`` to use this variant.
+
+ .. tacv:: rewrite @term by @tactic
+
+ Use tactic to completely solve the side-conditions arising from the
+ :tacn:`rewrite`.
+
+ .. tacv:: rewrite {+, @orientation @term} {? in @ident }
+
+ Is equivalent to the `n` successive tactics :n:`{+; rewrite @term}`, each one
+ working on the first subgoal generated by the previous one. An :production:`orientation`
+ ``->`` or ``<-`` can be inserted before each :token:`term` to rewrite. One
+ unique clause can be added at the end after the keyword in; it will then
+ affect all rewrite operations.
+
+ In all forms of rewrite described above, a :token:`term` to rewrite can be
+ immediately prefixed by one of the following modifiers:
+
+ + `?` : the tactic :n:`rewrite ?@term` performs the rewrite of :token:`term` as many
+ times as possible (perhaps zero time). This form never fails.
+ + :n:`@natural?` : works similarly, except that it will do at most :token:`natural` rewrites.
+ + `!` : works as `?`, except that at least one rewrite should succeed, otherwise
+ the tactic fails.
+ + :n:`@natural!` (or simply :n:`@natural`) : precisely :token:`natural` rewrites of :token:`term` will be done,
+ leading to failure if these :token:`natural` rewrites are not possible.
+
+ .. tacv:: erewrite @term
+ :name: erewrite
+
+ This tactic works as :n:`rewrite @term` but turning
+ unresolved bindings into existential variables, if any, instead of
+ failing. It has the same variants as :tacn:`rewrite` has.
+
+ .. flag:: Keyed Unification
+
+ Makes higher-order unification used by :tacn:`rewrite` rely on a set of keys to drive
+ unification. The subterms, considered as rewriting candidates, must start with
+ the same key as the left- or right-hand side of the lemma given to rewrite, and the arguments
+ are then unified up to full reduction.
+
+.. tacn:: replace @term with @term’
+ :name: replace
+
+ This tactic applies to any goal. It replaces all free occurrences of :n:`@term`
+ in the current goal with :n:`@term’` and generates an equality :n:`@term = @term’`
+ as a subgoal. This equality is automatically solved if it occurs among
+ the assumptions, or if its symmetric form occurs. It is equivalent to
+ :n:`cut @term = @term’; [intro H`:sub:`n` :n:`; rewrite <- H`:sub:`n` :n:`; clear H`:sub:`n`:n:`|| assumption || symmetry; try assumption]`.
+
+ .. exn:: Terms do not have convertible types.
+ :undocumented:
+
+ .. tacv:: replace @term with @term’ by @tactic
+
+ This acts as :n:`replace @term with @term’` but applies :token:`tactic` to solve the generated
+ subgoal :n:`@term = @term’`.
+
+ .. tacv:: replace @term
+
+ Replaces :n:`@term` with :n:`@term’` using the first assumption whose type has
+ the form :n:`@term = @term’` or :n:`@term’ = @term`.
+
+ .. tacv:: replace -> @term
+
+ Replaces :n:`@term` with :n:`@term’` using the first assumption whose type has
+ the form :n:`@term = @term’`
+
+ .. tacv:: replace <- @term
+
+ Replaces :n:`@term` with :n:`@term’` using the first assumption whose type has
+ the form :n:`@term’ = @term`
+
+ .. tacv:: replace @term {? with @term} in @goal_occurrences {? by @tactic}
+ replace -> @term in @goal_occurrences
+ replace <- @term in @goal_occurrences
+
+ Acts as before but the replacements take place in the specified clauses
+ (:token:`goal_occurrences`) (see :ref:`performingcomputations`) and not
+ only in the conclusion of the goal. The clause argument must not contain
+ any ``type of`` nor ``value of``.
+
+.. tacn:: subst @ident
+ :name: subst
+
+ This tactic applies to a goal that has :n:`@ident` in its context and (at
+ least) one hypothesis, say :g:`H`, of type :n:`@ident = t` or :n:`t = @ident`
+ with :n:`@ident` not occurring in :g:`t`. Then it replaces :n:`@ident` by
+ :g:`t` everywhere in the goal (in the hypotheses and in the conclusion) and
+ clears :n:`@ident` and :g:`H` from the context.
+
+ If :n:`@ident` is a local definition of the form :n:`@ident := t`, it is also
+ unfolded and cleared.
+
+ If :n:`@ident` is a section variable it is expected to have no
+ indirect occurrences in the goal, i.e. that no global declarations
+ implicitly depending on the section variable must be present in the
+ goal.
+
+ .. note::
+ + When several hypotheses have the form :n:`@ident = t` or :n:`t = @ident`, the
+ first one is used.
+
+ + If :g:`H` is itself dependent in the goal, it is replaced by the proof of
+ reflexivity of equality.
+
+ .. tacv:: subst {+ @ident}
+
+ This is equivalent to :n:`subst @ident`:sub:`1`:n:`; ...; subst @ident`:sub:`n`.
+
+ .. tacv:: subst
+
+ This applies :tacn:`subst` repeatedly from top to bottom to all hypotheses of the
+ context for which an equality of the form :n:`@ident = t` or :n:`t = @ident`
+ or :n:`@ident := t` exists, with :n:`@ident` not occurring in
+ ``t`` and :n:`@ident` not a section variable with indirect
+ dependencies in the goal.
+
+ .. flag:: Regular Subst Tactic
+
+ This flag controls the behavior of :tacn:`subst`. When it is
+ activated (it is by default), :tacn:`subst` also deals with the following corner cases:
+
+ + A context with ordered hypotheses :n:`@ident`:sub:`1` :n:`= @ident`:sub:`2`
+ and :n:`@ident`:sub:`1` :n:`= t`, or :n:`t′ = @ident`:sub:`1`` with `t′` not
+ a variable, and no other hypotheses of the form :n:`@ident`:sub:`2` :n:`= u`
+ or :n:`u = @ident`:sub:`2`; without the flag, a second call to
+ subst would be necessary to replace :n:`@ident`:sub:`2` by `t` or
+ `t′` respectively.
+ + The presence of a recursive equation which without the flag would
+ be a cause of failure of :tacn:`subst`.
+ + A context with cyclic dependencies as with hypotheses :n:`@ident`:sub:`1` :n:`= f @ident`:sub:`2`
+ and :n:`@ident`:sub:`2` :n:`= g @ident`:sub:`1` which without the
+ flag would be a cause of failure of :tacn:`subst`.
+
+ Additionally, it prevents a local definition such as :n:`@ident := t` to be
+ unfolded which otherwise it would exceptionally unfold in configurations
+ containing hypotheses of the form :n:`@ident = u`, or :n:`u′ = @ident`
+ with `u′` not a variable. Finally, it preserves the initial order of
+ hypotheses, which without the flag it may break.
+ default.
+
+ .. exn:: Cannot find any non-recursive equality over :n:`@ident`.
+ :undocumented:
+
+ .. exn:: Section variable :n:`@ident` occurs implicitly in global declaration :n:`@qualid` present in hypothesis :n:`@ident`.
+ Section variable :n:`@ident` occurs implicitly in global declaration :n:`@qualid` present in the conclusion.
+
+ Raised when the variable is a section variable with indirect
+ dependencies in the goal.
+
+
+.. tacn:: stepl @term
+ :name: stepl
+
+ This tactic is for chaining rewriting steps. It assumes a goal of the
+ form :n:`R @term @term` where ``R`` is a binary relation and relies on a
+ database of lemmas of the form :g:`forall x y z, R x y -> eq x z -> R z y`
+ where `eq` is typically a setoid equality. The application of :n:`stepl @term`
+ then replaces the goal by :n:`R @term @term` and adds a new goal stating
+ :n:`eq @term @term`.
+
+ .. cmd:: Declare Left Step @term
+
+ Adds :n:`@term` to the database used by :tacn:`stepl`.
+
+ This tactic is especially useful for parametric setoids which are not accepted
+ as regular setoids for :tacn:`rewrite` and :tacn:`setoid_replace` (see
+ :ref:`Generalizedrewriting`).
+
+ .. tacv:: stepl @term by @tactic
+
+ This applies :n:`stepl @term` then applies :token:`tactic` to the second goal.
+
+ .. tacv:: stepr @term by @tactic
+ :name: stepr
+
+ This behaves as :tacn:`stepl` but on the right-hand-side of the binary
+ relation. Lemmas are expected to be of the form
+ :g:`forall x y z, R x y -> eq y z -> R x z`.
+
+ .. cmd:: Declare Right Step @term
+
+ Adds :n:`@term` to the database used by :tacn:`stepr`.
+
+
+.. tacn:: change @term
+ :name: change
+
+ This tactic applies to any goal. It implements the rule ``Conv`` given in
+ :ref:`subtyping-rules`. :g:`change U` replaces the current goal `T`
+ with `U` providing that `U` is well-formed and that `T` and `U` are
+ convertible.
+
+ .. exn:: Not convertible.
+ :undocumented:
+
+ .. tacv:: change @term with @term’
+
+ This replaces the occurrences of :n:`@term` by :n:`@term’` in the current goal.
+ The term :n:`@term` and :n:`@term’` must be convertible.
+
+ .. tacv:: change @term at {+ @natural} with @term’
+
+ This replaces the occurrences numbered :n:`{+ @natural}` of :n:`@term` by :n:`@term’`
+ in the current goal. The terms :n:`@term` and :n:`@term’` must be convertible.
+
+ .. exn:: Too few occurrences.
+ :undocumented:
+
+ .. tacv:: change @term {? {? at {+ @natural}} with @term} in @ident
+
+ This applies the :tacn:`change` tactic not to the goal but to the hypothesis :n:`@ident`.
+
+ .. tacv:: now_show @term
+
+ This is a synonym of :n:`change @term`. It can be used to
+ make some proof steps explicit when refactoring a proof script
+ to make it readable.
+
+ .. seealso:: :ref:`Performing computations <performingcomputations>`
+
+.. _performingcomputations:
+
+Performing computations
+---------------------------
+
+.. insertprodn red_expr pattern_occ
+
+.. prodn::
+ red_expr ::= red
+ | hnf
+ | simpl {? @delta_flag } {? @ref_or_pattern_occ }
+ | cbv {? @strategy_flag }
+ | cbn {? @strategy_flag }
+ | lazy {? @strategy_flag }
+ | compute {? @delta_flag }
+ | vm_compute {? @ref_or_pattern_occ }
+ | native_compute {? @ref_or_pattern_occ }
+ | unfold {+, @unfold_occ }
+ | fold {+ @one_term }
+ | pattern {+, @pattern_occ }
+ | @ident
+ delta_flag ::= {? - } [ {+ @reference } ]
+ strategy_flag ::= {+ @red_flag }
+ | @delta_flag
+ red_flag ::= beta
+ | iota
+ | match
+ | fix
+ | cofix
+ | zeta
+ | delta {? @delta_flag }
+ ref_or_pattern_occ ::= @reference {? at @occs_nums }
+ | @one_term {? at @occs_nums }
+ occs_nums ::= {+ {| @natural | @ident } }
+ | - {| @natural | @ident } {* @int_or_var }
+ int_or_var ::= @integer
+ | @ident
+ unfold_occ ::= @reference {? at @occs_nums }
+ pattern_occ ::= @one_term {? at @occs_nums }
+
+This set of tactics implements different specialized usages of the
+tactic :tacn:`change`.
+
+All conversion tactics (including :tacn:`change`) can be parameterized by the
+parts of the goal where the conversion can occur. This is done using
+*goal clauses* which consists in a list of hypotheses and, optionally,
+of a reference to the conclusion of the goal. For defined hypothesis
+it is possible to specify if the conversion should occur on the type
+part, the body part or both (default).
+
+Goal clauses are written after a conversion tactic (tactics :tacn:`set`,
+:tacn:`rewrite`, :tacn:`replace` and :tacn:`autorewrite` also use goal
+clauses) and are introduced by the keyword `in`. If no goal clause is
+provided, the default is to perform the conversion only in the
+conclusion.
+
+The syntax and description of the various goal clauses is the
+following:
+
++ :n:`in {+ @ident} |-` only in hypotheses :n:`{+ @ident}`
++ :n:`in {+ @ident} |- *` in hypotheses :n:`{+ @ident}` and in the
+ conclusion
++ :n:`in * |-` in every hypothesis
++ :n:`in *` (equivalent to in :n:`* |- *`) everywhere
++ :n:`in (type of @ident) (value of @ident) ... |-` in type part of
+ :n:`@ident`, in the value part of :n:`@ident`, etc.
+
+For backward compatibility, the notation :n:`in {+ @ident}` performs
+the conversion in hypotheses :n:`{+ @ident}`.
+
+.. tacn:: cbv {? @strategy_flag }
+ lazy {? @strategy_flag }
+ :name: cbv; lazy
+
+ These parameterized reduction tactics apply to any goal and perform
+ the normalization of the goal according to the specified flags. In
+ correspondence with the kinds of reduction considered in |Coq| namely
+ :math:`\beta` (reduction of functional application), :math:`\delta`
+ (unfolding of transparent constants, see :ref:`vernac-controlling-the-reduction-strategies`),
+ :math:`\iota` (reduction of
+ pattern matching over a constructed term, and unfolding of :g:`fix` and
+ :g:`cofix` expressions) and :math:`\zeta` (contraction of local definitions), the
+ flags are either ``beta``, ``delta``, ``match``, ``fix``, ``cofix``,
+ ``iota`` or ``zeta``. The ``iota`` flag is a shorthand for ``match``, ``fix``
+ and ``cofix``. The ``delta`` flag itself can be refined into
+ :n:`delta [ {+ @qualid} ]` or :n:`delta - [ {+ @qualid} ]`, restricting in the first
+ case the constants to unfold to the constants listed, and restricting in the
+ second case the constant to unfold to all but the ones explicitly mentioned.
+ Notice that the ``delta`` flag does not apply to variables bound by a let-in
+ construction inside the :n:`@term` itself (use here the ``zeta`` flag). In
+ any cases, opaque constants are not unfolded (see :ref:`vernac-controlling-the-reduction-strategies`).
+
+ Normalization according to the flags is done by first evaluating the
+ head of the expression into a *weak-head* normal form, i.e. until the
+ evaluation is blocked by a variable (or an opaque constant, or an
+ axiom), as e.g. in :g:`x u1 ... un` , or :g:`match x with ... end`, or
+ :g:`(fix f x {struct x} := ...) x`, or is a constructed form (a
+ :math:`\lambda`-expression, a constructor, a cofixpoint, an inductive type, a
+ product type, a sort), or is a redex that the flags prevent to reduce. Once a
+ weak-head normal form is obtained, subterms are recursively reduced using the
+ same strategy.
+
+ Reduction to weak-head normal form can be done using two strategies:
+ *lazy* (``lazy`` tactic), or *call-by-value* (``cbv`` tactic). The lazy
+ strategy is a call-by-need strategy, with sharing of reductions: the
+ arguments of a function call are weakly evaluated only when necessary,
+ and if an argument is used several times then it is weakly computed
+ only once. This reduction is efficient for reducing expressions with
+ dead code. For instance, the proofs of a proposition :g:`exists x. P(x)`
+ reduce to a pair of a witness :g:`t`, and a proof that :g:`t` satisfies the
+ predicate :g:`P`. Most of the time, :g:`t` may be computed without computing
+ the proof of :g:`P(t)`, thanks to the lazy strategy.
+
+ The call-by-value strategy is the one used in ML languages: the
+ arguments of a function call are systematically weakly evaluated
+ first. Despite the lazy strategy always performs fewer reductions than
+ the call-by-value strategy, the latter is generally more efficient for
+ evaluating purely computational expressions (i.e. with little dead code).
+
+.. tacv:: compute
+ cbv
+ :name: compute; _
+
+ These are synonyms for ``cbv beta delta iota zeta``.
+
+.. tacv:: lazy
+
+ This is a synonym for ``lazy beta delta iota zeta``.
+
+.. tacv:: compute [ {+ @qualid} ]
+ cbv [ {+ @qualid} ]
+
+ These are synonyms of :n:`cbv beta delta {+ @qualid} iota zeta`.
+
+.. tacv:: compute - [ {+ @qualid} ]
+ cbv - [ {+ @qualid} ]
+
+ These are synonyms of :n:`cbv beta delta -{+ @qualid} iota zeta`.
+
+.. tacv:: lazy [ {+ @qualid} ]
+ lazy - [ {+ @qualid} ]
+
+ These are respectively synonyms of :n:`lazy beta delta {+ @qualid} iota zeta`
+ and :n:`lazy beta delta -{+ @qualid} iota zeta`.
+
+.. tacv:: vm_compute
+ :name: vm_compute
+
+ This tactic evaluates the goal using the optimized call-by-value evaluation
+ bytecode-based virtual machine described in :cite:`CompiledStrongReduction`.
+ This algorithm is dramatically more efficient than the algorithm used for the
+ :tacn:`cbv` tactic, but it cannot be fine-tuned. It is especially interesting for
+ full evaluation of algebraic objects. This includes the case of
+ reflection-based tactics.
+
+.. tacv:: native_compute
+ :name: native_compute
+
+ This tactic evaluates the goal by compilation to |OCaml| as described
+ in :cite:`FullReduction`. If |Coq| is running in native code, it can be
+ typically two to five times faster than :tacn:`vm_compute`. Note however that the
+ compilation cost is higher, so it is worth using only for intensive
+ computations.
+
+ .. flag:: NativeCompute Timing
+
+ This flag causes all calls to the native compiler to print
+ timing information for the conversion to native code,
+ compilation, execution, and reification phases of native
+ compilation. Timing is printed in units of seconds of
+ wall-clock time.
+
+ .. flag:: NativeCompute Profiling
+
+ On Linux, if you have the ``perf`` profiler installed, this flag makes
+ it possible to profile :tacn:`native_compute` evaluations.
+
+ .. opt:: NativeCompute Profile Filename @string
+ :name: NativeCompute Profile Filename
+
+ This option specifies the profile output; the default is
+ ``native_compute_profile.data``. The actual filename used
+ will contain extra characters to avoid overwriting an existing file; that
+ filename is reported to the user.
+ That means you can individually profile multiple uses of
+ :tacn:`native_compute` in a script. From the Linux command line, run ``perf report``
+ on the profile file to see the results. Consult the ``perf`` documentation
+ for more details.
+
+.. flag:: Debug Cbv
+
+ This flag makes :tacn:`cbv` (and its derivative :tacn:`compute`) print
+ information about the constants it encounters and the unfolding decisions it
+ makes.
+
+.. tacn:: red
+ :name: red
+
+ This tactic applies to a goal that has the form::
+
+ forall (x:T1) ... (xk:Tk), T
+
+ with :g:`T` :math:`\beta`:math:`\iota`:math:`\zeta`-reducing to :g:`c t`:sub:`1` :g:`... t`:sub:`n` and :g:`c` a
+ constant. If :g:`c` is transparent then it replaces :g:`c` with its
+ definition (say :g:`t`) and then reduces
+ :g:`(t t`:sub:`1` :g:`... t`:sub:`n` :g:`)` according to :math:`\beta`:math:`\iota`:math:`\zeta`-reduction rules.
+
+.. exn:: Not reducible.
+ :undocumented:
+
+.. exn:: No head constant to reduce.
+ :undocumented:
+
+.. tacn:: hnf
+ :name: hnf
+
+ This tactic applies to any goal. It replaces the current goal with its
+ head normal form according to the :math:`\beta`:math:`\delta`:math:`\iota`:math:`\zeta`-reduction rules, i.e. it
+ reduces the head of the goal until it becomes a product or an
+ irreducible term. All inner :math:`\beta`:math:`\iota`-redexes are also reduced.
+ The behavior of both :tacn:`hnf` can be tuned using the :cmd:`Arguments` command.
+
+ Example: The term :g:`fun n : nat => S n + S n` is not reduced by :n:`hnf`.
+
+.. note::
+ The :math:`\delta` rule only applies to transparent constants (see :ref:`vernac-controlling-the-reduction-strategies`
+ on transparency and opacity).
+
+.. tacn:: cbn
+ simpl
+ :name: cbn; simpl
+
+ These tactics apply to any goal. They try to reduce a term to
+ something still readable instead of fully normalizing it. They perform
+ a sort of strong normalization with two key differences:
+
+ + They unfold a constant if and only if it leads to a :math:`\iota`-reduction,
+ i.e. reducing a match or unfolding a fixpoint.
+ + While reducing a constant unfolding to (co)fixpoints, the tactics
+ use the name of the constant the (co)fixpoint comes from instead of
+ the (co)fixpoint definition in recursive calls.
+
+ The :tacn:`cbn` tactic is claimed to be a more principled, faster and more
+ predictable replacement for :tacn:`simpl`.
+
+ The :tacn:`cbn` tactic accepts the same flags as :tacn:`cbv` and
+ :tacn:`lazy`. The behavior of both :tacn:`simpl` and :tacn:`cbn`
+ can be tuned using the :cmd:`Arguments` command.
+
+ .. todo add "See <subsection about controlling the behavior of reduction strategies>"
+ to TBA section
+
+ Notice that only transparent constants whose name can be reused in the
+ recursive calls are possibly unfolded by :tacn:`simpl`. For instance a
+ constant defined by :g:`plus' := plus` is possibly unfolded and reused in
+ the recursive calls, but a constant such as :g:`succ := plus (S O)` is
+ never unfolded. This is the main difference between :tacn:`simpl` and :tacn:`cbn`.
+ The tactic :tacn:`cbn` reduces whenever it will be able to reuse it or not:
+ :g:`succ t` is reduced to :g:`S t`.
+
+.. tacv:: cbn [ {+ @qualid} ]
+ cbn - [ {+ @qualid} ]
+
+ These are respectively synonyms of :n:`cbn beta delta [ {+ @qualid} ] iota zeta`
+ and :n:`cbn beta delta - [ {+ @qualid} ] iota zeta` (see :tacn:`cbn`).
+
+.. tacv:: simpl @pattern
+
+ This applies :tacn:`simpl` only to the subterms matching
+ :n:`@pattern` in the current goal.
+
+.. tacv:: simpl @pattern at {+ @natural}
+
+ This applies :tacn:`simpl` only to the :n:`{+ @natural}` occurrences of the subterms
+ matching :n:`@pattern` in the current goal.
+
+ .. exn:: Too few occurrences.
+ :undocumented:
+
+.. tacv:: simpl @qualid
+ simpl @string
+
+ This applies :tacn:`simpl` only to the applicative subterms whose head occurrence
+ is the unfoldable constant :n:`@qualid` (the constant can be referred to by
+ its notation using :n:`@string` if such a notation exists).
+
+.. tacv:: simpl @qualid at {+ @natural}
+ simpl @string at {+ @natural}
+
+ This applies :tacn:`simpl` only to the :n:`{+ @natural}` applicative subterms whose
+ head occurrence is :n:`@qualid` (or :n:`@string`).
+
+.. flag:: Debug RAKAM
+
+ This flag makes :tacn:`cbn` print various debugging information.
+ ``RAKAM`` is the Refolding Algebraic Krivine Abstract Machine.
+
+.. tacn:: unfold @qualid
+ :name: unfold
+
+ This tactic applies to any goal. The argument qualid must denote a
+ defined transparent constant or local definition (see
+ :ref:`gallina-definitions` and
+ :ref:`vernac-controlling-the-reduction-strategies`). The tactic
+ :tacn:`unfold` applies the :math:`\delta` rule to each occurrence
+ of the constant to which :n:`@qualid` refers in the current goal
+ and then replaces it with its :math:`\beta\iota\zeta`-normal form.
+ Use the general reduction tactics if you want to avoid this final
+ reduction, for instance :n:`cbv delta [@qualid]`.
+
+ .. exn:: Cannot coerce @qualid to an evaluable reference.
+
+ This error is frequent when trying to unfold something that has
+ defined as an inductive type (or constructor) and not as a
+ definition.
+
+ .. example::
+
+ .. coqtop:: abort all fail
+
+ Goal 0 <= 1.
+ unfold le.
+
+ This error can also be raised if you are trying to unfold
+ something that has been marked as opaque.
+
+ .. example::
+
+ .. coqtop:: abort all fail
+
+ Opaque Nat.add.
+ Goal 1 + 0 = 1.
+ unfold Nat.add.
+
+ .. tacv:: unfold @qualid in @goal_occurrences
+
+ Replaces :n:`@qualid` in hypothesis (or hypotheses) designated
+ by :token:`goal_occurrences` with its definition and replaces
+ the hypothesis with its :math:`\beta`:math:`\iota` normal form.
+
+ .. tacv:: unfold {+, @qualid}
+
+ Replaces :n:`{+, @qualid}` with their definitions and replaces
+ the current goal with its :math:`\beta`:math:`\iota` normal
+ form.
+
+ .. tacv:: unfold {+, @qualid at @occurrences }
+
+ The list :token:`occurrences` specify the occurrences of
+ :n:`@qualid` to be unfolded. Occurrences are located from left
+ to right.
+
+ .. exn:: Bad occurrence number of @qualid.
+ :undocumented:
+
+ .. exn:: @qualid does not occur.
+ :undocumented:
+
+ .. tacv:: unfold @string
+
+ If :n:`@string` denotes the discriminating symbol of a notation
+ (e.g. "+") or an expression defining a notation (e.g. `"_ +
+ _"`), and this notation denotes an application whose head symbol
+ is an unfoldable constant, then the tactic unfolds it.
+
+ .. tacv:: unfold @string%@ident
+
+ This is variant of :n:`unfold @string` where :n:`@string` gets
+ its interpretation from the scope bound to the delimiting key
+ :token:`ident` instead of its default interpretation (see
+ :ref:`Localinterpretationrulesfornotations`).
+
+ .. tacv:: unfold {+, {| @qualid | @string{? %@ident } } {? at @occurrences } } {? in @goal_occurrences }
+
+ This is the most general form.
+
+.. tacn:: fold @term
+ :name: fold
+
+ This tactic applies to any goal. The term :n:`@term` is reduced using the
+ :tacn:`red` tactic. Every occurrence of the resulting :n:`@term` in the goal is
+ then replaced by :n:`@term`. This tactic is particularly useful when a fixpoint
+ definition has been wrongfully unfolded, making the goal very hard to read.
+ On the other hand, when an unfolded function applied to its argument has been
+ reduced, the :tacn:`fold` tactic won't do anything.
+
+ .. example::
+
+ .. coqtop:: all abort
+
+ Goal ~0=0.
+ unfold not.
+ Fail progress fold not.
+ pattern (0 = 0).
+ fold not.
+
+ .. tacv:: fold {+ @term}
+
+ Equivalent to :n:`fold @term ; ... ; fold @term`.
+
+.. tacn:: pattern @term
+ :name: pattern
+
+ This command applies to any goal. The argument :n:`@term` must be a free
+ subterm of the current goal. The command pattern performs :math:`\beta`-expansion
+ (the inverse of :math:`\beta`-reduction) of the current goal (say :g:`T`) by
+
+ + replacing all occurrences of :n:`@term` in :g:`T` with a fresh variable
+ + abstracting this variable
+ + applying the abstracted goal to :n:`@term`
+
+ For instance, if the current goal :g:`T` is expressible as
+ :math:`\varphi`:g:`(t)` where the notation captures all the instances of :g:`t`
+ in :math:`\varphi`:g:`(t)`, then :n:`pattern t` transforms it into
+ :g:`(fun x:A =>` :math:`\varphi`:g:`(x)) t`. This tactic can be used, for
+ instance, when the tactic ``apply`` fails on matching.
+
+.. tacv:: pattern @term at {+ @natural}
+
+ Only the occurrences :n:`{+ @natural}` of :n:`@term` are considered for
+ :math:`\beta`-expansion. Occurrences are located from left to right.
+
+.. tacv:: pattern @term at - {+ @natural}
+
+ All occurrences except the occurrences of indexes :n:`{+ @natural }`
+ of :n:`@term` are considered for :math:`\beta`-expansion. Occurrences are located from
+ left to right.
+
+.. tacv:: pattern {+, @term}
+
+ Starting from a goal :math:`\varphi`:g:`(t`:sub:`1` :g:`... t`:sub:`m`:g:`)`,
+ the tactic :n:`pattern t`:sub:`1`:n:`, ..., t`:sub:`m` generates the
+ equivalent goal
+ :g:`(fun (x`:sub:`1`:g:`:A`:sub:`1`:g:`) ... (x`:sub:`m` :g:`:A`:sub:`m` :g:`) =>`:math:`\varphi`:g:`(x`:sub:`1` :g:`... x`:sub:`m` :g:`)) t`:sub:`1` :g:`... t`:sub:`m`.
+ If :g:`t`:sub:`i` occurs in one of the generated types :g:`A`:sub:`j` these
+ occurrences will also be considered and possibly abstracted.
+
+.. tacv:: pattern {+, @term at {+ @natural}}
+
+ This behaves as above but processing only the occurrences :n:`{+ @natural}` of
+ :n:`@term` starting from :n:`@term`.
+
+.. tacv:: pattern {+, @term {? at {? -} {+, @natural}}}
+
+ This is the most general syntax that combines the different variants.
+
+.. tacn:: with_strategy @strategy_level_or_var [ {+ @reference } ] @ltac_expr3
+ :name: with_strategy
+
+ Executes :token:`ltac_expr3`, applying the alternate unfolding
+ behavior that the :cmd:`Strategy` command controls, but only for
+ :token:`ltac_expr3`. This can be useful for guarding calls to
+ reduction in tactic automation to ensure that certain constants are
+ never unfolded by tactics like :tacn:`simpl` and :tacn:`cbn` or to
+ ensure that unfolding does not fail.
+
+ .. example::
+
+ .. coqtop:: all reset abort
+
+ Opaque id.
+ Goal id 10 = 10.
+ Fail unfold id.
+ with_strategy transparent [id] unfold id.
+
+ .. warning::
+
+ Use this tactic with care, as effects do not persist past the
+ end of the proof script. Notably, this fine-tuning of the
+ conversion strategy is not in effect during :cmd:`Qed` nor
+ :cmd:`Defined`, so this tactic is most useful either in
+ combination with :tacn:`abstract`, which will check the proof
+ early while the fine-tuning is still in effect, or to guard
+ calls to conversion in tactic automation to ensure that, e.g.,
+ :tacn:`unfold` does not fail just because the user made a
+ constant :cmd:`Opaque`.
+
+ This can be illustrated with the following example involving the
+ factorial function.
+
+ .. coqtop:: in reset
+
+ Fixpoint fact (n : nat) : nat :=
+ match n with
+ | 0 => 1
+ | S n' => n * fact n'
+ end.
+
+ Suppose now that, for whatever reason, we want in general to
+ unfold the :g:`id` function very late during conversion:
+
+ .. coqtop:: in
+
+ Strategy 1000 [id].
+
+ If we try to prove :g:`id (fact n) = fact n` by
+ :tacn:`reflexivity`, it will now take time proportional to
+ :math:`n!`, because |Coq| will keep unfolding :g:`fact` and
+ :g:`*` and :g:`+` before it unfolds :g:`id`, resulting in a full
+ computation of :g:`fact n` (in unary, because we are using
+ :g:`nat`), which takes time :math:`n!`. We can see this cross
+ the relevant threshold at around :math:`n = 9`:
+
+ .. coqtop:: all abort
+
+ Goal True.
+ Time assert (id (fact 8) = fact 8) by reflexivity.
+ Time assert (id (fact 9) = fact 9) by reflexivity.
+
+ Note that behavior will be the same if you mark :g:`id` as
+ :g:`Opaque` because while most reduction tactics refuse to
+ unfold :g:`Opaque` constants, conversion treats :g:`Opaque` as
+ merely a hint to unfold this constant last.
+
+ We can get around this issue by using :tacn:`with_strategy`:
+
+ .. coqtop:: all
+
+ Goal True.
+ Fail Timeout 1 assert (id (fact 100) = fact 100) by reflexivity.
+ Time assert (id (fact 100) = fact 100) by with_strategy -1 [id] reflexivity.
+
+ However, when we go to close the proof, we will run into
+ trouble, because the reduction strategy changes are local to the
+ tactic passed to :tacn:`with_strategy`.
+
+ .. coqtop:: all abort fail
+
+ exact I.
+ Timeout 1 Defined.
+
+ We can fix this issue by using :tacn:`abstract`:
+
+ .. coqtop:: all
+
+ Goal True.
+ Time assert (id (fact 100) = fact 100) by with_strategy -1 [id] abstract reflexivity.
+ exact I.
+ Time Defined.
+
+ On small examples this sort of behavior doesn't matter, but
+ because |Coq| is a super-linear performance domain in so many
+ places, unless great care is taken, tactic automation using
+ :tacn:`with_strategy` may not be robustly performant when
+ scaling the size of the input.
+
+ .. warning::
+
+ In much the same way this tactic does not play well with
+ :cmd:`Qed` and :cmd:`Defined` without using :tacn:`abstract` as
+ an intermediary, this tactic does not play well with ``coqchk``,
+ even when used with :tacn:`abstract`, due to the inability of
+ tactics to persist information about conversion hints in the
+ proof term. See `#12200
+ <https://github.com/coq/coq/issues/12200>`_ for more details.
+
+Conversion tactics applied to hypotheses
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. tacn:: @tactic in {+, @ident}
+
+ Applies :token:`tactic` (any of the conversion tactics listed in this
+ section) to the hypotheses :n:`{+ @ident}`.
+
+ If :token:`ident` is a local definition, then :token:`ident` can be replaced by
+ :n:`type of @ident` to address not the body but the type of the local
+ definition.
+
+ Example: :n:`unfold not in (type of H1) (type of H3)`.
diff --git a/doc/sphinx/user-extensions/proof-schemes.rst b/doc/sphinx/user-extensions/proof-schemes.rst
index 8e23e61018..abecee8459 100644
--- a/doc/sphinx/user-extensions/proof-schemes.rst
+++ b/doc/sphinx/user-extensions/proof-schemes.rst
@@ -8,35 +8,36 @@ Proof schemes
Generation of induction principles with ``Scheme``
--------------------------------------------------------
-The ``Scheme`` command is a high-level tool for generating automatically
-(possibly mutual) induction principles for given types and sorts. Its
-syntax follows the schema:
+.. cmd:: Scheme {? @ident := } @scheme_kind {* with {? @ident := } @scheme_kind }
-.. cmd:: Scheme @ident__1 := Induction for @ident__2 Sort @sort {* with @ident__i := Induction for @ident__j Sort @sort}
+ .. insertprodn scheme_kind sort_family
- This command is a high-level tool for generating automatically
+ .. prodn::
+ scheme_kind ::= Equality for @reference
+ | {| Induction | Minimality | Elimination | Case } for @reference Sort @sort_family
+ sort_family ::= Set
+ | Prop
+ | SProp
+ | Type
+
+ A high-level tool for automatically generating
(possibly mutual) induction principles for given types and sorts.
- Each :n:`@ident__j` is a different inductive type identifier belonging to
+ Each :n:`@reference` is a different inductive type identifier belonging to
the same package of mutual inductive definitions.
- The command generates the :n:`@ident__i`\s to be mutually recursive
- definitions. Each term :n:`@ident__i` proves a general principle of mutual
- induction for objects in type :n:`@ident__j`.
-
-.. cmdv:: Scheme @ident := Minimality for @ident Sort @sort {* with @ident := Minimality for @ident' Sort @sort}
-
- Same as before but defines a non-dependent elimination principle more
- natural in case of inductively defined relations.
+ The command generates the :n:`@ident`\s as mutually recursive
+ definitions. Each term :n:`@ident` proves a general principle of mutual
+ induction for objects in type :n:`@reference`.
-.. cmdv:: Scheme Equality for @ident
- :name: Scheme Equality
+ :n:`@ident`
+ The name of the scheme. If not provided, the scheme name will be determined automatically
+ from the sorts involved.
- Tries to generate a Boolean equality and a proof of the decidability of the usual equality. If `ident`
- involves some other inductive types, their equality has to be defined first.
+ :n:`Minimality for @reference Sort @sort_family`
+ Defines a non-dependent elimination principle more natural for inductively defined relations.
-.. cmdv:: Scheme Induction for @ident Sort @sort {* with Induction for @ident Sort @sort}
-
- If you do not provide the name of the schemes, they will be automatically computed from the
- sorts involved (works also with Minimality).
+ :n:`Equality for @reference`
+ Tries to generate a Boolean equality and a proof of the decidability of the usual equality.
+ If :token:`reference` involves other inductive types, their equality has to be defined first.
.. example::
@@ -128,7 +129,7 @@ Automatic declaration of schemes
.. warning::
- You have to be careful with these flags since Coq may now reject well-defined
+ You have to be careful with these flags since |Coq| may now reject well-defined
inductive types because it cannot compute a Boolean equality for them.
.. flag:: Rewriting Schemes
@@ -138,13 +139,13 @@ Automatic declaration of schemes
Combined Scheme
~~~~~~~~~~~~~~~~~~~~~~
-.. cmd:: Combined Scheme @ident from {+, @ident__i}
+.. cmd:: Combined Scheme @ident__def from {+, @ident }
This command is a tool for combining induction principles generated
by the :cmd:`Scheme` command.
- Each :n:`@ident__i` is a different inductive principle that must belong
+ Each :n:`@ident` is a different inductive principle that must belong
to the same package of mutual inductive principle definitions.
- This command generates :n:`@ident` to be the conjunction of the
+ This command generates :n:`@ident__def` as the conjunction of the
principles: it is built from the common premises of the principles
and concluded by the conjunction of their conclusions.
In the case where all the inductive principles used are in sort
@@ -197,32 +198,30 @@ Combined Scheme
Generation of inversion principles with ``Derive`` ``Inversion``
-----------------------------------------------------------------
-.. cmd:: Derive Inversion @ident with @ident Sort @sort
- Derive Inversion @ident with (forall {* @binder }, @ident @term) Sort @sort
+.. cmd:: Derive Inversion @ident with @one_term {? Sort @sort_family }
- This command generates an inversion principle for the
- :tacn:`inversion ... using ...` tactic. The first :token:`ident` is the name
- of the generated principle. The second :token:`ident` should be an inductive
- predicate, and :n:`{* @binder }` the variables occurring in the term
- :token:`term`. This command generates the inversion lemma for the sort
- :token:`sort` corresponding to the instance :n:`forall {* @binder }, @ident @term`.
- When applied, it is equivalent to having inverted the instance with the
- tactic :g:`inversion`.
+ Generates an inversion lemma for the
+ :tacn:`inversion ... using ...` tactic. :token:`ident` is the name
+ of the generated lemma. :token:`one_term` should be in the form
+ :token:`qualid` or :n:`(forall {+ @binder }, @qualid @term)` where
+ :token:`qualid` is the name of an inductive
+ predicate and :n:`{+ @binder }` binds the variables occurring in the term
+ :token:`term`. The lemma is generated for the sort
+ :token:`sort_family` corresponding to :token:`one_term`.
+ Applying the lemma is equivalent to inverting the instance with the
+ :tacn:`inversion` tactic.
-.. cmdv:: Derive Inversion_clear @ident with @ident Sort @sort
- Derive Inversion_clear @ident with (forall {* @binder }, @ident @term) Sort @sort
+.. cmd:: Derive Inversion_clear @ident with @one_term {? Sort @sort_family }
When applied, it is equivalent to having inverted the instance with the
tactic inversion replaced by the tactic `inversion_clear`.
-.. cmdv:: Derive Dependent Inversion @ident with @ident Sort @sort
- Derive Dependent Inversion @ident with (forall {* @binder }, @ident @term) Sort @sort
+.. cmd:: Derive Dependent Inversion @ident with @one_term Sort @sort_family
When applied, it is equivalent to having inverted the instance with
the tactic `dependent inversion`.
-.. cmdv:: Derive Dependent Inversion_clear @ident with @ident Sort @sort
- Derive Dependent Inversion_clear @ident with (forall {* @binder }, @ident @term) Sort @sort
+.. cmd:: Derive Dependent Inversion_clear @ident with @one_term Sort @sort_family
When applied, it is equivalent to having inverted the instance
with the tactic `dependent inversion_clear`.
diff --git a/doc/sphinx/user-extensions/syntax-extensions.rst b/doc/sphinx/user-extensions/syntax-extensions.rst
index 5148fa84c9..9d1fcc160d 100644
--- a/doc/sphinx/user-extensions/syntax-extensions.rst
+++ b/doc/sphinx/user-extensions/syntax-extensions.rst
@@ -3,7 +3,7 @@
Syntax extensions and notation scopes
=====================================
-In this chapter, we introduce advanced commands to modify the way Coq
+In this chapter, we introduce advanced commands to modify the way |Coq|
parses and prints objects, i.e. the translations between the concrete
and internal representations of terms and commands.
@@ -57,22 +57,21 @@ to represent :g:`(and A B)`:
Notations must be in double quotes, except when the
abbreviation has the form of an ordinary applicative expression;
see :ref:`Abbreviations`. The notation consists of *tokens* separated by
-spaces. Alphanumeric strings (such as ``A`` and ``B``) are the *parameters*
+spaces. Tokens which are identifiers (such as ``A``, ``x0'``, etc.) are the *parameters*
of the notation. Each of them must occur at least once in the abbreviated term. The
other elements of the string (such as ``/\``) are the *symbols*.
-Substrings enclosed in single quotes are treated as literals. This is necessary
-for substrings that would otherwise be interpreted as :n:`@ident`\s. Similarly,
-every symbol of at least 3 characters and starting with a simple quote
-must be quoted (then it starts by two single quotes). Here is an
-example.
+Identifiers enclosed in single quotes are treated as symbols and thus
+lose their role of parameters. In the same vein, every symbol of at
+least 3 characters and starting with a simple quote must be quoted
+(then it starts with two single quotes). Here is an example.
.. coqtop:: in
Notation "'IF' c1 'then' c2 'else' c3" := (IF_then_else c1 c2 c3).
A notation binds a syntactic expression to a term. Unless the parser
-and pretty-printer of Coq already know how to deal with the syntactic
+and pretty-printer of |Coq| already know how to deal with the syntactic
expression (such as through :cmd:`Reserved Notation` or for notations
that contain only literals), explicit precedences and
associativity rules have to be given.
@@ -82,13 +81,14 @@ associativity rules have to be given.
The right-hand side of a notation is interpreted at the time the notation is
given. In particular, disambiguation of constants, :ref:`implicit arguments
<ImplicitArguments>` and other notations are resolved at the
- time of the declaration of the notation.
+ time of the declaration of the notation. The right-hand side is
+ currently typed only at use time but this may change in the future.
Precedences and associativity
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mixing different symbolic notations in the same text may cause serious
-parsing ambiguity. To deal with the ambiguity of notations, Coq uses
+parsing ambiguity. To deal with the ambiguity of notations, |Coq| uses
precedence levels ranging from 0 to 100 (plus one extra level numbered
200) and associativity rules.
@@ -99,7 +99,7 @@ Consider for example the new notation
Notation "A \/ B" := (or A B).
Clearly, an expression such as :g:`forall A:Prop, True /\ A \/ A \/ False`
-is ambiguous. To tell the Coq parser how to interpret the
+is ambiguous. To tell the |Coq| parser how to interpret the
expression, a priority between the symbols ``/\`` and ``\/`` has to be
given. Assume for instance that we want conjunction to bind more than
disjunction. This is expressed by assigning a precedence level to each
@@ -117,7 +117,7 @@ defaults to :g:`True /\ (False /\ False)` (right associativity) or to
expression is not well-formed and that parentheses are mandatory (this is a “no
associativity”) [#no_associativity]_. We do not know of a special convention for
the associativity of disjunction and conjunction, so let us apply
-right associativity (which is the choice of Coq).
+right associativity (which is the choice of |Coq|).
Precedence levels and associativity rules of notations are specified with a list of
parenthesized :n:`@syntax_modifier`\s. Here is how the previous examples refine:
@@ -187,7 +187,7 @@ left. See the next section for more about factorization.
Simple factorization rules
~~~~~~~~~~~~~~~~~~~~~~~~~~
-Coq extensible parsing is performed by *Camlp5* which is essentially a LL1
+|Coq| extensible parsing is performed by *Camlp5* which is essentially a LL1
parser: it decides which notation to parse by looking at tokens from left to right.
Hence, some care has to be taken not to hide already existing rules by new
rules. Some simple left factorization work has to be done. Here is an example.
@@ -209,16 +209,16 @@ need to force the parsing level of ``y``, as follows.
Notation "x < y" := (lt x y) (at level 70).
Notation "x < y < z" := (x < y /\ y < z) (at level 70, y at next level).
-For the sake of factorization with Coq predefined rules, simple rules
+For the sake of factorization with |Coq| predefined rules, simple rules
have to be observed for notations starting with a symbol, e.g., rules
starting with “\ ``{``\ ” or “\ ``(``\ ” should be put at level 0. The list
-of Coq predefined notations can be found in the chapter on :ref:`thecoqlibrary`.
+of |Coq| predefined notations can be found in the chapter on :ref:`thecoqlibrary`.
Displaying symbolic notations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-The command :cmd:`Notation` has an effect both on the Coq parser and on the
-Coq printer. For example:
+The command :cmd:`Notation` has an effect both on the |Coq| parser and on the
+|Coq| printer. For example:
.. coqtop:: all
@@ -226,7 +226,7 @@ Coq printer. For example:
However, printing, especially pretty-printing, also requires some
care. We may want specific indentations, line breaks, alignment if on
-several lines, etc. For pretty-printing, |Coq| relies on |ocaml|
+several lines, etc. For pretty-printing, |Coq| relies on |OCaml|
formatting library, which provides indentation and automatic line
breaks depending on page width by means of *formatting boxes*.
@@ -299,12 +299,29 @@ Notations disappear when a section is closed. No typing of the denoted
expression is performed at definition time. Type checking is done only
at the time of use of the notation.
-.. note:: Sometimes, a notation is expected only for the parser. To do
- so, the option ``only parsing`` is allowed in the list of :n:`@syntax_modifier`\s
- in :cmd:`Notation`. Conversely, the ``only printing`` :n:`@syntax_modifier` can be
- used to declare that a notation should only be used for printing and
- should not declare a parsing rule. In particular, such notations do
- not modify the parser.
+.. note::
+
+ The default for a notation is to be used both for parsing and
+ printing. It is possible to declare a notation only for parsing by
+ adding the option ``only parsing`` to the list of
+ :n:`@syntax_modifier`\s of :cmd:`Notation`. Symmetrically, the
+ ``only printing`` :n:`@syntax_modifier` can be used to declare that
+ a notation should only be used for printing.
+
+ If a notation to be used both for parsing and printing is
+ overriden, both the parsing and printing are invalided, even if the
+ overriding rule is only parsing.
+
+ If a given notation string occurs only in ``only printing`` rules,
+ the parser is not modified at all.
+
+ To a given notation string and scope can be attached at most one
+ notation with both parsing and printing or with only
+ parsing. Contrastingly, an arbitrary number of ``only printing``
+ notations differing in their right-hand sides but only a unique
+ right-hand side can be attached to a given string and
+ scope. Obviously, expressions printed by means of such extra
+ printing rules will not be reparsed to the same form.
The Infix command
~~~~~~~~~~~~~~~~~~
@@ -332,12 +349,12 @@ Reserving notations
.. cmd:: Reserved Notation @string {? ( {+, @syntax_modifier } ) }
- A given notation may be used in different contexts. Coq expects all
+ A given notation may be used in different contexts. |Coq| expects all
uses of the notation to be defined at the same precedence and with the
same associativity. To avoid giving the precedence and associativity
every time, this command declares a parsing rule (:token:`string`) in advance
without giving its interpretation. Here is an example from the initial
- state of Coq.
+ state of |Coq|.
.. coqtop:: in
@@ -368,8 +385,8 @@ a :token:`decl_notations` clause after the definition of the (co)inductive type
(co)recursive term (or after the definition of each of them in case of mutual
definitions). The exact syntax is given by :n:`@decl_notation` for inductive,
co-inductive, recursive and corecursive definitions and in :ref:`record-types`
-for records. Note that only syntax modifiers that do not require to add or
-change a parsing rule are accepted.
+for records. Note that only syntax modifiers that do not require adding or
+changing a parsing rule are accepted.
.. insertprodn decl_notations decl_notation
@@ -427,7 +444,7 @@ Displaying information about notations
This command doesn't display all nonterminals of the grammar. For example,
productions shown by `Print Grammar tactic` refer to nonterminals `tactic_then_locality`
- and `tactic_then_gen` which are not shown and can't be printed.
+ and `for_each_goal` which are not shown and can't be printed.
Most of the grammar in the documentation was updated in 8.12 to make it accurate and
readable. This was done using a new developer tool that extracts the grammar from the
@@ -460,16 +477,16 @@ Displaying information about notations
such as `1+2*3` in the usual way as `1+(2*3)`. However, most nonterminals have a single level.
For example, this output from `Print Grammar tactic` shows the first 3 levels for
- `tactic_expr`, designated as "5", "4" and "3". Level 3 is right-associative,
+ `ltac_expr`, designated as "5", "4" and "3". Level 3 is right-associative,
which applies to the productions within it, such as the `try` construct::
- Entry tactic_expr is
+ Entry ltac_expr is
[ "5" RIGHTA
[ binder_tactic ]
| "4" LEFTA
[ SELF; ";"; binder_tactic
| SELF; ";"; SELF
- | SELF; ";"; tactic_then_locality; tactic_then_gen; "]" ]
+ | SELF; ";"; tactic_then_locality; for_each_goal; "]" ]
| "3" RIGHTA
[ IDENT "try"; SELF
:
@@ -493,7 +510,7 @@ Displaying information about notations
The output for `Print Grammar constr` includes :cmd:`Notation` definitions,
which are dynamically added to the grammar at run time.
- For example, in the definition for `operconstr`, the production on the second line shown
+ For example, in the definition for `term`, the production on the second line shown
here is defined by a :cmd:`Reserved Notation` command in `Notations.v`::
| "50" LEFTA
@@ -745,7 +762,7 @@ recursive patterns. The basic example is:
Notation "[ x ; .. ; y ]" := (cons x .. (cons y nil) ..).
On the right-hand side, an extra construction of the form ``.. t ..`` can
-be used. Notice that ``..`` is part of the Coq syntax and it must not be
+be used. Notice that ``..`` is part of the |Coq| syntax and it must not be
confused with the three-dots notation “``…``” used in this manual to denote
a sequence of arbitrary size.
@@ -925,7 +942,7 @@ Custom entries
Custom entries have levels, like the main grammar of terms and grammar
of patterns have. The lower level is 0 and this is the level used by
default to put rules delimited with tokens on both ends. The level is
-left to be inferred by Coq when using :n:`in custom @ident`. The
+left to be inferred by |Coq| when using :n:`in custom @ident`. The
level is otherwise given explicitly by using the syntax
:n:`in custom @ident at level @natural`, where :n:`@natural` refers to the level.
@@ -979,7 +996,7 @@ associated to the custom entry ``expr``. The level can be omitted, as in
Notation "[ e ]" := e (e custom expr).
-in which case Coq infer it. If the sub-expression is at a border of
+in which case |Coq| infer it. If the sub-expression is at a border of
the notation (as e.g. ``x`` and ``y`` in ``x + y``), the level is
determined by the associativity. If the sub-expression is not at the
border of the notation (as e.g. ``e`` in ``"[ e ]``), the level is
@@ -1080,7 +1097,7 @@ Here are the syntax elements used by the various notation commands.
time. Type checking is done only at the time of use of the notation.
.. note:: Some examples of Notation may be found in the files composing
- the initial state of Coq (see directory :file:`$COQLIB/theories/Init`).
+ the initial state of |Coq| (see directory :file:`$COQLIB/theories/Init`).
.. note:: The notation ``"{ x }"`` has a special status in the main grammars of
terms and patterns so that
@@ -1105,7 +1122,7 @@ Here are the syntax elements used by the various notation commands.
.. warn:: Use of @string Notation is deprecated as it is inconsistent with pattern syntax.
This warning is disabled by default to avoid spurious diagnostics
- due to legacy notation in the Coq standard library.
+ due to legacy notation in the |Coq| standard library.
It can be turned on with the ``-w disj-pattern-notation`` flag.
.. _Scopes:
@@ -1139,7 +1156,7 @@ Most commands use :token:`scope_name`; :token:`scope_key`\s are used within :tok
.. cmd:: Declare Scope @scope_name
Declares a new notation scope. Note that the initial
- state of Coq declares the following notation scopes:
+ state of |Coq| declares the following notation scopes:
``core_scope``, ``type_scope``, ``function_scope``, ``nat_scope``,
``bool_scope``, ``list_scope``, ``int_scope``, ``uint_scope``.
@@ -1291,10 +1308,10 @@ recognized to be a ``Funclass`` instance, i.e., of type :g:`forall x:A, B` or
.. _notation-scopes:
-Notation scopes used in the standard library of Coq
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Notation scopes used in the standard library of |Coq|
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-We give an overview of the scopes used in the standard library of Coq.
+We give an overview of the scopes used in the standard library of |Coq|.
For a complete list of notations in each scope, use the commands :cmd:`Print
Scopes` or :cmd:`Print Scope`.
@@ -1360,7 +1377,7 @@ Scopes` or :cmd:`Print Scope`.
``string_scope``
This scope includes notation for strings as elements of the type string.
- Special characters and escaping follow Coq conventions on strings (see
+ Special characters and escaping follow |Coq| conventions on strings (see
:ref:`lexical-conventions`). Especially, there is no convention to visualize non
printable characters of a string. The file :file:`String.v` shows an example
that contains quotes, a newline and a beep (i.e. the ASCII character
@@ -1369,7 +1386,7 @@ Scopes` or :cmd:`Print Scope`.
``char_scope``
This scope includes interpretation for all strings of the form ``"c"``
where :g:`c` is an ASCII character, or of the form ``"nnn"`` where nnn is
- a three-digits number (possibly with leading 0's), or of the form
+ a three-digit number (possibly with leading 0s), or of the form
``""""``. Their respective denotations are the ASCII code of :g:`c`, the
decimal ASCII code ``nnn``, or the ascii code of the character ``"`` (i.e.
the ASCII code 34), all of them being represented in the type :g:`ascii`.
@@ -1461,7 +1478,7 @@ Abbreviations
An abbreviation expects no precedence nor associativity, since it
is parsed as an usual application. Abbreviations are used as
- much as possible by the Coq printers unless the modifier ``(only
+ much as possible by the |Coq| printers unless the modifier ``(only
parsing)`` is given.
An abbreviation is bound to an absolute name as an ordinary definition is
@@ -1536,16 +1553,18 @@ numbers (see :ref:`datatypes`).
Number notations
~~~~~~~~~~~~~~~~
-.. cmd:: Number Notation @qualid__type @qualid__parse @qualid__print : @scope_name {? @numeral_modifier }
+.. cmd:: Number Notation @qualid__type @qualid__parse @qualid__print {? ( {+, @number_modifier } ) } : @scope_name
:name: Number Notation
- .. insertprodn numeral_modifier numeral_modifier
+ .. insertprodn number_modifier number_string_via
.. prodn::
- numeral_modifier ::= ( warning after @bignat )
- | ( abstract after @bignat )
+ number_modifier ::= warning after @bignat
+ | abstract after @bignat
+ | @number_string_via
+ number_string_via ::= via @qualid mapping [ {+, {| @qualid => @qualid | [ @qualid ] => @qualid } } ]
- This command allows the user to customize the way numeral literals
+ This command allows the user to customize the way number literals
are parsed and printed.
:n:`@qualid__type`
@@ -1554,32 +1573,32 @@ Number notations
parsing and printing functions, respectively. The parsing function
:n:`@qualid__parse` should have one of the following types:
- * :n:`Numeral.int -> @qualid__type`
- * :n:`Numeral.int -> option @qualid__type`
- * :n:`Numeral.uint -> @qualid__type`
- * :n:`Numeral.uint -> option @qualid__type`
+ * :n:`Number.int -> @qualid__type`
+ * :n:`Number.int -> option @qualid__type`
+ * :n:`Number.uint -> @qualid__type`
+ * :n:`Number.uint -> option @qualid__type`
* :n:`Z -> @qualid__type`
* :n:`Z -> option @qualid__type`
- * :n:`Numeral.numeral -> @qualid__type`
- * :n:`Numeral.numeral -> option @qualid__type`
+ * :n:`Number.number -> @qualid__type`
+ * :n:`Number.number -> option @qualid__type`
And the printing function :n:`@qualid__print` should have one of the
following types:
- * :n:`@qualid__type -> Numeral.int`
- * :n:`@qualid__type -> option Numeral.int`
- * :n:`@qualid__type -> Numeral.uint`
- * :n:`@qualid__type -> option Numeral.uint`
+ * :n:`@qualid__type -> Number.int`
+ * :n:`@qualid__type -> option Number.int`
+ * :n:`@qualid__type -> Number.uint`
+ * :n:`@qualid__type -> option Number.uint`
* :n:`@qualid__type -> Z`
* :n:`@qualid__type -> option Z`
- * :n:`@qualid__type -> Numeral.numeral`
- * :n:`@qualid__type -> option Numeral.numeral`
+ * :n:`@qualid__type -> Number.number`
+ * :n:`@qualid__type -> option Number.number`
.. deprecated:: 8.12
- Numeral notations on :g:`Decimal.uint`, :g:`Decimal.int` and
- :g:`Decimal.decimal` are replaced respectively by numeral
- notations on :g:`Numeral.uint`, :g:`Numeral.int` and
- :g:`Numeral.numeral`.
+ Number notations on :g:`Decimal.uint`, :g:`Decimal.int` and
+ :g:`Decimal.decimal` are replaced respectively by number
+ notations on :g:`Number.uint`, :g:`Number.int` and
+ :g:`Number.number`.
When parsing, the application of the parsing function
:n:`@qualid__parse` to the number will be fully reduced, and universes
@@ -1589,7 +1608,44 @@ Number notations
function application, constructors, inductive type families,
sorts, and primitive integers) will be considered for printing.
- :n:`( warning after @bignat )`
+ .. _number-string-via:
+
+ :n:`via @qualid__ind mapping [ {+, @qualid__constant => @qualid__constructor } ]`
+ When using this option, :n:`@qualid__type` no
+ longer needs to be an inductive type and is instead mapped to the
+ inductive type :n:`@qualid__ind` according to the provided
+ list of pairs, whose first component :n:`@qualid__constant` is a
+ constant of type :n:`@qualid__type`
+ (or a function of type :n:`{* _ -> } @qualid__type`) and the second a
+ constructor of type :n:`@qualid__ind`. The type
+ :n:`@qualid__type` is then replaced by :n:`@qualid__ind` in the
+ above parser and printer types.
+
+ When :n:`@qualid__constant` is surrounded by square brackets,
+ all the implicit arguments of :n:`@qualid__constant` (whether maximally inserted or not) are ignored
+ when translating to :n:`@qualid__constructor` (i.e., before
+ applying :n:`@qualid__print`) and replaced with implicit
+ argument holes :g:`_` when translating from
+ :n:`@qualid__constructor` to :n:`@qualid__constant` (after
+ :n:`@qualid__parse`). See below for an :ref:`example <example-number-notation-implicit-args>`.
+
+ .. note::
+ The implicit status of the arguments is considered
+ only at notation declaration time, any further
+ modification of this status has no impact
+ on the previously declared notations.
+
+ .. note::
+ In case of multiple implicit options (for instance
+ :g:`Arguments eq_refl {A}%type_scope {x}, [_] _`), an
+ argument is considered implicit when it is implicit in any of the
+ options.
+
+ .. note::
+ To use a :token:`sort` as the target type :n:`@qualid__type`, use an :ref:`abbreviation <Abbreviations>`
+ as in the :ref:`example below <example-number-notation-non-inductive>`.
+
+ :n:`warning after @bignat`
displays a warning message about a possible stack
overflow when calling :n:`@qualid__parse` to parse a literal larger than :n:`@bignat`.
@@ -1599,11 +1655,11 @@ Number notations
with :n:`(warning after @bignat)`, this warning is emitted when
parsing a number greater than or equal to :token:`bignat`.
- :n:`( abstract after @bignat )`
+ :n:`abstract after @bignat`
returns :n:`(@qualid__parse m)` when parsing a literal
:n:`m` that's greater than :n:`@bignat` rather than reducing it to a normal form.
Here :g:`m` will be a
- :g:`Numeral.int`, :g:`Numeral.uint`, :g:`Z` or :g:`Numeral.numeral`, depending on the
+ :g:`Number.int`, :g:`Number.uint`, :g:`Z` or :g:`Number.number`, depending on the
type of the parsing function :n:`@qualid__parse`. This allows for a
more compact representation of literals in types such as :g:`nat`,
and limits parse failures due to stack overflow. Note that a
@@ -1617,7 +1673,7 @@ Number notations
with :n:`(abstract after @bignat)`, this warning is emitted when
parsing a number greater than or equal to :token:`bignat`.
Typically, this indicates that the fully computed representation
- of numbers can be so large that non-tail-recursive OCaml
+ of numbers can be so large that non-tail-recursive |OCaml|
functions run out of stack space when trying to walk them.
.. warn:: The 'abstract after' directive has no effect when the parsing function (@qualid__parse) targets an option type.
@@ -1625,76 +1681,94 @@ Number notations
As noted above, the :n:`(abstract after @natural)` directive has no
effect when :n:`@qualid__parse` lands in an :g:`option` type.
+ .. exn:: 'via' and 'abstract' cannot be used together.
+
+ With the :n:`abstract after` option, the parser function
+ :n:`@qualid__parse` does not reduce large numbers to a normal form,
+ which prevents doing the translation given in the :n:`mapping` list.
+
.. exn:: Cannot interpret this number as a value of type @type
- The numeral notation registered for :token:`type` does not support
+ The number notation registered for :token:`type` does not support
the given number. This error is given when the interpretation
function returns :g:`None`, or if the interpretation is registered
only for integers or non-negative integers, and the given number
has a fractional or exponent part or is negative.
- .. exn:: @qualid__parse should go from Numeral.int to @type or (option @type). Instead of Numeral.int, the types Numeral.uint or Z or Int63.int or Numeral.numeral could be used (you may need to require BinNums or Numeral or Int63 first).
+ .. exn:: @qualid__parse should go from Number.int to @type or (option @type). Instead of Number.int, the types Number.uint or Z or Int63.int or Number.number could be used (you may need to require BinNums or Number or Int63 first).
The parsing function given to the :cmd:`Number Notation`
vernacular is not of the right type.
- .. exn:: @qualid__print should go from @type to Numeral.int or (option Numeral.int). Instead of Numeral.int, the types Numeral.uint or Z or Int63.int or Numeral.numeral could be used (you may need to require BinNums or Numeral or Int63 first).
+ .. exn:: @qualid__print should go from @type to Number.int or (option Number.int). Instead of Number.int, the types Number.uint or Z or Int63.int or Number.number could be used (you may need to require BinNums or Number or Int63 first).
The printing function given to the :cmd:`Number Notation`
vernacular is not of the right type.
- .. exn:: Unexpected term @term while parsing a numeral notation.
+ .. exn:: Unexpected term @term while parsing a number notation.
Parsing functions must always return ground terms, made up of
- applications of constructors, inductive types, and primitive
+ function application, constructors, inductive type families, sorts and primitive
integers. Parsing functions may not return terms containing
axioms, bare (co)fixpoints, lambdas, etc.
- .. exn:: Unexpected non-option term @term while parsing a numeral notation.
+ .. exn:: Unexpected non-option term @term while parsing a number notation.
Parsing functions expected to return an :g:`option` must always
return a concrete :g:`Some` or :g:`None` when applied to a
concrete number expressed as a (hexa)decimal. They may not return
opaque constants.
+ .. exn:: Multiple 'via' options.
+
+ At most one :g:`via` option can be given.
+
+ .. exn:: Multiple 'warning after' or 'abstract after' options.
+
+ At most one :g:`warning after` or :g:`abstract after` option can be given.
+
.. _string-notations:
String notations
~~~~~~~~~~~~~~~~
-.. cmd:: String Notation @qualid @qualid__parse @qualid__print : @scope_name
+.. cmd:: String Notation @qualid__type @qualid__parse @qualid__print {? ( @number_string_via ) } : @scope_name
:name: String Notation
Allows the user to customize how strings are parsed and printed.
- The token :n:`@qualid` should be the name of an inductive type,
- while :n:`@qualid__parse` and :n:`@qualid__print` should be the names of the
- parsing and printing functions, respectively. The parsing function
- :n:`@qualid__parse` should have one of the following types:
+ :n:`@qualid__type`
+ the name of an inductive type,
+ while :n:`@qualid__parse` and :n:`@qualid__print` should be the names of the
+ parsing and printing functions, respectively. The parsing function
+ :n:`@qualid__parse` should have one of the following types:
+
+ * :n:`Byte.byte -> @qualid__type`
+ * :n:`Byte.byte -> option @qualid__type`
+ * :n:`list Byte.byte -> @qualid__type`
+ * :n:`list Byte.byte -> option @qualid__type`
- * :n:`Byte.byte -> @qualid`
- * :n:`Byte.byte -> option @qualid`
- * :n:`list Byte.byte -> @qualid`
- * :n:`list Byte.byte -> option @qualid`
+ The printing function :n:`@qualid__print` should have one of the
+ following types:
- The printing function :n:`@qualid__print` should have one of the
- following types:
+ * :n:`@qualid__type -> Byte.byte`
+ * :n:`@qualid__type -> option Byte.byte`
+ * :n:`@qualid__type -> list Byte.byte`
+ * :n:`@qualid__type -> option (list Byte.byte)`
- * :n:`@qualid -> Byte.byte`
- * :n:`@qualid -> option Byte.byte`
- * :n:`@qualid -> list Byte.byte`
- * :n:`@qualid -> option (list Byte.byte)`
+ When parsing, the application of the parsing function
+ :n:`@qualid__parse` to the string will be fully reduced, and universes
+ of the resulting term will be refreshed.
- When parsing, the application of the parsing function
- :n:`@qualid__parse` to the string will be fully reduced, and universes
- of the resulting term will be refreshed.
+ Note that only fully-reduced ground terms (terms containing only
+ function application, constructors, inductive type families,
+ sorts, and primitive integers) will be considered for printing.
- Note that only fully-reduced ground terms (terms containing only
- function application, constructors, inductive type families,
- sorts, and primitive integers) will be considered for printing.
+ :n:`via @qualid__ind mapping [ {+, @qualid__constant => @qualid__constructor } ]`
+ works as for :ref:`number notations above <number-string-via>`.
- .. exn:: Cannot interpret this string as a value of type @type
+ .. exn:: Cannot interpret this string as a value of type @type
The string notation registered for :token:`type` does not support
the given string. This error is given when the interpretation
@@ -1713,7 +1787,7 @@ String notations
.. exn:: Unexpected term @term while parsing a string notation.
Parsing functions must always return ground terms, made up of
- applications of constructors, inductive types, and primitive
+ function application, constructors, inductive type families, sorts and primitive
integers. Parsing functions may not return terms containing
axioms, bare (co)fixpoints, lambdas, etc.
@@ -1724,16 +1798,37 @@ String notations
concrete string expressed as a decimal. They may not return
opaque constants.
-The following errors apply to both string and numeral notations:
+.. note::
+ Number or string notations for parameterized inductive types can be
+ added by declaring an :ref:`abbreviation <Abbreviations>` for the
+ inductive which instantiates all parameters. See :ref:`example below <example-string-notation-parameterized-inductive>`.
+
+The following errors apply to both string and number notations:
.. exn:: @type is not an inductive type.
- String and numeral notations can only be declared for inductive types with no
- arguments.
+ String and number notations can only be declared for inductive types.
+ Declare string or numeral notations for non-inductive types using :n:`@number_string_via`.
+
+ .. exn:: @qualid was already mapped to @qualid and cannot be remapped to @qualid
+
+ Duplicates are not allowed in the :n:`mapping` list.
+
+ .. exn:: Missing mapping for constructor @qualid
+
+ A mapping should be provided for :n:`@qualid` in the :n:`mapping` list.
+
+ .. warn:: @type was already mapped to @type, mapping it also to @type might yield ill typed terms when using the notation.
+
+ Two pairs in the :n:`mapping` list associate types that might be incompatible.
+
+ .. warn:: Type of @qualid seems incompatible with the type of @qualid. Expected type is: @type instead of @type. This might yield ill typed terms when using the notation.
+
+ A mapping given in the :n:`mapping` list associates a constant with a seemingly incompatible constructor.
.. exn:: Cannot interpret in @scope_name because @qualid could not be found in the current environment.
- The inductive type used to register the string or numeral notation is no
+ The inductive type used to register the string or number notation is no
longer available in the environment. Most likely, this is because
the notation was declared inside a functor for an
inductive type inside the functor. This use case is not currently
@@ -1762,6 +1857,198 @@ The following errors apply to both string and numeral notations:
.. todo note on "single qualified identifiers" https://github.com/coq/coq/pull/11718#discussion_r415076703
+.. example:: Number Notation for radix 3
+
+ The following example parses and prints natural numbers
+ whose digits are :g:`0`, :g:`1` or :g:`2` as terms of the following
+ inductive type encoding radix 3 numbers.
+
+ .. coqtop:: in reset
+
+ Inductive radix3 : Set :=
+ | x0 : radix3
+ | x3 : radix3 -> radix3
+ | x3p1 : radix3 -> radix3
+ | x3p2 : radix3 -> radix3.
+
+ We first define a parsing function
+
+ .. coqtop:: in
+
+ Definition of_uint_dec (u : Decimal.uint) : option radix3 :=
+ let fix f u := match u with
+ | Decimal.Nil => Some x0
+ | Decimal.D0 u => match f u with Some u => Some (x3 u) | None => None end
+ | Decimal.D1 u => match f u with Some u => Some (x3p1 u) | None => None end
+ | Decimal.D2 u => match f u with Some u => Some (x3p2 u) | None => None end
+ | _ => None end in
+ f (Decimal.rev u).
+ Definition of_uint (u : Number.uint) : option radix3 :=
+ match u with Number.UIntDecimal u => of_uint_dec u | Number.UIntHexadecimal _ => None end.
+
+ and a printing function
+
+ .. coqtop:: in
+
+ Definition to_uint_dec (x : radix3) : Decimal.uint :=
+ let fix f x := match x with
+ | x0 => Decimal.Nil
+ | x3 x => Decimal.D0 (f x)
+ | x3p1 x => Decimal.D1 (f x)
+ | x3p2 x => Decimal.D2 (f x) end in
+ Decimal.rev (f x).
+ Definition to_uint (x : radix3) : Number.uint := Number.UIntDecimal (to_uint_dec x).
+
+ before declaring the notation
+
+ .. coqtop:: in
+
+ Declare Scope radix3_scope.
+ Open Scope radix3_scope.
+ Number Notation radix3 of_uint to_uint : radix3_scope.
+
+ We can check the printer
+
+ .. coqtop:: all
+
+ Check x3p2 (x3p1 x0).
+
+ and the parser
+
+ .. coqtop:: all
+
+ Set Printing All.
+ Check 120.
+
+ Digits other than :g:`0`, :g:`1` and :g:`2` are rejected.
+
+ .. coqtop:: all fail
+
+ Check 3.
+
+.. _example-number-notation-non-inductive:
+
+.. example:: Number Notation for a non inductive type
+
+ The following example encodes the terms in the form :g:`sum unit ( ... (sum unit unit) ... )`
+ as the number of units in the term. For instance :g:`sum unit (sum unit unit)`
+ is encoded as :g:`3` while :g:`unit` is :g:`1` and :g:`0` stands for :g:`Empty_set`.
+ The inductive :g:`I` will be used as :n:`@qualid__ind`.
+
+ .. coqtop:: in reset
+
+ Inductive I := Iempty : I | Iunit : I | Isum : I -> I -> I.
+
+ We then define :n:`@qualid__parse` and :n:`@qualid__print`
+
+ .. coqtop:: in
+
+ Definition of_uint (x : Number.uint) : I :=
+ let fix f n := match n with
+ | O => Iempty | S O => Iunit
+ | S n => Isum Iunit (f n) end in
+ f (Nat.of_num_uint x).
+
+ Definition to_uint (x : I) : Number.uint :=
+ let fix f i := match i with
+ | Iempty => O | Iunit => 1
+ | Isum i1 i2 => f i1 + f i2 end in
+ Nat.to_num_uint (f x).
+
+ Inductive sum (A : Set) (B : Set) : Set := pair : A -> B -> sum A B.
+
+ the number notation itself
+
+ .. coqtop:: in
+
+ Notation nSet := Set (only parsing).
+ Number Notation nSet of_uint to_uint (via I
+ mapping [Empty_set => Iempty, unit => Iunit, sum => Isum]) : type_scope.
+
+ and check the printer
+
+ .. coqtop:: all
+
+ Local Open Scope type_scope.
+ Check sum unit (sum unit unit).
+
+ and the parser
+
+ .. coqtop:: all
+
+ Set Printing All.
+ Check 3.
+
+.. _example-number-notation-implicit-args:
+
+.. example:: Number Notation with implicit arguments
+
+ The following example parses and prints natural numbers between
+ :g:`0` and :g:`n-1` as terms of type :g:`Fin.t n`.
+
+ .. coqtop:: all reset
+
+ Require Import Vector.
+ Print Fin.t.
+
+ Note the implicit arguments of :g:`Fin.F1` and :g:`Fin.FS`,
+ which won't appear in the corresponding inductive type.
+
+ .. coqtop:: in
+
+ Inductive I := I1 : I | IS : I -> I.
+
+ Definition of_uint (x : Number.uint) : I :=
+ let fix f n := match n with O => I1 | S n => IS (f n) end in
+ f (Nat.of_num_uint x).
+
+ Definition to_uint (x : I) : Number.uint :=
+ let fix f i := match i with I1 => O | IS n => S (f n) end in
+ Nat.to_num_uint (f x).
+
+ Declare Scope fin_scope.
+ Delimit Scope fin_scope with fin.
+ Local Open Scope fin_scope.
+ Number Notation Fin.t of_uint to_uint (via I
+ mapping [[Fin.F1] => I1, [Fin.FS] => IS]) : fin_scope.
+
+ Now :g:`2` is parsed as :g:`Fin.FS (Fin.FS Fin.F1)`, that is
+ :g:`@Fin.FS _ (@Fin.FS _ (@Fin.F1 _))`.
+
+ .. coqtop:: all
+
+ Check 2.
+
+ which can be of type :g:`Fin.t 3` (numbers :g:`0`, :g:`1` and :g:`2`)
+
+ .. coqtop:: all
+
+ Check 2 : Fin.t 3.
+
+ but cannot be of type :g:`Fin.t 2` (only :g:`0` and :g:`1`)
+
+ .. coqtop:: all fail
+
+ Check 2 : Fin.t 2.
+
+.. _example-string-notation-parameterized-inductive:
+
+.. example:: String Notation with a parameterized inductive type
+
+ The parameter :g:`Byte.byte` for the parameterized inductive type
+ :g:`list` is given through an :ref:`abbreviation <Abbreviations>`.
+
+ .. coqtop:: in reset
+
+ Notation string := (list Byte.byte) (only parsing).
+ Definition id_string := @id string.
+
+ String Notation string id_string id_string : list_scope.
+
+ .. coqtop:: all
+
+ Check "abc"%list.
+
.. _TacticNotation:
Tactic Notations
@@ -1877,12 +2164,12 @@ Tactic notations allow customizing the syntax of tactics.
- :tacn:`unfold`, :tacn:`with_strategy`
* - ``constr``
- - :token:`term`
+ - :token:`one_term`
- a term
- :tacn:`exact`
* - ``uconstr``
- - :token:`term`
+ - :token:`one_term`
- an untyped term
- :tacn:`refine`
@@ -1961,9 +2248,9 @@ Tactic notations allow customizing the syntax of tactics.
.. rubric:: Footnotes
.. [#and_or_levels] which are the levels effectively chosen in the current
- implementation of Coq
+ implementation of |Coq|
-.. [#no_associativity] Coq accepts notations declared as nonassociative but the parser on
- which Coq is built, namely Camlp5, currently does not implement ``no associativity`` and
- replaces it with ``left associativity``; hence it is the same for Coq: ``no associativity``
+.. [#no_associativity] |Coq| accepts notations declared as nonassociative but the parser on
+ which |Coq| is built, namely Camlp5, currently does not implement ``no associativity`` and
+ replaces it with ``left associativity``; hence it is the same for |Coq|: ``no associativity``
is in fact ``left associativity`` for the purposes of parsing
diff --git a/doc/sphinx/using/libraries/funind.rst b/doc/sphinx/using/libraries/funind.rst
index 738d64bfc3..93571ecebb 100644
--- a/doc/sphinx/using/libraries/funind.rst
+++ b/doc/sphinx/using/libraries/funind.rst
@@ -169,13 +169,24 @@ terminating functions.
Tactics
-------
-.. tacn:: functional induction (@qualid {+ @term})
+.. tacn:: functional induction @term {? using @one_term {? with @bindings } } {? as @simple_intropattern }
:name: functional induction
- The tactic functional induction performs case analysis and induction
- following the definition of a function. It makes use of a principle
+ Performs case analysis and induction following the definition of a function
+ :token:`qualid`, which must be fully applied to its arguments as part of
+ :token:`term`. It uses a principle
generated by :cmd:`Function` or :cmd:`Functional Scheme`.
Note that this tactic is only available after a ``Require Import FunInd``.
+ See the :cmd:`Function` command.
+
+ :n:`using @one_term`
+ Specifies the induction principle (aka elimination scheme).
+
+ :n:`with @bindings`
+ Specifies the arguments of the induction principle.
+
+ :n:`as @simple_intropattern`
+ Provides names for the introduced variables.
.. example::
@@ -189,15 +200,6 @@ Tactics
Qed.
.. note::
- :n:`(@qualid {+ @term})` must be a correct full application
- of :n:`@qualid`. In particular, the rules for implicit arguments are the
- same as usual. For example use :n:`@@qualid` if you want to write implicit
- arguments explicitly.
-
- .. note::
- Parentheses around :n:`@qualid {+ @term}` are not mandatory and can be skipped.
-
- .. note::
:n:`functional induction (f x1 x2 x3)` is actually a wrapper for
:n:`induction x1, x2, x3, (f x1 x2 x3) using @qualid` followed by a cleaning
phase, where :n:`@qualid` is the induction principle registered for :g:`f`
@@ -218,22 +220,27 @@ Tactics
.. exn:: Not the right number of induction arguments.
:undocumented:
- .. tacv:: functional induction (@qualid {+ @term}) as @simple_intropattern using @term with @bindings_list
-
- Similarly to :tacn:`induction` and :tacn:`elim`, this allows giving
- explicitly the name of the introduced variables, the induction principle, and
- the values of dependent premises of the elimination scheme, including
- *predicates* for mutual induction when :n:`@qualid` is part of a mutually
- recursive definition.
-
-.. tacn:: functional inversion @ident
+.. tacn:: functional inversion {| @ident | @natural } {? @qualid }
:name: functional inversion
- :tacn:`functional inversion` is a tactic that performs inversion on hypothesis
- :n:`@ident` of the form :n:`@qualid {+ @term} = @term` or :n:`@term = @qualid
- {+ @term}` where :n:`@qualid` must have been defined using :cmd:`Function`.
+ Performs inversion on hypothesis
+ :n:`@ident` of the form :n:`@qualid {+ @term} = @term` or
+ :n:`@term = @qualid {+ @term}` when :n:`@qualid` is defined using :cmd:`Function`.
Note that this tactic is only available after a ``Require Import FunInd``.
+ :n:`@natural`
+ Does the same thing as :n:`intros until @natural` followed by
+ :n:`functional inversion @ident` where :token:`ident` is the
+ identifier for the last introduced hypothesis.
+
+ :n:`@qualid`
+ If the hypothesis :token:`ident` (or :token:`natural`) has a type of the form
+ :n:`@qualid__1 {+ @term__i } = @qualid__2 {+ @term__j }` where
+ :n:`@qualid__1` and :n:`@qualid__2` are valid candidates to
+ functional inversion, this variant allows choosing which :token:`qualid`
+ is inverted.
+
+
.. exn:: Hypothesis @ident must contain at least one Function.
:undocumented:
@@ -242,39 +249,26 @@ Tactics
This error may be raised when some inversion lemma failed to be generated by
Function.
-
- .. tacv:: functional inversion @natural
-
- This does the same thing as :n:`intros until @natural` followed by
- :n:`functional inversion @ident` where :token:`ident` is the
- identifier for the last introduced hypothesis.
-
- .. tacv:: functional inversion @ident @qualid
- functional inversion @natural @qualid
-
- If the hypothesis :token:`ident` (or :token:`natural`) has a type of the form
- :n:`@qualid__1 {+ @term__i } = @qualid__2 {+ @term__j }` where
- :n:`@qualid__1` and :n:`@qualid__2` are valid candidates to
- functional inversion, this variant allows choosing which :token:`qualid`
- is inverted.
-
.. _functional-scheme:
Generation of induction principles with ``Functional`` ``Scheme``
-----------------------------------------------------------------
-.. cmd:: Functional Scheme @ident__0 := Induction for @ident' Sort @sort {* with @ident__i := Induction for @ident__i' Sort @sort}
+.. cmd:: Functional Scheme @func_scheme_def {* with @func_scheme_def }
+
+ .. insertprodn func_scheme_def func_scheme_def
+
+ .. prodn::
+ func_scheme_def ::= @ident := Induction for @qualid Sort @sort_family
+
+ An experimental high-level tool that
+ automatically generates induction principles corresponding to functions that
+ may be mutually recursive. The command generates an
+ induction principle named :n:`@ident` for each given function named :n:`@qualid`.
+ The :n:`@qualid`\s must be given in the same order as when they were defined.
- This command is a high-level experimental tool for
- generating automatically induction principles corresponding to
- (possibly mutually recursive) functions. First, it must be made
- available via ``Require Import FunInd``.
- Each :n:`@ident__i` is a different mutually defined function
- name (the names must be in the same order as when they were defined). This
- command generates the induction principle for each :n:`@ident__i`, following
- the recursive structure and case analyses of the corresponding function
- :n:`@ident__i'`.
+ Note the command must be made available via :cmd:`Require Import` ``FunInd``.
.. warning::
diff --git a/doc/sphinx/using/libraries/index.rst b/doc/sphinx/using/libraries/index.rst
index 0bd3054788..95218322ff 100644
--- a/doc/sphinx/using/libraries/index.rst
+++ b/doc/sphinx/using/libraries/index.rst
@@ -4,15 +4,15 @@
Libraries and plugins
=====================
-Coq is distributed with a standard library and a set of internal
+|Coq| is distributed with a standard library and a set of internal
plugins (most of which provide tactics that have already been
presented in :ref:`writing-proofs`). This chapter presents this
standard library and some of these internal plugins which provide
features that are not tactics.
-In addition, Coq has a rich ecosystem of external libraries and
+In addition, |Coq| has a rich ecosystem of external libraries and
plugins. These libraries and plugins can be browsed online through
-the `Coq Package Index <https://coq.inria.fr/opam/www/>`_ and
+the `|Coq| Package Index <https://coq.inria.fr/opam/www/>`_ and
installed with the `opam package manager
<https://coq.inria.fr/opam-using.html>`_.
diff --git a/doc/sphinx/using/libraries/writing.rst b/doc/sphinx/using/libraries/writing.rst
index 325ea2af60..724bcd0488 100644
--- a/doc/sphinx/using/libraries/writing.rst
+++ b/doc/sphinx/using/libraries/writing.rst
@@ -1,9 +1,9 @@
-Writing Coq libraries and plugins
-=================================
+Writing |Coq| libraries and plugins
+===================================
-This section presents the part of the Coq language that is useful only
-to library and plugin authors. A tutorial for writing Coq plugins is
-available in the Coq repository in `doc/plugin_tutorial
+This section presents the part of the |Coq| language that is useful only
+to library and plugin authors. A tutorial for writing |Coq| plugins is
+available in the |Coq| repository in `doc/plugin_tutorial
<https://github.com/coq/coq/tree/master/doc/plugin_tutorial>`_.
Deprecating library objects or tactics
diff --git a/doc/sphinx/using/tools/coqdoc.rst b/doc/sphinx/using/tools/coqdoc.rst
index 9ac3d2adda..88c1a575d9 100644
--- a/doc/sphinx/using/tools/coqdoc.rst
+++ b/doc/sphinx/using/tools/coqdoc.rst
@@ -253,7 +253,7 @@ The latter cannot be used around some inner parts of a proof, but can
be used around a whole proof.
Lastly, it is possible to adopt a middle-ground approach when the
-desired output is HTML, where a given snippet of Coq material is
+desired output is HTML, where a given snippet of |Coq| material is
hidden by default, but can be made visible with user interaction.
::
@@ -358,11 +358,11 @@ Command line options
**Hyperlink options**
:--glob-from file: Make references using |Coq| globalizations from file
- file. (Such globalizations are obtained with Coq option ``-dump-glob``).
+ file. (Such globalizations are obtained with |Coq| option ``-dump-glob``).
:--no-externals: Do not insert links to the |Coq| standard library.
:--external url coqdir: Use given URL for linking references whose
name starts with prefix ``coqdir``.
- :--coqlib url: Set base URL for the Coq standard library (default is
+ :--coqlib url: Set base URL for the |Coq| standard library (default is
`<http://coq.inria.fr/library/>`_). This is equivalent to ``--external url
Coq``.
:-R dir coqdir: Recursively map physical directory dir to |Coq| logical
diff --git a/doc/sphinx/using/tools/index.rst b/doc/sphinx/using/tools/index.rst
index dfe38dfce9..8543c5de8a 100644
--- a/doc/sphinx/using/tools/index.rst
+++ b/doc/sphinx/using/tools/index.rst
@@ -5,11 +5,11 @@ Command-line and graphical tools
================================
This chapter presents the command-line tools that users will need to
-build their Coq project, the documentation of the CoqIDE standalone
+build their |Coq| project, the documentation of the |CoqIDE| standalone
user interface and the documentation of the parallel proof processing
-feature that is supported by CoqIDE and several other user interfaces.
-A list of available user interfaces to interact with Coq is available
-on the `Coq website <https://coq.inria.fr/user-interfaces.html>`_.
+feature that is supported by |CoqIDE| and several other user interfaces.
+A list of available user interfaces to interact with |Coq| is available
+on the `|Coq| website <https://coq.inria.fr/user-interfaces.html>`_.
.. toctree::
:maxdepth: 1
diff --git a/doc/stdlib/hidden-files b/doc/stdlib/hidden-files
index f39c50238a..e4f0967794 100644
--- a/doc/stdlib/hidden-files
+++ b/doc/stdlib/hidden-files
@@ -1,3 +1,4 @@
+theories/Init/Numeral.v
theories/btauto/Algebra.v
theories/btauto/Btauto.v
theories/btauto/Reflect.v
@@ -50,6 +51,7 @@ theories/micromega/ZCoeff.v
theories/micromega/ZMicromega.v
theories/micromega/ZifyInst.v
theories/micromega/ZifyBool.v
+theories/micromega/ZifyInt63.v
theories/micromega/ZifyComparison.v
theories/micromega/ZifyClasses.v
theories/micromega/ZifyPow.v
diff --git a/doc/stdlib/index-list.html.template b/doc/stdlib/index-list.html.template
index 7c1328916b..b08d7e9d2c 100644
--- a/doc/stdlib/index-list.html.template
+++ b/doc/stdlib/index-list.html.template
@@ -22,7 +22,7 @@ through the <tt>Require Import</tt> command.</p>
theories/Init/Nat.v
theories/Init/Decimal.v
theories/Init/Hexadecimal.v
- theories/Init/Numeral.v
+ theories/Init/Number.v
theories/Init/Peano.v
theories/Init/Specif.v
theories/Init/Tactics.v
@@ -238,6 +238,7 @@ through the <tt>Require Import</tt> command.</p>
theories/Numbers/DecimalN.v
theories/Numbers/DecimalZ.v
theories/Numbers/DecimalQ.v
+ theories/Numbers/DecimalR.v
theories/Numbers/DecimalString.v
theories/Numbers/HexadecimalFacts.v
theories/Numbers/HexadecimalNat.v
@@ -245,6 +246,7 @@ through the <tt>Require Import</tt> command.</p>
theories/Numbers/HexadecimalN.v
theories/Numbers/HexadecimalZ.v
theories/Numbers/HexadecimalQ.v
+ theories/Numbers/HexadecimalR.v
theories/Numbers/HexadecimalString.v
</dd>
diff --git a/doc/tools/docgram/README.md b/doc/tools/docgram/README.md
index 4d38955fa8..dbb04bb6a6 100644
--- a/doc/tools/docgram/README.md
+++ b/doc/tools/docgram/README.md
@@ -42,7 +42,7 @@ for documentation purposes:
First, nonterminals that use levels (`"5" RIGHTA` below) are modified, for example:
```
- tactic_expr:
+ ltac_expr:
[ "5" RIGHTA
[ te = binder_tactic -> { te } ]
[ "4" ...
diff --git a/doc/tools/docgram/common.edit_mlg b/doc/tools/docgram/common.edit_mlg
index a9f9c805d8..97d479b238 100644
--- a/doc/tools/docgram/common.edit_mlg
+++ b/doc/tools/docgram/common.edit_mlg
@@ -28,15 +28,15 @@ strategy_level_or_var: [
| strategy_level
]
-operconstr0: [
-| "ltac" ":" "(" tactic_expr5 ")"
+term0: [
+| "ltac" ":" "(" ltac_expr5 ")"
]
EXTRAARGS_natural: [ | DELETENT ]
EXTRAARGS_lconstr: [ | DELETENT ]
EXTRAARGS_strategy_level: [ | DELETENT ]
G_LTAC_hint: [ | DELETENT ]
-G_LTAC_operconstr0: [ | DELETENT ]
+G_LTAC_term0: [ | DELETENT ]
G_REWRITE_binders: [
| DELETE Pcoq.Constr.binders
@@ -86,7 +86,7 @@ RENAME: [
| G_LTAC2_eqn_ipat ltac2_eqn_ipat
| G_LTAC2_conversion ltac2_conversion
| G_LTAC2_oriented_rewriter ltac2_oriented_rewriter
-| G_LTAC2_tactic_then_gen ltac2_tactic_then_gen
+| G_LTAC2_for_each_goal ltac2_for_each_goal
| G_LTAC2_tactic_then_last ltac2_tactic_then_last
| G_LTAC2_as_name ltac2_as_name
| G_LTAC2_as_ipat ltac2_as_ipat
@@ -94,18 +94,22 @@ RENAME: [
| G_LTAC2_match_list ltac2_match_list
]
-(* renames to eliminate qualified names
- put other renames at the end *)
+(* Renames to eliminate qualified names.
+ Put other renames at the end *)
RENAME: [
(* map missing names for rhs *)
| Constr.constr term
| Constr.global global
| Constr.lconstr lconstr
-| Constr.lconstr_pattern cpattern
+| Constr.cpattern cpattern
| G_vernac.query_command query_command
-| G_vernac.section_subset_expr section_subset_expr
+| G_vernac.section_subset_expr section_var_expr
| Prim.ident ident
| Prim.reference reference
+| Prim.string string
+| Prim.integer integer
+| Prim.qualid qualid
+| Prim.natural natural
| Pvernac.Vernac_.main_entry vernac_control
| Tactic.tactic tactic
@@ -117,7 +121,7 @@ RENAME: [
| Prim.identref ident
| Prim.natural natural
*)
-| Vernac.rec_definition rec_definition
+| Vernac.fix_definition fix_definition
(* todo: hmm, rename adds 1 prodn to closed_binder?? *)
| Constr.closed_binder closed_binder
]
@@ -182,24 +186,20 @@ DELETE: [
(* additional nts to be spliced *)
-hyp: [
-| var
-]
-
tactic_then_last: [
-| REPLACE "|" LIST0 ( OPT tactic_expr5 ) SEP "|"
-| WITH LIST0 ( "|" ( OPT tactic_expr5 ) )
+| REPLACE "|" LIST0 ( OPT ltac_expr5 ) SEP "|"
+| WITH LIST0 ( "|" ( OPT ltac_expr5 ) )
]
goal_tactics: [
-| LIST0 ( OPT tactic_expr5 ) SEP "|"
+| LIST0 ( OPT ltac_expr5 ) SEP "|"
]
-tactic_then_gen: [ | DELETENT ]
+for_each_goal: [ | DELETENT ]
-tactic_then_gen: [
+for_each_goal: [
| goal_tactics
-| OPT ( goal_tactics "|" ) OPT tactic_expr5 ".." OPT ( "|" goal_tactics )
+| OPT ( goal_tactics "|" ) OPT ltac_expr5 ".." OPT ( "|" goal_tactics )
]
tactic_then_last: [
@@ -207,19 +207,19 @@ tactic_then_last: [
]
ltac2_tactic_then_last: [
-| REPLACE "|" LIST0 ( OPT tac2expr6 ) SEP "|" (* Ltac2 plugin *)
-| WITH LIST0 ( "|" OPT tac2expr6 ) TAG Ltac2
+| REPLACE "|" LIST0 ( OPT ltac2_expr6 ) SEP "|" (* Ltac2 plugin *)
+| WITH LIST0 ( "|" OPT ltac2_expr6 ) TAG Ltac2
]
ltac2_goal_tactics: [
-| LIST0 ( OPT tac2expr6 ) SEP "|" TAG Ltac2
+| LIST0 ( OPT ltac2_expr6 ) SEP "|" TAG Ltac2
]
-ltac2_tactic_then_gen: [ | DELETENT ]
+ltac2_for_each_goal: [ | DELETENT ]
-ltac2_tactic_then_gen: [
+ltac2_for_each_goal: [
| ltac2_goal_tactics TAG Ltac2
-| OPT ( ltac2_goal_tactics "|" ) OPT tac2expr6 ".." OPT ( "|" ltac2_goal_tactics ) TAG Ltac2
+| OPT ( ltac2_goal_tactics "|" ) OPT ltac2_expr6 ".." OPT ( "|" ltac2_goal_tactics ) TAG Ltac2
]
ltac2_tactic_then_last: [
@@ -261,60 +261,55 @@ let_type_cstr: [
| type_cstr
]
-(* rename here because we want to use "return_type" for something else *)
-RENAME: [
-| return_type as_return_type
-]
-
case_item: [
-| REPLACE operconstr100 OPT [ "as" name ] OPT [ "in" pattern200 ]
-| WITH operconstr100 OPT ("as" name) OPT [ "in" pattern200 ]
+| REPLACE term100 OPT [ "as" name ] OPT [ "in" pattern200 ]
+| WITH term100 OPT ("as" name) OPT [ "in" pattern200 ]
]
binder_constr: [
-| MOVETO term_forall_or_fun "forall" open_binders "," operconstr200
-| MOVETO term_forall_or_fun "fun" open_binders "=>" operconstr200
-| MOVETO term_let "let" name binders let_type_cstr ":=" operconstr200 "in" operconstr200
-| MOVETO term_if "if" operconstr200 as_return_type "then" operconstr200 "else" operconstr200
-| MOVETO term_fix "let" "fix" fix_decl "in" operconstr200
-| MOVETO term_cofix "let" "cofix" cofix_decl "in" operconstr200
-| MOVETO term_let "let" [ "(" LIST0 name SEP "," ")" | "()" ] as_return_type ":=" operconstr200 "in" operconstr200
-| MOVETO term_let "let" "'" pattern200 ":=" operconstr200 "in" operconstr200
-| MOVETO term_let "let" "'" pattern200 ":=" operconstr200 case_type "in" operconstr200
-| MOVETO term_let "let" "'" pattern200 "in" pattern200 ":=" operconstr200 case_type "in" operconstr200
+| MOVETO term_forall_or_fun "forall" open_binders "," term200
+| MOVETO term_forall_or_fun "fun" open_binders "=>" term200
+| MOVETO term_let "let" name binders let_type_cstr ":=" term200 "in" term200
+| MOVETO term_if "if" term200 as_return_type "then" term200 "else" term200
+| MOVETO term_fix "let" "fix" fix_decl "in" term200
+| MOVETO term_cofix "let" "cofix" cofix_body "in" term200
+| MOVETO term_let "let" [ "(" LIST0 name SEP "," ")" | "()" ] as_return_type ":=" term200 "in" term200
+| MOVETO term_let "let" "'" pattern200 ":=" term200 "in" term200
+| MOVETO term_let "let" "'" pattern200 ":=" term200 case_type "in" term200
+| MOVETO term_let "let" "'" pattern200 "in" pattern200 ":=" term200 case_type "in" term200
| MOVETO term_fix "fix" fix_decls
| MOVETO term_cofix "cofix" cofix_decls
]
term_let: [
-| REPLACE "let" name binders let_type_cstr ":=" operconstr200 "in" operconstr200
-| WITH "let" name let_type_cstr ":=" operconstr200 "in" operconstr200
-| "let" name LIST1 binder let_type_cstr ":=" operconstr200 "in" operconstr200
+| REPLACE "let" name binders let_type_cstr ":=" term200 "in" term200
+| WITH "let" name let_type_cstr ":=" term200 "in" term200
+| "let" name LIST1 binder let_type_cstr ":=" term200 "in" term200
(* Don't need to document that "( )" is equivalent to "()" *)
-| REPLACE "let" [ "(" LIST0 name SEP "," ")" | "()" ] as_return_type ":=" operconstr200 "in" operconstr200
-| WITH "let" "(" LIST0 name SEP "," ")" as_return_type ":=" operconstr200 "in" operconstr200
-| REPLACE "let" "'" pattern200 ":=" operconstr200 "in" operconstr200
-| WITH "let" "'" pattern200 ":=" operconstr200 OPT case_type "in" operconstr200
-| DELETE "let" "'" pattern200 ":=" operconstr200 case_type "in" operconstr200
+| REPLACE "let" [ "(" LIST0 name SEP "," ")" | "()" ] as_return_type ":=" term200 "in" term200
+| WITH "let" "(" LIST0 name SEP "," ")" as_return_type ":=" term200 "in" term200
+| REPLACE "let" "'" pattern200 ":=" term200 "in" term200
+| WITH "let" "'" pattern200 ":=" term200 OPT case_type "in" term200
+| DELETE "let" "'" pattern200 ":=" term200 case_type "in" term200
]
atomic_constr: [
-| MOVETO qualid_annotated global univ_instance
+| MOVETO qualid_annotated global univ_annot
| MOVETO primitive_notations NUMBER
| MOVETO primitive_notations string
| MOVETO term_evar "_"
-| REPLACE "?" "[" ident "]"
-| WITH "?[" ident "]"
-| MOVETO term_evar "?[" ident "]"
+| REPLACE "?" "[" identref "]"
+| WITH "?[" identref "]"
+| MOVETO term_evar "?[" identref "]"
| REPLACE "?" "[" pattern_ident "]"
| WITH "?[" pattern_ident "]"
| MOVETO term_evar "?[" pattern_ident "]"
| MOVETO term_evar pattern_ident evar_instance
]
-tactic_expr0: [
-| REPLACE "[" ">" tactic_then_gen "]"
-| WITH "[>" tactic_then_gen "]"
+ltac_expr0: [
+| REPLACE "[" ">" for_each_goal "]"
+| WITH "[>" for_each_goal "]"
]
(* lexer token *)
@@ -341,68 +336,68 @@ scope_delimiter: [
]
type: [
-| operconstr200
+| term200
]
-operconstr100: [
-| REPLACE operconstr99 "<:" operconstr200
-| WITH operconstr99 "<:" type
-| MOVETO term_cast operconstr99 "<:" type
-| REPLACE operconstr99 "<<:" operconstr200
-| WITH operconstr99 "<<:" type
-| MOVETO term_cast operconstr99 "<<:" type
-| REPLACE operconstr99 ":" operconstr200
-| WITH operconstr99 ":" type
-| MOVETO term_cast operconstr99 ":" type
-| MOVETO term_cast operconstr99 ":>"
+term100: [
+| REPLACE term99 "<:" term200
+| WITH term99 "<:" type
+| MOVETO term_cast term99 "<:" type
+| REPLACE term99 "<<:" term200
+| WITH term99 "<<:" type
+| MOVETO term_cast term99 "<<:" type
+| REPLACE term99 ":" term200
+| WITH term99 ":" type
+| MOVETO term_cast term99 ":" type
+| MOVETO term_cast term99 ":>"
]
constr: [
-| REPLACE "@" global univ_instance
+| REPLACE "@" global univ_annot
| WITH "@" qualid_annotated
| MOVETO term_explicit "@" qualid_annotated
]
-operconstr10: [
+term10: [
(* Separate this LIST0 in the nonempty and the empty case *)
(* The empty case is covered by constr *)
-| REPLACE "@" global univ_instance LIST0 operconstr9
-| WITH "@" qualid_annotated LIST1 operconstr9
-| REPLACE operconstr9
+| REPLACE "@" global univ_annot LIST0 term9
+| WITH "@" qualid_annotated LIST1 term9
+| REPLACE term9
| WITH constr
-| MOVETO term_application operconstr9 LIST1 appl_arg
-| MOVETO term_application "@" qualid_annotated LIST1 operconstr9
+| MOVETO term_application term9 LIST1 arg
+| MOVETO term_application "@" qualid_annotated LIST1 term9
(* fixme: add in as a prodn somewhere *)
-| MOVETO dangling_pattern_extension_rule "@" pattern_identref LIST1 identref
+| MOVETO dangling_pattern_extension_rule "@" pattern_ident LIST1 identref
| DELETE dangling_pattern_extension_rule
]
-operconstr9: [
+term9: [
(* @Zimmi48: Special token .. is for use in the Notation command. (see bug_3304.v) *)
-| DELETE ".." operconstr0 ".."
+| DELETE ".." term0 ".."
]
-operconstr1: [
-| REPLACE operconstr0 ".(" global LIST0 appl_arg ")"
-| WITH operconstr0 ".(" global LIST0 appl_arg ")" (* huh? *)
-| REPLACE operconstr0 "%" IDENT
-| WITH operconstr0 "%" scope_key
-| MOVETO term_scope operconstr0 "%" scope_key
-| MOVETO term_projection operconstr0 ".(" global LIST0 appl_arg ")"
-| MOVETO term_projection operconstr0 ".(" "@" global LIST0 ( operconstr9 ) ")"
+term1: [
+| REPLACE term0 ".(" global LIST0 arg ")"
+| WITH term0 ".(" global LIST0 arg ")" (* huh? *)
+| REPLACE term0 "%" IDENT
+| WITH term0 "%" scope_key
+| MOVETO term_scope term0 "%" scope_key
+| MOVETO term_projection term0 ".(" global LIST0 arg ")"
+| MOVETO term_projection term0 ".(" "@" global LIST0 ( term9 ) ")"
]
-operconstr0: [
+term0: [
(* @Zimmi48: This rule is a hack, according to Hugo, and should not be shown in the manual. *)
| DELETE "{" binder_constr "}"
| REPLACE "{|" record_declaration bar_cbrace
-| WITH "{|" LIST0 field_def bar_cbrace
-| MOVETO term_record "{|" LIST0 field_def bar_cbrace
-| MOVETO term_generalizing "`{" operconstr200 "}"
-| MOVETO term_generalizing "`(" operconstr200 ")"
-| MOVETO term_ltac "ltac" ":" "(" tactic_expr5 ")"
-| REPLACE "[" "|" array_elems "|" lconstr type_cstr "|" "]" univ_instance
-| WITH "[|" array_elems "|" lconstr type_cstr "|]" univ_instance
+| WITH "{|" LIST0 field_def SEP ";" OPT ";" bar_cbrace
+| MOVETO term_record "{|" LIST0 field_def SEP ";" OPT ";" bar_cbrace
+| MOVETO term_generalizing "`{" term200 "}"
+| MOVETO term_generalizing "`(" term200 ")"
+| MOVETO term_ltac "ltac" ":" "(" ltac_expr5 ")"
+| REPLACE "[" "|" array_elems "|" lconstr type_cstr "|" "]" univ_annot
+| WITH "[|" array_elems "|" lconstr type_cstr "|]" univ_annot
]
fix_decls: [
@@ -412,9 +407,9 @@ fix_decls: [
]
cofix_decls: [
-| DELETE cofix_decl
-| REPLACE cofix_decl "with" LIST1 cofix_decl SEP "with" "for" identref
-| WITH cofix_decl OPT ( LIST1 ( "with" cofix_decl ) "for" identref )
+| DELETE cofix_body
+| REPLACE cofix_body "with" LIST1 cofix_body SEP "with" "for" identref
+| WITH cofix_body OPT ( LIST1 ( "with" cofix_body ) "for" identref )
]
fields_def: [
@@ -485,11 +480,11 @@ name_colon: [
]
typeclass_constraint: [
-| EDIT ADD_OPT "!" operconstr200
-| REPLACE "{" name "}" ":" [ "!" | ] operconstr200
-| WITH "{" name "}" ":" OPT "!" operconstr200
-| REPLACE name ":" [ "!" | ] operconstr200
-| WITH name ":" OPT "!" operconstr200
+| EDIT ADD_OPT "!" term200
+| REPLACE "{" name "}" ":" [ "!" | ] term200
+| WITH "{" name "}" ":" OPT "!" term200
+| REPLACE name ":" [ "!" | ] term200
+| WITH name ":" OPT "!" term200
]
(* ?? From the grammar, Prim.name seems to be only "_" but ident is also accepted "*)
@@ -545,7 +540,13 @@ evar_instance: [
(* No constructor syntax, OPT [ "|" binders ] is not supported for Record *)
record_definition: [
-| opt_coercion ident_decl binders OPT [ ":" type ] OPT [ identref ] "{" record_fields "}" decl_notations
+| opt_coercion ident_decl binders OPT [ ":" sort ] OPT ( ":=" OPT [ identref ] "{" record_fields "}" )
+]
+
+(* No mutual recursion, no inductive classes, type must be a sort *)
+(* constructor is optional but "Class record_definition" covers that case *)
+singleton_class_definition: [
+| opt_coercion ident_decl binders OPT [ ":" sort ] ":=" constructor
]
(* No record syntax, opt_coercion not supported for Variant, := ... required *)
@@ -562,15 +563,16 @@ gallina: [
| "CoInductive" inductive_definition LIST0 ( "with" inductive_definition )
| "Variant" variant_definition LIST0 ( "with" variant_definition )
| [ "Record" | "Structure" ] record_definition LIST0 ( "with" record_definition )
-| "Class" inductive_definition LIST0 ( "with" inductive_definition )
-| REPLACE "Fixpoint" LIST1 rec_definition SEP "with"
-| WITH "Fixpoint" rec_definition LIST0 ( "with" rec_definition )
-| REPLACE "Let" "Fixpoint" LIST1 rec_definition SEP "with"
-| WITH "Let" "Fixpoint" rec_definition LIST0 ( "with" rec_definition )
-| REPLACE "CoFixpoint" LIST1 corec_definition SEP "with"
-| WITH "CoFixpoint" corec_definition LIST0 ( "with" corec_definition )
-| REPLACE "Let" "CoFixpoint" LIST1 corec_definition SEP "with"
-| WITH "Let" "CoFixpoint" corec_definition LIST0 ( "with" corec_definition )
+| "Class" record_definition
+| "Class" singleton_class_definition
+| REPLACE "Fixpoint" LIST1 fix_definition SEP "with"
+| WITH "Fixpoint" fix_definition LIST0 ( "with" fix_definition )
+| REPLACE "Let" "Fixpoint" LIST1 fix_definition SEP "with"
+| WITH "Let" "Fixpoint" fix_definition LIST0 ( "with" fix_definition )
+| REPLACE "CoFixpoint" LIST1 cofix_definition SEP "with"
+| WITH "CoFixpoint" cofix_definition LIST0 ( "with" cofix_definition )
+| REPLACE "Let" "CoFixpoint" LIST1 cofix_definition SEP "with"
+| WITH "Let" "CoFixpoint" cofix_definition LIST0 ( "with" cofix_definition )
| REPLACE "Scheme" LIST1 scheme SEP "with"
| WITH "Scheme" scheme LIST0 ( "with" scheme )
]
@@ -579,13 +581,13 @@ finite_token: [
| DELETENT
]
-constructor_list_or_record_decl: [
+constructors_or_record: [
| OPTINREF
]
record_fields: [
| REPLACE record_field ";" record_fields
-| WITH LIST0 record_field SEP ";"
+| WITH LIST0 record_field SEP ";" OPT ";"
| DELETE record_field
| DELETE (* empty *)
]
@@ -601,7 +603,7 @@ inline: [
| OPTINREF
]
-univ_instance: [
+univ_annot: [
| OPTINREF
]
@@ -610,15 +612,15 @@ univ_decl: [
| WITH "@{" LIST0 identref OPT "+" OPT [ "|" LIST0 univ_constraint SEP "," OPT "+" ] "}"
]
-of_type_with_opt_coercion: [
+of_type: [
| DELETENT
]
-of_type_with_opt_coercion: [
+of_type: [
| [ ":" | ":>" ] type
]
-attribute_value: [
+attr_value: [
| OPTINREF
]
@@ -654,14 +656,6 @@ ltac2_branches: [
| OPTINREF
]
-RENAME: [
-| red_flag ltac2_red_flag
-| red_flags red_flag
-]
-
-RENAME: [
-]
-
strategy_flag: [
| REPLACE OPT delta_flag
| WITH delta_flag
@@ -694,8 +688,8 @@ is_module_type: [
]
gallina_ext: [
-| REPLACE "Arguments" smart_global LIST0 argument_spec_block OPT [ "," LIST1 [ LIST0 more_implicits_block ] SEP "," ] OPT [ ":" LIST1 arguments_modifier SEP "," ]
-| WITH "Arguments" smart_global LIST0 argument_spec_block LIST0 [ "," LIST0 more_implicits_block ] OPT [ ":" LIST1 arguments_modifier SEP "," ]
+| REPLACE "Arguments" smart_global LIST0 arg_specs OPT [ "," LIST1 [ LIST0 implicits_alt ] SEP "," ] OPT [ ":" LIST1 args_modifier SEP "," ]
+| WITH "Arguments" smart_global LIST0 arg_specs LIST0 [ "," LIST0 implicits_alt ] OPT [ ":" LIST1 args_modifier SEP "," ]
| REPLACE "Implicit" "Type" reserv_list
| WITH "Implicit" [ "Type" | "Types" ] reserv_list
| DELETE "Implicit" "Types" reserv_list
@@ -713,6 +707,10 @@ gallina_ext: [
| REPLACE "Coercion" by_notation ":" class_rawexpr ">->" class_rawexpr
| WITH "Coercion" smart_global ":" class_rawexpr ">->" class_rawexpr
+(* semantically restricted per https://github.com/coq/coq/pull/12936#discussion_r492705820 *)
+| REPLACE "Coercion" global OPT univ_decl def_body
+| WITH "Coercion" ident OPT univ_decl def_body
+
| REPLACE "Include" "Type" module_type_inl LIST0 ext_module_type
| WITH "Include" "Type" LIST1 module_type_inl SEP "<+"
@@ -720,12 +718,12 @@ gallina_ext: [
| WITH "Generalizable" [ [ "Variable" | "Variables" ] LIST1 identref | "All" "Variables" | "No" "Variables" ]
(* don't show Export for Set, Unset *)
-| REPLACE "Export" "Set" option_table option_setting
-| WITH "Set" option_table option_setting
-| REPLACE "Export" "Unset" option_table
-| WITH "Unset" option_table
-| REPLACE "Instance" instance_name ":" operconstr200 hint_info [ ":=" "{" record_declaration "}" | ":=" lconstr | ]
-| WITH "Instance" instance_name ":" operconstr200 hint_info OPT [ ":=" "{" record_declaration "}" | ":=" lconstr ]
+| REPLACE "Export" "Set" setting_name option_setting
+| WITH "Set" setting_name option_setting
+| REPLACE "Export" "Unset" setting_name
+| WITH "Unset" setting_name
+| REPLACE "Instance" instance_name ":" term200 hint_info [ ":=" "{" record_declaration "}" | ":=" lconstr | ]
+| WITH "Instance" instance_name ":" type hint_info OPT [ ":=" "{" record_declaration "}" | ":=" lconstr ]
| REPLACE "From" global "Require" export_token LIST1 global
| WITH "From" dirpath "Require" export_token LIST1 global
@@ -815,92 +813,92 @@ DELETE: [
| tactic_then_locality
]
-tactic_expr5: [
-(* make these look consistent with use of binder_tactic in other tactic_expr* *)
+ltac_expr5: [
+(* make these look consistent with use of binder_tactic in other ltac_expr* *)
| DELETE binder_tactic
-| DELETE tactic_expr4
-| [ tactic_expr4 | binder_tactic ]
+| DELETE ltac_expr4
+| [ ltac_expr4 | binder_tactic ]
]
ltac_constructs: [
(* repeated in main ltac grammar - need to create a COPY edit *)
-| tactic_expr3 ";" [ tactic_expr3 | binder_tactic ]
-| tactic_expr3 ";" "[" tactic_then_gen "]"
+| ltac_expr3 ";" [ ltac_expr3 | binder_tactic ]
+| ltac_expr3 ";" "[" for_each_goal "]"
-| tactic_expr1 "+" [ tactic_expr2 | binder_tactic ]
-| tactic_expr1 "||" [ tactic_expr2 | binder_tactic ]
+| ltac_expr1 "+" [ ltac_expr2 | binder_tactic ]
+| ltac_expr1 "||" [ ltac_expr2 | binder_tactic ]
-(* | qualid LIST0 tactic_arg add later due renaming tactic_arg *)
+(* | qualid LIST0 tactic_value add later due renaming tactic_value *)
-| "[>" tactic_then_gen "]"
-| toplevel_selector tactic_expr5
+| "[>" for_each_goal "]"
+| toplevel_selector ltac_expr5
]
-tactic_expr4: [
-| REPLACE tactic_expr3 ";" tactic_then_gen "]"
-| WITH tactic_expr3 ";" "[" tactic_then_gen "]"
-| REPLACE tactic_expr3 ";" binder_tactic
-| WITH tactic_expr3 ";" [ tactic_expr3 | binder_tactic ]
-| DELETE tactic_expr3 ";" tactic_expr3
+ltac_expr4: [
+| REPLACE ltac_expr3 ";" for_each_goal "]"
+| WITH ltac_expr3 ";" "[" for_each_goal "]"
+| REPLACE ltac_expr3 ";" binder_tactic
+| WITH ltac_expr3 ";" [ ltac_expr3 | binder_tactic ]
+| DELETE ltac_expr3 ";" ltac_expr3
]
l3_tactic: [ ]
-tactic_expr3: [
-| DELETE "abstract" tactic_expr2
-| REPLACE "abstract" tactic_expr2 "using" ident
-| WITH "abstract" tactic_expr2 OPT ( "using" ident )
+ltac_expr3: [
+| DELETE "abstract" ltac_expr2
+| REPLACE "abstract" ltac_expr2 "using" ident
+| WITH "abstract" ltac_expr2 OPT ( "using" ident )
| l3_tactic
| MOVEALLBUT ltac_builtins
| l3_tactic
-| tactic_expr2
+| ltac_expr2
]
l2_tactic: [ ]
-tactic_expr2: [
-| REPLACE tactic_expr1 "+" binder_tactic
-| WITH tactic_expr1 "+" [ tactic_expr2 | binder_tactic ]
-| DELETE tactic_expr1 "+" tactic_expr2
-| REPLACE tactic_expr1 "||" binder_tactic
-| WITH tactic_expr1 "||" [ tactic_expr2 | binder_tactic ]
-| DELETE tactic_expr1 "||" tactic_expr2
-| MOVETO ltac_builtins "tryif" tactic_expr5 "then" tactic_expr5 "else" tactic_expr2
+ltac_expr2: [
+| REPLACE ltac_expr1 "+" binder_tactic
+| WITH ltac_expr1 "+" [ ltac_expr2 | binder_tactic ]
+| DELETE ltac_expr1 "+" ltac_expr2
+| REPLACE ltac_expr1 "||" binder_tactic
+| WITH ltac_expr1 "||" [ ltac_expr2 | binder_tactic ]
+| DELETE ltac_expr1 "||" ltac_expr2
+| MOVETO ltac_builtins "tryif" ltac_expr5 "then" ltac_expr5 "else" ltac_expr2
| l2_tactic
| DELETE ltac_builtins
]
l1_tactic: [ ]
-tactic_expr1: [
+ltac_expr1: [
| EDIT match_key ADD_OPT "reverse" "goal" "with" match_context_list "end"
| MOVETO simple_tactic match_key OPT "reverse" "goal" "with" match_context_list "end"
-| MOVETO simple_tactic match_key tactic_expr5 "with" match_list "end"
+| MOVETO simple_tactic match_key ltac_expr5 "with" match_list "end"
| REPLACE failkw [ int_or_var | ] LIST0 message_token
| WITH failkw OPT int_or_var LIST0 message_token
-| REPLACE reference LIST0 tactic_arg_compat
-| WITH reference LIST1 tactic_arg_compat
+| REPLACE reference LIST0 tactic_arg
+| WITH reference LIST1 tactic_arg
| l1_tactic
| DELETE simple_tactic
| MOVEALLBUT ltac_builtins
| l1_tactic
-| tactic_arg
-| reference LIST1 tactic_arg_compat
-| tactic_expr0
+| tactic_value
+| reference LIST1 tactic_arg
+| ltac_expr0
]
(* split match_context_rule *)
goal_pattern: [
-| LIST0 match_hyps SEP "," "|-" match_pattern
-| "[" LIST0 match_hyps SEP "," "|-" match_pattern "]"
+| LIST0 match_hyp SEP "," "|-" match_pattern
+| "[" LIST0 match_hyp SEP "," "|-" match_pattern "]"
| "_"
]
match_context_rule: [
-| DELETE LIST0 match_hyps SEP "," "|-" match_pattern "=>" tactic_expr5
-| DELETE "[" LIST0 match_hyps SEP "," "|-" match_pattern "]" "=>" tactic_expr5
-| DELETE "_" "=>" tactic_expr5
-| goal_pattern "=>" tactic_expr5
+| DELETE LIST0 match_hyp SEP "," "|-" match_pattern "=>" ltac_expr5
+| DELETE "[" LIST0 match_hyp SEP "," "|-" match_pattern "]" "=>" ltac_expr5
+| DELETE "_" "=>" ltac_expr5
+| goal_pattern "=>" ltac_expr5
]
match_context_list: [
@@ -913,10 +911,10 @@ match_list: [
match_rule: [
(* redundant; match_pattern -> term -> _ *)
-| DELETE "_" "=>" tactic_expr5
+| DELETE "_" "=>" ltac_expr5
]
-selector_body: [
+selector: [
| REPLACE range_selector_or_nth (* depends on whether range_selector_or_nth is deleted first *)
| WITH LIST1 range_selector SEP ","
]
@@ -1083,8 +1081,8 @@ simple_tactic: [
| EDIT "psatz_R" ADD_OPT int_or_var tactic
| EDIT "psatz_Q" ADD_OPT int_or_var tactic
| EDIT "psatz_Z" ADD_OPT int_or_var tactic
-| REPLACE "subst" LIST1 var
-| WITH "subst" OPT ( LIST1 var )
+| REPLACE "subst" LIST1 hyp
+| WITH "subst" LIST0 hyp
| DELETE "subst"
| DELETE "congruence"
| DELETE "congruence" natural
@@ -1095,10 +1093,18 @@ simple_tactic: [
| REPLACE "show" "ltac" "profile" "cutoff" integer
| WITH "show" "ltac" "profile" OPT [ "cutoff" integer | string ]
| DELETE "show" "ltac" "profile" string
-(* perversely, the mlg uses "tactic3" instead of "tactic_expr3" *)
+(* perversely, the mlg uses "tactic3" instead of "ltac_expr3" *)
| DELETE "transparent_abstract" tactic3
| REPLACE "transparent_abstract" tactic3 "using" ident
-| WITH "transparent_abstract" tactic_expr3 OPT ( "using" ident )
+| WITH "transparent_abstract" ltac_expr3 OPT ( "using" ident )
+| "typeclasses" "eauto" OPT "bfs" OPT int_or_var OPT ( "with" LIST1 preident )
+| DELETE "typeclasses" "eauto" "bfs" OPT int_or_var "with" LIST1 preident
+| DELETE "typeclasses" "eauto" OPT int_or_var "with" LIST1 preident
+| DELETE "typeclasses" "eauto" "bfs" OPT int_or_var
+| DELETE "typeclasses" "eauto" OPT int_or_var
+(* in Tactic Notation: *)
+| "setoid_replace" constr "with" constr OPT ( "using" "relation" constr ) OPT ( "in" hyp )
+ OPT ( "at" LIST1 int_or_var ) OPT ( "by" ltac_expr3 )
]
(* todo: don't use DELETENT for this *)
@@ -1130,14 +1136,31 @@ printable: [
| INSERTALL "Print"
]
+add_zify: [
+| [ "InjTyp" | "BinOp" | "UnOp" | "CstOp" | "BinRel" | "UnOpSpec" | "BinOpSpec" ] TAG Micromega
+| [ "PropOp" | "PropBinOp" | "PropUOp" | "Saturate" ]TAG Micromega
+]
+
+show_zify: [
+| [ "InjTyp" | "BinOp" | "UnOp" | "CstOp" | "BinRel" | "UnOpSpec" | "BinOpSpec" | "Spec" ] TAG Micromega
+]
+
+scheme_kind: [
+| DELETE "Induction" "for" smart_global "Sort" sort_family
+| DELETE "Minimality" "for" smart_global "Sort" sort_family
+| DELETE "Elimination" "for" smart_global "Sort" sort_family
+| DELETE "Case" "for" smart_global "Sort" sort_family
+| [ "Induction" | "Minimality" | "Elimination" | "Case" ] "for" smart_global "Sort" sort_family
+]
+
command: [
| REPLACE "Print" printable
| WITH printable
| "SubClass" ident_decl def_body
| REPLACE "Ltac" LIST1 ltac_tacdef_body SEP "with"
| WITH "Ltac" ltac_tacdef_body LIST0 ( "with" ltac_tacdef_body )
-| REPLACE "Function" LIST1 function_rec_definition_loc SEP "with" (* funind plugin *)
-| WITH "Function" function_rec_definition_loc LIST0 ( "with" function_rec_definition_loc ) (* funind plugin *)
+| REPLACE "Function" LIST1 function_fix_definition SEP "with" (* funind plugin *)
+| WITH "Function" function_fix_definition LIST0 ( "with" function_fix_definition ) (* funind plugin *)
| REPLACE "Functional" "Scheme" LIST1 fun_scheme_arg SEP "with" (* funind plugin *)
| WITH "Functional" "Scheme" fun_scheme_arg LIST0 ( "with" fun_scheme_arg ) (* funind plugin *)
| DELETE "Cd"
@@ -1148,16 +1171,16 @@ command: [
| WITH "Back" OPT natural
| REPLACE "Load" [ "Verbose" | ] [ ne_string | IDENT ]
| WITH "Load" OPT "Verbose" [ ne_string | IDENT ]
-| DELETE "Unset" option_table
-| REPLACE "Set" option_table option_setting
-| WITH OPT "Export" "Set" option_table (* set flag *)
-| REPLACE "Test" option_table "for" LIST1 table_value
-| WITH "Test" option_table OPT ( "for" LIST1 table_value )
-| DELETE "Test" option_table
+| DELETE "Unset" setting_name
+| REPLACE "Set" setting_name option_setting
+| WITH OPT "Export" "Set" setting_name (* set flag *)
+| REPLACE "Test" setting_name "for" LIST1 table_value
+| WITH "Test" setting_name OPT ( "for" LIST1 table_value )
+| DELETE "Test" setting_name
(* hide the fact that table names are limited to 2 IDENTs *)
| REPLACE "Add" IDENT IDENT LIST1 table_value
-| WITH "Add" option_table LIST1 table_value
+| WITH "Add" setting_name LIST1 table_value
| DELETE "Add" IDENT LIST1 table_value
| DELETE "Add" "Parametric" "Relation" binders ":" constr constr "reflexivity" "proved" "by" constr "symmetry" "proved" "by" constr "as" ident
| DELETE "Add" "Parametric" "Relation" binders ":" constr constr "reflexivity" "proved" "by" constr "as" ident
@@ -1202,7 +1225,7 @@ command: [
| WITH "Next" "Obligation" OPT ( "of" ident ) withtac
| DELETE "Next" "Obligation" withtac
| REPLACE "Obligation" natural "of" ident ":" lglob withtac
-| WITH "Obligation" natural OPT ( "of" ident ) OPT ( ":" lglob withtac )
+| WITH "Obligation" natural OPT ( "of" ident ) OPT ( ":" type withtac )
| DELETE "Obligation" natural "of" ident withtac
| DELETE "Obligation" natural ":" lglob withtac
| DELETE "Obligation" natural withtac
@@ -1215,7 +1238,7 @@ command: [
(* hide the fact that table names are limited to 2 IDENTs *)
| REPLACE "Remove" IDENT IDENT LIST1 table_value
-| WITH "Remove" option_table LIST1 table_value
+| WITH "Remove" setting_name LIST1 table_value
| DELETE "Remove" IDENT LIST1 table_value
| DELETE "Restore" "State" IDENT
| DELETE "Restore" "State" ne_string
@@ -1232,13 +1255,14 @@ command: [
| REPLACE "Solve" "All" "Obligations" "with" tactic
| WITH "Solve" "All" "Obligations" OPT ( "with" tactic )
| DELETE "Solve" "All" "Obligations"
+| DELETE "Solve" "Obligations" "of" ident "with" tactic
+| DELETE "Solve" "Obligations" "of" ident
+| DELETE "Solve" "Obligations" "with" tactic
+| DELETE "Solve" "Obligations"
+| "Solve" "Obligations" OPT ( "of" ident ) OPT ( "with" tactic )
| REPLACE "Solve" "Obligation" natural "of" ident "with" tactic
| WITH "Solve" "Obligation" natural OPT ( "of" ident ) "with" tactic
-| DELETE "Solve" "Obligations"
| DELETE "Solve" "Obligation" natural "with" tactic
-| REPLACE "Solve" "Obligations" "of" ident "with" tactic
-| WITH "Solve" "Obligations" OPT ( OPT ( "of" ident ) "with" tactic )
-| DELETE "Solve" "Obligations" "with" tactic
| DELETE "Undo"
| DELETE "Undo" natural
| REPLACE "Undo" "To" natural
@@ -1261,12 +1285,38 @@ command: [
| WITH "Declare" "Scope" scope_name
(* odd that these are in command while other notation-related ones are in syntax *)
-| REPLACE "Numeral" "Notation" reference reference reference ":" ident numnotoption
-| WITH "Numeral" "Notation" reference reference reference ":" scope_name numnotoption
-| REPLACE "String" "Notation" reference reference reference ":" ident
-| WITH "String" "Notation" reference reference reference ":" scope_name
+| REPLACE "Number" "Notation" reference reference reference OPT number_options ":" ident
+| WITH "Number" "Notation" reference reference reference OPT number_options ":" scope_name
+| REPLACE "Numeral" "Notation" reference reference reference ":" ident deprecated_number_modifier
+| WITH "Numeral" "Notation" reference reference reference ":" scope_name deprecated_number_modifier
+| REPLACE "String" "Notation" reference reference reference OPT string_option ":" ident
+| WITH "String" "Notation" reference reference reference OPT string_option ":" scope_name
| DELETE "Ltac2" ltac2_entry (* was split up *)
+| DELETE "Add" "Zify" "InjTyp" constr (* micromega plugin *)
+| DELETE "Add" "Zify" "BinOp" constr (* micromega plugin *)
+| DELETE "Add" "Zify" "UnOp" constr (* micromega plugin *)
+| DELETE "Add" "Zify" "CstOp" constr (* micromega plugin *)
+| DELETE "Add" "Zify" "BinRel" constr (* micromega plugin *)
+| DELETE "Add" "Zify" "PropOp" constr (* micromega plugin *)
+| DELETE "Add" "Zify" "PropBinOp" constr (* micromega plugin *)
+| DELETE "Add" "Zify" "PropUOp" constr (* micromega plugin *)
+| DELETE "Add" "Zify" "BinOpSpec" constr (* micromega plugin *)
+| DELETE "Add" "Zify" "UnOpSpec" constr (* micromega plugin *)
+| DELETE "Add" "Zify" "Saturate" constr (* micromega plugin *)
+| "Add" "Zify" add_zify constr TAG Micromega
+
+| DELETE "Show" "Zify" "InjTyp" (* micromega plugin *)
+| DELETE "Show" "Zify" "BinOp" (* micromega plugin *)
+| DELETE "Show" "Zify" "UnOp" (* micromega plugin *)
+| DELETE "Show" "Zify" "CstOp" (* micromega plugin *)
+| DELETE "Show" "Zify" "BinRel" (* micromega plugin *)
+| DELETE "Show" "Zify" "UnOpSpec" (* micromega plugin *)
+| DELETE "Show" "Zify" "BinOpSpec" (* micromega plugin *)
+(* keep this one | "Show" "Zify" "Spec" (* micromega plugin *)*)
+| "Show" "Zify" show_zify TAG Micromega
+| REPLACE "Goal" lconstr
+| WITH "Goal" type
]
option_setting: [
@@ -1298,7 +1348,7 @@ syntax_modifier: [
| WITH LIST1 IDENT SEP "," "at" level
]
-syntax_extension_type: [
+explicit_subentry: [
| REPLACE "strict" "pattern" "at" "level" natural
| WITH "strict" "pattern" OPT ( "at" "level" natural )
| DELETE "strict" "pattern"
@@ -1308,31 +1358,27 @@ syntax_extension_type: [
| DELETE "constr" (* covered by another prod *)
]
-numnotoption: [
-| OPTINREF
-]
-
binder_tactic: [
-| REPLACE "let" [ "rec" | ] LIST1 let_clause SEP "with" "in" tactic_expr5
-| WITH "let" OPT "rec" let_clause LIST0 ( "with" let_clause ) "in" tactic_expr5
+| REPLACE "let" [ "rec" | ] LIST1 let_clause SEP "with" "in" ltac_expr5
+| WITH "let" OPT "rec" let_clause LIST0 ( "with" let_clause ) "in" ltac_expr5
| MOVEALLBUT ltac_builtins
]
-record_binder_body: [
-| REPLACE binders of_type_with_opt_coercion lconstr
-| WITH binders of_type_with_opt_coercion
-| REPLACE binders of_type_with_opt_coercion lconstr ":=" lconstr
-| WITH binders of_type_with_opt_coercion ":=" lconstr
+field_body: [
+| REPLACE binders of_type lconstr
+| WITH binders of_type
+| REPLACE binders of_type lconstr ":=" lconstr
+| WITH binders of_type ":=" lconstr
]
-simple_assum_coe: [
-| REPLACE LIST1 ident_decl of_type_with_opt_coercion lconstr
-| WITH LIST1 ident_decl of_type_with_opt_coercion
+assumpt: [
+| REPLACE LIST1 ident_decl of_type lconstr
+| WITH LIST1 ident_decl of_type
]
constructor_type: [
-| REPLACE binders [ of_type_with_opt_coercion lconstr | ]
-| WITH binders OPT of_type_with_opt_coercion
+| REPLACE binders [ of_type lconstr | ]
+| WITH binders OPT of_type
]
(* todo: is this really correct? Search for "Pvernac.register_proof_mode" *)
@@ -1376,12 +1422,12 @@ legacy_attr: [
sentence: [ ] (* productions defined below *)
-rec_definition: [
+fix_definition: [
| REPLACE ident_decl binders_fixannot type_cstr OPT [ ":=" lconstr ] decl_notations
| WITH ident_decl binders_fixannot type_cstr OPT [ ":=" lconstr ] decl_notations
]
-corec_definition: [
+cofix_definition: [
| REPLACE ident_decl binders type_cstr OPT [ ":=" lconstr ] decl_notations
| WITH ident_decl binders type_cstr OPT [ ":=" lconstr ] decl_notations
]
@@ -1394,11 +1440,11 @@ type_cstr: [
inductive_definition: [
| REPLACE opt_coercion ident_decl binders OPT [ "|" binders ] OPT [ ":" lconstr ] opt_constructors_or_fields decl_notations
-| WITH opt_coercion ident_decl binders OPT [ "|" binders ] OPT [ ":" type ] opt_constructors_or_fields decl_notations
+| WITH opt_coercion ident_decl binders OPT [ "|" binders ] OPT [ ":" type ] opt_constructors_or_fields decl_notations
]
(* note that constructor -> identref constructor_type *)
-constructor_list_or_record_decl: [
+constructors_or_record: [
| DELETE "|" LIST1 constructor SEP "|"
| REPLACE identref constructor_type "|" LIST1 constructor SEP "|"
| WITH OPT "|" LIST1 constructor SEP "|"
@@ -1409,8 +1455,8 @@ constructor_list_or_record_decl: [
]
record_binder: [
-| REPLACE name record_binder_body
-| WITH name OPT record_binder_body
+| REPLACE name field_body
+| WITH name OPT field_body
| DELETE name
]
@@ -1577,7 +1623,7 @@ ltac2_rewriter: [
| OPT natural OPT [ "?" | "!" ] ltac2_constr_with_bindings
]
-tac2expr0: [
+ltac2_expr0: [
| DELETE "(" ")"
]
@@ -1617,7 +1663,7 @@ eauto_search_strategy: [
constr_body: [
| DELETE ":=" lconstr
| REPLACE ":" lconstr ":=" lconstr
-| WITH OPT ( ":" lconstr ) ":=" lconstr
+| WITH OPT ( ":" type ) ":=" lconstr
]
opt_hintbases: [
@@ -1754,9 +1800,9 @@ input_fun: [
]
let_clause: [
-| DELETE identref ":=" tactic_expr5
-| REPLACE "_" ":=" tactic_expr5
-| WITH name ":=" tactic_expr5
+| DELETE identref ":=" ltac_expr5
+| REPLACE "_" ":=" ltac_expr5
+| WITH name ":=" ltac_expr5
]
tactic_mode: [
@@ -1769,13 +1815,20 @@ tactic_mode: [
| ltac_info tactic
| MOVETO command ltac_info tactic
| DELETE command
+| REPLACE OPT toplevel_selector "{"
+(* semantically restricted *)
+| WITH OPT ( [ natural | "[" ident "]" ] ":" ) "{"
+| MOVETO simple_tactic OPT ( [ natural | "[" ident "]" ] ":" ) "{"
+| DELETE simple_tactic
]
-sexpr: [
+tactic_mode: [ | DELETENT ]
+
+ltac2_scope: [
| REPLACE syn_node (* Ltac2 plugin *)
| WITH name TAG Ltac2
-| REPLACE syn_node "(" LIST1 sexpr SEP "," ")" (* Ltac2 plugin *)
-| WITH name "(" LIST1 sexpr SEP "," ")" TAG Ltac2
+| REPLACE syn_node "(" LIST1 ltac2_scope SEP "," ")" (* Ltac2 plugin *)
+| WITH name "(" LIST1 ltac2_scope SEP "," ")" TAG Ltac2
]
syn_node: [ | DELETENT ]
@@ -1785,7 +1838,7 @@ RENAME: [
]
toplevel_selector: [
-| selector_body
+| selector
| "all"
| "!"
(* par is accepted even though it's not in the .mlg *)
@@ -1793,7 +1846,7 @@ toplevel_selector: [
]
toplevel_selector_temp: [
-| DELETE selector_body ":"
+| DELETE selector ":"
| DELETE "all" ":"
| DELETE "!" ":"
| toplevel_selector ":"
@@ -1834,7 +1887,7 @@ query_command: [ ] (* re-add as a placeholder *)
sentence: [
| OPT attributes command "."
| OPT attributes OPT ( natural ":" ) query_command "."
-| OPT attributes OPT ( toplevel_selector ":" ) tactic_expr5 [ "." | "..." ]
+| OPT attributes OPT ( toplevel_selector ":" ) ltac_expr5 [ "." | "..." ]
| control_command
]
@@ -1858,27 +1911,27 @@ ltac_defined_tactics: [
| "split_Rabs"
| "split_Rmult"
| "tauto"
-| "time_constr" tactic_expr5
+| "time_constr" ltac_expr5
| "zify"
]
(* todo: need careful review; assume that "[" ... "]" are literals *)
tactic_notation_tactics: [
-| "assert_fails" tactic_expr3
-| "assert_succeeds" tactic_expr3
-| "field" OPT ( "[" LIST1 operconstr200 "]" )
-| "field_simplify" OPT ( "[" LIST1 operconstr200 "]" ) LIST1 operconstr200 OPT ( "in" ident )
-| "field_simplify_eq" OPT ( "[" LIST1 operconstr200 "]" ) OPT ( "in" ident )
-| "intuition" OPT tactic_expr5
-| "nsatz" OPT ( "with" "radicalmax" ":=" operconstr200 "strategy" ":=" operconstr200 "parameters" ":=" operconstr200 "variables" ":=" operconstr200 )
-| "psatz" operconstr200 OPT int_or_var
-| "ring" OPT ( "[" LIST1 operconstr200 "]" )
-| "ring_simplify" OPT ( "[" LIST1 operconstr200 "]" ) LIST1 operconstr200 OPT ( "in" ident ) (* todo: ident was "hyp", worth keeping? *)
+| "assert_fails" ltac_expr3
+| "assert_succeeds" ltac_expr3
+| "field" OPT ( "[" LIST1 constr "]" )
+| "field_simplify" OPT ( "[" LIST1 constr "]" ) LIST1 constr OPT ( "in" ident )
+| "field_simplify_eq" OPT ( "[" LIST1 constr "]" ) OPT ( "in" ident )
+| "intuition" OPT ltac_expr5
+| "nsatz" OPT ( "with" "radicalmax" ":=" constr "strategy" ":=" constr "parameters" ":=" constr "variables" ":=" constr )
+| "psatz" constr OPT int_or_var
+| "ring" OPT ( "[" LIST1 constr "]" )
+| "ring_simplify" OPT ( "[" LIST1 constr "]" ) LIST1 constr OPT ( "in" ident ) (* todo: ident was "hyp", worth keeping? *)
]
(* defined in OCaml outside of mlgs *)
-tactic_arg: [
-| "uconstr" ":" "(" operconstr200 ")"
+tactic_value: [
+| "uconstr" ":" "(" term200 ")"
| MOVEALLBUT simple_tactic
]
@@ -1886,10 +1939,6 @@ nonterminal: [ ]
value_tactic: [ ]
-RENAME: [
-| tactic_arg tactic_value
-]
-
syn_value: [
| IDENT; ":" "(" nonterminal ")"
]
@@ -1908,8 +1957,8 @@ ltac2_match_key: [
]
ltac2_constructs: [
-| ltac2_match_key tac2expr6 "with" ltac2_match_list "end"
-| ltac2_match_key OPT "reverse" "goal" "with" gmatch_list "end"
+| ltac2_match_key ltac2_expr6 "with" ltac2_match_list "end"
+| ltac2_match_key OPT "reverse" "goal" "with" goal_match_list "end"
]
simple_tactic: [
@@ -1921,9 +1970,9 @@ simple_tactic: [
]
tacdef_body: [
-| REPLACE global LIST1 input_fun ltac_def_kind tactic_expr5
-| WITH global LIST0 input_fun ltac_def_kind tactic_expr5
-| DELETE global ltac_def_kind tactic_expr5
+| REPLACE global LIST1 input_fun ltac_def_kind ltac_expr5
+| WITH global LIST0 input_fun ltac_def_kind ltac_expr5
+| DELETE global ltac_def_kind ltac_expr5
]
tac2def_typ: [
@@ -2005,7 +2054,7 @@ atomic_tac2pat: [
| OPTINREF
]
-tac2expr0: [
+ltac2_expr0: [
(*
| DELETE "(" ")" (* covered by "()" prodn *)
| REPLACE "{" [ | LIST1 tac2rec_fieldexpr OPT ";" ] "}"
@@ -2018,13 +2067,13 @@ tac2expr0: [
use LIST1? *)
SPLICE: [
-| tac2expr4
+| ltac2_expr4
]
-tac2expr3: [
-| REPLACE tac2expr2 "," LIST1 tac2expr2 SEP "," (* Ltac2 plugin *)
-| WITH LIST1 tac2expr2 SEP "," TAG Ltac2
-| DELETE tac2expr2 (* Ltac2 plugin *)
+ltac2_expr3: [
+| REPLACE ltac2_expr2 "," LIST1 ltac2_expr2 SEP "," (* Ltac2 plugin *)
+| WITH LIST1 ltac2_expr2 SEP "," TAG Ltac2
+| DELETE ltac2_expr2 (* Ltac2 plugin *)
]
tac2rec_fieldexprs: [
@@ -2105,7 +2154,7 @@ ltac2_entry: [
| WITH "Ltac2" tac2def_val
| REPLACE tac2def_ext (* Ltac2 plugin *)
| WITH "Ltac2" tac2def_ext
-| "Ltac2" "Notation" [ string | lident ] ":=" tac2expr6 TAG Ltac2 (* variant *)
+| "Ltac2" "Notation" [ string | lident ] ":=" ltac2_expr6 TAG Ltac2 (* variant *)
| MOVEALLBUT command
(* todo: MOVEALLBUT should ignore tag on "but" prodns *)
]
@@ -2141,21 +2190,15 @@ SPLICE: [
| anti
]
-tac2expr5: [
-| REPLACE "let" OPT "rec" LIST1 ltac2_let_clause SEP "with" "in" tac2expr6 (* Ltac2 plugin *)
-| WITH "let" OPT "rec" ltac2_let_clause LIST0 ( "with" ltac2_let_clause ) "in" tac2expr6 TAG Ltac2
-| MOVETO simple_tactic "match" tac2expr5 "with" OPT ltac2_branches "end" (* Ltac2 plugin *)
+ltac2_expr5: [
+| REPLACE "let" OPT "rec" LIST1 ltac2_let_clause SEP "with" "in" ltac2_expr6 (* Ltac2 plugin *)
+| WITH "let" OPT "rec" ltac2_let_clause LIST0 ( "with" ltac2_let_clause ) "in" ltac2_expr6 TAG Ltac2
+| MOVETO simple_tactic "match" ltac2_expr5 "with" OPT ltac2_branches "end" (* Ltac2 plugin *)
+| MOVETO simple_tactic "if" ltac2_expr5 "then" ltac2_expr5 "else" ltac2_expr5 (* Ltac2 plugin *)
| DELETE simple_tactic
]
-RENAME: [
-| Prim.string string
-| Prim.integer integer
-| Prim.qualid qualid
-| Prim.natural natural
-]
-
-gmatch_list: [
+goal_match_list: [
| EDIT ADD_OPT "|" LIST1 gmatch_rule SEP "|" (* Ltac2 plugin *)
]
@@ -2194,6 +2237,40 @@ ltac2_induction_clause: [
| WITH ltac2_destruction_arg OPT ltac2_as_or_and_ipat OPT ltac2_eqn_ipat OPT ltac2_clause TAG Ltac2
]
+starredidentref: [
+| EDIT identref ADD_OPT "*"
+| EDIT "Type" ADD_OPT "*"
+| "All"
+]
+
+ssexpr0: [
+| DELETE "(" LIST0 starredidentref ")"
+| DELETE "(" LIST0 starredidentref ")" "*"
+| DELETE "(" ssexpr35 ")"
+| DELETE "(" ssexpr35 ")" "*"
+| "(" section_subset_expr ")" OPT "*"
+]
+
+ssexpr35: [
+| EDIT ADD_OPT "-" ssexpr50
+]
+
+simple_binding: [
+| REPLACE "(" ident ":=" lconstr ")"
+| WITH "(" [ ident | natural ] ":=" lconstr ")"
+| DELETE "(" natural ":=" lconstr ")"
+]
+
+
+subprf: [
+| MOVEALLBUT simple_tactic
+| "{" (* should be removed. See https://github.com/coq/coq/issues/12004 *)
+]
+
+ltac2_expr: [
+| DELETE _ltac2_expr
+]
+
SPLICE: [
| clause
| noedit_mode
@@ -2204,7 +2281,6 @@ SPLICE: [
| NUMBER
| STRING
| hyp
-| var
| identref
| pattern_ident
| constr_eval (* splices as multiple prods *)
@@ -2214,10 +2290,10 @@ SPLICE: [
| ltac_selector
| Constr.ident
| attribute_list
-| operconstr99
-| operconstr90
-| operconstr9
-| operconstr8
+| term99
+| term90
+| term9
+| term8
| pattern200
| pattern99
| pattern90
@@ -2268,7 +2344,7 @@ SPLICE: [
| check_module_types
| constr_pattern
| decl_sep
-| function_rec_definition_loc (* loses funind annotation *)
+| function_fix_definition (* loses funind annotation *)
| glob
| glob_constr_with_bindings
| id_or_meta
@@ -2286,7 +2362,6 @@ SPLICE: [
| decorated_vernac
| ext_module_expr
| ext_module_type
-| pattern_identref
| test
| binder_constr
| atomic_constr
@@ -2354,7 +2429,6 @@ SPLICE: [
| intropatterns
| instance_name
| failkw
-| selector
| ne_in_or_out_modules
| search_queries
| locatable
@@ -2377,87 +2451,52 @@ SPLICE: [
| refglobals (* Ltac2 *)
| syntax_modifiers
| array_elems
-| ltac2_expr
| G_LTAC2_input_fun
| ltac2_simple_intropattern_closed
| ltac2_with_bindings
+| int_or_id
+| fun_ind_using
+| with_names
+| eauto_search_strategy_name
+| constr_with_bindings
+| simple_binding
+| ssexpr35 (* strange in mlg, ssexpr50 is after this *)
+| number_string_mapping
+| number_options
+| string_option
] (* end SPLICE *)
RENAME: [
| tactic3 ltac_expr3 (* todo: can't figure out how this gets mapped by coqpp *)
| tactic1 ltac_expr1 (* todo: can't figure out how this gets mapped by coqpp *)
| tactic0 ltac_expr0 (* todo: can't figure out how this gets mapped by coqpp *)
-| ltac1_expr ltac_expr
-| tactic_expr5 ltac_expr
-| tactic_expr4 ltac_expr4
-| tactic_expr3 ltac_expr3
-| tactic_expr2 ltac_expr2
-| tactic_expr1 ltac_expr1
-| tactic_expr0 ltac_expr0
+| ltac_expr5 ltac_expr
(* | nonsimple_intropattern intropattern (* ltac2 *) *)
-| operconstr200 term (* historical name *)
-| operconstr100 term100
-| operconstr10 term10
-| operconstr1 term1
-| operconstr0 term0
+| term200 term
| pattern100 pattern
-| match_constr term_match
(*| impl_ident_tail impl_ident*)
-| ssexpr35 ssexpr (* strange in mlg, ssexpr50 is after this *)
-
-| tactic_then_gen for_each_goal
-| ltac2_tactic_then_gen ltac2_for_each_goal
-| selector_body selector
-| match_hyps match_hyp
+| ssexpr50 section_var_expr50
+| ssexpr0 section_var_expr0
+| section_subset_expr section_var_expr
+| fun_scheme_arg func_scheme_def
| BULLET bullet
-| fix_decl fix_body
-| cofix_decl cofix_body
-(* todo: it's confusing that Constr.constr and constr are different things *)
-| constr one_term
-| appl_arg arg
-| rec_definition fix_definition
-| corec_definition cofix_definition
-| univ_instance univ_annot
-| simple_assum_coe assumpt
-| of_type_with_opt_coercion of_type
-| attribute_value attr_value
-| constructor_list_or_record_decl constructors_or_record
-| record_binder_body field_body
-| class_rawexpr class
-| smart_global reference
+| constr one_term (* many, many, many *)
+| class_rawexpr class (* OCaml reserved word *)
+| smart_global reference (* many, many *)
(*
| searchabout_query search_item
*)
-| option_table setting_name
-| argument_spec_block arg_specs
-| more_implicits_block implicits_alt
-| arguments_modifier args_modifier
-| constr_as_binder_kind binder_interp
-| syntax_extension_type explicit_subentry
-| numnotoption numeral_modifier
-| tactic_arg_compat tactic_arg
-| lconstr_pattern cpattern
-| Pltac.tactic ltac_expr
-| sexpr ltac2_scope
-| tac2type5 ltac2_type
-| tac2type2 ltac2_type2
-| tac2type1 ltac2_type1
-| tac2type0 ltac2_type0
-| typ_param ltac2_typevar
-| tac2expr6 ltac2_expr
-| tac2expr5 ltac2_expr5
-| tac2expr3 ltac2_expr3
-| tac2expr2 ltac2_expr2
-| tac2expr1 ltac2_expr1
-| tac2expr0 ltac2_expr0
-| gmatch_list goal_match_list
+| Pltac.tactic ltac_expr (* many uses in EXTENDs *)
+| ltac2_type5 ltac2_type
+| ltac2_expr6 ltac2_expr
+| starredidentref starred_ident_ref
]
simple_tactic: [
-(* due to renaming of tactic_arg; Use LIST1 for function application *)
+(* due to renaming of tactic_value; Use LIST1 for function application *)
| qualid LIST1 tactic_arg
]
@@ -2479,7 +2518,7 @@ SPLICE: [
| ltac_defined_tactics
| tactic_notation_tactics
]
-(* todo: ssrreflect*.rst ref to fix_body is incorrect *)
+(* todo: ssrreflect*.rst ref to fix_decl is incorrect *)
REACHABLE: [
| command
@@ -2518,17 +2557,7 @@ NOTINRSTS: [
| q_constr_matching
| q_goal_matching
-(* todo: figure these out
-(*Warning: editedGrammar: Undefined symbol 'ltac1_expr' *)
-| dangling_pattern_extension_rule
-| vernac_aux
-| subprf
-| tactic_mode
-| tac2expr_in_env (* no refs *)
-| tac2mode (* no refs *)
-| ltac_use_default (* from tac2mode *)
-| tacticals
-*)
+
]
REACHABLE: [
diff --git a/doc/tools/docgram/doc_grammar.ml b/doc/tools/docgram/doc_grammar.ml
index 0ac652c0db..92bcd51528 100644
--- a/doc/tools/docgram/doc_grammar.ml
+++ b/doc/tools/docgram/doc_grammar.ml
@@ -538,12 +538,11 @@ let autoloaded_mlgs = [ (* in the order they are loaded by Coq *)
"plugins/ltac/g_eqdecide.mlg";
"plugins/ltac/g_tactic.mlg";
"plugins/ltac/g_ltac.mlg";
- "plugins/syntax/g_string.mlg";
"plugins/btauto/g_btauto.mlg";
"plugins/rtauto/g_rtauto.mlg";
"plugins/cc/g_congruence.mlg";
"plugins/firstorder/g_ground.mlg";
- "plugins/syntax/g_numeral.mlg";
+ "plugins/syntax/g_number_string.mlg";
]
@@ -909,14 +908,17 @@ let apply_splice g edit_map =
List.iter (fun b ->
let (nt0, prods0) = b in
let rec splice_loop nt prods cnt =
- let max_cnt = 10 in
- let (nt', prods') = edit_rule g edit_map nt prods in
- if cnt > max_cnt then
- error "Splice for '%s' not done after %d iterations\n" nt0 max_cnt;
- if nt' = nt && prods' = prods then
- (nt', prods')
- else
- splice_loop nt' prods' (cnt+1)
+ if cnt >= 10 then begin
+ error "Splice for '%s' not done after %d iterations. Current value is:\n" nt0 cnt;
+ List.iter (fun prod -> Printf.eprintf " %s\n" (prod_to_str prod)) prods;
+ (nt, prods)
+ end else begin
+ let (nt', prods') = edit_rule g edit_map nt prods in
+ if nt' = nt && prods' = prods then
+ (nt, prods)
+ else
+ splice_loop nt' prods' (cnt+1)
+ end
in
let (nt', prods') = splice_loop nt0 prods0 0 in
g_update_prods g nt' prods')
@@ -1724,6 +1726,7 @@ let open_temp_bin file =
let match_cmd_regex = Str.regexp "[a-zA-Z0-9_ ]+"
let match_subscripts = Str.regexp "__[a-zA-Z0-9]+"
+let remove_subscrs str = Str.global_replace match_subscripts "" str
let find_longest_match prods str =
let get_pfx str = String.trim (if Str.string_match match_cmd_regex str 0 then Str.matched_string str else "") in
@@ -1737,7 +1740,6 @@ let find_longest_match prods str =
in
aux 0
in
- let remove_subscrs str = Str.global_replace match_subscripts "" str in
let slen = String.length str in
let str_pfx = get_pfx str in
@@ -1892,25 +1894,15 @@ let process_rst g file args seen tac_prods cmd_prods =
(* "doc/sphinx/proof-engine/ssreflect-proof-language.rst"]*)
(* in*)
- let cmd_replace_files = [
- "doc/sphinx/language/core/records.rst";
- "doc/sphinx/language/core/sections.rst";
- "doc/sphinx/language/extensions/implicit-arguments.rst";
- "doc/sphinx/language/extensions/arguments-command.rst";
- "doc/sphinx/language/gallina-extensions.rst";
- "doc/sphinx/language/gallina-specification-language.rst";
- "doc/sphinx/language/using/libraries/funind.rst";
- "doc/sphinx/proof-engine/ltac.rst";
- "doc/sphinx/proof-engine/ltac2.rst";
- "doc/sphinx/proof-engine/vernacular-commands.rst";
- "doc/sphinx/user-extensions/syntax-extensions.rst";
- "doc/sphinx/proof-engine/vernacular-commands.rst"
+ let cmd_exclude_files = [
+ "doc/sphinx/proof-engine/ssreflect-proof-language.rst";
+ "doc/sphinx/proof-engine/tactics.rst"
]
in
let save_n_get_more direc pfx first_rhs seen_map prods =
let replace rhs prods =
- if StringSet.is_empty prods || not (List.mem file cmd_replace_files) then
+ if StringSet.is_empty prods || (List.mem file cmd_exclude_files) then
rhs (* no change *)
else
let mtch, multi, best = find_longest_match prods rhs in
@@ -1918,12 +1910,15 @@ let process_rst g file args seen tac_prods cmd_prods =
if mtch = rhs then
rhs (* no change *)
else if mtch = "" then begin
- warn "%s line %d: NO MATCH `%s`\n" file !linenum rhs;
- if best <> "" then
- warn "%s line %d: BEST `%s`\n" file !linenum best;
+ error "%s line %d: NO MATCH for `%s`\n" file !linenum rhs;
+ if best <> "" then begin
+ Printf.eprintf " closest match is: `%s`\n" best;
+ Printf.eprintf " Please update the rst manually while preserving any subscripts, e.g. 'NT__sub'\n"
+ end;
rhs
end else if multi then begin
- warn "%s line %d: MULTIMATCH `%s`\n" file !linenum rhs;
+ error "%s line %d: MULTIPLE MATCHES for `%s`\n" file !linenum rhs;
+ Printf.eprintf " Please update the rst manually while preserving any subscripts, e.g. 'NT__sub'\n";
rhs
end else
mtch (* update cmd/tacn *)
@@ -1936,7 +1931,7 @@ let process_rst g file args seen tac_prods cmd_prods =
fprintf new_rst "%s%s\n" pfx (replace first_rhs prods);
- map := NTMap.add first_rhs (file, !linenum) !map;
+ map := NTMap.add (remove_subscrs first_rhs) (file, !linenum) !map;
while
let nextline = getline() in
ignore (Str.string_match contin_regex nextline 0);
@@ -2078,13 +2073,11 @@ let process_grammar args =
print_in_order out g `MLG !g.order StringSet.empty;
close_out out;
finish_with_file (dir "orderedGrammar") args;
- check_singletons g
+ check_singletons g;
(* print_dominated g*)
- end;
- let seen = ref { nts=NTMap.empty; tacs=NTMap.empty; tacvs=NTMap.empty; cmds=NTMap.empty; cmdvs=NTMap.empty } in
- let args = { args with no_update = false } in (* always update rsts in place for now *)
- if !exit_code = 0 then begin
+ let seen = ref { nts=NTMap.empty; tacs=NTMap.empty; tacvs=NTMap.empty; cmds=NTMap.empty; cmdvs=NTMap.empty } in
+ let args = { args with no_update = false } in (* always update rsts in place for now *)
let plist nt =
let list = (List.map (fun t -> String.trim (prod_to_prodn t))
(NTMap.find nt !g.map)) in
@@ -2095,7 +2088,6 @@ let process_grammar args =
report_omitted_prods g !seen.nts "Nonterminal" "";
let out = open_out (dir "updated_rsts") in
close_out out;
- end;
(*
if args.check_tacs then
@@ -2104,7 +2096,6 @@ let process_grammar args =
report_omitted_prods cmd_list !seen.cmds "Command" "\n ";
*)
- if !exit_code = 0 then begin
(* generate report on cmds or tacs *)
let cmdReport outfile cmdStr cmd_nts cmds cmdvs =
let rstCmds = StringSet.of_list (List.map (fun b -> let c, _ = b in c) (NTMap.bindings cmds)) in
@@ -2113,7 +2104,7 @@ let process_grammar args =
StringSet.union set (StringSet.of_list (List.map (fun p -> String.trim (prod_to_prodn p)) (NTMap.find nt !prodn_gram.map)))
) StringSet.empty cmd_nts in
let allCmds = StringSet.union rstCmdvs (StringSet.union rstCmds gramCmds) in
- let out = open_temp_bin (dir outfile) in
+ let out = open_out_bin (dir outfile) in
StringSet.iter (fun c ->
let rsts = StringSet.mem c rstCmds in
let gram = StringSet.mem c gramCmds in
@@ -2127,7 +2118,6 @@ let process_grammar args =
fprintf out "%s%s %s\n" pfx var c)
allCmds;
close_out out;
- finish_with_file (dir outfile) args;
Printf.printf "# %s in rsts, gram, total = %d %d %d\n" cmdStr (StringSet.cardinal gramCmds)
(StringSet.cardinal rstCmds) (StringSet.cardinal allCmds);
in
@@ -2139,17 +2129,16 @@ let process_grammar args =
let tac_nts = ["simple_tactic"] in
if args.check_tacs then
- cmdReport "prodnTactics" "tacs" tac_nts !seen.tacs !seen.tacvs
- end;
+ cmdReport "prodnTactics" "tacs" tac_nts !seen.tacs !seen.tacvs;
- (* generate prodnGrammar for reference *)
- if !exit_code = 0 && not args.verify then begin
- let out = open_temp_bin (dir "prodnGrammar") in
- print_in_order out prodn_gram `PRODN !prodn_gram.order StringSet.empty;
- close_out out;
- finish_with_file (dir "prodnGrammar") args
- end
- end
+ (* generate prodnGrammar for reference *)
+ if not args.verify then begin
+ let out = open_out_bin (dir "prodnGrammar") in
+ print_in_order out prodn_gram `PRODN !prodn_gram.order StringSet.empty;
+ close_out out;
+ end
+ end (* if !exit_code = 0 *)
+ end (* if not args.fullGrammar *)
let parse_args () =
let suffix_regex = Str.regexp ".*\\.\\([a-z]+\\)$" in
diff --git a/doc/tools/docgram/fullGrammar b/doc/tools/docgram/fullGrammar
index 067050b4f5..20ac8f8bf3 100644
--- a/doc/tools/docgram/fullGrammar
+++ b/doc/tools/docgram/fullGrammar
@@ -17,7 +17,7 @@ constr_pattern: [
| constr
]
-lconstr_pattern: [
+cpattern: [
| lconstr
]
@@ -58,67 +58,67 @@ universe: [
]
lconstr: [
-| operconstr200
+| term200
]
constr: [
-| operconstr8
-| "@" global univ_instance
+| term8
+| "@" global univ_annot
]
-operconstr200: [
+term200: [
| binder_constr
-| operconstr100
+| term100
]
-operconstr100: [
-| operconstr99 "<:" operconstr200
-| operconstr99 "<<:" operconstr200
-| operconstr99 ":" operconstr200
-| operconstr99 ":>"
-| operconstr99
+term100: [
+| term99 "<:" term200
+| term99 "<<:" term200
+| term99 ":" term200
+| term99 ":>"
+| term99
]
-operconstr99: [
-| operconstr90
+term99: [
+| term90
]
-operconstr90: [
-| operconstr10
+term90: [
+| term10
]
-operconstr10: [
-| operconstr9 LIST1 appl_arg
-| "@" global univ_instance LIST0 operconstr9
-| "@" pattern_identref LIST1 identref
-| operconstr9
+term10: [
+| term9 LIST1 arg
+| "@" global univ_annot LIST0 term9
+| "@" pattern_ident LIST1 identref
+| term9
]
-operconstr9: [
-| ".." operconstr0 ".."
-| operconstr8
+term9: [
+| ".." term0 ".."
+| term8
]
-operconstr8: [
-| operconstr1
+term8: [
+| term1
]
-operconstr1: [
-| operconstr0 ".(" global LIST0 appl_arg ")"
-| operconstr0 ".(" "@" global LIST0 ( operconstr9 ) ")"
-| operconstr0 "%" IDENT
-| operconstr0
+term1: [
+| term0 ".(" global LIST0 arg ")"
+| term0 ".(" "@" global LIST0 ( term9 ) ")"
+| term0 "%" IDENT
+| term0
]
-operconstr0: [
+term0: [
| atomic_constr
-| match_constr
-| "(" operconstr200 ")"
+| term_match
+| "(" term200 ")"
| "{|" record_declaration bar_cbrace
| "{" binder_constr "}"
-| "`{" operconstr200 "}"
-| test_array_opening "[" "|" array_elems "|" lconstr type_cstr test_array_closing "|" "]" univ_instance
-| "`(" operconstr200 ")"
+| "`{" term200 "}"
+| test_array_opening "[" "|" array_elems "|" lconstr type_cstr test_array_closing "|" "]" univ_annot
+| "`(" term200 ")"
]
array_elems: [
@@ -140,38 +140,38 @@ field_def: [
]
binder_constr: [
-| "forall" open_binders "," operconstr200
-| "fun" open_binders "=>" operconstr200
-| "let" name binders let_type_cstr ":=" operconstr200 "in" operconstr200
-| "let" "fix" fix_decl "in" operconstr200
-| "let" "cofix" cofix_decl "in" operconstr200
-| "let" [ "(" LIST0 name SEP "," ")" | "()" ] return_type ":=" operconstr200 "in" operconstr200
-| "let" "'" pattern200 ":=" operconstr200 "in" operconstr200
-| "let" "'" pattern200 ":=" operconstr200 case_type "in" operconstr200
-| "let" "'" pattern200 "in" pattern200 ":=" operconstr200 case_type "in" operconstr200
-| "if" operconstr200 return_type "then" operconstr200 "else" operconstr200
+| "forall" open_binders "," term200
+| "fun" open_binders "=>" term200
+| "let" name binders let_type_cstr ":=" term200 "in" term200
+| "let" "fix" fix_decl "in" term200
+| "let" "cofix" cofix_body "in" term200
+| "let" [ "(" LIST0 name SEP "," ")" | "()" ] as_return_type ":=" term200 "in" term200
+| "let" "'" pattern200 ":=" term200 "in" term200
+| "let" "'" pattern200 ":=" term200 case_type "in" term200
+| "let" "'" pattern200 "in" pattern200 ":=" term200 case_type "in" term200
+| "if" term200 as_return_type "then" term200 "else" term200
| "fix" fix_decls
| "cofix" cofix_decls
]
-appl_arg: [
-| test_lpar_id_coloneq "(" ident ":=" lconstr ")"
-| operconstr9
+arg: [
+| test_lpar_id_coloneq "(" identref ":=" lconstr ")"
+| term9
]
atomic_constr: [
-| global univ_instance
+| global univ_annot
| sort
| NUMBER
| string
| "_"
-| "?" "[" ident "]"
+| "?" "[" identref "]"
| "?" "[" pattern_ident "]"
| pattern_ident evar_instance
]
inst: [
-| ident ":=" lconstr
+| identref ":=" lconstr
]
evar_instance: [
@@ -179,7 +179,7 @@ evar_instance: [
|
]
-univ_instance: [
+univ_annot: [
| "@{" LIST0 universe_level "}"
|
]
@@ -198,31 +198,31 @@ fix_decls: [
]
cofix_decls: [
-| cofix_decl
-| cofix_decl "with" LIST1 cofix_decl SEP "with" "for" identref
+| cofix_body
+| cofix_body "with" LIST1 cofix_body SEP "with" "for" identref
]
fix_decl: [
-| identref binders_fixannot type_cstr ":=" operconstr200
+| identref binders_fixannot type_cstr ":=" term200
]
-cofix_decl: [
-| identref binders type_cstr ":=" operconstr200
+cofix_body: [
+| identref binders type_cstr ":=" term200
]
-match_constr: [
+term_match: [
| "match" LIST1 case_item SEP "," OPT case_type "with" branches "end"
]
case_item: [
-| operconstr100 OPT [ "as" name ] OPT [ "in" pattern200 ]
+| term100 OPT [ "as" name ] OPT [ "in" pattern200 ]
]
case_type: [
-| "return" operconstr100
+| "return" term100
]
-return_type: [
+as_return_type: [
| OPT [ OPT [ "as" name ] case_type ]
]
@@ -253,7 +253,7 @@ pattern200: [
]
pattern100: [
-| pattern99 ":" operconstr200
+| pattern99 ":" term200
| pattern99
]
@@ -335,10 +335,10 @@ closed_binder: [
]
typeclass_constraint: [
-| "!" operconstr200
-| "{" name "}" ":" [ "!" | ] operconstr200
-| test_name_colon name ":" [ "!" | ] operconstr200
-| operconstr200
+| "!" term200
+| "{" name "}" ":" [ "!" | ] term200
+| test_name_colon name ":" [ "!" | ] term200
+| term200
]
type_cstr: [
@@ -362,16 +362,12 @@ pattern_ident: [
| LEFTQMARK ident
]
-pattern_identref: [
-| pattern_ident
-]
-
-var: [
+identref: [
| ident
]
-identref: [
-| ident
+hyp: [
+| identref
]
field: [
@@ -510,7 +506,7 @@ command: [
| "Remove" "Hints" LIST1 global opt_hintbases
| "Hint" hint opt_hintbases
| "Comments" LIST0 comment
-| "Declare" "Instance" ident_decl binders ":" operconstr200 hint_info
+| "Declare" "Instance" ident_decl binders ":" term200 hint_info
| "Declare" "Scope" IDENT
| "Pwd"
| "Cd"
@@ -529,13 +525,13 @@ command: [
| "Print" "Namespace" dirpath
| "Inspect" natural
| "Add" "ML" "Path" ne_string
-| "Set" option_table option_setting
-| "Unset" option_table
-| "Print" "Table" option_table
+| "Set" setting_name option_setting
+| "Unset" setting_name
+| "Print" "Table" setting_name
| "Add" IDENT IDENT LIST1 table_value
| "Add" IDENT LIST1 table_value
-| "Test" option_table "for" LIST1 table_value
-| "Test" option_table
+| "Test" setting_name "for" LIST1 table_value
+| "Test" setting_name
| "Remove" IDENT IDENT LIST1 table_value
| "Remove" IDENT LIST1 table_value
| "Write" "State" IDENT
@@ -573,7 +569,7 @@ command: [
| "Show" "Extraction" (* extraction plugin *)
| "Set" "Firstorder" "Solver" tactic
| "Print" "Firstorder" "Solver"
-| "Function" LIST1 function_rec_definition_loc SEP "with" (* funind plugin *)
+| "Function" LIST1 function_fix_definition SEP "with" (* funind plugin *)
| "Functional" "Scheme" LIST1 fun_scheme_arg SEP "with" (* funind plugin *)
| "Functional" "Case" fun_scheme_arg (* funind plugin *)
| "Generate" "graph" "for" reference (* funind plugin *)
@@ -596,9 +592,9 @@ command: [
| "Optimize" "Proof"
| "Optimize" "Heap"
| "Hint" "Cut" "[" hints_path "]" opthints
-| "Typeclasses" "Transparent" LIST0 reference
-| "Typeclasses" "Opaque" LIST0 reference
-| "Typeclasses" "eauto" ":=" debug eauto_search_strategy OPT integer
+| "Typeclasses" "Transparent" LIST1 reference
+| "Typeclasses" "Opaque" LIST1 reference
+| "Typeclasses" "eauto" ":=" debug eauto_search_strategy OPT natural
| "Proof" "with" Pltac.tactic OPT [ "using" G_vernac.section_subset_expr ]
| "Proof" "using" G_vernac.section_subset_expr OPT [ "with" Pltac.tactic ]
| "Tactic" "Notation" OPT ltac_tactic_level LIST1 ltac_production_item ":=" tactic
@@ -615,6 +611,7 @@ command: [
| "Solve" "Obligation" natural "of" ident "with" tactic
| "Solve" "Obligation" natural "with" tactic
| "Solve" "Obligations" "of" ident "with" tactic
+| "Solve" "Obligations" "of" ident
| "Solve" "Obligations" "with" tactic
| "Solve" "Obligations"
| "Solve" "All" "Obligations" "with" tactic
@@ -689,11 +686,11 @@ command: [
| "Print" "Rings" (* ring plugin *)
| "Add" "Field" ident ":" constr OPT field_mods (* ring plugin *)
| "Print" "Fields" (* ring plugin *)
-| "Number" "Notation" reference reference reference ":" ident numnotoption
-| "Numeral" "Notation" reference reference reference ":" ident numnotoption
-| "String" "Notation" reference reference reference ":" ident
+| "Number" "Notation" reference reference reference OPT number_options ":" ident
+| "Numeral" "Notation" reference reference reference ":" ident deprecated_number_modifier
+| "String" "Notation" reference reference reference OPT string_option ":" ident
| "Ltac2" ltac2_entry (* Ltac2 plugin *)
-| "Ltac2" "Eval" ltac2_expr (* Ltac2 plugin *)
+| "Ltac2" "Eval" ltac2_expr6 (* Ltac2 plugin *)
| "Print" "Ltac2" reference (* Ltac2 plugin *)
]
@@ -748,10 +745,10 @@ attribute_list: [
]
attribute: [
-| ident attribute_value
+| ident attr_value
]
-attribute_value: [
+attr_value: [
| "=" string
| "(" attribute_list ")"
|
@@ -798,10 +795,10 @@ gallina: [
| def_token ident_decl def_body
| "Let" ident_decl def_body
| finite_token LIST1 inductive_definition SEP "with"
-| "Fixpoint" LIST1 rec_definition SEP "with"
-| "Let" "Fixpoint" LIST1 rec_definition SEP "with"
-| "CoFixpoint" LIST1 corec_definition SEP "with"
-| "Let" "CoFixpoint" LIST1 corec_definition SEP "with"
+| "Fixpoint" LIST1 fix_definition SEP "with"
+| "Let" "Fixpoint" LIST1 fix_definition SEP "with"
+| "CoFixpoint" LIST1 cofix_definition SEP "with"
+| "Let" "CoFixpoint" LIST1 cofix_definition SEP "with"
| "Scheme" LIST1 scheme SEP "with"
| "Combined" "Scheme" identref "from" LIST1 identref SEP ","
| "Register" global "as" qualid
@@ -900,7 +897,7 @@ decl_notations: [
]
opt_constructors_or_fields: [
-| ":=" constructor_list_or_record_decl
+| ":=" constructors_or_record
|
]
@@ -908,7 +905,7 @@ inductive_definition: [
| opt_coercion ident_decl binders OPT [ "|" binders ] OPT [ ":" lconstr ] opt_constructors_or_fields decl_notations
]
-constructor_list_or_record_decl: [
+constructors_or_record: [
| "|" LIST1 constructor SEP "|"
| identref constructor_type "|" LIST1 constructor SEP "|"
| identref constructor_type
@@ -922,11 +919,11 @@ opt_coercion: [
|
]
-rec_definition: [
+fix_definition: [
| ident_decl binders_fixannot type_cstr OPT [ ":=" lconstr ] decl_notations
]
-corec_definition: [
+cofix_definition: [
| ident_decl binders type_cstr OPT [ ":=" lconstr ] decl_notations
]
@@ -953,39 +950,39 @@ record_fields: [
|
]
-record_binder_body: [
-| binders of_type_with_opt_coercion lconstr
-| binders of_type_with_opt_coercion lconstr ":=" lconstr
+field_body: [
+| binders of_type lconstr
+| binders of_type lconstr ":=" lconstr
| binders ":=" lconstr
]
record_binder: [
| name
-| name record_binder_body
+| name field_body
]
assum_list: [
| LIST1 assum_coe
-| simple_assum_coe
+| assumpt
]
assum_coe: [
-| "(" simple_assum_coe ")"
+| "(" assumpt ")"
]
-simple_assum_coe: [
-| LIST1 ident_decl of_type_with_opt_coercion lconstr
+assumpt: [
+| LIST1 ident_decl of_type lconstr
]
constructor_type: [
-| binders [ of_type_with_opt_coercion lconstr | ]
+| binders [ of_type lconstr | ]
]
constructor: [
| identref constructor_type
]
-of_type_with_opt_coercion: [
+of_type: [
| ":>"
| ":" ">"
| ":"
@@ -1014,16 +1011,16 @@ gallina_ext: [
| "Coercion" global ":" class_rawexpr ">->" class_rawexpr
| "Coercion" by_notation ":" class_rawexpr ">->" class_rawexpr
| "Context" LIST1 binder
-| "Instance" instance_name ":" operconstr200 hint_info [ ":=" "{" record_declaration "}" | ":=" lconstr | ]
+| "Instance" instance_name ":" term200 hint_info [ ":=" "{" record_declaration "}" | ":=" lconstr | ]
| "Existing" "Instance" global hint_info
| "Existing" "Instances" LIST1 global OPT [ "|" natural ]
| "Existing" "Class" global
-| "Arguments" smart_global LIST0 argument_spec_block OPT [ "," LIST1 [ LIST0 more_implicits_block ] SEP "," ] OPT [ ":" LIST1 arguments_modifier SEP "," ]
+| "Arguments" smart_global LIST0 arg_specs OPT [ "," LIST1 [ LIST0 implicits_alt ] SEP "," ] OPT [ ":" LIST1 args_modifier SEP "," ]
| "Implicit" "Type" reserv_list
| "Implicit" "Types" reserv_list
| "Generalizable" [ "All" "Variables" | "No" "Variables" | [ "Variable" | "Variables" ] LIST1 identref ]
-| "Export" "Set" option_table option_setting
-| "Export" "Unset" option_table
+| "Export" "Set" setting_name option_setting
+| "Export" "Unset" setting_name
]
filtered_import: [
@@ -1145,7 +1142,7 @@ ssexpr0: [
| "(" ssexpr35 ")" "*"
]
-arguments_modifier: [
+args_modifier: [
| "simpl" "nomatch"
| "simpl" "never"
| "default" "implicits"
@@ -1167,7 +1164,7 @@ argument_spec: [
| OPT "!" name OPT scope_delimiter
]
-argument_spec_block: [
+arg_specs: [
| argument_spec
| "/"
| "&"
@@ -1176,7 +1173,7 @@ argument_spec_block: [
| "{" LIST1 argument_spec "}" OPT scope_delimiter
]
-more_implicits_block: [
+implicits_alt: [
| name
| "[" LIST1 name "]"
| "{" LIST1 name "}"
@@ -1285,7 +1282,7 @@ table_value: [
| STRING
]
-option_table: [
+setting_name: [
| LIST1 IDENT
]
@@ -1394,9 +1391,9 @@ syntax_modifier: [
| "only" "parsing"
| "format" STRING OPT STRING
| IDENT; "," LIST1 IDENT SEP "," "at" level
-| IDENT; "at" level OPT constr_as_binder_kind
-| IDENT constr_as_binder_kind
-| IDENT syntax_extension_type
+| IDENT; "at" level OPT binder_interp
+| IDENT binder_interp
+| IDENT explicit_subentry
]
syntax_modifiers: [
@@ -1404,19 +1401,19 @@ syntax_modifiers: [
|
]
-syntax_extension_type: [
+explicit_subentry: [
| "ident"
| "global"
| "bigint"
| "binder"
| "constr"
-| "constr" at_level_opt OPT constr_as_binder_kind
+| "constr" at_level_opt OPT binder_interp
| "pattern"
| "pattern" "at" "level" natural
| "strict" "pattern"
| "strict" "pattern" "at" "level" natural
| "closed" "binder"
-| "custom" IDENT at_level_opt OPT constr_as_binder_kind
+| "custom" IDENT at_level_opt OPT binder_interp
]
at_level_opt: [
@@ -1424,7 +1421,7 @@ at_level_opt: [
|
]
-constr_as_binder_kind: [
+binder_interp: [
| "as" "ident"
| "as" "pattern"
| "as" "strict" "pattern"
@@ -1551,7 +1548,7 @@ simple_tactic: [
| "notypeclasses" "refine" uconstr
| "simple" "notypeclasses" "refine" uconstr
| "solve_constraints"
-| "subst" LIST1 var
+| "subst" LIST1 hyp
| "subst"
| "simple" "subst"
| "evar" test_lpar_id_colon "(" ident ":" lconstr ")"
@@ -1619,6 +1616,7 @@ simple_tactic: [
| "convert_concl_no_check" constr
| "typeclasses" "eauto" "bfs" OPT int_or_var "with" LIST1 preident
| "typeclasses" "eauto" OPT int_or_var "with" LIST1 preident
+| "typeclasses" "eauto" "bfs" OPT int_or_var
| "typeclasses" "eauto" OPT int_or_var
| "head_of_constr" ident constr
| "not_evar" constr
@@ -1740,11 +1738,11 @@ simple_tactic: [
| "zify_elim_let" (* micromega plugin *)
| "nsatz_compute" constr (* nsatz plugin *)
| "omega" (* omega plugin *)
-| "rtauto"
| "protect_fv" string "in" ident (* ring plugin *)
| "protect_fv" string (* ring plugin *)
| "ring_lookup" tactic0 "[" LIST0 constr "]" LIST1 constr (* ring plugin *)
| "field_lookup" tactic "[" LIST0 constr "]" LIST1 constr (* ring plugin *)
+| "rtauto"
]
mlname: [
@@ -1791,8 +1789,8 @@ auto_using': [
| (* funind plugin *)
]
-function_rec_definition_loc: [
-| Vernac.rec_definition (* funind plugin *)
+function_fix_definition: [
+| Vernac.fix_definition (* funind plugin *)
]
fun_scheme_arg: [
@@ -1811,7 +1809,7 @@ EXTRAARGS_natural: [
occurrences: [
| LIST1 integer
-| var
+| hyp
]
glob: [
@@ -1925,16 +1923,16 @@ eauto_search_strategy: [
]
tactic_then_last: [
-| "|" LIST0 ( OPT tactic_expr5 ) SEP "|"
+| "|" LIST0 ( OPT ltac_expr5 ) SEP "|"
|
]
-tactic_then_gen: [
-| tactic_expr5 "|" tactic_then_gen
-| tactic_expr5 ".." tactic_then_last
+for_each_goal: [
+| ltac_expr5 "|" for_each_goal
+| ltac_expr5 ".." tactic_then_last
| ".." tactic_then_last
-| tactic_expr5
-| "|" tactic_then_gen
+| ltac_expr5
+| "|" for_each_goal
|
]
@@ -1942,60 +1940,60 @@ tactic_then_locality: [
| "[" OPT ">"
]
-tactic_expr5: [
+ltac_expr5: [
| binder_tactic
-| tactic_expr4
-]
-
-tactic_expr4: [
-| tactic_expr3 ";" binder_tactic
-| tactic_expr3 ";" tactic_expr3
-| tactic_expr3 ";" tactic_then_locality tactic_then_gen "]"
-| tactic_expr3
-]
-
-tactic_expr3: [
-| "try" tactic_expr3
-| "do" int_or_var tactic_expr3
-| "timeout" int_or_var tactic_expr3
-| "time" OPT string tactic_expr3
-| "repeat" tactic_expr3
-| "progress" tactic_expr3
-| "once" tactic_expr3
-| "exactly_once" tactic_expr3
-| "infoH" tactic_expr3
-| "abstract" tactic_expr2
-| "abstract" tactic_expr2 "using" ident
-| selector tactic_expr3
-| tactic_expr2
-]
-
-tactic_expr2: [
-| tactic_expr1 "+" binder_tactic
-| tactic_expr1 "+" tactic_expr2
-| "tryif" tactic_expr5 "then" tactic_expr5 "else" tactic_expr2
-| tactic_expr1 "||" binder_tactic
-| tactic_expr1 "||" tactic_expr2
-| tactic_expr1
-]
-
-tactic_expr1: [
+| ltac_expr4
+]
+
+ltac_expr4: [
+| ltac_expr3 ";" binder_tactic
+| ltac_expr3 ";" ltac_expr3
+| ltac_expr3 ";" tactic_then_locality for_each_goal "]"
+| ltac_expr3
+]
+
+ltac_expr3: [
+| "try" ltac_expr3
+| "do" int_or_var ltac_expr3
+| "timeout" int_or_var ltac_expr3
+| "time" OPT string ltac_expr3
+| "repeat" ltac_expr3
+| "progress" ltac_expr3
+| "once" ltac_expr3
+| "exactly_once" ltac_expr3
+| "infoH" ltac_expr3
+| "abstract" ltac_expr2
+| "abstract" ltac_expr2 "using" ident
+| "only" selector ":" ltac_expr3
+| ltac_expr2
+]
+
+ltac_expr2: [
+| ltac_expr1 "+" binder_tactic
+| ltac_expr1 "+" ltac_expr2
+| "tryif" ltac_expr5 "then" ltac_expr5 "else" ltac_expr2
+| ltac_expr1 "||" binder_tactic
+| ltac_expr1 "||" ltac_expr2
+| ltac_expr1
+]
+
+ltac_expr1: [
| match_key "goal" "with" match_context_list "end"
| match_key "reverse" "goal" "with" match_context_list "end"
-| match_key tactic_expr5 "with" match_list "end"
-| "first" "[" LIST0 tactic_expr5 SEP "|" "]"
-| "solve" "[" LIST0 tactic_expr5 SEP "|" "]"
+| match_key ltac_expr5 "with" match_list "end"
+| "first" "[" LIST0 ltac_expr5 SEP "|" "]"
+| "solve" "[" LIST0 ltac_expr5 SEP "|" "]"
| "idtac" LIST0 message_token
| failkw [ int_or_var | ] LIST0 message_token
| simple_tactic
-| tactic_arg
-| reference LIST0 tactic_arg_compat
-| tactic_expr0
+| tactic_value
+| reference LIST0 tactic_arg
+| ltac_expr0
]
-tactic_expr0: [
-| "(" tactic_expr5 ")"
-| "[" ">" tactic_then_gen "]"
+ltac_expr0: [
+| "(" ltac_expr5 ")"
+| "[" ">" for_each_goal "]"
| tactic_atom
]
@@ -2005,17 +2003,17 @@ failkw: [
]
binder_tactic: [
-| "fun" LIST1 input_fun "=>" tactic_expr5
-| "let" [ "rec" | ] LIST1 let_clause SEP "with" "in" tactic_expr5
+| "fun" LIST1 input_fun "=>" ltac_expr5
+| "let" [ "rec" | ] LIST1 let_clause SEP "with" "in" ltac_expr5
]
-tactic_arg_compat: [
-| tactic_arg
+tactic_arg: [
+| tactic_value
| Constr.constr
| "()"
]
-tactic_arg: [
+tactic_value: [
| constr_eval
| "fresh" LIST0 fresh_id
| "type_term" uconstr
@@ -2056,26 +2054,26 @@ input_fun: [
]
let_clause: [
-| identref ":=" tactic_expr5
-| "_" ":=" tactic_expr5
-| identref LIST1 input_fun ":=" tactic_expr5
+| identref ":=" ltac_expr5
+| "_" ":=" ltac_expr5
+| identref LIST1 input_fun ":=" ltac_expr5
]
match_pattern: [
-| "context" OPT Constr.ident "[" Constr.lconstr_pattern "]"
-| Constr.lconstr_pattern
+| "context" OPT Constr.ident "[" Constr.cpattern "]"
+| Constr.cpattern
]
-match_hyps: [
+match_hyp: [
| name ":" match_pattern
| name ":=" "[" match_pattern "]" ":" match_pattern
| name ":=" match_pattern
]
match_context_rule: [
-| LIST0 match_hyps SEP "," "|-" match_pattern "=>" tactic_expr5
-| "[" LIST0 match_hyps SEP "," "|-" match_pattern "]" "=>" tactic_expr5
-| "_" "=>" tactic_expr5
+| LIST0 match_hyp SEP "," "|-" match_pattern "=>" ltac_expr5
+| "[" LIST0 match_hyp SEP "," "|-" match_pattern "]" "=>" ltac_expr5
+| "_" "=>" ltac_expr5
]
match_context_list: [
@@ -2084,8 +2082,8 @@ match_context_list: [
]
match_rule: [
-| match_pattern "=>" tactic_expr5
-| "_" "=>" tactic_expr5
+| match_pattern "=>" ltac_expr5
+| "_" "=>" ltac_expr5
]
match_list: [
@@ -2105,12 +2103,12 @@ ltac_def_kind: [
]
tacdef_body: [
-| Constr.global LIST1 input_fun ltac_def_kind tactic_expr5
-| Constr.global ltac_def_kind tactic_expr5
+| Constr.global LIST1 input_fun ltac_def_kind ltac_expr5
+| Constr.global ltac_def_kind ltac_expr5
]
tactic: [
-| tactic_expr5
+| ltac_expr5
]
range_selector: [
@@ -2123,17 +2121,13 @@ range_selector_or_nth: [
| natural OPT [ "," LIST1 range_selector SEP "," ]
]
-selector_body: [
+selector: [
| range_selector_or_nth
| test_bracket_ident "[" ident "]"
]
-selector: [
-| "only" selector_body ":"
-]
-
toplevel_selector: [
-| selector_body ":"
+| selector ":"
| "!" ":"
| "all" ":"
]
@@ -2149,8 +2143,8 @@ G_LTAC_hint: [
| "Extern" natural OPT Constr.constr_pattern "=>" Pltac.tactic
]
-G_LTAC_operconstr0: [
-| "ltac" ":" "(" Pltac.tactic_expr ")"
+G_LTAC_term0: [
+| "ltac" ":" "(" Pltac.ltac_expr ")"
]
ltac_selector: [
@@ -2329,7 +2323,7 @@ intropattern: [
]
simple_intropattern: [
-| simple_intropattern_closed LIST0 [ "%" operconstr0 ]
+| simple_intropattern_closed LIST0 [ "%" term0 ]
]
simple_intropattern_closed: [
@@ -2358,7 +2352,7 @@ with_bindings: [
|
]
-red_flags: [
+red_flag: [
| "beta"
| "iota"
| "match"
@@ -2375,7 +2369,7 @@ delta_flag: [
]
strategy_flag: [
-| LIST1 red_flags
+| LIST1 red_flag
| delta_flag
]
@@ -2502,7 +2496,7 @@ as_name: [
]
by_tactic: [
-| "by" tactic_expr3
+| "by" ltac_expr3
|
]
@@ -2555,12 +2549,35 @@ field_mods: [
| "(" LIST1 field_mod SEP "," ")" (* ring plugin *)
]
-numnotoption: [
+deprecated_number_modifier: [
|
| "(" "warning" "after" bignat ")"
| "(" "abstract" "after" bignat ")"
]
+number_string_mapping: [
+| reference "=>" reference
+| "[" reference "]" "=>" reference
+]
+
+number_string_via: [
+| "via" reference "mapping" "[" LIST1 number_string_mapping SEP "," "]"
+]
+
+number_modifier: [
+| "warning" "after" bignat
+| "abstract" "after" bignat
+| number_string_via
+]
+
+number_options: [
+| "(" LIST1 number_modifier SEP "," ")"
+]
+
+string_option: [
+| "(" number_string_via ")"
+]
+
tac2pat1: [
| Prim.qualid LIST1 tac2pat0 (* Ltac2 plugin *)
| Prim.qualid (* Ltac2 plugin *)
@@ -2578,50 +2595,51 @@ tac2pat0: [
atomic_tac2pat: [
| (* Ltac2 plugin *)
-| tac2pat1 ":" tac2type5 (* Ltac2 plugin *)
+| tac2pat1 ":" ltac2_type5 (* Ltac2 plugin *)
| tac2pat1 "," LIST0 tac2pat1 SEP "," (* Ltac2 plugin *)
| tac2pat1 (* Ltac2 plugin *)
]
-tac2expr6: [
-| tac2expr5 ";" tac2expr6 (* Ltac2 plugin *)
-| tac2expr5 (* Ltac2 plugin *)
+ltac2_expr6: [
+| ltac2_expr5 ";" ltac2_expr6 (* Ltac2 plugin *)
+| ltac2_expr5 (* Ltac2 plugin *)
]
-tac2expr5: [
-| "fun" LIST1 G_LTAC2_input_fun "=>" tac2expr6 (* Ltac2 plugin *)
-| "let" rec_flag LIST1 G_LTAC2_let_clause SEP "with" "in" tac2expr6 (* Ltac2 plugin *)
-| "match" tac2expr5 "with" G_LTAC2_branches "end" (* Ltac2 plugin *)
-| tac2expr4 (* Ltac2 plugin *)
+ltac2_expr5: [
+| "fun" LIST1 G_LTAC2_input_fun "=>" ltac2_expr6 (* Ltac2 plugin *)
+| "let" rec_flag LIST1 G_LTAC2_let_clause SEP "with" "in" ltac2_expr6 (* Ltac2 plugin *)
+| "match" ltac2_expr5 "with" G_LTAC2_branches "end" (* Ltac2 plugin *)
+| "if" ltac2_expr5 "then" ltac2_expr5 "else" ltac2_expr5 (* Ltac2 plugin *)
+| ltac2_expr4 (* Ltac2 plugin *)
]
-tac2expr4: [
-| tac2expr3 (* Ltac2 plugin *)
+ltac2_expr4: [
+| ltac2_expr3 (* Ltac2 plugin *)
]
-tac2expr3: [
-| tac2expr2 "," LIST1 tac2expr2 SEP "," (* Ltac2 plugin *)
-| tac2expr2 (* Ltac2 plugin *)
+ltac2_expr3: [
+| ltac2_expr2 "," LIST1 ltac2_expr2 SEP "," (* Ltac2 plugin *)
+| ltac2_expr2 (* Ltac2 plugin *)
]
-tac2expr2: [
-| tac2expr1 "::" tac2expr2 (* Ltac2 plugin *)
-| tac2expr1 (* Ltac2 plugin *)
+ltac2_expr2: [
+| ltac2_expr1 "::" ltac2_expr2 (* Ltac2 plugin *)
+| ltac2_expr1 (* Ltac2 plugin *)
]
-tac2expr1: [
-| tac2expr0 LIST1 tac2expr0 (* Ltac2 plugin *)
-| tac2expr0 ".(" Prim.qualid ")" (* Ltac2 plugin *)
-| tac2expr0 ".(" Prim.qualid ")" ":=" tac2expr5 (* Ltac2 plugin *)
-| tac2expr0 (* Ltac2 plugin *)
+ltac2_expr1: [
+| ltac2_expr0 LIST1 ltac2_expr0 (* Ltac2 plugin *)
+| ltac2_expr0 ".(" Prim.qualid ")" (* Ltac2 plugin *)
+| ltac2_expr0 ".(" Prim.qualid ")" ":=" ltac2_expr5 (* Ltac2 plugin *)
+| ltac2_expr0 (* Ltac2 plugin *)
]
-tac2expr0: [
-| "(" tac2expr6 ")" (* Ltac2 plugin *)
-| "(" tac2expr6 ":" tac2type5 ")" (* Ltac2 plugin *)
+ltac2_expr0: [
+| "(" ltac2_expr6 ")" (* Ltac2 plugin *)
+| "(" ltac2_expr6 ":" ltac2_type5 ")" (* Ltac2 plugin *)
| "()" (* Ltac2 plugin *)
| "(" ")" (* Ltac2 plugin *)
-| "[" LIST0 tac2expr5 SEP ";" "]" (* Ltac2 plugin *)
+| "[" LIST0 ltac2_expr5 SEP ";" "]" (* Ltac2 plugin *)
| "{" tac2rec_fieldexprs "}" (* Ltac2 plugin *)
| G_LTAC2_tactic_atom (* Ltac2 plugin *)
]
@@ -2633,7 +2651,7 @@ G_LTAC2_branches: [
]
branch: [
-| tac2pat1 "=>" tac2expr6 (* Ltac2 plugin *)
+| tac2pat1 "=>" ltac2_expr6 (* Ltac2 plugin *)
]
rec_flag: [
@@ -2646,7 +2664,7 @@ mut_flag: [
| (* Ltac2 plugin *)
]
-typ_param: [
+ltac2_typevar: [
| "'" Prim.ident (* Ltac2 plugin *)
]
@@ -2660,48 +2678,48 @@ G_LTAC2_tactic_atom: [
| "constr" ":" "(" Constr.lconstr ")" (* Ltac2 plugin *)
| "open_constr" ":" "(" Constr.lconstr ")" (* Ltac2 plugin *)
| "ident" ":" "(" lident ")" (* Ltac2 plugin *)
-| "pattern" ":" "(" Constr.lconstr_pattern ")" (* Ltac2 plugin *)
+| "pattern" ":" "(" Constr.cpattern ")" (* Ltac2 plugin *)
| "reference" ":" "(" globref ")" (* Ltac2 plugin *)
| "ltac1" ":" "(" ltac1_expr_in_env ")" (* Ltac2 plugin *)
| "ltac1val" ":" "(" ltac1_expr_in_env ")" (* Ltac2 plugin *)
]
ltac1_expr_in_env: [
-| test_ltac1_env LIST0 locident "|-" ltac1_expr (* Ltac2 plugin *)
-| ltac1_expr (* Ltac2 plugin *)
+| test_ltac1_env LIST0 locident "|-" ltac_expr5 (* Ltac2 plugin *)
+| ltac_expr5 (* Ltac2 plugin *)
]
tac2expr_in_env: [
-| test_ltac1_env LIST0 locident "|-" tac2expr6 (* Ltac2 plugin *)
-| tac2expr6 (* Ltac2 plugin *)
+| test_ltac1_env LIST0 locident "|-" ltac2_expr6 (* Ltac2 plugin *)
+| ltac2_expr6 (* Ltac2 plugin *)
]
G_LTAC2_let_clause: [
-| let_binder ":=" tac2expr6 (* Ltac2 plugin *)
+| let_binder ":=" ltac2_expr6 (* Ltac2 plugin *)
]
let_binder: [
| LIST1 G_LTAC2_input_fun (* Ltac2 plugin *)
]
-tac2type5: [
-| tac2type2 "->" tac2type5 (* Ltac2 plugin *)
-| tac2type2 (* Ltac2 plugin *)
+ltac2_type5: [
+| ltac2_type2 "->" ltac2_type5 (* Ltac2 plugin *)
+| ltac2_type2 (* Ltac2 plugin *)
]
-tac2type2: [
-| tac2type1 "*" LIST1 tac2type1 SEP "*" (* Ltac2 plugin *)
-| tac2type1 (* Ltac2 plugin *)
+ltac2_type2: [
+| ltac2_type1 "*" LIST1 ltac2_type1 SEP "*" (* Ltac2 plugin *)
+| ltac2_type1 (* Ltac2 plugin *)
]
-tac2type1: [
-| tac2type0 Prim.qualid (* Ltac2 plugin *)
-| tac2type0 (* Ltac2 plugin *)
+ltac2_type1: [
+| ltac2_type0 Prim.qualid (* Ltac2 plugin *)
+| ltac2_type0 (* Ltac2 plugin *)
]
-tac2type0: [
-| "(" LIST1 tac2type5 SEP "," ")" OPT Prim.qualid (* Ltac2 plugin *)
-| typ_param (* Ltac2 plugin *)
+ltac2_type0: [
+| "(" LIST1 ltac2_type5 SEP "," ")" OPT Prim.qualid (* Ltac2 plugin *)
+| ltac2_typevar (* Ltac2 plugin *)
| "_" (* Ltac2 plugin *)
| Prim.qualid (* Ltac2 plugin *)
]
@@ -2720,7 +2738,7 @@ G_LTAC2_input_fun: [
]
tac2def_body: [
-| G_LTAC2_binder LIST0 G_LTAC2_input_fun ":=" tac2expr6 (* Ltac2 plugin *)
+| G_LTAC2_binder LIST0 G_LTAC2_input_fun ":=" ltac2_expr6 (* Ltac2 plugin *)
]
tac2def_val: [
@@ -2728,11 +2746,11 @@ tac2def_val: [
]
tac2def_mut: [
-| "Set" Prim.qualid OPT [ "as" locident ] ":=" tac2expr6 (* Ltac2 plugin *)
+| "Set" Prim.qualid OPT [ "as" locident ] ":=" ltac2_expr6 (* Ltac2 plugin *)
]
tac2typ_knd: [
-| tac2type5 (* Ltac2 plugin *)
+| ltac2_type5 (* Ltac2 plugin *)
| "[" ".." "]" (* Ltac2 plugin *)
| "[" tac2alg_constructors "]" (* Ltac2 plugin *)
| "{" tac2rec_fields "}" (* Ltac2 plugin *)
@@ -2745,7 +2763,7 @@ tac2alg_constructors: [
tac2alg_constructor: [
| Prim.ident (* Ltac2 plugin *)
-| Prim.ident "(" LIST0 tac2type5 SEP "," ")" (* Ltac2 plugin *)
+| Prim.ident "(" LIST0 ltac2_type5 SEP "," ")" (* Ltac2 plugin *)
]
tac2rec_fields: [
@@ -2756,7 +2774,7 @@ tac2rec_fields: [
]
tac2rec_field: [
-| mut_flag Prim.ident ":" tac2type5 (* Ltac2 plugin *)
+| mut_flag Prim.ident ":" ltac2_type5 (* Ltac2 plugin *)
]
tac2rec_fieldexprs: [
@@ -2767,13 +2785,13 @@ tac2rec_fieldexprs: [
]
tac2rec_fieldexpr: [
-| Prim.qualid ":=" tac2expr1 (* Ltac2 plugin *)
+| Prim.qualid ":=" ltac2_expr1 (* Ltac2 plugin *)
]
tac2typ_prm: [
| (* Ltac2 plugin *)
-| typ_param (* Ltac2 plugin *)
-| "(" LIST1 typ_param SEP "," ")" (* Ltac2 plugin *)
+| ltac2_typevar (* Ltac2 plugin *)
+| "(" LIST1 ltac2_typevar SEP "," ")" (* Ltac2 plugin *)
]
tac2typ_def: [
@@ -2791,7 +2809,7 @@ tac2def_typ: [
]
tac2def_ext: [
-| "@" "external" locident ":" tac2type5 ":=" Prim.string Prim.string (* Ltac2 plugin *)
+| "@" "external" locident ":" ltac2_type5 ":=" Prim.string Prim.string (* Ltac2 plugin *)
]
syn_node: [
@@ -2799,11 +2817,11 @@ syn_node: [
| Prim.ident (* Ltac2 plugin *)
]
-sexpr: [
+ltac2_scope: [
| Prim.string (* Ltac2 plugin *)
| Prim.integer (* Ltac2 plugin *)
| syn_node (* Ltac2 plugin *)
-| syn_node "(" LIST1 sexpr SEP "," ")" (* Ltac2 plugin *)
+| syn_node "(" LIST1 ltac2_scope SEP "," ")" (* Ltac2 plugin *)
]
syn_level: [
@@ -2812,7 +2830,7 @@ syn_level: [
]
tac2def_syn: [
-| "Notation" LIST1 sexpr syn_level ":=" tac2expr6 (* Ltac2 plugin *)
+| "Notation" LIST1 ltac2_scope syn_level ":=" ltac2_expr6 (* Ltac2 plugin *)
]
lident: [
@@ -3030,28 +3048,28 @@ q_rewriting: [
]
G_LTAC2_tactic_then_last: [
-| "|" LIST0 ( OPT tac2expr6 ) SEP "|" (* Ltac2 plugin *)
+| "|" LIST0 ( OPT ltac2_expr6 ) SEP "|" (* Ltac2 plugin *)
| (* Ltac2 plugin *)
]
-G_LTAC2_tactic_then_gen: [
-| tac2expr6 "|" G_LTAC2_tactic_then_gen (* Ltac2 plugin *)
-| tac2expr6 ".." G_LTAC2_tactic_then_last (* Ltac2 plugin *)
+G_LTAC2_for_each_goal: [
+| ltac2_expr6 "|" G_LTAC2_for_each_goal (* Ltac2 plugin *)
+| ltac2_expr6 ".." G_LTAC2_tactic_then_last (* Ltac2 plugin *)
| ".." G_LTAC2_tactic_then_last (* Ltac2 plugin *)
-| tac2expr6 (* Ltac2 plugin *)
-| "|" G_LTAC2_tactic_then_gen (* Ltac2 plugin *)
+| ltac2_expr6 (* Ltac2 plugin *)
+| "|" G_LTAC2_for_each_goal (* Ltac2 plugin *)
| (* Ltac2 plugin *)
]
q_dispatch: [
-| G_LTAC2_tactic_then_gen (* Ltac2 plugin *)
+| G_LTAC2_for_each_goal (* Ltac2 plugin *)
]
q_occurrences: [
| G_LTAC2_occs (* Ltac2 plugin *)
]
-red_flag: [
+ltac2_red_flag: [
| "beta" (* Ltac2 plugin *)
| "iota" (* Ltac2 plugin *)
| "match" (* Ltac2 plugin *)
@@ -3082,7 +3100,7 @@ G_LTAC2_delta_flag: [
]
G_LTAC2_strategy_flag: [
-| LIST1 red_flag (* Ltac2 plugin *)
+| LIST1 ltac2_red_flag (* Ltac2 plugin *)
| G_LTAC2_delta_flag (* Ltac2 plugin *)
]
@@ -3100,12 +3118,12 @@ q_hintdb: [
]
G_LTAC2_match_pattern: [
-| "context" OPT Prim.ident "[" Constr.lconstr_pattern "]" (* Ltac2 plugin *)
-| Constr.lconstr_pattern (* Ltac2 plugin *)
+| "context" OPT Prim.ident "[" Constr.cpattern "]" (* Ltac2 plugin *)
+| Constr.cpattern (* Ltac2 plugin *)
]
G_LTAC2_match_rule: [
-| G_LTAC2_match_pattern "=>" tac2expr6 (* Ltac2 plugin *)
+| G_LTAC2_match_pattern "=>" ltac2_expr6 (* Ltac2 plugin *)
]
G_LTAC2_match_list: [
@@ -3126,16 +3144,16 @@ gmatch_pattern: [
]
gmatch_rule: [
-| gmatch_pattern "=>" tac2expr6 (* Ltac2 plugin *)
+| gmatch_pattern "=>" ltac2_expr6 (* Ltac2 plugin *)
]
-gmatch_list: [
+goal_match_list: [
| LIST1 gmatch_rule SEP "|" (* Ltac2 plugin *)
| "|" LIST1 gmatch_rule SEP "|" (* Ltac2 plugin *)
]
q_goal_matching: [
-| gmatch_list (* Ltac2 plugin *)
+| goal_match_list (* Ltac2 plugin *)
]
move_location: [
@@ -3169,7 +3187,7 @@ G_LTAC2_as_ipat: [
]
G_LTAC2_by_tactic: [
-| "by" tac2expr6 (* Ltac2 plugin *)
+| "by" ltac2_expr6 (* Ltac2 plugin *)
| (* Ltac2 plugin *)
]
@@ -3192,11 +3210,11 @@ ltac2_entry: [
]
ltac2_expr: [
-| tac2expr6 (* Ltac2 plugin *)
+| _ltac2_expr (* Ltac2 plugin *)
]
tac2mode: [
-| ltac2_expr ltac_use_default (* Ltac2 plugin *)
+| ltac2_expr6 ltac_use_default (* Ltac2 plugin *)
| G_vernac.query_command (* Ltac2 plugin *)
]
diff --git a/doc/tools/docgram/orderedGrammar b/doc/tools/docgram/orderedGrammar
index cbef29fb39..75c0ca1453 100644
--- a/doc/tools/docgram/orderedGrammar
+++ b/doc/tools/docgram/orderedGrammar
@@ -3,10 +3,6 @@ doc_grammar will modify this file to add/remove nonterminals and productions
to match editedGrammar, which will remove comments. Not compiled into Coq *)
DOC_GRAMMAR
-tactic_mode: [
-| OPT ( toplevel_selector ":" ) "{"
-]
-
term: [
| term_forall_or_fun
| term_let
@@ -191,6 +187,15 @@ where: [
| "before" ident
]
+add_zify: [
+| [ "InjTyp" | "BinOp" | "UnOp" | "CstOp" | "BinRel" | "UnOpSpec" | "BinOpSpec" ] (* Micromega plugin *)
+| [ "PropOp" | "PropBinOp" | "PropUOp" | "Saturate" ] (* Micromega plugin *)
+]
+
+show_zify: [
+| [ "InjTyp" | "BinOp" | "UnOp" | "CstOp" | "BinRel" | "UnOpSpec" | "BinOpSpec" | "Spec" ] (* Micromega plugin *)
+]
+
REACHABLE: [
| command
| simple_tactic
@@ -315,11 +320,11 @@ univ_constraint: [
]
term_fix: [
-| "let" "fix" fix_body "in" term
-| "fix" fix_body OPT ( LIST1 ( "with" fix_body ) "for" ident )
+| "let" "fix" fix_decl "in" term
+| "fix" fix_decl OPT ( LIST1 ( "with" fix_decl ) "for" ident )
]
-fix_body: [
+fix_decl: [
| ident LIST0 binder OPT fixannot OPT ( ":" type ) ":=" term
]
@@ -448,9 +453,7 @@ vernac_aux: [
]
subprf: [
-| bullet
| "{"
-| "}"
]
fix_definition: [
@@ -538,8 +541,12 @@ variant_definition: [
| ident_decl LIST0 binder OPT [ "|" LIST0 binder ] OPT [ ":" type ] ":=" OPT "|" LIST1 constructor SEP "|" OPT decl_notations
]
+singleton_class_definition: [
+| OPT ">" ident_decl LIST0 binder OPT [ ":" sort ] ":=" constructor
+]
+
record_definition: [
-| OPT ">" ident_decl LIST0 binder OPT [ ":" type ] OPT ident "{" LIST0 record_field SEP ";" "}" OPT decl_notations
+| OPT ">" ident_decl LIST0 binder OPT [ ":" sort ] OPT ( ":=" OPT ident "{" LIST0 record_field SEP ";" OPT ";" "}" )
]
record_field: [
@@ -553,7 +560,7 @@ field_body: [
]
term_record: [
-| "{|" LIST0 field_def "|}"
+| "{|" LIST0 field_def SEP ";" OPT ";" "|}"
]
field_def: [
@@ -566,7 +573,7 @@ inductive_definition: [
constructors_or_record: [
| OPT "|" LIST1 constructor SEP "|"
-| OPT ident "{" LIST0 record_field SEP ";" "}"
+| OPT ident "{" LIST0 record_field SEP ";" OPT ";" "}"
]
constructor: [
@@ -582,11 +589,8 @@ cofix_definition: [
]
scheme_kind: [
-| "Induction" "for" reference "Sort" sort_family
-| "Minimality" "for" reference "Sort" sort_family
-| "Elimination" "for" reference "Sort" sort_family
-| "Case" "for" reference "Sort" sort_family
| "Equality" "for" reference
+| [ "Induction" | "Minimality" | "Elimination" | "Case" ] "for" reference "Sort" sort_family
]
sort_family: [
@@ -714,7 +718,7 @@ simple_reserv: [
]
command: [
-| "Goal" term
+| "Goal" type
| "Pwd"
| "Cd" OPT string
| "Load" OPT "Verbose" [ string | ident ]
@@ -723,6 +727,8 @@ command: [
| "Locate" "Term" reference
| "Locate" "Module" qualid
| "Info" natural ltac_expr
+| "Add" "Zify" add_zify one_term (* Micromega plugin *)
+| "Show" "Zify" show_zify (* Micromega plugin *)
| "Locate" "Ltac" qualid
| "Locate" "Library" qualid
| "Locate" "File" string
@@ -798,7 +804,7 @@ command: [
| "Extraction" "NoInline" LIST1 qualid (* extraction plugin *)
| "Print" "Extraction" "Inline" (* extraction plugin *)
| "Reset" "Extraction" "Inline" (* extraction plugin *)
-| "Extraction" "Implicit" qualid "[" LIST0 int_or_id "]" (* extraction plugin *)
+| "Extraction" "Implicit" qualid "[" LIST0 [ ident | integer ] "]" (* extraction plugin *)
| "Extraction" "Blacklist" LIST1 ident (* extraction plugin *)
| "Print" "Extraction" "Blacklist" (* extraction plugin *)
| "Reset" "Extraction" "Blacklist" (* extraction plugin *)
@@ -810,7 +816,7 @@ command: [
| "Proof" "Mode" string
| "Proof" term
| "Abort" OPT [ "All" | ident ]
-| "Existential" natural OPT ( ":" term ) ":=" term
+| "Existential" natural OPT ( ":" type ) ":=" term
| "Admitted"
| "Qed"
| "Save" ident
@@ -835,10 +841,10 @@ command: [
| "Comments" LIST0 [ one_term | string | natural ]
| "Declare" "Instance" ident_decl LIST0 binder ":" term OPT hint_info
| "Declare" "Scope" scope_name
-| "Obligation" natural OPT ( "of" ident ) OPT ( ":" term OPT ( "with" ltac_expr ) )
+| "Obligation" natural OPT ( "of" ident ) OPT ( ":" type OPT ( "with" ltac_expr ) )
| "Next" "Obligation" OPT ( "of" ident ) OPT ( "with" ltac_expr )
| "Solve" "Obligation" natural OPT ( "of" ident ) "with" ltac_expr
-| "Solve" "Obligations" OPT ( OPT ( "of" ident ) "with" ltac_expr )
+| "Solve" "Obligations" OPT ( "of" ident ) OPT ( "with" ltac_expr )
| "Solve" "All" "Obligations" OPT ( "with" ltac_expr )
| "Admit" "Obligations" OPT ( "of" ident )
| "Obligation" "Tactic" ":=" ltac_expr
@@ -862,17 +868,6 @@ command: [
| "Reset" "Ltac" "Profile"
| "Show" "Ltac" "Profile" OPT [ "CutOff" integer | string ]
| "Show" "Lia" "Profile" (* micromega plugin *)
-| "Add" "Zify" "InjTyp" one_term (* micromega plugin *)
-| "Add" "Zify" "BinOp" one_term (* micromega plugin *)
-| "Add" "Zify" "UnOp" one_term (* micromega plugin *)
-| "Add" "Zify" "CstOp" one_term (* micromega plugin *)
-| "Add" "Zify" "BinRel" one_term (* micromega plugin *)
-| "Add" "Zify" "PropOp" one_term (* micromega plugin *)
-| "Add" "Zify" "PropBinOp" one_term (* micromega plugin *)
-| "Add" "Zify" "PropUOp" one_term (* micromega plugin *)
-| "Add" "Zify" "BinOpSpec" one_term (* micromega plugin *)
-| "Add" "Zify" "UnOpSpec" one_term (* micromega plugin *)
-| "Add" "Zify" "Saturate" one_term (* micromega plugin *)
| "Add" "InjTyp" one_term (* micromega plugin *)
| "Add" "BinOp" one_term (* micromega plugin *)
| "Add" "UnOp" one_term (* micromega plugin *)
@@ -884,25 +879,17 @@ command: [
| "Add" "BinOpSpec" one_term (* micromega plugin *)
| "Add" "UnOpSpec" one_term (* micromega plugin *)
| "Add" "Saturate" one_term (* micromega plugin *)
-| "Show" "Zify" "InjTyp" (* micromega plugin *)
-| "Show" "Zify" "BinOp" (* micromega plugin *)
-| "Show" "Zify" "UnOp" (* micromega plugin *)
-| "Show" "Zify" "CstOp" (* micromega plugin *)
-| "Show" "Zify" "BinRel" (* micromega plugin *)
-| "Show" "Zify" "UnOpSpec" (* micromega plugin *)
-| "Show" "Zify" "BinOpSpec" (* micromega plugin *)
| "Show" "Zify" "Spec" (* micromega plugin *)
| "Add" "Ring" ident ":" one_term OPT ( "(" LIST1 ring_mod SEP "," ")" ) (* ring plugin *)
| "Print" "Rings" (* ring plugin *)
| "Add" "Field" ident ":" one_term OPT ( "(" LIST1 field_mod SEP "," ")" ) (* ring plugin *)
| "Print" "Fields" (* ring plugin *)
-| "Number" "Notation" qualid qualid qualid ":" ident OPT numeral_modifier
| "Hint" "Cut" "[" hints_path "]" OPT ( ":" LIST1 ident )
-| "Typeclasses" "Transparent" LIST0 qualid
-| "Typeclasses" "Opaque" LIST0 qualid
-| "Typeclasses" "eauto" ":=" OPT "debug" OPT ( "(" eauto_search_strategy_name ")" ) OPT integer
-| "Proof" "with" ltac_expr OPT [ "using" section_subset_expr ]
-| "Proof" "using" section_subset_expr OPT [ "with" ltac_expr ]
+| "Typeclasses" "Transparent" LIST1 qualid
+| "Typeclasses" "Opaque" LIST1 qualid
+| "Typeclasses" "eauto" ":=" OPT "debug" OPT ( "(" [ "bfs" | "dfs" ] ")" ) OPT natural
+| "Proof" "with" ltac_expr OPT [ "using" section_var_expr ]
+| "Proof" "using" section_var_expr OPT [ "with" ltac_expr ]
| "Tactic" "Notation" OPT ( "(" "at" "level" natural ")" ) LIST1 ltac_production_item ":=" ltac_expr
| "Print" "Rewrite" "HintDb" ident
| "Print" "Ltac" qualid
@@ -911,8 +898,8 @@ command: [
| "Set" "Firstorder" "Solver" ltac_expr
| "Print" "Firstorder" "Solver"
| "Function" fix_definition LIST0 ( "with" fix_definition )
-| "Functional" "Scheme" fun_scheme_arg LIST0 ( "with" fun_scheme_arg )
-| "Functional" "Case" fun_scheme_arg (* funind plugin *)
+| "Functional" "Scheme" func_scheme_def LIST0 ( "with" func_scheme_def )
+| "Functional" "Case" func_scheme_def (* funind plugin *)
| "Generate" "graph" "for" qualid (* funind plugin *)
| "Hint" "Rewrite" OPT [ "->" | "<-" ] LIST1 one_term OPT ( "using" ltac_expr ) OPT ( ":" LIST0 ident )
| "Derive" "Inversion_clear" ident "with" one_term OPT ( "Sort" sort_family )
@@ -921,8 +908,9 @@ command: [
| "Derive" "Dependent" "Inversion_clear" ident "with" one_term "Sort" sort_family
| "Declare" "Left" "Step" one_term
| "Declare" "Right" "Step" one_term
-| "Numeral" "Notation" qualid qualid qualid ":" scope_name OPT numeral_modifier
-| "String" "Notation" qualid qualid qualid ":" scope_name
+| "Number" "Notation" qualid qualid qualid OPT ( "(" LIST1 number_modifier SEP "," ")" ) ":" scope_name
+| "Numeral" "Notation" qualid qualid qualid ":" scope_name deprecated_number_modifier
+| "String" "Notation" qualid qualid qualid OPT ( "(" number_string_via ")" ) ":" scope_name
| "SubClass" ident_decl def_body
| thm_token ident_decl LIST0 binder ":" type LIST0 [ "with" ident_decl LIST0 binder ":" type ]
| assumption_token OPT ( "Inline" OPT ( "(" natural ")" ) ) [ LIST1 ( "(" assumpt ")" ) | assumpt ]
@@ -944,13 +932,14 @@ command: [
| "CoInductive" inductive_definition LIST0 ( "with" inductive_definition )
| "Variant" variant_definition LIST0 ( "with" variant_definition )
| [ "Record" | "Structure" ] record_definition LIST0 ( "with" record_definition )
-| "Class" inductive_definition LIST0 ( "with" inductive_definition )
+| "Class" record_definition
+| "Class" singleton_class_definition
| "Module" OPT [ "Import" | "Export" ] ident LIST0 module_binder OPT of_module_type OPT ( ":=" LIST1 module_expr_inl SEP "<+" )
| "Module" "Type" ident LIST0 module_binder LIST0 ( "<:" module_type_inl ) OPT ( ":=" LIST1 module_type_inl SEP "<+" )
| "Declare" "Module" OPT [ "Import" | "Export" ] ident LIST0 module_binder ":" module_type_inl
| "Section" ident
| "End" ident
-| "Collection" ident ":=" section_subset_expr
+| "Collection" ident ":=" section_var_expr
| "Require" OPT [ "Import" | "Export" ] LIST1 qualid
| "From" dirpath "Require" OPT [ "Import" | "Export" ] LIST1 qualid
| "Import" LIST1 filtered_import
@@ -962,11 +951,11 @@ command: [
| "Strategy" LIST1 [ strategy_level "[" LIST1 reference "]" ]
| "Canonical" OPT "Structure" ident_decl def_body
| "Canonical" OPT "Structure" reference
-| "Coercion" qualid OPT univ_decl def_body
+| "Coercion" ident OPT univ_decl def_body
| "Identity" "Coercion" ident ":" class ">->" class
| "Coercion" reference ":" class ">->" class
| "Context" LIST1 binder
-| "Instance" OPT ( ident_decl LIST0 binder ) ":" term OPT hint_info OPT [ ":=" "{" LIST0 field_def "}" | ":=" term ]
+| "Instance" OPT ( ident_decl LIST0 binder ) ":" type OPT hint_info OPT [ ":=" "{" LIST0 field_def "}" | ":=" term ]
| "Existing" "Instance" qualid OPT hint_info
| "Existing" "Instances" LIST1 qualid OPT [ "|" natural ]
| "Existing" "Class" qualid
@@ -1012,35 +1001,26 @@ command: [
| "Show" "Goal" natural "at" natural
]
-section_subset_expr: [
-| LIST0 starredidentref
-| ssexpr
+section_var_expr: [
+| LIST0 starred_ident_ref
+| OPT "-" section_var_expr50
]
-ssexpr: [
-| "-" ssexpr50
-| ssexpr50
+section_var_expr50: [
+| section_var_expr0 "-" section_var_expr0
+| section_var_expr0 "+" section_var_expr0
+| section_var_expr0
]
-ssexpr50: [
-| ssexpr0 "-" ssexpr0
-| ssexpr0 "+" ssexpr0
-| ssexpr0
+section_var_expr0: [
+| starred_ident_ref
+| "(" section_var_expr ")" OPT "*"
]
-ssexpr0: [
-| starredidentref
-| "(" LIST0 starredidentref ")"
-| "(" LIST0 starredidentref ")" "*"
-| "(" ssexpr ")"
-| "(" ssexpr ")" "*"
-]
-
-starredidentref: [
-| ident
-| ident "*"
-| "Type"
-| "Type" "*"
+starred_ident_ref: [
+| ident OPT "*"
+| "Type" OPT "*"
+| "All"
]
dirpath: [
@@ -1137,13 +1117,13 @@ lident: [
destruction_arg: [
| natural
-| constr_with_bindings
+| one_term OPT ( "with" bindings )
| constr_with_bindings_arg
]
constr_with_bindings_arg: [
-| ">" constr_with_bindings
-| constr_with_bindings
+| ">" one_term OPT ( "with" bindings )
+| one_term OPT ( "with" bindings )
]
clause_dft_concl: [
@@ -1262,11 +1242,6 @@ qhyp: [
| lident (* Ltac2 plugin *)
]
-int_or_id: [
-| ident
-| integer (* extraction plugin *)
-]
-
language: [
| "OCaml" (* extraction plugin *)
| "Haskell" (* extraction plugin *)
@@ -1274,10 +1249,6 @@ language: [
| "JSON" (* extraction plugin *)
]
-fun_scheme_arg: [
-| ident ":=" "Induction" "for" qualid "Sort" sort_family (* funind plugin *)
-]
-
ring_mod: [
| "decidable" one_term (* ring plugin *)
| "abstract" (* ring plugin *)
@@ -1298,11 +1269,22 @@ field_mod: [
| "completeness" one_term (* ring plugin *)
]
-numeral_modifier: [
+deprecated_number_modifier: [
+|
| "(" "warning" "after" bignat ")"
| "(" "abstract" "after" bignat ")"
]
+number_modifier: [
+| "warning" "after" bignat
+| "abstract" "after" bignat
+| number_string_via
+]
+
+number_string_via: [
+| "via" qualid "mapping" "[" LIST1 [ qualid "=>" qualid | "[" qualid "]" "=>" qualid ] SEP "," "]"
+]
+
hints_path: [
| "(" hints_path ")"
| hints_path "*"
@@ -1314,11 +1296,6 @@ hints_path: [
| hints_path hints_path
]
-eauto_search_strategy_name: [
-| "bfs"
-| "dfs"
-]
-
class: [
| "Funclass"
| "Sortclass"
@@ -1390,7 +1367,7 @@ simple_tactic: [
| "eright" OPT ( "with" bindings )
| "constructor" OPT int_or_var OPT ( "with" bindings )
| "econstructor" OPT ( int_or_var OPT ( "with" bindings ) )
-| "specialize" constr_with_bindings OPT ( "as" simple_intropattern )
+| "specialize" one_term OPT ( "with" bindings ) OPT ( "as" simple_intropattern )
| "symmetry" OPT ( "in" in_clause )
| "split" OPT ( "with" bindings )
| "esplit" OPT ( "with" bindings )
@@ -1411,6 +1388,10 @@ simple_tactic: [
| "generalize" "dependent" one_term
| "replace" one_term "with" one_term OPT clause_dft_concl OPT ( "by" ltac_expr3 )
| "replace" OPT [ "->" | "<-" ] one_term OPT clause_dft_concl
+| "setoid_replace" one_term "with" one_term OPT ( "using" "relation" one_term ) OPT ( "in" ident ) OPT ( "at" LIST1 int_or_var ) OPT ( "by" ltac_expr3 )
+| OPT ( [ natural | "[" ident "]" ] ":" ) "{"
+| bullet
+| "}"
| "try" ltac_expr3
| "do" int_or_var ltac_expr3
| "timeout" int_or_var ltac_expr3
@@ -1456,7 +1437,7 @@ simple_tactic: [
| "decompose" "sum" one_term
| "decompose" "record" one_term
| "absurd" one_term
-| "contradiction" OPT constr_with_bindings
+| "contradiction" OPT ( one_term OPT ( "with" bindings ) )
| "autorewrite" OPT "*" "with" LIST1 ident OPT clause_dft_concl OPT ( "using" ltac_expr )
| "rewrite" "*" OPT [ "->" | "<-" ] one_term OPT ( "in" ident ) OPT ( "at" occurrences OPT ( "by" ltac_expr3 ) )
| "rewrite" "*" OPT [ "->" | "<-" ] one_term "at" occurrences "in" ident OPT ( "by" ltac_expr3 )
@@ -1465,7 +1446,7 @@ simple_tactic: [
| "notypeclasses" "refine" one_term
| "simple" "notypeclasses" "refine" one_term
| "solve_constraints"
-| "subst" OPT ( LIST1 ident )
+| "subst" LIST0 ident
| "simple" "subst"
| "evar" "(" ident ":" term ")"
| "evar" one_term
@@ -1529,9 +1510,7 @@ simple_tactic: [
| "autounfold_one" OPT hintbases OPT ( "in" ident )
| "unify" one_term one_term OPT ( "with" ident )
| "convert_concl_no_check" one_term
-| "typeclasses" "eauto" "bfs" OPT int_or_var "with" LIST1 ident
-| "typeclasses" "eauto" OPT int_or_var "with" LIST1 ident
-| "typeclasses" "eauto" OPT int_or_var
+| "typeclasses" "eauto" OPT "bfs" OPT int_or_var OPT ( "with" LIST1 ident )
| "head_of_constr" ident one_term
| "not_evar" one_term
| "is_ground" one_term
@@ -1540,9 +1519,9 @@ simple_tactic: [
| "progress_evars" ltac_expr
| "rewrite_strat" rewstrategy OPT ( "in" ident )
| "rewrite_db" ident OPT ( "in" ident )
-| "substitute" OPT [ "->" | "<-" ] constr_with_bindings
-| "setoid_rewrite" OPT [ "->" | "<-" ] constr_with_bindings OPT ( "at" occurrences ) OPT ( "in" ident )
-| "setoid_rewrite" OPT [ "->" | "<-" ] constr_with_bindings "in" ident "at" occurrences
+| "substitute" OPT [ "->" | "<-" ] one_term OPT ( "with" bindings )
+| "setoid_rewrite" OPT [ "->" | "<-" ] one_term OPT ( "with" bindings ) OPT ( "at" occurrences ) OPT ( "in" ident )
+| "setoid_rewrite" OPT [ "->" | "<-" ] one_term OPT ( "with" bindings ) "in" ident "at" occurrences
| "setoid_symmetry" OPT ( "in" ident )
| "setoid_reflexivity"
| "setoid_transitivity" one_term
@@ -1555,8 +1534,8 @@ simple_tactic: [
| "eapply" LIST1 constr_with_bindings_arg SEP "," OPT in_hyp_as
| "simple" "apply" LIST1 constr_with_bindings_arg SEP "," OPT in_hyp_as
| "simple" "eapply" LIST1 constr_with_bindings_arg SEP "," OPT in_hyp_as
-| "elim" constr_with_bindings_arg OPT ( "using" constr_with_bindings )
-| "eelim" constr_with_bindings_arg OPT ( "using" constr_with_bindings )
+| "elim" constr_with_bindings_arg OPT ( "using" one_term OPT ( "with" bindings ) )
+| "eelim" constr_with_bindings_arg OPT ( "using" one_term OPT ( "with" bindings ) )
| "case" induction_clause_list
| "ecase" induction_clause_list
| "fix" ident natural OPT ( "with" LIST1 fixdecl )
@@ -1619,8 +1598,8 @@ simple_tactic: [
| "firstorder" OPT ltac_expr firstorder_rhs
| "gintuition" OPT ltac_expr
| "functional" "inversion" [ ident | natural ] OPT qualid (* funind plugin *)
-| "functional" "induction" term OPT fun_ind_using OPT with_names (* funind plugin *)
-| "soft" "functional" "induction" LIST1 one_term OPT fun_ind_using OPT with_names (* funind plugin *)
+| "functional" "induction" term OPT ( "using" one_term OPT ( "with" bindings ) ) OPT ( "as" simple_intropattern ) (* funind plugin *)
+| "soft" "functional" "induction" LIST1 one_term OPT ( "using" one_term OPT ( "with" bindings ) ) OPT ( "as" simple_intropattern ) (* funind plugin *)
| "psatz_Z" OPT int_or_var ltac_expr
| "xlia" ltac_expr (* micromega plugin *)
| "xnlia" ltac_expr (* micromega plugin *)
@@ -1663,15 +1642,16 @@ simple_tactic: [
| "zify"
| "assert_fails" ltac_expr3
| "assert_succeeds" ltac_expr3
-| "field" OPT ( "[" LIST1 term "]" )
-| "field_simplify" OPT ( "[" LIST1 term "]" ) LIST1 term OPT ( "in" ident )
-| "field_simplify_eq" OPT ( "[" LIST1 term "]" ) OPT ( "in" ident )
+| "field" OPT ( "[" LIST1 one_term "]" )
+| "field_simplify" OPT ( "[" LIST1 one_term "]" ) LIST1 one_term OPT ( "in" ident )
+| "field_simplify_eq" OPT ( "[" LIST1 one_term "]" ) OPT ( "in" ident )
| "intuition" OPT ltac_expr
-| "nsatz" OPT ( "with" "radicalmax" ":=" term "strategy" ":=" term "parameters" ":=" term "variables" ":=" term )
-| "psatz" term OPT int_or_var
-| "ring" OPT ( "[" LIST1 term "]" )
-| "ring_simplify" OPT ( "[" LIST1 term "]" ) LIST1 term OPT ( "in" ident )
+| "nsatz" OPT ( "with" "radicalmax" ":=" one_term "strategy" ":=" one_term "parameters" ":=" one_term "variables" ":=" one_term )
+| "psatz" one_term OPT int_or_var
+| "ring" OPT ( "[" LIST1 one_term "]" )
+| "ring_simplify" OPT ( "[" LIST1 one_term "]" ) LIST1 one_term OPT ( "in" ident )
| "match" ltac2_expr5 "with" OPT ltac2_branches "end"
+| "if" ltac2_expr5 "then" ltac2_expr5 "else" ltac2_expr5
| qualid LIST1 tactic_arg
]
@@ -1718,7 +1698,7 @@ induction_clause: [
]
induction_clause_list: [
-| LIST1 induction_clause SEP "," OPT ( "using" constr_with_bindings ) OPT opt_clause
+| LIST1 induction_clause SEP "," OPT ( "using" one_term OPT ( "with" bindings ) ) OPT opt_clause
]
auto_using: [
@@ -1764,13 +1744,8 @@ simple_intropattern_closed: [
| naming_intropattern
]
-simple_binding: [
-| "(" ident ":=" term ")"
-| "(" natural ":=" term ")"
-]
-
bindings: [
-| LIST1 simple_binding
+| LIST1 ( "(" [ ident | natural ] ":=" term ")" )
| LIST1 one_term
]
@@ -2184,10 +2159,6 @@ cofixdecl: [
| "(" ident LIST0 simple_binder ":" term ")"
]
-constr_with_bindings: [
-| one_term OPT ( "with" bindings )
-]
-
conversion: [
| one_term
| one_term "with" one_term
@@ -2200,12 +2171,8 @@ firstorder_using: [
| "using" qualid qualid LIST0 qualid
]
-fun_ind_using: [
-| "using" constr_with_bindings (* funind plugin *)
-]
-
-with_names: [
-| "as" simple_intropattern (* funind plugin *)
+func_scheme_def: [
+| ident ":=" "Induction" "for" qualid "Sort" sort_family (* funind plugin *)
]
occurrences: [
diff --git a/engine/eConstr.ml b/engine/eConstr.ml
index 36297fe243..0c84dee572 100644
--- a/engine/eConstr.ml
+++ b/engine/eConstr.ml
@@ -127,9 +127,9 @@ let isRef sigma c = match kind sigma c with
let isRefX sigma x c =
let open GlobRef in
match x, kind sigma c with
- | ConstRef c, Const (c', _) -> Constant.equal c c'
- | IndRef i, Ind (i', _) -> eq_ind i i'
- | ConstructRef i, Construct (i', _) -> eq_constructor i i'
+ | ConstRef c, Const (c', _) -> Constant.CanOrd.equal c c'
+ | IndRef i, Ind (i', _) -> Ind.CanOrd.equal i i'
+ | ConstructRef i, Construct (i', _) -> Construct.CanOrd.equal i i'
| VarRef id, Var id' -> Id.equal id id'
| _ -> false
@@ -514,7 +514,7 @@ let compare_head_gen_proj env sigma equ eqs eqc' nargs m n =
| Proj (p, c), App (f, args)
| App (f, args), Proj (p, c) ->
(match kind f with
- | Const (p', u) when Constant.equal (Projection.constant p) p' ->
+ | Const (p', u) when Environ.QConstant.equal env (Projection.constant p) p' ->
let npars = Projection.npars p in
if Array.length args == npars + 1 then
eqc' 0 c args.(npars)
@@ -563,6 +563,9 @@ let universes_of_constr sigma c =
| Array (u,_,_,_) ->
let s = LSet.fold LSet.add (Instance.levels (EInstance.kind sigma u)) s in
fold sigma aux s c
+ | Case (_,_,CaseInvert {univs;args=_},_,_) ->
+ let s = LSet.fold LSet.add (Instance.levels (EInstance.kind sigma univs)) s in
+ fold sigma aux s c
| _ -> fold sigma aux s c
in aux LSet.empty c
@@ -625,6 +628,9 @@ let subst_var subst c = of_constr (Vars.subst_var subst (to_constr c))
let subst_univs_level_constr subst c =
of_constr (Vars.subst_univs_level_constr subst (to_constr c))
+let subst_univs_constr subst c =
+ of_constr (UnivSubst.subst_univs_constr subst (to_constr c))
+
(** Operations that dot NOT commute with evar-normalization *)
let noccurn sigma n term =
let rec occur_rec n c = match kind sigma c with
diff --git a/engine/eConstr.mli b/engine/eConstr.mli
index a018f4064f..882dfe2848 100644
--- a/engine/eConstr.mli
+++ b/engine/eConstr.mli
@@ -295,6 +295,7 @@ val closedn : Evd.evar_map -> int -> t -> bool
val closed0 : Evd.evar_map -> t -> bool
val subst_univs_level_constr : Univ.universe_level_subst -> t -> t
+val subst_univs_constr : Univ.universe_subst -> t -> t
val subst_of_rel_context_instance : rel_context -> t list -> t list
diff --git a/engine/termops.ml b/engine/termops.ml
index 0923ab6f4b..693945d5ac 100644
--- a/engine/termops.ml
+++ b/engine/termops.ml
@@ -233,13 +233,13 @@ let pr_evar_universe_context ctx =
if UState.is_empty ctx then mt ()
else
(str"UNIVERSES:"++brk(0,1)++
- h 0 (Univ.pr_universe_context_set prl (UState.context_set ctx)) ++ fnl () ++
+ h (Univ.pr_universe_context_set prl (UState.context_set ctx)) ++ fnl () ++
str"ALGEBRAIC UNIVERSES:"++brk(0,1)++
- h 0 (Univ.LSet.pr prl (UState.algebraics ctx)) ++ fnl() ++
+ h (Univ.LSet.pr prl (UState.algebraics ctx)) ++ fnl() ++
str"UNDEFINED UNIVERSES:"++brk(0,1)++
- h 0 (UnivSubst.pr_universe_opt_subst (UState.subst ctx)) ++ fnl() ++
+ h (UnivSubst.pr_universe_opt_subst (UState.subst ctx)) ++ fnl() ++
str "WEAK CONSTRAINTS:"++brk(0,1)++
- h 0 (UState.pr_weak prl ctx) ++ fnl ())
+ h (UState.pr_weak prl ctx) ++ fnl ())
let print_env_short env sigma =
let print_constr = print_kconstr in
@@ -316,14 +316,14 @@ let pr_evar_list env sigma l =
| Some ev' -> str " (aliased to " ++ Evar.print ev' ++ str ")"
in
let pr (ev, evi) =
- h 0 (Evar.print ev ++
+ h (Evar.print ev ++
str "==" ++ pr_evar_info env sigma evi ++
pr_alias ev ++
(if evi.evar_body == Evar_empty
then str " {" ++ pr_existential_key sigma ev ++ str "}"
else mt ()))
in
- h 0 (prlist_with_sep fnl pr l)
+ hv 0 (prlist_with_sep fnl pr l)
let to_list d =
let open Evd in
@@ -1145,9 +1145,9 @@ let compare_constr_univ sigma f cv_pb t1 t2 =
Sort s1, Sort s2 -> base_sort_cmp cv_pb (ESorts.kind sigma s1) (ESorts.kind sigma s2)
| Prod (_,t1,c1), Prod (_,t2,c2) ->
f Reduction.CONV t1 t2 && f cv_pb c1 c2
- | Const (c, u), Const (c', u') -> Constant.equal c c'
- | Ind (i, _), Ind (i', _) -> eq_ind i i'
- | Construct (i, _), Construct (i', _) -> eq_constructor i i'
+ | Const (c, u), Const (c', u') -> Constant.CanOrd.equal c c'
+ | Ind (i, _), Ind (i', _) -> Ind.CanOrd.equal i i'
+ | Construct (i, _), Construct (i', _) -> Construct.CanOrd.equal i i'
| _ -> EConstr.compare_constr sigma (fun t1 t2 -> f Reduction.CONV t1 t2) t1 t2
let constr_cmp sigma cv_pb t1 t2 =
diff --git a/engine/uState.ml b/engine/uState.ml
index 8d1584cd95..9557111cfd 100644
--- a/engine/uState.ml
+++ b/engine/uState.ml
@@ -286,6 +286,10 @@ let process_universe_constraints ctx cstrs =
if not (drop_weak_constraints ()) then weak := UPairSet.add (l,r) !weak; local
| UEq (l, r) -> equalize_universes l r local
in
+ let unify_universes cst local =
+ if not (UGraph.type_in_type univs) then unify_universes cst local
+ else try unify_universes cst local with UniverseInconsistency _ -> local
+ in
let local =
UnivProblem.Set.fold unify_universes cstrs Constraint.empty
in
@@ -671,7 +675,7 @@ let subst_univs_context_with_def def usubst (ctx, cst) =
(LSet.diff ctx def, UnivSubst.subst_univs_constraints usubst cst)
let is_trivial_leq (l,d,r) =
- Level.is_prop l && (d == Le || (d == Lt && Level.is_set r))
+ Level.is_prop l && (d == Le || d == Lt) && Level.is_set r
(* Prop < i <-> Set+1 <= i <-> Set < i *)
let translate_cstr (l,d,r as cstr) =
diff --git a/engine/univMinim.ml b/engine/univMinim.ml
index 1c7e716fc2..4ed6e97526 100644
--- a/engine/univMinim.ml
+++ b/engine/univMinim.ml
@@ -292,22 +292,29 @@ let is_bound l lbound = match lbound with
| UGraph.Bound.Prop -> Level.is_prop l
| UGraph.Bound.Set -> Level.is_set l
+(* if [is_minimal u] then constraints [u <= v] may be dropped and get
+ used only for set_minimization. *)
+let is_minimal ~lbound u =
+ Level.is_sprop u || Level.is_prop u || is_bound u lbound
+
(* TODO check is_small/sprop *)
let normalize_context_set ~lbound g ctx us algs weak =
let (ctx, csts) = ContextSet.levels ctx, ContextSet.constraints ctx in
(* Keep the Prop/Set <= i constraints separate for minimization *)
let smallles, csts =
- Constraint.partition (fun (l,d,r) -> d == Le && (is_bound l lbound || Level.is_sprop l)) csts
+ Constraint.partition (fun (l,d,r) -> d == Le && is_minimal ~lbound l) csts
in
let smallles = if get_set_minimization ()
then Constraint.filter (fun (l,d,r) -> LMap.mem r us && not (Level.is_sprop l)) smallles
else Constraint.empty
in
+ let smallles = Constraint.map (fun (_,_,r) -> Level.set, Le, r) smallles in
let csts, partition =
(* We first put constraints in a normal-form: all self-loops are collapsed
to equalities. *)
+ let g = UGraph.initial_universes_with g in
let g = LSet.fold (fun v g -> UGraph.add_universe ~lbound ~strict:false v g)
- ctx UGraph.initial_universes
+ ctx g
in
let add_soft u g =
if not (Level.is_small u || LSet.mem u ctx)
diff --git a/gramlib/.merlin.in b/gramlib/.merlin.in
new file mode 100644
index 0000000000..cf828efdb7
--- /dev/null
+++ b/gramlib/.merlin.in
@@ -0,0 +1,3 @@
+FLG -open Gramlib
+
+REC
diff --git a/ide/.merlin.in b/ide/.merlin.in
index b8d7953833..50816ae3f5 100644
--- a/ide/.merlin.in
+++ b/ide/.merlin.in
@@ -1,8 +1,10 @@
PKG unix laglgtk3 lablgtk3-sourceview3
-S utils
-B utils
-S protocol
-B protocol
+S coqide/utils
+B coqide/utils
+S coqide/protocol
+B coqide/protocol
+S coqide/
+B coqide/
REC
diff --git a/ide/coqide/coq.ml b/ide/coqide/coq.ml
index 038c8b91a8..b8228df2aa 100644
--- a/ide/coqide/coq.ml
+++ b/ide/coqide/coq.ml
@@ -512,6 +512,7 @@ let hints x = eval_call (Xmlprotocol.hints x)
let search flags = eval_call (Xmlprotocol.search flags)
let init x = eval_call (Xmlprotocol.init x)
let stop_worker x = eval_call (Xmlprotocol.stop_worker x)
+let proof_diff x = eval_call (Xmlprotocol.proof_diff x)
let break_coqtop coqtop workers =
if coqtop.status = Busy then
@@ -549,6 +550,7 @@ struct
let existential = BoolOpt ["Printing"; "Existential"; "Instances"]
let universes = BoolOpt ["Printing"; "Universes"]
let unfocused = BoolOpt ["Printing"; "Unfocused"]
+ let goal_names = BoolOpt ["Printing"; "Goal"; "Names"]
let diff = StringOpt ["Diffs"]
type 'a descr = { opts : 'a t list; init : 'a; label : string }
@@ -567,7 +569,8 @@ struct
{ opts = [universes]; init = false; label = "Display _universe levels" };
{ opts = [all_basic;existential;universes]; init = false;
label = "Display all _low-level contents" };
- { opts = [unfocused]; init = false; label = "Display _unfocused goals" }
+ { opts = [unfocused]; init = false; label = "Display _unfocused goals" };
+ { opts = [goal_names]; init = false; label = "Display _goal names" }
]
let diff_item = { opts = [diff]; init = "off"; label = "Display _proof diffs" }
@@ -579,6 +582,9 @@ struct
let set (type a) (opt : a t) (v : a) =
Hashtbl.replace current_state (opt_name opt) (opt_data opt v)
+ let get (type a) (opt : a t) =
+ Hashtbl.find current_state (opt_name opt)
+
let reset () =
let init_descr d = List.iter (fun o -> set o d.init) d.opts in
List.iter init_descr bool_items;
diff --git a/ide/coqide/coq.mli b/ide/coqide/coq.mli
index 82df36c91c..aaaf14e4d0 100644
--- a/ide/coqide/coq.mli
+++ b/ide/coqide/coq.mli
@@ -127,6 +127,7 @@ val hints : Interface.hints_sty -> Interface.hints_rty query
val mkcases : Interface.mkcases_sty -> Interface.mkcases_rty query
val search : Interface.search_sty -> Interface.search_rty query
val init : Interface.init_sty -> Interface.init_rty query
+val proof_diff : Interface.proof_diff_sty -> Interface.proof_diff_rty query
val stop_worker: Interface.stop_worker_sty-> Interface.stop_worker_rty query
@@ -144,6 +145,10 @@ sig
val set : 'a t -> 'a -> unit
+ val get : 'a t -> Interface.option_value
+
+ val diff : string t
+
val printing_unfocused: unit -> bool
(** [enforce] transmits to coq the current option values.
diff --git a/ide/coqide/coqOps.ml b/ide/coqide/coqOps.ml
index 29ea3ce9ea..97076745a3 100644
--- a/ide/coqide/coqOps.ml
+++ b/ide/coqide/coqOps.ml
@@ -142,6 +142,7 @@ object
method handle_reset_initial : unit task
method raw_coq_query :
route_id:int -> next:(query_rty value -> unit task) -> string -> unit task
+ method proof_diff : GText.mark -> next:(Pp.t value -> unit task) -> unit task
method show_goals : unit task
method backtrack_last_phrase : unit task
method initialize : unit task
@@ -361,6 +362,27 @@ object(self)
let query = Coq.query (route_id,(phrase,sid)) in
Coq.bind (Coq.seq action query) next
+ method proof_diff where ~next : unit Coq.task =
+ (* todo: would be nice to ignore comments, too *)
+ let rec back iter =
+ if iter#is_start then iter
+ else
+ let c = iter#char in
+ if Glib.Unichar.isspace c || c = 0 then back (iter#backward_char)
+ else if c = int_of_char '.' then iter#backward_char
+ else iter in
+
+ let where = back (buffer#get_iter_at_mark where) in
+ let until _ start stop =
+ (buffer#get_iter_at_mark stop)#compare where >= 0 &&
+ (buffer#get_iter_at_mark start)#compare where <= 0 in
+ let state_id = fst @@ self#find_id until in
+ let diff_opt = Interface.(match Coq.PrintOpt.(get diff) with
+ | StringValue diffs -> diffs
+ | _ -> "off") in
+ let proof_diff = Coq.proof_diff (diff_opt, state_id) in
+ Coq.bind proof_diff next
+
method private still_valid { edit_id = id } =
try ignore(Doc.find_id document (fun _ { edit_id = id1 } -> id = id1)); true
with Not_found -> false
diff --git a/ide/coqide/coqOps.mli b/ide/coqide/coqOps.mli
index 3a4678ae9c..84911a6aa8 100644
--- a/ide/coqide/coqOps.mli
+++ b/ide/coqide/coqOps.mli
@@ -20,6 +20,7 @@ object
method handle_reset_initial : unit task
method raw_coq_query :
route_id:int -> next:(query_rty value -> unit task) -> string -> unit task
+ method proof_diff : GText.mark -> next:(Pp.t value -> unit task) -> unit task
method show_goals : unit task
method backtrack_last_phrase : unit task
method initialize : unit task
@@ -30,7 +31,6 @@ object
method get_errors : (int * string) list
method get_slaves_status : int * int * string CString.Map.t
-
method handle_failure : handle_exn_rty -> unit task
method destroy : unit -> unit
diff --git a/ide/coqide/coqide.ml b/ide/coqide/coqide.ml
index b66da11e7b..f9e6e74372 100644
--- a/ide/coqide/coqide.ml
+++ b/ide/coqide/coqide.ml
@@ -747,6 +747,24 @@ let coq_icon () =
let dir = List.find chk (Minilib.coqide_data_dirs ()) in
Filename.concat dir name
+let show_proof_diff where sn =
+ sn.messages#default_route#clear;
+ Coq.try_grab sn.coqtop (sn.coqops#proof_diff where
+ ~next:(function
+ | Interface.Fail (_, _, err) ->
+ let err = if (Pp.string_of_ppcmds err) <> "No proofs to diff." then err else
+ Pp.str "Put the cursor over proven lines for \"Show Proof\" diffs"
+ in
+ let err = Ideutils.validate err in
+ sn.messages#default_route#add err;
+ Coq.return ()
+ | Interface.Good diff ->
+ sn.messages#default_route#add diff;
+ Coq.return ()))
+ ignore
+
+let show_proof_diffs _ = cb_on_current_term (show_proof_diff `INSERT) ()
+
let about _ =
let dialog = GWindow.about_dialog () in
let _ = dialog#connect#response ~callback:(fun _ -> dialog#destroy ()) in
@@ -1103,6 +1121,8 @@ let build_ui () =
radio "Set diff" 1 ~label:"Show diffs: only _added";
radio "Set removed diff" 2 ~label:"Show diffs: added and _removed";
];
+ item "Show Proof Diffs" ~label:"_Show Proof (with diffs, if set)" ~accel:(modifier_for_display#get ^ "S")
+ ~callback:MiscMenu.show_proof_diffs;
];
toggle_items view_menu Coq.PrintOpt.bool_items;
@@ -1352,6 +1372,11 @@ let main files =
this default coqtop path *)
let read_coqide_args argv =
+ let set_debug () =
+ Minilib.debug := true;
+ Flags.debug := true;
+ Exninfo.record_backtrace true
+ in
let rec filter_coqtop coqtop project_files bindings_files out = function
|"-unicode-bindings" :: sfilenames :: args ->
let filenames = Str.split (Str.regexp ",") sfilenames in
@@ -1371,10 +1396,12 @@ let read_coqide_args argv =
|"-coqtop" :: [] ->
output_string stderr "Error: missing argument after -coqtop"; exit 1
|"-debug"::args ->
- Minilib.debug := true;
- Flags.debug := true;
- Exninfo.record_backtrace true;
+ set_debug ();
filter_coqtop coqtop project_files bindings_files ("-debug"::out) args
+ |"-xml-debug"::args ->
+ set_debug ();
+ Flags.xml_debug := true;
+ filter_coqtop coqtop project_files bindings_files ("-xml-debug"::out) args
|"-coqtop-flags" :: flags :: args->
Coq.ideslave_coqtop_flags := Some flags;
filter_coqtop coqtop project_files bindings_files out args
diff --git a/ide/coqide/coqide_ui.ml b/ide/coqide/coqide_ui.ml
index e9ff1bbba1..badfabf07e 100644
--- a/ide/coqide/coqide_ui.ml
+++ b/ide/coqide/coqide_ui.ml
@@ -85,10 +85,12 @@ let init () =
\n <menuitem action='Display universe levels' />\
\n <menuitem action='Display all low-level contents' />\
\n <menuitem action='Display unfocused goals' />\
+\n <menuitem action='Display goal names' />\
\n <separator/>\
\n <menuitem action='Unset diff' />\
\n <menuitem action='Set diff' />\
\n <menuitem action='Set removed diff' />\
+\n <menuitem action='Show Proof Diffs' />\
\n </menu>\
\n <menu action='Navigation'>\
\n <menuitem action='Forward' />\
diff --git a/ide/coqide/fake_ide.ml b/ide/coqide/fake_ide.ml
index e1736a5fe0..034f5b4e2a 100644
--- a/ide/coqide/fake_ide.ml
+++ b/ide/coqide/fake_ide.ml
@@ -136,7 +136,7 @@ module Parser = struct (* {{{ *)
match g with
| Item (s,_) -> Printf.sprintf "%s" (clean s)
| Opt g -> Printf.sprintf "[%s]" (print g)
- | Alt gs -> Printf.sprintf "( %s )" (String.concat " | " (List.map print gs))
+ | Alt gs -> Printf.sprintf "( %s )" (String.concat "\n| " (List.map print gs))
| Seq gs -> String.concat " " (List.map print gs)
let rec print_toklist = function
@@ -253,6 +253,9 @@ let eval_print l coq =
after_edit_at (to_id, need_unfocus) (base_eval_call (edit_at to_id) coq)
| [ Tok(_,"QUERY"); Top []; Tok(_,phrase) ] ->
eval_call (query (0,(phrase,tip_id()))) coq
+ | [ Tok(_,"PDIFF"); Tok(_,id) ] ->
+ let to_id, _ = get_id id in
+ eval_call (proof_diff ("on",to_id)) coq
| [ Tok(_,"QUERY"); Top [Tok(_,id)]; Tok(_,phrase) ] ->
let to_id, _ = get_id id in
eval_call (query (0,(phrase, to_id))) coq
@@ -282,6 +285,7 @@ let grammar =
; Seq [Item (eat_rex "FAILADD"); Item eat_phrase]
; Seq [Item (eat_rex "EDIT_AT"); Item eat_id]
; Seq [Item (eat_rex "QUERY"); Opt (Item eat_id); Item eat_phrase]
+ ; Seq [Item (eat_rex "PDIFF"); Item eat_id ]
; Seq [Item (eat_rex "WAIT")]
; Seq [Item (eat_rex "JOIN")]
; Seq [Item (eat_rex "GOALS")]
@@ -295,12 +299,11 @@ let grammar =
let read_command inc = Parser.parse grammar inc
let usage () =
- error (Printf.sprintf
- "A fake coqide process talking to a coqtop -toploop coqidetop.\n\
- Usage: %s (file|-) [<coqtop>]\n\
- Input syntax is the following:\n%s\n"
- (Filename.basename Sys.argv.(0))
- (Parser.print grammar))
+ prerr_endline (Printf.sprintf "Usage: %s ( file | - ) [ \"<coqtop arguments>\" ]\n\
+ Input syntax is:\n%s\n"
+ (Filename.basename Sys.argv.(0))
+ (Parser.print grammar));
+ exit 1
module Coqide = Spawn.Sync ()
@@ -308,14 +311,15 @@ let main =
if Sys.os_type = "Unix" then Sys.set_signal Sys.sigpipe
(Sys.Signal_handle
(fun _ -> prerr_endline "Broken Pipe (coqtop died ?)"; exit 1));
- let def_args = ["--xml_format=Ppcmds"] in
let idetop_name = System.get_toplevel_path "coqidetop" in
- let coqtop_args, input_file = match Sys.argv with
- | [| _; f |] -> Array.of_list def_args, f
- | [| _; f; ct |] ->
- let ct = Str.split (Str.regexp " ") ct in
- Array.of_list (def_args @ ct), f
+ let input_file, args = match Sys.argv with
+ | [| _; f |] -> f, []
+ | [| _; f; args |] ->
+ let args = Str.split (Str.regexp " ") args in
+ f, args
| _ -> usage () in
+ let def_coqtop_args = ["--xml_format=Ppcmds"] in
+ let coqtop_args = Array.of_list(def_coqtop_args @ args) in
let inc = if input_file = "-" then stdin else open_in input_file in
prerr_endline ("Running: "^idetop_name^" "^
(String.concat " " (Array.to_list coqtop_args)));
diff --git a/ide/coqide/idetop.ml b/ide/coqide/idetop.ml
index ad21f663e4..602acefa7c 100644
--- a/ide/coqide/idetop.ml
+++ b/ide/coqide/idetop.ml
@@ -195,7 +195,7 @@ let concl_next_tac =
let process_goal sigma g =
let env = Goal.V82.env sigma g in
let min_env = Environ.reset_context env in
- let id = Goal.uid g in
+ let id = if Printer.print_goal_names () then Names.Id.to_string (Termops.evar_suggested_name g sigma) else "" in
let ccl =
pr_letype_env ~goal_concl_style:true env sigma (Goal.V82.concl sigma g)
in
@@ -206,7 +206,7 @@ let process_goal sigma g =
let (_env, hyps) =
Context.Compacted.fold process_hyp
(Termops.compact_named_context (Environ.named_context env)) ~init:(min_env,[]) in
- { Interface.goal_hyp = List.rev hyps; Interface.goal_ccl = ccl; Interface.goal_id = id; }
+ { Interface.goal_hyp = List.rev hyps; Interface.goal_ccl = ccl; Interface.goal_id = id }
let process_goal_diffs diff_goal_map oldp nsigma ng =
let open Evd in
@@ -317,7 +317,7 @@ let pattern_of_string ?env s =
| None -> Global.env ()
| Some e -> e
in
- let constr = Pcoq.parse_string Pcoq.Constr.lconstr_pattern s in
+ let constr = Pcoq.parse_string Pcoq.Constr.cpattern s in
let (_, pat) = Constrintern.intern_constr_pattern env (Evd.from_env env) constr in
pat
@@ -367,6 +367,17 @@ let export_option_state s = {
Interface.opt_value = export_option_value s.Goptions.opt_value;
}
+exception NotSupported of string
+
+let proof_diff (diff_opt, sid) =
+ let diff_opt = Proof_diffs.string_to_diffs diff_opt in
+ let doc = get_doc () in
+ match Stm.get_proof ~doc sid with
+ | None -> CErrors.user_err (Pp.str "No proofs to diff.")
+ | Some proof ->
+ let old = Stm.get_prev_proof ~doc sid in
+ Proof_diffs.diff_proofs ~diff_opt ?old proof
+
let get_options () =
let table = Goptions.get_tables () in
let fold key state accu = (key, export_option_state state) :: accu in
@@ -455,6 +466,7 @@ let eval_call c =
Interface.hints = interruptible hints;
Interface.status = interruptible status;
Interface.search = interruptible search;
+ Interface.proof_diff = interruptible proof_diff;
Interface.get_options = interruptible get_options;
Interface.set_options = interruptible set_options;
Interface.mkcases = interruptible idetop_make_cases;
@@ -479,6 +491,8 @@ let print_xml =
let m = Mutex.create () in
fun oc xml ->
Mutex.lock m;
+ if !Flags.xml_debug then
+ Printf.printf "SENT --> %s\n%!" (Xml_printer.to_string_fmt xml);
try Control.protect_sigalrm (Xml_printer.print oc) xml; Mutex.unlock m
with e -> let e = Exninfo.capture e in Mutex.unlock m; Exninfo.iraise e
@@ -507,7 +521,7 @@ let loop run_mode ~opts:_ state =
set_doc state.doc;
init_signal_handler ();
catch_break := false;
- let in_ch, out_ch = Spawned.get_channels () in
+ let in_ch, out_ch = Spawned.get_channels () in
let xml_oc = Xml_printer.make (Xml_printer.TChannel out_ch) in
let in_lb = Lexing.from_function (fun s len ->
CThread.thread_friendly_read in_ch s ~off:0 ~len) in
@@ -518,7 +532,8 @@ let loop run_mode ~opts:_ state =
while not !quit do
try
let xml_query = Xml_parser.parse xml_ic in
-(* pr_with_pid (Xml_printer.to_string_fmt xml_query); *)
+ if !Flags.xml_debug then
+ pr_with_pid (Xml_printer.to_string_fmt xml_query);
let Xmlprotocol.Unknown q = Xmlprotocol.to_call xml_query in
let () = pr_debug_call q in
let r = eval_call q in
diff --git a/ide/coqide/protocol/interface.ml b/ide/coqide/protocol/interface.ml
index 646012dcaa..86a81446e8 100644
--- a/ide/coqide/protocol/interface.ml
+++ b/ide/coqide/protocol/interface.ml
@@ -187,6 +187,10 @@ type status_rty = status
type search_sty = search_flags
type search_rty = string coq_object list
+(** Diffs between the proof term at a given stateid and the previous one *)
+type proof_diff_sty = string * Stateid.t
+type proof_diff_rty = Pp.t
+
(** Retrieve the list of options of the current toplevel *)
type get_options_sty = unit
type get_options_rty = (option_name * option_state) list
@@ -252,6 +256,7 @@ type handler = {
stop_worker : stop_worker_sty -> stop_worker_rty;
print_ast : print_ast_sty -> print_ast_rty;
annotate : annotate_sty -> annotate_rty;
+ proof_diff : proof_diff_sty -> proof_diff_rty;
handle_exn : handle_exn_sty -> handle_exn_rty;
init : init_sty -> init_rty;
quit : quit_sty -> quit_rty;
diff --git a/ide/coqide/protocol/serialize.ml b/ide/coqide/protocol/serialize.ml
index bdbec5b30f..6a0a3d7f5d 100644
--- a/ide/coqide/protocol/serialize.ml
+++ b/ide/coqide/protocol/serialize.ml
@@ -35,6 +35,11 @@ let singleton = function
| l -> raise (Marshal_error
("singleton",PCData ("list of length " ^ string_of_int (List.length l))))
+let empty = function
+ | [] -> ()
+ | l -> raise (Marshal_error
+ ("empty",PCData ("list of length " ^ string_of_int (List.length l))))
+
let raw_string = function
| [] -> ""
| [PCData s] -> s
diff --git a/ide/coqide/protocol/serialize.mli b/ide/coqide/protocol/serialize.mli
index 5d88defe55..9d09b81d1e 100644
--- a/ide/coqide/protocol/serialize.mli
+++ b/ide/coqide/protocol/serialize.mli
@@ -16,6 +16,7 @@ val massoc: string -> (string * string) list -> string
val constructor: string -> string -> xml list -> xml
val do_match: string -> (string -> xml list -> 'b) -> xml -> 'b
val singleton: 'a list -> 'a
+val empty: 'a list -> unit
val raw_string: xml list -> string
val of_unit: unit -> xml
val to_unit: xml -> unit
diff --git a/ide/coqide/protocol/xmlprotocol.ml b/ide/coqide/protocol/xmlprotocol.ml
index 6cb0cec008..6a33ff8abc 100644
--- a/ide/coqide/protocol/xmlprotocol.ml
+++ b/ide/coqide/protocol/xmlprotocol.ml
@@ -12,7 +12,7 @@
(** WARNING: TO BE UPDATED WHEN MODIFIED! *)
-let protocol_version = "20170413"
+let protocol_version = "20200911"
type msg_format = Richpp of int | Ppcmds
let msg_format = ref (Richpp 72)
@@ -43,7 +43,7 @@ let to_search_cst = do_match "search_cst" (fun s args -> match s with
| "type_pattern" -> Type_Pattern (to_string (singleton args))
| "subtype_pattern" -> SubType_Pattern (to_string (singleton args))
| "in_module" -> In_Module (to_list to_string (singleton args))
- | "include_blacklist" -> Include_Blacklist
+ | "include_blacklist" -> empty args; Include_Blacklist
| x -> raise (Marshal_error("search",PCData x)))
let of_coq_object f ans =
@@ -103,14 +103,14 @@ let to_routeid = function
let of_routeid i = Element ("route_id",["val",string_of_int i],[])
let of_box (ppb : Pp.block_type) = let open Pp in match ppb with
- | Pp_hbox i -> constructor "ppbox" "hbox" [of_int i]
+ | Pp_hbox -> constructor "ppbox" "hbox" []
| Pp_vbox i -> constructor "ppbox" "vbox" [of_int i]
| Pp_hvbox i -> constructor "ppbox" "hvbox" [of_int i]
| Pp_hovbox i -> constructor "ppbox" "hovbox" [of_int i]
let to_box = let open Pp in
do_match "ppbox" (fun s args -> match s with
- | "hbox" -> Pp_hbox (to_int (singleton args))
+ | "hbox" -> empty args; Pp_hbox
| "vbox" -> Pp_vbox (to_int (singleton args))
| "hvbox" -> Pp_hvbox (to_int (singleton args))
| "hovbox" -> Pp_hovbox (to_int (singleton args))
@@ -132,7 +132,7 @@ let rec of_pp (pp : Pp.t) = let open Pp in match Pp.repr pp with
let rec to_pp xpp = let open Pp in
Pp.unrepr @@
do_match "ppdoc" (fun s args -> match s with
- | "empty" -> Ppcmd_empty
+ | "empty" -> empty args; Ppcmd_empty
| "string" -> Ppcmd_string (to_string (singleton args))
| "glue" -> Ppcmd_glue (to_list to_pp (singleton args))
| "box" -> let (bt,s) = to_pair to_box to_pp (singleton args) in
@@ -278,6 +278,7 @@ module ReifType : sig
val state_id_t : state_id val_t
val route_id_t : route_id val_t
val search_cst_t : search_constraint val_t
+ val pp_t : Pp.t val_t
val of_value_type : 'a val_t -> 'a -> xml
val to_value_type : 'a val_t -> xml -> 'a
@@ -314,6 +315,7 @@ end = struct
| State_id : state_id val_t
| Route_id : route_id val_t
| Search_cst : search_constraint val_t
+ | Pp : Pp.t val_t
type value_type = Value_type : 'a val_t -> value_type
@@ -340,6 +342,7 @@ end = struct
let state_id_t = State_id
let route_id_t = Route_id
let search_cst_t = Search_cst
+ let pp_t = Pp
let of_value_type (ty : 'a val_t) : 'a -> xml =
let rec convert : type a. a val_t -> a -> xml = function
@@ -362,6 +365,7 @@ end = struct
| State_id -> of_stateid
| Route_id -> of_routeid
| Search_cst -> of_search_cst
+ | Pp -> of_pp
in
convert ty
@@ -386,6 +390,7 @@ end = struct
| State_id -> to_stateid
| Route_id -> to_routeid
| Search_cst -> to_search_cst
+ | Pp -> to_pp
in
convert ty
@@ -443,6 +448,8 @@ end = struct
| In_Module s -> "In_Module " ^ String.concat "." s
| Include_Blacklist -> "Include_Blacklist"
+ let pr_pp = Pp.string_of_ppcmds
+
let rec print : type a. a val_t -> a -> string = function
| Unit -> pr_unit
| Bool -> pr_bool
@@ -463,6 +470,7 @@ end = struct
| Union (t1,t2) -> (pr_union (print t1) (print t2))
| State_id -> pr_state_id
| Route_id -> pr_int
+ | Pp -> pr_pp
(* This is to break if a rename/refactoring makes the strings below outdated *)
type 'a exists = bool
@@ -489,6 +497,7 @@ end = struct
Printf.sprintf "((%s, %s) CSig.union)" (print_val_t t1) (print_val_t t2)
| State_id -> assert(true : Stateid.t exists); "Stateid.t"
| Route_id -> assert(true : route_id exists); "route_id"
+ | Pp -> assert(true : Pp.t exists); "Pp.t"
let print_type = function Value_type ty -> print_val_t ty
@@ -507,6 +516,8 @@ end = struct
(pr_xml (of_pair of_bool of_int (false,3)));
Printf.printf "%s:\n\n%s\n\n" (print_val_t (Union (Bool,Int)))
(pr_xml (of_union of_bool of_int (Inl false)));
+ Printf.printf "%s:\n\n%s\n\n" (print_val_t Pp)
+ (pr_xml (of_pp Pp.(hv 3 (str "foo" ++ spc () ++ str "bar") )));
print_endline ("All other types are records represented by a node named like the OCaml\n"^
"type which contains a flattened n-tuple. We provide one example.\n");
Printf.printf "%s:\n\n%s\n\n" (print_val_t Option_state)
@@ -538,6 +549,7 @@ let interp_sty_t : interp_sty val_t = pair_t (pair_t bool_t bool_t) string_t
let stop_worker_sty_t : stop_worker_sty val_t = string_t
let print_ast_sty_t : print_ast_sty val_t = state_id_t
let annotate_sty_t : annotate_sty val_t = string_t
+let proof_diff_sty_t : proof_diff_sty val_t = pair_t string_t state_id_t
let add_rty_t : add_rty val_t =
pair_t state_id_t (pair_t (union_t unit_t state_id_t) string_t)
@@ -563,6 +575,7 @@ let interp_rty_t : interp_rty val_t = pair_t state_id_t (union_t string_t string
let stop_worker_rty_t : stop_worker_rty val_t = unit_t
let print_ast_rty_t : print_ast_rty val_t = xml_t
let annotate_rty_t : annotate_rty val_t = xml_t
+let proof_diff_rty_t : proof_diff_rty val_t = pp_t
let ($) x = erase x
let calls = [|
@@ -585,6 +598,7 @@ let calls = [|
"StopWorker", ($)stop_worker_sty_t, ($)stop_worker_rty_t;
"PrintAst", ($)print_ast_sty_t, ($)print_ast_rty_t;
"Annotate", ($)annotate_sty_t, ($)annotate_rty_t;
+ "PDiff", ($)proof_diff_sty_t, ($)proof_diff_rty_t;
|]
type 'a call =
@@ -609,7 +623,9 @@ type 'a call =
| Interp : interp_sty -> interp_rty call
| PrintAst : print_ast_sty -> print_ast_rty call
| Annotate : annotate_sty -> annotate_rty call
+ | PDiff : proof_diff_sty -> proof_diff_rty call
+(* the order of the entries must match the order in "calls" above *)
let id_of_call : type a. a call -> int = function
| Add _ -> 0
| Edit_at _ -> 1
@@ -630,6 +646,7 @@ let id_of_call : type a. a call -> int = function
| StopWorker _ -> 16
| PrintAst _ -> 17
| Annotate _ -> 18
+ | PDiff _ -> 19
let str_of_call c = pi1 calls.(id_of_call c)
@@ -652,8 +669,9 @@ let init x : init_rty call = Init x
let wait x : wait_rty call = Wait x
let interp x : interp_rty call = Interp x
let stop_worker x : stop_worker_rty call = StopWorker x
-let print_ast x : print_ast_rty call = PrintAst x
-let annotate x : annotate_rty call = Annotate x
+let print_ast x : print_ast_rty call = PrintAst x
+let annotate x : annotate_rty call = Annotate x
+let proof_diff x : proof_diff_rty call = PDiff x
let abstract_eval_call : type a. _ -> a call -> a value = fun handler c ->
let mkGood : type a. a -> a value = fun x -> Good x in
@@ -678,6 +696,7 @@ let abstract_eval_call : type a. _ -> a call -> a value = fun handler c ->
| StopWorker x -> mkGood (handler.stop_worker x)
| PrintAst x -> mkGood (handler.print_ast x)
| Annotate x -> mkGood (handler.annotate x)
+ | PDiff x -> mkGood (handler.proof_diff x)
with any ->
let any = Exninfo.capture any in
Fail (handler.handle_exn any)
@@ -703,6 +722,7 @@ let of_answer : type a. a call -> a value -> xml = function
| StopWorker _ -> of_value (of_value_type stop_worker_rty_t)
| PrintAst _ -> of_value (of_value_type print_ast_rty_t )
| Annotate _ -> of_value (of_value_type annotate_rty_t )
+ | PDiff _ -> of_value (of_value_type proof_diff_rty_t )
let of_answer msg_fmt =
msg_format := msg_fmt; of_answer
@@ -727,6 +747,7 @@ let to_answer : type a. a call -> xml -> a value = function
| StopWorker _ -> to_value (to_value_type stop_worker_rty_t)
| PrintAst _ -> to_value (to_value_type print_ast_rty_t )
| Annotate _ -> to_value (to_value_type annotate_rty_t )
+ | PDiff _ -> to_value (to_value_type proof_diff_rty_t )
let of_call : type a. a call -> xml = fun q ->
let mkCall x = constructor "call" (str_of_call q) [x] in
@@ -750,6 +771,7 @@ let of_call : type a. a call -> xml = fun q ->
| StopWorker x -> mkCall (of_value_type stop_worker_sty_t x)
| PrintAst x -> mkCall (of_value_type print_ast_sty_t x)
| Annotate x -> mkCall (of_value_type annotate_sty_t x)
+ | PDiff x -> mkCall (of_value_type proof_diff_sty_t x)
let to_call : xml -> unknown_call =
do_match "call" (fun s a ->
@@ -774,6 +796,7 @@ let to_call : xml -> unknown_call =
| "StopWorker" -> Unknown (StopWorker (mkCallArg stop_worker_sty_t a))
| "PrintAst" -> Unknown (PrintAst (mkCallArg print_ast_sty_t a))
| "Annotate" -> Unknown (Annotate (mkCallArg annotate_sty_t a))
+ | "PDiff" -> Unknown (PDiff (mkCallArg proof_diff_sty_t a))
| x -> raise (Marshal_error("call",PCData x)))
(** Debug printing *)
@@ -805,6 +828,7 @@ let pr_full_value : type a. a call -> a value -> string = fun call value -> matc
| StopWorker _ -> pr_value_gen (print stop_worker_rty_t) value
| PrintAst _ -> pr_value_gen (print print_ast_rty_t ) value
| Annotate _ -> pr_value_gen (print annotate_rty_t ) value
+ | PDiff _ -> pr_value_gen (print proof_diff_rty_t ) value
let pr_call : type a. a call -> string = fun call ->
let return what x = str_of_call call ^ " " ^ print what x in
match call with
@@ -827,6 +851,7 @@ let pr_call : type a. a call -> string = fun call ->
| StopWorker x -> return stop_worker_sty_t x
| PrintAst x -> return print_ast_sty_t x
| Annotate x -> return annotate_sty_t x
+ | PDiff x -> return proof_diff_sty_t x
let document to_string_fmt =
Printf.printf "=== Available calls ===\n\n";
@@ -858,11 +883,11 @@ let of_message_level = function
| Error -> Serialize.constructor "message_level" "error" []
let to_message_level =
Serialize.do_match "message_level" (fun s args -> match s with
- | "debug" -> Debug
- | "info" -> Info
- | "notice" -> Notice
- | "warning" -> Warning
- | "error" -> Error
+ | "debug" -> empty args; Debug
+ | "info" -> empty args; Info
+ | "notice" -> empty args; Notice
+ | "warning" -> empty args; Warning
+ | "error" -> empty args; Error
| x -> raise Serialize.(Marshal_error("error level",PCData x)))
let of_message lvl loc msg =
diff --git a/ide/coqide/protocol/xmlprotocol.mli b/ide/coqide/protocol/xmlprotocol.mli
index 44584d44d7..4dc05c18a9 100644
--- a/ide/coqide/protocol/xmlprotocol.mli
+++ b/ide/coqide/protocol/xmlprotocol.mli
@@ -37,6 +37,7 @@ val wait : wait_sty -> wait_rty call
val interp : interp_sty -> interp_rty call
val print_ast : print_ast_sty -> print_ast_rty call
val annotate : annotate_sty -> annotate_rty call
+val proof_diff : proof_diff_sty -> proof_diff_rty call
val abstract_eval_call : handler -> 'a call -> 'a value
diff --git a/ide/coqide/wg_ProofView.ml b/ide/coqide/wg_ProofView.ml
index 1de63953af..8e451c9917 100644
--- a/ide/coqide/wg_ProofView.ml
+++ b/ide/coqide/wg_ProofView.ml
@@ -52,7 +52,7 @@ let hook_tag_cb tag menu_content sel_cb hover_cb =
let mode_tactic sel_cb (proof : #GText.view_skel) goals ~unfoc_goals hints = match goals with
| [] -> assert false
- | { Interface.goal_hyp = hyps; Interface.goal_ccl = cur_goal; } :: rem_goals ->
+ | { Interface.goal_hyp = hyps; Interface.goal_ccl = cur_goal; Interface.goal_id = cur_id } :: rem_goals ->
let on_hover sel_start sel_stop =
proof#buffer#remove_tag
~start:proof#buffer#start_iter
@@ -68,11 +68,11 @@ let mode_tactic sel_cb (proof : #GText.view_skel) goals ~unfoc_goals hints = mat
let head_str = Printf.sprintf
"%d subgoal%s\n" goals_cnt (if 1 < goals_cnt then "s" else "")
in
- let goal_str ?(shownum=false) index total =
- if shownum then Printf.sprintf
- "______________________________________(%d/%d)\n" index total
- else Printf.sprintf
- "______________________________________\n"
+ let goal_str ?(shownum=false) index total id =
+ let annot =
+ if CString.is_empty id then if shownum then Printf.sprintf "(%d/%d)" index total else ""
+ else Printf.sprintf "(?%s)" id in
+ Printf.sprintf "______________________________________%s\n" annot
in
(* Insert current goal and its hypotheses *)
let hyps_hints, goal_hints = match hints with
@@ -103,13 +103,13 @@ let mode_tactic sel_cb (proof : #GText.view_skel) goals ~unfoc_goals hints = mat
[tag]
else []
in
- proof#buffer#insert (goal_str ~shownum:true 1 goals_cnt);
+ proof#buffer#insert (goal_str ~shownum:true 1 goals_cnt cur_id);
insert_xml ~tags:[Tags.Proof.goal] proof#buffer (Richpp.richpp_of_pp width cur_goal);
proof#buffer#insert "\n"
in
(* Insert remaining goals (no hypotheses) *)
- let fold_goal ?(shownum=false) i _ { Interface.goal_ccl = g } =
- proof#buffer#insert (goal_str ~shownum i goals_cnt);
+ let fold_goal ?(shownum=false) i _ { Interface.goal_ccl = g; Interface.goal_id = id } =
+ proof#buffer#insert (goal_str ~shownum i goals_cnt id);
insert_xml proof#buffer (Richpp.richpp_of_pp width g);
proof#buffer#insert "\n"
in
@@ -178,12 +178,16 @@ let display mode (view : #GText.view_skel) goals hints evars =
| _, _, _, _ ->
(* No foreground proofs, but still unfocused ones *)
let total = List.length bg in
- let goal_str index = Printf.sprintf
- "______________________________________(%d/%d)\n" index total
+ let goal_str index id =
+ let annot =
+ if CString.is_empty id then Printf.sprintf "(%d/%d)" index total
+ else Printf.sprintf "(?%s)" id in
+ Printf.sprintf
+ "______________________________________%s\n" annot
in
view#buffer#insert "This subproof is complete, but there are some unfocused goals:\n\n";
let iter i goal =
- let () = view#buffer#insert (goal_str (succ i)) in
+ let () = view#buffer#insert (goal_str (succ i) goal.Interface.goal_id) in
insert_xml view#buffer (Richpp.richpp_of_pp width goal.Interface.goal_ccl);
view#buffer#insert "\n"
in
diff --git a/interp/constrexpr.ml b/interp/constrexpr.ml
index c98e05370e..235310660b 100644
--- a/interp/constrexpr.ml
+++ b/interp/constrexpr.ml
@@ -58,7 +58,7 @@ type abstraction_kind = AbsLambda | AbsPi
type proj_flag = int option (** [Some n] = proj of the n-th visible argument *)
type prim_token =
- | Numeral of NumTok.Signed.t
+ | Number of NumTok.Signed.t
| String of string
type instance_expr = Glob_term.glob_level list
@@ -108,7 +108,7 @@ and constr_expr_r =
* constr_expr * constr_expr
| CHole of Evar_kinds.t option * Namegen.intro_pattern_naming_expr * Genarg.raw_generic_argument option
| CPatVar of Pattern.patvar
- | CEvar of Glob_term.existential_name * (Id.t * constr_expr) list
+ | CEvar of Glob_term.existential_name CAst.t * (lident * constr_expr) list
| CSort of Glob_term.glob_sort
| CCast of constr_expr * constr_expr Glob_term.cast_type
| CNotation of notation_with_optional_scope option * notation * constr_notation_substitution
diff --git a/interp/constrexpr_ops.ml b/interp/constrexpr_ops.ml
index ce8e7d3c2c..8cc63c5d03 100644
--- a/interp/constrexpr_ops.ml
+++ b/interp/constrexpr_ops.ml
@@ -44,13 +44,13 @@ let names_of_local_binders bl =
(**********************************************************************)
(* Functions on constr_expr *)
-(* Note: redundant Numeral representations, such as -0 and +0 (and others),
+(* Note: redundant Number representations, such as -0 and +0 (and others),
are considered different here. *)
let prim_token_eq t1 t2 = match t1, t2 with
-| Numeral n1, Numeral n2 -> NumTok.Signed.equal n1 n2
+| Number n1, Number n2 -> NumTok.Signed.equal n1 n2
| String s1, String s2 -> String.equal s1 s2
-| (Numeral _ | String _), _ -> false
+| (Number _ | String _), _ -> false
let explicitation_eq ex1 ex2 = match ex1, ex2 with
| ExplByPos (i1, id1), ExplByPos (i2, id2) ->
@@ -156,7 +156,7 @@ let rec constr_expr_eq e1 e2 =
| CPatVar i1, CPatVar i2 ->
Id.equal i1 i2
| CEvar (id1, c1), CEvar (id2, c2) ->
- Id.equal id1 id2 && List.equal instance_eq c1 c2
+ Id.equal id1.CAst.v id2.CAst.v && List.equal instance_eq c1 c2
| CSort s1, CSort s2 ->
Glob_ops.glob_sort_eq s1 s2
| CCast(t1,c1), CCast(t2,c2) ->
@@ -235,7 +235,7 @@ and constr_notation_substitution_eq (e1, el1, b1, bl1) (e2, el2, b2, bl2) =
List.equal (List.equal local_binder_eq) bl1 bl2
and instance_eq (x1,c1) (x2,c2) =
- Id.equal x1 x2 && constr_expr_eq c1 c2
+ Id.equal x1.CAst.v x2.CAst.v && constr_expr_eq c1 c2
and cast_expr_eq c1 c2 = match c1, c2 with
| CastConv t1, CastConv t2
diff --git a/interp/constrextern.ml b/interp/constrextern.ml
index 43fef8685d..d1bec16a3f 100644
--- a/interp/constrextern.ml
+++ b/interp/constrextern.ml
@@ -357,18 +357,18 @@ let destPatPrim = function { CAst.v = CPatPrim t } -> Some t | _ -> None
let make_notation_gen loc ntn mknot mkprim destprim l bl =
match snd ntn,List.map destprim l with
(* Special case to avoid writing "- 3" for e.g. (Z.opp 3) *)
- | "- _", [Some (Numeral p)] when not (NumTok.Signed.is_zero p) ->
+ | "- _", [Some (Number p)] when not (NumTok.Signed.is_zero p) ->
assert (bl=[]);
mknot (loc,ntn,([mknot (loc,(InConstrEntry,"( _ )"),l,[])]),[])
| _ ->
match decompose_notation_key ntn, l with
| (InConstrEntry,[Terminal "-"; Terminal x]), [] ->
begin match NumTok.Unsigned.parse_string x with
- | Some n -> mkprim (loc, Numeral (NumTok.SMinus,n))
+ | Some n -> mkprim (loc, Number (NumTok.SMinus,n))
| None -> mknot (loc,ntn,l,bl) end
| (InConstrEntry,[Terminal x]), [] ->
begin match NumTok.Unsigned.parse_string x with
- | Some n -> mkprim (loc, Numeral (NumTok.SPlus,n))
+ | Some n -> mkprim (loc, Number (NumTok.SPlus,n))
| None -> mknot (loc,ntn,l,bl) end
| _ -> mknot (loc,ntn,l,bl)
@@ -551,7 +551,7 @@ and extern_notation_pattern allscopes vars t = function
| [] -> raise No_match
| (keyrule,pat,n as _rule)::rules ->
try
- if is_inactive_rule keyrule then raise No_match;
+ if is_inactive_rule keyrule || is_printing_inactive_rule keyrule pat then raise No_match;
let loc = t.loc in
match DAst.get t with
| PatCstr (cstr,args,na) ->
@@ -568,7 +568,7 @@ let rec extern_notation_ind_pattern allscopes vars ind args = function
| [] -> raise No_match
| (keyrule,pat,n as _rule)::rules ->
try
- if is_inactive_rule keyrule then raise No_match;
+ if is_inactive_rule keyrule || is_printing_inactive_rule keyrule pat then raise No_match;
apply_notation_to_pattern (GlobRef.IndRef ind)
(match_notation_constr_ind_pattern ind args pat) allscopes vars keyrule
with
@@ -915,7 +915,7 @@ let extern_float f scopes =
let hex = !Flags.raw_print || not (get_printing_float ()) in
if hex then Float64.to_hex_string f else Float64.to_string f in
let n = NumTok.Signed.of_string s in
- extern_prim_token_delimiter_if_required (Numeral n)
+ extern_prim_token_delimiter_if_required (Number n)
"float" "float_scope" scopes
(**********************************************************************)
@@ -978,7 +978,7 @@ let rec extern inctx ?impargs scopes vars r =
if !print_meta_as_hole then CHole (None, IntroAnonymous, None) else
(match kind with
| Evar_kinds.SecondOrderPatVar n -> CPatVar n
- | Evar_kinds.FirstOrderPatVar n -> CEvar (n,[]))
+ | Evar_kinds.FirstOrderPatVar n -> CEvar (CAst.make n,[]))
| GApp (f,args) ->
(match DAst.get f with
@@ -1097,13 +1097,13 @@ let rec extern inctx ?impargs scopes vars r =
| GInt i ->
extern_prim_token_delimiter_if_required
- (Numeral (NumTok.Signed.of_int_string (Uint63.to_string i)))
+ (Number (NumTok.Signed.of_int_string (Uint63.to_string i)))
"int63" "int63_scope" (snd scopes)
| GFloat f -> extern_float f (snd scopes)
| GArray(u,t,def,ty) ->
- CArray(u,Array.map (extern inctx scopes vars) t, extern inctx scopes vars def, extern_typ scopes vars ty)
+ CArray(extern_universes u,Array.map (extern inctx scopes vars) t, extern inctx scopes vars def, extern_typ scopes vars ty)
in insert_entry_coercion coercion (CAst.make ?loc c)
@@ -1238,7 +1238,7 @@ and extern_notation inctx (custom,scopes as allscopes) vars t rules =
| (keyrule,pat,n as _rule)::rules ->
let loc = Glob_ops.loc_of_glob_constr t in
try
- if is_inactive_rule keyrule then raise No_match;
+ if is_inactive_rule keyrule || is_printing_inactive_rule keyrule pat then raise No_match;
let f,args =
match DAst.get t with
| GApp (f,args) -> f,args
@@ -1391,7 +1391,7 @@ let rec glob_of_pat avoid env sigma pat = DAst.make @@ match pat with
| None -> Id.of_string "__"
| Some id -> id
in
- GEvar (id,List.map (on_snd (glob_of_pat avoid env sigma)) l)
+ GEvar (CAst.make id,List.map (fun (id,c) -> (CAst.make id, glob_of_pat avoid env sigma c)) l)
| PRel n ->
let id = try match lookup_name_of_rel n env with
| Name id -> id
diff --git a/interp/constrintern.ml b/interp/constrintern.ml
index 48fb4a4a5d..ecf2b951a2 100644
--- a/interp/constrintern.ml
+++ b/interp/constrintern.ml
@@ -263,6 +263,13 @@ type intern_env = {
binder_block_names: (abstraction_kind option (* None = unknown *) * Id.Set.t) option;
}
+type pattern_intern_env = {
+ pat_scopes: Notation_term.subscopes;
+ (* ids = Some means accept local variables; this is useful for
+ terms as patterns parsed as pattersn in notations *)
+ pat_ids: Id.Set.t option;
+}
+
(**********************************************************************)
(* Remembering the parsing scope of variables in notations *)
@@ -317,6 +324,9 @@ let reset_tmp_scope env = {env with tmp_scope = None}
let set_env_scopes env (scopt,subscopes) =
{env with tmp_scope = scopt; scopes = subscopes @ env.scopes}
+let env_for_pattern env =
+ {pat_scopes = (env.tmp_scope, env.scopes); pat_ids = Some env.ids}
+
let mkGProd ?loc (na,bk,t) body = DAst.make ?loc @@ GProd (na, bk, t, body)
let mkGLambda ?loc (na,bk,t) body = DAst.make ?loc @@ GLambda (na, bk, t, body)
@@ -420,6 +430,40 @@ let binder_status_fun = {
slide = on_snd slide_binders;
}
+(* [test_kind_strict] rules out pattern which refers to global other
+ than constructors or variables; It is used in instances of notations *)
+
+let test_kind_pattern_in_notation ?loc = function
+ | GlobRef.ConstructRef _ -> ()
+ (* We do not accept non constructors to be used as variables in
+ patterns *)
+ | GlobRef.ConstRef _ ->
+ user_err ?loc (str "Found a constant while a pattern was expected.")
+ | GlobRef.IndRef _ ->
+ user_err ?loc (str "Found an inductive type while a pattern was expected.")
+ | GlobRef.VarRef _ ->
+ (* we accept a section variable name to be used as pattern variable *)
+ raise Not_found
+
+let test_kind_ident_in_notation ?loc = function
+ | GlobRef.ConstructRef _ ->
+ user_err ?loc (str "Found a constructor while a variable name was expected.")
+ | GlobRef.ConstRef _ ->
+ user_err ?loc (str "Found a constant while a variable name was expected.")
+ | GlobRef.IndRef _ ->
+ user_err ?loc (str "Found an inductive type while a variable name was expected.")
+ | GlobRef.VarRef _ ->
+ (* we accept a section variable name to be used as pattern variable *)
+ raise Not_found
+
+(* [test_kind_tolerant] allow global reference names to be used as pattern variables *)
+
+let test_kind_tolerant ?loc = function
+ | GlobRef.ConstructRef _ -> ()
+ | GlobRef.ConstRef _ | GlobRef.IndRef _ | GlobRef.VarRef _ ->
+ (* A non-constructor global reference in a pattern is seen as a variable *)
+ raise Not_found
+
(**)
let locate_if_hole ?loc na c = match DAst.get c with
@@ -539,9 +583,9 @@ let intern_letin_binder intern ntnvars env (({loc;v=na} as locna),def,ty) =
(push_name_env ntnvars impls env locna,
(na,Explicit,term,ty))
-let intern_cases_pattern_as_binder ?loc ntnvars env p =
+let intern_cases_pattern_as_binder ?loc test_kind ntnvars env p =
let il,disjpat =
- let (il, subst_disjpat) = !intern_cases_pattern_fwd ntnvars (None,env.scopes) p in
+ let (il, subst_disjpat) = !intern_cases_pattern_fwd test_kind ntnvars (env_for_pattern (reset_tmp_scope env)) p in
let substl,disjpat = List.split subst_disjpat in
if not (List.for_all (fun subst -> Id.Map.equal Id.equal subst Id.Map.empty) substl) then
user_err ?loc (str "Unsupported nested \"as\" clause.");
@@ -568,7 +612,7 @@ let intern_local_binder_aux intern ntnvars (env,bl) = function
| Some ty -> ty
| None -> CAst.make ?loc @@ CHole(None,IntroAnonymous,None)
in
- let env, ((disjpat,il),id),na = intern_cases_pattern_as_binder ?loc ntnvars env p in
+ let env, ((disjpat,il),id),na = intern_cases_pattern_as_binder ?loc test_kind_tolerant ntnvars env p in
let bk = Default Explicit in
let _, bl' = intern_assumption intern ntnvars env [na] bk tyc in
let {v=(_,bk,t)} = List.hd bl' in
@@ -661,27 +705,21 @@ let is_patvar_store store pat =
| PatVar na -> ignore(store na); true
| _ -> false
-let out_patvar pat =
- match pat.v with
+let out_patvar = CAst.map_with_loc (fun ?loc -> function
| CPatAtom (Some qid) when qualid_is_ident qid ->
Name (qualid_basename qid)
| CPatAtom None -> Anonymous
- | _ -> assert false
-
-let term_of_name = function
- | Name id -> DAst.make (GVar id)
- | Anonymous ->
- let st = Evar_kinds.Define (not (Program.get_proofs_transparency ())) in
- DAst.make (GHole (Evar_kinds.QuestionMark { Evar_kinds.default_question_mark with Evar_kinds.qm_obligation=st }, IntroAnonymous, None))
+ | _ -> assert false)
let traverse_binder intern_pat ntnvars (terms,_,binders,_ as subst) avoid (renaming,env) = function
| Anonymous -> (renaming,env), None, Anonymous
| Name id ->
let store,get = set_temporary_memory () in
+ let test_kind = test_kind_tolerant in
try
(* We instantiate binder name with patterns which may be parsed as terms *)
let pat = coerce_to_cases_pattern_expr (fst (Id.Map.find id terms)) in
- let env,((disjpat,ids),id),na = intern_pat ntnvars env pat in
+ let env,((disjpat,ids),id),na = intern_pat test_kind ntnvars env pat in
let pat, na = match disjpat with
| [pat] when is_patvar_store store pat -> let na = get () in None, na
| _ -> Some ((List.map (fun x -> x.v) ids,disjpat),id), na.v in
@@ -694,11 +732,11 @@ let traverse_binder intern_pat ntnvars (terms,_,binders,_ as subst) avoid (renam
if onlyident then
(* Do not try to interpret a variable as a constructor *)
let na = out_patvar pat in
- let env = push_name_env ntnvars [] env (make ?loc:pat.loc na) in
- (renaming,env), None, na
+ let env = push_name_env ntnvars [] env na in
+ (renaming,env), None, na.v
else
(* Interpret as a pattern *)
- let env,((disjpat,ids),id),na = intern_pat ntnvars env pat in
+ let env,((disjpat,ids),id),na = intern_pat test_kind ntnvars env pat in
let pat, na =
match disjpat with
| [pat] when is_patvar_store store pat -> let na = get () in None, na
@@ -829,22 +867,22 @@ let instantiate_notation_constr loc intern intern_pat ntnvars subst infos c =
let arg = match arg with
| None -> None
| Some arg ->
- let mk_env id (c, (tmp_scope, subscopes)) map =
- let nenv = {env with tmp_scope; scopes = subscopes @ env.scopes} in
+ let mk_env id (c, scopes) map =
+ let nenv = set_env_scopes env scopes in
try
let gc = intern nenv c in
Id.Map.add id (gc, None) map
with Nametab.GlobalizationError _ -> map
in
- let mk_env' (c, (onlyident,(tmp_scope,subscopes))) =
- let nenv = {env with tmp_scope; scopes = subscopes @ env.scopes} in
- if onlyident then
- let na = out_patvar c in term_of_name na, None
- else
- let _,((disjpat,_),_),_ = intern_pat ntnvars nenv c in
- match disjpat with
- | [pat] -> (glob_constr_of_cases_pattern (Global.env()) pat, None)
- | _ -> error_cannot_coerce_disjunctive_pattern_term ?loc:c.loc ()
+ let mk_env' (c, (onlyident,scopes)) =
+ let nenv = set_env_scopes env scopes in
+ let test_kind =
+ if onlyident then test_kind_ident_in_notation
+ else test_kind_pattern_in_notation in
+ let _,((disjpat,_),_),_ = intern_pat test_kind ntnvars nenv c in
+ match disjpat with
+ | [pat] -> (glob_constr_of_cases_pattern (Global.env()) pat, None)
+ | _ -> error_cannot_coerce_disjunctive_pattern_term ?loc:c.loc ()
in
let terms = Id.Map.fold mk_env terms Id.Map.empty in
let binders = Id.Map.map mk_env' binders in
@@ -890,20 +928,19 @@ let instantiate_notation_constr loc intern intern_pat ntnvars subst infos c =
(* subst remembers the delimiters stack in the interpretation *)
(* of the notations *)
try
- let (a,(scopt,subscopes)) = Id.Map.find id terms in
- intern {env with tmp_scope = scopt;
- scopes = subscopes @ env.scopes} a
+ let (a,scopes) = Id.Map.find id terms in
+ intern (set_env_scopes env scopes) a
with Not_found ->
try
let pat,(onlyident,scopes) = Id.Map.find id binders in
- let env = set_env_scopes env scopes in
- if onlyident then
- term_of_name (out_patvar pat)
- else
- let env,((disjpat,ids),id),na = intern_pat ntnvars env pat in
- match disjpat with
- | [pat] -> glob_constr_of_cases_pattern (Global.env()) pat
- | _ -> user_err Pp.(str "Cannot turn a disjunctive pattern into a term.")
+ let nenv = set_env_scopes env scopes in
+ let test_kind =
+ if onlyident then test_kind_ident_in_notation
+ else test_kind_pattern_in_notation in
+ let env,((disjpat,ids),id),na = intern_pat test_kind ntnvars nenv pat in
+ match disjpat with
+ | [pat] -> glob_constr_of_cases_pattern (Global.env()) pat
+ | _ -> user_err Pp.(str "Cannot turn a disjunctive pattern into a term.")
with Not_found ->
try
match binderopt with
@@ -1570,11 +1607,11 @@ let rec subst_pat_iterator y t = DAst.(map (function
| RCPatOr pl -> RCPatOr (List.map (subst_pat_iterator y t) pl)))
let is_non_zero c = match c with
-| { CAst.v = CPrim (Numeral p) } -> not (NumTok.Signed.is_zero p)
+| { CAst.v = CPrim (Number p) } -> not (NumTok.Signed.is_zero p)
| _ -> false
let is_non_zero_pat c = match c with
-| { CAst.v = CPatPrim (Numeral p) } -> not (NumTok.Signed.is_zero p)
+| { CAst.v = CPatPrim (Number p) } -> not (NumTok.Signed.is_zero p)
| _ -> false
let get_asymmetric_patterns = Goptions.declare_bool_option_and_ref
@@ -1582,19 +1619,14 @@ let get_asymmetric_patterns = Goptions.declare_bool_option_and_ref
~key:["Asymmetric";"Patterns"]
~value:false
-let drop_notations_pattern looked_for genv =
+let drop_notations_pattern (test_kind_top,test_kind_inner) genv env pat =
(* At toplevel, Constructors and Inductives are accepted, in recursive calls
only constructor are allowed *)
- let ensure_kind top loc g =
- try
- if top then looked_for g else
- match g with GlobRef.ConstructRef _ -> () | _ -> raise Not_found
+ let ensure_kind test_kind ?loc g =
+ try test_kind ?loc g
with Not_found ->
error_invalid_pattern_notation ?loc ()
in
- let test_kind top =
- if top then looked_for else function GlobRef.ConstructRef _ -> () | _ -> raise Not_found
- in
(* [rcp_of_glob] : from [glob_constr] to [raw_cases_pattern_expr] *)
let rec rcp_of_glob scopes x = DAst.(map (function
| GVar id -> RCPatAtom (Some (CAst.make ?loc:x.loc id,scopes))
@@ -1611,47 +1643,49 @@ let drop_notations_pattern looked_for genv =
end
| _ -> CErrors.anomaly Pp.(str "Invalid return pattern from Notation.interp_prim_token_cases_pattern_expr."))) x
in
- let rec drop_syndef top scopes qid pats =
+ let rec drop_syndef test_kind ?loc scopes qid pats =
try
+ if qualid_is_ident qid && Option.cata (Id.Set.mem (qualid_basename qid)) false env.pat_ids then
+ raise Not_found;
match Nametab.locate_extended qid with
| SynDef sp ->
let filter (vars,a) =
try match a with
| NRef g ->
(* Convention: do not deactivate implicit arguments and scopes for further arguments *)
- test_kind top g;
+ test_kind ?loc g;
let () = assert (List.is_empty vars) in
let (_,argscs) = find_remaining_scopes [] pats g in
Some (g, [], List.map2 (in_pat_sc scopes) argscs pats)
| NApp (NRef g,[]) -> (* special case: Syndef for @Cstr deactivates implicit arguments *)
- test_kind top g;
+ test_kind ?loc g;
let () = assert (List.is_empty vars) in
let (_,argscs) = find_remaining_scopes [] pats g in
Some (g, List.map2 (in_pat_sc scopes) argscs pats, [])
| NApp (NRef g,args) ->
(* Convention: do not deactivate implicit arguments and scopes for further arguments *)
- test_kind top g;
+ test_kind ?loc g;
let nvars = List.length vars in
if List.length pats < nvars then error_not_enough_arguments ?loc:qid.loc;
let pats1,pats2 = List.chop nvars pats in
let subst = split_by_type_pat vars (pats1,[]) in
- let idspl1 = List.map (in_not false qid.loc scopes subst []) args in
+ let idspl1 = List.map (in_not test_kind_inner qid.loc scopes subst []) args in
let (_,argscs) = find_remaining_scopes pats1 pats2 g in
Some (g, idspl1, List.map2 (in_pat_sc scopes) argscs pats2)
| _ -> raise Not_found
with Not_found -> None in
Syntax_def.search_filtered_syntactic_definition filter sp
| TrueGlobal g ->
- test_kind top g;
+ test_kind ?loc g;
Dumpglob.add_glob ?loc:qid.loc g;
let (_,argscs) = find_remaining_scopes [] pats g in
Some (g,[],List.map2 (in_pat_sc scopes) argscs pats)
with Not_found -> None
- and in_pat top scopes pt =
+ and in_pat test_kind scopes pt =
let open CAst in
let loc = pt.loc in
match pt.v with
- | CPatAlias (p, id) -> DAst.make ?loc @@ RCPatAlias (in_pat top scopes p, id)
+ | CPatAlias (p, id) -> DAst.make ?loc @@ RCPatAlias (in_pat test_kind scopes p, id)
| CPatRecord l ->
let sorted_fields =
sort_fields ~complete:false loc l (fun _idx fieldname constructor -> CAst.make ?loc @@ CPatAtom None) in
@@ -1668,7 +1702,7 @@ let drop_notations_pattern looked_for genv =
end
| CPatCstr (head, None, pl) ->
begin
- match drop_syndef top scopes head pl with
+ match drop_syndef test_kind ?loc scopes head pl with
| Some (a,b,c) -> DAst.make ?loc @@ RCPatCstr(a, b, c)
| None -> Loc.raise ?loc (InternalizationError (NotAConstructor head))
end
@@ -1682,37 +1716,37 @@ let drop_notations_pattern looked_for genv =
in
if expl_pl == [] then
(* Convention: (@r) deactivates all further implicit arguments and scopes *)
- DAst.make ?loc @@ RCPatCstr (g, List.map (in_pat false scopes) pl, [])
+ DAst.make ?loc @@ RCPatCstr (g, List.map (in_pat test_kind_inner scopes) pl, [])
else
(* Convention: (@r expl_pl) deactivates implicit arguments in expl_pl and in pl *)
(* but not scopes in expl_pl *)
let (argscs1,_) = find_remaining_scopes expl_pl pl g in
- DAst.make ?loc @@ RCPatCstr (g, List.map2 (in_pat_sc scopes) argscs1 expl_pl @ List.map (in_pat false scopes) pl, [])
+ DAst.make ?loc @@ RCPatCstr (g, List.map2 (in_pat_sc scopes) argscs1 expl_pl @ List.map (in_pat test_kind_inner scopes) pl, [])
| CPatNotation (_,(InConstrEntry,"- _"),([a],[]),[]) when is_non_zero_pat a ->
- let p = match a.CAst.v with CPatPrim (Numeral (_, p)) -> p | _ -> assert false in
- let pat, _df = Notation.interp_prim_token_cases_pattern_expr ?loc (ensure_kind false loc) (Numeral (SMinus,p)) scopes in
+ let p = match a.CAst.v with CPatPrim (Number (_, p)) -> p | _ -> assert false in
+ let pat, _df = Notation.interp_prim_token_cases_pattern_expr ?loc (ensure_kind test_kind_inner) (Number (SMinus,p)) scopes in
rcp_of_glob scopes pat
| CPatNotation (_,(InConstrEntry,"( _ )"),([a],[]),[]) ->
- in_pat top scopes a
+ in_pat test_kind scopes a
| CPatNotation (_,ntn,fullargs,extrargs) ->
let ntn,(terms,termlists) = contract_curly_brackets_pat ntn fullargs in
let ((ids',c),df) = Notation.interp_notation ?loc ntn scopes in
- let (terms,termlists) = split_by_type_pat ?loc ids' (terms,termlists) in
+ let subst = split_by_type_pat ?loc ids' (terms,termlists) in
Dumpglob.dump_notation_location (patntn_loc ?loc fullargs ntn) ntn df;
- in_not top loc scopes (terms,termlists) extrargs c
+ in_not test_kind loc scopes subst extrargs c
| CPatDelimiters (key, e) ->
- in_pat top (None,find_delimiters_scope ?loc key::snd scopes) e
+ in_pat test_kind (None,find_delimiters_scope ?loc key::snd scopes) e
| CPatPrim p ->
- let pat, _df = Notation.interp_prim_token_cases_pattern_expr ?loc (test_kind false) p scopes in
+ let pat, _df = Notation.interp_prim_token_cases_pattern_expr ?loc test_kind_inner p scopes in
rcp_of_glob scopes pat
| CPatAtom (Some id) ->
begin
- match drop_syndef top scopes id [] with
+ match drop_syndef test_kind ?loc scopes id [] with
| Some (a,b,c) -> DAst.make ?loc @@ RCPatCstr (a, b, c)
| None -> DAst.make ?loc @@ RCPatAtom (Some ((make ?loc @@ find_pattern_variable id),scopes))
end
| CPatAtom None -> DAst.make ?loc @@ RCPatAtom None
- | CPatOr pl -> DAst.make ?loc @@ RCPatOr (List.map (in_pat top scopes) pl)
+ | CPatOr pl -> DAst.make ?loc @@ RCPatOr (List.map (in_pat test_kind scopes) pl)
| CPatCast (_,_) ->
(* We raise an error if the pattern contains a cast, due to
current restrictions on casts in patterns. Cast in patterns
@@ -1725,8 +1759,8 @@ let drop_notations_pattern looked_for genv =
This check is here and not in the parser because it would require
duplicating the levels of the [pattern] rule. *)
CErrors.user_err ?loc (Pp.strbrk "Casts are not supported in this pattern.")
- and in_pat_sc scopes x = in_pat false (x,snd scopes)
- and in_not top loc scopes (subst,substlist as fullsubst) args = function
+ and in_pat_sc scopes x = in_pat test_kind_inner (x,snd scopes)
+ and in_not (test_kind:?loc:Loc.t->'a->'b) loc scopes (subst,substlist as fullsubst) args = function
| NVar id ->
let () = assert (List.is_empty args) in
begin
@@ -1734,21 +1768,21 @@ let drop_notations_pattern looked_for genv =
(* of the notations *)
try
let (a,(scopt,subscopes)) = Id.Map.find id subst in
- in_pat top (scopt,subscopes@snd scopes) a
+ in_pat test_kind (scopt,subscopes@snd scopes) a
with Not_found ->
if Id.equal id ldots_var then DAst.make ?loc @@ RCPatAtom (Some ((make ?loc id),scopes)) else
anomaly (str "Unbound pattern notation variable: " ++ Id.print id ++ str ".")
end
| NRef g ->
- ensure_kind top loc g;
+ ensure_kind test_kind ?loc g;
let (_,argscs) = find_remaining_scopes [] args g in
DAst.make ?loc @@ RCPatCstr (g, [], List.map2 (in_pat_sc scopes) argscs args)
| NApp (NRef g,pl) ->
- ensure_kind top loc g;
+ ensure_kind test_kind ?loc g;
let (argscs1,argscs2) = find_remaining_scopes pl args g in
- let pl = List.map2 (fun x -> in_not false loc (x,snd scopes) fullsubst []) argscs1 pl in
+ let pl = List.map2 (fun x -> in_not test_kind_inner loc (x,snd scopes) fullsubst []) argscs1 pl in
let pl = add_local_defs_and_check_length loc genv g pl args in
- let args = List.map2 (fun x -> in_pat false (x,snd scopes)) argscs2 args in
+ let args = List.map2 (fun x -> in_pat test_kind_inner (x,snd scopes)) argscs2 args in
let pat =
if List.length pl = 0 then
(* Convention: if notation is @f, encoded as NApp(Nref g,[]), then
@@ -1763,10 +1797,10 @@ let drop_notations_pattern looked_for genv =
(try
(* All elements of the list are in scopes (scopt,subscopes) *)
let (l,(scopt,subscopes)) = Id.Map.find x substlist in
- let termin = in_not top loc scopes fullsubst [] terminator in
+ let termin = in_not test_kind_inner loc scopes fullsubst [] terminator in
List.fold_right (fun a t ->
let nsubst = Id.Map.add y (a, (scopt, subscopes)) subst in
- let u = in_not false loc scopes (nsubst, substlist) [] iter in
+ let u = in_not test_kind_inner loc scopes (nsubst, substlist) [] iter in
subst_pat_iterator ldots_var t u)
(if revert then List.rev l else l) termin
with Not_found ->
@@ -1775,7 +1809,7 @@ let drop_notations_pattern looked_for genv =
let () = assert (List.is_empty args) in
DAst.make ?loc @@ RCPatAtom None
| t -> error_invalid_pattern_notation ?loc ()
- in in_pat true
+ in in_pat test_kind_top env.pat_scopes pat
let rec intern_pat genv ntnvars aliases pat =
let intern_cstr_with_all_args loc c with_letin idslpl1 pl2 =
@@ -1816,19 +1850,30 @@ let rec intern_pat genv ntnvars aliases pat =
check_or_pat_variables loc ids (List.tl idsl);
(ids,List.flatten pl')
-let intern_cases_pattern genv ntnvars scopes aliases pat =
+let intern_cases_pattern test_kind genv ntnvars env aliases pat =
intern_pat genv ntnvars aliases
- (drop_notations_pattern (function GlobRef.ConstructRef _ -> () | _ -> raise Not_found) genv scopes pat)
+ (drop_notations_pattern (test_kind,test_kind) genv env pat)
let _ =
intern_cases_pattern_fwd :=
- fun ntnvars scopes p -> intern_cases_pattern (Global.env ()) ntnvars scopes empty_alias p
-
-let intern_ind_pattern genv ntnvars scopes pat =
+ fun test_kind ntnvars env p ->
+ intern_cases_pattern test_kind (Global.env ()) ntnvars env empty_alias p
+
+let intern_ind_pattern genv ntnvars env pat =
+ let test_kind_top ?loc = function
+ | GlobRef.IndRef _ -> ()
+ | GlobRef.ConstructRef _ | GlobRef.ConstRef _ | GlobRef.VarRef _ ->
+ (* A non-inductive global reference at top is an error *)
+ error_invalid_pattern_notation ?loc () in
+ let test_kind_inner ?loc = function
+ | GlobRef.ConstructRef _ -> ()
+ | GlobRef.IndRef _ | GlobRef.ConstRef _ | GlobRef.VarRef _ ->
+ (* A non-constructor global reference deep in a pattern is seen as a variable *)
+ raise Not_found in
let no_not =
try
- drop_notations_pattern (function (GlobRef.IndRef _ | GlobRef.ConstructRef _) -> () | _ -> raise Not_found) genv scopes pat
- with InternalizationError(NotAConstructor _) as exn ->
+ drop_notations_pattern (test_kind_top,test_kind_inner) genv env pat
+ with InternalizationError (NotAConstructor _) as exn ->
let _, info = Exninfo.capture exn in
error_bad_inductive_type ~info ()
in
@@ -2006,8 +2051,8 @@ let internalize globalenv env pattern_mode (_, ntnvars as lvar) c =
GLetIn (na.CAst.v, inc1, int,
intern_restart_binders (push_name_env ntnvars (impls_term_list 1 inc1) env na) c2)
| CNotation (_,(InConstrEntry,"- _"), ([a],[],[],[])) when is_non_zero a ->
- let p = match a.CAst.v with CPrim (Numeral (_, p)) -> p | _ -> assert false in
- intern env (CAst.make ?loc @@ CPrim (Numeral (SMinus,p)))
+ let p = match a.CAst.v with CPrim (Number (_, p)) -> p | _ -> assert false in
+ intern env (CAst.make ?loc @@ CPrim (Number (SMinus,p)))
| CNotation (_,(InConstrEntry,"( _ )"),([a],[],[],[])) -> intern env a
| CNotation (_,ntn,args) ->
let c = intern_notation intern env ntnvars loc ntn args in
@@ -2188,7 +2233,7 @@ let internalize globalenv env pattern_mode (_, ntnvars as lvar) c =
GPatVar (Evar_kinds.SecondOrderPatVar n)
| CEvar (n, []) when pattern_mode ->
DAst.make ?loc @@
- GPatVar (Evar_kinds.FirstOrderPatVar n)
+ GPatVar (Evar_kinds.FirstOrderPatVar n.CAst.v)
(* end *)
(* Parsing existential variables *)
| CEvar (n, l) ->
@@ -2221,7 +2266,8 @@ let internalize globalenv env pattern_mode (_, ntnvars as lvar) c =
(* Expands a multiple pattern into a disjunction of multiple patterns *)
and intern_multiple_pattern env n pl =
- let idsl_pll = List.map (intern_cases_pattern globalenv ntnvars (None,env.scopes) empty_alias) pl in
+ let env = { pat_ids = None; pat_scopes = (None,env.scopes) } in
+ let idsl_pll = List.map (intern_cases_pattern test_kind_tolerant globalenv ntnvars env empty_alias) pl in
let loc = loc_of_multiple_pattern pl in
check_number_of_pattern loc n pl;
product_of_cases_patterns empty_alias idsl_pll
@@ -2262,7 +2308,7 @@ let internalize globalenv env pattern_mode (_, ntnvars as lvar) c =
let match_td,typ = match t with
| Some t ->
let with_letin,(ind,ind_ids,alias_subst,l) =
- intern_ind_pattern globalenv ntnvars (None,env.scopes) t in
+ intern_ind_pattern globalenv ntnvars (env_for_pattern (set_type_scope env)) t in
let (mib,mip) = Inductive.lookup_mind_specif globalenv ind in
let nparams = (List.length (mib.Declarations.mind_params_ctxt)) in
(* for "in Vect n", we answer (["n","n"],[(loc,"n")])
@@ -2403,7 +2449,8 @@ let intern_gen kind env sigma
let intern_constr env sigma c = intern_gen WithoutTypeConstraint env sigma c
let intern_type env sigma c = intern_gen IsType env sigma c
let intern_pattern globalenv patt =
- intern_cases_pattern globalenv Id.Map.empty (None,[]) empty_alias patt
+ let env = {pat_ids = None; pat_scopes = (None, [])} in
+ intern_cases_pattern test_kind_tolerant globalenv Id.Map.empty env empty_alias patt
(*********************************************************************)
(* Functions to parse and interpret constructions *)
@@ -2471,6 +2518,14 @@ let intern_constr_pattern env sigma ?(as_type=false) ?(ltacvars=empty_ltac_sign)
~pattern_mode:true ~ltacvars env sigma c in
pattern_of_glob_constr c
+let interp_constr_pattern env sigma ?(expected_type=WithoutTypeConstraint) c =
+ let c = intern_gen expected_type ~pattern_mode:true env sigma c in
+ let flags = { Pretyping.no_classes_no_fail_inference_flags with expand_evars = false } in
+ let sigma, c = understand_tcc ~flags env sigma ~expected_type c in
+ (* FIXME: it is necessary to be unsafe here because of the way we handle
+ evars in the pretyper. Sometimes they get solved eagerly. *)
+ pattern_of_constr env sigma (EConstr.Unsafe.to_constr c)
+
let intern_core kind env sigma ?(pattern_mode=false) ?(ltacvars=empty_ltac_sign)
{ Genintern.intern_ids = ids; Genintern.notation_variable_status = vl } c =
let tmp_scope = scope_of_type_kind env sigma kind in
diff --git a/interp/constrintern.mli b/interp/constrintern.mli
index 898a3e09c8..11d756803f 100644
--- a/interp/constrintern.mli
+++ b/interp/constrintern.mli
@@ -136,10 +136,16 @@ val interp_type_evars_impls : ?flags:inference_flags -> env -> evar_map ->
(** Interprets constr patterns *)
+(** Without typing *)
val intern_constr_pattern :
env -> evar_map -> ?as_type:bool -> ?ltacvars:ltac_sign ->
constr_pattern_expr -> patvar list * constr_pattern
+(** With typing *)
+val interp_constr_pattern :
+ env -> evar_map -> ?expected_type:typing_constraint ->
+ constr_pattern_expr -> constr_pattern
+
(** Raise Not_found if syndef not bound to a name and error if unexisting ref *)
val intern_reference : qualid -> GlobRef.t
diff --git a/interp/implicit_quantifiers.ml b/interp/implicit_quantifiers.ml
index 4016a3600e..ee07fb6ed1 100644
--- a/interp/implicit_quantifiers.ml
+++ b/interp/implicit_quantifiers.ml
@@ -114,23 +114,32 @@ let generalizable_vars_of_glob_constr ?(bound=Id.Set.empty) ?(allowed=Id.Set.emp
ungeneralizable loc id) vars;
vars
-let rec make_fresh ids env x =
- if is_freevar ids env x then x else make_fresh ids env (Nameops.increment_subscript x)
+let make_fresh ids env x =
+ Namegen.next_ident_away_from x (fun x -> not (is_freevar ids env x))
let next_name_away_from na avoid =
match na with
| Anonymous -> make_fresh avoid (Global.env ()) (Id.of_string "anon")
| Name id -> make_fresh avoid (Global.env ()) id
+let rec is_class_arg c =
+ let open Constr in
+ match kind c with
+ | Prod (_,_,c)
+ | Cast (c,_,_)
+ | LetIn (_,_,_,c) -> is_class_arg c
+ | _ ->
+ let c, _ = decompose_appvect c in
+ match destRef c with
+ | exception DestKO -> false
+ | r, _ -> is_class r
+
let combine_params avoid applied needed =
let named, applied =
List.partition
(function
(t, Some {CAst.loc;v=ExplByName id}) ->
- let is_id (_, decl) = match RelDecl.get_name decl with
- | Name id' -> Id.equal id id'
- | Anonymous -> false
- in
+ let is_id decl = Name.equal (Name id) (RelDecl.get_name decl) in
if not (List.exists is_id needed) then
user_err ?loc (str "Wrong argument name: " ++ Id.print id);
true
@@ -141,27 +150,27 @@ let combine_params avoid applied needed =
named
in
let rec aux ids avoid app need =
- match app, need with
-
- | _, (_, LocalDef _) :: need -> aux ids avoid app need
-
- | [], [] -> List.rev ids, avoid
+ match need with
+ | [] -> begin match app with
+ | [] -> List.rev ids, avoid
+ | (x, _) :: _ -> user_err ?loc:(Constrexpr_ops.constr_loc x) (str "Typeclass does not expect more arguments")
+ end
- | app, (_, (LocalAssum ({binder_name=Name id}, _))) :: need when Id.List.mem_assoc id named ->
- aux (Id.List.assoc id named :: ids) avoid app need
+ | LocalDef _ :: need -> aux ids avoid app need
- | (x, None) :: app, (None, (LocalAssum ({binder_name=Name id}, _))) :: need ->
- aux (x :: ids) avoid app need
- | x :: app, (None, _) :: need -> aux (fst x :: ids) avoid app need
+ | LocalAssum ({binder_name=Name id}, _) :: need when Id.List.mem_assoc id named ->
+ aux (Id.List.assoc id named :: ids) avoid app need
- | _, (Some _, decl) :: need | [], (None, decl) :: need ->
- let id' = next_name_away_from (RelDecl.get_name decl) avoid in
- let t' = CAst.make @@ CRef (qualid_of_ident id',None) in
- aux (t' :: ids) (Id.Set.add id' avoid) app need
+ | decl :: need ->
+ begin match app, is_class_arg (get_type decl) with
+ | (x, _) :: app, false -> aux (x :: ids) avoid app need
- | (x,_) :: _, [] ->
- user_err ?loc:(Constrexpr_ops.constr_loc x) (str "Typeclass does not expect more arguments")
+ | [], false | _, true ->
+ let id' = next_name_away_from (RelDecl.get_name decl) avoid in
+ let t' = CAst.make @@ CRef (qualid_of_ident id',None) in
+ aux (t' :: ids) (Id.Set.add id' avoid) app need
+ end
in
aux [] avoid applied needed
@@ -190,9 +199,7 @@ let implicit_application env ty =
let env = Global.env () in
let sigma = Evd.from_env env in
let c = class_info env sigma gr in
- let (ci, rd) = c.cl_context in
- let pars = List.rev (List.combine ci rd) in
- let args, avoid = combine_params avoid par pars in
+ let args, avoid = combine_params avoid par (List.rev c.cl_context) in
CAst.make ?loc @@ CAppExpl ((None, id, inst), args), avoid
let warn_ignoring_implicit_status =
diff --git a/interp/notation.ml b/interp/notation.ml
index 7e90e15b72..8d05fab63c 100644
--- a/interp/notation.ml
+++ b/interp/notation.ml
@@ -32,7 +32,7 @@ open NumTok
fail if a number has no interpretation in the scope (e.g. there is
no interpretation for negative numbers in [nat]); interpreters both for
terms and patterns can be set; these interpreters are in permanent table
- [numeral_interpreter_tab]
+ [number_interpreter_tab]
- a set of ML printers for expressions denoting numbers parsable in
this scope
- a set of interpretations for infix (more generally distfix) notations
@@ -58,6 +58,31 @@ let notation_with_optional_scope_eq inscope1 inscope2 = match (inscope1,inscope2
let notation_eq (from1,ntn1) (from2,ntn2) =
notation_entry_eq from1 from2 && String.equal ntn1 ntn2
+let pair_eq f g (x1, y1) (x2, y2) = f x1 x2 && g y1 y2
+
+let notation_binder_source_eq s1 s2 = match s1, s2 with
+| NtnParsedAsIdent, NtnParsedAsIdent -> true
+| NtnParsedAsPattern b1, NtnParsedAsPattern b2 -> b1 = b2
+| NtnBinderParsedAsConstr bk1, NtnBinderParsedAsConstr bk2 -> bk1 = bk2
+| (NtnParsedAsIdent | NtnParsedAsPattern _ | NtnBinderParsedAsConstr _), _ -> false
+
+let ntpe_eq t1 t2 = match t1, t2 with
+| NtnTypeConstr, NtnTypeConstr -> true
+| NtnTypeBinder s1, NtnTypeBinder s2 -> notation_binder_source_eq s1 s2
+| NtnTypeConstrList, NtnTypeConstrList -> true
+| NtnTypeBinderList, NtnTypeBinderList -> true
+| (NtnTypeConstr | NtnTypeBinder _ | NtnTypeConstrList | NtnTypeBinderList), _ -> false
+
+let var_attributes_eq (_, ((entry1, sc1), tp1)) (_, ((entry2, sc2), tp2)) =
+ notation_entry_level_eq entry1 entry2 &&
+ pair_eq (Option.equal String.equal) (List.equal String.equal) sc1 sc2 &&
+ ntpe_eq tp1 tp2
+
+let interpretation_eq (vars1, t1 as x1) (vars2, t2 as x2) =
+ x1 == x2 ||
+ List.equal var_attributes_eq vars1 vars2 &&
+ Notation_ops.eq_notation_constr (List.map fst vars1, List.map fst vars2) t1 t2
+
let pr_notation (from,ntn) = qstring ntn ++ match from with InConstrEntry -> mt () | InCustomEntry s -> str " in custom " ++ str s
module NotationOrd =
@@ -90,8 +115,21 @@ type notation_data = {
not_deprecation : Deprecation.t option;
}
+type activation = bool
+
+type extra_printing_notation_data =
+ (activation * notation_data) list
+
+type parsing_notation_data =
+ | NoParsingData
+ | OnlyParsingData of activation * notation_data
+ | ParsingAndPrintingData of
+ activation (* for parsing*) *
+ activation (* for printing *) *
+ notation_data (* common data for both *)
+
type scope = {
- notations: notation_data NotationMap.t;
+ notations: (parsing_notation_data * extra_printing_notation_data) NotationMap.t;
delimiters: delimiters option
}
@@ -285,7 +323,7 @@ type key =
| Oth
let key_compare k1 k2 = match k1, k2 with
-| RefKey gr1, RefKey gr2 -> GlobRef.Ordered.compare gr1 gr2
+| RefKey gr1, RefKey gr2 -> GlobRef.CanOrd.compare gr1 gr2
| RefKey _, Oth -> -1
| Oth, RefKey _ -> 1
| Oth, Oth -> 0
@@ -300,16 +338,30 @@ type notation_applicative_status =
type notation_rule = interp_rule * interpretation * notation_applicative_status
+let notation_rule_eq (rule1,pat1,s1 as x1) (rule2,pat2,s2 as x2) =
+ x1 == x2 || (rule1 = rule2 && interpretation_eq pat1 pat2 && s1 = s2)
+
+let also_cases_notation_rule_eq (also_cases1,rule1) (also_cases2,rule2) =
+ (* No need in principle to compare also_cases as it is inferred *)
+ also_cases1 = also_cases2 && notation_rule_eq rule1 rule2
+
let keymap_add key interp map =
let old = try KeyMap.find key map with Not_found -> [] in
+ (* In case of re-import, no need to keep the previous copy *)
+ let old = try List.remove_first (also_cases_notation_rule_eq interp) old with Not_found -> old in
KeyMap.add key (interp :: old) map
+let keymap_remove key interp map =
+ let old = try KeyMap.find key map with Not_found -> [] in
+ KeyMap.add key (List.remove_first (also_cases_notation_rule_eq interp) old) map
+
let keymap_find key map =
try KeyMap.find key map
with Not_found -> []
(* Scopes table : interpretation -> scope_name *)
-let notations_key_table = ref (KeyMap.empty : notation_rule list KeyMap.t)
+(* Boolean = for cases pattern also *)
+let notations_key_table = ref (KeyMap.empty : (bool * notation_rule) list KeyMap.t)
let glob_prim_constr_key c = match DAst.get c with
| GRef (ref, _) -> Some (canonical_gr ref)
@@ -399,13 +451,13 @@ module InnerPrimToken = struct
let do_interp ?loc interp primtok =
match primtok, interp with
- | Numeral n, RawNumInterp interp -> interp ?loc n
- | Numeral n, BigNumInterp interp ->
+ | Number n, RawNumInterp interp -> interp ?loc n
+ | Number n, BigNumInterp interp ->
(match NumTok.Signed.to_bigint n with
| Some n -> interp ?loc n
| None -> raise Not_found)
| String s, StringInterp interp -> interp ?loc s
- | (Numeral _ | String _),
+ | (Number _ | String _),
(RawNumInterp _ | BigNumInterp _ | StringInterp _) -> raise Not_found
type uninterpreter =
@@ -419,16 +471,16 @@ module InnerPrimToken = struct
| StringUninterp f, StringUninterp f' -> f == f'
| _ -> false
- let mkNumeral n =
- Numeral (NumTok.Signed.of_bigint CDec n)
+ let mkNumber n =
+ Number (NumTok.Signed.of_bigint CDec n)
let mkString = function
| None -> None
| Some s -> if Unicode.is_utf8 s then Some (String s) else None
let do_uninterp uninterp g = match uninterp with
- | RawNumUninterp u -> Option.map (fun (s,n) -> Numeral (s,n)) (u g)
- | BigNumUninterp u -> Option.map mkNumeral (u g)
+ | RawNumUninterp u -> Option.map (fun (s,n) -> Number (s,n)) (u g)
+ | BigNumUninterp u -> Option.map mkNumber (u g)
| StringUninterp u -> mkString (u g)
end
@@ -448,7 +500,7 @@ let prim_token_uninterpreters =
(Hashtbl.create 7 : (prim_token_uid, InnerPrimToken.uninterpreter) Hashtbl.t)
(*******************************************************)
-(* Numeral notation interpretation *)
+(* Number notation interpretation *)
type prim_token_notation_error =
| UnexpectedTerm of Constr.t
| UnexpectedNonOptionTerm of Constr.t
@@ -472,21 +524,21 @@ type z_pos_ty =
{ z_ty : Names.inductive;
pos_ty : Names.inductive }
-type numeral_ty =
+type number_ty =
{ int : int_ty;
decimal : Names.inductive;
hexadecimal : Names.inductive;
- numeral : Names.inductive }
+ number : Names.inductive }
type target_kind =
- | Int of int_ty (* Coq.Init.Numeral.int + uint *)
- | UInt of int_ty (* Coq.Init.Numeral.uint *)
+ | Int of int_ty (* Coq.Init.Number.int + uint *)
+ | UInt of int_ty (* Coq.Init.Number.uint *)
| Z of z_pos_ty (* Coq.Numbers.BinNums.Z and positive *)
| Int63 (* Coq.Numbers.Cyclic.Int63.Int63.int *)
- | Numeral of numeral_ty (* Coq.Init.Numeral.numeral + uint + int *)
+ | Number of number_ty (* Coq.Init.Number.number + uint + int *)
| DecimalInt of int_ty (* Coq.Init.Decimal.int + uint (deprecated) *)
| DecimalUInt of int_ty (* Coq.Init.Decimal.uint (deprecated) *)
- | Decimal of numeral_ty (* Coq.Init.Decimal.Decimal + uint + int (deprecated) *)
+ | Decimal of number_ty (* Coq.Init.Decimal.Decimal + uint + int (deprecated) *)
type string_target_kind =
| ListByte
@@ -495,19 +547,36 @@ type string_target_kind =
type option_kind = Option | Direct
type 'target conversion_kind = 'target * option_kind
+(** A postprocessing translation [to_post] can be done after execution
+ of the [to_ty] interpreter. The reverse translation is performed
+ before the [of_ty] uninterpreter.
+
+ [to_post] is an array of [n] lists [l_i] of tuples [(f, t,
+ args)]. When the head symbol of the translated term matches one of
+ the [f] in the list [l_0] it is replaced by [t] and its arguments
+ are translated acording to [args] where [ToPostCopy] means that the
+ argument is kept unchanged and [ToPostAs k] means that the
+ argument is recursively translated according to [l_k].
+ [ToPostHole] introduces an additional implicit argument hole
+ (in the reverse translation, the corresponding argument is removed).
+ [ToPostCheck r] behaves as [ToPostCopy] except in the reverse
+ translation which fails if the copied term is not [r].
+ When [n] is null, no translation is performed. *)
+type to_post_arg = ToPostCopy | ToPostAs of int | ToPostHole | ToPostCheck of GlobRef.t
type ('target, 'warning) prim_token_notation_obj =
{ to_kind : 'target conversion_kind;
to_ty : GlobRef.t;
+ to_post : ((GlobRef.t * GlobRef.t * to_post_arg list) list) array;
of_kind : 'target conversion_kind;
of_ty : GlobRef.t;
ty_name : Libnames.qualid; (* for warnings / error messages *)
warning : 'warning }
-type numeral_notation_obj = (target_kind, numnot_option) prim_token_notation_obj
+type number_notation_obj = (target_kind, numnot_option) prim_token_notation_obj
type string_notation_obj = (string_target_kind, unit) prim_token_notation_obj
module PrimTokenNotation = struct
-(** * Code shared between Numeral notation and String notation *)
+(** * Code shared between Number notation and String notation *)
(** Reduction
The constr [c] below isn't necessarily well-typed, since we
@@ -541,22 +610,69 @@ exception NotAValidPrimToken
to [constr] for the subset that concerns us.
Note that if you update [constr_of_glob], you should update the
- corresponding numeral notation *and* string notation doc in
+ corresponding number notation *and* string notation doc in
doc/sphinx/user-extensions/syntax-extensions.rst that describes
what it means for a term to be ground / to be able to be
considered for parsing. *)
-let rec constr_of_glob env sigma g = match DAst.get g with
- | Glob_term.GRef (GlobRef.ConstructRef c, _) ->
- let sigma,c = Evd.fresh_constructor_instance env sigma c in
- sigma,mkConstructU c
- | Glob_term.GRef (GlobRef.IndRef c, _) ->
- let sigma,c = Evd.fresh_inductive_instance env sigma c in
- sigma,mkIndU c
+let constr_of_globref allow_constant env sigma = function
+ | GlobRef.ConstructRef c ->
+ let sigma,c = Evd.fresh_constructor_instance env sigma c in
+ sigma,mkConstructU c
+ | GlobRef.IndRef c ->
+ let sigma,c = Evd.fresh_inductive_instance env sigma c in
+ sigma,mkIndU c
+ | GlobRef.ConstRef c when allow_constant ->
+ let sigma,c = Evd.fresh_constant_instance env sigma c in
+ sigma,mkConstU c
+ | _ -> raise NotAValidPrimToken
+
+let rec constr_of_glob allow_constant to_post post env sigma g = match DAst.get g with
+ | Glob_term.GRef (r, _) ->
+ let o = List.find_opt (fun (_,r',_) -> GlobRef.equal r r') post in
+ begin match o with
+ | None -> constr_of_globref allow_constant env sigma r
+ | Some (r, _, a) ->
+ (* [g] is not a GApp so check that [post]
+ does not expect any actual argument
+ (i.e., [a] contains only ToPostHole since they mean "ignore arg") *)
+ if List.exists ((<>) ToPostHole) a then raise NotAValidPrimToken;
+ constr_of_globref true env sigma r
+ end
| Glob_term.GApp (gc, gcl) ->
- let sigma,c = constr_of_glob env sigma gc in
- let sigma,cl = List.fold_left_map (constr_of_glob env) sigma gcl in
- sigma,mkApp (c, Array.of_list cl)
+ let o = match DAst.get gc with
+ | Glob_term.GRef (r, _) -> List.find_opt (fun (_,r',_) -> GlobRef.equal r r') post
+ | _ -> None in
+ begin match o with
+ | None ->
+ let sigma,c = constr_of_glob allow_constant to_post post env sigma gc in
+ let sigma,cl = List.fold_left_map (constr_of_glob allow_constant to_post post env) sigma gcl in
+ sigma,mkApp (c, Array.of_list cl)
+ | Some (r, _, a) ->
+ let sigma,c = constr_of_globref true env sigma r in
+ let rec aux sigma a gcl = match a, gcl with
+ | [], [] -> sigma,[]
+ | ToPostCopy :: a, gc :: gcl ->
+ let sigma,c = constr_of_glob allow_constant [||] [] env sigma gc in
+ let sigma,cl = aux sigma a gcl in
+ sigma, c :: cl
+ | ToPostCheck r :: a, gc :: gcl ->
+ let () = match DAst.get gc with
+ | Glob_term.GRef (r', _) when GlobRef.equal r r' -> ()
+ | _ -> raise NotAValidPrimToken in
+ let sigma,c = constr_of_glob true [||] [] env sigma gc in
+ let sigma,cl = aux sigma a gcl in
+ sigma, c :: cl
+ | ToPostAs i :: a, gc :: gcl ->
+ let sigma,c = constr_of_glob allow_constant to_post to_post.(i) env sigma gc in
+ let sigma,cl = aux sigma a gcl in
+ sigma, c :: cl
+ | ToPostHole :: post, _ :: gcl -> aux sigma post gcl
+ | [], _ :: _ | _ :: _, [] -> raise NotAValidPrimToken
+ in
+ let sigma,cl = aux sigma a gcl in
+ sigma,mkApp (c, Array.of_list cl)
+ end
| Glob_term.GInt i -> sigma, mkInt i
| Glob_term.GSort gs ->
let sigma,c = Evd.fresh_sort_in_family sigma (Glob_ops.glob_sort_family gs) in
@@ -564,6 +680,10 @@ let rec constr_of_glob env sigma g = match DAst.get g with
| _ ->
raise NotAValidPrimToken
+let constr_of_glob to_post env sigma (Glob_term.AnyGlobConstr g) =
+ let post = match to_post with [||] -> [] | _ -> to_post.(0) in
+ constr_of_glob false to_post post env sigma g
+
let rec glob_of_constr token_kind ?loc env sigma c = match Constr.kind c with
| App (c, ca) ->
let c = glob_of_constr token_kind ?loc env sigma c in
@@ -585,9 +705,38 @@ let no_such_prim_token uninterpreted_token_kind ?loc ty =
(str ("Cannot interpret this "^uninterpreted_token_kind^" as a value of type ") ++
pr_qualid ty)
-let interp_option uninterpreted_token_kind token_kind ty ?loc env sigma c =
+let rec postprocess token_kind ?loc ty to_post post g =
+ let g', gl = match DAst.get g with Glob_term.GApp (g, gl) -> g, gl | _ -> g, [] in
+ let o =
+ match DAst.get g' with
+ | Glob_term.GRef (r, None) ->
+ List.find_opt (fun (r',_,_) -> GlobRef.equal r r') post
+ | _ -> None in
+ match o with None -> g | Some (_, r, a) ->
+ let rec f n a gl = match a, gl with
+ | [], [] -> []
+ | ToPostHole :: a, gl ->
+ let e = Evar_kinds.ImplicitArg (r, (n, None), true) in
+ let h = DAst.make ?loc (Glob_term.GHole (e, Namegen.IntroAnonymous, None)) in
+ h :: f (n+1) a gl
+ | (ToPostCopy | ToPostCheck _) :: a, g :: gl -> g :: f (n+1) a gl
+ | ToPostAs c :: a, g :: gl ->
+ postprocess token_kind ?loc ty to_post to_post.(c) g :: f (n+1) a gl
+ | [], _::_ | _::_, [] ->
+ no_such_prim_token token_kind ?loc ty
+ in
+ let gl = f 1 a gl in
+ let g = DAst.make ?loc (Glob_term.GRef (r, None)) in
+ DAst.make ?loc (Glob_term.GApp (g, gl))
+
+let glob_of_constr token_kind ty ?loc env sigma to_post c =
+ let g = glob_of_constr token_kind ?loc env sigma c in
+ match to_post with [||] -> g | _ ->
+ postprocess token_kind ?loc ty to_post to_post.(0) g
+
+let interp_option uninterpreted_token_kind token_kind ty ?loc env sigma to_post c =
match Constr.kind c with
- | App (_Some, [| _; c |]) -> glob_of_constr token_kind ?loc env sigma c
+ | App (_Some, [| _; c |]) -> glob_of_constr token_kind ty ?loc env sigma to_post c
| App (_None, [| _ |]) -> no_such_prim_token uninterpreted_token_kind ?loc ty
| x -> Loc.raise ?loc (PrimTokenNotationError(token_kind,env,sigma,UnexpectedNonOptionTerm c))
@@ -596,13 +745,13 @@ let uninterp_option c =
| App (_Some, [| _; x |]) -> x
| _ -> raise NotAValidPrimToken
-let uninterp to_raw o (Glob_term.AnyGlobConstr n) =
+let uninterp to_raw o n =
let env = Global.env () in
let sigma = Evd.from_env env in
let sigma,of_ty = Evd.fresh_global env sigma o.of_ty in
let of_ty = EConstr.Unsafe.to_constr of_ty in
try
- let sigma,n = constr_of_glob env sigma n in
+ let sigma,n = constr_of_glob o.to_post env sigma n in
let c = eval_constr_app env sigma of_ty n in
let c = if snd o.of_kind == Direct then c else uninterp_option c in
Some (to_raw (fst o.of_kind, c))
@@ -623,8 +772,8 @@ let rec int63_of_pos_bigint i =
(Uint63.mul (Uint63.of_int 2) (int63_of_pos_bigint quo))
else Uint63.mul (Uint63.of_int 2) (int63_of_pos_bigint quo)
-module Numeral = struct
-(** * Numeral notation *)
+module Numbers = struct
+(** * Number notation *)
open PrimTokenNotation
let warn_large_num =
@@ -680,7 +829,7 @@ let coqint_of_rawnum inds c (sign,n) =
let pos_neg = match sign with SPlus -> 1 | SMinus -> 2 in
mkApp (mkConstruct (ind, pos_neg), [|uint|])
-let coqnumeral_of_rawnum inds c n =
+let coqnumber_of_rawnum inds c n =
let ind = match c with CDec -> inds.decimal | CHex -> inds.hexadecimal in
let i, f, e = NumTok.Signed.to_int_frac_and_exponent n in
let i = coqint_of_rawnum inds.int c i in
@@ -692,19 +841,19 @@ let coqnumeral_of_rawnum inds c n =
mkApp (mkConstruct (ind, 2), [|i; f; e|]) (* (D|Hexad)ecimalExp *)
let mkDecHex ind c n = match c with
- | CDec -> mkApp (mkConstruct (ind, 1), [|n|]) (* (UInt|Int|)Dec *)
- | CHex -> mkApp (mkConstruct (ind, 2), [|n|]) (* (UInt|Int|)Hex *)
+ | CDec -> mkApp (mkConstruct (ind, 1), [|n|]) (* (UInt|Int|)Decimal *)
+ | CHex -> mkApp (mkConstruct (ind, 2), [|n|]) (* (UInt|Int|)Hexadecimal *)
exception NonDecimal
-let decimal_coqnumeral_of_rawnum inds n =
+let decimal_coqnumber_of_rawnum inds n =
if NumTok.Signed.classify n <> CDec then raise NonDecimal;
- coqnumeral_of_rawnum inds CDec n
+ coqnumber_of_rawnum inds CDec n
-let coqnumeral_of_rawnum inds n =
+let coqnumber_of_rawnum inds n =
let c = NumTok.Signed.classify n in
- let n = coqnumeral_of_rawnum inds c n in
- mkDecHex inds.numeral c n
+ let n = coqnumber_of_rawnum inds c n in
+ mkDecHex inds.number c n
let decimal_coquint_of_rawnum inds n =
if NumTok.UnsignedNat.classify n <> CDec then raise NonDecimal;
@@ -754,7 +903,7 @@ let rawnum_of_coqint cl c =
| _ -> raise NotAValidPrimToken)
| _ -> raise NotAValidPrimToken
-let rawnum_of_coqnumeral cl c =
+let rawnum_of_coqnumber cl c =
let of_ife i f e =
let n = rawnum_of_coqint cl i in
let f = try Some (rawnum_of_coquint cl f) with NotAValidPrimToken -> None in
@@ -768,17 +917,17 @@ let rawnum_of_coqnumeral cl c =
let destDecHex c = match Constr.kind c with
| App (c,[|c'|]) ->
(match Constr.kind c with
- | Construct ((_,1), _) (* (UInt|Int|)Dec *) -> CDec, c'
- | Construct ((_,2), _) (* (UInt|Int|)Hex *) -> CHex, c'
+ | Construct ((_,1), _) (* (UInt|Int|)Decimal *) -> CDec, c'
+ | Construct ((_,2), _) (* (UInt|Int|)Hexadecimal *) -> CHex, c'
| _ -> raise NotAValidPrimToken)
| _ -> raise NotAValidPrimToken
-let decimal_rawnum_of_coqnumeral c =
- rawnum_of_coqnumeral CDec c
+let decimal_rawnum_of_coqnumber c =
+ rawnum_of_coqnumber CDec c
-let rawnum_of_coqnumeral c =
+let rawnum_of_coqnumber c =
let cl, c = destDecHex c in
- rawnum_of_coqnumeral cl c
+ rawnum_of_coqnumber cl c
let decimal_rawnum_of_coquint c =
rawnum_of_coquint CDec c
@@ -900,9 +1049,9 @@ let interp o ?loc n =
interp_int63 ?loc (NumTok.SignedNat.to_bigint n)
| (Int _ | UInt _ | DecimalInt _ | DecimalUInt _ | Z _ | Int63), _ ->
no_such_prim_token "number" ?loc o.ty_name
- | Numeral numeral_ty, _ -> coqnumeral_of_rawnum numeral_ty n
- | Decimal numeral_ty, _ ->
- (try decimal_coqnumeral_of_rawnum numeral_ty n
+ | Number number_ty, _ -> coqnumber_of_rawnum number_ty n
+ | Decimal number_ty, _ ->
+ (try decimal_coqnumber_of_rawnum number_ty n
with NonDecimal -> no_such_prim_token "number" ?loc o.ty_name)
in
let env = Global.env () in
@@ -912,12 +1061,13 @@ let interp o ?loc n =
match o.warning, snd o.to_kind with
| Abstract threshold, Direct when NumTok.Signed.is_bigger_int_than n threshold ->
warn_abstract_large_num (o.ty_name,o.to_ty);
- glob_of_constr "numeral" ?loc env sigma (mkApp (to_ty,[|c|]))
+ assert (Array.length o.to_post = 0);
+ glob_of_constr "number" o.ty_name ?loc env sigma o.to_post (mkApp (to_ty,[|c|]))
| _ ->
let res = eval_constr_app env sigma to_ty c in
match snd o.to_kind with
- | Direct -> glob_of_constr "numeral" ?loc env sigma res
- | Option -> interp_option "number" "numeral" o.ty_name ?loc env sigma res
+ | Direct -> glob_of_constr "number" o.ty_name ?loc env sigma o.to_post res
+ | Option -> interp_option "number" "number" o.ty_name ?loc env sigma o.to_post res
let uninterp o n =
PrimTokenNotation.uninterp
@@ -926,10 +1076,10 @@ let uninterp o n =
| (UInt _, c) -> NumTok.Signed.of_nat (rawnum_of_coquint c)
| (Z _, c) -> NumTok.Signed.of_bigint CDec (bigint_of_z c)
| (Int63, c) -> NumTok.Signed.of_bigint CDec (bigint_of_int63 c)
- | (Numeral _, c) -> rawnum_of_coqnumeral c
+ | (Number _, c) -> rawnum_of_coqnumber c
| (DecimalInt _, c) -> NumTok.Signed.of_int (decimal_rawnum_of_coqint c)
| (DecimalUInt _, c) -> NumTok.Signed.of_nat (decimal_rawnum_of_coquint c)
- | (Decimal _, c) -> decimal_rawnum_of_coqnumeral c
+ | (Decimal _, c) -> decimal_rawnum_of_coqnumber c
end o n
end
@@ -962,11 +1112,12 @@ let coqbyte_of_string ?loc byte s =
let p =
if Int.equal (String.length s) 1 then int_of_char s.[0]
else
- if Int.equal (String.length s) 3 && is_digit s.[0] && is_digit s.[1] && is_digit s.[2]
- then int_of_string s
- else
+ let n =
+ if Int.equal (String.length s) 3 && is_digit s.[0] && is_digit s.[1] && is_digit s.[2]
+ then int_of_string s else 256 in
+ if n < 256 then n else
user_err ?loc ~hdr:"coqbyte_of_string"
- (str "Expects a single character or a three-digits ascii code.") in
+ (str "Expects a single character or a three-digit ASCII code.") in
coqbyte_of_char_code byte p
let coqbyte_of_char byte c = coqbyte_of_char_code byte (Char.code c)
@@ -1021,8 +1172,8 @@ let interp o ?loc n =
let to_ty = EConstr.Unsafe.to_constr to_ty in
let res = eval_constr_app env sigma to_ty c in
match snd o.to_kind with
- | Direct -> glob_of_constr "string" ?loc env sigma res
- | Option -> interp_option "string" "string" o.ty_name ?loc env sigma res
+ | Direct -> glob_of_constr "string" o.ty_name ?loc env sigma o.to_post res
+ | Option -> interp_option "string" "string" o.ty_name ?loc env sigma o.to_post res
let uninterp o n =
PrimTokenNotation.uninterp
@@ -1034,21 +1185,21 @@ end
(* A [prim_token_infos], which is synchronized with the document
state, either contains a unique id pointing to an unsynchronized
- prim token function, or a numeral notation object describing how to
+ prim token function, or a number notation object describing how to
interpret and uninterpret. We provide [prim_token_infos] because
we expect plugins to provide their own interpretation functions,
- rather than going through numeral notations, which are available as
+ rather than going through number notations, which are available as
a vernacular. *)
type prim_token_interp_info =
Uid of prim_token_uid
- | NumeralNotation of numeral_notation_obj
+ | NumberNotation of number_notation_obj
| StringNotation of string_notation_obj
type prim_token_infos = {
pt_local : bool; (** Is this interpretation local? *)
pt_scope : scope_name; (** Concerned scope *)
- pt_interp_info : prim_token_interp_info; (** Unique id "pointing" to (un)interp functions, OR a numeral notation object describing (un)interp functions *)
+ pt_interp_info : prim_token_interp_info; (** Unique id "pointing" to (un)interp functions, OR a number notation object describing (un)interp functions *)
pt_required : required_module; (** Module that should be loaded first *)
pt_refs : GlobRef.t list; (** Entry points during uninterpretation *)
pt_in_match : bool (** Is this prim token legal in match patterns ? *)
@@ -1072,7 +1223,7 @@ let hashtbl_check_and_set allow_overwrite uid f h eq =
| _ ->
user_err ~hdr:"prim_token_interpreter"
(str "Unique identifier " ++ str uid ++
- str " already used to register a numeral or string (un)interpreter.")
+ str " already used to register a number or string (un)interpreter.")
let register_gen_interpretation allow_overwrite uid (interp, uninterp) =
hashtbl_check_and_set
@@ -1100,7 +1251,6 @@ let cache_prim_token_interpretation (_,infos) =
String.Map.add sc (infos.pt_required,ptii) !prim_token_interp_infos;
let add_uninterp r =
let l = try GlobRef.Map.find r !prim_token_uninterp_infos with Not_found -> [] in
- let l = List.remove_assoc_f String.equal sc l in
prim_token_uninterp_infos :=
GlobRef.Map.add r ((sc,(ptii,infos.pt_in_match)) :: l)
!prim_token_uninterp_infos in
@@ -1173,7 +1323,7 @@ let check_required_module ?loc sc (sp,d) =
(str "Cannot interpret in " ++ str sc ++ str " without requiring first module " ++
str (List.last d) ++ str ".")
-(* Look if some notation or numeral printer in [scope] can be used in
+(* Look if some notation or number printer in [scope] can be used in
the scope stack [scopes], and if yes, using delimiters or not *)
let find_with_delimiters = function
@@ -1190,7 +1340,7 @@ let rec find_without_delimiters find (ntn_scope,ntn) = function
| NotationInScope scope' when String.equal scope scope' ->
Some (None,None)
| _ ->
- (* If the most recently open scope has a notation/numeral printer
+ (* If the most recently open scope has a notation/number printer
but not the expected one then we need delimiters *)
if find scope then
find_with_delimiters ntn_scope
@@ -1225,39 +1375,89 @@ let rec find_without_delimiters find (ntn_scope,ntn) = function
(* The mapping between notations and their interpretation *)
+let pr_optional_scope = function
+ | LastLonelyNotation -> mt ()
+ | NotationInScope scope -> spc () ++ strbrk "in scope" ++ spc () ++ str scope
+
let warn_notation_overridden =
CWarnings.create ~name:"notation-overridden" ~category:"parsing"
- (fun (ntn,which_scope) ->
+ (fun (scope,ntn) ->
str "Notation" ++ spc () ++ pr_notation ntn ++ spc ()
- ++ strbrk "was already used" ++ which_scope ++ str ".")
+ ++ strbrk "was already used" ++ pr_optional_scope scope ++ str ".")
-let declare_notation_interpretation ntn scopt pat df ~onlyprint deprecation =
- let scope = match scopt with Some s -> s | None -> default_scope in
- let sc = find_scope scope in
- if not onlyprint then begin
- let () =
- if NotationMap.mem ntn sc.notations then
- let which_scope = match scopt with
- | None -> mt ()
- | Some _ -> spc () ++ strbrk "in scope" ++ spc () ++ str scope in
- warn_notation_overridden (ntn,which_scope)
- in
- let notdata = {
- not_interp = pat;
- not_location = df;
- not_deprecation = deprecation;
- } in
- let sc = { sc with notations = NotationMap.add ntn notdata sc.notations } in
- scope_map := String.Map.add scope sc !scope_map
- end;
- begin match scopt with
- | None -> scope_stack := LonelyNotationItem ntn :: !scope_stack
- | Some _ -> ()
- end
+let warn_deprecation_overridden =
+ CWarnings.create ~name:"notation-overridden" ~category:"parsing"
+ (fun ((scope,ntn),old,now) ->
+ match old, now with
+ | None, None -> assert false
+ | None, Some _ ->
+ (str "Notation" ++ spc () ++ pr_notation ntn ++ pr_optional_scope scope ++ spc ()
+ ++ strbrk "is now marked as deprecated" ++ str ".")
+ | Some _, None ->
+ (str "Cancelling previous deprecation of notation" ++ spc () ++
+ pr_notation ntn ++ pr_optional_scope scope ++ str ".")
+ | Some _, Some _ ->
+ (str "Amending deprecation of notation" ++ spc () ++
+ pr_notation ntn ++ pr_optional_scope scope ++ str "."))
+
+type notation_use =
+ | OnlyPrinting
+ | OnlyParsing
+ | ParsingAndPrinting
+
+let warn_override_if_needed (scopt,ntn) overridden data old_data =
+ if overridden then warn_notation_overridden (scopt,ntn)
+ else
+ if data.not_deprecation <> old_data.not_deprecation then
+ warn_deprecation_overridden ((scopt,ntn),old_data.not_deprecation,data.not_deprecation)
+
+let check_parsing_override (scopt,ntn) data = function
+ | OnlyParsingData (_,old_data) ->
+ let overridden = not (interpretation_eq data.not_interp old_data.not_interp) in
+ warn_override_if_needed (scopt,ntn) overridden data old_data;
+ None, not overridden
+ | ParsingAndPrintingData (_,on_printing,old_data) ->
+ let overridden = not (interpretation_eq data.not_interp old_data.not_interp) in
+ warn_override_if_needed (scopt,ntn) overridden data old_data;
+ (if on_printing then Some old_data.not_interp else None), not overridden
+ | NoParsingData -> None, false
+
+let check_printing_override (scopt,ntn) data parsingdata printingdata =
+ let parsing_update = match parsingdata with
+ | OnlyParsingData _ | NoParsingData -> parsingdata
+ | ParsingAndPrintingData (_,on_printing,old_data) ->
+ let overridden = not (interpretation_eq data.not_interp old_data.not_interp) in
+ warn_override_if_needed (scopt,ntn) overridden data old_data;
+ if overridden then NoParsingData else parsingdata in
+ let exists = List.exists (fun (on_printing,old_data) ->
+ let exists = interpretation_eq data.not_interp old_data.not_interp in
+ if exists && data.not_deprecation <> old_data.not_deprecation then
+ warn_deprecation_overridden ((scopt,ntn),old_data.not_deprecation,data.not_deprecation);
+ exists) printingdata in
+ parsing_update, exists
+
+let remove_uninterpretation rule also_in_cases_pattern (metas,c as pat) =
+ let (key,n) = notation_constr_key c in
+ notations_key_table := keymap_remove key (also_in_cases_pattern,(rule,pat,n)) !notations_key_table
-let declare_uninterpretation rule (metas,c as pat) =
+let declare_uninterpretation ?(also_in_cases_pattern=true) rule (metas,c as pat) =
let (key,n) = notation_constr_key c in
- notations_key_table := keymap_add key (rule,pat,n) !notations_key_table
+ notations_key_table := keymap_add key (also_in_cases_pattern,(rule,pat,n)) !notations_key_table
+
+let update_notation_data (scopt,ntn) use data table =
+ let (parsingdata,printingdata) =
+ try NotationMap.find ntn table with Not_found -> (NoParsingData, []) in
+ match use with
+ | OnlyParsing ->
+ let printing_update, exists = check_parsing_override (scopt,ntn) data parsingdata in
+ NotationMap.add ntn (OnlyParsingData (true,data), printingdata) table, printing_update, exists
+ | ParsingAndPrinting ->
+ let printing_update, exists = check_parsing_override (scopt,ntn) data parsingdata in
+ NotationMap.add ntn (ParsingAndPrintingData (true,true,data), printingdata) table, printing_update, exists
+ | OnlyPrinting ->
+ let parsingdata, exists = check_printing_override (scopt,ntn) data parsingdata printingdata in
+ let printingdata = if exists then printingdata else (true,data) :: printingdata in
+ NotationMap.add ntn (parsingdata, printingdata) table, None, exists
let rec find_interpretation ntn find = function
| [] -> raise Not_found
@@ -1273,11 +1473,13 @@ let rec find_interpretation ntn find = function
find_interpretation ntn find scopes
let find_notation ntn sc =
- NotationMap.find ntn (find_scope sc).notations
+ match fst (NotationMap.find ntn (find_scope sc).notations) with
+ | OnlyParsingData (true,data) | ParsingAndPrintingData (true,_,data) -> data
+ | _ -> raise Not_found
let notation_of_prim_token = function
- | Constrexpr.Numeral (SPlus,n) -> InConstrEntry, NumTok.Unsigned.sprint n
- | Constrexpr.Numeral (SMinus,n) -> InConstrEntry, "- "^NumTok.Unsigned.sprint n
+ | Constrexpr.Number (SPlus,n) -> InConstrEntry, NumTok.Unsigned.sprint n
+ | Constrexpr.Number (SMinus,n) -> InConstrEntry, "- "^NumTok.Unsigned.sprint n
| String _ -> raise Not_found
let find_prim_token check_allowed ?loc p sc =
@@ -1295,7 +1497,7 @@ let find_prim_token check_allowed ?loc p sc =
check_required_module ?loc sc spdir;
let interp = match info with
| Uid uid -> Hashtbl.find prim_token_interpreters uid
- | NumeralNotation o -> InnerPrimToken.RawNumInterp (Numeral.interp o)
+ | NumberNotation o -> InnerPrimToken.RawNumInterp (Numbers.interp o)
| StringNotation o -> InnerPrimToken.StringInterp (Strings.interp o)
in
let pat = InnerPrimToken.do_interp ?loc interp p in
@@ -1312,8 +1514,8 @@ let interp_prim_token_gen ?loc g p local_scopes =
let _, info = Exninfo.capture exn in
user_err ?loc ~info ~hdr:"interp_prim_token"
((match p with
- | Numeral _ ->
- str "No interpretation for numeral " ++ pr_notation (notation_of_prim_token p)
+ | Number _ ->
+ str "No interpretation for number " ++ pr_notation (notation_of_prim_token p)
| String s -> str "No interpretation for string " ++ qs s) ++ str ".")
let interp_prim_token ?loc =
@@ -1349,19 +1551,49 @@ let interp_notation ?loc ntn local_scopes =
(str "Unknown interpretation for notation " ++ pr_notation ntn ++ str ".")
let uninterp_notations c =
- List.map_append (fun key -> keymap_find key !notations_key_table)
+ List.map_append (fun key -> List.map snd (keymap_find key !notations_key_table))
(glob_constr_keys c)
+let filter_also_for_pattern =
+ List.map_filter (function (true,x) -> Some x | _ -> None)
+
let uninterp_cases_pattern_notations c =
- keymap_find (cases_pattern_key c) !notations_key_table
+ filter_also_for_pattern (keymap_find (cases_pattern_key c) !notations_key_table)
let uninterp_ind_pattern_notations ind =
- keymap_find (RefKey (canonical_gr (GlobRef.IndRef ind))) !notations_key_table
+ filter_also_for_pattern (keymap_find (RefKey (canonical_gr (GlobRef.IndRef ind))) !notations_key_table)
+
+let has_active_parsing_rule_in_scope ntn sc =
+ try
+ match NotationMap.find ntn (String.Map.find sc !scope_map).notations with
+ | OnlyParsingData (active,_),_ | ParsingAndPrintingData (active,_,_),_ -> active
+ | _ -> false
+ with Not_found -> false
+
+let is_printing_active_in_scope (scope,ntn) pat =
+ let sc = match scope with NotationInScope sc -> sc | LastLonelyNotation -> default_scope in
+ let is_active extra =
+ try
+ let (_,(active,_)) = List.extract_first (fun (active,d) -> interpretation_eq d.not_interp pat) extra in
+ active
+ with Not_found -> false in
+ try
+ match NotationMap.find ntn (String.Map.find sc !scope_map).notations with
+ | ParsingAndPrintingData (_,active,d), extra ->
+ if interpretation_eq d.not_interp pat then active
+ else is_active extra
+ | _, extra -> is_active extra
+ with Not_found -> false
+
+let is_printing_inactive_rule rule pat =
+ match rule with
+ | NotationRule (scope,ntn) ->
+ not (is_printing_active_in_scope (scope,ntn) pat)
+ | SynDefRule kn ->
+ try let _ = Nametab.path_of_syndef kn in false with Not_found -> true
let availability_of_notation (ntn_scope,ntn) scopes =
- let f scope =
- NotationMap.mem ntn (String.Map.find scope !scope_map).notations in
- find_without_delimiters f (ntn_scope,Some ntn) (make_current_scopes scopes)
+ find_without_delimiters (has_active_parsing_rule_in_scope ntn) (ntn_scope,Some ntn) (make_current_scopes scopes)
(* We support coercions from a custom entry at some level to an entry
at some level (possibly the same), and from and to the constr entry. E.g.:
@@ -1484,20 +1716,63 @@ let entry_has_ident = function
| InCustomEntryLevel (s,n) ->
try String.Map.find s !entry_has_ident_map <= n with Not_found -> false
+type entry_coercion_kind =
+ | IsEntryCoercion of notation_entry_level
+ | IsEntryGlobal of string * int
+ | IsEntryIdent of string * int
+
+let declare_notation (scopt,ntn) pat df ~use ~also_in_cases_pattern coe deprecation =
+ (* Register the interpretation *)
+ let scope = match scopt with NotationInScope s -> s | LastLonelyNotation -> default_scope in
+ let sc = find_scope scope in
+ let notdata = {
+ not_interp = pat;
+ not_location = df;
+ not_deprecation = deprecation;
+ } in
+ let notation_update,printing_update, exists = update_notation_data (scopt,ntn) use notdata sc.notations in
+ if not exists then
+ let sc = { sc with notations = notation_update } in
+ scope_map := String.Map.add scope sc !scope_map;
+ (* Update the uninterpretation cache *)
+ begin match printing_update with
+ | Some pat -> remove_uninterpretation (NotationRule (scopt,ntn)) also_in_cases_pattern pat
+ | None -> ()
+ end;
+ if not exists && use <> OnlyParsing then declare_uninterpretation ~also_in_cases_pattern (NotationRule (scopt,ntn)) pat;
+ (* Register visibility of lonely notations *)
+ if not exists then begin match scopt with
+ | LastLonelyNotation -> scope_stack := LonelyNotationItem ntn :: !scope_stack
+ | NotationInScope _ -> ()
+ end;
+ (* Declare a possible coercion *)
+ if not exists then begin match coe with
+ | Some (IsEntryCoercion entry) ->
+ let (_,level,_) = level_of_notation ntn in
+ let level = match fst ntn with
+ | InConstrEntry -> None
+ | InCustomEntry _ -> Some level
+ in
+ declare_entry_coercion (scopt,ntn) level entry
+ | Some (IsEntryGlobal (entry,n)) -> declare_custom_entry_has_global entry n
+ | Some (IsEntryIdent (entry,n)) -> declare_custom_entry_has_ident entry n
+ | None -> ()
+ end
+
let availability_of_prim_token n printer_scope local_scopes =
let f scope =
try
let uid = snd (String.Map.find scope !prim_token_interp_infos) in
let open InnerPrimToken in
match n, uid with
- | Constrexpr.Numeral _, NumeralNotation _ -> true
- | _, NumeralNotation _ -> false
+ | Constrexpr.Number _, NumberNotation _ -> true
+ | _, NumberNotation _ -> false
| String _, StringNotation _ -> true
| _, StringNotation _ -> false
| _, Uid uid ->
let interp = Hashtbl.find prim_token_interpreters uid in
match n, interp with
- | Constrexpr.Numeral _, (RawNumInterp _ | BigNumInterp _) -> true
+ | Constrexpr.Number _, (RawNumInterp _ | BigNumInterp _) -> true
| String _, StringInterp _ -> true
| _ -> false
with Not_found -> false
@@ -1512,7 +1787,7 @@ let rec find_uninterpretation need_delim def find = function
def
| OpenScopeItem scope :: scopes ->
(try find need_delim scope
- with Not_found -> find_uninterpretation need_delim def find scopes) (* TODO: here we should also update the need_delim list with all regular notations in scope [scope] that could shadow a numeral notation *)
+ with Not_found -> find_uninterpretation need_delim def find scopes) (* TODO: here we should also update the need_delim list with all regular notations in scope [scope] that could shadow a number notation *)
| LonelyNotationItem ntn::scopes ->
find_uninterpretation (ntn::need_delim) def find scopes
@@ -1524,7 +1799,7 @@ let uninterp_prim_token c local_scopes =
try
let uninterp = match info with
| Uid uid -> Hashtbl.find prim_token_uninterpreters uid
- | NumeralNotation o -> InnerPrimToken.RawNumUninterp (Numeral.uninterp o)
+ | NumberNotation o -> InnerPrimToken.RawNumUninterp (Numbers.uninterp o)
| StringNotation o -> InnerPrimToken.StringUninterp (Strings.uninterp o)
in
match InnerPrimToken.do_uninterp uninterp (AnyGlobConstr c) with
@@ -1561,38 +1836,6 @@ let uninterp_prim_token_cases_pattern c local_scopes =
(* Miscellaneous *)
-let pair_eq f g (x1, y1) (x2, y2) = f x1 x2 && g y1 y2
-
-let notation_binder_source_eq s1 s2 = match s1, s2 with
-| NtnParsedAsIdent, NtnParsedAsIdent -> true
-| NtnParsedAsPattern b1, NtnParsedAsPattern b2 -> b1 = b2
-| NtnBinderParsedAsConstr bk1, NtnBinderParsedAsConstr bk2 -> bk1 = bk2
-| (NtnParsedAsIdent | NtnParsedAsPattern _ | NtnBinderParsedAsConstr _), _ -> false
-
-let ntpe_eq t1 t2 = match t1, t2 with
-| NtnTypeConstr, NtnTypeConstr -> true
-| NtnTypeBinder s1, NtnTypeBinder s2 -> notation_binder_source_eq s1 s2
-| NtnTypeConstrList, NtnTypeConstrList -> true
-| NtnTypeBinderList, NtnTypeBinderList -> true
-| (NtnTypeConstr | NtnTypeBinder _ | NtnTypeConstrList | NtnTypeBinderList), _ -> false
-
-let var_attributes_eq (_, ((entry1, sc1), tp1)) (_, ((entry2, sc2), tp2)) =
- notation_entry_level_eq entry1 entry2 &&
- pair_eq (Option.equal String.equal) (List.equal String.equal) sc1 sc2 &&
- ntpe_eq tp1 tp2
-
-let interpretation_eq (vars1, t1) (vars2, t2) =
- List.equal var_attributes_eq vars1 vars2 &&
- Notation_ops.eq_notation_constr (List.map fst vars1, List.map fst vars2) t1 t2
-
-let exists_notation_in_scope scopt ntn onlyprint r =
- let scope = match scopt with Some s -> s | None -> default_scope in
- try
- let sc = String.Map.find scope !scope_map in
- let n = NotationMap.find ntn sc.notations in
- interpretation_eq n.not_interp r
- with Not_found -> false
-
let isNVar_or_NHole = function NVar _ | NHole _ -> true | _ -> false
(**********************************************************************)
@@ -1846,38 +2089,63 @@ let pr_scope_classes sc =
| _ :: ll ->
let opt_s = match ll with [] -> mt () | _ -> str "es" in
hov 0 (str "Bound to class" ++ opt_s ++
- spc() ++ prlist_with_sep spc pr_scope_class l) ++ fnl()
+ spc() ++ prlist_with_sep spc pr_scope_class l)
let pr_notation_info prglob ntn c =
- str "\"" ++ str ntn ++ str "\" := " ++
+ str "\"" ++ str ntn ++ str "\" :=" ++ brk (1,2) ++
prglob (Notation_ops.glob_constr_of_notation_constr c)
-let pr_named_scope prglob scope sc =
+let pr_notation_status on_parsing on_printing =
+ let deactivated b = if b then [] else ["deactivated"] in
+ let l = match on_parsing, on_printing with
+ | Some on, None -> "only parsing" :: deactivated on
+ | None, Some on -> "only printing" :: deactivated on
+ | Some false, Some false -> ["deactivated"]
+ | Some true, Some false -> ["deactivated for printing"]
+ | Some false, Some true -> ["deactivated for parsing"]
+ | Some true, Some true -> []
+ | None, None -> assert false in
+ match l with
+ | [] -> mt ()
+ | l -> str "(" ++ prlist_with_sep pr_comma str l ++ str ")"
+
+let pr_non_empty spc pp =
+ if pp = mt () then mt () else spc ++ pp
+
+let pr_notation_data prglob (on_parsing,on_printing,{ not_interp = (_, r); not_location = (_, df) }) =
+ hov 0 (pr_notation_info prglob df r ++ pr_non_empty (brk(1,2)) (pr_notation_status on_parsing on_printing))
+
+let extract_notation_data (main,extra) =
+ let main = match main with
+ | NoParsingData -> []
+ | ParsingAndPrintingData (on_parsing, on_printing, d) ->
+ [Some on_parsing, Some on_printing, d]
+ | OnlyParsingData (on_parsing, d) ->
+ [Some on_parsing, None, d] in
+ let extra = List.map (fun (on_printing, d) -> (None, Some on_printing, d)) extra in
+ main @ extra
+
+let pr_named_scope prglob (scope,sc) =
(if String.equal scope default_scope then
match NotationMap.cardinal sc.notations with
| 0 -> str "No lonely notation"
| n -> str "Lonely notation" ++ (if Int.equal n 1 then mt() else str"s")
else
str "Scope " ++ str scope ++ fnl () ++ pr_delimiters_info sc.delimiters)
- ++ fnl ()
- ++ pr_scope_classes scope
- ++ NotationMap.fold
- (fun ntn { not_interp = (_, r); not_location = (_, df) } strm ->
- pr_notation_info prglob df r ++ fnl () ++ strm)
- sc.notations (mt ())
+ ++ pr_non_empty (fnl ()) (pr_scope_classes scope)
+ ++ prlist (fun a -> fnl () ++ pr_notation_data prglob a)
+ (NotationMap.fold (fun ntn data l -> extract_notation_data data @ l) sc.notations [])
-let pr_scope prglob scope = pr_named_scope prglob scope (find_scope scope)
+let pr_scope prglob scope = pr_named_scope prglob (scope, find_scope scope)
let pr_scopes prglob =
- String.Map.fold
- (fun scope sc strm -> pr_named_scope prglob scope sc ++ fnl () ++ strm)
- !scope_map (mt ())
+ let l = String.Map.bindings !scope_map in
+ prlist_with_sep (fun () -> fnl () ++ fnl ()) (pr_named_scope prglob) l
let rec find_default ntn = function
| [] -> None
| OpenScopeItem scope :: scopes ->
- if NotationMap.mem ntn (find_scope scope).notations then
- Some scope
+ if has_active_parsing_rule_in_scope ntn scope then Some scope
else find_default ntn scopes
| LonelyNotationItem ntn' :: scopes ->
if notation_eq ntn ntn' then Some default_scope
@@ -1885,12 +2153,12 @@ let rec find_default ntn = function
let factorize_entries = function
| [] -> []
- | (ntn,c)::l ->
+ | (ntn,sc',c)::l ->
let (ntn,l_of_ntn,rest) =
List.fold_left
- (fun (a',l,rest) (a,c) ->
- if notation_eq a a' then (a',c::l,rest) else (a,[c],(a',l)::rest))
- (ntn,[c],[]) l in
+ (fun (a',l,rest) (a,sc,c) ->
+ if notation_eq a a' then (a',(sc,c)::l,rest) else (a,[sc,c],(a',l)::rest))
+ (ntn,[sc',c],[]) l in
(ntn,l_of_ntn)::rest
type symbol_token = WhiteSpace of int | String of string
@@ -1961,16 +2229,18 @@ let browse_notation strict ntn map =
let l =
String.Map.fold
(fun scope_name sc ->
- NotationMap.fold (fun ntn { not_interp = (_, r); not_location = df } l ->
- if List.exists (find ntn) ntns then (ntn,(scope_name,r,df))::l else l) sc.notations)
+ NotationMap.fold (fun ntn data l ->
+ if List.exists (find ntn) ntns
+ then List.map (fun d -> (ntn,scope_name,d)) (extract_notation_data data) @ l
+ else l) sc.notations)
map [] in
- List.sort (fun x y -> String.compare (snd (fst x)) (snd (fst y))) l
+ List.sort (fun x y -> String.compare (snd (pi1 x)) (snd (pi1 y))) l
-let global_reference_of_notation ~head test (ntn,(sc,c,_)) =
+let global_reference_of_notation ~head test (ntn,sc,(on_parsing,on_printing,{not_interp = (_,c)})) =
match c with
- | NRef ref when test ref -> Some (ntn,sc,ref)
+ | NRef ref when test ref -> Some (on_parsing,on_printing,ntn,sc,ref)
| NApp (NRef ref, l) when head || List.for_all isNVar_or_NHole l && test ref ->
- Some (ntn,sc,ref)
+ Some (on_parsing,on_printing,ntn,sc,ref)
| _ -> None
let error_ambiguous_notation ?loc _ntn =
@@ -1990,17 +2260,17 @@ let interp_notation_as_global_reference ?loc ~head test ntn sc =
let ntns = browse_notation true ntn scopes in
let refs = List.map (global_reference_of_notation ~head test) ntns in
match Option.List.flatten refs with
- | [_,_,ref] -> ref
+ | [Some true,_ (* why not if the only one? *),_,_,ref] -> ref
| [] -> error_notation_not_reference ?loc ntn
| refs ->
- let f (ntn,sc,ref) =
+ let f (on_parsing,_,ntn,sc,ref) =
let def = find_default ntn !scope_stack in
match def with
| None -> false
- | Some sc' -> String.equal sc sc'
+ | Some sc' -> on_parsing = Some true && String.equal sc sc'
in
match List.filter f refs with
- | [_,_,ref] -> ref
+ | [_,_,_,_,ref] -> ref
| [] -> error_notation_not_reference ?loc ntn
| _ -> error_ambiguous_notation ?loc ntn
@@ -2010,24 +2280,25 @@ let locate_notation prglob ntn scope =
match ntns with
| [] -> str "Unknown notation"
| _ ->
- str "Notation" ++ fnl () ++
prlist_with_sep fnl (fun (ntn,l) ->
let scope = find_default ntn scopes in
prlist_with_sep fnl
- (fun (sc,r,(_,df)) ->
+ (fun (sc,(on_parsing,on_printing,{ not_interp = (_, r); not_location = (_, df) })) ->
hov 0 (
+ str "Notation" ++ brk (1,2) ++
pr_notation_info prglob df r ++
(if String.equal sc default_scope then mt ()
- else (spc () ++ str ": " ++ str sc)) ++
+ else (brk (1,2) ++ str ": " ++ str sc)) ++
(if Option.equal String.equal (Some sc) scope
- then spc () ++ str "(default interpretation)" else mt ())))
+ then brk (1,2) ++ str "(default interpretation)" else mt ()) ++
+ pr_non_empty (brk (1,2)) (pr_notation_status on_parsing on_printing)))
l) ntns
let collect_notation_in_scope scope sc known =
assert (not (String.equal scope default_scope));
NotationMap.fold
- (fun ntn { not_interp = (_, r); not_location = (_, df) } (l,known as acc) ->
- if List.mem_f notation_eq ntn known then acc else ((df,r)::l,ntn::known))
+ (fun ntn d (l,known as acc) ->
+ if List.mem_f notation_eq ntn known then acc else (extract_notation_data d @ l,ntn::known))
sc.notations ([],known)
let collect_notations stack =
@@ -2043,13 +2314,13 @@ let collect_notations stack =
if List.mem_f notation_eq ntn knownntn then (all,knownntn)
else
try
- let { not_interp = (_, r); not_location = (_, df) } =
- NotationMap.find ntn (find_scope default_scope).notations in
+ let datas = extract_notation_data
+ (NotationMap.find ntn (find_scope default_scope).notations) in
let all' = match all with
| (s,lonelyntn)::rest when String.equal s default_scope ->
- (s,(df,r)::lonelyntn)::rest
+ (s,datas@lonelyntn)::rest
| _ ->
- (default_scope,[df,r])::all in
+ (default_scope,datas)::all in
(all',ntn::knownntn)
with Not_found -> (* e.g. if only printing *) (all,knownntn))
([],[]) stack)
@@ -2057,7 +2328,7 @@ let collect_notations stack =
let pr_visible_in_scope prglob (scope,ntns) =
let strm =
List.fold_right
- (fun (df,r) strm -> pr_notation_info prglob df r ++ fnl () ++ strm)
+ (fun d strm -> pr_notation_data prglob d ++ fnl () ++ strm)
ntns (mt ()) in
(if String.equal scope default_scope then
str "Lonely notation" ++ (match ntns with [_] -> mt () | _ -> str "s")
@@ -2066,9 +2337,7 @@ let pr_visible_in_scope prglob (scope,ntns) =
++ fnl () ++ strm
let pr_scope_stack prglob stack =
- List.fold_left
- (fun strm scntns -> strm ++ pr_visible_in_scope prglob scntns ++ fnl ())
- (mt ()) (collect_notations stack)
+ prlist_with_sep fnl (pr_visible_in_scope prglob) (collect_notations stack)
let pr_visibility prglob = function
| Some scope -> pr_scope_stack prglob (push_scope scope !scope_stack)
diff --git a/interp/notation.mli b/interp/notation.mli
index 948831b317..b8939ff87b 100644
--- a/interp/notation.mli
+++ b/interp/notation.mli
@@ -74,7 +74,7 @@ val find_delimiters_scope : ?loc:Loc.t -> delimiters -> scope_name
(** {6 Declare and uses back and forth an interpretation of primitive token } *)
-(** A numeral interpreter is the pair of an interpreter for **(hexa)decimal**
+(** A number interpreter is the pair of an interpreter for **(hexa)decimal**
numbers in terms and an optional interpreter in pattern, if
non integer or negative numbers are not supported, the interpreter
must fail with an appropriate error message *)
@@ -84,7 +84,7 @@ type required_module = full_path * string list
type rawnum = NumTok.Signed.t
(** The unique id string below will be used to refer to a particular
- registered interpreter/uninterpreter of numeral or string notation.
+ registered interpreter/uninterpreter of number or string notation.
Using the same uid for different (un)interpreters will fail.
If at most one interpretation of prim token is used per scope,
then the scope name could be used as unique id. *)
@@ -106,7 +106,7 @@ val register_bignumeral_interpretation :
val register_string_interpretation :
?allow_overwrite:bool -> prim_token_uid -> string prim_token_interpretation -> unit
-(** * Numeral notation *)
+(** * Number notation *)
type prim_token_notation_error =
| UnexpectedTerm of Constr.t
@@ -131,21 +131,21 @@ type z_pos_ty =
{ z_ty : Names.inductive;
pos_ty : Names.inductive }
-type numeral_ty =
+type number_ty =
{ int : int_ty;
decimal : Names.inductive;
hexadecimal : Names.inductive;
- numeral : Names.inductive }
+ number : Names.inductive }
type target_kind =
- | Int of int_ty (* Coq.Init.Numeral.int + uint *)
- | UInt of int_ty (* Coq.Init.Numeral.uint *)
+ | Int of int_ty (* Coq.Init.Number.int + uint *)
+ | UInt of int_ty (* Coq.Init.Number.uint *)
| Z of z_pos_ty (* Coq.Numbers.BinNums.Z and positive *)
| Int63 (* Coq.Numbers.Cyclic.Int63.Int63.int *)
- | Numeral of numeral_ty (* Coq.Init.Numeral.numeral + uint + int *)
+ | Number of number_ty (* Coq.Init.Number.number + uint + int *)
| DecimalInt of int_ty (* Coq.Init.Decimal.int + uint (deprecated) *)
| DecimalUInt of int_ty (* Coq.Init.Decimal.uint (deprecated) *)
- | Decimal of numeral_ty (* Coq.Init.Decimal.Decimal + uint + int (deprecated) *)
+ | Decimal of number_ty (* Coq.Init.Decimal.Decimal + uint + int (deprecated) *)
type string_target_kind =
| ListByte
@@ -154,26 +154,43 @@ type string_target_kind =
type option_kind = Option | Direct
type 'target conversion_kind = 'target * option_kind
+(** A postprocessing translation [to_post] can be done after execution
+ of the [to_ty] interpreter. The reverse translation is performed
+ before the [of_ty] uninterpreter.
+
+ [to_post] is an array of [n] lists [l_i] of tuples [(f, t,
+ args)]. When the head symbol of the translated term matches one of
+ the [f] in the list [l_0] it is replaced by [t] and its arguments
+ are translated acording to [args] where [ToPostCopy] means that the
+ argument is kept unchanged and [ToPostAs k] means that the
+ argument is recursively translated according to [l_k].
+ [ToPostHole] introduces an additional implicit argument hole
+ (in the reverse translation, the corresponding argument is removed).
+ [ToPostCheck r] behaves as [ToPostCopy] except in the reverse
+ translation which fails if the copied term is not [r].
+ When [n] is null, no translation is performed. *)
+type to_post_arg = ToPostCopy | ToPostAs of int | ToPostHole | ToPostCheck of GlobRef.t
type ('target, 'warning) prim_token_notation_obj =
{ to_kind : 'target conversion_kind;
to_ty : GlobRef.t;
+ to_post : ((GlobRef.t * GlobRef.t * to_post_arg list) list) array;
of_kind : 'target conversion_kind;
of_ty : GlobRef.t;
ty_name : Libnames.qualid; (* for warnings / error messages *)
warning : 'warning }
-type numeral_notation_obj = (target_kind, numnot_option) prim_token_notation_obj
+type number_notation_obj = (target_kind, numnot_option) prim_token_notation_obj
type string_notation_obj = (string_target_kind, unit) prim_token_notation_obj
type prim_token_interp_info =
Uid of prim_token_uid
- | NumeralNotation of numeral_notation_obj
+ | NumberNotation of number_notation_obj
| StringNotation of string_notation_obj
type prim_token_infos = {
pt_local : bool; (** Is this interpretation local? *)
pt_scope : scope_name; (** Concerned scope *)
- pt_interp_info : prim_token_interp_info; (** Unique id "pointing" to (un)interp functions, OR a numeral notation object describing (un)interp functions *)
+ pt_interp_info : prim_token_interp_info; (** Unique id "pointing" to (un)interp functions, OR a number notation object describing (un)interp functions *)
pt_required : required_module; (** Module that should be loaded first *)
pt_refs : GlobRef.t list; (** Entry points during uninterpretation *)
pt_in_match : bool (** Is this prim token legal in match patterns ? *)
@@ -229,11 +246,24 @@ type interp_rule =
| NotationRule of specific_notation
| SynDefRule of KerName.t
-val declare_notation_interpretation : notation -> scope_name option ->
- interpretation -> notation_location -> onlyprint:bool ->
+type notation_use =
+ | OnlyPrinting
+ | OnlyParsing
+ | ParsingAndPrinting
+
+val declare_uninterpretation : ?also_in_cases_pattern:bool -> interp_rule -> interpretation -> unit
+
+type entry_coercion_kind =
+ | IsEntryCoercion of notation_entry_level
+ | IsEntryGlobal of string * int
+ | IsEntryIdent of string * int
+
+val declare_notation : notation_with_optional_scope * notation ->
+ interpretation -> notation_location -> use:notation_use ->
+ also_in_cases_pattern:bool ->
+ entry_coercion_kind option ->
Deprecation.t option -> unit
-val declare_uninterpretation : interp_rule -> interpretation -> unit
(** Return the interpretation bound to a notation *)
val interp_notation : ?loc:Loc.t -> notation -> subscopes ->
@@ -257,16 +287,14 @@ val uninterp_ind_pattern_notations : inductive -> notation_rule list
val availability_of_notation : specific_notation -> subscopes ->
(scope_name option * delimiters option) option
+val is_printing_inactive_rule : interp_rule -> interpretation -> bool
+
(** {6 Miscellaneous} *)
(** If head is true, also allows applied global references. *)
val interp_notation_as_global_reference : ?loc:Loc.t -> head:bool -> (GlobRef.t -> bool) ->
notation_key -> delimiters option -> GlobRef.t
-(** Checks for already existing notations *)
-val exists_notation_in_scope : scope_name option -> notation ->
- bool -> interpretation -> bool
-
(** Declares and looks for scopes associated to arguments of a global ref *)
val declare_arguments_scope :
bool (** true=local *) -> GlobRef.t -> scope_name option list -> unit
diff --git a/interp/notation_ops.ml b/interp/notation_ops.ml
index 22531b0016..2e3fa0aa0e 100644
--- a/interp/notation_ops.ml
+++ b/interp/notation_ops.ml
@@ -27,7 +27,9 @@ open Notation_term
(* helper for NVar, NVar case in eq_notation_constr *)
let get_var_ndx id vs = try Some (List.index Id.equal id vs) with Not_found -> None
-let rec eq_notation_constr (vars1,vars2 as vars) t1 t2 = match t1, t2 with
+let rec eq_notation_constr (vars1,vars2 as vars) t1 t2 =
+(vars1 == vars2 && t1 == t2) ||
+match t1, t2 with
| NRef gr1, NRef gr2 -> GlobRef.equal gr1 gr2
| NVar id1, NVar id2 -> (
match (get_var_ndx id1 vars1,get_var_ndx id2 vars2) with
@@ -56,7 +58,7 @@ let rec eq_notation_constr (vars1,vars2 as vars) t1 t2 = match t1, t2 with
(eq_notation_constr vars) t1 t2
in
let eqf (t1, (na1, o1)) (t2, (na2, o2)) =
- let eq (i1, n1) (i2, n2) = eq_ind i1 i2 && List.equal Name.equal n1 n2 in
+ let eq (i1, n1) (i2, n2) = Ind.CanOrd.equal i1 i2 && List.equal Name.equal n1 n2 in
(eq_notation_constr vars) t1 t2 && Name.equal na1 na2 && Option.equal eq o1 o2
in
Option.equal (eq_notation_constr vars) o1 o2 &&
@@ -799,7 +801,7 @@ let rec fold_cases_pattern_eq f x p p' =
let loc = p.CAst.loc in
match DAst.get p, DAst.get p' with
| PatVar na, PatVar na' -> let x,na = f x na na' in x, DAst.make ?loc @@ PatVar na
- | PatCstr (c,l,na), PatCstr (c',l',na') when eq_constructor c c' ->
+ | PatCstr (c,l,na), PatCstr (c',l',na') when Construct.CanOrd.equal c c' ->
let x,l = fold_cases_pattern_list_eq f x l l' in
let x,na = f x na na' in
x, DAst.make ?loc @@ PatCstr (c,l,na)
@@ -816,7 +818,7 @@ and fold_cases_pattern_list_eq f x pl pl' = match pl, pl' with
let rec cases_pattern_eq p1 p2 = match DAst.get p1, DAst.get p2 with
| PatVar na1, PatVar na2 -> Name.equal na1 na2
| PatCstr (c1, pl1, na1), PatCstr (c2, pl2, na2) ->
- eq_constructor c1 c2 && List.equal cases_pattern_eq pl1 pl2 &&
+ Construct.CanOrd.equal c1 c2 && List.equal cases_pattern_eq pl1 pl2 &&
Name.equal na1 na2
| _ -> false
@@ -939,7 +941,7 @@ let bind_term_as_binding_env alp (terms,termlists,binders,binderlists as sigma)
try
(* If already bound to a term, unify the binder and the term *)
match DAst.get (Id.List.assoc var terms) with
- | GVar id' ->
+ | GVar id' | GRef (GlobRef.VarRef id',None) ->
(if not (Id.equal id id') then (fst alp,(id,id')::snd alp) else alp),
sigma
| t ->
@@ -1039,7 +1041,7 @@ let rec match_cases_pattern_binders allow_catchall metas (alp,sigma as acc) pat1
| PatVar na1, PatVar na2 -> match_names metas acc na1 na2
| _, PatVar Anonymous when allow_catchall -> acc
| PatCstr (c1,patl1,na1), PatCstr (c2,patl2,na2)
- when eq_constructor c1 c2 && Int.equal (List.length patl1) (List.length patl2) ->
+ when Construct.CanOrd.equal c1 c2 && Int.equal (List.length patl1) (List.length patl2) ->
List.fold_left2 (match_cases_pattern_binders false metas)
(match_names metas acc na1 na2) patl1 patl2
| _ -> raise No_match
@@ -1145,16 +1147,22 @@ let does_not_come_from_already_eta_expanded_var glob =
(* checked). *)
match DAst.get glob with GVar _ -> false | _ -> true
+let is_var_term = function
+ (* The kind of expressions allowed to be both a term and a binding variable *)
+ | GVar _ -> true
+ | GRef (GlobRef.VarRef _,None) -> true
+ | _ -> false
+
let rec match_ inner u alp metas sigma a1 a2 =
let open CAst in
let loc = a1.loc in
match DAst.get a1, a2 with
(* Matching notation variable *)
| r1, NVar id2 when is_term_meta id2 metas -> bind_term_env alp sigma id2 a1
- | GVar _, NVar id2 when is_onlybinding_pattern_like_meta true id2 metas -> bind_binding_as_term_env alp sigma id2 a1
+ | r1, NVar id2 when is_var_term r1 && is_onlybinding_pattern_like_meta true id2 metas -> bind_binding_as_term_env alp sigma id2 a1
| r1, NVar id2 when is_onlybinding_pattern_like_meta false id2 metas -> bind_binding_as_term_env alp sigma id2 a1
- | GVar _, NVar id2 when is_onlybinding_strict_meta id2 metas -> raise No_match
- | GVar _, NVar id2 when is_onlybinding_meta id2 metas -> bind_binding_as_term_env alp sigma id2 a1
+ | r1, NVar id2 when is_var_term r1 && is_onlybinding_strict_meta id2 metas -> raise No_match
+ | r1, NVar id2 when is_var_term r1 && is_onlybinding_meta id2 metas -> bind_binding_as_term_env alp sigma id2 a1
| r1, NVar id2 when is_bindinglist_meta id2 metas -> bind_term_env alp sigma id2 a1
(* Matching recursive notations for terms *)
@@ -1389,11 +1397,11 @@ let rec match_cases_pattern metas (terms,termlists,(),() as sigma) a1 a2 =
match DAst.get a1, a2 with
| r1, NVar id2 when Id.List.mem_assoc id2 metas -> (bind_env_cases_pattern sigma id2 a1),(false,0,[])
| PatVar Anonymous, NHole _ -> sigma,(false,0,[])
- | PatCstr ((ind,_ as r1),largs,Anonymous), NRef (GlobRef.ConstructRef r2) when eq_constructor r1 r2 ->
+ | PatCstr ((ind,_ as r1),largs,Anonymous), NRef (GlobRef.ConstructRef r2) when Construct.CanOrd.equal r1 r2 ->
let l = try add_patterns_for_params_remove_local_defs (Global.env ()) r1 largs with Not_found -> raise No_match in
sigma,(false,0,l)
| PatCstr ((ind,_ as r1),args1,Anonymous), NApp (NRef (GlobRef.ConstructRef r2),l2)
- when eq_constructor r1 r2 ->
+ when Construct.CanOrd.equal r1 r2 ->
let l1 = try add_patterns_for_params_remove_local_defs (Global.env()) r1 args1 with Not_found -> raise No_match in
let le2 = List.length l2 in
if le2 > List.length l1
@@ -1416,10 +1424,10 @@ and match_cases_pattern_no_more_args metas sigma a1 a2 =
let match_ind_pattern metas sigma ind pats a2 =
match a2 with
- | NRef (GlobRef.IndRef r2) when eq_ind ind r2 ->
+ | NRef (GlobRef.IndRef r2) when Ind.CanOrd.equal ind r2 ->
sigma,(false,0,pats)
| NApp (NRef (GlobRef.IndRef r2),l2)
- when eq_ind ind r2 ->
+ when Ind.CanOrd.equal ind r2 ->
let le2 = List.length l2 in
if Int.equal le2 0 (* Special case of a notation for a @Cstr *) || le2 > List.length pats
then
@@ -1434,9 +1442,8 @@ let reorder_canonically_substitution terms termlists metas =
List.fold_right (fun (x,(scl,typ)) (terms',termlists') ->
match typ with
| NtnTypeConstr -> ((Id.List.assoc x terms, scl)::terms',termlists')
- | NtnTypeBinder _ -> assert false
| NtnTypeConstrList -> (terms',(Id.List.assoc x termlists,scl)::termlists')
- | NtnTypeBinderList -> assert false)
+ | NtnTypeBinder _ | NtnTypeBinderList -> anomaly (str "Unexpected binder in pattern notation."))
metas ([],[])
let match_notation_constr_cases_pattern c (metas,pat) =
diff --git a/interp/numTok.mli b/interp/numTok.mli
index bcfe663dd2..386a25f042 100644
--- a/interp/numTok.mli
+++ b/interp/numTok.mli
@@ -8,20 +8,20 @@
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)
-(** Numerals in different forms: signed or unsigned, possibly with
+(** Numbers in different forms: signed or unsigned, possibly with
fractional part and exponent.
- Numerals are represented using raw strings of (hexa)decimal
+ Numbers are represented using raw strings of (hexa)decimal
literals and a separate sign flag.
Note that this representation is not unique, due to possible
multiple leading or trailing zeros, and -0 = +0, for instances.
- The reason to keep the numeral exactly as it was parsed is that
- specific notations can be declared for specific numerals
+ The reason to keep the number exactly as it was parsed is that
+ specific notations can be declared for specific numbers
(e.g. [Notation "0" := False], or [Notation "00" := (nil,nil)], or
[Notation "2e1" := ...]). Those notations override the generic
- interpretation as numeral. So, one has to record the form of the
- numeral which exactly matches the notation. *)
+ interpretation as number. So, one has to record the form of the
+ number which exactly matches the notation. *)
type sign = SPlus | SMinus
@@ -44,7 +44,7 @@ sig
val sprint : t -> string
val print : t -> Pp.t
- (** [sprint] and [print] returns the numeral as it was parsed, for printing *)
+ (** [sprint] and [print] returns the number as it was parsed, for printing *)
val classify : t -> num_class
@@ -69,7 +69,7 @@ sig
val to_bigint : t -> Z.t
end
-(** {6 Unsigned decimal numerals } *)
+(** {6 Unsigned decimal numbers } *)
module Unsigned :
sig
@@ -80,12 +80,12 @@ sig
val sprint : t -> string
val print : t -> Pp.t
- (** [sprint] and [print] returns the numeral as it was parsed, for printing *)
+ (** [sprint] and [print] returns the number as it was parsed, for printing *)
val parse : char Stream.t -> t
- (** Parse a positive Coq numeral.
+ (** Parse a positive Coq number.
Precondition: the first char on the stream is already known to be a digit (\[0-9\]).
- Precondition: at least two extra chars after the numeral to parse.
+ Precondition: at least two extra chars after the number to parse.
The recognized syntax is:
- integer part: \[0-9\]\[0-9_\]*
@@ -97,13 +97,13 @@ sig
- exponent part: empty or \[pP\]\[+-\]?\[0-9\]\[0-9_\]* *)
val parse_string : string -> t option
- (** Parse the string as a non negative Coq numeral, if possible *)
+ (** Parse the string as a non negative Coq number, if possible *)
val classify : t -> num_class
end
-(** {6 Signed decimal numerals } *)
+(** {6 Signed decimal numbers } *)
module Signed :
sig
@@ -117,10 +117,10 @@ sig
val sprint : t -> string
val print : t -> Pp.t
- (** [sprint] and [print] returns the numeral as it was parsed, for printing *)
+ (** [sprint] and [print] returns the number as it was parsed, for printing *)
val parse_string : string -> t option
- (** Parse the string as a signed Coq numeral, if possible *)
+ (** Parse the string as a signed Coq number, if possible *)
val of_int_string : string -> t
(** Convert from a string in the syntax of OCaml's int/int64 *)
diff --git a/interp/reserve.ml b/interp/reserve.ml
index 4418a32645..1d5af3ff39 100644
--- a/interp/reserve.ml
+++ b/interp/reserve.ml
@@ -28,7 +28,7 @@ type key =
(** TODO: share code from Notation *)
let key_compare k1 k2 = match k1, k2 with
-| RefKey gr1, RefKey gr2 -> GlobRef.Ordered.compare gr1 gr2
+| RefKey gr1, RefKey gr2 -> GlobRef.CanOrd.compare gr1 gr2
| RefKey _, Oth -> -1
| Oth, RefKey _ -> 1
| Oth, Oth -> 0
diff --git a/interp/smartlocate.ml b/interp/smartlocate.ml
index 33d8aa6064..46baa00c74 100644
--- a/interp/smartlocate.ml
+++ b/interp/smartlocate.ml
@@ -50,6 +50,16 @@ let locate_global_with_alias ?(head=false) qid =
user_err ?loc:qid.CAst.loc (pr_qualid qid ++
str " is bound to a notation that does not denote a reference.")
+let global_constant_with_alias qid =
+ try match locate_global_with_alias qid with
+ | Names.GlobRef.ConstRef c -> c
+ | ref ->
+ user_err ?loc:qid.CAst.loc ~hdr:"global_inductive"
+ (pr_qualid qid ++ spc () ++ str "is not a reference to a constant.")
+ with Not_found as exn ->
+ let _, info = Exninfo.capture exn in
+ Nametab.error_global_not_found ~info qid
+
let global_inductive_with_alias qid =
try match locate_global_with_alias qid with
| Names.GlobRef.IndRef ind -> ind
@@ -60,6 +70,16 @@ let global_inductive_with_alias qid =
let _, info = Exninfo.capture exn in
Nametab.error_global_not_found ~info qid
+let global_constructor_with_alias qid =
+ try match locate_global_with_alias qid with
+ | Names.GlobRef.ConstructRef c -> c
+ | ref ->
+ user_err ?loc:qid.CAst.loc ~hdr:"global_inductive"
+ (pr_qualid qid ++ spc () ++ str "is not a constructor of an inductive type.")
+ with Not_found as exn ->
+ let _, info = Exninfo.capture exn in
+ Nametab.error_global_not_found ~info qid
+
let global_with_alias ?head qid =
try locate_global_with_alias ?head qid
with Not_found as exn ->
@@ -72,9 +92,17 @@ let smart_global ?(head = false) = let open Constrexpr in CAst.with_loc_val (fun
| ByNotation (ntn,sc) ->
Notation.interp_notation_as_global_reference ?loc ~head (fun _ -> true) ntn sc)
-let smart_global_inductive = let open Constrexpr in CAst.with_loc_val (fun ?loc -> function
- | AN r ->
- global_inductive_with_alias r
+let smart_global_kind f dest is = let open Constrexpr in CAst.with_loc_val (fun ?loc -> function
+ | AN r -> f r
| ByNotation (ntn,sc) ->
- destIndRef
- (Notation.interp_notation_as_global_reference ?loc ~head:false isIndRef ntn sc))
+ dest
+ (Notation.interp_notation_as_global_reference ?loc ~head:false is ntn sc))
+
+let smart_global_constant =
+ smart_global_kind global_constant_with_alias destConstRef isConstRef
+
+let smart_global_inductive =
+ smart_global_kind global_inductive_with_alias destIndRef isIndRef
+
+let smart_global_constructor =
+ smart_global_kind global_constructor_with_alias destConstructRef isConstructRef
diff --git a/interp/smartlocate.mli b/interp/smartlocate.mli
index 9b24a62086..26f2a4f36d 100644
--- a/interp/smartlocate.mli
+++ b/interp/smartlocate.mli
@@ -28,11 +28,23 @@ val global_of_extended_global : extended_global_reference -> GlobRef.t
a reference. *)
val global_with_alias : ?head:bool -> qualid -> GlobRef.t
+(** The same for constants *)
+val global_constant_with_alias : qualid -> Constant.t
+
(** The same for inductive types *)
val global_inductive_with_alias : qualid -> inductive
+(** The same for constructors of an inductive type *)
+val global_constructor_with_alias : qualid -> constructor
+
(** Locate a reference taking into account notations and "aliases" *)
val smart_global : ?head:bool -> qualid Constrexpr.or_by_notation -> GlobRef.t
+(** The same for constants *)
+val smart_global_constant : qualid Constrexpr.or_by_notation -> Constant.t
+
(** The same for inductive types *)
val smart_global_inductive : qualid Constrexpr.or_by_notation -> inductive
+
+(** The same for constructors of an inductive type *)
+val smart_global_constructor : qualid Constrexpr.or_by_notation -> constructor
diff --git a/interp/stdarg.ml b/interp/stdarg.ml
index 343f85be03..70be55f843 100644
--- a/interp/stdarg.ml
+++ b/interp/stdarg.ml
@@ -40,8 +40,10 @@ let wit_int_or_var =
let wit_ident =
make0 "ident"
-let wit_var =
- make0 ~dyn:(val_tag (topwit wit_ident)) "var"
+let wit_hyp =
+ make0 ~dyn:(val_tag (topwit wit_ident)) "hyp"
+
+let wit_var = wit_hyp
let wit_ref = make0 "ref"
diff --git a/interp/stdarg.mli b/interp/stdarg.mli
index 3ae8b7d73f..bd34af5543 100644
--- a/interp/stdarg.mli
+++ b/interp/stdarg.mli
@@ -37,7 +37,10 @@ val wit_int_or_var : (int or_var, int or_var, int) genarg_type
val wit_ident : Id.t uniform_genarg_type
+val wit_hyp : (lident, lident, Id.t) genarg_type
+
val wit_var : (lident, lident, Id.t) genarg_type
+[@@ocaml.deprecated "Use Stdarg.wit_hyp"]
val wit_ref : (qualid, GlobRef.t located or_var, GlobRef.t) genarg_type
diff --git a/interp/syntax_def.ml b/interp/syntax_def.ml
index bd3e234a91..f3ad3546ff 100644
--- a/interp/syntax_def.ml
+++ b/interp/syntax_def.ml
@@ -22,6 +22,7 @@ type syndef =
{ syndef_pattern : interpretation;
syndef_onlyparsing : bool;
syndef_deprecation : Deprecation.t option;
+ syndef_also_in_cases_pattern : bool;
}
let syntax_table =
@@ -52,7 +53,7 @@ let open_syntax_constant i ((sp,kn),(_local,syndef)) =
if not syndef.syndef_onlyparsing then
(* Redeclare it to be used as (short) name in case an other (distfix)
notation was declared in between *)
- Notation.declare_uninterpretation (Notation.SynDefRule kn) pat
+ Notation.declare_uninterpretation ~also_in_cases_pattern:syndef.syndef_also_in_cases_pattern (Notation.SynDefRule kn) pat
end
let cache_syntax_constant d =
@@ -81,11 +82,12 @@ let in_syntax_constant : (bool * syndef) -> obj =
subst_function = subst_syntax_constant;
classify_function = classify_syntax_constant }
-let declare_syntactic_definition ~local deprecation id ~onlyparsing pat =
+let declare_syntactic_definition ~local ?(also_in_cases_pattern=true) deprecation id ~onlyparsing pat =
let syndef =
{ syndef_pattern = pat;
syndef_onlyparsing = onlyparsing;
syndef_deprecation = deprecation;
+ syndef_also_in_cases_pattern = also_in_cases_pattern;
}
in
let _ = add_leaf id (in_syntax_constant (local,syndef)) in ()
diff --git a/interp/syntax_def.mli b/interp/syntax_def.mli
index 66a3132f2a..31f685152c 100644
--- a/interp/syntax_def.mli
+++ b/interp/syntax_def.mli
@@ -13,7 +13,7 @@ open Notation_term
(** Syntactic definitions. *)
-val declare_syntactic_definition : local:bool -> Deprecation.t option -> Id.t ->
+val declare_syntactic_definition : local:bool -> ?also_in_cases_pattern:bool -> Deprecation.t option -> Id.t ->
onlyparsing:bool -> interpretation -> unit
val search_syntactic_definition : ?loc:Loc.t -> KerName.t -> interpretation
diff --git a/kernel/cClosure.ml b/kernel/cClosure.ml
index a23ef8fdca..174125fc57 100644
--- a/kernel/cClosure.ml
+++ b/kernel/cClosure.ml
@@ -1165,7 +1165,7 @@ module FNativeEntries =
let mkFloat env f =
check_float env;
- { mark = mark Norm KnownR; term = FFloat f }
+ { mark = mark Cstr KnownR; term = FFloat f }
let mkBool env b =
check_bool env;
@@ -1328,10 +1328,14 @@ let rec knr info tab m stk =
| FFlex(ConstKey (kn,_u as c)) when red_set info.i_flags (fCONST kn) ->
(match ref_value_cache info tab (ConstKey c) with
| Def v -> kni info tab v stk
- | Primitive op when check_native_args op stk ->
- let rargs, a, nargs, stk = get_native_args1 op c stk in
- kni info tab a (Zprimitive(op,c,rargs,nargs)::stk)
- | Undef _ | OpaqueDef _ | Primitive _ -> (set_norm m; (m,stk)))
+ | Primitive op ->
+ if check_native_args op stk then
+ let rargs, a, nargs, stk = get_native_args1 op c stk in
+ kni info tab a (Zprimitive(op,c,rargs,nargs)::stk)
+ else
+ (* Similarly to fix, partially applied primitives are not Norm! *)
+ (m, stk)
+ | Undef _ | OpaqueDef _ -> (set_norm m; (m,stk)))
| FFlex(VarKey id) when red_set info.i_flags (fVAR id) ->
(match ref_value_cache info tab (VarKey id) with
| Def v -> kni info tab v stk
@@ -1531,7 +1535,12 @@ let whd_stack infos tab m stk = match Mark.red_state m.mark with
knh infos m stk
| Red | Cstr ->
let k = kni infos tab m stk in
- let () = if infos.i_cache.i_share then ignore (fapp_stack k) in (* to unlock Zupdates! *)
+ let () =
+ if infos.i_cache.i_share then
+ (* to unlock Zupdates! *)
+ let (m', stk') = k in
+ if not (m == m' && stk == stk') then ignore (zip m' stk')
+ in
k
let create_clos_infos ?univs ?(evars=fun _ -> None) flgs env =
diff --git a/kernel/cPrimitives.ml b/kernel/cPrimitives.ml
index 314cb54d1d..5cd91b4e74 100644
--- a/kernel/cPrimitives.ml
+++ b/kernel/cPrimitives.ml
@@ -58,7 +58,6 @@ type t =
| Arraydefault
| Arrayset
| Arraycopy
- | Arrayreroot
| Arraylength
let parse = function
@@ -110,7 +109,6 @@ let parse = function
| "array_set" -> Arrayset
| "array_length" -> Arraylength
| "array_copy" -> Arraycopy
- | "array_reroot" -> Arrayreroot
| _ -> raise Not_found
let equal (p1 : t) (p2 : t) =
@@ -164,8 +162,7 @@ let hash = function
| Arraydefault -> 45
| Arrayset -> 46
| Arraycopy -> 47
- | Arrayreroot -> 48
- | Arraylength -> 49
+ | Arraylength -> 48
(* Should match names in nativevalues.ml *)
let to_string = function
@@ -216,7 +213,6 @@ let to_string = function
| Arraydefault -> "arraydefault"
| Arrayset -> "arrayset"
| Arraycopy -> "arraycopy"
- | Arrayreroot -> "arrayreroot"
| Arraylength -> "arraylength"
type const =
@@ -302,7 +298,6 @@ let types =
| Arraydefault -> [array_ty; PITT_param 1]
| Arrayset -> [array_ty; int_ty; PITT_param 1; array_ty]
| Arraycopy -> [array_ty; array_ty]
- | Arrayreroot -> [array_ty; array_ty]
| Arraylength -> [array_ty; int_ty]
let one_param =
@@ -360,7 +355,6 @@ let params = function
| Arraydefault
| Arrayset
| Arraycopy
- | Arrayreroot
| Arraylength -> one_param
let nparams x = List.length (params x)
@@ -414,7 +408,6 @@ let univs = function
| Arraydefault
| Arrayset
| Arraycopy
- | Arrayreroot
| Arraylength -> one_univ
type arg_kind =
diff --git a/kernel/cPrimitives.mli b/kernel/cPrimitives.mli
index 41b3bff465..0db643faf4 100644
--- a/kernel/cPrimitives.mli
+++ b/kernel/cPrimitives.mli
@@ -56,7 +56,6 @@ type t =
| Arraydefault
| Arrayset
| Arraycopy
- | Arrayreroot
| Arraylength
(** Can raise [Not_found].
diff --git a/kernel/constr.ml b/kernel/constr.ml
index 1837a39764..3157ec9f57 100644
--- a/kernel/constr.ml
+++ b/kernel/constr.ml
@@ -353,9 +353,9 @@ let isRef c = match kind c with
let isRefX x c =
let open GlobRef in
match x, kind c with
- | ConstRef c, Const (c', _) -> Constant.equal c c'
- | IndRef i, Ind (i', _) -> eq_ind i i'
- | ConstructRef i, Construct (i', _) -> eq_constructor i i'
+ | ConstRef c, Const (c', _) -> Constant.CanOrd.equal c c'
+ | IndRef i, Ind (i', _) -> Ind.CanOrd.equal i i'
+ | ConstructRef i, Construct (i', _) -> Construct.CanOrd.equal i i'
| VarRef id, Var id' -> Id.equal id id'
| _ -> false
@@ -950,14 +950,14 @@ let compare_head_gen_leq_with kind1 kind2 leq_universes leq_sorts eq leq nargs t
let len = Array.length l1 in
Int.equal len (Array.length l2) &&
leq (nargs+len) c1 c2 && Array.equal_norefl (eq 0) l1 l2
- | Proj (p1,c1), Proj (p2,c2) -> Projection.equal p1 p2 && eq 0 c1 c2
+ | Proj (p1,c1), Proj (p2,c2) -> Projection.CanOrd.equal p1 p2 && eq 0 c1 c2
| Evar (e1,l1), Evar (e2,l2) -> Evar.equal e1 e2 && List.equal (eq 0) l1 l2
| Const (c1,u1), Const (c2,u2) ->
(* The args length currently isn't used but may as well pass it. *)
- Constant.equal c1 c2 && leq_universes (Some (GlobRef.ConstRef c1, nargs)) u1 u2
- | Ind (c1,u1), Ind (c2,u2) -> eq_ind c1 c2 && leq_universes (Some (GlobRef.IndRef c1, nargs)) u1 u2
+ Constant.CanOrd.equal c1 c2 && leq_universes (Some (GlobRef.ConstRef c1, nargs)) u1 u2
+ | Ind (c1,u1), Ind (c2,u2) -> Ind.CanOrd.equal c1 c2 && leq_universes (Some (GlobRef.IndRef c1, nargs)) u1 u2
| Construct (c1,u1), Construct (c2,u2) ->
- eq_constructor c1 c2 && leq_universes (Some (GlobRef.ConstructRef c1, nargs)) u1 u2
+ Construct.CanOrd.equal c1 c2 && leq_universes (Some (GlobRef.ConstructRef c1, nargs)) u1 u2
| Case (_,p1,iv1,c1,bl1), Case (_,p2,iv2,c2,bl2) ->
eq 0 p1 p2 && eq_invert (eq 0) (leq_universes None) iv1 iv2 && eq 0 c1 c2 && Array.equal (eq 0) bl1 bl2
| Fix ((ln1, i1),(_,tl1,bl1)), Fix ((ln2, i2),(_,tl2,bl2)) ->
@@ -1139,9 +1139,9 @@ let constr_ord_int f t1 t2 =
| App _, _ -> -1 | _, App _ -> 1
| Const (c1,_u1), Const (c2,_u2) -> Constant.CanOrd.compare c1 c2
| Const _, _ -> -1 | _, Const _ -> 1
- | Ind (ind1, _u1), Ind (ind2, _u2) -> ind_ord ind1 ind2
+ | Ind (ind1, _u1), Ind (ind2, _u2) -> Ind.CanOrd.compare ind1 ind2
| Ind _, _ -> -1 | _, Ind _ -> 1
- | Construct (ct1,_u1), Construct (ct2,_u2) -> constructor_ord ct1 ct2
+ | Construct (ct1,_u1), Construct (ct2,_u2) -> Construct.CanOrd.compare ct1 ct2
| Construct _, _ -> -1 | _, Construct _ -> 1
| Case (_,p1,iv1,c1,bl1), Case (_,p2,iv2,c2,bl2) ->
let c = f p1 p2 in
@@ -1158,7 +1158,7 @@ let constr_ord_int f t1 t2 =
((Int.compare =? (Array.compare f)) ==? (Array.compare f))
ln1 ln2 tl1 tl2 bl1 bl2
| CoFix _, _ -> -1 | _, CoFix _ -> 1
- | Proj (p1,c1), Proj (p2,c2) -> (Projection.compare =? f) p1 p2 c1 c2
+ | Proj (p1,c1), Proj (p2,c2) -> (Projection.CanOrd.compare =? f) p1 p2 c1 c2
| Proj _, _ -> -1 | _, Proj _ -> 1
| Int i1, Int i2 -> Uint63.compare i1 i2
| Int _, _ -> -1 | _, Int _ -> 1
@@ -1331,11 +1331,11 @@ let hashcons (sh_sort,sh_ci,sh_construct,sh_ind,sh_con,sh_na,sh_id) =
| Ind (ind,u) ->
let u', hu = sh_instance u in
(Ind (sh_ind ind, u'),
- combinesmall 10 (combine (ind_syntactic_hash ind) hu))
+ combinesmall 10 (combine (Ind.SyntacticOrd.hash ind) hu))
| Construct (c,u) ->
let u', hu = sh_instance u in
(Construct (sh_construct c, u'),
- combinesmall 11 (combine (constructor_syntactic_hash c) hu))
+ combinesmall 11 (combine (Construct.SyntacticOrd.hash c) hu))
| Case (ci,p,iv,c,bl) ->
let p, hp = sh_rec p
and iv, hiv = sh_invert iv
@@ -1442,11 +1442,11 @@ let rec hash t =
| Evar (e,l) ->
combinesmall 8 (combine (Evar.hash e) (hash_term_list l))
| Const (c,u) ->
- combinesmall 9 (combine (Constant.hash c) (Instance.hash u))
+ combinesmall 9 (combine (Constant.CanOrd.hash c) (Instance.hash u))
| Ind (ind,u) ->
- combinesmall 10 (combine (ind_hash ind) (Instance.hash u))
+ combinesmall 10 (combine (Ind.CanOrd.hash ind) (Instance.hash u))
| Construct (c,u) ->
- combinesmall 11 (combine (constructor_hash c) (Instance.hash u))
+ combinesmall 11 (combine (Construct.CanOrd.hash c) (Instance.hash u))
| Case (_ , p, iv, c, bl) ->
combinesmall 12 (combine4 (hash c) (hash p) (hash_invert iv) (hash_term_array bl))
| Fix (_ln ,(_, tl, bl)) ->
@@ -1456,7 +1456,7 @@ let rec hash t =
| Meta n -> combinesmall 15 n
| Rel n -> combinesmall 16 n
| Proj (p,c) ->
- combinesmall 17 (combine (Projection.hash p) (hash c))
+ combinesmall 17 (combine (Projection.CanOrd.hash p) (hash c))
| Int i -> combinesmall 18 (Uint63.hash i)
| Float f -> combinesmall 19 (Float64.hash f)
| Array(u,t,def,ty) ->
@@ -1503,7 +1503,7 @@ struct
let h3 = Array.fold_left hash_bool_list 0 info.cstr_tags in
combine3 h1 h2 h3
let hash ci =
- let h1 = ind_hash ci.ci_ind in
+ let h1 = Ind.CanOrd.hash ci.ci_ind in
let h2 = Int.hash ci.ci_npar in
let h3 = Array.fold_left combine 0 ci.ci_cstr_ndecls in
let h4 = Array.fold_left combine 0 ci.ci_cstr_nargs in
diff --git a/kernel/cooking.ml b/kernel/cooking.ml
index fdcf44c943..3707a75157 100644
--- a/kernel/cooking.ml
+++ b/kernel/cooking.ml
@@ -38,14 +38,14 @@ struct
type t = my_global_reference
let equal gr1 gr2 = match gr1, gr2 with
| ConstRef c1, ConstRef c2 -> Constant.SyntacticOrd.equal c1 c2
- | IndRef i1, IndRef i2 -> eq_syntactic_ind i1 i2
- | ConstructRef c1, ConstructRef c2 -> eq_syntactic_constructor c1 c2
+ | IndRef i1, IndRef i2 -> Ind.SyntacticOrd.equal i1 i2
+ | ConstructRef c1, ConstructRef c2 -> Construct.SyntacticOrd.equal c1 c2
| _ -> false
open Hashset.Combine
let hash = function
| ConstRef c -> combinesmall 1 (Constant.SyntacticOrd.hash c)
- | IndRef i -> combinesmall 2 (ind_syntactic_hash i)
- | ConstructRef c -> combinesmall 3 (constructor_syntactic_hash c)
+ | IndRef i -> combinesmall 2 (Ind.SyntacticOrd.hash i)
+ | ConstructRef c -> combinesmall 3 (Construct.SyntacticOrd.hash c)
end
module RefTable = Hashtbl.Make(RefHash)
diff --git a/kernel/declareops.ml b/kernel/declareops.ml
index b9f434f179..8de7123fee 100644
--- a/kernel/declareops.ml
+++ b/kernel/declareops.ml
@@ -157,15 +157,15 @@ let hcons_const_body cb =
(** {6 Inductive types } *)
let eq_nested_type t1 t2 = match t1, t2 with
-| NestedInd ind1, NestedInd ind2 -> Names.eq_ind ind1 ind2
+| NestedInd ind1, NestedInd ind2 -> Names.Ind.CanOrd.equal ind1 ind2
| NestedInd _, _ -> false
-| NestedPrimitive c1, NestedPrimitive c2 -> Names.Constant.equal c1 c2
+| NestedPrimitive c1, NestedPrimitive c2 -> Names.Constant.CanOrd.equal c1 c2
| NestedPrimitive _, _ -> false
let eq_recarg r1 r2 = match r1, r2 with
| Norec, Norec -> true
| Norec, _ -> false
-| Mrec i1, Mrec i2 -> Names.eq_ind i1 i2
+| Mrec i1, Mrec i2 -> Names.Ind.CanOrd.equal i1 i2
| Mrec _, _ -> false
| Nested ty1, Nested ty2 -> eq_nested_type ty1 ty2
| Nested _, _ -> false
diff --git a/kernel/dune b/kernel/dune
index ce6fdc03df..bd663974da 100644
--- a/kernel/dune
+++ b/kernel/dune
@@ -3,7 +3,7 @@
(synopsis "The Coq Kernel")
(public_name coq.kernel)
(wrapped false)
- (modules (:standard \ genOpcodeFiles uint63_31 uint63_63))
+ (modules (:standard \ genOpcodeFiles uint63_31 uint63_63 float64_31 float64_63))
(libraries lib byterun dynlink))
(executable
@@ -19,6 +19,11 @@
(deps (:gen-file uint63_%{ocaml-config:int_size}.ml))
(action (copy# %{gen-file} %{targets})))
+(rule
+ (targets float64.ml)
+ (deps (:gen-file float64_%{ocaml-config:int_size}.ml))
+ (action (copy# %{gen-file} %{targets})))
+
(documentation
(package coq))
diff --git a/kernel/environ.ml b/kernel/environ.ml
index 03c9cb4be6..17c5a02e2b 100644
--- a/kernel/environ.ml
+++ b/kernel/environ.ml
@@ -274,6 +274,11 @@ let is_impredicative_sort env = function
let is_impredicative_univ env u = is_impredicative_sort env (Sorts.sort_of_univ u)
+let is_impredicative_family env = function
+ | Sorts.InSProp | Sorts.InProp -> true
+ | Sorts.InSet -> is_impredicative_set env
+ | Sorts.InType -> false
+
let type_in_type env = not (typing_flags env).check_universes
let deactivated_guard env = not (typing_flags env).check_guarded
@@ -467,14 +472,22 @@ let same_flags {
[@warning "+9"]
let set_cumulative_sprop b = map_universes (UGraph.set_cumulative_sprop b)
+let set_type_in_type b = map_universes (UGraph.set_type_in_type b)
let set_typing_flags c env =
if same_flags env.env_typing_flags c then env
- else set_cumulative_sprop c.cumulative_sprop { env with env_typing_flags = c }
+ else
+ let env = { env with env_typing_flags = c } in
+ let env = set_cumulative_sprop c.cumulative_sprop env in
+ let env = set_type_in_type (not c.check_universes) env in
+ env
let set_cumulative_sprop b env =
set_typing_flags {env.env_typing_flags with cumulative_sprop=b} env
+let set_type_in_type b env =
+ set_typing_flags {env.env_typing_flags with check_universes=not b} env
+
let set_allow_sprop b env =
{ env with env_stratification =
{ env.env_stratification with env_sprop_allowed = b } }
@@ -819,3 +832,66 @@ let set_retroknowledge env r = { env with retroknowledge = r }
let set_native_symbols env native_symbols = { env with native_symbols }
let add_native_symbols dir syms env =
{ env with native_symbols = DPmap.add dir syms env.native_symbols }
+
+module type QNameS =
+sig
+ type t
+ val equal : env -> t -> t -> bool
+ val compare : env -> t -> t -> int
+ val hash : env -> t -> int
+end
+
+module QConstant =
+struct
+ type t = Constant.t
+ let equal _env c1 c2 = Constant.CanOrd.equal c1 c2
+ let compare _env c1 c2 = Constant.CanOrd.compare c1 c2
+ let hash _env c = Constant.CanOrd.hash c
+end
+
+module QMutInd =
+struct
+ type t = MutInd.t
+ let equal _env c1 c2 = MutInd.CanOrd.equal c1 c2
+ let compare _env c1 c2 = MutInd.CanOrd.compare c1 c2
+ let hash _env c = MutInd.CanOrd.hash c
+end
+
+module QInd =
+struct
+ type t = Ind.t
+ let equal _env c1 c2 = Ind.CanOrd.equal c1 c2
+ let compare _env c1 c2 = Ind.CanOrd.compare c1 c2
+ let hash _env c = Ind.CanOrd.hash c
+end
+
+module QConstruct =
+struct
+ type t = Construct.t
+ let equal _env c1 c2 = Construct.CanOrd.equal c1 c2
+ let compare _env c1 c2 = Construct.CanOrd.compare c1 c2
+ let hash _env c = Construct.CanOrd.hash c
+end
+
+module QProjection =
+struct
+ type t = Projection.t
+ let equal _env c1 c2 = Projection.CanOrd.equal c1 c2
+ let compare _env c1 c2 = Projection.CanOrd.compare c1 c2
+ let hash _env c = Projection.CanOrd.hash c
+ module Repr =
+ struct
+ type t = Projection.Repr.t
+ let equal _env c1 c2 = Projection.Repr.CanOrd.equal c1 c2
+ let compare _env c1 c2 = Projection.Repr.CanOrd.compare c1 c2
+ let hash _env c = Projection.Repr.CanOrd.hash c
+ end
+end
+
+module QGlobRef =
+struct
+ type t = GlobRef.t
+ let equal _env c1 c2 = GlobRef.CanOrd.equal c1 c2
+ let compare _env c1 c2 = GlobRef.CanOrd.compare c1 c2
+ let hash _env c = GlobRef.CanOrd.hash c
+end
diff --git a/kernel/environ.mli b/kernel/environ.mli
index 974e794c6b..f0b40e6492 100644
--- a/kernel/environ.mli
+++ b/kernel/environ.mli
@@ -122,6 +122,7 @@ val indices_matter : env -> bool
val is_impredicative_sort : env -> Sorts.t -> bool
val is_impredicative_univ : env -> Univ.Universe.t -> bool
+val is_impredicative_family : env -> Sorts.family -> bool
(** is the local context empty *)
val empty_context : env -> bool
@@ -283,6 +284,32 @@ val template_polymorphic_ind : inductive -> env -> bool
val template_polymorphic_variables : inductive -> env -> Univ.Level.t list
val template_polymorphic_pind : pinductive -> env -> bool
+(** {6 Name quotients} *)
+
+module type QNameS =
+sig
+ type t
+ val equal : env -> t -> t -> bool
+ val compare : env -> t -> t -> int
+ val hash : env -> t -> int
+end
+
+module QConstant : QNameS with type t = Constant.t
+
+module QMutInd : QNameS with type t = MutInd.t
+
+module QInd : QNameS with type t = Ind.t
+
+module QConstruct : QNameS with type t = Construct.t
+
+module QProjection :
+sig
+ include QNameS with type t = Projection.t
+ module Repr : QNameS with type t = Projection.Repr.t
+end
+
+module QGlobRef : QNameS with type t = GlobRef.t
+
(** {5 Modules } *)
val add_modtype : module_type_body -> env -> env
@@ -320,6 +347,7 @@ val push_subgraph : Univ.ContextSet.t -> env -> env
val set_engagement : engagement -> env -> env
val set_typing_flags : typing_flags -> env -> env
val set_cumulative_sprop : bool -> env -> env
+val set_type_in_type : bool -> env -> env
val set_allow_sprop : bool -> env -> env
val sprop_allowed : env -> bool
diff --git a/kernel/float64_31.ml b/kernel/float64_31.ml
new file mode 100644
index 0000000000..09b28e6cf0
--- /dev/null
+++ b/kernel/float64_31.ml
@@ -0,0 +1,35 @@
+(************************************************************************)
+(* * The Coq Proof Assistant / The Coq Development Team *)
+(* v * Copyright INRIA, CNRS and contributors *)
+(* <O___,, * (see version control and CREDITS file for authors & dates) *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(* * (see LICENSE file for the text of the license) *)
+(************************************************************************)
+
+include Float64_common
+
+external mul : float -> float -> float = "coq_fmul_byte" "coq_fmul"
+[@@unboxed] [@@noalloc]
+
+external add : float -> float -> float = "coq_fadd_byte" "coq_fadd"
+[@@unboxed] [@@noalloc]
+
+external sub : float -> float -> float = "coq_fsub_byte" "coq_fsub"
+[@@unboxed] [@@noalloc]
+
+external div : float -> float -> float = "coq_fdiv_byte" "coq_fdiv"
+[@@unboxed] [@@noalloc]
+
+external sqrt : float -> float = "coq_fsqrt_byte" "coq_fsqrt"
+[@@unboxed] [@@noalloc]
+
+(*** Test at runtime that no harmful double rounding seems to
+ be performed with an intermediate 80 bits representation (x87). *)
+let () =
+ let b = ldexp 1. 53 in
+ let s = add 1. (ldexp 1. (-52)) in
+ if add b s <= b || add b 1. <> b || ldexp 1. (-1074) <= 0. then
+ failwith "Detected non IEEE-754 compliant architecture (or wrong \
+ rounding mode). Use of Float is thus unsafe."
diff --git a/kernel/float64_63.ml b/kernel/float64_63.ml
new file mode 100644
index 0000000000..0025531cb1
--- /dev/null
+++ b/kernel/float64_63.ml
@@ -0,0 +1,35 @@
+(************************************************************************)
+(* * The Coq Proof Assistant / The Coq Development Team *)
+(* v * Copyright INRIA, CNRS and contributors *)
+(* <O___,, * (see version control and CREDITS file for authors & dates) *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(* * (see LICENSE file for the text of the license) *)
+(************************************************************************)
+
+include Float64_common
+
+let mul (x : float) (y : float) : float = x *. y
+[@@ocaml.inline always]
+
+let add (x : float) (y : float) : float = x +. y
+[@@ocaml.inline always]
+
+let sub (x : float) (y : float) : float = x -. y
+[@@ocaml.inline always]
+
+let div (x : float) (y : float) : float = x /. y
+[@@ocaml.inline always]
+
+let sqrt (x : float) : float = sqrt x
+[@@ocaml.inline always]
+
+(*** Test at runtime that no harmful double rounding seems to
+ be performed with an intermediate 80 bits representation (x87). *)
+let () =
+ let b = ldexp 1. 53 in
+ let s = add 1. (ldexp 1. (-52)) in
+ if add b s <= b || add b 1. <> b || ldexp 1. (-1074) <= 0. then
+ failwith "Detected non IEEE-754 compliant architecture (or wrong \
+ rounding mode). Use of Float is thus unsafe."
diff --git a/kernel/float64.ml b/kernel/float64_common.ml
index 76005a3dc6..2991a20b49 100644
--- a/kernel/float64.ml
+++ b/kernel/float64_common.ml
@@ -88,21 +88,6 @@ let classify x =
| FP_nan -> NaN
[@@ocaml.inline always]
-external mul : float -> float -> float = "coq_fmul_byte" "coq_fmul"
-[@@unboxed] [@@noalloc]
-
-external add : float -> float -> float = "coq_fadd_byte" "coq_fadd"
-[@@unboxed] [@@noalloc]
-
-external sub : float -> float -> float = "coq_fsub_byte" "coq_fsub"
-[@@unboxed] [@@noalloc]
-
-external div : float -> float -> float = "coq_fdiv_byte" "coq_fdiv"
-[@@unboxed] [@@noalloc]
-
-external sqrt : float -> float = "coq_fsqrt_byte" "coq_fsqrt"
-[@@unboxed] [@@noalloc]
-
let of_int63 x = Uint63.to_float x
[@@ocaml.inline always]
@@ -157,12 +142,3 @@ let total_compare f1 f2 =
let is_float64 t =
Obj.tag t = Obj.double_tag
[@@ocaml.inline always]
-
-(*** Test at runtime that no harmful double rounding seems to
- be performed with an intermediate 80 bits representation (x87). *)
-let () =
- let b = ldexp 1. 53 in
- let s = add 1. (ldexp 1. (-52)) in
- if add b s <= b || add b 1. <> b || ldexp 1. (-1074) <= 0. then
- failwith "Detected non IEEE-754 compliant architecture (or wrong \
- rounding mode). Use of Float is thus unsafe."
diff --git a/kernel/float64_common.mli b/kernel/float64_common.mli
new file mode 100644
index 0000000000..4fb1c114a5
--- /dev/null
+++ b/kernel/float64_common.mli
@@ -0,0 +1,95 @@
+(************************************************************************)
+(* * The Coq Proof Assistant / The Coq Development Team *)
+(* v * Copyright INRIA, CNRS and contributors *)
+(* <O___,, * (see version control and CREDITS file for authors & dates) *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(* * (see LICENSE file for the text of the license) *)
+(************************************************************************)
+
+(** [t] is currently implemented by OCaml's [float] type.
+
+Beware: NaNs have a sign and a payload, while they should be
+indistinguishable from Coq's perspective. *)
+type t = float
+
+(** Test functions for special values to avoid calling [classify] *)
+val is_nan : t -> bool
+val is_infinity : t -> bool
+val is_neg_infinity : t -> bool
+
+val of_string : string -> t
+
+(** Print a float exactly as an hexadecimal value (exact decimal
+ * printing would be possible but sometimes requires more than 700
+ * digits). *)
+val to_hex_string : t -> string
+
+(** Print a float as a decimal value. The printing is not exact (the
+ * real value printed is not always the given floating-point value),
+ * however printing is precise enough that forall float [f],
+ * [of_string (to_decimal_string f) = f]. *)
+val to_string : t -> string
+
+val compile : t -> string
+
+val of_float : float -> t
+
+(** Return [true] for "-", [false] for "+". *)
+val sign : t -> bool
+
+val opp : t -> t
+val abs : t -> t
+
+type float_comparison = FEq | FLt | FGt | FNotComparable
+
+val eq : t -> t -> bool
+
+val lt : t -> t -> bool
+
+val le : t -> t -> bool
+
+(** The IEEE 754 float comparison.
+ * NotComparable is returned if there is a NaN in the arguments *)
+val compare : t -> t -> float_comparison
+[@@ocaml.inline always]
+
+type float_class =
+ | PNormal | NNormal | PSubn | NSubn | PZero | NZero | PInf | NInf | NaN
+
+val classify : t -> float_class
+[@@ocaml.inline always]
+
+(** Link with integers *)
+val of_int63 : Uint63.t -> t
+[@@ocaml.inline always]
+
+val normfr_mantissa : t -> Uint63.t
+[@@ocaml.inline always]
+
+(** Shifted exponent extraction *)
+val eshift : int
+
+val frshiftexp : t -> t * Uint63.t (* float remainder, shifted exponent *)
+[@@ocaml.inline always]
+
+val ldshiftexp : t -> Uint63.t -> t
+[@@ocaml.inline always]
+
+val next_up : t -> t
+
+val next_down : t -> t
+
+(** Return true if two floats are equal.
+ * All NaN values are considered equal. *)
+val equal : t -> t -> bool
+[@@ocaml.inline always]
+
+val hash : t -> int
+
+(** Total order relation over float values. Behaves like [Pervasives.compare].*)
+val total_compare : t -> t -> int
+
+val is_float64 : Obj.t -> bool
+[@@ocaml.inline always]
diff --git a/kernel/indTyping.ml b/kernel/indTyping.ml
index 179353d3f0..b2520b780f 100644
--- a/kernel/indTyping.ml
+++ b/kernel/indTyping.ml
@@ -77,7 +77,7 @@ let check_univ_leq ?(is_real_arg=false) env u info =
else info
in
(* Inductive types provide explicit lifting from SProp to other universes, so allow SProp <= any. *)
- if type_in_type env || Univ.Universe.is_sprop u || UGraph.check_leq (universes env) u ind_univ
+ if Univ.Universe.is_sprop u || UGraph.check_leq (universes env) u ind_univ
then { info with ind_min_univ = Option.map (Universe.sup u) info.ind_min_univ }
else if is_impredicative_univ env ind_univ
&& Option.is_empty info.ind_min_univ then { info with ind_squashed = true }
diff --git a/kernel/inductive.ml b/kernel/inductive.ml
index d751d9875a..e34b3c0b47 100644
--- a/kernel/inductive.ml
+++ b/kernel/inductive.ml
@@ -404,7 +404,7 @@ let type_case_branches env (pind,largs) pj c =
let check_case_info env (indsp,u) r ci =
let (mib,mip as spec) = lookup_mind_specif env indsp in
if
- not (eq_ind indsp ci.ci_ind) ||
+ not (Ind.CanOrd.equal indsp ci.ci_ind) ||
not (Int.equal mib.mind_nparams ci.ci_npar) ||
not (Array.equal Int.equal mip.mind_consnrealdecls ci.ci_cstr_ndecls) ||
not (Array.equal Int.equal mip.mind_consnrealargs ci.ci_cstr_nargs) ||
@@ -467,12 +467,12 @@ let inter_recarg r1 r2 = match r1, r2 with
| Norec, _ -> None
| Mrec i1, Mrec i2
| Nested (NestedInd i1), Nested (NestedInd i2)
-| Mrec i1, (Nested (NestedInd i2)) -> if Names.eq_ind i1 i2 then Some r1 else None
+| Mrec i1, (Nested (NestedInd i2)) -> if Names.Ind.CanOrd.equal i1 i2 then Some r1 else None
| Mrec _, _ -> None
-| Nested (NestedInd i1), Mrec i2 -> if Names.eq_ind i1 i2 then Some r2 else None
+| Nested (NestedInd i1), Mrec i2 -> if Names.Ind.CanOrd.equal i1 i2 then Some r2 else None
| Nested (NestedInd _), _ -> None
| Nested (NestedPrimitive c1), Nested (NestedPrimitive c2) ->
- if Names.Constant.equal c1 c2 then Some r1 else None
+ if Names.Constant.CanOrd.equal c1 c2 then Some r1 else None
| Nested (NestedPrimitive _), _ -> None
let inter_wf_paths = Rtree.inter Declareops.eq_recarg inter_recarg Norec
@@ -556,7 +556,7 @@ let lookup_subterms env ind =
let match_inductive ind ra =
match ra with
- | Mrec i | Nested (NestedInd i) -> eq_ind ind i
+ | Mrec i | Nested (NestedInd i) -> Ind.CanOrd.equal ind i
| Norec | Nested (NestedPrimitive _) -> false
(* In {match c as z in ci y_s return P with |C_i x_s => t end}
@@ -644,7 +644,7 @@ let abstract_mind_lc ntyps npars lc =
let is_primitive_positive_container env c =
match env.retroknowledge.Retroknowledge.retro_array with
- | Some c' when Constant.equal c c' -> true
+ | Some c' when QConstant.equal env c c' -> true
| _ -> false
(* [get_recargs_approx env tree ind args] builds an approximation of the recargs
@@ -667,13 +667,13 @@ let get_recargs_approx env tree ind args =
(* When the inferred tree allows it, we consider that we have a potential
nested inductive type *)
begin match dest_recarg tree with
- | Nested (NestedInd kn') | Mrec kn' when eq_ind (fst ind_kn) kn' ->
+ | Nested (NestedInd kn') | Mrec kn' when Ind.CanOrd.equal (fst ind_kn) kn' ->
build_recargs_nested ienv tree (ind_kn, largs)
| _ -> mk_norec
end
| Const (c,_) when is_primitive_positive_container env c ->
begin match dest_recarg tree with
- | Nested (NestedPrimitive c') when Constant.equal c c' ->
+ | Nested (NestedPrimitive c') when QConstant.equal env c c' ->
build_recargs_nested_primitive ienv tree (c, largs)
| _ -> mk_norec
end
diff --git a/kernel/kernel.mllib b/kernel/kernel.mllib
index d4d7150222..5b2a7bd9c2 100644
--- a/kernel/kernel.mllib
+++ b/kernel/kernel.mllib
@@ -2,6 +2,7 @@ Names
TransparentState
Uint63
Parray
+Float64_common
Float64
Univ
UGraph
diff --git a/kernel/mod_typing.ml b/kernel/mod_typing.ml
index 5873d1f502..c7b866179b 100644
--- a/kernel/mod_typing.ml
+++ b/kernel/mod_typing.ml
@@ -80,12 +80,11 @@ let rec check_with_def env struc (idl,(c,ctx)) mp equiv =
let j = Typeops.infer env' c in
assert (j.uj_val == c); (* relevances should already be correct here *)
let typ = cb.const_type in
- let cst' = Reduction.infer_conv_leq env' (Environ.universes env')
- j.uj_type typ in
+ let cst' = Reduction.infer_conv_leq env' j.uj_type typ in
j.uj_val, cst'
| Def cs ->
let c' = Mod_subst.force_constr cs in
- c, Reduction.infer_conv env' (Environ.universes env') c c'
+ c, Reduction.infer_conv env' c c'
| Primitive _ ->
error_incorrect_with_constraint lab
in
@@ -103,12 +102,11 @@ let rec check_with_def env struc (idl,(c,ctx)) mp equiv =
let j = Typeops.infer env' c in
assert (j.uj_val == c); (* relevances should already be correct here *)
let typ = cb.const_type in
- let cst' = Reduction.infer_conv_leq env' (Environ.universes env')
- j.uj_type typ in
+ let cst' = Reduction.infer_conv_leq env' j.uj_type typ in
cst'
| Def cs ->
let c' = Mod_subst.force_constr cs in
- let cst' = Reduction.infer_conv env' (Environ.universes env') c c' in
+ let cst' = Reduction.infer_conv env' c c' in
cst'
| Primitive _ ->
error_incorrect_with_constraint lab
diff --git a/kernel/names.ml b/kernel/names.ml
index 592b5e65f7..5b6064fa9f 100644
--- a/kernel/names.ml
+++ b/kernel/names.ml
@@ -447,6 +447,22 @@ module KNset = KNmap.Set
(** {6 Kernel pairs } *)
+module type EqType =
+sig
+ type t
+ val compare : t -> t -> int
+ val equal : t -> t -> bool
+ val hash : t -> int
+end
+
+module type QNameS =
+sig
+ type t
+ module CanOrd : EqType with type t = t
+ module UserOrd : EqType with type t = t
+ module SyntacticOrd : EqType with type t = t
+end
+
(** For constant and inductive names, we use a kernel name couple (kn1,kn2)
where kn1 corresponds to the name used at toplevel (i.e. what the user see)
and kn2 corresponds to the canonical kernel name i.e. in the environment
@@ -529,6 +545,7 @@ module KerPair = struct
end
module SyntacticOrd = struct
+ type t = kernel_pair
let compare x y = match x, y with
| Same knx, Same kny -> KerName.compare knx kny
| Dual (knux,kncx), Dual (knuy,kncy) ->
@@ -599,100 +616,147 @@ module Mindmap = HMap.Make(MutInd.CanOrd)
module Mindset = Mindmap.Set
module Mindmap_env = HMap.Make(MutInd.UserOrd)
+module Ind =
+struct
+ (** Designation of a (particular) inductive type. *)
+ type t = MutInd.t (* the name of the inductive type *)
+ * int (* the position of this inductive type
+ within the block of mutually-recursive inductive types.
+ BEWARE: indexing starts from 0. *)
+ let modpath (mind, _) = MutInd.modpath mind
+
+ module CanOrd =
+ struct
+ type nonrec t = t
+ let equal (m1, i1) (m2, i2) = Int.equal i1 i2 && MutInd.CanOrd.equal m1 m2
+ let compare (m1, i1) (m2, i2) =
+ let c = Int.compare i1 i2 in
+ if Int.equal c 0 then MutInd.CanOrd.compare m1 m2 else c
+ let hash (m, i) =
+ Hashset.Combine.combine (MutInd.CanOrd.hash m) (Int.hash i)
+ end
+
+ module UserOrd =
+ struct
+ type nonrec t = t
+ let equal (m1, i1) (m2, i2) =
+ Int.equal i1 i2 && MutInd.UserOrd.equal m1 m2
+ let compare (m1, i1) (m2, i2) =
+ let c = Int.compare i1 i2 in
+ if Int.equal c 0 then MutInd.UserOrd.compare m1 m2 else c
+ let hash (m, i) =
+ Hashset.Combine.combine (MutInd.UserOrd.hash m) (Int.hash i)
+ end
+
+ module SyntacticOrd =
+ struct
+ type nonrec t = t
+ let equal (m1, i1) (m2, i2) =
+ Int.equal i1 i2 && MutInd.SyntacticOrd.equal m1 m2
+
+ let compare (m1, i1) (m2, i2) =
+ let c = Int.compare i1 i2 in
+ if Int.equal c 0 then MutInd.SyntacticOrd.compare m1 m2 else c
+
+ let hash (m, i) =
+ Hashset.Combine.combine (MutInd.SyntacticOrd.hash m) (Int.hash i)
+ end
+
+end
+
+module Construct =
+struct
+ (** Designation of a (particular) constructor of a (particular) inductive type. *)
+ type t = Ind.t (* designates the inductive type *)
+ * int (* the index of the constructor
+ BEWARE: indexing starts from 1. *)
+
+ let modpath (ind, _) = Ind.modpath ind
+
+ module CanOrd =
+ struct
+ type nonrec t = t
+ let equal (ind1, j1) (ind2, j2) = Int.equal j1 j2 && Ind.CanOrd.equal ind1 ind2
+ let compare (ind1, j1) (ind2, j2) =
+ let c = Int.compare j1 j2 in
+ if Int.equal c 0 then Ind.CanOrd.compare ind1 ind2 else c
+ let hash (ind, i) =
+ Hashset.Combine.combine (Ind.CanOrd.hash ind) (Int.hash i)
+ end
+
+ module UserOrd =
+ struct
+ type nonrec t = t
+ let equal (ind1, j1) (ind2, j2) =
+ Int.equal j1 j2 && Ind.UserOrd.equal ind1 ind2
+ let compare (ind1, j1) (ind2, j2) =
+ let c = Int.compare j1 j2 in
+ if Int.equal c 0 then Ind.UserOrd.compare ind1 ind2 else c
+ let hash (ind, i) =
+ Hashset.Combine.combine (Ind.UserOrd.hash ind) (Int.hash i)
+ end
+
+ module SyntacticOrd =
+ struct
+ type nonrec t = t
+ let equal (ind1, j1) (ind2, j2) =
+ Int.equal j1 j2 && Ind.SyntacticOrd.equal ind1 ind2
+ let compare (ind1, j1) (ind2, j2) =
+ let c = Int.compare j1 j2 in
+ if Int.equal c 0 then Ind.SyntacticOrd.compare ind1 ind2 else c
+ let hash (ind, i) =
+ Hashset.Combine.combine (Ind.SyntacticOrd.hash ind) (Int.hash i)
+ end
+
+end
+
(** Designation of a (particular) inductive type. *)
-type inductive = MutInd.t (* the name of the inductive type *)
- * int (* the position of this inductive type
- within the block of mutually-recursive inductive types.
- BEWARE: indexing starts from 0. *)
+type inductive = Ind.t
(** Designation of a (particular) constructor of a (particular) inductive type. *)
-type constructor = inductive (* designates the inductive type *)
- * int (* the index of the constructor
- BEWARE: indexing starts from 1. *)
+type constructor = Construct.t
-let ind_modpath (mind,_) = MutInd.modpath mind
-let constr_modpath (ind,_) = ind_modpath ind
+let ind_modpath = Ind.modpath
+let constr_modpath = Construct.modpath
let ith_mutual_inductive (mind, _) i = (mind, i)
let ith_constructor_of_inductive ind i = (ind, i)
let inductive_of_constructor (ind, _i) = ind
let index_of_constructor (_ind, i) = i
-let eq_ind (m1, i1) (m2, i2) = Int.equal i1 i2 && MutInd.equal m1 m2
-let eq_user_ind (m1, i1) (m2, i2) =
- Int.equal i1 i2 && MutInd.UserOrd.equal m1 m2
-let eq_syntactic_ind (m1, i1) (m2, i2) =
- Int.equal i1 i2 && MutInd.SyntacticOrd.equal m1 m2
-
-let ind_ord (m1, i1) (m2, i2) =
- let c = Int.compare i1 i2 in
- if Int.equal c 0 then MutInd.CanOrd.compare m1 m2 else c
-let ind_user_ord (m1, i1) (m2, i2) =
- let c = Int.compare i1 i2 in
- if Int.equal c 0 then MutInd.UserOrd.compare m1 m2 else c
-let ind_syntactic_ord (m1, i1) (m2, i2) =
- let c = Int.compare i1 i2 in
- if Int.equal c 0 then MutInd.SyntacticOrd.compare m1 m2 else c
-
-let ind_hash (m, i) =
- Hashset.Combine.combine (MutInd.hash m) (Int.hash i)
-let ind_user_hash (m, i) =
- Hashset.Combine.combine (MutInd.UserOrd.hash m) (Int.hash i)
-let ind_syntactic_hash (m, i) =
- Hashset.Combine.combine (MutInd.SyntacticOrd.hash m) (Int.hash i)
-
-let eq_constructor (ind1, j1) (ind2, j2) = Int.equal j1 j2 && eq_ind ind1 ind2
-let eq_user_constructor (ind1, j1) (ind2, j2) =
- Int.equal j1 j2 && eq_user_ind ind1 ind2
-let eq_syntactic_constructor (ind1, j1) (ind2, j2) =
- Int.equal j1 j2 && eq_syntactic_ind ind1 ind2
-
-let constructor_ord (ind1, j1) (ind2, j2) =
- let c = Int.compare j1 j2 in
- if Int.equal c 0 then ind_ord ind1 ind2 else c
-let constructor_user_ord (ind1, j1) (ind2, j2) =
- let c = Int.compare j1 j2 in
- if Int.equal c 0 then ind_user_ord ind1 ind2 else c
-let constructor_syntactic_ord (ind1, j1) (ind2, j2) =
- let c = Int.compare j1 j2 in
- if Int.equal c 0 then ind_syntactic_ord ind1 ind2 else c
-
-let constructor_hash (ind, i) =
- Hashset.Combine.combine (ind_hash ind) (Int.hash i)
-let constructor_user_hash (ind, i) =
- Hashset.Combine.combine (ind_user_hash ind) (Int.hash i)
-let constructor_syntactic_hash (ind, i) =
- Hashset.Combine.combine (ind_syntactic_hash ind) (Int.hash i)
-
-module InductiveOrdered = struct
- type t = inductive
- let compare = ind_ord
-end
+let eq_ind = Ind.CanOrd.equal
+let eq_user_ind = Ind.UserOrd.equal
+let eq_syntactic_ind = Ind.SyntacticOrd.equal
-module InductiveOrdered_env = struct
- type t = inductive
- let compare = ind_user_ord
-end
+let ind_ord = Ind.CanOrd.compare
+let ind_user_ord = Ind.UserOrd.compare
+let ind_syntactic_ord = Ind.SyntacticOrd.compare
-module Indset = Set.Make(InductiveOrdered)
-module Indset_env = Set.Make(InductiveOrdered_env)
-module Indmap = Map.Make(InductiveOrdered)
-module Indmap_env = Map.Make(InductiveOrdered_env)
+let ind_hash = Ind.CanOrd.hash
+let ind_user_hash = Ind.UserOrd.hash
+let ind_syntactic_hash = Ind.SyntacticOrd.hash
-module ConstructorOrdered = struct
- type t = constructor
- let compare = constructor_ord
-end
+let eq_constructor = Construct.CanOrd.equal
+let eq_user_constructor = Construct.UserOrd.equal
+let eq_syntactic_constructor = Construct.SyntacticOrd.equal
-module ConstructorOrdered_env = struct
- type t = constructor
- let compare = constructor_user_ord
-end
+let constructor_ord = Construct.CanOrd.compare
+let constructor_user_ord = Construct.UserOrd.compare
+let constructor_syntactic_ord = Construct.SyntacticOrd.compare
+
+let constructor_hash = Construct.CanOrd.hash
+let constructor_user_hash = Construct.UserOrd.hash
+let constructor_syntactic_hash = Construct.SyntacticOrd.hash
+
+module Indset = Set.Make(Ind.CanOrd)
+module Indset_env = Set.Make(Ind.UserOrd)
+module Indmap = Map.Make(Ind.CanOrd)
+module Indmap_env = Map.Make(Ind.UserOrd)
-module Constrset = Set.Make(ConstructorOrdered)
-module Constrset_env = Set.Make(ConstructorOrdered_env)
-module Constrmap = Map.Make(ConstructorOrdered)
-module Constrmap_env = Map.Make(ConstructorOrdered_env)
+module Constrset = Set.Make(Construct.CanOrd)
+module Constrset_env = Set.Make(Construct.UserOrd)
+module Constrmap = Map.Make(Construct.CanOrd)
+module Constrmap_env = Map.Make(Construct.UserOrd)
(** {6 Hash-consing of name objects } *)
@@ -786,6 +850,8 @@ struct
Hashset.Combine.combinesmall p.proj_arg (ind_hash p.proj_ind)
module SyntacticOrd = struct
+ type nonrec t = t
+
let compare a b =
let c = ind_syntactic_ord a.proj_ind b.proj_ind in
if c == 0 then Int.compare a.proj_arg b.proj_arg
@@ -798,6 +864,8 @@ struct
Hashset.Combine.combinesmall p.proj_arg (ind_hash p.proj_ind)
end
module CanOrd = struct
+ type nonrec t = t
+
let compare a b =
let c = ind_ord a.proj_ind b.proj_ind in
if c == 0 then Int.compare a.proj_arg b.proj_arg
@@ -810,6 +878,8 @@ struct
Hashset.Combine.combinesmall p.proj_arg (ind_hash p.proj_ind)
end
module UserOrd = struct
+ type nonrec t = t
+
let compare a b =
let c = ind_user_ord a.proj_ind b.proj_ind in
if c == 0 then Int.compare a.proj_arg b.proj_arg
@@ -876,6 +946,7 @@ struct
let hash (c, b) = (if b then 0 else 1) + Repr.hash c
module SyntacticOrd = struct
+ type nonrec t = t
let compare (c, b) (c', b') =
if b = b' then Repr.SyntacticOrd.compare c c' else -1
let equal (c, b as x) (c', b' as x') =
@@ -883,12 +954,21 @@ struct
let hash (c, b) = (if b then 0 else 1) + Repr.SyntacticOrd.hash c
end
module CanOrd = struct
+ type nonrec t = t
let compare (c, b) (c', b') =
if b = b' then Repr.CanOrd.compare c c' else -1
let equal (c, b as x) (c', b' as x') =
x == x' || b = b' && Repr.CanOrd.equal c c'
let hash (c, b) = (if b then 0 else 1) + Repr.CanOrd.hash c
end
+ module UserOrd = struct
+ type nonrec t = t
+ let compare (c, b) (c', b') =
+ if b = b' then Repr.UserOrd.compare c c' else -1
+ let equal (c, b as x) (c', b' as x') =
+ x == x' || b = b' && Repr.UserOrd.equal c c'
+ let hash (c, b) = (if b then 0 else 1) + Repr.UserOrd.hash c
+ end
module Self_Hashcons =
struct
@@ -982,31 +1062,36 @@ module GlobRef = struct
(* By default, [global_reference] are ordered on their canonical part *)
- module Ordered = struct
- open Constant.CanOrd
+ module CanOrd = struct
type t = GlobRefInternal.t
let compare gr1 gr2 =
- GlobRefInternal.global_ord_gen compare ind_ord constructor_ord gr1 gr2
- let equal gr1 gr2 = GlobRefInternal.global_eq_gen equal eq_ind eq_constructor gr1 gr2
- let hash gr = GlobRefInternal.global_hash_gen hash ind_hash constructor_hash gr
+ GlobRefInternal.global_ord_gen Constant.CanOrd.compare Ind.CanOrd.compare Construct.CanOrd.compare gr1 gr2
+ let equal gr1 gr2 = GlobRefInternal.global_eq_gen Constant.CanOrd.equal Ind.CanOrd.equal Construct.CanOrd.equal gr1 gr2
+ let hash gr = GlobRefInternal.global_hash_gen Constant.CanOrd.hash Ind.CanOrd.hash Construct.CanOrd.hash gr
end
- module Ordered_env = struct
- open Constant.UserOrd
+ module UserOrd = struct
+ type t = GlobRefInternal.t
+ let compare gr1 gr2 =
+ GlobRefInternal.global_ord_gen Constant.UserOrd.compare Ind.UserOrd.compare Construct.UserOrd.compare gr1 gr2
+ let equal gr1 gr2 = GlobRefInternal.global_eq_gen Constant.UserOrd.equal Ind.UserOrd.equal Construct.UserOrd.equal gr1 gr2
+ let hash gr = GlobRefInternal.global_hash_gen Constant.UserOrd.hash Ind.UserOrd.hash Construct.UserOrd.hash gr
+ end
+
+ module SyntacticOrd = struct
type t = GlobRefInternal.t
let compare gr1 gr2 =
- GlobRefInternal.global_ord_gen compare ind_user_ord constructor_user_ord gr1 gr2
- let equal gr1 gr2 =
- GlobRefInternal.global_eq_gen equal eq_user_ind eq_user_constructor gr1 gr2
- let hash gr = GlobRefInternal.global_hash_gen hash ind_user_hash constructor_user_hash gr
+ GlobRefInternal.global_ord_gen Constant.SyntacticOrd.compare Ind.SyntacticOrd.compare Construct.SyntacticOrd.compare gr1 gr2
+ let equal gr1 gr2 = GlobRefInternal.global_eq_gen Constant.SyntacticOrd.equal Ind.SyntacticOrd.equal Construct.SyntacticOrd.equal gr1 gr2
+ let hash gr = GlobRefInternal.global_hash_gen Constant.SyntacticOrd.hash Ind.SyntacticOrd.hash Construct.SyntacticOrd.hash gr
end
- module Map = HMap.Make(Ordered)
+ module Map = HMap.Make(CanOrd)
module Set = Map.Set
(* Alternative sets and maps indexed by the user part of the kernel names *)
- module Map_env = HMap.Make(Ordered_env)
+ module Map_env = HMap.Make(UserOrd)
module Set_env = Map_env.Set
end
diff --git a/kernel/names.mli b/kernel/names.mli
index ea137ad1f4..9a4ceef802 100644
--- a/kernel/names.mli
+++ b/kernel/names.mli
@@ -307,6 +307,60 @@ module KNset : CSig.SetS with type elt = KerName.t
module KNpred : Predicate.S with type elt = KerName.t
module KNmap : Map.ExtS with type key = KerName.t and module Set := KNset
+(** {6 Signature for quotiented names} *)
+
+module type EqType =
+sig
+ type t
+ val compare : t -> t -> int
+ val equal : t -> t -> bool
+ val hash : t -> int
+end
+
+module type QNameS =
+sig
+ type t
+ (** A type of reference that implements an implicit quotient by containing
+ two different names. The first one is the user name, i.e. what the user
+ sees when printing. The second one is the canonical name, which is the
+ actual absolute name of the reference.
+
+ This mechanism is fundamentally tied to the module system of Coq. Functor
+ application and module inclusion are the typical ways to introduce names
+ where the canonical and user components differ. In particular, the two
+ components should be undistinguishable from the point of view of typing,
+ i.e. from a "kernel" ground. This aliasing only makes sense inside an
+ environment, but at this point this notion is not even defined so, this
+ dual name trick is fragile. One has to ensure many invariants when
+ creating such names, but the kernel is quite lenient when it comes to
+ checking that these invariants hold. (Read: there are soundness bugs
+ lurking in the module system.)
+
+ One could enforce the invariants by splitting the names and storing that
+ information in the environment instead, but unfortunately, this wreaks
+ havoc in the upper layers. The latter are infamously not stable by
+ syntactic equality, in particular they might observe the difference
+ between canonical and user names if not packed together.
+
+ For this reason, it is discouraged to use the canonical-accessing API
+ in the upper layers, notably the [CanOrd] module below. Instead, one
+ should use their quotiented versions defined in the [Environ] module.
+ Eventually all uses to [CanOrd] outside of the kernel should be removed.
+
+ CAVEAT: name sets and maps are still exposing a canonical-accessing API
+ surreptitiously. *)
+
+ module CanOrd : EqType with type t = t
+ (** Equality functions over the canonical name. Their use should be
+ restricted to the kernel. *)
+
+ module UserOrd : EqType with type t = t
+ (** Equality functions over the user name. *)
+
+ module SyntacticOrd : EqType with type t = t
+ (** Equality functions using both names, for low-level uses. *)
+end
+
(** {6 Constant Names } *)
module Constant:
@@ -340,28 +394,12 @@ sig
(** Comparisons *)
- module CanOrd : sig
- val compare : t -> t -> int
- val equal : t -> t -> bool
- val hash : t -> int
- end
-
- module UserOrd : sig
- val compare : t -> t -> int
- val equal : t -> t -> bool
- val hash : t -> int
- end
+ include QNameS with type t := t
- module SyntacticOrd : sig
- val compare : t -> t -> int
- val equal : t -> t -> bool
- val hash : t -> int
- end
-
- val equal : t -> t -> bool
+ val equal : t -> t -> bool [@@ocaml.deprecated "Use QConstant.equal"]
(** Default comparison, alias for [CanOrd.equal] *)
- val hash : t -> int
+ val hash : t -> int [@@ocaml.deprecated "Use QConstant.hash"]
(** Hashing function *)
val change_label : t -> Label.t -> t
@@ -430,28 +468,12 @@ sig
(** Comparisons *)
- module CanOrd : sig
- val compare : t -> t -> int
- val equal : t -> t -> bool
- val hash : t -> int
- end
-
- module UserOrd : sig
- val compare : t -> t -> int
- val equal : t -> t -> bool
- val hash : t -> int
- end
-
- module SyntacticOrd : sig
- val compare : t -> t -> int
- val equal : t -> t -> bool
- val hash : t -> int
- end
+ include QNameS with type t := t
- val equal : t -> t -> bool
- (** Default comparison, alias for [CanOrd.equal] *)
+ val equal : t -> t -> bool [@@ocaml.deprecated "Use QMutInd.equal"]
+ (** Default comparison, alias for [CanOrd.equal] *)
- val hash : t -> int
+ val hash : t -> int [@@ocaml.deprecated "Use QMutInd.hash"]
(** Displaying *)
@@ -473,16 +495,35 @@ module Mindset : CSig.SetS with type elt = MutInd.t
module Mindmap : Map.ExtS with type key = MutInd.t and module Set := Mindset
module Mindmap_env : CMap.ExtS with type key = MutInd.t
-(** Designation of a (particular) inductive type. *)
-type inductive = MutInd.t (* the name of the inductive type *)
- * int (* the position of this inductive type
- within the block of mutually-recursive inductive types.
- BEWARE: indexing starts from 0. *)
+module Ind :
+sig
+ (** Designation of a (particular) inductive type. *)
+ type t = MutInd.t (* the name of the inductive type *)
+ * int (* the position of this inductive type
+ within the block of mutually-recursive inductive types.
+ BEWARE: indexing starts from 0. *)
+ val modpath : t -> ModPath.t
+
+ include QNameS with type t := t
+
+end
+
+type inductive = Ind.t
-(** Designation of a (particular) constructor of a (particular) inductive type. *)
-type constructor = inductive (* designates the inductive type *)
- * int (* the index of the constructor
- BEWARE: indexing starts from 1. *)
+module Construct :
+sig
+ (** Designation of a (particular) constructor of a (particular) inductive type. *)
+ type t = Ind.t (* designates the inductive type *)
+ * int (* the index of the constructor
+ BEWARE: indexing starts from 1. *)
+
+ val modpath : t -> ModPath.t
+
+ include QNameS with type t := t
+
+end
+
+type constructor = Construct.t
module Indset : CSet.S with type elt = inductive
module Constrset : CSet.S with type elt = constructor
@@ -494,30 +535,51 @@ module Indmap_env : CMap.ExtS with type key = inductive and module Set := Indset
module Constrmap_env : CMap.ExtS with type key = constructor and module Set := Constrset_env
val ind_modpath : inductive -> ModPath.t
+[@@ocaml.deprecated "Use the Ind module"]
+
val constr_modpath : constructor -> ModPath.t
+[@@ocaml.deprecated "Use the Construct module"]
val ith_mutual_inductive : inductive -> int -> inductive
val ith_constructor_of_inductive : inductive -> int -> constructor
val inductive_of_constructor : constructor -> inductive
val index_of_constructor : constructor -> int
val eq_ind : inductive -> inductive -> bool
+[@@ocaml.deprecated "Use the Ind module"]
val eq_user_ind : inductive -> inductive -> bool
+[@@ocaml.deprecated "Use the Ind module"]
val eq_syntactic_ind : inductive -> inductive -> bool
+[@@ocaml.deprecated "Use the Ind module"]
val ind_ord : inductive -> inductive -> int
+[@@ocaml.deprecated "Use the Ind module"]
val ind_hash : inductive -> int
+[@@ocaml.deprecated "Use the Ind module"]
val ind_user_ord : inductive -> inductive -> int
+[@@ocaml.deprecated "Use the Ind module"]
val ind_user_hash : inductive -> int
+[@@ocaml.deprecated "Use the Ind module"]
val ind_syntactic_ord : inductive -> inductive -> int
+[@@ocaml.deprecated "Use the Ind module"]
val ind_syntactic_hash : inductive -> int
+[@@ocaml.deprecated "Use the Ind module"]
val eq_constructor : constructor -> constructor -> bool
+[@@ocaml.deprecated "Use the Construct module"]
val eq_user_constructor : constructor -> constructor -> bool
+[@@ocaml.deprecated "Use the Construct module"]
val eq_syntactic_constructor : constructor -> constructor -> bool
+[@@ocaml.deprecated "Use the Construct module"]
val constructor_ord : constructor -> constructor -> int
+[@@ocaml.deprecated "Use the Construct module"]
val constructor_hash : constructor -> int
+[@@ocaml.deprecated "Use the Construct module"]
val constructor_user_ord : constructor -> constructor -> int
+[@@ocaml.deprecated "Use the Construct module"]
val constructor_user_hash : constructor -> int
+[@@ocaml.deprecated "Use the Construct module"]
val constructor_syntactic_ord : constructor -> constructor -> int
+[@@ocaml.deprecated "Use the Construct module"]
val constructor_syntactic_hash : constructor -> int
+[@@ocaml.deprecated "Use the Construct module"]
(** {6 Hash-consing } *)
@@ -558,21 +620,7 @@ module Projection : sig
val make : inductive -> proj_npars:int -> proj_arg:int -> Label.t -> t
- module SyntacticOrd : sig
- val compare : t -> t -> int
- val equal : t -> t -> bool
- val hash : t -> int
- end
- module CanOrd : sig
- val compare : t -> t -> int
- val equal : t -> t -> bool
- val hash : t -> int
- end
- module UserOrd : sig
- val compare : t -> t -> int
- val equal : t -> t -> bool
- val hash : t -> int
- end
+ include QNameS with type t := t
val constant : t -> Constant.t
(** Don't use this if you don't have to. *)
@@ -583,9 +631,9 @@ module Projection : sig
val arg : t -> int
val label : t -> Label.t
- val equal : t -> t -> bool
- val hash : t -> int
- val compare : t -> t -> int
+ val equal : t -> t -> bool [@@ocaml.deprecated "Use QProjection.equal"]
+ val hash : t -> int [@@ocaml.deprecated "Use QProjection.hash"]
+ val compare : t -> t -> int [@@ocaml.deprecated "Use QProjection.compare"]
val map : (MutInd.t -> MutInd.t) -> t -> t
val map_npars : (MutInd.t -> int -> MutInd.t * int) -> t -> t
@@ -602,16 +650,7 @@ module Projection : sig
val make : Repr.t -> bool -> t
val repr : t -> Repr.t
- module SyntacticOrd : sig
- val compare : t -> t -> int
- val equal : t -> t -> bool
- val hash : t -> int
- end
- module CanOrd : sig
- val compare : t -> t -> int
- val equal : t -> t -> bool
- val hash : t -> int
- end
+ include QNameS with type t := t
val constant : t -> Constant.t
val mind : t -> MutInd.t
@@ -623,14 +662,18 @@ module Projection : sig
val unfold : t -> t
val equal : t -> t -> bool
+ [@@ocaml.deprecated "Use QProjection.equal"]
val hash : t -> int
+ [@@ocaml.deprecated "Use QProjection.hash"]
val hcons : t -> t
(** Hashconsing of projections. *)
val repr_equal : t -> t -> bool
+ [@@ocaml.deprecated "Use an explicit projection of Repr"]
(** Ignoring the unfolding boolean. *)
val compare : t -> t -> int
+ [@@ocaml.deprecated "Use QProjection.compare"]
val map : (MutInd.t -> MutInd.t) -> t -> t
val map_npars : (MutInd.t -> int -> MutInd.t * int) -> t -> t
@@ -656,19 +699,7 @@ module GlobRef : sig
val equal : t -> t -> bool
- module Ordered : sig
- type nonrec t = t
- val compare : t -> t -> int
- val equal : t -> t -> bool
- val hash : t -> int
- end
-
- module Ordered_env : sig
- type nonrec t = t
- val compare : t -> t -> int
- val equal : t -> t -> bool
- val hash : t -> int
- end
+ include QNameS with type t := t
module Set_env : CSig.SetS with type elt = t
module Map_env : Map.ExtS
diff --git a/kernel/nativecode.ml b/kernel/nativecode.ml
index ae070e6f8e..b5c4d6416a 100644
--- a/kernel/nativecode.ml
+++ b/kernel/nativecode.ml
@@ -65,11 +65,11 @@ type gname =
let eq_gname gn1 gn2 =
match gn1, gn2 with
| Gind (s1, ind1), Gind (s2, ind2) ->
- String.equal s1 s2 && eq_ind ind1 ind2
+ String.equal s1 s2 && Ind.CanOrd.equal ind1 ind2
| Gconstant (s1, c1), Gconstant (s2, c2) ->
- String.equal s1 s2 && Constant.equal c1 c2
+ String.equal s1 s2 && Constant.CanOrd.equal c1 c2
| Gproj (s1, ind1, i1), Gproj (s2, ind2, i2) ->
- String.equal s1 s2 && eq_ind ind1 ind2 && Int.equal i1 i2
+ String.equal s1 s2 && Ind.CanOrd.equal ind1 ind2 && Int.equal i1 i2
| Gcase (None, i1), Gcase (None, i2) -> Int.equal i1 i2
| Gcase (Some l1, i1), Gcase (Some l2, i2) -> Int.equal i1 i2 && Label.equal l1 l2
| Gpred (None, i1), Gpred (None, i2) -> Int.equal i1 i2
@@ -96,9 +96,9 @@ open Hashset.Combine
let gname_hash gn = match gn with
| Gind (s, ind) ->
- combinesmall 1 (combine (String.hash s) (ind_hash ind))
+ combinesmall 1 (combine (String.hash s) (Ind.CanOrd.hash ind))
| Gconstant (s, c) ->
- combinesmall 2 (combine (String.hash s) (Constant.hash c))
+ combinesmall 2 (combine (String.hash s) (Constant.CanOrd.hash c))
| Gcase (l, i) -> combinesmall 3 (combine (Option.hash Label.hash l) (Int.hash i))
| Gpred (l, i) -> combinesmall 4 (combine (Option.hash Label.hash l) (Int.hash i))
| Gfixtype (l, i) -> combinesmall 5 (combine (Option.hash Label.hash l) (Int.hash i))
@@ -107,7 +107,7 @@ let gname_hash gn = match gn with
| Ginternal s -> combinesmall 8 (String.hash s)
| Grel i -> combinesmall 9 (Int.hash i)
| Gnamed id -> combinesmall 10 (Id.hash id)
-| Gproj (s, p, i) -> combinesmall 11 (combine (String.hash s) (combine (ind_hash p) i))
+| Gproj (s, p, i) -> combinesmall 11 (combine (String.hash s) (combine (Ind.CanOrd.hash p) i))
let case_ctr = ref (-1)
@@ -148,13 +148,13 @@ let eq_symbol sy1 sy2 =
| SymbValue v1, SymbValue v2 -> (=) v1 v2 (** FIXME: how is this even valid? *)
| SymbSort s1, SymbSort s2 -> Sorts.equal s1 s2
| SymbName n1, SymbName n2 -> Name.equal n1 n2
- | SymbConst kn1, SymbConst kn2 -> Constant.equal kn1 kn2
+ | SymbConst kn1, SymbConst kn2 -> Constant.CanOrd.equal kn1 kn2
| SymbMatch sw1, SymbMatch sw2 -> eq_annot_sw sw1 sw2
- | SymbInd ind1, SymbInd ind2 -> eq_ind ind1 ind2
+ | SymbInd ind1, SymbInd ind2 -> Ind.CanOrd.equal ind1 ind2
| SymbMeta m1, SymbMeta m2 -> Int.equal m1 m2
| SymbEvar evk1, SymbEvar evk2 -> Evar.equal evk1 evk2
| SymbLevel l1, SymbLevel l2 -> Univ.Level.equal l1 l2
- | SymbProj (i1, k1), SymbProj (i2, k2) -> eq_ind i1 i2 && Int.equal k1 k2
+ | SymbProj (i1, k1), SymbProj (i2, k2) -> Ind.CanOrd.equal i1 i2 && Int.equal k1 k2
| _, _ -> false
let hash_symbol symb =
@@ -162,13 +162,13 @@ let hash_symbol symb =
| SymbValue v -> combinesmall 1 (Hashtbl.hash v) (** FIXME *)
| SymbSort s -> combinesmall 2 (Sorts.hash s)
| SymbName name -> combinesmall 3 (Name.hash name)
- | SymbConst c -> combinesmall 4 (Constant.hash c)
+ | SymbConst c -> combinesmall 4 (Constant.CanOrd.hash c)
| SymbMatch sw -> combinesmall 5 (hash_annot_sw sw)
- | SymbInd ind -> combinesmall 6 (ind_hash ind)
+ | SymbInd ind -> combinesmall 6 (Ind.CanOrd.hash ind)
| SymbMeta m -> combinesmall 7 m
| SymbEvar evk -> combinesmall 8 (Evar.hash evk)
| SymbLevel l -> combinesmall 9 (Univ.Level.hash l)
- | SymbProj (i, k) -> combinesmall 10 (combine (ind_hash i) k)
+ | SymbProj (i, k) -> combinesmall 10 (combine (Ind.CanOrd.hash i) k)
module HashedTypeSymbol = struct
type t = symbol
@@ -438,7 +438,7 @@ let rec eq_mllambda gn1 gn2 n env1 env2 t1 t2 =
eq_mllam_branches gn1 gn2 n env1 env2 br1 br2
| MLconstruct (pf1, ind1, tag1, args1), MLconstruct (pf2, ind2, tag2, args2) ->
String.equal pf1 pf2 &&
- eq_ind ind1 ind2 &&
+ Ind.CanOrd.equal ind1 ind2 &&
Int.equal tag1 tag2 &&
Array.equal (eq_mllambda gn1 gn2 n env1 env2) args1 args2
| MLint i1, MLint i2 ->
@@ -457,7 +457,7 @@ let rec eq_mllambda gn1 gn2 n env1 env2 t1 t2 =
Array.equal (eq_mllambda gn1 gn2 n env1 env2) arr1 arr2
| MLisaccu (s1, ind1, ml1), MLisaccu (s2, ind2, ml2) ->
- String.equal s1 s2 && eq_ind ind1 ind2 &&
+ String.equal s1 s2 && Ind.CanOrd.equal ind1 ind2 &&
eq_mllambda gn1 gn2 n env1 env2 ml1 ml2
| (MLlocal _ | MLglobal _ | MLprimitive _ | MLlam _ | MLletrec _ | MLlet _ |
MLapp _ | MLif _ | MLmatch _ | MLconstruct _ | MLint _ | MLuint _ |
@@ -527,7 +527,7 @@ let rec hash_mllambda gn n env t =
combinesmall 9 (hash_mllam_branches gn n env (combine3 hannot hc haccu) br)
| MLconstruct (pf, ind, tag, args) ->
let hpf = String.hash pf in
- let hcs = ind_hash ind in
+ let hcs = Ind.CanOrd.hash ind in
let htag = Int.hash tag in
combinesmall 10 (hash_mllambda_array gn n env (combine3 hpf hcs htag) args)
| MLint i ->
@@ -545,7 +545,7 @@ let rec hash_mllambda gn n env t =
| MLarray arr ->
combinesmall 15 (hash_mllambda_array gn n env 1 arr)
| MLisaccu (s, ind, c) ->
- combinesmall 16 (combine (String.hash s) (combine (ind_hash ind) (hash_mllambda gn n env c)))
+ combinesmall 16 (combine (String.hash s) (combine (Ind.CanOrd.hash ind) (hash_mllambda gn n env c)))
| MLfloat f ->
combinesmall 17 (Float64.hash f)
@@ -689,7 +689,7 @@ let eq_global g1 g2 =
eq_mllambda gn1 gn2 (Array.length lns1) env1 env2 t1 t2
| Gopen s1, Gopen s2 -> String.equal s1 s2
| Gtype (ind1, arr1), Gtype (ind2, arr2) ->
- eq_ind ind1 ind2 &&
+ Ind.CanOrd.equal ind1 ind2 &&
Array.equal (fun (tag1,ar1) (tag2,ar2) -> Int.equal tag1 tag2 && Int.equal ar1 ar2) arr1 arr2
| Gcomment s1, Gcomment s2 -> String.equal s1 s2
| _, _ -> false
@@ -720,7 +720,7 @@ let hash_global g =
let hash_aux acc (tag,ar) =
combine3 acc (Int.hash tag) (Int.hash ar)
in
- combinesmall 6 (combine (ind_hash ind) (Array.fold_left hash_aux 0 arr))
+ combinesmall 6 (combine (Ind.CanOrd.hash ind) (Array.fold_left hash_aux 0 arr))
| Gcomment s -> combinesmall 7 (String.hash s)
let global_stack = ref ([] : global list)
diff --git a/kernel/nativeconv.ml b/kernel/nativeconv.ml
index 01e9550ec5..76215b4386 100644
--- a/kernel/nativeconv.ml
+++ b/kernel/nativeconv.ml
@@ -80,17 +80,17 @@ and conv_atom env pb lvl a1 a2 cu =
| Arel i1, Arel i2 ->
if Int.equal i1 i2 then cu else raise NotConvertible
| Aind (ind1,u1), Aind (ind2,u2) ->
- if eq_ind ind1 ind2 then convert_instances ~flex:false u1 u2 cu
+ if Ind.CanOrd.equal ind1 ind2 then convert_instances ~flex:false u1 u2 cu
else raise NotConvertible
| Aconstant (c1,u1), Aconstant (c2,u2) ->
- if Constant.equal c1 c2 then convert_instances ~flex:true u1 u2 cu
+ if Constant.CanOrd.equal c1 c2 then convert_instances ~flex:true u1 u2 cu
else raise NotConvertible
| Asort s1, Asort s2 ->
sort_cmp_universes env pb s1 s2 cu
| Avar id1, Avar id2 ->
if Id.equal id1 id2 then cu else raise NotConvertible
| Acase(a1,ac1,p1,bs1), Acase(a2,ac2,p2,bs2) ->
- if not (eq_ind a1.asw_ind a2.asw_ind) then raise NotConvertible;
+ if not (Ind.CanOrd.equal a1.asw_ind a2.asw_ind) then raise NotConvertible;
let cu = conv_accu env CONV lvl ac1 ac2 cu in
let tbl = a1.asw_reloc in
let len = Array.length tbl in
@@ -124,7 +124,7 @@ and conv_atom env pb lvl a1 a2 cu =
let v = mk_rel_accu lvl in
conv_val env pb (lvl + 1) (d1 v) (d2 v) cu
| Aproj((ind1, i1), ac1), Aproj((ind2, i2), ac2) ->
- if not (eq_ind ind1 ind2 && Int.equal i1 i2) then raise NotConvertible
+ if not (Ind.CanOrd.equal ind1 ind2 && Int.equal i1 i2) then raise NotConvertible
else conv_accu env CONV lvl ac1 ac2 cu
| Arel _, _ | Aind _, _ | Aconstant _, _ | Asort _, _ | Avar _, _
| Acase _, _ | Afix _, _ | Acofix _, _ | Acofixe _, _ | Aprod _, _
@@ -176,7 +176,7 @@ let native_conv cv_pb sigma env t1 t2 =
else Constr.eq_constr_univs univs t1 t2
in
if not b then
- let univs = (univs, checked_universes) in
+ let state = (univs, checked_universes) in
let t1 = Term.it_mkLambda_or_LetIn t1 (Environ.rel_context env) in
let t2 = Term.it_mkLambda_or_LetIn t2 (Environ.rel_context env) in
- let _ = native_conv_gen cv_pb sigma env univs t1 t2 in ()
+ let _ = native_conv_gen cv_pb sigma env state t1 t2 in ()
diff --git a/kernel/nativelambda.ml b/kernel/nativelambda.ml
index 99090f0147..e98e97907a 100644
--- a/kernel/nativelambda.ml
+++ b/kernel/nativelambda.ml
@@ -433,8 +433,8 @@ module Cache =
module ConstrHash =
struct
type t = constructor
- let equal = eq_constructor
- let hash = constructor_hash
+ let equal = Construct.CanOrd.equal
+ let hash = Construct.CanOrd.hash
end
module ConstrTable = Hashtbl.Make(ConstrHash)
diff --git a/kernel/nativelib.ml b/kernel/nativelib.ml
index 494282d4e1..c1f14923fa 100644
--- a/kernel/nativelib.ml
+++ b/kernel/nativelib.ml
@@ -25,7 +25,8 @@ let open_header = ["Nativevalues";
let open_header = List.map mk_open open_header
(* Directory where compiled files are stored *)
-let output_dir = ref ".coq-native"
+let dft_output_dir = ".coq-native"
+let output_dir = ref dft_output_dir
(* Extension of generated ml files, stored for debugging purposes *)
let source_ext = ".native"
@@ -92,9 +93,14 @@ let error_native_compiler_failed e =
CErrors.user_err msg
let call_compiler ?profile:(profile=false) ml_filename =
- let load_path = !get_load_paths () in
- let load_path = List.map (fun dn -> dn / !output_dir) load_path in
- let include_dirs = List.flatten (List.map (fun x -> ["-I"; x]) (get_include_dirs () @ load_path)) in
+ (* The below path is computed from Require statements, by uniquizing
+ the paths, see [Library.get_used_load_paths] This is in general
+ hacky and we should do a bit better once we move loadpath to its
+ own library *)
+ let require_load_path = !get_load_paths () in
+ (* We assume that installed files always go in .coq-native for now *)
+ let install_load_path = List.map (fun dn -> dn / dft_output_dir) require_load_path in
+ let include_dirs = List.flatten (List.map (fun x -> ["-I"; x]) (get_include_dirs () @ install_load_path)) in
let f = Filename.chop_extension ml_filename in
let link_filename = f ^ ".cmo" in
let link_filename = Dynlink.adapt_filename link_filename in
@@ -186,5 +192,10 @@ let call_linker ?(fatal=true) env ~prefix f upds =
match upds with Some upds -> update_locations upds | _ -> ()
let link_library env ~prefix ~dirname ~basename =
- let f = dirname / !output_dir / basename in
+ (* We try both [output_dir] and [.coq-native], unfortunately from
+ [Require] we don't know if we are loading a library in the build
+ dir or in the installed layout *)
+ let install_location = dirname / dft_output_dir / basename in
+ let build_location = dirname / !output_dir / basename in
+ let f = if Sys.file_exists build_location then build_location else install_location in
call_linker env ~fatal:false ~prefix f None
diff --git a/kernel/nativevalues.ml b/kernel/nativevalues.ml
index 9e17f97a56..bd6241ae67 100644
--- a/kernel/nativevalues.ml
+++ b/kernel/nativevalues.ml
@@ -36,13 +36,13 @@ type annot_sw = {
(* We compare only what is relevant for generation of ml code *)
let eq_annot_sw asw1 asw2 =
- eq_ind asw1.asw_ind asw2.asw_ind &&
+ Ind.CanOrd.equal asw1.asw_ind asw2.asw_ind &&
String.equal asw1.asw_prefix asw2.asw_prefix
open Hashset.Combine
let hash_annot_sw asw =
- combine (ind_hash asw.asw_ind) (String.hash asw.asw_prefix)
+ combine (Ind.CanOrd.hash asw.asw_ind) (String.hash asw.asw_prefix)
type sort_annot = string * int
@@ -739,15 +739,6 @@ let arraycopy accu vA t =
no_check_arraycopy t
else accu vA t
-let no_check_arrayreroot t =
- of_parray (Parray.reroot (to_parray t))
-[@@ocaml.inline always]
-
-let arrayreroot accu vA t =
- if is_parray t then
- no_check_arrayreroot t
- else accu vA t
-
let no_check_arraylength t =
mk_uint (Parray.length (to_parray t))
[@@ocaml.inline always]
diff --git a/kernel/nativevalues.mli b/kernel/nativevalues.mli
index 08c5bd7126..b9b75a9d7c 100644
--- a/kernel/nativevalues.mli
+++ b/kernel/nativevalues.mli
@@ -344,7 +344,6 @@ val arrayget : t -> t -> t -> t -> t (* accu A t n *)
val arraydefault : t -> t -> t (* accu A t *)
val arrayset : t -> t -> t -> t -> t -> t (* accu A t n v *)
val arraycopy : t -> t -> t -> t (* accu A t *)
-val arrayreroot : t -> t -> t -> t (* accu A t *)
val arraylength : t -> t -> t -> t (* accu A t *)
val arrayinit : t -> t -> t -> t (* accu A n f def *)
val arraymap : t -> t -> t (* accu A B f t *)
@@ -364,8 +363,5 @@ val no_check_arrayset : t -> t -> t -> t
val no_check_arraycopy : t -> t
[@@ocaml.inline always]
-val no_check_arrayreroot : t -> t
-[@@ocaml.inline always]
-
val no_check_arraylength : t -> t
[@@ocaml.inline always]
diff --git a/kernel/parray.ml b/kernel/parray.ml
index ea314c1883..0953f4b33f 100644
--- a/kernel/parray.ml
+++ b/kernel/parray.ml
@@ -27,45 +27,52 @@ and 'a kind =
let unsafe_of_array t def = ref (Array (t,def))
let of_array t def = unsafe_of_array (Array.copy t) def
-let rec length_int p =
- match !p with
- | Array (t,_) -> Array.length t
- | Updated (_, _, p) -> length_int p
+let rec rerootk t k =
+ match !t with
+ | Array (a, _) -> k a
+ | Updated (i, v, p) ->
+ let k' a =
+ let v' = Array.unsafe_get a i in
+ Array.unsafe_set a i v;
+ t := !p; (* i.e., Array (a, def) *)
+ p := Updated (i, v', t);
+ k a in
+ rerootk p k'
+
+let reroot t = rerootk t (fun a -> a)
+
+let length_int p =
+ Array.length (reroot p)
let length p = Uint63.of_int @@ length_int p
-let rec get p n =
- match !p with
- | Array (t,def) ->
- let l = Array.length t in
- if Uint63.le Uint63.zero n && Uint63.lt n (Uint63.of_int l) then
- Array.unsafe_get t (length_to_int n)
- else def
- | Updated (k,e,p) ->
- if Uint63.equal n (Uint63.of_int k) then e
- else get p n
+let get p n =
+ let t = reroot p in
+ let l = Array.length t in
+ if Uint63.le Uint63.zero n && Uint63.lt n (Uint63.of_int l) then
+ Array.unsafe_get t (length_to_int n)
+ else
+ match !p with
+ | Array (_, def) -> def
+ | Updated _ -> assert false
let set p n e =
- let kind = !p in
- match kind with
- | Array (t,_) ->
- let l = Uint63.of_int @@ Array.length t in
- if Uint63.le Uint63.zero n && Uint63.lt n l then
- let res = ref kind in
- let n = length_to_int n in
- p := Updated (n, Array.unsafe_get t n, res);
- Array.unsafe_set t n e;
- res
- else p
- | Updated _ ->
- if Uint63.le Uint63.zero n && Uint63.lt n (length p) then
- ref (Updated((length_to_int n), e, p))
- else p
-
-let rec default p =
+ let a = reroot p in
+ let l = Uint63.of_int (Array.length a) in
+ if Uint63.le Uint63.zero n && Uint63.lt n l then
+ let i = length_to_int n in
+ let v' = Array.unsafe_get a i in
+ Array.unsafe_set a i e;
+ let t = ref !p in (* i.e., Array (a, def) *)
+ p := Updated (i, v', t);
+ t
+ else p
+
+let default p =
+ let _ = reroot p in
match !p with
| Array (_,def) -> def
- | Updated (_,_,p) -> default p
+ | Updated _ -> assert false
let make n def =
ref (Array (Array.make (trunc_size n) def, def))
@@ -75,33 +82,19 @@ let init n f def =
let t = Array.init n f in
ref (Array (t, def))
-let rec to_array p =
+let to_array p =
+ let _ = reroot p in
match !p with
| Array (t,def) -> Array.copy t, def
- | Updated (n,e,p) ->
- let (t,_) as r = to_array p in
- Array.unsafe_set t n e; r
+ | Updated _ -> assert false
let copy p =
let (t,def) = to_array p in
ref (Array (t,def))
-let rec rerootk t k =
- match !t with
- | Array _ -> k ()
- | Updated (i, v, t') ->
- let k' () =
- begin match !t' with
- | Array (a,_def) as n ->
- let v' = a.(i) in
- Array.unsafe_set a i v;
- t := n;
- t' := Updated (i, v', t)
- | Updated _ -> assert false
- end; k() in
- rerootk t' k'
-
-let reroot t = rerootk t (fun () -> t)
+let reroot t =
+ let _ = reroot t in
+ t
let map f p =
let p = reroot p in
diff --git a/kernel/parray.mli b/kernel/parray.mli
index 0276278bd0..8b6565c159 100644
--- a/kernel/parray.mli
+++ b/kernel/parray.mli
@@ -19,7 +19,6 @@ val default : 'a t -> 'a
val make : Uint63.t -> 'a -> 'a t
val init : Uint63.t -> (int -> 'a) -> 'a -> 'a t
val copy : 'a t -> 'a t
-val reroot : 'a t -> 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
diff --git a/kernel/primred.ml b/kernel/primred.ml
index 90eeeb9be7..f0b4d6d362 100644
--- a/kernel/primred.ml
+++ b/kernel/primred.ml
@@ -12,11 +12,11 @@ type _ action_kind =
type exn += IncompatibleDeclarations : 'a action_kind * 'a * 'a -> exn
let check_same_types typ c1 c2 =
- if not (Constant.equal c1 c2)
+ if not (Constant.CanOrd.equal c1 c2)
then raise (IncompatibleDeclarations (IncompatTypes typ, c1, c2))
let check_same_inds ind i1 i2 =
- if not (eq_ind i1 i2)
+ if not (Ind.CanOrd.equal i1 i2)
then raise (IncompatibleDeclarations (IncompatInd ind, i1, i2))
let add_retroknowledge retro action =
@@ -365,11 +365,6 @@ struct
let t = get_parray evd args 1 in
let t' = Parray.copy t in
E.mkArray env u t' ty
- | Arrayreroot ->
- let ar = E.get args 1 in
- let t = E.get_parray evd ar in
- let _ = Parray.reroot t in
- ar
| Arraylength ->
let t = get_parray evd args 1 in
E.mkInt env (Parray.length t)
diff --git a/kernel/reduction.ml b/kernel/reduction.ml
index 7c6b869b4a..c891b885c4 100644
--- a/kernel/reduction.ml
+++ b/kernel/reduction.ml
@@ -189,7 +189,7 @@ type 'a kernel_conversion_function = env -> 'a -> 'a -> unit
(* functions of this type can be called from outside the kernel *)
type 'a extended_conversion_function =
?l2r:bool -> ?reds:TransparentState.t -> env ->
- ?evars:((existential->constr option) * UGraph.t) ->
+ ?evars:(existential->constr option) ->
'a -> 'a -> unit
exception NotConvertible
@@ -210,9 +210,6 @@ type conv_pb =
let is_cumul = function CUMUL -> true | CONV -> false
type 'a universe_compare = {
- (* used in reduction *)
- compare_graph : 'a -> UGraph.t;
-
(* Might raise NotConvertible *)
compare_sorts : env -> conv_pb -> Sorts.t -> Sorts.t -> 'a -> 'a;
compare_instances: flex:bool -> Univ.Instance.t -> Univ.Instance.t -> 'a -> 'a;
@@ -224,7 +221,7 @@ type 'a universe_state = 'a * 'a universe_compare
type ('a,'b) generic_conversion_function = env -> 'b universe_state -> 'a -> 'a -> 'b
-type 'a infer_conversion_function = env -> UGraph.t -> 'a -> 'a -> Univ.Constraint.t
+type 'a infer_conversion_function = env -> 'a -> 'a -> Univ.Constraint.t
let sort_cmp_universes env pb s0 s1 (u, check) =
(check.compare_sorts env pb s0 s1 u, check)
@@ -286,7 +283,7 @@ let convert_constructors ctor nargs u1 u2 (s, check) =
let conv_table_key infos k1 k2 cuniv =
if k1 == k2 then cuniv else
match k1, k2 with
- | ConstKey (cst, u), ConstKey (cst', u') when Constant.equal cst cst' ->
+ | ConstKey (cst, u), ConstKey (cst', u') when Constant.CanOrd.equal cst cst' ->
if Univ.Instance.equal u u' then cuniv
else
let flex = evaluable_constant cst (info_env infos)
@@ -304,7 +301,7 @@ let unfold_ref_with_args infos tab fl v =
| Primitive op when check_native_args op v ->
let c = match fl with ConstKey c -> c | _ -> assert false in
let rargs, a, nargs, v = get_native_args1 op c v in
- Some (whd_stack infos tab a (Zupdate a::(Zprimitive(op,c,rargs,nargs)::v)))
+ Some (a, (Zupdate a::(Zprimitive(op,c,rargs,nargs)::v)))
| Undef _ | OpaqueDef _ | Primitive _ -> None
type conv_tab = {
@@ -414,23 +411,26 @@ and eqappr cv_pb l2r infos (lft1,st1) (lft2,st2) cuniv =
let cuniv = conv_table_key infos.cnv_inf fl1 fl2 cuniv in
convert_stacks l2r infos lft1 lft2 v1 v2 cuniv
with NotConvertible | Univ.UniverseInconsistency _ ->
- (* else the oracle tells which constant is to be expanded *)
- let oracle = CClosure.oracle_of_infos infos.cnv_inf in
- let (app1,app2) =
- let aux appr1 lft1 fl1 tab1 v1 appr2 lft2 fl2 tab2 v2 =
- match unfold_ref_with_args infos.cnv_inf tab1 fl1 v1 with
- | Some t1 -> ((lft1, t1), appr2)
- | None -> match unfold_ref_with_args infos.cnv_inf tab2 fl2 v2 with
- | Some t2 -> (appr1, (lft2, t2))
- | None -> raise NotConvertible
- in
- if Conv_oracle.oracle_order Univ.out_punivs oracle l2r fl1 fl2 then
- aux appr1 lft1 fl1 infos.lft_tab v1 appr2 lft2 fl2 infos.rgt_tab v2
- else
- let (app2,app1) = aux appr2 lft2 fl2 infos.rgt_tab v2 appr1 lft1 fl1 infos.lft_tab v1 in
- (app1,app2)
- in
- eqappr cv_pb l2r infos app1 app2 cuniv)
+ let r1 = unfold_ref_with_args infos.cnv_inf infos.lft_tab fl1 v1 in
+ let r2 = unfold_ref_with_args infos.cnv_inf infos.rgt_tab fl2 v2 in
+ match r1, r2 with
+ | None, None -> raise NotConvertible
+ | Some t1, Some t2 ->
+ (* else the oracle tells which constant is to be expanded *)
+ let oracle = CClosure.oracle_of_infos infos.cnv_inf in
+ if Conv_oracle.oracle_order Univ.out_punivs oracle l2r fl1 fl2 then
+ eqappr cv_pb l2r infos (lft1, t1) appr2 cuniv
+ else
+ eqappr cv_pb l2r infos appr1 (lft2, t2) cuniv
+ | Some (t1, v1), None ->
+ let all = RedFlags.red_add_transparent all (RedFlags.red_transparent (info_flags infos.cnv_inf)) in
+ let t1 = whd_stack (infos_with_reds infos.cnv_inf all) infos.lft_tab t1 v1 in
+ eqappr cv_pb l2r infos (lft1, t1) appr2 cuniv
+ | None, Some (t2, v2) ->
+ let all = RedFlags.red_add_transparent all (RedFlags.red_transparent (info_flags infos.cnv_inf)) in
+ let t2 = whd_stack (infos_with_reds infos.cnv_inf all) infos.rgt_tab t2 v2 in
+ eqappr cv_pb l2r infos appr1 (lft2, t2) cuniv
+ )
| (FProj (p1,c1), FProj (p2, c2)) ->
(* Projections: prefer unfolding to first-order unification,
@@ -444,7 +444,7 @@ and eqappr cv_pb l2r infos (lft1,st1) (lft2,st2) cuniv =
| Some s2 ->
eqappr cv_pb l2r infos appr1 (lft2, (c2, (s2 :: v2))) cuniv
| None ->
- if Projection.Repr.equal (Projection.repr p1) (Projection.repr p2)
+ if Projection.Repr.CanOrd.equal (Projection.repr p1) (Projection.repr p2)
&& compare_stack_shape v1 v2 then
let el1 = el_stack lft1 v1 in
let el2 = el_stack lft2 v2 in
@@ -571,7 +571,7 @@ and eqappr cv_pb l2r infos (lft1,st1) (lft2,st2) cuniv =
(* Inductive types: MutInd MutConstruct Fix Cofix *)
| (FInd (ind1,u1 as pind1), FInd (ind2,u2 as pind2)) ->
- if eq_ind ind1 ind2 then
+ if Ind.CanOrd.equal ind1 ind2 then
if Univ.Instance.length u1 = 0 || Univ.Instance.length u2 = 0 then
let cuniv = convert_instances ~flex:false u1 u2 cuniv in
convert_stacks l2r infos lft1 lft2 v1 v2 cuniv
@@ -591,7 +591,7 @@ and eqappr cv_pb l2r infos (lft1,st1) (lft2,st2) cuniv =
else raise NotConvertible
| (FConstruct ((ind1,j1),u1 as pctor1), FConstruct ((ind2,j2),u2 as pctor2)) ->
- if Int.equal j1 j2 && eq_ind ind1 ind2 then
+ if Int.equal j1 j2 && Ind.CanOrd.equal ind1 ind2 then
if Univ.Instance.length u1 = 0 || Univ.Instance.length u2 = 0 then
let cuniv = convert_instances ~flex:false u1 u2 cuniv in
convert_stacks l2r infos lft1 lft2 v1 v2 cuniv
@@ -672,7 +672,7 @@ and eqappr cv_pb l2r infos (lft1,st1) (lft2,st2) cuniv =
else raise NotConvertible
| FCaseInvert (ci1,p1,_,_,br1,e1), FCaseInvert (ci2,p2,_,_,br2,e2) ->
- (if not (eq_ind ci1.ci_ind ci2.ci_ind) then raise NotConvertible);
+ (if not (Ind.CanOrd.equal ci1.ci_ind ci2.ci_ind) then raise NotConvertible);
let el1 = el_stack lft1 v1 and el2 = el_stack lft2 v2 in
let ccnv = ccnv CONV l2r infos el1 el2 in
let cuniv = ccnv (mk_clos e1 p1) (mk_clos e2 p2) cuniv in
@@ -707,14 +707,14 @@ and convert_stacks l2r infos lft1 lft2 stk1 stk2 cuniv =
| (Zlapp a1,Zlapp a2) ->
Array.fold_right2 f a1 a2 cu1
| (Zlproj (c1,_l1),Zlproj (c2,_l2)) ->
- if not (Projection.Repr.equal c1 c2) then
+ if not (Projection.Repr.CanOrd.equal c1 c2) then
raise NotConvertible
else cu1
| (Zlfix(fx1,a1),Zlfix(fx2,a2)) ->
let cu2 = f fx1 fx2 cu1 in
cmp_rec a1 a2 cu2
| (Zlcase(ci1,l1,p1,br1,e1),Zlcase(ci2,l2,p2,br2,e2)) ->
- if not (eq_ind ci1.ci_ind ci2.ci_ind) then
+ if not (Ind.CanOrd.equal ci1.ci_ind ci2.ci_ind) then
raise NotConvertible;
let cu2 = f (l1, mk_clos e1 p1) (l2, mk_clos e2 p2) cu1 in
convert_branches l2r infos ci1 e1 e2 l1 l2 br1 br2 cu2
@@ -765,9 +765,8 @@ and convert_list l2r infos lft1 lft2 v1 v2 cuniv = match v1, v2 with
convert_list l2r infos lft1 lft2 v1 v2 cuniv
| _, _ -> raise NotConvertible
-let clos_gen_conv trans cv_pb l2r evars env univs t1 t2 =
+let clos_gen_conv trans cv_pb l2r evars env graph univs t1 t2 =
let reds = CClosure.RedFlags.red_add_transparent betaiotazeta trans in
- let graph = (snd univs).compare_graph (fst univs) in
let infos = create_clos_infos ~univs:graph ~evars reds env in
let infos = {
cnv_inf = infos;
@@ -815,8 +814,7 @@ let check_inductive_instances cv_pb variance u1 u2 univs =
else raise NotConvertible
let checked_universes =
- { compare_graph = (fun x -> x);
- compare_sorts = checked_sort_cmp_universes;
+ { compare_sorts = checked_sort_cmp_universes;
compare_instances = check_convert_instances;
compare_cumul_instances = check_inductive_instances; }
@@ -878,8 +876,7 @@ let infer_inductive_instances cv_pb variance u1 u2 (univs,csts') =
(univs, Univ.Constraint.union csts csts')
let inferred_universes : (UGraph.t * Univ.Constraint.t) universe_compare =
- { compare_graph = (fun (x,_) -> x);
- compare_sorts = infer_cmp_universes;
+ { compare_sorts = infer_cmp_universes;
compare_instances = infer_convert_instances;
compare_cumul_instances = infer_inductive_instances; }
@@ -890,12 +887,12 @@ let gen_conv cv_pb l2r reds env evars univs t1 t2 =
in
if b then ()
else
- let _ = clos_gen_conv reds cv_pb l2r evars env (univs, checked_universes) t1 t2 in
+ let _ = clos_gen_conv reds cv_pb l2r evars env univs (univs, checked_universes) t1 t2 in
()
(* Profiling *)
-let gen_conv cv_pb ?(l2r=false) ?(reds=TransparentState.full) env ?(evars=(fun _->None), universes env) =
- let evars, univs = evars in
+let gen_conv cv_pb ?(l2r=false) ?(reds=TransparentState.full) env ?(evars=(fun _->None)) =
+ let univs = Environ.universes env in
if Flags.profile then
let fconv_universes_key = CProfile.declare_profile "trans_fconv_universes" in
CProfile.profile8 fconv_universes_key gen_conv cv_pb l2r reds env evars univs
@@ -906,35 +903,37 @@ let conv = gen_conv CONV
let conv_leq = gen_conv CUMUL
let generic_conv cv_pb ~l2r evars reds env univs t1 t2 =
+ let graph = Environ.universes env in
let (s, _) =
- clos_gen_conv reds cv_pb l2r evars env univs t1 t2
+ clos_gen_conv reds cv_pb l2r evars env graph univs t1 t2
in s
-let infer_conv_universes cv_pb l2r evars reds env univs t1 t2 =
+let infer_conv_universes cv_pb l2r evars reds env t1 t2 =
+ let univs = Environ.universes env in
let b, cstrs =
if cv_pb == CUMUL then Constr.leq_constr_univs_infer univs t1 t2
else Constr.eq_constr_univs_infer univs t1 t2
in
if b then cstrs
else
- let univs = ((univs, Univ.Constraint.empty), inferred_universes) in
- let ((_,cstrs), _) = clos_gen_conv reds cv_pb l2r evars env univs t1 t2 in
+ let state = ((univs, Univ.Constraint.empty), inferred_universes) in
+ let ((_,cstrs), _) = clos_gen_conv reds cv_pb l2r evars env univs state t1 t2 in
cstrs
(* Profiling *)
let infer_conv_universes =
if Flags.profile then
let infer_conv_universes_key = CProfile.declare_profile "infer_conv_universes" in
- CProfile.profile8 infer_conv_universes_key infer_conv_universes
+ CProfile.profile7 infer_conv_universes_key infer_conv_universes
else infer_conv_universes
let infer_conv ?(l2r=false) ?(evars=fun _ -> None) ?(ts=TransparentState.full)
- env univs t1 t2 =
- infer_conv_universes CONV l2r evars ts env univs t1 t2
+ env t1 t2 =
+ infer_conv_universes CONV l2r evars ts env t1 t2
let infer_conv_leq ?(l2r=false) ?(evars=fun _ -> None) ?(ts=TransparentState.full)
- env univs t1 t2 =
- infer_conv_universes CUMUL l2r evars ts env univs t1 t2
+ env t1 t2 =
+ infer_conv_universes CUMUL l2r evars ts env t1 t2
let default_conv cv_pb ?l2r:_ env t1 t2 =
gen_conv cv_pb env t1 t2
diff --git a/kernel/reduction.mli b/kernel/reduction.mli
index 4ae3838691..7d32596f74 100644
--- a/kernel/reduction.mli
+++ b/kernel/reduction.mli
@@ -31,14 +31,12 @@ exception NotConvertible
type 'a kernel_conversion_function = env -> 'a -> 'a -> unit
type 'a extended_conversion_function =
?l2r:bool -> ?reds:TransparentState.t -> env ->
- ?evars:((existential->constr option) * UGraph.t) ->
+ ?evars:(existential->constr option) ->
'a -> 'a -> unit
type conv_pb = CONV | CUMUL
type 'a universe_compare = {
- compare_graph : 'a -> UGraph.t; (* used for case inversion in reduction *)
-
(* Might raise NotConvertible *)
compare_sorts : env -> conv_pb -> Sorts.t -> Sorts.t -> 'a -> 'a;
compare_instances: flex:bool -> Univ.Instance.t -> Univ.Instance.t -> 'a -> 'a;
@@ -50,7 +48,7 @@ type 'a universe_state = 'a * 'a universe_compare
type ('a,'b) generic_conversion_function = env -> 'b universe_state -> 'a -> 'a -> 'b
-type 'a infer_conversion_function = env -> UGraph.t -> 'a -> 'a -> Univ.Constraint.t
+type 'a infer_conversion_function = env -> 'a -> 'a -> Univ.Constraint.t
val get_cumulativity_constraints : conv_pb -> Univ.Variance.t array ->
Univ.Instance.t -> Univ.Instance.t -> Univ.Constraint.t
diff --git a/kernel/safe_typing.ml b/kernel/safe_typing.ml
index da77a2882e..3dee3d2b2f 100644
--- a/kernel/safe_typing.ml
+++ b/kernel/safe_typing.ml
@@ -79,8 +79,10 @@ module NamedDecl = Context.Named.Declaration
* STRUCT (params,oldsenv) : inside a local module, with
module parameters [params] and earlier environment [oldsenv]
* SIG (params,oldsenv) : same for a local module type
- - [modresolver] : delta_resolver concerning the module content
- - [paramresolver] : delta_resolver concerning the module parameters
+ - [modresolver] : delta_resolver concerning the module content, that needs to
+ be marshalled on disk
+ - [paramresolver] : delta_resolver in scope but not part of the library per
+ se, that is from functor parameters and required libraries
- [revstruct] : current module content, most recent declarations first
- [modlabels] and [objlabels] : names defined in the current module,
either for modules/modtypes or for constants/inductives.
@@ -1301,7 +1303,9 @@ let import lib cst vodigest senv =
mp,
{ senv with
env;
- modresolver = Mod_subst.add_delta_resolver mb.mod_delta senv.modresolver;
+ (* Do NOT store the name quotient from the dependencies in the set of
+ constraints that will be marshalled on disk. *)
+ paramresolver = Mod_subst.add_delta_resolver mb.mod_delta senv.paramresolver;
required = DPmap.add lib.comp_name vodigest senv.required;
loads = (mp,mb)::senv.loads;
sections;
diff --git a/kernel/subtyping.ml b/kernel/subtyping.ml
index 28baa82666..1a4c786e43 100644
--- a/kernel/subtyping.ml
+++ b/kernel/subtyping.ml
@@ -85,7 +85,7 @@ let make_labmap mp list =
let check_conv_error error why cst poly f env a1 a2 =
try
- let cst' = f env (Environ.universes env) a1 a2 in
+ let cst' = f env a1 a2 in
if poly then
if Constraint.is_empty cst' then cst
else error (IncompatiblePolymorphism (env, a1, a2))
@@ -182,7 +182,7 @@ let check_inductive cst env mp1 l info1 mp2 mib2 spec2 subst1 subst2 reso1 reso2
begin
let kn2' = kn_of_delta reso2 kn2 in
if KerName.equal kn2 kn2' ||
- MutInd.equal (mind_of_delta_kn reso1 kn1)
+ MutInd.CanOrd.equal (mind_of_delta_kn reso1 kn1)
(subst_mind subst2 (MutInd.make kn2 kn2'))
then ()
else error NotEqualInductiveAliases
diff --git a/kernel/typeops.ml b/kernel/typeops.ml
index f86c12e1f1..85e24f87b7 100644
--- a/kernel/typeops.ml
+++ b/kernel/typeops.ml
@@ -413,7 +413,7 @@ let type_of_projection env p c ct =
try find_rectype env ct
with Not_found -> error_case_not_inductive env (make_judge c ct)
in
- assert(eq_ind (Projection.inductive p) ind);
+ assert(Ind.CanOrd.equal (Projection.inductive p) ind);
let ty = Vars.subst_instance_constr u pty in
substl (c :: CList.rev args) ty
diff --git a/kernel/typeops.mli b/kernel/typeops.mli
index 87a5666fcc..d381e55dd6 100644
--- a/kernel/typeops.mli
+++ b/kernel/typeops.mli
@@ -111,7 +111,7 @@ val type_of_global_in_context : env -> GlobRef.t -> types * Univ.AUContext.t
(** {6 Miscellaneous. } *)
(** Check that hyps are included in env and fails with error otherwise *)
-val check_hyps_inclusion : env -> ?evars:((existential->constr option) * UGraph.t) ->
+val check_hyps_inclusion : env -> ?evars:(existential->constr option) ->
GlobRef.t -> Constr.named_context -> unit
(** Types for primitives *)
diff --git a/kernel/uGraph.ml b/kernel/uGraph.ml
index 52e93a9e22..096e458ec4 100644
--- a/kernel/uGraph.ml
+++ b/kernel/uGraph.ml
@@ -29,7 +29,12 @@ module G = AcyclicGraph.Make(struct
code (eg add_universe with a constraint vs G.add with no
constraint) *)
-type t = { graph: G.t; sprop_cumulative : bool }
+type t = {
+ graph: G.t;
+ sprop_cumulative : bool;
+ type_in_type : bool;
+}
+
type 'a check_function = t -> 'a -> 'a -> bool
let g_map f g =
@@ -39,6 +44,10 @@ let g_map f g =
let set_cumulative_sprop b g = {g with sprop_cumulative=b}
+let set_type_in_type b g = {g with type_in_type=b}
+
+let type_in_type g = g.type_in_type
+
let check_smaller_expr g (u,n) (v,m) =
let diff = n - m in
match diff with
@@ -55,28 +64,33 @@ let real_check_leq g u v =
Universe.for_all (fun ul -> exists_bigger g ul v) u
let check_leq g u v =
+ type_in_type g ||
Universe.equal u v || (g.sprop_cumulative && Universe.is_sprop u) ||
(not (Universe.is_sprop u) && not (Universe.is_sprop v) &&
(is_type0m_univ u ||
real_check_leq g u v))
let check_eq g u v =
+ type_in_type g ||
Universe.equal u v ||
(not (Universe.is_sprop u || Universe.is_sprop v) &&
(real_check_leq g u v && real_check_leq g v u))
let check_eq_level g u v =
u == v ||
+ type_in_type g ||
(not (Level.is_sprop u || Level.is_sprop v) && G.check_eq g.graph u v)
-let empty_universes = {graph=G.empty; sprop_cumulative=false}
+let empty_universes = {graph=G.empty; sprop_cumulative=false; type_in_type=false}
let initial_universes =
let big_rank = 1000000 in
let g = G.empty in
let g = G.add ~rank:big_rank Level.prop g in
let g = G.add ~rank:big_rank Level.set g in
- {graph=G.enforce_lt Level.prop Level.set g; sprop_cumulative=false}
+ {empty_universes with graph=G.enforce_lt Level.prop Level.set g}
+
+let initial_universes_with g = {g with graph=initial_universes.graph}
let enforce_constraint (u,d,v) g =
match d with
@@ -91,6 +105,10 @@ let enforce_constraint (u,d,v as cst) g =
| true, Le, false when g.sprop_cumulative -> g
| _ -> raise (UniverseInconsistency (d,Universe.make u, Universe.make v, None))
+let enforce_constraint cst g =
+ if not (type_in_type g) then enforce_constraint cst g
+ else try enforce_constraint cst g with UniverseInconsistency _ -> g
+
let merge_constraints csts g = Constraint.fold enforce_constraint csts g
let check_constraint g (u,d,v) =
@@ -103,8 +121,8 @@ let check_constraint g (u,d,v as cst) =
match Level.is_sprop u, d, Level.is_sprop v with
| false, _, false -> check_constraint g.graph cst
| true, (Eq|Le), true -> true
- | true, Le, false -> g.sprop_cumulative
- | _ -> false
+ | true, Le, false -> g.sprop_cumulative || type_in_type g
+ | _ -> type_in_type g
let check_constraints csts g = Constraint.for_all (check_constraint g) csts
@@ -145,8 +163,10 @@ let enforce_leq_alg u v g =
let enforce_leq_alg u v g =
match Universe.is_sprop u, Universe.is_sprop v with
| true, true -> Constraint.empty, g
- | true, false | false, true -> raise (UniverseInconsistency (Le, u, v, None))
| false, false -> enforce_leq_alg u v g
+ | left, _ ->
+ if left && g.sprop_cumulative then Constraint.empty, g
+ else raise (UniverseInconsistency (Le, u, v, None))
(* sanity check wrapper *)
let enforce_leq_alg u v g =
diff --git a/kernel/uGraph.mli b/kernel/uGraph.mli
index c9fbd7f694..87b3634e28 100644
--- a/kernel/uGraph.mli
+++ b/kernel/uGraph.mli
@@ -16,6 +16,15 @@ type t
val set_cumulative_sprop : bool -> t -> t
(** Makes the system incomplete. *)
+val set_type_in_type : bool -> t -> t
+
+(** When [type_in_type], functions adding constraints do not fail and
+ may instead ignore inconsistent constraints.
+
+ Checking functions such as [check_leq] always return [true].
+*)
+val type_in_type : t -> bool
+
type 'a check_function = t -> 'a -> 'a -> bool
val check_leq : Universe.t check_function
@@ -25,6 +34,9 @@ val check_eq_level : Level.t check_function
(** The initial graph of universes: Prop < Set *)
val initial_universes : t
+(** Initial universes, but keeping options such as type in type from the argument. *)
+val initial_universes_with : t -> t
+
(** Check equality of instances w.r.t. a universe graph *)
val check_eq_instances : Instance.t check_function
diff --git a/kernel/univ.ml b/kernel/univ.ml
index 6d8aa02dff..a2fd14025e 100644
--- a/kernel/univ.ml
+++ b/kernel/univ.ml
@@ -205,12 +205,6 @@ module Level = struct
let pr u = str (to_string u)
- let apart u v =
- match data u, data v with
- | SProp, _ | _, SProp
- | Prop, Set | Set, Prop -> true
- | _ -> false
-
let vars = Array.init 20 (fun i -> make (Var i))
let var n =
@@ -250,7 +244,7 @@ module LMap = struct
ext empty
let pr f m =
- h 0 (prlist_with_sep fnl (fun (u, v) ->
+ h (prlist_with_sep fnl (fun (u, v) ->
Level.pr u ++ f v) (bindings m))
end
@@ -568,16 +562,6 @@ let constraint_type_ord c1 c2 = match c1, c2 with
| Eq, Eq -> 0
| Eq, _ -> 1
-(* Universe inconsistency: error raised when trying to enforce a relation
- that would create a cycle in the graph of universes. *)
-
-type univ_inconsistency = constraint_type * universe * universe * explanation Lazy.t option
-
-exception UniverseInconsistency of univ_inconsistency
-
-let error_inconsistency o u v p =
- raise (UniverseInconsistency (o,Universe.make u,Universe.make v,p))
-
(* Constraints and sets of constraints. *)
type univ_constraint = Level.t * constraint_type * Level.t
@@ -660,8 +644,6 @@ type 'a constraint_function = 'a -> 'a -> constraints -> constraints
let enforce_eq_level u v c =
(* We discard trivial constraints like u=u *)
if Level.equal u v then c
- else if Level.apart u v then
- error_inconsistency Eq u v None
else Constraint.add (u,Eq,v) c
let enforce_eq u v c =
@@ -684,9 +666,9 @@ let constraint_add_leq v u c =
let j = m - n in
if j = -1 (* n = m+1, v+1 <= u <-> v < u *) then
Constraint.add (x,Lt,y) c
- else if j <= -1 (* n = m+k, v+k <= u <-> v+(k-1) < u *) then
- if Level.equal x y then (* u+(k+1) <= u *)
- raise (UniverseInconsistency (Le, Universe.tip v, Universe.tip u, None))
+ else if j <= -1 (* n = m+k, v+k <= u and k>0 *) then
+ if Level.equal x y then (* u+k <= u with k>0 *)
+ Constraint.add (x,Lt,x) c
else anomaly (Pp.str"Unable to handle arbitrary u+k <= v constraints.")
else if j = 0 then
Constraint.add (x,Le,y) c
@@ -703,8 +685,8 @@ let check_univ_leq u v =
let enforce_leq u v c =
match Universe.is_sprop u, Universe.is_sprop v with
| true, true -> c
- | true, false | false, true ->
- raise (UniverseInconsistency (Le, u, v, None))
+ | true, false -> Constraint.add (Level.sprop,Le,Level.prop) c
+ | false, true -> Constraint.add (Level.prop,Le,Level.sprop) c
| false, false ->
List.fold_left (fun c v -> (List.fold_left (fun c u -> constraint_add_leq u v c) c u)) c v
@@ -961,7 +943,7 @@ struct
let pr prl ?variance (univs, cst as ctx) =
if is_empty ctx then mt() else
- h 0 (Instance.pr prl ?variance univs ++ str " |= ") ++ h 0 (v 0 (Constraint.pr prl cst))
+ h (Instance.pr prl ?variance univs ++ str " |= ") ++ h (v 0 (Constraint.pr prl cst))
let hcons (univs, cst) =
(Instance.hcons univs, hcons_constraints cst)
@@ -1076,7 +1058,7 @@ struct
let pr prl (univs, cst as ctx) =
if is_empty ctx then mt() else
- h 0 (LSet.pr prl univs ++ str " |= ") ++ h 0 (v 0 (Constraint.pr prl cst))
+ h (LSet.pr prl univs ++ str " |= ") ++ h (v 0 (Constraint.pr prl cst))
let constraints (_univs, cst) = cst
let levels (univs, _cst) = univs
@@ -1232,6 +1214,14 @@ let hcons_universe_context_set (v, c) =
let hcons_univ x = Universe.hcons x
+(* Universe inconsistency: error raised when trying to enforce a relation
+ that would create a cycle in the graph of universes. *)
+
+type univ_inconsistency = constraint_type * universe * universe * explanation Lazy.t option
+
+(* Do not use in this file as we may be type-in-type *)
+exception UniverseInconsistency of univ_inconsistency
+
let explain_universe_inconsistency prl (o,u,v,p : univ_inconsistency) =
let pr_uni = Universe.pr_with prl in
let pr_rel = function
diff --git a/kernel/vars.ml b/kernel/vars.ml
index f7e28b0cfe..a446fa413c 100644
--- a/kernel/vars.ml
+++ b/kernel/vars.ml
@@ -348,5 +348,8 @@ let universes_of_constr c =
| Array (u,_,_,_) ->
let s = LSet.fold LSet.add (Instance.levels u) s in
Constr.fold aux s c
+ | Case (_,_,CaseInvert {univs;args=_},_,_) ->
+ let s = LSet.fold LSet.add (Instance.levels univs) s in
+ Constr.fold aux s c
| _ -> Constr.fold aux s c
in aux LSet.empty c
diff --git a/kernel/vconv.ml b/kernel/vconv.ml
index cc2c2c0b4b..1432fb9310 100644
--- a/kernel/vconv.ml
+++ b/kernel/vconv.ml
@@ -95,7 +95,7 @@ and conv_atom env pb k a1 stk1 a2 stk2 cu =
(* Pp.(msg_debug (str "conv_atom(" ++ pr_atom a1 ++ str ", " ++ pr_atom a2 ++ str ")")) ; *)
match a1, a2 with
| Aind ((mi,_i) as ind1) , Aind ind2 ->
- if eq_ind ind1 ind2 && compare_stack stk1 stk2 then
+ if Ind.CanOrd.equal ind1 ind2 && compare_stack stk1 stk2 then
let ulen = Univ.AUContext.size (Environ.mind_context env mi) in
if ulen = 0 then
conv_stack env k stk1 stk2 cu
@@ -141,7 +141,7 @@ and conv_stack env k stk1 stk2 cu =
conv_stack env k stk1 stk2 !rcu
else raise NotConvertible
| Zproj p1 :: stk1, Zproj p2 :: stk2 ->
- if Projection.Repr.equal p1 p2 then conv_stack env k stk1 stk2 cu
+ if Projection.Repr.CanOrd.equal p1 p2 then conv_stack env k stk1 stk2 cu
else raise NotConvertible
| [], _ | Zapp _ :: _, _ | Zfix _ :: _, _ | Zswitch _ :: _, _
| Zproj _ :: _, _ -> raise NotConvertible
@@ -211,5 +211,5 @@ let vm_conv cv_pb env t1 t2 =
else Constr.eq_constr_univs univs t1 t2
in
if not b then
- let univs = (univs, checked_universes) in
- let _ = vm_conv_gen cv_pb env univs t1 t2 in ()
+ let state = (univs, checked_universes) in
+ let _ = vm_conv_gen cv_pb env state t1 t2 in ()
diff --git a/kernel/vmbytecodes.ml b/kernel/vmbytecodes.ml
index 74405a0105..c156a21c86 100644
--- a/kernel/vmbytecodes.ml
+++ b/kernel/vmbytecodes.ml
@@ -106,14 +106,14 @@ let rec pp_instr i =
| Kclosure(lbl, n) ->
str "closure " ++ pp_lbl lbl ++ str ", " ++ int n
| Kclosurerec(fv,init,lblt,lblb) ->
- h 1 (str "closurerec " ++
+ hv 1 (str "closurerec " ++
int fv ++ str ", " ++ int init ++
str " types = " ++
prlist_with_sep spc pp_lbl (Array.to_list lblt) ++
str " bodies = " ++
prlist_with_sep spc pp_lbl (Array.to_list lblb))
| Kclosurecofix (fv,init,lblt,lblb) ->
- h 1 (str "closurecofix " ++
+ hv 1 (str "closurecofix " ++
int fv ++ str ", " ++ int init ++
str " types = " ++
prlist_with_sep spc pp_lbl (Array.to_list lblt) ++
@@ -129,7 +129,7 @@ let rec pp_instr i =
str "makeswitchblock " ++ pp_lbl lblt ++ str ", " ++
pp_lbl lbls ++ str ", " ++ int sz
| Kswitch(lblc,lblb) ->
- h 1 (str "switch " ++
+ hv 1 (str "switch " ++
prlist_with_sep spc pp_lbl (Array.to_list lblc) ++
str " | " ++
prlist_with_sep spc pp_lbl (Array.to_list lblb))
diff --git a/kernel/vmbytegen.ml b/kernel/vmbytegen.ml
index 375b1aface..16a0f42664 100644
--- a/kernel/vmbytegen.ml
+++ b/kernel/vmbytegen.ml
@@ -508,7 +508,6 @@ let is_caml_prim = let open CPrimitives in function
| Arraydefault
| Arrayset
| Arraycopy
- | Arrayreroot
| Arraylength -> true
| _ -> false
diff --git a/kernel/vmemitcodes.ml b/kernel/vmemitcodes.ml
index f913cb906c..babc57794b 100644
--- a/kernel/vmemitcodes.ml
+++ b/kernel/vmemitcodes.ml
@@ -36,9 +36,9 @@ let eq_reloc_info r1 r2 = match r1, r2 with
| Reloc_annot _, _ -> false
| Reloc_const c1, Reloc_const c2 -> eq_structured_constant c1 c2
| Reloc_const _, _ -> false
-| Reloc_getglobal c1, Reloc_getglobal c2 -> Constant.equal c1 c2
+| Reloc_getglobal c1, Reloc_getglobal c2 -> Constant.CanOrd.equal c1 c2
| Reloc_getglobal _, _ -> false
-| Reloc_proj_name p1, Reloc_proj_name p2 -> Projection.Repr.equal p1 p2
+| Reloc_proj_name p1, Reloc_proj_name p2 -> Projection.Repr.CanOrd.equal p1 p2
| Reloc_proj_name _, _ -> false
| Reloc_caml_prim p1, Reloc_caml_prim p2 -> CPrimitives.equal p1 p2
| Reloc_caml_prim _, _ -> false
@@ -48,8 +48,8 @@ let hash_reloc_info r =
match r with
| Reloc_annot sw -> combinesmall 1 (hash_annot_switch sw)
| Reloc_const c -> combinesmall 2 (hash_structured_constant c)
- | Reloc_getglobal c -> combinesmall 3 (Constant.hash c)
- | Reloc_proj_name p -> combinesmall 4 (Projection.Repr.hash p)
+ | Reloc_getglobal c -> combinesmall 3 (Constant.CanOrd.hash c)
+ | Reloc_proj_name p -> combinesmall 4 (Projection.Repr.CanOrd.hash p)
| Reloc_caml_prim p -> combinesmall 5 (CPrimitives.hash p)
module RelocTable = Hashtbl.Make(struct
@@ -262,7 +262,7 @@ let check_prim_op = function
| Arraymake -> opISINT_CAML_CALL2
| Arrayget -> opISARRAY_INT_CAML_CALL2
| Arrayset -> opISARRAY_INT_CAML_CALL3
- | Arraydefault | Arraycopy | Arrayreroot | Arraylength ->
+ | Arraydefault | Arraycopy | Arraylength ->
opISARRAY_CAML_CALL1
let emit_instr env = function
diff --git a/kernel/vmsymtable.ml b/kernel/vmsymtable.ml
index 4ad830a298..ae0fa38571 100644
--- a/kernel/vmsymtable.ml
+++ b/kernel/vmsymtable.ml
@@ -69,7 +69,6 @@ let parray_get = set_global Vmvalues.parray_get
let parray_get_default = set_global Vmvalues.parray_get_default
let parray_set = set_global Vmvalues.parray_set
let parray_copy = set_global Vmvalues.parray_copy
-let parray_reroot = set_global Vmvalues.parray_reroot
let parray_length = set_global Vmvalues.parray_length
(* table pour les structured_constant et les annotations des switchs *)
@@ -86,7 +85,7 @@ module AnnotTable = Hashtbl.Make (struct
let hash = hash_annot_switch
end)
-module ProjNameTable = Hashtbl.Make (Projection.Repr)
+module ProjNameTable = Hashtbl.Make (Projection.Repr.CanOrd)
let str_cst_tbl : int SConstTable.t = SConstTable.create 31
@@ -135,7 +134,6 @@ let slot_for_caml_prim =
| Arraydefault -> parray_get_default
| Arrayset -> parray_set
| Arraycopy -> parray_copy
- | Arrayreroot -> parray_reroot
| Arraylength -> parray_length
| _ -> assert false
diff --git a/kernel/vmvalues.ml b/kernel/vmvalues.ml
index 0678f37a0b..7b4101b9d0 100644
--- a/kernel/vmvalues.ml
+++ b/kernel/vmvalues.ml
@@ -96,7 +96,7 @@ let hash_structured_values (v : structured_values) =
let eq_structured_constant c1 c2 = match c1, c2 with
| Const_sort s1, Const_sort s2 -> Sorts.equal s1 s2
| Const_sort _, _ -> false
-| Const_ind i1, Const_ind i2 -> eq_ind i1 i2
+| Const_ind i1, Const_ind i2 -> Ind.CanOrd.equal i1 i2
| Const_ind _, _ -> false
| Const_b0 t1, Const_b0 t2 -> Int.equal t1 t2
| Const_b0 _, _ -> false
@@ -113,7 +113,7 @@ let hash_structured_constant c =
let open Hashset.Combine in
match c with
| Const_sort s -> combinesmall 1 (Sorts.hash s)
- | Const_ind i -> combinesmall 2 (ind_hash i)
+ | Const_ind i -> combinesmall 2 (Ind.CanOrd.hash i)
| Const_b0 t -> combinesmall 3 (Int.hash t)
| Const_univ_level l -> combinesmall 4 (Univ.Level.hash l)
| Const_val v -> combinesmall 5 (hash_structured_values v)
@@ -250,7 +250,7 @@ type id_key =
| EvarKey of Evar.t
let eq_id_key (k1 : id_key) (k2 : id_key) = match k1, k2 with
-| ConstKey c1, ConstKey c2 -> Constant.equal c1 c2
+| ConstKey c1, ConstKey c2 -> Constant.CanOrd.equal c1 c2
| VarKey id1, VarKey id2 -> Id.equal id1 id2
| RelKey n1, RelKey n2 -> Int.equal n1 n2
| EvarKey evk1, EvarKey evk2 -> Evar.equal evk1 evk2
@@ -469,7 +469,7 @@ struct
let equal = eq_id_key
open Hashset.Combine
let hash : t -> tag = function
- | ConstKey c -> combinesmall 1 (Constant.hash c)
+ | ConstKey c -> combinesmall 1 (Constant.CanOrd.hash c)
| VarKey id -> combinesmall 2 (Id.hash id)
| RelKey i -> combinesmall 3 (Int.hash i)
| EvarKey evk -> combinesmall 4 (Evar.hash evk)
@@ -700,5 +700,4 @@ let parray_get = Obj.magic Parray.get
let parray_get_default = Obj.magic Parray.default
let parray_set = Obj.magic Parray.set
let parray_copy = Obj.magic Parray.copy
-let parray_reroot = Obj.magic Parray.reroot
let parray_length = Obj.magic Parray.length
diff --git a/kernel/vmvalues.mli b/kernel/vmvalues.mli
index 6632dc46b2..d15595766a 100644
--- a/kernel/vmvalues.mli
+++ b/kernel/vmvalues.mli
@@ -204,5 +204,4 @@ val parray_get : values
val parray_get_default : values
val parray_set : values
val parray_copy : values
-val parray_reroot : values
val parray_length : values
diff --git a/lib/control.ml b/lib/control.ml
index bb42b5727e..95ea3935a7 100644
--- a/lib/control.ml
+++ b/lib/control.ml
@@ -18,10 +18,12 @@ let enable_thread_delay = ref false
let check_for_interrupt () =
if !interrupt then begin interrupt := false; raise Sys.Break end;
- incr steps;
- if !enable_thread_delay && !steps = 1000 then begin
- Thread.delay 0.001;
- steps := 0;
+ if !enable_thread_delay then begin
+ incr steps;
+ if !steps = 1000 then begin
+ Thread.delay 0.001;
+ steps := 0;
+ end
end
(** This function does not work on windows, sigh... *)
diff --git a/lib/explore.ml b/lib/explore.ml
index b3ffef6ac2..139de488e2 100644
--- a/lib/explore.ml
+++ b/lib/explore.ml
@@ -29,7 +29,7 @@ module Make = functor(S : SearchProblem) -> struct
| [i] -> int i
| i :: l -> pp_rec l ++ str "." ++ int i
in
- Feedback.msg_debug (h 0 (pp_rec p) ++ pp)
+ Feedback.msg_debug (h (pp_rec p) ++ pp)
(*s Depth first search. *)
diff --git a/lib/flags.ml b/lib/flags.ml
index 1d9d6d49bc..83733cf00d 100644
--- a/lib/flags.ml
+++ b/lib/flags.ml
@@ -47,6 +47,7 @@ let async_proofs_is_worker () = !async_proofs_worker_id <> "master"
let load_vos_libraries = ref false
let debug = ref false
+let xml_debug = ref false
let in_debugger = ref false
let in_toplevel = ref false
diff --git a/lib/flags.mli b/lib/flags.mli
index 30d1b5b2bd..ebd23a4d20 100644
--- a/lib/flags.mli
+++ b/lib/flags.mli
@@ -41,6 +41,7 @@ val load_vos_libraries : bool ref
(** Debug flags *)
val debug : bool ref
+val xml_debug : bool ref
val in_debugger : bool ref
val in_toplevel : bool ref
diff --git a/lib/genarg.mli b/lib/genarg.mli
index 88e9ff13e8..aac43db672 100644
--- a/lib/genarg.mli
+++ b/lib/genarg.mli
@@ -11,7 +11,7 @@
(** Generic arguments used by the extension mechanisms of several Coq ASTs. *)
(** The route of a generic argument, from parsing to evaluation.
-In the following diagram, "object" can be tactic_expr, constr, tactic_arg, etc.
+In the following diagram, "object" can be ltac_expr, constr, tactic_value, etc.
{% \begin{verbatim} %}
parsing in_raw out_raw
diff --git a/lib/pp.ml b/lib/pp.ml
index 78c5186449..a9994ac6fd 100644
--- a/lib/pp.ml
+++ b/lib/pp.ml
@@ -22,7 +22,7 @@
type pp_tag = string
type block_type =
- | Pp_hbox of int
+ | Pp_hbox
| Pp_vbox of int
| Pp_hvbox of int
| Pp_hovbox of int
@@ -131,7 +131,7 @@ let strbrk s =
let ismt = function | Ppcmd_empty -> true | _ -> false
(* boxing commands *)
-let h n s = Ppcmd_box(Pp_hbox n,s)
+let h s = Ppcmd_box(Pp_hbox,s)
let v n s = Ppcmd_box(Pp_vbox n,s)
let hv n s = Ppcmd_box(Pp_hvbox n,s)
let hov n s = Ppcmd_box(Pp_hovbox n,s)
@@ -151,7 +151,7 @@ let escape_string s =
let qstring s = str "\"" ++ str (escape_string s) ++ str "\""
let qs = qstring
-let quote s = h 0 (str "\"" ++ s ++ str "\"")
+let quote s = h (str "\"" ++ s ++ str "\"")
let rec pr_com ft s =
let (s1,os) =
@@ -181,7 +181,7 @@ let split_tag tag =
(* pretty printing functions *)
let pp_with ft pp =
let cpp_open_box = function
- | Pp_hbox n -> Format.pp_open_hbox ft ()
+ | Pp_hbox -> Format.pp_open_hbox ft ()
| Pp_vbox n -> Format.pp_open_vbox ft n
| Pp_hvbox n -> Format.pp_open_hvbox ft n
| Pp_hovbox n -> Format.pp_open_hovbox ft n
@@ -309,12 +309,14 @@ let db_print_pp fmt pp =
let block_type fmt btype =
let (bt, v) =
match btype with
- | Pp_hbox v -> ("Pp_hbox", v)
- | Pp_vbox v -> ("Pp_vbox", v)
- | Pp_hvbox v -> ("Pp_hvbox", v)
- | Pp_hovbox v -> ("Pp_hovbox", v)
+ | Pp_hbox -> ("Pp_hbox", None)
+ | Pp_vbox v -> ("Pp_vbox", Some v)
+ | Pp_hvbox v -> ("Pp_hvbox", Some v)
+ | Pp_hovbox v -> ("Pp_hovbox", Some v)
in
- fprintf fmt "%s %d" bt v
+ match v with
+ | None -> fprintf fmt "%s" bt
+ | Some v -> fprintf fmt "%s %d" bt v
in
let rec db_print_pp_r indent pp =
let ind () = fprintf fmt "%s" (String.make (2 * indent) ' ') in
diff --git a/lib/pp.mli b/lib/pp.mli
index b265537728..12f1ba9bb2 100644
--- a/lib/pp.mli
+++ b/lib/pp.mli
@@ -43,7 +43,7 @@ type pp_tag = string
type t
type block_type =
- | Pp_hbox of int
+ | Pp_hbox
| Pp_vbox of int
| Pp_hvbox of int
| Pp_hovbox of int
@@ -99,7 +99,7 @@ val strbrk : string -> t
(** {6 Boxing commands} *)
-val h : int -> t -> t
+val h : t -> t
val v : int -> t -> t
val hv : int -> t -> t
val hov : int -> t -> t
diff --git a/lib/pp_diff.ml b/lib/pp_diff.ml
index 988e8e4303..4593bf4b07 100644
--- a/lib/pp_diff.ml
+++ b/lib/pp_diff.ml
@@ -109,7 +109,7 @@ let shorten_diff_span dtype diff_list =
iter 0 len (<) 1; (* left to right *)
iter (len-1) (-1) (>) (-1); (* right to left *)
- if !changed then Array.to_list diffs else diff_list;;
+ if !changed then Array.to_list diffs else diff_list
let has_changes diffs =
let rec has_changes_r diffs added removed =
@@ -118,12 +118,12 @@ let has_changes diffs =
| `Removed _ :: t -> has_changes_r t added true
| h :: t -> has_changes_r t added removed
| [] -> (added, removed) in
- has_changes_r diffs false false;;
+ has_changes_r diffs false false
(* get the Myers diff of 2 lists of strings *)
let diff_strs old_strs new_strs =
let diffs = List.rev (StringDiff.diff old_strs new_strs) in
- shorten_diff_span `Removed (shorten_diff_span `Added diffs);;
+ shorten_diff_span `Removed (shorten_diff_span `Added diffs)
(* Default string tokenizer. Makes each character a separate strin.
Whitespace is not ignored. Doesn't handle UTF-8 differences well. *)
@@ -139,7 +139,7 @@ let def_tokenize_string s =
let diff_str ?(tokenize_string=def_tokenize_string) old_str new_str =
let old_toks = Array.of_list (tokenize_string old_str)
and new_toks = Array.of_list (tokenize_string new_str) in
- diff_strs old_toks new_toks;;
+ diff_strs old_toks new_toks
let get_dinfo = function
| `Common (_, _, s) -> (`Common, s)
@@ -281,14 +281,14 @@ let add_diff_tags which pp diffs =
skip ();
if !diffs <> [] then
raise (Diff_Failure "left-over diff info at end of Pp.t, should be impossible");
- if has_added || has_removed then wrap_in_bg diff_tag rv else rv;;
+ if has_added || has_removed then wrap_in_bg diff_tag rv else rv
let diff_pp ?(tokenize_string=def_tokenize_string) o_pp n_pp =
let open Pp in
let o_str = string_of_ppcmds o_pp in
let n_str = string_of_ppcmds n_pp in
let diffs = diff_str ~tokenize_string o_str n_str in
- (add_diff_tags `Removed o_pp diffs, add_diff_tags `Added n_pp diffs);;
+ (add_diff_tags `Removed o_pp diffs, add_diff_tags `Added n_pp diffs)
let diff_pp_combined ?(tokenize_string=def_tokenize_string) ?(show_removed=false) o_pp n_pp =
let open Pp in
@@ -300,4 +300,4 @@ let diff_pp_combined ?(tokenize_string=def_tokenize_string) ?(show_removed=false
if show_removed && has_removed then
let removed = add_diff_tags `Removed o_pp diffs in
(v 0 (removed ++ cut() ++ added))
- else added;;
+ else added
diff --git a/library/coqlib.ml b/library/coqlib.ml
index 04a6e159eb..82d1ecacb5 100644
--- a/library/coqlib.ml
+++ b/library/coqlib.ml
@@ -45,7 +45,7 @@ let has_ref s = CString.Map.mem s !table
let check_ind_ref s ind =
match CString.Map.find s !table with
- | GlobRef.IndRef r -> eq_ind r ind
+ | GlobRef.IndRef r -> Ind.CanOrd.equal r ind
| _ -> false
| exception Not_found -> false
@@ -84,7 +84,7 @@ let gen_reference_in_modules locstr dirs s =
let dirs = List.map make_dir dirs in
let qualid = qualid_of_string s in
let all = Nametab.locate_all qualid in
- let all = List.sort_uniquize GlobRef.Ordered_env.compare all in
+ let all = List.sort_uniquize GlobRef.UserOrd.compare all in
let these = List.filter (has_suffix_in_dirs dirs) all in
match these with
| [x] -> x
diff --git a/library/globnames.ml b/library/globnames.ml
index bc24fbf096..654349dea0 100644
--- a/library/globnames.ml
+++ b/library/globnames.ml
@@ -98,14 +98,14 @@ module ExtRefOrdered = struct
let equal x y =
x == y ||
match x, y with
- | TrueGlobal rx, TrueGlobal ry -> GlobRef.Ordered_env.equal rx ry
+ | TrueGlobal rx, TrueGlobal ry -> GlobRef.UserOrd.equal rx ry
| SynDef knx, SynDef kny -> KerName.equal knx kny
| (TrueGlobal _ | SynDef _), _ -> false
let compare x y =
if x == y then 0
else match x, y with
- | TrueGlobal rx, TrueGlobal ry -> GlobRef.Ordered_env.compare rx ry
+ | TrueGlobal rx, TrueGlobal ry -> GlobRef.UserOrd.compare rx ry
| SynDef knx, SynDef kny -> KerName.compare knx kny
| TrueGlobal _, SynDef _ -> -1
| SynDef _, TrueGlobal _ -> 1
@@ -113,7 +113,7 @@ module ExtRefOrdered = struct
open Hashset.Combine
let hash = function
- | TrueGlobal gr -> combinesmall 1 (GlobRef.Ordered_env.hash gr)
+ | TrueGlobal gr -> combinesmall 1 (GlobRef.UserOrd.hash gr)
| SynDef kn -> combinesmall 2 (KerName.hash kn)
end
diff --git a/library/lib.ml b/library/lib.ml
index 830777003b..fa0a95d366 100644
--- a/library/lib.ml
+++ b/library/lib.ml
@@ -525,8 +525,8 @@ let init () =
let mp_of_global = let open GlobRef in function
| VarRef id -> !lib_state.path_prefix.Nametab.obj_mp
| ConstRef cst -> Names.Constant.modpath cst
- | IndRef ind -> Names.ind_modpath ind
- | ConstructRef constr -> Names.constr_modpath constr
+ | IndRef ind -> Names.Ind.modpath ind
+ | ConstructRef constr -> Names.Construct.modpath constr
let rec dp_of_mp = function
|Names.MPfile dp -> dp
diff --git a/parsing/cLexer.ml b/parsing/cLexer.ml
index f485970eec..d8d2f2a2ef 100644
--- a/parsing/cLexer.ml
+++ b/parsing/cLexer.ml
@@ -823,7 +823,7 @@ let token_text : type c. c Tok.p -> string = function
| PKEYWORD t -> "'" ^ t ^ "'"
| PIDENT None -> "identifier"
| PIDENT (Some t) -> "'" ^ t ^ "'"
- | PNUMBER None -> "numeral"
+ | PNUMBER None -> "number"
| PNUMBER (Some n) -> "'" ^ NumTok.Unsigned.sprint n ^ "'"
| PSTRING None -> "string"
| PSTRING (Some s) -> "STRING \"" ^ s ^ "\""
@@ -916,7 +916,7 @@ let terminal s =
if is_ident_not_keyword s then PIDENT (Some s)
else PKEYWORD s
-(* Precondition: the input is a numeral (c.f. [NumTok.t]) *)
-let terminal_numeral s = match NumTok.Unsigned.parse_string s with
+(* Precondition: the input is a number (c.f. [NumTok.t]) *)
+let terminal_number s = match NumTok.Unsigned.parse_string s with
| Some n -> PNUMBER (Some n)
- | None -> failwith "numeral token expected."
+ | None -> failwith "number token expected."
diff --git a/parsing/cLexer.mli b/parsing/cLexer.mli
index ac2c5bcfe2..af4b7ba334 100644
--- a/parsing/cLexer.mli
+++ b/parsing/cLexer.mli
@@ -49,8 +49,8 @@ val check_keyword : string -> unit
(** When string is not an ident, returns a keyword. *)
val terminal : string -> string Tok.p
-(** Precondition: the input is a numeral (c.f. [NumTok.t]) *)
-val terminal_numeral : string -> NumTok.Unsigned.t Tok.p
+(** Precondition: the input is a number (c.f. [NumTok.t]) *)
+val terminal_number : string -> NumTok.Unsigned.t Tok.p
(** The lexer of Coq: *)
diff --git a/parsing/g_constr.mlg b/parsing/g_constr.mlg
index 1ec83c496a..67a061175a 100644
--- a/parsing/g_constr.mlg
+++ b/parsing/g_constr.mlg
@@ -80,11 +80,11 @@ let test_array_closing =
}
GRAMMAR EXTEND Gram
- GLOBAL: binder_constr lconstr constr operconstr
+ GLOBAL: binder_constr lconstr constr term
universe_level universe_name sort sort_family
- global constr_pattern lconstr_pattern Constr.ident
+ global constr_pattern cpattern Constr.ident
closed_binder open_binders binder binders binders_fixannot
- record_declaration typeclass_constraint pattern appl_arg type_cstr;
+ record_declaration typeclass_constraint pattern arg type_cstr;
Constr.ident:
[ [ id = Prim.ident -> { id } ] ]
;
@@ -97,7 +97,7 @@ GRAMMAR EXTEND Gram
constr_pattern:
[ [ c = constr -> { c } ] ]
;
- lconstr_pattern:
+ cpattern:
[ [ c = lconstr -> { c } ] ]
;
sort:
@@ -131,65 +131,65 @@ GRAMMAR EXTEND Gram
| u = universe_expr -> { [u] } ] ]
;
lconstr:
- [ [ c = operconstr LEVEL "200" -> { c } ] ]
+ [ [ c = term LEVEL "200" -> { c } ] ]
;
constr:
- [ [ c = operconstr LEVEL "8" -> { c }
- | "@"; f=global; i = univ_instance -> { CAst.make ~loc @@ CAppExpl((None,f,i),[]) } ] ]
+ [ [ c = term LEVEL "8" -> { c }
+ | "@"; f=global; i = univ_annot -> { CAst.make ~loc @@ CAppExpl((None,f,i),[]) } ] ]
;
- operconstr:
+ term:
[ "200" RIGHTA
[ c = binder_constr -> { c } ]
| "100" RIGHTA
- [ c1 = operconstr; "<:"; c2 = operconstr LEVEL "200" ->
+ [ c1 = term; "<:"; c2 = term LEVEL "200" ->
{ CAst.make ~loc @@ CCast(c1, CastVM c2) }
- | c1 = operconstr; "<<:"; c2 = operconstr LEVEL "200" ->
+ | c1 = term; "<<:"; c2 = term LEVEL "200" ->
{ CAst.make ~loc @@ CCast(c1, CastNative c2) }
- | c1 = operconstr; ":"; c2 = operconstr LEVEL "200" ->
+ | c1 = term; ":"; c2 = term LEVEL "200" ->
{ CAst.make ~loc @@ CCast(c1, CastConv c2) }
- | c1 = operconstr; ":>" ->
+ | c1 = term; ":>" ->
{ CAst.make ~loc @@ CCast(c1, CastCoerce) } ]
| "99" RIGHTA [ ]
| "90" RIGHTA [ ]
| "10" LEFTA
- [ f = operconstr; args = LIST1 appl_arg -> { CAst.make ~loc @@ CApp((None,f),args) }
- | "@"; f = global; i = univ_instance; args = LIST0 NEXT -> { CAst.make ~loc @@ CAppExpl((None,f,i),args) }
- | "@"; lid = pattern_identref; args = LIST1 identref ->
+ [ f = term; args = LIST1 arg -> { CAst.make ~loc @@ CApp((None,f),args) }
+ | "@"; f = global; i = univ_annot; args = LIST0 NEXT -> { CAst.make ~loc @@ CAppExpl((None,f,i),args) }
+ | "@"; lid = pattern_ident; args = LIST1 identref ->
{ let { CAst.loc = locid; v = id } = lid in
let args = List.map (fun x -> CAst.make @@ CRef (qualid_of_ident ?loc:x.CAst.loc x.CAst.v, None), None) args in
CAst.make ~loc @@ CApp((None, CAst.make ?loc:locid @@ CPatVar id),args) } ]
| "9"
- [ ".."; c = operconstr LEVEL "0"; ".." ->
+ [ ".."; c = term LEVEL "0"; ".." ->
{ CAst.make ~loc @@ CAppExpl ((None, (qualid_of_ident ~loc ldots_var), None),[c]) } ]
| "8" [ ]
| "1" LEFTA
- [ c = operconstr; ".("; f = global; args = LIST0 appl_arg; ")" ->
+ [ c = term; ".("; f = global; args = LIST0 arg; ")" ->
{ CAst.make ~loc @@ CApp((Some (List.length args+1), CAst.make @@ CRef (f,None)),args@[c,None]) }
- | c = operconstr; ".("; "@"; f = global;
- args = LIST0 (operconstr LEVEL "9"); ")" ->
+ | c = term; ".("; "@"; f = global;
+ args = LIST0 (term LEVEL "9"); ")" ->
{ CAst.make ~loc @@ CAppExpl((Some (List.length args+1),f,None),args@[c]) }
- | c = operconstr; "%"; key = IDENT -> { CAst.make ~loc @@ CDelimiters (key,c) } ]
+ | c = term; "%"; key = IDENT -> { CAst.make ~loc @@ CDelimiters (key,c) } ]
| "0"
[ c = atomic_constr -> { c }
- | c = match_constr -> { c }
- | "("; c = operconstr LEVEL "200"; ")" ->
- { (* Preserve parentheses around numerals so that constrintern does not
- collapse -(3) into the numeral -3. *)
+ | c = term_match -> { c }
+ | "("; c = term LEVEL "200"; ")" ->
+ { (* Preserve parentheses around numbers so that constrintern does not
+ collapse -(3) into the number -3. *)
(match c.CAst.v with
- | CPrim (Numeral (NumTok.SPlus,n)) ->
+ | CPrim (Number (NumTok.SPlus,n)) ->
CAst.make ~loc @@ CNotation(None,(InConstrEntry,"( _ )"),([c],[],[],[]))
| _ -> c) }
| "{|"; c = record_declaration; bar_cbrace -> { c }
| "{"; c = binder_constr ; "}" ->
{ CAst.make ~loc @@ CNotation(None,(InConstrEntry,"{ _ }"),([c],[],[],[])) }
- | "`{"; c = operconstr LEVEL "200"; "}" ->
+ | "`{"; c = term LEVEL "200"; "}" ->
{ CAst.make ~loc @@ CGeneralization (MaxImplicit, None, c) }
- | test_array_opening; "["; "|"; ls = array_elems; "|"; def = lconstr; ty = type_cstr; test_array_closing; "|"; "]"; u = univ_instance ->
+ | test_array_opening; "["; "|"; ls = array_elems; "|"; def = lconstr; ty = type_cstr; test_array_closing; "|"; "]"; u = univ_annot ->
{ let t = Array.make (List.length ls) def in
List.iteri (fun i e -> t.(i) <- e) ls;
CAst.make ~loc @@ CArray(u, t, def, ty)
}
- | "`("; c = operconstr LEVEL "200"; ")" ->
+ | "`("; c = term LEVEL "200"; ")" ->
{ CAst.make ~loc @@ CGeneralization (Explicit, None, c) } ] ]
;
array_elems:
@@ -208,71 +208,71 @@ GRAMMAR EXTEND Gram
{ (id, mkLambdaCN ~loc bl c) } ] ]
;
binder_constr:
- [ [ "forall"; bl = open_binders; ","; c = operconstr LEVEL "200" ->
+ [ [ "forall"; bl = open_binders; ","; c = term LEVEL "200" ->
{ mkProdCN ~loc bl c }
- | "fun"; bl = open_binders; "=>"; c = operconstr LEVEL "200" ->
+ | "fun"; bl = open_binders; "=>"; c = term LEVEL "200" ->
{ mkLambdaCN ~loc bl c }
| "let"; id=name; bl = binders; ty = let_type_cstr; ":=";
- c1 = operconstr LEVEL "200"; "in"; c2 = operconstr LEVEL "200" ->
+ c1 = term LEVEL "200"; "in"; c2 = term LEVEL "200" ->
{ let ty,c1 = match ty, c1 with
| (_,None), { CAst.v = CCast(c, CastConv t) } -> (Loc.tag ?loc:(constr_loc t) @@ Some t), c (* Tolerance, see G_vernac.def_body *)
| _, _ -> ty, c1 in
CAst.make ~loc @@ CLetIn(id,mkLambdaCN ?loc:(constr_loc c1) bl c1,
Option.map (mkProdCN ?loc:(fst ty) bl) (snd ty), c2) }
- | "let"; "fix"; fx = fix_decl; "in"; c = operconstr LEVEL "200" ->
+ | "let"; "fix"; fx = fix_decl; "in"; c = term LEVEL "200" ->
{ let {CAst.loc=locf;CAst.v=({CAst.loc=li;CAst.v=id} as lid,_,_,_,_ as dcl)} = fx in
let fix = CAst.make ?loc:locf @@ CFix (lid,[dcl]) in
CAst.make ~loc @@ CLetIn( CAst.make ?loc:li @@ Name id,fix,None,c) }
- | "let"; "cofix"; fx = cofix_decl; "in"; c = operconstr LEVEL "200" ->
+ | "let"; "cofix"; fx = cofix_body; "in"; c = term LEVEL "200" ->
{ let {CAst.loc=locf;CAst.v=({CAst.loc=li;CAst.v=id} as lid,_,_,_ as dcl)} = fx in
let cofix = CAst.make ?loc:locf @@ CCoFix (lid,[dcl]) in
CAst.make ~loc @@ CLetIn( CAst.make ?loc:li @@ Name id,cofix,None,c) }
| "let"; lb = ["("; l=LIST0 name SEP ","; ")" -> { l } | "()" -> { [] } ];
- po = return_type; ":="; c1 = operconstr LEVEL "200"; "in";
- c2 = operconstr LEVEL "200" ->
+ po = as_return_type; ":="; c1 = term LEVEL "200"; "in";
+ c2 = term LEVEL "200" ->
{ CAst.make ~loc @@ CLetTuple (lb,po,c1,c2) }
- | "let"; "'"; p = pattern LEVEL "200"; ":="; c1 = operconstr LEVEL "200";
- "in"; c2 = operconstr LEVEL "200" ->
+ | "let"; "'"; p = pattern LEVEL "200"; ":="; c1 = term LEVEL "200";
+ "in"; c2 = term LEVEL "200" ->
{ CAst.make ~loc @@
CCases (LetPatternStyle, None, [c1, None, None], [CAst.make ~loc ([[p]], c2)]) }
- | "let"; "'"; p = pattern LEVEL "200"; ":="; c1 = operconstr LEVEL "200";
- rt = case_type; "in"; c2 = operconstr LEVEL "200" ->
+ | "let"; "'"; p = pattern LEVEL "200"; ":="; c1 = term LEVEL "200";
+ rt = case_type; "in"; c2 = term LEVEL "200" ->
{ CAst.make ~loc @@
CCases (LetPatternStyle, Some rt, [c1, aliasvar p, None], [CAst.make ~loc ([[p]], c2)]) }
| "let"; "'"; p = pattern LEVEL "200"; "in"; t = pattern LEVEL "200";
- ":="; c1 = operconstr LEVEL "200"; rt = case_type;
- "in"; c2 = operconstr LEVEL "200" ->
+ ":="; c1 = term LEVEL "200"; rt = case_type;
+ "in"; c2 = term LEVEL "200" ->
{ CAst.make ~loc @@
CCases (LetPatternStyle, Some rt, [c1, aliasvar p, Some t], [CAst.make ~loc ([[p]], c2)]) }
- | "if"; c = operconstr LEVEL "200"; po = return_type;
- "then"; b1 = operconstr LEVEL "200";
- "else"; b2 = operconstr LEVEL "200" ->
+ | "if"; c = term LEVEL "200"; po = as_return_type;
+ "then"; b1 = term LEVEL "200";
+ "else"; b2 = term LEVEL "200" ->
{ CAst.make ~loc @@ CIf (c, po, b1, b2) }
| "fix"; c = fix_decls -> { let (id,dcls) = c in CAst.make ~loc @@ CFix (id,dcls) }
| "cofix"; c = cofix_decls -> { let (id,dcls) = c in CAst.make ~loc @@ CCoFix (id,dcls) } ] ]
;
- appl_arg:
- [ [ test_lpar_id_coloneq; "("; id = ident; ":="; c = lconstr; ")" -> { (c,Some (CAst.make ~loc @@ ExplByName id)) }
- | c=operconstr LEVEL "9" -> { (c,None) } ] ]
+ arg:
+ [ [ test_lpar_id_coloneq; "("; id = identref; ":="; c = lconstr; ")" -> { (c,Some (CAst.make ?loc:id.CAst.loc @@ ExplByName id.CAst.v)) }
+ | c=term LEVEL "9" -> { (c,None) } ] ]
;
atomic_constr:
- [ [ g = global; i = univ_instance -> { CAst.make ~loc @@ CRef (g,i) }
+ [ [ g = global; i = univ_annot -> { CAst.make ~loc @@ CRef (g,i) }
| s = sort -> { CAst.make ~loc @@ CSort s }
- | n = NUMBER-> { CAst.make ~loc @@ CPrim (Numeral (NumTok.SPlus,n)) }
+ | n = NUMBER-> { CAst.make ~loc @@ CPrim (Number (NumTok.SPlus,n)) }
| s = string -> { CAst.make ~loc @@ CPrim (String s) }
| "_" -> { CAst.make ~loc @@ CHole (None, IntroAnonymous, None) }
- | "?"; "["; id = ident; "]" -> { CAst.make ~loc @@ CHole (None, IntroIdentifier id, None) }
- | "?"; "["; id = pattern_ident; "]" -> { CAst.make ~loc @@ CHole (None, IntroFresh id, None) }
+ | "?"; "["; id = identref; "]" -> { CAst.make ~loc @@ CHole (None, IntroIdentifier id.CAst.v, None) }
+ | "?"; "["; id = pattern_ident; "]" -> { CAst.make ~loc @@ CHole (None, IntroFresh id.CAst.v, None) }
| id = pattern_ident; inst = evar_instance -> { CAst.make ~loc @@ CEvar(id,inst) } ] ]
;
inst:
- [ [ id = ident; ":="; c = lconstr -> { (id,c) } ] ]
+ [ [ id = identref; ":="; c = lconstr -> { (id,c) } ] ]
;
evar_instance:
[ [ "@{"; l = LIST1 inst SEP ";"; "}" -> { l }
| -> { [] } ] ]
;
- univ_instance:
+ univ_annot:
[ [ "@{"; l = LIST0 universe_level; "}" -> { Some l }
| -> { None } ] ]
;
@@ -290,34 +290,34 @@ GRAMMAR EXTEND Gram
{ (id,List.map (fun x -> x.CAst.v) (dcl::dcls)) } ] ]
;
cofix_decls:
- [ [ dcl = cofix_decl -> { let (id,_,_,_) = dcl.CAst.v in (id,[dcl.CAst.v]) }
- | dcl = cofix_decl; "with"; dcls = LIST1 cofix_decl SEP "with"; "for"; id = identref ->
+ [ [ dcl = cofix_body -> { let (id,_,_,_) = dcl.CAst.v in (id,[dcl.CAst.v]) }
+ | dcl = cofix_body; "with"; dcls = LIST1 cofix_body SEP "with"; "for"; id = identref ->
{ (id,List.map (fun x -> x.CAst.v) (dcl::dcls)) } ] ]
;
fix_decl:
[ [ id = identref; bl = binders_fixannot; ty = type_cstr; ":=";
- c = operconstr LEVEL "200" ->
+ c = term LEVEL "200" ->
{ CAst.make ~loc (id,snd bl,fst bl,ty,c) } ] ]
;
- cofix_decl:
+ cofix_body:
[ [ id = identref; bl = binders; ty = type_cstr; ":=";
- c = operconstr LEVEL "200" ->
+ c = term LEVEL "200" ->
{ CAst.make ~loc (id,bl,ty,c) } ] ]
;
- match_constr:
+ term_match:
[ [ "match"; ci = LIST1 case_item SEP ","; ty = OPT case_type; "with";
br = branches; "end" -> { CAst.make ~loc @@ CCases(RegularStyle,ty,ci,br) } ] ]
;
case_item:
- [ [ c = operconstr LEVEL "100";
+ [ [ c = term LEVEL "100";
ona = OPT ["as"; id = name -> { id } ];
ty = OPT ["in"; t = pattern LEVEL "200" -> { t } ] ->
{ (c,ona,ty) } ] ]
;
case_type:
- [ [ "return"; ty = operconstr LEVEL "100" -> { ty } ] ]
+ [ [ "return"; ty = term LEVEL "100" -> { ty } ] ]
;
- return_type:
+ as_return_type:
[ [ a = OPT [ na = OPT["as"; na = name -> { na } ];
ty = case_type -> { (na,ty) } ] ->
{ match a with
@@ -345,7 +345,7 @@ GRAMMAR EXTEND Gram
pattern:
[ "200" RIGHTA [ ]
| "100" RIGHTA
- [ p = pattern; ":"; ty = operconstr LEVEL "200" ->
+ [ p = pattern; ":"; ty = term LEVEL "200" ->
{ CAst.make ~loc @@ CPatCast (p, ty) } ]
| "99" RIGHTA [ ]
| "90" RIGHTA [ ]
@@ -362,15 +362,15 @@ GRAMMAR EXTEND Gram
| "{|"; pat = record_patterns; bar_cbrace -> { CAst.make ~loc @@ CPatRecord pat }
| "_" -> { CAst.make ~loc @@ CPatAtom None }
| "("; p = pattern LEVEL "200"; ")" ->
- { (* Preserve parentheses around numerals so that constrintern does not
- collapse -(3) into the numeral -3. *)
+ { (* Preserve parentheses around numbers so that constrintern does not
+ collapse -(3) into the number -3. *)
match p.CAst.v with
- | CPatPrim (Numeral (NumTok.SPlus,n)) ->
+ | CPatPrim (Number (NumTok.SPlus,n)) ->
CAst.make ~loc @@ CPatNotation(None,(InConstrEntry,"( _ )"),([p],[]),[])
| _ -> p }
| "("; p = pattern LEVEL "200"; "|" ; pl = LIST1 pattern LEVEL "200" SEP "|"; ")" ->
{ CAst.make ~loc @@ CPatOr (p::pl) }
- | n = NUMBER-> { CAst.make ~loc @@ CPatPrim (Numeral (NumTok.SPlus,n)) }
+ | n = NUMBER-> { CAst.make ~loc @@ CPatPrim (Number (NumTok.SPlus,n)) }
| s = string -> { CAst.make ~loc @@ CPatPrim (String s) } ] ]
;
fixannot:
@@ -447,12 +447,12 @@ GRAMMAR EXTEND Gram
[CLocalPattern (CAst.make ~loc (p, ty))] } ] ]
;
typeclass_constraint:
- [ [ "!" ; c = operconstr LEVEL "200" -> { (CAst.make ~loc Anonymous), true, c }
- | "{"; id = name; "}"; ":" ; expl = [ "!" -> { true } | -> { false } ] ; c = operconstr LEVEL "200" ->
+ [ [ "!" ; c = term LEVEL "200" -> { (CAst.make ~loc Anonymous), true, c }
+ | "{"; id = name; "}"; ":" ; expl = [ "!" -> { true } | -> { false } ] ; c = term LEVEL "200" ->
{ id, expl, c }
- | test_name_colon; iid = name; ":" ; expl = [ "!" -> { true } | -> { false } ] ; c = operconstr LEVEL "200" ->
+ | test_name_colon; iid = name; ":" ; expl = [ "!" -> { true } | -> { false } ] ; c = term LEVEL "200" ->
{ iid, expl, c }
- | c = operconstr LEVEL "200" ->
+ | c = term LEVEL "200" ->
{ (CAst.make ~loc Anonymous), false, c } ] ]
;
type_cstr:
diff --git a/parsing/g_prim.mlg b/parsing/g_prim.mlg
index 270662b824..1701830cd2 100644
--- a/parsing/g_prim.mlg
+++ b/parsing/g_prim.mlg
@@ -45,9 +45,9 @@ let test_minus_nat =
GRAMMAR EXTEND Gram
GLOBAL:
- bignat bigint natural integer identref name ident var preident
+ bignat bigint natural integer identref name ident hyp preident
fullyqualid qualid reference dirpath ne_lstring
- ne_string string lstring pattern_ident pattern_identref by_notation
+ ne_string string lstring pattern_ident by_notation
smart_global bar_cbrace strategy_level;
preident:
[ [ s = IDENT -> { s } ] ]
@@ -56,17 +56,14 @@ GRAMMAR EXTEND Gram
[ [ s = IDENT -> { Id.of_string s } ] ]
;
pattern_ident:
- [ [ LEFTQMARK; id = ident -> { id } ] ]
- ;
- pattern_identref:
- [ [ id = pattern_ident -> { CAst.make ~loc id } ] ]
- ;
- var: (* as identref, but interpret as a term identifier in ltac *)
- [ [ id = ident -> { CAst.make ~loc id } ] ]
+ [ [ LEFTQMARK; id = ident -> { CAst.make ~loc id } ] ]
;
identref:
[ [ id = ident -> { CAst.make ~loc id } ] ]
;
+ hyp: (* as identref, but interpreted as an hypothesis in tactic notations *)
+ [ [ id = identref -> { id } ] ]
+ ;
field:
[ [ s = FIELD -> { Id.of_string s } ] ]
;
diff --git a/parsing/pcoq.ml b/parsing/pcoq.ml
index 723f08413e..22b5e70311 100644
--- a/parsing/pcoq.ml
+++ b/parsing/pcoq.ml
@@ -279,14 +279,15 @@ module Prim =
let strategy_level = Entry.create "strategy_level"
(* parsed like ident but interpreted as a term *)
- let var = Entry.create "var"
+ let hyp = Entry.create "hyp"
+ let var = hyp
let name = Entry.create "name"
let identref = Entry.create "identref"
let univ_decl = Entry.create "univ_decl"
let ident_decl = Entry.create "ident_decl"
let pattern_ident = Entry.create "pattern_ident"
- let pattern_identref = Entry.create "pattern_identref"
+ let pattern_identref = pattern_ident (* To remove in 8.14 *)
(* A synonym of ident - maybe ident will be located one day *)
let base_ident = Entry.create "base_ident"
@@ -307,7 +308,8 @@ module Constr =
(* Entries that can be referred via the string -> Entry.t table *)
let constr = Entry.create "constr"
- let operconstr = Entry.create "operconstr"
+ let term = Entry.create "term"
+ let operconstr = term
let constr_eoi = eoi_entry constr
let lconstr = Entry.create "lconstr"
let binder_constr = Entry.create "binder_constr"
@@ -319,7 +321,8 @@ module Constr =
let sort_family = Entry.create "sort_family"
let pattern = Entry.create "pattern"
let constr_pattern = Entry.create "constr_pattern"
- let lconstr_pattern = Entry.create "lconstr_pattern"
+ let cpattern = Entry.create "cpattern"
+ let lconstr_pattern = cpattern
let closed_binder = Entry.create "closed_binder"
let binder = Entry.create "binder"
let binders = Entry.create "binders"
@@ -327,7 +330,8 @@ module Constr =
let binders_fixannot = Entry.create "binders_fixannot"
let typeclass_constraint = Entry.create "typeclass_constraint"
let record_declaration = Entry.create "record_declaration"
- let appl_arg = Entry.create "appl_arg"
+ let arg = Entry.create "arg"
+ let appl_arg = arg
let type_cstr = Entry.create "type_cstr"
end
@@ -504,7 +508,7 @@ let () =
Grammar.register0 wit_string (Prim.string);
Grammar.register0 wit_pre_ident (Prim.preident);
Grammar.register0 wit_ident (Prim.ident);
- Grammar.register0 wit_var (Prim.var);
+ Grammar.register0 wit_hyp (Prim.hyp);
Grammar.register0 wit_ref (Prim.reference);
Grammar.register0 wit_smart_global (Prim.smart_global);
Grammar.register0 wit_sort_family (Constr.sort_family);
diff --git a/parsing/pcoq.mli b/parsing/pcoq.mli
index ae9a7423c2..ce4c91d51f 100644
--- a/parsing/pcoq.mli
+++ b/parsing/pcoq.mli
@@ -156,8 +156,8 @@ module Prim :
val identref : lident Entry.t
val univ_decl : universe_decl_expr Entry.t
val ident_decl : ident_decl Entry.t
- val pattern_ident : Id.t Entry.t
- val pattern_identref : lident Entry.t
+ val pattern_ident : lident Entry.t
+ val pattern_identref : lident Entry.t [@@ocaml.deprecated "Use Prim.pattern_identref"]
val base_ident : Id.t Entry.t
val bignat : string Entry.t
val natural : int Entry.t
@@ -173,7 +173,8 @@ module Prim :
val dirpath : DirPath.t Entry.t
val ne_string : string Entry.t
val ne_lstring : lstring Entry.t
- val var : lident Entry.t
+ val hyp : lident Entry.t
+ val var : lident Entry.t [@@ocaml.deprecated "Use Prim.hyp"]
val bar_cbrace : unit Entry.t
val strategy_level : Conv_oracle.level Entry.t
end
@@ -184,7 +185,9 @@ module Constr :
val constr_eoi : constr_expr Entry.t
val lconstr : constr_expr Entry.t
val binder_constr : constr_expr Entry.t
+ val term : constr_expr Entry.t
val operconstr : constr_expr Entry.t
+ [@@deprecated "Deprecated in 8.13; use 'term' instead"]
val ident : Id.t Entry.t
val global : qualid Entry.t
val universe_name : Glob_term.glob_sort_name Entry.t
@@ -193,7 +196,9 @@ module Constr :
val sort_family : Sorts.family Entry.t
val pattern : cases_pattern_expr Entry.t
val constr_pattern : constr_expr Entry.t
+ val cpattern : constr_expr Entry.t
val lconstr_pattern : constr_expr Entry.t
+ [@@deprecated "Deprecated in 8.13; use 'cpattern' instead"]
val closed_binder : local_binder_expr list Entry.t
val binder : local_binder_expr list Entry.t (* closed_binder or variable *)
val binders : local_binder_expr list Entry.t (* list of binder *)
@@ -201,7 +206,9 @@ module Constr :
val binders_fixannot : (local_binder_expr list * recursion_order_expr option) Entry.t
val typeclass_constraint : (lname * bool * constr_expr) Entry.t
val record_declaration : constr_expr Entry.t
+ val arg : (constr_expr * explicitation CAst.t option) Entry.t
val appl_arg : (constr_expr * explicitation CAst.t option) Entry.t
+ [@@deprecated "Deprecated in 8.13; use 'arg' instead"]
val type_cstr : constr_expr Entry.t
end
diff --git a/parsing/ppextend.ml b/parsing/ppextend.ml
index fe6e8360c1..aab385a707 100644
--- a/parsing/ppextend.ml
+++ b/parsing/ppextend.ml
@@ -17,7 +17,7 @@ open Constrexpr
(*s Pretty-print. *)
type ppbox =
- | PpHB of int
+ | PpHB
| PpHOVB of int
| PpHVB of int
| PpVB of int
@@ -27,7 +27,7 @@ type ppcut =
| PpFnl
let ppcmd_of_box = function
- | PpHB n -> h n
+ | PpHB -> h
| PpHOVB n -> hov n
| PpHVB n -> hv n
| PpVB n -> v n
diff --git a/parsing/ppextend.mli b/parsing/ppextend.mli
index ee8180c7aa..56a3fc8e3c 100644
--- a/parsing/ppextend.mli
+++ b/parsing/ppextend.mli
@@ -13,7 +13,7 @@ open Constrexpr
(** {6 Pretty-print. } *)
type ppbox =
- | PpHB of int
+ | PpHB
| PpHOVB of int
| PpHVB of int
| PpVB of int
diff --git a/plugins/btauto/refl_btauto.ml b/plugins/btauto/refl_btauto.ml
index 23f8fe04a3..ac2058ba1b 100644
--- a/plugins/btauto/refl_btauto.ml
+++ b/plugins/btauto/refl_btauto.ml
@@ -115,7 +115,7 @@ module Bool = struct
| Case (info, r, _iv, arg, pats) ->
let is_bool =
let i = info.ci_ind in
- Names.eq_ind i (Lazy.force ind)
+ Names.Ind.CanOrd.equal i (Lazy.force ind)
in
if is_bool then
Ifb ((aux arg), (aux pats.(0)), (aux pats.(1)))
diff --git a/plugins/cc/ccalgo.ml b/plugins/cc/ccalgo.ml
index 6f5c910297..129b220680 100644
--- a/plugins/cc/ccalgo.ml
+++ b/plugins/cc/ccalgo.ml
@@ -145,7 +145,7 @@ let rec term_equal t1 t2 =
| Appli (t1, u1), Appli (t2, u2) -> term_equal t1 t2 && term_equal u1 u2
| Constructor {ci_constr=(c1,u1); ci_arity=i1; ci_nhyps=j1},
Constructor {ci_constr=(c2,u2); ci_arity=i2; ci_nhyps=j2} ->
- Int.equal i1 i2 && Int.equal j1 j2 && eq_constructor c1 c2 (* FIXME check eq? *)
+ Int.equal i1 i2 && Int.equal j1 j2 && Construct.CanOrd.equal c1 c2 (* FIXME check eq? *)
| _ -> false
open Hashset.Combine
@@ -155,7 +155,7 @@ let rec hash_term = function
| Product (s1, s2) -> combine3 2 (Sorts.hash s1) (Sorts.hash s2)
| Eps i -> combine 3 (Id.hash i)
| Appli (t1, t2) -> combine3 4 (hash_term t1) (hash_term t2)
- | Constructor {ci_constr=(c,u); ci_arity=i; ci_nhyps=j} -> combine4 5 (constructor_hash c) i j
+ | Constructor {ci_constr=(c,u); ci_arity=i; ci_nhyps=j} -> combine4 5 (Construct.CanOrd.hash c) i j
type ccpattern =
PApp of term * ccpattern list (* arguments are reversed *)
diff --git a/plugins/extraction/extraction.ml b/plugins/extraction/extraction.ml
index 2dca1d5e49..6869f9c47e 100644
--- a/plugins/extraction/extraction.ml
+++ b/plugins/extraction/extraction.ml
@@ -741,7 +741,7 @@ and extract_cst_app env sg mle mlt kn args =
(* Can we instantiate types variables for this constant ? *)
(* In Ocaml, inside the definition of this constant, the answer is no. *)
let instantiated =
- if lang () == Ocaml && List.mem_f Constant.equal kn !current_fixpoints
+ if lang () == Ocaml && List.mem_f Constant.CanOrd.equal kn !current_fixpoints
then var2var' (snd schema)
else instantiation schema
in
diff --git a/plugins/extraction/mlutil.ml b/plugins/extraction/mlutil.ml
index b1ce10985a..21ec80abbc 100644
--- a/plugins/extraction/mlutil.ml
+++ b/plugins/extraction/mlutil.ml
@@ -685,7 +685,7 @@ let is_regular_match br =
| _ -> raise Impossible
in
let is_ref i tr = match get_r tr with
- | GlobRef.ConstructRef (ind', j) -> eq_ind ind ind' && Int.equal j (i + 1)
+ | GlobRef.ConstructRef (ind', j) -> Ind.CanOrd.equal ind ind' && Int.equal j (i + 1)
| _ -> false
in
Array.for_all_i is_ref 0 br
diff --git a/plugins/extraction/scheme.ml b/plugins/extraction/scheme.ml
index ee50476b10..f671860bd5 100644
--- a/plugins/extraction/scheme.ml
+++ b/plugins/extraction/scheme.ml
@@ -28,7 +28,7 @@ let keywords =
"error"; "delay"; "force"; "_"; "__"]
Id.Set.empty
-let pp_comment s = str";; "++h 0 s++fnl ()
+let pp_comment s = str ";; " ++ h s ++ fnl ()
let pp_header_comment = function
| None -> mt ()
diff --git a/plugins/extraction/table.ml b/plugins/extraction/table.ml
index f8449bcda1..e56d66ca2d 100644
--- a/plugins/extraction/table.ml
+++ b/plugins/extraction/table.ml
@@ -32,7 +32,7 @@ module Refset' = GlobRef.Set_env
let occur_kn_in_ref kn = let open GlobRef in function
| IndRef (kn',_)
- | ConstructRef ((kn',_),_) -> MutInd.equal kn kn'
+ | ConstructRef ((kn',_),_) -> MutInd.CanOrd.equal kn kn'
| ConstRef _ | VarRef _ -> false
let repr_of_r = let open GlobRef in function
diff --git a/plugins/firstorder/instances.ml b/plugins/firstorder/instances.ml
index f13901c36d..4adad53899 100644
--- a/plugins/firstorder/instances.ml
+++ b/plugins/firstorder/instances.ml
@@ -38,7 +38,7 @@ let compare_gr id1 id2 =
if id1==id2 then 0 else
if id1==dummy_id then 1
else if id2==dummy_id then -1
- else GlobRef.Ordered.compare id1 id2
+ else GlobRef.CanOrd.compare id1 id2
module OrderedInstance=
struct
diff --git a/plugins/firstorder/sequent.ml b/plugins/firstorder/sequent.ml
index db3631daa4..99c5f85125 100644
--- a/plugins/firstorder/sequent.ml
+++ b/plugins/firstorder/sequent.ml
@@ -62,7 +62,7 @@ module Hitem=
struct
type t = h_item
let compare (id1,co1) (id2,co2)=
- let c = GlobRef.Ordered.compare id1 id2 in
+ let c = GlobRef.CanOrd.compare id1 id2 in
if c = 0 then
let cmp (i1, c1) (i2, c2) =
let c = Int.compare i1 i2 in
diff --git a/plugins/funind/functional_principles_proofs.ml b/plugins/funind/functional_principles_proofs.ml
index e50c6087bb..73eb943418 100644
--- a/plugins/funind/functional_principles_proofs.ml
+++ b/plugins/funind/functional_principles_proofs.ml
@@ -674,7 +674,7 @@ let build_proof (interactive_proof : bool) (fnames : Constant.t list) ptes_infos
|Prod _ ->
let new_infos = {dyn_infos with info = (f, args)} in
build_proof_args env sigma do_finalize new_infos
- | Const (c, _) when not (List.mem_f Constant.equal c fnames) ->
+ | Const (c, _) when not (List.mem_f Constant.CanOrd.equal c fnames) ->
let new_infos = {dyn_infos with info = (f, args)} in
(* Pp.msgnl (str "proving in " ++ pr_lconstr_env (pf_env g) dyn_infos.info); *)
build_proof_args env sigma do_finalize new_infos
diff --git a/plugins/funind/functional_principles_types.ml b/plugins/funind/functional_principles_types.ml
index 1ab747ca09..0ab9ac65d7 100644
--- a/plugins/funind/functional_principles_types.ml
+++ b/plugins/funind/functional_principles_types.ml
@@ -100,8 +100,8 @@ let compute_new_princ_type_from_rel rel_to_fun sorts princ_type =
let pre_princ = substl (List.map mkVar ptes_vars) pre_princ in
let is_dom c =
match Constr.kind c with
- | Ind ((u, _), _) -> MutInd.equal u rel_as_kn
- | Construct (((u, _), _), _) -> MutInd.equal u rel_as_kn
+ | Ind ((u, _), _) -> Environ.QMutInd.equal env u rel_as_kn
+ | Construct (((u, _), _), _) -> Environ.QMutInd.equal env u rel_as_kn
| _ -> false
in
let get_fun_num c =
diff --git a/plugins/funind/g_indfun.mlg b/plugins/funind/g_indfun.mlg
index bbc4df7dde..ca6ae150a7 100644
--- a/plugins/funind/g_indfun.mlg
+++ b/plugins/funind/g_indfun.mlg
@@ -147,19 +147,19 @@ END
module Vernac = Pvernac.Vernac_
module Tactic = Pltac
-let (wit_function_rec_definition_loc : Vernacexpr.fixpoint_expr Loc.located Genarg.uniform_genarg_type) =
- Genarg.create_arg "function_rec_definition_loc"
+let (wit_function_fix_definition : Vernacexpr.fixpoint_expr Loc.located Genarg.uniform_genarg_type) =
+ Genarg.create_arg "function_fix_definition"
-let function_rec_definition_loc =
- Pcoq.create_generic_entry2 "function_rec_definition_loc" (Genarg.rawwit wit_function_rec_definition_loc)
+let function_fix_definition =
+ Pcoq.create_generic_entry2 "function_fix_definition" (Genarg.rawwit wit_function_fix_definition)
}
GRAMMAR EXTEND Gram
- GLOBAL: function_rec_definition_loc ;
+ GLOBAL: function_fix_definition ;
- function_rec_definition_loc:
- [ [ g = Vernac.rec_definition -> { Loc.tag ~loc g } ]]
+ function_fix_definition:
+ [ [ g = Vernac.fix_definition -> { Loc.tag ~loc g } ]]
;
END
@@ -168,7 +168,7 @@ END
let () =
let raw_printer env sigma _ _ _ (loc,body) = Ppvernac.pr_rec_definition body in
- Pptactic.declare_extra_vernac_genarg_pprule wit_function_rec_definition_loc raw_printer
+ Pptactic.declare_extra_vernac_genarg_pprule wit_function_fix_definition raw_printer
let is_proof_termination_interactively_checked recsl =
List.exists (function
@@ -196,7 +196,7 @@ let is_interactive recsl =
}
VERNAC COMMAND EXTEND Function STATE CUSTOM
-| ["Function" ne_function_rec_definition_loc_list_sep(recsl,"with")]
+| ["Function" ne_function_fix_definition_list_sep(recsl,"with")]
=> { classify_funind recsl }
-> {
if is_interactive recsl then
diff --git a/plugins/funind/gen_principle.ml b/plugins/funind/gen_principle.ml
index 1ea803f561..314c8abcaf 100644
--- a/plugins/funind/gen_principle.ml
+++ b/plugins/funind/gen_principle.ml
@@ -1316,9 +1316,9 @@ let make_scheme evd (fas : (Constr.pconstant * Sorts.family) list) : _ list =
let prop_sort = Sorts.InProp in
let funs_indexes =
let this_block_funs_indexes = Array.to_list this_block_funs_indexes in
+ let eq c1 c2 = Environ.QConstant.equal env c1 c2 in
List.map
- (function
- | cst -> List.assoc_f Constant.equal (fst cst) this_block_funs_indexes)
+ (function cst -> List.assoc_f eq (fst cst) this_block_funs_indexes)
funs
in
let ind_list =
@@ -1860,13 +1860,13 @@ let do_generate_principle_aux pconstants on_error register_built
let warn_cannot_define_graph =
CWarnings.create ~name:"funind-cannot-define-graph" ~category:"funind"
(fun (names, error) ->
- Pp.(strbrk "Cannot define graph(s) for " ++ h 1 names ++ error))
+ Pp.(strbrk "Cannot define graph(s) for " ++ hv 1 names ++ error))
let warn_cannot_define_principle =
CWarnings.create ~name:"funind-cannot-define-principle" ~category:"funind"
(fun (names, error) ->
Pp.(
- strbrk "Cannot define induction principle(s) for " ++ h 1 names ++ error))
+ strbrk "Cannot define induction principle(s) for " ++ hv 1 names ++ error))
let warning_error names e =
let e_explain e =
@@ -1898,7 +1898,7 @@ let error_error names e =
CErrors.user_err
Pp.(
str "Cannot define graph(s) for "
- ++ h 1
+ ++ hv 1
(prlist_with_sep (fun _ -> str "," ++ spc ()) Ppconstr.pr_id names)
++ e_explain e)
| _ -> raise e
@@ -2228,7 +2228,8 @@ let build_case_scheme fa =
let prop_sort = Sorts.InProp in
let funs_indexes =
let this_block_funs_indexes = Array.to_list this_block_funs_indexes in
- List.assoc_f Constant.equal funs this_block_funs_indexes
+ let eq c1 c2 = Environ.QConstant.equal env c1 c2 in
+ List.assoc_f eq funs this_block_funs_indexes
in
let ind, sf =
let ind = (first_fun_kn, funs_indexes) in
diff --git a/plugins/funind/glob_term_to_relation.ml b/plugins/funind/glob_term_to_relation.ml
index 6ed61043f9..767a9ec39b 100644
--- a/plugins/funind/glob_term_to_relation.ml
+++ b/plugins/funind/glob_term_to_relation.ml
@@ -332,7 +332,7 @@ let add_pat_variables sigma pat typ env : Environ.env =
let constructors = Inductiveops.get_constructors env indf in
let constructor : Inductiveops.constructor_summary =
List.find
- (fun cs -> eq_constructor c (fst cs.Inductiveops.cs_cstr))
+ (fun cs -> Construct.CanOrd.equal c (fst cs.Inductiveops.cs_cstr))
(Array.to_list constructors)
in
let cs_args_types : types list =
@@ -402,7 +402,8 @@ let rec pattern_to_term_and_type env typ =
let constructors = Inductiveops.get_constructors env indf in
let constructor =
List.find
- (fun cs -> eq_constructor (fst cs.Inductiveops.cs_cstr) constr)
+ (fun cs ->
+ Construct.CanOrd.equal (fst cs.Inductiveops.cs_cstr) constr)
(Array.to_list constructors)
in
let cs_args_types : types list =
diff --git a/plugins/funind/glob_termops.ml b/plugins/funind/glob_termops.ml
index 8e1331ace9..164a446fe3 100644
--- a/plugins/funind/glob_termops.ml
+++ b/plugins/funind/glob_termops.ml
@@ -444,7 +444,8 @@ let rec are_unifiable_aux = function
match (DAst.get l, DAst.get r) with
| PatVar _, _ | _, PatVar _ -> are_unifiable_aux eqs
| PatCstr (constructor1, cpl1, _), PatCstr (constructor2, cpl2, _) ->
- if not (eq_constructor constructor2 constructor1) then raise NotUnifiable
+ if not (Construct.CanOrd.equal constructor2 constructor1) then
+ raise NotUnifiable
else
let eqs' =
try List.combine cpl1 cpl2 @ eqs
@@ -464,7 +465,8 @@ let rec eq_cases_pattern_aux = function
match (DAst.get l, DAst.get r) with
| PatVar _, PatVar _ -> eq_cases_pattern_aux eqs
| PatCstr (constructor1, cpl1, _), PatCstr (constructor2, cpl2, _) ->
- if not (eq_constructor constructor2 constructor1) then raise NotUnifiable
+ if not (Construct.CanOrd.equal constructor2 constructor1) then
+ raise NotUnifiable
else
let eqs' =
try List.combine cpl1 cpl2 @ eqs
diff --git a/plugins/funind/invfun.ml b/plugins/funind/invfun.ml
index 5d631aac84..118a917381 100644
--- a/plugins/funind/invfun.ml
+++ b/plugins/funind/invfun.ml
@@ -27,12 +27,13 @@ open Indfun_common
*)
let revert_graph kn post_tac hid =
Proofview.Goal.enter (fun gl ->
+ let env = Proofview.Goal.env gl in
let sigma = project gl in
let typ = pf_get_hyp_typ hid gl in
match EConstr.kind sigma typ with
| App (i, args) when isInd sigma i ->
let ((kn', num) as ind'), u = destInd sigma i in
- if MutInd.equal kn kn' then
+ if Environ.QMutInd.equal env kn kn' then
(* We have generated a graph hypothesis so that we must change it if we can *)
let info =
match find_Function_of_graph ind' with
diff --git a/plugins/ltac/coretactics.mlg b/plugins/ltac/coretactics.mlg
index f1f538ab39..b7ac71181a 100644
--- a/plugins/ltac/coretactics.mlg
+++ b/plugins/ltac/coretactics.mlg
@@ -20,8 +20,6 @@ open Tacarg
open Names
open Logic
-let wit_hyp = wit_var
-
}
DECLARE PLUGIN "ltac_plugin"
diff --git a/plugins/ltac/extraargs.mlg b/plugins/ltac/extraargs.mlg
index 863c4d37d8..ff4a82f864 100644
--- a/plugins/ltac/extraargs.mlg
+++ b/plugins/ltac/extraargs.mlg
@@ -41,13 +41,13 @@ let () = create_generic_quotation "ipattern" Pltac.simple_intropattern wit_simpl
let () = create_generic_quotation "open_constr" Pcoq.Constr.lconstr Stdarg.wit_open_constr
let () =
let inject (loc, v) = Tacexpr.Tacexp v in
- Tacentries.create_ltac_quotation "ltac" inject (Pltac.tactic_expr, Some 5)
+ Tacentries.create_ltac_quotation "ltac" inject (Pltac.ltac_expr, Some 5)
(** Backward-compatible tactic notation entry names *)
let () =
let register name entry = Tacentries.register_tactic_notation_entry name entry in
- register "hyp" wit_var;
+ register "hyp" wit_hyp;
register "simple_intropattern" wit_simple_intropattern;
register "integer" wit_integer;
register "reference" wit_ref;
@@ -140,7 +140,7 @@ ARGUMENT EXTEND occurrences
GLOB_PRINTED BY { pr_occurrences }
| [ ne_integer_list(l) ] -> { ArgArg l }
-| [ var(id) ] -> { ArgVar id }
+| [ hyp(id) ] -> { ArgVar id }
END
{
diff --git a/plugins/ltac/extratactics.mlg b/plugins/ltac/extratactics.mlg
index 4f20e5a800..a2a47c0bf4 100644
--- a/plugins/ltac/extratactics.mlg
+++ b/plugins/ltac/extratactics.mlg
@@ -33,8 +33,6 @@ open Proofview.Notations
open Attributes
open Vernacextend
-let wit_hyp = wit_var
-
}
DECLARE PLUGIN "ltac_plugin"
@@ -450,7 +448,7 @@ END
(* Subst *)
TACTIC EXTEND subst
-| [ "subst" ne_var_list(l) ] -> { subst l }
+| [ "subst" ne_hyp_list(l) ] -> { subst l }
| [ "subst" ] -> { subst_all () }
END
diff --git a/plugins/ltac/g_auto.mlg b/plugins/ltac/g_auto.mlg
index 2e72ceae5a..44472a1995 100644
--- a/plugins/ltac/g_auto.mlg
+++ b/plugins/ltac/g_auto.mlg
@@ -18,8 +18,6 @@ open Pcoq.Constr
open Pltac
open Hints
-let wit_hyp = wit_var
-
}
DECLARE PLUGIN "ltac_plugin"
diff --git a/plugins/ltac/g_class.mlg b/plugins/ltac/g_class.mlg
index 8d197e6056..8c2e633be5 100644
--- a/plugins/ltac/g_class.mlg
+++ b/plugins/ltac/g_class.mlg
@@ -31,12 +31,12 @@ let set_transparency cl b =
}
VERNAC COMMAND EXTEND Typeclasses_Unfold_Settings CLASSIFIED AS SIDEFF
-| [ "Typeclasses" "Transparent" reference_list(cl) ] -> {
+| [ "Typeclasses" "Transparent" ne_reference_list(cl) ] -> {
set_transparency cl true }
END
VERNAC COMMAND EXTEND Typeclasses_Rigid_Settings CLASSIFIED AS SIDEFF
-| [ "Typeclasses" "Opaque" reference_list(cl) ] -> {
+| [ "Typeclasses" "Opaque" ne_reference_list(cl) ] -> {
set_transparency cl false }
END
@@ -77,7 +77,7 @@ END
(* true = All transparent, false = Opaque if possible *)
VERNAC COMMAND EXTEND Typeclasses_Settings CLASSIFIED AS SIDEFF
- | [ "Typeclasses" "eauto" ":=" debug(d) eauto_search_strategy(s) integer_opt(depth) ] -> {
+ | [ "Typeclasses" "eauto" ":=" debug(d) eauto_search_strategy(s) natural_opt(depth) ] -> {
set_typeclasses_debug d;
Option.iter set_typeclasses_strategy s;
set_typeclasses_depth depth
@@ -87,11 +87,13 @@ END
(** Compatibility: typeclasses eauto has 8.5 and 8.6 modes *)
TACTIC EXTEND typeclasses_eauto
| [ "typeclasses" "eauto" "bfs" int_or_var_opt(d) "with" ne_preident_list(l) ] ->
- { typeclasses_eauto ~strategy:Bfs ~depth:d l }
+ { typeclasses_eauto ~depth:d ~strategy:Bfs l }
| [ "typeclasses" "eauto" int_or_var_opt(d) "with" ne_preident_list(l) ] ->
{ typeclasses_eauto ~depth:d l }
+ | [ "typeclasses" "eauto" "bfs" int_or_var_opt(d) ] -> {
+ typeclasses_eauto ~depth:d ~strategy:Bfs ~only_classes:true [Class_tactics.typeclasses_db] }
| [ "typeclasses" "eauto" int_or_var_opt(d) ] -> {
- typeclasses_eauto ~only_classes:true ~depth:d [Class_tactics.typeclasses_db] }
+ typeclasses_eauto ~depth:d ~only_classes:true [Class_tactics.typeclasses_db] }
END
TACTIC EXTEND head_of_constr
diff --git a/plugins/ltac/g_ltac.mlg b/plugins/ltac/g_ltac.mlg
index be0d71ad46..c54f8ffa78 100644
--- a/plugins/ltac/g_ltac.mlg
+++ b/plugins/ltac/g_ltac.mlg
@@ -74,22 +74,22 @@ let hint = G_proofs.hint
}
GRAMMAR EXTEND Gram
- GLOBAL: tactic tacdef_body tactic_expr binder_tactic tactic_arg command hint
+ GLOBAL: tactic tacdef_body ltac_expr binder_tactic tactic_value command hint
tactic_mode constr_may_eval constr_eval toplevel_selector
- operconstr;
+ term;
tactic_then_last:
- [ [ "|"; lta = LIST0 (OPT tactic_expr) SEP "|" ->
+ [ [ "|"; lta = LIST0 (OPT ltac_expr) SEP "|" ->
{ Array.map (function None -> TacId [] | Some t -> t) (Array.of_list lta) }
| -> { [||] }
] ]
;
- tactic_then_gen:
- [ [ ta = tactic_expr; "|"; tg = tactic_then_gen -> { let (first,last) = tg in (ta::first, last) }
- | ta = tactic_expr; ".."; l = tactic_then_last -> { ([], Some (ta, l)) }
+ for_each_goal:
+ [ [ ta = ltac_expr; "|"; tg = for_each_goal -> { let (first,last) = tg in (ta::first, last) }
+ | ta = ltac_expr; ".."; l = tactic_then_last -> { ([], Some (ta, l)) }
| ".."; l = tactic_then_last -> { ([], Some (TacId [], l)) }
- | ta = tactic_expr -> { ([ta], None) }
- | "|"; tg = tactic_then_gen -> { let (first,last) = tg in (TacId [] :: first, last) }
+ | ta = ltac_expr -> { ([ta], None) }
+ | "|"; tg = for_each_goal -> { let (first,last) = tg in (TacId [] :: first, last) }
| -> { ([TacId []], None) }
] ]
;
@@ -97,13 +97,13 @@ GRAMMAR EXTEND Gram
for [TacExtend] *)
[ [ "[" ; l = OPT">" -> { if Option.is_empty l then true else false } ] ]
;
- tactic_expr:
+ ltac_expr:
[ "5" RIGHTA
[ te = binder_tactic -> { te } ]
| "4" LEFTA
- [ ta0 = tactic_expr; ";"; ta1 = binder_tactic -> { TacThen (ta0, ta1) }
- | ta0 = tactic_expr; ";"; ta1 = tactic_expr -> { TacThen (ta0,ta1) }
- | ta0 = tactic_expr; ";"; l = tactic_then_locality; tg = tactic_then_gen; "]" -> {
+ [ ta0 = ltac_expr; ";"; ta1 = binder_tactic -> { TacThen (ta0, ta1) }
+ | ta0 = ltac_expr; ";"; ta1 = ltac_expr -> { TacThen (ta0,ta1) }
+ | ta0 = ltac_expr; ";"; l = tactic_then_locality; tg = for_each_goal; "]" -> {
let (first,tail) = tg in
match l , tail with
| false , Some (t,last) -> TacThen (ta0,TacExtendTac (Array.of_list first, t, last))
@@ -111,51 +111,51 @@ GRAMMAR EXTEND Gram
| false , None -> TacThen (ta0,TacDispatch first)
| true , None -> TacThens (ta0,first) } ]
| "3" RIGHTA
- [ IDENT "try"; ta = tactic_expr -> { TacTry ta }
- | IDENT "do"; n = int_or_var; ta = tactic_expr -> { TacDo (n,ta) }
- | IDENT "timeout"; n = int_or_var; ta = tactic_expr -> { TacTimeout (n,ta) }
- | IDENT "time"; s = OPT string; ta = tactic_expr -> { TacTime (s,ta) }
- | IDENT "repeat"; ta = tactic_expr -> { TacRepeat ta }
- | IDENT "progress"; ta = tactic_expr -> { TacProgress ta }
- | IDENT "once"; ta = tactic_expr -> { TacOnce ta }
- | IDENT "exactly_once"; ta = tactic_expr -> { TacExactlyOnce ta }
- | IDENT "infoH"; ta = tactic_expr -> { TacShowHyps ta }
+ [ IDENT "try"; ta = ltac_expr -> { TacTry ta }
+ | IDENT "do"; n = int_or_var; ta = ltac_expr -> { TacDo (n,ta) }
+ | IDENT "timeout"; n = int_or_var; ta = ltac_expr -> { TacTimeout (n,ta) }
+ | IDENT "time"; s = OPT string; ta = ltac_expr -> { TacTime (s,ta) }
+ | IDENT "repeat"; ta = ltac_expr -> { TacRepeat ta }
+ | IDENT "progress"; ta = ltac_expr -> { TacProgress ta }
+ | IDENT "once"; ta = ltac_expr -> { TacOnce ta }
+ | IDENT "exactly_once"; ta = ltac_expr -> { TacExactlyOnce ta }
+ | IDENT "infoH"; ta = ltac_expr -> { TacShowHyps ta }
(*To do: put Abstract in Refiner*)
| IDENT "abstract"; tc = NEXT -> { TacAbstract (tc,None) }
| IDENT "abstract"; tc = NEXT; "using"; s = ident ->
{ TacAbstract (tc,Some s) }
- | sel = selector; ta = tactic_expr -> { TacSelect (sel, ta) } ]
+ | IDENT "only"; sel = selector; ":"; ta = ltac_expr -> { TacSelect (sel, ta) } ]
(*End of To do*)
| "2" RIGHTA
- [ ta0 = tactic_expr; "+"; ta1 = binder_tactic -> { TacOr (ta0,ta1) }
- | ta0 = tactic_expr; "+"; ta1 = tactic_expr -> { TacOr (ta0,ta1) }
- | IDENT "tryif" ; ta = tactic_expr ;
- "then" ; tat = tactic_expr ;
- "else" ; tae = tactic_expr -> { TacIfThenCatch(ta,tat,tae) }
- | ta0 = tactic_expr; "||"; ta1 = binder_tactic -> { TacOrelse (ta0,ta1) }
- | ta0 = tactic_expr; "||"; ta1 = tactic_expr -> { TacOrelse (ta0,ta1) } ]
+ [ ta0 = ltac_expr; "+"; ta1 = binder_tactic -> { TacOr (ta0,ta1) }
+ | ta0 = ltac_expr; "+"; ta1 = ltac_expr -> { TacOr (ta0,ta1) }
+ | IDENT "tryif" ; ta = ltac_expr ;
+ "then" ; tat = ltac_expr ;
+ "else" ; tae = ltac_expr -> { TacIfThenCatch(ta,tat,tae) }
+ | ta0 = ltac_expr; "||"; ta1 = binder_tactic -> { TacOrelse (ta0,ta1) }
+ | ta0 = ltac_expr; "||"; ta1 = ltac_expr -> { TacOrelse (ta0,ta1) } ]
| "1" RIGHTA
[ b = match_key; IDENT "goal"; "with"; mrl = match_context_list; "end" ->
{ TacMatchGoal (b,false,mrl) }
| b = match_key; IDENT "reverse"; IDENT "goal"; "with";
mrl = match_context_list; "end" ->
{ TacMatchGoal (b,true,mrl) }
- | b = match_key; c = tactic_expr; "with"; mrl = match_list; "end" ->
+ | b = match_key; c = ltac_expr; "with"; mrl = match_list; "end" ->
{ TacMatch (b,c,mrl) }
- | IDENT "first" ; "["; l = LIST0 tactic_expr SEP "|"; "]" ->
+ | IDENT "first" ; "["; l = LIST0 ltac_expr SEP "|"; "]" ->
{ TacFirst l }
- | IDENT "solve" ; "["; l = LIST0 tactic_expr SEP "|"; "]" ->
+ | IDENT "solve" ; "["; l = LIST0 ltac_expr SEP "|"; "]" ->
{ TacSolve l }
| IDENT "idtac"; l = LIST0 message_token -> { TacId l }
| g=failkw; n = [ n = int_or_var -> { n } | -> { fail_default_value } ];
l = LIST0 message_token -> { TacFail (g,n,l) }
| st = simple_tactic -> { st }
- | a = tactic_arg -> { TacArg(CAst.make ~loc a) }
- | r = reference; la = LIST0 tactic_arg_compat ->
+ | a = tactic_value -> { TacArg(CAst.make ~loc a) }
+ | r = reference; la = LIST0 tactic_arg ->
{ TacArg(CAst.make ~loc @@ TacCall (CAst.make ~loc (r,la))) } ]
| "0"
- [ "("; a = tactic_expr; ")" -> { a }
- | "["; ">"; tg = tactic_then_gen; "]" -> {
+ [ "("; a = ltac_expr; ")" -> { a }
+ | "["; ">"; tg = for_each_goal; "]" -> {
let (tf,tail) = tg in
begin match tail with
| Some (t,tl) -> TacExtendTac(Array.of_list tf,t,tl)
@@ -166,24 +166,24 @@ GRAMMAR EXTEND Gram
failkw:
[ [ IDENT "fail" -> { TacLocal } | IDENT "gfail" -> { TacGlobal } ] ]
;
- (* binder_tactic: level 5 of tactic_expr *)
+ (* binder_tactic: level 5 of ltac_expr *)
binder_tactic:
[ RIGHTA
- [ "fun"; it = LIST1 input_fun ; "=>"; body = tactic_expr LEVEL "5" ->
+ [ "fun"; it = LIST1 input_fun ; "=>"; body = ltac_expr LEVEL "5" ->
{ TacFun (it,body) }
| "let"; isrec = [IDENT "rec" -> { true } | -> { false } ];
llc = LIST1 let_clause SEP "with"; "in";
- body = tactic_expr LEVEL "5" -> { TacLetIn (isrec,llc,body) } ] ]
+ body = ltac_expr LEVEL "5" -> { TacLetIn (isrec,llc,body) } ] ]
;
(* Tactic arguments to the right of an application *)
- tactic_arg_compat:
- [ [ a = tactic_arg -> { a }
+ tactic_arg:
+ [ [ a = tactic_value -> { a }
| c = Constr.constr -> { (match c with { CAst.v = CRef (r,None) } -> Reference r | c -> ConstrMayEval (ConstrTerm c)) }
(* Unambiguous entries: tolerated w/o "ltac:" modifier *)
| "()" -> { TacGeneric (None, genarg_of_unit ()) } ] ]
;
(* Can be used as argument and at toplevel in tactic expressions. *)
- tactic_arg:
+ tactic_value:
[ [ c = constr_eval -> { ConstrMayEval c }
| IDENT "fresh"; l = LIST0 fresh_id -> { TacFreshId l }
| IDENT "type_term"; c=uconstr -> { TacPretype c }
@@ -223,20 +223,20 @@ GRAMMAR EXTEND Gram
| l = ident -> { Name.Name l } ] ]
;
let_clause:
- [ [ idr = identref; ":="; te = tactic_expr ->
+ [ [ idr = identref; ":="; te = ltac_expr ->
{ (CAst.map (fun id -> Name id) idr, arg_of_expr te) }
- | na = ["_" -> { CAst.make ~loc Anonymous } ]; ":="; te = tactic_expr ->
+ | na = ["_" -> { CAst.make ~loc Anonymous } ]; ":="; te = ltac_expr ->
{ (na, arg_of_expr te) }
- | idr = identref; args = LIST1 input_fun; ":="; te = tactic_expr ->
+ | idr = identref; args = LIST1 input_fun; ":="; te = ltac_expr ->
{ (CAst.map (fun id -> Name id) idr, arg_of_expr (TacFun(args,te))) } ] ]
;
match_pattern:
[ [ IDENT "context"; oid = OPT Constr.ident;
- "["; pc = Constr.lconstr_pattern; "]" ->
+ "["; pc = Constr.cpattern; "]" ->
{ Subterm (oid, pc) }
- | pc = Constr.lconstr_pattern -> { Term pc } ] ]
+ | pc = Constr.cpattern -> { Term pc } ] ]
;
- match_hyps:
+ match_hyp:
[ [ na = name; ":"; mp = match_pattern -> { Hyp (na, mp) }
| na = name; ":="; "["; mpv = match_pattern; "]"; ":"; mpt = match_pattern -> { Def (na, mpv, mpt) }
| na = name; ":="; mpv = match_pattern ->
@@ -250,19 +250,19 @@ GRAMMAR EXTEND Gram
] ]
;
match_context_rule:
- [ [ largs = LIST0 match_hyps SEP ","; "|-"; mp = match_pattern;
- "=>"; te = tactic_expr -> { Pat (largs, mp, te) }
- | "["; largs = LIST0 match_hyps SEP ","; "|-"; mp = match_pattern;
- "]"; "=>"; te = tactic_expr -> { Pat (largs, mp, te) }
- | "_"; "=>"; te = tactic_expr -> { All te } ] ]
+ [ [ largs = LIST0 match_hyp SEP ","; "|-"; mp = match_pattern;
+ "=>"; te = ltac_expr -> { Pat (largs, mp, te) }
+ | "["; largs = LIST0 match_hyp SEP ","; "|-"; mp = match_pattern;
+ "]"; "=>"; te = ltac_expr -> { Pat (largs, mp, te) }
+ | "_"; "=>"; te = ltac_expr -> { All te } ] ]
;
match_context_list:
[ [ mrl = LIST1 match_context_rule SEP "|" -> { mrl }
| "|"; mrl = LIST1 match_context_rule SEP "|" -> { mrl } ] ]
;
match_rule:
- [ [ mp = match_pattern; "=>"; te = tactic_expr -> { Pat ([],mp,te) }
- | "_"; "=>"; te = tactic_expr -> { All te } ] ]
+ [ [ mp = match_pattern; "=>"; te = ltac_expr -> { Pat ([],mp,te) }
+ | "_"; "=>"; te = ltac_expr -> { All te } ] ]
;
match_list:
[ [ mrl = LIST1 match_rule SEP "|" -> { mrl }
@@ -282,13 +282,13 @@ GRAMMAR EXTEND Gram
(* Definitions for tactics *)
tacdef_body:
[ [ name = Constr.global; it=LIST1 input_fun;
- redef = ltac_def_kind; body = tactic_expr ->
+ redef = ltac_def_kind; body = ltac_expr ->
{ if redef then Tacexpr.TacticRedefinition (name, TacFun (it, body))
else
let id = reference_to_id name in
Tacexpr.TacticDefinition (id, TacFun (it, body)) }
| name = Constr.global; redef = ltac_def_kind;
- body = tactic_expr ->
+ body = ltac_expr ->
{ if redef then Tacexpr.TacticRedefinition (name, body)
else
let id = reference_to_id name in
@@ -296,7 +296,7 @@ GRAMMAR EXTEND Gram
] ]
;
tactic:
- [ [ tac = tactic_expr -> { tac } ] ]
+ [ [ tac = ltac_expr -> { tac } ] ]
;
range_selector:
@@ -314,15 +314,12 @@ GRAMMAR EXTEND Gram
{ let open Goal_select in
Option.cata (fun l -> SelectList ((n, n) :: l)) (SelectNth n) l } ] ]
;
- selector_body:
+ selector:
[ [ l = range_selector_or_nth -> { l }
| test_bracket_ident; "["; id = ident; "]" -> { Goal_select.SelectId id } ] ]
;
- selector:
- [ [ IDENT "only"; sel = selector_body; ":" -> { sel } ] ]
- ;
toplevel_selector:
- [ [ sel = selector_body; ":" -> { sel }
+ [ [ sel = selector; ":" -> { sel }
| "!"; ":" -> { Goal_select.SelectAlreadyFocused }
| IDENT "all"; ":" -> { Goal_select.SelectAll } ] ]
;
@@ -343,8 +340,8 @@ GRAMMAR EXTEND Gram
tac = Pltac.tactic ->
{ Vernacexpr.HintsExtern (n,c, in_tac tac) } ] ]
;
- operconstr: LEVEL "0"
- [ [ IDENT "ltac"; ":"; "("; tac = Pltac.tactic_expr; ")" ->
+ term: LEVEL "0"
+ [ [ IDENT "ltac"; ":"; "("; tac = Pltac.ltac_expr; ")" ->
{ let arg = Genarg.in_gen (Genarg.rawwit Tacarg.wit_tactic) tac in
CAst.make ~loc @@ CHole (None, IntroAnonymous, Some arg) } ] ]
;
@@ -355,28 +352,8 @@ GRAMMAR EXTEND Gram
open Stdarg
open Tacarg
open Vernacextend
-open Goptions
open Libnames
-let print_info_trace =
- declare_intopt_option_and_ref ~depr:false ~key:["Info" ; "Level"]
-
-let vernac_solve ~pstate n info tcom b =
- let open Goal_select in
- let pstate, status = Declare.Proof.map_fold_endline ~f:(fun etac p ->
- let with_end_tac = if b then Some etac else None in
- let global = match n with SelectAll | SelectList _ -> true | _ -> false in
- let info = Option.append info (print_info_trace ()) in
- let (p,status) =
- Proof.solve n info (Tacinterp.hide_interp global tcom None) ?with_end_tac p
- in
- (* in case a strict subtree was completed,
- go back to the top of the prooftree *)
- let p = Proof.maximal_unfocus Vernacentries.command_focus p in
- p,status) pstate in
- if not status then Feedback.feedback Feedback.AddedAxiom;
- pstate
-
let pr_ltac_selector s = Pptactic.pr_goal_selector ~toplevel:true s
}
@@ -409,34 +386,34 @@ END
{
-let is_anonymous_abstract = function
- | TacAbstract (_,None) -> true
- | TacSolve [TacAbstract (_,None)] -> true
- | _ -> false
let rm_abstract = function
- | TacAbstract (t,_) -> t
- | TacSolve [TacAbstract (t,_)] -> TacSolve [t]
- | x -> x
+ | TacAbstract (t,_) -> t, true
+ | TacSolve [TacAbstract (t,_)] -> TacSolve [t], true
+ | x -> x, false
let is_explicit_terminator = function TacSolve _ -> true | _ -> false
}
VERNAC { tactic_mode } EXTEND VernacSolve STATE proof
-| [ ltac_selector_opt(g) ltac_info_opt(n) tactic(t) ltac_use_default(def) ] =>
+| [ ltac_selector_opt(g) ltac_info_opt(info) tactic(t) ltac_use_default(with_end_tac) ] =>
{ classify_as_proofstep } -> {
let g = Option.default (Goal_select.get_default_goal_selector ()) g in
- vernac_solve g n t def
+ let global = match g with Goal_select.SelectAll | Goal_select.SelectList _ -> true | _ -> false in
+ let t = Tacinterp.hide_interp { Tacinterp.global; ast = t; } in
+ ComTactic.solve g ~info t ~with_end_tac
}
-| [ "par" ":" ltac_info_opt(n) tactic(t) ltac_use_default(def) ] =>
+END
+
+VERNAC { tactic_mode } EXTEND VernacSolveParallel STATE proof
+| [ "par" ":" ltac_info_opt(info) tactic(t) ltac_use_default(with_end_tac) ] =>
{
- let anon_abstracting_tac = is_anonymous_abstract t in
let solving_tac = is_explicit_terminator t in
- let parallel = `Yes (solving_tac,anon_abstracting_tac) in
let pbr = if solving_tac then Some "par" else None in
- VtProofStep{ parallel = parallel; proof_block_detection = pbr }
+ VtProofStep{ proof_block_detection = pbr }
} -> {
- let t = rm_abstract t in
- vernac_solve Goal_select.SelectAll n t def
+ let t, abstract = rm_abstract t in
+ let t = Tacinterp.hide_interp { Tacinterp.global = true; ast = t; } in
+ ComTactic.solve_parallel ~info t ~abstract ~with_end_tac
}
END
@@ -489,7 +466,7 @@ END
VERNAC COMMAND EXTEND VernacPrintLtac CLASSIFIED AS QUERY
| [ "Print" "Ltac" reference(r) ] ->
- { Feedback.msg_notice (Tacintern.print_ltac r) }
+ { Feedback.msg_notice (Tacentries.print_ltac r) }
END
VERNAC COMMAND EXTEND VernacLocateLtac CLASSIFIED AS QUERY
diff --git a/plugins/ltac/g_obligations.mlg b/plugins/ltac/g_obligations.mlg
index fc24475a62..6bf330c830 100644
--- a/plugins/ltac/g_obligations.mlg
+++ b/plugins/ltac/g_obligations.mlg
@@ -111,6 +111,8 @@ END
VERNAC COMMAND EXTEND Solve_Obligations CLASSIFIED AS SIDEFF STATE program
| [ "Solve" "Obligations" "of" ident(name) "with" tactic(t) ] ->
{ try_solve_obligations (Some name) (Some (Tacinterp.interp t)) }
+| [ "Solve" "Obligations" "of" ident(name) ] ->
+ { try_solve_obligations (Some name) None }
| [ "Solve" "Obligations" "with" tactic(t) ] ->
{ try_solve_obligations None (Some (Tacinterp.interp t)) }
| [ "Solve" "Obligations" ] ->
diff --git a/plugins/ltac/g_rewrite.mlg b/plugins/ltac/g_rewrite.mlg
index 8331927cda..a3f03b5bb5 100644
--- a/plugins/ltac/g_rewrite.mlg
+++ b/plugins/ltac/g_rewrite.mlg
@@ -29,8 +29,6 @@ open Pvernac.Vernac_
open Pltac
open Vernacextend
-let wit_hyp = wit_var
-
}
DECLARE PLUGIN "ltac_plugin"
@@ -69,12 +67,12 @@ END
{
type raw_strategy = (constr_expr, Tacexpr.raw_red_expr) strategy_ast
-type glob_strategy = (glob_constr_and_expr, Tacexpr.raw_red_expr) strategy_ast
+type glob_strategy = (glob_constr_and_expr, Tacexpr.glob_red_expr) strategy_ast
let interp_strategy ist gl s =
let sigma = project gl in
- sigma, strategy_of_ast s
-let glob_strategy ist s = map_strategy (Tacintern.intern_constr ist) (fun c -> c) s
+ sigma, strategy_of_ast ist s
+let glob_strategy ist s = map_strategy (Tacintern.intern_constr ist) (Tacintern.intern_red_expr ist) s
let subst_strategy s str = str
let pr_strategy _ _ _ (s : strategy) = Pp.str "<strategy>"
@@ -82,12 +80,9 @@ let pr_raw_strategy env sigma prc prlc _ (s : raw_strategy) =
let prr = Pptactic.pr_red_expr env sigma (prc, prlc, Pputils.pr_or_by_notation Libnames.pr_qualid, prc) in
Rewrite.pr_strategy (prc env sigma) prr s
let pr_glob_strategy env sigma prc prlc _ (s : glob_strategy) =
- let prr = Pptactic.pr_red_expr env sigma
- (Ppconstr.pr_constr_expr,
- Ppconstr.pr_lconstr_expr,
- Pputils.pr_or_by_notation Libnames.pr_qualid,
- Ppconstr.pr_constr_expr)
- in
+ let prpat env sigma (_,c,_) = prc env sigma c in
+ let prcst = Pputils.pr_or_var Pptactic.(pr_and_short_name (pr_evaluable_reference_env env)) in
+ let prr = Pptactic.pr_red_expr env sigma (prc, prlc, prcst, prpat) in
Rewrite.pr_strategy (prc env sigma) prr s
}
@@ -132,15 +127,15 @@ END
{
let db_strat db = StratUnary (Topdown, StratHints (false, db))
-let cl_rewrite_clause_db db = cl_rewrite_clause_strat (strategy_of_ast (db_strat db))
+let cl_rewrite_clause_db ist db = cl_rewrite_clause_strat (strategy_of_ast ist (db_strat db))
}
TACTIC EXTEND rewrite_strat
| [ "rewrite_strat" rewstrategy(s) "in" hyp(id) ] -> { cl_rewrite_clause_strat s (Some id) }
| [ "rewrite_strat" rewstrategy(s) ] -> { cl_rewrite_clause_strat s None }
-| [ "rewrite_db" preident(db) "in" hyp(id) ] -> { cl_rewrite_clause_db db (Some id) }
-| [ "rewrite_db" preident(db) ] -> { cl_rewrite_clause_db db None }
+| [ "rewrite_db" preident(db) "in" hyp(id) ] -> { cl_rewrite_clause_db ist db (Some id) }
+| [ "rewrite_db" preident(db) ] -> { cl_rewrite_clause_db ist db None }
END
{
diff --git a/plugins/ltac/g_tactic.mlg b/plugins/ltac/g_tactic.mlg
index e51b1f051d..ecfe6c1664 100644
--- a/plugins/ltac/g_tactic.mlg
+++ b/plugins/ltac/g_tactic.mlg
@@ -121,8 +121,8 @@ let destruction_arg_of_constr (c,lbind as clbind) = match lbind with
end
| _ -> ElimOnConstr clbind
-let mkNumeral n =
- Numeral (NumTok.Signed.of_int_string (string_of_int n))
+let mkNumber n =
+ Number (NumTok.Signed.of_int_string (string_of_int n))
let mkTacCase with_evar = function
| [(clear,ElimOnConstr cl),(None,None),None],None ->
@@ -130,7 +130,7 @@ let mkTacCase with_evar = function
(* Reinterpret numbers as a notation for terms *)
| [(clear,ElimOnAnonHyp n),(None,None),None],None ->
TacCase (with_evar,
- (clear,(CAst.make @@ CPrim (mkNumeral n),
+ (clear,(CAst.make @@ CPrim (mkNumber n),
NoBindings)))
(* Reinterpret ident as notations for variables in the context *)
(* because we don't know if they are quantified or not *)
@@ -280,7 +280,7 @@ GRAMMAR EXTEND Gram
| "[="; tc = intropatterns; "]" -> { IntroInjection tc } ] ]
;
naming_intropattern:
- [ [ prefix = pattern_ident -> { IntroFresh prefix }
+ [ [ prefix = pattern_ident -> { IntroFresh prefix.CAst.v }
| "?" -> { IntroAnonymous }
| id = ident -> { IntroIdentifier id } ] ]
;
@@ -291,7 +291,7 @@ GRAMMAR EXTEND Gram
;
simple_intropattern:
[ [ pat = simple_intropattern_closed;
- l = LIST0 ["%"; c = operconstr LEVEL "0" -> { c } ] ->
+ l = LIST0 ["%"; c = term LEVEL "0" -> { c } ] ->
{ let {CAst.loc=loc0;v=pat} = pat in
let f c pat =
let loc1 = Constrexpr_ops.constr_loc c in
@@ -320,7 +320,7 @@ GRAMMAR EXTEND Gram
with_bindings:
[ [ "with"; bl = bindings -> { bl } | -> { NoBindings } ] ]
;
- red_flags:
+ red_flag:
[ [ IDENT "beta" -> { [FBeta] }
| IDENT "iota" -> { [FMatch;FFix;FCofix] }
| IDENT "match" -> { [FMatch] }
@@ -337,7 +337,7 @@ GRAMMAR EXTEND Gram
] ]
;
strategy_flag:
- [ [ s = LIST1 red_flags -> { Redops.make_red_flag (List.flatten s) }
+ [ [ s = LIST1 red_flag -> { Redops.make_red_flag (List.flatten s) }
| d = delta_flag -> { all_with d }
] ]
;
@@ -460,7 +460,7 @@ GRAMMAR EXTEND Gram
[ [ "as"; id = ident -> { Names.Name.Name id } | -> { Names.Name.Anonymous } ] ]
;
by_tactic:
- [ [ "by"; tac = tactic_expr LEVEL "3" -> { Some tac }
+ [ [ "by"; tac = ltac_expr LEVEL "3" -> { Some tac }
| -> { None } ] ]
;
rewriter :
diff --git a/plugins/ltac/pltac.ml b/plugins/ltac/pltac.ml
index b7b54143df..94e398fe5d 100644
--- a/plugins/ltac/pltac.ml
+++ b/plugins/ltac/pltac.ml
@@ -37,8 +37,10 @@ let clause_dft_concl =
(* Main entries for ltac *)
-let tactic_arg = Entry.create "tactic_arg"
-let tactic_expr = Entry.create "tactic_expr"
+let tactic_value = Entry.create "tactic_value"
+let tactic_arg = tactic_value
+let ltac_expr = Entry.create "ltac_expr"
+let tactic_expr = ltac_expr
let binder_tactic = Entry.create "binder_tactic"
let tactic = Entry.create "tactic"
diff --git a/plugins/ltac/pltac.mli b/plugins/ltac/pltac.mli
index 8565c4b4d6..3a4a081c93 100644
--- a/plugins/ltac/pltac.mli
+++ b/plugins/ltac/pltac.mli
@@ -31,8 +31,12 @@ val simple_tactic : raw_tactic_expr Entry.t
val simple_intropattern : constr_expr intro_pattern_expr CAst.t Entry.t
val in_clause : Names.lident Locus.clause_expr Entry.t
val clause_dft_concl : Names.lident Locus.clause_expr Entry.t
+val tactic_value : raw_tactic_arg Entry.t
val tactic_arg : raw_tactic_arg Entry.t
+ [@@deprecated "Deprecated in 8.13; use 'tactic_value' instead"]
+val ltac_expr : raw_tactic_expr Entry.t
val tactic_expr : raw_tactic_expr Entry.t
+ [@@deprecated "Deprecated in 8.13; use 'ltac_expr' instead"]
val binder_tactic : raw_tactic_expr Entry.t
val tactic : raw_tactic_expr Entry.t
val tactic_eoi : raw_tactic_expr Entry.t
diff --git a/plugins/ltac/pptactic.ml b/plugins/ltac/pptactic.ml
index 85bb901046..edd56ee0f7 100644
--- a/plugins/ltac/pptactic.ml
+++ b/plugins/ltac/pptactic.ml
@@ -179,7 +179,7 @@ let string_of_genarg_arg (ArgumentType arg) =
| ConstrTypeOf c ->
hov 1 (keyword "type of" ++ spc() ++ prc env sigma c)
| ConstrTerm c when test c ->
- h 0 (str "(" ++ prc env sigma c ++ str ")")
+ h (str "(" ++ prc env sigma c ++ str ")")
| ConstrTerm c ->
prc env sigma c
@@ -1135,8 +1135,8 @@ let pr_goal_selector ~toplevel s =
pr_dconstr = (fun env sigma -> pr_and_constr_expr (pr_glob_constr_env env));
pr_lconstr = (fun env sigma -> pr_and_constr_expr (pr_lglob_constr_env env));
pr_pattern = (fun env sigma -> pr_pat_and_constr_expr (pr_glob_constr_env env));
- pr_lpattern = (fun env sigma -> pr_pat_and_constr_expr (pr_lglob_constr_env env));
pr_constant = pr_or_var (pr_and_short_name (pr_evaluable_reference_env env));
+ pr_lpattern = (fun env sigma -> pr_pat_and_constr_expr (pr_lglob_constr_env env));
pr_reference = pr_ltac_or_var (pr_located pr_ltac_constant);
pr_name = pr_lident;
pr_generic = Pputils.pr_glb_generic;
@@ -1323,7 +1323,7 @@ let () =
register_basic_print0 wit_smart_global
(pr_or_by_notation pr_qualid) (pr_or_var (pr_located pr_global)) pr_global;
register_basic_print0 wit_ident pr_id pr_id pr_id;
- register_basic_print0 wit_var pr_lident pr_lident pr_id;
+ register_basic_print0 wit_hyp pr_lident pr_lident pr_id;
register_print0 wit_intropattern pr_raw_intro_pattern pr_glob_intro_pattern pr_intro_pattern_env [@warning "-3"];
register_print0 wit_simple_intropattern pr_raw_intro_pattern pr_glob_intro_pattern pr_intro_pattern_env;
Genprint.register_print0
@@ -1334,8 +1334,8 @@ let () =
;
Genprint.register_print0
wit_constr
- (lift_env Ppconstr.pr_lconstr_expr)
- (lift_env (fun env sigma (c, _) -> pr_lglob_constr_pptac env sigma c))
+ (lift_env Ppconstr.pr_constr_expr)
+ (lift_env (fun env sigma (c, _) -> pr_glob_constr_pptac env sigma c))
(make_constr_printer Printer.pr_econstr_n_env)
;
Genprint.register_print0
diff --git a/plugins/ltac/pptactic.mli b/plugins/ltac/pptactic.mli
index 6a9fb5c2ea..5e199dad62 100644
--- a/plugins/ltac/pptactic.mli
+++ b/plugins/ltac/pptactic.mli
@@ -8,7 +8,7 @@
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)
-(** This module implements pretty-printers for tactic_expr syntactic
+(** This module implements pretty-printers for ltac_expr syntactic
objects and their subcomponents. *)
open Genarg
diff --git a/plugins/ltac/profile_ltac.ml b/plugins/ltac/profile_ltac.ml
index 0dbf16a821..9c15d24dd3 100644
--- a/plugins/ltac/profile_ltac.ml
+++ b/plugins/ltac/profile_ltac.ml
@@ -146,7 +146,7 @@ let header =
fnl ()
let rec print_node ~filter all_total indent prefix (s, e) =
- h 0 (
+ h (
padr_with '-' 40 (prefix ^ s ^ " ")
++ padl 7 (format_ratio (e.local /. all_total))
++ padl 7 (format_ratio (e.total /. all_total))
@@ -212,7 +212,7 @@ let to_string ~filter ?(cutoff=0.0) node =
in
let filter s n = filter s && (all_total <= 0.0 || n /. all_total >= cutoff /. 100.0) in
let msg =
- h 0 (str "total time: " ++ padl 11 (format_sec (all_total))) ++
+ h (str "total time: " ++ padl 11 (format_sec (all_total))) ++
fnl () ++
fnl () ++
header ++
diff --git a/plugins/ltac/rewrite.ml b/plugins/ltac/rewrite.ml
index 5ef76dbdc1..26e2b18a02 100644
--- a/plugins/ltac/rewrite.ml
+++ b/plugins/ltac/rewrite.ml
@@ -769,7 +769,7 @@ let get_rew_prf evars r = match r.rew_prf with
let poly_subrelation sort =
if sort then PropGlobal.subrelation else TypeGlobal.subrelation
-let resolve_subrelation env avoid car rel sort prf rel' res =
+let resolve_subrelation env car rel sort prf rel' res =
if Termops.eq_constr (fst res.rew_evars) rel rel' then res
else
let evars, app = app_poly_check env res.rew_evars (poly_subrelation sort) [|car; rel; rel'|] in
@@ -779,7 +779,7 @@ let resolve_subrelation env avoid car rel sort prf rel' res =
rew_prf = RewPrf (rel', appsub);
rew_evars = evars }
-let resolve_morphism env avoid oldt m ?(fnewt=fun x -> x) args args' (b,cstr) evars =
+let resolve_morphism env m args args' (b,cstr) evars =
let evars, morph_instance, proj, sigargs, m', args, args' =
let first = match (Array.findi (fun _ b -> not (Option.is_empty b)) args') with
| Some i -> i
@@ -843,18 +843,18 @@ let resolve_morphism env avoid oldt m ?(fnewt=fun x -> x) args args' (b,cstr) ev
let proof = applist (proj, List.rev projargs) in
let newt = applist (m', List.rev typeargs) in
match respars with
- [ a, Some r ] -> evars, proof, substl subst a, substl subst r, oldt, fnewt newt
+ [ a, Some r ] -> evars, proof, substl subst a, substl subst r, newt
| _ -> assert(false)
-let apply_constraint env avoid car rel prf cstr res =
+let apply_constraint env car rel prf cstr res =
match snd cstr with
| None -> res
- | Some r -> resolve_subrelation env avoid car rel (fst cstr) prf r res
+ | Some r -> resolve_subrelation env car rel (fst cstr) prf r res
-let coerce env avoid cstr res =
+let coerce env cstr res =
let evars, (rel, prf) = get_rew_prf res.rew_evars res in
let res = { res with rew_evars = evars } in
- apply_constraint env avoid res.rew_car rel prf cstr res
+ apply_constraint env res.rew_car rel prf cstr res
let apply_rule unify loccs : int pure_strategy =
let (nowhere_except_in,occs) = convert_occs loccs in
@@ -863,7 +863,7 @@ let apply_rule unify loccs : int pure_strategy =
then List.mem occ occs
else not (List.mem occ occs)
in
- { strategy = fun { state = occ ; env ; unfresh ;
+ { strategy = fun { state = occ ; env ;
term1 = t ; ty1 = ty ; cstr ; evars } ->
let unif = if isEvar (goalevars evars) t then None else unify env evars t in
match unif with
@@ -874,7 +874,7 @@ let apply_rule unify loccs : int pure_strategy =
else if Termops.eq_constr (fst rew.rew_evars) t rew.rew_to then (occ, Identity)
else
let res = { rew with rew_car = ty } in
- let res = Success (coerce env unfresh cstr res) in
+ let res = Success (coerce env cstr res) in
(occ, res)
}
@@ -968,7 +968,7 @@ let fold_match ?(force=false) env sigma c =
let unfold_match env sigma sk app =
match EConstr.kind sigma app with
- | App (f', args) when Constant.equal (fst (destConst sigma f')) sk ->
+ | App (f', args) when QConstant.equal env (fst (destConst sigma f')) sk ->
let v = Environ.constant_value_in (Global.env ()) (sk,Univ.Instance.empty)(*FIXME*) in
let v = EConstr.of_constr v in
Reductionops.whd_beta env sigma (mkApp (v, args))
@@ -1017,10 +1017,10 @@ let subterm all flags (s : 'a pure_strategy) : 'a pure_strategy =
| None -> false
| Some r -> not (is_rew_cast r.rew_prf)) args'
then
- let evars', prf, car, rel, c1, c2 =
- resolve_morphism env unfresh t m args args' (prop, cstr') evars'
+ let evars', prf, car, rel, c2 =
+ resolve_morphism env m args args' (prop, cstr') evars'
in
- let res = { rew_car = ty; rew_from = c1;
+ let res = { rew_car = ty; rew_from = t;
rew_to = c2; rew_prf = RewPrf (rel, prf);
rew_evars = evars' }
in Success res
@@ -1071,7 +1071,7 @@ let subterm all flags (s : 'a pure_strategy) : 'a pure_strategy =
let res =
match prf with
| RewPrf (rel, prf) ->
- Success (apply_constraint env unfresh res.rew_car
+ Success (apply_constraint env res.rew_car
rel prf (prop,cstr) res)
| _ -> Success res
in state, res
@@ -1094,20 +1094,6 @@ let subterm all flags (s : 'a pure_strategy) : 'a pure_strategy =
| Fail | Identity -> res
in state, res
- (* if x' = None && flags.under_lambdas then *)
- (* let lam = mkLambda (n, x, b) in *)
- (* let lam', occ = aux env lam occ None in *)
- (* let res = *)
- (* match lam' with *)
- (* | None -> None *)
- (* | Some (prf, (car, rel, c1, c2)) -> *)
- (* Some (resolve_morphism env sigma t *)
- (* ~fnewt:unfold_all *)
- (* (Lazy.force coq_all) [| x ; lam |] [| None; lam' |] *)
- (* cstr evars) *)
- (* in res, occ *)
- (* else *)
-
| Prod (n, dom, codom) ->
let lam = mkLambda (n, dom, codom) in
let (evars', app), unfold =
@@ -1131,31 +1117,13 @@ let subterm all flags (s : 'a pure_strategy) : 'a pure_strategy =
B. Barras' idea is to have a context of relations, of length 1, with Σ for gluing
dependent relations and using projections to get them out.
*)
- (* | Lambda (n, t, b) when flags.under_lambdas -> *)
- (* let n' = name_app (fun id -> Tactics.fresh_id_in_env avoid id env) n in *)
- (* let n'' = name_app (fun id -> Tactics.fresh_id_in_env avoid id env) n' in *)
- (* let n''' = name_app (fun id -> Tactics.fresh_id_in_env avoid id env) n'' in *)
- (* let rel = new_cstr_evar cstr env (mkApp (Lazy.force coq_relation, [|t|])) in *)
- (* let env' = Environ.push_rel_context [(n'',None,lift 2 rel);(n'',None,lift 1 t);(n', None, t)] env in *)
- (* let b' = s env' avoid b (Typing.type_of env' (goalevars evars) (lift 2 b)) (unlift_cstr env (goalevars evars) cstr) evars in *)
- (* (match b' with *)
- (* | Some (Some r) -> *)
- (* let prf = match r.rew_prf with *)
- (* | RewPrf (rel, prf) -> *)
- (* let rel = pointwise_or_dep_relation n' t r.rew_car rel in *)
- (* let prf = mkLambda (n', t, prf) in *)
- (* RewPrf (rel, prf) *)
- (* | x -> x *)
- (* in *)
- (* Some (Some { r with *)
- (* rew_prf = prf; *)
- (* rew_car = mkProd (n, t, r.rew_car); *)
- (* rew_from = mkLambda(n, t, r.rew_from); *)
- (* rew_to = mkLambda (n, t, r.rew_to) }) *)
- (* | _ -> b') *)
| Lambda (n, t, b) when flags.under_lambdas ->
let n' = map_annot (Nameops.Name.map (fun id -> Tactics.fresh_id_in_env unfresh id env)) n in
+ let unfresh = match n'.binder_name with
+ | Anonymous -> unfresh
+ | Name id -> Id.Set.add id unfresh
+ in
let open Context.Rel.Declaration in
let env' = EConstr.push_rel (LocalAssum (n', t)) env in
let bty = Retyping.get_type_of env' (goalevars evars) b in
@@ -1196,7 +1164,7 @@ let subterm all flags (s : 'a pure_strategy) : 'a pure_strategy =
| Success r ->
let case = mkCase (ci, lift 1 p, map_invert (lift 1) iv, mkRel 1, Array.map (lift 1) brs) in
let res = make_leibniz_proof env case ty r in
- state, Success (coerce env unfresh (prop,cstr) res)
+ state, Success (coerce env (prop,cstr) res)
| Fail | Identity ->
if Array.for_all (Int.equal 0) ci.ci_cstr_ndecls then
let evars', eqty = app_poly_sort prop env evars coq_eq [| ty |] in
@@ -1237,7 +1205,7 @@ let subterm all flags (s : 'a pure_strategy) : 'a pure_strategy =
in
let res =
match res with
- | Success r -> Success (coerce env unfresh (prop,cstr) r)
+ | Success r -> Success (coerce env (prop,cstr) r)
| Fail | Identity -> res
in state, res
| _ -> state, Fail
@@ -1670,9 +1638,9 @@ let cl_rewrite_clause l left2right occs clause =
let cl_rewrite_clause_strat strat clause =
cl_rewrite_clause_strat false strat clause
-let apply_glob_constr c l2r occs = (); fun ({ state = () ; env = env } as input) ->
+let apply_glob_constr ist c l2r occs = (); fun ({ state = () ; env = env } as input) ->
let c sigma =
- let (sigma, c) = Pretyping.understand_tcc env sigma c in
+ let (sigma, c) = Tacinterp.interp_open_constr ist env sigma c in
(sigma, (c, NoBindings))
in
let flags = general_rewrite_unif_flags () in
@@ -1749,12 +1717,12 @@ let rec pr_strategy prc prr = function
| StratEval r -> str "eval" ++ spc () ++ prr r
| StratFold c -> str "fold" ++ spc () ++ prc c
-let rec strategy_of_ast = function
+let rec strategy_of_ast ist = function
| StratId -> Strategies.id
| StratFail -> Strategies.fail
| StratRefl -> Strategies.refl
| StratUnary (f, s) ->
- let s' = strategy_of_ast s in
+ let s' = strategy_of_ast ist s in
let f' = match f with
| Subterms -> all_subterms
| Subterm -> one_subterm
@@ -1768,13 +1736,13 @@ let rec strategy_of_ast = function
| Repeat -> Strategies.repeat
in f' s'
| StratBinary (f, s, t) ->
- let s' = strategy_of_ast s in
- let t' = strategy_of_ast t in
+ let s' = strategy_of_ast ist s in
+ let t' = strategy_of_ast ist t in
let f' = match f with
| Compose -> Strategies.seq
| Choice -> Strategies.choice
in f' s' t'
- | StratConstr (c, b) -> { strategy = apply_glob_constr (fst c) b AllOccurrences }
+ | StratConstr (c, b) -> { strategy = apply_glob_constr ist c b AllOccurrences }
| StratHints (old, id) -> if old then Strategies.old_hints id else Strategies.hints id
| StratTerms l -> { strategy =
(fun ({ state = () ; env } as input) ->
@@ -1783,7 +1751,7 @@ let rec strategy_of_ast = function
}
| StratEval r -> { strategy =
(fun ({ state = () ; env ; evars } as input) ->
- let (sigma,r_interp) = Tacinterp.interp_redexp env (goalevars evars) r in
+ let (sigma,r_interp) = Tacinterp.interp_red_expr ist env (goalevars evars) r in
(Strategies.reduce r_interp).strategy { input with
evars = (sigma,cstrevars evars) }) }
| StratFold c -> Strategies.fold_glob (fst c)
diff --git a/plugins/ltac/rewrite.mli b/plugins/ltac/rewrite.mli
index 60a66dd861..8e0ce183c2 100644
--- a/plugins/ltac/rewrite.mli
+++ b/plugins/ltac/rewrite.mli
@@ -62,7 +62,7 @@ type rewrite_result =
type strategy
-val strategy_of_ast : (glob_constr_and_expr, raw_red_expr) strategy_ast -> strategy
+val strategy_of_ast : interp_sign -> (glob_constr_and_expr, glob_red_expr) strategy_ast -> strategy
val map_strategy : ('a -> 'b) -> ('c -> 'd) ->
('a, 'c) strategy_ast -> ('b, 'd) strategy_ast
diff --git a/plugins/ltac/taccoerce.ml b/plugins/ltac/taccoerce.ml
index f7037176d2..4c1fe6417e 100644
--- a/plugins/ltac/taccoerce.ml
+++ b/plugins/ltac/taccoerce.ml
@@ -161,8 +161,8 @@ let coerce_var_to_ident fresh env sigma v =
match out_gen (topwit wit_intro_pattern) v with
| { CAst.v=IntroNaming (IntroIdentifier id)} -> id
| _ -> fail ()
- else if has_type v (topwit wit_var) then
- out_gen (topwit wit_var) v
+ else if has_type v (topwit wit_hyp) then
+ out_gen (topwit wit_hyp) v
else match Value.to_constr v with
| None -> fail ()
| Some c ->
@@ -184,8 +184,8 @@ let id_of_name = function
| Some (IntroNaming (IntroIdentifier id)) -> id
| Some _ -> fail ()
| None ->
- if has_type v (topwit wit_var) then
- out_gen (topwit wit_var) v
+ if has_type v (topwit wit_hyp) then
+ out_gen (topwit wit_hyp) v
else
match Value.to_constr v with
| None -> fail ()
@@ -222,8 +222,8 @@ let coerce_to_intro_pattern sigma v =
match is_intro_pattern v with
| Some pat -> pat
| None ->
- if has_type v (topwit wit_var) then
- let id = out_gen (topwit wit_var) v in
+ if has_type v (topwit wit_hyp) then
+ let id = out_gen (topwit wit_hyp) v in
IntroNaming (IntroIdentifier id)
else match Value.to_constr v with
| Some c when isVar sigma c ->
@@ -259,8 +259,8 @@ let coerce_to_constr env v =
([], c)
else if has_type v (topwit wit_constr_under_binders) then
out_gen (topwit wit_constr_under_binders) v
- else if has_type v (topwit wit_var) then
- let id = out_gen (topwit wit_var) v in
+ else if has_type v (topwit wit_hyp) then
+ let id = out_gen (topwit wit_hyp) v in
(try [], constr_of_id env id with Not_found -> fail ())
else fail ()
@@ -282,8 +282,8 @@ let coerce_to_evaluable_ref env sigma v =
| Some (IntroNaming (IntroIdentifier id)) when is_variable env id -> EvalVarRef id
| Some _ -> fail ()
| None ->
- if has_type v (topwit wit_var) then
- let id = out_gen (topwit wit_var) v in
+ if has_type v (topwit wit_hyp) then
+ let id = out_gen (topwit wit_hyp) v in
if Id.List.mem id (Termops.ids_of_context env) then EvalVarRef id
else fail ()
else if has_type v (topwit wit_ref) then
@@ -328,8 +328,8 @@ let coerce_to_hyp env sigma v =
| Some (IntroNaming (IntroIdentifier id)) when is_variable env id -> id
| Some _ -> fail ()
| None ->
- if has_type v (topwit wit_var) then
- let id = out_gen (topwit wit_var) v in
+ if has_type v (topwit wit_hyp) then
+ let id = out_gen (topwit wit_hyp) v in
if is_variable env id then id else fail ()
else match Value.to_constr v with
| Some c when isVar sigma c -> destVar sigma c
@@ -360,8 +360,8 @@ let coerce_to_quantified_hypothesis sigma v =
| Some (IntroNaming (IntroIdentifier id)) -> NamedHyp id
| Some _ -> raise (CannotCoerceTo "a quantified hypothesis")
| None ->
- if has_type v (topwit wit_var) then
- let id = out_gen (topwit wit_var) v in
+ if has_type v (topwit wit_hyp) then
+ let id = out_gen (topwit wit_hyp) v in
NamedHyp id
else if has_type v (topwit wit_int) then
AnonHyp (out_gen (topwit wit_int) v)
@@ -394,8 +394,13 @@ type appl =
(* Values for interpretation *)
type tacvalue =
- | VFun of appl * Tacexpr.ltac_trace * Loc.t option * Val.t Id.Map.t *
- Name.t list * Tacexpr.glob_tactic_expr
+ | VFun of
+ appl *
+ Tacexpr.ltac_trace *
+ Loc.t option * (* when executing a global Ltac function: the location where this function was called *)
+ Val.t Id.Map.t * (* closure *)
+ Name.t list * (* binders *)
+ Tacexpr.glob_tactic_expr (* body *)
| VRec of Val.t Id.Map.t ref * Tacexpr.glob_tactic_expr
let (wit_tacvalue : (Empty.t, tacvalue, tacvalue) Genarg.genarg_type) =
diff --git a/plugins/ltac/tacentries.ml b/plugins/ltac/tacentries.ml
index f0ca813b08..29e29044f1 100644
--- a/plugins/ltac/tacentries.ml
+++ b/plugins/ltac/tacentries.ml
@@ -31,21 +31,9 @@ type argument = Genarg.ArgT.any Extend.user_symbol
(**********************************************************************)
(* Interpret entry names of the form "ne_constr_list" as entry keys *)
-let coincide s pat off =
- let len = String.length pat in
- let break = ref true in
- let i = ref 0 in
- while !break && !i < len do
- let c = Char.code s.[off + !i] in
- let d = Char.code pat.[!i] in
- break := Int.equal c d;
- incr i
- done;
- !break
-
let atactic n =
if n = 5 then Pcoq.Symbol.nterm Pltac.binder_tactic
- else Pcoq.Symbol.nterml Pltac.tactic_expr (string_of_int n)
+ else Pcoq.Symbol.nterml Pltac.ltac_expr (string_of_int n)
type entry_name = EntryName :
'a raw_abstract_argument_type * (Tacexpr.raw_tactic_expr, _, 'a) Pcoq.Symbol.t -> entry_name
@@ -70,28 +58,37 @@ let check_separator ?loc = function
| Some _ -> user_err ?loc (str "Separator is only for arguments with suffix _list_sep.")
let rec parse_user_entry ?loc s sep =
- let l = String.length s in
- if l > 8 && coincide s "ne_" 0 && coincide s "_list" (l - 5) then
- let entry = parse_user_entry ?loc (String.sub s 3 (l-8)) None in
+ let open CString in
+ let matches pre suf s =
+ String.length s > (String.length pre + String.length suf) &&
+ is_prefix pre s && is_suffix suf s
+ in
+ let basename pre suf s =
+ let plen = String.length pre in
+ String.sub s plen (String.length s - (plen + String.length suf))
+ in
+ let tactic_len = String.length "tactic" in
+ if matches "ne_" "_list" s then
+ let entry = parse_user_entry ?loc (basename "ne_" "_list" s) None in
check_separator ?loc sep;
Ulist1 entry
- else if l > 12 && coincide s "ne_" 0 &&
- coincide s "_list_sep" (l-9) then
- let entry = parse_user_entry ?loc (String.sub s 3 (l-12)) None in
+ else if matches "ne_" "_list_sep" s then
+ let entry = parse_user_entry ?loc (basename "ne_" "_list_sep" s) None in
Ulist1sep (entry, get_separator sep)
- else if l > 5 && coincide s "_list" (l-5) then
- let entry = parse_user_entry ?loc (String.sub s 0 (l-5)) None in
+ else if matches "" "_list" s then
+ let entry = parse_user_entry ?loc (basename "" "_list" s) None in
check_separator ?loc sep;
Ulist0 entry
- else if l > 9 && coincide s "_list_sep" (l-9) then
- let entry = parse_user_entry ?loc (String.sub s 0 (l-9)) None in
+ else if matches "" "_list_sep" s then
+ let entry = parse_user_entry ?loc (basename "" "_list_sep" s) None in
Ulist0sep (entry, get_separator sep)
- else if l > 4 && coincide s "_opt" (l-4) then
- let entry = parse_user_entry ?loc (String.sub s 0 (l-4)) None in
+ else if matches "" "_opt" s then
+ let entry = parse_user_entry ?loc (basename "" "_opt" s) None in
check_separator ?loc sep;
Uopt entry
- else if Int.equal l 7 && coincide s "tactic" 0 && '5' >= s.[6] && s.[6] >= '0' then
- let n = Char.code s.[6] - 48 in
+ else if String.length s = tactic_len + 1 && is_prefix "tactic" s
+ && '5' >= s.[tactic_len] && s.[tactic_len] >= '0' then
+ let n = Char.code s.[tactic_len] - Char.code '0' in
check_separator ?loc sep;
Uentryl ("tactic", n)
else
@@ -119,7 +116,7 @@ let get_tactic_entry n =
else if Int.equal n 5 then
Pltac.binder_tactic, None
else if 1<=n && n<5 then
- Pltac.tactic_expr, Some (Gramlib.Gramext.Level (string_of_int n))
+ Pltac.ltac_expr, Some (Gramlib.Gramext.Level (string_of_int n))
else
user_err Pp.(str ("Invalid Tactic Notation level: "^(string_of_int n)^"."))
@@ -159,7 +156,7 @@ let rec prod_item_of_symbol lev = function
EntryName (Rawwit wit, Pcoq.Symbol.nterm (genarg_grammar wit))
| Extend.Uentryl (s, n) ->
let ArgT.Any tag = s in
- assert (coincide (ArgT.repr tag) "tactic" 0);
+ assert (CString.is_suffix "tactic" (ArgT.repr tag));
get_tacentry n lev
(** Tactic grammar extensions *)
@@ -219,7 +216,9 @@ let interp_prod_item = function
| None ->
if String.Map.mem s !entry_names then String.Map.find s !entry_names
else begin match ArgT.name s with
- | None -> user_err Pp.(str ("Unknown entry "^s^"."))
+ | None ->
+ if s = "var" then user_err Pp.(str ("var is deprecated, use hyp.")) (* to remove in 8.14 *)
+ else user_err Pp.(str ("Unknown entry "^s^"."))
| Some arg -> arg
end
| Some n ->
@@ -384,7 +383,7 @@ let add_ml_tactic_notation name ~level ?deprecation prods =
in
List.iteri iter (List.rev prods);
(* We call [extend_atomic_tactic] only for "basic tactics" (the ones
- at tactic_expr level 0) *)
+ at ltac_expr level 0) *)
if Int.equal level 0 then extend_atomic_tactic name prods
(**********************************************************************)
@@ -421,7 +420,7 @@ let create_ltac_quotation name cast (e, l) =
in
let action _ v _ _ _ loc = cast (Some loc, v) in
let gram = (level, assoc, [Pcoq.Production.make rule action]) in
- Pcoq.grammar_extend Pltac.tactic_arg {pos=None; data=[gram]}
+ Pcoq.grammar_extend Pltac.tactic_value {pos=None; data=[gram]}
(** Command *)
@@ -529,16 +528,40 @@ let print_ltacs () =
let locatable_ltac = "Ltac"
+let split_ltac_fun = function
+ | Tacexpr.TacFun (l,t) -> (l,t)
+ | t -> ([],t)
+
+let pr_ltac_fun_arg n = spc () ++ Name.print n
+
+let print_ltac_body qid tac =
+ let filter mp =
+ try Some (Nametab.shortest_qualid_of_module mp)
+ with Not_found -> None
+ in
+ let mods = List.map_filter filter tac.Tacenv.tac_redef in
+ let redefined = match mods with
+ | [] -> mt ()
+ | mods ->
+ let redef = prlist_with_sep fnl pr_qualid mods in
+ fnl () ++ str "Redefined by:" ++ fnl () ++ redef
+ in
+ let l,t = split_ltac_fun tac.Tacenv.tac_body in
+ hv 2 (
+ hov 2 (str "Ltac" ++ spc() ++ pr_qualid qid ++
+ prlist pr_ltac_fun_arg l ++ spc () ++ str ":=")
+ ++ spc() ++ Pptactic.pr_glob_tactic (Global.env ()) t) ++ redefined
+
let () =
let open Prettyp in
- let locate qid = try Some (Tacenv.locate_tactic qid) with Not_found -> None in
- let locate_all = Tacenv.locate_extended_all_tactic in
- let shortest_qualid = Tacenv.shortest_qualid_of_tactic in
- let name kn = str "Ltac" ++ spc () ++ pr_path (Tacenv.path_of_tactic kn) in
- let print kn =
- let qid = qualid_of_path (Tacenv.path_of_tactic kn) in
- Tacintern.print_ltac qid
- in
+ let locate qid = try Some (qid, Tacenv.locate_tactic qid) with Not_found -> None in
+ let locate_all qid = List.map (fun kn -> (qid,kn)) (Tacenv.locate_extended_all_tactic qid) in
+ let shortest_qualid (qid,kn) = Tacenv.shortest_qualid_of_tactic kn in
+ let name (qid,kn) = str "Ltac" ++ spc () ++ pr_path (Tacenv.path_of_tactic kn) in
+ let print (qid,kn) =
+ let entries = Tacenv.ltac_entries () in
+ let tac = KNmap.find kn entries in
+ print_ltac_body qid tac in
let about = name in
register_locatable locatable_ltac {
locate;
@@ -552,14 +575,25 @@ let () =
let print_located_tactic qid =
Feedback.msg_notice (Prettyp.print_located_other locatable_ltac qid)
+let print_ltac id =
+ try
+ let kn = Tacenv.locate_tactic id in
+ let entries = Tacenv.ltac_entries () in
+ let tac = KNmap.find kn entries in
+ print_ltac_body id tac
+ with
+ Not_found ->
+ user_err ~hdr:"print_ltac"
+ (pr_qualid id ++ spc() ++ str "is not a user defined tactic.")
+
(** Grammar *)
let () =
let entries = [
- AnyEntry Pltac.tactic_expr;
+ AnyEntry Pltac.ltac_expr;
AnyEntry Pltac.binder_tactic;
AnyEntry Pltac.simple_tactic;
- AnyEntry Pltac.tactic_arg;
+ AnyEntry Pltac.tactic_value;
] in
register_grammars_by_name "tactic" entries
diff --git a/plugins/ltac/tacentries.mli b/plugins/ltac/tacentries.mli
index 6ee3ce091b..fc9ab54eba 100644
--- a/plugins/ltac/tacentries.mli
+++ b/plugins/ltac/tacentries.mli
@@ -69,6 +69,9 @@ val print_ltacs : unit -> unit
val print_located_tactic : Libnames.qualid -> unit
(** Display the absolute name of a tactic. *)
+val print_ltac : Libnames.qualid -> Pp.t
+(** Display the definition of a tactic. *)
+
(** {5 Low-level registering of tactics} *)
type (_, 'a) ml_ty_sig =
diff --git a/plugins/ltac/tacintern.ml b/plugins/ltac/tacintern.ml
index dea216045e..47f1d3bf66 100644
--- a/plugins/ltac/tacintern.ml
+++ b/plugins/ltac/tacintern.ml
@@ -769,38 +769,6 @@ let glob_tactic_env l env x =
(intern_pure_tactic { (Genintern.empty_glob_sign env) with ltacvars })
x
-let split_ltac_fun = function
- | TacFun (l,t) -> (l,t)
- | t -> ([],t)
-
-let pr_ltac_fun_arg n = spc () ++ Name.print n
-
-let print_ltac id =
- try
- let kn = Tacenv.locate_tactic id in
- let entries = Tacenv.ltac_entries () in
- let tac = KNmap.find kn entries in
- let filter mp =
- try Some (Nametab.shortest_qualid_of_module mp)
- with Not_found -> None
- in
- let mods = List.map_filter filter tac.Tacenv.tac_redef in
- let redefined = match mods with
- | [] -> mt ()
- | mods ->
- let redef = prlist_with_sep fnl pr_qualid mods in
- fnl () ++ str "Redefined by:" ++ fnl () ++ redef
- in
- let l,t = split_ltac_fun tac.Tacenv.tac_body in
- hv 2 (
- hov 2 (str "Ltac" ++ spc() ++ pr_qualid id ++
- prlist pr_ltac_fun_arg l ++ spc () ++ str ":=")
- ++ spc() ++ Pptactic.pr_glob_tactic (Global.env ()) t) ++ redefined
- with
- Not_found ->
- user_err ~hdr:"print_ltac"
- (pr_qualid id ++ spc() ++ str "is not a user defined tactic.")
-
(** Registering *)
let lift intern = (); fun ist x -> (ist, intern ist x)
@@ -835,7 +803,7 @@ let () =
Genintern.register_intern0 wit_ref (lift intern_global_reference);
Genintern.register_intern0 wit_pre_ident (fun ist c -> (ist,c));
Genintern.register_intern0 wit_ident intern_ident';
- Genintern.register_intern0 wit_var (lift intern_hyp);
+ Genintern.register_intern0 wit_hyp (lift intern_hyp);
Genintern.register_intern0 wit_tactic (lift intern_tactic_or_tacarg);
Genintern.register_intern0 wit_ltac (lift intern_ltac);
Genintern.register_intern0 wit_quant_hyp (lift intern_quantified_hypothesis);
diff --git a/plugins/ltac/tacintern.mli b/plugins/ltac/tacintern.mli
index 22ec15566b..f779aa470c 100644
--- a/plugins/ltac/tacintern.mli
+++ b/plugins/ltac/tacintern.mli
@@ -55,9 +55,6 @@ val intern_hyp : glob_sign -> lident -> lident
val intern_genarg : glob_sign -> raw_generic_argument -> glob_generic_argument
-(** printing *)
-val print_ltac : Libnames.qualid -> Pp.t
-
(** Reduction expressions *)
val intern_red_expr : glob_sign -> raw_red_expr -> glob_red_expr
diff --git a/plugins/ltac/tacinterp.ml b/plugins/ltac/tacinterp.ml
index ff6a36a049..3d734d3a66 100644
--- a/plugins/ltac/tacinterp.ml
+++ b/plugins/ltac/tacinterp.ml
@@ -153,11 +153,15 @@ let add_extra_loc loc extra =
match loc with
| None -> extra
| Some loc -> TacStore.set extra f_loc loc
-let add_loc loc ist =
+let extract_loc ist = TacStore.get ist.extra f_loc
+
+let ensure_loc loc ist =
match loc with
| None -> ist
- | Some loc -> { ist with extra = TacStore.set ist.extra f_loc loc }
-let extract_loc ist = TacStore.get ist.extra f_loc
+ | Some loc ->
+ match extract_loc ist with
+ | None -> { ist with extra = TacStore.set ist.extra f_loc loc }
+ | Some _ -> ist
let print_top_val env v = Pptactic.pr_value Pptactic.ltop v
@@ -971,8 +975,8 @@ let interp_destruction_arg ist gl arg =
match v with
| {v=IntroNaming (IntroIdentifier id)} -> try_cast_id id
| _ -> error ()
- else if has_type v (topwit wit_var) then
- let id = out_gen (topwit wit_var) v in
+ else if has_type v (topwit wit_hyp) then
+ let id = out_gen (topwit wit_hyp) v in
try_cast_id id
else if has_type v (topwit wit_int) then
keep,ElimOnAnonHyp (out_gen (topwit wit_int) v)
@@ -1175,7 +1179,7 @@ and eval_tactic_ist ist tac : unit Proofview.tactic = match tac with
| TacFirst l -> Tacticals.New.tclFIRST (List.map (interp_tactic ist) l)
| TacSolve l -> Tacticals.New.tclSOLVE (List.map (interp_tactic ist) l)
| TacComplete tac -> Tacticals.New.tclCOMPLETE (interp_tactic ist tac)
- | TacArg {CAst.loc} -> Ftactic.run (val_interp (add_loc loc ist) tac) (fun v -> tactic_of_value ist v)
+ | TacArg {CAst.loc} -> Ftactic.run (val_interp (ensure_loc loc ist) tac) (fun v -> tactic_of_value ist v)
| TacSelect (sel, tac) -> Tacticals.New.tclSELECT sel (interp_tactic ist tac)
(* For extensions *)
| TacAlias {loc; v=(s,l)} ->
@@ -1238,7 +1242,7 @@ and interp_ltac_reference ?loc' mustbetac ist r : Val.t Ftactic.t =
| ArgVar {loc;v=id} ->
let v =
try Id.Map.find id ist.lfun
- with Not_found -> in_gen (topwit wit_var) id
+ with Not_found -> in_gen (topwit wit_hyp) id
in
let open Ftactic in
force_vrec ist v >>= begin fun v ->
@@ -1254,9 +1258,12 @@ and interp_ltac_reference ?loc' mustbetac ist r : Val.t Ftactic.t =
let extra = TacStore.set extra f_trace trace in
let ist = { lfun = Id.Map.empty; poly; extra } in
let appl = GlbAppl[r,[]] in
+ (* We call a global ltac reference: add a loc on its executation only if not
+ already in another global reference *)
+ let ist = ensure_loc loc ist in
Profile_ltac.do_profile "interp_ltac_reference" trace ~count_call:false
- (catch_error_tac_loc (* interp *) loc false trace
- (val_interp ~appl (add_loc (* exec *) loc ist) (Tacenv.interp_ltac r)))
+ (catch_error_tac_loc (* loc for interpretation *) loc false trace
+ (val_interp ~appl ist (Tacenv.interp_ltac r)))
and interp_tacarg ist arg : Val.t Ftactic.t =
match arg with
@@ -1325,7 +1332,7 @@ and interp_app loc ist fv largs : Val.t Ftactic.t =
; extra = TacStore.set ist.extra f_trace []
} in
Profile_ltac.do_profile "interp_app" trace ~count_call:false
- (catch_error_tac_loc loc false trace (val_interp (add_loc loc ist) body)) >>= fun v ->
+ (catch_error_tac_loc loc false trace (val_interp (ensure_loc loc ist) body)) >>= fun v ->
Ftactic.return (name_vfun (push_appl appl largs) v)
end
begin fun (e, info) ->
@@ -1529,7 +1536,7 @@ and interp_genarg ist x : Val.t Ftactic.t =
let open Ftactic.Notations in
(* Ad-hoc handling of some types. *)
let tag = genarg_tag x in
- if argument_type_eq tag (unquote (topwit (wit_list wit_var))) then
+ if argument_type_eq tag (unquote (topwit (wit_list wit_hyp))) then
interp_genarg_var_list ist x
else if argument_type_eq tag (unquote (topwit (wit_list wit_constr))) then
interp_genarg_constr_list ist x
@@ -1573,9 +1580,9 @@ and interp_genarg_var_list ist x =
Ftactic.enter begin fun gl ->
let env = Proofview.Goal.env gl in
let sigma = Proofview.Goal.sigma gl in
- let lc = Genarg.out_gen (glbwit (wit_list wit_var)) x in
+ let lc = Genarg.out_gen (glbwit (wit_list wit_hyp)) x in
let lc = interp_hyp_list ist env sigma lc in
- let lc = in_list (val_tag wit_var) lc in
+ let lc = in_list (val_tag wit_hyp) lc in
Ftactic.return lc
end
@@ -1996,16 +2003,20 @@ let interp_tac_gen lfun avoid_ids debug t =
let interp t = interp_tac_gen Id.Map.empty Id.Set.empty (get_debug()) t
+(* MUST be marshallable! *)
+type ltac_expr = {
+ global: bool;
+ ast: Tacexpr.raw_tactic_expr;
+}
+
(* Used to hide interpretation for pretty-print, now just launch tactics *)
(* [global] means that [t] should be internalized outside of goals. *)
-let hide_interp global t ot =
+let hide_interp {global;ast} =
let hide_interp env =
let ist = Genintern.empty_glob_sign env in
- let te = intern_pure_tactic ist t in
+ let te = intern_pure_tactic ist ast in
let t = eval_tactic te in
- match ot with
- | None -> t
- | Some t' -> Tacticals.New.tclTHEN t t'
+ t
in
if global then
Proofview.tclENV >>= fun env ->
@@ -2015,6 +2026,8 @@ let hide_interp global t ot =
hide_interp (Proofview.Goal.env gl)
end
+let ComTactic.Interpreter hide_interp = ComTactic.register_tactic_interpreter "ltac1" hide_interp
+
(***************************************************************************)
(** Register standard arguments *)
@@ -2090,7 +2103,7 @@ let () =
register_interp0 wit_ref (lift interp_reference);
register_interp0 wit_pre_ident (lift interp_pre_ident);
register_interp0 wit_ident (lift interp_ident);
- register_interp0 wit_var (lift interp_hyp);
+ register_interp0 wit_hyp (lift interp_hyp);
register_interp0 wit_intropattern (lifts interp_intro_pattern) [@warning "-3"];
register_interp0 wit_simple_intropattern (lifts interp_intro_pattern);
register_interp0 wit_clause_dft_concl (lift interp_clause);
diff --git a/plugins/ltac/tacinterp.mli b/plugins/ltac/tacinterp.mli
index cbb17bf0fa..a74f4592f7 100644
--- a/plugins/ltac/tacinterp.mli
+++ b/plugins/ltac/tacinterp.mli
@@ -77,6 +77,9 @@ val val_interp : interp_sign -> glob_tactic_expr -> (value -> unit Proofview.tac
val interp_ltac_constr : interp_sign -> glob_tactic_expr -> (constr -> unit Proofview.tactic) -> unit Proofview.tactic
(** Interprets redexp arguments *)
+val interp_red_expr : interp_sign -> Environ.env -> Evd.evar_map -> glob_red_expr -> Evd.evar_map * red_expr
+
+(** Interprets redexp arguments from a raw one *)
val interp_redexp : Environ.env -> Evd.evar_map -> raw_red_expr -> Evd.evar_map * red_expr
(** Interprets tactic expressions *)
@@ -126,8 +129,12 @@ val interp_tac_gen : value Id.Map.t -> Id.Set.t ->
val interp : raw_tactic_expr -> unit Proofview.tactic
(** Hides interpretation for pretty-print *)
+type ltac_expr = {
+ global: bool;
+ ast: Tacexpr.raw_tactic_expr;
+}
-val hide_interp : bool -> raw_tactic_expr -> unit Proofview.tactic option -> unit Proofview.tactic
+val hide_interp : ltac_expr -> ComTactic.interpretable
(** Internals that can be useful for syntax extensions. *)
diff --git a/plugins/ltac/tacsubst.ml b/plugins/ltac/tacsubst.ml
index fd869b225f..ec44ae4698 100644
--- a/plugins/ltac/tacsubst.ml
+++ b/plugins/ltac/tacsubst.ml
@@ -282,7 +282,7 @@ let () =
Genintern.register_subst0 wit_smart_global subst_global_reference;
Genintern.register_subst0 wit_pre_ident (fun _ v -> v);
Genintern.register_subst0 wit_ident (fun _ v -> v);
- Genintern.register_subst0 wit_var (fun _ v -> v);
+ Genintern.register_subst0 wit_hyp (fun _ v -> v);
Genintern.register_subst0 wit_intropattern subst_intro_pattern [@warning "-3"];
Genintern.register_subst0 wit_simple_intropattern subst_intro_pattern;
Genintern.register_subst0 wit_tactic subst_tactic;
diff --git a/plugins/micromega/coq_micromega.ml b/plugins/micromega/coq_micromega.ml
index d2c49c4432..542b99075d 100644
--- a/plugins/micromega/coq_micromega.ml
+++ b/plugins/micromega/coq_micromega.ml
@@ -134,166 +134,161 @@ let selecti s m =
*)
(**
- * MODULE END: M
- *)
-module M = struct
- (**
* Initialization : a large amount of Caml symbols are derived from
* ZMicromega.v
*)
- let constr_of_ref str =
- EConstr.of_constr
- (UnivGen.constr_of_monomorphic_global (Coqlib.lib_ref str))
-
- let coq_and = lazy (constr_of_ref "core.and.type")
- let coq_or = lazy (constr_of_ref "core.or.type")
- let coq_not = lazy (constr_of_ref "core.not.type")
- let coq_iff = lazy (constr_of_ref "core.iff.type")
- let coq_True = lazy (constr_of_ref "core.True.type")
- let coq_False = lazy (constr_of_ref "core.False.type")
- let coq_bool = lazy (constr_of_ref "core.bool.type")
- let coq_true = lazy (constr_of_ref "core.bool.true")
- let coq_false = lazy (constr_of_ref "core.bool.false")
- let coq_andb = lazy (constr_of_ref "core.bool.andb")
- let coq_orb = lazy (constr_of_ref "core.bool.orb")
- let coq_implb = lazy (constr_of_ref "core.bool.implb")
- let coq_eqb = lazy (constr_of_ref "core.bool.eqb")
- let coq_negb = lazy (constr_of_ref "core.bool.negb")
- let coq_cons = lazy (constr_of_ref "core.list.cons")
- let coq_nil = lazy (constr_of_ref "core.list.nil")
- let coq_list = lazy (constr_of_ref "core.list.type")
- let coq_O = lazy (constr_of_ref "num.nat.O")
- let coq_S = lazy (constr_of_ref "num.nat.S")
- let coq_nat = lazy (constr_of_ref "num.nat.type")
- let coq_unit = lazy (constr_of_ref "core.unit.type")
-
- (* let coq_option = lazy (init_constant "option")*)
- let coq_None = lazy (constr_of_ref "core.option.None")
- let coq_tt = lazy (constr_of_ref "core.unit.tt")
- let coq_Inl = lazy (constr_of_ref "core.sum.inl")
- let coq_Inr = lazy (constr_of_ref "core.sum.inr")
- let coq_N0 = lazy (constr_of_ref "num.N.N0")
- let coq_Npos = lazy (constr_of_ref "num.N.Npos")
- let coq_xH = lazy (constr_of_ref "num.pos.xH")
- let coq_xO = lazy (constr_of_ref "num.pos.xO")
- let coq_xI = lazy (constr_of_ref "num.pos.xI")
- let coq_Z = lazy (constr_of_ref "num.Z.type")
- let coq_ZERO = lazy (constr_of_ref "num.Z.Z0")
- let coq_POS = lazy (constr_of_ref "num.Z.Zpos")
- let coq_NEG = lazy (constr_of_ref "num.Z.Zneg")
- let coq_Q = lazy (constr_of_ref "rat.Q.type")
- let coq_Qmake = lazy (constr_of_ref "rat.Q.Qmake")
- let coq_R = lazy (constr_of_ref "reals.R.type")
- let coq_Rcst = lazy (constr_of_ref "micromega.Rcst.type")
- let coq_C0 = lazy (constr_of_ref "micromega.Rcst.C0")
- let coq_C1 = lazy (constr_of_ref "micromega.Rcst.C1")
- let coq_CQ = lazy (constr_of_ref "micromega.Rcst.CQ")
- let coq_CZ = lazy (constr_of_ref "micromega.Rcst.CZ")
- let coq_CPlus = lazy (constr_of_ref "micromega.Rcst.CPlus")
- let coq_CMinus = lazy (constr_of_ref "micromega.Rcst.CMinus")
- let coq_CMult = lazy (constr_of_ref "micromega.Rcst.CMult")
- let coq_CPow = lazy (constr_of_ref "micromega.Rcst.CPow")
- let coq_CInv = lazy (constr_of_ref "micromega.Rcst.CInv")
- let coq_COpp = lazy (constr_of_ref "micromega.Rcst.COpp")
- let coq_R0 = lazy (constr_of_ref "reals.R.R0")
- let coq_R1 = lazy (constr_of_ref "reals.R.R1")
- let coq_proofTerm = lazy (constr_of_ref "micromega.ZArithProof.type")
- let coq_doneProof = lazy (constr_of_ref "micromega.ZArithProof.DoneProof")
- let coq_ratProof = lazy (constr_of_ref "micromega.ZArithProof.RatProof")
- let coq_cutProof = lazy (constr_of_ref "micromega.ZArithProof.CutProof")
- let coq_enumProof = lazy (constr_of_ref "micromega.ZArithProof.EnumProof")
- let coq_ExProof = lazy (constr_of_ref "micromega.ZArithProof.ExProof")
- let coq_IsProp = lazy (constr_of_ref "micromega.kind.isProp")
- let coq_IsBool = lazy (constr_of_ref "micromega.kind.isBool")
- let coq_Zgt = lazy (constr_of_ref "num.Z.gt")
- let coq_Zge = lazy (constr_of_ref "num.Z.ge")
- let coq_Zle = lazy (constr_of_ref "num.Z.le")
- let coq_Zlt = lazy (constr_of_ref "num.Z.lt")
- let coq_Zgtb = lazy (constr_of_ref "num.Z.gtb")
- let coq_Zgeb = lazy (constr_of_ref "num.Z.geb")
- let coq_Zleb = lazy (constr_of_ref "num.Z.leb")
- let coq_Zltb = lazy (constr_of_ref "num.Z.ltb")
- let coq_Zeqb = lazy (constr_of_ref "num.Z.eqb")
- let coq_eq = lazy (constr_of_ref "core.eq.type")
- let coq_Zplus = lazy (constr_of_ref "num.Z.add")
- let coq_Zminus = lazy (constr_of_ref "num.Z.sub")
- let coq_Zopp = lazy (constr_of_ref "num.Z.opp")
- let coq_Zmult = lazy (constr_of_ref "num.Z.mul")
- let coq_Zpower = lazy (constr_of_ref "num.Z.pow")
- let coq_Qle = lazy (constr_of_ref "rat.Q.Qle")
- let coq_Qlt = lazy (constr_of_ref "rat.Q.Qlt")
- let coq_Qeq = lazy (constr_of_ref "rat.Q.Qeq")
- let coq_Qplus = lazy (constr_of_ref "rat.Q.Qplus")
- let coq_Qminus = lazy (constr_of_ref "rat.Q.Qminus")
- let coq_Qopp = lazy (constr_of_ref "rat.Q.Qopp")
- let coq_Qmult = lazy (constr_of_ref "rat.Q.Qmult")
- let coq_Qpower = lazy (constr_of_ref "rat.Q.Qpower")
- let coq_Rgt = lazy (constr_of_ref "reals.R.Rgt")
- let coq_Rge = lazy (constr_of_ref "reals.R.Rge")
- let coq_Rle = lazy (constr_of_ref "reals.R.Rle")
- let coq_Rlt = lazy (constr_of_ref "reals.R.Rlt")
- let coq_Rplus = lazy (constr_of_ref "reals.R.Rplus")
- let coq_Rminus = lazy (constr_of_ref "reals.R.Rminus")
- let coq_Ropp = lazy (constr_of_ref "reals.R.Ropp")
- let coq_Rmult = lazy (constr_of_ref "reals.R.Rmult")
- let coq_Rinv = lazy (constr_of_ref "reals.R.Rinv")
- let coq_Rpower = lazy (constr_of_ref "reals.R.pow")
- let coq_powerZR = lazy (constr_of_ref "reals.R.powerRZ")
- let coq_IZR = lazy (constr_of_ref "reals.R.IZR")
- let coq_IQR = lazy (constr_of_ref "reals.R.Q2R")
- let coq_PEX = lazy (constr_of_ref "micromega.PExpr.PEX")
- let coq_PEc = lazy (constr_of_ref "micromega.PExpr.PEc")
- let coq_PEadd = lazy (constr_of_ref "micromega.PExpr.PEadd")
- let coq_PEopp = lazy (constr_of_ref "micromega.PExpr.PEopp")
- let coq_PEmul = lazy (constr_of_ref "micromega.PExpr.PEmul")
- let coq_PEsub = lazy (constr_of_ref "micromega.PExpr.PEsub")
- let coq_PEpow = lazy (constr_of_ref "micromega.PExpr.PEpow")
- let coq_PX = lazy (constr_of_ref "micromega.Pol.PX")
- let coq_Pc = lazy (constr_of_ref "micromega.Pol.Pc")
- let coq_Pinj = lazy (constr_of_ref "micromega.Pol.Pinj")
- let coq_OpEq = lazy (constr_of_ref "micromega.Op2.OpEq")
- let coq_OpNEq = lazy (constr_of_ref "micromega.Op2.OpNEq")
- let coq_OpLe = lazy (constr_of_ref "micromega.Op2.OpLe")
- let coq_OpLt = lazy (constr_of_ref "micromega.Op2.OpLt")
- let coq_OpGe = lazy (constr_of_ref "micromega.Op2.OpGe")
- let coq_OpGt = lazy (constr_of_ref "micromega.Op2.OpGt")
- let coq_PsatzIn = lazy (constr_of_ref "micromega.Psatz.PsatzIn")
- let coq_PsatzSquare = lazy (constr_of_ref "micromega.Psatz.PsatzSquare")
- let coq_PsatzMulE = lazy (constr_of_ref "micromega.Psatz.PsatzMulE")
- let coq_PsatzMultC = lazy (constr_of_ref "micromega.Psatz.PsatzMulC")
- let coq_PsatzAdd = lazy (constr_of_ref "micromega.Psatz.PsatzAdd")
- let coq_PsatzC = lazy (constr_of_ref "micromega.Psatz.PsatzC")
- let coq_PsatzZ = lazy (constr_of_ref "micromega.Psatz.PsatzZ")
-
- (* let coq_GT = lazy (m_constant "GT")*)
-
- let coq_DeclaredConstant =
- lazy (constr_of_ref "micromega.DeclaredConstant.type")
-
- let coq_TT = lazy (constr_of_ref "micromega.GFormula.TT")
- let coq_FF = lazy (constr_of_ref "micromega.GFormula.FF")
- let coq_AND = lazy (constr_of_ref "micromega.GFormula.AND")
- let coq_OR = lazy (constr_of_ref "micromega.GFormula.OR")
- let coq_NOT = lazy (constr_of_ref "micromega.GFormula.NOT")
- let coq_Atom = lazy (constr_of_ref "micromega.GFormula.A")
- let coq_X = lazy (constr_of_ref "micromega.GFormula.X")
- let coq_IMPL = lazy (constr_of_ref "micromega.GFormula.IMPL")
- let coq_IFF = lazy (constr_of_ref "micromega.GFormula.IFF")
- let coq_EQ = lazy (constr_of_ref "micromega.GFormula.EQ")
- let coq_Formula = lazy (constr_of_ref "micromega.BFormula.type")
- let coq_eKind = lazy (constr_of_ref "micromega.eKind")
-
- (**
+let constr_of_ref str =
+ EConstr.of_constr (UnivGen.constr_of_monomorphic_global (Coqlib.lib_ref str))
+
+let coq_and = lazy (constr_of_ref "core.and.type")
+let coq_or = lazy (constr_of_ref "core.or.type")
+let coq_not = lazy (constr_of_ref "core.not.type")
+let coq_iff = lazy (constr_of_ref "core.iff.type")
+let coq_True = lazy (constr_of_ref "core.True.type")
+let coq_False = lazy (constr_of_ref "core.False.type")
+let coq_bool = lazy (constr_of_ref "core.bool.type")
+let coq_true = lazy (constr_of_ref "core.bool.true")
+let coq_false = lazy (constr_of_ref "core.bool.false")
+let coq_andb = lazy (constr_of_ref "core.bool.andb")
+let coq_orb = lazy (constr_of_ref "core.bool.orb")
+let coq_implb = lazy (constr_of_ref "core.bool.implb")
+let coq_eqb = lazy (constr_of_ref "core.bool.eqb")
+let coq_negb = lazy (constr_of_ref "core.bool.negb")
+let coq_cons = lazy (constr_of_ref "core.list.cons")
+let coq_nil = lazy (constr_of_ref "core.list.nil")
+let coq_list = lazy (constr_of_ref "core.list.type")
+let coq_O = lazy (constr_of_ref "num.nat.O")
+let coq_S = lazy (constr_of_ref "num.nat.S")
+let coq_nat = lazy (constr_of_ref "num.nat.type")
+let coq_unit = lazy (constr_of_ref "core.unit.type")
+
+(* let coq_option = lazy (init_constant "option")*)
+let coq_None = lazy (constr_of_ref "core.option.None")
+let coq_tt = lazy (constr_of_ref "core.unit.tt")
+let coq_Inl = lazy (constr_of_ref "core.sum.inl")
+let coq_Inr = lazy (constr_of_ref "core.sum.inr")
+let coq_N0 = lazy (constr_of_ref "num.N.N0")
+let coq_Npos = lazy (constr_of_ref "num.N.Npos")
+let coq_xH = lazy (constr_of_ref "num.pos.xH")
+let coq_xO = lazy (constr_of_ref "num.pos.xO")
+let coq_xI = lazy (constr_of_ref "num.pos.xI")
+let coq_Z = lazy (constr_of_ref "num.Z.type")
+let coq_ZERO = lazy (constr_of_ref "num.Z.Z0")
+let coq_POS = lazy (constr_of_ref "num.Z.Zpos")
+let coq_NEG = lazy (constr_of_ref "num.Z.Zneg")
+let coq_Q = lazy (constr_of_ref "rat.Q.type")
+let coq_Qmake = lazy (constr_of_ref "rat.Q.Qmake")
+let coq_R = lazy (constr_of_ref "reals.R.type")
+let coq_Rcst = lazy (constr_of_ref "micromega.Rcst.type")
+let coq_C0 = lazy (constr_of_ref "micromega.Rcst.C0")
+let coq_C1 = lazy (constr_of_ref "micromega.Rcst.C1")
+let coq_CQ = lazy (constr_of_ref "micromega.Rcst.CQ")
+let coq_CZ = lazy (constr_of_ref "micromega.Rcst.CZ")
+let coq_CPlus = lazy (constr_of_ref "micromega.Rcst.CPlus")
+let coq_CMinus = lazy (constr_of_ref "micromega.Rcst.CMinus")
+let coq_CMult = lazy (constr_of_ref "micromega.Rcst.CMult")
+let coq_CPow = lazy (constr_of_ref "micromega.Rcst.CPow")
+let coq_CInv = lazy (constr_of_ref "micromega.Rcst.CInv")
+let coq_COpp = lazy (constr_of_ref "micromega.Rcst.COpp")
+let coq_R0 = lazy (constr_of_ref "reals.R.R0")
+let coq_R1 = lazy (constr_of_ref "reals.R.R1")
+let coq_proofTerm = lazy (constr_of_ref "micromega.ZArithProof.type")
+let coq_doneProof = lazy (constr_of_ref "micromega.ZArithProof.DoneProof")
+let coq_ratProof = lazy (constr_of_ref "micromega.ZArithProof.RatProof")
+let coq_cutProof = lazy (constr_of_ref "micromega.ZArithProof.CutProof")
+let coq_enumProof = lazy (constr_of_ref "micromega.ZArithProof.EnumProof")
+let coq_ExProof = lazy (constr_of_ref "micromega.ZArithProof.ExProof")
+let coq_IsProp = lazy (constr_of_ref "micromega.kind.isProp")
+let coq_IsBool = lazy (constr_of_ref "micromega.kind.isBool")
+let coq_Zgt = lazy (constr_of_ref "num.Z.gt")
+let coq_Zge = lazy (constr_of_ref "num.Z.ge")
+let coq_Zle = lazy (constr_of_ref "num.Z.le")
+let coq_Zlt = lazy (constr_of_ref "num.Z.lt")
+let coq_Zgtb = lazy (constr_of_ref "num.Z.gtb")
+let coq_Zgeb = lazy (constr_of_ref "num.Z.geb")
+let coq_Zleb = lazy (constr_of_ref "num.Z.leb")
+let coq_Zltb = lazy (constr_of_ref "num.Z.ltb")
+let coq_Zeqb = lazy (constr_of_ref "num.Z.eqb")
+let coq_eq = lazy (constr_of_ref "core.eq.type")
+let coq_Zplus = lazy (constr_of_ref "num.Z.add")
+let coq_Zminus = lazy (constr_of_ref "num.Z.sub")
+let coq_Zopp = lazy (constr_of_ref "num.Z.opp")
+let coq_Zmult = lazy (constr_of_ref "num.Z.mul")
+let coq_Zpower = lazy (constr_of_ref "num.Z.pow")
+let coq_Qle = lazy (constr_of_ref "rat.Q.Qle")
+let coq_Qlt = lazy (constr_of_ref "rat.Q.Qlt")
+let coq_Qeq = lazy (constr_of_ref "rat.Q.Qeq")
+let coq_Qplus = lazy (constr_of_ref "rat.Q.Qplus")
+let coq_Qminus = lazy (constr_of_ref "rat.Q.Qminus")
+let coq_Qopp = lazy (constr_of_ref "rat.Q.Qopp")
+let coq_Qmult = lazy (constr_of_ref "rat.Q.Qmult")
+let coq_Qpower = lazy (constr_of_ref "rat.Q.Qpower")
+let coq_Rgt = lazy (constr_of_ref "reals.R.Rgt")
+let coq_Rge = lazy (constr_of_ref "reals.R.Rge")
+let coq_Rle = lazy (constr_of_ref "reals.R.Rle")
+let coq_Rlt = lazy (constr_of_ref "reals.R.Rlt")
+let coq_Rplus = lazy (constr_of_ref "reals.R.Rplus")
+let coq_Rminus = lazy (constr_of_ref "reals.R.Rminus")
+let coq_Ropp = lazy (constr_of_ref "reals.R.Ropp")
+let coq_Rmult = lazy (constr_of_ref "reals.R.Rmult")
+let coq_Rinv = lazy (constr_of_ref "reals.R.Rinv")
+let coq_Rpower = lazy (constr_of_ref "reals.R.pow")
+let coq_powerZR = lazy (constr_of_ref "reals.R.powerRZ")
+let coq_IZR = lazy (constr_of_ref "reals.R.IZR")
+let coq_IQR = lazy (constr_of_ref "reals.R.Q2R")
+let coq_PEX = lazy (constr_of_ref "micromega.PExpr.PEX")
+let coq_PEc = lazy (constr_of_ref "micromega.PExpr.PEc")
+let coq_PEadd = lazy (constr_of_ref "micromega.PExpr.PEadd")
+let coq_PEopp = lazy (constr_of_ref "micromega.PExpr.PEopp")
+let coq_PEmul = lazy (constr_of_ref "micromega.PExpr.PEmul")
+let coq_PEsub = lazy (constr_of_ref "micromega.PExpr.PEsub")
+let coq_PEpow = lazy (constr_of_ref "micromega.PExpr.PEpow")
+let coq_PX = lazy (constr_of_ref "micromega.Pol.PX")
+let coq_Pc = lazy (constr_of_ref "micromega.Pol.Pc")
+let coq_Pinj = lazy (constr_of_ref "micromega.Pol.Pinj")
+let coq_OpEq = lazy (constr_of_ref "micromega.Op2.OpEq")
+let coq_OpNEq = lazy (constr_of_ref "micromega.Op2.OpNEq")
+let coq_OpLe = lazy (constr_of_ref "micromega.Op2.OpLe")
+let coq_OpLt = lazy (constr_of_ref "micromega.Op2.OpLt")
+let coq_OpGe = lazy (constr_of_ref "micromega.Op2.OpGe")
+let coq_OpGt = lazy (constr_of_ref "micromega.Op2.OpGt")
+let coq_PsatzIn = lazy (constr_of_ref "micromega.Psatz.PsatzIn")
+let coq_PsatzSquare = lazy (constr_of_ref "micromega.Psatz.PsatzSquare")
+let coq_PsatzMulE = lazy (constr_of_ref "micromega.Psatz.PsatzMulE")
+let coq_PsatzMultC = lazy (constr_of_ref "micromega.Psatz.PsatzMulC")
+let coq_PsatzAdd = lazy (constr_of_ref "micromega.Psatz.PsatzAdd")
+let coq_PsatzC = lazy (constr_of_ref "micromega.Psatz.PsatzC")
+let coq_PsatzZ = lazy (constr_of_ref "micromega.Psatz.PsatzZ")
+
+(* let coq_GT = lazy (m_constant "GT")*)
+
+let coq_DeclaredConstant =
+ lazy (constr_of_ref "micromega.DeclaredConstant.type")
+
+let coq_TT = lazy (constr_of_ref "micromega.GFormula.TT")
+let coq_FF = lazy (constr_of_ref "micromega.GFormula.FF")
+let coq_AND = lazy (constr_of_ref "micromega.GFormula.AND")
+let coq_OR = lazy (constr_of_ref "micromega.GFormula.OR")
+let coq_NOT = lazy (constr_of_ref "micromega.GFormula.NOT")
+let coq_Atom = lazy (constr_of_ref "micromega.GFormula.A")
+let coq_X = lazy (constr_of_ref "micromega.GFormula.X")
+let coq_IMPL = lazy (constr_of_ref "micromega.GFormula.IMPL")
+let coq_IFF = lazy (constr_of_ref "micromega.GFormula.IFF")
+let coq_EQ = lazy (constr_of_ref "micromega.GFormula.EQ")
+let coq_Formula = lazy (constr_of_ref "micromega.BFormula.type")
+let coq_eKind = lazy (constr_of_ref "micromega.eKind")
+
+(**
* Initialization : a few Caml symbols are derived from other libraries;
* QMicromega, ZArithRing, RingMicromega.
*)
- let coq_QWitness = lazy (constr_of_ref "micromega.QWitness.type")
- let coq_Build = lazy (constr_of_ref "micromega.Formula.Build_Formula")
- let coq_Cstr = lazy (constr_of_ref "micromega.Formula.type")
+let coq_QWitness = lazy (constr_of_ref "micromega.QWitness.type")
+let coq_Build = lazy (constr_of_ref "micromega.Formula.Build_Formula")
+let coq_Cstr = lazy (constr_of_ref "micromega.Formula.type")
- (**
+(**
* Parsing and dumping : transformation functions between Caml and Coq
* data-structures.
*
@@ -302,1048 +297,1018 @@ module M = struct
* pp_* functions pretty-print Coq terms.
*)
- exception ParseError
+exception ParseError
- (* A simple but useful getter function *)
+(* A simple but useful getter function *)
- let get_left_construct sigma term =
- match EConstr.kind sigma term with
- | Construct ((_, i), _) -> (i, [||])
- | App (l, rst) -> (
- match EConstr.kind sigma l with
- | Construct ((_, i), _) -> (i, rst)
- | _ -> raise ParseError )
- | _ -> raise ParseError
+let get_left_construct sigma term =
+ match EConstr.kind sigma term with
+ | Construct ((_, i), _) -> (i, [||])
+ | App (l, rst) -> (
+ match EConstr.kind sigma l with
+ | Construct ((_, i), _) -> (i, rst)
+ | _ -> raise ParseError )
+ | _ -> raise ParseError
- (* Access the Micromega module *)
+(* Access the Micromega module *)
- (* parse/dump/print from numbers up to expressions and formulas *)
+(* parse/dump/print from numbers up to expressions and formulas *)
- let rec parse_nat sigma term =
- let i, c = get_left_construct sigma term in
- match i with
- | 1 -> Mc.O
- | 2 -> Mc.S (parse_nat sigma c.(0))
- | i -> raise ParseError
+let rec parse_nat sigma term =
+ let i, c = get_left_construct sigma term in
+ match i with
+ | 1 -> Mc.O
+ | 2 -> Mc.S (parse_nat sigma c.(0))
+ | i -> raise ParseError
- let pp_nat o n = Printf.fprintf o "%i" (CoqToCaml.nat n)
+let pp_nat o n = Printf.fprintf o "%i" (CoqToCaml.nat n)
- let rec dump_nat x =
- match x with
- | Mc.O -> Lazy.force coq_O
- | Mc.S p -> EConstr.mkApp (Lazy.force coq_S, [|dump_nat p|])
+let rec dump_nat x =
+ match x with
+ | Mc.O -> Lazy.force coq_O
+ | Mc.S p -> EConstr.mkApp (Lazy.force coq_S, [|dump_nat p|])
- let rec parse_positive sigma term =
- let i, c = get_left_construct sigma term in
- match i with
- | 1 -> Mc.XI (parse_positive sigma c.(0))
- | 2 -> Mc.XO (parse_positive sigma c.(0))
- | 3 -> Mc.XH
- | i -> raise ParseError
+let rec parse_positive sigma term =
+ let i, c = get_left_construct sigma term in
+ match i with
+ | 1 -> Mc.XI (parse_positive sigma c.(0))
+ | 2 -> Mc.XO (parse_positive sigma c.(0))
+ | 3 -> Mc.XH
+ | i -> raise ParseError
- let rec dump_positive x =
- match x with
- | Mc.XH -> Lazy.force coq_xH
- | Mc.XO p -> EConstr.mkApp (Lazy.force coq_xO, [|dump_positive p|])
- | Mc.XI p -> EConstr.mkApp (Lazy.force coq_xI, [|dump_positive p|])
+let rec dump_positive x =
+ match x with
+ | Mc.XH -> Lazy.force coq_xH
+ | Mc.XO p -> EConstr.mkApp (Lazy.force coq_xO, [|dump_positive p|])
+ | Mc.XI p -> EConstr.mkApp (Lazy.force coq_xI, [|dump_positive p|])
- let pp_positive o x = Printf.fprintf o "%i" (CoqToCaml.positive x)
+let pp_positive o x = Printf.fprintf o "%i" (CoqToCaml.positive x)
- let dump_n x =
- match x with
- | Mc.N0 -> Lazy.force coq_N0
- | Mc.Npos p -> EConstr.mkApp (Lazy.force coq_Npos, [|dump_positive p|])
+let dump_n x =
+ match x with
+ | Mc.N0 -> Lazy.force coq_N0
+ | Mc.Npos p -> EConstr.mkApp (Lazy.force coq_Npos, [|dump_positive p|])
- (** [is_ground_term env sigma term] holds if the term [term]
+(** [is_ground_term env sigma term] holds if the term [term]
is an instance of the typeclass [DeclConstant.GT term]
i.e. built from user-defined constants and functions.
NB: This mechanism can be used to customise the reification process to decide
what to consider as a constant (see [parse_constant])
*)
- let is_declared_term env evd t =
- match EConstr.kind evd t with
- | Const _ | Construct _ -> (
- (* Restrict typeclass resolution to trivial cases *)
- let typ = Retyping.get_type_of env evd t in
- try
- ignore
- (Typeclasses.resolve_one_typeclass env evd
- (EConstr.mkApp (Lazy.force coq_DeclaredConstant, [|typ; t|])));
- true
- with Not_found -> false )
- | _ -> false
-
- let rec is_ground_term env evd term =
- match EConstr.kind evd term with
- | App (c, args) ->
- is_declared_term env evd c && Array.for_all (is_ground_term env evd) args
- | Const _ | Construct _ -> is_declared_term env evd term
- | _ -> false
-
- let parse_z sigma term =
- let i, c = get_left_construct sigma term in
- match i with
- | 1 -> Mc.Z0
- | 2 -> Mc.Zpos (parse_positive sigma c.(0))
- | 3 -> Mc.Zneg (parse_positive sigma c.(0))
- | i -> raise ParseError
-
- let dump_z x =
- match x with
- | Mc.Z0 -> Lazy.force coq_ZERO
- | Mc.Zpos p -> EConstr.mkApp (Lazy.force coq_POS, [|dump_positive p|])
- | Mc.Zneg p -> EConstr.mkApp (Lazy.force coq_NEG, [|dump_positive p|])
-
- let pp_z o x =
- Printf.fprintf o "%s" (NumCompat.Z.to_string (CoqToCaml.z_big_int x))
-
- let dump_q q =
+let is_declared_term env evd t =
+ match EConstr.kind evd t with
+ | Const _ | Construct _ -> (
+ (* Restrict typeclass resolution to trivial cases *)
+ let typ = Retyping.get_type_of env evd t in
+ try
+ ignore
+ (Typeclasses.resolve_one_typeclass env evd
+ (EConstr.mkApp (Lazy.force coq_DeclaredConstant, [|typ; t|])));
+ true
+ with Not_found -> false )
+ | _ -> false
+
+let rec is_ground_term env evd term =
+ match EConstr.kind evd term with
+ | App (c, args) ->
+ is_declared_term env evd c && Array.for_all (is_ground_term env evd) args
+ | Const _ | Construct _ -> is_declared_term env evd term
+ | _ -> false
+
+let parse_z sigma term =
+ let i, c = get_left_construct sigma term in
+ match i with
+ | 1 -> Mc.Z0
+ | 2 -> Mc.Zpos (parse_positive sigma c.(0))
+ | 3 -> Mc.Zneg (parse_positive sigma c.(0))
+ | i -> raise ParseError
+
+let dump_z x =
+ match x with
+ | Mc.Z0 -> Lazy.force coq_ZERO
+ | Mc.Zpos p -> EConstr.mkApp (Lazy.force coq_POS, [|dump_positive p|])
+ | Mc.Zneg p -> EConstr.mkApp (Lazy.force coq_NEG, [|dump_positive p|])
+
+let pp_z o x =
+ Printf.fprintf o "%s" (NumCompat.Z.to_string (CoqToCaml.z_big_int x))
+
+let dump_q q =
+ EConstr.mkApp
+ ( Lazy.force coq_Qmake
+ , [|dump_z q.Micromega.qnum; dump_positive q.Micromega.qden|] )
+
+let parse_q sigma term =
+ match EConstr.kind sigma term with
+ | App (c, args) ->
+ if EConstr.eq_constr sigma c (Lazy.force coq_Qmake) then
+ {Mc.qnum = parse_z sigma args.(0); Mc.qden = parse_positive sigma args.(1)}
+ else raise ParseError
+ | _ -> raise ParseError
+
+let rec pp_Rcst o cst =
+ match cst with
+ | Mc.C0 -> output_string o "C0"
+ | Mc.C1 -> output_string o "C1"
+ | Mc.CQ q -> output_string o "CQ _"
+ | Mc.CZ z -> pp_z o z
+ | Mc.CPlus (x, y) -> Printf.fprintf o "(%a + %a)" pp_Rcst x pp_Rcst y
+ | Mc.CMinus (x, y) -> Printf.fprintf o "(%a - %a)" pp_Rcst x pp_Rcst y
+ | Mc.CMult (x, y) -> Printf.fprintf o "(%a * %a)" pp_Rcst x pp_Rcst y
+ | Mc.CPow (x, y) -> Printf.fprintf o "(%a ^ _)" pp_Rcst x
+ | Mc.CInv t -> Printf.fprintf o "(/ %a)" pp_Rcst t
+ | Mc.COpp t -> Printf.fprintf o "(- %a)" pp_Rcst t
+
+let rec dump_Rcst cst =
+ match cst with
+ | Mc.C0 -> Lazy.force coq_C0
+ | Mc.C1 -> Lazy.force coq_C1
+ | Mc.CQ q -> EConstr.mkApp (Lazy.force coq_CQ, [|dump_q q|])
+ | Mc.CZ z -> EConstr.mkApp (Lazy.force coq_CZ, [|dump_z z|])
+ | Mc.CPlus (x, y) ->
+ EConstr.mkApp (Lazy.force coq_CPlus, [|dump_Rcst x; dump_Rcst y|])
+ | Mc.CMinus (x, y) ->
+ EConstr.mkApp (Lazy.force coq_CMinus, [|dump_Rcst x; dump_Rcst y|])
+ | Mc.CMult (x, y) ->
+ EConstr.mkApp (Lazy.force coq_CMult, [|dump_Rcst x; dump_Rcst y|])
+ | Mc.CPow (x, y) ->
EConstr.mkApp
- ( Lazy.force coq_Qmake
- , [|dump_z q.Micromega.qnum; dump_positive q.Micromega.qden|] )
-
- let parse_q sigma term =
- match EConstr.kind sigma term with
- | App (c, args) ->
- if EConstr.eq_constr sigma c (Lazy.force coq_Qmake) then
- { Mc.qnum = parse_z sigma args.(0)
- ; Mc.qden = parse_positive sigma args.(1) }
- else raise ParseError
- | _ -> raise ParseError
+ ( Lazy.force coq_CPow
+ , [| dump_Rcst x
+ ; ( match y with
+ | Mc.Inl z ->
+ EConstr.mkApp
+ ( Lazy.force coq_Inl
+ , [|Lazy.force coq_Z; Lazy.force coq_nat; dump_z z|] )
+ | Mc.Inr n ->
+ EConstr.mkApp
+ ( Lazy.force coq_Inr
+ , [|Lazy.force coq_Z; Lazy.force coq_nat; dump_nat n|] ) ) |] )
+ | Mc.CInv t -> EConstr.mkApp (Lazy.force coq_CInv, [|dump_Rcst t|])
+ | Mc.COpp t -> EConstr.mkApp (Lazy.force coq_COpp, [|dump_Rcst t|])
+
+let rec dump_list typ dump_elt l =
+ match l with
+ | [] -> EConstr.mkApp (Lazy.force coq_nil, [|typ|])
+ | e :: l ->
+ EConstr.mkApp
+ (Lazy.force coq_cons, [|typ; dump_elt e; dump_list typ dump_elt l|])
- let rec pp_Rcst o cst =
- match cst with
- | Mc.C0 -> output_string o "C0"
- | Mc.C1 -> output_string o "C1"
- | Mc.CQ q -> output_string o "CQ _"
- | Mc.CZ z -> pp_z o z
- | Mc.CPlus (x, y) -> Printf.fprintf o "(%a + %a)" pp_Rcst x pp_Rcst y
- | Mc.CMinus (x, y) -> Printf.fprintf o "(%a - %a)" pp_Rcst x pp_Rcst y
- | Mc.CMult (x, y) -> Printf.fprintf o "(%a * %a)" pp_Rcst x pp_Rcst y
- | Mc.CPow (x, y) -> Printf.fprintf o "(%a ^ _)" pp_Rcst x
- | Mc.CInv t -> Printf.fprintf o "(/ %a)" pp_Rcst t
- | Mc.COpp t -> Printf.fprintf o "(- %a)" pp_Rcst t
-
- let rec dump_Rcst cst =
- match cst with
- | Mc.C0 -> Lazy.force coq_C0
- | Mc.C1 -> Lazy.force coq_C1
- | Mc.CQ q -> EConstr.mkApp (Lazy.force coq_CQ, [|dump_q q|])
- | Mc.CZ z -> EConstr.mkApp (Lazy.force coq_CZ, [|dump_z z|])
- | Mc.CPlus (x, y) ->
- EConstr.mkApp (Lazy.force coq_CPlus, [|dump_Rcst x; dump_Rcst y|])
- | Mc.CMinus (x, y) ->
- EConstr.mkApp (Lazy.force coq_CMinus, [|dump_Rcst x; dump_Rcst y|])
- | Mc.CMult (x, y) ->
- EConstr.mkApp (Lazy.force coq_CMult, [|dump_Rcst x; dump_Rcst y|])
- | Mc.CPow (x, y) ->
- EConstr.mkApp
- ( Lazy.force coq_CPow
- , [| dump_Rcst x
- ; ( match y with
- | Mc.Inl z ->
- EConstr.mkApp
- ( Lazy.force coq_Inl
- , [|Lazy.force coq_Z; Lazy.force coq_nat; dump_z z|] )
- | Mc.Inr n ->
- EConstr.mkApp
- ( Lazy.force coq_Inr
- , [|Lazy.force coq_Z; Lazy.force coq_nat; dump_nat n|] ) ) |]
- )
- | Mc.CInv t -> EConstr.mkApp (Lazy.force coq_CInv, [|dump_Rcst t|])
- | Mc.COpp t -> EConstr.mkApp (Lazy.force coq_COpp, [|dump_Rcst t|])
-
- let rec dump_list typ dump_elt l =
+let pp_list op cl elt o l =
+ let rec _pp o l =
match l with
- | [] -> EConstr.mkApp (Lazy.force coq_nil, [|typ|])
- | e :: l ->
- EConstr.mkApp
- (Lazy.force coq_cons, [|typ; dump_elt e; dump_list typ dump_elt l|])
-
- let pp_list op cl elt o l =
- let rec _pp o l =
- match l with
- | [] -> ()
- | [e] -> Printf.fprintf o "%a" elt e
- | e :: l -> Printf.fprintf o "%a ,%a" elt e _pp l
- in
- Printf.fprintf o "%s%a%s" op _pp l cl
+ | [] -> ()
+ | [e] -> Printf.fprintf o "%a" elt e
+ | e :: l -> Printf.fprintf o "%a ,%a" elt e _pp l
+ in
+ Printf.fprintf o "%s%a%s" op _pp l cl
- let dump_var = dump_positive
+let dump_var = dump_positive
- let dump_expr typ dump_z e =
- let rec dump_expr e =
- match e with
- | Mc.PEX n -> EConstr.mkApp (Lazy.force coq_PEX, [|typ; dump_var n|])
- | Mc.PEc z -> EConstr.mkApp (Lazy.force coq_PEc, [|typ; dump_z z|])
- | Mc.PEadd (e1, e2) ->
- EConstr.mkApp (Lazy.force coq_PEadd, [|typ; dump_expr e1; dump_expr e2|])
- | Mc.PEsub (e1, e2) ->
- EConstr.mkApp (Lazy.force coq_PEsub, [|typ; dump_expr e1; dump_expr e2|])
- | Mc.PEopp e -> EConstr.mkApp (Lazy.force coq_PEopp, [|typ; dump_expr e|])
- | Mc.PEmul (e1, e2) ->
- EConstr.mkApp (Lazy.force coq_PEmul, [|typ; dump_expr e1; dump_expr e2|])
- | Mc.PEpow (e, n) ->
- EConstr.mkApp (Lazy.force coq_PEpow, [|typ; dump_expr e; dump_n n|])
- in
- dump_expr e
+let dump_expr typ dump_z e =
+ let rec dump_expr e =
+ match e with
+ | Mc.PEX n -> EConstr.mkApp (Lazy.force coq_PEX, [|typ; dump_var n|])
+ | Mc.PEc z -> EConstr.mkApp (Lazy.force coq_PEc, [|typ; dump_z z|])
+ | Mc.PEadd (e1, e2) ->
+ EConstr.mkApp (Lazy.force coq_PEadd, [|typ; dump_expr e1; dump_expr e2|])
+ | Mc.PEsub (e1, e2) ->
+ EConstr.mkApp (Lazy.force coq_PEsub, [|typ; dump_expr e1; dump_expr e2|])
+ | Mc.PEopp e -> EConstr.mkApp (Lazy.force coq_PEopp, [|typ; dump_expr e|])
+ | Mc.PEmul (e1, e2) ->
+ EConstr.mkApp (Lazy.force coq_PEmul, [|typ; dump_expr e1; dump_expr e2|])
+ | Mc.PEpow (e, n) ->
+ EConstr.mkApp (Lazy.force coq_PEpow, [|typ; dump_expr e; dump_n n|])
+ in
+ dump_expr e
- let dump_pol typ dump_c e =
- let rec dump_pol e =
- match e with
- | Mc.Pc n -> EConstr.mkApp (Lazy.force coq_Pc, [|typ; dump_c n|])
- | Mc.Pinj (p, pol) ->
- EConstr.mkApp
- (Lazy.force coq_Pinj, [|typ; dump_positive p; dump_pol pol|])
- | Mc.PX (pol1, p, pol2) ->
- EConstr.mkApp
- ( Lazy.force coq_PX
- , [|typ; dump_pol pol1; dump_positive p; dump_pol pol2|] )
- in
- dump_pol e
-
- let pp_pol pp_c o e =
- let rec pp_pol o e =
- match e with
- | Mc.Pc n -> Printf.fprintf o "Pc %a" pp_c n
- | Mc.Pinj (p, pol) ->
- Printf.fprintf o "Pinj(%a,%a)" pp_positive p pp_pol pol
- | Mc.PX (pol1, p, pol2) ->
- Printf.fprintf o "PX(%a,%a,%a)" pp_pol pol1 pp_positive p pp_pol pol2
- in
- pp_pol o e
-
- (* let pp_clause pp_c o (f: 'cst clause) =
- List.iter (fun ((p,_),(t,_)) -> Printf.fprintf o "(%a @%a)" (pp_pol pp_c) p Tag.pp t) f *)
-
- let pp_clause_tag o (f : 'cst clause) =
- List.iter (fun ((p, _), (t, _)) -> Printf.fprintf o "(_ @%a)" Tag.pp t) f
-
- (* let pp_cnf pp_c o (f:'cst cnf) =
- List.iter (fun l -> Printf.fprintf o "[%a]" (pp_clause pp_c) l) f *)
-
- let pp_cnf_tag o (f : 'cst cnf) =
- List.iter (fun l -> Printf.fprintf o "[%a]" pp_clause_tag l) f
-
- let dump_psatz typ dump_z e =
- let z = Lazy.force typ in
- let rec dump_cone e =
- match e with
- | Mc.PsatzIn n -> EConstr.mkApp (Lazy.force coq_PsatzIn, [|z; dump_nat n|])
- | Mc.PsatzMulC (e, c) ->
- EConstr.mkApp
- (Lazy.force coq_PsatzMultC, [|z; dump_pol z dump_z e; dump_cone c|])
- | Mc.PsatzSquare e ->
- EConstr.mkApp (Lazy.force coq_PsatzSquare, [|z; dump_pol z dump_z e|])
- | Mc.PsatzAdd (e1, e2) ->
- EConstr.mkApp
- (Lazy.force coq_PsatzAdd, [|z; dump_cone e1; dump_cone e2|])
- | Mc.PsatzMulE (e1, e2) ->
- EConstr.mkApp
- (Lazy.force coq_PsatzMulE, [|z; dump_cone e1; dump_cone e2|])
- | Mc.PsatzC p -> EConstr.mkApp (Lazy.force coq_PsatzC, [|z; dump_z p|])
- | Mc.PsatzZ -> EConstr.mkApp (Lazy.force coq_PsatzZ, [|z|])
- in
- dump_cone e
-
- let pp_psatz pp_z o e =
- let rec pp_cone o e =
- match e with
- | Mc.PsatzIn n -> Printf.fprintf o "(In %a)%%nat" pp_nat n
- | Mc.PsatzMulC (e, c) ->
- Printf.fprintf o "( %a [*] %a)" (pp_pol pp_z) e pp_cone c
- | Mc.PsatzSquare e -> Printf.fprintf o "(%a^2)" (pp_pol pp_z) e
- | Mc.PsatzAdd (e1, e2) ->
- Printf.fprintf o "(%a [+] %a)" pp_cone e1 pp_cone e2
- | Mc.PsatzMulE (e1, e2) ->
- Printf.fprintf o "(%a [*] %a)" pp_cone e1 pp_cone e2
- | Mc.PsatzC p -> Printf.fprintf o "(%a)%%positive" pp_z p
- | Mc.PsatzZ -> Printf.fprintf o "0"
- in
- pp_cone o e
+let dump_pol typ dump_c e =
+ let rec dump_pol e =
+ match e with
+ | Mc.Pc n -> EConstr.mkApp (Lazy.force coq_Pc, [|typ; dump_c n|])
+ | Mc.Pinj (p, pol) ->
+ EConstr.mkApp (Lazy.force coq_Pinj, [|typ; dump_positive p; dump_pol pol|])
+ | Mc.PX (pol1, p, pol2) ->
+ EConstr.mkApp
+ ( Lazy.force coq_PX
+ , [|typ; dump_pol pol1; dump_positive p; dump_pol pol2|] )
+ in
+ dump_pol e
- let dump_op = function
- | Mc.OpEq -> Lazy.force coq_OpEq
- | Mc.OpNEq -> Lazy.force coq_OpNEq
- | Mc.OpLe -> Lazy.force coq_OpLe
- | Mc.OpGe -> Lazy.force coq_OpGe
- | Mc.OpGt -> Lazy.force coq_OpGt
- | Mc.OpLt -> Lazy.force coq_OpLt
+let pp_pol pp_c o e =
+ let rec pp_pol o e =
+ match e with
+ | Mc.Pc n -> Printf.fprintf o "Pc %a" pp_c n
+ | Mc.Pinj (p, pol) ->
+ Printf.fprintf o "Pinj(%a,%a)" pp_positive p pp_pol pol
+ | Mc.PX (pol1, p, pol2) ->
+ Printf.fprintf o "PX(%a,%a,%a)" pp_pol pol1 pp_positive p pp_pol pol2
+ in
+ pp_pol o e
- let dump_cstr typ dump_constant {Mc.flhs = e1; Mc.fop = o; Mc.frhs = e2} =
- EConstr.mkApp
- ( Lazy.force coq_Build
- , [| typ
- ; dump_expr typ dump_constant e1
- ; dump_op o
- ; dump_expr typ dump_constant e2 |] )
+(* let pp_clause pp_c o (f: 'cst clause) =
+ List.iter (fun ((p,_),(t,_)) -> Printf.fprintf o "(%a @%a)" (pp_pol pp_c) p Tag.pp t) f *)
- let assoc_const sigma x l =
- try
- snd
- (List.find (fun (x', y) -> EConstr.eq_constr sigma x (Lazy.force x')) l)
- with Not_found -> raise ParseError
-
- let zop_table_prop =
- [ (coq_Zgt, Mc.OpGt)
- ; (coq_Zge, Mc.OpGe)
- ; (coq_Zlt, Mc.OpLt)
- ; (coq_Zle, Mc.OpLe) ]
-
- let zop_table_bool =
- [ (coq_Zgtb, Mc.OpGt)
- ; (coq_Zgeb, Mc.OpGe)
- ; (coq_Zltb, Mc.OpLt)
- ; (coq_Zleb, Mc.OpLe)
- ; (coq_Zeqb, Mc.OpEq) ]
-
- let rop_table_prop =
- [ (coq_Rgt, Mc.OpGt)
- ; (coq_Rge, Mc.OpGe)
- ; (coq_Rlt, Mc.OpLt)
- ; (coq_Rle, Mc.OpLe) ]
-
- let rop_table_bool = []
-
- let qop_table_prop =
- [(coq_Qlt, Mc.OpLt); (coq_Qle, Mc.OpLe); (coq_Qeq, Mc.OpEq)]
-
- let qop_table_bool = []
-
- type gl = {env : Environ.env; sigma : Evd.evar_map}
-
- let is_convertible gl t1 t2 = Reductionops.is_conv gl.env gl.sigma t1 t2
-
- let parse_operator table_prop table_bool has_equality typ gl k (op, args) =
- let sigma = gl.sigma in
- match args with
- | [|a1; a2|] ->
- ( assoc_const sigma op
- (match k with Mc.IsProp -> table_prop | Mc.IsBool -> table_bool)
- , a1
- , a2 )
- | [|ty; a1; a2|] ->
- if
- has_equality
- && EConstr.eq_constr sigma op (Lazy.force coq_eq)
- && is_convertible gl ty (Lazy.force typ)
- then (Mc.OpEq, args.(1), args.(2))
- else raise ParseError
- | _ -> raise ParseError
+let pp_clause_tag o (f : 'cst clause) =
+ List.iter (fun ((p, _), (t, _)) -> Printf.fprintf o "(_ @%a)" Tag.pp t) f
- let parse_zop = parse_operator zop_table_prop zop_table_bool true coq_Z
- let parse_rop = parse_operator rop_table_prop [] true coq_R
- let parse_qop = parse_operator qop_table_prop [] false coq_R
+(* let pp_cnf pp_c o (f:'cst cnf) =
+ List.iter (fun l -> Printf.fprintf o "[%a]" (pp_clause pp_c) l) f *)
- type 'a op =
- | Binop of ('a Mc.pExpr -> 'a Mc.pExpr -> 'a Mc.pExpr)
- | Opp
- | Power
- | Ukn of string
+let pp_cnf_tag o (f : 'cst cnf) =
+ List.iter (fun l -> Printf.fprintf o "[%a]" pp_clause_tag l) f
- let assoc_ops sigma x l =
- try
- snd
- (List.find (fun (x', y) -> EConstr.eq_constr sigma x (Lazy.force x')) l)
- with Not_found -> Ukn "Oups"
+let dump_psatz typ dump_z e =
+ let z = Lazy.force typ in
+ let rec dump_cone e =
+ match e with
+ | Mc.PsatzIn n -> EConstr.mkApp (Lazy.force coq_PsatzIn, [|z; dump_nat n|])
+ | Mc.PsatzMulC (e, c) ->
+ EConstr.mkApp
+ (Lazy.force coq_PsatzMultC, [|z; dump_pol z dump_z e; dump_cone c|])
+ | Mc.PsatzSquare e ->
+ EConstr.mkApp (Lazy.force coq_PsatzSquare, [|z; dump_pol z dump_z e|])
+ | Mc.PsatzAdd (e1, e2) ->
+ EConstr.mkApp (Lazy.force coq_PsatzAdd, [|z; dump_cone e1; dump_cone e2|])
+ | Mc.PsatzMulE (e1, e2) ->
+ EConstr.mkApp (Lazy.force coq_PsatzMulE, [|z; dump_cone e1; dump_cone e2|])
+ | Mc.PsatzC p -> EConstr.mkApp (Lazy.force coq_PsatzC, [|z; dump_z p|])
+ | Mc.PsatzZ -> EConstr.mkApp (Lazy.force coq_PsatzZ, [|z|])
+ in
+ dump_cone e
- (**
+let pp_psatz pp_z o e =
+ let rec pp_cone o e =
+ match e with
+ | Mc.PsatzIn n -> Printf.fprintf o "(In %a)%%nat" pp_nat n
+ | Mc.PsatzMulC (e, c) ->
+ Printf.fprintf o "( %a [*] %a)" (pp_pol pp_z) e pp_cone c
+ | Mc.PsatzSquare e -> Printf.fprintf o "(%a^2)" (pp_pol pp_z) e
+ | Mc.PsatzAdd (e1, e2) ->
+ Printf.fprintf o "(%a [+] %a)" pp_cone e1 pp_cone e2
+ | Mc.PsatzMulE (e1, e2) ->
+ Printf.fprintf o "(%a [*] %a)" pp_cone e1 pp_cone e2
+ | Mc.PsatzC p -> Printf.fprintf o "(%a)%%positive" pp_z p
+ | Mc.PsatzZ -> Printf.fprintf o "0"
+ in
+ pp_cone o e
+
+let dump_op = function
+ | Mc.OpEq -> Lazy.force coq_OpEq
+ | Mc.OpNEq -> Lazy.force coq_OpNEq
+ | Mc.OpLe -> Lazy.force coq_OpLe
+ | Mc.OpGe -> Lazy.force coq_OpGe
+ | Mc.OpGt -> Lazy.force coq_OpGt
+ | Mc.OpLt -> Lazy.force coq_OpLt
+
+let dump_cstr typ dump_constant {Mc.flhs = e1; Mc.fop = o; Mc.frhs = e2} =
+ EConstr.mkApp
+ ( Lazy.force coq_Build
+ , [| typ
+ ; dump_expr typ dump_constant e1
+ ; dump_op o
+ ; dump_expr typ dump_constant e2 |] )
+
+let assoc_const sigma x l =
+ try
+ snd (List.find (fun (x', y) -> EConstr.eq_constr sigma x (Lazy.force x')) l)
+ with Not_found -> raise ParseError
+
+let zop_table_prop =
+ [ (coq_Zgt, Mc.OpGt)
+ ; (coq_Zge, Mc.OpGe)
+ ; (coq_Zlt, Mc.OpLt)
+ ; (coq_Zle, Mc.OpLe) ]
+
+let zop_table_bool =
+ [ (coq_Zgtb, Mc.OpGt)
+ ; (coq_Zgeb, Mc.OpGe)
+ ; (coq_Zltb, Mc.OpLt)
+ ; (coq_Zleb, Mc.OpLe)
+ ; (coq_Zeqb, Mc.OpEq) ]
+
+let rop_table_prop =
+ [ (coq_Rgt, Mc.OpGt)
+ ; (coq_Rge, Mc.OpGe)
+ ; (coq_Rlt, Mc.OpLt)
+ ; (coq_Rle, Mc.OpLe) ]
+
+let rop_table_bool = []
+let qop_table_prop = [(coq_Qlt, Mc.OpLt); (coq_Qle, Mc.OpLe); (coq_Qeq, Mc.OpEq)]
+let qop_table_bool = []
+
+type gl = Environ.env * Evd.evar_map
+
+let is_convertible env sigma t1 t2 = Reductionops.is_conv env sigma t1 t2
+
+let parse_operator table_prop table_bool has_equality typ (env, sigma) k
+ (op, args) =
+ match args with
+ | [|a1; a2|] ->
+ ( assoc_const sigma op
+ (match k with Mc.IsProp -> table_prop | Mc.IsBool -> table_bool)
+ , a1
+ , a2 )
+ | [|ty; a1; a2|] ->
+ if
+ has_equality
+ && EConstr.eq_constr sigma op (Lazy.force coq_eq)
+ && is_convertible env sigma ty (Lazy.force typ)
+ then (Mc.OpEq, args.(1), args.(2))
+ else raise ParseError
+ | _ -> raise ParseError
+
+let parse_zop = parse_operator zop_table_prop zop_table_bool true coq_Z
+let parse_rop = parse_operator rop_table_prop [] true coq_R
+let parse_qop = parse_operator qop_table_prop [] false coq_R
+
+type 'a op =
+ | Binop of ('a Mc.pExpr -> 'a Mc.pExpr -> 'a Mc.pExpr)
+ | Opp
+ | Power
+ | Ukn of string
+
+let assoc_ops sigma x l =
+ try
+ snd (List.find (fun (x', y) -> EConstr.eq_constr sigma x (Lazy.force x')) l)
+ with Not_found -> Ukn "Oups"
+
+(**
* MODULE: Env is for environment.
*)
- module Env = struct
- type t =
- { vars : (EConstr.t * Mc.kind) list
- ; (* The list represents a mapping from EConstr.t to indexes. *)
- gl : gl
- (* The evar_map may be updated due to unification of universes *) }
-
- let empty gl = {vars = []; gl}
-
- (** [eq_constr gl x y] returns an updated [gl] if x and y can be unified *)
- let eq_constr gl x y =
- let evd = gl.sigma in
- match EConstr.eq_constr_universes_proj gl.env evd x y with
- | Some csts -> (
- let csts =
- UnivProblem.to_constraints ~force_weak:false (Evd.universes evd) csts
- in
- match Evd.add_constraints evd csts with
- | evd -> Some {gl with sigma = evd}
- | exception Univ.UniverseInconsistency _ -> None )
- | None -> None
-
- let compute_rank_add env v is_prop =
- let rec _add gl vars n v =
- match vars with
- | [] -> (gl, [(v, is_prop)], n)
- | (e, b) :: l -> (
- match eq_constr gl e v with
- | Some gl' -> (gl', vars, n)
- | None ->
- let gl, l', n = _add gl l (n + 1) v in
- (gl, (e, b) :: l', n) )
- in
- let gl', vars', n = _add env.gl env.vars 1 v in
- ({vars = vars'; gl = gl'}, CamlToCoq.positive n)
-
- let get_rank env v =
- let gl = env.gl in
- let rec _get_rank env n =
- match env with
- | [] -> raise (Invalid_argument "get_rank")
- | (e, _) :: l -> (
- match eq_constr gl e v with Some _ -> n | None -> _get_rank l (n + 1)
- )
- in
- _get_rank env.vars 1
-
- let elements env = env.vars
-
- (* let string_of_env gl env =
- let rec string_of_env i env acc =
- match env with
- | [] -> acc
- | e::env -> string_of_env (i+1) env
- (IMap.add i
- (Pp.string_of_ppcmds
- (Printer.pr_econstr_env gl.env gl.sigma e)) acc) in
- string_of_env 1 env IMap.empty
- *)
- let pp gl env =
- let ppl =
- List.mapi
- (fun i (e, _) ->
- Pp.str "x"
- ++ Pp.int (i + 1)
- ++ Pp.str ":"
- ++ Printer.pr_econstr_env gl.env gl.sigma e)
- env
+module Env = struct
+ type t =
+ { vars : (EConstr.t * Mc.kind) list
+ ; (* The list represents a mapping from EConstr.t to indexes. *)
+ gl : gl (* The evar_map may be updated due to unification of universes *)
+ }
+
+ let empty gl = {vars = []; gl}
+
+ (** [eq_constr gl x y] returns an updated [gl] if x and y can be unified *)
+ let eq_constr (env, sigma) x y =
+ match EConstr.eq_constr_universes_proj env sigma x y with
+ | Some csts -> (
+ let csts =
+ UnivProblem.to_constraints ~force_weak:false (Evd.universes sigma) csts
in
- List.fold_right (fun e p -> e ++ Pp.str " ; " ++ p) ppl (Pp.str "\n")
- end
+ match Evd.add_constraints sigma csts with
+ | sigma -> Some (env, sigma)
+ | exception Univ.UniverseInconsistency _ -> None )
+ | None -> None
+
+ let compute_rank_add env v is_prop =
+ let rec _add gl vars n v =
+ match vars with
+ | [] -> (gl, [(v, is_prop)], n)
+ | (e, b) :: l -> (
+ match eq_constr gl e v with
+ | Some gl' -> (gl', vars, n)
+ | None ->
+ let gl, l', n = _add gl l (n + 1) v in
+ (gl, (e, b) :: l', n) )
+ in
+ let gl', vars', n = _add env.gl env.vars 1 v in
+ ({vars = vars'; gl = gl'}, CamlToCoq.positive n)
+
+ let get_rank env v =
+ let gl = env.gl in
+ let rec _get_rank env n =
+ match env with
+ | [] -> raise (Invalid_argument "get_rank")
+ | (e, _) :: l -> (
+ match eq_constr gl e v with Some _ -> n | None -> _get_rank l (n + 1) )
+ in
+ _get_rank env.vars 1
+
+ let elements env = env.vars
+
+ (* let string_of_env gl env =
+ let rec string_of_env i env acc =
+ match env with
+ | [] -> acc
+ | e::env -> string_of_env (i+1) env
+ (IMap.add i
+ (Pp.string_of_ppcmds
+ (Printer.pr_econstr_env gl.env gl.sigma e)) acc) in
+ string_of_env 1 env IMap.empty
+ *)
+ let pp (genv, sigma) env =
+ let ppl =
+ List.mapi
+ (fun i (e, _) ->
+ Pp.str "x"
+ ++ Pp.int (i + 1)
+ ++ Pp.str ":"
+ ++ Printer.pr_econstr_env genv sigma e)
+ env
+ in
+ List.fold_right (fun e p -> e ++ Pp.str " ; " ++ p) ppl (Pp.str "\n")
+end
- (* MODULE END: Env *)
+(* MODULE END: Env *)
- (**
+(**
* This is the big generic function for expression parsers.
*)
- let parse_expr gl parse_constant parse_exp ops_spec env term =
- if debug then
- Feedback.msg_debug
- (Pp.str "parse_expr: " ++ Printer.pr_leconstr_env gl.env gl.sigma term);
- let parse_variable env term =
- let env, n = Env.compute_rank_add env term Mc.IsBool in
- (Mc.PEX n, env)
+let parse_expr (genv, sigma) parse_constant parse_exp ops_spec env term =
+ if debug then
+ Feedback.msg_debug
+ (Pp.str "parse_expr: " ++ Printer.pr_leconstr_env genv sigma term);
+ let parse_variable env term =
+ let env, n = Env.compute_rank_add env term Mc.IsBool in
+ (Mc.PEX n, env)
+ in
+ let rec parse_expr env term =
+ let combine env op (t1, t2) =
+ let expr1, env = parse_expr env t1 in
+ let expr2, env = parse_expr env t2 in
+ (op expr1 expr2, env)
in
- let rec parse_expr env term =
- let combine env op (t1, t2) =
- let expr1, env = parse_expr env t1 in
- let expr2, env = parse_expr env t2 in
- (op expr1 expr2, env)
- in
- try (Mc.PEc (parse_constant gl term), env)
- with ParseError -> (
- match EConstr.kind gl.sigma term with
- | App (t, args) -> (
- match EConstr.kind gl.sigma t with
- | Const c -> (
- match assoc_ops gl.sigma t ops_spec with
- | Binop f -> combine env f (args.(0), args.(1))
- | Opp ->
+ try (Mc.PEc (parse_constant (genv, sigma) term), env)
+ with ParseError -> (
+ match EConstr.kind sigma term with
+ | App (t, args) -> (
+ match EConstr.kind sigma t with
+ | Const c -> (
+ match assoc_ops sigma t ops_spec with
+ | Binop f -> combine env f (args.(0), args.(1))
+ | Opp ->
+ let expr, env = parse_expr env args.(0) in
+ (Mc.PEopp expr, env)
+ | Power -> (
+ try
let expr, env = parse_expr env args.(0) in
- (Mc.PEopp expr, env)
- | Power -> (
- try
- let expr, env = parse_expr env args.(0) in
- let power = parse_exp expr args.(1) in
- (power, env)
- with ParseError ->
- (* if the exponent is a variable *)
- let env, n = Env.compute_rank_add env term Mc.IsBool in
- (Mc.PEX n, env) )
- | Ukn s ->
- if debug then (
- Printf.printf "unknown op: %s\n" s;
- flush stdout );
+ let power = parse_exp expr args.(1) in
+ (power, env)
+ with ParseError ->
+ (* if the exponent is a variable *)
let env, n = Env.compute_rank_add env term Mc.IsBool in
(Mc.PEX n, env) )
- | _ -> parse_variable env term )
+ | Ukn s ->
+ if debug then (
+ Printf.printf "unknown op: %s\n" s;
+ flush stdout );
+ let env, n = Env.compute_rank_add env term Mc.IsBool in
+ (Mc.PEX n, env) )
| _ -> parse_variable env term )
- in
- parse_expr env term
-
- let zop_spec =
- [ (coq_Zplus, Binop (fun x y -> Mc.PEadd (x, y)))
- ; (coq_Zminus, Binop (fun x y -> Mc.PEsub (x, y)))
- ; (coq_Zmult, Binop (fun x y -> Mc.PEmul (x, y)))
- ; (coq_Zopp, Opp)
- ; (coq_Zpower, Power) ]
-
- let qop_spec =
- [ (coq_Qplus, Binop (fun x y -> Mc.PEadd (x, y)))
- ; (coq_Qminus, Binop (fun x y -> Mc.PEsub (x, y)))
- ; (coq_Qmult, Binop (fun x y -> Mc.PEmul (x, y)))
- ; (coq_Qopp, Opp)
- ; (coq_Qpower, Power) ]
-
- let rop_spec =
- [ (coq_Rplus, Binop (fun x y -> Mc.PEadd (x, y)))
- ; (coq_Rminus, Binop (fun x y -> Mc.PEsub (x, y)))
- ; (coq_Rmult, Binop (fun x y -> Mc.PEmul (x, y)))
- ; (coq_Ropp, Opp)
- ; (coq_Rpower, Power) ]
-
- let parse_constant parse gl t = parse gl.sigma t
-
- (** [parse_more_constant parse gl t] returns the reification of term [t].
+ | _ -> parse_variable env term )
+ in
+ parse_expr env term
+
+let zop_spec =
+ [ (coq_Zplus, Binop (fun x y -> Mc.PEadd (x, y)))
+ ; (coq_Zminus, Binop (fun x y -> Mc.PEsub (x, y)))
+ ; (coq_Zmult, Binop (fun x y -> Mc.PEmul (x, y)))
+ ; (coq_Zopp, Opp)
+ ; (coq_Zpower, Power) ]
+
+let qop_spec =
+ [ (coq_Qplus, Binop (fun x y -> Mc.PEadd (x, y)))
+ ; (coq_Qminus, Binop (fun x y -> Mc.PEsub (x, y)))
+ ; (coq_Qmult, Binop (fun x y -> Mc.PEmul (x, y)))
+ ; (coq_Qopp, Opp)
+ ; (coq_Qpower, Power) ]
+
+let rop_spec =
+ [ (coq_Rplus, Binop (fun x y -> Mc.PEadd (x, y)))
+ ; (coq_Rminus, Binop (fun x y -> Mc.PEsub (x, y)))
+ ; (coq_Rmult, Binop (fun x y -> Mc.PEmul (x, y)))
+ ; (coq_Ropp, Opp)
+ ; (coq_Rpower, Power) ]
+
+let parse_constant parse ((genv : Environ.env), sigma) t = parse sigma t
+
+(** [parse_more_constant parse gl t] returns the reification of term [t].
If [t] is a ground term, then it is first reduced to normal form
before using a 'syntactic' parser *)
- let parse_more_constant parse gl t =
- try parse gl t
- with ParseError ->
- if debug then Feedback.msg_debug Pp.(str "try harder");
- if is_ground_term gl.env gl.sigma t then
- parse gl (Redexpr.cbv_vm gl.env gl.sigma t)
- else raise ParseError
-
- let zconstant = parse_constant parse_z
- let qconstant = parse_constant parse_q
- let nconstant = parse_constant parse_nat
-
- (** [parse_more_zexpr parse_constant gl] improves the parsing of exponent
+let parse_more_constant parse (genv, sigma) t =
+ try parse (genv, sigma) t
+ with ParseError ->
+ if debug then Feedback.msg_debug Pp.(str "try harder");
+ if is_ground_term genv sigma t then
+ parse (genv, sigma) (Redexpr.cbv_vm genv sigma t)
+ else raise ParseError
+
+let zconstant = parse_constant parse_z
+let qconstant = parse_constant parse_q
+let nconstant = parse_constant parse_nat
+
+(** [parse_more_zexpr parse_constant gl] improves the parsing of exponent
which can be arithmetic expressions (without variables).
[parse_constant_expr] returns a constant if the argument is an expression without variables. *)
- let rec parse_zexpr gl =
- parse_expr gl zconstant
- (fun expr (x : EConstr.t) ->
- let z = parse_zconstant gl x in
- match z with
- | Mc.Zneg _ -> Mc.PEc Mc.Z0
- | _ -> Mc.PEpow (expr, Mc.Z.to_N z))
- zop_spec
-
- and parse_zconstant gl e =
- let e, _ = parse_zexpr gl (Env.empty gl) e in
- match Mc.zeval_const e with None -> raise ParseError | Some z -> z
-
- (* NB: R is a different story.
- Because it is axiomatised, reducing would not be effective.
- Therefore, there is a specific parser for constant over R
- *)
+let rec parse_zexpr gl =
+ parse_expr gl zconstant
+ (fun expr (x : EConstr.t) ->
+ let z = parse_zconstant gl x in
+ match z with
+ | Mc.Zneg _ -> Mc.PEc Mc.Z0
+ | _ -> Mc.PEpow (expr, Mc.Z.to_N z))
+ zop_spec
+
+and parse_zconstant gl e =
+ let e, _ = parse_zexpr gl (Env.empty gl) e in
+ match Mc.zeval_const e with None -> raise ParseError | Some z -> z
+
+(* NB: R is a different story.
+ Because it is axiomatised, reducing would not be effective.
+ Therefore, there is a specific parser for constant over R
+*)
- let rconst_assoc =
- [ (coq_Rplus, fun x y -> Mc.CPlus (x, y))
- ; (coq_Rminus, fun x y -> Mc.CMinus (x, y))
- ; (coq_Rmult, fun x y -> Mc.CMult (x, y))
- (* coq_Rdiv , (fun x y -> Mc.CMult(x,Mc.CInv y)) ;*) ]
+let rconst_assoc =
+ [ (coq_Rplus, fun x y -> Mc.CPlus (x, y))
+ ; (coq_Rminus, fun x y -> Mc.CMinus (x, y))
+ ; (coq_Rmult, fun x y -> Mc.CMult (x, y))
+ (* coq_Rdiv , (fun x y -> Mc.CMult(x,Mc.CInv y)) ;*) ]
- let rconstant gl term =
- let sigma = gl.sigma in
- let rec rconstant term =
- match EConstr.kind sigma term with
- | Const x ->
- if EConstr.eq_constr sigma term (Lazy.force coq_R0) then Mc.C0
- else if EConstr.eq_constr sigma term (Lazy.force coq_R1) then Mc.C1
- else raise ParseError
- | App (op, args) -> (
- try
- (* the evaluation order is important in the following *)
- let f = assoc_const sigma op rconst_assoc in
- let a = rconstant args.(0) in
- let b = rconstant args.(1) in
- f a b
- with ParseError -> (
- match op with
- | op when EConstr.eq_constr sigma op (Lazy.force coq_Rinv) ->
- let arg = rconstant args.(0) in
- if Mc.qeq_bool (Mc.q_of_Rcst arg) {Mc.qnum = Mc.Z0; Mc.qden = Mc.XH}
- then raise ParseError
- (* This is a division by zero -- no semantics *)
- else Mc.CInv arg
- | op when EConstr.eq_constr sigma op (Lazy.force coq_Rpower) ->
- Mc.CPow
- ( rconstant args.(0)
- , Mc.Inr (parse_more_constant nconstant gl args.(1)) )
- | op when EConstr.eq_constr sigma op (Lazy.force coq_IQR) ->
- Mc.CQ (qconstant gl args.(0))
- | op when EConstr.eq_constr sigma op (Lazy.force coq_IZR) ->
- Mc.CZ (parse_more_constant zconstant gl args.(0))
- | _ -> raise ParseError ) )
- | _ -> raise ParseError
- in
- rconstant term
-
- let rconstant gl term =
- if debug then
- Feedback.msg_debug
- ( Pp.str "rconstant: "
- ++ Printer.pr_leconstr_env gl.env gl.sigma term
- ++ fnl () );
- let res = rconstant gl term in
- if debug then (
- Printf.printf "rconstant -> %a\n" pp_Rcst res;
- flush stdout );
- res
+let rconstant (genv, sigma) term =
+ let rec rconstant term =
+ match EConstr.kind sigma term with
+ | Const x ->
+ if EConstr.eq_constr sigma term (Lazy.force coq_R0) then Mc.C0
+ else if EConstr.eq_constr sigma term (Lazy.force coq_R1) then Mc.C1
+ else raise ParseError
+ | App (op, args) -> (
+ try
+ (* the evaluation order is important in the following *)
+ let f = assoc_const sigma op rconst_assoc in
+ let a = rconstant args.(0) in
+ let b = rconstant args.(1) in
+ f a b
+ with ParseError -> (
+ match op with
+ | op when EConstr.eq_constr sigma op (Lazy.force coq_Rinv) ->
+ let arg = rconstant args.(0) in
+ if Mc.qeq_bool (Mc.q_of_Rcst arg) {Mc.qnum = Mc.Z0; Mc.qden = Mc.XH}
+ then raise ParseError (* This is a division by zero -- no semantics *)
+ else Mc.CInv arg
+ | op when EConstr.eq_constr sigma op (Lazy.force coq_Rpower) ->
+ Mc.CPow
+ ( rconstant args.(0)
+ , Mc.Inr (parse_more_constant nconstant (genv, sigma) args.(1)) )
+ | op when EConstr.eq_constr sigma op (Lazy.force coq_IQR) ->
+ Mc.CQ (qconstant (genv, sigma) args.(0))
+ | op when EConstr.eq_constr sigma op (Lazy.force coq_IZR) ->
+ Mc.CZ (parse_more_constant zconstant (genv, sigma) args.(0))
+ | _ -> raise ParseError ) )
+ | _ -> raise ParseError
+ in
+ rconstant term
+
+let rconstant (genv, sigma) term =
+ if debug then
+ Feedback.msg_debug
+ (Pp.str "rconstant: " ++ Printer.pr_leconstr_env genv sigma term ++ fnl ());
+ let res = rconstant (genv, sigma) term in
+ if debug then (
+ Printf.printf "rconstant -> %a\n" pp_Rcst res;
+ flush stdout );
+ res
- let parse_qexpr gl =
- parse_expr gl qconstant
- (fun expr x ->
- let exp = zconstant gl x in
- match exp with
- | Mc.Zneg _ -> (
- match expr with
- | Mc.PEc q -> Mc.PEc (Mc.qpower q exp)
- | _ -> raise ParseError )
- | _ ->
- let exp = Mc.Z.to_N exp in
- Mc.PEpow (expr, exp))
- qop_spec
-
- let parse_rexpr gl =
- parse_expr gl rconstant
- (fun expr x ->
- let exp = Mc.N.of_nat (parse_nat gl.sigma x) in
+let parse_qexpr gl =
+ parse_expr gl qconstant
+ (fun expr x ->
+ let exp = zconstant gl x in
+ match exp with
+ | Mc.Zneg _ -> (
+ match expr with
+ | Mc.PEc q -> Mc.PEc (Mc.qpower q exp)
+ | _ -> raise ParseError )
+ | _ ->
+ let exp = Mc.Z.to_N exp in
Mc.PEpow (expr, exp))
- rop_spec
-
- let parse_arith parse_op parse_expr (k : Mc.kind) env cstr gl =
- let sigma = gl.sigma in
- if debug then
- Feedback.msg_debug
- ( Pp.str "parse_arith: "
- ++ Printer.pr_leconstr_env gl.env sigma cstr
- ++ fnl () );
- match EConstr.kind sigma cstr with
- | App (op, args) ->
- let op, lhs, rhs = parse_op gl k (op, args) in
- let e1, env = parse_expr gl env lhs in
- let e2, env = parse_expr gl env rhs in
- ({Mc.flhs = e1; Mc.fop = op; Mc.frhs = e2}, env)
- | _ -> failwith "error : parse_arith(2)"
-
- let parse_zarith = parse_arith parse_zop parse_zexpr
- let parse_qarith = parse_arith parse_qop parse_qexpr
- let parse_rarith = parse_arith parse_rop parse_rexpr
-
- (* generic parsing of arithmetic expressions *)
-
- let mkAND b f1 f2 = Mc.AND (b, f1, f2)
- let mkOR b f1 f2 = Mc.OR (b, f1, f2)
- let mkIff b f1 f2 = Mc.IFF (b, f1, f2)
- let mkIMPL b f1 f2 = Mc.IMPL (b, f1, None, f2)
- let mkEQ f1 f2 = Mc.EQ (f1, f2)
-
- let mkformula_binary b g term f1 f2 =
- match (f1, f2) with
- | Mc.X (b1, _), Mc.X (b2, _) -> Mc.X (b, term)
- | _ -> g f1 f2
+ qop_spec
+
+let parse_rexpr (genv, sigma) =
+ parse_expr (genv, sigma) rconstant
+ (fun expr x ->
+ let exp = Mc.N.of_nat (parse_nat sigma x) in
+ Mc.PEpow (expr, exp))
+ rop_spec
+
+let parse_arith parse_op parse_expr (k : Mc.kind) env cstr (genv, sigma) =
+ if debug then
+ Feedback.msg_debug
+ ( Pp.str "parse_arith: "
+ ++ Printer.pr_leconstr_env genv sigma cstr
+ ++ fnl () );
+ match EConstr.kind sigma cstr with
+ | App (op, args) ->
+ let op, lhs, rhs = parse_op (genv, sigma) k (op, args) in
+ let e1, env = parse_expr (genv, sigma) env lhs in
+ let e2, env = parse_expr (genv, sigma) env rhs in
+ ({Mc.flhs = e1; Mc.fop = op; Mc.frhs = e2}, env)
+ | _ -> failwith "error : parse_arith(2)"
+
+let parse_zarith = parse_arith parse_zop parse_zexpr
+let parse_qarith = parse_arith parse_qop parse_qexpr
+let parse_rarith = parse_arith parse_rop parse_rexpr
+
+(* generic parsing of arithmetic expressions *)
+
+let mkAND b f1 f2 = Mc.AND (b, f1, f2)
+let mkOR b f1 f2 = Mc.OR (b, f1, f2)
+let mkIff b f1 f2 = Mc.IFF (b, f1, f2)
+let mkIMPL b f1 f2 = Mc.IMPL (b, f1, None, f2)
+let mkEQ f1 f2 = Mc.EQ (f1, f2)
+
+let mkformula_binary b g term f1 f2 =
+ match (f1, f2) with
+ | Mc.X (b1, _), Mc.X (b2, _) -> Mc.X (b, term)
+ | _ -> g f1 f2
- (**
+(**
* This is the big generic function for formula parsers.
*)
- let is_prop env sigma term =
- let sort = Retyping.get_sort_of env sigma term in
- Sorts.is_prop sort
+let is_prop env sigma term =
+ let sort = Retyping.get_sort_of env sigma term in
+ Sorts.is_prop sort
- type formula_op =
- { op_and : EConstr.t
- ; op_or : EConstr.t
- ; op_iff : EConstr.t
- ; op_not : EConstr.t
- ; op_tt : EConstr.t
- ; op_ff : EConstr.t }
+type formula_op =
+ { op_and : EConstr.t
+ ; op_or : EConstr.t
+ ; op_iff : EConstr.t
+ ; op_not : EConstr.t
+ ; op_tt : EConstr.t
+ ; op_ff : EConstr.t }
- let prop_op =
- lazy
- { op_and = Lazy.force coq_and
- ; op_or = Lazy.force coq_or
- ; op_iff = Lazy.force coq_iff
- ; op_not = Lazy.force coq_not
- ; op_tt = Lazy.force coq_True
- ; op_ff = Lazy.force coq_False }
-
- let bool_op =
- lazy
- { op_and = Lazy.force coq_andb
- ; op_or = Lazy.force coq_orb
- ; op_iff = Lazy.force coq_eqb
- ; op_not = Lazy.force coq_negb
- ; op_tt = Lazy.force coq_true
- ; op_ff = Lazy.force coq_false }
-
- let parse_formula gl parse_atom env tg term =
- let sigma = gl.sigma in
- let parse_atom b env tg t =
- try
- let at, env = parse_atom b env t gl in
- (Mc.A (b, at, (tg, t)), env, Tag.next tg)
- with ParseError -> (Mc.X (b, t), env, tg)
- in
- let prop_op = Lazy.force prop_op in
- let bool_op = Lazy.force bool_op in
- let eq = Lazy.force coq_eq in
- let bool = Lazy.force coq_bool in
- let rec xparse_formula op k env tg term =
- match EConstr.kind sigma term with
- | App (l, rst) -> (
- match rst with
- | [|a; b|] when EConstr.eq_constr sigma l op.op_and ->
- let f, env, tg = xparse_formula op k env tg a in
- let g, env, tg = xparse_formula op k env tg b in
- (mkformula_binary k (mkAND k) term f g, env, tg)
- | [|a; b|] when EConstr.eq_constr sigma l op.op_or ->
- let f, env, tg = xparse_formula op k env tg a in
- let g, env, tg = xparse_formula op k env tg b in
- (mkformula_binary k (mkOR k) term f g, env, tg)
- | [|a; b|] when EConstr.eq_constr sigma l op.op_iff ->
- let f, env, tg = xparse_formula op k env tg a in
- let g, env, tg = xparse_formula op k env tg b in
- (mkformula_binary k (mkIff k) term f g, env, tg)
- | [|ty; a; b|]
- when EConstr.eq_constr sigma l eq && is_convertible gl ty bool ->
- let f, env, tg = xparse_formula bool_op Mc.IsBool env tg a in
- let g, env, tg = xparse_formula bool_op Mc.IsBool env tg b in
- (mkformula_binary Mc.IsProp mkEQ term f g, env, tg)
- | [|a|] when EConstr.eq_constr sigma l op.op_not ->
- let f, env, tg = xparse_formula op k env tg a in
- (Mc.NOT (k, f), env, tg)
- | _ -> parse_atom k env tg term )
- | Prod (typ, a, b)
- when kind_is_prop k
- && (typ.binder_name = Anonymous || EConstr.Vars.noccurn sigma 1 b)
- ->
+let prop_op =
+ lazy
+ { op_and = Lazy.force coq_and
+ ; op_or = Lazy.force coq_or
+ ; op_iff = Lazy.force coq_iff
+ ; op_not = Lazy.force coq_not
+ ; op_tt = Lazy.force coq_True
+ ; op_ff = Lazy.force coq_False }
+
+let bool_op =
+ lazy
+ { op_and = Lazy.force coq_andb
+ ; op_or = Lazy.force coq_orb
+ ; op_iff = Lazy.force coq_eqb
+ ; op_not = Lazy.force coq_negb
+ ; op_tt = Lazy.force coq_true
+ ; op_ff = Lazy.force coq_false }
+
+let parse_formula (genv, sigma) parse_atom env tg term =
+ let parse_atom b env tg t =
+ try
+ let at, env = parse_atom b env t (genv, sigma) in
+ (Mc.A (b, at, (tg, t)), env, Tag.next tg)
+ with ParseError -> (Mc.X (b, t), env, tg)
+ in
+ let prop_op = Lazy.force prop_op in
+ let bool_op = Lazy.force bool_op in
+ let eq = Lazy.force coq_eq in
+ let bool = Lazy.force coq_bool in
+ let rec xparse_formula op k env tg term =
+ match EConstr.kind sigma term with
+ | App (l, rst) -> (
+ match rst with
+ | [|a; b|] when EConstr.eq_constr sigma l op.op_and ->
let f, env, tg = xparse_formula op k env tg a in
let g, env, tg = xparse_formula op k env tg b in
- (mkformula_binary Mc.IsProp (mkIMPL Mc.IsProp) term f g, env, tg)
- | _ ->
- if EConstr.eq_constr sigma term op.op_tt then (Mc.TT k, env, tg)
- else if EConstr.eq_constr sigma term op.op_ff then Mc.(FF k, env, tg)
- else (Mc.X (k, term), env, tg)
- in
- xparse_formula prop_op Mc.IsProp env tg (*Reductionops.whd_zeta*) term
+ (mkformula_binary k (mkAND k) term f g, env, tg)
+ | [|a; b|] when EConstr.eq_constr sigma l op.op_or ->
+ let f, env, tg = xparse_formula op k env tg a in
+ let g, env, tg = xparse_formula op k env tg b in
+ (mkformula_binary k (mkOR k) term f g, env, tg)
+ | [|a; b|] when EConstr.eq_constr sigma l op.op_iff ->
+ let f, env, tg = xparse_formula op k env tg a in
+ let g, env, tg = xparse_formula op k env tg b in
+ (mkformula_binary k (mkIff k) term f g, env, tg)
+ | [|ty; a; b|]
+ when EConstr.eq_constr sigma l eq && is_convertible genv sigma ty bool
+ ->
+ let f, env, tg = xparse_formula bool_op Mc.IsBool env tg a in
+ let g, env, tg = xparse_formula bool_op Mc.IsBool env tg b in
+ (mkformula_binary Mc.IsProp mkEQ term f g, env, tg)
+ | [|a|] when EConstr.eq_constr sigma l op.op_not ->
+ let f, env, tg = xparse_formula op k env tg a in
+ (Mc.NOT (k, f), env, tg)
+ | _ -> parse_atom k env tg term )
+ | Prod (typ, a, b)
+ when kind_is_prop k
+ && (typ.binder_name = Anonymous || EConstr.Vars.noccurn sigma 1 b) ->
+ let f, env, tg = xparse_formula op k env tg a in
+ let g, env, tg = xparse_formula op k env tg b in
+ (mkformula_binary Mc.IsProp (mkIMPL Mc.IsProp) term f g, env, tg)
+ | _ ->
+ if EConstr.eq_constr sigma term op.op_tt then (Mc.TT k, env, tg)
+ else if EConstr.eq_constr sigma term op.op_ff then Mc.(FF k, env, tg)
+ else (Mc.X (k, term), env, tg)
+ in
+ xparse_formula prop_op Mc.IsProp env tg (*Reductionops.whd_zeta*) term
- (* let dump_bool b = Lazy.force (if b then coq_true else coq_false)*)
+(* let dump_bool b = Lazy.force (if b then coq_true else coq_false)*)
- let dump_kind k =
- Lazy.force (match k with Mc.IsProp -> coq_IsProp | Mc.IsBool -> coq_IsBool)
+let dump_kind k =
+ Lazy.force (match k with Mc.IsProp -> coq_IsProp | Mc.IsBool -> coq_IsBool)
- let dump_formula typ dump_atom f =
- let app_ctor c args =
- EConstr.mkApp
- ( Lazy.force c
- , Array.of_list
- ( typ :: Lazy.force coq_eKind :: Lazy.force coq_unit
- :: Lazy.force coq_unit :: args ) )
- in
- let rec xdump f =
- match f with
- | Mc.TT k -> app_ctor coq_TT [dump_kind k]
- | Mc.FF k -> app_ctor coq_FF [dump_kind k]
- | Mc.AND (k, x, y) -> app_ctor coq_AND [dump_kind k; xdump x; xdump y]
- | Mc.OR (k, x, y) -> app_ctor coq_OR [dump_kind k; xdump x; xdump y]
- | Mc.IMPL (k, x, _, y) ->
- app_ctor coq_IMPL
- [ dump_kind k
- ; xdump x
- ; EConstr.mkApp (Lazy.force coq_None, [|Lazy.force coq_unit|])
- ; xdump y ]
- | Mc.NOT (k, x) -> app_ctor coq_NOT [dump_kind k; xdump x]
- | Mc.IFF (k, x, y) -> app_ctor coq_IFF [dump_kind k; xdump x; xdump y]
- | Mc.EQ (x, y) -> app_ctor coq_EQ [xdump x; xdump y]
- | Mc.A (k, x, _) ->
- app_ctor coq_Atom [dump_kind k; dump_atom x; Lazy.force coq_tt]
- | Mc.X (k, t) -> app_ctor coq_X [dump_kind k; t]
- in
- xdump f
-
- let prop_env_of_formula gl form =
- Mc.(
- let rec doit env = function
- | TT _ | FF _ | A (_, _, _) -> env
- | X (b, t) -> fst (Env.compute_rank_add env t b)
- | AND (b, f1, f2)
- |OR (b, f1, f2)
- |IMPL (b, f1, _, f2)
- |IFF (b, f1, f2) ->
- doit (doit env f1) f2
- | NOT (b, f) -> doit env f
- | EQ (f1, f2) -> doit (doit env f1) f2
- in
- doit (Env.empty gl) form)
-
- let var_env_of_formula form =
- let rec vars_of_expr = function
- | Mc.PEX n -> ISet.singleton (CoqToCaml.positive n)
- | Mc.PEc z -> ISet.empty
- | Mc.PEadd (e1, e2) | Mc.PEmul (e1, e2) | Mc.PEsub (e1, e2) ->
- ISet.union (vars_of_expr e1) (vars_of_expr e2)
- | Mc.PEopp e | Mc.PEpow (e, _) -> vars_of_expr e
- in
- let vars_of_atom {Mc.flhs; Mc.fop; Mc.frhs} =
- ISet.union (vars_of_expr flhs) (vars_of_expr frhs)
+let dump_formula typ dump_atom f =
+ let app_ctor c args =
+ EConstr.mkApp
+ ( Lazy.force c
+ , Array.of_list
+ ( typ :: Lazy.force coq_eKind :: Lazy.force coq_unit
+ :: Lazy.force coq_unit :: args ) )
+ in
+ let rec xdump f =
+ match f with
+ | Mc.TT k -> app_ctor coq_TT [dump_kind k]
+ | Mc.FF k -> app_ctor coq_FF [dump_kind k]
+ | Mc.AND (k, x, y) -> app_ctor coq_AND [dump_kind k; xdump x; xdump y]
+ | Mc.OR (k, x, y) -> app_ctor coq_OR [dump_kind k; xdump x; xdump y]
+ | Mc.IMPL (k, x, _, y) ->
+ app_ctor coq_IMPL
+ [ dump_kind k
+ ; xdump x
+ ; EConstr.mkApp (Lazy.force coq_None, [|Lazy.force coq_unit|])
+ ; xdump y ]
+ | Mc.NOT (k, x) -> app_ctor coq_NOT [dump_kind k; xdump x]
+ | Mc.IFF (k, x, y) -> app_ctor coq_IFF [dump_kind k; xdump x; xdump y]
+ | Mc.EQ (x, y) -> app_ctor coq_EQ [xdump x; xdump y]
+ | Mc.A (k, x, _) ->
+ app_ctor coq_Atom [dump_kind k; dump_atom x; Lazy.force coq_tt]
+ | Mc.X (k, t) -> app_ctor coq_X [dump_kind k; t]
+ in
+ xdump f
+
+let prop_env_of_formula gl form =
+ Mc.(
+ let rec doit env = function
+ | TT _ | FF _ | A (_, _, _) -> env
+ | X (b, t) -> fst (Env.compute_rank_add env t b)
+ | AND (b, f1, f2) | OR (b, f1, f2) | IMPL (b, f1, _, f2) | IFF (b, f1, f2)
+ ->
+ doit (doit env f1) f2
+ | NOT (b, f) -> doit env f
+ | EQ (f1, f2) -> doit (doit env f1) f2
in
- Mc.(
- let rec doit = function
- | TT _ | FF _ | X _ -> ISet.empty
- | A (_, a, (t, c)) -> vars_of_atom a
- | AND (_, f1, f2)
- |OR (_, f1, f2)
- |IMPL (_, f1, _, f2)
- |IFF (_, f1, f2)
- |EQ (f1, f2) ->
- ISet.union (doit f1) (doit f2)
- | NOT (_, f) -> doit f
- in
- doit form)
-
- type 'cst dump_expr =
- { (* 'cst is the type of the syntactic constants *)
- interp_typ : EConstr.constr
- ; dump_cst : 'cst -> EConstr.constr
- ; dump_add : EConstr.constr
- ; dump_sub : EConstr.constr
- ; dump_opp : EConstr.constr
- ; dump_mul : EConstr.constr
- ; dump_pow : EConstr.constr
- ; dump_pow_arg : Mc.n -> EConstr.constr
- ; dump_op_prop : (Mc.op2 * EConstr.constr) list
- ; dump_op_bool : (Mc.op2 * EConstr.constr) list }
-
- let dump_zexpr =
- lazy
- { interp_typ = Lazy.force coq_Z
- ; dump_cst = dump_z
- ; dump_add = Lazy.force coq_Zplus
- ; dump_sub = Lazy.force coq_Zminus
- ; dump_opp = Lazy.force coq_Zopp
- ; dump_mul = Lazy.force coq_Zmult
- ; dump_pow = Lazy.force coq_Zpower
- ; dump_pow_arg = (fun n -> dump_z (CamlToCoq.z (CoqToCaml.n n)))
- ; dump_op_prop = List.map (fun (x, y) -> (y, Lazy.force x)) zop_table_prop
- ; dump_op_bool = List.map (fun (x, y) -> (y, Lazy.force x)) zop_table_bool
- }
-
- let dump_qexpr =
- lazy
- { interp_typ = Lazy.force coq_Q
- ; dump_cst = dump_q
- ; dump_add = Lazy.force coq_Qplus
- ; dump_sub = Lazy.force coq_Qminus
- ; dump_opp = Lazy.force coq_Qopp
- ; dump_mul = Lazy.force coq_Qmult
- ; dump_pow = Lazy.force coq_Qpower
- ; dump_pow_arg = (fun n -> dump_z (CamlToCoq.z (CoqToCaml.n n)))
- ; dump_op_prop = List.map (fun (x, y) -> (y, Lazy.force x)) qop_table_prop
- ; dump_op_bool = List.map (fun (x, y) -> (y, Lazy.force x)) qop_table_bool
- }
-
- let rec dump_Rcst_as_R cst =
- match cst with
- | Mc.C0 -> Lazy.force coq_R0
- | Mc.C1 -> Lazy.force coq_R1
- | Mc.CQ q -> EConstr.mkApp (Lazy.force coq_IQR, [|dump_q q|])
- | Mc.CZ z -> EConstr.mkApp (Lazy.force coq_IZR, [|dump_z z|])
- | Mc.CPlus (x, y) ->
- EConstr.mkApp
- (Lazy.force coq_Rplus, [|dump_Rcst_as_R x; dump_Rcst_as_R y|])
- | Mc.CMinus (x, y) ->
- EConstr.mkApp
- (Lazy.force coq_Rminus, [|dump_Rcst_as_R x; dump_Rcst_as_R y|])
- | Mc.CMult (x, y) ->
- EConstr.mkApp
- (Lazy.force coq_Rmult, [|dump_Rcst_as_R x; dump_Rcst_as_R y|])
- | Mc.CPow (x, y) -> (
- match y with
- | Mc.Inl z ->
- EConstr.mkApp (Lazy.force coq_powerZR, [|dump_Rcst_as_R x; dump_z z|])
- | Mc.Inr n ->
- EConstr.mkApp (Lazy.force coq_Rpower, [|dump_Rcst_as_R x; dump_nat n|])
- )
- | Mc.CInv t -> EConstr.mkApp (Lazy.force coq_Rinv, [|dump_Rcst_as_R t|])
- | Mc.COpp t -> EConstr.mkApp (Lazy.force coq_Ropp, [|dump_Rcst_as_R t|])
-
- let dump_rexpr =
- lazy
- { interp_typ = Lazy.force coq_R
- ; dump_cst = dump_Rcst_as_R
- ; dump_add = Lazy.force coq_Rplus
- ; dump_sub = Lazy.force coq_Rminus
- ; dump_opp = Lazy.force coq_Ropp
- ; dump_mul = Lazy.force coq_Rmult
- ; dump_pow = Lazy.force coq_Rpower
- ; dump_pow_arg = (fun n -> dump_nat (CamlToCoq.nat (CoqToCaml.n n)))
- ; dump_op_prop = List.map (fun (x, y) -> (y, Lazy.force x)) rop_table_prop
- ; dump_op_bool = List.map (fun (x, y) -> (y, Lazy.force x)) rop_table_bool
- }
-
- let prodn n env b =
- let rec prodrec = function
- | 0, env, b -> b
- | n, (v, t) :: l, b ->
- prodrec (n - 1, l, EConstr.mkProd (make_annot v Sorts.Relevant, t, b))
- | _ -> assert false
+ doit (Env.empty gl) form)
+
+let var_env_of_formula form =
+ let rec vars_of_expr = function
+ | Mc.PEX n -> ISet.singleton (CoqToCaml.positive n)
+ | Mc.PEc z -> ISet.empty
+ | Mc.PEadd (e1, e2) | Mc.PEmul (e1, e2) | Mc.PEsub (e1, e2) ->
+ ISet.union (vars_of_expr e1) (vars_of_expr e2)
+ | Mc.PEopp e | Mc.PEpow (e, _) -> vars_of_expr e
+ in
+ let vars_of_atom {Mc.flhs; Mc.fop; Mc.frhs} =
+ ISet.union (vars_of_expr flhs) (vars_of_expr frhs)
+ in
+ Mc.(
+ let rec doit = function
+ | TT _ | FF _ | X _ -> ISet.empty
+ | A (_, a, (t, c)) -> vars_of_atom a
+ | AND (_, f1, f2)
+ |OR (_, f1, f2)
+ |IMPL (_, f1, _, f2)
+ |IFF (_, f1, f2)
+ |EQ (f1, f2) ->
+ ISet.union (doit f1) (doit f2)
+ | NOT (_, f) -> doit f
in
- prodrec (n, env, b)
+ doit form)
+
+type 'cst dump_expr =
+ { (* 'cst is the type of the syntactic constants *)
+ interp_typ : EConstr.constr
+ ; dump_cst : 'cst -> EConstr.constr
+ ; dump_add : EConstr.constr
+ ; dump_sub : EConstr.constr
+ ; dump_opp : EConstr.constr
+ ; dump_mul : EConstr.constr
+ ; dump_pow : EConstr.constr
+ ; dump_pow_arg : Mc.n -> EConstr.constr
+ ; dump_op_prop : (Mc.op2 * EConstr.constr) list
+ ; dump_op_bool : (Mc.op2 * EConstr.constr) list }
+
+let dump_zexpr =
+ lazy
+ { interp_typ = Lazy.force coq_Z
+ ; dump_cst = dump_z
+ ; dump_add = Lazy.force coq_Zplus
+ ; dump_sub = Lazy.force coq_Zminus
+ ; dump_opp = Lazy.force coq_Zopp
+ ; dump_mul = Lazy.force coq_Zmult
+ ; dump_pow = Lazy.force coq_Zpower
+ ; dump_pow_arg = (fun n -> dump_z (CamlToCoq.z (CoqToCaml.n n)))
+ ; dump_op_prop = List.map (fun (x, y) -> (y, Lazy.force x)) zop_table_prop
+ ; dump_op_bool = List.map (fun (x, y) -> (y, Lazy.force x)) zop_table_bool
+ }
+
+let dump_qexpr =
+ lazy
+ { interp_typ = Lazy.force coq_Q
+ ; dump_cst = dump_q
+ ; dump_add = Lazy.force coq_Qplus
+ ; dump_sub = Lazy.force coq_Qminus
+ ; dump_opp = Lazy.force coq_Qopp
+ ; dump_mul = Lazy.force coq_Qmult
+ ; dump_pow = Lazy.force coq_Qpower
+ ; dump_pow_arg = (fun n -> dump_z (CamlToCoq.z (CoqToCaml.n n)))
+ ; dump_op_prop = List.map (fun (x, y) -> (y, Lazy.force x)) qop_table_prop
+ ; dump_op_bool = List.map (fun (x, y) -> (y, Lazy.force x)) qop_table_bool
+ }
+
+let rec dump_Rcst_as_R cst =
+ match cst with
+ | Mc.C0 -> Lazy.force coq_R0
+ | Mc.C1 -> Lazy.force coq_R1
+ | Mc.CQ q -> EConstr.mkApp (Lazy.force coq_IQR, [|dump_q q|])
+ | Mc.CZ z -> EConstr.mkApp (Lazy.force coq_IZR, [|dump_z z|])
+ | Mc.CPlus (x, y) ->
+ EConstr.mkApp (Lazy.force coq_Rplus, [|dump_Rcst_as_R x; dump_Rcst_as_R y|])
+ | Mc.CMinus (x, y) ->
+ EConstr.mkApp (Lazy.force coq_Rminus, [|dump_Rcst_as_R x; dump_Rcst_as_R y|])
+ | Mc.CMult (x, y) ->
+ EConstr.mkApp (Lazy.force coq_Rmult, [|dump_Rcst_as_R x; dump_Rcst_as_R y|])
+ | Mc.CPow (x, y) -> (
+ match y with
+ | Mc.Inl z ->
+ EConstr.mkApp (Lazy.force coq_powerZR, [|dump_Rcst_as_R x; dump_z z|])
+ | Mc.Inr n ->
+ EConstr.mkApp (Lazy.force coq_Rpower, [|dump_Rcst_as_R x; dump_nat n|]) )
+ | Mc.CInv t -> EConstr.mkApp (Lazy.force coq_Rinv, [|dump_Rcst_as_R t|])
+ | Mc.COpp t -> EConstr.mkApp (Lazy.force coq_Ropp, [|dump_Rcst_as_R t|])
+
+let dump_rexpr =
+ lazy
+ { interp_typ = Lazy.force coq_R
+ ; dump_cst = dump_Rcst_as_R
+ ; dump_add = Lazy.force coq_Rplus
+ ; dump_sub = Lazy.force coq_Rminus
+ ; dump_opp = Lazy.force coq_Ropp
+ ; dump_mul = Lazy.force coq_Rmult
+ ; dump_pow = Lazy.force coq_Rpower
+ ; dump_pow_arg = (fun n -> dump_nat (CamlToCoq.nat (CoqToCaml.n n)))
+ ; dump_op_prop = List.map (fun (x, y) -> (y, Lazy.force x)) rop_table_prop
+ ; dump_op_bool = List.map (fun (x, y) -> (y, Lazy.force x)) rop_table_bool
+ }
+
+let prodn n env b =
+ let rec prodrec = function
+ | 0, env, b -> b
+ | n, (v, t) :: l, b ->
+ prodrec (n - 1, l, EConstr.mkProd (make_annot v Sorts.Relevant, t, b))
+ | _ -> assert false
+ in
+ prodrec (n, env, b)
- (** [make_goal_of_formula depxr vars props form] where
+(** [make_goal_of_formula depxr vars props form] where
- vars is an environment for the arithmetic variables occurring in form
- props is an environment for the propositions occurring in form
@return a goal where all the variables and propositions of the formula are quantified
*)
- let eKind = function
- | Mc.IsProp -> EConstr.mkProp
- | Mc.IsBool -> Lazy.force coq_bool
+let eKind = function
+ | Mc.IsProp -> EConstr.mkProp
+ | Mc.IsBool -> Lazy.force coq_bool
- let make_goal_of_formula gl dexpr form =
- let vars_idx =
- List.mapi
- (fun i v -> (v, i + 1))
- (ISet.elements (var_env_of_formula form))
- in
- (* List.iter (fun (v,i) -> Printf.fprintf stdout "var %i has index %i\n" v i) vars_idx ;*)
- let props = prop_env_of_formula gl form in
- let fresh_var str i = Names.Id.of_string (str ^ string_of_int i) in
- let fresh_prop str i = Names.Id.of_string (str ^ string_of_int i) in
- let vars_n =
- List.map (fun (_, i) -> (fresh_var "__x" i, dexpr.interp_typ)) vars_idx
- in
- let props_n =
- List.mapi
- (fun i (_, k) -> (fresh_prop "__p" (i + 1), eKind k))
- (Env.elements props)
- in
- let var_name_pos =
- List.map2 (fun (idx, _) (id, _) -> (id, idx)) vars_idx vars_n
- in
- let dump_expr i e =
- let rec dump_expr = function
- | Mc.PEX n ->
- EConstr.mkRel (i + List.assoc (CoqToCaml.positive n) vars_idx)
- | Mc.PEc z -> dexpr.dump_cst z
- | Mc.PEadd (e1, e2) ->
- EConstr.mkApp (dexpr.dump_add, [|dump_expr e1; dump_expr e2|])
- | Mc.PEsub (e1, e2) ->
- EConstr.mkApp (dexpr.dump_sub, [|dump_expr e1; dump_expr e2|])
- | Mc.PEopp e -> EConstr.mkApp (dexpr.dump_opp, [|dump_expr e|])
- | Mc.PEmul (e1, e2) ->
- EConstr.mkApp (dexpr.dump_mul, [|dump_expr e1; dump_expr e2|])
- | Mc.PEpow (e, n) ->
- EConstr.mkApp (dexpr.dump_pow, [|dump_expr e; dexpr.dump_pow_arg n|])
- in
- dump_expr e
- in
- let mkop_prop op e1 e2 =
- try EConstr.mkApp (List.assoc op dexpr.dump_op_prop, [|e1; e2|])
- with Not_found ->
- EConstr.mkApp (Lazy.force coq_eq, [|dexpr.interp_typ; e1; e2|])
- in
- let dump_cstr_prop i {Mc.flhs; Mc.fop; Mc.frhs} =
- mkop_prop fop (dump_expr i flhs) (dump_expr i frhs)
- in
- let mkop_bool op e1 e2 =
- try EConstr.mkApp (List.assoc op dexpr.dump_op_bool, [|e1; e2|])
- with Not_found ->
- EConstr.mkApp (Lazy.force coq_eq, [|dexpr.interp_typ; e1; e2|])
- in
- let dump_cstr_bool i {Mc.flhs; Mc.fop; Mc.frhs} =
- mkop_bool fop (dump_expr i flhs) (dump_expr i frhs)
- in
- let rec xdump_prop pi xi f =
- match f with
- | Mc.TT _ -> Lazy.force coq_True
- | Mc.FF _ -> Lazy.force coq_False
- | Mc.AND (_, x, y) ->
- EConstr.mkApp
- (Lazy.force coq_and, [|xdump_prop pi xi x; xdump_prop pi xi y|])
- | Mc.OR (_, x, y) ->
- EConstr.mkApp
- (Lazy.force coq_or, [|xdump_prop pi xi x; xdump_prop pi xi y|])
- | Mc.IFF (_, x, y) ->
- EConstr.mkApp
- (Lazy.force coq_iff, [|xdump_prop pi xi x; xdump_prop pi xi y|])
- | Mc.IMPL (_, x, _, y) ->
- EConstr.mkArrow (xdump_prop pi xi x) Sorts.Relevant
- (xdump_prop (pi + 1) (xi + 1) y)
- | Mc.NOT (_, x) ->
- EConstr.mkArrow (xdump_prop pi xi x) Sorts.Relevant
- (Lazy.force coq_False)
- | Mc.EQ (x, y) ->
- EConstr.mkApp
- ( Lazy.force coq_eq
- , [|Lazy.force coq_bool; xdump_bool pi xi x; xdump_bool pi xi y|] )
- | Mc.A (_, x, _) -> dump_cstr_prop xi x
- | Mc.X (_, t) ->
- let idx = Env.get_rank props t in
- EConstr.mkRel (pi + idx)
- and xdump_bool pi xi f =
- match f with
- | Mc.TT _ -> Lazy.force coq_true
- | Mc.FF _ -> Lazy.force coq_false
- | Mc.AND (_, x, y) ->
- EConstr.mkApp
- (Lazy.force coq_andb, [|xdump_bool pi xi x; xdump_bool pi xi y|])
- | Mc.OR (_, x, y) ->
- EConstr.mkApp
- (Lazy.force coq_orb, [|xdump_bool pi xi x; xdump_bool pi xi y|])
- | Mc.IFF (_, x, y) ->
- EConstr.mkApp
- (Lazy.force coq_eqb, [|xdump_bool pi xi x; xdump_bool pi xi y|])
- | Mc.IMPL (_, x, _, y) ->
- EConstr.mkApp
- (Lazy.force coq_implb, [|xdump_bool pi xi x; xdump_bool pi xi y|])
- | Mc.NOT (_, x) ->
- EConstr.mkApp (Lazy.force coq_negb, [|xdump_bool pi xi x|])
- | Mc.EQ (x, y) -> assert false
- | Mc.A (_, x, _) -> dump_cstr_bool xi x
- | Mc.X (_, t) ->
- let idx = Env.get_rank props t in
- EConstr.mkRel (pi + idx)
- in
- let nb_vars = List.length vars_n in
- let nb_props = List.length props_n in
- (* Printf.fprintf stdout "NBProps : %i\n" nb_props ;*)
- let subst_prop p =
- let idx = Env.get_rank props p in
- EConstr.mkVar (Names.Id.of_string (Printf.sprintf "__p%i" idx))
+let make_goal_of_formula gl dexpr form =
+ let vars_idx =
+ List.mapi (fun i v -> (v, i + 1)) (ISet.elements (var_env_of_formula form))
+ in
+ (* List.iter (fun (v,i) -> Printf.fprintf stdout "var %i has index %i\n" v i) vars_idx ;*)
+ let props = prop_env_of_formula gl form in
+ let fresh_var str i = Names.Id.of_string (str ^ string_of_int i) in
+ let fresh_prop str i = Names.Id.of_string (str ^ string_of_int i) in
+ let vars_n =
+ List.map (fun (_, i) -> (fresh_var "__x" i, dexpr.interp_typ)) vars_idx
+ in
+ let props_n =
+ List.mapi
+ (fun i (_, k) -> (fresh_prop "__p" (i + 1), eKind k))
+ (Env.elements props)
+ in
+ let var_name_pos =
+ List.map2 (fun (idx, _) (id, _) -> (id, idx)) vars_idx vars_n
+ in
+ let dump_expr i e =
+ let rec dump_expr = function
+ | Mc.PEX n ->
+ EConstr.mkRel (i + List.assoc (CoqToCaml.positive n) vars_idx)
+ | Mc.PEc z -> dexpr.dump_cst z
+ | Mc.PEadd (e1, e2) ->
+ EConstr.mkApp (dexpr.dump_add, [|dump_expr e1; dump_expr e2|])
+ | Mc.PEsub (e1, e2) ->
+ EConstr.mkApp (dexpr.dump_sub, [|dump_expr e1; dump_expr e2|])
+ | Mc.PEopp e -> EConstr.mkApp (dexpr.dump_opp, [|dump_expr e|])
+ | Mc.PEmul (e1, e2) ->
+ EConstr.mkApp (dexpr.dump_mul, [|dump_expr e1; dump_expr e2|])
+ | Mc.PEpow (e, n) ->
+ EConstr.mkApp (dexpr.dump_pow, [|dump_expr e; dexpr.dump_pow_arg n|])
in
- let form' = Mc.mapX (fun _ p -> subst_prop p) Mc.IsProp form in
- ( prodn nb_props
- (List.map (fun (x, y) -> (Name.Name x, y)) props_n)
- (prodn nb_vars
- (List.map (fun (x, y) -> (Name.Name x, y)) vars_n)
- (xdump_prop (List.length vars_n) 0 form))
- , List.rev props_n
- , List.rev var_name_pos
- , form' )
-
- (**
+ dump_expr e
+ in
+ let mkop_prop op e1 e2 =
+ try EConstr.mkApp (List.assoc op dexpr.dump_op_prop, [|e1; e2|])
+ with Not_found ->
+ EConstr.mkApp (Lazy.force coq_eq, [|dexpr.interp_typ; e1; e2|])
+ in
+ let dump_cstr_prop i {Mc.flhs; Mc.fop; Mc.frhs} =
+ mkop_prop fop (dump_expr i flhs) (dump_expr i frhs)
+ in
+ let mkop_bool op e1 e2 =
+ try EConstr.mkApp (List.assoc op dexpr.dump_op_bool, [|e1; e2|])
+ with Not_found ->
+ EConstr.mkApp (Lazy.force coq_eq, [|dexpr.interp_typ; e1; e2|])
+ in
+ let dump_cstr_bool i {Mc.flhs; Mc.fop; Mc.frhs} =
+ mkop_bool fop (dump_expr i flhs) (dump_expr i frhs)
+ in
+ let rec xdump_prop pi xi f =
+ match f with
+ | Mc.TT _ -> Lazy.force coq_True
+ | Mc.FF _ -> Lazy.force coq_False
+ | Mc.AND (_, x, y) ->
+ EConstr.mkApp
+ (Lazy.force coq_and, [|xdump_prop pi xi x; xdump_prop pi xi y|])
+ | Mc.OR (_, x, y) ->
+ EConstr.mkApp
+ (Lazy.force coq_or, [|xdump_prop pi xi x; xdump_prop pi xi y|])
+ | Mc.IFF (_, x, y) ->
+ EConstr.mkApp
+ (Lazy.force coq_iff, [|xdump_prop pi xi x; xdump_prop pi xi y|])
+ | Mc.IMPL (_, x, _, y) ->
+ EConstr.mkArrow (xdump_prop pi xi x) Sorts.Relevant
+ (xdump_prop (pi + 1) (xi + 1) y)
+ | Mc.NOT (_, x) ->
+ EConstr.mkArrow (xdump_prop pi xi x) Sorts.Relevant (Lazy.force coq_False)
+ | Mc.EQ (x, y) ->
+ EConstr.mkApp
+ ( Lazy.force coq_eq
+ , [|Lazy.force coq_bool; xdump_bool pi xi x; xdump_bool pi xi y|] )
+ | Mc.A (_, x, _) -> dump_cstr_prop xi x
+ | Mc.X (_, t) ->
+ let idx = Env.get_rank props t in
+ EConstr.mkRel (pi + idx)
+ and xdump_bool pi xi f =
+ match f with
+ | Mc.TT _ -> Lazy.force coq_true
+ | Mc.FF _ -> Lazy.force coq_false
+ | Mc.AND (_, x, y) ->
+ EConstr.mkApp
+ (Lazy.force coq_andb, [|xdump_bool pi xi x; xdump_bool pi xi y|])
+ | Mc.OR (_, x, y) ->
+ EConstr.mkApp
+ (Lazy.force coq_orb, [|xdump_bool pi xi x; xdump_bool pi xi y|])
+ | Mc.IFF (_, x, y) ->
+ EConstr.mkApp
+ (Lazy.force coq_eqb, [|xdump_bool pi xi x; xdump_bool pi xi y|])
+ | Mc.IMPL (_, x, _, y) ->
+ EConstr.mkApp
+ (Lazy.force coq_implb, [|xdump_bool pi xi x; xdump_bool pi xi y|])
+ | Mc.NOT (_, x) ->
+ EConstr.mkApp (Lazy.force coq_negb, [|xdump_bool pi xi x|])
+ | Mc.EQ (x, y) -> assert false
+ | Mc.A (_, x, _) -> dump_cstr_bool xi x
+ | Mc.X (_, t) ->
+ let idx = Env.get_rank props t in
+ EConstr.mkRel (pi + idx)
+ in
+ let nb_vars = List.length vars_n in
+ let nb_props = List.length props_n in
+ (* Printf.fprintf stdout "NBProps : %i\n" nb_props ;*)
+ let subst_prop p =
+ let idx = Env.get_rank props p in
+ EConstr.mkVar (Names.Id.of_string (Printf.sprintf "__p%i" idx))
+ in
+ let form' = Mc.mapX (fun _ p -> subst_prop p) Mc.IsProp form in
+ ( prodn nb_props
+ (List.map (fun (x, y) -> (Name.Name x, y)) props_n)
+ (prodn nb_vars
+ (List.map (fun (x, y) -> (Name.Name x, y)) vars_n)
+ (xdump_prop (List.length vars_n) 0 form))
+ , List.rev props_n
+ , List.rev var_name_pos
+ , form' )
+
+(**
* Given a conclusion and a list of affectations, rebuild a term prefixed by
* the appropriate letins.
* TODO: reverse the list of bindings!
*)
- let set l concl =
- let rec xset acc = function
- | [] -> acc
- | e :: l ->
- let name, expr, typ = e in
- xset
- (EConstr.mkNamedLetIn
- (make_annot (Names.Id.of_string name) Sorts.Relevant)
- expr typ acc)
- l
- in
- xset concl l
-end
-
-open M
+let set l concl =
+ let rec xset acc = function
+ | [] -> acc
+ | e :: l ->
+ let name, expr, typ = e in
+ xset
+ (EConstr.mkNamedLetIn
+ (make_annot (Names.Id.of_string name) Sorts.Relevant)
+ expr typ acc)
+ l
+ in
+ xset concl l
let coq_Branch = lazy (constr_of_ref "micromega.VarMap.Branch")
let coq_Elt = lazy (constr_of_ref "micromega.VarMap.Elt")
@@ -1424,14 +1389,14 @@ let rec pp_proof_term o = function
| Micromega.ExProof (p, prf) ->
Printf.fprintf o "Ex[%a,%a]" pp_positive p pp_proof_term prf
-let rec parse_hyps gl parse_arith env tg hyps =
+let rec parse_hyps (genv, sigma) parse_arith env tg hyps =
match hyps with
| [] -> ([], env, tg)
| (i, t) :: l ->
- let lhyps, env, tg = parse_hyps gl parse_arith env tg l in
- if is_prop gl.env gl.sigma t then
+ let lhyps, env, tg = parse_hyps (genv, sigma) parse_arith env tg l in
+ if is_prop genv sigma t then
try
- let c, env, tg = parse_formula gl parse_arith env tg t in
+ let c, env, tg = parse_formula (genv, sigma) parse_arith env tg t in
((i, c) :: lhyps, env, tg)
with ParseError -> (lhyps, env, tg)
else (lhyps, env, tg)
@@ -1852,19 +1817,22 @@ let clear_all_no_check =
let micromega_gen parse_arith pre_process cnf spec dumpexpr prover tac =
Proofview.Goal.enter (fun gl ->
let sigma = Tacmach.New.project gl in
+ let genv = Tacmach.New.pf_env gl in
let concl = Tacmach.New.pf_concl gl in
let hyps = Tacmach.New.pf_hyps_types gl in
try
- let gl0 = {env = Tacmach.New.pf_env gl; sigma} in
let hyps, concl, env =
- parse_goal gl0 parse_arith (Env.empty gl0) hyps concl
+ parse_goal (genv, sigma) parse_arith
+ (Env.empty (genv, sigma))
+ hyps concl
in
let env = Env.elements env in
let spec = Lazy.force spec in
let dumpexpr = Lazy.force dumpexpr in
- if debug then Feedback.msg_debug (Pp.str "Env " ++ Env.pp gl0 env);
+ if debug then
+ Feedback.msg_debug (Pp.str "Env " ++ Env.pp (genv, sigma) env);
match
- micromega_tauto pre_process cnf spec prover env hyps concl gl0
+ micromega_tauto pre_process cnf spec prover env hyps concl (env, sigma)
with
| Unknown ->
flush stdout;
@@ -1873,7 +1841,7 @@ let micromega_gen parse_arith pre_process cnf spec dumpexpr prover tac =
Tacticals.New.tclFAIL 0 (Pp.str " Cannot find witness")
| Prf (ids, ff', res') ->
let arith_goal, props, vars, ff_arith =
- make_goal_of_formula gl0 dumpexpr ff'
+ make_goal_of_formula (genv, sigma) dumpexpr ff'
in
let intro (id, _) = Tactics.introduction id in
let intro_vars = Tacticals.New.tclTHENLIST (List.map intro vars) in
@@ -1893,7 +1861,9 @@ let micromega_gen parse_arith pre_process cnf spec dumpexpr prover tac =
env' ff_arith ]
in
let goal_props =
- List.rev (List.map fst (Env.elements (prop_env_of_formula gl0 ff')))
+ List.rev
+ (List.map fst
+ (Env.elements (prop_env_of_formula (genv, sigma) ff')))
in
let goal_vars =
List.map (fun (_, i) -> fst (List.nth env (i - 1))) vars
@@ -1971,12 +1941,14 @@ let micromega_genr prover tac =
in
Proofview.Goal.enter (fun gl ->
let sigma = Tacmach.New.project gl in
+ let genv = Tacmach.New.pf_env gl in
let concl = Tacmach.New.pf_concl gl in
let hyps = Tacmach.New.pf_hyps_types gl in
try
- let gl0 = {env = Tacmach.New.pf_env gl; sigma} in
let hyps, concl, env =
- parse_goal gl0 parse_arith (Env.empty gl0) hyps concl
+ parse_goal (genv, sigma) parse_arith
+ (Env.empty (genv, sigma))
+ hyps concl
in
let env = Env.elements env in
let spec = Lazy.force spec in
@@ -1997,7 +1969,7 @@ let micromega_genr prover tac =
match
micromega_tauto
(fun _ x -> x)
- Mc.cnfQ spec prover env hyps' concl' gl0
+ Mc.cnfQ spec prover env hyps' concl' (genv, sigma)
with
| Unknown | Model _ ->
flush stdout;
@@ -2010,7 +1982,7 @@ let micromega_genr prover tac =
in
let ff' = abstract_wrt_formula ff' ff in
let arith_goal, props, vars, ff_arith =
- make_goal_of_formula gl0 (Lazy.force dump_rexpr) ff'
+ make_goal_of_formula (genv, sigma) (Lazy.force dump_rexpr) ff'
in
let intro (id, _) = Tactics.introduction id in
let intro_vars = Tacticals.New.tclTHENLIST (List.map intro vars) in
@@ -2030,7 +2002,9 @@ let micromega_genr prover tac =
; micromega_order_changer res' env' ff_arith ]
in
let goal_props =
- List.rev (List.map fst (Env.elements (prop_env_of_formula gl0 ff')))
+ List.rev
+ (List.map fst
+ (Env.elements (prop_env_of_formula (genv, sigma) ff')))
in
let goal_vars =
List.map (fun (_, i) -> fst (List.nth env (i - 1))) vars
diff --git a/plugins/micromega/zify.ml b/plugins/micromega/zify.ml
index fa29e6080e..917961fdcd 100644
--- a/plugins/micromega/zify.ml
+++ b/plugins/micromega/zify.ml
@@ -464,13 +464,18 @@ module ECstOp = struct
let cast x = CstOp x
let dest = function CstOp x -> Some x | _ -> None
+ let isConstruct evd c =
+ match EConstr.kind evd c with
+ | Construct _ | Int _ | Float _ -> true
+ | _ -> false
+
let mk_elt evd i a =
{ source = a.(0)
; target = a.(1)
; inj = get_inj evd a.(3)
; cst = a.(4)
; cstinj = a.(5)
- ; is_construct = EConstr.isConstruct evd a.(2) }
+ ; is_construct = isConstruct evd a.(2) }
let get_key = 2
end
@@ -979,17 +984,21 @@ let is_arrow env evd a p1 p2 =
where c is the head symbol and [a] is the array of arguments.
The function also transforms (x -> y) as (arrow x y) *)
let get_operator barrow env evd e =
- match EConstr.kind evd e with
+ let e' = EConstr.whd_evar evd e in
+ match EConstr.kind evd e' with
| Prod (a, p1, p2) ->
- if barrow && is_arrow env evd a p1 p2 then (arrow, [|p1; p2|])
+ if barrow && is_arrow env evd a p1 p2 then (arrow, [|p1; p2|], false)
else raise Not_found
| App (c, a) -> (
- match EConstr.kind evd c with
+ let c' = EConstr.whd_evar evd c in
+ match EConstr.kind evd c' with
| Construct _ (* e.g. Z0 , Z.pos *) | Const _ (* e.g. Z.max *) | Proj _
|Lambda _ (* e.g projections *) | Ind _ (* e.g. eq *) ->
- (c, a)
+ (c', a, false)
| _ -> raise Not_found )
- | Construct _ -> (EConstr.whd_evar evd e, [||])
+ | Const _ -> (e', [||], false)
+ | Construct _ -> (e', [||], true)
+ | Int _ | Float _ -> (e', [||], true)
| _ -> raise Not_found
let decompose_app env evd e =
@@ -1065,37 +1074,41 @@ let rec trans_expr env evd e =
let inj = e.inj in
let e = e.constr in
try
- let c, a = get_operator false env evd e in
- let k, t =
- find_option (match_operator env evd c a) (HConstr.find_all c !table_cache)
- in
- let n = Array.length a in
- match k with
- | CstOp {deriv = c'} ->
- ECstOpT.(if c'.is_construct then Term else Prf (c'.cst, c'.cstinj))
- | UnOp {deriv = unop} ->
- let prf =
- trans_expr env evd
- { constr = a.(n - 1)
- ; typ = unop.EUnOpT.source1
- ; inj = unop.EUnOpT.inj1_t }
- in
- app_unop evd e unop a.(n - 1) prf
- | BinOp {deriv = binop} ->
- let prf1 =
- trans_expr env evd
- { constr = a.(n - 2)
- ; typ = binop.EBinOpT.source1
- ; inj = binop.EBinOpT.inj1 }
- in
- let prf2 =
- trans_expr env evd
- { constr = a.(n - 1)
- ; typ = binop.EBinOpT.source2
- ; inj = binop.EBinOpT.inj2 }
+ let c, a, is_constant = get_operator false env evd e in
+ if is_constant then Term
+ else
+ let k, t =
+ find_option
+ (match_operator env evd c a)
+ (HConstr.find_all c !table_cache)
in
- app_binop evd e binop a.(n - 2) prf1 a.(n - 1) prf2
- | d -> mkvar evd inj e
+ let n = Array.length a in
+ match k with
+ | CstOp {deriv = c'} ->
+ ECstOpT.(if c'.is_construct then Term else Prf (c'.cst, c'.cstinj))
+ | UnOp {deriv = unop} ->
+ let prf =
+ trans_expr env evd
+ { constr = a.(n - 1)
+ ; typ = unop.EUnOpT.source1
+ ; inj = unop.EUnOpT.inj1_t }
+ in
+ app_unop evd e unop a.(n - 1) prf
+ | BinOp {deriv = binop} ->
+ let prf1 =
+ trans_expr env evd
+ { constr = a.(n - 2)
+ ; typ = binop.EBinOpT.source1
+ ; inj = binop.EBinOpT.inj1 }
+ in
+ let prf2 =
+ trans_expr env evd
+ { constr = a.(n - 1)
+ ; typ = binop.EBinOpT.source2
+ ; inj = binop.EBinOpT.inj2 }
+ in
+ app_binop evd e binop a.(n - 2) prf1 a.(n - 1) prf2
+ | d -> mkvar evd inj e
with Not_found ->
(* Feedback.msg_debug
Pp.(str "Not found " ++ Termops.Internal.debug_print_constr e); *)
diff --git a/plugins/rtauto/refl_tauto.ml b/plugins/rtauto/refl_tauto.ml
index d464ec4c06..61f90608b1 100644
--- a/plugins/rtauto/refl_tauto.ml
+++ b/plugins/rtauto/refl_tauto.ml
@@ -100,7 +100,7 @@ let rec make_form env sigma atom_env term =
| Cast(a,_,_) ->
make_form env sigma atom_env a
| Ind (ind, _) ->
- if Names.eq_ind ind (fst (Lazy.force li_False)) then
+ if Names.Ind.CanOrd.equal ind (fst (Lazy.force li_False)) then
Bot
else
make_atom atom_env (normalize term)
@@ -108,11 +108,11 @@ let rec make_form env sigma atom_env term =
begin
try
let ind, _ = destInd sigma hd in
- if Names.eq_ind ind (fst (Lazy.force li_and)) then
+ if Names.Ind.CanOrd.equal ind (fst (Lazy.force li_and)) then
let fa = make_form env sigma atom_env argv.(0) in
let fb = make_form env sigma atom_env argv.(1) in
Conjunct (fa,fb)
- else if Names.eq_ind ind (fst (Lazy.force li_or)) then
+ else if Names.Ind.CanOrd.equal ind (fst (Lazy.force li_or)) then
let fa = make_form env sigma atom_env argv.(0) in
let fb = make_form env sigma atom_env argv.(1) in
Disjunct (fa,fb)
diff --git a/plugins/ssr/ssrcommon.ml b/plugins/ssr/ssrcommon.ml
index d859fe51ab..cb58b9bcb8 100644
--- a/plugins/ssr/ssrcommon.ml
+++ b/plugins/ssr/ssrcommon.ml
@@ -280,7 +280,7 @@ let interp_wit wit ist gl x =
sigma, Tacinterp.Value.cast (topwit wit) arg
let interp_hyp ist gl (SsrHyp (loc, id)) =
- let s, id' = interp_wit wit_var ist gl CAst.(make ?loc id) in
+ let s, id' = interp_wit wit_hyp ist gl CAst.(make ?loc id) in
if not_section_id id' then s, SsrHyp (loc, id') else
hyp_err ?loc "Can't clear section hypothesis " id'
diff --git a/plugins/ssr/ssrequality.ml b/plugins/ssr/ssrequality.ml
index 38b26d06b9..a7ebd5f9f5 100644
--- a/plugins/ssr/ssrequality.ml
+++ b/plugins/ssr/ssrequality.ml
@@ -240,7 +240,7 @@ let strip_unfold_term _ ((sigma, t) as p) kt = match EConstr.kind sigma t with
let same_proj sigma t1 t2 =
match EConstr.kind sigma t1, EConstr.kind sigma t2 with
- | Proj(c1,_), Proj(c2, _) -> Projection.equal c1 c2
+ | Proj(c1,_), Proj(c2, _) -> Projection.CanOrd.equal c1 c2
| _ -> false
let all_ok _ _ = true
diff --git a/plugins/ssr/ssrparser.mlg b/plugins/ssr/ssrparser.mlg
index 89e0c9fcbe..ccdf5fa68e 100644
--- a/plugins/ssr/ssrparser.mlg
+++ b/plugins/ssr/ssrparser.mlg
@@ -100,7 +100,7 @@ ARGUMENT EXTEND ssrtacarg TYPED AS tactic PRINTED BY { pr_ssrtacarg env sigma }
END
GRAMMAR EXTEND Gram
GLOBAL: ssrtacarg;
- ssrtacarg: [[ tac = tactic_expr LEVEL "5" -> { tac } ]];
+ ssrtacarg: [[ tac = ltac_expr LEVEL "5" -> { tac } ]];
END
(* Copy of ssrtacarg with LEVEL "3", useful for: "under ... do ..." *)
@@ -108,7 +108,7 @@ ARGUMENT EXTEND ssrtac3arg TYPED AS tactic PRINTED BY { pr_ssrtacarg env sigma }
END
GRAMMAR EXTEND Gram
GLOBAL: ssrtac3arg;
- ssrtac3arg: [[ tac = tactic_expr LEVEL "3" -> { tac } ]];
+ ssrtac3arg: [[ tac = ltac_expr LEVEL "3" -> { tac } ]];
END
{
@@ -155,7 +155,7 @@ let pr_ssrhyp _ _ _ = pr_hyp
let wit_ssrhyprep = add_genarg "ssrhyprep" (fun env sigma -> pr_hyp)
let intern_hyp ist (SsrHyp (loc, id) as hyp) =
- let _ = Tacintern.intern_genarg ist (in_gen (rawwit wit_var) CAst.(make ?loc id)) in
+ let _ = Tacintern.intern_genarg ist (in_gen (rawwit wit_hyp) CAst.(make ?loc id)) in
if not_section_id id then hyp else
hyp_err ?loc "Can't clear section hypothesis " id
@@ -350,7 +350,7 @@ let interp_index ist gl idx =
| Some c ->
let rc = Detyping.detype Detyping.Now false Id.Set.empty (pf_env gl) (project gl) c in
begin match Notation.uninterp_prim_token rc (None, []) with
- | Constrexpr.Numeral n, _ when NumTok.Signed.is_int n ->
+ | Constrexpr.Number n, _ when NumTok.Signed.is_int n ->
int_of_string (NumTok.Signed.to_string n)
| _ -> raise Not_found
end
@@ -1337,7 +1337,7 @@ ARGUMENT EXTEND ssrbinder TYPED AS (ssrfwdfmt * constr) PRINTED BY { pr_ssrbinde
GRAMMAR EXTEND Gram
GLOBAL: ssrbinder;
ssrbinder: [
- [ ["of" -> { () } | "&" -> { () } ]; c = operconstr LEVEL "99" -> {
+ [ ["of" -> { () } | "&" -> { () } ]; c = term LEVEL "99" -> {
(FwdPose, [BFvar]),
CAst.make ~loc @@ CLambdaN ([CLocalAssum ([CAst.make ~loc Anonymous],Default Glob_term.Explicit,c)],mkCHole (Some loc)) } ]
];
@@ -1594,18 +1594,18 @@ GRAMMAR EXTEND Gram
| n = Prim.natural -> { ArgArg (check_index ~loc n) }
] ];
ssrswap: [[ IDENT "first" -> { loc, true } | IDENT "last" -> { loc, false } ]];
- ssrorelse: [[ "||"; tac = tactic_expr LEVEL "2" -> { tac } ]];
+ ssrorelse: [[ "||"; tac = ltac_expr LEVEL "2" -> { tac } ]];
ssrseqarg: [
[ arg = ssrswap -> { noindex, swaptacarg arg }
| i = ssrseqidx; tac = ssrortacarg; def = OPT ssrorelse -> { i, (tac, def) }
| i = ssrseqidx; arg = ssrswap -> { i, swaptacarg arg }
- | tac = tactic_expr LEVEL "3" -> { noindex, (mk_hint tac, None) }
+ | tac = ltac_expr LEVEL "3" -> { noindex, (mk_hint tac, None) }
] ];
END
{
-let tactic_expr = Pltac.tactic_expr
+let ltac_expr = Pltac.ltac_expr
}
@@ -1688,9 +1688,9 @@ let tclintros_expr ?loc tac ipats =
}
GRAMMAR EXTEND Gram
- GLOBAL: tactic_expr;
- tactic_expr: LEVEL "1" [ RIGHTA
- [ tac = tactic_expr; intros = ssrintros_ne -> { tclintros_expr ~loc tac intros }
+ GLOBAL: ltac_expr;
+ ltac_expr: LEVEL "1" [ RIGHTA
+ [ tac = ltac_expr; intros = ssrintros_ne -> { tclintros_expr ~loc tac intros }
] ];
END
@@ -1704,9 +1704,9 @@ END
(* (Removing user-specified parentheses is dubious anyway). *)
GRAMMAR EXTEND Gram
- GLOBAL: tactic_expr;
- ssrparentacarg: [[ "("; tac = tactic_expr; ")" -> { CAst.make ~loc (Tacexp tac) } ]];
- tactic_expr: LEVEL "0" [[ arg = ssrparentacarg -> { TacArg arg } ]];
+ GLOBAL: ltac_expr;
+ ssrparentacarg: [[ "("; tac = ltac_expr; ")" -> { CAst.make ~loc (Tacexp tac) } ]];
+ ltac_expr: LEVEL "0" [[ arg = ssrparentacarg -> { TacArg arg } ]];
END
(** The internal "done" and "ssrautoprop" tactics. *)
@@ -1741,7 +1741,7 @@ let tclBY tac = Tacticals.New.tclTHEN tac (donetac ~-1)
(* The latter two are used in forward-chaining tactics (have, suffice, wlog) *)
(* and subgoal reordering tacticals (; first & ; last), respectively. *)
-(* Force use of the tactic_expr parsing entry, to rule out tick marks. *)
+(* Force use of the ltac_expr parsing entry, to rule out tick marks. *)
(** The "by" tactical. *)
@@ -1782,12 +1782,12 @@ let ssrdotac_expr ?loc n m tac clauses =
}
GRAMMAR EXTEND Gram
- GLOBAL: tactic_expr;
+ GLOBAL: ltac_expr;
ssrdotac: [
- [ tac = tactic_expr LEVEL "3" -> { mk_hint tac }
+ [ tac = ltac_expr LEVEL "3" -> { mk_hint tac }
| tacs = ssrortacarg -> { tacs }
] ];
- tactic_expr: LEVEL "3" [ RIGHTA
+ ltac_expr: LEVEL "3" [ RIGHTA
[ IDENT "do"; m = ssrmmod; tac = ssrdotac; clauses = ssrclauses ->
{ ssrdotac_expr ~loc noindex m tac clauses }
| IDENT "do"; tac = ssrortacarg; clauses = ssrclauses ->
@@ -1833,20 +1833,20 @@ let tclseq_expr ?loc tac dir arg =
}
GRAMMAR EXTEND Gram
- GLOBAL: tactic_expr;
+ GLOBAL: ltac_expr;
ssr_first: [
[ tac = ssr_first; ipats = ssrintros_ne -> { tclintros_expr ~loc tac ipats }
- | "["; tacl = LIST0 tactic_expr SEP "|"; "]" -> { TacFirst tacl }
+ | "["; tacl = LIST0 ltac_expr SEP "|"; "]" -> { TacFirst tacl }
] ];
ssr_first_else: [
[ tac1 = ssr_first; tac2 = ssrorelse -> { TacOrelse (tac1, tac2) }
| tac = ssr_first -> { tac } ]];
- tactic_expr: LEVEL "4" [ LEFTA
- [ tac1 = tactic_expr; ";"; IDENT "first"; tac2 = ssr_first_else ->
+ ltac_expr: LEVEL "4" [ LEFTA
+ [ tac1 = ltac_expr; ";"; IDENT "first"; tac2 = ssr_first_else ->
{ TacThen (tac1, tac2) }
- | tac = tactic_expr; ";"; IDENT "first"; arg = ssrseqarg ->
+ | tac = ltac_expr; ";"; IDENT "first"; arg = ssrseqarg ->
{ tclseq_expr ~loc tac L2R arg }
- | tac = tactic_expr; ";"; IDENT "last"; arg = ssrseqarg ->
+ | tac = ltac_expr; ";"; IDENT "last"; arg = ssrseqarg ->
{ tclseq_expr ~loc tac R2L arg }
] ];
END
@@ -1894,7 +1894,8 @@ let has_occ ((_, occ), _) = occ <> None
let gens_sep = function [], [] -> mt | _ -> spc
let pr_dgens pr_gen (gensl, clr) =
- let prgens s gens = str s ++ pr_list spc pr_gen gens in
+ let prgens s gens =
+ if CList.is_empty gens then mt () else str s ++ pr_list spc pr_gen gens in
let prdeps deps = prgens ": " deps ++ spc () ++ str "/" in
match gensl with
| [deps; []] -> prdeps deps ++ pr_clear pr_spc clr
@@ -2194,7 +2195,7 @@ END
let pr_ssrcongrarg _ _ _ ((n, f), dgens) =
(if n <= 0 then mt () else str " " ++ int n) ++
- str " " ++ pr_term f ++ pr_dgens pr_gen dgens
+ pr_term f ++ pr_dgens pr_gen dgens
}
@@ -2447,8 +2448,8 @@ END
(* The standard TACTIC EXTEND does not work for abstract *)
GRAMMAR EXTEND Gram
- GLOBAL: tactic_expr;
- tactic_expr: LEVEL "3"
+ GLOBAL: ltac_expr;
+ ltac_expr: LEVEL "3"
[ RIGHTA [ IDENT "abstract"; gens = ssrdgens ->
{ ssrtac_expr ~loc "abstract"
[Tacexpr.TacGeneric (None, Genarg.in_gen (Genarg.rawwit wit_ssrdgens) gens)] } ]];
diff --git a/plugins/ssr/ssrprinters.ml b/plugins/ssr/ssrprinters.ml
index e231ab1f87..ab36d4fc7c 100644
--- a/plugins/ssr/ssrprinters.ml
+++ b/plugins/ssr/ssrprinters.ml
@@ -75,11 +75,14 @@ let pr_hyp (SsrHyp (_, id)) = Id.print id
let pr_hyps = pr_list pr_spc pr_hyp
let pr_occ = function
- | Some (true, occ) -> str "{-" ++ pr_list pr_spc int occ ++ str "}"
- | Some (false, occ) -> str "{+" ++ pr_list pr_spc int occ ++ str "}"
+ | Some (true, occ) ->
+ if CList.is_empty occ then mt () else str "{-" ++ pr_list pr_spc int occ ++ str "}"
+ | Some (false, occ) ->
+ if CList.is_empty occ then mt () else str "{+" ++ pr_list pr_spc int occ ++ str "}"
| None -> str "{}"
-let pr_clear_ne clr = str "{" ++ pr_hyps clr ++ str "}"
+let pr_clear_ne clr =
+ if CList.is_empty clr then mt () else str "{" ++ pr_hyps clr ++ str "}"
let pr_clear sep clr = sep () ++ pr_clear_ne clr
let pr_dir = function L2R -> str "->" | R2L -> str "<-"
diff --git a/plugins/ssr/ssrvernac.mlg b/plugins/ssr/ssrvernac.mlg
index 4a907b2795..99cf197b78 100644
--- a/plugins/ssr/ssrvernac.mlg
+++ b/plugins/ssr/ssrvernac.mlg
@@ -85,7 +85,7 @@ let mk_pat c (na, t) = (c, na, t)
GRAMMAR EXTEND Gram
GLOBAL: binder_constr;
- ssr_rtype: [[ "return"; t = operconstr LEVEL "100" -> { mk_rtype t } ]];
+ ssr_rtype: [[ "return"; t = term LEVEL "100" -> { mk_rtype t } ]];
ssr_mpat: [[ p = pattern -> { [[p]] } ]];
ssr_dpat: [
[ mp = ssr_mpat; "in"; t = pattern; rt = ssr_rtype -> { mp, mk_ctype mp t, rt }
@@ -96,9 +96,9 @@ GRAMMAR EXTEND Gram
ssr_elsepat: [[ "else" -> { [[CAst.make ~loc @@ CPatAtom None]] } ]];
ssr_else: [[ mp = ssr_elsepat; c = lconstr -> { CAst.make ~loc (mp, c) } ]];
binder_constr: [
- [ "if"; c = operconstr LEVEL "200"; "is"; db1 = ssr_dthen; b2 = ssr_else ->
+ [ "if"; c = term LEVEL "200"; "is"; db1 = ssr_dthen; b2 = ssr_else ->
{ let b1, ct, rt = db1 in CAst.make ~loc @@ CCases (MatchStyle, rt, [mk_pat c ct], [b1; b2]) }
- | "if"; c = operconstr LEVEL "200";"isn't";db1 = ssr_dthen; b2 = ssr_else ->
+ | "if"; c = term LEVEL "200";"isn't";db1 = ssr_dthen; b2 = ssr_else ->
{ let b1, ct, rt = db1 in
let b1, b2 = let open CAst in
let {loc=l1; v=(p1, r1)}, {loc=l2; v=(p2, r2)} = b1, b2 in
@@ -119,7 +119,7 @@ END
GRAMMAR EXTEND Gram
GLOBAL: closed_binder;
closed_binder: [
- [ ["of" -> { () } | "&" -> { () } ]; c = operconstr LEVEL "99" ->
+ [ ["of" -> { () } | "&" -> { () } ]; c = term LEVEL "99" ->
{ [CLocalAssum ([CAst.make ~loc Anonymous], Default Explicit, c)] }
] ];
END
@@ -304,15 +304,6 @@ END
{
- let warn_search_moved_enabled = ref true
- let warn_search_moved = CWarnings.create ~name:"ssr-search-moved"
- ~category:"deprecated" ~default:CWarnings.Enabled
- (fun () ->
- (Pp.strbrk
- "SSReflect's Search command has been moved to the \
- ssrsearch module; please Require that module if you \
- still want to use SSReflect's Search command"))
-
open G_vernac
}
@@ -322,7 +313,6 @@ GRAMMAR EXTEND Gram
query_command:
[ [ IDENT "Search"; s = search_query; l = search_queries; "." ->
{ let (sl,m) = l in
- if !warn_search_moved_enabled then warn_search_moved ();
fun g ->
Vernacexpr.VernacSearch (Vernacexpr.Search (s::sl),g, m) }
] ]
diff --git a/plugins/ssr/ssrvernac.mli b/plugins/ssr/ssrvernac.mli
index 93339313f0..327a2d4660 100644
--- a/plugins/ssr/ssrvernac.mli
+++ b/plugins/ssr/ssrvernac.mli
@@ -9,5 +9,3 @@
(************************************************************************)
(* This file is (C) Copyright 2006-2015 Microsoft Corporation and Inria. *)
-
-val warn_search_moved_enabled : bool ref
diff --git a/plugins/ssrmatching/ssrmatching.ml b/plugins/ssrmatching/ssrmatching.ml
index 5dedae6388..bd514f15d5 100644
--- a/plugins/ssrmatching/ssrmatching.ml
+++ b/plugins/ssrmatching/ssrmatching.ml
@@ -204,7 +204,8 @@ exception NoProgress
(* comparison can be much faster than the HO one. *)
let unif_EQ env sigma p c =
- let evars = existential_opt_value0 sigma, Evd.universes sigma in
+ let env = Environ.set_universes (Evd.universes sigma) env in
+ let evars = existential_opt_value0 sigma in
try let _ = Reduction.conv env p ~evars c in true with _ -> false
let unif_EQ_args env sigma pa a =
@@ -462,8 +463,8 @@ let nb_cs_proj_args pc f u =
try match kind f with
| Prod _ -> na Prod_cs
| Sort s -> na (Sort_cs (Sorts.family s))
- | Const (c',_) when Constant.equal c' pc -> nargs_of_proj u.up_f
- | Proj (c',_) when Constant.equal (Projection.constant c') pc -> nargs_of_proj u.up_f
+ | Const (c',_) when Constant.CanOrd.equal c' pc -> nargs_of_proj u.up_f
+ | Proj (c',_) when Constant.CanOrd.equal (Projection.constant c') pc -> nargs_of_proj u.up_f
| Var _ | Ind _ | Construct _ | Const _ -> na (Const_cs (fst @@ destRef f))
| _ -> -1
with Not_found -> -1
@@ -507,7 +508,7 @@ let filter_upat i0 f n u fpats =
let () = if !i0 < np then i0 := n in (u, np) :: fpats
let eq_prim_proj c t = match kind t with
- | Proj(p,_) -> Constant.equal (Projection.constant p) c
+ | Proj(p,_) -> Constant.CanOrd.equal (Projection.constant p) c
| _ -> false
let filter_upat_FO i0 f n u fpats =
diff --git a/plugins/ssrsearch/g_search.mlg b/plugins/ssrsearch/g_search.mlg
index 5e002e09cc..54fdea0860 100644
--- a/plugins/ssrsearch/g_search.mlg
+++ b/plugins/ssrsearch/g_search.mlg
@@ -301,10 +301,6 @@ let ssrdisplaysearch gr env t =
let pr_res = pr_global gr ++ str ":" ++ spc () ++ pr_lconstr_env env Evd.empty t in
Feedback.msg_notice (hov 2 pr_res ++ fnl ())
-(* Remove the warning entirely when this plugin is loaded. *)
-let _ =
- Ssreflect_plugin.Ssrvernac.warn_search_moved_enabled := false
-
let deprecated_search =
CWarnings.create
~name:"deprecated-ssr-search"
diff --git a/plugins/syntax/dune b/plugins/syntax/dune
index b395695c8a..f930fc265a 100644
--- a/plugins/syntax/dune
+++ b/plugins/syntax/dune
@@ -1,22 +1,8 @@
(library
- (name numeral_notation_plugin)
- (public_name coq.plugins.numeral_notation)
- (synopsis "Coq numeral notation plugin")
- (modules g_numeral numeral)
- (libraries coq.vernac))
-
-(library
- (name string_notation_plugin)
- (public_name coq.plugins.string_notation)
- (synopsis "Coq string notation plugin")
- (modules g_string string_notation)
- (libraries coq.vernac))
-
-(library
- (name r_syntax_plugin)
- (public_name coq.plugins.r_syntax)
- (synopsis "Coq syntax plugin: reals")
- (modules r_syntax)
+ (name number_string_notation_plugin)
+ (public_name coq.plugins.number_string_notation)
+ (synopsis "Coq number and string notation plugin")
+ (modules g_number_string string_notation number)
(libraries coq.vernac))
(library
@@ -33,4 +19,4 @@
(modules float_syntax)
(libraries coq.vernac))
-(coq.pp (modules g_numeral g_string))
+(coq.pp (modules g_number_string))
diff --git a/plugins/syntax/g_number_string.mlg b/plugins/syntax/g_number_string.mlg
new file mode 100644
index 0000000000..c8badd238d
--- /dev/null
+++ b/plugins/syntax/g_number_string.mlg
@@ -0,0 +1,110 @@
+(************************************************************************)
+(* * The Coq Proof Assistant / The Coq Development Team *)
+(* v * Copyright INRIA, CNRS and contributors *)
+(* <O___,, * (see version control and CREDITS file for authors & dates) *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(* * (see LICENSE file for the text of the license) *)
+(************************************************************************)
+
+DECLARE PLUGIN "number_string_notation_plugin"
+
+{
+
+open Notation
+open Number
+open String_notation
+open Pp
+open Names
+open Stdarg
+open Pcoq.Prim
+
+let pr_number_after = function
+ | Nop -> mt ()
+ | Warning n -> str "warning after " ++ NumTok.UnsignedNat.print n
+ | Abstract n -> str "abstract after " ++ NumTok.UnsignedNat.print n
+
+let pr_deprecated_number_modifier m = str "(" ++ pr_number_after m ++ str ")"
+
+let warn_deprecated_numeral_notation =
+ CWarnings.create ~name:"numeral-notation" ~category:"deprecated"
+ (fun () ->
+ strbrk "Numeral Notation is deprecated, please use Number Notation instead.")
+
+let pr_number_string_mapping (b, n, n') =
+ if b then
+ str "[" ++ Libnames.pr_qualid n ++ str "]" ++ spc () ++ str "=>" ++ spc ()
+ ++ Libnames.pr_qualid n'
+ else
+ Libnames.pr_qualid n ++ spc () ++ str "=>" ++ spc ()
+ ++ Libnames.pr_qualid n'
+
+let pr_number_string_via (n, l) =
+ str "via " ++ Libnames.pr_qualid n ++ str " mapping ["
+ ++ prlist_with_sep pr_comma pr_number_string_mapping l ++ str "]"
+
+let pr_number_modifier = function
+ | After a -> pr_number_after a
+ | Via nl -> pr_number_string_via nl
+
+let pr_number_options l =
+ str "(" ++ prlist_with_sep pr_comma pr_number_modifier l ++ str ")"
+
+let pr_string_option l =
+ str "(" ++ pr_number_string_via l ++ str ")"
+
+}
+
+VERNAC ARGUMENT EXTEND deprecated_number_modifier
+ PRINTED BY { pr_deprecated_number_modifier }
+| [ ] -> { Nop }
+| [ "(" "warning" "after" bignat(waft) ")" ] -> { Warning (NumTok.UnsignedNat.of_string waft) }
+| [ "(" "abstract" "after" bignat(n) ")" ] -> { Abstract (NumTok.UnsignedNat.of_string n) }
+END
+
+VERNAC ARGUMENT EXTEND number_string_mapping
+ PRINTED BY { pr_number_string_mapping }
+| [ reference(n) "=>" reference(n') ] -> { false, n, n' }
+| [ "[" reference(n) "]" "=>" reference(n') ] -> { true, n, n' }
+END
+
+VERNAC ARGUMENT EXTEND number_string_via
+ PRINTED BY { pr_number_string_via }
+| [ "via" reference(n) "mapping" "[" ne_number_string_mapping_list_sep(l, ",") "]" ] -> { n, l }
+END
+
+VERNAC ARGUMENT EXTEND number_modifier
+ PRINTED BY { pr_number_modifier }
+| [ "warning" "after" bignat(waft) ] -> { After (Warning (NumTok.UnsignedNat.of_string waft)) }
+| [ "abstract" "after" bignat(n) ] -> { After (Abstract (NumTok.UnsignedNat.of_string n)) }
+| [ number_string_via(v) ] -> { Via v }
+END
+
+VERNAC ARGUMENT EXTEND number_options
+ PRINTED BY { pr_number_options }
+| [ "(" ne_number_modifier_list_sep(l, ",") ")" ] -> { l }
+END
+
+VERNAC ARGUMENT EXTEND string_option
+ PRINTED BY { pr_string_option }
+| [ "(" number_string_via(v) ")" ] -> { v }
+END
+
+VERNAC COMMAND EXTEND NumberNotation CLASSIFIED AS SIDEFF
+ | #[ locality = Attributes.locality; ] [ "Number" "Notation" reference(ty) reference(f) reference(g) number_options_opt(nl) ":"
+ ident(sc) ] ->
+
+ { vernac_number_notation (Locality.make_module_locality locality) ty f g (Option.default [] nl) (Id.to_string sc) }
+ | #[ locality = Attributes.locality; ] [ "Numeral" "Notation" reference(ty) reference(f) reference(g) ":"
+ ident(sc) deprecated_number_modifier(o) ] ->
+
+ { warn_deprecated_numeral_notation ();
+ vernac_number_notation (Locality.make_module_locality locality) ty f g [After o] (Id.to_string sc) }
+END
+
+VERNAC COMMAND EXTEND StringNotation CLASSIFIED AS SIDEFF
+ | #[ locality = Attributes.locality; ] [ "String" "Notation" reference(ty) reference(f) reference(g) string_option_opt(o) ":"
+ ident(sc) ] ->
+ { vernac_string_notation (Locality.make_module_locality locality) ty f g o (Id.to_string sc) }
+END
diff --git a/plugins/syntax/g_numeral.mlg b/plugins/syntax/g_numeral.mlg
deleted file mode 100644
index c030925ea9..0000000000
--- a/plugins/syntax/g_numeral.mlg
+++ /dev/null
@@ -1,51 +0,0 @@
-(************************************************************************)
-(* * The Coq Proof Assistant / The Coq Development Team *)
-(* v * Copyright INRIA, CNRS and contributors *)
-(* <O___,, * (see version control and CREDITS file for authors & dates) *)
-(* \VV/ **************************************************************)
-(* // * This file is distributed under the terms of the *)
-(* * GNU Lesser General Public License Version 2.1 *)
-(* * (see LICENSE file for the text of the license) *)
-(************************************************************************)
-
-DECLARE PLUGIN "numeral_notation_plugin"
-
-{
-
-open Notation
-open Numeral
-open Pp
-open Names
-open Stdarg
-open Pcoq.Prim
-
-let pr_numnot_option = function
- | Nop -> mt ()
- | Warning n -> str "(warning after " ++ NumTok.UnsignedNat.print n ++ str ")"
- | Abstract n -> str "(abstract after " ++ NumTok.UnsignedNat.print n ++ str ")"
-
-let warn_deprecated_numeral_notation =
- CWarnings.create ~name:"numeral-notation" ~category:"deprecated"
- (fun () ->
- strbrk "Numeral Notation is deprecated, please use Number Notation instead.")
-
-}
-
-VERNAC ARGUMENT EXTEND numnotoption
- PRINTED BY { pr_numnot_option }
-| [ ] -> { Nop }
-| [ "(" "warning" "after" bignat(waft) ")" ] -> { Warning (NumTok.UnsignedNat.of_string waft) }
-| [ "(" "abstract" "after" bignat(n) ")" ] -> { Abstract (NumTok.UnsignedNat.of_string n) }
-END
-
-VERNAC COMMAND EXTEND NumeralNotation CLASSIFIED AS SIDEFF
- | #[ locality = Attributes.locality; ] [ "Number" "Notation" reference(ty) reference(f) reference(g) ":"
- ident(sc) numnotoption(o) ] ->
-
- { vernac_numeral_notation (Locality.make_module_locality locality) ty f g (Id.to_string sc) o }
- | #[ locality = Attributes.locality; ] [ "Numeral" "Notation" reference(ty) reference(f) reference(g) ":"
- ident(sc) numnotoption(o) ] ->
-
- { warn_deprecated_numeral_notation ();
- vernac_numeral_notation (Locality.make_module_locality locality) ty f g (Id.to_string sc) o }
-END
diff --git a/plugins/syntax/g_string.mlg b/plugins/syntax/g_string.mlg
deleted file mode 100644
index 788f9e011d..0000000000
--- a/plugins/syntax/g_string.mlg
+++ /dev/null
@@ -1,25 +0,0 @@
-(************************************************************************)
-(* * The Coq Proof Assistant / The Coq Development Team *)
-(* v * Copyright INRIA, CNRS and contributors *)
-(* <O___,, * (see version control and CREDITS file for authors & dates) *)
-(* \VV/ **************************************************************)
-(* // * This file is distributed under the terms of the *)
-(* * GNU Lesser General Public License Version 2.1 *)
-(* * (see LICENSE file for the text of the license) *)
-(************************************************************************)
-
-DECLARE PLUGIN "string_notation_plugin"
-
-{
-
-open String_notation
-open Names
-open Stdarg
-
-}
-
-VERNAC COMMAND EXTEND StringNotation CLASSIFIED AS SIDEFF
- | #[ locality = Attributes.locality; ] [ "String" "Notation" reference(ty) reference(f) reference(g) ":"
- ident(sc) ] ->
- { vernac_string_notation (Locality.make_module_locality locality) ty f g (Id.to_string sc) }
-END
diff --git a/plugins/syntax/int63_syntax.ml b/plugins/syntax/int63_syntax.ml
index 5f4db8e800..b14b02f3bb 100644
--- a/plugins/syntax/int63_syntax.ml
+++ b/plugins/syntax/int63_syntax.ml
@@ -43,6 +43,7 @@ let _ =
let id_int63 = Nametab.locate q_id_int63 in
let o = { to_kind = Int63, Direct;
to_ty = id_int63;
+ to_post = [||];
of_kind = Int63, Direct;
of_ty = id_int63;
ty_name = q_int63;
@@ -50,7 +51,7 @@ let _ =
enable_prim_token_interpretation
{ pt_local = false;
pt_scope = int63_scope;
- pt_interp_info = NumeralNotation o;
+ pt_interp_info = NumberNotation o;
pt_required = (int63_path, int63_module);
pt_refs = [];
pt_in_match = false })
diff --git a/plugins/syntax/number.ml b/plugins/syntax/number.ml
new file mode 100644
index 0000000000..89d757a72a
--- /dev/null
+++ b/plugins/syntax/number.ml
@@ -0,0 +1,505 @@
+(************************************************************************)
+(* * The Coq Proof Assistant / The Coq Development Team *)
+(* v * Copyright INRIA, CNRS and contributors *)
+(* <O___,, * (see version control and CREDITS file for authors & dates) *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(* * (see LICENSE file for the text of the license) *)
+(************************************************************************)
+
+open Pp
+open Util
+open Names
+open Libnames
+open Constrexpr
+open Constrexpr_ops
+open Notation
+
+module CSet = CSet.Make (Constr)
+module CMap = CMap.Make (Constr)
+
+(** * Number notation *)
+
+type number_string_via = qualid * (bool * qualid * qualid) list
+type number_option =
+ | After of numnot_option
+ | Via of number_string_via
+
+let warn_abstract_large_num_no_op =
+ CWarnings.create ~name:"abstract-large-number-no-op" ~category:"numbers"
+ (fun f ->
+ strbrk "The 'abstract after' directive has no effect when " ++
+ strbrk "the parsing function (" ++
+ Nametab.pr_global_env (Termops.vars_of_env (Global.env ())) f ++ strbrk ") targets an " ++
+ strbrk "option type.")
+
+let get_constructors ind =
+ let mib,oib = Global.lookup_inductive ind in
+ let mc = oib.Declarations.mind_consnames in
+ Array.to_list
+ (Array.mapi (fun j c -> GlobRef.ConstructRef (ind, j + 1)) mc)
+
+let qualid_of_ref n =
+ n |> Coqlib.lib_ref |> Nametab.shortest_qualid_of_global Id.Set.empty
+
+let q_option () = qualid_of_ref "core.option.type"
+
+let unsafe_locate_ind q =
+ match Nametab.locate q with
+ | GlobRef.IndRef i -> i
+ | _ -> raise Not_found
+
+let locate_z () =
+ let zn = "num.Z.type" in
+ let pn = "num.pos.type" in
+ if Coqlib.has_ref zn && Coqlib.has_ref pn
+ then
+ let q_z = qualid_of_ref zn in
+ let q_pos = qualid_of_ref pn in
+ Some ({
+ z_ty = unsafe_locate_ind q_z;
+ pos_ty = unsafe_locate_ind q_pos;
+ }, mkRefC q_z)
+ else None
+
+let locate_number () =
+ let dint = "num.int.type" in
+ let duint = "num.uint.type" in
+ let dec = "num.decimal.type" in
+ let hint = "num.hexadecimal_int.type" in
+ let huint = "num.hexadecimal_uint.type" in
+ let hex = "num.hexadecimal.type" in
+ let int = "num.num_int.type" in
+ let uint = "num.num_uint.type" in
+ let num = "num.number.type" in
+ if Coqlib.has_ref dint && Coqlib.has_ref duint && Coqlib.has_ref dec
+ && Coqlib.has_ref hint && Coqlib.has_ref huint && Coqlib.has_ref hex
+ && Coqlib.has_ref int && Coqlib.has_ref uint && Coqlib.has_ref num
+ then
+ let q_dint = qualid_of_ref dint in
+ let q_duint = qualid_of_ref duint in
+ let q_dec = qualid_of_ref dec in
+ let q_hint = qualid_of_ref hint in
+ let q_huint = qualid_of_ref huint in
+ let q_hex = qualid_of_ref hex in
+ let q_int = qualid_of_ref int in
+ let q_uint = qualid_of_ref uint in
+ let q_num = qualid_of_ref num in
+ let int_ty = {
+ dec_int = unsafe_locate_ind q_dint;
+ dec_uint = unsafe_locate_ind q_duint;
+ hex_int = unsafe_locate_ind q_hint;
+ hex_uint = unsafe_locate_ind q_huint;
+ int = unsafe_locate_ind q_int;
+ uint = unsafe_locate_ind q_uint;
+ } in
+ let num_ty = {
+ int = int_ty;
+ decimal = unsafe_locate_ind q_dec;
+ hexadecimal = unsafe_locate_ind q_hex;
+ number = unsafe_locate_ind q_num;
+ } in
+ Some (int_ty, mkRefC q_int, mkRefC q_uint, mkRefC q_dint, mkRefC q_duint,
+ num_ty, mkRefC q_num, mkRefC q_dec)
+ else None
+
+let locate_int63 () =
+ let int63n = "num.int63.type" in
+ if Coqlib.has_ref int63n
+ then
+ let q_int63 = qualid_of_ref int63n in
+ Some (mkRefC q_int63)
+ else None
+
+let has_type env sigma f ty =
+ let c = mkCastC (mkRefC f, Glob_term.CastConv ty) in
+ try let _ = Constrintern.interp_constr env sigma c in true
+ with Pretype_errors.PretypeError _ -> false
+
+let type_error_to f ty =
+ CErrors.user_err
+ (pr_qualid f ++ str " should go from Number.int to " ++
+ pr_qualid ty ++ str " or (option " ++ pr_qualid ty ++ str ")." ++
+ fnl () ++ str "Instead of Number.int, the types Number.uint or Z or Int63.int or Number.number could be used (you may need to require BinNums or Number or Int63 first).")
+
+let type_error_of g ty =
+ CErrors.user_err
+ (pr_qualid g ++ str " should go from " ++ pr_qualid ty ++
+ str " to Number.int or (option Number.int)." ++ fnl () ++
+ str "Instead of Number.int, the types Number.uint or Z or Int63.int or Number.number could be used (you may need to require BinNums or Number or Int63 first).")
+
+let warn_deprecated_decimal =
+ CWarnings.create ~name:"decimal-numeral-notation" ~category:"deprecated"
+ (fun () ->
+ strbrk "Deprecated Number Notation for Decimal.uint, \
+ Decimal.int or Decimal.decimal. Use Number.uint, \
+ Number.int or Number.number respectively.")
+
+let error_params ind =
+ CErrors.user_err
+ (str "Wrong number of parameters for inductive" ++ spc ()
+ ++ Printer.pr_global (GlobRef.IndRef ind) ++ str ".")
+
+let remapping_error ?loc ty ty' ty'' =
+ CErrors.user_err ?loc
+ (Printer.pr_global ty
+ ++ str " was already mapped to" ++ spc () ++ Printer.pr_global ty'
+ ++ str " and cannot be remapped to" ++ spc () ++ Printer.pr_global ty''
+ ++ str ".")
+
+let error_missing c =
+ CErrors.user_err
+ (str "Missing mapping for constructor " ++ Printer.pr_global c ++ str ".")
+
+let pr_constr env sigma c =
+ let c = Constrextern.extern_constr env sigma (EConstr.of_constr c) in
+ Ppconstr.pr_constr_expr env sigma c
+
+let warn_via_remapping =
+ CWarnings.create ~name:"via-type-remapping" ~category:"numbers"
+ (fun (env, sigma, ty, ty', ty'') ->
+ let constr = pr_constr env sigma in
+ constr ty ++ str " was already mapped to" ++ spc () ++ constr ty'
+ ++ str ", mapping it also to" ++ spc () ++ constr ty''
+ ++ str " might yield ill typed terms when using the notation.")
+
+let warn_via_type_mismatch =
+ CWarnings.create ~name:"via-type-mismatch" ~category:"numbers"
+ (fun (env, sigma, g, g', exp, actual) ->
+ let constr = pr_constr env sigma in
+ str "Type of" ++ spc() ++ Printer.pr_global g
+ ++ str " seems incompatible with the type of" ++ spc ()
+ ++ Printer.pr_global g' ++ str "." ++ spc ()
+ ++ str "Expected type is: " ++ constr exp ++ spc ()
+ ++ str "instead of " ++ constr actual ++ str "." ++ spc ()
+ ++ str "This might yield ill typed terms when using the notation.")
+
+let multiple_via_error () =
+ CErrors.user_err (Pp.str "Multiple 'via' options.")
+
+let multiple_after_error () =
+ CErrors.user_err (Pp.str "Multiple 'warning after' or 'abstract after' options.")
+
+let via_abstract_error () =
+ CErrors.user_err (Pp.str "'via' and 'abstract' cannot be used together.")
+
+let locate_global_sort_inductive_or_constant sigma qid =
+ let locate_sort qid =
+ match Nametab.locate_extended qid with
+ | Globnames.TrueGlobal _ -> raise Not_found
+ | Globnames.SynDef kn ->
+ match Syntax_def.search_syntactic_definition kn with
+ | [], Notation_term.NSort r ->
+ let sigma,c = Evd.fresh_sort_in_family sigma (Glob_ops.glob_sort_family r) in
+ sigma,Constr.mkSort c
+ | _ -> raise Not_found in
+ try locate_sort qid
+ with Not_found ->
+ match Smartlocate.global_with_alias qid with
+ | GlobRef.IndRef i -> sigma, Constr.mkInd i
+ | _ -> sigma, Constr.mkConst (Smartlocate.global_constant_with_alias qid)
+
+let locate_global_constructor_inductive_or_constant qid =
+ let g = Smartlocate.global_with_alias qid in
+ match g with
+ | GlobRef.ConstructRef c -> g, Constr.mkConstruct c
+ | GlobRef.IndRef i -> g, Constr.mkInd i
+ | _ -> g, Constr.mkConst (Smartlocate.global_constant_with_alias qid)
+
+(* [get_type env sigma c] retrieves the type of [c] and returns a pair
+ [l, t] such that [c : l_0 -> ... -> l_n -> t]. *)
+let get_type env sigma c =
+ (* inspired from [compute_implicit_names] in "interp/impargs.ml" *)
+ let rec aux env acc t =
+ let t = Reductionops.whd_all env sigma t in
+ match EConstr.kind sigma t with
+ | Constr.Prod (na, a, b) ->
+ let a = Reductionops.whd_all env sigma a in
+ let rel = Context.Rel.Declaration.LocalAssum (na, a) in
+ aux (EConstr.push_rel rel env) ((na, a) :: acc) b
+ | _ -> List.rev acc, t in
+ let t = Retyping.get_type_of env sigma (EConstr.of_constr c) in
+ let l, t = aux env [] t in
+ List.map (fun (na, a) -> na, EConstr.Unsafe.to_constr a) l,
+ EConstr.Unsafe.to_constr t
+
+(* [elaborate_to_post_params env sigma ty_ind params] builds the
+ [to_post] translation (c.f., interp/notation.mli) for the numeral
+ notation to parse/print type [ty_ind]. This translation is the
+ identity ([ToPostCopy]) except that it checks ([ToPostCheck]) that
+ the parameters of the inductive type [ty_ind] match the ones given
+ in [params]. *)
+let elaborate_to_post_params env sigma ty_ind params =
+ let to_post_for_constructor indc =
+ let sigma, c = match indc with
+ | GlobRef.ConstructRef c ->
+ let sigma,c = Evd.fresh_constructor_instance env sigma c in
+ sigma, Constr.mkConstructU c
+ | _ -> assert false in (* c.f. get_constructors *)
+ let args, t = get_type env sigma c in
+ let params_indc = match Constr.kind t with
+ | Constr.App (_, a) -> Array.to_list a | _ -> [] in
+ let sz = List.length args in
+ let a = Array.make sz ToPostCopy in
+ if List.length params <> List.length params_indc then error_params ty_ind;
+ List.iter2 (fun param param_indc ->
+ match param, Constr.kind param_indc with
+ | Some p, Constr.Rel i when i <= sz -> a.(sz - i) <- ToPostCheck p
+ | _ -> ())
+ params params_indc;
+ indc, indc, Array.to_list a in
+ let pt_refs = get_constructors ty_ind in
+ let to_post_0 = List.map to_post_for_constructor pt_refs in
+ let to_post =
+ let only_copy (_, _, args) = List.for_all ((=) ToPostCopy) args in
+ if (List.for_all only_copy to_post_0) then [||] else [|to_post_0|] in
+ to_post, pt_refs
+
+(* [elaborate_to_post_via env sigma ty_name ty_ind l] builds the [to_post]
+ translation (c.f., interp/notation.mli) for the number notation to
+ parse/print type [ty_name] through the inductive [ty_ind] according
+ to the pairs [constant, constructor] in the list [l]. *)
+let elaborate_to_post_via env sigma ty_name ty_ind l =
+ let sigma, ty_name =
+ locate_global_sort_inductive_or_constant sigma ty_name in
+ let ty_ind = Constr.mkInd ty_ind in
+ (* Retrieve constants and constructors mappings and their type.
+ For each constant [cnst] and inductive constructor [indc] in [l], retrieve:
+ * its location: [lcnst] and [lindc]
+ * its GlobRef: [cnst] and [indc]
+ * its type: [tcnst] and [tindc] (decomposed in product by [get_type] above)
+ * [impls] are the implicit arguments of [cnst] *)
+ let l =
+ let read (consider_implicits, cnst, indc) =
+ let lcnst, lindc = cnst.CAst.loc, indc.CAst.loc in
+ let cnst, ccnst = locate_global_constructor_inductive_or_constant cnst in
+ let indc, cindc =
+ let indc = Smartlocate.global_constructor_with_alias indc in
+ GlobRef.ConstructRef indc, Constr.mkConstruct indc in
+ let get_type_wo_params c =
+ (* ignore parameters of inductive types *)
+ let rm_params c = match Constr.kind c with
+ | Constr.App (c, _) when Constr.isInd c -> c
+ | _ -> c in
+ let lc, tc = get_type env sigma c in
+ List.map (fun (n, c) -> n, rm_params c) lc, rm_params tc in
+ let tcnst, tindc = get_type_wo_params ccnst, get_type_wo_params cindc in
+ let impls =
+ if not consider_implicits then [] else
+ Impargs.(select_stronger_impargs (implicits_of_global cnst)) in
+ lcnst, cnst, tcnst, lindc, indc, tindc, impls in
+ List.map read l in
+ let eq_indc indc (_, _, _, _, indc', _, _) = GlobRef.equal indc indc' in
+ (* Collect all inductive types involved.
+ That is [ty_ind] and all final codomains of [tindc] above. *)
+ let inds =
+ List.fold_left (fun s (_, _, _, _, _, tindc, _) -> CSet.add (snd tindc) s)
+ (CSet.singleton ty_ind) l in
+ (* And for each inductive, retrieve its constructors. *)
+ let constructors =
+ CSet.fold (fun ind m ->
+ let inductive, _ = Constr.destInd ind in
+ CMap.add ind (get_constructors inductive) m)
+ inds CMap.empty in
+ (* Error if one [constructor] in some inductive in [inds]
+ doesn't appear exactly once in [l] *)
+ let _ = (* check_for duplicate constructor and error *)
+ List.fold_left (fun already_seen (_, cnst, _, loc, indc, _, _) ->
+ try
+ let cnst' = List.assoc_f GlobRef.equal indc already_seen in
+ remapping_error ?loc indc cnst' cnst
+ with Not_found -> (indc, cnst) :: already_seen)
+ [] l in
+ let () = (* check for missing constructor and error *)
+ CMap.iter (fun _ ->
+ List.iter (fun cstr ->
+ if not (List.exists (eq_indc cstr) l) then error_missing cstr))
+ constructors in
+ (* Perform some checks on types and warn if they look strange.
+ These checks are neither sound nor complete, so we only warn. *)
+ let () =
+ (* associate inductives to types, and check that this mapping is one to one
+ and maps [ty_ind] to [ty_name] *)
+ let ind2ty, ty2ind =
+ let add loc ckey cval m =
+ match CMap.find_opt ckey m with
+ | None -> CMap.add ckey cval m
+ | Some old_cval ->
+ if not (Constr.equal old_cval cval) then
+ warn_via_remapping ?loc (env, sigma, ckey, old_cval, cval);
+ m in
+ List.fold_left
+ (fun (ind2ty, ty2ind) (lcnst, _, (_, tcnst), lindc, _, (_, tindc), _) ->
+ add lcnst tindc tcnst ind2ty, add lindc tcnst tindc ty2ind)
+ CMap.(singleton ty_ind ty_name, singleton ty_name ty_ind) l in
+ (* check that type of constants and constructors mapped in [l]
+ match modulo [ind2ty] *)
+ let rm_impls impls (l, t) =
+ let rec aux impls l = match impls, l with
+ | Some _ :: impls, _ :: b -> aux impls b
+ | None :: impls, (n, a) :: b -> (n, a) :: aux impls b
+ | _ -> l in
+ aux impls l, t in
+ let replace m (l, t) =
+ let apply_m c = try CMap.find c m with Not_found -> c in
+ List.fold_right (fun (na, a) b -> Constr.mkProd (na, (apply_m a), b))
+ l (apply_m t) in
+ List.iter (fun (_, cnst, tcnst, loc, indc, tindc, impls) ->
+ let tcnst = rm_impls impls tcnst in
+ let tcnst' = replace CMap.empty tcnst in
+ if not (Constr.equal tcnst' (replace ind2ty tindc)) then
+ let actual = replace CMap.empty tindc in
+ let expected = replace ty2ind tcnst in
+ warn_via_type_mismatch ?loc (env, sigma, indc, cnst, expected, actual))
+ l in
+ (* Associate an index to each inductive, starting from 0 for [ty_ind]. *)
+ let ind2num, num2ind, nb_ind =
+ CMap.fold (fun ind _ (ind2num, num2ind, i) ->
+ CMap.add ind i ind2num, Int.Map.add i ind num2ind, i + 1)
+ (CMap.remove ty_ind constructors)
+ (CMap.singleton ty_ind 0, Int.Map.singleton 0 ty_ind, 1) in
+ (* Finally elaborate [to_post] *)
+ let to_post =
+ let rec map_prod impls tindc = match impls with
+ | Some _ :: impls -> ToPostHole :: map_prod impls tindc
+ | _ ->
+ match tindc with
+ | [] -> []
+ | (_, a) :: b ->
+ let t = match CMap.find_opt a ind2num with
+ | Some i -> ToPostAs i
+ | None -> ToPostCopy in
+ let impls = match impls with [] -> [] | _ :: t -> t in
+ t :: map_prod impls b in
+ Array.init nb_ind (fun i ->
+ List.map (fun indc ->
+ let _, cnst, _, _, _, tindc, impls = List.find (eq_indc indc) l in
+ indc, cnst, map_prod impls (fst tindc))
+ (CMap.find (Int.Map.find i num2ind) constructors)) in
+ (* and use constants mapped to constructors of [ty_ind] as triggers. *)
+ let pt_refs = List.map (fun (_, cnst, _) -> cnst) (to_post.(0)) in
+ to_post, pt_refs
+
+let locate_global_inductive allow_params qid =
+ let locate_param_inductive qid =
+ match Nametab.locate_extended qid with
+ | Globnames.TrueGlobal _ -> raise Not_found
+ | Globnames.SynDef kn ->
+ match Syntax_def.search_syntactic_definition kn with
+ | [], Notation_term.(NApp (NRef (GlobRef.IndRef i), l)) when allow_params ->
+ i,
+ List.map (function
+ | Notation_term.NRef r -> Some r
+ | Notation_term.NHole _ -> None
+ | _ -> raise Not_found) l
+ | _ -> raise Not_found in
+ try locate_param_inductive qid
+ with Not_found -> Smartlocate.global_inductive_with_alias qid, []
+
+let vernac_number_notation local ty f g opts scope =
+ let rec parse_opts = function
+ | [] -> None, Nop
+ | h :: opts ->
+ let via, opts = parse_opts opts in
+ let via = match h, via with
+ | Via _, Some _ -> multiple_via_error ()
+ | Via v, None -> Some v
+ | _ -> via in
+ let opts = match h, opts with
+ | After _, (Warning _ | Abstract _) -> multiple_after_error ()
+ | After a, Nop -> a
+ | _ -> opts in
+ via, opts in
+ let via, opts = parse_opts opts in
+ (match via, opts with Some _, Abstract _ -> via_abstract_error () | _ -> ());
+ let env = Global.env () in
+ let sigma = Evd.from_env env in
+ let num_ty = locate_number () in
+ let z_pos_ty = locate_z () in
+ let int63_ty = locate_int63 () in
+ let ty_name = ty in
+ let ty, via =
+ match via with None -> ty, via | Some (ty', a) -> ty', Some (ty, a) in
+ let tyc, params = locate_global_inductive (via = None) ty in
+ let to_ty = Smartlocate.global_with_alias f in
+ let of_ty = Smartlocate.global_with_alias g in
+ let cty = mkRefC ty in
+ let app x y = mkAppC (x,[y]) in
+ let arrow x y =
+ mkProdC ([CAst.make Anonymous],Default Glob_term.Explicit, x, y)
+ in
+ let opt r = app (mkRefC (q_option ())) r in
+ (* Check the type of f *)
+ let to_kind =
+ match num_ty with
+ | Some (int_ty, cint, _, _, _, _, _, _) when has_type env sigma f (arrow cint cty) -> Int int_ty, Direct
+ | Some (int_ty, cint, _, _, _, _, _, _) when has_type env sigma f (arrow cint (opt cty)) -> Int int_ty, Option
+ | Some (int_ty, _, cuint, _, _, _, _, _) when has_type env sigma f (arrow cuint cty) -> UInt int_ty, Direct
+ | Some (int_ty, _, cuint, _, _, _, _, _) when has_type env sigma f (arrow cuint (opt cty)) -> UInt int_ty, Option
+ | Some (_, _, _, _, _, num_ty, cnum, _) when has_type env sigma f (arrow cnum cty) -> Number num_ty, Direct
+ | Some (_, _, _, _, _, num_ty, cnum, _) when has_type env sigma f (arrow cnum (opt cty)) -> Number num_ty, Option
+ | Some (int_ty, _, _, cint, _, _, _, _) when has_type env sigma f (arrow cint cty) -> DecimalInt int_ty, Direct
+ | Some (int_ty, _, _, cint, _, _, _, _) when has_type env sigma f (arrow cint (opt cty)) -> DecimalInt int_ty, Option
+ | Some (int_ty, _, _, _, cuint, _, _, _) when has_type env sigma f (arrow cuint cty) -> DecimalUInt int_ty, Direct
+ | Some (int_ty, _, _, _, cuint, _, _, _) when has_type env sigma f (arrow cuint (opt cty)) -> DecimalUInt int_ty, Option
+ | Some (_, _, _, _, _, num_ty, _, cdec) when has_type env sigma f (arrow cdec cty) -> Decimal num_ty, Direct
+ | Some (_, _, _, _, _, num_ty, _, cdec) when has_type env sigma f (arrow cdec (opt cty)) -> Decimal num_ty, Option
+ | _ ->
+ match z_pos_ty with
+ | Some (z_pos_ty, cZ) when has_type env sigma f (arrow cZ cty) -> Z z_pos_ty, Direct
+ | Some (z_pos_ty, cZ) when has_type env sigma f (arrow cZ (opt cty)) -> Z z_pos_ty, Option
+ | _ ->
+ match int63_ty with
+ | Some cint63 when has_type env sigma f (arrow cint63 cty) -> Int63, Direct
+ | Some cint63 when has_type env sigma f (arrow cint63 (opt cty)) -> Int63, Option
+ | _ -> type_error_to f ty
+ in
+ (* Check the type of g *)
+ let of_kind =
+ match num_ty with
+ | Some (int_ty, cint, _, _, _, _, _, _) when has_type env sigma g (arrow cty cint) -> Int int_ty, Direct
+ | Some (int_ty, cint, _, _, _, _, _, _) when has_type env sigma g (arrow cty (opt cint)) -> Int int_ty, Option
+ | Some (int_ty, _, cuint, _, _, _, _, _) when has_type env sigma g (arrow cty cuint) -> UInt int_ty, Direct
+ | Some (int_ty, _, cuint, _, _, _, _, _) when has_type env sigma g (arrow cty (opt cuint)) -> UInt int_ty, Option
+ | Some (_, _, _, _, _, num_ty, cnum, _) when has_type env sigma g (arrow cty cnum) -> Number num_ty, Direct
+ | Some (_, _, _, _, _, num_ty, cnum, _) when has_type env sigma g (arrow cty (opt cnum)) -> Number num_ty, Option
+ | Some (int_ty, _, _, cint, _, _, _, _) when has_type env sigma g (arrow cty cint) -> DecimalInt int_ty, Direct
+ | Some (int_ty, _, _, cint, _, _, _, _) when has_type env sigma g (arrow cty (opt cint)) -> DecimalInt int_ty, Option
+ | Some (int_ty, _, _, _, cuint, _, _, _) when has_type env sigma g (arrow cty cuint) -> DecimalUInt int_ty, Direct
+ | Some (int_ty, _, _, _, cuint, _, _, _) when has_type env sigma g (arrow cty (opt cuint)) -> DecimalUInt int_ty, Option
+ | Some (_, _, _, _, _, num_ty, _, cdec) when has_type env sigma g (arrow cty cdec) -> Decimal num_ty, Direct
+ | Some (_, _, _, _, _, num_ty, _, cdec) when has_type env sigma g (arrow cty (opt cdec)) -> Decimal num_ty, Option
+ | _ ->
+ match z_pos_ty with
+ | Some (z_pos_ty, cZ) when has_type env sigma g (arrow cty cZ) -> Z z_pos_ty, Direct
+ | Some (z_pos_ty, cZ) when has_type env sigma g (arrow cty (opt cZ)) -> Z z_pos_ty, Option
+ | _ ->
+ match int63_ty with
+ | Some cint63 when has_type env sigma g (arrow cty cint63) -> Int63, Direct
+ | Some cint63 when has_type env sigma g (arrow cty (opt cint63)) -> Int63, Option
+ | _ -> type_error_of g ty
+ in
+ (match to_kind, of_kind with
+ | ((DecimalInt _ | DecimalUInt _ | Decimal _), _), _
+ | _, ((DecimalInt _ | DecimalUInt _ | Decimal _), _) ->
+ warn_deprecated_decimal ()
+ | _ -> ());
+ let to_post, pt_refs = match via with
+ | None -> elaborate_to_post_params env sigma tyc params
+ | Some (ty, l) -> elaborate_to_post_via env sigma ty tyc l in
+ let o = { to_kind; to_ty; to_post; of_kind; of_ty; ty_name;
+ warning = opts }
+ in
+ (match opts, to_kind with
+ | Abstract _, (_, Option) -> warn_abstract_large_num_no_op o.to_ty
+ | _ -> ());
+ let i =
+ { pt_local = local;
+ pt_scope = scope;
+ pt_interp_info = NumberNotation o;
+ pt_required = Nametab.path_of_global (GlobRef.IndRef tyc),[];
+ pt_refs;
+ pt_in_match = true }
+ in
+ enable_prim_token_interpretation i
diff --git a/plugins/syntax/number.mli b/plugins/syntax/number.mli
new file mode 100644
index 0000000000..d7d28b29ed
--- /dev/null
+++ b/plugins/syntax/number.mli
@@ -0,0 +1,31 @@
+(************************************************************************)
+(* * The Coq Proof Assistant / The Coq Development Team *)
+(* v * Copyright INRIA, CNRS and contributors *)
+(* <O___,, * (see version control and CREDITS file for authors & dates) *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(* * (see LICENSE file for the text of the license) *)
+(************************************************************************)
+
+open Libnames
+open Vernacexpr
+open Notation
+
+(** * Number notation *)
+
+type number_string_via = qualid * (bool * qualid * qualid) list
+type number_option =
+ | After of numnot_option
+ | Via of number_string_via
+
+val vernac_number_notation : locality_flag ->
+ qualid ->
+ qualid -> qualid ->
+ number_option list ->
+ Notation_term.scope_name -> unit
+
+(** These are also used in string notations *)
+val locate_global_inductive : bool -> Libnames.qualid -> Names.inductive * Names.GlobRef.t option list
+val elaborate_to_post_params : Environ.env -> Evd.evar_map -> Names.inductive -> Names.GlobRef.t option list -> (Names.GlobRef.t * Names.GlobRef.t * Notation.to_post_arg list) list array * Names.GlobRef.t list
+val elaborate_to_post_via : Environ.env -> Evd.evar_map -> Libnames.qualid -> Names.inductive -> (bool * Libnames.qualid * Libnames.qualid) list -> (Names.GlobRef.t * Names.GlobRef.t * Notation.to_post_arg list) list array * Names.GlobRef.t list
diff --git a/plugins/syntax/number_string_notation_plugin.mlpack b/plugins/syntax/number_string_notation_plugin.mlpack
new file mode 100644
index 0000000000..74c32d3a53
--- /dev/null
+++ b/plugins/syntax/number_string_notation_plugin.mlpack
@@ -0,0 +1,3 @@
+Number
+String_notation
+G_number_string
diff --git a/plugins/syntax/numeral.ml b/plugins/syntax/numeral.ml
deleted file mode 100644
index 2db76719b8..0000000000
--- a/plugins/syntax/numeral.ml
+++ /dev/null
@@ -1,217 +0,0 @@
-(************************************************************************)
-(* * The Coq Proof Assistant / The Coq Development Team *)
-(* v * Copyright INRIA, CNRS and contributors *)
-(* <O___,, * (see version control and CREDITS file for authors & dates) *)
-(* \VV/ **************************************************************)
-(* // * This file is distributed under the terms of the *)
-(* * GNU Lesser General Public License Version 2.1 *)
-(* * (see LICENSE file for the text of the license) *)
-(************************************************************************)
-
-open Pp
-open Util
-open Names
-open Libnames
-open Constrexpr
-open Constrexpr_ops
-open Notation
-
-(** * Numeral notation *)
-
-let warn_abstract_large_num_no_op =
- CWarnings.create ~name:"abstract-large-number-no-op" ~category:"numbers"
- (fun f ->
- strbrk "The 'abstract after' directive has no effect when " ++
- strbrk "the parsing function (" ++
- Nametab.pr_global_env (Termops.vars_of_env (Global.env ())) f ++ strbrk ") targets an " ++
- strbrk "option type.")
-
-let get_constructors ind =
- let mib,oib = Global.lookup_inductive ind in
- let mc = oib.Declarations.mind_consnames in
- Array.to_list
- (Array.mapi (fun j c -> GlobRef.ConstructRef (ind, j + 1)) mc)
-
-let qualid_of_ref n =
- n |> Coqlib.lib_ref |> Nametab.shortest_qualid_of_global Id.Set.empty
-
-let q_option () = qualid_of_ref "core.option.type"
-
-let unsafe_locate_ind q =
- match Nametab.locate q with
- | GlobRef.IndRef i -> i
- | _ -> raise Not_found
-
-let locate_z () =
- let zn = "num.Z.type" in
- let pn = "num.pos.type" in
- if Coqlib.has_ref zn && Coqlib.has_ref pn
- then
- let q_z = qualid_of_ref zn in
- let q_pos = qualid_of_ref pn in
- Some ({
- z_ty = unsafe_locate_ind q_z;
- pos_ty = unsafe_locate_ind q_pos;
- }, mkRefC q_z)
- else None
-
-let locate_numeral () =
- let dint = "num.int.type" in
- let duint = "num.uint.type" in
- let dec = "num.decimal.type" in
- let hint = "num.hexadecimal_int.type" in
- let huint = "num.hexadecimal_uint.type" in
- let hex = "num.hexadecimal.type" in
- let int = "num.num_int.type" in
- let uint = "num.num_uint.type" in
- let num = "num.numeral.type" in
- if Coqlib.has_ref dint && Coqlib.has_ref duint && Coqlib.has_ref dec
- && Coqlib.has_ref hint && Coqlib.has_ref huint && Coqlib.has_ref hex
- && Coqlib.has_ref int && Coqlib.has_ref uint && Coqlib.has_ref num
- then
- let q_dint = qualid_of_ref dint in
- let q_duint = qualid_of_ref duint in
- let q_dec = qualid_of_ref dec in
- let q_hint = qualid_of_ref hint in
- let q_huint = qualid_of_ref huint in
- let q_hex = qualid_of_ref hex in
- let q_int = qualid_of_ref int in
- let q_uint = qualid_of_ref uint in
- let q_num = qualid_of_ref num in
- let int_ty = {
- dec_int = unsafe_locate_ind q_dint;
- dec_uint = unsafe_locate_ind q_duint;
- hex_int = unsafe_locate_ind q_hint;
- hex_uint = unsafe_locate_ind q_huint;
- int = unsafe_locate_ind q_int;
- uint = unsafe_locate_ind q_uint;
- } in
- let num_ty = {
- int = int_ty;
- decimal = unsafe_locate_ind q_dec;
- hexadecimal = unsafe_locate_ind q_hex;
- numeral = unsafe_locate_ind q_num;
- } in
- Some (int_ty, mkRefC q_int, mkRefC q_uint, mkRefC q_dint, mkRefC q_duint,
- num_ty, mkRefC q_num, mkRefC q_dec)
- else None
-
-let locate_int63 () =
- let int63n = "num.int63.type" in
- if Coqlib.has_ref int63n
- then
- let q_int63 = qualid_of_ref int63n in
- Some (mkRefC q_int63)
- else None
-
-let has_type env sigma f ty =
- let c = mkCastC (mkRefC f, Glob_term.CastConv ty) in
- try let _ = Constrintern.interp_constr env sigma c in true
- with Pretype_errors.PretypeError _ -> false
-
-let type_error_to f ty =
- CErrors.user_err
- (pr_qualid f ++ str " should go from Numeral.int to " ++
- pr_qualid ty ++ str " or (option " ++ pr_qualid ty ++ str ")." ++
- fnl () ++ str "Instead of Numeral.int, the types Numeral.uint or Z or Int63.int or Numeral.numeral could be used (you may need to require BinNums or Numeral or Int63 first).")
-
-let type_error_of g ty =
- CErrors.user_err
- (pr_qualid g ++ str " should go from " ++ pr_qualid ty ++
- str " to Numeral.int or (option Numeral.int)." ++ fnl () ++
- str "Instead of Numeral.int, the types Numeral.uint or Z or Int63.int or Numeral.numeral could be used (you may need to require BinNums or Numeral or Int63 first).")
-
-let warn_deprecated_decimal =
- CWarnings.create ~name:"decimal-numeral-notation" ~category:"deprecated"
- (fun () ->
- strbrk "Deprecated Numeral Notation for Decimal.uint, \
- Decimal.int or Decimal.decimal. Use Numeral.uint, \
- Numeral.int or Numeral.numeral respectively.")
-
-let vernac_numeral_notation local ty f g scope opts =
- let env = Global.env () in
- let sigma = Evd.from_env env in
- let num_ty = locate_numeral () in
- let z_pos_ty = locate_z () in
- let int63_ty = locate_int63 () in
- let tyc = Smartlocate.global_inductive_with_alias ty in
- let to_ty = Smartlocate.global_with_alias f in
- let of_ty = Smartlocate.global_with_alias g in
- let cty = mkRefC ty in
- let app x y = mkAppC (x,[y]) in
- let arrow x y =
- mkProdC ([CAst.make Anonymous],Default Glob_term.Explicit, x, y)
- in
- let opt r = app (mkRefC (q_option ())) r in
- let constructors = get_constructors tyc in
- (* Check the type of f *)
- let to_kind =
- match num_ty with
- | Some (int_ty, cint, _, _, _, _, _, _) when has_type env sigma f (arrow cint cty) -> Int int_ty, Direct
- | Some (int_ty, cint, _, _, _, _, _, _) when has_type env sigma f (arrow cint (opt cty)) -> Int int_ty, Option
- | Some (int_ty, _, cuint, _, _, _, _, _) when has_type env sigma f (arrow cuint cty) -> UInt int_ty, Direct
- | Some (int_ty, _, cuint, _, _, _, _, _) when has_type env sigma f (arrow cuint (opt cty)) -> UInt int_ty, Option
- | Some (_, _, _, _, _, num_ty, cnum, _) when has_type env sigma f (arrow cnum cty) -> Numeral num_ty, Direct
- | Some (_, _, _, _, _, num_ty, cnum, _) when has_type env sigma f (arrow cnum (opt cty)) -> Numeral num_ty, Option
- | Some (int_ty, _, _, cint, _, _, _, _) when has_type env sigma f (arrow cint cty) -> DecimalInt int_ty, Direct
- | Some (int_ty, _, _, cint, _, _, _, _) when has_type env sigma f (arrow cint (opt cty)) -> DecimalInt int_ty, Option
- | Some (int_ty, _, _, _, cuint, _, _, _) when has_type env sigma f (arrow cuint cty) -> DecimalUInt int_ty, Direct
- | Some (int_ty, _, _, _, cuint, _, _, _) when has_type env sigma f (arrow cuint (opt cty)) -> DecimalUInt int_ty, Option
- | Some (_, _, _, _, _, num_ty, _, cdec) when has_type env sigma f (arrow cdec cty) -> Decimal num_ty, Direct
- | Some (_, _, _, _, _, num_ty, _, cdec) when has_type env sigma f (arrow cdec (opt cty)) -> Decimal num_ty, Option
- | _ ->
- match z_pos_ty with
- | Some (z_pos_ty, cZ) when has_type env sigma f (arrow cZ cty) -> Z z_pos_ty, Direct
- | Some (z_pos_ty, cZ) when has_type env sigma f (arrow cZ (opt cty)) -> Z z_pos_ty, Option
- | _ ->
- match int63_ty with
- | Some cint63 when has_type env sigma f (arrow cint63 cty) -> Int63, Direct
- | Some cint63 when has_type env sigma f (arrow cint63 (opt cty)) -> Int63, Option
- | _ -> type_error_to f ty
- in
- (* Check the type of g *)
- let of_kind =
- match num_ty with
- | Some (int_ty, cint, _, _, _, _, _, _) when has_type env sigma g (arrow cty cint) -> Int int_ty, Direct
- | Some (int_ty, cint, _, _, _, _, _, _) when has_type env sigma g (arrow cty (opt cint)) -> Int int_ty, Option
- | Some (int_ty, _, cuint, _, _, _, _, _) when has_type env sigma g (arrow cty cuint) -> UInt int_ty, Direct
- | Some (int_ty, _, cuint, _, _, _, _, _) when has_type env sigma g (arrow cty (opt cuint)) -> UInt int_ty, Option
- | Some (_, _, _, _, _, num_ty, cnum, _) when has_type env sigma g (arrow cty cnum) -> Numeral num_ty, Direct
- | Some (_, _, _, _, _, num_ty, cnum, _) when has_type env sigma g (arrow cty (opt cnum)) -> Numeral num_ty, Option
- | Some (int_ty, _, _, cint, _, _, _, _) when has_type env sigma g (arrow cty cint) -> DecimalInt int_ty, Direct
- | Some (int_ty, _, _, cint, _, _, _, _) when has_type env sigma g (arrow cty (opt cint)) -> DecimalInt int_ty, Option
- | Some (int_ty, _, _, _, cuint, _, _, _) when has_type env sigma g (arrow cty cuint) -> DecimalUInt int_ty, Direct
- | Some (int_ty, _, _, _, cuint, _, _, _) when has_type env sigma g (arrow cty (opt cuint)) -> DecimalUInt int_ty, Option
- | Some (_, _, _, _, _, num_ty, _, cdec) when has_type env sigma g (arrow cty cdec) -> Decimal num_ty, Direct
- | Some (_, _, _, _, _, num_ty, _, cdec) when has_type env sigma g (arrow cty (opt cdec)) -> Decimal num_ty, Option
- | _ ->
- match z_pos_ty with
- | Some (z_pos_ty, cZ) when has_type env sigma g (arrow cty cZ) -> Z z_pos_ty, Direct
- | Some (z_pos_ty, cZ) when has_type env sigma g (arrow cty (opt cZ)) -> Z z_pos_ty, Option
- | _ ->
- match int63_ty with
- | Some cint63 when has_type env sigma g (arrow cty cint63) -> Int63, Direct
- | Some cint63 when has_type env sigma g (arrow cty (opt cint63)) -> Int63, Option
- | _ -> type_error_of g ty
- in
- (match to_kind, of_kind with
- | ((DecimalInt _ | DecimalUInt _ | Decimal _), _), _
- | _, ((DecimalInt _ | DecimalUInt _ | Decimal _), _) ->
- warn_deprecated_decimal ()
- | _ -> ());
- let o = { to_kind; to_ty; of_kind; of_ty;
- ty_name = ty;
- warning = opts }
- in
- (match opts, to_kind with
- | Abstract _, (_, Option) -> warn_abstract_large_num_no_op o.to_ty
- | _ -> ());
- let i =
- { pt_local = local;
- pt_scope = scope;
- pt_interp_info = NumeralNotation o;
- pt_required = Nametab.path_of_global (GlobRef.IndRef tyc),[];
- pt_refs = constructors;
- pt_in_match = true }
- in
- enable_prim_token_interpretation i
diff --git a/plugins/syntax/numeral.mli b/plugins/syntax/numeral.mli
deleted file mode 100644
index 99252484b4..0000000000
--- a/plugins/syntax/numeral.mli
+++ /dev/null
@@ -1,19 +0,0 @@
-(************************************************************************)
-(* * The Coq Proof Assistant / The Coq Development Team *)
-(* v * Copyright INRIA, CNRS and contributors *)
-(* <O___,, * (see version control and CREDITS file for authors & dates) *)
-(* \VV/ **************************************************************)
-(* // * This file is distributed under the terms of the *)
-(* * GNU Lesser General Public License Version 2.1 *)
-(* * (see LICENSE file for the text of the license) *)
-(************************************************************************)
-
-open Libnames
-open Vernacexpr
-open Notation
-
-(** * Numeral notation *)
-
-val vernac_numeral_notation : locality_flag ->
- qualid -> qualid -> qualid ->
- Notation_term.scope_name -> numnot_option -> unit
diff --git a/plugins/syntax/numeral_notation_plugin.mlpack b/plugins/syntax/numeral_notation_plugin.mlpack
deleted file mode 100644
index f4d9cae3ff..0000000000
--- a/plugins/syntax/numeral_notation_plugin.mlpack
+++ /dev/null
@@ -1,2 +0,0 @@
-Numeral
-G_numeral
diff --git a/plugins/syntax/r_syntax.ml b/plugins/syntax/r_syntax.ml
deleted file mode 100644
index d66b9537b4..0000000000
--- a/plugins/syntax/r_syntax.ml
+++ /dev/null
@@ -1,214 +0,0 @@
-(************************************************************************)
-(* * The Coq Proof Assistant / The Coq Development Team *)
-(* v * Copyright INRIA, CNRS and contributors *)
-(* <O___,, * (see version control and CREDITS file for authors & dates) *)
-(* \VV/ **************************************************************)
-(* // * This file is distributed under the terms of the *)
-(* * GNU Lesser General Public License Version 2.1 *)
-(* * (see LICENSE file for the text of the license) *)
-(************************************************************************)
-
-open Util
-open Names
-open Glob_term
-
-(* Poor's man DECLARE PLUGIN *)
-let __coq_plugin_name = "r_syntax_plugin"
-let () = Mltop.add_known_module __coq_plugin_name
-
-exception Non_closed_number
-
-(**********************************************************************)
-(* Parsing positive via scopes *)
-(**********************************************************************)
-
-let binnums = ["Coq";"Numbers";"BinNums"]
-
-let make_dir l = DirPath.make (List.rev_map Id.of_string l)
-let make_path dir id = Libnames.make_path (make_dir dir) (Id.of_string id)
-
-let is_gr c gr = match DAst.get c with
-| GRef (r, _) -> GlobRef.equal r gr
-| _ -> false
-
-let positive_modpath = MPfile (make_dir binnums)
-
-let positive_kn = MutInd.make2 positive_modpath (Label.make "positive")
-let path_of_xI = ((positive_kn,0),1)
-let path_of_xO = ((positive_kn,0),2)
-let path_of_xH = ((positive_kn,0),3)
-let glob_xI = GlobRef.ConstructRef path_of_xI
-let glob_xO = GlobRef.ConstructRef path_of_xO
-let glob_xH = GlobRef.ConstructRef path_of_xH
-
-let pos_of_bignat ?loc x =
- let ref_xI = DAst.make @@ GRef (glob_xI, None) in
- let ref_xH = DAst.make @@ GRef (glob_xH, None) in
- let ref_xO = DAst.make @@ GRef (glob_xO, None) in
- let rec pos_of x =
- match Z.(div_rem x (of_int 2)) with
- | (q,rem) when rem = Z.zero -> DAst.make @@ GApp (ref_xO,[pos_of q])
- | (q,_) when not Z.(equal q zero) -> DAst.make @@ GApp (ref_xI,[pos_of q])
- | (q,_) -> ref_xH
- in
- pos_of x
-
-(**********************************************************************)
-(* Printing positive via scopes *)
-(**********************************************************************)
-
-let rec bignat_of_pos c = match DAst.get c with
- | GApp (r, [a]) when is_gr r glob_xO -> Z.mul Z.(of_int 2) (bignat_of_pos a)
- | GApp (r, [a]) when is_gr r glob_xI -> Z.add Z.one Z.(mul (of_int 2) (bignat_of_pos a))
- | GRef (a, _) when GlobRef.equal a glob_xH -> Z.one
- | _ -> raise Non_closed_number
-
-(**********************************************************************)
-(* Parsing Z via scopes *)
-(**********************************************************************)
-
-let z_kn = MutInd.make2 positive_modpath (Label.make "Z")
-let path_of_ZERO = ((z_kn,0),1)
-let path_of_POS = ((z_kn,0),2)
-let path_of_NEG = ((z_kn,0),3)
-let glob_ZERO = GlobRef.ConstructRef path_of_ZERO
-let glob_POS = GlobRef.ConstructRef path_of_POS
-let glob_NEG = GlobRef.ConstructRef path_of_NEG
-
-let z_of_int ?loc n =
- if not Z.(equal n zero) then
- let sgn, n =
- if Z.(leq zero n) then glob_POS, n else glob_NEG, Z.neg n in
- DAst.make @@ GApp(DAst.make @@ GRef (sgn,None), [pos_of_bignat ?loc n])
- else
- DAst.make @@ GRef (glob_ZERO, None)
-
-(**********************************************************************)
-(* Printing Z via scopes *)
-(**********************************************************************)
-
-let bigint_of_z c = match DAst.get c with
- | GApp (r,[a]) when is_gr r glob_POS -> bignat_of_pos a
- | GApp (r,[a]) when is_gr r glob_NEG -> Z.neg (bignat_of_pos a)
- | GRef (a, _) when GlobRef.equal a glob_ZERO -> Z.zero
- | _ -> raise Non_closed_number
-
-(**********************************************************************)
-(* Parsing R via scopes *)
-(**********************************************************************)
-
-let rdefinitions = ["Coq";"Reals";"Rdefinitions"]
-let r_modpath = MPfile (make_dir rdefinitions)
-let r_base_modpath = MPdot (r_modpath, Label.make "RbaseSymbolsImpl")
-let r_path = make_path ["Coq";"Reals";"Rdefinitions";"RbaseSymbolsImpl"] "R"
-
-let glob_IZR = GlobRef.ConstRef (Constant.make2 r_modpath @@ Label.make "IZR")
-let glob_Rmult = GlobRef.ConstRef (Constant.make2 r_base_modpath @@ Label.make "Rmult")
-let glob_Rdiv = GlobRef.ConstRef (Constant.make2 r_modpath @@ Label.make "Rdiv")
-
-let binintdef = ["Coq";"ZArith";"BinIntDef"]
-let z_modpath = MPdot (MPfile (make_dir binintdef), Label.make "Z")
-
-let glob_pow_pos = GlobRef.ConstRef (Constant.make2 z_modpath @@ Label.make "pow_pos")
-
-let r_of_rawnum ?loc n =
- let n,e = NumTok.Signed.to_bigint_and_exponent n in
- let e,p = NumTok.(match e with EDec e -> e, 10 | EBin e -> e, 2) in
- let izr z =
- DAst.make @@ GApp (DAst.make @@ GRef(glob_IZR,None), [z]) in
- let rmult r r' =
- DAst.make @@ GApp (DAst.make @@ GRef(glob_Rmult,None), [r; r']) in
- let rdiv r r' =
- DAst.make @@ GApp (DAst.make @@ GRef(glob_Rdiv,None), [r; r']) in
- let pow p e =
- let p = z_of_int ?loc (Z.of_int p) in
- let e = pos_of_bignat e in
- DAst.make @@ GApp (DAst.make @@ GRef(glob_pow_pos,None), [p; e]) in
- let n =
- izr (z_of_int ?loc n) in
- if Int.equal (Z.sign e) 1 then rmult n (izr (pow p e))
- else if Int.equal (Z.sign e) (-1) then rdiv n (izr (pow p (Z.neg e)))
- else n (* e = 0 *)
-
-(**********************************************************************)
-(* Printing R via scopes *)
-(**********************************************************************)
-
-let rawnum_of_r c =
- (* print i * 10^e, precondition: e <> 0 *)
- let numTok_of_int_exp i e =
- (* choose between 123e-2 and 1.23, this is purely heuristic
- and doesn't play any soundness role *)
- let choose_exponent =
- if Int.equal (Z.sign e) 1 then
- true (* don't print 12 * 10^2 as 1200 to distinguish them *)
- else
- let i = Z.to_string i in
- let li = if i.[0] = '-' then String.length i - 1 else String.length i in
- let e = Z.neg e in
- let le = String.length (Z.to_string e) in
- Z.(lt (add (of_int li) (of_int le)) e) in
- (* print 123 * 10^-2 as 123e-2 *)
- let numTok_exponent () =
- NumTok.Signed.of_bigint_and_exponent i (NumTok.EDec e) in
- (* print 123 * 10^-2 as 1.23, precondition e < 0 *)
- let numTok_dot () =
- let s, i =
- if Z.sign i >= 0 then NumTok.SPlus, Z.to_string i
- else NumTok.SMinus, Z.(to_string (neg i)) in
- let ni = String.length i in
- let e = - (Z.to_int e) in
- assert (e > 0);
- let i, f =
- if e < ni then String.sub i 0 (ni - e), String.sub i (ni - e) e
- else "0", String.make (e - ni) '0' ^ i in
- let i = s, NumTok.UnsignedNat.of_string i in
- let f = NumTok.UnsignedNat.of_string f in
- NumTok.Signed.of_int_frac_and_exponent i (Some f) None in
- if choose_exponent then numTok_exponent () else numTok_dot () in
- match DAst.get c with
- | GApp (r, [a]) when is_gr r glob_IZR ->
- let n = bigint_of_z a in
- NumTok.(Signed.of_bigint CDec n)
- | GApp (md, [l; r]) when is_gr md glob_Rmult || is_gr md glob_Rdiv ->
- begin match DAst.get l, DAst.get r with
- | GApp (i, [l]), GApp (i', [r])
- when is_gr i glob_IZR && is_gr i' glob_IZR ->
- begin match DAst.get r with
- | GApp (p, [t; e]) when is_gr p glob_pow_pos ->
- let t = bigint_of_z t in
- if not (Z.(equal t (of_int 10))) then
- raise Non_closed_number
- else
- let i = bigint_of_z l in
- let e = bignat_of_pos e in
- let e = if is_gr md glob_Rdiv then Z.neg e else e in
- numTok_of_int_exp i e
- | _ -> raise Non_closed_number
- end
- | _ -> raise Non_closed_number
- end
- | _ -> raise Non_closed_number
-
-let uninterp_r (AnyGlobConstr p) =
- try
- Some (rawnum_of_r p)
- with Non_closed_number ->
- None
-
-open Notation
-
-let at_declare_ml_module f x =
- Mltop.declare_cache_obj (fun () -> f x) __coq_plugin_name
-
-let r_scope = "R_scope"
-
-let _ =
- register_rawnumeral_interpretation r_scope (r_of_rawnum,uninterp_r);
- at_declare_ml_module enable_prim_token_interpretation
- { pt_local = false;
- pt_scope = r_scope;
- pt_interp_info = Uid r_scope;
- pt_required = (r_path,["Coq";"Reals";"Rdefinitions"]);
- pt_refs = [glob_IZR; glob_Rmult; glob_Rdiv];
- pt_in_match = false }
diff --git a/plugins/syntax/r_syntax_plugin.mlpack b/plugins/syntax/r_syntax_plugin.mlpack
deleted file mode 100644
index d4ee75ea48..0000000000
--- a/plugins/syntax/r_syntax_plugin.mlpack
+++ /dev/null
@@ -1 +0,0 @@
-R_syntax
diff --git a/plugins/syntax/string_notation.ml b/plugins/syntax/string_notation.ml
index e7ed0d8061..774d59dda3 100644
--- a/plugins/syntax/string_notation.ml
+++ b/plugins/syntax/string_notation.ml
@@ -9,21 +9,15 @@
(************************************************************************)
open Pp
-open Util
open Names
open Libnames
open Constrexpr
open Constrexpr_ops
open Notation
+open Number
(** * String notation *)
-let get_constructors ind =
- let mib,oib = Global.lookup_inductive ind in
- let mc = oib.Declarations.mind_consnames in
- Array.to_list
- (Array.mapi (fun j c -> GlobRef.ConstructRef (ind, j + 1)) mc)
-
let qualid_of_ref n =
n |> Coqlib.lib_ref |> Nametab.shortest_qualid_of_global Id.Set.empty
@@ -46,7 +40,7 @@ let type_error_of g ty =
(pr_qualid g ++ str " should go from " ++ pr_qualid ty ++
str " to Byte.byte or (option Byte.byte) or (list Byte.byte) or (option (list Byte.byte)).")
-let vernac_string_notation local ty f g scope =
+let vernac_string_notation local ty f g via scope =
let env = Global.env () in
let sigma = Evd.from_env env in
let app x y = mkAppC (x,[y]) in
@@ -56,14 +50,16 @@ let vernac_string_notation local ty f g scope =
let coption = cref (q_option ()) in
let opt r = app coption r in
let clist_byte = app clist cbyte in
- let tyc = Smartlocate.global_inductive_with_alias ty in
+ let ty_name = ty in
+ let ty, via =
+ match via with None -> ty, via | Some (ty', a) -> ty', Some (ty, a) in
+ let tyc, params = locate_global_inductive (via = None) ty in
let to_ty = Smartlocate.global_with_alias f in
let of_ty = Smartlocate.global_with_alias g in
let cty = cref ty in
let arrow x y =
mkProdC ([CAst.make Anonymous],Default Glob_term.Explicit, x, y)
in
- let constructors = get_constructors tyc in
(* Check the type of f *)
let to_kind =
if has_type env sigma f (arrow clist_byte cty) then ListByte, Direct
@@ -80,11 +76,10 @@ let vernac_string_notation local ty f g scope =
else if has_type env sigma g (arrow cty (opt cbyte)) then Byte, Option
else type_error_of g ty
in
- let o = { to_kind = to_kind;
- to_ty = to_ty;
- of_kind = of_kind;
- of_ty = of_ty;
- ty_name = ty;
+ let to_post, pt_refs = match via with
+ | None -> elaborate_to_post_params env sigma tyc params
+ | Some (ty, l) -> elaborate_to_post_via env sigma ty tyc l in
+ let o = { to_kind; to_ty; to_post; of_kind; of_ty; ty_name;
warning = () }
in
let i =
@@ -92,7 +87,7 @@ let vernac_string_notation local ty f g scope =
pt_scope = scope;
pt_interp_info = StringNotation o;
pt_required = Nametab.path_of_global (GlobRef.IndRef tyc),[];
- pt_refs = constructors;
+ pt_refs;
pt_in_match = true }
in
enable_prim_token_interpretation i
diff --git a/plugins/syntax/string_notation.mli b/plugins/syntax/string_notation.mli
index 0d99f98d26..f3c7c969c6 100644
--- a/plugins/syntax/string_notation.mli
+++ b/plugins/syntax/string_notation.mli
@@ -14,5 +14,7 @@ open Vernacexpr
(** * String notation *)
val vernac_string_notation : locality_flag ->
- qualid -> qualid -> qualid ->
+ qualid ->
+ qualid -> qualid ->
+ Number.number_string_via option ->
Notation_term.scope_name -> unit
diff --git a/plugins/syntax/string_notation_plugin.mlpack b/plugins/syntax/string_notation_plugin.mlpack
deleted file mode 100644
index 6aa081dab4..0000000000
--- a/plugins/syntax/string_notation_plugin.mlpack
+++ /dev/null
@@ -1,2 +0,0 @@
-String_notation
-G_string
diff --git a/pretyping/cases.ml b/pretyping/cases.ml
index a459229256..4a29db0dcf 100644
--- a/pretyping/cases.ml
+++ b/pretyping/cases.ml
@@ -128,7 +128,8 @@ type 'a equation =
rhs : 'a rhs;
alias_stack : Name.t list;
eqn_loc : Loc.t option;
- used : bool ref }
+ used : int ref;
+ catch_all_vars : Id.t CAst.t list ref }
type 'a matrix = 'a equation list
@@ -514,7 +515,7 @@ let check_and_adjust_constructor env ind cstrs pat = match DAst.get pat with
let loc = pat.CAst.loc in
(* Check it is constructor of the right type *)
let ind' = inductive_of_constructor cstr in
- if eq_ind ind' ind then
+ if Ind.CanOrd.equal ind' ind then
(* Check the constructor has the right number of args *)
let ci = cstrs.(i-1) in
let nb_args_constr = ci.cs_nargs in
@@ -543,11 +544,34 @@ let check_all_variables env sigma typ mat =
error_bad_pattern ?loc env sigma cstr_sp typ)
mat
+let set_pattern_catch_all_var ?loc eqn = function
+ | Name id when not (Id.Set.mem id eqn.rhs.rhs_vars) ->
+ eqn.catch_all_vars := CAst.make ?loc id :: !(eqn.catch_all_vars)
+ | _ -> ()
+
+let warn_named_multi_catch_all =
+ CWarnings.create ~name:"unused-pattern-matching-variable" ~category:"pattern-matching"
+ (fun id ->
+ strbrk "Unused variable " ++ Id.print id ++ strbrk " catches more than one case.")
+
+let wildcard_id = Id.of_string "wildcard'"
+
+let is_wildcard id =
+ Id.equal (Id.of_string (Nameops.atompart_of_id id)) wildcard_id
+
let check_unused_pattern env eqn =
- if not !(eqn.used) then
- raise_pattern_matching_error ?loc:eqn.eqn_loc (env, Evd.empty, UnusedClause eqn.patterns)
+ match !(eqn.used) with
+ | 0 -> raise_pattern_matching_error ?loc:eqn.eqn_loc (env, Evd.empty, UnusedClause eqn.patterns)
+ | 1 -> ()
+ | _ ->
+ let warn {CAst.v = id; loc} =
+ (* Convention: Names starting with `_` and derivatives of Program's
+ "wildcard'" internal name deactivate the warning *)
+ if (Id.to_string id).[0] <> '_' && not (is_wildcard id)
+ then warn_named_multi_catch_all ?loc id in
+ List.iter warn !(eqn.catch_all_vars)
-let set_used_pattern eqn = eqn.used := true
+let set_used_pattern eqn = eqn.used := !(eqn.used) + 1
let extract_rhs pb =
match pb.mat with
@@ -1017,7 +1041,8 @@ let add_assert_false_case pb tomatch =
it = None };
alias_stack = Anonymous::aliasnames;
eqn_loc = None;
- used = ref false } ]
+ used = ref 0;
+ catch_all_vars = ref [] } ]
let adjust_impossible_cases sigma pb pred tomatch submat =
match submat with
@@ -1235,6 +1260,7 @@ let group_equations pb ind current cstrs mat =
let args = make_anonymous_patvars cstrs.(i-1).cs_nargs in
brs.(i-1) <- (args, name, rest) :: brs.(i-1)
done;
+ set_pattern_catch_all_var ?loc:pat.CAst.loc eqn name;
if !only_default == None then only_default := Some true
| PatCstr (((_,i)),args,name) ->
(* This is a regular clause *)
@@ -1602,7 +1628,8 @@ let matx_of_eqns env eqns =
{ patterns = initial_lpat;
alias_stack = [];
eqn_loc = loc;
- used = ref false;
+ used = ref 0;
+ catch_all_vars = ref [];
rhs = rhs }
in List.map build_eqn eqns
@@ -1859,7 +1886,8 @@ let build_inversion_problem ~program_mode loc env sigma tms t =
{ patterns = patl;
alias_stack = [];
eqn_loc = None;
- used = ref false;
+ used = ref 0;
+ catch_all_vars = ref [];
rhs = { rhs_env = pb_env;
(* we assume all vars are used; in practice we discard dependent
vars so that the field rhs_vars is normally not used *)
@@ -1879,7 +1907,8 @@ let build_inversion_problem ~program_mode loc env sigma tms t =
[ { patterns = List.map (fun _ -> DAst.make @@ PatVar Anonymous) patl;
alias_stack = [];
eqn_loc = None;
- used = ref false;
+ used = ref 0;
+ catch_all_vars = ref [];
rhs = { rhs_env = pb_env;
rhs_vars = Id.Set.empty;
avoid_ids = avoid0;
@@ -1936,7 +1965,7 @@ let extract_arity_signature ?(dolift=true) env0 tomatchl tmsign =
let realnal =
match t with
| Some {CAst.loc;v=(ind',realnal)} ->
- if not (eq_ind ind ind') then
+ if not (Ind.CanOrd.equal ind ind') then
user_err ?loc (str "Wrong inductive type.");
if not (Int.equal nrealargs_ctxt (List.length realnal)) then
anomaly (Pp.str "Ill-formed 'in' clause in cases.");
@@ -2149,7 +2178,7 @@ let constr_of_pat env sigma arsign pat avoid =
let name, avoid = match name with
Name n -> name, avoid
| Anonymous ->
- let previd, id = prime avoid (Name (Id.of_string "wildcard")) in
+ let id = next_ident_away wildcard_id avoid in
Name id, Id.Set.add id avoid
in
let r = Sorts.Relevant in (* TODO relevance *)
@@ -2164,7 +2193,7 @@ let constr_of_pat env sigma arsign pat avoid =
in
let (ind,u), params = dest_ind_family indf in
let params = List.map EConstr.of_constr params in
- if not (eq_ind ind cind) then error_bad_constructor ?loc env cstr ind;
+ if not (Ind.CanOrd.equal ind cind) then error_bad_constructor ?loc env cstr ind;
let cstrs = get_constructors env indf in
let ci = cstrs.(i-1) in
let nb_args_constr = ci.cs_nargs in
diff --git a/pretyping/cases.mli b/pretyping/cases.mli
index 8b1ec3aba0..9a986bc14c 100644
--- a/pretyping/cases.mli
+++ b/pretyping/cases.mli
@@ -68,7 +68,8 @@ type 'a equation =
rhs : 'a rhs;
alias_stack : Name.t list;
eqn_loc : Loc.t option;
- used : bool ref }
+ used : int ref;
+ catch_all_vars : Id.t CAst.t list ref }
type 'a matrix = 'a equation list
diff --git a/pretyping/coercion.ml b/pretyping/coercion.ml
index d759f82d35..6e6189796e 100644
--- a/pretyping/coercion.ml
+++ b/pretyping/coercion.ml
@@ -119,7 +119,7 @@ let disc_subset sigma x =
Ind (i,_) ->
let len = Array.length l in
let sigty = delayed_force sig_typ in
- if Int.equal len 2 && eq_ind i (Globnames.destIndRef sigty)
+ if Int.equal len 2 && Ind.CanOrd.equal i (Globnames.destIndRef sigty)
then
let (a, b) = pair_of_array l in
Some (a, b)
@@ -240,10 +240,10 @@ let coerce ?loc env sigma (x : EConstr.constr) (y : EConstr.constr)
let sigT = delayed_force sigT_typ in
let prod = delayed_force prod_typ in
(* Sigma types *)
- if Int.equal len (Array.length l') && Int.equal len 2 && eq_ind i i'
- && (eq_ind i (destIndRef sigT) || eq_ind i (destIndRef prod))
+ if Int.equal len (Array.length l') && Int.equal len 2 && Ind.CanOrd.equal i i'
+ && (Ind.CanOrd.equal i (destIndRef sigT) || Ind.CanOrd.equal i (destIndRef prod))
then
- if eq_ind i (destIndRef sigT)
+ if Ind.CanOrd.equal i (destIndRef sigT)
then
begin
let (a, pb), (a', pb') =
@@ -303,7 +303,7 @@ let coerce ?loc env sigma (x : EConstr.constr) (y : EConstr.constr)
papp sigma prod_intro [| a'; b'; x ; y |])
end
else
- if eq_ind i i' && Int.equal len (Array.length l') then
+ if Ind.CanOrd.equal i i' && Int.equal len (Array.length l') then
(try subco sigma
with NoSubtacCoercion ->
let sigma, typ = Typing.type_of env sigma c in
diff --git a/pretyping/coercionops.ml b/pretyping/coercionops.ml
index 0c3eaa1da9..8ddc576d83 100644
--- a/pretyping/coercionops.ml
+++ b/pretyping/coercionops.ml
@@ -57,7 +57,7 @@ let cl_typ_ord t1 t2 = match t1, t2 with
| CL_SECVAR v1, CL_SECVAR v2 -> Id.compare v1 v2
| CL_CONST c1, CL_CONST c2 -> Constant.CanOrd.compare c1 c2
| CL_PROJ c1, CL_PROJ c2 -> Projection.Repr.CanOrd.compare c1 c2
- | CL_IND i1, CL_IND i2 -> ind_ord i1 i2
+ | CL_IND i1, CL_IND i2 -> Ind.CanOrd.compare i1 i2
| _ -> pervasives_compare t1 t2 (** OK *)
module ClTyp = struct
diff --git a/pretyping/constr_matching.ml b/pretyping/constr_matching.ml
index 419eeaa92a..a3f1c0b004 100644
--- a/pretyping/constr_matching.ml
+++ b/pretyping/constr_matching.ml
@@ -244,9 +244,9 @@ let matches_core env sigma allow_bound_rels
let open GlobRef in
match ref, EConstr.kind sigma c with
| VarRef id, Var id' -> Names.Id.equal id id'
- | ConstRef c, Const (c',_) -> Constant.equal c c'
- | IndRef i, Ind (i', _) -> Names.eq_ind i i'
- | ConstructRef c, Construct (c',u) -> Names.eq_constructor c c'
+ | ConstRef c, Const (c',_) -> Environ.QConstant.equal env c c'
+ | IndRef i, Ind (i', _) -> Names.Ind.CanOrd.equal i i'
+ | ConstructRef c, Construct (c',u) -> Names.Construct.CanOrd.equal c c'
| _, _ -> false
in
let rec sorec ctx env subst p t =
@@ -307,11 +307,11 @@ let matches_core env sigma allow_bound_rels
| PApp (c1,arg1), App (c2,arg2) ->
(match c1, EConstr.kind sigma c2 with
- | PRef (GlobRef.ConstRef r), Proj (pr,c) when not (Constant.equal r (Projection.constant pr))
+ | PRef (GlobRef.ConstRef r), Proj (pr,c) when not (Environ.QConstant.equal env r (Projection.constant pr))
|| Projection.unfolded pr ->
raise PatternMatchingFailure
| PProj (pr1,c1), Proj (pr,c) ->
- if Projection.equal pr1 pr then
+ if Environ.QProjection.equal env pr1 pr then
try Array.fold_left2 (sorec ctx env) (sorec ctx env subst c1 c) arg1 arg2
with Invalid_argument _ -> raise PatternMatchingFailure
else raise PatternMatchingFailure
@@ -324,7 +324,7 @@ let matches_core env sigma allow_bound_rels
with Invalid_argument _ -> raise PatternMatchingFailure)
| PApp (PRef (GlobRef.ConstRef c1), _), Proj (pr, c2)
- when Projection.unfolded pr || not (Constant.equal c1 (Projection.constant pr)) ->
+ when Projection.unfolded pr || not (Environ.QConstant.equal env c1 (Projection.constant pr)) ->
raise PatternMatchingFailure
| PApp (c, args), Proj (pr, c2) ->
@@ -332,7 +332,7 @@ let matches_core env sigma allow_bound_rels
sorec ctx env subst p term
with Retyping.RetypeError _ -> raise PatternMatchingFailure)
- | PProj (p1,c1), Proj (p2,c2) when Projection.equal p1 p2 ->
+ | PProj (p1,c1), Proj (p2,c2) when Environ.QProjection.equal env p1 p2 ->
sorec ctx env subst c1 c2
| PProd (na1,c1,d1), Prod(na2,c2,d2) ->
@@ -374,7 +374,7 @@ let matches_core env sigma allow_bound_rels
| Some ind1 ->
(* ppedrot: Something spooky going here. The comparison used to be
the generic one, so I may have broken something. *)
- if not (eq_ind ind1 ci2.ci_ind) then raise PatternMatchingFailure
+ if not (Ind.CanOrd.equal ind1 ci2.ci_ind) then raise PatternMatchingFailure
in
let () =
if not ci1.cip_extensible && not (Int.equal (List.length br1) n2)
diff --git a/pretyping/detyping.ml b/pretyping/detyping.ml
index 7fcb0795bd..a12a832f76 100644
--- a/pretyping/detyping.ml
+++ b/pretyping/detyping.ml
@@ -715,9 +715,9 @@ and detype_r d flags avoid env sigma t =
(* Meta in constr are not user-parsable and are mapped to Evar *)
if n = Constr_matching.special_meta then
(* Using a dash to be unparsable *)
- GEvar (Id.of_string_soft "CONTEXT-HOLE", [])
+ GEvar (CAst.make @@ Id.of_string_soft "CONTEXT-HOLE", [])
else
- GEvar (Id.of_string_soft ("M" ^ string_of_int n), [])
+ GEvar (CAst.make @@ Id.of_string_soft ("M" ^ string_of_int n), [])
| Var id ->
(* Discriminate between section variable and non-section variable *)
(try let _ = Global.lookup_named id in GRef (GlobRef.VarRef id, None)
@@ -788,12 +788,12 @@ and detype_r d flags avoid env sigma t =
let l = Evd.evar_instance_array bound_to_itself_or_letin (Evd.find sigma evk) cl in
let fvs,rels = List.fold_left (fun (fvs,rels) (_,c) -> match EConstr.kind sigma c with Rel n -> (fvs,Int.Set.add n rels) | Var id -> (Id.Set.add id fvs,rels) | _ -> (fvs,rels)) (Id.Set.empty,Int.Set.empty) l in
let l = Evd.evar_instance_array (fun d c -> not !print_evar_arguments && (bound_to_itself_or_letin d c && not (isRel sigma c && Int.Set.mem (destRel sigma c) rels || isVar sigma c && (Id.Set.mem (destVar sigma c) fvs)))) (Evd.find sigma evk) cl in
- id,l
+ id,List.map (fun (id,c) -> (CAst.make id,c)) l
with Not_found ->
Id.of_string ("X" ^ string_of_int (Evar.repr evk)),
- (List.map (fun c -> (Id.of_string "__",c)) cl)
+ (List.map (fun c -> (CAst.make @@ Id.of_string "__",c)) cl)
in
- GEvar (id,
+ GEvar (CAst.make id,
List.map (on_snd (detype d flags avoid env sigma)) l)
| Ind (ind_sp,u) ->
GRef (GlobRef.IndRef ind_sp, detype_instance sigma u)
@@ -883,7 +883,12 @@ and detype_binder d flags bk avoid env sigma decl c =
| BLetIn ->
let c = detype d { flags with flg_isgoal = false } avoid env sigma (Option.get body) in
(* Heuristic: we display the type if in Prop *)
- let s = try Retyping.get_sort_family_of (snd env) sigma ty with _ when !Flags.in_debugger || !Flags.in_toplevel -> InType (* Can fail because of sigma missing in debugger *) in
+ let s =
+ (* It can fail if ty is an evar, or if run inside ocamldebug or the
+ OCaml toplevel since their printers don't have access to the proper sigma/env *)
+ try Retyping.get_sort_family_of (snd env) sigma ty
+ with Retyping.RetypeError _ -> InType
+ in
let t = if s != InProp && not !Flags.raw_print then None else Some (detype d { flags with flg_isgoal = false } avoid env sigma ty) in
GLetIn (na', c, t, r)
diff --git a/pretyping/evarconv.ml b/pretyping/evarconv.ml
index a5311e162d..90af143a2d 100644
--- a/pretyping/evarconv.ml
+++ b/pretyping/evarconv.ml
@@ -387,7 +387,7 @@ let ise_stack2 no_app env evd f sk1 sk2 =
| UnifFailure _ as x -> fail x)
| UnifFailure _ as x -> fail x)
| Stack.Proj (p1)::q1, Stack.Proj (p2)::q2 ->
- if Projection.Repr.equal (Projection.repr p1) (Projection.repr p2)
+ if QProjection.Repr.equal env (Projection.repr p1) (Projection.repr p2)
then ise_stack2 true i q1 q2
else fail (UnifFailure (i, NotSameHead))
| Stack.Fix (((li1, i1),(_,tys1,bds1 as recdef1)),a1)::q1,
@@ -429,7 +429,7 @@ let exact_ise_stack2 env evd f sk1 sk2 =
(fun i -> ise_stack2 i a1 a2)]
else UnifFailure (i,NotSameHead)
| Stack.Proj (p1)::q1, Stack.Proj (p2)::q2 ->
- if Projection.Repr.equal (Projection.repr p1) (Projection.repr p2)
+ if QProjection.Repr.equal env (Projection.repr p1) (Projection.repr p2)
then ise_stack2 i q1 q2
else (UnifFailure (i, NotSameHead))
| Stack.App _ :: _, Stack.App _ :: _ ->
@@ -566,11 +566,11 @@ and evar_eqappr_x ?(rhs_is_already_stuck = false) flags env evd pbty
in
let compare_heads evd =
match EConstr.kind evd term, EConstr.kind evd term' with
- | Const (c, u), Const (c', u') when Constant.equal c c' ->
+ | Const (c, u), Const (c', u') when QConstant.equal env c c' ->
let u = EInstance.kind evd u and u' = EInstance.kind evd u' in
check_strict evd u u'
| Const _, Const _ -> UnifFailure (evd, NotSameHead)
- | Ind ((mi,i) as ind , u), Ind (ind', u') when Names.eq_ind ind ind' ->
+ | Ind ((mi,i) as ind , u), Ind (ind', u') when Names.Ind.CanOrd.equal ind ind' ->
if EInstance.is_empty u && EInstance.is_empty u' then Success evd
else
let u = EInstance.kind evd u and u' = EInstance.kind evd u' in
@@ -589,7 +589,7 @@ and evar_eqappr_x ?(rhs_is_already_stuck = false) flags env evd pbty
end
| Ind _, Ind _ -> UnifFailure (evd, NotSameHead)
| Construct (((mi,ind),ctor as cons), u), Construct (cons', u')
- when Names.eq_constructor cons cons' ->
+ when Names.Construct.CanOrd.equal cons cons' ->
if EInstance.is_empty u && EInstance.is_empty u' then Success evd
else
let u = EInstance.kind evd u and u' = EInstance.kind evd u' in
@@ -831,7 +831,7 @@ and evar_eqappr_x ?(rhs_is_already_stuck = false) flags env evd pbty
in
ise_try evd [f1; f2]
- | Proj (p, c), Proj (p', c') when Projection.repr_equal p p' ->
+ | Proj (p, c), Proj (p', c') when QProjection.Repr.equal env (Projection.repr p) (Projection.repr p') ->
let f1 i =
ise_and i
[(fun i -> evar_conv_x flags env i CONV c c');
@@ -844,7 +844,7 @@ and evar_eqappr_x ?(rhs_is_already_stuck = false) flags env evd pbty
ise_try evd [f1; f2]
(* Catch the p.c ~= p c' cases *)
- | Proj (p,c), Const (p',u) when Constant.equal (Projection.constant p) p' ->
+ | Proj (p,c), Const (p',u) when QConstant.equal env (Projection.constant p) p' ->
let res =
try Some (destApp evd (Retyping.expand_projection env evd p c []))
with Retyping.RetypeError _ -> None
@@ -855,7 +855,7 @@ and evar_eqappr_x ?(rhs_is_already_stuck = false) flags env evd pbty
appr2
| None -> UnifFailure (evd,NotSameHead))
- | Const (p,u), Proj (p',c') when Constant.equal p (Projection.constant p') ->
+ | Const (p,u), Proj (p',c') when QConstant.equal env p (Projection.constant p') ->
let res =
try Some (destApp evd (Retyping.expand_projection env evd p' c' []))
with Retyping.RetypeError _ -> None
diff --git a/pretyping/evardefine.ml b/pretyping/evardefine.ml
index f33030d6a4..13abf47413 100644
--- a/pretyping/evardefine.ml
+++ b/pretyping/evardefine.ml
@@ -175,10 +175,7 @@ let define_evar_as_sort env evd (ev,args) =
let evd' = Evd.define ev (mkSort s) evd in
Evd.set_leq_sort env evd' (Sorts.super s) (ESorts.kind evd' sort), s
-(* Propagation of constraints through application and abstraction:
- Given a type constraint on a functional term, returns the type
- constraint on its domain and codomain. If the input constraint is
- an evar instantiate it with the product of 2 new evars. *)
+(* Unify with unknown array *)
let rec presplit env sigma c =
let c = Reductionops.whd_all env sigma c in
@@ -189,25 +186,6 @@ let rec presplit env sigma c =
presplit env sigma (mkApp (lam, args))
| _ -> sigma, c
-let split_tycon ?loc env evd tycon =
- match tycon with
- | None -> evd,(make_annot Anonymous Relevant,None,None)
- | Some c ->
- let evd, c = presplit env evd c in
- let evd, na, dom, rng = match EConstr.kind evd c with
- | Prod (na,dom,rng) -> evd, na, dom, rng
- | Evar ev ->
- let (evd,prod) = define_evar_as_product env evd ev in
- let (na,dom,rng) = destProd evd prod in
- let anon = {na with binder_name = Anonymous} in
- evd, anon, dom, rng
- | _ ->
- (* XXX no error to allow later coercion? Not sure if possible with funclass *)
- error_not_product ?loc env evd c
- in
- evd, (na, mk_tycon dom, mk_tycon rng)
-
-
let define_pure_evar_as_array env sigma evk =
let evi = Evd.find_undefined sigma evk in
let evenv = evar_env env evi in
@@ -228,7 +206,7 @@ let is_array_const env sigma c =
| Const (cst,_) ->
(match env.Environ.retroknowledge.Retroknowledge.retro_array with
| None -> false
- | Some cst' -> Constant.equal cst cst')
+ | Some cst' -> Environ.QConstant.equal env cst cst')
| _ -> false
let split_as_array env sigma0 = function
diff --git a/pretyping/evardefine.mli b/pretyping/evardefine.mli
index e5c3f8baa1..5702e169c8 100644
--- a/pretyping/evardefine.mli
+++ b/pretyping/evardefine.mli
@@ -8,7 +8,6 @@
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)
-open Names
open EConstr
open Evd
open Environ
@@ -31,10 +30,6 @@ val mk_valcon : constr -> val_constraint
val evar_absorb_arguments : env -> evar_map -> existential -> constr list ->
evar_map * existential
-val split_tycon :
- ?loc:Loc.t -> env -> evar_map -> type_constraint ->
- evar_map * (Name.t Context.binder_annot * type_constraint * type_constraint)
-
val split_as_array : env -> evar_map -> type_constraint ->
evar_map * type_constraint
(** If the constraint can be made to look like [array A] return [A],
@@ -51,3 +46,6 @@ val define_evar_as_sort : env -> evar_map -> existential -> evar_map * Sorts.t
val pr_tycon : env -> evar_map -> type_constraint -> Pp.t
+(** Used for bidi heuristic when typing lambdas. Transforms an applied
+ evar to an evar with bigger context (ie ?X e to ?X'@{y=e}). *)
+val presplit : env -> evar_map -> EConstr.t -> evar_map * EConstr.t
diff --git a/pretyping/glob_ops.ml b/pretyping/glob_ops.ml
index 5bd26be823..f42c754ef5 100644
--- a/pretyping/glob_ops.ml
+++ b/pretyping/glob_ops.ml
@@ -91,7 +91,7 @@ let case_style_eq s1 s2 = let open Constr in match s1, s2 with
let rec cases_pattern_eq p1 p2 = match DAst.get p1, DAst.get p2 with
| PatVar na1, PatVar na2 -> Name.equal na1 na2
| PatCstr (c1, pl1, na1), PatCstr (c2, pl2, na2) ->
- eq_constructor c1 c2 && List.equal cases_pattern_eq pl1 pl2 &&
+ Construct.CanOrd.equal c1 c2 && List.equal cases_pattern_eq pl1 pl2 &&
Name.equal na1 na2
| (PatVar _ | PatCstr _), _ -> false
@@ -109,7 +109,7 @@ let matching_var_kind_eq k1 k2 = match k1, k2 with
let tomatch_tuple_eq f (c1, p1) (c2, p2) =
let eqp {CAst.v=(i1, na1)} {CAst.v=(i2, na2)} =
- eq_ind i1 i2 && List.equal Name.equal na1 na2
+ Ind.CanOrd.equal i1 i2 && List.equal Name.equal na1 na2
in
let eq_pred (n1, o1) (n2, o2) = Name.equal n1 n2 && Option.equal eqp o1 o2 in
f c1 c2 && eq_pred p1 p2
@@ -128,7 +128,7 @@ let fix_kind_eq k1 k2 = match k1, k2 with
| (GFix _ | GCoFix _), _ -> false
let instance_eq f (x1,c1) (x2,c2) =
- Id.equal x1 x2 && f c1 c2
+ Id.equal x1.CAst.v x2.CAst.v && f c1 c2
let mk_glob_constr_eq f c1 c2 = match DAst.get c1, DAst.get c2 with
| GRef (gr1, u1), GRef (gr2, u2) ->
@@ -136,7 +136,7 @@ let mk_glob_constr_eq f c1 c2 = match DAst.get c1, DAst.get c2 with
Option.equal (List.equal glob_level_eq) u1 u2
| GVar id1, GVar id2 -> Id.equal id1 id2
| GEvar (id1, arg1), GEvar (id2, arg2) ->
- Id.equal id1 id2 && List.equal (instance_eq f) arg1 arg2
+ Id.equal id1.CAst.v id2.CAst.v && List.equal (instance_eq f) arg1 arg2
| GPatVar k1, GPatVar k2 -> matching_var_kind_eq k1 k2
| GApp (f1, arg1), GApp (f2, arg2) ->
f f1 f2 && List.equal f arg1 arg2
@@ -523,6 +523,7 @@ let rec cases_pattern_of_glob_constr env na c =
| Anonymous -> PatVar (Name id)
end
| GHole (_,_,_) -> PatVar na
+ | GRef (GlobRef.VarRef id,_) -> PatVar (Name id)
| GRef (GlobRef.ConstructRef cstr,_) -> PatCstr (cstr,[],na)
| GApp (c, l) ->
begin match DAst.get c with
diff --git a/pretyping/glob_term.ml b/pretyping/glob_term.ml
index 526eac6f1e..a49c8abe26 100644
--- a/pretyping/glob_term.ml
+++ b/pretyping/glob_term.ml
@@ -75,7 +75,7 @@ type 'a glob_constr_r =
| GVar of Id.t
(** An identifier that cannot be regarded as "GRef".
Bound variables are typically represented this way. *)
- | GEvar of existential_name * (Id.t * 'a glob_constr_g) list
+ | GEvar of existential_name CAst.t * (lident * 'a glob_constr_g) list
| GPatVar of Evar_kinds.matching_var_kind (** Used for patterns only *)
| GApp of 'a glob_constr_g * 'a glob_constr_g list
| GLambda of Name.t * binding_kind * 'a glob_constr_g * 'a glob_constr_g
diff --git a/pretyping/indrec.ml b/pretyping/indrec.ml
index 5be8f9f83c..5ffd919312 100644
--- a/pretyping/indrec.ml
+++ b/pretyping/indrec.ml
@@ -584,7 +584,7 @@ let build_mutual_induction_scheme env sigma ?(force_mutual=false) = function
(List.map
(function ((mind',u'),dep',s') ->
let (sp',_) = mind' in
- if MutInd.equal sp sp' then
+ if QMutInd.equal env sp sp' then
let (mibi',mipi') = lookup_mind_specif env mind' in
((mind',u'),mibi',mipi',dep',s')
else
diff --git a/pretyping/keys.ml b/pretyping/keys.ml
index 7a7099c195..dd3488c1df 100644
--- a/pretyping/keys.ml
+++ b/pretyping/keys.ml
@@ -34,7 +34,7 @@ module KeyOrdered = struct
let hash gr =
match gr with
- | KGlob gr -> 9 + GlobRef.Ordered.hash gr
+ | KGlob gr -> 9 + GlobRef.CanOrd.hash gr
| KLam -> 0
| KLet -> 1
| KProd -> 2
@@ -49,14 +49,14 @@ module KeyOrdered = struct
let compare gr1 gr2 =
match gr1, gr2 with
- | KGlob gr1, KGlob gr2 -> GlobRef.Ordered.compare gr1 gr2
+ | KGlob gr1, KGlob gr2 -> GlobRef.CanOrd.compare gr1 gr2
| _, KGlob _ -> -1
| KGlob _, _ -> 1
| k, k' -> Int.compare (hash k) (hash k')
let equal k1 k2 =
match k1, k2 with
- | KGlob gr1, KGlob gr2 -> GlobRef.Ordered.equal gr1 gr2
+ | KGlob gr1, KGlob gr2 -> GlobRef.CanOrd.equal gr1 gr2
| _, KGlob _ -> false
| KGlob _, _ -> false
| k, k' -> k == k'
diff --git a/pretyping/patternops.ml b/pretyping/patternops.ml
index 8c3d624f0f..b259945d9e 100644
--- a/pretyping/patternops.ml
+++ b/pretyping/patternops.ml
@@ -23,7 +23,7 @@ open Environ
let case_info_pattern_eq i1 i2 =
i1.cip_style == i2.cip_style &&
- Option.equal eq_ind i1.cip_ind i2.cip_ind &&
+ Option.equal Ind.CanOrd.equal i1.cip_ind i2.cip_ind &&
Option.equal (List.equal (==)) i1.cip_ind_tags i2.cip_ind_tags &&
i1.cip_extensible == i2.cip_extensible
@@ -59,7 +59,7 @@ let rec constr_pattern_eq p1 p2 = match p1, p2 with
| PCoFix (i1,f1), PCoFix (i2,f2) ->
Int.equal i1 i2 && rec_declaration_eq f1 f2
| PProj (p1, t1), PProj (p2, t2) ->
- Projection.equal p1 p2 && constr_pattern_eq t1 t2
+ Projection.CanOrd.equal p1 p2 && constr_pattern_eq t1 t2
| PInt i1, PInt i2 ->
Uint63.equal i1 i2
| PFloat f1, PFloat f2 ->
@@ -547,7 +547,7 @@ and pats_of_glob_branches loc metas vars ind brs =
true, [] (* ends with _ => _ *)
| PatCstr((indsp,j),lv,_), _, _ ->
let () = match ind with
- | Some sp when eq_ind sp indsp -> ()
+ | Some sp when Ind.CanOrd.equal sp indsp -> ()
| _ ->
err ?loc (Pp.str "All constructors must be in the same inductive type.")
in
diff --git a/pretyping/pretype_errors.ml b/pretyping/pretype_errors.ml
index 1e8441dd8a..1dddc5622d 100644
--- a/pretyping/pretype_errors.ml
+++ b/pretyping/pretype_errors.ml
@@ -48,7 +48,7 @@ type pretype_error =
| CannotUnifyBindingType of constr * constr
| CannotGeneralize of constr
| NoOccurrenceFound of constr * Id.t option
- | CannotFindWellTypedAbstraction of constr * constr list * (env * type_error) option
+ | CannotFindWellTypedAbstraction of constr * constr list * (env * pretype_error) option
| WrongAbstractionType of Name.t * constr * types * types
| AbstractionOverMeta of Name.t * Name.t
| NonLinearUnification of Name.t * constr
diff --git a/pretyping/pretype_errors.mli b/pretyping/pretype_errors.mli
index 45997e9a66..714d68165e 100644
--- a/pretyping/pretype_errors.mli
+++ b/pretyping/pretype_errors.mli
@@ -54,7 +54,7 @@ type pretype_error =
| CannotUnifyBindingType of constr * constr
| CannotGeneralize of constr
| NoOccurrenceFound of constr * Id.t option
- | CannotFindWellTypedAbstraction of constr * constr list * (env * type_error) option
+ | CannotFindWellTypedAbstraction of constr * constr list * (env * pretype_error) option
| WrongAbstractionType of Name.t * constr * types * types
| AbstractionOverMeta of Name.t * Name.t
| NonLinearUnification of Name.t * constr
@@ -132,7 +132,7 @@ val error_cannot_unify : ?loc:Loc.t -> env -> Evd.evar_map ->
val error_cannot_unify_local : env -> Evd.evar_map -> constr * constr * constr -> 'b
val error_cannot_find_well_typed_abstraction : env -> Evd.evar_map ->
- constr -> constr list -> (env * type_error) option -> 'b
+ constr -> constr list -> (env * pretype_error) option -> 'b
val error_wrong_abstraction_type : env -> Evd.evar_map ->
Name.t -> constr -> types -> types -> 'b
diff --git a/pretyping/pretyping.ml b/pretyping/pretyping.ml
index b9825b6a92..06f7d92e62 100644
--- a/pretyping/pretyping.ml
+++ b/pretyping/pretyping.ml
@@ -365,9 +365,9 @@ let inh_conv_coerce_to_tycon ?loc ~program_mode resolve_tc env sigma j = functio
| Some t ->
Coercion.inh_conv_coerce_to ?loc ~program_mode resolve_tc !!env sigma j t
-let check_instance loc subst = function
+let check_instance subst = function
| [] -> ()
- | (id,_) :: _ ->
+ | (CAst.{loc;v=id},_) :: _ ->
if List.mem_assoc id subst then
user_err ?loc (Id.print id ++ str "appears more than once.")
else
@@ -493,7 +493,7 @@ type 'a pretype_fun = ?loc:Loc.t -> program_mode:bool -> poly:bool -> bool -> ty
type pretyper = {
pretype_ref : pretyper -> GlobRef.t * glob_level list option -> unsafe_judgment pretype_fun;
pretype_var : pretyper -> Id.t -> unsafe_judgment pretype_fun;
- pretype_evar : pretyper -> existential_name * (Id.t * glob_constr) list -> unsafe_judgment pretype_fun;
+ pretype_evar : pretyper -> existential_name CAst.t * (lident * glob_constr) list -> unsafe_judgment pretype_fun;
pretype_patvar : pretyper -> Evar_kinds.matching_var_kind -> unsafe_judgment pretype_fun;
pretype_app : pretyper -> glob_constr * glob_constr list -> unsafe_judgment pretype_fun;
pretype_lambda : pretyper -> Name.t * binding_kind * glob_constr * glob_constr -> unsafe_judgment pretype_fun;
@@ -587,10 +587,10 @@ let pretype_instance self ~program_mode ~poly resolve_tc env sigma loc hyps evk
strbrk " is not well-typed.") in
let sigma, c, update =
try
- let c = List.assoc id update in
+ let c = snd (List.find (fun (CAst.{v=id'},c) -> Id.equal id id') update) in
let sigma, c = eval_pretyper self ~program_mode ~poly resolve_tc (mk_tycon t) env sigma c in
check_body sigma id (Some c.uj_val);
- sigma, c.uj_val, List.remove_assoc id update
+ sigma, c.uj_val, List.remove_first (fun (CAst.{v=id'},_) -> Id.equal id id') update
with Not_found ->
try
let (n,b',t') = lookup_rel_id id (rel_context !!env) in
@@ -609,7 +609,7 @@ let pretype_instance self ~program_mode ~poly resolve_tc env sigma loc hyps evk
str " in current context: no binding for " ++ Id.print id ++ str ".") in
((id,c)::subst, update, sigma) in
let subst,inst,sigma = List.fold_right f hyps ([],update,sigma) in
- check_instance loc subst inst;
+ check_instance subst inst;
sigma, List.map snd subst
module Default =
@@ -628,13 +628,13 @@ struct
let sigma, t_id = pretype_id (fun e r t -> pretype tycon e r t) loc env sigma id in
discard_trace @@ inh_conv_coerce_to_tycon ?loc ~program_mode resolve_tc env sigma t_id tycon
- let pretype_evar self (id, inst) ?loc ~program_mode ~poly resolve_tc tycon env sigma =
+ let pretype_evar self (CAst.{v=id;loc=locid}, inst) ?loc ~program_mode ~poly resolve_tc tycon env sigma =
(* Ne faudrait-il pas s'assurer que hyps est bien un
sous-contexte du contexte courant, et qu'il n'y a pas de Rel "caché" *)
let id = interp_ltac_id env id in
let evk =
try Evd.evar_key id sigma
- with Not_found -> error_evar_not_found ?loc !!env sigma id in
+ with Not_found -> error_evar_not_found ?loc:locid !!env sigma id in
let hyps = evar_filtered_context (Evd.find sigma evk) in
let sigma, args = pretype_instance self ~program_mode ~poly resolve_tc env sigma loc hyps evk inst in
let c = mkEvar (evk, args) in
@@ -813,7 +813,7 @@ struct
try
let IndType (indf, args) = find_rectype !!env sigma ty in
let ((ind',u'),pars) = dest_ind_family indf in
- if eq_ind ind ind' then List.map EConstr.of_constr pars
+ if Ind.CanOrd.equal ind ind' then List.map EConstr.of_constr pars
else (* Let the usual code throw an error *) []
with Not_found -> []
else []
@@ -857,7 +857,7 @@ struct
typing the argument, so we replace it by an existential
variable *)
let sigma, c_hole = new_evar env sigma ~src:(loc,Evar_kinds.InternalHole) c1 in
- (sigma, make_judge c_hole c1), (c_hole, c, trace) :: bidiargs
+ (sigma, make_judge c_hole c1), (c_hole, c1, c, trace) :: bidiargs
else
let tycon = Some c1 in
pretype tycon env sigma c, bidiargs
@@ -886,12 +886,10 @@ struct
let sigma, resj, resj_before_bidi, bidiargs = apply_rec env sigma 0 fj fj candargs [] args in
let sigma, resj = refresh_template env sigma resj in
let sigma, resj, otrace = inh_conv_coerce_to_tycon ?loc ~program_mode resolve_tc env sigma resj tycon in
- let refine_arg n (sigma,t) (newarg,origarg,trace) =
+ let refine_arg n (sigma,t) (newarg,ty,origarg,trace) =
(* Refine an argument (originally `origarg`) represented by an evar
(`newarg`) to use typing information from the context *)
- (* Recover the expected type of the argument *)
- let ty = Retyping.get_type_of !!env sigma newarg in
- (* Type the argument using this expected type *)
+ (* Type the argument using the expected type *)
let sigma, j = pretype (Some ty) env sigma origarg in
(* Unify the (possibly refined) existential variable with the
(typechecked) original value *)
@@ -925,7 +923,32 @@ struct
let sigma, ty' = Coercion.inh_coerce_to_prod ?loc ~program_mode !!env sigma ty in
sigma, Some ty'
in
- let sigma, (name',dom,rng) = split_tycon ?loc !!env sigma tycon' in
+ let sigma,name',dom,rng =
+ match tycon' with
+ | None -> sigma,Anonymous, None, None
+ | Some ty ->
+ let sigma, ty = Evardefine.presplit !!env sigma ty in
+ match EConstr.kind sigma ty with
+ | Prod (na,dom,rng) ->
+ sigma, na.binder_name, Some dom, Some rng
+ | Evar ev ->
+ (* define_evar_as_product works badly when impredicativity
+ is possible but not known (#12623). OTOH if we know we
+ are impredicative (typically Prop) we want to keep the
+ information when typing the body. *)
+ let s = Retyping.get_sort_of !!env sigma ty in
+ if Environ.is_impredicative_sort !!env s
+ || Evd.check_leq sigma (Univ.Universe.type1) (Sorts.univ_of_sort s)
+ then
+ let sigma, prod = define_evar_as_product !!env sigma ev in
+ let na,dom,rng = destProd sigma prod in
+ sigma, na.binder_name, Some dom, Some rng
+ else
+ sigma, Anonymous, None, None
+ | _ ->
+ (* XXX no error to allow later coercion? Not sure if possible with funclass *)
+ error_not_product ?loc !!env sigma ty
+ in
let dom_valcon = valcon_of_tycon dom in
let sigma, j = eval_type_pretyper self ~program_mode ~poly resolve_tc dom_valcon env sigma c1 in
let name = {binder_name=name; binder_relevance=Sorts.relevance_of_sort j.utj_type} in
@@ -934,7 +957,7 @@ struct
let var',env' = push_rel ~hypnaming sigma var env in
let sigma, j' = eval_pretyper self ~program_mode ~poly resolve_tc rng env' sigma c2 in
let name = get_name var' in
- let resj = judge_of_abstraction !!env (orelse_name name name'.binder_name) j j' in
+ let resj = judge_of_abstraction !!env (orelse_name name name') j j' in
discard_trace @@ inh_conv_coerce_to_tycon ?loc ~program_mode resolve_tc env sigma resj tycon
let pretype_prod self (name, bk, c1, c2) =
diff --git a/pretyping/pretyping.mli b/pretyping/pretyping.mli
index c03374c59f..7bb4a6e273 100644
--- a/pretyping/pretyping.mli
+++ b/pretyping/pretyping.mli
@@ -148,7 +148,7 @@ type 'a pretype_fun = ?loc:Loc.t -> program_mode:bool -> poly:bool -> bool -> Ev
type pretyper = {
pretype_ref : pretyper -> GlobRef.t * glob_level list option -> unsafe_judgment pretype_fun;
pretype_var : pretyper -> Id.t -> unsafe_judgment pretype_fun;
- pretype_evar : pretyper -> existential_name * (Id.t * glob_constr) list -> unsafe_judgment pretype_fun;
+ pretype_evar : pretyper -> existential_name CAst.t * (lident * glob_constr) list -> unsafe_judgment pretype_fun;
pretype_patvar : pretyper -> Evar_kinds.matching_var_kind -> unsafe_judgment pretype_fun;
pretype_app : pretyper -> glob_constr * glob_constr list -> unsafe_judgment pretype_fun;
pretype_lambda : pretyper -> Name.t * binding_kind * glob_constr * glob_constr -> unsafe_judgment pretype_fun;
diff --git a/pretyping/reductionops.ml b/pretyping/reductionops.ml
index aeb18ec322..3352bfce38 100644
--- a/pretyping/reductionops.ml
+++ b/pretyping/reductionops.ml
@@ -445,7 +445,7 @@ type state_reduction_function =
let pr_state env sigma (tm,sk) =
let open Pp in
let pr c = Termops.Internal.print_constr_env env sigma c in
- h 0 (pr tm ++ str "|" ++ cut () ++ Stack.pr pr sk)
+ h (pr tm ++ str "|" ++ cut () ++ Stack.pr pr sk)
(*************************************)
(*** Reduction Functions Operators ***)
@@ -705,7 +705,7 @@ let rec whd_state_gen flags env sigma =
let open Pp in
let pr c = Termops.Internal.print_constr_env env sigma c in
Feedback.msg_debug
- (h 0 (str "<<" ++ pr x ++
+ (h (str "<<" ++ pr x ++
str "|" ++ cut () ++ Stack.pr pr stack ++
str ">>"))
in
@@ -1094,7 +1094,8 @@ let f_conv_leq ?l2r ?reds env ?evars x y =
let test_trans_conversion (f: constr Reduction.extended_conversion_function) reds env sigma x y =
try
let evars ev = safe_evar_value sigma ev in
- let _ = f ~reds env ~evars:(evars, Evd.universes sigma) x y in
+ let env = Environ.set_universes (Evd.universes sigma) env in
+ let _ = f ~reds env ~evars x y in
true
with Reduction.NotConvertible -> false
| e ->
@@ -1112,7 +1113,8 @@ let check_conv ?(pb=Reduction.CUMUL) ?(ts=TransparentState.full) env sigma x y =
| Reduction.CONV -> f_conv
| Reduction.CUMUL -> f_conv_leq
in
- try f ~reds:ts env ~evars:(safe_evar_value sigma, Evd.universes sigma) x y; true
+ let env = Environ.set_universes (Evd.universes sigma) env in
+ try f ~reds:ts env ~evars:(safe_evar_value sigma) x y; true
with Reduction.NotConvertible -> false
| Univ.UniverseInconsistency _ -> false
| e ->
@@ -1138,8 +1140,7 @@ let sigma_check_inductive_instances cv_pb variance u1 u2 sigma =
let sigma_univ_state =
let open Reduction in
- { compare_graph = Evd.universes;
- compare_sorts = sigma_compare_sorts;
+ { compare_sorts = sigma_compare_sorts;
compare_instances = sigma_compare_instances;
compare_cumul_instances = sigma_check_inductive_instances; }
@@ -1164,6 +1165,7 @@ let infer_conv_gen conv_fun ?(catch_incon=true) ?(pb=Reduction.CUMUL)
| None ->
let x = EConstr.Unsafe.to_constr x in
let y = EConstr.Unsafe.to_constr y in
+ let env = Environ.set_universes (Evd.universes sigma) env in
let sigma' =
conv_fun pb ~l2r:false sigma ts
env (sigma, sigma_univ_state) x y in
diff --git a/pretyping/tacred.ml b/pretyping/tacred.ml
index 9d15e98373..9cf7119709 100644
--- a/pretyping/tacred.ml
+++ b/pretyping/tacred.ml
@@ -82,7 +82,7 @@ type evaluable_reference =
| EvalEvar of EConstr.existential
let evaluable_reference_eq sigma r1 r2 = match r1, r2 with
-| EvalConst c1, EvalConst c2 -> Constant.equal c1 c2
+| EvalConst c1, EvalConst c2 -> Constant.CanOrd.equal c1 c2
| EvalVar id1, EvalVar id2 -> Id.equal id1 id2
| EvalRel i1, EvalRel i2 -> Int.equal i1 i2
| EvalEvar (e1, ctx1), EvalEvar (e2, ctx2) ->
@@ -995,7 +995,7 @@ let whd_simpl_orelse_delta_but_fix env sigma c =
| CoFix _ | Fix _ -> s'
| Proj (p,t) when
(match EConstr.kind sigma constr with
- | Const (c', _) -> Constant.equal (Projection.constant p) c'
+ | Const (c', _) -> Constant.CanOrd.equal (Projection.constant p) c'
| _ -> false) ->
let npars = Projection.npars p in
if List.length stack <= npars then
@@ -1101,7 +1101,7 @@ let contextually byhead occs f env sigma t =
let match_constr_evaluable_ref sigma c evref =
match EConstr.kind sigma c, evref with
- | Const (c,u), EvalConstRef c' when Constant.equal c c' -> Some u
+ | Const (c,u), EvalConstRef c' when Constant.CanOrd.equal c c' -> Some u
| Var id, EvalVarRef id' when Id.equal id id' -> Some EInstance.empty
| _, _ -> None
@@ -1324,7 +1324,7 @@ let reduce_to_ref_gen allow_product env sigma ref t =
if isIndRef ref then
let ((mind,u),t) = reduce_to_ind_gen allow_product env sigma t in
begin match ref with
- | GlobRef.IndRef mind' when eq_ind mind mind' -> t
+ | GlobRef.IndRef mind' when Ind.CanOrd.equal mind mind' -> t
| _ -> error_cannot_recognize ref
end
else
diff --git a/pretyping/typeclasses.ml b/pretyping/typeclasses.ml
index fc71254a46..51b228a640 100644
--- a/pretyping/typeclasses.ml
+++ b/pretyping/typeclasses.ml
@@ -56,7 +56,7 @@ type typeclass = {
cl_impl : GlobRef.t;
(* Context in which the definitions are typed. Includes both typeclass parameters and superclasses. *)
- cl_context : GlobRef.t option list * Constr.rel_context;
+ cl_context : Constr.rel_context;
(* Context of definitions and properties on defs, will not be shared *)
cl_props : Constr.rel_context;
@@ -97,7 +97,7 @@ let instances : instances ref = Summary.ref GlobRef.Map.empty ~name:"instances"
let typeclass_univ_instance (cl, u) =
assert (Univ.AUContext.size cl.cl_univs == Univ.Instance.length u);
let subst_ctx c = Context.Rel.map (subst_instance_constr u) c in
- { cl with cl_context = on_snd subst_ctx cl.cl_context;
+ { cl with cl_context = subst_ctx cl.cl_context;
cl_props = subst_ctx cl.cl_props}
let class_info env sigma c =
@@ -178,7 +178,7 @@ let remove_instance inst =
let instance_constructor (cl,u) args =
- let lenpars = List.count is_local_assum (snd cl.cl_context) in
+ let lenpars = List.count is_local_assum cl.cl_context in
let open EConstr in
let pars = fst (List.chop lenpars args) in
match cl.cl_impl with
diff --git a/pretyping/typeclasses.mli b/pretyping/typeclasses.mli
index 3f84d08a7e..b749b978c3 100644
--- a/pretyping/typeclasses.mli
+++ b/pretyping/typeclasses.mli
@@ -36,9 +36,9 @@ type typeclass = {
(** The class implementation: a record parameterized by the context with defs in it or a definition if
the class is a singleton. This acts as the class' global identifier. *)
- cl_context : GlobRef.t option list * Constr.rel_context;
- (** Context in which the definitions are typed. Includes both typeclass parameters and superclasses.
- The global reference gives a direct link to the class itself. *)
+ cl_context : Constr.rel_context;
+ (** Context in which the definitions are typed.
+ Includes both typeclass parameters and superclasses. *)
cl_props : Constr.rel_context;
(** Context of definitions and properties on defs, will not be shared *)
diff --git a/pretyping/typing.ml b/pretyping/typing.ml
index 756ccd3438..aeb3873de7 100644
--- a/pretyping/typing.ml
+++ b/pretyping/typing.ml
@@ -220,14 +220,15 @@ let check_allowed_sort env sigma ind c p =
else
Sorts.relevance_of_sort_family ksort
+let check_actual_type env sigma cj t =
+ try Evarconv.unify_leq_delay env sigma cj.uj_type t
+ with Evarconv.UnableToUnify (sigma,e) -> error_actual_type env sigma cj t e
+
let judge_of_cast env sigma cj k tj =
let expected_type = tj.utj_val in
- match Evarconv.unify_leq_delay env sigma cj.uj_type expected_type with
- | exception Evarconv.UnableToUnify _ ->
- error_actual_type_core env sigma cj expected_type;
- | sigma ->
- sigma, { uj_val = mkCast (cj.uj_val, k, expected_type);
- uj_type = expected_type }
+ let sigma = check_actual_type env sigma cj expected_type in
+ sigma, { uj_val = mkCast (cj.uj_val, k, expected_type);
+ uj_type = expected_type }
let check_fix env sigma pfix =
let inj c = EConstr.to_constr ~abort_on_undefined_evars:false sigma c in
@@ -296,7 +297,8 @@ let judge_of_letin env name defj typj j =
uj_type = subst1 defj.uj_val j.uj_type }
let check_hyps_inclusion env sigma x hyps =
- let evars = Evarutil.safe_evar_value sigma, Evd.universes sigma in
+ let env = Environ.set_universes (Evd.universes sigma) env in
+ let evars = Evarutil.safe_evar_value sigma in
Typeops.check_hyps_inclusion env ~evars x hyps
let type_of_constant env sigma (c,u) =
@@ -340,7 +342,7 @@ let judge_of_array env sigma u tj defj tyj =
let sigma = Evd.set_leq_sort env sigma tyj.utj_type
(Sorts.sort_of_univ (Univ.Universe.make ulev))
in
- let check_one sigma j = Evarconv.unify_leq_delay env sigma j.uj_type tyj.utj_val in
+ let check_one sigma j = check_actual_type env sigma j tyj.utj_val in
let sigma = check_one sigma defj in
let sigma = Array.fold_left check_one sigma tj in
let arr = EConstr.of_constr @@ type_of_array env u in
@@ -391,7 +393,7 @@ let rec execute env sigma cstr =
let t = mkApp (mkIndU (ci.ci_ind,univs), args) in
let sigma, tj = execute env sigma t in
let sigma, tj = type_judgment env sigma tj in
- let sigma = Evarconv.unify_leq_delay env sigma cj.uj_type tj.utj_val in
+ let sigma = check_actual_type env sigma cj tj.utj_val in
sigma
in
judge_of_case env sigma ci pj iv cj lfj
@@ -492,10 +494,7 @@ and execute_array env = Array.fold_left_map (execute env)
let check env sigma c t =
let sigma, j = execute env sigma c in
- match Evarconv.unify_leq_delay env sigma j.uj_type t with
- | exception Evarconv.UnableToUnify _ ->
- error_actual_type_core env sigma j t
- | sigma -> sigma
+ check_actual_type env sigma j t
(* Type of a constr *)
diff --git a/pretyping/unification.ml b/pretyping/unification.ml
index 207a03d80f..982814fdfc 100644
--- a/pretyping/unification.ml
+++ b/pretyping/unification.ml
@@ -134,8 +134,8 @@ let abstract_list_all env evd typ c l =
| Type_errors.TypeError (env',x) ->
(* FIXME: plug back the typing information *)
error_cannot_find_well_typed_abstraction env evd p l None
- | Pretype_errors.PretypeError (env',evd,TypingError x) ->
- error_cannot_find_well_typed_abstraction env evd p l (Some (env',x)) in
+ | Pretype_errors.PretypeError (env',evd,e) ->
+ error_cannot_find_well_typed_abstraction env evd p l (Some (env',e)) in
evd,(p,typp)
let set_occurrences_of_last_arg n =
@@ -547,10 +547,10 @@ let oracle_order env cf1 cf2 =
| Some k2 ->
match k1, k2 with
| IsProj (p, _), IsKey (ConstKey (p',_))
- when Constant.equal (Projection.constant p) p' ->
+ when Environ.QConstant.equal env (Projection.constant p) p' ->
Some (not (Projection.unfolded p))
| IsKey (ConstKey (p,_)), IsProj (p', _)
- when Constant.equal p (Projection.constant p') ->
+ when Environ.QConstant.equal env p (Projection.constant p') ->
Some (Projection.unfolded p')
| _ ->
Some (Conv_oracle.oracle_order (fun x -> x)
@@ -687,6 +687,17 @@ let eta_constructor_app env sigma f l1 term =
| _ -> assert false)
| _ -> assert false
+(* If the terms are irrelevant, check that they have the same type. *)
+let careful_infer_conv ~pb ~ts env sigma m n =
+ if Retyping.relevance_of_term env sigma m == Sorts.Irrelevant &&
+ Retyping.relevance_of_term env sigma n == Sorts.Irrelevant
+ then
+ let tm = Retyping.get_type_of env sigma m in
+ let tn = Retyping.get_type_of env sigma n in
+ Option.bind (infer_conv ~pb:CONV ~ts env sigma tm tn)
+ (fun sigma -> infer_conv ~pb ~ts env sigma m n)
+ else infer_conv ~pb ~ts env sigma m n
+
let rec unify_0_with_initial_metas (sigma,ms,es as subst : subst0) conv_at_top env cv_pb flags m n =
let rec unirec_rec (curenv,nb as curenvnb) pb opt ((sigma,metasubst,evarsubst) as substn : subst0) curm curn =
let cM = Evarutil.whd_head_evar sigma curm
@@ -796,7 +807,7 @@ let rec unify_0_with_initial_metas (sigma,ms,es as subst : subst0) conv_at_top e
| _, LetIn (_,a,_,c) -> unirec_rec curenvnb pb opt substn cM (subst1 a c)
(* Fast path for projections. *)
- | Proj (p1,c1), Proj (p2,c2) when Constant.equal
+ | Proj (p1,c1), Proj (p2,c2) when Environ.QConstant.equal env
(Projection.constant p1) (Projection.constant p2) ->
(try unify_same_proj curenvnb cv_pb {opt with at_top = true}
substn c1 c2
@@ -844,7 +855,7 @@ let rec unify_0_with_initial_metas (sigma,ms,es as subst : subst0) conv_at_top e
| Case (ci1,p1,_,c1,cl1), Case (ci2,p2,_,c2,cl2) ->
(try
- if not (eq_ind ci1.ci_ind ci2.ci_ind) then error_cannot_unify curenv sigma (cM,cN);
+ if not (Ind.CanOrd.equal ci1.ci_ind ci2.ci_ind) then error_cannot_unify curenv sigma (cM,cN);
let opt' = {opt with at_top = true; with_types = false} in
Array.fold_left2 (unirec_rec curenvnb CONV {opt with at_top = true})
(unirec_rec curenvnb CONV opt'
@@ -914,7 +925,7 @@ let rec unify_0_with_initial_metas (sigma,ms,es as subst : subst0) conv_at_top e
match EConstr.kind sigma c' with
| Meta _ -> true
| Evar _ -> true
- | Const (c, u) -> Constant.equal c (Projection.constant p)
+ | Const (c, u) -> Environ.QConstant.equal env c (Projection.constant p)
| _ -> false
in
let expand_proj c c' l =
@@ -1127,7 +1138,7 @@ let rec unify_0_with_initial_metas (sigma,ms,es as subst : subst0) conv_at_top e
None
else
let ans = match flags.modulo_conv_on_closed_terms with
- | Some convflags -> infer_conv ~pb:cv_pb ~ts:convflags env sigma m n
+ | Some convflags -> careful_infer_conv ~pb:cv_pb ~ts:convflags env sigma m n
| _ -> constr_cmp cv_pb env sigma flags m n in
match ans with
| Some sigma -> ans
diff --git a/pretyping/vnorm.ml b/pretyping/vnorm.ml
index 900ba0edb9..1420401875 100644
--- a/pretyping/vnorm.ml
+++ b/pretyping/vnorm.ml
@@ -218,7 +218,8 @@ and nf_evar env sigma evk stk =
let t = List.fold_left fold concl hyps in
let t, args = nf_args env sigma args t in
let inst, args = Array.chop (List.length hyps) args in
- let inst = Array.to_list inst in
+ (* Evar instances are reversed w.r.t. argument order *)
+ let inst = Array.rev_to_list inst in
let c = mkApp (mkEvar (evk, inst), args) in
nf_stk env sigma c t stk
| _ ->
diff --git a/printing/ppconstr.ml b/printing/ppconstr.ml
index af105f4d63..e312c68b7d 100644
--- a/printing/ppconstr.ml
+++ b/printing/ppconstr.ml
@@ -77,8 +77,8 @@ let tag_var = tag Tag.variable
| LevelSome -> true
let prec_of_prim_token = function
- | Numeral (NumTok.SPlus,_) -> lposint
- | Numeral (NumTok.SMinus,_) -> lnegint
+ | Number (NumTok.SPlus,_) -> lposint
+ | Number (NumTok.SMinus,_) -> lnegint
| String _ -> latom
let print_hunks n pr pr_patt pr_binders (terms, termlists, binders, binderlists) unps =
@@ -222,18 +222,54 @@ let tag_var = tag Tag.variable
| t -> str " :" ++ pr_sep_com (fun()->brk(1,4)) (pr ltop) t
let pr_prim_token = function
- | Numeral n -> NumTok.Signed.print n
+ | Number n -> NumTok.Signed.print n
| String s -> qs s
let pr_evar pr id l =
hov 0 (
- tag_evar (str "?" ++ pr_id id) ++
+ tag_evar (str "?" ++ pr_lident id) ++
(match l with
| [] -> mt()
| l ->
- let f (id,c) = pr_id id ++ str ":=" ++ pr ltop c in
+ let f (id,c) = pr_lident id ++ str ":=" ++ pr ltop c in
str"@{" ++ hov 0 (prlist_with_sep pr_semicolon f (List.rev l)) ++ str"}"))
+ (* Assuming "{" and "}" brackets, prints
+ - if there is enough room
+ { a; b; c }
+ - otherwise
+ {
+ a;
+ b;
+ c
+ }
+ Alternatively, replace outer hv with h to get instead:
+ { a;
+ b;
+ c }
+ Replace the inner hv with hov to respectively get instead (if enough room):
+ {
+ a; b;
+ c
+ }
+ or
+ { a; b;
+ c }
+ *)
+ let pr_record left right pr = function
+ | [] -> str left ++ str " " ++ str right
+ | l ->
+ hv 0 (
+ str left ++
+ brk (1,String.length left) ++
+ hv 0 (prlist_with_sep pr_semicolon pr l) ++
+ brk (1,0) ++
+ str right)
+
+ let pr_record_body left right pr l =
+ let pr_defined_field (id, c) = hov 2 (pr_reference id ++ str" :=" ++ pr c) in
+ pr_record left right pr_defined_field l
+
let las = lapp
let lpator = 0
let lpatrec = 0
@@ -242,11 +278,7 @@ let tag_var = tag Tag.variable
let rec pr_patt sep inh p =
let (strm,prec) = match CAst.(p.v) with
| CPatRecord l ->
- let pp (c, p) =
- pr_reference c ++ spc() ++ str ":=" ++ pr_patt spc lpattop p
- in
- (if l = [] then str "{| |}"
- else str "{| " ++ prlist_with_sep pr_semicolon pp l ++ str " |}"), lpatrec
+ pr_record_body "{|" "|}" (pr_patt spc lpattop) l, lpatrec
| CPatAlias (p, na) ->
pr_patt mt (LevelLe las) p ++ str " as " ++ pr_lname na, las
@@ -287,6 +319,7 @@ let tag_var = tag Tag.variable
| CPatDelimiters (k,p) ->
pr_delimiters k (pr_patt mt lsimplepatt p), 1
+
| CPatCast _ ->
assert false
in
@@ -464,11 +497,6 @@ let tag_var = tag Tag.variable
pr (LevelLt lapp) a ++
prlist (fun a -> spc () ++ pr_expl_args pr a) l)
- let pr_record_body_gen pr l =
- spc () ++
- prlist_with_sep pr_semicolon
- (fun (id, c) -> h 1 (pr_reference id ++ spc () ++ str":=" ++ pr ltop c)) l
-
let pr_forall n = keyword "forall" ++ pr_com_at n ++ spc ()
let pr_fun n = keyword "fun" ++ pr_com_at n ++ spc ()
@@ -568,10 +596,7 @@ let tag_var = tag Tag.variable
| CApp ((None,a),l) ->
return (pr_app (pr mt) a l, lapp)
| CRecord l ->
- return (
- hv 0 (str"{|" ++ pr_record_body_gen (pr spc) l ++ str" |}"),
- latom
- )
+ return (pr_record_body "{|" "|}" (pr spc ltop) l, latom)
| CCases (Constr.LetPatternStyle,rtntypopt,[c,as_clause,in_clause],[{v=([[p]],b)}]) ->
return (
hv 0 (
@@ -656,13 +681,10 @@ let tag_var = tag Tag.variable
| CDelimiters (sc,a) ->
return (pr_delimiters sc (pr mt (LevelLe ldelim) a), ldelim)
| CArray(u, t,def,ty) ->
- let pp = ref (str " |"++ spc () ++ pr mt ltop def
- ++ pr_opt_type_spc (pr mt) ty ++ str " |]" ++ pr_universe_instance u) in
- for i = Array.length t - 1 downto 1 do
- pp := str ";" ++ pr mt ltop t.(i) ++ !pp
- done;
- pp := pr mt ltop t.(0) ++ !pp;
- hov 0 (str "[|" ++ !pp), 0
+ hov 0 (str "[| " ++ prvect_with_sep (fun () -> str "; ") (pr mt ltop) t ++
+ (if not (Array.is_empty t) then str " " else mt()) ++
+ str "|" ++ spc() ++ pr mt ltop def ++ pr_opt_type_spc (pr mt) ty ++
+ str " |]" ++ pr_universe_instance u), 0
in
let loc = constr_loc a in
pr_with_comments ?loc
@@ -717,7 +739,5 @@ let tag_var = tag Tag.variable
let pr_cases_pattern_expr = pr_patt ltop
- let pr_record_body = pr_record_body_gen pr
-
let pr_binders env sigma = pr_undelimited_binders spc (pr_expr env sigma ltop)
diff --git a/printing/ppconstr.mli b/printing/ppconstr.mli
index 2850e4bfa0..02e04573f8 100644
--- a/printing/ppconstr.mli
+++ b/printing/ppconstr.mli
@@ -41,7 +41,8 @@ val pr_guard_annot
-> recursion_order_expr option
-> Pp.t
-val pr_record_body : (qualid * constr_expr) list -> Pp.t
+val pr_record : string -> string -> ('a -> Pp.t) -> 'a list -> Pp.t
+val pr_record_body : string -> string -> ('a -> Pp.t) -> (Libnames.qualid * 'a) list -> Pp.t
val pr_binders : Environ.env -> Evd.evar_map -> local_binder_expr list -> Pp.t
val pr_constr_pattern_expr : Environ.env -> Evd.evar_map -> constr_pattern_expr -> Pp.t
val pr_lconstr_pattern_expr : Environ.env -> Evd.evar_map -> constr_pattern_expr -> Pp.t
diff --git a/printing/printer.ml b/printing/printer.ml
index a1a2d9ae51..ea718526de 100644
--- a/printing/printer.ml
+++ b/printing/printer.ml
@@ -45,6 +45,8 @@ let should_gname =
~key:["Printing";"Goal";"Names"]
~value:false
+let print_goal_names = should_gname (* for export *)
+
(**********************************************************************)
(** Terms *)
@@ -765,9 +767,9 @@ let pr_subgoals ?(pr_first=true) ?(diffs=false) ?os_map
v 0 (
int ngoals ++ focused_if_needed ++ str(String.plural ngoals "subgoal")
++ print_extra
- ++ str (if (should_gname()) then ", subgoal 1" else "")
- ++ (if should_tag() then pr_goal_tag g1 else str"")
- ++ pr_goal_name sigma g1 ++ cut () ++ goals
+ ++ str (if pr_first && (should_gname()) && ngoals > 1 then ", subgoal 1" else "")
+ ++ (if pr_first && should_tag() then pr_goal_tag g1 else str"")
+ ++ (if pr_first then pr_goal_name sigma g1 else mt()) ++ cut () ++ goals
++ (if unfocused=[] then str ""
else (cut() ++ cut() ++ str "*** Unfocused goals:" ++ cut()
++ pr_rec (List.length rest + 2) unfocused))
@@ -884,7 +886,7 @@ struct
MutInd.CanOrd.compare m1 m2
| Guarded k1 , Guarded k2
| TypeInType k1, TypeInType k2 ->
- GlobRef.Ordered.compare k1 k2
+ GlobRef.CanOrd.compare k1 k2
| Constant _, _ -> -1
| _, Constant _ -> 1
| Positive _, _ -> -1
diff --git a/printing/printer.mli b/printing/printer.mli
index a25cbebe91..ea388ae57e 100644
--- a/printing/printer.mli
+++ b/printing/printer.mli
@@ -264,3 +264,6 @@ val pr_goal_by_id : proof:Proof.t -> Id.t -> Pp.t
val pr_goal_emacs : proof:Proof.t option -> int -> int -> Pp.t
val pr_typing_flags : Declarations.typing_flags -> Pp.t
+
+(** Tells if flag "Printing Goal Names" is activated *)
+val print_goal_names : unit -> bool
diff --git a/printing/proof_diffs.ml b/printing/proof_diffs.ml
index 43f70dfecc..b2ebc61b4e 100644
--- a/printing/proof_diffs.ml
+++ b/printing/proof_diffs.ml
@@ -252,6 +252,9 @@ let pp_of_type env sigma ty =
let pr_leconstr_env ?lax ?inctx ?scope env sigma t =
Ppconstr.pr_lconstr_expr env sigma (Constrextern.extern_constr ?lax ?inctx ?scope env sigma t)
+let pr_econstr_env ?lax ?inctx ?scope env sigma t =
+ Ppconstr.pr_constr_expr env sigma (Constrextern.extern_constr ?lax ?inctx ?scope env sigma t)
+
let pr_lconstr_env ?lax ?inctx ?scope env sigma c =
pr_leconstr_env ?lax ?inctx ?scope env sigma (EConstr.of_constr c)
@@ -511,12 +514,12 @@ let match_goals ot nt =
| CHole (k,naming,solve), CHole (k2,naming2,solve2) -> ()
| CPatVar _, CPatVar _ -> ()
| CEvar (n,l), CEvar (n2,l2) ->
- let oevar = if ogname = "" then Id.to_string n else ogname in
- nevar_to_oevar := CString.Map.add (Id.to_string n2) oevar !nevar_to_oevar;
+ let oevar = if ogname = "" then Id.to_string n.CAst.v else ogname in
+ nevar_to_oevar := CString.Map.add (Id.to_string n2.CAst.v) oevar !nevar_to_oevar;
iter2 (fun x x2 -> let (_, g) = x and (_, g2) = x2 in constr_expr ogname g g2) l l2
| CEvar (n,l), nt' ->
(* pass down the old goal evar name *)
- match_goals_r (Id.to_string n) nt' nt'
+ match_goals_r (Id.to_string n.CAst.v) nt' nt'
| CSort s, CSort s2 -> ()
| CCast (c,c'), CCast (c2,c'2) ->
constr_expr ogname c c2;
@@ -660,3 +663,22 @@ let make_goal_map op np =
let ng_to_og = make_goal_map_i op np in
(*db_goal_map op np ng_to_og;*)
ng_to_og
+
+let diff_proofs ~diff_opt ?old proof =
+ let pp_proof p =
+ let sigma, env = Proof.get_proof_context p in
+ let pprf = Proof.partial_proof p in
+ Pp.prlist_with_sep Pp.fnl (pr_econstr_env env sigma) pprf in
+ match diff_opt with
+ | DiffOff -> pp_proof proof
+ | _ -> begin
+ try
+ let n_pp = pp_proof proof in
+ let o_pp = match old with
+ | None -> Pp.mt()
+ | Some old -> pp_proof old in
+ let show_removed = Some (diff_opt = DiffRemoved) in
+ Pp_diff.diff_pp_combined ~tokenize_string ?show_removed o_pp n_pp
+ with
+ | Pp_diff.Diff_Failure msg -> Pp.str msg
+ end
diff --git a/printing/proof_diffs.mli b/printing/proof_diffs.mli
index ea64439456..6bdd7004fb 100644
--- a/printing/proof_diffs.mli
+++ b/printing/proof_diffs.mli
@@ -25,6 +25,10 @@ val write_color_enabled : bool -> unit
(** true indicates that color output is enabled *)
val color_enabled : unit -> bool
+type diffOpt = DiffOff | DiffOn | DiffRemoved
+
+val string_to_diffs : string -> diffOpt
+
open Evd
open Environ
open Constr
@@ -84,3 +88,5 @@ type hyp_info = {
}
val diff_hyps : string list list -> hyp_info CString.Map.t -> string list list -> hyp_info CString.Map.t -> Pp.t list
+
+val diff_proofs : diff_opt:diffOpt -> ?old:Proof.t -> Proof.t -> Pp.t
diff --git a/proofs/clenv.ml b/proofs/clenv.ml
index 31bc698830..387f0f6f5f 100644
--- a/proofs/clenv.ml
+++ b/proofs/clenv.ml
@@ -720,7 +720,7 @@ let make_clenv_binding env sigma = make_clenv_binding_gen false None env sigma
(* Pretty-print *)
let pr_clenv clenv =
- h 0
+ h
(str"TEMPL: " ++ Termops.Internal.print_constr_env clenv.env clenv.evd clenv.templval.rebus ++
str" : " ++ Termops.Internal.print_constr_env clenv.env clenv.evd clenv.templtyp.rebus ++ fnl () ++
pr_evar_map (Some 2) clenv.env clenv.evd)
diff --git a/stm/asyncTaskQueue.ml b/stm/asyncTaskQueue.ml
index a8088dae36..4f04b9fe1c 100644
--- a/stm/asyncTaskQueue.ml
+++ b/stm/asyncTaskQueue.ml
@@ -386,3 +386,8 @@ end
module MakeQueue(T : Task) () = struct include Make(T) () end
module MakeWorker(T : Task) () = struct include Make(T) () end
+
+exception RemoteException of Pp.t
+let _ = CErrors.register_handler (function
+ | RemoteException ppcmd -> Some ppcmd
+ | _ -> None)
diff --git a/stm/asyncTaskQueue.mli b/stm/asyncTaskQueue.mli
index cf174d0c93..a1fa6f7268 100644
--- a/stm/asyncTaskQueue.mli
+++ b/stm/asyncTaskQueue.mli
@@ -220,3 +220,6 @@ module MakeWorker(T : Task) () : sig
val main_loop : unit -> unit
end
+
+(** convenience exception to marshall to master *)
+exception RemoteException of Pp.t
diff --git a/stm/partac.ml b/stm/partac.ml
new file mode 100644
index 0000000000..8232b017f9
--- /dev/null
+++ b/stm/partac.ml
@@ -0,0 +1,178 @@
+(************************************************************************)
+(* * The Coq Proof Assistant / The Coq Development Team *)
+(* v * Copyright INRIA, CNRS and contributors *)
+(* <O___,, * (see version control and CREDITS file for authors & dates) *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(* * (see LICENSE file for the text of the license) *)
+(************************************************************************)
+
+open Pp
+
+let stm_pr_err s = Format.eprintf "%s] %s\n%!" (Spawned.process_id ()) s
+
+module TacTask : sig
+
+ type output = (Constr.constr * UState.t) option
+ type task = {
+ t_state : Vernacstate.t;
+ t_assign : output Future.assignment -> unit;
+ t_ast : ComTactic.interpretable;
+ t_goalno : int;
+ t_goal : Goal.goal;
+ t_kill : unit -> unit;
+ t_name : string }
+
+ include AsyncTaskQueue.Task with type task := task
+
+end = struct (* {{{ *)
+
+ let forward_feedback { Feedback.doc_id = did; span_id = id; route; contents } =
+ Feedback.feedback ~did ~id ~route contents
+
+ type output = (Constr.constr * UState.t) option
+
+ type task = {
+ t_state : Vernacstate.t;
+ t_assign : output Future.assignment -> unit;
+ t_ast : ComTactic.interpretable;
+ t_goalno : int;
+ t_goal : Goal.goal;
+ t_kill : unit -> unit;
+ t_name : string }
+
+ type request = {
+ r_state : Vernacstate.t option;
+ r_ast : ComTactic.interpretable;
+ r_goalno : int;
+ r_goal : Goal.goal;
+ r_name : string }
+
+ type response =
+ | RespBuiltSubProof of (Constr.constr * UState.t)
+ | RespError of Pp.t
+ | RespNoProgress
+
+ let name = ref "tacticworker"
+ let extra_env () = [||]
+ type competence = unit
+ type worker_status = Fresh | Old of competence
+
+ let task_match _ _ = true
+
+ (* run by the master, on a thread *)
+ let request_of_task age { t_state; t_ast; t_goalno; t_goal; t_name } =
+ Some {
+ r_state = if age <> Fresh then None else Some t_state;
+ r_ast = t_ast;
+ r_goalno = t_goalno;
+ r_goal = t_goal;
+ r_name = t_name }
+
+ let use_response _ { t_assign; t_kill } resp =
+ match resp with
+ | RespBuiltSubProof o -> t_assign (`Val (Some o)); `Stay ((),[])
+ | RespNoProgress ->
+ t_assign (`Val None);
+ t_kill ();
+ `Stay ((),[])
+ | RespError msg ->
+ let e = (AsyncTaskQueue.RemoteException msg, Exninfo.null) in
+ t_assign (`Exn e);
+ t_kill ();
+ `Stay ((),[])
+
+ let on_marshal_error err { t_name } =
+ stm_pr_err ("Fatal marshal error: " ^ t_name );
+ flush_all (); exit 1
+
+ let on_task_cancellation_or_expiration_or_slave_death = function
+ | Some { t_kill } -> t_kill ()
+ | _ -> ()
+
+ let command_focus = Proof.new_focus_kind ()
+ let focus_cond = Proof.no_cond command_focus
+
+ let state = ref None
+ let receive_state = function
+ | None -> ()
+ | Some st -> state := Some st
+
+ let perform { r_state = st; r_ast = tactic; r_goal; r_goalno } =
+ receive_state st;
+ Vernacstate.unfreeze_interp_state (Option.get !state);
+ try
+ Vernacstate.LemmaStack.with_top (Option.get (Option.get !state).Vernacstate.lemmas) ~f:(fun pstate ->
+ let pstate =
+ Declare.Proof.map pstate ~f:(Proof.focus focus_cond () r_goalno) in
+ let pstate =
+ ComTactic.solve ~pstate
+ Goal_select.SelectAll ~info:None tactic ~with_end_tac:false in
+ let { Proof.sigma } = Declare.Proof.fold pstate ~f:Proof.data in
+ match Evd.(evar_body (find sigma r_goal)) with
+ | Evd.Evar_empty -> RespNoProgress
+ | Evd.Evar_defined t ->
+ let t = Evarutil.nf_evar sigma t in
+ let evars = Evarutil.undefined_evars_of_term sigma t in
+ if Evar.Set.is_empty evars then
+ let t = EConstr.Unsafe.to_constr t in
+ RespBuiltSubProof (t, Evd.evar_universe_context sigma)
+ else
+ CErrors.user_err ~hdr:"STM"
+ Pp.(str"The par: selector requires a tactic that makes no progress or fully" ++
+ str" solves the goal and leaves no unresolved existential variables. The following" ++
+ str" existentials remain unsolved: " ++ prlist (Termops.pr_existential_key sigma) (Evar.Set.elements evars))
+ )
+ with e when CErrors.noncritical e ->
+ RespError (CErrors.print e ++ spc() ++ str "(for subgoal "++int r_goalno ++ str ")")
+
+ let name_of_task { t_name } = t_name
+ let name_of_request { r_name } = r_name
+
+end (* }}} *)
+
+module TaskQueue = AsyncTaskQueue.MakeQueue(TacTask) ()
+
+let assign_tac ~abstract res : unit Proofview.tactic =
+ Proofview.(Goal.enter begin fun g ->
+ let gid = Goal.goal g in
+ let g_solution =
+ try List.assoc gid res
+ with Not_found -> CErrors.anomaly(str"Partac: wrong focus.") in
+ if not (Future.is_over g_solution) then
+ tclUNIT ()
+ else
+ let open Notations in
+ match Future.join g_solution with
+ | Some (pt, uc) ->
+ let push_state ctx =
+ Proofview.tclEVARMAP >>= fun sigma ->
+ Proofview.Unsafe.tclEVARS (Evd.merge_universe_context sigma ctx)
+ in
+ (if abstract then Abstract.tclABSTRACT None else (fun x -> x))
+ (push_state uc <*> Tactics.exact_no_check (EConstr.of_constr pt))
+ | None -> tclUNIT ()
+ end)
+
+let enable_par ~nworkers = ComTactic.set_par_implementation
+ (fun ~pstate ~info t_ast ~abstract ~with_end_tac ->
+ let t_state = Vernacstate.freeze_interp_state ~marshallable:true in
+ TaskQueue.with_n_workers nworkers CoqworkmgrApi.High (fun queue ->
+ Declare.Proof.map pstate ~f:(fun p ->
+ let open TacTask in
+ let results = (Proof.data p).Proof.goals |> CList.map_i (fun i g ->
+ let g_solution, t_assign =
+ Future.create_delegate ~name:(Printf.sprintf "subgoal %d" i)
+ (fun x -> x) in
+ TaskQueue.enqueue_task queue
+ ~cancel_switch:(ref false)
+ { t_state; t_assign; t_ast;
+ t_goalno = i; t_goal = g; t_name = Goal.uid g;
+ t_kill = (fun () -> TaskQueue.cancel_all queue) };
+ g, g_solution) 1 in
+ TaskQueue.join queue;
+ let p,_,() =
+ Proof.run_tactic (Global.env())
+ (assign_tac ~abstract results) p in
+ p)))
diff --git a/plugins/syntax/r_syntax.mli b/stm/partac.mli
index b72d544151..a206b2e5d8 100644
--- a/plugins/syntax/r_syntax.mli
+++ b/stm/partac.mli
@@ -7,3 +7,7 @@
(* * GNU Lesser General Public License Version 2.1 *)
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)
+
+val enable_par : nworkers:int -> unit
+
+module TacTask : AsyncTaskQueue.Task
diff --git a/stm/stm.ml b/stm/stm.ml
index 4ca0c365bf..df7e35beb5 100644
--- a/stm/stm.ml
+++ b/stm/stm.ml
@@ -159,9 +159,9 @@ type cmd_t = {
cids : Names.Id.t list;
cblock : proof_block_name option;
cqueue : [ `MainQueue
- | `TacQueue of solving_tac * anon_abstracting_tac * AsyncTaskQueue.cancel_switch
- | `QueryQueue of AsyncTaskQueue.cancel_switch
- | `SkipQueue ] }
+ | `QueryQueue
+ | `SkipQueue ];
+ cancel_switch : AsyncTaskQueue.cancel_switch; }
type fork_t = aast * Vcs_.Branch.t * opacity_guarantee * Names.Id.t list
type qed_t = {
qast : aast;
@@ -190,10 +190,10 @@ type step =
type visit = { step : step; next : Stateid.t }
let mkTransTac cast cblock cqueue =
- Cmd { ctac = true; cast; cblock; cqueue; cids = []; ceff = false }
+ Cmd { ctac = true; cast; cblock; cqueue; cids = []; ceff = false; cancel_switch = ref false }
let mkTransCmd cast cids ceff cqueue =
- Cmd { ctac = false; cast; cblock = None; cqueue; cids; ceff }
+ Cmd { ctac = false; cast; cblock = None; cqueue; cids; ceff; cancel_switch = ref false }
type cached_state =
| EmptyState
@@ -742,8 +742,7 @@ end = struct (* {{{ *)
Stateid.Set.iter (fun id ->
match (Vcs_aux.visit old_vcs id).step with
| `Qed ({ fproof = Some (_, cancel_switch) }, _)
- | `Cmd { cqueue = `TacQueue (_,_,cancel_switch) }
- | `Cmd { cqueue = `QueryQueue cancel_switch } ->
+ | `Cmd { cancel_switch } ->
cancel_switch := true
| _ -> ())
erased_nodes;
@@ -1222,11 +1221,6 @@ let record_pb_time ?loc proof_name time =
hints := Aux_file.set !hints proof_name proof_build_time
end
-exception RemoteException of Pp.t
-let _ = CErrors.register_handler (function
- | RemoteException ppcmd -> Some ppcmd
- | _ -> None)
-
(****************** proof structure for error recovery ************************)
(******************************************************************************)
@@ -1429,7 +1423,7 @@ end = struct (* {{{ *)
RespError { e_error_at; e_safe_id = valid; e_msg; e_safe_states } ->
feedback (InProgress ~-1);
let info = Stateid.add ~valid Exninfo.null e_error_at in
- let e = (RemoteException e_msg, info) in
+ let e = (AsyncTaskQueue.RemoteException e_msg, info) in
t_assign (`Exn e);
`Stay(t_states,[States e_safe_states])
| _ -> assert false
@@ -1440,7 +1434,7 @@ end = struct (* {{{ *)
| Some (BuildProof { t_start = start; t_assign }) ->
let s = "Worker dies or task expired" in
let info = Stateid.add ~valid:start Exninfo.null start in
- let e = (RemoteException (Pp.strbrk s), info) in
+ let e = (AsyncTaskQueue.RemoteException (Pp.strbrk s), info) in
t_assign (`Exn e);
execution_error start (Pp.strbrk s);
feedback (InProgress ~-1)
@@ -1792,225 +1786,6 @@ end = struct (* {{{ *)
end (* }}} *)
-and TacTask : sig
-
- type output = (Constr.constr * UState.t) option
- type task = {
- t_state : Stateid.t;
- t_state_fb : Stateid.t;
- t_assign : output Future.assignment -> unit;
- t_ast : int * aast;
- t_goal : Goal.goal;
- t_kill : unit -> unit;
- t_name : string }
-
- include AsyncTaskQueue.Task with type task := task
-
-end = struct (* {{{ *)
-
- type output = (Constr.constr * UState.t) option
-
- let forward_feedback msg = Hooks.(call forward_feedback msg)
-
- type task = {
- t_state : Stateid.t;
- t_state_fb : Stateid.t;
- t_assign : output Future.assignment -> unit;
- t_ast : int * aast;
- t_goal : Goal.goal;
- t_kill : unit -> unit;
- t_name : string }
-
- type request = {
- r_state : Stateid.t;
- r_state_fb : Stateid.t;
- r_document : VCS.vcs option;
- r_ast : int * aast;
- r_goal : Goal.goal;
- r_name : string }
-
- type response =
- | RespBuiltSubProof of (Constr.constr * UState.t)
- | RespError of Pp.t
- | RespNoProgress
-
- let name = ref "tacticworker"
- let extra_env () = [||]
- type competence = unit
- type worker_status = Fresh | Old of competence
-
- let task_match _ _ = true
-
- (* run by the master, on a thread *)
- let request_of_task age { t_state; t_state_fb; t_ast; t_goal; t_name } =
- try Some {
- r_state = t_state;
- r_state_fb = t_state_fb;
- r_document =
- if age <> Fresh then None
- else Some (VCS.slice ~block_start:t_state ~block_stop:t_state);
- r_ast = t_ast;
- r_goal = t_goal;
- r_name = t_name }
- with VCS.Expired -> None
-
- let use_response _ { t_assign; t_state; t_state_fb; t_kill } resp =
- match resp with
- | RespBuiltSubProof o -> t_assign (`Val (Some o)); `Stay ((),[])
- | RespNoProgress ->
- t_assign (`Val None);
- t_kill ();
- `Stay ((),[])
- | RespError msg ->
- let e = (RemoteException msg, Exninfo.null) in
- t_assign (`Exn e);
- t_kill ();
- `Stay ((),[])
-
- let on_marshal_error err { t_name } =
- stm_pr_err ("Fatal marshal error: " ^ t_name );
- flush_all (); exit 1
-
- let on_task_cancellation_or_expiration_or_slave_death = function
- | Some { t_kill } -> t_kill ()
- | _ -> ()
-
- let command_focus = Proof.new_focus_kind ()
- let focus_cond = Proof.no_cond command_focus
-
- let perform { r_state = id; r_state_fb; r_document = vcs; r_ast; r_goal } =
- Option.iter VCS.restore vcs;
- try
- Reach.known_state ~doc:dummy_doc (* XXX should be vcs *) ~cache:false id;
- State.purify (fun () ->
- let Proof.{sigma=sigma0} = Proof.data (PG_compat.give_me_the_proof ()) in
- let g = Evd.find sigma0 r_goal in
- let is_ground c = Evarutil.is_ground_term sigma0 c in
- if not (
- is_ground Evd.(evar_concl g) &&
- List.for_all (Context.Named.Declaration.for_all is_ground)
- Evd.(evar_context g))
- then
- CErrors.user_err ~hdr:"STM" Pp.(strbrk("The par: goal selector does not support goals with existential variables"))
- else begin
- let (i, ast) = r_ast in
- PG_compat.map_proof (fun p -> Proof.focus focus_cond () i p);
- (* STATE SPEC:
- * - start : id
- * - return: id
- * => captures state id in a future closure, which will
- discard execution state but for the proof + univs.
- *)
- let st = Vernacstate.freeze_interp_state ~marshallable:false in
- ignore(stm_vernac_interp r_state_fb st ast);
- let Proof.{sigma} = Proof.data (PG_compat.give_me_the_proof ()) in
- match Evd.(evar_body (find sigma r_goal)) with
- | Evd.Evar_empty -> RespNoProgress
- | Evd.Evar_defined t ->
- let t = Evarutil.nf_evar sigma t in
- let evars = Evarutil.undefined_evars_of_term sigma t in
- if Evar.Set.is_empty evars then
- let t = EConstr.Unsafe.to_constr t in
- RespBuiltSubProof (t, Evd.evar_universe_context sigma)
- else
- CErrors.user_err ~hdr:"STM"
- Pp.(str"The par: selector requires a tactic that makes no progress or fully" ++
- str" solves the goal and leaves no unresolved existential variables. The following" ++
- str" existentials remain unsolved: " ++ prlist (Termops.pr_existential_key sigma) (Evar.Set.elements evars))
- end) ()
- with e when CErrors.noncritical e ->
- RespError (CErrors.print e ++ spc() ++ str "(for subgoal "++int (fst r_ast) ++ str ")")
-
- let name_of_task { t_name } = t_name
- let name_of_request { r_name } = r_name
-
-end (* }}} *)
-
-and Partac : sig
-
- val vernac_interp :
- solve:bool -> abstract:bool -> cancel_switch:AsyncTaskQueue.cancel_switch ->
- int -> CoqworkmgrApi.priority -> Stateid.t -> Stateid.t -> aast -> unit
-
-end = struct (* {{{ *)
-
- module TaskQueue = AsyncTaskQueue.MakeQueue(TacTask) ()
-
- let stm_fail ~st fail f =
- if fail then
- Vernacinterp.with_fail ~st f
- else
- f ()
-
- let vernac_interp ~solve ~abstract ~cancel_switch nworkers priority safe_id id
- { indentation; verbose; expr = e; strlen } : unit
- =
- let cl, time, batch, fail =
- let rec find ~time ~batch ~fail cl = match cl with
- | ControlTime batch :: cl -> find ~time:true ~batch ~fail cl
- | ControlRedirect _ :: cl -> find ~time ~batch ~fail cl
- | ControlFail :: cl -> find ~time ~batch ~fail:true cl
- | cl -> cl, time, batch, fail in
- find ~time:false ~batch:false ~fail:false e.CAst.v.control in
- let e = CAst.map (fun cmd -> { cmd with control = cl }) e in
- let st = Vernacstate.freeze_interp_state ~marshallable:false in
- stm_fail ~st fail (fun () ->
- (if time then System.with_time ~batch ~header:(Pp.mt ()) else (fun x -> x)) (fun () ->
- TaskQueue.with_n_workers nworkers priority (fun queue ->
- PG_compat.map_proof (fun p ->
- let Proof.{goals} = Proof.data p in
- let open TacTask in
- let res = CList.map_i (fun i g ->
- let f, assign =
- Future.create_delegate
- ~name:(Printf.sprintf "subgoal %d" i)
- (State.exn_on id ~valid:safe_id) in
- let t_ast = (i, { indentation; verbose; expr = e; strlen }) in
- let t_name = Goal.uid g in
- TaskQueue.enqueue_task queue
- { t_state = safe_id; t_state_fb = id;
- t_assign = assign; t_ast; t_goal = g; t_name;
- t_kill = (fun () -> if solve then TaskQueue.cancel_all queue) }
- ~cancel_switch;
- g,f)
- 1 goals in
- TaskQueue.join queue;
- let assign_tac : unit Proofview.tactic =
- Proofview.(Goal.enter begin fun g ->
- let gid = Goal.goal g in
- let f =
- try List.assoc gid res
- with Not_found -> CErrors.anomaly(str"Partac: wrong focus.") in
- if not (Future.is_over f) then
- (* One has failed and cancelled the others, but not this one *)
- if solve then Tacticals.New.tclZEROMSG
- (str"Interrupted by the failure of another goal")
- else tclUNIT ()
- else
- let open Notations in
- match Future.join f with
- | Some (pt, uc) ->
- let sigma, env = PG_compat.get_current_context () in
- let push_state ctx =
- Proofview.tclEVARMAP >>= fun sigma ->
- Proofview.Unsafe.tclEVARS (Evd.merge_universe_context sigma ctx)
- in
- stm_pperr_endline (fun () -> hov 0 (
- str"g=" ++ int (Evar.repr gid) ++ spc () ++
- str"t=" ++ (Printer.pr_constr_env env sigma pt) ++ spc () ++
- str"uc=" ++ Termops.pr_evar_universe_context uc));
- (if abstract then Abstract.tclABSTRACT None else (fun x -> x))
- (push_state uc <*>
- Tactics.exact_no_check (EConstr.of_constr pt))
- | None ->
- if solve then Tacticals.New.tclSOLVE [] else tclUNIT ()
- end)
- in
- let p,_,() = Proof.run_tactic (Global.env()) assign_tac p in
- p))) ())
-
-end (* }}} *)
-
and QueryTask : sig
type task = { t_where : Stateid.t; t_for : Stateid.t ; t_what : aast }
@@ -2361,15 +2136,7 @@ let known_state ~doc ?(redefine_qed=false) ~cache id =
), cache, true
| `Cmd { cast = x; cqueue = `SkipQueue } -> (fun () ->
reach view.next), cache, true
- | `Cmd { cast = x; cqueue = `TacQueue (solve,abstract,cancel_switch); cblock } ->
- (fun () ->
- resilient_tactic id cblock (fun () ->
- reach ~cache:true view.next;
- Partac.vernac_interp ~solve ~abstract ~cancel_switch
- !cur_opt.async_proofs_n_tacworkers
- !cur_opt.async_proofs_worker_priority view.next id x)
- ), cache, true
- | `Cmd { cast = x; cqueue = `QueryQueue cancel_switch }
+ | `Cmd { cast = x; cqueue = `QueryQueue; cancel_switch }
when async_proofs_is_master !cur_opt -> (fun () ->
reach view.next;
Query.vernac_interp ~cancel_switch view.next id x
@@ -2377,7 +2144,6 @@ let known_state ~doc ?(redefine_qed=false) ~cache id =
| `Cmd { cast = x; ceff = eff; ctac = true; cblock } -> (fun () ->
resilient_tactic id cblock (fun () ->
reach view.next;
- (* State resulting from reach *)
let st = Vernacstate.freeze_interp_state ~marshallable:false in
ignore(stm_vernac_interp id st x)
)
@@ -2509,8 +2275,9 @@ let known_state ~doc ?(redefine_qed=false) ~cache id =
), true, true
| `MaybeASync (start, nodes, name, delegate) -> (fun () ->
reach ~cache:true start;
- (* no sections *)
- if CList.is_empty (Environ.named_context (Global.env ()))
+ if CList.is_empty (Environ.named_context (Global.env ())) (* no sections *)
+ || PG_compat.get_pstate () |> (* #[using] attribute *)
+ Option.cata (fun x -> Option.has_some (Declare.Proof.get_used_variables x)) false
then Util.pi1 (aux (`ASync (start, nodes, name, delegate))) ()
else Util.pi1 (aux (`Sync (name, `NoPU_NoHint_NoES))) ()
), not redefine_qed, true
@@ -2588,6 +2355,7 @@ let doc_type_module_name (std : stm_doc_type) =
let init_core () =
if !cur_opt.async_proofs_mode = APon then Control.enable_thread_delay := true;
+ if !Flags.async_proofs_worker_id = "master" then Partac.enable_par ~nworkers:!cur_opt.async_proofs_n_tacworkers;
State.register_root_state ()
let dirpath_of_file f =
@@ -2938,12 +2706,9 @@ let process_transaction ~doc ?(newtip=Stateid.fresh ())
VCS.set_parsing_state id head_parsing;
Backtrack.record (); `Ok
- | VtProofStep { parallel; proof_block_detection = cblock } ->
+ | VtProofStep { proof_block_detection = cblock } ->
let id = VCS.new_node ~id:newtip proof_mode () in
- let queue =
- match parallel with
- | `Yes(solve,abstract) -> `TacQueue (solve, abstract, ref false)
- | `No -> `MainQueue in
+ let queue = `MainQueue in
VCS.commit id (mkTransTac x cblock queue);
(* Static proof block detection delayed until an error really occurs.
If/when and UI will make something useful with this piece of info,
diff --git a/stm/stm.mli b/stm/stm.mli
index 9780c96512..097bcbe0ca 100644
--- a/stm/stm.mli
+++ b/stm/stm.mli
@@ -195,7 +195,6 @@ val set_perspective : doc:doc -> Stateid.t list -> unit
(** workers **************************************************************** **)
module ProofTask : AsyncTaskQueue.Task
-module TacTask : AsyncTaskQueue.Task
module QueryTask : AsyncTaskQueue.Task
(** document structure customization *************************************** **)
diff --git a/stm/stm.mllib b/stm/stm.mllib
index 4b254e8113..831369625f 100644
--- a/stm/stm.mllib
+++ b/stm/stm.mllib
@@ -6,6 +6,7 @@ WorkerPool
Vernac_classifier
CoqworkmgrApi
AsyncTaskQueue
+Partac
Stm
ProofBlockDelimiter
Vio_checking
diff --git a/stm/vernac_classifier.ml b/stm/vernac_classifier.ml
index f89fb9f52d..ffae2866c0 100644
--- a/stm/vernac_classifier.ml
+++ b/stm/vernac_classifier.ml
@@ -15,11 +15,6 @@ open CAst
open Vernacextend
open Vernacexpr
-let string_of_parallel = function
- | `Yes (solve,abs) ->
- "par" ^ if solve then "solve" else "" ^ if abs then "abs" else ""
- | `No -> ""
-
let string_of_vernac_when = function
| VtLater -> "Later"
| VtNow -> "Now"
@@ -30,9 +25,8 @@ let string_of_vernac_classification = function
| VtQed (VtKeep VtKeepAxiom) -> "Qed(admitted)"
| VtQed (VtKeep (VtKeepOpaque | VtKeepDefined)) -> "Qed(keep)"
| VtQed VtDrop -> "Qed(drop)"
- | VtProofStep { parallel; proof_block_detection } ->
- "ProofStep " ^ string_of_parallel parallel ^
- Option.default "" proof_block_detection
+ | VtProofStep { proof_block_detection } ->
+ "ProofStep " ^ Option.default "" proof_block_detection
| VtQuery -> "Query"
| VtMeta -> "Meta "
| VtProofMode _ -> "Proof Mode"
@@ -80,12 +74,11 @@ let classify_vernac e =
| VernacCheckGuard
| VernacUnfocused
| VernacSolveExistential _ ->
- VtProofStep { parallel = `No; proof_block_detection = None }
+ VtProofStep { proof_block_detection = None }
| VernacBullet _ ->
- VtProofStep { parallel = `No; proof_block_detection = Some "bullet" }
+ VtProofStep { proof_block_detection = Some "bullet" }
| VernacEndSubproof ->
- VtProofStep { parallel = `No;
- proof_block_detection = Some "curly" }
+ VtProofStep { proof_block_detection = Some "curly" }
(* StartProof *)
| VernacDefinition ((DoDischarge,_),({v=i},_),ProveBody _) ->
VtStartProof(Doesn'tGuaranteeOpacity, idents_of_name i)
@@ -135,7 +128,7 @@ let classify_vernac e =
| Constructors l -> List.map (fun (_,({v=id},_)) -> id) l
| RecordDecl (oid,l) -> (match oid with Some {v=x} -> [x] | _ -> []) @
CList.map_filter (function
- | AssumExpr({v=Names.Name n},_), _ -> Some n
+ | AssumExpr({v=Names.Name n},_,_), _ -> Some n
| _ -> None) l) l in
VtSideff (List.flatten ids, VtLater)
| VernacScheme l ->
@@ -213,7 +206,7 @@ let classify_vernac e =
(match static_classifier ~atts:v.attrs v.expr with
| VtQuery | VtProofStep _ | VtSideff _
| VtMeta as x -> x
- | VtQed _ -> VtProofStep { parallel = `No; proof_block_detection = None }
+ | VtQed _ -> VtProofStep { proof_block_detection = None }
| VtStartProof _ | VtProofMode _ -> VtQuery)
else
static_classifier ~atts:v.attrs v.expr
diff --git a/tactics/btermdn.ml b/tactics/btermdn.ml
index f721e9956b..af0ca22868 100644
--- a/tactics/btermdn.ml
+++ b/tactics/btermdn.ml
@@ -27,7 +27,7 @@ type term_label =
| SortLabel
let compare_term_label t1 t2 = match t1, t2 with
-| GRLabel gr1, GRLabel gr2 -> GlobRef.Ordered.compare gr1 gr2
+| GRLabel gr1, GRLabel gr2 -> GlobRef.CanOrd.compare gr1 gr2
| _ -> pervasives_compare t1 t2 (** OK *)
type 'res lookup_res = 'res Dn.lookup_res = Label of 'res | Nothing | Everything
diff --git a/tactics/cbn.ml b/tactics/cbn.ml
index 8f0966a486..31873ea6b0 100644
--- a/tactics/cbn.ml
+++ b/tactics/cbn.ml
@@ -225,8 +225,8 @@ struct
let equal_cst_member x y =
match x, y with
| Cst_const (c1,u1), Cst_const (c2, u2) ->
- Constant.equal c1 c2 && Univ.Instance.equal u1 u2
- | Cst_proj p1, Cst_proj p2 -> Projection.repr_equal p1 p2
+ Constant.CanOrd.equal c1 c2 && Univ.Instance.equal u1 u2
+ | Cst_proj p1, Cst_proj p2 -> Projection.Repr.CanOrd.equal (Projection.repr p1) (Projection.repr p2)
| _, _ -> false
in
let rec equal_rec sk1 sk2 =
@@ -239,7 +239,7 @@ struct
| Case (_,t1,_,a1,_) :: s1, Case (_,t2,_,a2,_) :: s2 ->
f t1 t2 && CArray.equal (fun x y -> f x y) a1 a2 && equal_rec s1 s2
| (Proj (p,_)::s1, Proj(p2,_)::s2) ->
- Projection.Repr.equal (Projection.repr p) (Projection.repr p2)
+ Projection.Repr.CanOrd.equal (Projection.repr p) (Projection.repr p2)
&& equal_rec s1 s2
| Fix (f1,s1,_) :: s1', Fix (f2,s2,_) :: s2' ->
f_fix f1 f2
@@ -543,7 +543,7 @@ let rec whd_state_gen ?csts ~refold ~tactic_mode flags env sigma =
let open Pp in
let pr c = Termops.Internal.print_constr_env env sigma c in
Feedback.msg_debug
- (h 0 (str "<<" ++ pr x ++
+ (h (str "<<" ++ pr x ++
str "|" ++ cut () ++ Cst_stack.pr env sigma cst_l ++
str "|" ++ cut () ++ Stack.pr pr stack ++
str ">>"))
diff --git a/tactics/class_tactics.ml b/tactics/class_tactics.ml
index ed92a85a12..9e66e8668f 100644
--- a/tactics/class_tactics.ml
+++ b/tactics/class_tactics.ml
@@ -482,8 +482,7 @@ let make_resolve_hyp env sigma st only_classes pri decl =
let keep = not only_classes || is_class in
if keep then
let id = GlobRef.VarRef id in
- let name = PathHints [id] in
- (make_resolves env sigma pri ~name ~check:false (IsGlobRef id))
+ make_resolves env sigma pri id
else []
let make_hints g (modes,st) only_classes sign =
diff --git a/tactics/elim.ml b/tactics/elim.ml
index 49437a2aef..9a55cabc86 100644
--- a/tactics/elim.ml
+++ b/tactics/elim.ml
@@ -193,7 +193,7 @@ let head_in indl t gl =
let sigma = Tacmach.New.project gl in
try
let ity,_ = extract_mrectype sigma t in
- List.exists (fun i -> eq_ind (fst i) (fst ity)) indl
+ List.exists (fun i -> Ind.CanOrd.equal (fst i) (fst ity)) indl
with Not_found -> false
let decompose_these c l =
diff --git a/tactics/equality.ml b/tactics/equality.ml
index 60e2db4dce..486575d229 100644
--- a/tactics/equality.ml
+++ b/tactics/equality.ml
@@ -768,7 +768,7 @@ let find_positions env sigma ~keep_proofs ~no_discr t1 t2 =
in
(* both sides are fully applied constructors, so either we descend,
or we can discriminate here. *)
- if eq_constructor sp1 sp2 then
+ if Construct.CanOrd.equal sp1 sp2 then
let nparams = inductive_nparams env ind1 in
let params1,rargs1 = List.chop nparams args1 in
let _,rargs2 = List.chop nparams args2 in
diff --git a/tactics/hints.ml b/tactics/hints.ml
index fe3efef7c5..68229dbe26 100644
--- a/tactics/hints.ml
+++ b/tactics/hints.ml
@@ -1347,6 +1347,10 @@ let add_hints ~locality dbnames h =
| HintsExternEntry (info, tacexp) ->
add_externs info tacexp ~local ~superglobal dbnames
+let hint_globref gr = IsGlobRef gr
+
+let hint_constr (c, diff) = IsConstr (c, diff)
+
let expand_constructor_hints env sigma lems =
List.map_append (fun (evd,lem) ->
match EConstr.kind sigma lem with
@@ -1365,8 +1369,9 @@ let constructor_hints env sigma eapply lems =
List.map_append (fun lem ->
make_resolves env sigma (eapply, true) empty_hint_info ~check:true lem) lems
-let make_resolves env sigma info ~check ?name hint =
- make_resolves env sigma (true, false) info ~check ?name hint
+let make_resolves env sigma info hint =
+ let name = PathHints [hint] in
+ make_resolves env sigma (true, false) info ~check:false ~name (IsGlobRef hint)
let make_local_hint_db env sigma ts eapply lems =
let map c = c env sigma in
diff --git a/tactics/hints.mli b/tactics/hints.mli
index dd22cff10b..3d4d9c7970 100644
--- a/tactics/hints.mli
+++ b/tactics/hints.mli
@@ -167,9 +167,7 @@ type hint_db = Hint_db.t
type hnf = bool
-type hint_term =
- | IsGlobRef of GlobRef.t
- | IsConstr of constr * Univ.ContextSet.t option [@ocaml.deprecated "Declare a hint constant instead"]
+type hint_term
type hints_entry =
| HintsResolveEntry of (hint_info * hnf * hints_path_atom * hint_term) list
@@ -199,8 +197,10 @@ val current_pure_db : unit -> hint_db list
val add_hints : locality:Goptions.option_locality -> hint_db_name list -> hints_entry -> unit
-val prepare_hint : bool (* Check no remaining evars *) ->
- env -> evar_map -> evar_map * constr -> (constr * Univ.ContextSet.t)
+val hint_globref : GlobRef.t -> hint_term
+
+val hint_constr : constr * Univ.ContextSet.t option -> hint_term
+[@ocaml.deprecated "Declare a hint constant instead"]
(** A constr which is Hint'ed will be:
- (1) used as an Exact, if it does not start with a product
@@ -210,8 +210,7 @@ val prepare_hint : bool (* Check no remaining evars *) ->
has missing arguments. *)
val make_resolves :
- env -> evar_map -> hint_info -> check:bool -> ?name:hints_path_atom ->
- hint_term -> hint_entry list
+ env -> evar_map -> hint_info -> GlobRef.t -> hint_entry list
(** [make_resolve_hyp hname htyp].
used to add an hypothesis to the local hint database;
diff --git a/tactics/tactics.ml b/tactics/tactics.ml
index a607c09010..f3ecc2a9f0 100644
--- a/tactics/tactics.ml
+++ b/tactics/tactics.ml
@@ -540,7 +540,7 @@ let mutual_fix f n rest j = Proofview.Goal.enter begin fun gl ->
| (f, n, ar) :: oth ->
let open Context.Named.Declaration in
let (sp', u') = check_mutind env sigma n ar in
- if not (MutInd.equal sp sp') then
+ if not (QMutInd.equal env sp sp') then
error "Fixpoints should be on the same mutual inductive declaration.";
if mem_named_context_val f sign then
user_err ~hdr:"Logic.prim_refiner"
diff --git a/tactics/term_dnet.ml b/tactics/term_dnet.ml
index 3bcd235b41..df07dcbca7 100644
--- a/tactics/term_dnet.ml
+++ b/tactics/term_dnet.ml
@@ -91,7 +91,7 @@ struct
| DArray (t,def,ty) -> DArray(Array.map f t, f def, f ty)
let compare_ci ci1 ci2 =
- let c = ind_ord ci1.ci_ind ci2.ci_ind in
+ let c = Ind.CanOrd.compare ci1.ci_ind ci2.ci_ind in
if c = 0 then
let c = Int.compare ci1.ci_npar ci2.ci_npar in
if c = 0 then
@@ -107,7 +107,7 @@ struct
| DRel, _ -> -1 | _, DRel -> 1
| DSort, DSort -> 0
| DSort, _ -> -1 | _, DSort -> 1
- | DRef gr1, DRef gr2 -> GlobRef.Ordered.compare gr1 gr2
+ | DRef gr1, DRef gr2 -> GlobRef.CanOrd.compare gr1 gr2
| DRef _, _ -> -1 | _, DRef _ -> 1
| DCtx (tl1, tr1), DCtx (tl2, tr2)
diff --git a/test-suite/bugs/closed/bug_10972.v b/test-suite/bugs/closed/bug_10972.v
new file mode 100644
index 0000000000..945c23c9a4
--- /dev/null
+++ b/test-suite/bugs/closed/bug_10972.v
@@ -0,0 +1,9 @@
+(* Check rewrite_strat is compatible with Ltac *)
+Require Import Coq.Setoids.Setoid.
+Module foo.
+ Definition Foo := True.
+ Ltac foo := rewrite_strat eval cbv [Foo].
+End foo.
+Goal foo.Foo.
+ foo.foo.
+Abort.
diff --git a/test-suite/bugs/closed/bug_12414.v b/test-suite/bugs/closed/bug_12414.v
new file mode 100644
index 0000000000..50b4b86eff
--- /dev/null
+++ b/test-suite/bugs/closed/bug_12414.v
@@ -0,0 +1,13 @@
+Set Universe Polymorphism.
+Set Printing Universes.
+Inductive list {T} : Type := | cons (t : T) : list -> list. (* who needs nil anyway? *)
+Arguments list : clear implicits.
+
+Fixpoint map {A B} (f: A -> B) (l : list A) : list B :=
+ let '(cons t l) := l in cons (f t) (map f l).
+About map@{_ _}.
+(* Two universes, as expected. *)
+
+Definition map_Set@{} {A B : Set} := @map A B.
+
+Definition map_Prop@{} {A B : Prop} := @map A B.
diff --git a/test-suite/bugs/closed/bug_12623.v b/test-suite/bugs/closed/bug_12623.v
new file mode 100644
index 0000000000..9fdcb94e0c
--- /dev/null
+++ b/test-suite/bugs/closed/bug_12623.v
@@ -0,0 +1,18 @@
+Set Universe Polymorphism.
+
+Axiom M : Type -> Prop.
+Axiom raise : forall {T}, M T.
+
+Inductive goal : Type :=
+| AHyp : forall {A : Type}, goal.
+
+Definition gtactic@{u u0} := goal@{u} -> M@{u0} (False).
+
+Class Seq (C : Type) :=
+ seq : C -> gtactic.
+Arguments seq {C _} _.
+
+Instance seq_one : Seq@{Set _ _} (gtactic) := fun t2 => fun g => raise.
+
+Definition x1 : gtactic := @seq@{_ _ _} _ _ (fun g : goal => raise).
+Definition x2 : gtactic := @seq@{_ _ _} _ seq_one (fun g : goal => raise).
diff --git a/test-suite/bugs/closed/bug_12895.v b/test-suite/bugs/closed/bug_12895.v
new file mode 100644
index 0000000000..53adc2981c
--- /dev/null
+++ b/test-suite/bugs/closed/bug_12895.v
@@ -0,0 +1,20 @@
+Fixpoint bug_1 (e1 : nat) {struct e1}
+ : nat
+with bug_2 {H_imp : nat} (e2 : nat) {struct e2}
+ : nat.
+Proof.
+ - exact e1.
+ - exact e2.
+Admitted.
+
+Fixpoint hbug_1 (a:bool) (e1 : nat) {struct e1}
+ : nat
+with hbug_2 (a:nat) (e2 : nat) {struct e2}
+ : nat.
+Proof.
+ - exact e1.
+ - exact e2.
+Admitted.
+
+Check (hbug_1 : bool -> nat -> nat).
+Check (hbug_2 : nat -> nat -> nat).
diff --git a/test-suite/bugs/closed/bug_12947.v b/test-suite/bugs/closed/bug_12947.v
new file mode 100644
index 0000000000..baf0579465
--- /dev/null
+++ b/test-suite/bugs/closed/bug_12947.v
@@ -0,0 +1,9 @@
+Require Import BinPos Int63 PArray.
+
+Definition foo (n : positive) :=
+ let a := make 2 0 in
+ let b := Pos.iter (fun b => set b 1 1) a 100000 in
+ let v := get b 0 in
+ Pos.iter (fun v => v + get a 0) v n.
+
+Timeout 5 Time Eval vm_compute in foo 1000000.
diff --git a/test-suite/bugs/closed/bug_12970.v b/test-suite/bugs/closed/bug_12970.v
new file mode 100644
index 0000000000..69ce7ec2c2
--- /dev/null
+++ b/test-suite/bugs/closed/bug_12970.v
@@ -0,0 +1,4 @@
+Arguments existT _ & _ _.
+
+Definition f := fun X (A : X -> Type) (P : forall x, A x -> Type) x y =>
+ existT (fun f => forall x, P x (f x)) x y : sigT (fun f => forall x, P x (f x)).
diff --git a/test-suite/bugs/closed/bug_13078.v b/test-suite/bugs/closed/bug_13078.v
new file mode 100644
index 0000000000..ec04408fd1
--- /dev/null
+++ b/test-suite/bugs/closed/bug_13078.v
@@ -0,0 +1,10 @@
+(* Check that rules with patterns are not registered for cases patterns *)
+Module PrintingTest.
+Declare Custom Entry test.
+Notation "& x" := (Some x) (in custom test at level 0, x pattern).
+Check fun x => match x with | None => None | Some tt => Some tt end.
+Notation "& x" := (Some x) (at level 0, x pattern).
+Check fun x => match x with | None => None | Some tt => Some tt end.
+End PrintingTest.
+
+Fail Notation "x &" := (Some x) (at level 0, x pattern).
diff --git a/test-suite/bugs/closed/bug_13086.v b/test-suite/bugs/closed/bug_13086.v
new file mode 100644
index 0000000000..75f842b1cf
--- /dev/null
+++ b/test-suite/bugs/closed/bug_13086.v
@@ -0,0 +1,11 @@
+Unset Universe Checking.
+
+Definition bad1@{|Set < Set} := Prop.
+
+Set Universe Polymorphism.
+Axiom ax : Type.
+Inductive I@{u} : Prop := foo : ax@{u} -> I.
+
+Definition bad2@{v} (x:I@{v}) : I@{Set} := x.
+
+Definition vsdvds (f : (Prop -> Prop) -> Prop) (x : Set -> Prop) := f x.
diff --git a/test-suite/bugs/closed/bug_13117.v b/test-suite/bugs/closed/bug_13117.v
new file mode 100644
index 0000000000..5db3f9fadc
--- /dev/null
+++ b/test-suite/bugs/closed/bug_13117.v
@@ -0,0 +1,23 @@
+
+Class A := {}.
+
+Class B (x:A) := {}.
+Class B' (a:=A) (x:a) := {}.
+
+Fail Definition foo a `{B a} := 0.
+Definition foo a `{B' a} := 0.
+
+Record C (x:A) := {}.
+Existing Class C.
+
+Fail Definition bar a `{C a} := 0.
+
+
+Definition X := Type.
+
+Class Y (x:X) := {}.
+
+Definition before `{Y Set} := 0.
+
+Existing Class X.
+Fail Definition after `{Y Set} := 0.
diff --git a/test-suite/bugs/closed/bug_13129.v b/test-suite/bugs/closed/bug_13129.v
new file mode 100644
index 0000000000..632605ecc7
--- /dev/null
+++ b/test-suite/bugs/closed/bug_13129.v
@@ -0,0 +1,58 @@
+From Coq Require Export Morphisms Setoid .
+
+Class Equiv A := equiv: relation A.
+
+Infix "≡" := equiv (at level 70, no associativity).
+Infix "≡@{ A }" := (@equiv A _)
+ (at level 70, only parsing, no associativity).
+
+Notation "(≡)" := equiv (only parsing).
+
+(** Unbundled version *)
+Class Dist A := dist : nat -> relation A.
+
+Notation "x ≡{ n }≡ y" := (dist n x y)
+ (at level 70, n at next level, format "x ≡{ n }≡ y").
+Notation "x ≡{ n }@{ A }≡ y" := (dist (A:=A) n x y)
+ (at level 70, n at next level, only parsing).
+
+Notation NonExpansive f := (forall n, Proper (dist n ==> dist n ==> dist n) f).
+
+Record OfeMixin A `{Equiv A, Dist A} := {
+ mixin_equiv_dist (x y : A) : x ≡ y <-> forall n, x ≡{n}≡ y;
+}.
+
+(** Bundled version *)
+Structure ofeT := OfeT {
+ ofe_car :> Type;
+ ofe_equiv : Equiv ofe_car;
+ ofe_dist : Dist ofe_car;
+ ofe_mixin : OfeMixin ofe_car
+}.
+Hint Extern 0 (Equiv _) => eapply (@ofe_equiv _) : typeclass_instances.
+Hint Extern 0 (Dist _) => eapply (@ofe_dist _) : typeclass_instances.
+
+(** Lifting properties from the mixin *)
+Section ofe_mixin.
+ Context {A : ofeT}.
+ Implicit Types x y : A.
+ Lemma equiv_dist x y : x ≡ y <-> forall n, x ≡{n}≡ y.
+ Proof. apply (mixin_equiv_dist _ (ofe_mixin A)). Qed.
+End ofe_mixin.
+
+Axiom _0 : Prop. (* dummy which somehow bothers mangle names *)
+Set Mangle Names.
+
+(** General properties *)
+Section ofe.
+ Context {A : ofeT}.
+
+ Lemma ne_proper_2 {B C : ofeT} (f : A -> B -> C) `{Hf:!NonExpansive f} :
+ Proper ((≡) ==> (≡) ==> (≡)) f.
+ Proof.
+ unfold Proper, respectful.
+ setoid_rewrite equiv_dist.
+ intros.
+ apply Hf;auto.
+ Qed.
+End ofe.
diff --git a/test-suite/bugs/closed/bug_13131.v b/test-suite/bugs/closed/bug_13131.v
new file mode 100644
index 0000000000..b358ae3ecc
--- /dev/null
+++ b/test-suite/bugs/closed/bug_13131.v
@@ -0,0 +1,6 @@
+Set Mangle Names.
+
+Class A := {}.
+
+Lemma foo `{A} : A.
+Proof. Fail exact H. assumption. Qed.
diff --git a/test-suite/bugs/closed/bug_13162.v b/test-suite/bugs/closed/bug_13162.v
new file mode 100644
index 0000000000..eacc8980a9
--- /dev/null
+++ b/test-suite/bugs/closed/bug_13162.v
@@ -0,0 +1,7 @@
+
+Module Type T. End T.
+Module F (X:T). End F.
+Fail Import F.
+(* Error: Anomaly "Uncaught exception Not_found." *)
+
+Fail Import T.
diff --git a/test-suite/bugs/closed/bug_13169.v b/test-suite/bugs/closed/bug_13169.v
new file mode 100644
index 0000000000..a0b564c725
--- /dev/null
+++ b/test-suite/bugs/closed/bug_13169.v
@@ -0,0 +1,14 @@
+Goal False.
+Proof.
+ set (H1:=I).
+ set (x:=true).
+ assert (H2: x = true) by reflexivity.
+ set (y:=false).
+ assert (H3: y = false) by reflexivity.
+ clearbody H1 x y.
+ eenough (H4: _ = false).
+ vm_compute in H4.
+ (* H4 now has "x:=y" in the evar context. *)
+ 2: exact H3.
+ match type of H4 with y = false => idtac end.
+Abort.
diff --git a/test-suite/bugs/closed/bug_13171.v b/test-suite/bugs/closed/bug_13171.v
new file mode 100644
index 0000000000..0564722729
--- /dev/null
+++ b/test-suite/bugs/closed/bug_13171.v
@@ -0,0 +1,10 @@
+Primitive array := #array_type.
+
+Goal False.
+Proof.
+ unshelve epose (_:nat). exact_no_check true.
+ Fail let c := open_constr:([| n | 0 |]) in
+ let c := eval cbv in c in
+ let c := type of c in
+ idtac c.
+Abort.
diff --git a/test-suite/bugs/closed/bug_13178.v b/test-suite/bugs/closed/bug_13178.v
new file mode 100644
index 0000000000..d9c516c362
--- /dev/null
+++ b/test-suite/bugs/closed/bug_13178.v
@@ -0,0 +1,3 @@
+Primitive array := #array_type.
+
+Check [| | 0 |].
diff --git a/test-suite/bugs/closed/bug_13276.v b/test-suite/bugs/closed/bug_13276.v
new file mode 100644
index 0000000000..15ac7e7b36
--- /dev/null
+++ b/test-suite/bugs/closed/bug_13276.v
@@ -0,0 +1,9 @@
+From Coq Require Import Floats.
+Open Scope float_scope.
+
+Lemma foo :
+ let n := opp 0 in sub n 0 = n.
+Proof.
+cbv.
+apply eq_refl.
+Qed.
diff --git a/test-suite/bugs/closed/bug_5197.v b/test-suite/bugs/closed/bug_5197.v
index 0c236e12ad..00b9e9bd9d 100644
--- a/test-suite/bugs/closed/bug_5197.v
+++ b/test-suite/bugs/closed/bug_5197.v
@@ -20,11 +20,11 @@ Definition Typeᶠ : TYPE := {|
rel := fun _ A => (forall ω : Ω, A ω) -> Type;
|}.
Set Printing Universes.
-Fail Definition Typeᵇ : El Typeᶠ :=
+Definition Typeᵇ : El Typeᶠ :=
mkPack _ _ (fun w => Type) (fun w A => (forall ω, A ω) -> Type).
-Definition Typeᵇ : El Typeᶠ :=
- mkPack _ (fun _ (A : Ω -> Type) => (forall ω : Ω, A ω) -> _) (fun w => Type) (fun w A => (forall ω, A ω) -> Type).
+(* Definition Typeᵇ : El Typeᶠ := *)
+(* mkPack _ (fun _ (A : Ω -> Type) => (forall ω : Ω, A ω) -> _) (fun w => Type) (fun w A => (forall ω, A ω) -> Type). *)
(** Bidirectional typechecking helps here *)
Require Import Program.Tactics.
diff --git a/test-suite/bugs/opened/bug_3395.v b/test-suite/bugs/opened/bug_3395.v
deleted file mode 100644
index 70b3a48a06..0000000000
--- a/test-suite/bugs/opened/bug_3395.v
+++ /dev/null
@@ -1,232 +0,0 @@
-Require Import TestSuite.admit.
-(* File reduced by coq-bug-finder from originally 10918 lines, then 3649 lines to 3177 lines, then from 3189 lines to 3164 lines, then from 2653 lines to 2496 lines, 2653 lines, then from 1642 lines to 651 lines, then from 736 lines to 473 lines, then from 433 lines to 275 lines, then from 258 lines to 235 lines. *)
-Generalizable All Variables.
-Set Implicit Arguments.
-
-Arguments fst {_ _} _.
-Arguments snd {_ _} _.
-
-Axiom cheat : forall {T}, T.
-
-Reserved Notation "g 'o' f" (at level 40, left associativity).
-
-Inductive paths {A : Type} (a : A) : A -> Type := idpath : paths a a.
-Arguments idpath {A a} , [A] a.
-Notation "x = y" := (paths x y) : type_scope.
-
-Definition symmetry {A : Type} {x y : A} (p : x = y) : y = x
- := match p with idpath => idpath end.
-
-Delimit Scope morphism_scope with morphism.
-Delimit Scope category_scope with category.
-Delimit Scope object_scope with object.
-Record PreCategory (object : Type) :=
- Build_PreCategory' {
- object :> Type := object;
- morphism : object -> object -> Type;
- identity : forall x, morphism x x;
- compose : forall s d d',
- morphism d d'
- -> morphism s d
- -> morphism s d'
- where "f 'o' g" := (compose f g);
- associativity : forall x1 x2 x3 x4
- (m1 : morphism x1 x2)
- (m2 : morphism x2 x3)
- (m3 : morphism x3 x4),
- (m3 o m2) o m1 = m3 o (m2 o m1);
- associativity_sym : forall x1 x2 x3 x4
- (m1 : morphism x1 x2)
- (m2 : morphism x2 x3)
- (m3 : morphism x3 x4),
- m3 o (m2 o m1) = (m3 o m2) o m1;
- left_identity : forall a b (f : morphism a b), identity b o f = f;
- right_identity : forall a b (f : morphism a b), f o identity a = f;
- identity_identity : forall x, identity x o identity x = identity x
- }.
-Bind Scope category_scope with PreCategory.
-Arguments PreCategory {_}.
-Arguments identity {_} [!C%category] x%object : rename.
-
-Arguments compose {_} [!C%category s%object d%object d'%object] m1%morphism m2%morphism : rename.
-
-Infix "o" := compose : morphism_scope.
-
-Delimit Scope functor_scope with functor.
-Local Open Scope morphism_scope.
-Record Functor `(C : @PreCategory objC, D : @PreCategory objD) :=
- {
- object_of :> C -> D;
- morphism_of : forall s d, morphism C s d
- -> morphism D (object_of s) (object_of d);
- composition_of : forall s d d'
- (m1 : morphism C s d) (m2: morphism C d d'),
- morphism_of _ _ (m2 o m1)
- = (morphism_of _ _ m2) o (morphism_of _ _ m1);
- identity_of : forall x, morphism_of _ _ (identity x)
- = identity (object_of x)
- }.
-Bind Scope functor_scope with Functor.
-
-Arguments morphism_of {_} [C%category] {_} [D%category] F%functor [s%object d%object] m%morphism : rename, simpl nomatch.
-
-Notation "F '_1' m" := (morphism_of F m) (at level 10, no associativity) : morphism_scope.
-
-Class IsIsomorphism `{C : @PreCategory objC} {s d} (m : morphism C s d) :=
- {
- morphism_inverse : morphism C d s;
- left_inverse : morphism_inverse o m = identity _;
- right_inverse : m o morphism_inverse = identity _
- }.
-
-Definition opposite `(C : @PreCategory objC) : PreCategory
- := @Build_PreCategory'
- C
- (fun s d => morphism C d s)
- (identity (C := C))
- (fun _ _ _ m1 m2 => m2 o m1)
- (fun _ _ _ _ _ _ _ => @associativity_sym _ _ _ _ _ _ _ _ _)
- (fun _ _ _ _ _ _ _ => @associativity _ _ _ _ _ _ _ _ _)
- (fun _ _ => @right_identity _ _ _ _)
- (fun _ _ => @left_identity _ _ _ _)
- (@identity_identity _ C).
-
-Notation "C ^op" := (opposite C) (at level 3) : category_scope.
-
-Definition prod `(C : @PreCategory objC, D : @PreCategory objD) : @PreCategory (objC * objD).
- refine (@Build_PreCategory'
- (C * D)%type
- (fun s d => (morphism C (fst s) (fst d)
- * morphism D (snd s) (snd d))%type)
- (fun x => (identity (fst x), identity (snd x)))
- (fun s d d' m2 m1 => (fst m2 o fst m1, snd m2 o snd m1))
- _
- _
- _
- _
- _); admit.
-Defined.
-Infix "*" := prod : category_scope.
-
-Definition compose_functor `(C : @PreCategory objC, D : @PreCategory objD, E : @PreCategory objE) (G : Functor D E) (F : Functor C D) : Functor C E
- := Build_Functor
- C E
- (fun c => G (F c))
- (fun _ _ m => morphism_of G (morphism_of F m))
- cheat
- cheat.
-
-Infix "o" := compose_functor : functor_scope.
-
-Record NaturalTransformation `(C : @PreCategory objC, D : @PreCategory objD) (F G : Functor C D) :=
- Build_NaturalTransformation' {
- components_of :> forall c, morphism D (F c) (G c);
- commutes : forall s d (m : morphism C s d),
- components_of d o F _1 m = G _1 m o components_of s;
-
- commutes_sym : forall s d (m : C.(morphism) s d),
- G _1 m o components_of s = components_of d o F _1 m
- }.
-Definition functor_category `(C : @PreCategory objC, D : @PreCategory objD) : PreCategory
- := @Build_PreCategory' (Functor C D)
- (@NaturalTransformation _ C _ D)
- cheat
- cheat
- cheat
- cheat
- cheat
- cheat
- cheat.
-
-Definition opposite_functor `(F : @Functor objC C objD D) : Functor C^op D^op
- := Build_Functor (C^op) (D^op)
- (object_of F)
- (fun s d => morphism_of F (s := d) (d := s))
- (fun d' d s m1 m2 => composition_of F s d d' m2 m1)
- (identity_of F).
-
-Definition opposite_invL `(F : @Functor objC C^op objD D) : Functor C D^op
- := Build_Functor C (D^op)
- (object_of F)
- (fun s d => morphism_of F (s := d) (d := s))
- (fun d' d s m1 m2 => composition_of F s d d' m2 m1)
- (identity_of F).
-Notation "F ^op" := (opposite_functor F) : functor_scope.
-
-Notation "F ^op'L" := (opposite_invL F) (at level 3) : functor_scope.
-Definition fst `{C : @PreCategory objC, D : @PreCategory objD} : Functor (C * D) C
- := Build_Functor (C * D) C
- (@fst _ _)
- (fun _ _ => @fst _ _)
- (fun _ _ _ _ _ => idpath)
- (fun _ => idpath).
-
-Definition snd `{C : @PreCategory objC, D : @PreCategory objD} : Functor (C * D) D
- := Build_Functor (C * D) D
- (@snd _ _)
- (fun _ _ => @snd _ _)
- (fun _ _ _ _ _ => idpath)
- (fun _ => idpath).
-Definition prod_functor `(F : @Functor objC C objD D, F' : @Functor objC C objD' D')
-: Functor C (D * D')
- := Build_Functor
- C (D * D')
- (fun c => (F c, F' c))
- (fun s d m => (F _1 m, F' _1 m))%morphism
- cheat
- cheat.
-Definition pair `(F : @Functor objC C objD D, F' : @Functor objC' C' objD' D') : Functor (C * C') (D * D')
- := (prod_functor (F o fst) (F' o snd))%functor.
-Notation cat_of obj :=
- (@Build_PreCategory' obj
- (fun x y => forall _ : x, y)
- (fun _ x => x)
- (fun _ _ _ f g x => f (g x))%core
- (fun _ _ _ _ _ _ _ => idpath)
- (fun _ _ _ _ _ _ _ => idpath)
- (fun _ _ _ => idpath)
- (fun _ _ _ => idpath)
- (fun _ => idpath)).
-
-Definition hom_functor `(C : @PreCategory objC) : Functor (C^op * C) (cat_of Type)
- := Build_Functor _ _ cheat cheat cheat cheat.
-
-Definition induced_hom_natural_transformation `(F : @Functor objC C objD D)
-: NaturalTransformation (hom_functor C) (hom_functor D o pair F^op F)
- := Build_NaturalTransformation' _ _ cheat cheat cheat.
-
-Class IsFullyFaithful `(F : @Functor objC C objD D)
- := is_fully_faithful
- : forall x y : C,
- IsIsomorphism (induced_hom_natural_transformation F (x, y)).
-
-Definition coyoneda `(A : @PreCategory objA) : Functor A^op (@functor_category _ A _ (cat_of Type))
- := cheat.
-
-Definition yoneda `(A : @PreCategory objA) : Functor A (@functor_category _ A^op _ (cat_of Type))
- := (((coyoneda A^op)^op'L)^op'L)%functor.
-Definition coyoneda_embedding `(A : @PreCategory objA) : @IsFullyFaithful _ _ _ _ (@coyoneda _ A).
-Admitted.
-
-Definition yoneda_embedding_fast `(A : @PreCategory objA) : @IsFullyFaithful _ _ _ _ (@yoneda _ A).
-Proof.
- intros a b.
- pose proof (coyoneda_embedding A^op a b) as CYE.
- unfold yoneda.
- Time let t := (type of CYE) in
- let t' := (eval simpl in t) in pose proof ((fun (x : t) => (x : t')) CYE) as CYE'. (* Finished transaction in 0. secs (0.216013u,0.004s) *)
- Fail Timeout 1 let t := match goal with |- ?G => constr:(G) end in
- let t' := (eval simpl in t) in exact ((fun (x : t') => (x : t)) CYE').
- Time let t := match goal with |- ?G => constr:(G) end in
- let t' := (eval simpl in t) in exact ((fun (x : t') => (x : t)) CYE'). (* Finished transaction in 0. secs (0.248016u,0.s) *)
-Fail Timeout 2 Defined.
-Time Defined. (* Finished transaction in 1. secs (0.432027u,0.s) *)
-
-Definition yoneda_embedding `(A : @PreCategory objA) : @IsFullyFaithful _ _ _ _ (@yoneda _ A).
-Proof.
- intros a b.
- pose proof (coyoneda_embedding A^op a b) as CYE.
- unfold yoneda; simpl in *.
- Fail Timeout 1 exact CYE.
- Time exact CYE. (* Finished transaction in 0. secs (0.012001u,0.s) *)
-Abort.
diff --git a/test-suite/ide/proof-diffs.fake b/test-suite/ide/proof-diffs.fake
new file mode 100644
index 0000000000..594ebced23
--- /dev/null
+++ b/test-suite/ide/proof-diffs.fake
@@ -0,0 +1,10 @@
+ADD { Goal True /\ False /\ True = False. }
+ADD { split. }
+GOALS
+ADD here { split. }
+GOALS
+PDIFF here
+ADD there { auto. }
+GOALS
+PDIFF there
+ADD { Admitted. }
diff --git a/test-suite/micromega/int63.v b/test-suite/micromega/int63.v
new file mode 100644
index 0000000000..20dfa2631e
--- /dev/null
+++ b/test-suite/micromega/int63.v
@@ -0,0 +1,24 @@
+Require Import ZArith ZifyInt63 Lia.
+Require Import Int63.
+
+Open Scope int63_scope.
+
+Goal forall (x:int), 0 <= x = true.
+Proof. lia. Qed.
+
+Goal max_int = 9223372036854775807.
+Proof. lia. Qed.
+
+Goal digits = 63.
+Proof. lia. Qed.
+
+Goal wB = (2^63)%Z.
+Proof. lia. Qed.
+
+Goal forall x y, x + y <= max_int = true.
+Proof. lia. Qed.
+
+Goal forall x, x <> 0 -> x / x = 1.
+Proof.
+ nia.
+Qed.
diff --git a/test-suite/misc/quotation_token/src/quotation.mlg b/test-suite/misc/quotation_token/src/quotation.mlg
index 961b170a0d..ba0bcb1b3c 100644
--- a/test-suite/misc/quotation_token/src/quotation.mlg
+++ b/test-suite/misc/quotation_token/src/quotation.mlg
@@ -2,9 +2,9 @@
open Pcoq.Constr
}
GRAMMAR EXTEND Gram
- GLOBAL: operconstr;
+ GLOBAL: term;
- operconstr: LEVEL "0"
+ term: LEVEL "0"
[ [ s = QUOTATION "foobar:" ->
{
CAst.make ~loc Constrexpr.(CSort Glob_term.(UNamed [GProp,0])) } ] ]
diff --git a/test-suite/output/Cases.out b/test-suite/output/Cases.out
index da2fc90fc3..01564e7f25 100644
--- a/test-suite/output/Cases.out
+++ b/test-suite/output/Cases.out
@@ -178,3 +178,6 @@ match N with
| _ => Node
end
: Tree -> Tree
+File "stdin", line 253, characters 4-5:
+Warning: Unused variable B catches more than one case.
+[unused-pattern-matching-variable,pattern-matching]
diff --git a/test-suite/output/Cases.v b/test-suite/output/Cases.v
index 262ec2b677..2d8a8b359c 100644
--- a/test-suite/output/Cases.v
+++ b/test-suite/output/Cases.v
@@ -242,3 +242,15 @@ end.
Print stray.
End Bug11231.
+
+Module Wish12762.
+
+Inductive foo := a | b | c.
+
+Definition bar (f : foo) :=
+ match f with
+ | a => 0
+ | B => 1
+ end.
+
+End Wish12762.
diff --git a/test-suite/output/DependentInductionErrors.out b/test-suite/output/DependentInductionErrors.out
new file mode 100644
index 0000000000..4a83375f6f
--- /dev/null
+++ b/test-suite/output/DependentInductionErrors.out
@@ -0,0 +1,4 @@
+The command has indeed failed with message:
+Tactic failure: To use dependent destruction, first [Require Import Coq.Program.Equality.].
+The command has indeed failed with message:
+Tactic failure: To use dependent induction, first [Require Import Coq.Program.Equality.].
diff --git a/test-suite/output/DependentInductionErrors.v b/test-suite/output/DependentInductionErrors.v
new file mode 100644
index 0000000000..2fce00f9fd
--- /dev/null
+++ b/test-suite/output/DependentInductionErrors.v
@@ -0,0 +1,17 @@
+Theorem foo (b:bool) : b = true \/ b = false.
+Proof.
+ Fail dependent destruction b.
+ Fail dependent induction b.
+Abort.
+
+From Coq Require Import Program.Equality.
+
+Theorem foo_with_destruction (b:bool) : b = true \/ b = false.
+Proof.
+ dependent destruction b; auto.
+Qed.
+
+Theorem foo_with_induction (b:bool) : b = true \/ b = false.
+Proof.
+ dependent induction b; auto.
+Qed.
diff --git a/test-suite/output/ErrorLocation_13241_1.out b/test-suite/output/ErrorLocation_13241_1.out
new file mode 100644
index 0000000000..d899dd5d46
--- /dev/null
+++ b/test-suite/output/ErrorLocation_13241_1.out
@@ -0,0 +1,3 @@
+File "stdin", line 4, characters 0-1:
+Error: No product even after head-reduction.
+
diff --git a/test-suite/output/ErrorLocation_13241_1.v b/test-suite/output/ErrorLocation_13241_1.v
new file mode 100644
index 0000000000..3102b13fb8
--- /dev/null
+++ b/test-suite/output/ErrorLocation_13241_1.v
@@ -0,0 +1,5 @@
+Ltac a := intro.
+Ltac b := a.
+Goal True.
+b.
+Abort.
diff --git a/test-suite/output/ErrorLocation_13241_2.out b/test-suite/output/ErrorLocation_13241_2.out
new file mode 100644
index 0000000000..d899dd5d46
--- /dev/null
+++ b/test-suite/output/ErrorLocation_13241_2.out
@@ -0,0 +1,3 @@
+File "stdin", line 4, characters 0-1:
+Error: No product even after head-reduction.
+
diff --git a/test-suite/output/ErrorLocation_13241_2.v b/test-suite/output/ErrorLocation_13241_2.v
new file mode 100644
index 0000000000..b82f36ed6f
--- /dev/null
+++ b/test-suite/output/ErrorLocation_13241_2.v
@@ -0,0 +1,5 @@
+Ltac a _ := intro.
+Ltac b := a ().
+Goal True.
+b.
+Abort.
diff --git a/test-suite/output/Notations3.out b/test-suite/output/Notations3.out
index abada44da7..bd22d45059 100644
--- a/test-suite/output/Notations3.out
+++ b/test-suite/output/Notations3.out
@@ -231,16 +231,13 @@ fun l : list nat => match l with
: list nat -> list nat
Arguments foo _%list_scope
-Notation
-"'exists' x .. y , p" := ex (fun x => .. (ex (fun y => p)) ..) : type_scope
-(default interpretation)
-"'exists' ! x .. y , p" := ex
- (unique
- (fun x => .. (ex (unique (fun y => p))) ..))
-: type_scope (default interpretation)
-Notation
-"( x , y , .. , z )" := pair .. (pair x y) .. z : core_scope
-(default interpretation)
+Notation "'exists' x .. y , p" := (ex (fun x => .. (ex (fun y => p)) ..))
+ : type_scope (default interpretation)
+Notation "'exists' ! x .. y , p" :=
+ (ex (unique (fun x => .. (ex (unique (fun y => p))) ..))) : type_scope
+ (default interpretation)
+Notation "( x , y , .. , z )" := (pair .. (pair x y) .. z) : core_scope
+ (default interpretation)
1 subgoal
============================
diff --git a/test-suite/output/Notations4.out b/test-suite/output/Notations4.out
index a42518822f..a6fd39c29b 100644
--- a/test-suite/output/Notations4.out
+++ b/test-suite/output/Notations4.out
@@ -8,7 +8,7 @@ Entry custom:myconstr is
| "4" RIGHTA
[ SELF; "*"; NEXT ]
| "3" RIGHTA
- [ "<"; operconstr LEVEL "10"; ">" ] ]
+ [ "<"; term LEVEL "10"; ">" ] ]
[< b > + < b > * < 2 >]
: nat
@@ -77,7 +77,7 @@ The command has indeed failed with message:
The format is not the same on the right- and left-hand sides of the special token "..".
Entry custom:expr is
[ "201" RIGHTA
- [ "{"; operconstr LEVEL "200"; "}" ] ]
+ [ "{"; term LEVEL "200"; "}" ] ]
fun x : nat => [ x ]
: nat -> nat
@@ -125,3 +125,57 @@ Warning: Notation "_ :=: _" was already used. [notation-overridden,parsing]
: Prop
fun x : nat => <{ x; (S x) }>
: nat -> nat
+exists p : nat, ▢_p (p >= 1)
+ : Prop
+▢_n (n >= 1)
+ : Prop
+The command has indeed failed with message:
+Found an inductive type while a variable name was expected.
+The command has indeed failed with message:
+Found a constructor while a variable name was expected.
+The command has indeed failed with message:
+Found a constant while a variable name was expected.
+exists x y : nat, ▢_(x, y) (x >= 1 /\ y >= 2)
+ : Prop
+▢_n (n >= 1)
+ : Prop
+The command has indeed failed with message:
+Found an inductive type while a pattern was expected.
+▢_tt (tt = tt)
+ : Prop
+The command has indeed failed with message:
+Found a constant while a pattern was expected.
+exists x y : nat, ▢_(x, y) (x >= 1 /\ y >= 2)
+ : Prop
+pseudo_force n (fun n : nat => n >= 1)
+ : Prop
+The command has indeed failed with message:
+Found an inductive type while a pattern was expected.
+▢_tt (tt = tt)
+ : Prop
+The command has indeed failed with message:
+Found a constant while a pattern was expected.
+exists x y : nat, myforce (x, y) (x >= 1 /\ y >= 2)
+ : Prop
+myforce n (n >= 1)
+ : Prop
+The command has indeed failed with message:
+Found an inductive type while a pattern was expected.
+myforce tt (tt = tt)
+ : Prop
+The command has indeed failed with message:
+Found a constant while a pattern was expected.
+id nat
+ : Set
+fun a : bool => id a
+ : bool -> bool
+fun nat : bool => id nat
+ : bool -> bool
+The command has indeed failed with message:
+Found an inductive type while a pattern was expected.
+!! nat, nat = true
+ : Prop
+!!! nat, nat = true
+ : Prop
+!!!! (nat, id), nat = true /\ id = false
+ : Prop
diff --git a/test-suite/output/Notations4.v b/test-suite/output/Notations4.v
index 6dadd8c7fe..0731819bba 100644
--- a/test-suite/output/Notations4.v
+++ b/test-suite/output/Notations4.v
@@ -124,7 +124,7 @@ Check r 2 3.
End I.
Require Import Coq.Numbers.Cyclic.Int63.Int63.
-Module NumeralNotations.
+Module NumberNotations.
Module Test17.
(** Test int63 *)
Declare Scope test17_scope.
@@ -134,7 +134,7 @@ Module NumeralNotations.
Number Notation myint63 of_int to_int : test17_scope.
Check let v := 0%test17 in v : myint63.
End Test17.
-End NumeralNotations.
+End NumberNotations.
Module K.
@@ -313,3 +313,104 @@ Notation "x" := x (in custom com_top at level 90, x custom com at level 90).
Check fun x => <{ x ; (S x) }>.
End CoercionEntryTransitivity.
+
+(* Some corner cases *)
+
+Module P.
+
+(* Basic rules:
+ - a section variable be used for itself and as a binding variable
+ - a global name cannot be used for itself and as a binding variable
+*)
+
+ Definition pseudo_force {A} (n:A) (P:A -> Prop) := forall n', n' = n -> P n'.
+
+ Module NotationMixedTermBinderAsIdent.
+
+ Notation "▢_ n P" := (pseudo_force n (fun n => P))
+ (at level 0, n ident, P at level 9, format "▢_ n P").
+ Check exists p, ▢_p (p >= 1).
+ Section S.
+ Variable n:nat.
+ Check ▢_n (n >= 1).
+ End S.
+ Fail Check ▢_nat (nat = bool).
+ Fail Check ▢_O (O >= 1).
+ Axiom n:nat.
+ Fail Check ▢_n (n >= 1).
+
+ End NotationMixedTermBinderAsIdent.
+
+ Module NotationMixedTermBinderAsPattern.
+
+ Notation "▢_ n P" := (pseudo_force n (fun n => P))
+ (at level 0, n pattern, P at level 9, format "▢_ n P").
+ Check exists x y, ▢_(x,y) (x >= 1 /\ y >= 2).
+ Section S.
+ Variable n:nat.
+ Check ▢_n (n >= 1).
+ End S.
+ Fail Check ▢_nat (nat = bool).
+ Check ▢_tt (tt = tt).
+ Axiom n:nat.
+ Fail Check ▢_n (n >= 1).
+
+ End NotationMixedTermBinderAsPattern.
+
+ Module NotationMixedTermBinderAsStrictPattern.
+
+ Notation "▢_ n P" := (pseudo_force n (fun n => P))
+ (at level 0, n strict pattern, P at level 9, format "▢_ n P").
+ Check exists x y, ▢_(x,y) (x >= 1 /\ y >= 2).
+ Section S.
+ Variable n:nat.
+ Check ▢_n (n >= 1).
+ End S.
+ Fail Check ▢_nat (nat = bool).
+ Check ▢_tt (tt = tt).
+ Axiom n:nat.
+ Fail Check ▢_n (n >= 1).
+
+ End NotationMixedTermBinderAsStrictPattern.
+
+ Module AbbreviationMixedTermBinderAsStrictPattern.
+
+ Notation myforce n P := (pseudo_force n (fun n => P)).
+ Check exists x y, myforce (x,y) (x >= 1 /\ y >= 2).
+ Section S.
+ Variable n:nat.
+ Check myforce n (n >= 1). (* strict hence not used for printing *)
+ End S.
+ Fail Check myforce nat (nat = bool).
+ Check myforce tt (tt = tt).
+ Axiom n:nat.
+ Fail Check myforce n (n >= 1).
+
+ End AbbreviationMixedTermBinderAsStrictPattern.
+
+ Module Bug4765Part.
+
+ Notation id x := ((fun y => y) x).
+ Check id nat.
+
+ Notation id' x := ((fun x => x) x).
+ Check fun a : bool => id' a.
+ Check fun nat : bool => id' nat.
+ Fail Check id' nat.
+
+ End Bug4765Part.
+
+ Module NotationBinderNotMixedWithTerms.
+
+ Notation "!! x , P" := (forall x, P) (at level 200, x pattern).
+ Check !! nat, nat = true.
+
+ Notation "!!! x , P" := (forall x, P) (at level 200).
+ Check !!! nat, nat = true.
+
+ Notation "!!!! x , P" := (forall x, P) (at level 200, x strict pattern).
+ Check !!!! (nat,id), nat = true /\ id = false.
+
+ End NotationBinderNotMixedWithTerms.
+
+End P.
diff --git a/test-suite/output/NumberNotations.out b/test-suite/output/NumberNotations.out
index 8065c8d311..60682edec8 100644
--- a/test-suite/output/NumberNotations.out
+++ b/test-suite/output/NumberNotations.out
@@ -1,9 +1,9 @@
The command has indeed failed with message:
-Unexpected term (nat -> nat) while parsing a numeral notation.
+Unexpected term (nat -> nat) while parsing a number notation.
The command has indeed failed with message:
-Unexpected non-option term opaque4 while parsing a numeral notation.
+Unexpected non-option term opaque4 while parsing a number notation.
The command has indeed failed with message:
-Unexpected term (fun (A : Type) (x : A) => x) while parsing a numeral
+Unexpected term (fun (A : Type) (x : A) => x) while parsing a number
notation.
let v := 0%ppp in v : punit
: punit
@@ -32,7 +32,7 @@ Warning: To avoid stack overflow, large numbers in punit are interpreted as
applications of pto_punits. [abstract-large-number,numbers]
The command has indeed failed with message:
In environment
-v := pto_punits (Numeral.UIntDec (Decimal.D1 Decimal.Nil)) : punit
+v := pto_punits (Number.UIntDecimal (Decimal.D1 Decimal.Nil)) : punit
The term "v" has type "punit@{Set}" while it is expected to have type
"punit@{u}".
S
@@ -61,7 +61,7 @@ The command has indeed failed with message:
In environment
v := 0 : nat
The term "v" has type "nat" while it is expected to have type "wuint".
- = {| unwrap := Numeral.UIntDec (Decimal.D0 Decimal.Nil) |}
+ = {| unwrap := Number.UIntDecimal (Decimal.D0 Decimal.Nil) |}
: wuint
let v := 0%wuint8' in v : wuint
: wuint
@@ -82,7 +82,7 @@ function (of_uint) targets an option type.
The command has indeed failed with message:
The 'abstract after' directive has no effect when the parsing function
(of_uint) targets an option type. [abstract-large-number-no-op,numbers]
-let v := of_uint (Numeral.UIntDec (Decimal.D1 Decimal.Nil)) in v : unit
+let v := of_uint (Number.UIntDecimal (Decimal.D1 Decimal.Nil)) in v : unit
: unit
let v := 0%test13 in v : unit
: unit
@@ -234,3 +234,282 @@ let v : ty := Build_ty Type type in v : ty
: Prop
1_000
: list nat
+0
+ : Set
+1
+ : Set
+2
+ : Set
+3
+ : Set
+Empty_set
+ : Set
+unit
+ : Set
+sum unit unit
+ : Set
+sum unit (sum unit unit)
+ : Set
+The command has indeed failed with message:
+Missing mapping for constructor Isum.
+The command has indeed failed with message:
+Iunit was already mapped to unit and cannot be remapped to unit.
+The command has indeed failed with message:
+add is not an inductive type.
+The command has indeed failed with message:
+add is not a constructor of an inductive type.
+The command has indeed failed with message:
+Missing mapping for constructor Iempty.
+File "stdin", line 574, characters 56-61:
+Warning: Type of I'sum seems incompatible with the type of sum.
+Expected type is: (I' -> I' -> I') instead of (I -> I' -> I').
+This might yield ill typed terms when using the notation.
+[via-type-mismatch,numbers]
+File "stdin", line 579, characters 32-33:
+Warning: I was already mapped to Set, mapping it also to
+nat might yield ill typed terms when using the notation.
+[via-type-remapping,numbers]
+File "stdin", line 579, characters 37-42:
+Warning: Type of Iunit seems incompatible with the type of O.
+Expected type is: I instead of I.
+This might yield ill typed terms when using the notation.
+[via-type-mismatch,numbers]
+The command has indeed failed with message:
+'via' and 'abstract' cannot be used together.
+File "stdin", line 659, characters 21-23:
+Warning: Type of I1 seems incompatible with the type of Fin.F1.
+Expected type is: (nat -> I) instead of I.
+This might yield ill typed terms when using the notation.
+[via-type-mismatch,numbers]
+File "stdin", line 659, characters 35-37:
+Warning: Type of IS seems incompatible with the type of Fin.FS.
+Expected type is: (nat -> I -> I) instead of (I -> I).
+This might yield ill typed terms when using the notation.
+[via-type-mismatch,numbers]
+The command has indeed failed with message:
+The term "0" has type "forall n : nat, Fin.t (S n)"
+while it is expected to have type "nat".
+0
+ : Fin.t (S ?n)
+where
+?n : [ |- nat]
+1
+ : Fin.t (S (S ?n))
+where
+?n : [ |- nat]
+2
+ : Fin.t (S (S (S ?n)))
+where
+?n : [ |- nat]
+3
+ : Fin.t (S (S (S (S ?n))))
+where
+?n : [ |- nat]
+0 : Fin.t 3
+ : Fin.t 3
+1 : Fin.t 3
+ : Fin.t 3
+2 : Fin.t 3
+ : Fin.t 3
+The command has indeed failed with message:
+The term "3" has type "Fin.t (S (S (S (S ?n))))"
+while it is expected to have type "Fin.t 3".
+@Fin.F1 ?n
+ : Fin.t (S ?n)
+where
+?n : [ |- nat]
+@Fin.FS (S ?n) (@Fin.F1 ?n)
+ : Fin.t (S (S ?n))
+where
+?n : [ |- nat]
+@Fin.FS (S (S ?n)) (@Fin.FS (S ?n) (@Fin.F1 ?n))
+ : Fin.t (S (S (S ?n)))
+where
+?n : [ |- nat]
+@Fin.FS (S (S (S ?n))) (@Fin.FS (S (S ?n)) (@Fin.FS (S ?n) (@Fin.F1 ?n)))
+ : Fin.t (S (S (S (S ?n))))
+where
+?n : [ |- nat]
+@Fin.F1 (S (S O)) : Fin.t (S (S (S O)))
+ : Fin.t (S (S (S O)))
+@Fin.FS (S (S O)) (@Fin.F1 (S O)) : Fin.t (S (S (S O)))
+ : Fin.t (S (S (S O)))
+@Fin.FS (S (S O)) (@Fin.FS (S O) (@Fin.F1 O)) : Fin.t (S (S (S O)))
+ : Fin.t (S (S (S O)))
+The command has indeed failed with message:
+The term
+ "@Fin.FS (S (S (S ?n))) (@Fin.FS (S (S ?n)) (@Fin.FS (S ?n) (@Fin.F1 ?n)))"
+has type "Fin.t (S (S (S (S ?n))))" while it is expected to have type
+ "Fin.t (S (S (S O)))".
+0
+ : list unit
+1
+ : list unit
+2
+ : list unit
+2
+ : list unit
+0 :: 0 :: nil
+ : list nat
+0
+ : Ip nat bool
+1
+ : Ip nat bool
+2
+ : Ip nat bool
+3
+ : Ip nat bool
+1
+ : Ip nat bool
+1
+ : Ip nat bool
+1
+ : Ip nat bool
+1
+ : Ip nat bool
+Ip0 nat nat 1
+ : Ip nat nat
+Ip0 bool bool 1
+ : Ip bool bool
+Ip1 nat nat 1
+ : Ip nat nat
+Ip3 1 nat nat
+ : Ip nat nat
+Ip0 nat bool O
+ : Ip nat bool
+Ip1 bool nat (S O)
+ : Ip nat bool
+Ip2 nat (S (S O)) bool
+ : Ip nat bool
+Ip3 (S (S (S O))) nat bool
+ : Ip nat bool
+0
+ : 0 = 0
+eq_refl
+ : 1 = 1
+0
+ : 1 = 1
+2
+ : extra_list_unit
+cons O unit tt (cons O unit tt (nil O unit))
+ : extra_list unit
+0
+ : Set
+1
+ : Set
+2
+ : Set
+3
+ : Set
+Empty_set
+ : Set
+unit
+ : Set
+sum unit unit
+ : Set
+sum unit (sum unit unit)
+ : Set
+0
+ : Fin.t (S ?n)
+where
+?n : [ |- nat]
+1
+ : Fin.t (S (S ?n))
+where
+?n : [ |- nat]
+2
+ : Fin.t (S (S (S ?n)))
+where
+?n : [ |- nat]
+3
+ : Fin.t (S (S (S (S ?n))))
+where
+?n : [ |- nat]
+0 : Fin.t 3
+ : Fin.t 3
+1 : Fin.t 3
+ : Fin.t 3
+2 : Fin.t 3
+ : Fin.t 3
+The command has indeed failed with message:
+The term "3" has type "Fin.t (S (S (S (S ?n))))"
+while it is expected to have type "Fin.t 3".
+@Fin.F1 ?n
+ : Fin.t (S ?n)
+where
+?n : [ |- nat]
+@Fin.FS (S ?n) (@Fin.F1 ?n)
+ : Fin.t (S (S ?n))
+where
+?n : [ |- nat]
+@Fin.FS (S (S ?n)) (@Fin.FS (S ?n) (@Fin.F1 ?n))
+ : Fin.t (S (S (S ?n)))
+where
+?n : [ |- nat]
+@Fin.FS (S (S (S ?n))) (@Fin.FS (S (S ?n)) (@Fin.FS (S ?n) (@Fin.F1 ?n)))
+ : Fin.t (S (S (S (S ?n))))
+where
+?n : [ |- nat]
+@Fin.F1 (S (S O)) : Fin.t (S (S (S O)))
+ : Fin.t (S (S (S O)))
+@Fin.FS (S (S O)) (@Fin.F1 (S O)) : Fin.t (S (S (S O)))
+ : Fin.t (S (S (S O)))
+@Fin.FS (S (S O)) (@Fin.FS (S O) (@Fin.F1 O)) : Fin.t (S (S (S O)))
+ : Fin.t (S (S (S O)))
+The command has indeed failed with message:
+The term
+ "@Fin.FS (S (S (S ?n))) (@Fin.FS (S (S ?n)) (@Fin.FS (S ?n) (@Fin.F1 ?n)))"
+has type "Fin.t (S (S (S (S ?n))))" while it is expected to have type
+ "Fin.t (S (S (S O)))".
+0
+ : Fin.t (S ?n)
+where
+?n : [ |- nat : Set]
+1
+ : Fin.t (S (S ?n))
+where
+?n : [ |- nat : Set]
+2
+ : Fin.t (S (S (S ?n)))
+where
+?n : [ |- nat : Set]
+3
+ : Fin.t (S (S (S (S ?n))))
+where
+?n : [ |- nat : Set]
+0 : Fin.t 3
+ : Fin.t 3
+1 : Fin.t 3
+ : Fin.t 3
+2 : Fin.t 3
+ : Fin.t 3
+The command has indeed failed with message:
+The term "3" has type "Fin.t (S (S (S (S ?n))))"
+while it is expected to have type "Fin.t 3".
+@Fin.F1 ?n
+ : Fin.t (S ?n)
+where
+?n : [ |- nat : Set]
+@Fin.FS (S ?n) (@Fin.F1 ?n)
+ : Fin.t (S (S ?n))
+where
+?n : [ |- nat : Set]
+@Fin.FS (S (S ?n)) (@Fin.FS (S ?n) (@Fin.F1 ?n))
+ : Fin.t (S (S (S ?n)))
+where
+?n : [ |- nat : Set]
+@Fin.FS (S (S (S ?n))) (@Fin.FS (S (S ?n)) (@Fin.FS (S ?n) (@Fin.F1 ?n)))
+ : Fin.t (S (S (S (S ?n))))
+where
+?n : [ |- nat : Set]
+@Fin.F1 (S (S O)) : Fin.t (S (S (S O)))
+ : Fin.t (S (S (S O)))
+@Fin.FS (S (S O)) (@Fin.F1 (S O)) : Fin.t (S (S (S O)))
+ : Fin.t (S (S (S O)))
+@Fin.FS (S (S O)) (@Fin.FS (S O) (@Fin.F1 O)) : Fin.t (S (S (S O)))
+ : Fin.t (S (S (S O)))
+The command has indeed failed with message:
+The term
+ "@Fin.FS (S (S (S ?n))) (@Fin.FS (S (S ?n)) (@Fin.FS (S ?n) (@Fin.F1 ?n)))"
+has type "Fin.t (S (S (S (S ?n))))" while it is expected to have type
+ "Fin.t (S (S (S O)))".
diff --git a/test-suite/output/NumberNotations.v b/test-suite/output/NumberNotations.v
index e411005da3..718da13500 100644
--- a/test-suite/output/NumberNotations.v
+++ b/test-suite/output/NumberNotations.v
@@ -5,17 +5,17 @@ Declare Scope opaque_scope.
(* https://github.com/coq/coq/pull/8064#discussion_r202497516 *)
Module Test1.
Axiom hold : forall {A B C}, A -> B -> C.
- Definition opaque3 (x : Numeral.int) : Numeral.int := hold x (fix f (x : nat) : nat := match x with O => O | S n => S (f n) end).
- Number Notation Numeral.int opaque3 opaque3 : opaque_scope.
+ Definition opaque3 (x : Number.int) : Number.int := hold x (fix f (x : nat) : nat := match x with O => O | S n => S (f n) end).
+ Number Notation Number.int opaque3 opaque3 : opaque_scope.
Delimit Scope opaque_scope with opaque.
Fail Check 1%opaque.
End Test1.
(* https://github.com/coq/coq/pull/8064#discussion_r202497990 *)
Module Test2.
- Axiom opaque4 : option Numeral.int.
- Definition opaque6 (x : Numeral.int) : option Numeral.int := opaque4.
- Number Notation Numeral.int opaque6 opaque6 : opaque_scope.
+ Axiom opaque4 : option Number.int.
+ Definition opaque6 (x : Number.int) : option Number.int := opaque4.
+ Number Notation Number.int opaque6 opaque6 : opaque_scope.
Delimit Scope opaque_scope with opaque.
Open Scope opaque_scope.
Fail Check 1%opaque.
@@ -24,8 +24,8 @@ End Test2.
Declare Scope silly_scope.
Module Test3.
- Inductive silly := SILLY (v : Numeral.uint) (f : forall A, A -> A).
- Definition to_silly (v : Numeral.uint) := SILLY v (fun _ x => x).
+ Inductive silly := SILLY (v : Number.uint) (f : forall A, A -> A).
+ Definition to_silly (v : Number.uint) := SILLY v (fun _ x => x).
Definition of_silly (v : silly) := match v with SILLY v _ => v end.
Number Notation silly to_silly of_silly : silly_scope.
Delimit Scope silly_scope with silly.
@@ -45,15 +45,15 @@ Module Test4.
Declare Scope upp.
Declare Scope ppps.
Polymorphic NonCumulative Inductive punit := ptt.
- Polymorphic Definition pto_punit (v : Numeral.uint) : option punit := match Nat.of_num_uint v with O => Some ptt | _ => None end.
- Polymorphic Definition pto_punit_all (v : Numeral.uint) : punit := ptt.
- Polymorphic Definition pof_punit (v : punit) : Numeral.uint := Nat.to_num_uint 0.
- Definition to_punit (v : Numeral.uint) : option punit := match Nat.of_num_uint v with O => Some ptt | _ => None end.
- Definition of_punit (v : punit) : Numeral.uint := Nat.to_num_uint 0.
- Polymorphic Definition pto_unit (v : Numeral.uint) : option unit := match Nat.of_num_uint v with O => Some tt | _ => None end.
- Polymorphic Definition pof_unit (v : unit) : Numeral.uint := Nat.to_num_uint 0.
- Definition to_unit (v : Numeral.uint) : option unit := match Nat.of_num_uint v with O => Some tt | _ => None end.
- Definition of_unit (v : unit) : Numeral.uint := Nat.to_num_uint 0.
+ Polymorphic Definition pto_punit (v : Number.uint) : option punit := match Nat.of_num_uint v with O => Some ptt | _ => None end.
+ Polymorphic Definition pto_punit_all (v : Number.uint) : punit := ptt.
+ Polymorphic Definition pof_punit (v : punit) : Number.uint := Nat.to_num_uint 0.
+ Definition to_punit (v : Number.uint) : option punit := match Nat.of_num_uint v with O => Some ptt | _ => None end.
+ Definition of_punit (v : punit) : Number.uint := Nat.to_num_uint 0.
+ Polymorphic Definition pto_unit (v : Number.uint) : option unit := match Nat.of_num_uint v with O => Some tt | _ => None end.
+ Polymorphic Definition pof_unit (v : unit) : Number.uint := Nat.to_num_uint 0.
+ Definition to_unit (v : Number.uint) : option unit := match Nat.of_num_uint v with O => Some tt | _ => None end.
+ Definition of_unit (v : unit) : Number.uint := Nat.to_num_uint 0.
Number Notation punit to_punit of_punit : pto.
Number Notation punit pto_punit of_punit : ppo.
Number Notation punit to_punit pof_punit : ptp.
@@ -83,7 +83,7 @@ Module Test4.
Polymorphic Definition pto_punits := pto_punit_all@{Set}.
Polymorphic Definition pof_punits := pof_punit@{Set}.
- Number Notation punit pto_punits pof_punits : ppps (abstract after 1).
+ Number Notation punit pto_punits pof_punits (abstract after 1) : ppps.
Delimit Scope ppps with ppps.
Universe u.
Constraint Set < u.
@@ -96,7 +96,7 @@ Module Test5.
End Test5.
Module Test6.
- (* Check that numeral notations on enormous terms don't take forever to print/parse *)
+ (* Check that number notations on enormous terms don't take forever to print/parse *)
(* Ackerman definition from https://stackoverflow.com/a/10303475/377022 *)
Fixpoint ack (n m : nat) : nat :=
match n with
@@ -113,15 +113,15 @@ Module Test6.
Local Set Primitive Projections.
Record > wnat := wrap { unwrap :> nat }.
- Definition to_uint (x : wnat) : Numeral.uint := Nat.to_num_uint x.
- Definition of_uint (x : Numeral.uint) : wnat := Nat.of_num_uint x.
+ Definition to_uint (x : wnat) : Number.uint := Nat.to_num_uint x.
+ Definition of_uint (x : Number.uint) : wnat := Nat.of_num_uint x.
Module Export Scopes.
Declare Scope wnat_scope.
Delimit Scope wnat_scope with wnat.
End Scopes.
Module Export Notations.
Export Scopes.
- Number Notation wnat of_uint to_uint : wnat_scope (abstract after 5000).
+ Number Notation wnat of_uint to_uint (abstract after 5000) : wnat_scope.
End Notations.
Set Printing Coercions.
Check let v := 0%wnat in v : wnat.
@@ -138,7 +138,7 @@ End Test6_2.
Module Test7.
Local Set Primitive Projections.
- Record wuint := wrap { unwrap : Numeral.uint }.
+ Record wuint := wrap { unwrap : Number.uint }.
Declare Scope wuint_scope.
Delimit Scope wuint_scope with wuint.
Number Notation wuint wrap unwrap : wuint_scope.
@@ -148,7 +148,7 @@ End Test7.
Module Test8.
Local Set Primitive Projections.
- Record wuint := wrap { unwrap : Numeral.uint }.
+ Record wuint := wrap { unwrap : Number.uint }.
Declare Scope wuint8_scope.
Declare Scope wuint8'_scope.
Delimit Scope wuint8_scope with wuint8.
@@ -177,7 +177,7 @@ Module Test9.
Delimit Scope wuint9'_scope with wuint9'.
Section with_let.
Local Set Primitive Projections.
- Record wuint := wrap { unwrap : Numeral.uint }.
+ Record wuint := wrap { unwrap : Number.uint }.
Let wrap' := wrap.
Let unwrap' := unwrap.
Local Notation wrap'' := wrap.
@@ -194,26 +194,26 @@ End Test9.
Module Test10.
(* Test that it is only a warning to add abstract after to an optional parsing function *)
Definition to_uint (v : unit) := Nat.to_num_uint 0.
- Definition of_uint (v : Numeral.uint) := match Nat.of_num_uint v with O => Some tt | _ => None end.
- Definition of_any_uint (v : Numeral.uint) := tt.
+ Definition of_uint (v : Number.uint) := match Nat.of_num_uint v with O => Some tt | _ => None end.
+ Definition of_any_uint (v : Number.uint) := tt.
Declare Scope unit_scope.
Declare Scope unit2_scope.
Delimit Scope unit_scope with unit.
Delimit Scope unit2_scope with unit2.
- Number Notation unit of_uint to_uint : unit_scope (abstract after 1).
+ Number Notation unit of_uint to_uint (abstract after 1) : unit_scope.
Local Set Warnings Append "+abstract-large-number-no-op".
(* Check that there is actually a warning here *)
- Fail Number Notation unit of_uint to_uint : unit2_scope (abstract after 1).
+ Fail Number Notation unit of_uint to_uint (abstract after 1) : unit2_scope.
(* Check that there is no warning here *)
- Number Notation unit of_any_uint to_uint : unit2_scope (abstract after 1).
+ Number Notation unit of_any_uint to_uint (abstract after 1) : unit2_scope.
End Test10.
Module Test12.
- (* Test for numeral notations on context variables *)
+ (* Test for number notations on context variables *)
Declare Scope test12_scope.
Delimit Scope test12_scope with test12.
Section test12.
- Context (to_uint : unit -> Numeral.uint) (of_uint : Numeral.uint -> unit).
+ Context (to_uint : unit -> Number.uint) (of_uint : Number.uint -> unit).
Number Notation unit of_uint to_uint : test12_scope.
Check let v := 1%test12 in v : unit.
@@ -221,15 +221,15 @@ Module Test12.
End Test12.
Module Test13.
- (* Test for numeral notations on notations which do not denote references *)
+ (* Test for number notations on notations which do not denote references *)
Declare Scope test13_scope.
Declare Scope test13'_scope.
Declare Scope test13''_scope.
Delimit Scope test13_scope with test13.
Delimit Scope test13'_scope with test13'.
Delimit Scope test13''_scope with test13''.
- Definition to_uint (x y : unit) : Numeral.uint := Nat.to_num_uint O.
- Definition of_uint (x : Numeral.uint) : unit := tt.
+ Definition to_uint (x y : unit) : Number.uint := Nat.to_num_uint O.
+ Definition of_uint (x : Number.uint) : unit := tt.
Definition to_uint_good := to_uint tt.
Notation to_uint' := (to_uint tt).
Notation to_uint'' := (to_uint _).
@@ -242,7 +242,7 @@ Module Test13.
End Test13.
Module Test14.
- (* Test that numeral notations follow [Import], not [Require], and
+ (* Test that number notations follow [Import], not [Require], and
also test that [Local Number Notation]s do not escape modules
nor sections. *)
Declare Scope test14_scope.
@@ -254,8 +254,8 @@ Module Test14.
Delimit Scope test14''_scope with test14''.
Delimit Scope test14'''_scope with test14'''.
Module Inner.
- Definition to_uint (x : unit) : Numeral.uint := Nat.to_num_uint O.
- Definition of_uint (x : Numeral.uint) : unit := tt.
+ Definition to_uint (x : unit) : Number.uint := Nat.to_num_uint O.
+ Definition of_uint (x : Number.uint) : unit := tt.
Local Number Notation unit of_uint to_uint : test14_scope.
Global Number Notation unit of_uint to_uint : test14'_scope.
Check let v := 0%test14 in v : unit.
@@ -267,8 +267,8 @@ Module Test14.
Fail Check let v := 0%test14 in v : unit.
Check let v := 0%test14' in v : unit.
Section InnerSection.
- Definition to_uint (x : unit) : Numeral.uint := Nat.to_num_uint O.
- Definition of_uint (x : Numeral.uint) : unit := tt.
+ Definition to_uint (x : unit) : Number.uint := Nat.to_num_uint O.
+ Definition of_uint (x : Number.uint) : unit := tt.
Local Number Notation unit of_uint to_uint : test14''_scope.
Fail Global Number Notation unit of_uint to_uint : test14'''_scope.
Check let v := 0%test14'' in v : unit.
@@ -283,8 +283,8 @@ Module Test15.
Declare Scope test15_scope.
Delimit Scope test15_scope with test15.
Module Inner.
- Definition to_uint (x : unit) : Numeral.uint := Nat.to_num_uint O.
- Definition of_uint (x : Numeral.uint) : unit := tt.
+ Definition to_uint (x : unit) : Number.uint := Nat.to_num_uint O.
+ Definition of_uint (x : Number.uint) : unit := tt.
Number Notation unit of_uint to_uint : test15_scope.
Check let v := 0%test15 in v : unit.
End Inner.
@@ -306,8 +306,8 @@ Module Test16.
End A.
Module F (a : A).
Inductive Foo := foo (_ : a.T).
- Definition to_uint (x : Foo) : Numeral.uint := Nat.to_num_uint O.
- Definition of_uint (x : Numeral.uint) : Foo := foo a.t.
+ Definition to_uint (x : Foo) : Number.uint := Nat.to_num_uint O.
+ Definition of_uint (x : Number.uint) : Foo := foo a.t.
Global Number Notation Foo of_uint to_uint : test16_scope.
Check let v := 0%test16 in v : Foo.
End F.
@@ -352,8 +352,8 @@ Module Test18.
Definition Q_of_nat (x : nat) : Q := {| num := x ; den := 1 ; reduced := transparentify (nat_eq_dec _ _) (gcd_good _) |}.
Definition nat_of_Q (x : Q) : option nat
:= if Nat.eqb x.(den) 1 then Some (x.(num)) else None.
- Definition Q_of_uint (x : Numeral.uint) : Q := Q_of_nat (Nat.of_num_uint x).
- Definition uint_of_Q (x : Q) : option Numeral.uint
+ Definition Q_of_uint (x : Number.uint) : Q := Q_of_nat (Nat.of_num_uint x).
+ Definition uint_of_Q (x : Q) : option Number.uint
:= option_map Nat.to_num_uint (nat_of_Q x).
Number Notation Q Q_of_uint uint_of_Q : Q_scope.
@@ -411,7 +411,7 @@ Module Test20.
Record > ty := { t : Type ; kt : known_type t }.
- Definition ty_of_uint (x : Numeral.uint) : option ty
+ Definition ty_of_uint (x : Number.uint) : option ty
:= match Nat.of_num_uint x with
| 0 => @Some ty zero
| 1 => @Some ty one
@@ -421,7 +421,7 @@ Module Test20.
| 5 => @Some ty type
| _ => None
end.
- Definition uint_of_ty (x : ty) : Numeral.uint
+ Definition uint_of_ty (x : ty) : Number.uint
:= Nat.to_num_uint match kt x with
| prop => 3
| set => 4
@@ -487,3 +487,488 @@ Check (-0)%Z.
*)
End Test22.
+
+(* Test the via ... mapping ... option *)
+Module Test23.
+
+Inductive sum (A : Set) (B : Set) : Set := pair : A -> B -> sum A B.
+
+Inductive I :=
+| Iempty : I
+| Iunit : I
+| Isum : I -> I -> I.
+
+Definition of_uint (x : Number.uint) : I :=
+ let fix f n :=
+ match n with
+ | O => Iempty
+ | S O => Iunit
+ | S n => Isum Iunit (f n)
+ end in
+ f (Nat.of_num_uint x).
+
+Definition to_uint (x : I) : Number.uint :=
+ let fix f i :=
+ match i with
+ | Iempty => O
+ | Iunit => 1
+ | Isum i1 i2 => f i1 + f i2
+ end in
+ Nat.to_num_uint (f x).
+
+Notation nSet := (Set) (only parsing). (* needed as a reference is expected in Number Notation and Set is syntactically not a reference *)
+Number Notation nSet of_uint to_uint (via I
+ mapping [Empty_set => Iempty, unit => Iunit, sum => Isum])
+ : type_scope.
+
+Local Open Scope type_scope.
+
+Check Empty_set.
+Check unit.
+Check sum unit unit.
+Check sum unit (sum unit unit).
+Set Printing All.
+Check 0.
+Check 1.
+Check 2.
+Check 3.
+Unset Printing All.
+
+(* Test error messages *)
+
+(* missing constructor *)
+Fail Number Notation nSet of_uint to_uint (via I
+ mapping [Empty_set => Iempty, unit => Iunit])
+ : type_scope.
+
+(* duplicate constructor *)
+Fail Number Notation nSet of_uint to_uint (via I
+ mapping [Empty_set => Iempty, unit => Iunit, sum => Isum, unit => Iunit])
+ : type_scope.
+
+(* not an inductive *)
+Fail Number Notation nSet of_uint to_uint (via add
+ mapping [Empty_set => Iempty, unit => Iunit, sum => Isum])
+ : type_scope.
+
+(* not a constructor *)
+Fail Number Notation nSet of_uint to_uint (via I
+ mapping [Empty_set => Iempty, unit => add, sum => Isum])
+ : type_scope.
+
+(* put constructors of the wrong inductive ~~> missing constructors *)
+Fail Number Notation nSet of_uint to_uint (via I
+ mapping [Empty_set => O, unit => S])
+ : type_scope.
+
+(* Test warnings *)
+
+(* wrong type *)
+Inductive I' :=
+| I'empty : I'
+| I'unit : I'
+| I'sum : I -> I' -> I'.
+Definition of_uint' (x : Number.uint) : I' := I'empty.
+Definition to_uint' (x : I') : Number.uint := Number.UIntDecimal Decimal.Nil.
+Number Notation nSet of_uint' to_uint' (via I'
+ mapping [Empty_set => I'empty, unit => I'unit, sum => I'sum])
+ : type_scope.
+
+(* wrong type mapping *)
+Number Notation nSet of_uint to_uint (via I
+ mapping [Empty_set => Iempty, O => Iunit, sum => Isum])
+ : type_scope.
+
+(* incompatibility with abstract (but warning is fine) *)
+Fail Number Notation nSet of_uint to_uint (via I
+ mapping [Empty_set => Iempty, unit => Iunit, sum => Isum],
+ abstract after 12)
+ : type_scope.
+Number Notation nSet of_uint to_uint (via I
+ mapping [Empty_set => Iempty, unit => Iunit, sum => Isum],
+ warning after 12)
+ : type_scope.
+
+(* Test reduction of types when building the notation *)
+
+Inductive foo := bar : match (true <: bool) with true => nat -> foo | false => True end.
+
+Definition foo_of_uint (x : Number.uint) : foo := bar (Nat.of_num_uint x).
+Definition foo_to_uint (x : foo) : Number.uint :=
+ match x with
+ | bar x => Nat.to_num_uint x
+ end.
+
+Number Notation foo foo_of_uint foo_to_uint (via foo mapping [bar => bar])
+ : type_scope.
+
+Inductive foo' := bar' : let n := nat in n -> foo'.
+
+Definition foo'_of_uint (x : Number.uint) : foo' := bar' (Nat.of_num_uint x).
+Definition foo'_to_uint (x : foo') : Number.uint :=
+ match x with
+ | bar' x => Nat.to_num_uint x
+ end.
+
+Number Notation foo' foo'_of_uint foo'_to_uint (via foo' mapping [bar' => bar'])
+ : type_scope.
+
+Inductive foo'' := bar'' : (nat <: Type) -> (foo'' <: Type).
+
+Definition foo''_of_uint (x : Number.uint) : foo'' := bar'' (Nat.of_num_uint x).
+Definition foo''_to_uint (x : foo'') : Number.uint :=
+ match x with
+ | bar'' x => Nat.to_num_uint x
+ end.
+
+Number Notation foo'' foo''_of_uint foo''_to_uint (via foo'' mapping [bar'' => bar''])
+ : type_scope.
+
+End Test23.
+
+(* Test the via ... mapping ... option with implicit arguments *)
+Require Vector.
+Module Test24.
+
+Import Vector.
+
+Inductive I :=
+| I1 : I
+| IS : I -> I.
+
+Definition of_uint (x : Number.uint) : I :=
+ let fix f n :=
+ match n with
+ | O => I1
+ | S n => IS (f n)
+ end in
+ f (Nat.of_num_uint x).
+
+Definition to_uint (x : I) : Number.uint :=
+ let fix f i :=
+ match i with
+ | I1 => O
+ | IS n => S (f n)
+ end in
+ Nat.to_num_uint (f x).
+
+Local Open Scope type_scope.
+
+(* ignoring implicit arguments doesn't work *)
+Number Notation Fin.t of_uint to_uint (via I
+ mapping [Fin.F1 => I1, Fin.FS => IS])
+ : type_scope.
+
+Fail Check 1.
+
+Number Notation Fin.t of_uint to_uint (via I
+ mapping [[Fin.F1] => I1, [Fin.FS] => IS])
+ : type_scope.
+
+Check Fin.F1.
+Check Fin.FS Fin.F1.
+Check Fin.FS (Fin.FS Fin.F1).
+Check Fin.FS (Fin.FS (Fin.FS Fin.F1)).
+Check Fin.F1 : Fin.t 3.
+Check Fin.FS Fin.F1 : Fin.t 3.
+Check Fin.FS (Fin.FS Fin.F1) : Fin.t 3.
+Fail Check Fin.FS (Fin.FS (Fin.FS Fin.F1)) : Fin.t 3.
+Set Printing All.
+Check 0.
+Check 1.
+Check 2.
+Check 3.
+Check 0 : Fin.t 3.
+Check 1 : Fin.t 3.
+Check 2 : Fin.t 3.
+Fail Check 3 : Fin.t 3.
+Unset Printing All.
+
+End Test24.
+
+(* Test number notations for parameterized inductives *)
+Module Test25.
+
+Definition of_uint (u : Number.uint) : list unit :=
+ let fix f n :=
+ match n with
+ | O => nil
+ | S n => cons tt (f n)
+ end in
+ f (Nat.of_num_uint u).
+
+Definition to_uint (l : list unit) : Number.uint :=
+ let fix f n :=
+ match n with
+ | nil => O
+ | cons tt l => S (f l)
+ end in
+ Nat.to_num_uint (f l).
+
+Notation listunit := (list unit) (only parsing).
+Number Notation listunit of_uint to_uint : nat_scope.
+
+Check 0.
+Check 1.
+Check 2.
+
+Check cons tt (cons tt nil).
+Check cons O (cons O nil). (* printer not called on list nat *)
+
+(* inductive with multiple parameters that are not the first
+ parameters and not in the same order for each constructor *)
+Inductive Ip : Type -> Type -> Type :=
+| Ip0 : forall T T', nat -> Ip T T'
+| Ip1 : forall T' T, nat -> Ip T T'
+| Ip2 : forall T, nat -> forall T', Ip T T'
+| Ip3 : nat -> forall T T', Ip T T'.
+
+Definition Ip_of_uint (u : Number.uint) : option (Ip nat bool) :=
+ let f n :=
+ match n with
+ | O => Some (Ip0 nat bool O)
+ | S O => Some (Ip1 bool nat (S O))
+ | S (S O) => Some (Ip2 nat (S (S O)) bool)
+ | S (S (S O)) => Some (Ip3 (S (S (S O))) nat bool)
+ | _ => None
+ end in
+ f (Nat.of_num_uint u).
+
+Definition Ip_to_uint (l : Ip nat bool) : Number.uint :=
+ let f n :=
+ match n with
+ | Ip0 _ _ n => n
+ | Ip1 _ _ n => n
+ | Ip2 _ n _ => n
+ | Ip3 n _ _ => n
+ end in
+ Nat.to_num_uint (f l).
+
+Notation Ip_nat_bool := (Ip nat bool) (only parsing).
+Number Notation Ip_nat_bool Ip_of_uint Ip_to_uint : nat_scope.
+
+Check 0.
+Check 1.
+Check 2.
+Check 3.
+Check Ip0 nat bool (S O).
+Check Ip1 bool nat (S O).
+Check Ip2 nat (S O) bool.
+Check Ip3 (S O) nat bool.
+Check Ip0 nat nat (S O). (* not printed *)
+Check Ip0 bool bool (S O). (* not printed *)
+Check Ip1 nat nat (S O). (* not printed *)
+Check Ip3 (S O) nat nat. (* not printed *)
+Set Printing All.
+Check 0.
+Check 1.
+Check 2.
+Check 3.
+Unset Printing All.
+
+Notation eqO := (eq _ O) (only parsing).
+Definition eqO_of_uint (x : Number.uint) : eqO := eq_refl O.
+Definition eqO_to_uint (x : O = O) : Number.uint :=
+ match x with
+ | eq_refl _ => Nat.to_num_uint O
+ end.
+Number Notation eqO eqO_of_uint eqO_to_uint : nat_scope.
+
+Check 42.
+Check eq_refl (S O). (* doesn't match eq _ O, printer not called *)
+
+Notation eq_ := (eq _ _) (only parsing).
+Number Notation eq_ eqO_of_uint eqO_to_uint : nat_scope.
+
+Check eq_refl (S O). (* matches eq _ _, printer called *)
+
+Inductive extra_list : Type -> Type :=
+| nil (n : nat) (v : Type) : extra_list v
+| cons (n : nat) (t : Type) (x : t) : extra_list t -> extra_list t.
+
+Definition extra_list_unit_of_uint (x : Number.uint) : extra_list unit :=
+ let fix f n :=
+ match n with
+ | O => nil O unit
+ | S n => cons O unit tt (f n)
+ end in
+ f (Nat.of_num_uint x).
+
+Definition extra_list_unit_to_uint (x : extra_list unit) : Number.uint :=
+ let fix f T (x : extra_list T) :=
+ match x with
+ | nil _ _ => O
+ | cons _ T _ x => S (f T x)
+ end in
+ Nat.to_num_uint (f unit x).
+
+Notation extra_list_unit := (extra_list unit).
+Number Notation extra_list_unit
+ extra_list_unit_of_uint extra_list_unit_to_uint : nat_scope.
+
+Check 2.
+Set Printing All.
+Check 2.
+Unset Printing All.
+
+End Test25.
+
+(* Test the via ... mapping ... option with let-binders, beta-redexes, delta-redexes, etc *)
+Module Test26.
+
+Inductive sum (A : Set) (B : Set) : Set := pair : A -> B -> sum A B.
+
+Inductive I (dummy:=O) :=
+| Iempty : let v := I in id v
+| Iunit : (fun x => x) I
+| Isum : let v := I in (fun A B => A -> B) (let v' := v in v') (forall x : match O with O => I | _ => Empty_set end, let dummy2 := x in I).
+
+Definition of_uint (x : (fun x => let v := I in x) Number.uint) : (fun x => let v := I in x) I :=
+ let fix f n :=
+ match n with
+ | O => Iempty
+ | S O => Iunit
+ | S n => Isum Iunit (f n)
+ end in
+ f (Nat.of_num_uint x).
+
+Definition to_uint (x : (fun x => let v := x in v) I) : match O with O => Number.uint | _ => Empty_set end :=
+ let fix f i :=
+ match i with
+ | Iempty => O
+ | Iunit => 1
+ | Isum i1 i2 => f i1 + f i2
+ end in
+ Nat.to_num_uint (f x).
+
+Notation nSet := (Set) (only parsing). (* needed as a reference is expected in Number Notation and Set is syntactically not a reference *)
+Number Notation nSet of_uint to_uint (via I
+ mapping [Empty_set => Iempty, unit => Iunit, sum => Isum])
+ : type_scope.
+
+Local Open Scope type_scope.
+
+Check Empty_set.
+Check unit.
+Check sum unit unit.
+Check sum unit (sum unit unit).
+Set Printing All.
+Check 0.
+Check 1.
+Check 2.
+Check 3.
+Unset Printing All.
+End Test26.
+
+(* Test the via ... mapping ... option with implicit arguments with let binders, etc *)
+Module Test27.
+
+Module Fin.
+Inductive t0 (x:=O) :=
+with
+ t (x:=O) : forall y : nat, let z := y in Set :=
+| F1 (y:=O) {n} : match y with O => t (S n) | _ => Empty_set end
+| FS (y:=x) {n} (v:=n+y) (m:=n) : id (match y with O => id (t n) | _ => Empty_set end -> (fun x => x) t (S m))
+with t' (x:=O) := .
+End Fin.
+
+Inductive I (dummy:=O) :=
+| I1 : I
+| IS : let x := I in id x -> I.
+
+Definition of_uint (x : Number.uint) : I :=
+ let fix f n :=
+ match n with
+ | O => I1
+ | S n => IS (f n)
+ end in
+ f (Nat.of_num_uint x).
+
+Definition to_uint (x : I) : Number.uint :=
+ let fix f i :=
+ match i with
+ | I1 => O
+ | IS n => S (f n)
+ end in
+ Nat.to_num_uint (f x).
+
+Local Open Scope type_scope.
+
+Number Notation Fin.t of_uint to_uint (via I
+ mapping [[Fin.F1] => I1, [Fin.FS] => IS])
+ : type_scope.
+
+Check Fin.F1.
+Check Fin.FS Fin.F1.
+Check Fin.FS (Fin.FS Fin.F1).
+Check Fin.FS (Fin.FS (Fin.FS Fin.F1)).
+Check Fin.F1 : Fin.t 3.
+Check Fin.FS Fin.F1 : Fin.t 3.
+Check Fin.FS (Fin.FS Fin.F1) : Fin.t 3.
+Fail Check Fin.FS (Fin.FS (Fin.FS Fin.F1)) : Fin.t 3.
+Set Printing All.
+Check 0.
+Check 1.
+Check 2.
+Check 3.
+Check 0 : Fin.t 3.
+Check 1 : Fin.t 3.
+Check 2 : Fin.t 3.
+Fail Check 3 : Fin.t 3.
+Unset Printing All.
+
+End Test27.
+
+Module Test28.
+Module Fin.
+Inductive t : nat -> Set :=
+| F1 {n : (nat : Set)} : (t (S n) : Set)
+| FS {n : (nat : Set)} : (t n : Set) -> (t (S n) : Set).
+End Fin.
+
+Inductive I :=
+| I1 : I
+| IS : I -> I.
+
+Definition of_uint (x : Number.uint) : I :=
+ let fix f n :=
+ match n with
+ | O => I1
+ | S n => IS (f n)
+ end in
+ f (Nat.of_num_uint x).
+
+Definition to_uint (x : I) : Number.uint :=
+ let fix f i :=
+ match i with
+ | I1 => O
+ | IS n => S (f n)
+ end in
+ Nat.to_num_uint (f x).
+
+Local Open Scope type_scope.
+
+Number Notation Fin.t of_uint to_uint (via I
+ mapping [[Fin.F1] => I1, [Fin.FS] => IS])
+ : type_scope.
+
+Check Fin.F1.
+Check Fin.FS Fin.F1.
+Check Fin.FS (Fin.FS Fin.F1).
+Check Fin.FS (Fin.FS (Fin.FS Fin.F1)).
+Check Fin.F1 : Fin.t 3.
+Check Fin.FS Fin.F1 : Fin.t 3.
+Check Fin.FS (Fin.FS Fin.F1) : Fin.t 3.
+Fail Check Fin.FS (Fin.FS (Fin.FS Fin.F1)) : Fin.t 3.
+Set Printing All.
+Check 0.
+Check 1.
+Check 2.
+Check 3.
+Check 0 : Fin.t 3.
+Check 1 : Fin.t 3.
+Check 2 : Fin.t 3.
+Fail Check 3 : Fin.t 3.
+Unset Printing All.
+
+End Test28.
diff --git a/test-suite/output/QArithSyntax.out b/test-suite/output/QArithSyntax.out
index 9b5c076cb4..ced52524f2 100644
--- a/test-suite/output/QArithSyntax.out
+++ b/test-suite/output/QArithSyntax.out
@@ -1,26 +1,72 @@
eq_refl : 1.02 = 1.02
: 1.02 = 1.02
-eq_refl : 10.2 = 10.2
- : 10.2 = 10.2
-eq_refl : 1020 = 1020
- : 1020 = 1020
-eq_refl : 102 = 102
- : 102 = 102
-eq_refl : 1.02 = 1.02
- : 1.02 = 1.02
-eq_refl : -1e-4 = -1e-4
- : -1e-4 = -1e-4
+1.02e1
+ : Q
+10.2
+ : Q
+1.02e3
+ : Q
+1020
+ : Q
+1.02e2
+ : Q
+102
+ : Q
+eq_refl : 10.2e-1 = 1.02
+ : 10.2e-1 = 1.02
+eq_refl : -0.0001 = -0.0001
+ : -0.0001 = -0.0001
eq_refl : -0.50 = -0.50
: -0.50 = -0.50
-eq_refl : -26 = -26
- : -26 = -26
-eq_refl : 2860 # 256 = 2860 # 256
- : 2860 # 256 = 2860 # 256
-eq_refl : -6882 = -6882
- : -6882 = -6882
-eq_refl : 2860 # 64 = 2860 # 64
- : 2860 # 64 = 2860 # 64
-eq_refl : 2860 = 2860
- : 2860 = 2860
-eq_refl : -2860 # 1024 = -2860 # 1024
- : -2860 # 1024 = -2860 # 1024
+0
+ : Q
+0
+ : Q
+42
+ : Q
+42
+ : Q
+1.23
+ : Q
+0x1.23%xQ
+ : Q
+0.0012
+ : Q
+42e3
+ : Q
+42e-3
+ : Q
+eq_refl : -0x1a = -0x1a
+ : -0x1a = -0x1a
+eq_refl : 0xb.2c = 0xb.2c
+ : 0xb.2c = 0xb.2c
+eq_refl : -0x1ae2 = -0x1ae2
+ : -0x1ae2 = -0x1ae2
+0xb.2cp2
+ : Q
+2860 # 64
+ : Q
+0xb.2cp8
+ : Q
+0xb2c
+ : Q
+eq_refl : -0xb.2cp-2 = -2860 # 1024
+ : -0xb.2cp-2 = -2860 # 1024
+0x0
+ : Q
+0x0
+ : Q
+0x2a
+ : Q
+0x2a
+ : Q
+1.23%Q
+ : Q
+0x1.23
+ : Q
+0x0.0012
+ : Q
+0x2ap3
+ : Q
+0x2ap-3
+ : Q
diff --git a/test-suite/output/QArithSyntax.v b/test-suite/output/QArithSyntax.v
index b5c6222bba..e979abca66 100644
--- a/test-suite/output/QArithSyntax.v
+++ b/test-suite/output/QArithSyntax.v
@@ -1,15 +1,39 @@
Require Import QArith.
Open Scope Q_scope.
Check (eq_refl : 1.02 = 102 # 100).
-Check (eq_refl : 1.02e1 = 102 # 10).
-Check (eq_refl : 1.02e+03 = 1020).
-Check (eq_refl : 1.02e+02 = 102 # 1).
+Check 1.02e1.
+Check 102 # 10.
+Check 1.02e+03.
+Check 1020.
+Check 1.02e+02.
+Check 102 # 1.
Check (eq_refl : 10.2e-1 = 1.02).
Check (eq_refl : -0.0001 = -1 # 10000).
Check (eq_refl : -0.50 = - 50 # 100).
+Check 0.
+Check 000.
+Check 42.
+Check 0x2a.
+Check 1.23.
+Check 0x1.23.
+Check 0.0012.
+Check 42e3.
+Check 42e-3.
+Open Scope hex_Q_scope.
Check (eq_refl : -0x1a = - 26 # 1).
Check (eq_refl : 0xb.2c = 2860 # 256).
Check (eq_refl : -0x1ae2 = -6882).
-Check (eq_refl : 0xb.2cp2 = 2860 # 64).
-Check (eq_refl : 0xb.2cp8 = 2860).
+Check 0xb.2cp2.
+Check 2860 # 64.
+Check 0xb.2cp8.
+Check 2860.
Check (eq_refl : -0xb.2cp-2 = -2860 # 1024).
+Check 0x0.
+Check 0x00.
+Check 42.
+Check 0x2a.
+Check 1.23.
+Check 0x1.23.
+Check 0x0.0012.
+Check 0x2ap3.
+Check 0x2ap-3.
diff --git a/test-suite/output/RealSyntax.out b/test-suite/output/RealSyntax.out
index a9386b2781..a7b7dabb20 100644
--- a/test-suite/output/RealSyntax.out
+++ b/test-suite/output/RealSyntax.out
@@ -4,34 +4,81 @@
: R
1.5%R
: R
-15%R
- : R
-eq_refl : 1.02 = 1.02
- : 1.02 = 1.02
-eq_refl : 10.2 = 10.2
- : 10.2 = 10.2
-eq_refl : 102e1 = 102e1
- : 102e1 = 102e1
-eq_refl : 102 = 102
- : 102 = 102
-eq_refl : 1.02 = 1.02
- : 1.02 = 1.02
-eq_refl : -1e-4 = -1e-4
- : -1e-4 = -1e-4
-eq_refl : -0.50 = -0.50
- : -0.50 = -0.50
+1.5e1%R
+ : R
+eq_refl : 1.02 = 102e-2
+ : 1.02 = 102e-2
+1.02e1
+ : R
+102e-1
+ : R
+1.02e3
+ : R
+102e1
+ : R
+1.02e2
+ : R
+102
+ : R
+10.2e-1
+ : R
+1.02
+ : R
+eq_refl : -0.0001 = -1e-4
+ : -0.0001 = -1e-4
+eq_refl : -0.50 = -50e-2
+ : -0.50 = -50e-2
eq_refl : -26 = -26
: -26 = -26
-eq_refl : 2860 / IZR (BinIntDef.Z.pow_pos 2 8) = 2860 / IZR (Z.pow_pos 2 8)
- : 2860 / IZR (BinIntDef.Z.pow_pos 2 8) = 2860 / IZR (Z.pow_pos 2 8)
+eq_refl : 0xb.2c%xR = 0xb2cp-8%xR
+ : 0xb.2c%xR = 0xb2cp-8%xR
eq_refl : -6882 = -6882
: -6882 = -6882
-eq_refl : 2860 / IZR (BinIntDef.Z.pow_pos 2 6) = 2860 / IZR (Z.pow_pos 2 6)
- : 2860 / IZR (BinIntDef.Z.pow_pos 2 6) = 2860 / IZR (Z.pow_pos 2 6)
-eq_refl : 2860 = 2860
- : 2860 = 2860
-eq_refl
-:
--2860 / IZR (BinIntDef.Z.pow_pos 2 10) = - (2860) / IZR (Z.pow_pos 2 10)
- : -2860 / IZR (BinIntDef.Z.pow_pos 2 10) =
- - (2860) / IZR (Z.pow_pos 2 10)
+0xb.2cp2%xR
+ : R
+0xb2cp-6%xR
+ : R
+0xb.2cp8%xR
+ : R
+2860
+ : R
+(-0xb.2cp-2)%xR
+ : R
+- 0xb2cp-10%xR
+ : R
+0
+ : R
+0
+ : R
+42
+ : R
+42
+ : R
+1.23
+ : R
+0x1.23%xR
+ : R
+0.0012
+ : R
+42e3
+ : R
+42e-3
+ : R
+0x0
+ : R
+0x0
+ : R
+0x2a
+ : R
+0x2a
+ : R
+1.23%R
+ : R
+0x1.23
+ : R
+0x0.0012
+ : R
+0x2ap3
+ : R
+0x2ap-3
+ : R
diff --git a/test-suite/output/RealSyntax.v b/test-suite/output/RealSyntax.v
index 69ce3ef5f9..790d5c654f 100644
--- a/test-suite/output/RealSyntax.v
+++ b/test-suite/output/RealSyntax.v
@@ -8,18 +8,48 @@ Check 1_.5_e1_%R.
Open Scope R_scope.
Check (eq_refl : 1.02 = IZR 102 / IZR (Z.pow_pos 10 2)).
-Check (eq_refl : 1.02e1 = IZR 102 / IZR (Z.pow_pos 10 1)).
-Check (eq_refl : 1.02e+03 = IZR 102 * IZR (Z.pow_pos 10 1)).
-Check (eq_refl : 1.02e+02 = IZR 102).
-Check (eq_refl : 10.2e-1 = 1.02).
+Check 1.02e1.
+Check IZR 102 / IZR (Z.pow_pos 10 1).
+Check 1.02e+03.
+Check IZR 102 * IZR (Z.pow_pos 10 1).
+Check 1.02e+02.
+Check IZR 102.
+Check 10.2e-1.
+Check 1.02.
Check (eq_refl : -0.0001 = IZR (-1) / IZR (Z.pow_pos 10 4)).
Check (eq_refl : -0.50 = IZR (-50) / IZR (Z.pow_pos 10 2)).
Check (eq_refl : -0x1a = - 26).
Check (eq_refl : 0xb.2c = IZR 2860 / IZR (Z.pow_pos 2 8)).
Check (eq_refl : -0x1ae2 = -6882).
-Check (eq_refl : 0xb.2cp2 = IZR 2860 / IZR (Z.pow_pos 2 6)).
-Check (eq_refl : 0xb.2cp8 = 2860).
-Check (eq_refl : -0xb.2cp-2 = - IZR 2860 / IZR (Z.pow_pos 2 10)).
+Check 0xb.2cp2.
+Check IZR 2860 / IZR (Z.pow_pos 2 6).
+Check 0xb.2cp8.
+Check 2860.
+Check -0xb.2cp-2.
+Check - (IZR 2860 / IZR (Z.pow_pos 2 10)).
+Check 0.
+Check 000.
+Check 42.
+Check 0x2a.
+Check 1.23.
+Check 0x1.23.
+Check 0.0012.
+Check 42e3.
+Check 42e-3.
+
+Open Scope hex_R_scope.
+
+Check 0x0.
+Check 0x000.
+Check 42.
+Check 0x2a.
+Check 1.23.
+Check 0x1.23.
+Check 0x0.0012.
+Check 0x2ap3.
+Check 0x2ap-3.
+
+Close Scope hex_R_scope.
Require Import Reals.
diff --git a/test-suite/output/Record.out b/test-suite/output/Record.out
index d45343fe60..7de1e7d559 100644
--- a/test-suite/output/Record.out
+++ b/test-suite/output/Record.out
@@ -30,3 +30,43 @@ fun '{| U := T; a := a; q := p |} => (T, p, a)
: M -> Type * True * nat
fun '{| U := T; a := a; q := p |} => (T, p, a)
: M -> Type * True * nat
+{| a := 0; b := 0 |}
+ : T
+fun '{| |} => 0
+ : LongModuleName.test -> nat
+ = {|
+ a :=
+ {|
+ LongModuleName.long_field_name0 := 0;
+ LongModuleName.long_field_name1 := 1;
+ LongModuleName.long_field_name2 := 2;
+ LongModuleName.long_field_name3 := 3
+ |};
+ b :=
+ fun
+ '{|
+ LongModuleName.long_field_name0 := a;
+ LongModuleName.long_field_name1 := b;
+ LongModuleName.long_field_name2 := c;
+ LongModuleName.long_field_name3 := d
+ |} => (a, b, c, d)
+ |}
+ : T
+ = {|
+ a :=
+ {|
+ long_field_name0 := 0;
+ long_field_name1 := 1;
+ long_field_name2 := 2;
+ long_field_name3 := 3
+ |};
+ b :=
+ fun
+ '{|
+ long_field_name0 := a;
+ long_field_name1 := b;
+ long_field_name2 := c;
+ long_field_name3 := d
+ |} => (a, b, c, d)
+ |}
+ : T
diff --git a/test-suite/output/Record.v b/test-suite/output/Record.v
index 71a8afa131..13ea37b11e 100644
--- a/test-suite/output/Record.v
+++ b/test-suite/output/Record.v
@@ -33,3 +33,34 @@ Check fun x:M => let 'D T _ p := x in T.
Check fun x:M => let 'D T p := x in (T,p).
Check fun x:M => let 'D T a p := x in (T,p,a).
Check fun x:M => let '{|U:=T;a:=a;q:=p|} := x in (T,p,a).
+
+Module FormattingIssue13142.
+
+Record T {A B} := {a:A;b:B}.
+
+Module LongModuleName.
+ Record test := { long_field_name0 : nat;
+ long_field_name1 : nat;
+ long_field_name2 : nat;
+ long_field_name3 : nat }.
+End LongModuleName.
+
+Definition c :=
+ {| LongModuleName.long_field_name0 := 0;
+ LongModuleName.long_field_name1 := 1;
+ LongModuleName.long_field_name2 := 2;
+ LongModuleName.long_field_name3 := 3 |}.
+
+Definition d :=
+ fun '{| LongModuleName.long_field_name0 := a;
+ LongModuleName.long_field_name1 := b;
+ LongModuleName.long_field_name2 := c;
+ LongModuleName.long_field_name3 := d |} => (a,b,c,d).
+
+Check {|a:=0;b:=0|}.
+Check fun '{| LongModuleName.long_field_name0:=_ |} => 0.
+Eval compute in {|a:=c;b:=d|}.
+Import LongModuleName.
+Eval compute in {|a:=c;b:=d|}.
+
+End FormattingIssue13142.
diff --git a/test-suite/output/Search.out b/test-suite/output/Search.out
index 09feca71e7..ef4c6bac93 100644
--- a/test-suite/output/Search.out
+++ b/test-suite/output/Search.out
@@ -30,15 +30,15 @@ implb: bool -> bool -> bool
Nat.odd: nat -> bool
Nat.even: nat -> bool
BoolSpec: Prop -> Prop -> bool -> Prop
-Numeral.numeral_beq: Numeral.numeral -> Numeral.numeral -> bool
+Number.number_beq: Number.number -> Number.number -> bool
Nat.eqb: nat -> nat -> bool
Nat.testbit: nat -> nat -> bool
Decimal.decimal_beq: Decimal.decimal -> Decimal.decimal -> bool
-Numeral.uint_beq: Numeral.uint -> Numeral.uint -> bool
+Number.uint_beq: Number.uint -> Number.uint -> bool
Decimal.uint_beq: Decimal.uint -> Decimal.uint -> bool
Hexadecimal.hexadecimal_beq:
Hexadecimal.hexadecimal -> Hexadecimal.hexadecimal -> bool
-Numeral.int_beq: Numeral.int -> Numeral.int -> bool
+Number.int_beq: Number.int -> Number.int -> bool
Hexadecimal.uint_beq: Hexadecimal.uint -> Hexadecimal.uint -> bool
Nat.ltb: nat -> nat -> bool
Nat.leb: nat -> nat -> bool
@@ -64,34 +64,34 @@ eq_true_rec:
bool_ind: forall P : bool -> Prop, P true -> P false -> forall b : bool, P b
eq_true_sind:
forall P : bool -> SProp, P true -> forall b : bool, eq_true b -> P b
-Numeral.internal_uint_dec_bl1:
- forall x y : Numeral.uint, Numeral.uint_beq x y = true -> x = y
+Number.internal_uint_dec_bl1:
+ forall x y : Number.uint, Number.uint_beq x y = true -> x = y
Hexadecimal.internal_hexadecimal_dec_lb:
forall x y : Hexadecimal.hexadecimal,
x = y -> Hexadecimal.hexadecimal_beq x y = true
Hexadecimal.internal_int_dec_lb0:
forall x y : Hexadecimal.int, x = y -> Hexadecimal.int_beq x y = true
-Numeral.internal_numeral_dec_lb:
- forall x y : Numeral.numeral, x = y -> Numeral.numeral_beq x y = true
+Number.internal_number_dec_lb:
+ forall x y : Number.number, x = y -> Number.number_beq x y = true
Decimal.internal_decimal_dec_lb:
forall x y : Decimal.decimal, x = y -> Decimal.decimal_beq x y = true
Hexadecimal.internal_int_dec_bl0:
forall x y : Hexadecimal.int, Hexadecimal.int_beq x y = true -> x = y
-Numeral.internal_int_dec_lb1:
- forall x y : Numeral.int, x = y -> Numeral.int_beq x y = true
-Numeral.internal_int_dec_bl1:
- forall x y : Numeral.int, Numeral.int_beq x y = true -> x = y
+Number.internal_int_dec_lb1:
+ forall x y : Number.int, x = y -> Number.int_beq x y = true
+Number.internal_int_dec_bl1:
+ forall x y : Number.int, Number.int_beq x y = true -> x = y
Hexadecimal.internal_hexadecimal_dec_bl:
forall x y : Hexadecimal.hexadecimal,
Hexadecimal.hexadecimal_beq x y = true -> x = y
-Numeral.internal_uint_dec_lb1:
- forall x y : Numeral.uint, x = y -> Numeral.uint_beq x y = true
+Number.internal_uint_dec_lb1:
+ forall x y : Number.uint, x = y -> Number.uint_beq x y = true
Decimal.internal_int_dec_bl:
forall x y : Decimal.int, Decimal.int_beq x y = true -> x = y
Decimal.internal_int_dec_lb:
forall x y : Decimal.int, x = y -> Decimal.int_beq x y = true
-Numeral.internal_numeral_dec_bl:
- forall x y : Numeral.numeral, Numeral.numeral_beq x y = true -> x = y
+Number.internal_number_dec_bl:
+ forall x y : Number.number, Number.number_beq x y = true -> x = y
Byte.of_bits:
bool * (bool * (bool * (bool * (bool * (bool * (bool * bool)))))) ->
Byte.byte
@@ -160,21 +160,21 @@ f_equal2_mult:
f_equal2_nat:
forall (B : Type) (f : nat -> nat -> B) (x1 y1 x2 y2 : nat),
x1 = y1 -> x2 = y2 -> f x1 x2 = f y1 y2
-Numeral.internal_numeral_dec_lb:
- forall x y : Numeral.numeral, x = y -> Numeral.numeral_beq x y = true
-Numeral.internal_int_dec_lb1:
- forall x y : Numeral.int, x = y -> Numeral.int_beq x y = true
-Numeral.internal_numeral_dec_bl:
- forall x y : Numeral.numeral, Numeral.numeral_beq x y = true -> x = y
+Number.internal_number_dec_lb:
+ forall x y : Number.number, x = y -> Number.number_beq x y = true
+Number.internal_int_dec_lb1:
+ forall x y : Number.int, x = y -> Number.int_beq x y = true
+Number.internal_number_dec_bl:
+ forall x y : Number.number, Number.number_beq x y = true -> x = y
Hexadecimal.internal_hexadecimal_dec_lb:
forall x y : Hexadecimal.hexadecimal,
x = y -> Hexadecimal.hexadecimal_beq x y = true
-Numeral.internal_int_dec_bl1:
- forall x y : Numeral.int, Numeral.int_beq x y = true -> x = y
-Numeral.internal_uint_dec_lb1:
- forall x y : Numeral.uint, x = y -> Numeral.uint_beq x y = true
-Numeral.internal_uint_dec_bl1:
- forall x y : Numeral.uint, Numeral.uint_beq x y = true -> x = y
+Number.internal_int_dec_bl1:
+ forall x y : Number.int, Number.int_beq x y = true -> x = y
+Number.internal_uint_dec_lb1:
+ forall x y : Number.uint, x = y -> Number.uint_beq x y = true
+Number.internal_uint_dec_bl1:
+ forall x y : Number.uint, Number.uint_beq x y = true -> x = y
Decimal.internal_decimal_dec_lb:
forall x y : Decimal.decimal, x = y -> Decimal.decimal_beq x y = true
Hexadecimal.internal_hexadecimal_dec_bl:
@@ -213,18 +213,18 @@ bool_choice:
forall [S : Set] [R1 R2 : S -> Prop],
(forall x : S, {R1 x} + {R2 x}) ->
{f : S -> bool | forall x : S, f x = true /\ R1 x \/ f x = false /\ R2 x}
-Numeral.internal_numeral_dec_lb:
- forall x y : Numeral.numeral, x = y -> Numeral.numeral_beq x y = true
-Numeral.internal_numeral_dec_bl:
- forall x y : Numeral.numeral, Numeral.numeral_beq x y = true -> x = y
-Numeral.internal_int_dec_lb1:
- forall x y : Numeral.int, x = y -> Numeral.int_beq x y = true
-Numeral.internal_int_dec_bl1:
- forall x y : Numeral.int, Numeral.int_beq x y = true -> x = y
-Numeral.internal_uint_dec_lb1:
- forall x y : Numeral.uint, x = y -> Numeral.uint_beq x y = true
-Numeral.internal_uint_dec_bl1:
- forall x y : Numeral.uint, Numeral.uint_beq x y = true -> x = y
+Number.internal_number_dec_lb:
+ forall x y : Number.number, x = y -> Number.number_beq x y = true
+Number.internal_number_dec_bl:
+ forall x y : Number.number, Number.number_beq x y = true -> x = y
+Number.internal_int_dec_lb1:
+ forall x y : Number.int, x = y -> Number.int_beq x y = true
+Number.internal_int_dec_bl1:
+ forall x y : Number.int, Number.int_beq x y = true -> x = y
+Number.internal_uint_dec_lb1:
+ forall x y : Number.uint, x = y -> Number.uint_beq x y = true
+Number.internal_uint_dec_bl1:
+ forall x y : Number.uint, Number.uint_beq x y = true -> x = y
Hexadecimal.internal_hexadecimal_dec_lb:
forall x y : Hexadecimal.hexadecimal,
x = y -> Hexadecimal.hexadecimal_beq x y = true
@@ -306,12 +306,12 @@ nat_rect_plus:
(nat_rect (fun _ : nat => A) x (fun _ : nat => f) m)
(fun _ : nat => f) n
Nat.bitwise: (bool -> bool -> bool) -> nat -> nat -> nat -> nat
-Numeral.internal_numeral_dec_bl:
- forall x y : Numeral.numeral, Numeral.numeral_beq x y = true -> x = y
-Numeral.internal_int_dec_bl1:
- forall x y : Numeral.int, Numeral.int_beq x y = true -> x = y
-Numeral.internal_uint_dec_bl1:
- forall x y : Numeral.uint, Numeral.uint_beq x y = true -> x = y
+Number.internal_number_dec_bl:
+ forall x y : Number.number, Number.number_beq x y = true -> x = y
+Number.internal_int_dec_bl1:
+ forall x y : Number.int, Number.int_beq x y = true -> x = y
+Number.internal_uint_dec_bl1:
+ forall x y : Number.uint, Number.uint_beq x y = true -> x = y
Hexadecimal.internal_hexadecimal_dec_bl:
forall x y : Hexadecimal.hexadecimal,
Hexadecimal.hexadecimal_beq x y = true -> x = y
@@ -328,12 +328,12 @@ Byte.to_bits_of_bits:
forall
b : bool * (bool * (bool * (bool * (bool * (bool * (bool * bool)))))),
Byte.to_bits (Byte.of_bits b) = b
-Numeral.internal_numeral_dec_lb:
- forall x y : Numeral.numeral, x = y -> Numeral.numeral_beq x y = true
-Numeral.internal_uint_dec_lb1:
- forall x y : Numeral.uint, x = y -> Numeral.uint_beq x y = true
-Numeral.internal_int_dec_lb1:
- forall x y : Numeral.int, x = y -> Numeral.int_beq x y = true
+Number.internal_number_dec_lb:
+ forall x y : Number.number, x = y -> Number.number_beq x y = true
+Number.internal_uint_dec_lb1:
+ forall x y : Number.uint, x = y -> Number.uint_beq x y = true
+Number.internal_int_dec_lb1:
+ forall x y : Number.int, x = y -> Number.int_beq x y = true
Decimal.internal_int_dec_lb:
forall x y : Decimal.int, x = y -> Decimal.int_beq x y = true
Hexadecimal.internal_hexadecimal_dec_lb:
@@ -391,7 +391,7 @@ Nat.lor: nat -> nat -> nat
Nat.lxor: nat -> nat -> nat
Nat.of_hex_uint: Hexadecimal.uint -> nat
Nat.of_uint: Decimal.uint -> nat
-Nat.of_num_uint: Numeral.uint -> nat
+Nat.of_num_uint: Number.uint -> nat
length: forall [A : Type], list A -> nat
plus_n_O: forall n : nat, n = n + 0
plus_O_n: forall n : nat, 0 + n = n
@@ -458,3 +458,7 @@ reflexive_eq_dom_reflexive:
B.b: B.a
A.b: A.a
F.L: F.P 0
+inr: forall {A B : Type}, B -> A + B
+inl: forall {A B : Type}, A -> A + B
+(use "About" for full details on the implicit arguments of inl and inr)
+f: None = 0
diff --git a/test-suite/output/Search.v b/test-suite/output/Search.v
index a5ac2cb511..2f29e1aff1 100644
--- a/test-suite/output/Search.v
+++ b/test-suite/output/Search.v
@@ -89,3 +89,10 @@ Module Bug12647.
Search F.P.
End Bar.
End Bug12647.
+
+Module WithCoercions.
+ Search headconcl:(_ + _) inside Datatypes.
+ Coercion Some_nat := @Some nat.
+ Axiom f : None = 0.
+ Search (None = 0).
+End WithCoercions.
diff --git a/test-suite/output/SearchHead.out b/test-suite/output/SearchHead.out
index 9554581ebe..2f0d854ac6 100644
--- a/test-suite/output/SearchHead.out
+++ b/test-suite/output/SearchHead.out
@@ -21,15 +21,15 @@ orb: bool -> bool -> bool
implb: bool -> bool -> bool
Nat.odd: nat -> bool
Nat.even: nat -> bool
-Numeral.uint_beq: Numeral.uint -> Numeral.uint -> bool
+Number.uint_beq: Number.uint -> Number.uint -> bool
Nat.testbit: nat -> nat -> bool
Nat.eqb: nat -> nat -> bool
Hexadecimal.hexadecimal_beq:
Hexadecimal.hexadecimal -> Hexadecimal.hexadecimal -> bool
Nat.ltb: nat -> nat -> bool
Nat.leb: nat -> nat -> bool
-Numeral.numeral_beq: Numeral.numeral -> Numeral.numeral -> bool
-Numeral.int_beq: Numeral.int -> Numeral.int -> bool
+Number.number_beq: Number.number -> Number.number -> bool
+Number.int_beq: Number.int -> Number.int -> bool
Hexadecimal.int_beq: Hexadecimal.int -> Hexadecimal.int -> bool
Hexadecimal.uint_beq: Hexadecimal.uint -> Hexadecimal.uint -> bool
Decimal.decimal_beq: Decimal.decimal -> Decimal.decimal -> bool
diff --git a/test-suite/output/SearchPattern.out b/test-suite/output/SearchPattern.out
index 80b03e8a0b..d705ec898b 100644
--- a/test-suite/output/SearchPattern.out
+++ b/test-suite/output/SearchPattern.out
@@ -7,15 +7,15 @@ orb: bool -> bool -> bool
implb: bool -> bool -> bool
Nat.odd: nat -> bool
Nat.even: nat -> bool
-Numeral.uint_beq: Numeral.uint -> Numeral.uint -> bool
+Number.uint_beq: Number.uint -> Number.uint -> bool
Nat.testbit: nat -> nat -> bool
Nat.eqb: nat -> nat -> bool
Hexadecimal.hexadecimal_beq:
Hexadecimal.hexadecimal -> Hexadecimal.hexadecimal -> bool
Nat.ltb: nat -> nat -> bool
Nat.leb: nat -> nat -> bool
-Numeral.numeral_beq: Numeral.numeral -> Numeral.numeral -> bool
-Numeral.int_beq: Numeral.int -> Numeral.int -> bool
+Number.number_beq: Number.number -> Number.number -> bool
+Number.int_beq: Number.int -> Number.int -> bool
Hexadecimal.int_beq: Hexadecimal.int -> Hexadecimal.int -> bool
Hexadecimal.uint_beq: Hexadecimal.uint -> Hexadecimal.uint -> bool
Decimal.decimal_beq: Decimal.decimal -> Decimal.decimal -> bool
@@ -50,7 +50,7 @@ Nat.lor: nat -> nat -> nat
Nat.gcd: nat -> nat -> nat
Hexadecimal.nb_digits: Hexadecimal.uint -> nat
Nat.of_hex_uint: Hexadecimal.uint -> nat
-Nat.of_num_uint: Numeral.uint -> nat
+Nat.of_num_uint: Number.uint -> nat
Nat.of_uint: Decimal.uint -> nat
Decimal.nb_digits: Decimal.uint -> nat
Nat.tail_addmul: nat -> nat -> nat -> nat
diff --git a/test-suite/output/Search_bug13298.out b/test-suite/output/Search_bug13298.out
new file mode 100644
index 0000000000..18488c790f
--- /dev/null
+++ b/test-suite/output/Search_bug13298.out
@@ -0,0 +1 @@
+snd: forall c : c, fst c = 0
diff --git a/test-suite/output/Search_bug13298.v b/test-suite/output/Search_bug13298.v
new file mode 100644
index 0000000000..9a75321c64
--- /dev/null
+++ b/test-suite/output/Search_bug13298.v
@@ -0,0 +1,3 @@
+Set Primitive Projections.
+Record c : Type := { fst : nat; snd : fst = 0 }.
+Search concl:fst.
diff --git a/test-suite/output/StringSyntax.out b/test-suite/output/StringSyntax.out
index e9cf4282dc..68ee7cfeb5 100644
--- a/test-suite/output/StringSyntax.out
+++ b/test-suite/output/StringSyntax.out
@@ -1051,7 +1051,7 @@ Arguments byte_ind _%function_scope _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"127"
: byte
The command has indeed failed with message:
-Expects a single character or a three-digits ascii code.
+Expects a single character or a three-digit ASCII code.
"000"
: ascii
"a"
@@ -1059,7 +1059,7 @@ Expects a single character or a three-digits ascii code.
"127"
: ascii
The command has indeed failed with message:
-Expects a single character or a three-digits ascii code.
+Expects a single character or a three-digit ASCII code.
"000"
: string
"a"
@@ -1084,3 +1084,21 @@ Expects a single character or a three-digits ascii code.
= ["000"; "001"; "002"; "003"; "004"; "005"; "006"; "007"; "008"; "009"; "010"; "011"; "012"; "013"; "014"; "015"; "016"; "017"; "018"; "019"; "020"; "021"; "022"; "023"; "024"; "025"; "026"; "027"; "028"; "029"; "030"; "031"; " "; "!"; """"; "#"; "$"; "%"; "&"; "'"; "("; ")"; "*"; "+"; ","; "-"; "."; "/"; "0"; "1"; "2"; "3"; "4"; "5"; "6"; "7"; "8"; "9"; ":"; ";"; "<"; "="; ">"; "?"; "@"; "A"; "B"; "C"; "D"; "E"; "F"; "G"; "H"; "I"; "J"; "K"; "L"; "M"; "N"; "O"; "P"; "Q"; "R"; "S"; "T"; "U"; "V"; "W"; "X"; "Y"; "Z"; "["; "\"; "]"; "^"; "_"; "`"; "a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"; "i"; "j"; "k"; "l"; "m"; "n"; "o"; "p"; "q"; "r"; "s"; "t"; "u"; "v"; "w"; "x"; "y"; "z"; "{"; "|"; "}"; "~"; "127"; "128"; "129"; "130"; "131"; "132"; "133"; "134"; "135"; "136"; "137"; "138"; "139"; "140"; "141"; "142"; "143"; "144"; "145"; "146"; "147"; "148"; "149"; "150"; "151"; "152"; "153"; "154"; "155"; "156"; "157"; "158"; "159"; "160"; "161"; "162"; "163"; "164"; "165"; "166"; "167";
"168"; "169"; "170"; "171"; "172"; "173"; "174"; "175"; "176"; "177"; "178"; "179"; "180"; "181"; "182"; "183"; "184"; "185"; "186"; "187"; "188"; "189"; "190"; "191"; "192"; "193"; "194"; "195"; "196"; "197"; "198"; "199"; "200"; "201"; "202"; "203"; "204"; "205"; "206"; "207"; "208"; "209"; "210"; "211"; "212"; "213"; "214"; "215"; "216"; "217"; "218"; "219"; "220"; "221"; "222"; "223"; "224"; "225"; "226"; "227"; "228"; "229"; "230"; "231"; "232"; "233"; "234"; "235"; "236"; "237"; "238"; "239"; "240"; "241"; "242"; "243"; "244"; "245"; "246"; "247"; "248"; "249"; "250"; "251"; "252"; "253"; "254"; "255"]
: list ascii
+"abc"
+ : string
+"000"
+ : nat
+"001"
+ : nat
+"002"
+ : nat
+"255"
+ : nat
+The command has indeed failed with message:
+Expects a single character or a three-digit ASCII code.
+"abc"
+ : string2
+"abc" : string2
+ : string2
+"abc" : string1
+ : string1
diff --git a/test-suite/output/StringSyntax.v b/test-suite/output/StringSyntax.v
index aab6e0bb03..a1ffe69527 100644
--- a/test-suite/output/StringSyntax.v
+++ b/test-suite/output/StringSyntax.v
@@ -50,3 +50,68 @@ Local Close Scope byte_scope.
Local Open Scope char_scope.
Compute List.map Ascii.ascii_of_nat (List.seq 0 256).
Local Close Scope char_scope.
+
+(* Test numeral notations for parameterized inductives *)
+Module Test2.
+
+Notation string := (list Byte.byte).
+Definition id_string := @id string.
+
+String Notation string id_string id_string : list_scope.
+
+Check "abc"%list.
+
+End Test2.
+
+(* Test the via ... using ... option *)
+Module Test3.
+
+Inductive I :=
+| IO : I
+| IS : I -> I.
+
+Definition of_byte (x : Byte.byte) : I :=
+ let fix f n :=
+ match n with
+ | O => IO
+ | S n => IS (f n)
+ end in
+ f (Byte.to_nat x).
+
+Definition to_byte (x : I) : option Byte.byte :=
+ let fix f i :=
+ match i with
+ | IO => O
+ | IS i => S (f i)
+ end in
+ Byte.of_nat (f x).
+
+String Notation nat of_byte to_byte (via I mapping [O => IO, S => IS]) : nat_scope.
+
+Check "000".
+Check "001".
+Check "002".
+Check "255".
+Fail Check "256".
+
+End Test3.
+
+(* Test overlapping string notations *)
+Module Test4.
+
+Notation string1 := (list Byte.byte).
+Definition id_string1 := @id string1.
+
+String Notation string1 id_string1 id_string1 : list_scope.
+
+Notation string2 := (list Ascii.ascii).
+Definition a2b := List.map byte_of_ascii.
+Definition b2a := List.map ascii_of_byte.
+
+String Notation string2 b2a a2b : list_scope.
+
+Check "abc"%list.
+Check ["a";"b";"c"]%char%list : string2.
+Check ["a";"b";"c"]%byte%list : string1.
+
+End Test4.
diff --git a/test-suite/output/ZSyntax.v b/test-suite/output/ZSyntax.v
index 7b2bb00ce0..67c4f85d5c 100644
--- a/test-suite/output/ZSyntax.v
+++ b/test-suite/output/ZSyntax.v
@@ -18,7 +18,7 @@ Require Import Arith.
Check (0 + Z.of_nat 11)%Z.
(* Check hexadecimal printing *)
-Definition to_num_int n := Numeral.IntHex (Z.to_hex_int n).
+Definition to_num_int n := Number.IntHexadecimal (Z.to_hex_int n).
Number Notation Z Z.of_num_int to_num_int : Z_scope.
Check 42%Z.
Check (-42)%Z.
diff --git a/test-suite/output/bug_12159.v b/test-suite/output/bug_12159.v
index 437b4a68e9..a7366f2d35 100644
--- a/test-suite/output/bug_12159.v
+++ b/test-suite/output/bug_12159.v
@@ -2,10 +2,10 @@ Declare Scope A.
Declare Scope B.
Delimit Scope A with A.
Delimit Scope B with B.
-Definition to_unit (v : Numeral.uint) : option unit
+Definition to_unit (v : Number.uint) : option unit
:= match Nat.of_num_uint v with O => Some tt | _ => None end.
-Definition of_unit (v : unit) : Numeral.uint := Nat.to_num_uint 0.
-Definition of_unit' (v : unit) : Numeral.uint := Nat.to_num_uint 1.
+Definition of_unit (v : unit) : Number.uint := Nat.to_num_uint 0.
+Definition of_unit' (v : unit) : Number.uint := Nat.to_num_uint 1.
Number Notation unit to_unit of_unit : A.
Number Notation unit to_unit of_unit' : B.
Definition f x : unit := x.
diff --git a/test-suite/output/bug_12908.out b/test-suite/output/bug_12908.out
index fca6dde704..54c4f98422 100644
--- a/test-suite/output/bug_12908.out
+++ b/test-suite/output/bug_12908.out
@@ -1,2 +1,7 @@
forall m n : nat, m * n = (2 * m * n)%nat
: Prop
+File "stdin", line 11, characters 0-31:
+Warning: Notation "_ * _" was already used in scope nat_scope.
+[notation-overridden,parsing]
+forall m n : nat, m * n = Nat.mul (Nat.mul 2 m) n
+ : Prop
diff --git a/test-suite/output/bug_12908.v b/test-suite/output/bug_12908.v
index 558c9f9f6a..6f7be22fa0 100644
--- a/test-suite/output/bug_12908.v
+++ b/test-suite/output/bug_12908.v
@@ -1,6 +1,13 @@
Definition mult' m n := 2 * m * n.
+
Module A.
(* Test hiding of a scoped notation by a lonely notation *)
Infix "*" := mult'.
Check forall m n, mult' m n = Nat.mul (Nat.mul 2 m) n.
End A.
+
+Module B.
+(* Test that an overriden scoped notation is deactivated *)
+Infix "*" := mult' : nat_scope.
+Check forall m n, mult' m n = Nat.mul (Nat.mul 2 m) n.
+End B.
diff --git a/test-suite/output/bug_13004.out b/test-suite/output/bug_13004.out
index 2bd7d67535..28bc580202 100644
--- a/test-suite/output/bug_13004.out
+++ b/test-suite/output/bug_13004.out
@@ -1,2 +1,2 @@
-Ltac bug_13004.t := ltac2:(print (of_string "hi"))
-Ltac bug_13004.u := ident:(H)
+Ltac t := ltac2:(print (of_string "hi"))
+Ltac u := ident:(H)
diff --git a/test-suite/output/bug_13112.out b/test-suite/output/bug_13112.out
new file mode 100644
index 0000000000..a8a98d6b68
--- /dev/null
+++ b/test-suite/output/bug_13112.out
@@ -0,0 +1,4 @@
+0 + 0
+ : nat
+HI
+ : nat
diff --git a/test-suite/output/bug_13112.v b/test-suite/output/bug_13112.v
new file mode 100644
index 0000000000..9fee5e09d8
--- /dev/null
+++ b/test-suite/output/bug_13112.v
@@ -0,0 +1,5 @@
+Reserved Notation "'HI'".
+Notation "'HI'" := (O + O) (only parsing).
+Check HI. (* 0 + 0 : nat *)
+Notation "'HI'" := (O + O) (only printing).
+Check HI. (* 0 + 0 : nat *)
diff --git a/test-suite/output/bug_13238.out b/test-suite/output/bug_13238.out
new file mode 100644
index 0000000000..a17d05200d
--- /dev/null
+++ b/test-suite/output/bug_13238.out
@@ -0,0 +1,4 @@
+Ltac t1 x := replace (x x) with (x x)
+Ltac t2 x := case : x
+Ltac t3 := by move ->
+Ltac t4 := congr True
diff --git a/test-suite/output/bug_13238.v b/test-suite/output/bug_13238.v
new file mode 100644
index 0000000000..9b8063bf13
--- /dev/null
+++ b/test-suite/output/bug_13238.v
@@ -0,0 +1,13 @@
+Require Import ssreflect.
+
+Ltac t1 x := replace (x x) with (x x).
+Print t1.
+
+Ltac t2 x := case: x.
+Print t2.
+
+Ltac t3 := by move->.
+Print t3.
+
+Ltac t4 := congr True.
+Print t4.
diff --git a/test-suite/output/bug_13244.out b/test-suite/output/bug_13244.out
new file mode 100644
index 0000000000..8c7d4ac776
--- /dev/null
+++ b/test-suite/output/bug_13244.out
@@ -0,0 +1,9 @@
+negbT: forall [b : bool], b = false -> ~~ b
+contra_notN: forall [P : Prop] [b : bool], (b -> P) -> ~ P -> ~~ b
+contraPN: forall [P : Prop] [b : bool], (b -> ~ P) -> P -> ~~ b
+contraNN: forall [c b : bool], (c -> b) -> ~~ b -> ~~ c
+contraL: forall [c b : bool], (c -> ~~ b) -> b -> ~~ c
+contraTN: forall [c b : bool], (c -> ~~ b) -> b -> ~~ c
+contra: forall [c b : bool], (c -> b) -> ~~ b -> ~~ c
+introN: forall [P : Prop] [b : bool], reflect P b -> ~ P -> ~~ b
+contraFN: forall [c b : bool], (c -> b) -> b = false -> ~~ c
diff --git a/test-suite/output/bug_13244.v b/test-suite/output/bug_13244.v
new file mode 100644
index 0000000000..83eaac1a35
--- /dev/null
+++ b/test-suite/output/bug_13244.v
@@ -0,0 +1,3 @@
+Require Import ssr.ssrbool.
+Set Warnings "-ssr-search-moved".
+Search headconcl:(~~ _).
diff --git a/test-suite/output/bug_9180.out b/test-suite/output/bug_9180.out
index ed4892b389..f035d0252a 100644
--- a/test-suite/output/bug_9180.out
+++ b/test-suite/output/bug_9180.out
@@ -1,4 +1,3 @@
-Notation
-"n .+1" := S n : nat_scope (default interpretation)
+Notation "n .+1" := (S n) : nat_scope (default interpretation)
forall x : nat, x.+1 = x.+1
: Prop
diff --git a/test-suite/output/bug_9682.out b/test-suite/output/bug_9682.out
index e69de29bb2..45d9e4cad1 100644
--- a/test-suite/output/bug_9682.out
+++ b/test-suite/output/bug_9682.out
@@ -0,0 +1,9 @@
+mmatch 1 + 2 + 3 + 4 + 5 + 6 in nat as x
+return M (x = x) with
+| 1
+end
+ : unit
+#
+ : True
+##
+ : True
diff --git a/test-suite/output/bug_9682.v b/test-suite/output/bug_9682.v
index 3630142126..fa30d323ef 100644
--- a/test-suite/output/bug_9682.v
+++ b/test-suite/output/bug_9682.v
@@ -16,3 +16,13 @@ Notation "'mmatch' x 'in' T 'as' y 'return' 'M' p 'with' ls 'end'" :=
(at level 200, ls at level 91, p at level 10, only printing,
format "'[ ' mmatch '/' x ']' '/' '[ ' in '/' T ']' '/' '[ ' as '/' y ']' '/' '[ ' return M p ']' with '//' '[' ls ']' '//' end"
).
+(* Check use of "mmatch" *)
+Check (mmatch 1 + 2 + 3 + 4 + 5 + 6 in nat as x return M (x = x) with | 1 end).
+
+(* 2nd example *)
+Notation "#" := I (at level 0, only parsing).
+Notation "#" := I (at level 0, only printing).
+Check #.
+Notation "##" := I (at level 0, only printing).
+Notation "##" := I (at level 0, only parsing).
+Check ##.
diff --git a/test-suite/output/goal_output.out b/test-suite/output/goal_output.out
index 773533a8d3..17c1aaa55b 100644
--- a/test-suite/output/goal_output.out
+++ b/test-suite/output/goal_output.out
@@ -2,7 +2,79 @@ Nat.t = nat
: Set
Nat.t = nat
: Set
+2 subgoals
+
+ ============================
+ True
+
+subgoal 2 is:
+ True
+2 subgoals, subgoal 1 (?Goal)
+
+ ============================
+ True
+
+subgoal 2 (?Goal0) is:
+ True
1 subgoal
============================
- False
+ True
+1 subgoal (?Goal0)
+
+ ============================
+ True
+1 subgoal (?Goal0)
+
+ ============================
+ True
+
+*** Unfocused goals:
+
+subgoal 2 (?Goal1) is:
+ True
+subgoal 3 (?Goal) is:
+ True
+1 subgoal
+
+ ============================
+ True
+
+*** Unfocused goals:
+
+subgoal 2 is:
+ True
+subgoal 3 is:
+ True
+This subproof is complete, but there are some unfocused goals.
+Focus next goal with bullet -.
+
+2 subgoals
+
+subgoal 1 is:
+ True
+subgoal 2 is:
+ True
+This subproof is complete, but there are some unfocused goals.
+Focus next goal with bullet -.
+
+2 subgoals
+
+subgoal 1 (?Goal0) is:
+ True
+subgoal 2 (?Goal) is:
+ True
+This subproof is complete, but there are some unfocused goals.
+Focus next goal with bullet -.
+
+1 subgoal
+
+subgoal 1 is:
+ True
+This subproof is complete, but there are some unfocused goals.
+Focus next goal with bullet -.
+
+1 subgoal
+
+subgoal 1 (?Goal) is:
+ True
diff --git a/test-suite/output/goal_output.v b/test-suite/output/goal_output.v
index 327b80b0aa..b1ced94054 100644
--- a/test-suite/output/goal_output.v
+++ b/test-suite/output/goal_output.v
@@ -6,8 +6,32 @@
Print Nat.t.
Timeout 1 Print Nat.t.
-Lemma toto: False.
Set Printing All.
+Lemma toto: True/\True.
+Proof.
+split.
Show.
+Set Printing Goal Names.
+Show.
+Unset Printing Goal Names.
+assert True.
+- idtac.
+Show.
+Set Printing Goal Names.
+Show.
+Set Printing Unfocused.
+Show.
+Unset Printing Goal Names.
+Show.
+Unset Printing Unfocused.
+ auto.
+Show.
+Set Printing Goal Names.
+Show.
+Unset Printing Goal Names.
+- auto.
+Show.
+Set Printing Goal Names.
+Show.
+Unset Printing Goal Names.
Abort.
-
diff --git a/test-suite/output/locate.out b/test-suite/output/locate.out
index 473db2d312..93d9d6cf7b 100644
--- a/test-suite/output/locate.out
+++ b/test-suite/output/locate.out
@@ -1,3 +1,2 @@
-Notation
-"b1 && b2" := if b1 then b2 else false (default interpretation)
-"x && y" := andb x y : bool_scope
+Notation "b1 && b2" := (if b1 then b2 else false) (default interpretation)
+Notation "x && y" := (andb x y) : bool_scope
diff --git a/test-suite/output/prim_array.out b/test-suite/output/prim_array.out
new file mode 100644
index 0000000000..6c12153ab9
--- /dev/null
+++ b/test-suite/output/prim_array.out
@@ -0,0 +1,9 @@
+[| | 0 : nat |]
+ : array nat
+[| 1; 2; 3 | 0 : nat |]
+ : array nat
+[| | 0 : nat |]@{Set}
+ : array@{Set} nat
+[| bool; list nat | nat : Set |]@{prim_array.4}
+ : array@{prim_array.4} Set
+(* {prim_array.4} |= Set < prim_array.4 *)
diff --git a/test-suite/output/prim_array.v b/test-suite/output/prim_array.v
new file mode 100644
index 0000000000..a82f6a16f1
--- /dev/null
+++ b/test-suite/output/prim_array.v
@@ -0,0 +1,10 @@
+Primitive array := #array_type.
+
+Check [| | 0 |].
+
+Check [| 1; 2; 3 | 0 |].
+
+Set Printing Universes.
+Check [| | 0 |].
+
+Check [| bool; list nat | nat |].
diff --git a/test-suite/primitive/arrays/reroot.v b/test-suite/primitive/arrays/reroot.v
deleted file mode 100644
index 172a118cc7..0000000000
--- a/test-suite/primitive/arrays/reroot.v
+++ /dev/null
@@ -1,22 +0,0 @@
-From Coq Require Import Int63 PArray.
-
-Open Scope array_scope.
-
-Definition t : array nat := [| 1; 5; 2 | 4 |].
-Definition t' : array nat := PArray.reroot t.
-
-Definition foo1 := (eq_refl : t'.[1] = 5).
-Definition foo2 := (eq_refl 5 <: t'.[1] = 5).
-Definition foo3 := (eq_refl 5 <<: t'.[1] = 5).
-Definition x1 := Eval compute in t'.[1].
-Definition foo4 := (eq_refl : x1 = 5).
-Definition x2 := Eval cbn in t'.[1].
-Definition foo5 := (eq_refl : x2 = 5).
-
-Definition foo6 := (eq_refl : t.[1] = 5).
-Definition foo7 := (eq_refl 5 <: t.[1] = 5).
-Definition foo8 := (eq_refl 5 <<: t.[1] = 5).
-Definition x3 := Eval compute in t.[1].
-Definition foo9 := (eq_refl : x3 = 5).
-Definition x4 := Eval cbn in t.[1].
-Definition foo10 := (eq_refl : x4 = 5).
diff --git a/test-suite/success/Nsatz.v b/test-suite/success/Nsatz.v
index 998f3f7dd1..73e98ea920 100644
--- a/test-suite/success/Nsatz.v
+++ b/test-suite/success/Nsatz.v
@@ -1,6 +1,8 @@
Require Import TestSuite.admit.
(* compile en user 3m39.915s sur cachalot *)
Require Import Nsatz.
+Require List.
+Import List.ListNotations.
(* Example with a generic domain *)
@@ -294,7 +296,7 @@ Lemma minh: forall A B C D O E H I:point,
Proof. geo_begin.
idtac "minh".
Time nsatz with radicalmax :=1%N strategy:=1%Z
- parameters:=(X O::X B::X C::nil)
+ parameters:=[X O; X B; X C]
variables:= (@nil R).
(*Finished transaction in 13. secs (10.102464u,0.s)
*)
@@ -314,15 +316,15 @@ Proof.
geo_begin.
idtac "Pappus".
Time nsatz with radicalmax :=1%N strategy:=0%Z
- parameters:=(X B::X A1::Y A1::X B1::Y B1::X C::Y C1::nil)
- variables:= (X B
- :: X A1
- :: Y A1
- :: X B1
- :: Y B1
- :: X C
- :: Y C1
- :: X C1 :: Y P :: X P :: Y Q :: X Q :: Y S :: X S :: nil).
+ parameters:=[X B; X A1; Y A1; X B1; Y B1; X C; Y C1]
+ variables:= [X B;
+ X A1;
+ Y A1;
+ X B1;
+ Y B1;
+ X C;
+ Y C1;
+ X C1; Y P; X P; Y Q; X Q; Y S; X S].
(*Finished transaction in 8. secs (7.795815u,0.000999999999999s)
*)
Qed.
@@ -347,7 +349,7 @@ Proof.
geo_begin.
idtac "Simson".
Time nsatz with radicalmax :=1%N strategy:=0%Z
- parameters:=(X B::Y B::X C::Y C::Y D::nil)
+ parameters:=[X B; Y B; X C; Y C; Y D]
variables:= (@nil R). (* compute -[X Y]. *)
(*Finished transaction in 8. secs (7.550852u,0.s)
*)
@@ -432,20 +434,20 @@ Proof.
geo_begin.
idtac "Desargues".
Time
-let lv := rev (X A
- :: X B
- :: Y B
- :: X C
- :: Y C
- :: Y A1 :: X A1
- :: Y B1
- :: Y C1
- :: X T
- :: Y T
- :: X Q
- :: Y Q :: X P :: Y P :: X C1 :: X B1 :: nil) in
+let lv := rev [X A;
+ X B;
+ Y B;
+ X C;
+ Y C;
+ Y A1; X A1;
+ Y B1;
+ Y C1;
+ X T;
+ Y T;
+ X Q;
+ Y Q; X P; Y P; X C1; X B1] in
nsatz with radicalmax :=1%N strategy:=0%Z
- parameters:=(X A::X B::Y B::X C::Y C::X A1::Y B1::Y C1::nil)
+ parameters:=[X A; X B; Y B; X C; Y C; X A1; Y B1; Y C1]
variables:= lv. (*Finished transaction in 8. secs (8.02578u,0.001s)*)
Qed.
@@ -522,9 +524,9 @@ Lemma hauteurs:forall A B C A1 B1 C1 H:point,
geo_begin.
idtac "hauteurs".
Time
- let lv := constr:(Y A1
- :: X A1 :: Y B1 :: X B1 :: Y A :: Y B :: X B :: X A :: X H :: Y C
- :: Y C1 :: Y H :: X C1 :: X C :: (@Datatypes.nil R)) in
+ let lv := constr:([Y A1;
+ X A1; Y B1; X B1; Y A; Y B; X B; X A; X H; Y C;
+ Y C1; Y H; X C1; X C]) in
nsatz with radicalmax := 2%N strategy := 1%Z parameters := (@Datatypes.nil R)
variables := lv.
(*Finished transaction in 5. secs (4.360337u,0.008999s)*)
diff --git a/test-suite/success/NumeralNotationsNoLocal.v b/test-suite/success/NumberNotationsNoLocal.v
index fe97f10ddf..e19d06cfa7 100644
--- a/test-suite/success/NumeralNotationsNoLocal.v
+++ b/test-suite/success/NumberNotationsNoLocal.v
@@ -1,4 +1,4 @@
-(* Test that numeral notations don't work on proof-local variables, especially not ones containing evars *)
+(* Test that number notations don't work on proof-local variables, especially not ones containing evars *)
Inductive unit11 := tt11.
Declare Scope unit11_scope.
Delimit Scope unit11_scope with unit11.
diff --git a/test-suite/success/Record.v b/test-suite/success/Record.v
index ce07512a1e..beb424dd40 100644
--- a/test-suite/success/Record.v
+++ b/test-suite/success/Record.v
@@ -93,3 +93,18 @@ Record R : Type := {
(* This is used in a couple of development such as UniMatch *)
Record S {A:Type} := { a : A; b : forall A:Type, A }.
+
+(* Bug #13165 on implicit arguments in defined fields *)
+Record T := {
+ f {n:nat} (p:n=n) := nat;
+ g := f (eq_refl 0)
+}.
+
+(* Slight improvement in when SProp relevance is detected *)
+Inductive True : SProp := I.
+Inductive eqI : True -> SProp := reflI : eqI I.
+
+Record U (c:True) := {
+ u := c;
+ v := reflI : eqI u;
+ }.
diff --git a/test-suite/success/definition_using.v b/test-suite/success/definition_using.v
new file mode 100644
index 0000000000..120e62b145
--- /dev/null
+++ b/test-suite/success/definition_using.v
@@ -0,0 +1,68 @@
+Require Import Program.
+Axiom bogus : Type.
+
+Section A.
+Variable x : bogus.
+
+#[using="All"]
+Definition c1 : bool := true.
+
+#[using="All"]
+Fixpoint c2 n : bool :=
+ match n with
+ | O => true
+ | S p => c3 p
+ end
+with c3 n : bool :=
+ match n with
+ | O => true
+ | S p => c2 p
+end.
+
+#[using="All"]
+Definition c4 : bool. Proof. exact true. Qed.
+
+#[using="All"]
+Fixpoint c5 (n : nat) {struct n} : bool. Proof. destruct n as [|p]. exact true. exact (c5 p). Qed.
+
+#[using="All", program]
+Definition c6 : bool. Proof. exact true. Qed.
+
+#[using="All", program]
+Fixpoint c7 (n : nat) {struct n} : bool :=
+ match n with
+ | O => true
+ | S p => c7 p
+ end.
+
+End A.
+
+Check c1 : bogus -> bool.
+Check c2 : bogus -> nat -> bool.
+Check c3 : bogus -> nat -> bool.
+Check c4 : bogus -> bool.
+Check c5 : bogus -> nat -> bool.
+Check c6 : bogus -> bool.
+Check c7 : bogus -> nat -> bool.
+
+Section B.
+
+Variable a : bogus.
+Variable h : c1 a = true.
+
+#[using="a*"]
+Definition c8 : bogus := a.
+
+Collection ccc := a h.
+
+#[using="ccc"]
+Definition c9 : bogus := a.
+
+#[using="ccc - h"]
+Definition c10 : bogus := a.
+
+End B.
+
+Check c8 : forall a, c1 a = true -> bogus.
+Check c9 : forall a, c1 a = true -> bogus.
+Check c10: bogus -> bogus.
diff --git a/test-suite/success/polymorphism.v b/test-suite/success/polymorphism.v
index 9ab8ace39e..0796b507a1 100644
--- a/test-suite/success/polymorphism.v
+++ b/test-suite/success/polymorphism.v
@@ -457,5 +457,10 @@ Module ObligationRegression.
(** Test for a regression encountered when fixing obligations for
stronger restriction of universe context. *)
Require Import CMorphisms.
- Check trans_co_eq_inv_arrow_morphism@{_ _ _ _ _ _ _ _}.
+ Check trans_co_eq_inv_arrow_morphism@{_ _ _ _ _ _ _}.
End ObligationRegression.
+
+Axiom poly@{i} : forall(A : Type@{i}) (a : A), unit.
+
+Definition nonpoly := @poly True Logic.I.
+Definition check := nonpoly@{}.
diff --git a/test-suite/success/rewrite_strat.v b/test-suite/success/rewrite_strat.v
index a6e59fdda0..98045d1162 100644
--- a/test-suite/success/rewrite_strat.v
+++ b/test-suite/success/rewrite_strat.v
@@ -51,3 +51,12 @@ Time Qed. (* 0.06 s *)
Set Printing All.
Set Printing Depth 100000.
+
+Tactic Notation "my_rewrite_strat" constr(x) := rewrite_strat topdown x.
+Tactic Notation "my_rewrite_strat2" uconstr(x) := rewrite_strat topdown x.
+Goal (forall x, S x = 0) -> 1=0.
+intro H.
+my_rewrite_strat H.
+Undo.
+my_rewrite_strat2 H.
+Abort.
diff --git a/test-suite/success/sprop_uip.v b/test-suite/success/sprop_uip.v
index eae1b75689..c9377727db 100644
--- a/test-suite/success/sprop_uip.v
+++ b/test-suite/success/sprop_uip.v
@@ -121,6 +121,33 @@ Proof.
simpl. Fail check.
Abort.
+Module HoTTStyle.
+ (* a small proof which tests destruct in a tricky case *)
+
+ Definition ap {A B} (f:A -> B) {x y} (e : seq x y) : seq (f x) (f y).
+ Proof. destruct e. reflexivity. Defined.
+
+ Section S.
+ Context
+ (A : Type)
+ (B : Type)
+ (f : A -> B)
+ (g : B -> A)
+ (section : forall a, seq (g (f a)) a)
+ (retraction : forall b, seq (f (g b)) b).
+
+ Lemma bla (P : B -> Type) (a : A) (F : forall a, P (f a))
+ : seq_rect _ (f (g (f a))) (fun a _ => P a) (F (g (f a))) (f a) (retraction (f a)) = F a.
+ Proof.
+ lazy.
+ change (retraction (f a)) with (ap f (section a)).
+ destruct (section a).
+ reflexivity.
+ Qed.
+ End S.
+
+End HoTTStyle.
+
(* check that extraction doesn't fall apart on matches with special reduction *)
Require Extraction.
diff --git a/theories/Array/PArray.v b/theories/Array/PArray.v
index 3511ba0918..e91a5bf9ad 100644
--- a/theories/Array/PArray.v
+++ b/theories/Array/PArray.v
@@ -22,12 +22,6 @@ Arguments length {_} _.
Primitive copy : forall A, array A -> array A := #array_copy.
Arguments copy {_} _.
-(* [reroot t] produces an array that is extensionaly equal to [t], but whose
- history has been squashed. Useful when performing multiple accesses in an old
- copy of an array that has been updated. *)
-Primitive reroot : forall A, array A -> array A := #array_reroot.
-Arguments reroot {_} _.
-
Module Export PArrayNotations.
Declare Scope array_scope.
@@ -64,9 +58,6 @@ Axiom length_set : forall A t i (a:A),
Axiom get_copy : forall A (t:array A) i, (copy t).[i] = t.[i].
Axiom length_copy : forall A (t:array A), length (copy t) = length t.
-Axiom get_reroot : forall A (t:array A) i, (reroot t).[i] = t.[i].
-Axiom length_reroot : forall A (t:array A), length (reroot t) = length t.
-
Axiom array_ext : forall A (t1 t2:array A),
length t1 = length t2 ->
(forall i, i <? length t1 = true -> t1.[i] = t2.[i]) ->
@@ -94,16 +85,6 @@ Proof.
rewrite !get_out_of_bounds in get_make; assumption.
Qed.
-Lemma default_reroot A (t:array A) : default (reroot t) = default t.
-Proof.
- assert (irr_lt : length t <? length t = false).
- destruct (Int63.ltbP (length t) (length t)); try reflexivity.
- exfalso; eapply BinInt.Z.lt_irrefl; eassumption.
- assert (get_reroot := get_reroot A t (length t)).
- rewrite !get_out_of_bounds in get_reroot; try assumption.
- rewrite length_reroot; assumption.
-Qed.
-
Lemma get_set_same_default A (t : array A) (i : int) :
t.[i <- default t].[i] = default t.
Proof.
diff --git a/theories/FSets/FMapPositive.v b/theories/FSets/FMapPositive.v
index c3c6c96997..02f408fd85 100644
--- a/theories/FSets/FMapPositive.v
+++ b/theories/FSets/FMapPositive.v
@@ -139,8 +139,8 @@ Module PositiveMap <: S with Module E:=PositiveOrderedTypeBits.
| xH =>
match m with
| Leaf => Leaf
- | Node Leaf o Leaf => Leaf
- | Node l o r => Node l None r
+ | Node Leaf _ Leaf => Leaf
+ | Node l _ r => Node l None r
end
| xO ii =>
match m with
diff --git a/theories/Init/Byte.v b/theories/Init/Byte.v
index 7449b52d76..e03820ef22 100644
--- a/theories/Init/Byte.v
+++ b/theories/Init/Byte.v
@@ -16,7 +16,7 @@ Require Import Coq.Init.Logic.
Require Import Coq.Init.Specif.
Require Coq.Init.Nat.
-Declare ML Module "string_notation_plugin".
+Declare ML Module "number_string_notation_plugin".
(** We define an inductive for use with the [String Notation] command
which contains all ascii characters. We use 256 constructors for
diff --git a/theories/Init/Decimal.v b/theories/Init/Decimal.v
index 025264ab01..bb12f9ca3e 100644
--- a/theories/Init/Decimal.v
+++ b/theories/Init/Decimal.v
@@ -118,6 +118,12 @@ Definition opp (d:int) :=
| Neg d => Pos d
end.
+Definition abs (d:int) : uint :=
+ match d with
+ | Pos d => d
+ | Neg d => d
+ end.
+
(** For conversions with binary numbers, it is easier to operate
on little-endian numbers. *)
diff --git a/theories/Init/Hexadecimal.v b/theories/Init/Hexadecimal.v
index 36f5e5ad1f..7467aa1262 100644
--- a/theories/Init/Hexadecimal.v
+++ b/theories/Init/Hexadecimal.v
@@ -125,6 +125,12 @@ Definition opp (d:int) :=
| Neg d => Pos d
end.
+Definition abs (d:int) : uint :=
+ match d with
+ | Pos d => d
+ | Neg d => d
+ end.
+
(** For conversions with binary numbers, it is easier to operate
on little-endian numbers. *)
@@ -173,6 +179,38 @@ Definition nztail_int d :=
| Neg d => let (r, n) := nztail d in pair (Neg r) n
end.
+(** [del_head n d] removes [n] digits at beginning of [d]
+ or returns [zero] if [d] has less than [n] digits. *)
+
+Fixpoint del_head n d :=
+ match n with
+ | O => d
+ | S n =>
+ match d with
+ | Nil => zero
+ | D0 d | D1 d | D2 d | D3 d | D4 d | D5 d | D6 d | D7 d | D8 d | D9 d
+ | Da d | Db d | Dc d | Dd d | De d | Df d =>
+ del_head n d
+ end
+ end.
+
+Definition del_head_int n d :=
+ match d with
+ | Pos d => del_head n d
+ | Neg d => del_head n d
+ end.
+
+(** [del_tail n d] removes [n] digits at end of [d]
+ or returns [zero] if [d] has less than [n] digits. *)
+
+Definition del_tail n d := rev (del_head n (rev d)).
+
+Definition del_tail_int n d :=
+ match d with
+ | Pos d => Pos (del_tail n d)
+ | Neg d => Neg (del_tail n d)
+ end.
+
Module Little.
(** Successor of little-endian numbers *)
diff --git a/theories/Init/Nat.v b/theories/Init/Nat.v
index 7c8cf0b536..9a3a3ec99b 100644
--- a/theories/Init/Nat.v
+++ b/theories/Init/Nat.v
@@ -9,7 +9,7 @@
(************************************************************************)
Require Import Notations Logic Datatypes.
-Require Decimal Hexadecimal Numeral.
+Require Decimal Hexadecimal Number.
Local Open Scope nat_scope.
(**********************************************************************)
@@ -212,10 +212,10 @@ Fixpoint of_hex_uint_acc (d:Hexadecimal.uint)(acc:nat) :=
Definition of_hex_uint (d:Hexadecimal.uint) := of_hex_uint_acc d O.
-Definition of_num_uint (d:Numeral.uint) :=
+Definition of_num_uint (d:Number.uint) :=
match d with
- | Numeral.UIntDec d => of_uint d
- | Numeral.UIntHex d => of_hex_uint d
+ | Number.UIntDecimal d => of_uint d
+ | Number.UIntHexadecimal d => of_hex_uint d
end.
Fixpoint to_little_uint n acc :=
@@ -236,9 +236,9 @@ Fixpoint to_little_hex_uint n acc :=
Definition to_hex_uint n :=
Hexadecimal.rev (to_little_hex_uint n Hexadecimal.zero).
-Definition to_num_uint n := Numeral.UIntDec (to_uint n).
+Definition to_num_uint n := Number.UIntDecimal (to_uint n).
-Definition to_num_hex_uint n := Numeral.UIntHex (to_hex_uint n).
+Definition to_num_hex_uint n := Number.UIntHexadecimal (to_hex_uint n).
Definition of_int (d:Decimal.int) : option nat :=
match Decimal.norm d with
@@ -252,17 +252,17 @@ Definition of_hex_int (d:Hexadecimal.int) : option nat :=
| _ => None
end.
-Definition of_num_int (d:Numeral.int) : option nat :=
+Definition of_num_int (d:Number.int) : option nat :=
match d with
- | Numeral.IntDec d => of_int d
- | Numeral.IntHex d => of_hex_int d
+ | Number.IntDecimal d => of_int d
+ | Number.IntHexadecimal d => of_hex_int d
end.
Definition to_int n := Decimal.Pos (to_uint n).
Definition to_hex_int n := Hexadecimal.Pos (to_hex_uint n).
-Definition to_num_int n := Numeral.IntDec (to_int n).
+Definition to_num_int n := Number.IntDecimal (to_int n).
(** ** Euclidean division *)
diff --git a/theories/Init/Number.v b/theories/Init/Number.v
new file mode 100644
index 0000000000..eb9cc856ac
--- /dev/null
+++ b/theories/Init/Number.v
@@ -0,0 +1,45 @@
+(************************************************************************)
+(* * The Coq Proof Assistant / The Coq Development Team *)
+(* v * Copyright INRIA, CNRS and contributors *)
+(* <O___,, * (see version control and CREDITS file for authors & dates) *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(* * (see LICENSE file for the text of the license) *)
+(************************************************************************)
+
+(** * Decimal or Hexadecimal numbers *)
+
+Require Import Decimal Hexadecimal.
+
+Variant uint := UIntDecimal (u:Decimal.uint) | UIntHexadecimal (u:Hexadecimal.uint).
+#[deprecated(since="8.13",note="Use UintDecimal instead.")]
+Notation UIntDec := UIntDecimal (only parsing).
+#[deprecated(since="8.13",note="Use UintHexadecimal instead.")]
+Notation UIntHex := UIntHexadecimal (only parsing).
+
+Variant int := IntDecimal (i:Decimal.int) | IntHexadecimal (i:Hexadecimal.int).
+#[deprecated(since="8.13",note="Use IntDecimal instead.")]
+Notation IntDec := IntDecimal (only parsing).
+#[deprecated(since="8.13",note="Use IntHexadecimal instead.")]
+Notation IntHex := IntHexadecimal (only parsing).
+
+Variant number := Decimal (d:Decimal.decimal) | Hexadecimal (h:Hexadecimal.hexadecimal).
+#[deprecated(since="8.13",note="Use Decimal instead.")]
+Notation Dec := Decimal (only parsing).
+#[deprecated(since="8.13",note="Use Hexadecimal instead.")]
+Notation Hex := Hexadecimal (only parsing).
+
+Scheme Equality for uint.
+Scheme Equality for int.
+Scheme Equality for number.
+
+Register uint as num.num_uint.type.
+Register int as num.num_int.type.
+Register number as num.number.type.
+
+(** Pseudo-conversion functions used when declaring
+ Number Notations on [uint] and [int]. *)
+
+Definition uint_of_uint (i:uint) := i.
+Definition int_of_int (i:int) := i.
diff --git a/theories/Init/Numeral.v b/theories/Init/Numeral.v
index 179547d0b3..50fa312e7e 100644
--- a/theories/Init/Numeral.v
+++ b/theories/Init/Numeral.v
@@ -8,26 +8,47 @@
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)
-(** * Decimal or Hexadecimal numbers *)
-
-Require Import Decimal Hexadecimal.
-
-Variant uint := UIntDec (u:Decimal.uint) | UIntHex (u:Hexadecimal.uint).
-
-Variant int := IntDec (i:Decimal.int) | IntHex (i:Hexadecimal.int).
-
-Variant numeral := Dec (d:Decimal.decimal) | Hex (h:Hexadecimal.hexadecimal).
-
-Scheme Equality for uint.
-Scheme Equality for int.
-Scheme Equality for numeral.
-
-Register uint as num.num_uint.type.
-Register int as num.num_int.type.
-Register numeral as num.numeral.type.
-
-(** Pseudo-conversion functions used when declaring
- Number Notations on [uint] and [int]. *)
-
-Definition uint_of_uint (i:uint) := i.
-Definition int_of_int (i:int) := i.
+(** * Deprecated: use Number.v instead *)
+
+Require Import Decimal Hexadecimal Number.
+
+#[deprecated(since="8.13",note="Use Number.uint instead.")]
+Notation uint := uint (only parsing).
+#[deprecated(since="8.13",note="Use Number.UintDecimal instead.")]
+Notation UIntDec := UIntDecimal (only parsing).
+#[deprecated(since="8.13",note="Use Number.UintHexadecimal instead.")]
+Notation UIntHex := UIntHexadecimal (only parsing).
+
+#[deprecated(since="8.13",note="Use Number.int instead.")]
+Notation int := int (only parsing).
+#[deprecated(since="8.13",note="Use Number.IntDecimal instead.")]
+Notation IntDec := IntDecimal (only parsing).
+#[deprecated(since="8.13",note="Use Number.IntHexadecimal instead.")]
+Notation IntHex := IntHexadecimal (only parsing).
+
+#[deprecated(since="8.13",note="Use Number.numeral instead.")]
+Notation numeral := number (only parsing).
+#[deprecated(since="8.13",note="Use Number.Decimal instead.")]
+Notation Dec := Decimal (only parsing).
+#[deprecated(since="8.13",note="Use Number.Hexadecimal instead.")]
+Notation Hex := Hexadecimal (only parsing).
+
+#[deprecated(since="8.13",note="Use Number.uint_beq instead.")]
+Notation uint_beq := uint_beq (only parsing).
+#[deprecated(since="8.13",note="Use Number.uint_eq_dec instead.")]
+Notation uint_eq_dec := uint_eq_dec (only parsing).
+#[deprecated(since="8.13",note="Use Number.int_beq instead.")]
+Notation int_beq := int_beq (only parsing).
+#[deprecated(since="8.13",note="Use Number.int_eq_dec instead.")]
+Notation int_eq_dec := int_eq_dec (only parsing).
+#[deprecated(since="8.13",note="Use Number.numeral_beq instead.")]
+Notation numeral_beq := number_beq (only parsing).
+#[deprecated(since="8.13",note="Use Number.numeral_eq_dec instead.")]
+Notation numeral_eq_dec := number_eq_dec (only parsing).
+
+Register number as num.numeral.type.
+
+#[deprecated(since="8.13",note="Use Number.uint_of_uint instead.")]
+Notation uint_of_uint := uint_of_uint (only parsing).
+#[deprecated(since="8.13",note="Use Number.int_of_int instead.")]
+Notation int_of_int := int_of_int (only parsing).
diff --git a/theories/Init/Prelude.v b/theories/Init/Prelude.v
index 0fe3d5491e..9f8a054b5c 100644
--- a/theories/Init/Prelude.v
+++ b/theories/Init/Prelude.v
@@ -17,6 +17,7 @@ Require Coq.Init.Byte.
Require Coq.Init.Decimal.
Require Coq.Init.Hexadecimal.
Require Coq.Init.Numeral.
+Require Coq.Init.Number.
Require Coq.Init.Nat.
Require Export Peano.
Require Export Coq.Init.Wf.
@@ -29,28 +30,26 @@ Require Export Coq.Init.Tauto.
*)
Declare ML Module "cc_plugin".
Declare ML Module "ground_plugin".
-Declare ML Module "numeral_notation_plugin".
-Declare ML Module "string_notation_plugin".
(* Parsing / printing of hexadecimal numbers *)
Arguments Nat.of_hex_uint d%hex_uint_scope.
Arguments Nat.of_hex_int d%hex_int_scope.
-Number Notation Numeral.uint Numeral.uint_of_uint Numeral.uint_of_uint
+Number Notation Number.uint Number.uint_of_uint Number.uint_of_uint
: hex_uint_scope.
-Number Notation Numeral.int Numeral.int_of_int Numeral.int_of_int
+Number Notation Number.int Number.int_of_int Number.int_of_int
: hex_int_scope.
(* Parsing / printing of decimal numbers *)
Arguments Nat.of_uint d%dec_uint_scope.
Arguments Nat.of_int d%dec_int_scope.
-Number Notation Numeral.uint Numeral.uint_of_uint Numeral.uint_of_uint
+Number Notation Number.uint Number.uint_of_uint Number.uint_of_uint
: dec_uint_scope.
-Number Notation Numeral.int Numeral.int_of_int Numeral.int_of_int
+Number Notation Number.int Number.int_of_int Number.int_of_int
: dec_int_scope.
(* Parsing / printing of [nat] numbers *)
-Number Notation nat Nat.of_num_uint Nat.to_num_hex_uint : hex_nat_scope (abstract after 5001).
-Number Notation nat Nat.of_num_uint Nat.to_num_uint : nat_scope (abstract after 5001).
+Number Notation nat Nat.of_num_uint Nat.to_num_hex_uint (abstract after 5001) : hex_nat_scope.
+Number Notation nat Nat.of_num_uint Nat.to_num_uint (abstract after 5001) : nat_scope.
(* Printing/Parsing of bytes *)
Export Byte.ByteSyntaxNotations.
diff --git a/theories/Init/Tactics.v b/theories/Init/Tactics.v
index e1db68aea9..35bab1021e 100644
--- a/theories/Init/Tactics.v
+++ b/theories/Init/Tactics.v
@@ -245,13 +245,16 @@ Tactic Notation "clear" "dependent" hyp(h) :=
Tactic Notation "revert" "dependent" hyp(h) :=
generalize dependent h.
-(** Provide an error message for dependent induction that reports an import is
-required to use it. Importing Coq.Program.Equality will shadow this notation
-with the actual [dependent induction] tactic. *)
+(** Provide an error message for dependent induction/dependent destruction that
+ reports an import is required to use it. Importing Coq.Program.Equality will
+ shadow this notation with the actual tactics. *)
Tactic Notation "dependent" "induction" ident(H) :=
fail "To use dependent induction, first [Require Import Coq.Program.Equality.]".
+Tactic Notation "dependent" "destruction" ident(H) :=
+ fail "To use dependent destruction, first [Require Import Coq.Program.Equality.]".
+
(** *** [inversion_sigma] *)
(** The built-in [inversion] will frequently leave equalities of
dependent pairs. When the first type in the pair is an hProp or
diff --git a/theories/NArith/BinNatDef.v b/theories/NArith/BinNatDef.v
index 222e76c3e7..e57e5fe856 100644
--- a/theories/NArith/BinNatDef.v
+++ b/theories/NArith/BinNatDef.v
@@ -390,10 +390,10 @@ Definition of_uint (d:Decimal.uint) := Pos.of_uint d.
Definition of_hex_uint (d:Hexadecimal.uint) := Pos.of_hex_uint d.
-Definition of_num_uint (d:Numeral.uint) :=
+Definition of_num_uint (d:Number.uint) :=
match d with
- | Numeral.UIntDec d => of_uint d
- | Numeral.UIntHex d => of_hex_uint d
+ | Number.UIntDecimal d => of_uint d
+ | Number.UIntHexadecimal d => of_hex_uint d
end.
Definition of_int (d:Decimal.int) :=
@@ -408,10 +408,10 @@ Definition of_hex_int (d:Hexadecimal.int) :=
| Hexadecimal.Neg _ => None
end.
-Definition of_num_int (d:Numeral.int) :=
+Definition of_num_int (d:Number.int) :=
match d with
- | Numeral.IntDec d => of_int d
- | Numeral.IntHex d => of_hex_int d
+ | Number.IntDecimal d => of_int d
+ | Number.IntHexadecimal d => of_hex_int d
end.
Definition to_uint n :=
@@ -426,13 +426,13 @@ Definition to_hex_uint n :=
| pos p => Pos.to_hex_uint p
end.
-Definition to_num_uint n := Numeral.UIntDec (to_uint n).
+Definition to_num_uint n := Number.UIntDecimal (to_uint n).
Definition to_int n := Decimal.Pos (to_uint n).
Definition to_hex_int n := Hexadecimal.Pos (to_hex_uint n).
-Definition to_num_int n := Numeral.IntDec (to_int n).
+Definition to_num_int n := Number.IntDecimal (to_int n).
Number Notation N of_num_uint to_num_uint : N_scope.
diff --git a/theories/Numbers/AltBinNotations.v b/theories/Numbers/AltBinNotations.v
index 7c846571a7..c203c178f5 100644
--- a/theories/Numbers/AltBinNotations.v
+++ b/theories/Numbers/AltBinNotations.v
@@ -17,7 +17,7 @@
the [Decimal.int] representation. When working with numbers with
thousands of digits and more, conversion from/to [Decimal.int] can
become significantly slow. If that becomes a problem for your
- development, this file provides some alternative [Numeral
+ development, this file provides some alternative [Number
Notation] commands that use [Z] as bridge type. To enable these
commands, just be sure to [Require] this file after other files
defining numeral notations.
diff --git a/theories/Numbers/DecimalFacts.v b/theories/Numbers/DecimalFacts.v
index dd361562ba..87a9f704cd 100644
--- a/theories/Numbers/DecimalFacts.v
+++ b/theories/Numbers/DecimalFacts.v
@@ -10,175 +10,425 @@
(** * DecimalFacts : some facts about Decimal numbers *)
-Require Import Decimal Arith.
+Require Import Decimal Arith ZArith.
+
+Variant digits := d0 | d1 | d2 | d3 | d4 | d5 | d6 | d7 | d8 | d9.
+
+Fixpoint to_list (u : uint) : list digits :=
+ match u with
+ | Nil => nil
+ | D0 u => cons d0 (to_list u)
+ | D1 u => cons d1 (to_list u)
+ | D2 u => cons d2 (to_list u)
+ | D3 u => cons d3 (to_list u)
+ | D4 u => cons d4 (to_list u)
+ | D5 u => cons d5 (to_list u)
+ | D6 u => cons d6 (to_list u)
+ | D7 u => cons d7 (to_list u)
+ | D8 u => cons d8 (to_list u)
+ | D9 u => cons d9 (to_list u)
+ end.
-Lemma uint_dec (d d' : uint) : { d = d' } + { d <> d' }.
-Proof.
- decide equality.
-Defined.
+Fixpoint of_list (l : list digits) : uint :=
+ match l with
+ | nil => Nil
+ | cons d0 l => D0 (of_list l)
+ | cons d1 l => D1 (of_list l)
+ | cons d2 l => D2 (of_list l)
+ | cons d3 l => D3 (of_list l)
+ | cons d4 l => D4 (of_list l)
+ | cons d5 l => D5 (of_list l)
+ | cons d6 l => D6 (of_list l)
+ | cons d7 l => D7 (of_list l)
+ | cons d8 l => D8 (of_list l)
+ | cons d9 l => D9 (of_list l)
+ end.
-Lemma rev_revapp d d' :
- rev (revapp d d') = revapp d' d.
+Lemma of_list_to_list u : of_list (to_list u) = u.
+Proof. now induction u; [|simpl; rewrite IHu..]. Qed.
+
+Lemma to_list_of_list l : to_list (of_list l) = l.
+Proof. now induction l as [|h t IHl]; [|case h; simpl; rewrite IHl]. Qed.
+
+Lemma to_list_inj u u' : to_list u = to_list u' -> u = u'.
Proof.
- revert d'. induction d; simpl; intros; now rewrite ?IHd.
+ now intro H; rewrite <-(of_list_to_list u), <-(of_list_to_list u'), H.
Qed.
-Lemma rev_rev d : rev (rev d) = d.
+Lemma of_list_inj u u' : of_list u = of_list u' -> u = u'.
Proof.
- apply rev_revapp.
+ now intro H; rewrite <-(to_list_of_list u), <-(to_list_of_list u'), H.
Qed.
-Lemma revapp_rev_nil d : revapp (rev d) Nil = d.
-Proof. now fold (rev (rev d)); rewrite rev_rev. Qed.
+Lemma nb_digits_spec u : nb_digits u = length (to_list u).
+Proof. now induction u; [|simpl; rewrite IHu..]. Qed.
-Lemma app_nil_r d : app d Nil = d.
-Proof. now unfold app; rewrite revapp_rev_nil. Qed.
+Fixpoint lnzhead l :=
+ match l with
+ | nil => nil
+ | cons d l' =>
+ match d with
+ | d0 => lnzhead l'
+ | _ => l
+ end
+ end.
-Lemma app_int_nil_r d : app_int d Nil = d.
-Proof. now case d; intro d'; simpl; rewrite app_nil_r. Qed.
+Lemma nzhead_spec u : to_list (nzhead u) = lnzhead (to_list u).
+Proof. now induction u; [|simpl; rewrite IHu|..]. Qed.
+
+Definition lzero := cons d0 nil.
+
+Definition lunorm l :=
+ match lnzhead l with
+ | nil => lzero
+ | d => d
+ end.
+
+Lemma unorm_spec u : to_list (unorm u) = lunorm (to_list u).
+Proof. now unfold unorm, lunorm; rewrite <-nzhead_spec; case (nzhead u). Qed.
-Lemma revapp_revapp_1 d d' d'' :
- nb_digits d <= 1 ->
- revapp (revapp d d') d'' = revapp d' (revapp d d'').
+Lemma revapp_spec d d' :
+ to_list (revapp d d') = List.rev_append (to_list d) (to_list d').
+Proof. now revert d'; induction d; intro d'; [|simpl; rewrite IHd..]. Qed.
+
+Lemma rev_spec d : to_list (rev d) = List.rev (to_list d).
+Proof. now unfold rev; rewrite revapp_spec, List.rev_alt; simpl. Qed.
+
+Lemma app_spec d d' :
+ to_list (app d d') = Datatypes.app (to_list d) (to_list d').
Proof.
- now case d; clear d; intro d;
- [|case d; clear d; intro d;
- [|simpl; case nb_digits; [|intros n]; intros Hn; exfalso;
- [apply (Nat.nle_succ_diag_l _ Hn)|
- apply (Nat.nle_succ_0 _ (le_S_n _ _ Hn))]..]..].
+ unfold app.
+ now rewrite revapp_spec, List.rev_append_rev, rev_spec, List.rev_involutive.
Qed.
-Lemma nb_digits_pos d : d <> Nil -> 0 < nb_digits d.
-Proof. now case d; [|intros d' _; apply Nat.lt_0_succ..]. Qed.
+Definition lnztail l :=
+ let fix aux l_rev :=
+ match l_rev with
+ | cons d0 l_rev => let (r, n) := aux l_rev in pair r (S n)
+ | _ => pair l_rev O
+ end in
+ let (r, n) := aux (List.rev l) in pair (List.rev r) n.
-Lemma nb_digits_revapp d d' :
- nb_digits (revapp d d') = nb_digits d + nb_digits d'.
+Lemma nztail_spec d :
+ let (r, n) := nztail d in
+ let (r', n') := lnztail (to_list d) in
+ to_list r = r' /\ n = n'.
Proof.
- now revert d'; induction d; [|intro d'; simpl; rewrite IHd; simpl..].
+ unfold nztail, lnztail.
+ set (f := fix aux d_rev := match d_rev with
+ | D0 d_rev => let (r, n) := aux d_rev in (r, S n)
+ | _ => (d_rev, 0) end).
+ set (f' := fix aux (l_rev : list digits) : list digits * nat :=
+ match l_rev with
+ | cons d0 l_rev => let (r, n) := aux l_rev in (r, S n)
+ | _ => (l_rev, 0)
+ end).
+ rewrite <-(of_list_to_list (rev d)), rev_spec.
+ induction (List.rev _) as [|h t IHl]; [now simpl|].
+ case h; simpl; [|now rewrite rev_spec; simpl; rewrite to_list_of_list..].
+ now revert IHl; case f; intros r n; case f'; intros r' n' [-> ->].
Qed.
-Lemma nb_digits_rev u : nb_digits (rev u) = nb_digits u.
-Proof. now unfold rev; rewrite nb_digits_revapp. Qed.
+Lemma del_head_spec_0 d : del_head 0 d = d.
+Proof. now simpl. Qed.
-Lemma nb_digits_nzhead u : nb_digits (nzhead u) <= nb_digits u.
-Proof. now induction u; [|apply le_S|..]. Qed.
+Lemma del_head_spec_small n d :
+ n <= length (to_list d) -> to_list (del_head n d) = List.skipn n (to_list d).
+Proof.
+ revert d; induction n as [|n IHn]; intro d; [now simpl|].
+ now case d; [|intros d' H; apply IHn, le_S_n..].
+Qed.
-Lemma del_head_nb_digits (u:uint) : del_head (nb_digits u) u = Nil.
-Proof. now induction u. Qed.
+Lemma del_head_spec_large n d : length (to_list d) < n -> del_head n d = zero.
+Proof.
+ revert d; induction n; intro d; [now case d|].
+ now case d; [|intro d'; simpl; intro H; rewrite (IHn _ (lt_S_n _ _ H))..].
+Qed.
-Lemma nb_digits_del_head n u :
- n <= nb_digits u -> nb_digits (del_head n u) = nb_digits u - n.
+Lemma nb_digits_0 d : nb_digits d = 0 -> d = Nil.
Proof.
- revert u; induction n; intros u; [now rewrite Nat.sub_0_r|].
- now case u; clear u; intro u; [|intro Hn; apply IHn, le_S_n..].
+ rewrite nb_digits_spec, <-(of_list_to_list d).
+ now case (to_list d) as [|h t]; [|rewrite to_list_of_list].
Qed.
+Lemma nb_digits_n0 d : nb_digits d <> 0 -> d <> Nil.
+Proof. now case d; [|intros u _..]. Qed.
+
Lemma nb_digits_iter_D0 n d :
nb_digits (Nat.iter n D0 d) = n + nb_digits d.
Proof. now induction n; simpl; [|rewrite IHn]. Qed.
-Fixpoint nth n u :=
- match n with
- | O =>
- match u with
- | Nil => Nil
- | D0 d => D0 Nil
- | D1 d => D1 Nil
- | D2 d => D2 Nil
- | D3 d => D3 Nil
- | D4 d => D4 Nil
- | D5 d => D5 Nil
- | D6 d => D6 Nil
- | D7 d => D7 Nil
- | D8 d => D8 Nil
- | D9 d => D9 Nil
- end
- | S n =>
- match u with
- | Nil => Nil
- | D0 d | D1 d | D2 d | D3 d | D4 d | D5 d | D6 d | D7 d | D8 d | D9 d =>
- nth n d
- end
- end.
+Lemma length_lnzhead l : length (lnzhead l) <= length l.
+Proof. now induction l as [|h t IHl]; [|case h; [apply le_S|..]]. Qed.
+
+Lemma nb_digits_nzhead u : nb_digits (nzhead u) <= nb_digits u.
+Proof. now induction u; [|apply le_S|..]. Qed.
+
+Lemma unorm_nzhead u : nzhead u <> Nil -> unorm u = nzhead u.
+Proof. now unfold unorm; case nzhead. Qed.
-Lemma nb_digits_nth n u : nb_digits (nth n u) <= 1.
+Lemma nb_digits_unorm u : u <> Nil -> nb_digits (unorm u) <= nb_digits u.
Proof.
- revert u; induction n.
- - now intro u; case u; [apply Nat.le_0_1|..].
- - intro u; case u; [apply Nat.le_0_1|intro u'; apply IHn..].
+ intro Hu; case (uint_eq_dec (nzhead u) Nil).
+ { unfold unorm; intros ->; simpl.
+ now revert Hu; case u; [|intros u' _; apply le_n_S, Nat.le_0_l..]. }
+ intro H; rewrite (unorm_nzhead _ H); apply nb_digits_nzhead.
Qed.
-Lemma del_head_nth n u :
- n < nb_digits u ->
- del_head n u = revapp (nth n u) (del_head (S n) u).
-Proof.
- revert u; induction n; intro u; [now case u|].
- now case u; [|intro u'; intro H; apply IHn, le_S_n..].
-Qed.
-
-Lemma nth_revapp_r n d d' :
- nb_digits d <= n ->
- nth n (revapp d d') = nth (n - nb_digits d) d'.
-Proof.
- revert d d'; induction n; intro d.
- - now case d; intro d';
- [case d'|intros d'' H; exfalso; revert H; apply Nat.nle_succ_0..].
- - now induction d;
- [intro d'; case d'|
- intros d' H;
- simpl revapp; rewrite IHd; [|now apply le_Sn_le];
- rewrite Nat.sub_succ_l; [|now apply le_S_n];
- simpl; rewrite <-(IHn _ _ (le_S_n _ _ H))..].
-Qed.
-
-Lemma nth_revapp_l n d d' :
- n < nb_digits d ->
- nth n (revapp d d') = nth (nb_digits d - n - 1) d.
-Proof.
- revert d d'; induction n; intro d.
- - rewrite Nat.sub_0_r.
- now induction d;
- [|intros d' _; simpl revapp;
- revert IHd; case d; clear d; [|intro d..]; intro IHd;
- [|rewrite IHd; [simpl nb_digits; rewrite (Nat.sub_succ_l _ (S _))|];
- [|apply le_n_S, Nat.le_0_l..]..]..].
- - now induction d;
- [|intros d' H;
- simpl revapp; simpl nb_digits;
- simpl in H; generalize (lt_S_n _ _ H); clear H; intro H;
- case (le_lt_eq_dec _ _ H); clear H; intro H;
- [rewrite (IHd _ H), Nat.sub_succ_l;
- [rewrite Nat.sub_succ_l; [|apply Nat.le_add_le_sub_r]|
- apply le_Sn_le]|
- rewrite nth_revapp_r; rewrite <-H;
- [rewrite Nat.sub_succ, Nat.sub_succ_l; [rewrite !Nat.sub_diag|]|]]..].
-Qed.
-
-Lemma app_del_tail_head (u:uint) n :
- n <= nb_digits u ->
- app (del_tail n u) (del_head (nb_digits u - n) u) = u.
-Proof.
- unfold app, del_tail; rewrite rev_rev.
- induction n.
- - intros _; rewrite Nat.sub_0_r, del_head_nb_digits; simpl.
- now rewrite revapp_rev_nil.
- - intro Hn.
- rewrite (del_head_nth (_ - _));
- [|now apply Nat.sub_lt; [|apply Nat.lt_0_succ]].
- rewrite Nat.sub_succ_r, <-Nat.sub_1_r.
- rewrite <-(nth_revapp_l _ _ Nil Hn); fold (rev u).
- rewrite <-revapp_revapp_1; [|now apply nb_digits_nth].
- rewrite <-(del_head_nth _ _); [|now rewrite nb_digits_rev].
- rewrite Nat.sub_1_r, Nat.succ_pred_pos; [|now apply Nat.lt_add_lt_sub_r].
- apply (IHn (le_Sn_le _ _ Hn)).
+Lemma nb_digits_rev d : nb_digits (rev d) = nb_digits d.
+Proof. now rewrite !nb_digits_spec, rev_spec, List.rev_length. Qed.
+
+Lemma nb_digits_del_head_sub d n :
+ n <= nb_digits d ->
+ nb_digits (del_head (nb_digits d - n) d) = n.
+Proof.
+ rewrite !nb_digits_spec; intro Hn.
+ rewrite del_head_spec_small; [|now apply Nat.le_sub_l].
+ rewrite List.skipn_length, <-(Nat2Z.id (_ - _)).
+ rewrite Nat2Z.inj_sub; [|now apply Nat.le_sub_l].
+ rewrite (Nat2Z.inj_sub _ _ Hn).
+ rewrite Z.sub_sub_distr, Z.sub_diag; apply Nat2Z.id.
+Qed.
+
+Lemma unorm_D0 u : unorm (D0 u) = unorm u.
+Proof. reflexivity. Qed.
+
+Lemma app_nil_l d : app Nil d = d.
+Proof. now simpl. Qed.
+
+Lemma app_nil_r d : app d Nil = d.
+Proof. now apply to_list_inj; rewrite app_spec, List.app_nil_r. Qed.
+
+Lemma abs_app_int d d' : abs (app_int d d') = app (abs d) d'.
+Proof. now case d. Qed.
+
+Lemma abs_norm d : abs (norm d) = unorm (abs d).
+Proof. now case d as [u|u]; [|simpl; unfold unorm; case nzhead]. Qed.
+
+Lemma iter_D0_nzhead d :
+ Nat.iter (nb_digits d - nb_digits (nzhead d)) D0 (nzhead d) = d.
+Proof.
+ induction d; [now simpl| |now rewrite Nat.sub_diag..].
+ simpl nzhead; simpl nb_digits.
+ rewrite (Nat.sub_succ_l _ _ (nb_digits_nzhead _)).
+ now rewrite <-IHd at 4.
+Qed.
+
+Lemma iter_D0_unorm d :
+ d <> Nil ->
+ Nat.iter (nb_digits d - nb_digits (unorm d)) D0 (unorm d) = d.
+Proof.
+ case (uint_eq_dec (nzhead d) Nil); intro Hn.
+ { unfold unorm; rewrite Hn; simpl; intro H.
+ revert H Hn; induction d; [now simpl|intros _|now intros _..].
+ case (uint_eq_dec d Nil); simpl; intros H Hn; [now rewrite H|].
+ rewrite Nat.sub_0_r, (le_plus_minus 1 (nb_digits d)).
+ { now simpl; rewrite IHd. }
+ revert H; case d; [now simpl|intros u _; apply le_n_S, Nat.le_0_l..]. }
+ intros _; rewrite (unorm_nzhead _ Hn); apply iter_D0_nzhead.
+Qed.
+
+Lemma nzhead_app_l d d' :
+ nb_digits d' < nb_digits (nzhead (app d d')) ->
+ nzhead (app d d') = app (nzhead d) d'.
+Proof.
+ intro Hl; apply to_list_inj; revert Hl.
+ rewrite !nb_digits_spec, app_spec, !nzhead_spec, app_spec.
+ induction (to_list d) as [|h t IHl].
+ { now simpl; intro H; exfalso; revert H; apply le_not_lt, length_lnzhead. }
+ rewrite <-List.app_comm_cons.
+ now case h; [simpl; intro Hl; apply IHl|..].
+Qed.
+
+Lemma nzhead_app_r d d' :
+ nb_digits (nzhead (app d d')) <= nb_digits d' ->
+ nzhead (app d d') = nzhead d'.
+Proof.
+ intro Hl; apply to_list_inj; revert Hl.
+ rewrite !nb_digits_spec, !nzhead_spec, app_spec.
+ induction (to_list d) as [|h t IHl]; [now simpl|].
+ rewrite <-List.app_comm_cons.
+ now case h; [| simpl; rewrite List.app_length; intro Hl; exfalso; revert Hl;
+ apply le_not_lt, le_plus_r..].
+Qed.
+
+Lemma nzhead_app_nil_r d d' : nzhead (app d d') = Nil -> nzhead d' = Nil.
+Proof.
+now intro H; generalize H; rewrite nzhead_app_r; [|rewrite H; apply Nat.le_0_l].
+Qed.
+
+Lemma nzhead_app_nil d d' :
+ nb_digits (nzhead (app d d')) <= nb_digits d' -> nzhead d = Nil.
+Proof.
+ intro H; apply to_list_inj; revert H.
+ rewrite !nb_digits_spec, !nzhead_spec, app_spec.
+ induction (to_list d) as [|h t IHl]; [now simpl|].
+ now case h; [now simpl|..];
+ simpl;intro H; exfalso; revert H; apply le_not_lt;
+ rewrite List.app_length; apply le_plus_r.
+Qed.
+
+Lemma nzhead_app_nil_l d d' : nzhead (app d d') = Nil -> nzhead d = Nil.
+Proof.
+ intro H; apply to_list_inj; generalize (f_equal to_list H); clear H.
+ rewrite !nzhead_spec, app_spec.
+ induction (to_list d) as [|h t IHl]; [now simpl|].
+ now rewrite <-List.app_comm_cons; case h.
+Qed.
+
+Lemma unorm_app_zero d d' :
+ nb_digits (unorm (app d d')) <= nb_digits d' -> unorm d = zero.
+Proof.
+ unfold unorm.
+ case (uint_eq_dec (nzhead (app d d')) Nil).
+ { now intro Hn; rewrite Hn, (nzhead_app_nil_l _ _ Hn). }
+ intro H; fold (unorm (app d d')); rewrite (unorm_nzhead _ H); intro H'.
+ case (uint_eq_dec (nzhead d) Nil); [now intros->|].
+ intro H''; fold (unorm d); rewrite (unorm_nzhead _ H'').
+ exfalso; apply H''; revert H'; apply nzhead_app_nil.
+Qed.
+
+Lemma app_int_nil_r d : app_int d Nil = d.
+Proof.
+ now case d; intro d'; simpl;
+ rewrite <-(of_list_to_list (app _ _)), app_spec;
+ rewrite List.app_nil_r, of_list_to_list.
+Qed.
+
+Lemma unorm_app_l d d' :
+ nb_digits d' < nb_digits (unorm (app d d')) ->
+ unorm (app d d') = app (unorm d) d'.
+Proof.
+ case (uint_eq_dec d' Nil); [now intros->; rewrite !app_nil_r|intro Hd'].
+ case (uint_eq_dec (nzhead (app d d')) Nil).
+ { unfold unorm; intros->; simpl; intro H; exfalso; revert H; apply le_not_lt.
+ now revert Hd'; case d'; [|intros d'' _; apply le_n_S, Peano.le_0_n..]. }
+ intro Ha; rewrite (unorm_nzhead _ Ha).
+ intro Hn; generalize Hn; rewrite (nzhead_app_l _ _ Hn).
+ rewrite !nb_digits_spec, app_spec, List.app_length.
+ case (uint_eq_dec (nzhead d) Nil).
+ { intros->; simpl; intro H; exfalso; revert H; apply Nat.lt_irrefl. }
+ now intro H; rewrite (unorm_nzhead _ H).
+Qed.
+
+Lemma unorm_app_r d d' :
+ nb_digits (unorm (app d d')) <= nb_digits d' ->
+ unorm (app d d') = unorm d'.
+Proof.
+ case (uint_eq_dec (nzhead (app d d')) Nil).
+ { now unfold unorm; intro H; rewrite H, (nzhead_app_nil_r _ _ H). }
+ intro Ha; rewrite (unorm_nzhead _ Ha).
+ case (uint_eq_dec (nzhead d') Nil).
+ { now intros H H'; exfalso; apply Ha; rewrite nzhead_app_r. }
+ intro Hd'; rewrite (unorm_nzhead _ Hd'); apply nzhead_app_r.
+Qed.
+
+Lemma norm_app_int d d' :
+ nb_digits d' < nb_digits (unorm (app (abs d) d')) ->
+ norm (app_int d d') = app_int (norm d) d'.
+Proof.
+ case (uint_eq_dec d' Nil); [now intros->; rewrite !app_int_nil_r|intro Hd'].
+ case d as [d|d]; [now simpl; intro H; apply f_equal, unorm_app_l|].
+ simpl; unfold unorm.
+ case (uint_eq_dec (nzhead (app d d')) Nil).
+ { intros->; simpl; intro H; exfalso; revert H; apply le_not_lt.
+ now revert Hd'; case d'; [|intros d'' _; apply le_n_S, Peano.le_0_n..]. }
+ set (m := match nzhead _ with Nil => _ | _ => _ end).
+ intro Ha.
+ replace m with (nzhead (app d d')).
+ 2:{ now unfold m; revert Ha; case nzhead. }
+ intro Hn; generalize Hn; rewrite (nzhead_app_l _ _ Hn).
+ case (uint_eq_dec (app (nzhead d) d') Nil).
+ { intros->; simpl; intro H; exfalso; revert H; apply le_not_lt, Nat.le_0_l. }
+ clear m; set (m := match app _ _ with Nil => _ | _ => _ end).
+ intro Ha'.
+ replace m with (Neg (app (nzhead d) d')); [|now unfold m; revert Ha'; case app].
+ case (uint_eq_dec (nzhead d) Nil).
+ { intros->; simpl; intro H; exfalso; revert H; apply Nat.lt_irrefl. }
+ clear m; set (m := match nzhead _ with Nil => _ | _ => _ end).
+ intro Hd.
+ now replace m with (Neg (nzhead d)); [|unfold m; revert Hd; case nzhead].
+Qed.
+
+Lemma del_head_nb_digits d : del_head (nb_digits d) d = Nil.
+Proof.
+ apply to_list_inj.
+ rewrite nb_digits_spec, del_head_spec_small; [|now simpl].
+ now rewrite List.skipn_all.
+Qed.
+
+Lemma del_tail_nb_digits d : del_tail (nb_digits d) d = Nil.
+Proof. now unfold del_tail; rewrite <-nb_digits_rev, del_head_nb_digits. Qed.
+
+Lemma del_head_app n d d' :
+ n <= nb_digits d -> del_head n (app d d') = app (del_head n d) d'.
+Proof.
+ rewrite nb_digits_spec; intro Hn.
+ apply to_list_inj.
+ rewrite del_head_spec_small.
+ 2:{ now rewrite app_spec, List.app_length; apply le_plus_trans. }
+ rewrite !app_spec, (del_head_spec_small _ _ Hn).
+ rewrite List.skipn_app.
+ now rewrite (proj2 (Nat.sub_0_le _ _) Hn).
+Qed.
+
+Lemma del_tail_app n d d' :
+ n <= nb_digits d' -> del_tail n (app d d') = app d (del_tail n d').
+Proof.
+ rewrite nb_digits_spec; intro Hn.
+ unfold del_tail.
+ rewrite <-(of_list_to_list (rev (app d d'))), rev_spec, app_spec.
+ rewrite List.rev_app_distr, <-!rev_spec, <-app_spec, of_list_to_list.
+ rewrite del_head_app; [|now rewrite nb_digits_spec, rev_spec, List.rev_length].
+ apply to_list_inj.
+ rewrite rev_spec, !app_spec, !rev_spec.
+ now rewrite List.rev_app_distr, List.rev_involutive.
+Qed.
+
+Lemma del_tail_app_int n d d' :
+ n <= nb_digits d' -> del_tail_int n (app_int d d') = app_int d (del_tail n d').
+Proof. now case d as [d|d]; simpl; intro H; rewrite del_tail_app. Qed.
+
+Lemma app_del_tail_head n (d:uint) :
+ n <= nb_digits d -> app (del_tail n d) (del_head (nb_digits d - n) d) = d.
+Proof.
+ rewrite nb_digits_spec; intro Hn; unfold del_tail.
+ rewrite <-(of_list_to_list (app _ _)), app_spec, rev_spec.
+ rewrite del_head_spec_small; [|now rewrite rev_spec, List.rev_length].
+ rewrite del_head_spec_small; [|now apply Nat.le_sub_l].
+ rewrite rev_spec.
+ set (n' := _ - n).
+ assert (Hn' : n = length (to_list d) - n').
+ { now apply plus_minus; rewrite Nat.add_comm; symmetry; apply le_plus_minus_r. }
+ now rewrite Hn', <-List.firstn_skipn_rev, List.firstn_skipn, of_list_to_list.
Qed.
Lemma app_int_del_tail_head n (d:int) :
- let ad := match d with Pos d | Neg d => d end in
- n <= nb_digits ad ->
- app_int (del_tail_int n d) (del_head (nb_digits ad - n) ad) = d.
+ n <= nb_digits (abs d) ->
+ app_int (del_tail_int n d) (del_head (nb_digits (abs d) - n) (abs d)) = d.
Proof. now case d; clear d; simpl; intros u Hu; rewrite app_del_tail_head. Qed.
+Lemma del_head_app_int_exact i f :
+ nb_digits f < nb_digits (unorm (app (abs i) f)) ->
+ del_head (nb_digits (unorm (app (abs i) f)) - nb_digits f) (unorm (app (abs i) f)) = f.
+Proof.
+ simpl; intro Hnb; generalize Hnb; rewrite (unorm_app_l _ _ Hnb); clear Hnb.
+ replace (_ - _) with (nb_digits (unorm (abs i))).
+ - now rewrite del_head_app; [rewrite del_head_nb_digits|].
+ - rewrite !nb_digits_spec, app_spec, List.app_length.
+ now rewrite Nat.add_comm, minus_plus.
+Qed.
+
+Lemma del_tail_app_int_exact i f :
+ nb_digits f < nb_digits (unorm (app (abs i) f)) ->
+ del_tail_int (nb_digits f) (norm (app_int i f)) = norm i.
+Proof.
+ simpl; intro Hnb.
+ rewrite (norm_app_int _ _ Hnb).
+ rewrite del_tail_app_int; [|now simpl].
+ now rewrite del_tail_nb_digits, app_int_nil_r.
+Qed.
+
(** Normalization on little-endian numbers *)
Fixpoint nztail d :=
@@ -224,10 +474,13 @@ Proof.
apply nzhead_revapp.
Qed.
+Lemma rev_rev d : rev (rev d) = d.
+Proof. now apply to_list_inj; rewrite !rev_spec, List.rev_involutive. Qed.
+
Lemma rev_nztail_rev d :
rev (nztail (rev d)) = nzhead d.
Proof.
- destruct (uint_dec (nztail (rev d)) Nil) as [H|H].
+ destruct (uint_eq_dec (nztail (rev d)) Nil) as [H|H].
- rewrite H. unfold rev; simpl.
rewrite <- (rev_rev d). symmetry.
now apply nzhead_revapp_0.
@@ -278,21 +531,9 @@ Proof.
unfold unorm. now destruct nzhead.
Qed.
-Lemma unorm_D0 u : unorm (D0 u) = unorm u.
-Proof. reflexivity. Qed.
-
Lemma unorm_iter_D0 n u : unorm (Nat.iter n D0 u) = unorm u.
Proof. now induction n. Qed.
-Lemma nb_digits_unorm u :
- u <> Nil -> nb_digits (unorm u) <= nb_digits u.
-Proof.
- case u; clear u; [now simpl|intro u..]; [|now simpl..].
- intros _; unfold unorm.
- case_eq (nzhead (D0 u)); [|now intros u' <-; apply nb_digits_nzhead..].
- intros _; apply le_n_S, Nat.le_0_l.
-Qed.
-
Lemma del_head_nonnil n u :
n < nb_digits u -> del_head n u <> Nil.
Proof.
@@ -311,73 +552,78 @@ Proof.
now apply del_head_nonnil.
Qed.
-Lemma nzhead_invol d : nzhead (nzhead d) = nzhead d.
+Lemma nzhead_involutive d : nzhead (nzhead d) = nzhead d.
Proof.
now induction d.
Qed.
+#[deprecated(since="8.13",note="Use nzhead_involutive instead.")]
+Notation nzhead_invol := nzhead_involutive (only parsing).
-Lemma nztail_invol d : nztail (nztail d) = nztail d.
+Lemma nztail_involutive d : nztail (nztail d) = nztail d.
Proof.
rewrite <-(rev_rev (nztail _)), <-(rev_rev (nztail d)), <-(rev_rev d).
- now rewrite !rev_nztail_rev, nzhead_invol.
+ now rewrite !rev_nztail_rev, nzhead_involutive.
Qed.
+#[deprecated(since="8.13",note="Use nztail_involutive instead.")]
+Notation nztail_invol := nztail_involutive (only parsing).
-Lemma unorm_invol d : unorm (unorm d) = unorm d.
+Lemma unorm_involutive d : unorm (unorm d) = unorm d.
Proof.
unfold unorm.
destruct (nzhead d) eqn:E; trivial.
destruct (nzhead_nonzero _ _ E).
Qed.
+#[deprecated(since="8.13",note="Use unorm_involutive instead.")]
+Notation unorm_invol := unorm_involutive (only parsing).
-Lemma norm_invol d : norm (norm d) = norm d.
+Lemma norm_involutive d : norm (norm d) = norm d.
Proof.
unfold norm.
destruct d.
- - f_equal. apply unorm_invol.
+ - f_equal. apply unorm_involutive.
- destruct (nzhead d) eqn:E; auto.
destruct (nzhead_nonzero _ _ E).
Qed.
+#[deprecated(since="8.13",note="Use norm_involutive instead.")]
+Notation norm_invol := norm_involutive (only parsing).
+
+Lemma lnzhead_neq_d0_head l l' : ~(lnzhead l = cons d0 l').
+Proof. now induction l as [|h t Il]; [|case h]. Qed.
+
+Lemma lnzhead_head_nd0 h t : h <> d0 -> lnzhead (cons h t) = cons h t.
+Proof. now case h. Qed.
Lemma nzhead_del_tail_nzhead_eq n u :
nzhead u = u ->
n < nb_digits u ->
nzhead (del_tail n u) = del_tail n u.
Proof.
+ rewrite nb_digits_spec, <-List.rev_length.
intros Hu Hn.
- assert (Hhd : forall u,
- nzhead u = u <-> match nth 0 u with D0 _ => False | _ => True end).
- { clear n u Hu Hn; intro u.
- case u; clear u; [|intro u..]; [now simpl| |now simpl..]; simpl.
- split; [|now simpl].
- apply nzhead_nonzero. }
- assert (Hhd' : nth 0 (del_tail n u) = nth 0 u).
- { rewrite <-(app_del_tail_head _ _ (le_Sn_le _ _ Hn)) at 2.
- unfold app.
- rewrite nth_revapp_l.
- - rewrite <-(nth_revapp_l _ _ Nil).
- + now fold (rev (rev (del_tail n u))); rewrite rev_rev.
- + unfold del_tail; rewrite rev_rev.
- rewrite nb_digits_del_head; rewrite nb_digits_rev.
- * now rewrite <-Nat.lt_add_lt_sub_r.
- * now apply Nat.lt_le_incl.
- - unfold del_tail; rewrite rev_rev.
- rewrite nb_digits_del_head; rewrite nb_digits_rev.
- + now rewrite <-Nat.lt_add_lt_sub_r.
- + now apply Nat.lt_le_incl. }
- revert Hu; rewrite Hhd; intro Hu.
- now rewrite Hhd, Hhd'.
+ apply to_list_inj; unfold del_tail.
+ rewrite nzhead_spec, rev_spec.
+ rewrite del_head_spec_small; [|now rewrite rev_spec; apply Nat.lt_le_incl].
+ rewrite rev_spec.
+ rewrite List.skipn_rev, List.rev_involutive.
+ generalize (f_equal to_list Hu) Hn; rewrite nzhead_spec; intro Hu'.
+ case (to_list u) as [|h t].
+ { simpl; intro H; exfalso; revert H; apply le_not_lt, Peano.le_0_n. }
+ intro Hn'; generalize (Nat.sub_gt _ _ Hn'); rewrite List.rev_length.
+ case (_ - _); [now simpl|]; intros n' _.
+ rewrite List.firstn_cons, lnzhead_head_nd0; [now simpl|].
+ intro Hh; revert Hu'; rewrite Hh; apply lnzhead_neq_d0_head.
Qed.
Lemma nzhead_del_tail_nzhead n u :
n < nb_digits (nzhead u) ->
nzhead (del_tail n (nzhead u)) = del_tail n (nzhead u).
-Proof. apply nzhead_del_tail_nzhead_eq, nzhead_invol. Qed.
+Proof. apply nzhead_del_tail_nzhead_eq, nzhead_involutive. Qed.
Lemma unorm_del_tail_unorm n u :
n < nb_digits (unorm u) ->
unorm (del_tail n (unorm u)) = del_tail n (unorm u).
Proof.
- case (uint_dec (nzhead u) Nil).
+ case (uint_eq_dec (nzhead u) Nil).
- unfold unorm; intros->; case n; [now simpl|]; intro n'.
now simpl; intro H; exfalso; generalize (lt_S_n _ _ H).
- unfold unorm.
@@ -396,7 +642,7 @@ Lemma norm_del_tail_int_norm n d :
Proof.
case d; clear d; intros u; simpl.
- now intro H; simpl; rewrite unorm_del_tail_unorm.
- - case (uint_dec (nzhead u) Nil); intro Hu.
+ - case (uint_eq_dec (nzhead u) Nil); intro Hu.
+ now rewrite Hu; case n; [|intros n' Hn'; generalize (lt_S_n _ _ Hn')].
+ set (m := match nzhead u with Nil => Pos zero | _ => _ end).
replace m with (Neg (nzhead u)); [|now unfold m; revert Hu; case nzhead].
@@ -418,7 +664,7 @@ Proof.
generalize (nzhead_revapp d d').
generalize (nzhead_revapp_0 (nztail d) d').
generalize (nzhead_revapp (nztail d) d').
- rewrite nztail_invol.
+ rewrite nztail_involutive.
now case nztail;
[intros _ H _ H'; rewrite (H eq_refl), (H' eq_refl)
|intros d'' H _ H' _; rewrite H; [rewrite H'|]..].
@@ -455,5 +701,10 @@ Proof.
|rewrite H'; unfold r; clear m r H'];
unfold norm;
rewrite rev_rev, <-Hd'';
- rewrite nzhead_revapp; rewrite nztail_invol; [|rewrite Hd'']..].
+ rewrite nzhead_revapp; rewrite nztail_involutive; [|rewrite Hd'']..].
+Qed.
+
+Lemma unorm_app_l_nil d d' : nzhead d = Nil -> unorm (app d d') = unorm d'.
+Proof.
+ now unfold unorm; rewrite <-nzhead_app_nzhead; intros->; rewrite app_nil_l.
Qed.
diff --git a/theories/Numbers/DecimalN.v b/theories/Numbers/DecimalN.v
index 8bc5c38fb5..a5dd97f24b 100644
--- a/theories/Numbers/DecimalN.v
+++ b/theories/Numbers/DecimalN.v
@@ -74,7 +74,7 @@ Proof.
destruct (norm d) eqn:Hd; intros [= <-].
unfold N.to_int. rewrite Unsigned.to_of. f_equal.
revert Hd; destruct d; simpl.
- - intros [= <-]. apply unorm_invol.
+ - intros [= <-]. apply unorm_involutive.
- destruct (nzhead d); now intros [= <-].
Qed.
@@ -93,7 +93,7 @@ Qed.
Lemma of_int_norm d : N.of_int (norm d) = N.of_int d.
Proof.
- unfold N.of_int. now rewrite norm_invol.
+ unfold N.of_int. now rewrite norm_involutive.
Qed.
Lemma of_inj_pos d d' :
diff --git a/theories/Numbers/DecimalNat.v b/theories/Numbers/DecimalNat.v
index 1962ac5d9d..4fee40caa2 100644
--- a/theories/Numbers/DecimalNat.v
+++ b/theories/Numbers/DecimalNat.v
@@ -270,7 +270,7 @@ Proof.
destruct (norm d) eqn:Hd; intros [= <-].
unfold Nat.to_int. rewrite Unsigned.to_of. f_equal.
revert Hd; destruct d; simpl.
- - intros [= <-]. apply unorm_invol.
+ - intros [= <-]. apply unorm_involutive.
- destruct (nzhead d); now intros [= <-].
Qed.
@@ -289,7 +289,7 @@ Qed.
Lemma of_int_norm d : Nat.of_int (norm d) = Nat.of_int d.
Proof.
- unfold Nat.of_int. now rewrite norm_invol.
+ unfold Nat.of_int. now rewrite norm_involutive.
Qed.
Lemma of_inj_pos d d' :
diff --git a/theories/Numbers/DecimalQ.v b/theories/Numbers/DecimalQ.v
index c51cced024..2027813eec 100644
--- a/theories/Numbers/DecimalQ.v
+++ b/theories/Numbers/DecimalQ.v
@@ -15,455 +15,413 @@
Require Import Decimal DecimalFacts DecimalPos DecimalN DecimalZ QArith.
-Lemma of_to (q:Q) : forall d, to_decimal q = Some d -> of_decimal d = q.
+Lemma of_IQmake_to_decimal num den :
+ match IQmake_to_decimal num den with
+ | None => True
+ | Some (DecimalExp _ _ _) => False
+ | Some (Decimal i f) => of_decimal (Decimal i f) = IQmake (IZ_of_Z num) den
+ end.
Proof.
- cut (match to_decimal q with None => True | Some d => of_decimal d = q end).
- { now case to_decimal; [intros d <- d' Hd'; injection Hd'; intros ->|]. }
- destruct q as (num, den).
- unfold to_decimal; simpl.
- generalize (DecimalPos.Unsigned.nztail_to_uint den).
- case Decimal.nztail; intros u n.
- case u; clear u; [intros; exact I|intros; exact I|intro u|intros; exact I..].
- case u; clear u; [|intros; exact I..].
- unfold Pos.of_uint, Pos.of_uint_acc; rewrite N.mul_1_l.
- case n.
- - unfold of_decimal, app_int, app, Z.to_int; simpl.
- intro H; inversion H as (H1); clear H H1.
- case num; [reflexivity|intro pnum; fold (rev (rev (Pos.to_uint pnum)))..].
- + rewrite rev_rev; simpl.
- now unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to.
- + rewrite rev_rev; simpl.
- now unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to.
- - clear n; intros n H.
- injection H; clear H; intros ->.
- case Nat.ltb.
- + unfold of_decimal.
- rewrite of_to.
- apply f_equal2; [|now simpl].
- unfold app_int, app, Z.to_int; simpl.
- now case num;
- [|intro pnum; fold (rev (rev (Pos.to_uint pnum)));
- rewrite rev_rev; unfold Z.of_int, Z.of_uint;
- rewrite DecimalPos.Unsigned.of_to..].
- + unfold of_decimal; case Nat.ltb_spec; intro Hn; simpl.
- * rewrite nb_digits_del_head; [|now apply Nat.le_sub_l].
- rewrite Nat2Z.inj_sub; [|now apply Nat.le_sub_l].
- rewrite Nat2Z.inj_sub; [|now apply le_Sn_le].
- rewrite Z.sub_sub_distr, Z.sub_diag; simpl.
- rewrite <-(of_to num) at 4.
- now revert Hn; case Z.to_int; clear num; intros pnum Hn; simpl;
- (rewrite app_del_tail_head; [|now apply le_Sn_le]).
- * revert Hn.
- set (anum := match Z.to_int num with Pos i => i | _ => _ end).
- intro Hn.
- assert (H : exists l, nb_digits anum = S l).
- { exists (Nat.pred (nb_digits anum)); apply S_pred_pos.
- now unfold anum; case num;
- [apply Nat.lt_0_1|
- intro pnum; apply nb_digits_pos, Unsigned.to_uint_nonnil..]. }
- destruct H as (l, Hl); rewrite Hl.
- assert (H : forall n d, (nb_digits (Nat.iter n D0 d) = n + nb_digits d)%nat).
- { now intros n'; induction n'; intro d; [|simpl; rewrite IHn']. }
- rewrite H, Hl.
- rewrite Nat.add_succ_r, Nat.sub_add; [|now apply le_S_n; rewrite <-Hl].
- assert (H' : forall n d, Pos.of_uint (Nat.iter n D0 d) = Pos.of_uint d).
- { now intro n'; induction n'; intro d; [|simpl; rewrite IHn']. }
- now unfold anum; case num; simpl; [|intro pnum..];
- unfold app, Z.of_uint; simpl;
- rewrite H', ?DecimalPos.Unsigned.of_to.
+ unfold IQmake_to_decimal.
+ generalize (Unsigned.nztail_to_uint den).
+ case Decimal.nztail; intros den' e_den'.
+ case den'; [now simpl|now simpl| |now simpl..]; clear den'; intro den'.
+ case den'; [ |now simpl..]; clear den'.
+ case e_den' as [|e_den']; simpl; intro H; injection H; clear H; intros->.
+ { now unfold of_decimal; simpl; rewrite app_int_nil_r, DecimalZ.of_to. }
+ replace (10 ^ _)%positive with (Nat.iter (S e_den') (Pos.mul 10) 1%positive).
+ 2:{ induction e_den' as [|n IHn]; [now simpl| ].
+ now rewrite SuccNat2Pos.inj_succ, Pos.pow_succ_r, <-IHn. }
+ case Nat.ltb_spec; intro He_den'.
+ - unfold of_decimal; simpl.
+ rewrite app_int_del_tail_head; [|now apply Nat.lt_le_incl].
+ rewrite DecimalZ.of_to.
+ now rewrite nb_digits_del_head_sub; [|now apply Nat.lt_le_incl].
+ - unfold of_decimal; simpl.
+ rewrite nb_digits_iter_D0.
+ apply f_equal2.
+ + apply f_equal, DecimalZ.to_int_inj.
+ rewrite DecimalZ.to_of.
+ rewrite <-(DecimalZ.of_to num), DecimalZ.to_of.
+ case (Z.to_int num); clear He_den' num; intro num; simpl.
+ * unfold app; simpl.
+ now rewrite unorm_D0, unorm_iter_D0, unorm_involutive.
+ * case (uint_eq_dec (nzhead num) Nil); [|intro Hn].
+ { intros->; simpl; unfold app; simpl.
+ now rewrite unorm_D0, unorm_iter_D0. }
+ replace (match nzhead num with Nil => _ | _ => _ end)
+ with (Neg (nzhead num)); [|now revert Hn; case nzhead].
+ simpl.
+ rewrite nzhead_iter_D0, nzhead_involutive.
+ now revert Hn; case nzhead.
+ + revert He_den'; case nb_digits as [|n]; [now simpl; rewrite Nat.add_0_r|].
+ intro Hn.
+ rewrite Nat.add_succ_r, Nat.add_comm.
+ now rewrite <-le_plus_minus; [|apply le_S_n].
Qed.
-(* normalize without fractional part, for instance norme 12.3e-1 is 123e-2 *)
-Definition dnorme (d:decimal) : decimal :=
- let '(i, f, e) :=
- match d with
- | Decimal i f => (i, f, Pos Nil)
- | DecimalExp i f e => (i, f, e)
- end in
- let i := norm (app_int i f) in
- let e := norm (Z.to_int (Z.of_int e - Z.of_nat (nb_digits f))) in
- match e with
- | Pos zero => Decimal i Nil
- | _ => DecimalExp i Nil e
+Lemma IZ_of_Z_IZ_to_Z z z' : IZ_to_Z z = Some z' -> IZ_of_Z z' = z.
+Proof. now case z as [| |p|p]; [|intro H; injection H; intros<-..]. Qed.
+
+Lemma of_IQmake_to_decimal' num den :
+ match IQmake_to_decimal' num den with
+ | None => True
+ | Some (DecimalExp _ _ _) => False
+ | Some (Decimal i f) => of_decimal (Decimal i f) = IQmake num den
end.
+Proof.
+ unfold IQmake_to_decimal'.
+ case_eq (IZ_to_Z num); [intros num' Hnum'|now simpl].
+ generalize (of_IQmake_to_decimal num' den).
+ case IQmake_to_decimal as [d|]; [|now simpl].
+ case d as [i f|]; [|now simpl].
+ now rewrite (IZ_of_Z_IZ_to_Z _ _ Hnum').
+Qed.
+
+Lemma of_to (q:IQ) : forall d, to_decimal q = Some d -> of_decimal d = q.
+Proof.
+ intro d.
+ case q as [num den|q q'|q q']; simpl.
+ - generalize (of_IQmake_to_decimal' num den).
+ case IQmake_to_decimal' as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ now intros H H'; injection H'; clear H'; intros <-.
+ - case q as [num den| |]; [|now simpl..].
+ case q' as [num' den'| |]; [|now simpl..].
+ case num' as [z p| | |]; [|now simpl..].
+ case (Z.eq_dec z 10); [intros->|].
+ 2:{ case z; [now simpl| |now simpl]; intro pz'.
+ case pz'; [intros d0..| ]; [now simpl| |now simpl].
+ case d0; [intros d1..| ]; [ |now simpl..].
+ case d1; [intros d2..| ]; [now simpl| |now simpl].
+ now case d2. }
+ case (Pos.eq_dec den' 1%positive); [intros->|now case den'].
+ generalize (of_IQmake_to_decimal' num den).
+ case IQmake_to_decimal' as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ intros <-; clear num den.
+ intros H; injection H; clear H; intros<-.
+ unfold of_decimal; simpl.
+ now unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
+ - case q as [num den| |]; [|now simpl..].
+ case q' as [num' den'| |]; [|now simpl..].
+ case num' as [z p| | |]; [|now simpl..].
+ case (Z.eq_dec z 10); [intros->|].
+ 2:{ case z; [now simpl| |now simpl]; intro pz'.
+ case pz'; [intros d0..| ]; [now simpl| |now simpl].
+ case d0; [intros d1..| ]; [ |now simpl..].
+ case d1; [intros d2..| ]; [now simpl| |now simpl].
+ now case d2. }
+ case (Pos.eq_dec den' 1%positive); [intros->|now case den'].
+ generalize (of_IQmake_to_decimal' num den).
+ case IQmake_to_decimal' as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ intros <-; clear num den.
+ intros H; injection H; clear H; intros<-.
+ unfold of_decimal; simpl.
+ now unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
+Qed.
-(* normalize without exponent part, for instance norme 12.3e-1 is 1.23 *)
-Definition dnormf (d:decimal) : decimal :=
- match dnorme d with
- | Decimal i _ => Decimal i Nil
- | DecimalExp i _ e =>
- match Z.of_int e with
- | Z0 => Decimal i Nil
- | Zpos e => Decimal (norm (app_int i (Pos.iter D0 Nil e))) Nil
- | Zneg e =>
- let ne := Pos.to_nat e in
- let ai := match i with Pos d | Neg d => d end in
- let ni := nb_digits ai in
- if ne <? ni then
- Decimal (del_tail_int ne i) (del_head (ni - ne) ai)
- else
- let z := match i with Pos _ => Pos zero | Neg _ => Neg zero end in
- Decimal z (Nat.iter (ne - ni) D0 ai)
+Definition dnorm (d:decimal) : decimal :=
+ let norm_i i f :=
+ match i with
+ | Pos i => Pos (unorm i)
+ | Neg i => match nzhead (app i f) with Nil => Pos zero | _ => Neg (unorm i) end
+ end in
+ match d with
+ | Decimal i f => Decimal (norm_i i f) f
+ | DecimalExp i f e =>
+ match norm e with
+ | Pos zero => Decimal (norm_i i f) f
+ | e => DecimalExp (norm_i i f) f e
end
end.
-Lemma dnorme_spec d :
- match dnorme d with
- | Decimal i Nil => i = norm i
- | DecimalExp i Nil e => i = norm i /\ e = norm e /\ e <> Pos zero
- | _ => False
+Lemma dnorm_spec_i d :
+ let (i, f) :=
+ match d with Decimal i f => (i, f) | DecimalExp i f _ => (i, f) end in
+ let i' := match dnorm d with Decimal i _ => i | DecimalExp i _ _ => i end in
+ match i with
+ | Pos i => i' = Pos (unorm i)
+ | Neg i =>
+ (i' = Neg (unorm i) /\ (nzhead i <> Nil \/ nzhead f <> Nil))
+ \/ (i' = Pos zero /\ (nzhead i = Nil /\ nzhead f = Nil))
end.
Proof.
- case d; clear d; intros i f; [|intro e]; unfold dnorme; simpl.
- - set (e' := Z.to_int _).
- case (int_eq_dec (norm e') (Pos zero)); [intros->|intro Hne'].
- + now rewrite norm_invol.
- + set (r := DecimalExp _ _ _).
- set (m := match norm e' with Pos zero => _ | _ => _ end).
- replace m with r; [now unfold r; rewrite !norm_invol|].
- unfold m; revert Hne'; case (norm e'); intro e''; [|now simpl].
- now case e''; [|intro e'''; case e'''..].
- - set (e' := Z.to_int _).
- case (int_eq_dec (norm e') (Pos zero)); [intros->|intro Hne'].
- + now rewrite norm_invol.
- + set (r := DecimalExp _ _ _).
- set (m := match norm e' with Pos zero => _ | _ => _ end).
- replace m with r; [now unfold r; rewrite !norm_invol|].
- unfold m; revert Hne'; case (norm e'); intro e''; [|now simpl].
- now case e''; [|intro e'''; case e'''..].
+ case d as [i f|i f e]; case i as [i|i].
+ - now simpl.
+ - simpl; case (uint_eq_dec (nzhead (app i f)) Nil); intro Ha.
+ + rewrite Ha; right; split; [now simpl|split].
+ * now unfold unorm; rewrite (nzhead_app_nil_l _ _ Ha).
+ * now unfold unorm; rewrite (nzhead_app_nil_r _ _ Ha).
+ + left; split; [now revert Ha; case nzhead|].
+ case (uint_eq_dec (nzhead i) Nil).
+ * intro Hi; right; intro Hf; apply Ha.
+ now rewrite <-nzhead_app_nzhead, Hi, app_nil_l.
+ * now intro H; left.
+ - simpl; case (norm e); clear e; intro e; [|now simpl].
+ now case e; clear e; [|intro e..]; [|case e|..].
+ - simpl.
+ set (m := match nzhead _ with Nil => _ | _ => _ end).
+ set (m' := match _ with Decimal _ _ => _ | _ => _ end).
+ replace m' with m.
+ 2:{ unfold m'; case (norm e); clear m' e; intro e; [|now simpl].
+ now case e; clear e; [|intro e..]; [|case e|..]. }
+ unfold m; case (uint_eq_dec (nzhead (app i f)) Nil); intro Ha.
+ + rewrite Ha; right; split; [now simpl|split].
+ * now unfold unorm; rewrite (nzhead_app_nil_l _ _ Ha).
+ * now unfold unorm; rewrite (nzhead_app_nil_r _ _ Ha).
+ + left; split; [now revert Ha; case nzhead|].
+ case (uint_eq_dec (nzhead i) Nil).
+ * intro Hi; right; intro Hf; apply Ha.
+ now rewrite <-nzhead_app_nzhead, Hi, app_nil_l.
+ * now intro H; left.
+Qed.
+
+Lemma dnorm_spec_f d :
+ let f := match d with Decimal _ f => f | DecimalExp _ f _ => f end in
+ let f' := match dnorm d with Decimal _ f => f | DecimalExp _ f _ => f end in
+ f' = f.
+Proof.
+ case d as [i f|i f e]; [now simpl|].
+ simpl; case (int_eq_dec (norm e) (Pos zero)); [now intros->|intro He].
+ set (i' := match i with Pos _ => _ | _ => _ end).
+ set (m := match norm e with Pos Nil => _ | _ => _ end).
+ replace m with (DecimalExp i' f (norm e)); [now simpl|].
+ unfold m; revert He; case (norm e); clear m e; intro e; [|now simpl].
+ now case e; clear e; [|intro e; case e|..].
Qed.
-Lemma dnormf_spec d :
- match dnormf d with
- | Decimal i f => i = Neg zero \/ i = norm i
- | _ => False
+Lemma dnorm_spec_e d :
+ match d, dnorm d with
+ | Decimal _ _, Decimal _ _ => True
+ | DecimalExp _ _ e, Decimal _ _ => norm e = Pos zero
+ | DecimalExp _ _ e, DecimalExp _ _ e' => e' = norm e /\ e' <> Pos zero
+ | Decimal _ _, DecimalExp _ _ _ => False
end.
Proof.
- case d; clear d; intros i f; [|intro e]; unfold dnormf, dnorme; simpl.
- - set (e' := Z.to_int _).
- case (int_eq_dec (norm e') (Pos zero)); [intros->|intro Hne'].
- + now right; rewrite norm_invol.
- + set (r := DecimalExp _ _ _).
- set (m := match norm e' with Pos zero => _ | _ => _ end).
- assert (H : m = r); [|rewrite H; unfold m, r; clear m r H].
- { unfold m; revert Hne'; case (norm e'); intro e''; [|now simpl].
- now case e''; [|intro e'''; case e'''..]. }
- rewrite <-DecimalZ.to_of, DecimalZ.of_to.
- case_eq (Z.of_int e'); [|intros pe'..]; intro Hpe';
- [now right; rewrite norm_invol..|].
- case Nat.ltb_spec.
- * now intro H; rewrite (norm_del_tail_int_norm _ _ H); right.
- * now intros _; case norm; intros _; [right|left].
- - set (e' := Z.to_int _).
- case (int_eq_dec (norm e') (Pos zero)); [intros->|intro Hne'].
- + now right; rewrite norm_invol.
- + set (r := DecimalExp _ _ _).
- set (m := match norm e' with Pos zero => _ | _ => _ end).
- assert (H : m = r); [|rewrite H; unfold m, r; clear m r H].
- { unfold m; revert Hne'; case (norm e'); intro e''; [|now simpl].
- now case e''; [|intro e'''; case e'''..]. }
- rewrite <-DecimalZ.to_of, DecimalZ.of_to.
- case_eq (Z.of_int e'); [|intros pe'..]; intro Hpe';
- [now right; rewrite norm_invol..|].
- case Nat.ltb_spec.
- * now intro H; rewrite (norm_del_tail_int_norm _ _ H); right.
- * now intros _; case norm; intros _; [right|left].
+ case d as [i f|i f e]; [now simpl|].
+ simpl; case (int_eq_dec (norm e) (Pos zero)); [now intros->|intro He].
+ set (i' := match i with Pos _ => _ | _ => _ end).
+ set (m := match norm e with Pos Nil => _ | _ => _ end).
+ replace m with (DecimalExp i' f (norm e)); [now simpl|].
+ unfold m; revert He; case (norm e); clear m e; intro e; [|now simpl].
+ now case e; clear e; [|intro e; case e|..].
Qed.
-Lemma dnorme_invol d : dnorme (dnorme d) = dnorme d.
+Lemma dnorm_involutive d : dnorm (dnorm d) = dnorm d.
Proof.
- case d; clear d; intros i f; [|intro e]; unfold dnorme; simpl.
- - set (e' := Z.to_int _).
- case (int_eq_dec (norm e') (Pos zero)); intro Hne'.
- + rewrite Hne'; simpl; rewrite app_int_nil_r, norm_invol.
- revert Hne'.
- rewrite <-to_of.
- change (Pos zero) with (Z.to_int 0).
- intro H; generalize (to_int_inj _ _ H); clear H.
- unfold e'; rewrite DecimalZ.of_to.
- now case f; [rewrite app_int_nil_r|..].
- + set (r := DecimalExp _ _ _).
- set (m := match norm e' with Pos zero => _ | _ => _ end).
- assert (H : m = r); [|rewrite H; unfold m, r; clear m r H].
- { unfold m; revert Hne'; case (norm e'); intro e''; [|now simpl].
- now case e''; [|intro e'''; case e'''..]. }
- rewrite <-DecimalZ.to_of, DecimalZ.of_to.
- unfold nb_digits, Z.of_nat; rewrite Z.sub_0_r, to_of, norm_invol.
- rewrite app_int_nil_r, norm_invol.
- set (r := DecimalExp _ _ _).
- set (m := match norm e' with Pos zero => _ | _ => _ end).
- unfold m; revert Hne'; case (norm e'); intro e''; [|now simpl].
- now case e''; [|intro e'''; case e'''..].
- - set (e' := Z.to_int _).
- case (int_eq_dec (norm e') (Pos zero)); intro Hne'.
- + rewrite Hne'; simpl; rewrite app_int_nil_r, norm_invol.
- revert Hne'.
- rewrite <-to_of.
- change (Pos zero) with (Z.to_int 0).
- intro H; generalize (to_int_inj _ _ H); clear H.
- unfold e'; rewrite DecimalZ.of_to.
- now case f; [rewrite app_int_nil_r|..].
- + set (r := DecimalExp _ _ _).
- set (m := match norm e' with Pos zero => _ | _ => _ end).
- assert (H : m = r); [|rewrite H; unfold m, r; clear m r H].
- { unfold m; revert Hne'; case (norm e'); intro e''; [|now simpl].
- now case e''; [|intro e'''; case e'''..]. }
- rewrite <-DecimalZ.to_of, DecimalZ.of_to.
- unfold nb_digits, Z.of_nat; rewrite Z.sub_0_r, to_of, norm_invol.
- rewrite app_int_nil_r, norm_invol.
- set (r := DecimalExp _ _ _).
- set (m := match norm e' with Pos zero => _ | _ => _ end).
- unfold m; revert Hne'; case (norm e'); intro e''; [|now simpl].
- now case e''; [|intro e'''; case e'''..].
+ case d as [i f|i f e]; case i as [i|i].
+ - now simpl; rewrite unorm_involutive.
+ - simpl; case (uint_eq_dec (nzhead (app i f)) Nil); [now intros->|intro Ha].
+ set (m := match nzhead _ with Nil =>_ | _ => _ end).
+ replace m with (Neg (unorm i)).
+ 2:{ now unfold m; revert Ha; case nzhead. }
+ case (uint_eq_dec (nzhead i) Nil); intro Hi.
+ + unfold unorm; rewrite Hi; simpl.
+ case (uint_eq_dec (nzhead f) Nil).
+ * intro Hf; exfalso; apply Ha.
+ now rewrite <-nzhead_app_nzhead, Hi, app_nil_l.
+ * now case nzhead.
+ + rewrite unorm_involutive, (unorm_nzhead _ Hi), nzhead_app_nzhead.
+ now revert Ha; case nzhead.
+ - simpl; case (int_eq_dec (norm e) (Pos zero)); intro He.
+ + now rewrite He; simpl; rewrite unorm_involutive.
+ + set (m := match norm e with Pos Nil => _ | _ => _ end).
+ replace m with (DecimalExp (Pos (unorm i)) f (norm e)).
+ 2:{ unfold m; revert He; case (norm e); clear m e; intro e; [|now simpl].
+ now case e; clear e; [|intro e; case e|..]. }
+ simpl; rewrite norm_involutive, unorm_involutive.
+ revert He; case (norm e); clear m e; intro e; [|now simpl].
+ now case e; clear e; [|intro e; case e|..].
+ - simpl; case (int_eq_dec (norm e) (Pos zero)); intro He.
+ + rewrite He; simpl.
+ case (uint_eq_dec (nzhead (app i f)) Nil); [now intros->|intro Ha].
+ set (m := match nzhead _ with Nil =>_ | _ => _ end).
+ replace m with (Neg (unorm i)).
+ 2:{ now unfold m; revert Ha; case nzhead. }
+ case (uint_eq_dec (nzhead i) Nil); intro Hi.
+ * unfold unorm; rewrite Hi; simpl.
+ case (uint_eq_dec (nzhead f) Nil).
+ -- intro Hf; exfalso; apply Ha.
+ now rewrite <-nzhead_app_nzhead, Hi, app_nil_l.
+ -- now case nzhead.
+ * rewrite unorm_involutive, (unorm_nzhead _ Hi), nzhead_app_nzhead.
+ now revert Ha; case nzhead.
+ + set (m := match norm e with Pos Nil => _ | _ => _ end).
+ pose (i' := match nzhead (app i f) with Nil => Pos zero | _ => Neg (unorm i) end).
+ replace m with (DecimalExp i' f (norm e)).
+ 2:{ unfold m; revert He; case (norm e); clear m e; intro e; [|now simpl].
+ now case e; clear e; [|intro e; case e|..]. }
+ simpl; rewrite norm_involutive.
+ set (i'' := match i' with Pos _ => _ | _ => _ end).
+ clear m; set (m := match norm e with Pos Nil => _ | _ => _ end).
+ replace m with (DecimalExp i'' f (norm e)).
+ 2:{ unfold m; revert He; case (norm e); clear m e; intro e; [|now simpl].
+ now case e; clear e; [|intro e; case e|..]. }
+ unfold i'', i'.
+ case (uint_eq_dec (nzhead (app i f)) Nil); [now intros->|intro Ha].
+ fold i'; replace i' with (Neg (unorm i)).
+ 2:{ now unfold i'; revert Ha; case nzhead. }
+ case (uint_eq_dec (nzhead i) Nil); intro Hi.
+ * unfold unorm; rewrite Hi; simpl.
+ case (uint_eq_dec (nzhead f) Nil).
+ -- intro Hf; exfalso; apply Ha.
+ now rewrite <-nzhead_app_nzhead, Hi, app_nil_l.
+ -- now case nzhead.
+ * rewrite unorm_involutive, (unorm_nzhead _ Hi), nzhead_app_nzhead.
+ now revert Ha; case nzhead.
Qed.
-Lemma dnormf_invol d : dnormf (dnormf d) = dnormf d.
+Lemma IZ_to_Z_IZ_of_Z z : IZ_to_Z (IZ_of_Z z) = Some z.
+Proof. now case z. Qed.
+
+Lemma dnorm_i_exact i f :
+ (nb_digits f < nb_digits (unorm (app (abs i) f)))%nat ->
+ match i with
+ | Pos i => Pos (unorm i)
+ | Neg i =>
+ match nzhead (app i f) with
+ | Nil => Pos zero
+ | _ => Neg (unorm i)
+ end
+ end = norm i.
Proof.
- case d; clear d; intros i f; [|intro e]; unfold dnormf, dnorme; simpl.
- - set (e' := Z.to_int _).
- case (int_eq_dec (norm e') (Pos zero)); intro Hne'.
- + rewrite Hne'; simpl; rewrite app_int_nil_r, norm_invol.
- revert Hne'.
- rewrite <-to_of.
- change (Pos zero) with (Z.to_int 0).
- intro H; generalize (to_int_inj _ _ H); clear H.
- unfold e'; rewrite DecimalZ.of_to.
- now case f; [rewrite app_int_nil_r|..].
- + set (r := DecimalExp _ _ _).
- set (m := match norm e' with Pos zero => _ | _ => _ end).
- assert (H : m = r); [|rewrite H; unfold m, r; clear m r H].
- { unfold m; revert Hne'; case (norm e'); intro e''; [|now simpl].
- now case e''; [|intro e'''; case e'''..]. }
- rewrite of_int_norm.
- case_eq (Z.of_int e'); [|intro pe'..]; intro Hnpe';
- [now simpl; rewrite app_int_nil_r, norm_invol..|].
- case Nat.ltb_spec; intro Hpe'.
- * rewrite nb_digits_del_head; [|now apply Nat.le_sub_l].
- rewrite Nat2Z.inj_sub; [|now apply Nat.le_sub_l].
- rewrite Nat2Z.inj_sub; [|now apply Nat.lt_le_incl].
- simpl.
- rewrite Z.sub_sub_distr, Z.sub_diag, Z.add_0_l.
- rewrite <-DecimalZ.to_of, DecimalZ.of_to.
- rewrite positive_nat_Z; simpl.
- unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
- rewrite app_int_del_tail_head; [|now apply Nat.lt_le_incl].
- now rewrite norm_invol, (proj2 (Nat.ltb_lt _ _) Hpe').
- * simpl.
- rewrite nb_digits_iter_D0.
- rewrite (Nat.sub_add _ _ Hpe').
- rewrite <-DecimalZ.to_of, DecimalZ.of_to.
- rewrite positive_nat_Z; simpl.
- unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
- revert Hpe'.
- set (i' := norm (app_int i f)).
- case_eq i'; intros u Hu Hpe'.
- ++ simpl; unfold app; simpl.
- rewrite unorm_D0, unorm_iter_D0.
- assert (Hu' : unorm u = u).
- { generalize (f_equal norm Hu).
- unfold i'; rewrite norm_invol; fold i'.
- now simpl; rewrite Hu; intro H; injection H. }
- now rewrite Hu', (proj2 (Nat.ltb_ge _ _) Hpe').
- ++ simpl; rewrite nzhead_iter_D0.
- assert (Hu' : nzhead u = u).
- { generalize (f_equal norm Hu).
- unfold i'; rewrite norm_invol; fold i'.
- now rewrite Hu; simpl; case (nzhead u); [|intros u' H; injection H..]. }
- rewrite Hu'.
- assert (Hu'' : u <> Nil).
- { intro H; revert Hu; rewrite H; unfold i'.
- now case app_int; intro u'; [|simpl; case nzhead]. }
- set (m := match u with Nil => Pos zero | _ => _ end).
- assert (H : m = Neg u); [|rewrite H; clear m H].
- { now revert Hu''; unfold m; case u. }
- now rewrite (proj2 (Nat.ltb_ge _ _) Hpe').
- - set (e' := Z.to_int _).
- case (int_eq_dec (norm e') (Pos zero)); intro Hne'.
- + rewrite Hne'; simpl; rewrite app_int_nil_r, norm_invol.
- revert Hne'.
- rewrite <-to_of.
- change (Pos zero) with (Z.to_int 0).
- intro H; generalize (to_int_inj _ _ H); clear H.
- unfold e'; rewrite DecimalZ.of_to.
- now case f; [rewrite app_int_nil_r|..].
- + set (r := DecimalExp _ _ _).
- set (m := match norm e' with Pos zero => _ | _ => _ end).
- assert (H : m = r); [|rewrite H; unfold m, r; clear m r H].
- { unfold m; revert Hne'; case (norm e'); intro e''; [|now simpl].
- now case e''; [|intro e'''; case e'''..]. }
- rewrite of_int_norm.
- case_eq (Z.of_int e'); [|intro pe'..]; intro Hnpe';
- [now simpl; rewrite app_int_nil_r, norm_invol..|].
- case Nat.ltb_spec; intro Hpe'.
- * rewrite nb_digits_del_head; [|now apply Nat.le_sub_l].
- rewrite Nat2Z.inj_sub; [|now apply Nat.le_sub_l].
- rewrite Nat2Z.inj_sub; [|now apply Nat.lt_le_incl].
- simpl.
- rewrite Z.sub_sub_distr, Z.sub_diag, Z.add_0_l.
- rewrite <-DecimalZ.to_of, DecimalZ.of_to.
- rewrite positive_nat_Z; simpl.
- unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
- rewrite app_int_del_tail_head; [|now apply Nat.lt_le_incl].
- now rewrite norm_invol, (proj2 (Nat.ltb_lt _ _) Hpe').
- * simpl.
- rewrite nb_digits_iter_D0.
- rewrite (Nat.sub_add _ _ Hpe').
- rewrite <-DecimalZ.to_of, DecimalZ.of_to.
- rewrite positive_nat_Z; simpl.
- unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
- revert Hpe'.
- set (i' := norm (app_int i f)).
- case_eq i'; intros u Hu Hpe'.
- ++ simpl; unfold app; simpl.
- rewrite unorm_D0, unorm_iter_D0.
- assert (Hu' : unorm u = u).
- { generalize (f_equal norm Hu).
- unfold i'; rewrite norm_invol; fold i'.
- now simpl; rewrite Hu; intro H; injection H. }
- now rewrite Hu', (proj2 (Nat.ltb_ge _ _) Hpe').
- ++ simpl; rewrite nzhead_iter_D0.
- assert (Hu' : nzhead u = u).
- { generalize (f_equal norm Hu).
- unfold i'; rewrite norm_invol; fold i'.
- now rewrite Hu; simpl; case (nzhead u); [|intros u' H; injection H..]. }
- rewrite Hu'.
- assert (Hu'' : u <> Nil).
- { intro H; revert Hu; rewrite H; unfold i'.
- now case app_int; intro u'; [|simpl; case nzhead]. }
- set (m := match u with Nil => Pos zero | _ => _ end).
- assert (H : m = Neg u); [|rewrite H; clear m H].
- { now revert Hu''; unfold m; case u. }
- now rewrite (proj2 (Nat.ltb_ge _ _) Hpe').
+ case i as [ni|ni]; [now simpl|]; simpl.
+ case (uint_eq_dec (nzhead (app ni f)) Nil); intro Ha.
+ { now rewrite Ha, (nzhead_app_nil_l _ _ Ha). }
+ rewrite (unorm_nzhead _ Ha).
+ set (m := match nzhead _ with Nil => _ | _ => _ end).
+ replace m with (Neg (unorm ni)); [|now unfold m; revert Ha; case nzhead].
+ case (uint_eq_dec (nzhead ni) Nil); intro Hni.
+ { rewrite <-nzhead_app_nzhead, Hni, app_nil_l.
+ intro H; exfalso; revert H; apply le_not_lt, nb_digits_nzhead. }
+ clear m; set (m := match nzhead ni with Nil => _ | _ => _ end).
+ replace m with (Neg (nzhead ni)); [|now unfold m; revert Hni; case nzhead].
+ now rewrite (unorm_nzhead _ Hni).
+Qed.
+
+Lemma dnorm_i_exact' i f :
+ (nb_digits (unorm (app (abs i) f)) <= nb_digits f)%nat ->
+ match i with
+ | Pos i => Pos (unorm i)
+ | Neg i =>
+ match nzhead (app i f) with
+ | Nil => Pos zero
+ | _ => Neg (unorm i)
+ end
+ end =
+ match norm (app_int i f) with
+ | Pos _ => Pos zero
+ | Neg _ => Neg zero
+ end.
+Proof.
+ case i as [ni|ni]; simpl.
+ { now intro Hnb; rewrite (unorm_app_zero _ _ Hnb). }
+ unfold unorm.
+ case (uint_eq_dec (nzhead (app ni f)) Nil); intro Hn.
+ { now rewrite Hn. }
+ set (m := match nzhead _ with Nil => _ | _ => _ end).
+ replace m with (nzhead (app ni f)).
+ 2:{ now unfold m; revert Hn; case nzhead. }
+ clear m; set (m := match nzhead _ with Nil => _ | _ => _ end).
+ replace m with (Neg (unorm ni)).
+ 2:{ now unfold m, unorm; revert Hn; case nzhead. }
+ clear m; set (m := match nzhead _ with Nil => _ | _ => _ end).
+ replace m with (Neg (nzhead (app ni f))).
+ 2:{ now unfold m; revert Hn; case nzhead. }
+ rewrite <-(unorm_nzhead _ Hn).
+ now intro H; rewrite (unorm_app_zero _ _ H).
Qed.
-Lemma to_of (d:decimal) :
- to_decimal (of_decimal d) = Some (dnorme d)
- \/ to_decimal (of_decimal d) = Some (dnormf d).
+Lemma to_of (d:decimal) : to_decimal (of_decimal d) = Some (dnorm d).
Proof.
- unfold to_decimal.
- pose (t10 := fun y => ((y + y~0~0)~0)%positive).
- assert (H : exists e_den,
- Decimal.nztail (Pos.to_uint (Qden (of_decimal d))) = (D1 Nil, e_den)).
- { assert (H : forall p,
- Decimal.nztail (Pos.to_uint (Pos.iter t10 1%positive p))
- = (D1 Nil, Pos.to_nat p)).
- { intro p; rewrite Pos2Nat.inj_iter.
- fold (Nat.iter (Pos.to_nat p) t10 1%positive).
- induction (Pos.to_nat p); [now simpl|].
- rewrite DecimalPos.Unsigned.nat_iter_S.
- unfold Pos.to_uint.
- change (Pos.to_little_uint _)
- with (Unsigned.to_lu (10 * N.pos (Nat.iter n t10 1%positive))).
- rewrite Unsigned.to_ldec_tenfold.
- revert IHn; unfold Pos.to_uint.
- unfold Decimal.nztail; rewrite !rev_rev; simpl.
- set (f'' := _ (Pos.to_little_uint _)).
- now case f''; intros r n' H; inversion H. }
- case d; intros i f; [|intro e]; unfold of_decimal; simpl.
- - case (- Z.of_nat _)%Z; [|intro p..]; simpl; [now exists O..|].
- exists (Pos.to_nat p); apply H.
- - case (_ - _)%Z; [|intros p..]; simpl; [now exists O..|].
- exists (Pos.to_nat p); apply H. }
- generalize (DecimalPos.Unsigned.nztail_to_uint (Qden (of_decimal d))).
- destruct H as (e, He); rewrite He; clear He; simpl.
- assert (Hn1 : forall p, N.pos (Pos.iter t10 1%positive p) = 1%N -> False).
- { intro p.
- rewrite Pos2Nat.inj_iter.
- case_eq (Pos.to_nat p); [|now simpl].
- intro H; exfalso; apply (lt_irrefl O).
- rewrite <-H at 2; apply Pos2Nat.is_pos. }
- assert (Ht10inj : forall n m, t10 n = t10 m -> n = m).
- { intros n m H; generalize (f_equal Z.pos H); clear H.
- change (Z.pos (t10 n)) with (Z.mul 10 (Z.pos n)).
- change (Z.pos (t10 m)) with (Z.mul 10 (Z.pos m)).
- rewrite Z.mul_comm, (Z.mul_comm 10).
- intro H; generalize (f_equal (fun z => Z.div z 10) H); clear H.
- now rewrite !Z.div_mul; [|now simpl..]; intro H; inversion H. }
- assert (Hinj : forall n m,
- Nat.iter n t10 1%positive = Nat.iter m t10 1%positive -> n = m).
- { induction n; [now intro m; case m|].
- intro m; case m; [now simpl|]; clear m; intro m.
- rewrite !Unsigned.nat_iter_S.
- intro H; generalize (Ht10inj _ _ H); clear H; intro H.
- now rewrite (IHn _ H). }
- case e; clear e; [|intro e]; simpl; unfold of_decimal, dnormf, dnorme.
- - case d; clear d; intros i f; [|intro e]; simpl.
- + intro H; left; revert H.
- generalize (nb_digits_pos f).
- case f;
- [|now clear f; intro f; intros H1 H2; exfalso; revert H1 H2;
- case nb_digits; simpl;
- [intros H _; apply (lt_irrefl O), H|intros n _; apply Hn1]..].
- now intros _ _; simpl; rewrite to_of.
- + intro H; right; revert H.
- rewrite <-to_of, DecimalZ.of_to.
- set (emf := (_ - _)%Z).
- case_eq emf; [|intro pemf..].
- * now simpl; rewrite to_of.
- * set (r := DecimalExp _ _ _).
- set (m := match _ with Pos _ => _ | _ => r end).
- assert (H : m = r).
- { unfold m, Z.to_int.
- generalize (Unsigned.to_uint_nonzero pemf).
- now case Pos.to_uint; [|intro u; case u..]. }
- rewrite H; unfold r; clear H m r.
- rewrite DecimalZ.of_to.
- simpl Qnum.
- intros Hpemf _.
- apply f_equal; apply f_equal2; [|reflexivity].
- rewrite !Pos2Nat.inj_iter.
- set (n := _ pemf).
- fold (Nat.iter n (Z.mul 10) (Z.of_int (app_int i f))).
- fold (Nat.iter n D0 Nil).
- rewrite <-of_int_iter_D0, to_of.
- now rewrite norm_app_int_norm; [|induction n].
- * simpl Qden; intros _ H; exfalso; revert H; apply Hn1.
- - case d; clear d; intros i f; [|intro e']; simpl.
- + case_eq (nb_digits f); [|intros nf' Hnf'];
- [now simpl; intros _ H; exfalso; symmetry in H; revert H; apply Hn1|].
- unfold Z.of_nat, Z.opp.
- simpl Qden.
- intro H; injection H; clear H; unfold Pos.pow.
- rewrite !Pos2Nat.inj_iter.
- intro H; generalize (Hinj _ _ H); clear H; intro H.
- generalize (SuccNat2Pos.inj _ _ ((Pos2Nat.inj _ _ H))); clear H.
- intro He; rewrite <-He; clear e He.
- simpl Qnum.
- case Nat.ltb; [left|right].
- * now rewrite <-to_of, DecimalZ.of_to, to_of.
- * rewrite to_of.
- set (nif := norm _).
- set (anif := match nif with Pos i0 => i0 | _ => _ end).
- set (r := DecimalExp nif Nil _).
- set (m := match _ with Pos _ => _ | _ => r end).
- assert (H : m = r); [|rewrite H; unfold m, r; clear m r H].
- { now unfold m; rewrite <-to_of, DecimalZ.of_to. }
- rewrite <-to_of, !DecimalZ.of_to.
- fold anif.
- now rewrite SuccNat2Pos.id_succ.
- + set (nemf := (_ - _)%Z); intro H.
- assert (H' : exists pnemf, nemf = Z.neg pnemf); [|revert H].
- { revert H; case nemf; [|intro pnemf..]; [..|now intros _; exists pnemf];
- simpl Qden; intro H; exfalso; symmetry in H; revert H; apply Hn1. }
- destruct H' as (pnemf,Hpnemf); rewrite Hpnemf.
- simpl Qden.
- intro H; injection H; clear H; unfold Pos.pow; rewrite !Pos2Nat.inj_iter.
- intro H; generalize (Hinj _ _ H); clear H; intro H.
- generalize (Pos2Nat.inj _ _ H); clear H.
- intro H; revert Hpnemf; rewrite H; clear pnemf H; intro Hnemf.
- simpl Qnum.
- case Nat.ltb; [left|right].
- * now rewrite <-to_of, DecimalZ.of_to, to_of.
- * rewrite to_of.
- set (nif := norm _).
- set (anif := match nif with Pos i0 => i0 | _ => _ end).
- set (r := DecimalExp nif Nil _).
- set (m := match _ with Pos _ => _ | _ => r end).
- assert (H : m = r); [|rewrite H; unfold m, r; clear m r H].
- { now unfold m; rewrite <-to_of, DecimalZ.of_to. }
- rewrite <-to_of, !DecimalZ.of_to.
- fold anif.
- now rewrite SuccNat2Pos.id_succ.
+ case d as [i f|i f e].
+ - unfold of_decimal; simpl; unfold IQmake_to_decimal'.
+ rewrite IZ_to_Z_IZ_of_Z.
+ unfold IQmake_to_decimal; simpl.
+ change (fun _ : positive => _) with (Pos.mul 10).
+ rewrite nztail_to_uint_pow10, to_of.
+ case_eq (nb_digits f); [|intro nb]; intro Hnb.
+ + rewrite (nb_digits_0 _ Hnb), app_int_nil_r.
+ case i as [ni|ni]; [now simpl|].
+ rewrite app_nil_r; simpl; unfold unorm.
+ now case (nzhead ni).
+ + rewrite <-Hnb.
+ rewrite abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnb'.
+ * rewrite (del_tail_app_int_exact _ _ Hnb').
+ rewrite (del_head_app_int_exact _ _ Hnb').
+ now rewrite (dnorm_i_exact _ _ Hnb').
+ * rewrite (unorm_app_r _ _ Hnb').
+ rewrite iter_D0_unorm; [|now apply nb_digits_n0; rewrite Hnb].
+ now rewrite dnorm_i_exact'.
+ - unfold of_decimal; simpl.
+ rewrite <-to_of.
+ case (Z.of_int e); clear e; [|intro e..]; simpl.
+ + unfold IQmake_to_decimal'.
+ rewrite IZ_to_Z_IZ_of_Z.
+ unfold IQmake_to_decimal; simpl.
+ change (fun _ : positive => _) with (Pos.mul 10).
+ rewrite nztail_to_uint_pow10, to_of.
+ case_eq (nb_digits f); [|intro nb]; intro Hnb.
+ * rewrite (nb_digits_0 _ Hnb), app_int_nil_r.
+ case i as [ni|ni]; [now simpl|].
+ rewrite app_nil_r; simpl; unfold unorm.
+ now case (nzhead ni).
+ * rewrite <-Hnb.
+ rewrite abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnb'.
+ -- rewrite (del_tail_app_int_exact _ _ Hnb').
+ rewrite (del_head_app_int_exact _ _ Hnb').
+ now rewrite (dnorm_i_exact _ _ Hnb').
+ -- rewrite (unorm_app_r _ _ Hnb').
+ rewrite iter_D0_unorm; [|now apply nb_digits_n0; rewrite Hnb].
+ now rewrite dnorm_i_exact'.
+ + unfold IQmake_to_decimal'.
+ rewrite IZ_to_Z_IZ_of_Z.
+ unfold IQmake_to_decimal; simpl.
+ change (fun _ : positive => _) with (Pos.mul 10).
+ rewrite nztail_to_uint_pow10, to_of.
+ generalize (Unsigned.to_uint_nonzero e); intro He.
+ set (dnorm_i := match i with Pos _ => _ | _ => _ end).
+ set (m := match Pos.to_uint e with Nil => _ | _ => _ end).
+ replace m with (DecimalExp dnorm_i f (Pos (Pos.to_uint e))).
+ 2:{ now unfold m; revert He; case (Pos.to_uint e); [|intro u; case u|..]. }
+ clear m; unfold dnorm_i.
+ case_eq (nb_digits f); [|intro nb]; intro Hnb.
+ * rewrite (nb_digits_0 _ Hnb), app_int_nil_r.
+ case i as [ni|ni]; [now simpl|].
+ rewrite app_nil_r; simpl; unfold unorm.
+ now case (nzhead ni).
+ * rewrite <-Hnb.
+ rewrite abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnb'.
+ -- rewrite (del_tail_app_int_exact _ _ Hnb').
+ rewrite (del_head_app_int_exact _ _ Hnb').
+ now rewrite (dnorm_i_exact _ _ Hnb').
+ -- rewrite (unorm_app_r _ _ Hnb').
+ rewrite iter_D0_unorm; [|now apply nb_digits_n0; rewrite Hnb].
+ now rewrite dnorm_i_exact'.
+ + unfold IQmake_to_decimal'.
+ rewrite IZ_to_Z_IZ_of_Z.
+ unfold IQmake_to_decimal; simpl.
+ change (fun _ : positive => _) with (Pos.mul 10).
+ rewrite nztail_to_uint_pow10, to_of.
+ case_eq (nb_digits f); [|intro nb]; intro Hnb.
+ * rewrite (nb_digits_0 _ Hnb), app_int_nil_r.
+ case i as [ni|ni]; [now simpl|].
+ rewrite app_nil_r; simpl; unfold unorm.
+ now case (nzhead ni).
+ * rewrite <-Hnb.
+ rewrite abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnb'.
+ -- rewrite (del_tail_app_int_exact _ _ Hnb').
+ rewrite (del_head_app_int_exact _ _ Hnb').
+ now rewrite (dnorm_i_exact _ _ Hnb').
+ -- rewrite (unorm_app_r _ _ Hnb').
+ rewrite iter_D0_unorm; [|now apply nb_digits_n0; rewrite Hnb].
+ now rewrite dnorm_i_exact'.
Qed.
(** Some consequences *)
@@ -478,84 +436,24 @@ Proof.
now intros d _ H1 H2; rewrite <-(H1 d eq_refl), <-(H2 d eq_refl).
Qed.
-Lemma to_decimal_surj d :
- exists q, to_decimal q = Some (dnorme d) \/ to_decimal q = Some (dnormf d).
+Lemma to_decimal_surj d : exists q, to_decimal q = Some (dnorm d).
Proof.
exists (of_decimal d). apply to_of.
Qed.
-Lemma of_decimal_dnorme d : of_decimal (dnorme d) = of_decimal d.
+Lemma of_decimal_dnorm d : of_decimal (dnorm d) = of_decimal d.
+Proof. now apply to_decimal_inj; rewrite !to_of; [|rewrite dnorm_involutive]. Qed.
+
+Lemma of_inj d d' : of_decimal d = of_decimal d' -> dnorm d = dnorm d'.
Proof.
- unfold of_decimal, dnorme.
- destruct d.
- - rewrite <-DecimalZ.to_of, DecimalZ.of_to; simpl.
- case_eq (nb_digits f); [|intro nf]; intro Hnf.
- + now simpl; rewrite app_int_nil_r, <-DecimalZ.to_of, DecimalZ.of_to.
- + simpl; rewrite Z.sub_0_r.
- unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
- rewrite app_int_nil_r.
- now rewrite <-DecimalZ.to_of, DecimalZ.of_to.
- - rewrite <-DecimalZ.to_of, DecimalZ.of_to; simpl.
- set (emf := (_ - _)%Z).
- case_eq emf; [|intro pemf..]; intro Hemf.
- + now simpl; rewrite app_int_nil_r, <-DecimalZ.to_of, DecimalZ.of_to.
- + simpl.
- set (r := DecimalExp _ Nil _).
- set (m := match Pos.to_uint pemf with zero => _ | _ => r end).
- assert (H : m = r); [|rewrite H; unfold r; clear m r H].
- { generalize (Unsigned.to_uint_nonzero pemf).
- now unfold m; case Pos.to_uint; [|intro u; case u|..]. }
- simpl; rewrite Z.sub_0_r.
- unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
- rewrite app_int_nil_r.
- now rewrite <-DecimalZ.to_of, DecimalZ.of_to.
- + simpl.
- unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
- rewrite app_int_nil_r.
- now rewrite <-DecimalZ.to_of, DecimalZ.of_to.
+ intro H.
+ apply (@f_equal _ _ (fun x => match x with Some x => x | _ => d end)
+ (Some (dnorm d)) (Some (dnorm d'))).
+ now rewrite <- !to_of, H.
Qed.
-Lemma of_decimal_dnormf d : of_decimal (dnormf d) = of_decimal d.
+Lemma of_iff d d' : of_decimal d = of_decimal d' <-> dnorm d = dnorm d'.
Proof.
- rewrite <-(of_decimal_dnorme d).
- unfold of_decimal, dnormf.
- assert (H : match dnorme d with Decimal _ f | DecimalExp _ f _ => f end = Nil).
- { now unfold dnorme; destruct d;
- (case norm; intro d; [case d; [|intro u; case u|..]|]). }
- revert H; generalize (dnorme d); clear d; intro d.
- destruct d; intro H; rewrite H; clear H; [now simpl|].
- case (Z.of_int e); clear e; [|intro e..].
- - now simpl.
- - simpl.
- rewrite app_int_nil_r.
- apply f_equal2; [|reflexivity].
- rewrite app_int_nil_r.
- rewrite <-DecimalZ.to_of, DecimalZ.of_to.
- rewrite !Pos2Nat.inj_iter.
- fold (Nat.iter (Pos.to_nat e) D0 Nil).
- now rewrite of_int_iter_D0.
- - simpl.
- set (ai := match i with Pos _ => _ | _ => _ end).
- rewrite app_int_nil_r.
- case Nat.ltb_spec; intro Hei; simpl.
- + rewrite nb_digits_del_head; [|now apply Nat.le_sub_l].
- rewrite Nat2Z.inj_sub; [|now apply Nat.le_sub_l].
- rewrite Nat2Z.inj_sub; [|now apply le_Sn_le].
- rewrite Z.sub_sub_distr, Z.sub_diag; simpl.
- rewrite positive_nat_Z; simpl.
- now revert Hei; unfold ai; case i; clear i ai; intros i Hei; simpl;
- (rewrite app_del_tail_head; [|now apply le_Sn_le]).
- + set (n := nb_digits _).
- assert (H : (n = Pos.to_nat e - nb_digits ai + nb_digits ai)%nat).
- { unfold n; induction (_ - _)%nat; [now simpl|].
- now rewrite Unsigned.nat_iter_S; simpl; rewrite IHn0. }
- rewrite H; clear n H.
- rewrite Nat2Z.inj_add, (Nat2Z.inj_sub _ _ Hei).
- rewrite <-Z.sub_sub_distr, Z.sub_diag, Z.sub_0_r.
- rewrite positive_nat_Z; simpl.
- rewrite <-(DecimalZ.of_to (Z.of_int (app_int _ _))), DecimalZ.to_of.
- rewrite <-(DecimalZ.of_to (Z.of_int i)), DecimalZ.to_of.
- apply f_equal2; [|reflexivity]; apply f_equal.
- now unfold ai; case i; clear i ai Hei; intro i;
- (induction (_ - _)%nat; [|rewrite <-IHn]).
+ split. apply of_inj. intros E. rewrite <- of_decimal_dnorm, E.
+ apply of_decimal_dnorm.
Qed.
diff --git a/theories/Numbers/DecimalR.v b/theories/Numbers/DecimalR.v
new file mode 100644
index 0000000000..9b65a7dc20
--- /dev/null
+++ b/theories/Numbers/DecimalR.v
@@ -0,0 +1,312 @@
+(************************************************************************)
+(* * The Coq Proof Assistant / The Coq Development Team *)
+(* v * Copyright INRIA, CNRS and contributors *)
+(* <O___,, * (see version control and CREDITS file for authors & dates) *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(* * (see LICENSE file for the text of the license) *)
+(************************************************************************)
+
+(** * DecimalR
+
+ Proofs that conversions between decimal numbers and [R]
+ are bijections. *)
+
+Require Import Decimal DecimalFacts DecimalPos DecimalZ DecimalQ Rdefinitions.
+
+Lemma of_IQmake_to_decimal num den :
+ match IQmake_to_decimal num den with
+ | None => True
+ | Some (DecimalExp _ _ _) => False
+ | Some (Decimal i f) =>
+ of_decimal (Decimal i f) = IRQ (QArith_base.Qmake num den)
+ end.
+Proof.
+ unfold IQmake_to_decimal.
+ case (Pos.eq_dec den 1); [now intros->|intro Hden].
+ assert (Hf : match QArith_base.IQmake_to_decimal num den with
+ | Some (Decimal i f) => f <> Nil
+ | _ => True
+ end).
+ { unfold QArith_base.IQmake_to_decimal; simpl.
+ generalize (Unsigned.nztail_to_uint den).
+ case Decimal.nztail as [den' e_den'].
+ case den'; [now simpl|now simpl| |now simpl..]; clear den'; intro den'.
+ case den'; [ |now simpl..]; clear den'.
+ case e_den' as [|e_den']; [now simpl; intros H _; apply Hden; injection H|].
+ intros _.
+ case Nat.ltb_spec; intro He_den'.
+ - apply del_head_nonnil.
+ revert He_den'; case nb_digits as [|n]; [now simpl|].
+ now intro H; simpl; apply le_lt_n_Sm, Nat.le_sub_l.
+ - apply nb_digits_n0.
+ now rewrite nb_digits_iter_D0, Nat.sub_add. }
+ replace (match den with 1%positive => _ | _ => _ end)
+ with (QArith_base.IQmake_to_decimal num den); [|now revert Hden; case den].
+ generalize (of_IQmake_to_decimal num den).
+ case QArith_base.IQmake_to_decimal as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ unfold of_decimal; simpl.
+ intro H; injection H; clear H; intros <-.
+ intro H; generalize (f_equal QArith_base.IZ_to_Z H); clear H.
+ rewrite !IZ_to_Z_IZ_of_Z; intro H; injection H; clear H; intros<-.
+ now revert Hf; case f.
+Qed.
+
+Lemma of_to (q:IR) : forall d, to_decimal q = Some d -> of_decimal d = q.
+Proof.
+ intro d.
+ case q as [z|q|r r'|r r']; simpl.
+ - case z as [z p| |p|p].
+ + now simpl.
+ + now simpl; intro H; injection H; clear H; intros<-.
+ + simpl; intro H; injection H; clear H; intros<-.
+ now unfold of_decimal; simpl; unfold Z.of_uint; rewrite Unsigned.of_to.
+ + simpl; intro H; injection H; clear H; intros<-.
+ now unfold of_decimal; simpl; unfold Z.of_uint; rewrite Unsigned.of_to.
+ - case q as [num den].
+ generalize (of_IQmake_to_decimal num den).
+ case IQmake_to_decimal as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ now intros H H'; injection H'; intros<-.
+ - case r as [z|q| |]; [|case q as[num den]|now simpl..];
+ (case r' as [z'| | |]; [|now simpl..]);
+ (case z' as [p e| | |]; [|now simpl..]).
+ + case (Z.eq_dec p 10); [intros->|intro Hp].
+ 2:{ revert Hp; case p; [now simpl|intro d0..];
+ (case d0; [intro d1..|]; [now simpl| |now simpl];
+ case d1; [intro d2..|]; [|now simpl..];
+ case d2; [intro d3..|]; [now simpl| |now simpl];
+ now case d3). }
+ case z as [| |p|p]; [now simpl|..]; intro H; injection H; intros<-.
+ * now unfold of_decimal; simpl; unfold Z.of_uint; rewrite Unsigned.of_to.
+ * unfold of_decimal; simpl; unfold Z.of_uint; rewrite Unsigned.of_to; simpl.
+ now rewrite Unsigned.of_to.
+ * unfold of_decimal; simpl; unfold Z.of_uint; rewrite Unsigned.of_to; simpl.
+ now rewrite Unsigned.of_to.
+ + case (Z.eq_dec p 10); [intros->|intro Hp].
+ 2:{ revert Hp; case p; [now simpl|intro d0..];
+ (case d0; [intro d1..|]; [now simpl| |now simpl];
+ case d1; [intro d2..|]; [|now simpl..];
+ case d2; [intro d3..|]; [now simpl| |now simpl];
+ now case d3). }
+ generalize (of_IQmake_to_decimal num den).
+ case IQmake_to_decimal as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ intros H H'; injection H'; clear H'; intros<-.
+ unfold of_decimal; simpl.
+ change (match f with Nil => _ | _ => _ end) with (of_decimal (Decimal i f)).
+ rewrite H; clear H.
+ now unfold Z.of_uint; rewrite Unsigned.of_to.
+ - case r as [z|q| |]; [|case q as[num den]|now simpl..];
+ (case r' as [z'| | |]; [|now simpl..]);
+ (case z' as [p e| | |]; [|now simpl..]).
+ + case (Z.eq_dec p 10); [intros->|intro Hp].
+ 2:{ revert Hp; case p; [now simpl|intro d0..];
+ (case d0; [intro d1..|]; [now simpl| |now simpl];
+ case d1; [intro d2..|]; [|now simpl..];
+ case d2; [intro d3..|]; [now simpl| |now simpl];
+ now case d3). }
+ case z as [| |p|p]; [now simpl|..]; intro H; injection H; intros<-.
+ * now unfold of_decimal; simpl; unfold Z.of_uint; rewrite Unsigned.of_to.
+ * unfold of_decimal; simpl; unfold Z.of_uint; rewrite Unsigned.of_to; simpl.
+ now rewrite Unsigned.of_to.
+ * unfold of_decimal; simpl; unfold Z.of_uint; rewrite Unsigned.of_to; simpl.
+ now rewrite Unsigned.of_to.
+ + case (Z.eq_dec p 10); [intros->|intro Hp].
+ 2:{ revert Hp; case p; [now simpl|intro d0..];
+ (case d0; [intro d1..|]; [now simpl| |now simpl];
+ case d1; [intro d2..|]; [|now simpl..];
+ case d2; [intro d3..|]; [now simpl| |now simpl];
+ now case d3). }
+ generalize (of_IQmake_to_decimal num den).
+ case IQmake_to_decimal as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ intros H H'; injection H'; clear H'; intros<-.
+ unfold of_decimal; simpl.
+ change (match f with Nil => _ | _ => _ end) with (of_decimal (Decimal i f)).
+ rewrite H; clear H.
+ now unfold Z.of_uint; rewrite Unsigned.of_to.
+Qed.
+
+Lemma to_of (d:decimal) : to_decimal (of_decimal d) = Some (dnorm d).
+Proof.
+ case d as [i f|i f e].
+ - unfold of_decimal; simpl.
+ case (uint_eq_dec f Nil); intro Hf.
+ + rewrite Hf; clear f Hf.
+ unfold to_decimal; simpl.
+ rewrite IZ_to_Z_IZ_of_Z, DecimalZ.to_of.
+ case i as [i|i]; [now simpl|]; simpl.
+ rewrite app_nil_r.
+ case (uint_eq_dec (nzhead i) Nil); [now intros->|intro Hi].
+ now rewrite (unorm_nzhead _ Hi); revert Hi; case nzhead.
+ + set (r := IRQ _).
+ set (m := match f with Nil => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ unfold to_decimal; simpl.
+ unfold IQmake_to_decimal; simpl.
+ set (n := Nat.iter _ _ _).
+ case (Pos.eq_dec n 1); intro Hn.
+ exfalso; apply Hf.
+ { now apply nb_digits_0; revert Hn; unfold n; case nb_digits. }
+ clear m; set (m := match n with 1%positive | _ => _ end).
+ replace m with (QArith_base.IQmake_to_decimal (Z.of_int (app_int i f)) n).
+ 2:{ now unfold m; revert Hn; case n. }
+ unfold QArith_base.IQmake_to_decimal, n; simpl.
+ rewrite nztail_to_uint_pow10.
+ clear r; set (r := if _ <? _ then Some (Decimal _ _) else Some _).
+ clear m; set (m := match nb_digits f with 0 => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ rewrite DecimalZ.to_of, abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnf.
+ * rewrite (del_tail_app_int_exact _ _ Hnf).
+ rewrite (del_head_app_int_exact _ _ Hnf).
+ now rewrite (dnorm_i_exact _ _ Hnf).
+ * rewrite (unorm_app_r _ _ Hnf).
+ rewrite (iter_D0_unorm _ Hf).
+ now rewrite dnorm_i_exact'.
+ - unfold of_decimal; simpl.
+ rewrite <-(DecimalZ.to_of e).
+ case (Z.of_int e); clear e; [|intro e..]; simpl.
+ + case (uint_eq_dec f Nil); intro Hf.
+ * rewrite Hf; clear f Hf.
+ unfold to_decimal; simpl.
+ rewrite IZ_to_Z_IZ_of_Z, DecimalZ.to_of.
+ case i as [i|i]; [now simpl|]; simpl.
+ rewrite app_nil_r.
+ case (uint_eq_dec (nzhead i) Nil); [now intros->|intro Hi].
+ now rewrite (unorm_nzhead _ Hi); revert Hi; case nzhead.
+ * set (r := IRQ _).
+ set (m := match f with Nil => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ unfold to_decimal; simpl.
+ unfold IQmake_to_decimal; simpl.
+ set (n := Nat.iter _ _ _).
+ case (Pos.eq_dec n 1); intro Hn.
+ exfalso; apply Hf.
+ { now apply nb_digits_0; revert Hn; unfold n; case nb_digits. }
+ clear m; set (m := match n with 1%positive | _ => _ end).
+ replace m with (QArith_base.IQmake_to_decimal (Z.of_int (app_int i f)) n).
+ 2:{ now unfold m; revert Hn; case n. }
+ unfold QArith_base.IQmake_to_decimal, n; simpl.
+ rewrite nztail_to_uint_pow10.
+ clear r; set (r := if _ <? _ then Some (Decimal _ _) else Some _).
+ clear m; set (m := match nb_digits f with 0 => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ rewrite DecimalZ.to_of, abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnf.
+ -- rewrite (del_tail_app_int_exact _ _ Hnf).
+ rewrite (del_head_app_int_exact _ _ Hnf).
+ now rewrite (dnorm_i_exact _ _ Hnf).
+ -- rewrite (unorm_app_r _ _ Hnf).
+ rewrite (iter_D0_unorm _ Hf).
+ now rewrite dnorm_i_exact'.
+ + set (i' := match i with Pos _ => _ | _ => _ end).
+ set (m := match Pos.to_uint e with Nil => _ | _ => _ end).
+ replace m with (DecimalExp i' f (Pos (Pos.to_uint e))).
+ 2:{ unfold m; generalize (Unsigned.to_uint_nonzero e).
+ now case Pos.to_uint; [|intro u; case u|..]. }
+ unfold i'; clear i' m.
+ case (uint_eq_dec f Nil); intro Hf.
+ * rewrite Hf; clear f Hf.
+ unfold to_decimal; simpl.
+ rewrite IZ_to_Z_IZ_of_Z, DecimalZ.to_of.
+ case i as [i|i]; [now simpl|]; simpl.
+ rewrite app_nil_r.
+ case (uint_eq_dec (nzhead i) Nil); [now intros->|intro Hi].
+ now rewrite (unorm_nzhead _ Hi); revert Hi; case nzhead.
+ * set (r := IRQ _).
+ set (m := match f with Nil => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ unfold to_decimal; simpl.
+ unfold IQmake_to_decimal; simpl.
+ set (n := Nat.iter _ _ _).
+ case (Pos.eq_dec n 1); intro Hn.
+ exfalso; apply Hf.
+ { now apply nb_digits_0; revert Hn; unfold n; case nb_digits. }
+ clear m; set (m := match n with 1%positive | _ => _ end).
+ replace m with (QArith_base.IQmake_to_decimal (Z.of_int (app_int i f)) n).
+ 2:{ now unfold m; revert Hn; case n. }
+ unfold QArith_base.IQmake_to_decimal, n; simpl.
+ rewrite nztail_to_uint_pow10.
+ clear r; set (r := if _ <? _ then Some (Decimal _ _) else Some _).
+ clear m; set (m := match nb_digits f with 0 => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ rewrite DecimalZ.to_of, abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnf.
+ -- rewrite (del_tail_app_int_exact _ _ Hnf).
+ rewrite (del_head_app_int_exact _ _ Hnf).
+ now rewrite (dnorm_i_exact _ _ Hnf).
+ -- rewrite (unorm_app_r _ _ Hnf).
+ rewrite (iter_D0_unorm _ Hf).
+ now rewrite dnorm_i_exact'.
+ + case (uint_eq_dec f Nil); intro Hf.
+ * rewrite Hf; clear f Hf.
+ unfold to_decimal; simpl.
+ rewrite IZ_to_Z_IZ_of_Z, DecimalZ.to_of.
+ case i as [i|i]; [now simpl|]; simpl.
+ rewrite app_nil_r.
+ case (uint_eq_dec (nzhead i) Nil); [now intros->|intro Hi].
+ now rewrite (unorm_nzhead _ Hi); revert Hi; case nzhead.
+ * set (r := IRQ _).
+ set (m := match f with Nil => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ unfold to_decimal; simpl.
+ unfold IQmake_to_decimal; simpl.
+ set (n := Nat.iter _ _ _).
+ case (Pos.eq_dec n 1); intro Hn.
+ exfalso; apply Hf.
+ { now apply nb_digits_0; revert Hn; unfold n; case nb_digits. }
+ clear m; set (m := match n with 1%positive | _ => _ end).
+ replace m with (QArith_base.IQmake_to_decimal (Z.of_int (app_int i f)) n).
+ 2:{ now unfold m; revert Hn; case n. }
+ unfold QArith_base.IQmake_to_decimal, n; simpl.
+ rewrite nztail_to_uint_pow10.
+ clear r; set (r := if _ <? _ then Some (Decimal _ _) else Some _).
+ clear m; set (m := match nb_digits f with 0 => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ rewrite DecimalZ.to_of, abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnf.
+ -- rewrite (del_tail_app_int_exact _ _ Hnf).
+ rewrite (del_head_app_int_exact _ _ Hnf).
+ now rewrite (dnorm_i_exact _ _ Hnf).
+ -- rewrite (unorm_app_r _ _ Hnf).
+ rewrite (iter_D0_unorm _ Hf).
+ now rewrite dnorm_i_exact'.
+Qed.
+
+(** Some consequences *)
+
+Lemma to_decimal_inj q q' :
+ to_decimal q <> None -> to_decimal q = to_decimal q' -> q = q'.
+Proof.
+ intros Hnone EQ.
+ generalize (of_to q) (of_to q').
+ rewrite <-EQ.
+ revert Hnone; case to_decimal; [|now simpl].
+ now intros d _ H1 H2; rewrite <-(H1 d eq_refl), <-(H2 d eq_refl).
+Qed.
+
+Lemma to_decimal_surj d : exists q, to_decimal q = Some (dnorm d).
+Proof.
+ exists (of_decimal d). apply to_of.
+Qed.
+
+Lemma of_decimal_dnorm d : of_decimal (dnorm d) = of_decimal d.
+Proof. now apply to_decimal_inj; rewrite !to_of; [|rewrite dnorm_involutive]. Qed.
+
+Lemma of_inj d d' : of_decimal d = of_decimal d' -> dnorm d = dnorm d'.
+Proof.
+ intro H.
+ apply (@f_equal _ _ (fun x => match x with Some x => x | _ => d end)
+ (Some (dnorm d)) (Some (dnorm d'))).
+ now rewrite <- !to_of, H.
+Qed.
+
+Lemma of_iff d d' : of_decimal d = of_decimal d' <-> dnorm d = dnorm d'.
+Proof.
+ split. apply of_inj. intros E. rewrite <- of_decimal_dnorm, E.
+ apply of_decimal_dnorm.
+Qed.
diff --git a/theories/Numbers/DecimalZ.v b/theories/Numbers/DecimalZ.v
index 69d8073fc7..faaf8a3932 100644
--- a/theories/Numbers/DecimalZ.v
+++ b/theories/Numbers/DecimalZ.v
@@ -79,9 +79,11 @@ Qed.
Lemma of_uint_iter_D0 d n :
Z.of_uint (app d (Nat.iter n D0 Nil)) = Nat.iter n (Z.mul 10) (Z.of_uint d).
Proof.
- unfold Z.of_uint.
- unfold app; rewrite <-rev_revapp.
- rewrite Unsigned.of_lu_rev, Unsigned.of_lu_revapp.
+ rewrite <-(rev_rev (app _ _)), <-(of_list_to_list (rev (app _ _))).
+ rewrite rev_spec, app_spec, List.rev_app_distr.
+ rewrite <-!rev_spec, <-app_spec, of_list_to_list.
+ unfold Z.of_uint; rewrite Unsigned.of_lu_rev.
+ unfold app; rewrite Unsigned.of_lu_revapp, !rev_rev.
rewrite <-!Unsigned.of_lu_rev, !rev_rev.
assert (H' : Pos.of_uint (Nat.iter n D0 Nil) = 0%N).
{ now induction n; [|rewrite Unsigned.nat_iter_S]. }
@@ -100,3 +102,22 @@ Proof.
- rewrite of_uint_iter_D0; induction n; [now simpl|].
rewrite !Unsigned.nat_iter_S, <-IHn; ring.
Qed.
+
+Lemma nztail_to_uint_pow10 n :
+ Decimal.nztail (Pos.to_uint (Nat.iter n (Pos.mul 10) 1%positive))
+ = (D1 Nil, n).
+Proof.
+ case n as [|n]; [now simpl|].
+ rewrite <-(Nat2Pos.id (S n)); [|now simpl].
+ generalize (Pos.of_nat (S n)); clear n; intro p.
+ induction (Pos.to_nat p); [now simpl|].
+ rewrite Unsigned.nat_iter_S.
+ unfold Pos.to_uint.
+ change (Pos.to_little_uint _)
+ with (Unsigned.to_lu (10 * N.pos (Nat.iter n (Pos.mul 10) 1%positive))).
+ rewrite Unsigned.to_ldec_tenfold.
+ revert IHn; unfold Pos.to_uint.
+ unfold Decimal.nztail; rewrite !rev_rev; simpl.
+ set (f'' := _ (Pos.to_little_uint _)).
+ now case f''; intros r n' H; inversion H.
+Qed.
diff --git a/theories/Numbers/HexadecimalFacts.v b/theories/Numbers/HexadecimalFacts.v
index 7328b2303d..c624b4e6b9 100644
--- a/theories/Numbers/HexadecimalFacts.v
+++ b/theories/Numbers/HexadecimalFacts.v
@@ -10,136 +10,437 @@
(** * HexadecimalFacts : some facts about Hexadecimal numbers *)
-Require Import Hexadecimal Arith.
+Require Import Hexadecimal Arith ZArith.
+
+Variant digits :=
+ | d0 | d1 | d2 | d3 | d4 | d5 | d6 | d7 | d8 | d9
+ | da | db | dc | dd | de | df.
+
+Fixpoint to_list (u : uint) : list digits :=
+ match u with
+ | Nil => nil
+ | D0 u => cons d0 (to_list u)
+ | D1 u => cons d1 (to_list u)
+ | D2 u => cons d2 (to_list u)
+ | D3 u => cons d3 (to_list u)
+ | D4 u => cons d4 (to_list u)
+ | D5 u => cons d5 (to_list u)
+ | D6 u => cons d6 (to_list u)
+ | D7 u => cons d7 (to_list u)
+ | D8 u => cons d8 (to_list u)
+ | D9 u => cons d9 (to_list u)
+ | Da u => cons da (to_list u)
+ | Db u => cons db (to_list u)
+ | Dc u => cons dc (to_list u)
+ | Dd u => cons dd (to_list u)
+ | De u => cons de (to_list u)
+ | Df u => cons df (to_list u)
+ end.
+
+Fixpoint of_list (l : list digits) : uint :=
+ match l with
+ | nil => Nil
+ | cons d0 l => D0 (of_list l)
+ | cons d1 l => D1 (of_list l)
+ | cons d2 l => D2 (of_list l)
+ | cons d3 l => D3 (of_list l)
+ | cons d4 l => D4 (of_list l)
+ | cons d5 l => D5 (of_list l)
+ | cons d6 l => D6 (of_list l)
+ | cons d7 l => D7 (of_list l)
+ | cons d8 l => D8 (of_list l)
+ | cons d9 l => D9 (of_list l)
+ | cons da l => Da (of_list l)
+ | cons db l => Db (of_list l)
+ | cons dc l => Dc (of_list l)
+ | cons dd l => Dd (of_list l)
+ | cons de l => De (of_list l)
+ | cons df l => Df (of_list l)
+ end.
-Scheme Equality for uint.
+Lemma of_list_to_list u : of_list (to_list u) = u.
+Proof. now induction u; [|simpl; rewrite IHu..]. Qed.
-Scheme Equality for int.
+Lemma to_list_of_list l : to_list (of_list l) = l.
+Proof. now induction l as [|h t IHl]; [|case h; simpl; rewrite IHl]. Qed.
-Lemma rev_revapp d d' :
- rev (revapp d d') = revapp d' d.
+Lemma to_list_inj u u' : to_list u = to_list u' -> u = u'.
Proof.
- revert d'. induction d; simpl; intros; now rewrite ?IHd.
+ now intro H; rewrite <-(of_list_to_list u), <-(of_list_to_list u'), H.
Qed.
-Lemma rev_rev d : rev (rev d) = d.
+Lemma of_list_inj u u' : of_list u = of_list u' -> u = u'.
Proof.
- apply rev_revapp.
+ now intro H; rewrite <-(to_list_of_list u), <-(to_list_of_list u'), H.
Qed.
-Lemma revapp_rev_nil d : revapp (rev d) Nil = d.
-Proof. now fold (rev (rev d)); rewrite rev_rev. Qed.
+Lemma nb_digits_spec u : nb_digits u = length (to_list u).
+Proof. now induction u; [|simpl; rewrite IHu..]. Qed.
-Lemma app_nil_r d : app d Nil = d.
-Proof. now unfold app; rewrite revapp_rev_nil. Qed.
+Fixpoint lnzhead l :=
+ match l with
+ | nil => nil
+ | cons d l' =>
+ match d with
+ | d0 => lnzhead l'
+ | _ => l
+ end
+ end.
-Lemma app_int_nil_r d : app_int d Nil = d.
-Proof. now case d; intro d'; simpl; rewrite app_nil_r. Qed.
+Lemma nzhead_spec u : to_list (nzhead u) = lnzhead (to_list u).
+Proof. now induction u; [|simpl; rewrite IHu|..]. Qed.
+
+Definition lzero := cons d0 nil.
+
+Definition lunorm l :=
+ match lnzhead l with
+ | nil => lzero
+ | d => d
+ end.
+
+Lemma unorm_spec u : to_list (unorm u) = lunorm (to_list u).
+Proof. now unfold unorm, lunorm; rewrite <-nzhead_spec; case (nzhead u). Qed.
+
+Lemma revapp_spec d d' :
+ to_list (revapp d d') = List.rev_append (to_list d) (to_list d').
+Proof. now revert d'; induction d; intro d'; [|simpl; rewrite IHd..]. Qed.
+
+Lemma rev_spec d : to_list (rev d) = List.rev (to_list d).
+Proof. now unfold rev; rewrite revapp_spec, List.rev_alt; simpl. Qed.
+
+Lemma app_spec d d' :
+ to_list (app d d') = Datatypes.app (to_list d) (to_list d').
+Proof.
+ unfold app.
+ now rewrite revapp_spec, List.rev_append_rev, rev_spec, List.rev_involutive.
+Qed.
-Lemma revapp_revapp_1 d d' d'' :
- nb_digits d <= 1 ->
- revapp (revapp d d') d'' = revapp d' (revapp d d'').
+Definition lnztail l :=
+ let fix aux l_rev :=
+ match l_rev with
+ | cons d0 l_rev => let (r, n) := aux l_rev in pair r (S n)
+ | _ => pair l_rev O
+ end in
+ let (r, n) := aux (List.rev l) in pair (List.rev r) n.
+
+Lemma nztail_spec d :
+ let (r, n) := nztail d in
+ let (r', n') := lnztail (to_list d) in
+ to_list r = r' /\ n = n'.
Proof.
- now case d; clear d; intro d;
- [|case d; clear d; intro d;
- [|simpl; case nb_digits; [|intros n]; intros Hn; exfalso;
- [apply (Nat.nle_succ_diag_l _ Hn)|
- apply (Nat.nle_succ_0 _ (le_S_n _ _ Hn))]..]..].
+ unfold nztail, lnztail.
+ set (f := fix aux d_rev := match d_rev with
+ | D0 d_rev => let (r, n) := aux d_rev in (r, S n)
+ | _ => (d_rev, 0) end).
+ set (f' := fix aux (l_rev : list digits) : list digits * nat :=
+ match l_rev with
+ | cons d0 l_rev => let (r, n) := aux l_rev in (r, S n)
+ | _ => (l_rev, 0)
+ end).
+ rewrite <-(of_list_to_list (rev d)), rev_spec.
+ induction (List.rev _) as [|h t IHl]; [now simpl|].
+ case h; simpl; [|now rewrite rev_spec; simpl; rewrite to_list_of_list..].
+ now revert IHl; case f; intros r n; case f'; intros r' n' [-> ->].
Qed.
-Lemma nb_digits_pos d : d <> Nil -> 0 < nb_digits d.
-Proof. now case d; [|intros d' _; apply Nat.lt_0_succ..]. Qed.
+Lemma del_head_spec_0 d : del_head 0 d = d.
+Proof. now simpl. Qed.
-Lemma nb_digits_revapp d d' :
- nb_digits (revapp d d') = nb_digits d + nb_digits d'.
+Lemma del_head_spec_small n d :
+ n <= length (to_list d) -> to_list (del_head n d) = List.skipn n (to_list d).
Proof.
- now revert d'; induction d; [|intro d'; simpl; rewrite IHd; simpl..].
+ revert d; induction n as [|n IHn]; intro d; [now simpl|].
+ now case d; [|intros d' H; apply IHn, le_S_n..].
Qed.
-Lemma nb_digits_rev u : nb_digits (rev u) = nb_digits u.
-Proof. now unfold rev; rewrite nb_digits_revapp. Qed.
+Lemma del_head_spec_large n d : length (to_list d) < n -> del_head n d = zero.
+Proof.
+ revert d; induction n; intro d; [now case d|].
+ now case d; [|intro d'; simpl; intro H; rewrite (IHn _ (lt_S_n _ _ H))..].
+Qed.
-Lemma nb_digits_nzhead u : nb_digits (nzhead u) <= nb_digits u.
-Proof. now induction u; [|apply le_S|..]. Qed.
+Lemma nb_digits_0 d : nb_digits d = 0 -> d = Nil.
+Proof.
+ rewrite nb_digits_spec, <-(of_list_to_list d).
+ now case (to_list d) as [|h t]; [|rewrite to_list_of_list].
+Qed.
+
+Lemma nb_digits_n0 d : nb_digits d <> 0 -> d <> Nil.
+Proof. now case d; [|intros u _..]. Qed.
Lemma nb_digits_iter_D0 n d :
nb_digits (Nat.iter n D0 d) = n + nb_digits d.
Proof. now induction n; simpl; [|rewrite IHn]. Qed.
-Fixpoint nth n u :=
- match n with
- | O =>
- match u with
- | Nil => Nil
- | D0 d => D0 Nil
- | D1 d => D1 Nil
- | D2 d => D2 Nil
- | D3 d => D3 Nil
- | D4 d => D4 Nil
- | D5 d => D5 Nil
- | D6 d => D6 Nil
- | D7 d => D7 Nil
- | D8 d => D8 Nil
- | D9 d => D9 Nil
- | Da d => Da Nil
- | Db d => Db Nil
- | Dc d => Dc Nil
- | Dd d => Dd Nil
- | De d => De Nil
- | Df d => Df Nil
- end
- | S n =>
- match u with
- | Nil => Nil
- | D0 d | D1 d | D2 d | D3 d | D4 d | D5 d | D6 d | D7 d | D8 d | D9 d
- | Da d | Db d | Dc d | Dd d | De d | Df d =>
- nth n d
- end
- end.
+Lemma length_lnzhead l : length (lnzhead l) <= length l.
+Proof. now induction l as [|h t IHl]; [|case h; [apply le_S|..]]. Qed.
+
+Lemma nb_digits_nzhead u : nb_digits (nzhead u) <= nb_digits u.
+Proof. now induction u; [|apply le_S|..]. Qed.
-Lemma nb_digits_nth n u : nb_digits (nth n u) <= 1.
-Proof.
- revert u; induction n.
- - now intro u; case u; [apply Nat.le_0_1|..].
- - intro u; case u; [apply Nat.le_0_1|intro u'; apply IHn..].
-Qed.
-
-Lemma nth_revapp_r n d d' :
- nb_digits d <= n ->
- nth n (revapp d d') = nth (n - nb_digits d) d'.
-Proof.
- revert d d'; induction n; intro d.
- - now case d; intro d';
- [case d'|intros d'' H; exfalso; revert H; apply Nat.nle_succ_0..].
- - now induction d;
- [intro d'; case d'|
- intros d' H;
- simpl revapp; rewrite IHd; [|now apply le_Sn_le];
- rewrite Nat.sub_succ_l; [|now apply le_S_n];
- simpl; rewrite <-(IHn _ _ (le_S_n _ _ H))..].
-Qed.
-
-Lemma nth_revapp_l n d d' :
- n < nb_digits d ->
- nth n (revapp d d') = nth (nb_digits d - n - 1) d.
-Proof.
- revert d d'; induction n; intro d.
- - rewrite Nat.sub_0_r.
- now induction d;
- [|intros d' _; simpl revapp;
- revert IHd; case d; clear d; [|intro d..]; intro IHd;
- [|rewrite IHd; [simpl nb_digits; rewrite (Nat.sub_succ_l _ (S _))|];
- [|apply le_n_S, Nat.le_0_l..]..]..].
- - now induction d;
- [|intros d' H;
- simpl revapp; simpl nb_digits;
- simpl in H; generalize (lt_S_n _ _ H); clear H; intro H;
- case (le_lt_eq_dec _ _ H); clear H; intro H;
- [rewrite (IHd _ H), Nat.sub_succ_l;
- [rewrite Nat.sub_succ_l; [|apply Nat.le_add_le_sub_r]|
- apply le_Sn_le]|
- rewrite nth_revapp_r; rewrite <-H;
- [rewrite Nat.sub_succ, Nat.sub_succ_l; [rewrite !Nat.sub_diag|]|]]..].
+Lemma unorm_nzhead u : nzhead u <> Nil -> unorm u = nzhead u.
+Proof. now unfold unorm; case nzhead. Qed.
+
+Lemma nb_digits_unorm u : u <> Nil -> nb_digits (unorm u) <= nb_digits u.
+Proof.
+ intro Hu; case (uint_eq_dec (nzhead u) Nil).
+ { unfold unorm; intros ->; simpl.
+ now revert Hu; case u; [|intros u' _; apply le_n_S, Nat.le_0_l..]. }
+ intro H; rewrite (unorm_nzhead _ H); apply nb_digits_nzhead.
+Qed.
+
+Lemma nb_digits_rev d : nb_digits (rev d) = nb_digits d.
+Proof. now rewrite !nb_digits_spec, rev_spec, List.rev_length. Qed.
+
+Lemma nb_digits_del_head_sub d n :
+ n <= nb_digits d ->
+ nb_digits (del_head (nb_digits d - n) d) = n.
+Proof.
+ rewrite !nb_digits_spec; intro Hn.
+ rewrite del_head_spec_small; [|now apply Nat.le_sub_l].
+ rewrite List.skipn_length, <-(Nat2Z.id (_ - _)).
+ rewrite Nat2Z.inj_sub; [|now apply Nat.le_sub_l].
+ rewrite (Nat2Z.inj_sub _ _ Hn).
+ rewrite Z.sub_sub_distr, Z.sub_diag; apply Nat2Z.id.
+Qed.
+
+Lemma unorm_D0 u : unorm (D0 u) = unorm u.
+Proof. reflexivity. Qed.
+
+Lemma app_nil_l d : app Nil d = d.
+Proof. now simpl. Qed.
+
+Lemma app_nil_r d : app d Nil = d.
+Proof. now apply to_list_inj; rewrite app_spec, List.app_nil_r. Qed.
+
+Lemma abs_app_int d d' : abs (app_int d d') = app (abs d) d'.
+Proof. now case d. Qed.
+
+Lemma abs_norm d : abs (norm d) = unorm (abs d).
+Proof. now case d as [u|u]; [|simpl; unfold unorm; case nzhead]. Qed.
+
+Lemma iter_D0_nzhead d :
+ Nat.iter (nb_digits d - nb_digits (nzhead d)) D0 (nzhead d) = d.
+Proof.
+ induction d; [now simpl| |now rewrite Nat.sub_diag..].
+ simpl nzhead; simpl nb_digits.
+ rewrite (Nat.sub_succ_l _ _ (nb_digits_nzhead _)).
+ now rewrite <-IHd at 4.
+Qed.
+
+Lemma iter_D0_unorm d :
+ d <> Nil ->
+ Nat.iter (nb_digits d - nb_digits (unorm d)) D0 (unorm d) = d.
+Proof.
+ case (uint_eq_dec (nzhead d) Nil); intro Hn.
+ { unfold unorm; rewrite Hn; simpl; intro H.
+ revert H Hn; induction d; [now simpl|intros _|now intros _..].
+ case (uint_eq_dec d Nil); simpl; intros H Hn; [now rewrite H|].
+ rewrite Nat.sub_0_r, (le_plus_minus 1 (nb_digits d)).
+ { now simpl; rewrite IHd. }
+ revert H; case d; [now simpl|intros u _; apply le_n_S, Nat.le_0_l..]. }
+ intros _; rewrite (unorm_nzhead _ Hn); apply iter_D0_nzhead.
+Qed.
+
+Lemma nzhead_app_l d d' :
+ nb_digits d' < nb_digits (nzhead (app d d')) ->
+ nzhead (app d d') = app (nzhead d) d'.
+Proof.
+ intro Hl; apply to_list_inj; revert Hl.
+ rewrite !nb_digits_spec, app_spec, !nzhead_spec, app_spec.
+ induction (to_list d) as [|h t IHl].
+ { now simpl; intro H; exfalso; revert H; apply le_not_lt, length_lnzhead. }
+ rewrite <-List.app_comm_cons.
+ now case h; [simpl; intro Hl; apply IHl|..].
+Qed.
+
+Lemma nzhead_app_r d d' :
+ nb_digits (nzhead (app d d')) <= nb_digits d' ->
+ nzhead (app d d') = nzhead d'.
+Proof.
+ intro Hl; apply to_list_inj; revert Hl.
+ rewrite !nb_digits_spec, !nzhead_spec, app_spec.
+ induction (to_list d) as [|h t IHl]; [now simpl|].
+ rewrite <-List.app_comm_cons.
+ now case h; [| simpl; rewrite List.app_length; intro Hl; exfalso; revert Hl;
+ apply le_not_lt, le_plus_r..].
+Qed.
+
+Lemma nzhead_app_nil_r d d' : nzhead (app d d') = Nil -> nzhead d' = Nil.
+Proof.
+now intro H; generalize H; rewrite nzhead_app_r; [|rewrite H; apply Nat.le_0_l].
+Qed.
+
+Lemma nzhead_app_nil d d' :
+ nb_digits (nzhead (app d d')) <= nb_digits d' -> nzhead d = Nil.
+Proof.
+ intro H; apply to_list_inj; revert H.
+ rewrite !nb_digits_spec, !nzhead_spec, app_spec.
+ induction (to_list d) as [|h t IHl]; [now simpl|].
+ now case h; [now simpl|..];
+ simpl;intro H; exfalso; revert H; apply le_not_lt;
+ rewrite List.app_length; apply le_plus_r.
+Qed.
+
+Lemma nzhead_app_nil_l d d' : nzhead (app d d') = Nil -> nzhead d = Nil.
+Proof.
+ intro H; apply to_list_inj; generalize (f_equal to_list H); clear H.
+ rewrite !nzhead_spec, app_spec.
+ induction (to_list d) as [|h t IHl]; [now simpl|].
+ now rewrite <-List.app_comm_cons; case h.
+Qed.
+
+Lemma unorm_app_zero d d' :
+ nb_digits (unorm (app d d')) <= nb_digits d' -> unorm d = zero.
+Proof.
+ unfold unorm.
+ case (uint_eq_dec (nzhead (app d d')) Nil).
+ { now intro Hn; rewrite Hn, (nzhead_app_nil_l _ _ Hn). }
+ intro H; fold (unorm (app d d')); rewrite (unorm_nzhead _ H); intro H'.
+ case (uint_eq_dec (nzhead d) Nil); [now intros->|].
+ intro H''; fold (unorm d); rewrite (unorm_nzhead _ H'').
+ exfalso; apply H''; revert H'; apply nzhead_app_nil.
+Qed.
+
+Lemma app_int_nil_r d : app_int d Nil = d.
+Proof.
+ now case d; intro d'; simpl;
+ rewrite <-(of_list_to_list (app _ _)), app_spec;
+ rewrite List.app_nil_r, of_list_to_list.
+Qed.
+
+Lemma unorm_app_l d d' :
+ nb_digits d' < nb_digits (unorm (app d d')) ->
+ unorm (app d d') = app (unorm d) d'.
+Proof.
+ case (uint_eq_dec d' Nil); [now intros->; rewrite !app_nil_r|intro Hd'].
+ case (uint_eq_dec (nzhead (app d d')) Nil).
+ { unfold unorm; intros->; simpl; intro H; exfalso; revert H; apply le_not_lt.
+ now revert Hd'; case d'; [|intros d'' _; apply le_n_S, Peano.le_0_n..]. }
+ intro Ha; rewrite (unorm_nzhead _ Ha).
+ intro Hn; generalize Hn; rewrite (nzhead_app_l _ _ Hn).
+ rewrite !nb_digits_spec, app_spec, List.app_length.
+ case (uint_eq_dec (nzhead d) Nil).
+ { intros->; simpl; intro H; exfalso; revert H; apply Nat.lt_irrefl. }
+ now intro H; rewrite (unorm_nzhead _ H).
+Qed.
+
+Lemma unorm_app_r d d' :
+ nb_digits (unorm (app d d')) <= nb_digits d' ->
+ unorm (app d d') = unorm d'.
+Proof.
+ case (uint_eq_dec (nzhead (app d d')) Nil).
+ { now unfold unorm; intro H; rewrite H, (nzhead_app_nil_r _ _ H). }
+ intro Ha; rewrite (unorm_nzhead _ Ha).
+ case (uint_eq_dec (nzhead d') Nil).
+ { now intros H H'; exfalso; apply Ha; rewrite nzhead_app_r. }
+ intro Hd'; rewrite (unorm_nzhead _ Hd'); apply nzhead_app_r.
+Qed.
+
+Lemma norm_app_int d d' :
+ nb_digits d' < nb_digits (unorm (app (abs d) d')) ->
+ norm (app_int d d') = app_int (norm d) d'.
+Proof.
+ case (uint_eq_dec d' Nil); [now intros->; rewrite !app_int_nil_r|intro Hd'].
+ case d as [d|d]; [now simpl; intro H; apply f_equal, unorm_app_l|].
+ simpl; unfold unorm.
+ case (uint_eq_dec (nzhead (app d d')) Nil).
+ { intros->; simpl; intro H; exfalso; revert H; apply le_not_lt.
+ now revert Hd'; case d'; [|intros d'' _; apply le_n_S, Peano.le_0_n..]. }
+ set (m := match nzhead _ with Nil => _ | _ => _ end).
+ intro Ha.
+ replace m with (nzhead (app d d')).
+ 2:{ now unfold m; revert Ha; case nzhead. }
+ intro Hn; generalize Hn; rewrite (nzhead_app_l _ _ Hn).
+ case (uint_eq_dec (app (nzhead d) d') Nil).
+ { intros->; simpl; intro H; exfalso; revert H; apply le_not_lt, Nat.le_0_l. }
+ clear m; set (m := match app _ _ with Nil => _ | _ => _ end).
+ intro Ha'.
+ replace m with (Neg (app (nzhead d) d')); [|now unfold m; revert Ha'; case app].
+ case (uint_eq_dec (nzhead d) Nil).
+ { intros->; simpl; intro H; exfalso; revert H; apply Nat.lt_irrefl. }
+ clear m; set (m := match nzhead _ with Nil => _ | _ => _ end).
+ intro Hd.
+ now replace m with (Neg (nzhead d)); [|unfold m; revert Hd; case nzhead].
+Qed.
+
+Lemma del_head_nb_digits d : del_head (nb_digits d) d = Nil.
+Proof.
+ apply to_list_inj.
+ rewrite nb_digits_spec, del_head_spec_small; [|now simpl].
+ now rewrite List.skipn_all.
+Qed.
+
+Lemma del_tail_nb_digits d : del_tail (nb_digits d) d = Nil.
+Proof. now unfold del_tail; rewrite <-nb_digits_rev, del_head_nb_digits. Qed.
+
+Lemma del_head_app n d d' :
+ n <= nb_digits d -> del_head n (app d d') = app (del_head n d) d'.
+Proof.
+ rewrite nb_digits_spec; intro Hn.
+ apply to_list_inj.
+ rewrite del_head_spec_small.
+ 2:{ now rewrite app_spec, List.app_length; apply le_plus_trans. }
+ rewrite !app_spec, (del_head_spec_small _ _ Hn).
+ rewrite List.skipn_app.
+ now rewrite (proj2 (Nat.sub_0_le _ _) Hn).
+Qed.
+
+Lemma del_tail_app n d d' :
+ n <= nb_digits d' -> del_tail n (app d d') = app d (del_tail n d').
+Proof.
+ rewrite nb_digits_spec; intro Hn.
+ unfold del_tail.
+ rewrite <-(of_list_to_list (rev (app d d'))), rev_spec, app_spec.
+ rewrite List.rev_app_distr, <-!rev_spec, <-app_spec, of_list_to_list.
+ rewrite del_head_app; [|now rewrite nb_digits_spec, rev_spec, List.rev_length].
+ apply to_list_inj.
+ rewrite rev_spec, !app_spec, !rev_spec.
+ now rewrite List.rev_app_distr, List.rev_involutive.
+Qed.
+
+Lemma del_tail_app_int n d d' :
+ n <= nb_digits d' -> del_tail_int n (app_int d d') = app_int d (del_tail n d').
+Proof. now case d as [d|d]; simpl; intro H; rewrite del_tail_app. Qed.
+
+Lemma app_del_tail_head n (d:uint) :
+ n <= nb_digits d -> app (del_tail n d) (del_head (nb_digits d - n) d) = d.
+Proof.
+ rewrite nb_digits_spec; intro Hn; unfold del_tail.
+ rewrite <-(of_list_to_list (app _ _)), app_spec, rev_spec.
+ rewrite del_head_spec_small; [|now rewrite rev_spec, List.rev_length].
+ rewrite del_head_spec_small; [|now apply Nat.le_sub_l].
+ rewrite rev_spec.
+ set (n' := _ - n).
+ assert (Hn' : n = length (to_list d) - n').
+ { now apply plus_minus; rewrite Nat.add_comm; symmetry; apply le_plus_minus_r. }
+ now rewrite Hn', <-List.firstn_skipn_rev, List.firstn_skipn, of_list_to_list.
+Qed.
+
+Lemma app_int_del_tail_head n (d:int) :
+ n <= nb_digits (abs d) ->
+ app_int (del_tail_int n d) (del_head (nb_digits (abs d) - n) (abs d)) = d.
+Proof. now case d; clear d; simpl; intros u Hu; rewrite app_del_tail_head. Qed.
+
+Lemma del_head_app_int_exact i f :
+ nb_digits f < nb_digits (unorm (app (abs i) f)) ->
+ del_head (nb_digits (unorm (app (abs i) f)) - nb_digits f) (unorm (app (abs i) f)) = f.
+Proof.
+ simpl; intro Hnb; generalize Hnb; rewrite (unorm_app_l _ _ Hnb); clear Hnb.
+ replace (_ - _) with (nb_digits (unorm (abs i))).
+ - now rewrite del_head_app; [rewrite del_head_nb_digits|].
+ - rewrite !nb_digits_spec, app_spec, List.app_length.
+ now rewrite Nat.add_comm, minus_plus.
+Qed.
+
+Lemma del_tail_app_int_exact i f :
+ nb_digits f < nb_digits (unorm (app (abs i) f)) ->
+ del_tail_int (nb_digits f) (norm (app_int i f)) = norm i.
+Proof.
+ simpl; intro Hnb.
+ rewrite (norm_app_int _ _ Hnb).
+ rewrite del_tail_app_int; [|now simpl].
+ now rewrite del_tail_nb_digits, app_int_nil_r.
Qed.
(** Normalization on little-endian numbers *)
@@ -193,6 +494,9 @@ Proof.
apply nzhead_revapp.
Qed.
+Lemma rev_rev d : rev (rev d) = d.
+Proof. now apply to_list_inj; rewrite !rev_spec, List.rev_involutive. Qed.
+
Lemma rev_nztail_rev d :
rev (nztail (rev d)) = nzhead d.
Proof.
@@ -247,47 +551,128 @@ Proof.
unfold unorm. now destruct nzhead.
Qed.
-Lemma unorm_D0 u : unorm (D0 u) = unorm u.
-Proof. reflexivity. Qed.
-
Lemma unorm_iter_D0 n u : unorm (Nat.iter n D0 u) = unorm u.
Proof. now induction n. Qed.
-Lemma nb_digits_unorm u :
- u <> Nil -> nb_digits (unorm u) <= nb_digits u.
+Lemma del_head_nonnil n u :
+ n < nb_digits u -> del_head n u <> Nil.
Proof.
- case u; clear u; [now simpl|intro u..]; [|now simpl..].
- intros _; unfold unorm.
- case_eq (nzhead (D0 u)); [|now intros u' <-; apply nb_digits_nzhead..].
- intros _; apply le_n_S, Nat.le_0_l.
+ now revert n; induction u; intro n;
+ [|case n; [|intro n'; simpl; intro H; apply IHu, lt_S_n]..].
Qed.
-Lemma nzhead_invol d : nzhead (nzhead d) = nzhead d.
+Lemma del_tail_nonnil n u :
+ n < nb_digits u -> del_tail n u <> Nil.
+Proof.
+ unfold del_tail.
+ rewrite <-nb_digits_rev.
+ generalize (rev u); clear u; intro u.
+ intros Hu H.
+ generalize (rev_nil_inv _ H); clear H.
+ now apply del_head_nonnil.
+Qed.
+
+Lemma nzhead_involutive d : nzhead (nzhead d) = nzhead d.
Proof.
now induction d.
Qed.
+#[deprecated(since="8.13",note="Use nzhead_involutive instead.")]
+Notation nzhead_invol := nzhead_involutive (only parsing).
-Lemma nztail_invol d : nztail (nztail d) = nztail d.
+Lemma nztail_involutive d : nztail (nztail d) = nztail d.
Proof.
rewrite <-(rev_rev (nztail _)), <-(rev_rev (nztail d)), <-(rev_rev d).
- now rewrite !rev_nztail_rev, nzhead_invol.
+ now rewrite !rev_nztail_rev, nzhead_involutive.
Qed.
+#[deprecated(since="8.13",note="Use nztail_involutive instead.")]
+Notation nztail_invol := nztail_involutive (only parsing).
-Lemma unorm_invol d : unorm (unorm d) = unorm d.
+Lemma unorm_involutive d : unorm (unorm d) = unorm d.
Proof.
unfold unorm.
destruct (nzhead d) eqn:E; trivial.
destruct (nzhead_nonzero _ _ E).
Qed.
+#[deprecated(since="8.13",note="Use unorm_involutive instead.")]
+Notation unorm_invol := unorm_involutive (only parsing).
-Lemma norm_invol d : norm (norm d) = norm d.
+Lemma norm_involutive d : norm (norm d) = norm d.
Proof.
unfold norm.
destruct d.
- - f_equal. apply unorm_invol.
+ - f_equal. apply unorm_involutive.
- destruct (nzhead d) eqn:E; auto.
destruct (nzhead_nonzero _ _ E).
Qed.
+#[deprecated(since="8.13",note="Use norm_involutive instead.")]
+Notation norm_invol := norm_involutive (only parsing).
+
+Lemma lnzhead_neq_d0_head l l' : ~(lnzhead l = cons d0 l').
+Proof. now induction l as [|h t Il]; [|case h]. Qed.
+
+Lemma lnzhead_head_nd0 h t : h <> d0 -> lnzhead (cons h t) = cons h t.
+Proof. now case h. Qed.
+
+Lemma nzhead_del_tail_nzhead_eq n u :
+ nzhead u = u ->
+ n < nb_digits u ->
+ nzhead (del_tail n u) = del_tail n u.
+Proof.
+ rewrite nb_digits_spec, <-List.rev_length.
+ intros Hu Hn.
+ apply to_list_inj; unfold del_tail.
+ rewrite nzhead_spec, rev_spec.
+ rewrite del_head_spec_small; [|now rewrite rev_spec; apply Nat.lt_le_incl].
+ rewrite rev_spec.
+ rewrite List.skipn_rev, List.rev_involutive.
+ generalize (f_equal to_list Hu) Hn; rewrite nzhead_spec; intro Hu'.
+ case (to_list u) as [|h t].
+ { simpl; intro H; exfalso; revert H; apply le_not_lt, Peano.le_0_n. }
+ intro Hn'; generalize (Nat.sub_gt _ _ Hn'); rewrite List.rev_length.
+ case (_ - _); [now simpl|]; intros n' _.
+ rewrite List.firstn_cons, lnzhead_head_nd0; [now simpl|].
+ intro Hh; revert Hu'; rewrite Hh; apply lnzhead_neq_d0_head.
+Qed.
+
+Lemma nzhead_del_tail_nzhead n u :
+ n < nb_digits (nzhead u) ->
+ nzhead (del_tail n (nzhead u)) = del_tail n (nzhead u).
+Proof. apply nzhead_del_tail_nzhead_eq, nzhead_involutive. Qed.
+
+Lemma unorm_del_tail_unorm n u :
+ n < nb_digits (unorm u) ->
+ unorm (del_tail n (unorm u)) = del_tail n (unorm u).
+Proof.
+ case (uint_eq_dec (nzhead u) Nil).
+ - unfold unorm; intros->; case n; [now simpl|]; intro n'.
+ now simpl; intro H; exfalso; generalize (lt_S_n _ _ H).
+ - unfold unorm.
+ set (m := match nzhead u with Nil => zero | _ => _ end).
+ intros H.
+ replace m with (nzhead u).
+ + intros H'.
+ rewrite (nzhead_del_tail_nzhead _ _ H').
+ now generalize (del_tail_nonnil _ _ H'); case del_tail.
+ + now unfold m; revert H; case nzhead.
+Qed.
+
+Lemma norm_del_tail_int_norm n d :
+ n < nb_digits (match norm d with Pos d | Neg d => d end) ->
+ norm (del_tail_int n (norm d)) = del_tail_int n (norm d).
+Proof.
+ case d; clear d; intros u; simpl.
+ - now intro H; simpl; rewrite unorm_del_tail_unorm.
+ - case (uint_eq_dec (nzhead u) Nil); intro Hu.
+ + now rewrite Hu; case n; [|intros n' Hn'; generalize (lt_S_n _ _ Hn')].
+ + set (m := match nzhead u with Nil => Pos zero | _ => _ end).
+ replace m with (Neg (nzhead u)); [|now unfold m; revert Hu; case nzhead].
+ unfold del_tail_int.
+ clear m Hu.
+ simpl.
+ intro H; generalize (del_tail_nonnil _ _ H).
+ rewrite (nzhead_del_tail_nzhead _ _ H).
+ now case del_tail.
+Qed.
Lemma nzhead_app_nzhead d d' :
nzhead (app (nzhead d) d') = nzhead (app d d').
@@ -299,7 +684,7 @@ Proof.
generalize (nzhead_revapp d d').
generalize (nzhead_revapp_0 (nztail d) d').
generalize (nzhead_revapp (nztail d) d').
- rewrite nztail_invol.
+ rewrite nztail_involutive.
now case nztail;
[intros _ H _ H'; rewrite (H eq_refl), (H' eq_refl)
|intros d'' H _ H' _; rewrite H; [rewrite H'|]..].
@@ -336,5 +721,5 @@ Proof.
|rewrite H'; unfold r; clear m r H'];
unfold norm;
rewrite rev_rev, <-Hd'';
- rewrite nzhead_revapp; rewrite nztail_invol; [|rewrite Hd'']..].
+ rewrite nzhead_revapp; rewrite nztail_involutive; [|rewrite Hd'']..].
Qed.
diff --git a/theories/Numbers/HexadecimalN.v b/theories/Numbers/HexadecimalN.v
index f333e2b7f6..93ba82d14a 100644
--- a/theories/Numbers/HexadecimalN.v
+++ b/theories/Numbers/HexadecimalN.v
@@ -74,7 +74,7 @@ Proof.
destruct (norm d) eqn:Hd; intros [= <-].
unfold N.to_hex_int. rewrite Unsigned.to_of. f_equal.
revert Hd; destruct d; simpl.
- - intros [= <-]. apply unorm_invol.
+ - intros [= <-]. apply unorm_involutive.
- destruct (nzhead d); now intros [= <-].
Qed.
@@ -93,7 +93,7 @@ Qed.
Lemma of_int_norm d : N.of_hex_int (norm d) = N.of_hex_int d.
Proof.
- unfold N.of_hex_int. now rewrite norm_invol.
+ unfold N.of_hex_int. now rewrite norm_involutive.
Qed.
Lemma of_inj_pos d d' :
diff --git a/theories/Numbers/HexadecimalNat.v b/theories/Numbers/HexadecimalNat.v
index b05184e821..94a14b90bd 100644
--- a/theories/Numbers/HexadecimalNat.v
+++ b/theories/Numbers/HexadecimalNat.v
@@ -289,7 +289,7 @@ Proof.
destruct (norm d) eqn:Hd; intros [= <-].
unfold Nat.to_hex_int. rewrite Unsigned.to_of. f_equal.
revert Hd; destruct d; simpl.
- - intros [= <-]. apply unorm_invol.
+ - intros [= <-]. apply unorm_involutive.
- destruct (nzhead d); now intros [= <-].
Qed.
@@ -308,7 +308,7 @@ Qed.
Lemma of_int_norm d : Nat.of_hex_int (norm d) = Nat.of_hex_int d.
Proof.
- unfold Nat.of_hex_int. now rewrite norm_invol.
+ unfold Nat.of_hex_int. now rewrite norm_involutive.
Qed.
Lemma of_inj_pos d d' :
diff --git a/theories/Numbers/HexadecimalQ.v b/theories/Numbers/HexadecimalQ.v
index 9bf43ceb88..a32019767c 100644
--- a/theories/Numbers/HexadecimalQ.v
+++ b/theories/Numbers/HexadecimalQ.v
@@ -16,442 +16,412 @@
Require Import Decimal DecimalFacts DecimalPos DecimalN DecimalZ.
Require Import Hexadecimal HexadecimalFacts HexadecimalPos HexadecimalN HexadecimalZ QArith.
-Lemma of_to (q:Q) : forall d, to_hexadecimal q = Some d -> of_hexadecimal d = q.
+Lemma of_IQmake_to_hexadecimal num den :
+ match IQmake_to_hexadecimal num den with
+ | None => True
+ | Some (HexadecimalExp _ _ _) => False
+ | Some (Hexadecimal i f) => of_hexadecimal (Hexadecimal i f) = IQmake (IZ_of_Z num) den
+ end.
+Proof.
+ unfold IQmake_to_hexadecimal.
+ generalize (Unsigned.nztail_to_hex_uint den).
+ case Hexadecimal.nztail; intros den' e_den'.
+ case den'; [now simpl|now simpl| |now simpl..]; clear den'; intro den'.
+ case den'; [ |now simpl..]; clear den'.
+ case e_den' as [|e_den']; simpl; intro H; injection H; clear H; intros->.
+ { now unfold of_hexadecimal; simpl; rewrite app_int_nil_r, HexadecimalZ.of_to. }
+ replace (16 ^ _)%positive with (Nat.iter (S e_den') (Pos.mul 16) 1%positive).
+ 2:{ induction e_den' as [|n IHn]; [now simpl| ].
+ now rewrite SuccNat2Pos.inj_succ, Pos.pow_succ_r, <-IHn. }
+ case Nat.ltb_spec; intro He_den'.
+ - unfold of_hexadecimal; simpl.
+ rewrite app_int_del_tail_head; [|now apply Nat.lt_le_incl].
+ rewrite HexadecimalZ.of_to.
+ now rewrite nb_digits_del_head_sub; [|now apply Nat.lt_le_incl].
+ - unfold of_hexadecimal; simpl.
+ rewrite nb_digits_iter_D0.
+ apply f_equal2.
+ + apply f_equal, HexadecimalZ.to_int_inj.
+ rewrite HexadecimalZ.to_of.
+ rewrite <-(HexadecimalZ.of_to num), HexadecimalZ.to_of.
+ case (Z.to_hex_int num); clear He_den' num; intro num; simpl.
+ * unfold app; simpl.
+ now rewrite unorm_D0, unorm_iter_D0, unorm_involutive.
+ * case (uint_eq_dec (nzhead num) Nil); [|intro Hn].
+ { intros->; simpl; unfold app; simpl.
+ now rewrite unorm_D0, unorm_iter_D0. }
+ replace (match nzhead num with Nil => _ | _ => _ end)
+ with (Neg (nzhead num)); [|now revert Hn; case nzhead].
+ simpl.
+ rewrite nzhead_iter_D0, nzhead_involutive.
+ now revert Hn; case nzhead.
+ + revert He_den'; case nb_digits as [|n]; [now simpl; rewrite Nat.add_0_r|].
+ intro Hn.
+ rewrite Nat.add_succ_r, Nat.add_comm.
+ now rewrite <-le_plus_minus; [|apply le_S_n].
+Qed.
+
+Lemma IZ_of_Z_IZ_to_Z z z' : IZ_to_Z z = Some z' -> IZ_of_Z z' = z.
+Proof. now case z as [| |p|p]; [|intro H; injection H; intros<-..]. Qed.
+
+Lemma of_IQmake_to_hexadecimal' num den :
+ match IQmake_to_hexadecimal' num den with
+ | None => True
+ | Some (HexadecimalExp _ _ _) => False
+ | Some (Hexadecimal i f) => of_hexadecimal (Hexadecimal i f) = IQmake num den
+ end.
+Proof.
+ unfold IQmake_to_hexadecimal'.
+ case_eq (IZ_to_Z num); [intros num' Hnum'|now simpl].
+ generalize (of_IQmake_to_hexadecimal num' den).
+ case IQmake_to_hexadecimal as [d|]; [|now simpl].
+ case d as [i f|]; [|now simpl].
+ now rewrite (IZ_of_Z_IZ_to_Z _ _ Hnum').
+Qed.
+
+Lemma of_to (q:IQ) : forall d, to_hexadecimal q = Some d -> of_hexadecimal d = q.
Proof.
- cut (match to_hexadecimal q with None => True | Some d => of_hexadecimal d = q end).
- { now case to_hexadecimal; [intros d <- d' Hd'; injection Hd'; intros ->|]. }
- destruct q as (num, den).
- unfold to_hexadecimal; simpl Qnum; simpl Qden.
- generalize (HexadecimalPos.Unsigned.nztail_to_hex_uint den).
- case Hexadecimal.nztail; intros u n.
- change 16%N with (2^4)%N; rewrite <-N.pow_mul_r.
- change 4%N with (N.of_nat 4); rewrite <-Nnat.Nat2N.inj_mul.
- change 4%Z with (Z.of_nat 4); rewrite <-Nat2Z.inj_mul.
- case u; clear u; try (intros; exact I); [| | |]; intro u;
- (case u; clear u; [|intros; exact I..]).
- - unfold Pos.of_hex_uint, Pos.of_hex_uint_acc; rewrite N.mul_1_l.
- case n.
- + unfold of_hexadecimal, app_int, app, Z.to_hex_int; simpl.
- intro H; inversion H as (H1); clear H H1.
- case num; [reflexivity|intro pnum; fold (rev (rev (Pos.to_hex_uint pnum)))..].
- * rewrite rev_rev; simpl.
- now unfold Z.of_hex_uint; rewrite HexadecimalPos.Unsigned.of_to.
- * rewrite rev_rev; simpl.
- now unfold Z.of_hex_uint; rewrite HexadecimalPos.Unsigned.of_to.
- + clear n; intros n.
- intro H; injection H; intros ->; clear H.
- unfold of_hexadecimal.
- rewrite DecimalZ.of_to.
- simpl nb_digits; rewrite Nat2Z.inj_0, Z.mul_0_r, Z.sub_0_r.
- now apply f_equal2; [rewrite app_int_nil_r, of_to|].
- - unfold Pos.of_hex_uint, Pos.of_hex_uint_acc.
- rewrite <-N.pow_succ_r', <-Nnat.Nat2N.inj_succ.
- intro H; injection H; intros ->; clear H.
- fold (4 * n)%nat.
- change 1%Z with (Z.of_nat 1); rewrite <-Znat.Nat2Z.inj_add.
- unfold of_hexadecimal.
- rewrite DecimalZ.of_to.
- simpl nb_digits; rewrite Nat2Z.inj_0, Z.mul_0_r, Z.sub_0_r.
- now apply f_equal2; [rewrite app_int_nil_r, of_to|].
- - change 2%Z with (Z.of_nat 2); rewrite <-Znat.Nat2Z.inj_add.
- unfold Pos.of_hex_uint, Pos.of_hex_uint_acc.
- change 4%N with (2^2)%N; rewrite <-N.pow_add_r.
- change 2%N with (N.of_nat 2); rewrite <-Nnat.Nat2N.inj_add.
- intro H; injection H; intros ->; clear H.
- fold (4 * n)%nat.
- unfold of_hexadecimal.
- rewrite DecimalZ.of_to.
- simpl nb_digits; rewrite Nat2Z.inj_0, Z.mul_0_r, Z.sub_0_r.
- now apply f_equal2; [rewrite app_int_nil_r, of_to|].
- - change 3%Z with (Z.of_nat 3); rewrite <-Znat.Nat2Z.inj_add.
- unfold Pos.of_hex_uint, Pos.of_hex_uint_acc.
- change 8%N with (2^3)%N; rewrite <-N.pow_add_r.
- change 3%N with (N.of_nat 3); rewrite <-Nnat.Nat2N.inj_add.
- intro H; injection H; intros ->; clear H.
- fold (4 * n)%nat.
- unfold of_hexadecimal.
- rewrite DecimalZ.of_to.
- simpl nb_digits; rewrite Nat2Z.inj_0, Z.mul_0_r, Z.sub_0_r.
- now apply f_equal2; [rewrite app_int_nil_r, of_to|].
+ intro d.
+ case q as [num den|q q'|q q']; simpl.
+ - generalize (of_IQmake_to_hexadecimal' num den).
+ case IQmake_to_hexadecimal' as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ now intros H H'; injection H'; clear H'; intros <-.
+ - case q as [num den| |]; [|now simpl..].
+ case q' as [num' den'| |]; [|now simpl..].
+ case num' as [z p| | |]; [|now simpl..].
+ case (Z.eq_dec z 2); [intros->|].
+ 2:{ case z; [now simpl| |now simpl]; intro pz'.
+ case pz'; [intros d0..| ]; [now simpl| |now simpl].
+ now case d0. }
+ case (Pos.eq_dec den' 1%positive); [intros->|now case den'].
+ generalize (of_IQmake_to_hexadecimal' num den).
+ case IQmake_to_hexadecimal' as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ intros <-; clear num den.
+ intros H; injection H; clear H; intros<-.
+ unfold of_hexadecimal; simpl.
+ now unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
+ - case q as [num den| |]; [|now simpl..].
+ case q' as [num' den'| |]; [|now simpl..].
+ case num' as [z p| | |]; [|now simpl..].
+ case (Z.eq_dec z 2); [intros->|].
+ 2:{ case z; [now simpl| |now simpl]; intro pz'.
+ case pz'; [intros d0..| ]; [now simpl| |now simpl].
+ now case d0. }
+ case (Pos.eq_dec den' 1%positive); [intros->|now case den'].
+ generalize (of_IQmake_to_hexadecimal' num den).
+ case IQmake_to_hexadecimal' as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ intros <-; clear num den.
+ intros H; injection H; clear H; intros<-.
+ unfold of_hexadecimal; simpl.
+ now unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
Qed.
-(* normalize without fractional part, for instance norme 0x1.2p-1 is 0x12e-5 *)
-Definition hnorme (d:hexadecimal) : hexadecimal :=
- let '(i, f, e) :=
- match d with
- | Hexadecimal i f => (i, f, Decimal.Pos Decimal.Nil)
- | HexadecimalExp i f e => (i, f, e)
+
+Definition dnorm (d:hexadecimal) : hexadecimal :=
+ let norm_i i f :=
+ match i with
+ | Pos i => Pos (unorm i)
+ | Neg i => match nzhead (app i f) with Nil => Pos zero | _ => Neg (unorm i) end
end in
- let i := norm (app_int i f) in
- let e := (Z.of_int e - 4 * Z.of_nat (nb_digits f))%Z in
- match e with
- | Z0 => Hexadecimal i Nil
- | Zpos e => Hexadecimal (Pos.iter double i e) Nil
- | Zneg _ => HexadecimalExp i Nil (Decimal.norm (Z.to_int e))
+ match d with
+ | Hexadecimal i f => Hexadecimal (norm_i i f) f
+ | HexadecimalExp i f e =>
+ match Decimal.norm e with
+ | Decimal.Pos Decimal.zero => Hexadecimal (norm_i i f) f
+ | e => HexadecimalExp (norm_i i f) f e
+ end
end.
-Lemma hnorme_spec d :
- match hnorme d with
- | Hexadecimal i Nil => i = norm i
- | HexadecimalExp i Nil e =>
- i = norm i /\ e = Decimal.norm e /\ e <> Decimal.Pos Decimal.zero
- | _ => False
+Lemma dnorm_spec_i d :
+ let (i, f) :=
+ match d with Hexadecimal i f => (i, f) | HexadecimalExp i f _ => (i, f) end in
+ let i' := match dnorm d with Hexadecimal i _ => i | HexadecimalExp i _ _ => i end in
+ match i with
+ | Pos i => i' = Pos (unorm i)
+ | Neg i =>
+ (i' = Neg (unorm i) /\ (nzhead i <> Nil \/ nzhead f <> Nil))
+ \/ (i' = Pos zero /\ (nzhead i = Nil /\ nzhead f = Nil))
end.
Proof.
- case d; clear d; intros i f; [|intro e]; unfold hnorme; simpl.
- - case_eq (nb_digits f); [now simpl; rewrite norm_invol|]; intros nf Hnf.
- split; [now simpl; rewrite norm_invol|].
- unfold Z.of_nat.
- now rewrite <-!DecimalZ.to_of, !DecimalZ.of_to.
- - set (e' := (_ - _)%Z).
- case_eq e'; [|intro pe'..]; intro He'.
- + now rewrite norm_invol.
- + rewrite Pos2Nat.inj_iter.
- set (ne' := Pos.to_nat pe').
- fold (Nat.iter ne' double (norm (app_int i f))).
- induction ne'; [now simpl; rewrite norm_invol|].
- now rewrite Unsigned.nat_iter_S, <-double_norm, IHne', norm_invol.
- + split; [now rewrite norm_invol|].
- split; [now rewrite DecimalFacts.norm_invol|].
- rewrite <-DecimalZ.to_of, DecimalZ.of_to.
- change (Decimal.Pos _) with (Z.to_int 0).
- now intro H; generalize (DecimalZ.to_int_inj _ _ H).
+ case d as [i f|i f e]; case i as [i|i].
+ - now simpl.
+ - simpl; case (uint_eq_dec (nzhead (app i f)) Nil); intro Ha.
+ + rewrite Ha; right; split; [now simpl|split].
+ * now unfold unorm; rewrite (nzhead_app_nil_l _ _ Ha).
+ * now unfold unorm; rewrite (nzhead_app_nil_r _ _ Ha).
+ + left; split; [now revert Ha; case nzhead|].
+ case (uint_eq_dec (nzhead i) Nil).
+ * intro Hi; right; intro Hf; apply Ha.
+ now rewrite <-nzhead_app_nzhead, Hi, app_nil_l.
+ * now intro H; left.
+ - simpl; case (Decimal.norm e); clear e; intro e; [|now simpl].
+ now case e; clear e; [|intro e..]; [|case e|..].
+ - simpl.
+ set (m := match nzhead _ with Nil => _ | _ => _ end).
+ set (m' := match _ with Hexadecimal _ _ => _ | _ => _ end).
+ replace m' with m.
+ 2:{ unfold m'; case (Decimal.norm e); clear m' e; intro e; [|now simpl].
+ now case e; clear e; [|intro e..]; [|case e|..]. }
+ unfold m; case (uint_eq_dec (nzhead (app i f)) Nil); intro Ha.
+ + rewrite Ha; right; split; [now simpl|split].
+ * now unfold unorm; rewrite (nzhead_app_nil_l _ _ Ha).
+ * now unfold unorm; rewrite (nzhead_app_nil_r _ _ Ha).
+ + left; split; [now revert Ha; case nzhead|].
+ case (uint_eq_dec (nzhead i) Nil).
+ * intro Hi; right; intro Hf; apply Ha.
+ now rewrite <-nzhead_app_nzhead, Hi, app_nil_l.
+ * now intro H; left.
Qed.
-Lemma hnorme_invol d : hnorme (hnorme d) = hnorme d.
+Lemma dnorm_spec_f d :
+ let f := match d with Hexadecimal _ f => f | HexadecimalExp _ f _ => f end in
+ let f' := match dnorm d with Hexadecimal _ f => f | HexadecimalExp _ f _ => f end in
+ f' = f.
+Proof.
+ case d as [i f|i f e]; [now simpl|].
+ simpl; case (Decimal.int_eq_dec (Decimal.norm e) (Decimal.Pos Decimal.zero)); [now intros->|intro He].
+ set (i' := match i with Pos _ => _ | _ => _ end).
+ set (m := match Decimal.norm e with Decimal.Pos _ => _ | _ => _ end).
+ replace m with (HexadecimalExp i' f (Decimal.norm e)); [now simpl|].
+ unfold m; revert He; case (Decimal.norm e); clear m e; intro e; [|now simpl].
+ now case e; clear e; [|intro e; case e|..].
+Qed.
+
+Lemma dnorm_spec_e d :
+ match d, dnorm d with
+ | Hexadecimal _ _, Hexadecimal _ _ => True
+ | HexadecimalExp _ _ e, Hexadecimal _ _ =>
+ Decimal.norm e = Decimal.Pos Decimal.zero
+ | HexadecimalExp _ _ e, HexadecimalExp _ _ e' =>
+ e' = Decimal.norm e /\ e' <> Decimal.Pos Decimal.zero
+ | Hexadecimal _ _, HexadecimalExp _ _ _ => False
+ end.
Proof.
- case d; clear d; intros i f; [|intro e]; unfold hnorme; simpl.
- - case_eq (nb_digits f); [now simpl; rewrite app_int_nil_r, norm_invol|].
- intros nf Hnf.
- unfold Z.of_nat.
- simpl.
- set (pnf := Pos.to_uint _).
- set (nz := Decimal.nzhead pnf).
- assert (Hnz : nz <> Decimal.Nil).
- { unfold nz, pnf.
- rewrite <-DecimalFacts.unorm_0.
- rewrite <-DecimalPos.Unsigned.to_of.
- rewrite DecimalPos.Unsigned.of_to.
- change Decimal.zero with (N.to_uint 0).
- now intro H; generalize (DecimalN.Unsigned.to_uint_inj _ _ H). }
- set (m := match nz with Decimal.Nil => _ | _ => _ end).
- assert (Hm : m = (Decimal.Neg (Decimal.unorm pnf))).
- { now revert Hnz; unfold m, nz, Decimal.unorm; fold nz; case nz. }
- rewrite Hm; unfold pnf.
- rewrite <-DecimalPos.Unsigned.to_of, DecimalPos.Unsigned.of_to.
- simpl; unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to.
- rewrite Z.sub_0_r; simpl.
- fold pnf; fold nz; fold m; rewrite Hm; unfold pnf.
- rewrite <-DecimalPos.Unsigned.to_of, DecimalPos.Unsigned.of_to.
- now rewrite app_int_nil_r, norm_invol.
- - set (e' := (_ - _)%Z).
- case_eq e'; [|intro pe'..]; intro Hpe'.
- + now simpl; rewrite app_int_nil_r, norm_invol.
- + simpl; rewrite app_int_nil_r.
- apply f_equal2; [|reflexivity].
- rewrite Pos2Nat.inj_iter.
- set (ne' := Pos.to_nat pe').
- fold (Nat.iter ne' double (norm (app_int i f))).
- induction ne'; [now simpl; rewrite norm_invol|].
- now rewrite Unsigned.nat_iter_S, <-double_norm, IHne'.
- + rewrite <-DecimalZ.to_of, !DecimalZ.of_to; simpl.
- rewrite app_int_nil_r, norm_invol.
- set (pnf := Pos.to_uint _).
- set (nz := Decimal.nzhead pnf).
- assert (Hnz : nz <> Decimal.Nil).
- { unfold nz, pnf.
- rewrite <-DecimalFacts.unorm_0.
- rewrite <-DecimalPos.Unsigned.to_of.
- rewrite DecimalPos.Unsigned.of_to.
- change Decimal.zero with (N.to_uint 0).
- now intro H; generalize (DecimalN.Unsigned.to_uint_inj _ _ H). }
- set (m := match nz with Decimal.Nil => _ | _ => _ end).
- assert (Hm : m = (Decimal.Neg (Decimal.unorm pnf))).
- { now revert Hnz; unfold m, nz, Decimal.unorm; fold nz; case nz. }
- rewrite Hm; unfold pnf.
- now rewrite <-DecimalPos.Unsigned.to_of, DecimalPos.Unsigned.of_to.
+ case d as [i f|i f e]; [now simpl|].
+ simpl; case (Decimal.int_eq_dec (Decimal.norm e) (Decimal.Pos Decimal.zero)); [now intros->|intro He].
+ set (i' := match i with Pos _ => _ | _ => _ end).
+ set (m := match Decimal.norm e with Decimal.Pos _ => _ | _ => _ end).
+ replace m with (HexadecimalExp i' f (Decimal.norm e)); [now simpl|].
+ unfold m; revert He; case (Decimal.norm e); clear m e; intro e; [|now simpl].
+ now case e; clear e; [|intro e; case e|..].
Qed.
-Lemma to_of (d:hexadecimal) :
- to_hexadecimal (of_hexadecimal d) = Some (hnorme d).
+Lemma dnorm_involutive d : dnorm (dnorm d) = dnorm d.
Proof.
- unfold to_hexadecimal.
- pose (t10 := fun y => (y~0~0~0~0)%positive).
- assert (H : exists h e_den,
- Hexadecimal.nztail (Pos.to_hex_uint (Qden (of_hexadecimal d)))
- = (h, e_den)
- /\ (h = D1 Nil \/ h = D2 Nil \/ h = D4 Nil \/ h = D8 Nil)).
- { assert (H : forall p,
- Hexadecimal.nztail (Pos.to_hex_uint (Pos.iter (Pos.mul 2) 1%positive p))
- = ((match (Pos.to_nat p) mod 4 with 0%nat => D1 | 1 => D2 | 2 => D4 | _ => D8 end)%nat Nil,
- (Pos.to_nat p / 4)%nat)).
- { intro p; clear d; rewrite Pos2Nat.inj_iter.
- fold (Nat.iter (Pos.to_nat p) (Pos.mul 2) 1%positive).
- set (n := Pos.to_nat p).
- fold (Nat.iter n t10 1%positive).
- set (nm4 := (n mod 4)%nat); set (nd4 := (n / 4)%nat).
- rewrite (Nat.div_mod n 4); [|now simpl].
- unfold nm4, nd4; clear nm4 nd4.
- generalize (Nat.mod_upper_bound n 4 ltac:(now simpl)).
- generalize (n mod 4); generalize (n / 4)%nat.
- intros d r Hr; clear p n.
- induction d.
- { simpl; revert Hr.
- do 4 (case r; [now simpl|clear r; intro r]).
- intro H; exfalso.
- now do 4 (generalize (lt_S_n _ _ H); clear H; intro H). }
- rewrite Nat.mul_succ_r, <-Nat.add_assoc, (Nat.add_comm 4), Nat.add_assoc.
- rewrite (Nat.add_comm _ 4).
- change (4 + _)%nat with (S (S (S (S (4 * d + r))))).
- rewrite !Unsigned.nat_iter_S.
- rewrite !Pos.mul_assoc.
- unfold Pos.to_hex_uint.
- change (2 * 2 * 2 * 2)%positive with 0x10%positive.
- set (n := Nat.iter _ _ _).
- change (Pos.to_little_hex_uint _) with (Unsigned.to_lu (16 * N.pos n)).
- rewrite Unsigned.to_lhex_tenfold.
- unfold Hexadecimal.nztail; rewrite rev_rev.
- rewrite <-(rev_rev (Unsigned.to_lu _)).
- set (m := _ (rev _)).
- replace m with (let (r, n) := let (r, n) := m in (rev r, n) in (rev r, n)).
- 2:{ now case m; intros r' n'; rewrite rev_rev. }
- change (let (r, n) := m in (rev r, n))
- with (Hexadecimal.nztail (Pos.to_hex_uint n)).
- now unfold n; rewrite IHd, rev_rev; clear n m. }
- unfold of_hexadecimal.
- case d; intros i f; [|intro e]; unfold of_hexadecimal; simpl.
- - case (Z.of_nat _)%Z; [|intro p..];
- [now exists (D1 Nil), O; split; [|left]
- | |now exists (D1 Nil), O; split; [|left]].
- exists (D1 Nil), (Pos.to_nat p).
- split; [|now left]; simpl.
- change (Pos.iter _ _ _) with (Pos.iter (Pos.mul 2) 1%positive (4 * p)).
- rewrite H.
- rewrite Pos2Nat.inj_mul, Nat.mul_comm, Nat.div_mul; [|now simpl].
- now rewrite Nat.mod_mul; [|now simpl].
- - case (_ - _)%Z; [|intros p..]; [now exists (D1 Nil), O; split; [|left]..|].
- simpl Qden; rewrite H.
- eexists; eexists; split; [reflexivity|].
- case (_ mod _); [now left|intro n].
- case n; [now right; left|clear n; intro n].
- case n; [now right; right; left|clear n; intro n].
- now right; right; right. }
- generalize (HexadecimalPos.Unsigned.nztail_to_hex_uint (Qden (of_hexadecimal d))).
- destruct H as (h, (e, (He, Hh))); rewrite He; clear He.
- assert (Hn1 : forall p, N.pos (Pos.iter (Pos.mul 2) 1%positive p) = 1%N -> False).
- { intro p.
- rewrite Pos2Nat.inj_iter.
- case_eq (Pos.to_nat p); [|now simpl].
- intro H; exfalso; apply (lt_irrefl O).
- rewrite <-H at 2; apply Pos2Nat.is_pos. }
- assert (H16_2 : forall p, (16^p = 2^(4 * p))%positive).
- { intro p.
- apply (@f_equal _ _ (fun z => match z with Z.pos p => p | _ => 1%positive end)
- (Z.pos _) (Z.pos _)).
- rewrite !Pos2Z.inj_pow_pos, !Z.pow_pos_fold, Pos2Z.inj_mul.
- now change 16%Z with (2^4)%Z; rewrite <-Z.pow_mul_r. }
- assert (HN16_2 : forall n, (16^n = 2^(4 * n))%N).
- { intro n.
- apply N2Z.inj; rewrite !N2Z.inj_pow, N2Z.inj_mul.
- change (Z.of_N 16) with (2^4)%Z.
- now rewrite <-Z.pow_mul_r; [| |apply N2Z.is_nonneg]. }
- assert (Hn1' : forall p, N.pos (Pos.iter (Pos.mul 16) 1%positive p) = 1%N -> False).
- { intro p; fold (16^p)%positive; rewrite H16_2; apply Hn1. }
- assert (Ht10inj : forall n m, t10 n = t10 m -> n = m).
- { intros n m H; generalize (f_equal Z.pos H); clear H.
- change (Z.pos (t10 n)) with (Z.mul 0x10 (Z.pos n)).
- change (Z.pos (t10 m)) with (Z.mul 0x10 (Z.pos m)).
- rewrite Z.mul_comm, (Z.mul_comm 0x10).
- intro H; generalize (f_equal (fun z => Z.div z 0x10) H); clear H.
- now rewrite !Z.div_mul; [|now simpl..]; intro H; inversion H. }
- assert (Ht2inj : forall n m, Pos.mul 2 n = Pos.mul 2 m -> n = m).
- { intros n m H; generalize (f_equal Z.pos H); clear H.
- change (Z.pos (Pos.mul 2 n)) with (Z.mul 2 (Z.pos n)).
- change (Z.pos (Pos.mul 2 m)) with (Z.mul 2 (Z.pos m)).
- rewrite Z.mul_comm, (Z.mul_comm 2).
- intro H; generalize (f_equal (fun z => Z.div z 2) H); clear H.
- now rewrite !Z.div_mul; [|now simpl..]; intro H; inversion H. }
- assert (Hinj : forall n m,
- Nat.iter n (Pos.mul 2) 1%positive = Nat.iter m (Pos.mul 2) 1%positive
- -> n = m).
- { induction n; [now intro m; case m|].
- intro m; case m; [now simpl|]; clear m; intro m.
- rewrite !Unsigned.nat_iter_S.
- intro H; generalize (Ht2inj _ _ H); clear H; intro H.
- now rewrite (IHn _ H). }
- change 4%Z with (Z.of_nat 4); rewrite <-Nat2Z.inj_mul.
- change 1%Z with (Z.of_nat 1); rewrite <-Nat2Z.inj_add.
- change 2%Z with (Z.of_nat 2); rewrite <-Nat2Z.inj_add.
- change 3%Z with (Z.of_nat 3); rewrite <-Nat2Z.inj_add.
- destruct Hh as [Hh|[Hh|[Hh|Hh]]]; rewrite Hh; clear h Hh.
- - case e; clear e; [|intro e]; simpl; unfold of_hexadecimal, hnorme.
- + case d; clear d; intros i f; [|intro e].
- * generalize (nb_digits_pos f).
- case f;
- [|now clear f; intro f; intros H1 H2; exfalso; revert H1 H2;
- case nb_digits;
- [intros H _; apply (lt_irrefl O), H|intros n _; apply Hn1]..].
- now intros _ _; simpl; rewrite to_of.
- * rewrite <-DecimalZ.to_of, DecimalZ.of_to.
- set (emf := (_ - _)%Z).
- case_eq emf; [|intro pemf..].
- ++ now simpl; rewrite to_of.
- ++ intros Hemf _; simpl.
- apply f_equal, f_equal2; [|reflexivity].
- rewrite !Pos2Nat.inj_iter.
- fold (Nat.iter (Pos.to_nat pemf) (Z.mul 2) (Z.of_hex_int (app_int i f))).
- fold (Nat.iter (Pos.to_nat pemf) double (norm (app_int i f))).
- induction Pos.to_nat; [now simpl; rewrite HexadecimalZ.to_of|].
- now rewrite !Unsigned.nat_iter_S, <-IHn, double_to_hex_int.
- ++ simpl Qden; intros _ H; exfalso; revert H; apply Hn1.
- + case d; clear d; intros i f; [|intro e'].
- * simpl; case_eq (nb_digits f); [|intros nf' Hnf'];
- [now simpl; intros _ H; exfalso; symmetry in H; revert H; apply Hn1'|].
- unfold Z.of_nat, Z.opp, Qnum, Qden.
- rewrite H16_2.
- fold (Pos.mul 2); fold (2^(Pos.of_succ_nat nf')~0~0)%positive.
- intro H; injection H; clear H.
- unfold Pos.pow; rewrite !Pos2Nat.inj_iter.
- intro H; generalize (Hinj _ _ H); clear H; intro H.
- generalize (Pos2Nat.inj _ _ H); clear H; intro H; injection H.
- clear H; intro H; generalize (SuccNat2Pos.inj _ _ H); clear H.
- intros <-.
- rewrite to_of.
- rewrite <-DecimalZ.to_of, DecimalZ.of_to; simpl.
- do 4 apply f_equal.
- apply Pos2Nat.inj.
- rewrite SuccNat2Pos.id_succ.
- change (_~0)%positive with (4 * Pos.of_succ_nat nf')%positive.
- now rewrite Pos2Nat.inj_mul, SuccNat2Pos.id_succ.
- * set (nemf := (_ - _)%Z); intro H.
- assert (H' : exists pnemf, nemf = Z.neg pnemf); [|revert H].
- { revert H; case nemf; [|intro pnemf..]; [..|now intros _; exists pnemf];
- simpl Qden; intro H; exfalso; symmetry in H; revert H; apply Hn1'. }
- destruct H' as (pnemf,Hpnemf); rewrite Hpnemf.
- unfold Qnum, Qden.
- rewrite H16_2.
- intro H; injection H; clear H; unfold Pos.pow; rewrite !Pos2Nat.inj_iter.
- intro H; generalize (Hinj _ _ H); clear H; intro H.
- generalize (Pos2Nat.inj _ _ H); clear H.
- intro H; revert Hpnemf; rewrite H; clear pnemf H; intro Hnemf.
- rewrite to_of.
- rewrite <-DecimalZ.to_of, DecimalZ.of_to; simpl.
- do 4 apply f_equal.
- apply Pos2Nat.inj.
- rewrite SuccNat2Pos.id_succ.
- change (_~0)%positive with (4 * Pos.of_succ_nat e)%positive.
- now rewrite Pos2Nat.inj_mul, SuccNat2Pos.id_succ.
- - simpl Pos.of_hex_uint.
- rewrite HN16_2.
- rewrite <-N.pow_succ_r; [|now apply N.le_0_l].
- rewrite <-N.succ_pos_spec.
- case d; clear d; intros i f; [|intro e']; unfold of_hexadecimal, hnorme.
- + set (em4f := (_ - _)%Z).
- case_eq em4f; [|intros pem4f..]; intro Hpem4f;
- [now simpl; intros H; exfalso; symmetry in H; revert H; apply Hn1..|].
- unfold Qnum, Qden.
- intro H; injection H; clear H; unfold Pos.pow; rewrite !Pos2Nat.inj_iter.
- intro H; generalize (Hinj _ _ H); clear H; intro H.
- generalize (Pos2Nat.inj _ _ H); clear H; intros ->.
- rewrite to_of.
- rewrite <-DecimalZ.to_of, DecimalZ.of_to; simpl.
- do 4 apply f_equal.
- apply Pos2Nat.inj.
- rewrite SuccNat2Pos.id_succ.
- case e; [now simpl|intro e'']; simpl.
- unfold Pos.to_nat; simpl.
- now rewrite Pmult_nat_mult, SuccNat2Pos.id_succ, Nat.mul_comm.
- + set (em4f := (_ - _)%Z).
- case_eq em4f; [|intros pem4f..]; intro Hpem4f;
- [now simpl; intros H; exfalso; symmetry in H; revert H; apply Hn1..|].
- unfold Qnum, Qden.
- intro H; injection H; clear H; unfold Pos.pow; rewrite !Pos2Nat.inj_iter.
- intro H; generalize (Hinj _ _ H); clear H; intro H.
- generalize (Pos2Nat.inj _ _ H); clear H; intros ->.
- rewrite to_of.
- rewrite <-DecimalZ.to_of, DecimalZ.of_to; simpl.
- do 4 apply f_equal.
- apply Pos2Nat.inj.
- rewrite SuccNat2Pos.id_succ.
- case e; [now simpl|intro e'']; simpl.
- unfold Pos.to_nat; simpl.
- now rewrite Pmult_nat_mult, SuccNat2Pos.id_succ, Nat.mul_comm.
- - simpl Pos.of_hex_uint.
- rewrite HN16_2.
- change 4%N with (2 * 2)%N at 1; rewrite <-!N.mul_assoc.
- do 2 (rewrite <-N.pow_succ_r; [|now apply N.le_0_l]).
- rewrite <-N.succ_pos_spec.
- case d; clear d; intros i f; [|intro e']; unfold of_hexadecimal, hnorme.
- + set (em4f := (_ - _)%Z).
- case_eq em4f; [|intros pem4f..]; intro Hpem4f;
- [now simpl; intros H; exfalso; symmetry in H; revert H; apply Hn1..|].
- unfold Qnum, Qden.
- intro H; injection H; clear H; unfold Pos.pow; rewrite !Pos2Nat.inj_iter.
- intro H; generalize (Hinj _ _ H); clear H; intro H.
- generalize (Pos2Nat.inj _ _ H); clear H; intros ->.
- rewrite to_of.
- rewrite <-DecimalZ.to_of, DecimalZ.of_to; simpl.
- do 4 apply f_equal.
- apply Pos2Nat.inj.
- rewrite <-SuccNat2Pos.inj_succ.
- rewrite SuccNat2Pos.id_succ.
- case e; [now simpl|intro e'']; simpl.
- unfold Pos.to_nat; simpl.
- now rewrite Pmult_nat_mult, SuccNat2Pos.id_succ, Nat.mul_comm.
- + set (em4f := (_ - _)%Z).
- case_eq em4f; [|intros pem4f..]; intro Hpem4f;
- [now simpl; intros H; exfalso; symmetry in H; revert H; apply Hn1..|].
- unfold Qnum, Qden.
- intro H; injection H; clear H; unfold Pos.pow; rewrite !Pos2Nat.inj_iter.
- intro H; generalize (Hinj _ _ H); clear H; intro H.
- generalize (Pos2Nat.inj _ _ H); clear H; intros ->.
- rewrite to_of.
- rewrite <-DecimalZ.to_of, DecimalZ.of_to; simpl.
- do 4 apply f_equal.
- apply Pos2Nat.inj.
- rewrite <-SuccNat2Pos.inj_succ.
- rewrite SuccNat2Pos.id_succ.
- case e; [now simpl|intro e'']; simpl.
- unfold Pos.to_nat; simpl.
- now rewrite Pmult_nat_mult, SuccNat2Pos.id_succ, Nat.mul_comm.
- - simpl Pos.of_hex_uint.
- rewrite HN16_2.
- change 8%N with (2 * 2 * 2)%N; rewrite <-!N.mul_assoc.
- do 3 (rewrite <-N.pow_succ_r; [|now apply N.le_0_l]).
- rewrite <-N.succ_pos_spec.
- case d; clear d; intros i f; [|intro e']; unfold of_hexadecimal, hnorme.
- + set (em4f := (_ - _)%Z).
- case_eq em4f; [|intros pem4f..]; intro Hpem4f;
- [now simpl; intros H; exfalso; symmetry in H; revert H; apply Hn1..|].
- unfold Qnum, Qden.
- intro H; injection H; clear H; unfold Pos.pow; rewrite !Pos2Nat.inj_iter.
- intro H; generalize (Hinj _ _ H); clear H; intro H.
- generalize (Pos2Nat.inj _ _ H); clear H; intros ->.
- rewrite to_of.
- rewrite <-DecimalZ.to_of, DecimalZ.of_to; simpl.
- do 4 apply f_equal.
- apply Pos2Nat.inj.
- rewrite <-!SuccNat2Pos.inj_succ.
- rewrite SuccNat2Pos.id_succ.
- case e; [now simpl|intro e'']; simpl.
- unfold Pos.to_nat; simpl.
- now rewrite Pmult_nat_mult, SuccNat2Pos.id_succ, Nat.mul_comm.
- + set (em4f := (_ - _)%Z).
- case_eq em4f; [|intros pem4f..]; intro Hpem4f;
- [now simpl; intros H; exfalso; symmetry in H; revert H; apply Hn1..|].
- unfold Qnum, Qden.
- intro H; injection H; clear H; unfold Pos.pow; rewrite !Pos2Nat.inj_iter.
- intro H; generalize (Hinj _ _ H); clear H; intro H.
- generalize (Pos2Nat.inj _ _ H); clear H; intros ->.
- rewrite to_of.
- rewrite <-DecimalZ.to_of, DecimalZ.of_to; simpl.
- do 4 apply f_equal.
- apply Pos2Nat.inj.
- rewrite <-!SuccNat2Pos.inj_succ.
- rewrite SuccNat2Pos.id_succ.
- case e; [now simpl|intro e'']; simpl.
- unfold Pos.to_nat; simpl.
- now rewrite Pmult_nat_mult, SuccNat2Pos.id_succ, Nat.mul_comm.
+ case d as [i f|i f e]; case i as [i|i].
+ - now simpl; rewrite unorm_involutive.
+ - simpl; case (uint_eq_dec (nzhead (app i f)) Nil); [now intros->|intro Ha].
+ set (m := match nzhead _ with Nil =>_ | _ => _ end).
+ replace m with (Neg (unorm i)).
+ 2:{ now unfold m; revert Ha; case nzhead. }
+ case (uint_eq_dec (nzhead i) Nil); intro Hi.
+ + unfold unorm; rewrite Hi; simpl.
+ case (uint_eq_dec (nzhead f) Nil).
+ * intro Hf; exfalso; apply Ha.
+ now rewrite <-nzhead_app_nzhead, Hi, app_nil_l.
+ * now case nzhead.
+ + rewrite unorm_involutive, (unorm_nzhead _ Hi), nzhead_app_nzhead.
+ now revert Ha; case nzhead.
+ - simpl; case (Decimal.int_eq_dec (Decimal.norm e) (Decimal.Pos Decimal.zero)); intro He.
+ + now rewrite He; simpl; rewrite unorm_involutive.
+ + set (m := match Decimal.norm e with Decimal.Pos _ => _ | _ => _ end).
+ replace m with (HexadecimalExp (Pos (unorm i)) f (Decimal.norm e)).
+ 2:{ unfold m; revert He; case (Decimal.norm e); clear m e; intro e; [|now simpl].
+ now case e; clear e; [|intro e; case e|..]. }
+ simpl; rewrite DecimalFacts.norm_involutive, unorm_involutive.
+ revert He; case (Decimal.norm e); clear m e; intro e; [|now simpl].
+ now case e; clear e; [|intro e; case e|..].
+ - simpl; case (Decimal.int_eq_dec (Decimal.norm e) (Decimal.Pos Decimal.zero)); intro He.
+ + rewrite He; simpl.
+ case (uint_eq_dec (nzhead (app i f)) Nil); [now intros->|intro Ha].
+ set (m := match nzhead _ with Nil =>_ | _ => _ end).
+ replace m with (Neg (unorm i)).
+ 2:{ now unfold m; revert Ha; case nzhead. }
+ case (uint_eq_dec (nzhead i) Nil); intro Hi.
+ * unfold unorm; rewrite Hi; simpl.
+ case (uint_eq_dec (nzhead f) Nil).
+ -- intro Hf; exfalso; apply Ha.
+ now rewrite <-nzhead_app_nzhead, Hi, app_nil_l.
+ -- now case nzhead.
+ * rewrite unorm_involutive, (unorm_nzhead _ Hi), nzhead_app_nzhead.
+ now revert Ha; case nzhead.
+ + set (m := match Decimal.norm e with Decimal.Pos _ => _ | _ => _ end).
+ pose (i' := match nzhead (app i f) with Nil => Pos zero | _ => Neg (unorm i) end).
+ replace m with (HexadecimalExp i' f (Decimal.norm e)).
+ 2:{ unfold m; revert He; case (Decimal.norm e); clear m e; intro e; [|now simpl].
+ now case e; clear e; [|intro e; case e|..]. }
+ simpl; rewrite DecimalFacts.norm_involutive.
+ set (i'' := match i' with Pos _ => _ | _ => _ end).
+ clear m; set (m := match Decimal.norm e with Decimal.Pos _ => _ | _ => _ end).
+ replace m with (HexadecimalExp i'' f (Decimal.norm e)).
+ 2:{ unfold m; revert He; case (Decimal.norm e); clear m e; intro e; [|now simpl].
+ now case e; clear e; [|intro e; case e|..]. }
+ unfold i'', i'.
+ case (uint_eq_dec (nzhead (app i f)) Nil); [now intros->|intro Ha].
+ fold i'; replace i' with (Neg (unorm i)).
+ 2:{ now unfold i'; revert Ha; case nzhead. }
+ case (uint_eq_dec (nzhead i) Nil); intro Hi.
+ * unfold unorm; rewrite Hi; simpl.
+ case (uint_eq_dec (nzhead f) Nil).
+ -- intro Hf; exfalso; apply Ha.
+ now rewrite <-nzhead_app_nzhead, Hi, app_nil_l.
+ -- now case nzhead.
+ * rewrite unorm_involutive, (unorm_nzhead _ Hi), nzhead_app_nzhead.
+ now revert Ha; case nzhead.
+Qed.
+
+Lemma IZ_to_Z_IZ_of_Z z : IZ_to_Z (IZ_of_Z z) = Some z.
+Proof. now case z. Qed.
+
+Lemma dnorm_i_exact i f :
+ (nb_digits f < nb_digits (unorm (app (abs i) f)))%nat ->
+ match i with
+ | Pos i => Pos (unorm i)
+ | Neg i =>
+ match nzhead (app i f) with
+ | Nil => Pos zero
+ | _ => Neg (unorm i)
+ end
+ end = norm i.
+Proof.
+ case i as [ni|ni]; [now simpl|]; simpl.
+ case (uint_eq_dec (nzhead (app ni f)) Nil); intro Ha.
+ { now rewrite Ha, (nzhead_app_nil_l _ _ Ha). }
+ rewrite (unorm_nzhead _ Ha).
+ set (m := match nzhead _ with Nil => _ | _ => _ end).
+ replace m with (Neg (unorm ni)); [|now unfold m; revert Ha; case nzhead].
+ case (uint_eq_dec (nzhead ni) Nil); intro Hni.
+ { rewrite <-nzhead_app_nzhead, Hni, app_nil_l.
+ intro H; exfalso; revert H; apply le_not_lt, nb_digits_nzhead. }
+ clear m; set (m := match nzhead ni with Nil => _ | _ => _ end).
+ replace m with (Neg (nzhead ni)); [|now unfold m; revert Hni; case nzhead].
+ now rewrite (unorm_nzhead _ Hni).
+Qed.
+
+Lemma dnorm_i_exact' i f :
+ (nb_digits (unorm (app (abs i) f)) <= nb_digits f)%nat ->
+ match i with
+ | Pos i => Pos (unorm i)
+ | Neg i =>
+ match nzhead (app i f) with
+ | Nil => Pos zero
+ | _ => Neg (unorm i)
+ end
+ end =
+ match norm (app_int i f) with
+ | Pos _ => Pos zero
+ | Neg _ => Neg zero
+ end.
+Proof.
+ case i as [ni|ni]; simpl.
+ { now intro Hnb; rewrite (unorm_app_zero _ _ Hnb). }
+ unfold unorm.
+ case (uint_eq_dec (nzhead (app ni f)) Nil); intro Hn.
+ { now rewrite Hn. }
+ set (m := match nzhead _ with Nil => _ | _ => _ end).
+ replace m with (nzhead (app ni f)).
+ 2:{ now unfold m; revert Hn; case nzhead. }
+ clear m; set (m := match nzhead _ with Nil => _ | _ => _ end).
+ replace m with (Neg (unorm ni)).
+ 2:{ now unfold m, unorm; revert Hn; case nzhead. }
+ clear m; set (m := match nzhead _ with Nil => _ | _ => _ end).
+ replace m with (Neg (nzhead (app ni f))).
+ 2:{ now unfold m; revert Hn; case nzhead. }
+ rewrite <-(unorm_nzhead _ Hn).
+ now intro H; rewrite (unorm_app_zero _ _ H).
+Qed.
+
+Lemma to_of (d:hexadecimal) : to_hexadecimal (of_hexadecimal d) = Some (dnorm d).
+Proof.
+ case d as [i f|i f e].
+ - unfold of_hexadecimal; simpl; unfold IQmake_to_hexadecimal'.
+ rewrite IZ_to_Z_IZ_of_Z.
+ unfold IQmake_to_hexadecimal; simpl.
+ change (fun _ : positive => _) with (Pos.mul 16).
+ rewrite nztail_to_hex_uint_pow16, to_of.
+ case_eq (nb_digits f); [|intro nb]; intro Hnb.
+ + rewrite (nb_digits_0 _ Hnb), app_int_nil_r.
+ case i as [ni|ni]; [now simpl|].
+ rewrite app_nil_r; simpl; unfold unorm.
+ now case (nzhead ni).
+ + rewrite <-Hnb.
+ rewrite abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnb'.
+ * rewrite (del_tail_app_int_exact _ _ Hnb').
+ rewrite (del_head_app_int_exact _ _ Hnb').
+ now rewrite (dnorm_i_exact _ _ Hnb').
+ * rewrite (unorm_app_r _ _ Hnb').
+ rewrite iter_D0_unorm; [|now apply nb_digits_n0; rewrite Hnb].
+ now rewrite dnorm_i_exact'.
+ - unfold of_hexadecimal; simpl.
+ rewrite <-DecimalZ.to_of.
+ case (Z.of_int e); clear e; [|intro e..]; simpl.
+ + unfold IQmake_to_hexadecimal'.
+ rewrite IZ_to_Z_IZ_of_Z.
+ unfold IQmake_to_hexadecimal; simpl.
+ change (fun _ : positive => _) with (Pos.mul 16).
+ rewrite nztail_to_hex_uint_pow16, to_of.
+ case_eq (nb_digits f); [|intro nb]; intro Hnb.
+ * rewrite (nb_digits_0 _ Hnb), app_int_nil_r.
+ case i as [ni|ni]; [now simpl|].
+ rewrite app_nil_r; simpl; unfold unorm.
+ now case (nzhead ni).
+ * rewrite <-Hnb.
+ rewrite abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnb'.
+ -- rewrite (del_tail_app_int_exact _ _ Hnb').
+ rewrite (del_head_app_int_exact _ _ Hnb').
+ now rewrite (dnorm_i_exact _ _ Hnb').
+ -- rewrite (unorm_app_r _ _ Hnb').
+ rewrite iter_D0_unorm; [|now apply nb_digits_n0; rewrite Hnb].
+ now rewrite dnorm_i_exact'.
+ + unfold IQmake_to_hexadecimal'.
+ rewrite IZ_to_Z_IZ_of_Z.
+ unfold IQmake_to_hexadecimal; simpl.
+ change (fun _ : positive => _) with (Pos.mul 16).
+ rewrite nztail_to_hex_uint_pow16, to_of.
+ generalize (DecimalPos.Unsigned.to_uint_nonzero e); intro He.
+ set (dnorm_i := match i with Pos _ => _ | _ => _ end).
+ set (m := match Pos.to_uint e with Decimal.Nil => _ | _ => _ end).
+ replace m with (HexadecimalExp dnorm_i f (Decimal.Pos (Pos.to_uint e))).
+ 2:{ now unfold m; revert He; case (Pos.to_uint e); [|intro u; case u|..]. }
+ clear m; unfold dnorm_i.
+ case_eq (nb_digits f); [|intro nb]; intro Hnb.
+ * rewrite (nb_digits_0 _ Hnb), app_int_nil_r.
+ case i as [ni|ni]; [now simpl|].
+ rewrite app_nil_r; simpl; unfold unorm.
+ now case (nzhead ni).
+ * rewrite <-Hnb.
+ rewrite abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnb'.
+ -- rewrite (del_tail_app_int_exact _ _ Hnb').
+ rewrite (del_head_app_int_exact _ _ Hnb').
+ now rewrite (dnorm_i_exact _ _ Hnb').
+ -- rewrite (unorm_app_r _ _ Hnb').
+ rewrite iter_D0_unorm; [|now apply nb_digits_n0; rewrite Hnb].
+ now rewrite dnorm_i_exact'.
+ + unfold IQmake_to_hexadecimal'.
+ rewrite IZ_to_Z_IZ_of_Z.
+ unfold IQmake_to_hexadecimal; simpl.
+ change (fun _ : positive => _) with (Pos.mul 16).
+ rewrite nztail_to_hex_uint_pow16, to_of.
+ case_eq (nb_digits f); [|intro nb]; intro Hnb.
+ * rewrite (nb_digits_0 _ Hnb), app_int_nil_r.
+ case i as [ni|ni]; [now simpl|].
+ rewrite app_nil_r; simpl; unfold unorm.
+ now case (nzhead ni).
+ * rewrite <-Hnb.
+ rewrite abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnb'.
+ -- rewrite (del_tail_app_int_exact _ _ Hnb').
+ rewrite (del_head_app_int_exact _ _ Hnb').
+ now rewrite (dnorm_i_exact _ _ Hnb').
+ -- rewrite (unorm_app_r _ _ Hnb').
+ rewrite iter_D0_unorm; [|now apply nb_digits_n0; rewrite Hnb].
+ now rewrite dnorm_i_exact'.
Qed.
(** Some consequences *)
@@ -466,68 +436,24 @@ Proof.
now intros d _ H1 H2; rewrite <-(H1 d eq_refl), <-(H2 d eq_refl).
Qed.
-Lemma to_hexadecimal_surj d : exists q, to_hexadecimal q = Some (hnorme d).
+Lemma to_hexadecimal_surj d : exists q, to_hexadecimal q = Some (dnorm d).
Proof.
exists (of_hexadecimal d). apply to_of.
Qed.
-Lemma of_hexadecimal_hnorme d : of_hexadecimal (hnorme d) = of_hexadecimal d.
-Proof.
- unfold of_hexadecimal, hnorme.
- destruct d.
- - simpl Z.of_int; unfold Z.of_uint, Z.of_N, Pos.of_uint.
- rewrite Z.sub_0_l.
- set (n4f := (- _)%Z).
- case_eq n4f; [|intro pn4f..]; intro Hn4f.
- + apply f_equal2; [|reflexivity].
- rewrite app_int_nil_r.
- now rewrite <-HexadecimalZ.to_of, HexadecimalZ.of_to.
- + apply f_equal2; [|reflexivity].
- rewrite app_int_nil_r.
- generalize (app_int i f); intro i'.
- rewrite !Pos2Nat.inj_iter.
- generalize (Pos.to_nat pn4f); intro n.
- fold (Nat.iter n double (norm i')).
- fold (Nat.iter n (Z.mul 2) (Z.of_hex_int i')).
- induction n; [now simpl; rewrite <-HexadecimalZ.to_of, HexadecimalZ.of_to|].
- now rewrite !Unsigned.nat_iter_S, <-IHn, of_hex_int_double.
- + unfold nb_digits, Z.of_nat.
- rewrite Z.mul_0_r, Z.sub_0_r.
- rewrite <-DecimalZ.to_of, !DecimalZ.of_to.
- rewrite app_int_nil_r.
- now rewrite <-HexadecimalZ.to_of, HexadecimalZ.of_to.
- - set (nem4f := (_ - _)%Z).
- case_eq nem4f; [|intro pnem4f..]; intro Hnem4f.
- + apply f_equal2; [|reflexivity].
- rewrite app_int_nil_r.
- now rewrite <-HexadecimalZ.to_of, HexadecimalZ.of_to.
- + apply f_equal2; [|reflexivity].
- rewrite app_int_nil_r.
- generalize (app_int i f); intro i'.
- rewrite !Pos2Nat.inj_iter.
- generalize (Pos.to_nat pnem4f); intro n.
- fold (Nat.iter n double (norm i')).
- fold (Nat.iter n (Z.mul 2) (Z.of_hex_int i')).
- induction n; [now simpl; rewrite <-HexadecimalZ.to_of, HexadecimalZ.of_to|].
- now rewrite !Unsigned.nat_iter_S, <-IHn, of_hex_int_double.
- + unfold nb_digits, Z.of_nat.
- rewrite Z.mul_0_r, Z.sub_0_r.
- rewrite <-DecimalZ.to_of, !DecimalZ.of_to.
- rewrite app_int_nil_r.
- now rewrite <-HexadecimalZ.to_of, HexadecimalZ.of_to.
-Qed.
+Lemma of_hexadecimal_dnorm d : of_hexadecimal (dnorm d) = of_hexadecimal d.
+Proof. now apply to_hexadecimal_inj; rewrite !to_of; [|rewrite dnorm_involutive]. Qed.
-Lemma of_inj d d' :
- of_hexadecimal d = of_hexadecimal d' -> hnorme d = hnorme d'.
+Lemma of_inj d d' : of_hexadecimal d = of_hexadecimal d' -> dnorm d = dnorm d'.
Proof.
- intros.
- cut (Some (hnorme d) = Some (hnorme d')); [now intro H'; injection H'|].
- rewrite <- !to_of. now f_equal.
+ intro H.
+ apply (@f_equal _ _ (fun x => match x with Some x => x | _ => d end)
+ (Some (dnorm d)) (Some (dnorm d'))).
+ now rewrite <- !to_of, H.
Qed.
-Lemma of_iff d d' :
- of_hexadecimal d = of_hexadecimal d' <-> hnorme d = hnorme d'.
+Lemma of_iff d d' : of_hexadecimal d = of_hexadecimal d' <-> dnorm d = dnorm d'.
Proof.
- split. apply of_inj. intros E. rewrite <- of_hexadecimal_hnorme, E.
- apply of_hexadecimal_hnorme.
+ split. apply of_inj. intros E. rewrite <- of_hexadecimal_dnorm, E.
+ apply of_hexadecimal_dnorm.
Qed.
diff --git a/theories/Numbers/HexadecimalR.v b/theories/Numbers/HexadecimalR.v
new file mode 100644
index 0000000000..2deecc5847
--- /dev/null
+++ b/theories/Numbers/HexadecimalR.v
@@ -0,0 +1,302 @@
+(************************************************************************)
+(* * The Coq Proof Assistant / The Coq Development Team *)
+(* v * Copyright INRIA, CNRS and contributors *)
+(* <O___,, * (see version control and CREDITS file for authors & dates) *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(* * (see LICENSE file for the text of the license) *)
+(************************************************************************)
+
+(** * HexadecimalR
+
+ Proofs that conversions between hexadecimal numbers and [R]
+ are bijections. *)
+
+Require Import Decimal DecimalFacts.
+Require Import Hexadecimal HexadecimalFacts HexadecimalPos HexadecimalZ.
+Require Import HexadecimalQ Rdefinitions.
+
+Lemma of_IQmake_to_hexadecimal num den :
+ match IQmake_to_hexadecimal num den with
+ | None => True
+ | Some (HexadecimalExp _ _ _) => False
+ | Some (Hexadecimal i f) =>
+ of_hexadecimal (Hexadecimal i f) = IRQ (QArith_base.Qmake num den)
+ end.
+Proof.
+ unfold IQmake_to_hexadecimal.
+ case (Pos.eq_dec den 1); [now intros->|intro Hden].
+ assert (Hf : match QArith_base.IQmake_to_hexadecimal num den with
+ | Some (Hexadecimal i f) => f <> Nil
+ | _ => True
+ end).
+ { unfold QArith_base.IQmake_to_hexadecimal; simpl.
+ generalize (Unsigned.nztail_to_hex_uint den).
+ case Hexadecimal.nztail as [den' e_den'].
+ case den'; [now simpl|now simpl| |now simpl..]; clear den'; intro den'.
+ case den'; [ |now simpl..]; clear den'.
+ case e_den' as [|e_den']; [now simpl; intros H _; apply Hden; injection H|].
+ intros _.
+ case Nat.ltb_spec; intro He_den'.
+ - apply del_head_nonnil.
+ revert He_den'; case nb_digits as [|n]; [now simpl|].
+ now intro H; simpl; apply le_lt_n_Sm, Nat.le_sub_l.
+ - apply nb_digits_n0.
+ now rewrite nb_digits_iter_D0, Nat.sub_add. }
+ replace (match den with 1%positive => _ | _ => _ end)
+ with (QArith_base.IQmake_to_hexadecimal num den); [|now revert Hden; case den].
+ generalize (of_IQmake_to_hexadecimal num den).
+ case QArith_base.IQmake_to_hexadecimal as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ unfold of_hexadecimal; simpl.
+ intro H; injection H; clear H; intros <-.
+ intro H; generalize (f_equal QArith_base.IZ_to_Z H); clear H.
+ rewrite !IZ_to_Z_IZ_of_Z; intro H; injection H; clear H; intros<-.
+ now revert Hf; case f.
+Qed.
+
+Lemma of_to (q:IR) : forall d, to_hexadecimal q = Some d -> of_hexadecimal d = q.
+Proof.
+ intro d.
+ case q as [z|q|r r'|r r']; simpl.
+ - case z as [z p| |p|p].
+ + now simpl.
+ + now simpl; intro H; injection H; clear H; intros<-.
+ + simpl; intro H; injection H; clear H; intros<-.
+ now unfold of_hexadecimal; simpl; unfold Z.of_hex_uint; rewrite Unsigned.of_to.
+ + simpl; intro H; injection H; clear H; intros<-.
+ now unfold of_hexadecimal; simpl; unfold Z.of_hex_uint; rewrite Unsigned.of_to.
+ - case q as [num den].
+ generalize (of_IQmake_to_hexadecimal num den).
+ case IQmake_to_hexadecimal as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ now intros H H'; injection H'; intros<-.
+ - case r as [z|q| |]; [|case q as[num den]|now simpl..];
+ (case r' as [z'| | |]; [|now simpl..]);
+ (case z' as [p e| | |]; [|now simpl..]).
+ + case (Z.eq_dec p 2); [intros->|intro Hp].
+ 2:{ now revert Hp; case p;
+ [|intro d0; case d0; [intro d1..|]; [|case d1|]..]. }
+ case z as [| |p|p]; [now simpl|..]; intro H; injection H; intros<-.
+ * now unfold of_hexadecimal; simpl; unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to.
+ * unfold of_hexadecimal; simpl; unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
+ now unfold Z.of_hex_uint; rewrite Unsigned.of_to.
+ * unfold of_hexadecimal; simpl; unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
+ now unfold Z.of_hex_uint; rewrite Unsigned.of_to.
+ + case (Z.eq_dec p 2); [intros->|intro Hp].
+ 2:{ now revert Hp; case p;
+ [|intro d0; case d0; [intro d1..|]; [|case d1|]..]. }
+ generalize (of_IQmake_to_hexadecimal num den).
+ case IQmake_to_hexadecimal as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ intros H H'; injection H'; clear H'; intros<-.
+ unfold of_hexadecimal; simpl.
+ change (match f with Nil => _ | _ => _ end) with (of_hexadecimal (Hexadecimal i f)).
+ rewrite H; clear H.
+ now unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to.
+ - case r as [z|q| |]; [|case q as[num den]|now simpl..];
+ (case r' as [z'| | |]; [|now simpl..]);
+ (case z' as [p e| | |]; [|now simpl..]).
+ + case (Z.eq_dec p 2); [intros->|intro Hp].
+ 2:{ now revert Hp; case p;
+ [|intro d0; case d0; [intro d1..|]; [|case d1|]..]. }
+ case z as [| |p|p]; [now simpl|..]; intro H; injection H; intros<-.
+ * now unfold of_hexadecimal; simpl; unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to.
+ * unfold of_hexadecimal; simpl; unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
+ now unfold Z.of_hex_uint; rewrite Unsigned.of_to.
+ * unfold of_hexadecimal; simpl; unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to; simpl.
+ now unfold Z.of_hex_uint; rewrite Unsigned.of_to.
+ + case (Z.eq_dec p 2); [intros->|intro Hp].
+ 2:{ now revert Hp; case p;
+ [|intro d0; case d0; [intro d1..|]; [|case d1|]..]. }
+ generalize (of_IQmake_to_hexadecimal num den).
+ case IQmake_to_hexadecimal as [d'|]; [|now simpl].
+ case d' as [i f|]; [|now simpl].
+ intros H H'; injection H'; clear H'; intros<-.
+ unfold of_hexadecimal; simpl.
+ change (match f with Nil => _ | _ => _ end) with (of_hexadecimal (Hexadecimal i f)).
+ rewrite H; clear H.
+ now unfold Z.of_uint; rewrite DecimalPos.Unsigned.of_to.
+Qed.
+
+Lemma to_of (d:hexadecimal) : to_hexadecimal (of_hexadecimal d) = Some (dnorm d).
+Proof.
+ case d as [i f|i f e].
+ - unfold of_hexadecimal; simpl.
+ case (uint_eq_dec f Nil); intro Hf.
+ + rewrite Hf; clear f Hf.
+ unfold to_hexadecimal; simpl.
+ rewrite IZ_to_Z_IZ_of_Z, HexadecimalZ.to_of.
+ case i as [i|i]; [now simpl|]; simpl.
+ rewrite app_nil_r.
+ case (uint_eq_dec (nzhead i) Nil); [now intros->|intro Hi].
+ now rewrite (unorm_nzhead _ Hi); revert Hi; case nzhead.
+ + set (r := IRQ _).
+ set (m := match f with Nil => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ unfold to_hexadecimal; simpl.
+ unfold IQmake_to_hexadecimal; simpl.
+ set (n := Nat.iter _ _ _).
+ case (Pos.eq_dec n 1); intro Hn.
+ exfalso; apply Hf.
+ { now apply nb_digits_0; revert Hn; unfold n; case nb_digits. }
+ clear m; set (m := match n with 1%positive | _ => _ end).
+ replace m with (QArith_base.IQmake_to_hexadecimal (Z.of_hex_int (app_int i f)) n).
+ 2:{ now unfold m; revert Hn; case n. }
+ unfold QArith_base.IQmake_to_hexadecimal, n; simpl.
+ rewrite nztail_to_hex_uint_pow16.
+ clear r; set (r := if _ <? _ then Some (Hexadecimal _ _) else Some _).
+ clear m; set (m := match nb_digits f with 0 => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ rewrite HexadecimalZ.to_of, abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnf.
+ * rewrite (del_tail_app_int_exact _ _ Hnf).
+ rewrite (del_head_app_int_exact _ _ Hnf).
+ now rewrite (dnorm_i_exact _ _ Hnf).
+ * rewrite (unorm_app_r _ _ Hnf).
+ rewrite (iter_D0_unorm _ Hf).
+ now rewrite dnorm_i_exact'.
+ - unfold of_hexadecimal; simpl.
+ rewrite <-(DecimalZ.to_of e).
+ case (Z.of_int e); clear e; [|intro e..]; simpl.
+ + case (uint_eq_dec f Nil); intro Hf.
+ * rewrite Hf; clear f Hf.
+ unfold to_hexadecimal; simpl.
+ rewrite IZ_to_Z_IZ_of_Z, HexadecimalZ.to_of.
+ case i as [i|i]; [now simpl|]; simpl.
+ rewrite app_nil_r.
+ case (uint_eq_dec (nzhead i) Nil); [now intros->|intro Hi].
+ now rewrite (unorm_nzhead _ Hi); revert Hi; case nzhead.
+ * set (r := IRQ _).
+ set (m := match f with Nil => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ unfold to_hexadecimal; simpl.
+ unfold IQmake_to_hexadecimal; simpl.
+ set (n := Nat.iter _ _ _).
+ case (Pos.eq_dec n 1); intro Hn.
+ exfalso; apply Hf.
+ { now apply nb_digits_0; revert Hn; unfold n; case nb_digits. }
+ clear m; set (m := match n with 1%positive | _ => _ end).
+ replace m with (QArith_base.IQmake_to_hexadecimal (Z.of_hex_int (app_int i f)) n).
+ 2:{ now unfold m; revert Hn; case n. }
+ unfold QArith_base.IQmake_to_hexadecimal, n; simpl.
+ rewrite nztail_to_hex_uint_pow16.
+ clear r; set (r := if _ <? _ then Some (Hexadecimal _ _) else Some _).
+ clear m; set (m := match nb_digits f with 0 => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ rewrite HexadecimalZ.to_of, abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnf.
+ -- rewrite (del_tail_app_int_exact _ _ Hnf).
+ rewrite (del_head_app_int_exact _ _ Hnf).
+ now rewrite (dnorm_i_exact _ _ Hnf).
+ -- rewrite (unorm_app_r _ _ Hnf).
+ rewrite (iter_D0_unorm _ Hf).
+ now rewrite dnorm_i_exact'.
+ + set (i' := match i with Pos _ => _ | _ => _ end).
+ set (m := match Pos.to_uint e with Decimal.Nil => _ | _ => _ end).
+ replace m with (HexadecimalExp i' f (Decimal.Pos (Pos.to_uint e))).
+ 2:{ unfold m; generalize (DecimalPos.Unsigned.to_uint_nonzero e).
+ now case Pos.to_uint; [|intro u; case u|..]. }
+ unfold i'; clear i' m.
+ case (uint_eq_dec f Nil); intro Hf.
+ * rewrite Hf; clear f Hf.
+ unfold to_hexadecimal; simpl.
+ rewrite IZ_to_Z_IZ_of_Z, HexadecimalZ.to_of.
+ case i as [i|i]; [now simpl|]; simpl.
+ rewrite app_nil_r.
+ case (uint_eq_dec (nzhead i) Nil); [now intros->|intro Hi].
+ now rewrite (unorm_nzhead _ Hi); revert Hi; case nzhead.
+ * set (r := IRQ _).
+ set (m := match f with Nil => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ unfold to_hexadecimal; simpl.
+ unfold IQmake_to_hexadecimal; simpl.
+ set (n := Nat.iter _ _ _).
+ case (Pos.eq_dec n 1); intro Hn.
+ exfalso; apply Hf.
+ { now apply nb_digits_0; revert Hn; unfold n; case nb_digits. }
+ clear m; set (m := match n with 1%positive | _ => _ end).
+ replace m with (QArith_base.IQmake_to_hexadecimal (Z.of_hex_int (app_int i f)) n).
+ 2:{ now unfold m; revert Hn; case n. }
+ unfold QArith_base.IQmake_to_hexadecimal, n; simpl.
+ rewrite nztail_to_hex_uint_pow16.
+ clear r; set (r := if _ <? _ then Some (Hexadecimal _ _) else Some _).
+ clear m; set (m := match nb_digits f with 0 => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ rewrite HexadecimalZ.to_of, abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnf.
+ -- rewrite (del_tail_app_int_exact _ _ Hnf).
+ rewrite (del_head_app_int_exact _ _ Hnf).
+ now rewrite (dnorm_i_exact _ _ Hnf).
+ -- rewrite (unorm_app_r _ _ Hnf).
+ rewrite (iter_D0_unorm _ Hf).
+ now rewrite dnorm_i_exact'.
+ + case (uint_eq_dec f Nil); intro Hf.
+ * rewrite Hf; clear f Hf.
+ unfold to_hexadecimal; simpl.
+ rewrite IZ_to_Z_IZ_of_Z, HexadecimalZ.to_of.
+ case i as [i|i]; [now simpl|]; simpl.
+ rewrite app_nil_r.
+ case (uint_eq_dec (nzhead i) Nil); [now intros->|intro Hi].
+ now rewrite (unorm_nzhead _ Hi); revert Hi; case nzhead.
+ * set (r := IRQ _).
+ set (m := match f with Nil => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ unfold to_hexadecimal; simpl.
+ unfold IQmake_to_hexadecimal; simpl.
+ set (n := Nat.iter _ _ _).
+ case (Pos.eq_dec n 1); intro Hn.
+ exfalso; apply Hf.
+ { now apply nb_digits_0; revert Hn; unfold n; case nb_digits. }
+ clear m; set (m := match n with 1%positive | _ => _ end).
+ replace m with (QArith_base.IQmake_to_hexadecimal (Z.of_hex_int (app_int i f)) n).
+ 2:{ now unfold m; revert Hn; case n. }
+ unfold QArith_base.IQmake_to_hexadecimal, n; simpl.
+ rewrite nztail_to_hex_uint_pow16.
+ clear r; set (r := if _ <? _ then Some (Hexadecimal _ _) else Some _).
+ clear m; set (m := match nb_digits f with 0 => _ | _ => _ end).
+ replace m with r; [unfold r|now unfold m; revert Hf; case f].
+ rewrite HexadecimalZ.to_of, abs_norm, abs_app_int.
+ case Nat.ltb_spec; intro Hnf.
+ -- rewrite (del_tail_app_int_exact _ _ Hnf).
+ rewrite (del_head_app_int_exact _ _ Hnf).
+ now rewrite (dnorm_i_exact _ _ Hnf).
+ -- rewrite (unorm_app_r _ _ Hnf).
+ rewrite (iter_D0_unorm _ Hf).
+ now rewrite dnorm_i_exact'.
+Qed.
+
+(** Some consequences *)
+
+Lemma to_hexadecimal_inj q q' :
+ to_hexadecimal q <> None -> to_hexadecimal q = to_hexadecimal q' -> q = q'.
+Proof.
+ intros Hnone EQ.
+ generalize (of_to q) (of_to q').
+ rewrite <-EQ.
+ revert Hnone; case to_hexadecimal; [|now simpl].
+ now intros d _ H1 H2; rewrite <-(H1 d eq_refl), <-(H2 d eq_refl).
+Qed.
+
+Lemma to_hexadecimal_surj d : exists q, to_hexadecimal q = Some (dnorm d).
+Proof.
+ exists (of_hexadecimal d). apply to_of.
+Qed.
+
+Lemma of_hexadecimal_dnorm d : of_hexadecimal (dnorm d) = of_hexadecimal d.
+Proof. now apply to_hexadecimal_inj; rewrite !to_of; [|rewrite dnorm_involutive]. Qed.
+
+Lemma of_inj d d' : of_hexadecimal d = of_hexadecimal d' -> dnorm d = dnorm d'.
+Proof.
+ intro H.
+ apply (@f_equal _ _ (fun x => match x with Some x => x | _ => d end)
+ (Some (dnorm d)) (Some (dnorm d'))).
+ now rewrite <- !to_of, H.
+Qed.
+
+Lemma of_iff d d' : of_hexadecimal d = of_hexadecimal d' <-> dnorm d = dnorm d'.
+Proof.
+ split. apply of_inj. intros E. rewrite <- of_hexadecimal_dnorm, E.
+ apply of_hexadecimal_dnorm.
+Qed.
diff --git a/theories/Numbers/HexadecimalZ.v b/theories/Numbers/HexadecimalZ.v
index c5ed0b5b28..1d78ad1ad2 100644
--- a/theories/Numbers/HexadecimalZ.v
+++ b/theories/Numbers/HexadecimalZ.v
@@ -80,9 +80,11 @@ Lemma of_hex_uint_iter_D0 d n :
Z.of_hex_uint (app d (Nat.iter n D0 Nil))
= Nat.iter n (Z.mul 0x10) (Z.of_hex_uint d).
Proof.
- unfold Z.of_hex_uint.
- unfold app; rewrite <-rev_revapp.
- rewrite Unsigned.of_lu_rev, Unsigned.of_lu_revapp.
+ rewrite <-(rev_rev (app _ _)), <-(of_list_to_list (rev (app _ _))).
+ rewrite rev_spec, app_spec, List.rev_app_distr.
+ rewrite <-!rev_spec, <-app_spec, of_list_to_list.
+ unfold Z.of_hex_uint; rewrite Unsigned.of_lu_rev.
+ unfold app; rewrite Unsigned.of_lu_revapp, !rev_rev.
rewrite <-!Unsigned.of_lu_rev, !rev_rev.
assert (H' : Pos.of_hex_uint (Nat.iter n D0 Nil) = 0%N).
{ now induction n; [|rewrite Unsigned.nat_iter_S]. }
@@ -140,3 +142,22 @@ Qed.
Lemma double_to_hex_int n :
double (Z.to_hex_int n) = Z.to_hex_int (Z.double n).
Proof. now rewrite <-(of_to n), <-of_hex_int_double, !to_of, double_norm. Qed.
+
+Lemma nztail_to_hex_uint_pow16 n :
+ Hexadecimal.nztail (Pos.to_hex_uint (Nat.iter n (Pos.mul 16) 1%positive))
+ = (D1 Nil, n).
+Proof.
+ case n as [|n]; [now simpl|].
+ rewrite <-(Nat2Pos.id (S n)); [|now simpl].
+ generalize (Pos.of_nat (S n)); clear n; intro p.
+ induction (Pos.to_nat p); [now simpl|].
+ rewrite Unsigned.nat_iter_S.
+ unfold Pos.to_hex_uint.
+ change (Pos.to_little_hex_uint _)
+ with (Unsigned.to_lu (16 * N.pos (Nat.iter n (Pos.mul 16) 1%positive))).
+ rewrite Unsigned.to_lhex_tenfold.
+ revert IHn; unfold Pos.to_hex_uint.
+ unfold Hexadecimal.nztail; rewrite !rev_rev; simpl.
+ set (f'' := _ (Pos.to_little_hex_uint _)).
+ now case f''; intros r n' H; inversion H.
+Qed.
diff --git a/theories/PArith/BinPosDef.v b/theories/PArith/BinPosDef.v
index b41cd571dc..2ec9f4d871 100644
--- a/theories/PArith/BinPosDef.v
+++ b/theories/PArith/BinPosDef.v
@@ -639,10 +639,10 @@ Fixpoint of_hex_uint (d:Hexadecimal.uint) : N :=
| Hexadecimal.Df l => Npos (of_hex_uint_acc l 1~1~1~1)
end.
-Definition of_num_uint (d:Numeral.uint) : N :=
+Definition of_num_uint (d:Number.uint) : N :=
match d with
- | Numeral.UIntDec d => of_uint d
- | Numeral.UIntHex d => of_hex_uint d
+ | Number.UIntDecimal d => of_uint d
+ | Number.UIntHexadecimal d => of_hex_uint d
end.
Definition of_int (d:Decimal.int) : option positive :=
@@ -665,10 +665,10 @@ Definition of_hex_int (d:Hexadecimal.int) : option positive :=
| Hexadecimal.Neg _ => None
end.
-Definition of_num_int (d:Numeral.int) : option positive :=
+Definition of_num_int (d:Number.int) : option positive :=
match d with
- | Numeral.IntDec d => of_int d
- | Numeral.IntHex d => of_hex_int d
+ | Number.IntDecimal d => of_int d
+ | Number.IntHexadecimal d => of_hex_int d
end.
Fixpoint to_little_uint p :=
@@ -689,13 +689,13 @@ Fixpoint to_little_hex_uint p :=
Definition to_hex_uint p := Hexadecimal.rev (to_little_hex_uint p).
-Definition to_num_uint p := Numeral.UIntDec (to_uint p).
+Definition to_num_uint p := Number.UIntDecimal (to_uint p).
Definition to_int n := Decimal.Pos (to_uint n).
Definition to_hex_int p := Hexadecimal.Pos (to_hex_uint p).
-Definition to_num_int n := Numeral.IntDec (to_int n).
+Definition to_num_int n := Number.IntDecimal (to_int n).
Number Notation positive of_num_int to_num_uint : positive_scope.
diff --git a/theories/QArith/QArith_base.v b/theories/QArith/QArith_base.v
index 192dcd885b..fa4f9134cc 100644
--- a/theories/QArith/QArith_base.v
+++ b/theories/QArith/QArith_base.v
@@ -18,6 +18,9 @@ Require Export Morphisms Setoid Bool.
Record Q : Set := Qmake {Qnum : Z; Qden : positive}.
+Declare Scope hex_Q_scope.
+Delimit Scope hex_Q_scope with xQ.
+
Declare Scope Q_scope.
Delimit Scope Q_scope with Q.
Bind Scope Q_scope with Q.
@@ -33,104 +36,6 @@ Ltac simpl_mult := rewrite ?Pos2Z.inj_mul.
Notation "a # b" := (Qmake a b) (at level 55, no associativity) : Q_scope.
-Definition of_decimal (d:Decimal.decimal) : Q :=
- let '(i, f, e) :=
- match d with
- | Decimal.Decimal i f => (i, f, Decimal.Pos Decimal.Nil)
- | Decimal.DecimalExp i f e => (i, f, e)
- end in
- let num := Z.of_int (Decimal.app_int i f) in
- let e := Z.sub (Z.of_int e) (Z.of_nat (Decimal.nb_digits f)) in
- match e with
- | Z0 => Qmake num 1
- | Zpos e => Qmake (Pos.iter (Z.mul 10) num e) 1
- | Zneg e => Qmake num (Pos.iter (Pos.mul 10) 1%positive e)
- end.
-
-Definition to_decimal (q:Q) : option Decimal.decimal :=
- (* choose between 123e-2 and 1.23, this is purely heuristic
- and doesn't play any soundness role *)
- let choose_exponent i ne :=
- let i := match i with Decimal.Pos i | Decimal.Neg i => i end in
- let li := Decimal.nb_digits i in
- let le := Decimal.nb_digits (Nat.to_uint ne) in
- Nat.ltb (Nat.add li le) ne in
- (* print 123 / 100 as 123e-2 *)
- let decimal_exponent i ne :=
- let e := Z.to_int (Z.opp (Z.of_nat ne)) in
- Decimal.DecimalExp i Decimal.Nil e in
- (* print 123 / 100 as 1.23 *)
- let decimal_dot i ne :=
- let ai := match i with Decimal.Pos i | Decimal.Neg i => i end in
- let ni := Decimal.nb_digits ai in
- if Nat.ltb ne ni then
- let i := Decimal.del_tail_int ne i in
- let f := Decimal.del_head (Nat.sub ni ne) ai in
- Decimal.Decimal i f
- else
- let z := match i with
- | Decimal.Pos _ => Decimal.Pos (Decimal.zero)
- | Decimal.Neg _ => Decimal.Neg (Decimal.zero) end in
- Decimal.Decimal z (Nat.iter (Nat.sub ne ni) Decimal.D0 ai) in
- let num := Z.to_int (Qnum q) in
- let (den, e_den) := Decimal.nztail (Pos.to_uint (Qden q)) in
- match den with
- | Decimal.D1 Decimal.Nil =>
- match e_den with
- | O => Some (Decimal.Decimal num Decimal.Nil)
- | ne =>
- if choose_exponent num ne then Some (decimal_exponent num ne)
- else Some (decimal_dot num ne)
- end
- | _ => None
- end.
-
-Definition of_hexadecimal (d:Hexadecimal.hexadecimal) : Q :=
- let '(i, f, e) :=
- match d with
- | Hexadecimal.Hexadecimal i f => (i, f, Decimal.Pos Decimal.Nil)
- | Hexadecimal.HexadecimalExp i f e => (i, f, e)
- end in
- let num := Z.of_hex_int (Hexadecimal.app_int i f) in
- let e := Z.sub (Z.of_int e) (Z.mul 4 (Z.of_nat (Hexadecimal.nb_digits f))) in
- match e with
- | Z0 => Qmake num 1
- | Zpos e => Qmake (Pos.iter (Z.mul 2) num e) 1
- | Zneg e => Qmake num (Pos.iter (Pos.mul 2) 1%positive e)
- end.
-
-Definition to_hexadecimal (q:Q) : option Hexadecimal.hexadecimal :=
- let mk_exp i e :=
- Hexadecimal.HexadecimalExp i Hexadecimal.Nil (Z.to_int (Z.opp e)) in
- let num := Z.to_hex_int (Qnum q) in
- let (den, e_den) := Hexadecimal.nztail (Pos.to_hex_uint (Qden q)) in
- let e := Z.of_nat e_den in
- match den with
- | Hexadecimal.D1 Hexadecimal.Nil =>
- match e_den with
- | O => Some (Hexadecimal.Hexadecimal num Hexadecimal.Nil)
- | _ => Some (mk_exp num (4 * e)%Z)
- end
- | Hexadecimal.D2 Hexadecimal.Nil => Some (mk_exp num (1 + 4 * e)%Z)
- | Hexadecimal.D4 Hexadecimal.Nil => Some (mk_exp num (2 + 4 * e)%Z)
- | Hexadecimal.D8 Hexadecimal.Nil => Some (mk_exp num (3 + 4 * e)%Z)
- | _ => None
- end.
-
-Definition of_numeral (d:Numeral.numeral) : option Q :=
- match d with
- | Numeral.Dec d => Some (of_decimal d)
- | Numeral.Hex d => Some (of_hexadecimal d)
- end.
-
-Definition to_numeral (q:Q) : option Numeral.numeral :=
- match to_decimal q with
- | None => None
- | Some q => Some (Numeral.Dec q)
- end.
-
-Number Notation Q of_numeral to_numeral : Q_scope.
-
Definition inject_Z (x : Z) := Qmake x 1.
Arguments inject_Z x%Z.
@@ -316,7 +221,7 @@ Definition Qminus (x y : Q) := Qplus x (Qopp y).
Definition Qinv (x : Q) :=
match Qnum x with
- | Z0 => 0
+ | Z0 => 0#1
| Zpos p => (QDen x)#p
| Zneg p => (Zneg (Qden x))#p
end.
@@ -335,6 +240,188 @@ Register Qminus as rat.Q.Qminus.
Register Qopp as rat.Q.Qopp.
Register Qmult as rat.Q.Qmult.
+(** Number notation for constants *)
+
+Inductive IZ :=
+ | IZpow_pos : Z -> positive -> IZ
+ | IZ0 : IZ
+ | IZpos : positive -> IZ
+ | IZneg : positive -> IZ.
+
+Inductive IQ :=
+ | IQmake : IZ -> positive -> IQ
+ | IQmult : IQ -> IQ -> IQ
+ | IQdiv : IQ -> IQ -> IQ.
+
+Definition IZ_of_Z z :=
+ match z with
+ | Z0 => IZ0
+ | Zpos e => IZpos e
+ | Zneg e => IZneg e
+ end.
+
+Definition IZ_to_Z z :=
+ match z with
+ | IZ0 => Some Z0
+ | IZpos e => Some (Zpos e)
+ | IZneg e => Some (Zneg e)
+ | IZpow_pos _ _ => None
+ end.
+
+Definition of_decimal (d:Decimal.decimal) : IQ :=
+ let '(i, f, e) :=
+ match d with
+ | Decimal.Decimal i f => (i, f, Decimal.Pos Decimal.Nil)
+ | Decimal.DecimalExp i f e => (i, f, e)
+ end in
+ let num := Z.of_int (Decimal.app_int i f) in
+ let den := Nat.iter (Decimal.nb_digits f) (Pos.mul 10) 1%positive in
+ let q := IQmake (IZ_of_Z num) den in
+ let e := Z.of_int e in
+ match e with
+ | Z0 => q
+ | Zpos e => IQmult q (IQmake (IZpow_pos 10 e) 1)
+ | Zneg e => IQdiv q (IQmake (IZpow_pos 10 e) 1)
+ end.
+
+Definition IQmake_to_decimal num den :=
+ let num := Z.to_int num in
+ let (den, e_den) := Decimal.nztail (Pos.to_uint den) in
+ match den with
+ | Decimal.D1 Decimal.Nil =>
+ match e_den with
+ | O => Some (Decimal.Decimal num Decimal.Nil)
+ | ne =>
+ let ai := Decimal.abs num in
+ let ni := Decimal.nb_digits ai in
+ if Nat.ltb ne ni then
+ let i := Decimal.del_tail_int ne num in
+ let f := Decimal.del_head (Nat.sub ni ne) ai in
+ Some (Decimal.Decimal i f)
+ else
+ let z := match num with
+ | Decimal.Pos _ => Decimal.Pos (Decimal.zero)
+ | Decimal.Neg _ => Decimal.Neg (Decimal.zero) end in
+ Some (Decimal.Decimal z (Nat.iter (Nat.sub ne ni) Decimal.D0 ai))
+ end
+ | _ => None
+ end.
+
+Definition IQmake_to_decimal' num den :=
+ match IZ_to_Z num with
+ | None => None
+ | Some num => IQmake_to_decimal num den
+ end.
+
+Definition to_decimal (n : IQ) : option Decimal.decimal :=
+ match n with
+ | IQmake num den => IQmake_to_decimal' num den
+ | IQmult (IQmake num den) (IQmake (IZpow_pos 10 e) 1) =>
+ match IQmake_to_decimal' num den with
+ | Some (Decimal.Decimal i f) =>
+ Some (Decimal.DecimalExp i f (Pos.to_int e))
+ | _ => None
+ end
+ | IQdiv (IQmake num den) (IQmake (IZpow_pos 10 e) 1) =>
+ match IQmake_to_decimal' num den with
+ | Some (Decimal.Decimal i f) =>
+ Some (Decimal.DecimalExp i f (Decimal.Neg (Pos.to_uint e)))
+ | _ => None
+ end
+ | _ => None
+ end.
+
+Definition of_hexadecimal (d:Hexadecimal.hexadecimal) : IQ :=
+ let '(i, f, e) :=
+ match d with
+ | Hexadecimal.Hexadecimal i f => (i, f, Decimal.Pos Decimal.Nil)
+ | Hexadecimal.HexadecimalExp i f e => (i, f, e)
+ end in
+ let num := Z.of_hex_int (Hexadecimal.app_int i f) in
+ let den := Nat.iter (Hexadecimal.nb_digits f) (Pos.mul 16) 1%positive in
+ let q := IQmake (IZ_of_Z num) den in
+ let e := Z.of_int e in
+ match e with
+ | Z0 => q
+ | Zpos e => IQmult q (IQmake (IZpow_pos 2 e) 1)
+ | Zneg e => IQdiv q (IQmake (IZpow_pos 2 e) 1)
+ end.
+
+Definition IQmake_to_hexadecimal num den :=
+ let num := Z.to_hex_int num in
+ let (den, e_den) := Hexadecimal.nztail (Pos.to_hex_uint den) in
+ match den with
+ | Hexadecimal.D1 Hexadecimal.Nil =>
+ match e_den with
+ | O => Some (Hexadecimal.Hexadecimal num Hexadecimal.Nil)
+ | ne =>
+ let ai := Hexadecimal.abs num in
+ let ni := Hexadecimal.nb_digits ai in
+ if Nat.ltb ne ni then
+ let i := Hexadecimal.del_tail_int ne num in
+ let f := Hexadecimal.del_head (Nat.sub ni ne) ai in
+ Some (Hexadecimal.Hexadecimal i f)
+ else
+ let z := match num with
+ | Hexadecimal.Pos _ => Hexadecimal.Pos (Hexadecimal.zero)
+ | Hexadecimal.Neg _ => Hexadecimal.Neg (Hexadecimal.zero) end in
+ Some (Hexadecimal.Hexadecimal z (Nat.iter (Nat.sub ne ni) Hexadecimal.D0 ai))
+ end
+ | _ => None
+ end.
+
+Definition IQmake_to_hexadecimal' num den :=
+ match IZ_to_Z num with
+ | None => None
+ | Some num => IQmake_to_hexadecimal num den
+ end.
+
+Definition to_hexadecimal (n : IQ) : option Hexadecimal.hexadecimal :=
+ match n with
+ | IQmake num den => IQmake_to_hexadecimal' num den
+ | IQmult (IQmake num den) (IQmake (IZpow_pos 2 e) 1) =>
+ match IQmake_to_hexadecimal' num den with
+ | Some (Hexadecimal.Hexadecimal i f) =>
+ Some (Hexadecimal.HexadecimalExp i f (Pos.to_int e))
+ | _ => None
+ end
+ | IQdiv (IQmake num den) (IQmake (IZpow_pos 2 e) 1) =>
+ match IQmake_to_hexadecimal' num den with
+ | Some (Hexadecimal.Hexadecimal i f) =>
+ Some (Hexadecimal.HexadecimalExp i f (Decimal.Neg (Pos.to_uint e)))
+ | _ => None
+ end
+ | _ => None
+ end.
+
+Definition of_number (n : Number.number) : IQ :=
+ match n with
+ | Number.Decimal d => of_decimal d
+ | Number.Hexadecimal h => of_hexadecimal h
+ end.
+
+Definition to_number (q:IQ) : option Number.number :=
+ match to_decimal q with
+ | None => None
+ | Some q => Some (Number.Decimal q)
+ end.
+
+Definition to_hex_number q :=
+ match to_hexadecimal q with
+ | None => None
+ | Some q => Some (Number.Hexadecimal q)
+ end.
+
+Number Notation Q of_number to_hex_number (via IQ
+ mapping [Qmake => IQmake, Qmult => IQmult, Qdiv => IQdiv,
+ Z.pow_pos => IZpow_pos, Z0 => IZ0, Zpos => IZpos, Zneg => IZneg])
+ : hex_Q_scope.
+
+Number Notation Q of_number to_number (via IQ
+ mapping [Qmake => IQmake, Qmult => IQmult, Qdiv => IQdiv,
+ Z.pow_pos => IZpow_pos, Z0 => IZ0, Zpos => IZpos, Zneg => IZneg])
+ : Q_scope.
+
(** A light notation for [Zpos] *)
Lemma Qmake_Qdiv a b : a#b==inject_Z a/inject_Z (Zpos b).
diff --git a/theories/QArith/Qreals.v b/theories/QArith/Qreals.v
index 1baefd6bf7..20b5cb236b 100644
--- a/theories/QArith/Qreals.v
+++ b/theories/QArith/Qreals.v
@@ -13,8 +13,6 @@ Require Export QArith_base.
(** Injection of rational numbers into real numbers. *)
-Definition Q2R (x : Q) : R := (IZR (Qnum x) * / IZR (QDen x))%R.
-
Lemma IZR_nz : forall p : positive, IZR (Zpos p) <> 0%R.
Proof.
intros.
diff --git a/theories/Reals/RIneq.v b/theories/Reals/RIneq.v
index 4fa8b3216a..993b7b3ec4 100644
--- a/theories/Reals/RIneq.v
+++ b/theories/Reals/RIneq.v
@@ -459,12 +459,12 @@ Lemma Rplus_eq_0_l :
forall r1 r2, 0 <= r1 -> 0 <= r2 -> r1 + r2 = 0 -> r1 = 0.
Proof.
intros a b H [H0| H0] H1; auto with real.
- absurd (0 < a + b).
- rewrite H1; auto with real.
- apply Rle_lt_trans with (a + 0).
- rewrite Rplus_0_r; assumption.
- auto using Rplus_lt_compat_l with real.
- rewrite <- H0, Rplus_0_r in H1; assumption.
+ - absurd (0 < a + b).
+ + rewrite H1; auto with real.
+ + apply Rle_lt_trans with (a + 0).
+ * rewrite Rplus_0_r; assumption.
+ * auto using Rplus_lt_compat_l with real.
+ - rewrite <- H0, Rplus_0_r in H1; assumption.
Qed.
Lemma Rplus_eq_R0 :
@@ -1529,7 +1529,7 @@ Qed.
Lemma Rinv_1_lt_contravar : forall r1 r2, 1 <= r1 -> r1 < r2 -> / r2 < / r1.
Proof.
- intros x y H' H'0.
+ intros x y H' H'0.
cut (0 < x); [ intros Lt0 | apply Rlt_le_trans with (r2 := 1) ];
auto with real.
apply Rmult_lt_reg_l with (r := x); auto with real.
@@ -1753,11 +1753,11 @@ Qed.
Lemma INR_IPR : forall p, INR (Pos.to_nat p) = IPR p.
Proof.
assert (H: forall p, 2 * INR (Pos.to_nat p) = IPR_2 p).
- induction p as [p|p|] ; simpl IPR_2.
+ { induction p as [p|p|] ; simpl IPR_2.
rewrite Pos2Nat.inj_xI, S_INR, mult_INR, <- IHp.
now rewrite (Rplus_comm (2 * _)).
now rewrite Pos2Nat.inj_xO, mult_INR, <- IHp.
- apply Rmult_1_r.
+ apply Rmult_1_r. }
intros [p|p|] ; unfold IPR.
rewrite Pos2Nat.inj_xI, S_INR, mult_INR, <- H.
apply Rplus_comm.
@@ -1830,12 +1830,12 @@ Qed.
Lemma pow_IZR : forall z n, pow (IZR z) n = IZR (Z.pow z (Z.of_nat n)).
Proof.
- intros z [|n];simpl;trivial.
- rewrite Zpower_pos_nat.
- rewrite SuccNat2Pos.id_succ. unfold Zpower_nat;simpl.
- rewrite mult_IZR.
- induction n;simpl;trivial.
- rewrite mult_IZR;ring[IHn].
+ intros z [|n];simpl;trivial.
+ rewrite Zpower_pos_nat.
+ rewrite SuccNat2Pos.id_succ. unfold Zpower_nat;simpl.
+ rewrite mult_IZR.
+ induction n;simpl;trivial.
+ rewrite mult_IZR;ring[IHn].
Qed.
(**********)
@@ -2043,7 +2043,7 @@ Proof.
Qed.
Lemma Ropp_div : forall x y, -x/y = - (x / y).
-intros x y; unfold Rdiv; ring.
+ intros x y; unfold Rdiv; ring.
Qed.
Lemma Ropp_div_den : forall x y : R, y<>0 -> x / - y = - (x / y).
@@ -2068,22 +2068,22 @@ Lemma R_rm : ring_morph
0%R 1%R Rplus Rmult Rminus Ropp eq
0%Z 1%Z Zplus Zmult Zminus Z.opp Zeq_bool IZR.
Proof.
-constructor ; try easy.
-exact plus_IZR.
-exact minus_IZR.
-exact mult_IZR.
-exact opp_IZR.
-intros x y H.
-apply f_equal.
-now apply Zeq_bool_eq.
+ constructor ; try easy.
+ - exact plus_IZR.
+ - exact minus_IZR.
+ - exact mult_IZR.
+ - exact opp_IZR.
+ - intros x y H.
+ apply f_equal.
+ now apply Zeq_bool_eq.
Qed.
Lemma Zeq_bool_IZR x y :
IZR x = IZR y -> Zeq_bool x y = true.
Proof.
-intros H.
-apply Zeq_is_eq_bool.
-now apply eq_IZR.
+ intros H.
+ apply Zeq_is_eq_bool.
+ now apply eq_IZR.
Qed.
Add Field RField : Rfield
@@ -2127,15 +2127,15 @@ Qed.
Lemma Rdiv_lt_0_compat : forall a b, 0 < a -> 0 < b -> 0 < a/b.
Proof.
-intros; apply Rmult_lt_0_compat;[|apply Rinv_0_lt_compat]; assumption.
+ intros; apply Rmult_lt_0_compat;[|apply Rinv_0_lt_compat]; assumption.
Qed.
Lemma Rdiv_plus_distr : forall a b c, (a + b)/c = a/c + b/c.
-intros a b c; apply Rmult_plus_distr_r.
+ intros a b c; apply Rmult_plus_distr_r.
Qed.
Lemma Rdiv_minus_distr : forall a b c, (a - b)/c = a/c - b/c.
-intros a b c; unfold Rminus, Rdiv; rewrite Rmult_plus_distr_r; ring.
+ intros a b c; unfold Rminus, Rdiv; rewrite Rmult_plus_distr_r; ring.
Qed.
(* A test for equality function. *)
diff --git a/theories/Reals/Rdefinitions.v b/theories/Reals/Rdefinitions.v
index affa129771..40736c61f2 100644
--- a/theories/Reals/Rdefinitions.v
+++ b/theories/Reals/Rdefinitions.v
@@ -22,11 +22,12 @@ Require Import ConstructiveRcomplete.
Require Import ClassicalDedekindReals.
-(* Declare primitive numeral notations for Scope R_scope *)
+(* Declare primitive number notations for Scope R_scope *)
+Declare Scope hex_R_scope.
Declare Scope R_scope.
-Declare ML Module "r_syntax_plugin".
(* Declare Scope R_scope with Key R *)
+Delimit Scope hex_R_scope with xR.
Delimit Scope R_scope with R.
Local Open Scope R_scope.
@@ -224,3 +225,165 @@ Proof.
- (* x = n-1 *) exact n.
- exact (Z.pred n).
Defined.
+
+(** Injection of rational numbers into real numbers. *)
+
+Definition Q2R (x : Q) : R := (IZR (Qnum x) * / IZR (QDen x))%R.
+
+(**********************************************************)
+(** * Number notation for constants *)
+(**********************************************************)
+
+Inductive IR :=
+ | IRZ : IZ -> IR
+ | IRQ : Q -> IR
+ | IRmult : IR -> IR -> IR
+ | IRdiv : IR -> IR -> IR.
+
+Definition of_decimal (d : Decimal.decimal) : IR :=
+ let '(i, f, e) :=
+ match d with
+ | Decimal.Decimal i f => (i, f, Decimal.Pos Decimal.Nil)
+ | Decimal.DecimalExp i f e => (i, f, e)
+ end in
+ let zq := match f with
+ | Decimal.Nil => IRZ (IZ_of_Z (Z.of_int i))
+ | _ =>
+ let num := Z.of_int (Decimal.app_int i f) in
+ let den := Nat.iter (Decimal.nb_digits f) (Pos.mul 10) 1%positive in
+ IRQ (Qmake num den) end in
+ let e := Z.of_int e in
+ match e with
+ | Z0 => zq
+ | Zpos e => IRmult zq (IRZ (IZpow_pos 10 e))
+ | Zneg e => IRdiv zq (IRZ (IZpow_pos 10 e))
+ end.
+
+Definition of_hexadecimal (d : Hexadecimal.hexadecimal) : IR :=
+ let '(i, f, e) :=
+ match d with
+ | Hexadecimal.Hexadecimal i f => (i, f, Decimal.Pos Decimal.Nil)
+ | Hexadecimal.HexadecimalExp i f e => (i, f, e)
+ end in
+ let zq := match f with
+ | Hexadecimal.Nil => IRZ (IZ_of_Z (Z.of_hex_int i))
+ | _ =>
+ let num := Z.of_hex_int (Hexadecimal.app_int i f) in
+ let den := Nat.iter (Hexadecimal.nb_digits f) (Pos.mul 16) 1%positive in
+ IRQ (Qmake num den) end in
+ let e := Z.of_int e in
+ match e with
+ | Z0 => zq
+ | Zpos e => IRmult zq (IRZ (IZpow_pos 2 e))
+ | Zneg e => IRdiv zq (IRZ (IZpow_pos 2 e))
+ end.
+
+Definition of_number (n : Number.number) : IR :=
+ match n with
+ | Number.Decimal d => of_decimal d
+ | Number.Hexadecimal h => of_hexadecimal h
+ end.
+
+Definition IQmake_to_decimal num den :=
+ match den with
+ | 1%positive => None (* this should be encoded as IRZ *)
+ | _ => IQmake_to_decimal num den
+ end.
+
+Definition to_decimal (n : IR) : option Decimal.decimal :=
+ match n with
+ | IRZ z =>
+ match IZ_to_Z z with
+ | Some z => Some (Decimal.Decimal (Z.to_int z) Decimal.Nil)
+ | None => None
+ end
+ | IRQ (Qmake num den) => IQmake_to_decimal num den
+ | IRmult (IRZ z) (IRZ (IZpow_pos 10 e)) =>
+ match IZ_to_Z z with
+ | Some z =>
+ Some (Decimal.DecimalExp (Z.to_int z) Decimal.Nil (Pos.to_int e))
+ | None => None
+ end
+ | IRmult (IRQ (Qmake num den)) (IRZ (IZpow_pos 10 e)) =>
+ match IQmake_to_decimal num den with
+ | Some (Decimal.Decimal i f) =>
+ Some (Decimal.DecimalExp i f (Pos.to_int e))
+ | _ => None
+ end
+ | IRdiv (IRZ z) (IRZ (IZpow_pos 10 e)) =>
+ match IZ_to_Z z with
+ | Some z =>
+ Some (Decimal.DecimalExp (Z.to_int z) Decimal.Nil (Decimal.Neg (Pos.to_uint e)))
+ | None => None
+ end
+ | IRdiv (IRQ (Qmake num den)) (IRZ (IZpow_pos 10 e)) =>
+ match IQmake_to_decimal num den with
+ | Some (Decimal.Decimal i f) =>
+ Some (Decimal.DecimalExp i f (Decimal.Neg (Pos.to_uint e)))
+ | _ => None
+ end
+ | _ => None
+ end.
+
+Definition IQmake_to_hexadecimal num den :=
+ match den with
+ | 1%positive => None (* this should be encoded as IRZ *)
+ | _ => IQmake_to_hexadecimal num den
+ end.
+
+Definition to_hexadecimal (n : IR) : option Hexadecimal.hexadecimal :=
+ match n with
+ | IRZ z =>
+ match IZ_to_Z z with
+ | Some z => Some (Hexadecimal.Hexadecimal (Z.to_hex_int z) Hexadecimal.Nil)
+ | None => None
+ end
+ | IRQ (Qmake num den) => IQmake_to_hexadecimal num den
+ | IRmult (IRZ z) (IRZ (IZpow_pos 2 e)) =>
+ match IZ_to_Z z with
+ | Some z =>
+ Some (Hexadecimal.HexadecimalExp (Z.to_hex_int z) Hexadecimal.Nil (Pos.to_int e))
+ | None => None
+ end
+ | IRmult (IRQ (Qmake num den)) (IRZ (IZpow_pos 2 e)) =>
+ match IQmake_to_hexadecimal num den with
+ | Some (Hexadecimal.Hexadecimal i f) =>
+ Some (Hexadecimal.HexadecimalExp i f (Pos.to_int e))
+ | _ => None
+ end
+ | IRdiv (IRZ z) (IRZ (IZpow_pos 2 e)) =>
+ match IZ_to_Z z with
+ | Some z =>
+ Some (Hexadecimal.HexadecimalExp (Z.to_hex_int z) Hexadecimal.Nil (Decimal.Neg (Pos.to_uint e)))
+ | None => None
+ end
+ | IRdiv (IRQ (Qmake num den)) (IRZ (IZpow_pos 2 e)) =>
+ match IQmake_to_hexadecimal num den with
+ | Some (Hexadecimal.Hexadecimal i f) =>
+ Some (Hexadecimal.HexadecimalExp i f (Decimal.Neg (Pos.to_uint e)))
+ | _ => None
+ end
+ | _ => None
+ end.
+
+Definition to_number q :=
+ match to_decimal q with
+ | None => None
+ | Some q => Some (Number.Decimal q)
+ end.
+
+Definition to_hex_number q :=
+ match to_hexadecimal q with
+ | None => None
+ | Some q => Some (Number.Hexadecimal q)
+ end.
+
+Number Notation R of_number to_hex_number (via IR
+ mapping [IZR => IRZ, Q2R => IRQ, Rmult => IRmult, Rdiv => IRdiv,
+ Z.pow_pos => IZpow_pos, Z0 => IZ0, Zpos => IZpos, Zneg => IZneg])
+ : hex_R_scope.
+
+Number Notation R of_number to_number (via IR
+ mapping [IZR => IRZ, Q2R => IRQ, Rmult => IRmult, Rdiv => IRdiv,
+ Z.pow_pos => IZpow_pos, Z0 => IZ0, Zpos => IZpos, Zneg => IZneg])
+ : R_scope.
diff --git a/theories/Reals/Rregisternames.v b/theories/Reals/Rregisternames.v
index 8b078f2cf3..8117d975fe 100644
--- a/theories/Reals/Rregisternames.v
+++ b/theories/Reals/Rregisternames.v
@@ -8,7 +8,7 @@
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)
-Require Import Raxioms Rfunctions Qreals.
+Require Import Raxioms Rfunctions.
(*****************************************************************)
(** Register names for use in plugins *)
@@ -31,4 +31,4 @@ Register IZR as reals.R.IZR.
Register Rabs as reals.R.Rabs.
Register powerRZ as reals.R.powerRZ.
Register pow as reals.R.pow.
-Register Qreals.Q2R as reals.R.Q2R.
+Register Q2R as reals.R.Q2R.
diff --git a/theories/Strings/ByteVector.v b/theories/Strings/ByteVector.v
index ac0323442a..144ffd59e0 100644
--- a/theories/Strings/ByteVector.v
+++ b/theories/Strings/ByteVector.v
@@ -42,7 +42,7 @@ Fixpoint to_Bvector {n : nat} (v : ByteVector n) : Bvector (n * 8) :=
Fixpoint of_Bvector {n : nat} : Bvector (n * 8) -> ByteVector n :=
match n with
| 0 => fun _ => []
- | S n' =>
+ | S _ =>
fun v =>
let (b0, v1) := uncons v in
let (b1, v2) := uncons v1 in
diff --git a/theories/Structures/OrdersEx.v b/theories/Structures/OrdersEx.v
index adffa1ded4..382538875d 100644
--- a/theories/Structures/OrdersEx.v
+++ b/theories/Structures/OrdersEx.v
@@ -138,12 +138,12 @@ Module PositiveOrderedTypeBits <: UsualOrderedType.
Fixpoint compare x y :=
match x, y with
| x~1, y~1 => compare x y
- | x~1, _ => Gt
+ | _~1, _ => Gt
| x~0, y~0 => compare x y
- | x~0, _ => Lt
- | 1, y~1 => Lt
+ | _~0, _ => Lt
+ | 1, _~1 => Lt
| 1, 1 => Eq
- | 1, y~0 => Gt
+ | 1, _~0 => Gt
end.
Lemma compare_spec : forall x y, CompSpec eq lt x y (compare x y).
diff --git a/theories/ZArith/BinIntDef.v b/theories/ZArith/BinIntDef.v
index 69ed101f24..58bc75b62c 100644
--- a/theories/ZArith/BinIntDef.v
+++ b/theories/ZArith/BinIntDef.v
@@ -311,10 +311,10 @@ Definition of_uint (d:Decimal.uint) := of_N (Pos.of_uint d).
Definition of_hex_uint (d:Hexadecimal.uint) := of_N (Pos.of_hex_uint d).
-Definition of_num_uint (d:Numeral.uint) :=
+Definition of_num_uint (d:Number.uint) :=
match d with
- | Numeral.UIntDec d => of_uint d
- | Numeral.UIntHex d => of_hex_uint d
+ | Number.UIntDecimal d => of_uint d
+ | Number.UIntHexadecimal d => of_hex_uint d
end.
Definition of_int (d:Decimal.int) :=
@@ -329,10 +329,10 @@ Definition of_hex_int (d:Hexadecimal.int) :=
| Hexadecimal.Neg d => opp (of_hex_uint d)
end.
-Definition of_num_int (d:Numeral.int) :=
+Definition of_num_int (d:Number.int) :=
match d with
- | Numeral.IntDec d => of_int d
- | Numeral.IntHex d => of_hex_int d
+ | Number.IntDecimal d => of_int d
+ | Number.IntHexadecimal d => of_hex_int d
end.
Definition to_int n :=
@@ -349,7 +349,7 @@ Definition to_hex_int n :=
| neg p => Hexadecimal.Neg (Pos.to_hex_uint p)
end.
-Definition to_num_int n := Numeral.IntDec (to_int n).
+Definition to_num_int n := Number.IntDecimal (to_int n).
(** ** Iteration of a function
diff --git a/theories/dune b/theories/dune
index c2d8197ee4..18e000cfe1 100644
--- a/theories/dune
+++ b/theories/dune
@@ -14,10 +14,8 @@
coq.plugins.cc
coq.plugins.firstorder
- coq.plugins.numeral_notation
- coq.plugins.string_notation
+ coq.plugins.number_string_notation
coq.plugins.int63_syntax
- coq.plugins.r_syntax
coq.plugins.float_syntax
coq.plugins.btauto
diff --git a/theories/extraction/ExtrOCamlPArray.v b/theories/extraction/ExtrOCamlPArray.v
index 67646bdb53..56d40c1d16 100644
--- a/theories/extraction/ExtrOCamlPArray.v
+++ b/theories/extraction/ExtrOCamlPArray.v
@@ -23,4 +23,3 @@ Extract Constant PArray.default => "Parray.default".
Extract Constant PArray.set => "Parray.set".
Extract Constant PArray.length => "Parray.length".
Extract Constant PArray.copy => "Parray.copy".
-Extract Constant PArray.reroot => "Parray.reroot".
diff --git a/theories/micromega/RingMicromega.v b/theories/micromega/RingMicromega.v
index 75ca2059bd..b5289b5800 100644
--- a/theories/micromega/RingMicromega.v
+++ b/theories/micromega/RingMicromega.v
@@ -1127,8 +1127,8 @@ Definition simpl_cone (e:Psatz) : Psatz :=
end
| PsatzMulE t1 t2 =>
match t1 , t2 with
- | PsatzZ , x => PsatzZ
- | x , PsatzZ => PsatzZ
+ | PsatzZ , _ => PsatzZ
+ | _ , PsatzZ => PsatzZ
| PsatzC c , PsatzC c' => PsatzC (ctimes c c')
| PsatzC p1 , PsatzMulE (PsatzC p2) x => PsatzMulE (PsatzC (ctimes p1 p2)) x
| PsatzC p1 , PsatzMulE x (PsatzC p2) => PsatzMulE (PsatzC (ctimes p1 p2)) x
diff --git a/theories/micromega/Zify.v b/theories/micromega/Zify.v
index 183fd6a914..01cc9ad810 100644
--- a/theories/micromega/Zify.v
+++ b/theories/micromega/Zify.v
@@ -16,11 +16,22 @@ Ltac zify_pre_hook := idtac.
Ltac zify_post_hook := idtac.
-Ltac iter_specs := zify_iter_specs.
+Ltac zify_convert_to_euclidean_division_equations_flag := constr:(false).
+
+(** [zify_internal_to_euclidean_division_equations] is bound in [PreOmega] *)
+Ltac zify_internal_to_euclidean_division_equations := idtac.
+
+Ltac zify_to_euclidean_division_equations :=
+ lazymatch zify_convert_to_euclidean_division_equations_flag with
+ | true => zify_internal_to_euclidean_division_equations
+ | false => idtac
+ end.
+
Ltac zify := intros;
zify_pre_hook ;
zify_elim_let ;
zify_op ;
(zify_iter_specs) ;
- zify_saturate ; zify_post_hook.
+ zify_saturate ;
+ zify_to_euclidean_division_equations ; zify_post_hook.
diff --git a/theories/micromega/ZifyInt63.v b/theories/micromega/ZifyInt63.v
new file mode 100644
index 0000000000..27845898aa
--- /dev/null
+++ b/theories/micromega/ZifyInt63.v
@@ -0,0 +1,178 @@
+Require Import ZArith.
+Require Import Int63.
+Require Import ZifyBool.
+Import ZifyClasses.
+
+Lemma to_Z_bounded : forall x, (0 <= to_Z x < 9223372036854775808)%Z.
+Proof. apply to_Z_bounded. Qed.
+
+Instance Inj_int_Z : InjTyp int Z :=
+ mkinj _ _ to_Z (fun x => 0 <= x < 9223372036854775808)%Z to_Z_bounded.
+Add Zify InjTyp Inj_int_Z.
+
+Instance Op_max_int : CstOp max_int :=
+ { TCst := 9223372036854775807 ; TCstInj := eq_refl }.
+Add Zify CstOp Op_max_int.
+
+Instance Op_digits : CstOp digits :=
+ { TCst := 63 ; TCstInj := eq_refl }.
+Add Zify CstOp Op_digits.
+
+Instance Op_size : CstOp size :=
+ { TCst := 63 ; TCstInj := eq_refl }.
+Add Zify CstOp Op_size.
+
+Instance Op_wB : CstOp wB :=
+ { TCst := 2^63 ; TCstInj := eq_refl }.
+Add Zify CstOp Op_wB.
+
+Lemma ltb_lt : forall n m,
+ (n <? m)%int63 = (φ (n)%int63 <? φ (m)%int63)%Z.
+Proof.
+ intros. apply Bool.eq_true_iff_eq.
+ rewrite ltb_spec. rewrite <- Z.ltb_lt.
+ apply iff_refl.
+Qed.
+
+Instance Op_ltb : BinOp ltb :=
+ {| TBOp := Z.ltb; TBOpInj := ltb_lt |}.
+Add Zify BinOp Op_ltb.
+
+Lemma leb_le : forall n m,
+ (n <=? m)%int63 = (φ (n)%int63 <=? φ (m)%int63)%Z.
+Proof.
+ intros. apply Bool.eq_true_iff_eq.
+ rewrite leb_spec. rewrite <- Z.leb_le.
+ apply iff_refl.
+Qed.
+
+Instance Op_leb : BinOp leb :=
+ {| TBOp := Z.leb; TBOpInj := leb_le |}.
+Add Zify BinOp Op_leb.
+
+Lemma eqb_eq : forall n m,
+ (n =? m)%int63 = (φ (n)%int63 =? φ (m)%int63)%Z.
+Proof.
+ intros. apply Bool.eq_true_iff_eq.
+ rewrite eqb_spec. rewrite Z.eqb_eq.
+ split ; intro H.
+ now subst; reflexivity.
+ now apply to_Z_inj in H.
+Qed.
+
+Instance Op_eqb : BinOp eqb :=
+ {| TBOp := Z.eqb; TBOpInj := eqb_eq |}.
+Add Zify BinOp Op_eqb.
+
+Lemma eq_int_inj : forall n m : int, n = m <-> (φ n = φ m)%int63.
+Proof.
+ split; intro H.
+ rewrite H ; reflexivity.
+ apply to_Z_inj; auto.
+Qed.
+
+Instance Op_eq : BinRel (@eq int) :=
+ {| TR := @eq Z; TRInj := eq_int_inj |}.
+Add Zify BinRel Op_eq.
+
+Instance Op_add : BinOp add :=
+ {| TBOp := fun x y => (x + y) mod 9223372036854775808%Z; TBOpInj := add_spec |}%Z.
+Add Zify BinOp Op_add.
+
+Instance Op_sub : BinOp sub :=
+ {| TBOp := fun x y => (x - y) mod 9223372036854775808%Z; TBOpInj := sub_spec |}%Z.
+Add Zify BinOp Op_sub.
+
+Instance Op_opp : UnOp Int63.opp :=
+ {| TUOp := (fun x => (- x) mod 9223372036854775808)%Z; TUOpInj := (sub_spec 0) |}%Z.
+Add Zify UnOp Op_opp.
+
+Instance Op_oppcarry : UnOp oppcarry :=
+ {| TUOp := (fun x => 2^63 - x - 1)%Z; TUOpInj := oppcarry_spec |}%Z.
+Add Zify UnOp Op_oppcarry.
+
+Instance Op_succ : UnOp succ :=
+ {| TUOp := (fun x => (x + 1) mod 2^63)%Z; TUOpInj := succ_spec |}%Z.
+Add Zify UnOp Op_succ.
+
+Instance Op_pred : UnOp Int63.pred :=
+ {| TUOp := (fun x => (x - 1) mod 2^63)%Z; TUOpInj := pred_spec |}%Z.
+Add Zify UnOp Op_pred.
+
+Instance Op_mul : BinOp mul :=
+ {| TBOp := fun x y => (x * y) mod 9223372036854775808%Z; TBOpInj := mul_spec |}%Z.
+Add Zify BinOp Op_mul.
+
+Instance Op_gcd : BinOp gcd:=
+ {| TBOp := (fun x y => Zgcd_alt.Zgcdn (2 * 63)%nat y x) ; TBOpInj := to_Z_gcd |}.
+Add Zify BinOp Op_gcd.
+
+Instance Op_mod : BinOp Int63.mod :=
+ {| TBOp := Z.modulo ; TBOpInj := mod_spec |}.
+Add Zify BinOp Op_mod.
+
+Instance Op_subcarry : BinOp subcarry :=
+ {| TBOp := (fun x y => (x - y - 1) mod 2^63)%Z ; TBOpInj := subcarry_spec |}.
+Add Zify BinOp Op_subcarry.
+
+Instance Op_addcarry : BinOp addcarry :=
+ {| TBOp := (fun x y => (x + y + 1) mod 2^63)%Z ; TBOpInj := addcarry_spec |}.
+Add Zify BinOp Op_addcarry.
+
+Instance Op_lsr : BinOp lsr :=
+ {| TBOp := (fun x y => x / 2^ y)%Z ; TBOpInj := lsr_spec |}.
+Add Zify BinOp Op_lsr.
+
+Instance Op_lsl : BinOp lsl :=
+ {| TBOp := (fun x y => (x * 2^ y) mod 2^ 63)%Z ; TBOpInj := lsl_spec |}.
+Add Zify BinOp Op_lsl.
+
+Instance Op_lor : BinOp Int63.lor :=
+ {| TBOp := Z.lor ; TBOpInj := lor_spec' |}.
+Add Zify BinOp Op_lor.
+
+Instance Op_land : BinOp Int63.land :=
+ {| TBOp := Z.land ; TBOpInj := land_spec' |}.
+Add Zify BinOp Op_land.
+
+Instance Op_lxor : BinOp Int63.lxor :=
+ {| TBOp := Z.lxor ; TBOpInj := lxor_spec' |}.
+Add Zify BinOp Op_lxor.
+
+Instance Op_div : BinOp div :=
+ {| TBOp := Z.div ; TBOpInj := div_spec |}.
+Add Zify BinOp Op_div.
+
+Instance Op_bit : BinOp bit :=
+ {| TBOp := Z.testbit ; TBOpInj := bitE |}.
+Add Zify BinOp Op_bit.
+
+Instance Op_of_Z : UnOp of_Z :=
+ { TUOp := (fun x => x mod 9223372036854775808)%Z; TUOpInj := of_Z_spec }.
+Add Zify UnOp Op_of_Z.
+
+Instance Op_to_Z : UnOp to_Z :=
+ { TUOp := fun x => x ; TUOpInj := fun x : int => eq_refl }.
+Add Zify UnOp Op_to_Z.
+
+Instance Op_is_zero : UnOp is_zero :=
+ { TUOp := (Z.eqb 0) ; TUOpInj := is_zeroE }.
+Add Zify UnOp Op_is_zero.
+
+Lemma is_evenE : forall x,
+ is_even x = Z.even φ (x)%int63.
+Proof.
+ intros.
+ generalize (is_even_spec x).
+ rewrite Z_evenE.
+ destruct (is_even x).
+ symmetry. apply Z.eqb_eq. auto.
+ symmetry. apply Z.eqb_neq. congruence.
+Qed.
+
+Instance Op_is_even : UnOp is_even :=
+ { TUOp := Z.even ; TUOpInj := is_evenE }.
+Add Zify UnOp Op_is_even.
+
+
+Ltac Zify.zify_convert_to_euclidean_division_equations_flag ::= constr:(true).
diff --git a/theories/omega/PreOmega.v b/theories/omega/PreOmega.v
index 506a4108ee..70f25e7243 100644
--- a/theories/omega/PreOmega.v
+++ b/theories/omega/PreOmega.v
@@ -573,4 +573,6 @@ Ltac zify_N := repeat zify_N_rel; repeat zify_N_op; unfold Z_of_N' in *.
Require Import ZifyClasses ZifyInst.
Require Zify.
+Ltac Zify.zify_internal_to_euclidean_division_equations ::= Z.to_euclidean_division_equations.
+
Ltac zify := Zify.zify.
diff --git a/theories/ssr/ssrbool.v b/theories/ssr/ssrbool.v
index f35da63fd6..e8a036bbb0 100644
--- a/theories/ssr/ssrbool.v
+++ b/theories/ssr/ssrbool.v
@@ -1401,8 +1401,8 @@ Definition mem T (pT : predType T) : pT -> mem_pred T :=
let: PredType toP := pT in fun A => Mem [eta toP A].
Arguments mem {T pT} A : rename, simpl never.
-Notation "x \in A" := (in_mem x (mem A)) : bool_scope.
-Notation "x \in A" := (in_mem x (mem A)) : bool_scope.
+Notation "x \in A" := (in_mem x (mem A)) (only parsing) : bool_scope.
+Notation "x \in A" := (in_mem x (mem A)) (only printing) : bool_scope.
Notation "x \notin A" := (~~ (x \in A)) : bool_scope.
Notation "A =i B" := (eq_mem (mem A) (mem B)) : type_scope.
Notation "{ 'subset' A <= B }" := (sub_mem (mem A) (mem B)) : type_scope.
@@ -1573,9 +1573,12 @@ Arguments has_quality n {T}.
Lemma qualifE n T p x : (x \in @Qualifier n T p) = p x. Proof. by []. Qed.
-Notation "x \is A" := (x \in has_quality 0 A) : bool_scope.
-Notation "x \is 'a' A" := (x \in has_quality 1 A) : bool_scope.
-Notation "x \is 'an' A" := (x \in has_quality 2 A) : bool_scope.
+Notation "x \is A" := (x \in has_quality 0 A) (only parsing) : bool_scope.
+Notation "x \is A" := (x \in has_quality 0 A) (only printing) : bool_scope.
+Notation "x \is 'a' A" := (x \in has_quality 1 A) (only parsing) : bool_scope.
+Notation "x \is 'a' A" := (x \in has_quality 1 A) (only printing) : bool_scope.
+Notation "x \is 'an' A" := (x \in has_quality 2 A) (only parsing) : bool_scope.
+Notation "x \is 'an' A" := (x \in has_quality 2 A) (only printing) : bool_scope.
Notation "x \isn't A" := (x \notin has_quality 0 A) : bool_scope.
Notation "x \isn't 'a' A" := (x \notin has_quality 1 A) : bool_scope.
Notation "x \isn't 'an' A" := (x \notin has_quality 2 A) : bool_scope.
diff --git a/topbin/coqtacticworker_bin.ml b/topbin/coqtacticworker_bin.ml
index 252c8faa05..706554e025 100644
--- a/topbin/coqtacticworker_bin.ml
+++ b/topbin/coqtacticworker_bin.ml
@@ -8,6 +8,6 @@
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)
-module W = AsyncTaskQueue.MakeWorker(Stm.TacTask) ()
+module W = AsyncTaskQueue.MakeWorker(Partac.TacTask) ()
let () = WorkerLoop.start ~init:W.init_stdout ~loop:W.main_loop "coqtacticworker"
diff --git a/toplevel/coqargs.ml b/toplevel/coqargs.ml
index eb386ea3e8..d587e57fd8 100644
--- a/toplevel/coqargs.ml
+++ b/toplevel/coqargs.ml
@@ -508,6 +508,7 @@ let parse_args ~help ~init arglist : t * string list =
|"-color" -> set_color oval (next ())
|"-config"|"--config" -> set_query oval PrintConfig
|"-debug" -> Coqinit.set_debug (); oval
+ |"-xml-debug" -> Flags.xml_debug := true; Coqinit.set_debug (); oval
|"-diffs" ->
add_set_option oval Proof_diffs.opt_name @@ Stm.OptionSet (Some (next ()))
|"-stm-debug" -> Stm.stm_debug := true; oval
diff --git a/toplevel/coqinit.ml b/toplevel/coqinit.ml
index 9faa455657..501047c520 100644
--- a/toplevel/coqinit.ml
+++ b/toplevel/coqinit.ml
@@ -56,14 +56,21 @@ let build_stdlib_vo_path ~unix_path ~coq_path =
let open Loadpath in
{ unix_path; coq_path ; has_ml = false; implicit = true; recursive = true }
+(* Note we don't use has_ml=true due to #12771 , we need to see if we
+ should just remove that option *)
let build_userlib_path ~unix_path =
let open Loadpath in
- { unix_path
- ; coq_path = Libnames.default_root_prefix
- ; has_ml = true
- ; implicit = false
- ; recursive = true
- }
+ if Sys.file_exists unix_path then
+ let ml_path = System.all_subdirs ~unix_path |> List.map fst in
+ let vo_path =
+ { unix_path
+ ; coq_path = Libnames.default_root_prefix
+ ; has_ml = false
+ ; implicit = false
+ ; recursive = true
+ } in
+ ml_path, [vo_path]
+ else [], []
(* LoadPath for Coq user libraries *)
let libs_init_load_path ~coqlib =
@@ -75,24 +82,30 @@ let libs_init_load_path ~coqlib =
let coq_path = Names.DirPath.make [Libnames.coq_root] in
(* ML includes *)
- let plugins_dirs = System.all_subdirs ~unix_path:(coqlib/"plugins") in
- List.map fst plugins_dirs,
-
- (* current directory (not recursively!) *)
- [ { unix_path = "."
- ; coq_path = Libnames.default_root_prefix
- ; implicit = false
- ; has_ml = true
- ; recursive = false
- } ] @
-
- (* then standard library *)
- [build_stdlib_vo_path ~unix_path:(coqlib/"theories") ~coq_path] @
-
- (* then user-contrib *)
- (if Sys.file_exists user_contrib then
- [build_userlib_path ~unix_path:user_contrib] else []
- ) @
-
- (* then directories in XDG_DATA_DIRS and XDG_DATA_HOME and COQPATH *)
- List.map (fun s -> build_userlib_path ~unix_path:s) (xdg_dirs @ coqpath)
+ let plugins_dirs = System.all_subdirs ~unix_path:(coqlib/"plugins") |> List.map fst in
+
+ let contrib_ml, contrib_vo = build_userlib_path ~unix_path:user_contrib in
+
+ let misc_ml, misc_vo =
+ List.map (fun s -> build_userlib_path ~unix_path:s) (xdg_dirs @ coqpath) |> List.split in
+
+ let ml_loadpath = plugins_dirs @ contrib_ml @ List.concat misc_ml in
+ let vo_loadpath =
+ (* current directory (not recursively!) *)
+ [ { unix_path = "."
+ ; coq_path = Libnames.default_root_prefix
+ ; implicit = false
+ ; has_ml = true
+ ; recursive = false
+ } ] @
+
+ (* then standard library *)
+ [build_stdlib_vo_path ~unix_path:(coqlib/"theories") ~coq_path] @
+
+ (* then user-contrib *)
+ contrib_vo @
+
+ (* then directories in XDG_DATA_DIRS and XDG_DATA_HOME and COQPATH *)
+ List.concat misc_vo
+ in
+ ml_loadpath, vo_loadpath
diff --git a/toplevel/coqinit.mli b/toplevel/coqinit.mli
index 2bfbbde50e..b96a0ef162 100644
--- a/toplevel/coqinit.mli
+++ b/toplevel/coqinit.mli
@@ -14,7 +14,9 @@ val set_debug : unit -> unit
val load_rcfile : rcfile:(string option) -> state:Vernac.State.t -> Vernac.State.t
-(* LoadPath for Coq user libraries *)
+(** Standard LoadPath for Coq user libraries; in particular it
+ includes (in-order) Coq's standard library, Coq's [user-contrib]
+ folder, and directories specified in [COQPATH] and [XDG_DIRS] *)
val libs_init_load_path
: coqlib:CUnix.physical_path
-> CUnix.physical_path list * Loadpath.vo_path list
diff --git a/toplevel/coqloop.ml b/toplevel/coqloop.ml
index 88924160ff..6460378edc 100644
--- a/toplevel/coqloop.ml
+++ b/toplevel/coqloop.ml
@@ -371,41 +371,13 @@ let exit_on_error =
declare_bool_option_and_ref ~depr:false ~key:["Coqtop";"Exit";"On";"Error"]
~value:false
-(* XXX: This is duplicated with Vernacentries.show_proof , at some
- point we should consolidate the code *)
-let show_proof_diff_to_pp pstate =
- let p = Option.get pstate in
- let sigma, env = Proof.get_proof_context p in
- let pprf = Proof.partial_proof p in
- Pp.prlist_with_sep Pp.fnl (Printer.pr_econstr_env env sigma) pprf
-
-let show_proof_diff_cmd ~state removed =
+let show_proof_diff_cmd ~state diff_opt =
let open Vernac.State in
- try
- let n_pp = show_proof_diff_to_pp state.proof in
- if true (*Proof_diffs.show_diffs ()*) then
- let doc = state.doc in
- let oproof = Stm.get_prev_proof ~doc (Stm.get_current_state ~doc) in
- try
- let o_pp = show_proof_diff_to_pp oproof in
- let tokenize_string = Proof_diffs.tokenize_string in
- let show_removed = Some removed in
- Pp_diff.diff_pp_combined ~tokenize_string ?show_removed o_pp n_pp
- with
- | Proof.NoSuchGoal _
- | Option.IsNone -> n_pp
- | Pp_diff.Diff_Failure msg -> begin
- (* todo: print the unparsable string (if we know it) *)
- Feedback.msg_warning Pp.(str ("Diff failure: " ^ msg) ++ cut()
- ++ str "Showing results without diff highlighting" );
- n_pp
- end
- else
- n_pp
- with
- | Proof.NoSuchGoal _
- | Option.IsNone ->
- CErrors.user_err (str "No goals to show.")
+ match state.proof with
+ | None -> CErrors.user_err (str "No proofs to diff.")
+ | Some proof ->
+ let old = Stm.get_prev_proof ~doc:state.doc state.sid in
+ Proof_diffs.diff_proofs ~diff_opt ?old proof
let process_toplevel_command ~state stm =
let open Vernac.State in
@@ -444,12 +416,12 @@ let process_toplevel_command ~state stm =
Feedback.msg_notice (v 0 (goal ++ evars));
state
- | VernacShowProofDiffs removed ->
+ | VernacShowProofDiffs diff_opt ->
(* We print nothing if there are no goals left *)
if not (Proof_diffs.color_enabled ()) then
CErrors.user_err Pp.(str "Show Proof Diffs requires setting the \"-color\" command line argument to \"on\" or \"auto\".")
else
- let out = show_proof_diff_cmd ~state removed in
+ let out = show_proof_diff_cmd ~state diff_opt in
Feedback.msg_notice out;
state
diff --git a/toplevel/g_toplevel.mlg b/toplevel/g_toplevel.mlg
index 1902103a3e..ef79f4562e 100644
--- a/toplevel/g_toplevel.mlg
+++ b/toplevel/g_toplevel.mlg
@@ -20,7 +20,7 @@ type vernac_toplevel =
| VernacQuit
| VernacControl of vernac_control
| VernacShowGoal of { gid : int; sid: int }
- | VernacShowProofDiffs of bool
+ | VernacShowProofDiffs of Proof_diffs.diffOpt
module Toplevel_ : sig
val vernac_toplevel : vernac_toplevel option Entry.t
@@ -52,7 +52,8 @@ GRAMMAR EXTEND Gram
| test_show_goal; IDENT "Show"; IDENT "Goal"; gid = natural; IDENT "at"; sid = natural; "." ->
{ Some (VernacShowGoal {gid; sid}) }
| IDENT "Show"; IDENT "Proof"; IDENT "Diffs"; removed = OPT [ IDENT "removed" -> { () } ]; "." ->
- { Some (VernacShowProofDiffs (removed <> None)) }
+ { Some (VernacShowProofDiffs
+ (if removed = None then Proof_diffs.DiffOn else Proof_diffs.DiffRemoved)) }
| cmd = Pvernac.Vernac_.main_entry ->
{ match cmd with
| None -> None
diff --git a/toplevel/usage.ml b/toplevel/usage.ml
index 732ad05b26..6fb5f821ee 100644
--- a/toplevel/usage.ml
+++ b/toplevel/usage.ml
@@ -72,6 +72,7 @@ let print_usage_common co command =
\n -init-file f set the rcfile to f\
\n -bt print backtraces (requires configure debug flag)\
\n -debug debug mode (implies -bt)\
+\n -xml-debug debug mode and print XML messages to/from coqide\
\n -diffs (on|off|removed) highlight differences between proof steps\
\n -stm-debug STM debug mode (will trace every transaction)\
\n -noglob do not dump globalizations\
diff --git a/user-contrib/Ltac2/g_ltac2.mlg b/user-contrib/Ltac2/g_ltac2.mlg
index 5ae8f4ae6e..65b61a0d93 100644
--- a/user-contrib/Ltac2/g_ltac2.mlg
+++ b/user-contrib/Ltac2/g_ltac2.mlg
@@ -71,8 +71,9 @@ let test_ltac1_env =
lk_ident_list >> lk_kw "|-"
end
-let tac2expr = Tac2entries.Pltac.tac2expr
-let tac2type = Entry.create "tac2type"
+let ltac2_expr = Tac2entries.Pltac.ltac2_expr
+let _ltac2_expr = ltac2_expr
+let ltac2_type = Entry.create "ltac2_type"
let tac2def_val = Entry.create "tac2def_val"
let tac2def_typ = Entry.create "tac2def_typ"
let tac2def_ext = Entry.create "tac2def_ext"
@@ -80,7 +81,7 @@ let tac2def_syn = Entry.create "tac2def_syn"
let tac2def_mut = Entry.create "tac2def_mut"
let tac2mode = Entry.create "ltac2_command"
-let ltac1_expr = Pltac.tactic_expr
+let ltac_expr = Pltac.ltac_expr
let tac2expr_in_env = Tac2entries.Pltac.tac2expr_in_env
let inj_wit wit loc x = CAst.make ~loc @@ CTacExt (wit, x)
@@ -101,7 +102,7 @@ let pattern_of_qualid qid =
}
GRAMMAR EXTEND Gram
- GLOBAL: tac2expr tac2type tac2def_val tac2def_typ tac2def_ext tac2def_syn
+ GLOBAL: ltac2_expr ltac2_type tac2def_val tac2def_typ tac2def_ext tac2def_syn
tac2def_mut tac2expr_in_env;
tac2pat:
[ "1" LEFTA
@@ -125,7 +126,7 @@ GRAMMAR EXTEND Gram
atomic_tac2pat:
[ [ ->
{ CAst.make ~loc @@ CPatRef (AbsKn (Tuple 0), []) }
- | p = tac2pat; ":"; t = tac2type ->
+ | p = tac2pat; ":"; t = ltac2_type ->
{ CAst.make ~loc @@ CPatCnv (p, t) }
| p = tac2pat; ","; pl = LIST0 tac2pat SEP "," ->
{ let pl = p :: pl in
@@ -133,43 +134,45 @@ GRAMMAR EXTEND Gram
| p = tac2pat -> { p }
] ]
;
- tac2expr:
+ ltac2_expr:
[ "6" RIGHTA
[ e1 = SELF; ";"; e2 = SELF -> { CAst.make ~loc @@ CTacSeq (e1, e2) } ]
| "5"
- [ "fun"; it = LIST1 input_fun ; "=>"; body = tac2expr LEVEL "6" ->
+ [ "fun"; it = LIST1 input_fun ; "=>"; body = ltac2_expr LEVEL "6" ->
{ CAst.make ~loc @@ CTacFun (it, body) }
| "let"; isrec = rec_flag;
lc = LIST1 let_clause SEP "with"; "in";
- e = tac2expr LEVEL "6" ->
+ e = ltac2_expr LEVEL "6" ->
{ CAst.make ~loc @@ CTacLet (isrec, lc, e) }
- | "match"; e = tac2expr LEVEL "5"; "with"; bl = branches; "end" ->
+ | "match"; e = ltac2_expr LEVEL "5"; "with"; bl = branches; "end" ->
{ CAst.make ~loc @@ CTacCse (e, bl) }
+ | "if"; e = ltac2_expr LEVEL "5"; "then"; e1 = ltac2_expr LEVEL "5"; "else"; e2 = ltac2_expr LEVEL "5" ->
+ { CAst.make ~loc @@ CTacIft (e, e1, e2) }
]
| "4" LEFTA [ ]
| "3" [ e0 = SELF; ","; el = LIST1 NEXT SEP "," ->
{ let el = e0 :: el in
CAst.make ~loc @@ CTacApp (CAst.make ~loc @@ CTacCst (AbsKn (Tuple (List.length el))), el) } ]
| "2" RIGHTA
- [ e1 = tac2expr; "::"; e2 = tac2expr ->
+ [ e1 = ltac2_expr; "::"; e2 = ltac2_expr ->
{ CAst.make ~loc @@ CTacApp (CAst.make ~loc @@ CTacCst (AbsKn (Other Tac2core.Core.c_cons)), [e1; e2]) }
]
| "1" LEFTA
- [ e = tac2expr; el = LIST1 tac2expr LEVEL "0" ->
+ [ e = ltac2_expr; el = LIST1 ltac2_expr LEVEL "0" ->
{ CAst.make ~loc @@ CTacApp (e, el) }
| e = SELF; ".("; qid = Prim.qualid; ")" ->
{ CAst.make ~loc @@ CTacPrj (e, RelId qid) }
- | e = SELF; ".("; qid = Prim.qualid; ")"; ":="; r = tac2expr LEVEL "5" ->
+ | e = SELF; ".("; qid = Prim.qualid; ")"; ":="; r = ltac2_expr LEVEL "5" ->
{ CAst.make ~loc @@ CTacSet (e, RelId qid, r) } ]
| "0"
[ "("; a = SELF; ")" -> { a }
- | "("; a = SELF; ":"; t = tac2type; ")" ->
+ | "("; a = SELF; ":"; t = ltac2_type; ")" ->
{ CAst.make ~loc @@ CTacCnv (a, t) }
| "()" ->
{ CAst.make ~loc @@ CTacCst (AbsKn (Tuple 0)) }
| "("; ")" ->
{ CAst.make ~loc @@ CTacCst (AbsKn (Tuple 0)) }
- | "["; a = LIST0 tac2expr LEVEL "5" SEP ";"; "]" ->
+ | "["; a = LIST0 ltac2_expr LEVEL "5" SEP ";"; "]" ->
{ Tac2quote.of_list ~loc (fun x -> x) a }
| "{"; a = tac2rec_fieldexprs; "}" ->
{ CAst.make ~loc @@ CTacRec a }
@@ -183,7 +186,7 @@ GRAMMAR EXTEND Gram
]
;
branch:
- [ [ pat = tac2pat LEVEL "1"; "=>"; e = tac2expr LEVEL "6" -> { (pat, e) } ] ]
+ [ [ pat = tac2pat LEVEL "1"; "=>"; e = ltac2_expr LEVEL "6" -> { (pat, e) } ] ]
;
rec_flag:
[ [ IDENT "rec" -> { true }
@@ -193,7 +196,7 @@ GRAMMAR EXTEND Gram
[ [ IDENT "mutable" -> { true }
| -> { false } ] ]
;
- typ_param:
+ ltac2_typevar:
[ [ "'"; id = Prim.ident -> { id } ] ]
;
tactic_atom:
@@ -210,19 +213,19 @@ GRAMMAR EXTEND Gram
| IDENT "constr"; ":"; "("; c = Constr.lconstr; ")" -> { Tac2quote.of_constr c }
| IDENT "open_constr"; ":"; "("; c = Constr.lconstr; ")" -> { Tac2quote.of_open_constr c }
| IDENT "ident"; ":"; "("; c = lident; ")" -> { Tac2quote.of_ident c }
- | IDENT "pattern"; ":"; "("; c = Constr.lconstr_pattern; ")" -> { inj_pattern loc c }
+ | IDENT "pattern"; ":"; "("; c = Constr.cpattern; ")" -> { inj_pattern loc c }
| IDENT "reference"; ":"; "("; c = globref; ")" -> { inj_reference loc c }
| IDENT "ltac1"; ":"; "("; qid = ltac1_expr_in_env; ")" -> { inj_ltac1 loc qid }
| IDENT "ltac1val"; ":"; "("; qid = ltac1_expr_in_env; ")" -> { inj_ltac1val loc qid }
] ]
;
ltac1_expr_in_env:
- [ [ test_ltac1_env; ids = LIST0 locident; "|-"; e = ltac1_expr -> { ids, e }
- | e = ltac1_expr -> { [], e }
+ [ [ test_ltac1_env; ids = LIST0 locident; "|-"; e = ltac_expr -> { ids, e }
+ | e = ltac_expr -> { [], e }
] ]
;
tac2expr_in_env :
- [ [ test_ltac1_env; ids = LIST0 locident; "|-"; e = tac2expr ->
+ [ [ test_ltac1_env; ids = LIST0 locident; "|-"; e = ltac2_expr ->
{ let check { CAst.v = id; CAst.loc = loc } =
if Tac2env.is_constructor (Libnames.qualid_of_ident ?loc id) then
CErrors.user_err ?loc Pp.(str "Invalid bound Ltac2 identifier " ++ Id.print id)
@@ -230,11 +233,11 @@ GRAMMAR EXTEND Gram
let () = List.iter check ids in
(ids, e)
}
- | tac = tac2expr -> { [], tac }
+ | tac = ltac2_expr -> { [], tac }
] ]
;
let_clause:
- [ [ binder = let_binder; ":="; te = tac2expr ->
+ [ [ binder = let_binder; ":="; te = ltac2_expr ->
{ let (pat, fn) = binder in
let te = match fn with
| None -> te
@@ -252,23 +255,23 @@ GRAMMAR EXTEND Gram
| _ -> CErrors.user_err ~loc (str "Invalid pattern") }
] ]
;
- tac2type:
+ ltac2_type:
[ "5" RIGHTA
- [ t1 = tac2type; "->"; t2 = tac2type -> { CAst.make ~loc @@ CTypArrow (t1, t2) } ]
+ [ t1 = ltac2_type; "->"; t2 = ltac2_type -> { CAst.make ~loc @@ CTypArrow (t1, t2) } ]
| "2"
- [ t = tac2type; "*"; tl = LIST1 tac2type LEVEL "1" SEP "*" ->
+ [ t = ltac2_type; "*"; tl = LIST1 ltac2_type LEVEL "1" SEP "*" ->
{ let tl = t :: tl in
CAst.make ~loc @@ CTypRef (AbsKn (Tuple (List.length tl)), tl) } ]
| "1" LEFTA
[ t = SELF; qid = Prim.qualid -> { CAst.make ~loc @@ CTypRef (RelId qid, [t]) } ]
| "0"
- [ "("; p = LIST1 tac2type LEVEL "5" SEP ","; ")"; qid = OPT Prim.qualid ->
+ [ "("; p = LIST1 ltac2_type LEVEL "5" SEP ","; ")"; qid = OPT Prim.qualid ->
{ match p, qid with
| [t], None -> t
| _, None -> CErrors.user_err ~loc (Pp.str "Syntax error")
| ts, Some qid -> CAst.make ~loc @@ CTypRef (RelId qid, p)
}
- | id = typ_param -> { CAst.make ~loc @@ CTypVar (Name id) }
+ | id = ltac2_typevar -> { CAst.make ~loc @@ CTypVar (Name id) }
| "_" -> { CAst.make ~loc @@ CTypVar Anonymous }
| qid = Prim.qualid -> { CAst.make ~loc @@ CTypRef (RelId qid, []) }
]
@@ -284,7 +287,7 @@ GRAMMAR EXTEND Gram
[ [ b = tac2pat LEVEL "0" -> { b } ] ]
;
tac2def_body:
- [ [ name = binder; it = LIST0 input_fun; ":="; e = tac2expr ->
+ [ [ name = binder; it = LIST0 input_fun; ":="; e = ltac2_expr ->
{ let e = if List.is_empty it then e else CAst.make ~loc @@ CTacFun (it, e) in
(name, e) }
] ]
@@ -295,10 +298,10 @@ GRAMMAR EXTEND Gram
] ]
;
tac2def_mut:
- [ [ "Set"; qid = Prim.qualid; old = OPT [ "as"; id = locident -> { id } ]; ":="; e = tac2expr -> { StrMut (qid, old, e) } ] ]
+ [ [ "Set"; qid = Prim.qualid; old = OPT [ "as"; id = locident -> { id } ]; ":="; e = ltac2_expr -> { StrMut (qid, old, e) } ] ]
;
tac2typ_knd:
- [ [ t = tac2type -> { CTydDef (Some t) }
+ [ [ t = ltac2_type -> { CTydDef (Some t) }
| "["; ".."; "]" -> { CTydOpn }
| "["; t = tac2alg_constructors; "]" -> { CTydAlg t }
| "{"; t = tac2rec_fields; "}"-> { CTydRec t } ] ]
@@ -309,7 +312,7 @@ GRAMMAR EXTEND Gram
;
tac2alg_constructor:
[ [ c = Prim.ident -> { (c, []) }
- | c = Prim.ident; "("; args = LIST0 tac2type SEP ","; ")"-> { (c, args) } ] ]
+ | c = Prim.ident; "("; args = LIST0 ltac2_type SEP ","; ")"-> { (c, args) } ] ]
;
tac2rec_fields:
[ [ f = tac2rec_field; ";"; l = tac2rec_fields -> { f :: l }
@@ -318,7 +321,7 @@ GRAMMAR EXTEND Gram
| -> { [] } ] ]
;
tac2rec_field:
- [ [ mut = mut_flag; id = Prim.ident; ":"; t = tac2type -> { (id, mut, t) } ] ]
+ [ [ mut = mut_flag; id = Prim.ident; ":"; t = ltac2_type -> { (id, mut, t) } ] ]
;
tac2rec_fieldexprs:
[ [ f = tac2rec_fieldexpr; ";"; l = tac2rec_fieldexprs -> { f :: l }
@@ -327,12 +330,12 @@ GRAMMAR EXTEND Gram
| -> { [] } ] ]
;
tac2rec_fieldexpr:
- [ [ qid = Prim.qualid; ":="; e = tac2expr LEVEL "1" -> { RelId qid, e } ] ]
+ [ [ qid = Prim.qualid; ":="; e = ltac2_expr LEVEL "1" -> { RelId qid, e } ] ]
;
tac2typ_prm:
[ [ -> { [] }
- | id = typ_param -> { [CAst.make ~loc id] }
- | "("; ids = LIST1 [ id = typ_param -> { CAst.make ~loc id } ] SEP "," ;")" -> { ids }
+ | id = ltac2_typevar -> { [CAst.make ~loc id] }
+ | "("; ids = LIST1 [ id = ltac2_typevar -> { CAst.make ~loc id } ] SEP "," ;")" -> { ids }
] ]
;
tac2typ_def:
@@ -350,7 +353,7 @@ GRAMMAR EXTEND Gram
] ]
;
tac2def_ext:
- [ [ "@"; IDENT "external"; id = locident; ":"; t = tac2type LEVEL "5"; ":=";
+ [ [ "@"; IDENT "external"; id = locident; ":"; t = ltac2_type LEVEL "5"; ":=";
plugin = Prim.string; name = Prim.string ->
{ let ml = { mltac_plugin = plugin; mltac_tactic = name } in
StrPrm (id, t, ml) }
@@ -361,11 +364,11 @@ GRAMMAR EXTEND Gram
| id = Prim.ident -> { CAst.make ~loc (Some id) }
] ]
;
- sexpr:
+ ltac2_scope:
[ [ s = Prim.string -> { SexprStr (CAst.make ~loc s) }
| n = Prim.integer -> { SexprInt (CAst.make ~loc n) }
| id = syn_node -> { SexprRec (loc, id, []) }
- | id = syn_node; "("; tok = LIST1 sexpr SEP "," ; ")" ->
+ | id = syn_node; "("; tok = LIST1 ltac2_scope SEP "," ; ")" ->
{ SexprRec (loc, id, tok) }
] ]
;
@@ -375,8 +378,8 @@ GRAMMAR EXTEND Gram
] ]
;
tac2def_syn:
- [ [ "Notation"; toks = LIST1 sexpr; n = syn_level; ":=";
- e = tac2expr ->
+ [ [ "Notation"; toks = LIST1 ltac2_scope; n = syn_level; ":=";
+ e = ltac2_expr ->
{ StrSyn (toks, n, e) }
] ]
;
@@ -497,7 +500,7 @@ GRAMMAR EXTEND Gram
;
simple_intropattern:
[ [ pat = simple_intropattern_closed ->
-(* l = LIST0 ["%"; c = operconstr LEVEL "0" -> c] -> *)
+(* l = LIST0 ["%"; c = term LEVEL "0" -> c] -> *)
(** TODO: handle %pat *)
{ pat }
] ]
@@ -654,26 +657,26 @@ GRAMMAR EXTEND Gram
[ [ r = oriented_rewriter -> { r } ] ]
;
tactic_then_last:
- [ [ "|"; lta = LIST0 (OPT tac2expr LEVEL "6") SEP "|" -> { lta }
+ [ [ "|"; lta = LIST0 (OPT ltac2_expr LEVEL "6") SEP "|" -> { lta }
| -> { [] }
] ]
;
- tactic_then_gen:
- [ [ ta = tac2expr; "|"; tg = tactic_then_gen -> { let (first,last) = tg in (Some ta :: first, last) }
- | ta = tac2expr; ".."; l = tactic_then_last -> { ([], Some (Some ta, l)) }
+ for_each_goal:
+ [ [ ta = ltac2_expr; "|"; tg = for_each_goal -> { let (first,last) = tg in (Some ta :: first, last) }
+ | ta = ltac2_expr; ".."; l = tactic_then_last -> { ([], Some (Some ta, l)) }
| ".."; l = tactic_then_last -> { ([], Some (None, l)) }
- | ta = tac2expr -> { ([Some ta], None) }
- | "|"; tg = tactic_then_gen -> { let (first,last) = tg in (None :: first, last) }
+ | ta = ltac2_expr -> { ([Some ta], None) }
+ | "|"; tg = for_each_goal -> { let (first,last) = tg in (None :: first, last) }
| -> { ([None], None) }
] ]
;
q_dispatch:
- [ [ d = tactic_then_gen -> { CAst.make ~loc d } ] ]
+ [ [ d = for_each_goal -> { CAst.make ~loc d } ] ]
;
q_occurrences:
[ [ occs = occs -> { occs } ] ]
;
- red_flag:
+ ltac2_red_flag:
[ [ IDENT "beta" -> { CAst.make ~loc @@ QBeta }
| IDENT "iota" -> { CAst.make ~loc @@ QIota }
| IDENT "match" -> { CAst.make ~loc @@ QMatch }
@@ -702,7 +705,7 @@ GRAMMAR EXTEND Gram
] ]
;
strategy_flag:
- [ [ s = LIST1 red_flag -> { CAst.make ~loc s }
+ [ [ s = LIST1 ltac2_red_flag -> { CAst.make ~loc s }
| d = delta_flag ->
{ CAst.make ~loc
[CAst.make ~loc QBeta; CAst.make ~loc QIota; CAst.make ~loc QZeta; d] }
@@ -721,11 +724,11 @@ GRAMMAR EXTEND Gram
;
match_pattern:
[ [ IDENT "context"; id = OPT Prim.ident;
- "["; pat = Constr.lconstr_pattern; "]" -> { CAst.make ~loc @@ QConstrMatchContext (id, pat) }
- | pat = Constr.lconstr_pattern -> { CAst.make ~loc @@ QConstrMatchPattern pat } ] ]
+ "["; pat = Constr.cpattern; "]" -> { CAst.make ~loc @@ QConstrMatchContext (id, pat) }
+ | pat = Constr.cpattern -> { CAst.make ~loc @@ QConstrMatchPattern pat } ] ]
;
match_rule:
- [ [ mp = match_pattern; "=>"; tac = tac2expr ->
+ [ [ mp = match_pattern; "=>"; tac = ltac2_expr ->
{ CAst.make ~loc @@ (mp, tac) }
] ]
;
@@ -748,16 +751,16 @@ GRAMMAR EXTEND Gram
] ]
;
gmatch_rule:
- [ [ mp = gmatch_pattern; "=>"; tac = tac2expr ->
+ [ [ mp = gmatch_pattern; "=>"; tac = ltac2_expr ->
{ CAst.make ~loc @@ (mp, tac) }
] ]
;
- gmatch_list:
+ goal_match_list:
[ [ mrl = LIST1 gmatch_rule SEP "|" -> { CAst.make ~loc @@ mrl }
| "|"; mrl = LIST1 gmatch_rule SEP "|" -> { CAst.make ~loc @@ mrl } ] ]
;
q_goal_matching:
- [ [ m = gmatch_list -> { m } ] ]
+ [ [ m = goal_match_list -> { m } ] ]
;
move_location:
[ [ "at"; IDENT "top" -> { CAst.make ~loc @@ QMoveFirst }
@@ -789,7 +792,7 @@ GRAMMAR EXTEND Gram
] ]
;
by_tactic:
- [ [ "by"; tac = tac2expr -> { Some tac }
+ [ [ "by"; tac = ltac2_expr -> { Some tac }
| -> { None }
] ]
;
@@ -812,8 +815,8 @@ END
(*
GRAMMAR EXTEND Gram
- Pcoq.Constr.operconstr: LEVEL "0"
- [ [ IDENT "ltac2"; ":"; "("; tac = tac2expr; ")" ->
+ Pcoq.Constr.term: LEVEL "0"
+ [ [ IDENT "ltac2"; ":"; "("; tac = ltac2_expr; ")" ->
{ let arg = Genarg.in_gen (Genarg.rawwit Tac2env.wit_ltac2_constr) tac in
CAst.make ~loc (CHole (None, Namegen.IntroAnonymous, Some arg)) }
| test_ampersand_ident; "&"; id = Prim.ident ->
@@ -858,7 +861,7 @@ let rules = [
Pcoq.(
Production.make
(Rule.stop ++ Symbol.token (PIDENT (Some "ltac2")) ++ Symbol.token (PKEYWORD ":") ++
- Symbol.token (PKEYWORD "(") ++ Symbol.nterm tac2expr ++ Symbol.token (PKEYWORD ")"))
+ Symbol.token (PKEYWORD "(") ++ Symbol.nterm ltac2_expr ++ Symbol.token (PKEYWORD ")"))
begin fun _ tac _ _ _ loc ->
let arg = Genarg.in_gen (Genarg.rawwit Tac2env.wit_ltac2_constr) tac in
CAst.make ~loc (CHole (None, Namegen.IntroAnonymous, Some arg))
@@ -867,7 +870,7 @@ let rules = [
] in
Hook.set Tac2entries.register_constr_quotations begin fun () ->
- Pcoq.grammar_extend Pcoq.Constr.operconstr {pos=Some (Gramlib.Gramext.Level "0"); data=[(None, None, rules)]}
+ Pcoq.grammar_extend Pcoq.Constr.term {pos=Some (Gramlib.Gramext.Level "0"); data=[(None, None, rules)]}
end
}
@@ -890,7 +893,7 @@ END
VERNAC ARGUMENT EXTEND ltac2_expr
PRINTED BY { pr_ltac2expr }
-| [ tac2expr(e) ] -> { e }
+| [ _ltac2_expr(e) ] -> { e }
END
{
@@ -920,10 +923,10 @@ open Vernacextend
}
VERNAC { tac2mode } EXTEND VernacLtac2
-| ![proof] [ ltac2_expr(t) ltac_use_default(default) ] =>
+| ![proof] [ ltac2_expr(t) ltac_use_default(with_end_tac) ] =>
{ classify_as_proofstep } -> {
(* let g = Option.default (Proof_global.get_default_goal_selector ()) g in *)
- fun ~pstate -> Tac2entries.call ~pstate ~default t }
+ fun ~pstate -> Tac2entries.call ~pstate ~with_end_tac t }
END
GRAMMAR EXTEND Gram
diff --git a/user-contrib/Ltac2/tac2core.ml b/user-contrib/Ltac2/tac2core.ml
index 3ce50865c0..5d49d1635c 100644
--- a/user-contrib/Ltac2/tac2core.ml
+++ b/user-contrib/Ltac2/tac2core.ml
@@ -1541,12 +1541,12 @@ end
let () = add_scope "tactic" begin function
| [] ->
(* Default to level 5 parsing *)
- let scope = Pcoq.Symbol.nterml tac2expr "5" in
+ let scope = Pcoq.Symbol.nterml ltac2_expr "5" in
let act tac = tac in
Tac2entries.ScopeRule (scope, act)
| [SexprInt {loc;v=n}] as arg ->
let () = if n < 0 || n > 6 then scope_fail "tactic" arg in
- let scope = Pcoq.Symbol.nterml tac2expr (string_of_int n) in
+ let scope = Pcoq.Symbol.nterml ltac2_expr (string_of_int n) in
let act tac = tac in
Tac2entries.ScopeRule (scope, act)
| arg -> scope_fail "tactic" arg
diff --git a/user-contrib/Ltac2/tac2entries.ml b/user-contrib/Ltac2/tac2entries.ml
index 30340cd632..eebd6635fa 100644
--- a/user-contrib/Ltac2/tac2entries.ml
+++ b/user-contrib/Ltac2/tac2entries.ml
@@ -24,7 +24,8 @@ open Tac2intern
module Pltac =
struct
-let tac2expr = Pcoq.Entry.create "tac2expr"
+let ltac2_expr = Pcoq.Entry.create "ltac2_expr"
+let tac2expr = ltac2_expr
let tac2expr_in_env = Pcoq.Entry.create "tac2expr_in_env"
let q_ident = Pcoq.Entry.create "q_ident"
@@ -643,7 +644,7 @@ let perform_notation syn st =
| Some lev -> Some (string_of_int lev)
in
let rule = (lev, None, [rule]) in
- ([Pcoq.ExtendRule (Pltac.tac2expr, {Pcoq.pos=None; data=[rule]})], st)
+ ([Pcoq.ExtendRule (Pltac.ltac2_expr, {Pcoq.pos=None; data=[rule]})], st)
let ltac2_notation =
Pcoq.create_grammar_command "ltac2-notation" perform_notation
@@ -911,25 +912,19 @@ let print_ltac qid =
(** Calling tactics *)
-let solve ~pstate default tac =
- let pstate, status = Declare.Proof.map_fold_endline pstate ~f:(fun etac p ->
- let with_end_tac = if default then Some etac else None in
- let g = Goal_select.get_default_goal_selector () in
- let (p, status) = Proof.solve g None tac ?with_end_tac p in
- (* in case a strict subtree was completed,
- go back to the top of the prooftree *)
- let p = Proof.maximal_unfocus Vernacentries.command_focus p in
- p, status)
- in
- if not status then Feedback.feedback Feedback.AddedAxiom;
- pstate
-
-let call ~pstate ~default e =
+let ltac2_interp e =
let loc = e.loc in
let (e, t) = intern ~strict:false [] e in
let () = check_unit ?loc t in
let tac = Tac2interp.interp Tac2interp.empty_environment e in
- solve ~pstate default (Proofview.tclIGNORE tac)
+ Proofview.tclIGNORE tac
+
+let ComTactic.Interpreter ltac2_interp = ComTactic.register_tactic_interpreter "ltac2" ltac2_interp
+
+let call ~pstate ~with_end_tac tac =
+ ComTactic.solve ~pstate ~with_end_tac
+ (Goal_select.get_default_goal_selector())
+ ~info:None (ltac2_interp tac)
(** Primitive algebraic types than can't be defined Coq-side *)
diff --git a/user-contrib/Ltac2/tac2entries.mli b/user-contrib/Ltac2/tac2entries.mli
index fc56a54e3a..782968c6e1 100644
--- a/user-contrib/Ltac2/tac2entries.mli
+++ b/user-contrib/Ltac2/tac2entries.mli
@@ -53,7 +53,7 @@ val print_ltac : Libnames.qualid -> unit
(** {5 Eval loop} *)
(** Evaluate a tactic expression in the current environment *)
-val call : pstate:Declare.Proof.t -> default:bool -> raw_tacexpr -> Declare.Proof.t
+val call : pstate:Declare.Proof.t -> with_end_tac:bool -> raw_tacexpr -> Declare.Proof.t
(** {5 Toplevel exceptions} *)
@@ -63,7 +63,9 @@ val backtrace : backtrace Exninfo.t
module Pltac :
sig
+val ltac2_expr : raw_tacexpr Pcoq.Entry.t
val tac2expr : raw_tacexpr Pcoq.Entry.t
+ [@@deprecated "Deprecated in 8.13; use 'ltac2_expr' instead"]
val tac2expr_in_env : (Id.t CAst.t list * raw_tacexpr) Pcoq.Entry.t
(** Quoted entries. To be used for complex notations. *)
diff --git a/user-contrib/Ltac2/tac2expr.mli b/user-contrib/Ltac2/tac2expr.mli
index 548655f561..0ae016265a 100644
--- a/user-contrib/Ltac2/tac2expr.mli
+++ b/user-contrib/Ltac2/tac2expr.mli
@@ -105,6 +105,7 @@ type raw_tacexpr_r =
| CTacLet of rec_flag * (raw_patexpr * raw_tacexpr) list * raw_tacexpr
| CTacCnv of raw_tacexpr * raw_typexpr
| CTacSeq of raw_tacexpr * raw_tacexpr
+| CTacIft of raw_tacexpr * raw_tacexpr * raw_tacexpr
| CTacCse of raw_tacexpr * raw_taccase list
| CTacRec of raw_recexpr
| CTacPrj of raw_tacexpr * ltac_projection or_relid
diff --git a/user-contrib/Ltac2/tac2intern.ml b/user-contrib/Ltac2/tac2intern.ml
index 797f72702d..ddf70a5a65 100644
--- a/user-contrib/Ltac2/tac2intern.ml
+++ b/user-contrib/Ltac2/tac2intern.ml
@@ -29,6 +29,7 @@ let t_string = coq_type "string"
let t_constr = coq_type "constr"
let t_ltac1 = ltac1_type "t"
let t_preterm = coq_type "preterm"
+let t_bool = coq_type "bool"
(** Union find *)
@@ -749,6 +750,15 @@ let rec intern_rec env {loc;v=e} = match e with
let (e2, t2) = intern_rec env e2 in
let () = check_elt_unit loc1 env t1 in
(GTacLet (false, [Anonymous, e1], e2), t2)
+| CTacIft (e, e1, e2) ->
+ let loc = e.loc in
+ let loc1 = e1.loc in
+ let (e, t) = intern_rec env e in
+ let (e1, t1) = intern_rec env e1 in
+ let (e2, t2) = intern_rec env e2 in
+ let () = unify ?loc env t (GTypRef (Other t_bool, [])) in
+ let () = unify ?loc:loc1 env t1 t2 in
+ (GTacCse (e, Other t_bool, [|e1; e2|], [||]), t2)
| CTacCse (e, pl) ->
intern_case env loc e pl
| CTacRec fs ->
@@ -1271,6 +1281,11 @@ let rec globalize ids ({loc;v=er} as e) = match er with
let e1 = globalize ids e1 in
let e2 = globalize ids e2 in
CAst.make ?loc @@ CTacSeq (e1, e2)
+| CTacIft (e, e1, e2) ->
+ let e = globalize ids e in
+ let e1 = globalize ids e1 in
+ let e2 = globalize ids e2 in
+ CAst.make ?loc @@ CTacIft (e, e1, e2)
| CTacCse (e, bl) ->
let e = globalize ids e in
let bl = List.map (fun b -> globalize_case ids b) bl in
@@ -1486,6 +1501,11 @@ let rec subst_rawexpr subst ({loc;v=tr} as t) = match tr with
let e1' = subst_rawexpr subst e1 in
let e2' = subst_rawexpr subst e2 in
if e1' == e1 && e2' == e2 then t else CAst.make ?loc @@ CTacSeq (e1', e2')
+| CTacIft (e, e1, e2) ->
+ let e' = subst_rawexpr subst e in
+ let e1' = subst_rawexpr subst e1 in
+ let e2' = subst_rawexpr subst e2 in
+ if e' == e && e1' == e1 && e2' == e2 then t else CAst.make ?loc @@ CTacIft (e', e1', e2')
| CTacCse (e, bl) ->
let map (p, e as x) =
let p' = subst_rawpattern subst p in
diff --git a/user-contrib/Ltac2/tac2quote.ml b/user-contrib/Ltac2/tac2quote.ml
index b346b3ee5c..90f8008dc2 100644
--- a/user-contrib/Ltac2/tac2quote.ml
+++ b/user-contrib/Ltac2/tac2quote.ml
@@ -229,7 +229,7 @@ let check_pattern_id ?loc id =
let pattern_vars pat =
let rec aux () accu pat = match pat.CAst.v with
| Constrexpr.CPatVar id
- | Constrexpr.CEvar (id, []) ->
+ | Constrexpr.CEvar ({CAst.v=id}, []) ->
let loc = pat.CAst.loc in
let () = check_pattern_id ?loc id in
Id.Map.add id loc accu
diff --git a/vernac/attributes.ml b/vernac/attributes.ml
index fb308fd316..efba6d332a 100644
--- a/vernac/attributes.ml
+++ b/vernac/attributes.ml
@@ -224,3 +224,11 @@ let canonical_field =
enable_attribute ~key:"canonical" ~default:(fun () -> true)
let canonical_instance =
enable_attribute ~key:"canonical" ~default:(fun () -> false)
+
+let uses_parser : string key_parser = fun orig args ->
+ assert_once ~name:"using" orig;
+ match args with
+ | VernacFlagLeaf str -> str
+ | _ -> CErrors.user_err (Pp.str "Ill formed \"using\" attribute")
+
+let using = attribute_of_list ["using",uses_parser]
diff --git a/vernac/attributes.mli b/vernac/attributes.mli
index 51bab79938..1969665082 100644
--- a/vernac/attributes.mli
+++ b/vernac/attributes.mli
@@ -51,6 +51,7 @@ val option_locality : Goptions.option_locality attribute
val deprecation : Deprecation.t option attribute
val canonical_field : bool attribute
val canonical_instance : bool attribute
+val using : string option attribute
val program_mode_option_name : string list
(** For internal use when messing with the global option. *)
diff --git a/vernac/auto_ind_decl.ml b/vernac/auto_ind_decl.ml
index 7a7e7d6e35..f715459616 100644
--- a/vernac/auto_ind_decl.ml
+++ b/vernac/auto_ind_decl.ml
@@ -145,7 +145,7 @@ let build_beq_scheme_deps kn =
| Cast (x,_,_) -> aux accu (Term.applist (x,a))
| App _ -> assert false
| Ind ((kn', _), _) ->
- if MutInd.equal kn kn' then accu
+ if Environ.QMutInd.equal env kn kn' then accu
else
let eff = SchemeMutualDep (kn', !beq_scheme_kind_aux ()) in
List.fold_left aux (eff :: accu) a
@@ -253,7 +253,7 @@ let build_beq_scheme mode kn =
| Cast (x,_,_) -> aux (Term.applist (x,a))
| App _ -> assert false
| Ind ((kn',i as ind'),u) (*FIXME: universes *) ->
- if MutInd.equal kn kn' then mkRel(eqA-nlist-i+nb_ind-1)
+ if Environ.QMutInd.equal env kn kn' then mkRel(eqA-nlist-i+nb_ind-1)
else begin
try
let eq = match lookup_scheme (!beq_scheme_kind_aux()) ind' with
@@ -496,7 +496,7 @@ let do_replace_bl bl_scheme_key (ind,u as indu) aavoid narg lft rgt =
let u,v = try destruct_ind env sigma tt1
(* trick so that the good sequence is returned*)
with e when CErrors.noncritical e -> indu,[||]
- in if eq_ind (fst u) ind
+ in if Ind.CanOrd.equal (fst u) ind
then Tacticals.New.tclTHENLIST [Equality.replace t1 t2; Auto.default_auto ; aux q1 q2 ]
else (
find_scheme bl_scheme_key (fst u) (*FIXME*) >>= fun c ->
@@ -539,7 +539,8 @@ let do_replace_bl bl_scheme_key (ind,u as indu) aavoid narg lft rgt =
with DestKO -> Tacticals.New.tclZEROMSG (str "The expected type is an inductive one.")
end
end >>= fun (sp2,i2) ->
- if not (MutInd.equal sp1 sp2) || not (Int.equal i1 i2)
+ Proofview.tclENV >>= fun env ->
+ if not (Environ.QMutInd.equal env sp1 sp2) || not (Int.equal i1 i2)
then Tacticals.New.tclZEROMSG (str "Eq should be on the same type")
else aux (Array.to_list ca1) (Array.to_list ca2)
diff --git a/vernac/classes.ml b/vernac/classes.ml
index a464eab127..a100352145 100644
--- a/vernac/classes.ml
+++ b/vernac/classes.ml
@@ -57,7 +57,7 @@ let is_local_for_hint i =
let add_instance_base inst =
let locality = if is_local_for_hint inst then Goptions.OptLocal else Goptions.OptGlobal in
- add_instance_hint (Hints.IsGlobRef inst.is_impl) [inst.is_impl] ~locality
+ add_instance_hint (Hints.hint_globref inst.is_impl) [inst.is_impl] ~locality
inst.is_info
let mk_instance cl info glob impl =
@@ -152,9 +152,6 @@ let subst_class (subst,cl) =
and do_subst c = Mod_subst.subst_mps subst c
and do_subst_gr gr = fst (subst_global subst gr) in
let do_subst_ctx = List.Smart.map (RelDecl.map_constr do_subst) in
- let do_subst_context (grs,ctx) =
- List.Smart.map (Option.Smart.map do_subst_gr) grs,
- do_subst_ctx ctx in
let do_subst_meth m =
let c = Option.Smart.map do_subst_con m.meth_const in
if c == m.meth_const then m
@@ -168,7 +165,7 @@ let subst_class (subst,cl) =
let do_subst_projs projs = List.Smart.map do_subst_meth projs in
{ cl_univs = cl.cl_univs;
cl_impl = do_subst_gr cl.cl_impl;
- cl_context = do_subst_context cl.cl_context;
+ cl_context = do_subst_ctx cl.cl_context;
cl_props = do_subst_ctx cl.cl_props;
cl_projs = do_subst_projs cl.cl_projs;
cl_strict = cl.cl_strict;
@@ -197,25 +194,16 @@ let discharge_class (_,cl) =
| VarRef _ | ConstructRef _ -> assert false
| ConstRef cst -> Lib.section_segment_of_constant cst
| IndRef (ind,_) -> Lib.section_segment_of_mutual_inductive ind in
- let discharge_context ctx' subst (grs, ctx) =
- let env = Global.env () in
- let sigma = Evd.from_env env in
- let grs' =
- let newgrs = List.map (fun decl ->
- match decl |> RelDecl.get_type |> EConstr.of_constr |> class_of_constr env sigma with
- | None -> None
- | Some (_, ((tc,_), _)) -> Some tc.cl_impl)
- ctx'
- in
- grs @ newgrs
- in grs', discharge_rel_context subst 1 ctx @ ctx' in
+ let discharge_context ctx' subst ctx =
+ discharge_rel_context subst 1 ctx @ ctx'
+ in
try
let info = abs_context cl in
let ctx = info.Section.abstr_ctx in
let ctx, subst = rel_of_variable_context ctx in
let usubst, cl_univs' = Lib.discharge_abstract_universe_context info cl.cl_univs in
let context = discharge_context ctx (subst, usubst) cl.cl_context in
- let props = discharge_rel_context (subst, usubst) (succ (List.length (fst cl.cl_context))) cl.cl_props in
+ let props = discharge_rel_context (subst, usubst) (succ (List.length cl.cl_context)) cl.cl_props in
let discharge_proj x = x in
{ cl_univs = cl_univs';
cl_impl = cl.cl_impl;
@@ -324,7 +312,7 @@ let declare_instance_constant iinfo global impargs ?hook name udecl poly sigma t
let do_declare_instance sigma ~global ~poly k u ctx ctx' pri udecl impargs subst name =
let subst = List.fold_left2
(fun subst' s decl -> if is_local_assum decl then s :: subst' else subst')
- [] subst (snd k.cl_context)
+ [] subst k.cl_context
in
let (_, ty_constr) = instance_constructor (k,u) subst in
let termtype = it_mkProd_or_LetIn ty_constr (ctx' @ ctx) in
@@ -399,7 +387,7 @@ let do_instance_subst_constructor_and_ty subst k u ctx =
let subst =
List.fold_left2 (fun subst' s decl ->
if is_local_assum decl then s :: subst' else subst')
- [] subst (k.cl_props @ snd k.cl_context)
+ [] subst (k.cl_props @ k.cl_context)
in
let (app, ty_constr) = instance_constructor (k,u) subst in
let termtype = it_mkProd_or_LetIn ty_constr ctx in
@@ -530,7 +518,7 @@ let interp_instance_context ~program_mode env ctx ~generalize pl tclass =
let u_s = EInstance.kind sigma u in
let cl = Typeclasses.typeclass_univ_instance (k, u_s) in
let args = List.map of_constr args in
- let cl_context = List.map (Termops.map_rel_decl of_constr) (snd cl.cl_context) in
+ let cl_context = List.map (Termops.map_rel_decl of_constr) cl.cl_context in
let _, args =
List.fold_right (fun decl (args, args') ->
match decl with
diff --git a/vernac/comAssumption.ml b/vernac/comAssumption.ml
index 401ba0fba4..12194ea20c 100644
--- a/vernac/comAssumption.ml
+++ b/vernac/comAssumption.ml
@@ -68,10 +68,12 @@ let declare_axiom is_coe ~poly ~local ~kind typ (univs, pl) imps nl {CAst.v=name
let inst = instance_of_univ_entry univs in
(gr,inst)
-let interp_assumption ~program_mode sigma env impls c =
+let interp_assumption ~program_mode env sigma impl_env bl c =
let flags = { Pretyping.all_no_fail_flags with program_mode } in
- let sigma, (ty, impls) = interp_type_evars_impls ~flags env sigma ~impls c in
- sigma, (ty, impls)
+ let sigma, (impls, ((env_bl, ctx), impls1)) = interp_context_evars ~program_mode ~impl_env env sigma bl in
+ let sigma, (ty, impls2) = interp_type_evars_impls ~flags env_bl sigma ~impls c in
+ let ty = EConstr.it_mkProd_or_LetIn ty ctx in
+ sigma, ty, impls1@impls2
(* When monomorphic the universe constraints and universe names are
declared with the first declaration only. *)
@@ -153,7 +155,7 @@ let do_assumptions ~program_mode ~poly ~scope ~kind nl l =
in
(* We interpret all declarations in the same evar_map, i.e. as a telescope. *)
let (sigma,_,_),l = List.fold_left_map (fun (sigma,env,ienv) (is_coe,(idl,c)) ->
- let sigma,(t,imps) = interp_assumption ~program_mode sigma env ienv c in
+ let sigma,t,imps = interp_assumption ~program_mode env sigma ienv [] c in
let r = Retyping.relevance_of_type env sigma t in
let env =
EConstr.push_named_context (List.map (fun {CAst.v=id} -> LocalAssum (make_annot id r,t)) idl) env in
diff --git a/vernac/comAssumption.mli b/vernac/comAssumption.mli
index 3d425ad768..64b8212b90 100644
--- a/vernac/comAssumption.mli
+++ b/vernac/comAssumption.mli
@@ -14,6 +14,15 @@ open Constrexpr
(** {6 Parameters/Assumptions} *)
+val interp_assumption
+ : program_mode:bool
+ -> Environ.env
+ -> Evd.evar_map
+ -> Constrintern.internalization_env
+ -> Constrexpr.local_binder_expr list
+ -> constr_expr
+ -> Evd.evar_map * EConstr.t * Impargs.manual_implicits
+
val do_assumptions
: program_mode:bool
-> poly:bool
diff --git a/vernac/comDefinition.ml b/vernac/comDefinition.ml
index 37b7106856..3fc74cba5b 100644
--- a/vernac/comDefinition.ml
+++ b/vernac/comDefinition.ml
@@ -81,14 +81,11 @@ let protect_pattern_in_binder bl c ctypopt =
else
(bl, c, ctypopt, fun f env evd c -> f env evd c)
-let interp_definition ~program_mode pl bl ~poly red_option c ctypopt =
+let interp_definition ~program_mode env evd impl_env bl red_option c ctypopt =
let flags = Pretyping.{ all_no_fail_flags with program_mode } in
- let env = Global.env() in
- (* Explicitly bound universes and constraints *)
- let evd, udecl = Constrexpr_ops.interp_univ_decl_opt env pl in
let (bl, c, ctypopt, apply_under_binders) = protect_pattern_in_binder bl c ctypopt in
(* Build the parameters *)
- let evd, (impls, ((env_bl, ctx), imps1)) = interp_context_evars ~program_mode env evd bl in
+ let evd, (impls, ((env_bl, ctx), imps1)) = interp_context_evars ~program_mode ~impl_env env evd bl in
(* Build the type *)
let evd, tyopt = Option.fold_left_map
(interp_type_evars_impls ~flags ~impls env_bl)
@@ -111,28 +108,44 @@ let interp_definition ~program_mode pl bl ~poly red_option c ctypopt =
(* Declare the definition *)
let c = EConstr.it_mkLambda_or_LetIn c ctx in
let tyopt = Option.map (fun ty -> EConstr.it_mkProd_or_LetIn ty ctx) tyopt in
- (c, tyopt), evd, udecl, imps
+ evd, (c, tyopt), imps
-let do_definition ?hook ~name ~scope ~poly ~kind udecl bl red_option c ctypopt =
+let do_definition ?hook ~name ~scope ~poly ~kind ?using udecl bl red_option c ctypopt =
let program_mode = false in
- let (body, types), evd, udecl, impargs =
- interp_definition ~program_mode udecl bl ~poly red_option c ctypopt
+ let env = Global.env() in
+ (* Explicitly bound universes and constraints *)
+ let evd, udecl = Constrexpr_ops.interp_univ_decl_opt env udecl in
+ let evd, (body, types), impargs =
+ interp_definition ~program_mode env evd empty_internalization_env bl red_option c ctypopt
+ in
+ let using = using |> Option.map (fun expr ->
+ let terms = body :: match types with Some x -> [x] | None -> [] in
+ let l = Proof_using.process_expr (Global.env()) evd expr terms in
+ Names.Id.Set.(List.fold_right add l empty))
in
let kind = Decls.IsDefinition kind in
- let cinfo = Declare.CInfo.make ~name ~impargs ~typ:types () in
+ let cinfo = Declare.CInfo.make ~name ~impargs ~typ:types ?using () in
let info = Declare.Info.make ~scope ~kind ?hook ~udecl ~poly () in
let _ : Names.GlobRef.t =
Declare.declare_definition ~info ~cinfo ~opaque:false ~body evd
in ()
-let do_definition_program ?hook ~pm ~name ~scope ~poly ~kind udecl bl red_option c ctypopt =
+let do_definition_program ?hook ~pm ~name ~scope ~poly ~kind ?using udecl bl red_option c ctypopt =
let program_mode = true in
- let (body, types), evd, udecl, impargs =
- interp_definition ~program_mode udecl bl ~poly red_option c ctypopt
+ let env = Global.env() in
+ (* Explicitly bound universes and constraints *)
+ let evd, udecl = Constrexpr_ops.interp_univ_decl_opt env udecl in
+ let evd, (body, types), impargs =
+ interp_definition ~program_mode env evd empty_internalization_env bl red_option c ctypopt
+ in
+ let using = using |> Option.map (fun expr ->
+ let terms = body :: match types with Some x -> [x] | None -> [] in
+ let l = Proof_using.process_expr (Global.env()) evd expr terms in
+ Names.Id.Set.(List.fold_right add l empty))
in
let term, typ, uctx, obls = Declare.Obls.prepare_obligation ~name ~body ~types evd in
let pm, _ =
- let cinfo = Declare.CInfo.make ~name ~typ ~impargs () in
+ let cinfo = Declare.CInfo.make ~name ~typ ~impargs ?using () in
let info = Declare.Info.make ~udecl ~scope ~poly ~kind ?hook () in
Declare.Obls.add_definition ~pm ~cinfo ~info ~term ~uctx obls
in pm
diff --git a/vernac/comDefinition.mli b/vernac/comDefinition.mli
index d95e64a85f..5e1b705ae4 100644
--- a/vernac/comDefinition.mli
+++ b/vernac/comDefinition.mli
@@ -14,12 +14,24 @@ open Constrexpr
(** {6 Definitions/Let} *)
+val interp_definition
+ : program_mode:bool
+ -> Environ.env
+ -> Evd.evar_map
+ -> Constrintern.internalization_env
+ -> Constrexpr.local_binder_expr list
+ -> red_expr option
+ -> constr_expr
+ -> constr_expr option
+ -> Evd.evar_map * (EConstr.t * EConstr.t option) * Impargs.manual_implicits
+
val do_definition
: ?hook:Declare.Hook.t
-> name:Id.t
-> scope:Locality.locality
-> poly:bool
-> kind:Decls.definition_object_kind
+ -> ?using:Vernacexpr.section_subset_expr
-> universe_decl_expr option
-> local_binder_expr list
-> red_expr option
@@ -34,6 +46,7 @@ val do_definition_program
-> scope:Locality.locality
-> poly:bool
-> kind:Decls.logical_kind
+ -> ?using:Vernacexpr.section_subset_expr
-> universe_decl_expr option
-> local_binder_expr list
-> red_expr option
diff --git a/vernac/comFixpoint.ml b/vernac/comFixpoint.ml
index 78572c6aa6..29bf5fbcc2 100644
--- a/vernac/comFixpoint.ml
+++ b/vernac/comFixpoint.ml
@@ -251,15 +251,22 @@ let interp_fixpoint ?(check_recursivity=true) ~cofix l :
let uctx,fix = ground_fixpoint env evd fix in
(fix,pl,uctx,info)
-let build_recthms ~indexes fixnames fixtypes fiximps =
+let build_recthms ~indexes ?using fixnames fixtypes fiximps =
let fix_kind, cofix = match indexes with
| Some indexes -> Decls.Fixpoint, false
| None -> Decls.CoFixpoint, true
in
let thms =
List.map3 (fun name typ (ctx,impargs,_) ->
+ let using = using |> Option.map (fun expr ->
+ let terms = [EConstr.of_constr typ] in
+ let env = Global.env() in
+ let sigma = Evd.from_env env in
+ let l = Proof_using.process_expr env sigma expr terms in
+ Names.Id.Set.(List.fold_right add l empty))
+ in
let args = List.map Context.Rel.Declaration.get_name ctx in
- Declare.CInfo.make ~name ~typ ~args ~impargs ()
+ Declare.CInfo.make ~name ~typ ~args ~impargs ?using ()
) fixnames fixtypes fiximps
in
fix_kind, cofix, thms
@@ -277,9 +284,9 @@ let declare_fixpoint_interactive_generic ?indexes ~scope ~poly ((fixnames,_fixrs
List.iter (Metasyntax.add_notation_interpretation (Global.env())) ntns;
lemma
-let declare_fixpoint_generic ?indexes ~scope ~poly ((fixnames,fixrs,fixdefs,fixtypes),udecl,uctx,fiximps) ntns =
+let declare_fixpoint_generic ?indexes ~scope ~poly ?using ((fixnames,fixrs,fixdefs,fixtypes),udecl,uctx,fiximps) ntns =
(* We shortcut the proof process *)
- let fix_kind, cofix, fixitems = build_recthms ~indexes fixnames fixtypes fiximps in
+ let fix_kind, cofix, fixitems = build_recthms ~indexes ?using fixnames fixtypes fiximps in
let fixdefs = List.map Option.get fixdefs in
let rec_declaration = prepare_recursive_declaration fixnames fixrs fixtypes fixdefs in
let fix_kind = Decls.IsDefinition fix_kind in
@@ -328,9 +335,9 @@ let do_fixpoint_interactive ~scope ~poly l : Declare.Proof.t =
let lemma = declare_fixpoint_interactive_generic ~indexes:possible_indexes ~scope ~poly fix ntns in
lemma
-let do_fixpoint ~scope ~poly l =
+let do_fixpoint ~scope ~poly ?using l =
let fixl, ntns, fix, possible_indexes = do_fixpoint_common l in
- declare_fixpoint_generic ~indexes:possible_indexes ~scope ~poly fix ntns
+ declare_fixpoint_generic ~indexes:possible_indexes ~scope ~poly ?using fix ntns
let do_cofixpoint_common (fixl : Vernacexpr.cofixpoint_expr list) =
let fixl = List.map (fun fix -> {fix with Vernacexpr.rec_order = None}) fixl in
@@ -342,6 +349,6 @@ let do_cofixpoint_interactive ~scope ~poly l =
let lemma = declare_fixpoint_interactive_generic ~scope ~poly cofix ntns in
lemma
-let do_cofixpoint ~scope ~poly l =
+let do_cofixpoint ~scope ~poly ?using l =
let cofix, ntns = do_cofixpoint_common l in
- declare_fixpoint_generic ~scope ~poly cofix ntns
+ declare_fixpoint_generic ~scope ~poly ?using cofix ntns
diff --git a/vernac/comFixpoint.mli b/vernac/comFixpoint.mli
index aa5446205c..a36aba7672 100644
--- a/vernac/comFixpoint.mli
+++ b/vernac/comFixpoint.mli
@@ -19,13 +19,13 @@ val do_fixpoint_interactive :
scope:Locality.locality -> poly:bool -> fixpoint_expr list -> Declare.Proof.t
val do_fixpoint :
- scope:Locality.locality -> poly:bool -> fixpoint_expr list -> unit
+ scope:Locality.locality -> poly:bool -> ?using:Vernacexpr.section_subset_expr -> fixpoint_expr list -> unit
val do_cofixpoint_interactive :
scope:Locality.locality -> poly:bool -> cofixpoint_expr list -> Declare.Proof.t
val do_cofixpoint :
- scope:Locality.locality -> poly:bool -> cofixpoint_expr list -> unit
+ scope:Locality.locality -> poly:bool -> ?using:Vernacexpr.section_subset_expr -> cofixpoint_expr list -> unit
(************************************************************************)
(** Internal API *)
diff --git a/vernac/comHints.ml b/vernac/comHints.ml
index 9eac558908..f642411fa4 100644
--- a/vernac/comHints.ml
+++ b/vernac/comHints.ml
@@ -62,7 +62,7 @@ let project_hint ~poly pri l2r r =
cb
in
let info = {Typeclasses.hint_priority = pri; hint_pattern = None} in
- (info, true, Hints.PathAny, Hints.IsGlobRef (GlobRef.ConstRef c))
+ (info, true, Hints.PathAny, Hints.hint_globref (GlobRef.ConstRef c))
let warn_deprecated_hint_constr =
CWarnings.create ~name:"fragile-hint-constr" ~category:"automation"
@@ -84,16 +84,6 @@ let soft_evaluable =
let interp_hints ~poly h =
let env = Global.env () in
let sigma = Evd.from_env env in
- let f poly c =
- let evd, c = Constrintern.interp_open_constr env sigma c in
- let env = Global.env () in
- let sigma = Evd.from_env env in
- let c, diff = Hints.prepare_hint true env sigma (evd, c) in
- if poly then (Hints.IsConstr (c, Some diff) [@ocaml.warning "-3"])
- else
- let () = DeclareUctx.declare_universe_context ~poly:false diff in
- (Hints.IsConstr (c, None) [@ocaml.warning "-3"])
- in
let fref r =
let gr = Smartlocate.global_with_alias r in
Dumpglob.add_glob ?loc:r.CAst.loc gr;
@@ -106,10 +96,22 @@ let interp_hints ~poly h =
match c with
| HintsReference c ->
let gr = Smartlocate.global_with_alias c in
- (PathHints [gr], IsGlobRef gr)
+ (PathHints [gr], hint_globref gr)
| HintsConstr c ->
let () = warn_deprecated_hint_constr () in
- (PathAny, f poly c)
+ let env = Global.env () in
+ let sigma = Evd.from_env env in
+ let c, uctx = Constrintern.interp_constr env sigma c in
+ let subst, uctx = UState.normalize_variables uctx in
+ let c = EConstr.Vars.subst_univs_constr subst c in
+ let diff = UState.context_set uctx in
+ let c =
+ if poly then (c, Some diff)
+ else
+ let () = DeclareUctx.declare_universe_context ~poly:false diff in
+ (c, None)
+ in
+ (PathAny, Hints.hint_constr c) [@ocaml.warning "-3"]
in
let fp = Constrintern.intern_constr_pattern env sigma in
let fres (info, b, r) =
@@ -149,7 +151,7 @@ let interp_hints ~poly h =
( empty_hint_info
, true
, PathHints [gr]
- , IsGlobRef gr ))
+ , hint_globref gr ))
in
HintsResolveEntry (List.flatten (List.map constr_hints_of_ind lqid))
| HintsExtern (pri, patcom, tacexp) ->
diff --git a/vernac/comProgramFixpoint.ml b/vernac/comProgramFixpoint.ml
index 55901fd604..9623317ddf 100644
--- a/vernac/comProgramFixpoint.ml
+++ b/vernac/comProgramFixpoint.ml
@@ -109,7 +109,7 @@ let telescope env sigma l =
let nf_evar_context sigma ctx =
List.map (map_constr (fun c -> Evarutil.nf_evar sigma c)) ctx
-let build_wellfounded pm (recname,pl,bl,arityc,body) poly r measure notation =
+let build_wellfounded pm (recname,pl,bl,arityc,body) poly ?using r measure notation =
let open EConstr in
let open Vars in
let lift_rel_context n l = Termops.map_rel_context_with_binders (liftn n) l in
@@ -259,8 +259,13 @@ let build_wellfounded pm (recname,pl,bl,arityc,body) poly r measure notation =
let evars, _, evars_def, evars_typ =
RetrieveObl.retrieve_obligations env recname sigma 0 def typ
in
+ let using = using |> Option.map (fun expr ->
+ let terms = List.map EConstr.of_constr [evars_def; evars_typ] in
+ let l = Proof_using.process_expr env sigma expr terms in
+ Names.Id.Set.(List.fold_right add l empty))
+ in
let uctx = Evd.evar_universe_context sigma in
- let cinfo = Declare.CInfo.make ~name:recname ~typ:evars_typ () in
+ let cinfo = Declare.CInfo.make ~name:recname ~typ:evars_typ ?using () in
let info = Declare.Info.make ~udecl ~poly ~hook () in
let pm, _ =
Declare.Obls.add_definition ~pm ~cinfo ~info ~term:evars_def ~uctx evars in
@@ -275,7 +280,7 @@ let collect_evars_of_term evd c ty =
Evar.Set.fold (fun ev acc -> Evd.add acc ev (Evd.find_undefined evd ev))
evars (Evd.from_ctx (Evd.evar_universe_context evd))
-let do_program_recursive ~pm ~scope ~poly fixkind fixl =
+let do_program_recursive ~pm ~scope ~poly ?using fixkind fixl =
let cofix = fixkind = Declare.Obls.IsCoFixpoint in
let (env, rec_sign, udecl, evd), fix, info =
interp_recursive ~cofix ~program_mode:true fixl
@@ -287,13 +292,18 @@ let do_program_recursive ~pm ~scope ~poly fixkind fixl =
let evd = nf_evar_map_undefined evd in
let collect_evars name def typ impargs =
(* Generalize by the recursive prototypes *)
+ let using = using |> Option.map (fun expr ->
+ let terms = [def; typ] in
+ let l = Proof_using.process_expr env evd expr terms in
+ Names.Id.Set.(List.fold_right add l empty))
+ in
let def = nf_evar evd (Termops.it_mkNamedLambda_or_LetIn def rec_sign) in
let typ = nf_evar evd (Termops.it_mkNamedProd_or_LetIn typ rec_sign) in
let evm = collect_evars_of_term evd def typ in
let evars, _, def, typ =
RetrieveObl.retrieve_obligations env name evm
(List.length rec_sign) def typ in
- let cinfo = Declare.CInfo.make ~name ~typ ~impargs () in
+ let cinfo = Declare.CInfo.make ~name ~typ ~impargs ?using () in
(cinfo, def, evars)
in
let (fixnames,fixrs,fixdefs,fixtypes) = fix in
@@ -325,13 +335,13 @@ let do_program_recursive ~pm ~scope ~poly fixkind fixl =
let info = Declare.Info.make ~poly ~scope ~kind ~udecl () in
Declare.Obls.add_mutual_definitions ~pm defs ~info ~uctx ~ntns fixkind
-let do_fixpoint ~pm ~scope ~poly l =
+let do_fixpoint ~pm ~scope ~poly ?using l =
let g = List.map (fun { Vernacexpr.rec_order } -> rec_order) l in
match g, l with
| [Some { CAst.v = CWfRec (n,r) }],
[ Vernacexpr.{fname={CAst.v=id}; univs; binders; rtype; body_def; notations} ] ->
let recarg = mkIdentC n.CAst.v in
- build_wellfounded pm (id, univs, binders, rtype, out_def body_def) poly r recarg notations
+ build_wellfounded pm (id, univs, binders, rtype, out_def body_def) poly ?using r recarg notations
| [Some { CAst.v = CMeasureRec (n, m, r) }],
[Vernacexpr.{fname={CAst.v=id}; univs; binders; rtype; body_def; notations }] ->
@@ -344,7 +354,7 @@ let do_fixpoint ~pm ~scope ~poly l =
user_err Pp.(str"Measure takes only two arguments in Program Fixpoint.")
| _, _ -> r
in
- build_wellfounded pm (id, univs, binders, rtype, out_def body_def) poly
+ build_wellfounded pm (id, univs, binders, rtype, out_def body_def) poly ?using
(Option.default (CAst.make @@ CRef (lt_ref,None)) r) m notations
| _, _ when List.for_all (fun ro -> match ro with None | Some { CAst.v = CStructRec _} -> true | _ -> false) g ->
@@ -352,11 +362,11 @@ let do_fixpoint ~pm ~scope ~poly l =
Vernacexpr.(ComFixpoint.adjust_rec_order ~structonly:true fix.binders fix.rec_order)) l in
let fixkind = Declare.Obls.IsFixpoint annots in
let l = List.map2 (fun fix rec_order -> { fix with Vernacexpr.rec_order }) l annots in
- do_program_recursive ~pm ~scope ~poly fixkind l
+ do_program_recursive ~pm ~scope ~poly ?using fixkind l
| _, _ ->
CErrors.user_err ~hdr:"do_fixpoint"
(str "Well-founded fixpoints not allowed in mutually recursive blocks")
-let do_cofixpoint ~pm ~scope ~poly fixl =
+let do_cofixpoint ~pm ~scope ~poly ?using fixl =
let fixl = List.map (fun fix -> { fix with Vernacexpr.rec_order = None }) fixl in
- do_program_recursive ~pm ~scope ~poly Declare.Obls.IsCoFixpoint fixl
+ do_program_recursive ~pm ~scope ~poly ?using Declare.Obls.IsCoFixpoint fixl
diff --git a/vernac/comProgramFixpoint.mli b/vernac/comProgramFixpoint.mli
index 7935cf27fb..30bf3ae8f8 100644
--- a/vernac/comProgramFixpoint.mli
+++ b/vernac/comProgramFixpoint.mli
@@ -15,6 +15,7 @@ val do_fixpoint :
pm:Declare.OblState.t
-> scope:Locality.locality
-> poly:bool
+ -> ?using:Vernacexpr.section_subset_expr
-> fixpoint_expr list
-> Declare.OblState.t
@@ -22,5 +23,6 @@ val do_cofixpoint :
pm:Declare.OblState.t
-> scope:Locality.locality
-> poly:bool
+ -> ?using:Vernacexpr.section_subset_expr
-> cofixpoint_expr list
-> Declare.OblState.t
diff --git a/vernac/comSearch.ml b/vernac/comSearch.ml
index 9de8d6fbc3..f3b21eb813 100644
--- a/vernac/comSearch.ml
+++ b/vernac/comSearch.ml
@@ -53,7 +53,16 @@ let kind_searcher = Decls.(function
let interp_search_item env sigma =
function
| SearchSubPattern ((where,head),pat) ->
- let _,pat = Constrintern.intern_constr_pattern env sigma pat in
+ let expected_type = Pretyping.(if head then IsType else WithoutTypeConstraint) in
+ let pat =
+ try Constrintern.interp_constr_pattern env sigma ~expected_type pat
+ with e when CErrors.noncritical e ->
+ (* We cannot ensure (yet?) that a typable pattern will
+ actually be typed, consider e.g. (forall A, A -> A /\ A)
+ which fails, not seeing that A can be Prop; so we use an
+ untyped pattern as a fallback (i.e w/o no insertion of
+ coercions, no compilation of pattern-matching) *)
+ snd (Constrintern.intern_constr_pattern env sigma ~as_type:head pat) in
GlobSearchSubPattern (where,head,pat)
| SearchString ((Anywhere,false),s,None) when Id.is_valid s ->
GlobSearchString s
diff --git a/vernac/comTactic.ml b/vernac/comTactic.ml
new file mode 100644
index 0000000000..2252d46e58
--- /dev/null
+++ b/vernac/comTactic.ml
@@ -0,0 +1,82 @@
+(************************************************************************)
+(* * The Coq Proof Assistant / The Coq Development Team *)
+(* v * Copyright INRIA, CNRS and contributors *)
+(* <O___,, * (see version control and CREDITS file for authors & dates) *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(* * (see LICENSE file for the text of the license) *)
+(************************************************************************)
+
+open Goptions
+
+module Dyn = Dyn.Make()
+
+module DMap = Dyn.Map(struct type 'a t = 'a -> unit Proofview.tactic end)
+
+let interp_map = ref DMap.empty
+
+type interpretable = I : 'a Dyn.tag * 'a -> interpretable
+type 'a tactic_interpreter = Interpreter of ('a -> interpretable)
+
+let register_tactic_interpreter na f =
+ let t = Dyn.create na in
+ interp_map := DMap.add t f !interp_map;
+ Interpreter (fun x -> I (t,x))
+
+let interp_tac (I (tag,t)) =
+ let f = DMap.find tag !interp_map in
+ f t
+
+type parallel_solver =
+ pstate:Declare.Proof.t ->
+ info:int option ->
+ interpretable ->
+ abstract:bool ->
+ with_end_tac:bool ->
+ Declare.Proof.t
+
+let print_info_trace =
+ declare_intopt_option_and_ref ~depr:false ~key:["Info" ; "Level"]
+
+let solve_core ~pstate n ~info t ~with_end_tac:b =
+ let pstate, status = Declare.Proof.map_fold_endline ~f:(fun etac p ->
+ let with_end_tac = if b then Some etac else None in
+ let info = Option.append info (print_info_trace ()) in
+ let (p,status) = Proof.solve n info t ?with_end_tac p in
+ (* in case a strict subtree was completed,
+ go back to the top of the prooftree *)
+ let p = Proof.maximal_unfocus Vernacentries.command_focus p in
+ p,status) pstate in
+ if not status then Feedback.feedback Feedback.AddedAxiom;
+ pstate
+
+let solve ~pstate n ~info t ~with_end_tac =
+ let t = interp_tac t in
+ solve_core ~pstate n ~info t ~with_end_tac
+
+let check_par_applicable pstate =
+ Declare.Proof.fold pstate ~f:(fun p ->
+ (Proof.data p).Proof.goals |> List.iter (fun goal ->
+ let is_ground =
+ let { Proof.sigma = sigma0 } = Declare.Proof.fold pstate ~f:Proof.data in
+ let g = Evd.find sigma0 goal in
+ let concl, hyps = Evd.evar_concl g, Evd.evar_context g in
+ Evarutil.is_ground_term sigma0 concl &&
+ List.for_all (Context.Named.Declaration.for_all (Evarutil.is_ground_term sigma0)) hyps in
+ if not is_ground then
+ CErrors.user_err
+ Pp.(strbrk("The par: goal selector does not support goals with existential variables"))))
+
+let par_implementation = ref (fun ~pstate ~info t ~abstract ~with_end_tac ->
+ let t = interp_tac t in
+ let t = Proofview.Goal.enter (fun _ ->
+ if abstract then Abstract.tclABSTRACT None ~opaque:true t else t)
+ in
+ solve_core ~pstate Goal_select.SelectAll ~info t ~with_end_tac)
+
+let set_par_implementation f = par_implementation := f
+
+let solve_parallel ~pstate ~info t ~abstract ~with_end_tac =
+ check_par_applicable pstate;
+ !par_implementation ~pstate ~info t ~abstract ~with_end_tac
diff --git a/vernac/comTactic.mli b/vernac/comTactic.mli
new file mode 100644
index 0000000000..72e71d013a
--- /dev/null
+++ b/vernac/comTactic.mli
@@ -0,0 +1,50 @@
+(************************************************************************)
+(* * The Coq Proof Assistant / The Coq Development Team *)
+(* v * Copyright INRIA, CNRS and contributors *)
+(* <O___,, * (see version control and CREDITS file for authors & dates) *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(* * (see LICENSE file for the text of the license) *)
+(************************************************************************)
+
+(** Tactic interpreters have to register their interpretation function *)
+type interpretable
+
+type 'a tactic_interpreter = private Interpreter of ('a -> interpretable)
+
+(** ['a] should be marshallable if ever used with [par:]. Must be
+ called no more than once per process with a particular string: make
+ sure to use partial application. *)
+val register_tactic_interpreter :
+ string -> ('a -> unit Proofview.tactic) -> 'a tactic_interpreter
+
+(** Entry point for toplevel tactic expression execution. It calls Proof.solve
+ after having interpreted the tactic, and after the tactic runs it
+ unfocus as much as needed to put a goal under focus. *)
+val solve :
+ pstate:Declare.Proof.t ->
+ Goal_select.t ->
+ info:int option ->
+ interpretable ->
+ with_end_tac:bool ->
+ Declare.Proof.t
+
+(** [par: tac] runs tac on all goals, possibly in parallel using a worker pool.
+ If tac is [abstract tac1], then [abstract] is passed
+ explicitly to the solver and [tac1] passed to worker since it is up to
+ master to opacify the sub proofs produced by the workers. *)
+type parallel_solver =
+ pstate:Declare.Proof.t ->
+ info:int option ->
+ interpretable ->
+ abstract:bool -> (* the tactic result has to be opacified as per abstract *)
+ with_end_tac:bool ->
+ Declare.Proof.t
+
+(** Entry point when the goal selector is par: *)
+val solve_parallel : parallel_solver
+
+(** By default par: is implemented with all: (sequential).
+ The STM and LSP document manager provide "more parallel" implementations *)
+val set_par_implementation : parallel_solver -> unit
diff --git a/vernac/declare.ml b/vernac/declare.ml
index ae7878b615..0baae6eca5 100644
--- a/vernac/declare.ml
+++ b/vernac/declare.ml
@@ -55,11 +55,13 @@ module CInfo = struct
(** Names to pre-introduce *)
; impargs : Impargs.manual_implicits
(** Explicitily declared implicit arguments *)
+ ; using : Names.Id.Set.t option
+ (** Explicit declaration of section variables used by the constant *)
}
- let make ~name ~typ ?(args=[]) ?(impargs=[]) () =
- { name; typ; args; impargs }
+ let make ~name ~typ ?(args=[]) ?(impargs=[]) ?using () =
+ { name; typ; args; impargs; using }
let to_constr sigma thm = { thm with typ = EConstr.to_constr sigma thm.typ }
@@ -108,10 +110,10 @@ let default_univ_entry = Entries.Monomorphic_entry Univ.ContextSet.empty
(** [univsbody] are universe-constraints attached to the body-only,
used in vio-delayed opaque constants and private poly universes *)
-let definition_entry_core ?(opaque=false) ?(inline=false) ?feedback_id ?section_vars ?types
+let definition_entry_core ?(opaque=false) ?using ?(inline=false) ?feedback_id ?types
?(univs=default_univ_entry) ?(eff=Evd.empty_side_effects) ?(univsbody=Univ.ContextSet.empty) body =
{ proof_entry_body = Future.from_val ((body,univsbody), eff);
- proof_entry_secctx = section_vars;
+ proof_entry_secctx = using;
proof_entry_type = types;
proof_entry_universes = univs;
proof_entry_opaque = opaque;
@@ -119,7 +121,7 @@ let definition_entry_core ?(opaque=false) ?(inline=false) ?feedback_id ?section_
proof_entry_inline_code = inline}
let definition_entry =
- definition_entry_core ?eff:None ?univsbody:None ?feedback_id:None ?section_vars:None
+ definition_entry_core ?eff:None ?univsbody:None ?feedback_id:None
type 'a constant_entry =
| DefinitionEntry of 'a proof_entry
@@ -162,7 +164,7 @@ let cache_constant ((sp,kn), obj) =
then Constant.make1 kn
else CErrors.anomaly Pp.(str"Missing constant " ++ Id.print(Libnames.basename sp) ++ str".")
in
- assert (Constant.equal kn' (Constant.make1 kn));
+ assert (Environ.QConstant.equal (Global.env ()) kn' (Constant.make1 kn));
Nametab.push (Nametab.Until 1) sp (GlobRef.ConstRef (Constant.make1 kn));
Dumpglob.add_constant_kind (Constant.make1 kn) obj.cst_kind
@@ -236,9 +238,9 @@ let pure_definition_entry ?(opaque=false) ?(inline=false) ?types
proof_entry_feedback = None;
proof_entry_inline_code = inline}
-let delayed_definition_entry ~opaque ?feedback_id ~section_vars ~univs ?types body =
+let delayed_definition_entry ~opaque ?feedback_id ~using ~univs ?types body =
{ proof_entry_body = body
- ; proof_entry_secctx = section_vars
+ ; proof_entry_secctx = using
; proof_entry_type = types
; proof_entry_universes = univs
; proof_entry_opaque = opaque
@@ -608,8 +610,8 @@ let declare_mutually_recursive_core ~info ~cinfo ~opaque ~ntns ~uctx ~rec_declar
uctx, univs
in
let csts = CList.map2
- (fun CInfo.{ name; typ; impargs } body ->
- let entry = definition_entry ~opaque ~types:typ ~univs body in
+ (fun CInfo.{ name; typ; impargs; using } body ->
+ let entry = definition_entry ~opaque ~types:typ ~univs ?using body in
declare_entry ~name ~scope ~kind ~impargs ~uctx entry)
cinfo fixdecls
in
@@ -660,7 +662,7 @@ let check_evars_are_solved env sigma t =
let evars = Evarutil.undefined_evars_of_term sigma t in
if not (Evar.Set.is_empty evars) then error_unresolved_evars env sigma t evars
-let prepare_definition ~info ~opaque ~body ~typ sigma =
+let prepare_definition ~info ~opaque ?using ~body ~typ sigma =
let { Info.poly; udecl; inline; _ } = info in
let env = Global.env () in
let sigma, (body, types) = Evarutil.finalize ~abort_on_undefined_evars:false
@@ -669,13 +671,13 @@ let prepare_definition ~info ~opaque ~body ~typ sigma =
Option.iter (check_evars_are_solved env sigma) types;
check_evars_are_solved env sigma body;
let univs = Evd.check_univ_decl ~poly sigma udecl in
- let entry = definition_entry ~opaque ~inline ?types ~univs body in
+ let entry = definition_entry ~opaque ?using ~inline ?types ~univs body in
let uctx = Evd.evar_universe_context sigma in
entry, uctx
let declare_definition_core ~info ~cinfo ~opaque ~obls ~body sigma =
- let { CInfo.name; impargs; typ; _ } = cinfo in
- let entry, uctx = prepare_definition ~info ~opaque ~body ~typ sigma in
+ let { CInfo.name; impargs; typ; using; _ } = cinfo in
+ let entry, uctx = prepare_definition ~info ~opaque ?using ~body ~typ sigma in
let { Info.scope; kind; hook; _ } = info in
declare_entry_core ~name ~scope ~kind ~impargs ~obls ?hook ~uctx entry, uctx
@@ -803,6 +805,7 @@ module ProgramDecl = struct
let set_uctx ~uctx prg = {prg with prg_uctx = uctx}
let get_poly prg = prg.prg_info.Info.poly
let get_obligations prg = prg.prg_obligations
+ let get_using prg = prg.prg_cinfo.CInfo.using
end
end
@@ -1137,7 +1140,7 @@ let declare_mutual_definition ~pm l =
in
let term = EConstr.to_constr sigma term in
let typ = EConstr.to_constr sigma typ in
- let def = (x.prg_reduce term, r, x.prg_reduce typ, x.prg_cinfo.CInfo.impargs) in
+ let def = (x.prg_reduce term, r, x.prg_reduce typ, x.prg_cinfo.CInfo.impargs, x.prg_cinfo.CInfo.using) in
let oblsubst = List.map (fun (id, (_, c)) -> (id, c)) oblsubst in
(def, oblsubst)
in
@@ -1151,11 +1154,11 @@ let declare_mutual_definition ~pm l =
(* let fixdefs = List.map reduce_fix fixdefs in *)
let fixdefs, fixrs, fixtypes, fixitems =
List.fold_right2
- (fun (d, r, typ, impargs) name (a1, a2, a3, a4) ->
+ (fun (d, r, typ, impargs, using) name (a1, a2, a3, a4) ->
( d :: a1
, r :: a2
, typ :: a3
- , CInfo.{name; typ; impargs; args = []} :: a4 ))
+ , CInfo.{name; typ; impargs; args = []; using } :: a4 ))
defs first.prg_deps ([], [], [], [])
in
let fixkind = Option.get first.prg_fixkind in
@@ -1376,7 +1379,7 @@ end
type t =
{ endline_tactic : Genarg.glob_generic_argument option
- ; section_vars : Id.Set.t option
+ ; using : Id.Set.t option
; proof : Proof.t
; initial_euctx : UState.t
(** The initial universe context (for the statement) *)
@@ -1435,7 +1438,7 @@ let start_proof_core ~name ~typ ~pinfo ?(sign=initialize_named_context_for_proof
let initial_euctx = Evd.evar_universe_context Proof.((data proof).sigma) in
{ proof
; endline_tactic = None
- ; section_vars = None
+ ; using = None
; initial_euctx
; pinfo
}
@@ -1458,7 +1461,7 @@ let start_dependent ~info ~name ~proof_ending goals =
let pinfo = Proof_info.make ~info ~cinfo ~proof_ending () in
{ proof
; endline_tactic = None
- ; section_vars = None
+ ; using = None
; initial_euctx
; pinfo
}
@@ -1523,7 +1526,7 @@ let start_mutual_with_initialization ~info ~cinfo ~mutual_info sigma snl =
map lemma ~f:(fun p ->
pi1 @@ Proof.run_tactic Global.(env ()) init_tac p)
-let get_used_variables pf = pf.section_vars
+let get_used_variables pf = pf.using
let get_universe_decl pf = pf.pinfo.Proof_info.info.Info.udecl
let set_used_variables ps l =
@@ -1547,9 +1550,9 @@ let set_used_variables ps l =
else (ctx, all_safe) in
let ctx, _ =
Environ.fold_named_context aux env ~init:(ctx,ctx_set) in
- if not (Option.is_empty ps.section_vars) then
+ if not (Option.is_empty ps.using) then
CErrors.user_err Pp.(str "Used section variables can be declared only once");
- ctx, { ps with section_vars = Some (Context.Named.to_vars ctx) }
+ ctx, { ps with using = Some (Context.Named.to_vars ctx) }
let get_open_goals ps =
let Proof.{ goals; stack; sigma } = Proof.data ps.proof in
@@ -1646,7 +1649,7 @@ let make_univs ~poly ~uctx ~udecl (used_univs_typ, typ) (used_univs_body, body)
let close_proof ~opaque ~keep_body_ucst_separate ps =
- let { section_vars; proof; initial_euctx; pinfo } = ps in
+ let { using; proof; initial_euctx; pinfo } = ps in
let { Proof_info.info = { Info.udecl } } = pinfo in
let { Proof.name; poly } = Proof.data proof in
let unsafe_typ = keep_body_ucst_separate && not poly in
@@ -1667,7 +1670,7 @@ let close_proof ~opaque ~keep_body_ucst_separate ps =
then make_univs_private_poly ~poly ~uctx ~udecl t b
else make_univs ~poly ~uctx ~udecl t b
in
- definition_entry_core ~opaque ?section_vars ~univs:utyp ~univsbody:ubody ~types:typ ~eff body
+ definition_entry_core ~opaque ?using ~univs:utyp ~univsbody:ubody ~types:typ ~eff body
in
let entries = CList.map make_entry elist in
{ name; entries; uctx }
@@ -1675,7 +1678,7 @@ let close_proof ~opaque ~keep_body_ucst_separate ps =
type closed_proof_output = (Constr.t * Evd.side_effects) list * UState.t
let close_proof_delayed ~feedback_id ps (fpl : closed_proof_output Future.computation) =
- let { section_vars; proof; initial_euctx; pinfo } = ps in
+ let { using; proof; initial_euctx; pinfo } = ps in
let { Proof_info.info = { Info.udecl } } = pinfo in
let { Proof.name; poly; entry; sigma } = Proof.data proof in
@@ -1712,7 +1715,7 @@ let close_proof_delayed ~feedback_id ps (fpl : closed_proof_output Future.comput
let univs = UState.restrict uctx used_univs in
let univs = UState.check_mono_univ_decl univs udecl in
(pt,univs),eff)
- |> delayed_definition_entry ~opaque ~feedback_id ~section_vars ~univs ~types
+ |> delayed_definition_entry ~opaque ~feedback_id ~using ~univs ~types
in
let entries = Future.map2 make_entry fpl (Proofview.initial_goals entry) in
{ name; entries; uctx = initial_euctx }
@@ -1854,7 +1857,8 @@ module MutualEntry : sig
val declare_variable
: pinfo:Proof_info.t
-> uctx:UState.t
- -> Entries.parameter_entry
+ -> sec_vars:Id.Set.t option
+ -> univs:Entries.universes_entry
-> Names.GlobRef.t list
val declare_mutdef
@@ -1920,10 +1924,11 @@ end = struct
in
List.map_i (declare_mutdef ~pinfo ~uctx pe) 0 pinfo.Proof_info.cinfo
- let declare_variable ~pinfo ~uctx pe =
+ let declare_variable ~pinfo ~uctx ~sec_vars ~univs =
let { Info.scope; hook } = pinfo.Proof_info.info in
List.map_i (
fun i { CInfo.name; typ; impargs } ->
+ let pe = (sec_vars, (typ, univs), None) in
declare_assumption ~name ~scope ~hook ~impargs ~uctx pe
) 0 pinfo.Proof_info.cinfo
@@ -1953,8 +1958,8 @@ let compute_proof_using_for_admitted proof typ pproofs =
Some (Environ.really_needed env (Id.Set.union ids_typ ids_def))
| _ -> None
-let finish_admitted ~pm ~pinfo ~uctx pe =
- let cst = MutualEntry.declare_variable ~pinfo ~uctx pe in
+let finish_admitted ~pm ~pinfo ~uctx ~sec_vars ~univs =
+ let cst = MutualEntry.declare_variable ~pinfo ~uctx ~sec_vars ~univs in
(* If the constant was an obligation we need to update the program map *)
match CEphemeron.get pinfo.Proof_info.proof_ending with
| Proof_ending.End_obligation oinfo ->
@@ -1974,7 +1979,7 @@ let save_admitted ~pm ~proof =
let sec_vars = compute_proof_using_for_admitted proof typ pproofs in
let uctx = get_initial_euctx proof in
let univs = UState.check_univ_decl ~poly uctx udecl in
- finish_admitted ~pm ~pinfo:proof.pinfo ~uctx (sec_vars, (typ, univs), None)
+ finish_admitted ~pm ~pinfo:proof.pinfo ~uctx ~sec_vars ~univs
(************************************************************************)
(* Saving a lemma-like constant *)
@@ -2097,12 +2102,9 @@ let save_lemma_admitted_delayed ~pm ~proof ~pinfo =
let poly = match proof_entry_universes with
| Entries.Monomorphic_entry _ -> false
| Entries.Polymorphic_entry (_, _) -> true in
- let typ = match proof_entry_type with
- | None -> CErrors.user_err Pp.(str "Admitted requires an explicit statement");
- | Some typ -> typ in
- let ctx = UState.univ_entry ~poly uctx in
+ let univs = UState.univ_entry ~poly uctx in
let sec_vars = if get_keep_admitted_vars () then proof_entry_secctx else None in
- finish_admitted ~pm ~uctx ~pinfo (sec_vars, (typ, ctx), None)
+ finish_admitted ~pm ~uctx ~pinfo ~sec_vars ~univs
let save_lemma_proved_delayed ~pm ~proof ~pinfo ~idopt =
(* vio2vo calls this but with invalid info, we have to workaround
@@ -2207,26 +2209,60 @@ let warn_solve_errored =
; fnl ()
; str "This will become an error in the future" ])
-let solve_by_tac ?loc name evi t ~poly ~uctx =
- (* the status is dropped. *)
+let solve_by_tac prg obls i tac =
+ let obl = obls.(i) in
+ let obl = subst_deps_obl obls obl in
+ let tac = Option.(default !default_tactic (append tac obl.obl_tac)) in
+ let uctx = Internal.get_uctx prg in
+ let uctx = UState.update_sigma_univs uctx (Global.universes ()) in
+ let poly = Internal.get_poly prg in
+ let evi = evar_of_obligation obl in
+ (* the status of [build_by_tactic] is dropped. *)
try
let env = Global.env () in
let body, types, _univs, _, uctx =
- build_by_tactic env ~uctx ~poly ~typ:evi.evar_concl t in
+ build_by_tactic env ~uctx ~poly ~typ:evi.evar_concl tac in
Inductiveops.control_only_guard env (Evd.from_ctx uctx) (EConstr.of_constr body);
Some (body, types, uctx)
with
| Tacticals.FailError (_, s) as exn ->
let _ = Exninfo.capture exn in
+ let loc = fst obl.obl_location in
CErrors.user_err ?loc ~hdr:"solve_obligation" (Lazy.force s)
(* If the proof is open we absorb the error and leave the obligation open *)
| Proof_.OpenProof _ ->
None
| e when CErrors.noncritical e ->
let err = CErrors.print e in
+ let loc = fst obl.obl_location in
warn_solve_errored ?loc err;
None
+let solve_and_declare_by_tac prg obls i tac =
+ match solve_by_tac prg obls i tac with
+ | None -> None
+ | Some (t, ty, uctx) ->
+ let obl = obls.(i) in
+ let poly = Internal.get_poly prg in
+ let prg = ProgramDecl.Internal.set_uctx ~uctx prg in
+ let def, obl', _cst = declare_obligation prg obl ~body:t ~types:ty ~uctx in
+ obls.(i) <- obl';
+ if def && not poly then (
+ (* Declare the term constraints with the first obligation only *)
+ let uctx_global = UState.from_env (Global.env ()) in
+ let uctx = UState.merge_subst uctx_global (UState.subst uctx) in
+ Some (ProgramDecl.Internal.set_uctx ~uctx prg))
+ else Some prg
+
+let solve_obligation_by_tac prg obls i tac =
+ let obl = obls.(i) in
+ match obl.obl_body with
+ | Some _ -> None
+ | None ->
+ if List.is_empty (deps_remaining obls obl.obl_deps)
+ then solve_and_declare_by_tac prg obls i tac
+ else None
+
let get_unique_prog ~pm prg =
match State.get_unique_open_prog pm prg with
| Ok prg -> prg
@@ -2256,7 +2292,8 @@ let rec solve_obligation prg num tac =
let name = Internal.get_name prg in
Proof_ending.End_obligation {name; num; auto}
in
- let cinfo = CInfo.make ~name:obl.obl_name ~typ:(EConstr.of_constr obl.obl_type) () in
+ let using = Internal.get_using prg in
+ let cinfo = CInfo.make ~name:obl.obl_name ~typ:(EConstr.of_constr obl.obl_type) ?using () in
let poly = Internal.get_poly prg in
let info = Info.make ~scope ~kind ~poly () in
let lemma = Proof.start_core ~cinfo ~info ~proof_ending evd in
@@ -2264,49 +2301,6 @@ let rec solve_obligation prg num tac =
let lemma = Option.cata (fun tac -> Proof.set_endline_tactic tac lemma) lemma tac in
lemma
-and obligation (user_num, name, typ) ~pm tac =
- let num = pred user_num in
- let prg = get_unique_prog ~pm name in
- let { obls; remaining } = Internal.get_obligations prg in
- if num >= 0 && num < Array.length obls then
- let obl = obls.(num) in
- match obl.obl_body with
- | None -> solve_obligation prg num tac
- | Some r -> Error.already_solved num
- else Error.unknown_obligation num
-
-and solve_obligation_by_tac prg obls i tac =
- let obl = obls.(i) in
- match obl.obl_body with
- | Some _ -> None
- | None ->
- if List.is_empty (deps_remaining obls obl.obl_deps) then
- let obl = subst_deps_obl obls obl in
- let tac =
- match tac with
- | Some t -> t
- | None ->
- match obl.obl_tac with
- | Some t -> t
- | None -> !default_tactic
- in
- let uctx = Internal.get_uctx prg in
- let uctx = UState.update_sigma_univs uctx (Global.universes ()) in
- let poly = Internal.get_poly prg in
- match solve_by_tac ?loc:(fst obl.obl_location) obl.obl_name (evar_of_obligation obl) tac ~poly ~uctx with
- | None -> None
- | Some (t, ty, uctx) ->
- let prg = ProgramDecl.Internal.set_uctx ~uctx prg in
- let def, obl', _cst = declare_obligation prg obl ~body:t ~types:ty ~uctx in
- obls.(i) <- obl';
- if def && not poly then (
- (* Declare the term constraints with the first obligation only *)
- let uctx_global = UState.from_env (Global.env ()) in
- let uctx = UState.merge_subst uctx_global (UState.subst uctx) in
- Some (ProgramDecl.Internal.set_uctx ~uctx prg))
- else Some prg
- else None
-
and solve_prg_obligations ~pm prg ?oblset tac =
let { obls; remaining } = Internal.get_obligations prg in
let rem = ref remaining in
@@ -2333,15 +2327,21 @@ and solve_prg_obligations ~pm prg ?oblset tac =
in
update_obls ~pm prg obls' !rem
-and solve_obligations ~pm n tac =
+and auto_solve_obligations ~pm n ?oblset tac : State.t * progress =
+ Flags.if_verbose Feedback.msg_info
+ (str "Solving obligations automatically...");
+ let prg = get_unique_prog ~pm n in
+ solve_prg_obligations ~pm prg ?oblset tac
+
+let solve_obligations ~pm n tac =
let prg = get_unique_prog ~pm n in
solve_prg_obligations ~pm prg tac
-and solve_all_obligations ~pm tac =
+let solve_all_obligations ~pm tac =
State.fold pm ~init:pm ~f:(fun k v pm ->
solve_prg_obligations ~pm v tac |> fst)
-and try_solve_obligation ~pm n prg tac =
+let try_solve_obligation ~pm n prg tac =
let prg = get_unique_prog ~pm prg in
let {obls; remaining} = Internal.get_obligations prg in
let obls' = Array.copy obls in
@@ -2351,14 +2351,19 @@ and try_solve_obligation ~pm n prg tac =
pm
| None -> pm
-and try_solve_obligations ~pm n tac =
+let try_solve_obligations ~pm n tac =
solve_obligations ~pm n tac |> fst
-and auto_solve_obligations ~pm n ?oblset tac : State.t * progress =
- Flags.if_verbose Feedback.msg_info
- (str "Solving obligations automatically...");
- let prg = get_unique_prog ~pm n in
- solve_prg_obligations ~pm prg ?oblset tac
+let obligation (user_num, name, typ) ~pm tac =
+ let num = pred user_num in
+ let prg = get_unique_prog ~pm name in
+ let { obls; remaining } = Internal.get_obligations prg in
+ if num >= 0 && num < Array.length obls then
+ let obl = obls.(num) in
+ match obl.obl_body with
+ | None -> solve_obligation prg num tac
+ | Some r -> Error.already_solved num
+ else Error.unknown_obligation num
let show_single_obligation i n obls x =
let x = subst_deps_obl obls x in
diff --git a/vernac/declare.mli b/vernac/declare.mli
index 1ad79928d5..0520bf8717 100644
--- a/vernac/declare.mli
+++ b/vernac/declare.mli
@@ -79,6 +79,7 @@ module CInfo : sig
-> typ:'constr
-> ?args:Name.t list
-> ?impargs:Impargs.manual_implicits
+ -> ?using:Names.Id.Set.t
-> unit
-> 'constr t
@@ -244,6 +245,12 @@ module Proof : sig
* (w.r.t. type dependencies and let-ins covered by it) *)
val set_used_variables : t -> Names.Id.t list -> Constr.named_context * t
+ (** Gets the set of variables declared to be used by the proof. None means
+ no "Proof using" or #[using] was given *)
+ val get_used_variables : t -> Id.Set.t option
+
+ (** Compacts the representation of the proof by pruning all intermediate
+ terms *)
val compact : t -> t
(** Update the proof's universe information typically after a
@@ -333,6 +340,7 @@ type 'a proof_entry
val definition_entry
: ?opaque:bool
+ -> ?using:Names.Id.Set.t
-> ?inline:bool
-> ?types:Constr.types
-> ?univs:Entries.universes_entry
diff --git a/vernac/egramcoq.ml b/vernac/egramcoq.ml
index b134f7b82b..efe4e17d0b 100644
--- a/vernac/egramcoq.ml
+++ b/vernac/egramcoq.ml
@@ -300,13 +300,13 @@ let interp_constr_entry_key : type r. _ -> r target -> int -> r Entry.t * int op
match forpat with
| ForConstr ->
if level = 200 then Constr.binder_constr, None
- else Constr.operconstr, Some level
+ else Constr.term, Some level
| ForPattern -> Constr.pattern, Some level
let target_entry : type s. notation_entry -> s target -> s Entry.t = function
| InConstrEntry ->
(function
- | ForConstr -> Constr.operconstr
+ | ForConstr -> Constr.term
| ForPattern -> Constr.pattern)
| InCustomEntry s ->
let (entry_for_constr, entry_for_patttern) = find_custom_entry s in
@@ -408,8 +408,8 @@ match e with
| TTClosedBinderList _ -> { subst with binderlists = List.flatten v :: subst.binderlists }
| TTBigint ->
begin match forpat with
- | ForConstr -> push_constr subst (CAst.make @@ CPrim (Numeral (NumTok.Signed.of_int_string v)))
- | ForPattern -> push_constr subst (CAst.make @@ CPatPrim (Numeral (NumTok.Signed.of_int_string v)))
+ | ForConstr -> push_constr subst (CAst.make @@ CPrim (Number (NumTok.Signed.of_int_string v)))
+ | ForPattern -> push_constr subst (CAst.make @@ CPatPrim (Number (NumTok.Signed.of_int_string v)))
end
| TTReference ->
begin match forpat with
diff --git a/vernac/g_vernac.mlg b/vernac/g_vernac.mlg
index 49d4847fde..f192d67624 100644
--- a/vernac/g_vernac.mlg
+++ b/vernac/g_vernac.mlg
@@ -48,7 +48,7 @@ let assumption_token = Entry.create "assumption_token"
let def_body = Entry.create "def_body"
let decl_notations = Entry.create "decl_notations"
let record_field = Entry.create "record_field"
-let of_type_with_opt_coercion = Entry.create "of_type_with_opt_coercion"
+let of_type = Entry.create "of_type"
let section_subset_expr = Entry.create "section_subset_expr"
let scope_delimiter = Entry.create "scope_delimiter"
let syntax_modifiers = Entry.create "syntax_modifiers"
@@ -113,10 +113,11 @@ GRAMMAR EXTEND Gram
]
;
attribute:
- [ [ k = ident ; v = attribute_value -> { Names.Id.to_string k, v } ]
+ [ [ k = ident ; v = attr_value -> { Names.Id.to_string k, v }
+ | "using" ; v = attr_value -> { "using", v } ]
]
;
- attribute_value:
+ attr_value:
[ [ "=" ; v = string -> { VernacFlagLeaf v }
| "(" ; a = attribute_list ; ")" -> { VernacFlagList a }
| -> { VernacFlagEmpty } ]
@@ -196,8 +197,8 @@ let name_of_ident_decl : ident_decl -> name_decl =
(* Gallina declarations *)
GRAMMAR EXTEND Gram
- GLOBAL: gallina gallina_ext thm_token def_token assumption_token def_body of_type_with_opt_coercion
- record_field decl_notations rec_definition ident_decl univ_decl;
+ GLOBAL: gallina gallina_ext thm_token def_token assumption_token def_body of_type
+ record_field decl_notations fix_definition ident_decl univ_decl;
gallina:
(* Definition, Theorem, Variable, Axiom, ... *)
@@ -219,13 +220,13 @@ GRAMMAR EXTEND Gram
(* Gallina inductive declarations *)
| f = finite_token; indl = LIST1 inductive_definition SEP "with" ->
{ VernacInductive (f, indl) }
- | "Fixpoint"; recs = LIST1 rec_definition SEP "with" ->
+ | "Fixpoint"; recs = LIST1 fix_definition SEP "with" ->
{ VernacFixpoint (NoDischarge, recs) }
- | IDENT "Let"; "Fixpoint"; recs = LIST1 rec_definition SEP "with" ->
+ | IDENT "Let"; "Fixpoint"; recs = LIST1 fix_definition SEP "with" ->
{ VernacFixpoint (DoDischarge, recs) }
- | "CoFixpoint"; corecs = LIST1 corec_definition SEP "with" ->
+ | "CoFixpoint"; corecs = LIST1 cofix_definition SEP "with" ->
{ VernacCoFixpoint (NoDischarge, corecs) }
- | IDENT "Let"; "CoFixpoint"; corecs = LIST1 corec_definition SEP "with" ->
+ | IDENT "Let"; "CoFixpoint"; corecs = LIST1 cofix_definition SEP "with" ->
{ VernacCoFixpoint (DoDischarge, corecs) }
| IDENT "Scheme"; l = LIST1 scheme SEP "with" -> { VernacScheme l }
| IDENT "Combined"; IDENT "Scheme"; id = identref; IDENT "from";
@@ -339,7 +340,7 @@ GRAMMAR EXTEND Gram
;
(* Inductives and records *)
opt_constructors_or_fields:
- [ [ ":="; lc = constructor_list_or_record_decl -> { lc }
+ [ [ ":="; lc = constructors_or_record -> { lc }
| -> { RecordDecl (None, []) } ] ]
;
inductive_definition:
@@ -349,7 +350,7 @@ GRAMMAR EXTEND Gram
lc=opt_constructors_or_fields; ntn = decl_notations ->
{ (((oc,id),(indpar,extrapar),c,lc),ntn) } ] ]
;
- constructor_list_or_record_decl:
+ constructors_or_record:
[ [ "|"; l = LIST1 constructor SEP "|" -> { Constructors l }
| id = identref ; c = constructor_type; "|"; l = LIST1 constructor SEP "|" ->
{ Constructors ((c id)::l) }
@@ -369,7 +370,7 @@ GRAMMAR EXTEND Gram
| -> { false } ] ]
;
(* (co)-fixpoints *)
- rec_definition:
+ fix_definition:
[ [ id_decl = ident_decl;
bl = binders_fixannot;
rtype = type_cstr;
@@ -378,7 +379,7 @@ GRAMMAR EXTEND Gram
{fname = fst id_decl; univs = snd id_decl; rec_order; binders; rtype; body_def; notations}
} ] ]
;
- corec_definition:
+ cofix_definition:
[ [ id_decl = ident_decl; binders = binders; rtype = type_cstr;
body_def = OPT [":="; def = lconstr -> { def }]; notations = decl_notations ->
{ {fname = fst id_decl; univs = snd id_decl; rec_order = (); binders; rtype; body_def; notations}
@@ -427,37 +428,37 @@ GRAMMAR EXTEND Gram
| -> { [] }
] ]
;
- record_binder_body:
- [ [ l = binders; oc = of_type_with_opt_coercion;
- t = lconstr -> { fun id -> (oc,AssumExpr (id,mkProdCN ~loc l t)) }
- | l = binders; oc = of_type_with_opt_coercion;
+ field_body:
+ [ [ l = binders; oc = of_type;
+ t = lconstr -> { fun id -> (oc,AssumExpr (id,l,t)) }
+ | l = binders; oc = of_type;
t = lconstr; ":="; b = lconstr -> { fun id ->
- (oc,DefExpr (id,mkLambdaCN ~loc l b,Some (mkProdCN ~loc l t))) }
+ (oc,DefExpr (id,l,b,Some t)) }
| l = binders; ":="; b = lconstr -> { fun id ->
match b.CAst.v with
| CCast(b', (CastConv t|CastVM t|CastNative t)) ->
- (NoInstance,DefExpr(id,mkLambdaCN ~loc l b',Some (mkProdCN ~loc l t)))
+ (NoInstance,DefExpr(id,l,b',Some t))
| _ ->
- (NoInstance,DefExpr(id,mkLambdaCN ~loc l b,None)) } ] ]
+ (NoInstance,DefExpr(id,l,b,None)) } ] ]
;
record_binder:
- [ [ id = name -> { (NoInstance,AssumExpr(id, CAst.make ~loc @@ CHole (None, IntroAnonymous, None))) }
- | id = name; f = record_binder_body -> { f id } ] ]
+ [ [ id = name -> { (NoInstance,AssumExpr(id, [], CAst.make ~loc @@ CHole (None, IntroAnonymous, None))) }
+ | id = name; f = field_body -> { f id } ] ]
;
assum_list:
- [ [ bl = LIST1 assum_coe -> { bl } | b = simple_assum_coe -> { [b] } ] ]
+ [ [ bl = LIST1 assum_coe -> { bl } | b = assumpt -> { [b] } ] ]
;
assum_coe:
- [ [ "("; a = simple_assum_coe; ")" -> { a } ] ]
+ [ [ "("; a = assumpt; ")" -> { a } ] ]
;
- simple_assum_coe:
- [ [ idl = LIST1 ident_decl; oc = of_type_with_opt_coercion; c = lconstr ->
+ assumpt:
+ [ [ idl = LIST1 ident_decl; oc = of_type; c = lconstr ->
{ (oc <> NoInstance,(idl,c)) } ] ]
;
constructor_type:
[[ l = binders;
- t= [ coe = of_type_with_opt_coercion; c = lconstr ->
+ t= [ coe = of_type; c = lconstr ->
{ fun l id -> (coe <> NoInstance,(id,mkProdCN ~loc l c)) }
| ->
{ fun l id -> (false,(id,mkProdCN ~loc l (CAst.make ~loc @@ CHole (None, IntroAnonymous, None)))) } ]
@@ -468,7 +469,7 @@ GRAMMAR EXTEND Gram
constructor:
[ [ id = identref; c=constructor_type -> { c id } ] ]
;
- of_type_with_opt_coercion:
+ of_type:
[ [ ":>" -> { BackInstance }
| ":"; ">" -> { BackInstance }
| ":" -> { NoInstance } ] ]
@@ -687,7 +688,7 @@ GRAMMAR EXTEND Gram
{ VernacContext (List.flatten c) }
| IDENT "Instance"; namesup = instance_name; ":";
- t = operconstr LEVEL "200";
+ t = term LEVEL "200";
info = hint_info ;
props = [ ":="; "{"; r = record_declaration; "}" -> { Some (true,r) } |
":="; c = lconstr -> { Some (false,c) } | -> { None } ] ->
@@ -707,13 +708,13 @@ GRAMMAR EXTEND Gram
(* Arguments *)
| IDENT "Arguments"; qid = smart_global;
- args = LIST0 argument_spec_block;
+ args = LIST0 arg_specs;
more_implicits = OPT
[ ","; impl = LIST1
- [ impl = LIST0 more_implicits_block -> { List.flatten impl } ]
+ [ impl = LIST0 implicits_alt -> { List.flatten impl } ]
SEP "," -> { impl }
];
- mods = OPT [ ":"; l = LIST1 arguments_modifier SEP "," -> { l } ] ->
+ mods = OPT [ ":"; l = LIST1 args_modifier SEP "," -> { l } ] ->
{ let mods = match mods with None -> [] | Some l -> List.flatten l in
let more_implicits = Option.default [] more_implicits in
VernacArguments (qid, List.flatten args, more_implicits, mods) }
@@ -732,7 +733,7 @@ GRAMMAR EXTEND Gram
idl = LIST1 identref -> { Some idl } ] ->
{ VernacGeneralizable gen } ] ]
;
- arguments_modifier:
+ args_modifier:
[ [ IDENT "simpl"; IDENT "nomatch" -> { [`ReductionDontExposeCase] }
| IDENT "simpl"; IDENT "never" -> { [`ReductionNeverUnfold] }
| IDENT "default"; IDENT "implicits" -> { [`DefaultImplicits] }
@@ -757,7 +758,7 @@ GRAMMAR EXTEND Gram
]
];
(* List of arguments implicit status, scope, modifiers *)
- argument_spec_block: [
+ arg_specs: [
[ item = argument_spec ->
{ let name, recarg_like, notation_scope = item in
[RealArg { name=name; recarg_like=recarg_like;
@@ -791,8 +792,8 @@ GRAMMAR EXTEND Gram
implicit_status = MaxImplicit}) items }
]
];
- (* Same as [argument_spec_block], but with only implicit status and names *)
- more_implicits_block: [
+ (* Same as [arg_specs], but with only implicit status and names *)
+ implicits_alt: [
[ name = name -> { [(name.CAst.v, Explicit)] }
| "["; items = LIST1 name; "]" ->
{ List.map (fun name -> (name.CAst.v, NonMaxImplicit)) items }
@@ -826,9 +827,9 @@ GRAMMAR EXTEND Gram
GLOBAL: command query_command class_rawexpr gallina_ext search_query search_queries;
gallina_ext:
- [ [ IDENT "Export"; "Set"; table = option_table; v = option_setting ->
+ [ [ IDENT "Export"; "Set"; table = setting_name; v = option_setting ->
{ VernacSetOption (true, table, v) }
- | IDENT "Export"; IDENT "Unset"; table = option_table ->
+ | IDENT "Export"; IDENT "Unset"; table = setting_name ->
{ VernacSetOption (true, table, OptionUnset) }
] ];
@@ -837,7 +838,7 @@ GRAMMAR EXTEND Gram
(* Hack! Should be in grammar_ext, but camlp5 factorizes badly *)
| IDENT "Declare"; IDENT "Instance"; id = ident_decl; bl = binders; ":";
- t = operconstr LEVEL "200";
+ t = term LEVEL "200";
info = hint_info ->
{ VernacDeclareInstance (id, bl, t, info) }
@@ -885,12 +886,12 @@ GRAMMAR EXTEND Gram
{ VernacAddMLPath dir }
(* For acting on parameter tables *)
- | "Set"; table = option_table; v = option_setting ->
+ | "Set"; table = setting_name; v = option_setting ->
{ VernacSetOption (false, table, v) }
- | IDENT "Unset"; table = option_table ->
+ | IDENT "Unset"; table = setting_name ->
{ VernacSetOption (false, table, OptionUnset) }
- | IDENT "Print"; IDENT "Table"; table = option_table ->
+ | IDENT "Print"; IDENT "Table"; table = setting_name ->
{ VernacPrintOption table }
| IDENT "Add"; table = IDENT; field = IDENT; v = LIST1 table_value
@@ -902,9 +903,9 @@ GRAMMAR EXTEND Gram
| IDENT "Add"; table = IDENT; v = LIST1 table_value ->
{ VernacAddOption ([table], v) }
- | IDENT "Test"; table = option_table; "for"; v = LIST1 table_value
+ | IDENT "Test"; table = setting_name; "for"; v = LIST1 table_value
-> { VernacMemOption (table, v) }
- | IDENT "Test"; table = option_table ->
+ | IDENT "Test"; table = setting_name ->
{ VernacPrintOption table }
| IDENT "Remove"; table = IDENT; field = IDENT; v= LIST1 table_value
@@ -1006,7 +1007,7 @@ GRAMMAR EXTEND Gram
[ [ id = global -> { Goptions.QualidRefValue id }
| s = STRING -> { Goptions.StringRefValue s } ] ]
;
- option_table:
+ setting_name:
[ [ fl = LIST1 [ x = IDENT -> { x } ] -> { fl } ]]
;
ne_in_or_out_modules:
@@ -1191,10 +1192,10 @@ GRAMMAR EXTEND Gram
| s, None -> SetFormat ("text",s) end }
| x = IDENT; ","; l = LIST1 [id = IDENT -> { id } ] SEP ","; "at";
lev = level -> { SetItemLevel (x::l,None,lev) }
- | x = IDENT; "at"; lev = level; b = OPT constr_as_binder_kind ->
+ | x = IDENT; "at"; lev = level; b = OPT binder_interp ->
{ SetItemLevel ([x],b,lev) }
- | x = IDENT; b = constr_as_binder_kind -> { SetItemLevel ([x],Some b,DefaultLevel) }
- | x = IDENT; typ = syntax_extension_type -> { SetEntryType (x,typ) }
+ | x = IDENT; b = binder_interp -> { SetItemLevel ([x],Some b,DefaultLevel) }
+ | x = IDENT; typ = explicit_subentry -> { SetEntryType (x,typ) }
] ]
;
syntax_modifiers:
@@ -1202,18 +1203,18 @@ GRAMMAR EXTEND Gram
| -> { [] }
] ]
;
- syntax_extension_type:
+ explicit_subentry:
[ [ IDENT "ident" -> { ETIdent } | IDENT "global" -> { ETGlobal }
| IDENT "bigint" -> { ETBigint }
| IDENT "binder" -> { ETBinder true }
| IDENT "constr" -> { ETConstr (InConstrEntry,None,DefaultLevel) }
- | IDENT "constr"; n = at_level_opt; b = OPT constr_as_binder_kind -> { ETConstr (InConstrEntry,b,n) }
+ | IDENT "constr"; n = at_level_opt; b = OPT binder_interp -> { ETConstr (InConstrEntry,b,n) }
| IDENT "pattern" -> { ETPattern (false,None) }
| IDENT "pattern"; "at"; IDENT "level"; n = natural -> { ETPattern (false,Some n) }
| IDENT "strict"; IDENT "pattern" -> { ETPattern (true,None) }
| IDENT "strict"; IDENT "pattern"; "at"; IDENT "level"; n = natural -> { ETPattern (true,Some n) }
| IDENT "closed"; IDENT "binder" -> { ETBinder false }
- | IDENT "custom"; x = IDENT; n = at_level_opt; b = OPT constr_as_binder_kind ->
+ | IDENT "custom"; x = IDENT; n = at_level_opt; b = OPT binder_interp ->
{ ETConstr (InCustomEntry x,b,n) }
] ]
;
@@ -1221,7 +1222,7 @@ GRAMMAR EXTEND Gram
[ [ "at"; n = level -> { n }
| -> { DefaultLevel } ] ]
;
- constr_as_binder_kind:
+ binder_interp:
[ [ "as"; IDENT "ident" -> { Notation_term.AsIdent }
| "as"; IDENT "pattern" -> { Notation_term.AsIdentOrPattern }
| "as"; IDENT "strict"; IDENT "pattern" -> { Notation_term.AsStrictPattern } ] ]
diff --git a/vernac/himsg.ml b/vernac/himsg.ml
index c16eaac516..bef9e29ac2 100644
--- a/vernac/himsg.ml
+++ b/vernac/himsg.ml
@@ -656,7 +656,7 @@ let explain_evar_not_found env sigma id =
let explain_wrong_case_info env (ind,u) ci =
let pi = pr_inductive env ind in
- if eq_ind ci.ci_ind ind then
+ if Ind.CanOrd.equal ci.ci_ind ind then
str "Pattern-matching expression on an object of inductive type" ++
spc () ++ pi ++ spc () ++ str "has invalid information."
else
@@ -831,7 +831,7 @@ let pr_constraints printenv env sigma evars cstrs =
(fun (ev, evi) -> fnl () ++ pr_existential_key sigma ev ++
str " : " ++ pr_leconstr_env env' sigma evi.evar_concl ++ fnl ()) l
in
- h 0 (pe ++ evs ++ pr_evar_constraints sigma cstrs)
+ h (pe ++ evs ++ pr_evar_constraints sigma cstrs)
else
let filter evk _ = Evar.Map.mem evk evars in
pr_evar_map_filter ~with_univs:false filter env sigma
@@ -866,7 +866,7 @@ let explain_unsatisfiable_constraints env sigma constr comp =
let info = Evar.Map.find ev undef in
explain_typeclass_resolution env sigma info k ++ fnl () ++ cstr
-let explain_pretype_error env sigma err =
+let rec explain_pretype_error env sigma err =
let env = Evardefine.env_nf_betaiotaevar sigma env in
let env = make_all_name_different env sigma in
match err with
@@ -893,7 +893,7 @@ let explain_pretype_error env sigma err =
| CannotUnifyBindingType (m,n) -> explain_cannot_unify_binding_type env sigma m n
| CannotFindWellTypedAbstraction (p,l,e) ->
explain_cannot_find_well_typed_abstraction env sigma p l
- (Option.map (fun (env',e) -> explain_type_error env' sigma e) e)
+ (Option.map (fun (env',e) -> explain_pretype_error env' sigma e) e)
| WrongAbstractionType (n,a,t,u) ->
explain_wrong_abstraction_type env sigma n a t u
| AbstractionOverMeta (m,n) -> explain_abstraction_over_meta env m n
@@ -973,8 +973,8 @@ let explain_not_match_error = function
(UContext.instance uctx)
(UContext.constraints uctx)
in
- str "incompatible polymorphic binders: got" ++ spc () ++ h 0 (pr_auctx got) ++ spc() ++
- str "but expected" ++ spc() ++ h 0 (pr_auctx expect) ++
+ str "incompatible polymorphic binders: got" ++ spc () ++ h (pr_auctx got) ++ spc() ++
+ str "but expected" ++ spc() ++ h (pr_auctx expect) ++
(if not (Int.equal (AUContext.size got) (AUContext.size expect)) then mt() else
fnl() ++ str "(incompatible constraints)")
| IncompatibleVariance ->
@@ -1232,7 +1232,7 @@ let error_not_allowed_dependent_analysis env isrec i =
pr_inductive env i ++ str "."
let error_not_mutual_in_scheme env ind ind' =
- if eq_ind ind ind' then
+ if Ind.CanOrd.equal ind ind' then
str "The inductive type " ++ pr_inductive env ind ++
str " occurs twice."
else
diff --git a/vernac/indschemes.ml b/vernac/indschemes.ml
index 356ccef06b..de72a30f18 100644
--- a/vernac/indschemes.ml
+++ b/vernac/indschemes.ml
@@ -405,7 +405,7 @@ let do_mutual_induction_scheme ?(force_mutual=false) lnamedepindsort =
let get_common_underlying_mutual_inductive env = function
| [] -> assert false
| (id,(mind,i as ind))::l as all ->
- match List.filter (fun (_,(mind',_)) -> not (MutInd.equal mind mind')) l with
+ match List.filter (fun (_,(mind',_)) -> not (Environ.QMutInd.equal env mind mind')) l with
| (_,ind')::_ ->
raise (RecursionSchemeError (env, NotMutualInScheme (ind,ind')))
| [] ->
diff --git a/vernac/metasyntax.ml b/vernac/metasyntax.ml
index 58b1698848..8477870cb4 100644
--- a/vernac/metasyntax.ml
+++ b/vernac/metasyntax.ml
@@ -61,15 +61,15 @@ let pr_registered_grammar name =
prlist pr_one entries
let pr_grammar = function
- | "constr" | "operconstr" | "binder_constr" ->
+ | "constr" | "term" | "binder_constr" ->
str "Entry constr is" ++ fnl () ++
pr_entry Pcoq.Constr.constr ++
str "and lconstr is" ++ fnl () ++
pr_entry Pcoq.Constr.lconstr ++
str "where binder_constr is" ++ fnl () ++
pr_entry Pcoq.Constr.binder_constr ++
- str "and operconstr is" ++ fnl () ++
- pr_entry Pcoq.Constr.operconstr
+ str "and term is" ++ fnl () ++
+ pr_entry Pcoq.Constr.term
| "pattern" ->
pr_entry Pcoq.Constr.pattern
| "vernac" ->
@@ -1042,6 +1042,13 @@ let interp_non_syntax_modifiers mods =
in
List.fold_left (fun st modif -> Option.bind st @@ set modif) (Some (false,false,InConstrEntry)) mods
+(* Check if an interpretation can be used for printing a cases printing *)
+let has_no_binders_type =
+ List.for_all (fun (_,(_,typ)) ->
+ match typ with
+ | NtnTypeBinder _ | NtnTypeBinderList -> false
+ | NtnTypeConstr | NtnTypeConstrList -> true)
+
(* Compute precedences from modifiers (or find default ones) *)
let set_entry_type from n etyps (x,typ) =
@@ -1165,11 +1172,6 @@ let warn_non_reversible_notation =
str " not occur in the right-hand side." ++ spc() ++
strbrk "The notation will not be used for printing as it is not reversible.")
-type entry_coercion_kind =
- | IsEntryCoercion of notation_entry_level
- | IsEntryGlobal of string * int
- | IsEntryIdent of string * int
-
let is_coercion level typs =
match level, typs with
| Some (custom,n,_), [e] ->
@@ -1231,6 +1233,9 @@ let find_precedence custom lev etyps symbols onlyprint =
| _ ->
user_err Pp.(str "A notation starting with an atomic expression must be at level 0.")
end
+ | (ETPattern _ | ETBinder _), InConstrEntry when not onlyprint ->
+ (* Don't know exactly if we can make sense of this case *)
+ user_err Pp.(str "Binders or patterns not supported in leftmost position.")
| (ETPattern _ | ETBinder _ | ETConstr _), _ ->
(* Give a default ? *)
if Option.is_empty lev then
@@ -1417,11 +1422,11 @@ type notation_obj = {
notobj_scope : scope_name option;
notobj_interp : interpretation;
notobj_coercion : entry_coercion_kind option;
- notobj_onlyparse : bool;
- notobj_onlyprint : bool;
+ notobj_use : notation_use option;
notobj_deprecation : Deprecation.t option;
notobj_notation : notation * notation_location;
notobj_specific_pp_rules : syntax_printing_extension option;
+ notobj_also_in_cases_pattern : bool;
}
let load_notation_common silently_define_scope_if_undefined _ (_, nobj) =
@@ -1442,37 +1447,20 @@ let open_notation i (_, nobj) =
let scope = nobj.notobj_scope in
let (ntn, df) = nobj.notobj_notation in
let pat = nobj.notobj_interp in
- let onlyprint = nobj.notobj_onlyprint in
let deprecation = nobj.notobj_deprecation in
- let specific = match scope with None -> LastLonelyNotation | Some sc -> NotationInScope sc in
- let specific_ntn = (specific,ntn) in
- let fresh = not (Notation.exists_notation_in_scope scope ntn onlyprint pat) in
- if fresh then begin
- (* Declare the interpretation *)
- let () = Notation.declare_notation_interpretation ntn scope pat df ~onlyprint deprecation in
- (* Declare the uninterpretation *)
- if not nobj.notobj_onlyparse then
- Notation.declare_uninterpretation (NotationRule specific_ntn) pat;
- (* Declare a possible coercion *)
- (match nobj.notobj_coercion with
- | Some (IsEntryCoercion entry) ->
- let (_,level,_) = Notation.level_of_notation ntn in
- let level = match fst ntn with
- | InConstrEntry -> None
- | InCustomEntry _ -> Some level
- in
- Notation.declare_entry_coercion specific_ntn level entry
- | Some (IsEntryGlobal (entry,n)) -> Notation.declare_custom_entry_has_global entry n
- | Some (IsEntryIdent (entry,n)) -> Notation.declare_custom_entry_has_ident entry n
- | None -> ())
- end;
+ let scope = match scope with None -> LastLonelyNotation | Some sc -> NotationInScope sc in
+ let also_in_cases_pattern = nobj.notobj_also_in_cases_pattern in
+ (* Declare the notation *)
+ (match nobj.notobj_use with
+ | Some use -> Notation.declare_notation (scope,ntn) pat df ~use ~also_in_cases_pattern nobj.notobj_coercion deprecation
+ | None -> ());
(* Declare specific format if any *)
- match nobj.notobj_specific_pp_rules with
+ (match nobj.notobj_specific_pp_rules with
| Some pp_sy ->
- if specific_format_to_declare specific_ntn pp_sy then
+ if specific_format_to_declare (scope,ntn) pp_sy then
Ppextend.declare_specific_notation_printing_rules
- specific_ntn ~extra:pp_sy.synext_extra pp_sy.synext_unparsing
- | None -> ()
+ (scope,ntn) ~extra:pp_sy.synext_extra pp_sy.synext_unparsing
+ | None -> ())
end
let cache_notation o =
@@ -1602,6 +1590,20 @@ let make_printing_rules reserved (sd : SynData.syn_data) = let open SynData in
synext_extra = sd.extra;
}
+let warn_unused_interpretation =
+ CWarnings.create ~name:"unused-notation" ~category:"parsing"
+ (fun b ->
+ strbrk "interpretation is used neither for printing nor for parsing, " ++
+ (if b then strbrk "the declaration could be replaced by \"Reserved Notation\"."
+ else strbrk "the declaration could be removed."))
+
+let make_use reserved onlyparse onlyprint =
+ match onlyparse, onlyprint with
+ | false, false -> Some ParsingAndPrinting
+ | true, false -> Some OnlyParsing
+ | false, true -> Some OnlyPrinting
+ | true, true -> warn_unused_interpretation reserved; None
+
(**********************************************************************)
(* Main functions about notations *)
@@ -1631,19 +1633,21 @@ let add_notation_in_scope ~local deprecation df env c mods scope =
let (acvars, ac, reversibility) = interp_notation_constr env nenv c in
let interp = make_interpretation_vars sd.recvars (pi2 sd.level) acvars (fst sd.pa_syntax_data) in
let map (x, _) = try Some (x, Id.Map.find x interp) with Not_found -> None in
+ let vars = List.map_filter map i_vars in (* Order of elements is important here! *)
+ let also_in_cases_pattern = has_no_binders_type vars in
let onlyparse,coe = printability (Some sd.level) sd.subentries sd.only_parsing reversibility ac in
let notation, location = sd.info in
+ let use = make_use true onlyparse sd.only_printing in
let notation = {
notobj_local = local;
notobj_scope = scope;
- notobj_interp = (List.map_filter map i_vars, ac);
- (* Order is important here! *)
- notobj_onlyparse = onlyparse;
+ notobj_use = use;
+ notobj_interp = (vars, ac);
notobj_coercion = coe;
- notobj_onlyprint = sd.only_printing;
notobj_deprecation = sd.deprecation;
notobj_notation = (notation, location);
notobj_specific_pp_rules = sy_pp_rules;
+ notobj_also_in_cases_pattern = also_in_cases_pattern;
} in
(* Ready to change the global state *)
List.iter (fun f -> f ()) sd.msgs;
@@ -1675,18 +1679,20 @@ let add_notation_interpretation_core ~local df env ?(impls=empty_internalization
let plevel = match level with Some (from,level,l) -> level | None (* numeral: irrelevant )*) -> 0 in
let interp = make_interpretation_vars recvars plevel acvars (List.combine mainvars i_typs) in
let map (x, _) = try Some (x, Id.Map.find x interp) with Not_found -> None in
+ let vars = List.map_filter map i_vars in (* Order of elements is important here! *)
+ let also_in_cases_pattern = has_no_binders_type vars in
let onlyparse,coe = printability level i_typs onlyparse reversibility ac in
+ let use = make_use false onlyparse onlyprint in
let notation = {
notobj_local = local;
notobj_scope = scope;
- notobj_interp = (List.map_filter map i_vars, ac);
- (* Order is important here! *)
- notobj_onlyparse = onlyparse;
+ notobj_use = use;
+ notobj_interp = (vars, ac);
notobj_coercion = coe;
- notobj_onlyprint = onlyprint;
notobj_deprecation = deprecation;
notobj_notation = df';
notobj_specific_pp_rules = pp_sy;
+ notobj_also_in_cases_pattern = also_in_cases_pattern;
} in
Lib.add_anonymous_leaf (inNotation notation);
df'
@@ -1860,8 +1866,9 @@ let add_syntactic_definition ~local deprecation env ident (vars,c) { onlyparsing
let in_pat id = (id,ETConstr (Constrexpr.InConstrEntry,None,(NextLevel,InternalProd))) in
let interp = make_interpretation_vars ~default_if_binding:AsIdentOrPattern [] 0 acvars (List.map in_pat vars) in
let vars = List.map (fun x -> (x, Id.Map.find x interp)) vars in
+ let also_in_cases_pattern = has_no_binders_type vars in
let onlyparsing = onlyparsing || fst (printability None [] false reversibility pat) in
- Syntax_def.declare_syntactic_definition ~local deprecation ident ~onlyparsing (vars,pat)
+ Syntax_def.declare_syntactic_definition ~local ~also_in_cases_pattern deprecation ident ~onlyparsing (vars,pat)
(**********************************************************************)
(* Declaration of custom entry *)
diff --git a/vernac/ppvernac.ml b/vernac/ppvernac.ml
index f972e05d3b..0e660bf20c 100644
--- a/vernac/ppvernac.ml
+++ b/vernac/ppvernac.ml
@@ -508,13 +508,15 @@ let pr_oc = function
let pr_record_field (x, { rf_subclass = oc ; rf_priority = pri ; rf_notation = ntn }) =
let prx = match x with
- | AssumExpr (id,t) ->
+ | AssumExpr (id,binders,t) ->
hov 1 (pr_lname id ++
+ pr_binders_arg binders ++ spc() ++
pr_oc oc ++ spc() ++
pr_lconstr_expr t)
- | DefExpr(id,b,opt) -> (match opt with
+ | DefExpr(id,binders,b,opt) -> (match opt with
| Some t ->
hov 1 (pr_lname id ++
+ pr_binders_arg binders ++ spc() ++
pr_oc oc ++ spc() ++
pr_lconstr_expr t ++ str" :=" ++ pr_lconstr b)
| None ->
@@ -524,8 +526,7 @@ let pr_record_field (x, { rf_subclass = oc ; rf_priority = pri ; rf_notation = n
prx ++ prpri ++ prlist (pr_decl_notation @@ pr_constr) ntn
let pr_record_decl c fs =
- pr_opt pr_lident c ++ (if c = None then str"{" else str" {") ++
- hv 0 (prlist_with_sep pr_semicolon pr_record_field fs ++ str"}")
+ pr_opt pr_lident c ++ pr_record "{" "}" pr_record_field fs
let pr_printable = function
| PrintFullContext ->
@@ -966,7 +967,7 @@ let pr_vernac_expr v =
str":" ++ spc () ++
pr_constr cl ++ pr_hint_info pr_constr_pattern_expr info ++
(match props with
- | Some (true, { v = CRecord l}) -> spc () ++ str":=" ++ spc () ++ str"{" ++ pr_record_body l ++ str "}"
+ | Some (true, { v = CRecord l}) -> spc () ++ str":=" ++ spc () ++ pr_record_body "{" "}" pr_lconstr l
| Some (true,_) -> assert false
| Some (false,p) -> spc () ++ str":=" ++ spc () ++ pr_constr p
| None -> mt()))
diff --git a/vernac/prettyp.ml b/vernac/prettyp.ml
index 8b00484b4a..06f7c32cdc 100644
--- a/vernac/prettyp.ml
+++ b/vernac/prettyp.ml
@@ -216,7 +216,7 @@ let print_polymorphism ref =
(if poly then str "universe polymorphic"
else if template_poly then
str "template universe polymorphic "
- ++ h 0 (pr_template_variables template_variables)
+ ++ h (pr_template_variables template_variables)
else str "not universe polymorphic") ]
let print_type_in_type ref =
diff --git a/vernac/proof_using.ml b/vernac/proof_using.ml
index 95680c2a4e..bdb0cabacf 100644
--- a/vernac/proof_using.ml
+++ b/vernac/proof_using.ml
@@ -18,30 +18,30 @@ module NamedDecl = Context.Named.Declaration
let known_names = Summary.ref [] ~name:"proofusing-nameset"
-let rec close_fwd e s =
+let rec close_fwd env sigma s =
let s' =
List.fold_left (fun s decl ->
let vb = match decl with
| LocalAssum _ -> Id.Set.empty
- | LocalDef (_,b,_) -> global_vars_set e b
+ | LocalDef (_,b,_) -> Termops.global_vars_set env sigma b
in
- let vty = global_vars_set e (NamedDecl.get_type decl) in
+ let vty = Termops.global_vars_set env sigma (NamedDecl.get_type decl) in
let vbty = Id.Set.union vb vty in
if Id.Set.exists (fun v -> Id.Set.mem v s) vbty
then Id.Set.add (NamedDecl.get_id decl) (Id.Set.union s vbty) else s)
- s (named_context e)
+ s (EConstr.named_context env)
in
- if Id.Set.equal s s' then s else close_fwd e s'
+ if Id.Set.equal s s' then s else close_fwd env sigma s'
-let set_of_type env ty =
+let set_of_type env sigma ty =
List.fold_left (fun acc ty ->
- Id.Set.union (global_vars_set env ty) acc)
+ Id.Set.union (Termops.global_vars_set env sigma ty) acc)
Id.Set.empty ty
let full_set env =
List.fold_right Id.Set.add (List.map NamedDecl.get_id (named_context env)) Id.Set.empty
-let process_expr env e v_ty =
+let process_expr env sigma e v_ty =
let rec aux = function
| SsEmpty -> Id.Set.empty
| SsType -> v_ty
@@ -49,7 +49,7 @@ let process_expr env e v_ty =
| SsUnion(e1,e2) -> Id.Set.union (aux e1) (aux e2)
| SsSubstr(e1,e2) -> Id.Set.diff (aux e1) (aux e2)
| SsCompl e -> Id.Set.diff (full_set env) (aux e)
- | SsFwdClose e -> close_fwd env (aux e)
+ | SsFwdClose e -> close_fwd env sigma (aux e)
and set_of_id id =
if Id.to_string id = "All" then
full_set env
@@ -59,9 +59,9 @@ let process_expr env e v_ty =
in
aux e
-let process_expr env e ty =
- let v_ty = set_of_type env ty in
- let s = Id.Set.union v_ty (process_expr env e v_ty) in
+let process_expr env sigma e ty =
+ let v_ty = set_of_type env sigma ty in
+ let s = Id.Set.union v_ty (process_expr env sigma e v_ty) in
Id.Set.elements s
let name_set id expr = known_names := (id,expr) :: !known_names
@@ -110,7 +110,7 @@ let suggest_common env ppid used ids_typ skip =
S.empty (named_context env)
in
let all = S.diff all skip in
- let fwd_typ = close_fwd env ids_typ in
+ let fwd_typ = close_fwd env (Evd.from_env env) ids_typ in
if !Flags.debug then begin
print (str "All " ++ pr_set false all);
print (str "Type " ++ pr_set false ids_typ);
diff --git a/vernac/proof_using.mli b/vernac/proof_using.mli
index dfc233e8fa..93dbd33ae4 100644
--- a/vernac/proof_using.mli
+++ b/vernac/proof_using.mli
@@ -11,7 +11,8 @@
(** Utility code for section variables handling in Proof using... *)
val process_expr :
- Environ.env -> Vernacexpr.section_subset_expr -> Constr.types list ->
+ Environ.env -> Evd.evar_map ->
+ Vernacexpr.section_subset_expr -> EConstr.types list ->
Names.Id.t list
val name_set : Names.Id.t -> Vernacexpr.section_subset_expr -> unit
@@ -24,3 +25,5 @@ val get_default_proof_using : unit -> Vernacexpr.section_subset_expr option
val proof_using_opt_name : string list
(** For the stm *)
+
+val using_from_string : string -> Vernacexpr.section_subset_expr
diff --git a/vernac/pvernac.ml b/vernac/pvernac.ml
index c9f68eed57..a7de34dd09 100644
--- a/vernac/pvernac.ml
+++ b/vernac/pvernac.ml
@@ -43,7 +43,8 @@ module Vernac_ =
let command = Entry.create "command"
let syntax = Entry.create "syntax_command"
let vernac_control = Entry.create "Vernac.vernac_control"
- let rec_definition = Entry.create "Vernac.rec_definition"
+ let fix_definition = Entry.create "Vernac.fix_definition"
+ let rec_definition = fix_definition
let red_expr = Entry.create "red_expr"
let hint_info = Entry.create "hint_info"
(* Main vernac entry *)
diff --git a/vernac/pvernac.mli b/vernac/pvernac.mli
index 8ab4af7d48..dac6877cb3 100644
--- a/vernac/pvernac.mli
+++ b/vernac/pvernac.mli
@@ -25,7 +25,9 @@ module Vernac_ :
val command : vernac_expr Entry.t
val syntax : vernac_expr Entry.t
val vernac_control : vernac_control Entry.t
+ val fix_definition : fixpoint_expr Entry.t
val rec_definition : fixpoint_expr Entry.t
+ [@@deprecated "Deprecated in 8.13; use 'fix_definition' instead"]
val noedit_mode : vernac_expr Entry.t
val command_entry : vernac_expr Entry.t
val main_entry : vernac_control option Entry.t
diff --git a/vernac/recLemmas.ml b/vernac/recLemmas.ml
index 534c358a3f..af72c01758 100644
--- a/vernac/recLemmas.ml
+++ b/vernac/recLemmas.ml
@@ -44,7 +44,7 @@ let find_mutually_recursive_statements sigma thms =
[] in
ind_hyps,ind_ccl) thms in
let inds_hyps,ind_ccls = List.split inds in
- let of_same_mutind ((kn,_),_,_) = function ((kn',_),_,_) -> Names.MutInd.equal kn kn' in
+ let of_same_mutind ((kn,_),_,_) = function ((kn',_),_,_) -> Environ.QMutInd.equal (Global.env ()) kn kn' in
(* Check if all conclusions are coinductive in the same type *)
(* (degenerated cartesian product since there is at most one coind ccl) *)
let same_indccl =
@@ -70,7 +70,7 @@ let find_mutually_recursive_statements sigma thms =
| [], _::_ ->
let () = match same_indccl with
| ind :: _ ->
- if List.distinct_f Names.ind_ord (List.map pi1 ind)
+ if List.distinct_f Names.Ind.CanOrd.compare (List.map pi1 ind)
then
Flags.if_verbose Feedback.msg_info
(Pp.strbrk
diff --git a/vernac/record.ml b/vernac/record.ml
index e362cb052a..acc97f61c1 100644
--- a/vernac/record.ml
+++ b/vernac/record.ml
@@ -62,23 +62,33 @@ let () =
let interp_fields_evars env sigma ~ninds ~nparams impls_env nots l =
let _, sigma, impls, newfs, _ =
List.fold_left2
- (fun (env, sigma, uimpls, params, impls) no ({CAst.loc;v=i}, b, t) ->
- let sigma, (t', impl) = interp_type_evars_impls env sigma ~impls t in
- let r = Retyping.relevance_of_type env sigma t' in
- let sigma, b' =
- Option.cata (fun x -> on_snd (fun x -> Some (fst x)) @@
- interp_casted_constr_evars_impls ~program_mode:false env sigma ~impls x t') (sigma,None) b in
- let impls =
+ (fun (env, sigma, uimpls, params, impls_env) no d ->
+ let sigma, (i, b, t), impl = match d with
+ | Vernacexpr.AssumExpr({CAst.loc;v=id},bl,t) ->
+ (* Temporary compatibility with the type-classes heuristics *)
+ (* which are applied after the interpretation of bl and *)
+ (* before the one of t otherwise (see #13166) *)
+ let t = if bl = [] then t else mkCProdN bl t in
+ let sigma, t, impl =
+ ComAssumption.interp_assumption ~program_mode:false env sigma impls_env [] t in
+ sigma, (id, None, t), impl
+ | Vernacexpr.DefExpr({CAst.loc;v=id},bl,b,t) ->
+ let sigma, (b, t), impl =
+ ComDefinition.interp_definition ~program_mode:false env sigma impls_env bl None b t in
+ let t = match t with Some t -> t | None -> Retyping.get_type_of env sigma b in
+ sigma, (id, Some b, t), impl in
+ let r = Retyping.relevance_of_type env sigma t in
+ let impls_env =
match i with
- | Anonymous -> impls
- | Name id -> Id.Map.add id (compute_internalization_data env sigma id Constrintern.Method t' impl) impls
+ | Anonymous -> impls_env
+ | Name id -> Id.Map.add id (compute_internalization_data env sigma id Constrintern.Method t impl) impls_env
in
- let d = match b' with
- | None -> LocalAssum (make_annot i r,t')
- | Some b' -> LocalDef (make_annot i r,b',t')
+ let d = match b with
+ | None -> LocalAssum (make_annot i r,t)
+ | Some b -> LocalDef (make_annot i r,b,t)
in
- List.iter (Metasyntax.set_notation_for_interpretation env impls) no;
- (EConstr.push_rel d env, sigma, impl :: uimpls, d::params, impls))
+ List.iter (Metasyntax.set_notation_for_interpretation env impls_env) no;
+ (EConstr.push_rel d env, sigma, impl :: uimpls, d::params, impls_env))
(env, sigma, [], [], impls_env) nots l
in
let _, _, sigma = Context.Rel.fold_outside ~init:(env,0,sigma) (fun f (env,k,sigma) ->
@@ -101,14 +111,6 @@ let compute_constructor_level evars env l =
in (EConstr.push_rel d env, univ))
l (env, Univ.Universe.sprop)
-let binder_of_decl = function
- | Vernacexpr.AssumExpr(n,t) -> (n,None,t)
- | Vernacexpr.DefExpr(n,c,t) ->
- (n,Some c, match t with Some c -> c
- | None -> CAst.make ?loc:n.CAst.loc @@ CHole (None, Namegen.IntroAnonymous, None))
-
-let binders_of_decls = List.map binder_of_decl
-
let check_anonymous_type ind =
match ind with
| { CAst.v = CSort (Glob_term.UAnonymous {rigid=true}) } -> true
@@ -176,7 +178,7 @@ let typecheck_params_and_fields def poly pl ps records =
let ninds = List.length arities in
let nparams = List.length newps in
let fold sigma (_, _, nots, fs) arity =
- interp_fields_evars env_ar sigma ~ninds ~nparams impls_env nots (binders_of_decls fs)
+ interp_fields_evars env_ar sigma ~ninds ~nparams impls_env nots fs
in
let (sigma, data) = List.fold_left2_map fold sigma records arities in
let sigma =
@@ -580,26 +582,17 @@ let declare_class def cumulative ubinders univs id idbuild paramimpls params uni
in
List.map map inds
in
- let ctx_context =
- let env = Global.env () in
- let sigma = Evd.from_env env in
- List.map (fun decl ->
- match Typeclasses.class_of_constr env sigma (EConstr.of_constr (RelDecl.get_type decl)) with
- | Some (_, ((cl,_), _)) -> Some cl.cl_impl
- | None -> None)
- params, params
- in
- let univs, ctx_context, fields =
+ let univs, params, fields =
match univs with
| Polymorphic_entry (nas, univs) ->
let usubst, auctx = Univ.abstract_universes nas univs in
let usubst = Univ.make_instance_subst usubst in
let map c = Vars.subst_univs_level_constr usubst c in
let fields = Context.Rel.map map fields in
- let ctx_context = on_snd (fun d -> Context.Rel.map map d) ctx_context in
- auctx, ctx_context, fields
+ let params = Context.Rel.map map params in
+ auctx, params, fields
| Monomorphic_entry _ ->
- Univ.AUContext.empty, ctx_context, fields
+ Univ.AUContext.empty, params, fields
in
let map (impl, projs) =
let k =
@@ -607,7 +600,7 @@ let declare_class def cumulative ubinders univs id idbuild paramimpls params uni
cl_impl = impl;
cl_strict = !typeclasses_strict;
cl_unique = !typeclasses_unique;
- cl_context = ctx_context;
+ cl_context = params;
cl_props = fields;
cl_projs = projs }
in
@@ -627,7 +620,7 @@ let add_constant_class env sigma cst =
let tc =
{ cl_univs = univs;
cl_impl = GlobRef.ConstRef cst;
- cl_context = (List.map (const None) ctx, ctx);
+ cl_context = ctx;
cl_props = [LocalAssum (make_annot Anonymous r, t)];
cl_projs = [];
cl_strict = !typeclasses_strict;
@@ -649,7 +642,7 @@ let add_inductive_class env sigma ind =
let r = Inductive.relevance_of_inductive env ind in
{ cl_univs = univs;
cl_impl = GlobRef.IndRef ind;
- cl_context = List.map (const None) ctx, ctx;
+ cl_context = ctx;
cl_props = [LocalAssum (make_annot Anonymous r, ty)];
cl_projs = [];
cl_strict = !typeclasses_strict;
@@ -676,8 +669,8 @@ open Vernacexpr
let check_unique_names records =
let extract_name acc (rf_decl, _) = match rf_decl with
- Vernacexpr.AssumExpr({CAst.v=Name id},_) -> id::acc
- | Vernacexpr.DefExpr ({CAst.v=Name id},_,_) -> id::acc
+ Vernacexpr.AssumExpr({CAst.v=Name id},_,_) -> id::acc
+ | Vernacexpr.DefExpr ({CAst.v=Name id},_,_,_) -> id::acc
| _ -> acc in
let allnames =
List.fold_left (fun acc (_, id, _, cfs, _, _) ->
diff --git a/vernac/search.ml b/vernac/search.ml
index abefeab779..501e5b1a91 100644
--- a/vernac/search.ml
+++ b/vernac/search.ml
@@ -216,18 +216,16 @@ let name_of_reference ref = Id.to_string (Nametab.basename_of_global ref)
let search_filter query gr kind env sigma typ = match query with
| GlobSearchSubPattern (where,head,pat) ->
let open Context.Rel.Declaration in
- let collect_hyps ctx =
- List.fold_left (fun acc d -> match get_value d with
- | None -> get_type d :: acc
- | Some b -> b :: get_type d :: acc) [] ctx in
+ let rec collect env hyps typ =
+ match Constr.kind typ with
+ | LetIn (na,b,t,c) -> collect (push_rel (LocalDef (na,b,t)) env) ((env,b) :: (env,t) :: hyps) c
+ | Prod (na,t,c) -> collect (push_rel (LocalAssum (na,t)) env) ((env,t) :: hyps) c
+ | _ -> (hyps,(env,typ)) in
let typl= match where with
- | InHyp -> collect_hyps (fst (Term.decompose_prod_assum typ))
- | InConcl -> [snd (Term.decompose_prod_assum typ)]
- | Anywhere ->
- if head then
- let ctx, ccl = Term.decompose_prod_assum typ in ccl :: collect_hyps ctx
- else [typ] in
- List.exists (fun typ ->
+ | InHyp -> fst (collect env [] typ)
+ | InConcl -> [snd (collect env [] typ)]
+ | Anywhere -> if head then let hyps, ccl = collect env [] typ in ccl :: hyps else [env,typ] in
+ List.exists (fun (env,typ) ->
let f =
if head then Constr_matching.is_matching_head
else Constr_matching.is_matching_appsubterm ~closed:false in
diff --git a/vernac/vernac.mllib b/vernac/vernac.mllib
index 994592a88a..cd0dd5e9a6 100644
--- a/vernac/vernac.mllib
+++ b/vernac/vernac.mllib
@@ -43,4 +43,5 @@ Topfmt
Loadpath
ComArguments
Vernacentries
+ComTactic
Vernacinterp
diff --git a/vernac/vernacentries.ml b/vernac/vernacentries.ml
index fe27d9ac8a..ef8631fbb6 100644
--- a/vernac/vernacentries.ml
+++ b/vernac/vernacentries.ml
@@ -57,14 +57,16 @@ module DefAttributes = struct
program : bool;
deprecated : Deprecation.t option;
canonical_instance : bool;
+ using : Vernacexpr.section_subset_expr option;
}
let parse f =
let open Attributes in
- let (((locality, deprecated), polymorphic), program), canonical_instance =
- parse Notations.(locality ++ deprecation ++ polymorphic ++ program ++ canonical_instance) f
+ let ((((locality, deprecated), polymorphic), program), canonical_instance), using =
+ parse Notations.(locality ++ deprecation ++ polymorphic ++ program ++ canonical_instance ++ using) f
in
- { polymorphic; program; locality; deprecated; canonical_instance }
+ let using = Option.map Proof_using.using_from_string using in
+ { polymorphic; program; locality; deprecated; canonical_instance; using }
end
let module_locality = Attributes.Notations.(locality >>= fun l -> return (make_module_locality l))
@@ -496,6 +498,25 @@ let program_inference_hook env sigma ev =
user_err Pp.(str "The statement obligations could not be resolved \
automatically, write a statement definition first.")
+let vernac_set_used_variables ~pstate e : Declare.Proof.t =
+ let env = Global.env () in
+ let sigma, _ = Declare.Proof.get_current_context pstate in
+ let initial_goals pf = Proofview.initial_goals Proof.((data pf).entry) in
+ let tys = List.map snd (initial_goals (Declare.Proof.get pstate)) in
+ let l = Proof_using.process_expr env sigma e tys in
+ let vars = Environ.named_context env in
+ List.iter (fun id ->
+ if not (List.exists (NamedDecl.get_id %> Id.equal id) vars) then
+ user_err ~hdr:"vernac_set_used_variables"
+ (str "Unknown variable: " ++ Id.print id))
+ l;
+ let _, pstate = Declare.Proof.set_used_variables pstate l in
+ pstate
+let vernac_set_used_variables_opt ?using pstate =
+ match using with
+ | None -> pstate
+ | Some expr -> vernac_set_used_variables ~pstate expr
+
(* XXX: Interpretation of lemma command, duplication with ComFixpoint
/ ComDefinition ? *)
let interp_lemma ~program_mode ~flags ~scope env0 evd thms =
@@ -525,7 +546,7 @@ let post_check_evd ~udecl ~poly evd =
else (* We fix the variables to ensure they won't be lowered to Set *)
Evd.fix_undefined_variables evd
-let start_lemma_com ~program_mode ~poly ~scope ~kind ?hook thms =
+let start_lemma_com ~program_mode ~poly ~scope ~kind ?using ?hook thms =
let env0 = Global.env () in
let flags = Pretyping.{ all_no_fail_flags with program_mode } in
let decl = fst (List.hd thms) in
@@ -533,17 +554,20 @@ let start_lemma_com ~program_mode ~poly ~scope ~kind ?hook thms =
let evd, thms = interp_lemma ~program_mode ~flags ~scope env0 evd thms in
let mut_analysis = RecLemmas.look_for_possibly_mutual_statements evd thms in
let evd = Evd.minimize_universes evd in
- match mut_analysis with
- | RecLemmas.NonMutual thm ->
- let thm = Declare.CInfo.to_constr evd thm in
- let evd = post_check_evd ~udecl ~poly evd in
- let info = Declare.Info.make ?hook ~poly ~scope ~kind ~udecl () in
- Declare.Proof.start_with_initialization ~info ~cinfo:thm evd
- | RecLemmas.Mutual { mutual_info; cinfo ; possible_guards } ->
- let cinfo = List.map (Declare.CInfo.to_constr evd) cinfo in
- let evd = post_check_evd ~udecl ~poly evd in
- let info = Declare.Info.make ?hook ~poly ~scope ~kind ~udecl () in
- Declare.Proof.start_mutual_with_initialization ~info ~cinfo evd ~mutual_info (Some possible_guards)
+ let pstate =
+ match mut_analysis with
+ | RecLemmas.NonMutual thm ->
+ let thm = Declare.CInfo.to_constr evd thm in
+ let evd = post_check_evd ~udecl ~poly evd in
+ let info = Declare.Info.make ?hook ~poly ~scope ~kind ~udecl () in
+ Declare.Proof.start_with_initialization ~info ~cinfo:thm evd
+ | RecLemmas.Mutual { mutual_info; cinfo ; possible_guards } ->
+ let cinfo = List.map (Declare.CInfo.to_constr evd) cinfo in
+ let evd = post_check_evd ~udecl ~poly evd in
+ let info = Declare.Info.make ?hook ~poly ~scope ~kind ~udecl () in
+ Declare.Proof.start_mutual_with_initialization ~info ~cinfo evd ~mutual_info (Some possible_guards)
+ in
+ vernac_set_used_variables_opt ?using pstate
let vernac_definition_hook ~canonical_instance ~local ~poly = let open Decls in function
| Coercion ->
@@ -583,7 +607,7 @@ let vernac_definition_interactive ~atts (discharge, kind) (lid, pl) bl t =
let program_mode = atts.program in
let poly = atts.polymorphic in
let name = vernac_definition_name lid local in
- start_lemma_com ~program_mode ~poly ~scope:local ~kind:(Decls.IsDefinition kind) ?hook [(name, pl), (bl, t)]
+ start_lemma_com ~program_mode ~poly ~scope:local ~kind:(Decls.IsDefinition kind) ?using:atts.using ?hook [(name, pl), (bl, t)]
let vernac_definition ~atts ~pm (discharge, kind) (lid, pl) bl red_option c typ_opt =
let open DefAttributes in
@@ -604,7 +628,7 @@ let vernac_definition ~atts ~pm (discharge, kind) (lid, pl) bl red_option c typ_
else
let () =
ComDefinition.do_definition ~name:name.v
- ~poly:atts.polymorphic ~scope ~kind pl bl red_option c typ_opt ?hook in
+ ~poly:atts.polymorphic ~scope ~kind ?using:atts.using pl bl red_option c typ_opt ?hook in
pm
(* NB: pstate argument to use combinators easily *)
@@ -613,7 +637,7 @@ let vernac_start_proof ~atts kind l =
let scope = enforce_locality_exp atts.locality NoDischarge in
if Dumpglob.dump () then
List.iter (fun ((id, _), _) -> Dumpglob.dump_definition id false "prf") l;
- start_lemma_com ~program_mode:atts.program ~poly:atts.polymorphic ~scope ~kind:(Decls.IsProof kind) l
+ start_lemma_com ~program_mode:atts.program ~poly:atts.polymorphic ~scope ~kind:(Decls.IsProof kind) ?using:atts.using l
let vernac_end_proof ~lemma ~pm = let open Vernacexpr in function
| Admitted ->
@@ -639,6 +663,8 @@ let vernac_assumption ~atts discharge kind l nl =
match scope with
| Global _ -> Dumpglob.dump_definition lid false "ax"
| Discharge -> Dumpglob.dump_definition lid true "var") idl) l;
+ if Option.has_some atts.using then
+ Attributes.unsupported_attributes ["using",VernacFlagEmpty];
ComAssumption.do_assumptions ~poly:atts.polymorphic ~program_mode:atts.program ~scope ~kind nl l
let is_polymorphic_inductive_cumulativity =
@@ -700,7 +726,7 @@ let vernac_record ~template udecl ~cumulative k ~poly finite records =
if Dumpglob.dump () then
let () = Dumpglob.dump_definition id false "rec" in
let iter (x, _) = match x with
- | Vernacexpr.AssumExpr ({loc;v=Name id}, _) ->
+ | Vernacexpr.(AssumExpr ({loc;v=Name id}, _, _) | DefExpr ({loc;v=Name id}, _, _, _)) ->
Dumpglob.dump_definition (make ?loc id) false "proj"
| _ -> ()
in
@@ -777,7 +803,7 @@ let vernac_inductive ~atts kind indl =
in
let (coe, (lid, ce)) = l in
let coe' = if coe then BackInstance else NoInstance in
- let f = AssumExpr ((make ?loc:lid.loc @@ Name lid.v), ce),
+ let f = AssumExpr ((make ?loc:lid.loc @@ Name lid.v), [], ce),
{ rf_subclass = coe' ; rf_priority = None ; rf_notation = [] ; rf_canonical = true } in
vernac_record ~template udecl ~cumulative (Class true) ~poly finite [id, bl, c, None, [f]]
else if List.for_all is_record indl then
@@ -842,16 +868,17 @@ let vernac_fixpoint_interactive ~atts discharge l =
let scope = vernac_fixpoint_common ~atts discharge l in
if atts.program then
CErrors.user_err Pp.(str"Program Fixpoint requires a body");
- ComFixpoint.do_fixpoint_interactive ~scope ~poly:atts.polymorphic l
+ vernac_set_used_variables_opt ?using:atts.using
+ (ComFixpoint.do_fixpoint_interactive ~scope ~poly:atts.polymorphic l)
let vernac_fixpoint ~atts ~pm discharge l =
let open DefAttributes in
let scope = vernac_fixpoint_common ~atts discharge l in
if atts.program then
(* XXX: Switch to the attribute system and match on ~atts *)
- ComProgramFixpoint.do_fixpoint ~pm ~scope ~poly:atts.polymorphic l
+ ComProgramFixpoint.do_fixpoint ~pm ~scope ~poly:atts.polymorphic ?using:atts.using l
else
- let () = ComFixpoint.do_fixpoint ~scope ~poly:atts.polymorphic l in
+ let () = ComFixpoint.do_fixpoint ~scope ~poly:atts.polymorphic ?using:atts.using l in
pm
let vernac_cofixpoint_common ~atts discharge l =
@@ -864,15 +891,16 @@ let vernac_cofixpoint_interactive ~atts discharge l =
let scope = vernac_cofixpoint_common ~atts discharge l in
if atts.program then
CErrors.user_err Pp.(str"Program CoFixpoint requires a body");
- ComFixpoint.do_cofixpoint_interactive ~scope ~poly:atts.polymorphic l
+ vernac_set_used_variables_opt ?using:atts.using
+ (ComFixpoint.do_cofixpoint_interactive ~scope ~poly:atts.polymorphic l)
let vernac_cofixpoint ~atts ~pm discharge l =
let open DefAttributes in
let scope = vernac_cofixpoint_common ~atts discharge l in
if atts.program then
- ComProgramFixpoint.do_cofixpoint ~pm ~scope ~poly:atts.polymorphic l
+ ComProgramFixpoint.do_cofixpoint ~pm ~scope ~poly:atts.polymorphic ?using:atts.using l
else
- let () = ComFixpoint.do_cofixpoint ~scope ~poly:atts.polymorphic l in
+ let () = ComFixpoint.do_cofixpoint ~scope ~poly:atts.polymorphic ?using:atts.using l in
pm
let vernac_scheme l =
@@ -957,9 +985,15 @@ let interp_filter_in m = function
let vernac_import export refl =
let import_mod (qid,f) =
- let m = try Nametab.locate_module qid
+ let loc = qid.loc in
+ let m = try
+ let m = Nametab.locate_module qid in
+ let () = if Modops.is_functor (Global.lookup_module m).Declarations.mod_type
+ then CErrors.user_err ?loc Pp.(str "Cannot import functor " ++ pr_qualid qid ++ str".")
+ in
+ m
with Not_found ->
- CErrors.user_err Pp.(str "Cannot find module " ++ pr_qualid qid)
+ CErrors.user_err ?loc Pp.(str "Cannot find module " ++ pr_qualid qid)
in
let f = interp_filter_in m f in
Declaremods.import_module f ~export m
@@ -1223,21 +1257,6 @@ let vernac_set_end_tac ~pstate tac =
(* TO DO verifier s'il faut pas mettre exist s | TacId s ici*)
Declare.Proof.set_endline_tactic tac pstate
-let vernac_set_used_variables ~pstate e : Declare.Proof.t =
- let env = Global.env () in
- let initial_goals pf = Proofview.initial_goals Proof.(data pf).Proof.entry in
- let tys = List.map snd (initial_goals (Declare.Proof.get pstate)) in
- let tys = List.map EConstr.Unsafe.to_constr tys in
- let l = Proof_using.process_expr env e tys in
- let vars = Environ.named_context env in
- List.iter (fun id ->
- if not (List.exists (NamedDecl.get_id %> Id.equal id) vars) then
- user_err ~hdr:"vernac_set_used_variables"
- (str "Unknown variable: " ++ Id.print id))
- l;
- let _, pstate = Declare.Proof.set_used_variables pstate l in
- pstate
-
(*****************************)
(* Auxiliary file management *)
@@ -1790,11 +1809,11 @@ let vernac_print ~pstate =
| PrintHintDbName s -> Hints.pr_hint_db_by_name env sigma s
| PrintHintDb -> Hints.pr_searchtable env sigma
| PrintScopes ->
- Notation.pr_scopes (Constrextern.without_symbols (pr_lglob_constr_env env))
+ Notation.pr_scopes (Constrextern.without_symbols (pr_glob_constr_env env))
| PrintScope s ->
- Notation.pr_scope (Constrextern.without_symbols (pr_lglob_constr_env env)) s
+ Notation.pr_scope (Constrextern.without_symbols (pr_glob_constr_env env)) s
| PrintVisibility s ->
- Notation.pr_visibility (Constrextern.without_symbols (pr_lglob_constr_env env)) s
+ Notation.pr_visibility (Constrextern.without_symbols (pr_glob_constr_env env)) s
| PrintAbout (ref_or_by_not,udecl,glnumopt) ->
print_about_hyp_globs ~pstate ref_or_by_not udecl glnumopt
| PrintImplicit qid ->
@@ -1830,7 +1849,7 @@ let vernac_locate ~pstate = let open Constrexpr in function
| LocateTerm {v=ByNotation (ntn, sc)} ->
let _, env = get_current_or_global_context ~pstate in
Notation.locate_notation
- (Constrextern.without_symbols (pr_lglob_constr_env env)) ntn sc
+ (Constrextern.without_symbols (pr_glob_constr_env env)) ntn sc
| LocateLibrary qid -> print_located_library qid
| LocateModule qid -> Prettyp.print_located_module qid
| LocateOther (s, qid) -> Prettyp.print_located_other s qid
diff --git a/vernac/vernacexpr.ml b/vernac/vernacexpr.ml
index eeebb43114..6a9a74144f 100644
--- a/vernac/vernacexpr.ml
+++ b/vernac/vernacexpr.ml
@@ -167,8 +167,8 @@ type fixpoint_expr = recursion_order_expr option fix_expr_gen
type cofixpoint_expr = unit fix_expr_gen
type local_decl_expr =
- | AssumExpr of lname * constr_expr
- | DefExpr of lname * constr_expr * constr_expr option
+ | AssumExpr of lname * local_binder_expr list * constr_expr
+ | DefExpr of lname * local_binder_expr list * constr_expr * constr_expr option
type inductive_kind = Inductive_kw | CoInductive | Variant | Record | Structure | Class of bool (* true = definitional, false = inductive *)
type simple_binder = lident list * constr_expr
diff --git a/vernac/vernacextend.ml b/vernac/vernacextend.ml
index eacb7fe6cb..ed63332861 100644
--- a/vernac/vernacextend.ml
+++ b/vernac/vernacextend.ml
@@ -30,7 +30,6 @@ type vernac_classification =
| VtQed of vernac_qed_type
(* A proof step *)
| VtProofStep of {
- parallel : [ `Yes of solving_tac * anon_abstracting_tac | `No ];
proof_block_detection : proof_block_name option
}
(* Queries are commands assumed to be "pure", that is to say, they
@@ -124,7 +123,7 @@ let declare_vernac_classifier name f =
let classify_as_query = VtQuery
let classify_as_sideeff = VtSideff ([], VtLater)
-let classify_as_proofstep = VtProofStep { parallel = `No; proof_block_detection = None}
+let classify_as_proofstep = VtProofStep { proof_block_detection = None}
type (_, _) ty_sig =
| TyNil : (vernac_command, vernac_classification) ty_sig
diff --git a/vernac/vernacextend.mli b/vernac/vernacextend.mli
index 5ef137cfc0..e1e3b4cfe5 100644
--- a/vernac/vernacextend.mli
+++ b/vernac/vernacextend.mli
@@ -46,7 +46,6 @@ type vernac_classification =
| VtQed of vernac_qed_type
(* A proof step *)
| VtProofStep of {
- parallel : [ `Yes of solving_tac * anon_abstracting_tac | `No ];
proof_block_detection : proof_block_name option
}
(* Queries are commands assumed to be "pure", that is to say, they