mirror of
https://github.com/achlipala/frap.git
synced 2024-11-10 00:07:51 +00:00
Avoid a notation conflict
This commit is contained in:
parent
a583e1d0d4
commit
4889f08ac4
1 changed files with 13 additions and 13 deletions
|
@ -37,13 +37,13 @@ Infix "*" := Times : arith_scope.
|
||||||
Delimit Scope arith_scope with arith.
|
Delimit Scope arith_scope with arith.
|
||||||
Notation "x <- e" := (Assign x e%arith) (at level 75).
|
Notation "x <- e" := (Assign x e%arith) (at level 75).
|
||||||
Infix ";;" := Sequence (at level 76). (* This one changed slightly, to avoid parsing clashes. *)
|
Infix ";;" := Sequence (at level 76). (* This one changed slightly, to avoid parsing clashes. *)
|
||||||
Notation "'when' e 'do' then_ 'else' else_ 'done'" := (If e%arith then_ else_) (at level 75, e at level 0).
|
Notation "'when' e 'loop' then_ 'else' else_ 'done'" := (If e%arith then_ else_) (at level 75, e at level 0).
|
||||||
Notation "'while' e 'do' body 'done'" := (While e%arith body) (at level 75).
|
Notation "'while' e 'loop' body 'done'" := (While e%arith body) (at level 75).
|
||||||
|
|
||||||
(* Here's an adaptation of our factorial example from Chapter 3. *)
|
(* Here's an adaptation of our factorial example from Chapter 3. *)
|
||||||
Example factorial :=
|
Example factorial :=
|
||||||
"output" <- 1;;
|
"output" <- 1;;
|
||||||
while "input" do
|
while "input" loop
|
||||||
"output" <- "output" * "input";;
|
"output" <- "output" * "input";;
|
||||||
"input" <- "input" - 1
|
"input" <- "input" - 1
|
||||||
done.
|
done.
|
||||||
|
@ -159,7 +159,7 @@ Fixpoint fact (n : nat) : nat :=
|
||||||
end.
|
end.
|
||||||
|
|
||||||
Example factorial_loop :=
|
Example factorial_loop :=
|
||||||
while "input" do
|
while "input" loop
|
||||||
"output" <- "output" * "input";;
|
"output" <- "output" * "input";;
|
||||||
"input" <- "input" - 1
|
"input" <- "input" - 1
|
||||||
done.
|
done.
|
||||||
|
@ -518,13 +518,13 @@ Inductive isEven : nat -> Prop :=
|
||||||
| EvenSS : forall n, isEven n -> isEven (S (S n)).
|
| EvenSS : forall n, isEven n -> isEven (S (S n)).
|
||||||
|
|
||||||
Definition my_loop :=
|
Definition my_loop :=
|
||||||
while "n" do
|
while "n" loop
|
||||||
"a" <- "a" + "n";;
|
"a" <- "a" + "n";;
|
||||||
"n" <- "n" - 2
|
"n" <- "n" - 2
|
||||||
done.
|
done.
|
||||||
|
|
||||||
Definition all_programs := {
|
Definition all_programs := {
|
||||||
(while "n" do
|
(while "n" loop
|
||||||
"a" <- "a" + "n";;
|
"a" <- "a" + "n";;
|
||||||
"n" <- "n" - 2
|
"n" <- "n" - 2
|
||||||
done),
|
done),
|
||||||
|
@ -535,23 +535,23 @@ Definition all_programs := {
|
||||||
("n" <- "n" - 2),
|
("n" <- "n" - 2),
|
||||||
(("a" <- "a" + "n";;
|
(("a" <- "a" + "n";;
|
||||||
"n" <- "n" - 2);;
|
"n" <- "n" - 2);;
|
||||||
while "n" do
|
while "n" loop
|
||||||
"a" <- "a" + "n";;
|
"a" <- "a" + "n";;
|
||||||
"n" <- "n" - 2
|
"n" <- "n" - 2
|
||||||
done),
|
done),
|
||||||
((Skip;;
|
((Skip;;
|
||||||
"n" <- "n" - 2);;
|
"n" <- "n" - 2);;
|
||||||
while "n" do
|
while "n" loop
|
||||||
"a" <- "a" + "n";;
|
"a" <- "a" + "n";;
|
||||||
"n" <- "n" - 2
|
"n" <- "n" - 2
|
||||||
done),
|
done),
|
||||||
("n" <- "n" - 2;;
|
("n" <- "n" - 2;;
|
||||||
while "n" do
|
while "n" loop
|
||||||
"a" <- "a" + "n";;
|
"a" <- "a" + "n";;
|
||||||
"n" <- "n" - 2
|
"n" <- "n" - 2
|
||||||
done),
|
done),
|
||||||
(Skip;;
|
(Skip;;
|
||||||
while "n" do
|
while "n" loop
|
||||||
"a" <- "a" + "n";;
|
"a" <- "a" + "n";;
|
||||||
"n" <- "n" - 2
|
"n" <- "n" - 2
|
||||||
done),
|
done),
|
||||||
|
@ -583,7 +583,7 @@ Proof.
|
||||||
Qed.
|
Qed.
|
||||||
|
|
||||||
Lemma manually_proved_invariant' :
|
Lemma manually_proved_invariant' :
|
||||||
invariantFor (trsys_of ($0 $+ ("n", 0) $+ ("a", 0)) (while "n" do "a" <- "a" + "n";; "n" <- "n" - 2 done))
|
invariantFor (trsys_of ($0 $+ ("n", 0) $+ ("a", 0)) (while "n" loop "a" <- "a" + "n";; "n" <- "n" - 2 done))
|
||||||
(fun s => all_programs (snd s)
|
(fun s => all_programs (snd s)
|
||||||
/\ exists n a, fst s $? "n" = Some n
|
/\ exists n a, fst s $? "n" = Some n
|
||||||
/\ fst s $? "a" = Some a
|
/\ fst s $? "a" = Some a
|
||||||
|
@ -680,7 +680,7 @@ Hint Constructors isEven.
|
||||||
Hint Resolve isEven_minus2 isEven_plus.
|
Hint Resolve isEven_minus2 isEven_plus.
|
||||||
|
|
||||||
Lemma manually_proved_invariant'_snazzy :
|
Lemma manually_proved_invariant'_snazzy :
|
||||||
invariantFor (trsys_of ($0 $+ ("n", 0) $+ ("a", 0)) (while "n" do "a" <- "a" + "n";; "n" <- "n" - 2 done))
|
invariantFor (trsys_of ($0 $+ ("n", 0) $+ ("a", 0)) (while "n" loop "a" <- "a" + "n";; "n" <- "n" - 2 done))
|
||||||
(fun s => all_programs (snd s)
|
(fun s => all_programs (snd s)
|
||||||
/\ exists n a, fst s $? "n" = Some n
|
/\ exists n a, fst s $? "n" = Some n
|
||||||
/\ fst s $? "a" = Some a
|
/\ fst s $? "a" = Some a
|
||||||
|
@ -700,7 +700,7 @@ Proof.
|
||||||
Qed.
|
Qed.
|
||||||
|
|
||||||
Theorem manually_proved_invariant :
|
Theorem manually_proved_invariant :
|
||||||
invariantFor (trsys_of ($0 $+ ("n", 0) $+ ("a", 0)) (while "n" do "a" <- "a" + "n";; "n" <- "n" - 2 done))
|
invariantFor (trsys_of ($0 $+ ("n", 0) $+ ("a", 0)) (while "n" loop "a" <- "a" + "n";; "n" <- "n" - 2 done))
|
||||||
(fun s => exists a, fst s $? "a" = Some a /\ isEven a).
|
(fun s => exists a, fst s $? "a" = Some a /\ isEven a).
|
||||||
Proof.
|
Proof.
|
||||||
eapply invariant_weaken.
|
eapply invariant_weaken.
|
||||||
|
|
Loading…
Reference in a new issue