Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.2% → 99.5%
Time: 11.7s
Alternatives: 16
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 16 alternatives:

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

Initial Program: 86.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.5% accurate, 0.3× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K 2))) < -4.9999999999999998e-235 or -0.0 < (*.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K 2)))

    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 -4.9999999999999998e-235 < (*.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K 2))) < -0.0

    1. Initial program 70.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(2 \cdot \ell\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}\;\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) \leq -5 \cdot 10^{-235} \lor \neg \left(\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) \leq 0\right):\\ \;\;\;\;\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 96.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := \left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot t\_0\\ \mathbf{if}\;t\_1 \leq 0:\\ \;\;\;\;t\_0 \cdot \left(J \cdot \left(0.016666666666666666 \cdot {\ell}^{5} + \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\right) + U\\ \mathbf{else}:\\ \;\;\;\;t\_1 + U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (* (* J (- (exp l) (exp (- l)))) t_0)))
   (if (<= t_1 0.0)
     (+
      (*
       t_0
       (*
        J
        (+
         (* 0.016666666666666666 (pow l 5.0))
         (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))
      U)
     (+ t_1 U))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = (J * (exp(l) - exp(-l))) * t_0;
	double tmp;
	if (t_1 <= 0.0) {
		tmp = (t_0 * (J * ((0.016666666666666666 * pow(l, 5.0)) + ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))))) + U;
	} else {
		tmp = t_1 + 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 / 2.0d0))
    t_1 = (j * (exp(l) - exp(-l))) * t_0
    if (t_1 <= 0.0d0) then
        tmp = (t_0 * (j * ((0.016666666666666666d0 * (l ** 5.0d0)) + ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))) + u
    else
        tmp = t_1 + 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 / 2.0));
	double t_1 = (J * (Math.exp(l) - Math.exp(-l))) * t_0;
	double tmp;
	if (t_1 <= 0.0) {
		tmp = (t_0 * (J * ((0.016666666666666666 * Math.pow(l, 5.0)) + ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))))) + U;
	} else {
		tmp = t_1 + U;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = (J * (math.exp(l) - math.exp(-l))) * t_0
	tmp = 0
	if t_1 <= 0.0:
		tmp = (t_0 * (J * ((0.016666666666666666 * math.pow(l, 5.0)) + ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))))) + U
	else:
		tmp = t_1 + U
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * t_0)
	tmp = 0.0
	if (t_1 <= 0.0)
		tmp = Float64(Float64(t_0 * Float64(J * Float64(Float64(0.016666666666666666 * (l ^ 5.0)) + Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))))) + U);
	else
		tmp = Float64(t_1 + U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = (J * (exp(l) - exp(-l))) * t_0;
	tmp = 0.0;
	if (t_1 <= 0.0)
		tmp = (t_0 * (J * ((0.016666666666666666 * (l ^ 5.0)) + ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))))) + U;
	else
		tmp = t_1 + U;
	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[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, 0.0], N[(N[(t$95$0 * N[(J * N[(N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(t$95$1 + U), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := \left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot t\_0\\
\mathbf{if}\;t\_1 \leq 0:\\
\;\;\;\;t\_0 \cdot \left(J \cdot \left(0.016666666666666666 \cdot {\ell}^{5} + \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\right) + U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K 2))) < -0.0

    1. Initial program 79.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 97.9%

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

    if -0.0 < (*.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K 2)))

    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 2 regimes into one program.
  4. Final simplification98.5%

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

Alternative 3: 87.3% accurate, 0.5× 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 2000000000\right):\\ \;\;\;\;J \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 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 2000000000.0)))
     (* J t_0)
     (+ U (* (cos (/ K 2.0)) (* J (* l 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 <= 2000000000.0)) {
		tmp = J * t_0;
	} else {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = exp(l) - exp(-l)
    if ((t_0 <= (-0.01d0)) .or. (.not. (t_0 <= 2000000000.0d0))) then
        tmp = j * t_0
    else
        tmp = u + (cos((k / 2.0d0)) * (j * (l * 2.0d0)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_0 <= -0.01) || !(t_0 <= 2000000000.0)) {
		tmp = J * t_0;
	} else {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_0 <= -0.01) or not (t_0 <= 2000000000.0):
		tmp = J * t_0
	else:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * 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 <= 2000000000.0))
		tmp = Float64(J * t_0);
	else
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	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.01) || ~((t_0 <= 2000000000.0)))
		tmp = J * t_0;
	else
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	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.01], N[Not[LessEqual[t$95$0, 2000000000.0]], $MachinePrecision]], N[(J * t$95$0), $MachinePrecision], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 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 2000000000\right):\\
\;\;\;\;J \cdot t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -0.0100000000000000002 or 2e9 < (-.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
    3. Taylor expanded in K around 0 78.8%

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

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

    if -0.0100000000000000002 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2e9

    1. Initial program 70.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 99.3%

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

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

Alternative 4: 81.5% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;t\_0 \leq -0.1:\\
\;\;\;\;U + \left(-0.25 \cdot \left(J \cdot \left(\ell \cdot {K}^{2}\right)\right) + 2 \cdot \left(J \cdot \ell\right)\right)\\

\mathbf{elif}\;t\_0 \leq 0.34:\\
\;\;\;\;t\_1\\

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


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

    1. Initial program 79.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 73.5%

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

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

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

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

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

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

    if -0.330000000000000016 < (cos.f64 (/.f64 K 2)) < -0.10000000000000001

    1. Initial program 95.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 24.9%

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

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

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

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

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

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

      \[\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 \]

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(0.016666666666666666 \cdot {\ell}^{5} + \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)\right)} + U \]
    5. Taylor expanded in l around 0 93.6%

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

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

Alternative 5: 89.9% accurate, 0.7× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;U + t\_0 \cdot \left({\ell}^{5} \cdot \left(J \cdot 0.016666666666666666\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)))) < 1.00000000000000006e-288

    1. Initial program 79.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 95.6%

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

    if 1.00000000000000006e-288 < (*.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 l around 0 85.7%

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

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

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

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

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

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

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

Alternative 6: 94.4% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := U + t\_0 \cdot \left({\ell}^{5} \cdot \left(J \cdot 0.016666666666666666\right)\right)\\ \mathbf{if}\;\ell \leq -1.35 \cdot 10^{+45}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -0.0062:\\ \;\;\;\;J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 3.3:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1 (+ U (* t_0 (* (pow l 5.0) (* J 0.016666666666666666))))))
   (if (<= l -1.35e+45)
     t_1
     (if (<= l -0.0062)
       (* J (- (exp l) (exp (- l))))
       (if (<= l 3.3) (+ U (* t_0 (* J (* l 2.0)))) t_1)))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = U + (t_0 * (pow(l, 5.0) * (J * 0.016666666666666666)));
	double tmp;
	if (l <= -1.35e+45) {
		tmp = t_1;
	} else if (l <= -0.0062) {
		tmp = J * (exp(l) - exp(-l));
	} else if (l <= 3.3) {
		tmp = U + (t_0 * (J * (l * 2.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 / 2.0d0))
    t_1 = u + (t_0 * ((l ** 5.0d0) * (j * 0.016666666666666666d0)))
    if (l <= (-1.35d+45)) then
        tmp = t_1
    else if (l <= (-0.0062d0)) then
        tmp = j * (exp(l) - exp(-l))
    else if (l <= 3.3d0) then
        tmp = u + (t_0 * (j * (l * 2.0d0)))
    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 / 2.0));
	double t_1 = U + (t_0 * (Math.pow(l, 5.0) * (J * 0.016666666666666666)));
	double tmp;
	if (l <= -1.35e+45) {
		tmp = t_1;
	} else if (l <= -0.0062) {
		tmp = J * (Math.exp(l) - Math.exp(-l));
	} else if (l <= 3.3) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = U + (t_0 * (math.pow(l, 5.0) * (J * 0.016666666666666666)))
	tmp = 0
	if l <= -1.35e+45:
		tmp = t_1
	elif l <= -0.0062:
		tmp = J * (math.exp(l) - math.exp(-l))
	elif l <= 3.3:
		tmp = U + (t_0 * (J * (l * 2.0)))
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(U + Float64(t_0 * Float64((l ^ 5.0) * Float64(J * 0.016666666666666666))))
	tmp = 0.0
	if (l <= -1.35e+45)
		tmp = t_1;
	elseif (l <= -0.0062)
		tmp = Float64(J * Float64(exp(l) - exp(Float64(-l))));
	elseif (l <= 3.3)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0))));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = U + (t_0 * ((l ^ 5.0) * (J * 0.016666666666666666)));
	tmp = 0.0;
	if (l <= -1.35e+45)
		tmp = t_1;
	elseif (l <= -0.0062)
		tmp = J * (exp(l) - exp(-l));
	elseif (l <= 3.3)
		tmp = U + (t_0 * (J * (l * 2.0)));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(t$95$0 * N[(N[Power[l, 5.0], $MachinePrecision] * N[(J * 0.016666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.35e+45], t$95$1, If[LessEqual[l, -0.0062], N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 3.3], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := U + t\_0 \cdot \left({\ell}^{5} \cdot \left(J \cdot 0.016666666666666666\right)\right)\\
\mathbf{if}\;\ell \leq -1.35 \cdot 10^{+45}:\\
\;\;\;\;t\_1\\

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

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

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


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

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

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

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

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

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

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

    if -1.34999999999999992e45 < l < -0.00619999999999999978

    1. Initial program 98.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 70.1%

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

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

    if -0.00619999999999999978 < l < 3.2999999999999998

    1. Initial program 70.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(2 \cdot \ell\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification95.4%

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

Alternative 7: 82.1% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 81.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 67.9%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(0.016666666666666666 \cdot {\ell}^{5} + \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)\right)} + U \]
    5. Taylor expanded in l around 0 93.6%

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

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

Alternative 8: 87.4% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{if}\;\ell \leq -0.0062:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 23.5:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 + U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* J (- (exp l) (exp (- l))))))
   (if (<= l -0.0062)
     t_0
     (if (<= l 23.5) (+ U (* (cos (/ K 2.0)) (* J (* l 2.0)))) (+ t_0 U)))))
double code(double J, double l, double K, double U) {
	double t_0 = J * (exp(l) - exp(-l));
	double tmp;
	if (l <= -0.0062) {
		tmp = t_0;
	} else if (l <= 23.5) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else {
		tmp = t_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) :: tmp
    t_0 = j * (exp(l) - exp(-l))
    if (l <= (-0.0062d0)) then
        tmp = t_0
    else if (l <= 23.5d0) then
        tmp = u + (cos((k / 2.0d0)) * (j * (l * 2.0d0)))
    else
        tmp = t_0 + u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = J * (Math.exp(l) - Math.exp(-l));
	double tmp;
	if (l <= -0.0062) {
		tmp = t_0;
	} else if (l <= 23.5) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	} else {
		tmp = t_0 + U;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = J * (math.exp(l) - math.exp(-l))
	tmp = 0
	if l <= -0.0062:
		tmp = t_0
	elif l <= 23.5:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * 2.0)))
	else:
		tmp = t_0 + U
	return tmp
function code(J, l, K, U)
	t_0 = Float64(J * Float64(exp(l) - exp(Float64(-l))))
	tmp = 0.0
	if (l <= -0.0062)
		tmp = t_0;
	elseif (l <= 23.5)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	else
		tmp = Float64(t_0 + U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = J * (exp(l) - exp(-l));
	tmp = 0.0;
	if (l <= -0.0062)
		tmp = t_0;
	elseif (l <= 23.5)
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	else
		tmp = t_0 + U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -0.0062], t$95$0, If[LessEqual[l, 23.5], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + U), $MachinePrecision]]]]
\begin{array}{l}

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

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

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


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

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

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

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

    if -0.00619999999999999978 < l < 23.5

    1. Initial program 70.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 99.3%

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

    if 23.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 K around 0 79.5%

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

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

Alternative 9: 82.0% accurate, 2.6× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.4e45 or 780 < 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 92.8%

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

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

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

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

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

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

      \[\leadsto \color{blue}{U + 0.016666666666666666 \cdot \left(J \cdot {\ell}^{5}\right)} \]
    8. Step-by-step derivation
      1. +-commutative76.1%

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

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

    if -1.4e45 < l < 780

    1. Initial program 72.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 94.6%

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

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

Alternative 10: 82.0% accurate, 2.6× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.4e45 or 56 < 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 92.8%

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

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

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

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

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

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

      \[\leadsto \color{blue}{U + 0.016666666666666666 \cdot \left(J \cdot {\ell}^{5}\right)} \]
    8. Step-by-step derivation
      1. +-commutative76.1%

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

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

    if -1.4e45 < l < 56

    1. Initial program 72.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 94.6%

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

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

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

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

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

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

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

Alternative 11: 82.0% accurate, 2.6× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.4e45 or 4.1e5 < 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 92.8%

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

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

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

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

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

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

      \[\leadsto \color{blue}{U + 0.016666666666666666 \cdot \left(J \cdot {\ell}^{5}\right)} \]
    8. Step-by-step derivation
      1. +-commutative76.1%

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

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

    if -1.4e45 < l < 4.1e5

    1. Initial program 72.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 94.7%

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

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

Alternative 12: 75.4% accurate, 2.6× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -9e11 or 2.1e-18 < l

    1. Initial program 99.7%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{U + 0.016666666666666666 \cdot \left(J \cdot {\ell}^{5}\right)} \]
    8. Step-by-step derivation
      1. +-commutative72.9%

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

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

    if -9e11 < l < 2.1e-18

    1. Initial program 71.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 97.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. *-commutative97.3%

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

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

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

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

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

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

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

Alternative 13: 42.2% accurate, 23.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -800 \lor \neg \left(\ell \leq 1100\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -800 or 1100 < 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.7%

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

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

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

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

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

      \[\leadsto \color{blue}{\left({\ell}^{5} \cdot \left(J \cdot 0.016666666666666666\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    7. Applied egg-rr14.1%

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

    if -800 < l < 1100

    1. Initial program 70.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -800 \lor \neg \left(\ell \leq 1100\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 54.0% 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 85.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 63.8%

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

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

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

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

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

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

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

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

Alternative 15: 2.8% accurate, 312.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 85.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 94.0%

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

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

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

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

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

    \[\leadsto \color{blue}{\left({\ell}^{5} \cdot \left(J \cdot 0.016666666666666666\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  7. Applied egg-rr2.8%

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

      \[\leadsto \color{blue}{1} \]
  9. Simplified2.8%

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

    \[\leadsto 1 \]
  11. Add Preprocessing

Alternative 16: 36.4% 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 85.3%

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

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

    \[\leadsto \color{blue}{U} \]
  5. Final simplification35.8%

    \[\leadsto U \]
  6. Add Preprocessing

Reproduce

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