| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 7232 |
\[\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x + -1\right)
\]

(FPCore (x) :precision binary64 (/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))
(FPCore (x) :precision binary64 (* (/ 6.0 (+ (+ x 1.0) (* 4.0 (sqrt x)))) (+ x -1.0)))
double code(double x) {
return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x)));
}
double code(double x) {
return (6.0 / ((x + 1.0) + (4.0 * sqrt(x)))) * (x + -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (6.0d0 * (x - 1.0d0)) / ((x + 1.0d0) + (4.0d0 * sqrt(x)))
end function
real(8) function code(x)
real(8), intent (in) :: x
code = (6.0d0 / ((x + 1.0d0) + (4.0d0 * sqrt(x)))) * (x + (-1.0d0))
end function
public static double code(double x) {
return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * Math.sqrt(x)));
}
public static double code(double x) {
return (6.0 / ((x + 1.0) + (4.0 * Math.sqrt(x)))) * (x + -1.0);
}
def code(x): return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * math.sqrt(x)))
def code(x): return (6.0 / ((x + 1.0) + (4.0 * math.sqrt(x)))) * (x + -1.0)
function code(x) return Float64(Float64(6.0 * Float64(x - 1.0)) / Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x)))) end
function code(x) return Float64(Float64(6.0 / Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x)))) * Float64(x + -1.0)) end
function tmp = code(x) tmp = (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x))); end
function tmp = code(x) tmp = (6.0 / ((x + 1.0) + (4.0 * sqrt(x)))) * (x + -1.0); end
code[x_] := N[(N[(6.0 * N[(x - 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(6.0 / N[(N[(x + 1.0), $MachinePrecision] + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]
\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x + -1\right)
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 99.7% |
|---|---|
| Target | 99.9% |
| Herbie | 99.9% |
Initial program 99.8%
Simplified99.9%
[Start]99.8% | \[ \frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
\] |
|---|---|
associate-*l/ [<=]99.9% | \[ \color{blue}{\frac{6}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \cdot \left(x - 1\right)}
\] |
+-commutative [=>]99.9% | \[ \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(x - 1\right)
\] |
fma-def [=>]99.9% | \[ \frac{6}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}} \cdot \left(x - 1\right)
\] |
sub-neg [=>]99.9% | \[ \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \color{blue}{\left(x + \left(-1\right)\right)}
\] |
metadata-eval [=>]99.9% | \[ \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + \color{blue}{-1}\right)
\] |
Applied egg-rr99.9%
[Start]99.9% | \[ \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + -1\right)
\] |
|---|---|
fma-udef [=>]99.9% | \[ \frac{6}{\color{blue}{4 \cdot \sqrt{x} + \left(x + 1\right)}} \cdot \left(x + -1\right)
\] |
+-commutative [<=]99.9% | \[ \frac{6}{\color{blue}{\left(x + 1\right) + 4 \cdot \sqrt{x}}} \cdot \left(x + -1\right)
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 7232 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 7364 |
| Alternative 3 | |
|---|---|
| Accuracy | 96.5% |
| Cost | 7236 |
| Alternative 4 | |
|---|---|
| Accuracy | 95.5% |
| Cost | 580 |
| Alternative 5 | |
|---|---|
| Accuracy | 95.5% |
| Cost | 580 |
| Alternative 6 | |
|---|---|
| Accuracy | 95.5% |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Accuracy | 95.5% |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Accuracy | 95.5% |
| Cost | 196 |
| Alternative 9 | |
|---|---|
| Accuracy | 47.7% |
| Cost | 64 |
herbie shell --seed 2023271
(FPCore (x)
:name "Data.Approximate.Numerics:blog from approximate-0.2.2.1"
:precision binary64
:herbie-target
(/ 6.0 (/ (+ (+ x 1.0) (* 4.0 (sqrt x))) (- x 1.0)))
(/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))