codac 1.5.6
Loading...
Searching...
No Matches
codac2_mod.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "codac2_Interval.h"
13#include "codac2_AnalyticType.h"
15#include "codac2_arith_sub.h"
16
17namespace codac2
18{
19 struct ModOp
20 {
21 static void bwd(Interval& x1, Interval& x2, double p);
22 static void bwd(Interval& x1, Interval& x2, Interval& p);
23 };
24
25 // Inline functions
26
27 inline void ModOp::bwd(Interval& x1, Interval& x2, double p) // x1 = x2 mod(p)
28 {
29 // The content of this function comes from the IBEX library.
30 // See ibex::Interval (IBEX lib, main author: Gilles Chabert)
31 // https://ibex-lib.readthedocs.io
32
33 assert_release(p > 0. && "Modulo needs a strictly positive period p.");
34
35 if(!(x2.diam() > p || x1.diam() > p))
36 {
37 Interval r = (x1-x2)/p;
38 Interval ir = integer(r);
39
40 if(ir.is_empty()) // additional protection because an empty interval is considered degenerated.
41 {
42 x1.set_empty();
43 x2.set_empty();
44 }
45
46 else
47 {
48 if(ir.is_degenerated())
49 SubOp::bwd(ir*p,x1,x2);
50
51 else if(ir.diam() == 1.)
52 {
53 double ir1 = ir.lb();
54 double ir2 = ir.ub();
55 Interval x1_1 = x1; Interval x1_2 = x1;
56 Interval x2_1 = x2; Interval x2_2 = x2;
57 SubOp::bwd(Interval(ir1*p),x1_1,x2_1);
58 SubOp::bwd(Interval(ir2*p),x1_2,x2_2);
59 x1 = x1_1 | x1_2;
60 x2 = x2_1 | x2_2;
61 }
62
63 else
64 {
65 assert_release(false && "Modulo diameter error.");
66 }
67 }
68 }
69 }
70
71 inline void ModOp::bwd(Interval& x1, Interval& x2, Interval& p) // x = y mod(p)
72 {
73 assert_release(p.is_degenerated() && "ModOp::bwd(y,x1,x2) (with x1 and x2 intervals) not implemented yet");
74 ModOp::bwd(x1, x2, p.mid());
75 }
76}
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
Interval integer(const Interval &x)
Returns the largest integer interval included in .
Definition codac2_Interval_operations_impl.h:284