
(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
double code(double x) {
return (x - sin(x)) / (x - tan(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x - sin(x)) / (x - tan(x))
end function
public static double code(double x) {
return (x - Math.sin(x)) / (x - Math.tan(x));
}
def code(x): return (x - math.sin(x)) / (x - math.tan(x))
function code(x) return Float64(Float64(x - sin(x)) / Float64(x - tan(x))) end
function tmp = code(x) tmp = (x - sin(x)) / (x - tan(x)); end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - \sin x}{x - \tan x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
double code(double x) {
return (x - sin(x)) / (x - tan(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x - sin(x)) / (x - tan(x))
end function
public static double code(double x) {
return (x - Math.sin(x)) / (x - Math.tan(x));
}
def code(x): return (x - math.sin(x)) / (x - math.tan(x))
function code(x) return Float64(Float64(x - sin(x)) / Float64(x - tan(x))) end
function tmp = code(x) tmp = (x - sin(x)) / (x - tan(x)); end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - \sin x}{x - \tan x}
\end{array}
(FPCore (x) :precision binary64 (let* ((t_0 (/ (- x (sin x)) (- x (tan x))))) (if (<= t_0 2.0) t_0 -0.5)))
double code(double x) {
double t_0 = (x - sin(x)) / (x - tan(x));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = -0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (x - sin(x)) / (x - tan(x))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = -0.5d0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (x - Math.sin(x)) / (x - Math.tan(x));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = -0.5;
}
return tmp;
}
def code(x): t_0 = (x - math.sin(x)) / (x - math.tan(x)) tmp = 0 if t_0 <= 2.0: tmp = t_0 else: tmp = -0.5 return tmp
function code(x) t_0 = Float64(Float64(x - sin(x)) / Float64(x - tan(x))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = -0.5; end return tmp end
function tmp_2 = code(x) t_0 = (x - sin(x)) / (x - tan(x)); tmp = 0.0; if (t_0 <= 2.0) tmp = t_0; else tmp = -0.5; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, -0.5]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - \sin x}{x - \tan x}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;-0.5\\
\end{array}
\end{array}
if (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x))) < 2Initial program 100.0%
if 2 < (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x))) Initial program 0.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= x 1.55) -0.5 1.0))
double code(double x) {
double tmp;
if (x <= 1.55) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.55d0) then
tmp = -0.5d0
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.55) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.55: tmp = -0.5 else: tmp = 1.0 return tmp
function code(x) tmp = 0.0 if (x <= 1.55) tmp = -0.5; else tmp = 1.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.55) tmp = -0.5; else tmp = 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.55], -0.5, 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.55:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.55000000000000004Initial program 34.5%
Taylor expanded in x around 0 66.0%
if 1.55000000000000004 < x Initial program 100.0%
Taylor expanded in x around inf 97.9%
Final simplification74.1%
(FPCore (x) :precision binary64 -0.5)
double code(double x) {
return -0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -0.5d0
end function
public static double code(double x) {
return -0.5;
}
def code(x): return -0.5
function code(x) return -0.5 end
function tmp = code(x) tmp = -0.5; end
code[x_] := -0.5
\begin{array}{l}
\\
-0.5
\end{array}
Initial program 51.2%
Taylor expanded in x around 0 49.6%
Final simplification49.6%
herbie shell --seed 2023297
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))