Generating collection queries from proofs
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 queries using products and projections, a singleton-former, and a map operation that lifts queries on tuples to queries 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 formulas φ 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.
READ FULL TEXT