Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 87.2% → 99.3%
Time: 13.9s
Alternatives: 16
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 16 alternatives:

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

Initial Program: 87.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.3% 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 87.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 64.7%

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

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

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

    \[\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.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-rr99.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. Add Preprocessing

Alternative 2: 96.5% accurate, 1.3× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -2.6e29 or 1.70000000000000006e43 < 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 97.4%

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

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

        \[\leadsto 0.0003968253968253968 \cdot \color{blue}{\left(\left(J \cdot {\ell}^{7}\right) \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    6. Simplified100.0%

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

    if -2.6e29 < l < -1.30000000000000004

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

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

    if -1.30000000000000004 < l < 820

    1. Initial program 74.2%

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

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

    if 820 < l < 1.70000000000000006e43

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

      \[\leadsto \color{blue}{\frac{-4}{U} - U} \]
    4. Step-by-step derivation
      1. log1p-expm1-u66.7%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)} \]
    5. Applied egg-rr66.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.6 \cdot 10^{+29}:\\ \;\;\;\;U + 0.0003968253968253968 \cdot \left(\left(J \cdot {\ell}^{7}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq -1.3:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 820:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.7 \cdot 10^{+43}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.0003968253968253968 \cdot \left(\left(J \cdot {\ell}^{7}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 97.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;\ell \leq -1.05:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\right)\\ \mathbf{elif}\;\ell \leq 500:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2.4 \cdot 10^{+43}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.0003968253968253968 \cdot \left(\left(J \cdot {\ell}^{7}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= l -1.05)
     (+ U (* t_0 (* J (- 0.3333333333333333 (exp (- l))))))
     (if (<= l 500.0)
       (+ U (* t_0 (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0)))))))
       (if (<= l 2.4e+43)
         (log1p (expm1 (- (/ -4.0 U) U)))
         (+
          U
          (* 0.0003968253968253968 (* (* J (pow l 7.0)) (cos (* K 0.5))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (l <= -1.05) {
		tmp = U + (t_0 * (J * (0.3333333333333333 - exp(-l))));
	} else if (l <= 500.0) {
		tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * pow(l, 2.0))))));
	} else if (l <= 2.4e+43) {
		tmp = log1p(expm1(((-4.0 / U) - U)));
	} else {
		tmp = U + (0.0003968253968253968 * ((J * pow(l, 7.0)) * cos((K * 0.5))));
	}
	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 (l <= -1.05) {
		tmp = U + (t_0 * (J * (0.3333333333333333 - Math.exp(-l))));
	} else if (l <= 500.0) {
		tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0))))));
	} else if (l <= 2.4e+43) {
		tmp = Math.log1p(Math.expm1(((-4.0 / U) - U)));
	} else {
		tmp = U + (0.0003968253968253968 * ((J * Math.pow(l, 7.0)) * Math.cos((K * 0.5))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if l <= -1.05:
		tmp = U + (t_0 * (J * (0.3333333333333333 - math.exp(-l))))
	elif l <= 500.0:
		tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0))))))
	elif l <= 2.4e+43:
		tmp = math.log1p(math.expm1(((-4.0 / U) - U)))
	else:
		tmp = U + (0.0003968253968253968 * ((J * math.pow(l, 7.0)) * math.cos((K * 0.5))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (l <= -1.05)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(0.3333333333333333 - exp(Float64(-l))))));
	elseif (l <= 500.0)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0)))))));
	elseif (l <= 2.4e+43)
		tmp = log1p(expm1(Float64(Float64(-4.0 / U) - U)));
	else
		tmp = Float64(U + Float64(0.0003968253968253968 * Float64(Float64(J * (l ^ 7.0)) * cos(Float64(K * 0.5)))));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -1.05], N[(U + N[(t$95$0 * N[(J * N[(0.3333333333333333 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 500.0], N[(U + N[(t$95$0 * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.4e+43], N[Log[1 + N[(Exp[N[(N[(-4.0 / U), $MachinePrecision] - U), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision], N[(U + N[(0.0003968253968253968 * N[(N[(J * N[Power[l, 7.0], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

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

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


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

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

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

    if -1.05000000000000004 < l < 500

    1. Initial program 74.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 99.6%

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

    if 500 < l < 2.40000000000000023e43

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

      \[\leadsto \color{blue}{\frac{-4}{U} - U} \]
    4. Step-by-step derivation
      1. log1p-expm1-u66.7%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)} \]
    5. Applied egg-rr66.7%

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

    if 2.40000000000000023e43 < l

    1. Initial program 100.0%

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

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

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

        \[\leadsto 0.0003968253968253968 \cdot \color{blue}{\left(\left(J \cdot {\ell}^{7}\right) \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    6. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.05:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\right)\\ \mathbf{elif}\;\ell \leq 500:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2.4 \cdot 10^{+43}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.0003968253968253968 \cdot \left(\left(J \cdot {\ell}^{7}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 97.7% accurate, 1.4× speedup?

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

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

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

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

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


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

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

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

    if -0.71999999999999997 < l < 780

    1. Initial program 74.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 99.4%

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

    if 780 < l < 9.5000000000000004e43

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

      \[\leadsto \color{blue}{\frac{-4}{U} - U} \]
    4. Step-by-step derivation
      1. log1p-expm1-u66.7%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)} \]
    5. Applied egg-rr66.7%

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

    if 9.5000000000000004e43 < l

    1. Initial program 100.0%

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

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

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

        \[\leadsto 0.0003968253968253968 \cdot \color{blue}{\left(\left(J \cdot {\ell}^{7}\right) \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    6. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -0.72:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\right)\\ \mathbf{elif}\;\ell \leq 780:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 9.5 \cdot 10^{+43}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.0003968253968253968 \cdot \left(\left(J \cdot {\ell}^{7}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 77.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \ell \cdot \cos \left(K \cdot 0.5\right)\\ t_1 := U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{t\_0}{U}\right)\right)\\ t_2 := \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{if}\;\ell \leq -2.8 \cdot 10^{+244}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -54000000:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\ell \leq 520:\\ \;\;\;\;U + 2 \cdot \left(J \cdot t\_0\right)\\ \mathbf{elif}\;\ell \leq 10^{+157}:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* l (cos (* K 0.5))))
        (t_1 (* U (+ 1.0 (* 2.0 (* J (/ t_0 U))))))
        (t_2 (log1p (expm1 (- (/ -4.0 U) U)))))
   (if (<= l -2.8e+244)
     t_1
     (if (<= l -54000000.0)
       t_2
       (if (<= l 520.0) (+ U (* 2.0 (* J t_0))) (if (<= l 1e+157) t_2 t_1))))))
double code(double J, double l, double K, double U) {
	double t_0 = l * cos((K * 0.5));
	double t_1 = U * (1.0 + (2.0 * (J * (t_0 / U))));
	double t_2 = log1p(expm1(((-4.0 / U) - U)));
	double tmp;
	if (l <= -2.8e+244) {
		tmp = t_1;
	} else if (l <= -54000000.0) {
		tmp = t_2;
	} else if (l <= 520.0) {
		tmp = U + (2.0 * (J * t_0));
	} else if (l <= 1e+157) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = l * Math.cos((K * 0.5));
	double t_1 = U * (1.0 + (2.0 * (J * (t_0 / U))));
	double t_2 = Math.log1p(Math.expm1(((-4.0 / U) - U)));
	double tmp;
	if (l <= -2.8e+244) {
		tmp = t_1;
	} else if (l <= -54000000.0) {
		tmp = t_2;
	} else if (l <= 520.0) {
		tmp = U + (2.0 * (J * t_0));
	} else if (l <= 1e+157) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = l * math.cos((K * 0.5))
	t_1 = U * (1.0 + (2.0 * (J * (t_0 / U))))
	t_2 = math.log1p(math.expm1(((-4.0 / U) - U)))
	tmp = 0
	if l <= -2.8e+244:
		tmp = t_1
	elif l <= -54000000.0:
		tmp = t_2
	elif l <= 520.0:
		tmp = U + (2.0 * (J * t_0))
	elif l <= 1e+157:
		tmp = t_2
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = Float64(l * cos(Float64(K * 0.5)))
	t_1 = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(t_0 / U)))))
	t_2 = log1p(expm1(Float64(Float64(-4.0 / U) - U)))
	tmp = 0.0
	if (l <= -2.8e+244)
		tmp = t_1;
	elseif (l <= -54000000.0)
		tmp = t_2;
	elseif (l <= 520.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * t_0)));
	elseif (l <= 1e+157)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U * N[(1.0 + N[(2.0 * N[(J * N[(t$95$0 / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Log[1 + N[(Exp[N[(N[(-4.0 / U), $MachinePrecision] - U), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -2.8e+244], t$95$1, If[LessEqual[l, -54000000.0], t$95$2, If[LessEqual[l, 520.0], N[(U + N[(2.0 * N[(J * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1e+157], t$95$2, t$95$1]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \ell \cdot \cos \left(K \cdot 0.5\right)\\
t_1 := U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{t\_0}{U}\right)\right)\\
t_2 := \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\
\mathbf{if}\;\ell \leq -2.8 \cdot 10^{+244}:\\
\;\;\;\;t\_1\\

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

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

\mathbf{elif}\;\ell \leq 10^{+157}:\\
\;\;\;\;t\_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.79999999999999991e244 or 9.99999999999999983e156 < 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 58.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. *-commutative58.5%

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

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified58.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-u100.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-rr100.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 65.7%

      \[\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*71.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. Simplified71.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 -2.79999999999999991e244 < l < -5.4e7 or 520 < l < 9.99999999999999983e156

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

      \[\leadsto \color{blue}{\frac{-4}{U} - U} \]
    4. Step-by-step derivation
      1. log1p-expm1-u58.8%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)} \]
    5. Applied egg-rr58.8%

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

    if -5.4e7 < l < 520

    1. Initial program 74.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.8 \cdot 10^{+244}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\ \mathbf{elif}\;\ell \leq -54000000:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{elif}\;\ell \leq 520:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 10^{+157}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-4}{U} - U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 86.5% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.35 \lor \neg \left(\ell \leq 0.45\right):\\
\;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.3500000000000001 or 0.450000000000000011 < l

    1. Initial program 100.0%

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

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

    if -1.3500000000000001 < l < 0.450000000000000011

    1. Initial program 74.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.35 \lor \neg \left(\ell \leq 0.45\right):\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\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 7: 66.6% accurate, 2.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -54000000 \lor \neg \left(\ell \leq 7600000000000\right):\\
\;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(5 + {K}^{2} \cdot -8\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.4e7 or 7.6e12 < 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.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. *-commutative34.1%

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

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

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

      \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\cos \left(-4 \cdot K\right)\right)} - -3\right)} + U \]
    7. Step-by-step derivation
      1. log1p-undefine24.8%

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(e^{\color{blue}{\log \left(1 + \cos \left(-4 \cdot K\right)\right)}} - -3\right) + U \]
      2. rem-exp-log24.8%

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

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(\cos \color{blue}{\left(K \cdot -4\right)} + \left(1 - -3\right)\right) + U \]
      6. metadata-eval24.8%

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

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

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

        \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(5 + \color{blue}{{K}^{2} \cdot -8}\right) + U \]
    11. Simplified42.0%

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

    if -5.4e7 < l < 7.6e12

    1. Initial program 74.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -54000000 \lor \neg \left(\ell \leq 7600000000000\right):\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(5 + {K}^{2} \cdot -8\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: 66.6% accurate, 2.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -650000000 \lor \neg \left(\ell \leq 5.2 \cdot 10^{+16}\right):\\
\;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(1 + {K}^{2} \cdot -0.125\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -6.5e8 or 5.2e16 < 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.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. *-commutative34.9%

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

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified34.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 43.0%

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

    if -6.5e8 < l < 5.2e16

    1. Initial program 75.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -650000000 \lor \neg \left(\ell \leq 5.2 \cdot 10^{+16}\right):\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(1 + {K}^{2} \cdot -0.125\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 9: 52.7% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -680:\\
\;\;\;\;\frac{{U}^{3} + 4096}{256 + U \cdot -16}\\

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


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

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

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

        \[\leadsto \color{blue}{-4 \cdot -4 + U} \]
      2. +-commutative2.4%

        \[\leadsto \color{blue}{U + -4 \cdot -4} \]
      3. metadata-eval2.4%

        \[\leadsto U + \color{blue}{16} \]
    5. Simplified2.4%

      \[\leadsto \color{blue}{U + 16} \]
    6. Step-by-step derivation
      1. flip3-+11.0%

        \[\leadsto \color{blue}{\frac{{U}^{3} + {16}^{3}}{U \cdot U + \left(16 \cdot 16 - U \cdot 16\right)}} \]
      2. div-inv11.0%

        \[\leadsto \color{blue}{\left({U}^{3} + {16}^{3}\right) \cdot \frac{1}{U \cdot U + \left(16 \cdot 16 - U \cdot 16\right)}} \]
      3. metadata-eval11.0%

        \[\leadsto \left({U}^{3} + \color{blue}{4096}\right) \cdot \frac{1}{U \cdot U + \left(16 \cdot 16 - U \cdot 16\right)} \]
      4. fma-define11.0%

        \[\leadsto \left({U}^{3} + 4096\right) \cdot \frac{1}{\color{blue}{\mathsf{fma}\left(U, U, 16 \cdot 16 - U \cdot 16\right)}} \]
      5. metadata-eval11.0%

        \[\leadsto \left({U}^{3} + 4096\right) \cdot \frac{1}{\mathsf{fma}\left(U, U, \color{blue}{256} - U \cdot 16\right)} \]
    7. Applied egg-rr11.0%

      \[\leadsto \color{blue}{\left({U}^{3} + 4096\right) \cdot \frac{1}{\mathsf{fma}\left(U, U, 256 - U \cdot 16\right)}} \]
    8. Step-by-step derivation
      1. associate-*r/11.0%

        \[\leadsto \color{blue}{\frac{\left({U}^{3} + 4096\right) \cdot 1}{\mathsf{fma}\left(U, U, 256 - U \cdot 16\right)}} \]
      2. *-rgt-identity11.0%

        \[\leadsto \frac{\color{blue}{{U}^{3} + 4096}}{\mathsf{fma}\left(U, U, 256 - U \cdot 16\right)} \]
      3. fma-undefine11.0%

        \[\leadsto \frac{{U}^{3} + 4096}{\color{blue}{U \cdot U + \left(256 - U \cdot 16\right)}} \]
      4. unpow211.0%

        \[\leadsto \frac{{U}^{3} + 4096}{\color{blue}{{U}^{2}} + \left(256 - U \cdot 16\right)} \]
      5. *-commutative11.0%

        \[\leadsto \frac{{U}^{3} + 4096}{{U}^{2} + \left(256 - \color{blue}{16 \cdot U}\right)} \]
      6. associate-+r-11.0%

        \[\leadsto \frac{{U}^{3} + 4096}{\color{blue}{\left({U}^{2} + 256\right) - 16 \cdot U}} \]
      7. +-commutative11.0%

        \[\leadsto \frac{{U}^{3} + 4096}{\color{blue}{\left(256 + {U}^{2}\right)} - 16 \cdot U} \]
      8. associate-+r-11.0%

        \[\leadsto \frac{{U}^{3} + 4096}{\color{blue}{256 + \left({U}^{2} - 16 \cdot U\right)}} \]
      9. cancel-sign-sub-inv11.0%

        \[\leadsto \frac{{U}^{3} + 4096}{256 + \color{blue}{\left({U}^{2} + \left(-16\right) \cdot U\right)}} \]
      10. unpow211.0%

        \[\leadsto \frac{{U}^{3} + 4096}{256 + \left(\color{blue}{U \cdot U} + \left(-16\right) \cdot U\right)} \]
      11. metadata-eval11.0%

        \[\leadsto \frac{{U}^{3} + 4096}{256 + \left(U \cdot U + \color{blue}{-16} \cdot U\right)} \]
      12. distribute-rgt-out11.0%

        \[\leadsto \frac{{U}^{3} + 4096}{256 + \color{blue}{U \cdot \left(U + -16\right)}} \]
    9. Simplified11.0%

      \[\leadsto \color{blue}{\frac{{U}^{3} + 4096}{256 + U \cdot \left(U + -16\right)}} \]
    10. Taylor expanded in U around 0 30.8%

      \[\leadsto \frac{{U}^{3} + 4096}{256 + \color{blue}{-16 \cdot U}} \]
    11. Step-by-step derivation
      1. *-commutative30.8%

        \[\leadsto \frac{{U}^{3} + 4096}{256 + \color{blue}{U \cdot -16}} \]
    12. Simplified30.8%

      \[\leadsto \frac{{U}^{3} + 4096}{256 + \color{blue}{U \cdot -16}} \]

    if -680 < l

    1. Initial program 83.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 75.7%

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

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

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

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

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

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

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

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

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

Alternative 10: 71.8% accurate, 2.7× speedup?

\[\begin{array}{l} \\ U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right) \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (* U (+ 1.0 (* 2.0 (* J (/ (* l (cos (* K 0.5))) U))))))
double code(double J, double l, double K, double U) {
	return U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / 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 * (1.0d0 + (2.0d0 * (j * ((l * cos((k * 0.5d0))) / u))))
end function
public static double code(double J, double l, double K, double U) {
	return U * (1.0 + (2.0 * (J * ((l * Math.cos((K * 0.5))) / U))));
}
def code(J, l, K, U):
	return U * (1.0 + (2.0 * (J * ((l * math.cos((K * 0.5))) / U))))
function code(J, l, K, U)
	return Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(Float64(l * cos(Float64(K * 0.5))) / U)))))
end
function tmp = code(J, l, K, U)
	tmp = U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U))));
end
code[J_, l_, K_, U_] := 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]
\begin{array}{l}

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

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

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

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

    \[\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.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-rr99.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 U around inf 68.4%

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

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

    \[\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)} \]
  11. Final simplification70.6%

    \[\leadsto U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right) \]
  12. 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 87.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 64.7%

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

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

Alternative 12: 40.0% accurate, 38.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 510000:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \end{array} \]
(FPCore (J l K U) :precision binary64 (if (<= l 510000.0) U (* U U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 510000.0) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (l <= 510000.0d0) then
        tmp = u
    else
        tmp = u * u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 510000.0) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= 510000.0:
		tmp = U
	else:
		tmp = U * U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= 510000.0)
		tmp = U;
	else
		tmp = Float64(U * U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= 510000.0)
		tmp = U;
	else
		tmp = U * U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, 510000.0], U, N[(U * U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 510000:\\
\;\;\;\;U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 5.1e5

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

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

    if 5.1e5 < l

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{U \cdot U} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 13: 53.8% accurate, 44.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 14: 47.9% accurate, 44.6× speedup?

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

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

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

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

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

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

    \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\cos \left(-4 \cdot K\right)\right)} - -3\right)} + U \]
  7. Step-by-step derivation
    1. log1p-undefine48.4%

      \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(e^{\color{blue}{\log \left(1 + \cos \left(-4 \cdot K\right)\right)}} - -3\right) + U \]
    2. rem-exp-log48.4%

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

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

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

      \[\leadsto \left(J \cdot \left(\ell \cdot 2\right)\right) \cdot \left(\cos \color{blue}{\left(K \cdot -4\right)} + \left(1 - -3\right)\right) + U \]
    6. metadata-eval48.4%

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

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

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

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

Alternative 15: 36.8% 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 87.7%

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

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

Alternative 16: 2.8% accurate, 312.0× speedup?

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

\\
16
\end{array}
Derivation
  1. Initial program 87.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-rr22.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(-4, -4, U\right)} \]
  4. Step-by-step derivation
    1. fma-undefine22.8%

      \[\leadsto \color{blue}{-4 \cdot -4 + U} \]
    2. +-commutative22.8%

      \[\leadsto \color{blue}{U + -4 \cdot -4} \]
    3. metadata-eval22.8%

      \[\leadsto U + \color{blue}{16} \]
  5. Simplified22.8%

    \[\leadsto \color{blue}{U + 16} \]
  6. Taylor expanded in U around 0 2.6%

    \[\leadsto \color{blue}{16} \]
  7. Add Preprocessing

Reproduce

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