pax_global_header00006660000000000000000000000064144532554460014526gustar00rootroot0000000000000052 comment=9f330a0bc41350a35a446be208d0722cbc109193 mczify-1.5.0-2.0-8.16/000077500000000000000000000000001445325544600137215ustar00rootroot00000000000000mczify-1.5.0-2.0-8.16/.github/000077500000000000000000000000001445325544600152615ustar00rootroot00000000000000mczify-1.5.0-2.0-8.16/.github/workflows/000077500000000000000000000000001445325544600173165ustar00rootroot00000000000000mczify-1.5.0-2.0-8.16/.github/workflows/docker-action.yml000066400000000000000000000023521445325544600225650ustar00rootroot00000000000000# This file was generated from `meta.yml` using the coq-community templates and # then patched to support the test-suite. Be careful when regenerate it. name: Docker CI on: push: branches: - master pull_request: branches: - '**' jobs: build: # the OS must be GNU/Linux to be able to use the docker-coq-action runs-on: ubuntu-latest strategy: matrix: image: - 'mathcomp/mathcomp:2.0.0-coq-8.16' - 'mathcomp/mathcomp:2.0.0-coq-8.17' - 'mathcomp/mathcomp-dev:coq-8.16' - 'mathcomp/mathcomp-dev:coq-8.17' - 'mathcomp/mathcomp-dev:coq-dev' fail-fast: false steps: - uses: actions/checkout@v2 - uses: coq-community/docker-coq-action@v1 with: opam_file: 'coq-mathcomp-zify.opam' custom_image: ${{ matrix.image }} after_script: | startGroup "Run tests" sudo chown -R coq:coq . make test-suite TEST_SKIP_BUILD=1 endGroup - name: Revert permissions if: ${{ always() }} run: sudo chown -R 1001:116 . # See also: # https://github.com/coq-community/docker-coq-action#readme # https://github.com/erikmd/docker-coq-github-action-demo mczify-1.5.0-2.0-8.16/.gitignore000066400000000000000000000001711445325544600157100ustar00rootroot00000000000000*.d *.vo *.vio *.vos *.vok *.cm* *~ *.glob *.aux *.a *.o Make*.coq Make*.coq.bak Make*.coq.conf *# .lia.cache .nia.cache mczify-1.5.0-2.0-8.16/CeCILL-B000066400000000000000000000526231445325544600150260ustar00rootroot00000000000000CeCILL-B FREE SOFTWARE LICENSE AGREEMENT Notice This Agreement is a Free Software license agreement that is the result of discussions between its authors in order to ensure compliance with the two main principles guiding its drafting: * firstly, compliance with the principles governing the distribution of Free Software: access to source code, broad rights granted to users, * secondly, the election of a governing law, French law, with which it is conformant, both as regards the law of torts and intellectual property law, and the protection that it offers to both authors and holders of the economic rights over software. The authors of the CeCILL-B (for Ce[a] C[nrs] I[nria] L[ogiciel] L[ibre]) license are: Commissariat à l'Energie Atomique - CEA, a public scientific, technical and industrial research establishment, having its principal place of business at 25 rue Leblanc, immeuble Le Ponant D, 75015 Paris, France. Centre National de la Recherche Scientifique - CNRS, a public scientific and technological establishment, having its principal place of business at 3 rue Michel-Ange, 75794 Paris cedex 16, France. Institut National de Recherche en Informatique et en Automatique - INRIA, a public scientific and technological establishment, having its principal place of business at Domaine de Voluceau, Rocquencourt, BP 105, 78153 Le Chesnay cedex, France. Preamble This Agreement is an open source software license intended to give users significant freedom to modify and redistribute the software licensed hereunder. The exercising of this freedom is conditional upon a strong obligation of giving credits for everybody that distributes a software incorporating a software ruled by the current license so as all contributions to be properly identified and acknowledged. In consideration of access to the source code and the rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors only have limited liability. In this respect, the risks associated with loading, using, modifying and/or developing or reproducing the software by the user are brought to the user's attention, given its Free Software status, which may make it complicated to use, with the result that its use is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the suitability of the software as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions of security. This Agreement may be freely reproduced and published, provided it is not altered, and that no provisions are either added or removed herefrom. This Agreement may apply to any or all software for which the holder of the economic rights decides to submit the use thereof to its provisions. Article 1 - DEFINITIONS For the purpose of this Agreement, when the following expressions commence with a capital letter, they shall have the following meaning: Agreement: means this license agreement, and its possible subsequent versions and annexes. Software: means the software in its Object Code and/or Source Code form and, where applicable, its documentation, "as is" when the Licensee accepts the Agreement. Initial Software: means the Software in its Source Code and possibly its Object Code form and, where applicable, its documentation, "as is" when it is first distributed under the terms and conditions of the Agreement. Modified Software: means the Software modified by at least one Contribution. Source Code: means all the Software's instructions and program lines to which access is required so as to modify the Software. Object Code: means the binary files originating from the compilation of the Source Code. Holder: means the holder(s) of the economic rights over the Initial Software. Licensee: means the Software user(s) having accepted the Agreement. Contributor: means a Licensee having made at least one Contribution. Licensor: means the Holder, or any other individual or legal entity, who distributes the Software under the Agreement. Contribution: means any or all modifications, corrections, translations, adaptations and/or new functions integrated into the Software by any or all Contributors, as well as any or all Internal Modules. Module: means a set of sources files including their documentation that enables supplementary functions or services in addition to those offered by the Software. External Module: means any or all Modules, not derived from the Software, so that this Module and the Software run in separate address spaces, with one calling the other when they are run. Internal Module: means any or all Module, connected to the Software so that they both execute in the same address space. Parties: mean both the Licensee and the Licensor. These expressions may be used both in singular and plural form. Article 2 - PURPOSE The purpose of the Agreement is the grant by the Licensor to the Licensee of a non-exclusive, transferable and worldwide license for the Software as set forth in Article 5 hereinafter for the whole term of the protection granted by the rights over said Software. Article 3 - ACCEPTANCE 3.1 The Licensee shall be deemed as having accepted the terms and conditions of this Agreement upon the occurrence of the first of the following events: * (i) loading the Software by any or all means, notably, by downloading from a remote server, or by loading from a physical medium; * (ii) the first time the Licensee exercises any of the rights granted hereunder. 3.2 One copy of the Agreement, containing a notice relating to the characteristics of the Software, to the limited warranty, and to the fact that its use is restricted to experienced users has been provided to the Licensee prior to its acceptance as set forth in Article 3.1 hereinabove, and the Licensee hereby acknowledges that it has read and understood it. Article 4 - EFFECTIVE DATE AND TERM 4.1 EFFECTIVE DATE The Agreement shall become effective on the date when it is accepted by the Licensee as set forth in Article 3.1. 4.2 TERM The Agreement shall remain in force for the entire legal term of protection of the economic rights over the Software. Article 5 - SCOPE OF RIGHTS GRANTED The Licensor hereby grants to the Licensee, who accepts, the following rights over the Software for any or all use, and for the term of the Agreement, on the basis of the terms and conditions set forth hereinafter. Besides, if the Licensor owns or comes to own one or more patents protecting all or part of the functions of the Software or of its components, the Licensor undertakes not to enforce the rights granted by these patents against successive Licensees using, exploiting or modifying the Software. If these patents are transferred, the Licensor undertakes to have the transferees subscribe to the obligations set forth in this paragraph. 5.1 RIGHT OF USE The Licensee is authorized to use the Software, without any limitation as to its fields of application, with it being hereinafter specified that this comprises: 1. permanent or temporary reproduction of all or part of the Software by any or all means and in any or all form. 2. loading, displaying, running, or storing the Software on any or all medium. 3. entitlement to observe, study or test its operation so as to determine the ideas and principles behind any or all constituent elements of said Software. This shall apply when the Licensee carries out any or all loading, displaying, running, transmission or storage operation as regards the Software, that it is entitled to carry out hereunder. 5.2 ENTITLEMENT TO MAKE CONTRIBUTIONS The right to make Contributions includes the right to translate, adapt, arrange, or make any or all modifications to the Software, and the right to reproduce the resulting software. The Licensee is authorized to make any or all Contributions to the Software provided that it includes an explicit notice that it is the author of said Contribution and indicates the date of the creation thereof. 5.3 RIGHT OF DISTRIBUTION In particular, the right of distribution includes the right to publish, transmit and communicate the Software to the general public on any or all medium, and by any or all means, and the right to market, either in consideration of a fee, or free of charge, one or more copies of the Software by any means. The Licensee is further authorized to distribute copies of the modified or unmodified Software to third parties according to the terms and conditions set forth hereinafter. 5.3.1 DISTRIBUTION OF SOFTWARE WITHOUT MODIFICATION The Licensee is authorized to distribute true copies of the Software in Source Code or Object Code form, provided that said distribution complies with all the provisions of the Agreement and is accompanied by: 1. a copy of the Agreement, 2. a notice relating to the limitation of both the Licensor's warranty and liability as set forth in Articles 8 and 9, and that, in the event that only the Object Code of the Software is redistributed, the Licensee allows effective access to the full Source Code of the Software at a minimum during the entire period of its distribution of the Software, it being understood that the additional cost of acquiring the Source Code shall not exceed the cost of transferring the data. 5.3.2 DISTRIBUTION OF MODIFIED SOFTWARE If the Licensee makes any Contribution to the Software, the resulting Modified Software may be distributed under a license agreement other than this Agreement subject to compliance with the provisions of Article 5.3.4. 5.3.3 DISTRIBUTION OF EXTERNAL MODULES When the Licensee has developed an External Module, the terms and conditions of this Agreement do not apply to said External Module, that may be distributed under a separate license agreement. 5.3.4 CREDITS Any Licensee who may distribute a Modified Software hereby expressly agrees to: 1. indicate in the related documentation that it is based on the Software licensed hereunder, and reproduce the intellectual property notice for the Software, 2. ensure that written indications of the Software intended use, intellectual property notice and license hereunder are included in easily accessible format from the Modified Software interface, 3. mention, on a freely accessible website describing the Modified Software, at least throughout the distribution term thereof, that it is based on the Software licensed hereunder, and reproduce the Software intellectual property notice, 4. where it is distributed to a third party that may distribute a Modified Software without having to make its source code available, make its best efforts to ensure that said third party agrees to comply with the obligations set forth in this Article . If the Software, whether or not modified, is distributed with an External Module designed for use in connection with the Software, the Licensee shall submit said External Module to the foregoing obligations. 5.3.5 COMPATIBILITY WITH THE CeCILL AND CeCILL-C LICENSES Where a Modified Software contains a Contribution subject to the CeCILL license, the provisions set forth in Article 5.3.4 shall be optional. A Modified Software may be distributed under the CeCILL-C license. In such a case the provisions set forth in Article 5.3.4 shall be optional. Article 6 - INTELLECTUAL PROPERTY 6.1 OVER THE INITIAL SOFTWARE The Holder owns the economic rights over the Initial Software. Any or all use of the Initial Software is subject to compliance with the terms and conditions under which the Holder has elected to distribute its work and no one shall be entitled to modify the terms and conditions for the distribution of said Initial Software. The Holder undertakes that the Initial Software will remain ruled at least by this Agreement, for the duration set forth in Article 4.2. 6.2 OVER THE CONTRIBUTIONS The Licensee who develops a Contribution is the owner of the intellectual property rights over this Contribution as defined by applicable law. 6.3 OVER THE EXTERNAL MODULES The Licensee who develops an External Module is the owner of the intellectual property rights over this External Module as defined by applicable law and is free to choose the type of agreement that shall govern its distribution. 6.4 JOINT PROVISIONS The Licensee expressly undertakes: 1. not to remove, or modify, in any manner, the intellectual property notices attached to the Software; 2. to reproduce said notices, in an identical manner, in the copies of the Software modified or not. The Licensee undertakes not to directly or indirectly infringe the intellectual property rights of the Holder and/or Contributors on the Software and to take, where applicable, vis-à-vis its staff, any and all measures required to ensure respect of said intellectual property rights of the Holder and/or Contributors. Article 7 - RELATED SERVICES 7.1 Under no circumstances shall the Agreement oblige the Licensor to provide technical assistance or maintenance services for the Software. However, the Licensor is entitled to offer this type of services. The terms and conditions of such technical assistance, and/or such maintenance, shall be set forth in a separate instrument. Only the Licensor offering said maintenance and/or technical assistance services shall incur liability therefor. 7.2 Similarly, any Licensor is entitled to offer to its licensees, under its sole responsibility, a warranty, that shall only be binding upon itself, for the redistribution of the Software and/or the Modified Software, under terms and conditions that it is free to decide. Said warranty, and the financial terms and conditions of its application, shall be subject of a separate instrument executed between the Licensor and the Licensee. Article 8 - LIABILITY 8.1 Subject to the provisions of Article 8.2, the Licensee shall be entitled to claim compensation for any direct loss it may have suffered from the Software as a result of a fault on the part of the relevant Licensor, subject to providing evidence thereof. 8.2 The Licensor's liability is limited to the commitments made under this Agreement and shall not be incurred as a result of in particular: (i) loss due the Licensee's total or partial failure to fulfill its obligations, (ii) direct or consequential loss that is suffered by the Licensee due to the use or performance of the Software, and (iii) more generally, any consequential loss. In particular the Parties expressly agree that any or all pecuniary or business loss (i.e. loss of data, loss of profits, operating loss, loss of customers or orders, opportunity cost, any disturbance to business activities) or any or all legal proceedings instituted against the Licensee by a third party, shall constitute consequential loss and shall not provide entitlement to any or all compensation from the Licensor. Article 9 - WARRANTY 9.1 The Licensee acknowledges that the scientific and technical state-of-the-art when the Software was distributed did not enable all possible uses to be tested and verified, nor for the presence of possible defects to be detected. In this respect, the Licensee's attention has been drawn to the risks associated with loading, using, modifying and/or developing and reproducing the Software which are reserved for experienced users. The Licensee shall be responsible for verifying, by any or all means, the suitability of the product for its requirements, its good working order, and for ensuring that it shall not cause damage to either persons or properties. 9.2 The Licensor hereby represents, in good faith, that it is entitled to grant all the rights over the Software (including in particular the rights set forth in Article 5). 9.3 The Licensee acknowledges that the Software is supplied "as is" by the Licensor without any other express or tacit warranty, other than that provided for in Article 9.2 and, in particular, without any warranty as to its commercial value, its secured, safe, innovative or relevant nature. Specifically, the Licensor does not warrant that the Software is free from any error, that it will operate without interruption, that it will be compatible with the Licensee's own equipment and software configuration, nor that it will meet the Licensee's requirements. 9.4 The Licensor does not either expressly or tacitly warrant that the Software does not infringe any third party intellectual property right relating to a patent, software or any other property right. Therefore, the Licensor disclaims any and all liability towards the Licensee arising out of any or all proceedings for infringement that may be instituted in respect of the use, modification and redistribution of the Software. Nevertheless, should such proceedings be instituted against the Licensee, the Licensor shall provide it with technical and legal assistance for its defense. Such technical and legal assistance shall be decided on a case-by-case basis between the relevant Licensor and the Licensee pursuant to a memorandum of understanding. The Licensor disclaims any and all liability as regards the Licensee's use of the name of the Software. No warranty is given as regards the existence of prior rights over the name of the Software or as regards the existence of a trademark. Article 10 - TERMINATION 10.1 In the event of a breach by the Licensee of its obligations hereunder, the Licensor may automatically terminate this Agreement thirty (30) days after notice has been sent to the Licensee and has remained ineffective. 10.2 A Licensee whose Agreement is terminated shall no longer be authorized to use, modify or distribute the Software. However, any licenses that it may have granted prior to termination of the Agreement shall remain valid subject to their having been granted in compliance with the terms and conditions hereof. Article 11 - MISCELLANEOUS 11.1 EXCUSABLE EVENTS Neither Party shall be liable for any or all delay, or failure to perform the Agreement, that may be attributable to an event of force majeure, an act of God or an outside cause, such as defective functioning or interruptions of the electricity or telecommunications networks, network paralysis following a virus attack, intervention by government authorities, natural disasters, water damage, earthquakes, fire, explosions, strikes and labor unrest, war, etc. 11.2 Any failure by either Party, on one or more occasions, to invoke one or more of the provisions hereof, shall under no circumstances be interpreted as being a waiver by the interested Party of its right to invoke said provision(s) subsequently. 11.3 The Agreement cancels and replaces any or all previous agreements, whether written or oral, between the Parties and having the same purpose, and constitutes the entirety of the agreement between said Parties concerning said purpose. No supplement or modification to the terms and conditions hereof shall be effective as between the Parties unless it is made in writing and signed by their duly authorized representatives. 11.4 In the event that one or more of the provisions hereof were to conflict with a current or future applicable act or legislative text, said act or legislative text shall prevail, and the Parties shall make the necessary amendments so as to comply with said act or legislative text. All other provisions shall remain effective. Similarly, invalidity of a provision of the Agreement, for any reason whatsoever, shall not cause the Agreement as a whole to be invalid. 11.5 LANGUAGE The Agreement is drafted in both French and English and both versions are deemed authentic. Article 12 - NEW VERSIONS OF THE AGREEMENT 12.1 Any person is authorized to duplicate and distribute copies of this Agreement. 12.2 So as to ensure coherence, the wording of this Agreement is protected and may only be modified by the authors of the License, who reserve the right to periodically publish updates or new versions of the Agreement, each with a separate number. These subsequent versions may address new issues encountered by Free Software. 12.3 Any Software distributed under a given version of the Agreement may only be subsequently distributed under the same version of the Agreement or a subsequent version. Article 13 - GOVERNING LAW AND JURISDICTION 13.1 The Agreement is governed by French law. The Parties agree to endeavor to seek an amicable solution to any disagreements or disputes that may arise during the performance of the Agreement. 13.2 Failing an amicable solution within two (2) months as from their occurrence, and unless emergency proceedings are necessary, the disagreements or disputes shall be referred to the Paris Courts having jurisdiction, by the more diligent Party. Version 1.0 dated 2006-09-05. mczify-1.5.0-2.0-8.16/Make000066400000000000000000000002171445325544600145210ustar00rootroot00000000000000theories/ssrZ.v theories/zify_ssreflect.v theories/zify_algebra.v theories/zify.v -R theories mathcomp.zify -arg -w -arg -notation-overridden mczify-1.5.0-2.0-8.16/Make.test-suite000066400000000000000000000002211445325544600166210ustar00rootroot00000000000000examples/boolean.v examples/divmod.v examples/zagier.v examples/test_ssreflect.v examples/test_algebra.v -I . -arg -w -arg -notation-overridden mczify-1.5.0-2.0-8.16/Makefile000066400000000000000000000035461445325544600153710ustar00rootroot00000000000000# KNOWNTARGETS will not be passed along to CoqMakefile KNOWNTARGETS := Makefile.coq Makefile.test-suite.coq test-suite \ clean cleanall distclean # KNOWNFILES will not get implicit targets from the final rule, and so # depending on them won't invoke the submake # Warning: These files get declared as PHONY, so any targets depending # on them always get rebuilt KNOWNFILES := Makefile Make Make.test-suite .DEFAULT_GOAL := invoke-coqmakefile ifneq "$(TEST_SKIP_BUILD)" "" TEST_DEP := LIBRARY_PATH := else TEST_DEP := invoke-coqmakefile LIBRARY_PATH := -R theories mathcomp.zify endif COQMAKEFILE = $(COQBIN)coq_makefile COQMAKE = $(MAKE) --no-print-directory -f Makefile.coq COQMAKE_TESTSUITE = $(MAKE) --no-print-directory -f Makefile.test-suite.coq Makefile.coq: Makefile Make $(COQMAKEFILE) -f Make -o Makefile.coq Makefile.test-suite.coq: Makefile Make.test-suite $(COQMAKEFILE) -f Make.test-suite $(LIBRARY_PATH) -o Makefile.test-suite.coq invoke-coqmakefile: Makefile.coq $(COQMAKE) $(filter-out $(KNOWNTARGETS),$(MAKECMDGOALS)) test-suite: Makefile.test-suite.coq invoke-coqmakefile $(COQMAKE_TESTSUITE) clean:: @if [ -f Makefile.coq ]; then $(COQMAKE) clean; fi @if [ -f Makefile.test-suite.coq ]; then $(COQMAKE_TESTSUITE) clean; fi cleanall:: @if [ -f Makefile.coq ]; then $(COQMAKE) cleanall; fi @if [ -f Makefile.test-suite.coq ]; then $(COQMAKE_TESTSUITE) cleanall; fi distclean:: cleanall rm -f Makefile.coq Makefile.coq.conf rm -f Makefile.test-suite.coq Makefile.test-suite.coq.conf .PHONY: invoke-coqmakefile $(KNOWNFILES) #################################################################### ## Your targets here ## #################################################################### # This should be the last rule, to handle any targets not declared above %: invoke-coqmakefile @true mczify-1.5.0-2.0-8.16/README.md000066400000000000000000000033761445325544600152110ustar00rootroot00000000000000 # Mczify [![Docker CI][docker-action-shield]][docker-action-link] [docker-action-shield]: https://github.com/math-comp/mczify/workflows/Docker%20CI/badge.svg?branch=master [docker-action-link]: https://github.com/math-comp/mczify/actions?query=workflow:"Docker%20CI" This small library enables the use of the Micromega arithmetic solvers of Coq for goals stated with the definitions of the Mathematical Components library by extending the zify tactic. ## Meta - Author(s): - Kazuhiko Sakaguchi (initial) - License: [CeCILL-B Free Software License Agreement](CeCILL-B) - Compatible Coq versions: 8.16 or later - Additional dependencies: - [MathComp](https://math-comp.github.io) ssreflect 2.0 or later - [MathComp](https://math-comp.github.io) algebra - Coq namespace: `mathcomp.zify` - Related publication(s): none ## Building and installation instructions The easiest way to install the latest released version of Mczify 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-mathcomp-zify ``` To instead build and install manually, do: ``` shell git clone https://github.com/math-comp/mczify.git cd mczify make # or make -j make install ``` ## File contents - `zify_ssreflect.v`: Z-ification instances for the `coq-mathcomp-ssreflect` library - `zify_algebra.v`: Z-ification instances for the `coq-mathcomp-algebra` library - `zify.v`: re-exports all the Z-ification instances - `ssrZ.v`: provides a minimal facility for reasoning about `Z` and relating `Z` and `int` mczify-1.5.0-2.0-8.16/_CoqProject000066400000000000000000000000741445325544600160550ustar00rootroot00000000000000-R theories mathcomp.zify -arg -w -arg -notation-overridden mczify-1.5.0-2.0-8.16/coq-mathcomp-zify.opam000066400000000000000000000016141445325544600201500ustar00rootroot00000000000000# This file was generated from `meta.yml`, please do not edit manually. # Follow the instructions on https://github.com/coq-community/templates to regenerate. opam-version: "2.0" maintainer: "kazuhiko.sakaguchi@inria.fr" version: "dev" homepage: "https://github.com/math-comp/mczify" dev-repo: "git+https://github.com/math-comp/mczify.git" bug-reports: "https://github.com/math-comp/mczify/issues" license: "CECILL-B" synopsis: "Micromega tactics for Mathematical Components" description: """ This small library enables the use of the Micromega arithmetic solvers of Coq for goals stated with the definitions of the Mathematical Components library by extending the zify tactic.""" build: [make "-j%{jobs}%"] install: [make "install"] depends: [ "coq" {>= "8.16"} "coq-mathcomp-ssreflect" {>= "2.0"} "coq-mathcomp-algebra" ] tags: [ "logpath:mathcomp.zify" ] authors: [ "Kazuhiko Sakaguchi" ] mczify-1.5.0-2.0-8.16/examples/000077500000000000000000000000001445325544600155375ustar00rootroot00000000000000mczify-1.5.0-2.0-8.16/examples/boolean.v000066400000000000000000000003211445325544600173410ustar00rootroot00000000000000From mathcomp Require Import all_ssreflect zify. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Lemma odd_add (n m : nat) : odd (m + n) = odd m (+) odd n. Proof. lia. Qed. mczify-1.5.0-2.0-8.16/examples/divmod.v000066400000000000000000000011721445325544600172110ustar00rootroot00000000000000From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path. From mathcomp Require Import div choice fintype tuple finfun bigop finset prime. From mathcomp Require Import binomial ssralg countalg ssrnum ssrint rat intdiv. From mathcomp Require Import zify. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Lemma dvdz_lcm_6_4 (m : int) : (6 %| m -> 4 %| m -> 12 %| m)%Z. Proof. lia. Qed. Lemma dvdz_lcm_6_4' (m : int) : (6 %| m)%Z && (4 %| m)%Z = (12 %| m)%Z. Proof. lia. Qed. Lemma divzMA_ge0 (m n p : int) : (0 <= n)%R -> (m %/ (n * p))%Z = ((m %/ n) %/ p)%Z. Proof. nia. Qed. mczify-1.5.0-2.0-8.16/examples/test_algebra.v000066400000000000000000000027511445325544600203670ustar00rootroot00000000000000From Coq Require Import BinInt Zify. From mathcomp Require Import all_ssreflect all_algebra zify ssrZ. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Delimit Scope Z_scope with Z. Fact test_zero_nat : Z.of_nat 0%R = 0%Z. Proof. zify_op; reflexivity. Qed. Fact test_add_nat n m : Z.of_nat (n + m)%R = (Z.of_nat n + Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_one_nat : Z.of_nat 1%R = 1%Z. Proof. zify_op; reflexivity. Qed. Fact test_mul_nat n m : Z.of_nat (n * m)%R = (Z.of_nat n * Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_natmul_nat n m : Z.of_nat (n *+ m)%R = (Z.of_nat n * Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_exp_nat n m : Z.of_nat (n ^+ m)%R = (Z.of_nat n ^ Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_zero_N : Z.of_N 0%R = 0%Z. Proof. zify_op; reflexivity. Qed. Fact test_add_N n m : Z.of_N (n + m)%R = (Z.of_N n + Z.of_N m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_one_N : Z.of_N 1%R = 1%Z. Proof. zify_op; reflexivity. Qed. Fact test_mul_N n m : Z.of_N (n * m)%R = (Z.of_N n * Z.of_N m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_natmul_N n m : Z.of_N (n *+ m)%R = (Z.of_N n * Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_exp_N n m : Z.of_N (n ^+ m)%R = (Z.of_N n ^ Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_unit_int m : m \is a GRing.unit = (Z_of_int m =? 1)%Z || (Z_of_int m =? - 1)%Z. Proof. zify_pre_hook; zify_op; reflexivity. Qed. mczify-1.5.0-2.0-8.16/examples/test_ssreflect.v000066400000000000000000000255761445325544600207760ustar00rootroot00000000000000From Coq Require Import BinInt Zify. From mathcomp Require Import all_ssreflect zify ssrZ. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. (* FIXME: dual instances are not exported *) Import Order.Theory. Local Delimit Scope Z_scope with Z. Implicit Types (b : bool) (n m : nat). (******************************************************************************) (* ssrbool *) (******************************************************************************) Fact test_andb b1 b2 : b1 (+) b2 = Bool.eqb b1 (~~ b2). Proof. zify_op; reflexivity. Qed. Fact test_eqb b1 b2 : eqb b1 b2 = Bool.eqb b1 b2. Proof. zify_op; reflexivity. Qed. Fact test_eq_op_bool b1 b2 : (b1 == b2) = Bool.eqb b1 b2. Proof. zify_op; reflexivity. Qed. Fact test_le_bool b1 b2 : (b1 <= b2)%O = implb b1 b2. Proof. zify_op; reflexivity. Qed. Fact test_ge_bool b1 b2 : (b1 >= b2)%O = implb b2 b1. Proof. zify_op; reflexivity. Qed. Fact test_dual_le_bool (b1 b2 : bool^d) : (b1 <=^d b2)%O = implb b2 b1. Proof. zify_op; reflexivity. Qed. Fact test_dual_ge_bool (b1 b2 : bool^d) : (b1 >=^d b2)%O = implb b1 b2. Proof. zify_op; reflexivity. Qed. Fact test_lt_bool b1 b2 : (b1 < b2)%O = ~~ b1 && b2. Proof. zify_op; reflexivity. Qed. Fact test_gt_bool b1 b2 : (b1 > b2)%O = ~~ b2 && b1. Proof. zify_op; reflexivity. Qed. Fact test_dual_lt_bool (b1 b2 : bool^d) : (b1 <^d b2)%O = b1 && ~~ b2. Proof. zify_op; reflexivity. Qed. Fact test_dual_gt_bool (b1 b2 : bool^d) : (b1 >^d b2)%O = b2 && ~~ b1. Proof. zify_op; reflexivity. Qed. (* FIXME: ge, gt *) Fact test_min_bool b1 b2 : Order.min b1 b2 = b1 && b2. Proof. zify_op; reflexivity. Qed. Fact test_max_bool b1 b2 : Order.max b1 b2 = b1 || b2. Proof. zify_op; reflexivity. Qed. Fact test_dual_min_bool (b1 b2 : bool^d) : Order.dual_min b1 b2 = b1 || b2. Proof. zify_op; reflexivity. Qed. Fact test_dual_max_bool (b1 b2 : bool^d) : Order.dual_max b1 b2 = b1 && b2. Proof. zify_op; reflexivity. Qed. (* FIXME: meet and join below are broken but the tests pass because they are *) (* convertible anyway. *) Fact test_meet_bool b1 b2 : (b1 `&` b2)%O = b1 && b2. Proof. zify_op; reflexivity. Qed. Fact test_join_bool b1 b2 : (b1 `|` b2)%O = b1 || b2. Proof. zify_op; reflexivity. Qed. Fact test_dual_meet_bool (b1 b2 : bool^d) : (b1 `&^d` b2)%O = b1 || b2. Proof. zify_op; reflexivity. Qed. Fact test_dual_join_bool (b1 b2 : bool^d) : (b1 `|^d` b2)%O = b1 && b2. Proof. zify_op; reflexivity. Qed. Fact test_bottom_bool : \bot%O = false :> bool. Proof. zify_op; reflexivity. Qed. Fact test_top_bool : \top%O = true :> bool. Proof. zify_op; reflexivity. Qed. (* FIXME: Notations 0^d and 1^d are broken. *) Fact test_dual_bottom_bool : \bot%O = true :> bool^d. Proof. zify_op; reflexivity. Qed. Fact test_dual_top_bool : \top%O = false :> bool^d. Proof. zify_op; reflexivity. Qed. Fact test_sub_bool b1 b2 : (b1 `\` b2)%O = b1 && ~~ b2. Proof. zify_op; reflexivity. Qed. Fact test_compl_bool b : (~` b)%O = ~~ b. Proof. zify_op; reflexivity. Qed. (******************************************************************************) (* ssrnat *) (******************************************************************************) Fact test_eqn n m : eqn n m = Z.eqb (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_eq_op_nat n m : (n == m) = Z.eqb (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_addn_rec n m : Z.of_nat (n + m)%Nrec = (Z.of_nat n + Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_addn n m : Z.of_nat (n + m) = (Z.of_nat n + Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_addn_trec n m : Z.of_nat (NatTrec.add n m) = (Z.of_nat n + Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_subn_rec n m : Z.of_nat (n - m)%Nrec = Z.max 0 (Z.of_nat n - Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_subn n m : Z.of_nat (n - m) = Z.max 0 (Z.of_nat n - Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_muln_rec n m : Z.of_nat (n * m)%Nrec = (Z.of_nat n * Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_muln n m : Z.of_nat (n * m) = (Z.of_nat n * Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_muln_trec n m : Z.of_nat (NatTrec.mul n m) = (Z.of_nat n * Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_leq n m : (n <= m) = (Z.of_nat n <=? Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. (* FIXME: geq, ltn, gtn *) Fact test_minn n m : Z.of_nat (minn n m) = Z.min (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_maxn n m : Z.of_nat (maxn n m) = Z.max (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_nat_of_bool b : Z.of_nat (nat_of_bool b) = Z.b2z b. Proof. zify_op; reflexivity. Qed. Fact test_double n : Z.of_nat n.*2 = (2 * Z.of_nat n)%Z. Proof. zify_op; reflexivity. Qed. Fact test_double_trec n : Z.of_nat (NatTrec.double n) = (2 * Z.of_nat n)%Z. Proof. zify_op; reflexivity. Qed. Fact test_expn n m : Z.of_nat (n ^ m) = (Z.of_nat n ^ Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_expn_trec n m : Z.of_nat (NatTrec.exp n m) = (Z.of_nat n ^ Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_eq_op_N (n m : N) : (n == m) = (Z.of_N n =? Z.of_N m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_nat_of_pos p : Z.of_nat (nat_of_pos p) = Z.pos p. Proof. zify_op; reflexivity. Qed. Fact test_nat_of_bin (n : N) : Z.of_nat (nat_of_bin n) = Z.of_N n. Proof. zify_op; reflexivity. Qed. Fact test_pos_of_nat n m : Z.pos (pos_of_nat n m) = Z.max 1 (Z.of_nat n * 2 - Z.of_nat m + 1). Proof. zify_op; reflexivity. Qed. Fact test_bin_of_nat n : Z.of_N (bin_of_nat n) = Z.of_nat n. Proof. zify_op; reflexivity. Qed. Fact test_le_nat n m : (n <= m)%O = (Z.of_nat n <=? Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_ge_nat n m : (n >= m)%O = (Z.of_nat m <=? Z.of_nat n)%Z. Proof. zify_op; reflexivity. Qed. Fact test_dual_le_nat (n m : nat^d) : (n <=^d m)%O = (Z.of_nat n >=? Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_dual_ge_nat (n m : nat^d) : (n >=^d m)%O = (Z.of_nat m >=? Z.of_nat n)%Z. Proof. zify_op; reflexivity. Qed. Fact test_lt_nat n m : (n < m)%O = (Z.of_nat n m)%O = (Z.of_nat m ? Z.of_nat m)%Z. Proof. zify_op; reflexivity. Qed. Fact test_dual_gt_nat (n m : nat^d) : (n >^d m)%O = (Z.of_nat m >? Z.of_nat n)%Z. Proof. zify_op; reflexivity. Qed. (* FIXME: ge, gt *) Fact test_min_nat n m : Z.of_nat (Order.min n m) = Z.min (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_max_nat n m : Z.of_nat (Order.max n m) = Z.max (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_dual_min_nat (n m : nat^d) : Z.of_nat (Order.dual_min n m) = Z.max (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_dual_max_nat (n m : nat^d) : Z.of_nat (Order.dual_max n m) = Z.min (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_meet_nat n m : Z.of_nat (n `&` m)%O = Z.min (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_join_nat n m : Z.of_nat (n `|` m)%O = Z.max (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_dual_meet_nat (n m : nat^d) : Z.of_nat (n `&^d` m)%O = Z.max (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_dual_join_nat (n m : nat^d) : Z.of_nat (n `|^d` m)%O = Z.min (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_bottom_nat : Z.of_nat \bot%O = 0%Z. Proof. zify_op; reflexivity. Qed. (******************************************************************************) (* div (divn, modn, dvdn, gcdn, lcmn, and coprime) *) (******************************************************************************) Notation divZ := zify_ssreflect.SsreflectZifyInstances.divZ. Notation modZ := zify_ssreflect.SsreflectZifyInstances.modZ. Fact test_divn n m : Z.of_nat (divn n m) = divZ (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_modn n m : Z.of_nat (modn n m) = modZ (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_dvdn n m : dvdn n m = (modZ (Z.of_nat m) (Z.of_nat n) =? 0)%Z. Proof. zify_op; reflexivity. Qed. Fact test_odd n : odd n = (modZ (Z.of_nat n) 2 =? 1)%Z. Proof. zify_op; reflexivity. Qed. Fact test_odd_trec n : NatTrec.odd n = (modZ (Z.of_nat n) 2 =? 1)%Z. Proof. zify_op; reflexivity. Qed. Fact test_half n : Z.of_nat (half n) = divZ (Z.of_nat n) 2. Proof. zify_op; reflexivity. Qed. Fact test_uphalf n : Z.of_nat (uphalf n) = divZ (Z.of_nat n + 1) 2. Proof. zify_op; reflexivity. Qed. Fact test_gcdn n m : Z.of_nat (gcdn n m) = Z.gcd (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_lcmn n m : Z.of_nat (lcmn n m) = Z.lcm (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_coprime n m : coprime n m = (Z.gcd (Z.of_nat n) (Z.of_nat m) =? 1)%Z. Proof. zify_op; reflexivity. Qed. (******************************************************************************) (* natdvd in order.v *) (******************************************************************************) Fact test_le_natdvd (n m : natdvd) : (n <= m)%O = (modZ (Z.of_nat m) (Z.of_nat n) =? 0)%Z. Proof. zify_op; reflexivity. Qed. Fact test_lt_natdvd (n m : natdvd) : (n < m)%O = ~~ (Z.of_nat m =? Z.of_nat n)%Z && (modZ (Z.of_nat m) (Z.of_nat n) =? 0)%Z. Proof. zify_op; reflexivity. Qed. Fact test_dual_le_natdvd (n m : natdvd^d) : (m <= n)%O = (modZ (Z.of_nat m) (Z.of_nat n) =? 0)%Z. Proof. zify_op; reflexivity. Qed. Fact test_dual_lt_natdvd (n m : natdvd^d) : (m < n)%O = ~~ (Z.of_nat m =? Z.of_nat n)%Z && (modZ (Z.of_nat m) (Z.of_nat n) =? 0)%Z. Proof. zify_op; reflexivity. Qed. (* FIXME: ge, gt *) Fact test_meet_natdvd (n m : natdvd) : Z.of_nat (n `&` m)%O = Z.gcd (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_join_natdvd (n m : natdvd) : Z.of_nat (n `|` m)%O = Z.lcm (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_dual_meet_natdvd (n m : natdvd^d) : Z.of_nat (n `&` m)%O = Z.lcm (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_dual_join_natdvd (n m : natdvd^d) : Z.of_nat (n `|` m)%O = Z.gcd (Z.of_nat n) (Z.of_nat m). Proof. zify_op; reflexivity. Qed. Fact test_bottom_natdvd : Z.of_nat (\bot%O : natdvd) = 1%Z. Proof. zify_op; reflexivity. Qed. Fact test_top_natdvd : Z.of_nat (\top%O : natdvd) = 0%Z. Proof. zify_op; reflexivity. Qed. Fact test_dual_bottom_natdvd : Z.of_nat (\bot^d%O : natdvd^d) = 0%Z. Proof. zify_op; reflexivity. Qed. Fact test_dual_top_natdvd : Z.of_nat (\top^d%O : natdvd^d) = 1%Z. Proof. zify_op; reflexivity. Qed. mczify-1.5.0-2.0-8.16/examples/zagier.v000066400000000000000000000007241445325544600172120ustar00rootroot00000000000000From mathcomp Require Import all_ssreflect zify. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Lemma zagierK x y z : 0 < x -> 0 < z -> let zagier t := let: (x, y, z) := t in if x < y - z then (x + z.*2, z, y - z - x) else if x < y.*2 then (y.*2 - x, y, x + z - y) else (x - y.*2, x + z - y, y) in zagier (zagier (x, y, z)) = (x, y, z). Proof. move=> xP zP /=. repeat case: leqP => *; congr (_,_,_); lia. Qed. mczify-1.5.0-2.0-8.16/meta.yml000066400000000000000000000031651445325544600153770ustar00rootroot00000000000000--- fullname: Mczify shortname: mczify opam_name: coq-mathcomp-zify organization: math-comp action: true synopsis: >- Micromega tactics for Mathematical Components description: |- This small library enables the use of the Micromega arithmetic solvers of Coq for goals stated with the definitions of the Mathematical Components library by extending the zify tactic. authors: - name: Kazuhiko Sakaguchi initial: true opam-file-maintainer: kazuhiko.sakaguchi@inria.fr license: fullname: CeCILL-B Free Software License Agreement identifier: CECILL-B file: CeCILL-B supported_coq_versions: text: 8.16 or later opam: '{>= "8.16"}' tested_coq_nix_versions: tested_coq_opam_versions: - version: '2.0.0-coq-8.16' repo: 'mathcomp/mathcomp' - version: '2.0.0-coq-8.17' repo: 'mathcomp/mathcomp' - version: 'coq-8.16' repo: 'mathcomp/mathcomp-dev' - version: 'coq-8.17' repo: 'mathcomp/mathcomp-dev' - version: 'coq-dev' repo: 'mathcomp/mathcomp-dev' dependencies: - opam: name: coq-mathcomp-ssreflect version: '{>= "2.0"}' description: |- [MathComp](https://math-comp.github.io) ssreflect 2.0 or later - opam: name: coq-mathcomp-algebra description: |- [MathComp](https://math-comp.github.io) algebra namespace: mathcomp.zify documentation: |- ## File contents - `zify_ssreflect.v`: Z-ification instances for the `coq-mathcomp-ssreflect` library - `zify_algebra.v`: Z-ification instances for the `coq-mathcomp-algebra` library - `zify.v`: re-exports all the Z-ification instances - `ssrZ.v`: provides a minimal facility for reasoning about `Z` and relating `Z` and `int` --- mczify-1.5.0-2.0-8.16/theories/000077500000000000000000000000001445325544600155435ustar00rootroot00000000000000mczify-1.5.0-2.0-8.16/theories/ssrZ.v000066400000000000000000000200331445325544600166710ustar00rootroot00000000000000From Coq Require Import ZArith. From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path. From mathcomp Require Import div choice fintype tuple finfun bigop finset prime. From mathcomp Require Import order binomial ssralg countalg ssrnum ssrint. From mathcomp Require Import zify_ssreflect. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import Order.Theory GRing.Theory Num.Theory. Definition int_of_Z (n : Z) : int := match n with | Z0 => Posz 0 | Zpos p => Posz (Pos.to_nat p) | Zneg p => Negz (Pos.to_nat p).-1 end. Definition Z_of_int (n : int) : Z := match n with | Posz n => Z.of_nat n | Negz n' => Z.opp (Z.of_nat (n' + 1)) end. Lemma int_of_ZK : cancel int_of_Z Z_of_int. Proof. by case=> //= p; lia. Qed. Lemma Z_of_intK : cancel Z_of_int int_of_Z. Proof. case=> [[|n]|n] //=. congr Posz; lia. rewrite addnC /=; congr Negz; lia. Qed. Module Instances. (* Instances taken from math-comp/math-comp#1031, authored by Pierre Roux *) (* TODO: remove them when we drop support for MathComp 2.0 *) #[export] HB.instance Definition _ := GRing.isNmodule.Build nat addnA addnC add0n. #[export] HB.instance Definition _ := GRing.Nmodule_isComSemiRing.Build nat mulnA mulnC mul1n mulnDl mul0n erefl. #[export] HB.instance Definition _ (V : nmodType) (x : V) := GRing.isSemiAdditive.Build nat V (GRing.natmul x) (mulr0n x, mulrnDr x). #[export] HB.instance Definition _ (R : semiRingType) := GRing.isMultiplicative.Build nat R (GRing.natmul 1) (natrM R, mulr1n 1). Fact Posz_is_semi_additive : semi_additive Posz. Proof. by []. Qed. #[export] HB.instance Definition _ := GRing.isSemiAdditive.Build nat int Posz Posz_is_semi_additive. Fact Posz_is_multiplicative : multiplicative Posz. Proof. by []. Qed. #[export] HB.instance Definition _ := GRing.isMultiplicative.Build nat int Posz Posz_is_multiplicative. (* end *) #[export] HB.instance Definition _ := Countable.copy N (can_type nat_of_binK). #[export] HB.instance Definition _ := GRing.isNmodule.Build N Nplus_assoc Nplus_comm Nplus_0_l. #[export] HB.instance Definition _ := GRing.Nmodule_isComSemiRing.Build N Nmult_assoc Nmult_comm Nmult_1_l Nmult_plus_distr_r N.mul_0_l isT. Fact bin_of_nat_is_semi_additive : semi_additive bin_of_nat. Proof. by split=> //= m n; rewrite /GRing.add /=; lia. Qed. #[export] HB.instance Definition _ := GRing.isSemiAdditive.Build nat N bin_of_nat bin_of_nat_is_semi_additive. Fact nat_of_bin_is_semi_additive : semi_additive nat_of_bin. Proof. by split=> //= m n; rewrite /GRing.add /=; lia. Qed. #[export] HB.instance Definition _ := GRing.isSemiAdditive.Build N nat nat_of_bin nat_of_bin_is_semi_additive. Fact bin_of_nat_is_multiplicative : multiplicative bin_of_nat. Proof. by split=> // m n; rewrite /GRing.mul /=; lia. Qed. #[export] HB.instance Definition _ := GRing.isMultiplicative.Build nat N bin_of_nat bin_of_nat_is_multiplicative. Fact nat_of_bin_is_multiplicative : multiplicative nat_of_bin. Proof. by split=> // m n; rewrite /GRing.mul /=; lia. Qed. #[export] HB.instance Definition _ := GRing.isMultiplicative.Build N nat nat_of_bin nat_of_bin_is_multiplicative. Fact N_of_nat_is_semi_additive : semi_additive N.of_nat. Proof. by split=> //= m n; rewrite /GRing.add /=; lia. Qed. #[export] HB.instance Definition _ := GRing.isSemiAdditive.Build nat N N.of_nat N_of_nat_is_semi_additive. Fact N_to_nat_is_semi_additive : semi_additive N.to_nat. Proof. by split=> //= m n; rewrite /GRing.add /=; lia. Qed. #[export] HB.instance Definition _ := GRing.isSemiAdditive.Build N nat N.to_nat N_to_nat_is_semi_additive. Fact N_of_nat_is_multiplicative : multiplicative N.of_nat. Proof. by split=> // m n; rewrite /GRing.mul /=; lia. Qed. #[export] HB.instance Definition _ := GRing.isMultiplicative.Build nat N N.of_nat N_of_nat_is_multiplicative. Fact N_to_nat_is_multiplicative : multiplicative N.to_nat. Proof. by split=> // m n; rewrite /GRing.mul /=; lia. Qed. #[export] HB.instance Definition _ := GRing.isMultiplicative.Build N nat N.to_nat N_to_nat_is_multiplicative. Implicit Types (m n : Z). Fact eqZP : Equality.axiom Z.eqb. Proof. by move=> x y; apply: (iffP idP); lia. Qed. #[export] HB.instance Definition _ := hasDecEq.Build Z eqZP. #[export] HB.instance Definition _ := Countable.copy Z (can_type int_of_ZK). #[export] HB.instance Definition _ := GRing.isZmodule.Build Z Zplus_assoc Zplus_comm Zplus_0_l Zplus_opp_l. #[export] HB.instance Definition _ := GRing.Zmodule_isComRing.Build Z Zmult_assoc Zmult_comm Zmult_1_l Zmult_plus_distr_l isT. Definition unitZ := [qualify a n : Z | (n == Z.pos xH) || (n == Z.neg xH)]. Definition invZ n := n. Fact mulVZ : {in unitZ, left_inverse 1%R invZ *%R}. Proof. by move=> n /pred2P[] ->. Qed. Fact unitZPl m n : (n * m = 1)%R -> m \is a unitZ. Proof. case: m n => [|[m|m|]|[m|m|]] [|n|n] //= []; lia. Qed. Fact invZ_out : {in [predC unitZ], invZ =1 id}. Proof. exact. Qed. #[export] HB.instance Definition _ := GRing.ComRing_hasMulInverse.Build Z mulVZ unitZPl invZ_out. Fact idomain_axiomZ m n : (m * n = 0)%R -> (m == 0%R) || (n == 0%R). Proof. by case: m n => [|m|m] []. Qed. #[export] HB.instance Definition _ := GRing.ComUnitRing_isIntegral.Build Z idomain_axiomZ. Fact leZ_add m n : Z.leb 0 m -> Z.leb 0 n -> Z.leb 0 (m + n). Proof. lia. Qed. Fact leZ_mul m n : Z.leb 0 m -> Z.leb 0 n -> Z.leb 0 (m * n). Proof. lia. Qed. Fact leZ_anti m : Z.leb 0 m -> Z.leb m 0 -> m = Z0. Proof. lia. Qed. Fact subZ_ge0 m n : Z.leb 0 (n - m)%R = Z.leb m n. Proof. by rewrite /GRing.add /GRing.opp /=; lia. Qed. Fact leZ_total m n : Z.leb m n || Z.leb n m. Proof. lia. Qed. Fact normZN m : Z.abs (- m) = Z.abs m. Proof. lia. Qed. Fact geZ0_norm m : Z.leb 0 m -> Z.abs m = m. Proof. lia. Qed. Fact ltZ_def m n : (Z.ltb m n) = (n != m) && (Z.leb m n). Proof. by rewrite eqE /=; lia. Qed. #[export] HB.instance Definition _ := Num.IntegralDomain_isLeReal.Build Z leZ_add leZ_mul leZ_anti subZ_ge0 (leZ_total 0) normZN geZ0_norm ltZ_def. Fact Z_of_intE (n : int) : Z_of_int n = (n%:~R)%R. Proof. have Hnat (m : nat) : Z.of_nat m = (m%:R)%R. by elim: m => // m; rewrite Nat2Z.inj_succ -Z.add_1_l mulrS => ->. case: n => n; rewrite /intmul /=; first exact: Hnat. by congr Z.opp; rewrite Nat2Z.inj_add /= mulrSr Hnat. Qed. Fact Z_of_int_is_additive : additive Z_of_int. Proof. by move=> m n; rewrite !Z_of_intE raddfB. Qed. #[export] HB.instance Definition _ := GRing.isAdditive.Build int Z Z_of_int Z_of_int_is_additive. Fact int_of_Z_is_additive : additive int_of_Z. Proof. exact: can2_additive Z_of_intK int_of_ZK. Qed. #[export] HB.instance Definition _ := GRing.isAdditive.Build Z int int_of_Z int_of_Z_is_additive. Fact Z_of_int_is_multiplicative : multiplicative Z_of_int. Proof. by split => // m n; rewrite !Z_of_intE rmorphM. Qed. #[export] HB.instance Definition _ := GRing.isMultiplicative.Build int Z Z_of_int Z_of_int_is_multiplicative. Fact int_of_Z_is_multiplicative : multiplicative int_of_Z. Proof. exact: can2_rmorphism Z_of_intK int_of_ZK. Qed. #[export] HB.instance Definition _ := GRing.isMultiplicative.Build Z int int_of_Z int_of_Z_is_multiplicative. Fact Z_of_nat_is_semi_additive : semi_additive Z.of_nat. Proof. by split=> //= m n; rewrite /GRing.add /=; lia. Qed. #[export] HB.instance Definition _ := GRing.isSemiAdditive.Build nat Z Z.of_nat Z_of_nat_is_semi_additive. Fact Z_of_nat_is_multiplicative : multiplicative Z.of_nat. Proof. by split => // m n; rewrite /GRing.mul /=; lia. Qed. #[export] HB.instance Definition _ := GRing.isMultiplicative.Build nat Z Z.of_nat Z_of_nat_is_multiplicative. Fact Z_of_N_is_semi_additive : semi_additive Z.of_N. Proof. by split=> //= m n; rewrite /GRing.add /=; lia. Qed. #[export] HB.instance Definition _ := GRing.isSemiAdditive.Build N Z Z.of_N Z_of_N_is_semi_additive. Fact Z_of_N_is_multiplicative : multiplicative Z.of_N. Proof. by split => // m n; rewrite /GRing.mul /=; lia. Qed. #[export] HB.instance Definition _ := GRing.isMultiplicative.Build N Z Z.of_N Z_of_N_is_multiplicative. Module Exports. HB.reexport. End Exports. End Instances. Export Instances.Exports. mczify-1.5.0-2.0-8.16/theories/zify.v000066400000000000000000000002431445325544600167120ustar00rootroot00000000000000From Coq Require Export Lia. From mathcomp Require Import zify_ssreflect zify_algebra. Export SsreflectZifyInstances.Exports. Export AlgebraZifyInstances.Exports. mczify-1.5.0-2.0-8.16/theories/zify_algebra.v000066400000000000000000000431751445325544600204020ustar00rootroot00000000000000From Coq Require Import ZArith ZifyClasses ZifyBool. From Coq Require Export Lia. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path. From mathcomp Require Import div choice fintype tuple finfun bigop finset prime. From mathcomp Require Import order binomial ssralg countalg ssrnum ssrint rat. From mathcomp Require Import intdiv. From mathcomp Require Import zify_ssreflect ssrZ. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Module AlgebraZifyInstances. Local Delimit Scope Z_scope with Z. Import Order.Theory GRing.Theory Num.Theory SsreflectZifyInstances. (* TODO: remove natn below when we drop support for MathComp 2.0 *) Local Lemma natn n : n%:R%R = n :> nat. Proof. by elim: n => // n; rewrite mulrS => ->. Qed. (******************************************************************************) (* nat *) (******************************************************************************) #[global] Instance Op_nat_0 : CstOp (0%R : nat) := ZifyInst.Op_O. Add Zify CstOp Op_nat_0. #[global] Instance Op_nat_add : BinOp (+%R : nat -> nat -> nat) := Op_addn. Add Zify BinOp Op_nat_add. #[global] Instance Op_nat_1 : CstOp (1%R : nat) := { TCst := 1%Z; TCstInj := erefl }. Add Zify CstOp Op_nat_1. #[global] Instance Op_nat_mul : BinOp ( *%R : nat -> nat -> nat) := Op_muln. Add Zify BinOp Op_nat_mul. Fact Op_nat_natmul_subproof (n m : nat) : Z.of_nat (n *+ m)%R = (Z.of_nat n * Z.of_nat m)%Z. Proof. by rewrite raddfMn -mulr_natr -[m in RHS]natn rmorph_nat. Qed. #[global] Instance Op_nat_natmul : BinOp (@GRing.natmul _ : nat -> nat -> nat) := { TBOp := Z.mul; TBOpInj := Op_nat_natmul_subproof }. Add Zify BinOp Op_nat_natmul. Fact Op_nat_exp_subproof (n : nat) (m : nat) : Z_of_nat (n ^+ m)%R = (Z_of_int n ^ Z.of_nat m)%Z. Proof. rewrite -Zpower_nat_Z; elim: m => //= m <-; rewrite exprS; lia. Qed. #[global] Instance Op_nat_exp : BinOp (@GRing.exp _ : nat -> nat -> nat) := { TBOp := Z.pow; TBOpInj := Op_nat_exp_subproof }. Add Zify BinOp Op_nat_exp. (******************************************************************************) (* N *) (******************************************************************************) #[global] Instance Op_N_0 : CstOp (0%R : N) := ZifyInst.Op_N_N0. Add Zify CstOp Op_N_0. #[global] Instance Op_N_add : BinOp (+%R : N -> N -> N) := ZifyInst.Op_N_add. Add Zify BinOp Op_N_add. #[global] Instance Op_N_1 : CstOp (1%R : N) := { TCst := 1%Z; TCstInj := erefl }. Add Zify CstOp Op_N_1. #[global] Instance Op_N_mul : BinOp ( *%R : N -> N -> N) := ZifyInst.Op_N_mul. Add Zify BinOp Op_N_mul. Fact Op_N_natmul_subproof (n : N) (m : nat) : Z.of_N (n *+ m)%R = (Z.of_N n * Z.of_nat m)%Z. Proof. by rewrite raddfMn -mulr_natr -[m in RHS]natn rmorph_nat. Qed. #[global] Instance Op_N_natmul : BinOp (@GRing.natmul _ : N -> nat -> N) := { TBOp := Z.mul; TBOpInj := Op_N_natmul_subproof }. Add Zify BinOp Op_N_natmul. Fact Op_N_exp_subproof (n : N) (m : nat) : Z_of_N (n ^+ m)%R = (Z_of_N n ^ Z.of_nat m)%Z. Proof. rewrite -Zpower_nat_Z; elim: m => //= m <-; rewrite exprS; lia. Qed. #[global] Instance Op_N_exp : BinOp (@GRing.exp _ : N -> nat -> N) := { TBOp := Z.pow; TBOpInj := Op_N_exp_subproof }. Add Zify BinOp Op_N_exp. (******************************************************************************) (* ssrint *) (******************************************************************************) #[global] Instance Inj_int_Z : InjTyp int Z := { inj := Z_of_int; pred _ := True; cstr _ := I }. Add Zify InjTyp Inj_int_Z. #[global] Instance Op_Z_of_int : UnOp Z_of_int := { TUOp := id; TUOpInj _ := erefl }. Add Zify UnOp Op_Z_of_int. #[global] Instance Op_int_of_Z : UnOp int_of_Z := { TUOp := id; TUOpInj := int_of_ZK }. Add Zify UnOp Op_int_of_Z. #[global] Instance Op_Posz : UnOp Posz := { TUOp := id; TUOpInj _ := erefl }. Add Zify UnOp Op_Posz. #[global] Instance Op_Negz : UnOp Negz := { TUOp x := (- (x + 1))%Z; TUOpInj := ltac:(simpl; lia) }. Add Zify UnOp Op_Negz. #[global] Instance Op_int_eq : BinRel (@eq int) := { TR := @eq Z; TRInj := ltac:(by split=> [->|/(can_inj Z_of_intK)]) }. Add Zify BinRel Op_int_eq. #[global] Instance Op_int_eq_op : BinOp (@eq_op int : int -> int -> bool) := { TBOp := Z.eqb; TBOpInj := ltac:(move=> [] ? [] ?; do 2 rewrite eqE /=; lia) }. Add Zify BinOp Op_int_eq_op. #[global] Instance Op_int_0 : CstOp (0%R : int) := { TCst := 0%Z; TCstInj := erefl }. Add Zify CstOp Op_int_0. #[global] Instance Op_addz : BinOp intZmod.addz := { TBOp := Z.add; TBOpInj := raddfD _ }. Add Zify BinOp Op_addz. #[global] Instance Op_int_add : BinOp +%R := Op_addz. Add Zify BinOp Op_int_add. #[global] Instance Op_oppz : UnOp intZmod.oppz := { TUOp := Z.opp; TUOpInj := raddfN _ }. Add Zify UnOp Op_oppz. #[global] Instance Op_int_opp : UnOp (@GRing.opp _) := Op_oppz. Add Zify UnOp Op_int_opp. #[global] Instance Op_int_1 : CstOp (1%R : int) := { TCst := 1%Z; TCstInj := erefl }. Add Zify CstOp Op_int_1. #[global] Instance Op_mulz : BinOp intRing.mulz := { TBOp := Z.mul; TBOpInj := rmorphM _ }. Add Zify BinOp Op_mulz. #[global] Instance Op_int_mulr : BinOp *%R := Op_mulz. Add Zify BinOp Op_int_mulr. #[global] Instance Op_int_natmul : BinOp (@GRing.natmul _ : int -> nat -> int) := { TBOp := Z.mul; TBOpInj _ _ := ltac:(rewrite /= pmulrn mulrzz; lia) }. Add Zify BinOp Op_int_natmul. #[global] Instance Op_int_intmul : BinOp ( *~%R%R : int -> int -> int) := { TBOp := Z.mul; TBOpInj _ _ := ltac:(rewrite /= mulrzz; lia) }. Add Zify BinOp Op_int_intmul. #[global] Instance Op_int_scale : BinOp (@GRing.scale _ int^o) := Op_mulz. Add Zify BinOp Op_int_scale. Fact Op_int_exp_subproof n m : Z_of_int (n ^+ m) = (Z_of_int n ^ Z.of_nat m)%Z. Proof. rewrite -Zpower_nat_Z; elim: m => //= m <-; rewrite exprS; lia. Qed. #[global] Instance Op_int_exp : BinOp (@GRing.exp _ : int -> nat -> int) := { TBOp := Z.pow; TBOpInj := Op_int_exp_subproof }. Add Zify BinOp Op_int_exp. #[global] Instance Op_unitz : UnOp (has_quality 1 intUnitRing.unitz : int -> bool) := { TUOp x := (x =? 1)%Z || (x =? - 1)%Z; TUOpInj := ltac:(simpl; lia) }. Add Zify UnOp Op_unitz. #[global] Instance Op_int_unit : UnOp (has_quality 1 GRing.unit) := Op_unitz. Add Zify UnOp Op_int_unit. #[global] Instance Op_invz : UnOp intUnitRing.invz := { TUOp := id; TUOpInj _ := erefl }. Add Zify UnOp Op_invz. #[global] Instance Op_int_inv : UnOp GRing.inv := Op_invz. Add Zify UnOp Op_int_inv. #[global] Instance Op_absz : UnOp absz := { TUOp := Z.abs; TUOpInj := ltac:(case=> ? /=; lia) }. Add Zify UnOp Op_absz. #[global] Instance Op_int_normr : UnOp (Num.norm : int -> int) := { TUOp := Z.abs; TUOpInj := ltac:(rewrite /Num.norm /=; lia) }. Add Zify UnOp Op_int_normr. #[global] Instance Op_lez : BinOp intOrdered.lez := { TBOp := Z.leb; TBOpInj := ltac:(case=> ? [] ? /=; lia) }. Add Zify BinOp Op_lez. #[global] Instance Op_ltz : BinOp intOrdered.ltz := { TBOp := Z.ltb; TBOpInj := ltac:(case=> ? [] ? /=; lia) }. Add Zify BinOp Op_ltz. #[global] Instance Op_int_sgr : UnOp (Num.sg : int -> int) := { TUOp := Z.sgn; TUOpInj := ltac:(case=> [[]|] //=; lia) }. Add Zify UnOp Op_int_sgr. #[global] Instance Op_int_sgz : UnOp (@sgz _) := Op_int_sgr. Add Zify UnOp Op_int_sgz. #[global] Instance Op_int_le : BinOp <=%O := Op_lez. Add Zify BinOp Op_int_le. #[global] Instance Op_int_le' : BinOp (>=^d%O : rel int^d) := Op_lez. Add Zify BinOp Op_int_le'. #[global] Instance Op_int_ge : BinOp (>=%O : int -> int -> bool) := { TBOp := Z.geb; TBOpInj := ltac:(simpl; lia) }. Add Zify BinOp Op_int_ge. #[global] Instance Op_int_ge' : BinOp (<=^d%O : rel int^d) := Op_int_ge. Add Zify BinOp Op_int_ge'. #[global] Instance Op_int_lt : BinOp <%O := Op_ltz. Add Zify BinOp Op_int_lt. #[global] Instance Op_int_lt' : BinOp (>^d%O : rel int^d) := Op_ltz. Add Zify BinOp Op_int_lt'. #[global] Instance Op_int_gt : BinOp (>%O : int -> int -> bool) := { TBOp := Z.gtb; TBOpInj := ltac:(simpl; lia) }. Add Zify BinOp Op_int_gt. #[global] Instance Op_int_gt' : BinOp (<^d%O : rel int^d) := Op_int_gt. Add Zify BinOp Op_int_gt'. #[global] Instance Op_int_min : BinOp (Order.min : int -> int -> int) := { TBOp := Z.min; TBOpInj _ _ := ltac:(case: leP => /=; lia) }. Add Zify BinOp Op_int_min. #[global] Instance Op_int_min' : BinOp ((Order.max : int^d -> _) : int -> int -> int) := { TBOp := Z.min; TBOpInj _ _ := ltac:(case: leP => /=; lia) }. Add Zify BinOp Op_int_min'. #[global] Instance Op_int_max : BinOp (Order.max : int -> int -> int) := { TBOp := Z.max; TBOpInj _ _ := ltac:(case: leP => /=; lia) }. Add Zify BinOp Op_int_max. #[global] Instance Op_int_max' : BinOp ((Order.min : int^d -> _) : int -> int -> int) := { TBOp := Z.max; TBOpInj _ _ := ltac:(case: leP => /=; lia) }. Add Zify BinOp Op_int_max'. #[global] Instance Op_int_meet : BinOp (Order.meet : int -> int -> int) := { TBOp := Z.min; TBOpInj _ _ := ltac:(case: leP => /=; lia) }. Add Zify BinOp Op_int_meet. #[global] Instance Op_int_meet' : BinOp (Order.join : int^d -> _) := Op_int_min. Add Zify BinOp Op_int_meet'. #[global] Instance Op_int_join : BinOp (Order.join : int -> int -> int) := { TBOp := Z.max; TBOpInj _ _ := ltac:(case: leP => /=; lia) }. Add Zify BinOp Op_int_join. #[global] Instance Op_int_join' : BinOp (Order.meet : int^d -> _) := Op_int_max. Add Zify BinOp Op_int_join'. (******************************************************************************) (* ssrZ *) (******************************************************************************) #[global] Instance Op_Z_eq_op : BinOp (eq_op : Z -> Z -> bool) := Op_Zeqb. Add Zify BinOp Op_Z_eq_op. #[global] Instance Op_Z_0 : CstOp (0%R : Z) := { TCst := 0%Z; TCstInj := erefl }. Add Zify CstOp Op_Z_0. #[global] Instance Op_Z_add : BinOp (+%R : Z -> Z -> Z) := { TBOp := Z.add; TBOpInj _ _ := erefl }. Add Zify BinOp Op_Z_add. #[global] Instance Op_Z_opp : UnOp (@GRing.opp _ : Z -> Z) := { TUOp := Z.opp; TUOpInj _ := erefl }. Add Zify UnOp Op_Z_opp. #[global] Instance Op_Z_1 : CstOp (1%R : Z) := { TCst := 1%Z; TCstInj := erefl }. Add Zify CstOp Op_Z_1. #[global] Instance Op_Z_mulr : BinOp ( *%R : Z -> Z -> Z) := { TBOp := Z.mul; TBOpInj _ _ := erefl }. Add Zify BinOp Op_Z_mulr. Fact Op_Z_natmul_subproof (n : Z) (m : nat) : (n *+ m)%R = (n * Z.of_nat m)%Z. Proof. elim: m => [|m]; rewrite (mulr0n, mulrS); lia. Qed. #[global] Instance Op_Z_natmul : BinOp (@GRing.natmul _ : Z -> nat -> Z) := { TBOp := Z.mul; TBOpInj := Op_Z_natmul_subproof }. Add Zify BinOp Op_Z_natmul. #[global] Instance Op_Z_intmul : BinOp ( *~%R%R : Z -> int -> Z) := { TBOp := Z.mul; TBOpInj := ltac:(move=> n [] m; rewrite /intmul /=; lia) }. Add Zify BinOp Op_Z_intmul. #[global] Instance Op_Z_scale : BinOp (@GRing.scale _ Z^o) := Op_Z_mulr. Add Zify BinOp Op_Z_scale. Fact Op_Z_exp_subproof n m : (n ^+ m)%R = (n ^ Z.of_nat m)%Z. Proof. by rewrite -Zpower_nat_Z; elim: m => //= m <-; rewrite exprS. Qed. #[global] Instance Op_Z_exp : BinOp (@GRing.exp _ : Z -> nat -> Z) := { TBOp := Z.pow; TBOpInj := Op_Z_exp_subproof }. Add Zify BinOp Op_Z_exp. #[global] Instance Op_unitZ : UnOp (has_quality 1 Instances.unitZ : Z -> bool) := { TUOp x := (x =? 1)%Z || (x =? - 1)%Z; TUOpInj _ := erefl }. Add Zify UnOp Op_unitZ. #[global] Instance Op_Z_unit : UnOp (has_quality 1 GRing.unit : Z -> bool) := Op_unitZ. Add Zify UnOp Op_Z_unit. #[global] Instance Op_invZ : UnOp Instances.invZ := { TUOp := id; TUOpInj _ := erefl }. Add Zify UnOp Op_invZ. #[global] Instance Op_Z_inv : UnOp (GRing.inv : Z -> Z) := { TUOp := id; TUOpInj _ := erefl }. Add Zify UnOp Op_Z_inv. #[global] Instance Op_Z_normr : UnOp (Num.norm : Z -> Z) := { TUOp := Z.abs; TUOpInj _ := erefl }. Add Zify UnOp Op_Z_normr. #[global] Instance Op_Z_sgr : UnOp (Num.sg : Z -> Z) := { TUOp := Z.sgn; TUOpInj := ltac:(case=> //=; lia) }. Add Zify UnOp Op_Z_sgr. #[global] Instance Op_Z_le : BinOp (<=%O : Z -> Z -> bool) := { TBOp := Z.leb; TBOpInj _ _ := erefl }. Add Zify BinOp Op_Z_le. #[global] Instance Op_Z_le' : BinOp (>=^d%O : rel Z^d) := Op_Z_le. Add Zify BinOp Op_Z_le'. #[global] Instance Op_Z_ge : BinOp (>=%O : Z -> Z -> bool) := { TBOp := Z.geb; TBOpInj := ltac:(simpl; lia) }. Add Zify BinOp Op_Z_ge. #[global] Instance Op_Z_ge' : BinOp (<=^d%O : rel Z^d) := Op_Z_ge. Add Zify BinOp Op_Z_ge'. #[global] Instance Op_Z_lt : BinOp (<%O : Z -> Z -> bool) := { TBOp := Z.ltb; TBOpInj _ _ := erefl }. Add Zify BinOp Op_Z_lt. #[global] Instance Op_Z_lt' : BinOp (>^d%O : rel Z^d) := Op_Z_lt. Add Zify BinOp Op_Z_lt'. #[global] Instance Op_Z_gt : BinOp (>%O : Z -> Z -> bool) := { TBOp := Z.gtb; TBOpInj := ltac:(simpl; lia) }. Add Zify BinOp Op_Z_gt. #[global] Instance Op_Z_gt' : BinOp (<^d%O : rel Z^d) := Op_Z_gt. Add Zify BinOp Op_Z_gt'. #[global] Instance Op_Z_min : BinOp (Order.min : Z -> Z -> Z) := { TBOp := Z.min; TBOpInj _ _ := ltac:(case: leP => /=; lia) }. Add Zify BinOp Op_Z_min. #[global] Instance Op_Z_min' : BinOp ((Order.max : Z^d -> _) : Z -> Z -> Z) := { TBOp := Z.min; TBOpInj _ _ := ltac:(case: leP => /=; lia) }. Add Zify BinOp Op_Z_min'. #[global] Instance Op_Z_max : BinOp (Order.max : Z -> Z -> Z) := { TBOp := Z.max; TBOpInj _ _ := ltac:(case: leP => /=; lia) }. Add Zify BinOp Op_Z_max. #[global] Instance Op_Z_max' : BinOp ((Order.min : Z^d -> _) : Z -> Z -> Z) := { TBOp := Z.max; TBOpInj _ _ := ltac:(case: leP => /=; lia) }. Add Zify BinOp Op_Z_max'. #[global] Instance Op_Z_meet : BinOp (Order.meet : Z -> Z -> Z) := { TBOp := Z.min; TBOpInj _ _ := ltac:(case: leP => /=; lia) }. Add Zify BinOp Op_Z_meet. #[global] Instance Op_Z_meet' : BinOp (Order.join : Z^d -> _) := Op_Z_min. Add Zify BinOp Op_Z_meet'. #[global] Instance Op_Z_join : BinOp (Order.join : Z -> Z -> Z) := { TBOp := Z.max; TBOpInj _ _ := ltac:(case: leP => /=; lia) }. Add Zify BinOp Op_Z_join. #[global] Instance Op_Z_join' : BinOp (Order.meet : Z^d -> _) := Op_Z_max. Add Zify BinOp Op_Z_join'. (******************************************************************************) (* intdiv *) (******************************************************************************) Fact Op_divz_subproof n m : Z_of_int (divz n m) = divZ (Z_of_int n) (Z_of_int m). Proof. case: n => [[|n]|n]; rewrite /divz /divZ /= ?addn1 /=; nia. Qed. #[global] Instance Op_divz : BinOp (divz : int -> int -> int) := { TBOp := divZ; TBOpInj := Op_divz_subproof }. Add Zify BinOp Op_divz. #[global] Instance Op_modz : BinOp modz := { TBOp := modZ; TBOpInj := ltac:(rewrite /= /modz; lia) }. Add Zify BinOp Op_modz. #[global] Instance Op_dvdz : BinOp dvdz := { TBOp n m := (modZ m n =? 0)%Z; TBOpInj _ _ := ltac:(apply/dvdz_mod0P/idP; lia) }. Add Zify BinOp Op_dvdz. Fact Op_gcdz_subproof n m : Z_of_int (gcdz n m) = Z.gcd (Z_of_int n) (Z_of_int m). Proof. rewrite /gcdz -Z.gcd_abs_l -Z.gcd_abs_r; lia. Qed. #[global] Instance Op_gcdz : BinOp gcdz := { TBOp := Z.gcd; TBOpInj := Op_gcdz_subproof }. Add Zify BinOp Op_gcdz. #[global] Instance Op_coprimez : BinOp coprimez := { TBOp x y := (Z.gcd x y =? 1)%Z; TBOpInj := ltac:(rewrite /= /coprimez; lia) }. Add Zify BinOp Op_coprimez. Module Exports. Add Zify CstOp Op_nat_0. Add Zify BinOp Op_nat_add. Add Zify CstOp Op_nat_1. Add Zify BinOp Op_nat_mul. Add Zify BinOp Op_nat_natmul. Add Zify BinOp Op_nat_exp. Add Zify CstOp Op_N_0. Add Zify BinOp Op_N_add. Add Zify CstOp Op_N_1. Add Zify BinOp Op_N_mul. Add Zify BinOp Op_N_natmul. Add Zify BinOp Op_N_exp. Add Zify InjTyp Inj_int_Z. Add Zify UnOp Op_Z_of_int. Add Zify UnOp Op_Posz. Add Zify UnOp Op_Negz. Add Zify BinRel Op_int_eq. Add Zify BinOp Op_int_eq_op. Add Zify CstOp Op_int_0. Add Zify BinOp Op_addz. Add Zify BinOp Op_int_add. Add Zify UnOp Op_oppz. Add Zify UnOp Op_int_opp. Add Zify CstOp Op_int_1. Add Zify BinOp Op_mulz. Add Zify BinOp Op_int_mulr. Add Zify BinOp Op_int_natmul. Add Zify BinOp Op_int_intmul. Add Zify BinOp Op_int_scale. Add Zify BinOp Op_int_exp. Add Zify UnOp Op_unitz. Add Zify UnOp Op_int_unit. Add Zify UnOp Op_invz. Add Zify UnOp Op_int_inv. Add Zify UnOp Op_absz. Add Zify UnOp Op_int_normr. Add Zify BinOp Op_lez. Add Zify BinOp Op_ltz. Add Zify UnOp Op_int_sgr. Add Zify UnOp Op_int_sgz. Add Zify BinOp Op_int_le. Add Zify BinOp Op_int_le'. Add Zify BinOp Op_int_ge. Add Zify BinOp Op_int_ge'. Add Zify BinOp Op_int_lt. Add Zify BinOp Op_int_lt'. Add Zify BinOp Op_int_gt. Add Zify BinOp Op_int_gt'. Add Zify BinOp Op_int_min. Add Zify BinOp Op_int_min'. Add Zify BinOp Op_int_max. Add Zify BinOp Op_int_max'. Add Zify BinOp Op_int_meet. Add Zify BinOp Op_int_meet'. Add Zify BinOp Op_int_join. Add Zify BinOp Op_int_join'. Add Zify BinOp Op_Z_eq_op. Add Zify CstOp Op_Z_0. Add Zify BinOp Op_Z_add. Add Zify UnOp Op_Z_opp. Add Zify CstOp Op_Z_1. Add Zify BinOp Op_Z_mulr. Add Zify BinOp Op_Z_natmul. Add Zify BinOp Op_Z_intmul. Add Zify BinOp Op_Z_scale. Add Zify BinOp Op_Z_exp. Add Zify UnOp Op_unitZ. Add Zify UnOp Op_Z_unit. Add Zify UnOp Op_invZ. Add Zify UnOp Op_Z_inv. Add Zify UnOp Op_Z_normr. Add Zify UnOp Op_Z_sgr. Add Zify BinOp Op_Z_le. Add Zify BinOp Op_Z_le'. Add Zify BinOp Op_Z_ge. Add Zify BinOp Op_Z_ge'. Add Zify BinOp Op_Z_lt. Add Zify BinOp Op_Z_lt'. Add Zify BinOp Op_Z_gt. Add Zify BinOp Op_Z_gt'. Add Zify BinOp Op_Z_min. Add Zify BinOp Op_Z_min'. Add Zify BinOp Op_Z_max. Add Zify BinOp Op_Z_max'. Add Zify BinOp Op_Z_meet. Add Zify BinOp Op_Z_meet'. Add Zify BinOp Op_Z_join. Add Zify BinOp Op_Z_join'. Add Zify BinOp Op_divz. Add Zify BinOp Op_modz. Add Zify BinOp Op_dvdz. Add Zify BinOp Op_gcdz. Add Zify BinOp Op_coprimez. End Exports. End AlgebraZifyInstances. Export SsreflectZifyInstances.Exports. Export AlgebraZifyInstances.Exports. mczify-1.5.0-2.0-8.16/theories/zify_ssreflect.v000066400000000000000000000512361445325544600207740ustar00rootroot00000000000000From Coq Require Import ZArith ZifyClasses ZifyInst ZifyBool. From Coq Require Export Lia. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path. From mathcomp Require Import div choice fintype tuple finfun bigop finset prime. From mathcomp Require Import order binomial. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Ltac Zify.zify_pre_hook ::= unfold is_true in *; do ?rewrite -> unfold_in in *. Module SsreflectZifyInstances. Import Order.Theory. #[global] Instance Op_bool_inj : UnOp (inj : bool -> bool) := { TUOp := id; TUOpInj _ := erefl }. Add Zify UnOp Op_bool_inj. #[global] Instance Op_nat_inj : UnOp (inj : nat -> Z) := Op_Z_of_nat. Add Zify UnOp Op_nat_inj. (******************************************************************************) (* ssrbool *) (******************************************************************************) #[global] Instance Op_addb : BinOp addb := { TBOp x y := Bool.eqb x (~~ y); TBOpInj := ltac:(by case=> [][]) }. Add Zify BinOp Op_addb. #[global] Instance Op_eqb : BinOp eqb := { TBOp := Bool.eqb; TBOpInj := ltac:(by case=> [][]) }. Add Zify BinOp Op_eqb. #[global] Instance Op_eq_op_bool : BinOp (eq_op : rel bool) := Op_eqb. Add Zify BinOp Op_eq_op_bool. #[global] Instance Op_bool_le : BinOp (<=%O : bool -> bool -> bool) := { TBOp := implb; TBOpInj := ltac:(by case=> [][]) }. Add Zify BinOp Op_bool_le. #[global] Instance Op_bool_le' : BinOp (>=^d%O : rel bool^d) := Op_bool_le. Add Zify BinOp Op_bool_le'. #[global] Instance Op_bool_ge : BinOp (>=%O : bool -> bool -> bool) := { TBOp x y := implb y x; TBOpInj := ltac:(by case=> [][]) }. Add Zify BinOp Op_bool_ge. #[global] Instance Op_bool_ge' : BinOp (<=^d%O : rel bool^d) := Op_bool_ge. Add Zify BinOp Op_bool_ge'. #[global] Instance Op_bool_lt : BinOp (<%O : bool -> bool -> bool) := { TBOp x y := ~~ x && y; TBOpInj := ltac:(by case=> [][]) }. Add Zify BinOp Op_bool_lt. #[global] Instance Op_bool_lt' : BinOp (>^d%O : rel bool^d) := Op_bool_lt. Add Zify BinOp Op_bool_lt'. #[global] Instance Op_bool_gt : BinOp (>%O : bool -> bool -> bool) := { TBOp x y := x && ~~ y; TBOpInj := ltac:(by case=> [][]) }. Add Zify BinOp Op_bool_gt. #[global] Instance Op_bool_gt' : BinOp (<^d%O : rel bool^d) := Op_bool_gt. Add Zify BinOp Op_bool_gt'. #[global] Instance Op_bool_min : BinOp (Order.min : bool -> bool -> bool) := { TBOp := andb; TBOpInj := ltac:(by case=> [][]) }. Add Zify BinOp Op_bool_min. #[global] Instance Op_bool_min' : BinOp ((Order.max : bool^d -> _) : bool -> bool -> bool) := { TBOp := andb; TBOpInj := ltac:(by case=> [][]) }. Add Zify BinOp Op_bool_min'. #[global] Instance Op_bool_max : BinOp (Order.max : bool -> bool -> bool) := { TBOp := orb; TBOpInj := ltac:(by case=> [][]) }. Add Zify BinOp Op_bool_max. #[global] Instance Op_bool_max' : BinOp ((Order.min : bool^d -> _) : bool -> bool -> bool) := { TBOp := orb; TBOpInj := ltac:(by case=> [][]) }. Add Zify BinOp Op_bool_max'. #[global] Instance Op_bool_meet : BinOp (Order.meet : bool -> bool -> bool) := Op_andb. Add Zify BinOp Op_bool_meet. #[global] Instance Op_bool_meet' : BinOp (Order.join : bool^d -> _) := Op_andb. Add Zify BinOp Op_bool_meet'. #[global] Instance Op_bool_join : BinOp (Order.join : bool -> bool -> bool) := Op_orb. Add Zify BinOp Op_bool_join. #[global] Instance Op_bool_join' : BinOp (Order.meet : bool^d -> _) := Op_orb. Add Zify BinOp Op_bool_join'. #[global] Instance Op_bool_bottom : CstOp (\bot : bool)%O := Op_false. Add Zify CstOp Op_bool_bottom. #[global] Instance Op_bool_bottom' : CstOp (\top : bool^d)%O := Op_false. Add Zify CstOp Op_bool_bottom'. #[global] Instance Op_bool_top : CstOp (\top : bool)%O := Op_true. Add Zify CstOp Op_bool_top. #[global] Instance Op_bool_top' : CstOp (\bot : bool^d)%O := Op_true. Add Zify CstOp Op_bool_top'. #[global] Instance Op_bool_sub : BinOp (Order.diff : bool -> bool -> bool) := { TBOp x y := x && ~~ y; TBOpInj := ltac:(by case=> [][]) }. Add Zify BinOp Op_bool_sub. #[global] Instance Op_bool_compl : UnOp (Order.compl : bool -> bool) := Op_negb. Add Zify UnOp Op_bool_compl. (******************************************************************************) (* ssrnat *) (******************************************************************************) #[global] Instance Op_eqn : BinOp eqn := Op_nat_eqb. Add Zify BinOp Op_eqn. #[global] Instance Op_eq_op_nat : BinOp (eq_op : rel nat) := Op_eqn. Add Zify BinOp Op_eq_op_nat. #[global] Instance Op_addn_rec : BinOp addn_rec := Op_plus. Add Zify BinOp Op_addn_rec. #[global] Instance Op_addn : BinOp addn := Op_plus. Add Zify BinOp Op_addn. #[global] Instance Op_addn_trec : BinOp NatTrec.add := { TBOp := Z.add; TBOpInj n m := ltac:(rewrite NatTrec.addE; lia) }. Add Zify BinOp Op_addn_trec. #[global] Instance Op_subn_rec : BinOp subn_rec := Op_sub. Add Zify BinOp Op_subn_rec. #[global] Instance Op_subn : BinOp subn := Op_sub. Add Zify BinOp Op_subn. #[global] Instance Op_muln_rec : BinOp muln_rec := Op_mul. Add Zify BinOp Op_muln_rec. #[global] Instance Op_muln : BinOp muln := Op_mul. Add Zify BinOp Op_muln. #[global] Instance Op_muln_trec : BinOp NatTrec.mul := { TBOp := Z.mul; TBOpInj n m := ltac:(rewrite NatTrec.mulE; lia) }. Add Zify BinOp Op_muln_trec. #[global] Instance Op_leq : BinOp leq := { TBOp := Z.leb; TBOpInj := ltac:(rewrite /leq; lia) }. Add Zify BinOp Op_leq. #[global] Instance Op_geq : BinOp (geq : nat -> nat -> bool) := { TBOp := Z.geb; TBOpInj := ltac:(simpl; lia) }. Add Zify BinOp Op_geq. #[global] Instance Op_ltn : BinOp (ltn : nat -> nat -> bool) := { TBOp := Z.ltb; TBOpInj := ltac:(simpl; lia) }. Add Zify BinOp Op_ltn. #[global] Instance Op_gtn : BinOp (gtn : nat -> nat -> bool) := { TBOp := Z.gtb; TBOpInj := ltac:(simpl; lia) }. Add Zify BinOp Op_gtn. #[global] Instance Op_minn : BinOp minn := { TBOp := Z.min; TBOpInj _ _ := ltac:(case: leqP; lia) }. Add Zify BinOp Op_minn. #[global] Instance Op_maxn : BinOp maxn := { TBOp := Z.max; TBOpInj _ _ := ltac:(case: leqP; lia) }. Add Zify BinOp Op_maxn. #[global] Instance Op_nat_of_bool : UnOp nat_of_bool := { TUOp := Z.b2z; TUOpInj := ltac:(by case) }. Add Zify UnOp Op_nat_of_bool. #[global] Instance Op_double : UnOp double := { TUOp := Z.mul 2; TUOpInj _ := ltac:(rewrite -muln2; lia) }. Add Zify UnOp Op_double. #[global] Instance Op_double_trec : UnOp NatTrec.double := { TUOp := Z.mul 2; TUOpInj _ := ltac:(rewrite NatTrec.doubleE; lia) }. Add Zify UnOp Op_double_trec. Fact Op_expn_subproof n m : Z.of_nat (n ^ m) = (Z.of_nat n ^ Z.of_nat m)%Z. Proof. rewrite -Zpower_nat_Z; elim: m => //= m <-; rewrite expnS; lia. Qed. #[global] Instance Op_expn_rec : BinOp expn_rec := { TBOp := Z.pow; TBOpInj := Op_expn_subproof }. Add Zify BinOp Op_expn_rec. #[global] Instance Op_expn : BinOp expn := Op_expn_rec. Add Zify BinOp Op_expn. #[global] Instance Op_expn_trec : BinOp NatTrec.exp := { TBOp := Z.pow; TBOpInj n m := ltac:(rewrite NatTrec.expE; lia) }. Add Zify BinOp Op_expn_trec. #[global] Instance Op_eq_op_N : BinOp (eq_op : N -> N -> bool) := { TBOp := Z.eqb; TBOpInj := ltac:(by case => [|n] []) }. Add Zify BinOp Op_eq_op_N. Fact nat_of_posE : nat_of_pos =1 Pos.to_nat. Proof. move=> p; rewrite /Pos.to_nat -[LHS]muln1. elim: p 1 => /= [p IHp | p IHp |] n; rewrite -?IHp; lia. Qed. #[global] Instance Op_nat_of_pos : UnOp nat_of_pos := { TUOp := id; TUOpInj n := ltac:(rewrite /= nat_of_posE; lia) }. Add Zify UnOp Op_nat_of_pos. #[global] Instance Op_nat_of_bin : UnOp nat_of_bin := { TUOp := id; TUOpInj := ltac:(case => //=; lia) }. Add Zify UnOp Op_nat_of_bin. Fact pos_of_natE n m : pos_of_nat n m = Pos.of_succ_nat (n * 2 - m). Proof. elim: n m => // n IHn [|[|m]] /=; rewrite IHn; lia. Qed. #[global] Instance Op_pos_of_nat : BinOp pos_of_nat := { TBOp n m := Z.max 1 (n * 2 - m + 1); TBOpInj n m := ltac:(rewrite /= pos_of_natE; lia) }. Add Zify BinOp Op_pos_of_nat. #[global] Instance Op_bin_of_nat : UnOp bin_of_nat := { TUOp := id; TUOpInj n := ltac:(rewrite /= -[n in RHS]bin_of_natK; lia) }. Add Zify UnOp Op_bin_of_nat. #[global] Instance Op_nat_le : BinOp (<=%O : rel nat) := Op_leq. Add Zify BinOp Op_nat_le. #[global] Instance Op_nat_le' : BinOp (>=^d%O : rel nat^d) := Op_leq. Add Zify BinOp Op_nat_le'. #[global] Instance Op_nat_ge : BinOp (>=%O : rel nat) := Op_geq. Add Zify BinOp Op_nat_ge. #[global] Instance Op_nat_ge' : BinOp (<=^d%O : rel nat^d) := Op_geq. Add Zify BinOp Op_nat_ge'. #[global] Instance Op_nat_lt : BinOp (<%O : rel nat) := Op_ltn. Add Zify BinOp Op_nat_lt. #[global] Instance Op_nat_lt' : BinOp (>^d%O : rel nat^d) := Op_ltn. Add Zify BinOp Op_nat_lt'. #[global] Instance Op_nat_gt : BinOp (>%O : rel nat) := Op_gtn. Add Zify BinOp Op_nat_gt. #[global] Instance Op_nat_gt' : BinOp (<^d%O : rel nat^d) := Op_gtn. Add Zify BinOp Op_nat_gt'. #[global] Instance Op_nat_min : BinOp (Order.min : nat -> _) := Op_minn. Add Zify BinOp Op_nat_min. #[global] Instance Op_nat_min' : BinOp ((Order.max : nat^d -> _) : nat -> nat -> nat) := { TBOp := Z.min; TBOpInj _ _ := ltac:(case: leP; lia) }. Add Zify BinOp Op_nat_min'. #[global] Instance Op_nat_max : BinOp (Order.max : nat -> _) := Op_maxn. Add Zify BinOp Op_nat_max. #[global] Instance Op_nat_max' : BinOp ((Order.min : nat^d -> _) : nat -> nat -> nat) := { TBOp := Z.max; TBOpInj _ _ := ltac:(case: leP; lia) }. Add Zify BinOp Op_nat_max'. #[global] Instance Op_nat_meet : BinOp (Order.meet : nat -> _) := Op_minn. Add Zify BinOp Op_nat_meet. #[global] Instance Op_nat_meet' : BinOp (Order.join : nat^d -> _) := Op_minn. Add Zify BinOp Op_nat_meet'. #[global] Instance Op_nat_join : BinOp (Order.join : nat -> _) := Op_maxn. Add Zify BinOp Op_nat_join. #[global] Instance Op_nat_join' : BinOp (Order.meet : nat^d -> _) := Op_maxn. Add Zify BinOp Op_nat_join'. #[global] Instance Op_nat_bottom : CstOp (\bot : nat)%O := Op_O. Add Zify CstOp Op_nat_bottom. (******************************************************************************) (* division / modulo: Since `divz` and `modz` of MathComp (defined in *) (* `intdiv.v`) are incompatible with the division and modulo functions for *) (* `Z` in the Coq standard library, here we have to define ones for `Z` which *) (* behave the same as `divz` and `modz`. *) (******************************************************************************) Definition divZ (m d : Z) : Z := Z.sgn d * match m with | Z0 => 0 | Z.pos p => Z.of_nat (Pos.to_nat p %/ Z.abs_nat d)%N | Z.neg p => - Z.succ (Z.of_nat ((Pos.to_nat p).-1 %/ Z.abs_nat d)%N) end%Z. Definition modZ (m d : Z) : Z := (m - divZ m d * d)%Z. #[global] Instance Op_divZ : BinOp divZ := { TBOp := divZ; TBOpInj _ _ := erefl }. Add Zify BinOp Op_divZ. #[global] Instance Op_modZ : BinOp modZ := { TBOp := modZ; TBOpInj _ _ := erefl }. Add Zify BinOp Op_modZ. (* Reimplementation of Z.div_mod_to_equations (PreOmega.v) for divZ and modZ: *) Fact divZ_eq m d : m = (divZ m d * d + modZ m d)%Z. Proof. rewrite /modZ; lia. Qed. Fact modZ_ge0 m d : d <> 0%Z -> (0 <= modZ m d)%Z. Proof. by move: d m => [] // d [] // m _; rewrite /modZ /divZ [Z.abs_nat _]/=; move: (leq_trunc_div (Pos.to_nat m) (Pos.to_nat d)); move: (@ltn_ceil (Pos.to_nat m).-1 (Pos.to_nat d)); lia. Qed. Fact ltz_pmodZ m d : (0 < d)%Z -> (modZ m d < d)%Z. Proof. by move: d m => [] // d [] // m _; rewrite /modZ /divZ [Z.abs_nat _]/=; move: (leq_trunc_div (Pos.to_nat m).-1 (Pos.to_nat d)); move: (@ltn_ceil (Pos.to_nat m) (Pos.to_nat d)); lia. Qed. Fact ltz_nmodZ m d : (d < 0)%Z -> (modZ m d < - d)%Z. Proof. move: d m => [] // d [] // m _; rewrite /modZ /divZ [Z.abs_nat _]/=; move: (leq_trunc_div (Pos.to_nat m).-1 (Pos.to_nat d)); move: (@ltn_ceil (Pos.to_nat m) (Pos.to_nat d)); lia. Qed. Fact divZ0 m d : d = 0%Z -> divZ m d = 0%Z. Proof. by move=> ->. Qed. Ltac divZ_modZ_to_equations := let divZ_modZ_to_equations' m d := pose proof (@divZ_eq m d); pose proof (@modZ_ge0 m d); pose proof (@ltz_pmodZ m d); pose proof (@ltz_nmodZ m d); pose proof (@divZ0 m d); let q := fresh "q" in let r := fresh "r" in set (q := divZ m d) in *; set (r := modZ m d) in *; (* Find [divZ ?m' ?d'] and [modZ ?m' ?d'] that are convertible with *) (* [divZ m d] and [modZ m d] respectively. *) repeat match goal with | |- context [divZ ?m' ?d'] => change (divZ m' d') with q | |- context [modZ ?m' ?d'] => change (modZ m' d') with r | H : context [divZ ?m' ?d'] |- _ => change (divZ m' d') with q in H | H : context [modZ ?m' ?d'] |- _ => change (modZ m' d') with r in H end; clearbody q r in repeat match goal with | [ |- context [divZ ?m ?d] ] => divZ_modZ_to_equations' m d | [ |- context [modZ ?m ?d] ] => divZ_modZ_to_equations' m d | [ H : context [divZ ?m ?d] |- _] => divZ_modZ_to_equations' m d | [ H : context [modZ ?m ?d] |- _] => divZ_modZ_to_equations' m d end. Ltac Zify.zify_post_hook ::= elim_bool_cstr; divZ_modZ_to_equations. (******************************************************************************) (* div (divn, modn, dvdn, gcdn, lcmn, and coprime) *) (******************************************************************************) Fact Op_divn_subproof n m : Z.of_nat (n %/ m) = divZ (Z.of_nat n) (Z.of_nat m). Proof. by case: n m => [|n] [|m]; rewrite /divZ //= ?SuccNat2Pos.id_succ; case: divn. Qed. #[global] Instance Op_divn : BinOp divn := { TBOp := divZ; TBOpInj := Op_divn_subproof }. Add Zify BinOp Op_divn. #[global] Instance Op_modn : BinOp modn := { TBOp := modZ; TBOpInj n m := ltac:(move: (divn_eq n m); lia) }. Add Zify BinOp Op_modn. #[global] Instance Op_dvdn : BinOp dvdn := { TBOp x y := (modZ y x =? 0)%Z; TBOpInj := ltac:(rewrite /dvdn; lia) }. Add Zify BinOp Op_dvdn. #[global] Instance Op_odd : UnOp odd := { TUOp x := (modZ x 2 =? 1)%Z; TUOpInj n := ltac:(case: odd (modn2 n); lia) }. Add Zify UnOp Op_odd. #[global] Instance Op_odd_trec : UnOp NatTrec.odd := { TUOp x := (modZ x 2 =? 1)%Z; TUOpInj n := ltac:(rewrite NatTrec.oddE; lia) }. Add Zify UnOp Op_odd_trec. #[global] Instance Op_half : UnOp half := { TUOp x := divZ x 2; TUOpInj _ := ltac:(rewrite -divn2; lia) }. Add Zify UnOp Op_half. #[global] Instance Op_uphalf : UnOp uphalf := { TUOp x := divZ (x + 1)%Z 2; TUOpInj _ := ltac:(rewrite uphalf_half; lia) }. Add Zify UnOp Op_uphalf. Fact Op_gcdn_subproof n m : Z.of_nat (gcdn n m) = Z.gcd (Z.of_nat n) (Z.of_nat m). Proof. apply/esym/Z.gcd_unique; first by case: gcdn. - case/dvdnP: (dvdn_gcdl n m) => k {2}->; exists (Z.of_nat k); lia. - case/dvdnP: (dvdn_gcdr n m) => k {2}->; exists (Z.of_nat k); lia. - move=> k [n' Hkn] [m' Hkm]. suff/dvdnP [k' ->]: Z.abs_nat k %| gcdn n m. by apply/Znumtheory.Zdivide_Zabs_l; exists (Z.of_nat k'); lia. rewrite dvdn_gcd; apply/andP; split; apply/dvdnP; [exists (Z.abs_nat n') | exists (Z.abs_nat m')]; nia. Qed. #[global] Instance Op_gcdn : BinOp gcdn := { TBOp := Z.gcd; TBOpInj := Op_gcdn_subproof }. Add Zify BinOp Op_gcdn. Fact Op_lcmn_subproof n m : Z.of_nat (lcmn n m) = Z.lcm (Z.of_nat n) (Z.of_nat m). Proof. case: n m => [|n][|m]; rewrite ?lcmn0 // /lcmn /Z.lcm -Op_gcdn_subproof. case/dvdnP: (dvdn_gcdr n.+1 m.+1) => k {1 3}->. rewrite mulnA mulnK ?gcdn_gt0 // !Nat2Z.inj_mul Z_div_mult_full //; first nia. by case: (gcdn _ _) (gcdn_gt0 n.+1 m.+1). Qed. #[global] Instance Op_lcmn : BinOp lcmn := { TBOp := Z.lcm; TBOpInj := Op_lcmn_subproof }. Add Zify BinOp Op_lcmn. #[global] Instance Op_coprime : BinOp coprime := { TBOp x y := (Z.gcd x y =? 1)%Z; TBOpInj := ltac:(rewrite /= /coprime; lia) }. Add Zify BinOp Op_coprime. (******************************************************************************) (* natdvd in order.v *) (******************************************************************************) #[global] Instance Op_natdvd_le : BinOp (<=%O : rel natdvd) := Op_dvdn. Add Zify BinOp Op_natdvd_le. #[global] Instance Op_natdvd_le' : BinOp (>=^d%O : rel natdvd^d) := Op_dvdn. Add Zify BinOp Op_natdvd_le'. #[global] Instance Op_natdvd_ge : BinOp ((>=%O : rel natdvd) : nat -> nat -> bool) := { TBOp x y := (modZ x y =? 0)%Z; TBOpInj := ltac:(simpl; lia) }. Add Zify BinOp Op_natdvd_ge. #[global] Instance Op_natdvd_ge' : BinOp (<=^d%O : rel natdvd^d) := Op_natdvd_ge. Add Zify BinOp Op_natdvd_ge'. #[global] Instance Op_natdvd_lt : BinOp ((<%O : rel natdvd) : nat -> nat -> bool) := { TBOp x y := ~~ (y =? x)%Z && (modZ y x =? 0)%Z; TBOpInj _ _ := ltac:(rewrite /= sdvdEnat; lia) }. Add Zify BinOp Op_natdvd_lt. #[global] Instance Op_natdvd_lt' : BinOp (>^d%O : rel natdvd^d) := Op_natdvd_lt. Add Zify BinOp Op_natdvd_lt'. #[global] Instance Op_natdvd_gt : BinOp ((>%O : rel natdvd) : nat -> nat -> bool) := { TBOp x y := ~~ (x =? y)%Z && (modZ x y =? 0)%Z; TBOpInj _ _ := ltac:(rewrite /= sdvdEnat; lia) }. Add Zify BinOp Op_natdvd_gt. #[global] Instance Op_natdvd_gt' : BinOp (<^d%O : rel natdvd^d) := Op_natdvd_gt. Add Zify BinOp Op_natdvd_gt'. #[global] Instance Op_natdvd_meet : BinOp (Order.meet : natdvd -> _) := Op_gcdn. Add Zify BinOp Op_natdvd_meet. #[global] Instance Op_natdvd_meet' : BinOp (Order.join : natdvd^d -> _) := Op_gcdn. Add Zify BinOp Op_natdvd_meet'. #[global] Instance Op_natdvd_join : BinOp (Order.join : natdvd -> _) := Op_lcmn. Add Zify BinOp Op_natdvd_join. #[global] Instance Op_natdvd_join' : BinOp (Order.meet : natdvd^d -> _) := Op_lcmn. Add Zify BinOp Op_natdvd_join'. #[global] Instance Op_natdvd_bottom : CstOp (\bot : natdvd)%O := { TCst := 1%Z; TCstInj := erefl }. Add Zify CstOp Op_natdvd_bottom. #[global] Instance Op_natdvd_bottom' : CstOp (\top : natdvd^d)%O := Op_natdvd_bottom. Add Zify CstOp Op_natdvd_bottom'. #[global] Instance Op_natdvd_top : CstOp (\top : natdvd)%O := Op_O. Add Zify CstOp Op_natdvd_top. #[global] Instance Op_natdvd_top' : CstOp (\bot : natdvd^d)%O := Op_O. Add Zify CstOp Op_natdvd_top'. Module Exports. (* Add Zify UnOp Op_bool_inj. *) (* Add Zify UnOp Op_nat_inj. *) Add Zify BinOp Op_addb. Add Zify BinOp Op_eqb. Add Zify BinOp Op_eq_op_bool. Add Zify BinOp Op_bool_le. Add Zify BinOp Op_bool_le'. Add Zify BinOp Op_bool_ge. Add Zify BinOp Op_bool_ge'. Add Zify BinOp Op_bool_lt. Add Zify BinOp Op_bool_lt'. Add Zify BinOp Op_bool_gt. Add Zify BinOp Op_bool_gt'. Add Zify BinOp Op_bool_min. Add Zify BinOp Op_bool_min'. Add Zify BinOp Op_bool_max. Add Zify BinOp Op_bool_max'. Add Zify BinOp Op_bool_meet. Add Zify BinOp Op_bool_meet'. Add Zify BinOp Op_bool_join. Add Zify BinOp Op_bool_join'. Add Zify CstOp Op_bool_bottom. Add Zify CstOp Op_bool_bottom'. Add Zify CstOp Op_bool_top. Add Zify CstOp Op_bool_top'. Add Zify BinOp Op_bool_sub. Add Zify UnOp Op_bool_compl. Add Zify BinOp Op_eqn. Add Zify BinOp Op_eq_op_nat. Add Zify BinOp Op_addn_rec. Add Zify BinOp Op_addn. Add Zify BinOp Op_addn_trec. Add Zify BinOp Op_subn_rec. Add Zify BinOp Op_subn. Add Zify BinOp Op_muln_rec. Add Zify BinOp Op_muln. Add Zify BinOp Op_muln_trec. Add Zify BinOp Op_leq. Add Zify BinOp Op_geq. Add Zify BinOp Op_ltn. Add Zify BinOp Op_gtn. Add Zify BinOp Op_minn. Add Zify BinOp Op_maxn. Add Zify UnOp Op_nat_of_bool. Add Zify UnOp Op_double. Add Zify UnOp Op_double_trec. Add Zify BinOp Op_expn_rec. Add Zify BinOp Op_expn. Add Zify BinOp Op_expn_trec. Add Zify BinOp Op_eq_op_N. Add Zify UnOp Op_nat_of_pos. Add Zify UnOp Op_nat_of_bin. Add Zify BinOp Op_pos_of_nat. Add Zify UnOp Op_bin_of_nat. Add Zify BinOp Op_nat_le. Add Zify BinOp Op_nat_le'. Add Zify BinOp Op_nat_ge. Add Zify BinOp Op_nat_ge'. Add Zify BinOp Op_nat_lt. Add Zify BinOp Op_nat_lt'. Add Zify BinOp Op_nat_gt. Add Zify BinOp Op_nat_gt'. Add Zify BinOp Op_nat_min. Add Zify BinOp Op_nat_min'. Add Zify BinOp Op_nat_max. Add Zify BinOp Op_nat_max'. Add Zify BinOp Op_nat_meet. Add Zify BinOp Op_nat_meet'. Add Zify BinOp Op_nat_join. Add Zify BinOp Op_nat_join'. Add Zify CstOp Op_nat_bottom. Add Zify BinOp Op_divZ. Add Zify BinOp Op_modZ. Add Zify BinOp Op_divn. Add Zify BinOp Op_modn. Add Zify BinOp Op_dvdn. Add Zify UnOp Op_odd. Add Zify UnOp Op_odd_trec. Add Zify UnOp Op_half. Add Zify UnOp Op_uphalf. Add Zify BinOp Op_gcdn. Add Zify BinOp Op_lcmn. Add Zify BinOp Op_coprime. Add Zify BinOp Op_natdvd_le. Add Zify BinOp Op_natdvd_le'. Add Zify BinOp Op_natdvd_ge. Add Zify BinOp Op_natdvd_ge'. Add Zify BinOp Op_natdvd_lt. Add Zify BinOp Op_natdvd_lt'. Add Zify BinOp Op_natdvd_gt. Add Zify BinOp Op_natdvd_gt'. Add Zify BinOp Op_natdvd_meet. Add Zify BinOp Op_natdvd_meet'. Add Zify BinOp Op_natdvd_join. Add Zify BinOp Op_natdvd_join'. Add Zify CstOp Op_natdvd_bottom. Add Zify CstOp Op_natdvd_bottom'. Add Zify CstOp Op_natdvd_top. Add Zify CstOp Op_natdvd_top'. End Exports. End SsreflectZifyInstances. Export SsreflectZifyInstances.Exports.