========
Function
========

This grammar adds bounds to Modelica models by translating Modelica
variable declarations and equations into sequences of the same
representing bounds. Currently available sorts of bounds are min/max
(translates a variable 'x' into two variables 'x_min' and 'x_max') and
standard deviation ('x_val' and 'x_var').

The grammar processes several Modelica files in command-line order,
passing definitions from earlier files on in an environment for
reference in later files.

====================
Syntactic extensions
====================

This grammar parses an extended version of Modelica that allows for
the explicit setting of bounds on variable declarations. A bounds
statement may appear after a variable declaration and initializing
assignment in this fashion:

    Real x = 4 bounded { <bounds> };

Currently supported bounds are:

* Inequality: For the min/max bounds; forces a variable to remain
within an absolute bound. At present there is only one available
inequality bound: greater than or equal to a constant number. For
example,

   Real x = y bounded { always >= 0 };

would be translated to

   Real x_min = max(y_min,0), x_max = max(y_max,0);

* Absolute error: For the min/max bounds; allows the variable to
deviate by the assigned value by no more than the given constant
number. For example,

    Real x = 4 bounded { plusminus 1 };

would be translated to

    Real x_min = 4 - 1, x_max = 4 + 1;

* Relative error: For the min/max bounds; allows the
variable to deviate from its assigned value by no more than the given
percentage of that value. For example,

    Real x = 4 bounded { plusminus 10% };

would be translated to

    Real x_min = 4 * ((100 - 10) / 100), x_max = 4 * ((100 + 10) / 100);

* Variance: For the standard-deviation bounds; sets the variance on
such a bound. For example,

    Real x = 4 { var = 6 };

would be translated to

    Real x_val = 4, x_var = 6;

* Several bounds may provided for the same variable, comma-separated.
The types of bounds that can be used together are limited; the
translator will produce an error if two conflicting bounds are
provided.

Min/max and standard deviation bounds do not conflict. Also, the
inequality and error bounds can be used in conjunction, as in

    Real x = 4 bounded { plusminus 1, always >= 3.5 };

which would be translated to

    Real x_min = max(4 - 1,3.5), x_max = max(4 + 1,3.5);

===================
Semantic extensions
===================

The extension also generates bounds on variables without any explicit
uncertainty bounds set, in order to propagate any explicit
uncertainties through a model. For example,

    Real x = y + z;

would be translated to

    Real x_min = y_min + z_min, x_max = y_max + z_max;

=====
Usage
=====

% java -jar modelica.jar [--minmax] [--stddev] [Modelica files]

The '--minmax' switch activates the production of min/max bounds, the
'--stddev' switch likewise for standard deviation bounds.

If a file has the extension '.mo.fused', its host-language translation
is output to a file with the same name but the extension '.mo'.
Otherwise, the file is checked for syntactic and semantic errors, but
no output is produced.
