You selected topology2022.pl

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% simulating topology
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% topology2022.pl
% 10 Jan 2022 (modified: 11 Jan 2022 15:38pm)
% By Kenryo Indo

% index function for list members
%----------------------------------------------------------------
% from menu.pl(27 Aug 2006)

list_projection( [ ], [ ], [ ]).
list_projection( [ 0 | A ], [ _ | Y ], Z ):-
	 list_projection( A, Y, Z ).
list_projection( [ 1 | A ], [ X | Y ], [ X | Z ] ):-
	 list_projection( A, Y, Z ).

% alias: selecting members from a list with index label
%----------------------------------------------------------------

group( Gid, L, G ):-
	 \+ var( L ),
	 list_projection( X, L, G ),
	 atomic_list_concat( X, Gid ).

% list equivalence as a set (e.g., same_members/2 of SWI-prolog)
%----------------------------------------------------------------

are_same_members( W, Z ):-
	 subset( W, Z ),
	 subset( Z, W ).

% recursive function in a generic form
%----------------------------------------------------------------
% from icaart2014c.pl(30 Dec 2013, 4 Feb 2014) with a modification

function( [ ], [ ], _).

function( [ Y | F ], [ X | D ], Axiom ):- 
	 function( F, D, Axiom ),
	 atomic( Axiom ),
	 Goal =.. [ Axiom, X, F, Y ],
	 call( Goal ).

function( [ Y | F ], [ X | D ], Axiom ):- 
	 function( F, D, Axiom ),
	 Axiom =.. [ Functor, P ],
	 Goal =.. [ Functor, X, F, Y, P ],
	 call( Goal ).

% a utility for showing members list
%----------------------------------------------------------------
	 
concatenate_for_each_list_of_members( F, T ):-
	 findall( P, ( 
		 member( X, F ), 
		 ( 
			 X = [ ]
		 ->	 P='null' 
		 ;	 atomic_list_concat( X, P ) 
	 	 ) 
	 ), T ). 

% Logical implication: If _ then _
%----------------------------------------------------------------

:- op( 1050, xfy, ==> ). 

A ==> B:-
	 \+ ( call( A ), \+ call( B ) ).

/*

?- A = (a, v ==> c,d), A=..B.
A =  (a, v==>c, d),
B = [==>,  (a, v),  (c, d)].

*/

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% hypergraph
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

axiom_of_hypergraph( X, _, X->Y, S ):-
	 group( _, S, Y ),
	 member( X, Y ).
	 
hypergraph( S, F ):-
	 function(
		 F, 
		 S, 
		 axiom_of_hypergraph( S )
	 ).

hypergraph( F ):-
	 hypergraph( [ a, b, c ], F ).

/*

?- hypergraph( F ), F = [ a->[ a ] | _ ], writeln( F ), fail.
[(a->[a]),(b->[b]),(c->[c])]
[(a->[a]),(b->[b,c]),(c->[c])]
[(a->[a]),(b->[a,b]),(c->[c])]
[(a->[a]),(b->[a,b,c]),(c->[c])]
[(a->[a]),(b->[b]),(c->[b,c])]
[(a->[a]),(b->[b,c]),(c->[b,c])]
[(a->[a]),(b->[a,b]),(c->[b,c])]
[(a->[a]),(b->[a,b,c]),(c->[b,c])]
[(a->[a]),(b->[b]),(c->[a,c])]
[(a->[a]),(b->[b,c]),(c->[a,c])]
[(a->[a]),(b->[a,b]),(c->[a,c])]
[(a->[a]),(b->[a,b,c]),(c->[a,c])]
[(a->[a]),(b->[b]),(c->[a,b,c])]
[(a->[a]),(b->[b,c]),(c->[a,b,c])]
[(a->[a]),(b->[a,b]),(c->[a,b,c])]
[(a->[a]),(b->[a,b,c]),(c->[a,b,c])]
false.

*/


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Family of subsets
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

power_set( S, D ):-
	 findall( A, group( _, S, A ), D ).

family_of_subsets( I, S, F ):-
	 power_set( S, D ), 
	 list_projection( I, D, F ).

	 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% closedness
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

is_a_common_member( X, L ):-
	 flatten( L, A ),
	 sort( A, B ),
	 member( X, B ),
	 ( member( C, L ) ==>  member( X, C ) ).

intersection_of_groups( G, M ):-
	 findall( X, is_a_common_member( X, G ), M ).

union_of_groups( G, U ):-
 	 flatten( G, A ),
	 sort( A, U ).

violation_of_closedness( intersection, T, [ G, M ] ):-
	 group( _, T, G ),
	 intersection_of_groups( G, M ),
	 \+ (
		 member( Z, T ),
		 are_same_members( Z, M )
	 ).

violation_of_closedness( union, T, [ G, U ] ):-
	 group( _, T, G ),
	 union_of_groups( G, U ),
	 \+ (
		 member( Z, T ),
		 are_same_members( Z, U )
	 ).

/*

?- family_of_subsets( I, [x,y,z], F ), violation_of_closedness( union, F, V ).
I = [0, 0, 0, 0, 0, 0, 0, 0],
F = [],
V = [[], []] ;
I = [0, 0, 0, 0, 0, 0, 0, 1],
F = [[x, y, z]],
V = [[], []] ;
I = [0, 0, 0, 0, 0, 0, 1, 0],
F = [[x, y]],
V = [[], []] ;
...

?- family_of_subsets( I, [x,y,z], F ), \+ violation_of_closedness( _, F, _ ).
I = [1, 0, 0, 0, 0, 0, 0, 0],
F = [[]] ;
I = [1, 0, 0, 0, 0, 0, 0, 1],
F = [[], [x, y, z]] ;
I = [1, 0, 0, 0, 0, 0, 1, 0],
F = [[], [x, y]] ;
I = [1, 0, 0, 0, 0, 0, 1, 1],
F = [[], [x, y], [x, y, z]] ;
...

?- findall( 1, (family_of_subsets( I, [x,y,z], F ), \+ violation_of_closedness( _, F, _ )), L ), length( L, N).
L = [1, 1, 1, 1, 1, 1, 1, 1, 1|...],
N = 45.

?- S=[x,y,z], findall( 1, (family_of_subsets( I, S, F ), \+ violation_of_closedness( _, F, _ ), subset( [[],S], F )), L ), length( L, N).
S = [x, y, z],
L = [1, 1, 1, 1, 1, 1, 1, 1, 1|...],
N = 29.

*/

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Topology : Generation-and-test
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/*
def. Topology (closed set)
1. The empty set and X are closed.
2. The intersection of any collection of closed sets is also closed.
3. The union of any finite number of closed sets is also closed.
*/

default_base_set_if_needed( S ):-
	 var( S )
	 ->	 S = [a,b,c] 
	 ;	 true.

'1. The empty set and X are closed.'( F, S, C ):-
	 ( subset( [ [], S ], F ) -> C = 1 ; C = 0 ).

'2. The intersection of any collection of closed sets is also closed.'( F, C ):-
	 ( violation_of_closedness( intersection, F, _ ) -> C = 0 ; C = 1 ).

'3. The union of any finite number of closed sets is also closed.'( F, C ):-
	 ( violation_of_closedness( union, F, _ ) -> C = 0 ; C = 1 ).

simulating_topology( S, F, T, C ):-
	 default_base_set_if_needed( S ),
	 family_of_subsets( _, S, F ),
	 '1. The empty set and X are closed.'( F, S, C1 ),
	 '2. The intersection of any collection of closed sets is also closed.'( F, C2 ),
	 '3. The union of any finite number of closed sets is also closed.'( F, C3 ),
 	 C = [ C1, C2, C3 ],
	 concatenate_for_each_list_of_members( F, T ).
	 
simulating_topology( S, F, T ):-
	 simulating_topology( S, F, T, [ 1, 1, 1 ] ).
	 
simulating_topology( S, F ):-
	 simulating_topology( S, F, _ ).

/*

?- simulating_topology( [a,b], F, C ), nl, write( C; F ), fail.

[0,0,0];[]
[0,0,0];[[a,b]]
[0,0,0];[[a]]
[0,0,0];[[a],[a,b]]
[0,0,0];[[b]]
[0,0,0];[[b],[a,b]]
[0,0,0];[[b],[a]]
[0,0,0];[[b],[a],[a,b]]
[0,1,1];[[]]
[1,1,1];[[],[a,b]]
[0,1,1];[[],[a]]
[1,1,1];[[],[a],[a,b]]
[0,1,1];[[],[b]]
[1,1,1];[[],[b],[a,b]]
[0,1,0];[[],[b],[a]]
[1,1,1];[[],[b],[a],[a,b]]
false.


?- S=[a,b], findall( T, simulating_topology( S, T ), L ), nth1(J, L, T ), nl, write( J : T ), fail.

1:[[],[a,b]]
2:[[],[a],[a,b]]
3:[[],[b],[a,b]]
4:[[],[b],[a],[a,b]]
false.

?- S=[a,b,c], findall( T, simulating_topology( S, _, T ), L ), nth1(J, L, T ), nl, write( J : T ), fail.

1:[null,abc]
2:[null,ab,abc]
3:[null,ac,abc]
4:[null,a,abc]
5:[null,a,ab,abc]
6:[null,a,ac,abc]
7:[null,a,ac,ab,abc]
8:[null,bc,abc]
9:[null,bc,a,abc]
10:[null,b,abc]
11:[null,b,ab,abc]
12:[null,b,ac,abc]
13:[null,b,a,ab,abc]
14:[null,b,a,ac,ab,abc]
15:[null,b,bc,abc]
16:[null,b,bc,ab,abc]
17:[null,b,bc,a,ab,abc]
18:[null,c,abc]
19:[null,c,ab,abc]
20:[null,c,ac,abc]
21:[null,c,a,ac,abc]
22:[null,c,a,ac,ab,abc]
23:[null,c,bc,abc]
24:[null,c,bc,ac,abc]
25:[null,c,bc,a,ac,abc]
26:[null,c,b,bc,abc]
27:[null,c,b,bc,ab,abc]
28:[null,c,b,bc,ac,abc]
29:[null,c,b,bc,a,ac,ab,abc]
false.

*/

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Topology : A recursive construction
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

list_of_checked_members( F, L ):-
	 findall( Y, member( Y -> _, F ), L ).

list_selected_members( F, H ):-
	 findall( Y, member( Y -> 1, F ), H ).

axiom_of_topology( X, _, X ->V, S ):-
	 member( X, [ [ ], S ] ),
	 !,
	 V = 1.

axiom_of_topology( X, F, X->1, _ ):-
	 % violation that caused by picking a subset up. 
	 list_selected_members( F, H ), 
	 list_of_checked_members( F, L ),
	 \+ (
		 violation_of_closedness( _, [ X | H ], [ _, W ] ),
		 member( Z, L ),
		 are_same_members( Z, W )
	 ).

axiom_of_topology( X, F, X->0, _ ):-
	 % violation that caused by unpicking a subset. 
	 list_selected_members( F, H ), 
	 \+ (
		 violation_of_closedness( _, H, [ _, Z ] ),
		 are_same_members( Z, X )
	 ).

topology( S, F, T ):-
	 power_set( S, D ), 
	 function(
		 F, 
		 D, 
		 axiom_of_topology( S )
	 ),
	 list_selected_members( F, T ).

topology( S, T ):-
	 topology( S, _, T ).

violation_of_topology_by_index_function( S, T, X->V ):-
	 member( X->V, T ),
	 \+ axiom_of_topology( X, T, X->V, S ).


/*

?- S = [a,b,c], topology( S, T ), violation_of_closedness(A, T, V ).
false.

?- S = [a,b,c], findall( 1, (topology( S, T )), L ), length( L, N ).
S = [a, b, c],
L = [1, 1, 1, 1, 1, 1, 1, 1, 1|...],
N = 29.

?- S = [a,b,c], topology( S, T ),  \+ simulating_topology( S, T ).
false.

?- S = [a,b,c], simulating_topology( S, T ), \+ topology( S, T ).
false.

*/


%%% end of program



return to front page.