Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Haskell: Sets

Name: Anonymous 2015-08-17 18:24

Given a finite Set type (not Data.Set), find a map Set -> Int that is bijective! (Let's try injective first, how would you do that?)

The definition of Set I have in mind is this:
data Set = Empty | Set [Set]
But if you want to use some other equivalent definition go ahead.

Name: Anonymous 2015-08-17 18:51

#define SET(type, init_size) type * data[size]
...
typedef SET(int, 10000) muh_set;

Name: Anonymous 2015-08-17 19:05

>>2
Why T*[]?

Name: Anonymous 2015-08-17 19:07

why

data Set = Empty | Set [Set]

and not

data Set = Set [Set]

you stupid haskel faget

Name: Anonymous 2015-08-17 19:10

Name: Anonymous 2015-08-17 19:15

did you mean something like:

data Nil :: *
data Cons :: * -> * -> *

data Set :: * -> * where
Nil :: Set Nil
Cons :: h -> Set t -> Set (Cons h t)

Name: Anonymous 2015-08-17 20:14

>>6
It depends on the underlying set axioms of the category FinSet you are implementing. For example, yours is with urelements while mine is GST.

Name: Anonymous 2015-08-17 20:15

>>6
Though the problem is that while my Set is countable, yours is not! Therefore, a binjection with Ints can not be found.

Name: Anonymous 2015-08-17 22:23

>>8
count my anus

Name: Anonymous 2015-08-18 22:51

Isn't this just Peano arithmetic?

Name: Anonymous 2015-08-19 2:35

Quoting 10:(my phone doesn't have them brackets ffs)
The peano arithmetic is an injection from sets to the integers that also has the nice property of translating set-theoretic terms into arithmetic ones. Going the other way you can construct an injection from the integers to finsets. I hadn't though of that, I had found another way myself, I'll post the idea some other time. With that said, how do you go from peano to bijection? I don't think you do.:-)

Name: Anonymous 2015-08-19 2:52

>>11
Nice answer. Why do you own a expensive toy with a touchscreen though?

Name: Anonymous 2015-08-19 3:25

>>12 actually now that I think of it some more, there is no "going the other way", peano arith gives an
Injection from integers to sets fullstop.

for the toy remark, it cost $60 second-hand n I just came to the US

Name: Anonymous 2015-08-19 5:13

>>13
Did immigration control require you to carry around the tracking collar in case you try to stay when your visa expires?

Name: Anonymous 2015-08-19 19:38

>>11
I don't think you do.:-)

Really? Peano evens count negative, odds count positive. Are we good, or do you want to talk about homos now?

Name: >>15 2015-08-21 3:50

Or do you want to talk about homos now?

I was serious when I asked this btw. I am prepared to talk about homomorphisms if you want to go there.

Name: Anonymous 2015-08-21 19:10

Fucking haskell, I have to fucking format my system to install an update. This is the Set -> Int injection I had in mind.

concatInteger :: [Integer] -> Integer
concatInteger = read . concatMap show

setLen Empty = 0
setLen (Set s) = length s

set2List Empty = []
set2List (Set s) = length s : sort $ concatMap set2List s

set2Int = concatInteger . set2List

Name: Anonymous 2015-08-21 19:11

>>17
Disregard setLen. It's not needed.

Name: Anonymous 2015-08-22 2:45

>>17,18
I just realized this is not 1-1

Name: Anonymous 2015-08-22 10:38

Name: Anonymous 2015-08-22 13:28

>>14
There's no immigration control in the US. The politicians want more immigrants from whatever hellhole.

Name: Anonymous 2015-08-22 13:53

>>20
Thats not relevant, finset is countable

Name: Anonymous 2015-08-22 14:02

>>21
Thats not relevant, immigrants are uncountable

Name: Anonymous 2015-08-22 14:41

Count my dubs.

Name: Anonymous 2015-08-22 16:14

>>22
It's relevant.

Name: Anonymous 2015-08-22 16:27

>>19
Okay so the solution for it to be 1-1 is to use 0 as a delimiter.

What I'm doing here is this:

Sets are basically things of this sort:
{{{},{{}}, {{},{{}}}}, {}}
Because the comma can be deduced, it runs down to this:
{{{}{{}}{{}{{}}}}{}}
Now what this really is, is just a tree without labels (hence the Set type definition looks exactly like a Tree). I will depict the above set in an ASCII tree diagram:
2 / \
1 /
3 / / \
1,2 / /\
1 \


At the left side is the number of branches. At the right side is the tree (so for example / / \ means there are 3 branches). The idea to give a unique integer to this tree is this: Sort out lists (the only list here is 1,2), and concatenate integers, with 0 as a delimiter. So what we'd get is this:
20103020101
The reason 0 is used as a delimiter is because I figured that it's not clear whether 21 means 2 and then 1 or really 21 nodes. It may be possible to deduce which of the two is true if you keep scanning the integer code to find the "only" legit set, but it may be that two different sets map to the same integer. I haven't figured out which of the two is true, but if you use 0 as a delimiter you are good to go.

Anyhow, that's the injection. Anybody up for the bijection? I tried lexicographical order on the {{{}{{}}{{}{{}}}}{}} representation, but it turns out it's not good enough: You run into infinity because of expressions like {{{{...}}}, X} and it doesn't matter what X is.

Name: Anonymous 2015-08-22 17:25

bijection was posted twice and ignored

Name: Anonymous 2015-08-22 17:36

>>27
Alright, elaborate then please. As far as I understand it you're wrong.

Name: Anonymous 2015-08-22 21:04

>>28
Try reading the thread, genius.

Name: Anonymous 2015-08-22 22:38

>>23
oh dear

Don't change these.
Name: Email:
Entire Thread Thread List