
(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 7 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.4%
/-lowering-/.f64N/A
--lowering--.f64N/A
pow2N/A
pow-lowering-pow.f64N/A
tan-lowering-tan.f64N/A
+-lowering-+.f64N/A
pow2N/A
pow-lowering-pow.f64N/A
tan-lowering-tan.f6499.4%
Applied egg-rr99.4%
(FPCore (x) :precision binary64 (let* ((t_0 (pow (tan x) 2.0))) (if (<= (* (tan x) (tan x)) 0.6) (exp (* -2.0 (log1p t_0))) (- 1.0 t_0))))
double code(double x) {
double t_0 = pow(tan(x), 2.0);
double tmp;
if ((tan(x) * tan(x)) <= 0.6) {
tmp = exp((-2.0 * log1p(t_0)));
} else {
tmp = 1.0 - t_0;
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.pow(Math.tan(x), 2.0);
double tmp;
if ((Math.tan(x) * Math.tan(x)) <= 0.6) {
tmp = Math.exp((-2.0 * Math.log1p(t_0)));
} else {
tmp = 1.0 - t_0;
}
return tmp;
}
def code(x): t_0 = math.pow(math.tan(x), 2.0) tmp = 0 if (math.tan(x) * math.tan(x)) <= 0.6: tmp = math.exp((-2.0 * math.log1p(t_0))) else: tmp = 1.0 - t_0 return tmp
function code(x) t_0 = tan(x) ^ 2.0 tmp = 0.0 if (Float64(tan(x) * tan(x)) <= 0.6) tmp = exp(Float64(-2.0 * log1p(t_0))); else tmp = Float64(1.0 - t_0); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[N[(N[Tan[x], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision], 0.6], N[Exp[N[(-2.0 * N[Log[1 + t$95$0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(1.0 - t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\tan x}^{2}\\
\mathbf{if}\;\tan x \cdot \tan x \leq 0.6:\\
\;\;\;\;e^{-2 \cdot \mathsf{log1p}\left(t\_0\right)}\\
\mathbf{else}:\\
\;\;\;\;1 - t\_0\\
\end{array}
\end{array}
if (*.f64 (tan.f64 x) (tan.f64 x)) < 0.599999999999999978Initial program 99.8%
div-invN/A
flip--N/A
div-invN/A
associate-*l*N/A
*-lowering-*.f64N/A
Applied egg-rr99.6%
Taylor expanded in x around 0
Simplified79.5%
*-lft-identityN/A
pow-to-expN/A
exp-lowering-exp.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
metadata-evalN/A
pow-flipN/A
log1p-defineN/A
log1p-lowering-log1p.f64N/A
pow-flipN/A
metadata-evalN/A
pow-lowering-pow.f64N/A
tan-lowering-tan.f6479.5%
Applied egg-rr79.5%
if 0.599999999999999978 < (*.f64 (tan.f64 x) (tan.f64 x)) Initial program 98.6%
/-lowering-/.f64N/A
--lowering--.f64N/A
pow2N/A
pow-lowering-pow.f64N/A
tan-lowering-tan.f64N/A
+-lowering-+.f64N/A
pow2N/A
pow-lowering-pow.f64N/A
tan-lowering-tan.f6498.6%
Applied egg-rr98.6%
Taylor expanded in x around 0
Simplified16.9%
Final simplification59.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (* 0.5 (cos (* x 2.0)))))
(if (<= (* (tan x) (tan x)) 0.6)
(pow (+ 1.0 (/ (- 0.5 t_0) (+ 0.5 t_0))) -2.0)
(- 1.0 (pow (tan x) 2.0)))))
double code(double x) {
double t_0 = 0.5 * cos((x * 2.0));
double tmp;
if ((tan(x) * tan(x)) <= 0.6) {
tmp = pow((1.0 + ((0.5 - t_0) / (0.5 + t_0))), -2.0);
} else {
tmp = 1.0 - pow(tan(x), 2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * cos((x * 2.0d0))
if ((tan(x) * tan(x)) <= 0.6d0) then
tmp = (1.0d0 + ((0.5d0 - t_0) / (0.5d0 + t_0))) ** (-2.0d0)
else
tmp = 1.0d0 - (tan(x) ** 2.0d0)
end if
code = tmp
end function
public static double code(double x) {
double t_0 = 0.5 * Math.cos((x * 2.0));
double tmp;
if ((Math.tan(x) * Math.tan(x)) <= 0.6) {
tmp = Math.pow((1.0 + ((0.5 - t_0) / (0.5 + t_0))), -2.0);
} else {
tmp = 1.0 - Math.pow(Math.tan(x), 2.0);
}
return tmp;
}
def code(x): t_0 = 0.5 * math.cos((x * 2.0)) tmp = 0 if (math.tan(x) * math.tan(x)) <= 0.6: tmp = math.pow((1.0 + ((0.5 - t_0) / (0.5 + t_0))), -2.0) else: tmp = 1.0 - math.pow(math.tan(x), 2.0) return tmp
function code(x) t_0 = Float64(0.5 * cos(Float64(x * 2.0))) tmp = 0.0 if (Float64(tan(x) * tan(x)) <= 0.6) tmp = Float64(1.0 + Float64(Float64(0.5 - t_0) / Float64(0.5 + t_0))) ^ -2.0; else tmp = Float64(1.0 - (tan(x) ^ 2.0)); end return tmp end
function tmp_2 = code(x) t_0 = 0.5 * cos((x * 2.0)); tmp = 0.0; if ((tan(x) * tan(x)) <= 0.6) tmp = (1.0 + ((0.5 - t_0) / (0.5 + t_0))) ^ -2.0; else tmp = 1.0 - (tan(x) ^ 2.0); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(0.5 * N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[Tan[x], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision], 0.6], N[Power[N[(1.0 + N[(N[(0.5 - t$95$0), $MachinePrecision] / N[(0.5 + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision], N[(1.0 - N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \cos \left(x \cdot 2\right)\\
\mathbf{if}\;\tan x \cdot \tan x \leq 0.6:\\
\;\;\;\;{\left(1 + \frac{0.5 - t\_0}{0.5 + t\_0}\right)}^{-2}\\
\mathbf{else}:\\
\;\;\;\;1 - {\tan x}^{2}\\
\end{array}
\end{array}
if (*.f64 (tan.f64 x) (tan.f64 x)) < 0.599999999999999978Initial program 99.8%
div-invN/A
flip--N/A
div-invN/A
associate-*l*N/A
*-lowering-*.f64N/A
Applied egg-rr99.6%
Taylor expanded in x around 0
Simplified79.5%
unpow2N/A
tan-quotN/A
tan-quotN/A
frac-timesN/A
unpow2N/A
metadata-evalN/A
unpow2N/A
metadata-evalN/A
/-lowering-/.f64N/A
metadata-evalN/A
unpow2N/A
sqr-sin-aN/A
metadata-evalN/A
--lowering--.f64N/A
metadata-evalN/A
metadata-evalN/A
*-lowering-*.f64N/A
metadata-evalN/A
cos-lowering-cos.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
unpow2N/A
sqr-cos-aN/A
metadata-evalN/A
Applied egg-rr79.5%
if 0.599999999999999978 < (*.f64 (tan.f64 x) (tan.f64 x)) Initial program 98.6%
/-lowering-/.f64N/A
--lowering--.f64N/A
pow2N/A
pow-lowering-pow.f64N/A
tan-lowering-tan.f64N/A
+-lowering-+.f64N/A
pow2N/A
pow-lowering-pow.f64N/A
tan-lowering-tan.f6498.6%
Applied egg-rr98.6%
Taylor expanded in x around 0
Simplified16.9%
Final simplification59.6%
(FPCore (x) :precision binary64 (let* ((t_0 (pow (tan x) 2.0))) (if (<= (* (tan x) (tan x)) 0.6) (pow (+ 1.0 t_0) -2.0) (- 1.0 t_0))))
double code(double x) {
double t_0 = pow(tan(x), 2.0);
double tmp;
if ((tan(x) * tan(x)) <= 0.6) {
tmp = pow((1.0 + t_0), -2.0);
} else {
tmp = 1.0 - t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = tan(x) ** 2.0d0
if ((tan(x) * tan(x)) <= 0.6d0) then
tmp = (1.0d0 + t_0) ** (-2.0d0)
else
tmp = 1.0d0 - t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.pow(Math.tan(x), 2.0);
double tmp;
if ((Math.tan(x) * Math.tan(x)) <= 0.6) {
tmp = Math.pow((1.0 + t_0), -2.0);
} else {
tmp = 1.0 - t_0;
}
return tmp;
}
def code(x): t_0 = math.pow(math.tan(x), 2.0) tmp = 0 if (math.tan(x) * math.tan(x)) <= 0.6: tmp = math.pow((1.0 + t_0), -2.0) else: tmp = 1.0 - t_0 return tmp
function code(x) t_0 = tan(x) ^ 2.0 tmp = 0.0 if (Float64(tan(x) * tan(x)) <= 0.6) tmp = Float64(1.0 + t_0) ^ -2.0; else tmp = Float64(1.0 - t_0); end return tmp end
function tmp_2 = code(x) t_0 = tan(x) ^ 2.0; tmp = 0.0; if ((tan(x) * tan(x)) <= 0.6) tmp = (1.0 + t_0) ^ -2.0; else tmp = 1.0 - t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[N[(N[Tan[x], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision], 0.6], N[Power[N[(1.0 + t$95$0), $MachinePrecision], -2.0], $MachinePrecision], N[(1.0 - t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\tan x}^{2}\\
\mathbf{if}\;\tan x \cdot \tan x \leq 0.6:\\
\;\;\;\;{\left(1 + t\_0\right)}^{-2}\\
\mathbf{else}:\\
\;\;\;\;1 - t\_0\\
\end{array}
\end{array}
if (*.f64 (tan.f64 x) (tan.f64 x)) < 0.599999999999999978Initial program 99.8%
div-invN/A
flip--N/A
div-invN/A
associate-*l*N/A
*-lowering-*.f64N/A
Applied egg-rr99.6%
Taylor expanded in x around 0
Simplified79.5%
*-lft-identityN/A
metadata-evalN/A
pow-flipN/A
pow-lowering-pow.f64N/A
+-lowering-+.f64N/A
pow-flipN/A
metadata-evalN/A
pow-lowering-pow.f64N/A
tan-lowering-tan.f6479.5%
Applied egg-rr79.5%
if 0.599999999999999978 < (*.f64 (tan.f64 x) (tan.f64 x)) Initial program 98.6%
/-lowering-/.f64N/A
--lowering--.f64N/A
pow2N/A
pow-lowering-pow.f64N/A
tan-lowering-tan.f64N/A
+-lowering-+.f64N/A
pow2N/A
pow-lowering-pow.f64N/A
tan-lowering-tan.f6498.6%
Applied egg-rr98.6%
Taylor expanded in x around 0
Simplified16.9%
Final simplification59.6%
(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.4%
flip-+N/A
associate-/r/N/A
associate-*l/N/A
/-lowering-/.f64N/A
pow2N/A
pow-lowering-pow.f64N/A
--lowering--.f64N/A
pow2N/A
pow-lowering-pow.f64N/A
tan-lowering-tan.f64N/A
metadata-evalN/A
--lowering--.f64N/A
Applied egg-rr99.2%
Taylor expanded in x around 0
Simplified56.8%
(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.4%
/-lowering-/.f64N/A
--lowering--.f64N/A
pow2N/A
pow-lowering-pow.f64N/A
tan-lowering-tan.f64N/A
+-lowering-+.f64N/A
pow2N/A
pow-lowering-pow.f64N/A
tan-lowering-tan.f6499.4%
Applied egg-rr99.4%
Taylor expanded in x around 0
Simplified57.8%
Final simplification57.8%
(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.4%
Taylor expanded in x around 0
Simplified53.1%
herbie shell --seed 2024150
(FPCore (x)
:name "Trigonometry B"
:precision binary64
(/ (- 1.0 (* (tan x) (tan x))) (+ 1.0 (* (tan x) (tan x)))))