Bill Green

Extracting meaning

Simple problem

| Comments

You have a list of N real numbers, x1 to xN. You decide you want to sum the products of the i first terms, for i from 1 to n. Let’s call this operation multadd.

A simple example with the following list L = [1, 5, 3]

1
multadd(L) = 1 + 1 * 5 + 1 * 5 * 3 = 21

One thing we can notice right away: the result depends on how we order the numbers in the list.

How to order the numbers in the list so that the result is maximized?

Hard solution

If all numbers are positive, the answer is simply to order them in descending order. But remember that any number can be negative, or 0.

The naive algorithm will check every possible permutation, and display the maximum result and one way to accomplish it. Here’s a working example in Python:

First attempt O(N!)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import itertools
from operator import mul

def multadd(L):
  """Sum of the multiplied i first elements, for i from 1 to N"""
  return sum([reduce(mul,L[:i]) for i in range(1,len(L)+1)])

def multaddmax(L):
  """Find the maximizing order"""
  tempmax = float("-inf")
  for p in itertools.permutations(L):
    temp = multadd(p)
    if temp > tempmax:
      tempmax = temp
      result = p
  return tempmax, result

The complexity is too high for this function to be applied to lists with lengths over ten elements, but at least we’re sure we have the right answer.

Now it’s easy to realize the problem is potentially a lot weirder and more complicated that we initially thought, with the addition of negative numbers:

First attempt O(N!)
1
2
3
print multaddmax([-5, -4, -3, -2, -1, -10, -10, -0.9, -0.3, -0.1])

(11320.0, (-4, -5, -3, -10, -2, -10, -0.3, -1, -0.1, -0.9))

Difficult to see a simple pattern that would help us towards a more efficient solution. Although we can notice a few interesting occurrences: negative numbers usually end up being “paired” together, higher value first, and ordered such that they go further and further from the median value.

First attempt O(N!)
1
2
3
print multaddmax([-8, -7, -6, -5, -4, -3, -2, -1])

(39916, (-4, -5, -3, -6, -2, -8, -1, -7))

Zeros introduce yet another difficulty, altough we can determine for sure that they will always end up grouped to the right:

First attempt O(N!)
1
2
3
print multaddmax([-4, -3, -2, -1, 0, 0, 2, 4, 6])

(1894, (-2, -4, -1, -3, 6, 4, 2, 0, 0))

With or without an isolated negative number that will therefore have no impact in the result anymore:

First attempt O(N!)
1
2
3
print multaddmax([-4, -3, -2, 1, 0, 0, 2, 4, 6])

(1521, (-3, -4, 6, 4, 2, 1, 0, -2, 0))

A definitive algorithm?

It seems that a more efficient algorithm can be found.

To be continued…

The bouncing DVD logo explained

| Comments

Many people seem to experience great satisfaction watching their DVD player screensaver on their TV, looking forward to the moment when the logo hits a corner perfectly.

I don’t judge, because it’s actually fascinating, from a mathematical point of view.

It was mentioned in a cold opening from The Office, and is still a great pastime when you’re under the influence.

The math behind the greatest mystery of all time

We’ll make a few reasonable assumptions:

  • The TV screen is a W by H rectangle, the DVD logo is a w by h rectangle, with
  • The DVD logo moves with a perfectly diagonal constant speed (same absolute speed on both axes).

  • It bounces off the edges of the screen perfectly.

  • Sometimes the DVD logo image and its collision rectangle aren’t perfectly aligned, but this is irrelevant to our discussion, just choose the appropriate collision shapes in your calculations.

Now we can start our investigations.

I leave the demonstration to the reader (simple high-school level(?) math, modular arithmetic, least common multiple and greatest common divisor, and using Bézout’s identity to solve a simple Diophantine equation).

x and y are the coordinates of the starting position. w and h are the dimensions of the logo. W and H are the dimensions of the screen.

We discover the following fascinating properties:

When you hit a corner, you will hit a different corner before hitting the same one again, etc.

You can never hit 1, 3 or 4 corners, always 2 or 0.

It’s a loop, at some point it will always repeat.

The traveled distance between corners is lcm(W - w, H - h).

The condition for corners to be reached is

When this condition is not met, no corner will be hit.

The corners hit can be determined in advance. The following Javascript code does it (once provided with lcm and gcd definitions).

L = Left R = Right B = Bottom T = Top

corner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var x = 0;
var y = 0;
var w = 90;
var h = 60;

var W = 400;
var H = 300;

var W0 = W - w; //the effective displacement
var H0 = H - h;

if (Math.abs(x-y) % gcd(W0, H0) == 0) {
    // corners will be reached
    if ((Math.abs(x-y) / gcd(W0, H0)) % 2 == 0) {
        console.log((lcm(W0,H0)/H0) % 2 == 0 ? 'T' : 'B');
        console.log((lcm(W0,H0)/W0) % 2 == 0 ? 'L' : 'R');

        console.log('T');
        console.log('L');

    } else {
        console.log((lcm(W0,H0)/H0) % 2 != 0 ? 'T' : 'B');
        console.log((lcm(W0,H0)/W0) % 2 != 0 ? 'L' : 'R');

        console.log('B');
        console.log('R');
    }
} else {
    // no corner will be hit
    console.log("No corner!");
}

For programmers out there, I made a simple HTML5 Canvas demo (might not work on some browsers) that you can integrate in an html file. If you’re patient it will eventually hit a corner after a few minutes, then another one, then the same again, indefinitely. You can play with the variables, check the Firebug console for results, or replace the bouncing rectangle with a proper DVD logo.

dvdlogo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<canvas id="c">

<script type="text/javascript">
var x = 0;
var y = 0;
var vx = 1;
var vy = 1;
var w = 90;
var h = 60;

var W = 400;
var H = 300;

function gcd(a,b) {
    var temp;
    if(a < 0) {a = -a;};
    if(b < 0) {b = -b;};
    if(b > a) {temp = a; a = b; b = temp;};
    while (true) {
     a %= b;
     if(a == 0) {return b;};
     b %= a;
     if(b == 0) {return a;};
    };
    return b;
}
function lcm(a,b) {
    return Math.abs(a*b)/gcd(a,b);
}

var W0 = W - w;
var H0 = H - h;


console.log('W0 ' + W0);
console.log('H0 ' + H0);
console.log('gcd ' + gcd(W0, H0));
console.log('lcm w h ' + lcm(W0, H0));

if (Math.abs(x-y) % gcd(W0, H0) == 0) {
    // corners will be reached
    if ((Math.abs(x-y) / gcd(W0, H0)) % 2 == 0) {
        console.log((lcm(W0,H0)/H0) % 2 == 0 ? 'T' : 'B');
        console.log((lcm(W0,H0)/W0) % 2 == 0 ? 'L' : 'R');

        console.log('T');
        console.log('L');

    } else {
        console.log((lcm(W0,H0)/H0) % 2 != 0 ? 'T' : 'B');
        console.log((lcm(W0,H0)/W0) % 2 != 0 ? 'L' : 'R');

        console.log('B');
        console.log('R');
    }
} else {
    console.log("No corner!");
}


function animate() {

    reqAnimFrame = window.mozRequestAnimationFrame    ||
                window.webkitRequestAnimationFrame ||
                window.msRequestAnimationFrame     ||
                window.oRequestAnimationFrame
                ;

    reqAnimFrame(animate);

    for (var i=0;i<1;i++) { // change if you want it to go faster
        x += vx;
        y += vy;
        if(x+w==W) vx = -vx;
        if(y+h==H) vy = -vy;
        if(x==0) vx = -vx;
        if(y==0) vy = -vy;


    }

    draw();
}


function draw() {
    var canvas  = document.getElementById("c");
    var context = canvas.getContext("2d");

    context.clearRect(0, 0, W, H);
    context.fillStyle = "#000000";
    context.fillRect(0, 0, W, H);
    context.fillStyle = "#00ff00";
    context.fillRect(x, y, w, h);
    //context.drawImage(img, x, y, w, h);

    // test whether we are in a corner
    if (x == 0 && y == 0) {
        context.clearRect(0, H, W, 200);
        context.fillText("TOP LEFT", 10, H+100);
    } else if (x == 0 && y + h == H) {
        context.clearRect(0, H, W, 200);
        context.fillText("BOTTOM LEFT", 10, H+100);
    } else if (x + w == W && y == 0) {
        context.clearRect(0, H, W, 200);
        context.fillText("TOP RIGHT", 10, H+100);
    } else if (x + w == W && y + h == H) {
        context.clearRect(0, H, W, 200);
        context.fillText("BOTTOM RIGHT", 10, H+100);
    }
}
var ctx = document.getElementById("c").getContext("2d");
ctx.canvas.width = W;
ctx.canvas.height = H+200;
ctx.font = 'italic 20pt Calibri';
//var img=document.createElement('image');
//img.src='http://www.otakia.com/wp-content/uploads/V_1/article_3565/7388.jpg';


animate();
</script>

Video games that help you do your job better

| Comments

It appears that 20% of video games nowadays are “serious games” designed for professional training.

Can’t video games also be used as an integral part of your job?

Video games to solve real problems?

Imagine a game that solves real-life issues, or is fed with information from the real world that players can manipulate in meaningful ways to produce accurate results.

Instead of crushing candy, you’d be folding proteins to help the progress of science. Of course, it already exists.

But it turns out it’s not that easy to make a video game that still feels fun while accomplishing something meaningful. Most math problems are already solved better by computers, and the few problems that humans can solve better would feel extremely repetitive and artificial when shoehorned into games.

Augmented reality games

A more promising way for video games to enter everyone’s lives is through augmented reality games, making “boring chores” or menial jobs more lively.

Imagine you work as a cook in a futuristic restaurant. In the future you’ll have screens in the kitchen, with realtime feedback from the customers. You’ll have information when people tweet their food, what they say about presentation, taste, etc. You can adjust the recipes, cooking, quantities, seasonings, with immediate feedback. Individual or general tastes can be made available to you so you can customise the food according to everyone’s needs. Every client’s special diet (kosher, vegetarian, vegan, gluten-free) can be immediately known and special iPad menus will display only the relevant items and allow immediate order without any need for intermediates (like, you know, waiters). Ambient music and decoration can be adjusted by the clients to automatically cater to their taste, etc.

It’s easy to imagine games between cooks to achieve the best cumulated score during the service, and have special rewards displayed on screen for “perfect” dishes or “best cook of the day”.

It would make people who work in all sorts of difficult jobs feel better when they have instant feedback to realize that their efforts are paying off. Hi-scores could be displayed in the restaurant on a front display, alongside a constantly updated list of the most successful dishes.

Being a garbageman could almost become funny and motivating if you had a realtime display on the sides of the truck of the quantity of trash accumulated since the beginning of the day, with a timer, compared to your best score. When you beat your best score or perform significantly well, a special cinematic and music reward you, and people in the vicinity are warned that they can send encouragement tweets displayed immediately on the sides of the truck, make money donations or gifts, etc.

Even the most humble jobs would get recognition. And feeling observed and having people giving you feedback for your job is the best way to entice you to improve continuously.

Depending on your level of cynicism it could be either the most pathetic excess of enslaving by entertainment and infantilization, or the best thing to ever happen to capitalism.

  • Games can motivate progress and easily give a sense of constant progression when there is no more.
  • Games can make cooperation easier between coworkers by exchanging only the relevant information by design.
  • Games can provide visual or sound indications for instantaneous feedback on your actions, and faster correction.

If people can play a game as dull and boring as World of Warcraft for years (that’s an inflammatory but fair opinion), there is no doubt that even simple video games with your coworkers can motivate you to accomplish boring tasks just to unlock achievements or grind xp to get to the next level before the end of the day. You are literally being rewarded for pressing buttons all day in specific patterns, arrange and optimize numbers, this can actually be made useful in industry.

It’s the same strategy used to make children or dogs do things. You have to convince them it’s a game (like, cleaning their room or completing an obstacle course), and they will gladly do it.

It would be extremely perilous to introduce the concept to grown-ups, as they would probably feel insulted, but probably less so in the future, when pretty much everyone has lived in a culture of video games since childhood.

By providing a more direct link between actions and rewards, video gamification of the world is the solution to optimizing human performance in the workplace.

Just having publicly displayed visual indicators that you can influence, is already a powerful motor for human action, as they trigger hunter impulse and collective emulation.

Video games are one of the cheapest entertainment medium available, you only need a screen and any interaction device, they can be linked to real information or sensors, and produce real consequences. They enforce a given framework, a set of rules that no one can break. They are the ultimate tool for enslavement of the younger generations.

Threats

There are obvious threats with video games everywhere in the workplace, mainly that it needs true employee involvement to work.

Also games might distract you too much from the real job. No game can fully encompass and evaluate all you need to do to be successful at your job, because they can only reflect reality as well as what is used as input to them. Anything that isn’t in the game, even when it would be beneficial, will not be done.

Consequently, evaluating employees based on game results can have nefarious consequences, it should remain “just” a game, with employees having a say at how it could be evolved or how new content could be added to reflect reality better.

Node.js, socket.io, jQuery, ntwitter, node-cron

| Comments

The most commonly advertised strengths of Node are:

  • Performance: Improved throughput and better latency in typical cases where the database queries are the limiting performance factor (not CPU).
  • Scalability: Solving the C10K problem by using optimized OS-specific network interfaces (epoll/kqueue, IOCP).
  • Productivity: The node module ecosystem will provide immediately usable solutions for most of your needs, allowing a very short time to market, or fast prototyping. Javascript as a server language is a debatable but pragmatic choice, since everyone already knows it, and JSON apis or communication with clients are made trivial.
  • Socket.io: Undoubtedly one of the “killer features”, allows for impressive realtime one-page web apps that can compete with regular native software, without the hassles of deployment or cross-platform compatibility (the browser takes care of that).

The one strength that draws me back to node regularly is the productivity boost. It would be possible to use alternatives like Python and gevent, with gevent-websocket, with a micro-framework like Flask. The parts feel more disconnected and pip is not as dead simple as npm, so deployment will always be harder than just “npm install”, but Python is arguably a more comfortable language, and the coroutine approach has a shorter learning curve than node’s callback nesting. People who like Ruby could probably argue that Ruby on Rails can achieve comparable results, despite falling somewhat out of fashion these last few years.

You can have an idea, and implement a working prototype in no time (whether the prototype can scale as advertised without careful planning is another more controversial story).

Imagine the following idea:

I want a website where I can watch tweeted pictures of a city in realtime.

We’ll take San Francisco for our example, but any location in the world is possible.

An example project: “World-o-vision”

I assume the reader has at least basic familiarity with Node, underscore.js, and socket.io.

The whole code is available from a GitHub repository. Don’t forget to “npm install” the missing modules if you intend to clone it, and fill in the relevant twitter account information.

We’ll use express as our web application framework of choice, for convenience, although we only have one route (it’s a one page web app).

We’ll use Twitter streaming API (version 1.1). The awesome ntwitter node module makes it easier to use Twitter API from Node.

You will need your own Twitter keys to make this work, since every account is limited to one connection.

app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//After node configuration...

var NPICS = 10;
var picList = [];

// routes
app.get('/', function(req, res) {
    res.render('index', { data: picList });
});

// socket.io server
var sio = io.listen(server);

sio.sockets.on('connection', function(socket) {
    socket.emit('data', _.last(picList, NPICS));
});

// twitter streamer
var t = new twitter({
    consumer_key: 'USE_YOUR_OWN',
    consumer_secret: 'USE_YOUR_OWN',
    access_token_key: 'USE_YOUR_OWN',
    access_token_secret: 'USE_YOUR_OWN'
});

t.stream('statuses/filter', { locations : '-122.75,36.8,-121.75,37.8' }, function(stream) {
  stream.on('data', function(tweet) {
    if (tweet.text !== undefined) {
        //console.log(tweet.text+'\n');
        if (tweet.entities != undefined && tweet.entities.media != undefined && tweet.entities.media[0].media_url != undefined) {
            picList.push(tweet.entities.media[0].media_url);
            console.log(picList.length);
            sio.sockets.emit('data', _.last(picList));
        }
      }
    });
});

The node server will connect to the Twitter streaming API, filter tweets by location (San Francisco in our example), add all links to tweeted photos in a list, and send either the last (more recent) 10 elements of the list (first update) or the individual elements (in subsequent realtime updates) to the client.

We limit ourselves to 10 pictures to avoid putting too much strain on the browser. On the server side though, we could save all photo links regularly to a database, if we wanted.

For now we’ll use this problem as an excuse to use the lovely node-cron module, and we’ll ask for the list to simply be emptied every 20 minutes:

1
2
3
new cronJob('0 */20 * * * *', function(){
    picList = [];
    }, null, true);

We can devise a simple design for a client:

  • display 9 pictures as thumbnails in a row, clicking a thumbnail opens the picture in another tab or window, in its original size
  • display one large picture underneath (the last received)

The client-side javascript can be quickly hacked together with a simple jade template:

worldovision.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$(function() {
    var socket = io.connect(window.location.hostname);

    var picList = [];
    var NBPICS = 8;

    function updatePics() {
      $('#pictures').html('');
      for (var i=0 ; i < picList.length-1 ; i++) {
        $('#pictures').append('<a href="' + picList[i] + ':large" target="_blank"><img src="' + picList[i] + ':thumb"></a>');
      }
      $('#big-picture').html('<img src="' + picList[picList.length-1] + ':large">');
    }

    socket.on('data', function(data) {
        if(data instanceof Array) {
            picList = data;
            picList.splice(0, picList.length - NBPICS);
        } else {
            if (picList.length >= NBPICS) {
                picList.splice(0, 1); //remove first element
            }
            picList.push(data);
        }
       updatePics();
    });
});
index.jade
1
2
3
4
5
extends layout

block content
  #pictures
  #big-picture

Although jQuery makes DOM manipulation easy and solves our problem, it’s worth noting that AngularJS components are usually the best long-term solution with a more correct level of abstraction.

The result can be observed here.

All the photos are realtime tweeted pictures from San Francisco!

All that can be coded and presented as a prototype, in less time than it took me to write this article!

Possibilities for future evolutions

  • We could add more interaction with the users by asking them to mark their favorite pictures. At the end of every day, we select the most liked pictures, more deserving of representing the city they originate from.

  • We could offer the use a choice of cities. Wonder what people are eating in Paris? Connect to World-o-vision at the right time of the day, and you’ll know!

  • We could display the average time between photos. The activity is a lot higher during the day. During the night the same photos will stay for a long time.

  • Elect the most attractive city, based on how liked the tweeted pictures from each city are.

  • Have various sources of photos to inject in our application, for example using the Instagram API.

Twitter use cases are infinite

| Comments

There’s a fundamental problem with Twitter, that is also a blessing: No one knows exactly how it should be used.

If you look at a single tweet, it’s already a mess, it could have all kinds of form or function:

  • self-contained text-only
  • retweet
  • response that can only be understood with the previous tweets of the conversation
  • “hey, check this out” (the message can be meaningless, sometimes it’s a summary) with a link to proper content
  • a description of an image, with the image attached, where the image is probably the most important part
  • varying, arbitrary, collision-vulnerable, manually attached hashtags. Some are only semantic (they add context to interpret what is written), some also have practical uses (regrouping Instagram pictures). Some are associated to a specific meaningful trend, some are just pleasantries.
  • it could originate from a bot or a human, sometimes it’s hard to know. It could be from an individual, from a brand, from a group of people, from someone managing a celebrity account, from someone claiming to be someone else, etc.

If you were to design the perfect and definitive “Twitter terminal” for every possible use of Twitter, you would have impossible ever-changing requirements. At the beginning for example, you could naively assume displaying text was enough, and an old non-smart phone with SMS capabilities was all you needed. But now you need images. You want geolocalization. You end up needing a complete web browser to follow URLs. Or even specialized software to extract meaning out of thousands of tweets.

This is why all sorts of third-party software exist: to help you make sense out of Twitter and provide new use cases.

Sure, patterns and “best practices” have emerged for typical personal use. But new ones can be imagined.

What’s next?

Twitter is not just about individual micro-blogging anymore, especially with the introduction of premium accounts. It can simply be used as a generic platform for communication between companies/celebrities/gurus/content producers and the masses.

Companies want the publicity and feedback, masses want to be informed on the new products, make suggestions, and eventually buy stuff.

With the Twitter API, it’s easy to imagine infinitely many new use cases, based on “practical hashtags”, that can be used by customers to place orders when they send tweets to a specific company bot account.

Have order-by-tweet pizzerias. You send them your address once, then you place your orders when you want. A tweet is easier and more explicit than a phone call. It has an associated timestamp and undeniable source, so you can check delivery speed claims, and there can be no ambiguity or shenanigans about who ordered what. With geolocalization added, you could be sitting on a park bench and still have your pizza delivered to you.

Of course, as of today, modern society assumes pretty much everyone has a phone, but you can’t assume everyone has a smartphone, or a Twitter account or knows how to use it or wants to. But the expectations of what is normal or not are shifting. In the future tweeting could be a ubiquitous activity any human being is assumed to be able to do, for a variety of purposes, like selecting entrees at a restaurant without the need to ever talk to a waiter (because you see, in the future people are all rendered socially awkward by all the time spent on their smartphones and computers). The telephone was widely adopted because of its practicality, and if Twitter can achieve the same level of practicality in its own domain, we can expect the same success in future generations.

Tweets as inputs to computer programs are not just useful to consumers, they help companies observe the realtime trends and act accordingly.

You can have social events with people voting by tweet instead of SMS (but hey, TV shows need the money).

If people have more incentives to tweet (I mean, more than social validation, tweets can get you stuff), if their tweet can trigger complex processes with more visible consequences, they will obviously tweet more and more people will tweet, all of which benefits Twitter.

Tweets in the future could be used as a way to trigger any verifiable transaction. Despite the outrage it would cause, Twitter might eventually offer all their users the possibility to confirm their real identity, because the possible applications are endless, from voting in elections to money transactions (now you have your viable business model, guys).

Vine is the new haiku

| Comments

What is the consequence of forcing users to an incredibly constrained six seconds video format?

  • The meaning is condensed. No more 5 minute video with only a few seconds of interesting action you could have skipped to directly.

  • Consistency is enforced. There is just no time to tackle multiple subjects or be distracted from your original point.

  • Ease of use. Anyone can make a 6 second video. Following the rules is not the hard part.

It’s Twitter all over again

The major trap with Vine or Twitter, or any fixed form of communication (haiku, sonnet, etc.), is that most people are tempted to use them for spontaneous (and usually meaningless) outbursts, when they should be carefully crafted and thought out for maximum impact.

Can Vine really be advertised as a new art form?

In itself, Vine is only a vector for communication. It’s up to the people to use them as they want, the same way Twitter is used differently by brands, celebrities, ‘gurus’, teenagers, etc.

Conciseness has never been an obstacle to depth, and Vine is certainly capable of harboring art.

Sure, a lot of Vine videos are ADHD kids doing pointless crap, the same way most tweets are random angsty comments you could live without, and most haikus are mediocre attempts.

It doesn’t mean the form is flawed, but that it is used in frivolous ways.

Vine is currently experimental and teeming with general bizarrerie. But we can expect that it will stabilize, and that the same thing will happen to Vine that happened to Twitter:

People will learn to use it effectively.

Speech is slowly becoming an obsolete emergency-only communication protocol

| Comments

Observing the real world you can notice this trend:

  • People in social situations (parties, conferences, dates…) texting on their smartphone instead of speaking to other people.

  • People in companies preferring to communicate via a collaborative textual chat, rather than speaking, sometimes with people a few feet away.

  • Young people who have no idea how to express themselves with words, people interviewed by television stumbling constantly for words, etc. ; when in the good old times, it seems people were generally more articulate and confident speakers.

People don’t like to speak anymore? We can try to understand the reasons why.

  • Speaking is not as necessary as it used to be. Alternative ways are simpler, usually require no formal greetings or keeping your attention focused, and are asynchronous (fire a text and forget about it until your friend reads it), while speaking requires synchronization of participants. Asynchronous is the future, the programmers say!

  • Speaking is vulnerable to ambient sounds. Our bustling modern world has constant background noise. Talking in public transportation can become tiring or tedious, while texting is still fine.

  • The information in everything you say is immediately lost if it’s not recorded or remembered. This is incredibly wasteful compared to text protocols.

  • People spend more time communicating on social media, because it catches their interest by design, and they feel that maintaining a relationship with friends is more important than striking up random conversations with strangers, which are always hit-or-miss.

  • Speech is always unfiltered. And you don’t decide who gets to talk to you or not. For example panhandlers can choose to harass you with their voice, but they can’t reach you on your smartphone. Arguably, writing notes or texts to you would be somewhat less impactful anyway.

  • You need to start the speaking procedure by something like “Hey” and close it by something like “OK, see ya”. If your start directly talking about what you want to say, or just walk away when you’re finished talking, you’re a psycho.

  • Speech is not as easily processed by computers in meaningful ways. Speech recognition is still awkward to use.

  • You might have to repeat yourself a lot to make sure all people hear/understand you well, especially on the phone.

  • Feeling ignored while talking is the worst feeling. Feeling ignored while texting is a more subdued form of rejection.

In conclusion, it’s possible to argue that trying not to speak too much is an optimization, a way towards a better attention/information ratio.

Why do we even speak?

OK, let’s not kid ourselves, the power of speech is important. Historically it was our best communication protocol for millions of years, a major turning point that confirmed the slow separation from our monkey cousins.

But really look at it from an exterior perspective: it’s a flawed and archaic protocol in the modern world.

The only advantages of speech compared to other communication protocols are:

  • The ability to broadcast a message to multiple geographically close persons easily.

  • Sensing involuntary body language and how feelings influence voices. This use of speech is especially irreplaceable in situations where you want to evaluate whether a person is trying to oversell him/herself, during dates, job interviews, business meetings, etc. You would never consider doing any of these activities through just a mail exchange.

  • Making sure you have the complete attention of someone. A good “Hey!” will always have priority over whatever the person is involved in.

  • Shouting to warn someone of an impending danger.

Objectively in an “augmented human” society where everyone has access to a communicating device, you could replace every use case of speech by text protocols, except maybe in case of emergency.

Well even then, I suppose you could implement differentiated ringtones or sound alerts depending on the content or special hashtags of the texts you receive on your smartphone.

But sound is not the most urgent or highest priority protocol available to mankind. When someone punches you in the face or kisses you on the mouth, their intent is obvious and immediately brought to your attention.

Smartphones being capable only of text and sound (as of today), it’s fun to imagine how the world would be changed if they could act physically on you, via a bluetooth extension in your brain to control you, for example.

Why be content with your smartphone triggering a sound alarm as it detects a bus with broken brakes coming right at you, when your smartphone could trigger your body to get out of the way, without wasting time to think, and with an unbeatable reaction time?

Shy in public? Not confident with your body language in the presence of women? Preload your smartphone with a selection of prerecorded body language from the most confident public speakers in the world, specifically tuned to the tastes of your target audience, and let your bluetooth brain extension direct your every move!

So yeah, the world is changing.

If the current evolution of technology is prolonged to its logical conclusion, it’s safe to assume everything you know about humanity might be unrecognizable in a hundred years.

I suspect speaking might become truly unnecessary once humans are all equipped with wireless binary data transceivers wired to a hybrid processor/brain.

What about speech commands, Xbox One, PS4, Kinect, PS Eye?

Don’t they prove that speech, and body language, and all archaic forms of communication, are the future?

A modern trend to focus on speech and body language, the two most primitive communication protocols available to mankind? How could that be?

And what about virtual reality and the buzz around Oculus Rift? It seems using the “natural” protocols of humanity and have the computer adapt to you, instead of asking unnatural things like pressing buttons, or entering text commands, is the future of gaming, or what?

I’m not the only one to think it’s not progress, although most people would have a difficult time articulating why.

Simply these technologies cater to people’s monkey brains, trying to increase sales by having the simplest requirements possible, the lowest common denominator, using communication protocols that everyone, even your mother, even your grandmother, use everyday.

And guess what, it works. People who would never play video games can understand that making the gesture of punching someone will hurt enemies, running will make you run, etc.

No need to press buttons anymore (a physical way of sending binary data!) to make the console do things, you talk and order it, like you would in a normal social situation.

Is it the future of gaming? At least it’s a way to attract more people to video games, younger kids, seniors, families, etc.

But the “energy spent”/”fun” ratio is really bad, and the more obsessive “optimizing” gamers will obviously find no interest in that, and are not the target audience anyway.

OK, so, no speech… then what’s in the future?

The most refined way you can interact with a gaming console is not speech or moving your arms around: it’s basically a computer, so the best way for it to understand what you want is… just programming it.

Pressing buttons means forcing the game program to follow different parts in the code based on your stream of binary input. What if you had more freedom than that, and could actually script your interactions with the games, essentially having your own code as a part of the game?

I would not be surprised if the future of gaming was just that: games where you interact with a world by programming parts of it.

Of course programming is hard for our monkey brains, we’re slow at it and make a lot of mistakes, it’s not always fun, which seems to defeat the purpose of a game. But we might evolve to a point where computers are so ubiquitous that programming skills are a required part of being a normal human being, just like basic math or speaking a natural language is required for every normal human being now.

Evolution towards a unique language for all humans is inevitable

| Comments

This is obviously a sensitive subject, especially when so many countries make deliberate efforts to preserve their own language.

Objections to a unique language make sense:

  • A language perpetuates the culture of a people or nation (litterature, laws, concepts, are shaped by language).

  • People will never give up their mother tongue willingly, so a unique language would have to be enforced globally with totalitarian techniques, and you don’t want that.

  • No one language is capable of expressing everything perfectly.

  • You’d need a consensus on which language humanity would adopt.

  • People will prefer learning multiple languages rather than fully adopting a common one.

  • People will break any attempt of a unique language by inventing their own words, simplifying, creating new ones, modifying the pronunciation, language is an ever evolving process and nothing can be set in stone once and for all.

All these objections are valid. In reality, evolving towards a unique language is already taking place, English being obviously the favored global language for business, trade, etc.

The need for a common ground with people you interact with is made more pressing by the Internet. The days are past, when most people would spend all their life speaking only to their geographical neighbors.

By personal experience I can say that the “invasion” of English into the French language, for example, is felt strongly as a threat by the older French generations, and not so much by the young, who are now taught English from age 7, even before they know how to use their mother tongue properly.

No one will be able to stop the process. After all, in year 3000 French is already a dead language.

Regional languages of French (they are plentiful… France is a gathering of multiple old “tribes”, not just Paris) are even more doomed, they are in fact already dying and a historical curiosity rather than functional languages, despite ongoing revival attempts in French schools. Strong regional accents that can be found easily among seniors are softened by the influence of the uniform accent of television and other mass media.

I even read about English middle-aged persons appalled by some young people sounding more and more American.

Of course everywhere where people are isolated, or in ghettos, or when specific efforts are made to preserve a language (French in Quebec for example is unlikely to just die out), the uniformity can never fully reach them.

Now imagine this “connected” future, maybe dozens or hundreds of years from now, everyone using exclusively social media and talking through cybernetic implants, not only with people closer to them geographically, but with people from all over the world with the same interests.

If this is indeed the evolution of the world, all languages will eventually die out except one.

Just by interacting, you lose your specificity, your idiosyncrasies must be abandoned. I can’t speak regional Picard anymore (yes, just like the Star Trek captain, this is not a mere coincidence) when I’m in California, and it’s unlikely my future children will ever hear a word of it, while my grandparents used to speak it almost exclusively.

A world where everybody interacts constantly with everyone, like in social media, tends to be more uniform. The French youth watch Breaking Bad. Because it’s discussed everywhere on Twitter. The French youth use the invented frenchized verb “liker” instead of “aimer”, for Facebook likes.

Emotionally rejected by many, fearful of a George Orwell’s dystopian Newspeak, a unique language would make (and already makes, since you’re reading this blog and you’re not necessarily a native English speaker) pragmatic sense.

Is English the answer?

You could argue that English is already the common language of the world, and in many ways it obviously is. Sadly, English is broken, and it shows.

  • It’s a bastard language, so there are multiple words for many things when one could theoretically be enough and greatly simplify the learning process for people all over the world.

  • You can’t know the correct pronunciation of a word by just reading it, if you never heard it pronounced before.

  • Vowels in general are shifted in various crazy ways. You can never be sure (shoor? shir? shor?) which one is preferred in this or that part of the world.

  • A rather simple and elegant grammar crippled with unfortunate bizarre exceptions (not as bad as French, though).

  • The pronunciation of English, “accents”, stressing words and sentences properly, is very hard for a lot of nations in the world. It’s all musical and slippery, when strong syllabic pronunciations (in French, German, Japanese) feel more consistent in this area.

  • Even when you’re comfortable with, say, a generic American accent, you can have all sorts of trouble understanding the crazy British local accents.

Can there be, conceptually, a language “good enough” that it could boast the necessary paradigm shift required for immediate and durable global adoption?

Of course many tries have been made historically, to form a language that everyone in the world could speak easily, some with reasonable success (Esperanto).

What would be the desirable properties a common language?

It would be nice if it were strongly logical, consistent, and with no ability to diverge from the original idea.

In our current world, with our current monkey brains, it’s close to impossible. We have poetry, ambiguity, play on words, litterature, portmanteaux, our languages are wild and free, which is arguably a good thing.

But imagine a future, thousands of years from now, where human beings are half-robots with incredible computing power wired to their brains, capable of enforcing rules strongly, and they spend all their time discussing with every other person on a hive-like Earth.

It’s possible humans will not even speak or write anymore, just exchange data instantly in binary form, wirelessly.

The following properties can be achieved, making natural languages an inferior alternative:

  • our unique language has no ambiguity. Everything is expressed clearly. No intent is ever misunderstood.

  • our unique language can easily be processed by computer programs. Sentences in natural languages can be formally verified and then used as integral parts of mathematical proofs.

  • our unique language punishes any divergence from the accepted norms by being rendered automatically incomprehensible when even one bit of it is invalid.

While it sounds like a 70s novel futuristic dystopia, it would at least make the programmer’s task considerably easier.

True hackers need math

| Comments

(and an intuitive comprehension of what’s happening in their code)

More and more software developers in the start-up world are the product of necessity. While their technical knowledge of programming is usually good, their understanding of mathematics is sometimes really disappointing, and is a real handicap in their job.

Now, don’t get me wrong, I’m not particularly good at math, and I’m an engineer so I should feel bad about it, but when I can constantly notice the flaws in my colleagues’ or friends’ work or reasoning, that makes it all the more alarming.

Math is indisputably at the heart of programming, the same way it’s the heart of physics, or engineering, or anything that allows us to understand or manipulate the evolution of reality in quantifiable ways.

From what I’ve seen, “genius hacker college dropout kids” seem to be the most affected by the lack of mathematical knowledge. To them programming is mastering the specificities of a technology and use it to create cool stuff fast, or as a means to disrupt society’s power balance in their favor. Since it’s a valuable skill after all, they obtain sufficient gratification from their coding skills alone, and they never get around to learning real math to help them progress past a certain critical point, which is a handicap in all but the most trivial problems a programmer has to face. So they end up plateauing pretty hard despite a promising start, and prefer abandoning coding altogether and just doing business. Only the more “mathematical” geniuses can continue enjoying programming for years in a somewhat autotelic fashion (I’m thinking John Carmack and his recent tech-heavy speech at QuakeCon 2013).

A few tales of mathematical ignorance

I promise those people are actually brilliant professional coders otherwise, but not understanding the math behind what they do is definitely a source of problems.


Example 1: Implementing the Glicko rating system (to assess players’ strength in an online game)

“Can you implement this formula?”

=> “Wait, what’s a logarithm?”

(and then not understanding the difference between natural logarithm of ten in base e, and logarithm in base ten)


Example 2:

“If your background image is too heavy for our website, you can try drawing more uniformly colored areas instead of varying the shades everywhere.”

=> “I don’t get it, if the image size doesn’t change, it has the same number of pixels so the download size remains the same for the users.”

No. Dude. No. Not even close. Images displayed on a website are in a compressed format! Try comparing a big image with white only (compression works perfectly, 1kB) and a an image with the same size and every single pixel set to a random value (compression becomes useless, your image now weighs a few MB…).

Information entropy, fast fourier transform, are complicated but useful notions.


Example 3:

Not a dialog, but I see a lot of programmers who like to obsess over time and space complexities (using a fragile understanding of big O notations), saying “I’ll just use quicksort because it has the best time complexity and I want it to be fast”.

Actually when sorting an input they should consider all the aspects:

  • in some cases the size of the input will remain low enough that more “complex” but simpler to understand algorithms with more favourable multiplicative constants are faster.

  • if the size of the input is high but there are very few possible values, bucket sort beats quicksort.

  • circumstances can justify using other algorithms, for example if the input is received by chunks over the network and needs to be constantly sorted, heap sort might be more adapted.

“Google coding”

Applying formulas or following recipes is no substitute for an intuitive understanding of what’s happening inside your code.

The general spirit of not wanting to think or do math but just “have fun” or “make something awesome” results in an annoying trend: the so-called “Google coders”, people who will use Google extensively to solve their problems, copy-paste and adapt some code without fully understanding what they’re doing, not really checking the internals, or wondering why it should work.

It’s OK to do that sometimes, and tapping into the internet hivemind might feel like a decent way to increase your productivity instantly. But mostly it’s just laziness.

There are indeed a few glaring flaws with this approach:

  • You end up trying to connect black boxes of code together, with potential impedance mismatch or lack of general consistency in your project.

  • How do you test code you don’t understand? How do you handle memory, errors, exceptions, tests, that were not in the original code because the author wanted to keep things simple?

  • You don’t learn anything that you can reapply in the future in similar circumstances using principles extracted from your intuitive comprehension of the problem.

  • If you don’t understand exactly what you need in your specific problem, your solution won’t exactly answer your problem.

  • No progress or breakthrough in technology was ever made by people who sacrifice for comfort the need to think.

Many programmers have the right idea when they try to roll their own piece of software (like, coding your blog platform or yet another content management system), and only then use all the available tools and libraries made by others and refined by years of use, understanding the intent behind every design decision and API call.

One immense advantage is that, when something breaks, you already know or imagine how the internals are made, and you can easily go fix it yourself (instead of waiting for the maintainer to manifest himself).

I would only use “google coding” in emergency situations, for fun coding marathons, where I would be convinced the code quality and maintainability matters less than getting something out in record time.

Worse than “Google coders”: “Microsoft black magic coders”

I’m not talking about people who work for Microsoft itself, who, I’m sure, are mostly brilliant people with a true passion for programming, for which I have a lot of respect.

I’m talking about people who believe they can get all the complicated parts of programming out of programming.

I talk to some of my friends who work and code for very big companies and are forced to use Microsoft products everywhere.

Microsoft products are great and make everything easier, except when they break, and they break all the time. I’m not blaming Microsoft particularly, everything breaks all the time, it’s called entropy, and it’s an inevitable part of the physical universe. Everyone can realize that programming is inherently hard, and it’s inevitable that sometimes, people will use your program in unforeseeable ways.

What I could blame Microsoft for, however, is that trying to hide all the implementation details and making programming simpler for a generation of subpar brainwashed programmers makes it harder to fix the inevitable problems one will encounter.

When something breaks in a fully open source stack, it’s relatively easy to identify which part, where, to correct the problem, to submit a fix to the maintainers, etc. It’s a very good feeling for a programmer, and it trains a generation of people who understand what happens at every level in their code, which is very sound and satisfying.

Microsoft deprives people from this feeling, by making the disputable (but economically justified) strategy choice to make everything “their way”, close-sourced and with voluntary divergence from internationally accepted norms or open interoperable formats.

Every programmer who uses Microsoft products is treated like a child, maintained in a state of voluntary ignorance, brainwashed into accepting a mix of archaic constructs and new idiomatically named features, given comparatively lower powers for fear that they could break things, and when (inevitably) something does break, no one has any idea what’s actually happening, and they are forced to call “experts” to unblock the situation.

I like to call them “black magic coders” because they see programming as summoning the powers of the dark side and pray that they consent to help. If Microsoft doesn’t provide any specific magical way to do what they want, they are distraught and helpless because they have no idea how to reimplement the basics by themselves.

I’ve talked to a software engineer with years of experience working with .Net and C#, who had no idea whether the huge web app they were making used “regular” HTTP calls or Ajax. Everything had always been abstracted away to him, to the point he had trouble making the connection between Microsoft mumbo jumbo and the actual underlying technologies used.

They memorize acronyms, standardized solutions, common answers good enough to pass their Microsoft certificate, and have a Pavlovian relationship to programming.

It’s fine to abstract away the implementation details, but only if you know what’s behind them in case you need to know, which happens often with those hard-to-find bugs where you hit a limitation or implementation quirk of the underlying technology.

Perseverance and probability

| Comments

Problem: Trying n times something that has a 1 in n chance of success.

For example, n = 2 means having 2 tries to guess the result of a coin flip.

For n = 6, you have 6 tries to guess the result of rolling a standard die.

The probability of success P can also be expressed as “one minus the probability of every try failing”. $$ P(n) = 1 - \Big(1-\frac{1}{n}\Big)^n $$

A surprisingly high number of people have a very flawed understanding of probabilities, even with mathematical backgrounds, and will just assume without thinking that P is always 1 or converges towards 1 as n goes to infinity. None of these propositions are true.

What is the limit as n goes to infinity?

If you try sufficiently hard something that has a very low chance of success, you will always succeed (your probability of success converges towards 1), so most people would be tempted to say that P converges towards 1. But that’s not the question.

The question is: if you try exactly n times something that has a 1 in n chance of success, and n grows very big, how good are your chances? Let’s call P the probability of success.

Numerically if you tried a few values of n you would realize that the right expression converges quickly towards a number that is neither 0 nor 1.

Remembering one of the definitions of e, the Euler number:

it becomes easy to realize that

A 63% chance of success means you’re a winner in the long term if you’re used to trying a million times something that has a one in a million chance of success.

Wacky logic: “Les Shadoks”

“If there is one in a million chance to succeed, rush failing the 999,999 first tries.”

During my childhood in France in the 90s, an old animated TV series from the late 60s called “Les Shadoks” was still running, that had been a significant cultural phenomenon among older generations. I remember it being very funny, and you should definitely check it out on Youtube if you understand French, and are prepared to feel overwhelmed with utter confusion and culture shock. Some of the ridiculously wrong and illogical Shadok mottos are still heard today in France, although since then end of the show less and less people know where they come from (“Pourquoi faire simple quand on peut faire compliqué ?” => “Why do it the easy way when you can do it the hard way?”).

“Better to pump even if nothing happens than to risk something worse happening by not pumping”

It had the most bizarre, absurd and eerie stories, and an unhealthy obsession with useless and endless pumping, but more importantly for our current discussion, the Shadoks, stupid and ruthless bird-like creatures, keep dying in atrocious circumstances because of how flawed their “logic” is.

One example that particularly struck me as a child: the Shadoks want to build a rocket to travel from their dysfunctional home planet to the Earth. Their most renowned mathematician calculates that their plan has a one in a million chance of success, then claims that all they have to do is rebuild the same rocket over and over again until it inevitably works when they reach 1 million attempts.

“When one tries continuously, one ends up succeeding. Thus, the more one fails, the greater the chance that it will work.”

Even 7 year-old me knew it couldn’t be right (and anyone who understands basic probabilities is warned specifically against this fallacy), but it took me years to figure out the real probability of success.

Approximately 63% is actually a pretty good chance for the Shadoks, given their general incompetence.

The Shadok brain can only memorize 4 words, so they count using a base 4 number system. They were my first introduction to non-decimal bases, at age 7, or BU MEU.

Here’s a link to a video explaining Shadok counting (in French): Shadok counting

Applied probabilities: picking up women (or men)

What are the odds that a girl you meet randomly in public agrees immediately to date you? The chances are pretty slim (although you’d be surprised how much blunt honesty works), especially now that I know you’d rather spend your free time reading through my ramblings instead of going outside making friends or something.

But the point is: the chances are small, but non-negligible, let’s say 1%. Ask every woman you meet during the day, in public transportation, on the streets, and more often than not (63% if you ask 100 girls out), you will end up dating someone today with little effort (probably someone really easy or mentally unstable, but that’s your problem now).

No need for sophisticated matching algorithms, loneliness in our contemporary societies is easily solved by brute force1!

  1. I am not liable for tragic misunderstandings of this sentence.