QuantumSuperposition plays nicely with the companion library
PositronicVariables, which builds temporal convergence and STM-backed updates on
top of QuBit<T>.
What PositronicVariables adds
-
PositronicVariable<T>: time-looping variables whose values are defined
by iterative timelines and convergence until a fixed point (or stable superposition) is reached.
-
NeuralNodule<T>: quantum-flavoured nodes wiring PositronicVariables into
recursive or cyclic networks.
-
STM-backed transactions:
TransactionScope and
TransactionV2 for multi-variable atomic updates, with telemetry covering commits,
retries, aborts and contention.
-
ConvergenceCoordinator and QuantumLedgerOfRegret for serialised,
debuggable convergence loops.
Small paradox example
using PositronicVariables;
var antival = PositronicVariable<int>.GetOrCreate("antival", -1);
Console.WriteLine($"antival = {antival}");
var val = -1 * antival;
Console.WriteLine($"val = {val}");
antival.State = val;
// after convergence: antival ≈ any(-1, 1)
PositronicVariables builds on QuantumSuperposition’s QuBit<T> types, while
QuantumSuperposition happily lives on its own. Same semantics, fewer mental gear changes.
Convergence loop
Convergence is a polite argument with yourself conducted in epochs. Each forward pass proposes values; each reverse pass reconstructs the prior state; small cycles are unified. When the last slice matches a previous one, we declare peace.
var rt = PositronicAmbient.Current; // ensure ambient runtime exists
var a = PositronicVariable<int>.GetOrCreate("a", 0);
var b = PositronicVariable<int>.GetOrCreate("b", 1);
PositronicVariable<int>.RunConvergenceLoop(rt, () =>
{
// Mutual recursion with a small constant offset
a.Assign(b + 1);
b.Assign(a - 1);
}, runFinalIteration: true, unifyOnConvergence: true);
Console.WriteLine($"a: {a}");
Console.WriteLine($"b: {b}");
Epoch tagging keeps slices aligned. Outside-loop writes are quarantined to bootstrap before the next run.
Transactions & STM
Use TransactionV2 for atomic multi-variable updates. Reads validate; writes stage; apply happens at commit under per-variable locks with deterministic ordering. Telemetry recounts every dramatic retry.
var x = PositronicVariable<int>.GetOrCreate("x", 41);
var y = PositronicVariable<int>.GetOrCreate("y", 1);
TransactionV2.RunWithRetry(tx =>
{
tx.RecordRead(x);
tx.RecordRead(y);
var next = x.GetCurrentQBit() + y.GetCurrentQBit(); // QExpr arithmetic
tx.StageWrite(x, (QuBit<int>)next);
});
Console.WriteLine(STMTelemetry.GetReport());
Read-only fast path: if no writes are staged, validation commits without taking write locks.
Reverse replay
Reverse ticks reconstruct the pre-print slice using the operation log (the QuantumLedgerOfRegret). Cross-variable assignments capture small additive deltas k in the forward pass and rebuild scalars accordingly in reverse.
var src = PositronicVariable<int>.GetOrCreate("src", 3);
var dst = PositronicVariable<int>.GetOrCreate("dst", 0);
PositronicVariable<int>.RunConvergenceLoop(PositronicAmbient.Current, () =>
{
// dst follows src + 2, but only src gets logged in forward
dst.Assign(src + 2);
});
Console.WriteLine(dst.ToTimelineString()); // shows reverse reconstruction slices
Edge guards suppress bootstrap union and scalar overwrite during the epoch a cross-reconstruction occurs, keeping causality tidy.
Cross-variable flows
Build networks of constraints across variables. Forward collects intent; reverse restores provenance.
var a = PositronicVariable<int>.GetOrCreate("a", -1);
var b = PositronicVariable<int>.GetOrCreate("b", 0);
var c = PositronicVariable<int>.GetOrCreate("c", 0);
PositronicVariable<int>.RunConvergenceLoop(PositronicAmbient.Current, () =>
{
b.Assign(a + 1); // b trails a by +1
c.Assign(b + 1); // c trails b by +1
a.Required = c - 2; // close the loop as an equality constraint
});
If your loop has multiple consistent answers, the engine will keep both and call it character growth.
Neural nodules
Tiny quantum-aware neurons that accept multiple Positronic inputs, apply an activation function, and write to an output variable. Converge whole networks in one go.
var rt = PositronicAmbient.Current;
var n1 = new NeuralNodule<int>(vals =>
{
var sum = vals.Sum();
return new QuBit<int>(new[] { sum % 5, (sum + 1) % 5 });
}, rt);
var aIn = PositronicVariable<int>.GetOrCreate("aIn", 1);
var bIn = PositronicVariable<int>.GetOrCreate("bIn", 2);
n1.Inputs.Add(aIn);
n1.Inputs.Add(bIn);
NeuralNodule<int>.ConvergeNetwork(rt, n1);
Console.WriteLine($"Neuron output: {n1.Output}");
Timeline & unification
Each write appends or replaces the active slice. Cycles get detected (last equals a previous slice) and can be unified explicitly or automatically.
var v = PositronicVariable<int>.GetOrCreate("v", -1);
PositronicVariable<int>.RunConvergenceLoop(PositronicAmbient.Current, () =>
{
v.Assign((v + 1) % 3); // gentle 0..2 cycle, depending on bootstrap
});
// If you insist on a single slice
v.UnifyAll();
Console.WriteLine(v);
Bootstrap is treated as sacred during a loop; outside writes are scrubbed before the next pass.
Telemetry & diagnostics
The STM layer tracks commits, retries, aborts, validation failures, lock-hold ticks and hotspots. The convergence layer exposes timeline snapshots and a readable ledger of operations.
Console.WriteLine(STMTelemetry.GetReport()); // contention, retries, hot variables
Console.WriteLine(v.ToTimelineString()); // per-slice states
var json = v.ExportToJson(); // take your timeline to a meeting
Concurrency patterns
- Concurrent mutation via transactions (deterministic lock ordering, id-based).
- Convergence loop is single-threaded through a coordinator; outside writes are deferred.
- Ambient state (operator logging suppression) is
AsyncLocal-scoped.
Best practices
- Keep forward writes simple; let reverse replay do the archaeology.
- Prefer
Required for hard constraints and Proposed/Assign for soft influence.
- Quarantine outside-loop experimentation with
NoteOutsideWrites() before convergence runs.
- Use telemetry to identify hotspots, then batch or reorder updates.
NuGet:
PositronicVariables