#author("2023-03-13T15:40:11+09:00","default:LMNtal","LMNtal")
//[[Documentation]]

*Hyperlinks (slim)
*Hyperlinks and hypergraphs [#se1fd52b]

LMNtal links represent point-to-point connection between atoms and form an ordinary graph.  In some applications, however, we may want '''hyperlinks''', namely links that interconnect more than two atoms and form a '''hypergraph'''.
LMNtal links represent point-to-point connection between atoms and form an ordinary graph.  In some applications, however, natural modeling calls for '''hyperlinks''', namely links that interconnect more than two atoms.  A graph structure with hyperlinks forms a '''(hierarchical) hypergraph'''.

LMNtal provides syntax and operations for hypergraphs, which will be described below.  Currently, hyperlinks are supported by the slim runtime
in the ordinary (as opposed to non-deterministic) execution mode. 
Accordingly, LMNtal now provides the syntax and operations for hypergraphs.  The language with this extension is also called HyperLMNtal.

**Creating a hyperlink
**Creating a hyperlink [#hcd901f8]

-A hyperlink is created by a "new" construct specified in a guard.

A hyperlink is created by a ''new'' construct specified in a guard.
 hoge.
 hoge :- new($h) | a($h), b($h).
 *--> a(!1), b(!1).
Since each hyperlink can be regarded as a unary atom with a fresh local name, we use the syntax of process contexts (starting with a '$') to represent it.

Another view of hyperlinks is a generalization of ordinary links, and they can be written also by attaching '!' to link names as
 hoge.
 hoge :- a(!H), b(!H).
or just
 a(!H), b(!H).

**Type checking for hyperlinks
-hlink($x)
The result of all the above programs will be 
 a(!H4), b(!H4).
That is, a hyperlink will be printed as a '!H' followed by a system-generated hexadecimal number.

 a(!1).
 a($x) :- hlink($x) | b($x).
 *--> b(!1).
**Type checking [#i375b878]

**Merging two hyperlinks
The type constraint ''hlink''($x) checks if $x represents a hyperlink.  
 main.
 main :- new($x) | a($y).
 a($x) :- hlink($x) | b($x,$x).
or
 a(!Y).
 a(!X) :- b(!X,!X).
Result:
 b(!H4,!H4).

-Two hyperlinks can be merged into one using the "><" operator.
**Equality checking [#gd567c1c]

 a(!1), b(!2).
 a($x), a($y) :- $x \= $y | a($x), b($y), $x >< $y.
--If $x and $y represent different hyperlinks, they will be merged into one.
Since an occurrence of a hyperlink is regarded as a unary atom with a special private name, the constructs ''=='' and ''\=='' can be used for comparing two hyperlinks, e.g.,
 a($x), b($y) :- hlink($x), hlink($y), $x == $y | ok.
The above rule can be written also as
 a($x), b($x) :- ok.
or
 a(!X), b(!X) :- ok.

***Number of occurrences
-The "num" construct in a guard will return the number of occurrences of the specified hyperlink.
**Fusing two hyperlinks [#e554f0f3]

 a(!1), b(!1).
 a($h) :- $n = num($h) | number($n).
 *--> b(!1), number(2).  
--Another use
 a(!1).
 a($h) :- $n = num($h), $n < 5 | a($h), a($h).
 *--> a(!1), a(!1), a(!1), a(!1), a(!1).
--Yet another use
 flag(!1), a(!1), a(!1), a(!1), a(!1).
 a($h) :- hlink($h) | .
 flag($h) :- $n = num($h), $n =:= 1 | ok.
 *--> ok. // ok is created when all a(!1)'s are removed
---Thus, using hyperlinks, one can check the absence of a particular atom.
Two hyperlinks can be fused into one using the "''><''" operator.
 main.
 main :- new($x), new($y) | a($x), b($z).
 a($x), b($y) :- $x \== $y | ab($x,$y), $x >< $y.
or
 a(!X), b(!Z).
 a(!X), b(!Y) :- !X \== !Y | ab(!X,!Y), !X >< !Y.
If $x and $y represent different hyperlinks (i.e., have different hyperlink names), they will be merged into one; that is, they are made to have the same hyperlink name.

**Guard Library
**Number of occurrences [#hc2d2626]

The following type constraints can be used in guards.
The + (input) sign preceding a process context name means that the name should
appear in the head, while the - (output) sign means that the name should not
appear in the head.
The ''num'' construct in a guard will return the number of occurrences of the specified hyperlink.
 main.
 main :- new($x) | a($x), b($x).
 a($h) :- $n = num($h) | occurrences($n).
or
 a(!X), b(!X).
 a(!H) :- $n = num(!H) | occurrences($n).
Result:
 b(!H4), occurrences(2). 
Another use:
 a(!X).
 a(!H) :- num(!H) < 5 | a(!H), a(!H).
Result:
 a(!H4), a(!H4), a(!H4), a(!H4), a(!H4).
Yet another use:
 flag(!X), a(!X), a(!X), a(!X), a(!X), a(!X).
 a(!H) :- .
 flag(!H) :- num(!H) =:= 1 | ok.
Result:
 ok. // ok is created when all a(!H1)'s are removed
In this way, using hyperlinks, one can check the '''absence''' of a particular hyperlink.

:'='(+$u,-$v)|make sure that $u[X] and $v[Y] are unary atoms with the same name.
:'='(-$u,+$v)|same as above.
:'=='(+$u,+$v)|check if $u[X] and $v[Y] are unary atoms with the same name.
:unary(+$u)|check if $u[X] is a unary atom.
:ground(+$g)|check if $g[X1,...,Xn] (n>0) is a connected graph whose free links are exactly X1,...,Xn.
:int(+$i)|check if $i[X] is an integer.
:float(+$f)|check if $f[X] is a floating-point number.
:int(+$float,-$int)|cast.
:float(+$int,-$float)|cast.
:345(-$int)|defined for every integer (not only with 345).
:'-3.14'(-$float)|defined for every float.
:'<'(+$int,+$int)|integer comparison; also: ''&color(#8B4513){'>'};'', ''&color(#8B4513){'=<'};'', ''&color(#8B4513){'>='};'', ''&color(#8B4513){'=:='};'', ''&color(#8B4513){'=\='};''.
:'+'(+$int,+$int,-$int)|integer operation;  also: ''&color(#8B4513){'-'};'', ''&color(#8B4513){'*'};'', ''&color(#8B4513){'/'};'', ''&color(#8B4513){mod};''.
:'<.'(+$float,+$float)|float comparison;   also: ''&color(#8B4513){'>.'};'', ''&color(#8B4513){'=<.'};'', ''&color(#8B4513){'>=.'};'', ''&color(#8B4513){'=:=.'};'', ''&color(#8B4513){'=\=.'};''.
:'+.'(+$float,+$float,-$float)|float operation;    also: ''&color(#8B4513){'-.'};'', ''&color(#8B4513){'*.'};'', ''&color(#8B4513){'/.'};''.
:uniq(+$g1,...,+$gn)|uniqueness constraint; checks if the rule has not been applied to the tuple $g1[X1], ..., $gn[Xn] (n>=0).
*How to use [#nade49a7]

**LaViT [#qcec53b9]

When you execute your program under LaViT (recommended), select the Option tab and turn on the following checkboxes:
- Compile Option: ''--slimcode'' and ''--hl-opt''
- Slim Option: ''--hl''

Please see below for the details of those options.

**Compiling [#nd78cdd2]

Currently, programs with hyperlinks can be executed only under SLIM.  To compile them, both ''--slimcode'' and ''--hl'' (or ''--hl-opt'') options need be specified, e.g.,
 lmntal --slimcode --hl hoge.lmn > hoge.il
- ''--hl''     : turn on hyperlinks.
- ''--hl-opt'' : turn on hyperlinks and optimize graph matching using hyperlink connection.

**Execution [#aff38a8e]

Specify ''--hl'' when running SLIM, e.g.,
 slim --hl --show-hl hoge.il
- ''--hl''      : turn on hyperlinks.
- ''--show-hl'' : prints the details of hyperlinks.
-- Without this option, different occurrences of a hyperlink are printed with the same name.
-- With this option, each occurrence of a hyperlink is printed with its own ID.  In addition, a table of hyperlink occurrences will be printed.


Front page List of pages Search Recent changes Backup   Help   RSS of recent changes