Escolar Documentos
Profissional Documentos
Cultura Documentos
Reference Text
Logic and Structure. Dirk van Dalen. 1994,
Springer-Verlag. Pages 215.
1.
2.
3.
What we skipped:
Model theory of Classical Logic (most of 3)
Second Order Logic ( 4)
Model theory of Intuitionistic Logic (in 5)
Roughly speaking: Lessons 1,2,3,4 correspond to sections
1, 2, 3 and 4, 5 and 6
of Van Dalens textbook.
Roughly speaking (and on the long run): in these Course
Notes, one slide corresponds to one page of Van Dalens
book.
Lesson 1
Propositional Calculus
Syntax
Semantic
Proofs
Completeness
6
Plan of Lesson 1
We will quickly go through Syntax and Semantic of
Propositional Calculus again.
1.1 Syntax. The set of formulas of Propositional
Calculus.
1.2 Semantic. Truth tables, valuations, and tautologies.
We will really start the course from here:
1.3 Proofs. We introduce Natural Deduction
formalization of Propositional Calculus.
1.4 Completeness. We prove that logical rules prove
exactly all true propositions.
Forthcoming Lesson:
First Order Logic
1.1 Syntax
The symbol of the language.
Propositional symbols: p0, p1, p2,
Connectives: (and), (or), (not),
(implies), (is equivalent to), (false).
Parenthesis: (, ).
1.1 Syntax
2.
1.1 Syntax
Examples:
(p0)
((p0))
(p0 (p1 p2))
(p0 (p1 p2))
Correct expressions of Propositional Logic
are full of unnecessary parenthesis.
10
1.1 Syntax
Abbreviations. Let c=, , . We write
p0 c p1 c p2 c
in the place of
(p0 c (p1 c (p2 c )))
Thus, we write
p0 p1 p2,
in the place of
(p0 (p1 p2)),
p0p1 p2,
(p0 (p1 p2))
11
1.1 Syntax
We omit parenthesis whenever we may
restore them through operator precedence:
binds more strictly than , , and ,
bind more strictly than , .
Thus, we write:
p0
for ((p0)),
p0 p1
for ((p0 ) p1)
p0 p1 p2 for ((p0 p1) p2),
12
1.1 Syntax
1.1 Syntax
1.
2.
3.
Immediate Subformulas :
Of and pi
are
none
Of
is
Of (), ( ), (), ()
are
,
is a subformula of iff there is some chain =0, ,
n=, each formula being some immediate subformula
of the next formula.
Subformulas of =((p0 p1) p2) are:
itself, (p0 p1), p0, p1, p2.
14
1.2 Semantic
is always F (false).
, , , , are interpreted as unary or binary map
(or Truth Tables), computing the truth of a statement
, (), (), (), (),
given to the truth of immediate subformulas , .
15
1.2 Semantic
Truth table of .
=T
=F
=F =T
16
1.2 Semantic
Truth table of .
=T
=F
=T
= T
= F
= F
= F
= F
17
1.2 Semantic
=F
=T
= T
= T
= F
= T
= F
18
1.2 Semantic
=F
=T
= T
= T
= F
= F
= T
19
1.2 Semantic
=F
=T
=T
=F
=F
=F
=T
20
1.2 Semantic
Inductive definition. Fix any set I, any map v:NI, any
bI, and for any unary (binary) connective c, some unary
(binary) map Tc on I.
Then there is exactly one map h:PROPI, such that:
f(pi)
= v(i)
I
for all iN,
f() = b
I
f()
= T(f())
I
f( c )
= Tc(f(), f())
1.2 Semantic
1.
2.
22
1.2 Semantic
Let PROP.
Tautologies. is a tautology iff for all
valuations v we have []v =T.
Contradictions. is a contradiction iff for
all valuations v we have []v =F.
Tautology conveys our intuitive idea of
being logically true, or true no matter
what the Propositional constants are.
23
1.2 Semantic
1.3 Proofs
1.3 Proofs
1.3 Proofs
Natural
Deduction:
the
missing
connectives.
We treat
,
,
as abbreviating
(),
()(),
We do not add specific rules for the
connectives , .
27
1.3 Proofs
abbreviated by |- , for:
there is a proof of whose assumptions are included
in .
28
1.3 Proofs
Natural
Deduction:
crossing
assumptions.
we use the notation
, \
1.3 Proofs
r -------------------------------
are inductively defined as:
all assumptions of proofs of 1, 2, 3, ,
minus all assumptions we crossed.
30
1.3 Proofs
1.3 Proofs
Rules for
Introduction rules: none ( is always false).
Elimination rules: from the truth of (a
contradiction) we derive everything:
---
1.3 Proofs
Rules for
Introduction rules:
-------
If |- and |- then |-
33
1.3 Proofs
Elimination rules:
-------
------
If |- , then |- and |-
34
1.3 Proofs
Rules for
Introduction rules:
-------
------
If |- or |- , then |-
35
1.3 Proofs
Elimination rules:
-------------------------------------
1.3 Proofs
Rules for
Introduction rule:
-------
If , |- , then |-
We may drop any number of assumptions equal to
from the proof of .
37
1.3 Proofs
Elimination rule:
---------------
If |- and |- , then |- .
38
1.3 Proofs
--
If , |- , then |-
We may drop any number of assumptions equal to
from the proof of .
39
1.3 Proofs
1.
2.
1.4 Completeness
1.4 Completeness
Correctness. If |- is true in Natural
Deduction, then |- is valid.
Proof. Routine. By induction over the
proof of |-, considering:
1. one case for each introduction and
elimination rule,
2. one for the Identity rule,
3. one for Excluded middle.
42
1.4 Completeness
Proof.
We will pass through many Lemmas:
Lemma 1 (Consistency). If |- is not derivable, then
, is consistent.
Lemma 2 (Consistent Extension). For all formulas , if
is consistent, then either , or , is consistent.
43
1.4 Completeness
1.4 Completeness
45
1.4 Completeness
1.4 Completeness
47
1.4 Completeness
48
1.4 Completeness
1.4 Completeness
v( ) = F because |- is false, by
consistency of .
50
1.4 Completeness
v( ) = T v( )=T or v( )=T
Left-to-Right. Assume for contradiction
v()=F and v()=F. By Completeness of ,
|- and |- are true. By -Elim., we
have ,|- and ,|-. From |- (by
hyp.) and -Elimination we conclude |-,
against the consistency of .
Right-to-Left. If |- or |-, then |-
by -Introduction.
51
1.4 Completeness
52
1.4 Completeness
1.
2.
v( ) = T v( )=F or v( )=T
Left-to-Right: If v()=F, we are done. If v()=T, then
|-, and by -E |-, v()=T.
Right-to-Left. Assume either v()=F or v()=T, in
order to prove v()=T.
Case v( )=F. By completeness of , we have |-.
Then ,|- by -Elimination, and ,|- by Elimination. We conclude |- by -Introduction.
Case v( )=T. If |-, then |- by some Introduction crossing no assumptions .
53
1.4 Completeness
1.4 Completeness
55
Appendix to 1
56
Appendix to 1
Appendix to 1
Associativity of , :
( )
( )
Commutativity of , :
58
Appendix to 1
Distributivity of , :
( ) ( ) ( )
( ) ( ) ( )
De Morgans Laws:
( )
( )
59
Appendix to 1
Idempotency of , :
Characterizing Implication
()
Characterizing Equivalence
( )
() ()
60
Appendix to 1
Case [ ]v = True:
[ ]v
T(True, False)
Case [ ]v = False:
[ ]v
T(False, True)
= T(True, T(True)) =
= True.
= T(False, T(False)) =
= True.
61
Appendix to 1
1.
2.
3.
4.
5.
6.
7.
8.
9.
62
Appendix to 1
Appendix to 1
Appendix to 1
Axioms
Hilbert-style proofs
Appendix to 1
Appendix to 1
68
Lesson 2
Predicate Calculus.
Syntax
Semantic
Proofs
69
Plan of Lesson 2
2.1 Syntax. The set of formulas of First Order
Logic.
2.2 Semantic. Interpreting formulas of First
Order Logic.
2.3 Proofs. We introduce Natural Deduction
formalization of First Order Logic.
Previous Lesson:
Propositional Logic
Forthcoming Lesson: Completeness Theorem
70
71
2.1 Syntax
for all i, mN
72
2.1 Syntax
2.1 Syntax
for all nN
2.1 Syntax
2.1 Syntax
Examples of formulas:
(P(f(f(c))))
((P(g(x,y)) ))
((xP(x)) (P(y) P(z)))
(x(P(x) (P(y) P(z))))
Correct formulas require
parenthesis.
unnecessary
76
2.1 Syntax
Abbreviations. Let c=, , . We write
p0 c p1 c p2 c
in the place of
(p0 c (p1 c (p2 c )))
Besides, we write
xy, xyz
in the place of
(x(y)), (x(y(z)))
We also use x,y for xy.
77
2.1 Syntax
We omit parenthesis whenever we may restore them through
operator precedence:
, , bind more strictly than , , and , bind more
strictly than , .
Thus, we write:
P(a)
for
((P(a))),
P(a) Q(x,y)
for
((P(a)) Q(x,y))
xP(x) P(y) P(z)
for
((xP(x)) (P(y) P(z)))
xP(x)P(y)P(z)for
(((xP(x))P(y)) P(z))
78
2.1 Syntax
2.1 Syntax
3.
2.1 Syntax
2.1 Syntax
2.1 Syntax
2.1 Syntax
2.1 Syntax
2.1 Syntax
2.2 Semantic
Structure M for a first order language:
A universe M of M, not empty.
For each Predicate Symbols: P, Q, R, , of integer arity
n, n, n, , some predicates
PMMn,QMMn, RMMn,
interpreting P, Q, R, .
For each Function Symbols: f, g, h, , of integer
arity m, m, m, some functions
fM MnM,gM MnM, hM MnM,
interpreting f, g, h, .
87
2.2 Semantic
Equality. Interpretation =M of the equality
name should be the equality predicate.
This condition may be weakened to: =M is
some equivalence relation compatible with
all predicate and functions of M.
In this case, we obtain a structure by taking
the quotient M/=M.
Constants, i.e., names c of functions of arity
0, are interpreted by cMM.
88
2.2 Semantic
Interpreting terms. Let M be any model. Every
map v:{0,1,2,}M may be extended to some
map
[.]v, M:TERMSM
If M is fixed, we abbreviate [.]v, M by [.]v.
We define [.]v,M by induction over the definition
of a term.
[xi]v
= v(i)
M
[f(t1,, tm)] v, M = fM([t1]v,, [tn]v) M
89
2.2 Semantic
90
2.2 Semantic
1. v[xi:=m](j)
2. v[xi:=m](j)
=m
= v(j)
if i=j
if ij
91
2.2 Semantic
Let M be any model. We extended every map v:
{variables}M to some map
[.]v, M : ATOMS {True, False},
We will now extend [.]v, M to some map
[.]v, M : FORMULAS {True,False},
by induction over the definition of a formula.
We distinguish several cases, according if the
outermost connective of is
, , , , , ,
92
2.2 Semantic
Let Tc be the truth table of c=,,,,.
[]v,M = T([]v,M)
for c=,,,:
[ c ] v,M
= Tc([]vM,[]v,M),
[x]v
[x]v
[x]v
[x]v
93
2.2 Semantic
94
2.2 Semantic
Substitution Theorem.
Substitution on is interpreted by substitution on the
valuation map v.
Let m=[t]v,M:
[[x:=t]]v,M = []v[x:=m],M ,
2.2 Semantic
96
2.3 Proofs
1.
2.
3.
1.
2.
2.3 Proofs
[x:=t]
--------x
2.3 Proofs
---------------
Provided x FV( , ).
99
2.3 Proofs
-----x
Provided x FV( )
If |- and x FV( ), then |- x
100
2.3 Proofs
x
--------[x:=t]
2.3 Proofs
2.3 Proofs
t=u
----u=t
----t=t
t1=u1
t=u u=v
-----------t=v
tn=un
-------------------------f(t1,,tn)=f(u1,,un)
103
2.3 Proofs
t1=u1
tn=un
P(t1,,tn)
----------------------------------------P(u1,,un)
By induction on , we deduce:
t1=u1
tn=un
[x1:=t1,, x1:=tn]
---------------------------------------------------[x1:=u1,, x1:=un]
104
2.3 Proofs
Mathematical Theories T are identified with sets
of axioms T.
is a theorem of T iff T|-.
An example: First Order Arithmetic PA has
language L={0, succ, <}.
PA is introduced adding axioms characterizing
successor, plus, for every formula , the
Induction Axiom for :
x.([x:=0]x([x:=x+1]))
105
2.3 Proofs
An exercise for the next Lesson: derive, for z not
free nor bound in ,
z(x[x:=z])
there is some z such that:
if (x) is true for some x, then (z)
Hint: prove first x|-Thesis and x|-Thesis.
Then conclude |-Thesis out of |- xx and
-Elimination.
106
Appendix to 2
Proof of Th= z( x [x:=z]).
As suggested, we are going to prove both
x|-Th and x|-Th, then conclude Th
out of |- xx and -Elimination.
By renaming z with x, we may replace Th
by Th = x(x) in the proof:
Th and Th are convertible, hence they may
be identified.
107
Appendix to 2
4.
x |-Th.
|-
|-x
|-x(x)
xFV(Th)
x|-x
x|-x(x)
by Id. Princ..
by 1 and -I
by 2 and -I
x is bound in Th.
by Id. Princ.
by 3, 4, 5 and -E
108
Appendix to 2
Proof of x |-Th.
x |- x
x |- x
x, x|-
x, x|-
x |-x
x |- x(x)
by id. princ.
by id. princ.
by 1,2, and-E
by 3 and -E
by 4 and -I
by 5 and -I
109
Lesson 3
Validity Theorem
Gdel Completeness Theorem
110
Plan of Lesson 3
111
114
3.1 -Introduction
preserves Validity
1. Assume []v,M{True}.
2. From |-[x:=t] valid and 1 we obtain:
[[x:=t]]v,M=True.
3. Set m=[t]v,MM.
4. By Substitution Theorem and 3:
[[x:=t]]v,M= []v[x:=m],M.
5. By 2, 4, we deduce []v[x:=m],M =True.
6. By 5, we deduce [x]v,M= True.
116
3.1 -Elimination
preserves Validity
3.1 -Elimination
preserves Validity
1.
2.
1.
2.
3.
4.
5.
Assume []v,M{True}.
By 1 and |-x valid, we deduce [x]v,M= True, that
is:
[]v[x:=m ],M = True, for some mM
By x FV( ), Sub.Thm: []v[x:=m],M = []v,M
By 1, 3 we deduce []v[x:=m],M {True}
By ,|- valid, and 2, 4, we deduce []v[x:=m],M= True.
By x FV( ), Sub.Thm: []v[x:=m],M= []v,M.
By 5, 6, we conclude []v,M=True.
118
3.2 Completeness
1.
2.
3.
128
131
By construction, = is interpreted in M by
provable equality in .
Provable equality is closed under equality rules,
therefore is an equivalence relation on M,
compatible with all functions and predicates of
L.
We will now prove that []v,M[]v,M=
{True}, or that M is a model of .
132
1.
2.
135
|- v(x) M|=v x
|- v(x)
(Identity a)
|- xv[x:=x]()
( Henkin)
for some closed term t:
|-v[x:=x][x:=t]()
(Identity b)
5. for some closed term t:
|-v[x:=t]()
(Ind.Hyp.)
6. for some closed term t:
M|=v[x:=t]
(def. of|=)
1.
2.
3.
7.
M|=v x
136
|- v(x) M|=v x
|- v(x)
|- xv[x:=x]()
for all closed term t:
|-v[x:=x][x:=t]()
5. for all closed term t:
|-v[x:=t]()
6. for all closed term t:
M|=v[x:=t]
1.
2.
3.
7.
(Identity a)
( Henkin)
(Identity b)
(Ind.Hyp.)
(def. of|=)
M|=v x
137
(w(v()))=v())
|-w(v())
(point 1)
[v()]w,M = True
138
139
we conclude
[]s,M {True}
140
Lesson 4
Intuitionistic Logic
Strong Normalization
Normal Forms
142
Plan of Lesson 4
Completeness Theorem
none.
143
147
149
4.2 Normalization
For all connectives c, every c-Elimination is
justified by the corresponding cIntroduction in the following sense:
If we have some c-I followed by some c-E,
we may derive the conclusion of c-E just
by combining in some suitable way the
premises of c-I.
We call any c-I followed by a c-E a c-Cut.
152
4.2 Normalization
Any c-Cut is, conceptually, a redundant step in
the proof, and it may be removed (often, at the
price of expanding the proof size considerably).
For any c-Cut we define an operation removing it
we call a c-reduction.
Removing a c-Cut may generated new Cuts.
Yet, we will prove that if we repeatedly remove
cuts in any order, eventually we get a (unique)
proof without cuts.
153
4.2 Normalization
We call Normal any proof without Cuts, and
Normalization the process removing all cuts (in
any order).
After Normalization, Intuitionistic Proofs satisfy
Heyting Interpretation.
Thus, normalizing an intuitionistic proof of is a
way of interpreting the truth of as a program of
specification .
We will now define some c-reduction for all c.
154
D2
2
Di
i
--------12
--------i
155
1\
D
i
E1
E2
Ei
-------------------------------
156
-------E
------------------
157
-----x
--------[x:=t]
D[x:=t]
[x:=t]
158
-------E
x
-----------------
D
[x:=t]
E[x:=t]
159
|-E:
161
162
1.
2.
1.
2.
164
4.2 Computability
In the strong normalization proof, we will actually
prove a notion of computability for a proof D,
implying Strong Normalization.
Definition of Computable proof: by induction over the
proof D.
D does not end with an Introduction. D is computable
iff all D1E are computable.
D ends with an ,,-Introduction. D is computable
iff all its premises are.
D ends with an , -Introduction:
next two pages
165
-----x
is computable iff for all tTERM,
D[x:=t]
[x:=t]
is computable
166
------
is computable iff for all computable E,
is computable.
167
169
The proof
-----x
is computable iff for all tTERM,
D[x:=t]
[x:=t]
-----x
is strongly normalizable.
172
------
is computable iff for all computable E,
173
D
strongly normalizes. Thus,also
------
strongly normalizes.
174
The proof
-----x
is computable iff for all tTERM,
D[x:=t]
[x:=t]
E[x:=t]
[x:=t]
-----x
is computable.
177
------
is computable iff for all computable E,
178
E
is computable. Thus, also
is computable.
------
179
4.2 Computable
by Substitution and Replacing
Definition. Assume |-D:, =1,,n, and
FV(,){x1,.,xm}. D is computable by
substitution and replacing iff for all substitutions
s(.)=(.)[x1:=t1,.,xm:=tm], for all computable
proofs p|-D1:s(i), , p|-Dn:s(n), the proof
D1
is computable
Dn
s(1) s(n)
s(D)
s()
180
181
D1
Dn
s(1) s(n)
s(D)
s()
----x
--------[x:=t]
184
reduces to
D1
Dn
s(1) s(n)
s(D)
s()[x:=t]
Dn
1[x:=t, x:=t] n[x:=t, x:=t]
D [x:=t, x:=t]
[x:=t, x:=t]
is computable for all sub. [x:=t, x:=t] on D.
187
D1
Dn
1[x:=t] n[x:=t]
(D[x:=t])[x:=t]
([x:=t])[x:=t]
is computable for all terms t, and all computable:
D1
Dn
1[x:=t], , n[x:=t]
189
Assume
D1
Dn
Then
D1
Dn
4.3 Structure of
Normal Forms
Lemma (Main Branch).
1. All Elimination rules have a non-atomic main
premise, and discharge no assumptions on the
branch main premise.
2. All main branches either include some cut, or,
from top to bottom, include first only elimination
rules, then only atomic rules, eventually only
introduction rules.
3. All Main Branches ending with an Elimination
rule include either some cut, or some free
assumption, or end with an introduction.
195
4.3 Proof of
Main Branch Lemma
1.
2.
4.3 Proof of
Main Branch Lemma
4.3 Proof of
Main Branch Lemma
3. If a main branch include no cuts, then all
Introductions are at the end of the branch.
If the last rule is not an Introduction, then
there are no Introductions at all, only
Eliminations and atomic rules. In this
case no formula is discharged when we
are going up the main branch. Thus, the
uppermost formula of the branch is a free
assumption.
198
199
200
204
205
206
Realizability: Extracting
Programs from proofs
Summer School on Proofs as Programs
2002 Eugene (Oregon)
Stefano Berardi Universit di Torino
stefano@di.unito.it
http://www.di.unito.it/~stefano
207
209
Reference Text
L. Boerio Optimizing Programs Extracted
from Proofs. Ph. D. Thesis, C. S. Dept.
Turin University, 1997.
Available in the web page of the course:
http://www.di.unito.it/~stefano
(look for the first line in the topic:
TEACHING)
210
Lesson 5
Realization Interpretation
A Model of Realizers
Harrop Formulas
211
Plan of Lesson 5
5.1 Realization
5.2 A Model of Realizers
5.2 Harrop Formulas.
212
216
1.
2.
3.
4.
5.
6.
219
220
Rules for
Introduction rules:
s1: s2:
------------------<s1,s2>:
Elimination rules:
s:
--------- 1(s):
s:
--------- 2(s):
then |- <T,r,_>:
then |- <F,_,s>:
227
<i,a,b>: s():
t():
---------------------------------------------u:
228
s():
------------------- .s():
Elimination rule:
r:
s:
------------------------r(s):
If |-r: and |-s: , then |-r(s): .
230
r: [x:=t]
------------------<t,r>: xT.
, :
<i,a>: xT.
t(x,):
----------------------------------t(i,a):
Provided x FV( , ).
If |-<i,a>: x T. , ,: |-t(x,): , and x FV( , ),
then |- t(i,a):
232
r:
----------------x.r:xT.
Provided x FV( )
If |- r: and x FV( ), then |- x.r:x T.
233
f:xT.
--------------f(t):[x:=t]
236
1.
2.
3.
4.
5.
6.
1.
2.
3.
1.
2.
240
242
5.3 Characterizing
Harrop Formulas
247
Appendix to 5: an example
248
Appendix to 5: an example
249
Appendix to 5: an example
Appendix to 5: an example
Appendix to 5: an example
Appendix to 5: an example
Appendix to 5: an example
254
Appendix to 5: an example
255
Appendix to 5: an example
sort(l)=recL(l,<nil,_,_>, x:N,m:L.ins(m,x,_))
: LUnitUnit
The map ins:LUnit(NLUnitUnit) takes some
sorted list m, and returns some map ins(m), inserting
any integer x in m, and preserving the ordering of m:
ins(m) = _:Unit. recL(m,
x:N. <x*nil,_,_>
y:N, f:NLH, x:N.
if(1(less(x,y)),x*f(y),y*f(x))
):NLUnitUnit
256
Lesson 6
Program Extraction from proofs
Useless Code Analysis
257
Plan of Lesson 6
6.1 Useless Code. In Program Extraction.
6.2 Useless Code Analysis.
Previous Lesson: Realization Interpretation.
Next Lesson: none.
258
259
6.1 Example 0
A particular case of Useless Code: Dead code. A
subterm t is dead code if, whatever the input values
are, there is an evaluation strategy not evaluating t.
A trivial example: 3 is dead code (never used) in
(x.5)(3).
Usually, it is not so easy to detect dead code! It is
even a non-recursive problem.
Indeed, to decide whether b is dead code in
if(h(x)=0,a,b) we have to decide whether h(x)=0 for
all x, or not, and this is a non-recursive problem.
266
6.1 Example 1
Let p a program of input x, of type A or B or C.
Let q be a program feeding such an x, but with possible
types only A, B. Compose p with q.
Consider any case analysis in p over the type of the
input x. There are three clauses, according if the type of
x is A or B or C.
The C clause is now dead code: it is never used
Such situation may happen if we extract a program from
a proof having a Lemma slightly more general than
required: we prove , then we apply it to
(instead of ).
267
6.1 Example 1
268
6.1 Example 2
The most general case of Useless code is a
code never affecting the final result, even if
it may be used for some inputs.
Let h(n,a,b) = <an,bn>:AB be recursively
defined by:
<a0, b0>
= <a, b>
: AB
<ai+1,bi+1>
= <f(ai), g(bi)> : AB
Define k(n) = (left component of h(n)) :A.
269
6.1 Example 2
Look to the computation of k(n):
<a,b>, <f(a),g(b)>, <f(f(a)),g((b))>, ..., <fn(a),gn(b)>
Eventually we trash gn(a) and we return an=fn(a).
g, b are dead code in k (they are never used, under a
suitable evaluation strategy).
The pairing operation <_,_> is useless code in k: it is
indeed used, however, it never affects the final result
an=fn(a).
Again, this situation may arise in a Realizer if we proved a
Lemma having a goal slightly more general than required.
270
6.1 Example 3
Let length(L) be a function taking a list L,
then returning the length n of it.
Look at the computation of length(L).
L = cons(x1,cons(x2,...cons(xn)...)), but the
actual values of x1, x2,... xn do not matter.
Eventually, we trash all xis, and we return
the number of conss.
271
6.1 Example 3
All elements of L are now useless code in f.
We compute the elements of L, using an
unpredictable amount of time; yet, we do not
use them in order to compute length(L).
This situation may arise in a Realizer when:
we first prove the existence of L, then, in the
rest of the proof, we only use the number of
elements of L.
272
6.2 log*(n)
1.
2.
3.
4.
5.
6.2 References
Type-bases useless code elimination for
functional programs (Position Paper), by
S. Berardi, M. Coppo, F. Damiani and P.
Giannini, to appear on proceeding of SAIG
conference on functional programming.
Automatic Useless code detection and
elimination
for
HOT
functional
programs, by F. Damiani, P. Giannini,
J.F.P. 10 (6): 509-559, 2000.
285