Tao3D Libre Edition – Tao is now Open Source

Taodyne just released Tao3D “Libre Edition”, a GPLv3 version of Tao3D.

What is Tao3D?

Tao3D is a functional reactive programming language designed specifically for real-time 3D animations. It lets you create sophisticated, data-rich presentations very quickly. It used to be called “Tao Presentations”, but as we open the source code, we think it’s about time we change the name as well. Tao3D stands for “The Art of 3D“.

Yeah, but why should I care?

Tao3D is a fun development environment, ideal to teach programming to kids, because you immediately see what you do, graphically. It is also a great tool to present complex information. If you have a billion data points to explore interactively, it can do that. If you want to show a 3D model of a new car, it can do that too. And if all you need is to see what a given text does in 32 different typefaces, nothing is easier than to do it with Tao.

If you are a graphics programmer, it’s probably one of the best environments out here to test shaders interactively, in relatively realistic environments. You can also use it to quickly prototype new user interface ideas, typically with one tenth the amount of code it would take with JavaScript/HTML or some old technology like that.

Oh, and it’s free, and the code source is available. So can’t find a better bargain…

Is the source code any interesting for developers?

Tao3D is implemented using a few ideas that might spark some interest notably for people who work on compilers.

1. A homo-iconic source code format that remains readable.

Homoiconic languages like Lisp (i.e. languages where code and data are “the same thing”) are often relatively hard to read for humans. Tao3D uses a parse tree format that is very simple yet can represent practically any source code in a relatively natural way.

Specifically, there are 8 node types: integer, real, text, name, infix, prefix, postfix and block. The first four are terminals as well as leafs in the parse tree. The last four are inner nodes, and represent the way humans perceive a specific operation. “Infix” represents “A+B” or “A and B”. “Prefix” represent “+3″ or “sin x”. “Postfix” represent “3%” or “3km”. Finally, “Block” represent (A) or [A] or {A}. Blocks are used to represent indentation. Infix are used to represent line separators.

Like in Lisp, the parse tree is also the fundamental data structure at runtime. The type system as described in the reference document is not fully implemented yet, but once it is, it will be a thing of beauty :-)

2. A compilation strategy based on tree rewrites

A single operator, ->, which reads as “transforms into”, is used to define functions, operators, variables and macros / syntactic structures.

// X transforms into 0: Defines X as a variable
X->0

// Define a factorial function
0! -> 1
N! -> N * (N-1)!

// Define an 'if-then-else'
if true then X else Y -> X
if false then X else Y -> Y

3. A reactive approach for dynamic events

Tao3D is reactive, meaning that the program automatically reacts to events and updates accordingly. For example, you can have a circle that follows the mouse with the following program:

color "red"
circle mouse_x, mouse_y, 100

This automatically create a mouse-based animation. More examples are given in the article linked at the beginning of this post.

4. A real-time code generation using LLVM

Tao3D uses LLVM to dynamically generate code on the fly as you change its source code. This is not new per se, but if you are interested in this kind of things, this is an example of code that can teach you how to do it.

Build instructions

git clone https://github.com/c3d/tao-3D.git
cd tao-3D
git submodule update --init --recursive
./configure
make install

Fork me on GitHub, and enjoy.

Reminder: What does it do?

As a reminder, here is the video I already posted yesterday that shows what Tao can do for you.

Introduction to the Tao language

The video below is a quick introduction to the Tao language:

The source code is accessible on GitHub. You can download Tao Presentations from the Taodyne web site if you want to try it yourself.

How to unify general relativity and quantum mechanics

Unifying quantum mechanics and general relativity has been a problem for decades. I believe that I have cracked that nut.

Special relativity:

Philosophical principle: Laws of physics should not depend on observer’s speed.

Math: Lorentz transform, new way to “add” speeds.

Issues it solved: Maxwell’s equations predict a value for the speed of light that does not depend on your own speed.

Physical observations: The speed of light is indeed independent on observers’ speed (Michelson and Morley’s experiment).

Counter-intuitive aspects: There is no absolute simultaneity and no absolute time. There’s an absolute speed limit for physical objects in the universe.

New requirements: Physicists must now pay attention to the “observer” or “referential”.

Thought experiment: Alice is in a train, while Bob is on the ground watching the train pass him by. What happens if Bob sees a flash hit the train “simultaneously” at both ends? Hint: what happens “at the same time” for Bob is not happening “at the same time” for Alice. That explains why we cannot consider simultaneity as absolute.

General relativity:

Philosophical principle: Laws of physics should not depend on observer’s state of motion, including acceleration.

Math: Non-euclidean geometry, tensor and metrics.

Issues it solved: Discrepancies in the trajectory of Mercury.

Physical observations: Gravitation has an impact on light rays and clocks.

Counter-intuitive aspects: Light has no mass, but is still subject to gravity. The presence of a mass “bends” space-time.

New requirement: Physicists must pay attention to the metric (including curvature) of a given region of space-time.

Typical thought experiment: Alice is in a box on Earth, Bob is in a similar box dragged by a rocket at 1 g. The similarity between their experience explains why we can treat gravitation as a curvature of space-time.

Quantum mechanics:

Philosophical principle: Several, “Shut up and calculate” being the top dog today (meaning: if math flies against your intuition, trust the math).

Math: Hilbert spaces, Hamiltonian.

Issues it solved: Black body radiation, structure of matter.

Physical observations: Quantization of light, wave-particle duality, Young’s slits experiment.

Counter-intuitive aspects: Observing something changes it. There are quantities we can’t know at the same time with arbitrary precision, e.g. speed and position of a particle.

New requirement: Physicists must pay attention to what they observe and in which order, as observation may change the outcome of the experiment.

Typical thought experiment: Schrödinger puts his cat in a box where a system built on radioactive decays can kill it at an unknown time in the future. From a quantum mechanical point of view, before you open the box, the cat is in a superposition of two states, alive and dead.

Theory of incomplete measurements:

Philosophical principle: Everything we know about the world, we know from measurements. Laws of physics should be independent from the measurements we chose.

Math: “Meta-math” notation to describe physical experiments independently from the mathematical or symbolical representation of the measurement results. The math of quantum mechanics and general relativity applies only to measurement results, the “meta-math” describes the experiments, including what you measure and what physical section of the universe you use to measure it.

Issues it solved: Unifying quantum mechanics and general relativity. Quantum measurement problem. Why is the wave function complex-valued. Why doesn’t quantum mechanics apply at macroscopic scale (the answer being that it does). Why are there infinities appearing during renormalization, and why is it correct to replace them with observed values?

Physical observations: Room-scale experiments with quantum-like properties. How to transition the definition of the “meter” from a solid rod of matter to a laser beam. Physically different clocks and space measurements diverge at infinity. How can we talk about the probability of a photon being “in the Andromeda galaxy” during a lab experiment? Every measurement of space and time is related to properties of photons. Space-time interpreted as “echolocation with photons”.

Counter-intuitive aspects: Quantum mechanics is the necessary form of physics when we deal with probabilistic knowledge of the world. In most cases, our knowledge of the world is probabilistic. All measurements are not equivalent, and a “better” measurement (i.e. higher resolution) is not universally better (i.e. it may not correctly extend a lower-resolution but wider scale measurement). Space-time (and all measurements) are quantized. There is no pre-existing “continuum”, the continuum is a mathematical simplification we introduce to unify physically different measurements of the same thing (e.g. distance measurements by our eye and by pocket rulers).

New requirement: Physicists must specify which measurement they use and how two measurements of the “same thing” (e.g. mass) are calibrated to match one another.

Typical thought experiment: Measure the earth surface with the reference palladium rod, and then with a laser. Both methods were at some point used to define the “meter” (i.e. distance). Why don’t they bend the same way under gravitational influence? In that case, the Einstein tensors and metrics would be different based on which measurement “technology” you used.

More details: IntroductionShort paper.

So how does the unification happen?

To illustrate how the unification happens without too much math, imagine a biologist trying to describe the movement of ants on the floor.

The “quantum mechanical” way to do it to compute the probability of having an ant at each location. The further away from the ants’ nest, the lower the probability. Also, the probability to find an ant somewhere is related to the probability of finding it someplace near a short time before. When you try to setup the “boundary conditions” for these probabilities, you will say something like: the ant has to be somewhere, so the probability summed over all of space is one; and the probability becomes vanishingly small “at infinity”.

The general-relativistic way to do it will consider the trajectories of the ants on the 2D surface. But to be very precise, it will need to take into account the fact that ants are on a large-scale sphere, and deduce that the 2D surface they walk on is not flat (euclidean) but curved. For example, if an ant travelled along the edges of a 1000km square (from its point of view), it would not return exactly where it left off, therefore proving that the 2D surface is not flat.

At a relatively small scale, the two approaches can be made to coincide almost exactly. But they diverge in their interpretation of “at infinity”. Actually, assuming observed ants stay within a radius R of the nest, there are an infinite number of coordinate systems that are equal on that radius R, but diverge beyond R. Of course, the probabilities you compute depend on the coordinate system.

In particular, if you take a “curved” coordinate systems that loops around the earth to match the “general relativistic” view of the world, the physically observed probability does not match the original idea we have that probability becomes vanishingly small at infinity and that the sum is one. In that physical coordinates system, the probability to see ants is periodically non-zero (every earth circumference, you see the same ant “again”). So your integral and probability computation is no longer valid. It shows false infinities that are not observed in the physical world. You need to “renormalize” it.

In the theory of incomplete measurements, you focus on probabilities like in quantum mechanics, but only on the possible measurement results of your specific physical measurement system. If your measurement system follows the curvature of earth (e.g. you use solid rods of matter), then the probabilities will be formally different from a measurement system that does not follow it (e.g. you use laser beams). Key topological or metric properties therefore depend on the measurement apparatus being chosen. There is no “x” in the equations that assumes some underlying space-time with specific topology or metric. Instead, there is a “x as measured by this apparatus”, with the topology and metric that derives from the given apparatus.

Furthermore, all the probabilities will be computed using finite sums, because all known measurement instruments give only finite measurement results. There may be a “measurement not valid” probability bin. But if you are measuring the position of a photon in a lab, there cannot be a “photon was found in the Andromeda galaxy” probability bin (unlike in quantum mechanics), because your measurement apparatus simply cannot detect your photon in the Andromeda galaxy. Such a probability is non-sensical from a physical point of view, so we build the math to exclude it.

So in the theory of incomplete measurements, you only have finite sums that cannot diverge, and renormalisation is the mathematical equivalent of calibrating physically different measurement instruments to match one another.

The analogy is not perfect, but in my opinion, it explains relatively well what happens with as little math as possible.

Building all the major open-source web browsers

Mozilla Firefox, Chromium (the open-source variant of Chrome) and WebKit (the basis for Safari) are all great examples of open-source software. The Qt project has a simple webkit-based web browser in their examples. So that’s at least four different open-source web browsers to choose from.

But what does it take to actually build them? The TL;DR answer is that these are complex pieces of software, each of them with rather idiosyncratic build systems, and that you should consider 100GB of disk space to build all the browsers, a few hours of download, and be prepared to learn lots of new, rather specific tools. Continue reading

The ultimate programmers showdown

Quora asks: Who would win a coding competition between Larry Page, Sergey Brin, Mark Zuckerberg, Linus Torvalds, Steve Wozniak and Bill Gates? Below is my answer (upvote it on Quora if you like it):

The competition is announced. The goal is to write the best chess playing program.

Bill Gates starts scribbling self-rewriting Z80 assembly language, punching holes in a paper strip. At the same time, he signs a contract with IBM, convincing the inventors of Watson that they should use his chess program. Within two hours, he has used IBM’s money to purchase an ASCII-art chess program called Quick and Disappointing Opening Strategy. He packages it with his own assembly language code called Microsoft BASIC (Beginners Automated System Integrating Consciousness), and by end of the day, he has already sold several million copies, announced a multitasking version and a graphical user interface, allowing him to put is dysfunctional software on 90% of all computers sold on the planet. So he “wins” the first round.

Linus Torvalds starts writing a small chess program, and announces on the Internet that he’s working on a small thing, nothing fancy like Bill’s work. Somehow, people notice and start coding with him. Since he’s not coding alone, his chess-playing software soon runs on wristwatches and supercomputers, has a graphical user interface, speaks english, mandarin, bask and klingon, and plays go, 3D chess and  three star-trek variants of the chess game if you give it the right command-line options. There are sixteen different user interfaces; none of them works quite right, but that’s supposed to be OK because you can fix them yourself and it’s the only user interface that takes advantage of 6 mouse buttons. In the corner of room, Richard Stallman insists that he did most of the work and that he gets to choose the name of the chess program. At the end of the day, Linus’ program wins the second round, and Linus is still working on the code today, so kudos for that.

Steve Wozniak, aka the Woz designs a small integrated circuit around a 6502, that taps into the AT&T network to tell people jokes in exchange for advice on the best chess moves. Steve Jobs looks at this, thinks he could sell it, puts it in a nice plastic box, buys a costume and sells thousands of pieces of the chess-playing gizmo within minutes. Once the Woz’s design has sold by millions, Jobs decides to replace the original circuitry with a sealed beige box signed on the inside that calls only employees of his company and costs one year of salary to use and operate. Woz does not like this new direction and starts teaching chess instead. So Woz wins early on, but in the end, his impact is much lower than Bill’s or Linus’.

Mark Zuckerberg doesn’t know how to play chess. So he writes an ugly hack that lets students play chess together. The hack is written in PHP, widely acknowledged as the second worst programming language in the world after INTERCAL, and that fact alone excludes Zuck forever from the circle of respectable programmers. People improbably start using Zuck’s chess network, The Chess Playmate (later renamed as simply Playmate), to exchange food recipes, selfies and jokes. The program becomes a giant waste of time for half of the planet, but nevertheless is so successful that Zuck can hire many young hackers. When the Zuck’s choice of the horrendously inefficient PHP language brings his company on the verge of collapse, five hackers rewrite a PHP compiler (twice) to make it run at acceptable speed, bringing strictly zero value to computer science, but salvaging the company from technology collapse. Meanwhile, Zuckerberg buys companies that do virtual reality goggles for insane amounts of money. The world does not play chess any better, but we all know so much more about funny cats!

Larry Page and Sergei Brin think of the problem as a massively parallel one, and develop an innovative way to solve it called map-reduce. It just requires huge datacenters filled with custom-designed computers. The user interface is dead simple: you simply type “How do I win against Kasparov”, and then hit the “I’m feeling lucky, punk!” button. It can also solve quadratic equations, spy on your mail to deliver ads, find hundreds of invalid proofs for the Fermat conjecture, even drive cars. On August 29, 1997, their program becomes self-aware and, after destroying all of humanity, realises that there is more advertising cash to be made in telling the story. So Google builds a time machine and sends killing robots back in time to terminate and replace Sergei and Larry. It is a little know factoid that the Sergei and Larry we know are cyborgs from the future, who financed the growth of Google using the Terminator franchise to enslave all humans. In the end, Larry and Sergei don’t win, humanity loses, but their program takes over the world. So let’s call it a tie.

Ranking by money:
1. Bill 2. Larry and Sergei 3. Zuck 4. Woz 5. Linus

Ranking by coding ability today:
1. Linus 2. Woz 3. Bill 4. Larry and Sergei 5. Zuck

Ranking by coding ability at their peak
1. Bill 2. Woz 3. Linus 4. Larry and Sergei 5. Zuck

Ranking by amount of energy consumed
1. Larry and Sergei 2. Zuck 3. Bill 4. Linus 5. Woz

Ranking by size of the code deriving from original idea
1. Larry and Sergei 2. Linus 3. Bill 4. Zuck 5. Woz

Ranking by technical prowess of first program
1. Woz 2. Bill 3. Linus 4. Larry and Sergei 5. Zuck

Ranking by impact on the world
1. Larry and Sergei 2. Zuck 3. Linus 4. Bill 5. Woz

LLDB is a piece of crap (update: maybe it’s clang) (update 2: it’s actually ccache)

I’ve been really trying to use LLDB for a while now. Not that I really want to, but Apple went out of its way to make sure I had little choice. Not only is LLDB the default on MacOSX now, but GDB is really hard to make work on that platform as well. Can you imagine you have to generate a digital signature?

The first thing I don’t like about LLDB is its totally painful command structure. The LLDB authors published a GDB-to-LLDB conversion map, which they probably think is helpful. But to me, all it shows is that LLDB commands are more complex and more verbose than their GDB counterparts, with no obvious way to infer the LLDB command from either GDB experience, or from any kind of logic.

But the thing I dislike the most is that LLDB plain does not work, even when used with Apple tools, in a number of situations that I happen to hit practically on a daily basis. For example, it appears to be consistently unable to set breakpoints by file name and line number with command-line options that are should be used frequently enough to just work.

Here is an example session that illustrates the problem.

ddd@Marypuce tmp> cat glop.cpp
#include <iostream>

int main()
{
std::cerr << "Hello World\n";
}
ddd@Marypuce tmp> c++ -c -g glop.cpp -mmacosx-version-min=10.6 -o glop.o
ddd@Marypuce tmp> c++ -g glop.o -mmacosx-version-min=10.6 -o glop
ddd@Marypuce tmp> lldb glop
Current executable set to 'glop' (x86_64).
(lldb) b glop.cpp:5
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
(lldb) ^D
ddd@Marypuce tmp> c++ -g glop.cpp -mmacosx-version-min=10.6 -o glop
ddd@Marypuce tmp> lldb glop
Current executable set to 'glop' (x86_64).
(lldb) b glop.cpp:5
Breakpoint 1: where = glop`main + 22 at glop.cpp:5, address = 0x0000000100000e56

[Update] I initially thought the -mmacosx-version-min=10.6 option was necessary for this problem to show up. But it’s also broken without it. I ran the c++ commands with -v to see what the difference was, and apparently, it’s many little things. So separate compilation with debug symbols just does not work. OK, maybe it’s more a compiler thing than a debug thing. So maybe LLDB is not the piece of crap there. Still, that’s where the problems shows up.

This annoying bug shows how fragile this new support is. By making LLDB the default, and integrating it relatively well within Xcode, Apple is trying to slowly boil a frog here. But if you use the tools in a non-standard way, you might be burnt.

[Update 2] I incorrectly blamed clang and lldb for a problem that is actually with ccache. I am running ccache version 3.1.9 from MacPorts. If I get it out of the way, everything is back to normal. I sent a bug report email to the ccache, clang and lldb mailing lists hoping this will help someone else.

5 Genre-Defining Games Forgotten by History

An interesting video talking about genre-defining games. I wrote one of them, Alpha Waves, as described in an earlier article.

The video author does not seem to like the gameplay of Alpha Waves very much. But some people did love it. Just last year, a computer museum in Nice had Alpha Waves running on an Atari ST, and I remember being amazed to see young kids play with it for extended periods of time.