Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.5% → 99.6%
Time: 12.9s
Alternatives: 14
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 14 alternatives:

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

Initial Program: 86.5% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% 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 -\infty \lor \neg \left(t\_1 \leq 2 \cdot 10^{-10}\right):\\ \;\;\;\;\left(t\_1 \cdot J\right) \cdot t\_0 + U\\ \mathbf{else}:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\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 (- INFINITY)) (not (<= t_1 2e-10)))
     (+ (* (* t_1 J) t_0) U)
     (+ U (* t_0 (* J (* l 2.0)))))))
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 <= -((double) INFINITY)) || !(t_1 <= 2e-10)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * (l * 2.0)));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 2e-10)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * (l * 2.0)));
	}
	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 <= -math.inf) or not (t_1 <= 2e-10):
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (t_0 * (J * (l * 2.0)))
	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 <= Float64(-Inf)) || !(t_1 <= 2e-10))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0))));
	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 <= -Inf) || ~((t_1 <= 2e-10)))
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (t_0 * (J * (l * 2.0)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 2e-10]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $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 -\infty \lor \neg \left(t\_1 \leq 2 \cdot 10^{-10}\right):\\
\;\;\;\;\left(t\_1 \cdot J\right) \cdot t\_0 + U\\

\mathbf{else}:\\
\;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\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 or 2.00000000000000007e-10 < (-.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 -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.00000000000000007e-10

    1. Initial program 71.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(2 \cdot \ell\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 -\infty \lor \neg \left(e^{\ell} - e^{-\ell} \leq 2 \cdot 10^{-10}\right):\\ \;\;\;\;\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \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 2: 78.2% accurate, 1.0× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (cos.f64 (/.f64 K 2)) < -0.47999999999999998

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

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

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

    if -0.47999999999999998 < (cos.f64 (/.f64 K 2)) < -0.0100000000000000002

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

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

    if -0.0100000000000000002 < (cos.f64 (/.f64 K 2))

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

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

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

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

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

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

        \[\leadsto \left(\left(2 \cdot \left(J \cdot \ell\right)\right) \cdot \cos \left(0.5 \cdot K\right) + \color{blue}{\left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right) \cdot \cos \left(0.5 \cdot K\right)}\right) + U \]
      6. distribute-rgt-out87.8%

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

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

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

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

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

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

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

Alternative 3: 94.9% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := U + \left(J \cdot 0.3333333333333333\right) \cdot \left({\ell}^{3} \cdot \cos \left(K \cdot 0.5\right)\right)\\
t_1 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;\ell \leq -5.7 \cdot 10^{+102}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -122:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;\ell \leq 1.25 \cdot 10^{+102}:\\
\;\;\;\;t\_1 + U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -5.6999999999999999e102 or 1.25e102 < 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 100.0%

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

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

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

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

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

        \[\leadsto \left(\left(2 \cdot \left(J \cdot \ell\right)\right) \cdot \cos \left(0.5 \cdot K\right) + \color{blue}{\left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right) \cdot \cos \left(0.5 \cdot K\right)}\right) + U \]
      6. distribute-rgt-out100.0%

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot K\right) \cdot \left(\ell \cdot \left(2 \cdot J\right) + 0.3333333333333333 \cdot \left({\ell}^{3} \cdot J\right)\right)} + U \]
    6. Taylor expanded in l around inf 100.0%

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

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

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

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

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

    if -5.6999999999999999e102 < l < -122

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in J around inf 81.8%

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

    if -122 < l < 5.8e10

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

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

    if 5.8e10 < l < 1.25e102

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.7 \cdot 10^{+102}:\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot \left({\ell}^{3} \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq -122:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 58000000000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 1.25 \cdot 10^{+102}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot \left({\ell}^{3} \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 87.3% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;\ell \leq -122:\\
\;\;\;\;t\_0\\

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

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


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

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in J around inf 71.9%

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

    if -122 < l < 5.8e10

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

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

    if 5.8e10 < 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 68.5%

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

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

Alternative 5: 87.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -122 \lor \neg \left(\ell \leq 58000000000\right):\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \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 -122.0) (not (<= l 58000000000.0)))
   (* (- (exp l) (exp (- l))) J)
   (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -122.0) || !(l <= 58000000000.0)) {
		tmp = (exp(l) - exp(-l)) * J;
	} 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 <= (-122.0d0)) .or. (.not. (l <= 58000000000.0d0))) then
        tmp = (exp(l) - exp(-l)) * j
    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 <= -122.0) || !(l <= 58000000000.0)) {
		tmp = (Math.exp(l) - Math.exp(-l)) * J;
	} else {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -122.0) or not (l <= 58000000000.0):
		tmp = (math.exp(l) - math.exp(-l)) * J
	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 <= -122.0) || !(l <= 58000000000.0))
		tmp = Float64(Float64(exp(l) - exp(Float64(-l))) * J);
	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 <= -122.0) || ~((l <= 58000000000.0)))
		tmp = (exp(l) - exp(-l)) * J;
	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, -122.0], N[Not[LessEqual[l, 58000000000.0]], $MachinePrecision]], N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $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 -122 \lor \neg \left(\ell \leq 58000000000\right):\\
\;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\

\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 < -122 or 5.8e10 < 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 70.1%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in J around inf 70.1%

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

    if -122 < l < 5.8e10

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -122 \lor \neg \left(\ell \leq 58000000000\right):\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \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 6: 53.9% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -2.4 \cdot 10^{+284} \lor \neg \left(\ell \leq -3 \cdot 10^{+20} \lor \neg \left(\ell \leq 1.3 \cdot 10^{+69}\right) \land \ell \leq 1.55 \cdot 10^{+179}\right):\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;{U}^{-4}\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -2.4e+284)
         (not (or (<= l -3e+20) (and (not (<= l 1.3e+69)) (<= l 1.55e+179)))))
   (+ U (* l (* J 2.0)))
   (pow U -4.0)))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -2.4e+284) || !((l <= -3e+20) || (!(l <= 1.3e+69) && (l <= 1.55e+179)))) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = pow(U, -4.0);
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if ((l <= (-2.4d+284)) .or. (.not. (l <= (-3d+20)) .or. (.not. (l <= 1.3d+69)) .and. (l <= 1.55d+179))) then
        tmp = u + (l * (j * 2.0d0))
    else
        tmp = u ** (-4.0d0)
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -2.4e+284) || !((l <= -3e+20) || (!(l <= 1.3e+69) && (l <= 1.55e+179)))) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = Math.pow(U, -4.0);
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -2.4e+284) or not ((l <= -3e+20) or (not (l <= 1.3e+69) and (l <= 1.55e+179))):
		tmp = U + (l * (J * 2.0))
	else:
		tmp = math.pow(U, -4.0)
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -2.4e+284) || !((l <= -3e+20) || (!(l <= 1.3e+69) && (l <= 1.55e+179))))
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	else
		tmp = U ^ -4.0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -2.4e+284) || ~(((l <= -3e+20) || (~((l <= 1.3e+69)) && (l <= 1.55e+179)))))
		tmp = U + (l * (J * 2.0));
	else
		tmp = U ^ -4.0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -2.4e+284], N[Not[Or[LessEqual[l, -3e+20], And[N[Not[LessEqual[l, 1.3e+69]], $MachinePrecision], LessEqual[l, 1.55e+179]]]], $MachinePrecision]], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[U, -4.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.4 \cdot 10^{+284} \lor \neg \left(\ell \leq -3 \cdot 10^{+20} \lor \neg \left(\ell \leq 1.3 \cdot 10^{+69}\right) \land \ell \leq 1.55 \cdot 10^{+179}\right):\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.4000000000000001e284 or -3e20 < l < 1.3000000000000001e69 or 1.55e179 < l

    1. Initial program 80.9%

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

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

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

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

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

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

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

    if -2.4000000000000001e284 < l < -3e20 or 1.3000000000000001e69 < l < 1.55e179

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.4 \cdot 10^{+284} \lor \neg \left(\ell \leq -3 \cdot 10^{+20} \lor \neg \left(\ell \leq 1.3 \cdot 10^{+69}\right) \land \ell \leq 1.55 \cdot 10^{+179}\right):\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;{U}^{-4}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 53.9% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{if}\;\ell \leq -1 \cdot 10^{+283}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -3 \cdot 10^{+20}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 1.2 \cdot 10^{+71}:\\ \;\;\;\;\mathsf{fma}\left(\ell, J \cdot 2, U\right)\\ \mathbf{elif}\;\ell \leq 7 \cdot 10^{+178}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* l (* J 2.0)))))
   (if (<= l -1e+283)
     t_0
     (if (<= l -3e+20)
       (pow U -4.0)
       (if (<= l 1.2e+71)
         (fma l (* J 2.0) U)
         (if (<= l 7e+178) (pow U -4.0) t_0))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (l * (J * 2.0));
	double tmp;
	if (l <= -1e+283) {
		tmp = t_0;
	} else if (l <= -3e+20) {
		tmp = pow(U, -4.0);
	} else if (l <= 1.2e+71) {
		tmp = fma(l, (J * 2.0), U);
	} else if (l <= 7e+178) {
		tmp = pow(U, -4.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(U + Float64(l * Float64(J * 2.0)))
	tmp = 0.0
	if (l <= -1e+283)
		tmp = t_0;
	elseif (l <= -3e+20)
		tmp = U ^ -4.0;
	elseif (l <= 1.2e+71)
		tmp = fma(l, Float64(J * 2.0), U);
	elseif (l <= 7e+178)
		tmp = U ^ -4.0;
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1e+283], t$95$0, If[LessEqual[l, -3e+20], N[Power[U, -4.0], $MachinePrecision], If[LessEqual[l, 1.2e+71], N[(l * N[(J * 2.0), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[l, 7e+178], N[Power[U, -4.0], $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\ell \leq 1.2 \cdot 10^{+71}:\\
\;\;\;\;\mathsf{fma}\left(\ell, J \cdot 2, U\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -9.99999999999999955e282 or 7.00000000000000001e178 < 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 44.3%

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

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

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

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

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

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

    if -9.99999999999999955e282 < l < -3e20 or 1.1999999999999999e71 < l < 7.00000000000000001e178

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

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

    if -3e20 < l < 1.1999999999999999e71

    1. Initial program 75.1%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\ell, J \cdot 2, U\right)} \]
    6. Simplified77.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1 \cdot 10^{+283}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{elif}\;\ell \leq -3 \cdot 10^{+20}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 1.2 \cdot 10^{+71}:\\ \;\;\;\;\mathsf{fma}\left(\ell, J \cdot 2, U\right)\\ \mathbf{elif}\;\ell \leq 7 \cdot 10^{+178}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 78.5% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -18000 \lor \neg \left(\ell \leq 2.2 \cdot 10^{+78}\right):\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot {\ell}^{3}\\ \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 -18000.0) (not (<= l 2.2e+78)))
   (+ U (* (* J 0.3333333333333333) (pow l 3.0)))
   (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -18000.0) || !(l <= 2.2e+78)) {
		tmp = U + ((J * 0.3333333333333333) * pow(l, 3.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 <= (-18000.0d0)) .or. (.not. (l <= 2.2d+78))) then
        tmp = u + ((j * 0.3333333333333333d0) * (l ** 3.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 <= -18000.0) || !(l <= 2.2e+78)) {
		tmp = U + ((J * 0.3333333333333333) * Math.pow(l, 3.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 <= -18000.0) or not (l <= 2.2e+78):
		tmp = U + ((J * 0.3333333333333333) * math.pow(l, 3.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 <= -18000.0) || !(l <= 2.2e+78))
		tmp = Float64(U + Float64(Float64(J * 0.3333333333333333) * (l ^ 3.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 <= -18000.0) || ~((l <= 2.2e+78)))
		tmp = U + ((J * 0.3333333333333333) * (l ^ 3.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, -18000.0], N[Not[LessEqual[l, 2.2e+78]], $MachinePrecision]], N[(U + N[(N[(J * 0.3333333333333333), $MachinePrecision] * N[Power[l, 3.0], $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 -18000 \lor \neg \left(\ell \leq 2.2 \cdot 10^{+78}\right):\\
\;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot {\ell}^{3}\\

\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 < -18000 or 2.20000000000000014e78 < l

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto \left(\left(2 \cdot \left(J \cdot \ell\right)\right) \cdot \cos \left(0.5 \cdot K\right) + \color{blue}{\left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right) \cdot \cos \left(0.5 \cdot K\right)}\right) + U \]
      6. distribute-rgt-out84.5%

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot K\right) \cdot \left(\ell \cdot \left(2 \cdot J\right) + 0.3333333333333333 \cdot \left({\ell}^{3} \cdot J\right)\right)} + U \]
    6. Taylor expanded in l around inf 84.5%

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

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

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

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

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

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

    if -18000 < l < 2.20000000000000014e78

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -18000 \lor \neg \left(\ell \leq 2.2 \cdot 10^{+78}\right):\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot {\ell}^{3}\\ \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 9: 78.5% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -120000 \lor \neg \left(\ell \leq 2.25 \cdot 10^{+78}\right):\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot {\ell}^{3}\\ \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 -120000.0) (not (<= l 2.25e+78)))
   (+ U (* (* J 0.3333333333333333) (pow l 3.0)))
   (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -120000.0) || !(l <= 2.25e+78)) {
		tmp = U + ((J * 0.3333333333333333) * pow(l, 3.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 <= (-120000.0d0)) .or. (.not. (l <= 2.25d+78))) then
        tmp = u + ((j * 0.3333333333333333d0) * (l ** 3.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 <= -120000.0) || !(l <= 2.25e+78)) {
		tmp = U + ((J * 0.3333333333333333) * Math.pow(l, 3.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 <= -120000.0) or not (l <= 2.25e+78):
		tmp = U + ((J * 0.3333333333333333) * math.pow(l, 3.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 <= -120000.0) || !(l <= 2.25e+78))
		tmp = Float64(U + Float64(Float64(J * 0.3333333333333333) * (l ^ 3.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 <= -120000.0) || ~((l <= 2.25e+78)))
		tmp = U + ((J * 0.3333333333333333) * (l ^ 3.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, -120000.0], N[Not[LessEqual[l, 2.25e+78]], $MachinePrecision]], N[(U + N[(N[(J * 0.3333333333333333), $MachinePrecision] * N[Power[l, 3.0], $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 -120000 \lor \neg \left(\ell \leq 2.25 \cdot 10^{+78}\right):\\
\;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot {\ell}^{3}\\

\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 < -1.2e5 or 2.25e78 < l

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto \left(\left(2 \cdot \left(J \cdot \ell\right)\right) \cdot \cos \left(0.5 \cdot K\right) + \color{blue}{\left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right) \cdot \cos \left(0.5 \cdot K\right)}\right) + U \]
      6. distribute-rgt-out84.5%

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot K\right) \cdot \left(\ell \cdot \left(2 \cdot J\right) + 0.3333333333333333 \cdot \left({\ell}^{3} \cdot J\right)\right)} + U \]
    6. Taylor expanded in l around inf 84.5%

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

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

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

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

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

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

    if -1.2e5 < l < 2.25e78

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -120000 \lor \neg \left(\ell \leq 2.25 \cdot 10^{+78}\right):\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot {\ell}^{3}\\ \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 10: 72.7% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -2.5 \lor \neg \left(\ell \leq 0.00017\right):\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot {\ell}^{3}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\ell, J \cdot 2, U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -2.5) (not (<= l 0.00017)))
   (+ U (* (* J 0.3333333333333333) (pow l 3.0)))
   (fma l (* J 2.0) U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -2.5) || !(l <= 0.00017)) {
		tmp = U + ((J * 0.3333333333333333) * pow(l, 3.0));
	} else {
		tmp = fma(l, (J * 2.0), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -2.5) || !(l <= 0.00017))
		tmp = Float64(U + Float64(Float64(J * 0.3333333333333333) * (l ^ 3.0)));
	else
		tmp = fma(l, Float64(J * 2.0), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -2.5], N[Not[LessEqual[l, 0.00017]], $MachinePrecision]], N[(U + N[(N[(J * 0.3333333333333333), $MachinePrecision] * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(l * N[(J * 2.0), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.5 \lor \neg \left(\ell \leq 0.00017\right):\\
\;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot {\ell}^{3}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.5 or 1.7e-4 < 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 76.6%

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

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

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

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

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

        \[\leadsto \left(\left(2 \cdot \left(J \cdot \ell\right)\right) \cdot \cos \left(0.5 \cdot K\right) + \color{blue}{\left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right) \cdot \cos \left(0.5 \cdot K\right)}\right) + U \]
      6. distribute-rgt-out76.6%

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot K\right) \cdot \left(\ell \cdot \left(2 \cdot J\right) + 0.3333333333333333 \cdot \left({\ell}^{3} \cdot J\right)\right)} + U \]
    6. Taylor expanded in l around inf 76.6%

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

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

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

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

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

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

    if -2.5 < l < 1.7e-4

    1. Initial program 71.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}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Taylor expanded in K around 0 87.6%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\ell, J \cdot 2, U\right)} \]
    6. Simplified87.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.5 \lor \neg \left(\ell \leq 0.00017\right):\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot {\ell}^{3}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\ell, J \cdot 2, U\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 42.1% accurate, 23.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.3e5 or 780 < l

    1. Initial program 100.0%

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

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

    if -2.3e5 < l < 780

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

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

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

Alternative 12: 54.0% accurate, 44.6× speedup?

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

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

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

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

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

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

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

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

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

Alternative 13: 2.7% accurate, 312.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 86.9%

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

    \[\leadsto \color{blue}{\frac{U}{U}} \]
  4. Step-by-step derivation
    1. *-inverses2.7%

      \[\leadsto \color{blue}{1} \]
  5. Simplified2.7%

    \[\leadsto \color{blue}{1} \]
  6. Final simplification2.7%

    \[\leadsto 1 \]
  7. Add Preprocessing

Alternative 14: 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 86.9%

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

    \[\leadsto \color{blue}{U} \]
  4. Final simplification34.0%

    \[\leadsto U \]
  5. Add Preprocessing

Reproduce

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