
(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 12 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 (+ (/ (- x) (tan B)) (pow (sin B) -1.0)))
double code(double B, double x) {
return (-x / tan(B)) + pow(sin(B), -1.0);
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = (-x / tan(b)) + (sin(b) ** (-1.0d0))
end function
public static double code(double B, double x) {
return (-x / Math.tan(B)) + Math.pow(Math.sin(B), -1.0);
}
def code(B, x): return (-x / math.tan(B)) + math.pow(math.sin(B), -1.0)
function code(B, x) return Float64(Float64(Float64(-x) / tan(B)) + (sin(B) ^ -1.0)) end
function tmp = code(B, x) tmp = (-x / tan(B)) + (sin(B) ^ -1.0); end
code[B_, x_] := N[(N[((-x) / N[Tan[B], $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-x}{\tan B} + {\sin B}^{-1}
\end{array}
Initial program 99.7%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lower-/.f6499.7
Applied rewrites99.7%
Final simplification99.7%
(FPCore (B x) :precision binary64 (if (or (<= x -380000000.0) (not (<= x 3500000000.0))) (/ (* (cos B) (- x)) (sin B)) (+ (- (/ x B)) (pow (sin B) -1.0))))
double code(double B, double x) {
double tmp;
if ((x <= -380000000.0) || !(x <= 3500000000.0)) {
tmp = (cos(B) * -x) / sin(B);
} else {
tmp = -(x / B) + pow(sin(B), -1.0);
}
return tmp;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-380000000.0d0)) .or. (.not. (x <= 3500000000.0d0))) then
tmp = (cos(b) * -x) / sin(b)
else
tmp = -(x / b) + (sin(b) ** (-1.0d0))
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if ((x <= -380000000.0) || !(x <= 3500000000.0)) {
tmp = (Math.cos(B) * -x) / Math.sin(B);
} else {
tmp = -(x / B) + Math.pow(Math.sin(B), -1.0);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -380000000.0) or not (x <= 3500000000.0): tmp = (math.cos(B) * -x) / math.sin(B) else: tmp = -(x / B) + math.pow(math.sin(B), -1.0) return tmp
function code(B, x) tmp = 0.0 if ((x <= -380000000.0) || !(x <= 3500000000.0)) tmp = Float64(Float64(cos(B) * Float64(-x)) / sin(B)); else tmp = Float64(Float64(-Float64(x / B)) + (sin(B) ^ -1.0)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if ((x <= -380000000.0) || ~((x <= 3500000000.0))) tmp = (cos(B) * -x) / sin(B); else tmp = -(x / B) + (sin(B) ^ -1.0); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -380000000.0], N[Not[LessEqual[x, 3500000000.0]], $MachinePrecision]], N[(N[(N[Cos[B], $MachinePrecision] * (-x)), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[((-N[(x / B), $MachinePrecision]) + N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -380000000 \lor \neg \left(x \leq 3500000000\right):\\
\;\;\;\;\frac{\cos B \cdot \left(-x\right)}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;\left(-\frac{x}{B}\right) + {\sin B}^{-1}\\
\end{array}
\end{array}
if x < -3.8e8 or 3.5e9 < x Initial program 99.6%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lower-/.f6499.7
Applied rewrites99.7%
Applied rewrites99.7%
Taylor expanded in x around inf
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
mul-1-negN/A
lower-neg.f6499.1
Applied rewrites99.1%
if -3.8e8 < x < 3.5e9Initial program 99.7%
Taylor expanded in B around 0
lower-/.f6498.4
Applied rewrites98.4%
Final simplification98.7%
(FPCore (B x) :precision binary64 (/ (fma (cos B) (- x) 1.0) (sin B)))
double code(double B, double x) {
return fma(cos(B), -x, 1.0) / sin(B);
}
function code(B, x) return Float64(fma(cos(B), Float64(-x), 1.0) / sin(B)) end
code[B_, x_] := N[(N[(N[Cos[B], $MachinePrecision] * (-x) + 1.0), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(\cos B, -x, 1\right)}{\sin B}
\end{array}
Initial program 99.7%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lower-/.f6499.7
Applied rewrites99.7%
Applied rewrites99.7%
Taylor expanded in B around inf
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
(FPCore (B x) :precision binary64 (if (or (<= x -1.5e+120) (not (<= x 2.65e+19))) (+ (/ (- x) (tan B)) (/ (fma (* 0.16666666666666666 B) B 1.0) B)) (/ (- 1.0 x) (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.5e+120) || !(x <= 2.65e+19)) {
tmp = (-x / tan(B)) + (fma((0.16666666666666666 * B), B, 1.0) / B);
} else {
tmp = (1.0 - x) / sin(B);
}
return tmp;
}
function code(B, x) tmp = 0.0 if ((x <= -1.5e+120) || !(x <= 2.65e+19)) tmp = Float64(Float64(Float64(-x) / tan(B)) + Float64(fma(Float64(0.16666666666666666 * B), B, 1.0) / B)); else tmp = Float64(Float64(1.0 - x) / sin(B)); end return tmp end
code[B_, x_] := If[Or[LessEqual[x, -1.5e+120], N[Not[LessEqual[x, 2.65e+19]], $MachinePrecision]], N[(N[((-x) / N[Tan[B], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(0.16666666666666666 * B), $MachinePrecision] * B + 1.0), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+120} \lor \neg \left(x \leq 2.65 \cdot 10^{+19}\right):\\
\;\;\;\;\frac{-x}{\tan B} + \frac{\mathsf{fma}\left(0.16666666666666666 \cdot B, B, 1\right)}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - x}{\sin B}\\
\end{array}
\end{array}
if x < -1.5e120 or 2.65e19 < x Initial program 99.6%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lower-/.f6499.7
Applied rewrites99.7%
Taylor expanded in B around 0
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6473.4
Applied rewrites73.4%
if -1.5e120 < x < 2.65e19Initial program 99.7%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lower-/.f6499.7
Applied rewrites99.7%
Applied rewrites99.7%
Taylor expanded in B around 0
mul-1-negN/A
sub-negN/A
lower--.f6493.4
Applied rewrites93.4%
Final simplification86.5%
(FPCore (B x) :precision binary64 (+ (fma (* 0.3333333333333333 B) x (/ (- x) B)) (pow B -1.0)))
double code(double B, double x) {
return fma((0.3333333333333333 * B), x, (-x / B)) + pow(B, -1.0);
}
function code(B, x) return Float64(fma(Float64(0.3333333333333333 * B), x, Float64(Float64(-x) / B)) + (B ^ -1.0)) end
code[B_, x_] := N[(N[(N[(0.3333333333333333 * B), $MachinePrecision] * x + N[((-x) / B), $MachinePrecision]), $MachinePrecision] + N[Power[B, -1.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.3333333333333333 \cdot B, x, \frac{-x}{B}\right) + {B}^{-1}
\end{array}
Initial program 99.7%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lower-/.f6499.7
Applied rewrites99.7%
Taylor expanded in B around 0
div-subN/A
sub-negN/A
associate-*r*N/A
associate-/l*N/A
mul-1-negN/A
distribute-rgt-outN/A
*-rgt-identityN/A
associate-*r/N/A
rem-exp-logN/A
exp-negN/A
distribute-rgt-outN/A
mul-1-negN/A
Applied rewrites66.7%
Taylor expanded in B around 0
lower-/.f6451.0
Applied rewrites51.0%
Final simplification51.0%
(FPCore (B x) :precision binary64 (+ (* (fma 0.3333333333333333 B (/ -1.0 B)) x) (pow B -1.0)))
double code(double B, double x) {
return (fma(0.3333333333333333, B, (-1.0 / B)) * x) + pow(B, -1.0);
}
function code(B, x) return Float64(Float64(fma(0.3333333333333333, B, Float64(-1.0 / B)) * x) + (B ^ -1.0)) end
code[B_, x_] := N[(N[(N[(0.3333333333333333 * B + N[(-1.0 / B), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] + N[Power[B, -1.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.3333333333333333, B, \frac{-1}{B}\right) \cdot x + {B}^{-1}
\end{array}
Initial program 99.7%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lower-/.f6499.7
Applied rewrites99.7%
Taylor expanded in B around 0
div-subN/A
sub-negN/A
associate-*r*N/A
associate-/l*N/A
mul-1-negN/A
distribute-rgt-outN/A
*-rgt-identityN/A
associate-*r/N/A
rem-exp-logN/A
exp-negN/A
distribute-rgt-outN/A
mul-1-negN/A
Applied rewrites66.7%
Taylor expanded in B around 0
lower-/.f6451.0
Applied rewrites51.0%
Taylor expanded in x around 0
Applied rewrites51.0%
Final simplification51.0%
(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%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lower-/.f6499.7
Applied rewrites99.7%
Applied rewrites99.7%
Taylor expanded in B around 0
mul-1-negN/A
sub-negN/A
lower--.f6480.4
Applied rewrites80.4%
(FPCore (B x) :precision binary64 (/ (fma (* (* 0.3333333333333333 x) B) B (- 1.0 x)) B))
double code(double B, double x) {
return fma(((0.3333333333333333 * x) * B), B, (1.0 - x)) / B;
}
function code(B, x) return Float64(fma(Float64(Float64(0.3333333333333333 * x) * B), B, Float64(1.0 - x)) / B) end
code[B_, x_] := N[(N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] * B), $MachinePrecision] * B + N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / B), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(\left(0.3333333333333333 \cdot x\right) \cdot B, B, 1 - x\right)}{B}
\end{array}
Initial program 99.7%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
clear-numN/A
frac-subN/A
lower-/.f64N/A
*-rgt-identityN/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6487.9
Applied rewrites87.9%
Taylor expanded in B around 0
lower-/.f64N/A
Applied rewrites50.9%
Taylor expanded in x around inf
Applied rewrites50.9%
Final simplification50.9%
(FPCore (B x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.35e-6))) (/ (- x) B) (/ 1.0 B)))
double code(double B, double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.35e-6)) {
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.35d-6))) 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.35e-6)) {
tmp = -x / B;
} else {
tmp = 1.0 / B;
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -1.0) or not (x <= 1.35e-6): tmp = -x / B else: tmp = 1.0 / B return tmp
function code(B, x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.35e-6)) 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 <= 1.35e-6))) 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.35e-6]], $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.35 \cdot 10^{-6}\right):\\
\;\;\;\;\frac{-x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B}\\
\end{array}
\end{array}
if x < -1 or 1.34999999999999999e-6 < x Initial program 99.6%
Taylor expanded in B around 0
lower-/.f64N/A
lower--.f6451.4
Applied rewrites51.4%
Taylor expanded in x around inf
Applied rewrites50.6%
if -1 < x < 1.34999999999999999e-6Initial program 99.7%
Taylor expanded in B around 0
lower-/.f64N/A
lower--.f6449.8
Applied rewrites49.8%
Taylor expanded in x around 0
Applied rewrites48.1%
Final simplification49.2%
(FPCore (B x) :precision binary64 (/ (fma (* 0.16666666666666666 B) B (- 1.0 x)) B))
double code(double B, double x) {
return fma((0.16666666666666666 * B), B, (1.0 - x)) / B;
}
function code(B, x) return Float64(fma(Float64(0.16666666666666666 * B), B, Float64(1.0 - x)) / B) end
code[B_, x_] := N[(N[(N[(0.16666666666666666 * B), $MachinePrecision] * B + N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / B), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(0.16666666666666666 \cdot B, B, 1 - x\right)}{B}
\end{array}
Initial program 99.7%
lift-/.f64N/A
inv-powN/A
pow-to-expN/A
*-commutativeN/A
log-powN/A
inv-powN/A
lift-/.f64N/A
lower-exp.f64N/A
lift-/.f64N/A
log-recN/A
lower-neg.f64N/A
lower-log.f6447.7
Applied rewrites47.7%
Taylor expanded in B around 0
Applied rewrites50.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
lower-/.f64N/A
lower--.f6450.5
Applied rewrites50.5%
Final simplification50.5%
(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
lower-/.f64N/A
lower--.f6450.5
Applied rewrites50.5%
Taylor expanded in x around 0
Applied rewrites27.7%
Final simplification27.7%
herbie shell --seed 2024296
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))