
(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 11 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 (/ (- (/ (tan B) (sin B)) x) (tan B)))
double code(double B, double x) {
return ((tan(B) / sin(B)) - x) / tan(B);
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = ((tan(b) / sin(b)) - x) / tan(b)
end function
public static double code(double B, double x) {
return ((Math.tan(B) / Math.sin(B)) - x) / Math.tan(B);
}
def code(B, x): return ((math.tan(B) / math.sin(B)) - x) / math.tan(B)
function code(B, x) return Float64(Float64(Float64(tan(B) / sin(B)) - x) / tan(B)) end
function tmp = code(B, x) tmp = ((tan(B) / sin(B)) - x) / tan(B); end
code[B_, x_] := N[(N[(N[(N[Tan[B], $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] / N[Tan[B], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\tan B}{\sin B} - x}{\tan B}
\end{array}
Initial program 99.7%
+-commutative99.7%
div-inv99.7%
sub-neg99.7%
frac-sub82.6%
associate-/r*99.7%
*-un-lft-identity99.7%
*-commutative99.7%
Applied egg-rr99.7%
div-sub99.7%
Applied egg-rr99.7%
associate-/l*99.8%
*-inverses99.8%
*-rgt-identity99.8%
Simplified99.8%
(FPCore (B x) :precision binary64 (/ (- (/ 1.0 (cos B)) x) (tan B)))
double code(double B, double x) {
return ((1.0 / cos(B)) - x) / tan(B);
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = ((1.0d0 / cos(b)) - x) / tan(b)
end function
public static double code(double B, double x) {
return ((1.0 / Math.cos(B)) - x) / Math.tan(B);
}
def code(B, x): return ((1.0 / math.cos(B)) - x) / math.tan(B)
function code(B, x) return Float64(Float64(Float64(1.0 / cos(B)) - x) / tan(B)) end
function tmp = code(B, x) tmp = ((1.0 / cos(B)) - x) / tan(B); end
code[B_, x_] := N[(N[(N[(1.0 / N[Cos[B], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] / N[Tan[B], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{\cos B} - x}{\tan B}
\end{array}
Initial program 99.7%
+-commutative99.7%
div-inv99.7%
sub-neg99.7%
frac-sub82.6%
associate-/r*99.7%
*-un-lft-identity99.7%
*-commutative99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 99.7%
neg-mul-199.7%
+-commutative99.7%
unsub-neg99.7%
Simplified99.7%
(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%
*-commutative99.7%
remove-double-neg99.7%
distribute-frac-neg299.7%
tan-neg99.7%
cancel-sign-sub-inv99.7%
*-commutative99.7%
associate-*r/99.7%
*-rgt-identity99.7%
tan-neg99.7%
distribute-neg-frac299.7%
distribute-neg-frac99.7%
remove-double-neg99.7%
Simplified99.7%
(FPCore (B x) :precision binary64 (if (or (<= x -3.2e-5) (not (<= x 9e-9))) (/ (- 1.0 x) (tan B)) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -3.2e-5) || !(x <= 9e-9)) {
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 <= (-3.2d-5)) .or. (.not. (x <= 9d-9))) 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 <= -3.2e-5) || !(x <= 9e-9)) {
tmp = (1.0 - x) / Math.tan(B);
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -3.2e-5) or not (x <= 9e-9): 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 <= -3.2e-5) || !(x <= 9e-9)) 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 <= -3.2e-5) || ~((x <= 9e-9))) tmp = (1.0 - x) / tan(B); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -3.2e-5], N[Not[LessEqual[x, 9e-9]], $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 -3.2 \cdot 10^{-5} \lor \neg \left(x \leq 9 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{1 - x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -3.19999999999999986e-5 or 8.99999999999999953e-9 < x Initial program 99.6%
+-commutative99.6%
div-inv99.7%
sub-neg99.7%
frac-sub91.2%
associate-/r*99.6%
*-un-lft-identity99.6%
*-commutative99.6%
Applied egg-rr99.6%
Taylor expanded in B around 0 98.5%
if -3.19999999999999986e-5 < x < 8.99999999999999953e-9Initial program 99.8%
Taylor expanded in x around 0 98.5%
Final simplification98.5%
(FPCore (B x) :precision binary64 (if (or (<= x -1.12) (not (<= x 1.0))) (/ x (- (tan B))) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.12) || !(x <= 1.0)) {
tmp = 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.12d0)) .or. (.not. (x <= 1.0d0))) then
tmp = 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.12) || !(x <= 1.0)) {
tmp = x / -Math.tan(B);
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -1.12) or not (x <= 1.0): tmp = x / -math.tan(B) else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -1.12) || !(x <= 1.0)) tmp = Float64(x / Float64(-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.12) || ~((x <= 1.0))) tmp = x / -tan(B); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -1.12], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x / (-N[Tan[B], $MachinePrecision])), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.12 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{x}{-\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -1.1200000000000001 or 1 < x Initial program 99.6%
+-commutative99.6%
div-inv99.7%
sub-neg99.7%
frac-sub92.4%
associate-/r*99.6%
*-un-lft-identity99.6%
*-commutative99.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 98.0%
neg-mul-198.0%
Simplified98.0%
if -1.1200000000000001 < x < 1Initial program 99.8%
Taylor expanded in x around 0 96.9%
Final simplification97.4%
(FPCore (B x)
:precision binary64
(if (<= B 0.112)
(/
(- (+ 1.0 (* (* B B) (+ 0.16666666666666666 (* x 0.3333333333333333)))) x)
B)
(/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if (B <= 0.112) {
tmp = ((1.0 + ((B * B) * (0.16666666666666666 + (x * 0.3333333333333333)))) - 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.112d0) then
tmp = ((1.0d0 + ((b * b) * (0.16666666666666666d0 + (x * 0.3333333333333333d0)))) - 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.112) {
tmp = ((1.0 + ((B * B) * (0.16666666666666666 + (x * 0.3333333333333333)))) - x) / B;
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if B <= 0.112: tmp = ((1.0 + ((B * B) * (0.16666666666666666 + (x * 0.3333333333333333)))) - x) / B else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if (B <= 0.112) tmp = Float64(Float64(Float64(1.0 + Float64(Float64(B * B) * Float64(0.16666666666666666 + Float64(x * 0.3333333333333333)))) - 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.112) tmp = ((1.0 + ((B * B) * (0.16666666666666666 + (x * 0.3333333333333333)))) - x) / B; else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[B, 0.112], N[(N[(N[(1.0 + N[(N[(B * B), $MachinePrecision] * N[(0.16666666666666666 + N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] / B), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq 0.112:\\
\;\;\;\;\frac{\left(1 + \left(B \cdot B\right) \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right)\right) - x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if B < 0.112000000000000002Initial program 99.8%
Taylor expanded in B around 0 68.7%
unpow268.7%
Applied egg-rr68.7%
if 0.112000000000000002 < B Initial program 99.5%
Taylor expanded in x around 0 48.0%
Final simplification64.1%
(FPCore (B x) :precision binary64 (+ (* B 0.16666666666666666) (+ (/ 1.0 B) (* x (+ (* B 0.3333333333333333) (/ -1.0 B))))))
double code(double B, double x) {
return (B * 0.16666666666666666) + ((1.0 / B) + (x * ((B * 0.3333333333333333) + (-1.0 / B))));
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = (b * 0.16666666666666666d0) + ((1.0d0 / b) + (x * ((b * 0.3333333333333333d0) + ((-1.0d0) / b))))
end function
public static double code(double B, double x) {
return (B * 0.16666666666666666) + ((1.0 / B) + (x * ((B * 0.3333333333333333) + (-1.0 / B))));
}
def code(B, x): return (B * 0.16666666666666666) + ((1.0 / B) + (x * ((B * 0.3333333333333333) + (-1.0 / B))))
function code(B, x) return Float64(Float64(B * 0.16666666666666666) + Float64(Float64(1.0 / B) + Float64(x * Float64(Float64(B * 0.3333333333333333) + Float64(-1.0 / B))))) end
function tmp = code(B, x) tmp = (B * 0.16666666666666666) + ((1.0 / B) + (x * ((B * 0.3333333333333333) + (-1.0 / B)))); end
code[B_, x_] := N[(N[(B * 0.16666666666666666), $MachinePrecision] + N[(N[(1.0 / B), $MachinePrecision] + N[(x * N[(N[(B * 0.3333333333333333), $MachinePrecision] + N[(-1.0 / B), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
B \cdot 0.16666666666666666 + \left(\frac{1}{B} + x \cdot \left(B \cdot 0.3333333333333333 + \frac{-1}{B}\right)\right)
\end{array}
Initial program 99.7%
Taylor expanded in B around 0 54.3%
Taylor expanded in x around 0 54.3%
Final simplification54.3%
(FPCore (B x) :precision binary64 (/ (- (+ 1.0 (* (* B B) (+ 0.16666666666666666 (* x 0.3333333333333333)))) x) B))
double code(double B, double x) {
return ((1.0 + ((B * B) * (0.16666666666666666 + (x * 0.3333333333333333)))) - x) / B;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = ((1.0d0 + ((b * b) * (0.16666666666666666d0 + (x * 0.3333333333333333d0)))) - x) / b
end function
public static double code(double B, double x) {
return ((1.0 + ((B * B) * (0.16666666666666666 + (x * 0.3333333333333333)))) - x) / B;
}
def code(B, x): return ((1.0 + ((B * B) * (0.16666666666666666 + (x * 0.3333333333333333)))) - x) / B
function code(B, x) return Float64(Float64(Float64(1.0 + Float64(Float64(B * B) * Float64(0.16666666666666666 + Float64(x * 0.3333333333333333)))) - x) / B) end
function tmp = code(B, x) tmp = ((1.0 + ((B * B) * (0.16666666666666666 + (x * 0.3333333333333333)))) - x) / B; end
code[B_, x_] := N[(N[(N[(1.0 + N[(N[(B * B), $MachinePrecision] * N[(0.16666666666666666 + N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] / B), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \left(B \cdot B\right) \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right)\right) - x}{B}
\end{array}
Initial program 99.7%
Taylor expanded in B around 0 54.3%
unpow254.3%
Applied egg-rr54.3%
Final simplification54.3%
(FPCore (B x) :precision binary64 (if (or (<= x -3.6e-6) (not (<= x 1.0))) (/ x (- B)) (/ 1.0 B)))
double code(double B, double x) {
double tmp;
if ((x <= -3.6e-6) || !(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 <= (-3.6d-6)) .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 <= -3.6e-6) || !(x <= 1.0)) {
tmp = x / -B;
} else {
tmp = 1.0 / B;
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -3.6e-6) or not (x <= 1.0): tmp = x / -B else: tmp = 1.0 / B return tmp
function code(B, x) tmp = 0.0 if ((x <= -3.6e-6) || !(x <= 1.0)) tmp = Float64(x / Float64(-B)); else tmp = Float64(1.0 / B); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if ((x <= -3.6e-6) || ~((x <= 1.0))) tmp = x / -B; else tmp = 1.0 / B; end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -3.6e-6], 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 -3.6 \cdot 10^{-6} \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{x}{-B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B}\\
\end{array}
\end{array}
if x < -3.59999999999999984e-6 or 1 < x Initial program 99.6%
Taylor expanded in B around 0 50.1%
Taylor expanded in x around inf 48.9%
associate-*r/48.9%
neg-mul-148.9%
Simplified48.9%
if -3.59999999999999984e-6 < x < 1Initial program 99.8%
Taylor expanded in B around 0 58.5%
Taylor expanded in x around 0 57.0%
Final simplification52.9%
(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 54.2%
(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%
Taylor expanded in B around 0 54.2%
Taylor expanded in x around 0 29.8%
herbie shell --seed 2024118
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))