Skip to content

Commit 66e41ed

Browse files
committed
rename tpi.lam, rm redundant one in misc
1 parent fd6ef2f commit 66e41ed

File tree

6 files changed

+114
-75
lines changed

6 files changed

+114
-75
lines changed

AIT.lhs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Size in bits of an expression, assuming no free variables
2121
> instance Encodeable DB where
2222
> encode z = prebin z "" where
2323
> prebin (DBVar 0) s = '1':'0':s
24-
> prebin (DBVar i) s | i>0 = '1':(prebin (DBVar (i-1)) s)
24+
> prebin (DBVar i) s | i>0 = '1':'1':(prebin (DBVar (i-1)) s)
2525
> prebin (DBVar _) _ = error "Negative de-Bruijn index"
2626
> prebin (DBLam e) s = '0':'0':(prebin e s)
2727
> prebin (DBApp x y) s = '0':'1':(prebin x (prebin y s))

BLC.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ \subsection{Functional Complexity}
722722
In the {\em simple} version, programs are terminated with
723723
$N=\Cnil$ and the result must equal $x$.
724724
In the {\em prefix} version, programs are terminated with unsolvable $\Omega$,
725-
and the result must $x$.
725+
and the result must equal $x$.
726726
In a former prefix definition, now considered unnecessarily complicated and renamed Kp, programs were not terminated,
727727
and the result had to equal the pair of $x$ and the remainder of the input.
728728
In all cases the complexity is conditional on zero or more terms $y_i$.

misc/pi.lam ait/pi.lam

+25-11
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,20 @@
1717
-- bn = b*n
1818
-- in go bn (a*n21+bn) (c*n21) (n+1)
1919

20+
-- related: tpi.hs and tuple_numerals.lam
21+
2022
\io. let
21-
id = \x. x;
22-
bit0 = \x0\x1. x0;
23-
bit1 = \x0\x1. x1;
24-
cons = \a\b\p. p a b;
25-
-- Church numerals
26-
C1 = id;
2723
Csucc = \n\f\x. f (n f x);
28-
Cadd = \a\b\f\x. a f (b f x);
29-
-- Tuple numerals
30-
-- Tm x (Tn y) = if n < m then y (Tm-1-n x) else x (Tn-m y)
31-
T1 = \x\f. f x;
3224
Tadd = \tm\tn\x. tm (tn x);
25+
id = \x. x;
26+
bit0 = \x\y. x;
27+
bit1 = \x\y. y;
3328
CTmul = \c\t. c t;
3429
Tsub = \tm\tn\x. tm id (tn x);
30+
Cadd = \a\b\f\x. a f (b f x);
31+
cons = \a\b\p. p a b;
3532

33+
-- 399+2 bits
3634
go = \Tb\Ta\Tc. let
3735
prod = \bit\Ta'\Cn. cons bit (go (Tadd Tb Tb) (Tadd Ta' Ta') Tc Cn) in
3836
(Tc (\_. prod bit1 (Tsub Tc Ta))) -- case Ta >= Tc
@@ -45,5 +43,21 @@
4543
(Ta (Tb (\_. prod bit0 Ta))) -- case Ta+Tb < Tc
4644
));
4745

46+
C1 = id;
47+
T1 = \x\f. f x;
4848
pi = go T1 T1 T1 C1;
49-
in pi
49+
50+
-- YOLO, 376+2 bits
51+
step = \cont\Tb\Ta\Tc\Cn.
52+
let
53+
x2np1 = CTmul (Csucc (Cadd Cn Cn));
54+
CnxTb = CTmul Cn Tb
55+
in cont CnxTb (x2np1 (Tadd Ta Tb)) (x2np1 Tc) (Csucc Cn);
56+
go_ = step (step (\Tb\Ta\Tc. let
57+
prod = \bit\Ta'\Cn. cons bit (go_ (Tadd Tb Tb) (Tadd Ta' Ta') Tc Cn) in
58+
(Tc (\_. prod bit1 (Tsub Tc Ta))) -- case Ta >= Tc
59+
(Ta (\_. prod bit0 Ta)))); -- case Ta < Tc
60+
T0 = \x. x;
61+
pi_probably = go_ T1 T0 T1 C1;
62+
in
63+
pi

ait/tpi.lam

-43
This file was deleted.

blc.pl

+85-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,87 @@
11
$z=pop=~/8/;
22

3-
sub bit2lam {my$c=pop;sub{my$x=pop;sub{$c?pop:$x}}}
4-
sub byte2lam {my($c,$x)=@_;sub{$x--?
5-
pop->(bit2lam(vec$c,$x,1))->(byte2lam($c,$x)):sub{pop}}}
6-
sub input {my$i=pop;sub{my$c;($B[$i]||=defined($c=getc)?sub{pop->($z?
7-
byte2lam($c,8):bit2lam($c))->(input($i+1))}:sub{sub{pop}})->(pop)}}
8-
9-
sub lam2bit {pop->(sub{0})->(sub{1})->()}
10-
sub lam2byte {my$x=pop;pop->(sub{$x=2*$x+lam2bit(pop);
11-
sub{my$r=pop;sub{lam2byte($r,$x)}}})->(chr$x)}
12-
sub output {pop->(sub{print($z?lam2byte(pop,0):lam2bit(pop));
13-
sub{my$r=pop;sub{output($r)}}})->("\n")}
14-
15-
sub getbit {$x||=($c=getc,$z?8:1);vec$c,--$x,1}
16-
sub program {if(getbit()){my$i;$i++while getbit();sub{$_[$i]}}
17-
elsif(getbit()){my$p=program();my$q=program();sub{my@bit2lam
18-
=@_;$p->(@bit2lam)->(sub{$q->(@bit2lam)->(pop)})}}else{my$p=
19-
program();sub{my@bit2lam=@_;sub{$p->(pop,@bit2lam)}}}}
20-
21-
$|=1; print output program()->()->(input(0))
3+
sub bit2lam {
4+
my $bit = pop;
5+
sub {
6+
my $x0 = pop;
7+
sub {
8+
my $x1 = pop;
9+
$bit ? $x1 : $x0
10+
}
11+
}
12+
}
13+
14+
sub byte2lam {
15+
my ($bits,$n) = @_;
16+
sub {
17+
$n-- ? pop->(bit2lam(vec$bits,$n,1))->(byte2lam($bits,$n)) # cons bitn bits>n
18+
: sub { pop } # nil
19+
}
20+
}
21+
22+
sub input {
23+
my $n = pop; # input from n'th character onward
24+
sub {
25+
my $c;
26+
($B[$n] ||= defined($c=getc) ?
27+
sub { pop->($z ? byte2lam($c,8) : bit2lam($c))->(input($n+1)) # cons charn chars>n
28+
} :
29+
sub { sub { pop } } # nil
30+
)->(pop)
31+
}
32+
}
33+
34+
sub lam2bit {
35+
pop->(sub{0})->(sub{1})->() # force suspension
36+
}
37+
38+
sub lam2byte {
39+
my $x = pop; # 2nd argument is partial byte
40+
pop->(sub {
41+
$x = 2*$x + lam2bit(pop);
42+
sub {
43+
my $tail = pop;
44+
sub { lam2byte($tail, $x) }
45+
}
46+
})->(chr $x) # end of byte
47+
}
48+
49+
sub output {
50+
pop->(sub { # more chars
51+
my $c = pop;
52+
print($z ? lam2byte($c,0) : lam2bit($c));
53+
sub {
54+
my $tail = pop;
55+
sub { output($tail) }
56+
}
57+
})->(0) # end of output
58+
}
59+
60+
sub getbit {
61+
$n ||= ($c = getc, $z?8:1);
62+
vec $c,--$n,1
63+
}
64+
65+
sub program {
66+
if (getbit()) { # variable
67+
my $i;
68+
$i++ while getbit();
69+
sub { $_[$i] }
70+
} elsif (getbit()) { # application
71+
my $p=program();
72+
my $q=program();
73+
sub {
74+
my @env = @_;
75+
$p->(@env)->(sub { $q->(@env)->(pop) }) # suspend argument
76+
}
77+
} else {
78+
my $p = program();
79+
sub {
80+
my @env = @_;
81+
sub { $p->(pop,@env) } # extend environment with one more argument
82+
}
83+
}
84+
}
85+
86+
$| = 1; # non zero value sets autoflush
87+
output program()->()->(input(0)) # run program with empty env on input

uni.c

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ u32 evac(u32 n) {
192192
if (y == 'K') {
193193
mem[n+1] = mem[x+1];
194194
x = mem[n] = 'I';
195+
} else if (y == 'F') {
196+
x = mem[n] = 'I';
195197
}
196198
y = mem[n + 1];
197199
if (!x) return y;

0 commit comments

Comments
 (0)