Logiweb(TM)

2.3 The Logiweb source language (lgs)

Prev Up Next Page 6 of 800 Search internet


Logiweb has two kinds of human users: authors and readers. When you click the combinations link and read the pdf you are a reader. When you write your own Logiweb pages, you are an author. Hence, programmers are called 'authors' in Logiweb terminology.

As an author, you express Logiweb pages in the Logiweb source language (lgs) and run them through the Logiweb compiler (lgc). For the source text of the combinations page see the combinations.lgs file.

Here comes a snippet from the source file. I added the line numbers.

    27  \section{Combinations}
    28  The number of combinations of size "[[ k ]]" from a set
    29  of size "[[ n ]]" is given by the binomial coefficient
    30  "[[ (( n , k )) = n factorial div k factorial
    31  div ( n - k ) factorial ]]". A recursive definition
    32  of "[[ (( n , k )) ]]" may be stated thus:
    33  "[[[ value define (( n , k )) as if k = 0 then 1
    34  else (( n - 1 , k - 1 )) * n div k end define ]]]"
    35  As an example, we have "[[ ttst (( 4 , 2 )) = 6 end test ]]".
    36  For details on how the binomial coefficient is rendered, see
    37  \cite{appendix}.

This is just plain text with some math in it. Or, rather, it is plain LaTeX as you can see in Line 37.

Math is expressed in lgs. "[[...]]" corresponds to $...$ in LaTeX and "[[[...]]]" corresponds to $$...$$.

Author defined syntax

As you can see, (( n , k )) denotes the binomial coefficient. That notation for binomial coefficients is not hardwired into lgs. Rather, the author of the combinations page defined that syntax in Line 6 and 7 of the source file:

     1  "";;0143BAB3BC67212340C9406BDB560819F3DCD4E859FC96F7B1C2B2BB0806
     2  ""P combinations
     3  
     4  ""R base
     5  
     6  ""D 0
     7  (( " , " ))

The double quote character is a reserved character in lgs. Actually, it is the only reserved character in lgs. That the double quote character is reserved is one of the very few things you cannot change in lgs. Otherwise, lgs is very flexible.

The double quote character is used for many different purposes. We shall refer to a sequence of two or more double quotes as a multiquote and to a multiquote followed by one non-quote as an escape sequence.

Line 6 contains a ""D escape sequence where D stands for Definition. We shall refer to the lines following a ""D escape sequence and until the next ""D, ""B, ""R, or ""P escape sequence as a 'charge section'.

Each line of a charge section defines a syntactic construct. In syntactic constructs, single double quotes are used as placeholders. Hence, the syntactic construct (( " , " )) allows you to write (( n , k )) where you can replace n and k by arbitrary wellformed formulas.

The number following ""D in Line 6 is a 'charge'. Constructs with a high charge has low priority and vice versa. So 'charge' is the exact opposite as 'priority'. As an example, p + q has greater charge than p * q so p * q + r * s means ( p * q ) + ( r * s ). Charges are dotted sequences of integers like 7.9.13 and charges are ordered lexicographically so that charge 7.9.13 is smaller than 7.11.

The binomial coefficient (( " , " )) neither starts nor ends with a double quote character, so the charge has no effect. By convention, such constructs should have charge zero.

Author defined rendering

The rendering of the binomial coefficient is defined in Line 47 to 50 of the lgs source:

    45  \section{\TeX\ definitions}
    46  \begin{statements}
    47  \item "[[ tex show define (( n , k )) as "
    48  \left( \begin{array}{l} "[ n ]"
    49  \\ "[ k ]"
    50  \end{array}\right)" end define ]]"
    51  \end{statements}

The 'TeX definitions' section ends up in the appendix of the combinations page.

The tex show define ... as ... end define construct in Line 47 to 50 defines the rendering of the binomial coefficient.

The tex show definition is included in "[[...]]" as usual. Inside the right hand side of the definition, the lgs variables n and k are enclosed in "[...]". "[...]" is like "[[...]]" except that "[[...]]" produces a LaTeX $...$ whereas "[...]" does not change to or from TeX math mode.

Prev Up Next Page 6 of 800 Search logiweb.eu

Copyright © 2010 Klaus Grue, GRD-2010-01-05