Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 85.7% → 99.2%
Time: 10.2s
Alternatives: 21
Speedup: 2.6×

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 21 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: 85.7% 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.2% accurate, 0.5× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

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

    1. Initial program 73.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. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

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

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

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

    if 1.0000000000000001e-15 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

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

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

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

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

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

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

Alternative 2: 95.9% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -5.2:\\
\;\;\;\;U + J \cdot \left(27 - t\_1\right)\\

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

\mathbf{elif}\;\ell \leq 2.6 \cdot 10^{+77}:\\
\;\;\;\;U + \left(e^{\ell} - t\_1\right) \cdot J\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if l < -1.25e106

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

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

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

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

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

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

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

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

    if -1.25e106 < l < -5.20000000000000018

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative80.0%

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Applied egg-rr80.0%

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

    if -5.20000000000000018 < l < 1.14e8

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

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

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

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

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

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

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

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

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

    if 1.14e8 < l < 2.6000000000000002e77

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative76.5%

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

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

    if 2.6000000000000002e77 < 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 \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. neg-mul-1100.0%

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

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

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

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

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

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

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

Alternative 3: 97.5% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -10.5:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.39999999999999996e106

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

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

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

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

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

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

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

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

    if -1.39999999999999996e106 < l < -10.5

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative80.0%

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Applied egg-rr80.0%

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

    if -10.5 < l < 5.60000000000000031e-10

    1. Initial program 73.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. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

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

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

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

    if 5.60000000000000031e-10 < 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 \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. neg-mul-1100.0%

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

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

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

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

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

Alternative 4: 95.9% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;\ell \leq -1.25 \cdot 10^{+106}:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot 0.16666666666666666\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -4.2:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 114000000:\\ \;\;\;\;U + \left(\ell \cdot 2\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq 2.6 \cdot 10^{+77}:\\ \;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot \left(0.16666666666666666 + \ell \cdot 0.041666666666666664\right)\right)\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= l -1.25e+106)
     (+ U (* t_0 (* J (* l (+ 2.0 (* l (+ 0.5 (* l 0.16666666666666666))))))))
     (if (<= l -4.2)
       (+ U (* J (- 27.0 (exp (- l)))))
       (if (<= l 114000000.0)
         (+ U (* (* l 2.0) (* J (cos (* K 0.5)))))
         (if (<= l 2.6e+77)
           (+ U (* J (+ l (expm1 l))))
           (+
            U
            (*
             t_0
             (*
              J
              (*
               l
               (+
                2.0
                (*
                 l
                 (+
                  0.5
                  (*
                   l
                   (+
                    0.16666666666666666
                    (* l 0.041666666666666664))))))))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (l <= -1.25e+106) {
		tmp = U + (t_0 * (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666)))))));
	} else if (l <= -4.2) {
		tmp = U + (J * (27.0 - exp(-l)));
	} else if (l <= 114000000.0) {
		tmp = U + ((l * 2.0) * (J * cos((K * 0.5))));
	} else if (l <= 2.6e+77) {
		tmp = U + (J * (l + expm1(l)));
	} else {
		tmp = U + (t_0 * (J * (l * (2.0 + (l * (0.5 + (l * (0.16666666666666666 + (l * 0.041666666666666664)))))))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (l <= -1.25e+106) {
		tmp = U + (t_0 * (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666)))))));
	} else if (l <= -4.2) {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	} else if (l <= 114000000.0) {
		tmp = U + ((l * 2.0) * (J * Math.cos((K * 0.5))));
	} else if (l <= 2.6e+77) {
		tmp = U + (J * (l + Math.expm1(l)));
	} else {
		tmp = U + (t_0 * (J * (l * (2.0 + (l * (0.5 + (l * (0.16666666666666666 + (l * 0.041666666666666664)))))))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if l <= -1.25e+106:
		tmp = U + (t_0 * (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666)))))))
	elif l <= -4.2:
		tmp = U + (J * (27.0 - math.exp(-l)))
	elif l <= 114000000.0:
		tmp = U + ((l * 2.0) * (J * math.cos((K * 0.5))))
	elif l <= 2.6e+77:
		tmp = U + (J * (l + math.expm1(l)))
	else:
		tmp = U + (t_0 * (J * (l * (2.0 + (l * (0.5 + (l * (0.16666666666666666 + (l * 0.041666666666666664)))))))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (l <= -1.25e+106)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * Float64(2.0 + Float64(l * Float64(0.5 + Float64(l * 0.16666666666666666))))))));
	elseif (l <= -4.2)
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	elseif (l <= 114000000.0)
		tmp = Float64(U + Float64(Float64(l * 2.0) * Float64(J * cos(Float64(K * 0.5)))));
	elseif (l <= 2.6e+77)
		tmp = Float64(U + Float64(J * Float64(l + expm1(l))));
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * Float64(2.0 + Float64(l * Float64(0.5 + Float64(l * Float64(0.16666666666666666 + Float64(l * 0.041666666666666664))))))))));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -1.25e+106], N[(U + N[(t$95$0 * N[(J * N[(l * N[(2.0 + N[(l * N[(0.5 + N[(l * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -4.2], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 114000000.0], N[(U + N[(N[(l * 2.0), $MachinePrecision] * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.6e+77], N[(U + N[(J * N[(l + N[(Exp[l] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(l * N[(2.0 + N[(l * N[(0.5 + N[(l * N[(0.16666666666666666 + N[(l * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -4.2:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

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

\mathbf{elif}\;\ell \leq 2.6 \cdot 10^{+77}:\\
\;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if l < -1.25e106

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

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

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

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

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

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

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

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

    if -1.25e106 < l < -4.20000000000000018

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative80.0%

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Applied egg-rr80.0%

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

    if -4.20000000000000018 < l < 1.14e8

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

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

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

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

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

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

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

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

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

    if 1.14e8 < l < 2.6000000000000002e77

    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 \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. neg-mul-1100.0%

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\left(\ell + e^{\ell}\right) - 1\right)} + U \]
    7. Step-by-step derivation
      1. associate--l+76.5%

        \[\leadsto J \cdot \color{blue}{\left(\ell + \left(e^{\ell} - 1\right)\right)} + U \]
      2. expm1-define76.5%

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

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

    if 2.6000000000000002e77 < 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 \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. neg-mul-1100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.25 \cdot 10^{+106}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot 0.16666666666666666\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -4.2:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 114000000:\\ \;\;\;\;U + \left(\ell \cdot 2\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq 2.6 \cdot 10^{+77}:\\ \;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot \left(0.16666666666666666 + \ell \cdot 0.041666666666666664\right)\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 95.5% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot 0.16666666666666666\right)\right)\right)\right)\\ \mathbf{if}\;\ell \leq -1.4 \cdot 10^{+106}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -9.2:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 114000000:\\ \;\;\;\;U + \left(\ell \cdot 2\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq 1.05 \cdot 10^{+103}:\\ \;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0
         (+
          U
          (*
           (cos (/ K 2.0))
           (* J (* l (+ 2.0 (* l (+ 0.5 (* l 0.16666666666666666))))))))))
   (if (<= l -1.4e+106)
     t_0
     (if (<= l -9.2)
       (+ U (* J (- 27.0 (exp (- l)))))
       (if (<= l 114000000.0)
         (+ U (* (* l 2.0) (* J (cos (* K 0.5)))))
         (if (<= l 1.05e+103) (+ U (* J (+ l (expm1 l)))) t_0))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (cos((K / 2.0)) * (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666)))))));
	double tmp;
	if (l <= -1.4e+106) {
		tmp = t_0;
	} else if (l <= -9.2) {
		tmp = U + (J * (27.0 - exp(-l)));
	} else if (l <= 114000000.0) {
		tmp = U + ((l * 2.0) * (J * cos((K * 0.5))));
	} else if (l <= 1.05e+103) {
		tmp = U + (J * (l + expm1(l)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (Math.cos((K / 2.0)) * (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666)))))));
	double tmp;
	if (l <= -1.4e+106) {
		tmp = t_0;
	} else if (l <= -9.2) {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	} else if (l <= 114000000.0) {
		tmp = U + ((l * 2.0) * (J * Math.cos((K * 0.5))));
	} else if (l <= 1.05e+103) {
		tmp = U + (J * (l + Math.expm1(l)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (math.cos((K / 2.0)) * (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666)))))))
	tmp = 0
	if l <= -1.4e+106:
		tmp = t_0
	elif l <= -9.2:
		tmp = U + (J * (27.0 - math.exp(-l)))
	elif l <= 114000000.0:
		tmp = U + ((l * 2.0) * (J * math.cos((K * 0.5))))
	elif l <= 1.05e+103:
		tmp = U + (J * (l + math.expm1(l)))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * Float64(2.0 + Float64(l * Float64(0.5 + Float64(l * 0.16666666666666666))))))))
	tmp = 0.0
	if (l <= -1.4e+106)
		tmp = t_0;
	elseif (l <= -9.2)
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	elseif (l <= 114000000.0)
		tmp = Float64(U + Float64(Float64(l * 2.0) * Float64(J * cos(Float64(K * 0.5)))));
	elseif (l <= 1.05e+103)
		tmp = Float64(U + Float64(J * Float64(l + expm1(l))));
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * N[(2.0 + N[(l * N[(0.5 + N[(l * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.4e+106], t$95$0, If[LessEqual[l, -9.2], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 114000000.0], N[(U + N[(N[(l * 2.0), $MachinePrecision] * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.05e+103], N[(U + N[(J * N[(l + N[(Exp[l] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -9.2:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

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

\mathbf{elif}\;\ell \leq 1.05 \cdot 10^{+103}:\\
\;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.39999999999999996e106 or 1.0500000000000001e103 < 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 68.0%

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

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

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

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

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

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

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

    if -1.39999999999999996e106 < l < -9.1999999999999993

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative80.0%

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Applied egg-rr80.0%

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

    if -9.1999999999999993 < l < 1.14e8

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

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

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

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

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

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

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

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

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

    if 1.14e8 < l < 1.0500000000000001e103

    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 \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. neg-mul-1100.0%

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\left(\ell + e^{\ell}\right) - 1\right)} + U \]
    7. Step-by-step derivation
      1. associate--l+79.2%

        \[\leadsto J \cdot \color{blue}{\left(\ell + \left(e^{\ell} - 1\right)\right)} + U \]
      2. expm1-define79.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.4 \cdot 10^{+106}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot 0.16666666666666666\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -9.2:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 114000000:\\ \;\;\;\;U + \left(\ell \cdot 2\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq 1.05 \cdot 10^{+103}:\\ \;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot 0.16666666666666666\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 90.5% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -4.6:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 114000000:\\ \;\;\;\;U + \left(\ell \cdot 2\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+154}:\\ \;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot 0.5\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -4.6)
   (+ U (* J (- 27.0 (exp (- l)))))
   (if (<= l 114000000.0)
     (+ U (* (* l 2.0) (* J (cos (* K 0.5)))))
     (if (<= l 1.9e+154)
       (+ U (* J (+ l (expm1 l))))
       (+ U (* (cos (/ K 2.0)) (* J (* l (+ 2.0 (* l 0.5))))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -4.6) {
		tmp = U + (J * (27.0 - exp(-l)));
	} else if (l <= 114000000.0) {
		tmp = U + ((l * 2.0) * (J * cos((K * 0.5))));
	} else if (l <= 1.9e+154) {
		tmp = U + (J * (l + expm1(l)));
	} else {
		tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + (l * 0.5)))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -4.6) {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	} else if (l <= 114000000.0) {
		tmp = U + ((l * 2.0) * (J * Math.cos((K * 0.5))));
	} else if (l <= 1.9e+154) {
		tmp = U + (J * (l + Math.expm1(l)));
	} else {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * (2.0 + (l * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -4.6:
		tmp = U + (J * (27.0 - math.exp(-l)))
	elif l <= 114000000.0:
		tmp = U + ((l * 2.0) * (J * math.cos((K * 0.5))))
	elif l <= 1.9e+154:
		tmp = U + (J * (l + math.expm1(l)))
	else:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * (2.0 + (l * 0.5)))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -4.6)
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	elseif (l <= 114000000.0)
		tmp = Float64(U + Float64(Float64(l * 2.0) * Float64(J * cos(Float64(K * 0.5)))));
	elseif (l <= 1.9e+154)
		tmp = Float64(U + Float64(J * Float64(l + expm1(l))));
	else
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * Float64(2.0 + Float64(l * 0.5))))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, -4.6], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 114000000.0], N[(U + N[(N[(l * 2.0), $MachinePrecision] * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.9e+154], N[(U + N[(J * N[(l + N[(Exp[l] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * N[(2.0 + N[(l * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.6:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

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

\mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+154}:\\
\;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\

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


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

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Applied egg-rr73.2%

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

    if -4.5999999999999996 < l < 1.14e8

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

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

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

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

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

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

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

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

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

    if 1.14e8 < l < 1.8999999999999999e154

    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 \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. neg-mul-1100.0%

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\left(\ell + e^{\ell}\right) - 1\right)} + U \]
    7. Step-by-step derivation
      1. associate--l+83.3%

        \[\leadsto J \cdot \color{blue}{\left(\ell + \left(e^{\ell} - 1\right)\right)} + U \]
      2. expm1-define83.3%

        \[\leadsto J \cdot \left(\ell + \color{blue}{\mathsf{expm1}\left(\ell\right)}\right) + U \]
    8. Simplified83.3%

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

    if 1.8999999999999999e154 < 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 \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. neg-mul-1100.0%

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

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

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

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

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

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

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

Alternative 7: 87.2% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -5.2:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 114000000:\\ \;\;\;\;U + \left(\ell \cdot 2\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -5.2)
   (+ U (* J (- 27.0 (exp (- l)))))
   (if (<= l 114000000.0)
     (+ U (* (* l 2.0) (* J (cos (* K 0.5)))))
     (+ U (* J (+ l (expm1 l)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -5.2) {
		tmp = U + (J * (27.0 - exp(-l)));
	} else if (l <= 114000000.0) {
		tmp = U + ((l * 2.0) * (J * cos((K * 0.5))));
	} else {
		tmp = U + (J * (l + expm1(l)));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -5.2) {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	} else if (l <= 114000000.0) {
		tmp = U + ((l * 2.0) * (J * Math.cos((K * 0.5))));
	} else {
		tmp = U + (J * (l + Math.expm1(l)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -5.2:
		tmp = U + (J * (27.0 - math.exp(-l)))
	elif l <= 114000000.0:
		tmp = U + ((l * 2.0) * (J * math.cos((K * 0.5))))
	else:
		tmp = U + (J * (l + math.expm1(l)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -5.2)
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	elseif (l <= 114000000.0)
		tmp = Float64(U + Float64(Float64(l * 2.0) * Float64(J * cos(Float64(K * 0.5)))));
	else
		tmp = Float64(U + Float64(J * Float64(l + expm1(l))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, -5.2], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 114000000.0], N[(U + N[(N[(l * 2.0), $MachinePrecision] * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l + N[(Exp[l] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.2:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

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

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


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

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

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

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Applied egg-rr73.2%

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

    if -5.20000000000000018 < l < 1.14e8

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

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

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

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

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

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

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

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

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

    if 1.14e8 < 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 \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. neg-mul-1100.0%

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\left(\ell + e^{\ell}\right) - 1\right)} + U \]
    7. Step-by-step derivation
      1. associate--l+81.5%

        \[\leadsto J \cdot \color{blue}{\left(\ell + \left(e^{\ell} - 1\right)\right)} + U \]
      2. expm1-define81.5%

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

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

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

Alternative 8: 87.2% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -4.9:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 114000000:\\ \;\;\;\;U + J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -4.9)
   (+ U (* J (- 27.0 (exp (- l)))))
   (if (<= l 114000000.0)
     (+ U (* J (* 2.0 (* l (cos (* K 0.5))))))
     (+ U (* J (+ l (expm1 l)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -4.9) {
		tmp = U + (J * (27.0 - exp(-l)));
	} else if (l <= 114000000.0) {
		tmp = U + (J * (2.0 * (l * cos((K * 0.5)))));
	} else {
		tmp = U + (J * (l + expm1(l)));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -4.9) {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	} else if (l <= 114000000.0) {
		tmp = U + (J * (2.0 * (l * Math.cos((K * 0.5)))));
	} else {
		tmp = U + (J * (l + Math.expm1(l)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -4.9:
		tmp = U + (J * (27.0 - math.exp(-l)))
	elif l <= 114000000.0:
		tmp = U + (J * (2.0 * (l * math.cos((K * 0.5)))))
	else:
		tmp = U + (J * (l + math.expm1(l)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -4.9)
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	elseif (l <= 114000000.0)
		tmp = Float64(U + Float64(J * Float64(2.0 * Float64(l * cos(Float64(K * 0.5))))));
	else
		tmp = Float64(U + Float64(J * Float64(l + expm1(l))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, -4.9], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 114000000.0], N[(U + N[(J * N[(2.0 * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l + N[(Exp[l] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.9:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

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

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


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

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

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

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Applied egg-rr73.2%

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

    if -4.9000000000000004 < l < 1.14e8

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

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

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

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

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

    if 1.14e8 < 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 \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. neg-mul-1100.0%

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\left(\ell + e^{\ell}\right) - 1\right)} + U \]
    7. Step-by-step derivation
      1. associate--l+81.5%

        \[\leadsto J \cdot \color{blue}{\left(\ell + \left(e^{\ell} - 1\right)\right)} + U \]
      2. expm1-define81.5%

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

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

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

Alternative 9: 80.4% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -2.45:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -2.45)
   (+ U (* J (- 27.0 (exp (- l)))))
   (+ U (* J (+ l (expm1 l))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -2.45) {
		tmp = U + (J * (27.0 - exp(-l)));
	} else {
		tmp = U + (J * (l + expm1(l)));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -2.45) {
		tmp = U + (J * (27.0 - Math.exp(-l)));
	} else {
		tmp = U + (J * (l + Math.expm1(l)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -2.45:
		tmp = U + (J * (27.0 - math.exp(-l)))
	else:
		tmp = U + (J * (l + math.expm1(l)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -2.45)
		tmp = Float64(U + Float64(J * Float64(27.0 - exp(Float64(-l)))));
	else
		tmp = Float64(U + Float64(J * Float64(l + expm1(l))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, -2.45], N[(U + N[(J * N[(27.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l + N[(Exp[l] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.45:\\
\;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\

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


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

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

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

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Applied egg-rr73.2%

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

    if -2.4500000000000002 < l

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

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

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\left(\ell + e^{\ell}\right) - 1\right)} + U \]
    7. Step-by-step derivation
      1. associate--l+77.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.45:\\ \;\;\;\;U + J \cdot \left(27 - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 75.7% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 114000000:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot 0.16666666666666666\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l 114000000.0)
   (+ U (* J (* l (+ 2.0 (* l (+ 0.5 (* l 0.16666666666666666)))))))
   (+ U (* J (+ l (expm1 l))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 114000000.0) {
		tmp = U + (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666))))));
	} else {
		tmp = U + (J * (l + expm1(l)));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 114000000.0) {
		tmp = U + (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666))))));
	} else {
		tmp = U + (J * (l + Math.expm1(l)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= 114000000.0:
		tmp = U + (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666))))))
	else:
		tmp = U + (J * (l + math.expm1(l)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= 114000000.0)
		tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(l * Float64(0.5 + Float64(l * 0.16666666666666666)))))));
	else
		tmp = Float64(U + Float64(J * Float64(l + expm1(l))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, 114000000.0], N[(U + N[(J * N[(l * N[(2.0 + N[(l * N[(0.5 + N[(l * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l + N[(Exp[l] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 83.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 K around 0 72.7%

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

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Taylor expanded in l around 0 52.5%

      \[\leadsto \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right) \cdot J + U \]
    7. Step-by-step derivation
      1. neg-mul-157.7%

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

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

      \[\leadsto \left(e^{\ell} - \color{blue}{\left(1 - \ell\right)}\right) \cdot J + U \]
    9. Taylor expanded in l around 0 74.9%

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

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

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

    if 1.14e8 < 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 \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. neg-mul-1100.0%

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\left(\ell + e^{\ell}\right) - 1\right)} + U \]
    7. Step-by-step derivation
      1. associate--l+81.5%

        \[\leadsto J \cdot \color{blue}{\left(\ell + \left(e^{\ell} - 1\right)\right)} + U \]
      2. expm1-define81.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 114000000:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot 0.16666666666666666\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell + \mathsf{expm1}\left(\ell\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 71.7% accurate, 13.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;K \leq 3.8 \cdot 10^{-12}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot 0.16666666666666666\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot \left(0.16666666666666666 + \ell \cdot 0.041666666666666664\right)\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= K 3.8e-12)
   (+ U (* J (* l (+ 2.0 (* l (+ 0.5 (* l 0.16666666666666666)))))))
   (+
    U
    (*
     J
     (*
      l
      (+
       2.0
       (*
        l
        (+ 0.5 (* l (+ 0.16666666666666666 (* l 0.041666666666666664)))))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (K <= 3.8e-12) {
		tmp = U + (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666))))));
	} else {
		tmp = U + (J * (l * (2.0 + (l * (0.5 + (l * (0.16666666666666666 + (l * 0.041666666666666664))))))));
	}
	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 (k <= 3.8d-12) then
        tmp = u + (j * (l * (2.0d0 + (l * (0.5d0 + (l * 0.16666666666666666d0))))))
    else
        tmp = u + (j * (l * (2.0d0 + (l * (0.5d0 + (l * (0.16666666666666666d0 + (l * 0.041666666666666664d0))))))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (K <= 3.8e-12) {
		tmp = U + (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666))))));
	} else {
		tmp = U + (J * (l * (2.0 + (l * (0.5 + (l * (0.16666666666666666 + (l * 0.041666666666666664))))))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if K <= 3.8e-12:
		tmp = U + (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666))))))
	else:
		tmp = U + (J * (l * (2.0 + (l * (0.5 + (l * (0.16666666666666666 + (l * 0.041666666666666664))))))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (K <= 3.8e-12)
		tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(l * Float64(0.5 + Float64(l * 0.16666666666666666)))))));
	else
		tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(l * Float64(0.5 + Float64(l * Float64(0.16666666666666666 + Float64(l * 0.041666666666666664)))))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (K <= 3.8e-12)
		tmp = U + (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666))))));
	else
		tmp = U + (J * (l * (2.0 + (l * (0.5 + (l * (0.16666666666666666 + (l * 0.041666666666666664))))))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[K, 3.8e-12], N[(U + N[(J * N[(l * N[(2.0 + N[(l * N[(0.5 + N[(l * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(2.0 + N[(l * N[(0.5 + N[(l * N[(0.16666666666666666 + N[(l * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;K \leq 3.8 \cdot 10^{-12}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot 0.16666666666666666\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 3.79999999999999996e-12

    1. Initial program 85.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 K around 0 76.2%

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

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Taylor expanded in l around 0 56.7%

      \[\leadsto \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right) \cdot J + U \]
    7. Step-by-step derivation
      1. neg-mul-164.5%

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

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

      \[\leadsto \left(e^{\ell} - \color{blue}{\left(1 - \ell\right)}\right) \cdot J + U \]
    9. Taylor expanded in l around 0 74.5%

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

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

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

    if 3.79999999999999996e-12 < K

    1. Initial program 93.0%

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

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

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Taylor expanded in l around 0 67.9%

      \[\leadsto \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right) \cdot J + U \]
    7. Step-by-step derivation
      1. neg-mul-178.5%

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

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

      \[\leadsto \left(e^{\ell} - \color{blue}{\left(1 - \ell\right)}\right) \cdot J + U \]
    9. Taylor expanded in l around 0 74.4%

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

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot \left(0.16666666666666666 + \color{blue}{\ell \cdot 0.041666666666666664}\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    11. Simplified74.4%

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

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

Alternative 12: 63.6% accurate, 19.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 5 \cdot 10^{+119}:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\

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


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

    1. Initial program 85.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 K around 0 73.5%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative73.5%

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Taylor expanded in l around 0 56.1%

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

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

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

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

    if 4.9999999999999999e119 < 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 83.8%

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

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Taylor expanded in l around 0 83.8%

      \[\leadsto \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right) \cdot J + U \]
    7. Step-by-step derivation
      1. neg-mul-1100.0%

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

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

      \[\leadsto \left(e^{\ell} - \color{blue}{\left(1 - \ell\right)}\right) \cdot J + U \]
    9. Taylor expanded in l around 0 76.1%

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

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

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

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

Alternative 13: 41.1% accurate, 20.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.2 \cdot 10^{-15} \lor \neg \left(\ell \leq 3.9 \cdot 10^{+58}\right):\\
\;\;\;\;U \cdot \left(U - -4\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.19999999999999997e-15 or 3.9000000000000001e58 < l

    1. Initial program 99.1%

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

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

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

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

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

    if -1.19999999999999997e-15 < l < 3.9000000000000001e58

    1. Initial program 76.0%

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

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

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

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

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

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

Alternative 14: 71.5% accurate, 20.8× speedup?

\[\begin{array}{l} \\ U + J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot 0.16666666666666666\right)\right)\right) \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ U (* J (* l (+ 2.0 (* l (+ 0.5 (* l 0.16666666666666666))))))))
double code(double J, double l, double K, double U) {
	return U + (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666))))));
}
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 + (l * (0.5d0 + (l * 0.16666666666666666d0))))))
end function
public static double code(double J, double l, double K, double U) {
	return U + (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666))))));
}
def code(J, l, K, U):
	return U + (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666))))))
function code(J, l, K, U)
	return Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(l * Float64(0.5 + Float64(l * 0.16666666666666666)))))))
end
function tmp = code(J, l, K, U)
	tmp = U + (J * (l * (2.0 + (l * (0.5 + (l * 0.16666666666666666))))));
end
code[J_, l_, K_, U_] := N[(U + N[(J * N[(l * N[(2.0 + N[(l * N[(0.5 + N[(l * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U + J \cdot \left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot 0.16666666666666666\right)\right)\right)
\end{array}
Derivation
  1. Initial program 87.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 K around 0 75.0%

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

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

    \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
  6. Taylor expanded in l around 0 59.9%

    \[\leadsto \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right) \cdot J + U \]
  7. Step-by-step derivation
    1. neg-mul-168.5%

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

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

    \[\leadsto \left(e^{\ell} - \color{blue}{\left(1 - \ell\right)}\right) \cdot J + U \]
  9. Taylor expanded in l around 0 71.8%

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

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

    \[\leadsto \color{blue}{\left(\ell \cdot \left(2 + \ell \cdot \left(0.5 + \ell \cdot 0.16666666666666666\right)\right)\right)} \cdot J + U \]
  12. Final simplification71.8%

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

Alternative 15: 55.5% accurate, 22.3× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 2.50000000000000018e-18

    1. Initial program 83.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 K around 0 73.2%

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

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Taylor expanded in l around 0 62.7%

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

    if 2.50000000000000018e-18 < l

    1. Initial program 98.9%

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

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

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

      \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
    6. Taylor expanded in l around 0 18.9%

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

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

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

Alternative 16: 41.2% accurate, 23.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.2 \cdot 10^{-9} \lor \neg \left(\ell \leq 7 \cdot 10^{+73}\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.2000000000000002e-9 or 7.00000000000000004e73 < l

    1. Initial program 99.7%

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

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

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

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

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

    if -5.2000000000000002e-9 < l < 7.00000000000000004e73

    1. Initial program 76.9%

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

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

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

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

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

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

Alternative 17: 60.2% accurate, 28.4× speedup?

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

\\
U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)
\end{array}
Derivation
  1. Initial program 87.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 K around 0 75.0%

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

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

    \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
  6. Taylor expanded in l around 0 51.0%

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

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

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

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

Alternative 18: 54.3% 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 87.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 K around 0 75.0%

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

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

    \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
  6. Taylor expanded in l around 0 51.0%

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

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

Alternative 19: 48.1% accurate, 62.4× speedup?

\[\begin{array}{l} \\ U + \ell \cdot J \end{array} \]
(FPCore (J l K U) :precision binary64 (+ U (* l J)))
double code(double J, double l, double K, double U) {
	return U + (l * J);
}
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)
end function
public static double code(double J, double l, double K, double U) {
	return U + (l * J);
}
def code(J, l, K, U):
	return U + (l * J)
function code(J, l, K, U)
	return Float64(U + Float64(l * J))
end
function tmp = code(J, l, K, U)
	tmp = U + (l * J);
end
code[J_, l_, K_, U_] := N[(U + N[(l * J), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U + \ell \cdot J
\end{array}
Derivation
  1. Initial program 87.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 K around 0 75.0%

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

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

    \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
  6. Taylor expanded in l around 0 59.9%

    \[\leadsto \left(e^{\ell} - \color{blue}{\left(1 + -1 \cdot \ell\right)}\right) \cdot J + U \]
  7. Step-by-step derivation
    1. neg-mul-168.5%

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

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

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

    \[\leadsto \color{blue}{\ell} \cdot J + U \]
  10. Final simplification45.3%

    \[\leadsto U + \ell \cdot J \]
  11. Add Preprocessing

Alternative 20: 37.1% 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 87.7%

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

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

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

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

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

Alternative 21: 2.8% accurate, 312.0× speedup?

\[\begin{array}{l} \\ -3 \end{array} \]
(FPCore (J l K U) :precision binary64 -3.0)
double code(double J, double l, double K, double U) {
	return -3.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 = -3.0d0
end function
public static double code(double J, double l, double K, double U) {
	return -3.0;
}
def code(J, l, K, U):
	return -3.0
function code(J, l, K, U)
	return -3.0
end
function tmp = code(J, l, K, U)
	tmp = -3.0;
end
code[J_, l_, K_, U_] := -3.0
\begin{array}{l}

\\
-3
\end{array}
Derivation
  1. Initial program 87.7%

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

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

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

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

    \[\leadsto \color{blue}{\sqrt[3]{U}} \]
  6. Applied egg-rr2.6%

    \[\leadsto \color{blue}{-3} \]
  7. Add Preprocessing

Reproduce

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