Average Error: 3.2 → 0.5
Time: 8.0s
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}\\ t_2 := t_1 + \frac{t}{y \cdot \left(z \cdot 3\right)}\\ \mathbf{if}\;t_2 \leq -1.2799624956574264 \cdot 10^{+294}:\\ \;\;\;\;t_1 + \frac{\frac{t}{z \cdot 3}}{y}\\ \mathbf{elif}\;t_2 \leq 1.5367392502597684 \cdot 10^{+308}:\\ \;\;\;\;t_1 + \frac{t}{3 \cdot \left(y \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{-0.3333333333333333}{z}, y - \frac{t}{y}, x\right)\\ \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}\\
t_2 := t_1 + \frac{t}{y \cdot \left(z \cdot 3\right)}\\
\mathbf{if}\;t_2 \leq -1.2799624956574264 \cdot 10^{+294}:\\
\;\;\;\;t_1 + \frac{\frac{t}{z \cdot 3}}{y}\\

\mathbf{elif}\;t_2 \leq 1.5367392502597684 \cdot 10^{+308}:\\
\;\;\;\;t_1 + \frac{t}{3 \cdot \left(y \cdot z\right)}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-0.3333333333333333}{z}, y - \frac{t}{y}, 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
 (let* ((t_1 (- x (/ y (* z 3.0)))) (t_2 (+ t_1 (/ t (* y (* z 3.0))))))
   (if (<= t_2 -1.2799624956574264e+294)
     (+ t_1 (/ (/ t (* z 3.0)) y))
     (if (<= t_2 1.5367392502597684e+308)
       (+ t_1 (/ t (* 3.0 (* y z))))
       (fma (/ -0.3333333333333333 z) (- y (/ t y)) 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 t_1 = x - (y / (z * 3.0));
	double t_2 = t_1 + (t / (y * (z * 3.0)));
	double tmp;
	if (t_2 <= -1.2799624956574264e+294) {
		tmp = t_1 + ((t / (z * 3.0)) / y);
	} else if (t_2 <= 1.5367392502597684e+308) {
		tmp = t_1 + (t / (3.0 * (y * z)));
	} else {
		tmp = fma((-0.3333333333333333 / z), (y - (t / y)), x);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original3.2
Target1.7
Herbie0.5
\[\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 (-.f64 x (/.f64 y (*.f64 z 3))) (/.f64 t (*.f64 (*.f64 z 3) y))) < -1.2799624956574264e294

    1. Initial program 34.0

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

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

    if -1.2799624956574264e294 < (+.f64 (-.f64 x (/.f64 y (*.f64 z 3))) (/.f64 t (*.f64 (*.f64 z 3) y))) < 1.5367392502597684e308

    1. Initial program 0.5

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

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

    if 1.5367392502597684e308 < (+.f64 (-.f64 x (/.f64 y (*.f64 z 3))) (/.f64 t (*.f64 (*.f64 z 3) y)))

    1. Initial program 62.9

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

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

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

Reproduce

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