
(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.8%
distribute-lft-neg-in99.8%
+-commutative99.8%
*-commutative99.8%
remove-double-neg99.8%
distribute-frac-neg299.8%
tan-neg99.8%
cancel-sign-sub-inv99.8%
*-commutative99.8%
associate-*r/99.8%
*-rgt-identity99.8%
tan-neg99.8%
distribute-neg-frac299.8%
distribute-neg-frac99.8%
remove-double-neg99.8%
Simplified99.8%
(FPCore (B x) :precision binary64 (if (<= x -920000.0) (* x (/ -1.0 (tan B))) (if (<= x 510000000.0) (/ (- 1.0 x) (sin B)) (/ x (- (tan B))))))
double code(double B, double x) {
double tmp;
if (x <= -920000.0) {
tmp = x * (-1.0 / tan(B));
} else if (x <= 510000000.0) {
tmp = (1.0 - x) / sin(B);
} else {
tmp = 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 <= (-920000.0d0)) then
tmp = x * ((-1.0d0) / tan(b))
else if (x <= 510000000.0d0) then
tmp = (1.0d0 - x) / sin(b)
else
tmp = x / -tan(b)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (x <= -920000.0) {
tmp = x * (-1.0 / Math.tan(B));
} else if (x <= 510000000.0) {
tmp = (1.0 - x) / Math.sin(B);
} else {
tmp = x / -Math.tan(B);
}
return tmp;
}
def code(B, x): tmp = 0 if x <= -920000.0: tmp = x * (-1.0 / math.tan(B)) elif x <= 510000000.0: tmp = (1.0 - x) / math.sin(B) else: tmp = x / -math.tan(B) return tmp
function code(B, x) tmp = 0.0 if (x <= -920000.0) tmp = Float64(x * Float64(-1.0 / tan(B))); elseif (x <= 510000000.0) tmp = Float64(Float64(1.0 - x) / sin(B)); else tmp = Float64(x / Float64(-tan(B))); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (x <= -920000.0) tmp = x * (-1.0 / tan(B)); elseif (x <= 510000000.0) tmp = (1.0 - x) / sin(B); else tmp = x / -tan(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[x, -920000.0], N[(x * N[(-1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 510000000.0], N[(N[(1.0 - x), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[(x / (-N[Tan[B], $MachinePrecision])), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -920000:\\
\;\;\;\;x \cdot \frac{-1}{\tan B}\\
\mathbf{elif}\;x \leq 510000000:\\
\;\;\;\;\frac{1 - x}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-\tan B}\\
\end{array}
\end{array}
if x < -9.2e5Initial program 99.8%
+-commutative99.8%
div-inv99.8%
sub-neg99.8%
clear-num99.7%
frac-sub83.0%
*-un-lft-identity83.0%
*-commutative83.0%
*-un-lft-identity83.0%
Applied egg-rr83.0%
associate-/r*99.7%
associate-/r/99.8%
div-sub99.8%
*-inverses99.8%
Simplified99.8%
Taylor expanded in x around inf 99.1%
if -9.2e5 < x < 5.1e8Initial program 99.8%
+-commutative99.8%
div-inv99.8%
sub-neg99.8%
clear-num99.8%
frac-sub91.0%
*-un-lft-identity91.0%
*-commutative91.0%
*-un-lft-identity91.0%
Applied egg-rr91.0%
associate-/r*99.6%
associate-/r/74.6%
div-sub74.6%
*-inverses74.6%
Simplified74.6%
Taylor expanded in B around inf 99.5%
Taylor expanded in B around 0 99.2%
sub-neg99.2%
metadata-eval99.2%
distribute-rgt-in99.2%
lft-mult-inverse99.4%
mul-1-neg99.4%
sub-neg99.4%
Simplified99.4%
if 5.1e8 < x Initial program 99.7%
Taylor expanded in x around inf 99.7%
mul-1-neg99.7%
associate-/l*99.7%
distribute-rgt-neg-in99.7%
distribute-neg-frac299.7%
Simplified99.7%
distribute-frac-neg299.7%
clear-num99.6%
tan-quot99.7%
distribute-rgt-neg-in99.7%
distribute-lft-neg-in99.7%
un-div-inv99.8%
Applied egg-rr99.8%
Final simplification99.4%
(FPCore (B x) :precision binary64 (if (or (<= x -1.65) (not (<= x 1.0))) (/ x (- (tan B))) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.65) || !(x <= 1.0)) {
tmp = 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 <= (-1.65d0)) .or. (.not. (x <= 1.0d0))) then
tmp = 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 <= -1.65) || !(x <= 1.0)) {
tmp = x / -Math.tan(B);
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -1.65) or not (x <= 1.0): tmp = x / -math.tan(B) else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -1.65) || !(x <= 1.0)) tmp = Float64(x / Float64(-tan(B))); else tmp = Float64(1.0 / sin(B)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if ((x <= -1.65) || ~((x <= 1.0))) tmp = x / -tan(B); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -1.65], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x / (-N[Tan[B], $MachinePrecision])), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{x}{-\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -1.6499999999999999 or 1 < x Initial program 99.7%
Taylor expanded in x around inf 98.0%
mul-1-neg98.0%
associate-/l*98.0%
distribute-rgt-neg-in98.0%
distribute-neg-frac298.0%
Simplified98.0%
distribute-frac-neg298.0%
clear-num97.9%
tan-quot98.0%
distribute-rgt-neg-in98.0%
distribute-lft-neg-in98.0%
un-div-inv98.0%
Applied egg-rr98.0%
if -1.6499999999999999 < x < 1Initial program 99.8%
Taylor expanded in x around 0 97.8%
Final simplification97.9%
(FPCore (B x) :precision binary64 (if (<= x -1.65) (* x (/ -1.0 (tan B))) (if (<= x 1.1) (/ 1.0 (sin B)) (/ x (- (tan B))))))
double code(double B, double x) {
double tmp;
if (x <= -1.65) {
tmp = x * (-1.0 / tan(B));
} else if (x <= 1.1) {
tmp = 1.0 / sin(B);
} else {
tmp = 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 <= (-1.65d0)) then
tmp = x * ((-1.0d0) / tan(b))
else if (x <= 1.1d0) then
tmp = 1.0d0 / sin(b)
else
tmp = x / -tan(b)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (x <= -1.65) {
tmp = x * (-1.0 / Math.tan(B));
} else if (x <= 1.1) {
tmp = 1.0 / Math.sin(B);
} else {
tmp = x / -Math.tan(B);
}
return tmp;
}
def code(B, x): tmp = 0 if x <= -1.65: tmp = x * (-1.0 / math.tan(B)) elif x <= 1.1: tmp = 1.0 / math.sin(B) else: tmp = x / -math.tan(B) return tmp
function code(B, x) tmp = 0.0 if (x <= -1.65) tmp = Float64(x * Float64(-1.0 / tan(B))); elseif (x <= 1.1) tmp = Float64(1.0 / sin(B)); else tmp = Float64(x / Float64(-tan(B))); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (x <= -1.65) tmp = x * (-1.0 / tan(B)); elseif (x <= 1.1) tmp = 1.0 / sin(B); else tmp = x / -tan(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[x, -1.65], N[(x * N[(-1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.1], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[(x / (-N[Tan[B], $MachinePrecision])), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65:\\
\;\;\;\;x \cdot \frac{-1}{\tan B}\\
\mathbf{elif}\;x \leq 1.1:\\
\;\;\;\;\frac{1}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-\tan B}\\
\end{array}
\end{array}
if x < -1.6499999999999999Initial program 99.8%
+-commutative99.8%
div-inv99.8%
sub-neg99.8%
clear-num99.7%
frac-sub82.1%
*-un-lft-identity82.1%
*-commutative82.1%
*-un-lft-identity82.1%
Applied egg-rr82.1%
associate-/r*99.7%
associate-/r/99.8%
div-sub99.8%
*-inverses99.8%
Simplified99.8%
Taylor expanded in x around inf 97.0%
if -1.6499999999999999 < x < 1.1000000000000001Initial program 99.8%
Taylor expanded in x around 0 97.8%
if 1.1000000000000001 < x Initial program 99.7%
Taylor expanded in x around inf 99.1%
mul-1-neg99.1%
associate-/l*99.2%
distribute-rgt-neg-in99.2%
distribute-neg-frac299.2%
Simplified99.2%
distribute-frac-neg299.2%
clear-num99.0%
tan-quot99.1%
distribute-rgt-neg-in99.1%
distribute-lft-neg-in99.1%
un-div-inv99.2%
Applied egg-rr99.2%
Final simplification97.9%
(FPCore (B x) :precision binary64 (if (<= B 3.1e-5) (/ (- 1.0 x) B) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if (B <= 3.1e-5) {
tmp = (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 <= 3.1d-5) then
tmp = (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 <= 3.1e-5) {
tmp = (1.0 - x) / B;
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if B <= 3.1e-5: tmp = (1.0 - x) / B else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if (B <= 3.1e-5) tmp = 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 <= 3.1e-5) tmp = (1.0 - x) / B; else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[B, 3.1e-5], N[(N[(1.0 - x), $MachinePrecision] / B), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;B \leq 3.1 \cdot 10^{-5}:\\
\;\;\;\;\frac{1 - x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if B < 3.10000000000000014e-5Initial program 99.8%
Taylor expanded in B around 0 72.0%
if 3.10000000000000014e-5 < B Initial program 99.6%
Taylor expanded in x around 0 53.6%
(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(x / Float64(-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.7%
Taylor expanded in B around 0 57.0%
Taylor expanded in x around inf 55.7%
neg-mul-155.7%
Simplified55.7%
if -1 < x < 1Initial program 99.8%
Taylor expanded in B around 0 49.3%
Taylor expanded in x around 0 47.9%
Final simplification51.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.8%
Taylor expanded in B around 0 53.3%
(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.8%
Taylor expanded in B around 0 53.3%
Taylor expanded in x around 0 25.1%
herbie shell --seed 2024148
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))