set/difference
Difference of two sets (stable insertion order)
Usage
D:=set/difference(A, B)D:=A∖B
Description
Computes the difference of two sets A and B, returning elements that appear in A
but not in B.
The implementation wraps a Rust IndexSet difference iterator, so the result
preserves stable insertion order:
Elements are returned in the order they appear in A, excluding those also in B.
Input
Arguments:
A : set of T (or array treated as a set; duplicates ignored)
B : set of T (or array treated as a set; duplicates ignored)
Element type constraints:
T must be hashable and comparable for equality (Eq + Hash in Rust).
Common scalar kinds: integers, strings, symbols, booleans.
Output
Result:
D : set of T containing elements in A but not in B, preserving A’s order.
Examples
Simple difference
Numbers
Order is preserved from A
Details
Set semantics:
Inputs are coerced to sets by dropping duplicates.
Only distinct elements present in A but not in B are returned.
Stable insertion order:
Matches Rust IndexSet behavior: difference elements follow A’s order.
Performance:
Average O(|A| + |B|) time with hashing, memory O(|A|) for the result.
Determinism:
Output is deterministic across runs and platforms.
Errors
Incorrect number of arguments (expects two).
Unsupported element type (not hashable or not comparable).
Inconsistent element kinds between A and B.