
(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 13 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 (- (exp l) (exp (- l)))))
(if (or (<= t_0 (- INFINITY)) (not (<= t_0 2e-16)))
(+ (* (* t_0 J) (cos (/ K 2.0))) U)
(+ U (* (* J (cos (* K 0.5))) (* l 2.0))))))
double code(double J, double l, double K, double U) {
double t_0 = exp(l) - exp(-l);
double tmp;
if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 2e-16)) {
tmp = ((t_0 * J) * cos((K / 2.0))) + U;
} else {
tmp = U + ((J * cos((K * 0.5))) * (l * 2.0));
}
return tmp;
}
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 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 2e-16)) {
tmp = ((t_0 * J) * Math.cos((K / 2.0))) + U;
} else {
tmp = U + ((J * Math.cos((K * 0.5))) * (l * 2.0));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.exp(l) - math.exp(-l) tmp = 0 if (t_0 <= -math.inf) or not (t_0 <= 2e-16): tmp = ((t_0 * J) * math.cos((K / 2.0))) + U else: tmp = U + ((J * math.cos((K * 0.5))) * (l * 2.0)) return tmp
function code(J, l, K, U) t_0 = Float64(exp(l) - exp(Float64(-l))) tmp = 0.0 if ((t_0 <= Float64(-Inf)) || !(t_0 <= 2e-16)) tmp = Float64(Float64(Float64(t_0 * J) * cos(Float64(K / 2.0))) + U); else tmp = Float64(U + Float64(Float64(J * cos(Float64(K * 0.5))) * Float64(l * 2.0))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = exp(l) - exp(-l); tmp = 0.0; if ((t_0 <= -Inf) || ~((t_0 <= 2e-16))) tmp = ((t_0 * J) * cos((K / 2.0))) + U; else tmp = U + ((J * cos((K * 0.5))) * (l * 2.0)); 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, (-Infinity)], N[Not[LessEqual[t$95$0, 2e-16]], $MachinePrecision]], N[(N[(N[(t$95$0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 2 \cdot 10^{-16}\right):\\
\;\;\;\;\left(t\_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\
\mathbf{else}:\\
\;\;\;\;U + \left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(\ell \cdot 2\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 2e-16 < (-.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))) < 2e-16Initial program 76.9%
Taylor expanded in l around 0 100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in l around 0 99.9%
*-commutative99.9%
associate-*r*100.0%
associate-*l*100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (J l K U)
:precision binary64
(let* ((t_0
(+ U (* (cos (/ K 2.0)) (* J (* 0.3333333333333333 (pow l 3.0))))))
(t_1 (+ (* (- (exp l) (exp (- l))) J) U)))
(if (<= l -8.2e+48)
t_0
(if (<= l -850000.0)
t_1
(if (<= l 1.65e-13)
(+ U (* (* J (cos (* K 0.5))) (* l 2.0)))
(if (<= l 1.05e+89) t_1 t_0))))))
double code(double J, double l, double K, double U) {
double t_0 = U + (cos((K / 2.0)) * (J * (0.3333333333333333 * pow(l, 3.0))));
double t_1 = ((exp(l) - exp(-l)) * J) + U;
double tmp;
if (l <= -8.2e+48) {
tmp = t_0;
} else if (l <= -850000.0) {
tmp = t_1;
} else if (l <= 1.65e-13) {
tmp = U + ((J * cos((K * 0.5))) * (l * 2.0));
} else if (l <= 1.05e+89) {
tmp = t_1;
} else {
tmp = 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 = u + (cos((k / 2.0d0)) * (j * (0.3333333333333333d0 * (l ** 3.0d0))))
t_1 = ((exp(l) - exp(-l)) * j) + u
if (l <= (-8.2d+48)) then
tmp = t_0
else if (l <= (-850000.0d0)) then
tmp = t_1
else if (l <= 1.65d-13) then
tmp = u + ((j * cos((k * 0.5d0))) * (l * 2.0d0))
else if (l <= 1.05d+89) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double t_0 = U + (Math.cos((K / 2.0)) * (J * (0.3333333333333333 * Math.pow(l, 3.0))));
double t_1 = ((Math.exp(l) - Math.exp(-l)) * J) + U;
double tmp;
if (l <= -8.2e+48) {
tmp = t_0;
} else if (l <= -850000.0) {
tmp = t_1;
} else if (l <= 1.65e-13) {
tmp = U + ((J * Math.cos((K * 0.5))) * (l * 2.0));
} else if (l <= 1.05e+89) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(J, l, K, U): t_0 = U + (math.cos((K / 2.0)) * (J * (0.3333333333333333 * math.pow(l, 3.0)))) t_1 = ((math.exp(l) - math.exp(-l)) * J) + U tmp = 0 if l <= -8.2e+48: tmp = t_0 elif l <= -850000.0: tmp = t_1 elif l <= 1.65e-13: tmp = U + ((J * math.cos((K * 0.5))) * (l * 2.0)) elif l <= 1.05e+89: tmp = t_1 else: tmp = t_0 return tmp
function code(J, l, K, U) t_0 = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(0.3333333333333333 * (l ^ 3.0))))) t_1 = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U) tmp = 0.0 if (l <= -8.2e+48) tmp = t_0; elseif (l <= -850000.0) tmp = t_1; elseif (l <= 1.65e-13) tmp = Float64(U + Float64(Float64(J * cos(Float64(K * 0.5))) * Float64(l * 2.0))); elseif (l <= 1.05e+89) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = U + (cos((K / 2.0)) * (J * (0.3333333333333333 * (l ^ 3.0)))); t_1 = ((exp(l) - exp(-l)) * J) + U; tmp = 0.0; if (l <= -8.2e+48) tmp = t_0; elseif (l <= -850000.0) tmp = t_1; elseif (l <= 1.65e-13) tmp = U + ((J * cos((K * 0.5))) * (l * 2.0)); elseif (l <= 1.05e+89) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision]}, If[LessEqual[l, -8.2e+48], t$95$0, If[LessEqual[l, -850000.0], t$95$1, If[LessEqual[l, 1.65e-13], N[(U + N[(N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.05e+89], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\
t_1 := \left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\
\mathbf{if}\;\ell \leq -8.2 \cdot 10^{+48}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\ell \leq -850000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;\ell \leq 1.65 \cdot 10^{-13}:\\
\;\;\;\;U + \left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(\ell \cdot 2\right)\\
\mathbf{elif}\;\ell \leq 1.05 \cdot 10^{+89}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if l < -8.2000000000000005e48 or 1.04999999999999993e89 < l Initial program 100.0%
Taylor expanded in l around 0 95.8%
Taylor expanded in l around inf 95.8%
associate-*r*75.5%
*-commutative75.5%
associate-*r*75.5%
Simplified95.8%
if -8.2000000000000005e48 < l < -8.5e5 or 1.65e-13 < l < 1.04999999999999993e89Initial program 100.0%
Taylor expanded in K around 0 83.3%
if -8.5e5 < l < 1.65e-13Initial program 77.1%
Taylor expanded in l around 0 99.2%
associate-*r*99.2%
*-commutative99.2%
associate-*r*99.2%
associate-*r*99.2%
*-commutative99.2%
associate-*r*99.2%
*-commutative99.2%
distribute-rgt-out99.2%
fma-define99.2%
Simplified99.2%
Taylor expanded in l around 0 99.2%
*-commutative99.2%
associate-*r*99.2%
associate-*l*99.2%
*-commutative99.2%
associate-*l*99.2%
Simplified99.2%
Final simplification96.1%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) 0.05) (+ U (* (* J (cos (* K 0.5))) (* l 2.0))) (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0))))))))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= 0.05) {
tmp = U + ((J * cos((K * 0.5))) * (l * 2.0));
} else {
tmp = U + (J * (l * (2.0 + (0.3333333333333333 * pow(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) :: tmp
if (cos((k / 2.0d0)) <= 0.05d0) then
tmp = u + ((j * cos((k * 0.5d0))) * (l * 2.0d0))
else
tmp = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l ** 2.0d0)))))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if (Math.cos((K / 2.0)) <= 0.05) {
tmp = U + ((J * Math.cos((K * 0.5))) * (l * 2.0));
} else {
tmp = U + (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0)))));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if math.cos((K / 2.0)) <= 0.05: tmp = U + ((J * math.cos((K * 0.5))) * (l * 2.0)) else: tmp = U + (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0))))) return tmp
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= 0.05) tmp = Float64(U + Float64(Float64(J * cos(Float64(K * 0.5))) * Float64(l * 2.0))); else tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0)))))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if (cos((K / 2.0)) <= 0.05) tmp = U + ((J * cos((K * 0.5))) * (l * 2.0)); else tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l ^ 2.0))))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], 0.05], N[(U + N[(N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.05:\\
\;\;\;\;U + \left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(\ell \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < 0.050000000000000003Initial program 88.2%
Taylor expanded in l around 0 84.6%
associate-*r*84.6%
*-commutative84.6%
associate-*r*84.6%
associate-*r*84.6%
*-commutative84.6%
associate-*r*84.6%
*-commutative84.6%
distribute-rgt-out84.6%
fma-define84.6%
Simplified84.6%
Taylor expanded in l around 0 60.7%
*-commutative60.7%
associate-*r*60.8%
associate-*l*60.8%
*-commutative60.8%
associate-*l*60.8%
Simplified60.8%
if 0.050000000000000003 < (cos.f64 (/.f64 K 2)) Initial program 88.2%
Taylor expanded in l around 0 89.9%
Taylor expanded in K around 0 85.6%
Final simplification80.2%
(FPCore (J l K U) :precision binary64 (if (or (<= l -850000.0) (not (<= l 1.65e-13))) (+ (* (- (exp l) (exp (- l))) J) U) (+ U (* (* J (cos (* K 0.5))) (* l 2.0)))))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -850000.0) || !(l <= 1.65e-13)) {
tmp = ((exp(l) - exp(-l)) * J) + U;
} else {
tmp = U + ((J * cos((K * 0.5))) * (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) :: tmp
if ((l <= (-850000.0d0)) .or. (.not. (l <= 1.65d-13))) then
tmp = ((exp(l) - exp(-l)) * j) + u
else
tmp = u + ((j * cos((k * 0.5d0))) * (l * 2.0d0))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -850000.0) || !(l <= 1.65e-13)) {
tmp = ((Math.exp(l) - Math.exp(-l)) * J) + U;
} else {
tmp = U + ((J * Math.cos((K * 0.5))) * (l * 2.0));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -850000.0) or not (l <= 1.65e-13): tmp = ((math.exp(l) - math.exp(-l)) * J) + U else: tmp = U + ((J * math.cos((K * 0.5))) * (l * 2.0)) return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -850000.0) || !(l <= 1.65e-13)) tmp = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U); else tmp = Float64(U + Float64(Float64(J * cos(Float64(K * 0.5))) * Float64(l * 2.0))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -850000.0) || ~((l <= 1.65e-13))) tmp = ((exp(l) - exp(-l)) * J) + U; else tmp = U + ((J * cos((K * 0.5))) * (l * 2.0)); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -850000.0], N[Not[LessEqual[l, 1.65e-13]], $MachinePrecision]], N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -850000 \lor \neg \left(\ell \leq 1.65 \cdot 10^{-13}\right):\\
\;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\
\mathbf{else}:\\
\;\;\;\;U + \left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(\ell \cdot 2\right)\\
\end{array}
\end{array}
if l < -8.5e5 or 1.65e-13 < l Initial program 100.0%
Taylor expanded in K around 0 79.0%
if -8.5e5 < l < 1.65e-13Initial program 77.1%
Taylor expanded in l around 0 99.2%
associate-*r*99.2%
*-commutative99.2%
associate-*r*99.2%
associate-*r*99.2%
*-commutative99.2%
associate-*r*99.2%
*-commutative99.2%
distribute-rgt-out99.2%
fma-define99.2%
Simplified99.2%
Taylor expanded in l around 0 99.2%
*-commutative99.2%
associate-*r*99.2%
associate-*l*99.2%
*-commutative99.2%
associate-*l*99.2%
Simplified99.2%
Final simplification89.5%
(FPCore (J l K U)
:precision binary64
(if (<= l -4.6e+52)
(+ U (* J (* 0.3333333333333333 (pow l 3.0))))
(if (<= l -850000.0)
(log1p (expm1 U))
(if (<= l 2.15e+89)
(+ U (* (* J (cos (* K 0.5))) (* l 2.0)))
(+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0))))))))))
double code(double J, double l, double K, double U) {
double tmp;
if (l <= -4.6e+52) {
tmp = U + (J * (0.3333333333333333 * pow(l, 3.0)));
} else if (l <= -850000.0) {
tmp = log1p(expm1(U));
} else if (l <= 2.15e+89) {
tmp = U + ((J * cos((K * 0.5))) * (l * 2.0));
} else {
tmp = U + (J * (l * (2.0 + (0.3333333333333333 * pow(l, 2.0)))));
}
return tmp;
}
public static double code(double J, double l, double K, double U) {
double tmp;
if (l <= -4.6e+52) {
tmp = U + (J * (0.3333333333333333 * Math.pow(l, 3.0)));
} else if (l <= -850000.0) {
tmp = Math.log1p(Math.expm1(U));
} else if (l <= 2.15e+89) {
tmp = U + ((J * Math.cos((K * 0.5))) * (l * 2.0));
} else {
tmp = U + (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0)))));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if l <= -4.6e+52: tmp = U + (J * (0.3333333333333333 * math.pow(l, 3.0))) elif l <= -850000.0: tmp = math.log1p(math.expm1(U)) elif l <= 2.15e+89: tmp = U + ((J * math.cos((K * 0.5))) * (l * 2.0)) else: tmp = U + (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0))))) return tmp
function code(J, l, K, U) tmp = 0.0 if (l <= -4.6e+52) tmp = Float64(U + Float64(J * Float64(0.3333333333333333 * (l ^ 3.0)))); elseif (l <= -850000.0) tmp = log1p(expm1(U)); elseif (l <= 2.15e+89) tmp = Float64(U + Float64(Float64(J * cos(Float64(K * 0.5))) * Float64(l * 2.0))); else tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0)))))); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[l, -4.6e+52], N[(U + N[(J * N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -850000.0], N[Log[1 + N[(Exp[U] - 1), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, 2.15e+89], N[(U + N[(N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.6 \cdot 10^{+52}:\\
\;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\
\mathbf{elif}\;\ell \leq -850000:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\
\mathbf{elif}\;\ell \leq 2.15 \cdot 10^{+89}:\\
\;\;\;\;U + \left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(\ell \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\
\end{array}
\end{array}
if l < -4.6e52Initial program 100.0%
Taylor expanded in l around 0 94.1%
Taylor expanded in K around 0 84.0%
Taylor expanded in l around inf 84.0%
associate-*r*84.0%
*-commutative84.0%
associate-*r*84.0%
Simplified84.0%
if -4.6e52 < l < -8.5e5Initial program 100.0%
associate-*l*100.0%
fma-define100.0%
Simplified100.0%
Applied egg-rr55.3%
if -8.5e5 < l < 2.1500000000000001e89Initial program 80.2%
Taylor expanded in l around 0 90.6%
associate-*r*90.6%
*-commutative90.6%
associate-*r*90.6%
associate-*r*90.6%
*-commutative90.6%
associate-*r*90.6%
*-commutative90.6%
distribute-rgt-out90.6%
fma-define90.6%
Simplified90.6%
Taylor expanded in l around 0 89.8%
*-commutative89.8%
associate-*r*89.9%
associate-*l*89.9%
*-commutative89.9%
associate-*l*89.9%
Simplified89.9%
if 2.1500000000000001e89 < l Initial program 100.0%
Taylor expanded in l around 0 97.6%
Taylor expanded in K around 0 69.0%
Final simplification83.8%
(FPCore (J l K U) :precision binary64 (if (or (<= l -1.05e+57) (not (<= l 1.08e+89))) (+ U (* J (* 0.3333333333333333 (pow l 3.0)))) (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -1.05e+57) || !(l <= 1.08e+89)) {
tmp = U + (J * (0.3333333333333333 * pow(l, 3.0)));
} 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) :: tmp
if ((l <= (-1.05d+57)) .or. (.not. (l <= 1.08d+89))) then
tmp = u + (j * (0.3333333333333333d0 * (l ** 3.0d0)))
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 tmp;
if ((l <= -1.05e+57) || !(l <= 1.08e+89)) {
tmp = U + (J * (0.3333333333333333 * Math.pow(l, 3.0)));
} else {
tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -1.05e+57) or not (l <= 1.08e+89): tmp = U + (J * (0.3333333333333333 * math.pow(l, 3.0))) else: tmp = U + (2.0 * (J * (l * math.cos((K * 0.5))))) return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -1.05e+57) || !(l <= 1.08e+89)) tmp = Float64(U + Float64(J * Float64(0.3333333333333333 * (l ^ 3.0)))); 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) tmp = 0.0; if ((l <= -1.05e+57) || ~((l <= 1.08e+89))) tmp = U + (J * (0.3333333333333333 * (l ^ 3.0))); else tmp = U + (2.0 * (J * (l * cos((K * 0.5))))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -1.05e+57], N[Not[LessEqual[l, 1.08e+89]], $MachinePrecision]], N[(U + N[(J * N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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}
\mathbf{if}\;\ell \leq -1.05 \cdot 10^{+57} \lor \neg \left(\ell \leq 1.08 \cdot 10^{+89}\right):\\
\;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\
\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 l < -1.04999999999999995e57 or 1.08000000000000006e89 < l Initial program 100.0%
Taylor expanded in l around 0 95.7%
Taylor expanded in K around 0 76.9%
Taylor expanded in l around inf 76.9%
associate-*r*76.9%
*-commutative76.9%
associate-*r*76.9%
Simplified76.9%
if -1.04999999999999995e57 < l < 1.08000000000000006e89Initial program 81.6%
Taylor expanded in l around 0 84.2%
Final simplification81.6%
(FPCore (J l K U) :precision binary64 (if (or (<= l -1e+57) (not (<= l 1.15e+89))) (+ U (* J (* 0.3333333333333333 (pow l 3.0)))) (+ U (* (* J (cos (* K 0.5))) (* l 2.0)))))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -1e+57) || !(l <= 1.15e+89)) {
tmp = U + (J * (0.3333333333333333 * pow(l, 3.0)));
} else {
tmp = U + ((J * cos((K * 0.5))) * (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) :: tmp
if ((l <= (-1d+57)) .or. (.not. (l <= 1.15d+89))) then
tmp = u + (j * (0.3333333333333333d0 * (l ** 3.0d0)))
else
tmp = u + ((j * cos((k * 0.5d0))) * (l * 2.0d0))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -1e+57) || !(l <= 1.15e+89)) {
tmp = U + (J * (0.3333333333333333 * Math.pow(l, 3.0)));
} else {
tmp = U + ((J * Math.cos((K * 0.5))) * (l * 2.0));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -1e+57) or not (l <= 1.15e+89): tmp = U + (J * (0.3333333333333333 * math.pow(l, 3.0))) else: tmp = U + ((J * math.cos((K * 0.5))) * (l * 2.0)) return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -1e+57) || !(l <= 1.15e+89)) tmp = Float64(U + Float64(J * Float64(0.3333333333333333 * (l ^ 3.0)))); else tmp = Float64(U + Float64(Float64(J * cos(Float64(K * 0.5))) * Float64(l * 2.0))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -1e+57) || ~((l <= 1.15e+89))) tmp = U + (J * (0.3333333333333333 * (l ^ 3.0))); else tmp = U + ((J * cos((K * 0.5))) * (l * 2.0)); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -1e+57], N[Not[LessEqual[l, 1.15e+89]], $MachinePrecision]], N[(U + N[(J * N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1 \cdot 10^{+57} \lor \neg \left(\ell \leq 1.15 \cdot 10^{+89}\right):\\
\;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\
\mathbf{else}:\\
\;\;\;\;U + \left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(\ell \cdot 2\right)\\
\end{array}
\end{array}
if l < -1.00000000000000005e57 or 1.1499999999999999e89 < l Initial program 100.0%
Taylor expanded in l around 0 95.7%
Taylor expanded in K around 0 76.9%
Taylor expanded in l around inf 76.9%
associate-*r*76.9%
*-commutative76.9%
associate-*r*76.9%
Simplified76.9%
if -1.00000000000000005e57 < l < 1.1499999999999999e89Initial program 81.6%
Taylor expanded in l around 0 85.5%
associate-*r*85.5%
*-commutative85.5%
associate-*r*85.5%
associate-*r*85.5%
*-commutative85.5%
associate-*r*85.5%
*-commutative85.5%
distribute-rgt-out85.5%
fma-define85.5%
Simplified85.5%
Taylor expanded in l around 0 84.2%
*-commutative84.2%
associate-*r*84.3%
associate-*l*84.3%
*-commutative84.3%
associate-*l*84.3%
Simplified84.3%
Final simplification81.7%
(FPCore (J l K U) :precision binary64 (if (or (<= l -1000000000.0) (not (<= l 1.4e-55))) (+ U (* J (* 0.3333333333333333 (pow l 3.0)))) (+ U (* J (* l 2.0)))))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -1000000000.0) || !(l <= 1.4e-55)) {
tmp = U + (J * (0.3333333333333333 * pow(l, 3.0)));
} else {
tmp = U + (J * (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) :: tmp
if ((l <= (-1000000000.0d0)) .or. (.not. (l <= 1.4d-55))) then
tmp = u + (j * (0.3333333333333333d0 * (l ** 3.0d0)))
else
tmp = u + (j * (l * 2.0d0))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -1000000000.0) || !(l <= 1.4e-55)) {
tmp = U + (J * (0.3333333333333333 * Math.pow(l, 3.0)));
} else {
tmp = U + (J * (l * 2.0));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -1000000000.0) or not (l <= 1.4e-55): tmp = U + (J * (0.3333333333333333 * math.pow(l, 3.0))) else: tmp = U + (J * (l * 2.0)) return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -1000000000.0) || !(l <= 1.4e-55)) tmp = Float64(U + Float64(J * Float64(0.3333333333333333 * (l ^ 3.0)))); else tmp = Float64(U + Float64(J * Float64(l * 2.0))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -1000000000.0) || ~((l <= 1.4e-55))) tmp = U + (J * (0.3333333333333333 * (l ^ 3.0))); else tmp = U + (J * (l * 2.0)); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -1000000000.0], N[Not[LessEqual[l, 1.4e-55]], $MachinePrecision]], N[(U + N[(J * N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1000000000 \lor \neg \left(\ell \leq 1.4 \cdot 10^{-55}\right):\\
\;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\
\end{array}
\end{array}
if l < -1e9 or 1.39999999999999992e-55 < l Initial program 99.4%
Taylor expanded in l around 0 80.3%
Taylor expanded in K around 0 64.4%
Taylor expanded in l around inf 64.4%
associate-*r*64.4%
*-commutative64.4%
associate-*r*64.4%
Simplified64.4%
if -1e9 < l < 1.39999999999999992e-55Initial program 77.1%
Taylor expanded in l around 0 97.7%
Taylor expanded in K around 0 86.6%
Taylor expanded in l around 0 86.6%
*-commutative86.6%
associate-*r*86.6%
*-commutative86.6%
Simplified86.6%
Final simplification75.6%
(FPCore (J l K U) :precision binary64 (if (or (<= l -1e+71) (and (not (<= l -130000000000.0)) (<= l 7.4e+62))) (+ U (* J (* l 2.0))) (pow U -4.0)))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -1e+71) || (!(l <= -130000000000.0) && (l <= 7.4e+62))) {
tmp = U + (J * (l * 2.0));
} else {
tmp = pow(U, -4.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) :: tmp
if ((l <= (-1d+71)) .or. (.not. (l <= (-130000000000.0d0))) .and. (l <= 7.4d+62)) then
tmp = u + (j * (l * 2.0d0))
else
tmp = u ** (-4.0d0)
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -1e+71) || (!(l <= -130000000000.0) && (l <= 7.4e+62))) {
tmp = U + (J * (l * 2.0));
} else {
tmp = Math.pow(U, -4.0);
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -1e+71) or (not (l <= -130000000000.0) and (l <= 7.4e+62)): tmp = U + (J * (l * 2.0)) else: tmp = math.pow(U, -4.0) return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -1e+71) || (!(l <= -130000000000.0) && (l <= 7.4e+62))) tmp = Float64(U + Float64(J * Float64(l * 2.0))); else tmp = U ^ -4.0; end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -1e+71) || (~((l <= -130000000000.0)) && (l <= 7.4e+62))) tmp = U + (J * (l * 2.0)); else tmp = U ^ -4.0; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -1e+71], And[N[Not[LessEqual[l, -130000000000.0]], $MachinePrecision], LessEqual[l, 7.4e+62]]], N[(U + N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[U, -4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1 \cdot 10^{+71} \lor \neg \left(\ell \leq -130000000000\right) \land \ell \leq 7.4 \cdot 10^{+62}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;{U}^{-4}\\
\end{array}
\end{array}
if l < -1e71 or -1.3e11 < l < 7.40000000000000028e62Initial program 84.5%
Taylor expanded in l around 0 93.1%
Taylor expanded in K around 0 82.6%
Taylor expanded in l around 0 69.9%
*-commutative69.9%
associate-*r*69.9%
*-commutative69.9%
Simplified69.9%
if -1e71 < l < -1.3e11 or 7.40000000000000028e62 < l Initial program 100.0%
associate-*l*100.0%
fma-define100.0%
Simplified100.0%
Applied egg-rr37.5%
Final simplification62.3%
(FPCore (J l K U) :precision binary64 (if (<= l 180000.0) U (* U U)))
double code(double J, double l, double K, double U) {
double tmp;
if (l <= 180000.0) {
tmp = U;
} else {
tmp = U * 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 <= 180000.0d0) then
tmp = u
else
tmp = u * u
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if (l <= 180000.0) {
tmp = U;
} else {
tmp = U * U;
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if l <= 180000.0: tmp = U else: tmp = U * U return tmp
function code(J, l, K, U) tmp = 0.0 if (l <= 180000.0) tmp = U; else tmp = Float64(U * U); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if (l <= 180000.0) tmp = U; else tmp = U * U; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[l, 180000.0], U, N[(U * U), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 180000:\\
\;\;\;\;U\\
\mathbf{else}:\\
\;\;\;\;U \cdot U\\
\end{array}
\end{array}
if l < 1.8e5Initial program 84.7%
associate-*l*84.7%
fma-define84.7%
Simplified84.7%
Taylor expanded in J around 0 53.2%
if 1.8e5 < l Initial program 100.0%
associate-*l*100.0%
fma-define100.0%
Simplified100.0%
Applied egg-rr17.2%
Final simplification45.0%
(FPCore (J l K U) :precision binary64 (+ U (* J (* l 2.0))))
double code(double J, double l, double K, double U) {
return U + (J * (l * 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 + (j * (l * 2.0d0))
end function
public static double code(double J, double l, double K, double U) {
return U + (J * (l * 2.0));
}
def code(J, l, K, U): return U + (J * (l * 2.0))
function code(J, l, K, U) return Float64(U + Float64(J * Float64(l * 2.0))) end
function tmp = code(J, l, K, U) tmp = U + (J * (l * 2.0)); end
code[J_, l_, K_, U_] := N[(U + N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
U + J \cdot \left(\ell \cdot 2\right)
\end{array}
Initial program 88.2%
Taylor expanded in l around 0 89.1%
Taylor expanded in K around 0 75.6%
Taylor expanded in l around 0 57.3%
*-commutative57.3%
associate-*r*57.3%
*-commutative57.3%
Simplified57.3%
Final simplification57.3%
(FPCore (J l K U) :precision binary64 1.0)
double code(double J, double l, double K, double U) {
return 1.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 = 1.0d0
end function
public static double code(double J, double l, double K, double U) {
return 1.0;
}
def code(J, l, K, U): return 1.0
function code(J, l, K, U) return 1.0 end
function tmp = code(J, l, K, U) tmp = 1.0; end
code[J_, l_, K_, U_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 88.2%
associate-*l*88.2%
fma-define88.2%
Simplified88.2%
Applied egg-rr2.6%
*-inverses2.6%
Simplified2.6%
Final simplification2.6%
(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 88.2%
associate-*l*88.2%
fma-define88.2%
Simplified88.2%
Taylor expanded in J around 0 41.6%
Final simplification41.6%
herbie shell --seed 2024080
(FPCore (J l K U)
:name "Maksimov and Kolovsky, Equation (4)"
:precision binary64
(+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))