-
-
Save rust-play/7d1d2b91f57c2244352cae037b60d30e to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Exploring Landauer's Principle with Joule and BTU heat dissipation. | |
| use std::f64::consts::LN_2; | |
| const BOLTZMANN_CONSTANT: f64 = 1.380649e_23; | |
| const JOULES_TO_BTU: f64 = 9.4781712e_4; | |
| // --- 1. Logic Gate Definitions --- | |
| #[allow(unused)] | |
| #[derive(Debug, Clone, Copy)] | |
| enum Gate { | |
| And, // Irreversible | |
| Or, // Irreversible | |
| Xor, // Irreversible | |
| Not, // Reversible | |
| Toffoli, // Reversible (CCNOT) | |
| } | |
| impl Gate { | |
| /// Returns the bits of entropy generated (logical erasure) | |
| fn entropy_cost(&self) -> f64 { | |
| match self { | |
| Gate::And | Gate::Or | Gate::Xor => 1.0, | |
| Gate::Not | Gate::Toffoli => 0.0, | |
| } | |
| } | |
| } | |
| // --- 2. Toffoli Implementation (The Reversible Core) --- | |
| #[derive(Debug, PartialEq, Clone, Copy)] | |
| struct State { | |
| c1: bool, | |
| c2: bool, | |
| target: bool, | |
| } | |
| struct ReversibleLogic; | |
| impl ReversibleLogic { | |
| fn toffoli(input: State) -> State { | |
| State { | |
| c1: input.c1, | |
| c2: input.c2, | |
| target: input.target ^ (input.c1 && input.c2), | |
| } | |
| } | |
| } | |
| // --- 3. Thermodynamic Calculator --- | |
| struct PhysicsEngine { | |
| temp_kelvin: f64, | |
| } | |
| impl PhysicsEngine { | |
| fn new(celsius: f64) -> Self { | |
| Self { | |
| temp_kelvin: celsius + 273.15, | |
| } | |
| } | |
| fn calculate_joules(&self, gate: Gate, count: u64) -> f64 { | |
| self.temp_kelvin * BOLTZMANN_CONSTANT * LN_2 * gate.entropy_cost() * (count as f64) | |
| } | |
| fn joules_to_btu(joules: f64) -> f64 { | |
| joules * JOULES_TO_BTU | |
| } | |
| } | |
| fn main() { | |
| let engine = PhysicsEngine::new(70.0); // Typical operating temp | |
| let billion_ops: u64 = 1_000_000_000; | |
| println!("=== LANDAUER'S PRINCIPLE LAB (70°C) ==="); | |
| // Part 1: Standard Logic Gate Comparison | |
| println!("\n[1] Heat Dissipation for 1 Billion Operations:"); | |
| let gates = [Gate::And, Gate::Xor, Gate::Not]; | |
| for gate in gates { | |
| let joules = engine.calculate_joules(gate, billion_ops); | |
| let btu = PhysicsEngine::joules_to_btu(joules); | |
| println!(" - {:?}: {:.4e} Joules | {:.4e} BTU", gate, joules, btu); | |
| } | |
| // Part 2: Toffoli Reversibility Proof | |
| println!("\n[2] Reversible Computing (Toffoli Gate):"); | |
| let test_input = State { | |
| c1: true, | |
| c2: true, | |
| target: false, | |
| }; | |
| let output = ReversibleLogic::toffoli(test_input); | |
| let recovered = ReversibleLogic::toffoli(output); | |
| println!(" Input: {:?}", test_input); | |
| println!(" Output: {:?}", output); | |
| println!(" Reversibility Verified: {}", test_input == recovered); | |
| println!(" Thermodynamic Cost: 0.0 Joules / 0.0 BTU"); | |
| // Part 3: Bitcoin PoW Thermodynamic Floor | |
| println!("\n[3] Bitcoin Hashing Floor (SHA-256):"); | |
| let gates_per_hash = 50_000; | |
| let hashrate_ehs = 700.0; | |
| let network_hashrate = hashrate_ehs * 1e18; | |
| let energy_per_hash_j = engine.calculate_joules(Gate::And, gates_per_hash); | |
| let network_power_watts = energy_per_hash_j * network_hashrate; | |
| // Power (Watts) over one hour to get total energy (Joules) then to BTU | |
| // 1 Watt = 1 Joule/second. 3600 seconds in an hour. | |
| let total_joules_per_hour = network_power_watts * 3600.0; | |
| let btu_per_hour = PhysicsEngine::joules_to_btu(total_joules_per_hour); | |
| println!(" Network Hashrate:\n {} EH/s", hashrate_ehs); | |
| println!(" Theoretical Floor:\n {:.2} Watts", network_power_watts); | |
| println!( | |
| " Heat Output Floor:\n {:.2} BTU/hr (Network-wide)", | |
| btu_per_hour | |
| ); | |
| println!("\n--- Conclusion ---"); | |
| println!("Even a 'perfect' Bitcoin network generates heat. At 700 EH/s, the absolute"); | |
| println!( | |
| "physical minimum heat generation is roughly \n{:.4} BTU every hour.", | |
| btu_per_hour | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment