?

Average Accuracy: 52.5% → 100.0%
Time: 6.1s
Precision: binary64
Cost: 13312

?

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

Error?

Target

Original52.5%
Target100.0%
Herbie100.0%
\[\frac{\sin x \cdot \sin x}{1 + \cos x} \]

Derivation?

  1. Initial program 57.2%

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

    \[\leadsto \color{blue}{\left(\sin x \cdot \sin x\right) \cdot \frac{1}{1 + \cos x}} \]
    Step-by-step derivation

    [Start]57.2

    \[ 1 - \cos x \]

    flip-- [=>]57.2

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

    div-inv [=>]57.2

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

    metadata-eval [=>]57.2

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

    1-sub-cos [=>]100.0

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

    \[\leadsto \color{blue}{\sin x \cdot \tan \left(\frac{x}{2}\right)} \]
    Step-by-step derivation

    [Start]100.0

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

    associate-*r/ [=>]100.0

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

    *-rgt-identity [=>]100.0

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

    associate-*r/ [<=]100.0

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

    hang-0p-tan [=>]100.0

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

    \[\leadsto \color{blue}{0.5 \cdot {x}^{2} + -0.041666666666666664 \cdot {x}^{4}} \]
  5. Simplified100.0%

    \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)} \]
    Step-by-step derivation

    [Start]100.0

    \[ 0.5 \cdot {x}^{2} + -0.041666666666666664 \cdot {x}^{4} \]

    +-commutative [=>]100.0

    \[ \color{blue}{-0.041666666666666664 \cdot {x}^{4} + 0.5 \cdot {x}^{2}} \]

    metadata-eval [<=]100.0

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

    pow-sqr [<=]100.0

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

    associate-*r* [=>]100.0

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

    distribute-rgt-out [=>]100.0

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

    *-commutative [<=]100.0

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

    unpow2 [=>]100.0

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

    unpow2 [=>]100.0

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

    associate-*l* [=>]100.0

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

    fma-def [=>]100.0

    \[ \left(x \cdot x\right) \cdot \color{blue}{\mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)} \]
  6. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) \cdot \left(x \cdot x\right) + 0.5 \cdot \left(x \cdot x\right)} \]
    Step-by-step derivation

    [Start]100.0

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

    fma-udef [=>]100.0

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

    distribute-rgt-in [=>]100.0

    \[ \color{blue}{\left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) \cdot \left(x \cdot x\right) + 0.5 \cdot \left(x \cdot x\right)} \]
  7. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot 0.5, x, {x}^{4} \cdot -0.041666666666666664\right)} \]
    Step-by-step derivation

    [Start]100.0

    \[ \left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) \cdot \left(x \cdot x\right) + 0.5 \cdot \left(x \cdot x\right) \]

    +-commutative [=>]100.0

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

    associate-*r* [=>]100.0

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

    fma-def [=>]100.0

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

    *-commutative [=>]100.0

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

    *-commutative [=>]100.0

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

    associate-*r* [=>]100.0

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

    associate-*r* [=>]100.0

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

    pow2 [=>]100.0

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

    pow2 [=>]100.0

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

    pow-prod-up [=>]100.0

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

    metadata-eval [=>]100.0

    \[ \mathsf{fma}\left(x \cdot 0.5, x, {x}^{\color{blue}{4}} \cdot -0.041666666666666664\right) \]
  8. Final simplification100.0%

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

Alternatives

Alternative 1
Accuracy99.9%
Cost960
\[\left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) \cdot \left(x \cdot x\right) + 0.5 \cdot \left(x \cdot x\right) \]
Alternative 2
Accuracy99.6%
Cost320
\[0.5 \cdot \left(x \cdot x\right) \]
Alternative 3
Accuracy99.6%
Cost320
\[x \cdot \left(x \cdot 0.5\right) \]

Error

Reproduce?

herbie shell --seed 2023157 
(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)))