Average Error: 4.6 → 2.1
Time: 16.8s
Precision: binary64
\[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
\[\begin{array}{l} t_1 := y \cdot \frac{x}{z} - \frac{t \cdot x}{1 - z}\\ t_2 := \frac{y}{z} - \frac{t}{1 - z}\\ t_3 := t_2 \cdot x\\ \mathbf{if}\;t_2 \leq -3.484467357253671 \cdot 10^{-197}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq 2.6205032469197644 \cdot 10^{-272}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 8.431641861418719 \cdot 10^{+179}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
t_1 := y \cdot \frac{x}{z} - \frac{t \cdot x}{1 - z}\\
t_2 := \frac{y}{z} - \frac{t}{1 - z}\\
t_3 := t_2 \cdot x\\
\mathbf{if}\;t_2 \leq -3.484467357253671 \cdot 10^{-197}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_2 \leq 2.6205032469197644 \cdot 10^{-272}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq 8.431641861418719 \cdot 10^{+179}:\\
\;\;\;\;t_3\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\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 (/ x z)) (/ (* t x) (- 1.0 z))))
        (t_2 (- (/ y z) (/ t (- 1.0 z))))
        (t_3 (* t_2 x)))
   (if (<= t_2 -3.484467357253671e-197)
     t_3
     (if (<= t_2 2.6205032469197644e-272)
       t_1
       (if (<= t_2 8.431641861418719e+179) t_3 t_1)))))
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 * (x / z)) - ((t * x) / (1.0 - z));
	double t_2 = (y / z) - (t / (1.0 - z));
	double t_3 = t_2 * x;
	double tmp;
	if (t_2 <= -3.484467357253671e-197) {
		tmp = t_3;
	} else if (t_2 <= 2.6205032469197644e-272) {
		tmp = t_1;
	} else if (t_2 <= 8.431641861418719e+179) {
		tmp = t_3;
	} else {
		tmp = t_1;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original4.6
Target3.9
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 2 regimes
  2. if (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < -3.48446735725367071e-197 or 2.62050324691976437e-272 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 8.4316418614187192e179

    1. Initial program 2.2

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

    if -3.48446735725367071e-197 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 2.62050324691976437e-272 or 8.4316418614187192e179 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z)))

    1. Initial program 13.9

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

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

      \[\leadsto \frac{y \cdot x}{\color{blue}{1 \cdot z}} - \frac{t \cdot x}{1 - z} \]
    4. Applied times-frac_binary641.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y}{z} - \frac{t}{1 - z} \leq -3.484467357253671 \cdot 10^{-197}:\\ \;\;\;\;\left(\frac{y}{z} - \frac{t}{1 - z}\right) \cdot x\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \leq 2.6205032469197644 \cdot 10^{-272}:\\ \;\;\;\;y \cdot \frac{x}{z} - \frac{t \cdot x}{1 - z}\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \leq 8.431641861418719 \cdot 10^{+179}:\\ \;\;\;\;\left(\frac{y}{z} - \frac{t}{1 - z}\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z} - \frac{t \cdot x}{1 - z}\\ \end{array} \]

Reproduce

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