2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: arith.yap *
|
|
|
|
* Last rev: *
|
|
|
|
* mods: *
|
|
|
|
* comments: arithmetical optimization *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
% the default mode is on
|
|
|
|
|
|
|
|
expand_exprs(Old,New) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
(get_value('$c_arith',true) ->
|
2001-04-09 20:54:03 +01:00
|
|
|
Old = on ;
|
|
|
|
Old = off ),
|
|
|
|
'$set_arith_expan'(New).
|
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
'$set_arith_expan'(on) :- set_value('$c_arith',true).
|
|
|
|
'$set_arith_expan'(off) :- set_value('$c_arith',[]).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
compile_expressions :- set_value('$c_arith',true).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
do_not_compile_expressions :- set_value('$c_arith',[]).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2008-03-13 14:38:02 +00:00
|
|
|
'$c_built_in'(IN, M, OUT) :-
|
2003-08-27 14:37:10 +01:00
|
|
|
get_value('$c_arith',true), !,
|
2008-03-13 14:38:02 +00:00
|
|
|
'$do_c_built_in'(IN, M, OUT).
|
|
|
|
'$c_built_in'(IN, _, IN).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
2008-03-13 14:38:02 +00:00
|
|
|
'$do_c_built_in'(G, M, OUT) :- var(G), !,
|
2013-03-05 21:50:03 +00:00
|
|
|
'$do_c_built_metacall'(G, M, OUT).
|
|
|
|
'$do_c_built_in'(Mod:G, _, OUT) :- !,
|
|
|
|
'$do_c_built_metacall'(G, Mod, OUT).
|
2008-03-13 14:38:02 +00:00
|
|
|
'$do_c_built_in'(\+ G, _, OUT) :-
|
2001-05-21 21:00:05 +01:00
|
|
|
nonvar(G),
|
|
|
|
G = (A = B),
|
|
|
|
!,
|
|
|
|
OUT = (A \= B).
|
2008-03-13 14:38:02 +00:00
|
|
|
'$do_c_built_in'(call(G), _, OUT) :-
|
2001-10-30 16:42:05 +00:00
|
|
|
nonvar(G),
|
2003-01-29 14:47:17 +00:00
|
|
|
G = (Mod:G1), !,
|
|
|
|
'$do_c_built_metacall'(G1, Mod, OUT).
|
2010-01-17 00:03:55 +00:00
|
|
|
'$do_c_built_in'(call(G), Mod, OUT) :-
|
|
|
|
var(G), !,
|
|
|
|
'$do_c_built_metacall'(G, Mod, OUT).
|
2008-03-13 14:38:02 +00:00
|
|
|
'$do_c_built_in'(depth_bound_call(G,D), M, OUT) :- !,
|
|
|
|
'$do_c_built_in'(G, M, NG),
|
2003-01-30 16:27:45 +00:00
|
|
|
% make sure we don't have something like (A,B) -> $depth_next(D), A, B.
|
|
|
|
( '$composed_built_in'(NG) ->
|
|
|
|
OUT = depth_bound_call(NG,D)
|
|
|
|
;
|
|
|
|
OUT = ('$set_depth_limit_for_next_call'(D),NG)
|
|
|
|
).
|
2008-03-13 14:38:02 +00:00
|
|
|
'$do_c_built_in'(once(G), M, (yap_hacks:current_choice_point(CP),NG,'$$cut_by'(CP))) :- !,
|
|
|
|
'$do_c_built_in'(G,M,NG0),
|
2008-02-12 17:03:59 +00:00
|
|
|
'$clean_cuts'(NG0, NG).
|
2008-05-15 14:41:48 +01:00
|
|
|
'$do_c_built_in'(forall(Cond,Action), M, \+((NCond, \+(NAction)))) :- !,
|
|
|
|
'$do_c_built_in'(Cond,M,ICond),
|
|
|
|
'$do_c_built_in'(Action,M,IAction),
|
|
|
|
'$clean_cuts'(ICond, NCond),
|
|
|
|
'$clean_cuts'(IAction, NAction).
|
|
|
|
'$do_c_built_in'(ignore(Goal), M, (NGoal -> true ; true)) :- !,
|
|
|
|
'$do_c_built_in'(Goal,M,IGoal),
|
|
|
|
'$clean_cuts'(IGoal, NGoal).
|
2008-03-13 14:38:02 +00:00
|
|
|
'$do_c_built_in'(if(G,A,B), M, (yap_hacks:current_choicepoint(DCP),NG,yap_hacks:cut_at(DCP),NA; NB)) :- !,
|
2008-10-18 12:50:02 +01:00
|
|
|
'$do_c_built_in'(G,M,NG0),
|
|
|
|
'$clean_cuts'(NG0, NG),
|
|
|
|
'$do_c_built_in'(A,M,NA),
|
2008-03-13 14:38:02 +00:00
|
|
|
'$do_c_built_in'(B,M,NB).
|
2012-06-21 15:41:35 +01:00
|
|
|
'$do_c_built_in'((G*->A;B), M, (yap_hacks:current_choicepoint(DCP),NG,yap_hacks:cut_at(DCP),NA; NB)) :- !,
|
|
|
|
'$do_c_built_in'(G,M,NG0),
|
|
|
|
'$clean_cuts'(NG0, NG),
|
|
|
|
'$do_c_built_in'(A,M,NA),
|
|
|
|
'$do_c_built_in'(B,M,NB).
|
2008-03-13 14:38:02 +00:00
|
|
|
'$do_c_built_in'((G*->A), M, (NG,NA)) :- !,
|
|
|
|
'$do_c_built_in'(G,M,NG0),
|
2008-02-12 17:03:59 +00:00
|
|
|
'$clean_cuts'(NG0, NG),
|
2008-03-13 14:38:02 +00:00
|
|
|
'$do_c_built_in'(A,M,NA).
|
2008-10-29 17:58:47 +00:00
|
|
|
'$do_c_built_in'('C'(A,B,C), _, (A=[B|C])) :- !.
|
2013-03-04 02:26:20 +00:00
|
|
|
'$do_c_built_in'(trace, _M, '$do_trace') :- !.
|
2009-09-10 00:13:12 +01:00
|
|
|
'$do_c_built_in'(X is Y, M, P) :-
|
|
|
|
primitive(X), !,
|
|
|
|
'$do_c_built_in'(X =:= Y, M, P).
|
2010-03-06 00:16:49 +00:00
|
|
|
'$do_c_built_in'(X is Y, M, (P,A=X)) :-
|
|
|
|
nonvar(X), !,
|
2009-09-10 00:13:12 +01:00
|
|
|
'$do_c_built_in'(A is Y, M, P).
|
2008-03-13 14:38:02 +00:00
|
|
|
'$do_c_built_in'(X is Y, _, P) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
nonvar(Y), % Don't rewrite variables
|
|
|
|
!,
|
|
|
|
(
|
2011-05-08 23:11:56 +01:00
|
|
|
number(Y) ->
|
2001-04-09 20:54:03 +01:00
|
|
|
P = ( X = Y); % This case reduces to an unification
|
|
|
|
'$expand_expr'(Y, P0, X0),
|
2009-07-22 20:23:32 +01:00
|
|
|
'$drop_is'(X0, X, P0, P)
|
2001-04-09 20:54:03 +01:00
|
|
|
).
|
2008-03-13 14:38:02 +00:00
|
|
|
'$do_c_built_in'(Comp0, _, R) :- % now, do it for comparisons
|
2001-04-09 20:54:03 +01:00
|
|
|
'$compop'(Comp0, Op, E, F),
|
|
|
|
!,
|
|
|
|
'$compop'(Comp, Op, U, V),
|
|
|
|
'$expand_expr'(E, P, U),
|
|
|
|
'$expand_expr'(F, Q, V),
|
|
|
|
'$do_and'(P, Q, R0),
|
|
|
|
'$do_and'(R0, Comp, R).
|
2008-03-13 14:38:02 +00:00
|
|
|
'$do_c_built_in'(P, _, P).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2007-11-08 16:03:20 +00:00
|
|
|
'$do_c_built_metacall'(G1, Mod, '$execute_wo_mod'(G1,Mod)) :-
|
|
|
|
var(Mod), !.
|
2004-02-12 12:37:12 +00:00
|
|
|
'$do_c_built_metacall'(G1, Mod, '$execute_in_mod'(G1,Mod)) :-
|
|
|
|
var(G1), atom(Mod), !.
|
2006-03-24 16:26:31 +00:00
|
|
|
'$do_c_built_metacall'(Mod:G1, _, OUT) :- !,
|
2003-01-29 14:47:17 +00:00
|
|
|
'$do_c_built_metacall'(G1, Mod, OUT).
|
2004-02-12 12:37:12 +00:00
|
|
|
'$do_c_built_metacall'(G1, Mod, '$execute_in_mod'(G1,Mod)) :-
|
|
|
|
atom(Mod), !.
|
2003-01-29 14:47:17 +00:00
|
|
|
'$do_c_built_metacall'(G1, Mod, call(Mod:G1)).
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
'$do_and'(true, P, P) :- !.
|
|
|
|
'$do_and'(P, true, P) :- !.
|
|
|
|
'$do_and'(P, Q, (P,Q)).
|
|
|
|
|
|
|
|
% V is the result of the simplification,
|
|
|
|
% X the result of the initial expression
|
|
|
|
% and the last argument is how we are writing this result
|
2009-07-22 20:23:32 +01:00
|
|
|
'$drop_is'(V, V1, P0, G) :- var(V), !, % usual case
|
2009-07-22 20:31:15 +01:00
|
|
|
V = V1, P0 = G.
|
2009-07-22 20:23:32 +01:00
|
|
|
'$drop_is'(V, X, P0, P) :- % atoms
|
|
|
|
'$do_and'(P1, X is V, P).
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
% Table of arithmetic comparisons
|
|
|
|
'$compop'(X < Y, < , X, Y).
|
|
|
|
'$compop'(X > Y, > , X, Y).
|
|
|
|
'$compop'(X=< Y,=< , X, Y).
|
|
|
|
'$compop'(X >=Y, >=, X, Y).
|
|
|
|
'$compop'(X=:=Y,=:=, X, Y).
|
|
|
|
'$compop'(X=\=Y,=\=, X, Y).
|
|
|
|
|
2003-01-30 16:27:45 +00:00
|
|
|
'$composed_built_in'(V) :- var(V), !,
|
|
|
|
fail.
|
2006-12-27 01:32:38 +00:00
|
|
|
'$composed_built_in'((yap_hacks:current_choice_point(_),NG,'$$cut_by'(_))) :- !,
|
2003-01-30 16:27:45 +00:00
|
|
|
'$composed_built_in'(NG).
|
|
|
|
'$composed_built_in'((_,_)).
|
|
|
|
'$composed_built_in'((_;_)).
|
|
|
|
'$composed_built_in'((_|_)).
|
|
|
|
'$composed_built_in'((_->_)).
|
|
|
|
'$composed_built_in'(_:G) :-
|
|
|
|
'$composed_built_in'(G).
|
|
|
|
'$composed_built_in'(\+G) :-
|
|
|
|
'$composed_built_in'(G).
|
|
|
|
'$composed_built_in'(not(G)) :-
|
|
|
|
'$composed_built_in'(G).
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
% expanding an expression:
|
|
|
|
% first argument is the expression not expanded,
|
|
|
|
% second argument the expanded expression
|
|
|
|
% third argument unifies with the result from the expression
|
|
|
|
'$expand_expr'(V, true, V) :-
|
|
|
|
var(V), !.
|
|
|
|
'$expand_expr'([T], E, V) :- !,
|
|
|
|
'$expand_expr'(T, E, V).
|
|
|
|
'$expand_expr'(A, true, A) :-
|
|
|
|
atomic(A), !.
|
|
|
|
'$expand_expr'(T, E, V) :-
|
2010-03-06 00:16:49 +00:00
|
|
|
T =.. [O, A], !,
|
2001-04-09 20:54:03 +01:00
|
|
|
'$expand_expr'(A, Q, X),
|
|
|
|
'$expand_expr'(O, X, V, Q, E).
|
|
|
|
'$expand_expr'(T, E, V) :-
|
2010-03-06 00:16:49 +00:00
|
|
|
T =.. [O, A, B], !,
|
2001-04-09 20:54:03 +01:00
|
|
|
'$expand_expr'(A, Q, X),
|
|
|
|
'$expand_expr'(B, R, Y),
|
|
|
|
'$expand_expr'(O, X, Y, V, Q, S),
|
|
|
|
'$do_and'(R, S, E).
|
|
|
|
|
|
|
|
% expanding an expression of the form:
|
|
|
|
% O is Op(X),
|
|
|
|
% after having expanded into Q
|
|
|
|
% and giving as result P (the last argument)
|
|
|
|
'$expand_expr'(Op, X, O, Q, Q) :-
|
|
|
|
number(X), !,
|
|
|
|
is( O, Op, X).
|
|
|
|
'$expand_expr'(Op, X, O, Q, P) :-
|
|
|
|
'$unary_op_as_integer'(Op,IOp),
|
|
|
|
'$do_and'(Q, is( O, IOp, X), P).
|
|
|
|
|
|
|
|
% expanding an expression of the form:
|
|
|
|
% O is Op(X,Y),
|
|
|
|
% after having expanded into Q
|
|
|
|
% and giving as result P (the last argument)
|
|
|
|
% included is some optimization for:
|
|
|
|
% incrementing and decrementing,
|
|
|
|
% the elementar arithmetic operations [+,-,*,//]
|
|
|
|
'$expand_expr'(Op, X, Y, O, Q, Q) :-
|
|
|
|
number(X), number(Y), !,
|
|
|
|
is( O, Op, X, Y).
|
|
|
|
'$expand_expr'(+, X, Y, O, Q, P) :- !,
|
|
|
|
'$preprocess_args_for_commutative'(X, Y, X1, Y1, E),
|
|
|
|
'$do_and'(E, '$plus'(X1,Y1,O), F),
|
|
|
|
'$do_and'(Q, F, P).
|
|
|
|
'$expand_expr'(-, X, Y, O, Q, P) :-
|
2009-02-16 09:55:31 +00:00
|
|
|
var(X), number(Y),
|
|
|
|
Z is -Y, !,
|
|
|
|
'$expand_expr'(+, Z, X, O, Q, P).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$expand_expr'(-, X, Y, O, Q, P) :- !,
|
|
|
|
'$preprocess_args_for_non_commutative'(X, Y, X1, Y1, E),
|
|
|
|
'$do_and'(E, '$minus'(X1,Y1,O), F),
|
|
|
|
'$do_and'(Q, F, P).
|
|
|
|
'$expand_expr'(*, X, Y, O, Q, P) :- !,
|
|
|
|
'$preprocess_args_for_commutative'(X, Y, X1, Y1, E),
|
|
|
|
'$do_and'(E, '$times'(X1,Y1,O), F),
|
|
|
|
'$do_and'(Q, F, P).
|
2009-02-16 09:55:31 +00:00
|
|
|
'$expand_expr'(//, X, Y, O, Q, P) :-
|
|
|
|
nonvar(Y), Y == 0, !,
|
|
|
|
'$binary_op_as_integer'(//,IOp),
|
|
|
|
'$do_and'(Q, is(O,IOp,X,Y), P).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$expand_expr'(//, X, Y, O, Q, P) :- !,
|
|
|
|
'$preprocess_args_for_non_commutative'(X, Y, X1, Y1, E),
|
|
|
|
'$do_and'(E, '$div'(X1,Y1,O), F),
|
|
|
|
'$do_and'(Q, F, P).
|
|
|
|
'$expand_expr'(/\, X, Y, O, Q, P) :- !,
|
|
|
|
'$preprocess_args_for_commutative'(X, Y, X1, Y1, E),
|
|
|
|
'$do_and'(E, '$and'(X1,Y1,O), F),
|
2001-10-30 16:42:05 +00:00
|
|
|
'$do_and'(Q, F, P).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$expand_expr'(\/, X, Y, O, Q, P) :- !,
|
|
|
|
'$preprocess_args_for_commutative'(X, Y, X1, Y1, E),
|
|
|
|
'$do_and'(E, '$or'(X1,Y1,O), F),
|
|
|
|
'$do_and'(Q, F, P).
|
2009-02-16 09:55:31 +00:00
|
|
|
'$expand_expr'(<<, X, Y, O, Q, P) :-
|
|
|
|
var(X), number(Y), Y < 0,
|
|
|
|
Z is -Y, !,
|
|
|
|
'$expand_expr'(>>, X, Z, O, Q, P).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$expand_expr'(<<, X, Y, O, Q, P) :- !,
|
|
|
|
'$preprocess_args_for_non_commutative'(X, Y, X1, Y1, E),
|
|
|
|
'$do_and'(E, '$sll'(X1,Y1,O), F),
|
|
|
|
'$do_and'(Q, F, P).
|
2009-02-16 09:55:31 +00:00
|
|
|
'$expand_expr'(>>, X, Y, O, Q, P) :-
|
|
|
|
var(X), number(Y), Y < 0,
|
|
|
|
Z is -Y, !,
|
|
|
|
'$expand_expr'(<<, X, Z, O, Q, P).
|
2001-04-09 20:54:03 +01:00
|
|
|
'$expand_expr'(>>, X, Y, O, Q, P) :- !,
|
|
|
|
'$preprocess_args_for_non_commutative'(X, Y, X1, Y1, E),
|
|
|
|
'$do_and'(E, '$slr'(X1,Y1,O), F),
|
|
|
|
'$do_and'(Q, F, P).
|
|
|
|
'$expand_expr'(Op, X, Y, O, Q, P) :-
|
|
|
|
'$binary_op_as_integer'(Op,IOp),
|
|
|
|
'$do_and'(Q, is(O,IOp,X,Y), P).
|
|
|
|
|
|
|
|
'$preprocess_args_for_commutative'(X, Y, X, Y, true) :-
|
|
|
|
var(X), var(Y), !.
|
|
|
|
'$preprocess_args_for_commutative'(X, Y, X, Y, true) :-
|
|
|
|
var(X), integer(Y), \+ '$bignum'(Y), !.
|
|
|
|
'$preprocess_args_for_commutative'(X, Y, X, Z, Z = Y) :-
|
|
|
|
var(X), !.
|
|
|
|
'$preprocess_args_for_commutative'(X, Y, Y, X, true) :-
|
|
|
|
integer(X), \+ '$bignum'(X), var(Y), !.
|
|
|
|
'$preprocess_args_for_commutative'(X, Y, Z, X, Z = Y) :-
|
|
|
|
integer(X), \+ '$bignum'(X), !.
|
|
|
|
'$preprocess_args_for_commutative'(X, Y, Z, W, E) :-
|
|
|
|
'$do_and'(Z = X, Y = W, E).
|
|
|
|
|
|
|
|
'$preprocess_args_for_non_commutative'(X, Y, X, Y, true) :-
|
|
|
|
var(X), var(Y), !.
|
|
|
|
'$preprocess_args_for_non_commutative'(X, Y, X, Y, true) :-
|
|
|
|
var(X), integer(Y), \+ '$bignum'(Y), !.
|
|
|
|
'$preprocess_args_for_non_commutative'(X, Y, X, Z, Z = Y) :-
|
|
|
|
var(X), !.
|
|
|
|
'$preprocess_args_for_non_commutative'(X, Y, X, Y, true) :-
|
|
|
|
integer(X), \+ '$bignum'(X), var(Y), !.
|
|
|
|
'$preprocess_args_for_non_commutative'(X, Y, X, Z, Z = Y) :-
|
2009-02-16 09:55:31 +00:00
|
|
|
integer(X), \+ '$bignum'(X), !.
|
2001-04-09 20:54:03 +01:00
|
|
|
'$preprocess_args_for_non_commutative'(X, Y, Z, W, E) :-
|
|
|
|
'$do_and'(Z = X, Y = W, E).
|
|
|
|
|
|
|
|
/* Arithmetics */
|
|
|
|
|
2009-05-21 06:36:09 +01:00
|
|
|
|
|
|
|
|
2010-04-20 23:06:41 +01:00
|
|
|
% M and N nonnegative integers, N is the successor of M
|
|
|
|
succ(M,N) :-
|
|
|
|
(
|
|
|
|
var(M)
|
|
|
|
->
|
|
|
|
(
|
|
|
|
integer(N),
|
|
|
|
N > 0
|
|
|
|
->
|
|
|
|
'$plus'(N,-1,M)
|
|
|
|
;
|
|
|
|
'$succ_error'(M,N)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
integer(M),
|
|
|
|
M >= 0
|
|
|
|
->
|
|
|
|
(
|
|
|
|
var(N)
|
|
|
|
->
|
|
|
|
'$plus'(M,1,N)
|
|
|
|
;
|
|
|
|
integer(N),
|
|
|
|
N > 0
|
|
|
|
->
|
|
|
|
'$plus'(M,1,N)
|
|
|
|
;
|
|
|
|
'$succ_error'(M,N)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
'$succ_error'(M,N)
|
|
|
|
).
|
|
|
|
|
|
|
|
'$succ_error'(M,N) :-
|
|
|
|
var(M),
|
|
|
|
var(N), !,
|
|
|
|
'$do_error'(instantiation_error,succ(M,N)).
|
|
|
|
'$succ_error'(M,N) :-
|
|
|
|
nonvar(M),
|
|
|
|
\+ integer(M),
|
|
|
|
'$do_error'(type_error(integer, M),succ(M,N)).
|
|
|
|
'$succ_error'(M,N) :-
|
|
|
|
nonvar(M),
|
|
|
|
M < 0,
|
|
|
|
'$do_error'(domain_error(not_less_than_zero, M),succ(M,N)).
|
|
|
|
'$succ_error'(M,N) :-
|
|
|
|
nonvar(N),
|
|
|
|
\+ integer(N),
|
|
|
|
'$do_error'(type_error(integer, N),succ(M,N)).
|
|
|
|
'$succ_error'(M,N) :-
|
|
|
|
nonvar(N),
|
|
|
|
N < 0,
|
|
|
|
'$do_error'(domain_error(not_less_than_zero, N),succ(M,N)).
|
2010-05-04 16:33:35 +01:00
|
|
|
|
2013-04-30 00:22:53 +01:00
|
|
|
|
|
|
|
|
2010-05-04 16:37:03 +01:00
|
|
|
plus(X, Y, Z) :-
|
2010-05-04 16:33:35 +01:00
|
|
|
(
|
|
|
|
var(X)
|
2010-05-04 16:37:03 +01:00
|
|
|
->
|
2010-05-04 16:33:35 +01:00
|
|
|
(
|
|
|
|
integer(Y), integer(Z)
|
2010-05-04 16:37:03 +01:00
|
|
|
->
|
2010-05-04 16:33:35 +01:00
|
|
|
'$minus'(Z,Y,X)
|
|
|
|
;
|
|
|
|
'$plus_error'(X,Y,Z)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
integer(X)
|
2010-05-04 16:37:03 +01:00
|
|
|
->
|
2010-05-04 16:33:35 +01:00
|
|
|
(
|
|
|
|
var(Y)
|
2010-05-04 16:37:03 +01:00
|
|
|
->
|
2010-05-04 16:33:35 +01:00
|
|
|
(
|
|
|
|
integer(Z)
|
2010-05-04 16:37:03 +01:00
|
|
|
->
|
2010-05-04 16:33:35 +01:00
|
|
|
'$minus'(Z,X,Y)
|
|
|
|
;
|
|
|
|
'$plus_error'(X,Y,Z)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
integer(Y)
|
2010-05-04 16:37:03 +01:00
|
|
|
->
|
2010-05-04 16:33:35 +01:00
|
|
|
(
|
|
|
|
integer(Z)
|
2010-05-04 16:37:03 +01:00
|
|
|
->
|
2010-05-04 16:33:35 +01:00
|
|
|
'$minus'(Z,Y,X)
|
|
|
|
;
|
|
|
|
var(Z)
|
2010-05-04 16:37:03 +01:00
|
|
|
->
|
2010-05-04 16:33:35 +01:00
|
|
|
'$plus'(X,Y,Z)
|
|
|
|
;
|
|
|
|
'$plus_error'(X,Y,Z)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
'$plus_error'(X,Y,Z)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
'$plus_error'(X,Y,Z)
|
|
|
|
).
|
|
|
|
|
2010-05-04 16:37:39 +01:00
|
|
|
'$plus_error'(X,Y,Z) :-
|
2010-05-04 16:33:35 +01:00
|
|
|
nonvar(X),
|
|
|
|
\+ integer(X),
|
|
|
|
'$do_error'(type_error(integer, X),plus(X,Y,Z)).
|
2010-05-04 16:37:39 +01:00
|
|
|
'$plus_error'(X,Y,Z) :-
|
2010-05-04 16:33:35 +01:00
|
|
|
nonvar(Y),
|
|
|
|
\+ integer(Y),
|
|
|
|
'$do_error'(type_error(integer, Y),plus(X,Y,Z)).
|
2010-05-04 16:37:39 +01:00
|
|
|
'$plus_error'(X,Y,Z) :-
|
2010-05-04 16:33:35 +01:00
|
|
|
nonvar(Z),
|
|
|
|
\+ integer(Z),
|
|
|
|
'$do_error'(type_error(integer, Z),plus(X,Y,Z)).
|
2010-05-04 16:37:39 +01:00
|
|
|
'$plus_error'(X,Y,Z) :-
|
2010-05-04 16:33:35 +01:00
|
|
|
'$do_error'(instantiation_error,plus(X,Y,Z)).
|
|
|
|
|
|
|
|
|
|
|
|
|