
(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 (+ (* (/ (- x) (sin B)) (cos B)) (pow (sin B) -1.0)))
double code(double B, double x) {
return ((-x / sin(B)) * cos(B)) + pow(sin(B), -1.0);
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = ((-x / sin(b)) * cos(b)) + (sin(b) ** (-1.0d0))
end function
public static double code(double B, double x) {
return ((-x / Math.sin(B)) * Math.cos(B)) + Math.pow(Math.sin(B), -1.0);
}
def code(B, x): return ((-x / math.sin(B)) * math.cos(B)) + math.pow(math.sin(B), -1.0)
function code(B, x) return Float64(Float64(Float64(Float64(-x) / sin(B)) * cos(B)) + (sin(B) ^ -1.0)) end
function tmp = code(B, x) tmp = ((-x / sin(B)) * cos(B)) + (sin(B) ^ -1.0); end
code[B_, x_] := N[(N[(N[((-x) / N[Sin[B], $MachinePrecision]), $MachinePrecision] * N[Cos[B], $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-x}{\sin B} \cdot \cos B + {\sin B}^{-1}
\end{array}
Initial program 99.6%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lift-tan.f64N/A
tan-quotN/A
lift-sin.f64N/A
associate-/r/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (B x)
:precision binary64
(let* ((t_0 (+ (* x (/ -1.0 (tan B))) (pow (sin B) -1.0))))
(if (or (<= t_0 -10.0) (not (<= t_0 1000000.0)))
(+ (/ (- x) (tan B)) (pow B -1.0))
(/ (- 1.0 x) (sin B)))))
double code(double B, double x) {
double t_0 = (x * (-1.0 / tan(B))) + pow(sin(B), -1.0);
double tmp;
if ((t_0 <= -10.0) || !(t_0 <= 1000000.0)) {
tmp = (-x / tan(B)) + pow(B, -1.0);
} 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) :: t_0
real(8) :: tmp
t_0 = (x * ((-1.0d0) / tan(b))) + (sin(b) ** (-1.0d0))
if ((t_0 <= (-10.0d0)) .or. (.not. (t_0 <= 1000000.0d0))) then
tmp = (-x / tan(b)) + (b ** (-1.0d0))
else
tmp = (1.0d0 - x) / sin(b)
end if
code = tmp
end function
public static double code(double B, double x) {
double t_0 = (x * (-1.0 / Math.tan(B))) + Math.pow(Math.sin(B), -1.0);
double tmp;
if ((t_0 <= -10.0) || !(t_0 <= 1000000.0)) {
tmp = (-x / Math.tan(B)) + Math.pow(B, -1.0);
} else {
tmp = (1.0 - x) / Math.sin(B);
}
return tmp;
}
def code(B, x): t_0 = (x * (-1.0 / math.tan(B))) + math.pow(math.sin(B), -1.0) tmp = 0 if (t_0 <= -10.0) or not (t_0 <= 1000000.0): tmp = (-x / math.tan(B)) + math.pow(B, -1.0) else: tmp = (1.0 - x) / math.sin(B) return tmp
function code(B, x) t_0 = Float64(Float64(x * Float64(-1.0 / tan(B))) + (sin(B) ^ -1.0)) tmp = 0.0 if ((t_0 <= -10.0) || !(t_0 <= 1000000.0)) tmp = Float64(Float64(Float64(-x) / tan(B)) + (B ^ -1.0)); else tmp = Float64(Float64(1.0 - x) / sin(B)); end return tmp end
function tmp_2 = code(B, x) t_0 = (x * (-1.0 / tan(B))) + (sin(B) ^ -1.0); tmp = 0.0; if ((t_0 <= -10.0) || ~((t_0 <= 1000000.0))) tmp = (-x / tan(B)) + (B ^ -1.0); else tmp = (1.0 - x) / sin(B); end tmp_2 = tmp; end
code[B_, x_] := Block[{t$95$0 = N[(N[(x * N[(-1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -10.0], N[Not[LessEqual[t$95$0, 1000000.0]], $MachinePrecision]], N[(N[((-x) / N[Tan[B], $MachinePrecision]), $MachinePrecision] + N[Power[B, -1.0], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \frac{-1}{\tan B} + {\sin B}^{-1}\\
\mathbf{if}\;t\_0 \leq -10 \lor \neg \left(t\_0 \leq 1000000\right):\\
\;\;\;\;\frac{-x}{\tan B} + {B}^{-1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - x}{\sin B}\\
\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))) < -10 or 1e6 < (+.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%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lift-tan.f64N/A
tan-quotN/A
lift-sin.f64N/A
associate-/r/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6499.8
Applied rewrites99.8%
lift-neg.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
distribute-neg-fracN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
associate-*r/N/A
clear-numN/A
lift-sin.f64N/A
lift-cos.f64N/A
tan-quotN/A
lift-tan.f64N/A
un-div-invN/A
lower-/.f6499.8
Applied rewrites99.8%
Taylor expanded in B around 0
lower-/.f6499.1
Applied rewrites99.1%
if -10 < (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (/.f64 #s(literal 1 binary64) (sin.f64 B))) < 1e6Initial program 99.6%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lift-tan.f64N/A
tan-quotN/A
lift-sin.f64N/A
associate-/r/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6499.6
Applied rewrites99.6%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
Taylor expanded in B around 0
lower--.f6496.1
Applied rewrites96.1%
Final simplification98.3%
(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.6%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lower-/.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (B x) :precision binary64 (/ (- 1.0 (* (cos B) x)) (sin B)))
double code(double B, double x) {
return (1.0 - (cos(B) * x)) / sin(B);
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = (1.0d0 - (cos(b) * x)) / sin(b)
end function
public static double code(double B, double x) {
return (1.0 - (Math.cos(B) * x)) / Math.sin(B);
}
def code(B, x): return (1.0 - (math.cos(B) * x)) / math.sin(B)
function code(B, x) return Float64(Float64(1.0 - Float64(cos(B) * x)) / sin(B)) end
function tmp = code(B, x) tmp = (1.0 - (cos(B) * x)) / sin(B); end
code[B_, x_] := N[(N[(1.0 - N[(N[Cos[B], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - \cos B \cdot x}{\sin B}
\end{array}
Initial program 99.6%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lift-tan.f64N/A
tan-quotN/A
lift-sin.f64N/A
associate-/r/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6499.8
Applied rewrites99.8%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
(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%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lift-tan.f64N/A
tan-quotN/A
lift-sin.f64N/A
associate-/r/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6499.8
Applied rewrites99.8%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
Taylor expanded in B around 0
lower--.f6478.3
Applied rewrites78.3%
(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.6%
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.1
Applied rewrites53.1%
(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--.f6452.8
Applied rewrites52.8%
(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%
Applied rewrites44.0%
Taylor expanded in B around 0
lower-/.f64N/A
+-commutativeN/A
distribute-lft-inN/A
rgt-mult-inverseN/A
*-rgt-identityN/A
lower-+.f6424.3
Applied rewrites24.3%
Taylor expanded in x around 0
Applied rewrites24.9%
(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(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.6%
Applied rewrites44.0%
Taylor expanded in B around 0
lower-/.f64N/A
+-commutativeN/A
distribute-lft-inN/A
rgt-mult-inverseN/A
*-rgt-identityN/A
lower-+.f6424.3
Applied rewrites24.3%
Taylor expanded in x around 0
Applied rewrites24.9%
Taylor expanded in x around inf
Applied rewrites2.3%
herbie shell --seed 2024320
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))