-
Notifications
You must be signed in to change notification settings - Fork 0
/
eq.p
371 lines (354 loc) · 8.67 KB
/
eq.p
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
program g (input,output);
{$R+}
var i,j,k,t,n,chib : integer;
fout,expan : boolean;
s : string;
f : array[1..3,0..9,1..25] of byte;
len,len2,len3 : array[1..3,0..9] of integer;
tau : array[1..2,0..9] of byte;
ff : array[1..3,1..1000] of byte;
hib : array[1..3] of integer;
p : array[0..9] of integer;
dim : array[1..2] of integer;
rate : array[1..2] of real;
a : array[1..2,0..9,0..9] of integer;
c : array[1..2,1..10,1..50] of byte;
ck : array[1..10,0..50] of boolean;
lenc : array[1..10] of integer;
procedure pp(m,ss,tt : integer);
var i,j : integer;
begin
hib[tt] := 0;
for i := 1 to hib[ss] do
for j := 1 to len[m,ff[ss,i]] do
if hib[tt] < 1000 then
begin
if m = 2 then
if ff[ss,i] > 0 then
if p[ff[ss,i]] = 0 then p[ff[ss,i]] := hib[tt];
hib[tt] := hib[tt]+1;
ff[tt,hib[tt]] := f[m,ff[ss,i],j];
end;
end;
function comprate(i:integer):real;
var j,k,m : integer;
t : real;
b : array[0..9,0..9] of real;
r : array[8..9] of real;
begin
b[0,0] := 1;
for j := 1 to dim[i]-1 do b[0,j] := 0;
for m := 1 to 9 do
for j := 0 to dim[i]-1 do
begin
b[m,j] := 0;
for k := 0 to dim[i]-1 do b[m,j] := b[m,j]+b[m-1,k]*a[i,k,j];
end;
for j := 8 to 9 do
begin
t := 0;
for k := 0 to dim[i]-1 do t := t+b[j,k];
r[j] := t;
end;
comprate := r[9]/r[8];
end;
procedure build(i:integer);
begin
hib[i] := 1;
ff[i,1] := 0;
pp(i,i,3);
pp(i,3,i);
pp(i,i,3);
pp(i,3,i);
pp(i,i,3);pp(i,3,i);
end;
procedure expand(i,q:integer);
var c : char;
j,k,m,mm : integer;
hib : array[0..9] of integer;
t : array[0..9,1..50] of byte;
begin
expan := true;
if i=1 then c := 'f' else c := 'g';
writeln('Replace ',c,' by ',c,'^',q,':');
for j := 0 to dim[i]-1 do
begin
write(c,'(',j,') = ');
hib[j] := 0;
for k := 1 to len[i,j] do
for m := 1 to len[i,f[i,j,k]] do
if q = 2 then
begin hib[j] := hib[j]+1; t[j,hib[j]] := f[i,f[i,j,k],m]; write(t[j,hib[j]]); end
else
for mm := 1 to len[i,f[i,f[i,j,k],m]] do
begin hib[j] := hib[j]+1; t[j,hib[j]] := f[i,f[i,f[i,j,k],m],mm]; write(t[j,hib[j]]); end;
writeln;
end;
for j := 0 to dim[i]-1 do
begin
len[i,j] := hib[j];
for k := 1 to len[i,j] do f[i,j,k] := t[j,k];
end;
if i = 2 then
begin
for j := 0 to 9 do p[j] := 0;
build(i);
end;
end;
procedure adjustrates;
var r: real;
begin
expan := false;
r := ln(rate[1])/ln(rate[2]);
if r > 0.49 then
if r < 0.51 then expand(1,2);
if r > 0.32 then
if r < 0.35 then expand(1,3);
if r > 1.98 then
if r < 2.02 then expand(2,2);
if r > 2.97 then
if r < 3.03 then expand(2,3);
if r > 1.48 then
if r < 1.52 then begin expand(2,3); expand(1,2); end;
if r > 0.66 then
if r < 0.68 then begin expand(2,2); expand(1,3); end;
if not expan then
if ((r < 0.98) or (r > 1.02)) then
begin
writeln('***** Approach fails, no proof will be given');
fout := true;
end;
end;
procedure maak;
var i,j,k,t,cc : integer;
b : array[1..2,1..1000] of byte;
bhib : array[1..2] of integer;
function tel(s : integer) : integer;
var t,t2,t3 : array[1..2] of integer;
i,p : integer;
begin
{writeln('**** start tel: ',s,' bhib = ',bhib[1],' ',bhib[2]);}
for i := 1 to 2 do t[i] := len[i,b[i,s]];
for i := 1 to 2 do t2[i] := len2[i,b[i,s]];
for i := 1 to 2 do t3[i] := len3[i,b[i,s]];
p := s;
while (p < bhib[1]) and (p < bhib[2]) and ((t[1] <> t[2]) or (t2[1] <> t2[2]) or (t3[1] <> t3[2])) do
begin
p := p + 1;
for i := 1 to 2 do t[i] := t[i] + len[i,b[i,p]];
for i := 1 to 2 do t2[i] := t2[i] + len2[i,b[i,p]];
for i := 1 to 2 do t3[i] := t3[i] + len3[i,b[i,p]];
{writeln('***** ',p);}
end;
{writeln('**** tel: ',p);}
tel := p;
end;{tel}
procedure voegtoe(p,q : integer);
var i,j : integer;
found : boolean;
begin
found := false;
for i := 1 to chib do
if not found then
if lenc[i] = q+1-p then
begin
j := 1;
while j <= lenc[i] do
if ((c[1,i,j] = b[1,p-1+j]) and (c[2,i,j] = b[2,p-1+j])) then j := j+1 else j := 1000;
if j = lenc[i]+1 then found := true;
end;
if not fout then
if not found then
if chib < 10 then
begin
chib := chib+1;
lenc[chib] := q+1-p;
for i := 1 to 2 do
for j := p to q do c[i,chib,j+1-p] := b[i,j];
if q-p > 24 then
begin
writeln('******** string too long in induction hypothesis');
fout := true;
end;
end else
begin
writeln('******** too many induction hypotheses');
fout := true;
end;
end;{voegtoe}
begin {maak}
for i := 1 to 2 do
begin
for k := 1 to len[i,0] do b[i,k] := f[i,0,k];
bhib[i] := len[i,0];
for j := 2 to len[i,0] do
for k := 1 to len[i,b[i,j]] do
begin bhib[i] := bhib[i]+ 1;b[i,bhib[i]] := f[i,b[i,j],k]; end;
{for j := 1 to bhib[i] do write(b[i,j]);
writeln;}
end;
chib := 1;
t := tel(1);
lenc[chib] := t;
for i := 1 to 2 do
for j := 1 to t do c[i,chib,j] := b[i,j];
cc := 0;
while cc < chib do
begin
cc := cc+1;
for i := 0 to 50 do ck[cc,i] := false;
for i := 1 to 2 do
begin
bhib[i] := 0;
for j := 1 to lenc[cc] do
for k := 1 to len[i,c[i,cc,j]] do
begin bhib[i] := bhib[i]+1; b[i,bhib[i]] := f[i,c[i,cc,j],k]; end;
{for j := 1 to bhib do write(b[i,j]);
writeln;}
end;
t := 1;
if bhib[1] <> bhib[2] then fout := true else
while t <= bhib[1] do
begin
k := tel(t);
ck[cc,k] := true;
{for i := t to k do write(b[1,i]);
write(', ');
for i := t to k do write(b[2,i]);
writeln;}
voegtoe(t,k);
t := k+1;
end;
end;
end;{maak}
begin {start program}
fout := false;
for j := 0 to 9 do p[j] := 0;
for i := 1 to 2 do
begin
readln(n); {size signature Fi}
dim[i] := n;
for j := 0 to dim[i] do
for k := 0 to dim[i] do a[i,j,k] := 0;
for j := 0 to n-1 do
begin
if i= 1 then write('f(',j,') = ') else write ('g(',j,') = ');
readln(s);
len[i,j] := length(s);
for k := 1 to len[i,j] do
begin f[i,j,k] := ord(s[k]) - ord('0'); write(f[i,j,k]); a[i,j,f[i,j,k]] := a[i,j,f[i,j,k]]+1; end;
writeln;
end;
readln(s);
for j := 1 to n do
begin
tau[i,j-1] := ord(s[j]) - ord('0');
if i=1 then write('tau') else write('rho');
writeln('(',j-1,') = ',tau[i,j-1]);
end;
rate[i] := comprate(i);
build(i);
end;
adjustrates;
for i := 1 to 2 do
for j := 0 to dim[i]-1 do
begin
len2[i,j] := 0;
for k := 1 to len[i,j] do len2[i,j] := len2[i,j]+len[i,f[i,j,k]];
end;
for i := 1 to 2 do
for j := 0 to dim[i]-1 do
begin
len3[i,j] := 0;
for k := 1 to len[i,j] do len3[i,j] := len3[i,j]+len2[i,f[i,j,k]];
end;
If not fout then
begin
writeln('Claim to be proved: tau(f^infty(0)) = rho(g^infty(0)).');
{writeln(hib[1]);
writeln(hib[2]);}
for i := 1 to 1000 do
if i <= hib[1] then
if i <= hib[2] then
if tau[1,ff[1,i]] <> tau[2,ff[2,i]] then
if not fout then
begin
writeln('****** error on position ',i);
fout := true;
end;
{if not fout then writeln('First part checked to be equal');}
if not fout then
begin
maak;
writeln('We will prove the following ',chib,' properties simultaneously by induction on n.');
for j := 1 to chib do
begin
write('(',j-1,') tau(f^n(');
for i := 1 to lenc[j] do write(c[1,j,i]);
write(')) = rho(g^n(');
for i := 1 to lenc[j] do write(c[2,j,i]);
writeln(')).');
end;
writeln('Then our claim follows from (0).');
writeln('Basis n=0 of induction:');
for j := 1 to chib do
begin
for i := 1 to lenc[j] do
if tau[1,c[1,j,i]] <> tau[2,c[2,j,i]] then begin fout := true; writeln('****** error in tau'); end;
write('tau(f^0(');
for i := 1 to lenc[j] do write(c[1,j,i]);
write(')) = ');
for i := 1 to lenc[j] do write(tau[1,c[1,j,i]]);
write(' = rho(g^0(');
for i := 1 to lenc[j] do write(c[2,j,i]);
writeln(')).');
end;
if not fout then writeln('Basis of induction proved.');
if not fout then
for j := 1 to chib do
begin
writeln('Induction step part (',j-1,'):');
write('tau(f^{n+1}(');
for i := 1 to lenc[j] do write(c[1,j,i]);
writeln(')) = ');
write('tau(f^n(f(');
for i := 1 to lenc[j] do write(c[1,j,i]);
writeln('))) = ');
write('tau(f^n(');
for i := 1 to lenc[j] do
for k := 1 to len[1,c[1,j,i]] do write(f[1,c[1,j,i],k]);
writeln(')) = ');
t := 0;
write('tau(f^n(');
for i := 1 to lenc[j] do
for k := 1 to len[1,c[1,j,i]] do
begin
t := t + 1;
if ck[j,t-1] then write(')) tau(f^n(',f[1,c[1,j,i],k]) else write(f[1,c[1,j,i],k]);
end;
writeln(')) = (by induction hypothesis)');
t := 0;
write('rho(g^n(');
for i := 1 to lenc[j] do
for k := 1 to len[2,c[2,j,i]] do
begin
t := t + 1;
if ck[j,t-1] then write(')) rho(g^n(',f[2,c[2,j,i],k]) else write(f[2,c[2,j,i],k]);
end;
writeln(')) = ');
write('rho(g^n(');
for i := 1 to lenc[j] do
for k := 1 to len[2,c[2,j,i]] do write(f[2,c[2,j,i],k]);
writeln(')) = ');
write('rho(g^n(g(');
for i := 1 to lenc[j] do write(c[2,j,i]);
writeln('))) = ');
write('rho(g^{n+1}(');
for i := 1 to lenc[j] do write(c[2,j,i]);
writeln(')).');
end;
if not fout then writeln('Induction step proved, hence claim proved.');
end;
end;
if fout then writeln('**** No proof found.');
end.