|
3 | 3 | :- use_module(library(format)).
|
4 | 4 | :- use_module(library(reif)).
|
5 | 5 |
|
| 6 | +tt :- |
| 7 | + tt(Clause), |
| 8 | + nl, portray_clause(Clause), nl. |
| 9 | +tt((f(V is Expr) :- Sequence)) :- |
| 10 | + sample("ttttffft", _ is Expr), |
| 11 | + once(phrase(ae(Expr,Repl), Removed)), |
| 12 | + append(Removed, [V is Repl], X), |
| 13 | + list_sequence(X, Sequence). |
| 14 | + |
| 15 | + |
| 16 | +sample(Template, R) :- |
| 17 | + setof(E, phrase(arith_relation(E), Template), Es), |
| 18 | + length(Es, L), |
| 19 | + repeat, |
| 20 | + random_integer(0, L, I), |
| 21 | + format("~n% Info: Selected ~dth out of ~d found aritmetic relations that satisfy ~s template:~n\t", [I,L,Template]), |
| 22 | + nth0(I, Es, R). |
| 23 | + |
6 | 24 | %% Proof-of-concept arithmetic expression expander
|
7 | 25 | %
|
8 | 26 | % TODO: Don't use DCG's, because they aren't available in loader.pl
|
|
14 | 32 | append(Removed, [V is Repl], X),
|
15 | 33 | list_sequence(X, Sequence).
|
16 | 34 |
|
17 |
| -ae(A, R) --> ex(A, R). |
18 |
| -ae(F, FR) --> ey(F, A, R, FR), ae(A, R). |
19 | 35 | ae(F, FR) --> ez(F, A, B, AR, BR, FR), ae(A, AR), ae(B, BR).
|
| 36 | +ae(F, FR) --> ey(F, A, R, FR), ae(A, R). |
| 37 | +ae(A, R) --> ex(A, R). |
20 | 38 |
|
21 |
| -ex([] , R ) --> [R = []]. |
22 |
| -ex([H|T] , R ) --> [R = [H|T]]. |
23 |
| -ex(zeta(A) , R ) --> [R = zeta(A)]. |
| 39 | +ex(A , R ) --> [R = A], { nonvar(A), \+number(A), A \= e, A \= pi}. |
24 | 40 | ex(A , A ) --> t, { var(A) }.
|
| 41 | +ex(A , A ) --> t, { number(A) }. |
25 | 42 | ex(e , e ) --> t.
|
26 | 43 | ex(pi , pi ) --> t.
|
27 | 44 |
|
|
35 | 52 | ez(A/B,A,B, AR,BR,AR/BR) --> t.
|
36 | 53 | ez(A^B,A,B, AR,BR,AR^BR) --> t.
|
37 | 54 |
|
38 |
| -t --> [true]. |
| 55 | +t --> []. |
39 | 56 |
|
40 | 57 | %% list_sequence(List, Sequence).
|
41 | 58 | %
|
|
0 commit comments