Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 85.7% → 99.7%
Time: 11.9s
Alternatives: 15
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 15 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: 85.7% 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.7% accurate, 0.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 2.0000000000000001e-4 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.0000000000000001e-4

    1. Initial program 69.3%

      \[\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}{\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + 2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -\infty \lor \neg \left(e^{\ell} - e^{-\ell} \leq 0.0002\right):\\ \;\;\;\;\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(\left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 99.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t\_1 \leq -\infty \lor \neg \left(t\_1 \leq 0.0002\right):\\ \;\;\;\;\left(t\_1 \cdot J\right) \cdot t\_0 + U\\ \mathbf{else}:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
   (if (or (<= t_1 (- INFINITY)) (not (<= t_1 0.0002)))
     (+ (* (* t_1 J) t_0) U)
     (+ U (* t_0 (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = exp(l) - exp(-l);
	double tmp;
	if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 0.0002)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 0.0002)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_1 <= -math.inf) or not (t_1 <= 0.0002):
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (t_0 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_1 <= Float64(-Inf)) || !(t_1 <= 0.0002))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_1 <= -Inf) || ~((t_1 <= 0.0002)))
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (t_0 * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 0.0002]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 2.0000000000000001e-4 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.0000000000000001e-4

    1. Initial program 69.3%

      \[\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 \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. distribute-rgt-in99.9%

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

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

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

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

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

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

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

Alternative 3: 87.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 0.0002\right):\\ \;\;\;\;t\_0 \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 0.0002)))
     (* t_0 J)
     (+ U (* l (* 2.0 (* J (cos (* K 0.5)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 0.0002)) {
		tmp = t_0 * J;
	} else {
		tmp = U + (l * (2.0 * (J * cos((K * 0.5)))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_0 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 0.0002)) {
		tmp = t_0 * J;
	} else {
		tmp = U + (l * (2.0 * (J * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_0 <= -math.inf) or not (t_0 <= 0.0002):
		tmp = t_0 * J
	else:
		tmp = U + (l * (2.0 * (J * math.cos((K * 0.5)))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 0.0002))
		tmp = Float64(t_0 * J);
	else
		tmp = Float64(U + Float64(l * Float64(2.0 * Float64(J * cos(Float64(K * 0.5))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_0 <= -Inf) || ~((t_0 <= 0.0002)))
		tmp = t_0 * J;
	else
		tmp = U + (l * (2.0 * (J * cos((K * 0.5)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 0.0002]], $MachinePrecision]], N[(t$95$0 * J), $MachinePrecision], N[(U + N[(l * N[(2.0 * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 0.0002\right):\\
\;\;\;\;t\_0 \cdot J\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 2.0000000000000001e-4 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in J around inf 79.6%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.0000000000000001e-4

    1. Initial program 69.3%

      \[\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}{\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + 2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -\infty \lor \neg \left(e^{\ell} - e^{-\ell} \leq 0.0002\right):\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 95.1% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;\ell \leq -36:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;\ell \leq 3 \cdot 10^{+102}:\\
\;\;\;\;t\_1 + U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -8.2000000000000004e139 or 2.9999999999999998e102 < 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 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in l around inf 100.0%

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

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

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

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

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

    if -8.2000000000000004e139 < l < -36

    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 87.5%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in J around inf 87.5%

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

    if -36 < l < 0.0115

    1. Initial program 69.3%

      \[\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}{\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + 2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

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

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

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

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

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

    if 0.0115 < l < 2.9999999999999998e102

    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 83.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -8.2 \cdot 10^{+139}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -36:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.0115:\\ \;\;\;\;U + \ell \cdot \left(2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 3 \cdot 10^{+102}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 95.2% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;\ell \leq -200:\\
\;\;\;\;t\_2\\

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

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

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


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

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 100.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. Taylor expanded in l around inf 100.0%

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

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

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

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

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

    if -8.2000000000000004e139 < l < -200

    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 87.5%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in J around inf 87.5%

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

    if -200 < l < 0.160000000000000003

    1. Initial program 69.3%

      \[\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 \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 \]

    if 0.160000000000000003 < l < 5.49999999999999981e102

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -8.2 \cdot 10^{+139}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -200:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.16:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 5.5 \cdot 10^{+102}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 95.2% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;\ell \leq -310:\\
\;\;\;\;t\_3\\

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

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

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


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

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 100.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. Taylor expanded in l around inf 100.0%

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

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

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

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

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

    if -8.2000000000000004e139 < l < -310

    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 87.5%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in J around inf 87.5%

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

    if -310 < l < 0.19

    1. Initial program 69.3%

      \[\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 \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. distribute-rgt-in99.9%

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

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

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

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

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

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

    if 0.19 < l < 5.49999999999999981e102

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -8.2 \cdot 10^{+139}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -310:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.19:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 5.5 \cdot 10^{+102}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 79.8% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

    1. Initial program 82.7%

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

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

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

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

Alternative 8: 87.8% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;\ell \leq -360:\\
\;\;\;\;t\_0\\

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

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


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

    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 83.9%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in J around inf 83.9%

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

    if -360 < l < 0.012

    1. Initial program 69.3%

      \[\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}{\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + 2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

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

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

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

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

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

    if 0.012 < 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 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 simplification91.2%

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

Alternative 9: 79.3% accurate, 2.5× speedup?

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

\\
\begin{array}{l}
t_0 := U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\
\mathbf{if}\;\ell \leq -4.5 \cdot 10^{+60}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -1800:\\
\;\;\;\;{U}^{-4}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -4.50000000000000013e60 or 145000 < 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 84.6%

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

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

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

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

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

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

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

    if -4.50000000000000013e60 < l < -1800

    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-rr1.4%

      \[\leadsto \left(J \cdot \color{blue}{0.25}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Applied egg-rr43.8%

      \[\leadsto \color{blue}{{U}^{-4}} \]

    if -1800 < l < 145000

    1. Initial program 69.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.5 \cdot 10^{+60}:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -1800:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 145000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 79.2% accurate, 2.5× speedup?

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

\\
\begin{array}{l}
t_0 := U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\
\mathbf{if}\;\ell \leq -3.8 \cdot 10^{+60}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -720:\\
\;\;\;\;{U}^{-4}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.80000000000000009e60 or 26000 < 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 84.6%

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

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

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

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

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

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

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

    if -3.80000000000000009e60 < l < -720

    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-rr1.4%

      \[\leadsto \left(J \cdot \color{blue}{0.25}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Applied egg-rr43.8%

      \[\leadsto \color{blue}{{U}^{-4}} \]

    if -720 < l < 26000

    1. Initial program 69.3%

      \[\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}{\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + 2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.8 \cdot 10^{+60}:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -720:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 26000:\\ \;\;\;\;U + \ell \cdot \left(2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 72.1% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \mathbf{if}\;\ell \leq -3.5 \cdot 10^{+60}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -860:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-23}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* J (* 0.3333333333333333 (pow l 3.0))))))
   (if (<= l -3.5e+60)
     t_0
     (if (<= l -860.0)
       (pow U -4.0)
       (if (<= l 1.3e-23) (+ U (* J (* l 2.0))) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (0.3333333333333333 * pow(l, 3.0)));
	double tmp;
	if (l <= -3.5e+60) {
		tmp = t_0;
	} else if (l <= -860.0) {
		tmp = pow(U, -4.0);
	} else if (l <= 1.3e-23) {
		tmp = U + (J * (l * 2.0));
	} 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.3333333333333333d0 * (l ** 3.0d0)))
    if (l <= (-3.5d+60)) then
        tmp = t_0
    else if (l <= (-860.0d0)) then
        tmp = u ** (-4.0d0)
    else if (l <= 1.3d-23) then
        tmp = u + (j * (l * 2.0d0))
    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.3333333333333333 * Math.pow(l, 3.0)));
	double tmp;
	if (l <= -3.5e+60) {
		tmp = t_0;
	} else if (l <= -860.0) {
		tmp = Math.pow(U, -4.0);
	} else if (l <= 1.3e-23) {
		tmp = U + (J * (l * 2.0));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * (0.3333333333333333 * math.pow(l, 3.0)))
	tmp = 0
	if l <= -3.5e+60:
		tmp = t_0
	elif l <= -860.0:
		tmp = math.pow(U, -4.0)
	elif l <= 1.3e-23:
		tmp = U + (J * (l * 2.0))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(J * Float64(0.3333333333333333 * (l ^ 3.0))))
	tmp = 0.0
	if (l <= -3.5e+60)
		tmp = t_0;
	elseif (l <= -860.0)
		tmp = U ^ -4.0;
	elseif (l <= 1.3e-23)
		tmp = Float64(U + Float64(J * Float64(l * 2.0)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (J * (0.3333333333333333 * (l ^ 3.0)));
	tmp = 0.0;
	if (l <= -3.5e+60)
		tmp = t_0;
	elseif (l <= -860.0)
		tmp = U ^ -4.0;
	elseif (l <= 1.3e-23)
		tmp = U + (J * (l * 2.0));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(J * N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.5e+60], t$95$0, If[LessEqual[l, -860.0], N[Power[U, -4.0], $MachinePrecision], If[LessEqual[l, 1.3e-23], N[(U + N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\
\mathbf{if}\;\ell \leq -3.5 \cdot 10^{+60}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -860:\\
\;\;\;\;{U}^{-4}\\

\mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-23}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.5000000000000002e60 or 1.3e-23 < l

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

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

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

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

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

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

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

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

    if -3.5000000000000002e60 < l < -860

    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-rr1.4%

      \[\leadsto \left(J \cdot \color{blue}{0.25}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Applied egg-rr43.8%

      \[\leadsto \color{blue}{{U}^{-4}} \]

    if -860 < l < 1.3e-23

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.5 \cdot 10^{+60}:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -860:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-23}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 42.8% accurate, 20.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.55 \cdot 10^{-13} \lor \neg \left(\ell \leq 16500000000000\right):\\
\;\;\;\;U \cdot \left(U + -1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.55e-13 or 1.65e13 < l

    1. Initial program 99.4%

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

      \[\leadsto \left(J \cdot \color{blue}{0.25}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Applied egg-rr22.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(U, U, -U\right)} \]
    5. Step-by-step derivation
      1. fma-undefine22.9%

        \[\leadsto \color{blue}{U \cdot U + \left(-U\right)} \]
      2. neg-mul-122.9%

        \[\leadsto U \cdot U + \color{blue}{-1 \cdot U} \]
      3. distribute-rgt-out22.9%

        \[\leadsto \color{blue}{U \cdot \left(U + -1\right)} \]
    6. Simplified22.9%

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

    if -1.55e-13 < l < 1.65e13

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.55 \cdot 10^{-13} \lor \neg \left(\ell \leq 16500000000000\right):\\ \;\;\;\;U \cdot \left(U + -1\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 42.8% accurate, 23.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.55 \cdot 10^{-13} \lor \neg \left(\ell \leq 20000000000000\right):\\
\;\;\;\;U \cdot U\\

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


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

    1. Initial program 99.4%

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

      \[\leadsto \left(J \cdot \color{blue}{0.25}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Applied egg-rr22.8%

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

    if -1.55e-13 < l < 2e13

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.55 \cdot 10^{-13} \lor \neg \left(\ell \leq 20000000000000\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 55.0% accurate, 44.6× speedup?

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

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

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

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

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

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

Alternative 15: 37.6% 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 82.3%

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

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

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

    \[\leadsto U \]
  6. Add Preprocessing

Reproduce

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