-
Notifications
You must be signed in to change notification settings - Fork 0
Quantum
A quantum mechanical system whose state is unknown until observed.
@propertyWrapper public struct Quantum<State: Hashable>At any point in time, a system is in a state. It takes an event to move a system from a state at one point in time to another state at the next point in time. For a classical mechanical system, it is possible to predict the present state if its past states and movements are known (determinism), and vice versa (reversibility). On the contrary, for a quantum mechanical system, it is impossible to predict its state at any point in time; its present state is unknown until observed. Similarly, an event that moves a quantum mechanical system from one state to another is not known to have happened until observed.
A quantum mechanical system can be created directly, via one of Quantum's initialisers.
var quantumText = Quantum(initialState: "wave–particle duality")Or, it can be create by annotating @Quantum to the declaration of a variable of a Hashable-conforming type.
@Quantum
var schrödingersNumber = 0A Quantum instance's present state can be observed via its measurement computed property, and a @Quantum-wrapped variable can be observed reading it directly or via any getter.
print(quantumText.measurement)
// Prints "wave–particle duality", the only possible state at this point in time.
print(schrödingersNumber)
// Prints 0, the only possible state at this point in time.Under the surface, a Quantum instance is represented by a rooted tree of events, where the root is the earliest observed event (the initialisation of the instance). The tree starts with a chain of observed events that ends at the latest observed event, which branches into trees of unobserved events. The latest observed event of a Quantum instance can be accessed directly, and all other events can be accessed via it:
let latestObservedTextEvent = quantumText.latestObservedEvent
let earliestObservedTextEvent = earliestObservedTextEvent.earliestObservedEvent
let latestObservedNumberEvent = $schrödingersNumber.latestObservedEvent
let nextUnobservedNumberEvents = latestObservedNumberEvent.immediatelySucceedingUnobservedEventsA system can arrive at a state through many possible chains of events; many events can move the system to the same state. Although, only one chain would have happened on observation, if the system was indeed in the state.
One event-chain may contain another event-chain, because a system's states may repeat. However, events never form a loop or cycle, because the arrow of time flies unidirectionally.
When a quantum mechanical system moves from all its possible but unobserved states to a (new) possible state A, it's said that the system is superposed on A. When such a superposition happens, all unobserved events not already resulting in A in the event-tree, along the latest observed event, branch off with new and distinct events moving the system to A. A Quantum instance can move to a new possible state via the superpose(on:) method, and @Quantum-wrapped variables can be moved through any setter or assignment:
quantumText.superpose(on: "uncertainty principle")
// At this point in time, quantumText.measurement has
// 50% probability for "wave–particle duality",
// and 50% "uncertainty principle".
quantumText.superpose(on: "optical comb")
// At this point in time, quantumText.measurement has
// 25% probability for "wave–particle duality",
// 25% "uncertainty principle",
// and 50% "optical comb".
$schrödingersNumber.superpose(on: 1)
// At this point in time, schrödingersNumber has
// 50% probability for 0,
// and 50% 1.
schrödingersNumber = 2
// At this point in time, schrödingersNumber has
// 25% probability for 0,
// 25% 1,
// and 50% 2.Additionally, a quantum mechanical system can be moved from one particular possible but unobserved state B to a different state C. With such a movement, only B, instead of the entire system, is superposed on C. Because there are many possible event-chains that lead to B, all unobserved events moving the system to B must branch off with new and distinct events moving the system to C. This kind of state-specific superposition is possible through superpose(_:on:):
quantumText.superpose("uncertainty principle", on: "potential barrier")
// At this point in time, quantumText.measurement has
// 25.0% probability for "wave–particle duality",
// 12.5% "uncertainty principle",
// 25.0% "optical comb",
// and 12.5% "potential barrier".
$schrödingersNumber.superpose(2, on: 3)
// At this point in time, schrödingersNumber has
// 25% probability for 0,
// 25% 1,
// 25% 2,
// and 25% 3.Although a quantum mechanical system's present state is unknown until observed, the probability distribution for the outcome of measuring the system at its present state is known. This information is accessible through the outcomeProbabilities computed property:
print(quantumText.outcomeProbabilities)
// Prints '["wave–particle duality": 0.25, "uncertainty principle": 0.125, "optical comb": 0.25, "potential barrier": 0.125]'.
print($schrödingersNumber.outcomeProbabilities)
// Prints "[0: 0.25, 1: 0.25, 2: 0.25, 3: 0.25]".Once a quantum mechanical system is observed, and before it's moved again, the present state's probability distribution is the observed state at 100% probability:
print(quantumText.measurement)
// Prints "optical comb", one of the possible states.
print(quantumText.outcomeProbabilities)
// Prints '["optical comb": 1]'
print(schrödingersNumber)
// Prints 0, one of the possible states.
print($schrödingersNumber.outcomeProbabilities)
// Prints "[0: 1]"public typealias Event = QuantumEvent<State>Creates a quantum mechanical system with the given initial state.
public init(initialState: State)- initialState: The initial state of the system.
Creates the quantum mechanical system with the given initial wrapped state.
public init(wrappedValue: State)- wrappedValue: The initial wrapped state of the system.
var wrappedValue: Statevar projectedValue: SelfThe final one in the chain of observed events.
var latestObservedEvent: EventThis event moved the system to its latest observed state.
The probability distribution for the outcome of measuring the system at its present state.
var outcomeProbabilities: [State: Double]The state the system is in.
var measurement: StateAccessing this property is equivalent to observing the system.
Superposes the system's all possible states on the given state.
@inlinable public mutating func superpose(on state: State)This superposition works by branching off all unobserved events not already resulting in state in the event-tree, along the latest observed event, with new and distinct events that move the system to state.
- state: The given state to superpose on.
Superposes one of the system's possible states on the given state.
@inlinable public mutating func superpose(_ possibleState: State, on nextState: State)This superposition works by branching off all unobserved events moving the system to possibleState with new and distinct events moving the system to nextState.
- possibleState: The possible state of the system to superpose on the given state.
- nextState: The given state to superpose on.
Creates a new quantum mechanical system from the superposition of this system on the given state.
@inlinable public func superposed(on state: State) -> Self- state: The given state to superpose on.
A new quantum mechanical system equivalent to the superposition of this system on the given state.
Generated at 2021-04-02T07:17:41+0000 using swift-doc 1.0.0-beta.5.