| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 26560 |

(FPCore (x) :precision binary64 (/ (- 1.0 (* (tan x) (tan x))) (+ 1.0 (* (tan x) (tan x)))))
(FPCore (x) :precision binary64 (let* ((t_0 (/ (tan x) (/ 1.0 (tan x))))) (/ (+ t_0 -1.0) (- -1.0 t_0))))
double code(double x) {
return (1.0 - (tan(x) * tan(x))) / (1.0 + (tan(x) * tan(x)));
}
double code(double x) {
double t_0 = tan(x) / (1.0 / tan(x));
return (t_0 + -1.0) / (-1.0 - t_0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 - (tan(x) * tan(x))) / (1.0d0 + (tan(x) * tan(x)))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = tan(x) / (1.0d0 / tan(x))
code = (t_0 + (-1.0d0)) / ((-1.0d0) - t_0)
end function
public static double code(double x) {
return (1.0 - (Math.tan(x) * Math.tan(x))) / (1.0 + (Math.tan(x) * Math.tan(x)));
}
public static double code(double x) {
double t_0 = Math.tan(x) / (1.0 / Math.tan(x));
return (t_0 + -1.0) / (-1.0 - t_0);
}
def code(x): return (1.0 - (math.tan(x) * math.tan(x))) / (1.0 + (math.tan(x) * math.tan(x)))
def code(x): t_0 = math.tan(x) / (1.0 / math.tan(x)) return (t_0 + -1.0) / (-1.0 - t_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) t_0 = Float64(tan(x) / Float64(1.0 / tan(x))) return Float64(Float64(t_0 + -1.0) / Float64(-1.0 - t_0)) end
function tmp = code(x) tmp = (1.0 - (tan(x) * tan(x))) / (1.0 + (tan(x) * tan(x))); end
function tmp = code(x) t_0 = tan(x) / (1.0 / tan(x)); tmp = (t_0 + -1.0) / (-1.0 - t_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_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] / N[(1.0 / N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$0 + -1.0), $MachinePrecision] / N[(-1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]]
\frac{1 - \tan x \cdot \tan x}{1 + \tan x \cdot \tan x}
\begin{array}{l}
t_0 := \frac{\tan x}{\frac{1}{\tan x}}\\
\frac{t_0 + -1}{-1 - t_0}
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 99.6%
Applied egg-rr99.5%
[Start]99.6% | \[ \frac{1 - \tan x \cdot \tan x}{1 + \tan x \cdot \tan x}
\] |
|---|---|
frac-2neg [=>]99.6% | \[ \color{blue}{\frac{-\left(1 - \tan x \cdot \tan x\right)}{-\left(1 + \tan x \cdot \tan x\right)}}
\] |
div-inv [=>]99.5% | \[ \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.5% | \[ \left(-\left(1 - \color{blue}{{\tan x}^{2}}\right)\right) \cdot \frac{1}{-\left(1 + \tan x \cdot \tan x\right)}
\] |
+-commutative [=>]99.5% | \[ \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.5% | \[ \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.5% | \[ \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.5% | \[ \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.5% | \[ \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.5% | \[ \left(-\left(1 - {\tan x}^{2}\right)\right) \cdot \frac{1}{\mathsf{fma}\left(-1, \color{blue}{{\tan x}^{2}}, -1\right)}
\] |
Simplified99.6%
[Start]99.5% | \[ \left(-\left(1 - {\tan x}^{2}\right)\right) \cdot \frac{1}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)}
\] |
|---|---|
associate-*r/ [=>]99.6% | \[ \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.6% | \[ \frac{\color{blue}{-\left(1 - {\tan x}^{2}\right)}}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)}
\] |
neg-sub0 [=>]99.6% | \[ \frac{\color{blue}{0 - \left(1 - {\tan x}^{2}\right)}}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)}
\] |
associate--r- [=>]99.6% | \[ \frac{\color{blue}{\left(0 - 1\right) + {\tan x}^{2}}}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)}
\] |
metadata-eval [=>]99.6% | \[ \frac{\color{blue}{-1} + {\tan x}^{2}}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)}
\] |
+-commutative [<=]99.6% | \[ \frac{\color{blue}{{\tan x}^{2} + -1}}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)}
\] |
unpow2 [=>]99.6% | \[ \frac{\color{blue}{\tan x \cdot \tan x} + -1}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)}
\] |
fma-udef [<=]99.6% | \[ \frac{\color{blue}{\mathsf{fma}\left(\tan x, \tan x, -1\right)}}{\mathsf{fma}\left(-1, {\tan x}^{2}, -1\right)}
\] |
fma-udef [=>]99.6% | \[ \frac{\mathsf{fma}\left(\tan x, \tan x, -1\right)}{\color{blue}{-1 \cdot {\tan x}^{2} + -1}}
\] |
neg-mul-1 [<=]99.6% | \[ \frac{\mathsf{fma}\left(\tan x, \tan x, -1\right)}{\color{blue}{\left(-{\tan x}^{2}\right)} + -1}
\] |
+-commutative [=>]99.6% | \[ \frac{\mathsf{fma}\left(\tan x, \tan x, -1\right)}{\color{blue}{-1 + \left(-{\tan x}^{2}\right)}}
\] |
unsub-neg [=>]99.6% | \[ \frac{\mathsf{fma}\left(\tan x, \tan x, -1\right)}{\color{blue}{-1 - {\tan x}^{2}}}
\] |
Applied egg-rr99.6%
[Start]99.6% | \[ \frac{\mathsf{fma}\left(\tan x, \tan x, -1\right)}{-1 - {\tan x}^{2}}
\] |
|---|---|
fma-udef [=>]99.6% | \[ \frac{\color{blue}{\tan x \cdot \tan x + -1}}{-1 - {\tan x}^{2}}
\] |
pow2 [=>]99.6% | \[ \frac{\color{blue}{{\tan x}^{2}} + -1}{-1 - {\tan x}^{2}}
\] |
Applied egg-rr99.6%
[Start]99.6% | \[ \frac{{\tan x}^{2} + -1}{-1 - {\tan x}^{2}}
\] |
|---|---|
pow2 [<=]99.6% | \[ \frac{{\tan x}^{2} + -1}{-1 - \color{blue}{\tan x \cdot \tan x}}
\] |
tan-quot [=>]99.5% | \[ \frac{{\tan x}^{2} + -1}{-1 - \tan x \cdot \color{blue}{\frac{\sin x}{\cos x}}}
\] |
clear-num [=>]99.5% | \[ \frac{{\tan x}^{2} + -1}{-1 - \tan x \cdot \color{blue}{\frac{1}{\frac{\cos x}{\sin x}}}}
\] |
div-inv [<=]99.5% | \[ \frac{{\tan x}^{2} + -1}{-1 - \color{blue}{\frac{\tan x}{\frac{\cos x}{\sin x}}}}
\] |
clear-num [=>]99.5% | \[ \frac{{\tan x}^{2} + -1}{-1 - \frac{\tan x}{\color{blue}{\frac{1}{\frac{\sin x}{\cos x}}}}}
\] |
tan-quot [<=]99.6% | \[ \frac{{\tan x}^{2} + -1}{-1 - \frac{\tan x}{\frac{1}{\color{blue}{\tan x}}}}
\] |
Applied egg-rr99.6%
[Start]99.6% | \[ \frac{{\tan x}^{2} + -1}{-1 - {\tan x}^{2}}
\] |
|---|---|
pow2 [<=]99.6% | \[ \frac{{\tan x}^{2} + -1}{-1 - \color{blue}{\tan x \cdot \tan x}}
\] |
tan-quot [=>]99.5% | \[ \frac{{\tan x}^{2} + -1}{-1 - \tan x \cdot \color{blue}{\frac{\sin x}{\cos x}}}
\] |
clear-num [=>]99.5% | \[ \frac{{\tan x}^{2} + -1}{-1 - \tan x \cdot \color{blue}{\frac{1}{\frac{\cos x}{\sin x}}}}
\] |
div-inv [<=]99.5% | \[ \frac{{\tan x}^{2} + -1}{-1 - \color{blue}{\frac{\tan x}{\frac{\cos x}{\sin x}}}}
\] |
clear-num [=>]99.5% | \[ \frac{{\tan x}^{2} + -1}{-1 - \frac{\tan x}{\color{blue}{\frac{1}{\frac{\sin x}{\cos x}}}}}
\] |
tan-quot [<=]99.6% | \[ \frac{{\tan x}^{2} + -1}{-1 - \frac{\tan x}{\frac{1}{\color{blue}{\tan x}}}}
\] |
Final simplification99.6%
| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 26560 |
| Alternative 2 | |
|---|---|
| Accuracy | 57.2% |
| Cost | 32516 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 26176 |
| Alternative 4 | |
|---|---|
| Accuracy | 57.1% |
| Cost | 26052 |
| Alternative 5 | |
|---|---|
| Accuracy | 57.1% |
| Cost | 19972 |
| Alternative 6 | |
|---|---|
| Accuracy | 57.1% |
| Cost | 19716 |
| Alternative 7 | |
|---|---|
| Accuracy | 55.2% |
| Cost | 13184 |
| Alternative 8 | |
|---|---|
| Accuracy | 54.9% |
| Cost | 64 |
herbie shell --seed 2023271
(FPCore (x)
:name "Trigonometry B"
:precision binary64
(/ (- 1.0 (* (tan x) (tan x))) (+ 1.0 (* (tan x) (tan x)))))