Average Error: 4.5 → 2.1
Time: 10.4s
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}\\ \mathbf{if}\;t_1 \leq -2.181314069237898 \cdot 10^{-307}:\\ \;\;\;\;\begin{array}{l} t_2 := \frac{-1}{1 - z}\\ x \cdot \left(\mathsf{fma}\left(y, \frac{1}{z}, t \cdot t_2\right) + \mathsf{fma}\left(t_2, t, t \cdot \frac{1}{1 - z}\right)\right) \end{array}\\ \mathbf{elif}\;t_1 \leq 1.1559562824622024 \cdot 10^{-159}:\\ \;\;\;\;\frac{x}{z} \cdot \left(y + t\right)\\ \mathbf{elif}\;t_1 \leq 6.454915979042131 \cdot 10^{+273}:\\ \;\;\;\;t_1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z} - t \cdot x\\ \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}\\
\mathbf{if}\;t_1 \leq -2.181314069237898 \cdot 10^{-307}:\\
\;\;\;\;\begin{array}{l}
t_2 := \frac{-1}{1 - z}\\
x \cdot \left(\mathsf{fma}\left(y, \frac{1}{z}, t \cdot t_2\right) + \mathsf{fma}\left(t_2, t, t \cdot \frac{1}{1 - z}\right)\right)
\end{array}\\

\mathbf{elif}\;t_1 \leq 1.1559562824622024 \cdot 10^{-159}:\\
\;\;\;\;\frac{x}{z} \cdot \left(y + t\right)\\

\mathbf{elif}\;t_1 \leq 6.454915979042131 \cdot 10^{+273}:\\
\;\;\;\;t_1 \cdot x\\

\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x}{z} - t \cdot 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 (- (/ y z) (/ t (- 1.0 z)))))
   (if (<= t_1 -2.181314069237898e-307)
     (let* ((t_2 (/ -1.0 (- 1.0 z))))
       (*
        x
        (+ (fma y (/ 1.0 z) (* t t_2)) (fma t_2 t (* t (/ 1.0 (- 1.0 z)))))))
     (if (<= t_1 1.1559562824622024e-159)
       (* (/ x z) (+ y t))
       (if (<= t_1 6.454915979042131e+273)
         (* t_1 x)
         (- (/ (* y x) z) (* t 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 = (y / z) - (t / (1.0 - z));
	double tmp;
	if (t_1 <= -2.181314069237898e-307) {
		double t_2_1 = -1.0 / (1.0 - z);
		tmp = x * (fma(y, (1.0 / z), (t * t_2_1)) + fma(t_2_1, t, (t * (1.0 / (1.0 - z)))));
	} else if (t_1 <= 1.1559562824622024e-159) {
		tmp = (x / z) * (y + t);
	} else if (t_1 <= 6.454915979042131e+273) {
		tmp = t_1 * x;
	} else {
		tmp = ((y * x) / z) - (t * x);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.5
Target4.2
Herbie2.1
\[\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 4 regimes
  2. if (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < -2.18131406923789798e-307

    1. Initial program 3.6

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

      \[\leadsto x \cdot \left(\frac{y}{z} - \color{blue}{t \cdot \frac{1}{1 - z}}\right) \]
    3. Applied div-inv_binary643.7

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

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

    if -2.18131406923789798e-307 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 1.15595628246220237e-159

    1. Initial program 9.5

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

      \[\leadsto x \cdot \color{blue}{\left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right)} \]
    3. Taylor expanded in z around inf 2.3

      \[\leadsto \color{blue}{\frac{y \cdot x + t \cdot x}{z}} \]
    4. Simplified2.2

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

    if 1.15595628246220237e-159 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 6.45491597904213068e273

    1. Initial program 0.2

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

      \[\leadsto x \cdot \color{blue}{\left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right)} \]
    3. Taylor expanded in x around 0 0.2

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

    if 6.45491597904213068e273 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z)))

    1. Initial program 38.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y}{z} - \frac{t}{1 - z} \leq -2.181314069237898 \cdot 10^{-307}:\\ \;\;\;\;x \cdot \left(\mathsf{fma}\left(y, \frac{1}{z}, t \cdot \frac{-1}{1 - z}\right) + \mathsf{fma}\left(\frac{-1}{1 - z}, t, t \cdot \frac{1}{1 - z}\right)\right)\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \leq 1.1559562824622024 \cdot 10^{-159}:\\ \;\;\;\;\frac{x}{z} \cdot \left(y + t\right)\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \leq 6.454915979042131 \cdot 10^{+273}:\\ \;\;\;\;\left(\frac{y}{z} - \frac{t}{1 - z}\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z} - t \cdot x\\ \end{array} \]

Reproduce

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