GithubHelp home page GithubHelp logo

matafou / libhyps Goto Github PK

View Code? Open in Web Editor NEW
19.0 3.0 3.0 169 KB

A Coq library providing tactics to deal with hypothesis

License: MIT License

Coq 99.66% Shell 0.34%
coq formal-proofs proof-assistant tactics tactical hypothesis

libhyps's Introduction

This Library provides several coq tactics and tacticals to deal with hypothesis during a proof.

Main page and documentation: https://github.com/Matafou/LibHyps

Demo file demo.v acts as a documentation.

Short description:

LibHyps provides utilities for hypothesis manipulations. In particular a new tactic especialize H and a set of tacticals to appy or iterate tactics either on all hypothesis of a goal or on "new' hypothesis after a tactic. It also provide syntax for a few predefined such iterators.

QUICK REF: especialize (BROKEN IN COQ-8.18)

This tactic is currently broken in coq v8.18. I am working on it. This may need some work on coq side.

  • especialize H at n [as h]. Creates a subgoal to prove the nth dependent premise of H, creating necessary evars for non unifiable variables. Once proved the subgoal is used to remove the nth premise of H (or of a new created hypothesis if the as option is given).

  • especialize H at * [as h]. Creates one subgoal for each dependent premise of H, creating necessary evars for non unifiable variables. Once proved the subgoal is used to remove the premises of H (or of a new createdd hypothesis if the as option is given).

  • especialize H until n [as h]. Creates one subgoal for each n first dependent premises of H, creating necessary evars for non unifiable variables. Once proved the subgoal is used to remove the premises of H (or of a new created hypothesis if the as option is given).

QUICK REF: Pre-defined tacticals /s /n...

The most useful user-dedicated tacticals are the following

  • tac /s try to apply subst on each new hyp.
  • tac /r revert each new hyp.
  • tac /n auto-rename each new hyp.
  • tac /g group all non-Prop new hyp at the top of the goal.
  • combine the above, as in tac /s/n/g.
  • usual combinations have shortcuts: \sng, \sn,\ng,\sg...

Install

Quick install using opam

If you have not done it already add the coq platform repository to opam!

opam repo add coq-released https://coq.inria.fr/opam/released

and then:

opam install coq-libhyps

Quick install using github:

Clone the github repository:

git clone https://github.com/Matafou/LibHyps

then compile:

configure.sh
make
make install

Quick test:

Require Import LibHyps.LibHyps.

Demo files demo.v.

More information

Deprecation from 1.0.x to 2.0.x

  • "!tac", "!!tac" etc are now only loaded if you do: Import LibHyps.LegacyNotations., the composable tacticals described above are preferred.
  • "tac1 ;; tac2" remains, but you can also use "tac1; { tac2 }".
  • "tac1 ;!; tac2" remains, but you can also use "tac1; {< tac2 }".

KNOWN BUGS

Due to Ltac limitation, it is difficult to define a tactic notation tac1 ; { tac2 } which delays tac1 and tac2 in all cases. Sometimes (rarely) you will have to write (idtac; tac1); {idtac; tac2}. You may then use tactic notation like: Tactic Notation tac1' := idtac; tac1..

Examples

Require Import LibHyps.LibHyps.

Lemma foo: forall x y z:nat,
    x = y -> forall  a b t : nat, a+1 = t+2 -> b + 5 = t - 7 ->  (forall u v, v+1 = 1 -> u+1 = 1 -> a+1 = z+2)  -> z = b + x-> True.
Proof.
  intros.
  (* ugly names *)
  Undo.
  (* Example of using the iterator on new hyps: this prints each new hyp name. *)
  intros; {fun h => idtac h}.
  Undo.
  (* This gives sensible names to each new hyp. *)
  intros ; { autorename }.
  Undo.
  (* short syntax: *)
  intros /n.
  Undo.
  (* same thing but use subst if possible, and group non prop hyps to the top. *)
  intros ; { substHyp }; { autorename}; {move_up_types}.
  Undo.
  (* short syntax: *)  
  intros /s/n/g.
  Undo.
  (* Even shorter: *)  
  intros /s/n/g.

  (* Let us instantiate the 2nd premis of h_all_eq_add_add without copying its type: *)
  (* BROKEN IN COQ 8.18*)
  (* especialize h_all_eq_add_add_ at 2.
  { apply Nat.add_0_l. }
  (* now h_all_eq_add_add is specialized *)
  Undo 6. *)
  Undo 2.
  intros until 1.
  (** The taticals apply after any tactic. Notice how H:x=y is not new
    and hence not substituted, whereas z = b + x is. *)
  destruct x eqn:heq;intros /sng.
  - apply I.
  - apply I.
Qed.

Short Documentation

The following explains how it works under the hood, for people willing to apply more generic iterators to their own tactics. See also the code.

Iterator on all hypothesis

  • onAllHyps tac does tac H for each hypothesis H of the current goal.
  • onAllHypsRev tac same as onAllHyps tac but in reverse order (good for reverting for instance).

Iterators on ALL NEW hypothesis (since LibHyps-1.2.0)

  • tac1 ;{! tac2 } applies tac1 to current goal and then tac2 to the list of all new hypothesis in each subgoal (iteration: oldest first). The list is a term of type LibHyps.TacNewHyps.DList. See the code.
  • tac1 ;{!< tac2 } is similar but the list of new hyps is reveresed.

Iterators on EACH NEW hypothesis

  • tac1 ;{ tac2 } applies tac1 to current goal and then tac2 to each new hypothesis in each subgoal (iteration: older first).

  • tac1 ;{< tac2 } is similar but applies tac2 on newer hyps first.

  • tac1 ;; tac2 is a synonym of tac1; { tac2 }.

  • tac1 ;!; tac2 is a synonym of tac1; {< tac2 }.

Customizable hypothesis auto naming system

Using previous taticals (in particular the ;!; tactical), some tactic allow to rename hypothesis automatically.

  • autorename H rename H according to the current naming scheme (which is customizable, see below).

  • rename_all_hyps applies autorename to all hypothesis.

  • !tac applies tactic tac and then applies autorename to each new hypothesis. Shortcut for: (Tac ;!; revert_if_norename ;; autorename)..`

  • !!tac same as !tac with lesser priority (less than ;) to apply renaming after a group of chained tactics.

How to cstomize the naming scheme

The naming engine analyzes the type of hypothesis and generates a name mimicking the first levels of term structure. At each level the customizable tactic rename_hyp is called. One can redefine it at will. It must be of the following form:

(** Redefining rename_hyp*)
(* First define a naming ltac. It takes the current level n and
   the sub-term th being looked at. It returns a "name". *)
Ltac rename_hyp_default n th :=
   match th with
   | (ind1 _ _) => name (`ind1`)
   | (ind1 _ _ ?x ?y) => name (`ind1` ++ x#(S n)x ++ y$n)
   | f1 _ ?x = ?y => name (`f1` ++ x#n ++ y#n)
   | _ => previously_defined_renaming_tac1 n th (* cumulative with previously defined renaming tactics *)
   | _ => previously_defined_renaming_tac2 n th
   end.

(* Then overwrite the definition of rename_hyp using the ::= operator. :*)
Ltac rename_hyp ::= my_rename_hyp.

Where:

  • `id` to use the name id itself
  • t$n to recursively call the naming engine on term t, n being the maximum depth allowed
  • name ++ name to concatenate name parts.

How to define variants of these tacticals?

Some more example of tacticals performing cleaning and renaming on new hypothesis.

(* subst or revert *)
Tactic Notation (at level 4) "??" tactic4(tac1) :=
  (tac1 ;; substHyp ;!; revertHyp).
(* subst or rename or revert *)
Tactic Notation "!!!" tactic3(Tac) := (Tac ;; substHyp ;!; revert_if_norename ;; autorename).
(* subst or rename or revert + move up if in (Set or Type). *)
Tactic Notation (at level 4) "!!!!" tactic4(Tac) :=
      (Tac ;; substHyp ;!; revert_if_norename ;; autorename ;; move_up_types).

libhyps's People

Contributors

matafou avatar palmskog avatar vzaliva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

libhyps's Issues

Please pick the version you prefer for Coq 8.18 in Coq Platform 2023.10

The Coq team released Coq 8.18.0 on September 7th, 2023.
The corresponding Coq Platform release 2023.10 should be released before November 30th, 2023.
It can be delayed in case of difficulties until January 15th, 2023, but this should be an exception.

This issue is to inform you that the opam package we are currently testing in Coq Platform CI works fine with Coq 8.18.0.

Coq Platform CI is currently testing opam package coq-libhyps.2.0.6
from official repository https://coq.inria.fr/opam/released/packages/coq-libhyps/coq-libhyps.2.0.6/opam.

In case this is the version you want to see in Coq Platform, there is nothing to do for you - please just close this issue.

In case you would prefer to see an updated or an older version in the upcoming Coq Platform 2023.10, please inform us as soon as possible and before October 31st, 2023!

The working branch of Coq Platform, can be found here main.
It contains package pick ~8.18+beta1 which already supports Coq version 8.18.0 and contains already working (possibly patched / commit pinned) Coq Platform packages.

In case you want to select a different version, please don't close this issue, even after creating the new tag and/or opam package.
We will close the issue after updating Coq Platform.
This is a measure of 'double book keeping' in order to avoid that we ship the wrong version.

In any case, Coq Platform won't be released before this issue is closed!

Thanks!

P.S.: this issue has been created automatically based on CI status.

CC: coq/platform#372

Error in LibHypsDemo.v

Using Coq 8.9.0

make doesn't actually build LibHypsDemo.v. Adding $(HIDE)$(TIMER) $(COQC) $(COQDEBUG) $(TIMING_ARG) $(COQFLAGS) $(COQLIBS) ./LibHyps/LibHypsDemo.v $(TIMING_EXTRA) to Makefile.local causes it to fail with the following error:

File "./LibHyps/LibHypsDemo.v", line 268, characters 21-61:
Error:
In nested Ltac calls to "(tactic4) ;!; (tactic3)", 
"tac_new_hyps_rev" and "tac1" (bound to decompose [ ex and ]
h_ex_and_neq_true_andb_and_le_w_w_eq_w_x), last call failed.
The reference h_ex_and_neq_true_andb_and_le_w_w_eq_w_x was not found
in the current environment.

Matching non-prop hypotheses of same type together?

Hello,

Your onAllHyps move_up_types. tactic is a life saver when dealing with big messy proofs. However, I really wish it would also organize together variables of identical types together, notably so that proof general would display their type only once.

Do you know if that would be easy to implement? (unless it's already available and I simply missed it?)

Thanks,
Yannick

New release with unambiguous license

After the merging of #10, the licensing concerns in #8 should be addressed. However, the project still can't be easily packaged in a system like Debian, since there is no release (git tag) which has the licensing fixes.

How about releasing a new version (tag libhyps-2.0.4) that includes the licensing fixes? I can help out with packaging on opam and so on.

Please create a tag for Coq 8.14 in Coq Platform 2021.11

The Coq team released Coq 8.14+rc1 on September 17, 2021 and plans to release Coq 8.14.0 before October 31, 2021.
The corresponding Coq Platform release 2021.11 should be released before November 30, 2021.
It can be delayed in case of difficulties until January 31, 2022, but this should be an exception.

This issue is to inform you that to our (possibly a few days old) best knoweldege the latest released version of your project (2.0.3) does not work with Coq 8.14+rc1.
We tried to remove version restrictions in opam files and possibly make or configure files, but this did not suffice.

Please note that in Coq Platform CI (unlike Coq CI) we test only released / tagged versions. Coq CI appears to test this project, but has some special handling for your project which makes it difficult to retrieve the commit it tests for your project.

Could you please create a tag, or communicate us any existing tag that works with Coq branch v8.14, preferably before November 15, 2021?
In case we might have to delay the Coq Platform release cause of issues with your project, we would prefer to be informed about the situation as early as possible.

The working branch of Coq Platform, which already supports Coq version 8.14+rc1, can be found here https://github.com/coq/platform/tree/main.

Please don't close this issue, even after creating the new tag and/or opam package.
We will close the issue after updating Coq Platform.
This is a measure of 'double book keeping' in order to avoid that we ship the wrong version.

In any case, Coq Platform won't be released before this issue is closed!

Thanks!

P.S.: this issue has been created automatically based on CI status.

CC: coq/platform#139

Please create a tag for Coq 8.19 in Coq Platform 2024.01

The Coq team released Coq 8.19.0 on January 24th, 2024.
The corresponding Coq Platform release 2024.01 should be released before April 30th, 2024.
It can be delayed in case of difficulties until May 15th, 2024, but this should be an exception.

This issue is to inform you that to our (possibly a few days old) best knowledge the latest released version of your project (2.0.8) does not work with Coq 8.19.0.
We tried to remove version restrictions in opam files and possibly make or configure files, but this did not suffice.

Please note that in Coq Platform CI (unlike Coq CI) we test only released / tagged versions. Coq CI appears to test this project, but has some special handling for your project which makes it difficult to retrieve the commit it tests for your project.

Could you please create a tag and opam package, or communicate us any existing tag that works with Coq branch v8.19, preferably before March 31st, 2024?
In case we might have to delay the Coq Platform release cause of issues with your project, we would prefer to be informed about the situation as early as possible.

In case the tag and opam package are available before March 31st, 2024, it will be included in an early Coq Platform beta release of the for Coq 8.19.0.

The working branch of Coq Platform, can be found here main.
It contains package pick ~8.19~2024.01+beta1 which already supports Coq version 8.19.0 and contains already working (possibly patched / commit pinned) Coq Platform packages.

Please don't close this issue, even after creating the new tag and/or opam package.
We will close the issue after updating Coq Platform.
This is a measure of 'double book keeping' in order to avoid that we ship the wrong version.

In any case, Coq Platform won't be released before this issue is closed!

Thanks!

P.S.: this issue has been created automatically based on CI status.

CC: coq/platform#405

Licensing

I'm packaging LibHyps for Debian, and found that while the main LICENSE file claims it's MIT:

  • opam still claims its GPL-2 ;
  • LibHyps/LibHypsNaming.v claims both MIT and LGPL-3.

Could you clarify the situation, both here and in a new release?

Thanks!

Please pick the version you prefer for Coq 8.17 in Coq Platform 2023.03

The Coq team released Coq 8.17+rc1 on December 29th, 2022 and plans to release Coq 8.17.0 around March 7th, 2023.
The corresponding Coq Platform release 2023.03 should be released before April 14th, 2023.
It can be delayed in case of difficulties until June 30, 2023, but this should be an exception.

This issue is to inform you that the opam package we are currently testing in Coq Platform CI works fine with Coq 8.17+rc1.

Coq Platform CI is currently testing opam package coq-libhyps.2.0.6
from official repository https://coq.inria.fr/opam/released/packages/coq-libhyps/coq-libhyps.2.0.6/opam.

In case this is the version you want to see in Coq Platform, there is nothing to do for you - please just close this issue.

In case you would prefer to see an updated or an older version in the upcoming Coq Platform 2023.03, please inform us as soon as possible and before March 21st, 2023!

The working branch of Coq Platform, can be found here main.
It contains package pick ~8.17~2023.03+preview1 which already supports Coq version 8.17+rc1 and contains already working (possibly patched / commit pinned) Coq Platform packages.

In case you want to select a different version, please don't close this issue, even after creating the new tag and/or opam package.
We will close the issue after updating Coq Platform.
This is a measure of 'double book keeping' in order to avoid that we ship the wrong version.

In any case, Coq Platform won't be released before this issue is closed!

Thanks!

P.S.: this issue has been created automatically based on CI status.

CC: coq/platform#335

coq-8.11 compatible release

Please make a release compatible with Coq-8.11.
The current master branch seems to be compiling fine, so it is just a matter of making a release and updating OPAM package.
I can produce a PR for OPAM package update, but I need a release first. Thanks!

Please pick the version you prefer for Coq 8.15 in Coq Platform 2022.02

The Coq team released Coq 8.15.0 on January 13, 2022.
The corresponding Coq Platform release 2022.02 should be released before February 28, 2022.
It can be delayed in case of difficulties until April 11, 2022, but this should be an exception.

This issue is to inform you that the opam package we are currently testing in Coq Platform CI works fine with Coq 8.15.0.

Coq Platform CI is currently testing opam package coq-libhyps.2.0.4
from platform patch repository https://github.com/coq/platform/tree/main/opam/opam-coq-archive/released/packages/coq-libhyps/coq-libhyps.2.0.4/opam.

In case this is the version you want to see in Coq Platform, there is nothing to do for you - please just close this issue.

In case you would prefer to see an updated or an older version in the upcoming Coq Platform 2022.02, please inform us as soon as possible and before February 14, 2022!

The working branch of Coq Platform, which already supports Coq version 8.15.0, can be found here https://github.com/coq/platform/tree/main.

In case you want to select a different version, please don't close this issue, even after creating the new tag and/or opam package.
We will close the issue after updating Coq Platform.
This is a measure of 'double book keeping' in order to avoid that we ship the wrong version.

In any case, Coq Platform won't be released before this issue is closed!

Thanks!

P.S.: this issue has been created automatically based on CI status.

CC: coq/platform#193

P.P.S.: I saw that in GIT there are tags 2.0.4.1 and 2.0.5 - Coq Platform is opam based, so it would help if you could create an opam package for each tag. Thanks!

Please pick the version you prefer for Coq 8.16 in Coq Platform 2022.09

The Coq team released Coq 8.16+rc1 on June 01, 2022.
The corresponding Coq Platform release 2022.09 should be released before September 15, 2022.
It can be delayed in case of difficulties until October 15, 2022, but this should be an exception.

This issue is to inform you that the opam package we are currently testing in Coq Platform CI works fine with Coq 8.16+rc1.

Coq Platform CI is currently testing opam package coq-libhyps.2.0.5
from platform patch repository https://github.com/coq/platform/tree/main/opam/opam-coq-archive/released/packages/coq-libhyps/coq-libhyps.2.0.5/opam. This means we had to weaken some version restrictions in the opam package, but no other changes were required.

In case this is the version you want to see in Coq Platform, there is nothing to do for you - please just close this issue.

In case you would prefer to see an updated or an older version in the upcoming Coq Platform 2022.09, please inform us as soon as possible and before August 31, 2022!

The working branch of Coq Platform, can be found here main.
It contains package pick ~8.16+rc1~2022.09~preview1 which already supports Coq version 8.16+rc1 and contains already working (possibly patched / commit pinned) Coq Platform packages.

In case you want to select a different version, please don't close this issue, even after creating the new tag and/or opam package.
We will close the issue after updating Coq Platform.
This is a measure of 'double book keeping' in order to avoid that we ship the wrong version.

In any case, Coq Platform won't be released before this issue is closed!

Thanks!

P.S.: this issue has been created automatically based on CI status.

CC: coq/platform#274

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.