Average Error: 11.4 → 2.8
Time: 21.1s
Precision: binary64
Cost: 1616
\[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 -4.8 \cdot 10^{+102}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1 \cdot 10^{-161}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{-163}:\\ \;\;\;\;x - \frac{-2 \cdot z}{t}\\ \mathbf{elif}\;z \leq 6.6 \cdot 10^{+54}:\\ \;\;\;\;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 -4.8e+102)
     t_1
     (if (<= z -1e-161)
       t_2
       (if (<= z 1.4e-163)
         (- x (/ (* -2.0 z) t))
         (if (<= z 6.6e+54) 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 <= -4.8e+102) {
		tmp = t_1;
	} else if (z <= -1e-161) {
		tmp = t_2;
	} else if (z <= 1.4e-163) {
		tmp = x - ((-2.0 * z) / t);
	} else if (z <= 6.6e+54) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x - (((y * 2.0d0) * z) / (((z * 2.0d0) * z) - (y * t)))
end function
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = x - (y / z)
    t_2 = x - (((y * 2.0d0) * z) / (((z * 2.0d0) * z) - (y * t)))
    if (z <= (-4.8d+102)) then
        tmp = t_1
    else if (z <= (-1d-161)) then
        tmp = t_2
    else if (z <= 1.4d-163) then
        tmp = x - (((-2.0d0) * z) / t)
    else if (z <= 6.6d+54) then
        tmp = t_2
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
public static 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 <= -4.8e+102) {
		tmp = t_1;
	} else if (z <= -1e-161) {
		tmp = t_2;
	} else if (z <= 1.4e-163) {
		tmp = x - ((-2.0 * z) / t);
	} else if (z <= 6.6e+54) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t):
	return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)))
def code(x, y, z, t):
	t_1 = x - (y / z)
	t_2 = x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)))
	tmp = 0
	if z <= -4.8e+102:
		tmp = t_1
	elif z <= -1e-161:
		tmp = t_2
	elif z <= 1.4e-163:
		tmp = x - ((-2.0 * z) / t)
	elif z <= 6.6e+54:
		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 <= -4.8e+102)
		tmp = t_1;
	elseif (z <= -1e-161)
		tmp = t_2;
	elseif (z <= 1.4e-163)
		tmp = Float64(x - Float64(Float64(-2.0 * z) / t));
	elseif (z <= 6.6e+54)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
end
function tmp_2 = code(x, y, z, t)
	t_1 = x - (y / z);
	t_2 = x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
	tmp = 0.0;
	if (z <= -4.8e+102)
		tmp = t_1;
	elseif (z <= -1e-161)
		tmp = t_2;
	elseif (z <= 1.4e-163)
		tmp = x - ((-2.0 * z) / t);
	elseif (z <= 6.6e+54)
		tmp = t_2;
	else
		tmp = t_1;
	end
	tmp_2 = 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, -4.8e+102], t$95$1, If[LessEqual[z, -1e-161], t$95$2, If[LessEqual[z, 1.4e-163], N[(x - N[(N[(-2.0 * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 6.6e+54], 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 -4.8 \cdot 10^{+102}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq -1 \cdot 10^{-161}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;z \leq 1.4 \cdot 10^{-163}:\\
\;\;\;\;x - \frac{-2 \cdot z}{t}\\

\mathbf{elif}\;z \leq 6.6 \cdot 10^{+54}:\\
\;\;\;\;t_2\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original11.4
Target0.1
Herbie2.8
\[x - \frac{1}{\frac{z}{y} - \frac{\frac{t}{2}}{z}} \]

Derivation

  1. Split input into 3 regimes
  2. if z < -4.79999999999999989e102 or 6.6e54 < z

    1. Initial program 21.8

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

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

    if -4.79999999999999989e102 < z < -1.00000000000000003e-161 or 1.4e-163 < z < 6.6e54

    1. Initial program 2.6

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

    if -1.00000000000000003e-161 < z < 1.4e-163

    1. Initial program 9.2

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

      \[\leadsto x - \color{blue}{-2 \cdot \frac{z}{t}} \]
    3. Simplified1.4

      \[\leadsto x - \color{blue}{\frac{-2 \cdot z}{t}} \]
      Proof
  3. Recombined 3 regimes into one program.

Alternatives

Alternative 1
Error16.2
Cost1048
\[\begin{array}{l} t_1 := -\frac{y}{z}\\ \mathbf{if}\;x \leq -1.22 \cdot 10^{-119}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -9.2 \cdot 10^{-168}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{-244}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-284}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{-229}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-206}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error7.1
Cost712
\[\begin{array}{l} t_1 := x - \frac{y}{z}\\ \mathbf{if}\;z \leq -1.22 \cdot 10^{-51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+47}:\\ \;\;\;\;x - \frac{-2 \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error12.0
Cost584
\[\begin{array}{l} t_1 := x - \frac{y}{z}\\ \mathbf{if}\;z \leq -4.8 \cdot 10^{-53}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{-111}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error15.3
Cost64
\[x \]

Error

Reproduce

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