7
$\begingroup$

The concept of an integer data type is not equivalent to the math concept of the set of integers. For example, in many programming languages the expressions 3. and $2^{10^{10000}}$ are math integers but (for different reasons) are not an integer data type. This potentially creates confusion for students in the age range of 8-16 years old who may be learning both the math and CS concepts of integer at once. What are effective ways to have students experience the distinct concepts so they reinforce each other rather than create confusion?

$\endgroup$
4
  • $\begingroup$ could you please specify in which languages 3. is an integer? $\endgroup$
    – ItamarG3
    Commented Jul 1, 2017 at 17:32
  • $\begingroup$ In Python for example, 3. is float but is mathematically an integer $\endgroup$ Commented Jul 1, 2017 at 17:33
  • $\begingroup$ In math Integer and Real are infinite sets. int and float are vanishingly small (i.e. finite) subsets of those infinite sets. The language designer makes a choice about which values are most useful to the programmer. $\endgroup$
    – Buffy
    Commented Jul 1, 2017 at 19:26
  • 3
    $\begingroup$ Robert M. Pirsig said, "One geometry cannot be more true than another; it can only be more convenient. Geometry is not true, it is advantageous." $\endgroup$
    – user737
    Commented Jul 2, 2017 at 2:38

3 Answers 3

7
$\begingroup$

This might be an interesting way to do it, but here goes.

Give your students a blank sheet of paper. Have them write out "3". Then have them write out $2^{10^{1000}}$. Most will probably stare at you blankly. A few clever/sassy ones will just write out the exponential notation. Tell them that just as they write out numbers a little differently depending on size, the computer stores numbers a little differently depending on type.

If a number has a decimal point, it treats it differently from a number like 1 or 2, and it treats that differently from a really large number and it treats all of these differently from something like a string. This is the whole reason that you have to convert between types when you ask for a number as input() in python and then get a TypeError when you try to add it - instead you must add float(input()) or int(input()). It's the computer's way of making life easier for itself, just like we make lives easier for ourselves using exponential notation.

Also, by now hopefully they've realized that the world of math doesn't directly translate to some of its uses. Math is a very abstract thing, though it describes many things remarkably well. Pure math is very different from most math they've seen, and I think they understand the difference, for the same reason they understand the difference between x = x**2 and $x = x^2$. It's a different context, so it has a different meaning.

$\endgroup$
1
  • 1
    $\begingroup$ @nocomprende, actually, the effects of words and meanings can be far more subtle than that. The words "YOU FLUNK THE COURSE," written on the board (even by a non-faculty prankster before class), would have a definite effect on the students. Practically everyone has some degree of irrational identification between the symbols for things and the things themselves. The first few paragraphs of this article come to mind. $\endgroup$
    – Wildcard
    Commented Jul 3, 2017 at 22:19
3
$\begingroup$

If your students are mathematically inclined, you could simply think of the variable type as a constraint on the value contained inside of it.

For example:

  • int represents $x \in \mathbb{Z}$ (and depending on your type's size, $-2^n \leq x < 2^n$ for a signed integer and $0 \leq x < 2^n$ for an unsigned integer)
  • The set of values that may be held by a float is a much larger set than $\mathbb{Z}$, but $\mathbb{Z}$ is a subset of the float set, which is why an integer can be stored in a float, but not vice versa.

In other words, if $\mathbb{F}$ is the set of values representable by a floating point number, $\mathbb{Z} \subseteq \mathbb{F}$ (the integers are a subset of the values represented by floats). Or, if you want an image to show:

Image of subset

Image by Booyabazooka of Wikipedia (public domain)

Whether this explanation is useful would depend on your students' proficiency with mathematics and set theory. For younger years, you could simply skip the subset discussion and show a Venn diagram to represent the idea that a float can be an integer, but an integer type can only represent an integernot all floats are whole numbers, but all whole numbers can be floats.

The issue of large integers not being represented by integers in some languages is more difficult to explain without stating the way that integers are stored. In many curricula, binary representation of integers is covered quite early, and if that's the case, explaining why int types can't hold extremely long integers is straightforward.

$\endgroup$
1
$\begingroup$

Show them how integers are actually represented in a computer. This has the benefit of also helping to explain integer underflow and overflow. In addition, it provides the opportunity later on to actually write a program that can convert from one number format to the other.

The two's complement system is not very difficult, and provides a good insight to some of the tricks that computers use to do basic operations. As a CS student, I think that these "go behind the scenes" opportunities help to generate a better appreciation for all the interesting problems students will encounter in the future in CS and Computer Engineering.

$\endgroup$
2
  • $\begingroup$ This. A computer is a machine. We don't need metaphors or math concepts, we need to know how the machine actually works. It is not rocket science, a 13 year old could (did, in my case) get it. Venn diagrams and stories would have put me off from computer science entirely. Just explain the facts. With the facts, as you say, we can understand many other things about computers immediately, that metaphors and concepts from math would have been no help whatsoever. People really over-think things. $\endgroup$
    – Scott Rowe
    Commented Sep 12, 2020 at 12:18
  • $\begingroup$ Maybe the real problem is that computer science instructors do not know as much about electronics as I did by the time I was 13, from perusing outdated books about vacuum tubes in the library. It had only 3 books that mentioned transistors, 40 years ago. But I understood how transistors could build a flip-flop, and flip-flops could build a latch, and how latches could implement registers, an ALU and main memory. I didn't have to have encyclopedic knowledge of those things, just an idea. So, instructors: stop diverting to math and teach from the implementation, which is what is real. $\endgroup$
    – Scott Rowe
    Commented Sep 12, 2020 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.