aboutsummaryrefslogtreecommitdiff
path: root/src/Reflection/Syntax.v
diff options
context:
space:
mode:
authorGravatar Jason Gross <jgross@mit.edu>2017-01-19 19:35:24 -0500
committerGravatar Jason Gross <jgross@mit.edu>2017-01-19 19:35:24 -0500
commitfa027c4a37ed455a26a5bb12c6f3d54ae4bd8774 (patch)
tree4e6d08d6d36595a068f3facf2c70f540bae0e8b1 /src/Reflection/Syntax.v
parent320c013f0c5550aed168dd7fd25274dbb9756590 (diff)
Remove the Const constructor of exprf
We instead use the [Op] constructor for constants. This allows [exprf] to not depend on the interpretation function; this means we don't need to map over it to change the interpretation function. This saves us about 300 lines of code and about 30s of build time, total. After | File Name | Before || Change ----------------------------------------------------------------------------------------------------------- 18m11.34s | Total | 18m46.86s || -0m35.52s ----------------------------------------------------------------------------------------------------------- 0m19.99s | Specific/GF25519ReflectiveAddCoordinates | 0m31.78s || -0m11.79s 1m53.69s | Specific/GF25519Reflective/Reified/LadderStep | 2m01.32s || -0m07.62s 1m27.74s | Specific/GF25519Reflective/Reified/AddCoordinates | 1m34.03s || -0m06.29s 0m01.45s | Specific/GF25519Reflective | 0m06.31s || -0m04.85s 0m04.62s | Reflection/InlineInterp | 0m01.52s || +0m03.10s 1m19.68s | CompleteEdwardsCurve/ExtendedCoordinates | 1m21.19s || -0m01.50s 0m02.90s | Reflection/InlineWf | 0m01.80s || +0m01.09s N/A | Reflection/MapWithInterpInfo | 0m01.70s || -0m01.70s 1m32.32s | Test/Curve25519SpecTestVectors | 1m32.25s || +0m00.06s 1m12.79s | Experiments/Ed25519 | 1m13.17s || -0m00.38s 0m40.52s | ModularArithmetic/Conversion | 0m40.44s || +0m00.08s 0m34.57s | Spec/Ed25519 | 0m34.53s || +0m00.03s 0m30.82s | ModularArithmetic/ModularBaseSystemProofs | 0m30.89s || -0m00.07s 0m30.11s | Specific/GF25519Bounded | 0m30.21s || -0m00.10s 0m23.20s | Experiments/MontgomeryCurve | 0m23.26s || -0m00.06s 0m22.16s | Reflection/Z/Interpretations128/Relations | 0m21.72s || +0m00.44s 0m21.69s | ModularArithmetic/Pow2BaseProofs | 0m21.58s || +0m00.11s 0m20.25s | Algebra | 0m20.27s || -0m00.01s 0m19.81s | Specific/GF25519 | 0m19.83s || -0m00.01s 0m18.82s | Reflection/Z/Interpretations64/Relations | 0m18.50s || +0m00.32s 0m18.19s | EdDSARepChange | 0m18.26s || -0m00.07s 0m17.08s | CompleteEdwardsCurve/CompleteEdwardsCurveTheorems | 0m17.16s || -0m00.08s 0m14.10s | Util/ZUtil | 0m14.03s || +0m00.07s 0m10.05s | Testbit | 0m10.02s || +0m00.03s 0m08.95s | Specific/GF25519BoundedCommon | 0m08.90s || +0m00.04s 0m08.87s | BoundedArithmetic/ArchitectureToZLikeProofs | 0m08.81s || +0m00.05s 0m08.80s | Assembly/GF25519 | 0m08.82s || -0m00.01s 0m08.80s | ModularArithmetic/Montgomery/ZProofs | 0m08.87s || -0m00.06s 0m08.51s | Encoding/PointEncoding | 0m08.53s || -0m00.01s 0m08.37s | BoundedArithmetic/Double/Proofs/Multiply | 0m08.39s || -0m00.02s 0m08.34s | Specific/GF1305 | 0m08.31s || +0m00.02s 0m07.85s | BoundedArithmetic/Double/Proofs/ShiftRightDoubleWordImmediate | 0m07.86s || -0m00.01s 0m07.60s | Specific/GF25519Reflective/Reified/Mul | 0m07.52s || +0m00.08s 0m07.13s | MxDHRepChange | 0m07.08s || +0m00.04s 0m06.85s | BoundedArithmetic/Double/Proofs/SpreadLeftImmediate | 0m06.77s || +0m00.08s 0m06.62s | Reflection/Z/InterpretationsGen | 0m06.62s || +0m00.00s 0m05.69s | Reflection/Z/Interpretations64/RelationsCombinations | 0m05.60s || +0m00.09s 0m05.68s | Reflection/Z/Interpretations128/RelationsCombinations | 0m05.67s || +0m00.00s 0m05.48s | Specific/SC25519 | 0m05.38s || +0m00.10s 0m05.40s | BoundedArithmetic/Double/Proofs/RippleCarryAddSub | 0m05.36s || +0m00.04s 0m04.93s | ModularArithmetic/ModularBaseSystemListProofs | 0m04.96s || -0m00.03s 0m04.87s | WeierstrassCurve/Pre | 0m04.83s || +0m00.04s 0m04.45s | Specific/GF25519Reflective/Reified/PreFreeze | 0m04.56s || -0m00.10s 0m04.33s | Specific/GF25519Reflective/CommonBinOp | 0m04.55s || -0m00.21s 0m03.95s | ModularArithmetic/BarrettReduction/ZHandbook | 0m03.98s || -0m00.02s 0m03.87s | Specific/GF25519Reflective/CommonUnOp | 0m04.08s || -0m00.20s 0m03.86s | Encoding/PointEncodingPre | 0m03.88s || -0m00.02s 0m03.84s | BaseSystemProofs | 0m03.88s || -0m00.04s 0m03.75s | Specific/GF25519Reflective/CommonUnOpWireToFE | 0m03.96s || -0m00.20s 0m03.64s | CompleteEdwardsCurve/Pre | 0m03.60s || +0m00.04s 0m03.51s | BoundedArithmetic/InterfaceProofs | 0m03.42s || +0m00.08s 0m03.41s | ModularArithmetic/Tutorial | 0m03.38s || +0m00.03s 0m03.30s | Reflection/LinearizeWf | 0m04.24s || -0m00.94s 0m03.20s | Specific/GF25519Reflective/Reified/CarrySub | 0m03.28s || -0m00.07s 0m03.14s | ModularArithmetic/ZBoundedZ | 0m03.14s || +0m00.00s 0m03.14s | ModularArithmetic/BarrettReduction/ZGeneralized | 0m03.14s || +0m00.00s 0m02.95s | Specific/GF25519Reflective/Reified/CarryAdd | 0m02.93s || +0m00.02s 0m02.92s | Specific/GF25519Reflective/Common9_4Op | 0m02.89s || +0m00.02s 0m02.82s | Specific/GF25519Reflective/Reified/CarryOpp | 0m02.95s || -0m00.13s 0m02.82s | BoundedArithmetic/Double/Proofs/Decode | 0m02.90s || -0m00.08s 0m02.69s | BoundedArithmetic/Double/Proofs/ShiftRight | 0m02.69s || +0m00.00s 0m02.66s | ModularArithmetic/ModularArithmeticTheorems | 0m02.67s || -0m00.00s 0m02.63s | Specific/FancyMachine256/Montgomery | 0m02.24s || +0m00.38s 0m02.61s | Specific/GF25519Reflective/CommonUnOpFEToWire | 0m02.76s || -0m00.14s 0m02.58s | BoundedArithmetic/Double/Proofs/ShiftLeft | 0m02.58s || +0m00.00s 0m02.56s | Specific/GF25519Reflective/Common | 0m02.60s || -0m00.04s 0m02.52s | Specific/FancyMachine256/Barrett | 0m02.20s || +0m00.31s 0m02.50s | Specific/GF25519BoundedAddCoordinates | 0m02.60s || -0m00.10s 0m02.39s | ModularArithmetic/BarrettReduction/ZBounded | 0m02.31s || +0m00.08s 0m02.34s | ModularArithmetic/ModularBaseSystemOpt | 0m02.31s || +0m00.02s 0m02.02s | Specific/GF25519Reflective/Reified/Sub | 0m02.01s || +0m00.01s 0m01.98s | Reflection/WfReflective | 0m02.54s || -0m00.56s 0m01.94s | Specific/GF25519Reflective/Reified/Pack | 0m02.07s || -0m00.12s 0m01.93s | Assembly/Evaluables | 0m01.93s || +0m00.00s 0m01.92s | Specific/GF25519Reflective/Reified/Unpack | 0m02.04s || -0m00.12s 0m01.90s | Specific/FancyMachine256/Core | 0m01.79s || +0m00.10s 0m01.79s | ModularArithmetic/Montgomery/ZBounded | 0m01.86s || -0m00.07s 0m01.77s | Specific/GF25519ExtendedAddCoordinates | 0m01.76s || +0m00.01s 0m01.68s | Specific/GF25519Reflective/Reified/Add | 0m01.69s || -0m00.01s 0m01.67s | Specific/GF25519BoundedExtendedAddCoordinates | 0m01.79s || -0m00.12s 0m01.63s | Experiments/Ed25519Extraction | 0m01.66s || -0m00.03s 0m01.62s | Specific/GF25519Reflective/Reified/Opp | 0m01.72s || -0m00.09s 0m01.54s | Specific/GF25519Reflective/Reified/GeModulus | 0m01.59s || -0m00.05s 0m01.50s | Reflection/TestCase | 0m01.42s || +0m00.08s 0m01.47s | ModularArithmetic/BarrettReduction/Z | 0m01.47s || +0m00.00s 0m01.43s | Assembly/Compile | 0m01.46s || -0m00.03s 0m01.33s | Reflection/WfProofs | 0m01.95s || -0m00.61s 0m01.26s | ModularArithmetic/PrimeFieldTheorems | 0m01.28s || -0m00.02s 0m01.20s | Assembly/Conversions | 0m01.19s || +0m00.01s 0m01.16s | ModularArithmetic/ExtendedBaseVector | 0m01.22s || -0m00.06s 0m01.16s | BaseSystem | 0m01.15s || +0m00.01s 0m01.09s | BoundedArithmetic/Double/Repeated/Proofs/Decode | 0m01.11s || -0m00.02s 0m00.99s | Util/NumTheoryUtil | 0m00.96s || +0m00.03s 0m00.96s | Assembly/HL | 0m00.96s || +0m00.00s 0m00.94s | Assembly/LL | 0m00.99s || -0m00.05s 0m00.94s | Assembly/Pipeline | 0m00.92s || +0m00.01s 0m00.88s | Reflection/WfInversion | 0m01.21s || -0m00.32s 0m00.86s | Assembly/PhoasCommon | 0m00.91s || -0m00.05s 0m00.86s | Specific/GF25519Reflective/CommonUnOpFEToZ | 0m01.02s || -0m00.16s 0m00.85s | BoundedArithmetic/Double/Proofs/LoadImmediate | 0m00.86s || -0m00.01s 0m00.84s | BoundedArithmetic/Double/Proofs/BitwiseOr | 0m00.91s || -0m00.07s 0m00.82s | BoundedArithmetic/X86ToZLikeProofs | 0m00.85s || -0m00.03s 0m00.79s | Util/IterAssocOp | 0m00.82s || -0m00.02s 0m00.75s | Reflection/Z/Syntax | 0m00.67s || +0m00.07s 0m00.73s | Util/PartiallyReifiedProp | 0m00.73s || +0m00.00s 0m00.70s | Encoding/ModularWordEncodingTheorems | 0m00.76s || -0m00.06s 0m00.70s | Specific/GF25519Reflective/Reified | 0m00.72s || -0m00.02s 0m00.66s | BoundedArithmetic/Double/Repeated/Proofs/Multiply | 0m00.62s || +0m00.04s 0m00.66s | ModularArithmetic/PseudoMersenneBaseParamProofs | 0m00.66s || +0m00.00s 0m00.64s | Encoding/ModularWordEncodingPre | 0m00.63s || +0m00.01s 0m00.61s | ModularArithmetic/ModularBaseSystem | 0m00.66s || -0m00.05s 0m00.61s | Util/AdditionChainExponentiation | 0m00.64s || -0m00.03s 0m00.60s | ModularArithmetic/ExtPow2BaseMulProofs | 0m00.64s || -0m00.04s 0m00.60s | Reflection/MultiSizeTest2 | 0m00.71s || -0m00.10s 0m00.60s | Spec/EdDSA | 0m00.65s || -0m00.05s 0m00.59s | BoundedArithmetic/Double/Repeated/Proofs/RippleCarryAddSub | 0m00.51s || +0m00.07s 0m00.58s | BoundedArithmetic/Interface | 0m00.60s || -0m00.02s 0m00.58s | ModularArithmetic/ModularBaseSystemList | 0m00.61s || -0m00.03s 0m00.55s | Spec/ModularWordEncoding | 0m00.63s || -0m00.07s 0m00.55s | BoundedArithmetic/Double/Repeated/Proofs/ShiftLeftRight | 0m00.50s || +0m00.05s 0m00.55s | Reflection/InterpWfRel | 0m00.58s || -0m00.02s 0m00.54s | BoundedArithmetic/X86ToZLike | 0m00.55s || -0m00.01s 0m00.54s | BoundedArithmetic/Double/Repeated/Proofs/SelectConditional | 0m00.53s || +0m00.01s 0m00.54s | BoundedArithmetic/Double/Proofs/SelectConditional | 0m00.62s || -0m00.07s 0m00.54s | Reflection/WfReflectiveGen | 0m00.58s || -0m00.03s 0m00.52s | BoundedArithmetic/ArchitectureToZLike | 0m00.41s || +0m00.11s 0m00.51s | BoundedArithmetic/Double/Core | 0m00.48s || +0m00.03s 0m00.50s | BoundedArithmetic/Double/Repeated/Proofs/BitwiseOr | 0m00.51s || -0m00.01s 0m00.49s | Spec/WeierstrassCurve | 0m00.42s || +0m00.07s 0m00.48s | BoundedArithmetic/Double/Repeated/Proofs/LoadImmediate | 0m00.54s || -0m00.06s 0m00.47s | BoundedArithmetic/Double/Repeated/Proofs/ShiftRightDoubleWordImmediate | 0m00.58s || -0m00.10s 0m00.47s | Reflection/InterpWf | 0m00.50s || -0m00.03s 0m00.47s | ModularArithmetic/Pre | 0m00.48s || -0m00.01s 0m00.47s | BoundedArithmetic/Double/Repeated/Core | 0m00.46s || +0m00.00s 0m00.46s | Reflection/Z/Interpretations64 | 0m00.49s || -0m00.02s 0m00.45s | Reflection/InputSyntax | 0m00.42s || +0m00.03s N/A | Reflection/MapInterpWf | 0m00.44s || -0m00.44s 0m00.44s | Spec/CompleteEdwardsCurve | 0m00.39s || +0m00.04s 0m00.44s | BoundedArithmetic/Double/Proofs/ShiftLeftRightTactic | 0m00.42s || +0m00.02s 0m00.44s | Reflection/Z/Interpretations128 | 0m00.52s || -0m00.08s 0m00.44s | ModularArithmetic/ZBounded | 0m00.45s || -0m00.01s 0m00.42s | BoundedArithmetic/StripCF | 0m00.42s || +0m00.00s 0m00.42s | Reflection/Z/Reify | 0m00.43s || -0m00.01s 0m00.42s | ModularArithmetic/ModularBaseSystemListZOperationsProofs | 0m00.47s || -0m00.04s 0m00.41s | Reflection/Named/DeadCodeElimination | 0m00.43s || -0m00.02s 0m00.41s | ModularArithmetic/PseudoMersenneBaseParams | 0m00.38s || +0m00.02s 0m00.41s | Spec/ModularArithmetic | 0m00.34s || +0m00.06s 0m00.41s | Reflection/Named/RegisterAssign | 0m00.37s || +0m00.03s 0m00.41s | Reflection/Reify | 0m00.39s || +0m00.01s 0m00.40s | ModularArithmetic/Pow2Base | 0m00.42s || -0m00.01s 0m00.40s | Reflection/Named/EstablishLiveness | 0m00.33s || +0m00.07s 0m00.40s | Reflection/ExprInversion | 0m00.57s || -0m00.16s 0m00.40s | Reflection/Named/Syntax | 0m00.40s || +0m00.00s 0m00.38s | Reflection/Named/Compile | 0m00.34s || +0m00.03s N/A | Reflection/MapInterp | 0m00.38s || -0m00.38s 0m00.38s | ModularArithmetic/Montgomery/Z | 0m00.39s || -0m00.01s 0m00.38s | ModularArithmetic/ModularBaseSystemWord | 0m00.36s || +0m00.02s N/A | Reflection/WfRel | 0m00.38s || -0m00.38s 0m00.38s | Reflection/Tuple | N/A || +0m00.38s 0m00.37s | Spec/MxDH | 0m00.39s || -0m00.02s 0m00.37s | BoundedArithmetic/Eta | 0m00.36s || +0m00.01s 0m00.36s | Reflection/Named/ContextOn | 0m00.37s || -0m00.01s 0m00.34s | Reflection/FilterLive | 0m00.34s || +0m00.00s 0m00.34s | Reflection/LinearizeInterp | 0m00.53s || -0m00.19s 0m00.33s | Reflection/Relations | N/A || +0m00.33s 0m00.32s | Reflection/Equality | 0m00.41s || -0m00.08s 0m00.30s | Reflection/Syntax | 0m00.52s || -0m00.22s 0m00.30s | Reflection/InterpProofs | 0m00.47s || -0m00.17s 0m00.30s | Reflection/ApplicationLemmas | 0m00.43s || -0m00.13s 0m00.30s | Reflection/CommonSubexpressionElimination | 0m00.50s || -0m00.20s 0m00.28s | Reflection/Inline | 0m00.37s || -0m00.08s 0m00.28s | Reflection/Conversion | 0m00.44s || -0m00.15s 0m00.27s | Reflection/MapCastWithCastOp | 0m00.38s || -0m00.10s 0m00.26s | Reflection/MapCast | 0m00.40s || -0m00.14s 0m00.26s | Reflection/ApplicationRelations | 0m00.35s || -0m00.08s 0m00.24s | Reflection/Application | 0m00.38s || -0m00.14s 0m00.23s | Reflection/Linearize | 0m00.35s || -0m00.11s 0m00.20s | Reflection/CountLets | 0m00.33s || -0m00.13s 0m00.20s | Reflection/Named/NameUtil | 0m00.36s || -0m00.15s 0m00.09s | Util/PointedProp | 0m00.08s || +0m00.00s 0m00.05s | Util/LetIn | 0m00.06s || -0m00.00s 0m00.03s | Util/Notations | 0m00.03s || +0m00.00s 0m00.03s | Util/AutoRewrite | 0m00.03s || +0m00.00s
Diffstat (limited to 'src/Reflection/Syntax.v')
-rw-r--r--src/Reflection/Syntax.v271
1 files changed, 69 insertions, 202 deletions
diff --git a/src/Reflection/Syntax.v b/src/Reflection/Syntax.v
index f8d7cdcf3..58000fdca 100644
--- a/src/Reflection/Syntax.v
+++ b/src/Reflection/Syntax.v
@@ -1,6 +1,5 @@
(** * PHOAS Representation of Gallina *)
Require Import Coq.Strings.String Coq.Classes.RelationClasses Coq.Classes.Morphisms.
-Require Import Crypto.Util.Tuple.
Require Import Crypto.Util.LetIn.
Require Import Crypto.Util.Tactics.
Require Import Crypto.Util.Notations.
@@ -16,7 +15,7 @@ Local Open Scope expr_scope.
Section language.
Context (base_type_code : Type).
- Inductive flat_type := Tbase (T : base_type_code) | Prod (A B : flat_type).
+ Inductive flat_type := Tbase (T : base_type_code) | Unit | Prod (A B : flat_type).
Bind Scope ctype_scope with flat_type.
Inductive type := Tflat (T : flat_type) | Arrow (A : base_type_code) (B : type).
@@ -27,16 +26,19 @@ Section language.
Notation "A -> B" := (Arrow A B) : ctype_scope.
Local Coercion Tbase : base_type_code >-> flat_type.
- Fixpoint tuple' T n :=
- match n with
- | O => T
- | S n' => (tuple' T n' * T)%ctype
- end.
- Definition tuple T n :=
- match n with
- | O => T (* default value; no empty tuple *)
- | S n' => tuple' T n'
- end.
+ Section tuple.
+ Context (T : flat_type).
+ Fixpoint tuple' n :=
+ match n with
+ | O => T
+ | S n' => (tuple' n' * T)%ctype
+ end.
+ Definition tuple n :=
+ match n with
+ | O => Unit
+ | S n' => tuple' n'
+ end.
+ End tuple.
Section interp.
Section type.
@@ -49,134 +51,19 @@ Section language.
| Arrow x y => (interp_src_type x -> interp_type_gen_hetero y)%type
end.
End hetero.
- Section homogenous.
- Context (interp_flat_type : flat_type -> Type).
- Definition interp_type_gen := interp_type_gen_hetero interp_flat_type interp_flat_type.
- Section rel.
- Context (R : forall t, interp_flat_type t -> interp_flat_type t -> Prop).
- Fixpoint interp_type_gen_rel_pointwise (t : type)
- : interp_type_gen t -> interp_type_gen t -> Prop :=
- match t with
- | Tflat t => R t
- | Arrow _ y => fun f g => forall x, interp_type_gen_rel_pointwise y (f x) (g x)
- end.
- Global Instance interp_type_gen_rel_pointwise_Reflexive {H : forall t, Reflexive (R t)}
- : forall t, Reflexive (interp_type_gen_rel_pointwise t).
- Proof. induction t; repeat intro; reflexivity. Qed.
- Global Instance interp_type_gen_rel_pointwise_Symmetric {H : forall t, Symmetric (R t)}
- : forall t, Symmetric (interp_type_gen_rel_pointwise t).
- Proof. induction t; simpl; repeat intro; symmetry; eauto. Qed.
- Global Instance interp_type_gen_rel_pointwise_Transitive {H : forall t, Transitive (R t)}
- : forall t, Transitive (interp_type_gen_rel_pointwise t).
- Proof. induction t; simpl; repeat intro; etransitivity; eauto. Qed.
- End rel.
- End homogenous.
+ Definition interp_type_gen (interp_flat_type : flat_type -> Type)
+ := interp_type_gen_hetero interp_flat_type interp_flat_type.
End type.
Section flat_type.
Context (interp_base_type : base_type_code -> Type).
Fixpoint interp_flat_type (t : flat_type) :=
match t with
| Tbase t => interp_base_type t
+ | Unit => unit
| Prod x y => prod (interp_flat_type x) (interp_flat_type y)
end.
Definition interp_type := interp_type_gen interp_flat_type.
- Fixpoint flat_interp_tuple' {T n} : interp_flat_type (tuple' T n) -> Tuple.tuple' (interp_flat_type T) n
- := match n return interp_flat_type (tuple' T n) -> Tuple.tuple' (interp_flat_type T) n with
- | O => fun x => x
- | S n' => fun xy => (@flat_interp_tuple' _ n' (fst xy), snd xy)
- end.
- Definition flat_interp_tuple {T n} : interp_flat_type (tuple T n) -> Tuple.tuple (interp_flat_type T) n
- := match n return interp_flat_type (tuple T n) -> Tuple.tuple (interp_flat_type T) n with
- | O => fun _ => tt
- | S n' => @flat_interp_tuple' T n'
- end.
- Fixpoint flat_interp_untuple' {T n} : Tuple.tuple' (interp_flat_type T) n -> interp_flat_type (tuple' T n)
- := match n return Tuple.tuple' (interp_flat_type T) n -> interp_flat_type (tuple' T n) with
- | O => fun x => x
- | S n' => fun xy => (@flat_interp_untuple' _ n' (fst xy), snd xy)
- end.
- Lemma flat_interp_untuple'_tuple' {T n v}
- : @flat_interp_untuple' T n (flat_interp_tuple' v) = v.
- Proof. induction n; [ reflexivity | simpl; rewrite IHn; destruct v; reflexivity ]. Qed.
- Lemma flat_interp_untuple'_tuple {T n v}
- : flat_interp_untuple' (@flat_interp_tuple T (S n) v) = v.
- Proof. apply flat_interp_untuple'_tuple'. Qed.
- Lemma flat_interp_tuple'_untuple' {T n v}
- : @flat_interp_tuple' T n (flat_interp_untuple' v) = v.
- Proof. induction n; [ reflexivity | simpl; rewrite IHn; destruct v; reflexivity ]. Qed.
- Lemma flat_interp_tuple_untuple' {T n v}
- : @flat_interp_tuple T (S n) (flat_interp_untuple' v) = v.
- Proof. apply flat_interp_tuple'_untuple'. Qed.
- Definition tuple_map {A B n} (f : interp_flat_type A -> interp_flat_type B) (v : interp_flat_type (tuple A n))
- : interp_flat_type (tuple B n)
- := let fv := Tuple.map f (flat_interp_tuple v) in
- match n return interp_flat_type (tuple A n) -> Tuple.tuple (interp_flat_type B) n -> interp_flat_type (tuple B n) with
- | 0 => fun v _ => f v
- | S _ => fun v fv => flat_interp_untuple' fv
- end v fv.
- Section rel.
- Context (R : forall t, interp_base_type t -> interp_base_type t -> Prop).
- Fixpoint interp_flat_type_rel_pointwise (t : flat_type)
- : interp_flat_type t -> interp_flat_type t -> Prop :=
- match t with
- | Tbase t => R t
- | Prod _ _ => fun x y => interp_flat_type_rel_pointwise _ (fst x) (fst y)
- /\ interp_flat_type_rel_pointwise _ (snd x) (snd y)
- end.
- Definition interp_type_rel_pointwise
- := interp_type_gen_rel_pointwise _ interp_flat_type_rel_pointwise.
- End rel.
End flat_type.
- Section rel_pointwise2.
- Section type.
- Section hetero.
- Context (interp_src1 interp_src2 : base_type_code -> Type)
- (interp_flat_type1 interp_flat_type2 : flat_type -> Type)
- (Rsrc : forall t, interp_src1 t -> interp_src2 t -> Prop)
- (R : forall t, interp_flat_type1 t -> interp_flat_type2 t -> Prop).
-
- Fixpoint interp_type_gen_rel_pointwise2_hetero (t : type)
- : interp_type_gen_hetero interp_src1 interp_flat_type1 t
- -> interp_type_gen_hetero interp_src2 interp_flat_type2 t
- -> Prop
- := match t with
- | Tflat t => R t
- | Arrow src dst => @respectful_hetero _ _ _ _ (Rsrc src) (fun _ _ => interp_type_gen_rel_pointwise2_hetero dst)
- end.
- End hetero.
- Section homogenous.
- Context (interp_flat_type1 interp_flat_type2 : flat_type -> Type)
- (R : forall t, interp_flat_type1 t -> interp_flat_type2 t -> Prop).
-
- Definition interp_type_gen_rel_pointwise2
- := interp_type_gen_rel_pointwise2_hetero interp_flat_type1 interp_flat_type2
- interp_flat_type1 interp_flat_type2
- R R.
- End homogenous.
- End type.
- Section flat_type.
- Context (interp_base_type1 interp_base_type2 : base_type_code -> Type).
- Section gen_prop.
- Context (P : Type)
- (and : P -> P -> P)
- (R : forall t, interp_base_type1 t -> interp_base_type2 t -> P).
-
- Fixpoint interp_flat_type_rel_pointwise2_gen_Prop (t : flat_type)
- : interp_flat_type interp_base_type1 t -> interp_flat_type interp_base_type2 t -> P
- := match t with
- | Tbase t => R t
- | Prod x y => fun a b => and (interp_flat_type_rel_pointwise2_gen_Prop x (fst a) (fst b))
- (interp_flat_type_rel_pointwise2_gen_Prop y (snd a) (snd b))
- end.
- End gen_prop.
-
- Definition interp_flat_type_rel_pointwise2
- := @interp_flat_type_rel_pointwise2_gen_Prop Prop and.
-
- Definition interp_type_rel_pointwise2 R
- := interp_type_gen_rel_pointwise2 _ _ (interp_flat_type_rel_pointwise2 R).
- End flat_type.
- End rel_pointwise2.
End interp.
Section expr_param.
@@ -190,7 +77,7 @@ Section language.
(** N.B. [Let] binds the components of a pair to separate variables, and does so recursively *)
Inductive exprf : flat_type -> Type :=
- | Const {t : flat_type} (x : interp_type t) : exprf t
+ | TT : exprf Unit
| Var {t} (v : var t) : exprf t
| Op {t1 tR} (opc : op t1 tR) (args : exprf t1) : exprf tR
| LetIn {tx} (ex : exprf tx) {tC} (eC : interp_flat_type_gen var tx -> exprf tC) : exprf tC
@@ -201,32 +88,6 @@ Section language.
| Abs {src dst} (f : var src -> expr dst) : expr (Arrow src dst).
Bind Scope expr_scope with expr.
Global Coercion Return : exprf >-> expr.
- Definition UnReturn {t} (e : expr (Tflat t)) : exprf t
- := match e with
- | Return _ v => v
- | Abs _ _ _ => I
- end.
- Definition UnAbs {src dst} (e : expr (Arrow src dst)) : var src -> expr dst
- := match e with
- | Return _ _ => I
- | Abs _ _ f => f
- end.
- Definition UnReturn_eta {t} (e : expr (Tflat t)) : Return (UnReturn e) = e
- := match e in expr T return match T return expr T -> Prop with
- | Tflat _ => fun e => Return (UnReturn e) = e
- | _ => fun _ => I = I
- end e with
- | Return _ _ => eq_refl
- | Abs _ _ _ => eq_refl
- end.
- Definition UnAbs_eta {src dst} (e : expr (Arrow src dst)) : Abs (UnAbs e) = e
- := match e in expr T return match T return expr T -> Prop with
- | Arrow src dst => fun e => Abs (UnAbs e) = e
- | _ => fun _ => I = I
- end e with
- | Return _ _ => eq_refl
- | Abs _ _ _ => eq_refl
- end.
(** Sometimes, we want to deal with partially-interpreted
expressions, things like [prod (exprf A) (exprf B)] rather
than [exprf (Prod A B)], or like [prod (var A) (var B)] when
@@ -239,25 +100,28 @@ Section language.
[interp_base_type] into [exprf])). *)
Fixpoint smart_interp_flat_map {f g}
(h : forall x, f x -> g (Tbase x))
+ (tt : g Unit)
(pair : forall A B, g A -> g B -> g (Prod A B))
{t}
: interp_flat_type_gen f t -> g t
:= match t return interp_flat_type_gen f t -> g t with
| Tbase _ => h _
+ | Unit => fun _ => tt
| Prod A B => fun v => pair _ _
- (@smart_interp_flat_map f g h pair A (fst v))
- (@smart_interp_flat_map f g h pair B (snd v))
+ (@smart_interp_flat_map f g h tt pair A (fst v))
+ (@smart_interp_flat_map f g h tt pair B (snd v))
end.
Fixpoint smart_interp_map_hetero {f g g'}
(h : forall x, f x -> g (Tflat (Tbase x)))
+ (tt : g Unit)
(pair : forall A B, g (Tflat A) -> g (Tflat B) -> g (Prod A B))
(abs : forall A B, (g' A -> g B) -> g (Arrow A B))
{t}
: interp_type_gen_hetero g' (interp_flat_type_gen f) t -> g t
:= match t return interp_type_gen_hetero g' (interp_flat_type_gen f) t -> g t with
- | Tflat _ => @smart_interp_flat_map f (fun x => g (Tflat x)) h pair _
+ | Tflat _ => @smart_interp_flat_map f (fun x => g (Tflat x)) h tt pair _
| Arrow A B => fun v => abs _ _
- (fun x => @smart_interp_map_hetero f g g' h pair abs B (v x))
+ (fun x => @smart_interp_map_hetero f g g' h tt pair abs B (v x))
end.
Fixpoint smart_interp_map_gen {f g}
(h : forall x, f x -> g (Tflat (Tbase x)))
@@ -274,44 +138,51 @@ Section language.
Definition smart_interp_map {f g}
(h : forall x, f x -> g (Tflat (Tbase x)))
(h' : forall x, g (Tflat (Tbase x)) -> f x)
+ (tt : g Unit)
(pair : forall A B, g (Tflat A) -> g (Tflat B) -> g (Prod A B))
(abs : forall A B, (g (Tflat (Tbase A)) -> g B) -> g (Arrow A B))
{t}
: interp_type_gen (interp_flat_type_gen f) t -> g t
- := @smart_interp_map_gen f g h h' (@smart_interp_flat_map f (fun x => g (Tflat x)) h pair) abs t.
+ := @smart_interp_map_gen f g h h' (@smart_interp_flat_map f (fun x => g (Tflat x)) h tt pair) abs t.
Fixpoint SmartValf {T} (val : forall t : base_type_code, T t) t : interp_flat_type_gen T t
:= match t return interp_flat_type_gen T t with
| Tbase _ => val _
+ | Unit => tt
| Prod A B => (@SmartValf T val A, @SmartValf T val B)
end.
Fixpoint SmartArrow (A : flat_type) (B : type) : type
:= match A with
| Tbase A' => Arrow A' B
+ | Unit => B
| Prod A0 A1
=> SmartArrow A0 (SmartArrow A1 B)
end.
Fixpoint SmartAbs {A B} {struct A} : forall (f : exprf A -> expr B), expr (SmartArrow A B)
:= match A return (exprf A -> expr B) -> expr (SmartArrow A B) with
| Tbase x => fun f => Abs (fun x => f (Var x))
+ | Unit => fun f => f TT
| Prod x y => fun f => @SmartAbs x _ (fun x' => @SmartAbs y _ (fun y' => f (Pair x' y')))
end.
(** [SmartVar] is like [Var], except that it inserts
pair-projections and [Pair] as necessary to handle
[flat_type], and not just [base_type_code] *)
+ Definition SmartPairf {t} : interp_flat_type_gen exprf t -> exprf t
+ := @smart_interp_flat_map exprf exprf (fun t x => x) TT (fun A B x y => Pair x y) t.
Definition SmartVarf {t} : interp_flat_type_gen var t -> exprf t
- := @smart_interp_flat_map var exprf (fun t => Var) (fun A B x y => Pair x y) t.
+ := @smart_interp_flat_map var exprf (fun t => Var) TT (fun A B x y => Pair x y) t.
Definition SmartVarfMap {var var'} (f : forall t, var t -> var' t) {t}
: interp_flat_type_gen var t -> interp_flat_type_gen var' t
- := @smart_interp_flat_map var (interp_flat_type_gen var') f (fun A B x y => pair x y) t.
+ := @smart_interp_flat_map var (interp_flat_type_gen var') f tt (fun A B x y => pair x y) t.
Definition SmartFlatTypeMap {var'} (f : forall t, var' t -> base_type_code) {t}
: interp_flat_type_gen var' t -> flat_type
- := @smart_interp_flat_map var' (fun _ => flat_type) f (fun _ _ => Prod) t.
+ := @smart_interp_flat_map var' (fun _ => flat_type) f Unit (fun _ _ => Prod) t.
Fixpoint SmartFlatTypeMapInterp {var' var''} (f : forall t, var' t -> base_type_code)
(fv : forall t v, var'' (f t v)) t {struct t}
: forall v, interp_flat_type_gen var'' (SmartFlatTypeMap f (t:=t) v)
:= match t return forall v, interp_flat_type_gen var'' (SmartFlatTypeMap f (t:=t) v) with
| Tbase x => fv _
+ | Unit => fun v => v
| Prod A B => fun xy => (@SmartFlatTypeMapInterp _ _ f fv A (fst xy),
@SmartFlatTypeMapInterp _ _ f fv B (snd xy))
end.
@@ -323,19 +194,20 @@ Section language.
:= match t return forall v, interp_flat_type_gen var'' (SmartFlatTypeMap f (t:=t) v)
-> interp_flat_type_gen var''' t with
| Tbase x => fv _
+ | Unit => fun _ v => v
| Prod A B => fun v xy => (@SmartFlatTypeMapUnInterp _ _ _ f fv A _ (fst xy),
@SmartFlatTypeMapUnInterp _ _ _ f fv B _ (snd xy))
end.
Definition SmartVarMap {var var'} (f : forall t, var t -> var' t) (f' : forall t, var' t -> var t) {t}
: interp_type_gen (interp_flat_type_gen var) t -> interp_type_gen (interp_flat_type_gen var') t
- := @smart_interp_map var (interp_type_gen (interp_flat_type_gen var')) f f' (fun A B x y => pair x y) (fun A B f x => f x) t.
+ := @smart_interp_map var (interp_type_gen (interp_flat_type_gen var')) f f' tt (fun A B x y => pair x y) (fun A B f x => f x) t.
Definition SmartVarMap_hetero {vars vars' var var'} (f : forall t, var t -> var' t) (f' : forall t, vars' t -> vars t) {t}
: interp_type_gen_hetero vars (interp_flat_type_gen var) t -> interp_type_gen_hetero vars' (interp_flat_type_gen var') t
- := @smart_interp_map_hetero var (interp_type_gen_hetero vars' (interp_flat_type_gen var')) vars f (fun A B x y => pair x y) (fun A B f x => f (f' _ x)) t.
+ := @smart_interp_map_hetero var (interp_type_gen_hetero vars' (interp_flat_type_gen var')) vars f tt (fun A B x y => pair x y) (fun A B f x => f (f' _ x)) t.
Definition SmartVarVarf {t} : interp_flat_type_gen var t -> interp_flat_type_gen exprf t
:= SmartVarfMap (fun t => Var).
- Definition SmartConstf {t} : interp_flat_type t -> interp_flat_type_gen exprf t
- := SmartVarfMap (fun t => Const (t:=t)).
+ (*Definition SmartConstf {t} : interp_flat_type t -> interp_flat_type_gen exprf t
+ := SmartVarfMap (fun t => Const (t:=t)).*)
End expr.
Definition Expr (t : type) := forall var, @expr var t.
@@ -347,7 +219,7 @@ Section language.
(interpf : forall {t} (e : @exprf interp_flat_type t), interp_flat_type t)
{t} (e : @exprf interp_flat_type t) : interp_flat_type t
:= match e in exprf t return interp_flat_type t with
- | Const _ x => x
+ | TT => tt
| Var _ x => x
| Op _ _ op args => @interp_op _ _ op (@interpf _ args)
| LetIn _ ex _ eC => dlet x := @interpf _ ex in @interpf _ (eC x)
@@ -375,13 +247,14 @@ Section language.
: interp_flat_type_gen var1 t
:= match t return interp_flat_type_gen _ t -> interp_flat_type_gen _ t with
| Tbase _ => fvar21 _
+ | Unit => fun v : unit => v
| Prod x y => fun xy => (@mapf_interp_flat_type _ (fst xy),
@mapf_interp_flat_type _ (snd xy))
end e.
Fixpoint mapf {t} (e : @exprf var1 t) : @exprf var2 t
:= match e in exprf t return exprf t with
- | Const _ x => Const x
+ | TT => TT
| Var _ x => Var (fvar12 _ x)
| Op _ _ op args => Op op (@mapf _ args)
| LetIn _ ex _ eC => LetIn (@mapf _ ex) (fun x => @mapf _ (eC (mapf_interp_flat_type x)))
@@ -397,11 +270,12 @@ Section language.
Fixpoint flatten_binding_list {t} (x : interp_flat_type_gen var1 t) (y : interp_flat_type_gen var2 t) : list (sigT eP)
:= (match t return interp_flat_type_gen var1 t -> interp_flat_type_gen var2 t -> list _ with
| Tbase _ => fun x y => (x == y) :: nil
+ | Unit => fun x y => nil
| Prod t0 t1 => fun x y => @flatten_binding_list _ (snd x) (snd y) ++ @flatten_binding_list _ (fst x) (fst y)
end x y)%list.
Inductive wff : list (sigT eP) -> forall {t}, @exprf var1 t -> @exprf var2 t -> Prop :=
- | WfConst : forall t G n, @wff G t (Const n) (Const n)
+ | WfTT : forall G, @wff G _ TT TT
| WfVar : forall G (t : base_type_code) x x', List.In (x == x') G -> @wff G t (Var x) (Var x')
| WfOp : forall G {t} {tR} (e : @exprf var1 t) (e' : @exprf var2 t) op,
wff G e e'
@@ -429,6 +303,7 @@ Section language.
End language.
Global Arguments tuple' {_}%type_scope _%ctype_scope _%nat_scope.
Global Arguments tuple {_}%type_scope _%ctype_scope _%nat_scope.
+Global Arguments Unit {_}%type_scope.
Global Arguments Prod {_}%type_scope (_ _)%ctype_scope.
Global Arguments Arrow {_}%type_scope (_ _)%ctype_scope.
Global Arguments Tbase {_}%type_scope _%ctype_scope.
@@ -436,47 +311,33 @@ Global Arguments Tflat {_}%type_scope _%ctype_scope.
Ltac admit_Wf := apply Wf_admitted.
-Global Arguments Const {_ _ _ _ _} _.
-Global Arguments Var {_ _ _ _ _} _.
-Global Arguments SmartVarf {_ _ _ _ _} _.
+Global Arguments Var {_ _ _ _} _.
+Global Arguments SmartVarf {_ _ _ _} _.
+Global Arguments SmartPairf {_ _ _ t} _.
Global Arguments SmartValf {_} T _ t.
-Global Arguments SmartVarVarf {_ _ _ _ _} _.
+Global Arguments SmartVarVarf {_ _ _ _} _.
Global Arguments SmartVarfMap {_ _ _} _ {_} _.
Global Arguments SmartFlatTypeMap {_ _} _ {_} _.
Global Arguments SmartFlatTypeMapInterp {_ _ _ _} _ {_} _.
Global Arguments SmartFlatTypeMapUnInterp {_ _ _ _ _} fv {_ _} _.
Global Arguments SmartVarMap_hetero {_ _ _ _ _} _ _ {_} _.
Global Arguments SmartVarMap {_ _ _} _ _ {_} _.
-Global Arguments SmartConstf {_ _ _ _ _} _.
-Global Arguments Op {_ _ _ _ _ _} _ _.
-Global Arguments LetIn {_ _ _ _ _} _ {_} _.
-Global Arguments Pair {_ _ _ _ _} _ {_} _.
-Global Arguments Return {_ _ _ _ _} _.
-Global Arguments Abs {_ _ _ _ _ _} _.
-Global Arguments SmartAbs {_ _ _ _ _ _} _.
-Global Arguments UnReturn {_ _ _ _ _} _.
-Global Arguments UnAbs {_ _ _ _ _ _} _ _.
-Global Arguments UnReturn_eta {_ _ _ _ _} _.
-Global Arguments UnAbs_eta {_ _ _ _ _ _} _.
-Global Arguments flat_interp_tuple' {_ _ _ _} _.
-Global Arguments flat_interp_tuple {_ _ _ _} _.
-Global Arguments flat_interp_untuple' {_ _ _ _} _.
-Global Arguments interp_type_rel_pointwise2 {_ _ _} R {t} _ _.
-Global Arguments interp_type_gen_rel_pointwise2_hetero {_ _ _ _ _} Rsrc R {t} _ _.
-Global Arguments interp_type_gen_rel_pointwise2 {_ _ _} R {t} _ _.
-Global Arguments interp_flat_type_rel_pointwise2_gen_Prop {_ _ _ P} and R {t} _ _.
-Global Arguments interp_flat_type_rel_pointwise2 {_ _ _} R {t} _ _.
+(*Global Arguments SmartConstf {_ _ _ _ _} _.*)
+Global Arguments TT {_ _ _}.
+Global Arguments Op {_ _ _ _ _} _ _.
+Global Arguments LetIn {_ _ _ _} _ {_} _.
+Global Arguments Pair {_ _ _ _} _ {_} _.
+Global Arguments Return {_ _ _ _} _.
+Global Arguments Abs {_ _ _ _ _} _.
+Global Arguments SmartAbs {_ _ _ _ _} _.
Global Arguments mapf_interp_flat_type {_ _ _} _ {t} _.
Global Arguments interp_type_gen_hetero {_} _ _ _.
Global Arguments interp_type_gen {_} _ _.
Global Arguments interp_flat_type {_} _ _.
-Global Arguments interp_type_rel_pointwise {_} _ _ {_} _ _.
-Global Arguments interp_type_gen_rel_pointwise {_ _} _ {_} _ _.
-Global Arguments interp_flat_type_rel_pointwise {_} _ _ {_} _ _.
Global Arguments interp_type {_} _ _.
-Global Arguments wff {_ _ _ _ _} G {t} _ _.
-Global Arguments wf {_ _ _ _ _} G {t} _ _.
-Global Arguments Wf {_ _ _ t} _.
+Global Arguments wff {_ _ _ _} G {t} _ _.
+Global Arguments wf {_ _ _ _} G {t} _ _.
+Global Arguments Wf {_ _ t} _.
Global Arguments Interp {_ _ _} interp_op {t} _.
Global Arguments interp {_ _ _} interp_op {t} _.
Global Arguments interpf {_ _ _} interp_op {t} _.
@@ -485,6 +346,7 @@ Section hetero_type.
Fixpoint flatten_flat_type {base_type_code} (t : flat_type (flat_type base_type_code)) : flat_type base_type_code
:= match t with
| Tbase T => T
+ | Unit => Unit
| Prod A B => Prod (@flatten_flat_type _ A) (@flatten_flat_type _ B)
end.
@@ -493,12 +355,13 @@ Section hetero_type.
Definition SmartFlatTypeMap2 {var' : base_type_code1 -> Type} (f : forall t, var' t -> flat_type base_type_code2) {t}
: interp_flat_type var' t -> flat_type base_type_code2
- := @smart_interp_flat_map base_type_code1 var' (fun _ => flat_type base_type_code2) f (fun _ _ => Prod) t.
+ := @smart_interp_flat_map base_type_code1 var' (fun _ => flat_type base_type_code2) f Unit (fun _ _ => Prod) t.
Fixpoint SmartFlatTypeMapInterp2 {var' var''} (f : forall t, var' t -> flat_type base_type_code2)
(fv : forall t v, interp_flat_type var'' (f t v)) t {struct t}
: forall v, interp_flat_type var'' (SmartFlatTypeMap2 f (t:=t) v)
:= match t return forall v, interp_flat_type var'' (SmartFlatTypeMap2 f (t:=t) v) with
| Tbase x => fv _
+ | Unit => fun v => v
| Prod A B => fun xy => (@SmartFlatTypeMapInterp2 _ _ f fv A (fst xy),
@SmartFlatTypeMapInterp2 _ _ f fv B (snd xy))
end.
@@ -510,6 +373,7 @@ Section hetero_type.
:= match t return forall v, interp_flat_type var'' (SmartFlatTypeMap2 f (t:=t) v)
-> interp_flat_type var''' t with
| Tbase x => fv _
+ | Unit => fun _ v => v
| Prod A B => fun v xy => (@SmartFlatTypeMapUnInterp2 _ _ _ f fv A _ (fst xy),
@SmartFlatTypeMapUnInterp2 _ _ _ f fv B _ (snd xy))
end.
@@ -521,11 +385,14 @@ Global Arguments SmartFlatTypeMapInterp2 {_ _ _ _ _} _ {_} _.
Global Arguments SmartFlatTypeMapUnInterp2 {_ _ _ _ _ _} fv {_ _} _.
Module Export Notations.
+ Notation "()" := (@Unit _) : ctype_scope.
Notation "A * B" := (@Prod _ A B) : ctype_scope.
Notation "A -> B" := (@Arrow _ A B) : ctype_scope.
Notation "'slet' x := A 'in' b" := (LetIn A (fun x => b)) : expr_scope.
Notation "'λ' x .. y , t" := (Abs (fun x => .. (Abs (fun y => t%expr)) ..)) : expr_scope.
Notation "( x , y , .. , z )" := (Pair .. (Pair x%expr y%expr) .. z%expr) : expr_scope.
+ Notation "( )" := TT : expr_scope.
+ Notation "()" := TT : expr_scope.
Bind Scope ctype_scope with flat_type.
Bind Scope ctype_scope with type.
End Notations.