Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.7% → 99.3%
Time: 12.2s
Alternatives: 14
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 86.7% 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} \\ 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 88.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 65.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. log1p-expm1-u98.8%

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

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

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

Alternative 2: 66.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \ell \cdot \cos \left(K \cdot 0.5\right)\\ t_1 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t\_1 \leq -0.48:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(t\_0 \cdot \frac{J}{U}\right)\right)\\ \mathbf{elif}\;t\_1 \leq 0.78:\\ \;\;\;\;J \cdot \left(2 \cdot t\_0 + \frac{U}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* l (cos (* K 0.5)))) (t_1 (cos (/ K 2.0))))
   (if (<= t_1 -0.48)
     (* U (+ 1.0 (* 2.0 (* t_0 (/ J U)))))
     (if (<= t_1 0.78)
       (* J (+ (* 2.0 t_0) (/ U J)))
       (* U (+ 1.0 (* 2.0 (* J (/ l U)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = l * cos((K * 0.5));
	double t_1 = cos((K / 2.0));
	double tmp;
	if (t_1 <= -0.48) {
		tmp = U * (1.0 + (2.0 * (t_0 * (J / U))));
	} else if (t_1 <= 0.78) {
		tmp = J * ((2.0 * t_0) + (U / J));
	} else {
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = l * cos((k * 0.5d0))
    t_1 = cos((k / 2.0d0))
    if (t_1 <= (-0.48d0)) then
        tmp = u * (1.0d0 + (2.0d0 * (t_0 * (j / u))))
    else if (t_1 <= 0.78d0) then
        tmp = j * ((2.0d0 * t_0) + (u / j))
    else
        tmp = u * (1.0d0 + (2.0d0 * (j * (l / u))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = l * Math.cos((K * 0.5));
	double t_1 = Math.cos((K / 2.0));
	double tmp;
	if (t_1 <= -0.48) {
		tmp = U * (1.0 + (2.0 * (t_0 * (J / U))));
	} else if (t_1 <= 0.78) {
		tmp = J * ((2.0 * t_0) + (U / J));
	} else {
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = l * math.cos((K * 0.5))
	t_1 = math.cos((K / 2.0))
	tmp = 0
	if t_1 <= -0.48:
		tmp = U * (1.0 + (2.0 * (t_0 * (J / U))))
	elif t_1 <= 0.78:
		tmp = J * ((2.0 * t_0) + (U / J))
	else:
		tmp = U * (1.0 + (2.0 * (J * (l / U))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(l * cos(Float64(K * 0.5)))
	t_1 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_1 <= -0.48)
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(t_0 * Float64(J / U)))));
	elseif (t_1 <= 0.78)
		tmp = Float64(J * Float64(Float64(2.0 * t_0) + Float64(U / J)));
	else
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l / U)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = l * cos((K * 0.5));
	t_1 = cos((K / 2.0));
	tmp = 0.0;
	if (t_1 <= -0.48)
		tmp = U * (1.0 + (2.0 * (t_0 * (J / U))));
	elseif (t_1 <= 0.78)
		tmp = J * ((2.0 * t_0) + (U / J));
	else
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	end
	tmp_2 = 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[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$1, -0.48], N[(U * N[(1.0 + N[(2.0 * N[(t$95$0 * N[(J / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.78], N[(J * N[(N[(2.0 * t$95$0), $MachinePrecision] + N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U * N[(1.0 + N[(2.0 * N[(J * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_1 \leq 0.78:\\
\;\;\;\;J \cdot \left(2 \cdot t\_0 + \frac{U}{J}\right)\\

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


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

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

      \[\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-u98.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. *-commutative98.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-rr98.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 U around inf 83.1%

      \[\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)} \]
    7. Step-by-step derivation
      1. *-commutative83.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 83.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 70.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 J around inf 72.8%

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

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

    1. Initial program 92.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 61.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-u98.9%

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

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

      \[\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 U around inf 63.6%

      \[\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)} \]
    7. Step-by-step derivation
      1. *-commutative63.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 88.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.09:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)}{U}\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
 (if (<= (cos (/ K 2.0)) 0.09)
   (* U (+ 1.0 (* 2.0 (/ (* J (* l (cos (* K 0.5)))) U))))
   (+ U (* 2.0 (* J (log1p (expm1 l)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= 0.09) {
		tmp = U * (1.0 + (2.0 * ((J * (l * cos((K * 0.5)))) / U)));
	} else {
		tmp = U + (2.0 * (J * log1p(expm1(l))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (Math.cos((K / 2.0)) <= 0.09) {
		tmp = U * (1.0 + (2.0 * ((J * (l * Math.cos((K * 0.5)))) / U)));
	} else {
		tmp = U + (2.0 * (J * Math.log1p(Math.expm1(l))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if math.cos((K / 2.0)) <= 0.09:
		tmp = U * (1.0 + (2.0 * ((J * (l * math.cos((K * 0.5)))) / U)))
	else:
		tmp = U + (2.0 * (J * math.log1p(math.expm1(l))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= 0.09)
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(Float64(J * Float64(l * cos(Float64(K * 0.5)))) / U))));
	else
		tmp = Float64(U + Float64(2.0 * Float64(J * log1p(expm1(l)))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], 0.09], N[(U * N[(1.0 + N[(2.0 * N[(N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / U), $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}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.09:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)}{U}\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 #s(literal 2 binary64))) < 0.089999999999999997

    1. Initial program 82.1%

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

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

    1. Initial program 90.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 64.1%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.09:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)}{U}\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: 98.8% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq 9.4 \cdot 10^{+42}:\\
\;\;\;\;U + J \cdot \left(e^{\ell} - t\_1\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.02

    1. Initial program 100.0%

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

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

    if -1.02 < l < 0.032000000000000001

    1. Initial program 78.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 0.032000000000000001 < l < 9.39999999999999971e42

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

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

    if 9.39999999999999971e42 < 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.8%

      \[\leadsto \color{blue}{\left(\ell \cdot \left(2 \cdot J + {\ell}^{2} \cdot \left(0.3333333333333333 \cdot J + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right)\right)\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. distribute-rgt-in95.8%

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

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

        \[\leadsto \left(\ell \cdot \color{blue}{\left(\left(2 \cdot J + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right)\right) + \left({\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right)\right) \cdot {\ell}^{2}\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. +-commutative95.8%

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

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

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

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

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

        \[\leadsto \left(\ell \cdot \left(\color{blue}{J \cdot \left(0.3333333333333333 \cdot {\ell}^{2} + 2\right)} + \left({\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right)\right) \cdot {\ell}^{2}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      10. fma-define95.8%

        \[\leadsto \left(\ell \cdot \left(J \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\right)} + \left({\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right)\right) \cdot {\ell}^{2}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      11. *-commutative95.8%

        \[\leadsto \left(\ell \cdot \left(J \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\right) + \color{blue}{\left(\left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right) \cdot {\ell}^{2}\right)} \cdot {\ell}^{2}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      12. associate-*l*95.8%

        \[\leadsto \left(\ell \cdot \left(J \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\right) + \color{blue}{\left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right) \cdot \left({\ell}^{2} \cdot {\ell}^{2}\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified95.8%

      \[\leadsto \color{blue}{\left(\ell \cdot \left(J \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\right) + \left(J \cdot \mathsf{fma}\left({\ell}^{2}, 0.0003968253968253968, 0.016666666666666666\right)\right) \cdot {\ell}^{4}\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. 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 \]
    7. 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 \]
    8. 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.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.02:\\ \;\;\;\;U + \left(J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{elif}\;\ell \leq 0.032:\\ \;\;\;\;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 9.4 \cdot 10^{+42}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\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: 98.7% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq 1.05 \cdot 10^{+44}:\\
\;\;\;\;U + J \cdot \left(e^{\ell} - t\_1\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.72999999999999998

    1. Initial program 100.0%

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

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

    if -0.72999999999999998 < l < 0.089999999999999997

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

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

    if 0.089999999999999997 < l < 1.04999999999999993e44

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

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

    if 1.04999999999999993e44 < 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.8%

      \[\leadsto \color{blue}{\left(\ell \cdot \left(2 \cdot J + {\ell}^{2} \cdot \left(0.3333333333333333 \cdot J + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right)\right)\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. distribute-rgt-in95.8%

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

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

        \[\leadsto \left(\ell \cdot \color{blue}{\left(\left(2 \cdot J + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right)\right) + \left({\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right)\right) \cdot {\ell}^{2}\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. +-commutative95.8%

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

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

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

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

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

        \[\leadsto \left(\ell \cdot \left(\color{blue}{J \cdot \left(0.3333333333333333 \cdot {\ell}^{2} + 2\right)} + \left({\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right)\right) \cdot {\ell}^{2}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      10. fma-define95.8%

        \[\leadsto \left(\ell \cdot \left(J \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\right)} + \left({\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right)\right) \cdot {\ell}^{2}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      11. *-commutative95.8%

        \[\leadsto \left(\ell \cdot \left(J \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\right) + \color{blue}{\left(\left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right) \cdot {\ell}^{2}\right)} \cdot {\ell}^{2}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      12. associate-*l*95.8%

        \[\leadsto \left(\ell \cdot \left(J \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\right) + \color{blue}{\left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right) \cdot \left({\ell}^{2} \cdot {\ell}^{2}\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified95.8%

      \[\leadsto \color{blue}{\left(\ell \cdot \left(J \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\right) + \left(J \cdot \mathsf{fma}\left({\ell}^{2}, 0.0003968253968253968, 0.016666666666666666\right)\right) \cdot {\ell}^{4}\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. 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 \]
    7. 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 \]
    8. 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 simplification96.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -0.73:\\ \;\;\;\;U + \left(J \cdot \left(0.3333333333333333 - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{elif}\;\ell \leq 0.09:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.05 \cdot 10^{+44}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\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 6: 96.4% accurate, 1.4× 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 -4.1:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq 0.1:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t\_0\right)\right)\\ \mathbf{elif}\;\ell \leq 9.5 \cdot 10^{+43}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\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 -4.1)
     t_1
     (if (<= l 0.1)
       (+ U (* 2.0 (* J (* l t_0))))
       (if (<= l 9.5e+43) (+ U (* J (- (exp l) (exp (- l))))) 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 <= -4.1) {
		tmp = t_1;
	} else if (l <= 0.1) {
		tmp = U + (2.0 * (J * (l * t_0)));
	} else if (l <= 9.5e+43) {
		tmp = U + (J * (exp(l) - exp(-l)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k * 0.5d0))
    t_1 = u + (0.0003968253968253968d0 * ((j * (l ** 7.0d0)) * t_0))
    if (l <= (-4.1d0)) then
        tmp = t_1
    else if (l <= 0.1d0) then
        tmp = u + (2.0d0 * (j * (l * t_0)))
    else if (l <= 9.5d+43) then
        tmp = u + (j * (exp(l) - exp(-l)))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K * 0.5));
	double t_1 = U + (0.0003968253968253968 * ((J * Math.pow(l, 7.0)) * t_0));
	double tmp;
	if (l <= -4.1) {
		tmp = t_1;
	} else if (l <= 0.1) {
		tmp = U + (2.0 * (J * (l * t_0)));
	} else if (l <= 9.5e+43) {
		tmp = U + (J * (Math.exp(l) - Math.exp(-l)));
	} 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 <= -4.1:
		tmp = t_1
	elif l <= 0.1:
		tmp = U + (2.0 * (J * (l * t_0)))
	elif l <= 9.5e+43:
		tmp = U + (J * (math.exp(l) - math.exp(-l)))
	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 <= -4.1)
		tmp = t_1;
	elseif (l <= 0.1)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * t_0))));
	elseif (l <= 9.5e+43)
		tmp = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l)))));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K * 0.5));
	t_1 = U + (0.0003968253968253968 * ((J * (l ^ 7.0)) * t_0));
	tmp = 0.0;
	if (l <= -4.1)
		tmp = t_1;
	elseif (l <= 0.1)
		tmp = U + (2.0 * (J * (l * t_0)));
	elseif (l <= 9.5e+43)
		tmp = U + (J * (exp(l) - exp(-l)));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(0.0003968253968253968 * N[(N[(J * N[Power[l, 7.0], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -4.1], t$95$1, If[LessEqual[l, 0.1], N[(U + N[(2.0 * N[(J * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 9.5e+43], N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}

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

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

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

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


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

      \[\leadsto \color{blue}{\left(\ell \cdot \left(2 \cdot J + {\ell}^{2} \cdot \left(0.3333333333333333 \cdot J + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right)\right)\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. distribute-rgt-in91.9%

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

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

        \[\leadsto \left(\ell \cdot \color{blue}{\left(\left(2 \cdot J + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right)\right) + \left({\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right)\right) \cdot {\ell}^{2}\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. +-commutative91.9%

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

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

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

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

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

        \[\leadsto \left(\ell \cdot \left(\color{blue}{J \cdot \left(0.3333333333333333 \cdot {\ell}^{2} + 2\right)} + \left({\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right)\right) \cdot {\ell}^{2}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      10. fma-define91.9%

        \[\leadsto \left(\ell \cdot \left(J \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\right)} + \left({\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right)\right) \cdot {\ell}^{2}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      11. *-commutative91.9%

        \[\leadsto \left(\ell \cdot \left(J \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{2}, 2\right) + \color{blue}{\left(\left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{2}\right) + 0.016666666666666666 \cdot J\right) \cdot {\ell}^{2}\right)} \cdot {\ell}^{2}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      12. associate-*l*91.9%

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

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

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

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

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

    if -4.0999999999999996 < l < 0.10000000000000001

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

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

    if 0.10000000000000001 < 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. Taylor expanded in K around 0 60.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.1:\\ \;\;\;\;U + 0.0003968253968253968 \cdot \left(\left(J \cdot {\ell}^{7}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq 0.1:\\ \;\;\;\;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}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\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 7: 69.1% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 83.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 71.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 U around inf 74.9%

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

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

    1. Initial program 92.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 61.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-u98.9%

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

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

      \[\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 U around inf 63.6%

      \[\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)} \]
    7. Step-by-step derivation
      1. *-commutative63.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 67.4% accurate, 1.4× speedup?

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

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

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


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

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

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

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

    1. Initial program 92.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 61.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-u98.9%

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

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

      \[\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 U around inf 63.6%

      \[\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)} \]
    7. Step-by-step derivation
      1. *-commutative63.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 61.5% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;J \leq -1.95 \cdot 10^{+142} \lor \neg \left(J \leq 1.05 \cdot 10^{+207}\right):\\
\;\;\;\;2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < -1.95e142 or 1.05e207 < J

    1. Initial program 73.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 88.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-u98.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. *-commutative98.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-rr98.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 U around inf 84.6%

      \[\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)} \]
    7. Step-by-step derivation
      1. *-commutative84.6%

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

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

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

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

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

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

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

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

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

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

    if -1.95e142 < J < 1.05e207

    1. Initial program 91.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 60.6%

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

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

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

      \[\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 U around inf 65.1%

      \[\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)} \]
    7. Step-by-step derivation
      1. *-commutative65.1%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.95 \cdot 10^{+142} \lor \neg \left(J \leq 1.05 \cdot 10^{+207}\right):\\ \;\;\;\;2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 42.6% accurate, 23.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -6200000000 \lor \neg \left(\ell \leq 6.8 \cdot 10^{+22}\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -6.2e9 or 6.8e22 < 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-rr16.5%

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

    if -6.2e9 < l < 6.8e22

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

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

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

Alternative 11: 60.3% accurate, 28.4× speedup?

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

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

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

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

    \[\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 U around inf 68.8%

    \[\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)} \]
  7. Step-by-step derivation
    1. *-commutative68.8%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 53.8% accurate, 44.6× speedup?

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

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

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

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

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

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

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

Alternative 13: 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 88.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 J around 0 41.2%

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

Alternative 14: 2.8% accurate, 312.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 88.3%

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

    \[\leadsto \color{blue}{\frac{U}{U}} \]
  4. Taylor expanded in U around 0 2.7%

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

Reproduce

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