Average Error: 2.5 → 0.6
Time: 8.6s
Precision: binary64
\[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
\[\begin{array}{l} t_1 := x - \frac{y}{z \cdot 3}\\ \mathbf{if}\;z \cdot 3 \leq -6.46146349214255 \cdot 10^{+19}:\\ \;\;\;\;t_1 + \frac{\frac{t}{z \cdot 3}}{y}\\ \mathbf{elif}\;z \cdot 3 \leq 4.143106767245704 \cdot 10^{-55}:\\ \;\;\;\;\mathsf{fma}\left(0.3333333333333333, \frac{1}{\frac{z}{\frac{t}{y} - y}}, x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + \frac{t}{\left(z \cdot 3\right) \cdot y}\\ \end{array} \]
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\begin{array}{l}
t_1 := x - \frac{y}{z \cdot 3}\\
\mathbf{if}\;z \cdot 3 \leq -6.46146349214255 \cdot 10^{+19}:\\
\;\;\;\;t_1 + \frac{\frac{t}{z \cdot 3}}{y}\\

\mathbf{elif}\;z \cdot 3 \leq 4.143106767245704 \cdot 10^{-55}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333, \frac{1}{\frac{z}{\frac{t}{y} - y}}, x\right)\\

\mathbf{else}:\\
\;\;\;\;t_1 + \frac{t}{\left(z \cdot 3\right) \cdot y}\\


\end{array}
(FPCore (x y z t)
 :precision binary64
 (+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (- x (/ y (* z 3.0)))))
   (if (<= (* z 3.0) -6.46146349214255e+19)
     (+ t_1 (/ (/ t (* z 3.0)) y))
     (if (<= (* z 3.0) 4.143106767245704e-55)
       (fma 0.3333333333333333 (/ 1.0 (/ z (- (/ t y) y))) x)
       (+ t_1 (/ t (* (* z 3.0) y)))))))
double code(double x, double y, double z, double t) {
	return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y));
}
double code(double x, double y, double z, double t) {
	double t_1 = x - (y / (z * 3.0));
	double tmp;
	if ((z * 3.0) <= -6.46146349214255e+19) {
		tmp = t_1 + ((t / (z * 3.0)) / y);
	} else if ((z * 3.0) <= 4.143106767245704e-55) {
		tmp = fma(0.3333333333333333, (1.0 / (z / ((t / y) - y))), x);
	} else {
		tmp = t_1 + (t / ((z * 3.0) * y));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original2.5
Target2.6
Herbie0.6
\[\left(x - \frac{y}{z \cdot 3}\right) + \frac{\frac{t}{z \cdot 3}}{y} \]

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 z 3) < -64614634921425502000

    1. Initial program 0.4

      \[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
    2. Applied associate-/r*_binary641.3

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

    if -64614634921425502000 < (*.f64 z 3) < 4.143106767245704e-55

    1. Initial program 5.0

      \[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
    2. Simplified0.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-0.3333333333333333}{z}, y - \frac{t}{y}, x\right)} \]
    3. Applied fma-udef_binary640.2

      \[\leadsto \color{blue}{\frac{-0.3333333333333333}{z} \cdot \left(y - \frac{t}{y}\right) + x} \]
    4. Simplified0.2

      \[\leadsto \color{blue}{\frac{0.3333333333333333}{\frac{z}{\frac{t}{y} - y}}} + x \]
    5. Applied div-inv_binary640.2

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{1}{\frac{z}{\frac{t}{y} - y}}} + x \]
    6. Applied fma-def_binary640.2

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

    if 4.143106767245704e-55 < (*.f64 z 3)

    1. Initial program 0.5

      \[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot 3 \leq -6.46146349214255 \cdot 10^{+19}:\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{\frac{t}{z \cdot 3}}{y}\\ \mathbf{elif}\;z \cdot 3 \leq 4.143106767245704 \cdot 10^{-55}:\\ \;\;\;\;\mathsf{fma}\left(0.3333333333333333, \frac{1}{\frac{z}{\frac{t}{y} - y}}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\\ \end{array} \]

Reproduce

herbie shell --seed 2022068 
(FPCore (x y z t)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, H"
  :precision binary64

  :herbie-target
  (+ (- x (/ y (* z 3.0))) (/ (/ t (* z 3.0)) y))

  (+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))