Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mpri2.4public
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
POTTIER Francois
mpri2.4public
Commits
9a1309c5
Commit
9a1309c5
authored
Dec 22, 2017
by
POTTIER Francois
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A Coq solution for part 1 of the midterm exam.
parent
6055421b
Changes
2
Hide whitespace changes
Inline
Sidebyside
Showing
2 changed files
with
242 additions
and
14 deletions
+242
14
README.md
README.md
+15
14
LambdaCalculusEncodingCBNIntoCBV.v
coq/LambdaCalculusEncodingCBNIntoCBV.v
+227
0
No files found.
README.md
View file @
9a1309c5
...
@@ 173,31 +173,32 @@ Although the course has changed, you may still have a look at previous exams
...
@@ 173,31 +173,32 @@ Although the course has changed, you may still have a look at previous exams
available with solutions:
available with solutions:

midterm exam 20172018:

midterm exam 20172018:
[
Callbyname. Extensible records
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20172018.pdf
)
[
Encoding callbyname into callbyvalue; extensible records
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20172018.pdf
)
(
[
Coq solution of part 1
](
coq/LambdaCalculusEncodingCBNIntoCBV.v
)
).

midterm exam 20162017:

midterm exam 20162017:
[
Record concatenation
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20162017.pdf
)
[
Record concatenation
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20162017.pdf
)
.

midterm exam 20152016:

midterm exam 20152016:
[
Type containment
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20152016.pdf
)
[
Type containment
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20152016.pdf
)
.

final exam 20142015:
[
Copatterns
](
http://gallium.inria.fr/~remy/mpri/exams/final20142015.pdf
)

final exam 20142015:
[
Copatterns
](
http://gallium.inria.fr/~remy/mpri/exams/final20142015.pdf
)
.

midterm exam 20142015:

midterm exam 20142015:
[
Information flow
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20142015.pdf
)
[
Information flow
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20142015.pdf
)
.

final exam 20132014:

final exam 20132014:
[
Operation on records
](
http://gallium.inria.fr/~remy/mpri/exams/final20132014.pdf
)
[
Operations on records
](
http://gallium.inria.fr/~remy/mpri/exams/final20132014.pdf
)
.

midterm exam 20132014:

midterm exam 20132014:
[
Typechecking Effects
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20132014.pdf
)
[
Typechecking effects
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20132014.pdf
)
.

final exam 20122013:

final exam 20122013:
[
Refinement types
](
http://gallium.inria.fr/~remy/mpri/exams/final20122013.pdf
)
[
Refinement types
](
http://gallium.inria.fr/~remy/mpri/exams/final20122013.pdf
)
.

midterm exam 20122013:

midterm exam 20122013:
[
Variations on ML
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20122013.pdf
)
[
Variations on ML
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20122013.pdf
)
.

final exam 20112012:

final exam 20112012:
[
Intersection types
](
http://gallium.inria.fr/~remy/mpri/exams/final20112012.pdf
)
[
Intersection types
](
http://gallium.inria.fr/~remy/mpri/exams/final20112012.pdf
)
.

midterm exam 20112012:

midterm exam 20112012:
[
Parametricity
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20112012.pdf
)
[
Parametricity
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20112012.pdf
)
.

final exam 20102011:

final exam 20102011:
[
Compiling a language with subtyping
](
http://gallium.inria.fr/~xleroy/mpri/24/exam20102011.pdf
)
[
Compiling a language with subtyping
](
http://gallium.inria.fr/~xleroy/mpri/24/exam20102011.pdf
)
.

midterm exam 20102011:

midterm exam 20102011:
[
Compilation
[
Compilation of polymorphic records
](
http://gallium.inria.fr/~remy/mpri/exams/partiel20102011.pdf
)
.
of polymorphic records](http://gallium.inria.fr/~remy/mpri/exams/partiel20102011.pdf)
## Recommended software
## Recommended software
...
...
coq/LambdaCalculusEncodingCBNIntoCBV.v
0 → 100644
View file @
9a1309c5
Require
Import
MyTactics
.
Require
Import
Sequences
.
Require
Import
LambdaCalculusSyntax
.
Require
Import
LambdaCalculusValues
.
Require
Import
LambdaCalculusFreeVars
.
Require
Import
LambdaCalculusReduction
.
(
*
This
file
defines
an
encoding
of
call

by

name
into
call

by

value
.
This
is
a
simple
encoding
,
based
on
two
combinators
[
delay
]
and
[
force
]
.
[
delay
]
is
implemented
as
a
function
which
ignores
its
argument
,
and
[
force
]
as
a
function
call
with
a
dummy
actual
argument
.
The
proof
of
semantic
preservation
involves
parallel
call

by

value
reduction
.
*
)
(
*

*
)
(
*
To
delay
the
evaluation
of
[
t
]
,
we
wrap
it
in
a
function
which
ignores
its
argument
.
*
)
Definition
delay
t
:=
Lam
(
lift
1
t
)
.
(
*
To
force
the
evaluation
of
a
thunk
(
a
delayed
computation
)
,
we
apply
it
to
a
dummy
actual
argument
.
*
)
Definition
dummy
:=
Lam
(
Var
0
)
.
Definition
force
t
:=
App
t
dummy
.
(
*
The
key
property
that
is
expected
of
[
force
]
and
[
delay
]
is
of
course
that
[
force
(
delay
t
)]
reduces
to
[
t
]
under
call

by

value
reduction
.
*
)
Lemma
force_delay
:
forall
t
,
cbv
(
force
(
delay
t
))
t
.
Proof
.
intros
.
unfold
force
,
delay
.
econstructor
;
obvious
.
autosubst
.
Qed
.
(
*
Obviously
,
[
delay
]
and
[
force
]
commute
with
substitutions
.
*
)
Lemma
delay_subst
:
forall
t
sigma
,
(
delay
t
)
.
[
sigma
]
=
delay
t
.
[
sigma
]
.
Proof
.
unfold
delay
.
intros
.
autosubst
.
Qed
.
Lemma
force_subst
:
forall
t
sigma
,
(
force
t
)
.
[
sigma
]
=
force
t
.
[
sigma
]
.
Proof
.
unfold
force
.
intros
.
autosubst
.
Qed
.
(
*
Finally
,
although
ordinary
reduction
under
[
delay
is
not
permitted
,
parallel
reduction
under
[
delay
]
is
permitted
.
*
)
Lemma
pcbv_delay
:
forall
t1
t2
,
pcbv
t1
t2
>
pcbv
(
delay
t1
)
(
delay
t2
)
.
Proof
.
unfold
delay
.
intros
.
econstructor
;
eauto
using
red_subst
with
obvious
.
Qed
.
Local
Hint
Resolve
pcbv_delay
:
obvious
.
(
*
That
is
all
we
need
to
know
about
[
force
]
and
[
delay
]
.
We
now
make
them
opaque
,
so
as
to
prevent
their
unfolding
during
the
proofs
that
follow
.
*
)
Opaque
force
delay
.
(
*

*
)
(
*
This
is
the
encoding
of
call

by

name
into
call

by

value
.
It
is
simple
:
in
short
,
in
every
application
,
the
actual
argument
is
wrapped
in
a
[
delay
]
;
accordingly
,
every
use
of
a
variable
involves
a
[
force
]
.
*
)
Fixpoint
encode
(
t
:
term
)
:=
match
t
with

Var
x
=>
force
(
Var
x
)

Lam
t
=>
Lam
(
encode
t
)

App
t1
t2
=>
App
(
encode
t1
)
(
delay
(
encode
t2
))

Let
t1
t2
=>
Let
(
delay
(
encode
t1
))
(
encode
t2
)
end
.
(
*

*
)
(
*
A
naive
attempt
at
a
simulation
diagram
,
which
(
if
it
were
true
)
would
imply
semantic
preservation
.
*
)
Lemma
encode_simulation
:
forall
t1
t2
,
cbn
t1
t2
>
cbv
(
encode
t1
)
(
encode
t2
)
.
Proof
.
induction
1
;
intros
;
subst
;
simpl
;
try
solve
[
tauto
]
.
(
*
Beta
*
)
{
econstructor
;
eauto
.
(
*
This
fails
because
[
encode
]
does
not
quite
commute
with
substitution
.
The
intuition
is
,
it
almost
commutes
,
but
this
introduces
[
force
/
delay
]
pairs
.
*
)
Abort
.
(
*

*
)
(
*
[
encode
]
commutes
with
renamings
.
*
)
Lemma
encode_renaming
:
forall
t
sigma
,
is_ren
sigma
>
(
encode
t
)
.
[
sigma
]
=
encode
t
.
[
sigma
]
.
Proof
.
induction
t
;
intros
;
asimpl
;
repeat
rewrite
delay_subst
;
repeat
f_equal
;
obvious
.
(
*
Var
*
)
{
pick
is_ren
invert
.
reflexivity
.
}
Qed
.
Lemma
encode_lift
:
forall
t
k
,
lift
k
(
encode
t
)
=
encode
(
lift
k
t
)
.
Proof
.
eauto
using
encode_renaming
with
obvious
.
Qed
.
(
*

*
)
(
*
In
order
to
express
the
fact
that
[
encode
]
commutes
with
substitutions
,
we
define
the
following
relation
between
substitutions
.
*
)
(
*
[
sigma1
]
is
a
target

level
substitution
,
intended
to
be
applied
after
[
encode
]
,
whereas
[
sigma2
]
is
a
source

level
substitution
,
intended
to
be
applied
before
[
encode
]
.
*
)
(
*
Because
[
sigma1
]
typically
maps
variables
to
terms
that
have
a
[
delay
]
at
the
root
,
we
allow
[
force
(
sigma1
x
)]
to
reduce
to
[
encode
(
sigma2
x
)]
.
We
use
parallel
reduction
[
pcbv
]
,
even
though
we
could
perhaps
use
a
slightly
more
precise
relation
at
this
point
(
such
as
"at most one step
of [cbv]"
)
because
it
is
convenient
and
[
pcbv
]
must
be
used
in
the
conclusion
of
the
lemma
[
encode_subst
]
anyway
.
*
)
Local
Definition
related
(
sigma1
sigma2
:
var
>
term
)
:=
forall
x
,
pcbv
(
force
(
sigma1
x
))
(
encode
(
sigma2
x
))
.
(
*
This
relation
is
preserved
by
[
up
]
.
*
)
Local
Lemma
up_related
:
forall
sigma1
sigma2
,
related
sigma1
sigma2
>
related
(
up
sigma1
)
(
up
sigma2
)
.
Proof
.
unfold
related
.
intros
.
destruct
x
as
[

x
]
;
asimpl
.
(
*
Variable
0.
This
case
goes
through
because
[
pcbv
]
is
reflexive
.
*
)
{
eapply
red_refl
;
obvious
.
}
(
*
Variables
above
0.
This
case
goes
through
because
[
force
]
,
[
encode
]
and
[
pcbv
]
are
compatible
with
[
lift
1
]
.
*
)
{
rewrite
<
force_subst
.
rewrite
<
encode_lift
.
eapply
red_subst
;
obvious
.
}
Qed
.
Local
Hint
Resolve
up_related
:
obvious
.
(
*
[
encode
]
commutes
with
substitutions
in
the
following
sense
.
*
)
Local
Lemma
encode_subst
:
forall
t
sigma1
sigma2
,
related
sigma1
sigma2
>
pcbv
(
encode
t
)
.
[
sigma1
]
(
encode
t
.
[
sigma2
])
.
Proof
.
induction
t
;
simpl
;
intros
;
subst
;
repeat
rewrite
force_subst
;
repeat
rewrite
delay_subst
;
eauto
6
with
obvious
.
Qed
.
(
*
We
obtain
the
following
corollary
for
singleton
substitutions
.
*
)
Local
Lemma
encode_subst_singleton
:
forall
t1
t2
,
pcbv
(
encode
t1
)
.
[
delay
(
encode
t2
)
/
]
(
encode
t1
.
[
t2
/
])
.
Proof
.
intros
.
eapply
encode_subst
.
intros
[

x
]
;
asimpl
.
(
*
Variable
0.
This
case
goes
through
by
[
force_delay
]
.
*
)
{
eauto
using
cbv_subset_pcbv
,
force_delay
.
}
(
*
Variables
above
0.
This
case
goes
through
because
[
pcbv
]
is
reflexive
.
*
)
{
eapply
red_refl
;
obvious
.
}
Qed
.
(
*

*
)
(
*
Equipped
with
the
previous
substitution
lemma
,
it
is
straightforward
to
establish
the
following
simulation
diagram
:
if
[
t1
]
steps
to
[
t2
]
under
call

by

name
reduction
,
then
[
encode
t1
]
steps
to
[
encode
t2
]
in
at
least
one
step
of
parallel
call

by

value
reduction
.
*
)
Lemma
encode_simulation
:
forall
t1
t2
,
cbn
t1
t2
>
plus
pcbv
(
encode
t1
)
(
encode
t2
)
.
Proof
.
induction
1
;
simpl
;
intros
;
subst
;
try
solve
[
tauto
]
.
(
*
Beta
.
Two
steps
of
reduction
are
required
.
*
)
{
econstructor
.
{
eauto
using
cbv_subset_pcbv
with
obvious
.
}
econstructor
.
{
eauto
using
encode_subst_singleton
.
}
finished
.
eauto
.
}
(
*
Let
.
Two
steps
of
reduction
are
required
.
*
)
{
econstructor
.
{
eauto
using
cbv_subset_pcbv
with
obvious
.
}
econstructor
.
{
eauto
using
encode_subst_singleton
.
}
finished
.
eauto
.
}
(
*
AppL
.
Just
perform
reduction
under
a
context
.
*
)
{
obvious
.
}
Qed
.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment