Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.8% → 99.5%
Time: 11.2s
Alternatives: 12
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 12 alternatives:

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

Initial Program: 86.8% accurate, 1.0× speedup?

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

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

Alternative 1: 99.5% accurate, 0.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;U + \left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(\ell \cdot 2\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 0.0 < (-.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))) < 0.0

    1. Initial program 75.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}{\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + 2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

        \[\leadsto \ell \cdot \left(\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot \left(0.3333333333333333 \cdot {\ell}^{2}\right) + \color{blue}{\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot 2}\right) + U \]
      7. distribute-lft-out99.9%

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

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

      \[\leadsto \color{blue}{\ell \cdot \left(\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\right)\right)} + U \]
    6. 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 \]
    7. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

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

Alternative 2: 95.1% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;\ell \leq -8000:\\
\;\;\;\;t\_2\\

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

\mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;t\_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.10000000000000001e102 or 5.60000000000000037e102 < 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 \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 \]
    4. 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 \]
    5. Step-by-step derivation
      1. *-commutative100.0%

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

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

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

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

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

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

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

    if -2.10000000000000001e102 < l < -8e3 or 1.3e-22 < l < 5.60000000000000037e102

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

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

    if -8e3 < l < 1.3e-22

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

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

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

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

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

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

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

        \[\leadsto \ell \cdot \left(\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot \left(0.3333333333333333 \cdot {\ell}^{2}\right) + \color{blue}{\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot 2}\right) + U \]
      7. distribute-lft-out99.2%

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 78.7% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.5 < (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 88.1%

      \[\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 \]
    4. Taylor expanded in K around 0 85.6%

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
    5. Taylor expanded in U around inf 88.7%

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

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

Alternative 4: 78.2% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.5 < (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 88.1%

      \[\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 \]
    4. Taylor expanded in K around 0 85.6%

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

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

Alternative 5: 86.9% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -8000 \lor \neg \left(\ell \leq 1.3 \cdot 10^{-22}\right):\\
\;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -8e3 or 1.3e-22 < 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 69.9%

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

    if -8e3 < l < 1.3e-22

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

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

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

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

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

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

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

        \[\leadsto \ell \cdot \left(\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot \left(0.3333333333333333 \cdot {\ell}^{2}\right) + \color{blue}{\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot 2}\right) + U \]
      7. distribute-lft-out99.2%

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 71.7% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{if}\;\ell \leq -2.5 \cdot 10^{+39}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 1050:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 2.8 \cdot 10^{+92}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* 0.3333333333333333 (* J (pow l 3.0))))))
   (if (<= l -2.5e+39)
     t_0
     (if (<= l 1050.0)
       (+ U (* J (* l 2.0)))
       (if (<= l 2.8e+92) (pow U -3.0) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (0.3333333333333333 * (J * pow(l, 3.0)));
	double tmp;
	if (l <= -2.5e+39) {
		tmp = t_0;
	} else if (l <= 1050.0) {
		tmp = U + (J * (l * 2.0));
	} else if (l <= 2.8e+92) {
		tmp = pow(U, -3.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = u + (0.3333333333333333d0 * (j * (l ** 3.0d0)))
    if (l <= (-2.5d+39)) then
        tmp = t_0
    else if (l <= 1050.0d0) then
        tmp = u + (j * (l * 2.0d0))
    else if (l <= 2.8d+92) then
        tmp = u ** (-3.0d0)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
	double tmp;
	if (l <= -2.5e+39) {
		tmp = t_0;
	} else if (l <= 1050.0) {
		tmp = U + (J * (l * 2.0));
	} else if (l <= 2.8e+92) {
		tmp = Math.pow(U, -3.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (0.3333333333333333 * (J * math.pow(l, 3.0)))
	tmp = 0
	if l <= -2.5e+39:
		tmp = t_0
	elif l <= 1050.0:
		tmp = U + (J * (l * 2.0))
	elif l <= 2.8e+92:
		tmp = math.pow(U, -3.0)
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))))
	tmp = 0.0
	if (l <= -2.5e+39)
		tmp = t_0;
	elseif (l <= 1050.0)
		tmp = Float64(U + Float64(J * Float64(l * 2.0)));
	elseif (l <= 2.8e+92)
		tmp = U ^ -3.0;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (0.3333333333333333 * (J * (l ^ 3.0)));
	tmp = 0.0;
	if (l <= -2.5e+39)
		tmp = t_0;
	elseif (l <= 1050.0)
		tmp = U + (J * (l * 2.0));
	elseif (l <= 2.8e+92)
		tmp = U ^ -3.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.5e+39], t$95$0, If[LessEqual[l, 1050.0], N[(U + N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.8e+92], N[Power[U, -3.0], $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\mathbf{if}\;\ell \leq -2.5 \cdot 10^{+39}:\\
\;\;\;\;t\_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.50000000000000008e39 or 2.80000000000000001e92 < 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 89.9%

      \[\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 \]
    4. Taylor expanded in l around inf 89.9%

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

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

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

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

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

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

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

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

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

    if -2.50000000000000008e39 < l < 1050

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

      \[\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 \]
    4. Taylor expanded in K around 0 86.2%

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
    5. Taylor expanded in l around 0 86.2%

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

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

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

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

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

    if 1050 < l < 2.80000000000000001e92

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.5 \cdot 10^{+39}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 1050:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 2.8 \cdot 10^{+92}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{else}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 74.3% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;J \leq -3.5 \cdot 10^{+123} \lor \neg \left(J \leq 1.05 \cdot 10^{+61}\right):\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < -3.5e123 or 1.0500000000000001e61 < J

    1. Initial program 71.9%

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

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

    if -3.5e123 < J < 1.0500000000000001e61

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

      \[\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 \]
    4. Taylor expanded in l around inf 80.0%

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

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

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

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

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

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

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

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

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

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

Alternative 8: 74.3% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ \mathbf{if}\;J \leq -3.4 \cdot 10^{+123}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t\_0\right)\right)\\ \mathbf{elif}\;J \leq 4.2 \cdot 10^{+59}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot t\_0\right) \cdot \left(\ell \cdot 2\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (* K 0.5))))
   (if (<= J -3.4e+123)
     (+ U (* 2.0 (* J (* l t_0))))
     (if (<= J 4.2e+59)
       (+ U (* 0.3333333333333333 (* J (pow l 3.0))))
       (+ U (* (* J t_0) (* l 2.0)))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K * 0.5));
	double tmp;
	if (J <= -3.4e+123) {
		tmp = U + (2.0 * (J * (l * t_0)));
	} else if (J <= 4.2e+59) {
		tmp = U + (0.3333333333333333 * (J * pow(l, 3.0)));
	} else {
		tmp = U + ((J * t_0) * (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) :: t_0
    real(8) :: tmp
    t_0 = cos((k * 0.5d0))
    if (j <= (-3.4d+123)) then
        tmp = u + (2.0d0 * (j * (l * t_0)))
    else if (j <= 4.2d+59) then
        tmp = u + (0.3333333333333333d0 * (j * (l ** 3.0d0)))
    else
        tmp = u + ((j * t_0) * (l * 2.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 * 0.5));
	double tmp;
	if (J <= -3.4e+123) {
		tmp = U + (2.0 * (J * (l * t_0)));
	} else if (J <= 4.2e+59) {
		tmp = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
	} else {
		tmp = U + ((J * t_0) * (l * 2.0));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K * 0.5))
	tmp = 0
	if J <= -3.4e+123:
		tmp = U + (2.0 * (J * (l * t_0)))
	elif J <= 4.2e+59:
		tmp = U + (0.3333333333333333 * (J * math.pow(l, 3.0)))
	else:
		tmp = U + ((J * t_0) * (l * 2.0))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K * 0.5))
	tmp = 0.0
	if (J <= -3.4e+123)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * t_0))));
	elseif (J <= 4.2e+59)
		tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))));
	else
		tmp = Float64(U + Float64(Float64(J * t_0) * Float64(l * 2.0)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K * 0.5));
	tmp = 0.0;
	if (J <= -3.4e+123)
		tmp = U + (2.0 * (J * (l * t_0)));
	elseif (J <= 4.2e+59)
		tmp = U + (0.3333333333333333 * (J * (l ^ 3.0)));
	else
		tmp = U + ((J * t_0) * (l * 2.0));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[J, -3.4e+123], N[(U + N[(2.0 * N[(J * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 4.2e+59], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(J * t$95$0), $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;J \leq 4.2 \cdot 10^{+59}:\\
\;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -3.40000000000000001e123

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

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

    if -3.40000000000000001e123 < J < 4.19999999999999968e59

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

      \[\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 \]
    4. Taylor expanded in l around inf 80.0%

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

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

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

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

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

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

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

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

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

    if 4.19999999999999968e59 < J

    1. Initial program 75.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 42.7% accurate, 23.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.35e41 or 1.2e10 < 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-rr17.9%

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

    if -1.35e41 < l < 1.2e10

    1. Initial program 77.5%

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

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

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

Alternative 10: 54.4% 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.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 88.0%

    \[\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 \]
  4. Taylor expanded in K around 0 69.8%

    \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
  5. Taylor expanded in l around 0 54.9%

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

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

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

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

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

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

Alternative 11: 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 88.1%

    \[\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 12: 37.2% 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.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 J around 0 38.1%

    \[\leadsto \color{blue}{U} \]
  4. Final simplification38.1%

    \[\leadsto U \]
  5. Add Preprocessing

Reproduce

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