File size: 3,657 Bytes
557a17a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
%% Test individual cases, Debug=trace=on or off, N=case number, Passed=output=result

cawptest1a(Debug,N,Passed) :-
	cawptest2a(N,Function,Rules,MaxLength,MaxPredicates,TotalVars,Numinputs, Numoutputs,Specifications,AlgDict,Program1),
	%%writeln1([cawptest2(N,Specifications,Program1)]),
	%%writeln1(caw00(Debug,Function,Rules,MaxLength,MaxPredicates,TotalVars,Numinputs, Numoutputs,Specifications,AlgDict,[],Program2)),

	(((caw000(Debug,Function,Rules,MaxLength,MaxPredicates,TotalVars,Numinputs, Numoutputs,Specifications,AlgDict,[],Program1)
	%%sort(Program1,ProgramA),
	%%sort(Program2,ProgramA)

	%%writeln(Program1),
	%%writeln(Program2),
	%%Program1=Program2
	))->(Passed=passed,writeln([cawptest,N,passed]));(Passed=failed,writeln([cawptest,N,failed]))),!.
	
cawptest2a(7,[add0,add0],[],[2,3],[1,1],%% it could be 5
[3,4], %% 4 not 3 because of bug
[1],[1],
[
[[[[[[v,a],[]]],[[[v,b],[]]],true]]],

[[[[[[v,a],[1,2,3]]],[[[v,b],[]]],true]]]
%%[[[[[v,a],[2]]],[[[v,b],[]]],true]], %% Needs to progress bottom up by writing base case first
%%[[[[[v,a],[1,2]]],[[[v,b],[]]],true]], %% add0 second clause has this not spec below
%%[[[[[v,a],[1,2]]],[[[v,b],[2]]],true]],
%%[[[[[v,a],[2]]],[[[v,b],[]]],true]]
%%[[[[[v,a],[1,2]]],[[[v,b],[]]],true]],
],
[ %% Algorithm dictionary
[[[n,add2],1,1],[[v,a],[v,b]],":-",
	[[[n,=],[[v,a],[]]],
	[[n,=],[[v,b],[]]]]],
[[[n,add3],1,1],[[v,a],[v,b]],":-",
	[[[n,tail],[[v,a],[v,b]]]]]
	
	 %% Result
/**[[[n,add1],1,1],[[v,a],[v,b]],":-",
	[[[n,add2],[[v,a],[v,c]]],
	[[n,=],[[v,c],[v,b]]]]]
**/
],
[ %% Result
%%[[n,add3],[[v,a],[v,b]],":-", %% swapped a3,a2
	%%[[[n,tail],[[v,a],[v,b]]]]],

/**[[n,add2],[[v,a],[v,b]],":-",
	[[[n,=],[[v,a],[]]],
	[[n,=],[[v,b],[]]]]],
[[n,add0],[[v,a],[v,b]],":-", 
	[[[n,add2],[[v,a],[v,c]]],
	[[n,=],[[v,c],[v,b]]]]]],
**/	
	 %% Resulting base case

	[[[n,add2],[[v,a],[v,b]],":-",
		[[[n,=],[[v,a],[]]],
		[[n,=],[[v,b],[]]]]],
	[[n,add0],[[v,a],[v,b]],":-",
		[[[n,add2],[[v,a],[v,c]]],
		[[n,=],[[v,c],[v,b]]]]]],
	
	[ %% Resulting recursive algorithm
	
[[n,add2],[[v,a],[v,b]],":-",
	[[[n,=],[[v,a],[]]],
	[[n,=],[[v,b],[]]]]],
[[n,add3],[[v,a],[v,b]],":-",
	[[[n,tail],[[v,a],[v,b]]]]],
[[n,add0],[[v,a],[v,b]],":-",
	[[[n,add2],[[v,a],[v,c]]],
	[[n,=],[[v,c],[v,b]]]]],
[[n,add0],[[v,a],[v,b]],":-",
	[[[n,add3],[[v,a],[v,c]]],
	[[n,add0],[[v,c],[v,d]]],
	[[n,=],[[v,d],[v,b]]]]]]]
	
	).


%%[[[n,add],[[v,a],[v,c],[v,d]],":-",[[[n,[]],[[v,a]]],[[n,=],[[v,c],[v,d]]]]]]

%% Add cover all vars before returning
%%**/


/** Doesn't work
%% before now, io=21
cawptest2(7,add0,[],2,3,5,% 3 x 5
[1,2],[0,1],
[[[[[[v,a],1],[[v,b],2]],[],true],[[[[v,a],2],[[v,b],1]],[],true]],
%%[[[[[v,a],1],[[v,b],2]],[],true],[[[[v,a],2],[[v,b],1]],[],true]],
[[[[[v,a],1]],[[[v,b],2]],true]],
[[[[[v,a],2]],[[[v,b],1]],true]]
],

[ %% Algorithm dictionary

        [[[n,a2],1,1],[[v,a],[v,b]],":-",
        [       [[n,+],[[v,a],1,[v,c]]],
                [[n,=],[[v,c],[v,b]]]]],

        [[[n,a3],1,1],[[v,a],[v,b]],":-",
        [       [[n,-],[[v,a],1,[v,c]]],
                [[n,=],[[v,c],[v,b]]]]]
],

[ %% Result
        [[n,a2],[[v,a],[v,b]],":-",
        [       [[n,+],[[v,a],1,[v,c]]],
                [[n,=],[[v,c],[v,b]]]]],

        [[n,a3],[[v,a],[v,b]],":-",
        [       [[n,-],[[v,a],1,[v,c]]],
                [[n,=],[[v,c],[v,b]]]]],

        [[n,add0],[[v,a],[v,b]],":-",
        [       [[n,1],[[v,a],[v,b]]]]],
        
        [[n,1],[[v,a],[v,b]],":-",
        [       [[n,a2],[[v,a],[v,c]]],
                [[n,=],[[v,c],[v,b]]]]],

        [[n,1],[[v,a],[v,b]],":-",
        [       [[n,a3],[[v,a],[v,c]]],
                [[n,=],[[v,c],[v,b]]]]]
]).

**/