Average Error: 24.4 → 6.6
Time: 7.4s
Precision: binary64
\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}} \]
\[\begin{array}{l} t_1 := \left(y \cdot x\right) \cdot \frac{z}{\sqrt{z \cdot z - a \cdot t}}\\ \mathbf{if}\;z \leq -4.148739357778477 \cdot 10^{+114}:\\ \;\;\;\;\frac{y \cdot x}{\mathsf{fma}\left(\frac{a \cdot 0.5}{z}, \frac{t}{z}, -1\right)}\\ \mathbf{elif}\;z \leq -1.5 \cdot 10^{-196}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{-195}:\\ \;\;\;\;y \cdot \left(\left(z \cdot x\right) \cdot \sqrt{\frac{-1}{a \cdot t}}\right)\\ \mathbf{elif}\;z \leq 0.00022:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{\mathsf{fma}\left(-0.5, \frac{t}{z} \cdot \frac{a}{z}, 1\right)}\\ \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (/ (* (* x y) z) (sqrt (- (* z z) (* t a)))))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (* (* y x) (/ z (sqrt (- (* z z) (* a t)))))))
   (if (<= z -4.148739357778477e+114)
     (/ (* y x) (fma (/ (* a 0.5) z) (/ t z) -1.0))
     (if (<= z -1.5e-196)
       t_1
       (if (<= z 1.3e-195)
         (* y (* (* z x) (sqrt (/ -1.0 (* a t)))))
         (if (<= z 0.00022)
           t_1
           (/ (* y x) (fma -0.5 (* (/ t z) (/ a z)) 1.0))))))))
double code(double x, double y, double z, double t, double a) {
	return ((x * y) * z) / sqrt(((z * z) - (t * a)));
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = (y * x) * (z / sqrt(((z * z) - (a * t))));
	double tmp;
	if (z <= -4.148739357778477e+114) {
		tmp = (y * x) / fma(((a * 0.5) / z), (t / z), -1.0);
	} else if (z <= -1.5e-196) {
		tmp = t_1;
	} else if (z <= 1.3e-195) {
		tmp = y * ((z * x) * sqrt((-1.0 / (a * t))));
	} else if (z <= 0.00022) {
		tmp = t_1;
	} else {
		tmp = (y * x) / fma(-0.5, ((t / z) * (a / z)), 1.0);
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(Float64(Float64(x * y) * z) / sqrt(Float64(Float64(z * z) - Float64(t * a))))
end
function code(x, y, z, t, a)
	t_1 = Float64(Float64(y * x) * Float64(z / sqrt(Float64(Float64(z * z) - Float64(a * t)))))
	tmp = 0.0
	if (z <= -4.148739357778477e+114)
		tmp = Float64(Float64(y * x) / fma(Float64(Float64(a * 0.5) / z), Float64(t / z), -1.0));
	elseif (z <= -1.5e-196)
		tmp = t_1;
	elseif (z <= 1.3e-195)
		tmp = Float64(y * Float64(Float64(z * x) * sqrt(Float64(-1.0 / Float64(a * t)))));
	elseif (z <= 0.00022)
		tmp = t_1;
	else
		tmp = Float64(Float64(y * x) / fma(-0.5, Float64(Float64(t / z) * Float64(a / z)), 1.0));
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] * z), $MachinePrecision] / N[Sqrt[N[(N[(z * z), $MachinePrecision] - N[(t * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y * x), $MachinePrecision] * N[(z / N[Sqrt[N[(N[(z * z), $MachinePrecision] - N[(a * t), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -4.148739357778477e+114], N[(N[(y * x), $MachinePrecision] / N[(N[(N[(a * 0.5), $MachinePrecision] / z), $MachinePrecision] * N[(t / z), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, -1.5e-196], t$95$1, If[LessEqual[z, 1.3e-195], N[(y * N[(N[(z * x), $MachinePrecision] * N[Sqrt[N[(-1.0 / N[(a * t), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.00022], t$95$1, N[(N[(y * x), $MachinePrecision] / N[(-0.5 * N[(N[(t / z), $MachinePrecision] * N[(a / z), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]]]]]
\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}}
\begin{array}{l}
t_1 := \left(y \cdot x\right) \cdot \frac{z}{\sqrt{z \cdot z - a \cdot t}}\\
\mathbf{if}\;z \leq -4.148739357778477 \cdot 10^{+114}:\\
\;\;\;\;\frac{y \cdot x}{\mathsf{fma}\left(\frac{a \cdot 0.5}{z}, \frac{t}{z}, -1\right)}\\

\mathbf{elif}\;z \leq -1.5 \cdot 10^{-196}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq 1.3 \cdot 10^{-195}:\\
\;\;\;\;y \cdot \left(\left(z \cdot x\right) \cdot \sqrt{\frac{-1}{a \cdot t}}\right)\\

\mathbf{elif}\;z \leq 0.00022:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x}{\mathsf{fma}\left(-0.5, \frac{t}{z} \cdot \frac{a}{z}, 1\right)}\\


\end{array}

Error

Target

Original24.4
Target7.8
Herbie6.6
\[\begin{array}{l} \mathbf{if}\;z < -3.1921305903852764 \cdot 10^{+46}:\\ \;\;\;\;-y \cdot x\\ \mathbf{elif}\;z < 5.976268120920894 \cdot 10^{+90}:\\ \;\;\;\;\frac{x \cdot z}{\frac{\sqrt{z \cdot z - a \cdot t}}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]

Derivation

  1. Split input into 4 regimes
  2. if z < -4.1487393577784772e114

    1. Initial program 44.8

      \[\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}} \]
    2. Simplified44.9

      \[\leadsto \color{blue}{x \cdot \frac{y \cdot z}{\sqrt{z \cdot z - t \cdot a}}} \]
    3. Applied egg-rr43.1

      \[\leadsto \color{blue}{\frac{y \cdot x}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}} \]
    4. Taylor expanded in z around -inf 6.4

      \[\leadsto \frac{y \cdot x}{\color{blue}{0.5 \cdot \frac{a \cdot t}{{z}^{2}} - 1}} \]
    5. Simplified2.0

      \[\leadsto \frac{y \cdot x}{\color{blue}{\mathsf{fma}\left(\frac{a \cdot 0.5}{z}, \frac{t}{z}, -1\right)}} \]

    if -4.1487393577784772e114 < z < -1.5e-196 or 1.3000000000000001e-195 < z < 2.20000000000000008e-4

    1. Initial program 9.0

      \[\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}} \]
    2. Simplified9.2

      \[\leadsto \color{blue}{x \cdot \frac{y \cdot z}{\sqrt{z \cdot z - t \cdot a}}} \]
    3. Applied egg-rr6.6

      \[\leadsto \color{blue}{\frac{y \cdot x}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}} \]
    4. Applied egg-rr6.5

      \[\leadsto \color{blue}{\left(y \cdot x\right) \cdot \frac{z}{\sqrt{z \cdot z - t \cdot a}}} \]

    if -1.5e-196 < z < 1.3000000000000001e-195

    1. Initial program 18.4

      \[\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}} \]
    2. Simplified16.9

      \[\leadsto \color{blue}{x \cdot \frac{y \cdot z}{\sqrt{z \cdot z - t \cdot a}}} \]
    3. Taylor expanded in z around 0 18.2

      \[\leadsto \color{blue}{\sqrt{\frac{-1}{a \cdot t}} \cdot \left(y \cdot \left(z \cdot x\right)\right)} \]
    4. Simplified18.3

      \[\leadsto \color{blue}{y \cdot \left(\left(z \cdot x\right) \cdot \sqrt{\frac{-1}{a \cdot t}}\right)} \]

    if 2.20000000000000008e-4 < z

    1. Initial program 32.7

      \[\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}} \]
    2. Simplified33.1

      \[\leadsto \color{blue}{x \cdot \frac{y \cdot z}{\sqrt{z \cdot z - t \cdot a}}} \]
    3. Applied egg-rr30.0

      \[\leadsto \color{blue}{\frac{y \cdot x}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}} \]
    4. Taylor expanded in z around inf 7.1

      \[\leadsto \frac{y \cdot x}{\color{blue}{1 + -0.5 \cdot \frac{a \cdot t}{{z}^{2}}}} \]
    5. Simplified4.3

      \[\leadsto \frac{y \cdot x}{\color{blue}{\mathsf{fma}\left(-0.5, \frac{a}{z} \cdot \frac{t}{z}, 1\right)}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification6.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.148739357778477 \cdot 10^{+114}:\\ \;\;\;\;\frac{y \cdot x}{\mathsf{fma}\left(\frac{a \cdot 0.5}{z}, \frac{t}{z}, -1\right)}\\ \mathbf{elif}\;z \leq -1.5 \cdot 10^{-196}:\\ \;\;\;\;\left(y \cdot x\right) \cdot \frac{z}{\sqrt{z \cdot z - a \cdot t}}\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{-195}:\\ \;\;\;\;y \cdot \left(\left(z \cdot x\right) \cdot \sqrt{\frac{-1}{a \cdot t}}\right)\\ \mathbf{elif}\;z \leq 0.00022:\\ \;\;\;\;\left(y \cdot x\right) \cdot \frac{z}{\sqrt{z \cdot z - a \cdot t}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{\mathsf{fma}\left(-0.5, \frac{t}{z} \cdot \frac{a}{z}, 1\right)}\\ \end{array} \]

Reproduce

herbie shell --seed 2022192 
(FPCore (x y z t a)
  :name "Statistics.Math.RootFinding:ridders from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (if (< z -3.1921305903852764e+46) (- (* y x)) (if (< z 5.976268120920894e+90) (/ (* x z) (/ (sqrt (- (* z z) (* a t))) y)) (* y x)))

  (/ (* (* x y) z) (sqrt (- (* z z) (* t a)))))