Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.7% → 99.7%
Time: 10.7s
Alternatives: 19
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 19 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.7% 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 -\infty:\\ \;\;\;\;\left(t\_1 \cdot J\right) \cdot t\_0 + U\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-7}:\\ \;\;\;\;U + t\_0 \cdot \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right) + J \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, t\_1 \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 (<= t_1 (- INFINITY))
     (+ (* (* t_1 J) t_0) U)
     (if (<= t_1 2e-7)
       (+
        U
        (* t_0 (* l (+ (* 0.3333333333333333 (* J (pow l 2.0))) (* J 2.0)))))
       (fma J (* t_1 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 <= -((double) INFINITY)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else if (t_1 <= 2e-7) {
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * pow(l, 2.0))) + (J * 2.0))));
	} else {
		tmp = fma(J, (t_1 * 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 <= Float64(-Inf))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	elseif (t_1 <= 2e-7)
		tmp = Float64(U + Float64(t_0 * Float64(l * Float64(Float64(0.3333333333333333 * Float64(J * (l ^ 2.0))) + Float64(J * 2.0)))));
	else
		tmp = fma(J, Float64(t_1 * 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[LessEqual[t$95$1, (-Infinity)], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[t$95$1, 2e-7], N[(U + N[(t$95$0 * N[(l * N[(N[(0.3333333333333333 * N[(J * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(J * N[(t$95$1 * 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 -\infty:\\
\;\;\;\;\left(t\_1 \cdot J\right) \cdot t\_0 + U\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J, t\_1 \cdot t\_0, U\right)\\


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

    1. Initial program 100.0%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1.9999999999999999e-7

    1. Initial program 66.6%

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

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

    if 1.9999999999999999e-7 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 98.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*98.3%

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

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

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

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

Alternative 2: 99.7% 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 -\infty \lor \neg \left(t\_1 \leq 2 \cdot 10^{-7}\right):\\ \;\;\;\;\left(t\_1 \cdot J\right) \cdot t\_0 + U\\ \mathbf{else}:\\ \;\;\;\;U + t\_0 \cdot \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right) + J \cdot 2\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
   (if (or (<= t_1 (- INFINITY)) (not (<= t_1 2e-7)))
     (+ (* (* t_1 J) t_0) U)
     (+
      U
      (* t_0 (* l (+ (* 0.3333333333333333 (* J (pow l 2.0))) (* J 2.0))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = exp(l) - exp(-l);
	double tmp;
	if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 2e-7)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * pow(l, 2.0))) + (J * 2.0))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 2e-7)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * Math.pow(l, 2.0))) + (J * 2.0))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_1 <= -math.inf) or not (t_1 <= 2e-7):
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * math.pow(l, 2.0))) + (J * 2.0))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_1 <= Float64(-Inf)) || !(t_1 <= 2e-7))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(l * Float64(Float64(0.3333333333333333 * Float64(J * (l ^ 2.0))) + Float64(J * 2.0)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_1 <= -Inf) || ~((t_1 <= 2e-7)))
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * (l ^ 2.0))) + (J * 2.0))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 2e-7]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(l * N[(N[(0.3333333333333333 * N[(J * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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


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

    1. Initial program 99.2%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1.9999999999999999e-7

    1. Initial program 66.6%

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

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

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

Alternative 3: 94.3% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -23:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;\ell \leq 3.4 \cdot 10^{+89}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;0.3333333333333333 \cdot \left(t\_0 \cdot \left(J \cdot {\ell}^{3}\right)\right)\\


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

    1. Initial program 100.0%

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

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

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

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

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

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

    if -2.6999999999999999e81 < l < -23 or 840 < l < 3.4000000000000002e89

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{-\ell}\right)} \]
    4. Step-by-step derivation
      1. +-commutative70.6%

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

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

    if -23 < l < 840

    1. Initial program 66.9%

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

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

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

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

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

    if 3.4000000000000002e89 < l

    1. Initial program 100.0%

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

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

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot 2 + \ell \cdot \left(0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. distribute-rgt-in100.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{U \cdot \left(1 + \frac{\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(J \cdot \ell\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. *-rgt-identity100.0%

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

        \[\leadsto U \cdot \left(\left(1 + \frac{\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(J \cdot \ell\right)\right)}{U}\right) \cdot \color{blue}{\left(--1\right)}\right) \]
      3. distribute-rgt-neg-in100.0%

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

        \[\leadsto U \cdot \left(-\color{blue}{\left(\frac{\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(J \cdot \ell\right)\right)}{U} + 1\right)} \cdot -1\right) \]
      5. distribute-lft1-in100.0%

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

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

        \[\leadsto U \cdot \left(-\left(-1 \cdot \frac{\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(J \cdot \ell\right)\right)}{U} + \color{blue}{\left(-1\right)}\right)\right) \]
      8. sub-neg100.0%

        \[\leadsto U \cdot \left(-\color{blue}{\left(-1 \cdot \frac{\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(J \cdot \ell\right)\right)}{U} - 1\right)}\right) \]
    8. Simplified100.0%

      \[\leadsto \color{blue}{U \cdot \left(1 + \cos \left(0.5 \cdot K\right) \cdot \frac{\mathsf{fma}\left(0.3333333333333333, J \cdot {\ell}^{3}, J \cdot \left(\ell \cdot 2\right)\right)}{U}\right)} \]
    9. Taylor expanded in l around inf 100.0%

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

        \[\leadsto 0.3333333333333333 \cdot \color{blue}{\left(\left(J \cdot {\ell}^{3}\right) \cdot \cos \left(0.5 \cdot K\right)\right)} \]
    11. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.7 \cdot 10^{+81}:\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot \left({\ell}^{3} \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq -23:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 840:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 3.4 \cdot 10^{+89}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;0.3333333333333333 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 94.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ t_1 := 0.3333333333333333 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \mathbf{if}\;\ell \leq -2.7 \cdot 10^{+81}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -23:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 750:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 1.55 \cdot 10^{+88}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ (* (- (exp l) (exp (- l))) J) U))
        (t_1 (* 0.3333333333333333 (* (cos (* K 0.5)) (* J (pow l 3.0))))))
   (if (<= l -2.7e+81)
     t_1
     (if (<= l -23.0)
       t_0
       (if (<= l 750.0)
         (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))
         (if (<= l 1.55e+88) t_0 t_1))))))
double code(double J, double l, double K, double U) {
	double t_0 = ((exp(l) - exp(-l)) * J) + U;
	double t_1 = 0.3333333333333333 * (cos((K * 0.5)) * (J * pow(l, 3.0)));
	double tmp;
	if (l <= -2.7e+81) {
		tmp = t_1;
	} else if (l <= -23.0) {
		tmp = t_0;
	} else if (l <= 750.0) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 1.55e+88) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((exp(l) - exp(-l)) * j) + u
    t_1 = 0.3333333333333333d0 * (cos((k * 0.5d0)) * (j * (l ** 3.0d0)))
    if (l <= (-2.7d+81)) then
        tmp = t_1
    else if (l <= (-23.0d0)) then
        tmp = t_0
    else if (l <= 750.0d0) then
        tmp = u + (cos((k / 2.0d0)) * (j * (l * 2.0d0)))
    else if (l <= 1.55d+88) then
        tmp = t_0
    else
        tmp = t_1
    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)) * J) + U;
	double t_1 = 0.3333333333333333 * (Math.cos((K * 0.5)) * (J * Math.pow(l, 3.0)));
	double tmp;
	if (l <= -2.7e+81) {
		tmp = t_1;
	} else if (l <= -23.0) {
		tmp = t_0;
	} else if (l <= 750.0) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 1.55e+88) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = ((math.exp(l) - math.exp(-l)) * J) + U
	t_1 = 0.3333333333333333 * (math.cos((K * 0.5)) * (J * math.pow(l, 3.0)))
	tmp = 0
	if l <= -2.7e+81:
		tmp = t_1
	elif l <= -23.0:
		tmp = t_0
	elif l <= 750.0:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * 2.0)))
	elif l <= 1.55e+88:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U)
	t_1 = Float64(0.3333333333333333 * Float64(cos(Float64(K * 0.5)) * Float64(J * (l ^ 3.0))))
	tmp = 0.0
	if (l <= -2.7e+81)
		tmp = t_1;
	elseif (l <= -23.0)
		tmp = t_0;
	elseif (l <= 750.0)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	elseif (l <= 1.55e+88)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = ((exp(l) - exp(-l)) * J) + U;
	t_1 = 0.3333333333333333 * (cos((K * 0.5)) * (J * (l ^ 3.0)));
	tmp = 0.0;
	if (l <= -2.7e+81)
		tmp = t_1;
	elseif (l <= -23.0)
		tmp = t_0;
	elseif (l <= 750.0)
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	elseif (l <= 1.55e+88)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision]}, Block[{t$95$1 = N[(0.3333333333333333 * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.7e+81], t$95$1, If[LessEqual[l, -23.0], t$95$0, If[LessEqual[l, 750.0], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.55e+88], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\
t_1 := 0.3333333333333333 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot {\ell}^{3}\right)\right)\\
\mathbf{if}\;\ell \leq -2.7 \cdot 10^{+81}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq -23:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;\ell \leq 1.55 \cdot 10^{+88}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.6999999999999999e81 or 1.5500000000000001e88 < l

    1. Initial program 100.0%

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

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

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot 2 + \ell \cdot \left(0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. distribute-rgt-in98.9%

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

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

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

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

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

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

      \[\leadsto \color{blue}{U \cdot \left(1 + \frac{\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(J \cdot \ell\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. *-rgt-identity98.9%

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

        \[\leadsto U \cdot \left(\left(1 + \frac{\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(J \cdot \ell\right)\right)}{U}\right) \cdot \color{blue}{\left(--1\right)}\right) \]
      3. distribute-rgt-neg-in98.9%

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

        \[\leadsto U \cdot \left(-\color{blue}{\left(\frac{\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(J \cdot \ell\right)\right)}{U} + 1\right)} \cdot -1\right) \]
      5. distribute-lft1-in98.9%

        \[\leadsto U \cdot \left(-\color{blue}{\left(\frac{\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(J \cdot \ell\right)\right)}{U} \cdot -1 + -1\right)}\right) \]
      6. *-commutative98.9%

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

        \[\leadsto U \cdot \left(-\left(-1 \cdot \frac{\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(J \cdot \ell\right)\right)}{U} + \color{blue}{\left(-1\right)}\right)\right) \]
      8. sub-neg98.9%

        \[\leadsto U \cdot \left(-\color{blue}{\left(-1 \cdot \frac{\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(J \cdot \ell\right)\right)}{U} - 1\right)}\right) \]
    8. Simplified98.9%

      \[\leadsto \color{blue}{U \cdot \left(1 + \cos \left(0.5 \cdot K\right) \cdot \frac{\mathsf{fma}\left(0.3333333333333333, J \cdot {\ell}^{3}, J \cdot \left(\ell \cdot 2\right)\right)}{U}\right)} \]
    9. Taylor expanded in l around inf 98.9%

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

        \[\leadsto 0.3333333333333333 \cdot \color{blue}{\left(\left(J \cdot {\ell}^{3}\right) \cdot \cos \left(0.5 \cdot K\right)\right)} \]
    11. Simplified98.9%

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

    if -2.6999999999999999e81 < l < -23 or 750 < l < 1.5500000000000001e88

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{-\ell}\right)} \]
    4. Step-by-step derivation
      1. +-commutative70.6%

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

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

    if -23 < l < 750

    1. Initial program 66.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.7 \cdot 10^{+81}:\\ \;\;\;\;0.3333333333333333 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -23:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 750:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 1.55 \cdot 10^{+88}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;0.3333333333333333 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 90.9% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.9 \cdot 10^{+81}:\\
\;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot \left({\ell}^{3} \cdot \cos \left(K \cdot 0.5\right)\right)\\

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

    if -1.9e81 < l < -23

    1. Initial program 100.0%

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

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

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

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

    if -23 < l

    1. Initial program 76.4%

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

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

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

Alternative 6: 77.6% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 78.8%

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

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

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

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

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

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

    1. Initial program 84.7%

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

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

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot 2 + \ell \cdot \left(0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. distribute-rgt-in89.2%

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

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

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

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

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

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

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

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

Alternative 7: 77.6% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 78.8%

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

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

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

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

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

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

    1. Initial program 84.7%

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

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

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

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

Alternative 8: 86.8% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

    if -23 < l < 750

    1. Initial program 66.9%

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

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

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

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

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

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

Alternative 9: 77.6% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.05 \cdot 10^{+54} \lor \neg \left(\ell \leq 3.5 \cdot 10^{+63}\right):\\
\;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.04999999999999984e54 or 3.50000000000000029e63 < l

    1. Initial program 100.0%

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

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

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

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

    if -2.04999999999999984e54 < l < 3.50000000000000029e63

    1. Initial program 70.8%

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

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

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

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

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

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

Alternative 10: 77.6% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.15 \cdot 10^{+53} \lor \neg \left(\ell \leq 1.9 \cdot 10^{+63}\right):\\
\;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.1499999999999999e53 or 1.9000000000000001e63 < l

    1. Initial program 100.0%

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

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

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

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

    if -2.1499999999999999e53 < l < 1.9000000000000001e63

    1. Initial program 70.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.15 \cdot 10^{+53} \lor \neg \left(\ell \leq 1.9 \cdot 10^{+63}\right):\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 71.1% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.1 \cdot 10^{+53} \lor \neg \left(\ell \leq 740\right):\\
\;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.1000000000000002e53 or 740 < l

    1. Initial program 99.2%

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

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

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

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

    if -2.1000000000000002e53 < l < 740

    1. Initial program 69.2%

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

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

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
    5. Taylor expanded in l around 0 77.6%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.1 \cdot 10^{+53} \lor \neg \left(\ell \leq 740\right):\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot 2, U\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 52.2% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;K \leq 1.06 \cdot 10^{+189} \lor \neg \left(K \leq 1.6 \cdot 10^{+256}\right):\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;{K}^{2} \cdot 32\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 1.05999999999999998e189 or 1.59999999999999998e256 < K

    1. Initial program 82.8%

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

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

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
    5. Taylor expanded in l around 0 54.3%

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

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

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

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

    if 1.05999999999999998e189 < K < 1.59999999999999998e256

    1. Initial program 85.7%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(-4, \cos \left(-4 \cdot K\right), -U\right)} \]
    4. Step-by-step derivation
      1. fma-neg2.3%

        \[\leadsto \color{blue}{-4 \cdot \cos \left(-4 \cdot K\right) - U} \]
      2. *-commutative2.3%

        \[\leadsto -4 \cdot \cos \color{blue}{\left(K \cdot -4\right)} - U \]
    5. Simplified2.3%

      \[\leadsto \color{blue}{-4 \cdot \cos \left(K \cdot -4\right) - U} \]
    6. Taylor expanded in K around 0 46.5%

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

      \[\leadsto \color{blue}{32 \cdot {K}^{2}} \]
    8. Step-by-step derivation
      1. *-commutative46.5%

        \[\leadsto \color{blue}{{K}^{2} \cdot 32} \]
    9. Simplified46.5%

      \[\leadsto \color{blue}{{K}^{2} \cdot 32} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification53.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 1.06 \cdot 10^{+189} \lor \neg \left(K \leq 1.6 \cdot 10^{+256}\right):\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;{K}^{2} \cdot 32\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 52.3% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;K \leq 8.5 \cdot 10^{+188}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot 2, U\right)\\ \mathbf{elif}\;K \leq 4.6 \cdot 10^{+255}:\\ \;\;\;\;{K}^{2} \cdot 32\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= K 8.5e+188)
   (fma J (* l 2.0) U)
   (if (<= K 4.6e+255) (* (pow K 2.0) 32.0) (+ U (* l (* J 2.0))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (K <= 8.5e+188) {
		tmp = fma(J, (l * 2.0), U);
	} else if (K <= 4.6e+255) {
		tmp = pow(K, 2.0) * 32.0;
	} else {
		tmp = U + (l * (J * 2.0));
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (K <= 8.5e+188)
		tmp = fma(J, Float64(l * 2.0), U);
	elseif (K <= 4.6e+255)
		tmp = Float64((K ^ 2.0) * 32.0);
	else
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[K, 8.5e+188], N[(J * N[(l * 2.0), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[K, 4.6e+255], N[(N[Power[K, 2.0], $MachinePrecision] * 32.0), $MachinePrecision], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;K \leq 8.5 \cdot 10^{+188}:\\
\;\;\;\;\mathsf{fma}\left(J, \ell \cdot 2, U\right)\\

\mathbf{elif}\;K \leq 4.6 \cdot 10^{+255}:\\
\;\;\;\;{K}^{2} \cdot 32\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if K < 8.49999999999999958e188

    1. Initial program 83.3%

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

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

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
    5. Taylor expanded in l around 0 54.2%

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

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

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

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

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

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

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

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

    if 8.49999999999999958e188 < K < 4.6000000000000001e255

    1. Initial program 85.7%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(-4, \cos \left(-4 \cdot K\right), -U\right)} \]
    4. Step-by-step derivation
      1. fma-neg2.3%

        \[\leadsto \color{blue}{-4 \cdot \cos \left(-4 \cdot K\right) - U} \]
      2. *-commutative2.3%

        \[\leadsto -4 \cdot \cos \color{blue}{\left(K \cdot -4\right)} - U \]
    5. Simplified2.3%

      \[\leadsto \color{blue}{-4 \cdot \cos \left(K \cdot -4\right) - U} \]
    6. Taylor expanded in K around 0 46.5%

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

      \[\leadsto \color{blue}{32 \cdot {K}^{2}} \]
    8. Step-by-step derivation
      1. *-commutative46.5%

        \[\leadsto \color{blue}{{K}^{2} \cdot 32} \]
    9. Simplified46.5%

      \[\leadsto \color{blue}{{K}^{2} \cdot 32} \]

    if 4.6000000000000001e255 < K

    1. Initial program 72.8%

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

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

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
    5. Taylor expanded in l around 0 55.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 8.5 \cdot 10^{+188}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot 2, U\right)\\ \mathbf{elif}\;K \leq 4.6 \cdot 10^{+255}:\\ \;\;\;\;{K}^{2} \cdot 32\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 42.6% accurate, 20.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -560000000000 \lor \neg \left(\ell \leq 260\right):\\
\;\;\;\;-4 - U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.6e11 or 260 < l

    1. Initial program 99.2%

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

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

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

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

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

        \[\leadsto \color{blue}{-4 - U \cdot U} \]
    7. Simplified14.8%

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

    if -5.6e11 < l < 260

    1. Initial program 67.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -560000000000 \lor \neg \left(\ell \leq 260\right):\\ \;\;\;\;-4 - U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 42.4% accurate, 20.8× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(-U, U, U\right) + U} \]
      2. fma-undefine16.6%

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

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

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

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

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

    if -5.4000000000000001e34 < l < 260

    1. Initial program 67.8%

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

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

    if 260 < l

    1. Initial program 98.2%

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

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

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

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

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

        \[\leadsto \color{blue}{-4 - U \cdot U} \]
    7. Simplified12.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.4 \cdot 10^{+34}:\\ \;\;\;\;U \cdot \left(2 - U\right)\\ \mathbf{elif}\;\ell \leq 260:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;-4 - U \cdot U\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 41.4% accurate, 23.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -6.2 \cdot 10^{+69} \lor \neg \left(\ell \leq 4.2 \cdot 10^{+89}\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -6.1999999999999997e69 or 4.19999999999999972e89 < l

    1. Initial program 100.0%

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

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

    if -6.1999999999999997e69 < l < 4.19999999999999972e89

    1. Initial program 73.2%

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

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

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

Alternative 17: 41.3% accurate, 23.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1.75 \cdot 10^{+72}:\\ \;\;\;\;U \cdot \left(U - -4\right)\\ \mathbf{elif}\;\ell \leq 4.2 \cdot 10^{+89}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -1.75e+72) (* U (- U -4.0)) (if (<= l 4.2e+89) U (* U U))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -1.75e+72) {
		tmp = U * (U - -4.0);
	} else if (l <= 4.2e+89) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (l <= (-1.75d+72)) then
        tmp = u * (u - (-4.0d0))
    else if (l <= 4.2d+89) then
        tmp = u
    else
        tmp = u * u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -1.75e+72) {
		tmp = U * (U - -4.0);
	} else if (l <= 4.2e+89) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -1.75e+72:
		tmp = U * (U - -4.0)
	elif l <= 4.2e+89:
		tmp = U
	else:
		tmp = U * U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -1.75e+72)
		tmp = Float64(U * Float64(U - -4.0));
	elseif (l <= 4.2e+89)
		tmp = U;
	else
		tmp = Float64(U * U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -1.75e+72)
		tmp = U * (U - -4.0);
	elseif (l <= 4.2e+89)
		tmp = U;
	else
		tmp = U * U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -1.75e+72], N[(U * N[(U - -4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 4.2e+89], U, N[(U * U), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.75 \cdot 10^{+72}:\\
\;\;\;\;U \cdot \left(U - -4\right)\\

\mathbf{elif}\;\ell \leq 4.2 \cdot 10^{+89}:\\
\;\;\;\;U\\

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


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

    1. Initial program 100.0%

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

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

    if -1.75000000000000005e72 < l < 4.19999999999999972e89

    1. Initial program 73.5%

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

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

    if 4.19999999999999972e89 < l

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{U \cdot U} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 18: 53.1% accurate, 44.6× speedup?

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

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

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

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

    \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
  5. Taylor expanded in l around 0 52.5%

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

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

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

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

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

Alternative 19: 36.7% 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 82.9%

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

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

Reproduce

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