
(FPCore (J l K U) :precision binary64 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = ((j * (exp(l) - exp(-l))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
return ((J * (Math.exp(l) - Math.exp(-l))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U): return ((J * (math.exp(l) - math.exp(-l))) * math.cos((K / 2.0))) + U
function code(J, l, K, U) return Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * cos(Float64(K / 2.0))) + U) end
function tmp = code(J, l, K, U) tmp = ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U; end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (J l K U) :precision binary64 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = ((j * (exp(l) - exp(-l))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
return ((J * (Math.exp(l) - Math.exp(-l))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U): return ((J * (math.exp(l) - math.exp(-l))) * math.cos((K / 2.0))) + U
function code(J, l, K, U) return Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * cos(Float64(K / 2.0))) + U) end
function tmp = code(J, l, K, U) tmp = ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U; end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
(if (or (<= t_1 (- INFINITY)) (not (<= t_1 1e-5)))
(+ (* (* t_1 J) t_0) U)
(+
U
(*
t_0
(+
(* 0.0003968253968253968 (* J (pow l 7.0)))
(+
(* 0.016666666666666666 (* J (pow l 5.0)))
(+ (* 0.3333333333333333 (* J (pow l 3.0))) (* 2.0 (* l J))))))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double t_1 = exp(l) - exp(-l);
double tmp;
if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 1e-5)) {
tmp = ((t_1 * J) * t_0) + U;
} else {
tmp = U + (t_0 * ((0.0003968253968253968 * (J * pow(l, 7.0))) + ((0.016666666666666666 * (J * pow(l, 5.0))) + ((0.3333333333333333 * (J * pow(l, 3.0))) + (2.0 * (l * J))))));
}
return tmp;
}
public static double code(double J, double l, double K, double U) {
double t_0 = Math.cos((K / 2.0));
double t_1 = Math.exp(l) - Math.exp(-l);
double tmp;
if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 1e-5)) {
tmp = ((t_1 * J) * t_0) + U;
} else {
tmp = U + (t_0 * ((0.0003968253968253968 * (J * Math.pow(l, 7.0))) + ((0.016666666666666666 * (J * Math.pow(l, 5.0))) + ((0.3333333333333333 * (J * Math.pow(l, 3.0))) + (2.0 * (l * J))))));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) t_1 = math.exp(l) - math.exp(-l) tmp = 0 if (t_1 <= -math.inf) or not (t_1 <= 1e-5): tmp = ((t_1 * J) * t_0) + U else: tmp = U + (t_0 * ((0.0003968253968253968 * (J * math.pow(l, 7.0))) + ((0.016666666666666666 * (J * math.pow(l, 5.0))) + ((0.3333333333333333 * (J * math.pow(l, 3.0))) + (2.0 * (l * J)))))) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) t_1 = Float64(exp(l) - exp(Float64(-l))) tmp = 0.0 if ((t_1 <= Float64(-Inf)) || !(t_1 <= 1e-5)) tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U); else tmp = Float64(U + Float64(t_0 * Float64(Float64(0.0003968253968253968 * Float64(J * (l ^ 7.0))) + Float64(Float64(0.016666666666666666 * Float64(J * (l ^ 5.0))) + Float64(Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))) + Float64(2.0 * Float64(l * J))))))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K / 2.0)); t_1 = exp(l) - exp(-l); tmp = 0.0; if ((t_1 <= -Inf) || ~((t_1 <= 1e-5))) tmp = ((t_1 * J) * t_0) + U; else tmp = U + (t_0 * ((0.0003968253968253968 * (J * (l ^ 7.0))) + ((0.016666666666666666 * (J * (l ^ 5.0))) + ((0.3333333333333333 * (J * (l ^ 3.0))) + (2.0 * (l * J)))))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 1e-5]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(N[(0.0003968253968253968 * N[(J * N[Power[l, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.016666666666666666 * N[(J * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 10^{-5}\right):\\
\;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + U\\
\mathbf{else}:\\
\;\;\;\;U + t_0 \cdot \left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{7}\right) + \left(0.016666666666666666 \cdot \left(J \cdot {\ell}^{5}\right) + \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(\ell \cdot J\right)\right)\right)\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 1.00000000000000008e-5 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) Initial program 100.0%
if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1.00000000000000008e-5Initial program 71.8%
Taylor expanded in l around 0 99.9%
Final simplification99.9%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (* K 0.5))) (t_1 (- (exp l) (exp (- l)))))
(if (or (<= t_1 -0.1) (not (<= t_1 1e-5)))
(+ (* (* t_1 J) (cos (/ K 2.0))) U)
(+
U
(+
(* 0.3333333333333333 (* J (* (pow l 3.0) t_0)))
(* 2.0 (* J (* l t_0))))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K * 0.5));
double t_1 = exp(l) - exp(-l);
double tmp;
if ((t_1 <= -0.1) || !(t_1 <= 1e-5)) {
tmp = ((t_1 * J) * cos((K / 2.0))) + U;
} else {
tmp = U + ((0.3333333333333333 * (J * (pow(l, 3.0) * t_0))) + (2.0 * (J * (l * t_0))));
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos((k * 0.5d0))
t_1 = exp(l) - exp(-l)
if ((t_1 <= (-0.1d0)) .or. (.not. (t_1 <= 1d-5))) then
tmp = ((t_1 * j) * cos((k / 2.0d0))) + u
else
tmp = u + ((0.3333333333333333d0 * (j * ((l ** 3.0d0) * t_0))) + (2.0d0 * (j * (l * t_0))))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double t_0 = Math.cos((K * 0.5));
double t_1 = Math.exp(l) - Math.exp(-l);
double tmp;
if ((t_1 <= -0.1) || !(t_1 <= 1e-5)) {
tmp = ((t_1 * J) * Math.cos((K / 2.0))) + U;
} else {
tmp = U + ((0.3333333333333333 * (J * (Math.pow(l, 3.0) * t_0))) + (2.0 * (J * (l * t_0))));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K * 0.5)) t_1 = math.exp(l) - math.exp(-l) tmp = 0 if (t_1 <= -0.1) or not (t_1 <= 1e-5): tmp = ((t_1 * J) * math.cos((K / 2.0))) + U else: tmp = U + ((0.3333333333333333 * (J * (math.pow(l, 3.0) * t_0))) + (2.0 * (J * (l * t_0)))) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K * 0.5)) t_1 = Float64(exp(l) - exp(Float64(-l))) tmp = 0.0 if ((t_1 <= -0.1) || !(t_1 <= 1e-5)) tmp = Float64(Float64(Float64(t_1 * J) * cos(Float64(K / 2.0))) + U); else tmp = Float64(U + Float64(Float64(0.3333333333333333 * Float64(J * Float64((l ^ 3.0) * t_0))) + Float64(2.0 * Float64(J * Float64(l * t_0))))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K * 0.5)); t_1 = exp(l) - exp(-l); tmp = 0.0; if ((t_1 <= -0.1) || ~((t_1 <= 1e-5))) tmp = ((t_1 * J) * cos((K / 2.0))) + U; else tmp = U + ((0.3333333333333333 * (J * ((l ^ 3.0) * t_0))) + (2.0 * (J * (l * t_0)))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -0.1], N[Not[LessEqual[t$95$1, 1e-5]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(N[(0.3333333333333333 * N[(J * N[(N[Power[l, 3.0], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(J * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
t_1 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_1 \leq -0.1 \lor \neg \left(t_1 \leq 10^{-5}\right):\\
\;\;\;\;\left(t_1 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\
\mathbf{else}:\\
\;\;\;\;U + \left(0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{3} \cdot t_0\right)\right) + 2 \cdot \left(J \cdot \left(\ell \cdot t_0\right)\right)\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -0.10000000000000001 or 1.00000000000000008e-5 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) Initial program 100.0%
if -0.10000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1.00000000000000008e-5Initial program 71.6%
Taylor expanded in l around 0 99.9%
Final simplification99.9%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
(if (or (<= t_1 -0.1) (not (<= t_1 1e-5)))
(+ (* (* t_1 J) t_0) U)
(+ U (* t_0 (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double t_1 = exp(l) - exp(-l);
double tmp;
if ((t_1 <= -0.1) || !(t_1 <= 1e-5)) {
tmp = ((t_1 * J) * t_0) + U;
} else {
tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos((k / 2.0d0))
t_1 = exp(l) - exp(-l)
if ((t_1 <= (-0.1d0)) .or. (.not. (t_1 <= 1d-5))) then
tmp = ((t_1 * j) * t_0) + u
else
tmp = u + (t_0 * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double t_0 = Math.cos((K / 2.0));
double t_1 = Math.exp(l) - Math.exp(-l);
double tmp;
if ((t_1 <= -0.1) || !(t_1 <= 1e-5)) {
tmp = ((t_1 * J) * t_0) + U;
} else {
tmp = U + (t_0 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) t_1 = math.exp(l) - math.exp(-l) tmp = 0 if (t_1 <= -0.1) or not (t_1 <= 1e-5): tmp = ((t_1 * J) * t_0) + U else: tmp = U + (t_0 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0)))) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) t_1 = Float64(exp(l) - exp(Float64(-l))) tmp = 0.0 if ((t_1 <= -0.1) || !(t_1 <= 1e-5)) tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U); else tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K / 2.0)); t_1 = exp(l) - exp(-l); tmp = 0.0; if ((t_1 <= -0.1) || ~((t_1 <= 1e-5))) tmp = ((t_1 * J) * t_0) + U; else tmp = U + (t_0 * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0)))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -0.1], N[Not[LessEqual[t$95$1, 1e-5]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_1 \leq -0.1 \lor \neg \left(t_1 \leq 10^{-5}\right):\\
\;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + U\\
\mathbf{else}:\\
\;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -0.10000000000000001 or 1.00000000000000008e-5 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) Initial program 100.0%
if -0.10000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1.00000000000000008e-5Initial program 71.6%
Taylor expanded in l around 0 99.9%
Final simplification99.9%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (- (exp l) (exp (- l)))))
(if (or (<= t_0 -0.1) (not (<= t_0 1e-5)))
(+ (* t_0 J) U)
(fma (* J 2.0) (* l (cos (* K 0.5))) U))))
double code(double J, double l, double K, double U) {
double t_0 = exp(l) - exp(-l);
double tmp;
if ((t_0 <= -0.1) || !(t_0 <= 1e-5)) {
tmp = (t_0 * J) + U;
} else {
tmp = fma((J * 2.0), (l * cos((K * 0.5))), U);
}
return tmp;
}
function code(J, l, K, U) t_0 = Float64(exp(l) - exp(Float64(-l))) tmp = 0.0 if ((t_0 <= -0.1) || !(t_0 <= 1e-5)) tmp = Float64(Float64(t_0 * J) + U); else tmp = fma(Float64(J * 2.0), Float64(l * cos(Float64(K * 0.5))), U); end return tmp end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.1], N[Not[LessEqual[t$95$0, 1e-5]], $MachinePrecision]], N[(N[(t$95$0 * J), $MachinePrecision] + U), $MachinePrecision], N[(N[(J * 2.0), $MachinePrecision] * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_0 \leq -0.1 \lor \neg \left(t_0 \leq 10^{-5}\right):\\
\;\;\;\;t_0 \cdot J + U\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J \cdot 2, \ell \cdot \cos \left(K \cdot 0.5\right), U\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -0.10000000000000001 or 1.00000000000000008e-5 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) Initial program 100.0%
Taylor expanded in K around 0 74.6%
if -0.10000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1.00000000000000008e-5Initial program 71.6%
Taylor expanded in l around 0 99.7%
+-commutative99.7%
associate-*r*99.7%
fma-def99.7%
Simplified99.7%
Final simplification87.3%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (- (exp l) (exp (- l)))))
(if (or (<= t_0 -0.1) (not (<= t_0 1e-5)))
(+ (* t_0 J) U)
(+ U (* 2.0 (* J (* l (cos (* K 0.5)))))))))
double code(double J, double l, double K, double U) {
double t_0 = exp(l) - exp(-l);
double tmp;
if ((t_0 <= -0.1) || !(t_0 <= 1e-5)) {
tmp = (t_0 * J) + U;
} else {
tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
real(8) :: tmp
t_0 = exp(l) - exp(-l)
if ((t_0 <= (-0.1d0)) .or. (.not. (t_0 <= 1d-5))) then
tmp = (t_0 * j) + u
else
tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double t_0 = Math.exp(l) - Math.exp(-l);
double tmp;
if ((t_0 <= -0.1) || !(t_0 <= 1e-5)) {
tmp = (t_0 * J) + U;
} else {
tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.exp(l) - math.exp(-l) tmp = 0 if (t_0 <= -0.1) or not (t_0 <= 1e-5): tmp = (t_0 * J) + U else: tmp = U + (2.0 * (J * (l * math.cos((K * 0.5))))) return tmp
function code(J, l, K, U) t_0 = Float64(exp(l) - exp(Float64(-l))) tmp = 0.0 if ((t_0 <= -0.1) || !(t_0 <= 1e-5)) tmp = Float64(Float64(t_0 * J) + U); else tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5)))))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = exp(l) - exp(-l); tmp = 0.0; if ((t_0 <= -0.1) || ~((t_0 <= 1e-5))) tmp = (t_0 * J) + U; else tmp = U + (2.0 * (J * (l * cos((K * 0.5))))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.1], N[Not[LessEqual[t$95$0, 1e-5]], $MachinePrecision]], N[(N[(t$95$0 * J), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_0 \leq -0.1 \lor \neg \left(t_0 \leq 10^{-5}\right):\\
\;\;\;\;t_0 \cdot J + U\\
\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -0.10000000000000001 or 1.00000000000000008e-5 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) Initial program 100.0%
Taylor expanded in K around 0 74.6%
if -0.10000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1.00000000000000008e-5Initial program 71.6%
Taylor expanded in l around 0 99.7%
Final simplification87.3%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(if (<= t_0 -0.9)
U
(if (<= t_0 -0.24)
(* 2.0 (* (* l J) (cos (* K 0.5))))
(fma l (* J 2.0) U)))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double tmp;
if (t_0 <= -0.9) {
tmp = U;
} else if (t_0 <= -0.24) {
tmp = 2.0 * ((l * J) * cos((K * 0.5)));
} else {
tmp = fma(l, (J * 2.0), U);
}
return tmp;
}
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) tmp = 0.0 if (t_0 <= -0.9) tmp = U; elseif (t_0 <= -0.24) tmp = Float64(2.0 * Float64(Float64(l * J) * cos(Float64(K * 0.5)))); else tmp = fma(l, Float64(J * 2.0), U); end return tmp end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, -0.9], U, If[LessEqual[t$95$0, -0.24], N[(2.0 * N[(N[(l * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(l * N[(J * 2.0), $MachinePrecision] + U), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t_0 \leq -0.9:\\
\;\;\;\;U\\
\mathbf{elif}\;t_0 \leq -0.24:\\
\;\;\;\;2 \cdot \left(\left(\ell \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\ell, J \cdot 2, U\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < -0.900000000000000022Initial program 83.1%
Taylor expanded in J around 0 51.3%
if -0.900000000000000022 < (cos.f64 (/.f64 K 2)) < -0.23999999999999999Initial program 76.8%
Taylor expanded in l around 0 56.5%
Taylor expanded in J around inf 43.5%
associate-*r*43.6%
*-commutative43.6%
Simplified43.6%
if -0.23999999999999999 < (cos.f64 (/.f64 K 2)) Initial program 87.6%
Taylor expanded in l around 0 62.0%
associate-*r*62.0%
*-commutative62.0%
Simplified62.0%
Taylor expanded in K around 0 57.1%
+-commutative57.1%
*-commutative57.1%
*-commutative57.1%
associate-*r*57.1%
fma-def57.1%
*-commutative57.1%
Simplified57.1%
Final simplification54.5%
(FPCore (J l K U)
:precision binary64
(if (or (<= l -1e+118)
(not (or (<= l -0.054) (and (not (<= l 0.07)) (<= l 3e+96)))))
(+
U
(* (cos (/ K 2.0)) (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))
(+ (* (- (exp l) (exp (- l))) J) U)))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -1e+118) || !((l <= -0.054) || (!(l <= 0.07) && (l <= 3e+96)))) {
tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
} else {
tmp = ((exp(l) - exp(-l)) * J) + U;
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: tmp
if ((l <= (-1d+118)) .or. (.not. (l <= (-0.054d0)) .or. (.not. (l <= 0.07d0)) .and. (l <= 3d+96))) then
tmp = u + (cos((k / 2.0d0)) * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
else
tmp = ((exp(l) - exp(-l)) * j) + u
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -1e+118) || !((l <= -0.054) || (!(l <= 0.07) && (l <= 3e+96)))) {
tmp = U + (Math.cos((K / 2.0)) * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
} else {
tmp = ((Math.exp(l) - Math.exp(-l)) * J) + U;
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -1e+118) or not ((l <= -0.054) or (not (l <= 0.07) and (l <= 3e+96))): tmp = U + (math.cos((K / 2.0)) * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0)))) else: tmp = ((math.exp(l) - math.exp(-l)) * J) + U return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -1e+118) || !((l <= -0.054) || (!(l <= 0.07) && (l <= 3e+96)))) tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))))); else tmp = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -1e+118) || ~(((l <= -0.054) || (~((l <= 0.07)) && (l <= 3e+96))))) tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0)))); else tmp = ((exp(l) - exp(-l)) * J) + U; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -1e+118], N[Not[Or[LessEqual[l, -0.054], And[N[Not[LessEqual[l, 0.07]], $MachinePrecision], LessEqual[l, 3e+96]]]], $MachinePrecision]], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1 \cdot 10^{+118} \lor \neg \left(\ell \leq -0.054 \lor \neg \left(\ell \leq 0.07\right) \land \ell \leq 3 \cdot 10^{+96}\right):\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\
\end{array}
\end{array}
if l < -9.99999999999999967e117 or -0.0539999999999999994 < l < 0.070000000000000007 or 3e96 < l Initial program 82.0%
Taylor expanded in l around 0 99.5%
if -9.99999999999999967e117 < l < -0.0539999999999999994 or 0.070000000000000007 < l < 3e96Initial program 99.9%
Taylor expanded in K around 0 86.2%
Final simplification96.8%
(FPCore (J l K U) :precision binary64 (+ U (* 2.0 (* J (* l (cos (* K 0.5)))))))
double code(double J, double l, double K, double U) {
return U + (2.0 * (J * (l * cos((K * 0.5)))));
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
end function
public static double code(double J, double l, double K, double U) {
return U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
}
def code(J, l, K, U): return U + (2.0 * (J * (l * math.cos((K * 0.5)))))
function code(J, l, K, U) return Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5)))))) end
function tmp = code(J, l, K, U) tmp = U + (2.0 * (J * (l * cos((K * 0.5))))); end
code[J_, l_, K_, U_] := N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)
\end{array}
Initial program 85.6%
Taylor expanded in l around 0 61.6%
Final simplification61.6%
(FPCore (J l K U) :precision binary64 (+ U (* (cos (/ K 2.0)) (* l (* J 2.0)))))
double code(double J, double l, double K, double U) {
return U + (cos((K / 2.0)) * (l * (J * 2.0)));
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = u + (cos((k / 2.0d0)) * (l * (j * 2.0d0)))
end function
public static double code(double J, double l, double K, double U) {
return U + (Math.cos((K / 2.0)) * (l * (J * 2.0)));
}
def code(J, l, K, U): return U + (math.cos((K / 2.0)) * (l * (J * 2.0)))
function code(J, l, K, U) return Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(l * Float64(J * 2.0)))) end
function tmp = code(J, l, K, U) tmp = U + (cos((K / 2.0)) * (l * (J * 2.0))); end
code[J_, l_, K_, U_] := N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)
\end{array}
Initial program 85.6%
Taylor expanded in l around 0 61.9%
associate-*r*61.9%
*-commutative61.9%
Simplified61.9%
Final simplification61.9%
(FPCore (J l K U) :precision binary64 (fma l (* J 2.0) U))
double code(double J, double l, double K, double U) {
return fma(l, (J * 2.0), U);
}
function code(J, l, K, U) return fma(l, Float64(J * 2.0), U) end
code[J_, l_, K_, U_] := N[(l * N[(J * 2.0), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\ell, J \cdot 2, U\right)
\end{array}
Initial program 85.6%
Taylor expanded in l around 0 61.9%
associate-*r*61.9%
*-commutative61.9%
Simplified61.9%
Taylor expanded in K around 0 50.2%
+-commutative50.2%
*-commutative50.2%
*-commutative50.2%
associate-*r*50.2%
fma-def50.2%
*-commutative50.2%
Simplified50.2%
Final simplification50.2%
(FPCore (J l K U) :precision binary64 (if (or (<= l -66000000.0) (not (<= l 3.7e-6))) (* U U) U))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -66000000.0) || !(l <= 3.7e-6)) {
tmp = U * U;
} else {
tmp = U;
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: tmp
if ((l <= (-66000000.0d0)) .or. (.not. (l <= 3.7d-6))) then
tmp = u * u
else
tmp = u
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -66000000.0) || !(l <= 3.7e-6)) {
tmp = U * U;
} else {
tmp = U;
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -66000000.0) or not (l <= 3.7e-6): tmp = U * U else: tmp = U return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -66000000.0) || !(l <= 3.7e-6)) tmp = Float64(U * U); else tmp = U; end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -66000000.0) || ~((l <= 3.7e-6))) tmp = U * U; else tmp = U; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -66000000.0], N[Not[LessEqual[l, 3.7e-6]], $MachinePrecision]], N[(U * U), $MachinePrecision], U]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -66000000 \lor \neg \left(\ell \leq 3.7 \cdot 10^{-6}\right):\\
\;\;\;\;U \cdot U\\
\mathbf{else}:\\
\;\;\;\;U\\
\end{array}
\end{array}
if l < -6.6e7 or 3.7000000000000002e-6 < l Initial program 99.8%
Applied egg-rr13.7%
if -6.6e7 < l < 3.7000000000000002e-6Initial program 72.2%
Taylor expanded in J around 0 69.5%
Final simplification42.5%
(FPCore (J l K U) :precision binary64 (+ U (* 2.0 (* l J))))
double code(double J, double l, double K, double U) {
return U + (2.0 * (l * J));
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = u + (2.0d0 * (l * j))
end function
public static double code(double J, double l, double K, double U) {
return U + (2.0 * (l * J));
}
def code(J, l, K, U): return U + (2.0 * (l * J))
function code(J, l, K, U) return Float64(U + Float64(2.0 * Float64(l * J))) end
function tmp = code(J, l, K, U) tmp = U + (2.0 * (l * J)); end
code[J_, l_, K_, U_] := N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
U + 2 \cdot \left(\ell \cdot J\right)
\end{array}
Initial program 85.6%
Taylor expanded in l around 0 61.9%
associate-*r*61.9%
*-commutative61.9%
Simplified61.9%
Taylor expanded in K around 0 50.2%
+-commutative50.2%
Simplified50.2%
Final simplification50.2%
(FPCore (J l K U) :precision binary64 -0.3333333333333333)
double code(double J, double l, double K, double U) {
return -0.3333333333333333;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = -0.3333333333333333d0
end function
public static double code(double J, double l, double K, double U) {
return -0.3333333333333333;
}
def code(J, l, K, U): return -0.3333333333333333
function code(J, l, K, U) return -0.3333333333333333 end
function tmp = code(J, l, K, U) tmp = -0.3333333333333333; end
code[J_, l_, K_, U_] := -0.3333333333333333
\begin{array}{l}
\\
-0.3333333333333333
\end{array}
Initial program 85.6%
Applied egg-rr2.4%
associate-+r+2.4%
distribute-rgt1-in2.4%
metadata-eval2.4%
*-commutative2.4%
distribute-lft-out2.4%
associate-/r*2.4%
*-inverses2.4%
+-commutative2.4%
*-commutative2.4%
Simplified2.4%
Taylor expanded in U around 0 2.8%
Final simplification2.8%
(FPCore (J l K U) :precision binary64 U)
double code(double J, double l, double K, double U) {
return U;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = u
end function
public static double code(double J, double l, double K, double U) {
return U;
}
def code(J, l, K, U): return U
function code(J, l, K, U) return U end
function tmp = code(J, l, K, U) tmp = U; end
code[J_, l_, K_, U_] := U
\begin{array}{l}
\\
U
\end{array}
Initial program 85.6%
Taylor expanded in J around 0 36.8%
Final simplification36.8%
herbie shell --seed 2023339
(FPCore (J l K U)
:name "Maksimov and Kolovsky, Equation (4)"
:precision binary64
(+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))