Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.4% → 99.9%
Time: 14.1s
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: 86.4% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_0 \leq -10000 \lor \neg \left(t_0 \leq 0.002\right):\\ \;\;\;\;J \cdot \left(t_0 \cdot \cos \left(0.5 \cdot K\right)\right) + U\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \left(0.016666666666666666 \cdot {\ell}^{5} + \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right), U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))))
   (if (or (<= t_0 -10000.0) (not (<= t_0 0.002)))
     (+ (* J (* t_0 (cos (* 0.5 K)))) U)
     (fma
      J
      (*
       (+
        (* 0.016666666666666666 (pow l 5.0))
        (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))
       (cos (/ K 2.0)))
      U))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -10000.0) || !(t_0 <= 0.002)) {
		tmp = (J * (t_0 * cos((0.5 * K)))) + U;
	} else {
		tmp = fma(J, (((0.016666666666666666 * pow(l, 5.0)) + ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))) * cos((K / 2.0))), U);
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= -10000.0) || !(t_0 <= 0.002))
		tmp = Float64(Float64(J * Float64(t_0 * cos(Float64(0.5 * K)))) + U);
	else
		tmp = fma(J, Float64(Float64(Float64(0.016666666666666666 * (l ^ 5.0)) + Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))) * cos(Float64(K / 2.0))), U);
	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, -10000.0], N[Not[LessEqual[t$95$0, 0.002]], $MachinePrecision]], N[(N[(J * N[(t$95$0 * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(J * N[(N[(N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_0 \leq -10000 \lor \neg \left(t_0 \leq 0.002\right):\\
\;\;\;\;J \cdot \left(t_0 \cdot \cos \left(0.5 \cdot K\right)\right) + U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -1e4 or 2e-3 < (-.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 J around 0 100.0%

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

    if -1e4 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2e-3

    1. Initial program 72.6%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*72.6%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    3. Simplified72.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in l around 0 99.9%

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

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

Alternative 2: 99.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(0.5 \cdot K\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_1 \leq -10000 \lor \neg \left(t_1 \leq 0.002\right):\\ \;\;\;\;J \cdot \left(t_1 \cdot t_0\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(t_0 \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 (* 0.5 K))) (t_1 (- (exp l) (exp (- l)))))
   (if (or (<= t_1 -10000.0) (not (<= t_1 0.002)))
     (+ (* J (* t_1 t_0)) U)
     (+ U (* J (* t_0 (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((0.5 * K));
	double t_1 = exp(l) - exp(-l);
	double tmp;
	if ((t_1 <= -10000.0) || !(t_1 <= 0.002)) {
		tmp = (J * (t_1 * t_0)) + U;
	} else {
		tmp = U + (J * (t_0 * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((0.5d0 * k))
    t_1 = exp(l) - exp(-l)
    if ((t_1 <= (-10000.0d0)) .or. (.not. (t_1 <= 0.002d0))) then
        tmp = (j * (t_1 * t_0)) + u
    else
        tmp = u + (j * (t_0 * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((0.5 * K));
	double t_1 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_1 <= -10000.0) || !(t_1 <= 0.002)) {
		tmp = (J * (t_1 * t_0)) + U;
	} else {
		tmp = U + (J * (t_0 * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((0.5 * K))
	t_1 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_1 <= -10000.0) or not (t_1 <= 0.002):
		tmp = (J * (t_1 * t_0)) + U
	else:
		tmp = U + (J * (t_0 * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(0.5 * K))
	t_1 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_1 <= -10000.0) || !(t_1 <= 0.002))
		tmp = Float64(Float64(J * Float64(t_1 * t_0)) + U);
	else
		tmp = Float64(U + Float64(J * Float64(t_0 * 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((0.5 * K));
	t_1 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_1 <= -10000.0) || ~((t_1 <= 0.002)))
		tmp = (J * (t_1 * t_0)) + U;
	else
		tmp = U + (J * (t_0 * ((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[(0.5 * K), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -10000.0], N[Not[LessEqual[t$95$1, 0.002]], $MachinePrecision]], N[(N[(J * N[(t$95$1 * t$95$0), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(J * N[(t$95$0 * 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(0.5 \cdot K\right)\\
t_1 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_1 \leq -10000 \lor \neg \left(t_1 \leq 0.002\right):\\
\;\;\;\;J \cdot \left(t_1 \cdot t_0\right) + U\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(t_0 \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))) < -1e4 or 2e-3 < (-.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 J around 0 100.0%

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

    if -1e4 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2e-3

    1. Initial program 72.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(\ell \cdot 2 + 0.3333333333333333 \cdot {\ell}^{3}\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 -10000 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 0.002\right):\\ \;\;\;\;J \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(0.5 \cdot K\right)\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 86.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_0 \leq -10000 \lor \neg \left(t_0 \leq 0.002\right):\\ \;\;\;\;U + t_0 \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\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 -10000.0) (not (<= t_0 0.002)))
     (+ U (* t_0 J))
     (+ U (* 2.0 (* J (* l (cos (* 0.5 K)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -10000.0) || !(t_0 <= 0.002)) {
		tmp = U + (t_0 * J);
	} else {
		tmp = U + (2.0 * (J * (l * cos((0.5 * K)))));
	}
	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)
    if ((t_0 <= (-10000.0d0)) .or. (.not. (t_0 <= 0.002d0))) then
        tmp = u + (t_0 * j)
    else
        tmp = u + (2.0d0 * (j * (l * cos((0.5d0 * k)))))
    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);
	double tmp;
	if ((t_0 <= -10000.0) || !(t_0 <= 0.002)) {
		tmp = U + (t_0 * J);
	} else {
		tmp = U + (2.0 * (J * (l * Math.cos((0.5 * K)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_0 <= -10000.0) or not (t_0 <= 0.002):
		tmp = U + (t_0 * J)
	else:
		tmp = U + (2.0 * (J * (l * math.cos((0.5 * K)))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= -10000.0) || !(t_0 <= 0.002))
		tmp = Float64(U + Float64(t_0 * J));
	else
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(0.5 * K))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_0 <= -10000.0) || ~((t_0 <= 0.002)))
		tmp = U + (t_0 * J);
	else
		tmp = U + (2.0 * (J * (l * cos((0.5 * K)))));
	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, -10000.0], N[Not[LessEqual[t$95$0, 0.002]], $MachinePrecision]], N[(U + N[(t$95$0 * J), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_0 \leq -10000 \lor \neg \left(t_0 \leq 0.002\right):\\
\;\;\;\;U + t_0 \cdot J\\

\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\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))) < -1e4 or 2e-3 < (-.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 73.3%

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

    if -1e4 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2e-3

    1. Initial program 72.6%

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

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

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

Alternative 4: 77.9% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;t_1 \leq -0.58:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + {K}^{2} \cdot -0.25\right)\right)\\

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

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


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

    1. Initial program 76.4%

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

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

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

    1. Initial program 95.2%

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

      \[\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*42.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(-J \cdot \left(-2 \cdot \ell\right)\right) + \left(-0.25 \cdot \color{blue}{\left(\left({K}^{2} \cdot \ell\right) \cdot J\right)}\right)\right) + U \]
      10. associate-*l*70.4%

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

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

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

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

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

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

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

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

    if -0.57999999999999996 < (cos.f64 (/.f64 K 2)) < 0.149999999999999994

    1. Initial program 84.8%

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

      \[\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*65.8%

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

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

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

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

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

    1. Initial program 87.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 96.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ t_1 := \cos \left(0.5 \cdot K\right)\\ t_2 := t_1 \cdot \left(J \cdot \left(0.016666666666666666 \cdot {\ell}^{5}\right)\right)\\ \mathbf{if}\;\ell \leq -1.3 \cdot 10^{+64}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\ell \leq -0.235:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 0.0028:\\ \;\;\;\;U + J \cdot \left(t_1 \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2 \cdot 10^{+52}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* (- (exp l) (exp (- l))) J)))
        (t_1 (cos (* 0.5 K)))
        (t_2 (* t_1 (* J (* 0.016666666666666666 (pow l 5.0))))))
   (if (<= l -1.3e+64)
     t_2
     (if (<= l -0.235)
       t_0
       (if (<= l 0.0028)
         (+ U (* J (* t_1 (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))
         (if (<= l 2e+52) t_0 t_2))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + ((exp(l) - exp(-l)) * J);
	double t_1 = cos((0.5 * K));
	double t_2 = t_1 * (J * (0.016666666666666666 * pow(l, 5.0)));
	double tmp;
	if (l <= -1.3e+64) {
		tmp = t_2;
	} else if (l <= -0.235) {
		tmp = t_0;
	} else if (l <= 0.0028) {
		tmp = U + (J * (t_1 * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
	} else if (l <= 2e+52) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = u + ((exp(l) - exp(-l)) * j)
    t_1 = cos((0.5d0 * k))
    t_2 = t_1 * (j * (0.016666666666666666d0 * (l ** 5.0d0)))
    if (l <= (-1.3d+64)) then
        tmp = t_2
    else if (l <= (-0.235d0)) then
        tmp = t_0
    else if (l <= 0.0028d0) then
        tmp = u + (j * (t_1 * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
    else if (l <= 2d+52) then
        tmp = t_0
    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 = U + ((Math.exp(l) - Math.exp(-l)) * J);
	double t_1 = Math.cos((0.5 * K));
	double t_2 = t_1 * (J * (0.016666666666666666 * Math.pow(l, 5.0)));
	double tmp;
	if (l <= -1.3e+64) {
		tmp = t_2;
	} else if (l <= -0.235) {
		tmp = t_0;
	} else if (l <= 0.0028) {
		tmp = U + (J * (t_1 * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
	} else if (l <= 2e+52) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + ((math.exp(l) - math.exp(-l)) * J)
	t_1 = math.cos((0.5 * K))
	t_2 = t_1 * (J * (0.016666666666666666 * math.pow(l, 5.0)))
	tmp = 0
	if l <= -1.3e+64:
		tmp = t_2
	elif l <= -0.235:
		tmp = t_0
	elif l <= 0.0028:
		tmp = U + (J * (t_1 * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))))
	elif l <= 2e+52:
		tmp = t_0
	else:
		tmp = t_2
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J))
	t_1 = cos(Float64(0.5 * K))
	t_2 = Float64(t_1 * Float64(J * Float64(0.016666666666666666 * (l ^ 5.0))))
	tmp = 0.0
	if (l <= -1.3e+64)
		tmp = t_2;
	elseif (l <= -0.235)
		tmp = t_0;
	elseif (l <= 0.0028)
		tmp = Float64(U + Float64(J * Float64(t_1 * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))));
	elseif (l <= 2e+52)
		tmp = t_0;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + ((exp(l) - exp(-l)) * J);
	t_1 = cos((0.5 * K));
	t_2 = t_1 * (J * (0.016666666666666666 * (l ^ 5.0)));
	tmp = 0.0;
	if (l <= -1.3e+64)
		tmp = t_2;
	elseif (l <= -0.235)
		tmp = t_0;
	elseif (l <= 0.0028)
		tmp = U + (J * (t_1 * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))));
	elseif (l <= 2e+52)
		tmp = t_0;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * N[(J * N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.3e+64], t$95$2, If[LessEqual[l, -0.235], t$95$0, If[LessEqual[l, 0.0028], N[(U + N[(J * N[(t$95$1 * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2e+52], t$95$0, t$95$2]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\ell \leq 0.0028:\\
\;\;\;\;U + J \cdot \left(t_1 \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\

\mathbf{elif}\;\ell \leq 2 \cdot 10^{+52}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.29999999999999998e64 or 2e52 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in l around 0 98.2%

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

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

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

        \[\leadsto \left(0.016666666666666666 \cdot J\right) \cdot \left({\ell}^{5} \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) \]
      3. associate-*r*98.3%

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

        \[\leadsto \left(\color{blue}{\left(J \cdot 0.016666666666666666\right)} \cdot {\ell}^{5}\right) \cdot \cos \left(K \cdot 0.5\right) \]
      5. associate-*r*98.3%

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

        \[\leadsto \left(J \cdot \left(0.016666666666666666 \cdot {\ell}^{5}\right)\right) \cdot \cos \color{blue}{\left(0.5 \cdot K\right)} \]
    8. Simplified98.3%

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

    if -1.29999999999999998e64 < l < -0.23499999999999999 or 0.00279999999999999997 < l < 2e52

    1. Initial program 99.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 K around 0 78.7%

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

    if -0.23499999999999999 < l < 0.00279999999999999997

    1. Initial program 72.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.3 \cdot 10^{+64}:\\ \;\;\;\;\cos \left(0.5 \cdot K\right) \cdot \left(J \cdot \left(0.016666666666666666 \cdot {\ell}^{5}\right)\right)\\ \mathbf{elif}\;\ell \leq -0.235:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.0028:\\ \;\;\;\;U + J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2 \cdot 10^{+52}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;\cos \left(0.5 \cdot K\right) \cdot \left(J \cdot \left(0.016666666666666666 \cdot {\ell}^{5}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 96.8% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ t_1 := \cos \left(0.5 \cdot K\right)\\ t_2 := t_1 \cdot \left(J \cdot \left(0.016666666666666666 \cdot {\ell}^{5}\right)\right)\\ \mathbf{if}\;\ell \leq -1.3 \cdot 10^{+64}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\ell \leq -0.28:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 0.003:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t_1\right)\right)\\ \mathbf{elif}\;\ell \leq 1.05 \cdot 10^{+54}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* (- (exp l) (exp (- l))) J)))
        (t_1 (cos (* 0.5 K)))
        (t_2 (* t_1 (* J (* 0.016666666666666666 (pow l 5.0))))))
   (if (<= l -1.3e+64)
     t_2
     (if (<= l -0.28)
       t_0
       (if (<= l 0.003)
         (+ U (* 2.0 (* J (* l t_1))))
         (if (<= l 1.05e+54) t_0 t_2))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + ((exp(l) - exp(-l)) * J);
	double t_1 = cos((0.5 * K));
	double t_2 = t_1 * (J * (0.016666666666666666 * pow(l, 5.0)));
	double tmp;
	if (l <= -1.3e+64) {
		tmp = t_2;
	} else if (l <= -0.28) {
		tmp = t_0;
	} else if (l <= 0.003) {
		tmp = U + (2.0 * (J * (l * t_1)));
	} else if (l <= 1.05e+54) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = u + ((exp(l) - exp(-l)) * j)
    t_1 = cos((0.5d0 * k))
    t_2 = t_1 * (j * (0.016666666666666666d0 * (l ** 5.0d0)))
    if (l <= (-1.3d+64)) then
        tmp = t_2
    else if (l <= (-0.28d0)) then
        tmp = t_0
    else if (l <= 0.003d0) then
        tmp = u + (2.0d0 * (j * (l * t_1)))
    else if (l <= 1.05d+54) then
        tmp = t_0
    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 = U + ((Math.exp(l) - Math.exp(-l)) * J);
	double t_1 = Math.cos((0.5 * K));
	double t_2 = t_1 * (J * (0.016666666666666666 * Math.pow(l, 5.0)));
	double tmp;
	if (l <= -1.3e+64) {
		tmp = t_2;
	} else if (l <= -0.28) {
		tmp = t_0;
	} else if (l <= 0.003) {
		tmp = U + (2.0 * (J * (l * t_1)));
	} else if (l <= 1.05e+54) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + ((math.exp(l) - math.exp(-l)) * J)
	t_1 = math.cos((0.5 * K))
	t_2 = t_1 * (J * (0.016666666666666666 * math.pow(l, 5.0)))
	tmp = 0
	if l <= -1.3e+64:
		tmp = t_2
	elif l <= -0.28:
		tmp = t_0
	elif l <= 0.003:
		tmp = U + (2.0 * (J * (l * t_1)))
	elif l <= 1.05e+54:
		tmp = t_0
	else:
		tmp = t_2
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J))
	t_1 = cos(Float64(0.5 * K))
	t_2 = Float64(t_1 * Float64(J * Float64(0.016666666666666666 * (l ^ 5.0))))
	tmp = 0.0
	if (l <= -1.3e+64)
		tmp = t_2;
	elseif (l <= -0.28)
		tmp = t_0;
	elseif (l <= 0.003)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * t_1))));
	elseif (l <= 1.05e+54)
		tmp = t_0;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + ((exp(l) - exp(-l)) * J);
	t_1 = cos((0.5 * K));
	t_2 = t_1 * (J * (0.016666666666666666 * (l ^ 5.0)));
	tmp = 0.0;
	if (l <= -1.3e+64)
		tmp = t_2;
	elseif (l <= -0.28)
		tmp = t_0;
	elseif (l <= 0.003)
		tmp = U + (2.0 * (J * (l * t_1)));
	elseif (l <= 1.05e+54)
		tmp = t_0;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * N[(J * N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.3e+64], t$95$2, If[LessEqual[l, -0.28], t$95$0, If[LessEqual[l, 0.003], N[(U + N[(2.0 * N[(J * N[(l * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.05e+54], t$95$0, t$95$2]]]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;\ell \leq 1.05 \cdot 10^{+54}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.29999999999999998e64 or 1.04999999999999993e54 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in l around 0 98.2%

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

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

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

        \[\leadsto \left(0.016666666666666666 \cdot J\right) \cdot \left({\ell}^{5} \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) \]
      3. associate-*r*98.3%

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

        \[\leadsto \left(\color{blue}{\left(J \cdot 0.016666666666666666\right)} \cdot {\ell}^{5}\right) \cdot \cos \left(K \cdot 0.5\right) \]
      5. associate-*r*98.3%

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

        \[\leadsto \left(J \cdot \left(0.016666666666666666 \cdot {\ell}^{5}\right)\right) \cdot \cos \color{blue}{\left(0.5 \cdot K\right)} \]
    8. Simplified98.3%

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

    if -1.29999999999999998e64 < l < -0.28000000000000003 or 0.0030000000000000001 < l < 1.04999999999999993e54

    1. Initial program 99.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 K around 0 78.7%

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

    if -0.28000000000000003 < l < 0.0030000000000000001

    1. Initial program 72.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.3 \cdot 10^{+64}:\\ \;\;\;\;\cos \left(0.5 \cdot K\right) \cdot \left(J \cdot \left(0.016666666666666666 \cdot {\ell}^{5}\right)\right)\\ \mathbf{elif}\;\ell \leq -0.28:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.003:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.05 \cdot 10^{+54}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;\cos \left(0.5 \cdot K\right) \cdot \left(J \cdot \left(0.016666666666666666 \cdot {\ell}^{5}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 66.0% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(\ell \cdot \left(2 + {K}^{2} \cdot -0.25\right)\right)\\ \mathbf{if}\;\ell \leq -1.9 \cdot 10^{+164}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -60000000000000:\\ \;\;\;\;U + {K}^{2} \cdot \left(J \cdot -0.03125\right)\\ \mathbf{elif}\;\ell \leq -2700000000 \lor \neg \left(\ell \leq 3.5 \cdot 10^{+15}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* J (* l (+ 2.0 (* (pow K 2.0) -0.25)))))))
   (if (<= l -1.9e+164)
     t_0
     (if (<= l -60000000000000.0)
       (+ U (* (pow K 2.0) (* J -0.03125)))
       (if (or (<= l -2700000000.0) (not (<= l 3.5e+15)))
         t_0
         (+ U (* 2.0 (* J (* l (cos (* 0.5 K)))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (l * (2.0 + (pow(K, 2.0) * -0.25))));
	double tmp;
	if (l <= -1.9e+164) {
		tmp = t_0;
	} else if (l <= -60000000000000.0) {
		tmp = U + (pow(K, 2.0) * (J * -0.03125));
	} else if ((l <= -2700000000.0) || !(l <= 3.5e+15)) {
		tmp = t_0;
	} else {
		tmp = U + (2.0 * (J * (l * cos((0.5 * K)))));
	}
	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 * (l * (2.0d0 + ((k ** 2.0d0) * (-0.25d0)))))
    if (l <= (-1.9d+164)) then
        tmp = t_0
    else if (l <= (-60000000000000.0d0)) then
        tmp = u + ((k ** 2.0d0) * (j * (-0.03125d0)))
    else if ((l <= (-2700000000.0d0)) .or. (.not. (l <= 3.5d+15))) then
        tmp = t_0
    else
        tmp = u + (2.0d0 * (j * (l * cos((0.5d0 * k)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (l * (2.0 + (Math.pow(K, 2.0) * -0.25))));
	double tmp;
	if (l <= -1.9e+164) {
		tmp = t_0;
	} else if (l <= -60000000000000.0) {
		tmp = U + (Math.pow(K, 2.0) * (J * -0.03125));
	} else if ((l <= -2700000000.0) || !(l <= 3.5e+15)) {
		tmp = t_0;
	} else {
		tmp = U + (2.0 * (J * (l * Math.cos((0.5 * K)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * (l * (2.0 + (math.pow(K, 2.0) * -0.25))))
	tmp = 0
	if l <= -1.9e+164:
		tmp = t_0
	elif l <= -60000000000000.0:
		tmp = U + (math.pow(K, 2.0) * (J * -0.03125))
	elif (l <= -2700000000.0) or not (l <= 3.5e+15):
		tmp = t_0
	else:
		tmp = U + (2.0 * (J * (l * math.cos((0.5 * K)))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64((K ^ 2.0) * -0.25)))))
	tmp = 0.0
	if (l <= -1.9e+164)
		tmp = t_0;
	elseif (l <= -60000000000000.0)
		tmp = Float64(U + Float64((K ^ 2.0) * Float64(J * -0.03125)));
	elseif ((l <= -2700000000.0) || !(l <= 3.5e+15))
		tmp = t_0;
	else
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(0.5 * K))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (J * (l * (2.0 + ((K ^ 2.0) * -0.25))));
	tmp = 0.0;
	if (l <= -1.9e+164)
		tmp = t_0;
	elseif (l <= -60000000000000.0)
		tmp = U + ((K ^ 2.0) * (J * -0.03125));
	elseif ((l <= -2700000000.0) || ~((l <= 3.5e+15)))
		tmp = t_0;
	else
		tmp = U + (2.0 * (J * (l * cos((0.5 * K)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(J * N[(l * N[(2.0 + N[(N[Power[K, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.9e+164], t$95$0, If[LessEqual[l, -60000000000000.0], N[(U + N[(N[Power[K, 2.0], $MachinePrecision] * N[(J * -0.03125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, -2700000000.0], N[Not[LessEqual[l, 3.5e+15]], $MachinePrecision]], t$95$0, N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -60000000000000:\\
\;\;\;\;U + {K}^{2} \cdot \left(J \cdot -0.03125\right)\\

\mathbf{elif}\;\ell \leq -2700000000 \lor \neg \left(\ell \leq 3.5 \cdot 10^{+15}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.90000000000000011e164 or -6e13 < l < -2.7e9 or 3.5e15 < 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 35.8%

      \[\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*35.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(-J \cdot \left(-2 \cdot \ell\right)\right) + \left(-0.25 \cdot \color{blue}{\left(\left({K}^{2} \cdot \ell\right) \cdot J\right)}\right)\right) + U \]
      10. associate-*l*37.4%

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

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

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

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

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

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

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

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

    if -1.90000000000000011e164 < l < -6e13

    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.6%

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

      \[\leadsto \color{blue}{\left(-0.03125 \cdot \left(J \cdot {K}^{2}\right) + 0.25 \cdot J\right)} + U \]
    5. Taylor expanded in K around inf 33.0%

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

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

        \[\leadsto \color{blue}{\left({K}^{2} \cdot J\right)} \cdot -0.03125 + U \]
      3. associate-*l*33.0%

        \[\leadsto \color{blue}{{K}^{2} \cdot \left(J \cdot -0.03125\right)} + U \]
    7. Simplified33.0%

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

    if -2.7e9 < l < 3.5e15

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.9 \cdot 10^{+164}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + {K}^{2} \cdot -0.25\right)\right)\\ \mathbf{elif}\;\ell \leq -60000000000000:\\ \;\;\;\;U + {K}^{2} \cdot \left(J \cdot -0.03125\right)\\ \mathbf{elif}\;\ell \leq -2700000000 \lor \neg \left(\ell \leq 3.5 \cdot 10^{+15}\right):\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + {K}^{2} \cdot -0.25\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 55.2% accurate, 2.6× speedup?

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

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

\mathbf{elif}\;\ell \leq -19500000000000:\\
\;\;\;\;U + {K}^{2} \cdot \left(J \cdot -0.03125\right)\\

\mathbf{elif}\;\ell \leq 1.8 \cdot 10^{+15} \lor \neg \left(\ell \leq 2.7 \cdot 10^{+177}\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;{U}^{-3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.99999999999999976e166 or -1.95e13 < l < 1.8e15 or 2.69999999999999991e177 < l

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

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

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

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

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

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

    if -3.99999999999999976e166 < l < -1.95e13

    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.6%

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

      \[\leadsto \color{blue}{\left(-0.03125 \cdot \left(J \cdot {K}^{2}\right) + 0.25 \cdot J\right)} + U \]
    5. Taylor expanded in K around inf 33.0%

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

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

        \[\leadsto \color{blue}{\left({K}^{2} \cdot J\right)} \cdot -0.03125 + U \]
      3. associate-*l*33.0%

        \[\leadsto \color{blue}{{K}^{2} \cdot \left(J \cdot -0.03125\right)} + U \]
    7. Simplified33.0%

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

    if 1.8e15 < l < 2.69999999999999991e177

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr28.0%

      \[\leadsto \color{blue}{{U}^{-3}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification57.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4 \cdot 10^{+166}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{elif}\;\ell \leq -19500000000000:\\ \;\;\;\;U + {K}^{2} \cdot \left(J \cdot -0.03125\right)\\ \mathbf{elif}\;\ell \leq 1.8 \cdot 10^{+15} \lor \neg \left(\ell \leq 2.7 \cdot 10^{+177}\right):\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;{U}^{-3}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 54.8% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 1.8 \cdot 10^{+15} \lor \neg \left(\ell \leq 2.7 \cdot 10^{+177}\right):\\
\;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;{U}^{-3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 1.8e15 or 2.69999999999999991e177 < l

    1. Initial program 85.1%

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

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

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

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

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

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

    if 1.8e15 < l < 2.69999999999999991e177

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr28.0%

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

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

Alternative 10: 64.1% accurate, 2.8× speedup?

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

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

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

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

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

Alternative 11: 42.9% accurate, 20.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -200000000000 \lor \neg \left(\ell \leq 1000\right):\\ \;\;\;\;U \cdot \left(U + -1\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -200000000000.0) (not (<= l 1000.0))) (* U (+ U -1.0)) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -200000000000.0) || !(l <= 1000.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 <= (-200000000000.0d0)) .or. (.not. (l <= 1000.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 <= -200000000000.0) || !(l <= 1000.0)) {
		tmp = U * (U + -1.0);
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -200000000000.0) or not (l <= 1000.0):
		tmp = U * (U + -1.0)
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -200000000000.0) || !(l <= 1000.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 <= -200000000000.0) || ~((l <= 1000.0)))
		tmp = U * (U + -1.0);
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -200000000000.0], N[Not[LessEqual[l, 1000.0]], $MachinePrecision]], N[(U * N[(U + -1.0), $MachinePrecision]), $MachinePrecision], U]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -200000000000 \lor \neg \left(\ell \leq 1000\right):\\
\;\;\;\;U \cdot \left(U + -1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2e11 or 1e3 < 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 29.6%

      \[\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*29.6%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{U \cdot \left(U + -1\right)} \]
    8. Simplified12.4%

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

    if -2e11 < l < 1e3

    1. Initial program 73.7%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*73.7%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    3. Simplified73.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in J around 0 68.0%

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

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

Alternative 12: 42.9% accurate, 23.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -41000000000 \lor \neg \left(\ell \leq 620\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -41000000000.0) (not (<= l 620.0))) (* U U) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -41000000000.0) || !(l <= 620.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 <= (-41000000000.0d0)) .or. (.not. (l <= 620.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 <= -41000000000.0) || !(l <= 620.0)) {
		tmp = U * U;
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -41000000000.0) or not (l <= 620.0):
		tmp = U * U
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -41000000000.0) || !(l <= 620.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 <= -41000000000.0) || ~((l <= 620.0)))
		tmp = U * U;
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -41000000000.0], N[Not[LessEqual[l, 620.0]], $MachinePrecision]], N[(U * U), $MachinePrecision], U]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -41000000000 \lor \neg \left(\ell \leq 620\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -4.1e10 or 620 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr12.4%

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

    if -4.1e10 < l < 620

    1. Initial program 73.7%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*73.7%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    3. Simplified73.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in J around 0 68.0%

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

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

Alternative 13: 54.2% 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 87.2%

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

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

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

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

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

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

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

Alternative 14: 2.8% accurate, 312.0× speedup?

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

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

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Step-by-step derivation
    1. associate-*l*87.3%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
  3. Simplified87.3%

    \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
  4. Add Preprocessing
  5. Applied egg-rr2.6%

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

      \[\leadsto \color{blue}{1} \]
  7. Simplified2.6%

    \[\leadsto \color{blue}{1} \]
  8. Final simplification2.6%

    \[\leadsto 1 \]
  9. Add Preprocessing

Alternative 15: 36.7% accurate, 312.0× speedup?

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

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

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Step-by-step derivation
    1. associate-*l*87.3%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
  3. Simplified87.3%

    \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in J around 0 34.1%

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

    \[\leadsto U \]
  7. Add Preprocessing

Reproduce

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