Average Error: 4.6 → 1.9
Time: 12.1s
Precision: binary64
\[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
\[\begin{array}{l} t_1 := \frac{t}{1 - z}\\ t_2 := \frac{y}{z} - t_1\\ \mathbf{if}\;t_2 \leq -3.0066117955886623 \cdot 10^{+167}:\\ \;\;\;\;\frac{y \cdot x}{z} - t_1 \cdot x\\ \mathbf{elif}\;t_2 \leq 1.0804566676969925 \cdot 10^{+220}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(\frac{y}{z}, 1, \frac{-t}{1 - z}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{z \cdot t - \left(y \cdot x\right) \cdot \frac{1 - z}{x}}{z \cdot \frac{z + -1}{x}}\\ \end{array} \]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
t_1 := \frac{t}{1 - z}\\
t_2 := \frac{y}{z} - t_1\\
\mathbf{if}\;t_2 \leq -3.0066117955886623 \cdot 10^{+167}:\\
\;\;\;\;\frac{y \cdot x}{z} - t_1 \cdot x\\

\mathbf{elif}\;t_2 \leq 1.0804566676969925 \cdot 10^{+220}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(\frac{y}{z}, 1, \frac{-t}{1 - z}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{z \cdot t - \left(y \cdot x\right) \cdot \frac{1 - z}{x}}{z \cdot \frac{z + -1}{x}}\\


\end{array}
(FPCore (x y z t) :precision binary64 (* x (- (/ y z) (/ t (- 1.0 z)))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (/ t (- 1.0 z))) (t_2 (- (/ y z) t_1)))
   (if (<= t_2 -3.0066117955886623e+167)
     (- (/ (* y x) z) (* t_1 x))
     (if (<= t_2 1.0804566676969925e+220)
       (* x (fma (/ y z) 1.0 (/ (- t) (- 1.0 z))))
       (/ (- (* z t) (* (* y x) (/ (- 1.0 z) x))) (* z (/ (+ z -1.0) x)))))))
double code(double x, double y, double z, double t) {
	return x * ((y / z) - (t / (1.0 - z)));
}
double code(double x, double y, double z, double t) {
	double t_1 = t / (1.0 - z);
	double t_2 = (y / z) - t_1;
	double tmp;
	if (t_2 <= -3.0066117955886623e+167) {
		tmp = ((y * x) / z) - (t_1 * x);
	} else if (t_2 <= 1.0804566676969925e+220) {
		tmp = x * fma((y / z), 1.0, (-t / (1.0 - z)));
	} else {
		tmp = ((z * t) - ((y * x) * ((1.0 - z) / x))) / (z * ((z + -1.0) / x));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.6
Target4.0
Herbie1.9
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) < -7.623226303312042 \cdot 10^{-196}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t \cdot \frac{1}{1 - z}\right)\\ \mathbf{elif}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) < 1.4133944927702302 \cdot 10^{-211}:\\ \;\;\;\;\frac{y \cdot x}{z} + \left(-\frac{t \cdot x}{1 - z}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t \cdot \frac{1}{1 - z}\right)\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < -3.00661179558866231e167

    1. Initial program 13.8

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
    2. Taylor expanded in y around 0 2.6

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

      \[\leadsto \frac{y \cdot x}{z} - \color{blue}{\frac{t}{1 - z} \cdot x} \]

    if -3.00661179558866231e167 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 1.08045666769699253e220

    1. Initial program 1.8

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
    2. Applied egg-rr1.8

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

    if 1.08045666769699253e220 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z)))

    1. Initial program 22.3

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
    2. Taylor expanded in y around 0 0.9

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

      \[\leadsto \color{blue}{\frac{\left(-y \cdot x\right) \cdot \frac{1 - z}{x} - \left(-z\right) \cdot t}{\left(-z\right) \cdot \frac{1 - z}{x}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y}{z} - \frac{t}{1 - z} \leq -3.0066117955886623 \cdot 10^{+167}:\\ \;\;\;\;\frac{y \cdot x}{z} - \frac{t}{1 - z} \cdot x\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \leq 1.0804566676969925 \cdot 10^{+220}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(\frac{y}{z}, 1, \frac{-t}{1 - z}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{z \cdot t - \left(y \cdot x\right) \cdot \frac{1 - z}{x}}{z \cdot \frac{z + -1}{x}}\\ \end{array} \]

Reproduce

herbie shell --seed 2022130 
(FPCore (x y z t)
  :name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, C"
  :precision binary64

  :herbie-target
  (if (< (* x (- (/ y z) (/ t (- 1.0 z)))) -7.623226303312042e-196) (* x (- (/ y z) (* t (/ 1.0 (- 1.0 z))))) (if (< (* x (- (/ y z) (/ t (- 1.0 z)))) 1.4133944927702302e-211) (+ (/ (* y x) z) (- (/ (* t x) (- 1.0 z)))) (* x (- (/ y z) (* t (/ 1.0 (- 1.0 z)))))))

  (* x (- (/ y z) (/ t (- 1.0 z)))))