Pattern

{PatternSet, LogicalPatternSet, Introduction, PatternSequence,

PatternType, PatternTypeSequence, Rule}

 

 

(0)                    Pattern

 

...is a frequently used suffix or prefix keyword modifier.

 

Pattern[Noop] is the Pattern matching nothing.

Pattern[] (also written as "_") matches any Expression.

 

Pattern[Set] matches every PatternSet.

Constructions with the form...

(True | Not | Or | And | Xor)[__patternSetï]

...are called LogicalPatternSets.  They do Set logic with PatternSets.

 

Pattern[Sequence] (also written as "__")

...matches any Expression Sequence.

Pattern[patForm] (also written as "_[patForm]")

...matches anything with the PatternForm patForm.

Pattern[patForm][Sequence] (also written as "...patForm...")

...matches the sequence whose elements match patForm.

Pattern[Type[head]] (also written as "_head")

...matches Expressions with (Head), head.

 

A Rule applies doIfMatch, to any input matching (PatternSet) ptrnSet:

ptrnSet -> doIfMatch

The above elicitation is the Standard ASCII RuleList shorthand for,

If[ptrnSet, doIfMatch]

The fully general Rule form:

If[ptrnSet, match, noMatch]

 

In addition to the above compilation of Pattern[...]-elicitations, the "NamePattern" is an attribute assigned to any Name that requires conformance with a syntax. The NamePattern is a subject in Name's definition, and is not specified here.

 

See English Definition of "pattern".

 

 

 

The Pattern Matching Nothing

 

(1)            Pattern[Noop]

 

...designates the Pattern matching nothing.  It matches a Sequence with no elements.

 

LogicalPatternSets use Pattern[Noop] to expand the meaning of a PatternSequence or PatternTypeSequence to include the possibility of no elements

 

Pattern[Noop] is interpreted as the PatternSet matching no-element.

For example, the following matches nothing or the PatternSequence with elements matching expr.

 

                        Or[Pattern[Noop], Pattern[expr][Sequence]]

 

In the above, the presence of the two Patterns in Or[...]'s argument sequence, makes it a LogicalPatternSet. 

 

 

PatternSet

 

The Pattern and the Set both compare an Expression and return True or False depending on whether the Expression matches or is included in a setThe difference between a Set and a Pattern, is that a Pattern specifies a form, while a Set is a construct which can be interpreted as a form

 

This distinction is blurred when Patterns and Sets are combined in a LogicalPatternSet.
A PatternSet is something which evaluates as True or False based on its input.

 

The Set, a Pattern, or a combination of the two (as in the LogicalPatternSet), are all PatternSets.

If ptrnSet is any PatternSet, then the following SubstitutionName, (_Type[_,_]-construct), is also a PatternSet:

 

                        Type[nam, ptrnSet]

 

Any Expression can be tested to determine if it is a PatternSet.
For example, suppose
patSet is something that might be a PatternSet, then the elicitation...

 

(2)                    Pattern[Set][patSet]

 

...returns True if patSet is a PatternSet and False otherwise.

 

Any subset of the PatternSet, patrnSet, or any Pattern which matches patrnSet, or any combination of subsets and subpatterns in patrnSet, is a subPatternSet.

 

 

input


                    Pattern[patForm]


...compares the input to the PatternForm, patForm, and returns True if there is a match, and False otherwise.
A Pattern's input is the object compared to the PatternForm.
It is either implied from the syntax of the containing construct, or the input is explicitly the right-most bracketed part of the Pattern-construct.

 

For example, a Branch construct with an odd number of arguments, has a PatternSet in each even argument, which each use the first argument as the input.

 

Similarly, the PatternSet in the 2nd argument in...

 

                        Type[subNam, Pattern[patForm]]

 

...uses an elicitation's argument as input which is compared to patForm to decide if this input should be substituted wherever subNam occurs in the rest of the containing construct.  See Rules below.

 

When a Pattern[...] is used where the syntax does not unambiguously identify the compared input, the test input (if it is present) is the Pattern[...]'s rightmost bracketed expression.

 

 

Named Patterns

 

Like any Expression, Patterns may be Named:


                    Name[patNam, Pattern[patForm]]

 

Here, patNam will be Reckoned (interpreted) by substituting patNam with Pattern[patForm].  Consequently, given the above assignment,

 

            patNam[testObj]

 

...evaluates to True or False depending on whether testObj matches patForm or not.

 

 

Logical Pattern Sets

 

It is natural to use Patterns or Sets in `Logic` constructions because they have boolean results.  When a Pattern or Set is an argument in a True[...], Not[...], Or[...], And[...], or Xor[...] Expression, it makes that `Logic` keyword into a LogicalPatternSet.  Such a construct is a PatternSet despite its `Logic`-keyword Head.

 

A LogicalPatternSet behaves in every way like a Set or Pattern except it has a `Logic` Keyword at its Head rather then "Pattern" or "Set".  If patternOrSet is a Named or literal PatternSet, then a LogicalPatternSet has the following form:

 

(3)                  logic[__patternOrSet]

 

...where logic is True, Not, Or, And, or Xor.

 

An element in a LogicalPatternSet such as (3), may be a Set or anything which returns a boolean result.  Both Set and Pattern elements presume an input (to compare and return True or False). Thus a LogicalPatternSet is a PatternSet.

 

The details of each LogicalPatternSet are documented with their respective `Logic` Keyword.

 

 

 

Expression matching

 

(4)            Pattern[]

 

...or, (using the Standard ASCII RuleList),

 

                                                _

 

...matches any Expression  (See Mathematica's Blank.)

 

The PatternForm is the contents of Pattern[...]'s brackets.

Suppose ptrnForm is any Expression, possibly containing Patterns in subExpression(s), then...

 

(5)            Pattern[ptrnForm]

 

...returns True if ptrnForm matches the input.

 

The PatternForm, ptrnForm, in (5) is written using the Standard ASCII RuleList, as...

 

                                                _[ptrnForm]


 

Within the PatternForm, there is a special interpretation environment...

The PatternForm is taken literally and never evaluated with the exception of any Pattern[...] within the Pattern-construct, whose PatternForm is compared to the indicated input subExpression.  In other words, within a PatternForm, everything is interpreted literally with the exception of Pattern[...] subExpressions.  These subPatterns must match their indicated subExpressions if the larger containing Pattern is to match.

 

The only exception to this rule is if...

 

(6)                        Not[Reckon][form]

 

...is a subExpression in a PatternForm.
If an expression like (6) occurs within a
PatternForm, then form will be treated literally like everything else in the PatternForm, even if form is a Pattern.

 

When a Pattern[...] is compared to the input, the Pattern is evaluated to whatever depth is required to determine if there is a match.  This process proceeds along the ExpressionEvaluationTree.

 

 

 

PatternSequence

 

(7)            Pattern[Sequence]


...also written as

                 __

 

...matches any sequence of Expressions.

This form is combined with SubstitutionNames in this related form....

 

(8)            subName__

 

...which is (formally interpreted by the Standard ASCII RuleList as)...

 

(9)            Type[subName, Pattern[Sequence]]

 

"subName__" is a nice shorthand for importing a SubstitutionNamed Sequence.

 

If each element of a Sequence matches some form, it will match a PatternSequence written as follows...

 

 

(10)            Pattern[patForm][Sequence]


...also written as

                   __[patForm]

 

...matches any Sequence of Expressions matching the PatternForm, patForm.  One or more Patterns may be nested in patForm whose evaluation conforms to the special interpretation environment described above.



 

PatternType

 

Often, a Pattern is referred by its Type or Head.  This is accomplished with the following construction:

 

(11)            Pattern[Type[head]]


...also written as


                   _head

 

...evaluates True when compared to any Expression with Head matching head.

 

The above construction is called a PatternType

 

 

 

PatternTypeSequence

 

The PatternTypeSequence has the following form:

 

(12)            Pattern[Type[head]][Sequence]


...also written as

                                                __head

 

...matches a Sequence of one or more Expressions with Head "head".

 

 

 

Rule

 

If ptrnSet is a PatternSet, the form below is called a Rule.

 

(13)            If[ptrnSet, match]

 

In the Standard ASCII RuleList (13) is written as...

 

                                    ptrnSet -> match

 

A Rule behaves like a PatternSet insofar as it expects input to compare to ptrnSet.

A Rule is unlike a PatternSet insofar as it does not generally return a boolean result. 

 

The Rule has a more general form:

 

(14)            If[ptrnSet, match, noMatch]

 

If ptrnSet matches the input, match is returned; otherwise noMatch is returned.

 

 

English definition of "pattern"

 

pattern n.

1. Anything proposed for imitation; an archtype; exemplare; that which is to be, or is fit to be, copied or imitated.

            I will be the pattern of patience.        Shak.

2. Anything designed as a model for making things; a model; plan; as, a dressmaker's pattern.

3. A representation or copy of an archetype or prototype; hence, a copy; a likeness Archaic.

            This pattern of things in the heavens.                      Heb.ix.23.

4. A representative instance; an example; also, a specimen showing the figure or quality of the whole; sample.

            He compares the pattern with the whole piece.                     Swift

5. An artistic or mechanical design.  Specif.; a Form; shape; outline; as to prefer a vase or a stove of another pattern.  b A figure used in or suitable for decoration; a motive; as, a rug with a bold or a geometrical pattern; chintz patterns.  c In literature, music, etc., expressive or stylistic design, resulting from emphasis on composition (sense 2); as, to Imitate Stevenson's patterns.

6. Hence, In natural or chance formations, markings, groupings, or In a series of events, an arrangement of parts, elements, or details that suggest a design or orderly distribution; as frost patterns.

7. In Ireland, a patron saint's day; hence, the festivity connected with one; a dance on any holiday.

8. A specimen of a proposed coin, minted before it's authorization as currency.

9. A length of cloth sufficient for a garment, sometimes specially woven for the purpose; as, a dress pattern.  U.S.

10. Founding  a Obs. A matrix.  b A model for making the mold into which molten metal is poured to form a casting.  It is usuallyu made of a varnished or painted wood, or of metal when many duplicate castings are required.  The pattern is made larger then the proposed casting to allow for contraction of the castings in cooling (See CONTRACTION RULE).  When the castings is of such a shape that the removal of the pattern in one piece would break the mold the pattern is made in two or more pieces and doweled together (split pattern), each piece being usually removed in a separate flask.  See LOOSE PIECE, CORE PRINT; FLASK, 4.  cf. WORKING PATTERN, BLOCK PATTERN, SKELETON PATTERN.

11. Gun. Distribution of the shot from a shotgun or the bullets from an exploded shrapnel on a target perpendicular to the plane of fire; also, a diagram showing such distribution of shot, bullets, etc.

12. Lacemaking.  Any figure, esp. one made separately, which belongs to the design; a motif; --contrasted with ground.

13. Psychol.  A complex whole, characterized by a definite arrangement or inter-relation of parts; as, a behavior pattern; a patern of brain activity; a configuration.

Syn. --PATTERN, MODEL, EXEMPLAR, IDEAL.  A PATTERN is that after which something is made; the word often supplies exp. to that which is worthy of imitation, and this suggestion is heightened in MODEL; as, Eleonora is still the pattern of charity, devotion, and humility.

 

                                                            [From Websters1949Unabridged.]

 

 


Grok32`
(c) 2004-2007 by

John Van Wie Bergamini

All rights reserved.

Hosted by www.Geocities.ws

1