Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.2% → 99.8%
Time: 16.4s
Alternatives: 14
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 86.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{+24} \lor \neg \left(t_0 \leq 2 \cdot 10^{-6}\right):\\ \;\;\;\;\cos \left(\frac{K}{2}\right) \cdot \left(t_0 \cdot J\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, \ell \cdot 2\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))))
   (if (or (<= t_0 -2e+24) (not (<= t_0 2e-6)))
     (+ (* (cos (/ K 2.0)) (* t_0 J)) U)
     (+
      U
      (*
       J
       (* (fma 0.3333333333333333 (pow l 3.0) (* l 2.0)) (cos (* K 0.5))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -2e+24) || !(t_0 <= 2e-6)) {
		tmp = (cos((K / 2.0)) * (t_0 * J)) + U;
	} else {
		tmp = U + (J * (fma(0.3333333333333333, pow(l, 3.0), (l * 2.0)) * cos((K * 0.5))));
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= -2e+24) || !(t_0 <= 2e-6))
		tmp = Float64(Float64(cos(Float64(K / 2.0)) * Float64(t_0 * J)) + U);
	else
		tmp = Float64(U + Float64(J * Float64(fma(0.3333333333333333, (l ^ 3.0), Float64(l * 2.0)) * cos(Float64(K * 0.5)))));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e+24], N[Not[LessEqual[t$95$0, 2e-6]], $MachinePrecision]], N[(N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(t$95$0 * J), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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


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

    1. Initial program 69.9%

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

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

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

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

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

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

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

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

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

Alternative 2: 99.8% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 69.9%

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

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

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

Alternative 3: 94.5% accurate, 1.4× speedup?

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

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

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

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

\mathbf{elif}\;\ell \leq 6.3 \cdot 10^{+100}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -4.99999999999999962e125 or 6.3000000000000004e100 < l

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.99999999999999962e125 < l < -57 or 1.65e10 < l < 6.3000000000000004e100

    1. Initial program 100.0%

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

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

    if -57 < l < 1.65e10

    1. Initial program 70.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5 \cdot 10^{+125}:\\ \;\;\;\;U + \cos \left(K \cdot 0.5\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -57:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 16500000000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 6.3 \cdot 10^{+100}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(K \cdot 0.5\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \end{array} \]

Alternative 4: 94.8% accurate, 1.4× speedup?

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

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

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

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

\mathbf{elif}\;\ell \leq 6.5 \cdot 10^{+100}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.95999999999999994e105 or 6.50000000000000001e100 < l

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.95999999999999994e105 < l < -57 or 1.65e10 < l < 6.50000000000000001e100

    1. Initial program 100.0%

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

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

    if -57 < l < 1.65e10

    1. Initial program 70.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.96 \cdot 10^{+105}:\\ \;\;\;\;U + \cos \left(K \cdot 0.5\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -57:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 16500000000:\\ \;\;\;\;U + \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(J \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 6.5 \cdot 10^{+100}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(K \cdot 0.5\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \end{array} \]

Alternative 5: 77.9% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

    1. Initial program 90.8%

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

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

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

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

Alternative 6: 81.3% accurate, 1.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.60000000000000008e143

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.60000000000000008e143 < J < 1.4500000000000001e73

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

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

    if 1.4500000000000001e73 < J

    1. Initial program 75.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.6 \cdot 10^{+143}:\\ \;\;\;\;U + \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(J \cdot 2\right)\\ \mathbf{elif}\;J \leq 1.45 \cdot 10^{+73}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]

Alternative 7: 64.2% accurate, 2.8× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 8: 64.2% accurate, 2.8× speedup?

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

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

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

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

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

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

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

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

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

Alternative 9: 64.2% accurate, 2.8× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 60.2% accurate, 18.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -56 \lor \neg \left(\ell \leq 260\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 -56.0) (not (<= l 260.0)))
   (+ 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 <= -56.0) || !(l <= 260.0)) {
		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 <= (-56.0d0)) .or. (.not. (l <= 260.0d0))) 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 <= -56.0) || !(l <= 260.0)) {
		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 <= -56.0) or not (l <= 260.0):
		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 <= -56.0) || !(l <= 260.0))
		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 <= -56.0) || ~((l <= 260.0)))
		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, -56.0], N[Not[LessEqual[l, 260.0]], $MachinePrecision]], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -56 \lor \neg \left(\ell \leq 260\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 < -56 or 260 < 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 34.1%

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

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

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

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

      \[\leadsto \color{blue}{\left(\ell \cdot \left(2 \cdot J\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Taylor expanded in K around 0 13.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 \]
    6. Step-by-step derivation
      1. +-commutative13.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. associate-*r*13.1%

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

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

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

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

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

    if -56 < l < 260

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -56 \lor \neg \left(\ell \leq 260\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 11: 41.7% accurate, 23.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U \cdot \left(U \cdot -134217728\right)\\ \mathbf{if}\;\ell \leq -3.2 \cdot 10^{+133}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -2.75 \cdot 10^{+60}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -56 \lor \neg \left(\ell \leq 1.35 \cdot 10^{+74}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* U (* U -134217728.0))))
   (if (<= l -3.2e+133)
     t_0
     (if (<= l -2.75e+60)
       (* U U)
       (if (or (<= l -56.0) (not (<= l 1.35e+74))) t_0 U)))))
double code(double J, double l, double K, double U) {
	double t_0 = U * (U * -134217728.0);
	double tmp;
	if (l <= -3.2e+133) {
		tmp = t_0;
	} else if (l <= -2.75e+60) {
		tmp = U * U;
	} else if ((l <= -56.0) || !(l <= 1.35e+74)) {
		tmp = t_0;
	} else {
		tmp = U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = u * (u * (-134217728.0d0))
    if (l <= (-3.2d+133)) then
        tmp = t_0
    else if (l <= (-2.75d+60)) then
        tmp = u * u
    else if ((l <= (-56.0d0)) .or. (.not. (l <= 1.35d+74))) then
        tmp = t_0
    else
        tmp = u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U * (U * -134217728.0);
	double tmp;
	if (l <= -3.2e+133) {
		tmp = t_0;
	} else if (l <= -2.75e+60) {
		tmp = U * U;
	} else if ((l <= -56.0) || !(l <= 1.35e+74)) {
		tmp = t_0;
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U * (U * -134217728.0)
	tmp = 0
	if l <= -3.2e+133:
		tmp = t_0
	elif l <= -2.75e+60:
		tmp = U * U
	elif (l <= -56.0) or not (l <= 1.35e+74):
		tmp = t_0
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U * Float64(U * -134217728.0))
	tmp = 0.0
	if (l <= -3.2e+133)
		tmp = t_0;
	elseif (l <= -2.75e+60)
		tmp = Float64(U * U);
	elseif ((l <= -56.0) || !(l <= 1.35e+74))
		tmp = t_0;
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U * (U * -134217728.0);
	tmp = 0.0;
	if (l <= -3.2e+133)
		tmp = t_0;
	elseif (l <= -2.75e+60)
		tmp = U * U;
	elseif ((l <= -56.0) || ~((l <= 1.35e+74)))
		tmp = t_0;
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U * N[(U * -134217728.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.2e+133], t$95$0, If[LessEqual[l, -2.75e+60], N[(U * U), $MachinePrecision], If[Or[LessEqual[l, -56.0], N[Not[LessEqual[l, 1.35e+74]], $MachinePrecision]], t$95$0, U]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U \cdot \left(U \cdot -134217728\right)\\
\mathbf{if}\;\ell \leq -3.2 \cdot 10^{+133}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -2.75 \cdot 10^{+60}:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq -56 \lor \neg \left(\ell \leq 1.35 \cdot 10^{+74}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.19999999999999997e133 or -2.75e60 < l < -56 or 1.3499999999999999e74 < l

    1. Initial program 100.0%

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

      \[\leadsto \left(J \cdot \color{blue}{512}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    3. Applied egg-rr21.7%

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

    if -3.19999999999999997e133 < l < -2.75e60

    1. Initial program 100.0%

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

      \[\leadsto \left(J \cdot \color{blue}{512}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    3. Applied egg-rr37.3%

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

    if -56 < l < 1.3499999999999999e74

    1. Initial program 73.5%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.2 \cdot 10^{+133}:\\ \;\;\;\;U \cdot \left(U \cdot -134217728\right)\\ \mathbf{elif}\;\ell \leq -2.75 \cdot 10^{+60}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -56 \lor \neg \left(\ell \leq 1.35 \cdot 10^{+74}\right):\\ \;\;\;\;U \cdot \left(U \cdot -134217728\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 12: 41.7% accurate, 43.8× speedup?

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

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

\mathbf{elif}\;\ell \leq 6.2 \cdot 10^{-7}:\\
\;\;\;\;U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.55e15 or 6.1999999999999999e-7 < l

    1. Initial program 99.8%

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

      \[\leadsto \left(J \cdot \color{blue}{512}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    3. Applied egg-rr12.6%

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

    if -1.55e15 < l < 6.1999999999999999e-7

    1. Initial program 70.7%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.55 \cdot 10^{+15}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 6.2 \cdot 10^{-7}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]

Alternative 13: 54.1% 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 86.8%

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

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

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

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

Alternative 14: 36.5% accurate, 312.0× speedup?

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

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

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

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

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

    \[\leadsto U \]

Reproduce

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