| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 704 |
\[x \cdot \left(x \cdot \left(\left(x \cdot x\right) \cdot -0.06388888888888888 + 0.16666666666666666\right)\right)
\]
(FPCore (x) :precision binary64 (/ (- x (sin x)) (tan x)))
(FPCore (x) :precision binary64 (* (* x x) (+ (* (* x x) -0.06388888888888888) 0.16666666666666666)))
double code(double x) {
return (x - sin(x)) / tan(x);
}
double code(double x) {
return (x * x) * (((x * x) * -0.06388888888888888) + 0.16666666666666666);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x - sin(x)) / tan(x)
end function
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) * (((x * x) * (-0.06388888888888888d0)) + 0.16666666666666666d0)
end function
public static double code(double x) {
return (x - Math.sin(x)) / Math.tan(x);
}
public static double code(double x) {
return (x * x) * (((x * x) * -0.06388888888888888) + 0.16666666666666666);
}
def code(x): return (x - math.sin(x)) / math.tan(x)
def code(x): return (x * x) * (((x * x) * -0.06388888888888888) + 0.16666666666666666)
function code(x) return Float64(Float64(x - sin(x)) / tan(x)) end
function code(x) return Float64(Float64(x * x) * Float64(Float64(Float64(x * x) * -0.06388888888888888) + 0.16666666666666666)) end
function tmp = code(x) tmp = (x - sin(x)) / tan(x); end
function tmp = code(x) tmp = (x * x) * (((x * x) * -0.06388888888888888) + 0.16666666666666666); end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[Tan[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(N[(N[(x * x), $MachinePrecision] * -0.06388888888888888), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]
\frac{x - \sin x}{\tan x}
\left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot -0.06388888888888888 + 0.16666666666666666\right)
Results
| Original | 53.4% |
|---|---|
| Target | 98.7% |
| Herbie | 99.3% |
Initial program 53.4%
Taylor expanded in x around 0 99.3%
Simplified99.3%
[Start]99.3 | \[ 0.16666666666666666 \cdot {x}^{2} + -0.06388888888888888 \cdot {x}^{4}
\] |
|---|---|
unpow2 [=>]99.3 | \[ 0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)} + -0.06388888888888888 \cdot {x}^{4}
\] |
fma-def [=>]99.3 | \[ \color{blue}{\mathsf{fma}\left(0.16666666666666666, x \cdot x, -0.06388888888888888 \cdot {x}^{4}\right)}
\] |
Applied egg-rr99.4%
[Start]99.3 | \[ \mathsf{fma}\left(0.16666666666666666, x \cdot x, -0.06388888888888888 \cdot {x}^{4}\right)
\] |
|---|---|
fma-udef [=>]99.3 | \[ \color{blue}{0.16666666666666666 \cdot \left(x \cdot x\right) + -0.06388888888888888 \cdot {x}^{4}}
\] |
associate-*r* [=>]99.4 | \[ \color{blue}{\left(0.16666666666666666 \cdot x\right) \cdot x} + -0.06388888888888888 \cdot {x}^{4}
\] |
Applied egg-rr99.3%
[Start]99.4 | \[ \left(0.16666666666666666 \cdot x\right) \cdot x + -0.06388888888888888 \cdot {x}^{4}
\] |
|---|---|
+-commutative [=>]99.4 | \[ \color{blue}{-0.06388888888888888 \cdot {x}^{4} + \left(0.16666666666666666 \cdot x\right) \cdot x}
\] |
*-commutative [=>]99.4 | \[ \color{blue}{{x}^{4} \cdot -0.06388888888888888} + \left(0.16666666666666666 \cdot x\right) \cdot x
\] |
add-sqr-sqrt [=>]99.4 | \[ \color{blue}{\left(\sqrt{{x}^{4}} \cdot \sqrt{{x}^{4}}\right)} \cdot -0.06388888888888888 + \left(0.16666666666666666 \cdot x\right) \cdot x
\] |
associate-*l* [=>]99.4 | \[ \color{blue}{\sqrt{{x}^{4}} \cdot \left(\sqrt{{x}^{4}} \cdot -0.06388888888888888\right)} + \left(0.16666666666666666 \cdot x\right) \cdot x
\] |
sqrt-pow1 [=>]99.4 | \[ \color{blue}{{x}^{\left(\frac{4}{2}\right)}} \cdot \left(\sqrt{{x}^{4}} \cdot -0.06388888888888888\right) + \left(0.16666666666666666 \cdot x\right) \cdot x
\] |
metadata-eval [=>]99.4 | \[ {x}^{\color{blue}{2}} \cdot \left(\sqrt{{x}^{4}} \cdot -0.06388888888888888\right) + \left(0.16666666666666666 \cdot x\right) \cdot x
\] |
unpow2 [=>]99.4 | \[ \color{blue}{\left(x \cdot x\right)} \cdot \left(\sqrt{{x}^{4}} \cdot -0.06388888888888888\right) + \left(0.16666666666666666 \cdot x\right) \cdot x
\] |
associate-*l* [=>]99.3 | \[ \left(x \cdot x\right) \cdot \left(\sqrt{{x}^{4}} \cdot -0.06388888888888888\right) + \color{blue}{0.16666666666666666 \cdot \left(x \cdot x\right)}
\] |
*-commutative [=>]99.3 | \[ \left(x \cdot x\right) \cdot \left(\sqrt{{x}^{4}} \cdot -0.06388888888888888\right) + \color{blue}{\left(x \cdot x\right) \cdot 0.16666666666666666}
\] |
distribute-lft-out [=>]99.3 | \[ \color{blue}{\left(x \cdot x\right) \cdot \left(\sqrt{{x}^{4}} \cdot -0.06388888888888888 + 0.16666666666666666\right)}
\] |
sqrt-pow1 [=>]99.3 | \[ \left(x \cdot x\right) \cdot \left(\color{blue}{{x}^{\left(\frac{4}{2}\right)}} \cdot -0.06388888888888888 + 0.16666666666666666\right)
\] |
metadata-eval [=>]99.3 | \[ \left(x \cdot x\right) \cdot \left({x}^{\color{blue}{2}} \cdot -0.06388888888888888 + 0.16666666666666666\right)
\] |
unpow2 [=>]99.3 | \[ \left(x \cdot x\right) \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot -0.06388888888888888 + 0.16666666666666666\right)
\] |
*-commutative [=>]99.3 | \[ \left(x \cdot x\right) \cdot \left(\color{blue}{-0.06388888888888888 \cdot \left(x \cdot x\right)} + 0.16666666666666666\right)
\] |
Final simplification99.3%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 704 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 320 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 320 |
herbie shell --seed 2023138
(FPCore (x)
:name "ENA, Section 1.4, Exercise 4a"
:precision binary64
:pre (and (<= -1.0 x) (<= x 1.0))
:herbie-target
(* 0.16666666666666666 (* x x))
(/ (- x (sin x)) (tan x)))