<a id="reference-entities-label"></a>

# Entity

An *entity* is a specification object that structures the specification.
In a document interpretation, entities are analogous to sections and subsections.
In a model interpretation, entities are model elements that either constrain or define the SOI or its environment.

## Structure

A .req specification starts with a [Package](#reference-package-label), which is called the *root* and is the parent of all other entities in the specification.
The specification forms a tree from the root down to leaf entities.

#### NOTE
It is common to place the constraint section — [Package](#reference-package-label) and [Requirement](#reference-requirement-label) — and the definition section — [Part](#reference-part-label), [Attribute](#reference-attribute-label) and [Type](#reference-type-label) — as direct children of the root.

#### ATTENTION
Multi-file specifications are not yet supported. All entities referenced in a specification must be defined in the same source file.

## Identification

### Identifier

Each entity has an *identifier* that can only be composed of:

* letters
* digits
* the underscore symbol `_`

An identifier cannot start with a digit.

#### NOTE
Naming conventions are introduced for each entity type in the sections below.

### Path

A *path* is the concatenation of identifiers separated by `::`, e.g. `Specification::System::Wheel`.
Each entity has an *absolute path* that lists each identifier from the root to the entity itself.

#### NOTE
Each entity is uniquely identified by its path. Two entities cannot share the same path.

<a id="reference-reference-label"></a>

### Reference

A *reference* is a mention of a path present in the specification.

#### NOTE
References are commonly used in [Markup](markup.md#reference-markup-label) and [Expression](expression.md#reference-expression-label).

The *scope* is the set of all entities that can be referenced. Each entity in scope is identified by a unique path — no duplication is allowed.

When resolving a reference, the following rules are evaluated in order:

1. The reference matches an identifier of a direct child of the parent entity
2. The reference is a full path from root to entity
3. The reference is the suffix of an imported path

### Imports

A [Package](#reference-package-label) or [Part](#reference-part-label) may have *imports* that allow references to be shortened.
Adding an import brings a *prefix* into scope that is merged with references at resolution time — see [Reference](#reference-reference-label).

**Syntax**

```none
import PATH
```

Imports are written right after the identifier of the package or part.

## Meta-information

Each entity is provided with *meta-information* that is meant to provide additional context on the entity.

### Comment

A *comment* is additional information about a given entity. Any entity can be provided with a comment; the comment may be interpreted differently depending on the kind of entity.

**Example of comment**

```req
package Display
  part Screen
  part

  @@
  # Rationale

  After the client meeting, this format fits the desired application best.
  @@
  requirement Significant_digits top bottom
    on Screen
  is
    @@
      The [[Screen]] shall use decimal format with 2 significant digits.
    @@
  requirement
package
```

The comment is written using the [Markup](markup.md#reference-markup-label) syntax.

#### NOTE
A common practice is to always provide [Part](#reference-part-label) and [Attribute](#reference-attribute-label) with a comment that acts as a definition. [Requirement](#reference-requirement-label) comments can be used as rationale.

### Tags

A *tag* is meta-information about a given entity, organized as a key-value pair. Any entity can be provided with tags and the value is optional.
Tags are useful to specify additional information about an entity:

**Syntax**

```none
# KEY VALUE? #
```

**Example of tag**

```req
package Quality
  part System
  part

  # verification proof #
  # priority high #
  requirement Perfection top bottom
    on System
  is
    @@
      The [[System]] shall be perfect.
    @@
  requirement
package
```

#### NOTE
Tags can be used to represent project, domain or management specific data such as change-requests, validation-method, priority, …

<a id="reference-requirement-label"></a>

## Requirement

A *requirement* is an expectation or an assumption about the SOI or its environment.
An implementation satisfies a specification if and only if all requirements are met in the assumed environment.

**Syntax**

```none
requirement IDENTIFIER
 <top | bottom | on PATH | via PATH | refines PATH | derives PATH | specializes PATH>*
is
 <MARKUP|EXPRESSION>
requirement
```

The clauses between the identifier and `is` can be written in any order.

Requirements can either be *formal* by using a Boolean [Expression](expression.md#reference-expression-label),
or *informal* by using the [Markup](markup.md#reference-markup-label) syntax. In the example below, `Comfort` is informal and
`Maximum_temperature` is formal:

**An informal requirement and a formal requirement that refines it**

```req
package Building
  part Room
    let temperature in real \ C \
  part

  requirement Comfort top
    on Room
  is
    @@
      The [[Room]] shall stay comfortable for its occupants.
    @@
  requirement

  requirement Maximum_temperature bottom
    on Room::temperature
    refines Comfort
  is
    Room::temperature < 30
  requirement
package
```

<a id="reference-requirement-constraint-label"></a>

### Constraint

Each requirement *constrains* either a [Part](#reference-part-label) or an [Attribute](#reference-attribute-label), named after `on`,
and uses it: with a `[[...]]` reference in its text, or an identifier in its expression.

<a id="reference-requirement-traceability-label"></a>

### Traceability

*Traceability* is a directed link between requirements. Unlike free-form trace links, each traceability keyword in req carries a defined semantic that constrains how requirements may be related:

1. *Refinement* (`refines`) — the child requirement adds detail or stronger conditions to what the parent requires. The parent’s intent still holds; the child narrows it. The child constrains the entity of the parent, or an entity nested inside it.
2. *Specialization* (`specializes`) — the child requirement applies to a specific subset of situations covered by the parent. The situations are meant to be selected via configuration management. Both requirements constrain the same entity.
3. *Derivation* (`derives`) — the child requirement was produced from the parent through a design or allocation decision. No constraint compatibility is implied; the constrained entities may differ. A derived requirement expects its parent to be allocated, see [Allocation](#reference-requirement-allocation-label).

<a id="reference-requirement-inhibitor-label"></a>

### Inhibitors

A requirement is expected to take part in the hierarchy of requirements: to have a *parent*, a requirement above it, and *children*, requirements below it.
The hierarchy is made of `refines` and `derives` links, `specializes` links are not part of it, see [Traceability](#reference-requirement-traceability-label).

The *inhibitors* `top` and `bottom` state that one of these expectations does not apply:

* `top` — the requirement has no parent. It does not refine nor derive another requirement.
* `bottom` — the requirement has no children. No requirement refines or derives it, and it is not allocated, since an allocation is meant to be derived, see [Allocation](#reference-requirement-allocation-label).

A requirement that is both `top` and `bottom` stands alone.

**A requirement that stands alone, and a parent with its child**

```req
package Vehicle
  part Wheel
    let speed in real \ m/s \
  part

  requirement Wheel_size top bottom
    on Wheel
  is
    @@
      The [[Wheel]] shall be below 30 cm.
    @@
  requirement

  requirement Wheel_stop top
    on Wheel
  is
    @@
      The [[Wheel]] shall stop.
    @@
  requirement

  requirement Speed_bound bottom
    on Wheel::speed
    refines Wheel_stop
  is
    Wheel::speed < 3
  requirement
package
```

<a id="reference-requirement-allocation-label"></a>

### Allocation

An *allocation* (`via`) names the part or attribute that is intended to derive a requirement, typically the sub-system to which a system delegates a function, as a client would to a contractor.
It is declared on the delegated requirement, not on the requirements that answer it.
An allocated requirement is expected to be answered by requirements that derive it and constrain the allocated entity:

* at least one requirement derives it, and every requirement deriving it constrains the allocated entity;
* it is not `bottom`, since it is meant to be derived;
* the allocated entity differs from the entity it constrains.

**A requirement allocated to a sub-system, and the requirement that derives it**

```req
package Kitchen
  part Kettle
  part
  part Mains
    let max_power in real \ W \
  part

  requirement Boil_fast top
    on Kettle
    via Mains
  is
    @@
      The [[Kettle]] shall boil one liter of water in less than 3 minutes.
    @@
  requirement

  requirement Power_supply
    on Mains
    derives Boil_fast
  is
    @@
      The [[Mains]] shall supply the power the [[Kettle]] needs to boil one liter of water.
    @@
  requirement

  requirement Supply_limit bottom
    on Mains::max_power
    refines Power_supply
  is
    Mains::max_power >= 2000
  requirement
package
```

<a id="reference-package-label"></a>

## Package

A *package* is a container element that provides a namespace for requirements. Packages can be nested to provide a hierarchy between concern areas.

**Syntax**

```none
package IDENTIFIER
 IMPORT*
 <PACKAGE|PART|TYPE|REQUIREMENT>*
package
```

Packages are used to provide a *thematic breakdown* of requirements.

**Example of a package**

```req
package Room_Control
  part Room
    let temperature in real \ C \
    let humidity in real \ % \
  part

  requirement Comfort top
    on Room
  is
    @@
      The [[Room]] shall stay comfortable for its occupants.
    @@
  requirement

  package Temperature_Control
    import Room_Control
    requirement Maximum_temperature bottom
      on Room::temperature
      refines Comfort
    is
      Room::temperature < 26
    requirement
  package

  package Humidity_Control
    import Room_Control
    requirement Maximum_humidity bottom
      on Room::humidity
      refines Comfort
    is
      Room::humidity < 60
    requirement
  package
package
```

The import lets the nested packages write `Room::temperature` instead of `Room_Control::Room::temperature`.

A [Requirement](#reference-requirement-label) belongs to one and only one package. Packages form a requirements partitioning of the system:

* **Function**, activity or operational breakdown of requirements
* **Non-functional** requirements, included either as function sub-packages or a separate package
* **Level of detail**: business, system, equipment, …

#### NOTE
A package can contain [Part](#reference-part-label), common use case is the root package that contain a root part.

<a id="reference-attribute-label"></a>

## Attribute

An *attribute* is a named quantity of the specification that can be assigned a value.

**Syntax**

```none
let IDENTIFIER in DOMAIN (\ UNIT \)?
```

Every attribute has a domain.

An attribute can represent several aspects of a system:

* A **state variable** of the specification that can evolve over time
* A **constant parameter** or external input
* An **event** relevant to the specification

**Example of a set of attributes**

```req
part Airplane
   let current_speed in real \ m/s \
   let wingspan in real \ m \
   let has_landed in boolean
 part
```

An attribute has semantic *type*, inferred by the compiler from its domain and the expressions in which it appears. The type determines which operations are applicable to the attribute.

### Domain

A *domain*, is the mathematical set of the allowed values of an attribute. It is defined first via an expression having the type `Set` in the attribute definition,
such as `real`, `[0, 1]` or an enumeration [type](#reference-type-label).

Formal requirements (see [Requirement](#reference-requirement-label)) constrain attributes. All constraints on an attribute must be *satisfiable* for the specification to be consistent.
More precisely, each constraint narrows the domain of the attribute; if the domain becomes empty the specification is unsatisfiable.

#### NOTE
As the number of constraints on an attribute grows, their intersection narrows. An empty intersection means the constraints are contradictory and the specification is unsatisfiable.

### Unit

A physical *unit* can be provided to numerical attributes

#### ATTENTION
For now, units are freeform labels and are not validated by the compiler.

<a id="reference-part-label"></a>

## Part

A *part* is a container element that provides a namespace for attributes and nested parts.
Parts can be nested to represent a physical or conceptual decomposition of the SOI
and its environment. This hierarchical structure is called an ontology.

**Syntax**

```none
part IDENTIFIER
 IMPORT*
 <ATTRIBUTE|PART|TYPE>*
part
```

Parts are typically used to partition a system in the following ways:

* **Physical decomposition** — the system is broken down into sub-systems or sub-equipment.
* **Conceptual decomposition** — B is a functional or logical aspect of A, without implying physical separation.

**Example of a part**

```req
part Airplane
  let current_speed in real \ m/s \
  let has_overspeed in boolean
  part Wings
    let wingspan in real \ m \
  part
part
```

Unlike [Package](#reference-package-label), it is common to use a part with no children to
introduce a *concept* relevant to the specification. A part, even with no children, allows for a concept to be named and referenced in requirements before
its attributes are defined.

Informal requirements (see [Requirement](#reference-requirement-label)) on parts serve as high-level
constraints that can be progressively formalized as the specification matures.

#### NOTE
In a more general sense, a part represents an *aspect* of the system under
consideration — either a grouping of physical characteristics (geometry, mass, speed)
or functional characteristics (behavior, capability, mode).

<a id="reference-type-label"></a>

## Type

A *type* defines an enumeration: a finite set of named values, its *members*.

**Syntax**

```none
type IDENTIFIER has MEMBER (| MEMBER)* type
```

A type is used as the domain of an [attribute](#reference-attribute-label). In an expression, a member is
written with the path of its type, `Door_state::closed`. A reference to a member, `[[Door_state::closed]]`,
points to its type.

**Example of a type**

```req
package Doors
  type Door_state has closed | opening | open | closing type

  part Door
    let state in Doors::Door_state
  part

  requirement Door_cycle top
    on Door
  is
    @@
      The [[Door]] shall be closed when the train departs.
    @@
  requirement

  requirement Initially_closed bottom
    on Door::state
    refines Door_cycle
  is
    Door::state °= Door_state::closed
  requirement
package
```
