"This external function converts a string to upper-case letters. It currently converts also diacritical marks (this behaviour may in future be controlled by an additional flag or option).\n",
"\n",
"Type: $STRING \\rightarrow STRING $."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$\\text{\"ABC_ABC\"}$"
],
"text/plain": [
"\"ABC_ABC\""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"STRING_TO_UPPER(\"abc_ABC\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$\\text{\"AZ-AZ-09-AAOU-AO\"}$"
],
"text/plain": [
"\"AZ-AZ-09-AAOU-AO\""
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"STRING_TO_UPPER(\"az-AZ-09-äàöù-ÄÖ\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$\\text{\"\"}$"
],
"text/plain": [
"\"\""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"STRING_TO_UPPER(\"\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### STRING_TO_LOWER\n",
"\n",
"This external function converts a string to lower-case letters. It currently converts also diacritical marks (this behaviour may in future be controlled by an additional flag or option).\n",
"\n",
"Type: $STRING \\rightarrow STRING $."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$\\text{\"az-az-09-aaou-ao\"}$"
],
"text/plain": [
"\"az-az-09-aaou-ao\""
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"STRING_TO_LOWER(\"az-AZ-09-äàöù-ÄÖ\")"
]
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"metadata": {},
"metadata": {},
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# External Functions
# External Functions
## LibraryStrings
## LibraryStrings
In pure B there are only two built-in operators on strings: equality $=$ and inequality $\neq$.
In pure B there are only two built-in operators on strings: equality $=$ and inequality $\neq$.
This library provides several string manipulation functions, and assumes that STRINGS are
This library provides several string manipulation functions, and assumes that STRINGS are
sequences of unicode characters (in UTF-8 encoding).
sequences of unicode characters (in UTF-8 encoding).
You can obtain the definitions below by putting the following into your DEFINITIONS clause:
You can obtain the definitions below by putting the following into your DEFINITIONS clause:
`DEFINITIONS "LibraryStrings.def"`
`DEFINITIONS "LibraryStrings.def"`
The file `LibraryStrings.def` is bundled with ProB and can be found in the `stdlib` folder.
The file `LibraryStrings.def` is bundled with ProB and can be found in the `stdlib` folder.
You can also include the machine `LibraryStrings.mch` instead of the definition file;
You can also include the machine `LibraryStrings.mch` instead of the definition file;
the machine defines some of the functions below as proper B functions (i.e., functions
the machine defines some of the functions below as proper B functions (i.e., functions
for which you can compute the domain and use constructs such as
for which you can compute the domain and use constructs such as
relational image).
relational image).
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
::load
::load
MACHINE Jupyter_LibraryStrings
MACHINE Jupyter_LibraryStrings
DEFINITIONS "LibraryStrings.def"
DEFINITIONS "LibraryStrings.def"
END
END
```
```
%% Output
%% Output
Loaded machine: Jupyter_LibraryStrings
Loaded machine: Jupyter_LibraryStrings
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### STRING_APPEND
### STRING_APPEND
This external function takes two strings and concatenates them.
This external function takes two strings and concatenates them.
Type: $STRING \times STRING \rightarrow STRING $.
Type: $STRING \times STRING \rightarrow STRING $.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_APPEND("abc","abc")
STRING_APPEND("abc","abc")
```
```
%% Output
%% Output
$\text{"abcabc"}$
$\text{"abcabc"}$
"abcabc"
"abcabc"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_APPEND("abc","")
STRING_APPEND("abc","")
```
```
%% Output
%% Output
$\text{"abc"}$
$\text{"abc"}$
"abc"
"abc"
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### STRING_LENGTH
### STRING_LENGTH
This external function takes a string and returns the length.
This external function takes a string and returns the length.
Type: $STRING \rightarrow INTEGER$.
Type: $STRING \rightarrow INTEGER$.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_LENGTH("abc")
STRING_LENGTH("abc")
```
```
%% Output
%% Output
$3$
$3$
3
3
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_LENGTH("")
STRING_LENGTH("")
```
```
%% Output
%% Output
$0$
$0$
0
0
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### STRING_SPLIT
### STRING_SPLIT
This external function takes two strings and separates the first string
This external function takes two strings and separates the first string
according to the separator specified by the second string.
according to the separator specified by the second string.
This external function is the inverse of the ```STRING_CODES``` function above.
Type: $\mathit{seq}(INTEGER)\rightarrow STRING$.
%% Cell type:code id: tags:
``` prob
CODES_TO_STRING([65,66,67])
```
%% Output
$\text{"ABC"}$
"ABC"
%% Cell type:markdown id: tags:
### STRING_TO_UPPER
This external function converts a string to upper-case letters. It currently converts also diacritical marks (this behaviour may in future be controlled by an additional flag or option).
Type: $STRING \rightarrow STRING $.
%% Cell type:code id: tags:
``` prob
STRING_TO_UPPER("abc_ABC")
```
%% Output
$\text{"ABC_ABC"}$
"ABC_ABC"
%% Cell type:code id: tags:
``` prob
STRING_TO_UPPER("az-AZ-09-äàöù-ÄÖ")
```
%% Output
$\text{"AZ-AZ-09-AAOU-AO"}$
"AZ-AZ-09-AAOU-AO"
%% Cell type:code id: tags:
``` prob
STRING_TO_UPPER("")
```
%% Output
$\text{""}$
""
%% Cell type:markdown id: tags:
### STRING_TO_LOWER
This external function converts a string to lower-case letters. It currently converts also diacritical marks (this behaviour may in future be controlled by an additional flag or option).
Type: $STRING \rightarrow STRING $.
%% Cell type:code id: tags:
``` prob
STRING_TO_LOWER("az-AZ-09-äàöù-ÄÖ")
```
%% Output
$\text{"az-az-09-aaou-ao"}$
"az-az-09-aaou-ao"
%% Cell type:markdown id: tags:
### SUB_STRING
### SUB_STRING
This external function takes a strings a position and a sequence and produces a corresponding substring.
This external function takes a strings a position and a sequence and produces a corresponding substring.
The numbering starts at 1 and the position must be at least 1, but can extend beyond the end of the string.
The numbering starts at 1 and the position must be at least 1, but can extend beyond the end of the string.
This external predicate takes a string and is true if the string represents an integer.
This external predicate takes a string and is true if the string represents an integer.
Type: $STRING $.
Type: $STRING $.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("1204")
STRING_IS_INT("1204")
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("-1204")
STRING_IS_INT("-1204")
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT(" - 1204")
STRING_IS_INT(" - 1204")
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("1.1")
STRING_IS_INT("1.1")
```
```
%% Output
%% Output
$\mathit{FALSE}$
$\mathit{FALSE}$
FALSE
FALSE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("1.0")
STRING_IS_INT("1.0")
```
```
%% Output
%% Output
$\mathit{FALSE}$
$\mathit{FALSE}$
FALSE
FALSE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("a")
STRING_IS_INT("a")
```
```
%% Output
%% Output
$\mathit{FALSE}$
$\mathit{FALSE}$
FALSE
FALSE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("1000000000000000000000000000")
STRING_IS_INT("1000000000000000000000000000")
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("-00001")
STRING_IS_INT("-00001")
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_IS_INT("00002")
STRING_IS_INT("00002")
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
TRUE
TRUE
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### STRING_TO_INT
### STRING_TO_INT
This external function takes a string and converts it into an integer.
This external function takes a string and converts it into an integer.
An error is raised if this cannot be done.
An error is raised if this cannot be done.
It is safer to first check with `STRING_IS_INT` whether the conversion can be done.
It is safer to first check with `STRING_IS_INT` whether the conversion can be done.
Type: $STRING \rightarrow INTEGER$.
Type: $STRING \rightarrow INTEGER$.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_TO_INT("1024")
STRING_TO_INT("1024")
```
```
%% Output
%% Output
$1024$
$1024$
1024
1024
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_TO_INT(" - 00001")
STRING_TO_INT(" - 00001")
```
```
%% Output
%% Output
$-1$
$-1$
−1
−1
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### INT_TO_STRING
### INT_TO_STRING
This external function converts an integer to a string representation.
This external function converts an integer to a string representation.
Type: $INTEGER \rightarrow STRING $.
Type: $INTEGER \rightarrow STRING $.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
INT_TO_STRING(1024)
INT_TO_STRING(1024)
```
```
%% Output
%% Output
$\text{"1024"}$
$\text{"1024"}$
"1024"
"1024"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
INT_TO_STRING(-1024)
INT_TO_STRING(-1024)
```
```
%% Output
%% Output
$\text{"-1024"}$
$\text{"-1024"}$
"-1024"
"-1024"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
INT_TO_STRING(STRING_TO_INT(" - 00001"))
INT_TO_STRING(STRING_TO_INT(" - 00001"))
```
```
%% Output
%% Output
$\text{"-1"}$
$\text{"-1"}$
"-1"
"-1"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_TO_INT(INT_TO_STRING(-1))=-1
STRING_TO_INT(INT_TO_STRING(-1))=-1
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
TRUE
TRUE
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### DEC_STRING_TO_INT
### DEC_STRING_TO_INT
This external function takes a decimal string (with optional decimal places) and converts it to an integer with the given precision (rounding if required).
This external function takes a decimal string (with optional decimal places) and converts it to an integer with the given precision (rounding if required).
This external function converts an integer to a hexadecimal string representation.
This external function converts an integer to a hexadecimal string representation.
Type: $INTEGER \rightarrow STRING $.
Type: $INTEGER \rightarrow STRING $.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
INT_TO_HEX_STRING(254)
INT_TO_HEX_STRING(254)
```
```
%% Output
%% Output
$\text{"fe"}$
$\text{"fe"}$
"fe"
"fe"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
INT_TO_HEX_STRING(0)
INT_TO_HEX_STRING(0)
```
```
%% Output
%% Output
$\text{"0"}$
$\text{"0"}$
"0"
"0"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
INT_TO_HEX_STRING(-254)
INT_TO_HEX_STRING(-254)
```
```
%% Output
%% Output
$\text{"-fe"}$
$\text{"-fe"}$
"-fe"
"-fe"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
INT_TO_HEX_STRING(2**100-1)
INT_TO_HEX_STRING(2**100-1)
```
```
%% Output
%% Output
$\text{"fffffffffffffffffffffffff"}$
$\text{"fffffffffffffffffffffffff"}$
"fffffffffffffffffffffffff"
"fffffffffffffffffffffffff"
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### TO_STRING
### TO_STRING
This external function converts a B data value to a string representation.
This external function converts a B data value to a string representation.
Type: $\tau \rightarrow STRING$.
Type: $\tau \rightarrow STRING$.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
TO_STRING(1024)
TO_STRING(1024)
```
```
%% Output
%% Output
$\text{"1024"}$
$\text{"1024"}$
"1024"
"1024"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
TO_STRING("1024")
TO_STRING("1024")
```
```
%% Output
%% Output
$\text{"1024"}$
$\text{"1024"}$
"1024"
"1024"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
TO_STRING({2,3,5})
TO_STRING({2,3,5})
```
```
%% Output
%% Output
$\text{"{2,3,5}"}$
$\text{"{2,3,5}"}$
"{2,3,5}"
"{2,3,5}"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
TO_STRING((TRUE,3,{11|->rec(a:22,b:33)}))
TO_STRING((TRUE,3,{11|->rec(a:22,b:33)}))
```
```
%% Output
%% Output
$\text{"(TRUE|->3|->{(11|->rec(a:22,b:33))})"}$
$\text{"(TRUE|->3|->{(11|->rec(a:22,b:33))})"}$
"(TRUE|->3|->{(11|->rec(a:22,b:33))})"
"(TRUE|->3|->{(11|->rec(a:22,b:33))})"
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### FORMAT_TO_STRING
### FORMAT_TO_STRING
This external function takes a format string and a B sequence of values and generates an output string, where the values have been inserted into the format string in place of the `~w` placeholders.
This external function takes a format string and a B sequence of values and generates an output string, where the values have been inserted into the format string in place of the `~w` placeholders.
- the length of sequence must correspond to the number of `~w` in the format string.
- the length of sequence must correspond to the number of `~w` in the format string.
- the format string follows the conventions of SICStus Prolog.
- the format string follows the conventions of SICStus Prolog.
E.g., one can use `~n` for newlines.
E.g., one can use `~n` for newlines.
Type: $(STRING*seq(\tau)) \rightarrow STRING$.
Type: $(STRING*seq(\tau)) \rightarrow STRING$.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
FORMAT_TO_STRING("two to the power ten = ~w",[2**10])
FORMAT_TO_STRING("two to the power ten = ~w",[2**10])
```
```
%% Output
%% Output
$\text{"two to the power ten = 1024"}$
$\text{"two to the power ten = 1024"}$
"two to the power ten = 1024"
"two to the power ten = 1024"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
FORMAT_TO_STRING("My two sets are ~w and ~w",[1..2,2..1])
FORMAT_TO_STRING("My two sets are ~w and ~w",[1..2,2..1])
```
```
%% Output
%% Output
$\text{"My two sets are {1,2} and {}"}$
$\text{"My two sets are {1,2} and {}"}$
"My two sets are {1,2} and {}"
"My two sets are {1,2} and {}"
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
#### Format Strings
#### Format Strings
Various external functions and predicates work with format strings.
Various external functions and predicates work with format strings.
ProB uses the conventions of the SICStus Prolog format string.
ProB uses the conventions of the SICStus Prolog format string.
-`~n` inserts a newline into the generated output
-`~n` inserts a newline into the generated output
-`~Nn` where N is a number: it inserts $N$ newlines into the output
-`~Nn` where N is a number: it inserts $N$ newlines into the output
-`~w` inserts the next argument into the generated output
-`~w` inserts the next argument into the generated output
-`~i` consumes the next argument but ignores it; i.e., nothing is inserted into the output
-`~i` consumes the next argument but ignores it; i.e., nothing is inserted into the output
-`~~` inserts the tilde symbol into the generated output
-`~~` inserts the tilde symbol into the generated output
-`~N` inserts a newline if not at the beginning of the line
-`~N` inserts a newline if not at the beginning of the line
SICStus Prolog also uses a few other formatting codes, such as `~@`, `~p`,... which should not be used.
SICStus Prolog also uses a few other formatting codes, such as `~@`, `~p`,... which should not be used.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### STRINGIFY
### STRINGIFY
This external function converts a B expression to a string representation of the expression, not the value.
This external function converts a B expression to a string representation of the expression, not the value.
It can be used to obtain the name of variables.
It can be used to obtain the name of variables.
Warning: ProB may simplify and rewrite expressions (you can turn this off by setting the OPTIMIZE_AST preference to false).
Warning: ProB may simplify and rewrite expressions (you can turn this off by setting the OPTIMIZE_AST preference to false).
Another command is PROB_INFO_STR("parser-version") which does not work within Jupyter.
Another command is PROB_INFO_STR("parser-version") which does not work within Jupyter.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### PROB_STATISTICS
### PROB_STATISTICS
This external function provides access to various statistics in the form of integers about ProB.
This external function provides access to various statistics in the form of integers about ProB.
Type: $STRING \rightarrow INTEGER$.
Type: $STRING \rightarrow INTEGER$.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROB_STATISTICS("prolog-memory-bytes-used")
PROB_STATISTICS("prolog-memory-bytes-used")
```
```
%% Output
%% Output
$157096032$
$157096032$
157096032
157096032
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROB_STATISTICS("states")
PROB_STATISTICS("states")
```
```
%% Output
%% Output
$1$
$1$
1
1
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROB_STATISTICS("transitions")
PROB_STATISTICS("transitions")
```
```
%% Output
%% Output
$0$
$0$
0
0
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROB_STATISTICS("processed-states")
PROB_STATISTICS("processed-states")
```
```
%% Output
%% Output
$0$
$0$
0
0
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROB_STATISTICS("current-state-id")
PROB_STATISTICS("current-state-id")
```
```
%% Output
%% Output
$-1$
$-1$
−1
−1
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROB_STATISTICS("now-timestamp")
PROB_STATISTICS("now-timestamp")
```
```
%% Output
%% Output
$1551789761$
$1551789761$
1551789761
1551789761
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROB_STATISTICS("prolog-runtime")
PROB_STATISTICS("prolog-runtime")
```
```
%% Output
%% Output
$1535$
$1535$
1535
1535
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROB_STATISTICS("prolog-walltime")
PROB_STATISTICS("prolog-walltime")
```
```
%% Output
%% Output
$2519$
$2519$
2519
2519
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Other possible information fields are prolog-memory-bytes-free,
Other possible information fields are prolog-memory-bytes-free,
prolog-global-stack-bytes-used,
prolog-global-stack-bytes-used,
prolog-local-stack-bytes-used,
prolog-local-stack-bytes-used,
prolog-global-stack-bytes-free,
prolog-global-stack-bytes-free,
prolog-local-stack-bytes-free,
prolog-local-stack-bytes-free,
prolog-trail-bytes-used,
prolog-trail-bytes-used,
prolog-choice-bytes-used,
prolog-choice-bytes-used,
prolog-atoms-bytes-used,
prolog-atoms-bytes-used,
prolog-atoms-nb-used,
prolog-atoms-nb-used,
prolog-gc-count,
prolog-gc-count,
prolog-gc-time.
prolog-gc-time.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### PROJECT_STATISTICS
### PROJECT_STATISTICS
This external function provides access to various statistics in the form of integers about the current specification being processed, with all auxiliary files (i.e., project).
This external function provides access to various statistics in the form of integers about the current specification being processed, with all auxiliary files (i.e., project).
Type: $STRING \rightarrow INTEGER$.
Type: $STRING \rightarrow INTEGER$.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROJECT_STATISTICS("constants")
PROJECT_STATISTICS("constants")
```
```
%% Output
%% Output
$0$
$0$
0
0
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROJECT_STATISTICS("variables")
PROJECT_STATISTICS("variables")
```
```
%% Output
%% Output
$0$
$0$
0
0
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROJECT_STATISTICS("properties")
PROJECT_STATISTICS("properties")
```
```
%% Output
%% Output
$0$
$0$
0
0
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROJECT_STATISTICS("invariants")
PROJECT_STATISTICS("invariants")
```
```
%% Output
%% Output
$0$
$0$
0
0
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROJECT_STATISTICS("operations")
PROJECT_STATISTICS("operations")
```
```
%% Output
%% Output
$0$
$0$
0
0
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROJECT_STATISTICS("static_assertions")
PROJECT_STATISTICS("static_assertions")
```
```
%% Output
%% Output
$0$
$0$
0
0
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROJECT_STATISTICS("dynamic_assertions")
PROJECT_STATISTICS("dynamic_assertions")
```
```
%% Output
%% Output
$0$
$0$
0
0
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### PROJECT_INFO
### PROJECT_INFO
This external function provides access to various information strings about the current specification being processed, with all auxiliary files (i.e., project).
This external function provides access to various information strings about the current specification being processed, with all auxiliary files (i.e., project).
Type: $STRING \rightarrow POW(STRING)$.
Type: $STRING \rightarrow POW(STRING)$.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
PROJECT_INFO("files")
PROJECT_INFO("files")
```
```
%% Output
%% Output
$\{\text{"(machine from Jupyter cell).mch"},\text{"LibraryMeta.def"}\}$
$\{\text{"(machine from Jupyter cell).mch"},\text{"LibraryMeta.def"}\}$
{"(machine from Jupyter cell).mch","LibraryMeta.def"}
{"(machine from Jupyter cell).mch","LibraryMeta.def"}
This library provides various facilities to compute hash values for B values.
This library provides various facilities to compute hash values for B values.
You can obtain the definitions below by putting the following into your DEFINITIONS clause:
You can obtain the definitions below by putting the following into your DEFINITIONS clause:
`DEFINITIONS "LibraryHash.def"`
`DEFINITIONS "LibraryHash.def"`
The file `LibraryHash.def` is also bundled with ProB and can be found in the `stdlib` folder.
The file `LibraryHash.def` is also bundled with ProB and can be found in the `stdlib` folder.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
::load
::load
MACHINE Jupyter_LibraryHash
MACHINE Jupyter_LibraryHash
DEFINITIONS "LibraryHash.def"
DEFINITIONS "LibraryHash.def"
END
END
```
```
%% Output
%% Output
Loaded machine: Jupyter_LibraryHash
Loaded machine: Jupyter_LibraryHash
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### HASH
### HASH
This external function converts a B data value to an integer hash value. It uses the ```term_hash``` predicate of SICStus Prolog. It will generate an integer that can be efficiently handled by ProB, but may generate collisions.
This external function converts a B data value to an integer hash value. It uses the ```term_hash``` predicate of SICStus Prolog. It will generate an integer that can be efficiently handled by ProB, but may generate collisions.
Type: $\tau \rightarrow INTEGER$.
Type: $\tau \rightarrow INTEGER$.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
HASH({1,2,4})
HASH({1,2,4})
```
```
%% Output
%% Output
$92915201$
$92915201$
92915201
92915201
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
HASH({1,2,5})
HASH({1,2,5})
```
```
%% Output
%% Output
$191034877$
$191034877$
191034877
191034877
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
i<: 1..7 & j<:1..7 & i /= j & HASH(i)=HASH(j)
i<: 1..7 & j<:1..7 & i /= j & HASH(i)=HASH(j)
```
```
%% Output
%% Output
$\mathit{FALSE}$
$\mathit{FALSE}$
FALSE
FALSE
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### SHA_HASH
### SHA_HASH
This external function converts a B data value to a SHA hash value represented as a sequence of bytes. It is unlikely to generate a collision.
This external function converts a B data value to a SHA hash value represented as a sequence of bytes. It is unlikely to generate a collision.
The library works on B strings and regular expression patterns are also written as B strings.
The library works on B strings and regular expression patterns are also written as B strings.
The syntax used is the ECMAScript syntax: http://www.cplusplus.com/reference/regex/ECMAScript/
The syntax used is the ECMAScript syntax: http://www.cplusplus.com/reference/regex/ECMAScript/
The library is currently implemented using the C++ standard library.
The library is currently implemented using the C++ standard library.
Below we repeat some information from http://www.cplusplus.com/reference/regex/ECMAScript/ for convenience.
Below we repeat some information from http://www.cplusplus.com/reference/regex/ECMAScript/ for convenience.
The library now does support UTF-8 encoded strings and patterns.
The library now does support UTF-8 encoded strings and patterns.
Note that ProB only supports UTF-8 for both B machines and for any strings and Unicode files it processes.
Note that ProB only supports UTF-8 for both B machines and for any strings and Unicode files it processes.
#### Operators/Quantifiers
#### Operators/Quantifiers
More precisely the library accepts the following operators:
More precisely the library accepts the following operators:
| Syntax | Descr. | Matches |
| Syntax | Descr. | Matches |
| --- | --- | --- |
| --- | --- | --- |
| ```*``` | 0 or more |The preceding atom is matched 0 or more times. |
| ```*``` | 0 or more |The preceding atom is matched 0 or more times. |
| ```+``` |1 or more |The preceding atom is matched 1 or more times. |
| ```+``` |1 or more |The preceding atom is matched 1 or more times. |
| ```?``` |0 or 1 |The preceding atom is optional (matched either 0 times or once). |
| ```?``` |0 or 1 |The preceding atom is optional (matched either 0 times or once). |
| ```{int}``` |int |The preceding atom is matched exactly int times. |
| ```{int}``` |int |The preceding atom is matched exactly int times. |
| ```{int,}``` |int or more |The preceding atom is matched int or more times. |
| ```{int,}``` |int or more |The preceding atom is matched int or more times. |
| ```{min,max}``` |between min and max |The preceding atom is matched at least min times, but not more than max. |
| ```{min,max}``` |between min and max |The preceding atom is matched at least min times, but not more than max. |
There is also the ```|``` separator.
There is also the ```|``` separator.
It separates two alternative patterns or subpatterns.
It separates two alternative patterns or subpatterns.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
#### Characters
#### Characters
The library accepts the following special characters:
The library accepts the following special characters:
| Syntax | Descr. | Matches |
| Syntax | Descr. | Matches |
| --- | --- | --- |
| --- | --- | --- |
| ```.``` | not newline | any character except line terminators (LF, CR, LS, PS).|
| ```.``` | not newline | any character except line terminators (LF, CR, LS, PS).|
| ```\t``` | tab (HT) | a horizontal tab character (same as \u0009).|
| ```\t``` | tab (HT) | a horizontal tab character (same as \u0009).|
| ```\n``` | newline (LF) | a newline (line feed) character (same as \u000A).|
| ```\n``` | newline (LF) | a newline (line feed) character (same as \u000A).|
| ```\v``` | vertical tab (VT) | a vertical tab character (same as \u000B).|
| ```\v``` | vertical tab (VT) | a vertical tab character (same as \u000B).|
| ```\f``` | form feed (FF) | a form feed character (same as \u000C).|
| ```\f``` | form feed (FF) | a form feed character (same as \u000C).|
| ```\r``` | carriage return (CR) | a carriage return character (same as \u000D).|
| ```\r``` | carriage return (CR) | a carriage return character (same as \u000D).|
| ```\cletter``` | control code | a control code character whose code unit value is the same as the remainder of dividing the code unit value of letter by 32.|
| ```\cletter``` | control code | a control code character whose code unit value is the same as the remainder of dividing the code unit value of letter by 32.|
For example: ```\ca``` is the same as ```\u0001```, ```\cb``` the same as ```\u0002```, and so on...
For example: ```\ca``` is the same as ```\u0001```, ```\cb``` the same as ```\u0002```, and so on...
| Syntax | Descr. | Matches |
| Syntax | Descr. | Matches |
| --- | --- | --- |
| --- | --- | --- |
| ```\xhh```| ASCII character| a character whose code unit value has an hex value equivalent to the two hex digits hh.|
| ```\xhh```| ASCII character| a character whose code unit value has an hex value equivalent to the two hex digits hh.|
For example: ```\x4c``` is the same as L, or ```\x23``` the same as #.
For example: ```\x4c``` is the same as L, or ```\x23``` the same as #.
| Syntax | Descr. | Matches |
| Syntax | Descr. | Matches |
| --- | --- | --- |
| --- | --- | --- |
| ```\uhhhh```| unicode character| a character whose code unit value has an hex value equivalent to the four hex digits hhhh.|
| ```\uhhhh```| unicode character| a character whose code unit value has an hex value equivalent to the four hex digits hhhh.|
| ```\0```| null| a null character (same as \u0000).|
| ```\0```| null| a null character (same as \u0000).|
| ```\int```| backreference| the result of the submatch whose opening parenthesis is the int-th (int shall begin by a digit other than 0). See groups below for more info.|
| ```\int```| backreference| the result of the submatch whose opening parenthesis is the int-th (int shall begin by a digit other than 0). See groups below for more info.|
| ```\d```| digit| a decimal digit character (same as [[:digit:]]).|
| ```\d```| digit| a decimal digit character (same as [[:digit:]]).|
| ```\D```| not digit| any character that is not a decimal digit character (same as [^[:digit:]]).|
| ```\D```| not digit| any character that is not a decimal digit character (same as [^[:digit:]]).|
| ```\s```| whitespace| a whitespace character (same as [[:space:]]).|
| ```\s```| whitespace| a whitespace character (same as [[:space:]]).|
| ```\S```| not whitespace| any character that is not a whitespace character (same as [^[:space:]]).|
| ```\S```| not whitespace| any character that is not a whitespace character (same as [^[:space:]]).|
| ```\w```| word| an alphanumeric or underscore character (same as [_[:alnum:]]).|
| ```\w```| word| an alphanumeric or underscore character (same as [_[:alnum:]]).|
| ```\W```| not word| any character that is not an alphanumeric or underscore character (same as [^_[:alnum:]]).|
| ```\W```| not word| any character that is not an alphanumeric or underscore character (same as [^_[:alnum:]]).|
| ```\character```| character| the character character as it is, without interpreting its special meaning within a regex expression.|
| ```\character```| character| the character character as it is, without interpreting its special meaning within a regex expression.|
Any character can be escaped except those which form any of the special character sequences above.
Any character can be escaped except those which form any of the special character sequences above.
Needed for: ```^ $ \ . * + ? ( ) [ ] { } |```
Needed for: ```^ $ \ . * + ? ( ) [ ] { } |```
| Syntax | Descr. | Matches |
| Syntax | Descr. | Matches |
| --- | --- | --- |
| --- | --- | --- |
| ```[class]```| character class| the target character is part of the class (see character classes below)|
| ```[class]```| character class| the target character is part of the class (see character classes below)|
| ```[^class]```| negated character class| the target character is not part of the class (see character classes below)|
| ```[^class]```| negated character class| the target character is not part of the class (see character classes below)|
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
#### Groups
#### Groups
Groups allow to apply quantifiers to a sequence of characters (instead of a single character). There are two kinds of groups:
Groups allow to apply quantifiers to a sequence of characters (instead of a single character). There are two kinds of groups:
| characters| description| effects|
| characters| description| effects|
| --- | --- | --- |
| --- | --- | --- |
| ```(subpattern)```| Group| Creates a backreference.
| ```(subpattern)```| Group| Creates a backreference.
| ```(?:subpattern)```| Passive group| Does not create a backreference.
| ```(?:subpattern)```| Passive group| Does not create a backreference.
#### Assertions
#### Assertions
Assertions are conditions that do not consume characters in the target sequence: they do not describe a character, but a condition that must be fulfilled before or after a character.
Assertions are conditions that do not consume characters in the target sequence: they do not describe a character, but a condition that must be fulfilled before or after a character.
characters description condition for match
characters description condition for match
-```^``` Beginning of line Either it is the beginning of the target sequence, or follows a line terminator.
-```^``` Beginning of line Either it is the beginning of the target sequence, or follows a line terminator.
-```$``` End of line Either it is the end of the target sequence, or precedes a line terminator.
-```$``` End of line Either it is the end of the target sequence, or precedes a line terminator.
-```\b``` Word boundary The previous character is a word character and the next is a non-word character (or vice-versa).
-```\b``` Word boundary The previous character is a word character and the next is a non-word character (or vice-versa).
Note: The beginning and the end of the target sequence are considered here as non-word characters.
Note: The beginning and the end of the target sequence are considered here as non-word characters.
-```\B``` Not a word boundary The previous and next characters are both word characters or both are non-word characters.
-```\B``` Not a word boundary The previous and next characters are both word characters or both are non-word characters.
Note: The beginning and the end of the target sequence are considered here as non-word characters.
Note: The beginning and the end of the target sequence are considered here as non-word characters.
-```(?=subpattern)``` Positive lookahead The characters following the assertion must match subpattern, but no characters are consumed.
-```(?=subpattern)``` Positive lookahead The characters following the assertion must match subpattern, but no characters are consumed.
-```(?!subpattern)``` Negative lookahead The characters following the assertion must not match subpattern, but no characters are consumed.
-```(?!subpattern)``` Negative lookahead The characters following the assertion must not match subpattern, but no characters are consumed.
#### Character classes
#### Character classes
A character class defines a category of characters. It is introduced by enclosing its descriptors in square brackets ([ and ]).
A character class defines a category of characters. It is introduced by enclosing its descriptors in square brackets ([ and ]).
The regex object attempts to match the entire character class against a single character in the target sequence (unless a quantifier specifies otherwise).
The regex object attempts to match the entire character class against a single character in the target sequence (unless a quantifier specifies otherwise).
The character class can contain any combination of:
The character class can contain any combination of:
Individual characters: Any character specified is considered part of the class (except the characters \, [, ] and - when they have a special meaning as described in the following paragraphs).
Individual characters: Any character specified is considered part of the class (except the characters \, [, ] and - when they have a special meaning as described in the following paragraphs).
For example:
For example:
```[abc]``` matches a, b or c.
```[abc]``` matches a, b or c.
```[^xyz]``` matches any character except x, y and z.
```[^xyz]``` matches any character except x, y and z.
Ranges: They can be specified by using the hyphen character (-) between two valid characters.
Ranges: They can be specified by using the hyphen character (-) between two valid characters.
For example:
For example:
```[a-z]``` matches any lowercase letter (a, b, c, ... until z).
```[a-z]``` matches any lowercase letter (a, b, c, ... until z).
```[abc1-5]``` matches either a, b or c, or a digit between 1 and 5.
```[abc1-5]``` matches either a, b or c, or a digit between 1 and 5.
POSIX-like classes: A whole set of predefined classes can be added to a custom character class. There are three kinds:
POSIX-like classes: A whole set of predefined classes can be added to a custom character class. There are three kinds:
class description notes
class description notes
- ```[:classname:]``` character class Uses the regex traits' isctype member with the appropriate type gotten from applying lookup_classname member on classname for the match.
- ```[:classname:]``` character class Uses the regex traits' isctype member with the appropriate type gotten from applying lookup_classname member on classname for the match.
- ```[.classname.]``` collating sequence Uses the regex traits' lookup_collatename to interpret classname.
- ```[.classname.]``` collating sequence Uses the regex traits' lookup_collatename to interpret classname.
- ```[=classname=]``` character equivalents Uses the regex traits' transform_primary of the result of regex_traits::lookup_collatename for classname to check for matches.
- ```[=classname=]``` character equivalents Uses the regex traits' transform_primary of the result of regex_traits::lookup_collatename for classname to check for matches.
The choice of available classes depend on the regex traits type and on its selected locale. But at least the following character classes shall be recognized by any regex traits type and locale:
The choice of available classes depend on the regex traits type and on its selected locale. But at least the following character classes shall be recognized by any regex traits type and locale:
class description equivalent (with regex_traits, default locale)
class description equivalent (with regex_traits, default locale)
- ```[:alnum:]``` alpha-numerical character isalnum
- ```[:alnum:]``` alpha-numerical character isalnum
- ```[:alpha:]``` alphabetic character isalpha
- ```[:alpha:]``` alphabetic character isalpha
- ```[:blank:]``` blank character isblank
- ```[:blank:]``` blank character isblank
- ```[:cntrl:]``` control character iscntrl
- ```[:cntrl:]``` control character iscntrl
- ```[:digit:]``` decimal digit character isdigit
- ```[:digit:]``` decimal digit character isdigit
- ```[:graph:]``` character with graphical representation isgraph
- ```[:graph:]``` character with graphical representation isgraph
- ```[:lower:]``` lowercase letter islower
- ```[:lower:]``` lowercase letter islower
- ```[:print:]``` printable character isprint
- ```[:print:]``` printable character isprint
- ```[:punct:]``` punctuation mark character ispunct
- ```[:punct:]``` punctuation mark character ispunct
- ```[:space:]``` whitespace character isspace
- ```[:space:]``` whitespace character isspace
- ```[:upper:]``` uppercase letter isupper
- ```[:upper:]``` uppercase letter isupper
- ```[:xdigit:]``` hexadecimal digit character isxdigit
- ```[:xdigit:]``` hexadecimal digit character isxdigit
- ```[:d:]``` decimal digit character isdigit
- ```[:d:]``` decimal digit character isdigit
- ```[:w:]``` word character isalnum
- ```[:w:]``` word character isalnum
- ```[:s:]``` whitespace character isspace
- ```[:s:]``` whitespace character isspace
Please note that the brackets in the class names are additional to those opening and closing the class definition.
Please note that the brackets in the class names are additional to those opening and closing the class definition.
For example:
For example:
```[[:alpha:]]``` is a character class that matches any alphabetic character.
```[[:alpha:]]``` is a character class that matches any alphabetic character.
```[abc[:digit:]]``` is a character class that matches a, b, c, or a digit.
```[abc[:digit:]]``` is a character class that matches a, b, c, or a digit.
```[^[:space:]]``` is a character class that matches any character except a whitespace.
```[^[:space:]]``` is a character class that matches any character except a whitespace.
Escape characters: All escape characters described above can also be used within a character class specification. The only change is with \b, that here is interpreted as a backspace character (\u0008) instead of a word boundary.
Escape characters: All escape characters described above can also be used within a character class specification. The only change is with \b, that here is interpreted as a backspace character (\u0008) instead of a word boundary.
Notice that within a class definition, those characters that have a special meaning in the regular expression (such as *, ., $) don't have such a meaning and are interpreted as normal characters (so they do not need to be escaped). Instead, within a class definition, the hyphen (-) and the brackets ([ and ]) do have special meanings under some circumstances, in which case they should be placed within the class in other locations where they do not have such special meaning, or be escaped with a backslash (\).
Notice that within a class definition, those characters that have a special meaning in the regular expression (such as *, ., $) don't have such a meaning and are interpreted as normal characters (so they do not need to be escaped). Instead, within a class definition, the hyphen (-) and the brackets ([ and ]) do have special meanings under some circumstances, in which case they should be placed within the class in other locations where they do not have such special meaning, or be escaped with a backslash (\).
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### REGEX_MATCH
### REGEX_MATCH
This external predicate checks if a string matches a regular expression pattern.
This external predicate checks if a string matches a regular expression pattern.
For example, the following calls check whether the first argument is a non-empty sequenze of lower-case letters:
For example, the following calls check whether the first argument is a non-empty sequenze of lower-case letters:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
REGEX_MATCH("abc","[a-z]+")
REGEX_MATCH("abc","[a-z]+")
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
REGEX_MATCH("abc1","[a-z]+")
REGEX_MATCH("abc1","[a-z]+")
```
```
%% Output
%% Output
$\mathit{FALSE}$
$\mathit{FALSE}$
FALSE
FALSE
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Here we check if we have a non-empty sequence of characters which are not letters:
Here we check if we have a non-empty sequence of characters which are not letters:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
REGEX_MATCH("123.45","[^a-zA-Z]+")
REGEX_MATCH("123.45","[^a-zA-Z]+")
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
REGEX_MATCH("1e9","[^a-zA-Z]+")
REGEX_MATCH("1e9","[^a-zA-Z]+")
```
```
%% Output
%% Output
$\mathit{FALSE}$
$\mathit{FALSE}$
FALSE
FALSE
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Observe that ```REGEX_MATCH``` is a **predicate** not a function returning a boolean value.
Observe that ```REGEX_MATCH``` is a **predicate** not a function returning a boolean value.
As such you can write:
As such you can write:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
str = "1.9" & (REGEX_MATCH(str,"[0-9]+") or REGEX_MATCH(str,"[0-9]*\.[0-9]+"))
str = "1.9" & (REGEX_MATCH(str,"[0-9]+") or REGEX_MATCH(str,"[0-9]*\.[0-9]+"))
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
**Solution:**
**Solution:**
* $\mathit{str} = \text{"1.9"}$
* $\mathit{str} = \text{"1.9"}$
TRUE
TRUE
Solution:
Solution:
str = "1.9"
str = "1.9"
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### IS_REGEXP
### IS_REGEXP
This external predicate checks if a string is a valid regular expression pattern.
This external predicate checks if a string is a valid regular expression pattern.
Again, this is a **predicate**, not a function returning a boolean value.
Again, this is a **predicate**, not a function returning a boolean value.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
IS_REGEX("ab[0-9]")
IS_REGEX("ab[0-9]")
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
IS_REGEX("ab[0-9")
IS_REGEX("ab[0-9")
```
```
%% Output
%% Output
$\mathit{FALSE}$
$\mathit{FALSE}$
FALSE
FALSE
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### REGEXP_REPLACE
### REGEXP_REPLACE
This external function replaces all occurences of a pattern in a string by a given replacement string.
This external function replaces all occurences of a pattern in a string by a given replacement string.
In case there is no match, it returns the empty string:
In case there is no match, it returns the empty string:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
REGEX_SEARCH_STR("0123","[[:alpha:]]+")
REGEX_SEARCH_STR("0123","[[:alpha:]]+")
```
```
%% Output
%% Output
$\text{""}$
$\text{""}$
""
""
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### REGEX_SEARCH
### REGEX_SEARCH
This external function searches for the first occurence of a pattern in a string and returns full information about the match: position, length, match and sub-matches.
This external function searches for the first occurence of a pattern in a string and returns full information about the match: position, length, match and sub-matches.
It also expects an index at which to start the search; which can be useful for writing loops to find all matches.
It also expects an index at which to start the search; which can be useful for writing loops to find all matches.
As regular expressions make heavy use of the backslash ```\``` it is important to know how B strings deal with backslashes.
As regular expressions make heavy use of the backslash ```\``` it is important to know how B strings deal with backslashes.
ProB supports two types of strings:
ProB supports two types of strings:
- single-line strings delimited using double quotation marks, e.g., ```"abc"```
- single-line strings delimited using double quotation marks, e.g., ```"abc"```
- multi-line strings delimited using three single quogtation marks. ```'''abc'''```
- multi-line strings delimited using three single quogtation marks. ```'''abc'''```
Inside both types of strings the following escape sequences using the backslash are recognised:
Inside both types of strings the following escape sequences using the backslash are recognised:
- ```\n``` stands simply for newline
- ```\n``` stands simply for newline
- ```\t``` stands simply for tab
- ```\t``` stands simply for tab
- ```\r``` stands for carriage return
- ```\r``` stands for carriage return
- ```\"``` stands simply for ```"``` (to be able to use quotes in single-line strings)
- ```\"``` stands simply for ```"``` (to be able to use quotes in single-line strings)
- ```\'``` stands simply for ```'``` (to be able to use quotes in multi-line strings)
- ```\'``` stands simply for ```'``` (to be able to use quotes in multi-line strings)
- ```\\``` stands simply for ```\``` (to be able to use backslash when preceding any of the above symbols)
- ```\\``` stands simply for ```\``` (to be able to use backslash when preceding any of the above symbols)
In all other contexts, i.e., for any value of ```c``` different from ```n,t,r,",',\```, the sequence ```\c``` simply stands for ```\c``` (i.e., the backslash remains unchanged in the string).
In all other contexts, i.e., for any value of ```c``` different from ```n,t,r,",',\```, the sequence ```\c``` simply stands for ```\c``` (i.e., the backslash remains unchanged in the string).
The following examples illustrate the above.
The following examples illustrate the above.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_LENGTH("\"")
STRING_LENGTH("\"")
```
```
%% Output
%% Output
$1$
$1$
1
1
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_LENGTH("\\\"")
STRING_LENGTH("\\\"")
```
```
%% Output
%% Output
$2$
$2$
2
2
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_LENGTH("\a")
STRING_LENGTH("\a")
```
```
%% Output
%% Output
$2$
$2$
2
2
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_LENGTH("\\a")
STRING_LENGTH("\\a")
```
```
%% Output
%% Output
$2$
$2$
2
2
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
"\a" = "\\a"
"\a" = "\\a"
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
TRUE
TRUE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
"\n" = "\\n"
"\n" = "\\n"
```
```
%% Output
%% Output
$\mathit{FALSE}$
$\mathit{FALSE}$
FALSE
FALSE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
"\\\""
"\\\""
```
```
%% Output
%% Output
$\text{"\\\""}$
$\text{"\\\""}$
"\\\""
"\\\""
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Note that the previous result thus contains two characters:
Note that the previous result thus contains two characters:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
STRING_CHARS("\\\"")
STRING_CHARS("\\\"")
```
```
%% Output
%% Output
:eval: Computation not completed: Unknown identifier "STRING_CHARS"
:eval: Computation not completed: Unknown identifier "STRING_CHARS"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
"\a"
"\a"
```
```
%% Output
%% Output
$\text{"\a"}$
$\text{"\a"}$
"\a"
"\a"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
"\\"
"\\"
```
```
%% Output
%% Output
$\text{"\\"}$
$\text{"\\"}$
"\\"
"\\"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
"(\d+)\D(\d+)\D(\d+)\D(\d+)"
"(\d+)\D(\d+)\D(\d+)\D(\d+)"
```
```
%% Output
%% Output
$\text{"(\d+)\D(\d+)\D(\d+)\D(\d+)"}$
$\text{"(\d+)\D(\d+)\D(\d+)\D(\d+)"}$
"(\d+)\D(\d+)\D(\d+)\D(\d+)"
"(\d+)\D(\d+)\D(\d+)\D(\d+)"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
"\b"
"\b"
```
```
%% Output
%% Output
$\text{"\b"}$
$\text{"\b"}$
"\b"
"\b"
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## LibraryProB
## LibraryProB
This library provides various facilities which are very specific to ProB.
This library provides various facilities which are very specific to ProB.
You can obtain the definitions below by putting the following into your DEFINITIONS clause:
You can obtain the definitions below by putting the following into your DEFINITIONS clause:
`DEFINITIONS "LibraryProB.def"`
`DEFINITIONS "LibraryProB.def"`
The file `LibraryProB.def` is bundled with ProB and can be found in the `stdlib` folder.
The file `LibraryProB.def` is bundled with ProB and can be found in the `stdlib` folder.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
::load
::load
MACHINE Jupyter_LibraryStrings
MACHINE Jupyter_LibraryStrings
DEFINITIONS "LibraryProB.def"
DEFINITIONS "LibraryProB.def"
END
END
```
```
%% Output
%% Output
Loaded machine: Jupyter_LibraryStrings
Loaded machine: Jupyter_LibraryStrings
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
With ```ASSERT_EXPR``` you can check assertions within expressions.
With ```ASSERT_EXPR``` you can check assertions within expressions.