//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2010, 2026 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available
// under the terms of the MIT License which is available at
// https://opensource.org/licenses/MIT
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////

include::../_part_attributes.asciidoc[]

:leveloffset: -2

[[tools-cif2cif-chapter-add-default-init-values]]
== Add default initial values

indexterm:[CIF to CIF transformer,add default initial values]
indexterm:[add default initial values]
This CIF to CIF transformation adds the default initial values to variables that are not given an explicit initial value.
This includes discrete and continuous variables, as well as local variables of functions.

indexterm:[add default initial values,supported specifications]

=== Supported specifications

This transformation supports a subset of CIF specifications.
The following restrictions apply:

* Component definitions and component instantiations are not supported.

indexterm:[add default initial values,preprocessing]

=== Preprocessing

No preprocessing is currently performed by this CIF to CIF transformation.
To increase the subset of specifications that can be transformed, apply the following <<tools-cif2cif-chapter-index,CIF to CIF transformations>> (in the given order):

* <<tools-cif2cif-chapter-elim-comp-def-inst>>

indexterm:[add default initial values,implementation]

=== Implementation details

The default values for all types are simple values.
The only exception are function types, for which a new function is introduced.
This new functions returns the default value for the return type of the function.
If multiple default values for the same function type are needed, the newly introduced function is reused.
The functions are named `+_f+`, `+_f2+`, `+_f3+`, etc.

For instance, the following specification:

[source, cif]
----
automaton x:
  disc int x, y = 5;
  disc func bool (int) f;
  location;
end
----

is transformed to the following specification:

[source, cif]
----
func bool _f(int p0):
  return false;
end

automaton x:
  disc int x = 0, y = 5;
  disc func bool (int) f = _f;
  location;
end
----

indexterm:[add default initial values,renaming]

=== Renaming

If the names of the functions that are introduced, conflict with already existing declarations, they are renamed.
For instance, if `+_f2+` is already in use, `+_f22+`, `+_f23+`, etc, are used instead.
If renaming takes place, a warning is printed to the console.

indexterm:[add default initial values,size considerations]

=== Size considerations

Since values are added, this transformation increases the size of the specification.
For an array of 400 elements, with an array of 300 integers each, the default initial value consists of 120,000 integers.
Adding such an initial value can significantly increase the size of the model.

indexterm:[add default initial values,optimality]

=== Optimality

The default values for all types are as primitive as they can be, and can usually not be simplified any further.
It may however be possible that functions are introduced for the default values of function types, while such a function already existed in the original specification.

=== Annotations

This transformation does not process, add, or remove any annotations.
