Next: Symbols Up: FLIP: Functional-plus-Logic Programming on Previous: Transforming Deterministic REL

# Sample Dialog

```
rfe-p> destroy
rfe-p>
rfe-p> az declare( mode[ fac[g,x] ]).
rfe-p>
rfe-p> az fac(0,1) :- !.
rfe-p> az fac(X,Y) :- X1 is -(X,1), fac(X1, FX1), Y is *(X, FX1).
rfe-p>
rfe-p> az declare( mode[ f[g,x] ]).
rfe-p>
rfe-p> az f(s[X,Y], u[s[X,Y],s[A,B]]) :-
A is -(B,A),
s[A,B] is s[X,Y],
fac(X,A),
fac(Y,B) !.
rfe-p> az f(X, [X,X]).
rfe-p>
rfe-p> az tripfac(X, [X,Y]) :- fac(X,Y).
rfe-p> az tripfac(X, [X1,Y]) :- X1 is +(X,1), fac(X1,Y).
rfe-p> az tripfac(X, [X2,Y]) :- X2 is +(X,2), fac(X2,Y).
rfe-p>
rfe-p> az declare( mode[ tripfac1[g,x,x,x] ]).
rfe-p>
rfe-p> az tripfac1(X,F,F1,F2) :-
fac(X,F),
X1 is +(X,1), F1 is *(X1,F),
X2 is +(X,2), F2 is *(X2,F1).
rfe-p>
rfe-p> undeclare
rfe-p> deta
rfe-p>
rfe-p> listing
tripfac(X, [X, Y]) :- Y is fac/2-1(X).
tripfac(X, [X1, Y]) :- X1 is +(X, 1), Y is fac/2-1(X1).
tripfac(X, [X2, Y]) :- X2 is +(X, 2), Y is fac/2-1(X2).
tripfac1(X1, X2, X3, X4) :- values[X2, X3, X4] is tripfac1/4-3(X1).
f(X1, X2) :- X2 is f/2-1(X1).
fac(X1, X2) :- X2 is fac/2-1(X1).

(defun tripfac1/4-3 (arg#1)
(let ((v2082 (fac/2-1 arg#1)))
(let ((v2083 (* (+ arg#1 1) v2082)))
(struct 'values v2082 v2083 (* (+ arg#1 2) v2083)))))
tripfac1/4-3(X) :-
F is fac/2-1(X),
X1 is +(X, 1),
F1 is *(X1, F),
X2 is +(X, 2),
F2 is *(X2, F1) &
values[F, F1, F2].

(defun f/2-1 (arg#1)
(if (and (structp arg#1) (equal 's (functor arg#1))
(equal 2 (arity arg#1)))
(let ((v2124 (elt arg#1 0)))
(if (equal v2124 (fac/2-1 v2124))
(let ((v2125 (elt arg#1 1)))
(if (and (equal v2124 (- v2125 v2124))
(equal v2125 (fac/2-1 v2125)))
(struct 'u arg#1 arg#1)
(cons arg#1 (cons arg#1 nil))))
(cons arg#1 (cons arg#1 nil))))
(cons arg#1 (cons arg#1 nil))))
f/2-1(s[X, Y]) :-
A is -(B, A),
s[A, B] is s[X, Y],
A is fac/2-1(X),
B is fac/2-1(Y) !&
u[s[X, Y], s[A, B]].
f/2-1(X) :-& [X, X].

(defun fac/2-1 (arg#1)
(if (equal 0 arg#1) 1 (* arg#1 (fac/2-1 (- arg#1 1)))))
fac/2-1(0) :- !& 1.
fac/2-1(X) :- X1 is -(X, 1), Fx1 is fac/2-1(X1), Y is *(X, Fx1) & Y.
rfe-p>
rfe-p> compile
rfe-p>
rfe-p> fac(5,R)
true
R = 120
rfe-p> f(s[1,2],R)
true
R = u[s[1, 2], s[1, 2]]
rfe-p> f(s[2,3],R)
true
R = [s[2, 3], s[2, 3]]
rfe-p> tripfac(3,R)
true
R = [3, 6]
rfe-p> m
true
R = [4, 24]
rfe-p> m
true
R = [5, 120]
rfe-p> m
unknown
rfe-p> tripfac1(3,F,F1,F2)
true
F = 6
F1 = 24
F2 = 120
rfe-p>
rfe-p> destroy
rfe-p>
rfe-p> az declare( dfmode[ app[g,g,x] ]).
rfe-p> az declare( dfmode[ rev[g,x] ]).
rfe-p>
rfe-p> az app([], X, X).
rfe-p> az app([H|T], X, [H|Y]) :- app(T,X,Y).
rfe-p>
rfe-p> az rev([],[]).
rfe-p> az rev([H|T],X) :- rev(T,T1), app(T1,[H],X).
rfe-p>
rfe-p> undeclare
rfe-p> deta
rfe-p>
rfe-p> listing
rev(X1, X2) :- X2 is rev/2-1(X1).
app(X1, X2, X3) :- X3 is app/3-1(X1, X2).

(defun rev/2-1 (arg#1)
(if (equal nil arg#1)
nil
(if (consp arg#1)
(app/3-1 (rev/2-1 (cdr arg#1)) (cons (car arg#1) nil))
(type-error))))
rev/2-1([]) :-& [].
rev/2-1([H | T]) :- T1 is rev/2-1(T), X is app/3-1(T1, [H]) & X.

(defun app/3-1 (arg#1 arg#2)
(if (equal nil arg#1)
arg#2
(if (consp arg#1)
(cons (car arg#1) (app/3-1 (cdr arg#1) arg#2))
(type-error))))
app/3-1([], X) :-& X.
app/3-1([H | T], X) :- Y is app/3-1(T, X) & [H | Y].
rfe-p>
rfe-p> compile
rfe-p>
rfe-p> app([1,2,3],[4,5,6],X)
true
X = [1, 2, 3, 4, 5, 6]
rfe-p> rev([1,2,3,4,5,6],X)
true
X = [6, 5, 4, 3, 2, 1]
rfe-p>
rfe-p> destroy
rfe-p>
rfe-p> az declare( mode[ app[g,g,x] ]).
rfe-p> az declare( mode[ rev[g,x] ]).
rfe-p>
rfe-p> az app([], X, X) :- !.
rfe-p> az app([H|T], X, [H|Y]) :- ! app(T,X,Y).
rfe-p> az app(X,Y,non-list-arg).
rfe-p>
rfe-p> az rev([],[]) :- ! .
rfe-p> az rev([H|T],X) :- ! rev(T,T1), app(T1,[H],X).
rfe-p> az rev(X,non-list-arg).
rfe-p>
rfe-p> undeclare
rfe-p> deta
rfe-p>
rfe-p> listing
rev(X1, X2) :- X2 is rev/2-1(X1).
app(X1, X2, X3) :- X3 is app/3-1(X1, X2).

(defun rev/2-1 (arg#1)
(if (equal nil arg#1)
nil
(if (consp arg#1)
(app/3-1 (rev/2-1 (cdr arg#1)) (cons (car arg#1) nil))
'non-list-arg)))
rev/2-1([]) :- !& [].
rev/2-1([H | T]) :- ! T1 is rev/2-1(T), X is app/3-1(T1, [H]) & X.
rev/2-1(X) :-& non-list-arg.

(defun app/3-1 (arg#1 arg#2)
(if (equal nil arg#1)
arg#2
(if (consp arg#1)
(cons (car arg#1) (app/3-1 (cdr arg#1) arg#2))
'non-list-arg)))
app/3-1([], X) :- !& X.
app/3-1([H | T], X) :- ! Y is app/3-1(T, X) & [H | Y].
app/3-1(X, Y) :-& non-list-arg.
rfe-p>
rfe-p> compile
rfe-p>
rfe-p> app([1,2,3],[4,5,6],X)
true
X = [1, 2, 3, 4, 5, 6]
rfe-p> app(3,4,X)
true
X = non-list-arg
rfe-p> rev([1,2,3,4,5,6],X)
true
X = [6, 5, 4, 3, 2, 1]
rfe-p>
rfe-p> destroy
rfe-p>
rfe-p> az declare( mode[ even[g] ] ).
rfe-p>
rfe-p> az even(0) :- !.
rfe-p> az even(X) :- >(X, 1), even(-(X,2)) !.
rfe-p> az even(X) :- <(X,-1), even(+(X,2)).
rfe-p>
rfe-p> az declare( mode[ small[g] ]).
rfe-p>
rfe-p> az small(0).
rfe-p> az small(1).
rfe-p> az small(2).
rfe-p>
rfe-p> undeclare
rfe-p> deta
rfe-p>
rfe-p> listing

(defun small (arg#1)
(if (equal 0 arg#1)
t
(if (equal 1 arg#1) t (if (equal 2 arg#1) t nil))))
small(0).
small(1).
small(2).

(defun even (arg#1)
(if (equal 0 arg#1)
t
(if (and (> arg#1 1) (even (- arg#1 2)))
t
(if (and (< arg#1 -1) (even (+ arg#1 2))) t nil))))
even(0) :- !.
even(X) :- >(X, 1), even(-(X, 2)) !.
even(X) :- <(X, -1), even(+(X, 2)).
rfe-p>
rfe-p> compile
rfe-p>
rfe-p> even(-3)
unknown
rfe-p> even(-2)
true
rfe-p> even(-1)
unknown
rfe-p> even(0)
true
rfe-p> even(1)
unknown
rfe-p> even(2)
true
rfe-p>
rfe-p> small(1)
true
rfe-p> small(3)
unknown
rfe-p>```

Harold Boley & Michael Sintek (sintek@dfki.uni-kl.de)