Average Error: 3.5 → 1.3
Time: 11.1s
Precision: binary64
\[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
\[\begin{array}{l} t_1 := \frac{y}{z} - \frac{t}{1 - z}\\ t_2 := \frac{y \cdot x}{z}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 1.1470477417419808 \cdot 10^{+254}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(1, \frac{y}{z}, \frac{t}{z + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;t_2 - t \cdot \frac{x}{1 - z}\\ \end{array} \]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
t_1 := \frac{y}{z} - \frac{t}{1 - z}\\
t_2 := \frac{y \cdot x}{z}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;t_2\\

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

\mathbf{else}:\\
\;\;\;\;t_2 - t \cdot \frac{x}{1 - z}\\


\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 (- (/ y z) (/ t (- 1.0 z)))) (t_2 (/ (* y x) z)))
   (if (<= t_1 (- INFINITY))
     t_2
     (if (<= t_1 1.1470477417419808e+254)
       (* x (fma 1.0 (/ y z) (/ t (+ z -1.0))))
       (- t_2 (* t (/ x (- 1.0 z))))))))
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 = (y / z) - (t / (1.0 - z));
	double t_2 = (y * x) / z;
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = t_2;
	} else if (t_1 <= 1.1470477417419808e+254) {
		tmp = x * fma(1.0, (y / z), (t / (z + -1.0)));
	} else {
		tmp = t_2 - (t * (x / (1.0 - z)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original3.5
Target3.3
Herbie1.3
\[\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))) < -inf.0

    1. Initial program 22.0

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} - \frac{t \cdot x}{1 - z}} \]
    3. Taylor expanded in y around inf 0.1

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
    4. Simplified0.1

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

    if -inf.0 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 1.14704774174198081e254

    1. Initial program 1.1

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

      \[\leadsto x \cdot \left(\frac{y}{z} - \color{blue}{t \cdot \frac{1}{1 - z}}\right) \]
    3. Applied *-un-lft-identity_binary641.1

      \[\leadsto x \cdot \left(\frac{y}{\color{blue}{1 \cdot z}} - t \cdot \frac{1}{1 - z}\right) \]
    4. Applied *-un-lft-identity_binary641.1

      \[\leadsto x \cdot \left(\frac{\color{blue}{1 \cdot y}}{1 \cdot z} - t \cdot \frac{1}{1 - z}\right) \]
    5. Applied times-frac_binary641.1

      \[\leadsto x \cdot \left(\color{blue}{\frac{1}{1} \cdot \frac{y}{z}} - t \cdot \frac{1}{1 - z}\right) \]
    6. Applied fma-neg_binary641.1

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

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

    if 1.14704774174198081e254 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z)))

    1. Initial program 13.1

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} - \frac{t \cdot x}{1 - z}} \]
    3. Applied *-un-lft-identity_binary643.4

      \[\leadsto \frac{y \cdot x}{z} - \frac{t \cdot x}{\color{blue}{1 \cdot \left(1 - z\right)}} \]
    4. Applied times-frac_binary643.4

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

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

Reproduce

herbie shell --seed 2022088 
(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)))))