tanhf (example 3.4)

?

Percentage Accurate: 53.0% → 100.0%
Time: 5.8s
Precision: binary64
Cost: 6592

?

\[\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));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 - cos(x)) / sin(x)
end function
real(8) function code(x)
    real(8), intent (in) :: x
    code = tan((x / 2.0d0))
end function
public static double code(double x) {
	return (1.0 - Math.cos(x)) / Math.sin(x);
}
public static double code(double x) {
	return Math.tan((x / 2.0));
}
def code(x):
	return (1.0 - math.cos(x)) / math.sin(x)
def code(x):
	return math.tan((x / 2.0))
function code(x)
	return Float64(Float64(1.0 - cos(x)) / sin(x))
end
function code(x)
	return tan(Float64(x / 2.0))
end
function tmp = code(x)
	tmp = (1.0 - cos(x)) / sin(x);
end
function tmp = code(x)
	tmp = tan((x / 2.0));
end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]
\frac{1 - \cos x}{\sin x}
\tan \left(\frac{x}{2}\right)

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original53.0%
Target100.0%
Herbie100.0%
\[\tan \left(\frac{x}{2}\right) \]

Derivation?

  1. Initial program 48.3%

    \[\frac{1 - \cos x}{\sin x} \]
  2. Simplified100.0%

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

    [Start]48.3

    \[ \frac{1 - \cos x}{\sin x} \]

    hang-p0-tan [=>]100.0

    \[ \color{blue}{\tan \left(\frac{x}{2}\right)} \]
  3. Final simplification100.0%

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

Reproduce?

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

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

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