| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 576 |
\[x \cdot \left(x \cdot 9 + -12\right) + 3
\]

(FPCore (x) :precision binary64 (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))
(FPCore (x) :precision binary64 (+ (* x (+ (* x 9.0) -12.0)) 3.0))
double code(double x) {
return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
double code(double x) {
return (x * ((x * 9.0) + -12.0)) + 3.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 3.0d0 * ((((x * 3.0d0) * x) - (x * 4.0d0)) + 1.0d0)
end function
real(8) function code(x)
real(8), intent (in) :: x
code = (x * ((x * 9.0d0) + (-12.0d0))) + 3.0d0
end function
public static double code(double x) {
return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
public static double code(double x) {
return (x * ((x * 9.0) + -12.0)) + 3.0;
}
def code(x): return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0)
def code(x): return (x * ((x * 9.0) + -12.0)) + 3.0
function code(x) return Float64(3.0 * Float64(Float64(Float64(Float64(x * 3.0) * x) - Float64(x * 4.0)) + 1.0)) end
function code(x) return Float64(Float64(x * Float64(Float64(x * 9.0) + -12.0)) + 3.0) end
function tmp = code(x) tmp = 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0); end
function tmp = code(x) tmp = (x * ((x * 9.0) + -12.0)) + 3.0; end
code[x_] := N[(3.0 * N[(N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] - N[(x * 4.0), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(x * N[(N[(x * 9.0), $MachinePrecision] + -12.0), $MachinePrecision]), $MachinePrecision] + 3.0), $MachinePrecision]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
x \cdot \left(x \cdot 9 + -12\right) + 3
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 99.8% |
|---|---|
| Target | 99.8% |
| Herbie | 99.9% |
Initial program 99.8%
Simplified99.9%
[Start]99.8% | \[ 3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\] |
|---|---|
*-commutative [=>]99.8% | \[ \color{blue}{\left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \cdot 3}
\] |
distribute-lft1-in [<=]99.9% | \[ \color{blue}{\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) \cdot 3 + 3}
\] |
*-commutative [=>]99.9% | \[ \left(\color{blue}{x \cdot \left(x \cdot 3\right)} - x \cdot 4\right) \cdot 3 + 3
\] |
distribute-lft-out-- [=>]99.8% | \[ \color{blue}{\left(x \cdot \left(x \cdot 3 - 4\right)\right)} \cdot 3 + 3
\] |
associate-*l* [=>]99.8% | \[ \color{blue}{x \cdot \left(\left(x \cdot 3 - 4\right) \cdot 3\right)} + 3
\] |
fma-def [=>]99.8% | \[ \color{blue}{\mathsf{fma}\left(x, \left(x \cdot 3 - 4\right) \cdot 3, 3\right)}
\] |
*-commutative [=>]99.8% | \[ \mathsf{fma}\left(x, \color{blue}{3 \cdot \left(x \cdot 3 - 4\right)}, 3\right)
\] |
sub-neg [=>]99.8% | \[ \mathsf{fma}\left(x, 3 \cdot \color{blue}{\left(x \cdot 3 + \left(-4\right)\right)}, 3\right)
\] |
distribute-lft-in [=>]99.8% | \[ \mathsf{fma}\left(x, \color{blue}{3 \cdot \left(x \cdot 3\right) + 3 \cdot \left(-4\right)}, 3\right)
\] |
*-commutative [<=]99.8% | \[ \mathsf{fma}\left(x, \color{blue}{\left(x \cdot 3\right) \cdot 3} + 3 \cdot \left(-4\right), 3\right)
\] |
associate-*l* [=>]99.9% | \[ \mathsf{fma}\left(x, \color{blue}{x \cdot \left(3 \cdot 3\right)} + 3 \cdot \left(-4\right), 3\right)
\] |
fma-def [=>]99.9% | \[ \mathsf{fma}\left(x, \color{blue}{\mathsf{fma}\left(x, 3 \cdot 3, 3 \cdot \left(-4\right)\right)}, 3\right)
\] |
metadata-eval [=>]99.9% | \[ \mathsf{fma}\left(x, \mathsf{fma}\left(x, \color{blue}{9}, 3 \cdot \left(-4\right)\right), 3\right)
\] |
metadata-eval [=>]99.9% | \[ \mathsf{fma}\left(x, \mathsf{fma}\left(x, 9, 3 \cdot \color{blue}{-4}\right), 3\right)
\] |
metadata-eval [=>]99.9% | \[ \mathsf{fma}\left(x, \mathsf{fma}\left(x, 9, \color{blue}{-12}\right), 3\right)
\] |
Applied egg-rr99.9%
[Start]99.9% | \[ \mathsf{fma}\left(x, \mathsf{fma}\left(x, 9, -12\right), 3\right)
\] |
|---|---|
fma-udef [=>]99.9% | \[ \color{blue}{x \cdot \mathsf{fma}\left(x, 9, -12\right) + 3}
\] |
Applied egg-rr99.5%
[Start]99.9% | \[ x \cdot \mathsf{fma}\left(x, 9, -12\right) + 3
\] |
|---|---|
fma-udef [=>]99.9% | \[ x \cdot \color{blue}{\left(x \cdot 9 + -12\right)} + 3
\] |
distribute-rgt-in [=>]99.5% | \[ \color{blue}{\left(\left(x \cdot 9\right) \cdot x + -12 \cdot x\right)} + 3
\] |
*-commutative [=>]99.5% | \[ \left(\left(x \cdot 9\right) \cdot x + \color{blue}{x \cdot -12}\right) + 3
\] |
Applied egg-rr99.9%
[Start]99.5% | \[ \left(\left(x \cdot 9\right) \cdot x + x \cdot -12\right) + 3
\] |
|---|---|
*-commutative [<=]99.5% | \[ \left(\color{blue}{x \cdot \left(x \cdot 9\right)} + x \cdot -12\right) + 3
\] |
distribute-lft-out [=>]99.9% | \[ \color{blue}{x \cdot \left(x \cdot 9 + -12\right)} + 3
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 576 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 585 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 585 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 448 |
| Alternative 5 | |
|---|---|
| Accuracy | 51.1% |
| Cost | 64 |
herbie shell --seed 2023272
(FPCore (x)
:name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, D"
:precision binary64
:herbie-target
(+ 3.0 (- (* (* 9.0 x) x) (* 12.0 x)))
(* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))