Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.8% → 97.6%
Time: 11.6s
Alternatives: 15
Speedup: 2.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 15 alternatives:

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

Initial Program: 86.8% 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: 97.6% accurate, 1.4× speedup?

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

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

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

\mathbf{elif}\;\ell \leq 8 \cdot 10^{+102}:\\
\;\;\;\;U + J \cdot \left(e^{\ell} - t\_0\right)\\

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


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

    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. Applied egg-rr98.5%

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

    if -0.73999999999999999 < l < 0.0038999999999999998

    1. Initial program 75.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 99.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. *-commutative99.9%

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

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

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

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

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

    if 0.0038999999999999998 < l < 7.99999999999999982e102

    1. Initial program 100.0%

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

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

    if 7.99999999999999982e102 < 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 100.0%

      \[\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 \]
    4. Step-by-step derivation
      1. unpow2100.0%

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

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

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

Alternative 2: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ (* (* J (log1p (expm1 (* l 2.0)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
	return ((J * log1p(expm1((l * 2.0)))) * cos((K / 2.0))) + U;
}
public static double code(double J, double l, double K, double U) {
	return ((J * Math.log1p(Math.expm1((l * 2.0)))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U):
	return ((J * math.log1p(math.expm1((l * 2.0)))) * math.cos((K / 2.0))) + U
function code(J, l, K, U)
	return Float64(Float64(Float64(J * log1p(expm1(Float64(l * 2.0)))) * cos(Float64(K / 2.0))) + U)
end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[Log[1 + N[(Exp[N[(l * 2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

\\
\left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}
Derivation
  1. Initial program 88.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 60.5%

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

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

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

    \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  6. Step-by-step derivation
    1. log1p-expm1-u98.2%

      \[\leadsto \left(J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  7. Applied egg-rr98.2%

    \[\leadsto \left(J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  8. Add Preprocessing

Alternative 3: 81.3% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Step-by-step derivation
      1. log1p-expm1-u99.0%

        \[\leadsto \left(J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    7. Applied egg-rr99.0%

      \[\leadsto \left(J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    8. Taylor expanded in U around inf 66.3%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    9. Step-by-step derivation
      1. associate-/l*75.1%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    10. Simplified75.1%

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

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

    1. Initial program 89.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 85.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 \]
    4. Taylor expanded in K around 0 83.2%

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
    5. Taylor expanded in U around inf 83.5%

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

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

Alternative 4: 81.0% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Step-by-step derivation
      1. log1p-expm1-u99.0%

        \[\leadsto \left(J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    7. Applied egg-rr99.0%

      \[\leadsto \left(J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot 2\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    8. Taylor expanded in U around inf 66.3%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    9. Step-by-step derivation
      1. associate-/l*75.1%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    10. Simplified75.1%

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

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

    1. Initial program 89.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 85.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 \]
    4. Taylor expanded in K around 0 83.2%

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

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

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

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

Alternative 5: 78.4% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

    1. Initial program 89.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 85.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 \]
    4. Taylor expanded in K around 0 83.2%

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

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

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

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

Alternative 6: 79.9% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-132}:\\
\;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\

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


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

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

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

    if 4.9999999999999999e-132 < (/.f64 K #s(literal 2 binary64))

    1. Initial program 91.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(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. unpow292.8%

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

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

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

Alternative 7: 88.0% accurate, 2.7× speedup?

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

\\
U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)
\end{array}
Derivation
  1. Initial program 88.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 89.2%

    \[\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 \]
  4. Step-by-step derivation
    1. unpow289.2%

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

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

    \[\leadsto U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right) \]
  7. Add Preprocessing

Alternative 8: 59.4% accurate, 19.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 10500

    1. Initial program 87.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 61.8%

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

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

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

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Step-by-step derivation
      1. log1p-expm1-u97.6%

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

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

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

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

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
    11. Taylor expanded in U around inf 53.3%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \ell}{U}\right)} \]
    12. Step-by-step derivation
      1. associate-/l*55.3%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    13. Simplified55.3%

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

    if 10500 < K

    1. Initial program 92.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 55.9%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot -6} + U \]
    9. Simplified44.5%

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

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

Alternative 9: 42.7% accurate, 20.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -5.5 \lor \neg \left(\ell \leq 120\right):\\ \;\;\;\;\frac{U \cdot U}{U}\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -5.5) (not (<= l 120.0))) (/ (* U U) U) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -5.5) || !(l <= 120.0)) {
		tmp = (U * 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 <= (-5.5d0)) .or. (.not. (l <= 120.0d0))) then
        tmp = (u * 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 <= -5.5) || !(l <= 120.0)) {
		tmp = (U * U) / U;
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -5.5) or not (l <= 120.0):
		tmp = (U * U) / U
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -5.5) || !(l <= 120.0))
		tmp = Float64(Float64(U * U) / U);
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -5.5) || ~((l <= 120.0)))
		tmp = (U * U) / U;
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -5.5], N[Not[LessEqual[l, 120.0]], $MachinePrecision]], N[(N[(U * U), $MachinePrecision] / U), $MachinePrecision], U]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.5 or 120 < 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. Applied egg-rr3.3%

      \[\leadsto \color{blue}{0} + U \]
    4. Step-by-step derivation
      1. flip-+20.6%

        \[\leadsto \color{blue}{\frac{0 \cdot 0 - U \cdot U}{0 - U}} \]
      2. metadata-eval20.6%

        \[\leadsto \frac{\color{blue}{0} - U \cdot U}{0 - U} \]
      3. div-sub20.6%

        \[\leadsto \color{blue}{\frac{0}{0 - U} - \frac{U \cdot U}{0 - U}} \]
      4. sub0-neg20.6%

        \[\leadsto \frac{0}{\color{blue}{-U}} - \frac{U \cdot U}{0 - U} \]
      5. pow220.6%

        \[\leadsto \frac{0}{-U} - \frac{\color{blue}{{U}^{2}}}{0 - U} \]
      6. sub0-neg20.6%

        \[\leadsto \frac{0}{-U} - \frac{{U}^{2}}{\color{blue}{-U}} \]
    5. Applied egg-rr20.6%

      \[\leadsto \color{blue}{\frac{0}{-U} - \frac{{U}^{2}}{-U}} \]
    6. Step-by-step derivation
      1. div020.6%

        \[\leadsto \color{blue}{0} - \frac{{U}^{2}}{-U} \]
      2. neg-sub020.6%

        \[\leadsto \color{blue}{-\frac{{U}^{2}}{-U}} \]
      3. distribute-frac-neg220.6%

        \[\leadsto \color{blue}{\frac{{U}^{2}}{-\left(-U\right)}} \]
      4. remove-double-neg20.6%

        \[\leadsto \frac{{U}^{2}}{\color{blue}{U}} \]
    7. Simplified20.6%

      \[\leadsto \color{blue}{\frac{{U}^{2}}{U}} \]
    8. Step-by-step derivation
      1. unpow220.6%

        \[\leadsto \frac{\color{blue}{U \cdot U}}{U} \]
    9. Applied egg-rr20.6%

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

    if -5.5 < l < 120

    1. Initial program 76.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-rr57.1%

      \[\leadsto \color{blue}{-4} + U \]
    4. Taylor expanded in U around inf 74.9%

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

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

Alternative 10: 72.2% accurate, 24.0× speedup?

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

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

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

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

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

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

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

Alternative 11: 54.0% accurate, 26.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 10500

    1. Initial program 87.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 61.8%

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

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

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

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

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

    if 10500 < K

    1. Initial program 92.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 55.9%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot -6} + U \]
    9. Simplified44.5%

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

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

Alternative 12: 54.0% accurate, 26.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 10500

    1. Initial program 87.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 61.8%

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

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

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

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

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

    if 10500 < K

    1. Initial program 92.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 55.9%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{J \cdot \left(\ell \cdot -6\right)} + U \]
    9. Simplified44.5%

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

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

Alternative 13: 51.9% accurate, 26.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.16 \cdot 10^{+51}:\\
\;\;\;\;\frac{U \cdot U}{U}\\

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


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

    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. Applied egg-rr2.7%

      \[\leadsto \color{blue}{0} + U \]
    4. Step-by-step derivation
      1. flip-+25.1%

        \[\leadsto \color{blue}{\frac{0 \cdot 0 - U \cdot U}{0 - U}} \]
      2. metadata-eval25.1%

        \[\leadsto \frac{\color{blue}{0} - U \cdot U}{0 - U} \]
      3. div-sub25.1%

        \[\leadsto \color{blue}{\frac{0}{0 - U} - \frac{U \cdot U}{0 - U}} \]
      4. sub0-neg25.1%

        \[\leadsto \frac{0}{\color{blue}{-U}} - \frac{U \cdot U}{0 - U} \]
      5. pow225.1%

        \[\leadsto \frac{0}{-U} - \frac{\color{blue}{{U}^{2}}}{0 - U} \]
      6. sub0-neg25.1%

        \[\leadsto \frac{0}{-U} - \frac{{U}^{2}}{\color{blue}{-U}} \]
    5. Applied egg-rr25.1%

      \[\leadsto \color{blue}{\frac{0}{-U} - \frac{{U}^{2}}{-U}} \]
    6. Step-by-step derivation
      1. div025.1%

        \[\leadsto \color{blue}{0} - \frac{{U}^{2}}{-U} \]
      2. neg-sub025.1%

        \[\leadsto \color{blue}{-\frac{{U}^{2}}{-U}} \]
      3. distribute-frac-neg225.1%

        \[\leadsto \color{blue}{\frac{{U}^{2}}{-\left(-U\right)}} \]
      4. remove-double-neg25.1%

        \[\leadsto \frac{{U}^{2}}{\color{blue}{U}} \]
    7. Simplified25.1%

      \[\leadsto \color{blue}{\frac{{U}^{2}}{U}} \]
    8. Step-by-step derivation
      1. unpow225.1%

        \[\leadsto \frac{\color{blue}{U \cdot U}}{U} \]
    9. Applied egg-rr25.1%

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

    if -1.16e51 < l

    1. Initial program 85.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 68.9%

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

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

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

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

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

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

Alternative 14: 37.2% accurate, 312.0× speedup?

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

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

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

    \[\leadsto \color{blue}{-4} + U \]
  4. Taylor expanded in U around inf 37.5%

    \[\leadsto \color{blue}{U} \]
  5. Add Preprocessing

Alternative 15: 2.8% accurate, 312.0× speedup?

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

\\
-4
\end{array}
Derivation
  1. Initial program 88.7%

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

    \[\leadsto \color{blue}{-4} + U \]
  4. Taylor expanded in U around 0 3.1%

    \[\leadsto \color{blue}{-4} \]
  5. Add Preprocessing

Reproduce

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