Skip to content
Snippets Groups Projects
Commit 572581f1 authored by Ralf Jung's avatar Ralf Jung
Browse files

Merge branch 'ralf/solve_proper' into 'master'

Factor out solve_proper_prepare

See merge request robbertkrebbers/coq-stdpp!19
parents e1fff8e2 e1c92aa2
No related branches found
No related tags found
1 merge request!19Factor out solve_proper_prepare
Pipeline #
...@@ -304,18 +304,18 @@ Ltac f_equiv := ...@@ -304,18 +304,18 @@ Ltac f_equiv :=
| |- (?R _) (?f _ _ _ _) _ => simple apply (_ : Proper (R _ ==> R _ ==> R _ ==> R _ ==> _) f) | |- (?R _) (?f _ _ _ _) _ => simple apply (_ : Proper (R _ ==> R _ ==> R _ ==> R _ ==> _) f)
| |- (?R _ _) (?f _ _ _ _) _ => simple apply (_ : Proper (R _ _ ==> R _ _ ==> R _ _ ==> R _ _ ==> _) f) | |- (?R _ _) (?f _ _ _ _) _ => simple apply (_ : Proper (R _ _ ==> R _ _ ==> R _ _ ==> R _ _ ==> _) f)
| |- (?R _ _ _) (?f _ _ _ _) _ => simple apply (_ : Proper (R _ _ _ ==> R _ _ _ R _ _ _ ==> R _ _ _ ==> _) f) | |- (?R _ _ _) (?f _ _ _ _) _ => simple apply (_ : Proper (R _ _ _ ==> R _ _ _ R _ _ _ ==> R _ _ _ ==> _) f)
(* Next, try to infer the relation. Unfortunately, there is an instance (* Next, try to infer the relation. Unfortunately, very often, it will turn
of Proper for (eq ==> _), which will always be matched. *) the goal into a Leibniz equality so we get stuck. *)
(* TODO: Can we exclude that instance? *) (* TODO: Can we exclude that instance? *)
(* TODO: If some of the arguments are the same, we could also
query for "pointwise_relation"'s. But that leads to a combinatorial
explosion about which arguments are and which are not the same. *)
| |- ?R (?f _) _ => simple apply (_ : Proper (_ ==> R) f) | |- ?R (?f _) _ => simple apply (_ : Proper (_ ==> R) f)
| |- ?R (?f _ _) _ => simple apply (_ : Proper (_ ==> _ ==> R) f) | |- ?R (?f _ _) _ => simple apply (_ : Proper (_ ==> _ ==> R) f)
| |- ?R (?f _ _ _) _ => simple apply (_ : Proper (_ ==> _ ==> _ ==> R) f) | |- ?R (?f _ _ _) _ => simple apply (_ : Proper (_ ==> _ ==> _ ==> R) f)
| |- ?R (?f _ _ _ _) _ => simple apply (_ : Proper (_ ==> _ ==> _ ==> _ ==> R) f) | |- ?R (?f _ _ _ _) _ => simple apply (_ : Proper (_ ==> _ ==> _ ==> _ ==> R) f)
(* In case the function symbol differs, but the arguments are the same, (* In case the function symbol differs, but the arguments are the same,
maybe we have a pointwise_relation in our context. *) maybe we have a pointwise_relation in our context. *)
(* TODO: If only some of the arguments are the same, we could also
query for "pointwise_relation"'s. But that leads to a combinatorial
explosion about which arguments are and which are not the same. *)
| H : pointwise_relation _ ?R ?f ?g |- ?R (?f ?x) (?g ?x) => simple apply H | H : pointwise_relation _ ?R ?f ?g |- ?R (?f ?x) (?g ?x) => simple apply H
end; end;
try simple apply reflexivity. try simple apply reflexivity.
...@@ -335,23 +335,30 @@ Ltac solve_proper_unfold := ...@@ -335,23 +335,30 @@ Ltac solve_proper_unfold :=
| |- ?R (?f _ _) (?f _ _) => unfold f | |- ?R (?f _ _) (?f _ _) => unfold f
| |- ?R (?f _) (?f _) => unfold f | |- ?R (?f _) (?f _) => unfold f
end. end.
(* [solve_proper_prepare] does some preparation work before the main
(** The tactic [solve_proper_core tac] solves goals of the form "Proper (R1 ==> R2)", for [solve_proper] loop. Having this as a separate tactic is useful for
any number of relations. The actual work is done by repeatedly applying debugging [solve_proper] failure. *)
[tac]. *) Ltac solve_proper_prepare :=
Ltac solve_proper_core tac :=
(* Introduce everything *) (* Introduce everything *)
intros; intros;
repeat lazymatch goal with repeat lazymatch goal with
| |- Proper _ _ => intros ??? | |- Proper _ _ => intros ???
| |- (_ ==> _)%signature _ _ => intros ??? | |- (_ ==> _)%signature _ _ => intros ???
| |- pointwise_relation _ _ _ _ => intros ? | |- pointwise_relation _ _ _ _ => intros ?
| |- ?R ?f _ => try let f' := constr:(λ x, f x) in intros ? | |- ?R ?f _ => let f' := constr:(λ x, f x) in intros ?
end; simplify_eq; end; simplify_eq;
(* Now do the job. We try with and without unfolding. We have to backtrack on (* We try with and without unfolding. We have to backtrack on
that because unfolding may succeed, but then the proof may fail. *) that because unfolding may succeed, but then the proof may fail. *)
(solve_proper_unfold + idtac); simpl; (solve_proper_unfold + idtac); simpl.
(** The tactic [solve_proper_core tac] solves goals of the form "Proper (R1 ==> R2)", for
any number of relations. The actual work is done by repeatedly applying
[tac]. *)
Ltac solve_proper_core tac :=
solve_proper_prepare;
(* Now do the job. *)
solve [repeat first [eassumption | tac ()] ]. solve [repeat first [eassumption | tac ()] ].
(** Finally, [solve_proper] tries to apply [f_equiv] in a loop. *)
Ltac solve_proper := solve_proper_core ltac:(fun _ => f_equiv). Ltac solve_proper := solve_proper_core ltac:(fun _ => f_equiv).
(** The tactic [intros_revert tac] introduces all foralls/arrows, performs tac, (** The tactic [intros_revert tac] introduces all foralls/arrows, performs tac,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment