
(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 5 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 (if (<= x 0.0044) (+ (* 0.225 (* x x)) -0.5) (/ (- x (sin x)) (- x (tan x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 0.0044) {
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.0044d0) 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.0044) {
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.0044: 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.0044) 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.0044) 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.0044], 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.0044:\\
\;\;\;\;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.00440000000000000027Initial program 32.5%
sub-neg32.5%
+-commutative32.5%
neg-sub032.5%
associate-+l-32.5%
sub0-neg32.5%
neg-mul-132.5%
sub-neg32.5%
+-commutative32.5%
neg-sub032.5%
associate-+l-32.5%
sub0-neg32.5%
neg-mul-132.5%
times-frac32.5%
metadata-eval32.5%
*-lft-identity32.5%
Simplified32.5%
Taylor expanded in x around 0 69.1%
fma-neg69.1%
unpow269.1%
metadata-eval69.1%
Simplified69.1%
fma-udef69.1%
Applied egg-rr69.1%
if 0.00440000000000000027 < x Initial program 100.0%
Final simplification77.2%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 2.4) (+ (* 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.4) {
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.4d0) 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.4) {
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.4: 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.4) 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.4) 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.4], 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.4:\\
\;\;\;\;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.39999999999999991Initial program 32.5%
sub-neg32.5%
+-commutative32.5%
neg-sub032.5%
associate-+l-32.5%
sub0-neg32.5%
neg-mul-132.5%
sub-neg32.5%
+-commutative32.5%
neg-sub032.5%
associate-+l-32.5%
sub0-neg32.5%
neg-mul-132.5%
times-frac32.5%
metadata-eval32.5%
*-lft-identity32.5%
Simplified32.5%
Taylor expanded in x around 0 69.1%
fma-neg69.1%
unpow269.1%
metadata-eval69.1%
Simplified69.1%
fma-udef69.1%
Applied egg-rr69.1%
if 2.39999999999999991 < 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 99.1%
associate--l+99.1%
associate-*r/99.1%
associate-/r*99.1%
associate-*r/99.1%
div-sub99.1%
distribute-lft-out--99.1%
associate-*r/99.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.1%
tan-quot99.1%
sub-neg99.1%
Applied egg-rr99.1%
sub-neg99.1%
Simplified99.1%
Final simplification77.0%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 4.5) (+ (* 0.225 (* x x)) -0.5) 1.0))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 4.5) {
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 <= 4.5d0) 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 <= 4.5) {
tmp = (0.225 * (x * x)) + -0.5;
} else {
tmp = 1.0;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 4.5: tmp = (0.225 * (x * x)) + -0.5 else: tmp = 1.0 return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 4.5) 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 <= 4.5) 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, 4.5], 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 4.5:\\
\;\;\;\;0.225 \cdot \left(x \cdot x\right) + -0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 4.5Initial program 32.5%
sub-neg32.5%
+-commutative32.5%
neg-sub032.5%
associate-+l-32.5%
sub0-neg32.5%
neg-mul-132.5%
sub-neg32.5%
+-commutative32.5%
neg-sub032.5%
associate-+l-32.5%
sub0-neg32.5%
neg-mul-132.5%
times-frac32.5%
metadata-eval32.5%
*-lft-identity32.5%
Simplified32.5%
Taylor expanded in x around 0 69.1%
fma-neg69.1%
unpow269.1%
metadata-eval69.1%
Simplified69.1%
fma-udef69.1%
Applied egg-rr69.1%
if 4.5 < 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 97.9%
Final simplification76.7%
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 32.5%
sub-neg32.5%
+-commutative32.5%
neg-sub032.5%
associate-+l-32.5%
sub0-neg32.5%
neg-mul-132.5%
sub-neg32.5%
+-commutative32.5%
neg-sub032.5%
associate-+l-32.5%
sub0-neg32.5%
neg-mul-132.5%
times-frac32.5%
metadata-eval32.5%
*-lft-identity32.5%
Simplified32.5%
Taylor expanded in x around 0 68.1%
if 1.5800000000000001 < 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 97.9%
Final simplification75.9%
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 50.2%
sub-neg50.2%
+-commutative50.2%
neg-sub050.2%
associate-+l-50.2%
sub0-neg50.2%
neg-mul-150.2%
sub-neg50.2%
+-commutative50.2%
neg-sub050.2%
associate-+l-50.2%
sub0-neg50.2%
neg-mul-150.2%
times-frac50.2%
metadata-eval50.2%
*-lft-identity50.2%
Simplified50.2%
Taylor expanded in x around 0 50.7%
Final simplification50.7%
herbie shell --seed 2023207
(FPCore (x)
:name "sintan (problem 3.4.5)"
:precision binary64
(/ (- x (sin x)) (- x (tan x))))