
(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 9 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 (* (cos M) (exp (- (- (fabs (- n m)) l) (pow (- (/ (+ m n) 2.0) M) 2.0)))))
double code(double K, double m, double n, double M, double l) {
return cos(M) * exp(((fabs((n - m)) - l) - pow((((m + n) / 2.0) - M), 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 = cos(m_1) * exp(((abs((n - m)) - l) - ((((m + n) / 2.0d0) - m_1) ** 2.0d0)))
end function
public static double code(double K, double m, double n, double M, double l) {
return Math.cos(M) * Math.exp(((Math.abs((n - m)) - l) - Math.pow((((m + n) / 2.0) - M), 2.0)));
}
def code(K, m, n, M, l): return math.cos(M) * math.exp(((math.fabs((n - m)) - l) - math.pow((((m + n) / 2.0) - M), 2.0)))
function code(K, m, n, M, l) return Float64(cos(M) * exp(Float64(Float64(abs(Float64(n - m)) - l) - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)))) end
function tmp = code(K, m, n, M, l) tmp = cos(M) * exp(((abs((n - m)) - l) - ((((m + n) / 2.0) - M) ^ 2.0))); end
code[K_, m_, n_, M_, l_] := N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos M \cdot e^{\left(\left|n - m\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
\end{array}
Initial program 77.9%
associate-/l*77.6%
+-commutative77.6%
fabs-sub77.6%
+-commutative77.6%
Simplified77.6%
Taylor expanded in K around 0 97.1%
cos-neg97.1%
Simplified97.1%
Final simplification97.1%
(FPCore (K m n M l)
:precision binary64
(if (<= n 10000.0)
(*
(cos (- (/ (* n K) 2.0) M))
(exp (- (- l) (pow (- (/ (+ m n) 2.0) M) 2.0))))
(* (cos M) (exp (* -0.25 (pow n 2.0))))))
double code(double K, double m, double n, double M, double l) {
double tmp;
if (n <= 10000.0) {
tmp = cos((((n * K) / 2.0) - M)) * exp((-l - pow((((m + n) / 2.0) - M), 2.0)));
} else {
tmp = cos(M) * exp((-0.25 * pow(n, 2.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) :: tmp
if (n <= 10000.0d0) then
tmp = cos((((n * k) / 2.0d0) - m_1)) * exp((-l - ((((m + n) / 2.0d0) - m_1) ** 2.0d0)))
else
tmp = cos(m_1) * exp(((-0.25d0) * (n ** 2.0d0)))
end if
code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
double tmp;
if (n <= 10000.0) {
tmp = Math.cos((((n * K) / 2.0) - M)) * Math.exp((-l - Math.pow((((m + n) / 2.0) - M), 2.0)));
} else {
tmp = Math.cos(M) * Math.exp((-0.25 * Math.pow(n, 2.0)));
}
return tmp;
}
def code(K, m, n, M, l): tmp = 0 if n <= 10000.0: tmp = math.cos((((n * K) / 2.0) - M)) * math.exp((-l - math.pow((((m + n) / 2.0) - M), 2.0))) else: tmp = math.cos(M) * math.exp((-0.25 * math.pow(n, 2.0))) return tmp
function code(K, m, n, M, l) tmp = 0.0 if (n <= 10000.0) tmp = Float64(cos(Float64(Float64(Float64(n * K) / 2.0) - M)) * exp(Float64(Float64(-l) - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)))); else tmp = Float64(cos(M) * exp(Float64(-0.25 * (n ^ 2.0)))); end return tmp end
function tmp_2 = code(K, m, n, M, l) tmp = 0.0; if (n <= 10000.0) tmp = cos((((n * K) / 2.0) - M)) * exp((-l - ((((m + n) / 2.0) - M) ^ 2.0))); else tmp = cos(M) * exp((-0.25 * (n ^ 2.0))); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := If[LessEqual[n, 10000.0], N[(N[Cos[N[(N[(N[(n * K), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[((-l) - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq 10000:\\
\;\;\;\;\cos \left(\frac{n \cdot K}{2} - M\right) \cdot e^{\left(-\ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {n}^{2}}\\
\end{array}
\end{array}
if n < 1e4Initial program 77.0%
Taylor expanded in l around inf 77.0%
Taylor expanded in m around 0 89.1%
if 1e4 < n Initial program 81.6%
associate-/l*81.6%
+-commutative81.6%
fabs-sub81.6%
+-commutative81.6%
Simplified81.6%
Taylor expanded in K around 0 100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in n around inf 98.0%
Final simplification90.8%
(FPCore (K m n M l)
:precision binary64
(if (<= n -7e-6)
(* (cos M) (exp (* -0.25 (pow m 2.0))))
(if (<= n 21000.0)
(*
(cos (- (/ (* (+ m n) K) 2.0) M))
(exp (- (* (- (* m 0.5) M) (- (- M (* m 0.5)) n)) l)))
(* (cos M) (exp (* -0.25 (pow n 2.0)))))))
double code(double K, double m, double n, double M, double l) {
double tmp;
if (n <= -7e-6) {
tmp = cos(M) * exp((-0.25 * pow(m, 2.0)));
} else if (n <= 21000.0) {
tmp = cos(((((m + n) * K) / 2.0) - M)) * exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) - l));
} else {
tmp = cos(M) * exp((-0.25 * pow(n, 2.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) :: tmp
if (n <= (-7d-6)) then
tmp = cos(m_1) * exp(((-0.25d0) * (m ** 2.0d0)))
else if (n <= 21000.0d0) then
tmp = cos(((((m + n) * k) / 2.0d0) - m_1)) * exp(((((m * 0.5d0) - m_1) * ((m_1 - (m * 0.5d0)) - n)) - l))
else
tmp = cos(m_1) * exp(((-0.25d0) * (n ** 2.0d0)))
end if
code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
double tmp;
if (n <= -7e-6) {
tmp = Math.cos(M) * Math.exp((-0.25 * Math.pow(m, 2.0)));
} else if (n <= 21000.0) {
tmp = Math.cos(((((m + n) * K) / 2.0) - M)) * Math.exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) - l));
} else {
tmp = Math.cos(M) * Math.exp((-0.25 * Math.pow(n, 2.0)));
}
return tmp;
}
def code(K, m, n, M, l): tmp = 0 if n <= -7e-6: tmp = math.cos(M) * math.exp((-0.25 * math.pow(m, 2.0))) elif n <= 21000.0: tmp = math.cos(((((m + n) * K) / 2.0) - M)) * math.exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) - l)) else: tmp = math.cos(M) * math.exp((-0.25 * math.pow(n, 2.0))) return tmp
function code(K, m, n, M, l) tmp = 0.0 if (n <= -7e-6) tmp = Float64(cos(M) * exp(Float64(-0.25 * (m ^ 2.0)))); elseif (n <= 21000.0) tmp = Float64(cos(Float64(Float64(Float64(Float64(m + n) * K) / 2.0) - M)) * exp(Float64(Float64(Float64(Float64(m * 0.5) - M) * Float64(Float64(M - Float64(m * 0.5)) - n)) - l))); else tmp = Float64(cos(M) * exp(Float64(-0.25 * (n ^ 2.0)))); end return tmp end
function tmp_2 = code(K, m, n, M, l) tmp = 0.0; if (n <= -7e-6) tmp = cos(M) * exp((-0.25 * (m ^ 2.0))); elseif (n <= 21000.0) tmp = cos(((((m + n) * K) / 2.0) - M)) * exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) - l)); else tmp = cos(M) * exp((-0.25 * (n ^ 2.0))); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := If[LessEqual[n, -7e-6], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 21000.0], N[(N[Cos[N[(N[(N[(N[(m + n), $MachinePrecision] * K), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(N[(N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision] * N[(N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision] - n), $MachinePrecision]), $MachinePrecision] - l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -7 \cdot 10^{-6}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\
\mathbf{elif}\;n \leq 21000:\\
\;\;\;\;\cos \left(\frac{\left(m + n\right) \cdot K}{2} - M\right) \cdot e^{\left(m \cdot 0.5 - M\right) \cdot \left(\left(M - m \cdot 0.5\right) - n\right) - \ell}\\
\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {n}^{2}}\\
\end{array}
\end{array}
if n < -6.99999999999999989e-6Initial program 71.6%
associate-/l*71.6%
+-commutative71.6%
fabs-sub71.6%
+-commutative71.6%
Simplified71.6%
Taylor expanded in K around 0 98.5%
cos-neg98.5%
Simplified98.5%
Taylor expanded in m around inf 40.7%
if -6.99999999999999989e-6 < n < 21000Initial program 79.6%
Taylor expanded in l around inf 79.6%
Taylor expanded in n around 0 79.6%
+-commutative79.6%
unpow279.6%
distribute-rgt-out79.6%
*-commutative79.6%
*-commutative79.6%
Simplified79.6%
if 21000 < n Initial program 81.6%
associate-/l*81.6%
+-commutative81.6%
fabs-sub81.6%
+-commutative81.6%
Simplified81.6%
Taylor expanded in K around 0 100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in n around inf 98.0%
Final simplification72.9%
(FPCore (K m n M l)
:precision binary64
(if (<= m -170.0)
(* (cos M) (exp (* -0.25 (pow m 2.0))))
(*
(cos (- (/ (* (+ m n) K) 2.0) M))
(exp (- (* (- (* n 0.5) M) (- (- M (* n 0.5)) m)) l)))))
double code(double K, double m, double n, double M, double l) {
double tmp;
if (m <= -170.0) {
tmp = cos(M) * exp((-0.25 * pow(m, 2.0)));
} else {
tmp = cos(((((m + n) * K) / 2.0) - M)) * exp(((((n * 0.5) - M) * ((M - (n * 0.5)) - m)) - l));
}
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) :: tmp
if (m <= (-170.0d0)) then
tmp = cos(m_1) * exp(((-0.25d0) * (m ** 2.0d0)))
else
tmp = cos(((((m + n) * k) / 2.0d0) - m_1)) * exp(((((n * 0.5d0) - m_1) * ((m_1 - (n * 0.5d0)) - m)) - l))
end if
code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
double tmp;
if (m <= -170.0) {
tmp = Math.cos(M) * Math.exp((-0.25 * Math.pow(m, 2.0)));
} else {
tmp = Math.cos(((((m + n) * K) / 2.0) - M)) * Math.exp(((((n * 0.5) - M) * ((M - (n * 0.5)) - m)) - l));
}
return tmp;
}
def code(K, m, n, M, l): tmp = 0 if m <= -170.0: tmp = math.cos(M) * math.exp((-0.25 * math.pow(m, 2.0))) else: tmp = math.cos(((((m + n) * K) / 2.0) - M)) * math.exp(((((n * 0.5) - M) * ((M - (n * 0.5)) - m)) - l)) return tmp
function code(K, m, n, M, l) tmp = 0.0 if (m <= -170.0) tmp = Float64(cos(M) * exp(Float64(-0.25 * (m ^ 2.0)))); else tmp = Float64(cos(Float64(Float64(Float64(Float64(m + n) * K) / 2.0) - M)) * exp(Float64(Float64(Float64(Float64(n * 0.5) - M) * Float64(Float64(M - Float64(n * 0.5)) - m)) - l))); end return tmp end
function tmp_2 = code(K, m, n, M, l) tmp = 0.0; if (m <= -170.0) tmp = cos(M) * exp((-0.25 * (m ^ 2.0))); else tmp = cos(((((m + n) * K) / 2.0) - M)) * exp(((((n * 0.5) - M) * ((M - (n * 0.5)) - m)) - l)); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -170.0], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(N[(N[(N[(m + n), $MachinePrecision] * K), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(N[(N[(N[(n * 0.5), $MachinePrecision] - M), $MachinePrecision] * N[(N[(M - N[(n * 0.5), $MachinePrecision]), $MachinePrecision] - m), $MachinePrecision]), $MachinePrecision] - l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq -170:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\frac{\left(m + n\right) \cdot K}{2} - M\right) \cdot e^{\left(n \cdot 0.5 - M\right) \cdot \left(\left(M - n \cdot 0.5\right) - m\right) - \ell}\\
\end{array}
\end{array}
if m < -170Initial program 70.9%
associate-/l*69.1%
+-commutative69.1%
fabs-sub69.1%
+-commutative69.1%
Simplified69.1%
Taylor expanded in K around 0 96.4%
cos-neg96.4%
Simplified96.4%
Taylor expanded in m around inf 94.6%
if -170 < m Initial program 79.8%
Taylor expanded in l around inf 79.8%
Taylor expanded in m around 0 69.1%
+-commutative69.1%
unpow269.1%
distribute-rgt-out71.1%
*-commutative71.1%
*-commutative71.1%
Simplified71.1%
Final simplification76.1%
(FPCore (K m n M l)
:precision binary64
(if (<= l 3e-7)
(*
(cos (- (/ (* (+ m n) K) 2.0) M))
(exp (- (* (- (* m 0.5) M) (- (- M (* m 0.5)) n)) l)))
(/ (cos M) (exp l))))
double code(double K, double m, double n, double M, double l) {
double tmp;
if (l <= 3e-7) {
tmp = cos(((((m + n) * K) / 2.0) - M)) * exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) - l));
} else {
tmp = cos(M) / exp(l);
}
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) :: tmp
if (l <= 3d-7) then
tmp = cos(((((m + n) * k) / 2.0d0) - m_1)) * exp(((((m * 0.5d0) - m_1) * ((m_1 - (m * 0.5d0)) - n)) - l))
else
tmp = cos(m_1) / exp(l)
end if
code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
double tmp;
if (l <= 3e-7) {
tmp = Math.cos(((((m + n) * K) / 2.0) - M)) * Math.exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) - l));
} else {
tmp = Math.cos(M) / Math.exp(l);
}
return tmp;
}
def code(K, m, n, M, l): tmp = 0 if l <= 3e-7: tmp = math.cos(((((m + n) * K) / 2.0) - M)) * math.exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) - l)) else: tmp = math.cos(M) / math.exp(l) return tmp
function code(K, m, n, M, l) tmp = 0.0 if (l <= 3e-7) tmp = Float64(cos(Float64(Float64(Float64(Float64(m + n) * K) / 2.0) - M)) * exp(Float64(Float64(Float64(Float64(m * 0.5) - M) * Float64(Float64(M - Float64(m * 0.5)) - n)) - l))); else tmp = Float64(cos(M) / exp(l)); end return tmp end
function tmp_2 = code(K, m, n, M, l) tmp = 0.0; if (l <= 3e-7) tmp = cos(((((m + n) * K) / 2.0) - M)) * exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) - l)); else tmp = cos(M) / exp(l); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := If[LessEqual[l, 3e-7], N[(N[Cos[N[(N[(N[(N[(m + n), $MachinePrecision] * K), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(N[(N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision] * N[(N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision] - n), $MachinePrecision]), $MachinePrecision] - l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] / N[Exp[l], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 3 \cdot 10^{-7}:\\
\;\;\;\;\cos \left(\frac{\left(m + n\right) \cdot K}{2} - M\right) \cdot e^{\left(m \cdot 0.5 - M\right) \cdot \left(\left(M - m \cdot 0.5\right) - n\right) - \ell}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos M}{e^{\ell}}\\
\end{array}
\end{array}
if l < 2.9999999999999999e-7Initial program 77.7%
Taylor expanded in l around inf 77.7%
Taylor expanded in n around 0 62.5%
+-commutative62.5%
unpow262.5%
distribute-rgt-out65.5%
*-commutative65.5%
*-commutative65.5%
Simplified65.5%
if 2.9999999999999999e-7 < l Initial program 78.6%
associate-/l*78.6%
+-commutative78.6%
fabs-sub78.6%
+-commutative78.6%
Simplified78.6%
Taylor expanded in K around 0 98.7%
cos-neg98.7%
Simplified98.7%
Taylor expanded in l around inf 96.9%
mul-1-neg96.9%
Simplified96.9%
Taylor expanded in l around -inf 96.9%
cos-neg96.9%
neg-mul-196.9%
exp-neg96.9%
associate-*r/96.9%
*-rgt-identity96.9%
cos-neg96.9%
Simplified96.9%
Final simplification72.4%
(FPCore (K m n M l)
:precision binary64
(let* ((t_0 (cos (- (/ (* (+ m n) K) 2.0) M))))
(if (<= n 1e-26)
(* t_0 (exp (- (* (- (* m 0.5) M) (- (- M (* m 0.5)) n)) l)))
(* t_0 (exp (- (* (- (* n 0.5) M) (- (- M (* n 0.5)) m)) l))))))
double code(double K, double m, double n, double M, double l) {
double t_0 = cos(((((m + n) * K) / 2.0) - M));
double tmp;
if (n <= 1e-26) {
tmp = t_0 * exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) - l));
} else {
tmp = t_0 * exp(((((n * 0.5) - M) * ((M - (n * 0.5)) - m)) - l));
}
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) :: tmp
t_0 = cos(((((m + n) * k) / 2.0d0) - m_1))
if (n <= 1d-26) then
tmp = t_0 * exp(((((m * 0.5d0) - m_1) * ((m_1 - (m * 0.5d0)) - n)) - l))
else
tmp = t_0 * exp(((((n * 0.5d0) - m_1) * ((m_1 - (n * 0.5d0)) - m)) - l))
end if
code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
double t_0 = Math.cos(((((m + n) * K) / 2.0) - M));
double tmp;
if (n <= 1e-26) {
tmp = t_0 * Math.exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) - l));
} else {
tmp = t_0 * Math.exp(((((n * 0.5) - M) * ((M - (n * 0.5)) - m)) - l));
}
return tmp;
}
def code(K, m, n, M, l): t_0 = math.cos(((((m + n) * K) / 2.0) - M)) tmp = 0 if n <= 1e-26: tmp = t_0 * math.exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) - l)) else: tmp = t_0 * math.exp(((((n * 0.5) - M) * ((M - (n * 0.5)) - m)) - l)) return tmp
function code(K, m, n, M, l) t_0 = cos(Float64(Float64(Float64(Float64(m + n) * K) / 2.0) - M)) tmp = 0.0 if (n <= 1e-26) tmp = Float64(t_0 * exp(Float64(Float64(Float64(Float64(m * 0.5) - M) * Float64(Float64(M - Float64(m * 0.5)) - n)) - l))); else tmp = Float64(t_0 * exp(Float64(Float64(Float64(Float64(n * 0.5) - M) * Float64(Float64(M - Float64(n * 0.5)) - m)) - l))); end return tmp end
function tmp_2 = code(K, m, n, M, l) t_0 = cos(((((m + n) * K) / 2.0) - M)); tmp = 0.0; if (n <= 1e-26) tmp = t_0 * exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) - l)); else tmp = t_0 * exp(((((n * 0.5) - M) * ((M - (n * 0.5)) - m)) - l)); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Cos[N[(N[(N[(N[(m + n), $MachinePrecision] * K), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[n, 1e-26], N[(t$95$0 * N[Exp[N[(N[(N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision] * N[(N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision] - n), $MachinePrecision]), $MachinePrecision] - l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Exp[N[(N[(N[(N[(n * 0.5), $MachinePrecision] - M), $MachinePrecision] * N[(N[(M - N[(n * 0.5), $MachinePrecision]), $MachinePrecision] - m), $MachinePrecision]), $MachinePrecision] - l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{\left(m + n\right) \cdot K}{2} - M\right)\\
\mathbf{if}\;n \leq 10^{-26}:\\
\;\;\;\;t_0 \cdot e^{\left(m \cdot 0.5 - M\right) \cdot \left(\left(M - m \cdot 0.5\right) - n\right) - \ell}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot e^{\left(n \cdot 0.5 - M\right) \cdot \left(\left(M - n \cdot 0.5\right) - m\right) - \ell}\\
\end{array}
\end{array}
if n < 1e-26Initial program 77.2%
Taylor expanded in l around inf 77.2%
Taylor expanded in n around 0 65.9%
+-commutative65.9%
unpow265.9%
distribute-rgt-out68.4%
*-commutative68.4%
*-commutative68.4%
Simplified68.4%
if 1e-26 < n Initial program 80.4%
Taylor expanded in l around inf 80.4%
Taylor expanded in m around 0 71.5%
+-commutative71.5%
unpow271.5%
distribute-rgt-out75.1%
*-commutative75.1%
*-commutative75.1%
Simplified75.1%
Final simplification69.9%
(FPCore (K m n M l) :precision binary64 (if (<= l 8.5e-15) (* (cos M) (exp l)) (exp (- l))))
double code(double K, double m, double n, double M, double l) {
double tmp;
if (l <= 8.5e-15) {
tmp = cos(M) * exp(l);
} else {
tmp = exp(-l);
}
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) :: tmp
if (l <= 8.5d-15) then
tmp = cos(m_1) * exp(l)
else
tmp = exp(-l)
end if
code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
double tmp;
if (l <= 8.5e-15) {
tmp = Math.cos(M) * Math.exp(l);
} else {
tmp = Math.exp(-l);
}
return tmp;
}
def code(K, m, n, M, l): tmp = 0 if l <= 8.5e-15: tmp = math.cos(M) * math.exp(l) else: tmp = math.exp(-l) return tmp
function code(K, m, n, M, l) tmp = 0.0 if (l <= 8.5e-15) tmp = Float64(cos(M) * exp(l)); else tmp = exp(Float64(-l)); end return tmp end
function tmp_2 = code(K, m, n, M, l) tmp = 0.0; if (l <= 8.5e-15) tmp = cos(M) * exp(l); else tmp = exp(-l); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := If[LessEqual[l, 8.5e-15], N[(N[Cos[M], $MachinePrecision] * N[Exp[l], $MachinePrecision]), $MachinePrecision], N[Exp[(-l)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 8.5 \cdot 10^{-15}:\\
\;\;\;\;\cos M \cdot e^{\ell}\\
\mathbf{else}:\\
\;\;\;\;e^{-\ell}\\
\end{array}
\end{array}
if l < 8.50000000000000007e-15Initial program 77.6%
associate-/l*77.2%
+-commutative77.2%
fabs-sub77.2%
+-commutative77.2%
Simplified77.2%
Taylor expanded in K around 0 96.7%
cos-neg96.7%
Simplified96.7%
Taylor expanded in l around inf 14.6%
mul-1-neg14.6%
Simplified14.6%
expm1-log1p-u14.0%
expm1-udef14.0%
add-sqr-sqrt10.8%
sqrt-unprod14.0%
sqr-neg14.0%
sqrt-unprod3.1%
add-sqr-sqrt29.9%
Applied egg-rr29.9%
expm1-def29.9%
expm1-log1p29.9%
Simplified29.9%
if 8.50000000000000007e-15 < l Initial program 79.0%
associate-/l*79.0%
+-commutative79.0%
fabs-sub79.0%
+-commutative79.0%
Simplified79.0%
Taylor expanded in K around 0 98.7%
cos-neg98.7%
Simplified98.7%
Taylor expanded in l around inf 95.3%
mul-1-neg95.3%
Simplified95.3%
Taylor expanded in M around 0 95.3%
Final simplification44.5%
(FPCore (K m n M l) :precision binary64 (if (<= l -2e-77) (* (cos M) (exp l)) (/ (cos M) (exp l))))
double code(double K, double m, double n, double M, double l) {
double tmp;
if (l <= -2e-77) {
tmp = cos(M) * exp(l);
} else {
tmp = cos(M) / exp(l);
}
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) :: tmp
if (l <= (-2d-77)) then
tmp = cos(m_1) * exp(l)
else
tmp = cos(m_1) / exp(l)
end if
code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
double tmp;
if (l <= -2e-77) {
tmp = Math.cos(M) * Math.exp(l);
} else {
tmp = Math.cos(M) / Math.exp(l);
}
return tmp;
}
def code(K, m, n, M, l): tmp = 0 if l <= -2e-77: tmp = math.cos(M) * math.exp(l) else: tmp = math.cos(M) / math.exp(l) return tmp
function code(K, m, n, M, l) tmp = 0.0 if (l <= -2e-77) tmp = Float64(cos(M) * exp(l)); else tmp = Float64(cos(M) / exp(l)); end return tmp end
function tmp_2 = code(K, m, n, M, l) tmp = 0.0; if (l <= -2e-77) tmp = cos(M) * exp(l); else tmp = cos(M) / exp(l); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := If[LessEqual[l, -2e-77], N[(N[Cos[M], $MachinePrecision] * N[Exp[l], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] / N[Exp[l], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2 \cdot 10^{-77}:\\
\;\;\;\;\cos M \cdot e^{\ell}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos M}{e^{\ell}}\\
\end{array}
\end{array}
if l < -1.9999999999999999e-77Initial program 82.1%
associate-/l*80.8%
+-commutative80.8%
fabs-sub80.8%
+-commutative80.8%
Simplified80.8%
Taylor expanded in K around 0 96.2%
cos-neg96.2%
Simplified96.2%
Taylor expanded in l around inf 19.5%
mul-1-neg19.5%
Simplified19.5%
expm1-log1p-u17.9%
expm1-udef17.9%
add-sqr-sqrt17.9%
sqrt-unprod17.9%
sqr-neg17.9%
sqrt-unprod0.0%
add-sqr-sqrt58.7%
Applied egg-rr58.7%
expm1-def58.7%
expm1-log1p58.7%
Simplified58.7%
if -1.9999999999999999e-77 < l Initial program 76.1%
associate-/l*76.2%
+-commutative76.2%
fabs-sub76.2%
+-commutative76.2%
Simplified76.2%
Taylor expanded in K around 0 97.6%
cos-neg97.6%
Simplified97.6%
Taylor expanded in l around inf 38.2%
mul-1-neg38.2%
Simplified38.2%
Taylor expanded in l around -inf 38.2%
cos-neg38.2%
neg-mul-138.2%
exp-neg38.2%
associate-*r/38.2%
*-rgt-identity38.2%
cos-neg38.2%
Simplified38.2%
Final simplification44.5%
(FPCore (K m n M l) :precision binary64 (exp (- l)))
double code(double K, double m, double n, double M, double l) {
return exp(-l);
}
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
public static double code(double K, double m, double n, double M, double l) {
return Math.exp(-l);
}
def code(K, m, n, M, l): return math.exp(-l)
function code(K, m, n, M, l) return exp(Float64(-l)) end
function tmp = code(K, m, n, M, l) tmp = exp(-l); end
code[K_, m_, n_, M_, l_] := N[Exp[(-l)], $MachinePrecision]
\begin{array}{l}
\\
e^{-\ell}
\end{array}
Initial program 77.9%
associate-/l*77.6%
+-commutative77.6%
fabs-sub77.6%
+-commutative77.6%
Simplified77.6%
Taylor expanded in K around 0 97.1%
cos-neg97.1%
Simplified97.1%
Taylor expanded in l around inf 32.5%
mul-1-neg32.5%
Simplified32.5%
Taylor expanded in M around 0 32.9%
Final simplification32.9%
herbie shell --seed 2024018
(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)))))))