
(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 10 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 (+ (* (log1p (expm1 (* l (cos (* 0.5 K))))) (* 2.0 J)) U))
double code(double J, double l, double K, double U) {
return (log1p(expm1((l * cos((0.5 * K))))) * (2.0 * J)) + U;
}
public static double code(double J, double l, double K, double U) {
return (Math.log1p(Math.expm1((l * Math.cos((0.5 * K))))) * (2.0 * J)) + U;
}
def code(J, l, K, U): return (math.log1p(math.expm1((l * math.cos((0.5 * K))))) * (2.0 * J)) + U
function code(J, l, K, U) return Float64(Float64(log1p(expm1(Float64(l * cos(Float64(0.5 * K))))) * Float64(2.0 * J)) + U) end
code[J_, l_, K_, U_] := N[(N[(N[Log[1 + N[(Exp[N[(l * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision] * N[(2.0 * J), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot \left(2 \cdot J\right) + U
\end{array}
Initial program 85.9%
Taylor expanded in l around 0 89.5%
Taylor expanded in l around 0 64.9%
associate-*r*64.9%
*-commutative64.9%
Simplified64.9%
log1p-expm1-u99.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (* J (- (exp l) (exp (- l))))))
(if (or (<= t_0 -2e+25) (not (<= t_0 2e+141)))
(+ U t_0)
(+ U (* 2.0 (* (* l (cos (* 0.5 K))) J))))))
double code(double J, double l, double K, double U) {
double t_0 = J * (exp(l) - exp(-l));
double tmp;
if ((t_0 <= -2e+25) || !(t_0 <= 2e+141)) {
tmp = U + t_0;
} else {
tmp = U + (2.0 * ((l * cos((0.5 * K))) * J));
}
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 = j * (exp(l) - exp(-l))
if ((t_0 <= (-2d+25)) .or. (.not. (t_0 <= 2d+141))) then
tmp = u + t_0
else
tmp = u + (2.0d0 * ((l * cos((0.5d0 * k))) * j))
end if
code = tmp
end function
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 <= -2e+25) || !(t_0 <= 2e+141)) {
tmp = U + t_0;
} else {
tmp = U + (2.0 * ((l * Math.cos((0.5 * K))) * J));
}
return tmp;
}
def code(J, l, K, U): t_0 = J * (math.exp(l) - math.exp(-l)) tmp = 0 if (t_0 <= -2e+25) or not (t_0 <= 2e+141): tmp = U + t_0 else: tmp = U + (2.0 * ((l * math.cos((0.5 * K))) * J)) return tmp
function code(J, l, K, U) t_0 = Float64(J * Float64(exp(l) - exp(Float64(-l)))) tmp = 0.0 if ((t_0 <= -2e+25) || !(t_0 <= 2e+141)) tmp = Float64(U + t_0); else tmp = Float64(U + Float64(2.0 * Float64(Float64(l * cos(Float64(0.5 * K))) * J))); 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 <= -2e+25) || ~((t_0 <= 2e+141))) tmp = U + t_0; else tmp = U + (2.0 * ((l * cos((0.5 * K))) * J)); 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, -2e+25], N[Not[LessEqual[t$95$0, 2e+141]], $MachinePrecision]], N[(U + t$95$0), $MachinePrecision], N[(U + N[(2.0 * N[(N[(l * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+25} \lor \neg \left(t_0 \leq 2 \cdot 10^{+141}\right):\\
\;\;\;\;U + t_0\\
\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(\left(\ell \cdot \cos \left(0.5 \cdot K\right)\right) \cdot J\right)\\
\end{array}
\end{array}
if (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < -2.00000000000000018e25 or 2.00000000000000003e141 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) Initial program 100.0%
Taylor expanded in K around 0 74.5%
if -2.00000000000000018e25 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < 2.00000000000000003e141Initial program 71.7%
Taylor expanded in l around 0 99.6%
Final simplification87.0%
(FPCore (J l K U)
:precision binary64
(let* ((t_0
(+ U (* (* (pow l 3.0) (* J 0.3333333333333333)) (cos (/ K 2.0)))))
(t_1 (+ U (* J (- (exp l) (exp (- l)))))))
(if (<= l -5.8e+102)
t_0
(if (<= l -0.00145)
t_1
(if (<= l 1.3e-18)
(+ U (* 2.0 (* (* l (cos (* 0.5 K))) J)))
(if (<= l 5.6e+102) t_1 t_0))))))
double code(double J, double l, double K, double U) {
double t_0 = U + ((pow(l, 3.0) * (J * 0.3333333333333333)) * cos((K / 2.0)));
double t_1 = U + (J * (exp(l) - exp(-l)));
double tmp;
if (l <= -5.8e+102) {
tmp = t_0;
} else if (l <= -0.00145) {
tmp = t_1;
} else if (l <= 1.3e-18) {
tmp = U + (2.0 * ((l * cos((0.5 * K))) * J));
} else if (l <= 5.6e+102) {
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 + (((l ** 3.0d0) * (j * 0.3333333333333333d0)) * cos((k / 2.0d0)))
t_1 = u + (j * (exp(l) - exp(-l)))
if (l <= (-5.8d+102)) then
tmp = t_0
else if (l <= (-0.00145d0)) then
tmp = t_1
else if (l <= 1.3d-18) then
tmp = u + (2.0d0 * ((l * cos((0.5d0 * k))) * j))
else if (l <= 5.6d+102) 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.pow(l, 3.0) * (J * 0.3333333333333333)) * Math.cos((K / 2.0)));
double t_1 = U + (J * (Math.exp(l) - Math.exp(-l)));
double tmp;
if (l <= -5.8e+102) {
tmp = t_0;
} else if (l <= -0.00145) {
tmp = t_1;
} else if (l <= 1.3e-18) {
tmp = U + (2.0 * ((l * Math.cos((0.5 * K))) * J));
} else if (l <= 5.6e+102) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(J, l, K, U): t_0 = U + ((math.pow(l, 3.0) * (J * 0.3333333333333333)) * math.cos((K / 2.0))) t_1 = U + (J * (math.exp(l) - math.exp(-l))) tmp = 0 if l <= -5.8e+102: tmp = t_0 elif l <= -0.00145: tmp = t_1 elif l <= 1.3e-18: tmp = U + (2.0 * ((l * math.cos((0.5 * K))) * J)) elif l <= 5.6e+102: tmp = t_1 else: tmp = t_0 return tmp
function code(J, l, K, U) t_0 = Float64(U + Float64(Float64((l ^ 3.0) * Float64(J * 0.3333333333333333)) * cos(Float64(K / 2.0)))) t_1 = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l))))) tmp = 0.0 if (l <= -5.8e+102) tmp = t_0; elseif (l <= -0.00145) tmp = t_1; elseif (l <= 1.3e-18) tmp = Float64(U + Float64(2.0 * Float64(Float64(l * cos(Float64(0.5 * K))) * J))); elseif (l <= 5.6e+102) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = U + (((l ^ 3.0) * (J * 0.3333333333333333)) * cos((K / 2.0))); t_1 = U + (J * (exp(l) - exp(-l))); tmp = 0.0; if (l <= -5.8e+102) tmp = t_0; elseif (l <= -0.00145) tmp = t_1; elseif (l <= 1.3e-18) tmp = U + (2.0 * ((l * cos((0.5 * K))) * J)); elseif (l <= 5.6e+102) 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[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5.8e+102], t$95$0, If[LessEqual[l, -0.00145], t$95$1, If[LessEqual[l, 1.3e-18], N[(U + N[(2.0 * N[(N[(l * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.6e+102], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := U + \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\
t_1 := U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
\mathbf{if}\;\ell \leq -5.8 \cdot 10^{+102}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\ell \leq -0.00145:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-18}:\\
\;\;\;\;U + 2 \cdot \left(\left(\ell \cdot \cos \left(0.5 \cdot K\right)\right) \cdot J\right)\\
\mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if l < -5.8000000000000005e102 or 5.60000000000000037e102 < l Initial program 100.0%
Taylor expanded in l around 0 100.0%
Taylor expanded in l around inf 100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
if -5.8000000000000005e102 < l < -0.00145 or 1.3e-18 < l < 5.60000000000000037e102Initial program 99.9%
Taylor expanded in K around 0 82.9%
if -0.00145 < l < 1.3e-18Initial program 71.0%
Taylor expanded in l around 0 99.6%
Final simplification97.1%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0)))
(t_1 (+ U (* (* (pow l 3.0) (* J 0.3333333333333333)) t_0)))
(t_2 (+ U (* J (- (exp l) (exp (- l)))))))
(if (<= l -5.8e+102)
t_1
(if (<= l -0.031)
t_2
(if (<= l 2200000.0)
(+ U (* t_0 (* J (+ (* (pow l 3.0) 0.3333333333333333) (* l 2.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 / 2.0));
double t_1 = U + ((pow(l, 3.0) * (J * 0.3333333333333333)) * t_0);
double t_2 = U + (J * (exp(l) - exp(-l)));
double tmp;
if (l <= -5.8e+102) {
tmp = t_1;
} else if (l <= -0.031) {
tmp = t_2;
} else if (l <= 2200000.0) {
tmp = U + (t_0 * (J * ((pow(l, 3.0) * 0.3333333333333333) + (l * 2.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 / 2.0d0))
t_1 = u + (((l ** 3.0d0) * (j * 0.3333333333333333d0)) * t_0)
t_2 = u + (j * (exp(l) - exp(-l)))
if (l <= (-5.8d+102)) then
tmp = t_1
else if (l <= (-0.031d0)) then
tmp = t_2
else if (l <= 2200000.0d0) then
tmp = u + (t_0 * (j * (((l ** 3.0d0) * 0.3333333333333333d0) + (l * 2.0d0))))
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 / 2.0));
double t_1 = U + ((Math.pow(l, 3.0) * (J * 0.3333333333333333)) * t_0);
double t_2 = U + (J * (Math.exp(l) - Math.exp(-l)));
double tmp;
if (l <= -5.8e+102) {
tmp = t_1;
} else if (l <= -0.031) {
tmp = t_2;
} else if (l <= 2200000.0) {
tmp = U + (t_0 * (J * ((Math.pow(l, 3.0) * 0.3333333333333333) + (l * 2.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 / 2.0)) t_1 = U + ((math.pow(l, 3.0) * (J * 0.3333333333333333)) * t_0) t_2 = U + (J * (math.exp(l) - math.exp(-l))) tmp = 0 if l <= -5.8e+102: tmp = t_1 elif l <= -0.031: tmp = t_2 elif l <= 2200000.0: tmp = U + (t_0 * (J * ((math.pow(l, 3.0) * 0.3333333333333333) + (l * 2.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 / 2.0)) t_1 = Float64(U + Float64(Float64((l ^ 3.0) * Float64(J * 0.3333333333333333)) * t_0)) t_2 = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l))))) tmp = 0.0 if (l <= -5.8e+102) tmp = t_1; elseif (l <= -0.031) tmp = t_2; elseif (l <= 2200000.0) tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64((l ^ 3.0) * 0.3333333333333333) + Float64(l * 2.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 / 2.0)); t_1 = U + (((l ^ 3.0) * (J * 0.3333333333333333)) * t_0); t_2 = U + (J * (exp(l) - exp(-l))); tmp = 0.0; if (l <= -5.8e+102) tmp = t_1; elseif (l <= -0.031) tmp = t_2; elseif (l <= 2200000.0) tmp = U + (t_0 * (J * (((l ^ 3.0) * 0.3333333333333333) + (l * 2.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 / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision] * t$95$0), $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, -5.8e+102], t$95$1, If[LessEqual[l, -0.031], t$95$2, If[LessEqual[l, 2200000.0], N[(U + N[(t$95$0 * N[(J * N[(N[(N[Power[l, 3.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $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(\frac{K}{2}\right)\\
t_1 := U + \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot t_0\\
t_2 := U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
\mathbf{if}\;\ell \leq -5.8 \cdot 10^{+102}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\ell \leq -0.031:\\
\;\;\;\;t_2\\
\mathbf{elif}\;\ell \leq 2200000:\\
\;\;\;\;U + t_0 \cdot \left(J \cdot \left({\ell}^{3} \cdot 0.3333333333333333 + \ell \cdot 2\right)\right)\\
\mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if l < -5.8000000000000005e102 or 5.60000000000000037e102 < l Initial program 100.0%
Taylor expanded in l around 0 100.0%
Taylor expanded in l around inf 100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
if -5.8000000000000005e102 < l < -0.031 or 2.2e6 < l < 5.60000000000000037e102Initial program 100.0%
Taylor expanded in K around 0 85.3%
if -0.031 < l < 2.2e6Initial program 72.3%
Taylor expanded in l around 0 98.5%
Final simplification97.3%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.045) (+ U (* -0.3333333333333333 (* J (pow l 3.0)))) (+ U (* J (+ (* (pow l 3.0) 0.3333333333333333) (* l 2.0))))))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= -0.045) {
tmp = U + (-0.3333333333333333 * (J * pow(l, 3.0)));
} else {
tmp = U + (J * ((pow(l, 3.0) * 0.3333333333333333) + (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.045d0)) then
tmp = u + ((-0.3333333333333333d0) * (j * (l ** 3.0d0)))
else
tmp = u + (j * (((l ** 3.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.045) {
tmp = U + (-0.3333333333333333 * (J * Math.pow(l, 3.0)));
} else {
tmp = U + (J * ((Math.pow(l, 3.0) * 0.3333333333333333) + (l * 2.0)));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if math.cos((K / 2.0)) <= -0.045: tmp = U + (-0.3333333333333333 * (J * math.pow(l, 3.0))) else: tmp = U + (J * ((math.pow(l, 3.0) * 0.3333333333333333) + (l * 2.0))) return tmp
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.045) tmp = Float64(U + Float64(-0.3333333333333333 * Float64(J * (l ^ 3.0)))); else tmp = Float64(U + Float64(J * Float64(Float64((l ^ 3.0) * 0.3333333333333333) + Float64(l * 2.0)))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if (cos((K / 2.0)) <= -0.045) tmp = U + (-0.3333333333333333 * (J * (l ^ 3.0))); else tmp = U + (J * (((l ^ 3.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.045], N[(U + N[(-0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(N[(N[Power[l, 3.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.045:\\
\;\;\;\;U + -0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left({\ell}^{3} \cdot 0.3333333333333333 + \ell \cdot 2\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < -0.044999999999999998Initial program 84.2%
Taylor expanded in l around 0 92.2%
Taylor expanded in K around 0 33.7%
add-sqr-sqrt30.5%
sqrt-unprod57.6%
*-commutative57.6%
*-commutative57.6%
swap-sqr57.6%
pow-prod-up57.6%
metadata-eval57.6%
metadata-eval57.6%
Applied egg-rr57.6%
Taylor expanded in l around -inf 75.8%
*-commutative75.8%
Simplified75.8%
if -0.044999999999999998 < (cos.f64 (/.f64 K 2)) Initial program 86.5%
Taylor expanded in l around 0 88.6%
Taylor expanded in K around 0 85.3%
Final simplification83.0%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (* J (pow l 3.0))))
(if (<= (cos (/ K 2.0)) -0.045)
(+ U (* -0.3333333333333333 t_0))
(+ U (* 0.3333333333333333 t_0)))))
double code(double J, double l, double K, double U) {
double t_0 = J * pow(l, 3.0);
double tmp;
if (cos((K / 2.0)) <= -0.045) {
tmp = U + (-0.3333333333333333 * t_0);
} else {
tmp = U + (0.3333333333333333 * 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) :: tmp
t_0 = j * (l ** 3.0d0)
if (cos((k / 2.0d0)) <= (-0.045d0)) then
tmp = u + ((-0.3333333333333333d0) * t_0)
else
tmp = u + (0.3333333333333333d0 * t_0)
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double t_0 = J * Math.pow(l, 3.0);
double tmp;
if (Math.cos((K / 2.0)) <= -0.045) {
tmp = U + (-0.3333333333333333 * t_0);
} else {
tmp = U + (0.3333333333333333 * t_0);
}
return tmp;
}
def code(J, l, K, U): t_0 = J * math.pow(l, 3.0) tmp = 0 if math.cos((K / 2.0)) <= -0.045: tmp = U + (-0.3333333333333333 * t_0) else: tmp = U + (0.3333333333333333 * t_0) return tmp
function code(J, l, K, U) t_0 = Float64(J * (l ^ 3.0)) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.045) tmp = Float64(U + Float64(-0.3333333333333333 * t_0)); else tmp = Float64(U + Float64(0.3333333333333333 * t_0)); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = J * (l ^ 3.0); tmp = 0.0; if (cos((K / 2.0)) <= -0.045) tmp = U + (-0.3333333333333333 * t_0); else tmp = U + (0.3333333333333333 * t_0); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.045], N[(U + N[(-0.3333333333333333 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(U + N[(0.3333333333333333 * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := J \cdot {\ell}^{3}\\
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.045:\\
\;\;\;\;U + -0.3333333333333333 \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;U + 0.3333333333333333 \cdot t_0\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < -0.044999999999999998Initial program 84.2%
Taylor expanded in l around 0 92.2%
Taylor expanded in K around 0 33.7%
add-sqr-sqrt30.5%
sqrt-unprod57.6%
*-commutative57.6%
*-commutative57.6%
swap-sqr57.6%
pow-prod-up57.6%
metadata-eval57.6%
metadata-eval57.6%
Applied egg-rr57.6%
Taylor expanded in l around -inf 75.8%
*-commutative75.8%
Simplified75.8%
if -0.044999999999999998 < (cos.f64 (/.f64 K 2)) Initial program 86.5%
Taylor expanded in l around 0 88.6%
Taylor expanded in K around 0 85.3%
Taylor expanded in l around inf 74.9%
Final simplification75.1%
(FPCore (J l K U) :precision binary64 (if (or (<= l -780000.0) (not (<= l 4.4))) (+ U (* 0.3333333333333333 (* J (pow l 3.0)))) (+ U (* 2.0 (* (* l (cos (* 0.5 K))) J)))))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -780000.0) || !(l <= 4.4)) {
tmp = U + (0.3333333333333333 * (J * pow(l, 3.0)));
} else {
tmp = U + (2.0 * ((l * cos((0.5 * K))) * J));
}
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 <= (-780000.0d0)) .or. (.not. (l <= 4.4d0))) then
tmp = u + (0.3333333333333333d0 * (j * (l ** 3.0d0)))
else
tmp = u + (2.0d0 * ((l * cos((0.5d0 * k))) * j))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -780000.0) || !(l <= 4.4)) {
tmp = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
} else {
tmp = U + (2.0 * ((l * Math.cos((0.5 * K))) * J));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -780000.0) or not (l <= 4.4): tmp = U + (0.3333333333333333 * (J * math.pow(l, 3.0))) else: tmp = U + (2.0 * ((l * math.cos((0.5 * K))) * J)) return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -780000.0) || !(l <= 4.4)) tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0)))); else tmp = Float64(U + Float64(2.0 * Float64(Float64(l * cos(Float64(0.5 * K))) * J))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -780000.0) || ~((l <= 4.4))) tmp = U + (0.3333333333333333 * (J * (l ^ 3.0))); else tmp = U + (2.0 * ((l * cos((0.5 * K))) * J)); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -780000.0], N[Not[LessEqual[l, 4.4]], $MachinePrecision]], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(N[(l * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -780000 \lor \neg \left(\ell \leq 4.4\right):\\
\;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(\left(\ell \cdot \cos \left(0.5 \cdot K\right)\right) \cdot J\right)\\
\end{array}
\end{array}
if l < -7.8e5 or 4.4000000000000004 < l Initial program 100.0%
Taylor expanded in l around 0 79.1%
Taylor expanded in K around 0 58.7%
Taylor expanded in l around inf 58.7%
if -7.8e5 < l < 4.4000000000000004Initial program 71.9%
Taylor expanded in l around 0 99.6%
Final simplification79.1%
(FPCore (J l K U) :precision binary64 (if (<= K 170000000000.0) (+ U (* J (* l 2.0))) (+ U (* -0.3333333333333333 (* J (pow l 3.0))))))
double code(double J, double l, double K, double U) {
double tmp;
if (K <= 170000000000.0) {
tmp = U + (J * (l * 2.0));
} 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 (k <= 170000000000.0d0) then
tmp = u + (j * (l * 2.0d0))
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 (K <= 170000000000.0) {
tmp = U + (J * (l * 2.0));
} else {
tmp = U + (-0.3333333333333333 * (J * Math.pow(l, 3.0)));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if K <= 170000000000.0: tmp = U + (J * (l * 2.0)) else: tmp = U + (-0.3333333333333333 * (J * math.pow(l, 3.0))) return tmp
function code(J, l, K, U) tmp = 0.0 if (K <= 170000000000.0) tmp = Float64(U + Float64(J * Float64(l * 2.0))); 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 (K <= 170000000000.0) tmp = U + (J * (l * 2.0)); else tmp = U + (-0.3333333333333333 * (J * (l ^ 3.0))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[K, 170000000000.0], N[(U + N[(J * N[(l * 2.0), $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}\;K \leq 170000000000:\\
\;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;U + -0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\end{array}
\end{array}
if K < 1.7e11Initial program 87.3%
Taylor expanded in l around 0 63.9%
associate-*r*63.8%
*-commutative63.8%
associate-*l*63.8%
associate-*r*63.8%
Simplified63.8%
Taylor expanded in K around 0 57.6%
if 1.7e11 < K Initial program 80.5%
Taylor expanded in l around 0 90.5%
Taylor expanded in K around 0 57.4%
add-sqr-sqrt39.2%
sqrt-unprod55.5%
*-commutative55.5%
*-commutative55.5%
swap-sqr55.5%
pow-prod-up55.5%
metadata-eval55.5%
metadata-eval55.5%
Applied egg-rr55.5%
Taylor expanded in l around -inf 52.3%
*-commutative52.3%
Simplified52.3%
Final simplification56.6%
(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 85.9%
Taylor expanded in l around 0 64.9%
associate-*r*64.9%
*-commutative64.9%
associate-*l*64.9%
associate-*r*64.9%
Simplified64.9%
Taylor expanded in K around 0 55.4%
Final simplification55.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 85.9%
Taylor expanded in l around 0 89.5%
Taylor expanded in l around inf 75.1%
*-commutative75.1%
*-commutative75.1%
associate-*l*75.1%
Simplified75.1%
Taylor expanded in l around 0 36.3%
Final simplification36.3%
herbie shell --seed 2024024
(FPCore (J l K U)
:name "Maksimov and Kolovsky, Equation (4)"
:precision binary64
(+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))