Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.3% → 99.9%
Time: 10.8s
Alternatives: 13
Speedup: 2.7×

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 13 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.9% 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 -20 \lor \neg \left(t_1 \leq 2 \cdot 10^{-9}\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} + \left(0.0003968253968253968 \cdot {\ell}^{7} + \left(0.016666666666666666 \cdot {\ell}^{5} + \ell \cdot 2\right)\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 -20.0) (not (<= t_1 2e-9)))
     (+ (* (* t_1 J) t_0) U)
     (+
      U
      (*
       t_0
       (*
        J
        (+
         (* 0.3333333333333333 (pow l 3.0))
         (+
          (* 0.0003968253968253968 (pow l 7.0))
          (+ (* 0.016666666666666666 (pow l 5.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 <= -20.0) || !(t_1 <= 2e-9)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + ((0.0003968253968253968 * pow(l, 7.0)) + ((0.016666666666666666 * pow(l, 5.0)) + (l * 2.0))))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    t_1 = exp(l) - exp(-l)
    if ((t_1 <= (-20.0d0)) .or. (.not. (t_1 <= 2d-9))) then
        tmp = ((t_1 * j) * t_0) + u
    else
        tmp = u + (t_0 * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + ((0.0003968253968253968d0 * (l ** 7.0d0)) + ((0.016666666666666666d0 * (l ** 5.0d0)) + (l * 2.0d0))))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_1 <= -20.0) || !(t_1 <= 2e-9)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + ((0.0003968253968253968 * Math.pow(l, 7.0)) + ((0.016666666666666666 * Math.pow(l, 5.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 <= -20.0) or not (t_1 <= 2e-9):
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (t_0 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + ((0.0003968253968253968 * math.pow(l, 7.0)) + ((0.016666666666666666 * math.pow(l, 5.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 <= -20.0) || !(t_1 <= 2e-9))
		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(Float64(0.0003968253968253968 * (l ^ 7.0)) + Float64(Float64(0.016666666666666666 * (l ^ 5.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 <= -20.0) || ~((t_1 <= 2e-9)))
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (t_0 * (J * ((0.3333333333333333 * (l ^ 3.0)) + ((0.0003968253968253968 * (l ^ 7.0)) + ((0.016666666666666666 * (l ^ 5.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, -20.0], N[Not[LessEqual[t$95$1, 2e-9]], $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[(N[(0.0003968253968253968 * N[Power[l, 7.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $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 -20 \lor \neg \left(t_1 \leq 2 \cdot 10^{-9}\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} + \left(0.0003968253968253968 \cdot {\ell}^{7} + \left(0.016666666666666666 \cdot {\ell}^{5} + \ell \cdot 2\right)\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))) < -20 or 2.00000000000000012e-9 < (-.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 -20 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.00000000000000012e-9

    1. Initial program 68.8%

      \[\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} + \left(0.0003968253968253968 \cdot {\ell}^{7} + \left(0.016666666666666666 \cdot {\ell}^{5} + 2 \cdot \ell\right)\right)\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 -20 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 2 \cdot 10^{-9}\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} + \left(0.0003968253968253968 \cdot {\ell}^{7} + \left(0.016666666666666666 \cdot {\ell}^{5} + \ell \cdot 2\right)\right)\right)\right)\\ \end{array} \]

Alternative 2: 99.9% 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 -0.05 \lor \neg \left(t_1 \leq 2 \cdot 10^{-9}\right):\\ \;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + U\\ \mathbf{else}:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(\ell \cdot 0.3333333333333333\right)\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 -0.05) (not (<= t_1 2e-9)))
     (+ (* (* t_1 J) t_0) U)
     (+ U (* t_0 (* J (* l (+ 2.0 (* l (* l 0.3333333333333333))))))))))
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 <= -0.05) || !(t_1 <= 2e-9)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))));
	}
	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 = exp(l) - exp(-l)
    if ((t_1 <= (-0.05d0)) .or. (.not. (t_1 <= 2d-9))) then
        tmp = ((t_1 * j) * t_0) + u
    else
        tmp = u + (t_0 * (j * (l * (2.0d0 + (l * (l * 0.3333333333333333d0))))))
    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 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_1 <= -0.05) || !(t_1 <= 2e-9)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))));
	}
	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 <= -0.05) or not (t_1 <= 2e-9):
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (t_0 * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))))
	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 <= -0.05) || !(t_1 <= 2e-9))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * Float64(2.0 + Float64(l * Float64(l * 0.3333333333333333)))))));
	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 <= -0.05) || ~((t_1 <= 2e-9)))
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (t_0 * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))));
	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, -0.05], N[Not[LessEqual[t$95$1, 2e-9]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(l * N[(2.0 + N[(l * N[(l * 0.3333333333333333), $MachinePrecision]), $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 -0.05 \lor \neg \left(t_1 \leq 2 \cdot 10^{-9}\right):\\
\;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + U\\

\mathbf{else}:\\
\;\;\;\;U + t_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(\ell \cdot 0.3333333333333333\right)\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))) < -0.050000000000000003 or 2.00000000000000012e-9 < (-.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 -0.050000000000000003 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.00000000000000012e-9

    1. Initial program 68.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\ell \cdot 0.3333333333333333\right)} + 2\right)\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 -0.05 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 2 \cdot 10^{-9}\right):\\ \;\;\;\;\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(\ell \cdot 0.3333333333333333\right)\right)\right)\right)\\ \end{array} \]

Alternative 3: 96.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ t_1 := \cos \left(\frac{K}{2}\right)\\ t_2 := U + t_1 \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(\ell \cdot 0.3333333333333333\right)\right)\right)\right)\\ t_3 := 0.3333333333333333 \cdot \left(\ell \cdot \left(\ell \cdot \ell\right)\right)\\ \mathbf{if}\;\ell \leq -8.2 \cdot 10^{+97}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\ell \leq -0.032:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 0.0065:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\ell \leq 3.5 \cdot 10^{+51}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 5.5 \cdot 10^{+102}:\\ \;\;\;\;U + t_1 \cdot \left(J \cdot \frac{t_3 \cdot t_3 - \left(\ell \cdot 2\right) \cdot \left(\ell \cdot 2\right)}{t_3 - \ell \cdot 2}\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ (* (- (exp l) (exp (- l))) J) U))
        (t_1 (cos (/ K 2.0)))
        (t_2 (+ U (* t_1 (* J (* l (+ 2.0 (* l (* l 0.3333333333333333))))))))
        (t_3 (* 0.3333333333333333 (* l (* l l)))))
   (if (<= l -8.2e+97)
     t_2
     (if (<= l -0.032)
       t_0
       (if (<= l 0.0065)
         t_2
         (if (<= l 3.5e+51)
           t_0
           (if (<= l 5.5e+102)
             (+
              U
              (*
               t_1
               (*
                J
                (/
                 (- (* t_3 t_3) (* (* l 2.0) (* l 2.0)))
                 (- t_3 (* l 2.0))))))
             t_2)))))))
double code(double J, double l, double K, double U) {
	double t_0 = ((exp(l) - exp(-l)) * J) + U;
	double t_1 = cos((K / 2.0));
	double t_2 = U + (t_1 * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))));
	double t_3 = 0.3333333333333333 * (l * (l * l));
	double tmp;
	if (l <= -8.2e+97) {
		tmp = t_2;
	} else if (l <= -0.032) {
		tmp = t_0;
	} else if (l <= 0.0065) {
		tmp = t_2;
	} else if (l <= 3.5e+51) {
		tmp = t_0;
	} else if (l <= 5.5e+102) {
		tmp = U + (t_1 * (J * (((t_3 * t_3) - ((l * 2.0) * (l * 2.0))) / (t_3 - (l * 2.0)))));
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = ((exp(l) - exp(-l)) * j) + u
    t_1 = cos((k / 2.0d0))
    t_2 = u + (t_1 * (j * (l * (2.0d0 + (l * (l * 0.3333333333333333d0))))))
    t_3 = 0.3333333333333333d0 * (l * (l * l))
    if (l <= (-8.2d+97)) then
        tmp = t_2
    else if (l <= (-0.032d0)) then
        tmp = t_0
    else if (l <= 0.0065d0) then
        tmp = t_2
    else if (l <= 3.5d+51) then
        tmp = t_0
    else if (l <= 5.5d+102) then
        tmp = u + (t_1 * (j * (((t_3 * t_3) - ((l * 2.0d0) * (l * 2.0d0))) / (t_3 - (l * 2.0d0)))))
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = ((Math.exp(l) - Math.exp(-l)) * J) + U;
	double t_1 = Math.cos((K / 2.0));
	double t_2 = U + (t_1 * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))));
	double t_3 = 0.3333333333333333 * (l * (l * l));
	double tmp;
	if (l <= -8.2e+97) {
		tmp = t_2;
	} else if (l <= -0.032) {
		tmp = t_0;
	} else if (l <= 0.0065) {
		tmp = t_2;
	} else if (l <= 3.5e+51) {
		tmp = t_0;
	} else if (l <= 5.5e+102) {
		tmp = U + (t_1 * (J * (((t_3 * t_3) - ((l * 2.0) * (l * 2.0))) / (t_3 - (l * 2.0)))));
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = ((math.exp(l) - math.exp(-l)) * J) + U
	t_1 = math.cos((K / 2.0))
	t_2 = U + (t_1 * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))))
	t_3 = 0.3333333333333333 * (l * (l * l))
	tmp = 0
	if l <= -8.2e+97:
		tmp = t_2
	elif l <= -0.032:
		tmp = t_0
	elif l <= 0.0065:
		tmp = t_2
	elif l <= 3.5e+51:
		tmp = t_0
	elif l <= 5.5e+102:
		tmp = U + (t_1 * (J * (((t_3 * t_3) - ((l * 2.0) * (l * 2.0))) / (t_3 - (l * 2.0)))))
	else:
		tmp = t_2
	return tmp
function code(J, l, K, U)
	t_0 = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U)
	t_1 = cos(Float64(K / 2.0))
	t_2 = Float64(U + Float64(t_1 * Float64(J * Float64(l * Float64(2.0 + Float64(l * Float64(l * 0.3333333333333333)))))))
	t_3 = Float64(0.3333333333333333 * Float64(l * Float64(l * l)))
	tmp = 0.0
	if (l <= -8.2e+97)
		tmp = t_2;
	elseif (l <= -0.032)
		tmp = t_0;
	elseif (l <= 0.0065)
		tmp = t_2;
	elseif (l <= 3.5e+51)
		tmp = t_0;
	elseif (l <= 5.5e+102)
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(Float64(Float64(t_3 * t_3) - Float64(Float64(l * 2.0) * Float64(l * 2.0))) / Float64(t_3 - Float64(l * 2.0))))));
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = ((exp(l) - exp(-l)) * J) + U;
	t_1 = cos((K / 2.0));
	t_2 = U + (t_1 * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))));
	t_3 = 0.3333333333333333 * (l * (l * l));
	tmp = 0.0;
	if (l <= -8.2e+97)
		tmp = t_2;
	elseif (l <= -0.032)
		tmp = t_0;
	elseif (l <= 0.0065)
		tmp = t_2;
	elseif (l <= 3.5e+51)
		tmp = t_0;
	elseif (l <= 5.5e+102)
		tmp = U + (t_1 * (J * (((t_3 * t_3) - ((l * 2.0) * (l * 2.0))) / (t_3 - (l * 2.0)))));
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(U + N[(t$95$1 * N[(J * N[(l * N[(2.0 + N[(l * N[(l * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(0.3333333333333333 * N[(l * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -8.2e+97], t$95$2, If[LessEqual[l, -0.032], t$95$0, If[LessEqual[l, 0.0065], t$95$2, If[LessEqual[l, 3.5e+51], t$95$0, If[LessEqual[l, 5.5e+102], N[(U + N[(t$95$1 * N[(J * N[(N[(N[(t$95$3 * t$95$3), $MachinePrecision] - N[(N[(l * 2.0), $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$3 - N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\ell \leq 0.0065:\\
\;\;\;\;t_2\\

\mathbf{elif}\;\ell \leq 3.5 \cdot 10^{+51}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq 5.5 \cdot 10^{+102}:\\
\;\;\;\;U + t_1 \cdot \left(J \cdot \frac{t_3 \cdot t_3 - \left(\ell \cdot 2\right) \cdot \left(\ell \cdot 2\right)}{t_3 - \ell \cdot 2}\right)\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -8.19999999999999977e97 or -0.032000000000000001 < l < 0.0064999999999999997 or 5.49999999999999981e102 < l

    1. Initial program 80.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.19999999999999977e97 < l < -0.032000000000000001 or 0.0064999999999999997 < l < 3.5e51

    1. Initial program 99.8%

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

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

    if 3.5e51 < l < 5.49999999999999981e102

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -8.2 \cdot 10^{+97}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(\ell \cdot 0.3333333333333333\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -0.032:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 0.0065:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(\ell \cdot 0.3333333333333333\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 3.5 \cdot 10^{+51}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 5.5 \cdot 10^{+102}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \frac{\left(0.3333333333333333 \cdot \left(\ell \cdot \left(\ell \cdot \ell\right)\right)\right) \cdot \left(0.3333333333333333 \cdot \left(\ell \cdot \left(\ell \cdot \ell\right)\right)\right) - \left(\ell \cdot 2\right) \cdot \left(\ell \cdot 2\right)}{0.3333333333333333 \cdot \left(\ell \cdot \left(\ell \cdot \ell\right)\right) - \ell \cdot 2}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(\ell \cdot 0.3333333333333333\right)\right)\right)\right)\\ \end{array} \]

Alternative 4: 62.9% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.9:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \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.9)
   (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25))))
   (+ U (* 2.0 (* l (* J (cos (* K 0.5))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.9) {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	} else {
		tmp = U + (2.0 * (l * (J * 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.9d0)) then
        tmp = u + ((l * j) * (2.0d0 + ((k * k) * (-0.25d0))))
    else
        tmp = u + (2.0d0 * (l * (j * 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.9) {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	} else {
		tmp = U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if math.cos((K / 2.0)) <= -0.9:
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)))
	else:
		tmp = U + (2.0 * (l * (J * math.cos((K * 0.5)))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.9)
		tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25))));
	else
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * 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.9)
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	else
		tmp = U + (2.0 * (l * (J * 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.9], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(l * N[(J * 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.9:\\
\;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\

\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \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.900000000000000022

    1. Initial program 93.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 43.5%

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 83.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 66.6%

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

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

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

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

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

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

Alternative 5: 93.0% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := U + t_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(\ell \cdot 0.3333333333333333\right)\right)\right)\right)\\ t_2 := 0.3333333333333333 \cdot \left(\ell \cdot \left(\ell \cdot \ell\right)\right)\\ t_3 := U + t_0 \cdot \left(J \cdot \frac{t_2 \cdot t_2 - \left(\ell \cdot 2\right) \cdot \left(\ell \cdot 2\right)}{t_2 - \ell \cdot 2}\right)\\ \mathbf{if}\;\ell \leq -5.6 \cdot 10^{+102}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq -5 \cdot 10^{-109}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;\ell \leq 10^{-21}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 5.5 \cdot 10^{+102}:\\ \;\;\;\;t_3\\ \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 (* J (* l (+ 2.0 (* l (* l 0.3333333333333333))))))))
        (t_2 (* 0.3333333333333333 (* l (* l l))))
        (t_3
         (+
          U
          (*
           t_0
           (*
            J
            (/ (- (* t_2 t_2) (* (* l 2.0) (* l 2.0))) (- t_2 (* l 2.0))))))))
   (if (<= l -5.6e+102)
     t_1
     (if (<= l -5e-109)
       t_3
       (if (<= l 1e-21)
         (+ U (* 2.0 (* l (* J (cos (* K 0.5))))))
         (if (<= l 5.5e+102) t_3 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 * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))));
	double t_2 = 0.3333333333333333 * (l * (l * l));
	double t_3 = U + (t_0 * (J * (((t_2 * t_2) - ((l * 2.0) * (l * 2.0))) / (t_2 - (l * 2.0)))));
	double tmp;
	if (l <= -5.6e+102) {
		tmp = t_1;
	} else if (l <= -5e-109) {
		tmp = t_3;
	} else if (l <= 1e-21) {
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	} else if (l <= 5.5e+102) {
		tmp = t_3;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    t_1 = u + (t_0 * (j * (l * (2.0d0 + (l * (l * 0.3333333333333333d0))))))
    t_2 = 0.3333333333333333d0 * (l * (l * l))
    t_3 = u + (t_0 * (j * (((t_2 * t_2) - ((l * 2.0d0) * (l * 2.0d0))) / (t_2 - (l * 2.0d0)))))
    if (l <= (-5.6d+102)) then
        tmp = t_1
    else if (l <= (-5d-109)) then
        tmp = t_3
    else if (l <= 1d-21) then
        tmp = u + (2.0d0 * (l * (j * cos((k * 0.5d0)))))
    else if (l <= 5.5d+102) then
        tmp = t_3
    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 * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))));
	double t_2 = 0.3333333333333333 * (l * (l * l));
	double t_3 = U + (t_0 * (J * (((t_2 * t_2) - ((l * 2.0) * (l * 2.0))) / (t_2 - (l * 2.0)))));
	double tmp;
	if (l <= -5.6e+102) {
		tmp = t_1;
	} else if (l <= -5e-109) {
		tmp = t_3;
	} else if (l <= 1e-21) {
		tmp = U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
	} else if (l <= 5.5e+102) {
		tmp = t_3;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = U + (t_0 * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))))
	t_2 = 0.3333333333333333 * (l * (l * l))
	t_3 = U + (t_0 * (J * (((t_2 * t_2) - ((l * 2.0) * (l * 2.0))) / (t_2 - (l * 2.0)))))
	tmp = 0
	if l <= -5.6e+102:
		tmp = t_1
	elif l <= -5e-109:
		tmp = t_3
	elif l <= 1e-21:
		tmp = U + (2.0 * (l * (J * math.cos((K * 0.5)))))
	elif l <= 5.5e+102:
		tmp = t_3
	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(J * Float64(l * Float64(2.0 + Float64(l * Float64(l * 0.3333333333333333)))))))
	t_2 = Float64(0.3333333333333333 * Float64(l * Float64(l * l)))
	t_3 = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(Float64(t_2 * t_2) - Float64(Float64(l * 2.0) * Float64(l * 2.0))) / Float64(t_2 - Float64(l * 2.0))))))
	tmp = 0.0
	if (l <= -5.6e+102)
		tmp = t_1;
	elseif (l <= -5e-109)
		tmp = t_3;
	elseif (l <= 1e-21)
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5))))));
	elseif (l <= 5.5e+102)
		tmp = t_3;
	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 * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))));
	t_2 = 0.3333333333333333 * (l * (l * l));
	t_3 = U + (t_0 * (J * (((t_2 * t_2) - ((l * 2.0) * (l * 2.0))) / (t_2 - (l * 2.0)))));
	tmp = 0.0;
	if (l <= -5.6e+102)
		tmp = t_1;
	elseif (l <= -5e-109)
		tmp = t_3;
	elseif (l <= 1e-21)
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	elseif (l <= 5.5e+102)
		tmp = t_3;
	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[(J * N[(l * N[(2.0 + N[(l * N[(l * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(0.3333333333333333 * N[(l * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(U + N[(t$95$0 * N[(J * N[(N[(N[(t$95$2 * t$95$2), $MachinePrecision] - N[(N[(l * 2.0), $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$2 - N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5.6e+102], t$95$1, If[LessEqual[l, -5e-109], t$95$3, If[LessEqual[l, 1e-21], N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.5e+102], t$95$3, t$95$1]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -5 \cdot 10^{-109}:\\
\;\;\;\;t_3\\

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

\mathbf{elif}\;\ell \leq 5.5 \cdot 10^{+102}:\\
\;\;\;\;t_3\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.60000000000000037e102 or 5.49999999999999981e102 < l

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.60000000000000037e102 < l < -5.0000000000000002e-109 or 9.99999999999999908e-22 < l < 5.49999999999999981e102

    1. Initial program 86.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.0000000000000002e-109 < l < 9.99999999999999908e-22

    1. Initial program 69.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.6 \cdot 10^{+102}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(\ell \cdot 0.3333333333333333\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -5 \cdot 10^{-109}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \frac{\left(0.3333333333333333 \cdot \left(\ell \cdot \left(\ell \cdot \ell\right)\right)\right) \cdot \left(0.3333333333333333 \cdot \left(\ell \cdot \left(\ell \cdot \ell\right)\right)\right) - \left(\ell \cdot 2\right) \cdot \left(\ell \cdot 2\right)}{0.3333333333333333 \cdot \left(\ell \cdot \left(\ell \cdot \ell\right)\right) - \ell \cdot 2}\right)\\ \mathbf{elif}\;\ell \leq 10^{-21}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 5.5 \cdot 10^{+102}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \frac{\left(0.3333333333333333 \cdot \left(\ell \cdot \left(\ell \cdot \ell\right)\right)\right) \cdot \left(0.3333333333333333 \cdot \left(\ell \cdot \left(\ell \cdot \ell\right)\right)\right) - \left(\ell \cdot 2\right) \cdot \left(\ell \cdot 2\right)}{0.3333333333333333 \cdot \left(\ell \cdot \left(\ell \cdot \ell\right)\right) - \ell \cdot 2}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(\ell \cdot 0.3333333333333333\right)\right)\right)\right)\\ \end{array} \]

Alternative 6: 87.8% accurate, 2.6× speedup?

\[\begin{array}{l} \\ U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot \left(\ell \cdot \left(\ell \cdot \ell\right)\right) + \ell \cdot 2\right)\right) \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+
  U
  (*
   (cos (/ K 2.0))
   (* J (+ (* 0.3333333333333333 (* l (* l l))) (* l 2.0))))))
double code(double J, double l, double K, double U) {
	return U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * (l * (l * l))) + (l * 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 + (cos((k / 2.0d0)) * (j * ((0.3333333333333333d0 * (l * (l * l))) + (l * 2.0d0))))
end function
public static double code(double J, double l, double K, double U) {
	return U + (Math.cos((K / 2.0)) * (J * ((0.3333333333333333 * (l * (l * l))) + (l * 2.0))));
}
def code(J, l, K, U):
	return U + (math.cos((K / 2.0)) * (J * ((0.3333333333333333 * (l * (l * l))) + (l * 2.0))))
function code(J, l, K, U)
	return Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(Float64(0.3333333333333333 * Float64(l * Float64(l * l))) + Float64(l * 2.0)))))
end
function tmp = code(J, l, K, U)
	tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * (l * (l * l))) + (l * 2.0))));
end
code[J_, l_, K_, U_] := N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(N[(0.3333333333333333 * N[(l * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot \left(\ell \cdot \left(\ell \cdot \ell\right)\right) + \ell \cdot 2\right)\right)
\end{array}
Derivation
  1. Initial program 83.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 57.7% accurate, 2.7× speedup?

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

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

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


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

    1. Initial program 85.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 67.9%

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 83.2%

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

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

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

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

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

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

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

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

Alternative 8: 87.8% accurate, 2.7× speedup?

\[\begin{array}{l} \\ U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(\ell \cdot 0.3333333333333333\right)\right)\right)\right) \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ U (* (cos (/ K 2.0)) (* J (* l (+ 2.0 (* l (* l 0.3333333333333333))))))))
double code(double J, double l, double K, double U) {
	return U + (cos((K / 2.0)) * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))));
}
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 + (cos((k / 2.0d0)) * (j * (l * (2.0d0 + (l * (l * 0.3333333333333333d0))))))
end function
public static double code(double J, double l, double K, double U) {
	return U + (Math.cos((K / 2.0)) * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))));
}
def code(J, l, K, U):
	return U + (math.cos((K / 2.0)) * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))))
function code(J, l, K, U)
	return Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * Float64(2.0 + Float64(l * Float64(l * 0.3333333333333333)))))))
end
function tmp = code(J, l, K, U)
	tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + (l * (l * 0.3333333333333333))))));
end
code[J_, l_, K_, U_] := N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * N[(2.0 + N[(l * N[(l * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(\ell \cdot 0.3333333333333333\right)\right)\right)\right)
\end{array}
Derivation
  1. Initial program 83.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 41.4% accurate, 34.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -920 \lor \neg \left(\ell \leq 1.9 \cdot 10^{+64}\right):\\
\;\;\;\;-8 - U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -920 or 1.9000000000000001e64 < 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-rr22.5%

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

        \[\leadsto \color{blue}{-8 - U \cdot U} \]
    6. Simplified22.5%

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

    if -920 < l < 1.9000000000000001e64

    1. Initial program 72.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -920 \lor \neg \left(\ell \leq 1.9 \cdot 10^{+64}\right):\\ \;\;\;\;-8 - U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 10: 51.5% accurate, 34.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

    if 1.35e64 < 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-rr24.0%

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

        \[\leadsto \color{blue}{-8 - U \cdot U} \]
    6. Simplified24.0%

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

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

Alternative 11: 41.4% accurate, 43.8× speedup?

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

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

\mathbf{elif}\;\ell \leq 6.4 \cdot 10^{+22}:\\
\;\;\;\;U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.1200000000000001e29 or 6.4e22 < l

    1. Initial program 100.0%

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

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

    if -1.1200000000000001e29 < l < 6.4e22

    1. Initial program 71.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.12 \cdot 10^{+29}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 6.4 \cdot 10^{+22}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]

Alternative 12: 2.7% accurate, 312.0× speedup?

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

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

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

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

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

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

    \[\leadsto 1 \]

Alternative 13: 36.2% 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 83.8%

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

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

    \[\leadsto U \]

Reproduce

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