Average Error: 3.9 → 0.8
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 := \frac{\frac{-1}{y}}{z}\\ \mathbf{if}\;t \leq -1 \cdot 10^{+102}:\\ \;\;\;\;-0.3333333333333333 \cdot \left(\mathsf{fma}\left(1, \frac{y}{z}, t \cdot t_1\right) + \mathsf{fma}\left(t_1, t, t \cdot \frac{\frac{1}{y}}{z}\right)\right) + x\\ \mathbf{elif}\;t \leq 1.0796416003667889 \cdot 10^{-97}:\\ \;\;\;\;x + {\left(-3 \cdot \frac{z}{y - \frac{t}{y}}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{y \cdot \left(z \cdot 3\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 (/ (/ -1.0 y) z)))
   (if (<= t -1e+102)
     (+
      (*
       -0.3333333333333333
       (+ (fma 1.0 (/ y z) (* t t_1)) (fma t_1 t (* t (/ (/ 1.0 y) z)))))
      x)
     (if (<= t 1.0796416003667889e-97)
       (+ x (pow (* -3.0 (/ z (- y (/ t y)))) -1.0))
       (+ (- x (/ y (* z 3.0))) (/ t (* y (* z 3.0))))))))
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 = (-1.0 / y) / z;
	double tmp;
	if (t <= -1e+102) {
		tmp = (-0.3333333333333333 * (fma(1.0, (y / z), (t * t_1)) + fma(t_1, t, (t * ((1.0 / y) / z))))) + x;
	} else if (t <= 1.0796416003667889e-97) {
		tmp = x + pow((-3.0 * (z / (y - (t / y)))), -1.0);
	} else {
		tmp = (x - (y / (z * 3.0))) + (t / (y * (z * 3.0)));
	}
	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(-1.0 / y) / z)
	tmp = 0.0
	if (t <= -1e+102)
		tmp = Float64(Float64(-0.3333333333333333 * Float64(fma(1.0, Float64(y / z), Float64(t * t_1)) + fma(t_1, t, Float64(t * Float64(Float64(1.0 / y) / z))))) + x);
	elseif (t <= 1.0796416003667889e-97)
		tmp = Float64(x + (Float64(-3.0 * Float64(z / Float64(y - Float64(t / y)))) ^ -1.0));
	else
		tmp = Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(t / Float64(y * Float64(z * 3.0))));
	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[(-1.0 / y), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t, -1e+102], N[(N[(-0.3333333333333333 * N[(N[(1.0 * N[(y / z), $MachinePrecision] + N[(t * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * t + N[(t * N[(N[(1.0 / y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t, 1.0796416003667889e-97], N[(x + N[Power[N[(-3.0 * N[(z / N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t / N[(y * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\begin{array}{l}
t_1 := \frac{\frac{-1}{y}}{z}\\
\mathbf{if}\;t \leq -1 \cdot 10^{+102}:\\
\;\;\;\;-0.3333333333333333 \cdot \left(\mathsf{fma}\left(1, \frac{y}{z}, t \cdot t_1\right) + \mathsf{fma}\left(t_1, t, t \cdot \frac{\frac{1}{y}}{z}\right)\right) + x\\

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

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


\end{array}

Error

Target

Original3.9
Target1.8
Herbie0.8
\[\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 < -9.99999999999999977e101

    1. Initial program 0.7

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

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

      \[\leadsto \color{blue}{-0.3333333333333333 \cdot \frac{y - \frac{t}{y}}{z} + x} \]
    4. Applied egg-rr0.7

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

    if -9.99999999999999977e101 < t < 1.0796416003667889e-97

    1. Initial program 6.1

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

      \[\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}{-0.3333333333333333 \cdot \frac{y - \frac{t}{y}}{z} + x} \]
    4. Applied egg-rr0.8

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

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

    if 1.0796416003667889e-97 < t

    1. Initial program 1.0

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

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

Reproduce

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