tanhf (example 3.4)

Percentage Accurate: 53.2% → 100.0%
Time: 9.3s
Alternatives: 9
Speedup: 2.0×

Specification

?
\[\begin{array}{l} \\ \frac{1 - \cos x}{\sin x} \end{array} \]
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (sin x)))
double code(double x) {
	return (1.0 - cos(x)) / sin(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 - cos(x)) / sin(x)
end function
public static double code(double x) {
	return (1.0 - Math.cos(x)) / Math.sin(x);
}
def code(x):
	return (1.0 - math.cos(x)) / math.sin(x)
function code(x)
	return Float64(Float64(1.0 - cos(x)) / sin(x))
end
function tmp = code(x)
	tmp = (1.0 - cos(x)) / sin(x);
end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1 - \cos x}{\sin x}
\end{array}

Sampling outcomes in binary64 precision:

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.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
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.

Initial Program: 53.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1 - \cos x}{\sin x} \end{array} \]
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (sin x)))
double code(double x) {
	return (1.0 - cos(x)) / sin(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 - cos(x)) / sin(x)
end function
public static double code(double x) {
	return (1.0 - Math.cos(x)) / Math.sin(x);
}
def code(x):
	return (1.0 - math.cos(x)) / math.sin(x)
function code(x)
	return Float64(Float64(1.0 - cos(x)) / sin(x))
end
function tmp = code(x)
	tmp = (1.0 - cos(x)) / sin(x);
end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1 - \cos x}{\sin x}
\end{array}

Alternative 1: 100.0% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \tan \left(\frac{x}{2}\right) \end{array} \]
(FPCore (x) :precision binary64 (tan (/ x 2.0)))
double code(double x) {
	return tan((x / 2.0));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = tan((x / 2.0d0))
end function
public static double code(double x) {
	return Math.tan((x / 2.0));
}
def code(x):
	return math.tan((x / 2.0))
function code(x)
	return tan(Float64(x / 2.0))
end
function tmp = code(x)
	tmp = tan((x / 2.0));
end
code[x_] := N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\tan \left(\frac{x}{2}\right)
\end{array}
Derivation
  1. Initial program 54.1%

    \[\frac{1 - \cos x}{\sin x} \]
  2. Step-by-step derivation
    1. hang-p0-tanN/A

      \[\leadsto \tan \left(\frac{x}{2}\right) \]
    2. tan-lowering-tan.f64N/A

      \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
    3. /-lowering-/.f64100.0%

      \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
  4. Add Preprocessing
  5. Add Preprocessing

Alternative 2: 52.1% accurate, 4.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2.35:\\ \;\;\;\;\frac{x \cdot \left(0.25 - \left(x \cdot \left(x \cdot \left(x \cdot x\right)\right)\right) \cdot \left(0.001736111111111111 + x \cdot \left(x \cdot 0.00034722222222222224\right)\right)\right)}{0.5 - x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 2.35)
   (/
    (*
     x
     (-
      0.25
      (*
       (* x (* x (* x x)))
       (+ 0.001736111111111111 (* x (* x 0.00034722222222222224))))))
    (-
     0.5
     (*
      x
      (*
       x
       (+
        0.041666666666666664
        (*
         (* x x)
         (+ 0.004166666666666667 (* (* x x) 0.00042162698412698415))))))))
   1.0))
double code(double x) {
	double tmp;
	if (x <= 2.35) {
		tmp = (x * (0.25 - ((x * (x * (x * x))) * (0.001736111111111111 + (x * (x * 0.00034722222222222224)))))) / (0.5 - (x * (x * (0.041666666666666664 + ((x * x) * (0.004166666666666667 + ((x * x) * 0.00042162698412698415)))))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 2.35d0) then
        tmp = (x * (0.25d0 - ((x * (x * (x * x))) * (0.001736111111111111d0 + (x * (x * 0.00034722222222222224d0)))))) / (0.5d0 - (x * (x * (0.041666666666666664d0 + ((x * x) * (0.004166666666666667d0 + ((x * x) * 0.00042162698412698415d0)))))))
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 2.35) {
		tmp = (x * (0.25 - ((x * (x * (x * x))) * (0.001736111111111111 + (x * (x * 0.00034722222222222224)))))) / (0.5 - (x * (x * (0.041666666666666664 + ((x * x) * (0.004166666666666667 + ((x * x) * 0.00042162698412698415)))))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 2.35:
		tmp = (x * (0.25 - ((x * (x * (x * x))) * (0.001736111111111111 + (x * (x * 0.00034722222222222224)))))) / (0.5 - (x * (x * (0.041666666666666664 + ((x * x) * (0.004166666666666667 + ((x * x) * 0.00042162698412698415)))))))
	else:
		tmp = 1.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 2.35)
		tmp = Float64(Float64(x * Float64(0.25 - Float64(Float64(x * Float64(x * Float64(x * x))) * Float64(0.001736111111111111 + Float64(x * Float64(x * 0.00034722222222222224)))))) / Float64(0.5 - Float64(x * Float64(x * Float64(0.041666666666666664 + Float64(Float64(x * x) * Float64(0.004166666666666667 + Float64(Float64(x * x) * 0.00042162698412698415))))))));
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 2.35)
		tmp = (x * (0.25 - ((x * (x * (x * x))) * (0.001736111111111111 + (x * (x * 0.00034722222222222224)))))) / (0.5 - (x * (x * (0.041666666666666664 + ((x * x) * (0.004166666666666667 + ((x * x) * 0.00042162698412698415)))))));
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 2.35], N[(N[(x * N[(0.25 - N[(N[(x * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.001736111111111111 + N[(x * N[(x * 0.00034722222222222224), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(0.5 - N[(x * N[(x * N[(0.041666666666666664 + N[(N[(x * x), $MachinePrecision] * N[(0.004166666666666667 + N[(N[(x * x), $MachinePrecision] * 0.00042162698412698415), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.35:\\
\;\;\;\;\frac{x \cdot \left(0.25 - \left(x \cdot \left(x \cdot \left(x \cdot x\right)\right)\right) \cdot \left(0.001736111111111111 + x \cdot \left(x \cdot 0.00034722222222222224\right)\right)\right)}{0.5 - x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2.35000000000000009

    1. Initial program 38.9%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{24} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)}\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\left(\frac{1}{24} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)}\right)\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\left(x \cdot x\right), \left(\color{blue}{\frac{1}{24}} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\frac{1}{24}} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)}\right)\right)\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)}\right)\right)\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left(x \cdot x\right), \left(\color{blue}{\frac{1}{240}} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\frac{1}{240}} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)\right)\right)\right) \]
      10. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \color{blue}{\left(\frac{17}{40320} \cdot {x}^{2}\right)}\right)\right)\right)\right)\right)\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \left({x}^{2} \cdot \color{blue}{\frac{17}{40320}}\right)\right)\right)\right)\right)\right)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\frac{17}{40320}}\right)\right)\right)\right)\right)\right)\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\left(x \cdot x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right) \]
      14. *-lowering-*.f6465.6%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right) \]
    7. Simplified65.6%

      \[\leadsto \color{blue}{x \cdot \left(0.5 + \left(x \cdot x\right) \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)} \]
    8. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\frac{1}{2} + \left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right) \cdot \color{blue}{x} \]
      2. flip-+N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{1}{2} - \left(\left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right) \cdot \left(\left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right)}{\frac{1}{2} - \left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)} \cdot x \]
      3. associate-*l/N/A

        \[\leadsto \frac{\left(\frac{1}{2} \cdot \frac{1}{2} - \left(\left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right) \cdot \left(\left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right)\right) \cdot x}{\color{blue}{\frac{1}{2} - \left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)}} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\left(\frac{1}{2} \cdot \frac{1}{2} - \left(\left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right) \cdot \left(\left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right)\right) \cdot x\right), \color{blue}{\left(\frac{1}{2} - \left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right)}\right) \]
    9. Applied egg-rr65.0%

      \[\leadsto \color{blue}{\frac{\left(0.25 - \left(x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)\right)\right) \cdot x}{0.5 - x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)}} \]
    10. Taylor expanded in x around 0

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \color{blue}{\left({x}^{4} \cdot \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)}\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
    11. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\left({x}^{4}\right), \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      2. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\left({x}^{\left(2 \cdot 2\right)}\right), \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      3. pow-sqrN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\left({x}^{2} \cdot {x}^{2}\right), \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\left(\left(x \cdot x\right) \cdot {x}^{2}\right), \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      5. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\left(x \cdot \left(x \cdot {x}^{2}\right)\right), \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\left(x \cdot \left(x \cdot \left(x \cdot x\right)\right)\right), \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      7. cube-multN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\left(x \cdot {x}^{3}\right), \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \left({x}^{3}\right)\right), \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      9. cube-multN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \left(x \cdot \left(x \cdot x\right)\right)\right), \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      10. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \left(x \cdot {x}^{2}\right)\right), \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left({x}^{2}\right)\right)\right), \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      12. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(x \cdot x\right)\right)\right), \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right)\right), \left(\frac{1}{576} + \frac{1}{2880} \cdot {x}^{2}\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      14. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right)\right), \mathsf{+.f64}\left(\frac{1}{576}, \left(\frac{1}{2880} \cdot {x}^{2}\right)\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      15. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right)\right), \mathsf{+.f64}\left(\frac{1}{576}, \left(\frac{1}{2880} \cdot \left(x \cdot x\right)\right)\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      16. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right)\right), \mathsf{+.f64}\left(\frac{1}{576}, \left(\left(\frac{1}{2880} \cdot x\right) \cdot x\right)\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      17. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right)\right), \mathsf{+.f64}\left(\frac{1}{576}, \left(x \cdot \left(\frac{1}{2880} \cdot x\right)\right)\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      18. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right)\right), \mathsf{+.f64}\left(\frac{1}{576}, \mathsf{*.f64}\left(x, \left(\frac{1}{2880} \cdot x\right)\right)\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      19. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right)\right), \mathsf{+.f64}\left(\frac{1}{576}, \mathsf{*.f64}\left(x, \left(x \cdot \frac{1}{2880}\right)\right)\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      20. *-lowering-*.f6465.1%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, x\right)\right)\right), \mathsf{+.f64}\left(\frac{1}{576}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \frac{1}{2880}\right)\right)\right)\right)\right), x\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
    12. Simplified65.1%

      \[\leadsto \frac{\left(0.25 - \color{blue}{\left(x \cdot \left(x \cdot \left(x \cdot x\right)\right)\right) \cdot \left(0.001736111111111111 + x \cdot \left(x \cdot 0.00034722222222222224\right)\right)}\right) \cdot x}{0.5 - x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)} \]

    if 2.35000000000000009 < x

    1. Initial program 98.5%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr12.3%

      \[\leadsto \color{blue}{{1}^{-0.5}} \]
    6. Step-by-step derivation
      1. pow-base-112.3%

        \[\leadsto 1 \]
    7. Applied egg-rr12.3%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification51.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.35:\\ \;\;\;\;\frac{x \cdot \left(0.25 - \left(x \cdot \left(x \cdot \left(x \cdot x\right)\right)\right) \cdot \left(0.001736111111111111 + x \cdot \left(x \cdot 0.00034722222222222224\right)\right)\right)}{0.5 - x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 52.4% accurate, 7.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 3.1:\\ \;\;\;\;x \cdot \left(0.5 + \left(x \cdot x\right) \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 3.1)
   (*
    x
    (+
     0.5
     (*
      (* x x)
      (+
       0.041666666666666664
       (*
        (* x x)
        (+ 0.004166666666666667 (* (* x x) 0.00042162698412698415)))))))
   1.0))
double code(double x) {
	double tmp;
	if (x <= 3.1) {
		tmp = x * (0.5 + ((x * x) * (0.041666666666666664 + ((x * x) * (0.004166666666666667 + ((x * x) * 0.00042162698412698415))))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 3.1d0) then
        tmp = x * (0.5d0 + ((x * x) * (0.041666666666666664d0 + ((x * x) * (0.004166666666666667d0 + ((x * x) * 0.00042162698412698415d0))))))
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 3.1) {
		tmp = x * (0.5 + ((x * x) * (0.041666666666666664 + ((x * x) * (0.004166666666666667 + ((x * x) * 0.00042162698412698415))))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 3.1:
		tmp = x * (0.5 + ((x * x) * (0.041666666666666664 + ((x * x) * (0.004166666666666667 + ((x * x) * 0.00042162698412698415))))))
	else:
		tmp = 1.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 3.1)
		tmp = Float64(x * Float64(0.5 + Float64(Float64(x * x) * Float64(0.041666666666666664 + Float64(Float64(x * x) * Float64(0.004166666666666667 + Float64(Float64(x * x) * 0.00042162698412698415)))))));
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 3.1)
		tmp = x * (0.5 + ((x * x) * (0.041666666666666664 + ((x * x) * (0.004166666666666667 + ((x * x) * 0.00042162698412698415))))));
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 3.1], N[(x * N[(0.5 + N[(N[(x * x), $MachinePrecision] * N[(0.041666666666666664 + N[(N[(x * x), $MachinePrecision] * N[(0.004166666666666667 + N[(N[(x * x), $MachinePrecision] * 0.00042162698412698415), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.1:\\
\;\;\;\;x \cdot \left(0.5 + \left(x \cdot x\right) \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3.10000000000000009

    1. Initial program 38.9%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{24} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)}\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\left(\frac{1}{24} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)}\right)\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\left(x \cdot x\right), \left(\color{blue}{\frac{1}{24}} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\frac{1}{24}} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)}\right)\right)\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)}\right)\right)\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left(x \cdot x\right), \left(\color{blue}{\frac{1}{240}} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\frac{1}{240}} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)\right)\right)\right) \]
      10. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \color{blue}{\left(\frac{17}{40320} \cdot {x}^{2}\right)}\right)\right)\right)\right)\right)\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \left({x}^{2} \cdot \color{blue}{\frac{17}{40320}}\right)\right)\right)\right)\right)\right)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\frac{17}{40320}}\right)\right)\right)\right)\right)\right)\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\left(x \cdot x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right) \]
      14. *-lowering-*.f6465.6%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right) \]
    7. Simplified65.6%

      \[\leadsto \color{blue}{x \cdot \left(0.5 + \left(x \cdot x\right) \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)} \]

    if 3.10000000000000009 < x

    1. Initial program 98.5%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr12.3%

      \[\leadsto \color{blue}{{1}^{-0.5}} \]
    6. Step-by-step derivation
      1. pow-base-112.3%

        \[\leadsto 1 \]
    7. Applied egg-rr12.3%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 52.4% accurate, 10.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 3.1:\\ \;\;\;\;x \cdot \left(0.5 + x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot 0.004166666666666667\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 3.1)
   (*
    x
    (+
     0.5
     (* x (* x (+ 0.041666666666666664 (* (* x x) 0.004166666666666667))))))
   1.0))
double code(double x) {
	double tmp;
	if (x <= 3.1) {
		tmp = x * (0.5 + (x * (x * (0.041666666666666664 + ((x * x) * 0.004166666666666667)))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 3.1d0) then
        tmp = x * (0.5d0 + (x * (x * (0.041666666666666664d0 + ((x * x) * 0.004166666666666667d0)))))
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 3.1) {
		tmp = x * (0.5 + (x * (x * (0.041666666666666664 + ((x * x) * 0.004166666666666667)))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 3.1:
		tmp = x * (0.5 + (x * (x * (0.041666666666666664 + ((x * x) * 0.004166666666666667)))))
	else:
		tmp = 1.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 3.1)
		tmp = Float64(x * Float64(0.5 + Float64(x * Float64(x * Float64(0.041666666666666664 + Float64(Float64(x * x) * 0.004166666666666667))))));
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 3.1)
		tmp = x * (0.5 + (x * (x * (0.041666666666666664 + ((x * x) * 0.004166666666666667)))));
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 3.1], N[(x * N[(0.5 + N[(x * N[(x * N[(0.041666666666666664 + N[(N[(x * x), $MachinePrecision] * 0.004166666666666667), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.1:\\
\;\;\;\;x \cdot \left(0.5 + x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot 0.004166666666666667\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3.10000000000000009

    1. Initial program 38.9%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(\left(x \cdot x\right) \cdot \left(\color{blue}{\frac{1}{24}} + \frac{1}{240} \cdot {x}^{2}\right)\right)\right)\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(x \cdot \color{blue}{\left(x \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)}\right)\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\left(x \cdot \left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)\right)}\right)\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{24} + \frac{1}{240} \cdot {x}^{2}\right)}\right)\right)\right)\right) \]
      7. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \color{blue}{\left(\frac{1}{240} \cdot {x}^{2}\right)}\right)\right)\right)\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \left({x}^{2} \cdot \color{blue}{\frac{1}{240}}\right)\right)\right)\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\frac{1}{240}}\right)\right)\right)\right)\right)\right) \]
      10. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left(x \cdot x\right), \frac{1}{240}\right)\right)\right)\right)\right)\right) \]
      11. *-lowering-*.f6465.6%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{1}{240}\right)\right)\right)\right)\right)\right) \]
    7. Simplified65.6%

      \[\leadsto \color{blue}{x \cdot \left(0.5 + x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot 0.004166666666666667\right)\right)\right)} \]

    if 3.10000000000000009 < x

    1. Initial program 98.5%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr12.3%

      \[\leadsto \color{blue}{{1}^{-0.5}} \]
    6. Step-by-step derivation
      1. pow-base-112.3%

        \[\leadsto 1 \]
    7. Applied egg-rr12.3%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 52.8% accurate, 12.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 520:\\ \;\;\;\;\frac{x \cdot 0.25}{0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 520.0)
   (/ (* x 0.25) (+ 0.5 (* (* x x) -0.041666666666666664)))
   1.0))
double code(double x) {
	double tmp;
	if (x <= 520.0) {
		tmp = (x * 0.25) / (0.5 + ((x * x) * -0.041666666666666664));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 520.0d0) then
        tmp = (x * 0.25d0) / (0.5d0 + ((x * x) * (-0.041666666666666664d0)))
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 520.0) {
		tmp = (x * 0.25) / (0.5 + ((x * x) * -0.041666666666666664));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 520.0:
		tmp = (x * 0.25) / (0.5 + ((x * x) * -0.041666666666666664))
	else:
		tmp = 1.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 520.0)
		tmp = Float64(Float64(x * 0.25) / Float64(0.5 + Float64(Float64(x * x) * -0.041666666666666664)));
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 520.0)
		tmp = (x * 0.25) / (0.5 + ((x * x) * -0.041666666666666664));
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 520.0], N[(N[(x * 0.25), $MachinePrecision] / N[(0.5 + N[(N[(x * x), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 520:\\
\;\;\;\;\frac{x \cdot 0.25}{0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664}\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 520

    1. Initial program 38.9%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{24} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)}\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\left(\frac{1}{24} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)}\right)\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\left(x \cdot x\right), \left(\color{blue}{\frac{1}{24}} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\frac{1}{24}} + {x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)\right)}\right)\right)\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\left(\frac{1}{240} + \frac{17}{40320} \cdot {x}^{2}\right)}\right)\right)\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left(x \cdot x\right), \left(\color{blue}{\frac{1}{240}} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(\color{blue}{\frac{1}{240}} + \frac{17}{40320} \cdot {x}^{2}\right)\right)\right)\right)\right)\right) \]
      10. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \color{blue}{\left(\frac{17}{40320} \cdot {x}^{2}\right)}\right)\right)\right)\right)\right)\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \left({x}^{2} \cdot \color{blue}{\frac{17}{40320}}\right)\right)\right)\right)\right)\right)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\frac{17}{40320}}\right)\right)\right)\right)\right)\right)\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\left(x \cdot x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right) \]
      14. *-lowering-*.f6465.6%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right) \]
    7. Simplified65.6%

      \[\leadsto \color{blue}{x \cdot \left(0.5 + \left(x \cdot x\right) \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)} \]
    8. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\frac{1}{2} + \left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right) \cdot \color{blue}{x} \]
      2. flip-+N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{1}{2} - \left(\left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right) \cdot \left(\left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right)}{\frac{1}{2} - \left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)} \cdot x \]
      3. associate-*l/N/A

        \[\leadsto \frac{\left(\frac{1}{2} \cdot \frac{1}{2} - \left(\left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right) \cdot \left(\left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right)\right) \cdot x}{\color{blue}{\frac{1}{2} - \left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)}} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\left(\frac{1}{2} \cdot \frac{1}{2} - \left(\left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right) \cdot \left(\left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right)\right) \cdot x\right), \color{blue}{\left(\frac{1}{2} - \left(x \cdot x\right) \cdot \left(\frac{1}{24} + \left(x \cdot x\right) \cdot \left(\frac{1}{240} + \left(x \cdot x\right) \cdot \frac{17}{40320}\right)\right)\right)}\right) \]
    9. Applied egg-rr65.0%

      \[\leadsto \color{blue}{\frac{\left(0.25 - \left(x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)\right)\right) \cdot x}{0.5 - x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)}} \]
    10. Taylor expanded in x around 0

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot x\right)}, \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
    11. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\left(x \cdot \frac{1}{4}\right), \mathsf{\_.f64}\left(\color{blue}{\frac{1}{2}}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
      2. *-lowering-*.f6466.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \frac{1}{4}\right), \mathsf{\_.f64}\left(\color{blue}{\frac{1}{2}}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{+.f64}\left(\frac{1}{240}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{17}{40320}\right)\right)\right)\right)\right)\right)\right)\right) \]
    12. Simplified66.0%

      \[\leadsto \frac{\color{blue}{x \cdot 0.25}}{0.5 - x \cdot \left(x \cdot \left(0.041666666666666664 + \left(x \cdot x\right) \cdot \left(0.004166666666666667 + \left(x \cdot x\right) \cdot 0.00042162698412698415\right)\right)\right)} \]
    13. Taylor expanded in x around 0

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \frac{1}{4}\right), \color{blue}{\left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right)}\right) \]
    14. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \frac{1}{4}\right), \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{-1}{24} \cdot {x}^{2}\right)}\right)\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \frac{1}{4}\right), \mathsf{+.f64}\left(\frac{1}{2}, \left({x}^{2} \cdot \color{blue}{\frac{-1}{24}}\right)\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \frac{1}{4}\right), \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\frac{-1}{24}}\right)\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \frac{1}{4}\right), \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\left(x \cdot x\right), \frac{-1}{24}\right)\right)\right) \]
      5. *-lowering-*.f6466.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \frac{1}{4}\right), \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{-1}{24}\right)\right)\right) \]
    15. Simplified66.2%

      \[\leadsto \frac{x \cdot 0.25}{\color{blue}{0.5 + \left(x \cdot x\right) \cdot -0.041666666666666664}} \]

    if 520 < x

    1. Initial program 98.5%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr12.3%

      \[\leadsto \color{blue}{{1}^{-0.5}} \]
    6. Step-by-step derivation
      1. pow-base-112.3%

        \[\leadsto 1 \]
    7. Applied egg-rr12.3%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 52.4% accurate, 12.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 3.1:\\ \;\;\;\;\frac{x}{2} + x \cdot \left(x \cdot \left(x \cdot 0.041666666666666664\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 3.1) (+ (/ x 2.0) (* x (* x (* x 0.041666666666666664)))) 1.0))
double code(double x) {
	double tmp;
	if (x <= 3.1) {
		tmp = (x / 2.0) + (x * (x * (x * 0.041666666666666664)));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 3.1d0) then
        tmp = (x / 2.0d0) + (x * (x * (x * 0.041666666666666664d0)))
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 3.1) {
		tmp = (x / 2.0) + (x * (x * (x * 0.041666666666666664)));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 3.1:
		tmp = (x / 2.0) + (x * (x * (x * 0.041666666666666664)))
	else:
		tmp = 1.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 3.1)
		tmp = Float64(Float64(x / 2.0) + Float64(x * Float64(x * Float64(x * 0.041666666666666664))));
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 3.1)
		tmp = (x / 2.0) + (x * (x * (x * 0.041666666666666664)));
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 3.1], N[(N[(x / 2.0), $MachinePrecision] + N[(x * N[(x * N[(x * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.1:\\
\;\;\;\;\frac{x}{2} + x \cdot \left(x \cdot \left(x \cdot 0.041666666666666664\right)\right)\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3.10000000000000009

    1. Initial program 38.9%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \frac{1}{24} \cdot {x}^{2}\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{2} + \frac{1}{24} \cdot {x}^{2}\right)}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{1}{24} \cdot {x}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{1}{24} \cdot \left(x \cdot \color{blue}{x}\right)\right)\right)\right) \]
      4. associate-*r*N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(\left(\frac{1}{24} \cdot x\right) \cdot \color{blue}{x}\right)\right)\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(x \cdot \color{blue}{\left(\frac{1}{24} \cdot x\right)}\right)\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{24} \cdot x\right)}\right)\right)\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \left(x \cdot \color{blue}{\frac{1}{24}}\right)\right)\right)\right) \]
      8. *-lowering-*.f6465.5%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{24}}\right)\right)\right)\right) \]
    7. Simplified65.5%

      \[\leadsto \color{blue}{x \cdot \left(0.5 + x \cdot \left(x \cdot 0.041666666666666664\right)\right)} \]
    8. Step-by-step derivation
      1. distribute-rgt-inN/A

        \[\leadsto \frac{1}{2} \cdot x + \color{blue}{\left(x \cdot \left(x \cdot \frac{1}{24}\right)\right) \cdot x} \]
      2. *-commutativeN/A

        \[\leadsto \frac{1}{2} \cdot x + x \cdot \color{blue}{\left(x \cdot \left(x \cdot \frac{1}{24}\right)\right)} \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{1}{2} \cdot x\right), \color{blue}{\left(x \cdot \left(x \cdot \left(x \cdot \frac{1}{24}\right)\right)\right)}\right) \]
      4. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{1}{2} \cdot x\right), \left(x \cdot \left(x \cdot \left(x \cdot \frac{1}{24}\right)\right)\right)\right) \]
      5. associate-/r/N/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{1}{\frac{2}{x}}\right), \left(\color{blue}{x} \cdot \left(x \cdot \left(x \cdot \frac{1}{24}\right)\right)\right)\right) \]
      6. clear-numN/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{x}{2}\right), \left(\color{blue}{x} \cdot \left(x \cdot \left(x \cdot \frac{1}{24}\right)\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \left(\color{blue}{x} \cdot \left(x \cdot \left(x \cdot \frac{1}{24}\right)\right)\right)\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{*.f64}\left(x, \color{blue}{\left(x \cdot \left(x \cdot \frac{1}{24}\right)\right)}\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\left(x \cdot \frac{1}{24}\right)}\right)\right)\right) \]
      10. *-lowering-*.f6465.5%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{24}}\right)\right)\right)\right) \]
    9. Applied egg-rr65.5%

      \[\leadsto \color{blue}{\frac{x}{2} + x \cdot \left(x \cdot \left(x \cdot 0.041666666666666664\right)\right)} \]

    if 3.10000000000000009 < x

    1. Initial program 98.5%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr12.3%

      \[\leadsto \color{blue}{{1}^{-0.5}} \]
    6. Step-by-step derivation
      1. pow-base-112.3%

        \[\leadsto 1 \]
    7. Applied egg-rr12.3%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 52.4% accurate, 14.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 3.1:\\ \;\;\;\;x \cdot \left(0.5 + x \cdot \left(x \cdot 0.041666666666666664\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 3.1) (* x (+ 0.5 (* x (* x 0.041666666666666664)))) 1.0))
double code(double x) {
	double tmp;
	if (x <= 3.1) {
		tmp = x * (0.5 + (x * (x * 0.041666666666666664)));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 3.1d0) then
        tmp = x * (0.5d0 + (x * (x * 0.041666666666666664d0)))
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 3.1) {
		tmp = x * (0.5 + (x * (x * 0.041666666666666664)));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 3.1:
		tmp = x * (0.5 + (x * (x * 0.041666666666666664)))
	else:
		tmp = 1.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 3.1)
		tmp = Float64(x * Float64(0.5 + Float64(x * Float64(x * 0.041666666666666664))));
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 3.1)
		tmp = x * (0.5 + (x * (x * 0.041666666666666664)));
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 3.1], N[(x * N[(0.5 + N[(x * N[(x * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.1:\\
\;\;\;\;x \cdot \left(0.5 + x \cdot \left(x \cdot 0.041666666666666664\right)\right)\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3.10000000000000009

    1. Initial program 38.9%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \frac{1}{24} \cdot {x}^{2}\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{2} + \frac{1}{24} \cdot {x}^{2}\right)}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{1}{24} \cdot {x}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{1}{24} \cdot \left(x \cdot \color{blue}{x}\right)\right)\right)\right) \]
      4. associate-*r*N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(\left(\frac{1}{24} \cdot x\right) \cdot \color{blue}{x}\right)\right)\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(x \cdot \color{blue}{\left(\frac{1}{24} \cdot x\right)}\right)\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{24} \cdot x\right)}\right)\right)\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \left(x \cdot \color{blue}{\frac{1}{24}}\right)\right)\right)\right) \]
      8. *-lowering-*.f6465.5%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{24}}\right)\right)\right)\right) \]
    7. Simplified65.5%

      \[\leadsto \color{blue}{x \cdot \left(0.5 + x \cdot \left(x \cdot 0.041666666666666664\right)\right)} \]

    if 3.10000000000000009 < x

    1. Initial program 98.5%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr12.3%

      \[\leadsto \color{blue}{{1}^{-0.5}} \]
    6. Step-by-step derivation
      1. pow-base-112.3%

        \[\leadsto 1 \]
    7. Applied egg-rr12.3%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 52.4% accurate, 25.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 3.1:\\ \;\;\;\;\frac{x}{2}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x) :precision binary64 (if (<= x 3.1) (/ x 2.0) 1.0))
double code(double x) {
	double tmp;
	if (x <= 3.1) {
		tmp = x / 2.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 3.1d0) then
        tmp = x / 2.0d0
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 3.1) {
		tmp = x / 2.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 3.1:
		tmp = x / 2.0
	else:
		tmp = 1.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 3.1)
		tmp = Float64(x / 2.0);
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 3.1)
		tmp = x / 2.0;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 3.1], N[(x / 2.0), $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.1:\\
\;\;\;\;\frac{x}{2}\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3.10000000000000009

    1. Initial program 38.9%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{1}{2} \cdot x} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\frac{1}{2}} \]
      2. metadata-evalN/A

        \[\leadsto x \cdot \frac{1}{\color{blue}{2}} \]
      3. associate-/l*N/A

        \[\leadsto \frac{x \cdot 1}{\color{blue}{2}} \]
      4. *-rgt-identityN/A

        \[\leadsto \frac{x}{2} \]
      5. /-lowering-/.f6465.5%

        \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{2}\right) \]
    7. Simplified65.5%

      \[\leadsto \color{blue}{\frac{x}{2}} \]

    if 3.10000000000000009 < x

    1. Initial program 98.5%

      \[\frac{1 - \cos x}{\sin x} \]
    2. Step-by-step derivation
      1. hang-p0-tanN/A

        \[\leadsto \tan \left(\frac{x}{2}\right) \]
      2. tan-lowering-tan.f64N/A

        \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
      3. /-lowering-/.f64100.0%

        \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr12.3%

      \[\leadsto \color{blue}{{1}^{-0.5}} \]
    6. Step-by-step derivation
      1. pow-base-112.3%

        \[\leadsto 1 \]
    7. Applied egg-rr12.3%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 7.0% accurate, 205.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (x) :precision binary64 1.0)
double code(double x) {
	return 1.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0
end function
public static double code(double x) {
	return 1.0;
}
def code(x):
	return 1.0
function code(x)
	return 1.0
end
function tmp = code(x)
	tmp = 1.0;
end
code[x_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 54.1%

    \[\frac{1 - \cos x}{\sin x} \]
  2. Step-by-step derivation
    1. hang-p0-tanN/A

      \[\leadsto \tan \left(\frac{x}{2}\right) \]
    2. tan-lowering-tan.f64N/A

      \[\leadsto \mathsf{tan.f64}\left(\left(\frac{x}{2}\right)\right) \]
    3. /-lowering-/.f64100.0%

      \[\leadsto \mathsf{tan.f64}\left(\mathsf{/.f64}\left(x, 2\right)\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right)} \]
  4. Add Preprocessing
  5. Applied egg-rr7.8%

    \[\leadsto \color{blue}{{1}^{-0.5}} \]
  6. Step-by-step derivation
    1. pow-base-17.8%

      \[\leadsto 1 \]
  7. Applied egg-rr7.8%

    \[\leadsto \color{blue}{1} \]
  8. Add Preprocessing

Developer Target 1: 100.0% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \tan \left(\frac{x}{2}\right) \end{array} \]
(FPCore (x) :precision binary64 (tan (/ x 2.0)))
double code(double x) {
	return tan((x / 2.0));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = tan((x / 2.0d0))
end function
public static double code(double x) {
	return Math.tan((x / 2.0));
}
def code(x):
	return math.tan((x / 2.0))
function code(x)
	return tan(Float64(x / 2.0))
end
function tmp = code(x)
	tmp = tan((x / 2.0));
end
code[x_] := N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\tan \left(\frac{x}{2}\right)
\end{array}

Reproduce

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

  :alt
  (! :herbie-platform default (tan (/ x 2)))

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