comparison infinite.pl @ 16:4360c2030303

strange...
author kono
date Sun, 21 Jan 2001 00:51:10 +0900
parents 816425e04ea7
children 29cf617f49db
comparison
equal deleted inserted replaced
15:816425e04ea7 16:4360c2030303
35 write_infinite_seq1(L). 35 write_infinite_seq1(L).
36 write_infinite_seq1([L]) :-!, % odd case. 36 write_infinite_seq1([L]) :-!, % odd case.
37 make_hist([L,L],L1), 37 make_hist([L,L],L1),
38 write_ce(L1,0),nl. 38 write_ce(L1,0),nl.
39 write_infinite_seq1(L) :- 39 write_infinite_seq1(L) :-
40 make_hist(L,L1), 40 insert_loop_mark(L,L1),
41 write_ce(L1,0),nl. 41 make_hist(L1,L2),
42 write_ce(L2,0),nl.
43
44 insert_loop_mark(L,L1) :-
45 last(L,Last),
46 insert_loop_mark(L,Last,L1).
47
48 last([Last],Last) :-!.
49 last([_|T],Last) :-
50 last(T,Last).
51
52 insert_loop_mark([Last|T],Last,[(*),Last|T]):-!.
53 insert_loop_mark([H|T],Last,[H|T1]):-
54 insert_loop_mark(T,Last,T1).
42 55
43 retract_all(X) :- 56 retract_all(X) :-
44 retract(X),fail. 57 retract(X),fail.
45 retract_all(_). 58 retract_all(_).
46 59
47 infinite(L) :- 60 infinite(L) :-
48 % 1 seems like original ITL formula that is root. 61 % 1 seems like original ITL formula that is root.
49 setof(S,links(S,1),Children), 62 setof(S,links(S,1),Children),
50 more_only_node(1,Children,L,[],[1]). 63 more_node(1,Children,L,[],[1]).
51 infinite([]) :- 64 infinite([]) :-
52 found_infinite. 65 found_infinite.
53 66
54 % more_only(S) :- 67 infinite_node(S) :-
55 % state(S,[empty|_],true),!,fail. 68 state(S,[empty|_],true),!,fail.
56 % more_only(S) :- number(S). 69 infinite_node(S) :- number(S).
57 70
58 more_only(true) :- !. 71 %infinite_node(true) :- !.
59 more_only(S) :- 72 %infinite_node(S) :-
60 number(S), 73 % number(S),
61 state(S,[more|_],_). 74 % state(S,[more|_],_).
62 75
63 more_only_node(S,[S1|Children],[S|L],L1,Hist) :- 76 more_node(S,[S1|Children],[S|L],L1,Hist) :-
64 % write('checking '),write(S),nl, 77 % write('checking '),write(S),nl,
65 more_only(S), 78 infinite_node(S),
66 % starting false loop 79 % starting false loop
67 more_only_loop(S1,Children,L,L1,[S|Hist],[S]). 80 more_loop(S1,Children,L,L1,[S|Hist],[S]).
68 more_only_node(S,Children,L,L1,Hist) :- % goto one depth deeper 81 more_node(S,Children,L,L1,Hist) :-
69 more_only_node1(Children,L,L1,[S|Hist]). 82 % goto one depth deeper
83 more_node1(Children,L,L1,[S|Hist]).
70 84
71 more_only_node1([H|_],_L,_L1,Hist) :- 85 more_node1([H|_],L,L1,Hist) :-
72 member(H,Hist), 86 not_member(H,Hist),
73 !,
74 fail.
75 more_only_node1([H|_],L,L1,Hist) :-
76 setof(S,links(S,H),Children), 87 setof(S,links(S,H),Children),
77 more_only_node(H,Children,L,L1,Hist). 88 more_node(H,Children,L,L1,Hist).
78 more_only_node1([_|T],L,L1,Hist) :- 89 more_node1([_|T],L,L1,Hist) :-
79 more_only_node1(T,L,L1,Hist). 90 more_node1(T,L,L1,Hist).
80 91
81 more_only_loop(true,_,[true|L],L,_Hist,_Seq) :- 92 more_loop(true,_,[true|L],L,_Hist,_Seq) :-
82 assert(found_infinite). 93 assert(found_infinite).
83 more_only_loop(S,_,[S|L],L,_Hist,Seq) :- 94 more_loop(S,_,[S|L],L,_Hist,Seq) :-
84 member(S,Seq),!, 95 member(S,Seq),!,
85 assert(found_infinite). 96 assert(found_infinite).
86 % we find the one 97 % we find the one
87 more_only_loop(S,_,L,L,Hist,_Seq) :- 98 more_loop(S,_,L,L,Hist,_Seq) :-
88 member(S,Hist),!, 99 member(S,Hist),!,
89 fail. 100 fail.
90 % end of this branch 101 % end of this branch
91 more_only_loop(H,_,[H|L],L1,Hist,Seq) :- 102 more_loop(H,_,[H|L],L1,Hist,Seq) :-
92 more_only(H),!, 103 infinite_node(H),!,
93 % still in the false interval 104 % still in the false interval
94 setof(S,links(S,H),Children), 105 setof(S,links(S,H),Children),
95 more_only_loop1(Children,L,L1,[H|Hist],[H|Seq]). 106 more_loop1(Children,L,L1,[H|Hist],[H|Seq]).
96 more_only_loop(H,[S|_],[H|L],L1,Hist,_) :- 107 more_loop(_,[S|T],L,L1,Hist,Seq) :-!,
97 % false interval ends, start new search in depth first way 108 % try another child
109 more_loop(S,T,L,L1,Hist,Seq).
110 % more_loop(H,[],L,L1,Hist,Seq) :-!,fail.
111 % empty case. fail and try another branch
112
113
114 more_loop1([H|_],L,L1,Hist,Seq) :-
98 setof(S,links(S,H),Children), 115 setof(S,links(S,H),Children),
99 % we already know S i not more_only 116 more_loop(H,Children,L,L1,Hist,Seq).
100 more_only_node1(Children,L,L1,[H|Hist]). 117 more_loop1([_|T],L,L1,Hist,Seq) :-
101 118 more_loop1(T,L,L1,Hist,Seq).
102 more_only_loop1([H|_],L,L1,Hist,Seq) :-
103 setof(S,links(S,H),Children),
104 more_only_loop(H,Children,L,L1,Hist,Seq).
105 more_only_loop1([_|T],L,L1,Hist,Seq) :-
106 more_only_loop1(T,L,L1,Hist,Seq).
107 119
108 /* end */ 120 /* end */