| Alternative 1 | |
|---|---|
| Error | 6.6 |
| Cost | 712 |
\[\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -1950:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq 0.035:\\
\;\;\;\;x - -2 \cdot \frac{z}{t}\\
\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
(if (<= z -5.5e+128)
(- (+ x x) (+ x (/ y z)))
(if (<= z 1.4e+116)
(- x (* y (/ z (- (* z z) (/ (* y t) 2.0)))))
(- x (/ y z)))))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 tmp;
if (z <= -5.5e+128) {
tmp = (x + x) - (x + (y / z));
} else if (z <= 1.4e+116) {
tmp = x - (y * (z / ((z * z) - ((y * t) / 2.0))));
} else {
tmp = x - (y / z);
}
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) :: tmp
if (z <= (-5.5d+128)) then
tmp = (x + x) - (x + (y / z))
else if (z <= 1.4d+116) then
tmp = x - (y * (z / ((z * z) - ((y * t) / 2.0d0))))
else
tmp = x - (y / z)
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 tmp;
if (z <= -5.5e+128) {
tmp = (x + x) - (x + (y / z));
} else if (z <= 1.4e+116) {
tmp = x - (y * (z / ((z * z) - ((y * t) / 2.0))));
} else {
tmp = x - (y / z);
}
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): tmp = 0 if z <= -5.5e+128: tmp = (x + x) - (x + (y / z)) elif z <= 1.4e+116: tmp = x - (y * (z / ((z * z) - ((y * t) / 2.0)))) else: tmp = x - (y / z) 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) tmp = 0.0 if (z <= -5.5e+128) tmp = Float64(Float64(x + x) - Float64(x + Float64(y / z))); elseif (z <= 1.4e+116) tmp = Float64(x - Float64(y * Float64(z / Float64(Float64(z * z) - Float64(Float64(y * t) / 2.0))))); else tmp = Float64(x - Float64(y / z)); 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) tmp = 0.0; if (z <= -5.5e+128) tmp = (x + x) - (x + (y / z)); elseif (z <= 1.4e+116) tmp = x - (y * (z / ((z * z) - ((y * t) / 2.0)))); else tmp = x - (y / z); 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_] := If[LessEqual[z, -5.5e+128], N[(N[(x + x), $MachinePrecision] - N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.4e+116], N[(x - N[(y * N[(z / N[(N[(z * z), $MachinePrecision] - N[(N[(y * t), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]]]
x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{+128}:\\
\;\;\;\;\left(x + x\right) - \left(x + \frac{y}{z}\right)\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{+116}:\\
\;\;\;\;x - y \cdot \frac{z}{z \cdot z - \frac{y \cdot t}{2}}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{y}{z}\\
\end{array}
Results
| Original | 11.9 |
|---|---|
| Target | 0.1 |
| Herbie | 3.5 |
if z < -5.4999999999999998e128Initial program 26.3
Taylor expanded in y around 0 2.1
Simplified2.1
[Start]2.1 | \[ -1 \cdot \frac{y}{z} + x
\] |
|---|---|
rational_best-simplify-3 [=>]2.1 | \[ \color{blue}{x + -1 \cdot \frac{y}{z}}
\] |
rational_best-simplify-55 [=>]2.1 | \[ x + \color{blue}{y \cdot \frac{-1}{z}}
\] |
Applied egg-rr2.1
if -5.4999999999999998e128 < z < 1.40000000000000002e116Initial program 5.8
Applied egg-rr3.9
Applied egg-rr3.5
Simplified3.9
[Start]3.5 | \[ x - \left(z \cdot \frac{-y}{\frac{y \cdot t}{2} - z \cdot z} + 0\right)
\] |
|---|---|
rational_best-simplify-3 [=>]3.5 | \[ x - \color{blue}{\left(0 + z \cdot \frac{-y}{\frac{y \cdot t}{2} - z \cdot z}\right)}
\] |
rational_best-simplify-6 [=>]3.5 | \[ x - \color{blue}{z \cdot \frac{-y}{\frac{y \cdot t}{2} - z \cdot z}}
\] |
rational_best-simplify-55 [=>]3.9 | \[ x - \color{blue}{\left(-y\right) \cdot \frac{z}{\frac{y \cdot t}{2} - z \cdot z}}
\] |
rational_best-simplify-1 [=>]3.9 | \[ x - \color{blue}{\frac{z}{\frac{y \cdot t}{2} - z \cdot z} \cdot \left(-y\right)}
\] |
rational_best-simplify-13 [=>]3.9 | \[ x - \frac{z}{\frac{y \cdot t}{2} - z \cdot z} \cdot \color{blue}{\frac{y}{-1}}
\] |
rational_best-simplify-55 [<=]3.9 | \[ x - \color{blue}{y \cdot \frac{\frac{z}{\frac{y \cdot t}{2} - z \cdot z}}{-1}}
\] |
rational_best-simplify-53 [=>]3.9 | \[ x - y \cdot \color{blue}{\frac{z}{\left(\frac{y \cdot t}{2} - z \cdot z\right) \cdot -1}}
\] |
rational_best-simplify-11 [<=]3.9 | \[ x - y \cdot \frac{z}{\color{blue}{-\left(\frac{y \cdot t}{2} - z \cdot z\right)}}
\] |
rational_best-simplify-14 [=>]3.9 | \[ x - y \cdot \frac{z}{\color{blue}{0 - \left(\frac{y \cdot t}{2} - z \cdot z\right)}}
\] |
rational_best-simplify-51 [=>]3.9 | \[ x - y \cdot \frac{z}{\color{blue}{z \cdot z - \left(\frac{y \cdot t}{2} - 0\right)}}
\] |
rational_best-simplify-9 [=>]3.9 | \[ x - y \cdot \frac{z}{z \cdot z - \color{blue}{\frac{y \cdot t}{2}}}
\] |
if 1.40000000000000002e116 < z Initial program 24.6
Taylor expanded in y around 0 3.1
Final simplification3.5
| Alternative 1 | |
|---|---|
| Error | 6.6 |
| Cost | 712 |
| Alternative 2 | |
|---|---|
| Error | 6.6 |
| Cost | 712 |
| Alternative 3 | |
|---|---|
| Error | 12.1 |
| Cost | 584 |
| Alternative 4 | |
|---|---|
| Error | 15.8 |
| Cost | 520 |
| Alternative 5 | |
|---|---|
| Error | 15.8 |
| Cost | 64 |
herbie shell --seed 2023099
(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)))))