
(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 9 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 (+ (* J (log1p (expm1 (* 2.0 (* l (cos (* K 0.5))))))) U))
double code(double J, double l, double K, double U) {
return (J * log1p(expm1((2.0 * (l * cos((K * 0.5))))))) + U;
}
public static double code(double J, double l, double K, double U) {
return (J * Math.log1p(Math.expm1((2.0 * (l * Math.cos((K * 0.5))))))) + U;
}
def code(J, l, K, U): return (J * math.log1p(math.expm1((2.0 * (l * math.cos((K * 0.5))))))) + U
function code(J, l, K, U) return Float64(Float64(J * log1p(expm1(Float64(2.0 * Float64(l * cos(Float64(K * 0.5))))))) + U) end
code[J_, l_, K_, U_] := N[(N[(J * N[Log[1 + N[(Exp[N[(2.0 * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\right) + U
\end{array}
Initial program 84.8%
Taylor expanded in l around 0 84.6%
*-commutative84.6%
associate-*l*84.6%
*-commutative84.6%
associate-*l*84.6%
distribute-lft-out84.6%
*-commutative84.6%
associate-*r*84.6%
*-commutative84.6%
associate-*r*84.6%
distribute-rgt-out84.6%
fma-def84.6%
Simplified84.6%
Taylor expanded in l around 0 60.8%
*-commutative60.8%
Simplified60.8%
log1p-expm1-u99.3%
*-commutative99.3%
*-commutative99.3%
associate-*l*99.3%
*-commutative99.3%
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (* J (- (exp l) (exp (- l))))))
(if (or (<= t_0 (- INFINITY)) (not (<= t_0 0.0)))
(+ U t_0)
(+ U (* 2.0 (* J (* l (cos (* K 0.5)))))))))
double code(double J, double l, double K, double U) {
double t_0 = J * (exp(l) - exp(-l));
double tmp;
if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 0.0)) {
tmp = U + t_0;
} else {
tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
}
return tmp;
}
public static double code(double J, double l, double K, double U) {
double t_0 = J * (Math.exp(l) - Math.exp(-l));
double tmp;
if ((t_0 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 0.0)) {
tmp = U + t_0;
} else {
tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
}
return tmp;
}
def code(J, l, K, U): t_0 = J * (math.exp(l) - math.exp(-l)) tmp = 0 if (t_0 <= -math.inf) or not (t_0 <= 0.0): tmp = U + t_0 else: tmp = U + (2.0 * (J * (l * math.cos((K * 0.5))))) return tmp
function code(J, l, K, U) t_0 = Float64(J * Float64(exp(l) - exp(Float64(-l)))) tmp = 0.0 if ((t_0 <= Float64(-Inf)) || !(t_0 <= 0.0)) tmp = Float64(U + t_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) t_0 = J * (exp(l) - exp(-l)); tmp = 0.0; if ((t_0 <= -Inf) || ~((t_0 <= 0.0))) tmp = U + t_0; 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[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], N[(U + t$95$0), $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 := J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;U + t_0\\
\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 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < -inf.0 or -0.0 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) Initial program 100.0%
Taylor expanded in K around 0 78.2%
if -inf.0 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < -0.0Initial program 68.4%
Taylor expanded in l around 0 99.4%
Final simplification88.4%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (* 0.3333333333333333 (pow l 3.0)))
(t_1 (cos (* K 0.5)))
(t_2 (+ U (* J (* t_1 t_0))))
(t_3 (+ U (* J (- (exp l) (exp (- l)))))))
(if (<= l -3.4e+151)
t_2
(if (<= l -0.29)
t_3
(if (<= l 0.345)
(+ U (* J (* t_1 (+ t_0 (* 2.0 l)))))
(if (<= l 5.6e+102) t_3 t_2))))))
double code(double J, double l, double K, double U) {
double t_0 = 0.3333333333333333 * pow(l, 3.0);
double t_1 = cos((K * 0.5));
double t_2 = U + (J * (t_1 * t_0));
double t_3 = U + (J * (exp(l) - exp(-l)));
double tmp;
if (l <= -3.4e+151) {
tmp = t_2;
} else if (l <= -0.29) {
tmp = t_3;
} else if (l <= 0.345) {
tmp = U + (J * (t_1 * (t_0 + (2.0 * l))));
} else if (l <= 5.6e+102) {
tmp = t_3;
} else {
tmp = t_2;
}
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) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = 0.3333333333333333d0 * (l ** 3.0d0)
t_1 = cos((k * 0.5d0))
t_2 = u + (j * (t_1 * t_0))
t_3 = u + (j * (exp(l) - exp(-l)))
if (l <= (-3.4d+151)) then
tmp = t_2
else if (l <= (-0.29d0)) then
tmp = t_3
else if (l <= 0.345d0) then
tmp = u + (j * (t_1 * (t_0 + (2.0d0 * l))))
else if (l <= 5.6d+102) then
tmp = t_3
else
tmp = t_2
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double t_0 = 0.3333333333333333 * Math.pow(l, 3.0);
double t_1 = Math.cos((K * 0.5));
double t_2 = U + (J * (t_1 * t_0));
double t_3 = U + (J * (Math.exp(l) - Math.exp(-l)));
double tmp;
if (l <= -3.4e+151) {
tmp = t_2;
} else if (l <= -0.29) {
tmp = t_3;
} else if (l <= 0.345) {
tmp = U + (J * (t_1 * (t_0 + (2.0 * l))));
} else if (l <= 5.6e+102) {
tmp = t_3;
} else {
tmp = t_2;
}
return tmp;
}
def code(J, l, K, U): t_0 = 0.3333333333333333 * math.pow(l, 3.0) t_1 = math.cos((K * 0.5)) t_2 = U + (J * (t_1 * t_0)) t_3 = U + (J * (math.exp(l) - math.exp(-l))) tmp = 0 if l <= -3.4e+151: tmp = t_2 elif l <= -0.29: tmp = t_3 elif l <= 0.345: tmp = U + (J * (t_1 * (t_0 + (2.0 * l)))) elif l <= 5.6e+102: tmp = t_3 else: tmp = t_2 return tmp
function code(J, l, K, U) t_0 = Float64(0.3333333333333333 * (l ^ 3.0)) t_1 = cos(Float64(K * 0.5)) t_2 = Float64(U + Float64(J * Float64(t_1 * t_0))) t_3 = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l))))) tmp = 0.0 if (l <= -3.4e+151) tmp = t_2; elseif (l <= -0.29) tmp = t_3; elseif (l <= 0.345) tmp = Float64(U + Float64(J * Float64(t_1 * Float64(t_0 + Float64(2.0 * l))))); elseif (l <= 5.6e+102) tmp = t_3; else tmp = t_2; end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = 0.3333333333333333 * (l ^ 3.0); t_1 = cos((K * 0.5)); t_2 = U + (J * (t_1 * t_0)); t_3 = U + (J * (exp(l) - exp(-l))); tmp = 0.0; if (l <= -3.4e+151) tmp = t_2; elseif (l <= -0.29) tmp = t_3; elseif (l <= 0.345) tmp = U + (J * (t_1 * (t_0 + (2.0 * l)))); elseif (l <= 5.6e+102) tmp = t_3; else tmp = t_2; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(U + N[(J * N[(t$95$1 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.4e+151], t$95$2, If[LessEqual[l, -0.29], t$95$3, If[LessEqual[l, 0.345], N[(U + N[(J * N[(t$95$1 * N[(t$95$0 + N[(2.0 * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.6e+102], t$95$3, t$95$2]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.3333333333333333 \cdot {\ell}^{3}\\
t_1 := \cos \left(K \cdot 0.5\right)\\
t_2 := U + J \cdot \left(t_1 \cdot t_0\right)\\
t_3 := U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
\mathbf{if}\;\ell \leq -3.4 \cdot 10^{+151}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;\ell \leq -0.29:\\
\;\;\;\;t_3\\
\mathbf{elif}\;\ell \leq 0.345:\\
\;\;\;\;U + J \cdot \left(t_1 \cdot \left(t_0 + 2 \cdot \ell\right)\right)\\
\mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\end{array}
if l < -3.4e151 or 5.60000000000000037e102 < l Initial program 100.0%
Taylor expanded in l around 0 100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
associate-*l*100.0%
distribute-lft-out100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in l around inf 100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
if -3.4e151 < l < -0.28999999999999998 or 0.34499999999999997 < l < 5.60000000000000037e102Initial program 100.0%
Taylor expanded in K around 0 91.7%
if -0.28999999999999998 < l < 0.34499999999999997Initial program 69.1%
Taylor expanded in l around 0 100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
associate-*l*100.0%
distribute-lft-out99.9%
*-commutative99.9%
associate-*r*99.9%
*-commutative99.9%
associate-*r*99.9%
distribute-rgt-out99.9%
fma-def99.9%
Simplified99.9%
fma-udef99.9%
+-commutative99.9%
*-commutative99.9%
Applied egg-rr99.9%
Final simplification98.0%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (* K 0.5)))
(t_1 (+ U (* J (* t_0 (* 0.3333333333333333 (pow l 3.0))))))
(t_2 (+ U (* J (- (exp l) (exp (- l)))))))
(if (<= l -3.4e+151)
t_1
(if (<= l -0.00075)
t_2
(if (<= l 0.0032)
(+ U (* 2.0 (* J (* l t_0))))
(if (<= l 5.6e+102) t_2 t_1))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K * 0.5));
double t_1 = U + (J * (t_0 * (0.3333333333333333 * pow(l, 3.0))));
double t_2 = U + (J * (exp(l) - exp(-l)));
double tmp;
if (l <= -3.4e+151) {
tmp = t_1;
} else if (l <= -0.00075) {
tmp = t_2;
} else if (l <= 0.0032) {
tmp = U + (2.0 * (J * (l * t_0)));
} else if (l <= 5.6e+102) {
tmp = t_2;
} else {
tmp = t_1;
}
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) :: t_2
real(8) :: tmp
t_0 = cos((k * 0.5d0))
t_1 = u + (j * (t_0 * (0.3333333333333333d0 * (l ** 3.0d0))))
t_2 = u + (j * (exp(l) - exp(-l)))
if (l <= (-3.4d+151)) then
tmp = t_1
else if (l <= (-0.00075d0)) then
tmp = t_2
else if (l <= 0.0032d0) then
tmp = u + (2.0d0 * (j * (l * t_0)))
else if (l <= 5.6d+102) then
tmp = t_2
else
tmp = t_1
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 = U + (J * (t_0 * (0.3333333333333333 * Math.pow(l, 3.0))));
double t_2 = U + (J * (Math.exp(l) - Math.exp(-l)));
double tmp;
if (l <= -3.4e+151) {
tmp = t_1;
} else if (l <= -0.00075) {
tmp = t_2;
} else if (l <= 0.0032) {
tmp = U + (2.0 * (J * (l * t_0)));
} else if (l <= 5.6e+102) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K * 0.5)) t_1 = U + (J * (t_0 * (0.3333333333333333 * math.pow(l, 3.0)))) t_2 = U + (J * (math.exp(l) - math.exp(-l))) tmp = 0 if l <= -3.4e+151: tmp = t_1 elif l <= -0.00075: tmp = t_2 elif l <= 0.0032: tmp = U + (2.0 * (J * (l * t_0))) elif l <= 5.6e+102: tmp = t_2 else: tmp = t_1 return tmp
function code(J, l, K, U) t_0 = cos(Float64(K * 0.5)) t_1 = Float64(U + Float64(J * Float64(t_0 * Float64(0.3333333333333333 * (l ^ 3.0))))) t_2 = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l))))) tmp = 0.0 if (l <= -3.4e+151) tmp = t_1; elseif (l <= -0.00075) tmp = t_2; elseif (l <= 0.0032) tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * t_0)))); elseif (l <= 5.6e+102) tmp = t_2; else tmp = t_1; end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K * 0.5)); t_1 = U + (J * (t_0 * (0.3333333333333333 * (l ^ 3.0)))); t_2 = U + (J * (exp(l) - exp(-l))); tmp = 0.0; if (l <= -3.4e+151) tmp = t_1; elseif (l <= -0.00075) tmp = t_2; elseif (l <= 0.0032) tmp = U + (2.0 * (J * (l * t_0))); elseif (l <= 5.6e+102) tmp = t_2; else tmp = t_1; 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[(U + N[(J * N[(t$95$0 * N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.4e+151], t$95$1, If[LessEqual[l, -0.00075], t$95$2, If[LessEqual[l, 0.0032], N[(U + N[(2.0 * N[(J * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.6e+102], t$95$2, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
t_1 := U + J \cdot \left(t_0 \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\
t_2 := U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
\mathbf{if}\;\ell \leq -3.4 \cdot 10^{+151}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\ell \leq -0.00075:\\
\;\;\;\;t_2\\
\mathbf{elif}\;\ell \leq 0.0032:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t_0\right)\right)\\
\mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if l < -3.4e151 or 5.60000000000000037e102 < l Initial program 100.0%
Taylor expanded in l around 0 100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
associate-*l*100.0%
distribute-lft-out100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in l around inf 100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
if -3.4e151 < l < -7.5000000000000002e-4 or 0.00320000000000000015 < l < 5.60000000000000037e102Initial program 100.0%
Taylor expanded in K around 0 91.8%
if -7.5000000000000002e-4 < l < 0.00320000000000000015Initial program 68.9%
Taylor expanded in l around 0 99.4%
Final simplification97.8%
(FPCore (J l K U) :precision binary64 (if (or (<= l -11.5) (not (<= l 5.4))) (+ U (* 0.3333333333333333 (* J (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 <= -11.5) || !(l <= 5.4)) {
tmp = U + (0.3333333333333333 * (J * 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 <= (-11.5d0)) .or. (.not. (l <= 5.4d0))) then
tmp = u + (0.3333333333333333d0 * (j * (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 <= -11.5) || !(l <= 5.4)) {
tmp = U + (0.3333333333333333 * (J * 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 <= -11.5) or not (l <= 5.4): tmp = U + (0.3333333333333333 * (J * 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 <= -11.5) || !(l <= 5.4)) tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (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 <= -11.5) || ~((l <= 5.4))) tmp = U + (0.3333333333333333 * (J * (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, -11.5], N[Not[LessEqual[l, 5.4]], $MachinePrecision]], N[(U + N[(0.3333333333333333 * N[(J * 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 -11.5 \lor \neg \left(\ell \leq 5.4\right):\\
\;\;\;\;U + 0.3333333333333333 \cdot \left(J \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 < -11.5 or 5.4000000000000004 < l Initial program 100.0%
Taylor expanded in l around 0 69.8%
*-commutative69.8%
associate-*l*69.8%
*-commutative69.8%
associate-*l*69.8%
distribute-lft-out69.8%
*-commutative69.8%
associate-*r*69.8%
*-commutative69.8%
associate-*r*69.8%
distribute-rgt-out69.8%
fma-def69.8%
Simplified69.8%
Taylor expanded in K around 0 51.2%
Taylor expanded in l around inf 51.2%
if -11.5 < l < 5.4000000000000004Initial program 69.1%
Taylor expanded in l around 0 99.3%
Final simplification74.9%
(FPCore (J l K U)
:precision binary64
(if (<= l -0.00115)
(+ U (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* 2.0 l))))
(if (<= l 13200000000000.0)
(+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
(+ U (* 0.3333333333333333 (* J (pow l 3.0)))))))
double code(double J, double l, double K, double U) {
double tmp;
if (l <= -0.00115) {
tmp = U + (J * ((0.3333333333333333 * pow(l, 3.0)) + (2.0 * l)));
} else if (l <= 13200000000000.0) {
tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
} else {
tmp = U + (0.3333333333333333 * (J * pow(l, 3.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 <= (-0.00115d0)) then
tmp = u + (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (2.0d0 * l)))
else if (l <= 13200000000000.0d0) then
tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
else
tmp = u + (0.3333333333333333d0 * (j * (l ** 3.0d0)))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if (l <= -0.00115) {
tmp = U + (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (2.0 * l)));
} else if (l <= 13200000000000.0) {
tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
} else {
tmp = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if l <= -0.00115: tmp = U + (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (2.0 * l))) elif l <= 13200000000000.0: tmp = U + (2.0 * (J * (l * math.cos((K * 0.5))))) else: tmp = U + (0.3333333333333333 * (J * math.pow(l, 3.0))) return tmp
function code(J, l, K, U) tmp = 0.0 if (l <= -0.00115) tmp = Float64(U + Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(2.0 * l)))); elseif (l <= 13200000000000.0) tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5)))))); else tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0)))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if (l <= -0.00115) tmp = U + (J * ((0.3333333333333333 * (l ^ 3.0)) + (2.0 * l))); elseif (l <= 13200000000000.0) tmp = U + (2.0 * (J * (l * cos((K * 0.5))))); else tmp = U + (0.3333333333333333 * (J * (l ^ 3.0))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[l, -0.00115], N[(U + N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 13200000000000.0], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -0.00115:\\
\;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)\\
\mathbf{elif}\;\ell \leq 13200000000000:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\end{array}
\end{array}
if l < -0.00115Initial program 100.0%
Taylor expanded in l around 0 69.2%
*-commutative69.2%
associate-*l*69.2%
*-commutative69.2%
associate-*l*69.2%
distribute-lft-out69.2%
*-commutative69.2%
associate-*r*69.2%
*-commutative69.2%
associate-*r*69.2%
distribute-rgt-out69.2%
fma-def69.2%
Simplified69.2%
Taylor expanded in K around 0 53.6%
if -0.00115 < l < 1.32e13Initial program 69.4%
Taylor expanded in l around 0 98.7%
if 1.32e13 < l Initial program 100.0%
Taylor expanded in l around 0 71.5%
*-commutative71.5%
associate-*l*71.5%
*-commutative71.5%
associate-*l*71.5%
distribute-lft-out71.5%
*-commutative71.5%
associate-*r*71.5%
*-commutative71.5%
associate-*r*71.5%
distribute-rgt-out71.5%
fma-def71.5%
Simplified71.5%
Taylor expanded in K around 0 49.6%
Taylor expanded in l around inf 49.6%
Final simplification75.0%
(FPCore (J l K U) :precision binary64 (if (or (<= l -2.9) (not (<= l 1.65e-7))) (+ U (* 0.3333333333333333 (* J (pow l 3.0)))) (+ U (* J (* 2.0 l)))))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -2.9) || !(l <= 1.65e-7)) {
tmp = U + (0.3333333333333333 * (J * pow(l, 3.0)));
} else {
tmp = U + (J * (2.0 * l));
}
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 <= (-2.9d0)) .or. (.not. (l <= 1.65d-7))) then
tmp = u + (0.3333333333333333d0 * (j * (l ** 3.0d0)))
else
tmp = u + (j * (2.0d0 * l))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -2.9) || !(l <= 1.65e-7)) {
tmp = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
} else {
tmp = U + (J * (2.0 * l));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -2.9) or not (l <= 1.65e-7): tmp = U + (0.3333333333333333 * (J * math.pow(l, 3.0))) else: tmp = U + (J * (2.0 * l)) return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -2.9) || !(l <= 1.65e-7)) tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0)))); else tmp = Float64(U + Float64(J * Float64(2.0 * l))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -2.9) || ~((l <= 1.65e-7))) tmp = U + (0.3333333333333333 * (J * (l ^ 3.0))); else tmp = U + (J * (2.0 * l)); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -2.9], N[Not[LessEqual[l, 1.65e-7]], $MachinePrecision]], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(2.0 * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.9 \lor \neg \left(\ell \leq 1.65 \cdot 10^{-7}\right):\\
\;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(2 \cdot \ell\right)\\
\end{array}
\end{array}
if l < -2.89999999999999991 or 1.6500000000000001e-7 < l Initial program 99.7%
Taylor expanded in l around 0 70.5%
*-commutative70.5%
associate-*l*70.5%
*-commutative70.5%
associate-*l*70.5%
distribute-lft-out70.5%
*-commutative70.5%
associate-*r*70.5%
*-commutative70.5%
associate-*r*70.5%
distribute-rgt-out70.5%
fma-def70.5%
Simplified70.5%
Taylor expanded in K around 0 50.8%
Taylor expanded in l around inf 50.8%
if -2.89999999999999991 < l < 1.6500000000000001e-7Initial program 68.7%
Taylor expanded in l around 0 99.8%
associate-*r*99.8%
*-commutative99.8%
associate-*l*99.8%
associate-*r*99.8%
Simplified99.8%
Taylor expanded in K around 0 82.6%
Final simplification66.1%
(FPCore (J l K U) :precision binary64 (+ U (* J (* 2.0 l))))
double code(double J, double l, double K, double U) {
return U + (J * (2.0 * l));
}
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 * (2.0d0 * l))
end function
public static double code(double J, double l, double K, double U) {
return U + (J * (2.0 * l));
}
def code(J, l, K, U): return U + (J * (2.0 * l))
function code(J, l, K, U) return Float64(U + Float64(J * Float64(2.0 * l))) end
function tmp = code(J, l, K, U) tmp = U + (J * (2.0 * l)); end
code[J_, l_, K_, U_] := N[(U + N[(J * N[(2.0 * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
U + J \cdot \left(2 \cdot \ell\right)
\end{array}
Initial program 84.8%
Taylor expanded in l around 0 60.8%
associate-*r*60.8%
*-commutative60.8%
associate-*l*60.8%
associate-*r*60.8%
Simplified60.8%
Taylor expanded in K around 0 49.4%
Final simplification49.4%
(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 84.8%
Applied egg-rr25.9%
Taylor expanded in J around 0 34.4%
Final simplification34.4%
herbie shell --seed 2023334
(FPCore (J l K U)
:name "Maksimov and Kolovsky, Equation (4)"
:precision binary64
(+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))