# Is it legal to publish the code of a published algorithm?

Let's say I want to implement an algorithm based on a paper or book and publish it under a non-proprietary but not necessarily non-commercial-friendly license (e.g. on a blog).

Is it legal to do this?

I know that a general all covering answer cannot be either yes or no, so I want to know additionally how to find out quickly whether this is legal or not. Some examples would be great. Here are some examples for discussion

• Apache Commons Math stated in their developer guide, that all developers should check for license issues before committing and link to Numerical Recipes as an example. This is the first time ever I saw such a warning. I do not have access to this book (neither online nor in dead-tree-format). What does the legal warning looks like ?
• Papers linked for download on the page of the author normally do not contain a legal warning. Does it mean that the algorithms are ... free?
• According to wikipedia, Random Forest is a trademarked term. Does that mean, that noone is allowed to implement this algorithm ? One can give it another name (like Good-Luck-Forests), since reproducing the exact algorithm given that not all details are published in paper (normally) is nearly impossible.
• What about papers where the access is both restricted and not. See for example the paper "Alternatives to the Median Absolute Deviation", which has been published in the Journal of the American Statistical Association, but which can be bought now via JSTOR or be downloaded from this page. Did Frank Masci, the uploader of this paper, break the law?

A lot of papers with or without restricted access can be found online.

Disclaimer: No answer should be treated as legal advice one can refer to before court.

-
I don't know about the exact law on that matter but. In science, most of the time you rely on other publications. When it comes to your result you are free to publish in your medium of choice. AFAIR you want to write your own implementation, not copy&paste. Of course a citation is needed, otherwise it is a plagiarism or an intellectual dishonesty. – Piotr Migdal Nov 2 '11 at 14:18
@Piotr Citation is mandatory! I certainly respect the authors' work and do not want to rip them off. Hence the question ... – steffen Nov 2 '11 at 14:32
@steffan: As it is published in a book/journal, I wouldn't bother and just put my own implementation on my website (unless it is protected by a patent). I guess the journal status (i.e. Restricted/Open Access) has a little to do with the issue. On a separate issue - sometimes journals allow you to publish a copy on your website. If not, usually people still do it, with a benefit for the society. – Piotr Migdal Nov 2 '11 at 14:47
I believe this question belongs on SO, although it might be of interest for this community too. The reason is that it doesn't have to do with data analysis or the use of a computer to answer a statistical question, as described in our FAQ. – chl Nov 2 '11 at 18:29
The question itself is marginal because it does refer to statistical matters (although they don't seem to add anything, IMHO). The answers it's getting, though, send a signal that the entire thread may be off topic. It would be nice to have some community opinions about this. (For people with sufficient reputation, your votes to close would speak loudly.) – whuber Nov 3 '11 at 4:30

As mentioned by the OP, this is probably not the right place for expert advice on legal issues, but we all have to live with such things as software licenses and try not to get into trouble, so here are a few things that I have learned.

• On the NR homepage you can find the license information and information on redistribution. This is solely a copyright issue regarding the source code provided in the books. The algorithms themselves are not copyrighted, and to my understanding you can't get into trouble by implementing and sharing an algorithm that happens to be in NR unless your implementation is derived from the source code distributed with NR.
• Hmm, nothing is free ... There is almost always a copyright holder. If the paper is published, the copyright may be transferred to the journal, but in some cases the author retain the right to distribute the paper via his or her homepage, say. Patent law is a completely different ball game, but I actually don't know of any examples related to statistical and machine learning algorithms where a patent protection of the algorithm was a problem. Hence, to me, the most important aspect regarding algorithms in papers, whether published in journals or on the authors homepage, is not to violate the copyright.
• A trademark is a third thing. To my understanding it protects only the name or symbol. So you just can't implement a program and call it "Random Forests", but you can implement and distribute the random forest algorithm.
• I have no idea if Frank Masci broke the law, but it is a copyright issue as I see it. Who holds the copyright and which rights did the copyright holder give to others?

From my point of view, though violations of patent rights might be serious, the more important issue for the average statistician is that of copyright. If you implement an algorithm from a paper from scratch and cite the paper I don't see any obvious problem with distributing the implementation regardless of the media. But you might think about what is the best way for you to use your copyright on the implementation. I don't know anything about how blogs are generally copyrighted, but if the copyright is transferred to the blog owner automatically, it might, in principle, be a bad idea to post hours of valuable implementations on a blog and thereby effectively give up the copyright of the work to somebody else.

If you, on the other hand, modify an existing implementation, you could run into problems with the copyright license. If the license for the original implementation is GPL, the license for the redistribution has to be GPL. Hence, you have to distribute in a way so that the distribution can be under GPL. This works the other way too. If you want to distribute an implementation under GPL but have to rely on a library that is not distributed under the GNU license, then you might not be able to include the library in your distribution $-$ even if the library is open source and "free". The library might be distributed under a copyright license that is incompatible with GPL.

-
 +1 Many good points here. Regarding specific algorithms, I'd add that I've encountered uncertainty regarding C4.5 and C5.0. I don't use either of them, but I remember encountering (many years ago) people who had concerns about whether they could re-implement the algorithms. – Iterator Nov 2 '11 at 21:54 @Iterator, thanks for giving this example. Maybe I should also point out that my real life takes place in a jurisdiction where software patents are essentially non-existing. – NRH Nov 2 '11 at 22:19 Whoa, is that feasible? Are there places that lawyers cannot reach? A place that has internet access but no software patents. How did that happen? :) – Iterator Nov 2 '11 at 22:54 @Iterator, the European patent law is not at liberal as the US patent law regarding software patents, and the individual countries in Europe have individual laws too. If I am distributing software from my homepage I can be pretty sure that I am not violating any local laws where the server is placed. I don't know how it works internationally, though. – NRH Nov 3 '11 at 7:27

The classic example of a patented algorithm is RSA, by the way. Rules for patents of algorithms are rather nebulous and changing quite a bit. In practice, implementations are okay, but distribution (including commercialization and free release) is where one tends to run afoul of things. What's more, release can be constrained, regardless of patent and copyright - Americans cannot export source code for cryptographic algorithms to certain prohibited countries, for instance, and the same may be true of many other countries.

A distinction has to be made between copyright and patents. Copyright is unlikely to affect you, and I believe the primary thing to consider is whether or not a patent may apply (and it need not be patented already: some countries allow some time after disclosure for the innovator to patent their work). Copyrights tend to affect distribution rights of original materials (so, you can't just republish an article - the journal or the author owns the copyright), patents affect distribution of the implementation of the idea. If there's no patent and the time for patenting has elapsed, then you should be good to go.

I'd said that patents are nebulous: in some jurisdictions it isn't all that easy to patent algorithms. In some it is, but the laws and interpretations of those laws are changing.

I hope this helps in focusing your analysis. I wouldn't worry about the case-by-case approach (e.g. is it published in this type of journal or that type), and instead focus on who holds the patent rights and how are they exercising those rights.

It's also courteous to talk with the original innovator. If they intend to patent or they want to collaborate, you are better off working with them. They can help suggest ideas for implementations and they may encourage others to use your implementation as a reference.

-

My understanding is that publication disqualifies an invention for patenting. Thus any algorithm that has been published can be used freely. That does not apply to the code itself! If you learn the algorithm, understand it, teach it to another person without ever letting them see the code in the original, and they implement it, it is completely unencumbered. That's the gold standard of clean room implementation (used for legally safe reverse engineering), but if you read the paper and write your own version, you're probably fine.

-