1 | % (c) 2012-2022 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, | |
2 | % Heinrich Heine Universitaet Duesseldorf | |
3 | % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) | |
4 | ||
5 | :- module(interval_calc,[interval_addition/3 | |
6 | ,interval_subtraction/3 | |
7 | ,interval_multiplication/3 | |
8 | ,interval_negation/2 | |
9 | ]). | |
10 | ||
11 | :- use_module(probsrc(module_information),[module_info/2]). | |
12 | :- module_info(group,kodkod). | |
13 | :- module_info(description,'This module provides methods to calculate with interval expressions.'). | |
14 | ||
15 | :- use_module(probsrc(inf_arith)). | |
16 | ||
17 | interval_addition(irange(Am,AM2),irange(Bm,BM2),irange(Cm,CM2)) :- | |
18 | Cm infis Am+Bm, CM2 infis AM2+BM2. | |
19 | interval_subtraction(irange(Am,AM2),irange(Bm,BM2),irange(Cm,CM2)) :- | |
20 | Cm infis Am-BM2, CM2 infis AM2-Bm. | |
21 | interval_multiplication(irange(Am,AM2),irange(Bm,BM2),irange(Cm,CM2)) :- | |
22 | MultExprs = [Am*Bm,Am*BM2,AM2*Bm,AM2*BM2], | |
23 | get_min(MultExprs,Cm), | |
24 | get_max(MultExprs,CM2). | |
25 | interval_negation(irange(Am,AM2),irange(Cm,CM2)) :- | |
26 | CM2 infis -Am, Cm infis -AM2. | |
27 | ||
28 | get_min([A],Min) :- !, Min infis A. | |
29 | get_min([A|Rest],Min) :- | |
30 | get_min(Rest,Rmin), Min infis min(A,Rmin). | |
31 | get_max([A],Max) :- !,Max infis A. | |
32 | get_max([A|Rest],Max) :- | |
33 | get_max(Rest,Rmax), Max infis max(A,Rmax). |