Skip to main content

Programming Enlightenment through Wolfram language

I have walked the path of programming and computers for many years and I have come to some very deep revelations about the core structure of computation most of which I had encoded in my book on programming available on Amazon. But what I want to talk about today is about the enlightenment that comes to those who know how to program in the Wolfram Language.

Just like Zen enlightenment, it is a subtle experience and thus very hard to describe to the unenlightened. To give a slight hint as to how this experience executes in the brain of the enlightened to the unenlightened will be like describing the nature of an apple to someone without senses.

The best I can do to describe this experience is to say its a little like floating in the clouds above a cityscape or having access to an infinite length lever that can lift anything with only the slightest application of effort.

The description above is the best I can do the explain an experience that is hard to put in words without saying stuff bluntly. If I were to say things bluntly and without modesty, I would simply say programming in Wolfram language makes you a superior programmer. Even if you spend a year with this language before returning to your mundane language, it will give you an experience that will transfer to your programming activities in other languages.

Transfer learning is all the buzz these days. To put it briefly for all the non-ML practitioners out there, transfer learning is when you train a neural network on some task, and then take portions of the resulting net, freeze it, attach some extra layers and train it on some new dataset and use the total net to perform inference.

One major reason we use transfer learning is when the new dataset is small so we use a trained net to augment our new net so that even with little data it could train well and produce good results. Another reason is to use the old net trained to do one task to do a new task that the old net was not designed for.

Transfer learning in human terms refers to a situation when you learn something and then what you learn can make learning another thing easier because of the internal structures you have obtained from the old knowledge.

When you spend time with the Wolfram Language, the overarching view of computation you will gain will transfer to your other programming activities in other languages and make you a better programmer for life. A caveat is that you might never want to program in another language once you have experienced programming in Wolfram language.

The Enlightenment experience is that overarching view of everything that puts you above everything. Making you see the connections between things and the true depth of things. It is not some blissful emptiness as is described by many people but some kind of power that puts everything in perspective.

It is the experience of the interconnectedness of everything that gives you unlimited leverage. Computing itself is one of our longest levers, enabling us to achieve more than we could ever achieve through naive labour alone.

Computing is the lever the mind uses to deal with the low-level details that seem to cloud its view of higher understanding. While in other languages, programming seems to be some kind of hard labour because of how distant the programming model is from the natural internal representation of the human mind, the Wolfram language fits in the exact mental representation that is closest to how a rigorous mind models problems and solution.

The Wolfram Language is the ultimate lever of the mind, freeing you from worrying about the details and focusing on the highest level of abstraction possible so that you spend more time working of issues of problem-solving and less on issues of problem representation.

One might say, if we are working on a very high level of abstraction then we should be facing the same performance bottleneck like we have with python, but this is not the case. While python spends most of its time transferring its internal representation to the representation of C, Wolfram language in many cases goes down to machine code without passing through the intermediate levels.

This post is not about the technical details of how Wolfram language gains its speed, it's about how Wolfram language enables you to gain speed in expressing the solution to your problems.

This post became important to write as I delved back into my primitive programming days with python. I had to start working in python to take advantage of the Google Colab platform which offers free GPU and TPU time for doing machine learning work.

It was not an easy downgrade for me to go back to python after working in strictly Wolfram language for some years. I had gotten used to elegance and going back to python way of doing things was a very painful experience.

What increased my pain is that to access those free Google resources, I had to write code in python. I could bear the agony of just reading code in python because I am an AI researcher and have to keep track of other people's work, and most of them wrote code in python. But the thought of actually doing something like: for i in range(5): ... was the most agonizing experience.

I had to will myself into writing python code and I was surprised at how clumsy it is.

The defining theme of my programming career is the efficiency of human time! I learnt C, C++ which are supposed to be the fastest languages but I realized they were fast for the computer to execute but not fast for the human mind to think in. The reason is that there is so much you have to help the computer do so that it could solve your problem. You had to think in terms of the details of the computer and not in terms of how naturally your own mind world think of the problem.

If your problem was sophisticated enough, then you would have to build enough abstraction away from the computer and towards your problem domain to enable you to express your solution. Details of memory management would also come to bite you in the back if you didn't think of it properly. You spend a huge amount of time fixing the limitation of the programming language paradigm.

Java came to help with that which C++ did poorly with objects! Objects were thought of as natural for the human mind to think in. Object-oriented programming posits that to express a program we are better off thinking in terms of objects, which are these things that bundle data and functionality (methods) together.

Object-oriented programming in Java was clearer than what was available in C++ to most programmers and so Java took over the world. Then came python, promising flexibility to the hard stiff view of Java. While Java forced you to do everything in an object-oriented way python allowed you to think in any paradigm you wanted. you could do object-oriented stuff or you could do functional stuff. I fell for python because it was the most flexible and efficient for the human mind but it was slow and therefore inefficient for the computer to execute because of the levels of interpretation that have to be traversed.

Despite the mental flexibility python offers and ignoring the speed of execution on the computer, there is still a fundamental flaw deep in the philosophy upon which it is built. If you are new to programming and you learn python, you will think that it is the only way to write code in and if you go to other languages like C, C++ and Java you will find it very uncomfortable to switch your mental mode due to the convenience you have experienced in python.

But what if I told you that even as good as python is, it still is not near elegant. This is because python like the other programming languages I have mentioned above was built on a patch-work-like philosophy of programming and does not encapsulate the core ideas of computing properly.

Even Java that tries to come clean with strict object-oriented programming still comes short when it comes to expressing computation in a pure elegant fashion.

Object-oriented programming as a philosophy sounds very enticing and philosophical. When you are getting in on something like Java, the examples that you see in object-oriented programming like Superclass Automobile and subclass Audi, might seem to make much sense at first but like in all things in life, if the seed is of low quality the resulting crop will reciprocate, although it is hard to see how bad a seed is until it grows.

Same goes in programming. A bad philosophy will result in bad consequences later on. And even though the seedling might look promising when describing simple cases of object-oriented programming, in large software systems the problems of the bad seed will start showing itself as complicated class hierarchies which exist for the sole purpose of project management and not for expressing the algorithms of a program.

Although many people say that object-oriented programming is suited for programming at large I actually think it bloats code and therefore the large code bases that it was invented to manage wouldn't have been vast at all if the code was compact and manageable in the first place.

There are many object-oriented programming bashing articles all over the internet and it is not my intention to go into that deeply in this post. My main task is to reveal that there is a kind of enlightenment that can only be obtained when one experiences a neat elegant language built of the fundamentals of computation like Wolfram language.

In my book, I go into the details of how most of what we call high-level languages were invented, even the idea of object-oriented programming, as a result of knee jerk reactions to the problems encountered in practical software engineering. Many language constructs like decision making and loops are not obvious at the lowest level of programming in machine language. They are patterns that occurred often enough in low-level programming that when we decided to build high-level languages we simply just made these patterns into constructs that saved us typing time.

But the core nature of computation is independent of the conveniences of any programming language construct. Apart from implementing computation on any specific hardware, you could describe general abstract operations that could, in reality, perform any kind of computation. The rule-rewrite paradigm of computation is the foundation upon which the Wolfram language is built and because of its fundamental nature, it is easier and much more elegant to express computation in the Wolfram language than it is in languages that were built as a result of knee jerk reactions to problems encountered in practical software engineering.

So rather than wait to discover recurring patterns in a large number of programming scenarios and then build languages with constructs that automate them, the Wolfram language builds from first principles enabling the programmer to rapidly design solutions in an almost intuitive fashion.

The Wolfram language is so close to the way humans think of computation that it is the only reasonable language to do symbolic math in, remember that math is the most fundamental rigorous language invented by humans to deal with problems.

To do math directly in other programming languages will result in so many absurd constructions, this is because you have to build away from the language sufficiently so as to enable the expression of math.

Due to the symbolic nature of the Wolfram language, you could just do math directly in it with very little extra abstraction supplied on your side.

                                                                 *   *   *
As I delved into python for deep-learning on Colab purposes, and after experiencing building and training neural networks in Wolfram language, I was heartbroken at the experience. Let me list a few of the problems I encountered for clarity.

1. Too much hackery to get machine learning to work: Although the Keras functional API has done a lot recently to simplify the building and training of neural networks, it still suffers from the fact that it is built in python and inherits many of the problems inherent in those kinds of languages.

When you are solving a problem in Wolfram language, you deal with things using a unified mental model. Easy things are super easy, hard things are easy. When using a traditional programming language, ones you go a little bit above what the language designers expect, you start facing a lot of scenarios where you have to literally hack yourself out of jungles of confusion. Although many people who have not seen the light will say this is programming and programming by its nature is hard if you have been enlightened by exposure to the Wolfram language you will realize that this is unnecessary labour.

Hardship is not really necessary that is why humans invented labour saving devices. If you enjoy hard labour for one reason or the other then you can continue toiling but if you want to get stuff done so that your time and energy is focused somewhere else then you can start thinking about how to use your energy to invent labour saving devices.

In the world of programming and especially when doing something as abstract as machine learning, you need a language that is built on powerful fundamentals so that when you want to express your idea you build them up from solid primitives and not twist and hack the language to help you do your stuff.

Cleaning up data in python requires too many non-standard stuff applied in a non-standard way. Although Keras helps a lot with preprocessing, in Wolfram language there are very powerful inbuilt primitives that enable you to clean up data using standard language interfaces. I can't explain more you will have to experience this personally to understand what I am talking about and maybe later I will share a post on how elegant this is.

2. Too much memorisation: When you learn Wolfram language, you learn standard ways of doing things through standard interfaces. As you use the language to solve your problems especially something like machine learning, you simply need to apply these standard interfaces to the new problem in a direct way. You don't need a special API to start building a computational graph for a neural network, the standard graph building interface will generalize into neural nets of any flavour. Need some layer like Batch normalization? it is available directly as a function somewhere in the language itself and you don't import any libraries and obey any convention to use it. Call the function and pass in the arguments that satisfy the interface and there you have some arbitrary usage of a Neural Network layer. With traditional programming language based systems, you will have to memorize so many new conventions that are not needed in normal programming but are only used in machine learning because they were upward-engineered from the language to model the neural network environment.

As things change with the APIs you will have to memorise the new way of doing things, which will still change in the future because things are built through non-standard interfaces in a knee jerk manner in reaction to problems. With Wolfram language, any new problem domain is handled with language primitives enabling you to use your mental resources to conquer new problems rather than memorising the latest hackery.

3. Weak Visualization system: If there is a single most important thing I could try to sell to you as a reason to use Wolfram language, it would be the visualization system. It is the most sophisticated visualization system in the world of publicly assessible software. There could be better systems caged up in private organizations or DARPA, but of course, you can't get access to them at any price. If you are looking for the most sophisticated and easy to use visualization system then I advise that you use the Wolfram language system available in any Wolfram Desktop or cloud.

The visualization system blows Matplotlib out of the water and there are no quirky hacky interfaces that you need to master to use the system efficiently. It is straight forward visualization included in the core of the language and is available from a single function call in most cases.

I could go on an on but this is not a book, it is a blog post and we can as well go on to other things

                                                                        *   *   *

In conclusion, with any traditional programming language, you can solve any problem that can be cast in computational terms. Python is the most popular programming language used to do things like machine learning these days and also a language in which most introductory computer science is taught.

But Python is limited despite its good intentions. Wolfram language is a far more superior language for doing any computation and is a better language for introducing computer science because of its compact nature allows you to express many powerful programs in very few lines of code. Python on the other hand and in general other traditional programming languages might appear simple when dealing with toy programs but as the programming requirements grow in highly abstract disciplines like machine learning the languages become unwiedly to use due to the difficulty of building from primitive language construct right up to the high of abstraction needed to express this domain.

After my sojourn on the mountain of programming enlightenment with Wolfram language and as I descend to the valley of traditional programming languages like Python, my vision is clearer. On encountering a problem that needs to be expressed in Python due to the requirements of the environment I am auditing, I realize that my code is clearer, explicit and more expressive.

A side effect of spending so much time with Wolfram language is that I tend to use the more elegant structures in Python like List comprehensions and try my best to stay away from anything that involves manually manipulating indices.

With Wolfram language in its 12th version, you have access to one of the most powerful computational tools on earth. Why don't you delve straight in with this free book created by the CEO of the Company himself, Stephen Wolfram, and also the author of the Wolfram Language.


Popular posts from this blog

Next Steps Towards Strong Artificial Intelligence

What is Intelligence? Pathways to Synthetic Intelligence If you follow current AI Research then it will be apparent to you that AI research, the deep learning type has stalled! This does not mean that new areas of application for existing techniques are not appearing but that the fundamentals have been solved and things have become pretty standardized.

How to become an AI researcher

Artificial Intelligence is all the rage these days. Everyone is getting on the bandwagon but there seems to be a shortage of AI researchers everywhere these days. Although many people are talking about doing AI not many people are actually doing AI research.