- Types
- Operators
- PrimitiveFunctions
- Option
- StreamFunctions
- List
- Set
- Map
- String
- MITL
- LTL
- InstrumentationAnnotations
- Tessla
- CTF

Fundamental types and primitive constants

`Bool`

A Boolean can be either `true`

or `false`

`Int`

Integer. The maximal and minimal values depend on the TeSSLa engine. The TeSSLa software backend uses BigInt, i.e. every integer can be represented

`Float`

Float. The data range depends on the TeSSLa engine. The TeSSLa software backend uses a 64-bit IEEE-754 floating point number

`String`

String can store arbitrary long character sequences

`Unit`

`()`

is the only value of type `Unit`

, i.e. this type can be used to represent events without values.

`Events[T]`

Basic type for streams

`@liftable`

Functions annotated with this annotation can be used on streams which will be equivalent to wrapping their call with `slift`

.

`true: Bool`

A Boolean value representing that a given proposition is true

`false: Bool`

A Boolean value representing that a given proposition is false

For every function defined in the operator module there exists a special operator syntax which can be used to call the function using an infix operator.

`@liftable`

not(arg: Bool): Bool

**Operator usage:** `!x`

Boolean complement

`@liftable`

ite[T](cond: Bool, thenCase: T, elseCase: T): T

**Operator usage:** `if c then a else b`

If-Then-Else

`@liftable`

and(lhs: Bool, rhs: Bool): Bool

**Operator usage:** `a && b`

Boolean conjunction

`@liftable`

or(lhs: Bool, rhs: Bool): Bool

**Operator usage:** `a || b`

Boolean disjunction

`@liftable`

eq[T](lhs: T, rhs: T): Bool

**Operator usage:** `a == b`

Equivalence on arbitrary data types. On complex data structures this operator checks the object's identity. Note, that this operator is defined as `@liftable`

, so it does neither check the equivalence nor the identity of streams, but applies the operator on two streams using the signal semantics.

`@liftable`

neq[T](lhs: T, rhs: T): Bool

**Operator usage:** `a != b`

Non-Equivalence on arbitrary data types. On complex data structures this operator checks the object's identity. Note, that this operator is defined as `@liftable`

, so it does neither check the equivalence nor the identity of streams, but applies the operator on two streams using the signal semantics.

`@liftable`

gt(lhs: Int, rhs: Int): Bool

**Operator usage:** `a > b`

Returns `true`

if `a`

is strictly greater than `b`

`@liftable`

lt(lhs: Int, rhs: Int): Bool

**Operator usage:** `a < b`

Returns `true`

if `a`

is strictly lower than `b`

`@liftable`

geq(lhs: Int, rhs: Int): Bool

**Operator usage:** `a >= b`

Returns `true`

if `a`

is greater than or equal to `b`

`@liftable`

leq(lhs: Int, rhs: Int): Bool

**Operator usage:** `a <= b`

Returns `true`

if `a`

is lower than or equal to `b`

`@liftable`

fgt(lhs: Float, rhs: Float): Bool

**Operator usage:** `a >. b`

Returns `true`

if `a`

is strictly greater than `b`

`@liftable`

flt(lhs: Float, rhs: Float): Bool

**Operator usage:** `a <. b`

Returns `true`

if `a`

is strictly lower than `b`

`@liftable`

fgeq(lhs: Float, rhs: Float): Bool

**Operator usage:** `a >=. b`

Returns `true`

if `a`

is greater than or equal to `b`

`@liftable`

fleq(lhs: Float, rhs: Float): Bool

**Operator usage:** `a <=. b`

Returns `true`

if `a`

is lower than or equal to `b`

`@liftable`

add(lhs: Int, rhs: Int): Int

**Operator usage:** `a + b`

Returns the sum of two integers

`@liftable`

sub(lhs: Int, rhs: Int): Int

**Operator usage:** `a - b`

Returns the difference of two integers

`@liftable`

mul(lhs: Int, rhs: Int): Int

**Operator usage:** `a * b`

Returns the multiplication of two integers

`@liftable`

div(lhs: Int, rhs: Int): Int

**Operator usage:** `a / b`

Returns the division of two integers

`@liftable`

mod(lhs: Int, rhs: Int): Int

**Operator usage:** `a % b`

Returns the remainder of two integers

`@liftable`

negate(arg: Int): Int

**Operator usage:** `-a`

Unary minus on integers

`@liftable`

bitand(lhs: Int, rhs: Int): Int

**Operator usage:** `a & b`

Bitwise AND on integers

`@liftable`

bitor(lhs: Int, rhs: Int): Int

**Operator usage:** `a | b`

Bitwise OR on integers

`@liftable`

bitxor(lhs: Int, rhs: Int): Int

**Operator usage:** `a ^ b`

Bitwise XOR on integers

`@liftable`

bitflip(arg: Int): Int

**Operator usage:** `~a`

Bitflip on integers

`@liftable`

leftshift(lhs: Int, rhs: Int): Int

**Operator usage:** `a << b`

Arithmetic left shift on integers

`@liftable`

rightshift(lhs: Int, rhs: Int): Int

**Operator usage:** `a >> b`

Arithmetic right shift on integers

`@liftable`

fadd(lhs: Float, rhs: Float): Float

**Operator usage:** `a +. b`

Returns the sum of two floats

`@liftable`

fsub(lhs: Float, rhs: Float): Float

**Operator usage:** `a -. b`

Returns the difference of two floats

`@liftable`

fmul(lhs: Float, rhs: Float): Float

**Operator usage:** `a *. b`

Returns the multiplication of two floats

`@liftable`

fdiv(lhs: Float, rhs: Float): Float

**Operator usage:** `a /. b`

Returns the division of two floats

`@liftable`

fnegate(arg: Float): Float

**Operator usage:** `-.a`

Unary minus on floats

Functions for primitive types

`@liftable`

max(a: Int, b: Int): Int

Compute the maximum of two integer values.

`@liftable`

min(a: Int, b: Int): Int

Compute the minimum of two integer values.

`@liftable`

toString[T](arg: T): String

Converts any type into its typical string representation

`@liftable`

pow(base: Float, exponent: Float): Float

Returns the value of the first argument raised to the power of the second argument.

`@liftable`

log(x: Float, base: Float): Float

Returns the logarithm to base `base`

of `x`

`@liftable`

sin(x: Float): Float

Returns the trigonometric sine of an angle `x`

in radians. Special cases:

- If the argument is NaN or an infinity, then the result is NaN.
- If the argument is zero, then the result is a zero with the same sign as the argument.

`@liftable`

cos(x: Float): Float

Returns the trigonometric cosine of an angle in radians. Special cases:

- If the argument is NaN or an infinity, then the result is NaN.

`@liftable`

tan(x: Float): Float

Returns the trigonometric tangent of an angle in radians. Special cases:

- If the argument is NaN or an infinity, then the result is NaN.
- If the argument is zero, then the result is a zero with the same sign as the argument.

`@liftable`

atan(x: Float): Float

Returns the arc tangent of a value; the returned angle is in the range *-π/2* through *π/2*. Special cases:

- If the argument is NaN, then the result is NaN.
- If the argument is zero, then the result is a zero with the same sign as the argument.

`@liftable`

intToFloat(x: Int): Float

Converts the given integer to a float.

`@liftable`

floatToInt(x: Float): Int

Converts the given float to an integer without

Optional values

`map[T, U](opt: Option[T], f: ((T) => U): Option[U]`

`flatMap[T, U](opt: Option[T], f: ((T) => Option[U]): Option[U]`

`map2[T, U, V](opt1: Option[T], opt2: Option[U], f: ((T, U) => V)`

`@liftable`

toSet[T](option: Option[T]): Set[T]

`Option[T]`

Represents optional values. Instances of `Option`

are either an instance of `Some`

or `None`

`None[T]: Option[T]`

Represents non-existent values of type `T`

`@liftable`

Some[T](value: T): Option[T]

Represents existing values of type `T`

`@liftable`

isNone[T](opt: Option[T]): Bool

Returns `true`

if the given option is a `None`

or `false`

if it is a `Some`

`@liftable`

isSome[T](opt: Option[T]): Bool

Returns `true`

if the given option is a `Some`

or `false`

if it is a `None`

`@liftable`

getSome[T](opt: Option[T]): T

Get the value contained in a `Some`

. If the given option is a `None`

, a run-time error will occur

`@liftable`

getSomeOrElse[T](opt: Option[T], value: T): T

Get the value contained in a `Some`

. If the given option is a `None`

, the default value `value`

will be returned

Built-in stream functions

`nil[T]: Events[T]`

Returns an empty stream without any event of type `T`

`default[T](stream: Events[T], value: T): Events[T]`

Returns a stream which contains all the events of the given `stream`

. If `stream`

has no event at timestamp 0, then an additional event with value `value`

is added at timestamp 0.

**Usage example:**

```
in a: Events[Int]
def d = default(a, 42)
out d
```

**Trace example:**

```
option timeDomain: [-0.1,6]
stream a: bubbles
stream d: bubbles
---
0: d = 42
2: a = 17
2: d = 17
5: a = 23
5: d = 23
```

**Alternative trace example:**

```
option timeDomain: [-0.1,6]
stream a: bubbles
stream d: bubbles
---
0: a = 12
0: d = 12
2: a = 17
2: d = 17
5: a = 23
5: d = 23
```

`defaultFrom[T](valueStream: Events[T], defaultStream: Events[T]): Events[T]`

Similar to `default`

, this operation returns a stream which contains all the events of the given `valueStream`

. If the first event on `defaultStream`

happens strictly before the first event on `valueStream`

then this event is added. No events other than the first event on `defaultStream`

are considered.

**Usage example:**

```
in v: Events[Int]
in x: Events[Int]
def d = defaultFrom(v, x)
out d
```

**Trace example:**

```
stream v: bubbles
stream x: bubbles
stream d: bubbles
---
2: x = 5
2: d = 5
3: x = 3
3: d = 2
3: v = 2
5: x = 7
6: d = 4
6: v = 4
```

**Alternative trace example:**

```
stream v: bubbles
stream x: bubbles
stream d: bubbles
---
1: d = 6
1: v = 6
2: x = 5
3: x = 3
3: d = 2
3: v = 2
5: x = 7
6: d = 4
6: v = 4
```

`lift1[T, U](stream: Events[T], f: ((Option[T]) => Option[U]): Events[U]`

Lifts a unary function `f`

which is defined on values to a function on a stream and applies it to the given stream. The function `f`

is called for every event on the streams. Because there is no other stream, the argument of `f`

will never be `None`

. (`f`

is never called with all arguments being `None`

.)

**Usage example:**

```
in a: Events[Int]
def f(a: Option[Int]) =
if getSome(a) > 5 then a else None[Int]
def b = lift1(a,f)
out b
```

**Trace example:**

```
stream a: bubbles
stream b: bubbles
---
1: b = 7
1: a = 7
2: a = 5
4: a = 3
5: b = 9
5: a = 9
```

`lift2[T, U, V](stream1: Events[T], stream2: Events[U], f: ((Option[T], Option[U]) => Option[V]): Events[V]`

Lifts a function `f`

which is defined on values to a function on streams and applies it to the given streams. The function `f`

is called for every event on any of the streams. If there is a simultaneous event on the other stream, then the values of both events are passed to `f`

. Otherwise the other argument is `None`

if there is no simultaneous event on the other stream. `f`

is never called with all arguments being `None`

.

**Usage example:**

```
in a: Events[Int]
in b: Events[Int]
def f(a: Option[Int], b: Option[Int]) =
if isSome(a) && getSome(a) > 5 then a else b
def c = lift(a,b,f)
out c
```

**Trace example:**

```
stream a: bubbles
stream b: bubbles
stream c: bubbles
---
1: c = 7
1: a = 7
2: a = 5
3: b = 6
3: c = 6
4: b = 2
4: c = 2
4: a = 3
5: b = 4
5: c = 9
5: a = 9
```

`lift`

`lift3[T1, T2, T3, T4](stream1: Events[T1], stream2: Events[T2], stream3: Events[T3], f: ((Option[T1], Option[T2], Option[T3]) => Option[T4]): Events[T4]`

Lifts a function `f`

which is defined on values to a function on streams and applies it to the given streams. The function `f`

is called for every event on any of the streams. If there is a simultaneous event on the other stream, then the values of both events are passed to `f`

. Otherwise the other argument is `None`

if there is no simultaneous event on the other stream. `f`

is never called with all arguments being `None`

.

**Usage example:**

```
in a: Events[Int]
in b: Events[Int]
in c: Events[Int]
def f(a: Option[Int], b: Option[Int], c: Option[Int]) =
if isSome(a) && getSome(a) > 5 then a
else if isSome(b) then b else c
def d = lift3(a,b,c,f)
out d
```

**Trace example:**

```
stream a: bubbles
stream b: bubbles
stream c: bubbles
stream d: bubbles
---
1: d = 7
1: a = 7
2: a = 5
3: b = 6
3: d = 6
4: b = 2
4: d = 2
4: a = 3
5: c = 1
5: d = 1
6: b = 4
6: c = 3
6: d = 9
6: a = 9
```

`lift4[T1, T2, T3, T4, T5](stream1: Events[T1], stream2: Events[T2], stream3: Events[T3], stream4: Events[T4], f: ((Option[T1], Option[T2], Option[T3], Option[T4]) => Option[T5]): Events[T5]`

Lifts a function `f`

which is defined on values to a function on streams and applies it to the given streams. The function `f`

is called for every event on any of the streams. If there is a simultaneous event on the other stream, then the values of both events are passed to `f`

. Otherwise the other argument is `None`

if there is no simultaneous event on the other stream. `f`

is never called with all arguments being `None`

.

**Usage example:**

```
in a: Events[Int]
in b: Events[Int]
in c: Events[Int]
in d: Events[Int]
def f(a: Option[Int], b: Option[Int], c: Option[Int], d: Option[Int]) =
if isSome(a) && getSome(a) > 5 then a
else if isSome(b) then b
else if isSome(c) then c
else d
def e = lift4(a,b,c,d,f)
out e
```

**Trace example:**

```
stream a: bubbles
stream b: bubbles
stream c: bubbles
stream d: bubbles
stream e: bubbles
---
1: a = 7
1: e = 7
2: a = 5
3: b = 6
3: e = 6
4: b = 2
4: a = 3
4: e = 2
5: e = 1
5: c = 1
6: d = 2
6: e = 2
7: b = 4
7: a = 9
7: d = 2
7: e = 9
7: c = 3
```

`lift5[T1, T2, T3, T4, T5, U](stream1: Events[T1], stream2: Events[T2], stream3: Events[T3], stream4: Events[T4], stream5: Events[T5], f: ((Option[T1], Option[T2], Option[T3], Option[T4], Option[T5]) => Option[U]): Events[U]`

`f`

which is defined on values to a function on streams and applies it to the given streams. The function `f`

is called for every event on any of the streams. If there is a simultaneous event on the other stream, then the values of both events are passed to `f`

. Otherwise the other argument is `None`

if there is no simultaneous event on the other stream. `f`

is never called with all arguments being `None`

.

See `lift4`

for a usage example. ~~~

`last[T, U](stream: Events[T], trigger: Events[U]): Events[T]`

The last operator takes two streams and returns the previous value of the first stream at the timestamps of the second. Note that while TeSSLa is defined on event streams, last realizes some essential aspects of the signal semantics: With this operator one can query the last known value of an event stream at a specific time and hence interpret the events on this stream as points where a piece-wise constant signal changes its value.

**Usage example:**

```
in values: Events[Int]
in trigger: Events[Unit]
def result = last(x,y)
out result
```

**Trace example:**

```
stream values: bubbles
stream trigger: unit events
stream result: bubbles
---
1: trigger = ()
2: values = 5
3: result = 5
3: trigger = ()
4: result = 5
4: trigger = ()
4: values = 3
5: result = 3
5: trigger = ()
```

`prev[A](a: Events[A]): Events[A]`

Return the previous event of `a`

. Does not work in recursive equations. Use `last`

with an explicit external trigger in recursive equations instead.

**Usage example:**

```
in x: Events[Int]
def y = prev(x)
out y
```

**Trace example:**

```
option axis: true
stream x: bubbles
stream y: bubbles
---
1: x = 3
3: y = 3
3: x = 2
7: y = 2
7: x = 1
8: y = 1
8: x = 5
```

`time[T](stream: Events[T]): Events[Int]`

The time operator returns the stream of the timestamps of another stream

**Usage example:**

```
in x: Events[Int]
def y = time(x)
out result
```

**Trace example:**

```
option axis: true
option timeDomain: [0,14]
stream x: bubbles
stream y: bubbles
---
2: x = 5
2: y = 2
4: x = 3
4: y = 4
10: x = 42
10: y = 10
```

`delay[T](delays: Events[Int], resets: Events[T]): Events[Unit]`

The delay operator takes delays as its first argument. After a delay has passed, a unit event is emitted. A delay can only be set if a reset event is received via the second argument, or if an event is emitted on the output.

**Usage example:**

```
in values: Events[Int]
in resets: Events[Int]
def result = delay(values, resets)
out result
```

**Trace example:**

```
option axis: true
stream values: bubbles
stream resets: unit events
stream result: unit events
---
1: resets = ()
1: values = 2
3: result = ()
4: resets = ()
4: values = 3
7: result = ()
7: values = 2
9: result = ()
9: resets = ()
9: values = 2
11: result = ()
11: values = 4
13: resets = ()
```

`const[T, U](value: T, stream: Events[U]): Events[T]`

Maps the event's values of a `stream`

to given constant `value`

.

**Usage example:**

```
in x: Events[Int]
def y = const(42, x)
out y
```

**Trace example:**

```
stream x: bubbles
stream y: bubbles
---
1: y = 42
1: x = 17
6: y = 42
6: x = 1
8: y = 42
8: x = 42
12: y = 42
12: x = 23
```

`first[T, U](stream1: Events[T], stream2: Events[U]): Events[T]`

Returns a variant of `stream1`

which has every original events of `stream1`

and additional events with the last value of `stream1`

for every event of `stream2`

. `first`

is defined as the signal lift of the function *f(a,b) = a*.

Note, the difference between `first(stream1, stream2)`

and `merge(stream1, last(stream1, stream2))`

. Since `first`

is defined via signal lift, it does not produce events before both input streams have been defined.

**Usage example:**

```
in x: Events[Int]
in y: Events[Int]
def z = first(x, y)
out z
```

**Trace example:**

```
stream x: signal
stream y: signal
stream z: signal
---
1: x = 17
2: y = 23
2: z = 17
3: z = 1
3: x = 1
4: y = 3
4: z = 1
6: y = 34
6: z = 42
6: x = 42
8: y = 12
8: z = 42
```

`slift1[T, U](stream: Events[T], f: ((T) => U): Events[U]`

The unary signal lift is very similar to `lift1`

. Since the lifted function is unary, there is no other stream with which events are being synchronized. The only difference is that `slift1`

takes a total function which cannot remove events.

**Usage example:**

```
in a: Events[Int]
def b = slift1(a, (x: Int) => x + 1)
out b
```

**Trace example:**

```
stream a: signal
stream b: signal
---
1: b = 3
1: a = 2
3: b = 6
3: a = 5
7: b = 4
7: a = 3
```

`slift2[T, U, V](a: Events[T], b: Events[U], f: ((T, U) => V): Events[V]`

Takes a function `f`

on values and lifts it to a function on streams using signal semantics. The function is then applied to the given streams. `f`

is evaluated for every event on any of the given streams. If a stream contains no simultaneous event with the same timestamp then `f`

is called with the last known value of that stream. `f`

is not called before every stream had at least one event.

Note, that in comparison to `lift`

`f`

takes no `Option`

type. `slift`

cannot filter events. The generated event pattern is independent of the lifted function `f`

.

**Usage example:**

```
in a: Events[Int]
in b: Events[Int]
def z = slift(a, b, (v1: Int, v2: Int) => (v1 + v2) / 2)
out z
```

**Trace example:**

```
stream a: signal
stream b: signal
stream z: signal
---
2: a = 2
3: a = 3
5: b = 1
5: z = 2
7: b = 4
7: a = 5
7: z = 4
10: b = 7
10: z = 6
12: a = 6
12: z = 6
```

`slift`

`slift3[T1, T2, T3, T4](a: Events[T1], b: Events[T2], c: Events[T3], f: ((T1, T2, T3) => T4): Events[T4]`

Takes a function `f`

on values and lifts it to a function on streams using signal semantics. The function is then applied to the given streams. `f`

is evaluated for every event on any of the given streams. If a stream contains no simultaneous event with the same timestamp then `f`

is called with the last known value of that stream. `f`

is not called before every stream had at least one event.

Note, that in comparison to `lift3`

`f`

takes no `Option`

type. `slift3`

cannot filter events. The generated event pattern is independent of the lifted function `f`

.

**Usage example:**

```
in a: Events[Int]
in b: Events[Int]
in c: Events[Int]
def z = slift3(a, b, c, (v1: Int, v2: Int, v3: Int) => (v1 + v2 + v3) / 3)
out z
```

**Trace example:**

```
stream a: signal
stream b: signal
stream c: signal
stream z: signal
---
2: a = 2
3: a = 3
5: b = 1
6: c = 8
6: z = 4
7: b = 4
7: a = 5
7: z = 5
10: b = 7
10: z = 6
12: b = 9
12: c = 10
12: a = 6
12: z = 8
```

`slift4[T1, T2, T3, T4, T5](s1: Events[T1], s2: Events[T2], s3: Events[T3], s4: Events[T4], f: ((T1, T2, T3, T4) => T5): Events[T5]`

Takes a function `f`

on values and lifts it to a function on streams using signal semantics. The function is then applied to the given streams. `f`

is evaluated for every event on any of the given streams. If a stream contains no simultaneous event with the same timestamp then `f`

is called with the last known value of that stream. `f`

is not called before every stream had at least one event.

Note, that in comparison to `lift4`

`f`

takes no `Option`

type. `slift4`

cannot filter events. The generated event pattern is independent of the lifted function `f`

.

**Usage example:**

```
in a: Events[Int]
in b: Events[Int]
in c: Events[Int]
in d: Events[Int]
def z = slift4(a, b, c, d,
(v1: Int, v2: Int, v3: Int, v4: Int) => (v1 + v2 + v3 + v4) / 4)
out z
```

**Trace example:**

```
stream a: signal
stream b: signal
stream c: signal
stream d: signal
stream z: signal
---
1: d = 12
2: a = 2
3: a = 3
5: b = 1
6: z = 6
6: c = 8
7: a = 5
7: b = 4
7: z = 7
10: b = 7
10: z = 8
12: a = 6
12: d = 11
12: b = 9
12: z = 9
12: c = 10
```

`slift5[T1, T2, T3, T4, T5, U](s1: Events[T1], s2: Events[T2], s3: Events[T3], s4: Events[T4], s5: Events[T5], f: ((T1, T2, T3, T4, T5) => U): Events[U]`

`f`

on values and lifts it to a function on streams using signal semantics. The function is then applied to the given streams. `f`

is evaluated for every event on any of the given streams. If a stream contains no simultaneous event with the same timestamp then `f`

is called with the last known value of that stream. `f`

is not called before every stream had at least one event.

Note, that in comparison to `lift5`

`f`

takes no `Option`

type. `slift5`

cannot filter events. The generated event pattern is independent of the lifted function `f`

.

See `slift4`

for a usage example.

`merge2[T](stream1: Events[T], stream2: Events[T]): Events[T]`

Merges the given event streams. Prioritizing the event streams from the left to the right in case of simultaneous events.

**Usage example:**

```
in a: Events[Int]
in b: Events[Int]
def z = merge(a,b)
out z
```

**Trace example:**

```
stream a: bubbles
stream b: bubbles
stream z: bubbles
---
1: a = 3
1: z = 3
2: b = 4
2: z = 4
3: a = 2
3: z = 2
7: b = 6
7: a = 1
7: z = 1
8: a = 5
8: z = 5
```

`merge`

`merge3[T](a: Events[T], b: Events[T], c: Events[T]): Events[T]`

Merges the given event streams. Prioritizing the event streams from the left to the right in case of simultaneous events.

See `merge`

for a usage example.

`merge4[T](a: Events[T], b: Events[T], c: Events[T], d: Events[T]): Events[T]`

Merges the given event streams. Prioritizing the event streams from the left to the right in case of simultaneous events.

See `merge`

for a usage example.

`merge5[T](a: Events[T], b: Events[T], c: Events[T], d: Events[T], e: Events[T]): Events[T]`

See `merge`

for a usage example.

`merge6[T](a: Events[T], b: Events[T], c: Events[T], d: Events[T], e: Events[T], f: Events[T]): Events[T]`

See `merge`

for a usage example.

`merge7[T](a: Events[T], b: Events[T], c: Events[T], d: Events[T], e: Events[T], f: Events[T], g: Events[T]): Events[T]`

See `merge`

for a usage example.

`merge8[T](a: Events[T], b: Events[T], c: Events[T], d: Events[T], e: Events[T], f: Events[T], g: Events[T], h: Events[T]): Events[T]`

See `merge`

for a usage example.

`mergeUnit2[T, U](a: Events[T], b: Events[U]): Events[Unit]`

Merges streams of different types, resulting in a stream that contains a unit event whenever any of the input streams produces an event.

**Usage example:**

```
in x: Events[Int]
in y: Events[Bool]
def z = mergeUnit(x, y)
out z
```

**Trace example:**

```
stream x: bubbles
stream y: bubbles
stream z: unit events
---
1: x = 3
1: z = ()
2: y = false
2: z = ()
3: x = 2
3: z = ()
7: y = true
7: x = 1
7: z = ()
8: x = 5
8: z = ()
```

`mergeUnit`

`mergeUnit3[T, U, V](a: Events[T], b: Events[U], c: Events[V]): Events[Unit]`

Merges streams of different types, resulting in a stream that contains a unit event whenever any of the input streams produces an event.

See `mergeUnit`

for a usage example.

`mergeUnit4[T, U, V, W](a: Events[T], b: Events[U], c: Events[V], d: Events[W]): Events[Unit]`

Merges streams of different types, resulting in a stream that contains a unit event whenever any of the input streams produces an event.

See `mergeUnit`

for a usage example.

`filter[A](events: Events[A], condition: Events[Bool]): Events[A]`

Filter the event stream `events`

based on the last known value of the boolean signal `condition`

.

**Usage example:**

```
in x: Events[String]
in c: Events[Bool]
def y = filter(x, c)
out y
```

```
stream x: events
stream c: signal
stream y: events
---
1: x = "Hello"
2: c = true
3: x = "World"
3: y = "World"
7: c = false
7: x = "Hey"
8: x = "You"
```

`pure[T](x: Events[T]): Events[T]`

Removes subsequent events with the same value

**Usage example:**

```
in x: Events[Int]
def y = pure(x)
out y
```

**Trace example:**

```
stream x: signal
stream y: signal
---
2: y = 3
2: x = 3
4: x = 3
5: x = 3
6: y = 1
6: x = 1
8: y = 2
8: x = 2
10: x = 2
12: y = 4
12: x = 4
```

`isFirst[A](x: Events[A]): Events[Bool]`

Signal which is only true with first event on `x`

**Usage example:**

```
in x: Events[Int]
def f = isFirst(x)
out f
```

**Trace example:**

```
stream x: bubbles
stream f: signal
---
0: f = false
2: f = true
2: x = 3
6: f = false
6: x = 1
8: f = false
8: x = 2
12: f = false
12: x = 4
```

`firstEvent[A](x: Events[A]): Events[A]`

Filters `x`

such that only the first event on `x`

remains

**Usage example:**

```
in x: Events[Int]
def y = firstEvent(x)
out y
```

**Trace example:**

```
stream x: bubbles
stream y: bubbles
---
2: y = 3
2: x = 3
6: x = 1
8: x = 2
12: x = 4
```

`defined[T](x: Events[T]): Events[Bool]`

Signal, which becomes `true`

with the first event on `x`

**Usage example:**

```
in x: Events[Int]
def f = defined(x)
out f
```

**Trace example:**

```
stream x: bubbles
stream f: signal
---
0: f = false
2: f = true
2: x = 3
6: f = true
6: x = 1
8: f = true
8: x = 2
12: f = true
12: x = 4
```

`runtime[A, B](call: Events[A], ret: Events[B]): Events[Int]`

Compute the runtime of a function on every `ret`

event. The runtime is the time passed between the last `call`

event and the `ret`

event. The values of the events are ignored.

**Usage example:**

```
in call: Events[Unit]
in ret: Events[Unit]
def rt = runtime(call, ret)
out rt
```

**Trace example:**

```
option axis: true
option timeDomain: [5,75]
stream call: unit events
stream ret: unit events
stream rt: events
---
10: call = ()
17: ret = ()
17: rt = 7
25: call = ()
35: ret = ()
35: rt = 10
57: call = ()
69: ret = ()
69: rt = 12
```

`maximum(x: Events[Int]): Events[Int]`

Compute the maximum value of all events on `x`

. Provides for every input event and output event whose value is the maximum up to this point.

**Usage example:**

```
in x: Events[Int]
def m = maximum(x)
out m
```

**Trace example:**

```
stream x: bubbles
stream m: signal
---
2: m = 4
2: x = 4
6: m = 4
6: x = 2
8: m = 5
8: x = 5
12: m = 5
12: x = 3
```

`minimum(x: Events[Int]): Events[Int]`

Compute the minimum value of all events on `x`

. Provides for every input event and output event whose value is the minimum up to this point.

**Usage example:**

```
in x: Events[Int]
def m = minimum(x)
out m
```

**Trace example:**

```
stream x: bubbles
stream m: signal
---
2: m = 4
2: x = 4
6: m = 2
6: x = 2
8: m = 2
8: x = 5
12: m = 2
12: x = 3
```

`count[T](x: Events[T]): Events[Int]`

Count the number of events on `x`

. Provides for every input event an output event whose value is the number of events seen so far. See `resetCount`

for a counting macro with an external reset.

**Usage example:**

```
in x: Events[Unit]
def y = count(x)
out y
```

**Trace example:**

```
stream x: unit events
stream y: signal
---
0: y = 0
2: y = 1
2: x = ()
6: y = 2
6: x = ()
7: y = 3
7: x = ()
9: y = 4
9: x = ()
```

`sum(x: Events[Int]): Events[Int]`

Sum up the values of all events on `x`

. Provides for every input event an output event whose value is the sum of the values of all events seen so far.

**Usage example:**

```
in x: Events[Int]
def y = sum(x)
out y
```

**Trace example:**

```
stream x: bubbles
stream y: signal
---
0: y = 0
2: y = 2
2: x = 2
6: y = 10
6: x = 8
7: y = 13
7: x = 3
9: y = 14
9: x = 1
```

`fold[T, R](stream: Events[T], init: R, f: ((R, T) => R): Events[R]`

Fold a function on values over all events on `stream`

. Starting with the initial value `init`

the function `f`

is called for every event on `stream`

with the last result and the current event’s value as arguments. So for the input stream `x`

```
2: x = 2
4: x = 6
5: x = 1
```

the call `def y = fold(f, x, 0)`

produces the following stream `y`

:

```
0: y = 0
2: y = f(0,2)
4: y = f(f(0,2),6)
5: y = f(f(f(0,2),6),1)
```

See `count`

for an example of `fold`

in action. `count`

is defined as `fold(x, 0, inc)`

.

`reduce[T](stream: Events[T], f: ((Events[T], Events[T]) => Events[T]): Events[T]`

Fold a function on values over all events on `stream`

. Starting with the first event on `stream`

as initial value, the function `f`

is called for every later event on `stream`

with the last result and the current event’s value as arguments. So for the input stream `x`

```
2: x = 2
4: x = 6
5: x = 1
```

the call `def y = reduce(f, x)`

produces the following stream `y`

:

```
2: y = 2
4: y = f(2,6)
5: y = f(f(2,6),1)
```

See `minimum`

for an example of reduce in action. `minimum`

is defined as `reduce(x, min)`

.

`resetCount[A, B](events: Events[A], reset: Events[B]): Events[Int]`

Count the number of events on `events`

. Reset the output to 0 on every event on `reset`

.

**Usage example:**

```
in events: Events[Unit]
in resets: Events[Unit]
def result = resetCount(events, resets)
out result
```

**Trace example:**

```
stream events: unit events
stream resets: unit events
stream result: signal
---
0: result = 0
2: events = ()
2: result = 1
3: events = ()
3: result = 2
5: events = ()
5: result = 3
7: resets = ()
7: events = ()
7: result = 1
9: events = ()
9: result = 2
10: events = ()
10: result = 3
12: resets = ()
12: result = 0
14: events = ()
14: result = 1
15: events = ()
15: result = 2
```

`bursts[A](e: Events[A], burstLength: Int, waitingPeriod: Int, burstAmount: Int): Events[Bool]`

Check if events on `e`

follow the burst pattern: After first event on `e`

only `burstAmount`

many events allowed during `burstLength`

time. After `burstLength`

during `waitingPeriod`

time no event allowed. After `waitingPeriod`

we wait for the next event on `e`

.

```
in send: Events[Unit]
def property :=
bursts(send, burstLength = 3s,
waitingPeriod = 2s, burstAmount = 4)
out property
```

```
option axis: true
option timeDomain: [0, 9000000000]
stream send: unit events
stream property: signal
---
0: property = true
500191958: property = true
500191958: send = ()
1000275162: property = true
1000275162: send = ()
1500422455: property = true
1500422455: send = ()
2000525066: property = true
2000525066: send = ()
4500724637: property = false
4500724637: send = ()
5000822890: property = false
5000822890: send = ()
7501025420: property = true
7501025420: send = ()
8001141937: property = true
8001141937: send = ()
8501245567: property = true
8501245567: send = ()
```

`burstsSince[A, B](e: Events[A], burstLength: Int, waitingPeriod: Int, burstAmount: Int, since: Events[B]): Events[Bool]`

Check if events on `e`

follow the burst pattern since the last event on `since`

: After first event on `e`

only `burstAmount`

many events allowed during `burstLength`

time. After `burstLength`

during `waitingPeriod`

time no event allowed. After `waitingPeriod`

we wait for the next event on `e`

.

**Usage example:**

```
in reset: Events[Unit]
in e: Events[Unit]
def p := burstsSince(e, burstLength = 2s,
waitingPeriod = 1s,
burstAmount = 3,
since = reset)
out p
```

```
option axis: true
option timeDomain: [0, 17000]
stream e: unit events
stream reset: unit events
stream p: signal
---
0: p = true
3000: e = ()
3000: p = true
3500: e = ()
3500: p = true
4000: e = ()
4000: p = true
4500: e = ()
4500: p = false
6000: reset = ()
7000: e = ()
7000: p = true
8000: e = ()
8000: p = true
12000: e = ()
12000: p = true
14500: e = ()
14500: p = false
16000: e = ()
16000: p = true
```

`noEvent[A, B](on: Events[A], since: Events[B]): Events[Bool]`

Check if no event happened on `on`

after last event on `since`

.

**Usage example:**

```
in reset: Events[Unit]
in e: Events[Unit]
def p := noEvent(e, since = reset)
out p
```

**Trace example:**

```
option timeDomain: [0,16]
stream e: unit events
stream reset: unit events
stream p: signal
---
0: p = true
2: e = ()
2: p = false
4: e = ()
4: p = false
6: reset = ()
6: p = true
12: e = ()
12: p = false
```

`constIf[T](value: T, condition: Events[Bool]): Events[T]`

Produce an event with the given value every time that the condition is met

**Usage example:**

```
in condition: Events[Bool]
def result = constIf(42, condition)
out result
```

**Trace example:**

```
2: condition = false
4: result = 42
4: condition = true
5: result = 42
5: condition = true
8: condition = false
9: condition = false
10: condition = false
12: result = 42
12: condition = true
```

`unitIf(cond: Events[Bool]): Events[Unit]`

Produces a unit event every time the condition is fulfilled

**Usage example:**

```
in condition: Events[Bool]
def result = unitIf(condition)
out result
```

**Trace example:**

```
2: condition = false
4: result = ()
4: condition = true
5: result = ()
5: condition = true
8: condition = false
9: condition = false
10: condition = false
12: result = ()
12: condition = true
```

`rising(condition: Events[Bool]): Events[Unit]`

Detect rising edge on `condition`

**Usage example:**

```
in condition: Events[Bool]
def result = rising(condition)
out result
```

**Trace example:**

```
stream condition: plot
stream result: unit events
---
2: condition = false
4: result = ()
4: condition = true
5: condition = true
8: condition = false
9: condition = false
10: condition = false
12: result = ()
12: condition = true
```

`falling(condition: Events[Bool]): Events[Unit]`

Detect falling edge on `condition`

**Usage example:**

```
in condition: Events[Bool]
def result = falling(condition)
out result
```

**Trace example:**

```
stream condition: plot
stream result: unit events
---
2: condition = false
4: condition = true
5: condition = true
8: result = ()
8: condition = false
9: condition = false
10: condition = false
12: condition = true
```

`on[A, B](trigger: Events[A], stream: Events[B]): Events[B]`

Produce the current or last value on `stream`

for every `trigger`

**Usage example:**

```
in trigger: Events[Unit]
in stream: Events[Int]
def result = on(trigger, stream)
out result
```

**Trace example:**

```
stream stream: signal
stream trigger: unit events
stream result: signal
---
2: trigger = ()
3: stream = 3
5: trigger = ()
5: result = 3
7: stream = 2
8: stream = 1
10: trigger = ()
10: result = 1
12: stream = 4
12: trigger = ()
12: result = 4
14: trigger = ()
14: result = 4
```

`average(x: Events[Int]): Events[Int]`

Compute the average value of all events on `x`

. For every input event on `x`

an output event is produced whose value is the average of all values seen so far.

**Usage example:**

```
in stream: Events[Int]
def result = average(stream)
out result
```

**Trace example:**

```
stream stream: bubbles
stream result: bubbles
---
3: result = 3
3: stream = 3
7: result = 2
7: stream = 2
8: result = 2
8: stream = 1
12: result = 2
12: stream = 4
```

`period(freq: Int): Events[Unit]`

Produce an event stream with a unit event every `delay`

time units. Starting with an event at timestamp 0.

**Usage example:**

```
in progress: Events[Unit]
def output = period(3)
out output
```

```
option axis: true
stream progress: unit events
stream output: unit events
---
0: output = ()
3: output = ()
6: output = ()
9: output = ()
12: output = ()
15: output = ()
18: output = ()
20: progress = ()
```

`sample[A](e: Events[A], rate: Int): Events[A]`

Filter out events to ensure a maximal event rate. Forwards the first event on `e`

and afterwards every event which is at least `rate`

time units later then the last forwarded event.

**Usage example:**

```
in x: Events[Int]
def y = sample(x, 5)
out y
```

**Trace example:**

```
option axis: true
stream x: events
stream y: events
---
2: y = 5
2: x = 5
4: x = 3
5: x = 4
7: y = 2
7: x = 2
9: x = 1
10: x = 8
13: y = 3
13: x = 3
15: x = 9
16: x = 7
18: y = 6
18: x = 6
20: x = 2
23: y = 4
23: x = 4
25: x = 9
```

Lists

`empty[T]: List[T]`

`@liftable`

size[T](list: List[T]): Int

`@liftable`

isEmpty[T](list: List[T]): Bool

`@liftable`

append[T](list: List[T], element: T): List[T]

`@liftable`

prepend[T](element: T, list: List[T]): List[T]

`@liftable`

tail[T](list: List[T]): List[T]

`@liftable`

init[T](list: List[T]): List[T]

`@liftable`

get[T](list: List[T], index: Int): T

`@liftable`

set[T](list: List[T], index: Int, value: T): List[T]

`@liftable`

head[T](list: List[T]): T

`@liftable`

last[T](list: List[T]): T

`@liftable`

fold[T, U](list: List[T], start: U, f: ((U, T) => U): U

`List[T]`

Set

`empty[T]: Set[T]`

`@liftable`

singleton[T](value: T): Set[T]

`@liftable`

add[T](set: Set[T], item: T): Set[T]

`@liftable`

contains[T](set: Set[T], item: T): Bool

`@liftable`

remove[T](set: Set[T], item: T): Set[T]

`@liftable`

size[T](set: Set[T]): Int

`@liftable`

union[T](set1: Set[T], set2: Set[T]): Set[T]

`@liftable`

intersection[T](set1: Set[T], set2: Set[T]): Set[T]

`@liftable`

minus[T](set1: Set[T], set2: Set[T]): Set[T]

`@liftable`

fold[T, U](set: Set[T], start: U, f: ((U, T) => U): U

`collect[T](value: Events[T])`

`collectWithRemove[T](value: Events[T], removeValue: Events[T])`

`old`

`set`

`Set[T]`

Maps

`empty[K, V]: Map[K, V]`

`@liftable`

add[K, V](map: Map[K, V], key: K, value: V): Map[K, V]

`@liftable`

contains[K, V](map: Map[K, V], key: K): Bool

`@liftable`

get[K, V](map: Map[K, V], key: K): V

`@liftable`

remove[K, V](map: Map[K, V], key: K): Map[K, V]

`@liftable`

size[K, V](map: Map[K, V]): Int

`@liftable`

keys[K, V](map: Map[K, V]): List[K]

`@liftable`

fold[K, V, R](map: Map[K, V], start: R, f: ((R, K, V) => R): R

`@liftable`

getOrElse[K, V](map: Map[K, V], key: K, default: V): V

`@liftable`

inc[K](counts: Map[K, Int], key: K): Map[K, Int]

`collectCount[T](events: Events[T]): Events[Map[T, Int]]`

`collectMax[K](key: Events[K], value: Events[Int]): Events[Map[K, Int]]`

`oldMap`

`collectMin[A](key: Events[A], value: Events[Int])`

`oldMap`

`counting[A](x: Events[A])`

Map every new key to a unique integer ID

`Map[K, V]`

Strings

`@liftable`

concat(str1: String, str2: String): String

`@liftable`

format[T](formatString: String, value: T): String

`@liftable`

formatInt(formatString: String, value: Int): String

`@liftable`

formatFloat(formatString: String, value: Float): String

MITL[S_{0,∞}]

`since0(x: Int, a: Events[Bool], b: Events[Bool]): Events[Bool]`

a S[0, x] b, x > 0

`sinceInfinity(x: Int, a: Events[Bool], b: Events[Bool]): Events[Bool]`

a S[x, ∞] b, x ≥ 0

`start`

`once0(x: Int, a: Events[Bool])`

O[0, x] a

`onceInfinity(x: Int, a: Events[Bool])`

O[x, ∞] a

`historically0(x: Int, a: Events[Bool])`

H[0, x] a

`historicallyInfinity(x: Int, a: Events[Bool])`

H[x, ∞] a

past-time LTL

`since(a: Events[Bool], b: Events[Bool]): Events[Bool]`

a S b

`once(a: Events[Bool]): Events[Bool]`

O a

`historically(a: Events[Bool]): Events[Bool]`

H a

Annotations controlling the instrumentation of C code

`@InstFunctionCall(name: String)`

Add event generation to every call of the function before the actual function call

`@InstFunctionCallArg(name: String, index: Int)`

Add event generation to every call of the function before the actual function call

`@InstFunctionCalled(name: String)`

Add event generation to the first line of the function

`@InstFunctionCalledArg(name: String, index: Int)`

Add event generation to the first line of the function

`@InstFunctionReturn(name: String)`

Add event generation to every return inside of the function. Generates unit events.

`@InstFunctionReturnValue(name: String)`

Add event generation to every return inside of the function. Generates events carrying the returned value as data.

`@InstFunctionReturned(name: String)`

Add event generation to every call of the function after the function returned. Generates unit events.

`@InstFunctionReturnedValue(name: String)`

Add event generation to every call of the function after the function returned. Generates events carrying the returned value as data.

`@GlobalRead(lvalue: String)`

Instrument every reading access of a global variable with the given name. Can handle more complex patterns, e.g. `*&bar[][].foo`

`@GlobalReadIndex(lvalue: String)`

Instrument every reading access of a global variable with the given name. Can handle more complex patterns, e.g. `*&bar[][].foo`

Get the index as event's value.

`@LocalRead(lvalue: String, function: String)`

Instrument every reading access of a local variable with the given name inside the given function. Can handle more complex patterns, e.g. `*&bar[][].foo`

`@LocalReadIndex(lvalue: String, function: String)`

Instrument every reading access of a local variable with the given name inside the given function. Can handle more complex patterns, e.g. `*&bar[][].foo`

Get the index as event's value.

`@GlobalWrite(lvalue: String)`

Instrument every writing access of a global variable with the given name. Can handle more complex patterns, e.g. `*&bar[][].foo`

`@GlobalWriteIndex(lvalue: String)`

Instrument every writing access of a global variable with the given name. Can handle more complex patterns, e.g. `*&bar[][].foo`

Get the index as event's value.

`@LocalWrite(lvalue: String, function: String)`

Instrument every writing access of a local variable with the given name inside the given function. Can handle more complex patterns, e.g. `*&bar[][].foo`

`@LocalWriteIndex(lvalue: String, function: String)`

Instrument every writing access of a local variable with the given name inside the given function. Can handle more complex patterns, e.g. `*&bar[][].foo`

Get the index as event's value.

`@ThreadId`

Writes the current thread ID to the annotated stream every time any other instrumentation produces any event

The Tessla module contains meta data about the used Tessla compiler and interpreter or engine.

`version: String`

The current TeSSLa version

Common Trace Format

`Object`

`@liftable`

getInt(ctfObject: Object, member: String): Int

`@liftable`

getString(ctfObject: Object, member: String): String