Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.2% → 99.5%
Time: 12.1s
Alternatives: 17
Speedup: 2.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 17 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.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ (* (* J (log1p (expm1 (* l 2.0)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
	return ((J * log1p(expm1((l * 2.0)))) * cos((K / 2.0))) + U;
}
public static double code(double J, double l, double K, double U) {
	return ((J * Math.log1p(Math.expm1((l * 2.0)))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U):
	return ((J * math.log1p(math.expm1((l * 2.0)))) * math.cos((K / 2.0))) + U
function code(J, l, K, U)
	return Float64(Float64(Float64(J * log1p(expm1(Float64(l * 2.0)))) * cos(Float64(K / 2.0))) + U)
end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[Log[1 + N[(Exp[N[(l * 2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

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

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

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

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

      \[\leadsto \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\ell \cdot 2}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  5. Applied egg-rr99.1%

    \[\leadsto \left(J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  6. Add Preprocessing

Alternative 2: 98.4% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ t_1 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;\ell \leq -125:\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(27 - t\_0\right)\right)\\ \mathbf{elif}\;\ell \leq 0.047:\\ \;\;\;\;U + t\_1 \cdot \left(\ell \cdot \left(J \cdot 2 + {\ell}^{2} \cdot \left(0.016666666666666666 \cdot \left(J \cdot \left(\ell \cdot \ell\right)\right) + J \cdot 0.3333333333333333\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.08 \cdot 10^{+61}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \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))) (t_1 (cos (/ K 2.0))))
   (if (<= l -125.0)
     (+ U (* t_1 (* J (- 27.0 t_0))))
     (if (<= l 0.047)
       (+
        U
        (*
         t_1
         (*
          l
          (+
           (* J 2.0)
           (*
            (pow l 2.0)
            (+
             (* 0.016666666666666666 (* J (* l l)))
             (* J 0.3333333333333333)))))))
       (if (<= l 1.08e+61)
         (+ U (* J (- (exp l) t_0)))
         (+
          U
          (* (* J 0.016666666666666666) (* (pow l 5.0) (cos (* K -0.5))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(-l);
	double t_1 = cos((K / 2.0));
	double tmp;
	if (l <= -125.0) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if (l <= 0.047) {
		tmp = U + (t_1 * (l * ((J * 2.0) + (pow(l, 2.0) * ((0.016666666666666666 * (J * (l * l))) + (J * 0.3333333333333333))))));
	} else if (l <= 1.08e+61) {
		tmp = U + (J * (exp(l) - t_0));
	} else {
		tmp = U + ((J * 0.016666666666666666) * (pow(l, 5.0) * cos((K * -0.5))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp(-l)
    t_1 = cos((k / 2.0d0))
    if (l <= (-125.0d0)) then
        tmp = u + (t_1 * (j * (27.0d0 - t_0)))
    else if (l <= 0.047d0) then
        tmp = u + (t_1 * (l * ((j * 2.0d0) + ((l ** 2.0d0) * ((0.016666666666666666d0 * (j * (l * l))) + (j * 0.3333333333333333d0))))))
    else if (l <= 1.08d+61) then
        tmp = u + (j * (exp(l) - t_0))
    else
        tmp = u + ((j * 0.016666666666666666d0) * ((l ** 5.0d0) * cos((k * (-0.5d0)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(-l);
	double t_1 = Math.cos((K / 2.0));
	double tmp;
	if (l <= -125.0) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if (l <= 0.047) {
		tmp = U + (t_1 * (l * ((J * 2.0) + (Math.pow(l, 2.0) * ((0.016666666666666666 * (J * (l * l))) + (J * 0.3333333333333333))))));
	} else if (l <= 1.08e+61) {
		tmp = U + (J * (Math.exp(l) - t_0));
	} else {
		tmp = U + ((J * 0.016666666666666666) * (Math.pow(l, 5.0) * Math.cos((K * -0.5))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(-l)
	t_1 = math.cos((K / 2.0))
	tmp = 0
	if l <= -125.0:
		tmp = U + (t_1 * (J * (27.0 - t_0)))
	elif l <= 0.047:
		tmp = U + (t_1 * (l * ((J * 2.0) + (math.pow(l, 2.0) * ((0.016666666666666666 * (J * (l * l))) + (J * 0.3333333333333333))))))
	elif l <= 1.08e+61:
		tmp = U + (J * (math.exp(l) - t_0))
	else:
		tmp = U + ((J * 0.016666666666666666) * (math.pow(l, 5.0) * math.cos((K * -0.5))))
	return tmp
function code(J, l, K, U)
	t_0 = exp(Float64(-l))
	t_1 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (l <= -125.0)
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(27.0 - t_0))));
	elseif (l <= 0.047)
		tmp = Float64(U + Float64(t_1 * Float64(l * Float64(Float64(J * 2.0) + Float64((l ^ 2.0) * Float64(Float64(0.016666666666666666 * Float64(J * Float64(l * l))) + Float64(J * 0.3333333333333333)))))));
	elseif (l <= 1.08e+61)
		tmp = Float64(U + Float64(J * Float64(exp(l) - t_0)));
	else
		tmp = Float64(U + Float64(Float64(J * 0.016666666666666666) * Float64((l ^ 5.0) * cos(Float64(K * -0.5)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(-l);
	t_1 = cos((K / 2.0));
	tmp = 0.0;
	if (l <= -125.0)
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	elseif (l <= 0.047)
		tmp = U + (t_1 * (l * ((J * 2.0) + ((l ^ 2.0) * ((0.016666666666666666 * (J * (l * l))) + (J * 0.3333333333333333))))));
	elseif (l <= 1.08e+61)
		tmp = U + (J * (exp(l) - t_0));
	else
		tmp = U + ((J * 0.016666666666666666) * ((l ^ 5.0) * cos((K * -0.5))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -125.0], N[(U + N[(t$95$1 * N[(J * N[(27.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 0.047], N[(U + N[(t$95$1 * N[(l * N[(N[(J * 2.0), $MachinePrecision] + N[(N[Power[l, 2.0], $MachinePrecision] * N[(N[(0.016666666666666666 * N[(J * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.08e+61], N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(J * 0.016666666666666666), $MachinePrecision] * N[(N[Power[l, 5.0], $MachinePrecision] * N[Cos[N[(K * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
t_1 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;\ell \leq -125:\\
\;\;\;\;U + t\_1 \cdot \left(J \cdot \left(27 - t\_0\right)\right)\\

\mathbf{elif}\;\ell \leq 0.047:\\
\;\;\;\;U + t\_1 \cdot \left(\ell \cdot \left(J \cdot 2 + {\ell}^{2} \cdot \left(0.016666666666666666 \cdot \left(J \cdot \left(\ell \cdot \ell\right)\right) + J \cdot 0.3333333333333333\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 1.08 \cdot 10^{+61}:\\
\;\;\;\;U + J \cdot \left(e^{\ell} - t\_0\right)\\

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


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

    1. Initial program 100.0%

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

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

    if -125 < l < 0.047

    1. Initial program 74.8%

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

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

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

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

    if 0.047 < l < 1.08e61

    1. Initial program 100.0%

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

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

    if 1.08e61 < 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. Add Preprocessing
    3. Taylor expanded in l around 0 100.0%

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

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

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

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

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

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

        \[\leadsto \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) + U \]
      4. metadata-eval100.0%

        \[\leadsto \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \left(K \cdot \color{blue}{\left(--0.5\right)}\right)\right) + U \]
      5. distribute-rgt-neg-in100.0%

        \[\leadsto \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \color{blue}{\left(-K \cdot -0.5\right)}\right) + U \]
      6. cos-neg100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -125:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(27 - e^{-\ell}\right)\right)\\ \mathbf{elif}\;\ell \leq 0.047:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2 + {\ell}^{2} \cdot \left(0.016666666666666666 \cdot \left(J \cdot \left(\ell \cdot \ell\right)\right) + J \cdot 0.3333333333333333\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.08 \cdot 10^{+61}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \left(K \cdot -0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 94.4% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -3.3 \cdot 10^{+133} \lor \neg \left(\ell \leq -0.0019 \lor \neg \left(\ell \leq 0.035\right) \land \ell \leq 2.2 \cdot 10^{+88}\right):\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot 0.3333333333333333\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -3.3e+133)
         (not (or (<= l -0.0019) (and (not (<= l 0.035)) (<= l 2.2e+88)))))
   (+ U (* (cos (/ K 2.0)) (* J (* l (+ 2.0 (* (* l l) 0.3333333333333333))))))
   (+ U (* J (- (exp l) (exp (- l)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -3.3e+133) || !((l <= -0.0019) || (!(l <= 0.035) && (l <= 2.2e+88)))) {
		tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * 0.3333333333333333)))));
	} else {
		tmp = U + (J * (exp(l) - exp(-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 ((l <= (-3.3d+133)) .or. (.not. (l <= (-0.0019d0)) .or. (.not. (l <= 0.035d0)) .and. (l <= 2.2d+88))) then
        tmp = u + (cos((k / 2.0d0)) * (j * (l * (2.0d0 + ((l * l) * 0.3333333333333333d0)))))
    else
        tmp = u + (j * (exp(l) - exp(-l)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -3.3e+133) || !((l <= -0.0019) || (!(l <= 0.035) && (l <= 2.2e+88)))) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * 0.3333333333333333)))));
	} else {
		tmp = U + (J * (Math.exp(l) - Math.exp(-l)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -3.3e+133) or not ((l <= -0.0019) or (not (l <= 0.035) and (l <= 2.2e+88))):
		tmp = U + (math.cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * 0.3333333333333333)))))
	else:
		tmp = U + (J * (math.exp(l) - math.exp(-l)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -3.3e+133) || !((l <= -0.0019) || (!(l <= 0.035) && (l <= 2.2e+88))))
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * Float64(2.0 + Float64(Float64(l * l) * 0.3333333333333333))))));
	else
		tmp = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -3.3e+133) || ~(((l <= -0.0019) || (~((l <= 0.035)) && (l <= 2.2e+88)))))
		tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * 0.3333333333333333)))));
	else
		tmp = U + (J * (exp(l) - exp(-l)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -3.3e+133], N[Not[Or[LessEqual[l, -0.0019], And[N[Not[LessEqual[l, 0.035]], $MachinePrecision], LessEqual[l, 2.2e+88]]]], $MachinePrecision]], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * N[(2.0 + N[(N[(l * l), $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.3 \cdot 10^{+133} \lor \neg \left(\ell \leq -0.0019 \lor \neg \left(\ell \leq 0.035\right) \land \ell \leq 2.2 \cdot 10^{+88}\right):\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot 0.3333333333333333\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -3.3e133 or -0.0019 < l < 0.035000000000000003 or 2.20000000000000009e88 < l

    1. Initial program 85.0%

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

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

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

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

    if -3.3e133 < l < -0.0019 or 0.035000000000000003 < l < 2.20000000000000009e88

    1. Initial program 99.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.3 \cdot 10^{+133} \lor \neg \left(\ell \leq -0.0019 \lor \neg \left(\ell \leq 0.035\right) \land \ell \leq 2.2 \cdot 10^{+88}\right):\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot 0.3333333333333333\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 98.4% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ t_1 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;\ell \leq -125:\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(27 - t\_0\right)\right)\\ \mathbf{elif}\;\ell \leq 0.058:\\ \;\;\;\;U + t\_1 \cdot \left(\ell \cdot \left(J \cdot 2 + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 4.3 \cdot 10^{+61}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \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))) (t_1 (cos (/ K 2.0))))
   (if (<= l -125.0)
     (+ U (* t_1 (* J (- 27.0 t_0))))
     (if (<= l 0.058)
       (+
        U
        (* t_1 (* l (+ (* J 2.0) (* 0.3333333333333333 (* J (pow l 2.0)))))))
       (if (<= l 4.3e+61)
         (+ U (* J (- (exp l) t_0)))
         (+
          U
          (* (* J 0.016666666666666666) (* (pow l 5.0) (cos (* K -0.5))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(-l);
	double t_1 = cos((K / 2.0));
	double tmp;
	if (l <= -125.0) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if (l <= 0.058) {
		tmp = U + (t_1 * (l * ((J * 2.0) + (0.3333333333333333 * (J * pow(l, 2.0))))));
	} else if (l <= 4.3e+61) {
		tmp = U + (J * (exp(l) - t_0));
	} else {
		tmp = U + ((J * 0.016666666666666666) * (pow(l, 5.0) * cos((K * -0.5))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp(-l)
    t_1 = cos((k / 2.0d0))
    if (l <= (-125.0d0)) then
        tmp = u + (t_1 * (j * (27.0d0 - t_0)))
    else if (l <= 0.058d0) then
        tmp = u + (t_1 * (l * ((j * 2.0d0) + (0.3333333333333333d0 * (j * (l ** 2.0d0))))))
    else if (l <= 4.3d+61) then
        tmp = u + (j * (exp(l) - t_0))
    else
        tmp = u + ((j * 0.016666666666666666d0) * ((l ** 5.0d0) * cos((k * (-0.5d0)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(-l);
	double t_1 = Math.cos((K / 2.0));
	double tmp;
	if (l <= -125.0) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if (l <= 0.058) {
		tmp = U + (t_1 * (l * ((J * 2.0) + (0.3333333333333333 * (J * Math.pow(l, 2.0))))));
	} else if (l <= 4.3e+61) {
		tmp = U + (J * (Math.exp(l) - t_0));
	} else {
		tmp = U + ((J * 0.016666666666666666) * (Math.pow(l, 5.0) * Math.cos((K * -0.5))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(-l)
	t_1 = math.cos((K / 2.0))
	tmp = 0
	if l <= -125.0:
		tmp = U + (t_1 * (J * (27.0 - t_0)))
	elif l <= 0.058:
		tmp = U + (t_1 * (l * ((J * 2.0) + (0.3333333333333333 * (J * math.pow(l, 2.0))))))
	elif l <= 4.3e+61:
		tmp = U + (J * (math.exp(l) - t_0))
	else:
		tmp = U + ((J * 0.016666666666666666) * (math.pow(l, 5.0) * math.cos((K * -0.5))))
	return tmp
function code(J, l, K, U)
	t_0 = exp(Float64(-l))
	t_1 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (l <= -125.0)
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(27.0 - t_0))));
	elseif (l <= 0.058)
		tmp = Float64(U + Float64(t_1 * Float64(l * Float64(Float64(J * 2.0) + Float64(0.3333333333333333 * Float64(J * (l ^ 2.0)))))));
	elseif (l <= 4.3e+61)
		tmp = Float64(U + Float64(J * Float64(exp(l) - t_0)));
	else
		tmp = Float64(U + Float64(Float64(J * 0.016666666666666666) * Float64((l ^ 5.0) * cos(Float64(K * -0.5)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(-l);
	t_1 = cos((K / 2.0));
	tmp = 0.0;
	if (l <= -125.0)
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	elseif (l <= 0.058)
		tmp = U + (t_1 * (l * ((J * 2.0) + (0.3333333333333333 * (J * (l ^ 2.0))))));
	elseif (l <= 4.3e+61)
		tmp = U + (J * (exp(l) - t_0));
	else
		tmp = U + ((J * 0.016666666666666666) * ((l ^ 5.0) * cos((K * -0.5))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -125.0], N[(U + N[(t$95$1 * N[(J * N[(27.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 0.058], N[(U + N[(t$95$1 * N[(l * N[(N[(J * 2.0), $MachinePrecision] + N[(0.3333333333333333 * N[(J * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 4.3e+61], N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(J * 0.016666666666666666), $MachinePrecision] * N[(N[Power[l, 5.0], $MachinePrecision] * N[Cos[N[(K * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
t_1 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;\ell \leq -125:\\
\;\;\;\;U + t\_1 \cdot \left(J \cdot \left(27 - t\_0\right)\right)\\

\mathbf{elif}\;\ell \leq 0.058:\\
\;\;\;\;U + t\_1 \cdot \left(\ell \cdot \left(J \cdot 2 + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 4.3 \cdot 10^{+61}:\\
\;\;\;\;U + J \cdot \left(e^{\ell} - t\_0\right)\\

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


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

    1. Initial program 100.0%

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

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

    if -125 < l < 0.0580000000000000029

    1. Initial program 74.8%

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

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

    if 0.0580000000000000029 < l < 4.3000000000000001e61

    1. Initial program 100.0%

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

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

    if 4.3000000000000001e61 < 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. Add Preprocessing
    3. Taylor expanded in l around 0 100.0%

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

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

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

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

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

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

        \[\leadsto \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) + U \]
      4. metadata-eval100.0%

        \[\leadsto \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \left(K \cdot \color{blue}{\left(--0.5\right)}\right)\right) + U \]
      5. distribute-rgt-neg-in100.0%

        \[\leadsto \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \color{blue}{\left(-K \cdot -0.5\right)}\right) + U \]
      6. cos-neg100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -125:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(27 - e^{-\ell}\right)\right)\\ \mathbf{elif}\;\ell \leq 0.058:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2 + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 4.3 \cdot 10^{+61}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \left(K \cdot -0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 98.4% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ t_1 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;\ell \leq -125:\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(27 - t\_0\right)\right)\\ \mathbf{elif}\;\ell \leq 0.06:\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot 0.3333333333333333\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2 \cdot 10^{+58}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \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))) (t_1 (cos (/ K 2.0))))
   (if (<= l -125.0)
     (+ U (* t_1 (* J (- 27.0 t_0))))
     (if (<= l 0.06)
       (+ U (* t_1 (* J (* l (+ 2.0 (* (* l l) 0.3333333333333333))))))
       (if (<= l 2e+58)
         (+ U (* J (- (exp l) t_0)))
         (+
          U
          (* (* J 0.016666666666666666) (* (pow l 5.0) (cos (* K -0.5))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(-l);
	double t_1 = cos((K / 2.0));
	double tmp;
	if (l <= -125.0) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if (l <= 0.06) {
		tmp = U + (t_1 * (J * (l * (2.0 + ((l * l) * 0.3333333333333333)))));
	} else if (l <= 2e+58) {
		tmp = U + (J * (exp(l) - t_0));
	} else {
		tmp = U + ((J * 0.016666666666666666) * (pow(l, 5.0) * cos((K * -0.5))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp(-l)
    t_1 = cos((k / 2.0d0))
    if (l <= (-125.0d0)) then
        tmp = u + (t_1 * (j * (27.0d0 - t_0)))
    else if (l <= 0.06d0) then
        tmp = u + (t_1 * (j * (l * (2.0d0 + ((l * l) * 0.3333333333333333d0)))))
    else if (l <= 2d+58) then
        tmp = u + (j * (exp(l) - t_0))
    else
        tmp = u + ((j * 0.016666666666666666d0) * ((l ** 5.0d0) * cos((k * (-0.5d0)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(-l);
	double t_1 = Math.cos((K / 2.0));
	double tmp;
	if (l <= -125.0) {
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	} else if (l <= 0.06) {
		tmp = U + (t_1 * (J * (l * (2.0 + ((l * l) * 0.3333333333333333)))));
	} else if (l <= 2e+58) {
		tmp = U + (J * (Math.exp(l) - t_0));
	} else {
		tmp = U + ((J * 0.016666666666666666) * (Math.pow(l, 5.0) * Math.cos((K * -0.5))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(-l)
	t_1 = math.cos((K / 2.0))
	tmp = 0
	if l <= -125.0:
		tmp = U + (t_1 * (J * (27.0 - t_0)))
	elif l <= 0.06:
		tmp = U + (t_1 * (J * (l * (2.0 + ((l * l) * 0.3333333333333333)))))
	elif l <= 2e+58:
		tmp = U + (J * (math.exp(l) - t_0))
	else:
		tmp = U + ((J * 0.016666666666666666) * (math.pow(l, 5.0) * math.cos((K * -0.5))))
	return tmp
function code(J, l, K, U)
	t_0 = exp(Float64(-l))
	t_1 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (l <= -125.0)
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(27.0 - t_0))));
	elseif (l <= 0.06)
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(l * Float64(2.0 + Float64(Float64(l * l) * 0.3333333333333333))))));
	elseif (l <= 2e+58)
		tmp = Float64(U + Float64(J * Float64(exp(l) - t_0)));
	else
		tmp = Float64(U + Float64(Float64(J * 0.016666666666666666) * Float64((l ^ 5.0) * cos(Float64(K * -0.5)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(-l);
	t_1 = cos((K / 2.0));
	tmp = 0.0;
	if (l <= -125.0)
		tmp = U + (t_1 * (J * (27.0 - t_0)));
	elseif (l <= 0.06)
		tmp = U + (t_1 * (J * (l * (2.0 + ((l * l) * 0.3333333333333333)))));
	elseif (l <= 2e+58)
		tmp = U + (J * (exp(l) - t_0));
	else
		tmp = U + ((J * 0.016666666666666666) * ((l ^ 5.0) * cos((K * -0.5))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -125.0], N[(U + N[(t$95$1 * N[(J * N[(27.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 0.06], N[(U + N[(t$95$1 * N[(J * N[(l * N[(2.0 + N[(N[(l * l), $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2e+58], N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(J * 0.016666666666666666), $MachinePrecision] * N[(N[Power[l, 5.0], $MachinePrecision] * N[Cos[N[(K * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
t_1 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;\ell \leq -125:\\
\;\;\;\;U + t\_1 \cdot \left(J \cdot \left(27 - t\_0\right)\right)\\

\mathbf{elif}\;\ell \leq 0.06:\\
\;\;\;\;U + t\_1 \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot 0.3333333333333333\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 2 \cdot 10^{+58}:\\
\;\;\;\;U + J \cdot \left(e^{\ell} - t\_0\right)\\

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


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

    1. Initial program 100.0%

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

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

    if -125 < l < 0.059999999999999998

    1. Initial program 74.8%

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

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

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

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

    if 0.059999999999999998 < l < 1.99999999999999989e58

    1. Initial program 100.0%

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

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

    if 1.99999999999999989e58 < 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. Add Preprocessing
    3. Taylor expanded in l around 0 100.0%

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

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

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

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

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

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

        \[\leadsto \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) + U \]
      4. metadata-eval100.0%

        \[\leadsto \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \left(K \cdot \color{blue}{\left(--0.5\right)}\right)\right) + U \]
      5. distribute-rgt-neg-in100.0%

        \[\leadsto \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \color{blue}{\left(-K \cdot -0.5\right)}\right) + U \]
      6. cos-neg100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -125:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(27 - e^{-\ell}\right)\right)\\ \mathbf{elif}\;\ell \leq 0.06:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot 0.3333333333333333\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2 \cdot 10^{+58}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \left(K \cdot -0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 95.0% accurate, 1.4× speedup?

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

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

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

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -125 or 9.39999999999999944e58 < 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. Add Preprocessing
    3. Taylor expanded in l around 0 93.6%

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

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

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

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

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

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

        \[\leadsto \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) + U \]
      4. metadata-eval93.6%

        \[\leadsto \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \left(K \cdot \color{blue}{\left(--0.5\right)}\right)\right) + U \]
      5. distribute-rgt-neg-in93.6%

        \[\leadsto \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \color{blue}{\left(-K \cdot -0.5\right)}\right) + U \]
      6. cos-neg93.6%

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

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

    if -125 < l < 0.0560000000000000012

    1. Initial program 74.8%

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

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

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

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

    if 0.0560000000000000012 < l < 9.39999999999999944e58

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -125:\\ \;\;\;\;U + \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \left(K \cdot -0.5\right)\right)\\ \mathbf{elif}\;\ell \leq 0.056:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot 0.3333333333333333\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 9.4 \cdot 10^{+58}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 0.016666666666666666\right) \cdot \left({\ell}^{5} \cdot \cos \left(K \cdot -0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 78.8% accurate, 1.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.110000000000000001

    1. Initial program 84.9%

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

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

    if 0.110000000000000001 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 88.9%

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

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

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

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

        \[\leadsto \left(J \cdot \ell\right) \cdot \left(2 + \color{blue}{{\ell}^{2} \cdot 0.3333333333333333}\right) + U \]
      3. distribute-lft-out84.5%

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right) + \color{blue}{J \cdot \left(\ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)}\right) + U \]
      6. distribute-lft-out86.0%

        \[\leadsto \color{blue}{J \cdot \left(\ell \cdot 2 + \ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)} + U \]
      7. fma-define86.0%

        \[\leadsto J \cdot \color{blue}{\mathsf{fma}\left(\ell, 2, \ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)} + U \]
      8. associate-*r*86.0%

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \color{blue}{\left(\ell \cdot {\ell}^{2}\right) \cdot 0.3333333333333333}\right) + U \]
      9. unpow286.0%

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \left(\ell \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right) \cdot 0.3333333333333333\right) + U \]
      10. cube-mult86.0%

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

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \color{blue}{0.3333333333333333 \cdot {\ell}^{3}}\right) + U \]
    6. Simplified86.0%

      \[\leadsto \color{blue}{J \cdot \mathsf{fma}\left(\ell, 2, 0.3333333333333333 \cdot {\ell}^{3}\right)} + U \]
    7. Step-by-step derivation
      1. fma-undefine86.0%

        \[\leadsto J \cdot \color{blue}{\left(\ell \cdot 2 + 0.3333333333333333 \cdot {\ell}^{3}\right)} + U \]
    8. Applied egg-rr86.0%

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

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

Alternative 8: 78.8% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t\_0 \leq 0.11:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot 0.3333333333333333\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= t_0 0.11)
     (+ U (* t_0 (* J (* l 2.0))))
     (+ U (* J (* l (+ 2.0 (* (pow l 2.0) 0.3333333333333333))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (t_0 <= 0.11) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else {
		tmp = U + (J * (l * (2.0 + (pow(l, 2.0) * 0.3333333333333333))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    if (t_0 <= 0.11d0) then
        tmp = u + (t_0 * (j * (l * 2.0d0)))
    else
        tmp = u + (j * (l * (2.0d0 + ((l ** 2.0d0) * 0.3333333333333333d0))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (t_0 <= 0.11) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else {
		tmp = U + (J * (l * (2.0 + (Math.pow(l, 2.0) * 0.3333333333333333))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if t_0 <= 0.11:
		tmp = U + (t_0 * (J * (l * 2.0)))
	else:
		tmp = U + (J * (l * (2.0 + (math.pow(l, 2.0) * 0.3333333333333333))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_0 <= 0.11)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0))));
	else
		tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64((l ^ 2.0) * 0.3333333333333333)))));
	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.11)
		tmp = U + (t_0 * (J * (l * 2.0)));
	else
		tmp = U + (J * (l * (2.0 + ((l ^ 2.0) * 0.3333333333333333))));
	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.11], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(2.0 + N[(N[Power[l, 2.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.110000000000000001

    1. Initial program 84.9%

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

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

    if 0.110000000000000001 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 88.9%

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

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

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

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

Alternative 9: 91.4% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -3.3 \cdot 10^{+133} \lor \neg \left(\ell \leq -125\right):\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot 0.3333333333333333\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -3.3e+133) (not (<= l -125.0)))
   (+ U (* (cos (/ K 2.0)) (* J (* l (+ 2.0 (* (* l l) 0.3333333333333333))))))
   (+ U (* J (- 27.0 (exp (- l)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -3.3e+133) || !(l <= -125.0)) {
		tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * 0.3333333333333333)))));
	} else {
		tmp = U + (J * (27.0 - exp(-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 ((l <= (-3.3d+133)) .or. (.not. (l <= (-125.0d0)))) then
        tmp = u + (cos((k / 2.0d0)) * (j * (l * (2.0d0 + ((l * l) * 0.3333333333333333d0)))))
    else
        tmp = u + (j * (27.0d0 - exp(-l)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -3.3e+133) || !(l <= -125.0)) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * 0.3333333333333333)))));
	} else {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -3.3e+133) or not (l <= -125.0):
		tmp = U + (math.cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * 0.3333333333333333)))))
	else:
		tmp = U + (J * (27.0 - math.exp(-l)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -3.3e+133) || !(l <= -125.0))
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * Float64(2.0 + Float64(Float64(l * l) * 0.3333333333333333))))));
	else
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -3.3e+133) || ~((l <= -125.0)))
		tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + ((l * l) * 0.3333333333333333)))));
	else
		tmp = U + (J * (27.0 - exp(-l)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -3.3e+133], N[Not[LessEqual[l, -125.0]], $MachinePrecision]], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * N[(2.0 + N[(N[(l * l), $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.3 \cdot 10^{+133} \lor \neg \left(\ell \leq -125\right):\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot 0.3333333333333333\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -3.3e133 or -125 < l

    1. Initial program 86.5%

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

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

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

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

    if -3.3e133 < l < -125

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.3 \cdot 10^{+133} \lor \neg \left(\ell \leq -125\right):\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot 0.3333333333333333\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 83.6% accurate, 2.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -125:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

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

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


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

    1. Initial program 100.0%

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

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

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

    if -125 < l < 8e10

    1. Initial program 75.6%

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

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

    if 8e10 < 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. Add Preprocessing
    3. Taylor expanded in l around 0 76.8%

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

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

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

        \[\leadsto \left(J \cdot \ell\right) \cdot \left(2 + \color{blue}{{\ell}^{2} \cdot 0.3333333333333333}\right) + U \]
      3. distribute-lft-out54.4%

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right) + \color{blue}{J \cdot \left(\ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)}\right) + U \]
      6. distribute-lft-out57.4%

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

        \[\leadsto J \cdot \color{blue}{\mathsf{fma}\left(\ell, 2, \ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)} + U \]
      8. associate-*r*57.4%

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

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \left(\ell \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right) \cdot 0.3333333333333333\right) + U \]
      10. cube-mult57.4%

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

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \color{blue}{0.3333333333333333 \cdot {\ell}^{3}}\right) + U \]
    6. Simplified57.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -125:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 80000000000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + \frac{J \cdot \left(\ell \cdot 2 + 0.3333333333333333 \cdot {\ell}^{3}\right)}{U}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 83.0% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -125:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

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

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


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

    1. Initial program 100.0%

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

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

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

    if -125 < l < 9.5e10

    1. Initial program 75.6%

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

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

    if 9.5e10 < 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. Add Preprocessing
    3. Taylor expanded in l around 0 76.8%

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

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

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

        \[\leadsto \left(J \cdot \ell\right) \cdot \left(2 + \color{blue}{{\ell}^{2} \cdot 0.3333333333333333}\right) + U \]
      3. distribute-lft-out54.4%

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right) + \color{blue}{J \cdot \left(\ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)}\right) + U \]
      6. distribute-lft-out57.4%

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

        \[\leadsto J \cdot \color{blue}{\mathsf{fma}\left(\ell, 2, \ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)} + U \]
      8. associate-*r*57.4%

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

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \left(\ell \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right) \cdot 0.3333333333333333\right) + U \]
      10. cube-mult57.4%

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

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \color{blue}{0.3333333333333333 \cdot {\ell}^{3}}\right) + U \]
    6. Simplified57.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -125:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 95000000000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 83.0% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -125:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 115000000000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -125.0)
   (+ U (* J (- 27.0 (exp (- l)))))
   (if (<= l 115000000000.0)
     (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
     (+ U (* 0.3333333333333333 (* J (pow l 3.0)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -125.0) {
		tmp = U + (J * (27.0 - exp(-l)));
	} else if (l <= 115000000000.0) {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	} else {
		tmp = U + (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) :: tmp
    if (l <= (-125.0d0)) then
        tmp = u + (j * (27.0d0 - exp(-l)))
    else if (l <= 115000000000.0d0) then
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    else
        tmp = u + (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 tmp;
	if (l <= -125.0) {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	} else if (l <= 115000000000.0) {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	} else {
		tmp = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -125.0:
		tmp = U + (J * (27.0 - math.exp(-l)))
	elif l <= 115000000000.0:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	else:
		tmp = U + (0.3333333333333333 * (J * math.pow(l, 3.0)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -125.0)
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	elseif (l <= 115000000000.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	else
		tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -125.0)
		tmp = U + (J * (27.0 - exp(-l)));
	elseif (l <= 115000000000.0)
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	else
		tmp = U + (0.3333333333333333 * (J * (l ^ 3.0)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -125.0], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 115000000000.0], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -125:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

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

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


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

    1. Initial program 100.0%

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

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

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

    if -125 < l < 1.15e11

    1. Initial program 75.6%

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

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

    if 1.15e11 < 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. Add Preprocessing
    3. Taylor expanded in l around 0 76.8%

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

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

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

        \[\leadsto \left(J \cdot \ell\right) \cdot \left(2 + \color{blue}{{\ell}^{2} \cdot 0.3333333333333333}\right) + U \]
      3. distribute-lft-out54.4%

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right) + \color{blue}{J \cdot \left(\ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)}\right) + U \]
      6. distribute-lft-out57.4%

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

        \[\leadsto J \cdot \color{blue}{\mathsf{fma}\left(\ell, 2, \ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)} + U \]
      8. associate-*r*57.4%

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

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \left(\ell \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right) \cdot 0.3333333333333333\right) + U \]
      10. cube-mult57.4%

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

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \color{blue}{0.3333333333333333 \cdot {\ell}^{3}}\right) + U \]
    6. Simplified57.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -125:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 115000000000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 71.9% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -125 \lor \neg \left(\ell \leq 78000000000\right):\\
\;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -125 or 7.8e10 < 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. Add Preprocessing
    3. Taylor expanded in l around 0 78.5%

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

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

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

        \[\leadsto \left(J \cdot \ell\right) \cdot \left(2 + \color{blue}{{\ell}^{2} \cdot 0.3333333333333333}\right) + U \]
      3. distribute-lft-out56.9%

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right) + \color{blue}{J \cdot \left(\ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)}\right) + U \]
      6. distribute-lft-out59.1%

        \[\leadsto \color{blue}{J \cdot \left(\ell \cdot 2 + \ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)} + U \]
      7. fma-define59.1%

        \[\leadsto J \cdot \color{blue}{\mathsf{fma}\left(\ell, 2, \ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)} + U \]
      8. associate-*r*59.1%

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \color{blue}{\left(\ell \cdot {\ell}^{2}\right) \cdot 0.3333333333333333}\right) + U \]
      9. unpow259.1%

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \left(\ell \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right) \cdot 0.3333333333333333\right) + U \]
      10. cube-mult59.1%

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

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \color{blue}{0.3333333333333333 \cdot {\ell}^{3}}\right) + U \]
    6. Simplified59.1%

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

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

    if -125 < l < 7.8e10

    1. Initial program 75.6%

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

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

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

        \[\leadsto \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\ell \cdot 2}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied egg-rr98.1%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -125 \lor \neg \left(\ell \leq 78000000000\right):\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 76.1% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -125:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 78000000000:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -125.0)
   (+ U (* J (- 27.0 (exp (- l)))))
   (if (<= l 78000000000.0)
     (+ U (* l (* J 2.0)))
     (+ U (* 0.3333333333333333 (* J (pow l 3.0)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -125.0) {
		tmp = U + (J * (27.0 - exp(-l)));
	} else if (l <= 78000000000.0) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = U + (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) :: tmp
    if (l <= (-125.0d0)) then
        tmp = u + (j * (27.0d0 - exp(-l)))
    else if (l <= 78000000000.0d0) then
        tmp = u + (l * (j * 2.0d0))
    else
        tmp = u + (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 tmp;
	if (l <= -125.0) {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	} else if (l <= 78000000000.0) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -125.0:
		tmp = U + (J * (27.0 - math.exp(-l)))
	elif l <= 78000000000.0:
		tmp = U + (l * (J * 2.0))
	else:
		tmp = U + (0.3333333333333333 * (J * math.pow(l, 3.0)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -125.0)
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	elseif (l <= 78000000000.0)
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	else
		tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -125.0)
		tmp = U + (J * (27.0 - exp(-l)));
	elseif (l <= 78000000000.0)
		tmp = U + (l * (J * 2.0));
	else
		tmp = U + (0.3333333333333333 * (J * (l ^ 3.0)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -125.0], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 78000000000.0], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -125:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

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

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


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

    1. Initial program 100.0%

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

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

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

    if -125 < l < 7.8e10

    1. Initial program 75.6%

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

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

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

        \[\leadsto \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\ell \cdot 2}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied egg-rr98.1%

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

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

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

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

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

    if 7.8e10 < 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. Add Preprocessing
    3. Taylor expanded in l around 0 76.8%

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

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

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

        \[\leadsto \left(J \cdot \ell\right) \cdot \left(2 + \color{blue}{{\ell}^{2} \cdot 0.3333333333333333}\right) + U \]
      3. distribute-lft-out54.4%

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right) + \color{blue}{J \cdot \left(\ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)}\right) + U \]
      6. distribute-lft-out57.4%

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

        \[\leadsto J \cdot \color{blue}{\mathsf{fma}\left(\ell, 2, \ell \cdot \left({\ell}^{2} \cdot 0.3333333333333333\right)\right)} + U \]
      8. associate-*r*57.4%

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

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \left(\ell \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right) \cdot 0.3333333333333333\right) + U \]
      10. cube-mult57.4%

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

        \[\leadsto J \cdot \mathsf{fma}\left(\ell, 2, \color{blue}{0.3333333333333333 \cdot {\ell}^{3}}\right) + U \]
    6. Simplified57.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -125:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 78000000000:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 38.0% accurate, 26.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 4 \cdot 10^{-6}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\frac{U}{J} - 4\right)\\ \end{array} \end{array} \]
(FPCore (J l K U) :precision binary64 (if (<= l 4e-6) U (* J (- (/ U J) 4.0))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 4e-6) {
		tmp = U;
	} else {
		tmp = J * ((U / J) - 4.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 <= 4d-6) then
        tmp = u
    else
        tmp = j * ((u / j) - 4.0d0)
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 4e-6) {
		tmp = U;
	} else {
		tmp = J * ((U / J) - 4.0);
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= 4e-6:
		tmp = U
	else:
		tmp = J * ((U / J) - 4.0)
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= 4e-6)
		tmp = U;
	else
		tmp = Float64(J * Float64(Float64(U / J) - 4.0));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= 4e-6)
		tmp = U;
	else
		tmp = J * ((U / J) - 4.0);
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, 4e-6], U, N[(J * N[(N[(U / J), $MachinePrecision] - 4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 4 \cdot 10^{-6}:\\
\;\;\;\;U\\

\mathbf{else}:\\
\;\;\;\;J \cdot \left(\frac{U}{J} - 4\right)\\


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

    1. Initial program 83.7%

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

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

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

    if 3.99999999999999982e-6 < l

    1. Initial program 99.6%

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

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

      \[\leadsto \color{blue}{-4 \cdot J} + U \]
    5. Step-by-step derivation
      1. *-commutative2.2%

        \[\leadsto \color{blue}{J \cdot -4} + U \]
    6. Simplified2.2%

      \[\leadsto \color{blue}{J \cdot -4} + U \]
    7. Taylor expanded in J around inf 9.2%

      \[\leadsto \color{blue}{J \cdot \left(\frac{U}{J} - 4\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 16: 53.9% accurate, 44.6× speedup?

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

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

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

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

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

      \[\leadsto \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\ell \cdot 2}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  5. Applied egg-rr99.1%

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

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

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

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

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

    \[\leadsto U + \ell \cdot \left(J \cdot 2\right) \]
  10. Add Preprocessing

Alternative 17: 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 87.9%

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

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

    \[\leadsto \color{blue}{U} \]
  5. Add Preprocessing

Reproduce

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