ebook img

On Two Infinite Families of Pairing Bijections PDF

0.39 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview On Two Infinite Families of Pairing Bijections

1 On Two Infinite Families of Pairing Bijections Paul Tarau Department of Computer Science and Engineering University of North Texas Denton, Texas Email: [email protected] Abstract—We describe two general mechanisms for producing pair- The characteristic-function mechanism, while intuitively obvious, ing bijections (bijective functions defined from N2 → N). The first opens the doors, in combination with a framework providing bijec- mechanism,usingn-adicvaluationsresultsinparameterizedalgorithms tions between them and arbitrary data-types [18], to custom-build generating a countable family of distinct pairing bijections. The second mechanism, using characteristic functions of subsets of N provides arbitrarily intricate pairing functions associated to for instance to 3 2N distinct pairing bijections. Mechanisms to combine such pairing “interesting” sequences of natural numbers or binary expansions of 1 functions and their application to generate families of permutations of [15] real numbers. 0 N are also described. The paper uses a small subset of the functional Wewilluseasubsetofthenon-strictfunctionallanguageHaskell 2 language Haskell to provide type checked executable specifications of (seen as an equational notation for typed λ-calculus) to provide all the functions defined in a literate programming style. The self- n contained Haskell code extracted from the paper is available at http: executabledefinitionsofmathematicalfunctionsonN,pairsinN×N, a //logic.cse.unt.edu/tarau/research/2012/infpair.hs. subsetsofN,andsequencesofnaturalnumbers.Wemention,forthe J Keywords:pairing/unpairingfunctions,datatypeisomorphisms,infinite benefit of the reader unfamiliar with the language, that a notation 1 dataobjects,lazyevaluation,functionalprogramming. like f x y stands for f(x,y), [t] represents sequences of type t and a type declaration like f :: s -> t -> u stands for a ] function f : s×t → u (modulo Haskell’s “currying” operation, S I. INTRODUCTION given the isomorphism between the function spaces s×t → u and M s→t → u). Our Haskell functions are always represented as sets Definition 1: A pairing bijection is a bijection f : N×N → N. s. Its inverse f−1 is called an unpairing bijection. of recursive equations guided by pattern matching, conditional to constraints (simple arithmetic relations following | and before the c Weareemphasizingherethefactthatthesefunctionsarebijections [ = symbol). Locally scoped helper functions are defined in Haskell 1 ainsdtihcaetenainmjeectpivaeirifnugncftuionncstiofrnomis Nso×meNtimtoeNu.sed in the literature to after the where keyword, using the same equational style. The composition of functions f and g is denoted f . g. It is also v Pairingbijectionshavebeenusedinthefirsthalfof19-thcentury customaryinHaskell,whendefiningfunctionsinanequationalstyle 9 by Cauchy as a mechanism to express duble summations as simple (using=)towritef =ginsteadoff x=gx(“point-free”notation). 2 summationsinseries.Theyhavebeenmadefamousbytheirusesin 1 TheuseofHaskell’s“call-by-need”evaluationallowsustoworkwith thesecondhalfofthe19-thcenturybyCantor’sworkonfoundations 0 infinitesequences,likethe[0..]infinitelistnotation,corresponding . of set theory. Their most well known application is to show that to the set N itself. 1 infinitesetslikeNandN×Nhavethesamecardinality.Aclassicuse 0 inthetheoryofrecursivefunctionsistoreducefunctionsonmultiple 3 II. DERIVINGPAIRINGBIJECTIONSFROMn-ADICVALUATIONS argumentstosingleargumentfunctions.Reasonsonwhytheyarean 1 Wefirstoverviewamechanismforderivingpairingbijectionsfrom interesting object of study in terms of practical applications ranging : one-solution Diophantine equations. Let us observe that v from multi-dimensional dynamic arrays to proximity search using i space filling curves are described in [4], [6], [7], [14]. Proposition 1: ∀z∈N+ =N−{0} the Diophantine equation X Like in the case of Cantor’s original function f(x,y) = 1(x+ 2x(2y+1)=z (1) r 2 a y)(x+y+1)+y,pairingbijectionshavebeenusuallyhand-crafted by putting to work geometric or arithmetic intuitions. has exactly one solution x,y∈N. This follows immediately from the unicity of the decomposition of While it is easy to prove (non-constructively) that there is an a natural number as a multiset of prime factors. Note that a slight uncountable family of distinct pairing bijections, we have not seen modification of equation 1 results in the pairing bijection originally in the literature general mechanisms for building families of pairing bijectionsindexedbyNor2N.Itiseveneasiertogenerate(construc- introducedin[3],[8],seenasamappingbetweenthepair(x,y)and z. tively) a countable family of pairing functions simply by modifying 2x(2y+1)−1=z (2) its result of a fixed pairing function with a reversible operation (e.g XOR with a natural number, seen as the index of the family). Wewillgeneralizethismechanismtoobtainafamilyofbijections This paper introduces two general mechanisms for generating between N×N and N+ (and the corresponding pairing bijections such families, using n-adic valuations (section II) and characteristic betweenN×NandN)bychoosinganarbitrarybasebinsteadof2. functions of subsets of N (section III), followed by a discussion of Definition 2: Givenanumbern∈N, n>1,then-adicvaluation related work (section IV) and our conclusions (section V). of a natural number m is the largest exponent k of n, such that nk We will give here a glimpse of why our arguably more complex divides m. It is denoted ν (m). n pairing bijections are interesting. Note that the solution x of the equation (1) is actually ν (z). This 2 Then-adicvaluationbasedpairingfunctionswillprovideageneral suggestderivingsimilarDiophantineequationsforanarbitraryn-adic mechanism for designing strongly asymmetric pairing functions, valuation. We start by observing that the following holds: where changes in one of the arguments have an exponential impact Proposition 2: ∀b ∈ N,b > 1,∀y ∈ N if ∃q,m such that b > on the result. m>0,y=bq+m, then there’s exactly one pair (y(cid:48),m(cid:48)), b−1> 2 m(cid:48) ≥ 0 such that y(cid:48) = (b−1)q+m(cid:48) and the function associating nAdicUnPair:: N→N→(N,N) (y(cid:48),m(cid:48)) to (y,m) is a bijection. nAdicUnPair b n=nAdicDeCons b (n+1) Proof:y=bq+m,b>m>0canberewrittenasy−q−1= bq−q+m−1,b>m>0,orequivalentlyy−q−1=(b−1)q+ nAdicPair:: N→(N,N)→N (m−1),b>m>0fromwhereitfollowsthatsettingy(cid:48) =y−q−1 nAdicPair b xy=(nAdicCons b xy)-1 andm(cid:48) =m−1ensurestheexistenceandunicityofy’andm’such One can see that we obtain a countable family of bijections f : b thaty(cid:48) =(b−1)q+m(cid:48) andb−1>m(cid:48) >0.Wecanthereforedefine N×N→N indexed by b∈N, b>1. a function f that transforms a pair (y,m), such that y = bq+m The following examples illustrate the work of these bijections for with b>m>0, into a pair (y(cid:48),m(cid:48)), such that y(cid:48) =q(b−1)+m(cid:48) b = 3. Note the use of Haskell’s higher-order function “map”, that withb−1>m(cid:48) ≥0.Notethatthetransformationworksalsointhe applies the function nAdicUnPair 3 to a list of elements and opposite direction with y(cid:48) =y−q−1 giving y =y(cid:48)+q+1, and collects the results to a list, and the special value “it”, standing withm(cid:48) =m−1givingm=m(cid:48)+1.Thereforef isabijection. for the previously computed result. Proposition 3: ∀b ∈ N,b > 1, ∀z ∈ N,z > 0 the system of *InfPair> map (nAdicUnPair 3) [0..7] Diophantine equations and inequations [(0,0),(0,1),(1,0),(0,2),(0,3),(1,1),(0,4),(0,5)] bx∗(y(cid:48)+q+1)=z (3) *InfPair> map (nAdicPair 3) it [0,1,2,3,4,5,6,7] y(cid:48) =(b−1)q+m(cid:48) (4) 1) Deriving bijections between N and [N]: For each base b>1, b−1>m(cid:48) ≥0 (5) wecanalsoobtainapairofbijectionsbetweennaturalnumbersand listsofnaturalnumbersin termsofnAdicHead,nAdicTailand has exactly one solution x,y(cid:48) ∈N. nAdicCons: Proof: Let f−1 be the inverse of the bijection f defined in Proposition 2. Then f−1 provides the desired unique mapping, that nat2nats:: N→N→[N] givesy=y(cid:48)+q+1andm=m(cid:48)−1suchthatb>m>0.Therefore nat2nats _ 0=[] y≡m(modb)withm>0.Andasyisnotdivisiblewithb,wecan nat2nats b n | n>0= nAdicHead b n : nat2nats b (nAdicTail b n) determineuniquelyxasthelargestpowerofbdividingz,x=ν (z). b We implement, for and arbitrary b ∈ N, the Haskell code cor- nats2nat:: N→[N]→N nats2nat _ []=0 responding to these bijections as the functions nAdicCons b and nats2nat b (x:xs)=nAdicCons b (x,nats2nat b xs) nAdicDeCons b, defined between N×N and N+. The following example illustrate how they work: nAdicCons:: N→(N,N)→N nAdicCons b (x,y’) | b>1=(bˆx)∗y where *InfPair> nat2nats 3 2012 q=y’ ‘div‘ (b-1) [0,2,2,0,0,0,0] y=y’+q+1 *InfPair> nats2nat 3 it 2012 nAdicDeCons:: N→N→(N,N) nAdicDeCons b z | b>1 && z>0=(x,y’)where Using the framework introduced in [16], [18] and summarized in hd n=if n ‘mod‘ b>0 then 0 else 1+hd (n ‘div‘ b) theAppendix,wecan“reify”thesebijectionsasEncodersbetween x=hd z naturalnumbersandsequencesofnaturalnumbers(parameterizedby y=z ‘div‘ (bˆx) thefirstargumentofnAdicHeadandnAdicTail).SuchEncoders q=y ‘div‘ b can now be “morphed”, by using the bijections provided by the y’=y-q-1 framework, into various data types sharing the same “information Using nAdicDeCons we define the head and tail projection func- content” (e.g. lists, sets, multisets). tions nAdicHead and nAdicTail: nAdicNat:: N→Encoder N nAdicHead, nAdicTail:: N→N→N nAdicNat k=Iso (nat2nats k) (nats2nat k) nAdicHead b=fst . nAdicDeCons b In particular, for k = 2, we obtain the Encoder corresponding nAdicTail b=snd . nAdicDeCons b to the Diophantine equation (1) The following examples illustrate the operations for base 3: nat ::Encoder N *InfPair> nAdicCons 3 (10,20) nat=nAdicNat 2 1830519 *InfPair> nAdicHead 3 1830519 Thefollowingexamplesillustratetheseoperations,liftedthroughthe 10 frameworkdefiningbijectionsbetweendatatypes,giveninAppendix. *InfPair> nAdicTail 3 1830519 *InfPair> as (nAdicNat 3) list [2,0,1,2] 20 873 Note that nAdicHead n x computes the n-adic valuation of x, *InfPair> as (nAdicNat 7) list [2,0,1,2] ν (x) while the tail corresponds to the “information content” ex- 27146 n tracted from the remainder, after division by ν (x). *InfPair> as nat list [2,0,1,2] n 300 Definition 3: We call the natural number computed by nAdicHead n x the n-adic head of x∈N+, by nAdicTail n *InfPair> as list nat it [2,0,1,2] xthen-adictailofx∈N+ andthenaturalnumberinN+ computed by nAdicCons n (x,y) the n-adic cons of x,y∈N. 2) DerivingnewfamiliesofEncodersandPermutationsofN: For By generalizing the mechanism shown for the equations 1 and 2 each l,k ∈N one can generate a family of permutations (bijections wederivefromnAdicDeConsandnAdicConsthecorresponding f : N → N), parameterized by the pair (l,k), by composing pairing and unpairing bijections nAdicPair and nAdicUnPair: nat2nats l and nats2nat k. 3 nAdicBij:: N → N → N → N list2bins:: [N]→[N] nAdicBij k l=(nats2nat l) . (nat2nats k) list2bins[]=[0] The following example illustrates their work on the initial segment [0..31] of N: list2binsns=f nswhere f []=[] *InfPair> map (nAdicBij 2 3) [0..31] f (x:xs)=(repl x 0)++(1:f xs) where [0,1,3,2,9,5,6,4,27,14,15,8,18,10,12,7,81,41,42, repl n a | n ≤ 0=[] 22,45,23,24,13,54,28,30,16,36,19,21,11] repl n a=a:repl (pred n) a *InfPair> map (nAdicBij 3 2) [0..31] [0,1,3,2,7,5,6,15,11,4,13,31,14,23,9,10,27,63, The function bin2list converts a characteristic function repre- 12,29,47,30,19,21,22,55,127,8,25,59,26,95] sented as bitstrings back to a list of natural numbers. It is easy to see that the following holds: bins2list:: [N] → [N] Proposition 4: bins2listxs=f xs 0 where f [] _=[] (nAdicBij k l)◦(nAdicBij l k)≡id (6) f (0:xs) k=f xs (k+1) f (1:xs) k=k : f xs 0 Asasidenote,suchbijectionsmighthaveapplicationstocryptogra- phy,providedthatamethodisdevisedtogenerate“interesting”pairs TogethertheyprovidetheEncoderbins,thatwewillusetoconnect (k,l) defining the encoding. characteristic functions to various data types. We can derive Encoders representing functions between N bins::Encoder [N] and sequences of natural numbers, parameterized by a (possibly bins=Isobins2listlist2bins infinite) list of nAdicHead / nAdicTail bases, by repeatedly applying the n-adic head, tail and cons operation parameterized by The following examples (where the Haskell library function take the (assumed infinite) sequence ks: is used to restrict execution to an initial segment of an infinite list) illustrate their use: nAdicNats:: [N]→Encoder N nAdicNatsks=Iso (nat2nAdicNatsks) (nAdicNats2natks) *InfPair> list2bins [2,0,1,2] [0,0,1,1,0,1,0,0,1] nat2nAdicNats:: [N]→N→[N] *InfPair> bins2list it nat2nAdicNats _ 0=[] [2,0,1,2] nat2nAdicNats (k:ks) n | n>0= nAdicHead k n : nat2nAdicNatsks (nAdicTail k n) *InfPair> take 20 (list2bins [0,2..]) [1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0] nAdicNats2nat:: [N]→[N]→N *InfPair> bins2list it nAdicNats2nat _ []=0 [0,2,4,6] nAdicNats2nat (k:ks) (x:xs)= The following holds: nAdicCons k (x,nAdicNats2natks xs) Proposition 5: IfM isasubsetofN,thebijectionas bins set For instance, the Encoder nat’ corresponds to ks defined as the returns the bitstring associated to M and its inverse is the bijection infinite sequence starting at 2. as set bins. nat’ ::Encoder N Proof: Observe that the transformations are the composition of nat’=nAdicNats[2..] bijections between bitstrings and lists and bijections between lists and sets. The following examples illustrate the mechanism: The following example illustrates this correspondence: *InfPair> as nat’ list [2,0,1,2] *InfPair> as bins set [0,2,4,5,7,8,9] 1644 [1,0,1,0,1,1,0,1,1,1] *InfPair> as list nat’ it *InfPair> as set bins it [2,0,1,2] [0,2,4,5,7,8,9] *InfPair> map (as nat’ nat) [0..15] [0,1,2,3,4,7,6,5,8,19,14,15,12,13,10,9] Note that, for convenient use on finite sets, the functions do not *InfPair> map (as nat’ nat) [0..15] add the infinite stream of 0 digits indicating its infinite stream of [0,1,2,3,4,7,6,5,8,19,14,15,12,13,10,9] non-members, but we will add it as needed when the semantics of Note that functions like as nat’ nat illustrate another general thecoderequiresitforrepresentingaccuratelyoperationsoninfinite mechanism for defining permutations of N. sequences. We will use the same convention through the paper. III. PAIRINGBIJECTIONSDERIVEDFROMCHARACTERISTIC B. Splitting and merging bitstrings with a characteristic function N FUNCTIONSOFSUBSETSOF GuidedbythecharacteristicfunctionofasubsetofN,represented Westartbyconnectingthebitstringrepresentationofcharacteristic as a bitstring, the function bsplit separates a (possibly infinite) functionstoourbijectivedatatransformationframework(overviewed sequence of numbers into two lists: members and non-members. in the Appendix). bsplit:: [N] → [N] → ([N], [N]) A. The bijection between lists and characteristic functions of sets bsplit _ []=([],[]) bsplit[] (n:ns)= Thefunctionlist2binsconvertsasequenceofnaturalnumbers error("bspiltprovidesnoguidanceat: "++(show n)) intoacharacteristicfunctionofasubsetofNrepresentedasastring bsplit(0:bs) (n:ns)=(xs,n:ys) where of binary digits. The algorithm interprets each element of the list (xs,ys)=bsplitbs ns as the number of 0 digits before the next 1 digit. Note that infinite bsplit(1:bs) (n:ns)=(n:xs,ys) where sequences are handled as well, resulting in infinite bitstrings. (xs,ys)=bsplitbs ns 4 GuidedbythecharacteristicfunctionofasubsetofN,represented Proposition 6: If {an}n∈N is an infinite sequence of bits con- as a bitstring, the function bmerge merges two lists of natural taining only finite blocks of 0 and 1 digits, genericPair bins numbersintoone,byinterpretingeach1inthecharacteristicfunction and genericUnPair bins define a family of pairing bijections as a request to extract an element of the first list and each 0 as a parameterized by {an}n∈N. request to extract an element of the second list. Proof: Having an alternation of finite blocks of 1s and 0s, ensures that, when called from genericPair and bmerge:: [N] → ([N], [N]) → [N] bmerge _ ([],[])=[] genericUnPair, the functions bmerge and bsplit terminate. bmergebs ([],[y])=[y] bmergebs ([x],[])=[x] For instance, Morton codes [4] are derived by using a stream of bmergebs ([],ys)=bmergebs ([0],ys) alternating 1 and 0 digits (provided by the Haskell library function bmergebs (xs,[])=bmergebs (xs,[0]) cycle) bmerge(0:bs) (xs,y:ys)=y : bmergebs (xs,ys) bmerge(1:bs) (x:xs,ys)=x : bmergebs (xs,ys) bunpair2=genericUnpairbins (cycle[1,0]) bpair2=genericPairbins (cycle[1,0]) The following examples (trimmed to finite lists) illustrate their use: and working as follows: *InfPair> bsplit [0,1,0,1,0,1] [10,20,30,40,50,60] ([20,40,60],[10,30,50]) *InfPair> map bunpair2 [0..10] *InfPair> bmerge [0,1,0,1,0,1] it [(0,0),(1,0),(0,1),(1,1),(2,0), [10,20,30,40,50,60] (3,0),(2,1),(3,1),(0,2),(1,2),(0,3)] *InfPair> map bpair2 it C. Defining pairing bijections, generically [0,1,2,3,4,5,6,7,8,9,10] We design a generic mechanism to derive pairing functions by Proposition 7: If {an}n∈N is an infinite sequence of non- combining the data type transformation operation as with the decreasingnaturalnumbers,thefunctionsgenericPair setand bsplit and bmerge functions that apply a characteristic function genericUnPair setdefineafamilyofpairingbijectionsparam- encoded as a list of bits. eterized by {an}n∈N. genericUnpair::Encoder t → t → N → (N, N) Proof: Given that the sequence is non-decreasing, it represents genericUnpairxEncoderxs n=(l,r) where canonically an infinite set such that its complement is also infinite, bs=asbinsxEncoderxs represented as a non-decreasing sequence. Therefore, the associated ns=asbinsnat n characteristic function will have an alternation of finite blocks of 1 (ls,rs)=bsplitbs ns and 0 digits, inducing a pairing/unpairing bijection. l=as natbinsls The bijection bpair k and its inverse bunpair k are derived r=as natbinsrs from a set representation (implicitly morphed into a characteristic function). genericPair::Encoder t → t → (N, N) → N genericPairxEncoderxs (l,r)=n where bpair k=genericPairset [0,k..] bs=asbinsxEncoderxs bunpair k=genericUnpairset [0,k..] ls=asbinsnat l rs=asbinsnat r Note that for k = 2 we obtain exactly the bijections bpair2 ns=bmergebs (ls,rs) and bunpair2 derived previously, as illustrated by the following n=as natbinsns example: Let us observe first that for termination of this functions depends *InfPair> map (bunpair 2) [0..10] on termination of the calls to bsplit and bmerge, as illustrated [(0,0),(1,0),(0,1),(1,1),(2,0),(3,0), by the following examples: (2,1),(3,1),(0,2),(1,2),(0,3)] *InfPair> genericPair bins (cycle [0]) (10,20) *InfPair> map (bpair 2) it [0,1,2,3,4,5,6,7,8,9,10] ˆCInterrupted. *InfPair> genericUnpair bins (cycle [1]) 42 We conclude with a similar result for lists: (ˆCInterrupted. Proposition 8: If{an}n∈N isaninfinitesequenceofnaturalnum- In this case, the characteristic functions given by cycle [0] or bersonlycontainingfiniteblocksof0s,thefunctionsgenericPair cycle [1]wouldtriggeraninfinitesearchforanon-existingfirst list and genericUnPair list define a family of pairing 1 or 0 in bsplit and bmerge. bijections parameterized by {an}n∈N. Clearly, this suggests restrictions on the acceptable characteristic Proof:ItfollowsfromProp.7byobservingthatsuchsequences functions. are transformed into infinite sets represented as non-decreasing se- Wewillnowgivesufficientconditionsensuringthatthefunctions quences. genericUnpair and genericPair terminate for any values of The Appendix discusses a few more examples of such pairing their last arguments. Such restrictions, will enable them to define functionsandvisualizesafewspace-fillingcurvesassociatedtothem. familiesofpairingfunctionsparameterizedbycharacteristicfunctions Proposition 9: Thereare2N pairingfunctionsdefinedusingchar- derived from various data types. acteristic functions of sets of N. Definition 4: We call bloc of digits occurring in a characteristic Proof:Observethatacharacteristicfunctioncorrespondingtoa function any (finite or infinite) contiguous sequence of digits. subset of N containing an infinite bloc of 0 or 1 digits necessarily Note that an infinite bloc made entirely of 0 (or 1) digits can only ends with the bloc. Therefore, by erasing the bloc we can put such occurattheendofthesequencedefiningthecharacteristicfunction, functionsinabijectionwithafinitesubsetofN.Giventhatthereare i.e. only if it exists a number n such that the index of each member onlyacountablenumberoffinitesubsetsofN,thecardinalityofthe of the bloc is larger than n. set of the remaining subsets’ characteristic functions is 2N. 5 IV. RELATEDWORK [7] Bongki Moon, H.v. Jagadish, Christos Faloutsos, and Joel H. Saltz. Analysis of the clustering properties of the hilbert space-filling curve. Pairing functions have been used in work on decision problems IEEE Transactions on Knowledge and Data Engineering, 13:124–141, as early as [3], [8], [10]–[13]. There are about 19200 Google 2001. documentsreferringtotheoriginal“Cantorpairingfunction”among [8] Jozef Pepis. Ein verfahren der mathematischen logik. The Journal of which we mention the surprising result that, together with the SymbolicLogic,3(2):61–76,jun1938. successorfunctionitdefinesadecidablesubsetofarithmetic[2].An [9] Stephen Pigeon. Contributions a` la compression de donne´es. Ph.d. thesis,Universite´ deMontre´al,Montre´al,2001. extensive study of various pairing functions and their computational [10] Julia Robinson. General recursive functions. Proceedings of the propertiesispresentedin[1],[14].Theyarealsorelatedto2D-space AmericanMathematicalSociety,1(6):703–718,dec1950. filling curves (Z-order, Gray-code and Hilbert curves) [4]–[7]. Such [11] Julia Robinson. A note on primitive recursive functions. Proceedings curves are obtained by connecting pairs of coordinates correspond- oftheAmericanMathematicalSociety,6(4):667–670,aug1955. ing to successive natural numbers (obtained by applying unpairing [12] Julia Robinson. Finite generation of recursively enumerable sets. Proceedings of the American Mathematical Society, 19(6):1480–1486, operations). They have applications to spatial and multi-dimensional dec1968. database indexing [4]–[7] and symbolic arbitrary length arithmetic [13] JuliaRobinson. Recursivefunctionsofonevariable. Proceedingsofthe computations [19]. Note also that bpair 2 and bunpair 2 are AmericanMathematicalSociety,19(4):815–820,aug1968. the same as the functions defined in [9] and also known as Morton- [14] Arnold L. Rosenberg. Efficient pairing functions - and why you codes, with uses in indexing of spatial databases [6]. shouldcare. InternationalJournalofFoundationsofComputerScience, 14(1):3–17,2003. [15] N.J.A.Sloane.TheOn-LineEncyclopediaofIntegerSequences.2010. V. CONCLUSION publishedelectronicallyatwww.research.att.com/∼njas/sequences. We have described mechanisms for generating countable and [16] Paul Tarau. A Groupoid of Isomorphic Data Transformations. In uncountable families of pairing / unpairing bijections. The mecha- J. Carette, L. Dixon, C. S. Coen, and S. M. Watt, editors, Intelligent Computer Mathematics, 16th Symposium, Calculemus 2009, 8th Inter- nism involving n-adic valuations is definitely novel, and we have nationalConferenceMKM2009,pages170–185,GrandBend,Canada, high confidence (despite of their obviousness) that the characteristic July2009.Springer,LNAI5625. function-based mechanisms are novel as well, at least in terms of [17] Paul Tarau. Declarative Combinatorics: Isomorphisms, Hylomor- their connections to list, set or multiset representations provided by phisms and Hereditarily Finite Data Types in Haskell, January 2009. theimplicituseofourbijectivedatatransformationframework[16]. Unpublished draft, http://arXiv.org/abs/0808.2953, updated version at http://logic.cse.unt.edu/tarau/research/2010/ISO.pdf,150pages. Given the space constraints, we have not explored the natural [18] Paul Tarau. “Everything Is Everything” Revisited: Shapeshifting Data extensions to more general tupling / untupling bijections (defined Types with Isomorphisms and Hylomorphisms. Complex Systems, between Nk and N) as well as bijections between finite lists, (18):475–493,2010. sets and multisets that can be derived quite easily, using the data [19] Paul Tarau and David Haraburda. On Computing with Types. In Proceedings of SAC’12, ACM Symposium on Applied Computing, PL transformation framework given in the Appendix. For the same track,pages1889–1896,RivadelGarda(Trento),Italy,March2012. reasonswehavenotdiscussedspecificapplicationsofthesefamilies of pairing functions, but we foresee interesting connections with possible cryptographic uses (e.g “one time pads” generated through APPENDIX intricate combinations of members of these families). An Embedded Data Transformation Language Theabilitytoassociatesuchpairingfunctionstoarbitrarycharac- teristic functions as well as to their equivalent set, multiset, list rep- We will describe briefly the embedded data transformation lan- resentationsprovidesconvenienttoolsforinventingandcustomizing guage used in this paper as a set of operations on a groupoid of pairing/unpairingbijections,aswellastherelatedtupling/untupling isomorphisms. We refer to ( [16], [17]) for details. bijectionsandthosedefinedbetweennaturalnumbersandsequences, The Groupoid of Isomorphisms: We implement an isomorphism sets and multisets of natural numbers. between two objects X and Y as a Haskell data type encapsulating We hope that our adoption of the non-strict functional language a bijection f and its inverse g. Haskell (freely available from haskell.org), as a complement to f =g−1 conventional mathematical notation, enables the empirically curious X ............................................................................................................................................................................................................................................................................................... Y reader to instantly validate our claims and encourage her/him to ....................................................................................................................g..................=.........................f.............−...............1.................................................................................................... independently explore their premises and their consequences. We will call the from function the first component (a section in categorytheoryparlance)andthetofunctionthesecondcomponent(a REFERENCES retraction)definingtheisomorphism.Theisomorphismsarenaturally [1] PatrickCegielskiandDenisRichard.Onarithmeticalfirst-ordertheories organized as a groupoid. allowingencodinganddecodingoflists.TheoreticalComputerScience, 222(12):55–75,1999. dataIso a b=Iso (a→b) (b→a) [2] PatrickCe´gielskiandDenisRichard. DecidabilityoftheTheoryofthe Natural Integers with the Cantor Pairing Function and the Successor. from (Iso f _)=f Theor.Comput.Sci.,257(1-2):51–77,2001. [3] LaszloKalmar. OntheReductionoftheDecisionProblem.FirstPaper. AckermannPrefix,ASingleBinaryPredicate. TheJournalofSymbolic to (Iso _ g)=g Logic,4(1):1–9,mar1939. [4] J.LawderandP.King. Usingspace-fillingcurvesformulti-dimensional compose:: Iso a b → Iso b c → Iso a c indexing. In Brian Lings and Keith Jeffery, editors, Advances in compose (Iso f g) (Iso f’ g’)=Iso (f’ . f) (g . g’) Databases,volume1832ofLectureNotesinComputerScience,pages 20–35.SpringerBerlin/Heidelberg,2000. itself=Iso id id [5] J.K.LawderandP.J.H.King.Queryingmulti-dimensionaldataindexed using the hilbert space-filling curve. SIGMOD Rec., 30:19–24, March invert (Iso f g)=Iso g f 2001. [6] JonathanLawder. Theapplicationofspace-fillingcurvestothestorage and retrieval of multi-dimensional data, 2000. PhD Thesis, University Assuming that for any pair of type Iso a b, f ◦g = idb and ofLondon,UK. g◦f =ida, we can now formulate laws about these isomorphisms. 6 The data type Iso has a groupoid structure, i.e. the compose Examples of pairing functions derived from characteristic functions operation, when defined, is associative, itself acts as an identity The function syracuse is used in an equivalent formulation of element and invert computes the inverse of an isomorphism. the Collatz conjecture. Interestingly, it can be computed using the The Hub: Sequences of Natural Numbers: To avoid defining nAdicTail which results after dividing a number n with µ (n). 2 n(n−1) isomorphisms between n objects, we choose a Hub object Note that we derive our pairing function directly from the list 2 to/from which we will actually implement isomorphisms. representation of the range of this function as genericPair and Choosing a Hub object is somewhat arbitrary, but it makes sense genericUnpair implicitly construct the associated characteristic to pick a representation that is relatively easy convertible to various function. others and scalable to accommodate large objects up to the runtime syracuse:: N→N system’s actual memory limits. syracuse n=nAdicTail 2 (6∗n+4) We will choose as our Hub object sequences of natural numbers. We will represent them as lists i.e. their Haskell type is [N]. nsyr 0=[0] nsyr n=n : nsyr (syracuse n) type N=Integer typeHub=[N] syrnats=mapsyracuse[0..] We can now define an Encoder as an isomorphism connecting an object to Hub syrpair=genericPairlistsyrnats syrunpair=genericUnpairlistsyrnats typeEncoder a=Iso a Hub Figures1and2showthe“Z-order”(Mortoncode)pathconnecting togetherwiththecombinator“as”,providinganembeddedtransfor- successive values in the range of the function bunpair 2 and mationlanguageforroutingisomorphismsthroughtwoEncoders. bunpair 3. Figures 3 and 4 show the path connecting the values in the range of unpairing functions associated, respectively to the as ::Encoder a → Encoder b → b → a Syracuse function and the binary digits of π. Interestingly, at a asthatthis x=g x whereIso _ g= first glance, some regular patterns emerge even in the case of such composethat (invertthis) notoriously irregular characteristic functions. The combinator “as” adds a convenient syntax such that converters between A and B can be designed as: a2b x = as B A x b2a x = as A B x a2b=as B A A ............................................................................................................................................................................................................................................................................................... B ............................................................................................................................................................................................................................................................................................... ...........................................................................a...............................−.....................................1..................................a..........................b..........................2..............................a..................................................................=............... as.............................................................A..............................................................B..............................b..........................................b..........................−...................................1........................................................................................................ Hub Given that [N] has been chosen as the root, we will define our sequence data type list simply as the identity isomorphism on sequences in [N]. list::Encoder [N] list=itself Fig.1. Pathconnectingvaluesofbunpair 2 TheEncodermsetformultisetsofnaturalnumbersisdefinedas: mset::Encoder [N] mset=Isomset2listlist2mset mset2list, list2mset:: [N]→[N] mset2listxs=zipWith(-) (xs) (0:xs) list2msetns=tail (scanl (+) 0 ns) The Encoder set for sets of natural numbers is defined as: set ::Encoder [N] set=Isoset2listlist2set set2list, list2set:: [N]→[N] list2set=(mappred) . list2mset . (mapsucc) set2list=(mappred) . mset2list . (mapsucc) Note that these converters between lists, multisets and sets make no assumptionaboutfinitenessoftheirargumentsandthereforetheycan usedinanon-strictlanguagelikeHaskelloninfiniteobjectsaswell. 7 Fig.2. Pathconnectingvaluesofbunpair3 Fig.3. PathconnectingvaluesofanunpairingbijectionbasedontheSyracuse function Fig. 4. Path connecting values of an unpairing bijection based on binary digitsofπ

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.