ENA, Section 1.4, Mentioned, A

?

Percentage Accurate: 53.5% → 100.0%
Time: 5.0s
Precision: binary64
Cost: 13120

?

\[-0.01 \leq x \land x \leq 0.01\]
\[1 - \cos x \]
\[\sin x \cdot \tan \left(\frac{x}{2}\right) \]
(FPCore (x) :precision binary64 (- 1.0 (cos x)))
(FPCore (x) :precision binary64 (* (sin x) (tan (/ x 2.0))))
double code(double x) {
	return 1.0 - cos(x);
}
double code(double x) {
	return sin(x) * tan((x / 2.0));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 - cos(x)
end function
real(8) function code(x)
    real(8), intent (in) :: x
    code = sin(x) * tan((x / 2.0d0))
end function
public static double code(double x) {
	return 1.0 - Math.cos(x);
}
public static double code(double x) {
	return Math.sin(x) * Math.tan((x / 2.0));
}
def code(x):
	return 1.0 - math.cos(x)
def code(x):
	return math.sin(x) * math.tan((x / 2.0))
function code(x)
	return Float64(1.0 - cos(x))
end
function code(x)
	return Float64(sin(x) * tan(Float64(x / 2.0)))
end
function tmp = code(x)
	tmp = 1.0 - cos(x);
end
function tmp = code(x)
	tmp = sin(x) * tan((x / 2.0));
end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[Sin[x], $MachinePrecision] * N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
1 - \cos x
\sin x \cdot \tan \left(\frac{x}{2}\right)

Local Percentage Accuracy vs ?

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.

Herbie found 4 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

  1. Initial program 52.3%

    \[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]52.3%

    \[ 1 - \cos x \]

    flip-- [=>]52.3%

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

    div-inv [=>]52.3%

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

    metadata-eval [=>]52.3%

    \[ \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. Final simplification100.0%

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

Alternatives

Alternative 1
Accuracy100.0%
Cost13120
\[\sin x \cdot \tan \left(\frac{x}{2}\right) \]
Alternative 2
Accuracy100.0%
Cost6976
\[x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\right) \]
Alternative 3
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 4
Accuracy99.6%
Cost320
\[0.5 \cdot \left(x \cdot x\right) \]

Reproduce?

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