?

Average Accuracy: 99.5% → 99.5%
Time: 10.6s
Precision: binary64
Cost: 32512

?

\[\frac{1 - \tan x \cdot \tan x}{1 + \tan x \cdot \tan x} \]
\[\frac{\mathsf{fma}\left(\tan x, \tan x, -1\right)}{-1 - {\tan x}^{2}} \]
(FPCore (x)
 :precision binary64
 (/ (- 1.0 (* (tan x) (tan x))) (+ 1.0 (* (tan x) (tan x)))))
(FPCore (x)
 :precision binary64
 (/ (fma (tan x) (tan x) -1.0) (- -1.0 (pow (tan x) 2.0))))
double code(double x) {
	return (1.0 - (tan(x) * tan(x))) / (1.0 + (tan(x) * tan(x)));
}
double code(double x) {
	return fma(tan(x), tan(x), -1.0) / (-1.0 - pow(tan(x), 2.0));
}
function code(x)
	return Float64(Float64(1.0 - Float64(tan(x) * tan(x))) / Float64(1.0 + Float64(tan(x) * tan(x))))
end
function code(x)
	return Float64(fma(tan(x), tan(x), -1.0) / Float64(-1.0 - (tan(x) ^ 2.0)))
end
code[x_] := N[(N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(N[Tan[x], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(N[Tan[x], $MachinePrecision] * N[Tan[x], $MachinePrecision] + -1.0), $MachinePrecision] / N[(-1.0 - N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1 - \tan x \cdot \tan x}{1 + \tan x \cdot \tan x}
\frac{\mathsf{fma}\left(\tan x, \tan x, -1\right)}{-1 - {\tan x}^{2}}

Error?

Derivation?

  1. Initial program 99.4%

    \[\frac{1 - \tan x \cdot \tan x}{1 + \tan x \cdot \tan x} \]
  2. Applied egg-rr99.4%

    \[\leadsto \color{blue}{\left(-\left(1 - {\tan x}^{2}\right)\right) \cdot \frac{1}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)}} \]
    Proof

    [Start]99.4

    \[ \frac{1 - \tan x \cdot \tan x}{1 + \tan x \cdot \tan x} \]

    frac-2neg [=>]99.4

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

    div-inv [=>]99.4

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

    pow2 [=>]99.4

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

    +-commutative [=>]99.4

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

    distribute-neg-in [=>]99.4

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

    neg-mul-1 [=>]99.4

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

    metadata-eval [=>]99.4

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

    fma-def [=>]99.4

    \[ \left(-\left(1 - {\tan x}^{2}\right)\right) \cdot \frac{1}{\color{blue}{\mathsf{fma}\left(-1, \tan x \cdot \tan x, -1\right)}} \]

    pow2 [=>]99.4

    \[ \left(-\left(1 - {\tan x}^{2}\right)\right) \cdot \frac{1}{\mathsf{fma}\left(-1, \color{blue}{{\tan x}^{2}}, -1\right)} \]
  3. Simplified99.4%

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\tan x, \tan x, -1\right)}{-1 - {\tan x}^{2}}} \]
    Proof

    [Start]99.4

    \[ \left(-\left(1 - {\tan x}^{2}\right)\right) \cdot \frac{1}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)} \]

    associate-*r/ [=>]99.4

    \[ \color{blue}{\frac{\left(-\left(1 - {\tan x}^{2}\right)\right) \cdot 1}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)}} \]

    *-rgt-identity [=>]99.4

    \[ \frac{\color{blue}{-\left(1 - {\tan x}^{2}\right)}}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)} \]

    neg-sub0 [=>]99.4

    \[ \frac{\color{blue}{0 - \left(1 - {\tan x}^{2}\right)}}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)} \]

    associate--r- [=>]99.4

    \[ \frac{\color{blue}{\left(0 - 1\right) + {\tan x}^{2}}}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)} \]

    metadata-eval [=>]99.4

    \[ \frac{\color{blue}{-1} + {\tan x}^{2}}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)} \]

    +-commutative [<=]99.4

    \[ \frac{\color{blue}{{\tan x}^{2} + -1}}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)} \]

    unpow2 [=>]99.4

    \[ \frac{\color{blue}{\tan x \cdot \tan x} + -1}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)} \]

    fma-def [=>]99.4

    \[ \frac{\color{blue}{\mathsf{fma}\left(\tan x, \tan x, -1\right)}}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)} \]

    fma-udef [=>]99.4

    \[ \frac{\mathsf{fma}\left(\tan x, \tan x, -1\right)}{\color{blue}{-1 \cdot {\tan x}^{2} + -1}} \]

    neg-mul-1 [<=]99.4

    \[ \frac{\mathsf{fma}\left(\tan x, \tan x, -1\right)}{\color{blue}{\left(-{\tan x}^{2}\right)} + -1} \]

    +-commutative [=>]99.4

    \[ \frac{\mathsf{fma}\left(\tan x, \tan x, -1\right)}{\color{blue}{-1 + \left(-{\tan x}^{2}\right)}} \]

    unsub-neg [=>]99.4

    \[ \frac{\mathsf{fma}\left(\tan x, \tan x, -1\right)}{\color{blue}{-1 - {\tan x}^{2}}} \]
  4. Final simplification99.4%

    \[\leadsto \frac{\mathsf{fma}\left(\tan x, \tan x, -1\right)}{-1 - {\tan x}^{2}} \]

Alternatives

Alternative 1
Accuracy60.1%
Cost39108
\[\begin{array}{l} \mathbf{if}\;\tan x \cdot \tan x \leq 1:\\ \;\;\;\;\frac{-1}{{\left(\sqrt[3]{-1 - {\tan x}^{2}}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;-1 + e^{\log 2 - x \cdot x}\\ \end{array} \]
Alternative 2
Accuracy60.1%
Cost38980
\[\begin{array}{l} \mathbf{if}\;\tan x \cdot \tan x \leq 1:\\ \;\;\;\;\sqrt[3]{{\left({\tan x}^{2} - -1\right)}^{-3}}\\ \mathbf{else}:\\ \;\;\;\;-1 + e^{\log 2 - x \cdot x}\\ \end{array} \]
Alternative 3
Accuracy60.1%
Cost26500
\[\begin{array}{l} \mathbf{if}\;\tan x \cdot \tan x \leq 1:\\ \;\;\;\;-1 + \left(1 + \frac{-1}{-1 - {\tan x}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;-1 + e^{\log 2 - x \cdot x}\\ \end{array} \]
Alternative 4
Accuracy60.1%
Cost26313
\[\begin{array}{l} \mathbf{if}\;\tan x \leq -1 \lor \neg \left(\tan x \leq 1\right):\\ \;\;\;\;-1 + e^{\log 2 - x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{-1 - {\tan x}^{2}}\\ \end{array} \]
Alternative 5
Accuracy59.0%
Cost26249
\[\begin{array}{l} t_0 := -1 - {\tan x}^{2}\\ \mathbf{if}\;\tan x \leq -1 \lor \neg \left(\tan x \leq 1\right):\\ \;\;\;\;\frac{1}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{t_0}\\ \end{array} \]
Alternative 6
Accuracy99.5%
Cost26176
\[\begin{array}{l} t_0 := {\tan x}^{2}\\ \frac{1 - t_0}{t_0 + 1} \end{array} \]
Alternative 7
Accuracy55.0%
Cost13184
\[\frac{-1}{-1 - {\tan x}^{2}} \]
Alternative 8
Accuracy54.7%
Cost64
\[1 \]

Error

Reproduce?

herbie shell --seed 2023153 
(FPCore (x)
  :name "Trigonometry B"
  :precision binary64
  (/ (- 1.0 (* (tan x) (tan x))) (+ 1.0 (* (tan x) (tan x)))))