# Gravity

Gravity was invented by Safalra (Stephen Morley) on 4th August 2005, based on a idea from Isaac Newton. Gravity is very different from any other existing programming language. Although its behavior is well-defined and deterministic, the evolution of its space is in general non-computable, due to the nature of the differential equations that govern it.

## Introduction

The execution of a Gravity program consists of the simulation of the effects of gravity on a countably infinite number of point particles. The initial space configuration is an infinite two-dimensional grid of point particles positioned with one at every point (x,y), where x and y are integers, with all but a finite number of unit mass. When particles collide they are replaced according to a set of collision rules specified by the program. Input, output, and halting can happen only when collisions occur. It can be shown that a Turing machine cannot compute, in the general case, whether even a single collision will ever happen.

## Examples

The language specification states that "comments are not permitted, but each program should ideally be accompanied by a mathematical paper offering a proof that the program behaves in the desired way." The examples below do not include proofs, but these can be found under "External resources".

### Hello World program

The following code is a Gravity Hello, world! program. It outputs ASCII values corresponding to the phrase "Hello world", and then, assuming no input was provided, it halts.

```(0,0) : 2

(1,1,1,1, 2) ->  3 :  72
(1,1,1,1, 3) ->  4 : 101
(1,1,1,1, 4) ->  5 : 108
(1,1,1,1, 5) ->  6 : 108
(1,1,1,1, 6) ->  7 : 111
(1,1,1,1, 7) ->  8 :  32
(1,1,1,1, 8) ->  9 : 119
(1,1,1,1, 9) -> 10 : 111
(1,1,1,1,10) -> 11 : 114
(1,1,1,1,11) -> 12 : 108
(1,1,1,1,12) ->  # : 100
```

### Cat program

The following code is a cat program. The encoding used can be any encoding that maps characters to a series of 3s and 4s (for example, mapping characters to their Unicode positions, and then turning 0 and 1 bits into 3s and 4s respectively).

```(0,0) : 2

(1,1,1,1,2) -> # :
(1,1,1,1,3) -> # : 3
(1,1,1,1,4) -> # : 4
```

### Digital root program

The following code is the first few lines of a digital root program. The program works with the standard ASCII encoding of the digits 0 to 9. The full program is 113 lines long.

```(0,0) : 2

(1,1,1,1, 2)    ->  # :
(1,1,1,1,48)    ->  # : 48
(1,1,1,1,49)    ->  # : 49
(1,1,1,1,50)    ->  # : 50
(1,1,1,1,51)    ->  # : 51
(1,1,1,1,52)    ->  # : 52
(1,1,1,1,53)    ->  # : 53
(1,1,1,1,54)    ->  # : 54
(1,1,1,1,55)    ->  # : 55
(1,1,1,1,56)    ->  # : 56
(1,1,1,1,57)    ->  # : 57
(1,1,1,1,48) 48 -> 48 :
(1,1,1,1,48) 49 -> 49 :
```