-
Notifications
You must be signed in to change notification settings - Fork 4
/
ranFullFormulas.pro
46 lines (34 loc) · 1.13 KB
/
ranFullFormulas.pro
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
35
36
37
38
39
40
41
42
43
44
45
46
ranFullFormula(N,T):-ranFullFormula(random,N,T).
ranFullFormula(Seed,N,T):-ranFullFormula(Seed,N,[(->),(&),(v),(<->)],T).
/*
ranFullFormula(Seed,N,FunList,T):-
set_random(seed(Seed)),
succ(N,SN),ranSetPart(SN,Vs),
sort(Vs,Sorted),length(Sorted,L),
K is random(L),
replace(K,false,Vs,NewVs),
remyExpr(N,FunList,T,NewVs).
replace(_,_,[],[]):-!.
replace(X,Y,[X|Xs],[Y|Ys]):-!,replace(X,Y,Xs,Ys).
replace(X,Y,[A|Xs],[A|Ys]):-replace(X,Y,Xs,Ys).
*/
ranFullFormula(Seed,N,FunList,T):-
set_random(seed(Seed)),
ranFullPosFormula(N,FunList,P),
negDec(P,T).
ranFullPosFormula(N,FunList,T):-
succ(N,SN),ranSetPart(SN,Vs),
remyExpr(N,FunList,T,Vs).
negDec((X->Y),D):-!,negDec(X,A),negDec(Y,B),decOne((A->B),D).
negDec((X<->Y),D):-!,negDec(X,A),negDec(Y,B),decOne((A<->B),D).
negDec((X & Y),D):-!,negDec(X,A),negDec(Y,B),decOne((A & B),D).
negDec((X v Y),D):-!,negDec(X,A),negDec(Y,B),decOne((A v B),D).
negDec(X,DX):-decOne(X,DX).
decOne(X,DX):-Choice is random(3),decOne(Choice,X,DX).
decOne(0,X,X).
decOne(1,X,~X).
decOne(2,X,~ ~ X).
ranFlatFormula(Seed,N,MT):-
ranFullFormula(Seed,N,T),
mints(T,H,Bs),
unexpand(Bs,H,MT).