% BEGIN LICENSE BLOCK
% Version: CMPL 1.1
%
% The contents of this file are subject to the Cisco-style Mozilla Public
% License Version 1.1 (the "License"); you may not use this file except
% in compliance with the License.  You may obtain a copy of the License
% at www.eclipse-clp.org/license.
% 
% Software distributed under the License is distributed on an "AS IS"
% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
% the License for the specific language governing rights and limitations
% under the License. 
% 
% The Original Code is  The ECLiPSe Constraint Logic Programming System. 
% The Initial Developer of the Original Code is  Cisco Systems, Inc. 
% Portions created by the Initial Developer are
% Copyright (C) 1991-2006 Cisco Systems, Inc.  All Rights Reserved.
% 
% Contributor(s): Thom Fruehwirth, ECRC. 
% 
% END LICENSE BLOCK

% math-inequalities.chr =====================================================
% thom fruehwirth 1991-93, 930518, 931223, 940308 'free var' case added
% for use in *math* constraint handlers

handler ineq.

option(already_in_store, off). 
option(already_in_heads, off).
option(check_guard_bindings, off).

:- local    (<)/2,(>)/2,(=\=)/2,(>=)/2,(=<)/2,(=:=)/2.
constraints (<)/2,(>)/2,(=\=)/2,(>=)/2,(=<)/2,(=:=)/2.

A =< B  <=> ground(A),ground(B) | call_kernel(A=<B).
A >= B  <=> ground(A),ground(B) | call_kernel(A>=B).
A < B   <=> ground(A),ground(B) | call_kernel(A<B).
A > B   <=> ground(A),ground(B) | call_kernel(A>B).
A =\= B <=> ground(A),ground(B) | call_kernel(A=\=B).

% introduce slack variables
A =< B  <=> A+slack(X) =:= B, call_kernel(X>=0).
A >= B  <=> B+slack(X) =:= A, call_kernel(X>=0).
A < B   <=> A+slack(X) =:= B, call_kernel(X>0).
A > B   <=> B+slack(X) =:= A, call_kernel(X>0).
A =\= B <=> A+      X  =:= B, call_kernel(X=\=0).  

A =:= B <=> ground(A),ground(B) | X is A-B, zero(X).  % handle imprecision
A =:= B <=> var(A),   ground(B) | A is B.
B =:= A <=> var(A),   ground(B) | A is B.
A =:= B <=> free(A),var(B) | A=B.   % variable A is not meta i.e. unconstrained
B =:= A <=> free(A),var(B) | A=B.   % variable A is not meta i.e. unconstrained
A =:= B <=> normalize(A,B,P,C), equals(P,C).


% load auxiliary file
:- ['math-utilities'].


% ineq.chr ------------------------------------------------------