
(FPCore (x) :precision binary64 (let* ((t_0 (* (tan x) (tan x)))) (/ (- 1.0 t_0) (+ 1.0 t_0))))
double code(double x) {
double t_0 = tan(x) * tan(x);
return (1.0 - t_0) / (1.0 + t_0);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = tan(x) * tan(x)
code = (1.0d0 - t_0) / (1.0d0 + t_0)
end function
public static double code(double x) {
double t_0 = Math.tan(x) * Math.tan(x);
return (1.0 - t_0) / (1.0 + t_0);
}
def code(x): t_0 = math.tan(x) * math.tan(x) return (1.0 - t_0) / (1.0 + t_0)
function code(x) t_0 = Float64(tan(x) * tan(x)) return Float64(Float64(1.0 - t_0) / Float64(1.0 + t_0)) end
function tmp = code(x) t_0 = tan(x) * tan(x); tmp = (1.0 - t_0) / (1.0 + t_0); end
code[x_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]}, N[(N[(1.0 - t$95$0), $MachinePrecision] / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan x \cdot \tan x\\
\frac{1 - t\_0}{1 + t\_0}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (let* ((t_0 (* (tan x) (tan x)))) (/ (- 1.0 t_0) (+ 1.0 t_0))))
double code(double x) {
double t_0 = tan(x) * tan(x);
return (1.0 - t_0) / (1.0 + t_0);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = tan(x) * tan(x)
code = (1.0d0 - t_0) / (1.0d0 + t_0)
end function
public static double code(double x) {
double t_0 = Math.tan(x) * Math.tan(x);
return (1.0 - t_0) / (1.0 + t_0);
}
def code(x): t_0 = math.tan(x) * math.tan(x) return (1.0 - t_0) / (1.0 + t_0)
function code(x) t_0 = Float64(tan(x) * tan(x)) return Float64(Float64(1.0 - t_0) / Float64(1.0 + t_0)) end
function tmp = code(x) t_0 = tan(x) * tan(x); tmp = (1.0 - t_0) / (1.0 + t_0); end
code[x_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]}, N[(N[(1.0 - t$95$0), $MachinePrecision] / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan x \cdot \tan x\\
\frac{1 - t\_0}{1 + t\_0}
\end{array}
\end{array}
(FPCore (x) :precision binary64 (let* ((t_0 (pow (tan x) 2.0))) (/ (- 1.0 t_0) (+ 1.0 t_0))))
double code(double x) {
double t_0 = pow(tan(x), 2.0);
return (1.0 - t_0) / (1.0 + t_0);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = tan(x) ** 2.0d0
code = (1.0d0 - t_0) / (1.0d0 + t_0)
end function
public static double code(double x) {
double t_0 = Math.pow(Math.tan(x), 2.0);
return (1.0 - t_0) / (1.0 + t_0);
}
def code(x): t_0 = math.pow(math.tan(x), 2.0) return (1.0 - t_0) / (1.0 + t_0)
function code(x) t_0 = tan(x) ^ 2.0 return Float64(Float64(1.0 - t_0) / Float64(1.0 + t_0)) end
function tmp = code(x) t_0 = tan(x) ^ 2.0; tmp = (1.0 - t_0) / (1.0 + t_0); end
code[x_] := Block[{t$95$0 = N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]}, N[(N[(1.0 - t$95$0), $MachinePrecision] / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\tan x}^{2}\\
\frac{1 - t\_0}{1 + t\_0}
\end{array}
\end{array}
Initial program 99.6%
clear-num99.4%
inv-pow99.4%
add-sqr-sqrt99.2%
pow299.2%
hypot-1-def99.2%
pow299.2%
Applied egg-rr99.2%
unpow-199.2%
hypot-1-def99.2%
pow299.2%
sqrt-pow299.4%
metadata-eval99.4%
pow199.4%
clear-num99.6%
+-commutative99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (<= (* (tan x) (tan x)) 1.0) (/ 1.0 (+ 1.0 (pow (tan x) 2.0))) (/ 1.0 (/ (fma x x 1.0) (- 1.0 (pow x 2.0))))))
double code(double x) {
double tmp;
if ((tan(x) * tan(x)) <= 1.0) {
tmp = 1.0 / (1.0 + pow(tan(x), 2.0));
} else {
tmp = 1.0 / (fma(x, x, 1.0) / (1.0 - pow(x, 2.0)));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(tan(x) * tan(x)) <= 1.0) tmp = Float64(1.0 / Float64(1.0 + (tan(x) ^ 2.0))); else tmp = Float64(1.0 / Float64(fma(x, x, 1.0) / Float64(1.0 - (x ^ 2.0)))); end return tmp end
code[x_] := If[LessEqual[N[(N[Tan[x], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision], 1.0], N[(1.0 / N[(1.0 + N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(x * x + 1.0), $MachinePrecision] / N[(1.0 - N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\tan x \cdot \tan x \leq 1:\\
\;\;\;\;\frac{1}{1 + {\tan x}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{fma}\left(x, x, 1\right)}{1 - {x}^{2}}}\\
\end{array}
\end{array}
if (*.f64 (tan.f64 x) (tan.f64 x)) < 1Initial program 99.7%
clear-num99.6%
inv-pow99.6%
add-sqr-sqrt99.4%
pow299.4%
hypot-1-def99.4%
pow299.4%
Applied egg-rr99.4%
unpow-199.4%
hypot-1-def99.4%
pow299.4%
sqrt-pow299.6%
metadata-eval99.6%
pow199.6%
clear-num99.7%
+-commutative99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 72.9%
if 1 < (*.f64 (tan.f64 x) (tan.f64 x)) Initial program 99.4%
clear-num99.0%
inv-pow99.0%
add-sqr-sqrt98.7%
pow298.7%
hypot-1-def98.6%
pow298.6%
Applied egg-rr98.6%
unpow-198.6%
unpow298.6%
hypot-1-def98.7%
pow298.7%
hypot-1-def98.7%
pow298.7%
add-sqr-sqrt99.0%
+-commutative99.0%
Applied egg-rr99.0%
Taylor expanded in x around 0 4.5%
Taylor expanded in x around 0 11.2%
+-commutative11.2%
unpow211.2%
fma-def11.2%
Simplified11.2%
Final simplification56.3%
(FPCore (x) :precision binary64 (/ 1.0 (+ 1.0 (pow (tan x) 2.0))))
double code(double x) {
return 1.0 / (1.0 + pow(tan(x), 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (1.0d0 + (tan(x) ** 2.0d0))
end function
public static double code(double x) {
return 1.0 / (1.0 + Math.pow(Math.tan(x), 2.0));
}
def code(x): return 1.0 / (1.0 + math.pow(math.tan(x), 2.0))
function code(x) return Float64(1.0 / Float64(1.0 + (tan(x) ^ 2.0))) end
function tmp = code(x) tmp = 1.0 / (1.0 + (tan(x) ^ 2.0)); end
code[x_] := N[(1.0 / N[(1.0 + N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + {\tan x}^{2}}
\end{array}
Initial program 99.6%
clear-num99.4%
inv-pow99.4%
add-sqr-sqrt99.2%
pow299.2%
hypot-1-def99.2%
pow299.2%
Applied egg-rr99.2%
unpow-199.2%
hypot-1-def99.2%
pow299.2%
sqrt-pow299.4%
metadata-eval99.4%
pow199.4%
clear-num99.6%
+-commutative99.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 53.7%
Final simplification53.7%
(FPCore (x) :precision binary64 (/ 1.0 (- 1.0 (pow (tan x) 4.0))))
double code(double x) {
return 1.0 / (1.0 - pow(tan(x), 4.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (1.0d0 - (tan(x) ** 4.0d0))
end function
public static double code(double x) {
return 1.0 / (1.0 - Math.pow(Math.tan(x), 4.0));
}
def code(x): return 1.0 / (1.0 - math.pow(math.tan(x), 4.0))
function code(x) return Float64(1.0 / Float64(1.0 - (tan(x) ^ 4.0))) end
function tmp = code(x) tmp = 1.0 / (1.0 - (tan(x) ^ 4.0)); end
code[x_] := N[(1.0 / N[(1.0 - N[Power[N[Tan[x], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 - {\tan x}^{4}}
\end{array}
Initial program 99.6%
flip-+99.5%
associate-/r/99.4%
pow299.4%
metadata-eval99.4%
pow299.4%
pow299.4%
pow-prod-up99.3%
metadata-eval99.3%
pow299.3%
Applied egg-rr99.3%
associate-*l/99.3%
unpow299.3%
Simplified99.3%
Taylor expanded in x around 0 57.0%
Final simplification57.0%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 99.6%
clear-num99.4%
inv-pow99.4%
add-sqr-sqrt99.2%
pow299.2%
hypot-1-def99.2%
pow299.2%
Applied egg-rr99.2%
unpow-199.2%
hypot-1-def99.2%
pow299.2%
sqrt-pow299.4%
metadata-eval99.4%
pow199.4%
clear-num99.6%
+-commutative99.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 53.3%
Final simplification53.3%
herbie shell --seed 2024027
(FPCore (x)
:name "Trigonometry B"
:precision binary64
(/ (- 1.0 (* (tan x) (tan x))) (+ 1.0 (* (tan x) (tan x)))))