Skip to content

Store that supports multiplication and addition. #598

@spacecaterpillar

Description

@spacecaterpillar

There are various calculations one would like to do in a streaming fashion that require composition operations.

So while there is a store for accumulation via addition, there is not one for accumulation via multiplication. It turns out that a calculation for average cost basis needs to accumulate with addition for a buy and then multiplication for a sell.

I don't think there's a way we can do that right now without a store that supports a union of operators.

Additionally, on often wants to accumulate fields on a struct, potentially in different ways: struct.cumulative_sum, struct.appended_array, struct.cumulative_product.

Is there a way to support accumulation for custom structs, where we might define how to "combine" the previous and current deltas?

Part of this is that I don't know how critical it is that the operation be reducible within the block. Certainly additions alone are, and multiplications alone are, but once you combine them, the mathematical expression doesn't really reduce. Is that a problem? From the description in the docs, it sounds like you guys just store the abstract operations and cycle through them, so maybe it'd be fine to store operations of different kinds in the same store?

(Some of this comes from a discussion in discord).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions