summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2019-02-13 20:40:51 -0500
committerGravatar Benjamin Barenblat <bbaren@google.com>2019-02-13 20:40:51 -0500
commit2ee22055c510a56c3d040fe023d0884b183bd68c (patch)
tree595eeed2159e90da8284b9e2d545430a61a60d04
parent7ecbed522b4b4a9829eb9bd7b3f36db53788a77c (diff)
parent8018e923c75eb5504310864f821972f794b7d554 (diff)
Updated version 8.8.0+1.gbp069dc3b from 'upstream/8.8.0+1.gbp069dc3b'
-rw-r--r--.gitignore22
-rw-r--r--CHANGELOG28
-rw-r--r--COPYING674
-rw-r--r--COPYING.LESSER165
-rw-r--r--LICENSE172
-rw-r--r--Make23
-rw-r--r--Makefile14
-rw-r--r--README55
-rw-r--r--README.md117
-rw-r--r--_CoqProject28
-rw-r--r--default.nix28
-rw-r--r--description15
-rw-r--r--meta.yml109
-rw-r--r--opam30
-rw-r--r--src/aac.ml479
-rw-r--r--src/aac_plugin.mlpack (renamed from aac.mlpack)1
-rw-r--r--src/aac_rewrite.ml (renamed from aac_rewrite.ml4)200
-rw-r--r--src/aac_rewrite.mli (renamed from aac_rewrite.mli)17
-rw-r--r--[-rwxr-xr-x]src/coq.ml (renamed from coq.ml)143
-rw-r--r--src/coq.mli (renamed from coq.mli)128
-rw-r--r--src/helper.ml (renamed from helper.ml)4
-rw-r--r--src/helper.mli (renamed from helper.mli)2
-rw-r--r--src/matcher.ml (renamed from matcher.ml)10
-rw-r--r--src/matcher.mli (renamed from matcher.mli)0
-rw-r--r--src/print.ml (renamed from print.ml)19
-rw-r--r--src/print.mli (renamed from print.mli)2
-rw-r--r--src/search_monad.ml (renamed from search_monad.ml)0
-rw-r--r--src/search_monad.mli (renamed from search_monad.mli)0
-rw-r--r--src/theory.ml (renamed from theory.ml)168
-rw-r--r--src/theory.mli (renamed from theory.mli)54
-rw-r--r--theories/AAC.v (renamed from AAC.v)254
-rw-r--r--theories/Caveats.v (renamed from Caveats.v)16
-rw-r--r--theories/Instances.v (renamed from Instances.v)41
-rw-r--r--theories/Tutorial.v (renamed from Tutorial.v)30
-rw-r--r--theories/Utils.v257
35 files changed, 1221 insertions, 1684 deletions
diff --git a/.gitignore b/.gitignore
index ce3c045..73bd09d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,19 @@
-doc
-html
-.pc
+*.aux
+*.a
+*.cma
+*.cmi
+*.cmo
+*.cmx
+*.cmxa
+*.cmxs
+*.glob
+*.native
+*.o
+*.d
+*.vio
+*.vo
+.coq-native
+
+.merlin
+Makefile.coq
+Makefile.coq.conf
diff --git a/CHANGELOG b/CHANGELOG
deleted file mode 100644
index 84b2aae..0000000
--- a/CHANGELOG
+++ /dev/null
@@ -1,28 +0,0 @@
-AAC_tactics 0.2-pl2 :
------------------
-
-- Improved the handling of nullifiable patterns.
-
-AAC_tactics 0.2.1 :
------------------
-
-- backport of some debian patches (thanks to S. Glondu)
-
-AAC_tactics 0.2 :
------------------
-
-- Several operators can share a given unit (like max and plus sharing zero)
-- Added some support to rewrite in inequations (using inequations)
-- Better priting functions for aac_instances
-- Overhauled inference of morphisms and operators :
- * Lift the previous requirement to have at leat one AC and one A operator
- * Binary operations are infered before morphisms (hence List.assoc can be recognized as being Associative)
-- Should now be able to handle goal with evars (but this is not unification modulo AC)
-- Added several new instances of Associative and Commutative operators
-- The old syntax to declare AC and A operators is no longer supported
-- The tactics do not abstract the proof they built (was troublesome if evars appeared)
-
-AAC_tactics 0.1 :
------------------
-Initial release
-
diff --git a/COPYING b/COPYING
deleted file mode 100644
index 94a9ed0..0000000
--- a/COPYING
+++ /dev/null
@@ -1,674 +0,0 @@
- GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
- The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works. By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users. We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors. You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
-
- To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights. Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received. You must make sure that they, too, receive
-or can get the source code. And you must show them these terms so they
-know their rights.
-
- Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
-
- For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software. For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
-
- Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so. This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software. The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable. Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products. If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
- Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary. To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- TERMS AND CONDITIONS
-
- 0. Definitions.
-
- "This License" refers to version 3 of the GNU General Public License.
-
- "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
- "The Program" refers to any copyrightable work licensed under this
-License. Each licensee is addressed as "you". "Licensees" and
-"recipients" may be individuals or organizations.
-
- To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy. The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
- A "covered work" means either the unmodified Program or a work based
-on the Program.
-
- To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy. Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
- To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies. Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
- An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License. If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
- 1. Source Code.
-
- The "source code" for a work means the preferred form of the work
-for making modifications to it. "Object code" means any non-source
-form of a work.
-
- A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
- The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form. A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
- The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities. However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work. For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
- The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
- The Corresponding Source for a work in source code form is that
-same work.
-
- 2. Basic Permissions.
-
- All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met. This License explicitly affirms your unlimited
-permission to run the unmodified Program. The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work. This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
- You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force. You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright. Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
- Conveying under any other circumstances is permitted solely under
-the conditions stated below. Sublicensing is not allowed; section 10
-makes it unnecessary.
-
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
- No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
- When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
- 4. Conveying Verbatim Copies.
-
- You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
- You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
- 5. Conveying Modified Source Versions.
-
- You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
- a) The work must carry prominent notices stating that you modified
- it, and giving a relevant date.
-
- b) The work must carry prominent notices stating that it is
- released under this License and any conditions added under section
- 7. This requirement modifies the requirement in section 4 to
- "keep intact all notices".
-
- c) You must license the entire work, as a whole, under this
- License to anyone who comes into possession of a copy. This
- License will therefore apply, along with any applicable section 7
- additional terms, to the whole of the work, and all its parts,
- regardless of how they are packaged. This License gives no
- permission to license the work in any other way, but it does not
- invalidate such permission if you have separately received it.
-
- d) If the work has interactive user interfaces, each must display
- Appropriate Legal Notices; however, if the Program has interactive
- interfaces that do not display Appropriate Legal Notices, your
- work need not make them do so.
-
- A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit. Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
- 6. Conveying Non-Source Forms.
-
- You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
- a) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by the
- Corresponding Source fixed on a durable physical medium
- customarily used for software interchange.
-
- b) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by a
- written offer, valid for at least three years and valid for as
- long as you offer spare parts or customer support for that product
- model, to give anyone who possesses the object code either (1) a
- copy of the Corresponding Source for all the software in the
- product that is covered by this License, on a durable physical
- medium customarily used for software interchange, for a price no
- more than your reasonable cost of physically performing this
- conveying of source, or (2) access to copy the
- Corresponding Source from a network server at no charge.
-
- c) Convey individual copies of the object code with a copy of the
- written offer to provide the Corresponding Source. This
- alternative is allowed only occasionally and noncommercially, and
- only if you received the object code with such an offer, in accord
- with subsection 6b.
-
- d) Convey the object code by offering access from a designated
- place (gratis or for a charge), and offer equivalent access to the
- Corresponding Source in the same way through the same place at no
- further charge. You need not require recipients to copy the
- Corresponding Source along with the object code. If the place to
- copy the object code is a network server, the Corresponding Source
- may be on a different server (operated by you or a third party)
- that supports equivalent copying facilities, provided you maintain
- clear directions next to the object code saying where to find the
- Corresponding Source. Regardless of what server hosts the
- Corresponding Source, you remain obligated to ensure that it is
- available for as long as needed to satisfy these requirements.
-
- e) Convey the object code using peer-to-peer transmission, provided
- you inform other peers where the object code and Corresponding
- Source of the work are being offered to the general public at no
- charge under subsection 6d.
-
- A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
- A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling. In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage. For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product. A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
- "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source. The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
- If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information. But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
- The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed. Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
- Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
- 7. Additional Terms.
-
- "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law. If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
- When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it. (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.) You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
- Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
- a) Disclaiming warranty or limiting liability differently from the
- terms of sections 15 and 16 of this License; or
-
- b) Requiring preservation of specified reasonable legal notices or
- author attributions in that material or in the Appropriate Legal
- Notices displayed by works containing it; or
-
- c) Prohibiting misrepresentation of the origin of that material, or
- requiring that modified versions of such material be marked in
- reasonable ways as different from the original version; or
-
- d) Limiting the use for publicity purposes of names of licensors or
- authors of the material; or
-
- e) Declining to grant rights under trademark law for use of some
- trade names, trademarks, or service marks; or
-
- f) Requiring indemnification of licensors and authors of that
- material by anyone who conveys the material (or modified versions of
- it) with contractual assumptions of liability to the recipient, for
- any liability that these contractual assumptions directly impose on
- those licensors and authors.
-
- All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10. If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term. If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
- If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
- Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
- 8. Termination.
-
- You may not propagate or modify a covered work except as expressly
-provided under this License. Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
- However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
- Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
- Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License. If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
- 9. Acceptance Not Required for Having Copies.
-
- You are not required to accept this License in order to receive or
-run a copy of the Program. Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance. However,
-nothing other than this License grants you permission to propagate or
-modify any covered work. These actions infringe copyright if you do
-not accept this License. Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
- 10. Automatic Licensing of Downstream Recipients.
-
- Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License. You are not responsible
-for enforcing compliance by third parties with this License.
-
- An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations. If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
- You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License. For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
- 11. Patents.
-
- A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based. The
-work thus licensed is called the contributor's "contributor version".
-
- A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version. For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
- Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
- In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement). To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
- If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients. "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
- If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
- A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License. You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
- Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
- 12. No Surrender of Others' Freedom.
-
- If conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all. For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
- 13. Use with the GNU Affero General Public License.
-
- Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work. The terms of this
-License will continue to apply to the part which is the covered work,
-but the special requirements of the GNU Affero General Public License,
-section 13, concerning interaction through a network will apply to the
-combination as such.
-
- 14. Revised Versions of this License.
-
- The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
- Each version is given a distinguishing version number. If the
-Program specifies that a certain numbered version of the GNU General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation. If the Program does not specify a version number of the
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
- If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
- Later license versions may give you additional or different
-permissions. However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
- 15. Disclaimer of Warranty.
-
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. Limitation of Liability.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
- 17. Interpretation of Sections 15 and 16.
-
- If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-Also add information on how to contact you by electronic and paper mail.
-
- If the program does terminal interaction, make it output a short
-notice like this when it starts in an interactive mode:
-
- <program> Copyright (C) <year> <name of author>
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, your program's commands
-might be different; for a GUI interface, you would use an "about box".
-
- You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU GPL, see
-<http://www.gnu.org/licenses/>.
-
- The GNU General Public License does not permit incorporating your program
-into proprietary programs. If your program is a subroutine library, you
-may consider it more useful to permit linking proprietary applications with
-the library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License. But first, please read
-<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/COPYING.LESSER b/COPYING.LESSER
deleted file mode 100644
index cca7fc2..0000000
--- a/COPYING.LESSER
+++ /dev/null
@@ -1,165 +0,0 @@
- GNU LESSER GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-
- This version of the GNU Lesser General Public License incorporates
-the terms and conditions of version 3 of the GNU General Public
-License, supplemented by the additional permissions listed below.
-
- 0. Additional Definitions.
-
- As used herein, "this License" refers to version 3 of the GNU Lesser
-General Public License, and the "GNU GPL" refers to version 3 of the GNU
-General Public License.
-
- "The Library" refers to a covered work governed by this License,
-other than an Application or a Combined Work as defined below.
-
- An "Application" is any work that makes use of an interface provided
-by the Library, but which is not otherwise based on the Library.
-Defining a subclass of a class defined by the Library is deemed a mode
-of using an interface provided by the Library.
-
- A "Combined Work" is a work produced by combining or linking an
-Application with the Library. The particular version of the Library
-with which the Combined Work was made is also called the "Linked
-Version".
-
- The "Minimal Corresponding Source" for a Combined Work means the
-Corresponding Source for the Combined Work, excluding any source code
-for portions of the Combined Work that, considered in isolation, are
-based on the Application, and not on the Linked Version.
-
- The "Corresponding Application Code" for a Combined Work means the
-object code and/or source code for the Application, including any data
-and utility programs needed for reproducing the Combined Work from the
-Application, but excluding the System Libraries of the Combined Work.
-
- 1. Exception to Section 3 of the GNU GPL.
-
- You may convey a covered work under sections 3 and 4 of this License
-without being bound by section 3 of the GNU GPL.
-
- 2. Conveying Modified Versions.
-
- If you modify a copy of the Library, and, in your modifications, a
-facility refers to a function or data to be supplied by an Application
-that uses the facility (other than as an argument passed when the
-facility is invoked), then you may convey a copy of the modified
-version:
-
- a) under this License, provided that you make a good faith effort to
- ensure that, in the event an Application does not supply the
- function or data, the facility still operates, and performs
- whatever part of its purpose remains meaningful, or
-
- b) under the GNU GPL, with none of the additional permissions of
- this License applicable to that copy.
-
- 3. Object Code Incorporating Material from Library Header Files.
-
- The object code form of an Application may incorporate material from
-a header file that is part of the Library. You may convey such object
-code under terms of your choice, provided that, if the incorporated
-material is not limited to numerical parameters, data structure
-layouts and accessors, or small macros, inline functions and templates
-(ten or fewer lines in length), you do both of the following:
-
- a) Give prominent notice with each copy of the object code that the
- Library is used in it and that the Library and its use are
- covered by this License.
-
- b) Accompany the object code with a copy of the GNU GPL and this license
- document.
-
- 4. Combined Works.
-
- You may convey a Combined Work under terms of your choice that,
-taken together, effectively do not restrict modification of the
-portions of the Library contained in the Combined Work and reverse
-engineering for debugging such modifications, if you also do each of
-the following:
-
- a) Give prominent notice with each copy of the Combined Work that
- the Library is used in it and that the Library and its use are
- covered by this License.
-
- b) Accompany the Combined Work with a copy of the GNU GPL and this license
- document.
-
- c) For a Combined Work that displays copyright notices during
- execution, include the copyright notice for the Library among
- these notices, as well as a reference directing the user to the
- copies of the GNU GPL and this license document.
-
- d) Do one of the following:
-
- 0) Convey the Minimal Corresponding Source under the terms of this
- License, and the Corresponding Application Code in a form
- suitable for, and under terms that permit, the user to
- recombine or relink the Application with a modified version of
- the Linked Version to produce a modified Combined Work, in the
- manner specified by section 6 of the GNU GPL for conveying
- Corresponding Source.
-
- 1) Use a suitable shared library mechanism for linking with the
- Library. A suitable mechanism is one that (a) uses at run time
- a copy of the Library already present on the user's computer
- system, and (b) will operate properly with a modified version
- of the Library that is interface-compatible with the Linked
- Version.
-
- e) Provide Installation Information, but only if you would otherwise
- be required to provide such information under section 6 of the
- GNU GPL, and only to the extent that such information is
- necessary to install and execute a modified version of the
- Combined Work produced by recombining or relinking the
- Application with a modified version of the Linked Version. (If
- you use option 4d0, the Installation Information must accompany
- the Minimal Corresponding Source and Corresponding Application
- Code. If you use option 4d1, you must provide the Installation
- Information in the manner specified by section 6 of the GNU GPL
- for conveying Corresponding Source.)
-
- 5. Combined Libraries.
-
- You may place library facilities that are a work based on the
-Library side by side in a single library together with other library
-facilities that are not Applications and are not covered by this
-License, and convey such a combined library under terms of your
-choice, if you do both of the following:
-
- a) Accompany the combined library with a copy of the same work based
- on the Library, uncombined with any other library facilities,
- conveyed under the terms of this License.
-
- b) Give prominent notice with the combined library that part of it
- is a work based on the Library, and explaining where to find the
- accompanying uncombined form of the same work.
-
- 6. Revised Versions of the GNU Lesser General Public License.
-
- The Free Software Foundation may publish revised and/or new versions
-of the GNU Lesser General Public License from time to time. Such new
-versions will be similar in spirit to the present version, but may
-differ in detail to address new problems or concerns.
-
- Each version is given a distinguishing version number. If the
-Library as you received it specifies that a certain numbered version
-of the GNU Lesser General Public License "or any later version"
-applies to it, you have the option of following the terms and
-conditions either of that published version or of any later version
-published by the Free Software Foundation. If the Library as you
-received it does not specify a version number of the GNU Lesser
-General Public License, you may choose any version of the GNU Lesser
-General Public License ever published by the Free Software Foundation.
-
- If the Library as you received it specifies that a proxy can decide
-whether future versions of the GNU Lesser General Public License shall
-apply, that proxy's public statement of acceptance of any version is
-permanent authorization for you to choose that version for the
-Library.
diff --git a/LICENSE b/LICENSE
index 1be0ca5..fb8f8b7 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,6 @@
-The aac_tactics plugin library is free software: you can redistribute
+Copyright (C) 2009-2018 Thomas Braibant, Damien Pous, Fabian Kunze
+
+The AAC tactics plugin library is free software: you can redistribute
it and/or modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.
@@ -8,6 +10,168 @@ WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
-You should have received a copy of the GNU Lesser General Public
-License along with this library. If not, see
-<http://www.gnu.org/licenses/>.
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/Make b/Make
deleted file mode 100644
index 3804332..0000000
--- a/Make
+++ /dev/null
@@ -1,23 +0,0 @@
--I .
--R . AAC_tactics
-
-coq.mli
-helper.mli
-search_monad.mli
-matcher.mli
-theory.mli
-print.mli
-aac_rewrite.mli
-coq.ml
-helper.ml
-search_monad.ml
-matcher.ml
-theory.ml
-print.ml
-aac_rewrite.ml4
-aac.mlpack
-
-AAC.v
-Instances.v
-Tutorial.v
-Caveats.v
diff --git a/Makefile b/Makefile
index abf2ec6..3e77020 100644
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,16 @@
all: Makefile.coq
- +make -f Makefile.coq all
+ +$(MAKE) -f Makefile.coq all
clean: Makefile.coq
- +make -f Makefile.coq clean
- rm -f Makefile.coq
+ +$(MAKE) -f Makefile.coq cleanall
+ rm -f Makefile.coq Makefile.coq.conf
-Makefile.coq: Make
- $(COQBIN)coq_makefile -f Make -o Makefile.coq
+Makefile.coq: _CoqProject
+ $(COQBIN)coq_makefile -f _CoqProject -o Makefile.coq
-Make: ;
+_CoqProject Makefile: ;
%: Makefile.coq
- +make -f Makefile.coq $@
+ +$(MAKE) -f Makefile.coq $@
.PHONY: all clean
diff --git a/README b/README
deleted file mode 100644
index 38fc514..0000000
--- a/README
+++ /dev/null
@@ -1,55 +0,0 @@
-
- aac_tactics
- ===========
-
- Thomas Braibant & Damien Pous
-
-Laboratoire d'Informatique de Grenoble (UMR 5217), INRIA, CNRS, France
-
-
-FOREWORD
-========
-
-This plugin provides tactics for rewriting universally quantified
-equations, modulo associativity and commutativity of some operators.
-
-INSTALLATION
-============
-
-opam repo add coq-released https://coq.inria.fr/opam/released
-opam install coq-aac-tactics
-
-DOCUMENTATION
-=============
-
-Please refer to Tutorial.v for a succinct introduction on how to use
-this plugin.
-
-To understand the inner-working of the tactic, please refer to the
-.mli files as the main source of information on each .ml
-file. Alternatively, [make world] generates ocamldoc/coqdoc
-documentation in directories doc/ and html/, respectively.
-
-File Instances.v defines several instances for frequent use-cases of
-this plugin, that should allow you to use it out-of-the-shelf. Namely,
-we have instances for:
-
-- Peano naturals (Import Instances.Peano)
-- Z binary numbers (Import Instances.Z)
-- N binary numbers (Import Instances.N)
-- P binary numbers (Import Instances.P)
-- Rationnal numbers (Import Instances.Q)
-- Prop (Import Instances.Prop_ops)
-- Booleans (Import Instances.Bool)
-- Relations (Import Instances.Relations)
-- All of the above (Import Instances.All)
-
-
-ACKNOWLEDGEMENTS
-================
-
-We are grateful to Evelyne Contejean, Hugo Herbelin, Assia Mahboubi
-and Matthieu Sozeau for highly instructive discussions.
-
-This plugin took inspiration from the plugin tutorial "constructors",
-distributed under the LGPL 2.1, copyrighted by Matthieu Sozeau
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c70f1bf
--- /dev/null
+++ b/README.md
@@ -0,0 +1,117 @@
+# AAC tactics
+
+[![Travis][travis-shield]][travis-link]
+[![Contributing][contributing-shield]][contributing-link]
+[![Code of Conduct][conduct-shield]][conduct-link]
+[![Gitter][gitter-shield]][gitter-link]
+[![DOI][doi-shield]][doi-link]
+
+[doi-shield]: https://zenodo.org/badge/DOI/10.1007/978-3-642-25379-9_14.svg
+[doi-link]: https://doi.org/10.1007/978-3-642-25379-9_14
+
+[travis-shield]: https://travis-ci.com/coq-community/aac-tactics.svg?branch=master
+[travis-link]: https://travis-ci.com/coq-community/aac-tactics/builds
+
+[contributing-shield]: https://img.shields.io/badge/contributions-welcome-%23f7931e.svg
+[contributing-link]: https://github.com/coq-community/manifesto/blob/master/CONTRIBUTING.md
+
+[conduct-shield]: https://img.shields.io/badge/%E2%9D%A4-code%20of%20conduct-%23f15a24.svg
+[conduct-link]: https://github.com/coq-community/manifesto/blob/master/CODE_OF_CONDUCT.md
+
+[gitter-shield]: https://img.shields.io/badge/chat-on%20gitter-%23c1272d.svg
+[gitter-link]: https://gitter.im/coq-community/Lobby
+
+This Coq plugin provides tactics for rewriting universally quantified
+equations, modulo associativity and commutativity of some operator.
+The tactics can be applied for custom operators by registering the
+operators and their properties as type class instances. Many common
+operator instances, such as for Z binary arithmetic and booleans, are
+provided with the plugin.
+
+
+More details about the project can be found in the paper
+[Tactics for Reasoning modulo AC in Coq](https://arxiv.org/abs/1106.4448).
+
+## Meta
+
+- Author(s):
+ - Thomas Braibant (initial)
+ - Damien Pous (initial)
+ - Fabian Kunze
+- Coq-community maintainer(s):
+ - Fabian Kunze ([**@fakusb**](https://github.com/fakusb))
+ - Karl Palmskog ([**@palmskog**](https://github.com/palmskog))
+- License: [GNU Lesser General Public License v3.0 or later](LICENSE)
+- Compatible Coq versions: Coq 8.9 (use the corresponding branch or release for other Coq versions)
+- Compatible OCaml versions: all versions supported by Coq
+- Additional dependencies: none
+
+## Building and installation instructions
+
+The easiest way to install the latest released version is via
+[OPAM](https://opam.ocaml.org/doc/Install.html):
+
+```shell
+opam repo add coq-released https://coq.inria.fr/opam/released
+opam install coq-aac-tactics
+```
+
+To instead build and install manually, do:
+
+``` shell
+git clone https://github.com/coq-community/aac-tactics
+cd aac-tactics
+make # or make -j <number-of-cores-on-your-machine>
+make install
+```
+
+After installation, the included modules are available under
+the `AAC_tactics` namespace.
+
+## Documentation
+
+The following example shows an application of the tactics for reasoning over Z binary numbers:
+```coq
+Require Import AAC_tactics.AAC.
+Require AAC_tactics.Instances.
+Require Import ZArith.
+
+Section ZOpp.
+ Import Instances.Z.
+ Variables a b c : Z.
+ Hypothesis H: forall x, x + Z.opp x = 0.
+
+ Goal a + b + c + Z.opp (c + a) = b.
+ aac_rewrite H.
+ aac_reflexivity.
+ Qed.
+End ZOpp.
+```
+
+The file [Tutorial.v](theories/Tutorial.v) provides a succinct introduction
+and more examples of how to use this plugin.
+
+The file [Instances.v](theories/Instances.v) defines several type class instances
+for frequent use-cases of this plugin, that should allow you to use it off-the-shelf.
+Namely, it contains instances for:
+
+- Peano naturals (`Import Instances.Peano.`)
+- Z binary numbers (`Import Instances.Z.`)
+- N binary numbers (`Import Instances.N.`)
+- P binary numbers (`Import Instances.P.`)
+- Rational numbers (`Import Instances.Q.`)
+- Prop (`Import Instances.Prop_ops.`)
+- Booleans (`Import Instances.Bool.`)
+- Relations (`Import Instances.Relations.`)
+- all of the above (`Import Instances.All.`)
+
+To understand the inner workings of the tactics, please refer to
+the `.mli` files as the main source of information on each `.ml` file.
+
+## Acknowledgements
+
+The initial authors are grateful to Evelyne Contejean, Hugo Herbelin,
+Assia Mahboubi, and Matthieu Sozeau for highly instructive discussions.
+The plugin took inspiration from the plugin tutorial "constructors" by
+Matthieu Sozeau, distributed under the LGPL 2.1.
+
diff --git a/_CoqProject b/_CoqProject
new file mode 100644
index 0000000..f803b8d
--- /dev/null
+++ b/_CoqProject
@@ -0,0 +1,28 @@
+-Q theories AAC_tactics
+-Q src AAC_tactics
+-I src
+
+-arg -w -arg +default
+
+src/coq.mli
+src/helper.mli
+src/search_monad.mli
+src/matcher.mli
+src/theory.mli
+src/print.mli
+src/aac_rewrite.mli
+src/coq.ml
+src/helper.ml
+src/search_monad.ml
+src/matcher.ml
+src/theory.ml
+src/print.ml
+src/aac_rewrite.ml
+src/aac.ml4
+src/aac_plugin.mlpack
+
+theories/Utils.v
+theories/AAC.v
+theories/Instances.v
+theories/Tutorial.v
+theories/Caveats.v
diff --git a/default.nix b/default.nix
new file mode 100644
index 0000000..8cd0cac
--- /dev/null
+++ b/default.nix
@@ -0,0 +1,28 @@
+{ pkgs ? (import <nixpkgs> {}), coq-version-or-url, shell ? false }:
+
+let
+ coq-version-parts = builtins.match "([0-9]+).([0-9]+)" coq-version-or-url;
+ coqPackages =
+ if coq-version-parts == null then
+ pkgs.mkCoqPackages (import (fetchTarball coq-version-or-url) {})
+ else
+ pkgs."coqPackages_${builtins.concatStringsSep "_" coq-version-parts}";
+in
+
+with coqPackages;
+
+pkgs.stdenv.mkDerivation {
+
+ name = "aac-tactics";
+
+ buildInputs = with coq.ocamlPackages; [ ocaml findlib camlp5 ]
+ ++ pkgs.lib.optionals shell [ merlin ocp-indent ocp-index ];
+
+ propagatedBuildInputs = [
+ coq
+ ];
+
+ src = if shell then null else ./.;
+
+ installFlags = "COQLIB=$(out)/lib/coq/${coq.coq-version}/";
+}
diff --git a/description b/description
deleted file mode 100644
index 7b7195d..0000000
--- a/description
+++ /dev/null
@@ -1,15 +0,0 @@
-Name: AACTactics
-Title: AAC tactics
-Description: This Coq plugin provides tactics for rewriting universally quantified equations, modulo associative (and possibly commutative) operators:
-Keywords: reflexive tactic, rewriting, rewriting modulo associativity and commutativity, rewriting modulo AC, reflexive decision procedure
-Category: Miscellaneous/Coq Extensions
-Author: Thomas Braibant
-Email: thomas.braibant@gmail.com
-Homepage: http://sardes.inrialpes.fr/~braibant/
-Institution: INRIA/UJF/Ens Lyon
-Author: Damien Pous
-Email: damien.pous@inria.fr
-Homepage: http://sardes.inrialpes.fr/~pous/
-Institution: CNRS
-Require:
-License: LGPL
diff --git a/meta.yml b/meta.yml
new file mode 100644
index 0000000..bc7f672
--- /dev/null
+++ b/meta.yml
@@ -0,0 +1,109 @@
+---
+fullname: AAC tactics
+shortname: aac-tactics
+
+description: |
+ This Coq plugin provides tactics for rewriting universally quantified
+ equations, modulo associativity and commutativity of some operator.
+ The tactics can be applied for custom operators by registering the
+ operators and their properties as type class instances. Many common
+ operator instances, such as for Z binary arithmetic and booleans, are
+ provided with the plugin.
+
+paper:
+ doi: 10.1007/978-3-642-25379-9_14
+ url: https://arxiv.org/abs/1106.4448
+ title: Tactics for Reasoning modulo AC in Coq
+
+authors:
+- name: Thomas Braibant
+ initial: true
+- name: Damien Pous
+ initial: true
+- name: Fabian Kunze
+ initial: false
+
+maintainers:
+- name: Fabian Kunze
+ nickname: fakusb
+- name: Karl Palmskog
+ nickname: palmskog
+
+opam-file-maintainer: palmskog@gmail.com
+
+license:
+ fullname: GNU Lesser General Public License v3.0 or later
+ identifier: LGPL-3.0-or-later
+
+plugin: true
+
+supported_coq_versions:
+ text: Coq 8.9 (use the corresponding branch or release for other Coq versions)
+ opam: '{>= "8.9" & < "8.10~"}'
+
+tested_coq_versions:
+- version_or_url: 8.9
+
+tested_coq_opam_version: 8.9
+
+namespace: AAC_tactics
+
+keywords:
+- name: reflexive tactic
+- name: rewriting
+- name: rewriting modulo associativity and commutativity
+- name: rewriting modulo ac
+- name: decision procedure
+
+categories:
+- name: Miscellaneous/Coq Extensions
+- name: Computer Science/Decision Procedures and Certified Algorithms/Decision procedures
+
+documentation: |
+ ## Documentation
+
+ The following example shows an application of the tactics for reasoning over Z binary numbers:
+ ```coq
+ Require Import AAC_tactics.AAC.
+ Require AAC_tactics.Instances.
+ Require Import ZArith.
+
+ Section ZOpp.
+ Import Instances.Z.
+ Variables a b c : Z.
+ Hypothesis H: forall x, x + Z.opp x = 0.
+
+ Goal a + b + c + Z.opp (c + a) = b.
+ aac_rewrite H.
+ aac_reflexivity.
+ Qed.
+ End ZOpp.
+ ```
+
+ The file [Tutorial.v](theories/Tutorial.v) provides a succinct introduction
+ and more examples of how to use this plugin.
+
+ The file [Instances.v](theories/Instances.v) defines several type class instances
+ for frequent use-cases of this plugin, that should allow you to use it off-the-shelf.
+ Namely, it contains instances for:
+
+ - Peano naturals (`Import Instances.Peano.`)
+ - Z binary numbers (`Import Instances.Z.`)
+ - N binary numbers (`Import Instances.N.`)
+ - P binary numbers (`Import Instances.P.`)
+ - Rational numbers (`Import Instances.Q.`)
+ - Prop (`Import Instances.Prop_ops.`)
+ - Booleans (`Import Instances.Bool.`)
+ - Relations (`Import Instances.Relations.`)
+ - all of the above (`Import Instances.All.`)
+
+ To understand the inner workings of the tactics, please refer to
+ the `.mli` files as the main source of information on each `.ml` file.
+
+ ## Acknowledgements
+
+ The initial authors are grateful to Evelyne Contejean, Hugo Herbelin,
+ Assia Mahboubi, and Matthieu Sozeau for highly instructive discussions.
+ The plugin took inspiration from the plugin tutorial "constructors" by
+ Matthieu Sozeau, distributed under the LGPL 2.1.
+---
diff --git a/opam b/opam
new file mode 100644
index 0000000..cd6aa36
--- /dev/null
+++ b/opam
@@ -0,0 +1,30 @@
+opam-version: "1.2"
+maintainer: "palmskog@gmail.com"
+
+homepage: "https://github.com/coq-community/aac-tactics"
+dev-repo: "https://github.com/coq-community/aac-tactics.git"
+bug-reports: "https://github.com/coq-community/aac-tactics/issues"
+license: "LGPL-3.0-or-later"
+
+build: [make "-j%{jobs}%"]
+install: [make "install"]
+remove: ["rm" "-R" "%{lib}%/coq/user-contrib/AAC_tactics"]
+depends: [
+ "coq" {>= "8.9" & < "8.10~"}
+]
+
+tags: [
+ "category:Miscellaneous/Coq Extensions"
+ "category:Computer Science/Decision Procedures and Certified Algorithms/Decision procedures"
+ "keyword:reflexive tactic"
+ "keyword:rewriting"
+ "keyword:rewriting modulo associativity and commutativity"
+ "keyword:rewriting modulo ac"
+ "keyword:decision procedure"
+ "logpath:AAC_tactics"
+]
+authors: [
+ "Thomas Braibant"
+ "Damien Pous"
+ "Fabian Kunze"
+]
diff --git a/src/aac.ml4 b/src/aac.ml4
new file mode 100644
index 0000000..e879a69
--- /dev/null
+++ b/src/aac.ml4
@@ -0,0 +1,79 @@
+(***************************************************************************)
+(* This is part of aac_tactics, it is distributed under the terms of the *)
+(* GNU Lesser General Public License version 3 *)
+(* (see file LICENSE for more details) *)
+(* *)
+(* Copyright 2009-2010: Thomas Braibant, Damien Pous. *)
+(***************************************************************************)
+
+(** aac -- Reasoning modulo associativity and commutativity *)
+
+DECLARE PLUGIN "aac_plugin"
+
+
+open Ltac_plugin
+open Pcoq.Prim
+open Pcoq.Constr
+open Stdarg
+open Aac_rewrite
+open Extraargs
+open Genarg
+
+ARGUMENT EXTEND aac_args
+TYPED AS ((string * int) list )
+PRINTED BY pr_aac_args
+| [ "at" integer(n) aac_args(q) ] -> [ add "at" n q ]
+| [ "subst" integer(n) aac_args(q) ] -> [ add "subst" n q ]
+| [ "in_right" aac_args(q) ] -> [ add "in_right" 0 q ]
+| [ ] -> [ [] ]
+END
+
+let pr_constro _ _ _ = fun b ->
+ match b with
+ | None -> Pp.str ""
+ | Some o -> Pp.str "<constr>"
+
+ARGUMENT EXTEND constro
+TYPED AS (constr option)
+PRINTED BY pr_constro
+| [ "[" constr(c) "]" ] -> [ Some c ]
+| [ ] -> [ None ]
+END
+
+TACTIC EXTEND _aac_reflexivity_
+| [ "aac_reflexivity" ] -> [ Proofview.V82.tactic aac_reflexivity ]
+END
+
+TACTIC EXTEND _aac_normalise_
+| [ "aac_normalise" ] -> [ Proofview.V82.tactic aac_normalise ]
+END
+
+TACTIC EXTEND _aac_rewrite_
+| [ "aac_rewrite" orient(l2r) constr(c) aac_args(args) constro(extra)] ->
+ [ Proofview.V82.tactic (fun gl -> aac_rewrite ?extra ~args ~l2r ~strict:true c gl) ]
+END
+
+TACTIC EXTEND _aac_pattern_
+| [ "aac_pattern" orient(l2r) constr(c) aac_args(args) constro(extra)] ->
+ [ Proofview.V82.tactic (fun gl -> aac_rewrite ?extra ~args ~l2r ~strict:true ~abort:true c gl) ]
+END
+
+TACTIC EXTEND _aac_instances_
+| [ "aac_instances" orient(l2r) constr(c) aac_args(args) constro(extra)] ->
+ [ Proofview.V82.tactic (fun gl -> aac_rewrite ?extra ~args ~l2r ~strict:true ~show:true c gl) ]
+END
+
+TACTIC EXTEND _aacu_rewrite_
+| [ "aacu_rewrite" orient(l2r) constr(c) aac_args(args) constro(extra)] ->
+ [ Proofview.V82.tactic (fun gl -> aac_rewrite ?extra ~args ~l2r ~strict:false c gl) ]
+END
+
+TACTIC EXTEND _aacu_pattern_
+| [ "aacu_pattern" orient(l2r) constr(c) aac_args(args) constro(extra)] ->
+ [ Proofview.V82.tactic (fun gl -> aac_rewrite ?extra ~args ~l2r ~strict:false ~abort:true c gl) ]
+END
+
+TACTIC EXTEND _aacu_instances_
+| [ "aacu_instances" orient(l2r) constr(c) aac_args(args) constro(extra)] ->
+ [ Proofview.V82.tactic (fun gl -> aac_rewrite ?extra ~args ~l2r ~strict:false ~show:true c gl) ]
+END
diff --git a/aac.mlpack b/src/aac_plugin.mlpack
index 80cb22c..ae61b0d 100644
--- a/aac.mlpack
+++ b/src/aac_plugin.mlpack
@@ -5,3 +5,4 @@ Matcher
Theory
Print
Aac_rewrite
+Aac
diff --git a/aac_rewrite.ml4 b/src/aac_rewrite.ml
index 1f57c0b..697c15c 100644
--- a/aac_rewrite.ml4
+++ b/src/aac_rewrite.ml
@@ -6,15 +6,10 @@
(* Copyright 2009-2010: Thomas Braibant, Damien Pous. *)
(***************************************************************************)
-(** aac_rewrite -- rewriting modulo *)
-
-open Pcoq.Prim
-open Pcoq.Constr
-open Stdarg
-open Constrarg
-
-DECLARE PLUGIN "aac"
-
+(** aac_rewrite -- rewriting modulo A or AC*)
+
+open Ltac_plugin
+
module Control = struct
let debug = false
let printing = false
@@ -29,57 +24,20 @@ let time_tac msg tac =
let tac_or_exn tac exn msg = fun gl ->
try tac gl with e ->
- pr_constr "last goal" (Tacmach.pf_concl gl);
+ let env = Tacmach.pf_env gl in
+ let sigma = Tacmach.project gl in
+ pr_constr env sigma "last goal" (Tacmach.pf_concl gl);
exn msg e
let retype = Coq.retype
-(* helper to be used with the previous function: raise a new anomaly
- except if a another one was previously raised *)
-let push_anomaly msg = function
- | e when CErrors.is_anomaly e -> raise e
- | _ -> Coq.anomaly msg
-
-module M = Matcher
-
-open Term
+open EConstr
open Names
-open Coqlib
open Proof_type
-(** The various kind of relation we can encounter, as a hierarchy *)
-type rew_relation =
- | Bare of Coq.Relation.t
- | Transitive of Coq.Transitive.t
- | Equivalence of Coq.Equivalence.t
-(** {!promote try to go higher in the aforementionned hierarchy} *)
-let promote (rlt : Coq.Relation.t) (k : rew_relation -> Proof_type.tactic) =
- try Coq.Equivalence.cps_from_relation rlt
- (fun e -> k (Equivalence e))
- with
- | Not_found ->
- begin
- try Coq.Transitive.cps_from_relation rlt
- (fun trans -> k (Transitive trans))
- with
- |Not_found -> k (Bare rlt)
- end
-
-
-(*
- Various situations:
- p == q |- left == right : rewrite <- ->
- p <= q |- left <= right : rewrite ->
- p <= q |- left == right : failure
- p == q |- left <= right : rewrite <- ->
-
- Not handled
- p <= q |- left >= right : failure
-*)
-
-(** aac_lift : the ideal type beyond AAC.v/Lift
+(** aac_lift : the ideal type beyond AAC_rewrite.v/Lift
A base relation r, together with an equivalence relation, and the
proof that the former lifts to the later. Howver, we have to
@@ -89,7 +47,7 @@ type aac_lift =
{
r : Coq.Relation.t;
e : Coq.Equivalence.t;
- lift : Term.constr
+ lift : constr
}
type rewinfo =
@@ -115,7 +73,7 @@ let infer_lifting (rlt: Coq.Relation.t) (k : lift:aac_lift -> Proof_type.tactic)
e
|]
) in
- Coq.cps_resolve_one_typeclass ~error:"Cannot infer a lifting"
+ Coq.cps_resolve_one_typeclass ~error:(Pp.strbrk "Cannot infer a lifting")
lift_ty (fun lift goal ->
let x = rlt.Coq.Relation.carrier in
let r = rlt.Coq.Relation.r in
@@ -189,12 +147,12 @@ let by_aac_reflexivity zero
(* This convert is required to deal with evars in a proper
way *)
let convert_to = mkApp (r, [| mkApp (eval,[| t |]); mkApp (eval, [|t'|])|]) in
- let convert = Proofview.V82.of_tactic (Tactics.convert_concl convert_to Term.VMcast) in
+ let convert = Proofview.V82.of_tactic (Tactics.convert_concl convert_to Constr.VMcast) in
let apply_tac = Proofview.V82.of_tactic (Tactics.apply decision_thm) in
(Tacticals.tclTHENLIST
[ retype decision_thm; retype convert_to;
convert ;
- tac_or_exn apply_tac Coq.user_error "unification failure";
+ tac_or_exn apply_tac Coq.user_error (Pp.strbrk "unification failure");
tac_or_exn (time_tac "vm_norm" (Proofview.V82.of_tactic (Tactics.normalise_in_concl))) Coq.anomaly "vm_compute failure";
Tacticals.tclORELSE (Proofview.V82.of_tactic Tactics.reflexivity)
(Tacticals.tclFAIL 0 (Pp.str "Not an equality modulo A/AC"))
@@ -220,7 +178,7 @@ let by_aac_normalise zero lift ir t t' =
(* This convert is required to deal with evars in a proper
way *)
let convert_to = mkApp (rlt.Coq.Relation.r, [| mkApp (eval,[| t |]); mkApp (eval, [|t'|])|]) in
- let convert = Proofview.V82.of_tactic (Tactics.convert_concl convert_to Term.VMcast) in
+ let convert = Proofview.V82.of_tactic (Tactics.convert_concl convert_to Constr.VMcast) in
let apply_tac = Proofview.V82.of_tactic (Tactics.apply normalise_thm) in
(Tacticals.tclTHENLIST
[ retype normalise_thm; retype convert_to;
@@ -233,13 +191,13 @@ let by_aac_normalise zero lift ir t t' =
(** A handler tactic, that reifies the goal, and infer the liftings,
and then call its continuation *)
let aac_conclude
- (k : Term.constr -> aac_lift -> Theory.Trans.ir -> Matcher.Terms.t -> Matcher.Terms.t -> Proof_type.tactic) = fun goal ->
+ (k : constr -> aac_lift -> Theory.Trans.ir -> Matcher.Terms.t -> Matcher.Terms.t -> Proof_type.tactic) = fun goal ->
- let (equation : Term.types) = Tacmach.pf_concl goal in
+ let (equation : types) = Tacmach.pf_concl goal in
let envs = Theory.Trans.empty_envs () in
let left, right,r =
match Coq.match_as_equation goal equation with
- | None -> Coq.user_error "The goal is not an applied relation"
+ | None -> Coq.user_error @@ Pp.strbrk "The goal is not an applied relation"
| Some x -> x in
try infer_lifting r
(fun ~lift goal ->
@@ -247,7 +205,9 @@ let aac_conclude
let tleft,tright, goal = Theory.Trans.t_of_constr goal eq envs (left,right) in
let goal, ir = Theory.Trans.ir_of_envs goal eq envs in
let concl = Tacmach.pf_concl goal in
- let _ = pr_constr "concl "concl in
+ let env = Tacmach.pf_env goal in
+ let sigma = Tacmach.project goal in
+ let _ = pr_constr env sigma "concl "concl in
let evar_map = Tacmach.project goal in
Tacticals.tclTHEN
(Refiner.tclEVARS evar_map)
@@ -255,22 +215,19 @@ let aac_conclude
goal
)goal
with
- | Not_found -> Coq.user_error "No lifting from the goal's relation to an equivalence"
+ | Not_found -> Coq.user_error @@ Pp.strbrk "No lifting from the goal's relation to an equivalence"
-open Libnames
open Tacexpr
-open Tacinterp
let aac_normalise = fun goal ->
let ids = Tacmach.pf_ids_of_hyps goal in
- let loc = Loc.ghost in
let mp = MPfile (DirPath.make (List.map Id.of_string ["AAC"; "AAC_tactics"])) in
let norm_tac = KerName.make2 mp (Label.make "internal_normalize") in
- let norm_tac = Misctypes.ArgArg (loc, norm_tac) in
+ let norm_tac = Locus.ArgArg (None, norm_tac) in
Tacticals.tclTHENLIST
[
aac_conclude by_aac_normalise;
- Proofview.V82.of_tactic (Tacinterp.eval_tactic (TacArg (loc, TacCall (loc, norm_tac, []))));
+ Proofview.V82.of_tactic (Tacinterp.eval_tactic (TacArg (None, TacCall (None, (norm_tac, [])))));
Proofview.V82.of_tactic (Tactics.keep ids)
] goal
@@ -279,7 +236,7 @@ let aac_reflexivity = fun goal ->
(fun zero lift ir t t' ->
let x,r = Coq.Relation.split (lift.r) in
let r_reflexive = (Coq.Classes.mk_reflexive x r) in
- Coq.cps_resolve_one_typeclass ~error:"The goal's relation is not reflexive"
+ Coq.cps_resolve_one_typeclass ~error:(Pp.strbrk "The goal's relation is not reflexive")
r_reflexive
(fun reflexive ->
let lift_reflexivity =
@@ -297,7 +254,9 @@ let aac_reflexivity = fun goal ->
(Tacticals.tclTHEN (retype lift_reflexivity) (Proofview.V82.of_tactic (Tactics.apply lift_reflexivity)))
(fun goal ->
let concl = Tacmach.pf_concl goal in
- let _ = pr_constr "concl "concl in
+ let env = Tacmach.pf_env goal in
+ let sigma = Tacmach.project goal in
+ let _ = pr_constr env sigma "concl "concl in
by_aac_reflexivity zero lift.e ir t t' goal)
)
) goal
@@ -309,7 +268,7 @@ let lift_transitivity in_left (step:constr) preorder lifting (using_eq : Coq.Equ
let concl = Tacmach.pf_concl goal in
let (left, right, _ ) = match Coq.match_as_equation goal concl with
| Some x -> x
- | None -> Coq.user_error "The goal is not an equation"
+ | None -> Coq.user_error @@ Pp.strbrk "The goal is not an equation"
in
let lift_transitivity =
let thm =
@@ -336,13 +295,13 @@ let lift_transitivity in_left (step:constr) preorder lifting (using_eq : Coq.Equ
] goal
-(** The core tactic for aac_rewrite *)
+(** The core tactic for aac_rewrite. Env and sigma are for the constr *)
let core_aac_rewrite ?abort
rewinfo
subst
(by_aac_reflexivity : Matcher.Terms.t -> Matcher.Terms.t -> Proof_type.tactic)
- (tr : constr) t left : tactic =
- pr_constr "transitivity through" tr;
+ env sigma (tr : constr) t left : tactic =
+ pr_constr env sigma "transitivity through" tr;
let tran_tac =
lift_transitivity rewinfo.in_left tr rewinfo.rlt rewinfo.lifting.lift rewinfo.eqt
in
@@ -382,12 +341,12 @@ let choose_subst subterm sol m=
(** rewrite the constr modulo AC from left to right in the left member
of the goal *)
-let aac_rewrite ?abort rew ?(l2r=true) ?(show = false) ?(in_left=true) ?strict ~occ_subterm ~occ_sol ?extra : Proof_type.tactic = fun goal ->
+let aac_rewrite_wrap ?abort rew ?(l2r=true) ?(show = false) ?(in_left=true) ?strict ~occ_subterm ~occ_sol ?extra : Proof_type.tactic = fun goal ->
let envs = Theory.Trans.empty_envs () in
- let (concl : Term.types) = Tacmach.pf_concl goal in
+ let (concl : types) = Tacmach.pf_concl goal in
let (_,_,rlt) as concl =
match Coq.match_as_equation goal concl with
- | None -> Coq.user_error "The goal is not an applied relation"
+ | None -> Coq.user_error @@ Pp.strbrk "The goal is not an applied relation"
| Some (left, right, rlt) -> left,right,rlt
in
let check_type x =
@@ -400,7 +359,7 @@ let aac_rewrite ?abort rew ?(l2r=true) ?(show = false) ?(in_left=true) ?strict
fun rewinfo ->
let goal =
match extra with
- | Some t -> Theory.Trans.add_symbol goal rewinfo.morph_rlt envs t
+ | Some t -> Theory.Trans.add_symbol goal rewinfo.morph_rlt envs (EConstr.to_constr (Tacmach.project goal) t)
| None -> goal
in
let pattern, subject, goal =
@@ -428,40 +387,35 @@ let aac_rewrite ?abort rew ?(l2r=true) ?(show = false) ?(in_left=true) ?strict
let subst = Matcher.Subst.to_list subst in
let subst = List.map (fun (x,y) -> x, conv y) subst in
let by_aac_reflexivity = (by_aac_reflexivity rewinfo.subject rewinfo.eqt ir) in
- core_aac_rewrite ?abort rewinfo subst by_aac_reflexivity tr_step_raw tr_step subject
+ let env = Tacmach.pf_env goal in
+ let sigma = Tacmach.project goal in
+ (* I'm not sure whether this is the right env/sigma for printing tr_step_raw *)
+ core_aac_rewrite ?abort rewinfo subst by_aac_reflexivity env sigma tr_step_raw tr_step subject
with
| NoSolutions ->
Tacticals.tclFAIL 0
(Pp.str (if occ_subterm = None && occ_sol = None
- then "No matching occurence modulo AC found"
+ then "No matching occurrence modulo AC found"
else "No such solution"))
)
) goal
+let get k l = try Some (List.assoc k l) with Not_found -> None
+
+let get_lhs l = try ignore (List.assoc "in_right" l); false with Not_found -> true
+
+let aac_rewrite ~args =
+ aac_rewrite_wrap ~occ_subterm:(get "at" args) ~occ_sol:(get "subst" args) ~in_left:(get_lhs args)
+
-open Coq.Rewrite
-open Tacmach
-open Tacticals
-open Tacexpr
-open Tacinterp
-open Extraargs
-open Genarg
let rec add k x = function
| [] -> [k,x]
| k',_ as ky::q ->
- if k'=k then Coq.user_error ("redondant argument ("^k^")")
+ if k'=k then Coq.user_error @@ Pp.strbrk ("redondant argument ("^k^")")
else ky::add k x q
-let get k l = try Some (List.assoc k l) with Not_found -> None
-
-let get_lhs l = try List.assoc "in_right" l; false with Not_found -> true
-
-let aac_rewrite ~args =
- aac_rewrite ~occ_subterm:(get "at" args) ~occ_sol:(get "subst" args) ~in_left:(get_lhs args)
-
-
let pr_aac_args _ _ _ l =
List.fold_left
(fun acc -> function
@@ -469,61 +423,3 @@ let pr_aac_args _ _ _ l =
| (k,i) -> Pp.(++) (Pp.(++) (Pp.str k) (Pp.int i)) acc
) (Pp.str "") l
-ARGUMENT EXTEND aac_args
-TYPED AS ((string * int) list )
-PRINTED BY pr_aac_args
-| [ "at" integer(n) aac_args(q) ] -> [ add "at" n q ]
-| [ "subst" integer(n) aac_args(q) ] -> [ add "subst" n q ]
-| [ "in_right" aac_args(q) ] -> [ add "in_right" 0 q ]
-| [ ] -> [ [] ]
-END
-
-let pr_constro _ _ _ = fun b ->
- match b with
- | None -> Pp.str ""
- | Some o -> Pp.str "<constr>"
-
-ARGUMENT EXTEND constro
-TYPED AS (constr option)
-PRINTED BY pr_constro
-| [ "[" constr(c) "]" ] -> [ Some c ]
-| [ ] -> [ None ]
-END
-
-TACTIC EXTEND _aac_reflexivity_
-| [ "aac_reflexivity" ] -> [ Proofview.V82.tactic aac_reflexivity ]
-END
-
-TACTIC EXTEND _aac_normalise_
-| [ "aac_normalise" ] -> [ Proofview.V82.tactic aac_normalise ]
-END
-
-TACTIC EXTEND _aac_rewrite_
-| [ "aac_rewrite" orient(l2r) constr(c) aac_args(args) constro(extra)] ->
- [ Proofview.V82.tactic (fun gl -> aac_rewrite ?extra ~args ~l2r ~strict:true c gl) ]
-END
-
-TACTIC EXTEND _aac_pattern_
-| [ "aac_pattern" orient(l2r) constr(c) aac_args(args) constro(extra)] ->
- [ Proofview.V82.tactic (fun gl -> aac_rewrite ?extra ~args ~l2r ~strict:true ~abort:true c gl) ]
-END
-
-TACTIC EXTEND _aac_instances_
-| [ "aac_instances" orient(l2r) constr(c) aac_args(args) constro(extra)] ->
- [ Proofview.V82.tactic (fun gl -> aac_rewrite ?extra ~args ~l2r ~strict:true ~show:true c gl) ]
-END
-
-TACTIC EXTEND _aacu_rewrite_
-| [ "aacu_rewrite" orient(l2r) constr(c) aac_args(args) constro(extra)] ->
- [ Proofview.V82.tactic (fun gl -> aac_rewrite ?extra ~args ~l2r ~strict:false c gl) ]
-END
-
-TACTIC EXTEND _aacu_pattern_
-| [ "aacu_pattern" orient(l2r) constr(c) aac_args(args) constro(extra)] ->
- [ Proofview.V82.tactic (fun gl -> aac_rewrite ?extra ~args ~l2r ~strict:false ~abort:true c gl) ]
-END
-
-TACTIC EXTEND _aacu_instances_
-| [ "aacu_instances" orient(l2r) constr(c) aac_args(args) constro(extra)] ->
- [ Proofview.V82.tactic (fun gl -> aac_rewrite ?extra ~args ~l2r ~strict:false ~show:true c gl) ]
-END
diff --git a/aac_rewrite.mli b/src/aac_rewrite.mli
index d195075..80134af 100644
--- a/aac_rewrite.mli
+++ b/src/aac_rewrite.mli
@@ -6,4 +6,19 @@
(* Copyright 2009-2010: Thomas Braibant, Damien Pous. *)
(***************************************************************************)
-(** Definition of the tactics, and corresponding Coq grammar entries.*)
+(** aac_rewrite -- rewriting modulo A or AC*)
+
+val aac_reflexivity : Coq.goal_sigma -> Proof_type.goal list Evd.sigma
+val aac_normalise : Coq.goal_sigma -> Proof_type.goal list Evd.sigma
+
+val aac_rewrite :
+ args:(string * int) list ->
+ ?abort:bool ->
+ EConstr.constr ->
+ ?l2r:bool ->
+ ?show:bool ->
+ ?strict:bool -> ?extra:EConstr.t -> Proof_type.tactic
+
+val add : string -> 'a -> (string * 'a) list -> (string * 'a) list
+
+val pr_aac_args : 'a -> 'b -> 'c -> (string * int) list -> Pp.t
diff --git a/coq.ml b/src/coq.ml
index eb4b5f1..ae1803a 100755..100644
--- a/coq.ml
+++ b/src/coq.ml
@@ -7,12 +7,10 @@
(***************************************************************************)
(** Interface with Coq *)
-type constr = Term.constr
-open Term
+open Constr
+open EConstr
open Names
-open Coqlib
-open Sigma.Notations
open Context.Rel.Declaration
(* The contrib name is used to locate errors when loading constrs *)
@@ -21,9 +19,11 @@ let contrib_name = "aac_tactics"
(* Getting constrs (primitive Coq terms) from existing Coq
libraries. *)
let find_constant contrib dir s =
- Universes.constr_of_global (Coqlib.find_reference contrib dir s)
+ UnivGen.constr_of_global (Coqlib.find_reference contrib dir s)
-let init_constant dir s = find_constant contrib_name dir s
+let init_constant_constr dir s = find_constant contrib_name dir s
+
+let init_constant dir s = EConstr.of_constr (find_constant contrib_name dir s)
(* A clause specifying that the [let] should not try to fold anything
in the goal *)
@@ -42,25 +42,17 @@ let cps_mk_letin
(k : constr -> Proof_type.tactic)
: Proof_type.tactic =
fun goal ->
- let name = (Names.id_of_string name) in
- let name = Tactics.fresh_id [] name goal in
+ let name = (Id.of_string name) in
+ let name = Tactics.fresh_id Id.Set.empty name goal in
let letin = (Proofview.V82.of_tactic (Tactics.letin_tac None (Name name) c None nowhere)) in
Tacticals.tclTHENLIST [retype c; letin; (k (mkVar name))] goal
-(** {2 General functions} *)
+(** {1 General functions} *)
-type goal_sigma = Proof_type.goal Tacmach.sigma
+type goal_sigma = Proof_type.goal Evd.sigma
let goal_update (goal : goal_sigma) evar_map : goal_sigma=
let it = Tacmach.sig_it goal in
Tacmach.re_sig it evar_map
-
-let fresh_evar goal ty : constr * goal_sigma =
- let env = Tacmach.pf_env goal in
- let evar_map = Tacmach.project goal in
- let evar_map = Sigma.Unsafe.of_evar_map evar_map in
- let Sigma (x,em,_) = Evarutil.new_evar env evar_map ty in
- let em = Sigma.to_evar_map em in
- x,( goal_update goal em)
let resolve_one_typeclass goal ty : constr*goal_sigma=
let env = Tacmach.pf_env goal in
@@ -68,65 +60,55 @@ let resolve_one_typeclass goal ty : constr*goal_sigma=
let em,c = Typeclasses.resolve_one_typeclass env evar_map ty in
c, (goal_update goal em)
-let general_error =
- "Cannot resolve a typeclass : please report"
-
-let cps_resolve_one_typeclass ?error : Term.types -> (Term.constr -> Proof_type.tactic) -> Proof_type.tactic = fun t k goal ->
+let cps_resolve_one_typeclass ?error : types -> (constr -> Proof_type.tactic) -> Proof_type.tactic = fun t k goal ->
Tacmach.pf_apply
(fun env em -> let em ,c =
try Typeclasses.resolve_one_typeclass env em t
with Not_found ->
begin match error with
| None -> CErrors.anomaly (Pp.str "Cannot resolve a typeclass : please report")
- | Some x -> CErrors.error x
+ | Some x -> CErrors.user_err x
end
in
Tacticals.tclTHENLIST [Refiner.tclEVARS em; k c] goal
) goal
-let nf_evar goal c : Term.constr=
+let nf_evar goal c : constr=
let evar_map = Tacmach.project goal in
- Evarutil.nf_evar evar_map c
+ Evarutil.nf_evar evar_map c
+
+ (* TODO: refactor following similar functions*)
let evar_unit (gl : goal_sigma) (x : constr) : constr * goal_sigma =
let env = Tacmach.pf_env gl in
let evar_map = Tacmach.project gl in
- let evar_map = Sigma.Unsafe.of_evar_map evar_map in
- let Sigma (x,em,_) = Evarutil.new_evar env evar_map x in
- let em = Sigma.to_evar_map em in
+ let (em,x) = Evarutil.new_evar env evar_map x in
x,(goal_update gl em)
let evar_binary (gl: goal_sigma) (x : constr) =
let env = Tacmach.pf_env gl in
let evar_map = Tacmach.project gl in
let ty = mkArrow x (mkArrow x x) in
- let evar_map = Sigma.Unsafe.of_evar_map evar_map in
- let Sigma (x,em,_) = Evarutil.new_evar env evar_map ty in
- let em = Sigma.to_evar_map em in
+ let (em,x) = Evarutil.new_evar env evar_map ty in
x,( goal_update gl em)
let evar_relation (gl: goal_sigma) (x: constr) =
let env = Tacmach.pf_env gl in
let evar_map = Tacmach.project gl in
- let ty = mkArrow x (mkArrow x (mkSort prop_sort)) in
- let evar_map = Sigma.Unsafe.of_evar_map evar_map in
- let Sigma (r, em, _) = Evarutil.new_evar env evar_map ty in
- let em = Sigma.to_evar_map em in
+ let ty = mkArrow x (mkArrow x (mkSort Sorts.prop)) in
+ let (em,r) = Evarutil.new_evar env evar_map ty in
r,( goal_update gl em)
let cps_evar_relation (x: constr) k = fun goal ->
Tacmach.pf_apply
(fun env em ->
- let ty = mkArrow x (mkArrow x (mkSort prop_sort)) in
- let em = Sigma.Unsafe.of_evar_map em in
- let Sigma (r, em, _) = Evarutil.new_evar env em ty in
- let em = Sigma.to_evar_map em in
+ let ty = mkArrow x (mkArrow x (mkSort Sorts.prop)) in
+ let (em, r) = Evarutil.new_evar env em ty in
Tacticals.tclTHENLIST [Refiner.tclEVARS em; k r] goal
) goal
-(* decomp_term : constr -> (constr, types) kind_of_term *)
-let decomp_term c = kind_of_term (strip_outer_cast c)
+let decomp_term sigma c = kind sigma (Termops.strip_outer_cast sigma c)
let lapp c v = mkApp (Lazy.force c, v)
@@ -180,7 +162,7 @@ end
module Pos = struct
- let path = ["Coq" ; "PArith"; "BinPos"]
+ let path = ["Coq" ; "Numbers"; "BinNums"]
let typ = lazy (init_constant path "positive")
let xI = lazy (init_constant path "xI")
let xO = lazy (init_constant path "xO")
@@ -227,7 +209,7 @@ end
(** Lists from the standard library*)
module List = struct
- let path = ["Coq"; "Lists"; "List"]
+ let path = ["Coq"; "Init"; "Datatypes"]
let typ = lazy (init_constant path "list")
let nil = lazy (init_constant path "nil")
let cons = lazy (init_constant path "cons")
@@ -335,10 +317,10 @@ end
remains typable*)
let match_as_equation ?(context = Context.Rel.empty) goal equation : (constr*constr* Std.Relation.t) option =
let env = Tacmach.pf_env goal in
- let env = Environ.push_rel_context context env in
+ let env = EConstr.push_rel_context context env in
let evar_map = Tacmach.project goal in
begin
- match decomp_term equation with
+ match decomp_term evar_map equation with
| App(c,ca) when Array.length ca >= 2 ->
let n = Array.length ca in
let left = ca.(n-2) in
@@ -364,8 +346,10 @@ let tclDEBUG msg tac = fun gl ->
let _ = Feedback.msg_debug (Pp.str msg) in
tac gl
-let tclPRINT tac = fun gl ->
- let _ = Feedback.msg_notice (Printer.pr_constr (Tacmach.pf_concl gl)) in
+let tclPRINT tac = fun gl ->
+ let env = Tacmach.pf_env gl in
+ let sigma = Tacmach.project gl in
+ let _ = Feedback.msg_notice (Printer.pr_econstr_env env sigma (Tacmach.pf_concl gl)) in
tac gl
@@ -376,7 +360,7 @@ let anomaly msg =
CErrors.anomaly ~label:"[aac_tactics]" (Pp.str msg)
let user_error msg =
- CErrors.error ("[aac_tactics] " ^ msg)
+ CErrors.user_err Pp.(str "[aac_tactics] " ++ msg)
let warning msg =
Feedback.msg_warning (Pp.str ("[aac_tactics]" ^ msg))
@@ -394,34 +378,35 @@ module Rewrite = struct
type hypinfo =
{
- hyp : Term.constr; (** the actual constr corresponding to the hypothese *)
- hyptype : Term.constr; (** the type of the hypothesis *)
- context : Context.Rel.t; (** the quantifications of the hypothese *)
- body : Term.constr; (** the body of the type of the hypothesis*)
+ hyp : constr; (** the actual constr corresponding to the hypothese *)
+ hyptype : constr; (** the type of the hypothesis *)
+ context : EConstr.rel_context; (** the quantifications of the hypothese *)
+ body : constr; (** the body of the type of the hypothesis*)
rel : Std.Relation.t; (** the relation *)
- left : Term.constr; (** left hand side *)
- right : Term.constr; (** right hand side *)
+ left : constr; (** left hand side *)
+ right : constr; (** right hand side *)
l2r : bool; (** rewriting from left to right *)
}
let get_hypinfo c ~l2r ?check_type (k : hypinfo -> Proof_type.tactic) : Proof_type.tactic = fun goal ->
let ctype = Tacmach.pf_unsafe_type_of goal c in
- let (rel_context, body_type) = Term.decompose_prod_assum ctype in
+ let evar_map = Tacmach.project goal in
+ let (rel_context, body_type) = decompose_prod_assum evar_map ctype in
let rec check f e =
- match decomp_term e with
- | Term.Rel i -> f (get_type (Context.Rel.lookup i rel_context))
- | _ -> Term.fold_constr (fun acc x -> acc && check f x) true e
+ match decomp_term evar_map e with
+ | Rel i -> f (get_type (Context.Rel.lookup i rel_context))
+ | _ -> fold evar_map (fun acc x -> acc && check f x) true e
in
begin match check_type with
| None -> ()
| Some f ->
if not (check f body_type)
- then user_error "Unable to deal with higher-order or heterogeneous patterns";
+ then user_error @@ Pp.strbrk "Unable to deal with higher-order or heterogeneous patterns";
end;
begin
- match match_as_equation ~context:rel_context goal body_type with
+ match match_as_equation ~context:rel_context goal body_type with
| None ->
- user_error "The hypothesis is not an applied relation"
+ user_error @@ Pp.strbrk "The hypothesis is not an applied relation"
| Some (hleft,hright,hrlt) ->
k {
hyp = c;
@@ -453,11 +438,11 @@ let get_hypinfo c ~l2r ?check_type (k : hypinfo -> Proof_type.tactic) : Proo
(* Fresh evars for everyone (should be the good way to do this
recompose in Coq v8.4) *)
let recompose_prod
- (context : Context.Rel.t)
- (subst : (int * Term.constr) list)
+ (context : rel_context)
+ (subst : (int * constr) list)
env
em
- : Evd.evar_map * Term.constr list =
+ : Evd.evar_map * constr list =
(* the last index of rel relevant for the rewriting *)
let min_n = List.fold_left
(fun acc (x,_) -> min acc x)
@@ -474,12 +459,10 @@ let recompose_prod
let em,x =
try em, List.assoc n subst
with | Not_found ->
- let em = Sigma.Unsafe.of_evar_map em in
- let Sigma (r, em, _) = Evarutil.new_evar env em (Vars.substl acc (get_type t)) in
- let em = Sigma.to_evar_map em in
+ let (em, r) = Evarutil.new_evar env em (Vars.substl acc (get_type t)) in
(em, r)
in
- (Environ.push_rel t env), em,x::acc
+ (EConstr.push_rel t env), em,x::acc
else
env,em,acc
in
@@ -487,11 +470,11 @@ let recompose_prod
em, acc
(* no fresh evars : instead, use a lambda abstraction around an
- application to handle non-instanciated variables. *)
+ application to handle non-instantiated variables. *)
let recompose_prod'
- (context : Context.Rel.t)
- (subst : (int *Term.constr) list)
+ (context : rel_context)
+ (subst : (int *constr) list)
c
=
let rec popn pop n l =
@@ -509,7 +492,7 @@ let recompose_prod'
aux sign (n+1) next (term::app) (None :: ctxt)
with
| Not_found ->
- let term = Term.mkRel next in
+ let term = mkRel next in
aux sign (n+1) (next+1) (term::app) (Some decl :: ctxt)
in
let app,ctxt = aux context 1 1 [] [] in
@@ -536,8 +519,8 @@ let recompose_prod'
update sign (decl :: res) (n+1)
in
let ctxt = update ctxt [] 0 in
- let c = Term.applistc c (List.rev app) in
- let c = Term.it_mkLambda_or_LetIn c (ctxt) in
+ let c = applist (c,List.rev app) in
+ let c = it_mkLambda_or_LetIn c ctxt in
c
(* Version de Matthieu
@@ -566,22 +549,22 @@ let recompose_prod' context subst c =
let build
(h : hypinfo)
- (subst : (int *Term.constr) list)
- (k :Term.constr -> Proof_type.tactic)
+ (subst : (int *constr) list)
+ (k :constr -> Proof_type.tactic)
: Proof_type.tactic = fun goal ->
let c = recompose_prod' h.context subst h.hyp in
Tacticals.tclTHENLIST [k c] goal
let build_with_evar
(h : hypinfo)
- (subst : (int *Term.constr) list)
- (k :Term.constr -> Proof_type.tactic)
+ (subst : (int *constr) list)
+ (k :constr -> Proof_type.tactic)
: Proof_type.tactic
= fun goal ->
Tacmach.pf_apply
(fun env em ->
let evar_map, acc = recompose_prod h.context subst env em in
- let c = Term.applistc h.hyp (List.rev acc) in
+ let c = applist (h.hyp,List.rev acc) in
Tacticals.tclTHENLIST [Refiner.tclEVARS evar_map; k c] goal
) goal
@@ -597,7 +580,7 @@ let rewrite ?(abort=false)hypinfo subst k =
Locus.AllOccurrences
true (* tell if existing evars must be frozen for instantiation *)
false
- (rew,Misctypes.NoBindings)
+ (rew,Tactypes.NoBindings)
true
end
else
diff --git a/coq.mli b/src/coq.mli
index 4d46c7d..9cf0db7 100644
--- a/coq.mli
+++ b/src/coq.mli
@@ -23,27 +23,26 @@
(** {2 Getting Coq terms from the environment} *)
-val init_constant : string list -> string -> Term.constr
+val init_constant_constr : string list -> string -> Constr.t
+val init_constant : string list -> string -> EConstr.constr
(** {2 General purpose functions} *)
-type goal_sigma = Proof_type.goal Tacmach.sigma
-val goal_update : goal_sigma -> Evd.evar_map -> goal_sigma
-val resolve_one_typeclass : Proof_type.goal Tacmach.sigma -> Term.types -> Term.constr * goal_sigma
-val cps_resolve_one_typeclass: ?error:string -> Term.types -> (Term.constr -> Proof_type.tactic) -> Proof_type.tactic
-val nf_evar : goal_sigma -> Term.constr -> Term.constr
-val fresh_evar :goal_sigma -> Term.types -> Term.constr* goal_sigma
-val evar_unit :goal_sigma ->Term.constr -> Term.constr* goal_sigma
-val evar_binary: goal_sigma -> Term.constr -> Term.constr* goal_sigma
-val evar_relation: goal_sigma -> Term.constr -> Term.constr* goal_sigma
-val cps_evar_relation : Term.constr -> (Term.constr -> Proof_type.tactic) -> Proof_type.tactic
+type goal_sigma = Proof_type.goal Evd.sigma
+val resolve_one_typeclass : Proof_type.goal Evd.sigma -> EConstr.types -> EConstr.constr * goal_sigma
+val cps_resolve_one_typeclass: ?error:Pp.t -> EConstr.types -> (EConstr.constr -> Proof_type.tactic) -> Proof_type.tactic
+val nf_evar : goal_sigma -> EConstr.constr -> EConstr.constr
+val evar_unit :goal_sigma ->EConstr.constr -> EConstr.constr* goal_sigma
+val evar_binary: goal_sigma -> EConstr.constr -> EConstr.constr* goal_sigma
+val evar_relation: goal_sigma -> EConstr.constr -> EConstr.constr* goal_sigma
+val cps_evar_relation : EConstr.constr -> (EConstr.constr -> Proof_type.tactic) -> Proof_type.tactic
(** [cps_mk_letin name v] binds the constr [v] using a letin tactic *)
-val cps_mk_letin : string -> Term.constr -> ( Term.constr -> Proof_type.tactic) -> Proof_type.tactic
+val cps_mk_letin : string -> EConstr.constr -> ( EConstr.constr -> Proof_type.tactic) -> Proof_type.tactic
-val retype : Term.constr -> Proof_type.tactic
+val retype : EConstr.constr -> Proof_type.tactic
-val decomp_term : Term.constr -> (Term.constr , Term.types) Term.kind_of_term
-val lapp : Term.constr lazy_t -> Term.constr array -> Term.constr
+val decomp_term : Evd.evar_map -> EConstr.constr -> (EConstr.constr , EConstr.types, EConstr.ESorts.t, EConstr.EInstance.t) Constr.kind_of_term
+val lapp : EConstr.constr lazy_t -> EConstr.constr array -> EConstr.constr
(** {2 Bindings with Coq' Standard Library} *)
@@ -51,81 +50,82 @@ val lapp : Term.constr lazy_t -> Term.constr array -> Term.constr
module List:
sig
(** [of_list ty l] *)
- val of_list:Term.constr ->Term.constr list ->Term.constr
+ val of_list:EConstr.constr ->EConstr.constr list ->EConstr.constr
(** [type_of_list ty] *)
- val type_of_list:Term.constr ->Term.constr
+ val type_of_list:EConstr.constr ->EConstr.constr
end
(** Coq pairs *)
module Pair:
sig
- val typ:Term.constr lazy_t
- val pair:Term.constr lazy_t
- val of_pair : Term.constr -> Term.constr -> Term.constr * Term.constr -> Term.constr
+ val typ:EConstr.constr lazy_t
+ val pair:EConstr.constr lazy_t
+ val of_pair : EConstr.constr -> EConstr.constr -> EConstr.constr * EConstr.constr -> EConstr.constr
end
module Bool : sig
- val typ : Term.constr lazy_t
- val of_bool : bool -> Term.constr
+ val typ : EConstr.constr lazy_t
+ val of_bool : bool -> EConstr.constr
end
module Comparison : sig
- val typ : Term.constr lazy_t
- val eq : Term.constr lazy_t
- val lt : Term.constr lazy_t
- val gt : Term.constr lazy_t
+ val typ : EConstr.constr lazy_t
+ val eq : EConstr.constr lazy_t
+ val lt : EConstr.constr lazy_t
+ val gt : EConstr.constr lazy_t
end
module Leibniz : sig
- val eq_refl : Term.types -> Term.constr -> Term.constr
+ val eq_refl : EConstr.types -> EConstr.constr -> EConstr.constr
end
module Option : sig
- val some : Term.constr -> Term.constr -> Term.constr
- val none : Term.constr -> Term.constr
- val of_option : Term.constr -> Term.constr option -> Term.constr
+ val typ : EConstr.constr lazy_t
+ val some : EConstr.constr -> EConstr.constr -> EConstr.constr
+ val none : EConstr.constr -> EConstr.constr
+ val of_option : EConstr.constr -> EConstr.constr option -> EConstr.constr
end
(** Coq positive numbers (pos) *)
module Pos:
sig
- val typ:Term.constr lazy_t
- val of_int: int ->Term.constr
+ val typ:EConstr.constr lazy_t
+ val of_int: int ->EConstr.constr
end
(** Coq unary numbers (peano) *)
module Nat:
sig
- val typ:Term.constr lazy_t
- val of_int: int ->Term.constr
+ val typ:EConstr.constr lazy_t
+ val of_int: int ->EConstr.constr
end
(** Coq typeclasses *)
module Classes:
sig
- val mk_morphism: Term.constr -> Term.constr -> Term.constr -> Term.constr
- val mk_equivalence: Term.constr -> Term.constr -> Term.constr
- val mk_reflexive: Term.constr -> Term.constr -> Term.constr
- val mk_transitive: Term.constr -> Term.constr -> Term.constr
+ val mk_morphism: EConstr.constr -> EConstr.constr -> EConstr.constr -> EConstr.constr
+ val mk_equivalence: EConstr.constr -> EConstr.constr -> EConstr.constr
+ val mk_reflexive: EConstr.constr -> EConstr.constr -> EConstr.constr
+ val mk_transitive: EConstr.constr -> EConstr.constr -> EConstr.constr
end
module Relation : sig
- type t = {carrier : Term.constr; r : Term.constr;}
- val make : Term.constr -> Term.constr -> t
- val split : t -> Term.constr * Term.constr
+ type t = {carrier : EConstr.constr; r : EConstr.constr;}
+ val make : EConstr.constr -> EConstr.constr -> t
+ val split : t -> EConstr.constr * EConstr.constr
end
module Transitive : sig
type t =
{
- carrier : Term.constr;
- leq : Term.constr;
- transitive : Term.constr;
+ carrier : EConstr.constr;
+ leq : EConstr.constr;
+ transitive : EConstr.constr;
}
- val make : Term.constr -> Term.constr -> Term.constr -> t
- val infer : goal_sigma -> Term.constr -> Term.constr -> t * goal_sigma
+ val make : EConstr.constr -> EConstr.constr -> EConstr.constr -> t
+ val infer : goal_sigma -> EConstr.constr -> EConstr.constr -> t * goal_sigma
val from_relation : goal_sigma -> Relation.t -> t * goal_sigma
val cps_from_relation : Relation.t -> (t -> Proof_type.tactic) -> Proof_type.tactic
val to_relation : t -> Relation.t
@@ -134,22 +134,22 @@ end
module Equivalence : sig
type t =
{
- carrier : Term.constr;
- eq : Term.constr;
- equivalence : Term.constr;
+ carrier : EConstr.constr;
+ eq : EConstr.constr;
+ equivalence : EConstr.constr;
}
- val make : Term.constr -> Term.constr -> Term.constr -> t
- val infer : goal_sigma -> Term.constr -> Term.constr -> t * goal_sigma
+ val make : EConstr.constr -> EConstr.constr -> EConstr.constr -> t
+ val infer : goal_sigma -> EConstr.constr -> EConstr.constr -> t * goal_sigma
val from_relation : goal_sigma -> Relation.t -> t * goal_sigma
val cps_from_relation : Relation.t -> (t -> Proof_type.tactic) -> Proof_type.tactic
val to_relation : t -> Relation.t
- val split : t -> Term.constr * Term.constr * Term.constr
+ val split : t -> EConstr.constr * EConstr.constr * EConstr.constr
end
(** [match_as_equation ?context goal c] try to decompose c as a
relation applied to two terms. An optionnal rel-context can be
provided to ensure that the term remains typable *)
-val match_as_equation : ?context:Context.Rel.t -> goal_sigma -> Term.constr -> (Term.constr * Term.constr * Relation.t) option
+val match_as_equation : ?context:EConstr.rel_context -> goal_sigma -> EConstr.constr -> (EConstr.constr * EConstr.constr * Relation.t) option
(** {2 Some tacticials} *)
@@ -166,7 +166,7 @@ val tclPRINT : Proof_type.tactic -> Proof_type.tactic
(** {2 Error related mechanisms} *)
val anomaly : string -> 'a
-val user_error : string -> 'a
+val user_error : Pp.t -> 'a
val warning : string -> unit
@@ -188,13 +188,13 @@ module Rewrite : sig
*)
type hypinfo =
{
- hyp : Term.constr; (** the actual constr corresponding to the hypothese *)
- hyptype : Term.constr; (** the type of the hypothesis *)
- context : Context.Rel.t; (** the quantifications of the hypothese *)
- body : Term.constr; (** the body of the hypothese*)
+ hyp : EConstr.constr; (** the actual constr corresponding to the hypothese *)
+ hyptype : EConstr.constr; (** the type of the hypothesis *)
+ context : EConstr.rel_context; (** the quantifications of the hypothese *)
+ body : EConstr.constr; (** the body of the hypothese*)
rel : Relation.t; (** the relation *)
- left : Term.constr; (** left hand side *)
- right : Term.constr; (** right hand side *)
+ left : EConstr.constr; (** left hand side *)
+ right : EConstr.constr; (** right hand side *)
l2r : bool; (** rewriting from left to right *)
}
@@ -202,7 +202,7 @@ type hypinfo =
build the related hypinfo, in CPS style. Moreover, an optionnal
function can be provided to check the type of every free
variable of the body of the hypothesis. *)
-val get_hypinfo :Term.constr -> l2r:bool -> ?check_type:(Term.types -> bool) -> (hypinfo -> Proof_type.tactic) -> Proof_type.tactic
+val get_hypinfo :EConstr.constr -> l2r:bool -> ?check_type:(EConstr.types -> bool) -> (hypinfo -> Proof_type.tactic) -> Proof_type.tactic
(** {2 Rewriting with bindings}
@@ -219,14 +219,14 @@ val get_hypinfo :Term.constr -> l2r:bool -> ?check_type:(Term.types -> bool) ->
*)
(** build the constr to rewrite, in CPS style, with lambda abstractions *)
-val build : hypinfo -> (int * Term.constr) list -> (Term.constr -> Proof_type.tactic) -> Proof_type.tactic
+val build : hypinfo -> (int * EConstr.constr) list -> (EConstr.constr -> Proof_type.tactic) -> Proof_type.tactic
(** build the constr to rewrite, in CPS style, with evars *)
-val build_with_evar : hypinfo -> (int * Term.constr) list -> (Term.constr -> Proof_type.tactic) -> Proof_type.tactic
+val build_with_evar : hypinfo -> (int * EConstr.constr) list -> (EConstr.constr -> Proof_type.tactic) -> Proof_type.tactic
(** [rewrite ?abort hypinfo subst] builds the rewriting tactic
associated with the given [subst] and [hypinfo], and feeds it to
the given continuation. If [abort] is set to [true], we build
[tclIDTAC] instead. *)
-val rewrite : ?abort:bool -> hypinfo -> (int * Term.constr) list -> (Proof_type.tactic -> Proof_type.tactic) -> Proof_type.tactic
+val rewrite : ?abort:bool -> hypinfo -> (int * EConstr.constr) list -> (Proof_type.tactic -> Proof_type.tactic) -> Proof_type.tactic
end
diff --git a/helper.ml b/src/helper.ml
index 636b17f..c1cae2a 100644
--- a/helper.ml
+++ b/src/helper.ml
@@ -27,10 +27,10 @@ module Debug (X : CONTROL) = struct
r
else f x
- let pr_constr msg constr =
+ let pr_constr env evd msg constr =
if printing then
( Feedback.msg_notice (Pp.str (Printf.sprintf "=====%s====" msg));
- Feedback.msg_notice (Printer.pr_constr constr);
+ Feedback.msg_notice (Printer.pr_econstr_env env evd constr);
)
diff --git a/helper.mli b/src/helper.mli
index f4e4454..400e847 100644
--- a/helper.mli
+++ b/src/helper.mli
@@ -28,6 +28,6 @@ sig
(** {!pr_constr} print a Coq constructor, that can be labelled
by a string *)
- val pr_constr : string -> Term.constr -> unit
+ val pr_constr : Environ.env -> Evd.evar_map -> string -> EConstr.constr -> unit
end
diff --git a/matcher.ml b/src/matcher.ml
index 1dcb1d2..cc66961 100644
--- a/matcher.ml
+++ b/src/matcher.ml
@@ -255,7 +255,7 @@ end
(** This function has to deal with the arities *)
- let rec merge (l : nf_term mset) (l' : nf_term mset) : nf_term mset=
+ let merge (l : nf_term mset) (l' : nf_term mset) : nf_term mset=
merge_ac nf_term_compare l l'
let extract_A units s t =
@@ -349,7 +349,7 @@ end
(** {2 Conversion functions} *)
(* rebuilds a tree out of a list, under the assumption that the list is not empty *)
- let rec binary_of_list f comb l =
+ let binary_of_list f comb l =
let l = List.rev l in
let rec aux = function
| [] -> assert false
@@ -455,7 +455,7 @@ end
| Dot (s,l,r) -> Dot (s, aux l, aux r)
| Var i ->
begin match find t i with
- | None -> CErrors.error "aac_tactics: instantiate failure"
+ | None -> CErrors.user_err (Pp.strbrk "aac_tactics: instantiate failure")
| Some x -> t_of_term x
end
in aux x
@@ -1094,7 +1094,7 @@ let unit_warning p ~nullif ~unitif =
begin
Feedback.msg_warning
(Pp.str
- "[aac_tactics] This pattern can be instanciated to match units, some solutions can be missing");
+ "[aac_tactics] This pattern can be instantiated to match units, some solutions can be missing");
end
;;
@@ -1127,7 +1127,7 @@ let unit_warning p ~nullif ~unitif =
pattern uninstantiated. We do so in order to allow interaction
with the user, to choose the env.
- Strange patterms like x*y*x can be instanciated by nothing, inside
+ Strange patterms like x*y*x can be instantiated by nothing, inside
a product. Therefore, we need to check that all the term is not
going into the context. With proper support for interaction with
the user, we should lift these tests. However, at the moment, they
diff --git a/matcher.mli b/src/matcher.mli
index a6b6f46..a6b6f46 100644
--- a/matcher.mli
+++ b/src/matcher.mli
diff --git a/print.ml b/src/print.ml
index 427b6dc..6800200 100644
--- a/print.ml
+++ b/src/print.ml
@@ -11,18 +11,19 @@
open Pp
open Matcher
open Context.Rel.Declaration
+open Names
-type named_env = (Names.name * Terms.t) list
+type named_env = (Name.t * Terms.t) list
(** {pp_env} prints a substitution mapping names to terms, using the
provided printer *)
-let pp_env pt : named_env -> Pp.std_ppcmds = fun env ->
+let pp_env pt : named_env -> Pp.t = fun env ->
List.fold_left
(fun acc (v,t) ->
begin match v with
- | Names.Name s -> str (Printf.sprintf "%s: " (Names.string_of_id s))
+ | Names.Name s -> str (Printf.sprintf "%s: " (Id.to_string s))
| Names.Anonymous -> str ("_")
end
++ pt t ++ str "; " ++ acc
@@ -33,7 +34,7 @@ let pp_env pt : named_env -> Pp.std_ppcmds = fun env ->
(** {pp_envm} prints a collection of possible environments, and number
them. This number must remain compatible with the parameters given to
{!aac_rewrite} *)
-let pp_envm pt : named_env Search_monad.m -> Pp.std_ppcmds = fun m ->
+let pp_envm pt : named_env Search_monad.m -> Pp.t = fun m ->
let _,s =
Search_monad.fold
(fun env (n,acc) ->
@@ -50,10 +51,10 @@ let trivial_substitution envm =
(** {pp_all} prints a collection of possible contexts and related
possibles substitutions, giving a number to each. This number must
remain compatible with the parameters of {!aac_rewrite} *)
-let pp_all pt : (int * Terms.t * named_env Search_monad.m) Search_monad.m -> Pp.std_ppcmds = fun m ->
+let pp_all pt : (int * Terms.t * named_env Search_monad.m) Search_monad.m -> Pp.t = fun m ->
let _,s = Search_monad.fold
(fun (size,context,envm) (n,acc) ->
- let s = str (Printf.sprintf "occurence %i: transitivity through " n) in
+ let s = str (Printf.sprintf "occurrence %i: transitivity through " n) in
let s = s ++ pt context ++ str "\n" in
let s = if trivial_substitution envm then s else
s ++ str (Printf.sprintf "%i possible(s) substitution(s)" (Search_monad.count envm) )
@@ -67,7 +68,7 @@ let pp_all pt : (int * Terms.t * named_env Search_monad.m) Search_monad.m -> Pp.
rename the variables, and rebuilds raw Coq terms (for the context, and
the terms in the environment). In order to do so, it requires the
information gathered by the {!Theory.Trans} module.*)
-let print rlt ir m (context : Context.Rel.t) goal =
+let print rlt ir m (context : EConstr.rel_context) goal =
if Search_monad.count m = 0
then
(
@@ -92,9 +93,11 @@ let print rlt ir m (context : Context.Rel.t) goal =
)
in
let m = Search_monad.sort (fun (x,_,_) (y,_,_) -> x - y) m in
+ let env = Tacmach.pf_env goal in
+ let sigma = Tacmach.project goal in
let _ = Feedback.msg_notice
(pp_all
- (fun t -> Printer.pr_constr (Theory.Trans.raw_constr_of_t ir rlt context t) ) m
+ (fun t -> Printer.pr_letype_env env sigma (Theory.Trans.raw_constr_of_t ir rlt context t)) m
)
in
Tacticals.tclIDTAC goal
diff --git a/print.mli b/src/print.mli
index bbb9b20..5ca6e27 100644
--- a/print.mli
+++ b/src/print.mli
@@ -18,6 +18,6 @@ val print :
Coq.Relation.t ->
Theory.Trans.ir ->
(int * Matcher.Terms.t * Matcher.Subst.t Search_monad.m) Search_monad.m ->
- Context.Rel.t ->
+ EConstr.rel_context ->
Proof_type.tactic
diff --git a/search_monad.ml b/src/search_monad.ml
index 09a6455..09a6455 100644
--- a/search_monad.ml
+++ b/src/search_monad.ml
diff --git a/search_monad.mli b/src/search_monad.mli
index 7e2a910..7e2a910 100644
--- a/search_monad.mli
+++ b/src/search_monad.mli
diff --git a/theory.ml b/src/theory.ml
index 20cb299..7871fe4 100644
--- a/theory.ml
+++ b/src/theory.ml
@@ -9,11 +9,10 @@
(** Constr from the theory of this particular development
The inner-working of this module is highly correlated with the
- particular structure of {b AAC.v}, therefore, it should
+ particular structure of {b AAC_rewrite.v}, therefore, it should
be of little interest to most readers.
*)
-open Term
-open Context
+open EConstr
module Control = struct
let printing = true
@@ -31,6 +30,7 @@ open Debug
module HMap = Hashtbl.Make(Constr)
let ac_theory_path = ["AAC_tactics"; "AAC"]
+let ac_util_path = ["AAC_tactics"; "Utils"]
module Stubs = struct
let path = ac_theory_path@["Internal"]
@@ -68,7 +68,7 @@ module Classes = struct
module Associative = struct
let path = ac_theory_path
let typ = lazy (Coq.init_constant path "Associative")
- let ty (rlt : Coq.Relation.t) (value : Term.constr) =
+ let ty (rlt : Coq.Relation.t) (value : constr) =
mkApp (Lazy.force typ, [| rlt.Coq.Relation.carrier;
rlt.Coq.Relation.r;
value
@@ -81,7 +81,7 @@ module Classes = struct
module Commutative = struct
let path = ac_theory_path
let typ = lazy (Coq.init_constant path "Commutative")
- let ty (rlt : Coq.Relation.t) (value : Term.constr) =
+ let ty (rlt : Coq.Relation.t) (value : constr) =
mkApp (Lazy.force typ, [| rlt.Coq.Relation.carrier;
rlt.Coq.Relation.r;
value
@@ -112,7 +112,7 @@ module Classes = struct
module Unit = struct
let path = ac_theory_path
let typ = lazy (Coq.init_constant path "Unit")
- let ty (rlt : Coq.Relation.t) (value : Term.constr) (unit : Term.constr)=
+ let ty (rlt : Coq.Relation.t) (value : constr) (unit : constr)=
mkApp (Lazy.force typ, [| rlt.Coq.Relation.carrier;
rlt.Coq.Relation.r;
value;
@@ -124,7 +124,7 @@ end
(* Non empty lists *)
module NEList = struct
- let path = ac_theory_path @ ["Internal"]
+ let path = ac_util_path
let typ = lazy (Coq.init_constant path "list")
let nil = lazy (Coq.init_constant path "nil")
let cons = lazy (Coq.init_constant path "cons")
@@ -189,7 +189,7 @@ end
module Sym = struct
- type pack = {ar: Term.constr; value: Term.constr ; morph: Term.constr}
+ type pack = {ar: Constr.t; value: Constr.t ; morph: Constr.t}
let path = ac_theory_path @ ["Internal";"Sym"]
let typ = lazy (Coq.init_constant path "pack")
let mkPack = lazy (Coq.init_constant path "mkPack")
@@ -197,7 +197,7 @@ module Sym = struct
let null = lazy (Coq.init_constant path "null")
let mk_pack (rlt: Coq.Relation.t) s =
let (x,r) = Coq.Relation.split rlt in
- mkApp (Lazy.force mkPack, [|x;r; s.ar;s.value;s.morph|])
+ mkApp (Lazy.force mkPack, [|x;r; EConstr.of_constr s.ar;EConstr.of_constr s.value;EConstr.of_constr s.morph|])
let null rlt =
let x = rlt.Coq.Relation.carrier in
let r = rlt.Coq.Relation.r in
@@ -209,24 +209,24 @@ module Sym = struct
end
module Bin =struct
- type pack = {value : Term.constr;
- compat : Term.constr;
- assoc : Term.constr;
- comm : Term.constr option;
+ type pack = {value : Constr.t;
+ compat : Constr.t;
+ assoc : Constr.t;
+ comm : Constr.t option;
}
let path = ac_theory_path @ ["Internal";"Bin"]
let typ = lazy (Coq.init_constant path "pack")
let mkPack = lazy (Coq.init_constant path "mk_pack")
- let mk_pack: Coq.Relation.t -> pack -> Term.constr = fun (rlt) s ->
+ let mk_pack: Coq.Relation.t -> pack -> constr = fun (rlt) s ->
let (x,r) = Coq.Relation.split rlt in
- let comm_ty = Classes.Commutative.ty rlt s.value in
+ let comm_ty = Classes.Commutative.ty rlt (EConstr.of_constr s.value) in
mkApp (Lazy.force mkPack , [| x ; r;
- s.value;
- s.compat ;
- s.assoc;
- Coq.Option.of_option comm_ty s.comm
+ EConstr.of_constr s.value;
+ EConstr.of_constr s.compat ;
+ EConstr.of_constr s.assoc;
+ Coq.Option.of_option comm_ty (Option.map EConstr.of_constr s.comm)
|])
let mk_ty : Coq.Relation.t -> constr = fun rlt ->
let (x,r) = Coq.Relation.split rlt in
@@ -242,13 +242,13 @@ module Unit = struct
type unit_of =
{
- uf_u : Term.constr; (* u *)
- uf_idx : Term.constr;
- uf_desc : Term.constr; (* Unit R (e_bin uf_idx) u *)
+ uf_u : Constr.t; (* u *)
+ uf_idx : Constr.t;
+ uf_desc : Constr.t; (* Unit R (e_bin uf_idx) u *)
}
type pack = {
- u_value : Term.constr; (* X *)
+ u_value : constr; (* X *)
u_desc : (unit_of) list (* unit_of u_value *)
}
@@ -266,11 +266,11 @@ module Unit = struct
r;
e_bin ;
u;
- unit_of.uf_idx;
- unit_of.uf_desc
+ EConstr.of_constr unit_of.uf_idx;
+ EConstr.of_constr unit_of.uf_desc
|])
- let mk_pack rlt e_bin pack : Term.constr =
+ let mk_pack rlt e_bin pack : constr =
let (x,r) = Coq.Relation.split rlt in
let ty = ty_unit_of rlt e_bin pack.u_value in
let mk_unit_of = mk_unit_of rlt e_bin pack.u_value in
@@ -292,7 +292,7 @@ let anomaly msg =
CErrors.anomaly ~label:"aac_tactics" (Pp.str msg)
let user_error msg =
- CErrors.error ("aac_tactics: " ^ msg)
+ CErrors.user_err Pp.(strbrk "aac_tactics: " ++ msg)
module Trans = struct
@@ -321,7 +321,7 @@ module Trans = struct
| Bin of Bin.pack with_unit
(* will only be used in the second pass : {!Parse}*)
| Sym of Sym.pack
- | Unit of constr (* to avoid confusion in bloom *)
+ | Unit of Constr.t (* to avoid confusion in bloom *)
module PackHash =
struct
@@ -381,7 +381,7 @@ module Trans = struct
module PackTable = Hashtbl.Make(PackHash)
- (** discr is a map from {!Term.constr} to {!pack}.
+ (** discr is a map from {!constr} to {!pack}.
[None] means that it is not possible to instantiate this partial
application to an interesting class.
@@ -423,9 +423,9 @@ module Trans = struct
try PackTable.find envs.bloom pack
with Not_found -> assert false
- (********************************************)
- (* (\* Gather the occuring AC/A symbols *\) *)
- (********************************************)
+ (*********************************************)
+ (* (\* Gather the occurring AC/A symbols *\) *)
+ (*********************************************)
(** This modules exhibit a function that memoize in the environment
all the AC/A operators as well as the morphism that occur. This
@@ -438,7 +438,7 @@ module Trans = struct
units. Otherwise, we do not have the ability to rewrite [0 = a +
a] in [a = ...]*)
module Gather : sig
- val gather : Coq.goal_sigma -> Coq.Relation.t -> envs -> Term.constr -> Coq.goal_sigma
+ val gather : Coq.goal_sigma -> Coq.Relation.t -> envs -> constr -> Coq.goal_sigma
end
= struct
@@ -492,10 +492,10 @@ module Trans = struct
None, goal
in
let bin =
- {Bin.value = op;
- Bin.compat = proper;
- Bin.assoc = assoc;
- Bin.comm = comm }
+ {Bin.value = EConstr.to_constr (Tacmach.project goal) op;
+ Bin.compat = EConstr.to_constr (Tacmach.project goal) proper;
+ Bin.assoc = EConstr.to_constr (Tacmach.project goal) assoc;
+ Bin.comm = Option.map (EConstr.to_constr (Tacmach.project goal)) comm }
in
Some (goal,bin)
with |Not_found -> None
@@ -509,25 +509,27 @@ module Trans = struct
| Some (gl, unit,s) ->
let unit_of =
{
- Unit.uf_u = unit;
+ Unit.uf_u = EConstr.to_constr (Tacmach.project goal) unit;
(* TRICK : this term is not well-typed by itself,
but it is okay the way we use it in the other
functions *)
- Unit.uf_idx = op;
- Unit.uf_desc = s;
+ Unit.uf_idx = EConstr.to_constr (Tacmach.project goal) op;
+ Unit.uf_desc = EConstr.to_constr (Tacmach.project goal) s;
}
in Some (gl,Bin (bin_pack, Some (unit_of)))
(** {is_morphism} try to infer the kind of operator we are
dealing with *)
- let is_morphism goal (rlt : Coq.Relation.t) (papp : Term.constr) (ar : int) : (Coq.goal_sigma * pack ) option =
+ let is_morphism goal (rlt : Coq.Relation.t) (papp : constr) (ar : int) : (Coq.goal_sigma * pack ) option =
let typeof = Classes.Proper.mk_typeof rlt ar in
let relof = Classes.Proper.mk_relof rlt ar in
let m = Coq.Classes.mk_morphism typeof relof papp in
try
let m,goal = Coq.resolve_one_typeclass goal m in
- let pack = {Sym.ar = (Coq.Nat.of_int ar); Sym.value= papp; Sym.morph= m} in
+ let pack = {Sym.ar = EConstr.to_constr (Tacmach.project goal) (Coq.Nat.of_int ar);
+ Sym.value= EConstr.to_constr (Tacmach.project goal) papp;
+ Sym.morph= EConstr.to_constr (Tacmach.project goal) m} in
Some (goal, Sym pack)
with
| Not_found -> None
@@ -541,7 +543,7 @@ module Trans = struct
if n <= 1
then None
else
- let papp = Term.mkApp (t, Array.sub ca 0 (n-2) ) in
+ let papp = mkApp (t, Array.sub ca 0 (n-2) ) in
let args = Array.sub ca (n-2) 2 in
Some (papp, args )
@@ -550,16 +552,16 @@ module Trans = struct
let nb_params = Array.length ca in
let rec aux n =
assert (n < nb_params && 0 < nb_params );
- let papp = Term.mkApp (t, Array.sub ca 0 n) in
+ let papp = mkApp (t, Array.sub ca 0 n) in
match is_morphism goal rlt papp (nb_params - n) with
| None ->
(* here we have to memoize the failures *)
- HMap.add envs.discr papp None;
+ HMap.add envs.discr (EConstr.to_constr (Tacmach.project goal) papp) None;
if n < nb_params - 1 then aux (n+1) else goal
| Some (goal, pack) ->
let args = Array.sub ca (n) (nb_params -n)in
let goal = Array.fold_left cont goal args in
- memoize envs papp pack;
+ memoize envs (EConstr.to_constr (Tacmach.project goal) papp) pack;
goal
in
if nb_params = 0 then goal else aux 0
@@ -572,7 +574,7 @@ module Trans = struct
begin match is_aac papp goal with
| None -> fold_morphism t ca
| Some (goal, pack) ->
- memoize envs papp pack;
+ memoize envs (EConstr.to_constr (Tacmach.project goal) papp) pack;
Array.fold_left cont goal args
end
@@ -580,8 +582,8 @@ module Trans = struct
have to memoize failures, here. *)
let gather goal (rlt : Coq.Relation.t ) envs t : Coq.goal_sigma =
let rec aux goal x =
- match Coq.decomp_term x with
- | App (t,ca) ->
+ match Coq.decomp_term (Tacmach.project goal) x with
+ | Constr.App (t,ca) ->
fold goal rlt envs t ca (aux )
| _ -> goal
in
@@ -614,13 +616,15 @@ module Trans = struct
This functions is prevented to go through [ar < 0] by the fact
that a constant is a morphism. But not an eva. *)
- let is_morphism goal (rlt : Coq.Relation.t) (papp : Term.constr) (ar : int) : (Coq.goal_sigma * pack ) option =
+ let is_morphism goal (rlt : Coq.Relation.t) (papp : constr) (ar : int) : (Coq.goal_sigma * pack ) option =
let typeof = Classes.Proper.mk_typeof rlt ar in
let relof = Classes.Proper.mk_relof rlt ar in
let m = Coq.Classes.mk_morphism typeof relof papp in
try
let m,goal = Coq.resolve_one_typeclass goal m in
- let pack = {Sym.ar = (Coq.Nat.of_int ar); Sym.value= papp; Sym.morph= m} in
+ let pack = {Sym.ar = EConstr.to_constr ~abort_on_undefined_evars:(false)(Tacmach.project goal) (Coq.Nat.of_int ar);
+ Sym.value= EConstr.to_constr ~abort_on_undefined_evars:(false)(Tacmach.project goal) papp;
+ Sym.morph= EConstr.to_constr ~abort_on_undefined_evars:(false)(Tacmach.project goal) m} in
Some (goal, Sym pack)
with
| e -> None
@@ -634,7 +638,7 @@ module Trans = struct
let p_app = mkApp (t, Array.sub ca 0 (nb_params - ar)) in
begin
try
- begin match HMap.find envs.discr p_app with
+ begin match HMap.find envs.discr (EConstr.to_constr ~abort_on_undefined_evars:(false) (Tacmach.project goal) p_app) with
| None ->
fold goal (ar-1)
| Some pack ->
@@ -649,7 +653,7 @@ module Trans = struct
assert (0 <= ar && ar <= nb_params);
match x with
| Some (goal, pack) ->
- HMap.add envs.discr p_app (Some pack);
+ HMap.add envs.discr (EConstr.to_constr ~abort_on_undefined_evars:(false) (Tacmach.project goal) p_app) (Some pack);
add_bloom envs pack;
(goal, pack, p_app, Array.sub ca (nb_params-ar) ar)
| None ->
@@ -657,29 +661,29 @@ module Trans = struct
if ar = 0 then raise NotReflexive;
begin
(* to memoise the failures *)
- HMap.add envs.discr p_app None;
+ HMap.add envs.discr (EConstr.to_constr ~abort_on_undefined_evars:(false) (Tacmach.project goal) p_app) None;
(* will terminate, since [const] is capped, and it is
easy to find an instance of a constant *)
fold goal (ar-1)
end
in
- try match HMap.find envs.discr (mkApp (t,ca))with
+ try match HMap.find envs.discr (EConstr.to_constr ~abort_on_undefined_evars:(false) (Tacmach.project goal) (mkApp (t,ca))) with
| None -> fold goal (nb_params)
| Some pack -> goal, pack, (mkApp (t,ca)), [| |]
with Not_found -> fold goal (nb_params)
let discriminate goal envs rlt x =
try
- match Coq.decomp_term x with
- | App (t,ca) ->
+ match Coq.decomp_term (Tacmach.project goal) x with
+ | Constr.App (t,ca) ->
discriminate goal envs rlt t ca
| _ -> discriminate goal envs rlt x [| |]
with
- | NotReflexive -> user_error "The relation to which the goal was lifted is not Reflexive"
+ | NotReflexive -> user_error @@ Pp.strbrk "The relation to which the goal was lifted is not Reflexive"
(* TODO: is it the only source of invalid use that fall
into this catch_all ? *)
| e ->
- user_error "Cannot handle this kind of hypotheses (variables occuring under a function symbol which is not a proper morphism)."
+ user_error @@ Pp.strbrk "Cannot handle this kind of hypotheses (variables occurring under a function symbol which is not a proper morphism)."
(** [t_of_constr goal rlt envs cstr] builds the abstract syntax tree
of the term [cstr]. Doing so, it modifies the environment of
@@ -688,8 +692,8 @@ module Trans = struct
let t_of_constr goal (rlt: Coq.Relation.t ) envs : constr -> Matcher.Terms.t * Coq.goal_sigma =
let r_goal = ref (goal) in
let rec aux x =
- match Coq.decomp_term x with
- | Rel i -> Matcher.Terms.Var i
+ match Coq.decomp_term (Tacmach.project goal) x with
+ | Constr.Rel i -> Matcher.Terms.Var i
| _ ->
let goal, pack , p_app, ca = discriminate (!r_goal) envs rlt x in
r_goal := goal;
@@ -718,7 +722,7 @@ module Trans = struct
end (* Parse *)
let add_symbol goal rlt envs l =
- let goal = Gather.gather goal rlt envs (Term.mkApp (l, [| Term.mkRel 0;Term.mkRel 0|])) in
+ let goal = Gather.gather goal rlt envs (EConstr.of_constr (Constr.mkApp (l, [| Constr.mkRel 0;Constr.mkRel 0|]))) in
goal
(* [t_of_constr] buils a the abstract syntax tree of a constr,
@@ -740,7 +744,7 @@ module Trans = struct
packer : (int, pack) Hashtbl.t; (* = bloom_back *)
bin : (int * Bin.pack) list ;
units : (int * Unit.pack) list;
- sym : (int * Term.constr) list ;
+ sym : (int * constr) list ;
matcher_units : Matcher.ext_units
}
@@ -751,7 +755,7 @@ module Trans = struct
let nil = [] in
let sym ,
(bin : (int * Bin.pack with_unit) list),
- (units : (int * constr) list) =
+ (units : (int * Constr.t) list) =
Hashtbl.fold
(fun int pack (sym,bin,units) ->
match pack with
@@ -797,14 +801,14 @@ module Trans = struct
if Constr.equal (unit_of.Unit.uf_u) u
then
{unit_of with
- Unit.uf_idx = (Coq.Pos.of_int nop)} :: acc
+ Unit.uf_idx = EConstr.to_constr (Tacmach.project goal) (Coq.Pos.of_int nop)} :: acc
else
acc
)
[] bin
in
(n,{
- Unit.u_value = u;
+ Unit.u_value = EConstr.of_constr u;
Unit.u_desc = all_bin
})::acc
)
@@ -831,7 +835,7 @@ module Trans = struct
(** [raw_constr_of_t_debruijn] rebuilds a term in the raw
representation, without products on top, and maybe escaping free
debruijn indices (in the case of a pattern for example). *)
- let raw_constr_of_t_debruijn ir (t : Matcher.Terms.t) : Term.constr * int list =
+ let raw_constr_of_t_debruijn ir (t : Matcher.Terms.t) : constr * int list =
let add_set,get =
let r = ref [] in
let rec add x = function
@@ -849,25 +853,25 @@ module Trans = struct
| Matcher.Terms.Plus (s,l,r) ->
begin match Hashtbl.find ir.packer s with
| Bin (s,_) ->
- mkApp (s.Bin.value , [|(aux l);(aux r)|])
+ mkApp (EConstr.of_constr s.Bin.value , [|(aux l);(aux r)|])
| _ -> Printf.printf "erreur:%i\n%!"s;
assert false
end
| Matcher.Terms.Dot (s,l,r) ->
begin match Hashtbl.find ir.packer s with
| Bin (s,_) ->
- mkApp (s.Bin.value, [|(aux l);(aux r)|])
+ mkApp (EConstr.of_constr s.Bin.value, [|(aux l);(aux r)|])
| _ -> assert false
end
| Matcher.Terms.Sym (s,t) ->
begin match Hashtbl.find ir.packer s with
| Sym s ->
- mkApp (s.Sym.value, Array.map aux t)
+ mkApp (EConstr.of_constr s.Sym.value, Array.map aux t)
| _ -> assert false
end
| Matcher.Terms.Unit x ->
begin match Hashtbl.find ir.packer x with
- | Unit s -> s
+ | Unit s -> EConstr.of_constr s
| _ -> assert false
end
| Matcher.Terms.Var i -> add_set i;
@@ -877,7 +881,7 @@ module Trans = struct
t , get ( )
(** [raw_constr_of_t] rebuilds a term in the raw representation *)
- let raw_constr_of_t ir rlt (context:Context.Rel.t) t =
+ let raw_constr_of_t ir rlt (context:rel_context) t =
(** cap rebuilds the products in front of the constr *)
let rec cap c = function [] -> c
| t::q ->
@@ -906,16 +910,16 @@ module Trans = struct
from the symbols (as ints) to indexes (as constr) *)
type sigmas = {
- env_sym : Term.constr;
- env_bin : Term.constr;
- env_units : Term.constr; (* the [idx -> X:constr] *)
+ env_sym : constr;
+ env_bin : constr;
+ env_units : constr; (* the [idx -> X:constr] *)
}
type sigma_maps = {
- sym_to_pos : int -> Term.constr;
- bin_to_pos : int -> Term.constr;
- units_to_pos : int -> Term.constr;
+ sym_to_pos : int -> constr;
+ bin_to_pos : int -> constr;
+ units_to_pos : int -> constr;
}
@@ -935,12 +939,12 @@ module Trans = struct
let compat,goal = Classes.Proper.infer goal rlt op 2 in
let op = Coq.nf_evar goal op in
{
- Bin.value = op;
- Bin.compat = compat;
- Bin.assoc = assoc;
+ Bin.value = EConstr.to_constr (Tacmach.project goal) op;
+ Bin.compat = EConstr.to_constr (Tacmach.project goal) compat;
+ Bin.assoc = EConstr.to_constr (Tacmach.project goal) assoc;
Bin.comm = None
}
- with Not_found -> user_error "Cannot infer a default A operator (required at least to be Proper and Associative)"
+ with Not_found -> user_error @@ Pp.strbrk "Cannot infer a default A operator (required at least to be Proper and Associative)"
in
let zero, goal =
try
diff --git a/theory.mli b/src/theory.mli
index fe79a11..e7bfbfe 100644
--- a/theory.mli
+++ b/src/theory.mli
@@ -10,14 +10,14 @@
reification and translation functions.
Note: this module is highly correlated with the definitions of {i
- AAC.v}.
+ AAC_rewrite.v}.
This module interfaces with the above Coq module; it provides
facilities to interpret a term with arbitrary operators as an
abstract syntax tree, and to convert an AST into a Coq term
(either using the Coq "raw" terms, as written in the starting
goal, or using the reified Coq datatypes we define in {i
- AAC.v}).
+ AAC_rewrite.v}).
*)
(** Both in OCaml and Coq, we represent finite multisets using
@@ -26,7 +26,7 @@
[mk_mset ty l] constructs a Coq multiset from an OCaml multiset
[l] of Coq terms of type [ty] *)
-val mk_mset:Term.constr -> (Term.constr * int) list ->Term.constr
+val mk_mset:EConstr.constr -> (EConstr.constr * int) list ->EConstr.constr
(** {2 Packaging modules} *)
@@ -34,16 +34,16 @@ val mk_mset:Term.constr -> (Term.constr * int) list ->Term.constr
module Sigma:
sig
(** [add ty n x map] adds the value [x] of type [ty] with key [n] in [map] *)
- val add: Term.constr ->Term.constr ->Term.constr ->Term.constr ->Term.constr
+ val add: EConstr.constr ->EConstr.constr ->EConstr.constr ->EConstr.constr ->EConstr.constr
(** [empty ty] create an empty map of type [ty] *)
- val empty: Term.constr ->Term.constr
+ val empty: EConstr.constr ->EConstr.constr
(** [of_list ty null l] translates an OCaml association list into a Coq one *)
- val of_list: Term.constr -> Term.constr -> (int * Term.constr ) list -> Term.constr
+ val of_list: EConstr.constr -> EConstr.constr -> (int * EConstr.constr ) list -> EConstr.constr
(** [to_fun ty null map] converts a Coq association list into a Coq function (with default value [null]) *)
- val to_fun: Term.constr ->Term.constr ->Term.constr ->Term.constr
+ val to_fun: EConstr.constr ->EConstr.constr ->EConstr.constr ->EConstr.constr
end
@@ -51,16 +51,16 @@ end
module Sym:
sig
(** mimics the Coq record [Sym.pack] *)
- type pack = {ar: Term.constr; value: Term.constr ; morph: Term.constr}
+ type pack = {ar: Constr.t; value: Constr.t ; morph: Constr.t}
- val typ: Term.constr lazy_t
+ val typ: EConstr.constr lazy_t
(** [mk_pack rlt (ar,value,morph)] *)
- val mk_pack: Coq.Relation.t -> pack -> Term.constr
+ val mk_pack: Coq.Relation.t -> pack -> EConstr.constr
(** [null] builds a dummy (identity) symbol, given an {!Coq.Relation.t} *)
- val null: Coq.Relation.t -> Term.constr
+ val null: Coq.Relation.t -> EConstr.constr
end
@@ -68,20 +68,20 @@ end
(** We need to export some Coq stubs out of this module. They are used
by the main tactic, see {!Rewrite} *)
module Stubs : sig
- val lift : Term.constr Lazy.t
- val lift_proj_equivalence : Term.constr Lazy.t
- val lift_transitivity_left : Term.constr Lazy.t
- val lift_transitivity_right : Term.constr Lazy.t
- val lift_reflexivity : Term.constr Lazy.t
+ val lift : EConstr.constr Lazy.t
+ val lift_proj_equivalence : EConstr.constr Lazy.t
+ val lift_transitivity_left : EConstr.constr Lazy.t
+ val lift_transitivity_right : EConstr.constr Lazy.t
+ val lift_reflexivity : EConstr.constr Lazy.t
(** The evaluation fonction, used to convert a reified coq term to a
raw coq term *)
- val eval: Term.constr lazy_t
+ val eval: EConstr.constr lazy_t
(** The main lemma of our theory, that is
[compare (norm u) (norm v) = Eq -> eval u == eval v] *)
- val decide_thm:Term.constr lazy_t
+ val decide_thm:EConstr.constr lazy_t
- val lift_normalise_thm : Term.constr lazy_t
+ val lift_normalise_thm : EConstr.constr lazy_t
end
(** {2 Building reified terms}
@@ -136,11 +136,11 @@ module Trans : sig
evars; this is why we give back the [goal], accordingly
updated. *)
- val t_of_constr : Coq.goal_sigma -> Coq.Relation.t -> envs -> (Term.constr * Term.constr) -> Matcher.Terms.t * Matcher.Terms.t * Coq.goal_sigma
+ val t_of_constr : Coq.goal_sigma -> Coq.Relation.t -> envs -> (EConstr.constr * EConstr.constr) -> Matcher.Terms.t * Matcher.Terms.t * Coq.goal_sigma
(** [add_symbol] adds a given binary symbol to the environment of
known stuff. *)
- val add_symbol : Coq.goal_sigma -> Coq.Relation.t -> envs -> Term.constr -> Coq.goal_sigma
+ val add_symbol : Coq.goal_sigma -> Coq.Relation.t -> envs -> Constr.t -> Coq.goal_sigma
(** {2 Reconstruction: from AST back to Coq terms }
@@ -160,16 +160,16 @@ module Trans : sig
reconstruct the named products on top of it. In particular, this
allow us to print the context put around the left (or right)
hand side of a pattern. *)
- val raw_constr_of_t : ir -> Coq.Relation.t -> (Context.Rel.t) ->Matcher.Terms.t -> Term.constr
+ val raw_constr_of_t : ir -> Coq.Relation.t -> EConstr.rel_context -> Matcher.Terms.t -> EConstr.constr
(** {2 Building reified terms} *)
(** The reification environments, as Coq constrs *)
type sigmas = {
- env_sym : Term.constr;
- env_bin : Term.constr;
- env_units : Term.constr; (* the [idx -> X:constr] *)
+ env_sym : EConstr.constr;
+ env_bin : EConstr.constr;
+ env_units : EConstr.constr; (* the [idx -> X:constr] *)
}
@@ -188,10 +188,10 @@ module Trans : sig
reify each term successively.*)
type reifier
- val mk_reifier : Coq.Relation.t -> Term.constr -> ir -> (sigmas * reifier -> Proof_type.tactic) -> Proof_type.tactic
+ val mk_reifier : Coq.Relation.t -> EConstr.constr -> ir -> (sigmas * reifier -> Proof_type.tactic) -> Proof_type.tactic
(** [reif_constr_of_t reifier t] rebuilds the term [t] in the
reified form. *)
- val reif_constr_of_t : reifier -> Matcher.Terms.t -> Term.constr
+ val reif_constr_of_t : reifier -> Matcher.Terms.t -> EConstr.constr
end
diff --git a/AAC.v b/theories/AAC.v
index 5feb0b6..d7cc7a2 100644
--- a/AAC.v
+++ b/theories/AAC.v
@@ -32,6 +32,9 @@ Require Import FMapPositive FMapFacts.
Require Import RelationClasses Equality.
Require Export Morphisms.
+From AAC_tactics
+Require Import Utils.
+
Set Implicit Arguments.
Set Asymmetric Patterns.
@@ -88,7 +91,6 @@ Instance aac_lift_proper {X} {R : relation X} {E} {HE: Equivalence E}
Module Internal.
-
(** * Utilities for the evaluation function *)
Section copy.
@@ -113,7 +115,7 @@ Section copy.
Qed.
Lemma copy_xH : forall x, R (copy 1 x) x.
Proof. intros; unfold copy; rewrite Prect_base. reflexivity. Qed.
- Lemma copy_Psucc : forall n x, R (copy (Psucc n) x) (plus x (copy n x)).
+ Lemma copy_Psucc : forall n x, R (copy (Pos.succ n) x) (plus x (copy n x)).
Proof. intros; unfold copy; rewrite Prect_succ. reflexivity. Qed.
Global Instance copy_compat n: Proper (R ==> R) (copy n).
@@ -126,248 +128,6 @@ Section copy.
End copy.
-(** * Utilities for positive numbers
- which we use as:
- - indices for morphisms and symbols
- - multiplicity of terms in sums *)
-
-Local Notation idx := positive.
-
-Fixpoint eq_idx_bool i j :=
- match i,j with
- | xH, xH => true
- | xO i, xO j => eq_idx_bool i j
- | xI i, xI j => eq_idx_bool i j
- | _, _ => false
- end.
-
-Fixpoint idx_compare i j :=
- match i,j with
- | xH, xH => Eq
- | xH, _ => Lt
- | _, xH => Gt
- | xO i, xO j => idx_compare i j
- | xI i, xI j => idx_compare i j
- | xI _, xO _ => Gt
- | xO _, xI _ => Lt
- end.
-
-Local Notation pos_compare := idx_compare (only parsing).
-
-(** Specification predicate for boolean binary functions *)
-Inductive decide_spec {A} {B} (R : A -> B -> Prop) (x : A) (y : B) : bool -> Prop :=
-| decide_true : R x y -> decide_spec R x y true
-| decide_false : ~(R x y) -> decide_spec R x y false.
-
-Lemma eq_idx_spec : forall i j, decide_spec (@eq _) i j (eq_idx_bool i j).
-Proof.
- induction i; destruct j; simpl; try (constructor; congruence).
- case (IHi j); constructor; congruence.
- case (IHi j); constructor; congruence.
-Qed.
-
-(** weak specification predicate for comparison functions: only the 'Eq' case is specified *)
-Inductive compare_weak_spec A: A -> A -> comparison -> Prop :=
-| pcws_eq: forall i, compare_weak_spec i i Eq
-| pcws_lt: forall i j, compare_weak_spec i j Lt
-| pcws_gt: forall i j, compare_weak_spec i j Gt.
-
-Lemma pos_compare_weak_spec: forall i j, compare_weak_spec i j (pos_compare i j).
-Proof. induction i; destruct j; simpl; try constructor; case (IHi j); intros; constructor. Qed.
-
-Lemma idx_compare_reflect_eq: forall i j, idx_compare i j = Eq -> i=j.
-Proof. intros i j. case (pos_compare_weak_spec i j); intros; congruence. Qed.
-
-(** * Dependent types utilities *)
-
-Local Notation cast T H u := (eq_rect _ T u _ H).
-
-Section dep.
- Variable U: Type.
- Variable T: U -> Type.
-
- Lemma cast_eq: (forall u v: U, {u=v}+{u<>v}) ->
- forall A (H: A=A) (u: T A), cast T H u = u.
- Proof. intros. rewrite <- Eqdep_dec.eq_rect_eq_dec; trivial. Qed.
-
- Variable f: forall A B, T A -> T B -> comparison.
- Definition reflect_eqdep := forall A u B v (H: A=B), @f A B u v = Eq -> cast T H u = v.
-
- (* these lemmas have to remain transparent to get structural recursion
- in the lemma [tcompare_weak_spec] below *)
- Lemma reflect_eqdep_eq: reflect_eqdep ->
- forall A u v, @f A A u v = Eq -> u = v.
- Proof. intros H A u v He. apply (H _ _ _ _ eq_refl He). Defined.
-
- Lemma reflect_eqdep_weak_spec: reflect_eqdep ->
- forall A u v, compare_weak_spec u v (@f A A u v).
- Proof.
- intros. case_eq (f u v); try constructor.
- intro H'. apply reflect_eqdep_eq in H'. subst. constructor. assumption.
- Defined.
-End dep.
-
-
-
-(** * Utilities about (non-empty) lists and multisets *)
-
-Inductive nelist (A : Type) : Type :=
-| nil : A -> nelist A
-| cons : A -> nelist A -> nelist A.
-
-Local Notation "x :: y" := (cons x y).
-
-Fixpoint nelist_map (A B: Type) (f: A -> B) l :=
- match l with
- | nil x => nil ( f x)
- | cons x l => cons ( f x) (nelist_map f l)
- end.
-
-Fixpoint appne A l l' : nelist A :=
- match l with
- nil x => cons x l'
- | cons t q => cons t (appne A q l')
- end.
-
-Local Notation "x ++ y" := (appne x y).
-
-(** finite multisets are represented with ordered lists with multiplicities *)
-Definition mset A := nelist (A*positive).
-
-(** lexicographic composition of comparisons (this is a notation to keep it lazy) *)
-Local Notation lex e f := (match e with Eq => f | _ => e end).
-
-
-Section lists.
-
- (** comparison functions *)
-
- Section c.
- Variables A B: Type.
- Variable compare: A -> B -> comparison.
- Fixpoint list_compare h k :=
- match h,k with
- | nil x, nil y => compare x y
- | nil x, _ => Lt
- | _, nil x => Gt
- | u::h, v::k => lex (compare u v) (list_compare h k)
- end.
- End c.
- Definition mset_compare A B compare: mset A -> mset B -> comparison :=
- list_compare (fun un vm =>
- let '(u,n) := un in
- let '(v,m) := vm in
- lex (compare u v) (pos_compare n m)).
-
- Section list_compare_weak_spec.
- Variable A: Type.
- Variable compare: A -> A -> comparison.
- Hypothesis Hcompare: forall u v, compare_weak_spec u v (compare u v).
- (* this lemma has to remain transparent to get structural recursion
- in the lemma [tcompare_weak_spec] below *)
- Lemma list_compare_weak_spec: forall h k,
- compare_weak_spec h k (list_compare compare h k).
- Proof.
- induction h as [|u h IHh]; destruct k as [|v k]; simpl; try constructor.
-
- case (Hcompare a a0 ); try constructor.
- case (Hcompare u v ); try constructor.
- case (IHh k); intros; constructor.
- Defined.
- End list_compare_weak_spec.
-
- Section mset_compare_weak_spec.
- Variable A: Type.
- Variable compare: A -> A -> comparison.
- Hypothesis Hcompare: forall u v, compare_weak_spec u v (compare u v).
- (* this lemma has to remain transparent to get structural recursion
- in the lemma [tcompare_weak_spec] below *)
- Lemma mset_compare_weak_spec: forall h k,
- compare_weak_spec h k (mset_compare compare h k).
- Proof.
- apply list_compare_weak_spec.
- intros [u n] [v m].
- case (Hcompare u v); try constructor.
- case (pos_compare_weak_spec n m); try constructor.
- Defined.
- End mset_compare_weak_spec.
-
- (** (sorted) merging functions *)
-
- Section m.
- Variable A: Type.
- Variable compare: A -> A -> comparison.
- Definition insert n1 h1 :=
- let fix insert_aux l2 :=
- match l2 with
- | nil (h2,n2) =>
- match compare h1 h2 with
- | Eq => nil (h1,Pplus n1 n2)
- | Lt => (h1,n1):: nil (h2,n2)
- | Gt => (h2,n2):: nil (h1,n1)
- end
- | (h2,n2)::t2 =>
- match compare h1 h2 with
- | Eq => (h1,Pplus n1 n2):: t2
- | Lt => (h1,n1)::l2
- | Gt => (h2,n2)::insert_aux t2
- end
- end
- in insert_aux.
-
- Fixpoint merge_msets l1 :=
- match l1 with
- | nil (h1,n1) => fun l2 => insert n1 h1 l2
- | (h1,n1)::t1 =>
- let fix merge_aux l2 :=
- match l2 with
- | nil (h2,n2) =>
- match compare h1 h2 with
- | Eq => (h1,Pplus n1 n2) :: t1
- | Lt => (h1,n1):: merge_msets t1 l2
- | Gt => (h2,n2):: l1
- end
- | (h2,n2)::t2 =>
- match compare h1 h2 with
- | Eq => (h1,Pplus n1 n2)::merge_msets t1 t2
- | Lt => (h1,n1)::merge_msets t1 l2
- | Gt => (h2,n2)::merge_aux t2
- end
- end
- in merge_aux
- end.
-
- (** interpretation of a list with a constant and a binary operation *)
-
- Variable B: Type.
- Variable map: A -> B.
- Variable b2: B -> B -> B.
- Fixpoint fold_map l :=
- match l with
- | nil x => map x
- | u::l => b2 (map u) (fold_map l)
- end.
-
- (** mapping and merging *)
-
- Variable merge: A -> nelist B -> nelist B.
- Fixpoint merge_map (l: nelist A): nelist B :=
- match l with
- | nil x => nil (map x)
- | u::l => merge u (merge_map l)
- end.
-
- Variable ret : A -> B.
- Variable bind : A -> B -> B.
- Fixpoint fold_map' (l : nelist A) : B :=
- match l with
- | nil x => ret x
- | u::l => bind u (fold_map' l)
- end.
-
- End m.
-End lists.
-
(** * Packaging structures *)
(** ** free symbols *)
@@ -842,7 +602,7 @@ Section s.
Qed.
- Lemma copy_mset_succ n (l: mset T): eval (sum i (copy_mset (Psucc n) l)) == @Bin.value _ _ (e_bin i) (eval (sum i l)) (eval (sum i (copy_mset n l))).
+ Lemma copy_mset_succ n (l: mset T): eval (sum i (copy_mset (Pos.succ n) l)) == @Bin.value _ _ (e_bin i) (eval (sum i l)) (eval (sum i (copy_mset n l))).
Proof.
rewrite 2 copy_mset'.
@@ -1118,7 +878,7 @@ End Internal.
Local Ltac internal_normalize :=
let x := fresh in let y := fresh in
intro x; intro y; vm_compute in x; vm_compute in y; unfold x; unfold y;
- compute [Internal.eval Internal.fold_map Internal.copy Prect]; simpl.
+ compute [Internal.eval Utils.fold_map Internal.copy Prect]; simpl.
(** * Lemmas for performing transitivity steps
@@ -1138,4 +898,4 @@ Section t.
End t.
-Declare ML Module "aac".
+Declare ML Module "aac_plugin".
diff --git a/Caveats.v b/theories/Caveats.v
index a7967cc..d7824cd 100644
--- a/Caveats.v
+++ b/theories/Caveats.v
@@ -13,7 +13,11 @@
with the path to the [aac_tactics] library
*)
+Require NArith Minus.
+
+From AAC_tactics
Require Import AAC.
+From AAC_tactics
Require Instances.
(** ** Limitations *)
@@ -74,7 +78,7 @@ End parameters.
type [T] to some other type [T']. *)
Section morphism.
- Require Import NArith Minus.
+ Import NArith Minus.
Open Scope nat_scope.
(** Typically, although [N_of_nat] is a proper morphism from
@@ -122,11 +126,11 @@ End morphism.
Section ineq.
- Require Import ZArith.
+ Import ZArith.
Import Instances.Z.
Open Scope Z_scope.
- Instance Zplus_incr: Proper (Zle ==> Zle ==> Zle) Zplus.
+ Instance Zplus_incr: Proper (Z.le ==> Z.le ==> Z.le) Zplus.
Proof. intros ? ? H ? ? H'. apply Zplus_le_compat; assumption. Qed.
Hypothesis H: forall x, x+x <= x.
@@ -197,7 +201,7 @@ appearing in a goal are considered as constants, they will not be
instantiated. *)
Section evars.
- Require Import ZArith.
+ Import ZArith.
Import Instances.Z.
Variable P: Prop.
@@ -333,7 +337,7 @@ Goal a+b*c = c.
*)
Abort.
-(** **** If the pattern is a unit or can be instanciated to be equal
+(** **** If the pattern is a unit or can be instantiated to be equal
to a unit:
The heuristic is to make the unit appear at each possible position
@@ -350,7 +354,7 @@ Goal a+b+c = c.
(** 7 solutions, we miss solutions like [(a+b+c+0*(1+0*[]))]*)
Abort.
-(** *** Another example of the former case is the following, where the hypothesis can be instanciated to be equal to [1] *)
+(** *** Another example of the former case is the following, where the hypothesis can be instantiated to be equal to [1] *)
Hypothesis H : forall x y, (x+y)*x = x*x + y *x.
Goal a*a+b*a + c = c.
(** Here, only one solution if we use the aac_instance tactic *)
diff --git a/Instances.v b/theories/Instances.v
index 55dffbb..d007ceb 100644
--- a/Instances.v
+++ b/theories/Instances.v
@@ -12,6 +12,7 @@ Require ZArith Zminmax.
Require QArith Qminmax.
Require Relations.
+From AAC_tactics
Require Export AAC.
(** Instances for aac_rewrite.*)
@@ -58,18 +59,18 @@ Module Z.
Instance aac_Zmult_Comm : Commutative eq Zmult := Zmult_comm.
Instance aac_Zmult_Assoc : Associative eq Zmult := Zmult_assoc.
- Instance aac_Zmin_Comm : Commutative eq Zmin := Zmin_comm.
- Instance aac_Zmin_Assoc : Associative eq Zmin := Zmin_assoc.
+ Instance aac_Zmin_Comm : Commutative eq Z.min := Z.min_comm.
+ Instance aac_Zmin_Assoc : Associative eq Z.min := Z.min_assoc.
- Instance aac_Zmax_Comm : Commutative eq Zmax := Zmax_comm.
- Instance aac_Zmax_Assoc : Associative eq Zmax := Zmax_assoc.
+ Instance aac_Zmax_Comm : Commutative eq Z.max := Z.max_comm.
+ Instance aac_Zmax_Assoc : Associative eq Z.max := Z.max_assoc.
Instance aac_one : Unit eq Zmult 1 := Build_Unit eq Zmult 1 Zmult_1_l Zmult_1_r.
Instance aac_zero_Zplus : Unit eq Zplus 0 := Build_Unit eq Zplus 0 Zplus_0_l Zplus_0_r.
(* We also provide liftings from le to eq *)
- Instance preorder_Zle : PreOrder Zle := Build_PreOrder _ Zle_refl Zle_trans.
- Instance lift_le_eq : AAC_lift Zle eq := Build_AAC_lift eq_equivalence _.
+ Instance preorder_Zle : PreOrder Z.le := Build_PreOrder _ Z.le_refl Z.le_trans.
+ Instance lift_le_eq : AAC_lift Z.le eq := Build_AAC_lift eq_equivalence _.
End Z.
@@ -95,19 +96,19 @@ Module N.
Instance aac_Nmult_Comm : Commutative eq Nmult := Nmult_comm.
Instance aac_Nmult_Assoc : Associative eq Nmult := Nmult_assoc.
- Instance aac_Nmin_Comm : Commutative eq Nmin := N.min_comm.
- Instance aac_Nmin_Assoc : Associative eq Nmin := N.min_assoc.
+ Instance aac_Nmin_Comm : Commutative eq N.min := N.min_comm.
+ Instance aac_Nmin_Assoc : Associative eq N.min := N.min_assoc.
- Instance aac_Nmax_Comm : Commutative eq Nmax := N.max_comm.
- Instance aac_Nmax_Assoc : Associative eq Nmax := N.max_assoc.
+ Instance aac_Nmax_Comm : Commutative eq N.max := N.max_comm.
+ Instance aac_Nmax_Assoc : Associative eq N.max := N.max_assoc.
Instance aac_one : Unit eq Nmult (1)%N := Build_Unit eq Nmult (1)%N Nmult_1_l Nmult_1_r.
Instance aac_zero : Unit eq Nplus (0)%N := Build_Unit eq Nplus (0)%N Nplus_0_l Nplus_0_r.
- Instance aac_zero_max : Unit eq Nmax 0 := Build_Unit eq Nmax 0 N.max_0_l N.max_0_r.
+ Instance aac_zero_max : Unit eq N.max 0 := Build_Unit eq N.max 0 N.max_0_l N.max_0_r.
(* We also provide liftings from le to eq *)
- Instance preorder_le : PreOrder Nle := Build_PreOrder Nle N.le_refl N.le_trans.
- Instance lift_le_eq : AAC_lift Nle eq := Build_AAC_lift eq_equivalence _.
+ Instance preorder_le : PreOrder N.le := Build_PreOrder N.le N.le_refl N.le_trans.
+ Instance lift_le_eq : AAC_lift N.le eq := Build_AAC_lift eq_equivalence _.
End N.
@@ -120,19 +121,19 @@ Module P.
Instance aac_Pmult_Comm : Commutative eq Pmult := Pmult_comm.
Instance aac_Pmult_Assoc : Associative eq Pmult := Pmult_assoc.
- Instance aac_Pmin_Comm : Commutative eq Pmin := Pos.min_comm.
- Instance aac_Pmin_Assoc : Associative eq Pmin := Pos.min_assoc.
+ Instance aac_Pmin_Comm : Commutative eq Pos.min := Pos.min_comm.
+ Instance aac_Pmin_Assoc : Associative eq Pos.min := Pos.min_assoc.
- Instance aac_Pmax_Comm : Commutative eq Pmax := Pos.max_comm.
- Instance aac_Pmax_Assoc : Associative eq Pmax := Pos.max_assoc.
+ Instance aac_Pmax_Comm : Commutative eq Pos.max := Pos.max_comm.
+ Instance aac_Pmax_Assoc : Associative eq Pos.max := Pos.max_assoc.
Instance aac_one : Unit eq Pmult 1 := Build_Unit eq Pmult 1 _ Pmult_1_r.
intros; reflexivity. Qed. (* TODO : add this lemma in the stdlib *)
- Instance aac_one_max : Unit eq Pmax 1 := Build_Unit eq Pmax 1 Pos.max_1_l Pos.max_1_r.
+ Instance aac_one_max : Unit eq Pos.max 1 := Build_Unit eq Pos.max 1 Pos.max_1_l Pos.max_1_r.
(* We also provide liftings from le to eq *)
- Instance preorder_le : PreOrder Ple := Build_PreOrder Ple Pos.le_refl Pos.le_trans.
- Instance lift_le_eq : AAC_lift Ple eq := Build_AAC_lift eq_equivalence _.
+ Instance preorder_le : PreOrder Pos.le := Build_PreOrder Pos.le Pos.le_refl Pos.le_trans.
+ Instance lift_le_eq : AAC_lift Pos.le eq := Build_AAC_lift eq_equivalence _.
End P.
Module Q.
diff --git a/Tutorial.v b/theories/Tutorial.v
index 76006ca..e403d92 100644
--- a/Tutorial.v
+++ b/theories/Tutorial.v
@@ -12,9 +12,11 @@
lines, or add them to your .coqrc files, replacing "." with the
path to the [aac_tactics] library. *)
-Add Rec LoadPath "." as AAC_tactics.
-Add ML Path ".".
+Require Arith ZArith.
+
+From AAC_tactics
Require Import AAC.
+From AAC_tactics
Require Instances.
(** ** Introductory example
@@ -29,12 +31,12 @@ Section introduction.
Import Instances.Z.
Variables a b c : Z.
- Hypothesis H: forall x, x + Zopp x = 0.
- Goal a + b + c + Zopp (c + a) = b.
+ Hypothesis H: forall x, x + Z.opp x = 0.
+ Goal a + b + c + Z.opp (c + a) = b.
aac_rewrite H.
aac_reflexivity.
Qed.
- Goal a + c + Zopp (b + a + Zopp b) = c.
+ Goal a + c + Z.opp (b + a + Z.opp b) = c.
do 2 aac_rewrite H.
reflexivity.
Qed.
@@ -223,7 +225,7 @@ End base.
already declared in file [Instances.v].) *)
Section Peano.
- Require Import Arith.
+ Import Arith.
Instance aac_plus_Assoc : Associative eq plus := plus_assoc.
Instance aac_plus_Comm : Commutative eq plus := plus_comm.
@@ -327,7 +329,7 @@ End Peano.
Section AAC_normalise.
Import Instances.Z.
- Require Import ZArith.
+ Import ZArith.
Open Scope Z_scope.
Variable a b c d : Z.
@@ -344,30 +346,30 @@ End AAC_normalise.
Section Examples.
Import Instances.Z.
- Require Import ZArith.
+ Import ZArith.
Open Scope Z_scope.
(** *** Reverse triangle inequality *)
- Lemma Zabs_triangle : forall x y, Zabs (x + y) <= Zabs x + Zabs y .
- Proof Zabs_triangle.
+ Lemma Zabs_triangle : forall x y, Z.abs (x + y) <= Z.abs x + Z.abs y .
+ Proof Z.abs_triangle.
Lemma Zplus_opp_r : forall x, x + -x = 0.
Proof Zplus_opp_r.
(** The following morphisms are required to perform the required rewrites *)
- Instance Zminus_compat : Proper (Zge ==> Zle) Zopp.
+ Instance Zminus_compat : Proper (Z.ge ==> Z.le) Z.opp.
Proof. intros x y. omega. Qed.
- Instance Proper_Zplus : Proper (Zle ==> Zle ==> Zle) Zplus.
+ Instance Proper_Zplus : Proper (Z.le ==> Z.le ==> Z.le) Zplus.
Proof. firstorder. Qed.
- Goal forall a b, Zabs a - Zabs b <= Zabs (a - b).
+ Goal forall a b, Z.abs a - Z.abs b <= Z.abs (a - b).
intros. unfold Zminus.
aac_instances <- (Zminus_diag b).
aac_rewrite <- (Zminus_diag b) at 3.
unfold Zminus.
- aac_rewrite Zabs_triangle.
+ aac_rewrite Z.abs_triangle.
aac_rewrite Zplus_opp_r.
aac_reflexivity.
Qed.
diff --git a/theories/Utils.v b/theories/Utils.v
new file mode 100644
index 0000000..0f37ae1
--- /dev/null
+++ b/theories/Utils.v
@@ -0,0 +1,257 @@
+(***************************************************************************)
+(* This is part of aac_tactics, it is distributed under the terms of the *)
+(* GNU Lesser General Public License version 3 *)
+(* (see file LICENSE for more details) *)
+(* *)
+(* Copyright 2009-2010: Thomas Braibant, Damien Pous. *)
+(***************************************************************************)
+
+
+Require Import Arith NArith.
+Require Import List.
+Require Import FMapPositive FMapFacts.
+Require Import RelationClasses Equality.
+
+Set Implicit Arguments.
+Set Asymmetric Patterns.
+
+(** * Utilities for positive numbers
+ which we use as:
+ - indices for morphisms and symbols
+ - multiplicity of terms in sums *)
+
+Notation idx := positive.
+
+Fixpoint eq_idx_bool i j :=
+ match i,j with
+ | xH, xH => true
+ | xO i, xO j => eq_idx_bool i j
+ | xI i, xI j => eq_idx_bool i j
+ | _, _ => false
+ end.
+
+Fixpoint idx_compare i j :=
+ match i,j with
+ | xH, xH => Eq
+ | xH, _ => Lt
+ | _, xH => Gt
+ | xO i, xO j => idx_compare i j
+ | xI i, xI j => idx_compare i j
+ | xI _, xO _ => Gt
+ | xO _, xI _ => Lt
+ end.
+
+Notation pos_compare := idx_compare (only parsing).
+
+(** Specification predicate for boolean binary functions *)
+Inductive decide_spec {A} {B} (R : A -> B -> Prop) (x : A) (y : B) : bool -> Prop :=
+| decide_true : R x y -> decide_spec R x y true
+| decide_false : ~(R x y) -> decide_spec R x y false.
+
+Lemma eq_idx_spec : forall i j, decide_spec (@eq _) i j (eq_idx_bool i j).
+Proof.
+ induction i; destruct j; simpl; try (constructor; congruence).
+ case (IHi j); constructor; congruence.
+ case (IHi j); constructor; congruence.
+Qed.
+
+(** weak specification predicate for comparison functions: only the 'Eq' case is specified *)
+Inductive compare_weak_spec A: A -> A -> comparison -> Prop :=
+| pcws_eq: forall i, compare_weak_spec i i Eq
+| pcws_lt: forall i j, compare_weak_spec i j Lt
+| pcws_gt: forall i j, compare_weak_spec i j Gt.
+
+Lemma pos_compare_weak_spec: forall i j, compare_weak_spec i j (pos_compare i j).
+Proof. induction i; destruct j; simpl; try constructor; case (IHi j); intros; constructor. Qed.
+
+Lemma idx_compare_reflect_eq: forall i j, idx_compare i j = Eq -> i=j.
+Proof. intros i j. case (pos_compare_weak_spec i j); intros; congruence. Qed.
+
+(** * Dependent types utilities *)
+
+Notation cast T H u := (eq_rect _ T u _ H).
+
+Section dep.
+ Variable U: Type.
+ Variable T: U -> Type.
+
+ Lemma cast_eq: (forall u v: U, {u=v}+{u<>v}) ->
+ forall A (H: A=A) (u: T A), cast T H u = u.
+ Proof. intros. rewrite <- Eqdep_dec.eq_rect_eq_dec; trivial. Qed.
+
+ Variable f: forall A B, T A -> T B -> comparison.
+ Definition reflect_eqdep := forall A u B v (H: A=B), @f A B u v = Eq -> cast T H u = v.
+
+ (* these lemmas have to remain transparent to get structural recursion
+ in the lemma [tcompare_weak_spec] below *)
+ Lemma reflect_eqdep_eq: reflect_eqdep ->
+ forall A u v, @f A A u v = Eq -> u = v.
+ Proof. intros H A u v He. apply (H _ _ _ _ eq_refl He). Defined.
+
+ Lemma reflect_eqdep_weak_spec: reflect_eqdep ->
+ forall A u v, compare_weak_spec u v (@f A A u v).
+ Proof.
+ intros. case_eq (f u v); try constructor.
+ intro H'. apply reflect_eqdep_eq in H'. subst. constructor. assumption.
+ Defined.
+End dep.
+
+
+(** * Utilities about (non-empty) lists and multisets *)
+
+Inductive nelist (A : Type) : Type :=
+| nil : A -> nelist A
+| cons : A -> nelist A -> nelist A.
+
+Notation "x :: y" := (cons x y).
+
+Fixpoint nelist_map (A B: Type) (f: A -> B) l :=
+ match l with
+ | nil x => nil ( f x)
+ | cons x l => cons ( f x) (nelist_map f l)
+ end.
+
+Fixpoint appne A l l' : nelist A :=
+ match l with
+ nil x => cons x l'
+ | cons t q => cons t (appne A q l')
+ end.
+
+Notation "x ++ y" := (appne x y).
+
+(** finite multisets are represented with ordered lists with multiplicities *)
+Definition mset A := nelist (A*positive).
+
+(** lexicographic composition of comparisons (this is a notation to keep it lazy) *)
+Notation lex e f := (match e with Eq => f | _ => e end).
+
+
+Section lists.
+
+ (** comparison functions *)
+
+ Section c.
+ Variables A B: Type.
+ Variable compare: A -> B -> comparison.
+ Fixpoint list_compare h k :=
+ match h,k with
+ | nil x, nil y => compare x y
+ | nil x, _ => Lt
+ | _, nil x => Gt
+ | u::h, v::k => lex (compare u v) (list_compare h k)
+ end.
+ End c.
+ Definition mset_compare A B compare: mset A -> mset B -> comparison :=
+ list_compare (fun un vm =>
+ let '(u,n) := un in
+ let '(v,m) := vm in
+ lex (compare u v) (pos_compare n m)).
+
+ Section list_compare_weak_spec.
+ Variable A: Type.
+ Variable compare: A -> A -> comparison.
+ Hypothesis Hcompare: forall u v, compare_weak_spec u v (compare u v).
+ (* this lemma has to remain transparent to get structural recursion
+ in the lemma [tcompare_weak_spec] below *)
+ Lemma list_compare_weak_spec: forall h k,
+ compare_weak_spec h k (list_compare compare h k).
+ Proof.
+ induction h as [|u h IHh]; destruct k as [|v k]; simpl; try constructor.
+
+ case (Hcompare a a0 ); try constructor.
+ case (Hcompare u v ); try constructor.
+ case (IHh k); intros; constructor.
+ Defined.
+ End list_compare_weak_spec.
+
+ Section mset_compare_weak_spec.
+ Variable A: Type.
+ Variable compare: A -> A -> comparison.
+ Hypothesis Hcompare: forall u v, compare_weak_spec u v (compare u v).
+ (* this lemma has to remain transparent to get structural recursion
+ in the lemma [tcompare_weak_spec] below *)
+ Lemma mset_compare_weak_spec: forall h k,
+ compare_weak_spec h k (mset_compare compare h k).
+ Proof.
+ apply list_compare_weak_spec.
+ intros [u n] [v m].
+ case (Hcompare u v); try constructor.
+ case (pos_compare_weak_spec n m); try constructor.
+ Defined.
+ End mset_compare_weak_spec.
+
+ (** (sorted) merging functions *)
+
+ Section m.
+ Variable A: Type.
+ Variable compare: A -> A -> comparison.
+ Definition insert n1 h1 :=
+ let fix insert_aux l2 :=
+ match l2 with
+ | nil (h2,n2) =>
+ match compare h1 h2 with
+ | Eq => nil (h1,Pplus n1 n2)
+ | Lt => (h1,n1):: nil (h2,n2)
+ | Gt => (h2,n2):: nil (h1,n1)
+ end
+ | (h2,n2)::t2 =>
+ match compare h1 h2 with
+ | Eq => (h1,Pplus n1 n2):: t2
+ | Lt => (h1,n1)::l2
+ | Gt => (h2,n2)::insert_aux t2
+ end
+ end
+ in insert_aux.
+
+ Fixpoint merge_msets l1 :=
+ match l1 with
+ | nil (h1,n1) => fun l2 => insert n1 h1 l2
+ | (h1,n1)::t1 =>
+ let fix merge_aux l2 :=
+ match l2 with
+ | nil (h2,n2) =>
+ match compare h1 h2 with
+ | Eq => (h1,Pplus n1 n2) :: t1
+ | Lt => (h1,n1):: merge_msets t1 l2
+ | Gt => (h2,n2):: l1
+ end
+ | (h2,n2)::t2 =>
+ match compare h1 h2 with
+ | Eq => (h1,Pplus n1 n2)::merge_msets t1 t2
+ | Lt => (h1,n1)::merge_msets t1 l2
+ | Gt => (h2,n2)::merge_aux t2
+ end
+ end
+ in merge_aux
+ end.
+
+ (** interpretation of a list with a constant and a binary operation *)
+
+ Variable B: Type.
+ Variable map: A -> B.
+ Variable b2: B -> B -> B.
+ Fixpoint fold_map l :=
+ match l with
+ | nil x => map x
+ | u::l => b2 (map u) (fold_map l)
+ end.
+
+ (** mapping and merging *)
+
+ Variable merge: A -> nelist B -> nelist B.
+ Fixpoint merge_map (l: nelist A): nelist B :=
+ match l with
+ | nil x => nil (map x)
+ | u::l => merge u (merge_map l)
+ end.
+
+ Variable ret : A -> B.
+ Variable bind : A -> B -> B.
+ Fixpoint fold_map' (l : nelist A) : B :=
+ match l with
+ | nil x => ret x
+ | u::l => bind u (fold_map' l)
+ end.
+
+ End m.
+End lists.