SMTStabilizer API
Public API documentation for SMTStabilizer
Loading...
Searching...
No Matches
interval.h
Go to the documentation of this file.
1/* -*- Header -*-
2 *
3 * The Interval Header
4 *
5 * Author: Fuqi Jia <jiafq@ios.ac.cn>
6 *
7 * Copyright (C) 2025 Fuqi Jia
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 */
27
28// Modified by Xiang Zhang, 2026
29// Additional changes licensed under the MIT License
30
31#ifndef INTERVAL_HEADER
32#define INTERVAL_HEADER
33
34#include <vector>
35
36#include "kind.h"
37#include "number.h"
38
39namespace stabilizer::parser {
40
41class Interval {
42 private:
47
48 public:
50
51 Interval(const Interval &other);
52 Interval &operator=(const Interval &other);
53 ~Interval();
54
55 // setters:
56 // warning: these functions will change the interval
57 void setLower(const Number &lower);
58 void setUpper(const Number &upper);
59 void setLeftClosed(bool leftClosed);
60 void setRightClosed(bool rightClosed);
61
62 // getters
63 Number getLower() const;
64 Number getUpper() const;
65 bool isLeftClosed() const;
66 bool isRightClosed() const;
67 bool isLeftUnbounded() const;
68 bool isRightUnbounded() const;
69 Number midpoint() const;
70 std::string toString() const;
71 void getIntegers(std::vector<Number> &integers) const;
72 bool isPoint() const;
73 bool isEmpty() const;
74 Number width() const;
75 bool contains(const Number &value) const;
76 bool isSubsetOf(const Interval &other) const;
77 bool isSubsetEqOf(const Interval &other) const;
78 bool isSupersetOf(const Interval &other) const;
79 bool isDisjointFrom(const Interval &other) const;
80 bool isIntersectingWith(const Interval &other) const;
81 Interval intersection(const Interval &other) const;
82 Interval unionWith(const Interval &other) const;
83 std::vector<Interval> difference(const Interval &other) const;
84 size_t getIntervalIntCount() const;
85
86 // unary operators
87 Interval operator++() const;
88 Interval operator--() const;
89 Interval operator-() const;
90 Interval operator+() const;
91 Interval operator~() const;
92 Interval operator!() const;
93 Interval operator++(int) const;
94 Interval operator--(int) const;
95 Interval negate() const;
96 Interval abs() const;
97 Interval lb() const;
98 Interval ln() const;
99 Interval lg() const;
100 Interval pow2() const;
101 Interval exp() const;
102 Interval sqrt() const;
103 Interval safeSqrt() const;
104 Interval sin() const;
105 Interval cos() const;
106 Interval tan() const;
107 Interval cot() const;
108 Interval sec() const;
109 Interval csc() const;
110 Interval asin() const;
111 Interval acos() const;
112 Interval atan() const;
113 Interval acot() const;
114 Interval asec() const;
115 Interval acsc() const;
116 Interval sinh() const;
117 Interval cosh() const;
118 Interval tanh() const;
119 Interval coth() const;
120 Interval sech() const;
121 Interval csch() const;
122 Interval asinh() const;
123 Interval acosh() const;
124 Interval atanh() const;
125 Interval acoth() const;
126 Interval asech() const;
127 Interval acsch() const;
128
129 // binary operators
130 Interval operator+(const Number &value) const;
131 Interval operator-(const Number &value) const;
132 Interval operator*(const Number &value) const;
133 Interval operator/(const Number &value) const;
134 Interval operator%(const Number &value) const;
135 Interval operator^(const Number &value) const;
136 Interval operator+(const Interval &other) const;
137 Interval operator-(const Interval &other) const;
138 Interval operator*(const Interval &other) const;
139 Interval operator/(const Interval &other) const;
140 Interval operator%(const Interval &other) const;
141 Interval operator^(const Interval &other) const;
142 Interval add(const Number &value) const;
143 Interval add(const Interval &other) const;
144 Interval sub(const Number &value) const;
145 Interval sub(const Interval &other) const;
146 Interval mul(const Number &value) const;
147 Interval mul(const Interval &other) const;
148 Interval divReal(const Number &value) const;
149 Interval divReal(const Interval &other) const;
150 Interval divInt(const Number &value) const;
151 Interval divInt(const Interval &other) const;
152 Interval mod(const Number &value) const;
153 Interval mod(const Interval &other) const;
154 Interval pow(const Number &exp) const;
155 Interval pow(const Interval &exp) const;
156 Interval atan2(const Number &x) const;
157 Interval atan2(const Interval &x) const;
158 Interval log(const Number &base) const;
159 Interval log(const Interval &base) const;
160
161 // advanced functions
162 Interval operate(const NODE_KIND &kind) const;
163 Interval operate(const NODE_KIND &kind, const Number &value) const;
164 Interval operate(const NODE_KIND &kind, const Interval &other) const;
165
166 // comparison operators
167 bool operator==(const Interval &other) const;
168 bool operator!=(const Interval &other) const;
169 bool operator<(const Interval &other) const;
170 bool operator<=(const Interval &other) const;
171 bool operator>(const Interval &other) const;
172 bool operator>=(const Interval &other) const;
173
174 // assignment operators
175 Interval &operator+=(const Number &value);
176 Interval &operator-=(const Number &value);
177 Interval &operator*=(const Number &value);
178 Interval &operator/=(const Number &value);
179
180 // static method, for handling multiple intervals
181 static std::vector<Interval>
182 unionMulti(const std::vector<Interval> &intervals);
183};
184
185inline Interval EmptyInterval = Interval(1, -1, false, false);
188
189} // namespace stabilizer::parser
190
191#endif
void getIntegers(std::vector< Number > &integers) const
Definition interval.cpp:106
Interval operator~() const
Definition interval.cpp:396
Interval add(const Number &value) const
Interval operator--() const
Definition interval.cpp:378
bool isIntersectingWith(const Interval &other) const
Definition interval.cpp:185
bool isSupersetOf(const Interval &other) const
Definition interval.cpp:154
void setLeftClosed(bool leftClosed)
Definition interval.cpp:76
void setUpper(const Number &upper)
Definition interval.cpp:69
Interval & operator/=(const Number &value)
void setLower(const Number &lower)
Definition interval.cpp:62
Interval divReal(const Number &value) const
Interval operator+() const
Definition interval.cpp:390
Interval log(const Number &base) const
Interval mul(const Number &value) const
Interval operator!() const
Definition interval.cpp:402
bool operator==(const Interval &other) const
Definition interval.cpp:53
bool operator<=(const Interval &other) const
Interval intersection(const Interval &other) const
Definition interval.cpp:193
Interval & operator-=(const Number &value)
Interval operator%(const Number &value) const
Interval operate(const NODE_KIND &kind) const
Interval unionWith(const Interval &other) const
Definition interval.cpp:209
bool operator<(const Interval &other) const
Interval mod(const Number &value) const
static std::vector< Interval > unionMulti(const std::vector< Interval > &intervals)
Definition interval.cpp:324
Interval operator++() const
Definition interval.cpp:372
std::vector< Interval > difference(const Interval &other) const
Definition interval.cpp:269
std::string toString() const
Definition interval.cpp:88
bool operator!=(const Interval &other) const
Definition interval.cpp:58
bool isSubsetEqOf(const Interval &other) const
Definition interval.cpp:234
bool isDisjointFrom(const Interval &other) const
Definition interval.cpp:170
size_t getIntervalIntCount() const
Definition interval.cpp:244
bool contains(const Number &value) const
Definition interval.cpp:129
Interval operator/(const Number &value) const
Interval pow(const Number &exp) const
Interval divInt(const Number &value) const
Interval & operator*=(const Number &value)
Interval & operator=(const Interval &other)
Definition interval.cpp:43
bool operator>=(const Interval &other) const
Interval operator-() const
Definition interval.cpp:384
void setRightClosed(bool rightClosed)
Definition interval.cpp:78
Interval & operator+=(const Number &value)
Interval atan2(const Number &x) const
bool operator>(const Interval &other) const
Interval safeSqrt() const
Definition interval.cpp:654
Interval operator*(const Number &value) const
Interval sub(const Number &value) const
Interval log(const Interval &base) const
Interval operator^(const Number &value) const
bool isSubsetOf(const Interval &other) const
Definition interval.cpp:137
static Number positiveInfinity()
Definition number.cpp:1199
static Number negativeInfinity()
Definition number.cpp:1194
Interval EmptyInterval
Definition interval.h:185
Interval FullInterval
Definition interval.h:186