Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.2% → 99.6%
Time: 12.2s
Alternatives: 13
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 alternatives:

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

Initial Program: 86.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 1.0× speedup?

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

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

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

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


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

    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 -4.0999999999999996 < l < 880

    1. Initial program 75.7%

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

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

    if 880 < l

    1. Initial program 100.0%

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

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

Alternative 2: 97.3% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;\ell \leq 880:\\
\;\;\;\;\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\_0 + U\\

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


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

    1. Initial program 84.1%

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

    1. Initial program 100.0%

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

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

Alternative 3: 77.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t\_0 \leq -0.69:\\ \;\;\;\;U + J \cdot \left({K}^{2} \cdot \left(\ell \cdot -0.25\right)\right)\\ \mathbf{elif}\;t\_0 \leq 0.22:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot 0.3333333333333333\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= t_0 -0.69)
     (+ U (* J (* (pow K 2.0) (* l -0.25))))
     (if (<= t_0 0.22)
       (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
       (+ U (* 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 tmp;
	if (t_0 <= -0.69) {
		tmp = U + (J * (pow(K, 2.0) * (l * -0.25)));
	} else if (t_0 <= 0.22) {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	} else {
		tmp = U + (J * (l * (2.0 + (pow(l, 2.0) * 0.3333333333333333))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    if (t_0 <= (-0.69d0)) then
        tmp = u + (j * ((k ** 2.0d0) * (l * (-0.25d0))))
    else if (t_0 <= 0.22d0) then
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    else
        tmp = u + (j * (l * (2.0d0 + ((l ** 2.0d0) * 0.3333333333333333d0))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (t_0 <= -0.69) {
		tmp = U + (J * (Math.pow(K, 2.0) * (l * -0.25)));
	} else if (t_0 <= 0.22) {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	} else {
		tmp = U + (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))
	tmp = 0
	if t_0 <= -0.69:
		tmp = U + (J * (math.pow(K, 2.0) * (l * -0.25)))
	elif t_0 <= 0.22:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	else:
		tmp = U + (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))
	tmp = 0.0
	if (t_0 <= -0.69)
		tmp = Float64(U + Float64(J * Float64((K ^ 2.0) * Float64(l * -0.25))));
	elseif (t_0 <= 0.22)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	else
		tmp = Float64(U + 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));
	tmp = 0.0;
	if (t_0 <= -0.69)
		tmp = U + (J * ((K ^ 2.0) * (l * -0.25)));
	elseif (t_0 <= 0.22)
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	else
		tmp = U + (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]}, If[LessEqual[t$95$0, -0.69], N[(U + N[(J * N[(N[Power[K, 2.0], $MachinePrecision] * N[(l * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.22], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(2.0 + N[(N[Power[l, 2.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 93.0%

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

      \[\leadsto \left(J \cdot \color{blue}{\left(2 \cdot \ell\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 56.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 \]
    5. Taylor expanded in K around inf 78.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \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 \color{blue}{1} + U \]
    7. Taylor expanded in l around 0 87.7%

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

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

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

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

Alternative 4: 97.4% accurate, 1.4× speedup?

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

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

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

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


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

    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 -4.0999999999999996 < l < 2.2000000000000002

    1. Initial program 76.1%

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

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

    if 2.2000000000000002 < l

    1. Initial program 98.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 93.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. *-commutative93.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. Simplified93.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 inf 93.6%

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

        \[\leadsto \color{blue}{\left(\left(0.0003968253968253968 \cdot J\right) \cdot {\ell}^{7}\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. *-commutative93.6%

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

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

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

Alternative 5: 97.2% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

    if -3.5 < l < 2.2000000000000002

    1. Initial program 76.1%

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

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

    if 2.2000000000000002 < l

    1. Initial program 98.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 93.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. *-commutative93.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. Simplified93.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 inf 93.6%

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

        \[\leadsto \color{blue}{\left(\left(0.0003968253968253968 \cdot J\right) \cdot {\ell}^{7}\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. *-commutative93.6%

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

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

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

Alternative 6: 93.0% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

    if -3.5 < l < 880

    1. Initial program 75.7%

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

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

    if 880 < l

    1. Initial program 100.0%

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

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

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

Alternative 7: 73.4% accurate, 1.4× speedup?

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

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

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


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

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

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

      \[\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 \]
    5. Taylor expanded in K around inf 75.1%

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

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

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

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

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

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

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

    1. Initial program 87.2%

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

      \[\leadsto \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 \color{blue}{1} + U \]
    7. Taylor expanded in l around inf 80.9%

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

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

Alternative 8: 58.1% accurate, 1.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \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.34499999999999997

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

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

      \[\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 \]
    5. Taylor expanded in K around inf 75.1%

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

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

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

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

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

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

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

    1. Initial program 87.2%

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

      \[\leadsto \left(J \cdot \color{blue}{\left(2 \cdot \ell\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 40.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 \]
    5. Taylor expanded in K around 0 58.9%

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

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

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

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

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

Alternative 9: 55.4% accurate, 2.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.58:\\
\;\;\;\;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 + J \cdot \left(\ell \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.57999999999999996

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

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

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

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

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

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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(2 \cdot \ell\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 41.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 \]
    5. Taylor expanded in K around 0 58.9%

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

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

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

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

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

Alternative 10: 83.1% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.9 \cdot 10^{+20} \lor \neg \left(\ell \leq 1.6 \cdot 10^{+30}\right):\\
\;\;\;\;U + 0.0003968253968253968 \cdot \left(J \cdot {\ell}^{7}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -4.9e20 or 1.59999999999999986e30 < l

    1. Initial program 100.0%

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

      \[\leadsto \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 \color{blue}{1} + U \]
    7. Taylor expanded in l around inf 69.9%

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

    if -4.9e20 < l < 1.59999999999999986e30

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.9 \cdot 10^{+20} \lor \neg \left(\ell \leq 1.6 \cdot 10^{+30}\right):\\ \;\;\;\;U + 0.0003968253968253968 \cdot \left(J \cdot {\ell}^{7}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 83.2% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.9 \cdot 10^{+20} \lor \neg \left(\ell \leq 1.6 \cdot 10^{+30}\right):\\
\;\;\;\;U + 0.0003968253968253968 \cdot \left(J \cdot {\ell}^{7}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -4.9e20 or 1.59999999999999986e30 < l

    1. Initial program 100.0%

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

      \[\leadsto \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 \color{blue}{1} + U \]
    7. Taylor expanded in l around inf 69.9%

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

    if -4.9e20 < l < 1.59999999999999986e30

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

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

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

Alternative 12: 54.0% accurate, 44.6× speedup?

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

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

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

    \[\leadsto \left(J \cdot \color{blue}{\left(2 \cdot \ell\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  4. Taylor expanded in K around 0 43.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 \]
  5. Taylor expanded in K around 0 53.4%

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

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

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

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

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

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

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

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

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

Reproduce

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