
(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 (<= x -0.11)
(- (/ 1.0 B) (/ x (tan B)))
(if (<= x 1.05)
(/ (- 1.0 x) (sin B))
(/ (+ (/ 1.0 x) -1.0) (/ (tan B) x)))))
double code(double B, double x) {
double tmp;
if (x <= -0.11) {
tmp = (1.0 / B) - (x / tan(B));
} else if (x <= 1.05) {
tmp = (1.0 - x) / sin(B);
} else {
tmp = ((1.0 / x) + -1.0) / (tan(B) / x);
}
return tmp;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-0.11d0)) then
tmp = (1.0d0 / b) - (x / tan(b))
else if (x <= 1.05d0) then
tmp = (1.0d0 - x) / sin(b)
else
tmp = ((1.0d0 / x) + (-1.0d0)) / (tan(b) / x)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (x <= -0.11) {
tmp = (1.0 / B) - (x / Math.tan(B));
} else if (x <= 1.05) {
tmp = (1.0 - x) / Math.sin(B);
} else {
tmp = ((1.0 / x) + -1.0) / (Math.tan(B) / x);
}
return tmp;
}
def code(B, x): tmp = 0 if x <= -0.11: tmp = (1.0 / B) - (x / math.tan(B)) elif x <= 1.05: tmp = (1.0 - x) / math.sin(B) else: tmp = ((1.0 / x) + -1.0) / (math.tan(B) / x) return tmp
function code(B, x) tmp = 0.0 if (x <= -0.11) tmp = Float64(Float64(1.0 / B) - Float64(x / tan(B))); elseif (x <= 1.05) tmp = Float64(Float64(1.0 - x) / sin(B)); else tmp = Float64(Float64(Float64(1.0 / x) + -1.0) / Float64(tan(B) / x)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (x <= -0.11) tmp = (1.0 / B) - (x / tan(B)); elseif (x <= 1.05) tmp = (1.0 - x) / sin(B); else tmp = ((1.0 / x) + -1.0) / (tan(B) / x); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[x, -0.11], N[(N[(1.0 / B), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.05], N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / x), $MachinePrecision] + -1.0), $MachinePrecision] / N[(N[Tan[B], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.11:\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\mathbf{elif}\;x \leq 1.05:\\
\;\;\;\;\frac{1 - x}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x} + -1}{\frac{\tan B}{x}}\\
\end{array}
\end{array}
if x < -0.110000000000000001Initial 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%
Taylor expanded in B around 0 99.8%
if -0.110000000000000001 < x < 1.05000000000000004Initial program 99.8%
+-commutative99.8%
div-inv99.8%
sub-neg99.8%
clear-num99.8%
frac-sub89.6%
*-un-lft-identity89.6%
*-commutative89.6%
*-un-lft-identity89.6%
Applied egg-rr89.6%
associate-/r*99.5%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around inf 99.6%
associate-*r*99.7%
sub-neg99.7%
associate-/r*99.6%
metadata-eval99.6%
Simplified99.6%
+-commutative99.6%
distribute-rgt-in99.6%
associate-*r*99.6%
neg-mul-199.6%
associate-/r*99.7%
lft-mult-inverse99.8%
Applied egg-rr99.8%
Taylor expanded in B around 0 98.5%
mul-1-neg98.5%
sub-neg98.5%
Simplified98.5%
if 1.05000000000000004 < x Initial program 99.6%
+-commutative99.6%
div-inv99.8%
sub-neg99.8%
clear-num99.6%
frac-sub87.8%
*-un-lft-identity87.8%
*-commutative87.8%
*-un-lft-identity87.8%
Applied egg-rr87.8%
associate-/r*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around 0 97.4%
Final simplification98.5%
(FPCore (B x) :precision binary64 (if (or (<= x -0.11) (not (<= x 15.5))) (- (/ 1.0 B) (/ x (tan B))) (/ (- 1.0 x) (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -0.11) || !(x <= 15.5)) {
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 <= (-0.11d0)) .or. (.not. (x <= 15.5d0))) 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 <= -0.11) || !(x <= 15.5)) {
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 <= -0.11) or not (x <= 15.5): 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 <= -0.11) || !(x <= 15.5)) 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 <= -0.11) || ~((x <= 15.5))) 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, -0.11], N[Not[LessEqual[x, 15.5]], $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 -0.11 \lor \neg \left(x \leq 15.5\right):\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - x}{\sin B}\\
\end{array}
\end{array}
if x < -0.110000000000000001 or 15.5 < x Initial program 99.6%
distribute-lft-neg-in99.6%
+-commutative99.6%
cancel-sign-sub-inv99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Taylor expanded in B around 0 99.0%
if -0.110000000000000001 < x < 15.5Initial program 99.8%
+-commutative99.8%
div-inv99.8%
sub-neg99.8%
clear-num99.8%
frac-sub89.6%
*-un-lft-identity89.6%
*-commutative89.6%
*-un-lft-identity89.6%
Applied egg-rr89.6%
associate-/r*99.5%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around inf 99.6%
associate-*r*99.7%
sub-neg99.7%
associate-/r*99.6%
metadata-eval99.6%
Simplified99.6%
+-commutative99.6%
distribute-rgt-in99.6%
associate-*r*99.6%
neg-mul-199.6%
associate-/r*99.7%
lft-mult-inverse99.8%
Applied egg-rr99.8%
Taylor expanded in B around 0 98.0%
mul-1-neg98.0%
sub-neg98.0%
Simplified98.0%
Final simplification98.5%
(FPCore (B x)
:precision binary64
(if (<= B 0.15)
(-
(+ (/ 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.15) {
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.15d0) 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.15) {
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.15: 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.15) tmp = Float64(Float64(Float64(1.0 / B) + Float64(B * Float64(0.16666666666666666 + Float64(x * 0.3333333333333333)))) - Float64(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.15) 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.15], N[(N[(N[(1.0 / B), $MachinePrecision] + N[(B * N[(0.16666666666666666 + N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x / B), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq 0.15:\\
\;\;\;\;\left(\frac{1}{B} + B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right)\right) - \frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if B < 0.149999999999999994Initial program 99.8%
Taylor expanded in B around 0 67.3%
if 0.149999999999999994 < B Initial program 99.5%
Taylor expanded in x around 0 47.0%
Final simplification62.5%
(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%
div-inv99.8%
sub-neg99.8%
clear-num99.7%
frac-sub89.2%
*-un-lft-identity89.2%
*-commutative89.2%
*-un-lft-identity89.2%
Applied egg-rr89.2%
associate-/r*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around inf 99.6%
associate-*r*99.6%
sub-neg99.6%
associate-/r*99.6%
metadata-eval99.6%
Simplified99.6%
+-commutative99.6%
distribute-rgt-in99.6%
associate-*r*99.6%
neg-mul-199.6%
associate-/r*99.6%
lft-mult-inverse99.7%
Applied egg-rr99.7%
Taylor expanded in B around 0 75.8%
mul-1-neg75.8%
sub-neg75.8%
Simplified75.8%
Final simplification75.8%
(FPCore (B x) :precision binary64 (if (or (<= x -1.0) (not (<= x 6.5e-9))) (/ (- x) B) (/ 1.0 B)))
double code(double B, double x) {
double tmp;
if ((x <= -1.0) || !(x <= 6.5e-9)) {
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 <= 6.5d-9))) 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 <= 6.5e-9)) {
tmp = -x / B;
} else {
tmp = 1.0 / B;
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -1.0) or not (x <= 6.5e-9): tmp = -x / B else: tmp = 1.0 / B return tmp
function code(B, x) tmp = 0.0 if ((x <= -1.0) || !(x <= 6.5e-9)) 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 <= 6.5e-9))) 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, 6.5e-9]], $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 6.5 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{-x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B}\\
\end{array}
\end{array}
if x < -1 or 6.5000000000000003e-9 < x Initial program 99.6%
Taylor expanded in B around 0 46.8%
Taylor expanded in x around inf 44.6%
neg-mul-144.6%
distribute-neg-frac44.6%
Simplified44.6%
if -1 < x < 6.5000000000000003e-9Initial program 99.8%
Taylor expanded in B around 0 56.7%
Taylor expanded in x around 0 55.5%
Final simplification50.1%
(FPCore (B x) :precision binary64 (+ (* 0.3333333333333333 (* B x)) (/ (- 1.0 x) B)))
double code(double B, double x) {
return (0.3333333333333333 * (B * x)) + ((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)) + ((1.0d0 - x) / b)
end function
public static double code(double B, double x) {
return (0.3333333333333333 * (B * x)) + ((1.0 - x) / B);
}
def code(B, x): return (0.3333333333333333 * (B * x)) + ((1.0 - x) / B)
function code(B, x) return Float64(Float64(0.3333333333333333 * Float64(B * x)) + Float64(Float64(1.0 - x) / B)) end
function tmp = code(B, x) tmp = (0.3333333333333333 * (B * x)) + ((1.0 - x) / B); end
code[B_, x_] := N[(N[(0.3333333333333333 * N[(B * x), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.3333333333333333 \cdot \left(B \cdot x\right) + \frac{1 - x}{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%
Taylor expanded in B around 0 77.2%
Taylor expanded in B around 0 52.6%
associate--l+52.6%
*-commutative52.6%
div-sub52.6%
Simplified52.6%
Final simplification52.6%
(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 51.8%
Final simplification51.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%
Taylor expanded in B around 0 51.8%
Taylor expanded in x around 0 29.5%
Final simplification29.5%
herbie shell --seed 2024041
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))