Skip to content

Add more built-in arithmetic nodes #153

@xujustinj

Description

@xujustinj

Motivation

The built-in arithmetic set is currently just Add (variadic), Sum (sequence), and Factorization. Composing real workflows with wengine quickly hits missing primitives — you can't subtract, multiply, divide, or round without dropping out of the node graph. This proposes a curated set, designed to match existing conventions.

⚠️ Blocked by #154 (type-union ports). See "Resolved decisions" #4 — the right shape for associative ops is a single variadic node whose input is FloatValue | SequenceValue[FloatValue], which requires union support. Until #154 lands, building these would mean shipping duplicate variadic+sequence nodes per op. Recommend resolving #154 first.

Design conventions to follow

  • Two established shapes: Add is variadic (N scalar inputs a, b, … via a num_arguments param + dynamic_input_type); Sum is sequence (one SequenceValue[FloatValue]).
  • Types: default to FloatValue in/out (Integer→Float casts already exist). Integer-only ops take/return IntegerValue.
  • Required title/description on all fields; auto-derived type discriminator; version 1.0.0.

Proposed nodes

Binary scalar ops (ordered — a, b inputs)

  • Subtracta - bFloatValue.
  • Dividea / bFloatValue.
  • Moduloa % bFloatValue (or integer variant).
  • Powerbase ** exponentFloatValue.

Associative ops (post-#154: single variadic node accepting FloatValue | SequenceValue[FloatValue])

  • Multiply / ProductFloatValue.
  • Min and MaxFloatValue.
  • Mean / AverageFloatValue.

Unary ops

  • Negate-aFloatValue.
  • Abs|a|FloatValue.
  • Round — with optional ndigits param (default 0).
  • Floor / Ceil — → IntegerValue.
  • Sign — → IntegerValue (-1/0/1).

Integer-specific (optional, lower priority)

  • IntegerDivide (a // b), Gcd, LcmIntegerValue in/out.

Resolved decisions

  1. Divide / modulo by zeroraise NodeException with a clear message (do not return inf/NaN). Consistent across both ops.
  2. Empty sequenceMin/Max/Mean raise an error; Product returns 1 (its identity element). (Sum already returns 0 for empty, i.e. additive identity — Product mirrors this with the multiplicative identity.)
  3. Round semantics → expose as a param (e.g. a rounding-mode param: banker's / half-up / etc.) rather than hard-coding, with a sensible default. ndigits is a separate param (default 0).
  4. Variadic vs sequence vs bothblocked by Support type-union ports (e.g. FloatValue | SequenceValue[FloatValue]) #154. With type-union ports we make the param/input type FloatValue | SequenceValue[FloatValue], so the single variadic node also handles sequences and we drop the separate Sum/Product-style duplicates. Until then, this design decision can't be cleanly implemented.

Suggested first slice (highest value, once unblocked)

Subtract, Multiply, Divide, Power, Negate, Abs, Min/Max, Round. The integer-specific ops can follow.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions