Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.5% → 99.5%
Time: 13.5s
Alternatives: 15
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 15 alternatives:

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

Initial Program: 86.5% accurate, 1.0× speedup?

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

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

Alternative 1: 99.5% 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 0\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 0.0)))
     (+ (* 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 <= 0.0)) {
		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 <= 0.0)) {
		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 <= 0.0):
		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 <= 0.0))
		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 <= 0.0)))
		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, 0.0]], $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 0\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 0.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -\infty \lor \neg \left(e^{\ell} - e^{-\ell} \leq 0\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: 86.4% accurate, 0.5× speedup?

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

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

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

    1. Initial program 100.0%

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

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.0

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

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

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

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

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

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

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

Alternative 3: 76.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{if}\;t_0 \leq -0.55:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -0.01:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{elif}\;t_0 \leq 0.25:\\ \;\;\;\;t_1\\ \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))) (t_1 (+ U (* 2.0 (* l (* J (cos (* K 0.5))))))))
   (if (<= t_0 -0.55)
     t_1
     (if (<= t_0 -0.01)
       (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25))))
       (if (<= t_0 0.25)
         t_1
         (+ 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 t_1 = U + (2.0 * (l * (J * cos((K * 0.5)))));
	double tmp;
	if (t_0 <= -0.55) {
		tmp = t_1;
	} else if (t_0 <= -0.01) {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	} else if (t_0 <= 0.25) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    t_1 = u + (2.0d0 * (l * (j * cos((k * 0.5d0)))))
    if (t_0 <= (-0.55d0)) then
        tmp = t_1
    else if (t_0 <= (-0.01d0)) then
        tmp = u + ((l * j) * (2.0d0 + ((k * k) * (-0.25d0))))
    else if (t_0 <= 0.25d0) then
        tmp = t_1
    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 t_1 = U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
	double tmp;
	if (t_0 <= -0.55) {
		tmp = t_1;
	} else if (t_0 <= -0.01) {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	} else if (t_0 <= 0.25) {
		tmp = t_1;
	} 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))
	t_1 = U + (2.0 * (l * (J * math.cos((K * 0.5)))))
	tmp = 0
	if t_0 <= -0.55:
		tmp = t_1
	elif t_0 <= -0.01:
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)))
	elif t_0 <= 0.25:
		tmp = t_1
	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))
	t_1 = Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5))))))
	tmp = 0.0
	if (t_0 <= -0.55)
		tmp = t_1;
	elseif (t_0 <= -0.01)
		tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25))));
	elseif (t_0 <= 0.25)
		tmp = t_1;
	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));
	t_1 = U + (2.0 * (l * (J * cos((K * 0.5)))));
	tmp = 0.0;
	if (t_0 <= -0.55)
		tmp = t_1;
	elseif (t_0 <= -0.01)
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	elseif (t_0 <= 0.25)
		tmp = t_1;
	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]}, Block[{t$95$1 = N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.55], t$95$1, If[LessEqual[t$95$0, -0.01], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.25], t$95$1, 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)\\
t_1 := U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
\mathbf{if}\;t_0 \leq -0.55:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq -0.01:\\
\;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\

\mathbf{elif}\;t_0 \leq 0.25:\\
\;\;\;\;t_1\\

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


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

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

      \[\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. *-commutative80.1%

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

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

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

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

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

    1. Initial program 87.2%

      \[\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 88.2%

      \[\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 l around 0 46.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 83.3%

      \[\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 90.1%

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

        \[\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. +-commutative90.1%

        \[\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*90.1%

        \[\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*90.1%

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

        \[\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. *-commutative90.1%

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

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

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

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

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

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

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

Alternative 4: 94.1% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -0.92:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\ell \leq 8.4 \cdot 10^{-16}:\\
\;\;\;\;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 6 \cdot 10^{+93}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -6.60000000000000032e146 or 5.99999999999999957e93 < 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 100.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 l around inf 100.0%

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

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

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

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

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

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

    if -6.60000000000000032e146 < l < -0.92000000000000004 or 8.4000000000000004e-16 < l < 5.99999999999999957e93

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

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

    if -0.92000000000000004 < l < 8.4000000000000004e-16

    1. Initial program 68.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 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 3 regimes into one program.
  4. Final simplification98.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6.6 \cdot 10^{+146}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left({\ell}^{3} \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -0.92:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 8.4 \cdot 10^{-16}:\\ \;\;\;\;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 6 \cdot 10^{+93}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left({\ell}^{3} \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]

Alternative 5: 94.0% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -0.0305:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\ell \leq 8.4 \cdot 10^{-16}:\\
\;\;\;\;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.95 \cdot 10^{+93}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -6.60000000000000032e146 or 1.9500000000000001e93 < 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 100.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 l around inf 100.0%

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

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

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

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

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

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

    if -6.60000000000000032e146 < l < -0.030499999999999999 or 8.4000000000000004e-16 < l < 1.9500000000000001e93

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

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

    if -0.030499999999999999 < l < 8.4000000000000004e-16

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6.6 \cdot 10^{+146}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left({\ell}^{3} \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -0.0305:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 8.4 \cdot 10^{-16}:\\ \;\;\;\;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.95 \cdot 10^{+93}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left({\ell}^{3} \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]

Alternative 6: 93.9% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -0.00072:\\
\;\;\;\;t_2\\

\mathbf{elif}\;\ell \leq 8.4 \cdot 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(\ell \cdot 2, t_0, U\right)\\

\mathbf{elif}\;\ell \leq 7 \cdot 10^{+93}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -4.99999999999999992e156 or 6.99999999999999996e93 < 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 100.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 l around inf 100.0%

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

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

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

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

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

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

    if -4.99999999999999992e156 < l < -7.20000000000000045e-4 or 8.4000000000000004e-16 < l < 6.99999999999999996e93

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

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

    if -7.20000000000000045e-4 < l < 8.4000000000000004e-16

    1. Initial program 68.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 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. Taylor expanded in l around 0 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\ell \cdot 2, J \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}, U\right) \]
    7. Applied egg-rr99.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5 \cdot 10^{+156}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left({\ell}^{3} \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -0.00072:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 8.4 \cdot 10^{-16}:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot 2, J \cdot \cos \left(K \cdot 0.5\right), U\right)\\ \mathbf{elif}\;\ell \leq 7 \cdot 10^{+93}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left({\ell}^{3} \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]

Alternative 7: 81.6% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-8}{U} - U\right)\right)\\ t_1 := U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\ \mathbf{if}\;\ell \leq -8 \cdot 10^{+73}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq -480:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 460:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 6.8 \cdot 10^{+129}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (log1p (expm1 (- (/ -8.0 U) U))))
        (t_1 (+ U (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))))))
   (if (<= l -8e+73)
     t_1
     (if (<= l -480.0)
       t_0
       (if (<= l 460.0)
         (+ U (* 2.0 (* l (* J (cos (* K 0.5))))))
         (if (<= l 6.8e+129) t_0 t_1))))))
double code(double J, double l, double K, double U) {
	double t_0 = log1p(expm1(((-8.0 / U) - U)));
	double t_1 = U + (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0)));
	double tmp;
	if (l <= -8e+73) {
		tmp = t_1;
	} else if (l <= -480.0) {
		tmp = t_0;
	} else if (l <= 460.0) {
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	} else if (l <= 6.8e+129) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.log1p(Math.expm1(((-8.0 / U) - U)));
	double t_1 = U + (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0)));
	double tmp;
	if (l <= -8e+73) {
		tmp = t_1;
	} else if (l <= -480.0) {
		tmp = t_0;
	} else if (l <= 460.0) {
		tmp = U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
	} else if (l <= 6.8e+129) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.log1p(math.expm1(((-8.0 / U) - U)))
	t_1 = U + (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0)))
	tmp = 0
	if l <= -8e+73:
		tmp = t_1
	elif l <= -480.0:
		tmp = t_0
	elif l <= 460.0:
		tmp = U + (2.0 * (l * (J * math.cos((K * 0.5)))))
	elif l <= 6.8e+129:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = log1p(expm1(Float64(Float64(-8.0 / U) - U)))
	t_1 = Float64(U + Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))))
	tmp = 0.0
	if (l <= -8e+73)
		tmp = t_1;
	elseif (l <= -480.0)
		tmp = t_0;
	elseif (l <= 460.0)
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5))))));
	elseif (l <= 6.8e+129)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Log[1 + N[(Exp[N[(N[(-8.0 / U), $MachinePrecision] - U), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -8e+73], t$95$1, If[LessEqual[l, -480.0], t$95$0, If[LessEqual[l, 460.0], N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 6.8e+129], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-8}{U} - U\right)\right)\\
t_1 := U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\
\mathbf{if}\;\ell \leq -8 \cdot 10^{+73}:\\
\;\;\;\;t_1\\

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

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

\mathbf{elif}\;\ell \leq 6.8 \cdot 10^{+129}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -7.99999999999999986e73 or 6.80000000000000036e129 < 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 96.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-def96.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. +-commutative96.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*96.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*96.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-out96.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. *-commutative96.5%

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

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

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

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

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

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

    if -7.99999999999999986e73 < l < -480 or 460 < l < 6.80000000000000036e129

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

      \[\leadsto \color{blue}{\frac{-8}{U} - U} \]
    3. Step-by-step derivation
      1. log1p-expm1-u65.6%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-8}{U} - U\right)\right)} \]
    4. Applied egg-rr65.6%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-8}{U} - U\right)\right)} \]

    if -480 < l < 460

    1. Initial program 69.1%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -8 \cdot 10^{+73}:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\ \mathbf{elif}\;\ell \leq -480:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-8}{U} - U\right)\right)\\ \mathbf{elif}\;\ell \leq 460:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 6.8 \cdot 10^{+129}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-8}{U} - U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\ \end{array} \]

Alternative 8: 86.6% accurate, 1.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -0.0025500000000000002 or 8.4000000000000004e-16 < 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 76.7%

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

    if -0.0025500000000000002 < l < 8.4000000000000004e-16

    1. Initial program 68.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 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. Taylor expanded in l around 0 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\ell \cdot 2, J \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}, U\right) \]
    7. Applied egg-rr99.8%

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

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

Alternative 9: 57.9% accurate, 2.7× speedup?

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

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

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


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

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

      \[\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 l around 0 62.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    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 90.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. Taylor expanded in l around 0 70.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 63.3% 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 82.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 68.8%

    \[\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. *-commutative68.8%

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

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

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

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

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

Alternative 11: 42.0% accurate, 34.2× speedup?

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

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

\mathbf{elif}\;\ell \leq 600000000:\\
\;\;\;\;U\\

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


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

    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-rr17.2%

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

    if -4.45e15 < l < 6e8

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

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

    if 6e8 < 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. Applied egg-rr16.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.45 \cdot 10^{+15}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 600000000:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(U - -8\right)\\ \end{array} \]

Alternative 12: 42.0% accurate, 43.8× speedup?

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

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

\mathbf{elif}\;\ell \leq 600000000:\\
\;\;\;\;U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.45e16 or 6e8 < 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. Applied egg-rr17.0%

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

    if -1.45e16 < l < 6e8

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

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

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

Alternative 13: 53.5% accurate, 44.6× speedup?

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

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

    \[\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 l around 0 68.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 14: 2.7% accurate, 312.0× speedup?

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

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

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

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

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

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

    \[\leadsto 1 \]

Alternative 15: 35.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 82.9%

    \[\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 38.9%

    \[\leadsto \color{blue}{U} \]
  3. Final simplification38.9%

    \[\leadsto U \]

Reproduce

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