Average Error: 30.3 → 0.0
Time: 2.1min
Precision: binary64
Cost: 6592
\[\frac{1 - \cos x}{\sin x}\]
\[\tan \left(\frac{x}{2}\right)\]
\frac{1 - \cos x}{\sin x}
\tan \left(\frac{x}{2}\right)
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (sin x)))
(FPCore (x) :precision binary64 (tan (/ x 2.0)))
double code(double x) {
	return (1.0 - cos(x)) / sin(x);
}
double code(double x) {
	return tan(x / 2.0);
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original30.3
Target0.0
Herbie0.0
\[\tan \left(\frac{x}{2}\right)\]

Alternatives

Alternative 1
Error28.7
Cost1346
\[\begin{array}{l} \mathbf{if}\;x \leq -14797.049530444241:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 32653.191470125723:\\ \;\;\;\;x \cdot 0.5 + \left(x \cdot x\right) \cdot \left(x \cdot 0.041666666666666664\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]
Alternative 2
Error29.9
Cost897
\[\begin{array}{l} \mathbf{if}\;x \leq 32653.191470125723:\\ \;\;\;\;\frac{1}{\frac{2}{x} - x \cdot 0.16666666666666666}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]
Alternative 3
Error29.0
Cost834
\[\begin{array}{l} \mathbf{if}\;x \leq -9.870414528139964 \cdot 10^{+33}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 186655444905042.75:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]
Alternative 4
Error59.5
Cost64
\[-1\]
Alternative 5
Error61.3
Cost64
\[0\]

Error

Derivation

  1. Initial program 30.3

    \[\frac{1 - \cos x}{\sin x}\]
  2. Using strategy rm
  3. Applied *-un-lft-identity_binary64_76030.3

    \[\leadsto \frac{1 - \cos x}{\color{blue}{1 \cdot \sin x}}\]
  4. Applied *-un-lft-identity_binary64_76030.3

    \[\leadsto \frac{\color{blue}{1 \cdot \left(1 - \cos x\right)}}{1 \cdot \sin x}\]
  5. Applied times-frac_binary64_76630.3

    \[\leadsto \color{blue}{\frac{1}{1} \cdot \frac{1 - \cos x}{\sin x}}\]
  6. Simplified30.3

    \[\leadsto \color{blue}{1} \cdot \frac{1 - \cos x}{\sin x}\]
  7. Simplified0.0

    \[\leadsto 1 \cdot \color{blue}{\tan \left(\frac{x}{2}\right)}\]
  8. Simplified0.0

    \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)}\]
  9. Final simplification0.0

    \[\leadsto \tan \left(\frac{x}{2}\right)\]

Reproduce

herbie shell --seed 2021014 
(FPCore (x)
  :name "tanhf (example 3.4)"
  :precision binary64
  :herbie-expected 2

  :herbie-target
  (tan (/ x 2.0))

  (/ (- 1.0 (cos x)) (sin x)))