
(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 8 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%
distribute-lft-neg-in99.6%
+-commutative99.6%
cancel-sign-sub-inv99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (B x) :precision binary64 (if (or (<= x -9.8e-12) (not (<= x 0.05))) (/ (- 1.0 x) (tan B)) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -9.8e-12) || !(x <= 0.05)) {
tmp = (1.0 - x) / tan(B);
} else {
tmp = 1.0 / 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 <= (-9.8d-12)) .or. (.not. (x <= 0.05d0))) then
tmp = (1.0d0 - x) / tan(b)
else
tmp = 1.0d0 / sin(b)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if ((x <= -9.8e-12) || !(x <= 0.05)) {
tmp = (1.0 - x) / Math.tan(B);
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -9.8e-12) or not (x <= 0.05): tmp = (1.0 - x) / math.tan(B) else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -9.8e-12) || !(x <= 0.05)) tmp = Float64(Float64(1.0 - x) / tan(B)); else tmp = Float64(1.0 / sin(B)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if ((x <= -9.8e-12) || ~((x <= 0.05))) tmp = (1.0 - x) / tan(B); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -9.8e-12], N[Not[LessEqual[x, 0.05]], $MachinePrecision]], N[(N[(1.0 - x), $MachinePrecision] / N[Tan[B], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.8 \cdot 10^{-12} \lor \neg \left(x \leq 0.05\right):\\
\;\;\;\;\frac{1 - x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -9.79999999999999944e-12 or 0.050000000000000003 < x Initial program 99.5%
+-commutative99.5%
div-inv99.8%
sub-neg99.8%
clear-num99.6%
frac-sub85.0%
*-un-lft-identity85.0%
*-commutative85.0%
*-un-lft-identity85.0%
Applied egg-rr85.0%
associate-/r*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
div-inv99.6%
clear-num99.8%
div-inv99.5%
associate-*r*99.6%
sub-neg99.6%
associate-/l/99.3%
associate-/r*99.6%
metadata-eval99.6%
Applied egg-rr99.6%
Taylor expanded in B around 0 97.7%
expm1-log1p-u47.3%
expm1-udef47.3%
un-div-inv47.3%
*-commutative47.3%
associate-/l*47.3%
Applied egg-rr47.3%
expm1-def47.3%
expm1-log1p97.6%
associate-/l*97.9%
distribute-rgt-in97.9%
lft-mult-inverse97.9%
neg-mul-197.9%
sub-neg97.9%
Simplified97.9%
if -9.79999999999999944e-12 < x < 0.050000000000000003Initial program 99.7%
Taylor expanded in x around 0 99.1%
Final simplification98.5%
(FPCore (B x) :precision binary64 (if (<= x -9.8e-12) (/ (* x (+ (/ 1.0 x) -1.0)) (tan B)) (if (<= x 0.05) (/ 1.0 (sin B)) (/ (- 1.0 x) (tan B)))))
double code(double B, double x) {
double tmp;
if (x <= -9.8e-12) {
tmp = (x * ((1.0 / x) + -1.0)) / tan(B);
} else if (x <= 0.05) {
tmp = 1.0 / 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 <= (-9.8d-12)) then
tmp = (x * ((1.0d0 / x) + (-1.0d0))) / tan(b)
else if (x <= 0.05d0) then
tmp = 1.0d0 / 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 <= -9.8e-12) {
tmp = (x * ((1.0 / x) + -1.0)) / Math.tan(B);
} else if (x <= 0.05) {
tmp = 1.0 / Math.sin(B);
} else {
tmp = (1.0 - x) / Math.tan(B);
}
return tmp;
}
def code(B, x): tmp = 0 if x <= -9.8e-12: tmp = (x * ((1.0 / x) + -1.0)) / math.tan(B) elif x <= 0.05: tmp = 1.0 / math.sin(B) else: tmp = (1.0 - x) / math.tan(B) return tmp
function code(B, x) tmp = 0.0 if (x <= -9.8e-12) tmp = Float64(Float64(x * Float64(Float64(1.0 / x) + -1.0)) / tan(B)); elseif (x <= 0.05) tmp = Float64(1.0 / 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 <= -9.8e-12) tmp = (x * ((1.0 / x) + -1.0)) / tan(B); elseif (x <= 0.05) tmp = 1.0 / sin(B); else tmp = (1.0 - x) / tan(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[x, -9.8e-12], N[(N[(x * N[(N[(1.0 / x), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] / N[Tan[B], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.05], N[(1.0 / 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 -9.8 \cdot 10^{-12}:\\
\;\;\;\;\frac{x \cdot \left(\frac{1}{x} + -1\right)}{\tan B}\\
\mathbf{elif}\;x \leq 0.05:\\
\;\;\;\;\frac{1}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - x}{\tan B}\\
\end{array}
\end{array}
if x < -9.79999999999999944e-12Initial program 99.6%
+-commutative99.6%
div-inv99.8%
sub-neg99.8%
clear-num99.7%
frac-sub83.7%
*-un-lft-identity83.7%
*-commutative83.7%
*-un-lft-identity83.7%
Applied egg-rr83.7%
associate-/r*99.6%
div-sub99.7%
*-inverses99.7%
Simplified99.7%
div-inv99.7%
clear-num99.8%
div-inv99.5%
associate-*r*99.6%
sub-neg99.6%
associate-/l/99.0%
associate-/r*99.6%
metadata-eval99.6%
Applied egg-rr99.6%
Taylor expanded in B around 0 97.1%
un-div-inv97.3%
*-commutative97.3%
Applied egg-rr97.3%
if -9.79999999999999944e-12 < x < 0.050000000000000003Initial program 99.7%
Taylor expanded in x around 0 99.1%
if 0.050000000000000003 < x Initial program 99.5%
+-commutative99.5%
div-inv99.7%
sub-neg99.7%
clear-num99.6%
frac-sub86.4%
*-un-lft-identity86.4%
*-commutative86.4%
*-un-lft-identity86.4%
Applied egg-rr86.4%
associate-/r*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
div-inv99.6%
clear-num99.7%
div-inv99.5%
associate-*r*99.6%
sub-neg99.6%
associate-/l/99.6%
associate-/r*99.6%
metadata-eval99.6%
Applied egg-rr99.6%
Taylor expanded in B around 0 98.3%
expm1-log1p-u46.5%
expm1-udef46.5%
un-div-inv46.5%
*-commutative46.5%
associate-/l*46.5%
Applied egg-rr46.5%
expm1-def46.5%
expm1-log1p98.4%
associate-/l*98.4%
distribute-rgt-in98.4%
lft-mult-inverse98.4%
neg-mul-198.4%
sub-neg98.4%
Simplified98.4%
Final simplification98.5%
(FPCore (B x) :precision binary64 (if (<= B 400.0) (+ (* B (+ 0.16666666666666666 (* x 0.3333333333333333))) (/ (- 1.0 x) B)) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if (B <= 400.0) {
tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B);
} else {
tmp = 1.0 / sin(B);
}
return tmp;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
real(8) :: tmp
if (b <= 400.0d0) then
tmp = (b * (0.16666666666666666d0 + (x * 0.3333333333333333d0))) + ((1.0d0 - x) / b)
else
tmp = 1.0d0 / sin(b)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (B <= 400.0) {
tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B);
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if B <= 400.0: tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B) else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if (B <= 400.0) tmp = Float64(Float64(B * Float64(0.16666666666666666 + Float64(x * 0.3333333333333333))) + Float64(Float64(1.0 - x) / B)); else tmp = Float64(1.0 / sin(B)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (B <= 400.0) tmp = (B * (0.16666666666666666 + (x * 0.3333333333333333))) + ((1.0 - x) / B); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[B, 400.0], N[(N[(B * N[(0.16666666666666666 + N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq 400:\\
\;\;\;\;B \cdot \left(0.16666666666666666 + x \cdot 0.3333333333333333\right) + \frac{1 - x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if B < 400Initial program 99.7%
Taylor expanded in B around 0 66.2%
associate--l+66.2%
*-commutative66.2%
div-sub66.2%
Simplified66.2%
if 400 < B Initial program 99.4%
Taylor expanded in x around 0 42.1%
Final simplification61.2%
(FPCore (B x) :precision binary64 (if (or (<= x -7.4e-7) (not (<= x 15600.0))) (- (/ x B)) (/ 1.0 B)))
double code(double B, double x) {
double tmp;
if ((x <= -7.4e-7) || !(x <= 15600.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 <= (-7.4d-7)) .or. (.not. (x <= 15600.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 <= -7.4e-7) || !(x <= 15600.0)) {
tmp = -(x / B);
} else {
tmp = 1.0 / B;
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -7.4e-7) or not (x <= 15600.0): tmp = -(x / B) else: tmp = 1.0 / B return tmp
function code(B, x) tmp = 0.0 if ((x <= -7.4e-7) || !(x <= 15600.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 <= -7.4e-7) || ~((x <= 15600.0))) tmp = -(x / B); else tmp = 1.0 / B; end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -7.4e-7], N[Not[LessEqual[x, 15600.0]], $MachinePrecision]], (-N[(x / B), $MachinePrecision]), N[(1.0 / B), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.4 \cdot 10^{-7} \lor \neg \left(x \leq 15600\right):\\
\;\;\;\;-\frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B}\\
\end{array}
\end{array}
if x < -7.40000000000000009e-7 or 15600 < x Initial program 99.6%
Taylor expanded in B around 0 50.4%
Taylor expanded in x around inf 49.4%
neg-mul-149.4%
distribute-neg-frac49.4%
Simplified49.4%
if -7.40000000000000009e-7 < x < 15600Initial program 99.7%
Taylor expanded in B around 0 56.0%
div-inv56.0%
add-sqr-sqrt23.8%
associate-/l*23.8%
Applied egg-rr23.8%
Taylor expanded in x around 0 55.2%
Final simplification52.5%
(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.6%
Taylor expanded in B around 0 76.2%
Taylor expanded in B around 0 53.2%
associate--l+53.2%
div-sub53.2%
Simplified53.2%
Final simplification53.2%
(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 53.1%
Final simplification53.1%
(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 76.2%
div-inv76.2%
add-sqr-sqrt35.9%
associate-/l*36.0%
Applied egg-rr36.0%
Taylor expanded in x around 0 30.1%
Final simplification30.1%
herbie shell --seed 2024019
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))