invcot (example 3.9)

Percentage Accurate: 6.3% → 99.5%
Time: 13.4s
Alternatives: 6
Speedup: 35.7×

Specification

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

\\
\frac{1}{x} - \frac{1}{\tan 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 6 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: 6.3% accurate, 1.0× speedup?

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

\\
\frac{1}{x} - \frac{1}{\tan x}
\end{array}

Alternative 1: 99.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \frac{x \cdot \left(1.0973936899862826 \cdot 10^{-5} \cdot {\left({x}^{2}\right)}^{3} + 0.037037037037037035\right)}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - {x}^{2} \cdot 0.007407407407407408\right)} \end{array} \]
(FPCore (x)
 :precision binary64
 (/
  (*
   x
   (+ (* 1.0973936899862826e-5 (pow (pow x 2.0) 3.0)) 0.037037037037037035))
  (+
   0.1111111111111111
   (-
    (* (pow x 4.0) 0.0004938271604938272)
    (* (pow x 2.0) 0.007407407407407408)))))
double code(double x) {
	return (x * ((1.0973936899862826e-5 * pow(pow(x, 2.0), 3.0)) + 0.037037037037037035)) / (0.1111111111111111 + ((pow(x, 4.0) * 0.0004938271604938272) - (pow(x, 2.0) * 0.007407407407407408)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x * ((1.0973936899862826d-5 * ((x ** 2.0d0) ** 3.0d0)) + 0.037037037037037035d0)) / (0.1111111111111111d0 + (((x ** 4.0d0) * 0.0004938271604938272d0) - ((x ** 2.0d0) * 0.007407407407407408d0)))
end function
public static double code(double x) {
	return (x * ((1.0973936899862826e-5 * Math.pow(Math.pow(x, 2.0), 3.0)) + 0.037037037037037035)) / (0.1111111111111111 + ((Math.pow(x, 4.0) * 0.0004938271604938272) - (Math.pow(x, 2.0) * 0.007407407407407408)));
}
def code(x):
	return (x * ((1.0973936899862826e-5 * math.pow(math.pow(x, 2.0), 3.0)) + 0.037037037037037035)) / (0.1111111111111111 + ((math.pow(x, 4.0) * 0.0004938271604938272) - (math.pow(x, 2.0) * 0.007407407407407408)))
function code(x)
	return Float64(Float64(x * Float64(Float64(1.0973936899862826e-5 * ((x ^ 2.0) ^ 3.0)) + 0.037037037037037035)) / Float64(0.1111111111111111 + Float64(Float64((x ^ 4.0) * 0.0004938271604938272) - Float64((x ^ 2.0) * 0.007407407407407408))))
end
function tmp = code(x)
	tmp = (x * ((1.0973936899862826e-5 * ((x ^ 2.0) ^ 3.0)) + 0.037037037037037035)) / (0.1111111111111111 + (((x ^ 4.0) * 0.0004938271604938272) - ((x ^ 2.0) * 0.007407407407407408)));
end
code[x_] := N[(N[(x * N[(N[(1.0973936899862826e-5 * N[Power[N[Power[x, 2.0], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] + 0.037037037037037035), $MachinePrecision]), $MachinePrecision] / N[(0.1111111111111111 + N[(N[(N[Power[x, 4.0], $MachinePrecision] * 0.0004938271604938272), $MachinePrecision] - N[(N[Power[x, 2.0], $MachinePrecision] * 0.007407407407407408), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot \left(1.0973936899862826 \cdot 10^{-5} \cdot {\left({x}^{2}\right)}^{3} + 0.037037037037037035\right)}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - {x}^{2} \cdot 0.007407407407407408\right)}
\end{array}
Derivation
  1. Initial program 6.1%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.3%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + 0.022222222222222223 \cdot {x}^{2}\right)} \]
  4. Step-by-step derivation
    1. *-commutative99.3%

      \[\leadsto \color{blue}{\left(0.3333333333333333 + 0.022222222222222223 \cdot {x}^{2}\right) \cdot x} \]
    2. flip3-+98.0%

      \[\leadsto \color{blue}{\frac{{0.3333333333333333}^{3} + {\left(0.022222222222222223 \cdot {x}^{2}\right)}^{3}}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)}} \cdot x \]
    3. associate-*l/98.2%

      \[\leadsto \color{blue}{\frac{\left({0.3333333333333333}^{3} + {\left(0.022222222222222223 \cdot {x}^{2}\right)}^{3}\right) \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)}} \]
    4. pow398.2%

      \[\leadsto \frac{\left({0.3333333333333333}^{3} + \color{blue}{\left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)}\right) \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
    5. +-commutative98.2%

      \[\leadsto \frac{\color{blue}{\left(\left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) + {0.3333333333333333}^{3}\right)} \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
    6. pow398.2%

      \[\leadsto \frac{\left(\color{blue}{{\left(0.022222222222222223 \cdot {x}^{2}\right)}^{3}} + {0.3333333333333333}^{3}\right) \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
    7. unpow-prod-down98.2%

      \[\leadsto \frac{\left(\color{blue}{{0.022222222222222223}^{3} \cdot {\left({x}^{2}\right)}^{3}} + {0.3333333333333333}^{3}\right) \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
    8. metadata-eval98.2%

      \[\leadsto \frac{\left(\color{blue}{1.0973936899862826 \cdot 10^{-5}} \cdot {\left({x}^{2}\right)}^{3} + {0.3333333333333333}^{3}\right) \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
    9. metadata-eval99.5%

      \[\leadsto \frac{\left(1.0973936899862826 \cdot 10^{-5} \cdot {\left({x}^{2}\right)}^{3} + \color{blue}{0.037037037037037035}\right) \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
    10. metadata-eval99.5%

      \[\leadsto \frac{\left(1.0973936899862826 \cdot 10^{-5} \cdot {\left({x}^{2}\right)}^{3} + 0.037037037037037035\right) \cdot x}{\color{blue}{0.1111111111111111} + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
  5. Applied egg-rr99.5%

    \[\leadsto \color{blue}{\frac{\left(1.0973936899862826 \cdot 10^{-5} \cdot {\left({x}^{2}\right)}^{3} + 0.037037037037037035\right) \cdot x}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - 0.007407407407407408 \cdot {x}^{2}\right)}} \]
  6. Final simplification99.5%

    \[\leadsto \frac{x \cdot \left(1.0973936899862826 \cdot 10^{-5} \cdot {\left({x}^{2}\right)}^{3} + 0.037037037037037035\right)}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - {x}^{2} \cdot 0.007407407407407408\right)} \]
  7. Add Preprocessing

Alternative 2: 99.5% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \frac{x \cdot 0.037037037037037035}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - 0.007407407407407408 \cdot \left(x \cdot x\right)\right)} \end{array} \]
(FPCore (x)
 :precision binary64
 (/
  (* x 0.037037037037037035)
  (+
   0.1111111111111111
   (-
    (* (pow x 4.0) 0.0004938271604938272)
    (* 0.007407407407407408 (* x x))))))
double code(double x) {
	return (x * 0.037037037037037035) / (0.1111111111111111 + ((pow(x, 4.0) * 0.0004938271604938272) - (0.007407407407407408 * (x * x))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x * 0.037037037037037035d0) / (0.1111111111111111d0 + (((x ** 4.0d0) * 0.0004938271604938272d0) - (0.007407407407407408d0 * (x * x))))
end function
public static double code(double x) {
	return (x * 0.037037037037037035) / (0.1111111111111111 + ((Math.pow(x, 4.0) * 0.0004938271604938272) - (0.007407407407407408 * (x * x))));
}
def code(x):
	return (x * 0.037037037037037035) / (0.1111111111111111 + ((math.pow(x, 4.0) * 0.0004938271604938272) - (0.007407407407407408 * (x * x))))
function code(x)
	return Float64(Float64(x * 0.037037037037037035) / Float64(0.1111111111111111 + Float64(Float64((x ^ 4.0) * 0.0004938271604938272) - Float64(0.007407407407407408 * Float64(x * x)))))
end
function tmp = code(x)
	tmp = (x * 0.037037037037037035) / (0.1111111111111111 + (((x ^ 4.0) * 0.0004938271604938272) - (0.007407407407407408 * (x * x))));
end
code[x_] := N[(N[(x * 0.037037037037037035), $MachinePrecision] / N[(0.1111111111111111 + N[(N[(N[Power[x, 4.0], $MachinePrecision] * 0.0004938271604938272), $MachinePrecision] - N[(0.007407407407407408 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot 0.037037037037037035}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - 0.007407407407407408 \cdot \left(x \cdot x\right)\right)}
\end{array}
Derivation
  1. Initial program 6.1%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.3%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + 0.022222222222222223 \cdot {x}^{2}\right)} \]
  4. Step-by-step derivation
    1. *-commutative99.3%

      \[\leadsto \color{blue}{\left(0.3333333333333333 + 0.022222222222222223 \cdot {x}^{2}\right) \cdot x} \]
    2. flip3-+98.0%

      \[\leadsto \color{blue}{\frac{{0.3333333333333333}^{3} + {\left(0.022222222222222223 \cdot {x}^{2}\right)}^{3}}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)}} \cdot x \]
    3. associate-*l/98.2%

      \[\leadsto \color{blue}{\frac{\left({0.3333333333333333}^{3} + {\left(0.022222222222222223 \cdot {x}^{2}\right)}^{3}\right) \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)}} \]
    4. pow398.2%

      \[\leadsto \frac{\left({0.3333333333333333}^{3} + \color{blue}{\left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)}\right) \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
    5. +-commutative98.2%

      \[\leadsto \frac{\color{blue}{\left(\left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) + {0.3333333333333333}^{3}\right)} \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
    6. pow398.2%

      \[\leadsto \frac{\left(\color{blue}{{\left(0.022222222222222223 \cdot {x}^{2}\right)}^{3}} + {0.3333333333333333}^{3}\right) \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
    7. unpow-prod-down98.2%

      \[\leadsto \frac{\left(\color{blue}{{0.022222222222222223}^{3} \cdot {\left({x}^{2}\right)}^{3}} + {0.3333333333333333}^{3}\right) \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
    8. metadata-eval98.2%

      \[\leadsto \frac{\left(\color{blue}{1.0973936899862826 \cdot 10^{-5}} \cdot {\left({x}^{2}\right)}^{3} + {0.3333333333333333}^{3}\right) \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
    9. metadata-eval99.5%

      \[\leadsto \frac{\left(1.0973936899862826 \cdot 10^{-5} \cdot {\left({x}^{2}\right)}^{3} + \color{blue}{0.037037037037037035}\right) \cdot x}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
    10. metadata-eval99.5%

      \[\leadsto \frac{\left(1.0973936899862826 \cdot 10^{-5} \cdot {\left({x}^{2}\right)}^{3} + 0.037037037037037035\right) \cdot x}{\color{blue}{0.1111111111111111} + \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) - 0.3333333333333333 \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right)} \]
  5. Applied egg-rr99.5%

    \[\leadsto \color{blue}{\frac{\left(1.0973936899862826 \cdot 10^{-5} \cdot {\left({x}^{2}\right)}^{3} + 0.037037037037037035\right) \cdot x}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - 0.007407407407407408 \cdot {x}^{2}\right)}} \]
  6. Taylor expanded in x around 0 99.5%

    \[\leadsto \frac{\color{blue}{0.037037037037037035 \cdot x}}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - 0.007407407407407408 \cdot {x}^{2}\right)} \]
  7. Step-by-step derivation
    1. *-commutative99.5%

      \[\leadsto \frac{\color{blue}{x \cdot 0.037037037037037035}}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - 0.007407407407407408 \cdot {x}^{2}\right)} \]
  8. Simplified99.5%

    \[\leadsto \frac{\color{blue}{x \cdot 0.037037037037037035}}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - 0.007407407407407408 \cdot {x}^{2}\right)} \]
  9. Step-by-step derivation
    1. unpow299.5%

      \[\leadsto \frac{x \cdot 0.037037037037037035}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - 0.007407407407407408 \cdot \color{blue}{\left(x \cdot x\right)}\right)} \]
  10. Applied egg-rr99.5%

    \[\leadsto \frac{x \cdot 0.037037037037037035}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - 0.007407407407407408 \cdot \color{blue}{\left(x \cdot x\right)}\right)} \]
  11. Add Preprocessing

Alternative 3: 99.5% accurate, 9.7× speedup?

\[\begin{array}{l} \\ \frac{x \cdot 0.1111111111111111}{0.3333333333333333 + \left(x \cdot x\right) \cdot -0.022222222222222223} \end{array} \]
(FPCore (x)
 :precision binary64
 (/
  (* x 0.1111111111111111)
  (+ 0.3333333333333333 (* (* x x) -0.022222222222222223))))
double code(double x) {
	return (x * 0.1111111111111111) / (0.3333333333333333 + ((x * x) * -0.022222222222222223));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x * 0.1111111111111111d0) / (0.3333333333333333d0 + ((x * x) * (-0.022222222222222223d0)))
end function
public static double code(double x) {
	return (x * 0.1111111111111111) / (0.3333333333333333 + ((x * x) * -0.022222222222222223));
}
def code(x):
	return (x * 0.1111111111111111) / (0.3333333333333333 + ((x * x) * -0.022222222222222223))
function code(x)
	return Float64(Float64(x * 0.1111111111111111) / Float64(0.3333333333333333 + Float64(Float64(x * x) * -0.022222222222222223)))
end
function tmp = code(x)
	tmp = (x * 0.1111111111111111) / (0.3333333333333333 + ((x * x) * -0.022222222222222223));
end
code[x_] := N[(N[(x * 0.1111111111111111), $MachinePrecision] / N[(0.3333333333333333 + N[(N[(x * x), $MachinePrecision] * -0.022222222222222223), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot 0.1111111111111111}{0.3333333333333333 + \left(x \cdot x\right) \cdot -0.022222222222222223}
\end{array}
Derivation
  1. Initial program 6.1%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.3%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + 0.022222222222222223 \cdot {x}^{2}\right)} \]
  4. Step-by-step derivation
    1. *-commutative99.3%

      \[\leadsto \color{blue}{\left(0.3333333333333333 + 0.022222222222222223 \cdot {x}^{2}\right) \cdot x} \]
    2. flip-+99.3%

      \[\leadsto \color{blue}{\frac{0.3333333333333333 \cdot 0.3333333333333333 - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}}} \cdot x \]
    3. associate-*l/99.4%

      \[\leadsto \color{blue}{\frac{\left(0.3333333333333333 \cdot 0.3333333333333333 - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}}} \]
    4. metadata-eval99.4%

      \[\leadsto \frac{\left(\color{blue}{0.1111111111111111} - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    5. *-commutative99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - \color{blue}{\left({x}^{2} \cdot 0.022222222222222223\right)} \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    6. *-commutative99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot \color{blue}{\left({x}^{2} \cdot 0.022222222222222223\right)}\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    7. swap-sqr99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - \color{blue}{\left({x}^{2} \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot 0.022222222222222223\right)}\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    8. pow-prod-up99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - \color{blue}{{x}^{\left(2 + 2\right)}} \cdot \left(0.022222222222222223 \cdot 0.022222222222222223\right)\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    9. metadata-eval99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - {x}^{\color{blue}{4}} \cdot \left(0.022222222222222223 \cdot 0.022222222222222223\right)\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    10. metadata-eval99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - {x}^{4} \cdot \color{blue}{0.0004938271604938272}\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    11. cancel-sign-sub-inv99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - {x}^{4} \cdot 0.0004938271604938272\right) \cdot x}{\color{blue}{0.3333333333333333 + \left(-0.022222222222222223\right) \cdot {x}^{2}}} \]
    12. metadata-eval99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - {x}^{4} \cdot 0.0004938271604938272\right) \cdot x}{0.3333333333333333 + \color{blue}{-0.022222222222222223} \cdot {x}^{2}} \]
  5. Applied egg-rr99.4%

    \[\leadsto \color{blue}{\frac{\left(0.1111111111111111 - {x}^{4} \cdot 0.0004938271604938272\right) \cdot x}{0.3333333333333333 + -0.022222222222222223 \cdot {x}^{2}}} \]
  6. Taylor expanded in x around 0 99.4%

    \[\leadsto \frac{\color{blue}{0.1111111111111111 \cdot x}}{0.3333333333333333 + -0.022222222222222223 \cdot {x}^{2}} \]
  7. Step-by-step derivation
    1. *-commutative99.4%

      \[\leadsto \frac{\color{blue}{x \cdot 0.1111111111111111}}{0.3333333333333333 + -0.022222222222222223 \cdot {x}^{2}} \]
  8. Simplified99.4%

    \[\leadsto \frac{\color{blue}{x \cdot 0.1111111111111111}}{0.3333333333333333 + -0.022222222222222223 \cdot {x}^{2}} \]
  9. Step-by-step derivation
    1. unpow299.5%

      \[\leadsto \frac{x \cdot 0.037037037037037035}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - 0.007407407407407408 \cdot \color{blue}{\left(x \cdot x\right)}\right)} \]
  10. Applied egg-rr99.4%

    \[\leadsto \frac{x \cdot 0.1111111111111111}{0.3333333333333333 + -0.022222222222222223 \cdot \color{blue}{\left(x \cdot x\right)}} \]
  11. Final simplification99.4%

    \[\leadsto \frac{x \cdot 0.1111111111111111}{0.3333333333333333 + \left(x \cdot x\right) \cdot -0.022222222222222223} \]
  12. Add Preprocessing

Alternative 4: 99.3% accurate, 11.9× speedup?

\[\begin{array}{l} \\ x \cdot \left(0.3333333333333333 + \left(x \cdot x\right) \cdot 0.022222222222222223\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (* x (+ 0.3333333333333333 (* (* x x) 0.022222222222222223))))
double code(double x) {
	return x * (0.3333333333333333 + ((x * x) * 0.022222222222222223));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x * (0.3333333333333333d0 + ((x * x) * 0.022222222222222223d0))
end function
public static double code(double x) {
	return x * (0.3333333333333333 + ((x * x) * 0.022222222222222223));
}
def code(x):
	return x * (0.3333333333333333 + ((x * x) * 0.022222222222222223))
function code(x)
	return Float64(x * Float64(0.3333333333333333 + Float64(Float64(x * x) * 0.022222222222222223)))
end
function tmp = code(x)
	tmp = x * (0.3333333333333333 + ((x * x) * 0.022222222222222223));
end
code[x_] := N[(x * N[(0.3333333333333333 + N[(N[(x * x), $MachinePrecision] * 0.022222222222222223), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(0.3333333333333333 + \left(x \cdot x\right) \cdot 0.022222222222222223\right)
\end{array}
Derivation
  1. Initial program 6.1%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.3%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + 0.022222222222222223 \cdot {x}^{2}\right)} \]
  4. Step-by-step derivation
    1. unpow299.5%

      \[\leadsto \frac{x \cdot 0.037037037037037035}{0.1111111111111111 + \left({x}^{4} \cdot 0.0004938271604938272 - 0.007407407407407408 \cdot \color{blue}{\left(x \cdot x\right)}\right)} \]
  5. Applied egg-rr99.3%

    \[\leadsto x \cdot \left(0.3333333333333333 + 0.022222222222222223 \cdot \color{blue}{\left(x \cdot x\right)}\right) \]
  6. Final simplification99.3%

    \[\leadsto x \cdot \left(0.3333333333333333 + \left(x \cdot x\right) \cdot 0.022222222222222223\right) \]
  7. Add Preprocessing

Alternative 5: 99.0% accurate, 21.4× speedup?

\[\begin{array}{l} \\ \frac{x \cdot 0.1111111111111111}{0.3333333333333333} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (* x 0.1111111111111111) 0.3333333333333333))
double code(double x) {
	return (x * 0.1111111111111111) / 0.3333333333333333;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x * 0.1111111111111111d0) / 0.3333333333333333d0
end function
public static double code(double x) {
	return (x * 0.1111111111111111) / 0.3333333333333333;
}
def code(x):
	return (x * 0.1111111111111111) / 0.3333333333333333
function code(x)
	return Float64(Float64(x * 0.1111111111111111) / 0.3333333333333333)
end
function tmp = code(x)
	tmp = (x * 0.1111111111111111) / 0.3333333333333333;
end
code[x_] := N[(N[(x * 0.1111111111111111), $MachinePrecision] / 0.3333333333333333), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot 0.1111111111111111}{0.3333333333333333}
\end{array}
Derivation
  1. Initial program 6.1%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.3%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + 0.022222222222222223 \cdot {x}^{2}\right)} \]
  4. Step-by-step derivation
    1. *-commutative99.3%

      \[\leadsto \color{blue}{\left(0.3333333333333333 + 0.022222222222222223 \cdot {x}^{2}\right) \cdot x} \]
    2. flip-+99.3%

      \[\leadsto \color{blue}{\frac{0.3333333333333333 \cdot 0.3333333333333333 - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}}} \cdot x \]
    3. associate-*l/99.4%

      \[\leadsto \color{blue}{\frac{\left(0.3333333333333333 \cdot 0.3333333333333333 - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}}} \]
    4. metadata-eval99.4%

      \[\leadsto \frac{\left(\color{blue}{0.1111111111111111} - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    5. *-commutative99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - \color{blue}{\left({x}^{2} \cdot 0.022222222222222223\right)} \cdot \left(0.022222222222222223 \cdot {x}^{2}\right)\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    6. *-commutative99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot \color{blue}{\left({x}^{2} \cdot 0.022222222222222223\right)}\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    7. swap-sqr99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - \color{blue}{\left({x}^{2} \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot 0.022222222222222223\right)}\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    8. pow-prod-up99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - \color{blue}{{x}^{\left(2 + 2\right)}} \cdot \left(0.022222222222222223 \cdot 0.022222222222222223\right)\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    9. metadata-eval99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - {x}^{\color{blue}{4}} \cdot \left(0.022222222222222223 \cdot 0.022222222222222223\right)\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    10. metadata-eval99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - {x}^{4} \cdot \color{blue}{0.0004938271604938272}\right) \cdot x}{0.3333333333333333 - 0.022222222222222223 \cdot {x}^{2}} \]
    11. cancel-sign-sub-inv99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - {x}^{4} \cdot 0.0004938271604938272\right) \cdot x}{\color{blue}{0.3333333333333333 + \left(-0.022222222222222223\right) \cdot {x}^{2}}} \]
    12. metadata-eval99.4%

      \[\leadsto \frac{\left(0.1111111111111111 - {x}^{4} \cdot 0.0004938271604938272\right) \cdot x}{0.3333333333333333 + \color{blue}{-0.022222222222222223} \cdot {x}^{2}} \]
  5. Applied egg-rr99.4%

    \[\leadsto \color{blue}{\frac{\left(0.1111111111111111 - {x}^{4} \cdot 0.0004938271604938272\right) \cdot x}{0.3333333333333333 + -0.022222222222222223 \cdot {x}^{2}}} \]
  6. Taylor expanded in x around 0 99.4%

    \[\leadsto \frac{\color{blue}{0.1111111111111111 \cdot x}}{0.3333333333333333 + -0.022222222222222223 \cdot {x}^{2}} \]
  7. Step-by-step derivation
    1. *-commutative99.4%

      \[\leadsto \frac{\color{blue}{x \cdot 0.1111111111111111}}{0.3333333333333333 + -0.022222222222222223 \cdot {x}^{2}} \]
  8. Simplified99.4%

    \[\leadsto \frac{\color{blue}{x \cdot 0.1111111111111111}}{0.3333333333333333 + -0.022222222222222223 \cdot {x}^{2}} \]
  9. Taylor expanded in x around 0 99.1%

    \[\leadsto \frac{x \cdot 0.1111111111111111}{\color{blue}{0.3333333333333333}} \]
  10. Add Preprocessing

Alternative 6: 98.9% accurate, 35.7× speedup?

\[\begin{array}{l} \\ x \cdot 0.3333333333333333 \end{array} \]
(FPCore (x) :precision binary64 (* x 0.3333333333333333))
double code(double x) {
	return x * 0.3333333333333333;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x * 0.3333333333333333d0
end function
public static double code(double x) {
	return x * 0.3333333333333333;
}
def code(x):
	return x * 0.3333333333333333
function code(x)
	return Float64(x * 0.3333333333333333)
end
function tmp = code(x)
	tmp = x * 0.3333333333333333;
end
code[x_] := N[(x * 0.3333333333333333), $MachinePrecision]
\begin{array}{l}

\\
x \cdot 0.3333333333333333
\end{array}
Derivation
  1. Initial program 6.1%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.0%

    \[\leadsto \color{blue}{0.3333333333333333 \cdot x} \]
  4. Final simplification99.0%

    \[\leadsto x \cdot 0.3333333333333333 \]
  5. Add Preprocessing

Developer Target 1: 99.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|x\right| < 0.026:\\ \;\;\;\;\frac{x}{3} \cdot \left(1 + \frac{x \cdot x}{15}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} - \frac{1}{\tan x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (< (fabs x) 0.026)
   (* (/ x 3.0) (+ 1.0 (/ (* x x) 15.0)))
   (- (/ 1.0 x) (/ 1.0 (tan x)))))
double code(double x) {
	double tmp;
	if (fabs(x) < 0.026) {
		tmp = (x / 3.0) * (1.0 + ((x * x) / 15.0));
	} else {
		tmp = (1.0 / x) - (1.0 / tan(x));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (abs(x) < 0.026d0) then
        tmp = (x / 3.0d0) * (1.0d0 + ((x * x) / 15.0d0))
    else
        tmp = (1.0d0 / x) - (1.0d0 / tan(x))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (Math.abs(x) < 0.026) {
		tmp = (x / 3.0) * (1.0 + ((x * x) / 15.0));
	} else {
		tmp = (1.0 / x) - (1.0 / Math.tan(x));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if math.fabs(x) < 0.026:
		tmp = (x / 3.0) * (1.0 + ((x * x) / 15.0))
	else:
		tmp = (1.0 / x) - (1.0 / math.tan(x))
	return tmp
function code(x)
	tmp = 0.0
	if (abs(x) < 0.026)
		tmp = Float64(Float64(x / 3.0) * Float64(1.0 + Float64(Float64(x * x) / 15.0)));
	else
		tmp = Float64(Float64(1.0 / x) - Float64(1.0 / tan(x)));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (abs(x) < 0.026)
		tmp = (x / 3.0) * (1.0 + ((x * x) / 15.0));
	else
		tmp = (1.0 / x) - (1.0 / tan(x));
	end
	tmp_2 = tmp;
end
code[x_] := If[Less[N[Abs[x], $MachinePrecision], 0.026], N[(N[(x / 3.0), $MachinePrecision] * N[(1.0 + N[(N[(x * x), $MachinePrecision] / 15.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] - N[(1.0 / N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| < 0.026:\\
\;\;\;\;\frac{x}{3} \cdot \left(1 + \frac{x \cdot x}{15}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{x} - \frac{1}{\tan x}\\


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024116 
(FPCore (x)
  :name "invcot (example 3.9)"
  :precision binary64
  :pre (and (< -0.026 x) (< x 0.026))

  :alt
  (! :herbie-platform default (if (< (fabs x) 13/500) (* (/ x 3) (+ 1 (/ (* x x) 15))) (- (/ 1 x) (/ 1 (tan x)))))

  (- (/ 1.0 x) (/ 1.0 (tan x))))