Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 85.9% → 99.7%
Time: 11.2s
Alternatives: 17
Speedup: 1.5×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 17 alternatives:

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

Initial Program: 85.9% 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.7% accurate, 0.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 5.00000000000000024e-5 < (-.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 \]

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

    1. Initial program 68.5%

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

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

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

Alternative 2: 94.9% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -0.48:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+97}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.35000000000000011e96 or 1.90000000000000018e97 < 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. Taylor expanded in l around 0 98.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\left(0.3333333333333333 \cdot {\ell}^{3}\right) \cdot J + \color{blue}{\left(2 \cdot \ell\right) \cdot J}, \cos \left(\frac{K}{2}\right), U\right) \]
      5. distribute-rgt-out98.9%

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

        \[\leadsto \mathsf{fma}\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right), \cos \color{blue}{\left(K \cdot \frac{1}{2}\right)}, U\right) \]
      7. metadata-eval98.9%

        \[\leadsto \mathsf{fma}\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right), \cos \left(K \cdot \color{blue}{0.5}\right), U\right) \]
    4. Applied egg-rr98.9%

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

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

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

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

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

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

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

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

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

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

    if -1.35000000000000011e96 < l < -0.47999999999999998 or 1.3e13 < l < 1.90000000000000018e97

    1. Initial program 100.0%

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

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

    if -0.47999999999999998 < l < 1.3e13

    1. Initial program 68.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.35 \cdot 10^{+96}:\\ \;\;\;\;\left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;\ell \leq -0.48:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 13000000000000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(2 \cdot \left(\ell \cdot J\right) + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+97}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;\left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot \cos \left(K \cdot 0.5\right)\\ \end{array} \]

Alternative 3: 94.9% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -0.056:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+97}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.35000000000000011e96 or 1.90000000000000018e97 < 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. Taylor expanded in l around 0 98.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\left(0.3333333333333333 \cdot {\ell}^{3}\right) \cdot J + \color{blue}{\left(2 \cdot \ell\right) \cdot J}, \cos \left(\frac{K}{2}\right), U\right) \]
      5. distribute-rgt-out98.9%

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

        \[\leadsto \mathsf{fma}\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right), \cos \color{blue}{\left(K \cdot \frac{1}{2}\right)}, U\right) \]
      7. metadata-eval98.9%

        \[\leadsto \mathsf{fma}\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right), \cos \left(K \cdot \color{blue}{0.5}\right), U\right) \]
    4. Applied egg-rr98.9%

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

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

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

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

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

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

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

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

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

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

    if -1.35000000000000011e96 < l < -0.0560000000000000012 or 1.3e13 < l < 1.90000000000000018e97

    1. Initial program 100.0%

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

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

    if -0.0560000000000000012 < l < 1.3e13

    1. Initial program 68.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.35 \cdot 10^{+96}:\\ \;\;\;\;\left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;\ell \leq -0.056:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 13000000000000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+97}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;\left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot \cos \left(K \cdot 0.5\right)\\ \end{array} \]

Alternative 4: 94.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ t_1 := \cos \left(K \cdot 0.5\right)\\ t_2 := \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot t_1\\ \mathbf{if}\;\ell \leq -2.6 \cdot 10^{+94}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\ell \leq -0.03:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 13000000000000:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot \left(J \cdot 2\right), t_1, U\right)\\ \mathbf{elif}\;\ell \leq 2.02 \cdot 10^{+96}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* (- (exp l) (exp (- l))) J)))
        (t_1 (cos (* K 0.5)))
        (t_2 (* (* (pow l 3.0) (* J 0.3333333333333333)) t_1)))
   (if (<= l -2.6e+94)
     t_2
     (if (<= l -0.03)
       t_0
       (if (<= l 13000000000000.0)
         (fma (* l (* J 2.0)) t_1 U)
         (if (<= l 2.02e+96) t_0 t_2))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + ((exp(l) - exp(-l)) * J);
	double t_1 = cos((K * 0.5));
	double t_2 = (pow(l, 3.0) * (J * 0.3333333333333333)) * t_1;
	double tmp;
	if (l <= -2.6e+94) {
		tmp = t_2;
	} else if (l <= -0.03) {
		tmp = t_0;
	} else if (l <= 13000000000000.0) {
		tmp = fma((l * (J * 2.0)), t_1, U);
	} else if (l <= 2.02e+96) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J))
	t_1 = cos(Float64(K * 0.5))
	t_2 = Float64(Float64((l ^ 3.0) * Float64(J * 0.3333333333333333)) * t_1)
	tmp = 0.0
	if (l <= -2.6e+94)
		tmp = t_2;
	elseif (l <= -0.03)
		tmp = t_0;
	elseif (l <= 13000000000000.0)
		tmp = fma(Float64(l * Float64(J * 2.0)), t_1, U);
	elseif (l <= 2.02e+96)
		tmp = t_0;
	else
		tmp = t_2;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]}, If[LessEqual[l, -2.6e+94], t$95$2, If[LessEqual[l, -0.03], t$95$0, If[LessEqual[l, 13000000000000.0], N[(N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision] * t$95$1 + U), $MachinePrecision], If[LessEqual[l, 2.02e+96], t$95$0, t$95$2]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -0.03:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq 13000000000000:\\
\;\;\;\;\mathsf{fma}\left(\ell \cdot \left(J \cdot 2\right), t_1, U\right)\\

\mathbf{elif}\;\ell \leq 2.02 \cdot 10^{+96}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.5999999999999999e94 or 2.02000000000000006e96 < 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. Taylor expanded in l around 0 98.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\left(0.3333333333333333 \cdot {\ell}^{3}\right) \cdot J + \color{blue}{\left(2 \cdot \ell\right) \cdot J}, \cos \left(\frac{K}{2}\right), U\right) \]
      5. distribute-rgt-out98.9%

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

        \[\leadsto \mathsf{fma}\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right), \cos \color{blue}{\left(K \cdot \frac{1}{2}\right)}, U\right) \]
      7. metadata-eval98.9%

        \[\leadsto \mathsf{fma}\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right), \cos \left(K \cdot \color{blue}{0.5}\right), U\right) \]
    4. Applied egg-rr98.9%

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

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

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

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

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

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

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

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

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

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

    if -2.5999999999999999e94 < l < -0.029999999999999999 or 1.3e13 < l < 2.02000000000000006e96

    1. Initial program 100.0%

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

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

    if -0.029999999999999999 < l < 1.3e13

    1. Initial program 68.9%

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\left(0.3333333333333333 \cdot {\ell}^{3}\right) \cdot J + \color{blue}{\left(2 \cdot \ell\right) \cdot J}, \cos \left(\frac{K}{2}\right), U\right) \]
      5. distribute-rgt-out98.5%

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

        \[\leadsto \mathsf{fma}\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right), \cos \color{blue}{\left(K \cdot \frac{1}{2}\right)}, U\right) \]
      7. metadata-eval98.5%

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{2 \cdot \left(\ell \cdot J\right)}, \cos \left(K \cdot 0.5\right), U\right) \]
    6. Step-by-step derivation
      1. *-commutative98.3%

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

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

        \[\leadsto \mathsf{fma}\left(\ell \cdot \color{blue}{\left(2 \cdot J\right)}, \cos \left(K \cdot 0.5\right), U\right) \]
    7. Simplified98.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.6 \cdot 10^{+94}:\\ \;\;\;\;\left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;\ell \leq -0.03:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 13000000000000:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot \left(J \cdot 2\right), \cos \left(K \cdot 0.5\right), U\right)\\ \mathbf{elif}\;\ell \leq 2.02 \cdot 10^{+96}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;\left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot \cos \left(K \cdot 0.5\right)\\ \end{array} \]

Alternative 5: 77.9% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 82.6%

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

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

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

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

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

    if 0.859999999999999987 < (cos.f64 (/.f64 K 2))

    1. Initial program 84.7%

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

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

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

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

Alternative 6: 77.9% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 82.6%

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

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

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

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

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

    if 0.859999999999999987 < (cos.f64 (/.f64 K 2))

    1. Initial program 84.7%

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\left(0.3333333333333333 \cdot {\ell}^{3}\right) \cdot J + \color{blue}{\left(2 \cdot \ell\right) \cdot J}, \cos \left(\frac{K}{2}\right), U\right) \]
      5. distribute-rgt-out91.0%

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

        \[\leadsto \mathsf{fma}\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right), \cos \color{blue}{\left(K \cdot \frac{1}{2}\right)}, U\right) \]
      7. metadata-eval91.0%

        \[\leadsto \mathsf{fma}\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right), \cos \left(K \cdot \color{blue}{0.5}\right), U\right) \]
    4. Applied egg-rr91.0%

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

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

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

Alternative 7: 86.5% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -0.03 \lor \neg \left(\ell \leq 13000000000000\right):\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot \left(J \cdot 2\right), \cos \left(K \cdot 0.5\right), U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -0.03) (not (<= l 13000000000000.0)))
   (+ U (* (- (exp l) (exp (- l))) J))
   (fma (* l (* J 2.0)) (cos (* K 0.5)) U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -0.03) || !(l <= 13000000000000.0)) {
		tmp = U + ((exp(l) - exp(-l)) * J);
	} else {
		tmp = fma((l * (J * 2.0)), cos((K * 0.5)), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -0.03) || !(l <= 13000000000000.0))
		tmp = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J));
	else
		tmp = fma(Float64(l * Float64(J * 2.0)), cos(Float64(K * 0.5)), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -0.03], N[Not[LessEqual[l, 13000000000000.0]], $MachinePrecision]], N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision], N[(N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -0.029999999999999999 or 1.3e13 < 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. Taylor expanded in K around 0 74.6%

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

    if -0.029999999999999999 < l < 1.3e13

    1. Initial program 68.9%

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\left(0.3333333333333333 \cdot {\ell}^{3}\right) \cdot J + \color{blue}{\left(2 \cdot \ell\right) \cdot J}, \cos \left(\frac{K}{2}\right), U\right) \]
      5. distribute-rgt-out98.5%

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

        \[\leadsto \mathsf{fma}\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right), \cos \color{blue}{\left(K \cdot \frac{1}{2}\right)}, U\right) \]
      7. metadata-eval98.5%

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{2 \cdot \left(\ell \cdot J\right)}, \cos \left(K \cdot 0.5\right), U\right) \]
    6. Step-by-step derivation
      1. *-commutative98.3%

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

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

        \[\leadsto \mathsf{fma}\left(\ell \cdot \color{blue}{\left(2 \cdot J\right)}, \cos \left(K \cdot 0.5\right), U\right) \]
    7. Simplified98.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -0.03 \lor \neg \left(\ell \leq 13000000000000\right):\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot \left(J \cdot 2\right), \cos \left(K \cdot 0.5\right), U\right)\\ \end{array} \]

Alternative 8: 86.5% accurate, 1.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -0.029999999999999999 or 1.3e13 < 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. Taylor expanded in K around 0 74.6%

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

    if -0.029999999999999999 < l < 1.3e13

    1. Initial program 68.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -0.03 \lor \neg \left(\ell \leq 13000000000000\right):\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\ \end{array} \]

Alternative 9: 64.6% accurate, 2.8× speedup?

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

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

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

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

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

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

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

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

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

Alternative 10: 64.6% accurate, 2.8× speedup?

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

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

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

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

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

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

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

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

Alternative 11: 47.3% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -700:\\ \;\;\;\;{U}^{-8}\\ \mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-5}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;{U}^{-8}\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -700.0) (pow U -8.0) (if (<= l 1.3e-5) U (pow U -8.0))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -700.0) {
		tmp = pow(U, -8.0);
	} else if (l <= 1.3e-5) {
		tmp = U;
	} else {
		tmp = pow(U, -8.0);
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (l <= (-700.0d0)) then
        tmp = u ** (-8.0d0)
    else if (l <= 1.3d-5) then
        tmp = u
    else
        tmp = u ** (-8.0d0)
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -700.0) {
		tmp = Math.pow(U, -8.0);
	} else if (l <= 1.3e-5) {
		tmp = U;
	} else {
		tmp = Math.pow(U, -8.0);
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -700.0:
		tmp = math.pow(U, -8.0)
	elif l <= 1.3e-5:
		tmp = U
	else:
		tmp = math.pow(U, -8.0)
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -700.0)
		tmp = U ^ -8.0;
	elseif (l <= 1.3e-5)
		tmp = U;
	else
		tmp = U ^ -8.0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -700.0)
		tmp = U ^ -8.0;
	elseif (l <= 1.3e-5)
		tmp = U;
	else
		tmp = U ^ -8.0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -700.0], N[Power[U, -8.0], $MachinePrecision], If[LessEqual[l, 1.3e-5], U, N[Power[U, -8.0], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -700:\\
\;\;\;\;{U}^{-8}\\

\mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-5}:\\
\;\;\;\;U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -700 or 1.29999999999999992e-5 < l

    1. Initial program 99.9%

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

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

    if -700 < l < 1.29999999999999992e-5

    1. Initial program 68.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -700:\\ \;\;\;\;{U}^{-8}\\ \mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-5}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;{U}^{-8}\\ \end{array} \]

Alternative 12: 42.5% accurate, 23.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.2 \cdot 10^{+18}:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-5}:\\
\;\;\;\;U\\

\mathbf{else}:\\
\;\;\;\;\frac{0.109375}{U \cdot U} - \frac{0.125}{U}\\


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

    1. Initial program 100.0%

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

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

    if -4.2e18 < l < 1.29999999999999992e-5

    1. Initial program 69.3%

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

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

    if 1.29999999999999992e-5 < 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. Applied egg-rr1.4%

      \[\leadsto \color{blue}{\frac{U}{U + \left(-8 \cdot U + U \cdot \left(-8 \cdot U\right)\right)}} \]
    3. Step-by-step derivation
      1. associate-+r+1.4%

        \[\leadsto \frac{U}{\color{blue}{\left(U + -8 \cdot U\right) + U \cdot \left(-8 \cdot U\right)}} \]
      2. distribute-rgt1-in1.4%

        \[\leadsto \frac{U}{\color{blue}{\left(-8 + 1\right) \cdot U} + U \cdot \left(-8 \cdot U\right)} \]
      3. *-commutative1.4%

        \[\leadsto \frac{U}{\left(-8 + 1\right) \cdot U + \color{blue}{\left(-8 \cdot U\right) \cdot U}} \]
      4. distribute-rgt-out1.4%

        \[\leadsto \frac{U}{\color{blue}{U \cdot \left(\left(-8 + 1\right) + -8 \cdot U\right)}} \]
      5. associate-/r*1.4%

        \[\leadsto \color{blue}{\frac{\frac{U}{U}}{\left(-8 + 1\right) + -8 \cdot U}} \]
      6. *-inverses1.4%

        \[\leadsto \frac{\color{blue}{1}}{\left(-8 + 1\right) + -8 \cdot U} \]
      7. +-commutative1.4%

        \[\leadsto \frac{1}{\color{blue}{-8 \cdot U + \left(-8 + 1\right)}} \]
      8. *-commutative1.4%

        \[\leadsto \frac{1}{\color{blue}{U \cdot -8} + \left(-8 + 1\right)} \]
      9. metadata-eval1.4%

        \[\leadsto \frac{1}{U \cdot -8 + \color{blue}{-7}} \]
    4. Simplified1.4%

      \[\leadsto \color{blue}{\frac{1}{U \cdot -8 + -7}} \]
    5. Taylor expanded in U around inf 23.1%

      \[\leadsto \color{blue}{0.109375 \cdot \frac{1}{{U}^{2}} - 0.125 \cdot \frac{1}{U}} \]
    6. Step-by-step derivation
      1. unpow223.1%

        \[\leadsto 0.109375 \cdot \frac{1}{\color{blue}{U \cdot U}} - 0.125 \cdot \frac{1}{U} \]
      2. associate-*r/23.1%

        \[\leadsto \color{blue}{\frac{0.109375 \cdot 1}{U \cdot U}} - 0.125 \cdot \frac{1}{U} \]
      3. metadata-eval23.1%

        \[\leadsto \frac{\color{blue}{0.109375}}{U \cdot U} - 0.125 \cdot \frac{1}{U} \]
      4. associate-*r/23.1%

        \[\leadsto \frac{0.109375}{U \cdot U} - \color{blue}{\frac{0.125 \cdot 1}{U}} \]
      5. metadata-eval23.1%

        \[\leadsto \frac{0.109375}{U \cdot U} - \frac{\color{blue}{0.125}}{U} \]
    7. Simplified23.1%

      \[\leadsto \color{blue}{\frac{0.109375}{U \cdot U} - \frac{0.125}{U}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification43.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.2 \cdot 10^{+18}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-5}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;\frac{0.109375}{U \cdot U} - \frac{0.125}{U}\\ \end{array} \]

Alternative 13: 42.2% accurate, 34.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.4 \cdot 10^{+18}:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq 2.45 \cdot 10^{+51}:\\
\;\;\;\;U\\

\mathbf{else}:\\
\;\;\;\;U \cdot \left(2 - U\right)\\


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

    1. Initial program 100.0%

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

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

    if -5.4e18 < l < 2.44999999999999992e51

    1. Initial program 71.3%

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

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

    if 2.44999999999999992e51 < l

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{U + \mathsf{fma}\left(-U, U, U\right)} \]
    5. Step-by-step derivation
      1. fma-udef19.5%

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

        \[\leadsto U + \color{blue}{\left(U + \left(-U\right) \cdot U\right)} \]
      3. associate-+r+19.5%

        \[\leadsto \color{blue}{\left(U + U\right) + \left(-U\right) \cdot U} \]
      4. count-219.5%

        \[\leadsto \color{blue}{2 \cdot U} + \left(-U\right) \cdot U \]
      5. distribute-rgt-out19.5%

        \[\leadsto \color{blue}{U \cdot \left(2 + \left(-U\right)\right)} \]
      6. unsub-neg19.5%

        \[\leadsto U \cdot \color{blue}{\left(2 - U\right)} \]
    6. Simplified19.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.4 \cdot 10^{+18}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 2.45 \cdot 10^{+51}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(2 - U\right)\\ \end{array} \]

Alternative 14: 39.9% accurate, 61.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -7.5 \cdot 10^{+16}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U) :precision binary64 (if (<= l -7.5e+16) (* U U) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -7.5e+16) {
		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 <= (-7.5d+16)) 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 <= -7.5e+16) {
		tmp = U * U;
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -7.5e+16:
		tmp = U * U
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -7.5e+16)
		tmp = Float64(U * U);
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -7.5e+16)
		tmp = U * U;
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -7.5e+16], N[(U * U), $MachinePrecision], U]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -7.5 \cdot 10^{+16}:\\
\;\;\;\;U \cdot U\\

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


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

    1. Initial program 100.0%

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

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

    if -7.5e16 < l

    1. Initial program 78.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7.5 \cdot 10^{+16}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 15: 2.7% accurate, 312.0× speedup?

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

\\
-0.14285714285714285
\end{array}
Derivation
  1. Initial program 83.7%

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

    \[\leadsto \color{blue}{\frac{U}{U + \left(-8 \cdot U + U \cdot \left(-8 \cdot U\right)\right)}} \]
  3. Step-by-step derivation
    1. associate-+r+2.2%

      \[\leadsto \frac{U}{\color{blue}{\left(U + -8 \cdot U\right) + U \cdot \left(-8 \cdot U\right)}} \]
    2. distribute-rgt1-in2.2%

      \[\leadsto \frac{U}{\color{blue}{\left(-8 + 1\right) \cdot U} + U \cdot \left(-8 \cdot U\right)} \]
    3. *-commutative2.2%

      \[\leadsto \frac{U}{\left(-8 + 1\right) \cdot U + \color{blue}{\left(-8 \cdot U\right) \cdot U}} \]
    4. distribute-rgt-out2.2%

      \[\leadsto \frac{U}{\color{blue}{U \cdot \left(\left(-8 + 1\right) + -8 \cdot U\right)}} \]
    5. associate-/r*2.2%

      \[\leadsto \color{blue}{\frac{\frac{U}{U}}{\left(-8 + 1\right) + -8 \cdot U}} \]
    6. *-inverses2.2%

      \[\leadsto \frac{\color{blue}{1}}{\left(-8 + 1\right) + -8 \cdot U} \]
    7. +-commutative2.2%

      \[\leadsto \frac{1}{\color{blue}{-8 \cdot U + \left(-8 + 1\right)}} \]
    8. *-commutative2.2%

      \[\leadsto \frac{1}{\color{blue}{U \cdot -8} + \left(-8 + 1\right)} \]
    9. metadata-eval2.2%

      \[\leadsto \frac{1}{U \cdot -8 + \color{blue}{-7}} \]
  4. Simplified2.2%

    \[\leadsto \color{blue}{\frac{1}{U \cdot -8 + -7}} \]
  5. Taylor expanded in U around 0 2.5%

    \[\leadsto \color{blue}{-0.14285714285714285} \]
  6. Final simplification2.5%

    \[\leadsto -0.14285714285714285 \]

Alternative 16: 2.8% accurate, 312.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{U}{U}} \]
  3. Step-by-step derivation
    1. *-inverses3.1%

      \[\leadsto \color{blue}{1} \]
  4. Simplified3.1%

    \[\leadsto \color{blue}{1} \]
  5. Final simplification3.1%

    \[\leadsto 1 \]

Alternative 17: 36.9% 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 83.7%

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

    \[\leadsto \color{blue}{U} \]
  3. Final simplification35.7%

    \[\leadsto U \]

Reproduce

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