Average Error: 3.8 → 0.5
Time: 5.8s
Precision: binary64
\[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
\[\begin{array}{l} t_1 := \left(0.3333333333333333 \cdot \frac{t}{y \cdot z} + x\right) - 0.3333333333333333 \cdot \frac{y}{z}\\ \mathbf{if}\;t \leq -4.1631542270516714 \cdot 10^{-67}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.533233474346769 \cdot 10^{-23}:\\ \;\;\;\;\mathsf{fma}\left({\left(\frac{z}{-0.3333333333333333}\right)}^{-1}, \mathsf{fma}\left(t, \frac{-1}{y}, y\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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
         (-
          (+ (* 0.3333333333333333 (/ t (* y z))) x)
          (* 0.3333333333333333 (/ y z)))))
   (if (<= t -4.1631542270516714e-67)
     t_1
     (if (<= t 1.533233474346769e-23)
       (fma (pow (/ z -0.3333333333333333) -1.0) (fma t (/ -1.0 y) y) x)
       t_1))))
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 = ((0.3333333333333333 * (t / (y * z))) + x) - (0.3333333333333333 * (y / z));
	double tmp;
	if (t <= -4.1631542270516714e-67) {
		tmp = t_1;
	} else if (t <= 1.533233474346769e-23) {
		tmp = fma(pow((z / -0.3333333333333333), -1.0), fma(t, (-1.0 / y), y), x);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(t / Float64(Float64(z * 3.0) * y)))
end
function code(x, y, z, t)
	t_1 = Float64(Float64(Float64(0.3333333333333333 * Float64(t / Float64(y * z))) + x) - Float64(0.3333333333333333 * Float64(y / z)))
	tmp = 0.0
	if (t <= -4.1631542270516714e-67)
		tmp = t_1;
	elseif (t <= 1.533233474346769e-23)
		tmp = fma((Float64(z / -0.3333333333333333) ^ -1.0), fma(t, Float64(-1.0 / y), y), x);
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(0.3333333333333333 * N[(t / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] - N[(0.3333333333333333 * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t, -4.1631542270516714e-67], t$95$1, If[LessEqual[t, 1.533233474346769e-23], N[(N[Power[N[(z / -0.3333333333333333), $MachinePrecision], -1.0], $MachinePrecision] * N[(t * N[(-1.0 / y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\begin{array}{l}
t_1 := \left(0.3333333333333333 \cdot \frac{t}{y \cdot z} + x\right) - 0.3333333333333333 \cdot \frac{y}{z}\\
\mathbf{if}\;t \leq -4.1631542270516714 \cdot 10^{-67}:\\
\;\;\;\;t_1\\

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

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

Derivation

  1. Split input into 2 regimes
  2. if t < -4.1631542270516714e-67 or 1.53323347434676888e-23 < t

    1. Initial program 0.7

      \[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
    2. Simplified7.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.7

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

    if -4.1631542270516714e-67 < t < 1.53323347434676888e-23

    1. Initial program 6.9

      \[\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 egg-rr0.2

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

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

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

Reproduce

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