Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.4% → 99.8%
Time: 10.6s
Alternatives: 16
Speedup: 2.7×

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 16 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: 86.4% 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.8% 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 -0.1 \lor \neg \left(t\_1 \leq 2 \cdot 10^{-12}\right):\\ \;\;\;\;\left(t\_1 \cdot J\right) \cdot t\_0 + U\\ \mathbf{else}:\\ \;\;\;\;U + t\_0 \cdot \left(\ell \cdot \left(J \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 -0.1) (not (<= t_1 2e-12)))
     (+ (* (* t_1 J) t_0) U)
     (+ U (* t_0 (* l (* J 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 <= -0.1) || !(t_1 <= 2e-12)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (l * (J * 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 <= (-0.1d0)) .or. (.not. (t_1 <= 2d-12))) then
        tmp = ((t_1 * j) * t_0) + u
    else
        tmp = u + (t_0 * (l * (j * 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 <= -0.1) || !(t_1 <= 2e-12)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (l * (J * 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 <= -0.1) or not (t_1 <= 2e-12):
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (t_0 * (l * (J * 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 <= -0.1) || !(t_1 <= 2e-12))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(l * Float64(J * 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 <= -0.1) || ~((t_1 <= 2e-12)))
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (t_0 * (l * (J * 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, -0.1], N[Not[LessEqual[t$95$1, 2e-12]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(l * N[(J * 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 -0.1 \lor \neg \left(t\_1 \leq 2 \cdot 10^{-12}\right):\\
\;\;\;\;\left(t\_1 \cdot J\right) \cdot t\_0 + U\\

\mathbf{else}:\\
\;\;\;\;U + t\_0 \cdot \left(\ell \cdot \left(J \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))) < -0.10000000000000001 or 1.99999999999999996e-12 < (-.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 -0.10000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1.99999999999999996e-12

    1. Initial program 81.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 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. associate-*r*100.0%

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

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\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 -0.1 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 2 \cdot 10^{-12}\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(\ell \cdot \left(J \cdot 2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 78.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t\_0 \leq -0.67:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\ \mathbf{elif}\;t\_0 \leq -0.055:\\ \;\;\;\;U + \left(\ell \cdot {K}^{2}\right) \cdot \left(J \cdot -0.25\right)\\ \mathbf{elif}\;t\_0 \leq 0.5:\\ \;\;\;\;U + t\_0 \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= t_0 -0.67)
     (* U (+ 1.0 (* 2.0 (* J (/ (* l (cos (* K 0.5))) U)))))
     (if (<= t_0 -0.055)
       (+ U (* (* l (pow K 2.0)) (* J -0.25)))
       (if (<= t_0 0.5)
         (+ U (* t_0 (* l (* J 2.0))))
         (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l)))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (t_0 <= -0.67) {
		tmp = U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U))));
	} else if (t_0 <= -0.055) {
		tmp = U + ((l * pow(K, 2.0)) * (J * -0.25));
	} else if (t_0 <= 0.5) {
		tmp = U + (t_0 * (l * (J * 2.0)));
	} else {
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    if (t_0 <= (-0.67d0)) then
        tmp = u * (1.0d0 + (2.0d0 * (j * ((l * cos((k * 0.5d0))) / u))))
    else if (t_0 <= (-0.055d0)) then
        tmp = u + ((l * (k ** 2.0d0)) * (j * (-0.25d0)))
    else if (t_0 <= 0.5d0) then
        tmp = u + (t_0 * (l * (j * 2.0d0)))
    else
        tmp = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l)))))
    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.67) {
		tmp = U * (1.0 + (2.0 * (J * ((l * Math.cos((K * 0.5))) / U))));
	} else if (t_0 <= -0.055) {
		tmp = U + ((l * Math.pow(K, 2.0)) * (J * -0.25));
	} else if (t_0 <= 0.5) {
		tmp = U + (t_0 * (l * (J * 2.0)));
	} else {
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if t_0 <= -0.67:
		tmp = U * (1.0 + (2.0 * (J * ((l * math.cos((K * 0.5))) / U))))
	elif t_0 <= -0.055:
		tmp = U + ((l * math.pow(K, 2.0)) * (J * -0.25))
	elif t_0 <= 0.5:
		tmp = U + (t_0 * (l * (J * 2.0)))
	else:
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_0 <= -0.67)
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(Float64(l * cos(Float64(K * 0.5))) / U)))));
	elseif (t_0 <= -0.055)
		tmp = Float64(U + Float64(Float64(l * (K ^ 2.0)) * Float64(J * -0.25)));
	elseif (t_0 <= 0.5)
		tmp = Float64(U + Float64(t_0 * Float64(l * Float64(J * 2.0))));
	else
		tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l))))));
	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.67)
		tmp = U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U))));
	elseif (t_0 <= -0.055)
		tmp = U + ((l * (K ^ 2.0)) * (J * -0.25));
	elseif (t_0 <= 0.5)
		tmp = U + (t_0 * (l * (J * 2.0)));
	else
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
	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.67], 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], If[LessEqual[t$95$0, -0.055], N[(U + N[(N[(l * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision] * N[(J * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.5], N[(U + N[(t$95$0 * N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $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.67:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\

\mathbf{elif}\;t\_0 \leq -0.055:\\
\;\;\;\;U + \left(\ell \cdot {K}^{2}\right) \cdot \left(J \cdot -0.25\right)\\

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

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


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

    1. Initial program 90.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 63.9%

      \[\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. associate-*r*63.9%

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

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

      \[\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)} \]
    7. Step-by-step derivation
      1. associate-/l*88.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) \]
    8. Simplified88.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)} \]

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

    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 48.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. associate-*r*48.3%

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

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

      \[\leadsto \left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \color{blue}{\left(1 + -0.125 \cdot {K}^{2}\right)} + U \]
    7. Taylor expanded in K around inf 77.6%

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

        \[\leadsto \color{blue}{\left(-0.25 \cdot J\right) \cdot \left({K}^{2} \cdot \ell\right)} + U \]
      2. *-commutative77.6%

        \[\leadsto \color{blue}{\left({K}^{2} \cdot \ell\right) \cdot \left(-0.25 \cdot J\right)} + U \]
      3. *-commutative77.6%

        \[\leadsto \color{blue}{\left(\ell \cdot {K}^{2}\right)} \cdot \left(-0.25 \cdot J\right) + U \]
      4. *-commutative77.6%

        \[\leadsto \left(\ell \cdot {K}^{2}\right) \cdot \color{blue}{\left(J \cdot -0.25\right)} + U \]
    9. Simplified77.6%

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

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

    1. Initial program 69.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 95.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. associate-*r*95.7%

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

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

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

    1. Initial program 92.8%

      \[\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 90.3%

      \[\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. Step-by-step derivation
      1. unpow290.3%

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

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

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

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

Alternative 3: 76.3% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;t\_0 \leq -0.055:\\
\;\;\;\;U + \left(\ell \cdot {K}^{2}\right) \cdot \left(J \cdot -0.25\right)\\

\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;t\_1\\

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


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

    1. Initial program 73.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 90.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. associate-*r*90.8%

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

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

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

    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 47.4%

      \[\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. associate-*r*47.4%

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

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

      \[\leadsto \left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \color{blue}{\left(1 + -0.125 \cdot {K}^{2}\right)} + U \]
    7. Taylor expanded in K around inf 67.9%

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

        \[\leadsto \color{blue}{\left(-0.25 \cdot J\right) \cdot \left({K}^{2} \cdot \ell\right)} + U \]
      2. *-commutative67.9%

        \[\leadsto \color{blue}{\left({K}^{2} \cdot \ell\right) \cdot \left(-0.25 \cdot J\right)} + U \]
      3. *-commutative67.9%

        \[\leadsto \color{blue}{\left(\ell \cdot {K}^{2}\right)} \cdot \left(-0.25 \cdot J\right) + U \]
      4. *-commutative67.9%

        \[\leadsto \left(\ell \cdot {K}^{2}\right) \cdot \color{blue}{\left(J \cdot -0.25\right)} + U \]
    9. Simplified67.9%

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

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

    1. Initial program 92.8%

      \[\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 90.3%

      \[\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. Step-by-step derivation
      1. unpow290.3%

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

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

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

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

Alternative 4: 76.3% accurate, 0.7× speedup?

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

\mathbf{elif}\;t\_0 \leq -0.055:\\
\;\;\;\;U + \left(\ell \cdot {K}^{2}\right) \cdot \left(J \cdot -0.25\right)\\

\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;U + \ell \cdot \left(\left(J \cdot 2\right) \cdot \cos \left(K \cdot -0.5\right)\right)\\

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


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

    1. Initial program 80.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 82.9%

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

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

    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 47.4%

      \[\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. associate-*r*47.4%

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

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

      \[\leadsto \left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \color{blue}{\left(1 + -0.125 \cdot {K}^{2}\right)} + U \]
    7. Taylor expanded in K around inf 67.9%

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

        \[\leadsto \color{blue}{\left(-0.25 \cdot J\right) \cdot \left({K}^{2} \cdot \ell\right)} + U \]
      2. *-commutative67.9%

        \[\leadsto \color{blue}{\left({K}^{2} \cdot \ell\right) \cdot \left(-0.25 \cdot J\right)} + U \]
      3. *-commutative67.9%

        \[\leadsto \color{blue}{\left(\ell \cdot {K}^{2}\right)} \cdot \left(-0.25 \cdot J\right) + U \]
      4. *-commutative67.9%

        \[\leadsto \left(\ell \cdot {K}^{2}\right) \cdot \color{blue}{\left(J \cdot -0.25\right)} + U \]
    9. Simplified67.9%

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

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

    1. Initial program 69.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 95.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. associate-*r*95.7%

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

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

        \[\leadsto \color{blue}{{\left(\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(\frac{K}{2}\right)\right)}^{1}} + U \]
      2. *-commutative95.7%

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

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

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

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

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

      \[\leadsto \color{blue}{{\left(\ell \cdot \left(\left(J \cdot 2\right) \cdot \cos \left(K \cdot 0.5\right)\right)\right)}^{1}} + U \]
    8. Step-by-step derivation
      1. unpow195.7%

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

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

        \[\leadsto \ell \cdot \left(\cos \left(K \cdot \color{blue}{\left(--0.5\right)}\right) \cdot \left(J \cdot 2\right)\right) + U \]
      4. distribute-rgt-neg-in95.7%

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

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

        \[\leadsto \ell \cdot \left(\cos \left(K \cdot -0.5\right) \cdot \color{blue}{\left(2 \cdot J\right)}\right) + U \]
    9. Simplified95.7%

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

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

    1. Initial program 92.8%

      \[\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 90.3%

      \[\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. Step-by-step derivation
      1. unpow290.3%

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

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

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

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

Alternative 5: 76.3% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;t\_0 \leq -0.055:\\
\;\;\;\;U + \left(\ell \cdot {K}^{2}\right) \cdot \left(J \cdot -0.25\right)\\

\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;t\_1\\

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


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

    1. Initial program 73.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 90.7%

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

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

    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 47.4%

      \[\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. associate-*r*47.4%

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

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

      \[\leadsto \left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \color{blue}{\left(1 + -0.125 \cdot {K}^{2}\right)} + U \]
    7. Taylor expanded in K around inf 67.9%

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

        \[\leadsto \color{blue}{\left(-0.25 \cdot J\right) \cdot \left({K}^{2} \cdot \ell\right)} + U \]
      2. *-commutative67.9%

        \[\leadsto \color{blue}{\left({K}^{2} \cdot \ell\right) \cdot \left(-0.25 \cdot J\right)} + U \]
      3. *-commutative67.9%

        \[\leadsto \color{blue}{\left(\ell \cdot {K}^{2}\right)} \cdot \left(-0.25 \cdot J\right) + U \]
      4. *-commutative67.9%

        \[\leadsto \left(\ell \cdot {K}^{2}\right) \cdot \color{blue}{\left(J \cdot -0.25\right)} + U \]
    9. Simplified67.9%

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

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

    1. Initial program 92.8%

      \[\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 90.3%

      \[\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. Step-by-step derivation
      1. unpow290.3%

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

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

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

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

Alternative 6: 97.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 -4:\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(27 - t\_0\right)\right)\\ \mathbf{elif}\;\ell \leq 2 \cdot 10^{-10}:\\ \;\;\;\;U + t\_1 \cdot \left(\ell \cdot \left(J \cdot 2 + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 10^{+68}:\\ \;\;\;\;\left(e^{\ell} - t\_0\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (exp (- l))) (t_1 (cos (/ K 2.0))))
   (if (<= l -4.0)
     (+ U (* t_1 (* J (- 27.0 t_0))))
     (if (<= l 2e-10)
       (+
        U
        (* t_1 (* l (+ (* J 2.0) (* 0.3333333333333333 (* J (pow l 2.0)))))))
       (if (<= l 1e+68)
         (+ (* (- (exp l) t_0) J) U)
         (+ U (* t_1 (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l))))))))))))
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 <= -4.0) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if (l <= 2e-10) {
		tmp = U + (t_1 * (l * ((J * 2.0) + (0.3333333333333333 * (J * pow(l, 2.0))))));
	} else if (l <= 1e+68) {
		tmp = ((exp(l) - t_0) * J) + U;
	} else {
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp(-l)
    t_1 = cos((k / 2.0d0))
    if (l <= (-4.0d0)) then
        tmp = u + (t_1 * (j * (27.0d0 - t_0)))
    else if (l <= 2d-10) then
        tmp = u + (t_1 * (l * ((j * 2.0d0) + (0.3333333333333333d0 * (j * (l ** 2.0d0))))))
    else if (l <= 1d+68) then
        tmp = ((exp(l) - t_0) * j) + u
    else
        tmp = u + (t_1 * (j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l))))))
    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 <= -4.0) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if (l <= 2e-10) {
		tmp = U + (t_1 * (l * ((J * 2.0) + (0.3333333333333333 * (J * Math.pow(l, 2.0))))));
	} else if (l <= 1e+68) {
		tmp = ((Math.exp(l) - t_0) * J) + U;
	} else {
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(-l)
	t_1 = math.cos((K / 2.0))
	tmp = 0
	if l <= -4.0:
		tmp = U + (t_1 * (J * (27.0 - t_0)))
	elif l <= 2e-10:
		tmp = U + (t_1 * (l * ((J * 2.0) + (0.3333333333333333 * (J * math.pow(l, 2.0))))))
	elif l <= 1e+68:
		tmp = ((math.exp(l) - t_0) * J) + U
	else:
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))))
	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 <= -4.0)
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(27.0 - t_0))));
	elseif (l <= 2e-10)
		tmp = Float64(U + Float64(t_1 * Float64(l * Float64(Float64(J * 2.0) + Float64(0.3333333333333333 * Float64(J * (l ^ 2.0)))))));
	elseif (l <= 1e+68)
		tmp = Float64(Float64(Float64(exp(l) - t_0) * J) + U);
	else
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))));
	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 <= -4.0)
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	elseif (l <= 2e-10)
		tmp = U + (t_1 * (l * ((J * 2.0) + (0.3333333333333333 * (J * (l ^ 2.0))))));
	elseif (l <= 1e+68)
		tmp = ((exp(l) - t_0) * J) + U;
	else
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	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, -4.0], N[(U + N[(t$95$1 * N[(J * N[(27.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2e-10], N[(U + N[(t$95$1 * N[(l * N[(N[(J * 2.0), $MachinePrecision] + N[(0.3333333333333333 * N[(J * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1e+68], N[(N[(N[(N[Exp[l], $MachinePrecision] - t$95$0), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$1 * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

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

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


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

    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 -4 < l < 2.00000000000000007e-10

    1. Initial program 81.8%

      \[\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.6%

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

    if 2.00000000000000007e-10 < l < 9.99999999999999953e67

    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 84.6%

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

    if 9.99999999999999953e67 < 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 94.9%

      \[\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. Step-by-step derivation
      1. unpow294.9%

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

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

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

Alternative 7: 97.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 -4:\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(27 - t\_0\right)\right)\\ \mathbf{elif}\;\ell \leq 2 \cdot 10^{-10} \lor \neg \left(\ell \leq 10^{+68}\right):\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\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 -4.0)
     (+ U (* t_1 (* J (- 27.0 t_0))))
     (if (or (<= l 2e-10) (not (<= l 1e+68)))
       (+ U (* t_1 (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l)))))))
       (+ (* (- (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 <= -4.0) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if ((l <= 2e-10) || !(l <= 1e+68)) {
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	} 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 <= (-4.0d0)) then
        tmp = u + (t_1 * (j * (27.0d0 - t_0)))
    else if ((l <= 2d-10) .or. (.not. (l <= 1d+68))) then
        tmp = u + (t_1 * (j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l))))))
    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 <= -4.0) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if ((l <= 2e-10) || !(l <= 1e+68)) {
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	} 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 <= -4.0:
		tmp = U + (t_1 * (J * (27.0 - t_0)))
	elif (l <= 2e-10) or not (l <= 1e+68):
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))))
	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 <= -4.0)
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(27.0 - t_0))));
	elseif ((l <= 2e-10) || !(l <= 1e+68))
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))));
	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 <= -4.0)
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	elseif ((l <= 2e-10) || ~((l <= 1e+68)))
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	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, -4.0], N[(U + N[(t$95$1 * N[(J * N[(27.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, 2e-10], N[Not[LessEqual[l, 1e+68]], $MachinePrecision]], N[(U + N[(t$95$1 * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $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 -4:\\
\;\;\;\;U + t\_1 \cdot \left(J \cdot \left(27 - t\_0\right)\right)\\

\mathbf{elif}\;\ell \leq 2 \cdot 10^{-10} \lor \neg \left(\ell \leq 10^{+68}\right):\\
\;\;\;\;U + t\_1 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\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 < -4

    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 -4 < l < 2.00000000000000007e-10 or 9.99999999999999953e67 < l

    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 98.1%

      \[\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. Step-by-step derivation
      1. unpow298.1%

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

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

    if 2.00000000000000007e-10 < l < 9.99999999999999953e67

    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 84.6%

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

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

Alternative 8: 76.8% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 91.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 58.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. associate-*r*58.2%

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

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

      \[\leadsto \left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \color{blue}{\left(1 + -0.125 \cdot {K}^{2}\right)} + U \]
    7. Taylor expanded in K around inf 60.7%

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

        \[\leadsto \color{blue}{\left(-0.25 \cdot J\right) \cdot \left({K}^{2} \cdot \ell\right)} + U \]
      2. *-commutative60.7%

        \[\leadsto \color{blue}{\left({K}^{2} \cdot \ell\right) \cdot \left(-0.25 \cdot J\right)} + U \]
      3. *-commutative60.7%

        \[\leadsto \color{blue}{\left(\ell \cdot {K}^{2}\right)} \cdot \left(-0.25 \cdot J\right) + U \]
      4. *-commutative60.7%

        \[\leadsto \left(\ell \cdot {K}^{2}\right) \cdot \color{blue}{\left(J \cdot -0.25\right)} + U \]
    9. Simplified60.7%

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

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

    1. Initial program 90.8%

      \[\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 91.3%

      \[\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. Step-by-step derivation
      1. unpow291.3%

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

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

      \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right) \cdot \color{blue}{1} + 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.02:\\ \;\;\;\;U + \left(\ell \cdot {K}^{2}\right) \cdot \left(J \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 80.2% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-16}:\\
\;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\

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


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

    1. Initial program 92.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 86.2%

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

    if 5.0000000000000004e-16 < (/.f64 K #s(literal 2 binary64))

    1. Initial program 87.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 89.7%

      \[\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. Step-by-step derivation
      1. unpow289.7%

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

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

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

Alternative 10: 75.8% accurate, 2.6× speedup?

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

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

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


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

    1. Initial program 91.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 58.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. associate-*r*58.2%

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

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

      \[\leadsto \left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \color{blue}{\left(1 + -0.125 \cdot {K}^{2}\right)} + U \]
    7. Step-by-step derivation
      1. unpow259.0%

        \[\leadsto \left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \left(1 + -0.125 \cdot \color{blue}{\left(K \cdot K\right)}\right) + U \]
    8. Applied egg-rr59.0%

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

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

    1. Initial program 90.8%

      \[\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 91.3%

      \[\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. Step-by-step derivation
      1. unpow291.3%

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

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

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

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

Alternative 11: 88.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right) \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ U (* (cos (/ K 2.0)) (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l))))))))
double code(double J, double l, double K, double U) {
	return U + (cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u + (cos((k / 2.0d0)) * (j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l))))))
end function
public static double code(double J, double l, double K, double U) {
	return U + (Math.cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
}
def code(J, l, K, U):
	return U + (math.cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))))
function code(J, l, K, U)
	return Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))))
end
function tmp = code(J, l, K, U)
	tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
end
code[J_, l_, K_, U_] := N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)
\end{array}
Derivation
  1. Initial program 91.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 89.0%

    \[\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. Step-by-step derivation
    1. unpow289.0%

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

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

    \[\leadsto U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right) \]
  7. Add Preprocessing

Alternative 12: 42.7% accurate, 14.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := J \cdot \left(K \cdot \left(-K\right)\right)\\ \mathbf{if}\;\ell \leq -1.65 \cdot 10^{+155}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -5.5 \cdot 10^{+16}:\\ \;\;\;\;J \cdot \frac{U}{J}\\ \mathbf{elif}\;\ell \leq 8 \cdot 10^{+14}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* J (* K (- K)))))
   (if (<= l -1.65e+155)
     t_0
     (if (<= l -5.5e+16) (* J (/ U J)) (if (<= l 8e+14) U t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = J * (K * -K);
	double tmp;
	if (l <= -1.65e+155) {
		tmp = t_0;
	} else if (l <= -5.5e+16) {
		tmp = J * (U / J);
	} else if (l <= 8e+14) {
		tmp = U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = j * (k * -k)
    if (l <= (-1.65d+155)) then
        tmp = t_0
    else if (l <= (-5.5d+16)) then
        tmp = j * (u / j)
    else if (l <= 8d+14) then
        tmp = u
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = J * (K * -K);
	double tmp;
	if (l <= -1.65e+155) {
		tmp = t_0;
	} else if (l <= -5.5e+16) {
		tmp = J * (U / J);
	} else if (l <= 8e+14) {
		tmp = U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = J * (K * -K)
	tmp = 0
	if l <= -1.65e+155:
		tmp = t_0
	elif l <= -5.5e+16:
		tmp = J * (U / J)
	elif l <= 8e+14:
		tmp = U
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(J * Float64(K * Float64(-K)))
	tmp = 0.0
	if (l <= -1.65e+155)
		tmp = t_0;
	elseif (l <= -5.5e+16)
		tmp = Float64(J * Float64(U / J));
	elseif (l <= 8e+14)
		tmp = U;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = J * (K * -K);
	tmp = 0.0;
	if (l <= -1.65e+155)
		tmp = t_0;
	elseif (l <= -5.5e+16)
		tmp = J * (U / J);
	elseif (l <= 8e+14)
		tmp = U;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(J * N[(K * (-K)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.65e+155], t$95$0, If[LessEqual[l, -5.5e+16], N[(J * N[(U / J), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 8e+14], U, t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := J \cdot \left(K \cdot \left(-K\right)\right)\\
\mathbf{if}\;\ell \leq -1.65 \cdot 10^{+155}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -5.5 \cdot 10^{+16}:\\
\;\;\;\;J \cdot \frac{U}{J}\\

\mathbf{elif}\;\ell \leq 8 \cdot 10^{+14}:\\
\;\;\;\;U\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.6499999999999999e155 or 8e14 < 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. Applied egg-rr3.2%

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

      \[\leadsto \color{blue}{\left(-1 \cdot \left(J \cdot {K}^{2}\right) + 8 \cdot J\right)} + U \]
    5. Step-by-step derivation
      1. +-commutative20.8%

        \[\leadsto \color{blue}{\left(8 \cdot J + -1 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
      2. *-commutative20.8%

        \[\leadsto \left(\color{blue}{J \cdot 8} + -1 \cdot \left(J \cdot {K}^{2}\right)\right) + U \]
      3. mul-1-neg20.8%

        \[\leadsto \left(J \cdot 8 + \color{blue}{\left(-J \cdot {K}^{2}\right)}\right) + U \]
      4. unsub-neg20.8%

        \[\leadsto \color{blue}{\left(J \cdot 8 - J \cdot {K}^{2}\right)} + U \]
    6. Simplified20.8%

      \[\leadsto \color{blue}{\left(J \cdot 8 - J \cdot {K}^{2}\right)} + U \]
    7. Taylor expanded in K around inf 19.8%

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

        \[\leadsto \color{blue}{\left(-1 \cdot J\right) \cdot {K}^{2}} \]
      2. neg-mul-119.8%

        \[\leadsto \color{blue}{\left(-J\right)} \cdot {K}^{2} \]
      3. *-commutative19.8%

        \[\leadsto \color{blue}{{K}^{2} \cdot \left(-J\right)} \]
    9. Simplified19.8%

      \[\leadsto \color{blue}{{K}^{2} \cdot \left(-J\right)} \]
    10. Step-by-step derivation
      1. unpow232.7%

        \[\leadsto \left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \left(1 + -0.125 \cdot \color{blue}{\left(K \cdot K\right)}\right) + U \]
    11. Applied egg-rr19.8%

      \[\leadsto \color{blue}{\left(K \cdot K\right)} \cdot \left(-J\right) \]

    if -1.6499999999999999e155 < l < -5.5e16

    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-rr2.8%

      \[\leadsto \left(J \cdot \color{blue}{8}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in J around inf 24.2%

      \[\leadsto \color{blue}{J \cdot \left(8 \cdot \cos \left(0.5 \cdot K\right) + \frac{U}{J}\right)} \]
    5. Taylor expanded in U around inf 24.5%

      \[\leadsto J \cdot \color{blue}{\frac{U}{J}} \]

    if -5.5e16 < l < 8e14

    1. Initial program 83.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.65 \cdot 10^{+155}:\\ \;\;\;\;J \cdot \left(K \cdot \left(-K\right)\right)\\ \mathbf{elif}\;\ell \leq -5.5 \cdot 10^{+16}:\\ \;\;\;\;J \cdot \frac{U}{J}\\ \mathbf{elif}\;\ell \leq 8 \cdot 10^{+14}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(K \cdot \left(-K\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 39.2% accurate, 20.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -4.2 \cdot 10^{+20} \lor \neg \left(\ell \leq 1.28 \cdot 10^{+14}\right):\\ \;\;\;\;J \cdot \frac{U}{J}\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -4.2e+20) (not (<= l 1.28e+14))) (* J (/ U J)) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -4.2e+20) || !(l <= 1.28e+14)) {
		tmp = J * (U / J);
	} 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 <= (-4.2d+20)) .or. (.not. (l <= 1.28d+14))) then
        tmp = j * (u / j)
    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 <= -4.2e+20) || !(l <= 1.28e+14)) {
		tmp = J * (U / J);
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -4.2e+20) or not (l <= 1.28e+14):
		tmp = J * (U / J)
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -4.2e+20) || !(l <= 1.28e+14))
		tmp = Float64(J * Float64(U / J));
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -4.2e+20) || ~((l <= 1.28e+14)))
		tmp = J * (U / J);
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -4.2e+20], N[Not[LessEqual[l, 1.28e+14]], $MachinePrecision]], N[(J * N[(U / J), $MachinePrecision]), $MachinePrecision], U]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.2 \cdot 10^{+20} \lor \neg \left(\ell \leq 1.28 \cdot 10^{+14}\right):\\
\;\;\;\;J \cdot \frac{U}{J}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -4.2e20 or 1.28e14 < 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. Applied egg-rr3.2%

      \[\leadsto \left(J \cdot \color{blue}{8}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in J around inf 14.1%

      \[\leadsto \color{blue}{J \cdot \left(8 \cdot \cos \left(0.5 \cdot K\right) + \frac{U}{J}\right)} \]
    5. Taylor expanded in U around inf 13.5%

      \[\leadsto J \cdot \color{blue}{\frac{U}{J}} \]

    if -4.2e20 < l < 1.28e14

    1. Initial program 83.2%

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

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

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

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

Alternative 14: 72.4% accurate, 24.0× speedup?

\[\begin{array}{l} \\ U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right) \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l)))))))
double code(double J, double l, double K, double U) {
	return U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l)))))
end function
public static double code(double J, double l, double K, double U) {
	return U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
}
def code(J, l, K, U):
	return U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))))
function code(J, l, K, U)
	return Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l))))))
end
function tmp = code(J, l, K, U)
	tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
end
code[J_, l_, K_, U_] := N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)
\end{array}
Derivation
  1. Initial program 91.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 89.0%

    \[\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. Step-by-step derivation
    1. unpow289.0%

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

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

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

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

Alternative 15: 52.9% accurate, 26.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;U \leq 2.6 \cdot 10^{+244}:\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;J \cdot \frac{U}{J}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 2.6e244

    1. Initial program 90.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 63.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. associate-*r*63.7%

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

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

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

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

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

    if 2.6e244 < U

    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-rr30.8%

      \[\leadsto \left(J \cdot \color{blue}{8}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in J around inf 76.7%

      \[\leadsto \color{blue}{J \cdot \left(8 \cdot \cos \left(0.5 \cdot K\right) + \frac{U}{J}\right)} \]
    5. Taylor expanded in U around inf 76.7%

      \[\leadsto J \cdot \color{blue}{\frac{U}{J}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification55.9%

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

Alternative 16: 36.6% 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 91.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-rr28.6%

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

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

Reproduce

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