-
Notifications
You must be signed in to change notification settings - Fork 1
/
Linear.cpp
86 lines (67 loc) · 1.66 KB
/
Linear.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "Vars.h"
#include "Linear.h"
#include "utils.h"
void Linear::add_var(char type, int idx, int val) {
vars.add_var(type, idx, val);
}
bool Linear::has_var(char type, int idx) {
return vars.has_var(type, idx);
}
int Linear::num_vars() {
return vars.num_vars();
}
mpz_class Linear::get_var(char type, int idx) {
return vars.get_var(type, idx);
}
void Linear::add(Linear& other) {
real = (real + other.real) % mod;
constant = (constant + other.constant) % mod;
vars.add(other.vars);
}
void Linear::sub(Linear& other) {
real = (real - other.real + mod) % mod;
constant = (constant - other.constant + mod) % mod;
vars.sub(other.vars);
}
void Linear::mul(mpz_class v) {
real = (real * v) % mod;
constant = (constant * v) % mod;
vars.mul(v);
}
void Linear::div(mpz_class v) {
v = modinv(v, mod);
mul(v);
}
void Linear::index_temp_vars(map<int, vector<int>>& index, int idx) {
vars.index_temp_vars(index, idx, *this);
}
void Linear::assign_temp_vars(Linear& other, map<int, vector<int>>& index, int idx) {
other.vars.index_temp_vars(index, idx, *this, true);
}
void Linear::to_str() {
vars.str(constant);
}
int Linear::equation_cost() {
return vars.cost();
}
bool Linear::is_const() {
return vars.is_empty();
}
bool Linear::is_zero() {
if (constant != 0) {
return false;
}
return vars.is_zero();
}
bool Linear::has_temp_var() {
return vars.has_temp_var();
}
bool Linear::has_several_temps() {
return vars.has_several_temps();
}
map<int, mpz_class>::iterator Linear::vars_begin() {
return vars.vars_begin();
}
map<int, mpz_class>::iterator Linear::vars_end() {
return vars.vars_end();
}