Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.3% → 99.8%
Time: 14.5s
Alternatives: 18
Speedup: 1.5×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 18 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 86.3% 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.005\right):\\ \;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + U\\ \mathbf{else}:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.016666666666666666 \cdot {\ell}^{5} + \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
   (if (or (<= t_1 (- INFINITY)) (not (<= t_1 0.005)))
     (+ (* (* t_1 J) t_0) U)
     (+
      U
      (*
       t_0
       (*
        J
        (+
         (* 0.016666666666666666 (pow l 5.0))
         (+ (* 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.005)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.016666666666666666 * pow(l, 5.0)) + ((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.005)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.016666666666666666 * Math.pow(l, 5.0)) + ((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.005):
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (t_0 * (J * ((0.016666666666666666 * math.pow(l, 5.0)) + ((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.005))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(0.016666666666666666 * (l ^ 5.0)) + 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.005)))
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (t_0 * (J * ((0.016666666666666666 * (l ^ 5.0)) + ((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.005]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 0.0050000000000000001 < (-.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))) < 0.0050000000000000001

    1. Initial program 76.7%

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

      \[\leadsto \left(J \cdot \color{blue}{\left(0.016666666666666666 \cdot {\ell}^{5} + \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)\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 0.005\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(0.016666666666666666 \cdot {\ell}^{5} + \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\right)\\ \end{array} \]

Alternative 2: 99.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 0\right):\\ \;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + 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.0)))
     (+ (* (* t_1 J) t_0) 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.0)) {
		tmp = ((t_1 * J) * t_0) + 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.0)) {
		tmp = ((t_1 * J) * t_0) + 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.0):
		tmp = ((t_1 * J) * t_0) + 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.0))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + 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.0)))
		tmp = ((t_1 * J) * t_0) + 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.0]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $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\right):\\
\;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + 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 0.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 99.9%

      \[\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))) < 0.0

    1. Initial program 75.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(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.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -\infty \lor \neg \left(e^{\ell} - e^{-\ell} \leq 0\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(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \end{array} \]

Alternative 3: 93.8% accurate, 1.4× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.5e12 or 3.59999999999999969e38 < 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 93.5%

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

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

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

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

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

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

    if -5.5e12 < l < 3.59999999999999974e-20

    1. Initial program 75.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.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 J around 0 99.0%

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

    if 3.59999999999999974e-20 < l < 3.59999999999999969e38

    1. Initial program 99.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5500000000000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{5} \cdot \left(J \cdot 0.016666666666666666\right)\right)\\ \mathbf{elif}\;\ell \leq 3.6 \cdot 10^{-20}:\\ \;\;\;\;U + J \cdot \left(\left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq 3.6 \cdot 10^{+38}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{5} \cdot \left(J \cdot 0.016666666666666666\right)\right)\\ \end{array} \]

Alternative 4: 93.8% 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}^{5} \cdot \left(J \cdot 0.016666666666666666\right)\right)\\ \mathbf{if}\;\ell \leq -5500000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq 3.6 \cdot 10^{-20}:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 3.6 \cdot 10^{+38}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \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 5.0) (* J 0.016666666666666666))))))
   (if (<= l -5500000000000.0)
     t_1
     (if (<= l 3.6e-20)
       (+ U (* t_0 (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))
       (if (<= l 3.6e+38) (+ (* (- (exp l) (exp (- l))) J) U) 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, 5.0) * (J * 0.016666666666666666)));
	double tmp;
	if (l <= -5500000000000.0) {
		tmp = t_1;
	} else if (l <= 3.6e-20) {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
	} else if (l <= 3.6e+38) {
		tmp = ((exp(l) - exp(-l)) * J) + U;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    t_1 = u + (t_0 * ((l ** 5.0d0) * (j * 0.016666666666666666d0)))
    if (l <= (-5500000000000.0d0)) then
        tmp = t_1
    else if (l <= 3.6d-20) then
        tmp = u + (t_0 * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
    else if (l <= 3.6d+38) then
        tmp = ((exp(l) - exp(-l)) * j) + u
    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, 5.0) * (J * 0.016666666666666666)));
	double tmp;
	if (l <= -5500000000000.0) {
		tmp = t_1;
	} else if (l <= 3.6e-20) {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
	} else if (l <= 3.6e+38) {
		tmp = ((Math.exp(l) - Math.exp(-l)) * J) + U;
	} 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, 5.0) * (J * 0.016666666666666666)))
	tmp = 0
	if l <= -5500000000000.0:
		tmp = t_1
	elif l <= 3.6e-20:
		tmp = U + (t_0 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))))
	elif l <= 3.6e+38:
		tmp = ((math.exp(l) - math.exp(-l)) * J) + U
	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 ^ 5.0) * Float64(J * 0.016666666666666666))))
	tmp = 0.0
	if (l <= -5500000000000.0)
		tmp = t_1;
	elseif (l <= 3.6e-20)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))));
	elseif (l <= 3.6e+38)
		tmp = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U);
	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 ^ 5.0) * (J * 0.016666666666666666)));
	tmp = 0.0;
	if (l <= -5500000000000.0)
		tmp = t_1;
	elseif (l <= 3.6e-20)
		tmp = U + (t_0 * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))));
	elseif (l <= 3.6e+38)
		tmp = ((exp(l) - exp(-l)) * J) + U;
	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, 5.0], $MachinePrecision] * N[(J * 0.016666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5500000000000.0], t$95$1, If[LessEqual[l, 3.6e-20], 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, 3.6e+38], N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision], 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}^{5} \cdot \left(J \cdot 0.016666666666666666\right)\right)\\
\mathbf{if}\;\ell \leq -5500000000000:\\
\;\;\;\;t_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.5e12 or 3.59999999999999969e38 < 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 93.5%

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

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

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

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

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

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

    if -5.5e12 < l < 3.59999999999999974e-20

    1. Initial program 75.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.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 \]

    if 3.59999999999999974e-20 < l < 3.59999999999999969e38

    1. Initial program 99.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5500000000000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{5} \cdot \left(J \cdot 0.016666666666666666\right)\right)\\ \mathbf{elif}\;\ell \leq 3.6 \cdot 10^{-20}:\\ \;\;\;\;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 3.6 \cdot 10^{+38}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{5} \cdot \left(J \cdot 0.016666666666666666\right)\right)\\ \end{array} \]

Alternative 5: 93.7% accurate, 1.4× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.5e12 or 3.59999999999999969e38 < 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 93.5%

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

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

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

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

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

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

    if -5.5e12 < l < 3.59999999999999974e-20

    1. Initial program 75.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 98.7%

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

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

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

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

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

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

    if 3.59999999999999974e-20 < l < 3.59999999999999969e38

    1. Initial program 99.3%

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

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

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

Alternative 6: 73.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.64:\\ \;\;\;\;U + \left(J \cdot -0.25\right) \cdot \left(\ell \cdot {K}^{2}\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
 (if (<= (cos (/ K 2.0)) -0.64)
   (+ U (* (* J -0.25) (* l (pow K 2.0))))
   (+ U (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.64) {
		tmp = U + ((J * -0.25) * (l * pow(K, 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) :: tmp
    if (cos((k / 2.0d0)) <= (-0.64d0)) then
        tmp = u + ((j * (-0.25d0)) * (l * (k ** 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 tmp;
	if (Math.cos((K / 2.0)) <= -0.64) {
		tmp = U + ((J * -0.25) * (l * Math.pow(K, 2.0)));
	} else {
		tmp = U + (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if math.cos((K / 2.0)) <= -0.64:
		tmp = U + ((J * -0.25) * (l * math.pow(K, 2.0)))
	else:
		tmp = U + (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.64)
		tmp = Float64(U + Float64(Float64(J * -0.25) * Float64(l * (K ^ 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)
	tmp = 0.0;
	if (cos((K / 2.0)) <= -0.64)
		tmp = U + ((J * -0.25) * (l * (K ^ 2.0)));
	else
		tmp = U + (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.64], N[(U + N[(N[(J * -0.25), $MachinePrecision] * N[(l * N[Power[K, 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}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.64:\\
\;\;\;\;U + \left(J \cdot -0.25\right) \cdot \left(\ell \cdot {K}^{2}\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.640000000000000013

    1. Initial program 91.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 45.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 89.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 88.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 81.4%

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

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

Alternative 7: 62.1% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 90.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 42.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.650000000000000022 < (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 63.7%

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

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

Alternative 8: 62.1% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 90.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 42.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.650000000000000022 < (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 94.0%

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

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

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

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

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

Alternative 9: 62.1% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 90.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 42.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.650000000000000022 < (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 63.7%

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

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

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

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

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

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

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

Alternative 10: 62.1% accurate, 1.5× speedup?

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

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


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

    1. Initial program 90.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 42.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.650000000000000022 < (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 94.0%

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

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

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

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

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

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

Alternative 11: 55.2% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 91.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 45.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 89.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 63.4%

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

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

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

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

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

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

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

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

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

Alternative 12: 55.9% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 91.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 45.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 89.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 63.4%

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

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

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

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

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

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

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

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

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

Alternative 13: 86.5% accurate, 1.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -0.00700000000000000015 or 3.59999999999999974e-20 < l

    1. Initial program 99.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 \]

    if -0.00700000000000000015 < l < 3.59999999999999974e-20

    1. Initial program 75.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.5%

      \[\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. *-commutative99.5%

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

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

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

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

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

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

Alternative 14: 52.0% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 4 \cdot 10^{+226}:\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\

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


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

    1. Initial program 89.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 61.0%

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

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

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

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

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

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

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

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

    if 3.99999999999999985e226 < (/.f64 K 2)

    1. Initial program 89.8%

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

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

      \[\leadsto \color{blue}{\left(-0.5 \cdot J + 0.0625 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
    4. Taylor expanded in K around inf 45.0%

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

        \[\leadsto \color{blue}{\left(0.0625 \cdot J\right) \cdot {K}^{2}} + U \]
      2. *-commutative45.0%

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

        \[\leadsto \color{blue}{{K}^{2} \cdot \left(J \cdot 0.0625\right)} + U \]
    6. Simplified45.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 4 \cdot 10^{+226}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + {K}^{2} \cdot \left(J \cdot 0.0625\right)\\ \end{array} \]

Alternative 15: 42.1% accurate, 43.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.5 \cdot 10^{+20} \lor \neg \left(\ell \leq 6 \cdot 10^{+30}\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.5e20 or 5.99999999999999956e30 < l

    1. Initial program 100.0%

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

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

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

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

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

    if -1.5e20 < l < 5.99999999999999956e30

    1. Initial program 78.6%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.5 \cdot 10^{+20} \lor \neg \left(\ell \leq 6 \cdot 10^{+30}\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 16: 53.2% accurate, 44.6× speedup?

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

\\
U + \ell \cdot \left(J \cdot 2\right)
\end{array}
Derivation
  1. Initial program 89.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 59.6%

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

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

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

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

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

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

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

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

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

Alternative 17: 2.8% accurate, 312.0× speedup?

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

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

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

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

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

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

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

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

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

    \[\leadsto 1 \]

Alternative 18: 36.7% accurate, 312.0× speedup?

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

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

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

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

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

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

    \[\leadsto \color{blue}{U} \]
  5. Final simplification34.2%

    \[\leadsto U \]

Reproduce

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