Average Error: 30.1 → 0.0
Time: 8.5s
Precision: binary64
Cost: 6976
\[-0.01 \leq x \land x \leq 0.01\]
\[1 - \cos x \]
\[x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\right) \]
(FPCore (x) :precision binary64 (- 1.0 (cos x)))
(FPCore (x)
 :precision binary64
 (* x (* x (fma x (* x -0.041666666666666664) 0.5))))
double code(double x) {
	return 1.0 - cos(x);
}
double code(double x) {
	return x * (x * fma(x, (x * -0.041666666666666664), 0.5));
}
function code(x)
	return Float64(1.0 - cos(x))
end
function code(x)
	return Float64(x * Float64(x * fma(x, Float64(x * -0.041666666666666664), 0.5)))
end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x * N[(x * N[(x * N[(x * -0.041666666666666664), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
1 - \cos x
x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\right)

Error

Target

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

Derivation

  1. Initial program 30.1

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

    \[\leadsto \color{blue}{\frac{\sin x \cdot \sin x}{1 + \cos x}} \]
  3. Taylor expanded in x around 0 0.0

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

    \[\leadsto \color{blue}{x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\right)} \]
    Proof
    (*.f64 x (*.f64 x (fma.f64 x (*.f64 x -1/24) 1/2))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (*.f64 x -1/24)) 1/2)))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x x) -1/24)) 1/2))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (+.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) -1/24) 1/2))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (*.f64 x (Rewrite=> +-commutative_binary64 (+.f64 1/2 (*.f64 (pow.f64 x 2) -1/24))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x x) (+.f64 1/2 (*.f64 (pow.f64 x 2) -1/24)))): 2 points increase in error, 0 points decrease in error
    (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) (+.f64 1/2 (*.f64 (pow.f64 x 2) -1/24))): 0 points increase in error, 0 points decrease in error
    (*.f64 (pow.f64 x 2) (+.f64 1/2 (Rewrite=> *-commutative_binary64 (*.f64 -1/24 (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 1/2 (pow.f64 x 2)) (*.f64 (*.f64 -1/24 (pow.f64 x 2)) (pow.f64 x 2)))): 2 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/2 (pow.f64 x 2)) (Rewrite<= associate-*r*_binary64 (*.f64 -1/24 (*.f64 (pow.f64 x 2) (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/2 (pow.f64 x 2)) (*.f64 -1/24 (Rewrite=> pow-sqr_binary64 (pow.f64 x (*.f64 2 2))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 1/2 (pow.f64 x 2)) (*.f64 -1/24 (pow.f64 x (Rewrite=> metadata-eval 4)))): 0 points increase in error, 0 points decrease in error
  5. Final simplification0.0

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

Alternatives

Alternative 1
Error0.0
Cost832
\[x \cdot \left(x \cdot \left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) + x \cdot 0.5\right) \]
Alternative 2
Error0.3
Cost320
\[x \cdot \left(x \cdot 0.5\right) \]

Error

Reproduce

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