Search code examples
mathlanguage-agnosticprogramming-languagessymbolic-math

Is there a difference between mathematical statements and programming statements?


This might be a very funny question for you all, but I am curious to know the answer :

i=10
i=i+1
i=i+1
i=i+1
i=?

what will be the final value of i in terms of pure mathematics and what will be the final value of i in terms of any programming language. I think I am thinking only in the programming way. I know in programming languages the value will be 13 but I am confused about the mathematical value.

So experts please tell me if there is any difference between pure mathematical and programming statements.What will be value of i in mathematics at last line?


Solution

  • i=10
    i=i+1
    i=i+1
    i=i+1

    In mathematics, A=B is not an assignment of the value of B to A. It instead expresses an identity. The expression i=i+1 just doesn't make sense mathematically. One exception is boolean algebra, where 0+0=0 and 0+1=1+0=1+1=1. But then the initial identity i=10 doesn't make any sense.

    The expression i=i+1 is illegal in languages such as Haskell that try to be closest to mathematics. Objects are normally immutable in Haskell and other pure functional languages.