
(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%
+-commutative99.7%
unsub-neg99.7%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (B x) :precision binary64 (if (or (<= x -2.6) (not (<= x 0.0017))) (- (/ 1.0 B) (/ x (tan B))) (/ (- 1.0 x) (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -2.6) || !(x <= 0.0017)) {
tmp = (1.0 / B) - (x / tan(B));
} else {
tmp = (1.0 - x) / 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 <= (-2.6d0)) .or. (.not. (x <= 0.0017d0))) then
tmp = (1.0d0 / b) - (x / tan(b))
else
tmp = (1.0d0 - x) / sin(b)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if ((x <= -2.6) || !(x <= 0.0017)) {
tmp = (1.0 / B) - (x / Math.tan(B));
} else {
tmp = (1.0 - x) / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -2.6) or not (x <= 0.0017): tmp = (1.0 / B) - (x / math.tan(B)) else: tmp = (1.0 - x) / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -2.6) || !(x <= 0.0017)) tmp = Float64(Float64(1.0 / B) - Float64(x / tan(B))); else tmp = Float64(Float64(1.0 - x) / sin(B)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if ((x <= -2.6) || ~((x <= 0.0017))) tmp = (1.0 / B) - (x / tan(B)); else tmp = (1.0 - x) / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -2.6], N[Not[LessEqual[x, 0.0017]], $MachinePrecision]], N[(N[(1.0 / B), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \lor \neg \left(x \leq 0.0017\right):\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - x}{\sin B}\\
\end{array}
\end{array}
if x < -2.60000000000000009 or 0.00169999999999999991 < x Initial program 99.5%
+-commutative99.5%
unsub-neg99.5%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
Taylor expanded in B around 0 97.9%
if -2.60000000000000009 < x < 0.00169999999999999991Initial program 99.8%
+-commutative99.8%
unsub-neg99.8%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
unsub-neg99.8%
*-inverses99.8%
*-commutative99.8%
*-lft-identity99.8%
*-lft-identity99.8%
times-frac99.8%
metadata-eval99.8%
*-inverses99.8%
times-frac78.8%
*-commutative78.8%
associate-*l*78.8%
associate-/r*99.8%
div-sub99.8%
Simplified99.8%
Taylor expanded in B around 0 98.7%
Final simplification98.3%
(FPCore (B x) :precision binary64 (if (or (<= B -0.028) (not (<= B 0.011))) (/ 1.0 (sin B)) (+ (* B (* x 0.3333333333333333)) (/ (- 1.0 x) B))))
double code(double B, double x) {
double tmp;
if ((B <= -0.028) || !(B <= 0.011)) {
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 ((b <= (-0.028d0)) .or. (.not. (b <= 0.011d0))) 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 ((B <= -0.028) || !(B <= 0.011)) {
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 (B <= -0.028) or not (B <= 0.011): 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 ((B <= -0.028) || !(B <= 0.011)) tmp = Float64(1.0 / sin(B)); else tmp = Float64(Float64(B * Float64(x * 0.3333333333333333)) + Float64(Float64(1.0 - x) / B)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if ((B <= -0.028) || ~((B <= 0.011))) tmp = 1.0 / sin(B); else tmp = (B * (x * 0.3333333333333333)) + ((1.0 - x) / B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[B, -0.028], N[Not[LessEqual[B, 0.011]], $MachinePrecision]], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[(N[(B * N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq -0.028 \lor \neg \left(B \leq 0.011\right):\\
\;\;\;\;\frac{1}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;B \cdot \left(x \cdot 0.3333333333333333\right) + \frac{1 - x}{B}\\
\end{array}
\end{array}
if B < -0.0280000000000000006 or 0.010999999999999999 < B Initial program 99.5%
distribute-lft-neg-in99.5%
Simplified99.5%
Taylor expanded in x around 0 52.3%
if -0.0280000000000000006 < B < 0.010999999999999999Initial program 99.8%
distribute-lft-neg-in99.8%
Simplified99.8%
Taylor expanded in B around 0 99.8%
Taylor expanded in B around 0 99.8%
+-commutative99.8%
associate-+l+99.8%
*-commutative99.8%
associate-*l*99.8%
mul-1-neg99.8%
sub-neg99.8%
div-sub99.8%
Simplified99.8%
Final simplification74.6%
(FPCore (B x) :precision binary64 (/ (- 1.0 x) (sin B)))
double code(double B, double x) {
return (1.0 - x) / sin(B);
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = (1.0d0 - x) / sin(b)
end function
public static double code(double B, double x) {
return (1.0 - x) / Math.sin(B);
}
def code(B, x): return (1.0 - x) / math.sin(B)
function code(B, x) return Float64(Float64(1.0 - x) / sin(B)) end
function tmp = code(B, x) tmp = (1.0 - x) / sin(B); end
code[B_, x_] := N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - x}{\sin B}
\end{array}
Initial program 99.7%
+-commutative99.7%
unsub-neg99.7%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Taylor expanded in x around 0 99.7%
Taylor expanded in x around 0 99.7%
mul-1-neg99.7%
unsub-neg99.7%
*-inverses99.7%
*-commutative99.7%
*-lft-identity99.7%
*-lft-identity99.7%
times-frac99.7%
metadata-eval99.7%
*-inverses99.7%
times-frac86.7%
*-commutative86.7%
associate-*l*86.7%
associate-/r*99.7%
div-sub99.7%
Simplified99.7%
Taylor expanded in B around 0 76.3%
Final simplification76.3%
(FPCore (B x) :precision binary64 (+ (* B (* x 0.3333333333333333)) (/ (- 1.0 x) B)))
double code(double B, double x) {
return (B * (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 * (x * 0.3333333333333333d0)) + ((1.0d0 - x) / b)
end function
public static double code(double B, double x) {
return (B * (x * 0.3333333333333333)) + ((1.0 - x) / B);
}
def code(B, x): return (B * (x * 0.3333333333333333)) + ((1.0 - x) / B)
function code(B, x) return Float64(Float64(B * Float64(x * 0.3333333333333333)) + Float64(Float64(1.0 - x) / B)) end
function tmp = code(B, x) tmp = (B * (x * 0.3333333333333333)) + ((1.0 - x) / B); end
code[B_, x_] := N[(N[(B * N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
B \cdot \left(x \cdot 0.3333333333333333\right) + \frac{1 - x}{B}
\end{array}
Initial program 99.7%
distribute-lft-neg-in99.7%
Simplified99.7%
Taylor expanded in B around 0 72.4%
Taylor expanded in B around 0 49.0%
+-commutative49.0%
associate-+l+49.0%
*-commutative49.0%
associate-*l*49.0%
mul-1-neg49.0%
sub-neg49.0%
div-sub49.0%
Simplified49.0%
Final simplification49.0%
(FPCore (B x) :precision binary64 (if (or (<= x -105000.0) (not (<= x 7800.0))) (/ (- x) B) (/ (+ 1.0 x) B)))
double code(double B, double x) {
double tmp;
if ((x <= -105000.0) || !(x <= 7800.0)) {
tmp = -x / B;
} else {
tmp = (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 <= (-105000.0d0)) .or. (.not. (x <= 7800.0d0))) then
tmp = -x / b
else
tmp = (1.0d0 + x) / b
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if ((x <= -105000.0) || !(x <= 7800.0)) {
tmp = -x / B;
} else {
tmp = (1.0 + x) / B;
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -105000.0) or not (x <= 7800.0): tmp = -x / B else: tmp = (1.0 + x) / B return tmp
function code(B, x) tmp = 0.0 if ((x <= -105000.0) || !(x <= 7800.0)) tmp = Float64(Float64(-x) / B); else tmp = Float64(Float64(1.0 + x) / B); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if ((x <= -105000.0) || ~((x <= 7800.0))) tmp = -x / B; else tmp = (1.0 + x) / B; end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -105000.0], N[Not[LessEqual[x, 7800.0]], $MachinePrecision]], N[((-x) / B), $MachinePrecision], N[(N[(1.0 + x), $MachinePrecision] / B), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -105000 \lor \neg \left(x \leq 7800\right):\\
\;\;\;\;\frac{-x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 + x}{B}\\
\end{array}
\end{array}
if x < -105000 or 7800 < x Initial program 99.5%
distribute-lft-neg-in99.5%
Simplified99.5%
Taylor expanded in B around 0 98.6%
Taylor expanded in B around 0 50.5%
associate-*r/50.5%
mul-1-neg50.5%
Simplified50.5%
Taylor expanded in x around inf 49.7%
associate-*r/49.7%
mul-1-neg49.7%
Simplified49.7%
if -105000 < x < 7800Initial program 99.8%
distribute-lft-neg-in99.8%
Simplified99.8%
Taylor expanded in B around 0 47.3%
Taylor expanded in B around 0 46.4%
associate-*r/46.4%
mul-1-neg46.4%
Simplified46.4%
expm1-log1p-u22.3%
expm1-udef22.1%
+-commutative22.1%
*-un-lft-identity22.1%
div-inv22.1%
distribute-rgt-out22.1%
add-sqr-sqrt10.8%
sqrt-unprod21.7%
sqr-neg21.7%
sqrt-unprod10.8%
add-sqr-sqrt21.7%
Applied egg-rr21.7%
expm1-def21.9%
expm1-log1p45.4%
associate-*l/45.4%
*-lft-identity45.4%
Simplified45.4%
Final simplification47.5%
(FPCore (B x) :precision binary64 (if (or (<= x -105000.0) (not (<= x 7800.0))) (/ (- x) B) (/ 1.0 B)))
double code(double B, double x) {
double tmp;
if ((x <= -105000.0) || !(x <= 7800.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 <= (-105000.0d0)) .or. (.not. (x <= 7800.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 <= -105000.0) || !(x <= 7800.0)) {
tmp = -x / B;
} else {
tmp = 1.0 / B;
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -105000.0) or not (x <= 7800.0): tmp = -x / B else: tmp = 1.0 / B return tmp
function code(B, x) tmp = 0.0 if ((x <= -105000.0) || !(x <= 7800.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 <= -105000.0) || ~((x <= 7800.0))) tmp = -x / B; else tmp = 1.0 / B; end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -105000.0], N[Not[LessEqual[x, 7800.0]], $MachinePrecision]], N[((-x) / B), $MachinePrecision], N[(1.0 / B), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -105000 \lor \neg \left(x \leq 7800\right):\\
\;\;\;\;\frac{-x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B}\\
\end{array}
\end{array}
if x < -105000 or 7800 < x Initial program 99.5%
distribute-lft-neg-in99.5%
Simplified99.5%
Taylor expanded in B around 0 98.6%
Taylor expanded in B around 0 50.5%
associate-*r/50.5%
mul-1-neg50.5%
Simplified50.5%
Taylor expanded in x around inf 49.7%
associate-*r/49.7%
mul-1-neg49.7%
Simplified49.7%
if -105000 < x < 7800Initial program 99.8%
distribute-lft-neg-in99.8%
Simplified99.8%
Taylor expanded in B around 0 47.3%
Taylor expanded in B around 0 46.4%
associate-*r/46.4%
mul-1-neg46.4%
Simplified46.4%
Taylor expanded in x around 0 45.4%
Final simplification47.5%
(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%
distribute-lft-neg-in99.7%
Simplified99.7%
Taylor expanded in B around 0 48.4%
mul-1-neg48.4%
sub-neg48.4%
Simplified48.4%
Final simplification48.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.7%
distribute-lft-neg-in99.7%
Simplified99.7%
Taylor expanded in B around 0 72.4%
Taylor expanded in B around 0 48.4%
associate-*r/48.4%
mul-1-neg48.4%
Simplified48.4%
Taylor expanded in x around 0 24.6%
Final simplification24.6%
herbie shell --seed 2023230
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))