1/* $Id$ 2 3 Part of CLP(Q) (Constraint Logic Programming over Rationals) 4 5 Author: Leslie De Koninck 6 E-mail: Leslie.DeKoninck@cs.kuleuven.be 7 WWW: http://www.swi-prolog.org 8 http://www.ai.univie.ac.at/cgi-bin/tr-online?number+95-09 9 Copyright (C): 2006, K.U. Leuven and 10 1992-1995, Austrian Research Institute for 11 Artificial Intelligence (OFAI), 12 Vienna, Austria 13 14 This software is based on CLP(Q,R) by Christian Holzbaur for SICStus 15 Prolog and distributed under the license details below with permission from 16 all mentioned authors. 17 18 This program is free software; you can redistribute it and/or 19 modify it under the terms of the GNU General Public License 20 as published by the Free Software Foundation; either version 2 21 of the License, or (at your option) any later version. 22 23 This program is distributed in the hope that it will be useful, 24 but WITHOUT ANY WARRANTY; without even the implied warranty of 25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 GNU General Public License for more details. 27 28 You should have received a copy of the GNU Lesser General Public 29 License along with this library; if not, write to the Free Software 30 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 31 32 As a special exception, if you link this library with other files, 33 compiled with a Free Software compiler, to produce an executable, this 34 library does not by itself cause the resulting executable to be covered 35 by the GNU General Public License. This exception does not however 36 invalidate any other reasons why the executable file might be covered by 37 the GNU General Public License. 38*/ 39 40:- module(cdq, []). 41 42:- license(gpl_swipl, 'CLP(CDQ)'). 43:- use_module(library(neck)). 44:- use_module(library(near_utils)). 45:- use_module(library(cdqr), []). 46:- reexport(library(clpcd)). 47:- init_expansors. 48 49clpcd_domain_opsclpcd_module(cdq, cdq). 50 51:- initialization(set_clpcd(cdq)). 52 53clpcd_domain_opscompare_d(cdq, Op, A, B) :- 54 compare_q(Op, A, B). 55 56compare_q(=, A, B) :- A =:= B. 57compare_q(=<, A, B) :- A =< B. 58compare_q(>=, A, B) :- A >= B. 59compare_q(<, A, B) :- A < B. 60compare_q(>, A, B) :- A > B. 61compare_q(\=, A, B) :- A =\= B. 62 63clpcd_domain_opsdiv_d(cdq, A, B, C) :- C is A rdiv B. 64 65cdq_epsilon(R) :- 66 repsilon(E), 67 R is epsilon/E, 68 neck. 69 70clpcd_domain_opscast_d(cdq, A, B) :- 71 cdq_epsilon(T), 72 ( number(A) 73 ->( A >= T 74 ->B is rationalize(A) 75 ; B is rational(A) 76 ) 77 ; rational(A) 78 ->B is rational(A) 79 ). 80 81clpcd_domain_opsfloor_d(cdq, A, B) :- B is floor(A). 82 83clpcd_domain_opsceiling_d(cdq, A, B) :- B is ceiling(A). 84 85clpcd_domain_opsintegerp(cdq, A, A) :- integer(A)