diff infinite.pl @ 16:4360c2030303

strange...
author kono
date Sun, 21 Jan 2001 00:51:10 +0900
parents 816425e04ea7
children 29cf617f49db
line wrap: on
line diff
--- a/infinite.pl	Sat Jan 20 21:21:44 2001 +0900
+++ b/infinite.pl	Sun Jan 21 00:51:10 2001 +0900
@@ -37,8 +37,21 @@
     make_hist([L,L],L1),
     write_ce(L1,0),nl.
 write_infinite_seq1(L) :-
-    make_hist(L,L1),
-    write_ce(L1,0),nl.
+    insert_loop_mark(L,L1),
+    make_hist(L1,L2),
+    write_ce(L2,0),nl.
+
+insert_loop_mark(L,L1) :-
+    last(L,Last),
+    insert_loop_mark(L,Last,L1).
+
+last([Last],Last) :-!.
+last([_|T],Last) :-
+    last(T,Last).
+
+insert_loop_mark([Last|T],Last,[(*),Last|T]):-!.
+insert_loop_mark([H|T],Last,[H|T1]):-
+    insert_loop_mark(T,Last,T1).
 
 retract_all(X) :-
     retract(X),fail.
@@ -47,62 +60,61 @@
 infinite(L) :-
     % 1 seems like original ITL formula that is root.
     setof(S,links(S,1),Children),
-    more_only_node(1,Children,L,[],[1]).
+    more_node(1,Children,L,[],[1]).
 infinite([]) :-
     found_infinite.
 
-% more_only(S) :- 
-%     state(S,[empty|_],true),!,fail.
-% more_only(S) :- number(S).
+infinite_node(S) :- 
+     state(S,[empty|_],true),!,fail.
+infinite_node(S) :- number(S).
 
-more_only(true) :- !.
-more_only(S) :- 
-    number(S),
-    state(S,[more|_],_).
+%infinite_node(true) :- !.
+%infinite_node(S) :- 
+%    number(S),
+%    state(S,[more|_],_).
 
-more_only_node(S,[S1|Children],[S|L],L1,Hist) :-
+more_node(S,[S1|Children],[S|L],L1,Hist) :-
 %    write('checking '),write(S),nl,
-    more_only(S),
+    infinite_node(S),
     % starting false loop
-    more_only_loop(S1,Children,L,L1,[S|Hist],[S]).
-more_only_node(S,Children,L,L1,Hist) :- % goto one depth deeper
-    more_only_node1(Children,L,L1,[S|Hist]).
+    more_loop(S1,Children,L,L1,[S|Hist],[S]).
+more_node(S,Children,L,L1,Hist) :- 
+    % goto one depth deeper
+    more_node1(Children,L,L1,[S|Hist]).
 
-more_only_node1([H|_],_L,_L1,Hist) :-
-    member(H,Hist),
-    !,
-    fail.
-more_only_node1([H|_],L,L1,Hist) :-
+more_node1([H|_],L,L1,Hist) :-
+    not_member(H,Hist),
     setof(S,links(S,H),Children),
-    more_only_node(H,Children,L,L1,Hist).
-more_only_node1([_|T],L,L1,Hist) :-
-    more_only_node1(T,L,L1,Hist).
+    more_node(H,Children,L,L1,Hist).
+more_node1([_|T],L,L1,Hist) :-
+    more_node1(T,L,L1,Hist).
 
-more_only_loop(true,_,[true|L],L,_Hist,_Seq) :-
+more_loop(true,_,[true|L],L,_Hist,_Seq) :-
     assert(found_infinite).
-more_only_loop(S,_,[S|L],L,_Hist,Seq) :-
+more_loop(S,_,[S|L],L,_Hist,Seq) :-
     member(S,Seq),!,
     assert(found_infinite).
     % we find the one
-more_only_loop(S,_,L,L,Hist,_Seq) :-
+more_loop(S,_,L,L,Hist,_Seq) :-
     member(S,Hist),!,
     fail.	
     % end of this branch
-more_only_loop(H,_,[H|L],L1,Hist,Seq) :-
-    more_only(H),!,		
+more_loop(H,_,[H|L],L1,Hist,Seq) :-
+    infinite_node(H),!,		
     % still in the false interval
     setof(S,links(S,H),Children),
-    more_only_loop1(Children,L,L1,[H|Hist],[H|Seq]).
-more_only_loop(H,[S|_],[H|L],L1,Hist,_) :-
-    % false interval ends, start new search in depth first way
+    more_loop1(Children,L,L1,[H|Hist],[H|Seq]).
+more_loop(_,[S|T],L,L1,Hist,Seq) :-!,
+    % try another child
+    more_loop(S,T,L,L1,Hist,Seq).
+% more_loop(H,[],L,L1,Hist,Seq) :-!,fail.
+    % empty case. fail and try another branch
+
+
+more_loop1([H|_],L,L1,Hist,Seq) :-
     setof(S,links(S,H),Children),
-    % we already know S i not more_only
-    more_only_node1(Children,L,L1,[H|Hist]).
-
-more_only_loop1([H|_],L,L1,Hist,Seq) :-
-    setof(S,links(S,H),Children),
-    more_only_loop(H,Children,L,L1,Hist,Seq).
-more_only_loop1([_|T],L,L1,Hist,Seq) :-
-    more_only_loop1(T,L,L1,Hist,Seq).
+    more_loop(H,Children,L,L1,Hist,Seq).
+more_loop1([_|T],L,L1,Hist,Seq) :-
+    more_loop1(T,L,L1,Hist,Seq).
 
 /* end */