| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 7232 |
(FPCore (x) :precision binary64 (/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))
(FPCore (x) :precision binary64 (* (/ (- 1.0 x) (+ (* (sqrt x) -4.0) (- -1.0 x))) 6.0))
double code(double x) {
return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x)));
}
double code(double x) {
return ((1.0 - x) / ((sqrt(x) * -4.0) + (-1.0 - x))) * 6.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 = ((1.0d0 - x) / ((sqrt(x) * (-4.0d0)) + ((-1.0d0) - x))) * 6.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 ((1.0 - x) / ((Math.sqrt(x) * -4.0) + (-1.0 - x))) * 6.0;
}
def code(x): return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * math.sqrt(x)))
def code(x): return ((1.0 - x) / ((math.sqrt(x) * -4.0) + (-1.0 - x))) * 6.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(Float64(1.0 - x) / Float64(Float64(sqrt(x) * -4.0) + Float64(-1.0 - x))) * 6.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 = ((1.0 - x) / ((sqrt(x) * -4.0) + (-1.0 - x))) * 6.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[(N[(1.0 - x), $MachinePrecision] / N[(N[(N[Sqrt[x], $MachinePrecision] * -4.0), $MachinePrecision] + N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 6.0), $MachinePrecision]
\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
\frac{1 - x}{\sqrt{x} \cdot -4 + \left(-1 - x\right)} \cdot 6
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.7%
[Start]99.9 | \[ \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)} \cdot \left(x + -1\right)
\] |
|---|---|
*-commutative [=>]99.9 | \[ \color{blue}{\left(x + -1\right) \cdot \frac{6}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}}
\] |
clear-num [=>]99.7 | \[ \left(x + -1\right) \cdot \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}{6}}}
\] |
un-div-inv [=>]99.9 | \[ \color{blue}{\frac{x + -1}{\frac{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right)}{6}}}
\] |
div-inv [=>]99.7 | \[ \frac{x + -1}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x + 1\right) \cdot \frac{1}{6}}}
\] |
fma-udef [=>]99.7 | \[ \frac{x + -1}{\color{blue}{\left(4 \cdot \sqrt{x} + \left(x + 1\right)\right)} \cdot \frac{1}{6}}
\] |
associate-+r+ [=>]99.7 | \[ \frac{x + -1}{\color{blue}{\left(\left(4 \cdot \sqrt{x} + x\right) + 1\right)} \cdot \frac{1}{6}}
\] |
fma-def [=>]99.7 | \[ \frac{x + -1}{\left(\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right)} + 1\right) \cdot \frac{1}{6}}
\] |
metadata-eval [=>]99.7 | \[ \frac{x + -1}{\left(\mathsf{fma}\left(4, \sqrt{x}, x\right) + 1\right) \cdot \color{blue}{0.16666666666666666}}
\] |
Simplified99.9%
[Start]99.7 | \[ \frac{x + -1}{\left(\mathsf{fma}\left(4, \sqrt{x}, x\right) + 1\right) \cdot 0.16666666666666666}
\] |
|---|---|
/-rgt-identity [<=]99.7 | \[ \frac{x + -1}{\color{blue}{\frac{\left(\mathsf{fma}\left(4, \sqrt{x}, x\right) + 1\right) \cdot 0.16666666666666666}{1}}}
\] |
associate-/l* [=>]99.9 | \[ \frac{x + -1}{\color{blue}{\frac{\mathsf{fma}\left(4, \sqrt{x}, x\right) + 1}{\frac{1}{0.16666666666666666}}}}
\] |
metadata-eval [=>]99.9 | \[ \frac{x + -1}{\frac{\mathsf{fma}\left(4, \sqrt{x}, x\right) + 1}{\color{blue}{6}}}
\] |
associate-/r/ [=>]99.9 | \[ \color{blue}{\frac{x + -1}{\mathsf{fma}\left(4, \sqrt{x}, x\right) + 1} \cdot 6}
\] |
*-lft-identity [<=]99.9 | \[ \frac{x + -1}{\color{blue}{1 \cdot \left(\mathsf{fma}\left(4, \sqrt{x}, x\right) + 1\right)}} \cdot 6
\] |
*-lft-identity [=>]99.9 | \[ \frac{x + -1}{\color{blue}{\mathsf{fma}\left(4, \sqrt{x}, x\right) + 1}} \cdot 6
\] |
fma-udef [=>]99.9 | \[ \frac{x + -1}{\color{blue}{\left(4 \cdot \sqrt{x} + x\right)} + 1} \cdot 6
\] |
+-commutative [=>]99.9 | \[ \frac{x + -1}{\color{blue}{\left(x + 4 \cdot \sqrt{x}\right)} + 1} \cdot 6
\] |
associate-+r+ [<=]99.9 | \[ \frac{x + -1}{\color{blue}{x + \left(4 \cdot \sqrt{x} + 1\right)}} \cdot 6
\] |
fma-udef [<=]99.9 | \[ \frac{x + -1}{x + \color{blue}{\mathsf{fma}\left(4, \sqrt{x}, 1\right)}} \cdot 6
\] |
Applied egg-rr99.8%
[Start]99.9 | \[ \frac{x + -1}{x + \mathsf{fma}\left(4, \sqrt{x}, 1\right)} \cdot 6
\] |
|---|---|
frac-2neg [=>]99.9 | \[ \color{blue}{\frac{-\left(x + -1\right)}{-\left(x + \mathsf{fma}\left(4, \sqrt{x}, 1\right)\right)}} \cdot 6
\] |
div-inv [=>]99.8 | \[ \color{blue}{\left(\left(-\left(x + -1\right)\right) \cdot \frac{1}{-\left(x + \mathsf{fma}\left(4, \sqrt{x}, 1\right)\right)}\right)} \cdot 6
\] |
+-commutative [=>]99.8 | \[ \left(\left(-\color{blue}{\left(-1 + x\right)}\right) \cdot \frac{1}{-\left(x + \mathsf{fma}\left(4, \sqrt{x}, 1\right)\right)}\right) \cdot 6
\] |
distribute-neg-in [=>]99.8 | \[ \left(\color{blue}{\left(\left(--1\right) + \left(-x\right)\right)} \cdot \frac{1}{-\left(x + \mathsf{fma}\left(4, \sqrt{x}, 1\right)\right)}\right) \cdot 6
\] |
metadata-eval [=>]99.8 | \[ \left(\left(\color{blue}{1} + \left(-x\right)\right) \cdot \frac{1}{-\left(x + \mathsf{fma}\left(4, \sqrt{x}, 1\right)\right)}\right) \cdot 6
\] |
Simplified99.9%
[Start]99.8 | \[ \left(\left(1 + \left(-x\right)\right) \cdot \frac{1}{-\left(x + \mathsf{fma}\left(4, \sqrt{x}, 1\right)\right)}\right) \cdot 6
\] |
|---|---|
associate-*r/ [=>]99.9 | \[ \color{blue}{\frac{\left(1 + \left(-x\right)\right) \cdot 1}{-\left(x + \mathsf{fma}\left(4, \sqrt{x}, 1\right)\right)}} \cdot 6
\] |
*-rgt-identity [=>]99.9 | \[ \frac{\color{blue}{1 + \left(-x\right)}}{-\left(x + \mathsf{fma}\left(4, \sqrt{x}, 1\right)\right)} \cdot 6
\] |
unsub-neg [=>]99.9 | \[ \frac{\color{blue}{1 - x}}{-\left(x + \mathsf{fma}\left(4, \sqrt{x}, 1\right)\right)} \cdot 6
\] |
+-commutative [=>]99.9 | \[ \frac{1 - x}{-\color{blue}{\left(\mathsf{fma}\left(4, \sqrt{x}, 1\right) + x\right)}} \cdot 6
\] |
distribute-neg-in [=>]99.9 | \[ \frac{1 - x}{\color{blue}{\left(-\mathsf{fma}\left(4, \sqrt{x}, 1\right)\right) + \left(-x\right)}} \cdot 6
\] |
fma-def [<=]99.9 | \[ \frac{1 - x}{\left(-\color{blue}{\left(4 \cdot \sqrt{x} + 1\right)}\right) + \left(-x\right)} \cdot 6
\] |
distribute-neg-in [=>]99.9 | \[ \frac{1 - x}{\color{blue}{\left(\left(-4 \cdot \sqrt{x}\right) + \left(-1\right)\right)} + \left(-x\right)} \cdot 6
\] |
metadata-eval [=>]99.9 | \[ \frac{1 - x}{\left(\left(-4 \cdot \sqrt{x}\right) + \color{blue}{-1}\right) + \left(-x\right)} \cdot 6
\] |
associate-+l+ [=>]99.9 | \[ \frac{1 - x}{\color{blue}{\left(-4 \cdot \sqrt{x}\right) + \left(-1 + \left(-x\right)\right)}} \cdot 6
\] |
*-commutative [=>]99.9 | \[ \frac{1 - x}{\left(-\color{blue}{\sqrt{x} \cdot 4}\right) + \left(-1 + \left(-x\right)\right)} \cdot 6
\] |
distribute-rgt-neg-in [=>]99.9 | \[ \frac{1 - x}{\color{blue}{\sqrt{x} \cdot \left(-4\right)} + \left(-1 + \left(-x\right)\right)} \cdot 6
\] |
metadata-eval [=>]99.9 | \[ \frac{1 - x}{\sqrt{x} \cdot \color{blue}{-4} + \left(-1 + \left(-x\right)\right)} \cdot 6
\] |
sub-neg [<=]99.9 | \[ \frac{1 - x}{\sqrt{x} \cdot -4 + \color{blue}{\left(-1 - x\right)}} \cdot 6
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 7232 |
| Alternative 2 | |
|---|---|
| Accuracy | 95.3% |
| Cost | 576 |
| Alternative 3 | |
|---|---|
| Accuracy | 95.3% |
| Cost | 452 |
| Alternative 4 | |
|---|---|
| Accuracy | 95.3% |
| Cost | 452 |
| Alternative 5 | |
|---|---|
| Accuracy | 95.3% |
| Cost | 452 |
| Alternative 6 | |
|---|---|
| Accuracy | 95.3% |
| Cost | 196 |
| Alternative 7 | |
|---|---|
| Accuracy | 49.2% |
| Cost | 64 |
herbie shell --seed 2023160
(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)))))