
(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 8 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 -0.000225) (/ (- 1.0 x) (tan B)) (if (<= x 0.00022) (/ 1.0 (sin B)) (- (/ 1.0 B) (* x (/ 1.0 (tan B)))))))
double code(double B, double x) {
double tmp;
if (x <= -0.000225) {
tmp = (1.0 - x) / tan(B);
} else if (x <= 0.00022) {
tmp = 1.0 / sin(B);
} else {
tmp = (1.0 / B) - (x * (1.0 / 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 <= (-0.000225d0)) then
tmp = (1.0d0 - x) / tan(b)
else if (x <= 0.00022d0) then
tmp = 1.0d0 / sin(b)
else
tmp = (1.0d0 / b) - (x * (1.0d0 / tan(b)))
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (x <= -0.000225) {
tmp = (1.0 - x) / Math.tan(B);
} else if (x <= 0.00022) {
tmp = 1.0 / Math.sin(B);
} else {
tmp = (1.0 / B) - (x * (1.0 / Math.tan(B)));
}
return tmp;
}
def code(B, x): tmp = 0 if x <= -0.000225: tmp = (1.0 - x) / math.tan(B) elif x <= 0.00022: tmp = 1.0 / math.sin(B) else: tmp = (1.0 / B) - (x * (1.0 / math.tan(B))) return tmp
function code(B, x) tmp = 0.0 if (x <= -0.000225) tmp = Float64(Float64(1.0 - x) / tan(B)); elseif (x <= 0.00022) tmp = Float64(1.0 / sin(B)); else tmp = Float64(Float64(1.0 / B) - Float64(x * Float64(1.0 / tan(B)))); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (x <= -0.000225) tmp = (1.0 - x) / tan(B); elseif (x <= 0.00022) tmp = 1.0 / sin(B); else tmp = (1.0 / B) - (x * (1.0 / tan(B))); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[x, -0.000225], N[(N[(1.0 - x), $MachinePrecision] / N[Tan[B], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.00022], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / B), $MachinePrecision] - N[(x * N[(1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.000225:\\
\;\;\;\;\frac{1 - x}{\tan B}\\
\mathbf{elif}\;x \leq 0.00022:\\
\;\;\;\;\frac{1}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B} - x \cdot \frac{1}{\tan B}\\
\end{array}
\end{array}
if x < -2.2499999999999999e-4Initial program 99.6%
+-commutative99.6%
div-inv99.7%
sub-neg99.7%
clear-num99.6%
frac-sub80.7%
*-un-lft-identity80.7%
*-commutative80.7%
*-un-lft-identity80.7%
Applied egg-rr80.7%
associate-/r*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around 0 97.0%
div-sub97.0%
associate-/r/97.0%
sub-neg97.0%
div-inv97.0%
clear-num97.0%
associate-*l/97.1%
*-un-lft-identity97.1%
distribute-neg-frac297.1%
Applied egg-rr97.1%
distribute-frac-neg297.1%
neg-mul-197.1%
distribute-rgt-in97.1%
associate-*l/97.1%
distribute-rgt-in97.1%
lft-mult-inverse97.1%
neg-mul-197.1%
sub-neg97.1%
Simplified97.1%
if -2.2499999999999999e-4 < x < 2.20000000000000008e-4Initial program 99.8%
Taylor expanded in x around 0 98.2%
if 2.20000000000000008e-4 < x Initial 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.7%
*-rgt-identity99.7%
tan-neg99.7%
distribute-neg-frac299.7%
distribute-neg-frac99.7%
remove-double-neg99.7%
Simplified99.7%
div-inv99.8%
*-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in B around 0 99.5%
Final simplification98.2%
(FPCore (B x) :precision binary64 (if (or (<= x -0.000225) (not (<= x 0.00022))) (/ (- 1.0 x) (tan B)) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -0.000225) || !(x <= 0.00022)) {
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 <= (-0.000225d0)) .or. (.not. (x <= 0.00022d0))) 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 <= -0.000225) || !(x <= 0.00022)) {
tmp = (1.0 - x) / Math.tan(B);
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -0.000225) or not (x <= 0.00022): 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 <= -0.000225) || !(x <= 0.00022)) 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 <= -0.000225) || ~((x <= 0.00022))) tmp = (1.0 - x) / tan(B); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -0.000225], N[Not[LessEqual[x, 0.00022]], $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 -0.000225 \lor \neg \left(x \leq 0.00022\right):\\
\;\;\;\;\frac{1 - x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -2.2499999999999999e-4 or 2.20000000000000008e-4 < x Initial program 99.7%
+-commutative99.7%
div-inv99.7%
sub-neg99.7%
clear-num99.6%
frac-sub85.2%
*-un-lft-identity85.2%
*-commutative85.2%
*-un-lft-identity85.2%
Applied egg-rr85.2%
associate-/r*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around 0 98.1%
div-sub86.5%
associate-/r/86.6%
sub-neg86.6%
div-inv84.5%
clear-num84.5%
associate-*l/84.6%
*-un-lft-identity84.6%
distribute-neg-frac284.6%
Applied egg-rr84.6%
distribute-frac-neg284.6%
neg-mul-184.6%
distribute-rgt-in98.2%
associate-*l/98.2%
distribute-rgt-in98.2%
lft-mult-inverse98.2%
neg-mul-198.2%
sub-neg98.2%
Simplified98.2%
if -2.2499999999999999e-4 < x < 2.20000000000000008e-4Initial program 99.8%
Taylor expanded in x around 0 98.2%
Final simplification98.2%
(FPCore (B x) :precision binary64 (if (or (<= x -1.2) (not (<= x 1.0))) (/ (- x) (tan B)) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.2) || !(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.2d0)) .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.2) || !(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.2) 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.2) || !(x <= 1.0)) tmp = Float64(Float64(-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.2) || ~((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.2], 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.2 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -1.19999999999999996 or 1 < x Initial program 99.7%
Taylor expanded in x around inf 97.3%
mul-1-neg97.3%
associate-*l/97.5%
*-commutative97.5%
Simplified97.5%
add-sqr-sqrt51.1%
sqrt-unprod27.4%
sqr-neg27.4%
sqrt-unprod0.3%
add-sqr-sqrt0.5%
neg-sub00.5%
sub-neg0.5%
add-sqr-sqrt0.3%
sqrt-unprod27.4%
sqr-neg27.4%
sqrt-unprod51.1%
add-sqr-sqrt97.5%
associate-*r/97.3%
clear-num97.2%
/-rgt-identity97.2%
div-inv97.2%
metadata-eval97.2%
Applied egg-rr97.5%
+-lft-identity97.5%
Simplified97.5%
if -1.19999999999999996 < x < 1Initial program 99.8%
Taylor expanded in x around 0 97.7%
Final simplification97.5%
(FPCore (B x) :precision binary64 (if (<= B 3.8) (/ (- 1.0 x) B) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if (B <= 3.8) {
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 <= 3.8d0) 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 <= 3.8) {
tmp = (1.0 - x) / B;
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if B <= 3.8: tmp = (1.0 - x) / B else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if (B <= 3.8) 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 <= 3.8) tmp = (1.0 - x) / B; else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[B, 3.8], 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 3.8:\\
\;\;\;\;\frac{1 - x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if B < 3.7999999999999998Initial program 99.8%
Taylor expanded in B around 0 66.4%
if 3.7999999999999998 < B Initial program 99.6%
Taylor expanded in x around 0 47.8%
(FPCore (B x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ x (- B)) (/ 1.0 B)))
double code(double B, double x) {
double tmp;
if ((x <= -1.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 <= (-1.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 <= -1.0) || !(x <= 1.0)) {
tmp = x / -B;
} else {
tmp = 1.0 / B;
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -1.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 <= -1.0) || !(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 <= -1.0) || ~((x <= 1.0))) 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, 1.0]], $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 1\right):\\
\;\;\;\;\frac{x}{-B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B}\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 99.7%
Taylor expanded in B around 0 57.1%
Taylor expanded in x around inf 56.4%
neg-mul-156.4%
distribute-neg-frac56.4%
Simplified56.4%
if -1 < x < 1Initial program 99.8%
Taylor expanded in B around 0 48.4%
Taylor expanded in x around 0 47.8%
Final simplification52.7%
(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 53.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%
Taylor expanded in B around 0 53.4%
Taylor expanded in x around 0 22.2%
herbie shell --seed 2024112
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))