
(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 3 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%
add-log-exp99.2%
*-un-lft-identity99.2%
log-prod99.2%
metadata-eval99.2%
add-log-exp99.5%
pow299.5%
add-sqr-sqrt99.2%
pow299.2%
hypot-1-def99.2%
Applied egg-rr99.2%
+-lft-identity99.2%
unpow299.2%
hypot-undefine99.3%
metadata-eval99.3%
unpow299.3%
rem-exp-log99.3%
log1p-undefine99.3%
hypot-undefine99.2%
metadata-eval99.2%
unpow299.2%
rem-exp-log99.2%
log1p-undefine99.2%
rem-square-sqrt99.3%
log1p-undefine99.3%
rem-exp-log99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (- 1.0 (pow (tan x) 2.0)))
double code(double x) {
return 1.0 - pow(tan(x), 2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - (tan(x) ** 2.0d0)
end function
public static double code(double x) {
return 1.0 - Math.pow(Math.tan(x), 2.0);
}
def code(x): return 1.0 - math.pow(math.tan(x), 2.0)
function code(x) return Float64(1.0 - (tan(x) ^ 2.0)) end
function tmp = code(x) tmp = 1.0 - (tan(x) ^ 2.0); end
code[x_] := N[(1.0 - N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - {\tan x}^{2}
\end{array}
Initial program 99.5%
add-log-exp99.2%
*-un-lft-identity99.2%
log-prod99.2%
metadata-eval99.2%
add-log-exp99.5%
pow299.5%
add-sqr-sqrt99.2%
pow299.2%
hypot-1-def99.2%
Applied egg-rr99.2%
+-lft-identity99.2%
unpow299.2%
hypot-undefine99.3%
metadata-eval99.3%
unpow299.3%
rem-exp-log99.3%
log1p-undefine99.3%
hypot-undefine99.2%
metadata-eval99.2%
unpow299.2%
rem-exp-log99.2%
log1p-undefine99.2%
rem-square-sqrt99.3%
log1p-undefine99.3%
rem-exp-log99.5%
Simplified99.5%
Taylor expanded in x around 0 53.8%
add-exp-log53.8%
log-rec53.8%
log1p-define53.8%
Applied egg-rr53.8%
add-sqr-sqrt20.7%
sqrt-unprod53.4%
sqr-neg53.4%
sqrt-unprod53.4%
add-sqr-sqrt53.4%
log1p-undefine53.4%
add-exp-log53.4%
+-commutative53.4%
unpow253.4%
fma-define53.4%
add-sqr-sqrt27.5%
sqrt-prod55.6%
sqr-neg55.6%
sqrt-unprod28.1%
add-sqr-sqrt58.4%
fma-undefine58.4%
+-commutative58.4%
*-commutative58.4%
cancel-sign-sub-inv58.4%
unpow258.4%
Applied egg-rr58.4%
Final simplification58.4%
(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.5%
add-log-exp99.2%
*-un-lft-identity99.2%
log-prod99.2%
metadata-eval99.2%
add-log-exp99.5%
pow299.5%
add-sqr-sqrt99.2%
pow299.2%
hypot-1-def99.2%
Applied egg-rr99.2%
+-lft-identity99.2%
unpow299.2%
hypot-undefine99.3%
metadata-eval99.3%
unpow299.3%
rem-exp-log99.3%
log1p-undefine99.3%
hypot-undefine99.2%
metadata-eval99.2%
unpow299.2%
rem-exp-log99.2%
log1p-undefine99.2%
rem-square-sqrt99.3%
log1p-undefine99.3%
rem-exp-log99.5%
Simplified99.5%
Taylor expanded in x around 0 53.8%
Taylor expanded in x around 0 53.5%
Final simplification53.5%
herbie shell --seed 2024095
(FPCore (x)
:name "Trigonometry B"
:precision binary64
(/ (- 1.0 (* (tan x) (tan x))) (+ 1.0 (* (tan x) (tan x)))))