
(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.8%
distribute-lft-neg-in99.8%
+-commutative99.8%
cancel-sign-sub-inv99.8%
*-commutative99.8%
*-commutative99.8%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (B x) :precision binary64 (if (<= x -2.05e+21) (/ (- x) (tan B)) (if (<= x 445000000.0) (/ (- 1.0 x) (sin B)) (- (/ 1.0 B) (/ x (tan B))))))
double code(double B, double x) {
double tmp;
if (x <= -2.05e+21) {
tmp = -x / tan(B);
} else if (x <= 445000000.0) {
tmp = (1.0 - x) / sin(B);
} else {
tmp = (1.0 / B) - (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 <= (-2.05d+21)) then
tmp = -x / tan(b)
else if (x <= 445000000.0d0) then
tmp = (1.0d0 - x) / sin(b)
else
tmp = (1.0d0 / b) - (x / tan(b))
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (x <= -2.05e+21) {
tmp = -x / Math.tan(B);
} else if (x <= 445000000.0) {
tmp = (1.0 - x) / Math.sin(B);
} else {
tmp = (1.0 / B) - (x / Math.tan(B));
}
return tmp;
}
def code(B, x): tmp = 0 if x <= -2.05e+21: tmp = -x / math.tan(B) elif x <= 445000000.0: tmp = (1.0 - x) / math.sin(B) else: tmp = (1.0 / B) - (x / math.tan(B)) return tmp
function code(B, x) tmp = 0.0 if (x <= -2.05e+21) tmp = Float64(Float64(-x) / tan(B)); elseif (x <= 445000000.0) tmp = Float64(Float64(1.0 - x) / sin(B)); else tmp = Float64(Float64(1.0 / B) - Float64(x / tan(B))); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (x <= -2.05e+21) tmp = -x / tan(B); elseif (x <= 445000000.0) tmp = (1.0 - x) / sin(B); else tmp = (1.0 / B) - (x / tan(B)); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[x, -2.05e+21], N[((-x) / N[Tan[B], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 445000000.0], N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / B), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{+21}:\\
\;\;\;\;\frac{-x}{\tan B}\\
\mathbf{elif}\;x \leq 445000000:\\
\;\;\;\;\frac{1 - x}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\end{array}
\end{array}
if x < -2.05e21Initial program 99.6%
Taylor expanded in x around inf 99.7%
associate-/l*99.8%
tan-quot99.8%
expm1-log1p-u40.5%
expm1-udef40.5%
Applied egg-rr40.5%
expm1-def40.5%
expm1-log1p99.8%
Simplified99.8%
if -2.05e21 < x < 4.45e8Initial program 99.9%
distribute-lft-neg-in99.9%
+-commutative99.9%
cancel-sign-sub-inv99.9%
*-commutative99.9%
*-commutative99.9%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
inv-pow99.8%
add-sqr-sqrt54.7%
unpow-prod-down54.5%
Applied egg-rr54.5%
pow-sqr54.7%
metadata-eval54.7%
Simplified54.7%
Taylor expanded in B around inf 99.8%
div-sub99.9%
Simplified99.9%
Taylor expanded in B around 0 98.6%
if 4.45e8 < 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 99.3%
Final simplification99.0%
(FPCore (B x) :precision binary64 (if (or (<= x -2.05e+21) (not (<= x 520000000.0))) (/ (- x) (tan B)) (/ (- 1.0 x) (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -2.05e+21) || !(x <= 520000000.0)) {
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 <= (-2.05d+21)) .or. (.not. (x <= 520000000.0d0))) 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 <= -2.05e+21) || !(x <= 520000000.0)) {
tmp = -x / Math.tan(B);
} else {
tmp = (1.0 - x) / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -2.05e+21) or not (x <= 520000000.0): tmp = -x / math.tan(B) else: tmp = (1.0 - x) / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -2.05e+21) || !(x <= 520000000.0)) tmp = Float64(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.05e+21) || ~((x <= 520000000.0))) tmp = -x / tan(B); else tmp = (1.0 - x) / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -2.05e+21], N[Not[LessEqual[x, 520000000.0]], $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 -2.05 \cdot 10^{+21} \lor \neg \left(x \leq 520000000\right):\\
\;\;\;\;\frac{-x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - x}{\sin B}\\
\end{array}
\end{array}
if x < -2.05e21 or 5.2e8 < x Initial program 99.6%
Taylor expanded in x around inf 99.5%
associate-/l*99.4%
tan-quot99.5%
expm1-log1p-u51.7%
expm1-udef51.7%
Applied egg-rr51.7%
expm1-def51.7%
expm1-log1p99.5%
Simplified99.5%
if -2.05e21 < x < 5.2e8Initial program 99.9%
distribute-lft-neg-in99.9%
+-commutative99.9%
cancel-sign-sub-inv99.9%
*-commutative99.9%
*-commutative99.9%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
inv-pow99.8%
add-sqr-sqrt54.7%
unpow-prod-down54.5%
Applied egg-rr54.5%
pow-sqr54.7%
metadata-eval54.7%
Simplified54.7%
Taylor expanded in B around inf 99.8%
div-sub99.9%
Simplified99.9%
Taylor expanded in B around 0 98.6%
Final simplification99.0%
(FPCore (B x) :precision binary64 (if (or (<= x -1.35) (not (<= x 1.0))) (/ (- x) (tan B)) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.35) || !(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.35d0)) .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.35) || !(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.35) 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.35) || !(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.35) || ~((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.35], 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.35 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -1.3500000000000001 or 1 < x Initial program 99.6%
Taylor expanded in x around inf 97.8%
associate-/l*97.8%
tan-quot97.9%
expm1-log1p-u52.0%
expm1-udef52.0%
Applied egg-rr52.0%
expm1-def52.0%
expm1-log1p97.9%
Simplified97.9%
if -1.3500000000000001 < x < 1Initial program 99.9%
Taylor expanded in x around 0 98.4%
Final simplification98.1%
(FPCore (B x) :precision binary64 (if (<= B 6.8e-13) (/ (- 1.0 x) B) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if (B <= 6.8e-13) {
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 <= 6.8d-13) 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 <= 6.8e-13) {
tmp = (1.0 - x) / B;
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if B <= 6.8e-13: tmp = (1.0 - x) / B else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if (B <= 6.8e-13) 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 <= 6.8e-13) tmp = (1.0 - x) / B; else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[B, 6.8e-13], 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 6.8 \cdot 10^{-13}:\\
\;\;\;\;\frac{1 - x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if B < 6.80000000000000031e-13Initial program 99.8%
Taylor expanded in B around 0 66.6%
if 6.80000000000000031e-13 < B Initial program 99.6%
Taylor expanded in x around 0 55.1%
Final simplification63.6%
(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.8%
distribute-lft-neg-in99.8%
+-commutative99.8%
cancel-sign-sub-inv99.8%
*-commutative99.8%
*-commutative99.8%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Taylor expanded in B around 0 72.5%
Taylor expanded in B around 0 50.9%
associate--l+50.9%
div-sub50.9%
Simplified50.9%
Final simplification50.9%
(FPCore (B x) :precision binary64 (+ (/ (- 1.0 x) B) (* B 0.16666666666666666)))
double code(double B, double x) {
return ((1.0 - x) / B) + (B * 0.16666666666666666);
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = ((1.0d0 - x) / b) + (b * 0.16666666666666666d0)
end function
public static double code(double B, double x) {
return ((1.0 - x) / B) + (B * 0.16666666666666666);
}
def code(B, x): return ((1.0 - x) / B) + (B * 0.16666666666666666)
function code(B, x) return Float64(Float64(Float64(1.0 - x) / B) + Float64(B * 0.16666666666666666)) end
function tmp = code(B, x) tmp = ((1.0 - x) / B) + (B * 0.16666666666666666); end
code[B_, x_] := N[(N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision] + N[(B * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - x}{B} + B \cdot 0.16666666666666666
\end{array}
Initial program 99.8%
Taylor expanded in B around 0 50.6%
associate--l+50.6%
*-commutative50.6%
div-sub50.7%
Simplified50.7%
Taylor expanded in x around 0 50.7%
*-commutative50.7%
Simplified50.7%
Final simplification50.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.8%
Taylor expanded in B around 0 50.6%
Final simplification50.6%
(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(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.8%
Taylor expanded in B around 0 50.6%
Taylor expanded in x around inf 24.3%
neg-mul-124.3%
distribute-neg-frac24.3%
Simplified24.3%
Final simplification24.3%
herbie shell --seed 2023338
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))