
(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 6 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 99.0%
if 2 < (/.f64 (-.f64 x (sin.f64 x)) (-.f64 x (tan.f64 x))) Initial program 0.0%
sub-neg0.0%
+-commutative0.0%
neg-sub00.0%
associate-+l-0.0%
sub0-neg0.0%
neg-mul-10.0%
sub-neg0.0%
+-commutative0.0%
neg-sub00.0%
associate-+l-0.0%
sub0-neg0.0%
neg-mul-10.0%
times-frac0.0%
metadata-eval0.0%
*-lft-identity0.0%
Simplified0.0%
Taylor expanded in x around 0 100.0%
Final simplification99.5%
(FPCore (x)
:precision binary64
(if (<= x -2.95)
1.0
(if (<= x 2.8)
(+ -0.5 (+ (* 0.225 (* x x)) (* -0.009642857142857142 (pow x 4.0))))
(/ x (- x (tan x))))))
double code(double x) {
double tmp;
if (x <= -2.95) {
tmp = 1.0;
} else if (x <= 2.8) {
tmp = -0.5 + ((0.225 * (x * x)) + (-0.009642857142857142 * pow(x, 4.0)));
} else {
tmp = x / (x - tan(x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2.95d0)) then
tmp = 1.0d0
else if (x <= 2.8d0) then
tmp = (-0.5d0) + ((0.225d0 * (x * x)) + ((-0.009642857142857142d0) * (x ** 4.0d0)))
else
tmp = x / (x - tan(x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -2.95) {
tmp = 1.0;
} else if (x <= 2.8) {
tmp = -0.5 + ((0.225 * (x * x)) + (-0.009642857142857142 * Math.pow(x, 4.0)));
} else {
tmp = x / (x - Math.tan(x));
}
return tmp;
}
def code(x): tmp = 0 if x <= -2.95: tmp = 1.0 elif x <= 2.8: tmp = -0.5 + ((0.225 * (x * x)) + (-0.009642857142857142 * math.pow(x, 4.0))) else: tmp = x / (x - math.tan(x)) return tmp
function code(x) tmp = 0.0 if (x <= -2.95) tmp = 1.0; elseif (x <= 2.8) tmp = Float64(-0.5 + Float64(Float64(0.225 * Float64(x * x)) + Float64(-0.009642857142857142 * (x ^ 4.0)))); else tmp = Float64(x / Float64(x - tan(x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -2.95) tmp = 1.0; elseif (x <= 2.8) tmp = -0.5 + ((0.225 * (x * x)) + (-0.009642857142857142 * (x ^ 4.0))); else tmp = x / (x - tan(x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -2.95], 1.0, If[LessEqual[x, 2.8], N[(-0.5 + N[(N[(0.225 * N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(-0.009642857142857142 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.95:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 2.8:\\
\;\;\;\;-0.5 + \left(0.225 \cdot \left(x \cdot x\right) + -0.009642857142857142 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x - \tan x}\\
\end{array}
\end{array}
if x < -2.9500000000000002Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around inf 98.4%
if -2.9500000000000002 < x < 2.7999999999999998Initial program 2.1%
sub-neg2.1%
+-commutative2.1%
neg-sub02.1%
associate-+l-2.1%
sub0-neg2.1%
neg-mul-12.1%
sub-neg2.1%
+-commutative2.1%
neg-sub02.1%
associate-+l-2.1%
sub0-neg2.1%
neg-mul-12.1%
times-frac2.1%
metadata-eval2.1%
*-lft-identity2.1%
Simplified2.1%
Taylor expanded in x around 0 99.9%
sub-neg99.9%
fma-def99.9%
unpow299.9%
metadata-eval99.9%
Simplified99.9%
fma-udef99.9%
Applied egg-rr99.9%
if 2.7999999999999998 < x Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around inf 98.6%
neg-mul-198.6%
Simplified98.6%
frac-2neg98.6%
div-inv98.4%
remove-double-neg98.4%
sub-neg98.4%
distribute-neg-in98.4%
remove-double-neg98.4%
Applied egg-rr98.4%
associate-*r/98.6%
*-rgt-identity98.6%
+-commutative98.6%
unsub-neg98.6%
Simplified98.6%
Final simplification99.2%
(FPCore (x) :precision binary64 (if (<= x -2.6) 1.0 (if (<= x 2.3) (+ -0.5 (* 0.225 (* x x))) (/ x (- x (tan x))))))
double code(double x) {
double tmp;
if (x <= -2.6) {
tmp = 1.0;
} else if (x <= 2.3) {
tmp = -0.5 + (0.225 * (x * x));
} else {
tmp = x / (x - tan(x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2.6d0)) then
tmp = 1.0d0
else if (x <= 2.3d0) then
tmp = (-0.5d0) + (0.225d0 * (x * x))
else
tmp = x / (x - tan(x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -2.6) {
tmp = 1.0;
} else if (x <= 2.3) {
tmp = -0.5 + (0.225 * (x * x));
} else {
tmp = x / (x - Math.tan(x));
}
return tmp;
}
def code(x): tmp = 0 if x <= -2.6: tmp = 1.0 elif x <= 2.3: tmp = -0.5 + (0.225 * (x * x)) else: tmp = x / (x - math.tan(x)) return tmp
function code(x) tmp = 0.0 if (x <= -2.6) tmp = 1.0; elseif (x <= 2.3) tmp = Float64(-0.5 + Float64(0.225 * Float64(x * x))); else tmp = Float64(x / Float64(x - tan(x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -2.6) tmp = 1.0; elseif (x <= 2.3) tmp = -0.5 + (0.225 * (x * x)); else tmp = x / (x - tan(x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -2.6], 1.0, If[LessEqual[x, 2.3], N[(-0.5 + N[(0.225 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 2.3:\\
\;\;\;\;-0.5 + 0.225 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x - \tan x}\\
\end{array}
\end{array}
if x < -2.60000000000000009Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around inf 98.4%
if -2.60000000000000009 < x < 2.2999999999999998Initial program 2.1%
sub-neg2.1%
+-commutative2.1%
neg-sub02.1%
associate-+l-2.1%
sub0-neg2.1%
neg-mul-12.1%
sub-neg2.1%
+-commutative2.1%
neg-sub02.1%
associate-+l-2.1%
sub0-neg2.1%
neg-mul-12.1%
times-frac2.1%
metadata-eval2.1%
*-lft-identity2.1%
Simplified2.1%
Taylor expanded in x around 0 99.7%
fma-neg99.7%
unpow299.7%
metadata-eval99.7%
Simplified99.7%
fma-udef99.7%
Applied egg-rr99.7%
if 2.2999999999999998 < x Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around inf 98.6%
neg-mul-198.6%
Simplified98.6%
frac-2neg98.6%
div-inv98.4%
remove-double-neg98.4%
sub-neg98.4%
distribute-neg-in98.4%
remove-double-neg98.4%
Applied egg-rr98.4%
associate-*r/98.6%
*-rgt-identity98.6%
+-commutative98.6%
unsub-neg98.6%
Simplified98.6%
Final simplification99.1%
(FPCore (x) :precision binary64 (if (<= x -2.6) 1.0 (if (<= x 2.55) (+ -0.5 (* 0.225 (* x x))) 1.0)))
double code(double x) {
double tmp;
if (x <= -2.6) {
tmp = 1.0;
} else if (x <= 2.55) {
tmp = -0.5 + (0.225 * (x * x));
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2.6d0)) then
tmp = 1.0d0
else if (x <= 2.55d0) then
tmp = (-0.5d0) + (0.225d0 * (x * x))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -2.6) {
tmp = 1.0;
} else if (x <= 2.55) {
tmp = -0.5 + (0.225 * (x * x));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= -2.6: tmp = 1.0 elif x <= 2.55: tmp = -0.5 + (0.225 * (x * x)) else: tmp = 1.0 return tmp
function code(x) tmp = 0.0 if (x <= -2.6) tmp = 1.0; elseif (x <= 2.55) tmp = Float64(-0.5 + Float64(0.225 * Float64(x * x))); else tmp = 1.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -2.6) tmp = 1.0; elseif (x <= 2.55) tmp = -0.5 + (0.225 * (x * x)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -2.6], 1.0, If[LessEqual[x, 2.55], N[(-0.5 + N[(0.225 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 2.55:\\
\;\;\;\;-0.5 + 0.225 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -2.60000000000000009 or 2.5499999999999998 < x Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around inf 98.5%
if -2.60000000000000009 < x < 2.5499999999999998Initial program 2.1%
sub-neg2.1%
+-commutative2.1%
neg-sub02.1%
associate-+l-2.1%
sub0-neg2.1%
neg-mul-12.1%
sub-neg2.1%
+-commutative2.1%
neg-sub02.1%
associate-+l-2.1%
sub0-neg2.1%
neg-mul-12.1%
times-frac2.1%
metadata-eval2.1%
*-lft-identity2.1%
Simplified2.1%
Taylor expanded in x around 0 99.7%
fma-neg99.7%
unpow299.7%
metadata-eval99.7%
Simplified99.7%
fma-udef99.7%
Applied egg-rr99.7%
Final simplification99.1%
(FPCore (x) :precision binary64 (if (<= x -1.58) 1.0 (if (<= x 1.55) -0.5 1.0)))
double code(double x) {
double tmp;
if (x <= -1.58) {
tmp = 1.0;
} else 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.58d0)) then
tmp = 1.0d0
else 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.58) {
tmp = 1.0;
} else if (x <= 1.55) {
tmp = -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.58: tmp = 1.0 elif x <= 1.55: tmp = -0.5 else: tmp = 1.0 return tmp
function code(x) tmp = 0.0 if (x <= -1.58) tmp = 1.0; elseif (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.58) tmp = 1.0; elseif (x <= 1.55) tmp = -0.5; else tmp = 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.58], 1.0, If[LessEqual[x, 1.55], -0.5, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.58:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 1.55:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.5800000000000001 or 1.55000000000000004 < x Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-lft-identity100.0%
Simplified100.0%
Taylor expanded in x around inf 98.5%
if -1.5800000000000001 < x < 1.55000000000000004Initial program 2.1%
sub-neg2.1%
+-commutative2.1%
neg-sub02.1%
associate-+l-2.1%
sub0-neg2.1%
neg-mul-12.1%
sub-neg2.1%
+-commutative2.1%
neg-sub02.1%
associate-+l-2.1%
sub0-neg2.1%
neg-mul-12.1%
times-frac2.1%
metadata-eval2.1%
*-lft-identity2.1%
Simplified2.1%
Taylor expanded in x around 0 98.5%
Final simplification98.5%
(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.0%
sub-neg51.0%
+-commutative51.0%
neg-sub051.0%
associate-+l-51.0%
sub0-neg51.0%
neg-mul-151.0%
sub-neg51.0%
+-commutative51.0%
neg-sub051.0%
associate-+l-51.0%
sub0-neg51.0%
neg-mul-151.0%
times-frac51.0%
metadata-eval51.0%
*-lft-identity51.0%
Simplified51.0%
Taylor expanded in x around 0 50.1%
Final simplification50.1%
herbie shell --seed 2023178
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))