| Alternative 1 | |
|---|---|
| Accuracy | 96.4% |
| Cost | 448 |
\[\frac{x}{\frac{z}{z + y}}
\]

(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z) :precision binary64 (/ x (/ z (+ z y))))
double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
double code(double x, double y, double z) {
return x / (z / (z + y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y + z)) / 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 = x / (z / (z + y))
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
public static double code(double x, double y, double z) {
return x / (z / (z + y));
}
def code(x, y, z): return (x * (y + z)) / z
def code(x, y, z): return x / (z / (z + y))
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function code(x, y, z) return Float64(x / Float64(z / Float64(z + y))) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
function tmp = code(x, y, z) tmp = x / (z / (z + y)); end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := N[(x / N[(z / N[(z + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x \cdot \left(y + z\right)}{z}
\frac{x}{\frac{z}{z + y}}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 84.5% |
|---|---|
| Target | 96.4% |
| Herbie | 96.4% |
Initial program 84.8%
Simplified81.0%
[Start]84.8% | \[ \frac{x \cdot \left(y + z\right)}{z}
\] |
|---|---|
associate-*l/ [<=]81.0% | \[ \color{blue}{\frac{x}{z} \cdot \left(y + z\right)}
\] |
Applied egg-rr96.5%
[Start]81.0% | \[ \frac{x}{z} \cdot \left(y + z\right)
\] |
|---|---|
associate-/r/ [<=]96.5% | \[ \color{blue}{\frac{x}{\frac{z}{y + z}}}
\] |
+-commutative [=>]96.5% | \[ \frac{x}{\frac{z}{\color{blue}{z + y}}}
\] |
Final simplification96.5%
| Alternative 1 | |
|---|---|
| Accuracy | 96.4% |
| Cost | 448 |
| Alternative 2 | |
|---|---|
| Accuracy | 89.6% |
| Cost | 712 |
| Alternative 3 | |
|---|---|
| Accuracy | 71.1% |
| Cost | 584 |
| Alternative 4 | |
|---|---|
| Accuracy | 72.9% |
| Cost | 584 |
| Alternative 5 | |
|---|---|
| Accuracy | 73.0% |
| Cost | 584 |
| Alternative 6 | |
|---|---|
| Accuracy | 50.8% |
| Cost | 64 |
herbie shell --seed 2023263
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))