Built with
Alectryon , running Coq+SerAPI v8.13.0+0.13.0. Bubbles (
) indicate interactive fragments: hover for details, tap to reveal contents. Use
Ctrl+↑ Ctrl+↓ to navigate,
Ctrl+🖱️ to focus. On Mac, use
⌘ instead of
Ctrl .
Load semantics2.
Lemma terminalTerminated :
forall (σ :State),
terminal (Terminated σ).
Proof .
intros .
intros [c' H].σ : State c' : Conf H : « σ » ~> c'
False
inversion H.
Qed .
Lemma terminalAbortion :
terminal ↯.
Proof .
intros .
intros [c' H].
inversion H.
Qed .
Section Exercise6_9 .
Definition W :=
While (Binary Ge (LVal (Var "a" )) (LVal(Var "b" )))
(* extra Block in Exercise *)
(Assign (Var "a" ) (Binary Sub (LVal (Var "a" )) (LVal (Var "b" ))))
.
Definition S :=
If (Binary Eq (LVal (Var "a" )) (Const (IntVal 8 )))
Abort
(Assign (Var "b" ) (Const (IntVal 0 ))).
Definition wp :=
[
W;
S
].
Definition ρ1 : VarEnv :=
(fun _ => None) [ "a" ↦ (Some △)] [ "b" ↦ (Some ○)].
Definition μ1 : MemEnv :=
(fun _ => None) [ △ ↦ (Some (Defined 42 ))] [ ○ ↦ (Some (Defined 17 ))].
Definition σ := ([ρ1],μ1).
Goal abortion wp σ.
Proof .
unfold abortion, wp, W.⟨ [While (Binary Ge (LVal (Var "a" )) (LVal (Var "b" )))
(Assign (Var "a" )
(Binary Sub (LVal (Var "a" )) (LVal (Var "b" ))));
S] | σ ⟩ ⇓ ↯
do 7 try eapply BigStepTrans.⟨ [While (Binary Ge (LVal (Var "a" )) (LVal (Var "b" )))
(Assign (Var "a" )
(Binary Sub (LVal (Var "a" )) (LVal (Var "b" ))));
S] | σ ⟩ ~> ?c2
- ⟨ [While (Binary Ge (LVal (Var "a" )) (LVal (Var "b" )))
(Assign (Var "a" )
(Binary Sub (LVal (Var "a" )) (LVal (Var "b" ))));
S] | σ ⟩ ~> ?c2
apply WhileTrueStep with (n:=1 ).R⟦ Binary Ge (LVal (Var "a" )) (LVal (Var "b" )) ⟧ σ =
Some 1
2 : easy .R⟦ Binary Ge (LVal (Var "a" )) (LVal (Var "b" )) ⟧ σ =
Some 1
now vm_compute .
- ⟨ [Assign (Var "a" )
(Binary Sub (LVal (Var "a" )) (LVal (Var "b" )));
While (Binary Ge (LVal (Var "a" )) (LVal (Var "b" )))
(Assign (Var "a" )
(Binary Sub (LVal (Var "a" )) (LVal (Var "b" ))));
S] | σ ⟩ ~> ?c2
apply AssignStep.R⟦ Binary Sub (LVal (Var "a" )) (LVal (Var "b" ))
⟧ ([ρ1], μ1) = Some ?v
+ R⟦ Binary Sub (LVal (Var "a" )) (LVal (Var "b" ))
⟧ ([ρ1], μ1) = Some ?v
now vm_compute .
+ L⟦ Var "a" ⟧ ([ρ1], μ1) = Some ?a
now vm_compute .
- ⟨ [While (Binary Ge (LVal (Var "a" )) (LVal (Var "b" )))
(Assign (Var "a" )
(Binary Sub (LVal (Var "a" )) (LVal (Var "b" ))));
S] | ([ρ1], μ1 [△ ↦ Some 25 ]) ⟩ ~> ?c2
apply WhileTrueStep with (n:=1 ).R⟦ Binary Ge (LVal (Var "a" )) (LVal (Var "b" ))
⟧ ([ρ1], μ1 [△ ↦ Some 25 ]) = Some 1
2 : easy .R⟦ Binary Ge (LVal (Var "a" )) (LVal (Var "b" ))
⟧ ([ρ1], μ1 [△ ↦ Some 25 ]) = Some 1
now vm_compute .
- ⟨ [Assign (Var "a" )
(Binary Sub (LVal (Var "a" )) (LVal (Var "b" )));
While (Binary Ge (LVal (Var "a" )) (LVal (Var "b" )))
(Assign (Var "a" )
(Binary Sub (LVal (Var "a" )) (LVal (Var "b" ))));
S] | ([ρ1], μ1 [△ ↦ Some 25 ]) ⟩ ~> ?c2
apply AssignStep.R⟦ Binary Sub (LVal (Var "a" )) (LVal (Var "b" ))
⟧ ([ρ1], μ1 [△ ↦ Some 25 ]) = Some ?v
+ R⟦ Binary Sub (LVal (Var "a" )) (LVal (Var "b" ))
⟧ ([ρ1], μ1 [△ ↦ Some 25 ]) = Some ?v
now vm_compute .
+ L⟦ Var "a" ⟧ ([ρ1], μ1 [△ ↦ Some 25 ]) = Some ?a
now vm_compute .
- ⟨ [While (Binary Ge (LVal (Var "a" )) (LVal (Var "b" )))
(Assign (Var "a" )
(Binary Sub (LVal (Var "a" )) (LVal (Var "b" ))));
S] | ([ρ1], (μ1 [△ ↦ Some 25 ]) [△ ↦ Some 8 ]) ⟩ ~>
?c2
apply WhileFalseStep.R⟦ Binary Ge (LVal (Var "a" )) (LVal (Var "b" ))
⟧ ([ρ1], (μ1 [△ ↦ Some 25 ]) [△ ↦ Some 8 ]) = Some 0
now vm_compute .
- ⟨ [S] | ([ρ1], (μ1 [△ ↦ Some 25 ]) [△ ↦ Some 8 ]) ⟩ ~>
?c2
unfold S.⟨ [If (Binary Eq (LVal (Var "a" )) (Const 8 )) Abort
(Assign (Var "b" ) (Const 0 ))]
| ([ρ1], (μ1 [△ ↦ Some 25 ]) [△ ↦ Some 8 ]) ⟩ ~> ?c2
apply IfTrueStep with (n:=1 ).R⟦ Binary Eq (LVal (Var "a" )) (Const 8 )
⟧ ([ρ1], (μ1 [△ ↦ Some 25 ]) [△ ↦ Some 8 ]) = Some 1
+ R⟦ Binary Eq (LVal (Var "a" )) (Const 8 )
⟧ ([ρ1], (μ1 [△ ↦ Some 25 ]) [△ ↦ Some 8 ]) = Some 1
now vm_compute .
+ now vm_compute .
- ⟨ [Abort ] | ([ρ1], (μ1 [△ ↦ Some 25 ]) [△ ↦ Some 8 ]) ⟩ ~>
?c2
apply AbortStep.
- apply BigStepEnd.
apply terminalAbortion.
Qed .
End Exercise6_9 .