Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.2% → 99.4%
Time: 16.1s
Alternatives: 16
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 16 alternatives:

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

Initial Program: 86.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.4% accurate, 1.0× speedup?

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

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

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

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

    \[\leadsto 2 \cdot \left(J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)}\right) + U \]
  6. Final simplification100.0%

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

Alternative 2: 87.2% accurate, 0.5× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1.00000000000000006e-9

    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}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.8%

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

Alternative 3: 94.4% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := U + t\_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ t_2 := U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{if}\;\ell \leq -2.8 \cdot 10^{+74}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -0.001:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\ell \leq 8 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(J, t\_0 \cdot \left(2 \cdot \ell\right), U\right)\\ \mathbf{elif}\;\ell \leq 1.85 \cdot 10^{+90}:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1 (+ U (* t_0 (* J (* 0.3333333333333333 (pow l 3.0))))))
        (t_2 (+ U (* J (- (exp l) (exp (- l)))))))
   (if (<= l -2.8e+74)
     t_1
     (if (<= l -0.001)
       t_2
       (if (<= l 8e-7)
         (fma J (* t_0 (* 2.0 l)) U)
         (if (<= l 1.85e+90) t_2 t_1))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = U + (t_0 * (J * (0.3333333333333333 * pow(l, 3.0))));
	double t_2 = U + (J * (exp(l) - exp(-l)));
	double tmp;
	if (l <= -2.8e+74) {
		tmp = t_1;
	} else if (l <= -0.001) {
		tmp = t_2;
	} else if (l <= 8e-7) {
		tmp = fma(J, (t_0 * (2.0 * l)), U);
	} else if (l <= 1.85e+90) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(U + Float64(t_0 * Float64(J * Float64(0.3333333333333333 * (l ^ 3.0)))))
	t_2 = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l)))))
	tmp = 0.0
	if (l <= -2.8e+74)
		tmp = t_1;
	elseif (l <= -0.001)
		tmp = t_2;
	elseif (l <= 8e-7)
		tmp = fma(J, Float64(t_0 * Float64(2.0 * l)), U);
	elseif (l <= 1.85e+90)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(t$95$0 * N[(J * N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.8e+74], t$95$1, If[LessEqual[l, -0.001], t$95$2, If[LessEqual[l, 8e-7], N[(J * N[(t$95$0 * N[(2.0 * l), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[l, 1.85e+90], t$95$2, t$95$1]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\ell \leq 8 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(J, t\_0 \cdot \left(2 \cdot \ell\right), U\right)\\

\mathbf{elif}\;\ell \leq 1.85 \cdot 10^{+90}:\\
\;\;\;\;t\_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.80000000000000002e74 or 1.85e90 < 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 95.9%

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

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

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

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

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

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

    if -2.80000000000000002e74 < l < -1e-3 or 7.9999999999999996e-7 < l < 1.85e90

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

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

    if -1e-3 < l < 7.9999999999999996e-7

    1. Initial program 75.2%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.8 \cdot 10^{+74}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -0.001:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 8 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(J, \cos \left(\frac{K}{2}\right) \cdot \left(2 \cdot \ell\right), U\right)\\ \mathbf{elif}\;\ell \leq 1.85 \cdot 10^{+90}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 79.7% accurate, 1.4× speedup?

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

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

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


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

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

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Taylor expanded in U around inf 70.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)} \]
    5. Step-by-step derivation
      1. associate-*r/70.0%

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

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

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

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

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

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

    1. Initial program 87.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 90.1%

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

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

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

Alternative 5: 87.5% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -0.000115 \lor \neg \left(\ell \leq 8 \cdot 10^{-7}\right):\\
\;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.15e-4 or 7.9999999999999996e-7 < l

    1. Initial program 100.0%

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

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

    if -1.15e-4 < l < 7.9999999999999996e-7

    1. Initial program 75.2%

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

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

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

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

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

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

Alternative 6: 78.7% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 87.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 90.1%

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

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

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

Alternative 7: 87.8% accurate, 1.4× speedup?

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

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

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

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

Alternative 8: 54.4% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1.12 \cdot 10^{+104}:\\ \;\;\;\;U + J \cdot \left(2 \cdot \ell\right)\\ \mathbf{elif}\;\ell \leq -4200000:\\ \;\;\;\;\frac{0.25 + \frac{\frac{0.140625 + \frac{0.10546875}{U}}{U} + -0.1875}{U}}{U}\\ \mathbf{elif}\;\ell \leq 700:\\ \;\;\;\;\mathsf{fma}\left(\ell, 2 \cdot J, U\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25 + \frac{0.1875 + \frac{-0.140625}{U}}{U}}{-U}\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -1.12e+104)
   (+ U (* J (* 2.0 l)))
   (if (<= l -4200000.0)
     (/ (+ 0.25 (/ (+ (/ (+ 0.140625 (/ 0.10546875 U)) U) -0.1875) U)) U)
     (if (<= l 700.0)
       (fma l (* 2.0 J) U)
       (/ (+ 0.25 (/ (+ 0.1875 (/ -0.140625 U)) U)) (- U))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -1.12e+104) {
		tmp = U + (J * (2.0 * l));
	} else if (l <= -4200000.0) {
		tmp = (0.25 + ((((0.140625 + (0.10546875 / U)) / U) + -0.1875) / U)) / U;
	} else if (l <= 700.0) {
		tmp = fma(l, (2.0 * J), U);
	} else {
		tmp = (0.25 + ((0.1875 + (-0.140625 / U)) / U)) / -U;
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -1.12e+104)
		tmp = Float64(U + Float64(J * Float64(2.0 * l)));
	elseif (l <= -4200000.0)
		tmp = Float64(Float64(0.25 + Float64(Float64(Float64(Float64(0.140625 + Float64(0.10546875 / U)) / U) + -0.1875) / U)) / U);
	elseif (l <= 700.0)
		tmp = fma(l, Float64(2.0 * J), U);
	else
		tmp = Float64(Float64(0.25 + Float64(Float64(0.1875 + Float64(-0.140625 / U)) / U)) / Float64(-U));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, -1.12e+104], N[(U + N[(J * N[(2.0 * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -4200000.0], N[(N[(0.25 + N[(N[(N[(N[(0.140625 + N[(0.10546875 / U), $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision] + -0.1875), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision], If[LessEqual[l, 700.0], N[(l * N[(2.0 * J), $MachinePrecision] + U), $MachinePrecision], N[(N[(0.25 + N[(N[(0.1875 + N[(-0.140625 / U), $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision] / (-U)), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -4200000:\\
\;\;\;\;\frac{0.25 + \frac{\frac{0.140625 + \frac{0.10546875}{U}}{U} + -0.1875}{U}}{U}\\

\mathbf{elif}\;\ell \leq 700:\\
\;\;\;\;\mathsf{fma}\left(\ell, 2 \cdot J, U\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{0.25 + \frac{0.1875 + \frac{-0.140625}{U}}{U}}{-U}\\


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -1.12000000000000003e104 < l < -4.2e6

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\frac{U}{U + \left(-4 \cdot U + U \cdot \left(-4 \cdot U\right)\right)}} \]
    4. Step-by-step derivation
      1. associate-+r+1.4%

        \[\leadsto \frac{U}{\color{blue}{\left(U + -4 \cdot U\right) + U \cdot \left(-4 \cdot U\right)}} \]
      2. distribute-rgt1-in1.4%

        \[\leadsto \frac{U}{\color{blue}{\left(-4 + 1\right) \cdot U} + U \cdot \left(-4 \cdot U\right)} \]
      3. metadata-eval1.4%

        \[\leadsto \frac{U}{\color{blue}{-3} \cdot U + U \cdot \left(-4 \cdot U\right)} \]
      4. *-commutative1.4%

        \[\leadsto \frac{U}{\color{blue}{U \cdot -3} + U \cdot \left(-4 \cdot U\right)} \]
      5. distribute-lft-out1.4%

        \[\leadsto \frac{U}{\color{blue}{U \cdot \left(-3 + -4 \cdot U\right)}} \]
      6. associate-/r*1.4%

        \[\leadsto \color{blue}{\frac{\frac{U}{U}}{-3 + -4 \cdot U}} \]
      7. *-inverses1.4%

        \[\leadsto \frac{\color{blue}{1}}{-3 + -4 \cdot U} \]
      8. +-commutative1.4%

        \[\leadsto \frac{1}{\color{blue}{-4 \cdot U + -3}} \]
      9. *-commutative1.4%

        \[\leadsto \frac{1}{\color{blue}{U \cdot -4} + -3} \]
    5. Simplified1.4%

      \[\leadsto \color{blue}{\frac{1}{U \cdot -4 + -3}} \]
    6. Taylor expanded in U around -inf 50.5%

      \[\leadsto \color{blue}{-1 \cdot \frac{0.25 + -1 \cdot \frac{0.1875 + -1 \cdot \frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}}{U}}{U}} \]
    7. Step-by-step derivation
      1. mul-1-neg50.5%

        \[\leadsto \color{blue}{-\frac{0.25 + -1 \cdot \frac{0.1875 + -1 \cdot \frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}}{U}}{U}} \]
      2. distribute-neg-frac250.5%

        \[\leadsto \color{blue}{\frac{0.25 + -1 \cdot \frac{0.1875 + -1 \cdot \frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}}{U}}{-U}} \]
      3. mul-1-neg50.5%

        \[\leadsto \frac{0.25 + \color{blue}{\left(-\frac{0.1875 + -1 \cdot \frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}}{U}\right)}}{-U} \]
      4. unsub-neg50.5%

        \[\leadsto \frac{\color{blue}{0.25 - \frac{0.1875 + -1 \cdot \frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}}{U}}}{-U} \]
      5. mul-1-neg50.5%

        \[\leadsto \frac{0.25 - \frac{0.1875 + \color{blue}{\left(-\frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}\right)}}{U}}{-U} \]
      6. unsub-neg50.5%

        \[\leadsto \frac{0.25 - \frac{\color{blue}{0.1875 - \frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}}}{U}}{-U} \]
      7. associate-*r/50.5%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \color{blue}{\frac{0.10546875 \cdot 1}{U}}}{U}}{U}}{-U} \]
      8. metadata-eval50.5%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{\color{blue}{0.10546875}}{U}}{U}}{U}}{-U} \]
    8. Simplified50.5%

      \[\leadsto \color{blue}{\frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}}{-U}} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt36.7%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}}{\color{blue}{\sqrt{-U} \cdot \sqrt{-U}}} \]
      2. sqrt-unprod37.2%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}}{\color{blue}{\sqrt{\left(-U\right) \cdot \left(-U\right)}}} \]
      3. sqr-neg37.2%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}}{\sqrt{\color{blue}{U \cdot U}}} \]
      4. sqrt-unprod0.5%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}}{\color{blue}{\sqrt{U} \cdot \sqrt{U}}} \]
      5. add-sqr-sqrt14.6%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}}{\color{blue}{U}} \]
      6. div-inv14.6%

        \[\leadsto \color{blue}{\left(0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}\right) \cdot \frac{1}{U}} \]
    10. Applied egg-rr50.6%

      \[\leadsto \color{blue}{\left(0.25 + \frac{-0.1875 + \frac{0.140625 + \frac{0.10546875}{U}}{U}}{U}\right) \cdot \frac{1}{U}} \]
    11. Step-by-step derivation
      1. associate-*r/50.6%

        \[\leadsto \color{blue}{\frac{\left(0.25 + \frac{-0.1875 + \frac{0.140625 + \frac{0.10546875}{U}}{U}}{U}\right) \cdot 1}{U}} \]
      2. *-rgt-identity50.6%

        \[\leadsto \frac{\color{blue}{0.25 + \frac{-0.1875 + \frac{0.140625 + \frac{0.10546875}{U}}{U}}{U}}}{U} \]
      3. +-commutative50.6%

        \[\leadsto \frac{0.25 + \frac{\color{blue}{\frac{0.140625 + \frac{0.10546875}{U}}{U} + -0.1875}}{U}}{U} \]
    12. Simplified50.6%

      \[\leadsto \color{blue}{\frac{0.25 + \frac{\frac{0.140625 + \frac{0.10546875}{U}}{U} + -0.1875}{U}}{U}} \]

    if -4.2e6 < l < 700

    1. Initial program 75.6%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\ell, 2 \cdot J, U\right)} \]
    6. Simplified87.6%

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

    if 700 < 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-rr1.9%

      \[\leadsto \color{blue}{\frac{U}{U + \left(-4 \cdot U + U \cdot \left(-4 \cdot U\right)\right)}} \]
    4. Step-by-step derivation
      1. associate-+r+1.9%

        \[\leadsto \frac{U}{\color{blue}{\left(U + -4 \cdot U\right) + U \cdot \left(-4 \cdot U\right)}} \]
      2. distribute-rgt1-in1.9%

        \[\leadsto \frac{U}{\color{blue}{\left(-4 + 1\right) \cdot U} + U \cdot \left(-4 \cdot U\right)} \]
      3. metadata-eval1.9%

        \[\leadsto \frac{U}{\color{blue}{-3} \cdot U + U \cdot \left(-4 \cdot U\right)} \]
      4. *-commutative1.9%

        \[\leadsto \frac{U}{\color{blue}{U \cdot -3} + U \cdot \left(-4 \cdot U\right)} \]
      5. distribute-lft-out1.9%

        \[\leadsto \frac{U}{\color{blue}{U \cdot \left(-3 + -4 \cdot U\right)}} \]
      6. associate-/r*1.9%

        \[\leadsto \color{blue}{\frac{\frac{U}{U}}{-3 + -4 \cdot U}} \]
      7. *-inverses1.9%

        \[\leadsto \frac{\color{blue}{1}}{-3 + -4 \cdot U} \]
      8. +-commutative1.9%

        \[\leadsto \frac{1}{\color{blue}{-4 \cdot U + -3}} \]
      9. *-commutative1.9%

        \[\leadsto \frac{1}{\color{blue}{U \cdot -4} + -3} \]
    5. Simplified1.9%

      \[\leadsto \color{blue}{\frac{1}{U \cdot -4 + -3}} \]
    6. Taylor expanded in U around -inf 8.2%

      \[\leadsto \color{blue}{-1 \cdot \frac{0.25 + -1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}}{U}} \]
    7. Step-by-step derivation
      1. *-un-lft-identity8.2%

        \[\leadsto -1 \cdot \color{blue}{\left(1 \cdot \frac{0.25 + -1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}}{U}\right)} \]
      2. add-sqr-sqrt7.9%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \color{blue}{\sqrt{-1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}} \cdot \sqrt{-1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}}}}{U}\right) \]
      3. sqrt-unprod8.2%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \color{blue}{\sqrt{\left(-1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}\right) \cdot \left(-1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}\right)}}}{U}\right) \]
      4. mul-1-neg8.2%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \sqrt{\color{blue}{\left(-\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}\right)} \cdot \left(-1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}\right)}}{U}\right) \]
      5. mul-1-neg8.2%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \sqrt{\left(-\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}\right) \cdot \color{blue}{\left(-\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}\right)}}}{U}\right) \]
      6. sqr-neg8.2%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \sqrt{\color{blue}{\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U} \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}}}}{U}\right) \]
      7. sqrt-unprod0.3%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \color{blue}{\sqrt{\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}} \cdot \sqrt{\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}}}}{U}\right) \]
      8. add-sqr-sqrt28.1%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \color{blue}{\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}}}{U}\right) \]
      9. cancel-sign-sub-inv28.1%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \frac{\color{blue}{0.1875 + \left(-0.140625\right) \cdot \frac{1}{U}}}{U}}{U}\right) \]
      10. un-div-inv28.1%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \frac{0.1875 + \color{blue}{\frac{-0.140625}{U}}}{U}}{U}\right) \]
      11. metadata-eval28.1%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \frac{0.1875 + \frac{\color{blue}{-0.140625}}{U}}{U}}{U}\right) \]
    8. Applied egg-rr28.1%

      \[\leadsto -1 \cdot \color{blue}{\left(1 \cdot \frac{0.25 + \frac{0.1875 + \frac{-0.140625}{U}}{U}}{U}\right)} \]
    9. Step-by-step derivation
      1. *-lft-identity28.1%

        \[\leadsto -1 \cdot \color{blue}{\frac{0.25 + \frac{0.1875 + \frac{-0.140625}{U}}{U}}{U}} \]
    10. Simplified28.1%

      \[\leadsto -1 \cdot \color{blue}{\frac{0.25 + \frac{0.1875 + \frac{-0.140625}{U}}{U}}{U}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification61.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.12 \cdot 10^{+104}:\\ \;\;\;\;U + J \cdot \left(2 \cdot \ell\right)\\ \mathbf{elif}\;\ell \leq -4200000:\\ \;\;\;\;\frac{0.25 + \frac{\frac{0.140625 + \frac{0.10546875}{U}}{U} + -0.1875}{U}}{U}\\ \mathbf{elif}\;\ell \leq 700:\\ \;\;\;\;\mathsf{fma}\left(\ell, 2 \cdot J, U\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25 + \frac{0.1875 + \frac{-0.140625}{U}}{U}}{-U}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 64.4% accurate, 2.8× speedup?

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

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

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

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

Alternative 10: 54.4% accurate, 11.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(2 \cdot \ell\right)\\ \mathbf{if}\;\ell \leq -3.8 \cdot 10^{+101}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -9500000:\\ \;\;\;\;\frac{0.25 + \frac{\frac{0.140625 + \frac{0.10546875}{U}}{U} + -0.1875}{U}}{U}\\ \mathbf{elif}\;\ell \leq 520:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25 + \frac{0.1875 + \frac{-0.140625}{U}}{U}}{-U}\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* J (* 2.0 l)))))
   (if (<= l -3.8e+101)
     t_0
     (if (<= l -9500000.0)
       (/ (+ 0.25 (/ (+ (/ (+ 0.140625 (/ 0.10546875 U)) U) -0.1875) U)) U)
       (if (<= l 520.0)
         t_0
         (/ (+ 0.25 (/ (+ 0.1875 (/ -0.140625 U)) U)) (- U)))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (2.0 * l));
	double tmp;
	if (l <= -3.8e+101) {
		tmp = t_0;
	} else if (l <= -9500000.0) {
		tmp = (0.25 + ((((0.140625 + (0.10546875 / U)) / U) + -0.1875) / U)) / U;
	} else if (l <= 520.0) {
		tmp = t_0;
	} else {
		tmp = (0.25 + ((0.1875 + (-0.140625 / U)) / U)) / -U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = u + (j * (2.0d0 * l))
    if (l <= (-3.8d+101)) then
        tmp = t_0
    else if (l <= (-9500000.0d0)) then
        tmp = (0.25d0 + ((((0.140625d0 + (0.10546875d0 / u)) / u) + (-0.1875d0)) / u)) / u
    else if (l <= 520.0d0) then
        tmp = t_0
    else
        tmp = (0.25d0 + ((0.1875d0 + ((-0.140625d0) / u)) / u)) / -u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (2.0 * l));
	double tmp;
	if (l <= -3.8e+101) {
		tmp = t_0;
	} else if (l <= -9500000.0) {
		tmp = (0.25 + ((((0.140625 + (0.10546875 / U)) / U) + -0.1875) / U)) / U;
	} else if (l <= 520.0) {
		tmp = t_0;
	} else {
		tmp = (0.25 + ((0.1875 + (-0.140625 / U)) / U)) / -U;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * (2.0 * l))
	tmp = 0
	if l <= -3.8e+101:
		tmp = t_0
	elif l <= -9500000.0:
		tmp = (0.25 + ((((0.140625 + (0.10546875 / U)) / U) + -0.1875) / U)) / U
	elif l <= 520.0:
		tmp = t_0
	else:
		tmp = (0.25 + ((0.1875 + (-0.140625 / U)) / U)) / -U
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(J * Float64(2.0 * l)))
	tmp = 0.0
	if (l <= -3.8e+101)
		tmp = t_0;
	elseif (l <= -9500000.0)
		tmp = Float64(Float64(0.25 + Float64(Float64(Float64(Float64(0.140625 + Float64(0.10546875 / U)) / U) + -0.1875) / U)) / U);
	elseif (l <= 520.0)
		tmp = t_0;
	else
		tmp = Float64(Float64(0.25 + Float64(Float64(0.1875 + Float64(-0.140625 / U)) / U)) / Float64(-U));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (J * (2.0 * l));
	tmp = 0.0;
	if (l <= -3.8e+101)
		tmp = t_0;
	elseif (l <= -9500000.0)
		tmp = (0.25 + ((((0.140625 + (0.10546875 / U)) / U) + -0.1875) / U)) / U;
	elseif (l <= 520.0)
		tmp = t_0;
	else
		tmp = (0.25 + ((0.1875 + (-0.140625 / U)) / U)) / -U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(J * N[(2.0 * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.8e+101], t$95$0, If[LessEqual[l, -9500000.0], N[(N[(0.25 + N[(N[(N[(N[(0.140625 + N[(0.10546875 / U), $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision] + -0.1875), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision], If[LessEqual[l, 520.0], t$95$0, N[(N[(0.25 + N[(N[(0.1875 + N[(-0.140625 / U), $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision] / (-U)), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -9500000:\\
\;\;\;\;\frac{0.25 + \frac{\frac{0.140625 + \frac{0.10546875}{U}}{U} + -0.1875}{U}}{U}\\

\mathbf{elif}\;\ell \leq 520:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{0.25 + \frac{0.1875 + \frac{-0.140625}{U}}{U}}{-U}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.7999999999999998e101 or -9.5e6 < l < 520

    1. Initial program 81.4%

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

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

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

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

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

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

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

    if -3.7999999999999998e101 < l < -9.5e6

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\frac{U}{U + \left(-4 \cdot U + U \cdot \left(-4 \cdot U\right)\right)}} \]
    4. Step-by-step derivation
      1. associate-+r+1.4%

        \[\leadsto \frac{U}{\color{blue}{\left(U + -4 \cdot U\right) + U \cdot \left(-4 \cdot U\right)}} \]
      2. distribute-rgt1-in1.4%

        \[\leadsto \frac{U}{\color{blue}{\left(-4 + 1\right) \cdot U} + U \cdot \left(-4 \cdot U\right)} \]
      3. metadata-eval1.4%

        \[\leadsto \frac{U}{\color{blue}{-3} \cdot U + U \cdot \left(-4 \cdot U\right)} \]
      4. *-commutative1.4%

        \[\leadsto \frac{U}{\color{blue}{U \cdot -3} + U \cdot \left(-4 \cdot U\right)} \]
      5. distribute-lft-out1.4%

        \[\leadsto \frac{U}{\color{blue}{U \cdot \left(-3 + -4 \cdot U\right)}} \]
      6. associate-/r*1.4%

        \[\leadsto \color{blue}{\frac{\frac{U}{U}}{-3 + -4 \cdot U}} \]
      7. *-inverses1.4%

        \[\leadsto \frac{\color{blue}{1}}{-3 + -4 \cdot U} \]
      8. +-commutative1.4%

        \[\leadsto \frac{1}{\color{blue}{-4 \cdot U + -3}} \]
      9. *-commutative1.4%

        \[\leadsto \frac{1}{\color{blue}{U \cdot -4} + -3} \]
    5. Simplified1.4%

      \[\leadsto \color{blue}{\frac{1}{U \cdot -4 + -3}} \]
    6. Taylor expanded in U around -inf 50.5%

      \[\leadsto \color{blue}{-1 \cdot \frac{0.25 + -1 \cdot \frac{0.1875 + -1 \cdot \frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}}{U}}{U}} \]
    7. Step-by-step derivation
      1. mul-1-neg50.5%

        \[\leadsto \color{blue}{-\frac{0.25 + -1 \cdot \frac{0.1875 + -1 \cdot \frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}}{U}}{U}} \]
      2. distribute-neg-frac250.5%

        \[\leadsto \color{blue}{\frac{0.25 + -1 \cdot \frac{0.1875 + -1 \cdot \frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}}{U}}{-U}} \]
      3. mul-1-neg50.5%

        \[\leadsto \frac{0.25 + \color{blue}{\left(-\frac{0.1875 + -1 \cdot \frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}}{U}\right)}}{-U} \]
      4. unsub-neg50.5%

        \[\leadsto \frac{\color{blue}{0.25 - \frac{0.1875 + -1 \cdot \frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}}{U}}}{-U} \]
      5. mul-1-neg50.5%

        \[\leadsto \frac{0.25 - \frac{0.1875 + \color{blue}{\left(-\frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}\right)}}{U}}{-U} \]
      6. unsub-neg50.5%

        \[\leadsto \frac{0.25 - \frac{\color{blue}{0.1875 - \frac{0.140625 - 0.10546875 \cdot \frac{1}{U}}{U}}}{U}}{-U} \]
      7. associate-*r/50.5%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \color{blue}{\frac{0.10546875 \cdot 1}{U}}}{U}}{U}}{-U} \]
      8. metadata-eval50.5%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{\color{blue}{0.10546875}}{U}}{U}}{U}}{-U} \]
    8. Simplified50.5%

      \[\leadsto \color{blue}{\frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}}{-U}} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt36.7%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}}{\color{blue}{\sqrt{-U} \cdot \sqrt{-U}}} \]
      2. sqrt-unprod37.2%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}}{\color{blue}{\sqrt{\left(-U\right) \cdot \left(-U\right)}}} \]
      3. sqr-neg37.2%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}}{\sqrt{\color{blue}{U \cdot U}}} \]
      4. sqrt-unprod0.5%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}}{\color{blue}{\sqrt{U} \cdot \sqrt{U}}} \]
      5. add-sqr-sqrt14.6%

        \[\leadsto \frac{0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}}{\color{blue}{U}} \]
      6. div-inv14.6%

        \[\leadsto \color{blue}{\left(0.25 - \frac{0.1875 - \frac{0.140625 - \frac{0.10546875}{U}}{U}}{U}\right) \cdot \frac{1}{U}} \]
    10. Applied egg-rr50.6%

      \[\leadsto \color{blue}{\left(0.25 + \frac{-0.1875 + \frac{0.140625 + \frac{0.10546875}{U}}{U}}{U}\right) \cdot \frac{1}{U}} \]
    11. Step-by-step derivation
      1. associate-*r/50.6%

        \[\leadsto \color{blue}{\frac{\left(0.25 + \frac{-0.1875 + \frac{0.140625 + \frac{0.10546875}{U}}{U}}{U}\right) \cdot 1}{U}} \]
      2. *-rgt-identity50.6%

        \[\leadsto \frac{\color{blue}{0.25 + \frac{-0.1875 + \frac{0.140625 + \frac{0.10546875}{U}}{U}}{U}}}{U} \]
      3. +-commutative50.6%

        \[\leadsto \frac{0.25 + \frac{\color{blue}{\frac{0.140625 + \frac{0.10546875}{U}}{U} + -0.1875}}{U}}{U} \]
    12. Simplified50.6%

      \[\leadsto \color{blue}{\frac{0.25 + \frac{\frac{0.140625 + \frac{0.10546875}{U}}{U} + -0.1875}{U}}{U}} \]

    if 520 < 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-rr1.9%

      \[\leadsto \color{blue}{\frac{U}{U + \left(-4 \cdot U + U \cdot \left(-4 \cdot U\right)\right)}} \]
    4. Step-by-step derivation
      1. associate-+r+1.9%

        \[\leadsto \frac{U}{\color{blue}{\left(U + -4 \cdot U\right) + U \cdot \left(-4 \cdot U\right)}} \]
      2. distribute-rgt1-in1.9%

        \[\leadsto \frac{U}{\color{blue}{\left(-4 + 1\right) \cdot U} + U \cdot \left(-4 \cdot U\right)} \]
      3. metadata-eval1.9%

        \[\leadsto \frac{U}{\color{blue}{-3} \cdot U + U \cdot \left(-4 \cdot U\right)} \]
      4. *-commutative1.9%

        \[\leadsto \frac{U}{\color{blue}{U \cdot -3} + U \cdot \left(-4 \cdot U\right)} \]
      5. distribute-lft-out1.9%

        \[\leadsto \frac{U}{\color{blue}{U \cdot \left(-3 + -4 \cdot U\right)}} \]
      6. associate-/r*1.9%

        \[\leadsto \color{blue}{\frac{\frac{U}{U}}{-3 + -4 \cdot U}} \]
      7. *-inverses1.9%

        \[\leadsto \frac{\color{blue}{1}}{-3 + -4 \cdot U} \]
      8. +-commutative1.9%

        \[\leadsto \frac{1}{\color{blue}{-4 \cdot U + -3}} \]
      9. *-commutative1.9%

        \[\leadsto \frac{1}{\color{blue}{U \cdot -4} + -3} \]
    5. Simplified1.9%

      \[\leadsto \color{blue}{\frac{1}{U \cdot -4 + -3}} \]
    6. Taylor expanded in U around -inf 8.2%

      \[\leadsto \color{blue}{-1 \cdot \frac{0.25 + -1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}}{U}} \]
    7. Step-by-step derivation
      1. *-un-lft-identity8.2%

        \[\leadsto -1 \cdot \color{blue}{\left(1 \cdot \frac{0.25 + -1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}}{U}\right)} \]
      2. add-sqr-sqrt7.9%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \color{blue}{\sqrt{-1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}} \cdot \sqrt{-1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}}}}{U}\right) \]
      3. sqrt-unprod8.2%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \color{blue}{\sqrt{\left(-1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}\right) \cdot \left(-1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}\right)}}}{U}\right) \]
      4. mul-1-neg8.2%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \sqrt{\color{blue}{\left(-\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}\right)} \cdot \left(-1 \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}\right)}}{U}\right) \]
      5. mul-1-neg8.2%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \sqrt{\left(-\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}\right) \cdot \color{blue}{\left(-\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}\right)}}}{U}\right) \]
      6. sqr-neg8.2%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \sqrt{\color{blue}{\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U} \cdot \frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}}}}{U}\right) \]
      7. sqrt-unprod0.3%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \color{blue}{\sqrt{\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}} \cdot \sqrt{\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}}}}{U}\right) \]
      8. add-sqr-sqrt28.1%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \color{blue}{\frac{0.1875 - 0.140625 \cdot \frac{1}{U}}{U}}}{U}\right) \]
      9. cancel-sign-sub-inv28.1%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \frac{\color{blue}{0.1875 + \left(-0.140625\right) \cdot \frac{1}{U}}}{U}}{U}\right) \]
      10. un-div-inv28.1%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \frac{0.1875 + \color{blue}{\frac{-0.140625}{U}}}{U}}{U}\right) \]
      11. metadata-eval28.1%

        \[\leadsto -1 \cdot \left(1 \cdot \frac{0.25 + \frac{0.1875 + \frac{\color{blue}{-0.140625}}{U}}{U}}{U}\right) \]
    8. Applied egg-rr28.1%

      \[\leadsto -1 \cdot \color{blue}{\left(1 \cdot \frac{0.25 + \frac{0.1875 + \frac{-0.140625}{U}}{U}}{U}\right)} \]
    9. Step-by-step derivation
      1. *-lft-identity28.1%

        \[\leadsto -1 \cdot \color{blue}{\frac{0.25 + \frac{0.1875 + \frac{-0.140625}{U}}{U}}{U}} \]
    10. Simplified28.1%

      \[\leadsto -1 \cdot \color{blue}{\frac{0.25 + \frac{0.1875 + \frac{-0.140625}{U}}{U}}{U}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification61.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.8 \cdot 10^{+101}:\\ \;\;\;\;U + J \cdot \left(2 \cdot \ell\right)\\ \mathbf{elif}\;\ell \leq -9500000:\\ \;\;\;\;\frac{0.25 + \frac{\frac{0.140625 + \frac{0.10546875}{U}}{U} + -0.1875}{U}}{U}\\ \mathbf{elif}\;\ell \leq 520:\\ \;\;\;\;U + J \cdot \left(2 \cdot \ell\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25 + \frac{0.1875 + \frac{-0.140625}{U}}{U}}{-U}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 42.5% accurate, 20.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.7 \cdot 10^{+23} \lor \neg \left(\ell \leq 1220\right):\\
\;\;\;\;U \cdot \left(2 - U\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.7e23 or 1220 < l

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \color{blue}{U + \mathsf{fma}\left(-U, U, U\right)} \]
    6. Step-by-step derivation
      1. +-commutative15.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-U, U, U\right) + U} \]
      2. fma-undefine15.2%

        \[\leadsto \color{blue}{\left(\left(-U\right) \cdot U + U\right)} + U \]
      3. associate-+l+15.2%

        \[\leadsto \color{blue}{\left(-U\right) \cdot U + \left(U + U\right)} \]
      4. count-215.2%

        \[\leadsto \left(-U\right) \cdot U + \color{blue}{2 \cdot U} \]
      5. distribute-rgt-out15.2%

        \[\leadsto \color{blue}{U \cdot \left(\left(-U\right) + 2\right)} \]
    7. Simplified15.2%

      \[\leadsto \color{blue}{U \cdot \left(\left(-U\right) + 2\right)} \]
    8. Taylor expanded in U around 0 15.2%

      \[\leadsto \color{blue}{U \cdot \left(2 + -1 \cdot U\right)} \]
    9. Step-by-step derivation
      1. mul-1-neg15.2%

        \[\leadsto U \cdot \left(2 + \color{blue}{\left(-U\right)}\right) \]
      2. unsub-neg15.2%

        \[\leadsto U \cdot \color{blue}{\left(2 - U\right)} \]
    10. Simplified15.2%

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

    if -5.7e23 < l < 1220

    1. Initial program 76.0%

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

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

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

Alternative 12: 42.5% accurate, 20.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.0500000000000001e24 or 580 < l

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \color{blue}{-4 + \left(-U\right) \cdot U} \]
    6. Step-by-step derivation
      1. cancel-sign-sub-inv15.5%

        \[\leadsto \color{blue}{-4 - U \cdot U} \]
    7. Simplified15.5%

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

    if -1.0500000000000001e24 < l < 580

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

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

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

Alternative 13: 39.5% accurate, 38.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -3.3 \cdot 10^{+84}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U) :precision binary64 (if (<= l -3.3e+84) (* U U) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -3.3e+84) {
		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 <= (-3.3d+84)) 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 <= -3.3e+84) {
		tmp = U * U;
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -3.3e+84:
		tmp = U * U
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -3.3e+84)
		tmp = Float64(U * U);
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -3.3e+84)
		tmp = U * U;
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -3.3e+84], N[(U * U), $MachinePrecision], U]
\begin{array}{l}

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

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


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

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

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

    if -3.30000000000000017e84 < l

    1. Initial program 84.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 48.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.3 \cdot 10^{+84}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 54.8% accurate, 44.6× speedup?

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

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

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

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

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

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

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

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

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

Alternative 15: 2.8% accurate, 312.0× speedup?

\[\begin{array}{l} \\ -0.3333333333333333 \end{array} \]
(FPCore (J l K U) :precision binary64 -0.3333333333333333)
double code(double J, double l, double K, double U) {
	return -0.3333333333333333;
}
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 = -0.3333333333333333d0
end function
public static double code(double J, double l, double K, double U) {
	return -0.3333333333333333;
}
def code(J, l, K, U):
	return -0.3333333333333333
function code(J, l, K, U)
	return -0.3333333333333333
end
function tmp = code(J, l, K, U)
	tmp = -0.3333333333333333;
end
code[J_, l_, K_, U_] := -0.3333333333333333
\begin{array}{l}

\\
-0.3333333333333333
\end{array}
Derivation
  1. Initial program 87.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-rr2.4%

    \[\leadsto \color{blue}{\frac{U}{U + \left(-4 \cdot U + U \cdot \left(-4 \cdot U\right)\right)}} \]
  4. Step-by-step derivation
    1. associate-+r+2.4%

      \[\leadsto \frac{U}{\color{blue}{\left(U + -4 \cdot U\right) + U \cdot \left(-4 \cdot U\right)}} \]
    2. distribute-rgt1-in2.4%

      \[\leadsto \frac{U}{\color{blue}{\left(-4 + 1\right) \cdot U} + U \cdot \left(-4 \cdot U\right)} \]
    3. metadata-eval2.4%

      \[\leadsto \frac{U}{\color{blue}{-3} \cdot U + U \cdot \left(-4 \cdot U\right)} \]
    4. *-commutative2.4%

      \[\leadsto \frac{U}{\color{blue}{U \cdot -3} + U \cdot \left(-4 \cdot U\right)} \]
    5. distribute-lft-out2.4%

      \[\leadsto \frac{U}{\color{blue}{U \cdot \left(-3 + -4 \cdot U\right)}} \]
    6. associate-/r*2.3%

      \[\leadsto \color{blue}{\frac{\frac{U}{U}}{-3 + -4 \cdot U}} \]
    7. *-inverses2.3%

      \[\leadsto \frac{\color{blue}{1}}{-3 + -4 \cdot U} \]
    8. +-commutative2.3%

      \[\leadsto \frac{1}{\color{blue}{-4 \cdot U + -3}} \]
    9. *-commutative2.3%

      \[\leadsto \frac{1}{\color{blue}{U \cdot -4} + -3} \]
  5. Simplified2.3%

    \[\leadsto \color{blue}{\frac{1}{U \cdot -4 + -3}} \]
  6. Taylor expanded in U around 0 2.9%

    \[\leadsto \color{blue}{-0.3333333333333333} \]
  7. Final simplification2.9%

    \[\leadsto -0.3333333333333333 \]
  8. Add Preprocessing

Alternative 16: 37.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.0%

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

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

    \[\leadsto U \]
  5. Add Preprocessing

Reproduce

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