?

Average Error: 11.6 → 3.2
Time: 1.0min
Precision: binary64
Cost: 8012

?

\[x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t} \]
\[\begin{array}{l} t_1 := x - \frac{y}{z}\\ t_2 := x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}\\ \mathbf{if}\;z \leq -2.8 \cdot 10^{+90}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{-135}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-207}:\\ \;\;\;\;x - \mathsf{fma}\left(-4, \frac{\left(\frac{z}{t} \cdot \frac{z}{t}\right) \cdot z}{y}, \frac{-2 \cdot z}{t}\right)\\ \mathbf{elif}\;z \leq 6.3 \cdot 10^{+44}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (- x (/ y z)))
        (t_2 (- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t))))))
   (if (<= z -2.8e+90)
     t_1
     (if (<= z -4.5e-135)
       t_2
       (if (<= z 2.5e-207)
         (- x (fma -4.0 (/ (* (* (/ z t) (/ z t)) z) y) (/ (* -2.0 z) t)))
         (if (<= z 6.3e+44) t_2 t_1))))))
double code(double x, double y, double z, double t) {
	return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
double code(double x, double y, double z, double t) {
	double t_1 = x - (y / z);
	double t_2 = x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
	double tmp;
	if (z <= -2.8e+90) {
		tmp = t_1;
	} else if (z <= -4.5e-135) {
		tmp = t_2;
	} else if (z <= 2.5e-207) {
		tmp = x - fma(-4.0, ((((z / t) * (z / t)) * z) / y), ((-2.0 * z) / t));
	} else if (z <= 6.3e+44) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x - Float64(Float64(Float64(y * 2.0) * z) / Float64(Float64(Float64(z * 2.0) * z) - Float64(y * t))))
end
function code(x, y, z, t)
	t_1 = Float64(x - Float64(y / z))
	t_2 = Float64(x - Float64(Float64(Float64(y * 2.0) * z) / Float64(Float64(Float64(z * 2.0) * z) - Float64(y * t))))
	tmp = 0.0
	if (z <= -2.8e+90)
		tmp = t_1;
	elseif (z <= -4.5e-135)
		tmp = t_2;
	elseif (z <= 2.5e-207)
		tmp = Float64(x - fma(-4.0, Float64(Float64(Float64(Float64(z / t) * Float64(z / t)) * z) / y), Float64(Float64(-2.0 * z) / t)));
	elseif (z <= 6.3e+44)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x - N[(N[(N[(y * 2.0), $MachinePrecision] * z), $MachinePrecision] / N[(N[(N[(z * 2.0), $MachinePrecision] * z), $MachinePrecision] - N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x - N[(N[(N[(y * 2.0), $MachinePrecision] * z), $MachinePrecision] / N[(N[(N[(z * 2.0), $MachinePrecision] * z), $MachinePrecision] - N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.8e+90], t$95$1, If[LessEqual[z, -4.5e-135], t$95$2, If[LessEqual[z, 2.5e-207], N[(x - N[(-4.0 * N[(N[(N[(N[(z / t), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision] / y), $MachinePrecision] + N[(N[(-2.0 * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 6.3e+44], t$95$2, t$95$1]]]]]]
x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
t_2 := x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}\\
\mathbf{if}\;z \leq -2.8 \cdot 10^{+90}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq -4.5 \cdot 10^{-135}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;z \leq 2.5 \cdot 10^{-207}:\\
\;\;\;\;x - \mathsf{fma}\left(-4, \frac{\left(\frac{z}{t} \cdot \frac{z}{t}\right) \cdot z}{y}, \frac{-2 \cdot z}{t}\right)\\

\mathbf{elif}\;z \leq 6.3 \cdot 10^{+44}:\\
\;\;\;\;t_2\\

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


\end{array}

Error?

Target

Original11.6
Target0.1
Herbie3.2
\[x - \frac{1}{\frac{z}{y} - \frac{\frac{t}{2}}{z}} \]

Derivation?

  1. Split input into 3 regimes
  2. if z < -2.8e90 or 6.3e44 < z

    1. Initial program 22.0

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

      \[\leadsto \color{blue}{\frac{2 \cdot \left(y \cdot z\right)}{\mathsf{fma}\left(t, y, -2 \cdot {z}^{2}\right)} + x} \]
      Proof
    3. Taylor expanded in z around inf 4.0

      \[\leadsto \color{blue}{-1 \cdot \frac{y}{z} + x} \]
    4. Simplified4.0

      \[\leadsto \color{blue}{x - \frac{y}{z}} \]
      Proof

    if -2.8e90 < z < -4.49999999999999987e-135 or 2.50000000000000007e-207 < z < 6.3e44

    1. Initial program 3.2

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

    if -4.49999999999999987e-135 < z < 2.50000000000000007e-207

    1. Initial program 8.2

      \[x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t} \]
    2. Taylor expanded in t around inf 16.4

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

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

Alternatives

Alternative 1
Error3.1
Cost1616
\[\begin{array}{l} t_1 := x - \frac{y}{z}\\ t_2 := x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}\\ \mathbf{if}\;z \leq -5.2 \cdot 10^{+88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -6.5 \cdot 10^{-135}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-207}:\\ \;\;\;\;x - \frac{-2 \cdot z}{t}\\ \mathbf{elif}\;z \leq 1.22 \cdot 10^{+46}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error6.6
Cost712
\[\begin{array}{l} t_1 := x - \frac{y}{z}\\ \mathbf{if}\;z \leq -1.05 \cdot 10^{-26}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{-12}:\\ \;\;\;\;x - \frac{-2 \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error11.5
Cost584
\[\begin{array}{l} t_1 := x - \frac{y}{z}\\ \mathbf{if}\;z \leq -2.3 \cdot 10^{-30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-22}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error17.7
Cost520
\[\begin{array}{l} \mathbf{if}\;t \leq -2.9 \cdot 10^{-174}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -5.4 \cdot 10^{-255}:\\ \;\;\;\;\frac{-y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error16.2
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023033 
(FPCore (x y z t)
  :name "Numeric.AD.Rank1.Halley:findZero from ad-4.2.4"
  :precision binary64

  :herbie-target
  (- x (/ 1.0 (- (/ z y) (/ (/ t 2.0) z))))

  (- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))