Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.7% → 99.6%
Time: 18.5s
Alternatives: 18
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 18 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.7% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ t_1 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t_0 \leq -100000:\\ \;\;\;\;t_0 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right) + U\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot 2\right) \cdot t_1, U\right)\\ \mathbf{else}:\\ \;\;\;\;U + t_1 \cdot \left(t_0 \cdot J\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))) (t_1 (cos (/ K 2.0))))
   (if (<= t_0 -100000.0)
     (+ (* t_0 (* J (cos (* 0.5 K)))) U)
     (if (<= t_0 0.0) (fma J (* (* l 2.0) t_1) U) (+ U (* t_1 (* t_0 J)))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double t_1 = cos((K / 2.0));
	double tmp;
	if (t_0 <= -100000.0) {
		tmp = (t_0 * (J * cos((0.5 * K)))) + U;
	} else if (t_0 <= 0.0) {
		tmp = fma(J, ((l * 2.0) * t_1), U);
	} else {
		tmp = U + (t_1 * (t_0 * J));
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	t_1 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_0 <= -100000.0)
		tmp = Float64(Float64(t_0 * Float64(J * cos(Float64(0.5 * K)))) + U);
	elseif (t_0 <= 0.0)
		tmp = fma(J, Float64(Float64(l * 2.0) * t_1), U);
	else
		tmp = Float64(U + Float64(t_1 * Float64(t_0 * J)));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, -100000.0], N[(N[(t$95$0 * N[(J * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(J * N[(N[(l * 2.0), $MachinePrecision] * t$95$1), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$1 * N[(t$95$0 * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot 2\right) \cdot t_1, U\right)\\

\mathbf{else}:\\
\;\;\;\;U + t_1 \cdot \left(t_0 \cdot J\right)\\


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
    3. Step-by-step derivation
      1. associate-*r*100.0%

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

        \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    4. Simplified100.0%

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

    if -1e5 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.0

    1. Initial program 71.3%

      \[\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*71.3%

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

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

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

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

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

    1. Initial program 100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -100000:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right) + U\\ \mathbf{elif}\;e^{\ell} - e^{-\ell} \leq 0:\\ \;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot 2\right) \cdot \cos \left(\frac{K}{2}\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\\ \end{array} \]

Alternative 2: 99.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_1 \leq -100000 \lor \neg \left(t_1 \leq 0\right):\\ \;\;\;\;U + t_0 \cdot \left(t_1 \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot 2\right) \cdot t_0, U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
   (if (or (<= t_1 -100000.0) (not (<= t_1 0.0)))
     (+ U (* t_0 (* t_1 J)))
     (fma J (* (* l 2.0) t_0) U))))
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 <= -100000.0) || !(t_1 <= 0.0)) {
		tmp = U + (t_0 * (t_1 * J));
	} else {
		tmp = fma(J, ((l * 2.0) * t_0), U);
	}
	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 <= -100000.0) || !(t_1 <= 0.0))
		tmp = Float64(U + Float64(t_0 * Float64(t_1 * J)));
	else
		tmp = fma(J, Float64(Float64(l * 2.0) * t_0), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -100000.0], N[Not[LessEqual[t$95$1, 0.0]], $MachinePrecision]], N[(U + N[(t$95$0 * N[(t$95$1 * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(J * N[(N[(l * 2.0), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $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 -100000 \lor \neg \left(t_1 \leq 0\right):\\
\;\;\;\;U + t_0 \cdot \left(t_1 \cdot J\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot 2\right) \cdot t_0, U\right)\\


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

    1. Initial program 100.0%

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

    if -1e5 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.0

    1. Initial program 71.3%

      \[\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*71.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -100000 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 0\right):\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot 2\right) \cdot \cos \left(\frac{K}{2}\right), U\right)\\ \end{array} \]

Alternative 3: 87.1% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_0 \leq -100000 \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;U + t_0 \cdot J\\

\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\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))) < -1e5 or 0.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

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

    if -1e5 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.0

    1. Initial program 71.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -100000 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 0\right):\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \end{array} \]

Alternative 4: 77.0% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;t_0 \leq -0.02:\\
\;\;\;\;U + \left(J \cdot \left(K \cdot K\right)\right) \cdot \left(\ell \cdot -0.25\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (cos.f64 (/.f64 K 2)) < -0.92000000000000004

    1. Initial program 100.0%

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

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

    if -0.92000000000000004 < (cos.f64 (/.f64 K 2)) < -0.0200000000000000004

    1. Initial program 88.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto U + \left(J \cdot \color{blue}{\left(K \cdot K\right)}\right) \cdot \left(\ell \cdot -0.25\right) \]
    8. Simplified69.7%

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

    if -0.0200000000000000004 < (cos.f64 (/.f64 K 2))

    1. Initial program 84.7%

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
    3. Step-by-step derivation
      1. associate-*r*84.7%

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

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    5. Taylor expanded in K around 0 84.0%

      \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \color{blue}{J} + U \]
    6. Taylor expanded in l around 0 81.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.92:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq -0.02:\\ \;\;\;\;U + \left(J \cdot \left(K \cdot K\right)\right) \cdot \left(\ell \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2 + 0.3333333333333333 \cdot {\ell}^{3}\right)\\ \end{array} \]

Alternative 5: 86.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -5 \cdot 10^{+176}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -3.3 \lor \neg \left(\ell \leq 3 \cdot 10^{-14}\right):\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot 2\right) \cdot \cos \left(\frac{K}{2}\right), U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -5e+176)
   (+ U (* 0.3333333333333333 (* J (pow l 3.0))))
   (if (or (<= l -3.3) (not (<= l 3e-14)))
     (+ U (* (- (exp l) (exp (- l))) (+ J (* J (* K (* K -0.125))))))
     (fma J (* (* l 2.0) (cos (/ K 2.0))) U))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -5e+176) {
		tmp = U + (0.3333333333333333 * (J * pow(l, 3.0)));
	} else if ((l <= -3.3) || !(l <= 3e-14)) {
		tmp = U + ((exp(l) - exp(-l)) * (J + (J * (K * (K * -0.125)))));
	} else {
		tmp = fma(J, ((l * 2.0) * cos((K / 2.0))), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -5e+176)
		tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))));
	elseif ((l <= -3.3) || !(l <= 3e-14))
		tmp = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * Float64(J + Float64(J * Float64(K * Float64(K * -0.125))))));
	else
		tmp = fma(J, Float64(Float64(l * 2.0) * cos(Float64(K / 2.0))), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, -5e+176], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, -3.3], N[Not[LessEqual[l, 3e-14]], $MachinePrecision]], N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * N[(J + N[(J * N[(K * N[(K * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(J * N[(N[(l * 2.0), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -3.3 \lor \neg \left(\ell \leq 3 \cdot 10^{-14}\right):\\
\;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
    3. Step-by-step derivation
      1. associate-*r*100.0%

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

        \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    4. Simplified100.0%

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    5. Taylor expanded in K around 0 95.8%

      \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \color{blue}{J} + U \]
    6. Taylor expanded in l around 0 95.8%

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

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

    if -5e176 < l < -3.2999999999999998 or 2.9999999999999998e-14 < 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. Taylor expanded in K around 0 3.5%

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

        \[\leadsto \color{blue}{\left(J \cdot \left(e^{\ell} - e^{-\ell}\right) + -0.125 \cdot \left(J \cdot \left({K}^{2} \cdot \left(e^{\ell} - e^{-\ell}\right)\right)\right)\right)} + U \]
      2. associate-*r*3.5%

        \[\leadsto \left(J \cdot \left(e^{\ell} - e^{-\ell}\right) + -0.125 \cdot \color{blue}{\left(\left(J \cdot {K}^{2}\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)}\right) + U \]
      3. associate-*r*3.5%

        \[\leadsto \left(J \cdot \left(e^{\ell} - e^{-\ell}\right) + \color{blue}{\left(-0.125 \cdot \left(J \cdot {K}^{2}\right)\right) \cdot \left(e^{\ell} - e^{-\ell}\right)}\right) + U \]
      4. distribute-rgt-out81.9%

        \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + -0.125 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
      5. associate-*r*81.9%

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

        \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + \color{blue}{\left(J \cdot -0.125\right)} \cdot {K}^{2}\right) + U \]
      7. associate-*l*81.9%

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

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

        \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot -0.125\right)\right) + U \]
      10. associate-*l*81.9%

        \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \color{blue}{\left(K \cdot \left(K \cdot -0.125\right)\right)}\right) + U \]
    4. Simplified81.9%

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

    if -3.2999999999999998 < l < 2.9999999999999998e-14

    1. Initial program 71.3%

      \[\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*71.3%

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

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

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

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(2 \cdot \ell\right)} \cdot \cos \left(\frac{K}{2}\right), U\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification91.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5 \cdot 10^{+176}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -3.3 \lor \neg \left(\ell \leq 3 \cdot 10^{-14}\right):\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot 2\right) \cdot \cos \left(\frac{K}{2}\right), U\right)\\ \end{array} \]

Alternative 6: 86.5% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -0.0009 \lor \neg \left(\ell \leq 2.3 \cdot 10^{-31}\right):\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot 2\right) \cdot \cos \left(\frac{K}{2}\right), U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -0.0009) (not (<= l 2.3e-31)))
   (+ U (* (- (exp l) (exp (- l))) J))
   (fma J (* (* l 2.0) (cos (/ K 2.0))) U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -0.0009) || !(l <= 2.3e-31)) {
		tmp = U + ((exp(l) - exp(-l)) * J);
	} else {
		tmp = fma(J, ((l * 2.0) * cos((K / 2.0))), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -0.0009) || !(l <= 2.3e-31))
		tmp = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J));
	else
		tmp = fma(J, Float64(Float64(l * 2.0) * cos(Float64(K / 2.0))), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -0.0009], N[Not[LessEqual[l, 2.3e-31]], $MachinePrecision]], N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision], N[(J * N[(N[(l * 2.0), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -0.0009 \lor \neg \left(\ell \leq 2.3 \cdot 10^{-31}\right):\\
\;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -8.9999999999999998e-4 or 2.2999999999999998e-31 < 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. Taylor expanded in K around 0 75.0%

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

    if -8.9999999999999998e-4 < l < 2.2999999999999998e-31

    1. Initial program 70.9%

      \[\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*70.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -0.0009 \lor \neg \left(\ell \leq 2.3 \cdot 10^{-31}\right):\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot 2\right) \cdot \cos \left(\frac{K}{2}\right), U\right)\\ \end{array} \]

Alternative 7: 78.2% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{if}\;\ell \leq -1.55 \cdot 10^{+55}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -7.5 \cdot 10^{+20}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\right)\\ \mathbf{elif}\;\ell \leq -1300000000:\\ \;\;\;\;U + J \cdot \left(512 + K \cdot \left(K \cdot -64\right)\right)\\ \mathbf{elif}\;\ell \leq 2.3 \cdot 10^{-31}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* 0.3333333333333333 (* J (pow l 3.0))))))
   (if (<= l -1.55e+55)
     t_0
     (if (<= l -7.5e+20)
       (+ U (* l (* J (+ 2.0 (* (* K K) -0.25)))))
       (if (<= l -1300000000.0)
         (+ U (* J (+ 512.0 (* K (* K -64.0)))))
         (if (<= l 2.3e-31) (+ U (* 2.0 (* J (* l (cos (* 0.5 K)))))) t_0))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (0.3333333333333333 * (J * pow(l, 3.0)));
	double tmp;
	if (l <= -1.55e+55) {
		tmp = t_0;
	} else if (l <= -7.5e+20) {
		tmp = U + (l * (J * (2.0 + ((K * K) * -0.25))));
	} else if (l <= -1300000000.0) {
		tmp = U + (J * (512.0 + (K * (K * -64.0))));
	} else if (l <= 2.3e-31) {
		tmp = U + (2.0 * (J * (l * cos((0.5 * K)))));
	} 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 + (0.3333333333333333d0 * (j * (l ** 3.0d0)))
    if (l <= (-1.55d+55)) then
        tmp = t_0
    else if (l <= (-7.5d+20)) then
        tmp = u + (l * (j * (2.0d0 + ((k * k) * (-0.25d0)))))
    else if (l <= (-1300000000.0d0)) then
        tmp = u + (j * (512.0d0 + (k * (k * (-64.0d0)))))
    else if (l <= 2.3d-31) then
        tmp = u + (2.0d0 * (j * (l * cos((0.5d0 * k)))))
    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 + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
	double tmp;
	if (l <= -1.55e+55) {
		tmp = t_0;
	} else if (l <= -7.5e+20) {
		tmp = U + (l * (J * (2.0 + ((K * K) * -0.25))));
	} else if (l <= -1300000000.0) {
		tmp = U + (J * (512.0 + (K * (K * -64.0))));
	} else if (l <= 2.3e-31) {
		tmp = U + (2.0 * (J * (l * Math.cos((0.5 * K)))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (0.3333333333333333 * (J * math.pow(l, 3.0)))
	tmp = 0
	if l <= -1.55e+55:
		tmp = t_0
	elif l <= -7.5e+20:
		tmp = U + (l * (J * (2.0 + ((K * K) * -0.25))))
	elif l <= -1300000000.0:
		tmp = U + (J * (512.0 + (K * (K * -64.0))))
	elif l <= 2.3e-31:
		tmp = U + (2.0 * (J * (l * math.cos((0.5 * K)))))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))))
	tmp = 0.0
	if (l <= -1.55e+55)
		tmp = t_0;
	elseif (l <= -7.5e+20)
		tmp = Float64(U + Float64(l * Float64(J * Float64(2.0 + Float64(Float64(K * K) * -0.25)))));
	elseif (l <= -1300000000.0)
		tmp = Float64(U + Float64(J * Float64(512.0 + Float64(K * Float64(K * -64.0)))));
	elseif (l <= 2.3e-31)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(0.5 * K))))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (0.3333333333333333 * (J * (l ^ 3.0)));
	tmp = 0.0;
	if (l <= -1.55e+55)
		tmp = t_0;
	elseif (l <= -7.5e+20)
		tmp = U + (l * (J * (2.0 + ((K * K) * -0.25))));
	elseif (l <= -1300000000.0)
		tmp = U + (J * (512.0 + (K * (K * -64.0))));
	elseif (l <= 2.3e-31)
		tmp = U + (2.0 * (J * (l * cos((0.5 * K)))));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.55e+55], t$95$0, If[LessEqual[l, -7.5e+20], N[(U + N[(l * N[(J * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -1300000000.0], N[(U + N[(J * N[(512.0 + N[(K * N[(K * -64.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.3e-31], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\mathbf{if}\;\ell \leq -1.55 \cdot 10^{+55}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -7.5 \cdot 10^{+20}:\\
\;\;\;\;U + \ell \cdot \left(J \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\right)\\

\mathbf{elif}\;\ell \leq -1300000000:\\
\;\;\;\;U + J \cdot \left(512 + K \cdot \left(K \cdot -64\right)\right)\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.54999999999999997e55 or 2.2999999999999998e-31 < 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. Taylor expanded in J around 0 100.0%

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
    3. Step-by-step derivation
      1. associate-*r*100.0%

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

        \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    4. Simplified100.0%

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    5. Taylor expanded in K around 0 77.8%

      \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \color{blue}{J} + U \]
    6. Taylor expanded in l around 0 62.7%

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

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

    if -1.54999999999999997e55 < l < -7.5e20

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.5e20 < l < -1.3e9

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Applied egg-rr3.8%

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

      \[\leadsto \color{blue}{\left(-64 \cdot \left(J \cdot {K}^{2}\right) + 512 \cdot J\right)} + U \]
    4. Step-by-step derivation
      1. +-commutative68.4%

        \[\leadsto \color{blue}{\left(512 \cdot J + -64 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
      2. *-commutative68.4%

        \[\leadsto \left(512 \cdot J + -64 \cdot \color{blue}{\left({K}^{2} \cdot J\right)}\right) + U \]
      3. associate-*r*68.4%

        \[\leadsto \left(512 \cdot J + \color{blue}{\left(-64 \cdot {K}^{2}\right) \cdot J}\right) + U \]
      4. distribute-rgt-out68.4%

        \[\leadsto \color{blue}{J \cdot \left(512 + -64 \cdot {K}^{2}\right)} + U \]
      5. *-commutative68.4%

        \[\leadsto J \cdot \left(512 + \color{blue}{{K}^{2} \cdot -64}\right) + U \]
      6. unpow268.4%

        \[\leadsto J \cdot \left(512 + \color{blue}{\left(K \cdot K\right)} \cdot -64\right) + U \]
      7. associate-*l*68.4%

        \[\leadsto J \cdot \left(512 + \color{blue}{K \cdot \left(K \cdot -64\right)}\right) + U \]
    5. Simplified68.4%

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

    if -1.3e9 < l < 2.2999999999999998e-31

    1. Initial program 72.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.55 \cdot 10^{+55}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -7.5 \cdot 10^{+20}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\right)\\ \mathbf{elif}\;\ell \leq -1300000000:\\ \;\;\;\;U + J \cdot \left(512 + K \cdot \left(K \cdot -64\right)\right)\\ \mathbf{elif}\;\ell \leq 2.3 \cdot 10^{-31}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \end{array} \]

Alternative 8: 72.3% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{if}\;\ell \leq -1.6 \cdot 10^{+55}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -1.46 \cdot 10^{+20}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\right)\\ \mathbf{elif}\;\ell \leq 2.3 \cdot 10^{-31}:\\ \;\;\;\;\mathsf{fma}\left(J \cdot 2, \ell, U\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* 0.3333333333333333 (* J (pow l 3.0))))))
   (if (<= l -1.6e+55)
     t_0
     (if (<= l -1.46e+20)
       (+ U (* l (* J (+ 2.0 (* (* K K) -0.25)))))
       (if (<= l 2.3e-31) (fma (* J 2.0) l U) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (0.3333333333333333 * (J * pow(l, 3.0)));
	double tmp;
	if (l <= -1.6e+55) {
		tmp = t_0;
	} else if (l <= -1.46e+20) {
		tmp = U + (l * (J * (2.0 + ((K * K) * -0.25))));
	} else if (l <= 2.3e-31) {
		tmp = fma((J * 2.0), l, U);
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))))
	tmp = 0.0
	if (l <= -1.6e+55)
		tmp = t_0;
	elseif (l <= -1.46e+20)
		tmp = Float64(U + Float64(l * Float64(J * Float64(2.0 + Float64(Float64(K * K) * -0.25)))));
	elseif (l <= 2.3e-31)
		tmp = fma(Float64(J * 2.0), l, U);
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.6e+55], t$95$0, If[LessEqual[l, -1.46e+20], N[(U + N[(l * N[(J * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.3e-31], N[(N[(J * 2.0), $MachinePrecision] * l + U), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\mathbf{if}\;\ell \leq -1.6 \cdot 10^{+55}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -1.46 \cdot 10^{+20}:\\
\;\;\;\;U + \ell \cdot \left(J \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\right)\\

\mathbf{elif}\;\ell \leq 2.3 \cdot 10^{-31}:\\
\;\;\;\;\mathsf{fma}\left(J \cdot 2, \ell, U\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.6000000000000001e55 or 2.2999999999999998e-31 < 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. Taylor expanded in J around 0 100.0%

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
    3. Step-by-step derivation
      1. associate-*r*100.0%

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

        \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    4. Simplified100.0%

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    5. Taylor expanded in K around 0 77.8%

      \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \color{blue}{J} + U \]
    6. Taylor expanded in l around 0 62.7%

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

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

    if -1.6000000000000001e55 < l < -1.46e20

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.46e20 < l < 2.2999999999999998e-31

    1. Initial program 72.9%

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

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

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

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

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
      3. fma-def84.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot J, \ell, U\right)} \]
      4. *-commutative84.5%

        \[\leadsto \mathsf{fma}\left(\color{blue}{J \cdot 2}, \ell, U\right) \]
    5. Simplified84.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.6 \cdot 10^{+55}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -1.46 \cdot 10^{+20}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\right)\\ \mathbf{elif}\;\ell \leq 2.3 \cdot 10^{-31}:\\ \;\;\;\;\mathsf{fma}\left(J \cdot 2, \ell, U\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \end{array} \]

Alternative 9: 56.2% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -8.4 \cdot 10^{+215}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{elif}\;\ell \leq -6 \cdot 10^{+152}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -1100:\\ \;\;\;\;-8 - U \cdot U\\ \mathbf{elif}\;\ell \leq 2.45 \cdot 10^{+27}:\\ \;\;\;\;\mathsf{fma}\left(J \cdot 2, \ell, U\right)\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -8.4e+215)
   (+ U (* 2.0 (* l J)))
   (if (<= l -6e+152)
     (* U U)
     (if (<= l -1100.0)
       (- -8.0 (* U U))
       (if (<= l 2.45e+27)
         (fma (* J 2.0) l U)
         (+ U (* l (* J (+ 2.0 (* (* K K) -0.25))))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -8.4e+215) {
		tmp = U + (2.0 * (l * J));
	} else if (l <= -6e+152) {
		tmp = U * U;
	} else if (l <= -1100.0) {
		tmp = -8.0 - (U * U);
	} else if (l <= 2.45e+27) {
		tmp = fma((J * 2.0), l, U);
	} else {
		tmp = U + (l * (J * (2.0 + ((K * K) * -0.25))));
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -8.4e+215)
		tmp = Float64(U + Float64(2.0 * Float64(l * J)));
	elseif (l <= -6e+152)
		tmp = Float64(U * U);
	elseif (l <= -1100.0)
		tmp = Float64(-8.0 - Float64(U * U));
	elseif (l <= 2.45e+27)
		tmp = fma(Float64(J * 2.0), l, U);
	else
		tmp = Float64(U + Float64(l * Float64(J * Float64(2.0 + Float64(Float64(K * K) * -0.25)))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, -8.4e+215], N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -6e+152], N[(U * U), $MachinePrecision], If[LessEqual[l, -1100.0], N[(-8.0 - N[(U * U), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.45e+27], N[(N[(J * 2.0), $MachinePrecision] * l + U), $MachinePrecision], N[(U + N[(l * N[(J * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -6 \cdot 10^{+152}:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq -1100:\\
\;\;\;\;-8 - U \cdot U\\

\mathbf{elif}\;\ell \leq 2.45 \cdot 10^{+27}:\\
\;\;\;\;\mathsf{fma}\left(J \cdot 2, \ell, U\right)\\

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


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

    1. Initial program 100.0%

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

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

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

    if -8.4000000000000007e215 < l < -5.99999999999999981e152

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Applied egg-rr64.5%

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

    if -5.99999999999999981e152 < l < -1100

    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-def100.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. Applied egg-rr26.9%

      \[\leadsto \color{blue}{-8 + \left(-U\right) \cdot U} \]
    5. Step-by-step derivation
      1. cancel-sign-sub-inv26.9%

        \[\leadsto \color{blue}{-8 - U \cdot U} \]
    6. Simplified26.9%

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

    if -1100 < l < 2.45000000000000007e27

    1. Initial program 73.5%

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

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

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

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

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
      3. fma-def85.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot J, \ell, U\right)} \]
      4. *-commutative85.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{J \cdot 2}, \ell, U\right) \]
    5. Simplified85.8%

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

    if 2.45000000000000007e27 < 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. Taylor expanded in l around 0 26.8%

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

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

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

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

        \[\leadsto U + \left(\left(-0.25 \cdot \left(J \cdot {K}^{2}\right)\right) \cdot \ell + \color{blue}{\left(2 \cdot J\right) \cdot \ell}\right) \]
      4. distribute-rgt-out43.1%

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

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

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

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

        \[\leadsto U + \ell \cdot \left(J \cdot \left(-0.25 \cdot \color{blue}{\left(K \cdot K\right)} + 2\right)\right) \]
    5. Simplified43.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -8.4 \cdot 10^{+215}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{elif}\;\ell \leq -6 \cdot 10^{+152}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -1100:\\ \;\;\;\;-8 - U \cdot U\\ \mathbf{elif}\;\ell \leq 2.45 \cdot 10^{+27}:\\ \;\;\;\;\mathsf{fma}\left(J \cdot 2, \ell, U\right)\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\right)\\ \end{array} \]

Alternative 10: 56.2% accurate, 14.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{if}\;\ell \leq -5.6 \cdot 10^{+215}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -4.4 \cdot 10^{+153}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -1100:\\ \;\;\;\;-8 - U \cdot U\\ \mathbf{elif}\;\ell \leq 4.6 \cdot 10^{+28}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* 2.0 (* l J)))))
   (if (<= l -5.6e+215)
     t_0
     (if (<= l -4.4e+153)
       (* U U)
       (if (<= l -1100.0)
         (- -8.0 (* U U))
         (if (<= l 4.6e+28)
           t_0
           (+ U (* l (* J (+ 2.0 (* (* K K) -0.25)))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (l * J));
	double tmp;
	if (l <= -5.6e+215) {
		tmp = t_0;
	} else if (l <= -4.4e+153) {
		tmp = U * U;
	} else if (l <= -1100.0) {
		tmp = -8.0 - (U * U);
	} else if (l <= 4.6e+28) {
		tmp = t_0;
	} else {
		tmp = U + (l * (J * (2.0 + ((K * K) * -0.25))));
	}
	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 + (2.0d0 * (l * j))
    if (l <= (-5.6d+215)) then
        tmp = t_0
    else if (l <= (-4.4d+153)) then
        tmp = u * u
    else if (l <= (-1100.0d0)) then
        tmp = (-8.0d0) - (u * u)
    else if (l <= 4.6d+28) then
        tmp = t_0
    else
        tmp = u + (l * (j * (2.0d0 + ((k * k) * (-0.25d0)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (l * J));
	double tmp;
	if (l <= -5.6e+215) {
		tmp = t_0;
	} else if (l <= -4.4e+153) {
		tmp = U * U;
	} else if (l <= -1100.0) {
		tmp = -8.0 - (U * U);
	} else if (l <= 4.6e+28) {
		tmp = t_0;
	} else {
		tmp = U + (l * (J * (2.0 + ((K * K) * -0.25))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (2.0 * (l * J))
	tmp = 0
	if l <= -5.6e+215:
		tmp = t_0
	elif l <= -4.4e+153:
		tmp = U * U
	elif l <= -1100.0:
		tmp = -8.0 - (U * U)
	elif l <= 4.6e+28:
		tmp = t_0
	else:
		tmp = U + (l * (J * (2.0 + ((K * K) * -0.25))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(2.0 * Float64(l * J)))
	tmp = 0.0
	if (l <= -5.6e+215)
		tmp = t_0;
	elseif (l <= -4.4e+153)
		tmp = Float64(U * U);
	elseif (l <= -1100.0)
		tmp = Float64(-8.0 - Float64(U * U));
	elseif (l <= 4.6e+28)
		tmp = t_0;
	else
		tmp = Float64(U + Float64(l * Float64(J * Float64(2.0 + Float64(Float64(K * K) * -0.25)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (2.0 * (l * J));
	tmp = 0.0;
	if (l <= -5.6e+215)
		tmp = t_0;
	elseif (l <= -4.4e+153)
		tmp = U * U;
	elseif (l <= -1100.0)
		tmp = -8.0 - (U * U);
	elseif (l <= 4.6e+28)
		tmp = t_0;
	else
		tmp = U + (l * (J * (2.0 + ((K * K) * -0.25))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5.6e+215], t$95$0, If[LessEqual[l, -4.4e+153], N[(U * U), $MachinePrecision], If[LessEqual[l, -1100.0], N[(-8.0 - N[(U * U), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 4.6e+28], t$95$0, N[(U + N[(l * N[(J * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + 2 \cdot \left(\ell \cdot J\right)\\
\mathbf{if}\;\ell \leq -5.6 \cdot 10^{+215}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -4.4 \cdot 10^{+153}:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq -1100:\\
\;\;\;\;-8 - U \cdot U\\

\mathbf{elif}\;\ell \leq 4.6 \cdot 10^{+28}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -5.5999999999999999e215 or -1100 < l < 4.59999999999999968e28

    1. Initial program 76.7%

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

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

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

    if -5.5999999999999999e215 < l < -4.3999999999999999e153

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Applied egg-rr64.5%

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

    if -4.3999999999999999e153 < l < -1100

    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-def100.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. Applied egg-rr26.9%

      \[\leadsto \color{blue}{-8 + \left(-U\right) \cdot U} \]
    5. Step-by-step derivation
      1. cancel-sign-sub-inv26.9%

        \[\leadsto \color{blue}{-8 - U \cdot U} \]
    6. Simplified26.9%

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

    if 4.59999999999999968e28 < 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. Taylor expanded in l around 0 26.8%

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

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

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

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

        \[\leadsto U + \left(\left(-0.25 \cdot \left(J \cdot {K}^{2}\right)\right) \cdot \ell + \color{blue}{\left(2 \cdot J\right) \cdot \ell}\right) \]
      4. distribute-rgt-out43.1%

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

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

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

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

        \[\leadsto U + \ell \cdot \left(J \cdot \left(-0.25 \cdot \color{blue}{\left(K \cdot K\right)} + 2\right)\right) \]
    5. Simplified43.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.6 \cdot 10^{+215}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{elif}\;\ell \leq -4.4 \cdot 10^{+153}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -1100:\\ \;\;\;\;-8 - U \cdot U\\ \mathbf{elif}\;\ell \leq 4.6 \cdot 10^{+28}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\right)\\ \end{array} \]

Alternative 11: 52.9% accurate, 16.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{if}\;\ell \leq -5.6 \cdot 10^{+215}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -5.2 \cdot 10^{+155}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -1200:\\ \;\;\;\;-8 - U \cdot U\\ \mathbf{elif}\;\ell \leq 3.8 \cdot 10^{+32}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(K \cdot K\right)\right) \cdot \left(\ell \cdot -0.25\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* 2.0 (* l J)))))
   (if (<= l -5.6e+215)
     t_0
     (if (<= l -5.2e+155)
       (* U U)
       (if (<= l -1200.0)
         (- -8.0 (* U U))
         (if (<= l 3.8e+32) t_0 (+ U (* (* J (* K K)) (* l -0.25)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (l * J));
	double tmp;
	if (l <= -5.6e+215) {
		tmp = t_0;
	} else if (l <= -5.2e+155) {
		tmp = U * U;
	} else if (l <= -1200.0) {
		tmp = -8.0 - (U * U);
	} else if (l <= 3.8e+32) {
		tmp = t_0;
	} else {
		tmp = U + ((J * (K * K)) * (l * -0.25));
	}
	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 + (2.0d0 * (l * j))
    if (l <= (-5.6d+215)) then
        tmp = t_0
    else if (l <= (-5.2d+155)) then
        tmp = u * u
    else if (l <= (-1200.0d0)) then
        tmp = (-8.0d0) - (u * u)
    else if (l <= 3.8d+32) then
        tmp = t_0
    else
        tmp = u + ((j * (k * k)) * (l * (-0.25d0)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (l * J));
	double tmp;
	if (l <= -5.6e+215) {
		tmp = t_0;
	} else if (l <= -5.2e+155) {
		tmp = U * U;
	} else if (l <= -1200.0) {
		tmp = -8.0 - (U * U);
	} else if (l <= 3.8e+32) {
		tmp = t_0;
	} else {
		tmp = U + ((J * (K * K)) * (l * -0.25));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (2.0 * (l * J))
	tmp = 0
	if l <= -5.6e+215:
		tmp = t_0
	elif l <= -5.2e+155:
		tmp = U * U
	elif l <= -1200.0:
		tmp = -8.0 - (U * U)
	elif l <= 3.8e+32:
		tmp = t_0
	else:
		tmp = U + ((J * (K * K)) * (l * -0.25))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(2.0 * Float64(l * J)))
	tmp = 0.0
	if (l <= -5.6e+215)
		tmp = t_0;
	elseif (l <= -5.2e+155)
		tmp = Float64(U * U);
	elseif (l <= -1200.0)
		tmp = Float64(-8.0 - Float64(U * U));
	elseif (l <= 3.8e+32)
		tmp = t_0;
	else
		tmp = Float64(U + Float64(Float64(J * Float64(K * K)) * Float64(l * -0.25)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (2.0 * (l * J));
	tmp = 0.0;
	if (l <= -5.6e+215)
		tmp = t_0;
	elseif (l <= -5.2e+155)
		tmp = U * U;
	elseif (l <= -1200.0)
		tmp = -8.0 - (U * U);
	elseif (l <= 3.8e+32)
		tmp = t_0;
	else
		tmp = U + ((J * (K * K)) * (l * -0.25));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5.6e+215], t$95$0, If[LessEqual[l, -5.2e+155], N[(U * U), $MachinePrecision], If[LessEqual[l, -1200.0], N[(-8.0 - N[(U * U), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 3.8e+32], t$95$0, N[(U + N[(N[(J * N[(K * K), $MachinePrecision]), $MachinePrecision] * N[(l * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + 2 \cdot \left(\ell \cdot J\right)\\
\mathbf{if}\;\ell \leq -5.6 \cdot 10^{+215}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -5.2 \cdot 10^{+155}:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq -1200:\\
\;\;\;\;-8 - U \cdot U\\

\mathbf{elif}\;\ell \leq 3.8 \cdot 10^{+32}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -5.5999999999999999e215 or -1200 < l < 3.8000000000000003e32

    1. Initial program 76.9%

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

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

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

    if -5.5999999999999999e215 < l < -5.2000000000000004e155

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Applied egg-rr64.5%

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

    if -5.2000000000000004e155 < l < -1200

    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-def100.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. Applied egg-rr26.9%

      \[\leadsto \color{blue}{-8 + \left(-U\right) \cdot U} \]
    5. Step-by-step derivation
      1. cancel-sign-sub-inv26.9%

        \[\leadsto \color{blue}{-8 - U \cdot U} \]
    6. Simplified26.9%

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

    if 3.8000000000000003e32 < 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. Taylor expanded in l around 0 27.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto U + \left(J \cdot \color{blue}{\left(K \cdot K\right)}\right) \cdot \left(\ell \cdot -0.25\right) \]
    8. Simplified34.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.6 \cdot 10^{+215}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{elif}\;\ell \leq -5.2 \cdot 10^{+155}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -1200:\\ \;\;\;\;-8 - U \cdot U\\ \mathbf{elif}\;\ell \leq 3.8 \cdot 10^{+32}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(K \cdot K\right)\right) \cdot \left(\ell \cdot -0.25\right)\\ \end{array} \]

Alternative 12: 43.3% accurate, 23.5× speedup?

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

\\
\begin{array}{l}
t_0 := U \cdot \left(U \cdot -8\right)\\
\mathbf{if}\;\ell \leq -3.6 \cdot 10^{+154}:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq -1000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq 1100:\\
\;\;\;\;U\\

\mathbf{elif}\;\ell \leq 1.35 \cdot 10^{+78}:\\
\;\;\;\;U \cdot U\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.6000000000000001e154 or 1100 < l < 1.35000000000000002e78

    1. Initial program 100.0%

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

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

    if -3.6000000000000001e154 < l < -1e3 or 1.35000000000000002e78 < 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. Taylor expanded in J around 0 100.0%

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
    3. Step-by-step derivation
      1. associate-*r*100.0%

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

        \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    4. Simplified100.0%

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    5. Taylor expanded in K around 0 71.8%

      \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \color{blue}{J} + U \]
    6. Applied egg-rr22.8%

      \[\leadsto \color{blue}{\left(U \cdot -8\right) \cdot U} \]

    if -1e3 < l < 1100

    1. Initial program 72.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.6 \cdot 10^{+154}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -1000:\\ \;\;\;\;U \cdot \left(U \cdot -8\right)\\ \mathbf{elif}\;\ell \leq 1100:\\ \;\;\;\;U\\ \mathbf{elif}\;\ell \leq 1.35 \cdot 10^{+78}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(U \cdot -8\right)\\ \end{array} \]

Alternative 13: 43.3% accurate, 23.5× speedup?

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

\\
\begin{array}{l}
t_0 := -8 - U \cdot U\\
\mathbf{if}\;\ell \leq -8.5 \cdot 10^{+155}:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq -480:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq 2300:\\
\;\;\;\;U\\

\mathbf{elif}\;\ell \leq 6.6 \cdot 10^{+81}:\\
\;\;\;\;U \cdot U\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -8.5000000000000002e155 or 2300 < l < 6.6e81

    1. Initial program 100.0%

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

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

    if -8.5000000000000002e155 < l < -480 or 6.6e81 < 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-def100.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. Applied egg-rr23.2%

      \[\leadsto \color{blue}{-8 + \left(-U\right) \cdot U} \]
    5. Step-by-step derivation
      1. cancel-sign-sub-inv23.2%

        \[\leadsto \color{blue}{-8 - U \cdot U} \]
    6. Simplified23.2%

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

    if -480 < l < 2300

    1. Initial program 72.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -8.5 \cdot 10^{+155}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -480:\\ \;\;\;\;-8 - U \cdot U\\ \mathbf{elif}\;\ell \leq 2300:\\ \;\;\;\;U\\ \mathbf{elif}\;\ell \leq 6.6 \cdot 10^{+81}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;-8 - U \cdot U\\ \end{array} \]

Alternative 14: 43.3% accurate, 23.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -2.5 \cdot 10^{+155}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -780:\\ \;\;\;\;-8 - U \cdot U\\ \mathbf{elif}\;\ell \leq 600:\\ \;\;\;\;U\\ \mathbf{elif}\;\ell \leq 1.95 \cdot 10^{+82}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(2 - U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -2.5e+155)
   (* U U)
   (if (<= l -780.0)
     (- -8.0 (* U U))
     (if (<= l 600.0) U (if (<= l 1.95e+82) (* U U) (* U (- 2.0 U)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -2.5e+155) {
		tmp = U * U;
	} else if (l <= -780.0) {
		tmp = -8.0 - (U * U);
	} else if (l <= 600.0) {
		tmp = U;
	} else if (l <= 1.95e+82) {
		tmp = U * U;
	} else {
		tmp = U * (2.0 - 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.5d+155)) then
        tmp = u * u
    else if (l <= (-780.0d0)) then
        tmp = (-8.0d0) - (u * u)
    else if (l <= 600.0d0) then
        tmp = u
    else if (l <= 1.95d+82) then
        tmp = u * u
    else
        tmp = u * (2.0d0 - u)
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -2.5e+155) {
		tmp = U * U;
	} else if (l <= -780.0) {
		tmp = -8.0 - (U * U);
	} else if (l <= 600.0) {
		tmp = U;
	} else if (l <= 1.95e+82) {
		tmp = U * U;
	} else {
		tmp = U * (2.0 - U);
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -2.5e+155:
		tmp = U * U
	elif l <= -780.0:
		tmp = -8.0 - (U * U)
	elif l <= 600.0:
		tmp = U
	elif l <= 1.95e+82:
		tmp = U * U
	else:
		tmp = U * (2.0 - U)
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -2.5e+155)
		tmp = Float64(U * U);
	elseif (l <= -780.0)
		tmp = Float64(-8.0 - Float64(U * U));
	elseif (l <= 600.0)
		tmp = U;
	elseif (l <= 1.95e+82)
		tmp = Float64(U * U);
	else
		tmp = Float64(U * Float64(2.0 - U));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -2.5e+155)
		tmp = U * U;
	elseif (l <= -780.0)
		tmp = -8.0 - (U * U);
	elseif (l <= 600.0)
		tmp = U;
	elseif (l <= 1.95e+82)
		tmp = U * U;
	else
		tmp = U * (2.0 - U);
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -2.5e+155], N[(U * U), $MachinePrecision], If[LessEqual[l, -780.0], N[(-8.0 - N[(U * U), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 600.0], U, If[LessEqual[l, 1.95e+82], N[(U * U), $MachinePrecision], N[(U * N[(2.0 - U), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.5 \cdot 10^{+155}:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq -780:\\
\;\;\;\;-8 - U \cdot U\\

\mathbf{elif}\;\ell \leq 600:\\
\;\;\;\;U\\

\mathbf{elif}\;\ell \leq 1.95 \cdot 10^{+82}:\\
\;\;\;\;U \cdot U\\

\mathbf{else}:\\
\;\;\;\;U \cdot \left(2 - U\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -2.5e155 or 600 < l < 1.94999999999999988e82

    1. Initial program 100.0%

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

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

    if -2.5e155 < l < -780

    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-def100.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. Applied egg-rr26.9%

      \[\leadsto \color{blue}{-8 + \left(-U\right) \cdot U} \]
    5. Step-by-step derivation
      1. cancel-sign-sub-inv26.9%

        \[\leadsto \color{blue}{-8 - U \cdot U} \]
    6. Simplified26.9%

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

    if -780 < l < 600

    1. Initial program 72.5%

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

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

    if 1.94999999999999988e82 < 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-def100.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. Applied egg-rr19.9%

      \[\leadsto \color{blue}{U + \mathsf{fma}\left(-U, U, U\right)} \]
    5. Step-by-step derivation
      1. fma-udef19.9%

        \[\leadsto U + \color{blue}{\left(\left(-U\right) \cdot U + U\right)} \]
      2. +-commutative19.9%

        \[\leadsto U + \color{blue}{\left(U + \left(-U\right) \cdot U\right)} \]
      3. associate-+r+19.9%

        \[\leadsto \color{blue}{\left(U + U\right) + \left(-U\right) \cdot U} \]
      4. count-219.9%

        \[\leadsto \color{blue}{2 \cdot U} + \left(-U\right) \cdot U \]
      5. distribute-rgt-out19.9%

        \[\leadsto \color{blue}{U \cdot \left(2 + \left(-U\right)\right)} \]
    6. Simplified19.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.5 \cdot 10^{+155}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -780:\\ \;\;\;\;-8 - U \cdot U\\ \mathbf{elif}\;\ell \leq 600:\\ \;\;\;\;U\\ \mathbf{elif}\;\ell \leq 1.95 \cdot 10^{+82}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(2 - U\right)\\ \end{array} \]

Alternative 15: 43.2% accurate, 43.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -180000:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 800:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -180000.0) (* U U) (if (<= l 800.0) U (* U U))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -180000.0) {
		tmp = U * U;
	} else if (l <= 800.0) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (l <= (-180000.0d0)) then
        tmp = u * u
    else if (l <= 800.0d0) then
        tmp = u
    else
        tmp = u * u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -180000.0) {
		tmp = U * U;
	} else if (l <= 800.0) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -180000.0:
		tmp = U * U
	elif l <= 800.0:
		tmp = U
	else:
		tmp = U * U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -180000.0)
		tmp = Float64(U * U);
	elseif (l <= 800.0)
		tmp = U;
	else
		tmp = Float64(U * U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -180000.0)
		tmp = U * U;
	elseif (l <= 800.0)
		tmp = U;
	else
		tmp = U * U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -180000.0], N[(U * U), $MachinePrecision], If[LessEqual[l, 800.0], U, N[(U * U), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -180000:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq 800:\\
\;\;\;\;U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.8e5 or 800 < 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. Applied egg-rr17.8%

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

    if -1.8e5 < l < 800

    1. Initial program 72.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -180000:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 800:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]

Alternative 16: 54.6% accurate, 44.6× speedup?

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

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

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

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

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

    \[\leadsto U + 2 \cdot \left(\ell \cdot J\right) \]

Alternative 17: 2.8% accurate, 312.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (J l K U) :precision binary64 1.0)
double code(double J, double l, double K, double U) {
	return 1.0;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = 1.0d0
end function
public static double code(double J, double l, double K, double U) {
	return 1.0;
}
def code(J, l, K, U):
	return 1.0
function code(J, l, K, U)
	return 1.0
end
function tmp = code(J, l, K, U)
	tmp = 1.0;
end
code[J_, l_, K_, U_] := 1.0
\begin{array}{l}

\\
1
\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. Applied egg-rr2.9%

    \[\leadsto \color{blue}{\frac{U}{U}} \]
  3. Step-by-step derivation
    1. *-inverses2.9%

      \[\leadsto \color{blue}{1} \]
  4. Simplified2.9%

    \[\leadsto \color{blue}{1} \]
  5. Final simplification2.9%

    \[\leadsto 1 \]

Alternative 18: 37.4% 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. Taylor expanded in J around 0 35.8%

    \[\leadsto \color{blue}{U} \]
  3. Final simplification35.8%

    \[\leadsto U \]

Reproduce

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