
(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%
*-commutative99.7%
remove-double-neg99.7%
distribute-frac-neg299.7%
tan-neg99.7%
cancel-sign-sub-inv99.7%
*-commutative99.7%
associate-*r/99.8%
*-rgt-identity99.8%
tan-neg99.8%
distribute-neg-frac299.8%
distribute-neg-frac99.8%
remove-double-neg99.8%
Simplified99.8%
(FPCore (B x) :precision binary64 (if (<= x -1.25) (/ (- 1.0 x) (tan B)) (if (<= x 51000.0) (- (/ 1.0 (sin B)) (/ x B)) (/ x (- (tan B))))))
double code(double B, double x) {
double tmp;
if (x <= -1.25) {
tmp = (1.0 - x) / tan(B);
} else if (x <= 51000.0) {
tmp = (1.0 / sin(B)) - (x / B);
} else {
tmp = x / -tan(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.25d0)) then
tmp = (1.0d0 - x) / tan(b)
else if (x <= 51000.0d0) then
tmp = (1.0d0 / sin(b)) - (x / b)
else
tmp = x / -tan(b)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (x <= -1.25) {
tmp = (1.0 - x) / Math.tan(B);
} else if (x <= 51000.0) {
tmp = (1.0 / Math.sin(B)) - (x / B);
} else {
tmp = x / -Math.tan(B);
}
return tmp;
}
def code(B, x): tmp = 0 if x <= -1.25: tmp = (1.0 - x) / math.tan(B) elif x <= 51000.0: tmp = (1.0 / math.sin(B)) - (x / B) else: tmp = x / -math.tan(B) return tmp
function code(B, x) tmp = 0.0 if (x <= -1.25) tmp = Float64(Float64(1.0 - x) / tan(B)); elseif (x <= 51000.0) tmp = Float64(Float64(1.0 / sin(B)) - Float64(x / B)); else tmp = Float64(x / Float64(-tan(B))); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (x <= -1.25) tmp = (1.0 - x) / tan(B); elseif (x <= 51000.0) tmp = (1.0 / sin(B)) - (x / B); else tmp = x / -tan(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[x, -1.25], N[(N[(1.0 - x), $MachinePrecision] / N[Tan[B], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 51000.0], N[(N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision] - N[(x / B), $MachinePrecision]), $MachinePrecision], N[(x / (-N[Tan[B], $MachinePrecision])), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25:\\
\;\;\;\;\frac{1 - x}{\tan B}\\
\mathbf{elif}\;x \leq 51000:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-\tan B}\\
\end{array}
\end{array}
if x < -1.25Initial program 99.6%
+-commutative99.6%
div-inv99.8%
sub-neg99.8%
clear-num99.4%
frac-sub88.9%
*-un-lft-identity88.9%
*-commutative88.9%
*-un-lft-identity88.9%
Applied egg-rr88.9%
associate-/r*99.5%
div-sub99.5%
*-inverses99.5%
Simplified99.5%
div-sub75.6%
div-inv75.6%
associate-/l/99.4%
*-commutative99.4%
clear-num99.4%
clear-num99.8%
Applied egg-rr99.8%
sub-neg99.8%
neg-mul-199.8%
distribute-rgt-in99.8%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in B around 0 99.6%
if -1.25 < x < 51000Initial program 99.8%
distribute-lft-neg-in99.8%
+-commutative99.8%
*-commutative99.8%
remove-double-neg99.8%
distribute-frac-neg299.8%
tan-neg99.8%
cancel-sign-sub-inv99.8%
*-commutative99.8%
associate-*r/99.8%
*-rgt-identity99.8%
tan-neg99.8%
distribute-neg-frac299.8%
distribute-neg-frac99.8%
remove-double-neg99.8%
Simplified99.8%
Taylor expanded in B around 0 97.1%
if 51000 < x Initial program 99.7%
Taylor expanded in x around inf 98.1%
mul-1-neg98.1%
associate-/l*98.0%
distribute-lft-neg-in98.0%
Simplified98.0%
distribute-lft-neg-out98.0%
clear-num98.0%
tan-quot98.1%
div-inv98.2%
neg-sub098.2%
Applied egg-rr98.2%
neg-sub098.2%
distribute-frac-neg298.2%
Simplified98.2%
(FPCore (B x) :precision binary64 (if (or (<= x -102500000000.0) (not (<= x 0.92))) (/ x (- (tan B))) (/ (- 1.0 x) (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -102500000000.0) || !(x <= 0.92)) {
tmp = 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 <= (-102500000000.0d0)) .or. (.not. (x <= 0.92d0))) then
tmp = 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 <= -102500000000.0) || !(x <= 0.92)) {
tmp = x / -Math.tan(B);
} else {
tmp = (1.0 - x) / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -102500000000.0) or not (x <= 0.92): tmp = x / -math.tan(B) else: tmp = (1.0 - x) / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -102500000000.0) || !(x <= 0.92)) tmp = Float64(x / Float64(-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 <= -102500000000.0) || ~((x <= 0.92))) tmp = x / -tan(B); else tmp = (1.0 - x) / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -102500000000.0], N[Not[LessEqual[x, 0.92]], $MachinePrecision]], N[(x / (-N[Tan[B], $MachinePrecision])), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -102500000000 \lor \neg \left(x \leq 0.92\right):\\
\;\;\;\;\frac{x}{-\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - x}{\sin B}\\
\end{array}
\end{array}
if x < -1.025e11 or 0.92000000000000004 < x Initial program 99.6%
Taylor expanded in x around inf 98.0%
mul-1-neg98.0%
associate-/l*97.8%
distribute-lft-neg-in97.8%
Simplified97.8%
distribute-lft-neg-out97.8%
clear-num97.8%
tan-quot97.9%
div-inv98.1%
neg-sub098.1%
Applied egg-rr98.1%
neg-sub098.1%
distribute-frac-neg298.1%
Simplified98.1%
if -1.025e11 < x < 0.92000000000000004Initial program 99.8%
Taylor expanded in x around inf 75.1%
Taylor expanded in x around 0 99.8%
+-commutative99.8%
*-lft-identity99.8%
*-lft-identity99.8%
rgt-mult-inverse99.7%
associate-*r/75.1%
mul-1-neg75.1%
associate-/l*75.1%
distribute-rgt-neg-in75.1%
mul-1-neg75.1%
distribute-lft-in75.1%
mul-1-neg75.1%
sub-neg75.1%
div-sub75.1%
associate-*r/99.7%
Simplified99.8%
Taylor expanded in B around 0 97.8%
mul-1-neg97.8%
unsub-neg97.8%
Simplified97.8%
Final simplification97.9%
(FPCore (B x) :precision binary64 (if (<= x -1.15) (/ (- 1.0 x) (tan B)) (if (<= x 0.92) (/ (- 1.0 x) (sin B)) (/ x (- (tan B))))))
double code(double B, double x) {
double tmp;
if (x <= -1.15) {
tmp = (1.0 - x) / tan(B);
} else if (x <= 0.92) {
tmp = (1.0 - x) / sin(B);
} else {
tmp = x / -tan(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.15d0)) then
tmp = (1.0d0 - x) / tan(b)
else if (x <= 0.92d0) then
tmp = (1.0d0 - x) / sin(b)
else
tmp = x / -tan(b)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (x <= -1.15) {
tmp = (1.0 - x) / Math.tan(B);
} else if (x <= 0.92) {
tmp = (1.0 - x) / Math.sin(B);
} else {
tmp = x / -Math.tan(B);
}
return tmp;
}
def code(B, x): tmp = 0 if x <= -1.15: tmp = (1.0 - x) / math.tan(B) elif x <= 0.92: tmp = (1.0 - x) / math.sin(B) else: tmp = x / -math.tan(B) return tmp
function code(B, x) tmp = 0.0 if (x <= -1.15) tmp = Float64(Float64(1.0 - x) / tan(B)); elseif (x <= 0.92) tmp = Float64(Float64(1.0 - x) / sin(B)); else tmp = Float64(x / Float64(-tan(B))); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (x <= -1.15) tmp = (1.0 - x) / tan(B); elseif (x <= 0.92) tmp = (1.0 - x) / sin(B); else tmp = x / -tan(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[x, -1.15], N[(N[(1.0 - x), $MachinePrecision] / N[Tan[B], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.92], N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[(x / (-N[Tan[B], $MachinePrecision])), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15:\\
\;\;\;\;\frac{1 - x}{\tan B}\\
\mathbf{elif}\;x \leq 0.92:\\
\;\;\;\;\frac{1 - x}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-\tan B}\\
\end{array}
\end{array}
if x < -1.1499999999999999Initial program 99.6%
+-commutative99.6%
div-inv99.8%
sub-neg99.8%
clear-num99.4%
frac-sub88.9%
*-un-lft-identity88.9%
*-commutative88.9%
*-un-lft-identity88.9%
Applied egg-rr88.9%
associate-/r*99.5%
div-sub99.5%
*-inverses99.5%
Simplified99.5%
div-sub75.6%
div-inv75.6%
associate-/l/99.4%
*-commutative99.4%
clear-num99.4%
clear-num99.8%
Applied egg-rr99.8%
sub-neg99.8%
neg-mul-199.8%
distribute-rgt-in99.8%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in B around 0 99.6%
if -1.1499999999999999 < x < 0.92000000000000004Initial program 99.8%
Taylor expanded in x around inf 74.9%
Taylor expanded in x around 0 99.8%
+-commutative99.8%
*-lft-identity99.8%
*-lft-identity99.8%
rgt-mult-inverse99.7%
associate-*r/74.9%
mul-1-neg74.9%
associate-/l*74.9%
distribute-rgt-neg-in74.9%
mul-1-neg74.9%
distribute-lft-in74.9%
mul-1-neg74.9%
sub-neg74.9%
div-sub74.9%
associate-*r/99.7%
Simplified99.8%
Taylor expanded in B around 0 97.8%
mul-1-neg97.8%
unsub-neg97.8%
Simplified97.8%
if 0.92000000000000004 < x Initial program 99.7%
Taylor expanded in x around inf 97.1%
mul-1-neg97.1%
associate-/l*96.9%
distribute-lft-neg-in96.9%
Simplified96.9%
distribute-lft-neg-out96.9%
clear-num96.9%
tan-quot97.1%
div-inv97.2%
neg-sub097.2%
Applied egg-rr97.2%
neg-sub097.2%
distribute-frac-neg297.2%
Simplified97.2%
(FPCore (B x) :precision binary64 (if (or (<= x -1.55) (not (<= x 1.0))) (/ x (- (tan B))) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.55) || !(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.55d0)) .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.55) || !(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.55) 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.55) || !(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.55) || ~((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.55], 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.55 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{x}{-\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -1.55000000000000004 or 1 < x Initial program 99.6%
Taylor expanded in x around inf 98.4%
mul-1-neg98.4%
associate-/l*98.2%
distribute-lft-neg-in98.2%
Simplified98.2%
distribute-lft-neg-out98.2%
clear-num98.2%
tan-quot98.3%
div-inv98.5%
neg-sub098.5%
Applied egg-rr98.5%
neg-sub098.5%
distribute-frac-neg298.5%
Simplified98.5%
if -1.55000000000000004 < x < 1Initial program 99.8%
Taylor expanded in x around 0 96.1%
Final simplification97.4%
(FPCore (B x) :precision binary64 (if (<= B 0.0023) (/ (- 1.0 x) B) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if (B <= 0.0023) {
tmp = (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.0023d0) then
tmp = (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.0023) {
tmp = (1.0 - x) / B;
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if B <= 0.0023: tmp = (1.0 - x) / B else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if (B <= 0.0023) tmp = 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.0023) tmp = (1.0 - x) / B; else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[B, 0.0023], N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq 0.0023:\\
\;\;\;\;\frac{1 - x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if B < 0.0023Initial program 99.8%
Taylor expanded in B around 0 67.8%
if 0.0023 < B Initial program 99.6%
Taylor expanded in x around 0 45.3%
(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 48.9%
(FPCore (B x) :precision binary64 (/ x (- B)))
double code(double B, double x) {
return x / -B;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = x / -b
end function
public static double code(double B, double x) {
return x / -B;
}
def code(B, x): return x / -B
function code(B, x) return Float64(x / Float64(-B)) end
function tmp = code(B, x) tmp = x / -B; end
code[B_, x_] := N[(x / (-B)), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{-B}
\end{array}
Initial program 99.7%
Taylor expanded in x around inf 54.5%
mul-1-neg54.5%
associate-/l*54.4%
distribute-lft-neg-in54.4%
Simplified54.4%
Taylor expanded in B around 0 27.4%
associate-*r/27.4%
mul-1-neg27.4%
Simplified27.4%
Final simplification27.4%
(FPCore (B x) :precision binary64 (/ x B))
double code(double B, double x) {
return x / B;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = x / b
end function
public static double code(double B, double x) {
return x / B;
}
def code(B, x): return x / B
function code(B, x) return Float64(x / B) end
function tmp = code(B, x) tmp = x / B; end
code[B_, x_] := N[(x / B), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{B}
\end{array}
Initial program 99.7%
Taylor expanded in x around inf 54.5%
mul-1-neg54.5%
associate-/l*54.4%
distribute-lft-neg-in54.4%
Simplified54.4%
Taylor expanded in B around 0 27.4%
associate-*r/27.4%
mul-1-neg27.4%
Simplified27.4%
div-inv27.3%
add-sqr-sqrt14.3%
sqrt-unprod14.5%
sqr-neg14.5%
sqrt-unprod1.5%
add-sqr-sqrt2.5%
Applied egg-rr2.5%
associate-*r/2.5%
*-rgt-identity2.5%
Simplified2.5%
herbie shell --seed 2024113
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))