# Difference between revisions of "Mathematical Language Evolution Design"

imported>Nicolas |
imported>Nicolas m (→Upgrade) |
||

Line 94: | Line 94: | ||

In these cases an upgrade procedure will be applied to the formula using a {{class|IFormulaRewriter}}, to rewrite KPRJ1, KPRJ2, KID expressions into their generic equivalent (see [[Changes to the Mathematical Language of Event-B#Generic Identity and Projections]]). | In these cases an upgrade procedure will be applied to the formula using a {{class|IFormulaRewriter}}, to rewrite KPRJ1, KPRJ2, KID expressions into their generic equivalent (see [[Changes to the Mathematical Language of Event-B#Generic Identity and Projections]]). | ||

− | Upgraded formulas can be obtained from a formula string by calling one of the new {{class|FormulaFactory}} {{method|upgrade}} methods. | + | Upgraded formulas can be obtained from a formula string by calling one of the new {{class|FormulaFactory}}{{method|.upgrade()}} methods. |

=== File upgrade === | === File upgrade === | ||

Line 182: | Line 182: | ||

==== Typing generic operators ==== | ==== Typing generic operators ==== | ||

− | {{ | + | The problem of typing generic operators arises when upgrading a fomula like <math>\operatorname{id(x)}</math>. |

+ | We know that, in the general case, the upgraded version is <math>x \domres \id</math>. | ||

+ | But which type should the generic <math>\id</math> bear ? | ||

+ | |||

+ | An answer is: | ||

+ | If the V1 operator is typed, then the V2 generic one should bear the same type. | ||

+ | |||

+ | Given the convention that <math>\operatorname{o}_T</math> means that <math>\operatorname{o}</math> has type <math>T</math>, this entails rewriting <math>\id_{T}(x)</math> into <math>x \domres \id_{T}</math>. | ||

+ | |||

+ | But then, what happens if <math>x</math> is a type expression,like <math>\mathbb{Z}</math> ? | ||

+ | |||

+ | We would come to rewriting <math>\id_{\mathbb{P}(\mathbb{Z}\times\mathbb{Z})}(\mathbb{Z})</math> into <math>\mathbb{Z} \domres \id_{\mathbb{P}(\mathbb{Z}\times\mathbb{Z})}</math>. | ||

+ | |||

+ | In this case, the domain restriction is clearly superfluous. This brings in a new rule: | ||

+ | If the V1 unary operator has a type expression for argument, then the V2 generic atomic one needs no domain restriction | ||

− | {| | + | Putting things together, the following table summarizes the upgrade of generic operators, based on the <math>\id</math> operator example. Similar rules apply to <math>\prjone</math> and <math>\prjtwo</math>. |

− | + | {| cellspacing="10" cellpadding="10" style="text-align:center;" | |

! scope=col | | ! scope=col | | ||

! scope=col |Math V1 | ! scope=col |Math V1 | ||

Line 191: | Line 205: | ||

|- | |- | ||

! scope=row |Type expression | ! scope=row |Type expression | ||

− | |<math>\ | + | |<math>\id_{\mathbb{P}(\mathbb{Z}\times\mathbb{Z})}(\mathbb{Z})</math> |

− | |<math>\ | + | |<math>\id_{\mathbb{P}(\mathbb{Z}\times\mathbb{Z})}</math> |

|- | |- | ||

! scope=row |Typed | ! scope=row |Typed | ||

− | |<math>\ | + | |<math>\id_{T}(x)</math> |

− | |<math>x \ | + | |<math>x \domres \id_{T}</math> |

|- | |- | ||

! scope=row |Not typed | ! scope=row |Not typed | ||

− | |<math>\ | + | |<math>\id(x)</math> |

− | |<math>x \domres \ | + | |<math>x \domres \id</math> |

|} | |} | ||

Line 206: | Line 220: | ||

{{TODO}} | {{TODO}} | ||

− | |||

== Sequent Prover == | == Sequent Prover == |

## Revision as of 10:10, 20 April 2009

## Introduction

This document describes the modifications that occur to the Event-B mathematical language from the developer point of view. The old language will still be recognized, in order to provide backward compatibility.

These changes are described from a user point of view in Changes to the Mathematical Language of Event-B.

## Abstract Syntax Tree

Deprecated nodes (becoming atomic expressions):

- KPRJ1
- KPRJ2
- KID

New nodes:

- KPARTITION that represents the new partition predicate (multiple predicate)
- KPRJ1_GEN that represents the generic atomic version of the first projection
- KPRJ2_GEN that represents the generic atomic version of the second projection
- KID_GEN that represents the generic atomic version of the identity

### Parser Changes

The new parser has a version attribute. Depending on the version, formulas are parsed differently. Thus, the KPARTITION node is a regular identifier if version is V1. It is accepted as a keyword only from version V2. Concerning identity and projections, they are recognized as non-generic with V1 and generic with V2. The following table summarizes how tokens are processed depending on the language version:

Language V1 | Language V2 | |
---|---|---|

"partition" | IDENT | KPARTITION |

"id" | KID | KID_GEN |

"prj1" | KPRJ1 | KPRJ1_GEN |

"prj2" | KPRJ2 | KPRJ2_GEN |

#### Parsing

FormulaFactory has new parse() methods with a language version argument. Existing methods default to the first version (LanguageVersion.V1), while becoming deprecated. Thus, one now has to know, before parsing a formula, the version of the language it has been written with. It also provides methods to upgrade to the new language version.

#### Multiple Predicates / Partition

A new predicate class is introduced: MultiplePredicate, in which the partition predicate is implemented. A MultiplePredicate is a predicate that applies to a list of one or more expressions. In a partition, all expressions must have the same type, that is the type of the partitioned set (first child).

#### Associativity

Newly non associative relational set operators now require parentheses around their operands for parsing to succeed. This is managed directly by the parser. Unparsing also requires those parentheses, so the BinaryExpression.toString() method has been changed accordingly.

#### Visitors

Partition, identity and projections also entail new visitor methods, as follows:

IVisitor has 6 more methods:

- enterKPARTITION(MultiplePredicate)
- continueKPARTITION(MultiplePredicate)
- exitKPARTITION(MultiplePredicate)
- visitKID_GEN(AtomicExpression)
- visitKPRJ1_GEN(AtomicExpression)
- visitKPRJ2_GEN(AtomicExpression)

ISimpleVisitor has 1 more method:

- visitMultiplePredicate(MultiplePredicate)

Thus, implementors of those interfaces are required to implemented new methods, while subclassers of DefaultVisitor and DefaultSimpleVisitor should consider whether or not to override them.

## Upgrade

Formulas written with version V1 will need upgrading to version V2. However, most of the V1 formulas will be exactly the same with V2. A formula needs ugrading if:

- it contains one of {KPRJ1, KPRJ2, KID}
- it contains a non parenthesised sequence of relational set operators

In these cases an upgrade procedure will be applied to the formula using a IFormulaRewriter, to rewrite KPRJ1, KPRJ2, KID expressions into their generic equivalent (see Changes to the Mathematical Language of Event-B#Generic Identity and Projections).

Upgraded formulas can be obtained from a formula string by calling one of the new FormulaFactory.upgrade() methods.

### File upgrade

Existing rodin files with V1 formulas inside need converting to V2 formulas. Concerned files are:

- Contexts
- Machines
- Proofs

This is managed through the version tools of the rodin core package: a new version number for each of these files represents the passing from V1 to V2 mathematical language. The following table summarizes the correspondence between file version number and mathematical version number:

Math V1 | Math V2 | |
---|---|---|

Context | ||

Machine | ||

Proof |

In those XML files, the formulas are written inside various attributes. Existing version conversion tools (in

) allowed making changes to the structure of the files (adding an element, renaming an attribute, …), through XSL transformations, targetting a single element to apply the conversion to.

But upgrading formulas entails dealing with the contents of attributes in various elements dispatched all over the file. So, extending the conversion tools, a new conversion operation is implemented (ModifyAttribute) that changes the contents of an attribute, together with a new kind of file conversion: 'multiple' conversion, in contrast to 'simple' conversion. This new one allows targetting several elements through unrestricted XPath expressions.

These new core tools extend the existing 'conversions' extension point. It now allows writing conversion extensions in

client package that target every assignment, expression or predicate in any context, machine or proof file and upgrade their contents to the new language version.

The modifying code is delegated to the client that must provide, in the conversion extension, a class that implements IAttributeModifier. It builds the new string value of the attribute from the value read in the file. In our case, it builds a V2 formula that is the upgraded equivalent to the given V1 formula.

### Formula upgrade

#### Formatting

Ideally, upgrading a formula would preserve its previous formatting (spaces, tabs, new lines). But this turns out being quite tricky. Indeed, it prevents from simply rewriting the formula then applying a toString(), as this would totally forget and override any formatting. Thus, we would have to write directly into the original string. Firstly find the source locations where changes will occur, then patching the formula with the new expression versions at those source locations.

But that leads to more complexity when we come to consider formulas that contain

- recursive relational set operators (that recursively shift source locations)
- binary operators with higher priorities nearby (that mindlessly absorb a member of the rewritten expression)

Let's look at the following formula:

A straight rewriting would proceed as follows:

- which already is false (requires parentheses)

Then, with the appropriate shift of the source location to replace the first operator:

- which is even worse

This suggests putting parentheses around rewritten expressions. But they would sometimes be superfluous, which brings us to distinguish cases where they are needed and cases where they are not, depending on the priority of the operators nearby.

Considering this is going quite far, a simpler upgrade method is applied:

- if the formula does not use deprecated expressions, nor lacks parentheses around relational set operators, it is left unchanged, preserving the formatting
- it it does, it is rewritten and any previous formatting is overridden

#### Detecting missing parentheses

Missing parentheses can be quite easily detected, given a parsed formula and its string.

Using a visitor, we check each relational set expression.

Starting from its source location, we search the string for parentheses towards both left and right directions around the expression, skipping space characters. If the first non space character is not the expected parenthesis, then one is missing and the formula needs upgrading to V2.

The fussy part is about the definition of space characters.

c is an Event-B white space character if one of the following holds: * java.lang.Character.isSpaceChar(c) * '\u0009' <= c && c <= '\u000d' * '\u001c' <= c && c <= '\u001f'

A new isEventBWhiteSpace(char) method has been provided in FormulaFactory to prevent developers from worrying about the details of this matter.

#### Typing generic operators

The problem of typing generic operators arises when upgrading a fomula like . We know that, in the general case, the upgraded version is . But which type should the generic bear ?

An answer is:

If the V1 operator is typed, then the V2 generic one should bear the same type.

Given the convention that means that has type , this entails rewriting into .

But then, what happens if is a type expression,like ?

We would come to rewriting into .

In this case, the domain restriction is clearly superfluous. This brings in a new rule:

If the V1 unary operator has a type expression for argument, then the V2 generic atomic one needs no domain restriction

Putting things together, the following table summarizes the upgrade of generic operators, based on the operator example. Similar rules apply to and .

Math V1 | Math V2 | |
---|---|---|

Type expression | ||

Typed | ||

Not typed |

#### Not upgradable cases

**TODO**

## Sequent Prover

**TODO**