
(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 7 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))) (t_1 (- x (tan x)))) (if (<= (/ t_0 t_1) 2.0) (pow (/ t_1 t_0) -1.0) -0.5)))
double code(double x) {
double t_0 = x - sin(x);
double t_1 = x - tan(x);
double tmp;
if ((t_0 / t_1) <= 2.0) {
tmp = pow((t_1 / t_0), -1.0);
} else {
tmp = -0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x - sin(x)
t_1 = x - tan(x)
if ((t_0 / t_1) <= 2.0d0) then
tmp = (t_1 / t_0) ** (-1.0d0)
else
tmp = -0.5d0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = x - Math.sin(x);
double t_1 = x - Math.tan(x);
double tmp;
if ((t_0 / t_1) <= 2.0) {
tmp = Math.pow((t_1 / t_0), -1.0);
} else {
tmp = -0.5;
}
return tmp;
}
def code(x): t_0 = x - math.sin(x) t_1 = x - math.tan(x) tmp = 0 if (t_0 / t_1) <= 2.0: tmp = math.pow((t_1 / t_0), -1.0) else: tmp = -0.5 return tmp
function code(x) t_0 = Float64(x - sin(x)) t_1 = Float64(x - tan(x)) tmp = 0.0 if (Float64(t_0 / t_1) <= 2.0) tmp = Float64(t_1 / t_0) ^ -1.0; else tmp = -0.5; end return tmp end
function tmp_2 = code(x) t_0 = x - sin(x); t_1 = x - tan(x); tmp = 0.0; if ((t_0 / t_1) <= 2.0) tmp = (t_1 / t_0) ^ -1.0; else tmp = -0.5; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / t$95$1), $MachinePrecision], 2.0], N[Power[N[(t$95$1 / t$95$0), $MachinePrecision], -1.0], $MachinePrecision], -0.5]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \sin x\\
t_1 := x - \tan x\\
\mathbf{if}\;\frac{t_0}{t_1} \leq 2:\\
\;\;\;\;{\left(\frac{t_1}{t_0}\right)}^{-1}\\
\mathbf{else}:\\
\;\;\;\;-0.5\\
\end{array}
\end{array}
if (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x))) < 2Initial program 100.0%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.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 (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 2.4) (- (pow (* x (sqrt 0.225)) 2.0) 0.5) (+ 1.0 (/ (- (tan x) (sin x)) x))))
double code(double x) {
double tmp;
if (x <= 2.4) {
tmp = pow((x * sqrt(0.225)), 2.0) - 0.5;
} else {
tmp = 1.0 + ((tan(x) - sin(x)) / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 2.4d0) then
tmp = ((x * sqrt(0.225d0)) ** 2.0d0) - 0.5d0
else
tmp = 1.0d0 + ((tan(x) - sin(x)) / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 2.4) {
tmp = Math.pow((x * Math.sqrt(0.225)), 2.0) - 0.5;
} else {
tmp = 1.0 + ((Math.tan(x) - Math.sin(x)) / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 2.4: tmp = math.pow((x * math.sqrt(0.225)), 2.0) - 0.5 else: tmp = 1.0 + ((math.tan(x) - math.sin(x)) / x) return tmp
function code(x) tmp = 0.0 if (x <= 2.4) tmp = Float64((Float64(x * sqrt(0.225)) ^ 2.0) - 0.5); else tmp = Float64(1.0 + Float64(Float64(tan(x) - sin(x)) / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 2.4) tmp = ((x * sqrt(0.225)) ^ 2.0) - 0.5; else tmp = 1.0 + ((tan(x) - sin(x)) / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 2.4], N[(N[Power[N[(x * N[Sqrt[0.225], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] - 0.5), $MachinePrecision], N[(1.0 + N[(N[(N[Tan[x], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.4:\\
\;\;\;\;{\left(x \cdot \sqrt{0.225}\right)}^{2} - 0.5\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{\tan x - \sin x}{x}\\
\end{array}
\end{array}
if x < 2.39999999999999991Initial program 31.7%
Taylor expanded in x around 0 69.6%
add-sqr-sqrt69.6%
pow269.6%
*-commutative69.6%
sqrt-prod69.6%
unpow269.6%
sqrt-prod29.1%
add-sqr-sqrt69.6%
Applied egg-rr69.6%
if 2.39999999999999991 < x Initial program 100.0%
Taylor expanded in x around inf 97.5%
associate--l+97.5%
sub-neg97.5%
*-lft-identity97.5%
metadata-eval97.5%
cancel-sign-sub-inv97.5%
distribute-lft-out--97.5%
mul-1-neg97.5%
remove-double-neg97.5%
*-commutative97.5%
associate-/r*97.5%
div-sub97.5%
associate-*r/97.5%
Simplified97.5%
expm1-log1p-u97.5%
expm1-udef97.5%
sub-neg97.5%
neg-mul-197.5%
distribute-lft-in97.5%
associate-*r/97.5%
metadata-eval97.5%
div-inv97.5%
tan-quot97.5%
Applied egg-rr97.5%
expm1-def97.5%
expm1-log1p97.5%
+-commutative97.5%
*-commutative97.5%
neg-mul-197.5%
unsub-neg97.5%
Simplified97.5%
Final simplification77.3%
(FPCore (x) :precision binary64 (if (<= x 2.55) (- (pow (* x (sqrt 0.225)) 2.0) 0.5) 1.0))
double code(double x) {
double tmp;
if (x <= 2.55) {
tmp = pow((x * sqrt(0.225)), 2.0) - 0.5;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 2.55d0) then
tmp = ((x * sqrt(0.225d0)) ** 2.0d0) - 0.5d0
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 2.55) {
tmp = Math.pow((x * Math.sqrt(0.225)), 2.0) - 0.5;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 2.55: tmp = math.pow((x * math.sqrt(0.225)), 2.0) - 0.5 else: tmp = 1.0 return tmp
function code(x) tmp = 0.0 if (x <= 2.55) tmp = Float64((Float64(x * sqrt(0.225)) ^ 2.0) - 0.5); else tmp = 1.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 2.55) tmp = ((x * sqrt(0.225)) ^ 2.0) - 0.5; else tmp = 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 2.55], N[(N[Power[N[(x * N[Sqrt[0.225], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] - 0.5), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.55:\\
\;\;\;\;{\left(x \cdot \sqrt{0.225}\right)}^{2} - 0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 2.5499999999999998Initial program 31.7%
Taylor expanded in x around 0 69.6%
add-sqr-sqrt69.6%
pow269.6%
*-commutative69.6%
sqrt-prod69.6%
unpow269.6%
sqrt-prod29.1%
add-sqr-sqrt69.6%
Applied egg-rr69.6%
if 2.5499999999999998 < x Initial program 100.0%
Taylor expanded in x around inf 95.2%
Final simplification76.6%
(FPCore (x) :precision binary64 (if (<= x 2.55) (- (* x (* x 0.225)) 0.5) 1.0))
double code(double x) {
double tmp;
if (x <= 2.55) {
tmp = (x * (x * 0.225)) - 0.5;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 2.55d0) then
tmp = (x * (x * 0.225d0)) - 0.5d0
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 2.55) {
tmp = (x * (x * 0.225)) - 0.5;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 2.55: tmp = (x * (x * 0.225)) - 0.5 else: tmp = 1.0 return tmp
function code(x) tmp = 0.0 if (x <= 2.55) tmp = Float64(Float64(x * Float64(x * 0.225)) - 0.5); else tmp = 1.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 2.55) tmp = (x * (x * 0.225)) - 0.5; else tmp = 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 2.55], N[(N[(x * N[(x * 0.225), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.55:\\
\;\;\;\;x \cdot \left(x \cdot 0.225\right) - 0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 2.5499999999999998Initial program 31.7%
Taylor expanded in x around 0 69.6%
add-sqr-sqrt69.6%
pow269.6%
*-commutative69.6%
sqrt-prod69.6%
unpow269.6%
sqrt-prod29.1%
add-sqr-sqrt69.6%
Applied egg-rr69.6%
unpow269.6%
swap-sqr69.6%
rem-square-sqrt69.6%
associate-*l*69.6%
Applied egg-rr69.6%
if 2.5499999999999998 < x Initial program 100.0%
Taylor expanded in x around inf 95.2%
Final simplification76.6%
(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 31.4%
Taylor expanded in x around 0 69.1%
if 1.55000000000000004 < x Initial program 99.9%
Taylor expanded in x around inf 94.0%
Final simplification76.0%
(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 50.4%
Taylor expanded in x around 0 50.4%
Final simplification50.4%
herbie shell --seed 2023333
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))