
(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 11 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.6%
Applied rewrites99.7%
(FPCore (B x)
:precision binary64
(let* ((t_0 (/ 1.0 (sin B)))
(t_1 (- t_0 (* x (/ 1.0 (tan B)))))
(t_2 (- (/ 1.0 B) (/ x (tan B)))))
(if (<= t_1 -50000.0) t_2 (if (<= t_1 400.0) t_0 t_2))))
double code(double B, double x) {
double t_0 = 1.0 / sin(B);
double t_1 = t_0 - (x * (1.0 / tan(B)));
double t_2 = (1.0 / B) - (x / tan(B));
double tmp;
if (t_1 <= -50000.0) {
tmp = t_2;
} else if (t_1 <= 400.0) {
tmp = t_0;
} else {
tmp = t_2;
}
return tmp;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = 1.0d0 / sin(b)
t_1 = t_0 - (x * (1.0d0 / tan(b)))
t_2 = (1.0d0 / b) - (x / tan(b))
if (t_1 <= (-50000.0d0)) then
tmp = t_2
else if (t_1 <= 400.0d0) then
tmp = t_0
else
tmp = t_2
end if
code = tmp
end function
public static double code(double B, double x) {
double t_0 = 1.0 / Math.sin(B);
double t_1 = t_0 - (x * (1.0 / Math.tan(B)));
double t_2 = (1.0 / B) - (x / Math.tan(B));
double tmp;
if (t_1 <= -50000.0) {
tmp = t_2;
} else if (t_1 <= 400.0) {
tmp = t_0;
} else {
tmp = t_2;
}
return tmp;
}
def code(B, x): t_0 = 1.0 / math.sin(B) t_1 = t_0 - (x * (1.0 / math.tan(B))) t_2 = (1.0 / B) - (x / math.tan(B)) tmp = 0 if t_1 <= -50000.0: tmp = t_2 elif t_1 <= 400.0: tmp = t_0 else: tmp = t_2 return tmp
function code(B, x) t_0 = Float64(1.0 / sin(B)) t_1 = Float64(t_0 - Float64(x * Float64(1.0 / tan(B)))) t_2 = Float64(Float64(1.0 / B) - Float64(x / tan(B))) tmp = 0.0 if (t_1 <= -50000.0) tmp = t_2; elseif (t_1 <= 400.0) tmp = t_0; else tmp = t_2; end return tmp end
function tmp_2 = code(B, x) t_0 = 1.0 / sin(B); t_1 = t_0 - (x * (1.0 / tan(B))); t_2 = (1.0 / B) - (x / tan(B)); tmp = 0.0; if (t_1 <= -50000.0) tmp = t_2; elseif (t_1 <= 400.0) tmp = t_0; else tmp = t_2; end tmp_2 = tmp; end
code[B_, x_] := Block[{t$95$0 = N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 - N[(x * N[(1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(1.0 / B), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -50000.0], t$95$2, If[LessEqual[t$95$1, 400.0], t$95$0, t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\sin B}\\
t_1 := t\_0 - x \cdot \frac{1}{\tan B}\\
t_2 := \frac{1}{B} - \frac{x}{\tan B}\\
\mathbf{if}\;t\_1 \leq -50000:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 400:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (/.f64 #s(literal 1 binary64) (sin.f64 B))) < -5e4 or 400 < (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (/.f64 #s(literal 1 binary64) (sin.f64 B))) Initial program 99.7%
Applied rewrites99.8%
Taylor expanded in B around 0
lower-/.f6499.0
Applied rewrites99.0%
if -5e4 < (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (/.f64 #s(literal 1 binary64) (sin.f64 B))) < 400Initial program 99.5%
Taylor expanded in x around 0
lower-/.f64N/A
lower-sin.f6497.1
Applied rewrites97.1%
Final simplification98.5%
(FPCore (B x) :precision binary64 (/ (- 1.0 (* x (cos B))) (sin B)))
double code(double B, double x) {
return (1.0 - (x * cos(B))) / sin(B);
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = (1.0d0 - (x * cos(b))) / sin(b)
end function
public static double code(double B, double x) {
return (1.0 - (x * Math.cos(B))) / Math.sin(B);
}
def code(B, x): return (1.0 - (x * math.cos(B))) / math.sin(B)
function code(B, x) return Float64(Float64(1.0 - Float64(x * cos(B))) / sin(B)) end
function tmp = code(B, x) tmp = (1.0 - (x * cos(B))) / sin(B); end
code[B_, x_] := N[(N[(1.0 - N[(x * N[Cos[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - x \cdot \cos B}{\sin B}
\end{array}
Initial program 99.6%
Applied rewrites99.7%
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
div-invN/A
lift-tan.f64N/A
tan-quotN/A
lift-sin.f64N/A
lift-cos.f64N/A
clear-numN/A
associate-/l*N/A
lift-*.f64N/A
sub-divN/A
lower-/.f64N/A
lower--.f6499.7
Applied rewrites99.7%
(FPCore (B x) :precision binary64 (let* ((t_0 (- (/ 1.0 B) (/ x (tan B))))) (if (<= x -1.7) t_0 (if (<= x 0.065) (- (/ 1.0 (sin B)) (/ x B)) t_0))))
double code(double B, double x) {
double t_0 = (1.0 / B) - (x / tan(B));
double tmp;
if (x <= -1.7) {
tmp = t_0;
} else if (x <= 0.065) {
tmp = (1.0 / sin(B)) - (x / B);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (1.0d0 / b) - (x / tan(b))
if (x <= (-1.7d0)) then
tmp = t_0
else if (x <= 0.065d0) then
tmp = (1.0d0 / sin(b)) - (x / b)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double B, double x) {
double t_0 = (1.0 / B) - (x / Math.tan(B));
double tmp;
if (x <= -1.7) {
tmp = t_0;
} else if (x <= 0.065) {
tmp = (1.0 / Math.sin(B)) - (x / B);
} else {
tmp = t_0;
}
return tmp;
}
def code(B, x): t_0 = (1.0 / B) - (x / math.tan(B)) tmp = 0 if x <= -1.7: tmp = t_0 elif x <= 0.065: tmp = (1.0 / math.sin(B)) - (x / B) else: tmp = t_0 return tmp
function code(B, x) t_0 = Float64(Float64(1.0 / B) - Float64(x / tan(B))) tmp = 0.0 if (x <= -1.7) tmp = t_0; elseif (x <= 0.065) tmp = Float64(Float64(1.0 / sin(B)) - Float64(x / B)); else tmp = t_0; end return tmp end
function tmp_2 = code(B, x) t_0 = (1.0 / B) - (x / tan(B)); tmp = 0.0; if (x <= -1.7) tmp = t_0; elseif (x <= 0.065) tmp = (1.0 / sin(B)) - (x / B); else tmp = t_0; end tmp_2 = tmp; end
code[B_, x_] := Block[{t$95$0 = N[(N[(1.0 / B), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.7], t$95$0, If[LessEqual[x, 0.065], N[(N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision] - N[(x / B), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{B} - \frac{x}{\tan B}\\
\mathbf{if}\;x \leq -1.7:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.065:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.69999999999999996 or 0.065000000000000002 < x Initial program 99.5%
Applied rewrites99.7%
Taylor expanded in B around 0
lower-/.f6498.5
Applied rewrites98.5%
if -1.69999999999999996 < x < 0.065000000000000002Initial program 99.8%
Taylor expanded in B around 0
lower-/.f6498.5
Applied rewrites98.5%
Final simplification98.5%
(FPCore (B x)
:precision binary64
(if (<= B 490000.0)
(/
(fma
(* B B)
(fma
x
0.3333333333333333
(fma
(* B B)
(fma
B
(* B (fma x 0.0021164021164021165 0.00205026455026455))
(fma x 0.022222222222222223 0.019444444444444445))
0.16666666666666666))
(- 1.0 x))
B)
(/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if (B <= 490000.0) {
tmp = fma((B * B), fma(x, 0.3333333333333333, fma((B * B), fma(B, (B * fma(x, 0.0021164021164021165, 0.00205026455026455)), fma(x, 0.022222222222222223, 0.019444444444444445)), 0.16666666666666666)), (1.0 - x)) / B;
} else {
tmp = 1.0 / sin(B);
}
return tmp;
}
function code(B, x) tmp = 0.0 if (B <= 490000.0) tmp = Float64(fma(Float64(B * B), fma(x, 0.3333333333333333, fma(Float64(B * B), fma(B, Float64(B * fma(x, 0.0021164021164021165, 0.00205026455026455)), fma(x, 0.022222222222222223, 0.019444444444444445)), 0.16666666666666666)), Float64(1.0 - x)) / B); else tmp = Float64(1.0 / sin(B)); end return tmp end
code[B_, x_] := If[LessEqual[B, 490000.0], N[(N[(N[(B * B), $MachinePrecision] * N[(x * 0.3333333333333333 + N[(N[(B * B), $MachinePrecision] * N[(B * N[(B * N[(x * 0.0021164021164021165 + 0.00205026455026455), $MachinePrecision]), $MachinePrecision] + N[(x * 0.022222222222222223 + 0.019444444444444445), $MachinePrecision]), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision] + N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / B), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq 490000:\\
\;\;\;\;\frac{\mathsf{fma}\left(B \cdot B, \mathsf{fma}\left(x, 0.3333333333333333, \mathsf{fma}\left(B \cdot B, \mathsf{fma}\left(B, B \cdot \mathsf{fma}\left(x, 0.0021164021164021165, 0.00205026455026455\right), \mathsf{fma}\left(x, 0.022222222222222223, 0.019444444444444445\right)\right), 0.16666666666666666\right)\right), 1 - x\right)}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if B < 4.9e5Initial program 99.7%
Taylor expanded in B around 0
Applied rewrites65.2%
if 4.9e5 < B Initial program 99.4%
Taylor expanded in x around 0
lower-/.f64N/A
lower-sin.f6446.4
Applied rewrites46.4%
(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.6%
Applied rewrites99.7%
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
div-invN/A
lift-tan.f64N/A
tan-quotN/A
lift-sin.f64N/A
lift-cos.f64N/A
clear-numN/A
associate-/l*N/A
lift-*.f64N/A
sub-divN/A
lower-/.f64N/A
lower--.f6499.7
Applied rewrites99.7%
Taylor expanded in B around 0
lower--.f6474.1
Applied rewrites74.1%
(FPCore (B x) :precision binary64 (/ (- (fma (* B B) (fma x 0.3333333333333333 0.16666666666666666) 1.0) x) B))
double code(double B, double x) {
return (fma((B * B), fma(x, 0.3333333333333333, 0.16666666666666666), 1.0) - x) / B;
}
function code(B, x) return Float64(Float64(fma(Float64(B * B), fma(x, 0.3333333333333333, 0.16666666666666666), 1.0) - x) / B) end
code[B_, x_] := N[(N[(N[(N[(B * B), $MachinePrecision] * N[(x * 0.3333333333333333 + 0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision] - x), $MachinePrecision] / B), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(B \cdot B, \mathsf{fma}\left(x, 0.3333333333333333, 0.16666666666666666\right), 1\right) - x}{B}
\end{array}
Initial program 99.6%
Taylor expanded in B around 0
lower-/.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6446.9
Applied rewrites46.9%
(FPCore (B x) :precision binary64 (/ (/ (fma B (- x) B) B) B))
double code(double B, double x) {
return (fma(B, -x, B) / B) / B;
}
function code(B, x) return Float64(Float64(fma(B, Float64(-x), B) / B) / B) end
code[B_, x_] := N[(N[(N[(B * (-x) + B), $MachinePrecision] / B), $MachinePrecision] / B), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\mathsf{fma}\left(B, -x, B\right)}{B}}{B}
\end{array}
Initial program 99.6%
Taylor expanded in B around 0
lower-/.f64N/A
lower--.f6446.7
Applied rewrites46.7%
Applied rewrites32.3%
Applied rewrites46.8%
(FPCore (B x) :precision binary64 (let* ((t_0 (/ (- x) B))) (if (<= x -3.5e-9) t_0 (if (<= x 1.0) (/ 1.0 B) t_0))))
double code(double B, double x) {
double t_0 = -x / B;
double tmp;
if (x <= -3.5e-9) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = 1.0 / B;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = -x / b
if (x <= (-3.5d-9)) then
tmp = t_0
else if (x <= 1.0d0) then
tmp = 1.0d0 / b
else
tmp = t_0
end if
code = tmp
end function
public static double code(double B, double x) {
double t_0 = -x / B;
double tmp;
if (x <= -3.5e-9) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = 1.0 / B;
} else {
tmp = t_0;
}
return tmp;
}
def code(B, x): t_0 = -x / B tmp = 0 if x <= -3.5e-9: tmp = t_0 elif x <= 1.0: tmp = 1.0 / B else: tmp = t_0 return tmp
function code(B, x) t_0 = Float64(Float64(-x) / B) tmp = 0.0 if (x <= -3.5e-9) tmp = t_0; elseif (x <= 1.0) tmp = Float64(1.0 / B); else tmp = t_0; end return tmp end
function tmp_2 = code(B, x) t_0 = -x / B; tmp = 0.0; if (x <= -3.5e-9) tmp = t_0; elseif (x <= 1.0) tmp = 1.0 / B; else tmp = t_0; end tmp_2 = tmp; end
code[B_, x_] := Block[{t$95$0 = N[((-x) / B), $MachinePrecision]}, If[LessEqual[x, -3.5e-9], t$95$0, If[LessEqual[x, 1.0], N[(1.0 / B), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{B}\\
\mathbf{if}\;x \leq -3.5 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\frac{1}{B}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.4999999999999999e-9 or 1 < x Initial program 99.5%
Taylor expanded in B around 0
lower-/.f64N/A
lower--.f6442.1
Applied rewrites42.1%
Taylor expanded in x around inf
Applied rewrites41.9%
if -3.4999999999999999e-9 < x < 1Initial program 99.8%
Taylor expanded in B around 0
lower-/.f64N/A
lower--.f6450.9
Applied rewrites50.9%
Taylor expanded in x around 0
Applied rewrites49.8%
(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.6%
Taylor expanded in B around 0
lower-/.f64N/A
lower--.f6446.7
Applied rewrites46.7%
(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.6%
Taylor expanded in B around 0
lower-/.f64N/A
lower--.f6446.7
Applied rewrites46.7%
Taylor expanded in x around 0
Applied rewrites27.1%
herbie shell --seed 2024223
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))