Symmetrical program

From Esolang
Jump to navigation Jump to search

The concept of a symmetrical program is an extension of the concept of a palindromic program into multiple dimensions.

Definition

A symmetrical program in an n-dimensional language has at least one n-1-dimensional surface of symmetry. For example, a symmetrical program in a 2-dimensional language has at least one line of symmetry, and a symmetrical program in a 3-dimensional language has at least one plane of symmetry. A palindromic program is therefore a symmetrical program in a 1-dimensional language.

Symbols in the program may be regarded as self-symmetrical, or alternatively may be associated with their visual representations and hence form symmetrical pairs (for example, an opening bracket may be regarded as the symmetrical partner of a closing bracket, dependent on the direction of symmetry). This is essentially required for palindromic Brainfuck programs.

Non-triviality

Formally, a symmetrical program is regarded as non-trivial if every instruction within it is executed for some input data (but not necessarily the same input data for each instruction). Informally, an additional requirement may be that the program perform some "non-trivial" (that is, complex) task.

Examples

Safalra has produced many symmetrical programs in his language Sansism, of which two examples are given below.

The following Sansism program, exhibiting symmetry around a vertical line, outputs the ASCII or Unicode table and then halts, dependent on the implementation:

 G.G
>G+G>

This may be regarded as trivial in the informal sense. The following more complex Sansism program, exhibiting symmetry around a horizontal line, outputs the string HELLO. The left-hand side demonstrates a generic symmetrical multiplication routine, and the right-hand side demonstrates a generic symmetrical output routine. Note that the output is produced by a six-character loop, but an additional thirty-nine characters are used to guarantee symmetry.

                                                                                                   GG
                                                                                      G + G    G--G +
                                                       GG                              G-G  G  G   +G
>+++++++++++++++++++!!!!!#>#++++!++++!++++!++++!++++!-# G#!----!-------!!!+++##!!!!!##+ +G>!>.!G   --
                                                       GG                              G-G  G  G   +G
                                                                                      G + G    G--G +
                                                                                                   GG

External resources