
(FPCore (B x) :precision binary64 (+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))
double code(double B, double x) {
return -(x * (1.0 / tan(B))) + (1.0 / sin(B));
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = -(x * (1.0d0 / tan(b))) + (1.0d0 / sin(b))
end function
public static double code(double B, double x) {
return -(x * (1.0 / Math.tan(B))) + (1.0 / Math.sin(B));
}
def code(B, x): return -(x * (1.0 / math.tan(B))) + (1.0 / math.sin(B))
function code(B, x) return Float64(Float64(-Float64(x * Float64(1.0 / tan(B)))) + Float64(1.0 / sin(B))) end
function tmp = code(B, x) tmp = -(x * (1.0 / tan(B))) + (1.0 / sin(B)); end
code[B_, x_] := N[((-N[(x * N[(1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]) + N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (B x) :precision binary64 (+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))
double code(double B, double x) {
return -(x * (1.0 / tan(B))) + (1.0 / sin(B));
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = -(x * (1.0d0 / tan(b))) + (1.0d0 / sin(b))
end function
public static double code(double B, double x) {
return -(x * (1.0 / Math.tan(B))) + (1.0 / Math.sin(B));
}
def code(B, x): return -(x * (1.0 / math.tan(B))) + (1.0 / math.sin(B))
function code(B, x) return Float64(Float64(-Float64(x * Float64(1.0 / tan(B)))) + Float64(1.0 / sin(B))) end
function tmp = code(B, x) tmp = -(x * (1.0 / tan(B))) + (1.0 / sin(B)); end
code[B_, x_] := N[((-N[(x * N[(1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]) + N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}
\end{array}
(FPCore (B x) :precision binary64 (- (/ 1.0 (sin B)) (/ x (tan B))))
double code(double B, double x) {
return (1.0 / sin(B)) - (x / tan(B));
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = (1.0d0 / sin(b)) - (x / tan(b))
end function
public static double code(double B, double x) {
return (1.0 / Math.sin(B)) - (x / Math.tan(B));
}
def code(B, x): return (1.0 / math.sin(B)) - (x / math.tan(B))
function code(B, x) return Float64(Float64(1.0 / sin(B)) - Float64(x / tan(B))) end
function tmp = code(B, x) tmp = (1.0 / sin(B)) - (x / tan(B)); end
code[B_, x_] := N[(N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sin B} - \frac{x}{\tan B}
\end{array}
Initial program 99.8%
+-commutative99.8%
unsub-neg99.8%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (B x) :precision binary64 (if (or (<= x -1.32e-8) (not (<= x 1.85e-8))) (* x (/ (+ (/ 1.0 x) -1.0) (tan B))) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.32e-8) || !(x <= 1.85e-8)) {
tmp = x * (((1.0 / x) + -1.0) / tan(B));
} else {
tmp = 1.0 / sin(B);
}
return tmp;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.32d-8)) .or. (.not. (x <= 1.85d-8))) then
tmp = x * (((1.0d0 / x) + (-1.0d0)) / tan(b))
else
tmp = 1.0d0 / sin(b)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if ((x <= -1.32e-8) || !(x <= 1.85e-8)) {
tmp = x * (((1.0 / x) + -1.0) / Math.tan(B));
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -1.32e-8) or not (x <= 1.85e-8): tmp = x * (((1.0 / x) + -1.0) / math.tan(B)) else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -1.32e-8) || !(x <= 1.85e-8)) tmp = Float64(x * Float64(Float64(Float64(1.0 / x) + -1.0) / tan(B))); else tmp = Float64(1.0 / sin(B)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if ((x <= -1.32e-8) || ~((x <= 1.85e-8))) tmp = x * (((1.0 / x) + -1.0) / tan(B)); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -1.32e-8], N[Not[LessEqual[x, 1.85e-8]], $MachinePrecision]], N[(x * N[(N[(N[(1.0 / x), $MachinePrecision] + -1.0), $MachinePrecision] / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.32 \cdot 10^{-8} \lor \neg \left(x \leq 1.85 \cdot 10^{-8}\right):\\
\;\;\;\;x \cdot \frac{\frac{1}{x} + -1}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -1.32000000000000007e-8 or 1.85e-8 < x Initial program 99.7%
distribute-lft-neg-in99.7%
Simplified99.7%
+-commutative99.7%
cancel-sign-sub-inv99.7%
div-inv99.8%
clear-num99.7%
frac-sub90.4%
*-un-lft-identity90.4%
*-commutative90.4%
*-un-lft-identity90.4%
Applied egg-rr90.4%
associate-/r*99.6%
associate-/r/99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around 0 97.6%
if -1.32000000000000007e-8 < x < 1.85e-8Initial program 99.9%
distribute-lft-neg-in99.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
Final simplification98.7%
(FPCore (B x) :precision binary64 (if (or (<= x -1.05e-9) (not (<= x 8.8e-10))) (/ x (/ (tan B) (+ (/ 1.0 x) -1.0))) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.05e-9) || !(x <= 8.8e-10)) {
tmp = x / (tan(B) / ((1.0 / x) + -1.0));
} else {
tmp = 1.0 / sin(B);
}
return tmp;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.05d-9)) .or. (.not. (x <= 8.8d-10))) then
tmp = x / (tan(b) / ((1.0d0 / x) + (-1.0d0)))
else
tmp = 1.0d0 / sin(b)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if ((x <= -1.05e-9) || !(x <= 8.8e-10)) {
tmp = x / (Math.tan(B) / ((1.0 / x) + -1.0));
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -1.05e-9) or not (x <= 8.8e-10): tmp = x / (math.tan(B) / ((1.0 / x) + -1.0)) else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -1.05e-9) || !(x <= 8.8e-10)) tmp = Float64(x / Float64(tan(B) / Float64(Float64(1.0 / x) + -1.0))); else tmp = Float64(1.0 / sin(B)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if ((x <= -1.05e-9) || ~((x <= 8.8e-10))) tmp = x / (tan(B) / ((1.0 / x) + -1.0)); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -1.05e-9], N[Not[LessEqual[x, 8.8e-10]], $MachinePrecision]], N[(x / N[(N[Tan[B], $MachinePrecision] / N[(N[(1.0 / x), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{-9} \lor \neg \left(x \leq 8.8 \cdot 10^{-10}\right):\\
\;\;\;\;\frac{x}{\frac{\tan B}{\frac{1}{x} + -1}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -1.0500000000000001e-9 or 8.7999999999999996e-10 < x Initial program 99.7%
distribute-lft-neg-in99.7%
Simplified99.7%
+-commutative99.7%
cancel-sign-sub-inv99.7%
div-inv99.8%
clear-num99.7%
frac-sub90.4%
*-un-lft-identity90.4%
*-commutative90.4%
*-un-lft-identity90.4%
Applied egg-rr90.4%
associate-/r*99.6%
associate-/r/99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around 0 97.6%
*-commutative97.6%
clear-num97.6%
un-div-inv97.7%
sub-neg97.7%
metadata-eval97.7%
Applied egg-rr97.7%
if -1.0500000000000001e-9 < x < 8.7999999999999996e-10Initial program 99.9%
distribute-lft-neg-in99.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
Final simplification98.7%
(FPCore (B x)
:precision binary64
(if (<= x -1.4e-10)
(/ (/ (- B (* B x)) B) B)
(if (<= x 3.1e-7)
(/ 1.0 (sin B))
(+ (* (* B x) 0.3333333333333333) (/ (- 1.0 x) B)))))
double code(double B, double x) {
double tmp;
if (x <= -1.4e-10) {
tmp = ((B - (B * x)) / B) / B;
} else if (x <= 3.1e-7) {
tmp = 1.0 / sin(B);
} else {
tmp = ((B * x) * 0.3333333333333333) + ((1.0 - x) / B);
}
return tmp;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.4d-10)) then
tmp = ((b - (b * x)) / b) / b
else if (x <= 3.1d-7) then
tmp = 1.0d0 / sin(b)
else
tmp = ((b * x) * 0.3333333333333333d0) + ((1.0d0 - x) / b)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (x <= -1.4e-10) {
tmp = ((B - (B * x)) / B) / B;
} else if (x <= 3.1e-7) {
tmp = 1.0 / Math.sin(B);
} else {
tmp = ((B * x) * 0.3333333333333333) + ((1.0 - x) / B);
}
return tmp;
}
def code(B, x): tmp = 0 if x <= -1.4e-10: tmp = ((B - (B * x)) / B) / B elif x <= 3.1e-7: tmp = 1.0 / math.sin(B) else: tmp = ((B * x) * 0.3333333333333333) + ((1.0 - x) / B) return tmp
function code(B, x) tmp = 0.0 if (x <= -1.4e-10) tmp = Float64(Float64(Float64(B - Float64(B * x)) / B) / B); elseif (x <= 3.1e-7) tmp = Float64(1.0 / sin(B)); else tmp = Float64(Float64(Float64(B * x) * 0.3333333333333333) + Float64(Float64(1.0 - x) / B)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (x <= -1.4e-10) tmp = ((B - (B * x)) / B) / B; elseif (x <= 3.1e-7) tmp = 1.0 / sin(B); else tmp = ((B * x) * 0.3333333333333333) + ((1.0 - x) / B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[x, -1.4e-10], N[(N[(N[(B - N[(B * x), $MachinePrecision]), $MachinePrecision] / B), $MachinePrecision] / B), $MachinePrecision], If[LessEqual[x, 3.1e-7], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[(N[(N[(B * x), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-10}:\\
\;\;\;\;\frac{\frac{B - B \cdot x}{B}}{B}\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{-7}:\\
\;\;\;\;\frac{1}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;\left(B \cdot x\right) \cdot 0.3333333333333333 + \frac{1 - x}{B}\\
\end{array}
\end{array}
if x < -1.40000000000000008e-10Initial program 99.6%
distribute-lft-neg-in99.6%
Simplified99.6%
Taylor expanded in B around 0 57.5%
mul-1-neg57.5%
sub-neg57.5%
Simplified57.5%
div-sub57.5%
Applied egg-rr57.5%
frac-sub53.0%
associate-/r*57.9%
*-un-lft-identity57.9%
Applied egg-rr57.9%
if -1.40000000000000008e-10 < x < 3.1e-7Initial program 99.9%
distribute-lft-neg-in99.9%
Simplified99.9%
Taylor expanded in x around 0 99.8%
if 3.1e-7 < x Initial program 99.8%
distribute-lft-neg-in99.8%
Simplified99.8%
Taylor expanded in B around 0 53.0%
+-commutative53.0%
mul-1-neg53.0%
sub-neg53.0%
associate--l+53.0%
*-commutative53.0%
*-commutative53.0%
div-sub53.1%
Simplified53.1%
Taylor expanded in x around inf 53.1%
Final simplification77.7%
(FPCore (B x) :precision binary64 (/ (/ (- B (* B x)) B) B))
double code(double B, double x) {
return ((B - (B * x)) / B) / B;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = ((b - (b * x)) / b) / b
end function
public static double code(double B, double x) {
return ((B - (B * x)) / B) / B;
}
def code(B, x): return ((B - (B * x)) / B) / B
function code(B, x) return Float64(Float64(Float64(B - Float64(B * x)) / B) / B) end
function tmp = code(B, x) tmp = ((B - (B * x)) / B) / B; end
code[B_, x_] := N[(N[(N[(B - N[(B * x), $MachinePrecision]), $MachinePrecision] / B), $MachinePrecision] / B), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{B - B \cdot x}{B}}{B}
\end{array}
Initial program 99.8%
distribute-lft-neg-in99.8%
Simplified99.8%
Taylor expanded in B around 0 55.2%
mul-1-neg55.2%
sub-neg55.2%
Simplified55.2%
div-sub55.2%
Applied egg-rr55.2%
frac-sub40.8%
associate-/r*55.4%
*-un-lft-identity55.4%
Applied egg-rr55.4%
Final simplification55.4%
(FPCore (B x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ (- x) B) (/ 1.0 B)))
double code(double B, double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -x / B;
} else {
tmp = 1.0 / B;
}
return tmp;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = -x / b
else
tmp = 1.0d0 / b
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -x / B;
} else {
tmp = 1.0 / B;
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -x / B else: tmp = 1.0 / B return tmp
function code(B, x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(Float64(-x) / B); else tmp = Float64(1.0 / B); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -x / B; else tmp = 1.0 / B; end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[((-x) / B), $MachinePrecision], N[(1.0 / B), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B}\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 99.7%
distribute-lft-neg-in99.7%
Simplified99.7%
Taylor expanded in B around 0 54.8%
mul-1-neg54.8%
sub-neg54.8%
Simplified54.8%
Taylor expanded in x around inf 53.7%
neg-mul-153.7%
distribute-neg-frac53.7%
Simplified53.7%
if -1 < x < 1Initial program 99.9%
distribute-lft-neg-in99.9%
Simplified99.9%
Taylor expanded in B around 0 55.6%
mul-1-neg55.6%
sub-neg55.6%
Simplified55.6%
Taylor expanded in x around 0 53.8%
Final simplification53.8%
(FPCore (B x) :precision binary64 (/ (- 1.0 x) B))
double code(double B, double x) {
return (1.0 - x) / B;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = (1.0d0 - x) / b
end function
public static double code(double B, double x) {
return (1.0 - x) / B;
}
def code(B, x): return (1.0 - x) / B
function code(B, x) return Float64(Float64(1.0 - x) / B) end
function tmp = code(B, x) tmp = (1.0 - x) / B; end
code[B_, x_] := N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - x}{B}
\end{array}
Initial program 99.8%
distribute-lft-neg-in99.8%
Simplified99.8%
Taylor expanded in B around 0 55.2%
mul-1-neg55.2%
sub-neg55.2%
Simplified55.2%
Final simplification55.2%
(FPCore (B x) :precision binary64 (* B 0.16666666666666666))
double code(double B, double x) {
return B * 0.16666666666666666;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = b * 0.16666666666666666d0
end function
public static double code(double B, double x) {
return B * 0.16666666666666666;
}
def code(B, x): return B * 0.16666666666666666
function code(B, x) return Float64(B * 0.16666666666666666) end
function tmp = code(B, x) tmp = B * 0.16666666666666666; end
code[B_, x_] := N[(B * 0.16666666666666666), $MachinePrecision]
\begin{array}{l}
\\
B \cdot 0.16666666666666666
\end{array}
Initial program 99.8%
+-commutative99.8%
unsub-neg99.8%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Taylor expanded in B around 0 67.1%
Taylor expanded in B around inf 3.4%
*-commutative3.4%
Simplified3.4%
Final simplification3.4%
(FPCore (B x) :precision binary64 (/ 1.0 B))
double code(double B, double x) {
return 1.0 / B;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = 1.0d0 / b
end function
public static double code(double B, double x) {
return 1.0 / B;
}
def code(B, x): return 1.0 / B
function code(B, x) return Float64(1.0 / B) end
function tmp = code(B, x) tmp = 1.0 / B; end
code[B_, x_] := N[(1.0 / B), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{B}
\end{array}
Initial program 99.8%
distribute-lft-neg-in99.8%
Simplified99.8%
Taylor expanded in B around 0 55.2%
mul-1-neg55.2%
sub-neg55.2%
Simplified55.2%
Taylor expanded in x around 0 29.5%
Final simplification29.5%
herbie shell --seed 2023207
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))