
(FPCore (K m n M l) :precision binary64 (* (cos (- (/ (* K (+ m n)) 2.0) M)) (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l (fabs (- m n)))))))
double code(double K, double m, double n, double M, double l) {
return cos((((K * (m + n)) / 2.0) - M)) * exp((-pow((((m + n) / 2.0) - M), 2.0) - (l - fabs((m - n)))));
}
real(8) function code(k, m, n, m_1, l)
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8), intent (in) :: n
real(8), intent (in) :: m_1
real(8), intent (in) :: l
code = cos((((k * (m + n)) / 2.0d0) - m_1)) * exp((-((((m + n) / 2.0d0) - m_1) ** 2.0d0) - (l - abs((m - n)))))
end function
public static double code(double K, double m, double n, double M, double l) {
return Math.cos((((K * (m + n)) / 2.0) - M)) * Math.exp((-Math.pow((((m + n) / 2.0) - M), 2.0) - (l - Math.abs((m - n)))));
}
def code(K, m, n, M, l): return math.cos((((K * (m + n)) / 2.0) - M)) * math.exp((-math.pow((((m + n) / 2.0) - M), 2.0) - (l - math.fabs((m - n)))))
function code(K, m, n, M, l) return Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * exp(Float64(Float64(-(Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)) - Float64(l - abs(Float64(m - n)))))) end
function tmp = code(K, m, n, M, l) tmp = cos((((K * (m + n)) / 2.0) - M)) * exp((-((((m + n) / 2.0) - M) ^ 2.0) - (l - abs((m - n))))); end
code[K_, m_, n_, M_, l_] := N[(N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[((-N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]) - N[(l - N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (K m n M l) :precision binary64 (* (cos (- (/ (* K (+ m n)) 2.0) M)) (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l (fabs (- m n)))))))
double code(double K, double m, double n, double M, double l) {
return cos((((K * (m + n)) / 2.0) - M)) * exp((-pow((((m + n) / 2.0) - M), 2.0) - (l - fabs((m - n)))));
}
real(8) function code(k, m, n, m_1, l)
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8), intent (in) :: n
real(8), intent (in) :: m_1
real(8), intent (in) :: l
code = cos((((k * (m + n)) / 2.0d0) - m_1)) * exp((-((((m + n) / 2.0d0) - m_1) ** 2.0d0) - (l - abs((m - n)))))
end function
public static double code(double K, double m, double n, double M, double l) {
return Math.cos((((K * (m + n)) / 2.0) - M)) * Math.exp((-Math.pow((((m + n) / 2.0) - M), 2.0) - (l - Math.abs((m - n)))));
}
def code(K, m, n, M, l): return math.cos((((K * (m + n)) / 2.0) - M)) * math.exp((-math.pow((((m + n) / 2.0) - M), 2.0) - (l - math.fabs((m - n)))))
function code(K, m, n, M, l) return Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * exp(Float64(Float64(-(Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)) - Float64(l - abs(Float64(m - n)))))) end
function tmp = code(K, m, n, M, l) tmp = cos((((K * (m + n)) / 2.0) - M)) * exp((-((((m + n) / 2.0) - M) ^ 2.0) - (l - abs((m - n))))); end
code[K_, m_, n_, M_, l_] := N[(N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[((-N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]) - N[(l - N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)}
\end{array}
NOTE: m and n should be sorted in increasing order before calling this function. (FPCore (K m n M l) :precision binary64 (* (cos M) (exp (- m (+ (+ n l) (pow (- (* 0.5 (+ m n)) M) 2.0))))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
return cos(M) * exp((m - ((n + l) + pow(((0.5 * (m + n)) - M), 2.0))));
}
NOTE: m and n should be sorted in increasing order before calling this function.
real(8) function code(k, m, n, m_1, l)
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8), intent (in) :: n
real(8), intent (in) :: m_1
real(8), intent (in) :: l
code = cos(m_1) * exp((m - ((n + l) + (((0.5d0 * (m + n)) - m_1) ** 2.0d0))))
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
return Math.cos(M) * Math.exp((m - ((n + l) + Math.pow(((0.5 * (m + n)) - M), 2.0))));
}
[m, n] = sort([m, n]) def code(K, m, n, M, l): return math.cos(M) * math.exp((m - ((n + l) + math.pow(((0.5 * (m + n)) - M), 2.0))))
m, n = sort([m, n]) function code(K, m, n, M, l) return Float64(cos(M) * exp(Float64(m - Float64(Float64(n + l) + (Float64(Float64(0.5 * Float64(m + n)) - M) ^ 2.0))))) end
m, n = num2cell(sort([m, n])){:}
function tmp = code(K, m, n, M, l)
tmp = cos(M) * exp((m - ((n + l) + (((0.5 * (m + n)) - M) ^ 2.0))));
end
NOTE: m and n should be sorted in increasing order before calling this function. code[K_, m_, n_, M_, l_] := N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(m - N[(N[(n + l), $MachinePrecision] + N[Power[N[(N[(0.5 * N[(m + n), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\cos M \cdot e^{m - \left(\left(n + \ell\right) + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)}
\end{array}
Initial program 77.2%
*-commutative77.2%
associate-*r/77.2%
associate--r-77.2%
+-commutative77.2%
associate-+r-77.2%
unsub-neg77.2%
associate--r+77.2%
+-commutative77.2%
associate--r+77.2%
Simplified77.2%
Taylor expanded in K around 0 98.1%
cos-neg98.1%
Simplified98.1%
associate--l-98.1%
sub-neg98.1%
add-sqr-sqrt53.4%
fabs-sqr53.4%
add-sqr-sqrt98.1%
div-inv98.1%
metadata-eval98.1%
Applied egg-rr98.1%
sub-neg98.1%
associate--l-98.1%
associate-+r+98.1%
*-commutative98.1%
+-commutative98.1%
Simplified98.1%
Final simplification98.1%
NOTE: m and n should be sorted in increasing order before calling this function. (FPCore (K m n M l) :precision binary64 (* (cos M) (exp (- m (+ (+ n l) (* M M))))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
return cos(M) * exp((m - ((n + l) + (M * M))));
}
NOTE: m and n should be sorted in increasing order before calling this function.
real(8) function code(k, m, n, m_1, l)
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8), intent (in) :: n
real(8), intent (in) :: m_1
real(8), intent (in) :: l
code = cos(m_1) * exp((m - ((n + l) + (m_1 * m_1))))
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
return Math.cos(M) * Math.exp((m - ((n + l) + (M * M))));
}
[m, n] = sort([m, n]) def code(K, m, n, M, l): return math.cos(M) * math.exp((m - ((n + l) + (M * M))))
m, n = sort([m, n]) function code(K, m, n, M, l) return Float64(cos(M) * exp(Float64(m - Float64(Float64(n + l) + Float64(M * M))))) end
m, n = num2cell(sort([m, n])){:}
function tmp = code(K, m, n, M, l)
tmp = cos(M) * exp((m - ((n + l) + (M * M))));
end
NOTE: m and n should be sorted in increasing order before calling this function. code[K_, m_, n_, M_, l_] := N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(m - N[(N[(n + l), $MachinePrecision] + N[(M * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\cos M \cdot e^{m - \left(\left(n + \ell\right) + M \cdot M\right)}
\end{array}
Initial program 77.2%
*-commutative77.2%
associate-*r/77.2%
associate--r-77.2%
+-commutative77.2%
associate-+r-77.2%
unsub-neg77.2%
associate--r+77.2%
+-commutative77.2%
associate--r+77.2%
Simplified77.2%
Taylor expanded in K around 0 98.1%
cos-neg98.1%
Simplified98.1%
associate--l-98.1%
sub-neg98.1%
add-sqr-sqrt53.4%
fabs-sqr53.4%
add-sqr-sqrt98.1%
div-inv98.1%
metadata-eval98.1%
Applied egg-rr98.1%
sub-neg98.1%
associate--l-98.1%
associate-+r+98.1%
*-commutative98.1%
+-commutative98.1%
Simplified98.1%
Taylor expanded in M around inf 73.1%
unpow273.1%
Simplified73.1%
Final simplification73.1%
NOTE: m and n should be sorted in increasing order before calling this function. (FPCore (K m n M l) :precision binary64 (exp (- m (+ (+ n l) (* M M)))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
return exp((m - ((n + l) + (M * M))));
}
NOTE: m and n should be sorted in increasing order before calling this function.
real(8) function code(k, m, n, m_1, l)
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8), intent (in) :: n
real(8), intent (in) :: m_1
real(8), intent (in) :: l
code = exp((m - ((n + l) + (m_1 * m_1))))
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
return Math.exp((m - ((n + l) + (M * M))));
}
[m, n] = sort([m, n]) def code(K, m, n, M, l): return math.exp((m - ((n + l) + (M * M))))
m, n = sort([m, n]) function code(K, m, n, M, l) return exp(Float64(m - Float64(Float64(n + l) + Float64(M * M)))) end
m, n = num2cell(sort([m, n])){:}
function tmp = code(K, m, n, M, l)
tmp = exp((m - ((n + l) + (M * M))));
end
NOTE: m and n should be sorted in increasing order before calling this function. code[K_, m_, n_, M_, l_] := N[Exp[N[(m - N[(N[(n + l), $MachinePrecision] + N[(M * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
e^{m - \left(\left(n + \ell\right) + M \cdot M\right)}
\end{array}
Initial program 77.2%
*-commutative77.2%
associate-*r/77.2%
associate--r-77.2%
+-commutative77.2%
associate-+r-77.2%
unsub-neg77.2%
associate--r+77.2%
+-commutative77.2%
associate--r+77.2%
Simplified77.2%
Taylor expanded in K around 0 98.1%
cos-neg98.1%
Simplified98.1%
associate--l-98.1%
sub-neg98.1%
add-sqr-sqrt53.4%
fabs-sqr53.4%
add-sqr-sqrt98.1%
div-inv98.1%
metadata-eval98.1%
Applied egg-rr98.1%
sub-neg98.1%
associate--l-98.1%
associate-+r+98.1%
*-commutative98.1%
+-commutative98.1%
Simplified98.1%
Taylor expanded in M around inf 73.1%
unpow273.1%
Simplified73.1%
Taylor expanded in M around 0 72.7%
Final simplification72.7%
NOTE: m and n should be sorted in increasing order before calling this function. (FPCore (K m n M l) :precision binary64 (exp (- l)))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
return exp(-l);
}
NOTE: m and n should be sorted in increasing order before calling this function.
real(8) function code(k, m, n, m_1, l)
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8), intent (in) :: n
real(8), intent (in) :: m_1
real(8), intent (in) :: l
code = exp(-l)
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
return Math.exp(-l);
}
[m, n] = sort([m, n]) def code(K, m, n, M, l): return math.exp(-l)
m, n = sort([m, n]) function code(K, m, n, M, l) return exp(Float64(-l)) end
m, n = num2cell(sort([m, n])){:}
function tmp = code(K, m, n, M, l)
tmp = exp(-l);
end
NOTE: m and n should be sorted in increasing order before calling this function. code[K_, m_, n_, M_, l_] := N[Exp[(-l)], $MachinePrecision]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
e^{-\ell}
\end{array}
Initial program 77.2%
*-commutative77.2%
associate-*r/77.2%
associate--r-77.2%
+-commutative77.2%
associate-+r-77.2%
unsub-neg77.2%
associate--r+77.2%
+-commutative77.2%
associate--r+77.2%
Simplified77.2%
Taylor expanded in l around inf 25.2%
neg-mul-125.2%
Simplified25.2%
Taylor expanded in K around 0 31.6%
cos-neg31.6%
Simplified31.6%
Taylor expanded in M around 0 31.2%
Final simplification31.2%
NOTE: m and n should be sorted in increasing order before calling this function. (FPCore (K m n M l) :precision binary64 (cos M))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
return cos(M);
}
NOTE: m and n should be sorted in increasing order before calling this function.
real(8) function code(k, m, n, m_1, l)
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8), intent (in) :: n
real(8), intent (in) :: m_1
real(8), intent (in) :: l
code = cos(m_1)
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
return Math.cos(M);
}
[m, n] = sort([m, n]) def code(K, m, n, M, l): return math.cos(M)
m, n = sort([m, n]) function code(K, m, n, M, l) return cos(M) end
m, n = num2cell(sort([m, n])){:}
function tmp = code(K, m, n, M, l)
tmp = cos(M);
end
NOTE: m and n should be sorted in increasing order before calling this function. code[K_, m_, n_, M_, l_] := N[Cos[M], $MachinePrecision]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\cos M
\end{array}
Initial program 77.2%
*-commutative77.2%
associate-*r/77.2%
associate--r-77.2%
+-commutative77.2%
associate-+r-77.2%
unsub-neg77.2%
associate--r+77.2%
+-commutative77.2%
associate--r+77.2%
Simplified77.2%
Taylor expanded in m around -inf 37.4%
+-commutative37.4%
mul-1-neg37.4%
unsub-neg37.4%
*-commutative37.4%
unpow237.4%
associate-*l*37.4%
*-commutative37.4%
Simplified37.4%
Taylor expanded in m around 0 6.1%
Taylor expanded in n around 0 6.7%
cos-neg6.7%
Simplified6.7%
Final simplification6.7%
NOTE: m and n should be sorted in increasing order before calling this function. (FPCore (K m n M l) :precision binary64 1.0)
assert(m < n);
double code(double K, double m, double n, double M, double l) {
return 1.0;
}
NOTE: m and n should be sorted in increasing order before calling this function.
real(8) function code(k, m, n, m_1, l)
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8), intent (in) :: n
real(8), intent (in) :: m_1
real(8), intent (in) :: l
code = 1.0d0
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
return 1.0;
}
[m, n] = sort([m, n]) def code(K, m, n, M, l): return 1.0
m, n = sort([m, n]) function code(K, m, n, M, l) return 1.0 end
m, n = num2cell(sort([m, n])){:}
function tmp = code(K, m, n, M, l)
tmp = 1.0;
end
NOTE: m and n should be sorted in increasing order before calling this function. code[K_, m_, n_, M_, l_] := 1.0
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
1
\end{array}
Initial program 77.2%
*-commutative77.2%
associate-*r/77.2%
associate--r-77.2%
+-commutative77.2%
associate-+r-77.2%
unsub-neg77.2%
associate--r+77.2%
+-commutative77.2%
associate--r+77.2%
Simplified77.2%
Taylor expanded in m around -inf 37.4%
+-commutative37.4%
mul-1-neg37.4%
unsub-neg37.4%
*-commutative37.4%
unpow237.4%
associate-*l*37.4%
*-commutative37.4%
Simplified37.4%
Taylor expanded in m around 0 6.1%
Taylor expanded in n around 0 6.7%
cos-neg6.7%
Simplified6.7%
Taylor expanded in M around 0 6.7%
Final simplification6.7%
herbie shell --seed 2023215
(FPCore (K m n M l)
:name "Maksimov and Kolovsky, Equation (32)"
:precision binary64
(* (cos (- (/ (* K (+ m n)) 2.0) M)) (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l (fabs (- m n)))))))