@@ -307,15 +307,14 @@ Section Wcbv.
307307 rewrite orb_true_r orb_true_l in H0. easy.
308308 Qed .
309309
310- Lemma closed_unfold_fix_cunfold_eq mfix idx :
310+ Lemma closed_fix_substl_subst_eq { mfix idx d} :
311311 closed (tFix mfix idx) ->
312- unfold_fix mfix idx = cunfold_fix mfix idx.
312+ nth_error mfix idx = Some d ->
313+ subst0 (fix_subst mfix) (dbody d) = substl (fix_subst mfix) (dbody d).
313314 Proof .
314- unfold unfold_fix, cunfold_fix.
315- destruct (nth_error mfix idx) eqn:Heq => //.
316315 move=> /= Hf; f_equal; f_equal.
317316 have clfix : All (closedn 0) (fix_subst mfix).
318- { clear Heq d idx.
317+ { clear idx.
319318 solve_all.
320319 unfold fix_subst.
321320 move: #|mfix| => n.
@@ -327,11 +326,22 @@ Section Wcbv.
327326 now rewrite subst_empty.
328327 move=> Ha; depelim Ha.
329328 simpl in *.
329+ intros hnth.
330330 rewrite -IHfix_subst => //.
331331 rewrite (subst_app_decomp [_]). simpl.
332332 f_equal. rewrite lift_closed // closed_subst //.
333333 Qed .
334334
335+ Lemma closed_unfold_fix_cunfold_eq mfix idx :
336+ closed (tFix mfix idx) ->
337+ unfold_fix mfix idx = cunfold_fix mfix idx.
338+ Proof .
339+ unfold unfold_fix, cunfold_fix.
340+ destruct (nth_error mfix idx) eqn:Heq => //.
341+ intros cl; f_equal; f_equal.
342+ now rewrite (closed_fix_substl_subst_eq cl).
343+ Qed .
344+
335345 Lemma closed_unfold_cofix_cunfold_eq mfix idx :
336346 closed (tCoFix mfix idx) ->
337347 unfold_cofix mfix idx = cunfold_cofix mfix idx.
@@ -377,6 +387,106 @@ Qed.
377387
378388Derive NoConfusionHom for EAst.global_decl.
379389
390+
391+ Lemma Forall_Forall2_refl :
392+ forall (A : Type) (R : A -> A -> Prop) (l : list A),
393+ Forall (fun x : A => R x x) l -> Forall2 R l l.
394+ Proof .
395+ induction 1; constructor; auto.
396+ Qed .
397+
398+ Lemma value_head_spec_impl t :
399+ implb (value_head t) (~~ (isLambda t || isFixApp t || isBox t)).
400+ Proof .
401+ destruct t; simpl; intuition auto; eapply implybT.
402+ Qed .
403+
404+ Derive Signature for Forall.
405+
406+ Lemma eval_stuck_fix args argsv mfix idx :
407+ Forall2 eval args argsv ->
408+ isStuckFix (tFix mfix idx) argsv ->
409+ eval (mkApps (tFix mfix idx) args) (mkApps (tFix mfix idx) argsv).
410+ Proof .
411+ revert argsv.
412+ induction args as [|a args IH] using MCList.rev_ind;
413+ intros argsv all stuck.
414+ - apply Forall2_length in all.
415+ destruct argsv; [|easy].
416+ now apply eval_atom.
417+ - destruct argsv as [|? ? _] using MCList.rev_ind;
418+ [apply Forall2_length in all; rewrite app_length in all; now cbn in *|].
419+ apply Forall2_app_r in all as (all & ev_a).
420+ rewrite <- !mkApps_nested.
421+ cbn in *.
422+ destruct (cunfold_fix mfix idx) as [(? & ?)|] eqn:cuf; [|easy].
423+ eapply eval_fix_value.
424+ + apply IH; [easy|].
425+ destruct (cunfold_fix mfix idx) as [(? & ?)|]; [|easy].
426+ rewrite app_length /= in stuck.
427+ eapply Nat.leb_le in stuck. eapply Nat.leb_le. lia.
428+ + easy.
429+ + easy.
430+ + rewrite app_length /= in stuck.
431+ eapply Nat.leb_le in stuck; lia.
432+ Qed .
433+
434+ Lemma stuck_fix_value_inv argsv mfix idx narg fn :
435+ value (mkApps (tFix mfix idx) argsv) ->
436+ cunfold_fix mfix idx = Some (narg, fn) ->
437+ (Forall value argsv /\ isStuckFix (tFix mfix idx) argsv).
438+ Proof .
439+ remember (mkApps (tFix mfix idx) argsv) as tfix.
440+ intros hv; revert Heqtfix.
441+ induction hv using value_values_ind; intros eq; subst.
442+ unfold atom in H. destruct argsv using rev_case => //.
443+ split; auto. simpl. simpl in H. rewrite H0 //.
444+ rewrite -mkApps_nested /= in H. depelim H.
445+ solve_discr => //.
446+ solve_discr.
447+ Qed .
448+
449+ Lemma stuck_fix_value_args argsv mfix idx narg fn :
450+ value (mkApps (tFix mfix idx) argsv) ->
451+ cunfold_fix mfix idx = Some (narg, fn) ->
452+ #|argsv| <= narg.
453+ Proof .
454+ intros val unf.
455+ eapply stuck_fix_value_inv in val; eauto.
456+ destruct val.
457+ simpl in H0. rewrite unf in H0.
458+ now eapply Nat.leb_le in H0.
459+ Qed .
460+
461+ Lemma value_final e : value e -> eval e e.
462+ Proof .
463+ induction 1 using value_values_ind; simpl; auto using value.
464+ - apply Forall_Forall2_refl in H1 as H2.
465+ move/implyP: (value_head_spec_impl t).
466+ move/(_ H) => Ht.
467+ induction l using rev_ind. simpl.
468+ destruct t; try discriminate.
469+ * repeat constructor.
470+ * repeat constructor.
471+ * rewrite -mkApps_nested.
472+ eapply Forall_app in H0 as [Hl Hx]. depelim Hx.
473+ eapply Forall_app in H1 as [Hl' Hx']. depelim Hx'.
474+ eapply Forall2_app_inv_r in H2 as [Hl'' [Hx'' [? [? ?]]]].
475+ depelim H3. depelim H4.
476+ eapply eval_app_cong; auto.
477+ eapply IHl; auto.
478+ now eapply Forall_Forall2.
479+ destruct l using rev_ind; auto.
480+ eapply value_head_nApp in H.
481+ rewrite isFixApp_mkApps => //.
482+ rewrite -mkApps_nested; simpl.
483+ rewrite orb_false_r.
484+ destruct t; auto.
485+ - destruct f; try discriminate.
486+ apply Forall_Forall2_refl in H0.
487+ now apply eval_stuck_fix.
488+ Qed .
489+
380490Unset SsrRewrite.
381491Lemma eval_deterministic {t v v'} :
382492 eval t v ->
0 commit comments