Nested relations, built up from atomic types via tupling and set types, form a rich data model. Over the last decades the nested relational calculus, NRC, has emerged as a standard language for defining transformations on nested collections. NRC is a strongly-typed functional language which allows building up transformations using products and projections, a singleton-former, and a map operation that lifts transformations on tuples to transformations on sets. In this work we show that NRC has a strong connection with first-order logic: it contains exactly the transformations that are implicitly definable by a theory Σ in first-order logic with quantification suited for nested collections.We also prove an effective variant of our result, providing a procedure that synthesizes an NRC expression in polynomial time from a proof witnessing that Σ provides an implicit definition for one subset of its free variables in terms of another subset of the variables. This synthesis result works off of proofs within an intuitionistic calculus that captures a natural style of reasoning about implicit definability in the context of nested collections.
ACM Subject Classification 500Acknowledgements We are very grateful to Szymon Toruńczyk, who outlined a route to show that implicitly definable transformations over nested relations can be defined via interpretations, in the process conjecturing a more general result concerning definability in multi-sorted logic. Szymon also helped in simplifying the mapping of NRC to interpretations, a basic component in one of our characterizations. We also thank Ehud Hrushovksi, who sketched a proof of the Beth-style result for multi-sorted logic that serves as another component. His proof proceeds along very similar lines to the one we present in the appendix of this submission, but making use of a prior Beth-style result in classical model theory [32].