## Hyperlinks and hypergraphs

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.

Accordingly, LMNtal now provides the syntax and operations for hypergraphs. The language with this extension is also called HyperLMNtal.

HyperLMNtal programs run with the SLIM runtime. SLIM 2.1.3 supports the ordinary (as opposed to nondeterministic) execution mode only, while SLIM 2.2.0 supports nondeterministic execution as well.

### Creating a hyperlink

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

```hoge.
hoge :- new(\$h) | a(\$h), b(\$h).

--> a(!1), b(!1).```

Each hyperlink is given a fresh private name, which will be printed as a "!" followed by a hexadecimal number.

### Type checking

The type constraint hlink(\$x) checks if \$x represents a hyperlink.

```main.
main :- new(\$x) | a(\$x).
a(\$x) :- hlink(\$x) | b(\$x).

--> b(!1).```

### Equality checking

An occurrence of a hyperlink is regarded as a unary atom with a special, private name. Therefore, 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.`

### Fusing two hyperlinks

Two hyperlinks can be fused into one using the "><" operator.

```main.
main :- new(\$x), new(\$y) | a(\$x), b(\$y).
a(\$x), a(\$y) :- \$x \= \$y | a(\$x), b(\$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.

### Number of occurrences

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) | number(\$n).

--> b(!1), number(2). ```

Another use:

```main.
main :- new(\$x) | a(\$x).
a(\$h) :- \$n = num(\$h), \$n < 5 | a(\$h), a(\$h).

--> a(!1), a(!1), a(!1), a(!1), a(!1).```

Yet another use:

```main :- new(\$x) | flag(!x), a(!x), a(!x), a(!x), a(!x).
a(\$h) :- hlink(\$h) | .
flag(\$h) :- \$n = num(\$h), \$n =:= 1 | ok.

--> ok. // ok is created when all a(!1)'s are removed```

In this way, using hyperlinks, one can check the absence of a particular hyperlink.

## How to use

### LaViT

When you execute your program under LaViT (recommended), select the Option tab and turn on the following checkboxes:

• Slimcode Compile Option: --slimcode and --hl-opt
• Slim Option: --hl

Please see below for the details of those options.

### Compiling

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

Specify --hl when running SLIM, e.g.,

`slim --hl --show-hl hoge.il`
• --hl : turn on hyperlinks
• currently, this cannot be specified with -nd.
• --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.

Last-modified: 2017-03-02 (Thu) 03:32:49 (653d)