Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.2% → 99.8%
Time: 13.7s
Alternatives: 15
Speedup: 1.3×

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.2% 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 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 0.0005\right):\\ \;\;\;\;\left(t\_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot 0.016666666666666666\right)\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.0005)))
     (+ (* (* t_0 J) (cos (/ K 2.0))) U)
     (+
      U
      (*
       J
       (*
        l
        (*
         (cos (* K 0.5))
         (+
          2.0
          (*
           (pow l 2.0)
           (+ 0.3333333333333333 (* (pow l 2.0) 0.016666666666666666)))))))))))
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.0005)) {
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	} else {
		tmp = U + (J * (l * (cos((K * 0.5)) * (2.0 + (pow(l, 2.0) * (0.3333333333333333 + (pow(l, 2.0) * 0.016666666666666666)))))));
	}
	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.0005)) {
		tmp = ((t_0 * J) * Math.cos((K / 2.0))) + U;
	} else {
		tmp = U + (J * (l * (Math.cos((K * 0.5)) * (2.0 + (Math.pow(l, 2.0) * (0.3333333333333333 + (Math.pow(l, 2.0) * 0.016666666666666666)))))));
	}
	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.0005):
		tmp = ((t_0 * J) * math.cos((K / 2.0))) + U
	else:
		tmp = U + (J * (l * (math.cos((K * 0.5)) * (2.0 + (math.pow(l, 2.0) * (0.3333333333333333 + (math.pow(l, 2.0) * 0.016666666666666666)))))))
	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.0005))
		tmp = Float64(Float64(Float64(t_0 * J) * cos(Float64(K / 2.0))) + U);
	else
		tmp = Float64(U + Float64(J * Float64(l * Float64(cos(Float64(K * 0.5)) * Float64(2.0 + Float64((l ^ 2.0) * Float64(0.3333333333333333 + Float64((l ^ 2.0) * 0.016666666666666666))))))));
	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.0005)))
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	else
		tmp = U + (J * (l * (cos((K * 0.5)) * (2.0 + ((l ^ 2.0) * (0.3333333333333333 + ((l ^ 2.0) * 0.016666666666666666)))))));
	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.0005]], $MachinePrecision]], N[(N[(N[(t$95$0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(J * N[(l * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(2.0 + N[(N[Power[l, 2.0], $MachinePrecision] * N[(0.3333333333333333 + N[(N[Power[l, 2.0], $MachinePrecision] * 0.016666666666666666), $MachinePrecision]), $MachinePrecision]), $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.0005\right):\\
\;\;\;\;\left(t\_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\

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

    1. Initial program 100.0%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 5.0000000000000001e-4

    1. Initial program 74.4%

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

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

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

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

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

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

Alternative 2: 99.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t\_0 \leq -0.005 \lor \neg \left(t\_0 \leq 0.0005\right):\\ \;\;\;\;\left(t\_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(2 + {\ell}^{2} \cdot 0.3333333333333333\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 -0.005) (not (<= t_0 0.0005)))
     (+ (* (* t_0 J) (cos (/ K 2.0))) U)
     (+
      U
      (*
       J
       (*
        l
        (* (cos (* K 0.5)) (+ 2.0 (* (pow l 2.0) 0.3333333333333333)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -0.005) || !(t_0 <= 0.0005)) {
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	} else {
		tmp = U + (J * (l * (cos((K * 0.5)) * (2.0 + (pow(l, 2.0) * 0.3333333333333333)))));
	}
	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 <= (-0.005d0)) .or. (.not. (t_0 <= 0.0005d0))) then
        tmp = ((t_0 * j) * cos((k / 2.0d0))) + u
    else
        tmp = u + (j * (l * (cos((k * 0.5d0)) * (2.0d0 + ((l ** 2.0d0) * 0.3333333333333333d0)))))
    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 <= -0.005) || !(t_0 <= 0.0005)) {
		tmp = ((t_0 * J) * Math.cos((K / 2.0))) + U;
	} else {
		tmp = U + (J * (l * (Math.cos((K * 0.5)) * (2.0 + (Math.pow(l, 2.0) * 0.3333333333333333)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_0 <= -0.005) or not (t_0 <= 0.0005):
		tmp = ((t_0 * J) * math.cos((K / 2.0))) + U
	else:
		tmp = U + (J * (l * (math.cos((K * 0.5)) * (2.0 + (math.pow(l, 2.0) * 0.3333333333333333)))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= -0.005) || !(t_0 <= 0.0005))
		tmp = Float64(Float64(Float64(t_0 * J) * cos(Float64(K / 2.0))) + U);
	else
		tmp = Float64(U + Float64(J * Float64(l * Float64(cos(Float64(K * 0.5)) * Float64(2.0 + Float64((l ^ 2.0) * 0.3333333333333333))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_0 <= -0.005) || ~((t_0 <= 0.0005)))
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	else
		tmp = U + (J * (l * (cos((K * 0.5)) * (2.0 + ((l ^ 2.0) * 0.3333333333333333)))));
	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, -0.005], N[Not[LessEqual[t$95$0, 0.0005]], $MachinePrecision]], N[(N[(N[(t$95$0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(J * N[(l * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(2.0 + N[(N[Power[l, 2.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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

    1. Initial program 99.9%

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

    if -0.0050000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 5.0000000000000001e-4

    1. Initial program 73.7%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 99.9% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;t\_1 \leq 0.0005:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(t\_0 \cdot \left(2 + {\ell}^{2} \cdot 0.3333333333333333\right)\right)\right)\\

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


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

    1. Initial program 99.7%

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

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

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

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

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

    if -0.0050000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 5.0000000000000001e-4

    1. Initial program 73.7%

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

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

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

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

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

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

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

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

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

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

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

    if 5.0000000000000001e-4 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification99.9%

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

Alternative 4: 87.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+282}:\\ \;\;\;\;\mathsf{fma}\left(J, \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot 2\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 + U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* (- (exp l) (exp (- l))) J)))
   (if (<= t_0 (- INFINITY))
     t_0
     (if (<= t_0 2e+282) (fma J (* (cos (/ K 2.0)) (* l 2.0)) U) (+ t_0 U)))))
double code(double J, double l, double K, double U) {
	double t_0 = (exp(l) - exp(-l)) * J;
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = t_0;
	} else if (t_0 <= 2e+282) {
		tmp = fma(J, (cos((K / 2.0)) * (l * 2.0)), U);
	} else {
		tmp = t_0 + U;
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(Float64(exp(l) - exp(Float64(-l))) * J)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = t_0;
	elseif (t_0 <= 2e+282)
		tmp = fma(J, Float64(cos(Float64(K / 2.0)) * Float64(l * 2.0)), U);
	else
		tmp = Float64(t_0 + U);
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$0, If[LessEqual[t$95$0, 2e+282], N[(J * N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(t$95$0 + U), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+282}:\\
\;\;\;\;\mathsf{fma}\left(J, \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot 2\right), U\right)\\

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


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

    1. Initial program 100.0%

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

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

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

    if -inf.0 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < 2.00000000000000007e282

    1. Initial program 74.4%

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

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

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

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

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

    if 2.00000000000000007e282 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))))

    1. Initial program 100.0%

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

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

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

Alternative 5: 87.2% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;t\_0\\

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

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


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

    1. Initial program 100.0%

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

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

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

    if -inf.0 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < 2.00000000000000007e282

    1. Initial program 74.4%

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

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

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

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

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

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

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

    if 2.00000000000000007e282 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))))

    1. Initial program 100.0%

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

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

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

Alternative 6: 87.2% accurate, 0.5× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

    if -inf.0 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < 2.00000000000000007e282

    1. Initial program 74.4%

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

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

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

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

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

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

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

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

Alternative 7: 96.9% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + {\ell}^{5} \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 0.016666666666666666\right)\right)\\ t_1 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{if}\;\ell \leq -6.4 \cdot 10^{+49}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -260:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq 0.18:\\ \;\;\;\;\mathsf{fma}\left(J, \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot 2\right), U\right)\\ \mathbf{elif}\;\ell \leq 1.42 \cdot 10^{+41}:\\ \;\;\;\;t\_1 + U\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0
         (+ U (* (pow l 5.0) (* (cos (* K 0.5)) (* J 0.016666666666666666)))))
        (t_1 (* (- (exp l) (exp (- l))) J)))
   (if (<= l -6.4e+49)
     t_0
     (if (<= l -260.0)
       t_1
       (if (<= l 0.18)
         (fma J (* (cos (/ K 2.0)) (* l 2.0)) U)
         (if (<= l 1.42e+41) (+ t_1 U) t_0))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (pow(l, 5.0) * (cos((K * 0.5)) * (J * 0.016666666666666666)));
	double t_1 = (exp(l) - exp(-l)) * J;
	double tmp;
	if (l <= -6.4e+49) {
		tmp = t_0;
	} else if (l <= -260.0) {
		tmp = t_1;
	} else if (l <= 0.18) {
		tmp = fma(J, (cos((K / 2.0)) * (l * 2.0)), U);
	} else if (l <= 1.42e+41) {
		tmp = t_1 + U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(U + Float64((l ^ 5.0) * Float64(cos(Float64(K * 0.5)) * Float64(J * 0.016666666666666666))))
	t_1 = Float64(Float64(exp(l) - exp(Float64(-l))) * J)
	tmp = 0.0
	if (l <= -6.4e+49)
		tmp = t_0;
	elseif (l <= -260.0)
		tmp = t_1;
	elseif (l <= 0.18)
		tmp = fma(J, Float64(cos(Float64(K / 2.0)) * Float64(l * 2.0)), U);
	elseif (l <= 1.42e+41)
		tmp = Float64(t_1 + U);
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[Power[l, 5.0], $MachinePrecision] * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(J * 0.016666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]}, If[LessEqual[l, -6.4e+49], t$95$0, If[LessEqual[l, -260.0], t$95$1, If[LessEqual[l, 0.18], N[(J * N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[l, 1.42e+41], N[(t$95$1 + U), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + {\ell}^{5} \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 0.016666666666666666\right)\right)\\
t_1 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;\ell \leq -6.4 \cdot 10^{+49}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -260:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq 0.18:\\
\;\;\;\;\mathsf{fma}\left(J, \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot 2\right), U\right)\\

\mathbf{elif}\;\ell \leq 1.42 \cdot 10^{+41}:\\
\;\;\;\;t\_1 + U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -6.40000000000000028e49 or 1.42000000000000007e41 < l

    1. Initial program 100.0%

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + \color{blue}{{\ell}^{2} \cdot 0.016666666666666666}\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified98.1%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot 0.016666666666666666\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 98.1%

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

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

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

        \[\leadsto \color{blue}{\left(0.016666666666666666 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot {\ell}^{5}} + U \]
      4. *-commutative98.1%

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

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

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

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

    if -6.40000000000000028e49 < l < -260

    1. Initial program 100.0%

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

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

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

    if -260 < l < 0.17999999999999999

    1. Initial program 74.4%

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

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

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

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

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

    if 0.17999999999999999 < l < 1.42000000000000007e41

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6.4 \cdot 10^{+49}:\\ \;\;\;\;U + {\ell}^{5} \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 0.016666666666666666\right)\right)\\ \mathbf{elif}\;\ell \leq -260:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.18:\\ \;\;\;\;\mathsf{fma}\left(J, \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot 2\right), U\right)\\ \mathbf{elif}\;\ell \leq 1.42 \cdot 10^{+41}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + {\ell}^{5} \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 0.016666666666666666\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 97.1% accurate, 1.3× speedup?

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

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

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

\mathbf{elif}\;\ell \leq 0.018:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(t\_0 \cdot \left(2 + {\ell}^{2} \cdot 0.3333333333333333\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 1.42 \cdot 10^{+41}:\\
\;\;\;\;t\_2 + U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -6.40000000000000028e49 or 1.42000000000000007e41 < l

    1. Initial program 100.0%

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + \color{blue}{{\ell}^{2} \cdot 0.016666666666666666}\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified98.1%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot 0.016666666666666666\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 98.1%

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

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

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

        \[\leadsto \color{blue}{\left(0.016666666666666666 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot {\ell}^{5}} + U \]
      4. *-commutative98.1%

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

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

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

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

    if -6.40000000000000028e49 < l < -26.5

    1. Initial program 100.0%

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

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

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

    if -26.5 < l < 0.0179999999999999986

    1. Initial program 74.4%

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

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

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

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

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

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

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

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

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

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

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

    if 0.0179999999999999986 < l < 1.42000000000000007e41

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6.4 \cdot 10^{+49}:\\ \;\;\;\;U + {\ell}^{5} \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 0.016666666666666666\right)\right)\\ \mathbf{elif}\;\ell \leq -26.5:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.018:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(2 + {\ell}^{2} \cdot 0.3333333333333333\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.42 \cdot 10^{+41}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + {\ell}^{5} \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 0.016666666666666666\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 82.1% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.7 \cdot 10^{+16} \lor \neg \left(\ell \leq 1.08 \cdot 10^{+19}\right):\\
\;\;\;\;U + 0.016666666666666666 \cdot \left(J \cdot {\ell}^{5}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -3.7e16 or 1.08e19 < l

    1. Initial program 100.0%

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + \color{blue}{{\ell}^{2} \cdot 0.016666666666666666}\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified90.2%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot 0.016666666666666666\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 90.2%

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

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

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

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

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

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

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

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

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

    if -3.7e16 < l < 1.08e19

    1. Initial program 75.3%

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

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

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

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

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

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

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

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

Alternative 10: 75.5% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.15 \cdot 10^{+16} \lor \neg \left(\ell \leq 3.3\right):\\
\;\;\;\;U + 0.016666666666666666 \cdot \left(J \cdot {\ell}^{5}\right)\\

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


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

    1. Initial program 100.0%

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + \color{blue}{{\ell}^{2} \cdot 0.016666666666666666}\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified88.9%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot 0.016666666666666666\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 88.9%

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

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

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

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

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

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

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

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

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

    if -3.15e16 < l < 3.2999999999999998

    1. Initial program 74.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot J, \ell, U\right)} \]
    11. Simplified83.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.15 \cdot 10^{+16} \lor \neg \left(\ell \leq 3.3\right):\\ \;\;\;\;U + 0.016666666666666666 \cdot \left(J \cdot {\ell}^{5}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J \cdot 2, \ell, U\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 54.5% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(J \cdot 2, \ell, U\right) \end{array} \]
(FPCore (J l K U) :precision binary64 (fma (* J 2.0) l U))
double code(double J, double l, double K, double U) {
	return fma((J * 2.0), l, U);
}
function code(J, l, K, U)
	return fma(Float64(J * 2.0), l, U)
end
code[J_, l_, K_, U_] := N[(N[(J * 2.0), $MachinePrecision] * l + U), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(J \cdot 2, \ell, U\right)
\end{array}
Derivation
  1. Initial program 86.6%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot J, \ell, U\right)} \]
  11. Simplified54.1%

    \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot J, \ell, U\right)} \]
  12. Final simplification54.1%

    \[\leadsto \mathsf{fma}\left(J \cdot 2, \ell, U\right) \]
  13. Add Preprocessing

Alternative 12: 41.9% accurate, 23.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -6.5000000000000005e49 or 1.3499999999999999e23 < 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. associate-*l*100.0%

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

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

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

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

    if -6.5000000000000005e49 < l < 1.3499999999999999e23

    1. Initial program 76.7%

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

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

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

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

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

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

Alternative 13: 42.2% accurate, 23.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -750:\\
\;\;\;\;U \cdot U - U\\

\mathbf{elif}\;\ell \leq 1.4 \cdot 10^{+23}:\\
\;\;\;\;U\\

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


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

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Applied egg-rr16.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(U, U, -U\right)} \]
    7. Step-by-step derivation
      1. fmm-undef16.6%

        \[\leadsto \color{blue}{U \cdot U - U} \]
    8. Simplified16.6%

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

    if -750 < l < 1.4e23

    1. Initial program 75.3%

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

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

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

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

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

    if 1.4e23 < 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. associate-*l*100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -750:\\ \;\;\;\;U \cdot U - U\\ \mathbf{elif}\;\ell \leq 1.4 \cdot 10^{+23}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]
  5. Add Preprocessing

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

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

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

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

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

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

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

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

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

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

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

Alternative 15: 36.9% accurate, 312.0× speedup?

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

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

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

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

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

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

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

    \[\leadsto U \]
  7. Add Preprocessing

Reproduce

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