
(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 10 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.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (B x)
:precision binary64
(let* ((t_0 (pow (sin B) -1.0)) (t_1 (+ (* x (/ -1.0 (tan B))) t_0)))
(if (or (<= t_1 -2e+143) (not (<= t_1 1e+48)))
(+ (/ (- x) (tan B)) (/ (fma 0.16666666666666666 (* B B) 1.0) B))
(+ (- (/ x B)) t_0))))
double code(double B, double x) {
double t_0 = pow(sin(B), -1.0);
double t_1 = (x * (-1.0 / tan(B))) + t_0;
double tmp;
if ((t_1 <= -2e+143) || !(t_1 <= 1e+48)) {
tmp = (-x / tan(B)) + (fma(0.16666666666666666, (B * B), 1.0) / B);
} else {
tmp = -(x / B) + t_0;
}
return tmp;
}
function code(B, x) t_0 = sin(B) ^ -1.0 t_1 = Float64(Float64(x * Float64(-1.0 / tan(B))) + t_0) tmp = 0.0 if ((t_1 <= -2e+143) || !(t_1 <= 1e+48)) tmp = Float64(Float64(Float64(-x) / tan(B)) + Float64(fma(0.16666666666666666, Float64(B * B), 1.0) / B)); else tmp = Float64(Float64(-Float64(x / B)) + t_0); end return tmp end
code[B_, x_] := Block[{t$95$0 = N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * N[(-1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -2e+143], N[Not[LessEqual[t$95$1, 1e+48]], $MachinePrecision]], N[(N[((-x) / N[Tan[B], $MachinePrecision]), $MachinePrecision] + N[(N[(0.16666666666666666 * N[(B * B), $MachinePrecision] + 1.0), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision], N[((-N[(x / B), $MachinePrecision]) + t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin B}^{-1}\\
t_1 := x \cdot \frac{-1}{\tan B} + t\_0\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+143} \lor \neg \left(t\_1 \leq 10^{+48}\right):\\
\;\;\;\;\frac{-x}{\tan B} + \frac{\mathsf{fma}\left(0.16666666666666666, B \cdot B, 1\right)}{B}\\
\mathbf{else}:\\
\;\;\;\;\left(-\frac{x}{B}\right) + t\_0\\
\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))) < -2e143 or 1.00000000000000004e48 < (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (/.f64 #s(literal 1 binary64) (sin.f64 B))) Initial program 99.8%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lower-/.f6499.9
Applied rewrites99.9%
Taylor expanded in B around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6485.7
Applied rewrites85.7%
if -2e143 < (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (/.f64 #s(literal 1 binary64) (sin.f64 B))) < 1.00000000000000004e48Initial program 99.7%
Taylor expanded in B around 0
lower-/.f6481.7
Applied rewrites81.7%
Final simplification84.2%
(FPCore (B x) :precision binary64 (* (/ -1.0 (sin B)) (fma (cos B) x -1.0)))
double code(double B, double x) {
return (-1.0 / sin(B)) * fma(cos(B), x, -1.0);
}
function code(B, x) return Float64(Float64(-1.0 / sin(B)) * fma(cos(B), x, -1.0)) end
code[B_, x_] := N[(N[(-1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[B], $MachinePrecision] * x + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\sin B} \cdot \mathsf{fma}\left(\cos B, x, -1\right)
\end{array}
Initial program 99.7%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lower-/.f6499.8
Applied rewrites99.8%
Taylor expanded in B around inf
rgt-mult-inverseN/A
associate-*r/N/A
associate-/r*N/A
associate-/l*N/A
distribute-lft-out--N/A
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
neg-sub0N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
sub-negN/A
distribute-rgt-inN/A
Applied rewrites99.6%
(FPCore (B x) :precision binary64 (if (<= B 0.075) (/ (- (fma (fma 0.3333333333333333 x 0.16666666666666666) (* B B) 1.0) x) B) (+ (* (* 0.3333333333333333 B) x) (pow (sin B) -1.0))))
double code(double B, double x) {
double tmp;
if (B <= 0.075) {
tmp = (fma(fma(0.3333333333333333, x, 0.16666666666666666), (B * B), 1.0) - x) / B;
} else {
tmp = ((0.3333333333333333 * B) * x) + pow(sin(B), -1.0);
}
return tmp;
}
function code(B, x) tmp = 0.0 if (B <= 0.075) tmp = Float64(Float64(fma(fma(0.3333333333333333, x, 0.16666666666666666), Float64(B * B), 1.0) - x) / B); else tmp = Float64(Float64(Float64(0.3333333333333333 * B) * x) + (sin(B) ^ -1.0)); end return tmp end
code[B_, x_] := If[LessEqual[B, 0.075], N[(N[(N[(N[(0.3333333333333333 * x + 0.16666666666666666), $MachinePrecision] * N[(B * B), $MachinePrecision] + 1.0), $MachinePrecision] - x), $MachinePrecision] / B), $MachinePrecision], N[(N[(N[(0.3333333333333333 * B), $MachinePrecision] * x), $MachinePrecision] + N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq 0.075:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, x, 0.16666666666666666\right), B \cdot B, 1\right) - x}{B}\\
\mathbf{else}:\\
\;\;\;\;\left(0.3333333333333333 \cdot B\right) \cdot x + {\sin B}^{-1}\\
\end{array}
\end{array}
if B < 0.0749999999999999972Initial program 99.8%
Taylor expanded in B around 0
lower-/.f64N/A
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6469.7
Applied rewrites69.7%
if 0.0749999999999999972 < B Initial program 99.6%
Taylor expanded in B around 0
div-subN/A
sub-negN/A
mul-1-negN/A
associate-/l*N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
mul-1-negN/A
distribute-neg-fracN/A
lower-/.f64N/A
lower-neg.f6430.8
Applied rewrites30.8%
Taylor expanded in B around inf
Applied rewrites30.8%
Final simplification60.3%
(FPCore (B x) :precision binary64 (+ (- (/ x B)) (pow (sin B) -1.0)))
double code(double B, double x) {
return -(x / B) + pow(sin(B), -1.0);
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = -(x / b) + (sin(b) ** (-1.0d0))
end function
public static double code(double B, double x) {
return -(x / B) + Math.pow(Math.sin(B), -1.0);
}
def code(B, x): return -(x / B) + math.pow(math.sin(B), -1.0)
function code(B, x) return Float64(Float64(-Float64(x / B)) + (sin(B) ^ -1.0)) end
function tmp = code(B, x) tmp = -(x / B) + (sin(B) ^ -1.0); end
code[B_, x_] := N[((-N[(x / B), $MachinePrecision]) + N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-\frac{x}{B}\right) + {\sin B}^{-1}
\end{array}
Initial program 99.7%
Taylor expanded in B around 0
lower-/.f6475.2
Applied rewrites75.2%
Final simplification75.2%
(FPCore (B x) :precision binary64 (+ (fma (* B x) 0.3333333333333333 (/ (- x) B)) (pow B -1.0)))
double code(double B, double x) {
return fma((B * x), 0.3333333333333333, (-x / B)) + pow(B, -1.0);
}
function code(B, x) return Float64(fma(Float64(B * x), 0.3333333333333333, Float64(Float64(-x) / B)) + (B ^ -1.0)) end
code[B_, x_] := N[(N[(N[(B * x), $MachinePrecision] * 0.3333333333333333 + N[((-x) / B), $MachinePrecision]), $MachinePrecision] + N[Power[B, -1.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(B \cdot x, 0.3333333333333333, \frac{-x}{B}\right) + {B}^{-1}
\end{array}
Initial program 99.7%
Taylor expanded in B around 0
div-subN/A
sub-negN/A
mul-1-negN/A
associate-/l*N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
mul-1-negN/A
distribute-neg-fracN/A
lower-/.f64N/A
lower-neg.f6462.9
Applied rewrites62.9%
Taylor expanded in B around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6453.7
Applied rewrites53.7%
Taylor expanded in B around 0
Applied rewrites54.2%
Final simplification54.2%
(FPCore (B x) :precision binary64 (/ (- (fma (fma 0.3333333333333333 x 0.16666666666666666) (* B B) 1.0) x) B))
double code(double B, double x) {
return (fma(fma(0.3333333333333333, x, 0.16666666666666666), (B * B), 1.0) - x) / B;
}
function code(B, x) return Float64(Float64(fma(fma(0.3333333333333333, x, 0.16666666666666666), Float64(B * B), 1.0) - x) / B) end
code[B_, x_] := N[(N[(N[(N[(0.3333333333333333 * x + 0.16666666666666666), $MachinePrecision] * N[(B * B), $MachinePrecision] + 1.0), $MachinePrecision] - x), $MachinePrecision] / B), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, x, 0.16666666666666666\right), B \cdot B, 1\right) - x}{B}
\end{array}
Initial program 99.7%
Taylor expanded in B around 0
lower-/.f64N/A
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6453.8
Applied rewrites53.8%
Final simplification53.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(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.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.6%
Taylor expanded in B around 0
lower-/.f64N/A
lower--.f6453.8
Applied rewrites53.8%
Taylor expanded in x around inf
Applied rewrites53.1%
if -1 < x < 1Initial program 99.8%
Taylor expanded in B around 0
lower-/.f64N/A
lower--.f6453.4
Applied rewrites53.4%
Taylor expanded in x around 0
Applied rewrites51.4%
Final simplification52.3%
(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--.f6453.6
Applied rewrites53.6%
Final simplification53.6%
(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--.f6453.6
Applied rewrites53.6%
Taylor expanded in x around 0
Applied rewrites26.1%
Final simplification26.1%
herbie shell --seed 2024302
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))