Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.3% → 99.6%
Time: 10.1s
Alternatives: 10
Speedup: 1.5×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 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.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_1 \leq -5000 \lor \neg \left(t_1 \leq 0\right):\\ \;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + U\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(t_0 \cdot \left(\ell \cdot 2\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
   (if (or (<= t_1 -5000.0) (not (<= t_1 0.0)))
     (+ (* (* t_1 J) t_0) U)
     (+ U (* J (* t_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 <= -5000.0) || !(t_1 <= 0.0)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (J * (t_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 <= (-5000.0d0)) .or. (.not. (t_1 <= 0.0d0))) then
        tmp = ((t_1 * j) * t_0) + u
    else
        tmp = u + (j * (t_0 * (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 <= -5000.0) || !(t_1 <= 0.0)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (J * (t_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 <= -5000.0) or not (t_1 <= 0.0):
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (J * (t_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 <= -5000.0) || !(t_1 <= 0.0))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	else
		tmp = Float64(U + Float64(J * Float64(t_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 <= -5000.0) || ~((t_1 <= 0.0)))
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (J * (t_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, -5000.0], N[Not[LessEqual[t$95$1, 0.0]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(J * N[(t$95$0 * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)} + U \]
    5. Step-by-step derivation
      1. expm1-log1p-u84.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)\right)} + U \]
      2. expm1-udef74.8%

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right)} + U \]
      3. *-commutative74.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{\left(J \cdot \cos \left(0.5 \cdot K\right)\right)} \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      4. *-commutative74.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      5. metadata-eval74.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \left(K \cdot \color{blue}{\frac{1}{2}}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      6. div-inv74.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \color{blue}{\left(\frac{K}{2}\right)}\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      7. *-commutative74.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, \color{blue}{\ell \cdot 2}\right)\right)} - 1\right) + U \]
    6. Applied egg-rr74.8%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, \ell \cdot 2\right)\right)} - 1\right)} + U \]
    7. Step-by-step derivation
      1. expm1-def84.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, \ell \cdot 2\right)\right)\right)} + U \]
      2. expm1-log1p99.9%

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

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

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

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

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

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

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

Alternative 2: 90.6% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
t_0 := J \cdot \left(2 \cdot \sinh \ell\right)\\
\mathbf{if}\;\ell \leq -0.017:\\
\;\;\;\;U + \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot t_0\\

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

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

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


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

    1. Initial program 100.0%

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

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

        \[\leadsto \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J + \color{blue}{\left(-0.125 \cdot {K}^{2}\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)}\right) + U \]
      2. distribute-rgt1-in83.9%

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\right)} + U \]
      2. expm1-udef26.0%

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)} - 1\right)} + U \]
      3. *-commutative26.0%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)}\right)} - 1\right) + U \]
      4. sinh-undef26.0%

        \[\leadsto \left(e^{\mathsf{log1p}\left(J \cdot \color{blue}{\left(2 \cdot \sinh \ell\right)}\right)} - 1\right) + U \]
    6. Applied egg-rr38.6%

      \[\leadsto \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(J \cdot \left(2 \cdot \sinh \ell\right)\right)} - 1\right)} + U \]
    7. Step-by-step derivation
      1. expm1-def26.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(J \cdot \left(2 \cdot \sinh \ell\right)\right)\right)} + U \]
      2. expm1-log1p64.9%

        \[\leadsto \color{blue}{J \cdot \left(2 \cdot \sinh \ell\right)} + U \]
    8. Simplified83.9%

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

    if -0.017000000000000001 < l < 1.4e7

    1. Initial program 69.7%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)} + U \]
    4. Simplified99.1%

      \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)} + U \]
    5. Step-by-step derivation
      1. expm1-log1p-u84.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)\right)} + U \]
      2. expm1-udef74.4%

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right)} + U \]
      3. *-commutative74.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{\left(J \cdot \cos \left(0.5 \cdot K\right)\right)} \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      4. *-commutative74.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      5. metadata-eval74.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \left(K \cdot \color{blue}{\frac{1}{2}}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      6. div-inv74.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \color{blue}{\left(\frac{K}{2}\right)}\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      7. *-commutative74.4%

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

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, \ell \cdot 2\right)\right)} - 1\right)} + U \]
    7. Step-by-step derivation
      1. expm1-def84.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, \ell \cdot 2\right)\right)\right)} + U \]
      2. expm1-log1p99.1%

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

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

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

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

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

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

    if 1.4e7 < 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 K around 0 95.0%

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\right)} + U \]
      2. expm1-udef45.0%

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)} - 1\right)} + U \]
      3. *-commutative45.0%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)}\right)} - 1\right) + U \]
      4. sinh-undef45.0%

        \[\leadsto \left(e^{\mathsf{log1p}\left(J \cdot \color{blue}{\left(2 \cdot \sinh \ell\right)}\right)} - 1\right) + U \]
    4. Applied egg-rr45.0%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(J \cdot \left(2 \cdot \sinh \ell\right)\right)} - 1\right)} + U \]
    5. Step-by-step derivation
      1. expm1-def45.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(J \cdot \left(2 \cdot \sinh \ell\right)\right)\right)} + U \]
      2. expm1-log1p95.0%

        \[\leadsto \color{blue}{J \cdot \left(2 \cdot \sinh \ell\right)} + U \]
    6. Simplified95.0%

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

    if 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 \color{blue}{\left(2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(\ell \cdot J\right)\right) + 0.3333333333333333 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left({\ell}^{3} \cdot J\right)\right)\right)} + U \]
    3. Step-by-step derivation
      1. *-commutative100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -0.017:\\ \;\;\;\;U + \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot \left(J \cdot \left(2 \cdot \sinh \ell\right)\right)\\ \mathbf{elif}\;\ell \leq 14000000:\\ \;\;\;\;U + J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 5.5 \cdot 10^{+102}:\\ \;\;\;\;U + J \cdot \left(2 \cdot \sinh \ell\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(K \cdot 0.5\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \end{array} \]

Alternative 3: 86.6% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 87.4%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)} + U \]
    4. Simplified90.5%

      \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)} + U \]
    5. Step-by-step derivation
      1. expm1-log1p-u64.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)\right)} + U \]
      2. expm1-udef58.8%

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right)} + U \]
      3. *-commutative58.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{\left(J \cdot \cos \left(0.5 \cdot K\right)\right)} \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      4. *-commutative58.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      5. metadata-eval58.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \left(K \cdot \color{blue}{\frac{1}{2}}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      6. div-inv58.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \color{blue}{\left(\frac{K}{2}\right)}\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      7. *-commutative58.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, \color{blue}{\ell \cdot 2}\right)\right)} - 1\right) + U \]
    6. Applied egg-rr58.8%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, \ell \cdot 2\right)\right)} - 1\right)} + U \]
    7. Step-by-step derivation
      1. expm1-def64.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, \ell \cdot 2\right)\right)\right)} + U \]
      2. expm1-log1p90.5%

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

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

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

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

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

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

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

    1. Initial program 83.9%

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\right)} + U \]
      2. expm1-udef55.3%

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)} - 1\right)} + U \]
      3. *-commutative55.3%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)}\right)} - 1\right) + U \]
      4. sinh-undef55.7%

        \[\leadsto \left(e^{\mathsf{log1p}\left(J \cdot \color{blue}{\left(2 \cdot \sinh \ell\right)}\right)} - 1\right) + U \]
    4. Applied egg-rr55.7%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(J \cdot \left(2 \cdot \sinh \ell\right)\right)} - 1\right)} + U \]
    5. Step-by-step derivation
      1. expm1-def59.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(J \cdot \left(2 \cdot \sinh \ell\right)\right)\right)} + U \]
      2. expm1-log1p94.5%

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

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

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

Alternative 4: 82.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.55:\\ \;\;\;\;U + \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(2 \cdot \sinh \ell\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.55)
   (+ U (* (+ (* -0.125 (* K K)) 1.0) (* J (* l 2.0))))
   (+ U (* J (* 2.0 (sinh l))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.55) {
		tmp = U + (((-0.125 * (K * K)) + 1.0) * (J * (l * 2.0)));
	} else {
		tmp = U + (J * (2.0 * sinh(l)));
	}
	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.55d0)) then
        tmp = u + ((((-0.125d0) * (k * k)) + 1.0d0) * (j * (l * 2.0d0)))
    else
        tmp = u + (j * (2.0d0 * sinh(l)))
    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.55) {
		tmp = U + (((-0.125 * (K * K)) + 1.0) * (J * (l * 2.0)));
	} else {
		tmp = U + (J * (2.0 * Math.sinh(l)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if math.cos((K / 2.0)) <= -0.55:
		tmp = U + (((-0.125 * (K * K)) + 1.0) * (J * (l * 2.0)))
	else:
		tmp = U + (J * (2.0 * math.sinh(l)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.55)
		tmp = Float64(U + Float64(Float64(Float64(-0.125 * Float64(K * K)) + 1.0) * Float64(J * Float64(l * 2.0))));
	else
		tmp = Float64(U + Float64(J * Float64(2.0 * sinh(l))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (cos((K / 2.0)) <= -0.55)
		tmp = U + (((-0.125 * (K * K)) + 1.0) * (J * (l * 2.0)));
	else
		tmp = U + (J * (2.0 * sinh(l)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.55], N[(U + N[(N[(N[(-0.125 * N[(K * K), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(2.0 * N[Sinh[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 86.9%

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

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

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

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

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

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

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

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

    1. Initial program 84.5%

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\right)} + U \]
      2. expm1-udef54.6%

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)} - 1\right)} + U \]
      3. *-commutative54.6%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)}\right)} - 1\right) + U \]
      4. sinh-undef54.9%

        \[\leadsto \left(e^{\mathsf{log1p}\left(J \cdot \color{blue}{\left(2 \cdot \sinh \ell\right)}\right)} - 1\right) + U \]
    4. Applied egg-rr54.9%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(J \cdot \left(2 \cdot \sinh \ell\right)\right)} - 1\right)} + U \]
    5. Step-by-step derivation
      1. expm1-def58.1%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(J \cdot \left(2 \cdot \sinh \ell\right)\right)\right)} + U \]
      2. expm1-log1p88.6%

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

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

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

Alternative 5: 86.2% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
t_0 := J \cdot \left(2 \cdot \sinh \ell\right)\\
\mathbf{if}\;\ell \leq -4:\\
\;\;\;\;U + \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot t_0\\

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

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


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

    1. Initial program 100.0%

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

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

        \[\leadsto \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J + \color{blue}{\left(-0.125 \cdot {K}^{2}\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)}\right) + U \]
      2. distribute-rgt1-in83.9%

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\right)} + U \]
      2. expm1-udef26.0%

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)} - 1\right)} + U \]
      3. *-commutative26.0%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)}\right)} - 1\right) + U \]
      4. sinh-undef26.0%

        \[\leadsto \left(e^{\mathsf{log1p}\left(J \cdot \color{blue}{\left(2 \cdot \sinh \ell\right)}\right)} - 1\right) + U \]
    6. Applied egg-rr38.6%

      \[\leadsto \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(J \cdot \left(2 \cdot \sinh \ell\right)\right)} - 1\right)} + U \]
    7. Step-by-step derivation
      1. expm1-def26.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(J \cdot \left(2 \cdot \sinh \ell\right)\right)\right)} + U \]
      2. expm1-log1p64.9%

        \[\leadsto \color{blue}{J \cdot \left(2 \cdot \sinh \ell\right)} + U \]
    8. Simplified83.9%

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

    if -4 < l < 1.4e7

    1. Initial program 69.7%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)} + U \]
    4. Simplified99.1%

      \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)} + U \]
    5. Step-by-step derivation
      1. expm1-log1p-u84.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)\right)} + U \]
      2. expm1-udef74.4%

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right)} + U \]
      3. *-commutative74.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{\left(J \cdot \cos \left(0.5 \cdot K\right)\right)} \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      4. *-commutative74.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      5. metadata-eval74.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \left(K \cdot \color{blue}{\frac{1}{2}}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      6. div-inv74.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \color{blue}{\left(\frac{K}{2}\right)}\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} - 1\right) + U \]
      7. *-commutative74.4%

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

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, \ell \cdot 2\right)\right)} - 1\right)} + U \]
    7. Step-by-step derivation
      1. expm1-def84.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, \ell \cdot 2\right)\right)\right)} + U \]
      2. expm1-log1p99.1%

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

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

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

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

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

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

    if 1.4e7 < l

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\right)} + U \]
      2. expm1-udef36.4%

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)} - 1\right)} + U \]
      3. *-commutative36.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)}\right)} - 1\right) + U \]
      4. sinh-undef36.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(J \cdot \color{blue}{\left(2 \cdot \sinh \ell\right)}\right)} - 1\right) + U \]
    4. Applied egg-rr36.4%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(J \cdot \left(2 \cdot \sinh \ell\right)\right)} - 1\right)} + U \]
    5. Step-by-step derivation
      1. expm1-def36.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(J \cdot \left(2 \cdot \sinh \ell\right)\right)\right)} + U \]
      2. expm1-log1p80.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4:\\ \;\;\;\;U + \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot \left(J \cdot \left(2 \cdot \sinh \ell\right)\right)\\ \mathbf{elif}\;\ell \leq 14000000:\\ \;\;\;\;U + J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(2 \cdot \sinh \ell\right)\\ \end{array} \]

Alternative 6: 58.7% accurate, 16.3× speedup?

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

\\
\begin{array}{l}
t_0 := J \cdot \left(\ell \cdot 2\right)\\
\mathbf{if}\;\ell \leq -1.9 \cdot 10^{-38}:\\
\;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\

\mathbf{elif}\;\ell \leq 5 \cdot 10^{-27}:\\
\;\;\;\;U + t_0\\

\mathbf{else}:\\
\;\;\;\;U + \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot t_0\\


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

    1. Initial program 98.4%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)} + U \]
    4. Simplified74.0%

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

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

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

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

      \[\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 \]
    9. Step-by-step derivation
      1. +-commutative10.1%

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

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

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

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

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

    if -1.9e-38 < l < 5.0000000000000002e-27

    1. Initial program 69.5%

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

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

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

    if 5.0000000000000002e-27 < l

    1. Initial program 100.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.9 \cdot 10^{-38}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{elif}\;\ell \leq 5 \cdot 10^{-27}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \end{array} \]

Alternative 7: 58.7% accurate, 18.2× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.9e-38 or 5.0000000000000002e-27 < l

    1. Initial program 99.3%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)} + U \]
    4. Simplified75.1%

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

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

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

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

      \[\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 \]
    9. Step-by-step derivation
      1. +-commutative10.4%

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

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

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

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

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

    if -1.9e-38 < l < 5.0000000000000002e-27

    1. Initial program 69.5%

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

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

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

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

Alternative 8: 43.5% accurate, 28.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.9 \cdot 10^{-38} \lor \neg \left(\ell \leq 38000000\right):\\
\;\;\;\;U + J \cdot \left(K \cdot K\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.9e-38 or 3.8e7 < l

    1. Initial program 99.2%

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

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

      \[\leadsto \color{blue}{\left({K}^{2} \cdot J + -8 \cdot J\right)} + U \]
    4. Step-by-step derivation
      1. distribute-rgt-out17.2%

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

        \[\leadsto J \cdot \left(\color{blue}{K \cdot K} + -8\right) + U \]
    5. Simplified17.2%

      \[\leadsto \color{blue}{J \cdot \left(K \cdot K + -8\right)} + U \]
    6. Taylor expanded in K around inf 17.0%

      \[\leadsto \color{blue}{{K}^{2} \cdot J} + U \]
    7. Step-by-step derivation
      1. unpow217.0%

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

        \[\leadsto \color{blue}{J \cdot \left(K \cdot K\right)} + U \]
    8. Simplified17.0%

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

    if -1.9e-38 < l < 3.8e7

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)} + U \]
    4. Simplified99.1%

      \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)} + U \]
    5. Taylor expanded in J around 0 69.5%

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

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

Alternative 9: 53.9% accurate, 44.6× speedup?

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

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

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

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

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

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

Alternative 10: 36.7% accurate, 312.0× speedup?

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

\\
U
\end{array}
Derivation
  1. Initial program 84.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 87.1%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)} + U \]
  4. Simplified87.1%

    \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot K\right) \cdot J\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)} + U \]
  5. Taylor expanded in J around 0 35.6%

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

    \[\leadsto U \]

Reproduce

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