Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.6% → 96.4%
Time: 11.5s
Alternatives: 15
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 15 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.6% 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: 96.4% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_0 := J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
t_1 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t\_0 \leq 10^{+139}:\\
\;\;\;\;\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\_1 + U\\

\mathbf{else}:\\
\;\;\;\;U + t\_0 \cdot t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < 1.00000000000000003e139

    1. Initial program 81.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.0%

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

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

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

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

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

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

      \[\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 \]

    if 1.00000000000000003e139 < (*.f64 J (-.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 2 regimes into one program.
  4. Final simplification98.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \cdot \left(e^{\ell} - e^{-\ell}\right) \leq 10^{+139}:\\ \;\;\;\;\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) + U\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 98.2% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq 4.9 \cdot 10^{-14} \lor \neg \left(\ell \leq 5.4 \cdot 10^{+45}\right):\\
\;\;\;\;\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\_1 + U\\

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


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

    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-rr98.5%

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

    if -4.5999999999999996 < l < 4.89999999999999995e-14 or 5.39999999999999968e45 < l

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

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

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

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

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

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

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

      \[\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 \]

    if 4.89999999999999995e-14 < l < 5.39999999999999968e45

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.6:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(27 - e^{-\ell}\right)\right)\\ \mathbf{elif}\;\ell \leq 4.9 \cdot 10^{-14} \lor \neg \left(\ell \leq 5.4 \cdot 10^{+45}\right):\\ \;\;\;\;\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) + U\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(e^{\ell} - e^{-\ell}\right) + U\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 94.7% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 4.9 \cdot 10^{-14} \lor \neg \left(\ell \leq 5.6 \cdot 10^{+46}\right):\\
\;\;\;\;\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) + U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 4.89999999999999995e-14 or 5.60000000000000037e46 < l

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

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

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

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

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

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

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

      \[\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 \]

    if 4.89999999999999995e-14 < l < 5.60000000000000037e46

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 4.9 \cdot 10^{-14} \lor \neg \left(\ell \leq 5.6 \cdot 10^{+46}\right):\\ \;\;\;\;\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) + U\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(e^{\ell} - e^{-\ell}\right) + U\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 93.1% accurate, 2.5× speedup?

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

\\
\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) + U
\end{array}
Derivation
  1. Initial program 85.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 92.5%

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

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

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

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

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

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

Alternative 5: 56.8% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(5 + -8 \cdot \left(K \cdot K\right)\right)\\ \mathbf{if}\;\ell \leq -6 \cdot 10^{+170}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -920:\\ \;\;\;\;\frac{16 - U \cdot U}{U + -4}\\ \mathbf{elif}\;\ell \leq 10500:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 2.05 \cdot 10^{+195}:\\ \;\;\;\;{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)) (+ 5.0 (* -8.0 (* K K)))))))
   (if (<= l -6e+170)
     t_0
     (if (<= l -920.0)
       (/ (- 16.0 (* U U)) (+ U -4.0))
       (if (<= l 10500.0)
         (+ U (* l (* J 2.0)))
         (if (<= l 2.05e+195) (pow U -4.0) t_0))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + ((J * (l * 2.0)) * (5.0 + (-8.0 * (K * K))));
	double tmp;
	if (l <= -6e+170) {
		tmp = t_0;
	} else if (l <= -920.0) {
		tmp = (16.0 - (U * U)) / (U + -4.0);
	} else if (l <= 10500.0) {
		tmp = U + (l * (J * 2.0));
	} else if (l <= 2.05e+195) {
		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)) * (5.0d0 + ((-8.0d0) * (k * k))))
    if (l <= (-6d+170)) then
        tmp = t_0
    else if (l <= (-920.0d0)) then
        tmp = (16.0d0 - (u * u)) / (u + (-4.0d0))
    else if (l <= 10500.0d0) then
        tmp = u + (l * (j * 2.0d0))
    else if (l <= 2.05d+195) 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)) * (5.0 + (-8.0 * (K * K))));
	double tmp;
	if (l <= -6e+170) {
		tmp = t_0;
	} else if (l <= -920.0) {
		tmp = (16.0 - (U * U)) / (U + -4.0);
	} else if (l <= 10500.0) {
		tmp = U + (l * (J * 2.0));
	} else if (l <= 2.05e+195) {
		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)) * (5.0 + (-8.0 * (K * K))))
	tmp = 0
	if l <= -6e+170:
		tmp = t_0
	elif l <= -920.0:
		tmp = (16.0 - (U * U)) / (U + -4.0)
	elif l <= 10500.0:
		tmp = U + (l * (J * 2.0))
	elif l <= 2.05e+195:
		tmp = math.pow(U, -4.0)
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(Float64(J * Float64(l * 2.0)) * Float64(5.0 + Float64(-8.0 * Float64(K * K)))))
	tmp = 0.0
	if (l <= -6e+170)
		tmp = t_0;
	elseif (l <= -920.0)
		tmp = Float64(Float64(16.0 - Float64(U * U)) / Float64(U + -4.0));
	elseif (l <= 10500.0)
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	elseif (l <= 2.05e+195)
		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)) * (5.0 + (-8.0 * (K * K))));
	tmp = 0.0;
	if (l <= -6e+170)
		tmp = t_0;
	elseif (l <= -920.0)
		tmp = (16.0 - (U * U)) / (U + -4.0);
	elseif (l <= 10500.0)
		tmp = U + (l * (J * 2.0));
	elseif (l <= 2.05e+195)
		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[(N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision] * N[(5.0 + N[(-8.0 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -6e+170], t$95$0, If[LessEqual[l, -920.0], N[(N[(16.0 - N[(U * U), $MachinePrecision]), $MachinePrecision] / N[(U + -4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 10500.0], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.05e+195], N[Power[U, -4.0], $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -920:\\
\;\;\;\;\frac{16 - U \cdot U}{U + -4}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -5.99999999999999994e170 or 2.05e195 < 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 53.1%

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

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

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

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(e^{\color{blue}{\log \left(1 + \cos \left(-4 \cdot K\right)\right)}} - -3\right) + U \]
      2. rem-exp-log33.1%

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

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(\cos \color{blue}{\left(K \cdot -4\right)} + \left(1 - -3\right)\right) + U \]
      6. metadata-eval33.1%

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

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

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

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

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

    if -5.99999999999999994e170 < l < -920

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-4 - U} \]
    4. Step-by-step derivation
      1. sub-neg3.2%

        \[\leadsto \color{blue}{-4 + \left(-U\right)} \]
      2. flip-+34.2%

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

        \[\leadsto \frac{\color{blue}{16} - \left(-U\right) \cdot \left(-U\right)}{-4 - \left(-U\right)} \]
    5. Applied egg-rr34.2%

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

    if -920 < l < 10500

    1. Initial program 75.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 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 \]
    6. Taylor expanded in K around 0 84.2%

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

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

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

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

    if 10500 < l < 2.05e195

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6 \cdot 10^{+170}:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(5 + -8 \cdot \left(K \cdot K\right)\right)\\ \mathbf{elif}\;\ell \leq -920:\\ \;\;\;\;\frac{16 - U \cdot U}{U + -4}\\ \mathbf{elif}\;\ell \leq 10500:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 2.05 \cdot 10^{+195}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(5 + -8 \cdot \left(K \cdot K\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 64.9% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ \mathbf{if}\;\ell \leq -2.4 \cdot 10^{-33}:\\ \;\;\;\;J \cdot \left(2 \cdot \left(\ell \cdot t\_0\right) + \frac{U}{J}\right)\\ \mathbf{elif}\;\ell \leq 5.4 \cdot 10^{+17}:\\ \;\;\;\;U + \ell \cdot \left(t\_0 \cdot \left(J \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 1.95 \cdot 10^{+195}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(5 + -8 \cdot \left(K \cdot K\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (* K 0.5))))
   (if (<= l -2.4e-33)
     (* J (+ (* 2.0 (* l t_0)) (/ U J)))
     (if (<= l 5.4e+17)
       (+ U (* l (* t_0 (* J 2.0))))
       (if (<= l 1.95e+195)
         (pow U -4.0)
         (+ U (* (* J (* l 2.0)) (+ 5.0 (* -8.0 (* K K))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K * 0.5));
	double tmp;
	if (l <= -2.4e-33) {
		tmp = J * ((2.0 * (l * t_0)) + (U / J));
	} else if (l <= 5.4e+17) {
		tmp = U + (l * (t_0 * (J * 2.0)));
	} else if (l <= 1.95e+195) {
		tmp = pow(U, -4.0);
	} else {
		tmp = U + ((J * (l * 2.0)) * (5.0 + (-8.0 * (K * K))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos((k * 0.5d0))
    if (l <= (-2.4d-33)) then
        tmp = j * ((2.0d0 * (l * t_0)) + (u / j))
    else if (l <= 5.4d+17) then
        tmp = u + (l * (t_0 * (j * 2.0d0)))
    else if (l <= 1.95d+195) then
        tmp = u ** (-4.0d0)
    else
        tmp = u + ((j * (l * 2.0d0)) * (5.0d0 + ((-8.0d0) * (k * k))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K * 0.5));
	double tmp;
	if (l <= -2.4e-33) {
		tmp = J * ((2.0 * (l * t_0)) + (U / J));
	} else if (l <= 5.4e+17) {
		tmp = U + (l * (t_0 * (J * 2.0)));
	} else if (l <= 1.95e+195) {
		tmp = Math.pow(U, -4.0);
	} else {
		tmp = U + ((J * (l * 2.0)) * (5.0 + (-8.0 * (K * K))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K * 0.5))
	tmp = 0
	if l <= -2.4e-33:
		tmp = J * ((2.0 * (l * t_0)) + (U / J))
	elif l <= 5.4e+17:
		tmp = U + (l * (t_0 * (J * 2.0)))
	elif l <= 1.95e+195:
		tmp = math.pow(U, -4.0)
	else:
		tmp = U + ((J * (l * 2.0)) * (5.0 + (-8.0 * (K * K))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K * 0.5))
	tmp = 0.0
	if (l <= -2.4e-33)
		tmp = Float64(J * Float64(Float64(2.0 * Float64(l * t_0)) + Float64(U / J)));
	elseif (l <= 5.4e+17)
		tmp = Float64(U + Float64(l * Float64(t_0 * Float64(J * 2.0))));
	elseif (l <= 1.95e+195)
		tmp = U ^ -4.0;
	else
		tmp = Float64(U + Float64(Float64(J * Float64(l * 2.0)) * Float64(5.0 + Float64(-8.0 * Float64(K * K)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K * 0.5));
	tmp = 0.0;
	if (l <= -2.4e-33)
		tmp = J * ((2.0 * (l * t_0)) + (U / J));
	elseif (l <= 5.4e+17)
		tmp = U + (l * (t_0 * (J * 2.0)));
	elseif (l <= 1.95e+195)
		tmp = U ^ -4.0;
	else
		tmp = U + ((J * (l * 2.0)) * (5.0 + (-8.0 * (K * K))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -2.4e-33], N[(J * N[(N[(2.0 * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision] + N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.4e+17], N[(U + N[(l * N[(t$95$0 * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.95e+195], N[Power[U, -4.0], $MachinePrecision], N[(U + N[(N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision] * N[(5.0 + N[(-8.0 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

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

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


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

    1. Initial program 95.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 36.7%

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

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

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

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

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

    if -2.4e-33 < l < 5.4e17

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

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

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

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

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

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

    if 5.4e17 < l < 1.9499999999999999e195

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

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

    if 1.9499999999999999e195 < l

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(e^{\color{blue}{\log \left(1 + \cos \left(-4 \cdot K\right)\right)}} - -3\right) + U \]
      2. rem-exp-log34.4%

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

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(\cos \color{blue}{\left(K \cdot -4\right)} + \left(1 - -3\right)\right) + U \]
      6. metadata-eval34.4%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.4 \cdot 10^{-33}:\\ \;\;\;\;J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right) + \frac{U}{J}\right)\\ \mathbf{elif}\;\ell \leq 5.4 \cdot 10^{+17}:\\ \;\;\;\;U + \ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 1.95 \cdot 10^{+195}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(5 + -8 \cdot \left(K \cdot K\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 63.7% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 3.4 \cdot 10^{+20}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 5.5 \cdot 10^{+195}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(5 + -8 \cdot \left(K \cdot K\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l 3.4e+20)
   (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
   (if (<= l 5.5e+195)
     (pow U -4.0)
     (+ U (* (* J (* l 2.0)) (+ 5.0 (* -8.0 (* K K))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 3.4e+20) {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	} else if (l <= 5.5e+195) {
		tmp = pow(U, -4.0);
	} else {
		tmp = U + ((J * (l * 2.0)) * (5.0 + (-8.0 * (K * K))));
	}
	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.4d+20) then
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    else if (l <= 5.5d+195) then
        tmp = u ** (-4.0d0)
    else
        tmp = u + ((j * (l * 2.0d0)) * (5.0d0 + ((-8.0d0) * (k * k))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 3.4e+20) {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	} else if (l <= 5.5e+195) {
		tmp = Math.pow(U, -4.0);
	} else {
		tmp = U + ((J * (l * 2.0)) * (5.0 + (-8.0 * (K * K))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= 3.4e+20:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	elif l <= 5.5e+195:
		tmp = math.pow(U, -4.0)
	else:
		tmp = U + ((J * (l * 2.0)) * (5.0 + (-8.0 * (K * K))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= 3.4e+20)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	elseif (l <= 5.5e+195)
		tmp = U ^ -4.0;
	else
		tmp = Float64(U + Float64(Float64(J * Float64(l * 2.0)) * Float64(5.0 + Float64(-8.0 * Float64(K * K)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= 3.4e+20)
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	elseif (l <= 5.5e+195)
		tmp = U ^ -4.0;
	else
		tmp = U + ((J * (l * 2.0)) * (5.0 + (-8.0 * (K * K))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, 3.4e+20], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.5e+195], N[Power[U, -4.0], $MachinePrecision], N[(U + N[(N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision] * N[(5.0 + N[(-8.0 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 82.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 79.2%

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

    if 3.4e20 < l < 5.49999999999999994e195

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

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

    if 5.49999999999999994e195 < l

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(e^{\color{blue}{\log \left(1 + \cos \left(-4 \cdot K\right)\right)}} - -3\right) + U \]
      2. rem-exp-log34.4%

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

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(\cos \color{blue}{\left(K \cdot -4\right)} + \left(1 - -3\right)\right) + U \]
      6. metadata-eval34.4%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 3.4 \cdot 10^{+20}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 5.5 \cdot 10^{+195}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(5 + -8 \cdot \left(K \cdot K\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 72.0% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

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

Alternative 9: 57.6% accurate, 10.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(5 + -8 \cdot \left(K \cdot K\right)\right)\\ \mathbf{if}\;\ell \leq -3.6 \cdot 10^{+170}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -1350000:\\ \;\;\;\;\frac{16 - U \cdot U}{U + -4}\\ \mathbf{elif}\;\ell \leq 245:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* (* J (* l 2.0)) (+ 5.0 (* -8.0 (* K K)))))))
   (if (<= l -3.6e+170)
     t_0
     (if (<= l -1350000.0)
       (/ (- 16.0 (* U U)) (+ U -4.0))
       (if (<= l 245.0) (+ U (* l (* J 2.0))) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + ((J * (l * 2.0)) * (5.0 + (-8.0 * (K * K))));
	double tmp;
	if (l <= -3.6e+170) {
		tmp = t_0;
	} else if (l <= -1350000.0) {
		tmp = (16.0 - (U * U)) / (U + -4.0);
	} else if (l <= 245.0) {
		tmp = U + (l * (J * 2.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)) * (5.0d0 + ((-8.0d0) * (k * k))))
    if (l <= (-3.6d+170)) then
        tmp = t_0
    else if (l <= (-1350000.0d0)) then
        tmp = (16.0d0 - (u * u)) / (u + (-4.0d0))
    else if (l <= 245.0d0) then
        tmp = u + (l * (j * 2.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)) * (5.0 + (-8.0 * (K * K))));
	double tmp;
	if (l <= -3.6e+170) {
		tmp = t_0;
	} else if (l <= -1350000.0) {
		tmp = (16.0 - (U * U)) / (U + -4.0);
	} else if (l <= 245.0) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + ((J * (l * 2.0)) * (5.0 + (-8.0 * (K * K))))
	tmp = 0
	if l <= -3.6e+170:
		tmp = t_0
	elif l <= -1350000.0:
		tmp = (16.0 - (U * U)) / (U + -4.0)
	elif l <= 245.0:
		tmp = U + (l * (J * 2.0))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(Float64(J * Float64(l * 2.0)) * Float64(5.0 + Float64(-8.0 * Float64(K * K)))))
	tmp = 0.0
	if (l <= -3.6e+170)
		tmp = t_0;
	elseif (l <= -1350000.0)
		tmp = Float64(Float64(16.0 - Float64(U * U)) / Float64(U + -4.0));
	elseif (l <= 245.0)
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + ((J * (l * 2.0)) * (5.0 + (-8.0 * (K * K))));
	tmp = 0.0;
	if (l <= -3.6e+170)
		tmp = t_0;
	elseif (l <= -1350000.0)
		tmp = (16.0 - (U * U)) / (U + -4.0);
	elseif (l <= 245.0)
		tmp = U + (l * (J * 2.0));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision] * N[(5.0 + N[(-8.0 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.6e+170], t$95$0, If[LessEqual[l, -1350000.0], N[(N[(16.0 - N[(U * U), $MachinePrecision]), $MachinePrecision] / N[(U + -4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 245.0], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -1350000:\\
\;\;\;\;\frac{16 - U \cdot U}{U + -4}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.6e170 or 245 < 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 34.7%

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

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

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

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

      \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\cos \left(-4 \cdot K\right)\right)} - -3\right)} + U \]
    7. Step-by-step derivation
      1. log1p-undefine23.0%

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(e^{\color{blue}{\log \left(1 + \cos \left(-4 \cdot K\right)\right)}} - -3\right) + U \]
      2. rem-exp-log23.0%

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

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(\cos \color{blue}{\left(K \cdot -4\right)} + \left(1 - -3\right)\right) + U \]
      6. metadata-eval23.0%

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

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

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

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

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

    if -3.6e170 < l < -1.35e6

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-4 - U} \]
    4. Step-by-step derivation
      1. sub-neg3.2%

        \[\leadsto \color{blue}{-4 + \left(-U\right)} \]
      2. flip-+34.2%

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

        \[\leadsto \frac{\color{blue}{16} - \left(-U\right) \cdot \left(-U\right)}{-4 - \left(-U\right)} \]
    5. Applied egg-rr34.2%

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

    if -1.35e6 < l < 245

    1. Initial program 74.9%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 98.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. *-commutative98.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.6 \cdot 10^{+170}:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(5 + -8 \cdot \left(K \cdot K\right)\right)\\ \mathbf{elif}\;\ell \leq -1350000:\\ \;\;\;\;\frac{16 - U \cdot U}{U + -4}\\ \mathbf{elif}\;\ell \leq 245:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(5 + -8 \cdot \left(K \cdot K\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 42.2% accurate, 23.9× speedup?

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

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

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


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

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

    if -980 < l < 2.65e8

    1. Initial program 75.2%

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

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

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

Alternative 11: 39.9% accurate, 23.9× speedup?

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

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

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

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


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

    1. Initial program 97.5%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, -4, -U\right)} \]
    4. Step-by-step derivation
      1. fmm-undef4.0%

        \[\leadsto \color{blue}{J \cdot -4 - U} \]
    5. Simplified4.0%

      \[\leadsto \color{blue}{J \cdot -4 - U} \]
    6. Taylor expanded in J around inf 12.4%

      \[\leadsto \color{blue}{J \cdot \left(-1 \cdot \frac{U}{J} - 4\right)} \]
    7. Step-by-step derivation
      1. sub-neg12.4%

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

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

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

        \[\leadsto J \cdot \left(-4 + \color{blue}{\left(-\frac{U}{J}\right)}\right) \]
      5. unsub-neg12.4%

        \[\leadsto J \cdot \color{blue}{\left(-4 - \frac{U}{J}\right)} \]
    8. Simplified12.4%

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

    if -4.1999999999999999e-24 < l < 6.6e7

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

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

    if 6.6e7 < l

    1. Initial program 100.0%

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

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

Alternative 12: 54.1% 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 85.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 68.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. *-commutative68.6%

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

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

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

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

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

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

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

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

Alternative 13: 47.8% accurate, 44.6× speedup?

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

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

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

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

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

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

      \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(e^{\color{blue}{\log \left(1 + \cos \left(-4 \cdot K\right)\right)}} - -3\right) + U \]
    2. rem-exp-log51.1%

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

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

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

      \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(\cos \color{blue}{\left(K \cdot -4\right)} + \left(1 - -3\right)\right) + U \]
    6. metadata-eval51.1%

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

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

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

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

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

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

Alternative 14: 36.4% accurate, 312.0× speedup?

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

\\
U
\end{array}
Derivation
  1. Initial program 85.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 42.0%

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

Alternative 15: 2.7% accurate, 312.0× speedup?

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

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

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

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

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

Reproduce

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