Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.0% → 99.7%
Time: 11.6s
Alternatives: 18
Speedup: 1.3×

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 18 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.0% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 0.4× speedup?

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

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

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


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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1e-3

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.7% accurate, 0.4× speedup?

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

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

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


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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1e-3

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

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

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

Alternative 3: 95.5% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := U + {\ell}^{5} \cdot \left(J \cdot \left(t\_0 \cdot 0.016666666666666666\right)\right)\\ \mathbf{if}\;\ell \leq -1.9 \cdot 10^{+47}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -600:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 400000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t\_0\right)\right)\\ \mathbf{elif}\;\ell \leq 2.5 \cdot 10^{+43}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (* K 0.5)))
        (t_1 (+ U (* (pow l 5.0) (* J (* t_0 0.016666666666666666))))))
   (if (<= l -1.9e+47)
     t_1
     (if (<= l -600.0)
       (+ (* (- (exp l) (exp (- l))) J) U)
       (if (<= l 400000.0)
         (+ U (* 2.0 (* J (* l t_0))))
         (if (<= l 2.5e+43) (log1p (expm1 (- (/ -4.0 U) U))) t_1))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K * 0.5));
	double t_1 = U + (pow(l, 5.0) * (J * (t_0 * 0.016666666666666666)));
	double tmp;
	if (l <= -1.9e+47) {
		tmp = t_1;
	} else if (l <= -600.0) {
		tmp = ((exp(l) - exp(-l)) * J) + U;
	} else if (l <= 400000.0) {
		tmp = U + (2.0 * (J * (l * t_0)));
	} else if (l <= 2.5e+43) {
		tmp = log1p(expm1(((-4.0 / U) - U)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K * 0.5));
	double t_1 = U + (Math.pow(l, 5.0) * (J * (t_0 * 0.016666666666666666)));
	double tmp;
	if (l <= -1.9e+47) {
		tmp = t_1;
	} else if (l <= -600.0) {
		tmp = ((Math.exp(l) - Math.exp(-l)) * J) + U;
	} else if (l <= 400000.0) {
		tmp = U + (2.0 * (J * (l * t_0)));
	} else if (l <= 2.5e+43) {
		tmp = Math.log1p(Math.expm1(((-4.0 / U) - U)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K * 0.5))
	t_1 = U + (math.pow(l, 5.0) * (J * (t_0 * 0.016666666666666666)))
	tmp = 0
	if l <= -1.9e+47:
		tmp = t_1
	elif l <= -600.0:
		tmp = ((math.exp(l) - math.exp(-l)) * J) + U
	elif l <= 400000.0:
		tmp = U + (2.0 * (J * (l * t_0)))
	elif l <= 2.5e+43:
		tmp = math.log1p(math.expm1(((-4.0 / U) - U)))
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K * 0.5))
	t_1 = Float64(U + Float64((l ^ 5.0) * Float64(J * Float64(t_0 * 0.016666666666666666))))
	tmp = 0.0
	if (l <= -1.9e+47)
		tmp = t_1;
	elseif (l <= -600.0)
		tmp = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U);
	elseif (l <= 400000.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * t_0))));
	elseif (l <= 2.5e+43)
		tmp = log1p(expm1(Float64(Float64(-4.0 / U) - U)));
	else
		tmp = t_1;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(N[Power[l, 5.0], $MachinePrecision] * N[(J * N[(t$95$0 * 0.016666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.9e+47], t$95$1, If[LessEqual[l, -600.0], N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[l, 400000.0], N[(U + N[(2.0 * N[(J * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.5e+43], N[Log[1 + N[(Exp[N[(N[(-4.0 / U), $MachinePrecision] - U), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;\ell \leq 2.5 \cdot 10^{+43}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.9000000000000002e47 or 2.5000000000000002e43 < 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 98.2%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.9000000000000002e47 < l < -600

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

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

    if -600 < l < 4e5

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

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

    if 4e5 < l < 2.5000000000000002e43

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

      \[\leadsto \color{blue}{\frac{-4}{U} - U} \]
    4. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification97.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.9 \cdot 10^{+47}:\\ \;\;\;\;U + {\ell}^{5} \cdot \left(J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot 0.016666666666666666\right)\right)\\ \mathbf{elif}\;\ell \leq -600:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 400000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2.5 \cdot 10^{+43}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + {\ell}^{5} \cdot \left(J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot 0.016666666666666666\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 95.6% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + {\ell}^{5} \cdot \left(J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot 0.016666666666666666\right)\right)\\ \mathbf{if}\;\ell \leq -1.9 \cdot 10^{+47}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -600:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 400000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 10^{+41}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0
         (+ U (* (pow l 5.0) (* J (* (cos (* K 0.5)) 0.016666666666666666))))))
   (if (<= l -1.9e+47)
     t_0
     (if (<= l -600.0)
       (+ (* (- (exp l) (exp (- l))) J) U)
       (if (<= l 400000.0)
         (+
          U
          (*
           (cos (/ K 2.0))
           (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0)))))))
         (if (<= l 1e+41) (log1p (expm1 (- (/ -4.0 U) U))) t_0))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (pow(l, 5.0) * (J * (cos((K * 0.5)) * 0.016666666666666666)));
	double tmp;
	if (l <= -1.9e+47) {
		tmp = t_0;
	} else if (l <= -600.0) {
		tmp = ((exp(l) - exp(-l)) * J) + U;
	} else if (l <= 400000.0) {
		tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * pow(l, 2.0))))));
	} else if (l <= 1e+41) {
		tmp = log1p(expm1(((-4.0 / U) - U)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (Math.pow(l, 5.0) * (J * (Math.cos((K * 0.5)) * 0.016666666666666666)));
	double tmp;
	if (l <= -1.9e+47) {
		tmp = t_0;
	} else if (l <= -600.0) {
		tmp = ((Math.exp(l) - Math.exp(-l)) * J) + U;
	} else if (l <= 400000.0) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0))))));
	} else if (l <= 1e+41) {
		tmp = Math.log1p(Math.expm1(((-4.0 / U) - U)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (math.pow(l, 5.0) * (J * (math.cos((K * 0.5)) * 0.016666666666666666)))
	tmp = 0
	if l <= -1.9e+47:
		tmp = t_0
	elif l <= -600.0:
		tmp = ((math.exp(l) - math.exp(-l)) * J) + U
	elif l <= 400000.0:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0))))))
	elif l <= 1e+41:
		tmp = math.log1p(math.expm1(((-4.0 / U) - U)))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64((l ^ 5.0) * Float64(J * Float64(cos(Float64(K * 0.5)) * 0.016666666666666666))))
	tmp = 0.0
	if (l <= -1.9e+47)
		tmp = t_0;
	elseif (l <= -600.0)
		tmp = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U);
	elseif (l <= 400000.0)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0)))))));
	elseif (l <= 1e+41)
		tmp = log1p(expm1(Float64(Float64(-4.0 / U) - U)));
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[Power[l, 5.0], $MachinePrecision] * N[(J * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * 0.016666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.9e+47], t$95$0, If[LessEqual[l, -600.0], N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[l, 400000.0], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1e+41], N[Log[1 + N[(Exp[N[(N[(-4.0 / U), $MachinePrecision] - U), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;\ell \leq 10^{+41}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.9000000000000002e47 or 1.00000000000000001e41 < 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 98.2%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.9000000000000002e47 < l < -600

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

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

    if -600 < l < 4e5

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

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

    if 4e5 < l < 1.00000000000000001e41

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

      \[\leadsto \color{blue}{\frac{-4}{U} - U} \]
    4. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification98.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.9 \cdot 10^{+47}:\\ \;\;\;\;U + {\ell}^{5} \cdot \left(J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot 0.016666666666666666\right)\right)\\ \mathbf{elif}\;\ell \leq -600:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 400000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 10^{+41}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + {\ell}^{5} \cdot \left(J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot 0.016666666666666666\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 72.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := U \cdot \left(1 + 2 \cdot \left(\ell \cdot \left(J \cdot \frac{t\_0}{U}\right)\right)\right)\\ t_2 := \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{if}\;\ell \leq -1.28 \cdot 10^{+132}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -3700000000000:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\ell \leq 400000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t\_0\right)\right)\\ \mathbf{elif}\;\ell \leq 5.1 \cdot 10^{+116}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+160}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 1.1 \cdot 10^{+217}:\\ \;\;\;\;U \cdot \left(1 + \left(J \cdot 2\right) \cdot \frac{\ell}{U}\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (* K 0.5)))
        (t_1 (* U (+ 1.0 (* 2.0 (* l (* J (/ t_0 U)))))))
        (t_2 (log1p (expm1 (- (/ -4.0 U) U)))))
   (if (<= l -1.28e+132)
     t_1
     (if (<= l -3700000000000.0)
       t_2
       (if (<= l 400000.0)
         (+ U (* 2.0 (* J (* l t_0))))
         (if (<= l 5.1e+116)
           t_2
           (if (<= l 1.9e+160)
             (pow U -3.0)
             (if (<= l 1.1e+217)
               (* U (+ 1.0 (* (* J 2.0) (/ l U))))
               t_1))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K * 0.5));
	double t_1 = U * (1.0 + (2.0 * (l * (J * (t_0 / U)))));
	double t_2 = log1p(expm1(((-4.0 / U) - U)));
	double tmp;
	if (l <= -1.28e+132) {
		tmp = t_1;
	} else if (l <= -3700000000000.0) {
		tmp = t_2;
	} else if (l <= 400000.0) {
		tmp = U + (2.0 * (J * (l * t_0)));
	} else if (l <= 5.1e+116) {
		tmp = t_2;
	} else if (l <= 1.9e+160) {
		tmp = pow(U, -3.0);
	} else if (l <= 1.1e+217) {
		tmp = U * (1.0 + ((J * 2.0) * (l / U)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K * 0.5));
	double t_1 = U * (1.0 + (2.0 * (l * (J * (t_0 / U)))));
	double t_2 = Math.log1p(Math.expm1(((-4.0 / U) - U)));
	double tmp;
	if (l <= -1.28e+132) {
		tmp = t_1;
	} else if (l <= -3700000000000.0) {
		tmp = t_2;
	} else if (l <= 400000.0) {
		tmp = U + (2.0 * (J * (l * t_0)));
	} else if (l <= 5.1e+116) {
		tmp = t_2;
	} else if (l <= 1.9e+160) {
		tmp = Math.pow(U, -3.0);
	} else if (l <= 1.1e+217) {
		tmp = U * (1.0 + ((J * 2.0) * (l / U)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K * 0.5))
	t_1 = U * (1.0 + (2.0 * (l * (J * (t_0 / U)))))
	t_2 = math.log1p(math.expm1(((-4.0 / U) - U)))
	tmp = 0
	if l <= -1.28e+132:
		tmp = t_1
	elif l <= -3700000000000.0:
		tmp = t_2
	elif l <= 400000.0:
		tmp = U + (2.0 * (J * (l * t_0)))
	elif l <= 5.1e+116:
		tmp = t_2
	elif l <= 1.9e+160:
		tmp = math.pow(U, -3.0)
	elif l <= 1.1e+217:
		tmp = U * (1.0 + ((J * 2.0) * (l / U)))
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K * 0.5))
	t_1 = Float64(U * Float64(1.0 + Float64(2.0 * Float64(l * Float64(J * Float64(t_0 / U))))))
	t_2 = log1p(expm1(Float64(Float64(-4.0 / U) - U)))
	tmp = 0.0
	if (l <= -1.28e+132)
		tmp = t_1;
	elseif (l <= -3700000000000.0)
		tmp = t_2;
	elseif (l <= 400000.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * t_0))));
	elseif (l <= 5.1e+116)
		tmp = t_2;
	elseif (l <= 1.9e+160)
		tmp = U ^ -3.0;
	elseif (l <= 1.1e+217)
		tmp = Float64(U * Float64(1.0 + Float64(Float64(J * 2.0) * Float64(l / U))));
	else
		tmp = t_1;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U * N[(1.0 + N[(2.0 * N[(l * N[(J * N[(t$95$0 / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Log[1 + N[(Exp[N[(N[(-4.0 / U), $MachinePrecision] - U), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -1.28e+132], t$95$1, If[LessEqual[l, -3700000000000.0], t$95$2, If[LessEqual[l, 400000.0], N[(U + N[(2.0 * N[(J * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.1e+116], t$95$2, If[LessEqual[l, 1.9e+160], N[Power[U, -3.0], $MachinePrecision], If[LessEqual[l, 1.1e+217], N[(U * N[(1.0 + N[(N[(J * 2.0), $MachinePrecision] * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
t_1 := U \cdot \left(1 + 2 \cdot \left(\ell \cdot \left(J \cdot \frac{t\_0}{U}\right)\right)\right)\\
t_2 := \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\
\mathbf{if}\;\ell \leq -1.28 \cdot 10^{+132}:\\
\;\;\;\;t\_1\\

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

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

\mathbf{elif}\;\ell \leq 5.1 \cdot 10^{+116}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+160}:\\
\;\;\;\;{U}^{-3}\\

\mathbf{elif}\;\ell \leq 1.1 \cdot 10^{+217}:\\
\;\;\;\;U \cdot \left(1 + \left(J \cdot 2\right) \cdot \frac{\ell}{U}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if l < -1.2800000000000001e132 or 1.1e217 < 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 55.0%

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

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

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

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

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

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

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

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

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(\ell \cdot \left(J \cdot \frac{\cos \left(0.5 \cdot K\right)}{U}\right)\right)}\right) \]
    10. Applied egg-rr68.8%

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

    if -1.2800000000000001e132 < l < -3.7e12 or 4e5 < l < 5.09999999999999999e116

    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-rr3.3%

      \[\leadsto \color{blue}{\frac{-4}{U} - U} \]
    4. Step-by-step derivation
      1. log1p-expm1-u64.0%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)} \]
    5. Applied egg-rr64.0%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)} \]

    if -3.7e12 < l < 4e5

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

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

    if 5.09999999999999999e116 < l < 1.90000000000000006e160

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

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

    if 1.90000000000000006e160 < l < 1.1e217

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.28 \cdot 10^{+132}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(\ell \cdot \left(J \cdot \frac{\cos \left(K \cdot 0.5\right)}{U}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -3700000000000:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{elif}\;\ell \leq 400000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 5.1 \cdot 10^{+116}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+160}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 1.1 \cdot 10^{+217}:\\ \;\;\;\;U \cdot \left(1 + \left(J \cdot 2\right) \cdot \frac{\ell}{U}\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(\ell \cdot \left(J \cdot \frac{\cos \left(K \cdot 0.5\right)}{U}\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 85.6% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq 7.5 \cdot 10^{-6}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t\_1\right)\right)\\

\mathbf{elif}\;\ell \leq 1.3 \cdot 10^{+250}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -780 or 7.50000000000000019e-6 < l < 1.30000000000000006e250

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

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

    if -780 < l < 7.50000000000000019e-6

    1. Initial program 74.9%

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

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

    if 1.30000000000000006e250 < 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 74.7%

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

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

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

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

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

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

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

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

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(\ell \cdot \left(J \cdot \frac{\cos \left(0.5 \cdot K\right)}{U}\right)\right)}\right) \]
    10. Applied egg-rr87.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -780:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 7.5 \cdot 10^{-6}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.3 \cdot 10^{+250}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(\ell \cdot \left(J \cdot \frac{\cos \left(K \cdot 0.5\right)}{U}\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 66.3% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto U \cdot \left(1 + \color{blue}{\left(J \cdot 2\right)} \cdot \frac{\ell}{U}\right) \]
    11. Simplified69.3%

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

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

Alternative 8: 67.2% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto U \cdot \left(1 + \color{blue}{\left(J \cdot 2\right)} \cdot \frac{\ell}{U}\right) \]
    11. Simplified69.3%

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

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

Alternative 9: 65.0% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 89.9%

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

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

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

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

      \[\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. Taylor expanded in K around inf 60.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 67.7% accurate, 2.7× speedup?

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

\\
U \cdot \left(1 + 2 \cdot \frac{\cos \left(K \cdot 0.5\right) \cdot \left(\ell \cdot J\right)}{U}\right)
\end{array}
Derivation
  1. Initial program 87.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 65.6%

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

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

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

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

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

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

    \[\leadsto U \cdot \left(1 + 2 \cdot \frac{\cos \left(K \cdot 0.5\right) \cdot \left(\ell \cdot J\right)}{U}\right) \]
  10. Add Preprocessing

Alternative 11: 41.4% accurate, 20.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -5.2 \cdot 10^{+37} \lor \neg \left(\ell \leq 400000\right):\\ \;\;\;\;U \cdot \left(U - -4\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -5.2e+37) (not (<= l 400000.0))) (* U (- U -4.0)) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -5.2e+37) || !(l <= 400000.0)) {
		tmp = U * (U - -4.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 <= (-5.2d+37)) .or. (.not. (l <= 400000.0d0))) then
        tmp = u * (u - (-4.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 <= -5.2e+37) || !(l <= 400000.0)) {
		tmp = U * (U - -4.0);
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -5.2e+37) or not (l <= 400000.0):
		tmp = U * (U - -4.0)
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -5.2e+37) || !(l <= 400000.0))
		tmp = Float64(U * Float64(U - -4.0));
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -5.2e+37) || ~((l <= 400000.0)))
		tmp = U * (U - -4.0);
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -5.2e+37], N[Not[LessEqual[l, 400000.0]], $MachinePrecision]], N[(U * N[(U - -4.0), $MachinePrecision]), $MachinePrecision], U]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.2 \cdot 10^{+37} \lor \neg \left(\ell \leq 400000\right):\\
\;\;\;\;U \cdot \left(U - -4\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.1999999999999998e37 or 4e5 < 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. Applied egg-rr16.4%

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

    if -5.1999999999999998e37 < l < 4e5

    1. Initial program 77.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 J around 0 68.6%

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

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

Alternative 12: 45.4% accurate, 20.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -7.3 \cdot 10^{+15} \lor \neg \left(\ell \leq 450\right):\\ \;\;\;\;\ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -7.3e+15) (not (<= l 450.0))) (* l (* J 2.0)) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -7.3e+15) || !(l <= 450.0)) {
		tmp = l * (J * 2.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 <= (-7.3d+15)) .or. (.not. (l <= 450.0d0))) then
        tmp = l * (j * 2.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 <= -7.3e+15) || !(l <= 450.0)) {
		tmp = l * (J * 2.0);
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -7.3e+15) or not (l <= 450.0):
		tmp = l * (J * 2.0)
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -7.3e+15) || !(l <= 450.0))
		tmp = Float64(l * Float64(J * 2.0));
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -7.3e+15) || ~((l <= 450.0)))
		tmp = l * (J * 2.0);
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -7.3e+15], N[Not[LessEqual[l, 450.0]], $MachinePrecision]], N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision], U]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -7.3 \cdot 10^{+15} \lor \neg \left(\ell \leq 450\right):\\
\;\;\;\;\ell \cdot \left(J \cdot 2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -7.3e15 or 450 < 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 32.1%

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

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

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

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

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

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

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

        \[\leadsto 2 \cdot \color{blue}{\left(\left(J \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)\right)} \]
    11. Simplified32.3%

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

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

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

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

        \[\leadsto \color{blue}{\ell \cdot \left(J \cdot 2\right)} \]
    14. Simplified21.2%

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

    if -7.3e15 < l < 450

    1. Initial program 76.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 J around 0 72.1%

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

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

Alternative 13: 41.4% accurate, 23.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.9 \cdot 10^{+37} \lor \neg \left(\ell \leq 400000\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.89999999999999978e37 or 4e5 < 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. Applied egg-rr16.4%

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

    if -2.89999999999999978e37 < l < 4e5

    1. Initial program 77.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 J around 0 68.6%

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

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

Alternative 14: 56.9% accurate, 28.4× speedup?

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

\\
U \cdot \left(1 + 2 \cdot \frac{\ell \cdot J}{U}\right)
\end{array}
Derivation
  1. Initial program 87.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 65.6%

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

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

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

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

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

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

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

    \[\leadsto U \cdot \left(1 + 2 \cdot \frac{\ell \cdot J}{U}\right) \]
  11. Add Preprocessing

Alternative 15: 59.5% accurate, 28.4× speedup?

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

\\
U \cdot \left(1 + \left(J \cdot 2\right) \cdot \frac{\ell}{U}\right)
\end{array}
Derivation
  1. Initial program 87.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 65.6%

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

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

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

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

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

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

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

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

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

      \[\leadsto U \cdot \left(1 + \color{blue}{\left(J \cdot 2\right)} \cdot \frac{\ell}{U}\right) \]
  11. Simplified60.8%

    \[\leadsto U \cdot \left(1 + \color{blue}{\left(J \cdot 2\right) \cdot \frac{\ell}{U}}\right) \]
  12. Final simplification60.8%

    \[\leadsto U \cdot \left(1 + \left(J \cdot 2\right) \cdot \frac{\ell}{U}\right) \]
  13. Add Preprocessing

Alternative 16: 53.3% 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.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 65.6%

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

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

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

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

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

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

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

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

Alternative 17: 2.7% 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.6%

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

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

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

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

    \[\leadsto 1 \]
  7. Add Preprocessing

Alternative 18: 36.4% 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.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 38.4%

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

    \[\leadsto U \]
  5. Add Preprocessing

Reproduce

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