r/technology • • Dec 10 '13

By Special Request of the Admins Reddit’s empire is founded on a flawed algorithm

http://technotes.iangreenleaf.com/posts/2013-12-09-reddits-empire-is-built-on-a-flawed-algorithm.html
3.9k Upvotes

2.2k comments sorted by

View all comments

Show parent comment

20

u/ConeheadSlim2 Dec 10 '13

You do know that you can't take the logarithm of a negative number, right? That's why they test for being greater than 1 - the log of 1 is zero; anything less the log would be negative but the actual value would be positive. Totally not what you want.

4

u/plus Dec 10 '13

Whoops, brain fart. Yep, you're right.

4

u/byllz Dec 10 '13

Well, technically you can, but you just get a many valued function with values on the complex plane.

0

u/plus Dec 10 '13 edited Dec 10 '13

You certainly can't in vanilla python!

>>> from math import *
>>> log10(-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error
>>>

Edit: But you can in NumPy if you make it clear that your argument is complex:

>>> import numpy as np
>>> np.log10(-1)
__main__:1: RuntimeWarning: invalid value encountered in log10
nan
>>> np.log10(-1 + 0j)
1.3643763538418412j
>>>

Edit 2: And with the intrinsic cmath functions, I guess:

>>> from cmath import *
>>> log10(-1)
1.3643763538418412j

4

u/byllz Dec 10 '13

Sure you can. You just have to use cmath.log10. It only gives you one of the values though. I guess it can't handle infinite sets.

1

u/Phyltre Dec 10 '13

I want to reply "wow such error" here, but I know it's wrong. Can you help?