Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.2% → 99.7%
Time: 32.7s
Alternatives: 14
Speedup: 2.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 86.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 0.4× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1.00000000000000005e-4

    1. Initial program 71.9%

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

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

    if 1.00000000000000005e-4 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification100.0%

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

Alternative 2: 99.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{-\ell}\\ \mathbf{if}\;\ell \leq -5.5:\\ \;\;\;\;\left(J \cdot \left(27 - t\_1\right)\right) \cdot t\_0 + U\\ \mathbf{elif}\;\ell \leq 1.3 \lor \neg \left(\ell \leq 3.6 \cdot 10^{+39}\right):\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(e^{\ell} - t\_1\right) \cdot J\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (exp (- l))))
   (if (<= l -5.5)
     (+ (* (* J (- 27.0 t_1)) t_0) U)
     (if (or (<= l 1.3) (not (<= l 3.6e+39)))
       (+
        U
        (*
         t_0
         (*
          J
          (*
           l
           (+
            2.0
            (*
             (* l l)
             (+
              0.3333333333333333
              (*
               (* l l)
               (+
                0.016666666666666666
                (* (* l l) 0.0003968253968253968))))))))))
       (+ U (* (- (exp l) t_1) J))))))
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 (l <= -5.5) {
		tmp = ((J * (27.0 - t_1)) * t_0) + U;
	} else if ((l <= 1.3) || !(l <= 3.6e+39)) {
		tmp = U + (t_0 * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))));
	} else {
		tmp = U + ((exp(l) - t_1) * 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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    t_1 = exp(-l)
    if (l <= (-5.5d0)) then
        tmp = ((j * (27.0d0 - t_1)) * t_0) + u
    else if ((l <= 1.3d0) .or. (.not. (l <= 3.6d+39))) then
        tmp = u + (t_0 * (j * (l * (2.0d0 + ((l * l) * (0.3333333333333333d0 + ((l * l) * (0.016666666666666666d0 + ((l * l) * 0.0003968253968253968d0)))))))))
    else
        tmp = u + ((exp(l) - t_1) * j)
    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 = Math.exp(-l);
	double tmp;
	if (l <= -5.5) {
		tmp = ((J * (27.0 - t_1)) * t_0) + U;
	} else if ((l <= 1.3) || !(l <= 3.6e+39)) {
		tmp = U + (t_0 * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))));
	} else {
		tmp = U + ((Math.exp(l) - t_1) * J);
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = math.exp(-l)
	tmp = 0
	if l <= -5.5:
		tmp = ((J * (27.0 - t_1)) * t_0) + U
	elif (l <= 1.3) or not (l <= 3.6e+39):
		tmp = U + (t_0 * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))))
	else:
		tmp = U + ((math.exp(l) - t_1) * J)
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = exp(Float64(-l))
	tmp = 0.0
	if (l <= -5.5)
		tmp = Float64(Float64(Float64(J * Float64(27.0 - t_1)) * t_0) + U);
	elseif ((l <= 1.3) || !(l <= 3.6e+39))
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * Float64(2.0 + Float64(Float64(l * l) * Float64(0.3333333333333333 + Float64(Float64(l * l) * Float64(0.016666666666666666 + Float64(Float64(l * l) * 0.0003968253968253968))))))))));
	else
		tmp = Float64(U + Float64(Float64(exp(l) - t_1) * J));
	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 (l <= -5.5)
		tmp = ((J * (27.0 - t_1)) * t_0) + U;
	elseif ((l <= 1.3) || ~((l <= 3.6e+39)))
		tmp = U + (t_0 * (J * (l * (2.0 + ((l * l) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968)))))))));
	else
		tmp = U + ((exp(l) - t_1) * J);
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-l)], $MachinePrecision]}, If[LessEqual[l, -5.5], N[(N[(N[(J * N[(27.0 - t$95$1), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], If[Or[LessEqual[l, 1.3], N[Not[LessEqual[l, 3.6e+39]], $MachinePrecision]], N[(U + N[(t$95$0 * N[(J * N[(l * N[(2.0 + N[(N[(l * l), $MachinePrecision] * N[(0.3333333333333333 + N[(N[(l * l), $MachinePrecision] * N[(0.016666666666666666 + N[(N[(l * l), $MachinePrecision] * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(N[Exp[l], $MachinePrecision] - t$95$1), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq 1.3 \lor \neg \left(\ell \leq 3.6 \cdot 10^{+39}\right):\\
\;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;U + \left(e^{\ell} - t\_1\right) \cdot J\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.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 \]

    if -5.5 < l < 1.30000000000000004 or 3.59999999999999984e39 < l

    1. Initial program 80.9%

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + 0.0003968253968253968 \cdot {\ell}^{2}\right)\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 + {\ell}^{2} \cdot \left(0.016666666666666666 + \color{blue}{{\ell}^{2} \cdot 0.0003968253968253968}\right)\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 \left(0.016666666666666666 + {\ell}^{2} \cdot 0.0003968253968253968\right)\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 + {\ell}^{2} \cdot \left(0.016666666666666666 + \color{blue}{\left(\ell \cdot \ell\right)} \cdot 0.0003968253968253968\right)\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 + {\ell}^{2} \cdot \left(0.016666666666666666 + \color{blue}{\left(\ell \cdot \ell\right)} \cdot 0.0003968253968253968\right)\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 + {\ell}^{2} \cdot \left(0.016666666666666666 + \color{blue}{\left(\ell \cdot \ell\right)} \cdot 0.0003968253968253968\right)\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 + {\ell}^{2} \cdot \left(0.3333333333333333 + \color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    10. Step-by-step derivation
      1. unpow299.9%

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + \color{blue}{\left(\ell \cdot \ell\right)} \cdot 0.0003968253968253968\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    11. 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 \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]

    if 1.30000000000000004 < l < 3.59999999999999984e39

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification98.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.5:\\ \;\;\;\;\left(J \cdot \left(27 - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{elif}\;\ell \leq 1.3 \lor \neg \left(\ell \leq 3.6 \cdot 10^{+39}\right):\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 96.6% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 0.43 \lor \neg \left(\ell \leq 3.6 \cdot 10^{+39}\right):\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \left(\ell \cdot \ell\right) \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 0.429999999999999993 or 3.59999999999999984e39 < l

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

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

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

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

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

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

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

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

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

      \[\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 \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]

    if 0.429999999999999993 < l < 3.59999999999999984e39

    1. Initial program 100.0%

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

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

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

Alternative 4: 84.1% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\\ \mathbf{if}\;\ell \leq -1.15 \cdot 10^{-5}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 820:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 14500000000000:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0
         (+
          U
          (*
           J
           (*
            l
            (+
             2.0
             (*
              (pow l 2.0)
              (+
               0.3333333333333333
               (*
                (* l l)
                (+
                 0.016666666666666666
                 (* (* l l) 0.0003968253968253968)))))))))))
   (if (<= l -1.15e-5)
     t_0
     (if (<= l 820.0)
       (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))
       (if (<= l 14500000000000.0) (pow U -4.0) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (l * (2.0 + (pow(l, 2.0) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968))))))));
	double tmp;
	if (l <= -1.15e-5) {
		tmp = t_0;
	} else if (l <= 820.0) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 14500000000000.0) {
		tmp = pow(U, -4.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = u + (j * (l * (2.0d0 + ((l ** 2.0d0) * (0.3333333333333333d0 + ((l * l) * (0.016666666666666666d0 + ((l * l) * 0.0003968253968253968d0))))))))
    if (l <= (-1.15d-5)) then
        tmp = t_0
    else if (l <= 820.0d0) then
        tmp = u + (cos((k / 2.0d0)) * (j * (l * 2.0d0)))
    else if (l <= 14500000000000.0d0) then
        tmp = u ** (-4.0d0)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (l * (2.0 + (Math.pow(l, 2.0) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968))))))));
	double tmp;
	if (l <= -1.15e-5) {
		tmp = t_0;
	} else if (l <= 820.0) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 14500000000000.0) {
		tmp = Math.pow(U, -4.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * (l * (2.0 + (math.pow(l, 2.0) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968))))))))
	tmp = 0
	if l <= -1.15e-5:
		tmp = t_0
	elif l <= 820.0:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * 2.0)))
	elif l <= 14500000000000.0:
		tmp = math.pow(U, -4.0)
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64((l ^ 2.0) * Float64(0.3333333333333333 + Float64(Float64(l * l) * Float64(0.016666666666666666 + Float64(Float64(l * l) * 0.0003968253968253968)))))))))
	tmp = 0.0
	if (l <= -1.15e-5)
		tmp = t_0;
	elseif (l <= 820.0)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	elseif (l <= 14500000000000.0)
		tmp = U ^ -4.0;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (J * (l * (2.0 + ((l ^ 2.0) * (0.3333333333333333 + ((l * l) * (0.016666666666666666 + ((l * l) * 0.0003968253968253968))))))));
	tmp = 0.0;
	if (l <= -1.15e-5)
		tmp = t_0;
	elseif (l <= 820.0)
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	elseif (l <= 14500000000000.0)
		tmp = U ^ -4.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(J * N[(l * N[(2.0 + N[(N[Power[l, 2.0], $MachinePrecision] * N[(0.3333333333333333 + N[(N[(l * l), $MachinePrecision] * N[(0.016666666666666666 + N[(N[(l * l), $MachinePrecision] * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.15e-5], t$95$0, If[LessEqual[l, 820.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, 14500000000000.0], N[Power[U, -4.0], $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\ell \leq 14500000000000:\\
\;\;\;\;{U}^{-4}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.15e-5 or 1.45e13 < l

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

    if -1.15e-5 < l < 820

    1. Initial program 72.1%

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

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

    if 820 < l < 1.45e13

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.15 \cdot 10^{-5}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 820:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 14500000000000:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + \left(\ell \cdot \ell\right) \cdot \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 95.2% accurate, 2.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

    \[\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 \left(0.016666666666666666 + \left(\ell \cdot \ell\right) \cdot 0.0003968253968253968\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  12. Final simplification90.2%

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

Alternative 6: 46.3% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -4500:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 900:\\ \;\;\;\;U\\ \mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+94}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;U + -0.008333333333333333 \cdot {U}^{5}\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -4500.0)
   (pow U -4.0)
   (if (<= l 900.0)
     U
     (if (<= l 5.6e+94)
       (pow U -4.0)
       (+ U (* -0.008333333333333333 (pow U 5.0)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -4500.0) {
		tmp = pow(U, -4.0);
	} else if (l <= 900.0) {
		tmp = U;
	} else if (l <= 5.6e+94) {
		tmp = pow(U, -4.0);
	} else {
		tmp = U + (-0.008333333333333333 * pow(U, 5.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 <= (-4500.0d0)) then
        tmp = u ** (-4.0d0)
    else if (l <= 900.0d0) then
        tmp = u
    else if (l <= 5.6d+94) then
        tmp = u ** (-4.0d0)
    else
        tmp = u + ((-0.008333333333333333d0) * (u ** 5.0d0))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -4500.0) {
		tmp = Math.pow(U, -4.0);
	} else if (l <= 900.0) {
		tmp = U;
	} else if (l <= 5.6e+94) {
		tmp = Math.pow(U, -4.0);
	} else {
		tmp = U + (-0.008333333333333333 * Math.pow(U, 5.0));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -4500.0:
		tmp = math.pow(U, -4.0)
	elif l <= 900.0:
		tmp = U
	elif l <= 5.6e+94:
		tmp = math.pow(U, -4.0)
	else:
		tmp = U + (-0.008333333333333333 * math.pow(U, 5.0))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -4500.0)
		tmp = U ^ -4.0;
	elseif (l <= 900.0)
		tmp = U;
	elseif (l <= 5.6e+94)
		tmp = U ^ -4.0;
	else
		tmp = Float64(U + Float64(-0.008333333333333333 * (U ^ 5.0)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -4500.0)
		tmp = U ^ -4.0;
	elseif (l <= 900.0)
		tmp = U;
	elseif (l <= 5.6e+94)
		tmp = U ^ -4.0;
	else
		tmp = U + (-0.008333333333333333 * (U ^ 5.0));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -4500.0], N[Power[U, -4.0], $MachinePrecision], If[LessEqual[l, 900.0], U, If[LessEqual[l, 5.6e+94], N[Power[U, -4.0], $MachinePrecision], N[(U + N[(-0.008333333333333333 * N[Power[U, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4500:\\
\;\;\;\;{U}^{-4}\\

\mathbf{elif}\;\ell \leq 900:\\
\;\;\;\;U\\

\mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+94}:\\
\;\;\;\;{U}^{-4}\\

\mathbf{else}:\\
\;\;\;\;U + -0.008333333333333333 \cdot {U}^{5}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -4500 or 900 < l < 5.59999999999999997e94

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

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

    if -4500 < l < 900

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

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

    if 5.59999999999999997e94 < 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-rr22.2%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)} \]
    4. Taylor expanded in U around 0 22.3%

      \[\leadsto \mathsf{log1p}\left(\color{blue}{U \cdot \left(1 + U \cdot \left(0.5 + U \cdot \left(0.16666666666666666 + 0.041666666666666664 \cdot U\right)\right)\right)}\right) \]
    5. Step-by-step derivation
      1. *-commutative22.3%

        \[\leadsto \mathsf{log1p}\left(U \cdot \left(1 + U \cdot \left(0.5 + U \cdot \left(0.16666666666666666 + \color{blue}{U \cdot 0.041666666666666664}\right)\right)\right)\right) \]
    6. Simplified22.3%

      \[\leadsto \mathsf{log1p}\left(\color{blue}{U \cdot \left(1 + U \cdot \left(0.5 + U \cdot \left(0.16666666666666666 + U \cdot 0.041666666666666664\right)\right)\right)}\right) \]
    7. Taylor expanded in U around 0 28.7%

      \[\leadsto \color{blue}{U \cdot \left(1 + -0.008333333333333333 \cdot {U}^{4}\right)} \]
    8. Step-by-step derivation
      1. distribute-rgt-in28.7%

        \[\leadsto \color{blue}{1 \cdot U + \left(-0.008333333333333333 \cdot {U}^{4}\right) \cdot U} \]
      2. *-lft-identity28.7%

        \[\leadsto \color{blue}{U} + \left(-0.008333333333333333 \cdot {U}^{4}\right) \cdot U \]
      3. associate-*l*28.7%

        \[\leadsto U + \color{blue}{-0.008333333333333333 \cdot \left({U}^{4} \cdot U\right)} \]
      4. pow-plus28.7%

        \[\leadsto U + -0.008333333333333333 \cdot \color{blue}{{U}^{\left(4 + 1\right)}} \]
      5. metadata-eval28.7%

        \[\leadsto U + -0.008333333333333333 \cdot {U}^{\color{blue}{5}} \]
    9. Simplified28.7%

      \[\leadsto \color{blue}{U + -0.008333333333333333 \cdot {U}^{5}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 7: 46.0% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -920 \lor \neg \left(\ell \leq 920\right):\\
\;\;\;\;{U}^{-4}\\

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


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

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

    if -920 < l < 920

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

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

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

Alternative 8: 45.4% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -750:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 1350:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;{U}^{-3}\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -750.0) (pow U -4.0) (if (<= l 1350.0) U (pow U -3.0))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -750.0) {
		tmp = pow(U, -4.0);
	} else if (l <= 1350.0) {
		tmp = U;
	} else {
		tmp = pow(U, -3.0);
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (l <= (-750.0d0)) then
        tmp = u ** (-4.0d0)
    else if (l <= 1350.0d0) then
        tmp = u
    else
        tmp = u ** (-3.0d0)
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -750.0) {
		tmp = Math.pow(U, -4.0);
	} else if (l <= 1350.0) {
		tmp = U;
	} else {
		tmp = Math.pow(U, -3.0);
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -750.0:
		tmp = math.pow(U, -4.0)
	elif l <= 1350.0:
		tmp = U
	else:
		tmp = math.pow(U, -3.0)
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -750.0)
		tmp = U ^ -4.0;
	elseif (l <= 1350.0)
		tmp = U;
	else
		tmp = U ^ -3.0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -750.0)
		tmp = U ^ -4.0;
	elseif (l <= 1350.0)
		tmp = U;
	else
		tmp = U ^ -3.0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -750.0], N[Power[U, -4.0], $MachinePrecision], If[LessEqual[l, 1350.0], U, N[Power[U, -3.0], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -750:\\
\;\;\;\;{U}^{-4}\\

\mathbf{elif}\;\ell \leq 1350:\\
\;\;\;\;U\\

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


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

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

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

    if -750 < l < 1350

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

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

    if 1350 < 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-rr24.1%

      \[\leadsto \color{blue}{{U}^{-3}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 9: 64.1% accurate, 2.8× speedup?

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

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

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

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

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

Alternative 10: 64.0% accurate, 2.8× speedup?

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

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

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

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

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

Alternative 11: 43.3% accurate, 20.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -850 or 5.2e9 < 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-rr13.1%

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

    if -850 < l < 5.2e9

    1. Initial program 73.3%

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

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

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

Alternative 12: 42.9% accurate, 20.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1.2 \cdot 10^{-25}:\\ \;\;\;\;U \cdot \left(1 + -4 \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;\ell \leq 2300000000:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(U - -4\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -1.2e-25)
   (* U (+ 1.0 (* -4.0 (/ J U))))
   (if (<= l 2300000000.0) U (* U (- U -4.0)))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -1.2e-25) {
		tmp = U * (1.0 + (-4.0 * (J / U)));
	} else if (l <= 2300000000.0) {
		tmp = U;
	} else {
		tmp = U * (U - -4.0);
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (l <= (-1.2d-25)) then
        tmp = u * (1.0d0 + ((-4.0d0) * (j / u)))
    else if (l <= 2300000000.0d0) then
        tmp = u
    else
        tmp = u * (u - (-4.0d0))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -1.2e-25) {
		tmp = U * (1.0 + (-4.0 * (J / U)));
	} else if (l <= 2300000000.0) {
		tmp = U;
	} else {
		tmp = U * (U - -4.0);
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -1.2e-25:
		tmp = U * (1.0 + (-4.0 * (J / U)))
	elif l <= 2300000000.0:
		tmp = U
	else:
		tmp = U * (U - -4.0)
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -1.2e-25)
		tmp = Float64(U * Float64(1.0 + Float64(-4.0 * Float64(J / U))));
	elseif (l <= 2300000000.0)
		tmp = U;
	else
		tmp = Float64(U * Float64(U - -4.0));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -1.2e-25)
		tmp = U * (1.0 + (-4.0 * (J / U)));
	elseif (l <= 2300000000.0)
		tmp = U;
	else
		tmp = U * (U - -4.0);
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -1.2e-25], N[(U * N[(1.0 + N[(-4.0 * N[(J / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2300000000.0], U, N[(U * N[(U - -4.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.2 \cdot 10^{-25}:\\
\;\;\;\;U \cdot \left(1 + -4 \cdot \frac{J}{U}\right)\\

\mathbf{elif}\;\ell \leq 2300000000:\\
\;\;\;\;U\\

\mathbf{else}:\\
\;\;\;\;U \cdot \left(U - -4\right)\\


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

    1. Initial program 94.8%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, -4, U\right)} \]
    4. Taylor expanded in U around inf 21.0%

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

    if -1.20000000000000005e-25 < l < 2.3e9

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

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

    if 2.3e9 < 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-rr13.8%

      \[\leadsto \color{blue}{U \cdot \left(U - -4\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 13: 43.2% accurate, 23.9× speedup?

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

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

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


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

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

    if -800 < l < 1.6e15

    1. Initial program 73.9%

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

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

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

Alternative 14: 36.9% accurate, 312.0× speedup?

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

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

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

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

Reproduce

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