Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.4% → 99.6%
Time: 13.3s
Alternatives: 18
Speedup: 1.0×

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 18 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.4% 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.6% accurate, 1.0× speedup?

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

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

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

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

    \[\leadsto 2 \cdot \left(J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)}\right) + U \]
  6. Final simplification99.3%

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

Alternative 2: 86.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t\_0 \leq -0.98:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\right)\\ \mathbf{elif}\;t\_0 \leq 0.26:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= t_0 -0.98)
     (+ U (* 2.0 (* J (+ l (* -0.125 (* l (pow K 2.0)))))))
     (if (<= t_0 0.26)
       (+ U (* 2.0 (* l (* J (cos (* K 0.5))))))
       (+ U (* 2.0 (* J (log1p (expm1 l)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (t_0 <= -0.98) {
		tmp = U + (2.0 * (J * (l + (-0.125 * (l * pow(K, 2.0))))));
	} else if (t_0 <= 0.26) {
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	} else {
		tmp = U + (2.0 * (J * log1p(expm1(l))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (t_0 <= -0.98) {
		tmp = U + (2.0 * (J * (l + (-0.125 * (l * Math.pow(K, 2.0))))));
	} else if (t_0 <= 0.26) {
		tmp = U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
	} else {
		tmp = U + (2.0 * (J * Math.log1p(Math.expm1(l))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if t_0 <= -0.98:
		tmp = U + (2.0 * (J * (l + (-0.125 * (l * math.pow(K, 2.0))))))
	elif t_0 <= 0.26:
		tmp = U + (2.0 * (l * (J * math.cos((K * 0.5)))))
	else:
		tmp = U + (2.0 * (J * math.log1p(math.expm1(l))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_0 <= -0.98)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l + Float64(-0.125 * Float64(l * (K ^ 2.0)))))));
	elseif (t_0 <= 0.26)
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5))))));
	else
		tmp = Float64(U + Float64(2.0 * Float64(J * log1p(expm1(l)))));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, -0.98], N[(U + N[(2.0 * N[(J * N[(l + N[(-0.125 * N[(l * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.26], N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(J * N[Log[1 + N[(Exp[l] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 91.2%

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

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

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

    if -0.97999999999999998 < (cos.f64 (/.f64 K 2)) < 0.26000000000000001

    1. Initial program 82.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 77.4%

      \[\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. associate-*r*77.3%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto 2 \cdot \left(J \cdot \mathsf{log1p}\left(\color{blue}{e^{\ell} - 1}\right)\right) + U \]
    7. Step-by-step derivation
      1. expm1-define96.6%

        \[\leadsto 2 \cdot \left(J \cdot \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\ell\right)}\right)\right) + U \]
    8. Simplified96.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.98:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\right)\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq 0.26:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 93.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t\_0 \leq 0.26:\\ \;\;\;\;U + t\_0 \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(J \cdot \ell\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= t_0 0.26)
     (+ U (* t_0 (+ (* 0.3333333333333333 (* J (pow l 3.0))) (* 2.0 (* J l)))))
     (+ U (* 2.0 (* J (log1p (expm1 l))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (t_0 <= 0.26) {
		tmp = U + (t_0 * ((0.3333333333333333 * (J * pow(l, 3.0))) + (2.0 * (J * l))));
	} else {
		tmp = U + (2.0 * (J * log1p(expm1(l))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (t_0 <= 0.26) {
		tmp = U + (t_0 * ((0.3333333333333333 * (J * Math.pow(l, 3.0))) + (2.0 * (J * l))));
	} else {
		tmp = U + (2.0 * (J * Math.log1p(Math.expm1(l))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if t_0 <= 0.26:
		tmp = U + (t_0 * ((0.3333333333333333 * (J * math.pow(l, 3.0))) + (2.0 * (J * l))))
	else:
		tmp = U + (2.0 * (J * math.log1p(math.expm1(l))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_0 <= 0.26)
		tmp = Float64(U + Float64(t_0 * Float64(Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))) + Float64(2.0 * Float64(J * l)))));
	else
		tmp = Float64(U + Float64(2.0 * Float64(J * log1p(expm1(l)))));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.26], N[(U + N[(t$95$0 * N[(N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(J * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(J * N[Log[1 + N[(Exp[l] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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


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

    1. Initial program 84.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 89.5%

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

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

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

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

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

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

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

      \[\leadsto 2 \cdot \left(J \cdot \mathsf{log1p}\left(\color{blue}{e^{\ell} - 1}\right)\right) + U \]
    7. Step-by-step derivation
      1. expm1-define96.6%

        \[\leadsto 2 \cdot \left(J \cdot \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\ell\right)}\right)\right) + U \]
    8. Simplified96.6%

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

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

Alternative 4: 93.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t\_0 \leq 0.26:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= t_0 0.26)
     (+ U (* t_0 (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* 2.0 l)))))
     (+ U (* 2.0 (* J (log1p (expm1 l))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (t_0 <= 0.26) {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + (2.0 * l))));
	} else {
		tmp = U + (2.0 * (J * log1p(expm1(l))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (t_0 <= 0.26) {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (2.0 * l))));
	} else {
		tmp = U + (2.0 * (J * Math.log1p(Math.expm1(l))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if t_0 <= 0.26:
		tmp = U + (t_0 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (2.0 * l))))
	else:
		tmp = U + (2.0 * (J * math.log1p(math.expm1(l))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_0 <= 0.26)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(2.0 * l)))));
	else
		tmp = Float64(U + Float64(2.0 * Float64(J * log1p(expm1(l)))));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.26], N[(U + N[(t$95$0 * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(J * N[Log[1 + N[(Exp[l] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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


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

    1. Initial program 84.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 89.5%

      \[\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 0.26000000000000001 < (cos.f64 (/.f64 K 2))

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

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

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

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

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

      \[\leadsto 2 \cdot \left(J \cdot \mathsf{log1p}\left(\color{blue}{e^{\ell} - 1}\right)\right) + U \]
    7. Step-by-step derivation
      1. expm1-define96.6%

        \[\leadsto 2 \cdot \left(J \cdot \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\ell\right)}\right)\right) + U \]
    8. Simplified96.6%

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

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

Alternative 5: 67.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\right)\\ \mathbf{if}\;\ell \leq -4.1 \cdot 10^{+92}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -2.45 \cdot 10^{+67}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U \cdot \left(U + 4\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -1.55 \cdot 10^{+23}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 820:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+131}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* 2.0 (* J (+ l (* -0.125 (* l (pow K 2.0)))))))))
   (if (<= l -4.1e+92)
     t_0
     (if (<= l -2.45e+67)
       (log1p (expm1 (* U (+ U 4.0))))
       (if (<= l -1.55e+23)
         t_0
         (if (<= l 820.0)
           (+ U (* 2.0 (* l (* J (cos (* K 0.5))))))
           (if (<= l 1.65e+131) (log1p (expm1 U)) t_0)))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (J * (l + (-0.125 * (l * pow(K, 2.0))))));
	double tmp;
	if (l <= -4.1e+92) {
		tmp = t_0;
	} else if (l <= -2.45e+67) {
		tmp = log1p(expm1((U * (U + 4.0))));
	} else if (l <= -1.55e+23) {
		tmp = t_0;
	} else if (l <= 820.0) {
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	} else if (l <= 1.65e+131) {
		tmp = log1p(expm1(U));
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (J * (l + (-0.125 * (l * Math.pow(K, 2.0))))));
	double tmp;
	if (l <= -4.1e+92) {
		tmp = t_0;
	} else if (l <= -2.45e+67) {
		tmp = Math.log1p(Math.expm1((U * (U + 4.0))));
	} else if (l <= -1.55e+23) {
		tmp = t_0;
	} else if (l <= 820.0) {
		tmp = U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
	} else if (l <= 1.65e+131) {
		tmp = Math.log1p(Math.expm1(U));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (2.0 * (J * (l + (-0.125 * (l * math.pow(K, 2.0))))))
	tmp = 0
	if l <= -4.1e+92:
		tmp = t_0
	elif l <= -2.45e+67:
		tmp = math.log1p(math.expm1((U * (U + 4.0))))
	elif l <= -1.55e+23:
		tmp = t_0
	elif l <= 820.0:
		tmp = U + (2.0 * (l * (J * math.cos((K * 0.5)))))
	elif l <= 1.65e+131:
		tmp = math.log1p(math.expm1(U))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(2.0 * Float64(J * Float64(l + Float64(-0.125 * Float64(l * (K ^ 2.0)))))))
	tmp = 0.0
	if (l <= -4.1e+92)
		tmp = t_0;
	elseif (l <= -2.45e+67)
		tmp = log1p(expm1(Float64(U * Float64(U + 4.0))));
	elseif (l <= -1.55e+23)
		tmp = t_0;
	elseif (l <= 820.0)
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5))))));
	elseif (l <= 1.65e+131)
		tmp = log1p(expm1(U));
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(2.0 * N[(J * N[(l + N[(-0.125 * N[(l * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -4.1e+92], t$95$0, If[LessEqual[l, -2.45e+67], N[Log[1 + N[(Exp[N[(U * N[(U + 4.0), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, -1.55e+23], t$95$0, If[LessEqual[l, 820.0], N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.65e+131], N[Log[1 + N[(Exp[U] - 1), $MachinePrecision]], $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\right)\\
\mathbf{if}\;\ell \leq -4.1 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -2.45 \cdot 10^{+67}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U \cdot \left(U + 4\right)\right)\right)\\

\mathbf{elif}\;\ell \leq -1.55 \cdot 10^{+23}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+131}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -4.10000000000000024e92 or -2.44999999999999995e67 < l < -1.54999999999999985e23 or 1.6499999999999999e131 < 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 34.6%

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

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

    if -4.10000000000000024e92 < l < -2.44999999999999995e67

    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-rr28.2%

      \[\leadsto \color{blue}{U \cdot \left(U - -4\right)} \]
    4. Step-by-step derivation
      1. log1p-expm1-u87.5%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(U \cdot \left(U - -4\right)\right)\right)} \]
      2. sub-neg87.5%

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(U \cdot \color{blue}{\left(U + \left(--4\right)\right)}\right)\right) \]
      3. metadata-eval87.5%

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(U \cdot \left(U + \color{blue}{4}\right)\right)\right) \]
    5. Applied egg-rr87.5%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(U \cdot \left(U + 4\right)\right)\right)} \]

    if -1.54999999999999985e23 < l < 820

    1. Initial program 73.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 96.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. associate-*r*96.8%

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

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

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

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

    if 820 < l < 1.6499999999999999e131

    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-rr31.1%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification76.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.1 \cdot 10^{+92}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -2.45 \cdot 10^{+67}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U \cdot \left(U + 4\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -1.55 \cdot 10^{+23}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 820:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+131}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 68.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\right)\\ \mathbf{if}\;\ell \leq -1.55 \cdot 10^{+23}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 940:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.35 \cdot 10^{+131}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* 2.0 (* J (+ l (* -0.125 (* l (pow K 2.0)))))))))
   (if (<= l -1.55e+23)
     t_0
     (if (<= l 940.0)
       (+ U (* 2.0 (* l (* J (cos (* K 0.5))))))
       (if (<= l 1.35e+131) (log1p (expm1 U)) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (J * (l + (-0.125 * (l * pow(K, 2.0))))));
	double tmp;
	if (l <= -1.55e+23) {
		tmp = t_0;
	} else if (l <= 940.0) {
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	} else if (l <= 1.35e+131) {
		tmp = log1p(expm1(U));
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (J * (l + (-0.125 * (l * Math.pow(K, 2.0))))));
	double tmp;
	if (l <= -1.55e+23) {
		tmp = t_0;
	} else if (l <= 940.0) {
		tmp = U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
	} else if (l <= 1.35e+131) {
		tmp = Math.log1p(Math.expm1(U));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (2.0 * (J * (l + (-0.125 * (l * math.pow(K, 2.0))))))
	tmp = 0
	if l <= -1.55e+23:
		tmp = t_0
	elif l <= 940.0:
		tmp = U + (2.0 * (l * (J * math.cos((K * 0.5)))))
	elif l <= 1.35e+131:
		tmp = math.log1p(math.expm1(U))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(2.0 * Float64(J * Float64(l + Float64(-0.125 * Float64(l * (K ^ 2.0)))))))
	tmp = 0.0
	if (l <= -1.55e+23)
		tmp = t_0;
	elseif (l <= 940.0)
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5))))));
	elseif (l <= 1.35e+131)
		tmp = log1p(expm1(U));
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(2.0 * N[(J * N[(l + N[(-0.125 * N[(l * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.55e+23], t$95$0, If[LessEqual[l, 940.0], N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.35e+131], N[Log[1 + N[(Exp[U] - 1), $MachinePrecision]], $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\right)\\
\mathbf{if}\;\ell \leq -1.55 \cdot 10^{+23}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;\ell \leq 1.35 \cdot 10^{+131}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.54999999999999985e23 or 1.35000000000000002e131 < 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 32.9%

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

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

    if -1.54999999999999985e23 < l < 940

    1. Initial program 73.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 96.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. associate-*r*96.8%

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

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

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

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

    if 940 < l < 1.35000000000000002e131

    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-rr31.1%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.55 \cdot 10^{+23}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 940:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.35 \cdot 10^{+131}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 66.4% accurate, 2.4× speedup?

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

\\
\begin{array}{l}
t_0 := U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\right)\\
t_1 := \cos \left(K \cdot 0.5\right)\\
\mathbf{if}\;\ell \leq -1.55 \cdot 10^{+23}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq 8.2 \cdot 10^{+130}:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot t\_1\right)\right)\\

\mathbf{elif}\;\ell \leq 1.75 \cdot 10^{+247}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.54999999999999985e23 or 8.19999999999999955e130 < l < 1.7500000000000001e247

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

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

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

    if -1.54999999999999985e23 < l < 8.19999999999999955e130

    1. Initial program 77.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 85.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. associate-*r*85.3%

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

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

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

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

    if 1.7500000000000001e247 < 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 61.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.55 \cdot 10^{+23}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 8.2 \cdot 10^{+130}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.75 \cdot 10^{+247}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot {K}^{2}\right)\right)\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 8: 52.6% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -6.3 \cdot 10^{+244}:\\ \;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -16\right)}{U + -4}\\ \mathbf{elif}\;\ell \leq -2.4 \cdot 10^{+143}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq -9 \cdot 10^{+19}:\\ \;\;\;\;U + J \cdot \left(-0.5 + {K}^{2} \cdot 0.0625\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \ell\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -6.3e+244)
   (/ (* U (fma U U -16.0)) (+ U -4.0))
   (if (<= l -2.4e+143)
     (pow U -3.0)
     (if (<= l -9e+19)
       (+ U (* J (+ -0.5 (* (pow K 2.0) 0.0625))))
       (+ U (* 2.0 (* J l)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -6.3e+244) {
		tmp = (U * fma(U, U, -16.0)) / (U + -4.0);
	} else if (l <= -2.4e+143) {
		tmp = pow(U, -3.0);
	} else if (l <= -9e+19) {
		tmp = U + (J * (-0.5 + (pow(K, 2.0) * 0.0625)));
	} else {
		tmp = U + (2.0 * (J * l));
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -6.3e+244)
		tmp = Float64(Float64(U * fma(U, U, -16.0)) / Float64(U + -4.0));
	elseif (l <= -2.4e+143)
		tmp = U ^ -3.0;
	elseif (l <= -9e+19)
		tmp = Float64(U + Float64(J * Float64(-0.5 + Float64((K ^ 2.0) * 0.0625))));
	else
		tmp = Float64(U + Float64(2.0 * Float64(J * l)));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, -6.3e+244], N[(N[(U * N[(U * U + -16.0), $MachinePrecision]), $MachinePrecision] / N[(U + -4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -2.4e+143], N[Power[U, -3.0], $MachinePrecision], If[LessEqual[l, -9e+19], N[(U + N[(J * N[(-0.5 + N[(N[Power[K, 2.0], $MachinePrecision] * 0.0625), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(J * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -6.3 \cdot 10^{+244}:\\
\;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -16\right)}{U + -4}\\

\mathbf{elif}\;\ell \leq -2.4 \cdot 10^{+143}:\\
\;\;\;\;{U}^{-3}\\

\mathbf{elif}\;\ell \leq -9 \cdot 10^{+19}:\\
\;\;\;\;U + J \cdot \left(-0.5 + {K}^{2} \cdot 0.0625\right)\\

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


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

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

      \[\leadsto \color{blue}{U \cdot \left(U - -4\right)} \]
    4. Step-by-step derivation
      1. *-commutative33.1%

        \[\leadsto \color{blue}{\left(U - -4\right) \cdot U} \]
      2. flip--33.1%

        \[\leadsto \color{blue}{\frac{U \cdot U - -4 \cdot -4}{U + -4}} \cdot U \]
      3. associate-*l/54.6%

        \[\leadsto \color{blue}{\frac{\left(U \cdot U - -4 \cdot -4\right) \cdot U}{U + -4}} \]
      4. fma-neg54.6%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(U, U, --4 \cdot -4\right)} \cdot U}{U + -4} \]
      5. metadata-eval54.6%

        \[\leadsto \frac{\mathsf{fma}\left(U, U, -\color{blue}{16}\right) \cdot U}{U + -4} \]
      6. metadata-eval54.6%

        \[\leadsto \frac{\mathsf{fma}\left(U, U, \color{blue}{-16}\right) \cdot U}{U + -4} \]
    5. Applied egg-rr54.6%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(U, U, -16\right) \cdot U}{U + -4}} \]

    if -6.2999999999999996e244 < l < -2.3999999999999998e143

    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-rr43.9%

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

    if -2.3999999999999998e143 < l < -9e19

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

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

      \[\leadsto \color{blue}{\left(-0.5 \cdot J + 0.0625 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
    5. Step-by-step derivation
      1. *-commutative32.4%

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

        \[\leadsto \left(-0.5 \cdot J + \color{blue}{\left(0.0625 \cdot {K}^{2}\right) \cdot J}\right) + U \]
      3. distribute-rgt-out32.4%

        \[\leadsto \color{blue}{J \cdot \left(-0.5 + 0.0625 \cdot {K}^{2}\right)} + U \]
    6. Simplified32.4%

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

    if -9e19 < l

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6.3 \cdot 10^{+244}:\\ \;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -16\right)}{U + -4}\\ \mathbf{elif}\;\ell \leq -2.4 \cdot 10^{+143}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq -9 \cdot 10^{+19}:\\ \;\;\;\;U + J \cdot \left(-0.5 + {K}^{2} \cdot 0.0625\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \ell\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 52.5% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{U \cdot \mathsf{fma}\left(U, U, -16\right)}{U + -4}\\ \mathbf{if}\;\ell \leq -7.2 \cdot 10^{+247}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -2.05 \cdot 10^{+95}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq -950:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \ell\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (/ (* U (fma U U -16.0)) (+ U -4.0))))
   (if (<= l -7.2e+247)
     t_0
     (if (<= l -2.05e+95)
       (pow U -3.0)
       (if (<= l -950.0) t_0 (+ U (* 2.0 (* J l))))))))
double code(double J, double l, double K, double U) {
	double t_0 = (U * fma(U, U, -16.0)) / (U + -4.0);
	double tmp;
	if (l <= -7.2e+247) {
		tmp = t_0;
	} else if (l <= -2.05e+95) {
		tmp = pow(U, -3.0);
	} else if (l <= -950.0) {
		tmp = t_0;
	} else {
		tmp = U + (2.0 * (J * l));
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(Float64(U * fma(U, U, -16.0)) / Float64(U + -4.0))
	tmp = 0.0
	if (l <= -7.2e+247)
		tmp = t_0;
	elseif (l <= -2.05e+95)
		tmp = U ^ -3.0;
	elseif (l <= -950.0)
		tmp = t_0;
	else
		tmp = Float64(U + Float64(2.0 * Float64(J * l)));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[(U * N[(U * U + -16.0), $MachinePrecision]), $MachinePrecision] / N[(U + -4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -7.2e+247], t$95$0, If[LessEqual[l, -2.05e+95], N[Power[U, -3.0], $MachinePrecision], If[LessEqual[l, -950.0], t$95$0, N[(U + N[(2.0 * N[(J * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{U \cdot \mathsf{fma}\left(U, U, -16\right)}{U + -4}\\
\mathbf{if}\;\ell \leq -7.2 \cdot 10^{+247}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -2.05 \cdot 10^{+95}:\\
\;\;\;\;{U}^{-3}\\

\mathbf{elif}\;\ell \leq -950:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -7.2e247 or -2.04999999999999993e95 < l < -950

    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-rr27.9%

      \[\leadsto \color{blue}{U \cdot \left(U - -4\right)} \]
    4. Step-by-step derivation
      1. *-commutative27.9%

        \[\leadsto \color{blue}{\left(U - -4\right) \cdot U} \]
      2. flip--27.9%

        \[\leadsto \color{blue}{\frac{U \cdot U - -4 \cdot -4}{U + -4}} \cdot U \]
      3. associate-*l/39.8%

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

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(U, U, --4 \cdot -4\right)} \cdot U}{U + -4} \]
      5. metadata-eval39.8%

        \[\leadsto \frac{\mathsf{fma}\left(U, U, -\color{blue}{16}\right) \cdot U}{U + -4} \]
      6. metadata-eval39.8%

        \[\leadsto \frac{\mathsf{fma}\left(U, U, \color{blue}{-16}\right) \cdot U}{U + -4} \]
    5. Applied egg-rr39.8%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(U, U, -16\right) \cdot U}{U + -4}} \]

    if -7.2e247 < l < -2.04999999999999993e95

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

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

    if -950 < l

    1. Initial program 80.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 79.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7.2 \cdot 10^{+247}:\\ \;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -16\right)}{U + -4}\\ \mathbf{elif}\;\ell \leq -2.05 \cdot 10^{+95}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq -950:\\ \;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -16\right)}{U + -4}\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \ell\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 51.7% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.7 \cdot 10^{+240}:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq -6.2 \cdot 10^{+103}:\\
\;\;\;\;{U}^{-3}\\

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


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

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

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

    if -5.69999999999999973e240 < l < -6.2000000000000003e103

    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-rr43.0%

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

    if -6.2000000000000003e103 < l

    1. Initial program 82.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 73.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.7 \cdot 10^{+240}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -6.2 \cdot 10^{+103}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \ell\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 64.0% accurate, 2.8× speedup?

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

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

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

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

Alternative 12: 64.0% accurate, 2.8× speedup?

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

\\
U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)
\end{array}
Derivation
  1. Initial program 85.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 67.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. associate-*r*67.5%

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

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

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

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

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

Alternative 13: 52.8% accurate, 2.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.3 \cdot 10^{+104}:\\
\;\;\;\;{U}^{-4}\\

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


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

    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-rr28.3%

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

    if -3.29999999999999985e104 < l

    1. Initial program 82.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 73.8%

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

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

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

Alternative 14: 42.6% accurate, 20.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1000 \lor \neg \left(\ell \leq 7.5 \cdot 10^{-5}\right):\\
\;\;\;\;U \cdot \left(U - -4\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1e3 or 7.49999999999999934e-5 < 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. Applied egg-rr17.6%

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

    if -1e3 < l < 7.49999999999999934e-5

    1. Initial program 72.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 J around 0 72.6%

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

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

Alternative 15: 42.5% accurate, 23.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1250 \lor \neg \left(\ell \leq 7.5 \cdot 10^{-5}\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1250 or 7.49999999999999934e-5 < 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. Applied egg-rr17.4%

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

    if -1250 < l < 7.49999999999999934e-5

    1. Initial program 72.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 J around 0 72.6%

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

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

Alternative 16: 54.2% accurate, 44.6× speedup?

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

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

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

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

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

Alternative 17: 2.7% accurate, 312.0× speedup?

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

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

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

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

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

    \[\leadsto 1 \]
  7. Add Preprocessing

Alternative 18: 36.7% 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.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 J around 0 40.8%

    \[\leadsto \color{blue}{U} \]
  4. Final simplification40.8%

    \[\leadsto U \]
  5. Add Preprocessing

Reproduce

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