| Alternative 1 | |
|---|---|
| Error | 1.9 |
| 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)))
(t_2 (- x (* z (/ (* y 2.0) (- (* z (* 2.0 z)) (* y t)))))))
(if (<= z -9e+162)
t_1
(if (<= z -4.3e-134)
t_2
(if (<= z 2e-187)
(- x (* -2.0 (/ z t)))
(if (<= z 1.25e+147) 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 - (z * ((y * 2.0) / ((z * (2.0 * z)) - (y * t))));
double tmp;
if (z <= -9e+162) {
tmp = t_1;
} else if (z <= -4.3e-134) {
tmp = t_2;
} else if (z <= 2e-187) {
tmp = x - (-2.0 * (z / t));
} else if (z <= 1.25e+147) {
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 - (z * ((y * 2.0d0) / ((z * (2.0d0 * z)) - (y * t))))
if (z <= (-9d+162)) then
tmp = t_1
else if (z <= (-4.3d-134)) then
tmp = t_2
else if (z <= 2d-187) then
tmp = x - ((-2.0d0) * (z / t))
else if (z <= 1.25d+147) 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 - (z * ((y * 2.0) / ((z * (2.0 * z)) - (y * t))));
double tmp;
if (z <= -9e+162) {
tmp = t_1;
} else if (z <= -4.3e-134) {
tmp = t_2;
} else if (z <= 2e-187) {
tmp = x - (-2.0 * (z / t));
} else if (z <= 1.25e+147) {
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 - (z * ((y * 2.0) / ((z * (2.0 * z)) - (y * t)))) tmp = 0 if z <= -9e+162: tmp = t_1 elif z <= -4.3e-134: tmp = t_2 elif z <= 2e-187: tmp = x - (-2.0 * (z / t)) elif z <= 1.25e+147: 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(z * Float64(Float64(y * 2.0) / Float64(Float64(z * Float64(2.0 * z)) - Float64(y * t))))) tmp = 0.0 if (z <= -9e+162) tmp = t_1; elseif (z <= -4.3e-134) tmp = t_2; elseif (z <= 2e-187) tmp = Float64(x - Float64(-2.0 * Float64(z / t))); elseif (z <= 1.25e+147) 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 - (z * ((y * 2.0) / ((z * (2.0 * z)) - (y * t)))); tmp = 0.0; if (z <= -9e+162) tmp = t_1; elseif (z <= -4.3e-134) tmp = t_2; elseif (z <= 2e-187) tmp = x - (-2.0 * (z / t)); elseif (z <= 1.25e+147) 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[(z * N[(N[(y * 2.0), $MachinePrecision] / N[(N[(z * N[(2.0 * z), $MachinePrecision]), $MachinePrecision] - N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -9e+162], t$95$1, If[LessEqual[z, -4.3e-134], t$95$2, If[LessEqual[z, 2e-187], N[(x - N[(-2.0 * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.25e+147], 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 - z \cdot \frac{y \cdot 2}{z \cdot \left(2 \cdot z\right) - y \cdot t}\\
\mathbf{if}\;z \leq -9 \cdot 10^{+162}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -4.3 \cdot 10^{-134}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-187}:\\
\;\;\;\;x - -2 \cdot \frac{z}{t}\\
\mathbf{elif}\;z \leq 1.25 \cdot 10^{+147}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Results
| Original | 11.8 |
|---|---|
| Target | 0.1 |
| Herbie | 1.8 |
if z < -8.99999999999999944e162 or 1.2500000000000001e147 < z Initial program 27.2
Simplified14.7
[Start]27.2 | \[ x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
|---|---|
rational.json-simplify-49 [=>]14.8 | \[ x - \color{blue}{z \cdot \frac{y \cdot 2}{\left(z \cdot 2\right) \cdot z - y \cdot t}}
\] |
rational.json-simplify-2 [=>]14.8 | \[ x - z \cdot \frac{\color{blue}{2 \cdot y}}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
rational.json-simplify-49 [=>]14.8 | \[ x - z \cdot \color{blue}{\left(y \cdot \frac{2}{\left(z \cdot 2\right) \cdot z - y \cdot t}\right)}
\] |
rational.json-simplify-43 [=>]14.7 | \[ x - \color{blue}{y \cdot \left(\frac{2}{\left(z \cdot 2\right) \cdot z - y \cdot t} \cdot z\right)}
\] |
rational.json-simplify-2 [=>]14.7 | \[ x - y \cdot \color{blue}{\left(z \cdot \frac{2}{\left(z \cdot 2\right) \cdot z - y \cdot t}\right)}
\] |
rational.json-simplify-50 [=>]14.7 | \[ x - y \cdot \left(z \cdot \color{blue}{\frac{-2}{y \cdot t - \left(z \cdot 2\right) \cdot z}}\right)
\] |
metadata-eval [=>]14.7 | \[ x - y \cdot \left(z \cdot \frac{\color{blue}{-2}}{y \cdot t - \left(z \cdot 2\right) \cdot z}\right)
\] |
rational.json-simplify-2 [=>]14.7 | \[ x - y \cdot \left(z \cdot \frac{-2}{y \cdot t - \color{blue}{z \cdot \left(z \cdot 2\right)}}\right)
\] |
rational.json-simplify-43 [<=]14.7 | \[ x - y \cdot \left(z \cdot \frac{-2}{y \cdot t - \color{blue}{2 \cdot \left(z \cdot z\right)}}\right)
\] |
Taylor expanded in y around 0 1.5
if -8.99999999999999944e162 < z < -4.29999999999999987e-134 or 2e-187 < z < 1.2500000000000001e147Initial program 5.7
Simplified2.2
[Start]5.7 | \[ x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
|---|---|
rational.json-simplify-49 [=>]2.2 | \[ x - \color{blue}{z \cdot \frac{y \cdot 2}{\left(z \cdot 2\right) \cdot z - y \cdot t}}
\] |
rational.json-simplify-50 [=>]2.2 | \[ x - z \cdot \color{blue}{\frac{-y \cdot 2}{y \cdot t - \left(z \cdot 2\right) \cdot z}}
\] |
rational.json-simplify-5 [<=]2.2 | \[ x - z \cdot \frac{-y \cdot 2}{\color{blue}{\left(y \cdot t - \left(z \cdot 2\right) \cdot z\right) - 0}}
\] |
rational.json-simplify-50 [<=]2.2 | \[ x - z \cdot \color{blue}{\frac{y \cdot 2}{0 - \left(y \cdot t - \left(z \cdot 2\right) \cdot z\right)}}
\] |
rational.json-simplify-45 [=>]2.2 | \[ x - z \cdot \frac{y \cdot 2}{\color{blue}{\left(z \cdot 2\right) \cdot z - \left(y \cdot t - 0\right)}}
\] |
rational.json-simplify-2 [=>]2.2 | \[ x - z \cdot \frac{y \cdot 2}{\color{blue}{z \cdot \left(z \cdot 2\right)} - \left(y \cdot t - 0\right)}
\] |
rational.json-simplify-2 [=>]2.2 | \[ x - z \cdot \frac{y \cdot 2}{z \cdot \color{blue}{\left(2 \cdot z\right)} - \left(y \cdot t - 0\right)}
\] |
rational.json-simplify-5 [=>]2.2 | \[ x - z \cdot \frac{y \cdot 2}{z \cdot \left(2 \cdot z\right) - \color{blue}{y \cdot t}}
\] |
if -4.29999999999999987e-134 < z < 2e-187Initial program 8.8
Simplified9.1
[Start]8.8 | \[ x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
|---|---|
rational.json-simplify-49 [=>]6.9 | \[ x - \color{blue}{z \cdot \frac{y \cdot 2}{\left(z \cdot 2\right) \cdot z - y \cdot t}}
\] |
rational.json-simplify-2 [=>]6.9 | \[ x - z \cdot \frac{\color{blue}{2 \cdot y}}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
rational.json-simplify-49 [=>]8.0 | \[ x - z \cdot \color{blue}{\left(y \cdot \frac{2}{\left(z \cdot 2\right) \cdot z - y \cdot t}\right)}
\] |
rational.json-simplify-43 [=>]9.1 | \[ x - \color{blue}{y \cdot \left(\frac{2}{\left(z \cdot 2\right) \cdot z - y \cdot t} \cdot z\right)}
\] |
rational.json-simplify-2 [=>]9.1 | \[ x - y \cdot \color{blue}{\left(z \cdot \frac{2}{\left(z \cdot 2\right) \cdot z - y \cdot t}\right)}
\] |
rational.json-simplify-50 [=>]9.1 | \[ x - y \cdot \left(z \cdot \color{blue}{\frac{-2}{y \cdot t - \left(z \cdot 2\right) \cdot z}}\right)
\] |
metadata-eval [=>]9.1 | \[ x - y \cdot \left(z \cdot \frac{\color{blue}{-2}}{y \cdot t - \left(z \cdot 2\right) \cdot z}\right)
\] |
rational.json-simplify-2 [=>]9.1 | \[ x - y \cdot \left(z \cdot \frac{-2}{y \cdot t - \color{blue}{z \cdot \left(z \cdot 2\right)}}\right)
\] |
rational.json-simplify-43 [<=]9.1 | \[ x - y \cdot \left(z \cdot \frac{-2}{y \cdot t - \color{blue}{2 \cdot \left(z \cdot z\right)}}\right)
\] |
Taylor expanded in y around inf 1.5
Final simplification1.8
| Alternative 1 | |
|---|---|
| Error | 1.9 |
| Cost | 1616 |
| Alternative 2 | |
|---|---|
| Error | 1.9 |
| Cost | 1616 |
| Alternative 3 | |
|---|---|
| Error | 6.9 |
| Cost | 712 |
| Alternative 4 | |
|---|---|
| Error | 11.6 |
| Cost | 584 |
| Alternative 5 | |
|---|---|
| Error | 16.3 |
| Cost | 520 |
| Alternative 6 | |
|---|---|
| Error | 16.1 |
| Cost | 64 |
herbie shell --seed 2023074
(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)))))