1:- module(mcint, []). 2
3:- reexport(interval). 4:- reexport(rint). 5
9interval:int_hook(plus, plus1(atomic, atomic), atomic, []).
10interval:plus1(atomic(A), atomic(B), atomic(Res), _Flags) :-
11 !,
12 writeln(+),
13 Res is A + B.
14
15interval:int_hook(plus, plus2(..., ...), ..., []).
16interval:plus2(A, B, Res, Flags) :-
17 !,
18 writeln(+),
19 interval:interval_(A + B, Res, Flags).
20
24interval:int_hook(frac, frac(_, _), _, []).
25interval:frac(A, B, Res, Flags) :-
26 option(digits(Dig), Flags, _),
27 interval:interval_(round(A, atomic(Dig)), A1, Flags),
28 interval:interval_(round(B, atomic(Dig)), B1, Flags),
29 !,
30 interval:interval(A1 / B1, Res, Flags).
31
32interval:int_hook(dfrac, dfrac(_, _), _, []).
33interval:dfrac(A, B, Res, Flags) :-
34 interval(frac(A, B), Res, Flags).
35
39interval:int_hook(tstat, tstat(...), ..., []).
40interval:tstat(A...B, Res, Flags) :-
41 interval:interval_(round(A...B, atomic(2)), Res, Flags).
42
43interval:int_hook(hdrs, hdrs(...), ..., []).
44interval:hdrs(A...B, Res, Flags) :-
45 interval:interval_(round(A...B, atomic(1)), Res, Flags).
46
47interval:int_hook(chi2ratio, chi2ratio(...), ..., []).
48interval:chi2ratio(A...B, Res, Flags) :-
49 interval:interval_(round(A...B, atomic(2)), Res, Flags).
50
51interval:int_hook(pval, pval(...), ..., []).
52interval:pval(A...B, Res, Flags) :-
53 interval:interval_(round(A...B, atomic(3)), Res, Flags).
54
58interval:int_hook(omit_left, omit_left(_), _, [evaluate(false)]).
59interval:omit_left(Expr, Res, Flags) :-
60 Expr =.. [_Op, _L, R],
61 interval:interval_(R, Res, Flags).
62
63interval:int_hook(omit_right, omit_right(_), _, [evaluate(false)]).
64interval:omit_right(Expr, Res, Flags) :-
65 Expr =.. [_Op, L, _R],
66 interval:interval_(L, Res, Flags).
67
71interval:int_hook(dot, dot(_, _), _, []).
72interval:dot(A, B, Res, Flags) :-
73 interval:interval_(A * B, Res, Flags).
74
78interval:int_hook(available, avail1(atomic), _, []).
79interval:avail1(atomic(A), Res, _Flags) :-
80 avail2(atomic(A), Res),
81 !,
82 Res = true
83 ; Res = false.
84
85avail2(atomic(A), Res),
86 integer(A)
87=> interval:eval(A, Res).
88
89avail2(atomic(A), Res),
90 number(A)
91=> float_class(A, Class),
92 dif(Class, nan),
93 interval:eval(A, Res).
94
95avail2(atomic(A), Res)
96=> interval:eval(A, A1),
97 avail2(A1, Res).
98
99interval:int_hook(available, avail3(...), _, []).
100interval:avail3(A ... B, Res, _Flags)
101=> avail2(atomic(A), A1),
102 avail2(atomic(B), B1),
103 interval:eval(A1, B1, _),
104 !,
105 Res = true;
106 Res = false.
107
108interval:int_hook(=@=, equal1(..., ...), _, []).
109interval:equal1(A, B, Res, Flags) :-
110 interval:interval_(A =:= B, Res, Flags)