
(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}
(FPCore (K m n M l)
:precision binary64
(let* ((t_0 (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l (fabs (- m n)))))
(t_1 (exp t_0))
(t_2 (* (cos (- (/ (* K (+ m n)) 2.0) M)) t_1)))
(if (<= t_2 2.0) t_2 (* t_0 t_1))))
double code(double K, double m, double n, double M, double l) {
double t_0 = -pow((((m + n) / 2.0) - M), 2.0) - (l - fabs((m - n)));
double t_1 = exp(t_0);
double t_2 = cos((((K * (m + n)) / 2.0) - M)) * t_1;
double tmp;
if (t_2 <= 2.0) {
tmp = t_2;
} else {
tmp = t_0 * t_1;
}
return tmp;
}
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
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = -((((m + n) / 2.0d0) - m_1) ** 2.0d0) - (l - abs((m - n)))
t_1 = exp(t_0)
t_2 = cos((((k * (m + n)) / 2.0d0) - m_1)) * t_1
if (t_2 <= 2.0d0) then
tmp = t_2
else
tmp = t_0 * t_1
end if
code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
double t_0 = -Math.pow((((m + n) / 2.0) - M), 2.0) - (l - Math.abs((m - n)));
double t_1 = Math.exp(t_0);
double t_2 = Math.cos((((K * (m + n)) / 2.0) - M)) * t_1;
double tmp;
if (t_2 <= 2.0) {
tmp = t_2;
} else {
tmp = t_0 * t_1;
}
return tmp;
}
def code(K, m, n, M, l): t_0 = -math.pow((((m + n) / 2.0) - M), 2.0) - (l - math.fabs((m - n))) t_1 = math.exp(t_0) t_2 = math.cos((((K * (m + n)) / 2.0) - M)) * t_1 tmp = 0 if t_2 <= 2.0: tmp = t_2 else: tmp = t_0 * t_1 return tmp
function code(K, m, n, M, l) t_0 = Float64(Float64(-(Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)) - Float64(l - abs(Float64(m - n)))) t_1 = exp(t_0) t_2 = Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * t_1) tmp = 0.0 if (t_2 <= 2.0) tmp = t_2; else tmp = Float64(t_0 * t_1); end return tmp end
function tmp_2 = code(K, m, n, M, l) t_0 = -((((m + n) / 2.0) - M) ^ 2.0) - (l - abs((m - n))); t_1 = exp(t_0); t_2 = cos((((K * (m + n)) / 2.0) - M)) * t_1; tmp = 0.0; if (t_2 <= 2.0) tmp = t_2; else tmp = t_0 * t_1; end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = 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]}, Block[{t$95$1 = N[Exp[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, 2.0], t$95$2, N[(t$95$0 * t$95$1), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)\\
t_1 := e^{t\_0}\\
t_2 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot t\_1\\
\mathbf{if}\;t\_2 \leq 2:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot t\_1\\
\end{array}
\end{array}
if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < 2Initial program 96.0%
if 2 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) Initial program 22.5%
Taylor expanded in K around 0
Applied rewrites33.8%
(FPCore (K m n M l)
:precision binary64
(let* ((t_0 (- (/ (+ m n) 2.0) M)) (t_1 (/ (* K (+ m n)) 2.0)))
(if (<=
(* (cos (- t_1 M)) (exp (- (- (pow t_0 2.0)) (- l (fabs (- m n))))))
0.0)
t_1
(cos t_0))))
double code(double K, double m, double n, double M, double l) {
double t_0 = ((m + n) / 2.0) - M;
double t_1 = (K * (m + n)) / 2.0;
double tmp;
if ((cos((t_1 - M)) * exp((-pow(t_0, 2.0) - (l - fabs((m - n)))))) <= 0.0) {
tmp = t_1;
} else {
tmp = cos(t_0);
}
return tmp;
}
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
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = ((m + n) / 2.0d0) - m_1
t_1 = (k * (m + n)) / 2.0d0
if ((cos((t_1 - m_1)) * exp((-(t_0 ** 2.0d0) - (l - abs((m - n)))))) <= 0.0d0) then
tmp = t_1
else
tmp = cos(t_0)
end if
code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
double t_0 = ((m + n) / 2.0) - M;
double t_1 = (K * (m + n)) / 2.0;
double tmp;
if ((Math.cos((t_1 - M)) * Math.exp((-Math.pow(t_0, 2.0) - (l - Math.abs((m - n)))))) <= 0.0) {
tmp = t_1;
} else {
tmp = Math.cos(t_0);
}
return tmp;
}
def code(K, m, n, M, l): t_0 = ((m + n) / 2.0) - M t_1 = (K * (m + n)) / 2.0 tmp = 0 if (math.cos((t_1 - M)) * math.exp((-math.pow(t_0, 2.0) - (l - math.fabs((m - n)))))) <= 0.0: tmp = t_1 else: tmp = math.cos(t_0) return tmp
function code(K, m, n, M, l) t_0 = Float64(Float64(Float64(m + n) / 2.0) - M) t_1 = Float64(Float64(K * Float64(m + n)) / 2.0) tmp = 0.0 if (Float64(cos(Float64(t_1 - M)) * exp(Float64(Float64(-(t_0 ^ 2.0)) - Float64(l - abs(Float64(m - n)))))) <= 0.0) tmp = t_1; else tmp = cos(t_0); end return tmp end
function tmp_2 = code(K, m, n, M, l) t_0 = ((m + n) / 2.0) - M; t_1 = (K * (m + n)) / 2.0; tmp = 0.0; if ((cos((t_1 - M)) * exp((-(t_0 ^ 2.0) - (l - abs((m - n)))))) <= 0.0) tmp = t_1; else tmp = cos(t_0); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]}, Block[{t$95$1 = N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(t$95$1 - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[((-N[Power[t$95$0, 2.0], $MachinePrecision]) - N[(l - N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0], t$95$1, N[Cos[t$95$0], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{m + n}{2} - M\\
t_1 := \frac{K \cdot \left(m + n\right)}{2}\\
\mathbf{if}\;\cos \left(t\_1 - M\right) \cdot e^{\left(-{t\_0}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \leq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\cos t\_0\\
\end{array}
\end{array}
if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < -0.0Initial program 96.8%
Taylor expanded in K around 0
Applied rewrites7.4%
if -0.0 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) Initial program 29.8%
Taylor expanded in K around 0
Applied rewrites10.0%
Taylor expanded in K around 0
Applied rewrites10.3%
Taylor expanded in K around 0
Applied rewrites12.2%
(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}
Initial program 75.6%
(FPCore (K m n M l) :precision binary64 (/ (* K (+ m n)) 2.0))
double code(double K, double m, double n, double M, double l) {
return (K * (m + n)) / 2.0;
}
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 = (k * (m + n)) / 2.0d0
end function
public static double code(double K, double m, double n, double M, double l) {
return (K * (m + n)) / 2.0;
}
def code(K, m, n, M, l): return (K * (m + n)) / 2.0
function code(K, m, n, M, l) return Float64(Float64(K * Float64(m + n)) / 2.0) end
function tmp = code(K, m, n, M, l) tmp = (K * (m + n)) / 2.0; end
code[K_, m_, n_, M_, l_] := N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{K \cdot \left(m + n\right)}{2}
\end{array}
Initial program 75.6%
Taylor expanded in K around 0
Applied rewrites6.0%
(FPCore (K m n M l) :precision binary64 (* K (+ m n)))
double code(double K, double m, double n, double M, double l) {
return K * (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 = k * (m + n)
end function
public static double code(double K, double m, double n, double M, double l) {
return K * (m + n);
}
def code(K, m, n, M, l): return K * (m + n)
function code(K, m, n, M, l) return Float64(K * Float64(m + n)) end
function tmp = code(K, m, n, M, l) tmp = K * (m + n); end
code[K_, m_, n_, M_, l_] := N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
K \cdot \left(m + n\right)
\end{array}
Initial program 75.6%
Taylor expanded in K around 0
Applied rewrites5.4%
Taylor expanded in K around 0
Applied rewrites6.0%
(FPCore (K m n M l) :precision binary64 (+ m n))
double code(double K, double m, double n, double M, double l) {
return 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 = m + n
end function
public static double code(double K, double m, double n, double M, double l) {
return m + n;
}
def code(K, m, n, M, l): return m + n
function code(K, m, n, M, l) return Float64(m + n) end
function tmp = code(K, m, n, M, l) tmp = m + n; end
code[K_, m_, n_, M_, l_] := N[(m + n), $MachinePrecision]
\begin{array}{l}
\\
m + n
\end{array}
Initial program 75.6%
Taylor expanded in K around 0
Applied rewrites5.4%
Taylor expanded in K around 0
Applied rewrites2.6%
herbie shell --seed 2024321
(FPCore (K m n M l)
:name "Maksimov and Kolovsky, Equation (32)"
:precision binary64
:pre (TRUE)
(* (cos (- (/ (* K (+ m n)) 2.0) M)) (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l (fabs (- m n)))))))