fact
stringlengths 12
6.75k
| type
stringclasses 14
values | library
stringclasses 3
values | imports
listlengths 0
17
| filename
stringclasses 26
values | symbolic_name
stringlengths 2
34
| docstring
stringclasses 1
value |
|---|---|---|---|---|---|---|
euclidean_division : forall x y:R, y <> 0 -> exists k : Z, (exists r : R, x = IZR k * y + r /\ 0 <= r < Rabs y). Proof. unfold not; intros x y H. assert (H0: y > 0 \/ y <= 0). { hecrush use: @Rtotal_order unfold: Rle. } destruct H0 as [H0|H0]. - pose (k := (up (x / y) - 1)%Z). exists k. exists (x - IZR k * y). assert (HH: IZR k = IZR (up (x / y)) - 1). { assert (IZR k = IZR (up (x / y)) - IZR 1%Z). { qauto use: @Z_R_minus. } sauto. } rewrite HH; clear HH. clear k. split. + qauto use: RIneq.Rplus_minus. + assert (HH: x - (IZR (up (x / y)) - 1) * y = x - IZR (up (x / y)) * y + y) by lra. rewrite HH; clear HH. split. * assert (IZR (up (x / y)) * y <= y + x). { assert (IZR (up (x / y)) <= 1 + (x / y)). { generalize (archimed (x / y)); sintuition. assert (IZR (up (x / y)) - (x / y) + (x / y) <= 1 + (x / y)). { qauto use: @Rplus_le_compat_r. } qauto use: Rplus_opp_l, Rplus_assoc, Rplus_0_r unfold: Rdefinitions.Rminus. } assert (IZR (up (x / y)) * y <= (1 + x / y) * y) by sauto. assert (IZR (up (x / y)) * y <= y + ((x / y) * y)). { qauto use: @Rmult_1_l, @Rmult_plus_distr_r. } hfcrush use: @Rmult_1_r, @Rmult_assoc, @Rinv_l_sym unfold: Rdiv. } lra. * assert (IZR (up (x / y)) * y > x). { assert (IZR (up (x / y)) > x / y). { hauto use: @archimed. } assert (IZR (up (x / y)) * y > (x / y) * y). { hauto use: @Rmult_gt_compat_r. } hfcrush use: @Rmult_1_r, @Rmult_assoc, @Rmult_comm, @Rinv_r_sym unfold: Rdiv. } assert (HH: Rabs y = y). { (* Unset Hammer CVC4. hammer. *) (* If you get an unreconstructible proof, it might help to disable the prover which found it. *) hauto ered: off use: @Rlt_asym unfold: Rabs, Rgt. } rewrite HH; clear HH. lra. - pose (k := (1 - up (x / -y))%Z). exists k. exists (x - IZR k * y). assert (HH: IZR k = 1 - IZR (up (x / -y))). { assert (IZR k = IZR 1 - IZR (up (x / -y))). { hauto ered: off use: @Z_R_minus unfold: Rminus, BinIntDef.Z.sub, Rdiv. } sauto. } rewrite HH; clear HH. clear k. split. + qauto use: @Rplus_minus. + assert (HH: x - (1 - IZR (up (x / - y))) * y = x - y + IZR (up (x / -y)) * y) by lra. rewrite HH; clear HH. split. * assert (IZR (up (x / -y)) * y >= y - x). { assert (IZR (up (x / -y)) <= 1 + (x / -y)). { generalize (archimed (x / -y)); sintuition. assert (IZR (up (x / -y)) - (x / -y) + (x / -y) <= 1 + (x / -y)). { hauto use: @Rplus_comm, @Rplus_le_compat_l. } hcrush use: @Rplus_opp_l, @Rplus_assoc, @Rplus_0_r unfold: Rminus, Rmax. } assert (y < 0) by sauto. assert (IZR (up (x / - y)) * y >= y + (x / - y) * y). { assert (IZR (up (x / - y)) * (-y) <= (1 + (x / - y)) * (-y)). { hauto use: @Ropp_0_ge_le_contravar, @Rmult_le_compat_r, @RIneq.Rle_ge. } assert (HH: IZR (up (x / - y)) * (-y) = - (IZR (up (x / - y)) * y)) by lra. rewrite HH in *; clear HH. assert (HH: (1 + (x / - y)) * (-y) = - (y + (x / -y) * y)) by lra. rewrite HH in *; clear HH. hfcrush use: @Rle_ge, @Ropp_le_cancel unfold: Rle, Rge, Rgt. } assert (HH: y + x / - y * y = y - x). { assert (x / - y * - y = x). { assert (HH1: - y > 0) by lra. assert (HH2: forall u, u <> 0 -> (x / u) * u = x). { hfcrush use: @Rinv_l_sym, @Rmult_1_r, @Rmult_assoc unfold: Rdiv. } (* Unset Hammer CVC4. hammer. *) qauto use: @Ropp_gt_cancel, @atan_right_inv, @Rgt_not_eq unfold: atan, Rdiv. } qauto use: @Ropp_involutive, @Ropp_mult_distr_r_reverse unfold: Rminus. } rewrite HH in *; clear HH. sauto. } lra. * assert (HH: Rabs y = -y). { qauto use: @Rabs_left1. } rewrite HH; clear HH. assert (IZR (up (x / -y)) * y < -x). { assert (IZR (up (x / -y)) > x / -y). { hfcrush use: @archimed. } assert (IZR (up (x / -y)) * -y > (x / -y) * -y). { hauto ered: off use: @Rlt_irrefl, @Rmult_gt_compat_r, @Rabs_pos, @Rabs_pos_lt, @Rle_lt_trans unfold: Rabs, Rle, Rgt. } assert (HH: x / - y * - y = x). { assert (- y <> 0). { hauto use: @Rplus_0_r, @Rplus_opp_r. } assert (forall u, u <> 0 -> (x / u) * u = x). { hfcrush use: @Rmult_1_r, @Rinv_l_sym, @Rmult_assoc unfold: Rdiv. } sauto. } rewrite HH in *; clear HH. lra. } lra. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Reals.",
"Require Import Lra."
] |
examples/euclidean_division.v
|
euclidean_division
| |
lem_false : False. Proof. hammer. Qed.*) (*
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_false
| |
lem_classic : forall P : Prop, P \/ ~P. Proof. hammer. Qed.*) Require Import Arith. (* disable the preliminary sauto tactic *) Set Hammer SAutoLimit 0.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_classic
| |
lem_1 : le 1 2. hammer. Restart. scongruence use: Nat.lt_0_2 unfold: lt. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_1
| |
lem_2 : forall n : nat, Nat.Odd n \/ Nat.Odd (n + 1). hammer. Restart. hauto lq: on use: Nat.Even_or_Odd, Nat.add_1_r, Nat.Odd_succ. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_2
| |
lem_2_1 : forall n : nat, Nat.Even n \/ Nat.Even (n + 1). hammer. Restart. hauto lq: on use: Nat.add_1_r, Nat.Even_or_Odd, Nat.Even_succ. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_2_1
| |
lem_3 : le 2 3. hammer. Restart. srun eauto use: Nat.le_succ_diag_r unfold: Init.Nat.two. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_3
| |
lem_4 : le 3 10. hammer. Restart. sfirstorder use: Nat.nle_succ_0, Nat.le_gt_cases, Nat.lt_succ_r, Nat.succ_le_mono, Nat.log2_up_2 unfold: Init.Nat.two. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_4
| |
mult_1 : forall m n k : nat, m * n + k = k + n * m. Proof. hammer. Restart. scongruence use: Nat.mul_comm, Nat.add_comm. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
mult_1
| |
lem_rew : forall m n : nat, 1 + n + m + 1 = m + 2 + n. Proof. hammer. Restart. strivial use: Nat.add_comm, Nat.add_1_r, Nat.add_shuffle1, Nat.add_assoc. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_rew
| |
lem_pow : forall n : nat, 3 * 3 ^ n = 3 ^ (n + 1). Proof. hammer. Restart. qauto use: Nat.pow_succ_r, Nat.le_0_l, Nat.add_1_r. Qed. Require Coq.Reals.RIneq. Require Coq.Reals.Raxioms. Require Coq.Reals.Rtrigo1.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_pow
| |
cos_decreasing_1 : forall y x : Rdefinitions.R, Rdefinitions.Rlt x y -> Rdefinitions.Rle x Rtrigo1.PI -> Rdefinitions.Rge y Rdefinitions.R0 -> Rdefinitions.Rle y Rtrigo1.PI -> Rdefinitions.Rge x Rdefinitions.R0 -> Rdefinitions.Rlt (Rtrigo_def.cos y) (Rtrigo_def.cos x). Proof. (* hammer. Restart. *) hauto using (@Reals.Rtrigo1.cos_decreasing_1, @Reals.RIneq.Rge_le). Qed. Require ZArith.BinInt.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
cos_decreasing_1
| |
max_lub : forall m p k n : BinNums.Z, BinInt.Z.ge p m -> BinInt.Z.le n p -> BinInt.Z.le (BinInt.Z.max n m) p. Proof. hammer. Restart. srun eauto use: BinInt.Z.max_lub, BinInt.Z.ge_le. Qed. Require Reals.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
max_lub
| |
lem_iso : forall x1 y1 x2 y2 theta : Rdefinitions.R, Rgeom.dist_euc x1 y1 x2 y2 = Rgeom.dist_euc (Rgeom.xr x1 y1 theta) (Rgeom.yr x1 y1 theta) (Rgeom.xr x2 y2 theta) (Rgeom.yr x2 y2 theta). Proof. hammer. Restart. scongruence use: Rgeom.isometric_rotation. Qed. Require Import List.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_iso
| |
lem_lst : forall {A} (x : A) l1 l2 (P : A -> Prop), In x (l1 ++ l2) -> (forall y, In y l1 -> P y) -> (forall y, In y l2 -> P y) -> P x. Proof. hammer. Restart. qauto use: in_app_iff. (* `firstorder with datatypes' does not work *) Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_lst
| |
lem_lst2 : forall {A} (y1 y2 y3 : A) l l' z, In z l \/ In z l' -> In z (y1 :: y2 :: l ++ y3 :: l'). Proof. hammer. Restart. hauto lq: on use: in_app_iff, in_or_app, not_in_cons, in_cons, Add_in unfold: app. (* `firstorder with datatypes' does not work *) Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_lst2
| |
lem_lst3 : forall {A} (l : list A), length (tl l) <= length l. Proof. hammer. Restart. qauto use: le_S, Nat.le_0_l, le_n unfold: tl, length. Qed. Require NArith.Ndec.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_lst3
| |
Nleb_alt : forall b a c : BinNums.N, Ndec.Nleb b c = BinNat.N.leb b c /\ Ndec.Nleb a b = BinNat.N.leb a b. Proof. hammer. Restart. srun eauto use: Ndec.Nleb_alt. Qed. Require NArith.BinNat.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
Nleb_alt
| |
setbit_iff : forall m a n : BinNums.N, n = m \/ true = BinNat.N.testbit a m <-> BinNat.N.testbit (BinNat.N.setbit a n) m = true. Proof. hammer. Restart. hfcrush use: BinNat.N.setbit_iff. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
setbit_iff
| |
in_int_p_Sq : forall r p q a : nat, a >= 0 -> Between.in_int p (S q) r -> Between.in_int p q r \/ r = q \/ a = 0. Proof. hammer. Restart. hauto lq: on use: in_int_p_Sq. Qed. Require Reals.Rminmax.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
in_int_p_Sq
| |
min_spec_1 : forall n m : Rdefinitions.R, (Rdefinitions.Rle m n /\ Rbasic_fun.Rmin m m = m) \/ (Rdefinitions.Rlt n m /\ Rbasic_fun.Rmin m n = n). Proof. hammer. Restart. hauto use: RIneq.Rnot_le_lt unfold: Rbasic_fun.Rmin. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
min_spec_1
| |
min_spec_2 : forall n m : Rdefinitions.R, (Rdefinitions.Rle m n /\ Rbasic_fun.Rmin m n = m) \/ (Rdefinitions.Rlt n m /\ Rbasic_fun.Rmin m n = n). Proof. hammer. Restart. hauto use: RIneq.Rnot_le_lt unfold: Rbasic_fun.Rmin. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
min_spec_2
| |
incl_app : forall (A : Type) (n l m : list A), List.incl l n /\ List.incl m n -> List.incl (l ++ m) n. Proof. hammer. Restart. strivial use: incl_app. Qed. Require Reals.Rpower.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
incl_app
| |
exp_Ropp : forall x y : Rdefinitions.R, Rdefinitions.Rinv (Rtrigo_def.exp x) = Rtrigo_def.exp (Rdefinitions.Ropp x). Proof. hammer. Restart. srun eauto use: Rpower.exp_Ropp. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
exp_Ropp
| |
lem_lst_1 : forall (A : Type) (l l' : list A), List.NoDup (l ++ l') -> List.NoDup l. Proof. (* The hammer can't do induction. If induction is necessary to carry out the proof, then one needs to start the induction manually. *) induction l'. - hammer. Undo. scongruence use: app_nil_end. - hammer. Undo. srun eauto use: NoDup_remove_1. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
lem_lst_1
| |
NoDup_remove_2 : forall (A : Type) (a : A) (l' l : list A), List.NoDup (l ++ a :: l') -> ~ List.In a (l ++ l') /\ List.NoDup (l ++ l') /\ List.NoDup l. Proof. hammer. Restart. strivial use: lem_lst_1, NoDup_remove. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
NoDup_remove_2
| |
leb_compare2 : forall m n : nat, PeanoNat.Nat.leb n m = true <-> (PeanoNat.Nat.compare n m = Lt \/ PeanoNat.Nat.compare n m = Eq). Proof. (* hammer. Restart. *) (* Sometimes the tactics cannot reconstruct the goal, but the returned dependencies may still be used to create the proof semi-manually. *) assert (forall c : Datatypes.comparison, c = Eq \/ c = Lt \/ c = Gt) by sauto inv: Datatypes.comparison. hauto erew: off use: Compare_dec.leb_compare. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
leb_compare2
| |
leb_1 : forall m n : nat, PeanoNat.Nat.leb m n = true <-> m <= n. Proof. hammer. Restart. srun eauto use: Nat.leb_le, Nat.leb_nle, leb_correct, leb_complete. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
leb_1
| |
leb_2 : forall m n : nat, PeanoNat.Nat.leb m n = false <-> m > n. Proof. hammer. Restart. srun eauto use: leb_iff_conv, leb_correct_conv unfold: gt. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
leb_2
| |
incl_appl_1 : forall (A : Type) (l m n : list A), List.incl l n -> List.incl l (n ++ m) /\ List.incl l (m ++ n) /\ List.incl l (l ++ l). Proof. hammer. Restart. strivial use: incl_appl, incl_refl, incl_appr. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
incl_appl_1
| |
in_int_lt2 : forall p q r : nat, Between.in_int p q r -> q >= p /\ r >= p /\ r <= q. Proof. hammer. Restart. sfirstorder use: Nat.lt_le_incl, in_int_lt unfold: ge, in_int. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
in_int_lt2
| |
nat_compare_eq : forall n m : nat, PeanoNat.Nat.compare n m = Eq <-> n = m. Proof. hammer. Restart. srun eauto use: Nat.compare_eq_iff. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
nat_compare_eq
| |
Forall_1 : forall (A : Type) (P : A -> Prop) (a : A), forall (l l' : list A), List.Forall P l /\ List.Forall P l' /\ P a -> List.Forall P (l ++ a :: l'). Proof. induction l. - hammer. Undo. strivial use: app_nil_l, Forall_cons. - (* hammer. Undo. *) sauto use: Forall_cons. Restart. induction l; qsimpl. Qed. (* Neither the base case nor the inductive step may be solved using 'firstorder with datatypes'. *)
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
Forall_1
| |
Forall_impl : forall (A : Type) (P : A -> Prop), forall l : list A, List.Forall P l -> List.Forall P (l ++ l). Proof. induction l. - hammer. Undo. srun eauto use: app_nil_end. - hammer. Undo. qauto use: Forall_inv, Forall_inv_tail, Forall_1. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
Forall_impl
| |
minus_neq_O : forall n i:nat, (i < n) -> (n - i) <> 0. Proof. hammer. Undo. srun eauto use: Nat.sub_gt. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import List."
] |
examples/hammer_tests.v
|
minus_neq_O
| |
lem_0 : forall n m, n <> 0 -> m * m = 2 * n * n -> m < 2 * n. Proof. intros n m H H0. destruct (lt_dec m (2 * n)) as [|H1]; try strivial. exfalso. assert (m >= 2 * n) by lia. clear H1. assert (m * m >= 2 * n * (2 * n)). { assert (m * m >= 2 * n * m). { hauto use: @Nat.le_0_l, @Nat.mul_le_mono_nonneg_r unfold: ge. } assert (2 * n * m >= 2 * n * (2 * n)). { hauto use: @Nat.le_0_l, @Nat.mul_le_mono_nonneg_l unfold: ge. } eauto with arith. } sauto. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Reals.",
"Require Import Arith.",
"Require Import Wf_nat.",
"Require Import Even.",
"Require Import Lia."
] |
examples/sqrt2_irrational.v
|
lem_0
| |
lem_main : forall n m, n * n = 2 * m * m -> m = 0. Proof. intro n; pattern n; apply lt_wf_ind; clear n. intros n H m H0. destruct (Nat.eq_dec n 0) as [H1|H1]; subst. - sauto. - destruct (even_odd_cor n) as [k HH]. destruct HH as [H2|H2]; subst. + assert (2 * k * k = m * m) by lia. assert (m < 2 * k). { qauto use: @Nat.mul_0_r, @lem_0. } sauto. + sauto. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Reals.",
"Require Import Arith.",
"Require Import Wf_nat.",
"Require Import Even.",
"Require Import Lia."
] |
examples/sqrt2_irrational.v
|
lem_main
| |
thm_irrational : forall (p q : nat), q <> 0 -> sqrt 2 <> (INR p / INR q)%R. Proof. unfold not. intros p q H H0. assert (2 * q * q = p * p). { assert (((sqrt 2) ^ 2)%R = 2%R). { hauto use: @Rsqr_sqrt, @Rlt_R0_R2, @Rsqr_pow2 unfold: Rle. } assert (((INR p / INR q) ^ 2)%R = ((INR p / INR q) * (INR p / INR q))%R). { qauto use: @Rsqr_pow2 unfold: Rsqr. } assert (((INR p / INR q) * (INR p / INR q))%R = ((INR p * INR p) / (INR q * INR q))%R). { hauto use: @Rsqr_div, @not_0_INR. } assert (HH: 2%R = ((INR p * INR p) / (INR q * INR q))%R) by sauto. assert (INR q <> 0%R). { qauto use: @INR_not_0, @INR_eq. } assert (HH2: (2 * INR q * INR q)%R = (INR p * INR p)%R). { rewrite HH; rewrite Rmult_assoc. hfcrush use: @Rinv_l_sym, @Rmult_1_r, @Rmult_integral_contrapositive_currified, @Rmult_assoc unfold: Rsqr, Rdiv. } clear -HH2. assert (forall a b, INR a = INR b -> a = b). { qauto use: @INR_eq. } assert (INR (2 * q * q) = INR (p * p)). { assert (INR (p * p) = (INR p * INR p)%R). { hfcrush use: @mult_INR. } assert (INR (2 * q * q) = (2 * INR q * INR q)%R). { assert (INR (2 * q * q) = (INR 2 * INR q * INR q)%R). { hauto ered: off use: @mult_INR. } sauto. } sauto. } sauto. } sauto use: lem_main. Qed.
|
Theorem
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Reals.",
"Require Import Arith.",
"Require Import Wf_nat.",
"Require Import Even.",
"Require Import Lia."
] |
examples/sqrt2_irrational.v
|
thm_irrational
| |
lem_odd : forall n : nat, Nat.Odd n \/ Nat.Odd (n + 1). Proof. (* hammer. *) hauto lq: on use: Nat.Odd_succ, Nat.Even_or_Odd, Nat.add_1_r. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import Sorting."
] |
examples/tutorial/hammer/demo.v
|
lem_odd
| |
lem_even : forall n : nat, Nat.Even n \/ Nat.Even (n + 1). Proof. (* predict 16. *) (* hammer. *) hauto lq: on use: Nat.add_1_r, Nat.Even_or_Odd, Nat.Even_succ. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import Sorting."
] |
examples/tutorial/hammer/demo.v
|
lem_even
| |
lem_pow : forall n : nat, 3 * 3 ^ n = 3 ^ (n + 1). Proof. Fail sauto. (* hammer. *) hauto lq: on use: Nat.pow_succ_r, Nat.le_0_l, Nat.add_1_r. Qed. Require List. Import List.ListNotations. Open Scope list_scope.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import Sorting."
] |
examples/tutorial/hammer/demo.v
|
lem_pow
| |
lem_incl_concat : forall (A : Type) (l m n : list A), List.incl l n -> List.incl l (n ++ m) /\ List.incl l (m ++ n) /\ List.incl l (l ++ l). Proof. (* hammer. *) strivial use: List.incl_appr, List.incl_refl, List.incl_appl. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import Sorting."
] |
examples/tutorial/hammer/demo.v
|
lem_incl_concat
| |
lem_lst_1 : forall (A : Type) (l l' : list A), List.NoDup (l ++ l') -> List.NoDup l. Proof. (* The "hammer" tactic can't do induction. If induction is necessary to carry out the proof, then one needs to start the induction manually. *) induction l'. - (* hammer. *) scongruence use: List.app_nil_end. - (* hammer. *) srun eauto use: List.NoDup_remove_1. Qed. Require Import Sorting.Permutation. (*
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import Sorting."
] |
examples/tutorial/hammer/demo.v
|
lem_lst_1
| |
lem_perm_1 {A} : forall (x y : A) l1 l2 l3, Permutation l1 (y :: l2) -> Permutation (x :: l1 ++ l3) (y :: x :: l2 ++ l3). Proof. hammer. *)
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import Sorting."
] |
examples/tutorial/hammer/demo.v
|
lem_perm_1
| |
lem_perm_0 {A} : forall (x y : A) l1 l2 l3, Permutation l1 (y :: l2) -> Permutation (x :: l1 ++ l3) (x :: y :: l2 ++ l3). Proof. (* hammer. *) hauto lq: on drew: off use: Permutation_app, List.app_comm_cons, Permutation_refl, perm_skip. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import Sorting."
] |
examples/tutorial/hammer/demo.v
|
lem_perm_0
| |
lem_perm_1 {A} : forall (x y : A) l1 l2 l3, Permutation l1 (y :: l2) -> Permutation (x :: l1 ++ l3) (y :: x :: l2 ++ l3). Proof. (* hammer. *) srun eauto use: @lem_perm_0, perm_skip, Permutation_Add, Permutation_trans, Permutation_sym, perm_swap unfold: app. Undo. (* Occasionally, some of the returned dependencies are not necessary. *) srun eauto use: @lem_perm_0, Permutation_trans, perm_swap. (* Undo. Set Hammer MinimizationThreshold 0. hammer. *) Qed. (* A general advice: use "hammer" to prove entire lemmas which are stated separately. Using "hammer" to prove subgoals in a larger proof is less effective. One reason is that the machine-learning premise selection can get confused by the presence of unnecessary hypotheses in the context. *)
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import Sorting."
] |
examples/tutorial/hammer/demo.v
|
lem_perm_1
| |
lem_perm_2 : forall (x : nat) l1 l2 l3, Permutation (x :: l1) l2 -> Permutation (x :: l3 ++ l1) (l3 ++ l2). Proof. (* hammer. *) (* If an ATP returns at least 8 dependencies, then "hammer" tries to automatically minimize the number of dependencies by repeatedly running the ATPs with the returned dependencies as long as some ATP returns fewer dependencies. *) srun eauto use: Permutation_app_head, Permutation_trans, Permutation_app_comm, Permutation_cons_app. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import Sorting."
] |
examples/tutorial/hammer/demo.v
|
lem_perm_2
| |
lem_perm_3 : forall (x y : nat) l1 l2 l3, Permutation (x :: l1) l2 -> Permutation (x :: y :: l1 ++ l3) (y :: l2 ++ l3). Proof. (* hammer. *) srun eauto use: @lem_perm_1, Permutation_sym. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import Sorting."
] |
examples/tutorial/hammer/demo.v
|
lem_perm_3
| |
lem_perm_4 : forall (x y : nat) l1 l2 l3, Permutation (x :: l1) l2 -> Permutation (x :: y :: l3 ++ l1) (y :: l3 ++ l2). Proof. (* hammer. *) intros. rewrite List.app_comm_cons. pattern (y :: l3 ++ l2). rewrite List.app_comm_cons. apply lem_perm_2; assumption. Qed. (*
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import Sorting."
] |
examples/tutorial/hammer/demo.v
|
lem_perm_4
| |
lem_classic : forall P : Prop, P \/ ~P. Proof. hammer. Qed.*)
|
Lemma
|
examples
|
[
"From Hammer Require Import Hammer.",
"Require Import Arith.",
"Require Import Sorting."
] |
examples/tutorial/hammer/demo.v
|
lem_classic
| |
is_cd d a b := a mod d = 0 /\ b mod d = 0. (* Is "d" the greatest common divisor of "a" and "b"? *)
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics.",
"From Hammer Require Import Hammer.",
"Require Import Program.",
"Require Import Arith.",
"Require Import Lia."
] |
examples/tutorial/hammer/gcd.v
|
is_cd
| |
is_gcd d a b := is_cd d a b /\ forall d', is_cd d' a b -> d' <= d.
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics.",
"From Hammer Require Import Hammer.",
"Require Import Program.",
"Require Import Arith.",
"Require Import Lia."
] |
examples/tutorial/hammer/gcd.v
|
is_gcd
| |
lem_gcd_step : forall a b d, b <> 0 -> is_gcd d b (a mod b) -> is_gcd d a b. Proof. unfold is_gcd, is_cd. intros a b d Hb. sintuition. - destruct (Nat.eq_dec d 0) as [Hd|Hd]. + subst; reflexivity. + assert (Hc1: exists c1, b = d * c1). { (* hammer. *) strivial use: Nat.mod_divides. } assert (Hc2: exists c2, a mod b = d * c2). { (* hammer. *) strivial use: Nat.mod_divides. } assert (Hc3: exists c3, a = b * c3 + a mod b). { (* hammer. *) srun eauto use: Nat.div_mod. } clear -Hc1 Hc2 Hc3 Hd. destruct Hc1 as [c1 H1]. destruct Hc2 as [c2 H2]. destruct Hc3 as [c3 H3]. subst. rewrite H2 in H3. subst. assert (H: d * c1 * c3 + d * c2 = (c1 * c3 + c2) * d) by lia. rewrite H. auto using Nat.mod_mul. - enough ((a mod b) mod d' = 0) by auto. destruct (Nat.eq_dec d' 0) as [Hd|Hd]. + subst; reflexivity. + assert (Hc1: exists c1, b = d' * c1) by hauto use: Nat.mod_divides. assert (Hc2: exists c2, a = d' * c2) by hauto use: Nat.mod_divides. assert (Hc3: exists c3, a = b * c3 + a mod b). { exists (a / b); auto using Nat.div_mod. } clear -Hc1 Hc2 Hc3 Hd Hb. destruct Hc1 as [c1 H1]. destruct Hc2 as [c2 H2]. destruct Hc3 as [c3 H3]. subst. (* hammer. *) clear - Hb Hd. (* Coq.Arith.PeanoNat.Nat.mod_mul, Coq.Arith.PeanoNat.Nat.mul_mod_distr_l, Coq.Arith.PeanoNat.Nat.mul_comm *) rewrite Nat.mul_mod_distr_l; [| lia | lia ]. rewrite Nat.mul_comm. apply Nat.mod_mul; assumption. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics.",
"From Hammer Require Import Hammer.",
"Require Import Program.",
"Require Import Arith.",
"Require Import Lia."
] |
examples/tutorial/hammer/gcd.v
|
lem_gcd_step
| |
Fixpoint gcd (a b : nat) {measure b} : {d : nat | a + b > 0 -> is_gcd d a b} := match b with | 0 => a | _ => gcd b (a mod b) end.
|
Program
|
examples
|
[
"From Hammer Require Import Tactics.",
"From Hammer Require Import Hammer.",
"Require Import Program.",
"Require Import Arith.",
"Require Import Lia."
] |
examples/tutorial/hammer/gcd.v
|
Fixpoint
| |
Obligation . unfold is_gcd, is_cd. sintuition. - (* hammer. *) sfirstorder use: Nat.mod_same. - (* hammer. *) (* time sauto. *) (* Set Hammer SAutoLimit 0. hammer. *) sfirstorder use: Nat.mod_0_l. - (* hammer. *) qauto use: Nat.add_pos_cases, Nat.le_gt_cases, Nat.mod_small, Nat.neq_0_lt_0. Qed.
|
Next
|
examples
|
[
"From Hammer Require Import Tactics.",
"From Hammer Require Import Hammer.",
"Require Import Program.",
"Require Import Arith.",
"Require Import Lia."
] |
examples/tutorial/hammer/gcd.v
|
Obligation
| |
Obligation . (* hammer. *) srun eauto use: Nat.mod_upper_bound. Qed.
|
Next
|
examples
|
[
"From Hammer Require Import Tactics.",
"From Hammer Require Import Hammer.",
"Require Import Program.",
"Require Import Arith.",
"Require Import Lia."
] |
examples/tutorial/hammer/gcd.v
|
Obligation
| |
Obligation . simpl_sigma. (* hammer. *) apply lem_gcd_step; [ lia | apply i; lia ]. Qed. Check gcd. Compute ` (gcd 2 3). Compute ` (gcd 5 15). Compute ` (gcd 20 15). Compute ` (gcd 2424 1542).
|
Next
|
examples
|
[
"From Hammer Require Import Tactics.",
"From Hammer Require Import Hammer.",
"Require Import Program.",
"Require Import Arith.",
"Require Import Lia."
] |
examples/tutorial/hammer/gcd.v
|
Obligation
| |
type := Nat | Bool | Prod (ty1 ty2 : type).
|
Inductive
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
type
| |
tyeval (ty : type) : Type := match ty with | Nat => nat | Bool => bool | Prod ty1 ty2 => tyeval ty1 * tyeval ty2 end.
|
Fixpoint
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
tyeval
| |
expr : type -> Type := | Var : string -> expr Nat | Plus : expr Nat -> expr Nat -> expr Nat | Equal : expr Nat -> expr Nat -> expr Bool | Pair : forall {A B}, expr A -> expr B -> expr (Prod A B) | Fst : forall {A B}, expr (Prod A B) -> expr A | Snd : forall {A B}, expr (Prod A B) -> expr B | Const : forall A, tyeval A -> expr A | Ite : forall {A}, expr Bool -> expr A -> expr A -> expr A.
|
Inductive
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
expr
| |
store := string -> nat.
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
store
| |
eval {A} (s : store) (e : expr A) : tyeval A := match e with | Var n => s n | Plus e1 e2 => eval s e1 + eval s e2 | Equal e1 e2 => eval s e1 =? eval s e2 | Pair e1 e2 => (eval s e1, eval s e2) | Fst e => fst (eval s e) | Snd e => snd (eval s e) | Const _ c => c | Ite b e1 e2 => if eval s b then eval s e1 else eval s e2 end.
|
Fixpoint
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
eval
| |
simp_plus (e1 e2 : expr Nat) := match e1, e2 with | Const Nat n1, Const Nat n2 => Const Nat (n1 + n2) | _, Const Nat 0 => e1 | Const Nat 0, _ => e2 | _, _ => Plus e1 e2 end.
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
simp_plus
| |
lem_plus : forall s e1 e2, eval s (simp_plus e1 e2) = eval s e1 + eval s e2. Proof. time (depind e1; depelim e2; sauto). (* Undo. time (depind e1; depelim e2; sauto l: on). *) Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
lem_plus
| |
lem_plus' : forall s e1 e2, eval s (simp_plus e1 e2) = eval s e1 + eval s e2. Proof. Fail depind e1; sauto. time (depind e1; sauto dep: on). (* "dep: on" instructs "sauto" to use the "depelim" tactic for inversion. This may be slower and it will make your proof depend on axioms (equivalent to Uniqueness of Identity Proofs). *) Qed. Hint Rewrite lem_plus : simp_db.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
lem_plus'
| |
simp_equal (e1 e2 : expr Nat) := match e1, e2 with | Const Nat n1, Const Nat n2 => Const Bool (n1 =? n2) | _, _ => Equal e1 e2 end.
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
simp_equal
| |
lem_equal : forall s e1 e2, eval s (simp_equal e1 e2) = (eval s e1 =? eval s e2). Proof. Fail depind e1; sauto. time (depind e1; sauto dep: on). Undo. time (depind e1; depelim e2; sauto). Qed. Hint Rewrite lem_equal : simp_db.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
lem_equal
| |
unpair_type (T : type) := option (match T with Prod A B => expr A * expr B | _ => unit end).
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
unpair_type
| |
unpair {A B : type} (e : expr (Prod A B)) : option (expr A * expr B) := match e in expr T return unpair_type T with | Pair e1 e2 => Some (e1, e2) | _ => None end.
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
unpair
| |
simp_fst {A B : type} (e : expr (Prod A B)) : expr A := match unpair e with | Some (e1, e2) => e1 | None => Fst e end.
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
simp_fst
| |
lem_fst {A B} : forall s (e : expr (Prod A B)), eval s (simp_fst e) = fst (eval s e). Proof. depind e; sauto. Qed. Hint Rewrite @lem_fst : simp_db.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
lem_fst
| |
simp_snd {A B : type} (e : expr (Prod A B)) : expr B := match unpair e with | Some (e1, e2) => e2 | None => Snd e end.
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
simp_snd
| |
lem_snd {A B} : forall s (e : expr (Prod A B)), eval s (simp_snd e) = snd (eval s e). Proof. depind e; sauto. Qed. Hint Rewrite @lem_snd : simp_db.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
lem_snd
| |
simp_ite {A} (e : expr Bool) (e1 e2 : expr A) : expr A := match e with | Const Bool true => e1 | Const Bool false => e2 | _ => Ite e e1 e2 end.
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
simp_ite
| |
lem_ite {A} : forall s e (e1 e2 : expr A), eval s (simp_ite e e1 e2) = if eval s e then eval s e1 else eval s e2. Proof. depind e; sauto. Qed. Hint Rewrite @lem_ite : simp_db.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
lem_ite
| |
simp {A} (e : expr A) : expr A := match e with | Var n => Var n | Plus e1 e2 => simp_plus (simp e1) (simp e2) | Equal e1 e2 => simp_equal (simp e1) (simp e2) | Pair e1 e2 => Pair (simp e1) (simp e2) | Fst e => simp_fst (simp e) | Snd e => simp_snd (simp e) | Const t c => Const t c | Ite e e1 e2 => simp_ite (simp e) (simp e1) (simp e2) end.
|
Fixpoint
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
simp
| |
lem_simp {A} : forall s (e : expr A), eval s (simp e) = eval s e. Proof. time (depind e; sauto use: lem_plus, lem_equal, @lem_fst, @lem_snd, @lem_ite). Undo. time (depind e; sauto db: simp_db). Undo. time (depind e; simpl; autorewrite with simp_db; sauto). Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics.",
"Require Import Program.",
"Require Import Arith.",
"Require Import String."
] |
examples/tutorial/sauto/exp.v
|
lem_simp
| |
aexpr := | Aval : nat -> aexpr | Avar : string -> aexpr | Aplus : aexpr -> aexpr -> aexpr | Aminus : aexpr -> aexpr -> aexpr.
|
Inductive
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
aexpr
| |
Aval : nat >-> aexpr.
|
Coercion
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
Aval
| |
state := string -> nat.
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
state
| |
aval (s : state) (e : aexpr) := match e with | Aval n => n | Avar x => s x | Aplus x y => aval s x + aval s y | Aminus x y => aval s x - aval s y end.
|
Fixpoint
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
aval
| |
bexpr := | Bval : bool -> bexpr | Bnot : bexpr -> bexpr | Band : bexpr -> bexpr -> bexpr | Bless : aexpr -> aexpr -> bexpr.
|
Inductive
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
bexpr
| |
Bval : bool >-> bexpr.
|
Coercion
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
Bval
| |
bval (s : state) (e : bexpr) := match e with | Bval b => b | Bnot e1 => negb (bval s e1) | Band e1 e2 => bval s e1 && bval s e2 | Bless a1 a2 => aval s a1 <? aval s a2 end.
|
Fixpoint
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
bval
| |
cmd := | Nop : cmd | Assign : string -> aexpr -> cmd | Seq : cmd -> cmd -> cmd | If : bexpr -> cmd -> cmd -> cmd | While : bexpr -> cmd -> cmd.
|
Inductive
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
cmd
| |
update (s : state) x v y := if string_dec x y then v else s y.
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
update
| |
state_subst (s : state) (x : string) (a : aexpr) : state := (update s x (aval s a)).
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
state_subst
| |
BigStep : cmd -> state -> state -> Prop := | NopSem : forall s, BigStep Nop s s | AssignSem : forall s x a, BigStep (x <- a) s s[x := a] | SeqSem : forall c1 c2 s1 s2 s3, BigStep c1 s1 s2 -> BigStep c2 s2 s3 -> BigStep (c1 ;; c2) s1 s3 | IfTrue : forall b c1 c2 s s', bval s b -> BigStep c1 s s' -> BigStep (If b Then c1 Else c2) s s' | IfFalse : forall b c1 c2 s s', negb (bval s b) -> BigStep c2 s s' -> BigStep (If b Then c1 Else c2) s s' | WhileFalse : forall b c s, negb (bval s b) -> BigStep (While b Do c) s s | WhileTrue : forall b c s1 s2 s3, bval s1 b -> BigStep c s1 s2 -> BigStep (While b Do c) s2 s3 -> BigStep (While b Do c) s1 s3.
|
Inductive
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
BigStep
| |
lem_big_step_deterministic : forall c s s1, c >> s ==> s1 -> forall s2, c >> s ==> s2 -> s1 = s2. Proof. time (induction 1; sauto brefl: on). Undo. time (induction 1; sauto lazy: on brefl: on). Undo. time (induction 1; sauto lazy: on quick: on brefl: on). Qed. (* Program equivalence *)
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
lem_big_step_deterministic
| |
equiv_cmd (c1 c2 : cmd) := forall s s', c1 >> s ==> s' <-> c2 >> s ==> s'.
|
Definition
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
equiv_cmd
| |
lem_sim_refl : forall c, c ~~ c. Proof. sauto. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
lem_sim_refl
| |
lem_sim_sym : forall c c', c ~~ c' -> c' ~~ c. Proof. sauto unfold: equiv_cmd. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
lem_sim_sym
| |
lem_sim_trans : forall c1 c2 c3, c1 ~~ c2 -> c2 ~~ c3 -> c1 ~~ c3. Proof. sauto unfold: equiv_cmd. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
lem_sim_trans
| |
lem_seq_assoc : forall c1 c2 c3, c1;; (c2;; c3) ~~ (c1;; c2);; c3. Proof. time sauto unfold: equiv_cmd. Undo. time sauto lazy: on unfold: equiv_cmd. (* "lazy: on" turns off all eager heuristics *) (* This may sometimes speed up "sauto" noticeably, but sometimes it may prevent "sauto" from solving the goal. *) (* To increase the performance of "sauto" you may need to fiddle with various options. *) (* Things to try which commonly result in speed increase (if "sauto" can still solve the goal): - "lazy: on" ("l: on") - "quick: on" ("q: on") - a combination of various options which typically make "sauto" faster but weaker; this is more conservative than "qauto" which additionally severely decreases the proof cost limit - "lq: on" - an abbreviation for "l: on q: on" - "erew: off" - turn off eager rewriting - "rew: off" - turn off rewriting entirely - "ered: off" - turn off eager reduction with "simpl" - "red: off" - turn off reduction entirely - "ecases: off" - turn off eager case splitting - "cases: -" - turn off case splitting entirely - "einv: off sinv: off" - turn off eager inversion heuristics *) Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
lem_seq_assoc
| |
lem_triv_if : forall b c, If b Then c Else c ~~ c. Proof. unfold equiv_cmd. intros b c s s'. destruct (bval s b) eqn:?; sauto. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
lem_triv_if
| |
lem_commute_if : forall b1 b2 c1 c2 c3, If b1 Then (If b2 Then c1 Else c2) Else c3 ~~ If b2 Then (If b1 Then c1 Else c3) Else (If b1 Then c2 Else c3). Proof. unfold equiv_cmd. intros *. time (destruct (bval s b1) eqn:?; destruct (bval s b2) eqn:?; sauto). Undo. time (destruct (bval s b1) eqn:?; destruct (bval s b2) eqn:?; sauto inv: BigStep ctrs: BigStep). Undo. time (destruct (bval s b1) eqn:?; destruct (bval s b2) eqn:?; sauto quick: on inv: BigStep ctrs: BigStep). (* "quick: on" sets various options in a way which typically makes "sauto" weaker but faster. "quato" is "hauto" with "quick: on", a smaller cost limit and a different leaf solver. See https://github.com/lukaszcz/coqhammer#Sauto for details. *) Undo. time (destruct (bval s b1) eqn:?; destruct (bval s b2) eqn:?; sauto lazy: on inv: BigStep ctrs: BigStep). Undo. time (destruct (bval s b1) eqn:?; destruct (bval s b2) eqn:?; sauto lazy: on quick: on inv: BigStep ctrs: BigStep). Undo. time (destruct (bval s b1) eqn:?; destruct (bval s b2) eqn:?; sauto lq: on inv: BigStep ctrs: BigStep). (* "lq: on" is an abbreviation for "lazy: on quick: on" *) (* "lazy:" may be abbreviated to "l:" *) (* "quick:" may be abbreviated to "q:" *) Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
lem_commute_if
| |
lem_unfold_while : forall b c, While b Do c ~~ If b Then c;; While b Do c Else Nop. Proof. time sauto unfold: equiv_cmd. Undo. time sauto q: on unfold: equiv_cmd. (* "quick: on" does not result in significant speed increase this time *) Undo. time sauto l: on unfold: equiv_cmd. (* "lazy: on" does *) Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
lem_unfold_while
| |
lem_while_cong_aux : forall b c c' s s', While b Do c >> s ==> s' -> c ~~ c' -> While b Do c' >> s ==> s'. Proof. intros *. remember (While b Do c). induction 1; sauto lq: on unfold: equiv_cmd. Qed.
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
lem_while_cong_aux
| |
lem_while_cong : forall b c c', c ~~ c' -> While b Do c ~~ While b Do c'. Proof. hauto use: lem_while_cong_aux unfold: equiv_cmd. Qed. (* Small-step operational semantics *)
|
Lemma
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
lem_while_cong
| |
SmallStep : cmd * state -> cmd * state -> Prop := | AssignSemS : forall x a s, SmallStep (x <- a, s) (Nop, s[x := a]) | SeqSemS1 : forall c s, SmallStep (Nop ;; c, s) (c, s) | SeqSemS2 : forall c1 c2 s c1' s', SmallStep (c1, s) (c1', s') -> SmallStep (c1 ;; c2, s) (c1';; c2, s') | IfTrueS : forall b c1 c2 s, bval s b -> SmallStep (If b Then c1 Else c2, s) (c1, s) | IfFalseS : forall b c1 c2 s, negb (bval s b) -> SmallStep (If b Then c1 Else c2, s) (c2, s) | WhileS : forall b c s, SmallStep (While b Do c, s) (If b Then c;; While b Do c Else Nop, s).
|
Inductive
|
examples
|
[
"From Hammer Require Import Tactics Reflect.",
"Require Import String.",
"Require Import Arith.",
"Require Import Lia.",
"Require Import Relations."
] |
examples/tutorial/sauto/imp.v
|
SmallStep
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.