
(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.3%
distribute-lft-neg-in99.3%
+-commutative99.3%
cancel-sign-sub-inv99.3%
*-commutative99.3%
*-commutative99.3%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (B x) :precision binary64 (if (or (<= x -1.25e-5) (not (<= x 2.3e-5))) (* (/ x (tan B)) (+ (/ 1.0 x) -1.0)) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.25e-5) || !(x <= 2.3e-5)) {
tmp = (x / tan(B)) * ((1.0 / x) + -1.0);
} 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.25d-5)) .or. (.not. (x <= 2.3d-5))) then
tmp = (x / tan(b)) * ((1.0d0 / x) + (-1.0d0))
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.25e-5) || !(x <= 2.3e-5)) {
tmp = (x / Math.tan(B)) * ((1.0 / x) + -1.0);
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -1.25e-5) or not (x <= 2.3e-5): tmp = (x / math.tan(B)) * ((1.0 / x) + -1.0) else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -1.25e-5) || !(x <= 2.3e-5)) tmp = Float64(Float64(x / tan(B)) * Float64(Float64(1.0 / x) + -1.0)); else tmp = Float64(1.0 / sin(B)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if ((x <= -1.25e-5) || ~((x <= 2.3e-5))) tmp = (x / tan(B)) * ((1.0 / x) + -1.0); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -1.25e-5], N[Not[LessEqual[x, 2.3e-5]], $MachinePrecision]], N[(N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / x), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{-5} \lor \neg \left(x \leq 2.3 \cdot 10^{-5}\right):\\
\;\;\;\;\frac{x}{\tan B} \cdot \left(\frac{1}{x} + -1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -1.25000000000000006e-5 or 2.3e-5 < x Initial program 99.6%
+-commutative99.6%
div-inv99.7%
sub-neg99.7%
clear-num99.5%
frac-sub90.3%
*-un-lft-identity90.3%
*-commutative90.3%
*-un-lft-identity90.3%
Applied egg-rr90.3%
associate-/r*99.5%
div-sub99.5%
*-inverses99.5%
Simplified99.5%
Taylor expanded in B around inf 99.5%
associate-/r*99.5%
Simplified99.5%
clear-num99.5%
associate-/r/99.5%
clear-num99.7%
sub-neg99.7%
associate-/l/99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in B around 0 98.0%
if -1.25000000000000006e-5 < x < 2.3e-5Initial program 99.0%
Taylor expanded in x around 0 98.4%
Final simplification98.2%
(FPCore (B x) :precision binary64 (if (or (<= x -8e-5) (not (<= x 0.00054))) (- (/ 1.0 B) (/ x (tan B))) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -8e-5) || !(x <= 0.00054)) {
tmp = (1.0 / B) - (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 <= (-8d-5)) .or. (.not. (x <= 0.00054d0))) then
tmp = (1.0d0 / b) - (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 <= -8e-5) || !(x <= 0.00054)) {
tmp = (1.0 / B) - (x / Math.tan(B));
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -8e-5) or not (x <= 0.00054): tmp = (1.0 / B) - (x / math.tan(B)) else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -8e-5) || !(x <= 0.00054)) tmp = Float64(Float64(1.0 / B) - 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 <= -8e-5) || ~((x <= 0.00054))) tmp = (1.0 / B) - (x / tan(B)); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -8e-5], N[Not[LessEqual[x, 0.00054]], $MachinePrecision]], N[(N[(1.0 / B), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-5} \lor \neg \left(x \leq 0.00054\right):\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -8.00000000000000065e-5 or 5.40000000000000007e-4 < x Initial program 99.6%
distribute-lft-neg-in99.6%
+-commutative99.6%
cancel-sign-sub-inv99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
Taylor expanded in B around 0 97.9%
if -8.00000000000000065e-5 < x < 5.40000000000000007e-4Initial program 99.0%
Taylor expanded in x around 0 98.4%
Final simplification98.2%
(FPCore (B x) :precision binary64 (if (<= B 0.043) (+ (* B (+ 0.16666666666666666 (* x 0.3333333333333333))) (/ (- 1.0 x) B)) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if (B <= 0.043) {
tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((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.043d0) then
tmp = (b * (0.16666666666666666d0 + (x * 0.3333333333333333d0))) + ((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.043) {
tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B);
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if B <= 0.043: tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B) else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if (B <= 0.043) tmp = Float64(Float64(B * Float64(0.16666666666666666 + Float64(x * 0.3333333333333333))) + 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.043) tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[B, 0.043], N[(N[(B * N[(0.16666666666666666 + N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq 0.043:\\
\;\;\;\;B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right) + \frac{1 - x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if B < 0.042999999999999997Initial program 99.2%
Taylor expanded in B around 0 52.6%
associate--l+52.6%
*-commutative52.6%
div-sub52.6%
Simplified52.6%
if 0.042999999999999997 < B Initial program 99.5%
Taylor expanded in x around 0 50.1%
Final simplification52.0%
(FPCore (B x) :precision binary64 (+ (/ (- 1.0 x) B) (* 0.3333333333333333 (* B x))))
double code(double B, double x) {
return ((1.0 - x) / B) + (0.3333333333333333 * (B * x));
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = ((1.0d0 - x) / b) + (0.3333333333333333d0 * (b * x))
end function
public static double code(double B, double x) {
return ((1.0 - x) / B) + (0.3333333333333333 * (B * x));
}
def code(B, x): return ((1.0 - x) / B) + (0.3333333333333333 * (B * x))
function code(B, x) return Float64(Float64(Float64(1.0 - x) / B) + Float64(0.3333333333333333 * Float64(B * x))) end
function tmp = code(B, x) tmp = ((1.0 - x) / B) + (0.3333333333333333 * (B * x)); end
code[B_, x_] := N[(N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision] + N[(0.3333333333333333 * N[(B * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - x}{B} + 0.3333333333333333 \cdot \left(B \cdot x\right)
\end{array}
Initial program 99.3%
Taylor expanded in B around 0 67.4%
Taylor expanded in B around 0 40.4%
associate--l+40.4%
*-commutative40.4%
div-sub40.4%
Simplified40.4%
Final simplification40.4%
(FPCore (B x) :precision binary64 (if (or (<= x -4e+24) (not (<= x 1.9e+29))) (/ (- x) B) (/ 1.0 B)))
double code(double B, double x) {
double tmp;
if ((x <= -4e+24) || !(x <= 1.9e+29)) {
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 <= (-4d+24)) .or. (.not. (x <= 1.9d+29))) 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 <= -4e+24) || !(x <= 1.9e+29)) {
tmp = -x / B;
} else {
tmp = 1.0 / B;
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -4e+24) or not (x <= 1.9e+29): tmp = -x / B else: tmp = 1.0 / B return tmp
function code(B, x) tmp = 0.0 if ((x <= -4e+24) || !(x <= 1.9e+29)) 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 <= -4e+24) || ~((x <= 1.9e+29))) tmp = -x / B; else tmp = 1.0 / B; end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -4e+24], N[Not[LessEqual[x, 1.9e+29]], $MachinePrecision]], N[((-x) / B), $MachinePrecision], N[(1.0 / B), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+24} \lor \neg \left(x \leq 1.9 \cdot 10^{+29}\right):\\
\;\;\;\;\frac{-x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B}\\
\end{array}
\end{array}
if x < -3.9999999999999999e24 or 1.89999999999999985e29 < x Initial program 99.6%
Taylor expanded in B around 0 43.1%
Taylor expanded in x around inf 43.1%
neg-mul-143.1%
distribute-neg-frac43.1%
Simplified43.1%
if -3.9999999999999999e24 < x < 1.89999999999999985e29Initial program 99.0%
Taylor expanded in B around 0 37.3%
Taylor expanded in x around 0 36.8%
Final simplification39.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.3%
Taylor expanded in B around 0 39.9%
Final simplification39.9%
(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.3%
Taylor expanded in B around 0 39.9%
Taylor expanded in x around 0 21.5%
Final simplification21.5%
herbie shell --seed 2023322
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))