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

(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z) :precision binary64 (- x (/ x (/ y z))))
double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
double code(double x, double y, double z) {
return x - (x / (y / z));
}
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)) / y
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 - (x / (y / z))
end function
public static double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
public static double code(double x, double y, double z) {
return x - (x / (y / z));
}
def code(x, y, z): return (x * (y - z)) / y
def code(x, y, z): return x - (x / (y / z))
function code(x, y, z) return Float64(Float64(x * Float64(y - z)) / y) end
function code(x, y, z) return Float64(x - Float64(x / Float64(y / z))) end
function tmp = code(x, y, z) tmp = (x * (y - z)) / y; end
function tmp = code(x, y, z) tmp = x - (x / (y / z)); end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
code[x_, y_, z_] := N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
\\
x - \frac{x}{\frac{y}{z}}
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 84.6% |
|---|---|
| Target | 96.2% |
| Herbie | 96.6% |
Initial program 87.6%
Simplified92.2%
[Start]87.6% | \[ \frac{x \cdot \left(y - z\right)}{y}
\] |
|---|---|
associate-*l/ [<=]83.4% | \[ \color{blue}{\frac{x}{y} \cdot \left(y - z\right)}
\] |
distribute-rgt-out-- [<=]79.2% | \[ \color{blue}{y \cdot \frac{x}{y} - z \cdot \frac{x}{y}}
\] |
associate-*r/ [=>]80.5% | \[ \color{blue}{\frac{y \cdot x}{y}} - z \cdot \frac{x}{y}
\] |
associate-*l/ [<=]92.2% | \[ \color{blue}{\frac{y}{y} \cdot x} - z \cdot \frac{x}{y}
\] |
*-inverses [=>]92.2% | \[ \color{blue}{1} \cdot x - z \cdot \frac{x}{y}
\] |
*-lft-identity [=>]92.2% | \[ \color{blue}{x} - z \cdot \frac{x}{y}
\] |
Taylor expanded in z around 0 96.3%
Simplified97.7%
[Start]96.3% | \[ x - \frac{z \cdot x}{y}
\] |
|---|---|
*-commutative [=>]96.3% | \[ x - \frac{\color{blue}{x \cdot z}}{y}
\] |
associate-/l* [=>]97.7% | \[ x - \color{blue}{\frac{x}{\frac{y}{z}}}
\] |
Final simplification97.7%
| Alternative 1 | |
|---|---|
| Accuracy | 96.6% |
| Cost | 448 |
| Alternative 2 | |
|---|---|
| Accuracy | 72.8% |
| Cost | 649 |
| Alternative 3 | |
|---|---|
| Accuracy | 72.5% |
| Cost | 649 |
| Alternative 4 | |
|---|---|
| Accuracy | 72.0% |
| Cost | 648 |
| Alternative 5 | |
|---|---|
| Accuracy | 51.4% |
| Cost | 452 |
| Alternative 6 | |
|---|---|
| Accuracy | 50.9% |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Accuracy | 96.2% |
| Cost | 448 |
| Alternative 8 | |
|---|---|
| Accuracy | 50.5% |
| Cost | 64 |
herbie shell --seed 2023167
(FPCore (x y z)
:name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
:precision binary64
:herbie-target
(if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y))))
(/ (* x (- y z)) y))