3. Foreign Rust References
This chapter previews foreign Rust references backed by a live language-server
lookup. Resolved references render a compact Rust source link and a grouped Rust
code panel fetched from the location returned by rust-analyzer.
- No associated Lean code or declarations.
The Collatz step sends an even number to half of itself and an odd number to
3n + 1.
Rust code for Definition3.1
-
collatz_stepsource
/// Return the next value in the Collatz orbit. pub fn collatz_step(n: u64) -> u64 { if n % 2 == 0 { n / 2 } else { 3 * n + 1 } }
- No associated Lean code or declarations.
The bounded search version measures each orbit and checks a finite prefix of the Collatz conjecture.
Rust code for Definition3.2
-
collatz_total_stopping_timesource
/// Count how long the Collatz orbit of `n` takes to reach `1`. pub fn collatz_total_stopping_time(mut n: u64) -> u64 { let mut steps = 0; while n > 1 { n = collatz_step(n); steps += 1; } steps }
-
collatz_holds_belowsource
/// Check the Collatz conjecture by exhaustive search below a finite bound. pub fn collatz_holds_below(limit: u64) -> bool { for n in 1..=limit { if collatz_total_stopping_time(n) > 10_000 { return false; } } true }
- No associated Lean code or declarations.
Constants and statics live in Rust's value namespace, so the current synthetic lookup strategy resolves them like functions.
- No associated Lean code or declarations.
A mixed attachment keeps the resolved reference and reports the missing one as a warning.
Rust code for Definition3.4
- Resolvedcollatz_step
- Unresolvedcollatz_typo: language server did not return a definition location
-
collatz_stepsource
/// Return the next value in the Collatz orbit. pub fn collatz_step(n: u64) -> u64 { if n % 2 == 0 { n / 2 } else { 3 * n + 1 } }
- No associated Lean code or declarations.
A completely missing Rust symbol produces an unresolved reference without a code panel.
Rust code for Definition3.5
- Unresolvedmissing_collatz_symbol: language server did not return a definition location
- No associated Lean code or declarations.
These names exercise Rust's type namespace. They are included as a live preview of the current synthetic lookup shape, which is still optimized for value references.
Rust code for Definition3.6
-
CollatzRecordsource
/// A small record for Collatz computations. pub struct CollatzRecord { pub start: u64, pub steps: u64, }
-
CollatzParitysource
/// The parity branch selected by one Collatz step. pub enum CollatzParity { Even, Odd, }
-
CollatzMeasuresource
/// A trait shape included to exercise Rust's type namespace. pub trait CollatzMeasure { fn measure(&self) -> u64; }
-
CollatzValuesource
/// A type alias included to exercise Rust's type namespace. pub type CollatzValue = u64;