pattern.spad line 1 [edit on github]
Patterns for use by the pattern matcher.
a * b
returns the pattern a * b
.
a + b
returns the pattern a + b
.
a / b
returns the pattern a / b
.
0
1
a ^ b
returns the pattern a ^ b
.
a ^ n
returns the pattern a ^ n
.
addBadValue(p, v)
adds v
to the list of "bad values" for p
. Note: p
is not allowed to match any of its "bad values".
constant?(p)
tests if p
contains no matching variables.
convert([a1, ..., an])
returns the pattern [a1, ..., an]
.
copy(p)
returns a recursive copy of p
.
depth(p)
returns the nesting level of p
.
elt(op, [a1, ..., an])
returns op(a1, ..., an)
.
generic?(p)
tests if p
is a single matching variable.
getBadValues(p)
returns the list of "bad values" for p
. Note: p
is not allowed to match any of its "bad values".
hasPredicate?(p)
tests if p
has predicates attached to it.
hasTopPredicate?(p)
tests if p
has a top-level predicate.
inR?(p)
tests if p
is an atom (i.e. an element of R
).
isExpt(p)
returns [q, n]
if n > 0
and p = q ^ n
, and "failed" otherwise.
isList(p)
returns [a1, ..., an]
if p = [a1, ..., an]
, "failed" otherwise.
isOp(p, op)
returns [a1, ..., an]
if p = op(a1, ..., an)
, and "failed" otherwise.
isOp(p)
returns [op, [a1, ..., an]]
if p = op(a1, ..., an)
, and "failed" otherwise.
isPlus(p)
returns [a1, ..., an]
if n > 1
and p = a1 + ... + an
, and "failed" otherwise.
isPower(p)
returns [a, b]
if p = a ^ b
, and "failed" otherwise.
isQuotient(p)
returns [a, b]
if p = a / b
, and "failed" otherwise.
isTimes(p)
returns [a1, ..., an]
if n > 1
and p = a1 * ... * an
, and "failed" otherwise.
multiple?(p)
tests if p
is a single matching variable allowing list matching or multiple term matching in a sum or product.
optional?(p)
tests if p
is a single matching variable which can match an identity.
optpair(l)
returns l
has the form [a, b]
and a is optional, and "failed" otherwise.
patternVariable(x, c?, o?, m?)
creates a pattern variable x
, which is constant if c? = true
, optional if o? = true
, and multiple if m? = true
.
predicates(p)
returns [p1, ..., pn]
such that the predicate attached to p
is p1
and ... and pn
.
quoted?(p)
tests if p
is of the form 's
for a symbol s
.
resetBadValues(p)
initializes the list of "bad values" for p
to []
. Note: p
is not allowed to match any of its "bad values".
setPredicates(p, [p1, ..., pn])
attaches the predicate p1
and ... and pn
to p
.
setTopPredicate(x, [a1, ..., an], f)
returns x
with the top-level predicate set to f(a1, ..., an)
.
symbol?(p)
tests if p
is a symbol.
topPredicate(x)
returns [[a1, ..., an], f]
where the top-level predicate of x
is f(a1, ..., an)
. Note: n
is 0 if x
has no top-level predicate.
variables(p)
returns the list of matching variables appearing in p
.
withPredicates(p, [p1, ..., pn])
makes a copy of p
and attaches the predicate p1
and ... and pn
to the copy, which is returned.