diff options
| author | Shinya Sato <shinnya.sato@gmail.com> | 2022-07-20 00:00:44 +0900 |
|---|---|---|
| committer | Shinya Sato <shinnya.sato@gmail.com> | 2022-07-20 00:00:44 +0900 |
| commit | c57cb1fd511d2c69bf332324c73608f309bb4772 (patch) | |
| tree | 634287f3becc3fae3f81b09cf808b95bba009cae /README.md | |
| parent | e9db0870164cfec10aa219cc0898c30f6a888f53 (diff) | |
| parent | 633a31e251950349d3b8f9ae208af55667a4f9c4 (diff) | |
| download | inpla-c57cb1fd511d2c69bf332324c73608f309bb4772.tar.gz inpla-c57cb1fd511d2c69bf332324c73608f309bb4772.zip | |
Merge branch 'develop'
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 805 |
1 files changed, 12 insertions, 793 deletions
@@ -6,12 +6,14 @@ Inpla is a multi-threaded parallel interpreter of interaction nets. Once you write programs for sequential execution, it works also in multi-threaded parallel execution. Each thread is managed on each CPU-core with POSIX-thread library. -* The current version is 0.8.2-2 (bugfix), released on **30 May 2022**. (See [Changelog.md](Changelog.md) for details.) -* The below graph shows speed-up ratio to threads numbers for programs in the following benchmark table, though quick sort and merge sort are for 800000 elements. This is because 260000 elements, which are in the following benchmark table, are too small for Inpla to perform in parallel as shown in the description of v0.8.2-1 in [Changelog.md](./Changelog.md). +* The current version is 0.8.3, released on **19 July 2022**. (See [Changelog.md](Changelog.md) for details.) +* The below graph shows speed-up ratio to threads numbers for programs in the following benchmark table.  +- **Comparison in execution time** with other implementations: **Haskell** (GHC version 8.10.7), **OCaml** (ocamlopt, the native-code compiler, version 4.08.1), **Standard ML of New Jersey** v110.74 (interpreter mode) and **Python** 3.8.5 in execution time. + | | Haskell | OCaml | SML | Python | Inpla8 | Inpla8r | | -------------- | :------: | :------: | :----: | :----: | :------: | :------: | @@ -22,7 +24,9 @@ Inpla is a multi-threaded parallel interpreter of interaction nets. Once you wri | qsort 260000 | [0.34](comparison/Haskell/qsort-800000.hs) | [0.25](comparison/OCaml/qsort800000.ml) | [0.27](comparison/SML/qsort-800000.sml) | [10.40](comparison/Python/qsort-800000.py) | [0.15](comparison/Inpla/src/qsort-800000.in) | [**0.11**](comparison/Inpla/src/qsort-800000-reuse.in) | | msort 260000 | [0.39](comparison/Haskell/msort-800000.hs) | [0.29](comparison/OCaml/msort800000.ml) | [0.26](comparison/SML/msort-800000.sml) | [10.96](comparison/Python/msort-800000.py) | [**0.15**](comparison/Inpla/src/msort-800000.in) | [**0.15**](comparison/Inpla/src/msort-800000-reuse.in) | -- **Comparison in execution time** with other implementations: **Haskell** (GHC version 8.10.7), **OCaml** (ocamlopt, the native-code compiler, version 4.08.1), **Standard ML of New Jersey** v110.74 (interpreter mode) and **Python** 3.8.5 in execution time. + + + - The above table contains execution time in second on average of ten times execution by using Linux PC (Core i7-9700 (8 threads, no Hyper-threading), 16GB memory). The fastest one is shown with bold style. Scripts for the comparison table are in the `comparison` directory. @@ -33,7 +37,7 @@ Inpla is a multi-threaded parallel interpreter of interaction nets. Once you wri - "fib 38" is computation to get the 38th Fibonacci number. - "bsort *n*", "isort *n*", "qsort *n*" and "msort *n*" are computation of bubble sort, insertion sort, quick sort and merge sort for random *n*-element lists, respectively, followed by a validation check process. - + In the graph quick sort and merge sort are for 800000 elements because the 260000 elements are too small for Inpla to show the performance in parallel. See the description of v0.8.2-1 in [Changelog.md](./Changelog.md) for details. ## Contents @@ -42,9 +46,7 @@ Inpla is a multi-threaded parallel interpreter of interaction nets. Once you wri - [Interactive mode (single-thread version)](#interactive-mode-single-thread-version) - [Interactive mode (multi-thread version)](#interactive-mode-multi-thread-version) - [Batch mode and sample files](#batch-mode-and-sample-files) -* [Introduction to Programming in Inpla](#introduction-to-programming-in-inpla) -* [Commands](#commands) -* [Execution Options](#execution-options) +* [How to write programs in Inpla](#how-to-write-programs-in-inpla) * [Updates](#updates) * [Publications](#publications) * [Related Works](#related-works) @@ -189,7 +191,7 @@ Inpla is a multi-threaded parallel interpreter of interaction nets. Once you wri // Note: `Append' is implemented as the following built-in agent: // Append(ret, b)~a --> ret ~ a++b // The ret << Append(left, x:right) is rewritten - // by the built-in abrreviation into: + // by the built-in abbreviation into: // Append(ret, x:right)~left. part(smaller, larger, int x) >< [] => smaller~[], larger~[]; @@ -259,590 +261,8 @@ Inpla is a multi-threaded parallel interpreter of interaction nets. Once you wri -# Introduction to Programming in Inpla -#### Contents in this section -* [Nets: terms and connections](#nets-terms-and-connections) -* [Interaction rules: rewriting rules for nets](#interaction-rules-rewriting-rules-for-nets) - - [Example: Operations on unary natural numbers](#example-operations-on-unary-natural-numbers) -* [Built-in Agents](#built-in-agents) -* [Attributes (integers)](#attributes-integers) - - [Built-in anonymous agent for attributes](#built-in-anonymous-agent-for-attributes) - - [Arithmetic expressions on attributes](#arithmetic-expressions-on-attributes) - - [Interaction rules with expressions on attributes](#interaction-rules-with-expressions-on-attributes) - - [Built-in rules of attributes in the anonymous agents](#built-in-rules-of-attributes-in-the-anonymous-agents) - - [Interaction rules with conditions on attributes](#interaction-rules-with-conditions-on-attributes) - - - - -## Nets: terms and connections - -Inpla evaluates *nets*, which are built by *connections between terms*. First, we start learning about terms and connections. - -### Terms - -**Terms** are built on *names* and *agents* as follows: - -``` -<term> ::= <name> | <agent> -<name> ::= <nameID> -<agent> ::= <agentID> - | <agentID> ['(' <term> ',' ... ',' <term> ')'] -``` -* **Name**: It works a buffer between terms and **the same name must occur at most twice in order to ensure one-to-one connections between terms**. The ```<nameID>``` is defined as strings start with a small letter, e.g. ```x``` and ```y```. To show connected terms from names, type the names. For instance, type just `x` to show a term connected from the 'x': - - ``` - >>> x; - <NON-DEFINED> - >>> - ``` - - This means that nothing has not been connected from the `x` yet, of course. - - - -* **Agent**: It works constructors and de-constructors (defined functions). Generally agents have one *principal port* and *n*-fixed *auxiliary ports*. The fixed number of auxiliary ports is called *arity*, and it is determined according to each agent sort. In graphical representation an agent term `A(x1,...,xn)`, whose arity is *n*, is drawn as the following picture, where its auxiliary ports and the principal port (drawn as an arrow) correspond to the occurrences of the `x1`,...`xn`, and `A(x1,...,xn)`, respectively: - -  - - The ```<agentID>``` is defined as strings start with a capital letter, e.g. ```A``` and ```Succ```, and also ```<nameID>``` followed by a open curry bracket```(```. So, ```foo(x)``` is recognised as an agent. - - - -### Connections - -A **connection** is a relation between two terms, that means the two term are connected, and it is expressed with the symbol `~`. For instance, a connection between a name `x` and an agent `A` (whose arity is 0) is denoted as `x~A`. There is no order in the left-hand and the right-hand side terms, thus `x~A` and `A~x` are identified as the same one. - -* **Connections between a name and an agent** are evaluated as that the agent is connected from the name. For instance, `x~A` is evaluated as that the `A` is connected from the `x`. Here, as an example, type `x~A` with the termination symbol `;` as follows: - - ``` - >>> x~A; - (0 interactions, 0.00 sec) - >>> - ``` - - To show the connected terms from the name x, type just `x`: - ``` - >>> x; - A - >>> - ``` - - To dispose the name `x` and anything connceted from the `x`, use `free` command: - ``` - >>> free x; - >>> x; - <NON-DEFINED> - >>> - ``` - - -* **Connections between names** are evaluated as that ports corresponding to these names are connected mutually in interaction nets frameworks. However, in Inpla, these are evaluated as that, for the connections, the left-hand side name connects to the right-hand side name, thus only one way. For instance, `x~y` is evaluated that the `x` connects to the `x` (not that the `y` connects to `x`): - - ``` - >>> x~y; - >>> x; - y - >>> y; - <EMPTY> - >>> - ``` - -* **Connections between agents** are evaluated according to *interaction rules* explained later. - -One more connections are also evaluated. Connections whose the left-hand side is a name, such as `x~t`, are disposed and another occurrence `x` in other connections, if exists, is replaced with the `t`. For instance, `x~A, x~y` are evaluated as `A~y` by replacing `x` with `A`, or possibly `y~A` by replacing the `x` with `y` when the second connection `x~y` is used. **We note** that the `x` is disposed because it is consumed by the substitution. Thus, **every connection is kept one-to-one via names, cannot be one-to-many**. -``` ->>> x~A, x~y; -(0 interactions, 0.00 sec) ->>> y; -A ->>> x; // x has been consumed by the re-connection of x~A and x~y. -<NON-DEFINED> ->>> -``` - -Just in case for other examples, let the `y` disposed: - -``` ->>> free y; ->>> y; -<NON-DEFINED> ->>> -``` - - - -## Interaction rules: rewriting rules for nets - -Connections between agents are re-written according to **interaction rules**: - -``` -<interaction-rule> ::= <rule-agent> '><' <rule-agent> '=>' <connections> ';' -<rule-agent> ::= <agentID> - | <agentID> '(' <name> ',' ... ',' <name> ')' -``` - with the **priviso** that: - - * each name that occur in `<rule-agent>` must be **distinct** - * (**Linearity restriction**): every name in `<interaction-rule>` must **occur twice**. - -Something complicated? No problem! Let's us learn how to define the rules with some example! - -### Example: Operations on unary natural numbers - -Unary natural numbers are built by Z and S. For instance, 0, 1, 2, 3 are expressed as Z, S(Z), S(S(Z)), S(S(S(Z))). Here, let's think about an increment operation `inc` such that inc(n) = S(n). This is written as rules for Z and S(x) as follows: - -``` -inc(ret) >< Z => ret~S(Z); -inc(ret) >< S(x) => ret~S(S(x)); -``` - -In the first rule, the name `ret` occurs twice, so it satisfies the rule proviso. The second rule also satisfies because the `ret` and `x` are distinct names and occur twice in the rule. - -When agents works can be separated into constructors and de-constructors, it could be good to use strings of all small letters for de-constructors such as `inc` , and for constructors ones start from a capital letter such as `Z` and `S`. - -Let's take the result of the increment operation for `S(S(Z))`: - -``` ->>> inc(r)~S(S(Z)); // This is also written as: r << inc(S(S(Z))) -(1 interactions, 0.01 sec) ->>> r; -S(S(S(Z)) ->>> -``` - -Good! We get `S(S(S(Z)))` as the result of incrementation of `S(S(Z))` . - -To show the result as a natural number, use `prnat` command: - -``` ->>> prnat result; -3 ->>> -``` - -Let's clean the result in case it could be used anywhere: - -``` ->>> free r; ->>> -``` - -* **Exercise**: Addition on unary natural numbers. - - It is defined recursively in term rewriting systems as follows: - - - add(x, Z) = x, - - add(x, S(y)) = add(S(x), y). - - This is written in interaction nets as follows:  - - In Inpla (and textual notation in interaction nets also), each agent is expressed as a term whose arguments correspond to its auxiliary ports. For instance, the `add` agent in the most left-hand side of the above figure, after putting distinct names on auxiliary ports such as `ret` and `x`, is written as a term `add(ret,x)` by assembling these names anti-clockwise from the principal port (drawn as an arrow). - - Every computation is performed on connections between principal ports according to interaction rules. The rules shown in avobe figure are written textually as follows: - - ``` - add(ret, x) >< Z => ret~x; - add(ret, x) >< S(y) => add(ret, S(x))~y; - ``` - The following is an execution example: - ``` - >>> add(r,S(Z))~S(S(Z)); // This is also written as: r << add(S(Z), S(S(Z))) - (3 interactions, 0.00 sec) - >>> r; - S(S(S(Z))) - >>> prnat result; - 3 - >>> free r; - >>> - ``` - -* **Exercise**: Another version of the addition. - - There is another version defined in term rewriting system as follows: - - - add(x,Z) = x, - - add(x, S(y)) = S(add(x,y)). - - These are written in interaction nets:  - - and written textually as follows: - - ``` - add(ret,x) >< Z => ret~x; - add(ret,x) >< S(y) => ret~S(cnt), add(cnt, x)~y; - ``` - In comparison with the previous example, whereas those calculation results are stored until every computation finishes, these results can be sent partially as `S(cnt)` to other soon. So, **this version is suitable for parallel execution**. - - - - -## Built-in Agents -Inpla has built-in agents: - -### Tuples - -* `Tuple0`, `Tuple2(x1,x2)`, `Tuple3(x1,x2,x2)`, `Tuple4(x1,x2,x3,x4)`, `Tuple5(x1,x2,x3,x4,x5)`, written as `()`, `(x1,x2)`, `(x1,x2,x3)`, `(x1,x2,x3,x4)`, `(x1,x2,x3,x4,x5)`, respectively. - -* There is no Tuple1, and so `(x)` is evaluated as just `x`. - - -### Lists - -* `Nil`, `Cons(x,xs)`, written as `[]` and `x:xs`, respectively. -* A nested `Cons` that is terminated at `Nil` is written as a list notation using brackets `[` and `]`. For instance, `x1 : x2: x3 : Nil` is written as `[x1,x2,x3]` . - -#### Built-in rules for tuples and lists - -There are built-in rules for pairs of the same built-in agents that match and connect each element such that: - -``` -(x1,x2)><(y1,y2) => x1~y1, x2~y2 // This is already defined as a built-in rule. -``` - -We also have a built-in agent `Append` to append two lists as shown in the following pseudo code: - -``` -Append(r, listB) ~ listA --> r ~ (listA ++ listB) // pseudo code -``` - -* The following is an example of built-in agents: - - ``` - >>> (x1,x2)~(Z, S(Z)); - (1 interactions, 0.00 sec) - >>> x1 x2; - Z S(Z) - >>> - ``` - - ``` - >>> [y1, y2, y3]~[Z, S(Z), S(S(Z))]; - (1 interactions, 0.00 sec) - >>> y1 y2 y3; - Z S(Z) S(S(Z)) - >>> - ``` - - ``` - >>> Append(r, [Z, S(Z)]) ~ [A,B,C]; - (4 interactions, 0.00 sec) - >>> r; - [A,B,C,Z,S(Z)] - >>> free x1 x2 y1 y2 y3 r; - >>> - ``` - -* We also have a built-in abbreviation for the Append to denote the operation naturally: - ``` - >>> r << Append([A,B,C], [Z, S(Z)]); - (4 interactions, 0.00 sec) - >>> r; - [A,B,C,Z,S(Z)] - >>> free x1 x2 y1 y2 y3 r; - >>> - ``` - - - -### Eraser - -* Eraser agent `Eraser` removes any nets gragually: -  - - ``` - >>> Eraser ~ A(x1,x2); - (1 interactions, 0.00 sec) - >>> x1 x2 - Eraser Eraser - >>> free x1 x2; - >>> - ``` - - -## Attributes (integers) - -Agents can be extended so that these can have integers in their ports. These integers are called *attributes*. - -* For instance, `A(100)` is evaluated as an agent `A` that holds an attribute of an integer value `100`. - - ``` - >>> x~A(100); - (0 interactions, 0.01 sec) - >>> x; - A(100); - >>> free x; - >>> - ``` - - -### Built-in anonymous agent for attributes -It is possible to use integers the same as agents, but these are recognised as attributes of a built-in *anonymous agent* in Inpla. For instance, when we write just `x~100`, then the `100` is regarded as an attribute of the anonymous agent. - -* The following is another version of the above example in the case of using the anonymous agent: - - ``` - >>> x~100; // The `100' is regarded as an attribute of an anonymous agent - (0 interactions, 0.00 sec) - >>> x; - 100 - >>> free x; - >>> - ``` - - - -### Arithmetic expressions on attributes -Attributes can be given as the results of arithmetic operation using `where` statement after connections: - -``` -<connections-with-expressions> ::= - <connections> - | <connections> 'where' <let-clause>* ';' - -<let-clause> ::= <name> '=' <arithmetic expression> -``` - -The symbol of addition, subtraction, multiplication, division, modulo are `+`, `-`, `*`, `/` and `%`, respectively. Not `!` (`not`), And `&&` (`and`) and Or `||` (`or`) are also available where only `0` is regarded as False and return `1` for Truth. - -* For instance, the following is an expression using `where`: - - ``` - >>> x~A(a) where a=3+5; - (0 interactions, 0.00 sec) - >>> x; - A(8) - >>> free x; - >>> - ``` - -* Arithmetic expressions can be written in arguments directly without using `where`: - - ``` - >>> x~A(3+5); - (0 interactions, 0.00 sec) - >>> x; - A(8) - >>> free x; - >>> - ``` - - -* Arithmetic expressions are also available for the anonymous agent: - - ``` - >>> x~(3+5); // this is also written without brackets as x~3+5; - (0 interactions, 0.00 sec) - >>> x; - 8 - >>> free x; - >>> - ``` - - -### Interaction rules with expressions on attributes -In interaction rules, attributes that occur in the rule-agent parts are recognised by specifying variables with a modifier `int`, we call these *attribute variables*. **It is OK if we do not care about the Linear restriction for attributes variables**, so we can use the same attribute variable as many times as you want. This is because these do not affect keeping the one-to-one connection among agent ports, whereas every ordinary name has to occur exactly twice in interaction rules. - -* Example: Incrementor on an attribute: - - ``` - >>> inc(result) >< (int a) => result~(a+1); // The `a' is a varible for an attribute - >>> inc(r)~10; // This is also written as: r << inc(10) - (1 interactions, 0.00 sec) - >>> r; - 11 - >>> free r; - >>> - ``` - - -- Example: Duplicator of integer lists. - -  - - **We note that**, on the first line from the top of the following execution example, there is a rule allowed to have twice occurrences of *i* in the right-hand side (here, `(i:xs1)` and `(i:xs2)`). This is possible because the *i* is an attribute variable. - - ``` - >>> dup(a1,a2) >< (int i):xs => a1~(i:xs1), a2~(i:xs2), dup(xs1,xs2)~xs; - >>> dup(a1,a2) >< [] => a1~[], a2~[]; - >>> dup(a,b) ~ [1,2,3]; // This is also written as: a,b << dup([1,2,3]) - (4 interactions, 0.00 sec) - >>> a b; - [1,2,3] [1,2,3] - >>> free a b; - >>> - ``` - - - -**We have to be careful for operations of two attributes on distinct agents**. For instance, we take the following rule of an `add` agent: - -``` ->>> add(result, int b) >< (int a) => result~(a+b); -``` - -Of course, it works as an addition operation on two attributes: - -``` ->>> add(r, 3) ~ 5; -(1 interactions, 0.00 sec) ->>> r; -8 ->>> free r; ->>> -``` - -However, it causes runtime error if the second argument `int b` for the `add` rule can haven't been connected to an attribute when the rule is invoked. For instance, we take the following computation: - -``` ->>> add(r, b)~3, add(b, 10)~20; -``` - -If the `add(r, b)~3` is operated first, it causes runtime error because the `b` has not been connected to an attribute, whereas it is OK if the `add(b, 10)~20` is operated first. To prevent this fragile situation, **we have to have extra rules to ensure that every port with the modifier `int` has been connected to an attribute**. For the rule of the `add` agent, the following is a **solution** to have the extra rule (the `addn` is introduced as the extra agent): - -``` ->>> add(result, b) >< (int a) => addn(result, a) ~ b; ->>> addn(result, int a) >< (int b) => r~(a+b); -``` - - - -### Built-in rules of attributes in the anonymous agents - -There are built-in rules for arithmetic operations between two agents by using `Add`, `Sub`, `Mul`, `Div`, `Mod` agents as addition, subtraction, multiplication, division and modulo, respectively. Rules for the `Add` are defined so that it can join two attributes on distinct agents safely as follows, and the others are also defined the same way: - -``` -Add(result, y)><(int x) => _Add(result, x)~y; -_Add(result, int x)><(int y) => result~(x+y); -``` - -* Example: - - ``` - >>> Add(r,3)~5; // Add is already defined as a bulit-in - >>> r; - 8 - >>> r1 << Sub(r,2), r2 << Mul(r1,10) // These are also written as an abbreviation form. - >>> r2; - 60 - >>> - ``` - - - -### Interaction rules with conditions on attributes -In interaction rules, conditional rewritings on attributes are available. The following is a general form: - -``` -<rule-with-conditions> ::= - <agent> '><' <agent> - '|' <condition-on-attributes> '=>' <connections-with-expressions> - '|' <condition-on-attributes> '=>' <connections-with-expressions> - ... - '|' '_' '=>' <connections-with-expressions> ';' - -<condition-on-attributes> is an expression on attributes specified in the two <agent>. -``` - -The sequence of `<condition-on-attributes> ` must be finished with the otherwise case `_`. - -* Example: The following shows rules to obtain a list that contains only even numbers: - - ``` - // Rules - evenList(result) >< [] => r~[]; - evenList(result) >< (int x):xs - | x%2==0 => result~(x:cnt), evenList(cnt)~xs - | _ => evenList(result)~xs; - ``` - - ``` - >>> evenList(r)~[1,3,7,5,3,4,9,10]; - >>> r; - [4,10] - >>> free r; - >>> - ``` - - - -- Example: Fibonacci number: - - ``` - fib(result) >< (int n) - | n == 0 => result~0 - | n == 1 => result~1 - | _ => fib(r1)~(n-1), fib(r2)~(n-2), Add(result, r2)~r1; - - // * We cannot write result~(r1+r2) for Add(resut, r2)~r1 - // because r1, r2 may have not been connected to attributes in the anonymous agents, - // thus we have to leave the addition until fib(r1)~(n-1), fib(r2)~(n-2) are finished. - // For this purpose we must use the addition operation between agents defined as - // Add(result, y)><(int x) => _Add(result, x)~y; - // _Add(result, int x)><(int y) => result~(x+y); - // By using this as Add(result, r2)~r1, - // after r1,r2 have been connected to (int x), (int y), respectively, - // x+y is executed and the calculation result is connected to the result safely. - ``` - - ``` - >>> fib(r)~39; - >>> r; - 63245986 - >>> free r; - >>> - ``` - - - -## Commands - -Inpla has the following commands: -* `free` *name1* ... *name_n* `;` - The *name1* ... *name_n* and connected terms from these are disposed. To dispose every living name and term connected from those, type `free ifce;`, where the `ifce` is an abbreviation of *interface* that is called for the set of names that live and occur once. -* *name1* ... *name_n* `;` - Put terms connected from the *name1* ... *name_n*. To put every term connected from the interface, type `ifce;`. -* `prnat` *name*`;` - Put a term connected from the *name* as a natural number. -* `use` `"`filename`";` - Read the file named as "filename". -* `exit;` - Quit the system. - -Inpla has the following macro: -* `const` *NAME*`=` *i* `;` - The *NAME* is bound to the integer value *i* as immutable, and replaced with the value *i* in nets and interaction rules. - - - -## Execution Options - -* When invoking Inpla, you can specify the following options: - - ``` - $ ./inpla -h - Inpla version 0.8.0 - Usage: inpla [options] - - Options: - -f <filename> Set input file name (Defalut: STDIN) - -d <Name>=<val> Bind <val> to <Name> - -Xms <num> Set initial heap size to 2^<num> (Defalut: 12 (=4096)) - -Xmt <num> Set multiple heap increment to 2^<num> (Defalut: 3 (= 8)) - 0: the same size heap is inserted when it runs up. - 1: the twice (=2^1) size heap is inserted. - -Xes <num> Set initial equation stack size (Default: 256) - -w Enable Weak Reduction strategy (Default: false) - -t <num> Set the number of threads (Default: 8) - -h Print this help message - ``` - -**Note**: - -* The option `-w` is available for the single-thread version. -* The option ```-t``` is available for the multi-thread version that is compiled by ```make thread```. The default value is setting for the number of cores, so execution will be automatically scaled without specifying this. - - +## How to write programs in Inpla +[How_to_write_programs.md](How_to_write_programs.md) explains how to make programs in Inpla step by step. Please see it! ## Updates @@ -850,207 +270,6 @@ Inpla has the following macro: See [Changelog.md](Changelog.md) for details. -### v0.8.0 (released on 27 February 2022) - -#### New Features: - -* **Flexibly expandable ring buffer for agents and names**: We can change the size of buffers that are inserted when all of nodes run up, though it was fixed before. It is possible to start a small heap for small computation, and it can be expanded for larger computation. - -  - - * To set the initial size to 2^*n*, use the execution option `-Xms n` (default `n` is 12, so the size is 4096): - * To set the increasing magnification to 2^*n*, use the option `-Xmt n` (default `n` is 3, so the inserted heap is 8 times of the run up heap) - - See [Changelog.md](Changelog.md) for more details. - - - -### v0.7.0 (released on 30 January 2022) - -#### New Features: - -* **Logical operators on integers**: Not `!` (`not`), And `&&` (`and`) and Or `||` (`or`) are available. Only `0` is regarded as False and these operators return `1` for Truth, `0` for False. -* **Bytecode optimisations**: Bytecodes are optimised by Copy propagation, Dead code elimination methods. See [Changelog.md](Changelog.md) for more details. - - - -### v0.6.0 (released on 9 January 2022) - -#### New Features: - -* **Introduced new data structure for ring buffers for agents and names**: The ring buffers are automatically expanded when all elements of these are used up. See [Changelog.md](Changelog.md) for more details. - - - -### Logo of Inpla (relased on 27 December 2021) - -* A logo is released as an idea: - -  - - -### Feature of Version 0.5.0 (released on 28 October 2021) - -* **Abbreviation notation**: An abbreviation notation `<<` is introduced. The following description: - - ``` - a,b,...,z << Agent(aa,bb,...,yy,zz) - ``` - - is rewritten internally as follows: - - ``` - Agent(a,b,...,z,aa,bb,...,yy) ~ zz - ``` - - For instance, `r << Add(1,2)` is rewritten internally as `Add(r,1)~2`. It is handy to denote ports that take computation results. As a special case we prepare a built-in abbreviation for the built-in agent `Append(a,b)` because the order of those arguments `a`, `b` is different from the abbreviation rewriting rule: - - ``` - ret << Append(a,b) --- rewritten as ---> Append(ret,b)~a - ``` - -* **Merger agent that merges two lists into one**: Merger agent is implemented, such that it has two principal ports for the two lists, and whose interactions are performed as soon as one of the principal ports is ready for the interaction, that is to say, connected to a list. So, the merged result is decided non-deterministically, especially in multi-threaded execution. - -  - - We overload `<<` in order to use the Merger agent naturally as follows: - - ``` - ret << Merger(alist, blist) - ``` - - The following is an execution example (the count of interactions is not supported yet): - ``` - >>> r << Merger([0,0,0,0,0,0,0,0,0,0], [1,1,1,1,1,1,1,1,1,1]); - (1 interactions by 4 threads, 0.10 sec) - >>> ifce; - r - - Connections: - r ->[0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0] - - >>> - ``` - - -* **Built-in rules for arithmetic operations between two agents**: These operation, besides `Add`, are fully implemented and managed by agents `Sub`, `Mul`, `Div`, `Mod`: - - ``` - >>> r1<<Add(3,5), r2<<Sub(r1,2); - >>> ifce; // put all interface (living names) and connected nets. - r2 - - Connections: - r2 ->6 - - >>> - ``` - - These are useful to join safely two computational results on two agents in multi-threaded execution regardless of finished status of the two agents, because there rules are written so that the arithmetic operation can be invoked after ensuring that every argument modified by `int` has an attribute value as follows: - - ``` - Add(ret, b) >< (int a) => _Add(ret, a)~b; - _Add(ret, int a) >< (int b) => r~(a+b); - ``` - - For instance, in the following rules for Fibonacci numbers, we can join two recursively computed results safely: - - ``` - // Fibonacci number - - // Rules - fib(ret) >< (int n) - | n == 0 => ret~0 - | n == 1 => ret~1 - | _ => fib(cnt1)~(n-1), fib(cnt2)~(n-2), Add(ret,cnt1)~cnt2; - ``` - - The last line is also written by the abbreviation naturally: - - ``` - | _ => cnt1<<fib(n-1), cnt2<<fib(n-2), ret<<Add(cnt1,cnt2); - ``` - - - -### Features of Version 0.4 - -#### Summaries -* Integer numbers can be written the same as one of the first-class objects. -* Interaction rules can re-allocate heaps of the rule agents to agents in nets. This re-allocation is specified by modifications such as `(*L)`, `(*R)`, called reuse annotation [1], in front of agents in nets, such as `(*L)Add(r,a)`. This re-allocation can improve performance in multi-threaded execution. This is experimental, thus in future version these can be decided automatically, so please do not care so much. -* Weak reduction strategy is supported. It turns on by invoked with ```-w``` option, and then only connections that have living names are evaluated. -* Nested guards in conditional rules are supporeted. -* Line edit supports multi-line inputs. - - - -### Reuse annotations - -In interaction rule definitions, we can specify which agent is reused in the nets again by annotations `(*L)` and `(*R)`, which means the left-hand side and the right-hand side agents in the rule. This annotations promote in-place computing, and as the result performance in parallel execution can be improved well. - -* For instance, in the rule `gcd(ret) >< (int a, int b)`, we can reuse the `gcd` and `Tuple2` in nets as follows: - - ``` - gcd(ret) >< (int a, int b) - | b==0 => ret ~ a - | _ => (*L)gcd(ret) ~ (*R)(b, a%b); - ``` - - - -### Weak reduction strategy - -In this reduction strategy, only connections that have interface names (thus, live and occur once) are evaluated. This is taken for non-terminate computation such as fixed point combinator and process networks. - -* Example: We have a sample net in `sample/processnet1.in` that keep producing natural numbers from 1 and output these to the port `r`: - - ``` - // Rules - dup(a1,a2) >< (int i):xs => a1~(i:xs1), a2~(i:xs2), dup(xs1,xs2)~xs; - dup(a1,a2) >< [] => a1~[], a2~[]; - - inc(r) >< (int i):xs => r~(i+1):w, inc(w)~xs; - inc(r) >< [] => r~[]; - - // Nets - dup(r,w)~r1, inc(r1) ~ 0:w; - - // +-----+ +-----+ +---+ - // r ----| | r1 | | | | - // | dup |--->---| inc |---><---| 0 |----+ - // +---| | | | | | | - // | +-----+ +-----+ +---+ | - // | | - // +-----------------------------------------+ - // w - ``` - - This is executable in this reduction strategy as follows: - - ``` - $ ./inpla -w - Inpla 0.5.0 (Weak Strategy) : Interaction nets as a programming language [28 Oct. 2021] - >>> use "sample/processnet1.in"; - (2 interactions, 0.00 sec) - >>> ifce; - r - - Connections: - r ->[1,<a1>... // this means a list of 1 and something. - - >>> a:b ~ r; - (2 interactions, 0.00 sec) - >>> ifce; - a b - - Connections: - a ->1 - b ->[2,<b1>... - - >>> - ``` - - |
