?

Average Error: 30.8 → 0.0
Time: 7.8s
Precision: binary64
Cost: 19968

?

\[-0.01 \leq x \land x \leq 0.01\]
\[1 - \cos x \]
\[\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right), 0.001388888888888889 \cdot {x}^{6}\right) \]
(FPCore (x) :precision binary64 (- 1.0 (cos x)))
(FPCore (x)
 :precision binary64
 (fma
  (* x x)
  (fma x (* x -0.041666666666666664) 0.5)
  (* 0.001388888888888889 (pow x 6.0))))
double code(double x) {
	return 1.0 - cos(x);
}
double code(double x) {
	return fma((x * x), fma(x, (x * -0.041666666666666664), 0.5), (0.001388888888888889 * pow(x, 6.0)));
}
function code(x)
	return Float64(1.0 - cos(x))
end
function code(x)
	return fma(Float64(x * x), fma(x, Float64(x * -0.041666666666666664), 0.5), Float64(0.001388888888888889 * (x ^ 6.0)))
end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * -0.041666666666666664), $MachinePrecision] + 0.5), $MachinePrecision] + N[(0.001388888888888889 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
1 - \cos x
\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right), 0.001388888888888889 \cdot {x}^{6}\right)

Error?

Target

Original30.8
Target0.0
Herbie0.0
\[\frac{\sin x \cdot \sin x}{1 + \cos x} \]

Derivation?

  1. Initial program 30.8

    \[1 - \cos x \]
  2. Applied egg-rr0.0

    \[\leadsto \color{blue}{\left(\sin x \cdot \sin x\right) \cdot \frac{1}{1 + \cos x}} \]
  3. Simplified0.0

    \[\leadsto \color{blue}{\sin x \cdot \tan \left(\frac{x}{2}\right)} \]
    Proof

    [Start]0.0

    \[ \left(\sin x \cdot \sin x\right) \cdot \frac{1}{1 + \cos x} \]

    associate-*r/ [=>]0.0

    \[ \color{blue}{\frac{\left(\sin x \cdot \sin x\right) \cdot 1}{1 + \cos x}} \]

    *-rgt-identity [=>]0.0

    \[ \frac{\color{blue}{\sin x \cdot \sin x}}{1 + \cos x} \]

    associate-*r/ [<=]0.0

    \[ \color{blue}{\sin x \cdot \frac{\sin x}{1 + \cos x}} \]

    hang-0p-tan [=>]0.0

    \[ \sin x \cdot \color{blue}{\tan \left(\frac{x}{2}\right)} \]
  4. Taylor expanded in x around 0 0.0

    \[\leadsto \color{blue}{0.5 \cdot {x}^{2} + \left(-0.041666666666666664 \cdot {x}^{4} + 0.001388888888888889 \cdot {x}^{6}\right)} \]
  5. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right), 0.001388888888888889 \cdot {x}^{6}\right)} \]
    Proof

    [Start]0.0

    \[ 0.5 \cdot {x}^{2} + \left(-0.041666666666666664 \cdot {x}^{4} + 0.001388888888888889 \cdot {x}^{6}\right) \]

    associate-+r+ [=>]0.0

    \[ \color{blue}{\left(0.5 \cdot {x}^{2} + -0.041666666666666664 \cdot {x}^{4}\right) + 0.001388888888888889 \cdot {x}^{6}} \]

    *-commutative [=>]0.0

    \[ \left(\color{blue}{{x}^{2} \cdot 0.5} + -0.041666666666666664 \cdot {x}^{4}\right) + 0.001388888888888889 \cdot {x}^{6} \]

    *-commutative [=>]0.0

    \[ \left({x}^{2} \cdot 0.5 + \color{blue}{{x}^{4} \cdot -0.041666666666666664}\right) + 0.001388888888888889 \cdot {x}^{6} \]

    metadata-eval [<=]0.0

    \[ \left({x}^{2} \cdot 0.5 + {x}^{\color{blue}{\left(2 \cdot 2\right)}} \cdot -0.041666666666666664\right) + 0.001388888888888889 \cdot {x}^{6} \]

    pow-sqr [<=]0.0

    \[ \left({x}^{2} \cdot 0.5 + \color{blue}{\left({x}^{2} \cdot {x}^{2}\right)} \cdot -0.041666666666666664\right) + 0.001388888888888889 \cdot {x}^{6} \]

    associate-*l* [=>]0.0

    \[ \left({x}^{2} \cdot 0.5 + \color{blue}{{x}^{2} \cdot \left({x}^{2} \cdot -0.041666666666666664\right)}\right) + 0.001388888888888889 \cdot {x}^{6} \]

    distribute-lft-out [=>]0.0

    \[ \color{blue}{{x}^{2} \cdot \left(0.5 + {x}^{2} \cdot -0.041666666666666664\right)} + 0.001388888888888889 \cdot {x}^{6} \]

    fma-def [=>]0.0

    \[ \color{blue}{\mathsf{fma}\left({x}^{2}, 0.5 + {x}^{2} \cdot -0.041666666666666664, 0.001388888888888889 \cdot {x}^{6}\right)} \]

    unpow2 [=>]0.0

    \[ \mathsf{fma}\left(\color{blue}{x \cdot x}, 0.5 + {x}^{2} \cdot -0.041666666666666664, 0.001388888888888889 \cdot {x}^{6}\right) \]

    +-commutative [=>]0.0

    \[ \mathsf{fma}\left(x \cdot x, \color{blue}{{x}^{2} \cdot -0.041666666666666664 + 0.5}, 0.001388888888888889 \cdot {x}^{6}\right) \]

    unpow2 [=>]0.0

    \[ \mathsf{fma}\left(x \cdot x, \color{blue}{\left(x \cdot x\right)} \cdot -0.041666666666666664 + 0.5, 0.001388888888888889 \cdot {x}^{6}\right) \]

    associate-*l* [=>]0.0

    \[ \mathsf{fma}\left(x \cdot x, \color{blue}{x \cdot \left(x \cdot -0.041666666666666664\right)} + 0.5, 0.001388888888888889 \cdot {x}^{6}\right) \]

    fma-def [=>]0.0

    \[ \mathsf{fma}\left(x \cdot x, \color{blue}{\mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)}, 0.001388888888888889 \cdot {x}^{6}\right) \]
  6. Final simplification0.0

    \[\leadsto \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right), 0.001388888888888889 \cdot {x}^{6}\right) \]

Alternatives

Alternative 1
Error0.0
Cost7680
\[\left(0.001388888888888889 \cdot {x}^{6} + \left(x \cdot x\right) \cdot \left(x \cdot \left(x \cdot -0.041666666666666664\right)\right)\right) + \left(x \cdot x\right) \cdot 0.5 \]
Alternative 2
Error0.0
Cost832
\[x \cdot \left(x \cdot \left(\left(x \cdot x\right) \cdot -0.041666666666666664\right) + x \cdot 0.5\right) \]
Alternative 3
Error0.3
Cost320
\[\left(x \cdot x\right) \cdot 0.5 \]

Error

Reproduce?

herbie shell --seed 2023027 
(FPCore (x)
  :name "ENA, Section 1.4, Mentioned, A"
  :precision binary64
  :pre (and (<= -0.01 x) (<= x 0.01))

  :herbie-target
  (/ (* (sin x) (sin x)) (+ 1.0 (cos x)))

  (- 1.0 (cos x)))