Average Error: 35.0 → 25.3
Time: 13.2s
Precision: binary64
\[\sqrt{\left(\left(2 \cdot n\right) \cdot U\right) \cdot \left(\left(t - 2 \cdot \frac{\ell \cdot \ell}{Om}\right) - \left(n \cdot {\left(\frac{\ell}{Om}\right)}^{2}\right) \cdot \left(U - U*\right)\right)} \]
\[\begin{array}{l} t_1 := \left(2 \cdot n\right) \cdot U\\ t_2 := \sqrt{t_1 \cdot \left(\left(t - 2 \cdot \frac{\ell \cdot \ell}{Om}\right) + \left(n \cdot {\left(\frac{\ell}{Om}\right)}^{2}\right) \cdot \left(U* - U\right)\right)}\\ \mathbf{if}\;t_2 \leq 0:\\ \;\;\;\;\sqrt{n \cdot \left(2 \cdot \left(U \cdot t\right) - 4 \cdot \frac{U \cdot {\ell}^{2}}{Om}\right)}\\ \mathbf{elif}\;t_2 \leq \infty:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(t_1, t, \left(t_1 \cdot \frac{\ell}{Om}\right) \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \frac{n}{\frac{Om}{\ell}}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(t_1, t, \left(2 \cdot \left(\frac{n}{Om} \cdot \left(U \cdot \ell\right)\right)\right) \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \left(n \cdot \frac{\ell}{Om}\right)\right)\right)}\\ \end{array} \]
(FPCore (n U t l Om U*)
 :precision binary64
 (sqrt
  (*
   (* (* 2.0 n) U)
   (- (- t (* 2.0 (/ (* l l) Om))) (* (* n (pow (/ l Om) 2.0)) (- U U*))))))
(FPCore (n U t l Om U*)
 :precision binary64
 (let* ((t_1 (* (* 2.0 n) U))
        (t_2
         (sqrt
          (*
           t_1
           (+
            (- t (* 2.0 (/ (* l l) Om)))
            (* (* n (pow (/ l Om) 2.0)) (- U* U)))))))
   (if (<= t_2 0.0)
     (sqrt (* n (- (* 2.0 (* U t)) (* 4.0 (/ (* U (pow l 2.0)) Om)))))
     (if (<= t_2 INFINITY)
       (sqrt
        (fma
         t_1
         t
         (* (* t_1 (/ l Om)) (fma l -2.0 (* (- U* U) (/ n (/ Om l)))))))
       (sqrt
        (fma
         t_1
         t
         (*
          (* 2.0 (* (/ n Om) (* U l)))
          (fma l -2.0 (* (- U* U) (* n (/ l Om)))))))))))
double code(double n, double U, double t, double l, double Om, double U_42_) {
	return sqrt((((2.0 * n) * U) * ((t - (2.0 * ((l * l) / Om))) - ((n * pow((l / Om), 2.0)) * (U - U_42_)))));
}
double code(double n, double U, double t, double l, double Om, double U_42_) {
	double t_1 = (2.0 * n) * U;
	double t_2 = sqrt((t_1 * ((t - (2.0 * ((l * l) / Om))) + ((n * pow((l / Om), 2.0)) * (U_42_ - U)))));
	double tmp;
	if (t_2 <= 0.0) {
		tmp = sqrt((n * ((2.0 * (U * t)) - (4.0 * ((U * pow(l, 2.0)) / Om)))));
	} else if (t_2 <= ((double) INFINITY)) {
		tmp = sqrt(fma(t_1, t, ((t_1 * (l / Om)) * fma(l, -2.0, ((U_42_ - U) * (n / (Om / l)))))));
	} else {
		tmp = sqrt(fma(t_1, t, ((2.0 * ((n / Om) * (U * l))) * fma(l, -2.0, ((U_42_ - U) * (n * (l / Om)))))));
	}
	return tmp;
}
function code(n, U, t, l, Om, U_42_)
	return sqrt(Float64(Float64(Float64(2.0 * n) * U) * Float64(Float64(t - Float64(2.0 * Float64(Float64(l * l) / Om))) - Float64(Float64(n * (Float64(l / Om) ^ 2.0)) * Float64(U - U_42_)))))
end
function code(n, U, t, l, Om, U_42_)
	t_1 = Float64(Float64(2.0 * n) * U)
	t_2 = sqrt(Float64(t_1 * Float64(Float64(t - Float64(2.0 * Float64(Float64(l * l) / Om))) + Float64(Float64(n * (Float64(l / Om) ^ 2.0)) * Float64(U_42_ - U)))))
	tmp = 0.0
	if (t_2 <= 0.0)
		tmp = sqrt(Float64(n * Float64(Float64(2.0 * Float64(U * t)) - Float64(4.0 * Float64(Float64(U * (l ^ 2.0)) / Om)))));
	elseif (t_2 <= Inf)
		tmp = sqrt(fma(t_1, t, Float64(Float64(t_1 * Float64(l / Om)) * fma(l, -2.0, Float64(Float64(U_42_ - U) * Float64(n / Float64(Om / l)))))));
	else
		tmp = sqrt(fma(t_1, t, Float64(Float64(2.0 * Float64(Float64(n / Om) * Float64(U * l))) * fma(l, -2.0, Float64(Float64(U_42_ - U) * Float64(n * Float64(l / Om)))))));
	end
	return tmp
end
code[n_, U_, t_, l_, Om_, U$42$_] := N[Sqrt[N[(N[(N[(2.0 * n), $MachinePrecision] * U), $MachinePrecision] * N[(N[(t - N[(2.0 * N[(N[(l * l), $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(n * N[Power[N[(l / Om), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(U - U$42$), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[n_, U_, t_, l_, Om_, U$42$_] := Block[{t$95$1 = N[(N[(2.0 * n), $MachinePrecision] * U), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(t$95$1 * N[(N[(t - N[(2.0 * N[(N[(l * l), $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(n * N[Power[N[(l / Om), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(U$42$ - U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$2, 0.0], N[Sqrt[N[(n * N[(N[(2.0 * N[(U * t), $MachinePrecision]), $MachinePrecision] - N[(4.0 * N[(N[(U * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision] / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$2, Infinity], N[Sqrt[N[(t$95$1 * t + N[(N[(t$95$1 * N[(l / Om), $MachinePrecision]), $MachinePrecision] * N[(l * -2.0 + N[(N[(U$42$ - U), $MachinePrecision] * N[(n / N[(Om / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(t$95$1 * t + N[(N[(2.0 * N[(N[(n / Om), $MachinePrecision] * N[(U * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(l * -2.0 + N[(N[(U$42$ - U), $MachinePrecision] * N[(n * N[(l / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
\sqrt{\left(\left(2 \cdot n\right) \cdot U\right) \cdot \left(\left(t - 2 \cdot \frac{\ell \cdot \ell}{Om}\right) - \left(n \cdot {\left(\frac{\ell}{Om}\right)}^{2}\right) \cdot \left(U - U*\right)\right)}
\begin{array}{l}
t_1 := \left(2 \cdot n\right) \cdot U\\
t_2 := \sqrt{t_1 \cdot \left(\left(t - 2 \cdot \frac{\ell \cdot \ell}{Om}\right) + \left(n \cdot {\left(\frac{\ell}{Om}\right)}^{2}\right) \cdot \left(U* - U\right)\right)}\\
\mathbf{if}\;t_2 \leq 0:\\
\;\;\;\;\sqrt{n \cdot \left(2 \cdot \left(U \cdot t\right) - 4 \cdot \frac{U \cdot {\ell}^{2}}{Om}\right)}\\

\mathbf{elif}\;t_2 \leq \infty:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(t_1, t, \left(t_1 \cdot \frac{\ell}{Om}\right) \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \frac{n}{\frac{Om}{\ell}}\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(t_1, t, \left(2 \cdot \left(\frac{n}{Om} \cdot \left(U \cdot \ell\right)\right)\right) \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \left(n \cdot \frac{\ell}{Om}\right)\right)\right)}\\


\end{array}

Error

Bits error versus n

Bits error versus U

Bits error versus t

Bits error versus l

Bits error versus Om

Bits error versus U*

Derivation

  1. Split input into 3 regimes
  2. if (sqrt.f64 (*.f64 (*.f64 (*.f64 2 n) U) (-.f64 (-.f64 t (*.f64 2 (/.f64 (*.f64 l l) Om))) (*.f64 (*.f64 n (pow.f64 (/.f64 l Om) 2)) (-.f64 U U*))))) < 0.0

    1. Initial program 56.4

      \[\sqrt{\left(\left(2 \cdot n\right) \cdot U\right) \cdot \left(\left(t - 2 \cdot \frac{\ell \cdot \ell}{Om}\right) - \left(n \cdot {\left(\frac{\ell}{Om}\right)}^{2}\right) \cdot \left(U - U*\right)\right)} \]
    2. Simplified55.9

      \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \left(n \cdot U\right)\right) \cdot \left(t + \frac{\ell}{Om} \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \left(n \cdot \frac{\ell}{Om}\right)\right)\right)}} \]
    3. Taylor expanded in n around 0 38.3

      \[\leadsto \sqrt{\color{blue}{n \cdot \left(2 \cdot \left(t \cdot U\right) - 4 \cdot \frac{{\ell}^{2} \cdot U}{Om}\right)}} \]

    if 0.0 < (sqrt.f64 (*.f64 (*.f64 (*.f64 2 n) U) (-.f64 (-.f64 t (*.f64 2 (/.f64 (*.f64 l l) Om))) (*.f64 (*.f64 n (pow.f64 (/.f64 l Om) 2)) (-.f64 U U*))))) < +inf.0

    1. Initial program 24.9

      \[\sqrt{\left(\left(2 \cdot n\right) \cdot U\right) \cdot \left(\left(t - 2 \cdot \frac{\ell \cdot \ell}{Om}\right) - \left(n \cdot {\left(\frac{\ell}{Om}\right)}^{2}\right) \cdot \left(U - U*\right)\right)} \]
    2. Simplified21.2

      \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \left(n \cdot U\right)\right) \cdot \left(t + \frac{\ell}{Om} \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \left(n \cdot \frac{\ell}{Om}\right)\right)\right)}} \]
    3. Applied egg-rr21.2

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\left(2 \cdot n\right) \cdot U, t, \left(\left(2 \cdot n\right) \cdot U\right) \cdot \left(\frac{\ell}{Om} \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \left(n \cdot \frac{\ell}{Om}\right)\right)\right)\right)}} \]
    4. Applied egg-rr19.2

      \[\leadsto \sqrt{\mathsf{fma}\left(\left(2 \cdot n\right) \cdot U, t, \color{blue}{{\left(\left(\left(\left(2 \cdot n\right) \cdot U\right) \cdot \frac{\ell}{Om}\right) \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \left(n \cdot \frac{\ell}{Om}\right)\right)\right)}^{1}}\right)} \]
    5. Taylor expanded in n around 0 20.5

      \[\leadsto \sqrt{\mathsf{fma}\left(\left(2 \cdot n\right) \cdot U, t, {\left(\left(\left(\left(2 \cdot n\right) \cdot U\right) \cdot \frac{\ell}{Om}\right) \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \color{blue}{\frac{n \cdot \ell}{Om}}\right)\right)}^{1}\right)} \]
    6. Simplified19.2

      \[\leadsto \sqrt{\mathsf{fma}\left(\left(2 \cdot n\right) \cdot U, t, {\left(\left(\left(\left(2 \cdot n\right) \cdot U\right) \cdot \frac{\ell}{Om}\right) \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \color{blue}{\frac{n}{\frac{Om}{\ell}}}\right)\right)}^{1}\right)} \]

    if +inf.0 < (sqrt.f64 (*.f64 (*.f64 (*.f64 2 n) U) (-.f64 (-.f64 t (*.f64 2 (/.f64 (*.f64 l l) Om))) (*.f64 (*.f64 n (pow.f64 (/.f64 l Om) 2)) (-.f64 U U*)))))

    1. Initial program 64.0

      \[\sqrt{\left(\left(2 \cdot n\right) \cdot U\right) \cdot \left(\left(t - 2 \cdot \frac{\ell \cdot \ell}{Om}\right) - \left(n \cdot {\left(\frac{\ell}{Om}\right)}^{2}\right) \cdot \left(U - U*\right)\right)} \]
    2. Simplified57.6

      \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \left(n \cdot U\right)\right) \cdot \left(t + \frac{\ell}{Om} \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \left(n \cdot \frac{\ell}{Om}\right)\right)\right)}} \]
    3. Applied egg-rr57.6

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\left(2 \cdot n\right) \cdot U, t, \left(\left(2 \cdot n\right) \cdot U\right) \cdot \left(\frac{\ell}{Om} \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \left(n \cdot \frac{\ell}{Om}\right)\right)\right)\right)}} \]
    4. Applied egg-rr51.3

      \[\leadsto \sqrt{\mathsf{fma}\left(\left(2 \cdot n\right) \cdot U, t, \color{blue}{{\left(\left(\left(\left(2 \cdot n\right) \cdot U\right) \cdot \frac{\ell}{Om}\right) \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \left(n \cdot \frac{\ell}{Om}\right)\right)\right)}^{1}}\right)} \]
    5. Taylor expanded in n around 0 45.4

      \[\leadsto \sqrt{\mathsf{fma}\left(\left(2 \cdot n\right) \cdot U, t, {\left(\color{blue}{\left(2 \cdot \frac{n \cdot \left(\ell \cdot U\right)}{Om}\right)} \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \left(n \cdot \frac{\ell}{Om}\right)\right)\right)}^{1}\right)} \]
    6. Simplified42.7

      \[\leadsto \sqrt{\mathsf{fma}\left(\left(2 \cdot n\right) \cdot U, t, {\left(\color{blue}{\left(2 \cdot \left(\frac{n}{Om} \cdot \left(\ell \cdot U\right)\right)\right)} \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \left(n \cdot \frac{\ell}{Om}\right)\right)\right)}^{1}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sqrt{\left(\left(2 \cdot n\right) \cdot U\right) \cdot \left(\left(t - 2 \cdot \frac{\ell \cdot \ell}{Om}\right) + \left(n \cdot {\left(\frac{\ell}{Om}\right)}^{2}\right) \cdot \left(U* - U\right)\right)} \leq 0:\\ \;\;\;\;\sqrt{n \cdot \left(2 \cdot \left(U \cdot t\right) - 4 \cdot \frac{U \cdot {\ell}^{2}}{Om}\right)}\\ \mathbf{elif}\;\sqrt{\left(\left(2 \cdot n\right) \cdot U\right) \cdot \left(\left(t - 2 \cdot \frac{\ell \cdot \ell}{Om}\right) + \left(n \cdot {\left(\frac{\ell}{Om}\right)}^{2}\right) \cdot \left(U* - U\right)\right)} \leq \infty:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(\left(2 \cdot n\right) \cdot U, t, \left(\left(\left(2 \cdot n\right) \cdot U\right) \cdot \frac{\ell}{Om}\right) \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \frac{n}{\frac{Om}{\ell}}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(\left(2 \cdot n\right) \cdot U, t, \left(2 \cdot \left(\frac{n}{Om} \cdot \left(U \cdot \ell\right)\right)\right) \cdot \mathsf{fma}\left(\ell, -2, \left(U* - U\right) \cdot \left(n \cdot \frac{\ell}{Om}\right)\right)\right)}\\ \end{array} \]

Reproduce

herbie shell --seed 2022162 
(FPCore (n U t l Om U*)
  :name "Toniolo and Linder, Equation (13)"
  :precision binary64
  (sqrt (* (* (* 2.0 n) U) (- (- t (* 2.0 (/ (* l l) Om))) (* (* n (pow (/ l Om) 2.0)) (- U U*))))))