Average Error: 3.6 → 1.0
Time: 5.1s
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 -4.6790990739954146 \cdot 10^{+292}:\\ \;\;\;\;t_1 + \left(0.3333333333333333 \cdot \frac{t}{z}\right) \cdot \frac{1}{y}\\ \mathbf{elif}\;t_2 \leq 1.1588464228584103 \cdot 10^{+288}:\\ \;\;\;\;t_1 - \frac{t}{y \cdot \left(z \cdot -3\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y - \frac{t}{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
 (let* ((t_1 (- x (/ y (* z 3.0)))) (t_2 (+ t_1 (/ t (* y (* z 3.0))))))
   (if (<= t_2 -4.6790990739954146e+292)
     (+ t_1 (* (* 0.3333333333333333 (/ t z)) (/ 1.0 y)))
     (if (<= t_2 1.1588464228584103e+288)
       (- t_1 (/ t (* y (* z -3.0))))
       (fma -0.3333333333333333 (/ (- y (/ t 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 t_1 = x - (y / (z * 3.0));
	double t_2 = t_1 + (t / (y * (z * 3.0)));
	double tmp;
	if (t_2 <= -4.6790990739954146e+292) {
		tmp = t_1 + ((0.3333333333333333 * (t / z)) * (1.0 / y));
	} else if (t_2 <= 1.1588464228584103e+288) {
		tmp = t_1 - (t / (y * (z * -3.0)));
	} else {
		tmp = fma(-0.3333333333333333, ((y - (t / y)) / z), x);
	}
	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(x - Float64(y / Float64(z * 3.0)))
	t_2 = Float64(t_1 + Float64(t / Float64(y * Float64(z * 3.0))))
	tmp = 0.0
	if (t_2 <= -4.6790990739954146e+292)
		tmp = Float64(t_1 + Float64(Float64(0.3333333333333333 * Float64(t / z)) * Float64(1.0 / y)));
	elseif (t_2 <= 1.1588464228584103e+288)
		tmp = Float64(t_1 - Float64(t / Float64(y * Float64(z * -3.0))));
	else
		tmp = fma(-0.3333333333333333, Float64(Float64(y - Float64(t / y)) / z), x);
	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[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 + N[(t / N[(y * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -4.6790990739954146e+292], N[(t$95$1 + N[(N[(0.3333333333333333 * N[(t / z), $MachinePrecision]), $MachinePrecision] * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1.1588464228584103e+288], N[(t$95$1 - N[(t / N[(y * N[(z * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.3333333333333333 * N[(N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision] + x), $MachinePrecision]]]]]
\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 -4.6790990739954146 \cdot 10^{+292}:\\
\;\;\;\;t_1 + \left(0.3333333333333333 \cdot \frac{t}{z}\right) \cdot \frac{1}{y}\\

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

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original3.6
Target1.8
Herbie1.0
\[\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))) < -4.67909907399541e292

    1. Initial program 32.8

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

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

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

    if -4.67909907399541e292 < (+.f64 (-.f64 x (/.f64 y (*.f64 z 3))) (/.f64 t (*.f64 (*.f64 z 3) y))) < 1.15884642285841031e288

    1. Initial program 0.6

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

      \[\leadsto \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\left(t \cdot \frac{0.3333333333333333}{z}\right) \cdot \frac{1}{y}} \]
    3. Applied egg-rr1.7

      \[\leadsto \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{t}{z \cdot 3}} \cdot \frac{1}{y} \]
    4. Applied egg-rr0.6

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

    if 1.15884642285841031e288 < (+.f64 (-.f64 x (/.f64 y (*.f64 z 3))) (/.f64 t (*.f64 (*.f64 z 3) y)))

    1. Initial program 25.8

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

      \[\leadsto \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\left(t \cdot \frac{0.3333333333333333}{z}\right) \cdot \frac{1}{y}} \]
    3. Applied egg-rr3.3

      \[\leadsto \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{t}{z \cdot 3}} \cdot \frac{1}{y} \]
    4. Applied egg-rr3.3

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

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

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

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

Reproduce

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