-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arithemetic operators in interval domain
- Loading branch information
Showing
3 changed files
with
98 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,99 @@ | ||
#include <algorithm> | ||
|
||
#include "ast.hpp" | ||
|
||
class Interval { | ||
public: | ||
int lower; | ||
int upper; | ||
using long long ll; | ||
|
||
ll lb; | ||
ll ub; | ||
|
||
Interval() : lb(0), ub(0) {} | ||
Interval(int lb, int ub) : lb(lb), ub(ub) {} | ||
|
||
void add(const Interval& other){ | ||
lb += other.lb; | ||
ub += other.ub; | ||
return; | ||
} | ||
|
||
void sub(const Interval& other){ | ||
lb -= other.lb; | ||
ub -= other.ub; | ||
return; | ||
} | ||
|
||
void mul(const Interval& other){ | ||
ll B[4]; | ||
B[0] = lb * other.lb; | ||
B[1] = lb * other.ub; | ||
B[2] = ub * other.lb; | ||
B[3] = ub * other.ub; | ||
|
||
lb = std::min_element(B, B+4); | ||
ub = std::max_element(B, B+4); | ||
|
||
return; | ||
} | ||
|
||
Interval() : lower(0), upper(0) {} | ||
Interval(int lower, int upper) : lower(lower), upper(upper) {} | ||
void div(const Interval& other){ | ||
if (0 < other.lb || other.ub < 0){ | ||
std::cout << "[ERORR]: The division contains zero." << std::endl; | ||
} | ||
|
||
ll B[4]; | ||
B[0] = lb * (1 / other.lb); | ||
B[1] = lb * (1 / other.ub); | ||
B[2] = ub * (1 / other.lb); | ||
B[3] = ub * (1 / other.ub); | ||
|
||
lb = std::min_element(B, B+4); | ||
ub = std::max_element(B, B+4); | ||
|
||
void add(){return;} | ||
void sub(){return;} | ||
void mul(){return;} | ||
void div(){return;} | ||
return; | ||
} | ||
|
||
bool le(const Interval& other){ | ||
return false; | ||
} | ||
|
||
void le(){return;} | ||
void leq(){return;} | ||
void ge(){return;} | ||
void geq(){return;} | ||
void eq(){return;} | ||
void neq(){return;} | ||
bool leq(const Interval& other){ | ||
return false; | ||
} | ||
|
||
bool ge(const Interval& other){ | ||
return false; | ||
} | ||
|
||
bool geq(const Interval& other){ | ||
return false; | ||
} | ||
|
||
bool eq(const Interval& other){ | ||
return false; | ||
} | ||
|
||
bool neq(const Interval& other){ | ||
return false; | ||
} | ||
|
||
void meet(const Interval& other){ | ||
lower = std::max(lower, other.lower); | ||
upper = std::min(upper, other.upper); | ||
lb = std::max(lb, other.lb); | ||
ub = std::min(ub, other.ub); | ||
} | ||
|
||
void join(const Interval& other){ | ||
lower = std::min(lower, other.lower); | ||
upper = std::max(upper, other.upper); | ||
lb = std::min(lb, other.lb); | ||
ub = std::max(ub, other.ub); | ||
} | ||
|
||
void widen(const Interval& other){ | ||
if (lower > other.lower){ | ||
lower = std::numeric_limits<int>::min(); | ||
if (lb > other.lb){ | ||
lb = std::numeric_limits<int>::min(); | ||
} | ||
if (upper < other.upper){ | ||
upper = std::numeric_limits<int>::max(); | ||
if (ub < other.ub){ | ||
ub = std::numeric_limits<int>::max(); | ||
} | ||
} | ||
}; |