| | abdullahkhalids on Dec 30, 2022 | parent | context | favorite | on: Why I'm still using Python
I now use python, but Python is not even half the language Mathematica is for scientific computing. If only Mathematica was free, I think it would become the defacto language for scientists. The most important feature of Mathematica is that it is functional and not object-oriented. Mathematics is functional, not object-oriented. So thinking in Mathematica is as easy as thinking in maths. Thinking in python is to force yourself to think in an unnatural way. | | | cycomanic on Dec 30, 2022 | next [–]
I think you're regarding Mathematica from a purely "theory/analytics" point of view, however I think you're missing the fact for a lot of scientific computing you want to interact with other things apart from numerics/analytics etc.. I believe that is really where Python shines and why it's also eating Matlab's lunch (more so than Mathematica's). It's incredibly easy to write a gui to interface with e.g. a scientific instrument do some reasonably fast analytics with numpy and possibly even produce publication ready plots. This is not really possible with Mathematica and while you can do this in Matlab, you need several toolboxes which are expensive, but more over are of extremely varying quality (let's not even talk about the horror of writing GUIs in Matlab). With Python, you have all of that for free, with a single tool (remember most scientists don't want to learn lots of programming languages). | | | | bee_rider on Dec 31, 2022 | parent | next [–]
Octave/matlab is a little more enjoyable to use for matrix stuff in the REPL though. The game of “is this in Numpy or Scipy and why won’t it autocomplete” is kind of annoying, IMO. On the other hand, the non-mathematical functionality of Python of course is much better developed! | | | | analog31 on Dec 31, 2022 | prev | next [–]
I like Mathematica a lot, but a couple of issues limit its usefulness for me. First, I'm an experimental scientist, so a lot of programming is in the lab, automating experiments, running tests, etc. Makers of specialized software tend to choose their battles in terms of the application of their product, justifiably, but this means no single app is general purpose enough to serve me in the office, lab, and at home. Second, unless an organization is enlightened enough to approve a site license, specialized software tends to create a "silo" of people who can use it, and forces it to be used in a centralized fashion. With Python, I can literally install my tools on every computer that I touch -- in the office, multiple labs, at home, etc. It makes it more likely that a tool will be woven into "how I think." I can also share things and/or encourage others to try them out with minimal friction. Almost as easy as sharing an Excel spreadsheet within an organization that has purchased a site license. Free means free site license. The friction of approving a license also discourages people from learning a tool by just giving it a try on some trivial project, or taking it home. | | | | shanebellone on Dec 31, 2022 | parent | next [–]
This is great commentary. | | | | prpl on Dec 31, 2022 | prev | next [–]
Mathematica (and matlab for that matter) is effectively free at most national labs, and it’s still a tiny market share. That’s because scientific computing is rarely just scientists, but often includes engineers, SWEs, system admins, theorists, grad students, and more, solving lots of problems. If you can’t get wide adoption at a national lab, where are you going to get it? Similar problem with Julia and Fortran even. They all have their niches and are great at certain problems, but Python (and C/C++) rule the overall landscape. in HEP, for example, it’s even the case that a full batteries-included C++ environment (ROOT) has slowly given way to python. | | | | UniverseHacker on Dec 31, 2022 | parent | next [–]
I was amused to notice that the Google trends map for Fortran was essentially a map of the US national labs. | | | | pdonis on Dec 30, 2022 | prev | next [–]
> The most important feature of Mathematica is that it is functional and not object-oriented. Python has object-oriented features but there is nothing that requires you to use them; you certainly don't have to express every Python program in terms of classes and methods, the way you do in Java. Doing functional programming in Python is common. Is there a particular aspect of doing functional programming in Python that you find to be a roadblock? | | | | abdullahkhalids on Dec 30, 2022 | parent | next [–]
It's more of the fact that all popular scientific libraries in python are written in an object-oriented way. That kind of forces you to write your own code in an OO way. I am guilty of this as I am writing a library myself. But users have to use, say numpy, along with my library. It would be suboptimal to force the user to constantly switch between functional and OO, so now my library is OO. On the other hand, all the code I wrote in Mathematica during my PhD was functional, because it is just easier to write functional in Mathematica. | | | | pdonis on Dec 31, 2022 | root | parent | next [–]
> It's more of the fact that all popular scientific libraries in python are written in an object-oriented way. That kind of forces you to write your own code in an OO way. I'm not sure I see why. The object orientation in libraries like numpy or scipy is to provide the user with fast implementations of the kinds of mathematical objects they will need to do computations. But unless you are defining additional such objects in your own code, there's no reason why your own code needs to be object oriented. You can just write ordinary functional programs that use the mathematical objects the library provides. For example, say you are doing matrix computations. You are of course going to use the matrix objects provided by the library; but your own code shouldn't need to define any new matrix objects. Your own code can just be straightforward computations using the existing matrix objects in the library. | | | | v3ss0n on Jan 1, 2023 | root | parent | prev | next [–]
It doesn't matter how libraries are written, in py you can use in functional way. I don't get what do you mean by forcing you to code in OO? I Had used pandas, scikit-learn, numpy, pytorch in production and I had never wrote them in OO way. Are we from same universe? | | | | prepend on Dec 30, 2022 | prev | next [–]
> If only Mathematica was free, I think it would become the defacto language for scientists. Of course. It’s one of the few languages that I think are worth it. I’ve been waiting for Wolfram to open source it for 10 years as I can’t afford it, or really justify why my org should use it. | | | | ur-whale on Dec 31, 2022 | parent | next [–]
> I’ve been waiting for Wolfram to open source it for 10 years as I can’t afford it, Wolframscript is free (not guaranteed to stay that way, as it isn't Open Source, but free for now). It can AFAIK do pretty much all Mathematica can. Only part missing is the Mathematica IDE/GUI/Notebook which I personally dislike profoundly anyways. Best of all, since it's a batch tool, it can be integrated in a Makefile and/or data processing pipeline without that nasty GUI showing up at all. https://www.wolfram.com/wolframscript/ | | | | abdullahkhalids on Dec 31, 2022 | root | parent | next [–]
I believe this is only the language. Not the set of libraries that come with Mathematica. Without those, one cannot do a lot in terms of scientific computation. | | | | steve1977 on Dec 31, 2022 | prev | next [–]
I often like to compare Python and Mathematica to English and Latin. English is not really a beautiful language - it’s a wild mess of different influences, but it’s easy to get to a basic level of fluency as there are few rules (but many exceptions due to the many influences). And it’s in use by large parts of the world. On the other hand, Latin is beautiful and pure. It has more rules, but very few exceptions. You can also see how it influenced other languages (hello Jupyter notebooks…) But it’s simply not a very practical language today, as there are few people who use it. | | | | 411111111111111 on Dec 31, 2022 | parent | next [–]
> It has more rules, but very few exceptions. ... That we know about. It's a dead language, so the exceptions would've been lost to time as it hasn't been spoken in ages. Your point stands regardless, just felt like being nitpicky | | | | PeterisP on Dec 31, 2022 | prev | next [–]
I feel that choosing the language based on how close it is to thinking in maths is putting the cart behind the horse, because in all scientific and applied scientific code I've seen, the actual math models is something like 10-20% of the code, and the majority is all the data management and plumbing around that; so you should pick the language based on how easy and maintainable the majority of the code will be, which is not the 'mathy' part of it. | | | | klyrs on Dec 30, 2022 | prev | next [–]
> Mathematics is functional, not object-oriented. I beg to differ. If by "math" you mean arithmetic and calculus, then sure. Combinatorics, graph theory; probably most of discrete math is very much object-oriented. | | | | abdullahkhalids on Dec 30, 2022 | parent | next [–]
Consider a graph G, with vertices (a,b,...,z). Say, we want to find the shortest path between vertices a and m. A mathematician might write an algorithm called shortest_path(G, a, m) which might call the algorithm breadth_first_search(a) etc. Functions are called on objects to determine their properties. Or to modify them into other objects. This is what you see in math or theoretical CS papers. In python, in popular libraries, the above will be attained by something like G.shortest_path(a,b) which seems to imply as per OO that graph G has a property shortest_path. In mathematics we don't think like this. Because it prevents mathematical abstraction. An abstract algorithm, like say Eigenvalues can be applied to a matrix M or to a graph G. In a functional language, the user would just do Eigenvalue(M) or Eigenvalue(G) as needed. In python, these would be M.eigenvalues() and G.eigenvalues(), which makes them distinct. | | | | klyrs on Dec 30, 2022 | root | parent | next [–]
What you're saying is not true of the most popular graph package in Python (networkx). Graphs there are objects with attributes (edges, nodes, etc) and methods (add_edge, etc), but algorithms such as shortest paths are functions as you have called most natural: shortest_path(G, a, b) | | | | abdullahkhalids on Dec 31, 2022 | root | parent | next [–]
Well, I am glad that at least this library is being functional, rather than object oriented. I wish all the others did as well. | | | | klyrs on Dec 31, 2022 | root | parent | next [–]
It's still object-oriented, though. The graphs themselves are objects, which helps with ergonomics. There are also functions that operate on graphs, because the alternative would be to stuff perhaps thousands of methods into the graph class -- which would be extremely annoying to maintain as well as abysmally slow. | | | | osigurdson on Dec 31, 2022 | root | parent | prev | next [–]
Since you capitalized it, it looks like a static method on the “G” class. There is nothing OO about static methods - this is purely and organizational construct. | | | | cft on Dec 31, 2022 | root | parent | prev | next [–]
I think it's the superclass A of both G and M that defines the eigenvalue() function. Then when both G(A) and M(A) inherit from A, it captures the mathematical relationship. The subclasses indeed should implement the eigenvalues computations differently, like in real mathematics. Funcional programming is used in Coq because it captures logical chains, for theorem PROOFS, but not for specific COMPUTATIONS, such as eigenvalues. | | | | abdullahkhalids on Dec 31, 2022 | root | parent | next [–]
I understand that this is possible. But this is not how mathematicians think. If you got together a bunch of mathematicians and asked to invent a programming language to do mathematics, they would never ever invent the concept of a class. Mathematics (outside of stuff like category theory etc) is simply sets and mappings between sets. Anything more complicated is forcing the user to think in a way that mathematics does not. | | | | klyrs on Dec 31, 2022 | root | parent | next [–]
> But this is not how mathematicians think. If you got together a bunch of mathematicians and asked to invent a programming language to do mathematics, they would never ever invent the concept of a class. Hi, mathematician here. Please read the source of SageMath: written by mathematicians, for mathematicians. Therein, you will find thousands of classes. Almost all computer algebra systems, written by mathematicians for mathematicians, have a notion of classes. > Mathematics (outside of stuff like category theory etc) is simply sets and mappings between sets. This is an extremely narrow-minded view of mathematics. Mathematicians thrive on abstraction, (category theory is literally mathematics; that's a very strange exception for you to carve out), and if we were to boil everything down to "simply sets and mappings between sets" then we'd be bogged down in utter tedium and nothing would ever get done. Object-oriented programming, specifically class hierarchies and inheritance, are extremely valuable for doing all sorts of math at high levels of abstraction. Hell. If I were to be especially pedantic, I'd point out that category theory itself is "simply sets and mappings between sets" except that sets aren't quite large enough so it's actually "categories and mapping between categories". | | | | CuriouslyC on Dec 31, 2022 | root | parent | prev | next [–]
Since the eigen decomposition is specifically a property of the matrix representation of the graph, but other things like shortest path distance between two nodes are naturally enough computed on graphs formed by objects with pointers, perhaps the correct interface is G.adjacency_matrix().eigenvalues(). | | | | agumonkey on Dec 31, 2022 | parent | prev | next [–]
object orientation here means boxing side effects behind methods, math doesn't seem to bother with implicit mutable state | | | | weakfortress on Dec 31, 2022 | parent | prev | next [–]
"Most discrete math is object oriented" ...what? | | | | klyrs on Dec 31, 2022 | root | parent | next [–]
There are a lot of hierarchies in the families of objects that discrete mathematicians are interested in. Inheritance is extremely natural in such settings. | | | | Heston on Dec 30, 2022 | prev | next [–]
How does the speed of Mathematica compare to python or C? | | | | pharmakom on Dec 30, 2022 | prev [–]
There is Octave and Julia | | | | baq on Dec 30, 2022 | parent [–]
Mathematica is so much more it’s hard to even describe. It’s free on a raspberry pi, so if you have time and access to hardware, take a look. | | | | jrumbut on Dec 30, 2022 | root | parent [–]
I think the so much more/hard to even describe is sort of a problem? There is a lot to it, and in my experience it's a very long road to getting your first problem solved. There are a lot of very cool pieces but I want it to be something I can pull off the shelf once in a while and be productive rather than something that I need to be an expert in before I can get started. | | |