1

Is the capability of every programming language the same since it is eventually translated into machine code. Python, Java etc. are all together instructions the CPU is going to process. So, you could (theoretically) do the exact same thing with ever language, don't you?

Raphael
  • 73,212
  • 30
  • 182
  • 400
BeldCode
  • 15
  • 3

2 Answers2

7

The answer to the question depends on what you mean by "the same".

It is a famous result of computability theory that many reasonable models of computation all calculate the same nubmber-theoretic functions. That is, all reasonable general-purpose programming languages compute the same partial functions $\mathbb{N} \to \mathbb{N}$. So in this sense the capabilities of all programming languages are "the same". By the way, this is not the Church-Turing thesis, contrary to what you may be told.

However, a programming language can do many other things in addition to computing with numbers. For instance, it may access external devices, run parallel programs etc. While these features do not allow it to compute any extra number-theoretic functions, they may make a difference when it comes to computing other functions. For instance, a famous early example is that of the language PCF. It can simulate Turing machines, but it cannot compute the "parallel or" function, while its parallel variant PCF++ can.

When we look at higher-order functions languages differ in their capabilities. A purely functional language such as Haskell cannot compute the modulus of continuity but a functional language extended with local state can.

So it really depends on what you mean by "the same".

Andrej Bauer
  • 31,657
  • 1
  • 75
  • 121
-1

Yes, that's correct.

The usual justification for the computational equivalence of two programming languages X and Y is that we can write an interpreter runX for X programs written in the Y language, and vice versa.

Therefore, any program y written in Y can be simulated in language X using something like runX("y"), and vice versa. So, the computational power of the two languages is the same.

Sometimes, we state these fact stating "all programming languages are Turing-equivalent", i.e. that they can compute anything that a Turing machine can compute (and nothing else).

Note that this does not mean that the two languages have the same features. For instance, X might feature OOP classes, while Y might be purely procedural. X might have primitives for 3D graphics, while Y has not. X might allow access to files, Y might not. X might have garbage collection, when Y has not. X might be a functional (or logic) language, while Y is imperative. X might feature higher order functions, or dependent types, etc. which Y does not have. When we say that they have the "same power", here we only mean that they can compute the same set of functions (say, mapping an input strings to an output string).

Finally, note that there do exist some computer languages which are less powerful than general purpose programming languages like Python, Java, and the like. These are not usually called programming languages, even if they might share some aspects. For instance, the Bitcoin scripting language allows some limited computation, but has no loops (e.g. while), so it drastically restricts the algorithms one can implement. The basic querying part of SQL (select) is a simple reporting language, and is not Turing powerful (unless one adds triggers / stored procedures or other more advanced features.).

chi
  • 14,704
  • 1
  • 31
  • 40