Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.8% → 99.9%
Time: 13.4s
Alternatives: 17
Speedup: 0.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 17 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.8% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;t\_0 \leq 0.04:\\
\;\;\;\;U + \left(J \cdot \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 t\_1\\

\mathbf{else}:\\
\;\;\;\;U + t\_1 \cdot \left(t\_0 \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))) < -0.20000000000000001

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*100.0%

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

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

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

    if -0.20000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.0400000000000000008

    1. Initial program 68.3%

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

    if 0.0400000000000000008 < (-.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 -0.2:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right) + U\\ \mathbf{elif}\;e^{\ell} - e^{-\ell} \leq 0.04:\\ \;\;\;\;U + \left(J \cdot \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)\\ \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.9% accurate, 0.4× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;U + t\_1 \cdot \left(t\_0 \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))) < -0.20000000000000001

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*100.0%

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

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

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

    if -0.20000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.0400000000000000008

    1. Initial program 68.3%

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

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

    if 0.0400000000000000008 < (-.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 -0.2:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right) + U\\ \mathbf{elif}\;e^{\ell} - e^{-\ell} \leq 0.04:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2 + {\ell}^{2} \cdot \left(0.016666666666666666 \cdot \left(J \cdot {\ell}^{2}\right) + J \cdot 0.3333333333333333\right)\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 3: 99.9% accurate, 0.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -0.20000000000000001 or 0.0400000000000000008 < (-.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

    if -0.20000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.0400000000000000008

    1. Initial program 68.3%

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

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

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

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

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

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

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

Alternative 4: 99.9% accurate, 0.4× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;U + t\_1 \cdot \left(t\_0 \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))) < -0.20000000000000001

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*100.0%

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

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

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

    if -0.20000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.0400000000000000008

    1. Initial program 68.3%

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

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

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

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

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

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

    if 0.0400000000000000008 < (-.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 -0.2:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right) + U\\ \mathbf{elif}\;e^{\ell} - e^{-\ell} \leq 0.04:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + 0.016666666666666666 \cdot \left(\ell \cdot \ell\right)\right)\right)\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 5: 87.0% accurate, 0.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < -4.9999999999999999e-48 or 1.99999999999999985e210 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))))

    1. Initial program 99.8%

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

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

    if -4.9999999999999999e-48 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < 1.99999999999999985e210

    1. Initial program 68.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 99.4%

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

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

Alternative 6: 93.1% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-16}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\

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


\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))) < 5.0000000000000004e-16

    1. Initial program 67.8%

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

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

    if 5.0000000000000004e-16 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 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 K around 0 83.5%

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

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

Alternative 7: 96.3% accurate, 0.7× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

      \[\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 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.2%

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

Alternative 8: 93.8% accurate, 0.7× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

    1. Initial program 78.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 93.2%

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

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

Alternative 9: 69.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\\ t_1 := U \cdot \left(1 + 2 \cdot \frac{t\_0}{U}\right)\\ \mathbf{if}\;\ell \leq -4.8 \cdot 10^{+159}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -8.8 \cdot 10^{+90}:\\ \;\;\;\;U + \left(-0.25 \cdot \left(J \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right) + 2 \cdot \left(\ell \cdot J\right)\right)\\ \mathbf{elif}\;\ell \leq -95000000:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U \cdot -3\right)\right)\\ \mathbf{elif}\;\ell \leq 1.4 \cdot 10^{-15}:\\ \;\;\;\;U + 2 \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* J (* l (cos (* 0.5 K)))))
        (t_1 (* U (+ 1.0 (* 2.0 (/ t_0 U))))))
   (if (<= l -4.8e+159)
     t_1
     (if (<= l -8.8e+90)
       (+ U (+ (* -0.25 (* J (* l (* K K)))) (* 2.0 (* l J))))
       (if (<= l -95000000.0)
         (log1p (expm1 (* U -3.0)))
         (if (<= l 1.4e-15) (+ U (* 2.0 t_0)) t_1))))))
double code(double J, double l, double K, double U) {
	double t_0 = J * (l * cos((0.5 * K)));
	double t_1 = U * (1.0 + (2.0 * (t_0 / U)));
	double tmp;
	if (l <= -4.8e+159) {
		tmp = t_1;
	} else if (l <= -8.8e+90) {
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)));
	} else if (l <= -95000000.0) {
		tmp = log1p(expm1((U * -3.0)));
	} else if (l <= 1.4e-15) {
		tmp = U + (2.0 * t_0);
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = J * (l * Math.cos((0.5 * K)));
	double t_1 = U * (1.0 + (2.0 * (t_0 / U)));
	double tmp;
	if (l <= -4.8e+159) {
		tmp = t_1;
	} else if (l <= -8.8e+90) {
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)));
	} else if (l <= -95000000.0) {
		tmp = Math.log1p(Math.expm1((U * -3.0)));
	} else if (l <= 1.4e-15) {
		tmp = U + (2.0 * t_0);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = J * (l * math.cos((0.5 * K)))
	t_1 = U * (1.0 + (2.0 * (t_0 / U)))
	tmp = 0
	if l <= -4.8e+159:
		tmp = t_1
	elif l <= -8.8e+90:
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)))
	elif l <= -95000000.0:
		tmp = math.log1p(math.expm1((U * -3.0)))
	elif l <= 1.4e-15:
		tmp = U + (2.0 * t_0)
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = Float64(J * Float64(l * cos(Float64(0.5 * K))))
	t_1 = Float64(U * Float64(1.0 + Float64(2.0 * Float64(t_0 / U))))
	tmp = 0.0
	if (l <= -4.8e+159)
		tmp = t_1;
	elseif (l <= -8.8e+90)
		tmp = Float64(U + Float64(Float64(-0.25 * Float64(J * Float64(l * Float64(K * K)))) + Float64(2.0 * Float64(l * J))));
	elseif (l <= -95000000.0)
		tmp = log1p(expm1(Float64(U * -3.0)));
	elseif (l <= 1.4e-15)
		tmp = Float64(U + Float64(2.0 * t_0));
	else
		tmp = t_1;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(J * N[(l * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U * N[(1.0 + N[(2.0 * N[(t$95$0 / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -4.8e+159], t$95$1, If[LessEqual[l, -8.8e+90], N[(U + N[(N[(-0.25 * N[(J * N[(l * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -95000000.0], N[Log[1 + N[(Exp[N[(U * -3.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, 1.4e-15], N[(U + N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\ell \leq -95000000:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U \cdot -3\right)\right)\\

\mathbf{elif}\;\ell \leq 1.4 \cdot 10^{-15}:\\
\;\;\;\;U + 2 \cdot t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -4.8e159 or 1.40000000000000007e-15 < 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 94.0%

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

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

      \[\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. Taylor expanded in l around 0 40.4%

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

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

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

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

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

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

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

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

        \[\leadsto {\left(J \cdot \left(\ell \cdot \left(2 \cdot \cos \left(K \cdot \color{blue}{0.5}\right)\right)\right)\right)}^{1} + U \]
    10. Applied egg-rr40.4%

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

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

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

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

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

    if -4.8e159 < l < -8.79999999999999961e90

    1. Initial program 100.0%

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\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. *-commutative100.0%

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

      \[\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. Taylor expanded in l around 0 12.8%

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

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

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

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

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

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

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

    if -8.79999999999999961e90 < l < -9.5e7

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \color{blue}{U \cdot -4 + U} \]
    6. Step-by-step derivation
      1. *-rgt-identity4.1%

        \[\leadsto U \cdot -4 + \color{blue}{U \cdot 1} \]
      2. distribute-lft-out4.1%

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

        \[\leadsto U \cdot \color{blue}{-3} \]
    7. Simplified4.1%

      \[\leadsto \color{blue}{U \cdot -3} \]
    8. Step-by-step derivation
      1. log1p-expm1-u47.9%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(U \cdot -3\right)\right)} \]
    9. Applied egg-rr47.9%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(U \cdot -3\right)\right)} \]

    if -9.5e7 < l < 1.40000000000000007e-15

    1. Initial program 68.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.8 \cdot 10^{+159}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)\\ \mathbf{elif}\;\ell \leq -8.8 \cdot 10^{+90}:\\ \;\;\;\;U + \left(-0.25 \cdot \left(J \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right) + 2 \cdot \left(\ell \cdot J\right)\right)\\ \mathbf{elif}\;\ell \leq -95000000:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U \cdot -3\right)\right)\\ \mathbf{elif}\;\ell \leq 1.4 \cdot 10^{-15}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 56.8% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 83.4%

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

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

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

      \[\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. Taylor expanded in l around 0 52.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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. Taylor expanded in l around 0 65.5%

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

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

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

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

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

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

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

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

        \[\leadsto {\left(J \cdot \left(\ell \cdot \left(2 \cdot \cos \left(K \cdot \color{blue}{0.5}\right)\right)\right)\right)}^{1} + U \]
    10. Applied egg-rr65.5%

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 68.8% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\\ t_1 := U \cdot \left(1 + 2 \cdot \frac{t\_0}{U}\right)\\ \mathbf{if}\;\ell \leq -4.8 \cdot 10^{+159}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -2.45 \cdot 10^{+101}:\\ \;\;\;\;U + \left(-0.25 \cdot \left(J \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right) + 2 \cdot \left(\ell \cdot J\right)\right)\\ \mathbf{elif}\;\ell \leq -92000:\\ \;\;\;\;\mathsf{log1p}\left(U \cdot \left(1 + U \cdot \left(0.5 + U \cdot \left(0.16666666666666666 + U \cdot 0.041666666666666664\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.4 \cdot 10^{-15}:\\ \;\;\;\;U + 2 \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* J (* l (cos (* 0.5 K)))))
        (t_1 (* U (+ 1.0 (* 2.0 (/ t_0 U))))))
   (if (<= l -4.8e+159)
     t_1
     (if (<= l -2.45e+101)
       (+ U (+ (* -0.25 (* J (* l (* K K)))) (* 2.0 (* l J))))
       (if (<= l -92000.0)
         (log1p
          (*
           U
           (+
            1.0
            (*
             U
             (+
              0.5
              (* U (+ 0.16666666666666666 (* U 0.041666666666666664))))))))
         (if (<= l 1.4e-15) (+ U (* 2.0 t_0)) t_1))))))
double code(double J, double l, double K, double U) {
	double t_0 = J * (l * cos((0.5 * K)));
	double t_1 = U * (1.0 + (2.0 * (t_0 / U)));
	double tmp;
	if (l <= -4.8e+159) {
		tmp = t_1;
	} else if (l <= -2.45e+101) {
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)));
	} else if (l <= -92000.0) {
		tmp = log1p((U * (1.0 + (U * (0.5 + (U * (0.16666666666666666 + (U * 0.041666666666666664))))))));
	} else if (l <= 1.4e-15) {
		tmp = U + (2.0 * t_0);
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = J * (l * Math.cos((0.5 * K)));
	double t_1 = U * (1.0 + (2.0 * (t_0 / U)));
	double tmp;
	if (l <= -4.8e+159) {
		tmp = t_1;
	} else if (l <= -2.45e+101) {
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)));
	} else if (l <= -92000.0) {
		tmp = Math.log1p((U * (1.0 + (U * (0.5 + (U * (0.16666666666666666 + (U * 0.041666666666666664))))))));
	} else if (l <= 1.4e-15) {
		tmp = U + (2.0 * t_0);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = J * (l * math.cos((0.5 * K)))
	t_1 = U * (1.0 + (2.0 * (t_0 / U)))
	tmp = 0
	if l <= -4.8e+159:
		tmp = t_1
	elif l <= -2.45e+101:
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)))
	elif l <= -92000.0:
		tmp = math.log1p((U * (1.0 + (U * (0.5 + (U * (0.16666666666666666 + (U * 0.041666666666666664))))))))
	elif l <= 1.4e-15:
		tmp = U + (2.0 * t_0)
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = Float64(J * Float64(l * cos(Float64(0.5 * K))))
	t_1 = Float64(U * Float64(1.0 + Float64(2.0 * Float64(t_0 / U))))
	tmp = 0.0
	if (l <= -4.8e+159)
		tmp = t_1;
	elseif (l <= -2.45e+101)
		tmp = Float64(U + Float64(Float64(-0.25 * Float64(J * Float64(l * Float64(K * K)))) + Float64(2.0 * Float64(l * J))));
	elseif (l <= -92000.0)
		tmp = log1p(Float64(U * Float64(1.0 + Float64(U * Float64(0.5 + Float64(U * Float64(0.16666666666666666 + Float64(U * 0.041666666666666664))))))));
	elseif (l <= 1.4e-15)
		tmp = Float64(U + Float64(2.0 * t_0));
	else
		tmp = t_1;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(J * N[(l * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U * N[(1.0 + N[(2.0 * N[(t$95$0 / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -4.8e+159], t$95$1, If[LessEqual[l, -2.45e+101], N[(U + N[(N[(-0.25 * N[(J * N[(l * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -92000.0], N[Log[1 + N[(U * N[(1.0 + N[(U * N[(0.5 + N[(U * N[(0.16666666666666666 + N[(U * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, 1.4e-15], N[(U + N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\ell \leq -92000:\\
\;\;\;\;\mathsf{log1p}\left(U \cdot \left(1 + U \cdot \left(0.5 + U \cdot \left(0.16666666666666666 + U \cdot 0.041666666666666664\right)\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 1.4 \cdot 10^{-15}:\\
\;\;\;\;U + 2 \cdot t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -4.8e159 or 1.40000000000000007e-15 < 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 94.0%

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

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

      \[\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. Taylor expanded in l around 0 40.4%

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

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

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

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

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

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

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

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

        \[\leadsto {\left(J \cdot \left(\ell \cdot \left(2 \cdot \cos \left(K \cdot \color{blue}{0.5}\right)\right)\right)\right)}^{1} + U \]
    10. Applied egg-rr40.4%

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

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

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

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

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

    if -4.8e159 < l < -2.44999999999999991e101

    1. Initial program 100.0%

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\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. *-commutative100.0%

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

      \[\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. Taylor expanded in l around 0 12.8%

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

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

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

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

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

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

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

    if -2.44999999999999991e101 < l < -92000

    1. Initial program 100.0%

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

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

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

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

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

      \[\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) \]
    7. Step-by-step derivation
      1. *-commutative42.5%

        \[\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) \]
    8. Simplified42.5%

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

    if -92000 < l < 1.40000000000000007e-15

    1. Initial program 68.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.8 \cdot 10^{+159}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)\\ \mathbf{elif}\;\ell \leq -2.45 \cdot 10^{+101}:\\ \;\;\;\;U + \left(-0.25 \cdot \left(J \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right) + 2 \cdot \left(\ell \cdot J\right)\right)\\ \mathbf{elif}\;\ell \leq -92000:\\ \;\;\;\;\mathsf{log1p}\left(U \cdot \left(1 + U \cdot \left(0.5 + U \cdot \left(0.16666666666666666 + U \cdot 0.041666666666666664\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.4 \cdot 10^{-15}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 64.1% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \mathbf{if}\;\ell \leq -2.3 \cdot 10^{+216}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -5 \cdot 10^{+90}:\\ \;\;\;\;U + \left(-0.25 \cdot \left(J \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right) + 2 \cdot \left(\ell \cdot J\right)\right)\\ \mathbf{elif}\;\ell \leq -620000:\\ \;\;\;\;\mathsf{log1p}\left(U \cdot \left(1 + U \cdot \left(0.5 + U \cdot \left(0.16666666666666666 + U \cdot 0.041666666666666664\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* 2.0 (* J (* l (cos (* 0.5 K))))))))
   (if (<= l -2.3e+216)
     t_0
     (if (<= l -5e+90)
       (+ U (+ (* -0.25 (* J (* l (* K K)))) (* 2.0 (* l J))))
       (if (<= l -620000.0)
         (log1p
          (*
           U
           (+
            1.0
            (*
             U
             (+
              0.5
              (* U (+ 0.16666666666666666 (* U 0.041666666666666664))))))))
         t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (J * (l * cos((0.5 * K)))));
	double tmp;
	if (l <= -2.3e+216) {
		tmp = t_0;
	} else if (l <= -5e+90) {
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)));
	} else if (l <= -620000.0) {
		tmp = log1p((U * (1.0 + (U * (0.5 + (U * (0.16666666666666666 + (U * 0.041666666666666664))))))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (J * (l * Math.cos((0.5 * K)))));
	double tmp;
	if (l <= -2.3e+216) {
		tmp = t_0;
	} else if (l <= -5e+90) {
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)));
	} else if (l <= -620000.0) {
		tmp = Math.log1p((U * (1.0 + (U * (0.5 + (U * (0.16666666666666666 + (U * 0.041666666666666664))))))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (2.0 * (J * (l * math.cos((0.5 * K)))))
	tmp = 0
	if l <= -2.3e+216:
		tmp = t_0
	elif l <= -5e+90:
		tmp = U + ((-0.25 * (J * (l * (K * K)))) + (2.0 * (l * J)))
	elif l <= -620000.0:
		tmp = math.log1p((U * (1.0 + (U * (0.5 + (U * (0.16666666666666666 + (U * 0.041666666666666664))))))))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(0.5 * K))))))
	tmp = 0.0
	if (l <= -2.3e+216)
		tmp = t_0;
	elseif (l <= -5e+90)
		tmp = Float64(U + Float64(Float64(-0.25 * Float64(J * Float64(l * Float64(K * K)))) + Float64(2.0 * Float64(l * J))));
	elseif (l <= -620000.0)
		tmp = log1p(Float64(U * Float64(1.0 + Float64(U * Float64(0.5 + Float64(U * Float64(0.16666666666666666 + Float64(U * 0.041666666666666664))))))));
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.3e+216], t$95$0, If[LessEqual[l, -5e+90], N[(U + N[(N[(-0.25 * N[(J * N[(l * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -620000.0], N[Log[1 + N[(U * N[(1.0 + N[(U * N[(0.5 + N[(U * N[(0.16666666666666666 + N[(U * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\ell \leq -620000:\\
\;\;\;\;\mathsf{log1p}\left(U \cdot \left(1 + U \cdot \left(0.5 + U \cdot \left(0.16666666666666666 + U \cdot 0.041666666666666664\right)\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.29999999999999996e216 or -6.2e5 < 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 76.9%

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

    if -2.29999999999999996e216 < l < -5.0000000000000004e90

    1. Initial program 100.0%

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\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. *-commutative100.0%

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

      \[\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. Taylor expanded in l around 0 14.8%

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

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

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

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

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

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

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

    if -5.0000000000000004e90 < l < -6.2e5

    1. Initial program 100.0%

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

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

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

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

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

      \[\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) \]
    7. Step-by-step derivation
      1. *-commutative42.5%

        \[\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) \]
    8. Simplified42.5%

      \[\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) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification70.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.3 \cdot 10^{+216}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -5 \cdot 10^{+90}:\\ \;\;\;\;U + \left(-0.25 \cdot \left(J \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right) + 2 \cdot \left(\ell \cdot J\right)\right)\\ \mathbf{elif}\;\ell \leq -620000:\\ \;\;\;\;\mathsf{log1p}\left(U \cdot \left(1 + U \cdot \left(0.5 + U \cdot \left(0.16666666666666666 + U \cdot 0.041666666666666664\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 63.7% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.15 \cdot 10^{+216} \lor \neg \left(\ell \leq -3 \cdot 10^{+23}\right):\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.14999999999999985e216 or -3.0000000000000001e23 < l

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

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

    if -2.14999999999999985e216 < l < -3.0000000000000001e23

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

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

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

      \[\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. Taylor expanded in l around 0 11.8%

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

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

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

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

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

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

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

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

Alternative 14: 54.8% accurate, 14.2× speedup?

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

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

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


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

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

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

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

      \[\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. Taylor expanded in l around 0 22.8%

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

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

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

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

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

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

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

    if -3.2e23 < l

    1. Initial program 79.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(J \cdot \left(\ell \cdot \left(2 \cdot \cos \left(K \cdot \color{blue}{0.5}\right)\right)\right)\right)}^{1} + U \]
    10. Applied egg-rr77.5%

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

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

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

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

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

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

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

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

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

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

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

Alternative 15: 41.9% accurate, 23.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -115000 or 9.5000000000000003e30 < l

    1. Initial program 100.0%

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

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

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

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

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

    if -115000 < l < 9.5000000000000003e30

    1. Initial program 70.2%

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

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

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

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

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

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

Alternative 16: 53.7% 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 84.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 94.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. *-commutative94.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. Simplified94.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. Taylor expanded in l around 0 63.4%

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

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

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

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

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

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

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

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

      \[\leadsto {\left(J \cdot \left(\ell \cdot \left(2 \cdot \cos \left(K \cdot \color{blue}{0.5}\right)\right)\right)\right)}^{1} + U \]
  10. Applied egg-rr63.4%

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

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

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

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

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

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

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

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

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

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

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

Alternative 17: 36.6% 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 84.7%

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

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

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

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

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

Reproduce

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