Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "four-line" proposal for units of literals #3266

Open
wants to merge 24 commits into
base: MCP/0027
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7524b11
Initial commit of ReadMe.md for MCP-0027
henrikt-ma Oct 4, 2022
a762fc7
Added "four-line" proposal for units of literals
casella Oct 25, 2022
bdbea3b
Reformatted to use sentence-based line breaks. Added inline codes for…
casella Oct 26, 2022
eb116d7
Wrote out LHS and RHS
casella Oct 26, 2022
b676ad9
Outputs of transcendental functions should be dimensionless
casella Oct 26, 2022
11dc52d
Fixed type
casella Oct 27, 2022
9a1deda
Updated proposal
casella Oct 28, 2022
df6242b
Update chapters/lexicalstructure.tex
casella Nov 2, 2022
5d5f466
Update chapters/lexicalstructure.tex
casella Nov 2, 2022
398c013
Update chapters/lexicalstructure.tex
casella Nov 9, 2022
7a9f340
Update chapters/lexicalstructure.tex
casella Nov 9, 2022
77eaae7
Update chapters/lexicalstructure.tex
casella Nov 9, 2022
8916f6e
Update chapters/lexicalstructure.tex
casella Nov 9, 2022
2c817dd
Update chapters/lexicalstructure.tex
casella Nov 9, 2022
942776f
Update chapters/lexicalstructure.tex
casella Nov 9, 2022
b3e0dc1
Update chapters/lexicalstructure.tex
casella Nov 9, 2022
3370313
Update lexicalstructure.tex
casella Nov 10, 2022
7539f1b
Update lexicalstructure.tex
casella Nov 10, 2022
15bb554
Update chapters/lexicalstructure.tex
HansOlsson Nov 11, 2022
26bce83
Update chapters/lexicalstructure.tex
HansOlsson Nov 11, 2022
ba23447
Update chapters/lexicalstructure.tex
HansOlsson Nov 11, 2022
4a7c941
Update chapters/lexicalstructure.tex
HansOlsson Nov 11, 2022
0f5c46a
Update lexicalstructure.tex
casella Nov 15, 2022
e325f6f
Used LaTeX instead of rST for itemized list
casella Nov 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions RationaleMCP/0027/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Modelica Change Proposal MCP-0027<br/>Units of Literal Constants
Francesco Casella, Henrik Tidefelt

**(In Development)**

## Summary
The purpose of this MCP is to allow more unit errors to be detected by giving more expressions the unit `"1"` instead of having an undefined unit.
The problem with undefined unit is that it gets in the way of carrying out checking of units (which tools tend to deal with by not checking units at all where this happens).

## Revisions
| Date | Description |
| --- | --- |
| 2022-10-04 | Henrik Tidefelt. Filling this document with initial content. |

## Contributor License Agreement
All authors of this MCP or their organizations have signed the "Modelica Contributor License Agreement".

## Rationale
FIXME

## Backwards Compatibility
As current Modelica doesn't clearly reject some models with non-sensical combination of units, this MCP will break backwards compatibility by turning at least some of these invalid.

## Tool Implementation
None, so far.

### Experience with Prototype
N/A

## Required Patents
To the best of our knowledge, there are no patents that would conflict with the incorporation of this MCP.

## References
(None.)
18 changes: 18 additions & 0 deletions chapters/lexicalstructure.tex
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,24 @@ \subsection{Strings}\label{strings}
\end{lstlisting}
\end{nonnormative}

\subsection{Units of Literal Constants}\label{units-literal-constants}

Literal \lstinline!Real! and \lstinline!Integer! constants are implicitly assumed to have \lstinline!unit = "1"! if they appear in expressions containing variables, parameters, or constants that have a non-empty \lstinline!unit! attribute string.
casella marked this conversation as resolved.
Show resolved Hide resolved
casella marked this conversation as resolved.
Show resolved Hide resolved

The inputs of transcendental built-in functions such as \lstinline!sin()!, \lstinline!cos()!, \lstinline!exp()!, etc., should have a dimensionless unit (e.g., \lstinline!"1"| or \lstinline!"rad"!) if they involve expressions containing variables, parameters, or constants that have a non-empty unit attribute string.
casella marked this conversation as resolved.
Show resolved Hide resolved
Their outputs are implicitly assumed to have unit \lstinline!"1"! if they are called within expressions containing variables, parameters, or constants that have a non-empty \lstinline!unit! attribute string.
casella marked this conversation as resolved.
Show resolved Hide resolved

\begin{nonnormative}
Rationale: unit attributes allow to check dimensional consistency of expressions and equations, as long as all the involved terms have a non-empty \lstinline!unit! attribute.
casella marked this conversation as resolved.
Show resolved Hide resolved
Non-dimensional literal factors, e.g., \lstinline!2! in \lstinline!v = sqrt(2*g*h)! in physical laws involving quantities with units are always meant to be dimensionless, so they should be considered as such by giving them \lstinline!unit = "1"!.
casella marked this conversation as resolved.
Show resolved Hide resolved
This allows to find out that, e.g., \lstinline!v = sqrt(2*h)! is dimensionally inconsistent (hence most likely wrong), because it has unit \lstinline!"m/s"! on the LHS and unit \lstinline!"m0.5"! on the RHS, which are not consistent.
Without this rule, \lstinline!2! would have the default \lstinline!unit = ""! of \lstinline!Real!, making it impossible to determine the RHS unit.

On the other hand, literal constants showing up in expressions containing only literal constants should be left with the default \lstinline!unit = ""! attribute, otherwise declarations such as \lstinline!Real L(unit = "m") = 2.0!, equations such as \lstinline!L = 2.0! and function calls such as \lstinline!temperature_ph(1e5, 293.15)! or \lstinline!temperature_ph(1e5, 273.15 + 20)! would be erroneously flagged as dimensionally inconsistent.
casella marked this conversation as resolved.
Show resolved Hide resolved

The rules involving built-in transcendental functions extend the scope of this concept to also allow determining that equations such as \lstinline!i = i0*exp(v/i0)! or \lstinline!i = v0*exp(i/i0)! are dimensionally inconsistent.
casella marked this conversation as resolved.
Show resolved Hide resolved
casella marked this conversation as resolved.
Show resolved Hide resolved
\end{nonnormative}

\section{Operator Symbols}\label{operator-symbols}

The predefined operator symbols are formally defined on page \pageref{lexical-conventions} and
Expand Down