Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.1% → 99.9%
Time: 10.9s
Alternatives: 14
Speedup: 1.4×

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 14 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.1% 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.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t\_0 \leq -0.01 \lor \neg \left(t\_0 \leq 2 \cdot 10^{-5}\right):\\ \;\;\;\;\left(t\_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(\left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\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.01) (not (<= t_0 2e-5)))
     (+ (* (* t_0 J) (cos (/ K 2.0))) U)
     (+
      U
      (*
       l
       (* (* J (cos (* K 0.5))) (fma 0.3333333333333333 (pow l 2.0) 2.0)))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -0.01) || !(t_0 <= 2e-5)) {
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	} else {
		tmp = U + (l * ((J * cos((K * 0.5))) * fma(0.3333333333333333, pow(l, 2.0), 2.0)));
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= -0.01) || !(t_0 <= 2e-5))
		tmp = Float64(Float64(Float64(t_0 * J) * cos(Float64(K / 2.0))) + U);
	else
		tmp = Float64(U + Float64(l * Float64(Float64(J * cos(Float64(K * 0.5))) * fma(0.3333333333333333, (l ^ 2.0), 2.0))));
	end
	return 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.01], N[Not[LessEqual[t$95$0, 2e-5]], $MachinePrecision]], N[(N[(N[(t$95$0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(l * N[(N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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

    1. Initial program 100.0%

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

    if -0.0100000000000000002 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.00000000000000016e-5

    1. Initial program 69.5%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\ell \cdot \left(\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\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.01 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 2 \cdot 10^{-5}\right):\\ \;\;\;\;\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(\left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 99.9% 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 -0.01 \lor \neg \left(t\_1 \leq 2 \cdot 10^{-5}\right):\\ \;\;\;\;\left(t\_1 \cdot J\right) \cdot t\_0 + U\\ \mathbf{else}:\\ \;\;\;\;U + t\_0 \cdot \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right) + J \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 -0.01) (not (<= t_1 2e-5)))
     (+ (* (* t_1 J) t_0) U)
     (+
      U
      (* t_0 (* l (+ (* 0.3333333333333333 (* J (pow l 2.0))) (* J 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 <= -0.01) || !(t_1 <= 2e-5)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * pow(l, 2.0))) + (J * 2.0))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    t_1 = exp(l) - exp(-l)
    if ((t_1 <= (-0.01d0)) .or. (.not. (t_1 <= 2d-5))) then
        tmp = ((t_1 * j) * t_0) + u
    else
        tmp = u + (t_0 * (l * ((0.3333333333333333d0 * (j * (l ** 2.0d0))) + (j * 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 <= -0.01) || !(t_1 <= 2e-5)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * Math.pow(l, 2.0))) + (J * 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 <= -0.01) or not (t_1 <= 2e-5):
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * math.pow(l, 2.0))) + (J * 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 <= -0.01) || !(t_1 <= 2e-5))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(l * Float64(Float64(0.3333333333333333 * Float64(J * (l ^ 2.0))) + Float64(J * 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 <= -0.01) || ~((t_1 <= 2e-5)))
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * (l ^ 2.0))) + (J * 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, -0.01], N[Not[LessEqual[t$95$1, 2e-5]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(l * N[(N[(0.3333333333333333 * N[(J * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(J * 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 -0.01 \lor \neg \left(t\_1 \leq 2 \cdot 10^{-5}\right):\\
\;\;\;\;\left(t\_1 \cdot J\right) \cdot t\_0 + U\\

\mathbf{else}:\\
\;\;\;\;U + t\_0 \cdot \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right) + J \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))) < -0.0100000000000000002 or 2.00000000000000016e-5 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

    if -0.0100000000000000002 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.00000000000000016e-5

    1. Initial program 69.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -0.01 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 2 \cdot 10^{-5}\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(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right) + J \cdot 2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 94.6% accurate, 1.3× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.9999999999999996e76 or 5 < 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 95.6%

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

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

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

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

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

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

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

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

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

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

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

    if -5.9999999999999996e76 < l < -0.0060000000000000001

    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 K around 0 84.7%

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

    if -0.0060000000000000001 < l < 5

    1. Initial program 69.5%

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

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

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

Alternative 4: 94.6% accurate, 1.4× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.1000000000000002e76 or 5 < 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 95.6%

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

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

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

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

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

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

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

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

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

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

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

    if -5.1000000000000002e76 < l < -0.0060000000000000001

    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 K around 0 84.7%

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

    if -0.0060000000000000001 < l < 5

    1. Initial program 69.5%

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

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

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

Alternative 5: 94.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := U + {\ell}^{5} \cdot \left(J \cdot \left(t\_0 \cdot 0.016666666666666666\right)\right)\\ \mathbf{if}\;\ell \leq -5.1 \cdot 10^{+76}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -0.0048:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 3.3:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 \cdot t\_0\right)\right)\\ \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) (* J (* t_0 0.016666666666666666))))))
   (if (<= l -5.1e+76)
     t_1
     (if (<= l -0.0048)
       (+ (* (- (exp l) (exp (- l))) J) U)
       (if (<= l 3.3) (+ U (* l (* J (* 2.0 t_0)))) 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) * (J * (t_0 * 0.016666666666666666)));
	double tmp;
	if (l <= -5.1e+76) {
		tmp = t_1;
	} else if (l <= -0.0048) {
		tmp = ((exp(l) - exp(-l)) * J) + U;
	} else if (l <= 3.3) {
		tmp = U + (l * (J * (2.0 * t_0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k * 0.5d0))
    t_1 = u + ((l ** 5.0d0) * (j * (t_0 * 0.016666666666666666d0)))
    if (l <= (-5.1d+76)) then
        tmp = t_1
    else if (l <= (-0.0048d0)) then
        tmp = ((exp(l) - exp(-l)) * j) + u
    else if (l <= 3.3d0) then
        tmp = u + (l * (j * (2.0d0 * t_0)))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K * 0.5));
	double t_1 = U + (Math.pow(l, 5.0) * (J * (t_0 * 0.016666666666666666)));
	double tmp;
	if (l <= -5.1e+76) {
		tmp = t_1;
	} else if (l <= -0.0048) {
		tmp = ((Math.exp(l) - Math.exp(-l)) * J) + U;
	} else if (l <= 3.3) {
		tmp = U + (l * (J * (2.0 * t_0)));
	} 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) * (J * (t_0 * 0.016666666666666666)))
	tmp = 0
	if l <= -5.1e+76:
		tmp = t_1
	elif l <= -0.0048:
		tmp = ((math.exp(l) - math.exp(-l)) * J) + U
	elif l <= 3.3:
		tmp = U + (l * (J * (2.0 * t_0)))
	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(J * Float64(t_0 * 0.016666666666666666))))
	tmp = 0.0
	if (l <= -5.1e+76)
		tmp = t_1;
	elseif (l <= -0.0048)
		tmp = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U);
	elseif (l <= 3.3)
		tmp = Float64(U + Float64(l * Float64(J * Float64(2.0 * t_0))));
	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) * (J * (t_0 * 0.016666666666666666)));
	tmp = 0.0;
	if (l <= -5.1e+76)
		tmp = t_1;
	elseif (l <= -0.0048)
		tmp = ((exp(l) - exp(-l)) * J) + U;
	elseif (l <= 3.3)
		tmp = U + (l * (J * (2.0 * t_0)));
	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[(J * N[(t$95$0 * 0.016666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5.1e+76], t$95$1, If[LessEqual[l, -0.0048], N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[l, 3.3], N[(U + N[(l * N[(J * N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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(J \cdot \left(t\_0 \cdot 0.016666666666666666\right)\right)\\
\mathbf{if}\;\ell \leq -5.1 \cdot 10^{+76}:\\
\;\;\;\;t\_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.1000000000000002e76 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 95.6%

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

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

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

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

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

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

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

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

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

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

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

    if -5.1000000000000002e76 < l < -0.00479999999999999958

    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 K around 0 84.7%

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

    if -0.00479999999999999958 < l < 3.2999999999999998

    1. Initial program 69.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 86.5% accurate, 1.4× speedup?

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

\mathbf{else}:\\
\;\;\;\;U + \ell \cdot \left(J \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 < -4.00000000000000019e-4 or 2.79999999999999984e-9 < l

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

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

    if -4.00000000000000019e-4 < l < 2.79999999999999984e-9

    1. Initial program 69.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 59.1% accurate, 1.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.050000000000000003

    1. Initial program 86.1%

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

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

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

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

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

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

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

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

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

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

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

    if -0.050000000000000003 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 84.5%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 93.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. *-commutative93.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. Simplified93.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 66.6%

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

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

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

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

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

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

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

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

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

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

Alternative 8: 56.2% accurate, 2.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.050000000000000003

    1. Initial program 86.1%

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

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

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

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

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

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

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

    if -0.050000000000000003 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 84.5%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 93.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. *-commutative93.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. Simplified93.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 66.6%

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

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

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

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

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

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

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

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

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

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

Alternative 9: 72.2% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 400000000:\\
\;\;\;\;U + \ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right) + J \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;U + \ell \cdot \left(J \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 K #s(literal 2 binary64)) < 4e8

    1. Initial program 84.9%

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

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

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

    if 4e8 < (/.f64 K #s(literal 2 binary64))

    1. Initial program 84.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 92.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. *-commutative92.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. Simplified92.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 0 65.5%

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

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

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

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

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

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

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

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

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

Alternative 10: 64.2% accurate, 2.8× speedup?

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

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

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

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

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

Alternative 11: 64.2% accurate, 2.8× speedup?

\[\begin{array}{l} \\ U + \ell \cdot \left(J \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\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(l * Float64(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[(l * N[(J * N[(2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in l around 0 93.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. *-commutative93.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. Simplified93.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 0 66.5%

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

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

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

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

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

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

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

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

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

Alternative 12: 54.2% accurate, 44.6× speedup?

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

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

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in l around 0 93.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. *-commutative93.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. Simplified93.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 0 66.5%

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

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

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

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

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

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

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

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

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

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

Alternative 13: 26.8% accurate, 62.4× speedup?

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

\\
U + J \cdot -4
\end{array}
Derivation
  1. Initial program 84.9%

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

    \[\leadsto \left(J \cdot \color{blue}{-4}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  4. Taylor expanded in K around 0 27.3%

    \[\leadsto \color{blue}{-4 \cdot J} + U \]
  5. Step-by-step derivation
    1. *-commutative27.3%

      \[\leadsto \color{blue}{J \cdot -4} + U \]
  6. Simplified27.3%

    \[\leadsto \color{blue}{J \cdot -4} + U \]
  7. Final simplification27.3%

    \[\leadsto U + J \cdot -4 \]
  8. Add Preprocessing

Alternative 14: 26.9% accurate, 62.4× speedup?

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

\\
U + J \cdot -0.5
\end{array}
Derivation
  1. Initial program 84.9%

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

    \[\leadsto \left(J \cdot \color{blue}{-0.5}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  4. Taylor expanded in K around 0 27.3%

    \[\leadsto \color{blue}{-0.5 \cdot J} + U \]
  5. Step-by-step derivation
    1. *-commutative27.3%

      \[\leadsto \color{blue}{J \cdot -0.5} + U \]
  6. Simplified27.3%

    \[\leadsto \color{blue}{J \cdot -0.5} + U \]
  7. Final simplification27.3%

    \[\leadsto U + J \cdot -0.5 \]
  8. Add Preprocessing

Reproduce

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