perimosocordiae / bigO

Symbolic representation of big-O notation
MIT License
9 stars 2 forks source link

Support basic arithmetic operators #3

Closed treyhunner closed 9 years ago

treyhunner commented 9 years ago
# this works
O(n).inside(O(n**2)).followed_by(O(sympy.sqrt(n))) == O(n**3)

# it would be great if this worked
O(n) * O(n**2) + O(sympy.sqrt(n)) == O(n**3)
perimosocordiae commented 9 years ago

I agree that your proposed API makes sense and looks clean.

Would you like to submit a PR with the necessary changes and a test case? If not, I'll look into it myself.

asmeurer commented 9 years ago

FYI SymPy supports expansion at infinity now:

In [45]: O(n, (n, oo)) * O(n**2, (n, oo)) + O(sqrt(n), (n, oo))
Out[45]:
 ⎛ 3       ⎞
O⎝n ; n → ∞⎠
treyhunner commented 9 years ago

@perimosocordiae I probably won't implement this myself. I won't have a need for bigO for a few weeks if I end up needing it.

You could implement this by implementing an __add__ and __mul__ method.

perimosocordiae commented 9 years ago

Done. Thanks for the suggestion, @treyhunner.

@asmeurer: Looks like that was added only a few months after I made this package, but I didn't know about it until now. Thanks for pointing it out! I'll add a note to the readme.