Difference between revisions of "PEGWiki:Notational conventions"
From PEGWiki
(Created page with 'This page documents some conventions to be followed when writing pseudocode on PEGWiki. These are not binding policy on PEGWiki, but following them should minimize confusion and …') |
m (→Math-mode pseudocode) |
||
Line 14: | Line 14: | ||
=Math-mode pseudocode= | =Math-mode pseudocode= | ||
* The LaTeX \sqrt command is almost always preferable to typing out <math>\operatorname{sqrt}</math>. | * The LaTeX \sqrt command is almost always preferable to typing out <math>\operatorname{sqrt}</math>. | ||
− | * The vinculum (horizontal bar) to indicate division is usually best, but if the numerator or denominator is complex, a single slash <math>/</math> is preferable when it improves readability or overall aesthetic appeal. | + | * The vinculum (horizontal bar) to indicate division (produced by the \frac command) is usually best, but if the numerator or denominator is complex, a single slash <math>/</math> is preferable when it improves readability or overall aesthetic appeal. |
* Exponentiation should ''always'' occur in the form <math>a^b</math> rather than in the form <math>a</math>^<math>b</math>. When the exponent is so complex that superscripting makes the expression look ugly, use a temporary variable for the exponent. The exception is when the base is <math>e</math>: you can replace <math>e^x</math> with <math>\exp(x)</math> in that case. | * Exponentiation should ''always'' occur in the form <math>a^b</math> rather than in the form <math>a</math>^<math>b</math>. When the exponent is so complex that superscripting makes the expression look ugly, use a temporary variable for the exponent. The exception is when the base is <math>e</math>: you can replace <math>e^x</math> with <math>\exp(x)</math> in that case. | ||
* Actual words, such as "if" and "and", should not be italicized. Use the \mathrm function to de-italicize them. | * Actual words, such as "if" and "and", should not be italicized. Use the \mathrm function to de-italicize them. | ||
* Equality testing should occur through the <math>=</math> symbol. | * Equality testing should occur through the <math>=</math> symbol. | ||
* Variable assignment should occur through the <math>\gets</math> symbol (LaTeX code: "\gets") | * Variable assignment should occur through the <math>\gets</math> symbol (LaTeX code: "\gets") |
Revision as of 22:14, 14 November 2009
This page documents some conventions to be followed when writing pseudocode on PEGWiki. These are not binding policy on PEGWiki, but following them should minimize confusion and promote consistency across articles. Similarly, if you see unfamiliar notation in a pseudocode block, you may find its meaning here. Changes to these conventions should be discussed on the talk page.
All pseudocode
- Structure should be indicated by indentation, as in Python. Adding braces
{}
as in C or words such asbegin
andend
as in Pascal would introduce unnecessary clutter into pseudocode blocks. Do not use tabs for indentation. Five spaces is a good guideline. (In LaTeX pseudocode, this means five full-width spaces (a full-width space is "\ ").) - The
for
,if
/else
, andwhile
statements should not be followed by words like "do" or "then"; pseudocode is intended for humans, not machines. - Indices into arrays should be placed in square brackets,
[]
. The Pascal convention of separating indices by commas is preferred to the C convention of having a separate set of brackets for each index (simply by virtue of being nicer and more intuitive), but the latter may be occasionally appropriate to reinforce the interpretation of the array's structure. Use your common sense. - Parameter lists should be enclosed in parentheses,
()
, and parameters should be separated by commas.
Text-mode pseudocode
- Variable assignment should occur through the use of a single equals sign,
=
, although the Pascal notation of:=
is also acceptable. - Equality testing should also occur through the use of a single equals sign,
=
, but is distinguished from variable assignment by context. For example, if it is preceded byif
, it is an equality test, and if it stands alone, it is an assignment. The C notation of==
should be avoided. - The symbols
<=
/>=
and≤/≥
are equally acceptable, but in most other cases a Unicode symbol should be used whenever both necessary and possible. For example,oo
for∞
is unacceptable.
Math-mode pseudocode
- The LaTeX \sqrt command is almost always preferable to typing out .
- The vinculum (horizontal bar) to indicate division (produced by the \frac command) is usually best, but if the numerator or denominator is complex, a single slash is preferable when it improves readability or overall aesthetic appeal.
- Exponentiation should always occur in the form rather than in the form ^. When the exponent is so complex that superscripting makes the expression look ugly, use a temporary variable for the exponent. The exception is when the base is : you can replace with in that case.
- Actual words, such as "if" and "and", should not be italicized. Use the \mathrm function to de-italicize them.
- Equality testing should occur through the symbol.
- Variable assignment should occur through the symbol (LaTeX code: "\gets")