Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.6% → 99.8%
Time: 13.2s
Alternatives: 16
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 16 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.6% 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.8% 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 -1 \lor \neg \left(t_1 \leq 10^{-11}\right):\\ \;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + U\\ \mathbf{else}:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
   (if (or (<= t_1 -1.0) (not (<= t_1 1e-11)))
     (+ (* (* t_1 J) t_0) U)
     (+ U (* t_0 (* 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 = exp(l) - exp(-l);
	double tmp;
	if ((t_1 <= -1.0) || !(t_1 <= 1e-11)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (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 = exp(l) - exp(-l)
    if ((t_1 <= (-1.0d0)) .or. (.not. (t_1 <= 1d-11))) then
        tmp = ((t_1 * j) * t_0) + u
    else
        tmp = u + (t_0 * (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 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_1 <= -1.0) || !(t_1 <= 1e-11)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (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 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_1 <= -1.0) or not (t_1 <= 1e-11):
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (t_0 * (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(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_1 <= -1.0) || !(t_1 <= 1e-11))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	else
		tmp = Float64(U + Float64(t_0 * 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 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_1 <= -1.0) || ~((t_1 <= 1e-11)))
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (t_0 * (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[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -1.0], N[Not[LessEqual[t$95$1, 1e-11]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $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 -1 \lor \neg \left(t_1 \leq 10^{-11}\right):\\
\;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + U\\

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


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

    1. Initial program 73.8%

      \[\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 2 regimes into one program.
  4. Final simplification100.0%

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

Alternative 2: 87.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_0 \leq -1 \lor \neg \left(t_0 \leq 10^{-11}\right):\\ \;\;\;\;t_0 \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))))
   (if (or (<= t_0 -1.0) (not (<= t_0 1e-11)))
     (+ (* t_0 J) U)
     (+ U (* (* l J) (* 2.0 (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 <= -1.0) || !(t_0 <= 1e-11)) {
		tmp = (t_0 * J) + U;
	} else {
		tmp = U + ((l * J) * (2.0 * cos((K * 0.5))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = exp(l) - exp(-l)
    if ((t_0 <= (-1.0d0)) .or. (.not. (t_0 <= 1d-11))) then
        tmp = (t_0 * j) + u
    else
        tmp = u + ((l * j) * (2.0d0 * cos((k * 0.5d0))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_0 <= -1.0) || !(t_0 <= 1e-11)) {
		tmp = (t_0 * J) + U;
	} else {
		tmp = U + ((l * J) * (2.0 * 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 <= -1.0) or not (t_0 <= 1e-11):
		tmp = (t_0 * J) + U
	else:
		tmp = U + ((l * J) * (2.0 * 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 <= -1.0) || !(t_0 <= 1e-11))
		tmp = Float64(Float64(t_0 * J) + U);
	else
		tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 * 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 <= -1.0) || ~((t_0 <= 1e-11)))
		tmp = (t_0 * J) + U;
	else
		tmp = U + ((l * J) * (2.0 * 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, -1.0], N[Not[LessEqual[t$95$0, 1e-11]], $MachinePrecision]], N[(N[(t$95$0 * J), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -1 or 9.99999999999999939e-12 < (-.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 70.0%

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

    if -1 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 9.99999999999999939e-12

    1. Initial program 73.8%

      \[\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}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    3. Step-by-step derivation
      1. associate-*r*99.9%

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

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

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

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

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

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

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

Alternative 3: 94.1% accurate, 1.4× speedup?

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

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

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

\mathbf{elif}\;\ell \leq 10^{+67}:\\
\;\;\;\;t_0\\

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


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

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

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

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

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

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

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

    if -4.19999999999999997e75 < l < -0.0264999999999999993 or 1.18e-4 < l < 9.99999999999999983e66

    1. Initial program 99.9%

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

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

    if -0.0264999999999999993 < l < 1.18e-4

    1. Initial program 73.8%

      \[\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}{U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} \]
    3. Step-by-step derivation
      1. +-commutative99.9%

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

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

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

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

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

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

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

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

    if 9.99999999999999983e66 < 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 92.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. Taylor expanded in l around inf 92.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.2 \cdot 10^{+75}:\\ \;\;\;\;\left(J \cdot 0.3333333333333333\right) \cdot \left({\ell}^{3} \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq -0.0265:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 0.000118:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot J, 2 \cdot \cos \left(K \cdot 0.5\right), U\right)\\ \mathbf{elif}\;\ell \leq 10^{+67}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \end{array} \]

Alternative 4: 94.1% accurate, 1.4× speedup?

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

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

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

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

\mathbf{elif}\;\ell \leq 8.8 \cdot 10^{+66}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -4.19999999999999997e75 or 8.7999999999999994e66 < 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. Taylor expanded in l around 0 94.2%

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

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

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

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

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

    if -4.19999999999999997e75 < l < -0.0054999999999999997 or 6.2e-4 < l < 8.7999999999999994e66

    1. Initial program 99.9%

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

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

    if -0.0054999999999999997 < l < 6.2e-4

    1. Initial program 73.8%

      \[\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}{U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} \]
    3. Step-by-step derivation
      1. +-commutative99.9%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.2 \cdot 10^{+75}:\\ \;\;\;\;\left(J \cdot 0.3333333333333333\right) \cdot \left({\ell}^{3} \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq -0.0055:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 0.00062:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot J, 2 \cdot \cos \left(K \cdot 0.5\right), U\right)\\ \mathbf{elif}\;\ell \leq 8.8 \cdot 10^{+66}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;\left(J \cdot 0.3333333333333333\right) \cdot \left({\ell}^{3} \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 5: 76.2% accurate, 1.4× speedup?

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

    1. Initial program 91.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 79.2% accurate, 1.4× speedup?

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

    1. Initial program 91.8%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 88.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+
  U
  (* (cos (/ K 2.0)) (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))))))
double code(double J, double l, double K, double U) {
	return U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u + (cos((k / 2.0d0)) * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
end function
public static double code(double J, double l, double K, double U) {
	return U + (Math.cos((K / 2.0)) * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
}
def code(J, l, K, U):
	return U + (math.cos((K / 2.0)) * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))))
function code(J, l, K, U)
	return Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))))
end
function tmp = code(J, l, K, U)
	tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))));
end
code[J_, l_, K_, U_] := 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]
\begin{array}{l}

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

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

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

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

Alternative 8: 87.3% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -0.0245 \lor \neg \left(\ell \leq 0.0023\right):\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot J, 2 \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.0245) (not (<= l 0.0023)))
   (+ (* (- (exp l) (exp (- l))) J) U)
   (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.0245) || !(l <= 0.0023)) {
		tmp = ((exp(l) - exp(-l)) * J) + U;
	} 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.0245) || !(l <= 0.0023))
		tmp = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U);
	else
		tmp = fma(Float64(l * J), Float64(2.0 * cos(Float64(K * 0.5))), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -0.0245], N[Not[LessEqual[l, 0.0023]], $MachinePrecision]], N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision], N[(N[(l * J), $MachinePrecision] * N[(2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\ell \cdot J, 2 \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.024500000000000001 or 0.0023 < 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 70.0%

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

    if -0.024500000000000001 < l < 0.0023

    1. Initial program 73.8%

      \[\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}{U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} \]
    3. Step-by-step derivation
      1. +-commutative99.9%

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

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

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

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

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

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

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

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

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

Alternative 9: 64.5% accurate, 2.8× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 10: 64.5% accurate, 2.8× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 53.8% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1.02 \cdot 10^{+50}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 760:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-4}{U} \cdot \frac{-4}{U} - U \cdot U}{U + \frac{-4}{U}}\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -1.02e+50)
   (pow U -3.0)
   (if (<= l 760.0)
     (+ U (* J (* l 2.0)))
     (/ (- (* (/ -4.0 U) (/ -4.0 U)) (* U U)) (+ U (/ -4.0 U))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -1.02e+50) {
		tmp = pow(U, -3.0);
	} else if (l <= 760.0) {
		tmp = U + (J * (l * 2.0));
	} else {
		tmp = (((-4.0 / U) * (-4.0 / U)) - (U * U)) / (U + (-4.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 <= (-1.02d+50)) then
        tmp = u ** (-3.0d0)
    else if (l <= 760.0d0) then
        tmp = u + (j * (l * 2.0d0))
    else
        tmp = ((((-4.0d0) / u) * ((-4.0d0) / u)) - (u * u)) / (u + ((-4.0d0) / u))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -1.02e+50) {
		tmp = Math.pow(U, -3.0);
	} else if (l <= 760.0) {
		tmp = U + (J * (l * 2.0));
	} else {
		tmp = (((-4.0 / U) * (-4.0 / U)) - (U * U)) / (U + (-4.0 / U));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -1.02e+50:
		tmp = math.pow(U, -3.0)
	elif l <= 760.0:
		tmp = U + (J * (l * 2.0))
	else:
		tmp = (((-4.0 / U) * (-4.0 / U)) - (U * U)) / (U + (-4.0 / U))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -1.02e+50)
		tmp = U ^ -3.0;
	elseif (l <= 760.0)
		tmp = Float64(U + Float64(J * Float64(l * 2.0)));
	else
		tmp = Float64(Float64(Float64(Float64(-4.0 / U) * Float64(-4.0 / U)) - Float64(U * U)) / Float64(U + Float64(-4.0 / U)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -1.02e+50)
		tmp = U ^ -3.0;
	elseif (l <= 760.0)
		tmp = U + (J * (l * 2.0));
	else
		tmp = (((-4.0 / U) * (-4.0 / U)) - (U * U)) / (U + (-4.0 / U));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -1.02e+50], N[Power[U, -3.0], $MachinePrecision], If[LessEqual[l, 760.0], N[(U + N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(-4.0 / U), $MachinePrecision] * N[(-4.0 / U), $MachinePrecision]), $MachinePrecision] - N[(U * U), $MachinePrecision]), $MachinePrecision] / N[(U + N[(-4.0 / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.02 \cdot 10^{+50}:\\
\;\;\;\;{U}^{-3}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{-4}{U} \cdot \frac{-4}{U} - U \cdot U}{U + \frac{-4}{U}}\\


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

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

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

    if -1.01999999999999991e50 < l < 760

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

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

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

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

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

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

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

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

    if 760 < 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-rr3.2%

      \[\leadsto \color{blue}{\frac{-4}{U} - U} \]
    3. Step-by-step derivation
      1. sub-neg3.2%

        \[\leadsto \color{blue}{\frac{-4}{U} + \left(-U\right)} \]
      2. flip-+28.8%

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

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

        \[\leadsto \frac{\frac{\color{blue}{16}}{U \cdot U} - \left(-U\right) \cdot \left(-U\right)}{\frac{-4}{U} - \left(-U\right)} \]
      5. pow228.8%

        \[\leadsto \frac{\frac{16}{\color{blue}{{U}^{2}}} - \left(-U\right) \cdot \left(-U\right)}{\frac{-4}{U} - \left(-U\right)} \]
    4. Applied egg-rr28.8%

      \[\leadsto \color{blue}{\frac{\frac{16}{{U}^{2}} - \left(-U\right) \cdot \left(-U\right)}{\frac{-4}{U} - \left(-U\right)}} \]
    5. Step-by-step derivation
      1. metadata-eval28.8%

        \[\leadsto \frac{\frac{\color{blue}{-4 \cdot -4}}{{U}^{2}} - \left(-U\right) \cdot \left(-U\right)}{\frac{-4}{U} - \left(-U\right)} \]
      2. unpow228.8%

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

        \[\leadsto \frac{\color{blue}{\frac{-4}{U} \cdot \frac{-4}{U}} - \left(-U\right) \cdot \left(-U\right)}{\frac{-4}{U} - \left(-U\right)} \]
    6. Applied egg-rr28.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.02 \cdot 10^{+50}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 760:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-4}{U} \cdot \frac{-4}{U} - U \cdot U}{U + \frac{-4}{U}}\\ \end{array} \]

Alternative 12: 42.7% accurate, 43.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.1000000000000002e53 or 8.5e9 < 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-rr14.3%

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

    if -2.1000000000000002e53 < l < 8.5e9

    1. Initial program 76.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.1 \cdot 10^{+53} \lor \neg \left(\ell \leq 8500000000\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 13: 42.0% accurate, 43.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -7.5 \cdot 10^{-26}:\\
\;\;\;\;U \cdot \left(2 - U\right)\\

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

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


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

    1. Initial program 95.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. *-commutative95.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*95.0%

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

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

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

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

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

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

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

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

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

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

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

    if -7.4999999999999994e-26 < l < 2.3e10

    1. Initial program 76.6%

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

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

    if 2.3e10 < 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-rr15.8%

      \[\leadsto \color{blue}{U \cdot U} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification40.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7.5 \cdot 10^{-26}:\\ \;\;\;\;U \cdot \left(2 - U\right)\\ \mathbf{elif}\;\ell \leq 23000000000:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]

Alternative 14: 54.6% accurate, 44.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 15: 2.7% accurate, 312.0× speedup?

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

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

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

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

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

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

    \[\leadsto 1 \]

Alternative 16: 37.3% accurate, 312.0× speedup?

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

\\
U
\end{array}
Derivation
  1. Initial program 88.1%

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

    \[\leadsto \color{blue}{U} \]
  3. Final simplification33.8%

    \[\leadsto U \]

Reproduce

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