|
4 | 4 | :- use_module(library(lists)).
|
5 | 5 | :- use_module(library(dif)).
|
6 | 6 | :- use_module(library(loader)).
|
| 7 | +:- use_module(library(format)). |
7 | 8 | :- use_module(test_framework).
|
8 | 9 |
|
9 |
| -% Those tests are just sanity checks – examples from the paper, to make sure |
10 |
| -% I haven't messed up. |
| 10 | +/* |
| 11 | +Those tests are just sanity checks – examples from the paper, to make sure I |
| 12 | +haven't messed up. |
| 13 | +*/ |
11 | 14 | test("indexing dif/2 p6#1", (
|
12 | 15 | findall(X-Fs, tfilter(=(X),[1,2,3,2,3,3],Fs), [1-[1], 2-[2,2], 3-[3,3,3], Y-[]]),
|
13 | 16 | maplist(dif(Y), [1,2,3])
|
|
45 | 48 | X == Y
|
46 | 49 | )).
|
47 | 50 |
|
48 |
| -% This test fails, and I don't know if goal_expanded/2 should be recursive or not, |
49 |
| -% and what properties it shall maintain (is idempotence even desirable?). |
50 |
| -%test("second expansion doesnt modify goal", ( |
51 |
| -% findall(G==Gxx, test_expand_goal_twice(G,Gxx), Goals), |
52 |
| -% maplist(call, Goals) |
53 |
| -%)). |
| 51 | +/* |
| 52 | +Following tests capture current results of goal expansion |
| 53 | +TODO: Investigate if if_/3 can be further expanded, and if it will be beneficial |
| 54 | +*/ |
| 55 | +test("goal_expansion (=)", ( |
| 56 | + subsumes_full_expansion(if_(1=2,a,b), ( |
| 57 | + 1 \= 2 -> b |
| 58 | + ; 1 == 2 -> a |
| 59 | + ; 1 = 2, a |
| 60 | + ; dif(1,2), b)))). |
54 | 61 |
|
55 |
| -test("ge1", ( |
56 |
| - loader:goal_expansion(if_(1=2,false,true), reif_tests, _) |
57 |
| -)). |
| 62 | +test("goal_expansion (;)", ( |
| 63 | + subsumes_full_expansion(if_((1=2;3=3),a,b), ( |
| 64 | + 1 \= 2 -> if_(3=3,a,b) |
| 65 | + ; 1 == 2 -> a |
| 66 | + ; 1 = 2, a |
| 67 | + ; dif(1,2), if_(3=3,a,b))))). |
| 68 | + |
| 69 | +test("goal_expansion (,)", ( |
| 70 | + subsumes_full_expansion(if_((1=2,3=3),a,b), ( |
| 71 | + 1 \= 2 -> b |
| 72 | + ; 1 == 2 -> if_(3=3,a,b) |
| 73 | + ; 1 = 2, if_(3=3,a,b) |
| 74 | + ; dif(1,2), b)))). |
| 75 | + |
| 76 | +test("goal_expansion memberd_t", ( |
| 77 | + subsumes_full_expansion(if_(memberd_t(f,"abcdefgh"),t,f), ( |
| 78 | + call(memberd_t(f,"abcdefgh"),A), |
| 79 | + ( A == true -> t |
| 80 | + ; A == false -> f |
| 81 | + ; nonvar(A) -> throw(error(type_error(boolean,A),_)) |
| 82 | + ; throw(error(instantiation_error,_))))))). |
| 83 | + |
| 84 | +test("goal_expansion cond_t", ( |
| 85 | + subsumes_full_expansion(if_(cond_t(a,b),t,f), ( |
| 86 | + call(cond_t(a,b),A), |
| 87 | + ( A == true -> t |
| 88 | + ; A == false -> f |
| 89 | + ; nonvar(A) -> throw(error(type_error(boolean,A),_)) |
| 90 | + ; throw(error(instantiation_error,_))))))). |
58 | 91 |
|
59 |
| -test_expand_goal_twice(G, Gxx) :- |
60 |
| - test_goal(G), |
61 |
| - reif:goal_expanded(G,Gx), |
62 |
| - reif:goal_expanded(Gx, Gxx). |
| 92 | +% Expand goal until fix point is found |
| 93 | +full_expansion(G, X) :- |
| 94 | + user:goal_expansion(G, Gx) -> full_expansion(Gx, X); G = X. |
63 | 95 |
|
64 |
| -test_goal(_). |
65 |
| -test_goal(call(a)). |
66 |
| -test_goal(call(a:b(1))). |
67 |
| -test_goal(call(a:b,c)). |
68 |
| -test_goal(call(call(a))). |
69 |
| -test_goal(call(call(a:b))). |
| 96 | +% X is more general than fully expanded goal G |
| 97 | +subsumes_full_expansion(G, X) :- |
| 98 | + full_expansion(G, Y), |
| 99 | + subsumes_term(X, Y). |
70 | 100 |
|
71 |
| -% Extra predicates from the paper |
| 101 | +/* |
| 102 | +Extra predicates from the paper |
| 103 | +*/ |
72 | 104 | duplicate(X, Xs) :-
|
73 | 105 | tfilter(=(X), Xs, [_,_|_]).
|
74 | 106 |
|
|
0 commit comments