| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 6912 |
\[0.5 \cdot \left(x + \frac{y}{{z}^{-0.5}}\right)
\]

(FPCore (x y z) :precision binary64 (* (/ 1.0 2.0) (+ x (* y (sqrt z)))))
(FPCore (x y z) :precision binary64 (* 0.5 (+ x (/ y (pow z -0.5)))))
double code(double x, double y, double z) {
return (1.0 / 2.0) * (x + (y * sqrt(z)));
}
double code(double x, double y, double z) {
return 0.5 * (x + (y / pow(z, -0.5)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (1.0d0 / 2.0d0) * (x + (y * sqrt(z)))
end function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.5d0 * (x + (y / (z ** (-0.5d0))))
end function
public static double code(double x, double y, double z) {
return (1.0 / 2.0) * (x + (y * Math.sqrt(z)));
}
public static double code(double x, double y, double z) {
return 0.5 * (x + (y / Math.pow(z, -0.5)));
}
def code(x, y, z): return (1.0 / 2.0) * (x + (y * math.sqrt(z)))
def code(x, y, z): return 0.5 * (x + (y / math.pow(z, -0.5)))
function code(x, y, z) return Float64(Float64(1.0 / 2.0) * Float64(x + Float64(y * sqrt(z)))) end
function code(x, y, z) return Float64(0.5 * Float64(x + Float64(y / (z ^ -0.5)))) end
function tmp = code(x, y, z) tmp = (1.0 / 2.0) * (x + (y * sqrt(z))); end
function tmp = code(x, y, z) tmp = 0.5 * (x + (y / (z ^ -0.5))); end
code[x_, y_, z_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(x + N[(y * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(0.5 * N[(x + N[(y / N[Power[z, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right)
0.5 \cdot \left(x + \frac{y}{{z}^{-0.5}}\right)
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 99.9%
Simplified99.9%
[Start]99.9% | \[ \frac{1}{2} \cdot \left(x + y \cdot \sqrt{z}\right)
\] |
|---|---|
metadata-eval [=>]99.9% | \[ \color{blue}{0.5} \cdot \left(x + y \cdot \sqrt{z}\right)
\] |
Applied egg-rr99.1%
[Start]99.9% | \[ 0.5 \cdot \left(x + y \cdot \sqrt{z}\right)
\] |
|---|---|
add-cube-cbrt [=>]99.1% | \[ 0.5 \cdot \left(x + \color{blue}{\left(\sqrt[3]{y \cdot \sqrt{z}} \cdot \sqrt[3]{y \cdot \sqrt{z}}\right) \cdot \sqrt[3]{y \cdot \sqrt{z}}}\right)
\] |
pow3 [=>]99.1% | \[ 0.5 \cdot \left(x + \color{blue}{{\left(\sqrt[3]{y \cdot \sqrt{z}}\right)}^{3}}\right)
\] |
Applied egg-rr99.5%
[Start]99.1% | \[ 0.5 \cdot \left(x + {\left(\sqrt[3]{y \cdot \sqrt{z}}\right)}^{3}\right)
\] |
|---|---|
rem-cube-cbrt [=>]99.9% | \[ 0.5 \cdot \left(x + \color{blue}{y \cdot \sqrt{z}}\right)
\] |
add-cbrt-cube [=>]79.1% | \[ 0.5 \cdot \left(x + y \cdot \color{blue}{\sqrt[3]{\left(\sqrt{z} \cdot \sqrt{z}\right) \cdot \sqrt{z}}}\right)
\] |
add-sqr-sqrt [<=]79.1% | \[ 0.5 \cdot \left(x + y \cdot \sqrt[3]{\color{blue}{z} \cdot \sqrt{z}}\right)
\] |
cbrt-prod [=>]99.5% | \[ 0.5 \cdot \left(x + y \cdot \color{blue}{\left(\sqrt[3]{z} \cdot \sqrt[3]{\sqrt{z}}\right)}\right)
\] |
associate-*r* [=>]99.5% | \[ 0.5 \cdot \left(x + \color{blue}{\left(y \cdot \sqrt[3]{z}\right) \cdot \sqrt[3]{\sqrt{z}}}\right)
\] |
Applied egg-rr99.9%
[Start]99.5% | \[ 0.5 \cdot \left(x + \left(y \cdot \sqrt[3]{z}\right) \cdot \sqrt[3]{\sqrt{z}}\right)
\] |
|---|---|
associate-*l* [=>]99.5% | \[ 0.5 \cdot \left(x + \color{blue}{y \cdot \left(\sqrt[3]{z} \cdot \sqrt[3]{\sqrt{z}}\right)}\right)
\] |
cbrt-prod [<=]79.1% | \[ 0.5 \cdot \left(x + y \cdot \color{blue}{\sqrt[3]{z \cdot \sqrt{z}}}\right)
\] |
add-sqr-sqrt [=>]79.1% | \[ 0.5 \cdot \left(x + y \cdot \sqrt[3]{\color{blue}{\left(\sqrt{z} \cdot \sqrt{z}\right)} \cdot \sqrt{z}}\right)
\] |
add-cbrt-cube [<=]99.9% | \[ 0.5 \cdot \left(x + y \cdot \color{blue}{\sqrt{z}}\right)
\] |
remove-double-div [<=]99.8% | \[ 0.5 \cdot \left(x + y \cdot \color{blue}{\frac{1}{\frac{1}{\sqrt{z}}}}\right)
\] |
metadata-eval [<=]99.8% | \[ 0.5 \cdot \left(x + y \cdot \frac{1}{\frac{\color{blue}{\sqrt{1}}}{\sqrt{z}}}\right)
\] |
sqrt-div [<=]99.8% | \[ 0.5 \cdot \left(x + y \cdot \frac{1}{\color{blue}{\sqrt{\frac{1}{z}}}}\right)
\] |
div-inv [<=]99.8% | \[ 0.5 \cdot \left(x + \color{blue}{\frac{y}{\sqrt{\frac{1}{z}}}}\right)
\] |
inv-pow [=>]99.8% | \[ 0.5 \cdot \left(x + \frac{y}{\sqrt{\color{blue}{{z}^{-1}}}}\right)
\] |
sqrt-pow1 [=>]99.9% | \[ 0.5 \cdot \left(x + \frac{y}{\color{blue}{{z}^{\left(\frac{-1}{2}\right)}}}\right)
\] |
metadata-eval [=>]99.9% | \[ 0.5 \cdot \left(x + \frac{y}{{z}^{\color{blue}{-0.5}}}\right)
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 6912 |
| Alternative 2 | |
|---|---|
| Accuracy | 73.6% |
| Cost | 6984 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 6848 |
| Alternative 4 | |
|---|---|
| Accuracy | 50.8% |
| Cost | 192 |
herbie shell --seed 2023271
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:quadForm from diagrams-solve-0.1, B"
:precision binary64
(* (/ 1.0 2.0) (+ x (* y (sqrt z)))))