
(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.7%
+-commutative99.7%
unsub-neg99.7%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (B x) :precision binary64 (if (or (<= x -3600.0) (not (<= x 6e-14))) (/ (- 1.0 x) (tan B)) (/ (- 1.0 x) (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -3600.0) || !(x <= 6e-14)) {
tmp = (1.0 - 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 <= (-3600.0d0)) .or. (.not. (x <= 6d-14))) then
tmp = (1.0d0 - 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 <= -3600.0) || !(x <= 6e-14)) {
tmp = (1.0 - x) / Math.tan(B);
} else {
tmp = (1.0 - x) / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -3600.0) or not (x <= 6e-14): tmp = (1.0 - x) / math.tan(B) else: tmp = (1.0 - x) / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -3600.0) || !(x <= 6e-14)) tmp = Float64(Float64(1.0 - 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 <= -3600.0) || ~((x <= 6e-14))) tmp = (1.0 - x) / tan(B); else tmp = (1.0 - x) / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -3600.0], N[Not[LessEqual[x, 6e-14]], $MachinePrecision]], N[(N[(1.0 - x), $MachinePrecision] / 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 -3600 \lor \neg \left(x \leq 6 \cdot 10^{-14}\right):\\
\;\;\;\;\frac{1 - x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - x}{\sin B}\\
\end{array}
\end{array}
if x < -3600 or 5.9999999999999997e-14 < x Initial program 99.6%
distribute-lft-neg-in99.6%
Simplified99.6%
+-commutative99.6%
cancel-sign-sub-inv99.6%
div-inv99.8%
clear-num99.6%
frac-sub88.7%
*-un-lft-identity88.7%
*-commutative88.7%
*-un-lft-identity88.7%
Applied egg-rr88.7%
associate-/r*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around 0 98.4%
div-sub89.9%
Applied egg-rr89.9%
div-sub98.4%
sub-neg98.4%
metadata-eval98.4%
associate-/l*98.5%
*-commutative98.5%
distribute-rgt-in98.5%
neg-mul-198.5%
unsub-neg98.5%
lft-mult-inverse98.5%
Simplified98.5%
if -3600 < x < 5.9999999999999997e-14Initial program 99.7%
+-commutative99.7%
unsub-neg99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
tan-quot99.7%
associate-/r/99.7%
Applied egg-rr99.7%
Taylor expanded in B around inf 99.7%
*-commutative99.7%
div-sub99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in B around 0 98.7%
Final simplification98.6%
(FPCore (B x) :precision binary64 (if (<= x -3600.0) (- (/ 1.0 B) (/ x (tan B))) (if (<= x 6e-14) (/ (- 1.0 x) (sin B)) (/ (- 1.0 x) (tan B)))))
double code(double B, double x) {
double tmp;
if (x <= -3600.0) {
tmp = (1.0 / B) - (x / tan(B));
} else if (x <= 6e-14) {
tmp = (1.0 - x) / sin(B);
} else {
tmp = (1.0 - 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 <= (-3600.0d0)) then
tmp = (1.0d0 / b) - (x / tan(b))
else if (x <= 6d-14) then
tmp = (1.0d0 - x) / sin(b)
else
tmp = (1.0d0 - x) / tan(b)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (x <= -3600.0) {
tmp = (1.0 / B) - (x / Math.tan(B));
} else if (x <= 6e-14) {
tmp = (1.0 - x) / Math.sin(B);
} else {
tmp = (1.0 - x) / Math.tan(B);
}
return tmp;
}
def code(B, x): tmp = 0 if x <= -3600.0: tmp = (1.0 / B) - (x / math.tan(B)) elif x <= 6e-14: tmp = (1.0 - x) / math.sin(B) else: tmp = (1.0 - x) / math.tan(B) return tmp
function code(B, x) tmp = 0.0 if (x <= -3600.0) tmp = Float64(Float64(1.0 / B) - Float64(x / tan(B))); elseif (x <= 6e-14) tmp = Float64(Float64(1.0 - x) / sin(B)); else tmp = Float64(Float64(1.0 - x) / tan(B)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (x <= -3600.0) tmp = (1.0 / B) - (x / tan(B)); elseif (x <= 6e-14) tmp = (1.0 - x) / sin(B); else tmp = (1.0 - x) / tan(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[x, -3600.0], N[(N[(1.0 / B), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 6e-14], N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] / N[Tan[B], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3600:\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-14}:\\
\;\;\;\;\frac{1 - x}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - x}{\tan B}\\
\end{array}
\end{array}
if x < -3600Initial program 99.6%
+-commutative99.6%
unsub-neg99.6%
associate-*r/99.9%
*-rgt-identity99.9%
Simplified99.9%
Taylor expanded in B around 0 99.0%
if -3600 < x < 5.9999999999999997e-14Initial program 99.7%
+-commutative99.7%
unsub-neg99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
tan-quot99.7%
associate-/r/99.7%
Applied egg-rr99.7%
Taylor expanded in B around inf 99.7%
*-commutative99.7%
div-sub99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in B around 0 98.7%
if 5.9999999999999997e-14 < x Initial program 99.6%
distribute-lft-neg-in99.6%
Simplified99.6%
+-commutative99.6%
cancel-sign-sub-inv99.6%
div-inv99.7%
clear-num99.5%
frac-sub91.1%
*-un-lft-identity91.1%
*-commutative91.1%
*-un-lft-identity91.1%
Applied egg-rr91.1%
associate-/r*99.4%
div-sub99.5%
*-inverses99.5%
Simplified99.5%
Taylor expanded in B around 0 97.8%
div-sub80.9%
Applied egg-rr80.9%
div-sub97.8%
sub-neg97.8%
metadata-eval97.8%
associate-/l*98.1%
*-commutative98.1%
distribute-rgt-in98.1%
neg-mul-198.1%
unsub-neg98.1%
lft-mult-inverse98.1%
Simplified98.1%
Final simplification98.6%
(FPCore (B x)
:precision binary64
(let* ((t_0 (/ (- 1.0 x) B)))
(if (<= x -0.115)
t_0
(if (<= x 6e-14)
(/ 1.0 (sin B))
(+ t_0 (* 0.3333333333333333 (* B x)))))))
double code(double B, double x) {
double t_0 = (1.0 - x) / B;
double tmp;
if (x <= -0.115) {
tmp = t_0;
} else if (x <= 6e-14) {
tmp = 1.0 / sin(B);
} else {
tmp = t_0 + (0.3333333333333333 * (B * x));
}
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 - x) / b
if (x <= (-0.115d0)) then
tmp = t_0
else if (x <= 6d-14) then
tmp = 1.0d0 / sin(b)
else
tmp = t_0 + (0.3333333333333333d0 * (b * x))
end if
code = tmp
end function
public static double code(double B, double x) {
double t_0 = (1.0 - x) / B;
double tmp;
if (x <= -0.115) {
tmp = t_0;
} else if (x <= 6e-14) {
tmp = 1.0 / Math.sin(B);
} else {
tmp = t_0 + (0.3333333333333333 * (B * x));
}
return tmp;
}
def code(B, x): t_0 = (1.0 - x) / B tmp = 0 if x <= -0.115: tmp = t_0 elif x <= 6e-14: tmp = 1.0 / math.sin(B) else: tmp = t_0 + (0.3333333333333333 * (B * x)) return tmp
function code(B, x) t_0 = Float64(Float64(1.0 - x) / B) tmp = 0.0 if (x <= -0.115) tmp = t_0; elseif (x <= 6e-14) tmp = Float64(1.0 / sin(B)); else tmp = Float64(t_0 + Float64(0.3333333333333333 * Float64(B * x))); end return tmp end
function tmp_2 = code(B, x) t_0 = (1.0 - x) / B; tmp = 0.0; if (x <= -0.115) tmp = t_0; elseif (x <= 6e-14) tmp = 1.0 / sin(B); else tmp = t_0 + (0.3333333333333333 * (B * x)); end tmp_2 = tmp; end
code[B_, x_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision]}, If[LessEqual[x, -0.115], t$95$0, If[LessEqual[x, 6e-14], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[(0.3333333333333333 * N[(B * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1 - x}{B}\\
\mathbf{if}\;x \leq -0.115:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-14}:\\
\;\;\;\;\frac{1}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;t_0 + 0.3333333333333333 \cdot \left(B \cdot x\right)\\
\end{array}
\end{array}
if x < -0.115000000000000005Initial program 99.6%
distribute-lft-neg-in99.6%
Simplified99.6%
Taylor expanded in B around 0 60.5%
mul-1-neg60.5%
sub-neg60.5%
Simplified60.5%
if -0.115000000000000005 < x < 5.9999999999999997e-14Initial program 99.8%
distribute-lft-neg-in99.8%
Simplified99.8%
Taylor expanded in x around 0 98.5%
if 5.9999999999999997e-14 < x Initial program 99.6%
distribute-lft-neg-in99.6%
Simplified99.6%
Taylor expanded in B around 0 97.9%
Taylor expanded in B around 0 52.2%
mul-1-neg52.2%
+-commutative52.2%
associate-+l+52.2%
sub-neg52.2%
div-sub52.2%
Simplified52.2%
Final simplification76.9%
(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%
+-commutative99.7%
unsub-neg99.7%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
tan-quot99.7%
associate-/r/99.8%
Applied egg-rr99.8%
Taylor expanded in B around inf 99.8%
*-commutative99.8%
div-sub99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in B around 0 78.9%
Final simplification78.9%
(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.7%
distribute-lft-neg-in99.7%
Simplified99.7%
Taylor expanded in B around 0 72.4%
Taylor expanded in B around 0 50.9%
mul-1-neg50.9%
+-commutative50.9%
associate-+l+50.9%
sub-neg50.9%
div-sub50.9%
Simplified50.9%
Final simplification50.9%
(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%
distribute-lft-neg-in99.7%
Simplified99.7%
Taylor expanded in B around 0 50.6%
mul-1-neg50.6%
sub-neg50.6%
Simplified50.6%
Final simplification50.6%
(FPCore (B x) :precision binary64 (* B 0.16666666666666666))
double code(double B, double x) {
return B * 0.16666666666666666;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
code = b * 0.16666666666666666d0
end function
public static double code(double B, double x) {
return B * 0.16666666666666666;
}
def code(B, x): return B * 0.16666666666666666
function code(B, x) return Float64(B * 0.16666666666666666) end
function tmp = code(B, x) tmp = B * 0.16666666666666666; end
code[B_, x_] := N[(B * 0.16666666666666666), $MachinePrecision]
\begin{array}{l}
\\
B \cdot 0.16666666666666666
\end{array}
Initial program 99.7%
distribute-lft-neg-in99.7%
Simplified99.7%
Taylor expanded in B around 0 50.8%
+-commutative50.8%
mul-1-neg50.8%
sub-neg50.8%
associate--l+50.8%
*-commutative50.8%
*-commutative50.8%
div-sub50.8%
Simplified50.8%
Taylor expanded in x around 0 24.9%
Taylor expanded in B around inf 3.2%
*-commutative3.2%
Simplified3.2%
Final simplification3.2%
(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%
distribute-lft-neg-in99.7%
Simplified99.7%
Taylor expanded in B around 0 72.4%
Taylor expanded in x around 0 24.6%
Final simplification24.6%
herbie shell --seed 2023229
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))