set/symmetric-difference

Usage

Description

Input

Output

Examples

Simple symmetric difference

Numbers

Order is stable

Details

Errors

set/symmetric-difference

Symmetric difference of two sets (stable insertion order)

Usage

D:=set/symmetric-difference(A, B)D:=AΔB

Description

Computes the symmetric difference of two sets A and B (A Δ B).

The result contains elements that appear in exactly one of the inputs, but not both.

The implementation wraps a Rust IndexSet symmetric difference iterator, so the result

preserves stable insertion order:

  • Elements from A that are not in B come first, in A's order.

  • Then elements from B that are not in A are appended, in B's order.

Input

Arguments:

  • A : set of T (or an array treated as a set; duplicates ignored)

  • B : set of T (or an array treated as a set; duplicates ignored)

Element type constraints:

  • T must be hashable and comparable for equality (Eq and Hash in Rust).

  • Common kinds include integers, strings, symbols, and booleans.

Output

Result:

  • D : set of T containing elements unique to either A or B, preserving order.

Examples

Simple symmetric difference

A:={"a", "b", "c"}B:={"b", "c", "d"}D:=set/symmetric-difference(A, B)

Numbers

A:={1, 2, 3}B:={3, 4, 5}D:=AΔB

Order is stable

A:={"x", "y"}B:={"y", "z"}D:=set/symmetric-difference(A, B)

Details

Set semantics:

  • Inputs are coerced to sets by dropping duplicates using hash and equality.

  • The result contains each distinct element exactly once.

Stable insertion order:

  • Matches Rust IndexSet behavior: order reflects first appearance in A, then B.

Performance:

  • Average O(|A| + |B|) time with hashing; memory is O(|A| + |B|) for the result.

Determinism:

  • Given equal inputs, output order is deterministic across runs and platforms.

Errors

  • Incorrect number of arguments (expects exactly two).

  • Unsupported element type (not hashable or not comparable for equality).

  • Inconsistent element kinds between A and B.