Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Subject | Re: Cantor pairing... For Moebius... |
|---|---|
| Newsgroups | sci.logic, sci.math |
| References | <110a4bh$bn6d$1@dont-email.me> |
| From | Ross Finlayson <ross.a.finlayson@gmail.com> |
| Date | 2026-06-10 08:55 -0700 |
| Message-ID | <fpGdnX0ncN4vFbT3nZ2dnZfqn_WdnZ2d@giganews.com> (permalink) |
Cross-posted to 2 groups.
On 06/09/2026 03:33 PM, Chris M. Thomasson wrote:
> I tried to code up a quick and dirty way to use Cantor Pairing with
> integers instead of just unsigned. Using a mapping from Moebius in a
> different thread vs traditional unsigned Cantor.
>
> Its funny... His mapping is giving me different numbers for when the
> pair is two positive integers.
> ____________
> ct_cantor_integer::manifest()
> Input Pair: (47, 32)
>
> === Traditional Unsigned Cantor ===
> Resulting Index: 3192
> Unpacked Pair: (47, 32)
> Verification: SUCCESS
>
> === Moebius Interleaved Signed Cantor ===
> Intermediate Nat Index: 12625
> Final Mapping (Z): -6313
> Unpacked Pair: (47, 32)
> Verification: SUCCESS
> ____________
>
>
> Here is 3 and 4:
> ____________
> ct_cantor_integer::manifest()
> Input Pair: (3, 4)
>
> === Traditional Unsigned Cantor ===
> Resulting Index: 32
> Unpacked Pair: (3, 4)
> Verification: SUCCESS
>
> === Moebius Interleaved Signed Cantor ===
> Intermediate Nat Index: 113
> Final Mapping (Z): -57
> Unpacked Pair: (3, 4)
> Verification: SUCCESS
> ____________
>
>
> Okay, here is a run using a pair of (-11, 15)... Traditional Cantor
> Pairing does not like that too much?
>
> Oh it failed, but the integer map worked:
> ____________
> ct_cantor_integer::manifest()
> Input Pair: (-11, 15)
>
> === Traditional Unsigned Cantor ===
> Resulting Index: 25
> Unpacked Pair: (2, 4)
> Verification: FAILED
>
> === Moebius Interleaved Signed Cantor ===
> Intermediate Nat Index: 1356
> Final Mapping (Z): 678
> Unpacked Pair: (-11, 15)
> Verification: SUCCESS
> ____________
>
>
> Here is (42, 42), the both should work:
> ____________
> ct_cantor_integer::manifest()
> Input Pair: (42, 42)
>
> === Traditional Unsigned Cantor ===
> Resulting Index: 3612
> Unpacked Pair: (42, 42)
> Verification: SUCCESS
>
> === Moebius Interleaved Signed Cantor ===
> Intermediate Nat Index: 14280
> Final Mapping (Z): 7140
> Unpacked Pair: (42, 42)
> Verification: SUCCESS
> ____________
>
> Interesting!
>
>
> Fwiw, here is my crude code:
> ________________________________
> // For Moebius
> // Quick and crude Cantor mapper.
> // Works with integers, I think.
> // When all the components are positive I can use
> // traditional Cantor Pairing...
> namespace ct_cantor_integer
> {
> struct cantor_pair
> {
> int m_a;
> int m_b;
> };
>
> // Fold a signed integer Z into a natural number N
> unsigned long long
> fold_z_to_n(
> int z
> ) {
> if (z >= 0)
> {
> return 2ULL * static_cast<unsigned long long>(z);
> }
> else
> {
> long long positive_result = -2LL * static_cast<long
> long>(z) - 1LL;
> return static_cast<unsigned long long>(positive_result);
> }
> }
>
> // Unfold a natural number N back into a signed integer Z
> int
> unfold_n_to_z(
> unsigned long long n
> ) {
> if (n % 2 == 0)
> {
> return static_cast<int>(n / 2ULL);
> }
> else
> {
> return static_cast<int>(-static_cast<long long>((n + 1ULL)
> / 2ULL));
> }
> }
>
> // Pure, traditional unsigned Cantor pairing baseline
> unsigned long long
> traditional_pack(
> unsigned int x,
> unsigned int y
> ) {
> unsigned long long sum = x + y;
> return (sum * (sum + 1ULL)) / 2ULL + y;
> }
>
> // Traditional unsigned Cantor unpacker
> cantor_pair
> traditional_unpack(
> unsigned long long w
> ) {
> unsigned long long t = static_cast<unsigned long
> long>((std::sqrt(static_cast<double>(8ULL * w + 1ULL)) - 1.0) / 2.0);
> unsigned long long tri = (t * (t + 1ULL)) / 2ULL;
> unsigned long long Y = w - tri;
> unsigned long long X = t - Y;
> return { static_cast<int>(X), static_cast<int>(Y) };
> }
>
> // Pack two signed integers into a single unique natural number
> (Moebius phase 1)
> unsigned long long
> pack_pair_signed(
> int a,
> int b
> ) {
> unsigned long long X = fold_z_to_n(a);
> unsigned long long Y = fold_z_to_n(b);
> unsigned long long sum = X + Y;
> return (sum * (sum + 1ULL)) / 2ULL + Y;
> }
>
> // Unpack a single natural number back into a pair of signed
> integers (Moebius phase 2)
> cantor_pair unpack_seed_signed(
> unsigned long long w
> ) {
> unsigned long long t = static_cast<unsigned long
> long>((std::sqrt(static_cast<double>(8ULL * w + 1ULL)) - 1.0) / 2.0);
> unsigned long long tri = (t * (t + 1ULL)) / 2ULL;
> unsigned long long Y = w - tri;
> unsigned long long X = t - Y;
>
> return { unfold_n_to_z(X), unfold_n_to_z(Y) };
> }
>
> void
> manifest()
> {
> std::cout << "ct_cantor_integer::manifest()\n";
>
> // Testing purely positive inputs to allow comparison with
> traditional
> int orig_a = 47;
> int orig_b = 32;
> std::cout << " Input Pair: (" << orig_a << ", " << orig_b <<
> ")\n\n";
>
> //
> =====================================================================
> // TRADITIONAL UNSIGNED CANTOR PIPELINE
> //
> =====================================================================
> unsigned long long trad_index = traditional_pack(orig_a, orig_b);
> cantor_pair trad_recovered = traditional_unpack(trad_index);
>
> std::cout << " === Traditional Unsigned Cantor ===\n";
> std::cout << " Resulting Index: " << trad_index << "\n";
> std::cout << " Unpacked Pair: (" << trad_recovered.m_a
> << ", " << trad_recovered.m_b << ")\n";
>
> if (trad_recovered.m_a == orig_a && trad_recovered.m_b ==
> orig_b) {
> std::cout << " Verification: SUCCESS\n\n";
> }
> else {
> std::cout << " Verification: FAILED\n\n";
> }
>
> //
> =====================================================================
> // MOEBIUS INTERLEAVED SIGNED PIPELINE
> //
> =====================================================================
> unsigned long long moebius_nat_index = pack_pair_signed(orig_a,
> orig_b);
> int moebius_final_integer = unfold_n_to_z(moebius_nat_index);
>
> // Reverse the mapping pipeline entirely
> unsigned long long moebius_recovered_nat =
> fold_z_to_n(moebius_final_integer);
> cantor_pair moebius_recovered_pair =
> unpack_seed_signed(moebius_recovered_nat);
>
> std::cout << " === Moebius Interleaved Signed Cantor ===\n";
> std::cout << " Intermediate Nat Index: " <<
> moebius_nat_index << "\n";
> std::cout << " Final Mapping (Z): " <<
> moebius_final_integer << "\n";
> std::cout << " Unpacked Pair: (" <<
> moebius_recovered_pair.m_a << ", " << moebius_recovered_pair.m_b << ")\n";
>
> if (moebius_recovered_pair.m_a == orig_a &&
> moebius_recovered_pair.m_b == orig_b) {
> std::cout << " Verification: SUCCESS\n";
> }
> else {
> std::cout << " Verification: FAILED\n";
> }
> }
> }
> ________________________________
>
>
> any thoughts? Thanks everybody! :^)
Why not typedef "unsigned long long" as "ull"?
Why not figure out what operator overloads would make sense as an
arithmetization and then just use the plain syntax of arithmetic?
Why not bind a thread-local streams handle to make it so that
std::cout is not concrete for just plain "out"?
Why not make for something that's not static casts where it appears
that the use of static_cast loses precision or overflow?
Why not call this "Galileo pairing" since it was already around for
hundreds of years?
Back to sci.math | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Cantor pairing... For Moebius... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-09 15:33 -0700
Re: Cantor pairing... For Moebius... Ross Finlayson <ross.a.finlayson@gmail.com> - 2026-06-10 08:55 -0700
Re: Cantor pairing... For Moebius... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-15 15:14 -0700
Re: Cantor pairing... For Moebius... Ross Finlayson <ross.a.finlayson@gmail.com> - 2026-06-15 20:56 -0700
Re: Cantor pairing... For Moebius... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-16 13:32 -0700
Re: Cantor pairing... For Moebius... Ross Finlayson <ross.a.finlayson@gmail.com> - 2026-06-17 07:47 -0700
Re: Cantor pairing... For Moebius... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-17 20:48 -0700
Re: Cantor pairing... For Moebius... Ross Finlayson <ross.a.finlayson@gmail.com> - 2026-06-17 23:54 -0700
Re: Cantor pairing... For Moebius... Ross Finlayson <ross.a.finlayson@gmail.com> - 2026-06-18 00:21 -0700
Re: Cantor pairing... For Moebius... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-18 04:50 -0700
Re: Cantor pairing... For Moebius... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-18 04:57 -0700
Re: Cantor pairing... For Moebius... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-18 05:06 -0700
Re: Cantor pairing... For Moebius... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-18 05:34 -0700
Re: Cantor pairing... For Moebius... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-06-18 05:18 -0700
csiph-web