11 return int(val < 0 ? floor(val + 0.5) : ceil(val - 0.5));
34 idum = IA * (idum - k * IQ) - IR * k;
38 double ran = AM * idum;
47 int max_val = a.size() + b.size();
50 std::map<char, int> DA;
53 Eigen::MatrixXi H(a.size() + 2, b.size() + 2);
57 for (
int i = 0; i <= a.size(); ++i) {
59 H(i + 1, 0) = max_val;
62 for (
int j = 0; j <= b.size(); ++j) {
64 H(0, j + 1) = max_val;
70 for (
int i = 1; i <= a.size(); ++i) {
73 for (
int j = 1; j <= b.size(); ++j) {
74 int i1 = DA[b[j - 1]];
77 if (a[i - 1] == b[j - 1]) {
82 H(i + 1, j + 1) =
min(
min(H(i, j) + cost,
85 H(i1, j1) + (i - i1 - 1) + 1 + (j - j1 - 1)));
89 return H(a.size() + 1, b.size() + 1);
94 int gcf(
int i1,
int i2) {
97 while (i1 != i2 && i1 != 1 && i2 != 1) {
113 int lcm(
int i1,
int i2) {
return std::abs(i1 * (i2 /
gcf(i1, i2))); }
120 double gaussian(
double a,
double x,
double b,
double c) {
121 return a * exp(-((x - b) * (x - b)) / (c * c));
131 if (expon % 2)
return 0.0;
133 double m = pow(sigma, expon);
136 while (expon - 2 > 0) {
151 for (
int i = 0; i <= expon; i++) {
172 long sgn(val < 0 ? -1 : 1);
175 long lim(
max(
long(100),
long(1 / (10 * tol))));
176 for (
long i = 1; i < lim + 1; i++) {
177 tdenom = double(i) / val;
178 tnum = val / double(i);
181 denominator =
round(tdenom);
200 std::stringstream tstr;
209 double tval(val), tdenom, tnum;
211 for (
int ipow = 1; ipow < max_pow + 1; ipow++) {
212 for (
int i = 1; i < lim + 1; i++) {
213 tdenom = double(i) / tval;
214 tnum = tval / double(i);
217 idenom =
round(tdenom);
226 tstr << inum <<
'/' << idenom;
230 tstr <<
"\\sqrt{" << inum;
231 if (idenom != 1) tstr <<
'/' << idenom;
236 if (idenom != 1) tstr <<
'/' << idenom;
237 tstr <<
")^{1/" << ipow <<
"}";
249 char prepend_char ) {
250 max_i =
max(i, max_i);
252 while (max_i /= 10)
length++;
256 std::string result(
length - tresult.size(), prepend_char);
257 return result.append(tresult);
263 if (b < 0)
return mod(-a, -b);
266 if (ret < 0) ret += b;
274 return -pow(-number, 1.0 / 3);
278 return pow(number, 1.0 / 3);
std::string to_string(ENUM val)
Return string representation of enum class.
Eigen::CwiseUnaryOp< decltype(Local::round_l< typename Derived::Scalar >), const Derived > round(const Eigen::MatrixBase< Derived > &val)
Round Eigen::MatrixXd.
double gaussian_moment(int expon, double sigma)
void nearest_rational_number(double val, long &numerator, long &denominator, double tol=TOL)
double cuberoot(double number)
IntType nchoosek(IntType n, IntType k)
std::string to_sequential_string(Index i, Index max_i, char prepend_char='0')
int lcm(const Array< int > &series)
Find least common multiple.
bool almost_zero(const T &val, double tol=TOL)
If T is not integral, use std::abs(val) < tol;.
int dl_string_dist(const std::string &a, const std::string &b)
Computes the Damerescau-Levenshtein distance – the number of edits (deletions, insertions,...
T min(const T &A, const T &B)
std::string irrational_to_tex_string(double val, int lim, int max_pow=2)
double gaussian(double a, double x, double b, double c)
INDEX_TYPE Index
For long integer indexing:
int gcf(int i1, int i2)
Find greatest common factor.
T max(const T &A, const T &B)
double length(const Eigen::MatrixBase< Derived > &value)