| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 960 |
\[\frac{x}{\frac{2 + \frac{3}{x}}{9 + \left(x \cdot x\right) \cdot -4}}
\]

(FPCore (x) :precision binary64 (* (* x x) (- 3.0 (* x 2.0))))
(FPCore (x) :precision binary64 (/ x (/ (+ 2.0 (/ 3.0 x)) (+ 9.0 (* (* x x) -4.0)))))
double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
double code(double x) {
return x / ((2.0 + (3.0 / x)) / (9.0 + ((x * x) * -4.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) * (3.0d0 - (x * 2.0d0))
end function
real(8) function code(x)
real(8), intent (in) :: x
code = x / ((2.0d0 + (3.0d0 / x)) / (9.0d0 + ((x * x) * (-4.0d0))))
end function
public static double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
public static double code(double x) {
return x / ((2.0 + (3.0 / x)) / (9.0 + ((x * x) * -4.0)));
}
def code(x): return (x * x) * (3.0 - (x * 2.0))
def code(x): return x / ((2.0 + (3.0 / x)) / (9.0 + ((x * x) * -4.0)))
function code(x) return Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0))) end
function code(x) return Float64(x / Float64(Float64(2.0 + Float64(3.0 / x)) / Float64(9.0 + Float64(Float64(x * x) * -4.0)))) end
function tmp = code(x) tmp = (x * x) * (3.0 - (x * 2.0)); end
function tmp = code(x) tmp = x / ((2.0 + (3.0 / x)) / (9.0 + ((x * x) * -4.0))); end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x / N[(N[(2.0 + N[(3.0 / x), $MachinePrecision]), $MachinePrecision] / N[(9.0 + N[(N[(x * x), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
\frac{x}{\frac{2 + \frac{3}{x}}{9 + \left(x \cdot x\right) \cdot -4}}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 99.8% |
|---|---|
| Target | 99.8% |
| Herbie | 99.8% |
Initial program 99.8%
Simplified99.8%
[Start]99.8% | \[ \left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
\] |
|---|---|
associate-*l* [=>]99.8% | \[ \color{blue}{x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right)}
\] |
Applied egg-rr99.8%
[Start]99.8% | \[ x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right)
\] |
|---|---|
*-commutative [=>]99.8% | \[ x \cdot \color{blue}{\left(\left(3 - x \cdot 2\right) \cdot x\right)}
\] |
flip-- [=>]99.7% | \[ x \cdot \left(\color{blue}{\frac{3 \cdot 3 - \left(x \cdot 2\right) \cdot \left(x \cdot 2\right)}{3 + x \cdot 2}} \cdot x\right)
\] |
associate-*l/ [=>]99.8% | \[ x \cdot \color{blue}{\frac{\left(3 \cdot 3 - \left(x \cdot 2\right) \cdot \left(x \cdot 2\right)\right) \cdot x}{3 + x \cdot 2}}
\] |
metadata-eval [=>]99.8% | \[ x \cdot \frac{\left(\color{blue}{9} - \left(x \cdot 2\right) \cdot \left(x \cdot 2\right)\right) \cdot x}{3 + x \cdot 2}
\] |
swap-sqr [=>]99.8% | \[ x \cdot \frac{\left(9 - \color{blue}{\left(x \cdot x\right) \cdot \left(2 \cdot 2\right)}\right) \cdot x}{3 + x \cdot 2}
\] |
metadata-eval [=>]99.8% | \[ x \cdot \frac{\left(9 - \left(x \cdot x\right) \cdot \color{blue}{4}\right) \cdot x}{3 + x \cdot 2}
\] |
+-commutative [=>]99.8% | \[ x \cdot \frac{\left(9 - \left(x \cdot x\right) \cdot 4\right) \cdot x}{\color{blue}{x \cdot 2 + 3}}
\] |
fma-def [=>]99.8% | \[ x \cdot \frac{\left(9 - \left(x \cdot x\right) \cdot 4\right) \cdot x}{\color{blue}{\mathsf{fma}\left(x, 2, 3\right)}}
\] |
Applied egg-rr99.8%
[Start]99.8% | \[ x \cdot \frac{\left(9 - \left(x \cdot x\right) \cdot 4\right) \cdot x}{\mathsf{fma}\left(x, 2, 3\right)}
\] |
|---|---|
clear-num [=>]99.7% | \[ x \cdot \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(x, 2, 3\right)}{\left(9 - \left(x \cdot x\right) \cdot 4\right) \cdot x}}}
\] |
un-div-inv [=>]99.8% | \[ \color{blue}{\frac{x}{\frac{\mathsf{fma}\left(x, 2, 3\right)}{\left(9 - \left(x \cdot x\right) \cdot 4\right) \cdot x}}}
\] |
*-commutative [=>]99.8% | \[ \frac{x}{\frac{\mathsf{fma}\left(x, 2, 3\right)}{\color{blue}{x \cdot \left(9 - \left(x \cdot x\right) \cdot 4\right)}}}
\] |
associate-/r* [=>]99.8% | \[ \frac{x}{\color{blue}{\frac{\frac{\mathsf{fma}\left(x, 2, 3\right)}{x}}{9 - \left(x \cdot x\right) \cdot 4}}}
\] |
sub-neg [=>]99.8% | \[ \frac{x}{\frac{\frac{\mathsf{fma}\left(x, 2, 3\right)}{x}}{\color{blue}{9 + \left(-\left(x \cdot x\right) \cdot 4\right)}}}
\] |
distribute-rgt-neg-in [=>]99.8% | \[ \frac{x}{\frac{\frac{\mathsf{fma}\left(x, 2, 3\right)}{x}}{9 + \color{blue}{\left(x \cdot x\right) \cdot \left(-4\right)}}}
\] |
metadata-eval [=>]99.8% | \[ \frac{x}{\frac{\frac{\mathsf{fma}\left(x, 2, 3\right)}{x}}{9 + \left(x \cdot x\right) \cdot \color{blue}{-4}}}
\] |
Taylor expanded in x around 0 99.7%
Simplified99.8%
[Start]99.7% | \[ \frac{x}{\frac{2 + 3 \cdot \frac{1}{x}}{9 + \left(x \cdot x\right) \cdot -4}}
\] |
|---|---|
associate-*r/ [=>]99.8% | \[ \frac{x}{\frac{2 + \color{blue}{\frac{3 \cdot 1}{x}}}{9 + \left(x \cdot x\right) \cdot -4}}
\] |
metadata-eval [=>]99.8% | \[ \frac{x}{\frac{2 + \frac{\color{blue}{3}}{x}}{9 + \left(x \cdot x\right) \cdot -4}}
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 960 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 713 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 713 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 712 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.1% |
| Cost | 712 |
| Alternative 6 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 712 |
| Alternative 7 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 576 |
| Alternative 8 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 576 |
| Alternative 9 | |
|---|---|
| Accuracy | 61.5% |
| Cost | 320 |
| Alternative 10 | |
|---|---|
| Accuracy | 3.1% |
| Cost | 192 |
herbie shell --seed 2023263
(FPCore (x)
:name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
:precision binary64
:herbie-target
(* x (* x (- 3.0 (* x 2.0))))
(* (* x x) (- 3.0 (* x 2.0))))