
(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 6 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.5%
div-sub99.3%
*-un-lft-identity99.3%
add-sqr-sqrt99.2%
prod-diff99.3%
Applied egg-rr99.2%
fma-undefine99.1%
Simplified99.5%
Final simplification99.5%
(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.5%
div-sub99.3%
*-un-lft-identity99.3%
add-sqr-sqrt99.2%
prod-diff99.3%
Applied egg-rr99.2%
fma-undefine99.1%
Simplified99.5%
Taylor expanded in x around 0 58.1%
Final simplification58.1%
(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.5%
div-sub99.3%
*-un-lft-identity99.3%
add-sqr-sqrt99.2%
prod-diff99.3%
Applied egg-rr99.2%
fma-undefine99.1%
Simplified99.5%
Taylor expanded in x around 0 58.1%
frac-2neg58.1%
metadata-eval58.1%
div-inv58.1%
+-commutative58.1%
distribute-neg-in58.1%
pow258.1%
distribute-rgt-neg-in58.1%
pow158.1%
metadata-eval58.1%
sqrt-pow160.0%
add-sqr-sqrt30.3%
sqrt-unprod61.2%
sqr-neg61.2%
pow261.2%
add-sqr-sqrt61.2%
metadata-eval61.2%
Applied egg-rr61.2%
mul-1-neg61.2%
distribute-neg-frac261.2%
+-commutative61.2%
distribute-neg-in61.2%
metadata-eval61.2%
sub-neg61.2%
Simplified61.2%
Final simplification61.2%
(FPCore (x) :precision binary64 (pow (hypot 1.0 x) -2.0))
double code(double x) {
return pow(hypot(1.0, x), -2.0);
}
public static double code(double x) {
return Math.pow(Math.hypot(1.0, x), -2.0);
}
def code(x): return math.pow(math.hypot(1.0, x), -2.0)
function code(x) return hypot(1.0, x) ^ -2.0 end
function tmp = code(x) tmp = hypot(1.0, x) ^ -2.0; end
code[x_] := N[Power[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], -2.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(1, x\right)\right)}^{-2}
\end{array}
Initial program 99.5%
div-sub99.3%
*-un-lft-identity99.3%
add-sqr-sqrt99.2%
prod-diff99.3%
Applied egg-rr99.2%
fma-undefine99.1%
Simplified99.5%
Taylor expanded in x around 0 58.1%
Taylor expanded in x around 0 54.4%
+-commutative54.4%
unpow254.4%
fma-define54.4%
Simplified54.4%
inv-pow54.4%
add-sqr-sqrt54.4%
unpow-prod-down54.4%
Applied egg-rr54.4%
pow-sqr54.4%
fma-undefine54.4%
unpow254.4%
+-commutative54.4%
unpow254.4%
hypot-1-def54.4%
metadata-eval54.4%
Simplified54.4%
Final simplification54.4%
(FPCore (x) :precision binary64 (/ 1.0 (fma x x 1.0)))
double code(double x) {
return 1.0 / fma(x, x, 1.0);
}
function code(x) return Float64(1.0 / fma(x, x, 1.0)) end
code[x_] := N[(1.0 / N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\mathsf{fma}\left(x, x, 1\right)}
\end{array}
Initial program 99.5%
div-sub99.3%
*-un-lft-identity99.3%
add-sqr-sqrt99.2%
prod-diff99.3%
Applied egg-rr99.2%
fma-undefine99.1%
Simplified99.5%
Taylor expanded in x around 0 58.1%
Taylor expanded in x around 0 54.4%
+-commutative54.4%
unpow254.4%
fma-define54.4%
Simplified54.4%
Final simplification54.4%
(FPCore (x) :precision binary64 (/ 1.0 (pow x 2.0)))
double code(double x) {
return 1.0 / pow(x, 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x ** 2.0d0)
end function
public static double code(double x) {
return 1.0 / Math.pow(x, 2.0);
}
def code(x): return 1.0 / math.pow(x, 2.0)
function code(x) return Float64(1.0 / (x ^ 2.0)) end
function tmp = code(x) tmp = 1.0 / (x ^ 2.0); end
code[x_] := N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{{x}^{2}}
\end{array}
Initial program 99.5%
div-sub99.3%
*-un-lft-identity99.3%
add-sqr-sqrt99.2%
prod-diff99.3%
Applied egg-rr99.2%
fma-undefine99.1%
Simplified99.5%
Taylor expanded in x around 0 58.1%
Taylor expanded in x around 0 54.4%
+-commutative54.4%
unpow254.4%
fma-define54.4%
Simplified54.4%
Taylor expanded in x around inf 4.0%
Final simplification4.0%
herbie shell --seed 2024059
(FPCore (x)
:name "Trigonometry B"
:precision binary64
(/ (- 1.0 (* (tan x) (tan x))) (+ 1.0 (* (tan x) (tan x)))))