Guards
[
Front page
|
List of pages
|
Search
|
Recent changes
|
Backup
|
Help
]
Start:
//[[Documentation]]
#mathjax
*Guards [#v398323a]
**Rules with a Guard [#x7373323]
Guards specify applicability conditions of rewrite rules....
>\( \textit{Head}\ \texttt{:-}\ \textit{Guard}\ \texttt{|...
where \( \textit{Guard} \) is a multiset of ''type constr...
\( c(\texttt{\$}p_1, \dots, \texttt{\$}p_n) \).
Type constraints constrains the shapes of processes
(or the names of unary atoms)
received by the process contexts \( \texttt{\$}p_1, \dots...
The ''type constraint name'' \( c \) is drawn from a buil...
A constraint of the form ''uniq''(\( \texttt{\$}p_1, \dot...
also allowed. This is a control structure rather than a ...
and used to avoid infinite rule application (see below).
***Examples [#oc28c486]
Here is an example rule with guard:
waitint(X), $p[X] :- int($p) | ok.
This can be abbreviated to
waitint($p) :- int($p) | ok.
and can be thought of representing the following infinite...
waitint(0) :- ok. waitint(1) :- ok. waitint(-1) :...
waitint(2) :- ok. waitint(-2) :- ok. ...
The following are examples of some type constraints that ...
-&color(#8B4513){int($p)}; ... specifies that $p must be ...
-&color(#8B4513){4($p)}; ... specifies that $p must be a ...
-&color(#8B4513){$p < $q}; ... specifies that $p and $q a...
such that the value of $p is less than that of $q.
-&color(#8B4513){$r = $p +. $q}; ... specifies that $p, $...
point number atoms such that the sum of the values of $p ...
***Notes [#z6515d94]
Each type constraint name (such as int or <)
has its own mode of usage
that specifies which of its arguments are input arguments.
The effect of the constraint specified by a type constraint
is enabled only after the shapes (or values)
of its input arguments are all determined.
For example, $r = $p + $q proceeds only when $p and $q ar...
The same abbreviation scheme as defined for atoms
applies to type constraints when a process context name
$'''p'''&size(10){'''k'''};
occurs exactly twice in the rule.
For example,
p($n) :- $n > $z, 0($z) | ok
can be abbreviated to:
p($n) :- $n > 0 | ok
// **Typed Process Contexts [#z5d7f69f]
A process context constrained in '''Guard'''
is said to be a ''typed process context''.
// As a syntactic sugar,
// typed process context names can be written as link nam...
// For inscance, the above example can be written as:
// waitint(X) :- int(X) | ok.
// // ( Res = gen(N) :- N > 0 | Res = [N|gen(N-1)] ), p(g...
// However, the original form, waitint($p) :- int($p) | o...
// because, unlike link names, typed process context name...
// on the number of their occurrences.
**Guard Library [#udf848a7]
The following type constraints can be used in guards.
The + (input) sign preceding a process context name means...
appear in the head, while the - (output) sign means that ...
appear in the head.
***Type checking [#l78e805c]
:int(+$i)|check if $i[X] is an integer.
:float(+$f)|check if $f[X] is a floating-point number.
:unary(+$u)|check if $u[X] is a unary atom. Note that ''...
:ground(+$g)|check if $g[X1,...,Xn] (n>0) is a connected ...
***Assignment [#ne364170]
:'='(+$u,-$v)|make sure that $u[X] and $v[Y] are unary at...
:'='(-$u,+$v)|same as above.
:int(+$float,-$int)|cast to int.
:float(+$int,-$float)|cast to float.
:345(-$int)|defined for every integer (not only with 345).
:'-3.14'(-$float)|defined for every float.
:'+'(+$int,+$int,-$int)|binary integer operation; also: ...
:'+'(+$int,+$int)|unary integer operation; also: ''&colo...
:'+.'(+$float,+$float,-$float)|binary float operation; ...
:'+.'(+$float,+$float)|unary float operation; also: ''...
The term notation allows you to write
abs($x,$v), '*'(3,$v,$w), '+'($w,$y,$z)
as
$v = abs($x), $w = 3 * $v, $z = $w + $y
which can in turn be written as
$z = 3 * abs($x) + $y .
***Comparison [#r7825264]
:'='(+$u,+$v)|check if $u[X1,...,Xn] and $v[Y1,...,Yn] ar...
:'\='(+$u,+$v)|check if $u[X1,...,Xn] and $v[Y1,...,Ym] a...
:'=='(+$u,+$v)|check if $u[X] and $v[Y] are unary atoms w...
:'\=='(+$u,+$v)|check if $u[X] and $v[Y] are unary atoms ...
(if either of them are not unary, the check fails.)
:'<.'(+$float,+$float)|float comparison; also: ''&color...
:'<'(+$int,+$int)|integer comparison; also: ''&color(#8B4...
The term notation allows you to write
abs($x,$y), $y < 10
as
abs($x) < 10 .
**Avoiding Infinite Rule Application [#w149d3ab]
A constraint of the form
''uniq''($'''p'''&size(10){1};, ..., $'''p'''&size(10){''...
succeeds if each $'''p'''&size(10){'''k'''}; is a '''grou...
(connected graph with exactly one free link; see below)
and the rule has not
been applied to the tuple
$'''p'''&size(10){1};, ..., $'''p'''&size(10){'''n'''};
before.
As a special case of '''n'''=0,
''uniq'' succeeds if the rule in question has not been used
before. The ''uniq''() test is a general tool for avoidi...
infinite application of rules whose right-hand side is a
super(multi)set of the left-hand side.
//***Others [#i37c8a7c]
:uniq(+$g1,...,+$gn)|uniqueness constraint; checks if the...
End:
//[[Documentation]]
#mathjax
*Guards [#v398323a]
**Rules with a Guard [#x7373323]
Guards specify applicability conditions of rewrite rules....
>\( \textit{Head}\ \texttt{:-}\ \textit{Guard}\ \texttt{|...
where \( \textit{Guard} \) is a multiset of ''type constr...
\( c(\texttt{\$}p_1, \dots, \texttt{\$}p_n) \).
Type constraints constrains the shapes of processes
(or the names of unary atoms)
received by the process contexts \( \texttt{\$}p_1, \dots...
The ''type constraint name'' \( c \) is drawn from a buil...
A constraint of the form ''uniq''(\( \texttt{\$}p_1, \dot...
also allowed. This is a control structure rather than a ...
and used to avoid infinite rule application (see below).
***Examples [#oc28c486]
Here is an example rule with guard:
waitint(X), $p[X] :- int($p) | ok.
This can be abbreviated to
waitint($p) :- int($p) | ok.
and can be thought of representing the following infinite...
waitint(0) :- ok. waitint(1) :- ok. waitint(-1) :...
waitint(2) :- ok. waitint(-2) :- ok. ...
The following are examples of some type constraints that ...
-&color(#8B4513){int($p)}; ... specifies that $p must be ...
-&color(#8B4513){4($p)}; ... specifies that $p must be a ...
-&color(#8B4513){$p < $q}; ... specifies that $p and $q a...
such that the value of $p is less than that of $q.
-&color(#8B4513){$r = $p +. $q}; ... specifies that $p, $...
point number atoms such that the sum of the values of $p ...
***Notes [#z6515d94]
Each type constraint name (such as int or <)
has its own mode of usage
that specifies which of its arguments are input arguments.
The effect of the constraint specified by a type constraint
is enabled only after the shapes (or values)
of its input arguments are all determined.
For example, $r = $p + $q proceeds only when $p and $q ar...
The same abbreviation scheme as defined for atoms
applies to type constraints when a process context name
$'''p'''&size(10){'''k'''};
occurs exactly twice in the rule.
For example,
p($n) :- $n > $z, 0($z) | ok
can be abbreviated to:
p($n) :- $n > 0 | ok
// **Typed Process Contexts [#z5d7f69f]
A process context constrained in '''Guard'''
is said to be a ''typed process context''.
// As a syntactic sugar,
// typed process context names can be written as link nam...
// For inscance, the above example can be written as:
// waitint(X) :- int(X) | ok.
// // ( Res = gen(N) :- N > 0 | Res = [N|gen(N-1)] ), p(g...
// However, the original form, waitint($p) :- int($p) | o...
// because, unlike link names, typed process context name...
// on the number of their occurrences.
**Guard Library [#udf848a7]
The following type constraints can be used in guards.
The + (input) sign preceding a process context name means...
appear in the head, while the - (output) sign means that ...
appear in the head.
***Type checking [#l78e805c]
:int(+$i)|check if $i[X] is an integer.
:float(+$f)|check if $f[X] is a floating-point number.
:unary(+$u)|check if $u[X] is a unary atom. Note that ''...
:ground(+$g)|check if $g[X1,...,Xn] (n>0) is a connected ...
***Assignment [#ne364170]
:'='(+$u,-$v)|make sure that $u[X] and $v[Y] are unary at...
:'='(-$u,+$v)|same as above.
:int(+$float,-$int)|cast to int.
:float(+$int,-$float)|cast to float.
:345(-$int)|defined for every integer (not only with 345).
:'-3.14'(-$float)|defined for every float.
:'+'(+$int,+$int,-$int)|binary integer operation; also: ...
:'+'(+$int,+$int)|unary integer operation; also: ''&colo...
:'+.'(+$float,+$float,-$float)|binary float operation; ...
:'+.'(+$float,+$float)|unary float operation; also: ''...
The term notation allows you to write
abs($x,$v), '*'(3,$v,$w), '+'($w,$y,$z)
as
$v = abs($x), $w = 3 * $v, $z = $w + $y
which can in turn be written as
$z = 3 * abs($x) + $y .
***Comparison [#r7825264]
:'='(+$u,+$v)|check if $u[X1,...,Xn] and $v[Y1,...,Yn] ar...
:'\='(+$u,+$v)|check if $u[X1,...,Xn] and $v[Y1,...,Ym] a...
:'=='(+$u,+$v)|check if $u[X] and $v[Y] are unary atoms w...
:'\=='(+$u,+$v)|check if $u[X] and $v[Y] are unary atoms ...
(if either of them are not unary, the check fails.)
:'<.'(+$float,+$float)|float comparison; also: ''&color...
:'<'(+$int,+$int)|integer comparison; also: ''&color(#8B4...
The term notation allows you to write
abs($x,$y), $y < 10
as
abs($x) < 10 .
**Avoiding Infinite Rule Application [#w149d3ab]
A constraint of the form
''uniq''($'''p'''&size(10){1};, ..., $'''p'''&size(10){''...
succeeds if each $'''p'''&size(10){'''k'''}; is a '''grou...
(connected graph with exactly one free link; see below)
and the rule has not
been applied to the tuple
$'''p'''&size(10){1};, ..., $'''p'''&size(10){'''n'''};
before.
As a special case of '''n'''=0,
''uniq'' succeeds if the rule in question has not been used
before. The ''uniq''() test is a general tool for avoidi...
infinite application of rules whose right-hand side is a
super(multi)set of the left-hand side.
//***Others [#i37c8a7c]
:uniq(+$g1,...,+$gn)|uniqueness constraint; checks if the...
Page: