Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.5% → 99.9%
Time: 11.6s
Alternatives: 16
Speedup: 2.5×

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

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

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

Alternative 1: 99.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t\_0 \leq -0.05 \lor \neg \left(t\_0 \leq 0.005\right):\\ \;\;\;\;J \cdot \left(t\_0 \cdot \cos \left(0.5 \cdot K\right)\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot 0.016666666666666666\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))))
   (if (or (<= t_0 -0.05) (not (<= t_0 0.005)))
     (+ (* J (* t_0 (cos (* 0.5 K)))) U)
     (+
      U
      (*
       (*
        J
        (*
         l
         (+
          2.0
          (*
           (* l l)
           (+ 0.3333333333333333 (* (* l l) 0.016666666666666666))))))
       (cos (/ K 2.0)))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -0.05) || !(t_0 <= 0.005)) {
		tmp = (J * (t_0 * cos((0.5 * K)))) + U;
	} else {
		tmp = U + ((J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * 0.016666666666666666)))))) * cos((K / 2.0)));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = exp(l) - exp(-l)
    if ((t_0 <= (-0.05d0)) .or. (.not. (t_0 <= 0.005d0))) then
        tmp = (j * (t_0 * cos((0.5d0 * k)))) + u
    else
        tmp = u + ((j * (l * (2.0d0 + ((l * l) * (0.3333333333333333d0 + ((l * l) * 0.016666666666666666d0)))))) * cos((k / 2.0d0)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_0 <= -0.05) || !(t_0 <= 0.005)) {
		tmp = (J * (t_0 * Math.cos((0.5 * K)))) + U;
	} else {
		tmp = U + ((J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * 0.016666666666666666)))))) * Math.cos((K / 2.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_0 <= -0.05) or not (t_0 <= 0.005):
		tmp = (J * (t_0 * math.cos((0.5 * K)))) + U
	else:
		tmp = U + ((J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * 0.016666666666666666)))))) * math.cos((K / 2.0)))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= -0.05) || !(t_0 <= 0.005))
		tmp = Float64(Float64(J * Float64(t_0 * cos(Float64(0.5 * K)))) + U);
	else
		tmp = Float64(U + Float64(Float64(J * Float64(l * Float64(2.0 + Float64(Float64(l * l) * Float64(0.3333333333333333 + Float64(Float64(l * l) * 0.016666666666666666)))))) * cos(Float64(K / 2.0))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_0 <= -0.05) || ~((t_0 <= 0.005)))
		tmp = (J * (t_0 * cos((0.5 * K)))) + U;
	else
		tmp = U + ((J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * 0.016666666666666666)))))) * cos((K / 2.0)));
	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, -0.05], N[Not[LessEqual[t$95$0, 0.005]], $MachinePrecision]], N[(N[(J * N[(t$95$0 * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(N[(J * N[(l * N[(2.0 + N[(N[(l * l), $MachinePrecision] * N[(0.3333333333333333 + N[(N[(l * l), $MachinePrecision] * 0.016666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -0.050000000000000003 or 0.0050000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

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

    if -0.050000000000000003 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.0050000000000000001

    1. Initial program 69.7%

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

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

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

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

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

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

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

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

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

Alternative 2: 96.5% accurate, 0.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 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)))

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

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

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + \color{blue}{\left(\ell \cdot \ell\right)} \cdot 0.016666666666666666\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    7. Applied egg-rr92.4%

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

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

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

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

Alternative 3: 91.6% accurate, 2.2× 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(26 + \ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right)\right)\right)\\ \mathbf{if}\;\ell \leq -1.95 \cdot 10^{+138}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -5.2:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 4.2 \cdot 10^{-58}:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+101}:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot 0.016666666666666666\right)\right)\right)\right) \cdot \cos \left(K \cdot -4\right)\\ \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
            (+ 26.0 (* l (+ 1.0 (* l (- (* l 0.16666666666666666) 0.5))))))))))
   (if (<= l -1.95e+138)
     t_1
     (if (<= l -5.2)
       (+ U (* J (- 27.0 (exp (- l)))))
       (if (<= l 4.2e-58)
         (+ U (* t_0 (* J (* l 2.0))))
         (if (<= l 5.6e+101)
           (+
            U
            (*
             (*
              J
              (*
               l
               (+
                2.0
                (*
                 (* l l)
                 (+ 0.3333333333333333 (* (* l l) 0.016666666666666666))))))
             (cos (* K -4.0))))
           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 * (26.0 + (l * (1.0 + (l * ((l * 0.16666666666666666) - 0.5)))))));
	double tmp;
	if (l <= -1.95e+138) {
		tmp = t_1;
	} else if (l <= -5.2) {
		tmp = U + (J * (27.0 - exp(-l)));
	} else if (l <= 4.2e-58) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else if (l <= 5.6e+101) {
		tmp = U + ((J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * 0.016666666666666666)))))) * cos((K * -4.0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    t_1 = u + (t_0 * (j * (26.0d0 + (l * (1.0d0 + (l * ((l * 0.16666666666666666d0) - 0.5d0)))))))
    if (l <= (-1.95d+138)) then
        tmp = t_1
    else if (l <= (-5.2d0)) then
        tmp = u + (j * (27.0d0 - exp(-l)))
    else if (l <= 4.2d-58) then
        tmp = u + (t_0 * (j * (l * 2.0d0)))
    else if (l <= 5.6d+101) then
        tmp = u + ((j * (l * (2.0d0 + ((l * l) * (0.3333333333333333d0 + ((l * l) * 0.016666666666666666d0)))))) * cos((k * (-4.0d0))))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = U + (t_0 * (J * (26.0 + (l * (1.0 + (l * ((l * 0.16666666666666666) - 0.5)))))));
	double tmp;
	if (l <= -1.95e+138) {
		tmp = t_1;
	} else if (l <= -5.2) {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	} else if (l <= 4.2e-58) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else if (l <= 5.6e+101) {
		tmp = U + ((J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * 0.016666666666666666)))))) * Math.cos((K * -4.0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = U + (t_0 * (J * (26.0 + (l * (1.0 + (l * ((l * 0.16666666666666666) - 0.5)))))))
	tmp = 0
	if l <= -1.95e+138:
		tmp = t_1
	elif l <= -5.2:
		tmp = U + (J * (27.0 - math.exp(-l)))
	elif l <= 4.2e-58:
		tmp = U + (t_0 * (J * (l * 2.0)))
	elif l <= 5.6e+101:
		tmp = U + ((J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * 0.016666666666666666)))))) * math.cos((K * -4.0)))
	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(26.0 + Float64(l * Float64(1.0 + Float64(l * Float64(Float64(l * 0.16666666666666666) - 0.5))))))))
	tmp = 0.0
	if (l <= -1.95e+138)
		tmp = t_1;
	elseif (l <= -5.2)
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	elseif (l <= 4.2e-58)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0))));
	elseif (l <= 5.6e+101)
		tmp = Float64(U + Float64(Float64(J * Float64(l * Float64(2.0 + Float64(Float64(l * l) * Float64(0.3333333333333333 + Float64(Float64(l * l) * 0.016666666666666666)))))) * cos(Float64(K * -4.0))));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = U + (t_0 * (J * (26.0 + (l * (1.0 + (l * ((l * 0.16666666666666666) - 0.5)))))));
	tmp = 0.0;
	if (l <= -1.95e+138)
		tmp = t_1;
	elseif (l <= -5.2)
		tmp = U + (J * (27.0 - exp(-l)));
	elseif (l <= 4.2e-58)
		tmp = U + (t_0 * (J * (l * 2.0)));
	elseif (l <= 5.6e+101)
		tmp = U + ((J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * 0.016666666666666666)))))) * cos((K * -4.0)));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(t$95$0 * N[(J * N[(26.0 + N[(l * N[(1.0 + N[(l * N[(N[(l * 0.16666666666666666), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.95e+138], t$95$1, If[LessEqual[l, -5.2], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 4.2e-58], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.6e+101], N[(U + N[(N[(J * N[(l * N[(2.0 + N[(N[(l * l), $MachinePrecision] * N[(0.3333333333333333 + N[(N[(l * l), $MachinePrecision] * 0.016666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := U + t\_0 \cdot \left(J \cdot \left(26 + \ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right)\right)\right)\\
\mathbf{if}\;\ell \leq -1.95 \cdot 10^{+138}:\\
\;\;\;\;t\_1\\

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

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

\mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+101}:\\
\;\;\;\;U + \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot 0.016666666666666666\right)\right)\right)\right) \cdot \cos \left(K \cdot -4\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.9499999999999999e138 or 5.59999999999999962e101 < 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-rr56.0%

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

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

    if -1.9499999999999999e138 < l < -5.20000000000000018

    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 \]
    4. Taylor expanded in K around 0 78.1%

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

    if -5.20000000000000018 < l < 4.19999999999999975e-58

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

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

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

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

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

    if 4.19999999999999975e-58 < l < 5.59999999999999962e101

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.95 \cdot 10^{+138}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(26 + \ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -5.2:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 4.2 \cdot 10^{-58}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+101}:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot 0.016666666666666666\right)\right)\right)\right) \cdot \cos \left(K \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(26 + \ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 90.9% accurate, 2.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(26 + \ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right)\right)\right)\\ \mathbf{if}\;\ell \leq -1.95 \cdot 10^{+138}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -5.8:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 2.5:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \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
            (+ 26.0 (* l (+ 1.0 (* l (- (* l 0.16666666666666666) 0.5))))))))))
   (if (<= l -1.95e+138)
     t_1
     (if (<= l -5.8)
       (+ U (* J (- 27.0 (exp (- l)))))
       (if (<= l 2.5) (+ U (* t_0 (* J (* l 2.0)))) 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 * (26.0 + (l * (1.0 + (l * ((l * 0.16666666666666666) - 0.5)))))));
	double tmp;
	if (l <= -1.95e+138) {
		tmp = t_1;
	} else if (l <= -5.8) {
		tmp = U + (J * (27.0 - exp(-l)));
	} else if (l <= 2.5) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    t_1 = u + (t_0 * (j * (26.0d0 + (l * (1.0d0 + (l * ((l * 0.16666666666666666d0) - 0.5d0)))))))
    if (l <= (-1.95d+138)) then
        tmp = t_1
    else if (l <= (-5.8d0)) then
        tmp = u + (j * (27.0d0 - exp(-l)))
    else if (l <= 2.5d0) then
        tmp = u + (t_0 * (j * (l * 2.0d0)))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = U + (t_0 * (J * (26.0 + (l * (1.0 + (l * ((l * 0.16666666666666666) - 0.5)))))));
	double tmp;
	if (l <= -1.95e+138) {
		tmp = t_1;
	} else if (l <= -5.8) {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	} else if (l <= 2.5) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = U + (t_0 * (J * (26.0 + (l * (1.0 + (l * ((l * 0.16666666666666666) - 0.5)))))))
	tmp = 0
	if l <= -1.95e+138:
		tmp = t_1
	elif l <= -5.8:
		tmp = U + (J * (27.0 - math.exp(-l)))
	elif l <= 2.5:
		tmp = U + (t_0 * (J * (l * 2.0)))
	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(26.0 + Float64(l * Float64(1.0 + Float64(l * Float64(Float64(l * 0.16666666666666666) - 0.5))))))))
	tmp = 0.0
	if (l <= -1.95e+138)
		tmp = t_1;
	elseif (l <= -5.8)
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	elseif (l <= 2.5)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0))));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = U + (t_0 * (J * (26.0 + (l * (1.0 + (l * ((l * 0.16666666666666666) - 0.5)))))));
	tmp = 0.0;
	if (l <= -1.95e+138)
		tmp = t_1;
	elseif (l <= -5.8)
		tmp = U + (J * (27.0 - exp(-l)));
	elseif (l <= 2.5)
		tmp = U + (t_0 * (J * (l * 2.0)));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(t$95$0 * N[(J * N[(26.0 + N[(l * N[(1.0 + N[(l * N[(N[(l * 0.16666666666666666), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.95e+138], t$95$1, If[LessEqual[l, -5.8], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.5], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := U + t\_0 \cdot \left(J \cdot \left(26 + \ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right)\right)\right)\\
\mathbf{if}\;\ell \leq -1.95 \cdot 10^{+138}:\\
\;\;\;\;t\_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.9499999999999999e138 or 2.5 < 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-rr43.5%

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

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

    if -1.9499999999999999e138 < l < -5.79999999999999982

    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 \]
    4. Taylor expanded in K around 0 78.1%

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

    if -5.79999999999999982 < l < 2.5

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.95 \cdot 10^{+138}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(26 + \ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -5.8:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 2.5:\\ \;\;\;\;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(J \cdot \left(26 + \ell \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.16666666666666666 - 0.5\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 76.6% accurate, 2.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.8:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

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

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

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


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

    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 \]
    4. Taylor expanded in K around 0 76.0%

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

    if -5.79999999999999982 < l < 1e3

    1. Initial program 70.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 96.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. *-commutative96.9%

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

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

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

    if 1e3 < l < 1.25000000000000006e244

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

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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot 0.016666666666666666\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around 0 12.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. *-commutative12.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*12.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*12.3%

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

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

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

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

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

    if 1.25000000000000006e244 < 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 70.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. *-commutative70.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*70.6%

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

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

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

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

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

Alternative 6: 75.0% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -5.8:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 250 \lor \neg \left(\ell \leq 1.85 \cdot 10^{+202}\right):\\ \;\;\;\;U + J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(-0.25 \cdot {K}^{2}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -5.8)
   (+ U (* J (- 27.0 (exp (- l)))))
   (if (or (<= l 250.0) (not (<= l 1.85e+202)))
     (+ U (* J (* (cos (* 0.5 K)) (* l 2.0))))
     (+ U (* (* l J) (* -0.25 (pow K 2.0)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -5.8) {
		tmp = U + (J * (27.0 - exp(-l)));
	} else if ((l <= 250.0) || !(l <= 1.85e+202)) {
		tmp = U + (J * (cos((0.5 * K)) * (l * 2.0)));
	} else {
		tmp = U + ((l * J) * (-0.25 * pow(K, 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 (l <= (-5.8d0)) then
        tmp = u + (j * (27.0d0 - exp(-l)))
    else if ((l <= 250.0d0) .or. (.not. (l <= 1.85d+202))) then
        tmp = u + (j * (cos((0.5d0 * k)) * (l * 2.0d0)))
    else
        tmp = u + ((l * j) * ((-0.25d0) * (k ** 2.0d0)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -5.8) {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	} else if ((l <= 250.0) || !(l <= 1.85e+202)) {
		tmp = U + (J * (Math.cos((0.5 * K)) * (l * 2.0)));
	} else {
		tmp = U + ((l * J) * (-0.25 * Math.pow(K, 2.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -5.8:
		tmp = U + (J * (27.0 - math.exp(-l)))
	elif (l <= 250.0) or not (l <= 1.85e+202):
		tmp = U + (J * (math.cos((0.5 * K)) * (l * 2.0)))
	else:
		tmp = U + ((l * J) * (-0.25 * math.pow(K, 2.0)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -5.8)
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	elseif ((l <= 250.0) || !(l <= 1.85e+202))
		tmp = Float64(U + Float64(J * Float64(cos(Float64(0.5 * K)) * Float64(l * 2.0))));
	else
		tmp = Float64(U + Float64(Float64(l * J) * Float64(-0.25 * (K ^ 2.0))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -5.8)
		tmp = U + (J * (27.0 - exp(-l)));
	elseif ((l <= 250.0) || ~((l <= 1.85e+202)))
		tmp = U + (J * (cos((0.5 * K)) * (l * 2.0)));
	else
		tmp = U + ((l * J) * (-0.25 * (K ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -5.8], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, 250.0], N[Not[LessEqual[l, 1.85e+202]], $MachinePrecision]], N[(U + N[(J * N[(N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(l * J), $MachinePrecision] * N[(-0.25 * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.8:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

\mathbf{elif}\;\ell \leq 250 \lor \neg \left(\ell \leq 1.85 \cdot 10^{+202}\right):\\
\;\;\;\;U + J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(\ell \cdot 2\right)\right)\\

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


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

    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 \]
    4. Taylor expanded in K around 0 76.0%

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

    if -5.79999999999999982 < l < 250 or 1.8499999999999999e202 < l

    1. Initial program 74.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 92.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. *-commutative92.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*92.4%

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

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

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

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

    if 250 < l < 1.8499999999999999e202

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 75.1% accurate, 2.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.5:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

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

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

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


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

    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 \]
    4. Taylor expanded in K around 0 76.0%

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

    if -4.5 < l < 300

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

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

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

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

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

    if 300 < l < 4.59999999999999989e199

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.59999999999999989e199 < 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 57.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. *-commutative57.9%

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

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

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

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

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

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

Alternative 8: 66.9% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -3.5:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 0.31 \lor \neg \left(\ell \leq 2.2 \cdot 10^{+247}\right):\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(-0.25 \cdot {K}^{2}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -3.5)
   (+ U (* J (- 27.0 (exp (- l)))))
   (if (or (<= l 0.31) (not (<= l 2.2e+247)))
     (+ U (* l (* J 2.0)))
     (+ U (* (* l J) (* -0.25 (pow K 2.0)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -3.5) {
		tmp = U + (J * (27.0 - exp(-l)));
	} else if ((l <= 0.31) || !(l <= 2.2e+247)) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = U + ((l * J) * (-0.25 * pow(K, 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 (l <= (-3.5d0)) then
        tmp = u + (j * (27.0d0 - exp(-l)))
    else if ((l <= 0.31d0) .or. (.not. (l <= 2.2d+247))) then
        tmp = u + (l * (j * 2.0d0))
    else
        tmp = u + ((l * j) * ((-0.25d0) * (k ** 2.0d0)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -3.5) {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	} else if ((l <= 0.31) || !(l <= 2.2e+247)) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = U + ((l * J) * (-0.25 * Math.pow(K, 2.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -3.5:
		tmp = U + (J * (27.0 - math.exp(-l)))
	elif (l <= 0.31) or not (l <= 2.2e+247):
		tmp = U + (l * (J * 2.0))
	else:
		tmp = U + ((l * J) * (-0.25 * math.pow(K, 2.0)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -3.5)
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	elseif ((l <= 0.31) || !(l <= 2.2e+247))
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	else
		tmp = Float64(U + Float64(Float64(l * J) * Float64(-0.25 * (K ^ 2.0))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -3.5)
		tmp = U + (J * (27.0 - exp(-l)));
	elseif ((l <= 0.31) || ~((l <= 2.2e+247)))
		tmp = U + (l * (J * 2.0));
	else
		tmp = U + ((l * J) * (-0.25 * (K ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -3.5], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, 0.31], N[Not[LessEqual[l, 2.2e+247]], $MachinePrecision]], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(l * J), $MachinePrecision] * N[(-0.25 * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.5:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

\mathbf{elif}\;\ell \leq 0.31 \lor \neg \left(\ell \leq 2.2 \cdot 10^{+247}\right):\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\

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


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

    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 \]
    4. Taylor expanded in K around 0 76.0%

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

    if -3.5 < l < 0.309999999999999998 or 2.20000000000000011e247 < l

    1. Initial program 72.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 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.309999999999999998 < l < 2.20000000000000011e247

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.5:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 0.31 \lor \neg \left(\ell \leq 2.2 \cdot 10^{+247}\right):\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(-0.25 \cdot {K}^{2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 77.8% accurate, 2.5× speedup?

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

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

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

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


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

    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 \]
    4. Taylor expanded in K around 0 76.0%

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

    if -10 < l < 5e15

    1. Initial program 71.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 95.3%

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

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

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

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

    if 5e15 < l

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\ell \cdot \left(\left(2 \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    9. Taylor expanded in U around inf 39.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)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification76.5%

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

Alternative 10: 93.2% accurate, 2.5× speedup?

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

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

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

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

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

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

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

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

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

Alternative 11: 68.0% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -3.5:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 0.31 \lor \neg \left(\ell \leq 7.3 \cdot 10^{+244}\right):\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(-0.25 \cdot \left(J \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right) + 2 \cdot \left(\ell \cdot J\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -3.5)
   (+ U (* J (- 27.0 (exp (- l)))))
   (if (or (<= l 0.31) (not (<= l 7.3e+244)))
     (+ U (* l (* J 2.0)))
     (+ U (+ (* -0.25 (* J (* l (* K K)))) (* 2.0 (* l J)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -3.5) {
		tmp = U + (J * (27.0 - exp(-l)));
	} else if ((l <= 0.31) || !(l <= 7.3e+244)) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)));
	}
	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.5d0)) then
        tmp = u + (j * (27.0d0 - exp(-l)))
    else if ((l <= 0.31d0) .or. (.not. (l <= 7.3d+244))) then
        tmp = u + (l * (j * 2.0d0))
    else
        tmp = u + (((-0.25d0) * (j * (l * (k * k)))) + (2.0d0 * (l * j)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -3.5) {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	} else if ((l <= 0.31) || !(l <= 7.3e+244)) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -3.5:
		tmp = U + (J * (27.0 - math.exp(-l)))
	elif (l <= 0.31) or not (l <= 7.3e+244):
		tmp = U + (l * (J * 2.0))
	else:
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -3.5)
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	elseif ((l <= 0.31) || !(l <= 7.3e+244))
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	else
		tmp = Float64(U + Float64(Float64(-0.25 * Float64(J * Float64(l * Float64(K * K)))) + Float64(2.0 * Float64(l * J))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -3.5)
		tmp = U + (J * (27.0 - exp(-l)));
	elseif ((l <= 0.31) || ~((l <= 7.3e+244)))
		tmp = U + (l * (J * 2.0));
	else
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -3.5], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, 0.31], N[Not[LessEqual[l, 7.3e+244]], $MachinePrecision]], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(-0.25 * N[(J * N[(l * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.5:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

\mathbf{elif}\;\ell \leq 0.31 \lor \neg \left(\ell \leq 7.3 \cdot 10^{+244}\right):\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\

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


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

    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 \]
    4. Taylor expanded in K around 0 76.0%

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

    if -3.5 < l < 0.309999999999999998 or 7.29999999999999956e244 < l

    1. Initial program 73.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.309999999999999998 < l < 7.29999999999999956e244

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-0.25 \cdot \left(J \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot \ell\right)\right) + 2 \cdot \left(J \cdot \ell\right)\right) + U \]
    11. Applied egg-rr28.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.5:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 0.31 \lor \neg \left(\ell \leq 7.3 \cdot 10^{+244}\right):\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(-0.25 \cdot \left(J \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right) + 2 \cdot \left(\ell \cdot J\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 56.7% accurate, 8.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1.25 \cdot 10^{+281} \lor \neg \left(\ell \leq -1120000\right) \land \left(\ell \leq 0.31 \lor \neg \left(\ell \leq 1.02 \cdot 10^{+244}\right)\right):\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(-0.25 \cdot \left(J \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right) + 2 \cdot \left(\ell \cdot J\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -1.25e+281)
         (and (not (<= l -1120000.0)) (or (<= l 0.31) (not (<= l 1.02e+244)))))
   (+ U (* l (* J 2.0)))
   (+ U (+ (* -0.25 (* J (* l (* K K)))) (* 2.0 (* l J))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -1.25e+281) || (!(l <= -1120000.0) && ((l <= 0.31) || !(l <= 1.02e+244)))) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)));
	}
	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.25d+281)) .or. (.not. (l <= (-1120000.0d0))) .and. (l <= 0.31d0) .or. (.not. (l <= 1.02d+244))) then
        tmp = u + (l * (j * 2.0d0))
    else
        tmp = u + (((-0.25d0) * (j * (l * (k * k)))) + (2.0d0 * (l * j)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -1.25e+281) || (!(l <= -1120000.0) && ((l <= 0.31) || !(l <= 1.02e+244)))) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -1.25e+281) or (not (l <= -1120000.0) and ((l <= 0.31) or not (l <= 1.02e+244))):
		tmp = U + (l * (J * 2.0))
	else:
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -1.25e+281) || (!(l <= -1120000.0) && ((l <= 0.31) || !(l <= 1.02e+244))))
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	else
		tmp = Float64(U + Float64(Float64(-0.25 * Float64(J * Float64(l * Float64(K * K)))) + Float64(2.0 * Float64(l * J))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -1.25e+281) || (~((l <= -1120000.0)) && ((l <= 0.31) || ~((l <= 1.02e+244)))))
		tmp = U + (l * (J * 2.0));
	else
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -1.25e+281], And[N[Not[LessEqual[l, -1120000.0]], $MachinePrecision], Or[LessEqual[l, 0.31], N[Not[LessEqual[l, 1.02e+244]], $MachinePrecision]]]], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(-0.25 * N[(J * N[(l * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.25 \cdot 10^{+281} \lor \neg \left(\ell \leq -1120000\right) \land \left(\ell \leq 0.31 \lor \neg \left(\ell \leq 1.02 \cdot 10^{+244}\right)\right):\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.25000000000000004e281 or -1.12e6 < l < 0.309999999999999998 or 1.02e244 < l

    1. Initial program 75.3%

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

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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot 0.016666666666666666\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around 0 92.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. *-commutative92.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*92.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*92.3%

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

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

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

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

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

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

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

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

    if -1.25000000000000004e281 < l < -1.12e6 or 0.309999999999999998 < l < 1.02e244

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-0.25 \cdot \left(J \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot \ell\right)\right) + 2 \cdot \left(J \cdot \ell\right)\right) + U \]
    11. Applied egg-rr29.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.25 \cdot 10^{+281} \lor \neg \left(\ell \leq -1120000\right) \land \left(\ell \leq 0.31 \lor \neg \left(\ell \leq 1.02 \cdot 10^{+244}\right)\right):\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(-0.25 \cdot \left(J \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right) + 2 \cdot \left(\ell \cdot J\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 42.5% accurate, 23.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -4.5e16 or 1050 < 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-rr17.7%

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

    if -4.5e16 < l < 1050

    1. Initial program 71.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*71.2%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    3. Simplified71.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 J around 0 65.5%

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

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

Alternative 14: 53.5% accurate, 44.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 15: 37.0% 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 86.4%

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

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

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

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

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

Alternative 16: 2.7% accurate, 312.0× speedup?

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

\\
0.25
\end{array}
Derivation
  1. Initial program 86.4%

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

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

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

Reproduce

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