invcot (example 3.9)

Percentage Accurate: 6.5% → 99.6%
Time: 27.7s
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.5% 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.6% accurate, 7.1× speedup?

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \left(\frac{1}{3} + \left(\mathsf{neg}\left(\frac{-1}{45}\right)\right) \cdot {\color{blue}{x}}^{2}\right)\right) \]
    3. cancel-sign-sub-invN/A

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{\_.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\frac{-1}{45}}\right)\right)\right) \]
    7. unpow2N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{\_.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(\left(x \cdot x\right), \frac{-1}{45}\right)\right)\right) \]
    8. *-lowering-*.f6499.2%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{\_.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{-1}{45}\right)\right)\right) \]
  5. Simplified99.2%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 - \left(x \cdot x\right) \cdot -0.022222222222222223\right)} \]
  6. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \left(\frac{1}{3} - \left(x \cdot x\right) \cdot \frac{-1}{45}\right) \cdot \color{blue}{x} \]
    2. flip--N/A

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

      \[\leadsto \frac{\left(\frac{1}{3} \cdot \frac{1}{3} - \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right) \cdot x}{\color{blue}{\frac{1}{3} + \left(x \cdot x\right) \cdot \frac{-1}{45}}} \]
    4. clear-numN/A

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

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\frac{1}{3}, \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right), \left(\color{blue}{\left(\frac{1}{3} \cdot \frac{1}{3} - \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right)} \cdot x\right)\right)\right) \]
    8. associate-*l*N/A

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

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \frac{-1}{45}\right)\right)\right), \mathsf{*.f64}\left(\left(\frac{1}{3} \cdot \frac{1}{3} - \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right), \color{blue}{x}\right)\right)\right) \]
  7. Applied egg-rr99.2%

    \[\leadsto \color{blue}{\frac{1}{\frac{0.3333333333333333 + x \cdot \left(x \cdot -0.022222222222222223\right)}{\left(0.1111111111111111 - 0.0004938271604938272 \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right) \cdot x}}} \]
  8. Step-by-step derivation
    1. associate-/r*N/A

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

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(x, \color{blue}{\left(\frac{\frac{1}{3} + x \cdot \left(x \cdot \frac{-1}{45}\right)}{\frac{1}{9} - \frac{1}{2025} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)}\right)}\right)\right)\right) \]
    5. clear-numN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(x, \left(\frac{1}{\color{blue}{\frac{\frac{1}{9} - \frac{1}{2025} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)}{\frac{1}{3} + x \cdot \left(x \cdot \frac{-1}{45}\right)}}}\right)\right)\right)\right) \]
    6. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(x, \left(\frac{1}{\frac{\frac{1}{9} - \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \frac{1}{2025}}{\frac{1}{3} + x \cdot \left(x \cdot \frac{-1}{45}\right)}}\right)\right)\right)\right) \]
    7. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(x, \left(\frac{1}{\frac{\frac{1}{9} - \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\frac{-1}{45} \cdot \frac{-1}{45}\right)}{\frac{1}{3} + x \cdot \left(x \cdot \frac{-1}{45}\right)}}\right)\right)\right)\right) \]
    8. swap-sqrN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(x, \left(\frac{1}{\frac{\frac{1}{9} - \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)}{\frac{1}{3} + x \cdot \left(x \cdot \frac{-1}{45}\right)}}\right)\right)\right)\right) \]
    9. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(x, \left(\frac{1}{\frac{\frac{1}{9} - \left(x \cdot \left(x \cdot \frac{-1}{45}\right)\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)}{\frac{1}{3} + x \cdot \left(x \cdot \frac{-1}{45}\right)}}\right)\right)\right)\right) \]
    10. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(x, \left(\frac{1}{\frac{\frac{1}{9} - \left(x \cdot \left(x \cdot \frac{-1}{45}\right)\right) \cdot \left(x \cdot \left(x \cdot \frac{-1}{45}\right)\right)}{\frac{1}{3} + x \cdot \left(x \cdot \frac{-1}{45}\right)}}\right)\right)\right)\right) \]
    11. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(x, \left(\frac{1}{\frac{\frac{1}{3} \cdot \frac{1}{3} - \left(x \cdot \left(x \cdot \frac{-1}{45}\right)\right) \cdot \left(x \cdot \left(x \cdot \frac{-1}{45}\right)\right)}{\frac{1}{3} + x \cdot \left(x \cdot \frac{-1}{45}\right)}}\right)\right)\right)\right) \]
    12. flip--N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(x, \left(\frac{1}{\frac{1}{3} - \color{blue}{x \cdot \left(x \cdot \frac{-1}{45}\right)}}\right)\right)\right)\right) \]
    13. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{1}{3} - x \cdot \left(x \cdot \frac{-1}{45}\right)\right)}\right)\right)\right)\right) \]
  9. Applied egg-rr99.5%

    \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{x}{\frac{1}{0.3333333333333333 - x \cdot \left(x \cdot -0.022222222222222223\right)}}}}} \]
  10. Add Preprocessing

Alternative 2: 99.5% accurate, 7.1× speedup?

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \left(\frac{1}{3} + {x}^{2} \cdot \left(\frac{2}{945} \cdot {x}^{2} + \color{blue}{\frac{1}{45}}\right)\right)\right) \]
    3. distribute-lft-inN/A

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \left(\left(\frac{1}{3} + \left(\frac{2}{945} \cdot {x}^{2}\right) \cdot {x}^{2}\right) + \frac{1}{45} \cdot {x}^{2}\right)\right) \]
    7. associate-*l*N/A

      \[\leadsto \mathsf{*.f64}\left(x, \left(\left(\frac{1}{3} + \frac{2}{945} \cdot \left({x}^{2} \cdot {x}^{2}\right)\right) + \frac{1}{45} \cdot {x}^{2}\right)\right) \]
    8. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(x, \left(\left(\frac{1}{3} + \left(\mathsf{neg}\left(\frac{-2}{945}\right)\right) \cdot \left({x}^{2} \cdot {x}^{2}\right)\right) + \frac{1}{45} \cdot {x}^{2}\right)\right) \]
    9. cancel-sign-sub-invN/A

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

      \[\leadsto \mathsf{*.f64}\left(x, \left(\left(\frac{1}{3} - \left(\frac{-2}{945} \cdot {x}^{2}\right) \cdot {x}^{2}\right) + \frac{1}{45} \cdot {x}^{2}\right)\right) \]
    11. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(x, \left(\left(\frac{1}{3} - {x}^{2} \cdot \left(\frac{-2}{945} \cdot {x}^{2}\right)\right) + \frac{1}{45} \cdot {x}^{2}\right)\right) \]
    12. associate-+l-N/A

      \[\leadsto \mathsf{*.f64}\left(x, \left(\frac{1}{3} - \color{blue}{\left({x}^{2} \cdot \left(\frac{-2}{945} \cdot {x}^{2}\right) - \frac{1}{45} \cdot {x}^{2}\right)}\right)\right) \]
    13. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(x, \left(\frac{1}{3} - \left({x}^{2} \cdot \left(\frac{-2}{945} \cdot {x}^{2}\right) - {x}^{2} \cdot \color{blue}{\frac{1}{45}}\right)\right)\right) \]
    14. distribute-lft-out--N/A

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{\_.f64}\left(\frac{1}{3}, \color{blue}{\left({x}^{2} \cdot \left(\frac{-2}{945} \cdot {x}^{2} - \frac{1}{45}\right)\right)}\right)\right) \]
  5. Simplified99.4%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 - \left(x \cdot x\right) \cdot \left(-0.022222222222222223 + x \cdot \left(x \cdot -0.0021164021164021165\right)\right)\right)} \]
  6. Add Preprocessing

Alternative 3: 99.5% accurate, 9.7× speedup?

\[\begin{array}{l} \\ \frac{x \cdot 0.1111111111111111}{0.3333333333333333 + x \cdot \left(x \cdot -0.022222222222222223\right)} \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(x * Float64(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[(x * N[(x * -0.022222222222222223), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \left(\frac{1}{3} + \left(\mathsf{neg}\left(\frac{-1}{45}\right)\right) \cdot {\color{blue}{x}}^{2}\right)\right) \]
    3. cancel-sign-sub-invN/A

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{\_.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\frac{-1}{45}}\right)\right)\right) \]
    7. unpow2N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{\_.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(\left(x \cdot x\right), \frac{-1}{45}\right)\right)\right) \]
    8. *-lowering-*.f6499.2%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{\_.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{-1}{45}\right)\right)\right) \]
  5. Simplified99.2%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 - \left(x \cdot x\right) \cdot -0.022222222222222223\right)} \]
  6. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \left(\frac{1}{3} - \left(x \cdot x\right) \cdot \frac{-1}{45}\right) \cdot \color{blue}{x} \]
    2. flip--N/A

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

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

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

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\left(\frac{1}{3} \cdot \frac{1}{3}\right), \left(\left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right)\right), x\right), \left(\frac{1}{3} + \left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right) \]
    7. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{9}, \left(\left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right)\right), x\right), \left(\frac{1}{3} + \left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right) \]
    8. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{9}, \left(\left(\frac{-1}{45} \cdot \left(x \cdot x\right)\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right)\right), x\right), \left(\frac{1}{3} + \left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right) \]
    9. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{9}, \left(\left(\frac{-1}{45} \cdot \left(x \cdot x\right)\right) \cdot \left(\frac{-1}{45} \cdot \left(x \cdot x\right)\right)\right)\right), x\right), \left(\frac{1}{3} + \left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right) \]
    10. swap-sqrN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{9}, \left(\left(\frac{-1}{45} \cdot \frac{-1}{45}\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\right), x\right), \left(\frac{1}{3} + \left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right) \]
    11. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{9}, \mathsf{*.f64}\left(\left(\frac{-1}{45} \cdot \frac{-1}{45}\right), \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\right), x\right), \left(\frac{1}{3} + \left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right) \]
    12. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{9}, \mathsf{*.f64}\left(\frac{1}{2025}, \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\right), x\right), \left(\frac{1}{3} + \left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right) \]
    13. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{9}, \mathsf{*.f64}\left(\frac{1}{2025}, \mathsf{*.f64}\left(\left(x \cdot x\right), \left(x \cdot x\right)\right)\right)\right), x\right), \left(\frac{1}{3} + \left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right) \]
    14. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{9}, \mathsf{*.f64}\left(\frac{1}{2025}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \left(x \cdot x\right)\right)\right)\right), x\right), \left(\frac{1}{3} + \left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right) \]
    15. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{9}, \mathsf{*.f64}\left(\frac{1}{2025}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(x, x\right)\right)\right)\right), x\right), \left(\frac{1}{3} + \left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right) \]
    16. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{9}, \mathsf{*.f64}\left(\frac{1}{2025}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(x, x\right)\right)\right)\right), x\right), \mathsf{+.f64}\left(\frac{1}{3}, \color{blue}{\left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)}\right)\right) \]
    17. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\frac{1}{9}, \mathsf{*.f64}\left(\frac{1}{2025}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \mathsf{*.f64}\left(x, x\right)\right)\right)\right), x\right), \mathsf{+.f64}\left(\frac{1}{3}, \left(x \cdot \color{blue}{\left(x \cdot \frac{-1}{45}\right)}\right)\right)\right) \]
  7. Applied egg-rr99.3%

    \[\leadsto \color{blue}{\frac{\left(0.1111111111111111 - 0.0004938271604938272 \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right) \cdot x}{0.3333333333333333 + x \cdot \left(x \cdot -0.022222222222222223\right)}} \]
  8. Taylor expanded in x around 0

    \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(\frac{1}{9} \cdot x\right)}, \mathsf{+.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \frac{-1}{45}\right)\right)\right)\right) \]
  9. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\left(x \cdot \frac{1}{9}\right), \mathsf{+.f64}\left(\color{blue}{\frac{1}{3}}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \frac{-1}{45}\right)\right)\right)\right) \]
    2. *-lowering-*.f6499.3%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(x, \frac{1}{9}\right), \mathsf{+.f64}\left(\color{blue}{\frac{1}{3}}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \frac{-1}{45}\right)\right)\right)\right) \]
  10. Simplified99.3%

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

Alternative 4: 99.4% accurate, 11.9× speedup?

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \left(\frac{1}{3} + \left(\mathsf{neg}\left(\frac{-1}{45}\right)\right) \cdot {\color{blue}{x}}^{2}\right)\right) \]
    3. cancel-sign-sub-invN/A

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{\_.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\frac{-1}{45}}\right)\right)\right) \]
    7. unpow2N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{\_.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(\left(x \cdot x\right), \frac{-1}{45}\right)\right)\right) \]
    8. *-lowering-*.f6499.2%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{\_.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{-1}{45}\right)\right)\right) \]
  5. Simplified99.2%

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

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

Alternative 5: 99.4% accurate, 35.7× speedup?

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

\\
\frac{x}{3}
\end{array}
Derivation
  1. Initial program 6.9%

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \left(\frac{1}{3} + \left(\mathsf{neg}\left(\frac{-1}{45}\right)\right) \cdot {\color{blue}{x}}^{2}\right)\right) \]
    3. cancel-sign-sub-invN/A

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{\_.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(\left({x}^{2}\right), \color{blue}{\frac{-1}{45}}\right)\right)\right) \]
    7. unpow2N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{\_.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(\left(x \cdot x\right), \frac{-1}{45}\right)\right)\right) \]
    8. *-lowering-*.f6499.2%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{\_.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, x\right), \frac{-1}{45}\right)\right)\right) \]
  5. Simplified99.2%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 - \left(x \cdot x\right) \cdot -0.022222222222222223\right)} \]
  6. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \left(\frac{1}{3} - \left(x \cdot x\right) \cdot \frac{-1}{45}\right) \cdot \color{blue}{x} \]
    2. flip--N/A

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

      \[\leadsto \frac{\left(\frac{1}{3} \cdot \frac{1}{3} - \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right) \cdot x}{\color{blue}{\frac{1}{3} + \left(x \cdot x\right) \cdot \frac{-1}{45}}} \]
    4. clear-numN/A

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

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\frac{1}{3}, \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right), \left(\color{blue}{\left(\frac{1}{3} \cdot \frac{1}{3} - \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right)} \cdot x\right)\right)\right) \]
    8. associate-*l*N/A

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

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \frac{-1}{45}\right)\right)\right), \mathsf{*.f64}\left(\left(\frac{1}{3} \cdot \frac{1}{3} - \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{-1}{45}\right)\right), \color{blue}{x}\right)\right)\right) \]
  7. Applied egg-rr99.2%

    \[\leadsto \color{blue}{\frac{1}{\frac{0.3333333333333333 + x \cdot \left(x \cdot -0.022222222222222223\right)}{\left(0.1111111111111111 - 0.0004938271604938272 \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right) \cdot x}}} \]
  8. Taylor expanded in x around 0

    \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{3}{x}\right)}\right) \]
  9. Step-by-step derivation
    1. /-lowering-/.f6498.6%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(3, \color{blue}{x}\right)\right) \]
  10. Simplified98.6%

    \[\leadsto \frac{1}{\color{blue}{\frac{3}{x}}} \]
  11. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \frac{x}{\color{blue}{3}} \]
    2. /-lowering-/.f6499.0%

      \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{3}\right) \]
  12. Applied egg-rr99.0%

    \[\leadsto \color{blue}{\frac{x}{3}} \]
  13. 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.9%

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

    \[\leadsto \color{blue}{\frac{1}{3} \cdot x} \]
  4. Step-by-step derivation
    1. *-lowering-*.f6498.5%

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{3}, \color{blue}{x}\right) \]
  5. Simplified98.5%

    \[\leadsto \color{blue}{0.3333333333333333 \cdot x} \]
  6. Final simplification98.5%

    \[\leadsto x \cdot 0.3333333333333333 \]
  7. 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 2024141 
(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))))