
(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 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (J l K U) :precision binary64 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = ((j * (exp(l) - exp(-l))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
return ((J * (Math.exp(l) - Math.exp(-l))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U): return ((J * (math.exp(l) - math.exp(-l))) * math.cos((K / 2.0))) + U
function code(J, l, K, U) return Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * cos(Float64(K / 2.0))) + U) end
function tmp = code(J, l, K, U) tmp = ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U; end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
(if (or (<= t_1 -2e+167) (not (<= t_1 0.002)))
(+ (* t_0 (* t_1 J)) U)
(+
U
(*
t_0
(*
J
(+
(* 0.3333333333333333 (pow l 3.0))
(+ (* 0.016666666666666666 (pow l 5.0)) (* l 2.0)))))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double t_1 = exp(l) - exp(-l);
double tmp;
if ((t_1 <= -2e+167) || !(t_1 <= 0.002)) {
tmp = (t_0 * (t_1 * J)) + U;
} else {
tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + ((0.016666666666666666 * pow(l, 5.0)) + (l * 2.0)))));
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos((k / 2.0d0))
t_1 = exp(l) - exp(-l)
if ((t_1 <= (-2d+167)) .or. (.not. (t_1 <= 0.002d0))) then
tmp = (t_0 * (t_1 * j)) + u
else
tmp = u + (t_0 * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + ((0.016666666666666666d0 * (l ** 5.0d0)) + (l * 2.0d0)))))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double t_0 = Math.cos((K / 2.0));
double t_1 = Math.exp(l) - Math.exp(-l);
double tmp;
if ((t_1 <= -2e+167) || !(t_1 <= 0.002)) {
tmp = (t_0 * (t_1 * J)) + U;
} else {
tmp = U + (t_0 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + ((0.016666666666666666 * Math.pow(l, 5.0)) + (l * 2.0)))));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) t_1 = math.exp(l) - math.exp(-l) tmp = 0 if (t_1 <= -2e+167) or not (t_1 <= 0.002): tmp = (t_0 * (t_1 * J)) + U else: tmp = U + (t_0 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + ((0.016666666666666666 * math.pow(l, 5.0)) + (l * 2.0))))) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) t_1 = Float64(exp(l) - exp(Float64(-l))) tmp = 0.0 if ((t_1 <= -2e+167) || !(t_1 <= 0.002)) tmp = Float64(Float64(t_0 * Float64(t_1 * J)) + U); else tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(Float64(0.016666666666666666 * (l ^ 5.0)) + Float64(l * 2.0)))))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K / 2.0)); t_1 = exp(l) - exp(-l); tmp = 0.0; if ((t_1 <= -2e+167) || ~((t_1 <= 0.002))) tmp = (t_0 * (t_1 * J)) + U; else tmp = U + (t_0 * (J * ((0.3333333333333333 * (l ^ 3.0)) + ((0.016666666666666666 * (l ^ 5.0)) + (l * 2.0))))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -2e+167], N[Not[LessEqual[t$95$1, 0.002]], $MachinePrecision]], N[(N[(t$95$0 * N[(t$95$1 * J), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+167} \lor \neg \left(t_1 \leq 0.002\right):\\
\;\;\;\;t_0 \cdot \left(t_1 \cdot J\right) + U\\
\mathbf{else}:\\
\;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \left(0.016666666666666666 \cdot {\ell}^{5} + \ell \cdot 2\right)\right)\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -2.0000000000000001e167 or 2e-3 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) Initial program 100.0%
if -2.0000000000000001e167 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2e-3Initial program 74.3%
Taylor expanded in l around 0 99.9%
Final simplification100.0%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
(if (or (<= t_1 -2e+167) (not (<= t_1 0.002)))
(+ (* t_0 (* t_1 J)) U)
(+
U
(* t_0 (+ (* 2.0 (* l J)) (* 0.3333333333333333 (* J (pow l 3.0)))))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double t_1 = exp(l) - exp(-l);
double tmp;
if ((t_1 <= -2e+167) || !(t_1 <= 0.002)) {
tmp = (t_0 * (t_1 * J)) + U;
} else {
tmp = U + (t_0 * ((2.0 * (l * J)) + (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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos((k / 2.0d0))
t_1 = exp(l) - exp(-l)
if ((t_1 <= (-2d+167)) .or. (.not. (t_1 <= 0.002d0))) then
tmp = (t_0 * (t_1 * j)) + u
else
tmp = u + (t_0 * ((2.0d0 * (l * j)) + (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 t_0 = Math.cos((K / 2.0));
double t_1 = Math.exp(l) - Math.exp(-l);
double tmp;
if ((t_1 <= -2e+167) || !(t_1 <= 0.002)) {
tmp = (t_0 * (t_1 * J)) + U;
} else {
tmp = U + (t_0 * ((2.0 * (l * J)) + (0.3333333333333333 * (J * Math.pow(l, 3.0)))));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) t_1 = math.exp(l) - math.exp(-l) tmp = 0 if (t_1 <= -2e+167) or not (t_1 <= 0.002): tmp = (t_0 * (t_1 * J)) + U else: tmp = U + (t_0 * ((2.0 * (l * J)) + (0.3333333333333333 * (J * math.pow(l, 3.0))))) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) t_1 = Float64(exp(l) - exp(Float64(-l))) tmp = 0.0 if ((t_1 <= -2e+167) || !(t_1 <= 0.002)) tmp = Float64(Float64(t_0 * Float64(t_1 * J)) + U); else tmp = Float64(U + Float64(t_0 * Float64(Float64(2.0 * Float64(l * J)) + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0)))))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K / 2.0)); t_1 = exp(l) - exp(-l); tmp = 0.0; if ((t_1 <= -2e+167) || ~((t_1 <= 0.002))) tmp = (t_0 * (t_1 * J)) + U; else tmp = U + (t_0 * ((2.0 * (l * J)) + (0.3333333333333333 * (J * (l ^ 3.0))))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -2e+167], N[Not[LessEqual[t$95$1, 0.002]], $MachinePrecision]], N[(N[(t$95$0 * N[(t$95$1 * J), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+167} \lor \neg \left(t_1 \leq 0.002\right):\\
\;\;\;\;t_0 \cdot \left(t_1 \cdot J\right) + U\\
\mathbf{else}:\\
\;\;\;\;U + t_0 \cdot \left(2 \cdot \left(\ell \cdot J\right) + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -2.0000000000000001e167 or 2e-3 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) Initial program 100.0%
if -2.0000000000000001e167 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2e-3Initial program 74.3%
Taylor expanded in l around 0 99.9%
Final simplification99.9%
(FPCore (J l K U)
:precision binary64
(if (or (<= l -5.2e+111)
(not (or (<= l -130.0) (and (not (<= l 0.046)) (<= l 5.6e+102)))))
(+
U
(* (cos (/ K 2.0)) (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))
(+ U (* (- (exp l) (exp (- l))) J))))
double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -5.2e+111) || !((l <= -130.0) || (!(l <= 0.046) && (l <= 5.6e+102)))) {
tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
} else {
tmp = U + ((exp(l) - exp(-l)) * 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 <= (-5.2d+111)) .or. (.not. (l <= (-130.0d0)) .or. (.not. (l <= 0.046d0)) .and. (l <= 5.6d+102))) then
tmp = u + (cos((k / 2.0d0)) * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
else
tmp = u + ((exp(l) - exp(-l)) * j)
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if ((l <= -5.2e+111) || !((l <= -130.0) || (!(l <= 0.046) && (l <= 5.6e+102)))) {
tmp = U + (Math.cos((K / 2.0)) * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
} else {
tmp = U + ((Math.exp(l) - Math.exp(-l)) * J);
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (l <= -5.2e+111) or not ((l <= -130.0) or (not (l <= 0.046) and (l <= 5.6e+102))): tmp = U + (math.cos((K / 2.0)) * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0)))) else: tmp = U + ((math.exp(l) - math.exp(-l)) * J) return tmp
function code(J, l, K, U) tmp = 0.0 if ((l <= -5.2e+111) || !((l <= -130.0) || (!(l <= 0.046) && (l <= 5.6e+102)))) tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))))); else tmp = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J)); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((l <= -5.2e+111) || ~(((l <= -130.0) || (~((l <= 0.046)) && (l <= 5.6e+102))))) tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0)))); else tmp = U + ((exp(l) - exp(-l)) * J); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -5.2e+111], N[Not[Or[LessEqual[l, -130.0], And[N[Not[LessEqual[l, 0.046]], $MachinePrecision], LessEqual[l, 5.6e+102]]]], $MachinePrecision]], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.2 \cdot 10^{+111} \lor \neg \left(\ell \leq -130 \lor \neg \left(\ell \leq 0.046\right) \land \ell \leq 5.6 \cdot 10^{+102}\right):\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\end{array}
\end{array}
if l < -5.1999999999999997e111 or -130 < l < 0.045999999999999999 or 5.60000000000000037e102 < l Initial program 84.1%
Taylor expanded in l around 0 99.9%
if -5.1999999999999997e111 < l < -130 or 0.045999999999999999 < l < 5.60000000000000037e102Initial program 100.0%
Taylor expanded in K around 0 73.3%
Final simplification94.9%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (+ U (* (- (exp l) (exp (- l))) J)))
(t_1 (cos (/ K 2.0)))
(t_2
(+ U (* t_1 (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))))
(if (<= l -5.2e+111)
t_2
(if (<= l -130.0)
t_0
(if (<= l 0.0145)
(+
U
(* t_1 (+ (* 2.0 (* l J)) (* 0.3333333333333333 (* J (pow l 3.0))))))
(if (<= l 5.2e+102) t_0 t_2))))))
double code(double J, double l, double K, double U) {
double t_0 = U + ((exp(l) - exp(-l)) * J);
double t_1 = cos((K / 2.0));
double t_2 = U + (t_1 * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
double tmp;
if (l <= -5.2e+111) {
tmp = t_2;
} else if (l <= -130.0) {
tmp = t_0;
} else if (l <= 0.0145) {
tmp = U + (t_1 * ((2.0 * (l * J)) + (0.3333333333333333 * (J * pow(l, 3.0)))));
} else if (l <= 5.2e+102) {
tmp = t_0;
} 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) :: tmp
t_0 = u + ((exp(l) - exp(-l)) * j)
t_1 = cos((k / 2.0d0))
t_2 = u + (t_1 * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
if (l <= (-5.2d+111)) then
tmp = t_2
else if (l <= (-130.0d0)) then
tmp = t_0
else if (l <= 0.0145d0) then
tmp = u + (t_1 * ((2.0d0 * (l * j)) + (0.3333333333333333d0 * (j * (l ** 3.0d0)))))
else if (l <= 5.2d+102) then
tmp = t_0
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 = U + ((Math.exp(l) - Math.exp(-l)) * J);
double t_1 = Math.cos((K / 2.0));
double t_2 = U + (t_1 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
double tmp;
if (l <= -5.2e+111) {
tmp = t_2;
} else if (l <= -130.0) {
tmp = t_0;
} else if (l <= 0.0145) {
tmp = U + (t_1 * ((2.0 * (l * J)) + (0.3333333333333333 * (J * Math.pow(l, 3.0)))));
} else if (l <= 5.2e+102) {
tmp = t_0;
} else {
tmp = t_2;
}
return tmp;
}
def code(J, l, K, U): t_0 = U + ((math.exp(l) - math.exp(-l)) * J) t_1 = math.cos((K / 2.0)) t_2 = U + (t_1 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0)))) tmp = 0 if l <= -5.2e+111: tmp = t_2 elif l <= -130.0: tmp = t_0 elif l <= 0.0145: tmp = U + (t_1 * ((2.0 * (l * J)) + (0.3333333333333333 * (J * math.pow(l, 3.0))))) elif l <= 5.2e+102: tmp = t_0 else: tmp = t_2 return tmp
function code(J, l, K, U) t_0 = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J)) t_1 = cos(Float64(K / 2.0)) t_2 = Float64(U + Float64(t_1 * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))))) tmp = 0.0 if (l <= -5.2e+111) tmp = t_2; elseif (l <= -130.0) tmp = t_0; elseif (l <= 0.0145) tmp = Float64(U + Float64(t_1 * Float64(Float64(2.0 * Float64(l * J)) + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0)))))); elseif (l <= 5.2e+102) tmp = t_0; else tmp = t_2; end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = U + ((exp(l) - exp(-l)) * J); t_1 = cos((K / 2.0)); t_2 = U + (t_1 * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0)))); tmp = 0.0; if (l <= -5.2e+111) tmp = t_2; elseif (l <= -130.0) tmp = t_0; elseif (l <= 0.0145) tmp = U + (t_1 * ((2.0 * (l * J)) + (0.3333333333333333 * (J * (l ^ 3.0))))); elseif (l <= 5.2e+102) tmp = t_0; else tmp = t_2; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(U + N[(t$95$1 * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5.2e+111], t$95$2, If[LessEqual[l, -130.0], t$95$0, If[LessEqual[l, 0.0145], N[(U + N[(t$95$1 * N[(N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.2e+102], t$95$0, t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
t_1 := \cos \left(\frac{K}{2}\right)\\
t_2 := U + t_1 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\
\mathbf{if}\;\ell \leq -5.2 \cdot 10^{+111}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;\ell \leq -130:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\ell \leq 0.0145:\\
\;\;\;\;U + t_1 \cdot \left(2 \cdot \left(\ell \cdot J\right) + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)\\
\mathbf{elif}\;\ell \leq 5.2 \cdot 10^{+102}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\end{array}
if l < -5.1999999999999997e111 or 5.20000000000000013e102 < l Initial program 100.0%
Taylor expanded in l around 0 100.0%
if -5.1999999999999997e111 < l < -130 or 0.0145000000000000007 < l < 5.20000000000000013e102Initial program 100.0%
Taylor expanded in K around 0 73.3%
if -130 < l < 0.0145000000000000007Initial program 74.3%
Taylor expanded in l around 0 99.9%
Final simplification94.9%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0))))
(if (<= t_0 0.5989)
(+ U (* t_0 (* l (* J 2.0))))
(+ U (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))))
double code(double J, double l, double K, double U) {
double t_0 = cos((K / 2.0));
double tmp;
if (t_0 <= 0.5989) {
tmp = U + (t_0 * (l * (J * 2.0)));
} else {
tmp = U + (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0)));
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
real(8) :: tmp
t_0 = cos((k / 2.0d0))
if (t_0 <= 0.5989d0) then
tmp = u + (t_0 * (l * (j * 2.0d0)))
else
tmp = u + (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0)))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double t_0 = Math.cos((K / 2.0));
double tmp;
if (t_0 <= 0.5989) {
tmp = U + (t_0 * (l * (J * 2.0)));
} else {
tmp = U + (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0)));
}
return tmp;
}
def code(J, l, K, U): t_0 = math.cos((K / 2.0)) tmp = 0 if t_0 <= 0.5989: tmp = U + (t_0 * (l * (J * 2.0))) else: tmp = U + (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))) return tmp
function code(J, l, K, U) t_0 = cos(Float64(K / 2.0)) tmp = 0.0 if (t_0 <= 0.5989) tmp = Float64(U + Float64(t_0 * Float64(l * Float64(J * 2.0)))); else tmp = Float64(U + Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = cos((K / 2.0)); tmp = 0.0; if (t_0 <= 0.5989) tmp = U + (t_0 * (l * (J * 2.0))); else tmp = U + (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.5989], N[(U + N[(t$95$0 * N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t_0 \leq 0.5989:\\
\;\;\;\;U + t_0 \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < 0.59889999999999999Initial program 85.4%
Taylor expanded in l around 0 66.2%
*-commutative66.2%
associate-*l*66.2%
Simplified66.2%
if 0.59889999999999999 < (cos.f64 (/.f64 K 2)) Initial program 88.1%
Taylor expanded in l around 0 87.3%
Taylor expanded in K around 0 84.3%
Final simplification77.3%
(FPCore (J l K U)
:precision binary64
(let* ((t_0 (+ U (* (- (exp l) (exp (- l))) J))))
(if (<= l -130.0)
t_0
(if (<= l 0.0038)
(+ U (* (cos (/ K 2.0)) (* l (* J 2.0))))
(if (<= l 3.5e+255) t_0 (+ U (* 2.0 (* l (* J (cos (* K 0.5)))))))))))
double code(double J, double l, double K, double U) {
double t_0 = U + ((exp(l) - exp(-l)) * J);
double tmp;
if (l <= -130.0) {
tmp = t_0;
} else if (l <= 0.0038) {
tmp = U + (cos((K / 2.0)) * (l * (J * 2.0)));
} else if (l <= 3.5e+255) {
tmp = t_0;
} else {
tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
}
return tmp;
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
real(8) :: tmp
t_0 = u + ((exp(l) - exp(-l)) * j)
if (l <= (-130.0d0)) then
tmp = t_0
else if (l <= 0.0038d0) then
tmp = u + (cos((k / 2.0d0)) * (l * (j * 2.0d0)))
else if (l <= 3.5d+255) then
tmp = t_0
else
tmp = u + (2.0d0 * (l * (j * cos((k * 0.5d0)))))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double t_0 = U + ((Math.exp(l) - Math.exp(-l)) * J);
double tmp;
if (l <= -130.0) {
tmp = t_0;
} else if (l <= 0.0038) {
tmp = U + (Math.cos((K / 2.0)) * (l * (J * 2.0)));
} else if (l <= 3.5e+255) {
tmp = t_0;
} else {
tmp = U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
}
return tmp;
}
def code(J, l, K, U): t_0 = U + ((math.exp(l) - math.exp(-l)) * J) tmp = 0 if l <= -130.0: tmp = t_0 elif l <= 0.0038: tmp = U + (math.cos((K / 2.0)) * (l * (J * 2.0))) elif l <= 3.5e+255: tmp = t_0 else: tmp = U + (2.0 * (l * (J * math.cos((K * 0.5))))) return tmp
function code(J, l, K, U) t_0 = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J)) tmp = 0.0 if (l <= -130.0) tmp = t_0; elseif (l <= 0.0038) tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(l * Float64(J * 2.0)))); elseif (l <= 3.5e+255) tmp = t_0; else tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5)))))); end return tmp end
function tmp_2 = code(J, l, K, U) t_0 = U + ((exp(l) - exp(-l)) * J); tmp = 0.0; if (l <= -130.0) tmp = t_0; elseif (l <= 0.0038) tmp = U + (cos((K / 2.0)) * (l * (J * 2.0))); elseif (l <= 3.5e+255) tmp = t_0; else tmp = U + (2.0 * (l * (J * cos((K * 0.5))))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -130.0], t$95$0, If[LessEqual[l, 0.0038], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 3.5e+255], t$95$0, N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;\ell \leq -130:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\ell \leq 0.0038:\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\
\mathbf{elif}\;\ell \leq 3.5 \cdot 10^{+255}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if l < -130 or 0.00379999999999999999 < l < 3.49999999999999986e255Initial program 100.0%
Taylor expanded in K around 0 75.3%
if -130 < l < 0.00379999999999999999Initial program 74.3%
Taylor expanded in l around 0 99.4%
*-commutative99.4%
associate-*l*99.4%
Simplified99.4%
if 3.49999999999999986e255 < l Initial program 100.0%
Taylor expanded in l around 0 84.0%
*-commutative84.0%
associate-*l*84.0%
*-commutative84.0%
Simplified84.0%
Final simplification87.7%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.56) (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25)))) (+ U (* 2.0 (* l J)))))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= -0.56) {
tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
} else {
tmp = U + (2.0 * (l * 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 (cos((k / 2.0d0)) <= (-0.56d0)) then
tmp = u + ((l * j) * (2.0d0 + ((k * k) * (-0.25d0))))
else
tmp = u + (2.0d0 * (l * j))
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.56) {
tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
} else {
tmp = U + (2.0 * (l * J));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if math.cos((K / 2.0)) <= -0.56: tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25))) else: tmp = U + (2.0 * (l * J)) return tmp
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.56) tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25)))); else tmp = Float64(U + Float64(2.0 * Float64(l * J))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if (cos((K / 2.0)) <= -0.56) tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25))); else tmp = U + (2.0 * (l * J)); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.56], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.56:\\
\;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\
\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K 2)) < -0.56000000000000005Initial program 82.7%
Taylor expanded in l around 0 58.5%
*-commutative58.5%
associate-*l*58.5%
*-commutative58.5%
Simplified58.5%
Taylor expanded in K around 0 39.6%
associate-+r+39.6%
+-commutative39.6%
associate-*r*39.6%
distribute-rgt-out50.7%
*-commutative50.7%
unpow250.7%
Simplified50.7%
if -0.56000000000000005 < (cos.f64 (/.f64 K 2)) Initial program 88.0%
Taylor expanded in l around 0 65.4%
*-commutative65.4%
associate-*l*65.4%
*-commutative65.4%
Simplified65.4%
Taylor expanded in K around 0 58.8%
Final simplification57.4%
(FPCore (J l K U) :precision binary64 (+ U (* 2.0 (* l (* J (cos (* K 0.5)))))))
double code(double J, double l, double K, double U) {
return U + (2.0 * (l * (J * cos((K * 0.5)))));
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = u + (2.0d0 * (l * (j * cos((k * 0.5d0)))))
end function
public static double code(double J, double l, double K, double U) {
return U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
}
def code(J, l, K, U): return U + (2.0 * (l * (J * math.cos((K * 0.5)))))
function code(J, l, K, U) return Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5)))))) end
function tmp = code(J, l, K, U) tmp = U + (2.0 * (l * (J * cos((K * 0.5))))); end
code[J_, l_, K_, U_] := N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)
\end{array}
Initial program 87.1%
Taylor expanded in l around 0 64.2%
*-commutative64.2%
associate-*l*64.2%
*-commutative64.2%
Simplified64.2%
Final simplification64.2%
(FPCore (J l K U) :precision binary64 (+ U (* (cos (/ K 2.0)) (* l (* J 2.0)))))
double code(double J, double l, double K, double U) {
return U + (cos((K / 2.0)) * (l * (J * 2.0)));
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = u + (cos((k / 2.0d0)) * (l * (j * 2.0d0)))
end function
public static double code(double J, double l, double K, double U) {
return U + (Math.cos((K / 2.0)) * (l * (J * 2.0)));
}
def code(J, l, K, U): return U + (math.cos((K / 2.0)) * (l * (J * 2.0)))
function code(J, l, K, U) return Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(l * Float64(J * 2.0)))) end
function tmp = code(J, l, K, U) tmp = U + (cos((K / 2.0)) * (l * (J * 2.0))); end
code[J_, l_, K_, U_] := N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)
\end{array}
Initial program 87.1%
Taylor expanded in l around 0 64.2%
*-commutative64.2%
associate-*l*64.2%
Simplified64.2%
Final simplification64.2%
(FPCore (J l K U) :precision binary64 (if (<= l -1.1e+25) (* U U) (if (<= l 1200.0) U (* U U))))
double code(double J, double l, double K, double U) {
double tmp;
if (l <= -1.1e+25) {
tmp = U * U;
} else if (l <= 1200.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 <= (-1.1d+25)) then
tmp = u * u
else if (l <= 1200.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 <= -1.1e+25) {
tmp = U * U;
} else if (l <= 1200.0) {
tmp = U;
} else {
tmp = U * U;
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if l <= -1.1e+25: tmp = U * U elif l <= 1200.0: tmp = U else: tmp = U * U return tmp
function code(J, l, K, U) tmp = 0.0 if (l <= -1.1e+25) tmp = Float64(U * U); elseif (l <= 1200.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 <= -1.1e+25) tmp = U * U; elseif (l <= 1200.0) tmp = U; else tmp = U * U; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[l, -1.1e+25], N[(U * U), $MachinePrecision], If[LessEqual[l, 1200.0], U, N[(U * U), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.1 \cdot 10^{+25}:\\
\;\;\;\;U \cdot U\\
\mathbf{elif}\;\ell \leq 1200:\\
\;\;\;\;U\\
\mathbf{else}:\\
\;\;\;\;U \cdot U\\
\end{array}
\end{array}
if l < -1.1e25 or 1200 < l Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Applied egg-rr13.7%
if -1.1e25 < l < 1200Initial program 75.3%
*-commutative75.3%
associate-*l*75.3%
fma-def75.3%
Simplified75.3%
Taylor expanded in l around 0 70.7%
Final simplification43.6%
(FPCore (J l K U) :precision binary64 (+ U (* 2.0 (* l J))))
double code(double J, double l, double K, double U) {
return U + (2.0 * (l * J));
}
real(8) function code(j, l, k, u)
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = u + (2.0d0 * (l * j))
end function
public static double code(double J, double l, double K, double U) {
return U + (2.0 * (l * J));
}
def code(J, l, K, U): return U + (2.0 * (l * J))
function code(J, l, K, U) return Float64(U + Float64(2.0 * Float64(l * J))) end
function tmp = code(J, l, K, U) tmp = U + (2.0 * (l * J)); end
code[J_, l_, K_, U_] := N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
U + 2 \cdot \left(\ell \cdot J\right)
\end{array}
Initial program 87.1%
Taylor expanded in l around 0 64.2%
*-commutative64.2%
associate-*l*64.2%
*-commutative64.2%
Simplified64.2%
Taylor expanded in K around 0 53.3%
Final simplification53.3%
(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 87.1%
*-commutative87.1%
associate-*l*87.1%
fma-def87.1%
Simplified87.1%
Taylor expanded in l around 0 38.0%
Final simplification38.0%
herbie shell --seed 2023240
(FPCore (J l K U)
:name "Maksimov and Kolovsky, Equation (4)"
:precision binary64
(+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))