-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathflatten.pl
More file actions
34 lines (32 loc) · 805 Bytes
/
flatten.pl
File metadata and controls
34 lines (32 loc) · 805 Bytes
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
flatten(X,Res) :- var(X),!,Res=X.
flatten((X,Y),Res) :- !,
flatten(X,FX),
((FX==fail) -> (Res=fail)
;
(flatten(Y,FY),
((FX==true) -> (Res=FY); ((FY==true) -> (Res = FX) ; (Res = (FX,FY))))
)).
flatten((LHS;E), Res) :- nonvar(LHS), LHS=(I->T),!,
flatten(I,FI),
((FI==fail) -> flatten(E,Res) ;
((FI==true) -> flatten(T,Res) ;
(Res = (FI->FT;FE), flatten(T,FT), flatten(E,FE))
)).
flatten(call(X),X) :- nonvar(X), !.
%flatten((Lhs;true), LHS) :- !.
%flatten((true;RHS), RHS) :- !.
flatten((L;R), Disj) :-
!,
flatten(L, FL),
flatten(R, FR),
(FL = true -> Disj = FR ;
(
FR = true ->
Disj = FL
;
Disj = (FL;FR)
)
).
flatten(\+(X),\+(Y)) :- flatten(X,Y),!.
flatten(when(C,Call), when(C,FCall)) :- flatten(Call,FCall), !.
flatten(X,X).