?

Average Error: 30.0 → 0.7
Time: 20.0s
Precision: binary64
Cost: 59464

?

\[\frac{1 - \cos x}{\sin x} \]
\[\begin{array}{l} t_0 := 1 - \cos x\\ t_1 := \frac{t_0}{\sin x}\\ \mathbf{if}\;t_1 \leq -0.011:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\left(0.041666666666666664 \cdot {x}^{3} + 0.00042162698412698415 \cdot {x}^{7}\right) + \left(0.5 \cdot x + 0.004166666666666667 \cdot {x}^{5}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\frac{1}{t_0} - \frac{\cos x}{t_0}\right) \cdot t_0}{\sin x}\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (sin x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- 1.0 (cos x))) (t_1 (/ t_0 (sin x))))
   (if (<= t_1 -0.011)
     t_1
     (if (<= t_1 0.0)
       (+
        (+
         (* 0.041666666666666664 (pow x 3.0))
         (* 0.00042162698412698415 (pow x 7.0)))
        (+ (* 0.5 x) (* 0.004166666666666667 (pow x 5.0))))
       (/ (* (- (/ 1.0 t_0) (/ (cos x) t_0)) t_0) (sin x))))))
double code(double x) {
	return (1.0 - cos(x)) / sin(x);
}
double code(double x) {
	double t_0 = 1.0 - cos(x);
	double t_1 = t_0 / sin(x);
	double tmp;
	if (t_1 <= -0.011) {
		tmp = t_1;
	} else if (t_1 <= 0.0) {
		tmp = ((0.041666666666666664 * pow(x, 3.0)) + (0.00042162698412698415 * pow(x, 7.0))) + ((0.5 * x) + (0.004166666666666667 * pow(x, 5.0)));
	} else {
		tmp = (((1.0 / t_0) - (cos(x) / t_0)) * t_0) / sin(x);
	}
	return tmp;
}
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
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 1.0d0 - cos(x)
    t_1 = t_0 / sin(x)
    if (t_1 <= (-0.011d0)) then
        tmp = t_1
    else if (t_1 <= 0.0d0) then
        tmp = ((0.041666666666666664d0 * (x ** 3.0d0)) + (0.00042162698412698415d0 * (x ** 7.0d0))) + ((0.5d0 * x) + (0.004166666666666667d0 * (x ** 5.0d0)))
    else
        tmp = (((1.0d0 / t_0) - (cos(x) / t_0)) * t_0) / sin(x)
    end if
    code = tmp
end function
public static double code(double x) {
	return (1.0 - Math.cos(x)) / Math.sin(x);
}
public static double code(double x) {
	double t_0 = 1.0 - Math.cos(x);
	double t_1 = t_0 / Math.sin(x);
	double tmp;
	if (t_1 <= -0.011) {
		tmp = t_1;
	} else if (t_1 <= 0.0) {
		tmp = ((0.041666666666666664 * Math.pow(x, 3.0)) + (0.00042162698412698415 * Math.pow(x, 7.0))) + ((0.5 * x) + (0.004166666666666667 * Math.pow(x, 5.0)));
	} else {
		tmp = (((1.0 / t_0) - (Math.cos(x) / t_0)) * t_0) / Math.sin(x);
	}
	return tmp;
}
def code(x):
	return (1.0 - math.cos(x)) / math.sin(x)
def code(x):
	t_0 = 1.0 - math.cos(x)
	t_1 = t_0 / math.sin(x)
	tmp = 0
	if t_1 <= -0.011:
		tmp = t_1
	elif t_1 <= 0.0:
		tmp = ((0.041666666666666664 * math.pow(x, 3.0)) + (0.00042162698412698415 * math.pow(x, 7.0))) + ((0.5 * x) + (0.004166666666666667 * math.pow(x, 5.0)))
	else:
		tmp = (((1.0 / t_0) - (math.cos(x) / t_0)) * t_0) / math.sin(x)
	return tmp
function code(x)
	return Float64(Float64(1.0 - cos(x)) / sin(x))
end
function code(x)
	t_0 = Float64(1.0 - cos(x))
	t_1 = Float64(t_0 / sin(x))
	tmp = 0.0
	if (t_1 <= -0.011)
		tmp = t_1;
	elseif (t_1 <= 0.0)
		tmp = Float64(Float64(Float64(0.041666666666666664 * (x ^ 3.0)) + Float64(0.00042162698412698415 * (x ^ 7.0))) + Float64(Float64(0.5 * x) + Float64(0.004166666666666667 * (x ^ 5.0))));
	else
		tmp = Float64(Float64(Float64(Float64(1.0 / t_0) - Float64(cos(x) / t_0)) * t_0) / sin(x));
	end
	return tmp
end
function tmp = code(x)
	tmp = (1.0 - cos(x)) / sin(x);
end
function tmp_2 = code(x)
	t_0 = 1.0 - cos(x);
	t_1 = t_0 / sin(x);
	tmp = 0.0;
	if (t_1 <= -0.011)
		tmp = t_1;
	elseif (t_1 <= 0.0)
		tmp = ((0.041666666666666664 * (x ^ 3.0)) + (0.00042162698412698415 * (x ^ 7.0))) + ((0.5 * x) + (0.004166666666666667 * (x ^ 5.0)));
	else
		tmp = (((1.0 / t_0) - (cos(x) / t_0)) * t_0) / sin(x);
	end
	tmp_2 = tmp;
end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.011], t$95$1, If[LessEqual[t$95$1, 0.0], N[(N[(N[(0.041666666666666664 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(0.00042162698412698415 * N[Power[x, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.5 * x), $MachinePrecision] + N[(0.004166666666666667 * N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(1.0 / t$95$0), $MachinePrecision] - N[(N[Cos[x], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]]]]]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
t_0 := 1 - \cos x\\
t_1 := \frac{t_0}{\sin x}\\
\mathbf{if}\;t_1 \leq -0.011:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;\left(0.041666666666666664 \cdot {x}^{3} + 0.00042162698412698415 \cdot {x}^{7}\right) + \left(0.5 \cdot x + 0.004166666666666667 \cdot {x}^{5}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{1}{t_0} - \frac{\cos x}{t_0}\right) \cdot t_0}{\sin x}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

  1. Split input into 3 regimes
  2. if (/.f64 (-.f64 1 (cos.f64 x)) (sin.f64 x)) < -0.010999999999999999

    1. Initial program 0.8

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

    if -0.010999999999999999 < (/.f64 (-.f64 1 (cos.f64 x)) (sin.f64 x)) < 0.0

    1. Initial program 60.1

      \[\frac{1 - \cos x}{\sin x} \]
    2. Taylor expanded in x around 0 0.2

      \[\leadsto \color{blue}{0.5 \cdot x + \left(0.004166666666666667 \cdot {x}^{5} + \left(0.00042162698412698415 \cdot {x}^{7} + 0.041666666666666664 \cdot {x}^{3}\right)\right)} \]
    3. Simplified0.2

      \[\leadsto \color{blue}{\left(0.041666666666666664 \cdot {x}^{3} + 0.00042162698412698415 \cdot {x}^{7}\right) + \left(0.5 \cdot x + 0.004166666666666667 \cdot {x}^{5}\right)} \]
      Proof

      [Start]0.2

      \[ 0.5 \cdot x + \left(0.004166666666666667 \cdot {x}^{5} + \left(0.00042162698412698415 \cdot {x}^{7} + 0.041666666666666664 \cdot {x}^{3}\right)\right) \]

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.2

      \[ 0.5 \cdot x + \color{blue}{\left(\left(0.00042162698412698415 \cdot {x}^{7} + 0.041666666666666664 \cdot {x}^{3}\right) + 0.004166666666666667 \cdot {x}^{5}\right)} \]

      rational_best_oopsla_all_46_json_45_simplify-82 [=>]0.2

      \[ \color{blue}{\left(0.00042162698412698415 \cdot {x}^{7} + 0.041666666666666664 \cdot {x}^{3}\right) + \left(0.5 \cdot x + 0.004166666666666667 \cdot {x}^{5}\right)} \]

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.2

      \[ \color{blue}{\left(0.041666666666666664 \cdot {x}^{3} + 0.00042162698412698415 \cdot {x}^{7}\right)} + \left(0.5 \cdot x + 0.004166666666666667 \cdot {x}^{5}\right) \]

    if 0.0 < (/.f64 (-.f64 1 (cos.f64 x)) (sin.f64 x))

    1. Initial program 1.6

      \[\frac{1 - \cos x}{\sin x} \]
    2. Applied egg-rr1.6

      \[\leadsto \frac{\color{blue}{\left(1 - \cos x\right) \cdot \left(\left(1 - \cos x\right) \cdot \frac{1}{1 - \cos x}\right)}}{\sin x} \]
    3. Applied egg-rr1.6

      \[\leadsto \frac{\left(1 - \cos x\right) \cdot \color{blue}{\left(\left(1 - \cos x\right) \cdot \frac{\frac{1}{1 - \cos x}}{1 - \cos x} - \left(\left(1 - \cos x\right) \cdot \frac{\frac{1}{1 - \cos x}}{1 - \cos x}\right) \cdot \cos x\right)}}{\sin x} \]
    4. Taylor expanded in x around inf 1.7

      \[\leadsto \color{blue}{\frac{\left(\frac{1}{1 - \cos x} - \frac{\cos x}{1 - \cos x}\right) \cdot \left(1 - \cos x\right)}{\sin x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \leq -0.011:\\ \;\;\;\;\frac{1 - \cos x}{\sin x}\\ \mathbf{elif}\;\frac{1 - \cos x}{\sin x} \leq 0:\\ \;\;\;\;\left(0.041666666666666664 \cdot {x}^{3} + 0.00042162698412698415 \cdot {x}^{7}\right) + \left(0.5 \cdot x + 0.004166666666666667 \cdot {x}^{5}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\frac{1}{1 - \cos x} - \frac{\cos x}{1 - \cos x}\right) \cdot \left(1 - \cos x\right)}{\sin x}\\ \end{array} \]

Alternatives

Alternative 1
Error0.7
Cost46728
\[\begin{array}{l} t_0 := \frac{1 - \cos x}{\sin x}\\ \mathbf{if}\;t_0 \leq -0.011:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\left(0.041666666666666664 \cdot {x}^{3} + 0.00042162698412698415 \cdot {x}^{7}\right) + \left(0.5 \cdot x + 0.004166666666666667 \cdot {x}^{5}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.7
Cost39496
\[\begin{array}{l} t_0 := \frac{1 - \cos x}{\sin x}\\ \mathbf{if}\;t_0 \leq -0.01:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;0.5 \cdot x + 0.041666666666666664 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error31.5
Cost192
\[0.5 \cdot x \]

Error

Reproduce?

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

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

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