| Alternative 1 | |
|---|---|
| Accuracy | 87.0% |
| Cost | 13248 |
(FPCore (B x) :precision binary64 (+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))
(FPCore (B x)
:precision binary64
(if (<= x -4e+14)
(/ (- x) (tan B))
(if (<= x 6.2e-27)
(- (/ 1.0 (sin B)) (/ x B))
(- (/ 1.0 B) (/ x (tan B))))))double code(double B, double x) {
return -(x * (1.0 / tan(B))) + (1.0 / sin(B));
}
double code(double B, double x) {
double tmp;
if (x <= -4e+14) {
tmp = -x / tan(B);
} else if (x <= 6.2e-27) {
tmp = (1.0 / sin(B)) - (x / B);
} else {
tmp = (1.0 / B) - (x / tan(B));
}
return tmp;
}
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
real(8) function code(b, x)
real(8), intent (in) :: b
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-4d+14)) then
tmp = -x / tan(b)
else if (x <= 6.2d-27) then
tmp = (1.0d0 / sin(b)) - (x / b)
else
tmp = (1.0d0 / b) - (x / tan(b))
end if
code = tmp
end function
public static double code(double B, double x) {
return -(x * (1.0 / Math.tan(B))) + (1.0 / Math.sin(B));
}
public static double code(double B, double x) {
double tmp;
if (x <= -4e+14) {
tmp = -x / Math.tan(B);
} else if (x <= 6.2e-27) {
tmp = (1.0 / Math.sin(B)) - (x / B);
} else {
tmp = (1.0 / B) - (x / Math.tan(B));
}
return tmp;
}
def code(B, x): return -(x * (1.0 / math.tan(B))) + (1.0 / math.sin(B))
def code(B, x): tmp = 0 if x <= -4e+14: tmp = -x / math.tan(B) elif x <= 6.2e-27: tmp = (1.0 / math.sin(B)) - (x / B) else: tmp = (1.0 / B) - (x / math.tan(B)) return tmp
function code(B, x) return Float64(Float64(-Float64(x * Float64(1.0 / tan(B)))) + Float64(1.0 / sin(B))) end
function code(B, x) tmp = 0.0 if (x <= -4e+14) tmp = Float64(Float64(-x) / tan(B)); elseif (x <= 6.2e-27) tmp = Float64(Float64(1.0 / sin(B)) - Float64(x / B)); else tmp = Float64(Float64(1.0 / B) - Float64(x / tan(B))); end return tmp end
function tmp = code(B, x) tmp = -(x * (1.0 / tan(B))) + (1.0 / sin(B)); end
function tmp_2 = code(B, x) tmp = 0.0; if (x <= -4e+14) tmp = -x / tan(B); elseif (x <= 6.2e-27) tmp = (1.0 / sin(B)) - (x / B); else tmp = (1.0 / B) - (x / tan(B)); end tmp_2 = tmp; 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]
code[B_, x_] := If[LessEqual[x, -4e+14], N[((-x) / N[Tan[B], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 6.2e-27], N[(N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision] - N[(x / B), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / B), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+14}:\\
\;\;\;\;\frac{-x}{\tan B}\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{-27}:\\
\;\;\;\;\frac{1}{\sin B} - \frac{x}{B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{B} - \frac{x}{\tan B}\\
\end{array}
Results
if x < -4e14Initial program 73.5%
Simplified73.7%
[Start]73.5 | \[ \left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}
\] |
|---|---|
+-commutative [=>]73.5 | \[ \color{blue}{\frac{1}{\sin B} + \left(-x \cdot \frac{1}{\tan B}\right)}
\] |
unsub-neg [=>]73.5 | \[ \color{blue}{\frac{1}{\sin B} - x \cdot \frac{1}{\tan B}}
\] |
associate-*r/ [=>]73.7 | \[ \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}}
\] |
*-rgt-identity [=>]73.7 | \[ \frac{1}{\sin B} - \frac{\color{blue}{x}}{\tan B}
\] |
Taylor expanded in x around inf 73.6%
Simplified73.6%
[Start]73.6 | \[ -1 \cdot \frac{\cos B \cdot x}{\sin B}
\] |
|---|---|
mul-1-neg [=>]73.6 | \[ \color{blue}{-\frac{\cos B \cdot x}{\sin B}}
\] |
associate-*r/ [<=]73.6 | \[ -\color{blue}{\cos B \cdot \frac{x}{\sin B}}
\] |
distribute-rgt-neg-in [=>]73.6 | \[ \color{blue}{\cos B \cdot \left(-\frac{x}{\sin B}\right)}
\] |
distribute-neg-frac [=>]73.6 | \[ \cos B \cdot \color{blue}{\frac{-x}{\sin B}}
\] |
Taylor expanded in B around inf 73.6%
Simplified73.6%
[Start]73.6 | \[ -1 \cdot \frac{\cos B \cdot x}{\sin B}
\] |
|---|---|
associate-*r/ [=>]73.6 | \[ \color{blue}{\frac{-1 \cdot \left(\cos B \cdot x\right)}{\sin B}}
\] |
*-commutative [=>]73.6 | \[ \frac{-1 \cdot \color{blue}{\left(x \cdot \cos B\right)}}{\sin B}
\] |
associate-*r* [=>]73.6 | \[ \frac{\color{blue}{\left(-1 \cdot x\right) \cdot \cos B}}{\sin B}
\] |
neg-mul-1 [<=]73.6 | \[ \frac{\color{blue}{\left(-x\right)} \cdot \cos B}{\sin B}
\] |
Applied egg-rr73.7%
[Start]73.6 | \[ \frac{\left(-x\right) \cdot \cos B}{\sin B}
\] |
|---|---|
associate-/l* [=>]73.6 | \[ \color{blue}{\frac{-x}{\frac{\sin B}{\cos B}}}
\] |
neg-sub0 [=>]73.6 | \[ \frac{\color{blue}{0 - x}}{\frac{\sin B}{\cos B}}
\] |
div-sub [=>]73.6 | \[ \color{blue}{\frac{0}{\frac{\sin B}{\cos B}} - \frac{x}{\frac{\sin B}{\cos B}}}
\] |
quot-tan [=>]73.6 | \[ \frac{0}{\color{blue}{\tan B}} - \frac{x}{\frac{\sin B}{\cos B}}
\] |
quot-tan [=>]73.7 | \[ \frac{0}{\tan B} - \frac{x}{\color{blue}{\tan B}}
\] |
Simplified73.7%
[Start]73.7 | \[ \frac{0}{\tan B} - \frac{x}{\tan B}
\] |
|---|---|
div-sub [<=]73.7 | \[ \color{blue}{\frac{0 - x}{\tan B}}
\] |
neg-sub0 [<=]73.7 | \[ \frac{\color{blue}{-x}}{\tan B}
\] |
if -4e14 < x < 6.1999999999999997e-27Initial program 99.8%
Simplified99.8%
[Start]99.8 | \[ \left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}
\] |
|---|---|
+-commutative [=>]99.8 | \[ \color{blue}{\frac{1}{\sin B} + \left(-x \cdot \frac{1}{\tan B}\right)}
\] |
unsub-neg [=>]99.8 | \[ \color{blue}{\frac{1}{\sin B} - x \cdot \frac{1}{\tan B}}
\] |
associate-*r/ [=>]99.8 | \[ \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}}
\] |
*-rgt-identity [=>]99.8 | \[ \frac{1}{\sin B} - \frac{\color{blue}{x}}{\tan B}
\] |
Taylor expanded in B around 0 98.2%
if 6.1999999999999997e-27 < x Initial program 75.3%
Simplified75.4%
[Start]75.3 | \[ \left(-x \cdot \frac{1}{\tan B}\right) + \frac{1}{\sin B}
\] |
|---|---|
+-commutative [=>]75.3 | \[ \color{blue}{\frac{1}{\sin B} + \left(-x \cdot \frac{1}{\tan B}\right)}
\] |
unsub-neg [=>]75.3 | \[ \color{blue}{\frac{1}{\sin B} - x \cdot \frac{1}{\tan B}}
\] |
associate-*r/ [=>]75.4 | \[ \frac{1}{\sin B} - \color{blue}{\frac{x \cdot 1}{\tan B}}
\] |
*-rgt-identity [=>]75.4 | \[ \frac{1}{\sin B} - \frac{\color{blue}{x}}{\tan B}
\] |
Applied egg-rr50.6%
[Start]75.4 | \[ \frac{1}{\sin B} - \frac{x}{\tan B}
\] |
|---|---|
log1p-expm1-u [=>]50.6 | \[ \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\sin B}\right)\right)} - \frac{x}{\tan B}
\] |
Taylor expanded in B around 0 71.2%
Final simplification85.0%
| Alternative 1 | |
|---|---|
| Accuracy | 87.0% |
| Cost | 13248 |
| Alternative 2 | |
|---|---|
| Accuracy | 85.1% |
| Cost | 7113 |
| Alternative 3 | |
|---|---|
| Accuracy | 85.0% |
| Cost | 6921 |
| Alternative 4 | |
|---|---|
| Accuracy | 61.2% |
| Cost | 6856 |
| Alternative 5 | |
|---|---|
| Accuracy | 38.2% |
| Cost | 576 |
| Alternative 6 | |
|---|---|
| Accuracy | 36.6% |
| Cost | 521 |
| Alternative 7 | |
|---|---|
| Accuracy | 38.0% |
| Cost | 320 |
| Alternative 8 | |
|---|---|
| Accuracy | 26.2% |
| Cost | 192 |
herbie shell --seed 2023153
(FPCore (B x)
:name "VandenBroeck and Keller, Equation (24)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (/ 1.0 (sin B))))