Average Error: 3.6 → 2.3
Time: 12.0s
Precision: binary64
\[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{y \cdot \left(z \cdot 3\right)} \leq -2.0587203320363797 \cdot 10^{+298}:\\ \;\;\;\;x + -0.3333333333333333 \cdot \frac{y - \frac{t}{y}}{z}\\ \mathbf{elif}\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{y \cdot \left(z \cdot 3\right)} \leq -5.274546549140728 \cdot 10^{-10}:\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{y \cdot \left(z \cdot 3\right)}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{-0.3333333333333333 \cdot \left(y + t \cdot \frac{-1}{y}\right)}{z}\\ \end{array}\]
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{y \cdot \left(z \cdot 3\right)} \leq -2.0587203320363797 \cdot 10^{+298}:\\
\;\;\;\;x + -0.3333333333333333 \cdot \frac{y - \frac{t}{y}}{z}\\

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

\mathbf{else}:\\
\;\;\;\;x + \frac{-0.3333333333333333 \cdot \left(y + t \cdot \frac{-1}{y}\right)}{z}\\

\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 (<=
      (+ (- x (/ y (* z 3.0))) (/ t (* y (* z 3.0))))
      -2.0587203320363797e+298)
   (+ x (* -0.3333333333333333 (/ (- y (/ t y)) z)))
   (if (<=
        (+ (- x (/ y (* z 3.0))) (/ t (* y (* z 3.0))))
        -5.274546549140728e-10)
     (+ (- x (/ y (* z 3.0))) (/ t (* y (* z 3.0))))
     (+ x (/ (* -0.3333333333333333 (+ y (* t (/ -1.0 y)))) z)))))
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 (((x - (y / (z * 3.0))) + (t / (y * (z * 3.0)))) <= -2.0587203320363797e+298) {
		tmp = x + (-0.3333333333333333 * ((y - (t / y)) / z));
	} else if (((x - (y / (z * 3.0))) + (t / (y * (z * 3.0)))) <= -5.274546549140728e-10) {
		tmp = (x - (y / (z * 3.0))) + (t / (y * (z * 3.0)));
	} else {
		tmp = x + ((-0.3333333333333333 * (y + (t * (-1.0 / y)))) / z);
	}
	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

Original3.6
Target1.7
Herbie2.3
\[\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))) < -2.05872033203637967e298

    1. Initial program 37.8

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

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

      \[\leadsto x + \color{blue}{-0.3333333333333333 \cdot \frac{y - \frac{t}{y}}{z}}\]

    if -2.05872033203637967e298 < (+.f64 (-.f64 x (/.f64 y (*.f64 z 3))) (/.f64 t (*.f64 (*.f64 z 3) y))) < -5.27454654914072818e-10

    1. Initial program 0.4

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

    if -5.27454654914072818e-10 < (+.f64 (-.f64 x (/.f64 y (*.f64 z 3))) (/.f64 t (*.f64 (*.f64 z 3) y)))

    1. Initial program 3.1

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

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

      \[\leadsto x + \color{blue}{\frac{0.3333333333333333 \cdot \frac{t}{y} - 0.3333333333333333 \cdot y}{z}}\]
    4. Simplified3.6

      \[\leadsto x + \color{blue}{-0.3333333333333333 \cdot \frac{y - \frac{t}{y}}{z}}\]
    5. Using strategy rm
    6. Applied associate-*r/_binary64_184343.5

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

      \[\leadsto x + \frac{\color{blue}{\left(y - \frac{t}{y}\right) \cdot -0.3333333333333333}}{z}\]
    8. Using strategy rm
    9. Applied div-inv_binary64_184893.5

      \[\leadsto x + \frac{\left(y - \color{blue}{t \cdot \frac{1}{y}}\right) \cdot -0.3333333333333333}{z}\]
    10. Applied cancel-sign-sub-inv_binary64_184583.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{y \cdot \left(z \cdot 3\right)} \leq -2.0587203320363797 \cdot 10^{+298}:\\ \;\;\;\;x + -0.3333333333333333 \cdot \frac{y - \frac{t}{y}}{z}\\ \mathbf{elif}\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{y \cdot \left(z \cdot 3\right)} \leq -5.274546549140728 \cdot 10^{-10}:\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{y \cdot \left(z \cdot 3\right)}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{-0.3333333333333333 \cdot \left(y + t \cdot \frac{-1}{y}\right)}{z}\\ \end{array}\]

Reproduce

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