1 Langlet Toolkit User Manual Stuart Smith stuart.smith3@comcast.net November 2015 2 Langlet Toolkit User Manual ....................................................... 1 Introduction .................................................................................... 4 The Langlet Transforms ............................................................... 5 cog ............................................................................................................................................................. 5 hel .............................................................................................................................................................. 5 Operations on Arrays .................................................................... 6 bmp ............................................................................................................................................................ 6 bpp ............................................................................................................................................................. 6 bsi .............................................................................................................................................................. 6 bvd ............................................................................................................................................................. 6 bvi .............................................................................................................................................................. 7 ravel ........................................................................................................................................................... 7 reverse........................................................................................................................................................ 7 roi............................................................................................................................................................... 7 suppress ..................................................................................................................................................... 7 Create Arrays ................................................................................. 8 antiI ............................................................................................................................................................ 8 antiZ ........................................................................................................................................................... 8 fanion ......................................................................................................................................................... 8 G ................................................................................................................................................................ 8 Gd .............................................................................................................................................................. 9 Gh .............................................................................................................................................................. 9 Gv .............................................................................................................................................................. 9 I .................................................................................................................................................................. 9 par .............................................................................................................................................................. 9 randm ........................................................................................................................................................10 randp .........................................................................................................................................................10 randv .........................................................................................................................................................10 sequency ...................................................................................................................................................10 walsh .........................................................................................................................................................10 Z................................................................................................................................................................11 Predicates ...................................................................................... 11 ispar ..........................................................................................................................................................11 maj ............................................................................................................................................................11 Pattern Generators ...................................................................... 11 tile .............................................................................................................................................................11 CA.............................................................................................................................................................12 CAinit .......................................................................................................................................................12 Data Conversions ......................................................................... 12 a2b ............................................................................................................................................................12 b2a ............................................................................................................................................................12 3 b2d ............................................................................................................................................................13 b2g ............................................................................................................................................................13 b2w ...........................................................................................................................................................13 c2u ............................................................................................................................................................13 bin2gray ....................................................................................................................................................13 d2b ............................................................................................................................................................14 d2g ............................................................................................................................................................14 g2b ............................................................................................................................................................14 gray2bin ....................................................................................................................................................14 u2c ............................................................................................................................................................15 w2b ...........................................................................................................................................................15 Display Functions ......................................................................... 15 binimg .......................................................................................................................................................15 cdisplay .....................................................................................................................................................15 imdisplay ..................................................................................................................................................16 mdisplay ...................................................................................................................................................16 Formatting .................................................................................... 16 crop ...........................................................................................................................................................16 pad ............................................................................................................................................................16 prep ...........................................................................................................................................................17 Extended Additivity ..................................................................... 17 analyze ......................................................................................................................................................17 synthesize..................................................................................................................................................17 Texture Analysis .......................................................................... 18 texcorrel ....................................................................................................................................................18 texdetect ....................................................................................................................................................18 texfabric ....................................................................................................................................................18 texfind .......................................................................................................................................................18 texmake .....................................................................................................................................................19 textile ........................................................................................................................................................19 Testing ........................................................................................... 19 test_all.......................................................................................................................................................19 theorems....................................................................................................................................................19 Sources .......................................................................................... 21 4 Introduction The Langlet Toolkit is a collection of Matlab functions I developed to help myself understand and explore Gerard Langlet’s ideas about computation. Langlet himself wrote toolkits like this one in APL, a programming language he believed gave an entirely new perspective on what scientific and engineering computing could be. I agree with Langlet’s general point that APL does make it much easier to think about solutions to the kinds of problems he was interested in solving, but I myself prefer a lesser-known programming language called “Q’Nial”, which was written by Mike Jenkins of Queens University. Q’Nial and APL2 (IBM’s current APL product) are both based on Trenchard More’s array theory. I used Matlab for this toolkit because it is a standard tool in science and engineering, and because I have been using it almost exclusively in my own teaching and research for the last several years. Langlet presents a black-or-white “topological universe.” Every point in this universe can be described by a list of attributes, each of which is capable of taking on only one or the other of two possible values, conventionally designated as 0 and 1. All mathematical operations are done in the boolean field, with exclusive-or as addition and logical-and as multiplication. While these constraints lead to some radical simplifications in computation, they leave open the question of how to deal with quantities that vary continuously or are at least capable of taking on more than two different values. Binary approximations of such quantities are of course available, but their use detracts from the coherence of Langlet’s system, which depends upon the requirement that the key operations are all exactly reversible (i.e., each function has an exact inverse). This Toolkit implements all of the exactly reversible functions (the transforms, the array operations and the data conversions). At the end of this manual is a list of sources for Langlet’s writings. Anyone who is interested in trying out Langlet-style computation should read “Towards the ultimate APL-TOE “, “The Fractal MAGIC Universe”, and “The Axiom Waltz”. Langlet’s French is notoriously difficult to translate; however, these three papers provide a reasonably readable starting point for understanding his thought. It probably helps to have in mind problems you might like to try to solve with Langlet’s methods. This will give you something concrete to work on as you learn Langlet’s approach to computing. In my own case, I thought I might get some interesting results in binary image processing and in processing SACD audio recordings. These seemed to be obvious application areas. So far I’ve had a little success with the former, none with the latter. Some more recent work with visual textures has produced a few interesting results. In the last few years I’ve come to see that Wolfram’s A New Kind of Science offers a more comprehensive approach to the kind of computing Langlet wanted to do. While this book is still somewhat controversial because of Wolfram’s “experimental” approach to mathematics, it has nonetheless stimulated research across virtually all of the sciences. Langlet, for better or worse, never had this kind of wide acceptance; however, I hope readers will nonetheless find something interesting to experiment with here. 5 The Langlet Transforms Langlet’s Helical and Cognitive transforms are key components of his computational system. Several variants of each are available in the Toolkit. The variants serve different purposes and satisfy different requirements, as summarized in the following table. Function Name hel, cog ghel, gcog fanhel, fancog hel2, cog2 Lhel, Lcog rhel, rcog xhel, xcog Argument boolean vector or matrix, dimensions a power of 2 boolean vector or marix boolean vector of any length square boolean matrix with side a power of 2 boolean vector whose length is a power of 2 boolean vector whose length is a power of 2 boolean matrix with arbitrary dimensions Comments input argument will be padded to power of 2 dimensions Langlet’s fast recursive divide-and-conquer algorithm Fast recursive divide-andconquer algorithm These use fanhel and fancog to handle arrays with arbitrary dimensions cog Langlet's Cognitive transform r = cog( s ) Input: s = vector or matrix of 1's and 0's, dimensions a power of 2 Output: r = Cognitive transform of s See also gcog, fancog, cog2, Lcog, rcog, and xcog in the Toolkit code. hel Langlet's Helix transform r = hel( s ) Input: s = vector or matrix of 1's and 0's, dimensions a power of 2 Output: r = Helical transform of s See also ghel, fanhel, hel2, Lhel, rhel, and xhel in the Toolkit code. 6 Operations on Arrays bmp Boolean inner product y = bmp( a , b ) Inputs: a , b = conformable boolean arrays Output: y = boolean inner product of a and b bpp Raise a boolean matrix to a given power. y = bpp( m , n ) Inputs: m = square boolean matrix n = power Output: y = m raised to the nth power bsi Scalar integral. The modulo-2 sum of a boolean vector. In APL-family languages this would be done with not-equal reduce. y = bsi( x ) Input: x = vector of 1's and 0's Output: y = modulo-2 sum of x (can also be interpreted as the parity of x) bvd Parity differential. This is the same as the binary-to-graycode conversion of a vector of 1's and 0's. bvd is the inverse of bvi. y = bvd( x ) Input: x = vector of 1's and 0's Output: y = boolean vector differential of x 7 bvi Parity integral. In APL-family languages this would be done with not-equal scan. Langlet's binary vector integral (bvi) is the same as the graycode-to-binary conversion of a vector of 1's and 0's. bvi is the inverse of bvd. y = bvi( x ) Input: x = vector of 1's and 0's Output: y = modulo-2 cumulative sum of x ravel Ravels a matrix into a vector in column-major order. y = ravel( x ) Input: x = any matrix Output: y = x raveled into a vector in column-major order reverse Reverses the order of the items in a vector y = reverse( x ) Input: x = any vector Output: y = reversed vector roi Extracts a square region of interest from an image y = roi( m , tlc , side ) Inputs: m = input image tlc = 2-element vector containing the coordinates of the top left corner of the ROI side = length of side of the ROI Output: y = matrix containing the region of interest suppress Removes the last row and first column of matrix x. If x == G(n), the transformational properties of G will be preserved. y = suppress( x ) 8 Input: x = square matrix of 1's and 0's Output: matrix x with the last row and first column removed See also nsuppress in the Toolkit code. Create Arrays antiI Generates the Anti-identity matrix with side = n y = antiI( n ) Input: n = side of the desired matrix Output: y = n x n boolean matrix with 1's only on the main anti-diagonal antiZ Creates the square Anti-zero (all ones) matrix with side = n y = antiZ( n ) Input: n = length of the side of the matrix Output: y = n x n all-1's matrix fanion Constructs "fanion" of a boolean vector r = fanion( s ) Input: s = vector of 1's and 0's Output: r = the fanion of s, displayed with fandisp G Creates Langlet's G matrix, or “geniton” y = G( n ) Input: n = order of G (a square matrix) Output: y = G matrix of the specified order 9 Gd Creates Langlet's Gd matrix y = Gd( n ) Input: n = order of Gd (a square matrix) Output: y = Gd matrix of the specified order Gh Creates Langlet's Gh matrix and Wolfram’s basic Rule 60 pattern y = Gh( n ) Input: n = order of Gh (a square matrix) Output: y = Gh matrix of the specified order Gv Creates Langlet's Gv matrix y = Gv( n ) Input: n = order of Gv (a square matrix) Output: y = Gv matrix of the specified order I Generates the identity matrix with side = n y = I( n ) Input: n = length of the side of the output matrix Output: y = order-n identity matrix par Construct a pariton from a vector of 1's and 0's y = par( s ) Input: s = vector of 1's and 0's (length is usually a power of 2) Output: y = the pariton of s 10 randm Creates a random boolean matrix with side = n y = randm( n , p ) Input: n = length of the side of the output matrix p = approximate fraction of 1’s in y, 0<p<1 Output: y = random matrix of 1's and 0's randp Creates a random pariton with side = n y = randp( n ) Input: n = length of the side of the pariton p = approximate fraction of 1’s in y, 0<p<1 Output: y = random pariton with side = n randv Creates a random boolean vector of length n y = randv( n , p ) Input: n = length of the output vector p = approximate fraction of 1’s in y, 0<p<1 Output: y = length-n random vector of 1's and 0's sequency Creates an order-n boolean hadamard matrix with sequency ordering y = sequency( n ) Input: n = order of the output matrix Output: y = sequency-ordered hadamard matrix with side = n, boolean values walsh Generates a boolean Hadamard matrix with "natural" ordering. y = walsh( n ) Input: n = length of the side of the output matrix Output: 11 y = order-n Hadamard matrix, boolean values Z Generates the all-zeroes matrix with side = n y = Z( n ) Input: n = length of the side of output matrix Output: y = square all-zeroes matrix with side = n Predicates ispar Determines whether a given matrix is a pariton res = ispar( m ) Input: m = square matrix of 1's and 0's Output: res = 1 if m is a pariton, 0 otherwise maj Langlet's majority function. Returns 1 if the matrix argument contains more 1's than 0's; otherwise it returns 0. maj does not have an inverse. y = maj( x ) Input: x = square matrix of 1's and 0's Output: y = 1 if the matrix argument contains more 1's than 0's; otherwise it returns 0. Pattern Generators tile Creates 2×2 2-symbol L-system tiling patterns res = tile( logN , black , white ) Inputs: logN black white Output: res = number of iterations (each iteration doubles the side of res) = the initial pattern and the replacement for "1" squares = the replacement for white, or "0", squares. = binary matrix representing the desired image The 2×2 input patterns are specified as decimal numbers, 0-15, which are translated by the program into 4-bit binary numbers. The first two 12 bits are the top row of a 2×2 pattern, and the last two bits are the bottom row. CA Wolfram's elementary one-dimensional cellular automaton Inputs: rule = 0-255 (see A New Kind of Science for information about rules) x = initial conditions (boolean vector) Output: y = evolution of the cellular automaton for length(x)/2 steps Statement [22] can be un-commented to allow the program to remove large areas of empty cells on either side of the result. CAinit Creates the "standard" initial conditions for Wolfram's elementary cellular automaton Input: n = width in cells either side of the initial "1" (remaining cell are zero) Output: y = vector of initial conditions Data Conversions a2b Converts a quoted string of characters into a vector containing the corresponding binary codes. res = a2b( s ) Input: s = quoted string of characters Output: res = vector of the corresponding binary codes b2a Converts a vector containing 8-bit character codes into a string of the corresponding characters. res = b2a( x ) Input: x = vector of 8-bit character codes Output: res = character string corresponding to x 13 b2d Convert a vector of 1's and 0's representing a binary number into the corresponding decimal number y = b2d( x ) Input: x = vector of 1's and 0's Output: y = decimal number corresponding to x b2g Converts a vector of 1's and 0's representing a binary number into the corresponding gray code y = b2g( x ) Input: x = vector of 1's and 0's representing a binary number Output: y = vector of 1’s and 0’s representing the gray code corresponding to x b2w Converts a vector of 1's and 0's into the corresponding Walsh representation (i.e., -1 and +1) y = b2w( x ) Input: x = vector of 1's and 0's Output: y = corresponding Walsh representation c2u Converts a character string into a vector of 1's and 0's representing the corresponding binary codes (uint8). y = c2u( c ) Input: c = quoted character string Output: y = vector representing the corresponding binary codes bin2gray Converts a vector of 1's and 0's representing a binary number into the character-string representation of the corresponding gray code g = bin2gray( b ) 14 Input: b = vector of 1's and 0's representing a binary number Output: g = character string representing the gray code corresponding to b d2b Converts a decimal number to a length-n vector of 1's and 0's representing the corresponding binary number y = d2b( x , n ) Input: x = decimal number to be converted n = number of bits in the binary representation of x Output: y = length-n vector of 1’s and 0’s representing x as a binary number d2g Convert a decimal integer to the corresponding n-bit gray code y = d2g( x , n ) Input: x = decimal integer n = bit width of gray code Output: y = vector containing the n-bit gray code corresponding to x g2b Convert a gray code represented as a vector of 1's and 0's to a vector of 1's and 0's representing the corresponding binary number y = g2b( x ) Input: x = vector of 1's and 0's representing a gray code Output: y = vector of 1's and 0's representing the binary number corresponding to x gray2bin Converts a gray code represented as a vector of 1's and 0's to a character string representing the corresponding binary number b = gray2bin( g ) Input: g = vector of 1's and 0's representing a gray code Output: b = character string representing the corresponding binary number 15 u2c Segments a vector of 1's and 0's into bytes and converts the bytes into a vector of the corresponding characters. This is the inverse of c2u. y = u2c( b ) Input: b = vector of 1's and 0's assumed to be character codes (uint8) Output: y = vector of characters corresponding to b w2b walsh to boolean conversion y = w2b( x ) Input: x = vector or matrix containing only -1 and +1 values Output: y = vector or matrix containing only 0 and 1 values Display Functions binimg Write the binary image of boolean array x to .gif file filename binimg( x , file ) Input: x = 1- or 2-dimensional array of boolean values Output: file = pathname of file containing the binary image cdisplay Q'Nial-style compact display of boolean array m using "l" for true, "o" for false cdisplay( m ) Input: m = array of 1's and 0's Output: Compact display of a boolean array m 16 imdisplay Displays a binary image imdisplay( x ) Input: x = matrix of 1's and 0's Output: Binary (black and white) picture representing x mdisplay Compact numeric display of a boolean array mdisplay( x ) Input: x = array of 1's and 0's Output: Compact display of boolean array x Formatting crop Crop a matrix representing a binary image to the smallest rectangle that encloses all the 1 pixels. y = crop( m ) Input: m = matrix to be cropped Output: y = cropped matrix pad Pad a matrix or vector with zeroes. If the input is a matrix, the result will be padded with zeroes to make a square matrix whose side is the smallest power of 2 not less than the length of the longer side of the input matrix. If the input is a vector, the result will be a vector padded with zeroes to make the length of the result the smallest power of 2 not less than the length of the input vector. y = pad( m ) Input: m = any vector or matrix Output: y = m padded with zeroes 17 prep crop and pad a matrix to fit in the smallest square with side a power of 2 y = prep( m ) Input: m = any matrix Output: y = m padded to fit in the smallest square with side a power of 2 Extended Additivity The two functions in this section illustrate how the “additive” property possessed by certain basic patterns produced by Wolfram’s elementary one-dimensional cellular automaton extends into two dimensions. Rotated or shifted instances of the Rule 60 pattern (which can be generated with the Gh function above) can be added together to produce any square boolean matrix. The analyze function reveals which instances must be added together to produce a given matrix, while the synthesize function reconstructs the original matrix from the analysis. analyze analyzes a square boolean matrix and returns a matrix result; the inverse of synthesize. y = analyze( x ) Input: x = a square boolean matrix whose side is a power of 2 Output: y = boolean matrix representing the analysis of x See also the code for anal in the Toolkit. synthesize reconstructs the square boolean matrix analyzed by analyze; the inverse of analyze. y = synthesize( x ) Input: x = a square boolean matrix representing an analysis Output: y = reconstructed matrix represented by the analysis of x See also the code for synth in the Toolkit. 18 Texture Analysis This section is under construction. texcorrel Estimates the horizontal and vertical periods of a tiled binary image [ yh , yv ] = texcorrel( img ) ; Inputs: img : a binary image Output: yh : estimated horizontal period yv : estimated vertical period texdetect Attempts to find a figure in a binary image of a visual texture in which the individual texture elements contain corrupted pixels, i.e., the image is somewhat noisy. This function can usually extract the figure from an image in which up to about 15% of the pixels over the entire image are corrupt. y = texdetect( img , fn ) Inputs: img : input image fn : 'hel' or 'cog' Output: y : image in which the figure buried in img may be visible texfabric Demo to illustrate how the Helical or Cognitive transform can be used To create an idealized version of a fabric or tile pattern from a patch that does not consist exclusively of exact repetitions of the pattern. y = texfabric( file , fn ) Inputs: file: the full pathname of a .gif file containing the image of a section of tile or fabric. fn : ‘hel’ or’cog’ Output: Y: a section of tile or fabric constructed from exact instances of the pattern discovered texfind Extracts an estimated texture element from a binary image texel = texfind( img , fn ) Inputs: img = input image 19 fn = 'hel' or 'cog' Output: texel = estimate of the texture element from which the image is constructed texmake Creates a noisy textured image with an embedded figure; for use in testing the other tex functions function y = texmake( xin , pat , p ) Inputs: xin : an image containing the figure to be embedded pat : the texture element used to build the background p : the fraction of noise pixels over the whole image. 0<=p<=1. p<=0.15 will generally allow texmake to find the figure. Output: y : noisy image with embedded figure textile Forms a rectangular binary image by tiling with a given pattern y = textile( pat , rows , cols ) Inputs: pat : rows : cols : Output: y : a binary image representing the tile the number of tiles in a row of the output image the number of tiles in a column of the output image the tiled image Testing test_all This function tests all of the major functions in the Toolkit. If you get a clean run, the Toolkit will work successfully on your system. theorems This function tests 22 theorems from, or derived from, Langlet's "The Ultimate APL-TOE" paper. The tests can be completed in a reasonable amount of time for n = 2, 4, 8, or 16. After 16 it takes a REALLY long time. test_all( n ) The theorems are as follows: [1] [2] [3] [4] [5] [6] hel( hel( S ) cog( cog( S ) hel( S ) <==> cog( S ) <==> reverse( hel( reverse( cog( ) <==> S ) <==> S reverse( cog( reverse( S reverse( hel( reverse( S S ) ) <==> cog( reverse( S ) ) <==> hel( reverse( ) ) S S ) ) ) ) ) ) ) ) 20 [7] hel( reverse( cog( S ) ) ) <==> reverse( S ) [8] cog( reverse( hel( S ) ) ) <==> reverse( S ) [9] hel( reverse( cog( S ) ) ) <==> cog( reverse( hel S ) ) [10] cog( reverse( hel( S ) ) ) <==> hel( reverse( cog( S ) ) ) [11] hel( S ) <==> bmp( S , Gv( n ) ) [12] cog( S ) <==> bmp( S , Gh( n ) ) [13] hel( S ) <==> reverse( bmp( S , G( n ) ) ) [14] cog( S ) <==> bmp( reverse( S ) , G( n ) ) [15] hel( s ) <==> bmp( cog( S ) , G( n ) ) [16] cog( S ) <==> reverse( bmp( reverse( hel( S ) ) , G( n ) ) ) [17] S <==> hel( bmp( S , Gv( n ) ) ) [18] S <==> cog( bmp( S , Gh( n ) ) ) [19] S <==> reverse( bmp( hel( S ) , G( n ) ) ) [20] S <==> ( bmp( reverse( cog( S ) ) , G( n ) ) ) [21] Replacement Theorem The Replacement Theorem states that if each 1 in a pariton is replaced by G, and each 0 is replaced by a 2x2 zero matrix, the result will still be a pariton. [22] Cogniton Theorem The Cogniton Theorem states that a pariton can be completely reconstructed from just its rightmost column ("Cogniton"). [23] Some additional relationships between the Helical and Cognitive transforms. 21 Sources Proceedings Towards the ultimate APL-TOE. APL '92 Proceedings of the international conference on APL Pages 118 - 134 ACM New York, NY, USA ©1992 Newsletter Towards the ultimate APL-TOE. ACM SIGAPL APL Quote Quad Volume 23 Issue 1, July 1992 Pages 118 - 134 ACM New York, NY, USA Articles published in Vector, the journal of the British APL Association Gérard Langlet: A Man of Distinction, Sylvia Camacho, 22:2, p.56 Obituary: Memories of Gérard Langlet, Anthony Camacho, 13:4 Paritons and Cognitons: Towards a New Theory of Information, Gérard Langlet, 19:3, p.93 Obituary: Memories of Gérard Langlet (compiled Camacho), Gérard Langlet, 13:4, p.138 A Quite Different New Primitive, Gérard Langlet, 12:1, p.93 Letter: More Thoughts on Dragons, Gérard Langlet, 12:1, p.121 Letter: Non-syllogistic mathematical proof, Gérard Langlet, 12:1, p.123 Letter: Non-Syllogistic Mathematical Proof, Gérard Langlet, 12:1, p.123 The APL Theory of Human Vision, Gérard Langlet, 11:3, p.42 The Axiom Waltz – or When 1+1 make Zero, Gérard Langlet, 11:3, p.101 Editorial: Monsieur Langlet’s Enterprise, Anthony Camacho, 11:2, p.3 APL94: Binary Algebra Workshop, Gérard Langlet, 11:2, p.60 Chaotic behaviour revisited, Gérard Langlet, 11:2, p.82 [PDF] Editorial: Monsieur Langlet's Enterprise, Anthony Camacho, 11:2 The Ultimate Turing Proof, Gérard Langlet, 10:3, p.124 The Fractal MAGIC Universe, Gérard Langlet, 10:1, p.137 From the Vital Execute to Fractals and 5-fold Symmetry, Gérard Langlet, 9:3, p.91 Recreation with Transcendental Numbers, Gérard Langlet, 8:2, p.25 The Steam Hammer and the Fly, Gérard Langlet, 7:4, p.138 APL “RISC Programming Style”, Gérard Langlet, 6:2, p.23 APL "RISC Programming Style", Gérard Langlet, 6:2 Books Michael Zaus. Crisp and Soft Computing with Hypercubical Calculus: New Approaches to Modeling in Cognitive Science and Technology with Parity Logic, Fuzzy Logic, and Evolutionary Computing: Volume 27 of Studies in Fuzziness and Soft Computing. Physica-Verlag HD, 1999. Stephen Wolfram. A New Kind of Science. Wolfram Media, 2002.