Sunday, November 25, 2012

Question! (And answer)

Notation:

!=     ------------>     not equal to (a relic from C++)
iff     ------------->     if and only if
||     ------>     modulus; the absolute value of.
-1     ------------>     This was supposed to be in superscript, but I can't find the how to make them appear.  Also used for footnotes.


Question:

Does there exist a function f(x) mapping from rational numbers to positive integers such that:
(1) f(x)=f(y) iff x=y
(2) For any given real R, there exists a rational number x such that e>|R-x|*f(x) for any e>0.

Notes about question:
1) Criteria (1) for f is basically constructing an ordering of the rational numbers.
2) It is relatively simple to construct an ordering of the rational numbers such that (2) is heuristically "probably true", but this is vague to define and prove. This is because for any e, the "area", including overlaps, containing the set of reals between x-e*f(x) and x+ e*f(x) goes to infinity as long as we have solutions for f(x)=N for any positive integer N.
(See http://en.wikipedia.org/wiki/Harmonic_series_(mathematics) .)



Solution:

Lemma 1: The above question is equivalent to the following question:


     Does there exist a function f(x) mapping from rational numbers in [0,1) to positive integers such that:
     (1) f(x)=f(y) iff x=y
     (2') For any given real R in [0,1), there exists a rational number x such that e>|R-x|*f(x) for any e>0.

Let f1 be one such function that satisfies (1) and (2') and in particular has an inverse 1.
Let f2(x-1) = f1(x), f3(x+1) = f1(x),
      f4(x-2) = f1(x), f5(x+2) = f1(x),
      ...etc.

Now we construct a function g(x) that also maps from rational numbers to positive integers, where g(x) is defined as follows:


f1-1(x) = g-1(2x-1)
f2-1(x) = g-1(4x-2)
f3-1(x) = g-1(8x-4)
and in general:
fk-1(x) = g-1(2^k * x - 2^(k-1)) for all values of x and k.

We notice that g-1(x) is taken from f1-1 if x=1 (mod 2), f2-1 if x=2(mod 4), etc., so g-1(x) is uniquely defined for all x.

Then g(x) satisfies conditions (1) and (2). 2

Using lemma 1, all that's left to do is construct one such f1.
This can be done as follows:

Construct a function h that maps from positive integers to rational numbers, where h(1), h(2), h(3),... are
-42, 0,     0, 1/2,     0, 1/2, 2/8, 3/8,     8/16, 9/16, 10/16, 11/16, 12/16, 13/16, 14/16, 15/16,     ...


Specifically, h(1) = -42 3, h(2) = 0+0*(1-0),

h(3) = 0+0*(1/2-0), h(4) = 0+1*(1/2-0), h(x)= 1/2+(x-5)*(1-1/2) for 5<=x<=8,

h(x)= 0+ (x-9) * (1/4-0) for 9<=x<=16, h(x)= 1/4+ (x-17) * (2/4-1/4) for 17<=x<=32,

... for 65<=x<=128,

h(x)= 0+ (x-129)* (1/8-0) for 129<=x<=256, ... etc.


where the underlining separates the definition of functions into recognizable groups. Furthermore, within each group as partitioned by the underlining, it is possible to bound the maximum |R-x|*h-1(x) by half. 4

f1-1 can be generated by taking the next nonrepeated term in the sequence of h(1), h(2),... etc.



That this is a valid assumption (because it relaxes the conditions) is left as an exercise to the reader.
2 Again left to an exercise for the reader. It's quite evident, but horrid to type out.
3 A null element for the sake of a convenient proof.
4 This is left as an exercise to the reader as well... nah just kidding, will hopefully post a somewhat rigorously written (and readable) proof at a later date.

Edit: A final note... it was a lot more readable from the luxury of a wide page, so perhaps one should try pasting it onto notepad with wordwrap.

Saturday, November 24, 2012

Technical framework up

  Good day.

  Today, I am proudly presenting... nothing!... since this marks the start of the making of the simulation game. As for names, there hasn't been any good ones coming to mind yet, so for now I shall just summon my powers to connect random words and call this game... BalalaikaOpus! (BO for short).

  As of now, there is currently no world to live in, but nevertheless, the npcs have been created and are currently paddling through space, and been given stats (Athleticism, Age, Creativity, Deftness, Learning, Resilience for now). Mindsets have also been implemented, for now j perseverance and morality. Some skills have also been implemented: Walking (What a undervalued skill!), Running (just for the sake of juxtaposition), Cooking, Painting, Fighting and Life Experience (for whatever can't quite fit... stone-skipping skills anyone?). As can be seen, most of such skills are broad, and hence implementation has been done on the basis of possible future subskills, e.g. cooking.baking.

  The difference for classification into stats, mindsets and skills is basically to make the concept clearer, since although the variables are be treated as equal, the way the variables behave are fundamentally different. Stats in general do not change (age aside), mindsets change slowly, and skills change quickly. Moreover, skills do not decrease, while external interaction can, and likely will change mindsets. Also, while skills have dependencies on stats, mindsets do not, and as for individual actions taken, they will be based off mindsets and skills solely (with stats only being indirectly involved).

  Each npc is planned to have a set of stats, skills and mindsets, although if the skillset gets too large and that creates a problem for computer memory, some of those might have to be ignored and estimated based on situational need (e.g. pancake flipping skills, while not implemented, is likely to be related to the cooking skill).

  P.S. I forgot to mention the inclusion of goals, which are objectives an npc tries to pursue. For now, there is wealth, attention and fame.

  Coming up: Planned vague goals, to account for unconventional objectives, such as promoting the joy of eating chocolate. Such goals will be given just an ID, instead of a name, and are set to be randomly generated by the computer.

Monday, November 19, 2012

Simulation of a society

Fact:  I enjoyed Roller Coaster Tycoon immensely (the original version, created 1999). Parts of what I enjoyed about it were the simplicity of design, together with the "interesting" details microscopically (such as when you observed a single guest) and macroscopically (while managing the entire theme park).

  As such, I have on different occasions thought of how a simulation of a society (in the sense of a group of people, probably isolated, living together) would function.

  I imagined it being a wonderful simulation (my ideal), where one got to observed the macroscopic panorama of the layout of the structures sprawled over space, as well as the individual simulated citizens going about their daily lives. It would also include the intrinsic concept of progress, since it is the basis for many games, whether RPG, Sim, strategy or shooter. This would come in both microscopic and macroscopic forms, respectively being the way an individual pursues his or her goals, and achieves (or doesn't achieve) them eventually, and the way a society progresses over time, with definite short-term direction but not necessarily with a fixed long-term route to follow.

  As such, I have planned to pen down (and give a structure to... concretise?) the ideas for a sim (i.e. those that I remember at the time of writing). This is again a short-term direction, and may (and probably will) suffer from the lack of follow-up.

  In the next post of this series (if it exists) I shall cover various (at least one) specific aspect of the sim of my imagination, probably written in the form of a design note (design notes are awesome!)