
(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%
distribute-lft-neg-in99.7%
+-commutative99.7%
*-commutative99.7%
remove-double-neg99.7%
distribute-frac-neg299.7%
tan-neg99.7%
cancel-sign-sub-inv99.7%
*-commutative99.7%
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 -4.5e-11) (- (/ 1.0 B) (/ x (tan B))) (if (<= x 4.2e-24) (/ 1.0 (sin B)) (+ (/ 1.0 B) (* x (/ -1.0 (tan B)))))))
double code(double B, double x) {
double tmp;
if (x <= -4.5e-11) {
tmp = (1.0 / B) - (x / tan(B));
} else if (x <= 4.2e-24) {
tmp = 1.0 / sin(B);
} else {
tmp = (1.0 / B) + (x * (-1.0 / 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 <= (-4.5d-11)) then
tmp = (1.0d0 / b) - (x / tan(b))
else if (x <= 4.2d-24) then
tmp = 1.0d0 / sin(b)
else
tmp = (1.0d0 / b) + (x * ((-1.0d0) / tan(b)))
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (x <= -4.5e-11) {
tmp = (1.0 / B) - (x / Math.tan(B));
} else if (x <= 4.2e-24) {
tmp = 1.0 / Math.sin(B);
} else {
tmp = (1.0 / B) + (x * (-1.0 / Math.tan(B)));
}
return tmp;
}
def code(B, x): tmp = 0 if x <= -4.5e-11: tmp = (1.0 / B) - (x / math.tan(B)) elif x <= 4.2e-24: tmp = 1.0 / math.sin(B) else: tmp = (1.0 / B) + (x * (-1.0 / math.tan(B))) return tmp
function code(B, x) tmp = 0.0 if (x <= -4.5e-11) tmp = Float64(Float64(1.0 / B) - Float64(x / tan(B))); elseif (x <= 4.2e-24) tmp = Float64(1.0 / sin(B)); else tmp = Float64(Float64(1.0 / B) + Float64(x * Float64(-1.0 / tan(B)))); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (x <= -4.5e-11) tmp = (1.0 / B) - (x / tan(B)); elseif (x <= 4.2e-24) tmp = 1.0 / sin(B); else tmp = (1.0 / B) + (x * (-1.0 / tan(B))); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[x, -4.5e-11], N[(N[(1.0 / B), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.2e-24], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / B), $MachinePrecision] + N[(x * N[(-1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{-11}:\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-24}:\\
\;\;\;\;\frac{1}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B} + x \cdot \frac{-1}{\tan B}\\
\end{array}
\end{array}
if x < -4.5e-11Initial program 99.6%
distribute-lft-neg-in99.6%
+-commutative99.6%
*-commutative99.6%
remove-double-neg99.6%
distribute-frac-neg299.6%
tan-neg99.6%
cancel-sign-sub-inv99.6%
*-commutative99.6%
associate-*r/99.8%
*-rgt-identity99.8%
tan-neg99.8%
distribute-neg-frac299.8%
distribute-neg-frac99.8%
remove-double-neg99.8%
Simplified99.8%
Taylor expanded in B around 0 99.8%
if -4.5e-11 < x < 4.1999999999999999e-24Initial program 99.8%
Taylor expanded in x around 0 99.8%
if 4.1999999999999999e-24 < x Initial program 99.7%
Taylor expanded in B around 0 96.0%
Final simplification98.7%
(FPCore (B x) :precision binary64 (if (or (<= x -4.5e-11) (not (<= x 4.2e-24))) (- (/ 1.0 B) (/ x (tan B))) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -4.5e-11) || !(x <= 4.2e-24)) {
tmp = (1.0 / B) - (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 <= (-4.5d-11)) .or. (.not. (x <= 4.2d-24))) then
tmp = (1.0d0 / b) - (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 <= -4.5e-11) || !(x <= 4.2e-24)) {
tmp = (1.0 / B) - (x / Math.tan(B));
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -4.5e-11) or not (x <= 4.2e-24): tmp = (1.0 / B) - (x / math.tan(B)) else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -4.5e-11) || !(x <= 4.2e-24)) tmp = Float64(Float64(1.0 / B) - Float64(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 <= -4.5e-11) || ~((x <= 4.2e-24))) tmp = (1.0 / B) - (x / tan(B)); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -4.5e-11], N[Not[LessEqual[x, 4.2e-24]], $MachinePrecision]], N[(N[(1.0 / B), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{-11} \lor \neg \left(x \leq 4.2 \cdot 10^{-24}\right):\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -4.5e-11 or 4.1999999999999999e-24 < x Initial program 99.6%
distribute-lft-neg-in99.6%
+-commutative99.6%
*-commutative99.6%
remove-double-neg99.6%
distribute-frac-neg299.6%
tan-neg99.6%
cancel-sign-sub-inv99.6%
*-commutative99.6%
associate-*r/99.7%
*-rgt-identity99.7%
tan-neg99.7%
distribute-neg-frac299.7%
distribute-neg-frac99.7%
remove-double-neg99.7%
Simplified99.7%
Taylor expanded in B around 0 97.8%
if -4.5e-11 < x < 4.1999999999999999e-24Initial program 99.8%
Taylor expanded in x around 0 99.8%
Final simplification98.7%
(FPCore (B x) :precision binary64 (if (<= x -1.4) (/ x (- (tan B))) (if (<= x 1.1) (/ 1.0 (sin B)) (* x (/ -1.0 (tan B))))))
double code(double B, double x) {
double tmp;
if (x <= -1.4) {
tmp = x / -tan(B);
} else if (x <= 1.1) {
tmp = 1.0 / sin(B);
} else {
tmp = x * (-1.0 / 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.4d0)) then
tmp = x / -tan(b)
else if (x <= 1.1d0) then
tmp = 1.0d0 / sin(b)
else
tmp = x * ((-1.0d0) / tan(b))
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (x <= -1.4) {
tmp = x / -Math.tan(B);
} else if (x <= 1.1) {
tmp = 1.0 / Math.sin(B);
} else {
tmp = x * (-1.0 / Math.tan(B));
}
return tmp;
}
def code(B, x): tmp = 0 if x <= -1.4: tmp = x / -math.tan(B) elif x <= 1.1: tmp = 1.0 / math.sin(B) else: tmp = x * (-1.0 / math.tan(B)) return tmp
function code(B, x) tmp = 0.0 if (x <= -1.4) tmp = Float64(x / Float64(-tan(B))); elseif (x <= 1.1) tmp = Float64(1.0 / sin(B)); else tmp = Float64(x * Float64(-1.0 / tan(B))); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (x <= -1.4) tmp = x / -tan(B); elseif (x <= 1.1) tmp = 1.0 / sin(B); else tmp = x * (-1.0 / tan(B)); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[x, -1.4], N[(x / (-N[Tan[B], $MachinePrecision])), $MachinePrecision], If[LessEqual[x, 1.1], N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision], N[(x * N[(-1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4:\\
\;\;\;\;\frac{x}{-\tan B}\\
\mathbf{elif}\;x \leq 1.1:\\
\;\;\;\;\frac{1}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{-1}{\tan B}\\
\end{array}
\end{array}
if x < -1.3999999999999999Initial program 99.6%
Taylor expanded in x around inf 98.4%
mul-1-neg98.4%
associate-/l*98.5%
distribute-rgt-neg-in98.5%
distribute-neg-frac98.5%
Simplified98.5%
distribute-frac-neg98.5%
neg-sub098.5%
clear-num98.4%
tan-quot98.5%
Applied egg-rr98.5%
neg-sub098.5%
distribute-neg-frac98.5%
metadata-eval98.5%
Simplified98.5%
frac-2neg98.5%
metadata-eval98.5%
un-div-inv98.7%
Applied egg-rr98.7%
distribute-frac-neg298.7%
distribute-frac-neg98.7%
Simplified98.7%
if -1.3999999999999999 < x < 1.1000000000000001Initial program 99.8%
Taylor expanded in x around 0 97.1%
if 1.1000000000000001 < x Initial program 99.7%
Taylor expanded in x around inf 96.5%
mul-1-neg96.5%
associate-/l*96.4%
distribute-rgt-neg-in96.4%
distribute-neg-frac96.4%
Simplified96.4%
distribute-frac-neg96.4%
neg-sub096.4%
clear-num96.4%
tan-quot96.5%
Applied egg-rr96.5%
neg-sub096.5%
distribute-neg-frac96.5%
metadata-eval96.5%
Simplified96.5%
Final simplification97.3%
(FPCore (B x) :precision binary64 (if (or (<= x -1.5) (not (<= x 1.0))) (/ x (- (tan B))) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.5) || !(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.5d0)) .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.5) || !(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.5) 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.5) || !(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.5) || ~((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.5], 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.5 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{x}{-\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -1.5 or 1 < x Initial program 99.6%
Taylor expanded in x around inf 97.4%
mul-1-neg97.4%
associate-/l*97.4%
distribute-rgt-neg-in97.4%
distribute-neg-frac97.4%
Simplified97.4%
distribute-frac-neg97.4%
neg-sub097.4%
clear-num97.3%
tan-quot97.5%
Applied egg-rr97.5%
neg-sub097.5%
distribute-neg-frac97.5%
metadata-eval97.5%
Simplified97.5%
frac-2neg97.5%
metadata-eval97.5%
un-div-inv97.5%
Applied egg-rr97.5%
distribute-frac-neg297.5%
distribute-frac-neg97.5%
Simplified97.5%
if -1.5 < x < 1Initial program 99.8%
Taylor expanded in x around 0 97.1%
Final simplification97.3%
(FPCore (B x) :precision binary64 (if (<= B 1950000.0) (/ (- 1.0 x) B) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if (B <= 1950000.0) {
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 <= 1950000.0d0) 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 <= 1950000.0) {
tmp = (1.0 - x) / B;
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if B <= 1950000.0: tmp = (1.0 - x) / B else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if (B <= 1950000.0) 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 <= 1950000.0) tmp = (1.0 - x) / B; else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[B, 1950000.0], 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 1950000:\\
\;\;\;\;\frac{1 - x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if B < 1.95e6Initial program 99.8%
Taylor expanded in B around 0 64.5%
if 1.95e6 < B Initial program 99.6%
Taylor expanded in x around 0 43.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(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.6%
Taylor expanded in B around 0 42.9%
Taylor expanded in x around inf 40.7%
neg-mul-140.7%
distribute-neg-frac40.7%
Simplified40.7%
if -1 < x < 1Initial program 99.8%
Taylor expanded in B around 0 57.9%
Taylor expanded in x around 0 56.6%
Final simplification48.7%
(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 50.4%
(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 50.4%
Taylor expanded in x around 0 29.8%
herbie shell --seed 2024103
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))