@@ -71,6 +71,14 @@ Proof.
7171 intros. subst. reflexivity.
7272Qed .
7373
74+ Lemma bool_depelim_false :
75+ ∀ (X : Type ) (b : bool) (htrue : b = true → X) (hfalse : b = false → X)
76+ (e : b = false),
77+ bool_depelim X b htrue hfalse = hfalse e.
78+ Proof .
79+ intros. subst. reflexivity.
80+ Qed .
81+
7482(* helper lemma for multiplication of reals *)
7583Lemma R_no0div : ∀ (u v : R), (u * v ≠ 0 → u ≠ 0 ∧ v ≠ 0)%R.
7684Proof .
@@ -223,21 +231,23 @@ Arguments bind [_ _ _] _ _.
223231
224232End Def.
225233
234+ Class EvalOp :=
235+ eval_interface_operations : forall o, src o -> Def.stsubdistr heap_choiceType (tgt o).
226236
227237(** Semantic evaluation of code and commands *)
228238Section Evaluation.
229239 #[local]
230240 Notation M := (Def.stsubdistr heap_choiceType).
231241
232242 (** Assume an interpretation of operations *)
233- Context (eval_op : ∀ o, src o → M (tgt o)) .
243+ Context `{EvalOp} .
234244
235245 Definition eval [A : choiceType] : raw_code A → M A.
236246 Proof .
237247 elim.
238248 - apply: Def.ret.
239249 - intros o x k ih.
240- exact (Def.bind (eval_op o x) ih).
250+ exact (Def.bind (eval_interface_operations o x) ih).
241251 - intros l k ih.
242252 exact (λ map, let v := get_heap map l in ih v map).
243253 - intros l v k ih.
@@ -252,8 +262,10 @@ Section Evaluation.
252262 Definition precondition := pred heap.
253263 Definition postcondition A := pred (A * heap).
254264
255- Definition unary_judgement [A : choiceType] (pre : precondition) (c : raw_code A) (post : postcondition A) : Prop :=
256- forall map, pre map -> forall p, (eval c map p <> 0)%R -> post p.
265+ Definition spec_valid [A : choiceType] (pre : precondition) (m : M A) (post : postcondition A) : Prop :=
266+ forall map, pre map -> forall p, (m map p <> 0)%R -> post p.
267+
268+ Definition unary_judgement [A : choiceType] (pre : precondition) (c : raw_code A) (post : postcondition A) : Prop := spec_valid pre (eval c) post.
257269
258270 Declare Scope Rules_scope.
259271
@@ -336,6 +348,18 @@ Section Evaluation.
336348
337349End Evaluation.
338350
351+ Module UnaryNotations.
352+ Notation "⊨ ⦃ pre ⦄ c ⦃ p , post ⦄" :=
353+ (unary_judgement pre c (fun p => post))
354+ (p pattern ) : Rules_scope.
355+ Open Scope Rules_scope.
356+ End UnaryNotations.
357+
358+
359+ (** Default interpretation for operations *)
360+ Definition eval_op_null : EvalOp :=
361+ fun o _ => Def.stsubnull _ _.
362+
339363
340364Section ScopedImportEval.
341365 #[local] Open Scope fset.
@@ -349,15 +373,43 @@ Section ScopedImportEval.
349373 (** Taking an interpretation of the imported operation as assumption *)
350374 Context (import_eval : ∀ o, o \in import → src o → M (tgt o)).
351375
352- Definition eval_op : forall o, src o -> M (tgt o) :=
353- fun o => bool_depelim _ (o \in import) (fun oval => import_eval o oval) (fun _ _ => Def.stsubnull _ _).
354-
355- Let eval := (eval eval_op).
356-
357- (* Problem: the notation for the judgement is parametrized by eval, how can I
358- have access to this notation instantiated with eval without redefining it ?
359- Use a functor ? *)
360-
361- (* TODO: Add spec and Rule for imported operations *)
376+ #[local]
377+ Instance eval_op : EvalOp :=
378+ fun o => bool_depelim _ (o \in import)
379+ (fun oval => import_eval o oval)
380+ (fun _ _ => Def.stsubnull _ _).
381+
382+ Import UnaryNotations.
383+
384+ Context (op_precondition : forall o, o \in import -> src o -> precondition)
385+ (op_postcondition : forall o, o \in import -> src o -> postcondition (tgt o))
386+ (import_eval_valid : forall o (oval : o \in import) (s : src o),
387+ spec_valid (op_precondition o oval s)
388+ (import_eval o oval s)
389+ (op_postcondition o oval s)).
390+
391+ Definition op_pre : forall o, src o -> precondition :=
392+ fun o s => bool_depelim _ (o \in import)
393+ (fun oval => op_precondition o oval s)
394+ (fun _ => pred0).
395+
396+ Definition op_post : forall o, src o -> postcondition (tgt o) :=
397+ fun o s => bool_depelim _ (o \in import)
398+ (fun oval => op_postcondition o oval s)
399+ (fun _ => predT).
400+
401+ Lemma opr_rule [A : choiceType] (post : postcondition A) :
402+ forall o (s : src o) (k : tgt o -> raw_code A)
403+ (spec_k : forall r, ⊨ ⦃ [pred map | op_post o s (r, map)] ⦄ k r ⦃ p , post p ⦄),
404+ ⊨ ⦃ op_pre o s ⦄ opr o s k ⦃ p , post p ⦄.
405+ Proof .
406+ move=> o s k; case oval: (o \in import); rewrite /op_pre /op_post.
407+ 2: move=> _; by rewrite bool_depelim_false.
408+ rewrite !bool_depelim_true // => spec_k map hpre p /=.
409+ move=> /Def.bind_not_null [[r map0] []].
410+ rewrite /eval_interface_operations/eval_op bool_depelim_true=> ??.
411+ apply: (spec_k r map0)=> //=.
412+ apply: import_eval_valid; first apply: hpre; move => //.
413+ Qed .
362414
363415End ScopedImportEval.
0 commit comments