Lecture 10: Abstract Machines
Reminder:
cf. pictures
Notations:
: rewriting for code ( -calculus) : rewriting for abstract machines : search : substitute : well-formed and correctly -renamed
Code | Stack | Code | Stack | |
---|---|---|---|---|
-
-
terminates deterministic is final state then is normal
Micro Abstract Machine
Code | Environment | Code | Environment | |
---|---|---|---|---|
Ex: You may need two
Number of
Lemma: Let
be a Micro-AM reachable state.
Abs: if
is a subterm of or , then occurs only in Env scope:
then is fresh wrt and
So
Ex: Pay attention to renaming. Example of a mistake (we don’t rename in the second step):
So it reduces to
Milner Abstract Machines (MAM)
Simplified version of Krivine AM.
Code | Stack | Environment | Code | Stack | Environment | |
---|---|---|---|---|---|---|
TODO: write
Complexity analysis
Let
- Input: the size
of the initial term - Length:
- Number of machine transitions
- Cost of a single transition
- Combine the two
Code | Environment | Code | Environment | |
---|---|---|---|---|
Let
How do
The size of the environment is the number of
then, the
Therefore, if
then
where
So
Is this bound reached? Yes:
Subterm Invariant
The “equivalent” of the Hauptsatz in sequent calculus, or the subformula property.
Lemma (Subterm Invariant): Let
be an execution. Then and any code in and are subterms of the (up to )
Proof: The only subtle proof step:
This gives us a bound on the size of duplicated terms.
Recall
This lemma tells us: whenever
as in each step you can only duplicate subterms, then the size of
⟹ there’s no size explosion wrt the number of steps.
Warning: it could happen that the number of steps is itself exponential ⟹ we have to make sure that the number of transitions is reasonable (from
by the subterm invariant.
But
Recall that that AM take care of SEA(rch), SUB(stitution), and NAMES. But SEA is quadratic wrt to SUB ⟹ we can afford not to take it into account, it doesn’t impact much the complexity. NAMES impact even less the complexity.
Number of transitions | |
---|---|
SEA | |
SUB |
With pointers, the SEA and the
As for SUB: if we implement the environments as lists, you don’t have constant time access. But if variables are pointers, we can access the substituted term for
Therefore:
Number of transitions | Cost of single transition | Global cost | |
---|---|---|---|
SEA | |||
SUB |
Call-by-Value evaluation
We saw that there’s an efficient abstract machine to implement call-by-name evaluation. But reasonable cost models are not about finding such efficient machines.
But
Ex: Duplicator:
⟹ CBN seems to be silly (we duplicate work), but we just showed that it is reasonable.
Ex: Erasor:
⟹ CBV seems to be silly, but we can show that it is reasonable too.
Being reasonable has nothing to do with finding an efficient strategy. It means that the overhead is not too complex (polynomial) ⟹ relative efficiency.
But still, are there non reasonable strategies? Yes (there’s one example in the literature: Jean-Jacques Lévy’s one).
Is there an optimal strategy (that takes the least number of steps)? No, the optimal strategy is not recursive.
But even though it is not recursive, we can have a notion of parallel optimal strategy, which is recursive (shown by Lévy). But Lévy didn’t know how to implement it. It was done a few years later by someone else. Question that arose: can take
But it doesn’t make it useless for all that: just because it’s not reasonable doesn’t mean that it’s not efficient (hidden but wrong assumption: steps count as 1, i.e. there are reasonable). Nowadays, we still don’t know if it’s efficient or not.
Comparing the number of steps of strategies that are not reasonable doesn’t make sense.
Weak Call-by-Value (CBV) -calculus
NB: we consider only the weak version (we don’t reduce under
Harmony property: if
is closed, then
- either
- or
is a value (an abstraction)
Proof: by induction on
So if
- either
reduces to another term - or it diverges
NB: if we remove variables from values, nothing changes.
In theoretical papers, values are defined as
In papers about abstract machines (practical), values are defined as
⟹ Why nothing changes? Because a variable can never be arguments: the only way to have a subterm of the form
This is better than confluent, it has the diamond property:
⟹ we can always close the diagram in one step.
It fails when we’re allowed to duplicate redexes, as in
On top of that, all reduction sequences have the same length.
Right-to-left strategy (the only rule that changes):
So contexts are given by:
AM:
We can rewrite the last ones in the same fashion, where
Code | Environment | Code | Environment | |
---|---|---|---|---|
Leave a comment