Tuply singleton v3 (with proof)

In my previous post, I had a different approach to Tuply singleton.

This is the third and last post in the Tuply singleton series. We will provide mathematical proof for correctness, and also show a generalized formula.

We will now show the mathematical proof for Tuply singleton v2. The gist of the proof is that we will consider two pairs, and we’ll be using the least nonzero difference of the second element of each pair and show that it will always be bigger than the constraint we added to the first element of each pair.

We’re trying to prove (a,b) = (u,v) \iff a=u \land b=v for a, u \in \mathbb{R}, b, v \in \mathbb{N}.

  • \Leftarrow: Suppose a=u \land b=v. Then 2^a \cdot 33^b = 2^u \cdot 33^v and we’re done.
  • \Rightarrow: Suppose (a,b) = (u,v), i.e. 2^a \cdot 33^b = 2^u \cdot 33^v. If we take \log_2 of both sides, we get:
    \begin{aligned} \log_2{2^a} + \log_2{33^b} = \log_2{2^u} + \log_2{33^v} \\ a \log_2{2} + b \log_2{33} = u \log_2{2} + v \log_2{33} \\ a + b \log_2{33} = u + v \log_2{33} \\ a - u = (v - b) \log_2{33} \end{aligned}

    Note that a, u must be in [0,5] \subset \mathbb{R}. Thus, the maximal difference a - u allowed is 5. Also note that \log_2 33 = 5.04\ldots > 5.

    Now, suppose that v - b = 1. Then a - u = \log_2{33} > 5, which isn’t allowed. Thus the difference is too large. And b, v are integers, so the only smaller difference is when v - b = 0, which implies a = u \land b = v.

Now our Tuply singleton formula can further be generalized to just (a, b) = a + kb with the following constraints: a \in \mathbb{R}, b \in \mathbb{N}, 0 \leq a \leq n – some upper bound n, k \in \mathbb{R} \land k > n.

Validity:

> isFormulaValid (\x1 x2 -> x1 + 5.1 * fromIntegral x2))
True
> isFormulaValid (\x1 x2 -> x1 + 5 * fromIntegral x2))
False

Haskell code:

mkFuns
  :: Integer
     -> Double
     -> (Double -> Integer -> Double, Double -> Double,
         Double -> Integer)
mkFuns n k = if k <= fromIntegral n then error "k must be > n" else (mkPair, fst', snd')
    where
    mkPair :: Double -> Integer -> Double
    mkPair a b = if a > k || a < 0 then error "Out of bounds" else a + fromIntegral (n * b)
    fst' :: Double -> Double
    fst' x = if x > fromIntegral n then fst' (x - fromIntegral n) else x
    snd' :: Double -> Integer
    snd' x = round $ (x - fst' x) / fromIntegral n

And finally, usage:

> let (mkPair, fst', snd') = mkFuns 5 5.1
> fst' $ mkPair 3 7
3.0
> snd' $ mkPair 3 7
7

Thanks to greenbagels from ##math@freenode for their help on the proof.

One thought on “Tuply singleton v3 (with proof)

Leave a comment