
(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 8 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}
NOTE: x should be positive before calling this function
(FPCore (x)
:precision binary64
(let* ((t_0 (- x (sin x))))
(if (<= x 0.0043)
(+ (* 0.225 (* x x)) -0.5)
(/ 1.0 (- (/ x t_0) (/ (tan x) t_0))))))x = abs(x);
double code(double x) {
double t_0 = x - sin(x);
double tmp;
if (x <= 0.0043) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = 1.0 / ((x / t_0) - (tan(x) / t_0));
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = x - sin(x)
if (x <= 0.0043d0) then
tmp = (0.225d0 * (x * x)) + (-0.5d0)
else
tmp = 1.0d0 / ((x / t_0) - (tan(x) / t_0))
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double t_0 = x - Math.sin(x);
double tmp;
if (x <= 0.0043) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = 1.0 / ((x / t_0) - (Math.tan(x) / t_0));
}
return tmp;
}
x = abs(x) def code(x): t_0 = x - math.sin(x) tmp = 0 if x <= 0.0043: tmp = (0.225 * (x * x)) + -0.5 else: tmp = 1.0 / ((x / t_0) - (math.tan(x) / t_0)) return tmp
x = abs(x) function code(x) t_0 = Float64(x - sin(x)) tmp = 0.0 if (x <= 0.0043) tmp = Float64(Float64(0.225 * Float64(x * x)) + -0.5); else tmp = Float64(1.0 / Float64(Float64(x / t_0) - Float64(tan(x) / t_0))); end return tmp end
x = abs(x) function tmp_2 = code(x) t_0 = x - sin(x); tmp = 0.0; if (x <= 0.0043) tmp = (0.225 * (x * x)) + -0.5; else tmp = 1.0 / ((x / t_0) - (tan(x) / t_0)); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function
code[x_] := Block[{t$95$0 = N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 0.0043], N[(N[(0.225 * N[(x * x), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], N[(1.0 / N[(N[(x / t$95$0), $MachinePrecision] - N[(N[Tan[x], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
t_0 := x - \sin x\\
\mathbf{if}\;x \leq 0.0043:\\
\;\;\;\;0.225 \cdot \left(x \cdot x\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{t_0} - \frac{\tan x}{t_0}}\\
\end{array}
\end{array}
if x < 0.0043Initial program 37.2%
Taylor expanded in x around 0 65.5%
fma-neg65.5%
unpow265.5%
metadata-eval65.5%
Simplified65.5%
fma-udef65.5%
Applied egg-rr65.5%
if 0.0043 < x Initial program 99.9%
clear-num99.9%
inv-pow99.9%
Applied egg-rr99.9%
unpow-199.9%
Simplified99.9%
div-sub100.0%
Applied egg-rr100.0%
Final simplification74.1%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0032) (+ (* 0.225 (* x x)) -0.5) (/ 1.0 (/ (- x (tan x)) (- x (sin x))))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0032) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = 1.0 / ((x - tan(x)) / (x - sin(x)));
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.0032d0) then
tmp = (0.225d0 * (x * x)) + (-0.5d0)
else
tmp = 1.0d0 / ((x - tan(x)) / (x - sin(x)))
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 0.0032) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = 1.0 / ((x - Math.tan(x)) / (x - Math.sin(x)));
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 0.0032: tmp = (0.225 * (x * x)) + -0.5 else: tmp = 1.0 / ((x - math.tan(x)) / (x - math.sin(x))) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.0032) tmp = Float64(Float64(0.225 * Float64(x * x)) + -0.5); else tmp = Float64(1.0 / Float64(Float64(x - tan(x)) / Float64(x - sin(x)))); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 0.0032) tmp = (0.225 * (x * x)) + -0.5; else tmp = 1.0 / ((x - tan(x)) / (x - sin(x))); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.0032], N[(N[(0.225 * N[(x * x), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], N[(1.0 / N[(N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0032:\\
\;\;\;\;0.225 \cdot \left(x \cdot x\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x - \tan x}{x - \sin x}}\\
\end{array}
\end{array}
if x < 0.00320000000000000015Initial program 37.2%
Taylor expanded in x around 0 65.5%
fma-neg65.5%
unpow265.5%
metadata-eval65.5%
Simplified65.5%
fma-udef65.5%
Applied egg-rr65.5%
if 0.00320000000000000015 < x Initial program 99.9%
clear-num99.9%
inv-pow99.9%
Applied egg-rr99.9%
unpow-199.9%
Simplified99.9%
Final simplification74.1%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.45) (+ (* 0.225 (* x x)) -0.5) (+ 1.0 (/ (- (tan x) (sin x)) x))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 2.45) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = 1.0 + ((tan(x) - sin(x)) / x);
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 2.45d0) then
tmp = (0.225d0 * (x * x)) + (-0.5d0)
else
tmp = 1.0d0 + ((tan(x) - sin(x)) / x)
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 2.45) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = 1.0 + ((Math.tan(x) - Math.sin(x)) / x);
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 2.45: tmp = (0.225 * (x * x)) + -0.5 else: tmp = 1.0 + ((math.tan(x) - math.sin(x)) / x) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 2.45) tmp = Float64(Float64(0.225 * Float64(x * x)) + -0.5); else tmp = Float64(1.0 + Float64(Float64(tan(x) - sin(x)) / x)); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 2.45) tmp = (0.225 * (x * x)) + -0.5; else tmp = 1.0 + ((tan(x) - sin(x)) / x); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 2.45], N[(N[(0.225 * N[(x * x), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], N[(1.0 + N[(N[(N[Tan[x], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.45:\\
\;\;\;\;0.225 \cdot \left(x \cdot x\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{\tan x - \sin x}{x}\\
\end{array}
\end{array}
if x < 2.4500000000000002Initial program 37.2%
Taylor expanded in x around 0 65.5%
fma-neg65.5%
unpow265.5%
metadata-eval65.5%
Simplified65.5%
fma-udef65.5%
Applied egg-rr65.5%
if 2.4500000000000002 < x Initial program 99.9%
Taylor expanded in x around inf 99.3%
associate--l+99.3%
sub-neg99.3%
*-lft-identity99.3%
metadata-eval99.3%
cancel-sign-sub-inv99.3%
distribute-lft-out--99.3%
mul-1-neg99.3%
remove-double-neg99.3%
*-commutative99.3%
associate-/r*99.3%
div-sub99.3%
Simplified99.3%
tan-quot99.3%
sub-neg99.3%
Applied egg-rr99.3%
sub-neg99.3%
Simplified99.3%
Final simplification74.0%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 0.0032) (+ (* 0.225 (* x x)) -0.5) (/ (- x (sin x)) (- x (tan x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0032) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = (x - sin(x)) / (x - tan(x));
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.0032d0) then
tmp = (0.225d0 * (x * x)) + (-0.5d0)
else
tmp = (x - sin(x)) / (x - tan(x))
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 0.0032) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = (x - Math.sin(x)) / (x - Math.tan(x));
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 0.0032: tmp = (0.225 * (x * x)) + -0.5 else: tmp = (x - math.sin(x)) / (x - math.tan(x)) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 0.0032) tmp = Float64(Float64(0.225 * Float64(x * x)) + -0.5); else tmp = Float64(Float64(x - sin(x)) / Float64(x - tan(x))); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 0.0032) tmp = (0.225 * (x * x)) + -0.5; else tmp = (x - sin(x)) / (x - tan(x)); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 0.0032], N[(N[(0.225 * N[(x * x), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0032:\\
\;\;\;\;0.225 \cdot \left(x \cdot x\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \sin x}{x - \tan x}\\
\end{array}
\end{array}
if x < 0.00320000000000000015Initial program 37.2%
Taylor expanded in x around 0 65.5%
fma-neg65.5%
unpow265.5%
metadata-eval65.5%
Simplified65.5%
fma-udef65.5%
Applied egg-rr65.5%
if 0.00320000000000000015 < x Initial program 99.9%
Final simplification74.1%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.25) (+ (* 0.225 (* x x)) -0.5) (/ (- x (sin x)) x)))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 2.25) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = (x - sin(x)) / x;
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 2.25d0) then
tmp = (0.225d0 * (x * x)) + (-0.5d0)
else
tmp = (x - sin(x)) / x
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 2.25) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = (x - Math.sin(x)) / x;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 2.25: tmp = (0.225 * (x * x)) + -0.5 else: tmp = (x - math.sin(x)) / x return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 2.25) tmp = Float64(Float64(0.225 * Float64(x * x)) + -0.5); else tmp = Float64(Float64(x - sin(x)) / x); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 2.25) tmp = (0.225 * (x * x)) + -0.5; else tmp = (x - sin(x)) / x; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 2.25], N[(N[(0.225 * N[(x * x), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.25:\\
\;\;\;\;0.225 \cdot \left(x \cdot x\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x - \sin x}{x}\\
\end{array}
\end{array}
if x < 2.25Initial program 37.2%
Taylor expanded in x around 0 65.5%
fma-neg65.5%
unpow265.5%
metadata-eval65.5%
Simplified65.5%
fma-udef65.5%
Applied egg-rr65.5%
if 2.25 < x Initial program 99.9%
Taylor expanded in x around inf 96.7%
Final simplification73.3%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.6) (+ (* 0.225 (* x x)) -0.5) 1.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 2.6) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 2.6d0) then
tmp = (0.225d0 * (x * x)) + (-0.5d0)
else
tmp = 1.0d0
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 2.6) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 2.6: tmp = (0.225 * (x * x)) + -0.5 else: tmp = 1.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 2.6) tmp = Float64(Float64(0.225 * Float64(x * x)) + -0.5); else tmp = 1.0; end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 2.6) tmp = (0.225 * (x * x)) + -0.5; else tmp = 1.0; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 2.6], N[(N[(0.225 * N[(x * x), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], 1.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.6:\\
\;\;\;\;0.225 \cdot \left(x \cdot x\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 2.60000000000000009Initial program 37.2%
Taylor expanded in x around 0 65.5%
fma-neg65.5%
unpow265.5%
metadata-eval65.5%
Simplified65.5%
fma-udef65.5%
Applied egg-rr65.5%
if 2.60000000000000009 < x Initial program 99.9%
Taylor expanded in x around inf 96.6%
Final simplification73.3%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.58) -0.5 1.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.58) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.58d0) then
tmp = -0.5d0
else
tmp = 1.0d0
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 1.58) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.58: tmp = -0.5 else: tmp = 1.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.58) tmp = -0.5; else tmp = 1.0; end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 1.58) tmp = -0.5; else tmp = 1.0; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 1.58], -0.5, 1.0]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.58:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.5800000000000001Initial program 37.2%
Taylor expanded in x around 0 64.3%
if 1.5800000000000001 < x Initial program 99.9%
Taylor expanded in x around inf 96.6%
Final simplification72.4%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 -0.5)
x = abs(x);
double code(double x) {
return -0.5;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = -0.5d0
end function
x = Math.abs(x);
public static double code(double x) {
return -0.5;
}
x = abs(x) def code(x): return -0.5
x = abs(x) function code(x) return -0.5 end
x = abs(x) function tmp = code(x) tmp = -0.5; end
NOTE: x should be positive before calling this function code[x_] := -0.5
\begin{array}{l}
x = |x|\\
\\
-0.5
\end{array}
Initial program 52.9%
Taylor expanded in x around 0 48.6%
Final simplification48.6%
herbie shell --seed 2023271
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))