Skip to content
RUMLRUML

Open Format for Digital Law

6.4 Recursion

6.4 Recursion

Modular nodes MAY contain themselves as a child (recursion). (Rule MOD-02MOD-02 A parser MUST accept a modular node that lists its own LexID in its children (recursion).) This enables modeling of processes with unknown iteration depth, such as contract negotiations.


Structure of Recursive Nodes

A recursive node is a modular node that contains its own lexId in the children array:

"4": {
"id": "7d3f2a91-5c6e-4b8a-9f1d-2e4c6a8b0d13",
"modular": true,
"operator": "XOR",
"label": "Verhandlungsrunde",
"children": [
"5",
"6",
"4" // ← self-reference
]
}

Safe Recursion

Recursion can lead to infinite loops. Safe recursion is ONLY possible when BOTH conditions are met:

  1. The operator of the recursive node is XOR or NOT_XOR
  2. The recursive self-reference is NOT positioned as the first child

Rationale: With XOR/NOT_XOR, evaluation terminates as soon as a child becomes true. If a non-recursive child (exit condition) before the self-reference becomes true, evaluation ends — the recursion is not entered.


Maximum Recursion Depth

Implementations MUST define a maximum recursion depth to prevent infinite loops and MUST return undefined for a node result above the maximum recursion depth.

AspectRequirement
Default maximum500 levels
ConfigurabilitySHOULD be configurable
Behavior on exceedanceNode receives status undefined with a reason of type error (see 5.0); the error is logged

The recursion depth of a node instance counts the self-references on its path: the first instance of a recursive node has depth 0, and each time the node contains itself, the depth grows by 1. In the complete example below:

PathInstanceRecursion depth
1.2Negotiation round (lexId 4), round 10
1.2.3Negotiation round (lexId 4), round 21
1.2.3.3Negotiation round (lexId 4), round 32

With a maximum of n, instances up to depth n are evaluated; an instance at depth n + 1 is the one that receives status undefined. The recursion depth is not the depth of the path: nodes above the recursive node do not count.


Complete Example

Use case: Contract negotiation with any number of rounds

Structure:

Root (AND, lexId: 1)
├── Vertragsfähigkeit geprüft (Leaf, lexId: 2)
└── Verhandlungsrunde (XOR, lexId: 4, modular, recursive)
├── Angebot angenommen (Leaf, lexId: 5)
├── Verhandlung abgebrochen (Leaf, lexId: 6)
└── [Recursion → lexId: 4]

RUML file (static):

"rulemap": {
"nodes": {
"1": {
"id": "b6620b3c-4279-4a45-9115-c8bb2032d868",
"operator": "AND",
"label": "Vertragsabschluss",
"children": ["2", "4"]
},
"2": {
"id": "551ff73a-66ce-48ca-b889-84bc63ce864c",
"label": "Vertragsfähigkeit geprüft",
"capabilities": [
{
"id": "ruml:query",
"payload": {
"expression": "dp_legal_capacity = true"
}
}
]
},
"4": {
"id": "7d3f2a91-5c6e-4b8a-9f1d-2e4c6a8b0d13",
"modular": true,
"operator": "XOR",
"label": "Verhandlungsrunde",
"children": ["5", "6", "4"]
},
"5": {
"id": "6840b48d-117f-474e-ae4e-337b8e60537c",
"label": "Angebot angenommen",
"capabilities": [
{
"id": "ruml:query",
"payload": {
"expression": "dp_offer_accepted = true"
}
}
]
},
"6": {
"id": "0eb360a6-626a-406d-89a1-9f434ced141b",
"label": "Verhandlung abgebrochen",
"capabilities": [
{
"id": "ruml:query",
"payload": {
"expression": "dp_negotiation_cancelled = true"
}
}
]
}
}
}

Evaluation result after two negotiation rounds:

Scenario: First round — no result, second round — offer accepted.

{
"$format": "RUML-Result",
"$specVersion": "1.0",
"rumlReference": {
"id": "ec36948d-fbb2-4815-985a-bd5e9375d934",
"hash": "sha3-256:4e03657aea45a94fc7d9c7e5c89e3f5a2b7c4d8e9f0a1b2c3d4e5f6a7b8c9d0e"
},
"evaluation": {
"id": "20453004-30ad-4a39-9be3-0c687754948f",
"timestamp": "2024-01-15T10:00:00Z",
"mode": "optimized",
"results": {
"1": {
"lexId": "1",
"status": "true",
"reason": "AND: alle Kinder true"
},
"1.1": {
"lexId": "2",
"status": "true",
"reason": "Vertragsfähigkeit bestätigt"
},
"1.2": {
"lexId": "4",
"status": "true",
"reason": "XOR: Kind 1.2.3 ist true (Rekursion betreten)"
},
"1.2.1": {
"lexId": "5",
"status": "false",
"reason": "Angebot nicht angenommen"
},
"1.2.2": {
"lexId": "6",
"status": "false",
"reason": "Verhandlung nicht abgebrochen"
},
"1.2.3": {
"lexId": "4",
"status": "true",
"reason": "XOR: Angebot angenommen (Rekursionsebene 1)"
},
"1.2.3.1": {
"lexId": "5",
"status": "true",
"reason": "Angebot angenommen"
},
"1.2.3.2": {
"lexId": "6",
"status": "ignored",
"reason": {
"type": "shortCircuit",
"trigger": "Knoten 1.2.3.1 wurde true",
"operator": "XOR",
"mode": "optimized"
}
},
"1.2.3.3": {
"lexId": "4",
"status": "ignored",
"reason": {
"type": "shortCircuit",
"trigger": "Knoten 1.2.3.1 wurde true",
"operator": "XOR",
"mode": "optimized"
}
}
}
}
}

Note: The paths 1.2.3, 1.2.3.1, 1.2.3.2 and 1.2.3.3 in the results object are dynamically generated — they are computed at runtime from the tree structure.


UI Representation

Implementations SHOULD visually distinguish recursive nodes:

AspectRecommendation
SymbolSpecial icon to identify recursive nodes
ExpansionClick on symbol opens the next recursion level
Depth indicatorDisplay of the current recursion depth
Maximum warningWarning when approaching the maximum depth

Validation Rules

RuleDescription
Self-reference only with modular: trueA node without modular: true MUST NOT reference itself (Rule MOD-01MOD-01 A node whose LexID appears more than once in the children arrays of the rulemap (a self-reference counts) MUST have modular: true.)
Operator recommendationRecursive nodes SHOULD NOT use the operator AND, NOT_AND, OR, or NOT_OR, as this can lead to potentially unresolvable decision logic
Runtime warningImplementations MUST issue a warning when a recursive node operates with AND, NOT_AND, OR, or NOT_OR. This warning is not cycle detection (depth limit, see Maximum Recursion Depth), but an indication of semantically blocked evaluation (Rule MOD-03MOD-03 A processor MUST warn about a recursive node whose operator is AND, NOT_AND, OR or NOT_OR; the warning alone does not make the file invalid.)
Position of self-referenceThe self-reference MUST NOT be at position 0 in the children array (Rule MOD-04MOD-04 A self-reference MUST NOT be the first entry of children.)
At least one exit conditionRecursive nodes MUST have at least one non-recursive child (Rule MOD-05MOD-05 A recursive node MUST have at least one child that is not a self-reference.)

Note: The validation of these rules is defined in Chapter 8.