Average Error: 3.6 → 0.9
Time: 6.8s
Precision: binary64
\[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
\[\begin{array}{l} \mathbf{if}\;z \cdot 3 \leq -5.340817638704946 \cdot 10^{-84} \lor \neg \left(z \cdot 3 \leq 9.199046531699814 \cdot 10^{+119}\right):\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.3333333333333333, \frac{\frac{t}{y} - y}{z}, x\right)\\ \end{array} \]
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;z \cdot 3 \leq -5.340817638704946 \cdot 10^{-84} \lor \neg \left(z \cdot 3 \leq 9.199046531699814 \cdot 10^{+119}\right):\\
\;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333, \frac{\frac{t}{y} - y}{z}, x\right)\\


\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
 (if (or (<= (* z 3.0) -5.340817638704946e-84)
         (not (<= (* z 3.0) 9.199046531699814e+119)))
   (+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y)))
   (fma 0.3333333333333333 (/ (- (/ t y) y) z) x)))
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 tmp;
	if (((z * 3.0) <= -5.340817638704946e-84) || !((z * 3.0) <= 9.199046531699814e+119)) {
		tmp = (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y));
	} else {
		tmp = fma(0.3333333333333333, (((t / y) - y) / z), x);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original3.6
Target1.7
Herbie0.9
\[\left(x - \frac{y}{z \cdot 3}\right) + \frac{\frac{t}{z \cdot 3}}{y} \]

Derivation

  1. Split input into 2 regimes
  2. if (*.f64 z 3) < -5.3408176387049462e-84 or 9.19904653169981393e119 < (*.f64 z 3)

    1. Initial program 0.6

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

    if -5.3408176387049462e-84 < (*.f64 z 3) < 9.19904653169981393e119

    1. Initial program 8.4

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{-0.3333333333333333 \cdot \frac{1}{z}}, y - \frac{t}{y}, x\right) \]
    4. Taylor expanded in z around 0 8.6

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.3333333333333333, \frac{\frac{t}{y} - y}{z}, x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot 3 \leq -5.340817638704946 \cdot 10^{-84} \lor \neg \left(z \cdot 3 \leq 9.199046531699814 \cdot 10^{+119}\right):\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.3333333333333333, \frac{\frac{t}{y} - y}{z}, x\right)\\ \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))))