
(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 -0.225)
(/ (- 1.0 x) (tan B))
(if (<= x 1.6)
(- (/ 1.0 (sin B)) (/ x B))
(* (/ x (tan B)) (+ -1.0 (/ 1.0 x))))))
double code(double B, double x) {
double tmp;
if (x <= -0.225) {
tmp = (1.0 - x) / tan(B);
} else if (x <= 1.6) {
tmp = (1.0 / sin(B)) - (x / B);
} else {
tmp = (x / tan(B)) * (-1.0 + (1.0 / x));
}
return tmp;
}
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-0.225d0)) then
tmp = (1.0d0 - x) / tan(b)
else if (x <= 1.6d0) then
tmp = (1.0d0 / sin(b)) - (x / b)
else
tmp = (x / tan(b)) * ((-1.0d0) + (1.0d0 / x))
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if (x <= -0.225) {
tmp = (1.0 - x) / Math.tan(B);
} else if (x <= 1.6) {
tmp = (1.0 / Math.sin(B)) - (x / B);
} else {
tmp = (x / Math.tan(B)) * (-1.0 + (1.0 / x));
}
return tmp;
}
def code(B, x): tmp = 0 if x <= -0.225: tmp = (1.0 - x) / math.tan(B) elif x <= 1.6: tmp = (1.0 / math.sin(B)) - (x / B) else: tmp = (x / math.tan(B)) * (-1.0 + (1.0 / x)) return tmp
function code(B, x) tmp = 0.0 if (x <= -0.225) tmp = Float64(Float64(1.0 - x) / tan(B)); elseif (x <= 1.6) tmp = Float64(Float64(1.0 / sin(B)) - Float64(x / B)); else tmp = Float64(Float64(x / tan(B)) * Float64(-1.0 + Float64(1.0 / x))); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if (x <= -0.225) tmp = (1.0 - x) / tan(B); elseif (x <= 1.6) tmp = (1.0 / sin(B)) - (x / B); else tmp = (x / tan(B)) * (-1.0 + (1.0 / x)); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[x, -0.225], N[(N[(1.0 - x), $MachinePrecision] / N[Tan[B], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.6], N[(N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision] - N[(x / B), $MachinePrecision]), $MachinePrecision], N[(N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision] * N[(-1.0 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.225:\\
\;\;\;\;\frac{1 - x}{\tan B}\\
\mathbf{elif}\;x \leq 1.6:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\tan B} \cdot \left(-1 + \frac{1}{x}\right)\\
\end{array}
\end{array}
if x < -0.225000000000000006Initial program 99.6%
*-commutative99.6%
distribute-lft-neg-in99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Applied egg-rr99.6%
+-commutative99.6%
associate-*l/99.8%
neg-mul-199.8%
distribute-neg-frac99.8%
div-inv99.6%
sub-neg99.6%
div-inv99.8%
clear-num99.7%
frac-sub85.6%
*-un-lft-identity85.6%
metadata-eval85.6%
div-inv85.6%
/-rgt-identity85.6%
Applied egg-rr85.6%
associate-/r*99.7%
div-sub99.7%
*-inverses99.7%
Simplified99.7%
Taylor expanded in B around 0 97.8%
div-sub97.8%
div-inv97.8%
clear-num97.8%
clear-num97.9%
Applied egg-rr97.9%
sub-neg97.9%
neg-mul-197.9%
distribute-rgt-in97.9%
+-commutative97.9%
*-commutative97.9%
associate-*r/97.9%
/-rgt-identity97.9%
associate-/r/97.8%
+-commutative97.8%
metadata-eval97.8%
sub-neg97.8%
div-sub97.8%
*-inverses97.8%
remove-double-div97.9%
Simplified97.9%
if -0.225000000000000006 < x < 1.6000000000000001Initial 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%
expm1-log1p-u86.4%
expm1-undefine39.4%
Applied egg-rr39.4%
expm1-define86.4%
Simplified86.4%
Taylor expanded in B around 0 98.3%
if 1.6000000000000001 < x Initial program 99.6%
*-commutative99.6%
distribute-lft-neg-in99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Applied egg-rr99.6%
+-commutative99.6%
associate-*l/99.8%
neg-mul-199.8%
distribute-neg-frac99.8%
div-inv99.6%
sub-neg99.6%
div-inv99.8%
clear-num99.6%
frac-sub91.9%
*-un-lft-identity91.9%
metadata-eval91.9%
div-inv91.9%
/-rgt-identity91.9%
Applied egg-rr91.9%
associate-/r*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around 0 99.2%
clear-num99.2%
associate-/r/99.2%
clear-num99.4%
sub-neg99.4%
metadata-eval99.4%
+-commutative99.4%
Applied egg-rr99.4%
(FPCore (B x) :precision binary64 (if (or (<= x -1.1) (not (<= x 2.7))) (/ (- 1.0 x) (tan B)) (- (/ 1.0 (sin B)) (/ x B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.1) || !(x <= 2.7)) {
tmp = (1.0 - x) / tan(B);
} else {
tmp = (1.0 / sin(B)) - (x / 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.1d0)) .or. (.not. (x <= 2.7d0))) then
tmp = (1.0d0 - x) / tan(b)
else
tmp = (1.0d0 / sin(b)) - (x / b)
end if
code = tmp
end function
public static double code(double B, double x) {
double tmp;
if ((x <= -1.1) || !(x <= 2.7)) {
tmp = (1.0 - x) / Math.tan(B);
} else {
tmp = (1.0 / Math.sin(B)) - (x / B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -1.1) or not (x <= 2.7): tmp = (1.0 - x) / math.tan(B) else: tmp = (1.0 / math.sin(B)) - (x / B) return tmp
function code(B, x) tmp = 0.0 if ((x <= -1.1) || !(x <= 2.7)) tmp = Float64(Float64(1.0 - x) / tan(B)); else tmp = Float64(Float64(1.0 / sin(B)) - Float64(x / B)); end return tmp end
function tmp_2 = code(B, x) tmp = 0.0; if ((x <= -1.1) || ~((x <= 2.7))) tmp = (1.0 - x) / tan(B); else tmp = (1.0 / sin(B)) - (x / B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -1.1], N[Not[LessEqual[x, 2.7]], $MachinePrecision]], N[(N[(1.0 - x), $MachinePrecision] / N[Tan[B], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision] - N[(x / B), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \lor \neg \left(x \leq 2.7\right):\\
\;\;\;\;\frac{1 - x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{B}\\
\end{array}
\end{array}
if x < -1.1000000000000001 or 2.7000000000000002 < x Initial program 99.6%
*-commutative99.6%
distribute-lft-neg-in99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Applied egg-rr99.6%
+-commutative99.6%
associate-*l/99.8%
neg-mul-199.8%
distribute-neg-frac99.8%
div-inv99.6%
sub-neg99.6%
div-inv99.8%
clear-num99.6%
frac-sub89.0%
*-un-lft-identity89.0%
metadata-eval89.0%
div-inv89.0%
/-rgt-identity89.0%
Applied egg-rr89.0%
associate-/r*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around 0 98.6%
div-sub84.5%
div-inv83.6%
clear-num83.6%
clear-num83.8%
Applied egg-rr83.8%
sub-neg83.8%
neg-mul-183.8%
distribute-rgt-in98.7%
+-commutative98.7%
*-commutative98.7%
associate-*r/98.7%
/-rgt-identity98.7%
associate-/r/98.6%
+-commutative98.6%
metadata-eval98.6%
sub-neg98.6%
div-sub98.6%
*-inverses98.6%
remove-double-div98.7%
Simplified98.7%
if -1.1000000000000001 < x < 2.7000000000000002Initial 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%
expm1-log1p-u86.4%
expm1-undefine39.4%
Applied egg-rr39.4%
expm1-define86.4%
Simplified86.4%
Taylor expanded in B around 0 98.3%
Final simplification98.5%
(FPCore (B x) :precision binary64 (if (or (<= x -0.000135) (not (<= x 0.36))) (/ (- 1.0 x) (tan B)) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -0.000135) || !(x <= 0.36)) {
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 <= (-0.000135d0)) .or. (.not. (x <= 0.36d0))) 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 <= -0.000135) || !(x <= 0.36)) {
tmp = (1.0 - x) / Math.tan(B);
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -0.000135) or not (x <= 0.36): 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 <= -0.000135) || !(x <= 0.36)) 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 <= -0.000135) || ~((x <= 0.36))) tmp = (1.0 - x) / tan(B); else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[Or[LessEqual[x, -0.000135], N[Not[LessEqual[x, 0.36]], $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 -0.000135 \lor \neg \left(x \leq 0.36\right):\\
\;\;\;\;\frac{1 - x}{\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -1.35000000000000002e-4 or 0.35999999999999999 < x Initial program 99.6%
*-commutative99.6%
distribute-lft-neg-in99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Applied egg-rr99.6%
+-commutative99.6%
associate-*l/99.8%
neg-mul-199.8%
distribute-neg-frac99.8%
div-inv99.6%
sub-neg99.6%
div-inv99.8%
clear-num99.6%
frac-sub89.0%
*-un-lft-identity89.0%
metadata-eval89.0%
div-inv89.0%
/-rgt-identity89.0%
Applied egg-rr89.0%
associate-/r*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in B around 0 98.6%
div-sub84.5%
div-inv83.6%
clear-num83.6%
clear-num83.8%
Applied egg-rr83.8%
sub-neg83.8%
neg-mul-183.8%
distribute-rgt-in98.7%
+-commutative98.7%
*-commutative98.7%
associate-*r/98.7%
/-rgt-identity98.7%
associate-/r/98.6%
+-commutative98.6%
metadata-eval98.6%
sub-neg98.6%
div-sub98.6%
*-inverses98.6%
remove-double-div98.7%
Simplified98.7%
if -1.35000000000000002e-4 < x < 0.35999999999999999Initial program 99.8%
Taylor expanded in x around 0 98.1%
Final simplification98.4%
(FPCore (B x) :precision binary64 (if (or (<= x -1.25) (not (<= x 1.0))) (/ x (- (tan B))) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if ((x <= -1.25) || !(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.25d0)) .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.25) || !(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.25) 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.25) || !(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.25) || ~((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.25], 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.25 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{x}{-\tan B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if x < -1.25 or 1 < x Initial program 99.6%
*-commutative99.6%
distribute-lft-neg-in99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Applied egg-rr99.6%
+-commutative99.6%
associate-*l/99.8%
neg-mul-199.8%
distribute-neg-frac99.8%
div-inv99.6%
sub-neg99.6%
div-inv99.8%
clear-num99.6%
frac-sub89.0%
*-un-lft-identity89.0%
metadata-eval89.0%
div-inv89.0%
/-rgt-identity89.0%
Applied egg-rr89.0%
associate-/r*99.6%
div-sub99.6%
*-inverses99.6%
Simplified99.6%
Taylor expanded in x around inf 97.1%
associate-/r/97.1%
*-commutative97.1%
Applied egg-rr97.1%
*-commutative97.1%
associate-*l/97.2%
mul-1-neg97.2%
Simplified97.2%
if -1.25 < x < 1Initial program 99.8%
Taylor expanded in x around 0 98.1%
Final simplification97.8%
(FPCore (B x) :precision binary64 (if (<= B 7.6e-10) (/ (- 1.0 x) B) (/ 1.0 (sin B))))
double code(double B, double x) {
double tmp;
if (B <= 7.6e-10) {
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 <= 7.6d-10) 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 <= 7.6e-10) {
tmp = (1.0 - x) / B;
} else {
tmp = 1.0 / Math.sin(B);
}
return tmp;
}
def code(B, x): tmp = 0 if B <= 7.6e-10: tmp = (1.0 - x) / B else: tmp = 1.0 / math.sin(B) return tmp
function code(B, x) tmp = 0.0 if (B <= 7.6e-10) 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 <= 7.6e-10) tmp = (1.0 - x) / B; else tmp = 1.0 / sin(B); end tmp_2 = tmp; end
code[B_, x_] := If[LessEqual[B, 7.6e-10], 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 7.6 \cdot 10^{-10}:\\
\;\;\;\;\frac{1 - x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin B}\\
\end{array}
\end{array}
if B < 7.5999999999999996e-10Initial program 99.7%
Taylor expanded in B around 0 66.6%
if 7.5999999999999996e-10 < B Initial program 99.6%
Taylor expanded in x around 0 64.7%
(FPCore (B x) :precision binary64 (if (or (<= x -1.0) (not (<= x 7.2e-6))) (/ x (- B)) (/ 1.0 B)))
double code(double B, double x) {
double tmp;
if ((x <= -1.0) || !(x <= 7.2e-6)) {
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 <= 7.2d-6))) 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 <= 7.2e-6)) {
tmp = x / -B;
} else {
tmp = 1.0 / B;
}
return tmp;
}
def code(B, x): tmp = 0 if (x <= -1.0) or not (x <= 7.2e-6): tmp = x / -B else: tmp = 1.0 / B return tmp
function code(B, x) tmp = 0.0 if ((x <= -1.0) || !(x <= 7.2e-6)) 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 <= 7.2e-6))) 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, 7.2e-6]], $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 7.2 \cdot 10^{-6}\right):\\
\;\;\;\;\frac{x}{-B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B}\\
\end{array}
\end{array}
if x < -1 or 7.19999999999999967e-6 < x Initial program 99.6%
Taylor expanded in B around 0 51.4%
Taylor expanded in x around inf 50.1%
neg-mul-150.1%
Simplified50.1%
if -1 < x < 7.19999999999999967e-6Initial program 99.8%
Taylor expanded in B around 0 52.1%
Taylor expanded in x around 0 52.1%
Final simplification51.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.7%
Taylor expanded in B around 0 51.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.7%
Taylor expanded in B around 0 51.8%
Taylor expanded in x around 0 31.1%
herbie shell --seed 2024136
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))