Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 85.4% → 99.7%
Time: 9.8s
Alternatives: 14
Speedup: 2.7×

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 14 alternatives:

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

Initial Program: 85.4% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{-\ell}\\ t_2 := e^{\ell} - t\_1\\ \mathbf{if}\;t\_2 \leq -\infty:\\ \;\;\;\;\left(J \cdot \left(27 - t\_1\right)\right) \cdot t\_0 + U\\ \mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-8}:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + t\_0 \cdot \left(t\_2 \cdot J\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (exp (- l))) (t_2 (- (exp l) t_1)))
   (if (<= t_2 (- INFINITY))
     (+ (* (* J (- 27.0 t_1)) t_0) U)
     (if (<= t_2 5e-8)
       (+ U (* t_0 (* J (* l 2.0))))
       (+ U (* t_0 (* t_2 J)))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = exp(-l);
	double t_2 = exp(l) - t_1;
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = ((J * (27.0 - t_1)) * t_0) + U;
	} else if (t_2 <= 5e-8) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else {
		tmp = U + (t_0 * (t_2 * J));
	}
	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);
	double t_2 = Math.exp(l) - t_1;
	double tmp;
	if (t_2 <= -Double.POSITIVE_INFINITY) {
		tmp = ((J * (27.0 - t_1)) * t_0) + U;
	} else if (t_2 <= 5e-8) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else {
		tmp = U + (t_0 * (t_2 * J));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = math.exp(-l)
	t_2 = math.exp(l) - t_1
	tmp = 0
	if t_2 <= -math.inf:
		tmp = ((J * (27.0 - t_1)) * t_0) + U
	elif t_2 <= 5e-8:
		tmp = U + (t_0 * (J * (l * 2.0)))
	else:
		tmp = U + (t_0 * (t_2 * J))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = exp(Float64(-l))
	t_2 = Float64(exp(l) - t_1)
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = Float64(Float64(Float64(J * Float64(27.0 - t_1)) * t_0) + U);
	elseif (t_2 <= 5e-8)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0))));
	else
		tmp = Float64(U + Float64(t_0 * Float64(t_2 * J)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = exp(-l);
	t_2 = exp(l) - t_1;
	tmp = 0.0;
	if (t_2 <= -Inf)
		tmp = ((J * (27.0 - t_1)) * t_0) + U;
	elseif (t_2 <= 5e-8)
		tmp = U + (t_0 * (J * (l * 2.0)));
	else
		tmp = U + (t_0 * (t_2 * J));
	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[Exp[(-l)], $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[l], $MachinePrecision] - t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(N[(N[(J * N[(27.0 - t$95$1), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[t$95$2, 5e-8], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(t$95$0 * N[(t$95$2 * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

\mathbf{else}:\\
\;\;\;\;U + t\_0 \cdot \left(t\_2 \cdot J\right)\\


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

    1. Initial program 100.0%

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

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 4.9999999999999998e-8

    1. Initial program 68.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.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. *-commutative99.9%

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

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

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

    if 4.9999999999999998e-8 < (-.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. Recombined 3 regimes into one program.
  4. Final simplification99.9%

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

Alternative 2: 97.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;\ell \leq -225:\\ \;\;\;\;\left(J \cdot \left(27 - e^{-\ell}\right)\right) \cdot t\_0 + U\\ \mathbf{elif}\;\ell \leq 450:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 6.6 \cdot 10^{+101}:\\ \;\;\;\;U + J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= l -225.0)
     (+ (* (* J (- 27.0 (exp (- l)))) t_0) U)
     (if (<= l 450.0)
       (+ U (* t_0 (* J (* l 2.0))))
       (if (<= l 6.6e+101)
         (+ U (* J (log1p (expm1 (* l 2.0)))))
         (+ U (* t_0 (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l))))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (l <= -225.0) {
		tmp = ((J * (27.0 - exp(-l))) * t_0) + U;
	} else if (l <= 450.0) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else if (l <= 6.6e+101) {
		tmp = U + (J * log1p(expm1((l * 2.0))));
	} else {
		tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (l <= -225.0) {
		tmp = ((J * (27.0 - Math.exp(-l))) * t_0) + U;
	} else if (l <= 450.0) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else if (l <= 6.6e+101) {
		tmp = U + (J * Math.log1p(Math.expm1((l * 2.0))));
	} else {
		tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if l <= -225.0:
		tmp = ((J * (27.0 - math.exp(-l))) * t_0) + U
	elif l <= 450.0:
		tmp = U + (t_0 * (J * (l * 2.0)))
	elif l <= 6.6e+101:
		tmp = U + (J * math.log1p(math.expm1((l * 2.0))))
	else:
		tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (l <= -225.0)
		tmp = Float64(Float64(Float64(J * Float64(27.0 - exp(Float64(-l)))) * t_0) + U);
	elseif (l <= 450.0)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0))));
	elseif (l <= 6.6e+101)
		tmp = Float64(U + Float64(J * log1p(expm1(Float64(l * 2.0)))));
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -225.0], N[(N[(N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[l, 450.0], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 6.6e+101], N[(U + N[(J * N[Log[1 + N[(Exp[N[(l * 2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\ell \leq 6.6 \cdot 10^{+101}:\\
\;\;\;\;U + J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)\\

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


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

    1. Initial program 100.0%

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

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

    if -225 < l < 450

    1. Initial program 68.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.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. *-commutative99.9%

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

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

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

    if 450 < l < 6.60000000000000022e101

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\ell \cdot 2}\right)\right) + U \]
    10. Applied egg-rr92.0%

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

    if 6.60000000000000022e101 < l

    1. Initial program 100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -225:\\ \;\;\;\;\left(J \cdot \left(27 - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{elif}\;\ell \leq 450:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 6.6 \cdot 10^{+101}:\\ \;\;\;\;U + J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 80.4% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 79.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 66.4%

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

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

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

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

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

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

      \[\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-/l*73.6%

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

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

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

    1. Initial program 90.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 84.3%

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Applied egg-rr84.1%

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

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

Alternative 4: 76.7% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 79.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 66.4%

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

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

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

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

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

    1. Initial program 90.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 84.3%

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Applied egg-rr84.1%

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

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

Alternative 5: 87.2% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-20}:\\ \;\;\;\;U + J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (/ K 2.0) 5e-20)
   (+ U (* J (log1p (expm1 (* l 2.0)))))
   (+
    U
    (* (cos (/ K 2.0)) (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l)))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 5e-20) {
		tmp = U + (J * log1p(expm1((l * 2.0))));
	} else {
		tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 5e-20) {
		tmp = U + (J * Math.log1p(Math.expm1((l * 2.0))));
	} else {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (K / 2.0) <= 5e-20:
		tmp = U + (J * math.log1p(math.expm1((l * 2.0))))
	else:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (Float64(K / 2.0) <= 5e-20)
		tmp = Float64(U + Float64(J * log1p(expm1(Float64(l * 2.0)))));
	else
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[(K / 2.0), $MachinePrecision], 5e-20], N[(U + N[(J * N[Log[1 + N[(Exp[N[(l * 2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-20}:\\
\;\;\;\;U + J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)\\

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


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

    1. Initial program 85.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\ell \cdot 2}\right)\right) + U \]
    10. Applied egg-rr83.7%

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

    if 4.9999999999999999e-20 < (/.f64 K #s(literal 2 binary64))

    1. Initial program 84.8%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 83.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. Step-by-step derivation
      1. unpow283.1%

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

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

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

Alternative 6: 78.6% accurate, 2.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;U \leq -2.05 \cdot 10^{-81} \lor \neg \left(U \leq 5800000\right):\\
\;\;\;\;U + \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right) \cdot \cos \left(K \cdot -4\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < -2.04999999999999992e-81 or 5.8e6 < U

    1. Initial program 97.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 90.0%

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

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

      \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Applied egg-rr83.1%

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right) \cdot \cos \color{blue}{\left(K \cdot -4\right)} + U \]
    8. Simplified83.1%

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

    if -2.04999999999999992e-81 < U < 5.8e6

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

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

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

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)\right)} + U \]
    6. Taylor expanded in U around inf 74.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-/l*80.2%

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

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

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

Alternative 7: 88.4% accurate, 2.7× speedup?

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

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

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

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

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

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

Alternative 8: 74.6% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;K \leq 98000000000:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 9.8e10

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

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

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

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

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

    if 9.8e10 < K

    1. Initial program 83.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 81.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 74.6% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;K \leq 18000000000:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 1.8e10

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

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

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

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

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

    if 1.8e10 < K

    1. Initial program 83.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 56.3%

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

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

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

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

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

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

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

Alternative 10: 71.8% accurate, 24.0× speedup?

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

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

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

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

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

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

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

Alternative 11: 60.3% accurate, 28.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\ell \cdot 2}\right)\right) + U \]
  10. Applied egg-rr78.1%

    \[\leadsto J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)} + U \]
  11. Taylor expanded in U around inf 54.8%

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

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

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

Alternative 12: 53.9% 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 85.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.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{-4} + U \]
  4. Taylor expanded in U around inf 32.5%

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

Alternative 14: 2.8% accurate, 312.0× speedup?

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

\\
-4
\end{array}
Derivation
  1. Initial program 85.5%

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

    \[\leadsto \color{blue}{-4} + U \]
  4. Taylor expanded in U around 0 2.8%

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

Reproduce

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