Repository navigation
Expand file tree
/
Copy pathProgram.vb
More file actions
152 lines (123 loc) · 6.02 KB
/
Copy pathProgram.vb
File metadata and controls
152 lines (123 loc) · 6.02 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
Option Strict On
Option Explicit On
Option Infer On
Imports System
Imports System.Collections.Generic
''' <summary>
''' Immutable 3-bit stack-allocated state vector for modeling logically reversible transformations.
''' </summary>
Public ReadOnly Structure TriBitState
Implements IEquatable(Of TriBitState)
Public ReadOnly A As Boolean
Public ReadOnly B As Boolean
Public ReadOnly C As Boolean
Public Sub New(a As Boolean, b As Boolean, c As Boolean)
Me.A = a
Me.B = b
Me.C = c
End Sub
''' <summary>
''' Universal Reversible Toffoli Gate (CCNOT): (A, B, C) -> (A, B, C XOR (A AND B)).
''' Because the Toffoli gate is an involution (self-inverse), applying it twice
''' deterministically recovers the exact original state with zero information loss.
''' </summary>
Public Function ApplyToffoli() As TriBitState
Return New TriBitState(A, B, C Xor (A And B))
End Function
''' <summary>
''' Reversible Controlled-NOT Gate (CNOT) on bits (A, B): (A, B, C) -> (A, B XOR A, C).
''' </summary>
Public Function ApplyCnot() As TriBitState
Return New TriBitState(A, B Xor A, C)
End Function
''' <summary>
''' Reversible NOT Gate on target bit C: (A, B, C) -> (A, B, NOT C).
''' </summary>
Public Function ApplyNotC() As TriBitState
Return New TriBitState(A, B, Not C)
End Function
Public Overloads Function Equals(other As TriBitState) As Boolean Implements IEquatable(Of TriBitState).Equals
Return A = other.A AndAlso B = other.B AndAlso C = other.C
End Function
Public Overrides Function Equals(obj As Object) As Boolean
If TypeOf obj Is TriBitState Then
Return Equals(DirectCast(obj, TriBitState))
End If
Return False
End Function
Public Overrides Function GetHashCode() As Integer
Return HashCode.Combine(A, B, C)
End Function
Public Shared Operator =(left As TriBitState, right As TriBitState) As Boolean
Return left.Equals(right)
End Operator
Public Shared Operator <>(left As TriBitState, right As TriBitState) As Boolean
Return Not left.Equals(right)
End Operator
Public Overrides Function ToString() As String
Return $"({Convert.ToInt32(A)}, {Convert.ToInt32(B)}, {Convert.ToInt32(C)})"
End Function
End Structure
''' <summary>
''' Audits Shannon entropy loss and calculates the physical Landauer heat dissipation floor
''' for irreversible vs. logically reversible operations.
''' </summary>
Public Module Program
' Exact 2019 SI Boltzmann constant (J/K)
Public Const BoltzmannConstant As Double = 1.380649E-23
' Shannon conditional entropy H(X|Y) erased by a 2-input irreversible AND/OR gate
' under uniform input distribution: (3/4) * log2(3) bits
Private ReadOnly IrreversibleTwoInputGateEntropyBits As Double = 0.75 * Math.Log2(3.0)
''' <summary>
''' Computes Landauer's minimum thermodynamic heat dissipation: E_min = N * k_B * T * ln(2).
''' </summary>
Public Function CalculateMinimumHeatJoules(erasedBits As Double, temperatureKelvin As Double) As Double
If erasedBits < 0.0 Then Throw New ArgumentOutOfRangeException(NameOf(erasedBits), "Erased bits cannot be negative.")
If temperatureKelvin <= 0.0 Then Throw New ArgumentOutOfRangeException(NameOf(temperatureKelvin), "Temperature must be above absolute zero (0 K).")
Return erasedBits * BoltzmannConstant * temperatureKelvin * Math.Log(2.0)
End Function
''' <summary>
''' Verifies bijective (one-to-one) state mapping across all 8 states of the 3-bit Toffoli gate.
''' </summary>
Public Function VerifyToffoliBijection() As Boolean
Dim outputs As New HashSet(Of TriBitState)()
For i As Integer = 0 To 7
Dim a As Boolean = (i And 4) <> 0
Dim b As Boolean = (i And 2) <> 0
Dim c As Boolean = (i And 1) <> 0
Dim inputState As New TriBitState(a, b, c)
Dim forwardState As TriBitState = inputState.ApplyToffoli()
Dim recoveredState As TriBitState = forwardState.ApplyToffoli()
If inputState <> recoveredState Then
Return False
End If
outputs.Add(forwardState)
Next
' A bijective mapping over 8 states must produce 8 unique output states
Return outputs.Count = 8
End Function
Public Sub Main(args As String())
Console.WriteLine("=== Landauer Principle & Reversible Logic Engine (VB.NET) ===")
Console.WriteLine()
' 1. Demonstrate single state forward & inverse execution
Dim initial As New TriBitState(True, True, False)
Dim forward As TriBitState = initial.ApplyToffoli()
Dim reversed As TriBitState = forward.ApplyToffoli()
Console.WriteLine($"Initial State : {initial}")
Console.WriteLine($"Toffoli Out : {forward} (0 bits erased)")
Console.WriteLine($"Inverse Out : {reversed} (Exact state recovered)")
Console.WriteLine()
' 2. Exhaustive truth-table bijectivity audit
Dim isBijective As Boolean = VerifyToffoliBijection()
Console.WriteLine($"Exhaustive 8-State Bijection Audit Passed: {isBijective}")
Console.WriteLine()
' 3. Thermodynamic comparison across operating temperatures (10^9 irreversible AND gates)
Dim operationCount As Double = 1_000_000_000.0
Dim totalErasedBits As Double = operationCount * IrreversibleTwoInputGateEntropyBits
Console.WriteLine($"Irreversible Entropy Lost (10^9 AND ops): {totalErasedBits:N2} bits")
Console.WriteLine($" @ 300 K (Room Temp) : {CalculateMinimumHeatJoules(totalErasedBits, 300.0):E4} J")
Console.WriteLine($" @ 77 K (Liquid Nitrogen) : {CalculateMinimumHeatJoules(totalErasedBits, 77.0):E4} J")
Console.WriteLine($" @ 4 K (Cryogenic) : {CalculateMinimumHeatJoules(totalErasedBits, 4.0):E4} J")
Console.WriteLine($" Reversible Toffoli Engine : {CalculateMinimumHeatJoules(0.0, 300.0):E4} J")
End Sub
End Module