Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 87.1% → 99.6%
Time: 11.1s
Alternatives: 17
Speedup: 1.4×

Specification

?
\[\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 (- (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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 17 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 87.1% accurate, 1.0× speedup?

\[\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 (- (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}

Alternative 1: 99.6% accurate, 0.4× speedup?

\[\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 -1 \lor \neg \left(t\_1 \leq 2 \cdot 10^{-14}\right):\\ \;\;\;\;\left(t\_1 \cdot J\right) \cdot t\_0 + U\\ \mathbf{else}:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \end{array} \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 -1.0) (not (<= t_1 2e-14)))
     (+ (* (* t_1 J) t_0) U)
     (+ U (* t_0 (* J (* 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 <= -1.0) || !(t_1 <= 2e-14)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    t_1 = exp(l) - exp(-l)
    if ((t_1 <= (-1.0d0)) .or. (.not. (t_1 <= 2d-14))) then
        tmp = ((t_1 * j) * t_0) + u
    else
        tmp = u + (t_0 * (j * (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 <= -1.0) || !(t_1 <= 2e-14)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * (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 <= -1.0) or not (t_1 <= 2e-14):
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (t_0 * (J * (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 <= -1.0) || !(t_1 <= 2e-14))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * 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 <= -1.0) || ~((t_1 <= 2e-14)))
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (t_0 * (J * (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, -1.0], N[Not[LessEqual[t$95$1, 2e-14]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $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 -1 \lor \neg \left(t\_1 \leq 2 \cdot 10^{-14}\right):\\
\;\;\;\;\left(t\_1 \cdot J\right) \cdot t\_0 + U\\

\mathbf{else}:\\
\;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -1 or 2e-14 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing

    if -1 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2e-14

    1. Initial program 73.7%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 100.0%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*100.0%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified100.0%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification100.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -1 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 2 \cdot 10^{-14}\right):\\ \;\;\;\;\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 82.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.05:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.05)
   (* U (+ 1.0 (* 2.0 (* J (/ (* l (cos (* K 0.5))) U)))))
   (+ (* (- (exp l) (exp (- l))) J) U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.05) {
		tmp = U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U))));
	} else {
		tmp = ((exp(l) - exp(-l)) * J) + U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (cos((k / 2.0d0)) <= (-0.05d0)) then
        tmp = u * (1.0d0 + (2.0d0 * (j * ((l * cos((k * 0.5d0))) / u))))
    else
        tmp = ((exp(l) - exp(-l)) * j) + u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (Math.cos((K / 2.0)) <= -0.05) {
		tmp = U * (1.0 + (2.0 * (J * ((l * Math.cos((K * 0.5))) / U))));
	} else {
		tmp = ((Math.exp(l) - Math.exp(-l)) * J) + U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if math.cos((K / 2.0)) <= -0.05:
		tmp = U * (1.0 + (2.0 * (J * ((l * math.cos((K * 0.5))) / U))))
	else:
		tmp = ((math.exp(l) - math.exp(-l)) * J) + U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.05)
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(Float64(l * cos(Float64(K * 0.5))) / U)))));
	else
		tmp = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (cos((K / 2.0)) <= -0.05)
		tmp = U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U))));
	else
		tmp = ((exp(l) - exp(-l)) * J) + U;
	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[(1.0 + N[(2.0 * N[(J * N[(N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.05:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.050000000000000003

    1. Initial program 88.5%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 59.8%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative59.8%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*59.8%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified59.8%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Step-by-step derivation
      1. add-cbrt-cube71.4%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right)}} + U \]
      2. pow371.4%

        \[\leadsto \sqrt[3]{\color{blue}{{\left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right)}^{3}}} + U \]
      3. associate-*l*71.4%

        \[\leadsto \sqrt[3]{{\color{blue}{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \left(\frac{K}{2}\right)\right)\right)}}^{3}} + U \]
      4. div-inv71.4%

        \[\leadsto \sqrt[3]{{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \color{blue}{\left(K \cdot \frac{1}{2}\right)}\right)\right)}^{3}} + U \]
      5. metadata-eval71.4%

        \[\leadsto \sqrt[3]{{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \left(K \cdot \color{blue}{0.5}\right)\right)\right)}^{3}} + U \]
    7. Applied egg-rr71.4%

      \[\leadsto \color{blue}{\sqrt[3]{{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \left(K \cdot 0.5\right)\right)\right)}^{3}}} + U \]
    8. Taylor expanded in U around inf 65.5%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    9. Step-by-step derivation
      1. associate-/l*68.0%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    10. Simplified68.0%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]

    if -0.050000000000000003 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 87.6%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 87.6%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification81.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.05:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 98.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ t_1 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;\ell \leq -7.7:\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(27 - t\_0\right)\right)\\ \mathbf{elif}\;\ell \leq 4.15 \cdot 10^{-10} \lor \neg \left(\ell \leq 2.7 \cdot 10^{+102}\right):\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{\ell} - t\_0\right) \cdot J + U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (exp (- l))) (t_1 (cos (/ K 2.0))))
   (if (<= l -7.7)
     (+ U (* t_1 (* J (- 27.0 t_0))))
     (if (or (<= l 4.15e-10) (not (<= l 2.7e+102)))
       (+ U (* t_1 (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0)))))))
       (+ (* (- (exp l) t_0) J) U)))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(-l);
	double t_1 = cos((K / 2.0));
	double tmp;
	if (l <= -7.7) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if ((l <= 4.15e-10) || !(l <= 2.7e+102)) {
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * pow(l, 2.0))))));
	} else {
		tmp = ((exp(l) - t_0) * J) + U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp(-l)
    t_1 = cos((k / 2.0d0))
    if (l <= (-7.7d0)) then
        tmp = u + (t_1 * (j * (27.0d0 - t_0)))
    else if ((l <= 4.15d-10) .or. (.not. (l <= 2.7d+102))) then
        tmp = u + (t_1 * (j * (l * (2.0d0 + (0.3333333333333333d0 * (l ** 2.0d0))))))
    else
        tmp = ((exp(l) - t_0) * j) + u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(-l);
	double t_1 = Math.cos((K / 2.0));
	double tmp;
	if (l <= -7.7) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if ((l <= 4.15e-10) || !(l <= 2.7e+102)) {
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0))))));
	} else {
		tmp = ((Math.exp(l) - t_0) * J) + U;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(-l)
	t_1 = math.cos((K / 2.0))
	tmp = 0
	if l <= -7.7:
		tmp = U + (t_1 * (J * (27.0 - t_0)))
	elif (l <= 4.15e-10) or not (l <= 2.7e+102):
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0))))))
	else:
		tmp = ((math.exp(l) - t_0) * J) + U
	return tmp
function code(J, l, K, U)
	t_0 = exp(Float64(-l))
	t_1 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (l <= -7.7)
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(27.0 - t_0))));
	elseif ((l <= 4.15e-10) || !(l <= 2.7e+102))
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0)))))));
	else
		tmp = Float64(Float64(Float64(exp(l) - t_0) * J) + U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(-l);
	t_1 = cos((K / 2.0));
	tmp = 0.0;
	if (l <= -7.7)
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	elseif ((l <= 4.15e-10) || ~((l <= 2.7e+102)))
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l ^ 2.0))))));
	else
		tmp = ((exp(l) - t_0) * J) + U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -7.7], N[(U + N[(t$95$1 * N[(J * N[(27.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, 4.15e-10], N[Not[LessEqual[l, 2.7e+102]], $MachinePrecision]], N[(U + N[(t$95$1 * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Exp[l], $MachinePrecision] - t$95$0), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
t_1 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;\ell \leq -7.7:\\
\;\;\;\;U + t\_1 \cdot \left(J \cdot \left(27 - t\_0\right)\right)\\

\mathbf{elif}\;\ell \leq 4.15 \cdot 10^{-10} \lor \neg \left(\ell \leq 2.7 \cdot 10^{+102}\right):\\
\;\;\;\;U + t\_1 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(e^{\ell} - t\_0\right) \cdot J + U\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -7.70000000000000018

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr100.0%

      \[\leadsto \left(J \cdot \left(\color{blue}{27} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]

    if -7.70000000000000018 < l < 4.1500000000000001e-10 or 2.7000000000000001e102 < l

    1. Initial program 80.1%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 99.5%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]

    if 4.1500000000000001e-10 < l < 2.7000000000000001e102

    1. Initial program 99.9%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 70.7%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification97.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7.7:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(27 - e^{-\ell}\right)\right)\\ \mathbf{elif}\;\ell \leq 4.15 \cdot 10^{-10} \lor \neg \left(\ell \leq 2.7 \cdot 10^{+102}\right):\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 81.4% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.05:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.05)
   (* U (+ 1.0 (* 2.0 (* J (/ (* l (cos (* K 0.5))) U)))))
   (+ 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 * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U))));
	} 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 * (1.0d0 + (2.0d0 * (j * ((l * cos((k * 0.5d0))) / u))))
    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 * (1.0 + (2.0 * (J * ((l * Math.cos((K * 0.5))) / U))));
	} 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 * (1.0 + (2.0 * (J * ((l * math.cos((K * 0.5))) / U))))
	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(1.0 + Float64(2.0 * Float64(J * Float64(Float64(l * cos(Float64(K * 0.5))) / U)))));
	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 * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U))));
	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[(1.0 + N[(2.0 * N[(J * N[(N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision]), $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 \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.050000000000000003

    1. Initial program 88.5%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 59.8%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative59.8%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*59.8%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified59.8%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Step-by-step derivation
      1. add-cbrt-cube71.4%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right)}} + U \]
      2. pow371.4%

        \[\leadsto \sqrt[3]{\color{blue}{{\left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right)}^{3}}} + U \]
      3. associate-*l*71.4%

        \[\leadsto \sqrt[3]{{\color{blue}{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \left(\frac{K}{2}\right)\right)\right)}}^{3}} + U \]
      4. div-inv71.4%

        \[\leadsto \sqrt[3]{{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \color{blue}{\left(K \cdot \frac{1}{2}\right)}\right)\right)}^{3}} + U \]
      5. metadata-eval71.4%

        \[\leadsto \sqrt[3]{{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \left(K \cdot \color{blue}{0.5}\right)\right)\right)}^{3}} + U \]
    7. Applied egg-rr71.4%

      \[\leadsto \color{blue}{\sqrt[3]{{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \left(K \cdot 0.5\right)\right)\right)}^{3}}} + U \]
    8. Taylor expanded in U around inf 65.5%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    9. Step-by-step derivation
      1. associate-/l*68.0%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    10. Simplified68.0%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]

    if -0.050000000000000003 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 87.6%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 88.5%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 84.6%

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification79.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.05:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 77.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.05:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(1 + -0.125 \cdot {K}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.05)
   (+ U (* (* J (* l 2.0)) (+ 1.0 (* -0.125 (pow K 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 * (l * 2.0)) * (1.0 + (-0.125 * pow(K, 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 * (l * 2.0d0)) * (1.0d0 + ((-0.125d0) * (k ** 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 * (l * 2.0)) * (1.0 + (-0.125 * Math.pow(K, 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 * (l * 2.0)) * (1.0 + (-0.125 * math.pow(K, 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 * Float64(l * 2.0)) * Float64(1.0 + Float64(-0.125 * (K ^ 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 * (l * 2.0)) * (1.0 + (-0.125 * (K ^ 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[(l * 2.0), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-0.125 * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $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 \left(\ell \cdot 2\right)\right) \cdot \left(1 + -0.125 \cdot {K}^{2}\right)\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.050000000000000003

    1. Initial program 88.5%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 59.8%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative59.8%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*59.8%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified59.8%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in K around 0 61.7%

      \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \color{blue}{\left(1 + -0.125 \cdot {K}^{2}\right)} + U \]

    if -0.050000000000000003 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 87.6%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 88.5%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 84.6%

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.05:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(1 + -0.125 \cdot {K}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 79.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t\_0 \leq -0.05:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= t_0 -0.05)
     (+ U (* t_0 (* J (* 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 t_0 = cos((K / 2.0));
	double tmp;
	if (t_0 <= -0.05) {
		tmp = U + (t_0 * (J * (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) :: t_0
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    if (t_0 <= (-0.05d0)) then
        tmp = u + (t_0 * (j * (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 t_0 = Math.cos((K / 2.0));
	double tmp;
	if (t_0 <= -0.05) {
		tmp = U + (t_0 * (J * (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):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if t_0 <= -0.05:
		tmp = U + (t_0 * (J * (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)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_0 <= -0.05)
		tmp = Float64(U + Float64(t_0 * Float64(J * 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)
	t_0 = cos((K / 2.0));
	tmp = 0.0;
	if (t_0 <= -0.05)
		tmp = U + (t_0 * (J * (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_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, -0.05], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $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}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t\_0 \leq -0.05:\\
\;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.050000000000000003

    1. Initial program 88.5%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 59.8%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative59.8%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*59.8%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified59.8%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]

    if -0.050000000000000003 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 87.6%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 88.5%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 84.6%

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.05:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 93.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ t_1 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;\ell \leq -7.7:\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(27 - t\_0\right)\right)\\ \mathbf{elif}\;\ell \leq 4.15 \cdot 10^{-10}:\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{\ell} - t\_0\right) \cdot J + U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (exp (- l))) (t_1 (cos (/ K 2.0))))
   (if (<= l -7.7)
     (+ U (* t_1 (* J (- 27.0 t_0))))
     (if (<= l 4.15e-10)
       (+ U (* t_1 (* J (* l 2.0))))
       (+ (* (- (exp l) t_0) J) U)))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(-l);
	double t_1 = cos((K / 2.0));
	double tmp;
	if (l <= -7.7) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if (l <= 4.15e-10) {
		tmp = U + (t_1 * (J * (l * 2.0)));
	} else {
		tmp = ((exp(l) - t_0) * J) + U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp(-l)
    t_1 = cos((k / 2.0d0))
    if (l <= (-7.7d0)) then
        tmp = u + (t_1 * (j * (27.0d0 - t_0)))
    else if (l <= 4.15d-10) then
        tmp = u + (t_1 * (j * (l * 2.0d0)))
    else
        tmp = ((exp(l) - t_0) * j) + u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(-l);
	double t_1 = Math.cos((K / 2.0));
	double tmp;
	if (l <= -7.7) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if (l <= 4.15e-10) {
		tmp = U + (t_1 * (J * (l * 2.0)));
	} else {
		tmp = ((Math.exp(l) - t_0) * J) + U;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(-l)
	t_1 = math.cos((K / 2.0))
	tmp = 0
	if l <= -7.7:
		tmp = U + (t_1 * (J * (27.0 - t_0)))
	elif l <= 4.15e-10:
		tmp = U + (t_1 * (J * (l * 2.0)))
	else:
		tmp = ((math.exp(l) - t_0) * J) + U
	return tmp
function code(J, l, K, U)
	t_0 = exp(Float64(-l))
	t_1 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (l <= -7.7)
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(27.0 - t_0))));
	elseif (l <= 4.15e-10)
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(l * 2.0))));
	else
		tmp = Float64(Float64(Float64(exp(l) - t_0) * J) + U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(-l);
	t_1 = cos((K / 2.0));
	tmp = 0.0;
	if (l <= -7.7)
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	elseif (l <= 4.15e-10)
		tmp = U + (t_1 * (J * (l * 2.0)));
	else
		tmp = ((exp(l) - t_0) * J) + U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -7.7], N[(U + N[(t$95$1 * N[(J * N[(27.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 4.15e-10], N[(U + N[(t$95$1 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Exp[l], $MachinePrecision] - t$95$0), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
t_1 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;\ell \leq -7.7:\\
\;\;\;\;U + t\_1 \cdot \left(J \cdot \left(27 - t\_0\right)\right)\\

\mathbf{elif}\;\ell \leq 4.15 \cdot 10^{-10}:\\
\;\;\;\;U + t\_1 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(e^{\ell} - t\_0\right) \cdot J + U\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -7.70000000000000018

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr100.0%

      \[\leadsto \left(J \cdot \left(\color{blue}{27} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]

    if -7.70000000000000018 < l < 4.1500000000000001e-10

    1. Initial program 74.1%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 99.3%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative99.3%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*99.3%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified99.3%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]

    if 4.1500000000000001e-10 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 68.3%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification92.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7.7:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(27 - e^{-\ell}\right)\right)\\ \mathbf{elif}\;\ell \leq 4.15 \cdot 10^{-10}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 64.7% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 1000000000:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (/ K 2.0) 1000000000.0)
   (* U (+ 1.0 (* 2.0 (* J (/ l U)))))
   (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 1000000000.0) {
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	} else {
		tmp = U + (cos((K / 2.0)) * (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 ((k / 2.0d0) <= 1000000000.0d0) then
        tmp = u * (1.0d0 + (2.0d0 * (j * (l / u))))
    else
        tmp = u + (cos((k / 2.0d0)) * (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 ((K / 2.0) <= 1000000000.0) {
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	} else {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (K / 2.0) <= 1000000000.0:
		tmp = U * (1.0 + (2.0 * (J * (l / U))))
	else:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * 2.0)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (Float64(K / 2.0) <= 1000000000.0)
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l / U)))));
	else
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((K / 2.0) <= 1000000000.0)
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	else
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[N[(K / 2.0), $MachinePrecision], 1000000000.0], N[(U * N[(1.0 + N[(2.0 * N[(J * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 1000000000:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 K #s(literal 2 binary64)) < 1e9

    1. Initial program 87.4%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 64.5%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative64.5%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*64.5%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified64.5%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in K around 0 55.6%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
    7. Taylor expanded in U around inf 59.4%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \ell}{U}\right)} \]
    8. Step-by-step derivation
      1. +-commutative59.4%

        \[\leadsto U \cdot \color{blue}{\left(2 \cdot \frac{J \cdot \ell}{U} + 1\right)} \]
      2. associate-/l*63.1%

        \[\leadsto U \cdot \left(2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)} + 1\right) \]
    9. Simplified63.1%

      \[\leadsto \color{blue}{U \cdot \left(2 \cdot \left(J \cdot \frac{\ell}{U}\right) + 1\right)} \]

    if 1e9 < (/.f64 K #s(literal 2 binary64))

    1. Initial program 88.9%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 57.5%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative57.5%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*57.5%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified57.5%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 1000000000:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 64.7% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;K \leq 2100000000000:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= K 2100000000000.0)
   (* U (+ 1.0 (* 2.0 (* J (/ l U)))))
   (+ U (* J (* 2.0 (* l (cos (* K 0.5))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (K <= 2100000000000.0) {
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	} else {
		tmp = U + (J * (2.0 * (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 (k <= 2100000000000.0d0) then
        tmp = u * (1.0d0 + (2.0d0 * (j * (l / u))))
    else
        tmp = u + (j * (2.0d0 * (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 (K <= 2100000000000.0) {
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	} else {
		tmp = U + (J * (2.0 * (l * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if K <= 2100000000000.0:
		tmp = U * (1.0 + (2.0 * (J * (l / U))))
	else:
		tmp = U + (J * (2.0 * (l * math.cos((K * 0.5)))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (K <= 2100000000000.0)
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l / U)))));
	else
		tmp = Float64(U + Float64(J * Float64(2.0 * Float64(l * cos(Float64(K * 0.5))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (K <= 2100000000000.0)
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	else
		tmp = U + (J * (2.0 * (l * cos((K * 0.5)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[K, 2100000000000.0], N[(U * N[(1.0 + N[(2.0 * N[(J * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(2.0 * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;K \leq 2100000000000:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 2.1e12

    1. Initial program 87.4%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 64.5%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative64.5%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*64.5%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified64.5%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in K around 0 55.6%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
    7. Taylor expanded in U around inf 59.4%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \ell}{U}\right)} \]
    8. Step-by-step derivation
      1. +-commutative59.4%

        \[\leadsto U \cdot \color{blue}{\left(2 \cdot \frac{J \cdot \ell}{U} + 1\right)} \]
      2. associate-/l*63.1%

        \[\leadsto U \cdot \left(2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)} + 1\right) \]
    9. Simplified63.1%

      \[\leadsto \color{blue}{U \cdot \left(2 \cdot \left(J \cdot \frac{\ell}{U}\right) + 1\right)} \]

    if 2.1e12 < K

    1. Initial program 88.9%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 57.5%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative57.5%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot 2} + U \]
      2. associate-*l*57.5%

        \[\leadsto \color{blue}{J \cdot \left(\left(\ell \cdot \cos \left(0.5 \cdot K\right)\right) \cdot 2\right)} + U \]
      3. *-commutative57.5%

        \[\leadsto J \cdot \color{blue}{\left(2 \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
      4. *-commutative57.5%

        \[\leadsto J \cdot \left(2 \cdot \color{blue}{\left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)}\right) + U \]
    5. Simplified57.5%

      \[\leadsto \color{blue}{J \cdot \left(2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 2100000000000:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 61.6% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;J \leq 4 \cdot 10^{+202}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(\ell \cdot J\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= J 4e+202)
   (* U (+ 1.0 (* 2.0 (* J (/ l U)))))
   (* 2.0 (* (cos (* K 0.5)) (* l J)))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (J <= 4e+202) {
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	} else {
		tmp = 2.0 * (cos((K * 0.5)) * (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 (j <= 4d+202) then
        tmp = u * (1.0d0 + (2.0d0 * (j * (l / u))))
    else
        tmp = 2.0d0 * (cos((k * 0.5d0)) * (l * j))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (J <= 4e+202) {
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	} else {
		tmp = 2.0 * (Math.cos((K * 0.5)) * (l * J));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if J <= 4e+202:
		tmp = U * (1.0 + (2.0 * (J * (l / U))))
	else:
		tmp = 2.0 * (math.cos((K * 0.5)) * (l * J))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (J <= 4e+202)
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l / U)))));
	else
		tmp = Float64(2.0 * Float64(cos(Float64(K * 0.5)) * Float64(l * J)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (J <= 4e+202)
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	else
		tmp = 2.0 * (cos((K * 0.5)) * (l * J));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[J, 4e+202], N[(U * N[(1.0 + N[(2.0 * N[(J * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;J \leq 4 \cdot 10^{+202}:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(\ell \cdot J\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < 3.9999999999999996e202

    1. Initial program 90.7%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 60.2%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative60.2%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*60.2%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified60.2%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in K around 0 52.3%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
    7. Taylor expanded in U around inf 55.0%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \ell}{U}\right)} \]
    8. Step-by-step derivation
      1. +-commutative55.0%

        \[\leadsto U \cdot \color{blue}{\left(2 \cdot \frac{J \cdot \ell}{U} + 1\right)} \]
      2. associate-/l*58.8%

        \[\leadsto U \cdot \left(2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)} + 1\right) \]
    9. Simplified58.8%

      \[\leadsto \color{blue}{U \cdot \left(2 \cdot \left(J \cdot \frac{\ell}{U}\right) + 1\right)} \]

    if 3.9999999999999996e202 < J

    1. Initial program 62.3%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 83.1%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative83.1%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*83.1%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified83.1%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Step-by-step derivation
      1. add-cbrt-cube67.2%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right)}} + U \]
      2. pow367.2%

        \[\leadsto \sqrt[3]{\color{blue}{{\left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right)}^{3}}} + U \]
      3. associate-*l*67.1%

        \[\leadsto \sqrt[3]{{\color{blue}{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \left(\frac{K}{2}\right)\right)\right)}}^{3}} + U \]
      4. div-inv67.1%

        \[\leadsto \sqrt[3]{{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \color{blue}{\left(K \cdot \frac{1}{2}\right)}\right)\right)}^{3}} + U \]
      5. metadata-eval67.1%

        \[\leadsto \sqrt[3]{{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \left(K \cdot \color{blue}{0.5}\right)\right)\right)}^{3}} + U \]
    7. Applied egg-rr67.1%

      \[\leadsto \color{blue}{\sqrt[3]{{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \left(K \cdot 0.5\right)\right)\right)}^{3}}} + U \]
    8. Taylor expanded in U around inf 86.0%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    9. Step-by-step derivation
      1. associate-/l*86.1%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    10. Simplified86.1%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
    11. Taylor expanded in U around 0 75.5%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} \]
    12. Step-by-step derivation
      1. associate-*r*75.7%

        \[\leadsto 2 \cdot \color{blue}{\left(\left(J \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)\right)} \]
      2. *-commutative75.7%

        \[\leadsto 2 \cdot \color{blue}{\left(\cos \left(0.5 \cdot K\right) \cdot \left(J \cdot \ell\right)\right)} \]
    13. Simplified75.7%

      \[\leadsto \color{blue}{2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(J \cdot \ell\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification60.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 4 \cdot 10^{+202}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(\ell \cdot J\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 47.0% accurate, 20.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -5.4 \cdot 10^{+42} \lor \neg \left(\ell \leq 0.48\right):\\ \;\;\;\;\ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -5.4e+42) (not (<= l 0.48))) (* l (* J 2.0)) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -5.4e+42) || !(l <= 0.48)) {
		tmp = l * (J * 2.0);
	} else {
		tmp = U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if ((l <= (-5.4d+42)) .or. (.not. (l <= 0.48d0))) then
        tmp = l * (j * 2.0d0)
    else
        tmp = u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -5.4e+42) || !(l <= 0.48)) {
		tmp = l * (J * 2.0);
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -5.4e+42) or not (l <= 0.48):
		tmp = l * (J * 2.0)
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -5.4e+42) || !(l <= 0.48))
		tmp = Float64(l * Float64(J * 2.0));
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -5.4e+42) || ~((l <= 0.48)))
		tmp = l * (J * 2.0);
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -5.4e+42], N[Not[LessEqual[l, 0.48]], $MachinePrecision]], N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision], U]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.4 \cdot 10^{+42} \lor \neg \left(\ell \leq 0.48\right):\\
\;\;\;\;\ell \cdot \left(J \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;U\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.4000000000000001e42 or 0.47999999999999998 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 31.3%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative31.3%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*31.3%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified31.3%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in K around 0 20.8%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
    7. Taylor expanded in J around inf 20.8%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} \]
    8. Step-by-step derivation
      1. associate-*r*20.8%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} \]
      2. *-commutative20.8%

        \[\leadsto \color{blue}{\ell \cdot \left(2 \cdot J\right)} \]
    9. Simplified20.8%

      \[\leadsto \color{blue}{\ell \cdot \left(2 \cdot J\right)} \]

    if -5.4000000000000001e42 < l < 0.47999999999999998

    1. Initial program 76.8%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr46.1%

      \[\leadsto \color{blue}{-4} + U \]
    4. Taylor expanded in U around inf 67.3%

      \[\leadsto \color{blue}{U} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification45.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.4 \cdot 10^{+42} \lor \neg \left(\ell \leq 0.48\right):\\ \;\;\;\;\ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 54.5% accurate, 26.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;K \leq 22000000000000:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot -6\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= K 22000000000000.0) (+ U (* 2.0 (* l J))) (+ U (* l (* J -6.0)))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (K <= 22000000000000.0) {
		tmp = U + (2.0 * (l * J));
	} else {
		tmp = U + (l * (J * -6.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 <= 22000000000000.0d0) then
        tmp = u + (2.0d0 * (l * j))
    else
        tmp = u + (l * (j * (-6.0d0)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (K <= 22000000000000.0) {
		tmp = U + (2.0 * (l * J));
	} else {
		tmp = U + (l * (J * -6.0));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if K <= 22000000000000.0:
		tmp = U + (2.0 * (l * J))
	else:
		tmp = U + (l * (J * -6.0))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (K <= 22000000000000.0)
		tmp = Float64(U + Float64(2.0 * Float64(l * J)));
	else
		tmp = Float64(U + Float64(l * Float64(J * -6.0)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (K <= 22000000000000.0)
		tmp = U + (2.0 * (l * J));
	else
		tmp = U + (l * (J * -6.0));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[K, 22000000000000.0], N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(l * N[(J * -6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;K \leq 22000000000000:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\

\mathbf{else}:\\
\;\;\;\;U + \ell \cdot \left(J \cdot -6\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 2.2e13

    1. Initial program 87.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 64.7%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative64.7%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*64.7%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified64.7%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in K around 0 55.4%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]

    if 2.2e13 < K

    1. Initial program 90.2%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 57.0%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative57.0%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*57.0%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified57.0%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Applied egg-rr41.5%

      \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \color{blue}{\left(\cos \left(-4 \cdot K\right) \cdot -3\right)} + U \]
    7. Taylor expanded in K around 0 41.7%

      \[\leadsto \color{blue}{-6 \cdot \left(J \cdot \ell\right)} + U \]
    8. Step-by-step derivation
      1. associate-*r*41.7%

        \[\leadsto \color{blue}{\left(-6 \cdot J\right) \cdot \ell} + U \]
      2. *-commutative41.7%

        \[\leadsto \color{blue}{\ell \cdot \left(-6 \cdot J\right)} + U \]
      3. *-commutative41.7%

        \[\leadsto \ell \cdot \color{blue}{\left(J \cdot -6\right)} + U \]
    9. Simplified41.7%

      \[\leadsto \color{blue}{\ell \cdot \left(J \cdot -6\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification51.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 22000000000000:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot -6\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 61.0% accurate, 28.4× speedup?

\[\begin{array}{l} \\ U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right) \end{array} \]
(FPCore (J l K U) :precision binary64 (* U (+ 1.0 (* 2.0 (* J (/ l U))))))
double code(double J, double l, double K, double U) {
	return U * (1.0 + (2.0 * (J * (l / 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 * (1.0d0 + (2.0d0 * (j * (l / u))))
end function
public static double code(double J, double l, double K, double U) {
	return U * (1.0 + (2.0 * (J * (l / U))));
}
def code(J, l, K, U):
	return U * (1.0 + (2.0 * (J * (l / U))))
function code(J, l, K, U)
	return Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l / U)))))
end
function tmp = code(J, l, K, U)
	tmp = U * (1.0 + (2.0 * (J * (l / U))));
end
code[J_, l_, K_, U_] := N[(U * N[(1.0 + N[(2.0 * N[(J * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)
\end{array}
Derivation
  1. Initial program 87.9%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in l around 0 62.5%

    \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  4. Step-by-step derivation
    1. *-commutative62.5%

      \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. associate-*l*62.5%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  5. Simplified62.5%

    \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  6. Taylor expanded in K around 0 51.1%

    \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
  7. Taylor expanded in U around inf 53.8%

    \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \ell}{U}\right)} \]
  8. Step-by-step derivation
    1. +-commutative53.8%

      \[\leadsto U \cdot \color{blue}{\left(2 \cdot \frac{J \cdot \ell}{U} + 1\right)} \]
    2. associate-/l*57.2%

      \[\leadsto U \cdot \left(2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)} + 1\right) \]
  9. Simplified57.2%

    \[\leadsto \color{blue}{U \cdot \left(2 \cdot \left(J \cdot \frac{\ell}{U}\right) + 1\right)} \]
  10. Final simplification57.2%

    \[\leadsto U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right) \]
  11. Add Preprocessing

Alternative 14: 58.2% accurate, 28.4× speedup?

\[\begin{array}{l} \\ U \cdot \left(1 + 2 \cdot \frac{\ell \cdot J}{U}\right) \end{array} \]
(FPCore (J l K U) :precision binary64 (* U (+ 1.0 (* 2.0 (/ (* l J) U)))))
double code(double J, double l, double K, double U) {
	return U * (1.0 + (2.0 * ((l * J) / 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 * (1.0d0 + (2.0d0 * ((l * j) / u)))
end function
public static double code(double J, double l, double K, double U) {
	return U * (1.0 + (2.0 * ((l * J) / U)));
}
def code(J, l, K, U):
	return U * (1.0 + (2.0 * ((l * J) / U)))
function code(J, l, K, U)
	return Float64(U * Float64(1.0 + Float64(2.0 * Float64(Float64(l * J) / U))))
end
function tmp = code(J, l, K, U)
	tmp = U * (1.0 + (2.0 * ((l * J) / U)));
end
code[J_, l_, K_, U_] := N[(U * N[(1.0 + N[(2.0 * N[(N[(l * J), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U \cdot \left(1 + 2 \cdot \frac{\ell \cdot J}{U}\right)
\end{array}
Derivation
  1. Initial program 87.9%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in l around 0 62.5%

    \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  4. Step-by-step derivation
    1. *-commutative62.5%

      \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. associate-*l*62.5%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  5. Simplified62.5%

    \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  6. Step-by-step derivation
    1. add-cbrt-cube71.6%

      \[\leadsto \color{blue}{\sqrt[3]{\left(\left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right)}} + U \]
    2. pow371.6%

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\right)}^{3}}} + U \]
    3. associate-*l*71.6%

      \[\leadsto \sqrt[3]{{\color{blue}{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \left(\frac{K}{2}\right)\right)\right)}}^{3}} + U \]
    4. div-inv71.6%

      \[\leadsto \sqrt[3]{{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \color{blue}{\left(K \cdot \frac{1}{2}\right)}\right)\right)}^{3}} + U \]
    5. metadata-eval71.6%

      \[\leadsto \sqrt[3]{{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \left(K \cdot \color{blue}{0.5}\right)\right)\right)}^{3}} + U \]
  7. Applied egg-rr71.6%

    \[\leadsto \color{blue}{\sqrt[3]{{\left(J \cdot \left(\left(\ell \cdot 2\right) \cdot \cos \left(K \cdot 0.5\right)\right)\right)}^{3}}} + U \]
  8. Taylor expanded in U around inf 67.0%

    \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
  9. Step-by-step derivation
    1. associate-/l*71.2%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
  10. Simplified71.2%

    \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
  11. Taylor expanded in K around 0 53.8%

    \[\leadsto U \cdot \left(1 + \color{blue}{2 \cdot \frac{J \cdot \ell}{U}}\right) \]
  12. Final simplification53.8%

    \[\leadsto U \cdot \left(1 + 2 \cdot \frac{\ell \cdot J}{U}\right) \]
  13. Add Preprocessing

Alternative 15: 54.6% accurate, 44.6× speedup?

\[\begin{array}{l} \\ U + 2 \cdot \left(\ell \cdot J\right) \end{array} \]
(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}
Derivation
  1. Initial program 87.9%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in l around 0 62.5%

    \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  4. Step-by-step derivation
    1. *-commutative62.5%

      \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. associate-*l*62.5%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  5. Simplified62.5%

    \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  6. Taylor expanded in K around 0 51.1%

    \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
  7. Final simplification51.1%

    \[\leadsto U + 2 \cdot \left(\ell \cdot J\right) \]
  8. Add Preprocessing

Alternative 16: 37.5% accurate, 312.0× speedup?

\[\begin{array}{l} \\ U \end{array} \]
(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}
Derivation
  1. Initial program 87.9%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Applied egg-rr25.1%

    \[\leadsto \color{blue}{-4} + U \]
  4. Taylor expanded in U around inf 36.2%

    \[\leadsto \color{blue}{U} \]
  5. Add Preprocessing

Alternative 17: 2.7% accurate, 312.0× speedup?

\[\begin{array}{l} \\ -4 \end{array} \]
(FPCore (J l K U) :precision binary64 -4.0)
double code(double J, double l, double K, double U) {
	return -4.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 = -4.0d0
end function
public static double code(double J, double l, double K, double U) {
	return -4.0;
}
def code(J, l, K, U):
	return -4.0
function code(J, l, K, U)
	return -4.0
end
function tmp = code(J, l, K, U)
	tmp = -4.0;
end
code[J_, l_, K_, U_] := -4.0
\begin{array}{l}

\\
-4
\end{array}
Derivation
  1. Initial program 87.9%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Applied egg-rr25.1%

    \[\leadsto \color{blue}{-4} + U \]
  4. Taylor expanded in U around 0 2.7%

    \[\leadsto \color{blue}{-4} \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2024172 
(FPCore (J l K U)
  :name "Maksimov and Kolovsky, Equation (4)"
  :precision binary64
  (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))