| Alternative 1 | |
|---|---|
| Error | 4.3 |
| Cost | 2116 |
(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 (- (* y t) (* 2.0 (* z z)))) (t_2 (- x (/ y z))))
(if (<= z -8.6e+139)
t_2
(if (<= z -1.1e-119)
(- x (* y (* z (/ -2.0 t_1))))
(if (<= z 1.5e-205)
(- x (* -2.0 (/ z t)))
(if (<= z 1e+134) (- x (* y (/ (* z -2.0) t_1))) t_2))))))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 = (y * t) - (2.0 * (z * z));
double t_2 = x - (y / z);
double tmp;
if (z <= -8.6e+139) {
tmp = t_2;
} else if (z <= -1.1e-119) {
tmp = x - (y * (z * (-2.0 / t_1)));
} else if (z <= 1.5e-205) {
tmp = x - (-2.0 * (z / t));
} else if (z <= 1e+134) {
tmp = x - (y * ((z * -2.0) / t_1));
} else {
tmp = t_2;
}
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 = (y * t) - (2.0d0 * (z * z))
t_2 = x - (y / z)
if (z <= (-8.6d+139)) then
tmp = t_2
else if (z <= (-1.1d-119)) then
tmp = x - (y * (z * ((-2.0d0) / t_1)))
else if (z <= 1.5d-205) then
tmp = x - ((-2.0d0) * (z / t))
else if (z <= 1d+134) then
tmp = x - (y * ((z * (-2.0d0)) / t_1))
else
tmp = t_2
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 = (y * t) - (2.0 * (z * z));
double t_2 = x - (y / z);
double tmp;
if (z <= -8.6e+139) {
tmp = t_2;
} else if (z <= -1.1e-119) {
tmp = x - (y * (z * (-2.0 / t_1)));
} else if (z <= 1.5e-205) {
tmp = x - (-2.0 * (z / t));
} else if (z <= 1e+134) {
tmp = x - (y * ((z * -2.0) / t_1));
} else {
tmp = t_2;
}
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 = (y * t) - (2.0 * (z * z)) t_2 = x - (y / z) tmp = 0 if z <= -8.6e+139: tmp = t_2 elif z <= -1.1e-119: tmp = x - (y * (z * (-2.0 / t_1))) elif z <= 1.5e-205: tmp = x - (-2.0 * (z / t)) elif z <= 1e+134: tmp = x - (y * ((z * -2.0) / t_1)) else: tmp = t_2 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(Float64(y * t) - Float64(2.0 * Float64(z * z))) t_2 = Float64(x - Float64(y / z)) tmp = 0.0 if (z <= -8.6e+139) tmp = t_2; elseif (z <= -1.1e-119) tmp = Float64(x - Float64(y * Float64(z * Float64(-2.0 / t_1)))); elseif (z <= 1.5e-205) tmp = Float64(x - Float64(-2.0 * Float64(z / t))); elseif (z <= 1e+134) tmp = Float64(x - Float64(y * Float64(Float64(z * -2.0) / t_1))); else tmp = t_2; 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 = (y * t) - (2.0 * (z * z)); t_2 = x - (y / z); tmp = 0.0; if (z <= -8.6e+139) tmp = t_2; elseif (z <= -1.1e-119) tmp = x - (y * (z * (-2.0 / t_1))); elseif (z <= 1.5e-205) tmp = x - (-2.0 * (z / t)); elseif (z <= 1e+134) tmp = x - (y * ((z * -2.0) / t_1)); else tmp = t_2; 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[(N[(y * t), $MachinePrecision] - N[(2.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -8.6e+139], t$95$2, If[LessEqual[z, -1.1e-119], N[(x - N[(y * N[(z * N[(-2.0 / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.5e-205], N[(x - N[(-2.0 * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1e+134], N[(x - N[(y * N[(N[(z * -2.0), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]]
x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\begin{array}{l}
t_1 := y \cdot t - 2 \cdot \left(z \cdot z\right)\\
t_2 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -8.6 \cdot 10^{+139}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;z \leq -1.1 \cdot 10^{-119}:\\
\;\;\;\;x - y \cdot \left(z \cdot \frac{-2}{t_1}\right)\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{-205}:\\
\;\;\;\;x - -2 \cdot \frac{z}{t}\\
\mathbf{elif}\;z \leq 10^{+134}:\\
\;\;\;\;x - y \cdot \frac{z \cdot -2}{t_1}\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
Results
| Original | 11.7 |
|---|---|
| Target | 0.1 |
| Herbie | 2.1 |
if z < -8.5999999999999996e139 or 9.99999999999999921e133 < z Initial program 25.5
Simplified12.9
[Start]25.5 | \[ x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
|---|---|
rational.json-simplify-49 [=>]13.0 | \[ x - \color{blue}{z \cdot \frac{y \cdot 2}{\left(z \cdot 2\right) \cdot z - y \cdot t}}
\] |
rational.json-simplify-2 [=>]13.0 | \[ x - z \cdot \frac{\color{blue}{2 \cdot y}}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
rational.json-simplify-49 [=>]13.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 [=>]12.9 | \[ 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 [=>]12.9 | \[ 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 [=>]12.9 | \[ x - y \cdot \left(z \cdot \color{blue}{\frac{-2}{y \cdot t - \left(z \cdot 2\right) \cdot z}}\right)
\] |
metadata-eval [=>]12.9 | \[ 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 [=>]12.9 | \[ 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 [<=]12.9 | \[ 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 2.0
if -8.5999999999999996e139 < z < -1.1e-119Initial program 5.4
Simplified2.0
[Start]5.4 | \[ x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
|---|---|
rational.json-simplify-49 [=>]2.0 | \[ x - \color{blue}{z \cdot \frac{y \cdot 2}{\left(z \cdot 2\right) \cdot z - y \cdot t}}
\] |
rational.json-simplify-2 [=>]2.0 | \[ x - z \cdot \frac{\color{blue}{2 \cdot y}}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
rational.json-simplify-49 [=>]2.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 [=>]2.0 | \[ 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 [=>]2.0 | \[ 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 [=>]2.0 | \[ x - y \cdot \left(z \cdot \color{blue}{\frac{-2}{y \cdot t - \left(z \cdot 2\right) \cdot z}}\right)
\] |
metadata-eval [=>]2.0 | \[ 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 [=>]2.0 | \[ 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 [<=]2.0 | \[ x - y \cdot \left(z \cdot \frac{-2}{y \cdot t - \color{blue}{2 \cdot \left(z \cdot z\right)}}\right)
\] |
if -1.1e-119 < z < 1.5e-205Initial program 7.8
Simplified8.1
[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-49 [=>]6.2 | \[ x - \color{blue}{z \cdot \frac{y \cdot 2}{\left(z \cdot 2\right) \cdot z - y \cdot t}}
\] |
rational.json-simplify-2 [=>]6.2 | \[ x - z \cdot \frac{\color{blue}{2 \cdot y}}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
rational.json-simplify-49 [=>]7.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 [=>]8.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 [=>]8.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 [=>]8.1 | \[ x - y \cdot \left(z \cdot \color{blue}{\frac{-2}{y \cdot t - \left(z \cdot 2\right) \cdot z}}\right)
\] |
metadata-eval [=>]8.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 [=>]8.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 [<=]8.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.7
if 1.5e-205 < z < 9.99999999999999921e133Initial program 5.3
Simplified2.6
[Start]5.3 | \[ x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\] |
|---|---|
rational.json-simplify-50 [=>]5.3 | \[ 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.3 | \[ 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.3 | \[ 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.3 | \[ 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.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 [<=]5.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 [=>]5.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 [=>]2.6 | \[ 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 [=>]2.6 | \[ 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 [=>]2.6 | \[ 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 [=>]2.6 | \[ x - y \cdot \frac{\color{blue}{z \cdot \frac{2}{-1}}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
metadata-eval [=>]2.6 | \[ x - y \cdot \frac{z \cdot \color{blue}{-2}}{y \cdot t - \left(z \cdot 2\right) \cdot z}
\] |
rational.json-simplify-2 [=>]2.6 | \[ x - y \cdot \frac{z \cdot -2}{y \cdot t - \color{blue}{z \cdot \left(z \cdot 2\right)}}
\] |
rational.json-simplify-43 [<=]2.6 | \[ x - y \cdot \frac{z \cdot -2}{y \cdot t - \color{blue}{2 \cdot \left(z \cdot z\right)}}
\] |
Final simplification2.1
| Alternative 1 | |
|---|---|
| Error | 4.3 |
| Cost | 2116 |
| Alternative 2 | |
|---|---|
| Error | 2.5 |
| Cost | 1616 |
| Alternative 3 | |
|---|---|
| Error | 12.6 |
| Cost | 848 |
| Alternative 4 | |
|---|---|
| Error | 7.2 |
| Cost | 712 |
| Alternative 5 | |
|---|---|
| Error | 15.8 |
| Cost | 520 |
| Alternative 6 | |
|---|---|
| Error | 15.8 |
| Cost | 64 |
herbie shell --seed 2023068
(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)))))