File size: 2,236 Bytes
9425aed | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | Object subclass: #QuantumVortex
instanceVariableNames: 'position windingNumber phase energy entangledNeighbors measurementCount creationTime'
classVariableNames: ''
package: 'RBG-FS-Civilization-Primitives'
QuantumVortex >> initialize
super initialize.
position := Array new: 3.
windingNumber := 0.
phase := 0 + 0i.
energy := 0.0.
entangledNeighbors := OrderedCollection new.
measurementCount := 0.
creationTime := Timestamp now.
QuantumVortex >> position: aPosition winding: aWinding phase: aPhase energy: anEnergy
position := aPosition.
windingNumber := aWinding.
phase := aPhase.
energy := anEnergy.
^ self
QuantumVortex >> entangleWith: anotherVortex
(entangledNeighbors includes: anotherVortex) ifFalse: [
entangledNeighbors add: anotherVortex.
anotherVortex entangleWith: self.
"Create entangled state: (|ψ₁⟩ + |ψ₂⟩)/√2"
| combinedPhase |
combinedPhase := (phase + anotherVortex phase) * (1 / 2 sqrt).
phase := combinedPhase.
anotherVortex phase: combinedPhase.
].
QuantumVortex >> applyErrorCorrection
| magnitude |
magnitude := phase abs.
magnitude < 0.1 ifTrue: [
"Phase flip (X gate)"
phase := phase negated.
].
magnitude > 0 ifTrue: [
phase := phase / magnitude.
].
QuantumVortex >> measure
"Born rule: probability = |phase|²"
| prob |
measurementCount := measurementCount + 1.
prob := phase abs squared.
^ (Random next) < prob
QuantumVortex >> phase
^ phase
QuantumVortex >> phase: aPhase
phase := aPhase
QuantumVortex >> energy
^ energy
QuantumVortex >> windingNumber
^ windingNumber
QuantumVortex >> entangledNeighbors
^ entangledNeighbors
QuantumVortex >> printOn: aStream
aStream
nextPutAll: 'QuantumVortex(';
nextPutAll: position printString;
nextPutAll: ', w=';
nextPutAll: windingNumber printString;
nextPutAll: ', phase=';
nextPutAll: phase printString;
nextPutAll: ', E=';
nextPutAll: energy printString;
nextPutAll: ')'.
|