I changed the Pascal triangle backward chaining rules, going from goals
to sub goals, that ordinary Prolog also does, into Pascal triangle
forward chaining rules, going from facts to derived facts:
% rule(-Term)
rule(p(1, 1, 1)).
% rule(+Term, -Term)
rule(p(R2, 1, 1), p(R, 1, 1)) :-
R is R2+1.
rule(p(R2, R2, 1), p(R, R, 1)) :-
R is R2+1.
% rule(+Term, +Term, -Term)
rule(p(R2, C2, M1), p(R2, C, M2), p(R, C, M)) :-
R is R2+1,
C =:= C2+1,
M is M1+M2.
Now using a predicate init/1 that writes all the result of rule/1 on a
file. And a predicate step/2 that applies and writes all the results
of rule/2 and rule/3 by reading an old file and writing a new file:
?- init('even.p').
?- step('even.p', 'odd.p').
?- step('odd.p', 'even.p').
?- step('even.p', 'odd.p').
?- step('odd.p', 'even.p').
Its basically BinProlog but bottom up and streaming, step/2 trivially
uses an inner and outer loop for the two inputs of rule/3. After doing
the above, inspecting the file ‘even.p’ I see a valid Pascal triangle
row, and its indeed a frontier calculation:
p(5, 1, 1).
p(5, 2, 4).
p(5, 3, 6).
p(5, 4, 4).
p(5, 5, 1).