uwplse / pumpkin-pi

An extension to PUMPKIN PATCH with support for proof repair across type equivalences.
MIT License
49 stars 9 forks source link

Support for translating fixed-points to eliminations (cf. Issue #18) #23

Closed nateyazdani closed 5 years ago

nateyazdani commented 5 years ago

Quick aside: I know that I'm submitting this on a Friday evening, so I want to emphasize that code review can easily wait until next week :-)

The translation approach is mostly as described in Issue #18:

  1. Reorder the fixed-point's parameters to align with the appropriate eliminator, which follows the standard order from the inductive definition.
  2. Partially evaluate the functional (fixed-point body) on each hypothetical constructor to derive the minor premises (a.k.a., case branches), while also exposing structurally recursive calls. Partial evaluation is done with beta-iota normalization.
  3. Replace each recursive call with a reference to the appropriate recurrence binding (e.g., an inductive hypothesis).
  4. Wrap the resulting term to accept arguments in the same order as the original fixed-point and reorder them for the elimination expression.

Support for whole-module translation will come in a subsequent PR.

The translated function will not necessary satisfy definitional equality with the original (fixed-point) form but has equivalent computational behavior (more precisely, bisimulative). This "definitional difference" can lead to an ill-typed translation when a proof term contains an expansion of another constant; List.In_nth demonstrates such a situation, unlike List.nth_In (for comparison). Whole-module translation will solve such problems, via compositionality analogous to ornamental lifting.

As one would expect, this translation only supports "primitive" structural recursion, in which each recursive call is on a direct descendent of the current structural guard value (i.e., no fancy transformation for n-induction). (Implicitly, that also leaves mutual recursion unsupported.) The benefit of this restriction is that the translated term corresponds extremely closely to its original form.

The new helper functions for fixed-point support also led to substantial simplification of the translation for bare (non-recursive) match expressions.

Tests were added to plugin/coq/Desugar.v and linked into plugin/test.sh.

I'm going to read through the current resubmission draft this weekend, to check for any mismatch between the paper's description of this translation and its present implementation.

tlringer commented 5 years ago

I think the best thing would be to go over this PR together when we meet.

nateyazdani commented 5 years ago

Alright, I think that I've covered all the needed revisions: