| Alternative 1 | |
|---|---|
| Error | 3.0 |
| Cost | 1616 |
(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))))
(if (<= z -3.1e+118)
t_1
(if (<= z -2e-118)
(- x (/ (/ y (- (* y t) (* z (+ z z)))) (/ -0.5 z)))
(if (<= z 4.4e-254)
(- x (* -2.0 (/ z t)))
(if (<= z 2e+71)
(- x (* y (/ (* z -2.0) (- (* y t) (* 2.0 (* z z))))))
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 tmp;
if (z <= -3.1e+118) {
tmp = t_1;
} else if (z <= -2e-118) {
tmp = x - ((y / ((y * t) - (z * (z + z)))) / (-0.5 / z));
} else if (z <= 4.4e-254) {
tmp = x - (-2.0 * (z / t));
} else if (z <= 2e+71) {
tmp = x - (y * ((z * -2.0) / ((y * t) - (2.0 * (z * z)))));
} 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) :: tmp
t_1 = x - (y / z)
if (z <= (-3.1d+118)) then
tmp = t_1
else if (z <= (-2d-118)) then
tmp = x - ((y / ((y * t) - (z * (z + z)))) / ((-0.5d0) / z))
else if (z <= 4.4d-254) then
tmp = x - ((-2.0d0) * (z / t))
else if (z <= 2d+71) then
tmp = x - (y * ((z * (-2.0d0)) / ((y * t) - (2.0d0 * (z * z)))))
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 tmp;
if (z <= -3.1e+118) {
tmp = t_1;
} else if (z <= -2e-118) {
tmp = x - ((y / ((y * t) - (z * (z + z)))) / (-0.5 / z));
} else if (z <= 4.4e-254) {
tmp = x - (-2.0 * (z / t));
} else if (z <= 2e+71) {
tmp = x - (y * ((z * -2.0) / ((y * t) - (2.0 * (z * z)))));
} 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) tmp = 0 if z <= -3.1e+118: tmp = t_1 elif z <= -2e-118: tmp = x - ((y / ((y * t) - (z * (z + z)))) / (-0.5 / z)) elif z <= 4.4e-254: tmp = x - (-2.0 * (z / t)) elif z <= 2e+71: tmp = x - (y * ((z * -2.0) / ((y * t) - (2.0 * (z * z))))) 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)) tmp = 0.0 if (z <= -3.1e+118) tmp = t_1; elseif (z <= -2e-118) tmp = Float64(x - Float64(Float64(y / Float64(Float64(y * t) - Float64(z * Float64(z + z)))) / Float64(-0.5 / z))); elseif (z <= 4.4e-254) tmp = Float64(x - Float64(-2.0 * Float64(z / t))); elseif (z <= 2e+71) tmp = Float64(x - Float64(y * Float64(Float64(z * -2.0) / Float64(Float64(y * t) - Float64(2.0 * Float64(z * z)))))); 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); tmp = 0.0; if (z <= -3.1e+118) tmp = t_1; elseif (z <= -2e-118) tmp = x - ((y / ((y * t) - (z * (z + z)))) / (-0.5 / z)); elseif (z <= 4.4e-254) tmp = x - (-2.0 * (z / t)); elseif (z <= 2e+71) tmp = x - (y * ((z * -2.0) / ((y * t) - (2.0 * (z * z))))); 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]}, If[LessEqual[z, -3.1e+118], t$95$1, If[LessEqual[z, -2e-118], N[(x - N[(N[(y / N[(N[(y * t), $MachinePrecision] - N[(z * N[(z + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-0.5 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 4.4e-254], N[(x - N[(-2.0 * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2e+71], N[(x - N[(y * N[(N[(z * -2.0), $MachinePrecision] / N[(N[(y * t), $MachinePrecision] - N[(2.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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}\\
\mathbf{if}\;z \leq -3.1 \cdot 10^{+118}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -2 \cdot 10^{-118}:\\
\;\;\;\;x - \frac{\frac{y}{y \cdot t - z \cdot \left(z + z\right)}}{\frac{-0.5}{z}}\\
\mathbf{elif}\;z \leq 4.4 \cdot 10^{-254}:\\
\;\;\;\;x - -2 \cdot \frac{z}{t}\\
\mathbf{elif}\;z \leq 2 \cdot 10^{+71}:\\
\;\;\;\;x - y \cdot \frac{z \cdot -2}{y \cdot t - 2 \cdot \left(z \cdot z\right)}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Results
| Original | 11.4 |
|---|---|
| Target | 0.1 |
| Herbie | 3.0 |
if z < -3.09999999999999986e118 or 2.0000000000000001e71 < z Initial program 22.5
Simplified11.4
[Start]22.5 | \[ x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
|---|---|
rational.json-simplify-50 [=>]22.5 | \[ x - \color{blue}{\frac{-\left(y \cdot 2\right) \cdot z}{y \cdot t - \left(z \cdot 2\right) \cdot z}}
\] |
rational.json-simplify-10 [=>]22.5 | \[ x - \frac{\color{blue}{\frac{\left(y \cdot 2\right) \cdot z}{-1}}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
rational.json-simplify-47 [=>]22.5 | \[ x - \color{blue}{\frac{\left(y \cdot 2\right) \cdot z}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}}
\] |
rational.json-simplify-2 [=>]22.5 | \[ x - \frac{\color{blue}{z \cdot \left(y \cdot 2\right)}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-43 [=>]22.6 | \[ x - \frac{\color{blue}{y \cdot \left(2 \cdot z\right)}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-2 [<=]22.6 | \[ x - \frac{y \cdot \color{blue}{\left(z \cdot 2\right)}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-2 [=>]22.6 | \[ x - \frac{\color{blue}{\left(z \cdot 2\right) \cdot y}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-49 [=>]11.4 | \[ x - \color{blue}{y \cdot \frac{z \cdot 2}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}}
\] |
rational.json-simplify-46 [=>]11.4 | \[ x - y \cdot \color{blue}{\frac{\frac{z \cdot 2}{-1}}{y \cdot t - \left(z \cdot 2\right) \cdot z}}
\] |
rational.json-simplify-2 [=>]11.4 | \[ x - y \cdot \frac{\frac{\color{blue}{2 \cdot z}}{-1}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
rational.json-simplify-49 [=>]11.4 | \[ x - y \cdot \frac{\color{blue}{z \cdot \frac{2}{-1}}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
metadata-eval [=>]11.4 | \[ x - y \cdot \frac{z \cdot \color{blue}{-2}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
rational.json-simplify-2 [=>]11.4 | \[ x - y \cdot \frac{z \cdot -2}{y \cdot t - \color{blue}{z \cdot \left(z \cdot 2\right)}}
\] |
rational.json-simplify-43 [<=]11.4 | \[ x - y \cdot \frac{z \cdot -2}{y \cdot t - \color{blue}{2 \cdot \left(z \cdot z\right)}}
\] |
Taylor expanded in y around 0 3.4
if -3.09999999999999986e118 < z < -1.99999999999999997e-118Initial program 4.2
Simplified1.8
[Start]4.2 | \[ x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
|---|---|
rational.json-simplify-50 [=>]4.2 | \[ x - \color{blue}{\frac{-\left(y \cdot 2\right) \cdot z}{y \cdot t - \left(z \cdot 2\right) \cdot z}}
\] |
rational.json-simplify-10 [=>]4.2 | \[ x - \frac{\color{blue}{\frac{\left(y \cdot 2\right) \cdot z}{-1}}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
rational.json-simplify-47 [=>]4.2 | \[ x - \color{blue}{\frac{\left(y \cdot 2\right) \cdot z}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}}
\] |
rational.json-simplify-2 [=>]4.2 | \[ x - \frac{\color{blue}{z \cdot \left(y \cdot 2\right)}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-43 [=>]4.2 | \[ x - \frac{\color{blue}{y \cdot \left(2 \cdot z\right)}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-2 [<=]4.2 | \[ x - \frac{y \cdot \color{blue}{\left(z \cdot 2\right)}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-2 [=>]4.2 | \[ x - \frac{\color{blue}{\left(z \cdot 2\right) \cdot y}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-49 [=>]1.8 | \[ x - \color{blue}{y \cdot \frac{z \cdot 2}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}}
\] |
rational.json-simplify-46 [=>]1.8 | \[ x - y \cdot \color{blue}{\frac{\frac{z \cdot 2}{-1}}{y \cdot t - \left(z \cdot 2\right) \cdot z}}
\] |
rational.json-simplify-2 [=>]1.8 | \[ x - y \cdot \frac{\frac{\color{blue}{2 \cdot z}}{-1}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
rational.json-simplify-49 [=>]1.8 | \[ x - y \cdot \frac{\color{blue}{z \cdot \frac{2}{-1}}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
metadata-eval [=>]1.8 | \[ x - y \cdot \frac{z \cdot \color{blue}{-2}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
rational.json-simplify-2 [=>]1.8 | \[ x - y \cdot \frac{z \cdot -2}{y \cdot t - \color{blue}{z \cdot \left(z \cdot 2\right)}}
\] |
rational.json-simplify-43 [<=]1.8 | \[ x - y \cdot \frac{z \cdot -2}{y \cdot t - \color{blue}{2 \cdot \left(z \cdot z\right)}}
\] |
Applied egg-rr1.7
if -1.99999999999999997e-118 < z < 4.4000000000000002e-254Initial program 7.8
Simplified7.5
[Start]7.8 | \[ x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
|---|---|
rational.json-simplify-50 [=>]7.8 | \[ x - \color{blue}{\frac{-\left(y \cdot 2\right) \cdot z}{y \cdot t - \left(z \cdot 2\right) \cdot z}}
\] |
rational.json-simplify-10 [=>]7.8 | \[ x - \frac{\color{blue}{\frac{\left(y \cdot 2\right) \cdot z}{-1}}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
rational.json-simplify-47 [=>]7.8 | \[ x - \color{blue}{\frac{\left(y \cdot 2\right) \cdot z}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}}
\] |
rational.json-simplify-2 [=>]7.8 | \[ x - \frac{\color{blue}{z \cdot \left(y \cdot 2\right)}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-43 [=>]7.8 | \[ x - \frac{\color{blue}{y \cdot \left(2 \cdot z\right)}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-2 [<=]7.8 | \[ x - \frac{y \cdot \color{blue}{\left(z \cdot 2\right)}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-2 [=>]7.8 | \[ x - \frac{\color{blue}{\left(z \cdot 2\right) \cdot y}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-49 [=>]7.5 | \[ x - \color{blue}{y \cdot \frac{z \cdot 2}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}}
\] |
rational.json-simplify-46 [=>]7.5 | \[ x - y \cdot \color{blue}{\frac{\frac{z \cdot 2}{-1}}{y \cdot t - \left(z \cdot 2\right) \cdot z}}
\] |
rational.json-simplify-2 [=>]7.5 | \[ x - y \cdot \frac{\frac{\color{blue}{2 \cdot z}}{-1}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
rational.json-simplify-49 [=>]7.5 | \[ x - y \cdot \frac{\color{blue}{z \cdot \frac{2}{-1}}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
metadata-eval [=>]7.5 | \[ x - y \cdot \frac{z \cdot \color{blue}{-2}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
rational.json-simplify-2 [=>]7.5 | \[ x - y \cdot \frac{z \cdot -2}{y \cdot t - \color{blue}{z \cdot \left(z \cdot 2\right)}}
\] |
rational.json-simplify-43 [<=]7.5 | \[ x - y \cdot \frac{z \cdot -2}{y \cdot t - \color{blue}{2 \cdot \left(z \cdot z\right)}}
\] |
Taylor expanded in y around inf 1.9
if 4.4000000000000002e-254 < z < 2.0000000000000001e71Initial program 5.0
Simplified4.1
[Start]5.0 | \[ x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
|---|---|
rational.json-simplify-50 [=>]5.0 | \[ x - \color{blue}{\frac{-\left(y \cdot 2\right) \cdot z}{y \cdot t - \left(z \cdot 2\right) \cdot z}}
\] |
rational.json-simplify-10 [=>]5.0 | \[ x - \frac{\color{blue}{\frac{\left(y \cdot 2\right) \cdot z}{-1}}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
rational.json-simplify-47 [=>]5.0 | \[ x - \color{blue}{\frac{\left(y \cdot 2\right) \cdot z}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}}
\] |
rational.json-simplify-2 [=>]5.0 | \[ x - \frac{\color{blue}{z \cdot \left(y \cdot 2\right)}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-43 [=>]5.0 | \[ x - \frac{\color{blue}{y \cdot \left(2 \cdot z\right)}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-2 [<=]5.0 | \[ x - \frac{y \cdot \color{blue}{\left(z \cdot 2\right)}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-2 [=>]5.0 | \[ x - \frac{\color{blue}{\left(z \cdot 2\right) \cdot y}}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}
\] |
rational.json-simplify-49 [=>]4.1 | \[ x - \color{blue}{y \cdot \frac{z \cdot 2}{-1 \cdot \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}}
\] |
rational.json-simplify-46 [=>]4.1 | \[ x - y \cdot \color{blue}{\frac{\frac{z \cdot 2}{-1}}{y \cdot t - \left(z \cdot 2\right) \cdot z}}
\] |
rational.json-simplify-2 [=>]4.1 | \[ x - y \cdot \frac{\frac{\color{blue}{2 \cdot z}}{-1}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
rational.json-simplify-49 [=>]4.1 | \[ x - y \cdot \frac{\color{blue}{z \cdot \frac{2}{-1}}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
metadata-eval [=>]4.1 | \[ x - y \cdot \frac{z \cdot \color{blue}{-2}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
rational.json-simplify-2 [=>]4.1 | \[ x - y \cdot \frac{z \cdot -2}{y \cdot t - \color{blue}{z \cdot \left(z \cdot 2\right)}}
\] |
rational.json-simplify-43 [<=]4.1 | \[ x - y \cdot \frac{z \cdot -2}{y \cdot t - \color{blue}{2 \cdot \left(z \cdot z\right)}}
\] |
Final simplification3.0
| Alternative 1 | |
|---|---|
| Error | 3.0 |
| Cost | 1616 |
| Alternative 2 | |
|---|---|
| Error | 2.9 |
| Cost | 1616 |
| Alternative 3 | |
|---|---|
| Error | 7.3 |
| Cost | 712 |
| Alternative 4 | |
|---|---|
| Error | 11.3 |
| Cost | 584 |
| Alternative 5 | |
|---|---|
| Error | 15.4 |
| Cost | 520 |
| Alternative 6 | |
|---|---|
| Error | 15.5 |
| Cost | 64 |
herbie shell --seed 2023064
(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)))))