Skip to content

Commit 7046d0d

Browse files
committed
Show that inhabitants of product types evaluate to functions through the erasure pipeline
1 parent 64db6e3 commit 7046d0d

File tree

1 file changed

+130
-2
lines changed

1 file changed

+130
-2
lines changed

erasure-plugin/theories/ErasureCorrectness.v

+130-2
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ Section ErasureFunction.
837837

838838
Lemma pcuic_function_value (wfl := default_wcbv_flags)
839839
{guard_impl : abstract_guard_impl}
840-
(cf:=config.extraction_checker_flags) (Σ:global_env_ext) f na A B
840+
(cf:=config.extraction_checker_flags) {Σ : global_env_ext} {f na A B}
841841
(wfΣ : wf_ext Σ) (axfree : axiom_free Σ) (wf : Σ ;;; [] |- f : PCUICAst.tProd na A B) : { v & PCUICWcbvEval.eval Σ f v }.
842842
Proof.
843843
eapply (PCUICNormalization.wcbv_normalization wfΣ axfree wf). Unshelve.
@@ -856,7 +856,7 @@ Section ErasureFunction.
856856
Proof.
857857
intros axfree nise.
858858
destruct pr as [[]]. destruct wf.
859-
epose proof (pcuic_function_value Σ f na A B w.1 axfree X) as [v hv].
859+
epose proof (pcuic_function_value w.1 axfree X) as [v hv].
860860
eapply erase_function; tea. now sq.
861861
Qed.
862862

@@ -1444,6 +1444,21 @@ Proof.
14441444
tc.
14451445
Qed.
14461446

1447+
1448+
Lemma expand_lets_function (wfl := default_wcbv_flags)
1449+
{guard_impl : abstract_guard_impl}
1450+
(cf:=config.extraction_checker_flags) (Σ:global_env_ext_map) K f na A B
1451+
(wf : ∥ Σ ;;; [] |- f : PCUICAst.tProd na A B ∥) pr :
1452+
let (Σ', f') := transform (pcuic_expand_lets_transform K) (Σ, f) pr in
1453+
∥ Σ' ;;; [] |- f' : PCUICExpandLets.trans (PCUICAst.tProd na A B) ∥.
1454+
Proof.
1455+
unfold transform, pcuic_expand_lets_transform. cbn.
1456+
destruct pr as [[[]] ?].
1457+
sq.
1458+
eapply PCUICExpandLetsCorrectness.pcuic_expand_lets in wf; eauto.
1459+
now eapply PCUICExpandLetsCorrectness.trans_wf.
1460+
Qed.
1461+
14471462
Lemma transform_lambda_box_firstorder (Σer : EEnvMap.GlobalContextMap.t) p pre :
14481463
firstorder_evalue Σer p ->
14491464
(transform verified_lambdabox_pipeline (Σer, p) pre).2 = (compile_evalue_box (ERemoveParams.strip Σer p) []).
@@ -1810,6 +1825,119 @@ Section PCUICErase.
18101825
now eapply (PCUICExpandLetsCorrectness.expand_lets_sound (cf := extraction_checker_flags)) in Hsort.
18111826
Qed.
18121827

1828+
#[local] Existing Instance PCUICSN.extraction_normalizing.
1829+
1830+
(* Beware, this internally uses preservation of observations and determinism of evaluation
1831+
from the canonical evaluation of [f] in the source to the evaluation in the target.
1832+
*)
1833+
Lemma transform_erasure_pipeline_function
1834+
(wfl := default_wcbv_flags)
1835+
{guard_impl : abstract_guard_impl}
1836+
(cf:=config.extraction_checker_flags) (Σ:global_env_ext_map)
1837+
{f v' na A B}
1838+
(wf : ∥ Σ ;;; [] |- f : PCUICAst.tProd na A B ∥) pr :
1839+
axiom_free Σ ->
1840+
∥ nisErasable Σ [] f ∥ ->
1841+
let tr := transform verified_erasure_pipeline (Σ, f) pr in
1842+
eval (wfl := extraction_wcbv_flags) tr.1 tr.2 v' -> isFunction v' = true.
1843+
Proof.
1844+
intros axfree nise.
1845+
unfold verified_erasure_pipeline.
1846+
rewrite -!transform_compose_assoc.
1847+
pose proof (expand_lets_function Σ (fun p : global_env_ext_map =>
1848+
(wf_ext p -> PCUICSN.NormalizationIn p) /\
1849+
(wf_ext p -> PCUICWeakeningEnvSN.normalizationInAdjustUniversesIn p)) f na A B wf pr).
1850+
destruct_compose. intros pre.
1851+
set (trexp := transform (pcuic_expand_lets_transform _) _ _) in *.
1852+
eapply (PCUICExpandLetsCorrectness.trans_axiom_free Σ) in axfree.
1853+
have nise' : ∥ nisErasable trexp.1 [] trexp.2 ∥.
1854+
destruct pr as [[[]] ?], nise. sq; now eapply nisErasable_lets.
1855+
change (trans_global_env _) with (global_env_ext_map_global_env_ext trexp.1).1 in axfree.
1856+
clearbody trexp. clear nise pr wf Σ f. destruct trexp as [Σ f].
1857+
pose proof pre as pre'; destruct pre' as [[[wf _]] _].
1858+
pose proof (map_squash (pcuic_function_value wf axfree) H) as [[v ev]].
1859+
epose proof (Transform.preservation erase_transform).
1860+
specialize (H0 _ v pre (sq ev)).
1861+
revert H0.
1862+
destruct_compose. intros pre' htr.
1863+
destruct htr as [v'' [ev' _]].
1864+
epose proof (erase_function_to_function _ f v'' _ _ _ H pre axfree nise').
1865+
set (tre := transform erase_transform _ _) in *. clearbody tre.
1866+
cbn -[transform obseq].
1867+
intros ev2. red in ev'. destruct ev'.
1868+
epose proof (Transform.preservation verified_lambdabox_pipeline).
1869+
destruct tre as [Σ' f'].
1870+
specialize (H2 _ v'' pre' (sq H1)) as [finalv [[evfinal] obseq]].
1871+
pose proof (eval_deterministic evfinal ev2). subst v'.
1872+
have prev : Transform.pre verified_lambdabox_pipeline (Σ', v'').
1873+
{ clear -wfl pre' H1. cbn in H1.
1874+
destruct pre' as [[] []]. split; split => //=.
1875+
eapply Prelim.Ee.eval_wellformed; eauto.
1876+
eapply EEtaExpandedFix.isEtaExp_expanded.
1877+
eapply (@EEtaExpandedFix.eval_etaexp wfl); eauto.
1878+
now eapply EEtaExpandedFix.expanded_global_env_isEtaExp_env.
1879+
now eapply EEtaExpandedFix.expanded_isEtaExp. }
1880+
specialize (H0 H1).
1881+
eapply (obseq_lambdabox (Σ', f') (Σ', v'')) in obseq.
1882+
epose proof (ETransformPresAppLam.transform_lam _ _ _ (t := lambdabox_pres_app) (Σ', v'') prev H0).
1883+
rewrite -obseq. exact H2. cbn. red; tauto.
1884+
Qed.
1885+
1886+
(* This version provides the evaluation proof. *)
1887+
Lemma transform_erasure_pipeline_function'
1888+
(wfl := default_wcbv_flags)
1889+
{guard_impl : abstract_guard_impl}
1890+
(cf:=config.extraction_checker_flags) (Σ:global_env_ext_map)
1891+
{f na A B}
1892+
(wf : ∥ Σ ;;; [] |- f : PCUICAst.tProd na A B ∥) pr :
1893+
axiom_free Σ ->
1894+
∥ nisErasable Σ [] f ∥ ->
1895+
let tr := transform verified_erasure_pipeline (Σ, f) pr in
1896+
exists v, ∥ eval (wfl := extraction_wcbv_flags) tr.1 tr.2 v ∥ /\ isFunction v = true.
1897+
Proof.
1898+
intros axfree nise.
1899+
unfold verified_erasure_pipeline.
1900+
rewrite -!transform_compose_assoc.
1901+
pose proof (expand_lets_function Σ (fun p : global_env_ext_map =>
1902+
(wf_ext p -> PCUICSN.NormalizationIn p) /\
1903+
(wf_ext p -> PCUICWeakeningEnvSN.normalizationInAdjustUniversesIn p)) f na A B wf pr).
1904+
destruct_compose. intros pre.
1905+
set (trexp := transform (pcuic_expand_lets_transform _) _ _) in *.
1906+
eapply (PCUICExpandLetsCorrectness.trans_axiom_free Σ) in axfree.
1907+
have nise' : ∥ nisErasable trexp.1 [] trexp.2 ∥.
1908+
destruct pr as [[[]] ?], nise. sq; now eapply nisErasable_lets.
1909+
change (trans_global_env _) with (global_env_ext_map_global_env_ext trexp.1).1 in axfree.
1910+
clearbody trexp. clear nise pr wf Σ f. destruct trexp as [Σ f].
1911+
pose proof pre as pre'; destruct pre' as [[[wf _]] _].
1912+
pose proof (map_squash (pcuic_function_value wf axfree) H) as [[v ev]].
1913+
epose proof (Transform.preservation erase_transform).
1914+
specialize (H0 _ v pre (sq ev)).
1915+
revert H0.
1916+
destruct_compose. intros pre' htr.
1917+
destruct htr as [v'' [ev' _]].
1918+
epose proof (erase_function_to_function _ f v'' _ _ _ H pre axfree nise').
1919+
set (tre := transform erase_transform _ _) in *. clearbody tre.
1920+
cbn -[transform obseq].
1921+
red in ev'. destruct ev'.
1922+
epose proof (Transform.preservation verified_lambdabox_pipeline).
1923+
destruct tre as [Σ' f'].
1924+
specialize (H2 _ v'' pre' (sq H1)) as [finalv [[evfinal] obseq]].
1925+
exists finalv.
1926+
split. now sq.
1927+
have prev : Transform.pre verified_lambdabox_pipeline (Σ', v'').
1928+
{ clear -wfl pre' H1. cbn in H1.
1929+
destruct pre' as [[] []]. split; split => //=.
1930+
eapply Prelim.Ee.eval_wellformed; eauto.
1931+
eapply EEtaExpandedFix.isEtaExp_expanded.
1932+
eapply (@EEtaExpandedFix.eval_etaexp wfl); eauto.
1933+
now eapply EEtaExpandedFix.expanded_global_env_isEtaExp_env.
1934+
now eapply EEtaExpandedFix.expanded_isEtaExp. }
1935+
specialize (H0 H1).
1936+
eapply (obseq_lambdabox (Σ', f') (Σ', v'')) in obseq.
1937+
epose proof (ETransformPresAppLam.transform_lam _ _ _ (t := lambdabox_pres_app) (Σ', v'') prev H0).
1938+
rewrite -obseq. exact H2. cbn. red; tauto.
1939+
Qed.
1940+
18131941
Lemma expand_lets_transform_env K p p' pre pre' :
18141942
p.1 = p'.1 ->
18151943
(transform (pcuic_expand_lets_transform K) p pre).1 =

0 commit comments

Comments
 (0)