Felisyn patch 0001: LGN noise in libstdc++'s pair order. Applies to: nest-step-current-module at fe91c0345a602d564a74ebe0ea2c66d9a4157005, on a copy (patch -p1), only for a libc++ build. Approved on 7 Nov 2026 as change (1) of two approved source changes. Reason. NEST 3.4 uses std::normal_distribution, so the C++ library picks the algorithm. libstdc++ 11.5 (the server) and libc++ (this Mac) both run the Marsaglia polar method on the same two uniforms, but libstdc++ returns y and saves x, while libc++ returns u and saves v. Each LGN cell's noise on the Mac is therefore the server's with adjacent time steps exchanged, and the LGN lead-in identity of protocol 023 cannot hold. Evidence: logs/g2.txt, audit-server-dependence.md section 2. Change. normal_dist_ in Variables_ of iaf_cond_exp_sc_nc gets a small wrapper type with the same lifetime and copy behaviour. It does not reimplement the polar method. On a call with nothing held it draws a and b from nest::normal_distribution, holds a and returns b; the next call returns a. The second draw reads libc++'s saved value and touches no engine state, so the engine is consumed exactly as before. aeif_cond_exp_sc_nc has the same draw, but no parameter file names it (logs/rng-census.txt), so it stays unchanged. --- a/src/iaf_cond_exp_sc_nc.h +++ b/src/iaf_cond_exp_sc_nc.h @@ -171,7 +171,44 @@ using nest::GSLSolverFailure; using nest::UnknownReceptorType; +/** + * Normal draws in libstdc++'s pair order, on any C++ library. Felisyn patch 0001. + * + * std::normal_distribution computes each polar pair in one step. libstdc++ returns the second value of the pair + * first and libc++ returns the first value first, so one seed gives adjacent noise steps exchanged. This takes both + * values from nest::normal_distribution and returns them in libstdc++'s order. The second call to dist_ reads the + * value dist_ saved and does not touch the engine, so each pair uses the engine exactly as before. + * Under libstdc++ this wrapper would exchange the pairs, so it belongs only in a libc++ build. + */ +class pair_swapped_normal_distribution +{ +public: + pair_swapped_normal_distribution() + : held_( 0.0 ) + , holding_( false ) + { + } + double + operator()( nest::RngPtr rng ) + { + if ( holding_ ) + { + holding_ = false; + return held_; + } + held_ = dist_( rng ); + holding_ = true; + return dist_( rng ); + } + +private: + normal_distribution dist_; + double held_; + bool holding_; +}; + + class iaf_cond_exp_sc_nc : public nest::ArchivingNode { @@ -353,7 +390,7 @@ { int RefractoryCounts_; - normal_distribution normal_dist_; //!< normal distribution NOISE + pair_swapped_normal_distribution normal_dist_; //!< normal distribution NOISE long dt_steps_; //!< update interval in steps NOISE double omega_; //!< frequency [radian/s] NOISE