Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Restart and ltac:(...) #63

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Tutorial_Equations_basics.v
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,11 @@ Global Transparent f4.
Goal f4 3 = 4.
Proof.
(* [f4] can now be unfolded *)
unfold f4. Restart.
unfold f4.
Abort.

Goal f4 3 = 4.
Proof.
(* Yet, it still cannot be simplify by [cbn] *)
Fail progress cbn.
(* [Arguments] enables to recover simplification *)
Expand Down Expand Up @@ -418,6 +422,7 @@ Proof.
- apply H.
Abort.

(* Doing induction naively to reproduce a pattern can get you stuck *)
Definition half_mod2 (n : nat) : n = half n + half n + mod2 n.
Proof.
induction n; try reflexivity.
Expand All @@ -427,7 +432,11 @@ Proof.
rewrite PeanoNat.Nat.add_succ_r. cbn.
f_equal. f_equal.
(* We then get stuck as we have the wrong hypotheses *)
Restart.
Abort.

(* Wheras funelim does it automatically for you *)
Definition half_mod2 (n : nat) : n = half n + half n + mod2 n.
Proof.
funelim (half n); try reflexivity.
autorewrite with half mod2.
rewrite PeanoNat.Nat.add_succ_r. cbn.
Expand Down
20 changes: 14 additions & 6 deletions src/Tutorial_Equations_wf.v
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,10 @@ Definition ack1 {n} : ack 1 n = 2 + n.
Proof.
(* If we apply [ack_elim], we get unwarranted cases *)
apply ack_elim; intros.
Restart.
(* So we reproduce the pattern with induction *)
Abort.

(* So we reproduce the pattern with induction *)
Definition ack1 {n} : ack 1 n = 2 + n.
induction n; simp ack.
- reflexivity.
- rewrite IHn. reflexivity.
Expand Down Expand Up @@ -496,23 +498,29 @@ Context (h : exists m : nat, f m = true).
Consequently, to prove [Acc n] when [n < m], we want to reason by induction
on [k := m - n]. To do so, we add [n = S m] to the relation.

This gives us the following relation and proof of our intuition:
This gives us the following relation and proof of our intuition.
Note that understanding the proofs doe not matter for this tutorial.
*)

Definition R n m := (forall k, k <= m -> f k = false) /\ n = S m.

Lemma wf_R_m_le m (h : f m = true) : forall n, m <= n -> Acc R n.
Proof.
intros n H. constructor. intros ? [h' ?].
specialize (h' m ltac:(auto)).
specialize (h' m H).
congruence.
Qed.


Lemma wf_R_lt_m m (h : f m = true) : forall n, n < m -> Acc R n.
Proof.
intros n H. assert (Acc R m) by (eapply wf_R_m_le; eauto).
rewrite <- (Nat.sub_add n m ltac:(lia)) in *.
intros n H.
(* Prove Acc m *)
assert (Acc R m) as Hm_acc by (eapply wf_R_m_le; eauto).
(* Set up induction on k := m - n *)
rewrite <- (Nat.sub_add n m) in * by lia.
set (k := m - n) in *; clearbody k. clear h H.
(* Proof *)
induction k.
- easy.
- apply IHk. constructor. intros ? [? ->]. assumption.
Expand Down
Loading