Average Error: 29.7 → 0.5
Time: 8.5s
Precision: binary64
\[\]
\[\]
double code(double x) {
	return ((double) (((double) (1.0 - ((double) cos(x)))) / ((double) sin(x))));
}
double code(double x) {
	double VAR;
	if ((x <= -0.024063447430569557)) {
		VAR = ((double) log(((double) exp(((double) (((double) (1.0 - ((double) cos(x)))) / ((double) sin(x))))))));
	} else {
		double VAR_1;
		if ((x <= 0.01943327581439173)) {
			VAR_1 = ((double) (((double) (0.041666666666666664 * ((double) pow(x, 3.0)))) + ((double) (((double) (0.004166666666666667 * ((double) pow(x, 5.0)))) + ((double) (x * 0.5))))));
		} else {
			VAR_1 = ((double) (((double) exp(((double) cbrt(((double) pow(((double) log(((double) (((double) (((double) pow(1.0, 3.0)) - ((double) pow(((double) cos(x)), 3.0)))) / ((double) (((double) (1.0 * 1.0)) + ((double) (((double) cos(x)) * ((double) (1.0 + ((double) cos(x)))))))))))), 3.0)))))) / ((double) sin(x))));
		}
		VAR = VAR_1;
	}
	return VAR;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original29.7
Target0.0
Herbie0.5
\[\]

Derivation

  1. Split input into 3 regimes
  2. if x < -0.0240634474305695574

    1. Initial program 0.9

      \[\]
    2. Using strategy rm
    3. Applied add-log-exp1.0

      \[\leadsto \]

    if -0.0240634474305695574 < x < 0.019433275814391731

    1. Initial program 59.9

      \[\]
    2. Taylor expanded around 0 0.0

      \[\leadsto \]
    3. Simplified0.0

      \[\leadsto \]

    if 0.019433275814391731 < x

    1. Initial program 0.9

      \[\]
    2. Using strategy rm
    3. Applied add-exp-log0.9

      \[\leadsto \]
    4. Using strategy rm
    5. Applied add-cbrt-cube1.0

      \[\leadsto \]
    6. Simplified1.0

      \[\leadsto \]
    7. Using strategy rm
    8. Applied flip3--1.1

      \[\leadsto \]
    9. Simplified1.1

      \[\leadsto \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \]

Reproduce

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

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

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