Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 85.9% → 99.8%
Time: 11.9s
Alternatives: 14
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 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: 85.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 0.0002\right):\\ \;\;\;\;t_0 \cdot \left(t_1 \cdot J\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \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 0.0002)))
     (+ (* t_0 (* t_1 J)) U)
     (+ U (* t_0 (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* 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 <= 0.0002)) {
		tmp = (t_0 * (t_1 * J)) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + (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 <= 0.0002)) {
		tmp = (t_0 * (t_1 * J)) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (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 <= 0.0002):
		tmp = (t_0 * (t_1 * J)) + U
	else:
		tmp = U + (t_0 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (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 <= 0.0002))
		tmp = Float64(Float64(t_0 * Float64(t_1 * J)) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + 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 <= 0.0002)))
		tmp = (t_0 * (t_1 * J)) + U;
	else
		tmp = U + (t_0 * (J * ((0.3333333333333333 * (l ^ 3.0)) + (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, 0.0002]], $MachinePrecision]], N[(N[(t$95$0 * N[(t$95$1 * J), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \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 2.0000000000000001e-4 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 99.2%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.0000000000000001e-4

    1. Initial program 78.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 99.9%

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

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

Alternative 2: 87.2% 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 0.0002\right):\\ \;\;\;\;U + t_0 \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \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 0.0002)))
     (+ U (* t_0 J))
     (+ U (* (cos (/ K 2.0)) (* l (* J 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 <= 0.0002)) {
		tmp = U + (t_0 * J);
	} else {
		tmp = U + (cos((K / 2.0)) * (l * (J * 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 <= 0.0002)) {
		tmp = U + (t_0 * J);
	} else {
		tmp = U + (Math.cos((K / 2.0)) * (l * (J * 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 <= 0.0002):
		tmp = U + (t_0 * J)
	else:
		tmp = U + (math.cos((K / 2.0)) * (l * (J * 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 <= 0.0002))
		tmp = Float64(U + Float64(t_0 * J));
	else
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(l * Float64(J * 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 <= 0.0002)))
		tmp = U + (t_0 * J);
	else
		tmp = U + (cos((K / 2.0)) * (l * (J * 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, 0.0002]], $MachinePrecision]], N[(U + N[(t$95$0 * J), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(l * N[(J * 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 0.0002\right):\\
\;\;\;\;U + t_0 \cdot J\\

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


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

    1. Initial program 99.2%

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

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.0000000000000001e-4

    1. Initial program 78.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 99.7%

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

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

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

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

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

Alternative 3: 95.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;\ell \leq -9.2 \cdot 10^{+132}:\\ \;\;\;\;U + t_0 \cdot \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)\\ \mathbf{elif}\;\ell \leq -0.0245 \lor \neg \left(\ell \leq 46\right) \land \ell \leq 8 \cdot 10^{+91}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= l -9.2e+132)
     (+ U (* t_0 (* (pow l 3.0) (* J 0.3333333333333333))))
     (if (or (<= l -0.0245) (and (not (<= l 46.0)) (<= l 8e+91)))
       (+ U (* (- (exp l) (exp (- l))) (+ J (* J (* K (* K -0.125))))))
       (+ U (* t_0 (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (l <= -9.2e+132) {
		tmp = U + (t_0 * (pow(l, 3.0) * (J * 0.3333333333333333)));
	} else if ((l <= -0.0245) || (!(l <= 46.0) && (l <= 8e+91))) {
		tmp = U + ((exp(l) - exp(-l)) * (J + (J * (K * (K * -0.125)))));
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    if (l <= (-9.2d+132)) then
        tmp = u + (t_0 * ((l ** 3.0d0) * (j * 0.3333333333333333d0)))
    else if ((l <= (-0.0245d0)) .or. (.not. (l <= 46.0d0)) .and. (l <= 8d+91)) then
        tmp = u + ((exp(l) - exp(-l)) * (j + (j * (k * (k * (-0.125d0))))))
    else
        tmp = u + (t_0 * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (l <= -9.2e+132) {
		tmp = U + (t_0 * (Math.pow(l, 3.0) * (J * 0.3333333333333333)));
	} else if ((l <= -0.0245) || (!(l <= 46.0) && (l <= 8e+91))) {
		tmp = U + ((Math.exp(l) - Math.exp(-l)) * (J + (J * (K * (K * -0.125)))));
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if l <= -9.2e+132:
		tmp = U + (t_0 * (math.pow(l, 3.0) * (J * 0.3333333333333333)))
	elif (l <= -0.0245) or (not (l <= 46.0) and (l <= 8e+91)):
		tmp = U + ((math.exp(l) - math.exp(-l)) * (J + (J * (K * (K * -0.125)))))
	else:
		tmp = U + (t_0 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (l <= -9.2e+132)
		tmp = Float64(U + Float64(t_0 * Float64((l ^ 3.0) * Float64(J * 0.3333333333333333))));
	elseif ((l <= -0.0245) || (!(l <= 46.0) && (l <= 8e+91)))
		tmp = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * Float64(J + Float64(J * Float64(K * Float64(K * -0.125))))));
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	tmp = 0.0;
	if (l <= -9.2e+132)
		tmp = U + (t_0 * ((l ^ 3.0) * (J * 0.3333333333333333)));
	elseif ((l <= -0.0245) || (~((l <= 46.0)) && (l <= 8e+91)))
		tmp = U + ((exp(l) - exp(-l)) * (J + (J * (K * (K * -0.125)))));
	else
		tmp = U + (t_0 * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -9.2e+132], N[(U + N[(t$95$0 * N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, -0.0245], And[N[Not[LessEqual[l, 46.0]], $MachinePrecision], LessEqual[l, 8e+91]]], N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * N[(J + N[(J * N[(K * N[(K * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -0.0245 \lor \neg \left(\ell \leq 46\right) \land \ell \leq 8 \cdot 10^{+91}:\\
\;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\

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


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

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

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

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

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

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

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

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

    if -9.2000000000000006e132 < l < -0.024500000000000001 or 46 < l < 8.00000000000000064e91

    1. Initial program 98.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(\left(e^{\ell} - e^{-\ell}\right) \cdot J + -0.125 \cdot \left({K}^{2} \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\right)\right)} + U \]
    3. Step-by-step derivation
      1. *-commutative0.0%

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

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

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

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

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

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

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

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

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

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

    if -0.024500000000000001 < l < 46 or 8.00000000000000064e91 < l

    1. Initial program 83.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -9.2 \cdot 10^{+132}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)\\ \mathbf{elif}\;\ell \leq -0.0245 \lor \neg \left(\ell \leq 46\right) \land \ell \leq 8 \cdot 10^{+91}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \end{array} \]

Alternative 4: 95.5% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -0.047:\\
\;\;\;\;t_2\\

\mathbf{elif}\;\ell \leq 0.003:\\
\;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\

\mathbf{elif}\;\ell \leq 4.2 \cdot 10^{+94}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.49999999999999981e102 or 4.19999999999999979e94 < 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 100.0%

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

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

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

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

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

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

    if -5.49999999999999981e102 < l < -0.047 or 0.0030000000000000001 < l < 4.19999999999999979e94

    1. Initial program 97.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 68.2%

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

    if -0.047 < l < 0.0030000000000000001

    1. Initial program 78.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 99.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.5 \cdot 10^{+102}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)\\ \mathbf{elif}\;\ell \leq -0.047:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.003:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 4.2 \cdot 10^{+94}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)\\ \end{array} \]

Alternative 5: 95.4% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -0.00088:\\
\;\;\;\;t_2\\

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

\mathbf{elif}\;\ell \leq 3 \cdot 10^{+94}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.49999999999999981e102 or 3.0000000000000001e94 < 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 100.0%

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

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

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

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

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

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

    if -5.49999999999999981e102 < l < -8.80000000000000031e-4 or 4.2000000000000002e-4 < l < 3.0000000000000001e94

    1. Initial program 97.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 68.2%

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

    if -8.80000000000000031e-4 < l < 4.2000000000000002e-4

    1. Initial program 78.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 99.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.5 \cdot 10^{+102}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)\\ \mathbf{elif}\;\ell \leq -0.00088:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.00042:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 3 \cdot 10^{+94}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)\\ \end{array} \]

Alternative 6: 77.9% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 86.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 62.9%

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

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

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

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

    if 0.75 < (cos.f64 (/.f64 K 2))

    1. Initial program 89.5%

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

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

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

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

Alternative 7: 70.0% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\ \mathbf{if}\;\ell \leq -1.9 \cdot 10^{+28}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 800000:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{elif}\;\ell \leq 8.4 \cdot 10^{+91}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 1.95 \cdot 10^{+161} \lor \neg \left(\ell \leq 1.35 \cdot 10^{+228}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))
   (if (<= l -1.9e+28)
     t_0
     (if (<= l 800000.0)
       (+ U (* 2.0 (* l J)))
       (if (<= l 8.4e+91)
         (pow U -3.0)
         (if (or (<= l 1.95e+161) (not (<= l 1.35e+228)))
           t_0
           (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0));
	double tmp;
	if (l <= -1.9e+28) {
		tmp = t_0;
	} else if (l <= 800000.0) {
		tmp = U + (2.0 * (l * J));
	} else if (l <= 8.4e+91) {
		tmp = pow(U, -3.0);
	} else if ((l <= 1.95e+161) || !(l <= 1.35e+228)) {
		tmp = t_0;
	} else {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))
    if (l <= (-1.9d+28)) then
        tmp = t_0
    else if (l <= 800000.0d0) then
        tmp = u + (2.0d0 * (l * j))
    else if (l <= 8.4d+91) then
        tmp = u ** (-3.0d0)
    else if ((l <= 1.95d+161) .or. (.not. (l <= 1.35d+228))) then
        tmp = t_0
    else
        tmp = u + ((l * j) * (2.0d0 + ((k * k) * (-0.25d0))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0));
	double tmp;
	if (l <= -1.9e+28) {
		tmp = t_0;
	} else if (l <= 800000.0) {
		tmp = U + (2.0 * (l * J));
	} else if (l <= 8.4e+91) {
		tmp = Math.pow(U, -3.0);
	} else if ((l <= 1.95e+161) || !(l <= 1.35e+228)) {
		tmp = t_0;
	} else {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))
	tmp = 0
	if l <= -1.9e+28:
		tmp = t_0
	elif l <= 800000.0:
		tmp = U + (2.0 * (l * J))
	elif l <= 8.4e+91:
		tmp = math.pow(U, -3.0)
	elif (l <= 1.95e+161) or not (l <= 1.35e+228):
		tmp = t_0
	else:
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))
	tmp = 0.0
	if (l <= -1.9e+28)
		tmp = t_0;
	elseif (l <= 800000.0)
		tmp = Float64(U + Float64(2.0 * Float64(l * J)));
	elseif (l <= 8.4e+91)
		tmp = U ^ -3.0;
	elseif ((l <= 1.95e+161) || !(l <= 1.35e+228))
		tmp = t_0;
	else
		tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0));
	tmp = 0.0;
	if (l <= -1.9e+28)
		tmp = t_0;
	elseif (l <= 800000.0)
		tmp = U + (2.0 * (l * J));
	elseif (l <= 8.4e+91)
		tmp = U ^ -3.0;
	elseif ((l <= 1.95e+161) || ~((l <= 1.35e+228)))
		tmp = t_0;
	else
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.9e+28], t$95$0, If[LessEqual[l, 800000.0], N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 8.4e+91], N[Power[U, -3.0], $MachinePrecision], If[Or[LessEqual[l, 1.95e+161], N[Not[LessEqual[l, 1.35e+228]], $MachinePrecision]], t$95$0, N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\ell \leq 8.4 \cdot 10^{+91}:\\
\;\;\;\;{U}^{-3}\\

\mathbf{elif}\;\ell \leq 1.95 \cdot 10^{+161} \lor \neg \left(\ell \leq 1.35 \cdot 10^{+228}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.8999999999999999e28 or 8.40000000000000031e91 < l < 1.9500000000000001e161 or 1.3500000000000001e228 < 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 90.7%

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

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

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

    if -1.8999999999999999e28 < l < 8e5

    1. Initial program 79.6%

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

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

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

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

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

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

    if 8e5 < l < 8.40000000000000031e91

    1. Initial program 100.0%

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

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

    if 1.9500000000000001e161 < l < 1.3500000000000001e228

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.9 \cdot 10^{+28}:\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 800000:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{elif}\;\ell \leq 8.4 \cdot 10^{+91}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 1.95 \cdot 10^{+161} \lor \neg \left(\ell \leq 1.35 \cdot 10^{+228}\right):\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \]

Alternative 8: 76.8% accurate, 2.6× speedup?

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

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

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

\mathbf{elif}\;\ell \leq 4.1 \cdot 10^{+93}:\\
\;\;\;\;{U}^{-3}\\

\mathbf{elif}\;\ell \leq 2.45 \cdot 10^{+160} \lor \neg \left(\ell \leq 3.5 \cdot 10^{+226}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.8e28 or 4.1000000000000001e93 < l < 2.4500000000000001e160 or 3.4999999999999998e226 < 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 90.7%

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

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

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

    if -1.8e28 < l < 8e5

    1. Initial program 79.6%

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

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

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

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

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

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

    if 8e5 < l < 4.1000000000000001e93

    1. Initial program 100.0%

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

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

    if 2.4500000000000001e160 < l < 3.4999999999999998e226

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.8 \cdot 10^{+28}:\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 800000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 4.1 \cdot 10^{+93}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 2.45 \cdot 10^{+160} \lor \neg \left(\ell \leq 3.5 \cdot 10^{+226}\right):\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \]

Alternative 9: 76.8% accurate, 2.6× speedup?

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

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

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

\mathbf{elif}\;\ell \leq 4 \cdot 10^{+92}:\\
\;\;\;\;{U}^{-3}\\

\mathbf{elif}\;\ell \leq 1.95 \cdot 10^{+161} \lor \neg \left(\ell \leq 3.4 \cdot 10^{+226}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -4.19999999999999978e28 or 4.0000000000000002e92 < l < 1.9500000000000001e161 or 3.39999999999999979e226 < 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 90.7%

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

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

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

    if -4.19999999999999978e28 < l < 8e5

    1. Initial program 79.6%

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

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

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

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

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

    if 8e5 < l < 4.0000000000000002e92

    1. Initial program 100.0%

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

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

    if 1.9500000000000001e161 < l < 3.39999999999999979e226

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.2 \cdot 10^{+28}:\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 800000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 4 \cdot 10^{+92}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 1.95 \cdot 10^{+161} \lor \neg \left(\ell \leq 3.4 \cdot 10^{+226}\right):\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \]

Alternative 10: 59.5% accurate, 18.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -7 \cdot 10^{-21} \lor \neg \left(\ell \leq 550\right):\\
\;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -7.0000000000000007e-21 or 550 < l

    1. Initial program 97.3%

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.0000000000000007e-21 < l < 550

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7 \cdot 10^{-21} \lor \neg \left(\ell \leq 550\right):\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \end{array} \]

Alternative 11: 53.8% accurate, 44.6× speedup?

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

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

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

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

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

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

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

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

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

Alternative 12: 39.3% accurate, 61.6× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

    if -720 < l

    1. Initial program 85.0%

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

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

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

Alternative 13: 2.7% accurate, 312.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 88.2%

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

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

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

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

    \[\leadsto 1 \]

Alternative 14: 36.4% accurate, 312.0× speedup?

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

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

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

    \[\leadsto \color{blue}{U} \]
  3. Final simplification42.5%

    \[\leadsto U \]

Reproduce

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