
(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.7%
distribute-lft-neg-in99.7%
+-commutative99.7%
cancel-sign-sub-inv99.7%
*-commutative99.7%
*-commutative99.7%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (B x) :precision binary64 (if (or (<= x -1.75) (not (<= x 1.0))) (/ -1.0 (/ (tan B) x)) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.75) || !(x <= 1.0)) {
tmp = -1.0 / (tan(B) / x);
} 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.75d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (-1.0d0) / (tan(b) / x)
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.75) || !(x <= 1.0)) {
tmp = -1.0 / (Math.tan(B) / x);
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -1.75) or not (x <= 1.0): tmp = -1.0 / (math.tan(B) / x) else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -1.75) || !(x <= 1.0)) tmp = Float64(-1.0 / Float64(tan(B) / x)); else tmp = Float64(1.0 / sin(B)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if ((x <= -1.75) || ~((x <= 1.0))) tmp = -1.0 / (tan(B) / x); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -1.75], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-1.0 / N[(N[Tan[B], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.75 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-1}{\frac{\tan B}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -1.75 or 1 < x Initial program 99.6%
+-commutative99.6%
div-inv99.8%
sub-neg99.8%
clear-num99.7%
frac-sub86.8%
*-un-lft-identity86.8%
*-commutative86.8%
*-un-lft-identity86.8%
Applied egg-rr86.8%
associate-/r*99.7%
div-sub99.7%
*-inverses99.7%
Simplified99.7%
Taylor expanded in x around inf 97.6%
if -1.75 < x < 1Initial program 99.8%
Taylor expanded in x around 0 96.5%
Final simplification97.1%
(FPCore (B x) :precision binary64 (if (or (<= x -1.45e-14) (not (<= x 4.1e-5))) (/ (- 1.0 x) (tan B)) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.45e-14) || !(x <= 4.1e-5)) {
tmp = (1.0 - x) / 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.45d-14)) .or. (.not. (x <= 4.1d-5))) then
tmp = (1.0d0 - x) / 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.45e-14) || !(x <= 4.1e-5)) {
tmp = (1.0 - x) / Math.tan(B);
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -1.45e-14) or not (x <= 4.1e-5): tmp = (1.0 - x) / math.tan(B) else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -1.45e-14) || !(x <= 4.1e-5)) tmp = Float64(Float64(1.0 - x) / 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.45e-14) || ~((x <= 4.1e-5))) tmp = (1.0 - x) / tan(B); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -1.45e-14], N[Not[LessEqual[x, 4.1e-5]], $MachinePrecision]], N[(N[(1.0 - x), $MachinePrecision] / N[Tan[B], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-14} \lor \neg \left(x \leq 4.1 \cdot 10^{-5}\right):\\
\;\;\;\;\frac{1 - x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -1.4500000000000001e-14 or 4.10000000000000005e-5 < x Initial program 99.6%
+-commutative99.6%
div-inv99.8%
sub-neg99.8%
clear-num99.7%
frac-sub83.9%
*-un-lft-identity83.9%
*-commutative83.9%
*-un-lft-identity83.9%
Applied egg-rr83.9%
associate-/r*99.6%
div-sub99.7%
*-inverses99.7%
Simplified99.7%
Taylor expanded in B around 0 98.2%
div-sub88.6%
*-un-lft-identity88.6%
*-un-lft-identity88.6%
associate-*l/88.6%
times-frac98.1%
remove-double-div98.1%
clear-num98.3%
Applied egg-rr98.3%
*-commutative98.3%
associate-*l/98.3%
associate-*r/88.0%
unsub-neg88.0%
neg-mul-188.0%
distribute-rgt-in98.3%
associate-*l/98.3%
distribute-rgt-in98.3%
neg-mul-198.3%
unsub-neg98.3%
lft-mult-inverse98.3%
Simplified98.3%
if -1.4500000000000001e-14 < x < 4.10000000000000005e-5Initial program 99.8%
Taylor expanded in x around 0 98.6%
Final simplification98.5%
(FPCore (B x) :precision binary64 (if (<= B 0.18) (+ (* B (+ 0.16666666666666666 (* x 0.3333333333333333))) (/ (- 1.0 x) B)) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if (B <= 0.18) {
tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / 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 (b <= 0.18d0) then
tmp = (b * (0.16666666666666666d0 + (x * 0.3333333333333333d0))) + ((1.0d0 - x) / b)
else
tmp = 1.0d0 / sin(b)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (B <= 0.18) {
tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B);
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if B <= 0.18: tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B) else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if (B <= 0.18) tmp = Float64(Float64(B * Float64(0.16666666666666666 + Float64(x * 0.3333333333333333))) + Float64(Float64(1.0 - x) / B)); else tmp = Float64(1.0 / sin(B)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (B <= 0.18) tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[B, 0.18], N[(N[(B * N[(0.16666666666666666 + N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq 0.18:\\
\;\;\;\;B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right) + \frac{1 - x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if B < 0.17999999999999999Initial program 99.7%
Taylor expanded in B around 0 65.5%
associate--l+65.5%
*-commutative65.5%
div-sub65.5%
Simplified65.5%
if 0.17999999999999999 < B Initial program 99.5%
Taylor expanded in x around 0 46.6%
Final simplification61.7%
(FPCore (B x) :precision binary64 (+ (* 0.3333333333333333 (* B x)) (/ (* x (+ -1.0 (/ 1.0 x))) B)))
double code(double B, double x) {
return (0.3333333333333333 * (B * x)) + ((x * (-1.0 + (1.0 / x))) / B);
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = (0.3333333333333333d0 * (b * x)) + ((x * ((-1.0d0) + (1.0d0 / x))) / b)
end function
public static double code(double B, double x) {
return (0.3333333333333333 * (B * x)) + ((x * (-1.0 + (1.0 / x))) / B);
}
def code(B, x): return (0.3333333333333333 * (B * x)) + ((x * (-1.0 + (1.0 / x))) / B)
function code(B, x) return Float64(Float64(0.3333333333333333 * Float64(B * x)) + Float64(Float64(x * Float64(-1.0 + Float64(1.0 / x))) / B)) end
function tmp = code(B, x) tmp = (0.3333333333333333 * (B * x)) + ((x * (-1.0 + (1.0 / x))) / B); end
code[B_, x_] := N[(N[(0.3333333333333333 * N[(B * x), $MachinePrecision]), $MachinePrecision] + N[(N[(x * N[(-1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.3333333333333333 \cdot \left(B \cdot x\right) + \frac{x \cdot \left(-1 + \frac{1}{x}\right)}{B}
\end{array}
Initial program 99.7%
+-commutative99.7%
div-inv99.8%
sub-neg99.8%
clear-num99.7%
frac-sub86.9%
*-un-lft-identity86.9%
*-commutative86.9%
*-un-lft-identity86.9%
Applied egg-rr86.9%
associate-/r*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around 0 77.7%
Taylor expanded in B around 0 52.9%
Taylor expanded in x around inf 53.2%
Final simplification53.2%
(FPCore (B x) :precision binary64 (if (or (<= x -550.0) (not (<= x 1.0))) (/ (- x) B) (/ 1.0 B)))
double code(double B, double x) {
double tmp;
if ((x <= -550.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 <= (-550.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 <= -550.0) || !(x <= 1.0)) {
tmp = -x / B;
} else {
tmp = 1.0 / B;
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -550.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 <= -550.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 <= -550.0) || ~((x <= 1.0))) tmp = -x / B; else tmp = 1.0 / B; end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -550.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 -550 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B}\\
\end{array}
\end{array}
if x < -550 or 1 < x Initial program 99.6%
+-commutative99.6%
div-inv99.8%
sub-neg99.8%
clear-num99.7%
frac-sub86.7%
*-un-lft-identity86.7%
*-commutative86.7%
*-un-lft-identity86.7%
Applied egg-rr86.7%
associate-/r*99.7%
div-sub99.7%
*-inverses99.7%
Simplified99.7%
Taylor expanded in B around 0 52.4%
associate-/l*52.4%
sub-neg52.4%
metadata-eval52.4%
Simplified52.4%
Taylor expanded in x around inf 51.4%
associate-*r/51.4%
neg-mul-151.4%
Simplified51.4%
if -550 < x < 1Initial program 99.8%
+-commutative99.8%
div-inv99.8%
sub-neg99.8%
clear-num99.8%
frac-sub87.1%
*-un-lft-identity87.1%
*-commutative87.1%
*-un-lft-identity87.1%
Applied egg-rr87.1%
associate-/r*99.5%
div-sub99.5%
*-inverses99.5%
Simplified99.5%
Taylor expanded in B around 0 53.2%
associate-/l*28.6%
sub-neg28.6%
metadata-eval28.6%
Simplified28.6%
Taylor expanded in x around 0 51.7%
Final simplification51.5%
(FPCore (B x) :precision binary64 (+ (* B (+ 0.16666666666666666 (* x 0.3333333333333333))) (/ (- 1.0 x) B)))
double code(double B, double x) {
return (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B);
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = (b * (0.16666666666666666d0 + (x * 0.3333333333333333d0))) + ((1.0d0 - x) / b)
end function
public static double code(double B, double x) {
return (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B);
}
def code(B, x): return (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B)
function code(B, x) return Float64(Float64(B * Float64(0.16666666666666666 + Float64(x * 0.3333333333333333))) + Float64(Float64(1.0 - x) / B)) end
function tmp = code(B, x) tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B); end
code[B_, x_] := N[(N[(B * N[(0.16666666666666666 + N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right) + \frac{1 - x}{B}
\end{array}
Initial program 99.7%
Taylor expanded in B around 0 53.0%
associate--l+53.0%
*-commutative53.0%
div-sub53.1%
Simplified53.1%
Final simplification53.1%
(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.7%
Taylor expanded in B around 0 52.8%
Final simplification52.8%
(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.7%
+-commutative99.7%
div-inv99.8%
sub-neg99.8%
clear-num99.7%
frac-sub86.9%
*-un-lft-identity86.9%
*-commutative86.9%
*-un-lft-identity86.9%
Applied egg-rr86.9%
associate-/r*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around 0 52.8%
associate-/l*40.6%
sub-neg40.6%
metadata-eval40.6%
Simplified40.6%
Taylor expanded in x around 0 27.2%
Final simplification27.2%
herbie shell --seed 2024027
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))