Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.4% → 97.5%
Time: 8.9s
Alternatives: 12
Speedup: 2.4×

Specification

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

\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 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: 97.5% accurate, 0.6× 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 -200:\\ \;\;\;\;\left(t\_1 \cdot J\right) \cdot t\_0 + U\\ \mathbf{else}:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\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 (<= t_1 -200.0)
     (+ (* (* t_1 J) t_0) U)
     (+
      U
      (*
       t_0
       (*
        J
        (*
         l
         (+
          2.0
          (*
           (* l l)
           (+
            0.3333333333333333
            (*
             (* l l)
             (+
              0.016666666666666666
              (* (* l l) 0.0003968253968253968)))))))))))))
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 <= -200.0) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))));
	}
	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 <= (-200.0d0)) then
        tmp = ((t_1 * j) * t_0) + u
    else
        tmp = u + (t_0 * (j * (l * (2.0d0 + ((l * l) * (0.3333333333333333d0 + ((l * l) * (0.016666666666666666d0 + ((l * l) * 0.0003968253968253968d0)))))))))
    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 <= -200.0) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))));
	}
	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 <= -200.0:
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (t_0 * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))))
	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 <= -200.0)
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * Float64(2.0 + Float64(Float64(l * l) * Float64(0.3333333333333333 + Float64(Float64(l * l) * Float64(0.016666666666666666 + Float64(Float64(l * l) * 0.0003968253968253968))))))))));
	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 <= -200.0)
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (t_0 * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))));
	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[LessEqual[t$95$1, -200.0], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(l * N[(2.0 + N[(N[(l * l), $MachinePrecision] * N[(0.3333333333333333 + N[(N[(l * l), $MachinePrecision] * N[(0.016666666666666666 + N[(N[(l * l), $MachinePrecision] * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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


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

    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 -200 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 81.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 98.4%

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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + {\ell}^{2} \cdot 0.0003968253968253968\right)\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Step-by-step derivation
      1. unpow298.4%

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

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

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

      \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + \color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    10. Step-by-step derivation
      1. unpow298.4%

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

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

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

Alternative 2: 97.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ \mathbf{if}\;e^{\ell} - t\_0 \leq -200:\\ \;\;\;\;U + J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(0.3333333333333333 - t\_0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (exp (- l))))
   (if (<= (- (exp l) t_0) -200.0)
     (+ U (* J (* (cos (* K 0.5)) (- 0.3333333333333333 t_0))))
     (+
      U
      (*
       (cos (/ K 2.0))
       (*
        J
        (*
         l
         (+
          2.0
          (*
           (* l l)
           (+
            0.3333333333333333
            (*
             (* l l)
             (+
              0.016666666666666666
              (* (* l l) 0.0003968253968253968)))))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(-l);
	double tmp;
	if ((exp(l) - t_0) <= -200.0) {
		tmp = U + (J * (cos((K * 0.5)) * (0.3333333333333333 - t_0)));
	} else {
		tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))));
	}
	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 = exp(-l)
    if ((exp(l) - t_0) <= (-200.0d0)) then
        tmp = u + (j * (cos((k * 0.5d0)) * (0.3333333333333333d0 - t_0)))
    else
        tmp = u + (cos((k / 2.0d0)) * (j * (l * (2.0d0 + ((l * l) * (0.3333333333333333d0 + ((l * l) * (0.016666666666666666d0 + ((l * l) * 0.0003968253968253968d0)))))))))
    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 tmp;
	if ((Math.exp(l) - t_0) <= -200.0) {
		tmp = U + (J * (Math.cos((K * 0.5)) * (0.3333333333333333 - t_0)));
	} else {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(-l)
	tmp = 0
	if (math.exp(l) - t_0) <= -200.0:
		tmp = U + (J * (math.cos((K * 0.5)) * (0.3333333333333333 - t_0)))
	else:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))))
	return tmp
function code(J, l, K, U)
	t_0 = exp(Float64(-l))
	tmp = 0.0
	if (Float64(exp(l) - t_0) <= -200.0)
		tmp = Float64(U + Float64(J * Float64(cos(Float64(K * 0.5)) * Float64(0.3333333333333333 - t_0))));
	else
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * Float64(2.0 + Float64(Float64(l * l) * Float64(0.3333333333333333 + Float64(Float64(l * l) * Float64(0.016666666666666666 + Float64(Float64(l * l) * 0.0003968253968253968))))))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(-l);
	tmp = 0.0;
	if ((exp(l) - t_0) <= -200.0)
		tmp = U + (J * (cos((K * 0.5)) * (0.3333333333333333 - t_0)));
	else
		tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, If[LessEqual[N[(N[Exp[l], $MachinePrecision] - t$95$0), $MachinePrecision], -200.0], N[(U + N[(J * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(0.3333333333333333 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * N[(2.0 + N[(N[(l * l), $MachinePrecision] * N[(0.3333333333333333 + N[(N[(l * l), $MachinePrecision] * N[(0.016666666666666666 + N[(N[(l * l), $MachinePrecision] * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
\mathbf{if}\;e^{\ell} - t\_0 \leq -200:\\
\;\;\;\;U + J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(0.3333333333333333 - t\_0\right)\right)\\

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


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

    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-rr99.1%

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

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

    if -200 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 81.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 98.4%

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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + {\ell}^{2} \cdot 0.0003968253968253968\right)\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Step-by-step derivation
      1. unpow298.4%

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

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

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

      \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + \color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    10. Step-by-step derivation
      1. unpow298.4%

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

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

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

Alternative 3: 93.9% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right) - 0.6666666666666666\right)\right)\\ \mathbf{if}\;\ell \leq -1 \cdot 10^{+103}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -22:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 1.9 \cdot 10^{-9}:\\ \;\;\;\;U + \ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2 \cdot 10^{+101}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right) \cdot {\ell}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0
         (+
          U
          (*
           (cos (/ K 2.0))
           (*
            J
            (-
             (* l (+ 1.0 (* l (- (* l 0.16666666666666666) 0.5))))
             0.6666666666666666))))))
   (if (<= l -1e+103)
     t_0
     (if (<= l -22.0)
       (+ U (* J (- 0.3333333333333333 (exp (- l)))))
       (if (<= l 1.9e-9)
         (+ U (* l (* (cos (* K 0.5)) (* J 2.0))))
         (if (<= l 2e+101)
           (+
            U
            (*
             J
             (*
              l
              (+
               2.0
               (*
                (+
                 0.3333333333333333
                 (*
                  (* l l)
                  (+ 0.016666666666666666 (* (* l l) 0.0003968253968253968))))
                (pow l 2.0))))))
           t_0))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (cos((K / 2.0)) * (J * ((l * (1.0 + (l * ((l * 0.16666666666666666) - 0.5)))) - 0.6666666666666666)));
	double tmp;
	if (l <= -1e+103) {
		tmp = t_0;
	} else if (l <= -22.0) {
		tmp = U + (J * (0.3333333333333333 - exp(-l)));
	} else if (l <= 1.9e-9) {
		tmp = U + (l * (cos((K * 0.5)) * (J * 2.0)));
	} else if (l <= 2e+101) {
		tmp = U + (J * (l * (2.0 + ((0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))) * pow(l, 2.0)))));
	} 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 = u + (cos((k / 2.0d0)) * (j * ((l * (1.0d0 + (l * ((l * 0.16666666666666666d0) - 0.5d0)))) - 0.6666666666666666d0)))
    if (l <= (-1d+103)) then
        tmp = t_0
    else if (l <= (-22.0d0)) then
        tmp = u + (j * (0.3333333333333333d0 - exp(-l)))
    else if (l <= 1.9d-9) then
        tmp = u + (l * (cos((k * 0.5d0)) * (j * 2.0d0)))
    else if (l <= 2d+101) then
        tmp = u + (j * (l * (2.0d0 + ((0.3333333333333333d0 + ((l * l) * (0.016666666666666666d0 + ((l * l) * 0.0003968253968253968d0)))) * (l ** 2.0d0)))))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (Math.cos((K / 2.0)) * (J * ((l * (1.0 + (l * ((l * 0.16666666666666666) - 0.5)))) - 0.6666666666666666)));
	double tmp;
	if (l <= -1e+103) {
		tmp = t_0;
	} else if (l <= -22.0) {
		tmp = U + (J * (0.3333333333333333 - Math.exp(-l)));
	} else if (l <= 1.9e-9) {
		tmp = U + (l * (Math.cos((K * 0.5)) * (J * 2.0)));
	} else if (l <= 2e+101) {
		tmp = U + (J * (l * (2.0 + ((0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))) * Math.pow(l, 2.0)))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (math.cos((K / 2.0)) * (J * ((l * (1.0 + (l * ((l * 0.16666666666666666) - 0.5)))) - 0.6666666666666666)))
	tmp = 0
	if l <= -1e+103:
		tmp = t_0
	elif l <= -22.0:
		tmp = U + (J * (0.3333333333333333 - math.exp(-l)))
	elif l <= 1.9e-9:
		tmp = U + (l * (math.cos((K * 0.5)) * (J * 2.0)))
	elif l <= 2e+101:
		tmp = U + (J * (l * (2.0 + ((0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))) * math.pow(l, 2.0)))))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(Float64(l * Float64(1.0 + Float64(l * Float64(Float64(l * 0.16666666666666666) - 0.5)))) - 0.6666666666666666))))
	tmp = 0.0
	if (l <= -1e+103)
		tmp = t_0;
	elseif (l <= -22.0)
		tmp = Float64(U + Float64(J * Float64(0.3333333333333333 - exp(Float64(-l)))));
	elseif (l <= 1.9e-9)
		tmp = Float64(U + Float64(l * Float64(cos(Float64(K * 0.5)) * Float64(J * 2.0))));
	elseif (l <= 2e+101)
		tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(Float64(0.3333333333333333 + Float64(Float64(l * l) * Float64(0.016666666666666666 + Float64(Float64(l * l) * 0.0003968253968253968)))) * (l ^ 2.0))))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (cos((K / 2.0)) * (J * ((l * (1.0 + (l * ((l * 0.16666666666666666) - 0.5)))) - 0.6666666666666666)));
	tmp = 0.0;
	if (l <= -1e+103)
		tmp = t_0;
	elseif (l <= -22.0)
		tmp = U + (J * (0.3333333333333333 - exp(-l)));
	elseif (l <= 1.9e-9)
		tmp = U + (l * (cos((K * 0.5)) * (J * 2.0)));
	elseif (l <= 2e+101)
		tmp = U + (J * (l * (2.0 + ((0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))) * (l ^ 2.0)))));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(N[(l * N[(1.0 + N[(l * N[(N[(l * 0.16666666666666666), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.6666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1e+103], t$95$0, If[LessEqual[l, -22.0], N[(U + N[(J * N[(0.3333333333333333 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.9e-9], N[(U + N[(l * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2e+101], N[(U + N[(J * N[(l * N[(2.0 + N[(N[(0.3333333333333333 + N[(N[(l * l), $MachinePrecision] * N[(0.016666666666666666 + N[(N[(l * l), $MachinePrecision] * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right) - 0.6666666666666666\right)\right)\\
\mathbf{if}\;\ell \leq -1 \cdot 10^{+103}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -22:\\
\;\;\;\;U + J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\\

\mathbf{elif}\;\ell \leq 1.9 \cdot 10^{-9}:\\
\;\;\;\;U + \ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)\right)\\

\mathbf{elif}\;\ell \leq 2 \cdot 10^{+101}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right) \cdot {\ell}^{2}\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1e103 or 2e101 < 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-rr58.3%

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

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

    if -1e103 < l < -22

    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}{0.3333333333333333} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 81.0%

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

    if -22 < l < 1.90000000000000006e-9

    1. Initial program 72.9%

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

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

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

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

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

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

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

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

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

    if 1.90000000000000006e-9 < l < 2e101

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

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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + {\ell}^{2} \cdot 0.0003968253968253968\right)\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Step-by-step derivation
      1. unpow282.9%

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

      \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + \color{blue}{\left(\ell \cdot \ell\right)} \cdot 0.0003968253968253968\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    8. Step-by-step derivation
      1. unpow282.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1 \cdot 10^{+103}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right) - 0.6666666666666666\right)\right)\\ \mathbf{elif}\;\ell \leq -22:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 1.9 \cdot 10^{-9}:\\ \;\;\;\;U + \ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2 \cdot 10^{+101}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right) \cdot {\ell}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right) - 0.6666666666666666\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 91.3% accurate, 2.3× speedup?

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

\\
\begin{array}{l}
t_0 := U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right) - 0.6666666666666666\right)\right)\\
\mathbf{if}\;\ell \leq -1 \cdot 10^{+103}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -22:\\
\;\;\;\;U + J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\\

\mathbf{elif}\;\ell \leq 1.9 \cdot 10^{-9}:\\
\;\;\;\;U + \ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1e103 or 1.90000000000000006e-9 < 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-rr52.3%

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

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

    if -1e103 < l < -22

    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}{0.3333333333333333} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 81.0%

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

    if -22 < l < 1.90000000000000006e-9

    1. Initial program 72.9%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1 \cdot 10^{+103}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right) - 0.6666666666666666\right)\right)\\ \mathbf{elif}\;\ell \leq -22:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 1.9 \cdot 10^{-9}:\\ \;\;\;\;U + \ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right) - 0.6666666666666666\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 94.9% accurate, 2.4× speedup?

\[\begin{array}{l} \\ U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right) \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+
  U
  (*
   (cos (/ K 2.0))
   (*
    J
    (*
     l
     (+
      2.0
      (*
       (* l l)
       (+
        0.3333333333333333
        (*
         (* l l)
         (+ 0.016666666666666666 (* (* l l) 0.0003968253968253968)))))))))))
double code(double J, double l, double K, double U) {
	return U + (cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))));
}
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 + ((l * l) * (0.3333333333333333d0 + ((l * l) * (0.016666666666666666d0 + ((l * l) * 0.0003968253968253968d0)))))))))
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 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))));
}
def code(J, l, K, U):
	return U + (math.cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))))
function code(J, l, K, U)
	return Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * Float64(2.0 + Float64(Float64(l * l) * Float64(0.3333333333333333 + Float64(Float64(l * l) * Float64(0.016666666666666666 + Float64(Float64(l * l) * 0.0003968253968253968))))))))))
end
function tmp = code(J, l, K, U)
	tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))));
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[(N[(l * l), $MachinePrecision] * N[(0.3333333333333333 + N[(N[(l * l), $MachinePrecision] * N[(0.016666666666666666 + N[(N[(l * l), $MachinePrecision] * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 + \left(\ell \cdot \ell\right) \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right)
\end{array}
Derivation
  1. Initial program 86.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 95.9%

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

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

    \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + {\ell}^{2} \cdot 0.0003968253968253968\right)\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  6. Step-by-step derivation
    1. unpow295.9%

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

    \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + \color{blue}{\left(\ell \cdot \ell\right)} \cdot 0.0003968253968253968\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  8. Step-by-step derivation
    1. unpow295.9%

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

    \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + \color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  10. Step-by-step derivation
    1. unpow295.9%

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

    \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + \color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  12. Final simplification95.9%

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

Alternative 6: 84.3% accurate, 2.5× speedup?

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

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

\mathbf{elif}\;\ell \leq -22:\\
\;\;\;\;U + J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\\

\mathbf{elif}\;\ell \leq 1.9 \cdot 10^{-9}:\\
\;\;\;\;U + \ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)\right)\\

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


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

    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}{0.3333333333333333} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in l around 0 94.7%

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

    if -5.9999999999999998e144 < l < -22

    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}{0.3333333333333333} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 80.0%

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

    if -22 < l < 1.90000000000000006e-9

    1. Initial program 72.9%

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

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

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

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

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

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

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

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

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

    if 1.90000000000000006e-9 < 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-rr8.9%

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

      \[\leadsto \color{blue}{\left(-0.6666666666666666 \cdot J + \ell \cdot \left(J + \ell \cdot \left(-0.5 \cdot J + 0.16666666666666666 \cdot \left(J \cdot \ell\right)\right)\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Taylor expanded in K around 0 54.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6 \cdot 10^{+144}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(1 + \ell \cdot -0.5\right) - 0.6666666666666666\right)\right)\\ \mathbf{elif}\;\ell \leq -22:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 1.9 \cdot 10^{-9}:\\ \;\;\;\;U + \ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot -0.6666666666666666 + \ell \cdot \left(J + \ell \cdot \left(J \cdot -0.5 + 0.16666666666666666 \cdot \left(\ell \cdot J\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 81.2% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -22:\\
\;\;\;\;U + J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\\

\mathbf{elif}\;\ell \leq 1.9 \cdot 10^{-9}:\\
\;\;\;\;U + \ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)\right)\\

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


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

    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}{0.3333333333333333} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 77.8%

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

    if -22 < l < 1.90000000000000006e-9

    1. Initial program 72.9%

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

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

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

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

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

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

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

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

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

    if 1.90000000000000006e-9 < 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-rr8.9%

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

      \[\leadsto \color{blue}{\left(-0.6666666666666666 \cdot J + \ell \cdot \left(J + \ell \cdot \left(-0.5 \cdot J + 0.16666666666666666 \cdot \left(J \cdot \ell\right)\right)\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Taylor expanded in K around 0 54.6%

      \[\leadsto \color{blue}{\left(-0.6666666666666666 \cdot J + \ell \cdot \left(J + \ell \cdot \left(-0.5 \cdot J + 0.16666666666666666 \cdot \left(J \cdot \ell\right)\right)\right)\right)} + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification83.1%

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

Alternative 8: 81.3% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -22:\\
\;\;\;\;U + J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\\

\mathbf{elif}\;\ell \leq 1.9 \cdot 10^{-9}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\

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


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

    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}{0.3333333333333333} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 77.8%

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

    if -22 < l < 1.90000000000000006e-9

    1. Initial program 72.9%

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

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

    if 1.90000000000000006e-9 < 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-rr8.9%

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

      \[\leadsto \color{blue}{\left(-0.6666666666666666 \cdot J + \ell \cdot \left(J + \ell \cdot \left(-0.5 \cdot J + 0.16666666666666666 \cdot \left(J \cdot \ell\right)\right)\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Taylor expanded in K around 0 54.6%

      \[\leadsto \color{blue}{\left(-0.6666666666666666 \cdot J + \ell \cdot \left(J + \ell \cdot \left(-0.5 \cdot J + 0.16666666666666666 \cdot \left(J \cdot \ell\right)\right)\right)\right)} + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification83.1%

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

Alternative 9: 67.4% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -6.4 \cdot 10^{-52}:\\
\;\;\;\;U + J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\\

\mathbf{elif}\;\ell \leq 7.6 \cdot 10^{-11}:\\
\;\;\;\;U\\

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


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

    1. Initial program 94.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-rr91.9%

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

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

    if -6.4000000000000002e-52 < l < 7.5999999999999996e-11

    1. Initial program 74.2%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*74.2%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    3. Simplified74.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in J around 0 74.0%

      \[\leadsto \color{blue}{U} \]

    if 7.5999999999999996e-11 < 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-rr8.9%

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

      \[\leadsto \color{blue}{\left(-0.6666666666666666 \cdot J + \ell \cdot \left(J + \ell \cdot \left(-0.5 \cdot J + 0.16666666666666666 \cdot \left(J \cdot \ell\right)\right)\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Taylor expanded in K around 0 54.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6.4 \cdot 10^{-52}:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 7.6 \cdot 10^{-11}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot -0.6666666666666666 + \ell \cdot \left(J + \ell \cdot \left(J \cdot -0.5 + 0.16666666666666666 \cdot \left(\ell \cdot J\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 61.5% accurate, 10.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.3 \cdot 10^{-51} \lor \neg \left(\ell \leq 1.1 \cdot 10^{-9}\right):\\
\;\;\;\;U + \left(J \cdot -0.6666666666666666 + \ell \cdot \left(J + \ell \cdot \left(J \cdot -0.5 + 0.16666666666666666 \cdot \left(\ell \cdot J\right)\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.30000000000000002e-51 or 1.0999999999999999e-9 < l

    1. Initial program 96.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-rr59.2%

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

      \[\leadsto \color{blue}{\left(-0.6666666666666666 \cdot J + \ell \cdot \left(J + \ell \cdot \left(-0.5 \cdot J + 0.16666666666666666 \cdot \left(J \cdot \ell\right)\right)\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Taylor expanded in K around 0 54.8%

      \[\leadsto \color{blue}{\left(-0.6666666666666666 \cdot J + \ell \cdot \left(J + \ell \cdot \left(-0.5 \cdot J + 0.16666666666666666 \cdot \left(J \cdot \ell\right)\right)\right)\right)} + U \]

    if -2.30000000000000002e-51 < l < 1.0999999999999999e-9

    1. Initial program 74.2%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*74.2%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    3. Simplified74.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in J around 0 74.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.3 \cdot 10^{-51} \lor \neg \left(\ell \leq 1.1 \cdot 10^{-9}\right):\\ \;\;\;\;U + \left(J \cdot -0.6666666666666666 + \ell \cdot \left(J + \ell \cdot \left(J \cdot -0.5 + 0.16666666666666666 \cdot \left(\ell \cdot J\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 42.7% accurate, 23.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.4 \cdot 10^{+22} \lor \neg \left(\ell \leq 750\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -3.4e22 or 750 < 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. Step-by-step derivation
      1. associate-*l*100.0%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr17.2%

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

    if -3.4e22 < l < 750

    1. Initial program 74.4%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*74.3%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    3. Simplified74.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in J around 0 69.4%

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

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

Alternative 12: 36.9% 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 86.5%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Step-by-step derivation
    1. associate-*l*86.5%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
  3. Simplified86.5%

    \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in J around 0 37.7%

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

Reproduce

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