added shiftOperartion and diff

This commit is contained in:
mrFendel 2023-04-11 20:31:04 +03:00
parent a4ca6e3d58
commit 31d1cc774a

View File

@ -199,12 +199,25 @@ public open class SeriesAlgebra<T, out A : Ring<T>, out BA : BufferAlgebra<T, A>
}
}
/**
* Zip buffer with itself, but shifted
* */
public inline fun Buffer<T>.shiftOp(
shift: Int = 1,
crossinline operation: A.(left: T, right: T) -> T
): Buffer<T> {
val shifted = this.moveTo(this.startOffset+shift)
return zip(shifted, operation)
}
override fun Buffer<T>.unaryMinus(): Buffer<T> = map { -it }
override fun add(left: Buffer<T>, right: Buffer<T>): Series<T> = left.zip(right) { l, r -> l + r }
override fun multiply(left: Buffer<T>, right: Buffer<T>): Buffer<T> = left.zip(right) { l, r -> l * r }
public inline fun Buffer<T>.diff(): Buffer<T> = this.shiftOp {l, r -> r - l}
public companion object
}