-1

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?

Anonymous
  • 1,726
  • 4
  • 22
  • 47
  • Mathematics is the way of reasoning, not any particular notation or field. If you do it the right way, code is mathematics. You cannot contrast programming and mathematics, only programming and some specific well-defined branch of mathematics. You didn't name one, so your question makes no sense. – n. m. could be an AI Dec 26 '14 at 10:33
  • Not all programming languages use `=` for assignment. For example, Pascal uses `=` for comparison and `:=` for assignment. – svick Dec 26 '14 at 17:37

2 Answers2

2

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.

David Hammen
  • 32,454
  • 9
  • 60
  • 108
1

What changes usually is more the notations than the meaning.

When you write =, you mean an assignment of a variable. If I were to read that symbol written on a piece of paper, I would tend to treat it as == (in a typical C-like language). Assignment would be written with an arrow going left, something like i <- i + 1 in some fields of mathematics, and the notion wouldn't make sense at all in some others.

Reading your lines of code as if they were some random math statements would lead me to the fact that you write the same equation several times, and that we operate modulo 1 (since I read i == i+1), but also that i = ? = 10 = 0, that is that all these symbols have the same value of 0 modulo 1.

If conversely I were to express in "typical math speak" what you wrote -- if I understand it as code -- you would have something like :

Solve i, where i=1+ ( 1+ ( 1+ ( 10 ) ) )

Which is a bit trivial. The reason I write it like this, is that it is not common to use the same variable for different values within a same problem. I could also use different names :

Solve i, where i=1+j, j=1+k, k=1+m and m=10

svick
  • 236,525
  • 50
  • 385
  • 514
Cimbali
  • 11,012
  • 1
  • 39
  • 68