Average Error: 3.5 → 0.5
Time: 6.1s
Precision: binary64
\[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
\[\begin{array}{l} \mathbf{if}\;t \leq -479840.16688788246:\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{y \cdot \left(z \cdot 3\right)}\\ \mathbf{elif}\;t \leq 1.4877270337603418 \cdot 10^{+50}:\\ \;\;\;\;\mathsf{fma}\left(\frac{-0.3333333333333333}{z}, y + t \cdot \frac{-1}{y}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + 0.3333333333333333 \cdot \frac{t}{y \cdot z}\right) - 0.3333333333333333 \cdot \frac{y}{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}\;t \leq -479840.16688788246:\\
\;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{y \cdot \left(z \cdot 3\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\left(x + 0.3333333333333333 \cdot \frac{t}{y \cdot z}\right) - 0.3333333333333333 \cdot \frac{y}{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 (<= t -479840.16688788246)
   (+ (- x (/ y (* z 3.0))) (/ t (* y (* z 3.0))))
   (if (<= t 1.4877270337603418e+50)
     (fma (/ -0.3333333333333333 z) (+ y (* t (/ -1.0 y))) x)
     (-
      (+ x (* 0.3333333333333333 (/ t (* y z))))
      (* 0.3333333333333333 (/ 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 (t <= -479840.16688788246) {
		tmp = (x - (y / (z * 3.0))) + (t / (y * (z * 3.0)));
	} else if (t <= 1.4877270337603418e+50) {
		tmp = fma((-0.3333333333333333 / z), (y + (t * (-1.0 / y))), x);
	} else {
		tmp = (x + (0.3333333333333333 * (t / (y * z)))) - (0.3333333333333333 * (y / z));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original3.5
Target1.6
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 t < -479840.166887882457

    1. Initial program 0.7

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

    if -479840.166887882457 < t < 1.4877270337603418e50

    1. Initial program 5.2

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

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

      \[\leadsto \mathsf{fma}\left(\frac{-0.3333333333333333}{z}, y - \color{blue}{t \cdot \frac{1}{y}}, x\right) \]
    4. Applied cancel-sign-sub-inv_binary640.4

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

    if 1.4877270337603418e50 < t

    1. Initial program 0.7

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

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

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

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

Reproduce

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