| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 7040 |
\[x \cdot \left(0.16666666666666666 \cdot x\right) + {x}^{4} \cdot -0.06388888888888888
\]
(FPCore (x) :precision binary64 (/ (- x (sin x)) (tan x)))
(FPCore (x) :precision binary64 (+ (* x (* 0.16666666666666666 x)) (* (pow x 4.0) (+ (* (* x x) -0.0007275132275132275) -0.06388888888888888))))
double code(double x) {
return (x - sin(x)) / tan(x);
}
double code(double x) {
return (x * (0.16666666666666666 * x)) + (pow(x, 4.0) * (((x * x) * -0.0007275132275132275) + -0.06388888888888888));
}
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 * (0.16666666666666666d0 * x)) + ((x ** 4.0d0) * (((x * x) * (-0.0007275132275132275d0)) + (-0.06388888888888888d0)))
end function
public static double code(double x) {
return (x - Math.sin(x)) / Math.tan(x);
}
public static double code(double x) {
return (x * (0.16666666666666666 * x)) + (Math.pow(x, 4.0) * (((x * x) * -0.0007275132275132275) + -0.06388888888888888));
}
def code(x): return (x - math.sin(x)) / math.tan(x)
def code(x): return (x * (0.16666666666666666 * x)) + (math.pow(x, 4.0) * (((x * x) * -0.0007275132275132275) + -0.06388888888888888))
function code(x) return Float64(Float64(x - sin(x)) / tan(x)) end
function code(x) return Float64(Float64(x * Float64(0.16666666666666666 * x)) + Float64((x ^ 4.0) * Float64(Float64(Float64(x * x) * -0.0007275132275132275) + -0.06388888888888888))) end
function tmp = code(x) tmp = (x - sin(x)) / tan(x); end
function tmp = code(x) tmp = (x * (0.16666666666666666 * x)) + ((x ^ 4.0) * (((x * x) * -0.0007275132275132275) + -0.06388888888888888)); end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[Tan[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(x * N[(0.16666666666666666 * x), $MachinePrecision]), $MachinePrecision] + N[(N[Power[x, 4.0], $MachinePrecision] * N[(N[(N[(x * x), $MachinePrecision] * -0.0007275132275132275), $MachinePrecision] + -0.06388888888888888), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x - \sin x}{\tan x}
x \cdot \left(0.16666666666666666 \cdot x\right) + {x}^{4} \cdot \left(\left(x \cdot x\right) \cdot -0.0007275132275132275 + -0.06388888888888888\right)
Results
| Original | 53.6% |
|---|---|
| Target | 98.6% |
| Herbie | 99.4% |
Initial program 53.6%
Taylor expanded in x around 0 99.4%
Applied egg-rr99.4%
[Start]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
|---|---|
*-commutative [=>]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left(\color{blue}{{x}^{6} \cdot -0.0007275132275132275} + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
add-cube-cbrt [=>]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left(\color{blue}{\left(\left(\sqrt[3]{{x}^{6}} \cdot \sqrt[3]{{x}^{6}}\right) \cdot \sqrt[3]{{x}^{6}}\right)} \cdot -0.0007275132275132275 + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
associate-*l* [=>]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left(\color{blue}{\left(\sqrt[3]{{x}^{6}} \cdot \sqrt[3]{{x}^{6}}\right) \cdot \left(\sqrt[3]{{x}^{6}} \cdot -0.0007275132275132275\right)} + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
pow2 [=>]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left(\color{blue}{{\left(\sqrt[3]{{x}^{6}}\right)}^{2}} \cdot \left(\sqrt[3]{{x}^{6}} \cdot -0.0007275132275132275\right) + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
metadata-eval [<=]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left({\left(\sqrt[3]{{x}^{\color{blue}{\left(4 + 2\right)}}}\right)}^{2} \cdot \left(\sqrt[3]{{x}^{6}} \cdot -0.0007275132275132275\right) + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
pow-prod-up [<=]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left({\left(\sqrt[3]{\color{blue}{{x}^{4} \cdot {x}^{2}}}\right)}^{2} \cdot \left(\sqrt[3]{{x}^{6}} \cdot -0.0007275132275132275\right) + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
metadata-eval [<=]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left({\left(\sqrt[3]{{x}^{\color{blue}{\left(2 \cdot 2\right)}} \cdot {x}^{2}}\right)}^{2} \cdot \left(\sqrt[3]{{x}^{6}} \cdot -0.0007275132275132275\right) + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
pow-sqr [<=]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left({\left(\sqrt[3]{\color{blue}{\left({x}^{2} \cdot {x}^{2}\right)} \cdot {x}^{2}}\right)}^{2} \cdot \left(\sqrt[3]{{x}^{6}} \cdot -0.0007275132275132275\right) + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
add-cbrt-cube [<=]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left({\color{blue}{\left({x}^{2}\right)}}^{2} \cdot \left(\sqrt[3]{{x}^{6}} \cdot -0.0007275132275132275\right) + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
pow2 [<=]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left(\color{blue}{\left({x}^{2} \cdot {x}^{2}\right)} \cdot \left(\sqrt[3]{{x}^{6}} \cdot -0.0007275132275132275\right) + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
pow-sqr [=>]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left(\color{blue}{{x}^{\left(2 \cdot 2\right)}} \cdot \left(\sqrt[3]{{x}^{6}} \cdot -0.0007275132275132275\right) + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
metadata-eval [=>]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left({x}^{\color{blue}{4}} \cdot \left(\sqrt[3]{{x}^{6}} \cdot -0.0007275132275132275\right) + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
*-commutative [=>]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \left({x}^{4} \cdot \left(\sqrt[3]{{x}^{6}} \cdot -0.0007275132275132275\right) + \color{blue}{{x}^{4} \cdot -0.06388888888888888}\right)
\] |
distribute-lft-out [=>]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + \color{blue}{{x}^{4} \cdot \left(\sqrt[3]{{x}^{6}} \cdot -0.0007275132275132275 + -0.06388888888888888\right)}
\] |
Applied egg-rr53.1%
[Start]99.4 | \[ 0.16666666666666666 \cdot {x}^{2} + {x}^{4} \cdot \left(\left(x \cdot x\right) \cdot -0.0007275132275132275 + -0.06388888888888888\right)
\] |
|---|---|
expm1-log1p-u [=>]99.4 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(0.16666666666666666 \cdot {x}^{2}\right)\right)} + {x}^{4} \cdot \left(\left(x \cdot x\right) \cdot -0.0007275132275132275 + -0.06388888888888888\right)
\] |
expm1-udef [=>]53.1 | \[ \color{blue}{\left(e^{\mathsf{log1p}\left(0.16666666666666666 \cdot {x}^{2}\right)} - 1\right)} + {x}^{4} \cdot \left(\left(x \cdot x\right) \cdot -0.0007275132275132275 + -0.06388888888888888\right)
\] |
unpow2 [=>]53.1 | \[ \left(e^{\mathsf{log1p}\left(0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)}\right)} - 1\right) + {x}^{4} \cdot \left(\left(x \cdot x\right) \cdot -0.0007275132275132275 + -0.06388888888888888\right)
\] |
Simplified99.4%
[Start]53.1 | \[ \left(e^{\mathsf{log1p}\left(0.16666666666666666 \cdot \left(x \cdot x\right)\right)} - 1\right) + {x}^{4} \cdot \left(\left(x \cdot x\right) \cdot -0.0007275132275132275 + -0.06388888888888888\right)
\] |
|---|---|
expm1-def [=>]99.4 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(0.16666666666666666 \cdot \left(x \cdot x\right)\right)\right)} + {x}^{4} \cdot \left(\left(x \cdot x\right) \cdot -0.0007275132275132275 + -0.06388888888888888\right)
\] |
expm1-log1p [=>]99.4 | \[ \color{blue}{0.16666666666666666 \cdot \left(x \cdot x\right)} + {x}^{4} \cdot \left(\left(x \cdot x\right) \cdot -0.0007275132275132275 + -0.06388888888888888\right)
\] |
associate-*r* [=>]99.4 | \[ \color{blue}{\left(0.16666666666666666 \cdot x\right) \cdot x} + {x}^{4} \cdot \left(\left(x \cdot x\right) \cdot -0.0007275132275132275 + -0.06388888888888888\right)
\] |
Final simplification99.4%
| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 7040 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 6976 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 6976 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 6976 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.6% |
| Cost | 320 |
| Alternative 6 | |
|---|---|
| Accuracy | 98.6% |
| Cost | 320 |
| Alternative 7 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 320 |
| Alternative 8 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 320 |
herbie shell --seed 2023131
(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)))