comparison src/LogicProg.v @ 410:b4c37245502e

Typesetting pass over LogicProg
author Adam Chlipala <adam@chlipala.net>
date Fri, 08 Jun 2012 15:09:11 -0400
parents 05efde66559d
children 610568369aee
comparison
equal deleted inserted replaced
409:934945edc6b5 410:b4c37245502e
141 141
142 (** This time, [auto] is not enough to make any progress. Since even a single candidate step may lead to an infinite space of possible proof trees, [auto] is parameterized on the maximum depth of trees to consider. The default depth is 5, and it turns out that we need depth 6 to prove the goal. *) 142 (** This time, [auto] is not enough to make any progress. Since even a single candidate step may lead to an infinite space of possible proof trees, [auto] is parameterized on the maximum depth of trees to consider. The default depth is 5, and it turns out that we need depth 6 to prove the goal. *)
143 143
144 auto 6. 144 auto 6.
145 145
146 (** Sometimes it is useful to see a description of the proof tree that [auto] finds, with the %\index{tactics!info}%[info] tactical. *) 146 (** Sometimes it is useful to see a description of the proof tree that [auto] finds, with the %\index{tactics!info}%[info] tactical. (This tactical is not available in Coq 8.4 as of this writing, but I hope it reappears soon.) *)
147 147
148 Restart. 148 Restart.
149 info auto 6. 149 info auto 6.
150 (** %\vspace{-.15in}%[[ 150 (** %\vspace{-.15in}%[[
151 == apply PlusS; apply PlusS; apply PlusS; apply PlusS; 151 == apply PlusS; apply PlusS; apply PlusS; apply PlusS;
153 ]] 153 ]]
154 *) 154 *)
155 Qed. 155 Qed.
156 (* end thide *) 156 (* end thide *)
157 157
158 (** The two key components of logic programming are %\index{backtracking}%_backtracking_ and %\index{unification}%_unification_. To see these techniques in action, consider this further silly example. Here our candidate proof steps will be reflexivity and quantifier instantiation. *) 158 (** The two key components of logic programming are%\index{backtracking}% _backtracking_ and%\index{unification}% _unification_. To see these techniques in action, consider this further silly example. Here our candidate proof steps will be reflexivity and quantifier instantiation. *)
159 159
160 Example seven_minus_three : exists x, x + 3 = 7. 160 Example seven_minus_three : exists x, x + 3 = 7.
161 (* begin thide *) 161 (* begin thide *)
162 (** For explanatory purposes, let us simulate a user with minimal understanding of arithmetic. We start by choosing an instantiation for the quantifier. Recall that [ex_intro] is the constructor for existentially quantified formulas. *) 162 (** For explanatory purposes, let us simulate a user with minimal understanding of arithmetic. We start by choosing an instantiation for the quantifier. Recall that [ex_intro] is the constructor for existentially quantified formulas. *)
163 163
183 183
184 Next we demonstrate unification, which will be easier when we switch to the relational formulation of addition. *) 184 Next we demonstrate unification, which will be easier when we switch to the relational formulation of addition. *)
185 185
186 Example seven_minus_three' : exists x, plusR x 3 7. 186 Example seven_minus_three' : exists x, plusR x 3 7.
187 (* begin thide *) 187 (* begin thide *)
188 (** We could attempt to guess the quantifier instantiation manually as before, but here there is no need. Instead of [apply], we use %\index{tactics!eapply}%[eapply] instead, which proceeds with placeholder %\index{unification variable}%_unification variables_ standing in for those parameters we wish to postpone guessing. *) 188 (** We could attempt to guess the quantifier instantiation manually as before, but here there is no need. Instead of [apply], we use %\index{tactics!eapply}%[eapply] instead, which proceeds with placeholder%\index{unification variable}% _unification variables_ standing in for those parameters we wish to postpone guessing. *)
189 189
190 eapply ex_intro. 190 eapply ex_intro.
191 (** [[ 191 (** [[
192 1 subgoal 192 1 subgoal
193 193
378 ]] 378 ]]
379 *) 379 *)
380 Abort. 380 Abort.
381 End slow. 381 End slow.
382 382
383 (** Sometimes, though, transitivity is just what is needed to get a proof to go through automatically with [eauto]. For those cases, we can use named %\index{hint databases}%_hint databases_ to segragate hints into different groups that may be called on as needed. Here we put [eq_trans] into the database [slow]. *) 383 (** Sometimes, though, transitivity is just what is needed to get a proof to go through automatically with [eauto]. For those cases, we can use named%\index{hint databases}% _hint databases_ to segragate hints into different groups that may be called on as needed. Here we put [eq_trans] into the database [slow]. *)
384 384
385 (* begin thide *) 385 (* begin thide *)
386 Hint Resolve eq_trans : slow. 386 Hint Resolve eq_trans : slow.
387 (* end thide *) 387 (* end thide *)
388 388
789 789
790 Theorem bool_neq : true <> false. 790 Theorem bool_neq : true <> false.
791 (* begin thide *) 791 (* begin thide *)
792 auto. 792 auto.
793 793
794 (** [crush] would have discharged this goal, but the default hint database for [auto] contains no hint that applies. *) 794 (** A call to [crush] would have discharged this goal, but the default hint database for [auto] contains no hint that applies. *)
795 795
796 Abort. 796 Abort.
797 797
798 (** It is hard to come up with a [bool]-specific hint that is not just a restatement of the theorem we mean to prove. Luckily, a simpler form suffices, by appealing to the built-in tactic %\index{tactics!congruence}%[congruence], a complete procedure for the theory of equality, uninterpreted functions, and datatype constructors. *) 798 (** It is hard to come up with a [bool]-specific hint that is not just a restatement of the theorem we mean to prove. Luckily, a simpler form suffices, by appealing to the built-in tactic %\index{tactics!congruence}%[congruence], a complete procedure for the theory of equality, uninterpreted functions, and datatype constructors. *)
799 799
802 Theorem bool_neq : true <> false. 802 Theorem bool_neq : true <> false.
803 auto. 803 auto.
804 Qed. 804 Qed.
805 (* end thide *) 805 (* end thide *)
806 806
807 (** [Extern] hints may be implemented with the full Ltac language. This example shows a case where a hint uses a [match]. *) 807 (** A [Hint Extern] may be implemented with the full Ltac language. This example shows a case where a hint uses a [match]. *)
808 808
809 Section forall_and. 809 Section forall_and.
810 Variable A : Set. 810 Variable A : Set.
811 Variables P Q : A -> Prop. 811 Variables P Q : A -> Prop.
812 812
840 ]] 840 ]]
841 << 841 <<
842 User error: Bound head variable 842 User error: Bound head variable
843 >> 843 >>
844 844
845 Coq's [auto] hint databases work as tables mapping %\index{head symbol}%_head symbols_ to lists of tactics to try. Because of this, the constant head of an [Extern] pattern must be determinable statically. In our first [Extern] hint, the head symbol was [not], since [x <> y] desugars to [not (eq x y)]; and, in the second example, the head symbol was [P]. 845 Coq's [auto] hint databases work as tables mapping%\index{head symbol}% _head symbols_ to lists of tactics to try. Because of this, the constant head of an [Extern] pattern must be determinable statically. In our first [Extern] hint, the head symbol was [not], since [x <> y] desugars to [not (eq x y)]; and, in the second example, the head symbol was [P].
846 846
847 Fortunately, a more basic form of [Hint Extern] also applies. We may simply leave out the pattern to the left of the [=>], incorporating the corresponding logic into the Ltac script. *) 847 Fortunately, a more basic form of [Hint Extern] also applies. We may simply leave out the pattern to the left of the [=>], incorporating the corresponding logic into the Ltac script. *)
848 848
849 Hint Extern 1 => 849 Hint Extern 1 =>
850 match goal with 850 match goal with
946 intros; autorewrite with core; reflexivity. 946 intros; autorewrite with core; reflexivity.
947 (* end thide *) 947 (* end thide *)
948 Qed. 948 Qed.
949 End garden_path. 949 End garden_path.
950 950
951 (** remove printing * *)
952
953 (** It can also be useful to apply the [autorewrite with db in *] form, which does rewriting in hypotheses, as well as in the conclusion. *) 951 (** It can also be useful to apply the [autorewrite with db in *] form, which does rewriting in hypotheses, as well as in the conclusion. *)
954
955 (** printing * $*$ *)
956 952
957 Lemma in_star : forall x y, f (f (f (f x))) = f (f y) 953 Lemma in_star : forall x y, f (f (f (f x))) = f (f y)
958 -> f x = f (f (f y)). 954 -> f x = f (f (f y)).
959 (* begin thide *) 955 (* begin thide *)
960 intros; autorewrite with core in *; assumption. 956 intros; autorewrite with core in *; assumption.