Skip to main content

SequenceExtensions

Provides LINQ extensions methods for Sequence and Element.

public static class SequenceExtensions

Inheritance objectSequenceExtensions

Methods

ToSequence(IEnumerable<Element>)

Builds a Sequence object from the set of elements.

public static Sequence ToSequence(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>
Set of elements composing the sequence. Must be in uninterrupted order.

Returns

Sequence

ToSequence(IEnumerable<Element>, Rational, Rational, Rational?)

Builds a Sequence object from the set of elements. Fills the gaps within [fillFrom, fillTo[ with ++\infty.

public static Sequence ToSequence(this IEnumerable<Element> elements, Rational fillFrom, Rational fillTo, Rational? fillWith = null)

Parameters

elements IEnumerable<Element>
Partial set of elements composing the sequence. Must be ordered, but can have gaps.

fillFrom Rational
Left inclusive endpoint of the filling interval.

fillTo Rational
Right exclusive endpoint of the filling interval.

fillWith Rational?
The value filled in. Defaults to ++\infty

Returns

Sequence

Cut(IEnumerable<Element>, Rational, Rational, bool, bool)

Returns a cut of the sequence for a smaller support.

note

Optimized for minimal allocations

public static IEnumerable<Element> Cut(this IEnumerable<Element> elements, Rational cutStart, Rational cutEnd, bool isStartIncluded = true, bool isEndIncluded = false)

Parameters

elements IEnumerable<Element>
The elements to process.

cutStart Rational
Left endpoint of the new support.

cutEnd Rational
Right endpoint of the new support.

isStartIncluded bool
If true, the support is left-closed.

isEndIncluded bool
If true, the support is right-closed.

Returns

IEnumerable<Element>

Exceptions

ArgumentException
Thrown if the new support is not a subset of the current one.

Fill(IEnumerable<Element>, Rational, Rational, bool, bool, Rational?)

Fills the gaps of the set of elements within fillFrom and fillTo with the given value, defaults to ++\infty.

public static IEnumerable<Element> Fill(this IEnumerable<Element> elements, Rational fillFrom, Rational fillTo, bool isFromIncluded = true, bool isToIncluded = false, Rational? fillWith = null)

Parameters

elements IEnumerable<Element>
The set of elements. Must be in order.

fillFrom Rational
Left endpoint of the filling interval.

fillTo Rational
Right endpoint of the filling interval.

isFromIncluded bool
If true, left endpoint is inclusive.

isToIncluded bool
If true, right endpoint is inclusive.

fillWith Rational?
The value filled in. Defaults to ++\infty

Returns

IEnumerable<Element>
The result.

Merge(IReadOnlyList<Element>, bool, ComputationSettings)

Applies merge, whenever possible, to a set of elements. The result is the minimal set, in number of elements, to represent the same information.

public static List<Element> Merge(this IReadOnlyList<Element> elements, bool doSort = false, ComputationSettings settings = null)

Parameters

elements IReadOnlyList<Element>
The elements to merge.

doSort bool
If true, the elements are sorted before attempting to merge.

settings ComputationSettings
Settings to forward to SortElements, if used.

Returns

List<Element>
A set where no further merges are possible.

MergeAsEnumerable(IEnumerable<Element>)

Applies merge, whenever possible, to a set of elements. The result is the minimal set, in number of elements, to represent the same information.

note

Optimized for minimal allocations

public static IEnumerable<Element> MergeAsEnumerable(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>
The elements to merge, must be sorted

Returns

IEnumerable<Element>
A set where no further merges are possible.

GetElementAt(IEnumerable<Element>, Rational)

Returns the Element that describes the sequence in time.

note

This method is implemented using a linear search, O(n)O(n)

public static Element GetElementAt(this IEnumerable<Element> elements, Rational time)

Parameters

elements IEnumerable<Element>
The elements to process.

time Rational
Time of the sample.

Returns

Element
The describing the sequence at .

Exceptions

ArgumentException
Thrown if the given time +ϵ+\epsilon is out of sequence support.

GetSegmentBefore(IEnumerable<Element>, Rational)

Returns the Segment that describes the sequence before time.

note

This method is implemented using a linear search, O(n)O(n)

public static Segment GetSegmentBefore(this IEnumerable<Element> elements, Rational time)

Parameters

elements IEnumerable<Element>
The elements to process.

time Rational
Time of the sample.

Returns

Segment
The describing the sequence before .

Exceptions

ArgumentException
Thrown if the given time +ϵ+\epsilon is out of sequence support.

GetSegmentAfter(IEnumerable<Element>, Rational)

Returns the Segment that describes the sequence after time.

note

This method is implemented using a linear search, O(n)O(n)

public static Segment GetSegmentAfter(this IEnumerable<Element> elements, Rational time)

Parameters

elements IEnumerable<Element>
The elements to process.

time Rational
Time of the sample.

Returns

Segment
The describing the sequence after .

Exceptions

ArgumentException
Thrown if the given time +ϵ+\epsilon is out of sequence support.

AreInTimeOrder(IEnumerable<Element>)

Checks if time order is respected, i.e. they are ordered first by start, then by end.

public static bool AreInTimeOrder(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

bool

AreInTimeSequence(IEnumerable<Element>)

Checks if the elements form a sequence. In addition to AreInTimeOrder(IEnumerable<Element>) it requires non-overlapping, but it allows gaps.

public static bool AreInTimeSequence(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

bool

AreUninterruptedSequence(IEnumerable<Element>)

Checks if the elements form a uninterrupted sequence.

public static bool AreUninterruptedSequence(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

bool

SortElements(IReadOnlyList<Element>, ComputationSettings)

Sorts the elements in time order.

public static IReadOnlyList<Element> SortElements(this IReadOnlyList<Element> elements, ComputationSettings settings = null)

Parameters

elements IReadOnlyList<Element>

settings ComputationSettings

Returns

IReadOnlyList<Element>

EnumerateBreakpoints(Sequence)

Enumerates a Sequence as a series of breakpoints.

note

Does not attempt merging.

public static IEnumerable<(Segment left, Point center, Segment right)> EnumerateBreakpoints(this Sequence sequence)

Parameters

sequence Sequence
The sequence to process.

Returns

IEnumerable<(Segment left, Point center, Segment right)>

EnumerateBreakpoints(IEnumerable<Element>)

Enumerates a set of Elements as a series of breakpoints.

note

Does not attempt merging.

public static IEnumerable<(Segment left, Point center, Segment right)> EnumerateBreakpoints(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>
The elements to enumerate, must be sorted.

Returns

IEnumerable<(Segment left, Point center, Segment right)>

GetBreakpointBoundaryValues((Segment left, Point center, Segment right))

Enumerates the left-limit, the value and right-limit at the breakpoint.

public static IEnumerable<Rational> GetBreakpointBoundaryValues(this (Segment left, Point center, Segment right) breakpoint)

Parameters

breakpoint (Segment left, Point center, Segment right)

Returns

IEnumerable<Rational>

GetBreakpointsBoundaryValues(IEnumerable<(Segment left, Point center, Segment right)>)

Enumerates, for each breakpoint, the left-limit, the value and right-limit at the breakpoint.

public static IEnumerable<Rational> GetBreakpointsBoundaryValues(this IEnumerable<(Segment left, Point center, Segment right)> breakpoints)

Parameters

breakpoints IEnumerable<(Segment left, Point center, Segment right)>

Returns

IEnumerable<Rational>

GetElementsBoundaryValues(IEnumerable<Element>)

Enumerates for each point its value, and for each segment its right-limit at start and left-limit at end.

public static IEnumerable<Rational> GetElementsBoundaryValues(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

IEnumerable<Rational>

GetElementsBoundaryPairs(IEnumerable<Element>)

Enumerates for each point its time and value, and for each segment 1) its start time and right-limit at start, 2) its end time and left-limit at end.

note

The returned pairs are not points since, particularly for the pairs coming from segments, it is not given that the value is attained at that time.

public static IEnumerable<(Rational time, Rational value)> GetElementsBoundaryPairs(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

IEnumerable<(Rational time, Rational value)>

IsContinuous(IEnumerable<Element>)

True if there is no discontinuity within the sequence.

public static bool IsContinuous(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

bool

IsLeftContinuous(IEnumerable<Element>)

True if there is no left-discontinuity within the sequence.

public static bool IsLeftContinuous(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

bool

IsRightContinuous(IEnumerable<Element>)

True if there is no right-discontinuity within the sequence.

public static bool IsRightContinuous(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

bool

IsNonNegative(IEnumerable<Element>)

True if the sequence is non-negative, i.e. f(t)0f(t) \ge 0 for any tt.

public static bool IsNonNegative(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

bool

IsNonDecreasing(IEnumerable<Element>)

True if for any t>st > s, f(t)f(s)f(t) \ge f(s).

public static bool IsNonDecreasing(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

bool

IsIncreasing(IEnumerable<Element>)

True if for any t>st > s, f(t)>f(s)f(t) > f(s).

public static bool IsIncreasing(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

bool

IsFinite(IEnumerable<Element>)

True if for any tt, f(t)<+\left|f(t)\right| < +\infty.

public static bool IsFinite(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>
The elements to process.

Returns

bool
The result.

IsMinusInfinite(IEnumerable<Element>)

True if for any tt, f(t)=f(t) = -\infty.

public static bool IsMinusInfinite(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>
The elements to process.

Returns

bool
The result.

IsPlusInfinite(IEnumerable<Element>)

True if for any tt, f(t)=+f(t) = +\infty.

public static bool IsPlusInfinite(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>
The elements to process.

Returns

bool
The result.

BreakpointSupValue((Segment left, Point center, Segment right))

If the sequence is upper-bounded around the breakpoint tct_c, i.e., exists xx such that f(t)xf(t) \le x for any t[tcε,tc+ε]t \in [t_c - \varepsilon, t_c + \varepsilon], returns infx\inf x. Otherwise, returns ++\infty.

public static Rational BreakpointSupValue(this (Segment left, Point center, Segment right) breakpoint)

Parameters

breakpoint (Segment left, Point center, Segment right)

Returns

Rational

SupValue(IEnumerable<Element>)

If the sequence is upper-bounded, i.e., exists xx such that f(t)xf(t) \le x for any t0t \ge 0, returns infx\inf x. Otherwise, returns ++\infty.

public static Rational SupValue(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Rational

SupArg(IEnumerable<Element>)

If the sequence is upper-bounded, i.e., exists xx such that f(t)xf(t) \le x for any t0t \ge 0, returns the first time around which f(t)f(t) gets close to xx (i.e., either it attains the value or has it as a limit). Otherwise, returns ++\infty.

public static Rational SupArg(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Rational

MaxValue(IEnumerable<Element>)

If the sequence has a maximum, i.e., exist xx and tt^* such that f(t)xf(t) \le x for any t0t \ge 0 and f(t)=xf(t^*) = x, returns xx. Otherwise, returns null.

public static Rational? MaxValue(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Rational?

MaxValue(IReadOnlyCollection<Element>)

public static Rational? MaxValue(this IReadOnlyCollection<Element> elements)

Parameters

elements IReadOnlyCollection<Element>

Returns

Rational?

MaxArg(IEnumerable<Element>)

If the sequence has a maximum, i.e., exist xx and tt^* such that f(t)xf(t) \le x for any t0t \ge 0 and f(t)=xf(t^*) = x, returns tt^*. Otherwise, returns null.

public static Rational? MaxArg(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Rational?

MaxArg(IReadOnlyCollection<Element>)

public static Rational? MaxArg(this IReadOnlyCollection<Element> elements)

Parameters

elements IReadOnlyCollection<Element>

Returns

Rational?

BreakpointInfValue((Segment left, Point center, Segment right))

If the sequence is upper-bounded around the breakpoint tct_c, i.e., exists xx such that f(t)xf(t) \ge x for any t[tcε,tc+ε]t \in [t_c - \varepsilon, t_c + \varepsilon], returns supx\sup x. Otherwise, returns -\infty.

public static Rational BreakpointInfValue(this (Segment left, Point center, Segment right) breakpoint)

Parameters

breakpoint (Segment left, Point center, Segment right)

Returns

Rational

InfValue(IEnumerable<Element>)

If the sequence is lower-bounded, i.e., exists xx such that f(t)xf(t) \ge x for any t0t \ge 0, returns supx\sup x. Otherwise, returns -\infty.

public static Rational InfValue(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Rational

InfArg(IEnumerable<Element>)

If the sequence is lower-bounded, i.e., exists xx such that f(t)xf(t) \ge x for any t0t \ge 0, returns the first time around which f(t)f(t) gets close to xx (i.e., either it attains the value or has it as a limit). Otherwise, returns -\infty.

public static Rational InfArg(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Rational

MinValue(IEnumerable<Element>)

If the sequence has a minimum, i.e., exist xx and tt^* such that f(t)xf(t) \ge x for any t0t \ge 0 and f(t)=xf(t^*) = x, returns xx. Otherwise, returns null.

public static Rational? MinValue(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Rational?

MinValue(IReadOnlyCollection<Element>)

public static Rational? MinValue(this IReadOnlyCollection<Element> elements)

Parameters

elements IReadOnlyCollection<Element>

Returns

Rational?

MinArg(IEnumerable<Element>)

If the sequence has a minimum, i.e., exist xx and tt^* such that f(t)xf(t) \ge x for any t0t \ge 0 and f(t)=xf(t^*) = x, returns tt^*. Otherwise, returns null.

public static Rational? MinArg(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Rational?

MinArg(IReadOnlyCollection<Element>)

public static Rational? MinArg(this IReadOnlyCollection<Element> elements)

Parameters

elements IReadOnlyCollection<Element>

Returns

Rational?

ToLeftContinuous(IEnumerable<Element>)

Computes a left-continuous version of this sequence.

public static IEnumerable<Element> ToLeftContinuous(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

IEnumerable<Element>

ToRightContinuous(IEnumerable<Element>)

Computes a right-continuous version of this sequence.

public static IEnumerable<Element> ToRightContinuous(this IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

IEnumerable<Element>

LowerPseudoInverse(IEnumerable<Element>, bool)

Computes the lower pseudo-inverse function, f1(x)=inf{t:f(t)>=x}f^{-1}_\downarrow(x) = \inf \left\{ t : f(t) >= x \right\}, where tSupport(f)t \in Support(f) and xImage(f)x \in Image(f).

note

The result of this operation is left-continuous, thus is revertible, i.e. (f1)1=f\left(f^{-1}_\downarrow\right)^{-1}_\downarrow = f, only if ff is left-continuous. See [DNC18] § 3.2.1 If there are jumps or plateaus at the endpoints, those may also be lost during pseudoinversion.

public static IEnumerable<Element> LowerPseudoInverse(this IEnumerable<Element> elements, bool startFromZero = false)

Parameters

elements IEnumerable<Element>
The elements to process.

startFromZero bool
If true, it is assumed that f1(x)f^{-1}_\downarrow(x) is defined from x=0x = 0, rather than only in Image(f)Image(f).

Returns

IEnumerable<Element>

Exceptions

ArgumentException
If the elements are not non-decreasing.

ArgumentException
If the collection is empty.

UpperPseudoInverse(IEnumerable<Element>, bool)

Computes the upper pseudo-inverse function, f1(x)=inf{t:f(t)>x}f^{-1}_\uparrow(x) = \inf \left\{ t : f(t) > x \right\}, where tSupport(f)t \in Support(f) and xImage(f)x \in Image(f).

note

The result of this operation is right-continuous, thus is revertible, i.e. (f1)1=f\left(f^{-1}_\uparrow\right)^{-1}_\uparrow = f, only if ff is right-continuous. See [DNC18] § 3.2.1 If there are jumps or plateaus at the endpoints, those may also be lost during pseudoinversion.

public static IEnumerable<Element> UpperPseudoInverse(this IEnumerable<Element> elements, bool startFromZero = false)

Parameters

elements IEnumerable<Element>
The elements to process.

startFromZero bool
If true, it is assumed that f1(x)f^{-1}_\uparrow(x) is defined from x=0x = 0, rather than only in Image(f)Image(f).

Returns

IEnumerable<Element>

Exceptions

ArgumentException
If the elements are not non-decreasing.

ArgumentException
If the collection is empty.

LowerEnvelope(IReadOnlyList<Element>, ComputationSettings)

Computes the lower envelope of the set of elements given. O(nlog(n))O(n \cdot \log(n)) complexity.

note

Used for convolution

public static List<Element> LowerEnvelope(this IReadOnlyList<Element> elements, ComputationSettings settings = null)

Parameters

elements IReadOnlyList<Element>

settings ComputationSettings

Returns

List<Element>

LowerEnvelope(IReadOnlyList<Sequence>, ComputationSettings)

Computes the lower envelope of the set of sequences given.

note

Used for partitioned convolution.

public static IReadOnlyList<Element> LowerEnvelope(this IReadOnlyList<Sequence> sequences, ComputationSettings settings = null)

Parameters

sequences IReadOnlyList<Sequence>

settings ComputationSettings

Returns

IReadOnlyList<Element>

UpperEnvelope(IReadOnlyList<Element>, ComputationSettings)

Computes the upper envelope of the set of elements given. O(nlog(n))O(n \cdot \log(n)) complexity.

note

Used for deconvolution

public static List<Element> UpperEnvelope(this IReadOnlyList<Element> elements, ComputationSettings settings = null)

Parameters

elements IReadOnlyList<Element>
The elements to process.

settings ComputationSettings
Optional settings for the operation.

Returns

List<Element>

UpperEnvelope(IReadOnlyList<Sequence>, ComputationSettings)

Computes the lower envelope of the set of sequences given.

public static IReadOnlyList<Element> UpperEnvelope(this IReadOnlyList<Sequence> sequences, ComputationSettings settings = null)

Parameters

sequences IReadOnlyList<Sequence>

settings ComputationSettings

Returns

IReadOnlyList<Element>