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(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, Nullable<Rational>)

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

public static Sequence ToSequence(IEnumerable<Element> elements, Rational fillFrom, Rational fillTo, Nullable<Rational> fillWith)

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 Nullable<Rational>
The value filled in. Defaults to ++\infty

Returns

Sequence

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

Returns a cut of the sequence for a smaller support.

note

Optimized for minimal allocations

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

Parameters

elements IEnumerable<Element>

cutStart Rational
Left endpoint of the new support.

cutEnd Rational
Right endpoint of the new support.

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

isEndIncluded Boolean
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, Boolean, Boolean, Nullable<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(IEnumerable<Element> elements, Rational fillFrom, Rational fillTo, bool isFromIncluded, bool isToIncluded, Nullable<Rational> fillWith)

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 Boolean
If true, left endpoint is inclusive.

isToIncluded Boolean
If true, right endpoint is inclusive.

fillWith Nullable<Rational>
The value filled in. Defaults to ++\infty

Returns

IEnumerable<Element>

Merge(IReadOnlyList<Element>, Boolean, 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(IReadOnlyList<Element> elements, bool doSort, ComputationSettings settings)

Parameters

elements IReadOnlyList<Element>
The elements to merge.

doSort Boolean
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(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(IEnumerable<Element> elements, Rational time)

Parameters

elements IEnumerable<Element>

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(IEnumerable<Element> elements, Rational time)

Parameters

elements IEnumerable<Element>

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(IEnumerable<Element> elements, Rational time)

Parameters

elements IEnumerable<Element>

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(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Boolean

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(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Boolean

AreUninterruptedSequence(IEnumerable<Element>)

Checks if the elements form a uninterrupted sequence.

public static bool AreUninterruptedSequence(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Boolean

SortElements(IReadOnlyList<Element>, ComputationSettings)

Sorts the elements in time order.

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

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<ValueTuple<Segment, Point, Segment>> EnumerateBreakpoints(Sequence sequence)

Parameters

sequence Sequence

Returns

IEnumerable<ValueTuple<Segment, Point, Segment>>

EnumerateBreakpoints(IEnumerable<Element>)

Enumerates a set of Elements as a series of breakpoints.

note

Does not attempt merging.

public static IEnumerable<ValueTuple<Segment, Point, Segment>> EnumerateBreakpoints(IEnumerable<Element> elements)

Parameters

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

Returns

IEnumerable<ValueTuple<Segment, Point, Segment>>

GetBreakpointValues(ValueTuple<Segment, Point, Segment>)

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

public static IEnumerable<Rational> GetBreakpointValues(ValueTuple<Segment, Point, Segment> breakpoint)

Parameters

breakpoint ValueTuple<Segment, Point, Segment>

Returns

IEnumerable<Rational>

GetBreakpointsValues(IEnumerable<ValueTuple<Segment, Point, Segment>>)

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

public static IEnumerable<Rational> GetBreakpointsValues(IEnumerable<ValueTuple<Segment, Point, Segment>> breakpoints)

Parameters

breakpoints IEnumerable<ValueTuple<Segment, Point, Segment>>

Returns

IEnumerable<Rational>

IsContinuous(IEnumerable<Element>)

True if there is no discontinuity within the sequence.

public static bool IsContinuous(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Boolean

IsLeftContinuous(IEnumerable<Element>)

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

public static bool IsLeftContinuous(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Boolean

IsRightContinuous(IEnumerable<Element>)

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

public static bool IsRightContinuous(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Boolean

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(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Boolean

IsNonDecreasing(IEnumerable<Element>)

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

public static bool IsNonDecreasing(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Boolean

IsFinite(IEnumerable<Element>)

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

public static bool IsFinite(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Boolean

IsMinusInfinite(IEnumerable<Element>)

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

public static bool IsMinusInfinite(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Boolean

IsPlusInfinite(IEnumerable<Element>)

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

public static bool IsPlusInfinite(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Boolean

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(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

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(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

Rational

ToLeftContinuous(IEnumerable<Element>)

Computes a left-continuous version of this sequence.

public static IEnumerable<Element> ToLeftContinuous(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(IEnumerable<Element> elements)

Parameters

elements IEnumerable<Element>

Returns

IEnumerable<Element>

LowerPseudoInverse(IEnumerable<Element>, Boolean)

Computes the lower pseudo-inverse function, f1(x)=inf{t:f(t)>=x}=sup{t:f(t)<x}f^{-1}_\downarrow(x) = \inf \left\{ t : f(t) >= x \right\} = \sup \left\{ t : f(t) < x \right\}.

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

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

Parameters

elements IEnumerable<Element>

startFromZero Boolean
If true, it is assumed that f1(x)f^{-1}_\downarrow(x) be defined from x=0x = 0.

Returns

IEnumerable<Element>

Exceptions

ArgumentException
If the curve is not non-decreasing.

ArgumentException
If the collection is empty.

UpperPseudoInverse(IEnumerable<Element>, Boolean)

Computes the upper pseudo-inverse function, f1(x)=inf{t:f(t)>x}=sup{t:f(t)<=x}f^{-1}_\uparrow(x) = \inf \left\{ t : f(t) > x \right\} = \sup \left\{ t : f(t) <= x \right\}.

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

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

Parameters

elements IEnumerable<Element>

startFromZero Boolean
If true, it is assumed that f1(x)f^{-1}_\uparrow(x) be defined from x=0x = 0.

Returns

IEnumerable<Element>

Exceptions

ArgumentException
If the curve is 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(IReadOnlyList<Element> elements, ComputationSettings settings)

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(IReadOnlyList<Sequence> sequences, ComputationSettings settings)

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(IReadOnlyList<Element> elements, ComputationSettings settings)

Parameters

elements IReadOnlyList<Element>

settings ComputationSettings

Returns

List<Element>

UpperEnvelope(IReadOnlyList<Sequence>, ComputationSettings)

Computes the lower envelope of the set of sequences given.

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

Parameters

sequences IReadOnlyList<Sequence>

settings ComputationSettings

Returns

IReadOnlyList<Element>