Skip to content

engine: DELAY N and SMOOTH N reject any order other than literal 1 or 3 #562

Open

Description

@bpowers

DELAY N and SMOOTH N (DELAYN/SMTHN) only compile when the order argument is the literal 1 or 3.
Any other order, including another literal and an expression of constants, is refused with UnknownBuiltin.
They should support any whole-number order that is fixed for the run.

Example

Output Second Order Delay = DELAY N(Input, Fractional Delay Time, Initial Value, 2)

Refused: "delayn of order 2 is not supported; use order 1 or 3".
A non-literal order is refused too, even when it can only be a constant.
thyroid-2008-d.mdl defines :MACRO: DELAYN(Input,DelayTime,Init,Order) with body DELAY N(Input,DelayTime,Init,Order) and calls it as DELAYN(TSH, tau, TSH, MAX(1, Delay Order)), where Delay Order is a constant slider (0-10).
The macro body is refused because Order is not a literal.

Why it matters

Seen in real models and in fixtures with Vensim output:

  • test/test-models/tests/delay_pipeline/test_pipeline_delays.mdl uses order 2 and has a Vensim DSS output.tab.
  • test/test-models/samples/Population/Subscripted Population Model.mdl uses order 8.
  • test/metasd/thyroid-dynamics/thyroid-2008-d.mdl, above.
    Thyroid also needs DELAY MATERIAL (its PIPELINE macro), a pipeline delay the engine does not have; see engine: DELAY FIXED is refused instead of simulated #346.

Fix

Fold the order argument to a constant at compile time (it may reference only constants), and build an N-stage delay or smooth for that N instead of choosing between the order-1 and order-3 stdlib models.
Thyroid is the hard case: a macro expands as a module, so inside the body Order is a module input, not a constant, and the fold would have to see through the macro call.
Leaving thyroid refused is acceptable if that turns out messy.
An order that varies during the run is refused with a clear error, not supported: whether Vensim even allows one is unverified (vensim.com/documentation/fn_delay_n.html says only that Vensim lowers the order when delay time < order * TIME STEP).

Alternative: per-order stdlib models (delay2, ..., delay10).
Simpler to wire but caps the order and grows the stdlib.

Pointers

Activity

  1. added
    engine
    compat
    on Jun 8, 2026
  2. added
    enhancement
    on Oct 12, 2026
  3. changed the title [-]engine: DELAY N / SMOOTH N require a compile-time-constant order -- non-constant/parameterized order -> UnknownBuiltin (blocks full simulation of thyroid-2008-d and any dynamic-order delay/smooth)[/-] [+]engine: DELAY N and SMOOTH N reject any order other than literal 1 or 3[/+] on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatengineenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions