Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.5% → 99.6%
Time: 11.5s
Alternatives: 19
Speedup: 1.0×

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

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

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

Alternative 1: 99.6% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 100.0%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 4.9999999999999999e-13

    1. Initial program 67.7%

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

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

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

Alternative 2: 87.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ t_1 := t_0 \cdot J\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-13}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))) (t_1 (* t_0 J)))
   (if (<= t_0 (- INFINITY))
     t_1
     (if (<= t_0 5e-13) (+ U (* (cos (/ K 2.0)) (* J (* l 2.0)))) (+ t_1 U)))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double t_1 = t_0 * J;
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_0 <= 5e-13) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else {
		tmp = t_1 + U;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double t_1 = t_0 * J;
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else if (t_0 <= 5e-13) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	} else {
		tmp = t_1 + U;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	t_1 = t_0 * J
	tmp = 0
	if t_0 <= -math.inf:
		tmp = t_1
	elif t_0 <= 5e-13:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * 2.0)))
	else:
		tmp = t_1 + U
	return tmp
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	t_1 = Float64(t_0 * J)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_0 <= 5e-13)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	else
		tmp = Float64(t_1 + U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(l) - exp(-l);
	t_1 = t_0 * J;
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = t_1;
	elseif (t_0 <= 5e-13)
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	else
		tmp = t_1 + U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * J), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, 5e-13], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + U), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
t_1 := t_0 \cdot J\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{-13}:\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\

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


\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. Taylor expanded in K around 0 75.4%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    3. Taylor expanded in J around inf 75.4%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 4.9999999999999999e-13

    1. Initial program 67.7%

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

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

    if 4.9999999999999999e-13 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

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

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

Alternative 3: 87.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;U + t_0 \cdot \left(J + K \cdot \left(-0.125 \cdot \left(J \cdot K\right)\right)\right)\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-13}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot J + U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))))
   (if (<= t_0 (- INFINITY))
     (+ U (* t_0 (+ J (* K (* -0.125 (* J K))))))
     (if (<= t_0 5e-13)
       (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))
       (+ (* t_0 J) U)))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = U + (t_0 * (J + (K * (-0.125 * (J * K)))));
	} else if (t_0 <= 5e-13) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else {
		tmp = (t_0 * J) + U;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = U + (t_0 * (J + (K * (-0.125 * (J * K)))));
	} else if (t_0 <= 5e-13) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	} else {
		tmp = (t_0 * J) + U;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = U + (t_0 * (J + (K * (-0.125 * (J * K)))))
	elif t_0 <= 5e-13:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * 2.0)))
	else:
		tmp = (t_0 * J) + U
	return tmp
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(U + Float64(t_0 * Float64(J + Float64(K * Float64(-0.125 * Float64(J * K))))));
	elseif (t_0 <= 5e-13)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	else
		tmp = Float64(Float64(t_0 * J) + U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(l) - exp(-l);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = U + (t_0 * (J + (K * (-0.125 * (J * K)))));
	elseif (t_0 <= 5e-13)
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	else
		tmp = (t_0 * J) + U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(U + N[(t$95$0 * N[(J + N[(K * N[(-0.125 * N[(J * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e-13], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * J), $MachinePrecision] + U), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;U + t_0 \cdot \left(J + K \cdot \left(-0.125 \cdot \left(J \cdot K\right)\right)\right)\\

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{-13}:\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot J + U\\


\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. Taylor expanded in K around 0 0.0%

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

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

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

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

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

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

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

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

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 4.9999999999999999e-13

    1. Initial program 67.7%

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

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

    if 4.9999999999999999e-13 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -\infty:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + K \cdot \left(-0.125 \cdot \left(J \cdot K\right)\right)\right)\\ \mathbf{elif}\;e^{\ell} - e^{-\ell} \leq 5 \cdot 10^{-13}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \end{array} \]

Alternative 4: 86.8% accurate, 0.5× speedup?

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

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


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    3. Taylor expanded in J around inf 78.2%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 5.00000000000000031e-10

    1. Initial program 67.9%

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

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

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

Alternative 5: 86.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;\ell \leq -110:\\ \;\;\;\;U + t_0 \cdot \left(J + K \cdot \left(-0.125 \cdot \left(J \cdot K\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2.1 \cdot 10^{-10}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 6.5 \cdot 10^{+153}:\\ \;\;\;\;t_0 \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + \sqrt[3]{{\left(J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\right)}^{3}}\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))))
   (if (<= l -110.0)
     (+ U (* t_0 (+ J (* K (* -0.125 (* J K))))))
     (if (<= l 2.1e-10)
       (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))
       (if (<= l 6.5e+153)
         (+ (* t_0 J) U)
         (+ U (cbrt (pow (* J (* 2.0 (* l (cos (* K 0.5))))) 3.0))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if (l <= -110.0) {
		tmp = U + (t_0 * (J + (K * (-0.125 * (J * K)))));
	} else if (l <= 2.1e-10) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 6.5e+153) {
		tmp = (t_0 * J) + U;
	} else {
		tmp = U + cbrt(pow((J * (2.0 * (l * cos((K * 0.5))))), 3.0));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if (l <= -110.0) {
		tmp = U + (t_0 * (J + (K * (-0.125 * (J * K)))));
	} else if (l <= 2.1e-10) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 6.5e+153) {
		tmp = (t_0 * J) + U;
	} else {
		tmp = U + Math.cbrt(Math.pow((J * (2.0 * (l * Math.cos((K * 0.5))))), 3.0));
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if (l <= -110.0)
		tmp = Float64(U + Float64(t_0 * Float64(J + Float64(K * Float64(-0.125 * Float64(J * K))))));
	elseif (l <= 2.1e-10)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	elseif (l <= 6.5e+153)
		tmp = Float64(Float64(t_0 * J) + U);
	else
		tmp = Float64(U + cbrt((Float64(J * Float64(2.0 * Float64(l * cos(Float64(K * 0.5))))) ^ 3.0)));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -110.0], N[(U + N[(t$95$0 * N[(J + N[(K * N[(-0.125 * N[(J * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.1e-10], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 6.5e+153], N[(N[(t$95$0 * J), $MachinePrecision] + U), $MachinePrecision], N[(U + N[Power[N[Power[N[(J * N[(2.0 * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;\ell \leq -110:\\
\;\;\;\;U + t_0 \cdot \left(J + K \cdot \left(-0.125 \cdot \left(J \cdot K\right)\right)\right)\\

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

\mathbf{elif}\;\ell \leq 6.5 \cdot 10^{+153}:\\
\;\;\;\;t_0 \cdot J + U\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

    if -110 < l < 2.1e-10

    1. Initial program 67.7%

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

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

    if 2.1e-10 < l < 6.49999999999999972e153

    1. Initial program 100.0%

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

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

    if 6.49999999999999972e153 < l

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -110:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + K \cdot \left(-0.125 \cdot \left(J \cdot K\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2.1 \cdot 10^{-10}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 6.5 \cdot 10^{+153}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + \sqrt[3]{{\left(J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\right)}^{3}}\\ \end{array} \]

Alternative 6: 79.0% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 81.1%

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

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

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

    1. Initial program 85.7%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.015:\\ \;\;\;\;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 2 + 0.3333333333333333 \cdot {\ell}^{3}\right)\\ \end{array} \]

Alternative 7: 76.6% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
t_0 := U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
t_1 := 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
t_2 := U + t_1\\
\mathbf{if}\;\ell \leq -2 \cdot 10^{+42}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;\ell \leq 2.1 \cdot 10^{-10}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq 5 \cdot 10^{+229}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;\ell \leq 3 \cdot 10^{+285}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.00000000000000009e42 or 2.1e-10 < l < 5.0000000000000005e229

    1. Initial program 100.0%

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

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

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

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

    if -2.00000000000000009e42 < l < 2.1e-10 or 5.0000000000000005e229 < l < 3.0000000000000002e285

    1. Initial program 72.4%

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

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

    if 3.0000000000000002e285 < l

    1. Initial program 100.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2 \cdot 10^{+42}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 2.1 \cdot 10^{-10}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 5 \cdot 10^{+229}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 3 \cdot 10^{+285}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \end{array} \]

Alternative 8: 76.6% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
t_0 := 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
t_1 := U + t_0\\
t_2 := \cos \left(K \cdot 0.5\right)\\
\mathbf{if}\;\ell \leq -1.8 \cdot 10^{+42}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;\ell \leq 5 \cdot 10^{+229}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\ell \leq 9.5 \cdot 10^{+284}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t_2\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.8e42 or 2.1e-10 < l < 5.0000000000000005e229

    1. Initial program 100.0%

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

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

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

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

    if -1.8e42 < l < 2.1e-10

    1. Initial program 68.2%

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

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

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

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

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

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

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

    if 5.0000000000000005e229 < l < 9.4999999999999997e284

    1. Initial program 100.0%

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

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

    if 9.4999999999999997e284 < l

    1. Initial program 100.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.8 \cdot 10^{+42}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 2.1 \cdot 10^{-10}:\\ \;\;\;\;U + \left(\ell \cdot 2\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq 5 \cdot 10^{+229}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 9.5 \cdot 10^{+284}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \end{array} \]

Alternative 9: 76.7% accurate, 2.6× speedup?

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

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

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

\mathbf{elif}\;\ell \leq 1.6 \cdot 10^{+229}:\\
\;\;\;\;t_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -2.00000000000000009e42 or 2.1e-10 < l < 1.5999999999999999e229

    1. Initial program 100.0%

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

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

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

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

    if -2.00000000000000009e42 < l < 2.1e-10

    1. Initial program 68.2%

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

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

    if 1.5999999999999999e229 < l < 2.35000000000000011e284

    1. Initial program 100.0%

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

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

    if 2.35000000000000011e284 < l

    1. Initial program 100.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2 \cdot 10^{+42}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 2.1 \cdot 10^{-10}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 1.6 \cdot 10^{+229}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 2.35 \cdot 10^{+284}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \end{array} \]

Alternative 10: 72.3% accurate, 2.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.8e42 or 2.1e-10 < l

    1. Initial program 100.0%

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

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

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

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

    if -1.8e42 < l < 2.1e-10

    1. Initial program 68.2%

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

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

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

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

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

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

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

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

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

Alternative 11: 72.2% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.8 \cdot 10^{+42} \lor \neg \left(\ell \leq 9.8 \cdot 10^{+44}\right):\\
\;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.8e42 or 9.80000000000000071e44 < l

    1. Initial program 100.0%

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

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

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

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

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

    if -1.8e42 < l < 9.80000000000000071e44

    1. Initial program 71.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.8 \cdot 10^{+42} \lor \neg \left(\ell \leq 9.8 \cdot 10^{+44}\right):\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J \cdot 2, \ell, U\right)\\ \end{array} \]

Alternative 12: 55.5% accurate, 2.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 2300:\\
\;\;\;\;\mathsf{fma}\left(J \cdot 2, \ell, U\right)\\

\mathbf{elif}\;\ell \leq 6.6 \cdot 10^{+168}:\\
\;\;\;\;{U}^{-134217728}\\

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


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

    1. Initial program 78.8%

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

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

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

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

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

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

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

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

    if 2300 < l < 6.5999999999999997e168

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{{U}^{-134217728}} \]

    if 6.5999999999999997e168 < l

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 2300:\\ \;\;\;\;\mathsf{fma}\left(J \cdot 2, \ell, U\right)\\ \mathbf{elif}\;\ell \leq 6.6 \cdot 10^{+168}:\\ \;\;\;\;{U}^{-134217728}\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\ell \cdot 2\right)\\ \end{array} \]

Alternative 13: 55.5% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := J \cdot \left(\ell \cdot 2\right)\\ \mathbf{if}\;\ell \leq 2300:\\ \;\;\;\;U + t_0\\ \mathbf{elif}\;\ell \leq 1.8 \cdot 10^{+168}:\\ \;\;\;\;{U}^{-134217728}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* J (* l 2.0))))
   (if (<= l 2300.0) (+ U t_0) (if (<= l 1.8e+168) (pow U -134217728.0) t_0))))
double code(double J, double l, double K, double U) {
	double t_0 = J * (l * 2.0);
	double tmp;
	if (l <= 2300.0) {
		tmp = U + t_0;
	} else if (l <= 1.8e+168) {
		tmp = pow(U, -134217728.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = j * (l * 2.0d0)
    if (l <= 2300.0d0) then
        tmp = u + t_0
    else if (l <= 1.8d+168) then
        tmp = u ** (-134217728.0d0)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = J * (l * 2.0);
	double tmp;
	if (l <= 2300.0) {
		tmp = U + t_0;
	} else if (l <= 1.8e+168) {
		tmp = Math.pow(U, -134217728.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = J * (l * 2.0)
	tmp = 0
	if l <= 2300.0:
		tmp = U + t_0
	elif l <= 1.8e+168:
		tmp = math.pow(U, -134217728.0)
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(J * Float64(l * 2.0))
	tmp = 0.0
	if (l <= 2300.0)
		tmp = Float64(U + t_0);
	elseif (l <= 1.8e+168)
		tmp = U ^ -134217728.0;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = J * (l * 2.0);
	tmp = 0.0;
	if (l <= 2300.0)
		tmp = U + t_0;
	elseif (l <= 1.8e+168)
		tmp = U ^ -134217728.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, 2300.0], N[(U + t$95$0), $MachinePrecision], If[LessEqual[l, 1.8e+168], N[Power[U, -134217728.0], $MachinePrecision], t$95$0]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq 1.8 \cdot 10^{+168}:\\
\;\;\;\;{U}^{-134217728}\\

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


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

    1. Initial program 78.8%

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

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

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

    if 2300 < l < 1.8e168

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{{U}^{-134217728}} \]

    if 1.8e168 < l

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 2300:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 1.8 \cdot 10^{+168}:\\ \;\;\;\;{U}^{-134217728}\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\ell \cdot 2\right)\\ \end{array} \]

Alternative 14: 45.4% accurate, 27.9× speedup?

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

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

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

\mathbf{elif}\;\ell \leq 1.24 \cdot 10^{+179}:\\
\;\;\;\;U \cdot \left(2 - U\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.1999999999999999e-34 or 1.23999999999999996e179 < l

    1. Initial program 96.0%

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

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

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

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

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

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

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

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

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

    if -5.1999999999999999e-34 < l < 215

    1. Initial program 69.8%

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

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

    if 215 < l < 1.23999999999999996e179

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{U \cdot \left(U - -8\right)} \]
    3. Applied egg-rr27.7%

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

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

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

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

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

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

        \[\leadsto U \cdot \color{blue}{\left(2 - U\right)} \]
    5. Simplified27.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.2 \cdot 10^{-34}:\\ \;\;\;\;J \cdot \left(\ell \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 215:\\ \;\;\;\;U\\ \mathbf{elif}\;\ell \leq 1.24 \cdot 10^{+179}:\\ \;\;\;\;U \cdot \left(2 - U\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\ell \cdot 2\right)\\ \end{array} \]

Alternative 15: 45.1% accurate, 34.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.2 \cdot 10^{-34} \lor \neg \left(\ell \leq 1.2 \cdot 10^{+45}\right):\\
\;\;\;\;J \cdot \left(\ell \cdot 2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.1999999999999999e-34 or 1.19999999999999995e45 < l

    1. Initial program 97.0%

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

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

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

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

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

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

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

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

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

    if -5.1999999999999999e-34 < l < 1.19999999999999995e45

    1. Initial program 72.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.2 \cdot 10^{-34} \lor \neg \left(\ell \leq 1.2 \cdot 10^{+45}\right):\\ \;\;\;\;J \cdot \left(\ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 16: 54.2% accurate, 34.2× speedup?

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

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

\mathbf{elif}\;\ell \leq 1.62 \cdot 10^{+174}:\\
\;\;\;\;U \cdot \left(2 - U\right)\\

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


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

    1. Initial program 78.9%

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

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

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

    if 3.1e6 < l < 1.62000000000000007e174

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{U \cdot \left(U - -8\right)} \]
    3. Applied egg-rr29.7%

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

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

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

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

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

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

        \[\leadsto U \cdot \color{blue}{\left(2 - U\right)} \]
    5. Simplified29.7%

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

    if 1.62000000000000007e174 < l

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 3100000:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 1.62 \cdot 10^{+174}:\\ \;\;\;\;U \cdot \left(2 - U\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\ell \cdot 2\right)\\ \end{array} \]

Alternative 17: 42.2% accurate, 43.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -480 or 1.85e10 < l

    1. Initial program 100.0%

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

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

    if -480 < l < 1.85e10

    1. Initial program 68.9%

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

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

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

Alternative 18: 2.8% accurate, 312.0× speedup?

\[\begin{array}{l} \\ -3.725290312339702 \cdot 10^{-9} \end{array} \]
(FPCore (J l K U) :precision binary64 -3.725290312339702e-9)
double code(double J, double l, double K, double U) {
	return -3.725290312339702e-9;
}
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 = -3.725290312339702d-9
end function
public static double code(double J, double l, double K, double U) {
	return -3.725290312339702e-9;
}
def code(J, l, K, U):
	return -3.725290312339702e-9
function code(J, l, K, U)
	return -3.725290312339702e-9
end
function tmp = code(J, l, K, U)
	tmp = -3.725290312339702e-9;
end
code[J_, l_, K_, U_] := -3.725290312339702e-9
\begin{array}{l}

\\
-3.725290312339702 \cdot 10^{-9}
\end{array}
Derivation
  1. Initial program 84.6%

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

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

    \[\leadsto \color{blue}{\frac{U}{U + \left(-134217728 \cdot U + -134217728 \cdot U\right)}} \]
  4. Step-by-step derivation
    1. associate-+r+2.9%

      \[\leadsto \frac{U}{\color{blue}{\left(U + -134217728 \cdot U\right) + -134217728 \cdot U}} \]
    2. distribute-rgt1-in2.9%

      \[\leadsto \frac{U}{\color{blue}{\left(-134217728 + 1\right) \cdot U} + -134217728 \cdot U} \]
    3. distribute-rgt-out2.9%

      \[\leadsto \frac{U}{\color{blue}{U \cdot \left(\left(-134217728 + 1\right) + -134217728\right)}} \]
    4. associate-/r*2.9%

      \[\leadsto \color{blue}{\frac{\frac{U}{U}}{\left(-134217728 + 1\right) + -134217728}} \]
    5. *-inverses2.9%

      \[\leadsto \frac{\color{blue}{1}}{\left(-134217728 + 1\right) + -134217728} \]
    6. metadata-eval2.9%

      \[\leadsto \frac{1}{\color{blue}{-134217727} + -134217728} \]
    7. metadata-eval2.9%

      \[\leadsto \frac{1}{\color{blue}{-268435455}} \]
    8. metadata-eval2.9%

      \[\leadsto \color{blue}{-3.725290312339702 \cdot 10^{-9}} \]
  5. Simplified2.9%

    \[\leadsto \color{blue}{-3.725290312339702 \cdot 10^{-9}} \]
  6. Final simplification2.9%

    \[\leadsto -3.725290312339702 \cdot 10^{-9} \]

Alternative 19: 36.5% accurate, 312.0× speedup?

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

\\
U
\end{array}
Derivation
  1. Initial program 84.6%

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

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

    \[\leadsto U \]

Reproduce

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