4 ms·
"I had already explained that [1..N ⟶ 1..N] is the set of functions that map the set 1..N of integers from 1 through N into itself" As a programmer, I woul
by bjourne 10y ago
"I had already explained that [1..N ⟶ 1..N] is the set of functions that map the set 1..N of integers from 1 through N into itself"
As a programmer, I would read that as if he is defining a set of function objects. And the domain and codomain of the those function objects must be integers in the range 1..N.
Come to think about it... Isn't the size of the set exactly the number of permutations from 1..N? In other words N^N? If so, an audience of computer scientists would probably have understood the following better:
import itertools
list(itertools.product(range(N), repeat = N))
- areyousure 10y agoThe number of permutations of 1..N is N! ("N factorial"). The total number of functions from 1..N to 1..N is N^N.
- pron 10y ago> If so, an audience of computer scientists would probably have understood the following better I'm a very experienced programmer (>25 years) and I don't know the language you're using in your notation (Python maybe?). The kind of mathematical notation Lamport is using is much more universal (at least after he explains its particular peculiarities). Also, reading your notation, I assume that you're describing a list, while he's describing a set.
- bjourne 10y agoYes, it is Python. Python has become a lingua franca in the programming world, and you'd be well-advised to learn it. It creates a list but that is inconsequential. Here is the fixed code (to actually generate permutations) and examples: >>> from itertools import * >>> [s for s in product(range(2), repeat=2) if len(set(s))==2] [(0, 1), (1, 0)] >>> [s for s in product(range(3), repeat=3) if len(set(s))==3] [(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)] >>> len([s for s in product(range(4), repeat=4) if len(set(s))==4]) 24 >>> len([s for s in product(range(5), repeat=5) if len(set(s))==5]) 120
- pron 10y ago> Python has become a lingua franca in the programming world I don't think so. Probably depends on your section of the industry. In mine, C, Java and Matlab are all better known than Python. > you'd be well-advised to learn it I did; a few times, actually. I just keep forgetting because I never get an opportunity to use it. Once you've used well over 10 languages, you don't even try to maintain your skills as that would be a waste of time. You just relearn the language next time you need it, especially as popular languages come and go. Standard mathematical notation, however, has been with us, pretty much unchanged, for about 100 years now. In any event, you can't express in Python nearly everything you can express in standard mathematical notation, unless Python has gained some features that allow it to express uncomputable objects since last time I used it. Does the itertools library support infinite sequences? How about uncountable sets?