The Deductive Spreadsheet
The Deductive Spreadsheet
Iliano Cervesato
The
Deductive
Spreadsheet
Cognitive Technologies
123
Iliano Cervesato
Carnegie Mellon University
School of Computer Science
Doha, Qatar
Managing Editors
Dov M. Gabbay Jörg Siekmann
Augustus De Morgan Professor of Logic Forschungsbereich Deduktions- und
Department of Computer Science Multiagentensysteme
King’s College London DFKI
London, UK Saarbrücken, Germany
Nowadays, data are more easily accessible than ever, yet support for deriving
interesting consequences from base data is often unavailable, too expensive, or too
technical for many users. For example, a student may have access to prerequisite
listings and expected offering dates of courses but have no way to sieve through
possible course sequences unless the college provides a dedicated tool. Similarly,
an investor may know the instruments held in his or her mutual fund portfolio but
have no easy way to unravel them and reveal his exposure to a specific industry or
company. As an additional example, a secretary in a midsize company will typically
need to juggle clients and transportation schedules by hand into an itinerary for her
boss’s forthcoming business trip. In all cases, manually inferring useful information
from raw data is time-consuming and error-prone, a situation that often results in
bad decisions, suboptimal plans, or missed opportunities.
The problem is not the lack of automated tools: databases are all about relating
data, financial service firms will happily use their software to dissect one’s portfolio
in any desired way, and a plethora of scheduling and workflow applications are
available for purchase. Yet individuals, small and medium enterprises, and even
small departments in large companies rarely avail themselves of such products: even
when the purchase price is affordable, there is an associated financial and cognitive
training cost, often quite large. Indeed, the secretary may be unknowingly querying
databases all day long, but setting one up may go well beyond her training. There is
no simple and general application that empowers users to compute useful inferences
on raw data.
This book addresses this problem by drawing inspiration from a type of
automated data inference that is immensely popular: the spreadsheet. Applications
such as Microsoft Excel and Google Spreadsheet are readily available and allow
users to routinely perform complex custom calculations on numerical data. The
spreadsheet’s clever interface makes it easy to use productively with little or no
training and its gentle learning curve allows users to reinforce their skills and
acquire new ones in a learning-by-doing fashion. However, none of the above data
manipulation problems is expressible in today’s spreadsheets. The approach investi-
gated here remedies this situation by extending the spreadsheet paradigm to enable
vii
viii Preface
developments in most of these areas but also learn how to reach out to adjoining
and distant fields to achieve a multidisciplinary focus. Practitioners will find fully
developed solutions to numerous problems that are not solvable using a traditional
spreadsheet application or not easily solvable with them. They will then be able to
either enter them in a forthcoming deductive spreadsheet application or to use the
provided insight to program them.
xi
Contents
1 Introduction .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 1
1.1 Deductive Decision-Making . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 3
1.2 Target Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 4
1.3 Drawbacks of Existing Solutions .. . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 5
1.3.1 Spreadsheets . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 5
1.3.2 Logic Programming . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 6
1.3.3 Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 9
1.3.4 Task-Specific Tools . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 10
1.4 Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 10
1.4.1 The Deductive Engine .. . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 11
1.4.2 The User Interface .. . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 13
1.5 A More Elaborate Example .. . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 14
1.6 Related Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 17
1.6.1 Logics and Spreadsheets . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 18
1.6.2 Beyond Logical Spreadsheets .. . . . . . . . .. . . . . . . . . . . . . . . . . . . . 20
1.7 Work Plan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 22
2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 25
2.1 Functional Requirements . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 25
2.2 Cognitive Requirements . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 28
2.3 Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 30
xiii
xiv Contents
3.4 Explanation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 53
3.5 Summary .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 53
4 The Relational Spreadsheet .. . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 55
4.1 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 55
4.1.1 Generic Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 57
4.1.2 Spreadsheet Arrays . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 58
4.1.3 Array Operators . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 59
4.1.4 Array Formulas . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 60
4.1.5 Component Expressions . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 60
4.1.6 Spreadsheets with Arrays .. . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 62
4.1.7 Arrays Versus Scalars . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 64
4.2 Relational Support in the Traditional Spreadsheet . . . . . . . . . . . . . . . . . . . 64
4.3 Extending Spreadsheets with First-Class Relations .. . . . . . . . . . . . . . . . . 66
4.3.1 Formalizing Relations . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 67
4.3.2 Relational Operators and Expressions . .. . . . . . . . . . . . . . . . . . . . 71
4.3.3 Relational Spreadsheets.. . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 85
4.3.4 Relational Spreadsheets Versus Relational Databases . . . . . 91
4.4 Evaluation .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 95
4.4.1 Cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 95
4.4.2 Naı̈ve Evaluation .. . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 98
4.4.3 Dependency Graph .. . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 102
4.4.4 Semi-naı̈ve Evaluation .. . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 106
4.5 Updates .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 108
4.5.1 Relation-Level Updates .. . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 108
4.5.2 Incremental Updates of Relations . . . . . . .. . . . . . . . . . . . . . . . . . . . 110
4.5.3 Recalculation Policies . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 114
4.6 Explanation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 115
4.7 Summary .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 116
5 The Logical Spreadsheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 119
5.1 A First-Order Logic Refresher . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 120
5.1.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 120
5.1.2 Model Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 122
5.1.3 Proof Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 122
5.2 The Logic of the Relational Spreadsheet . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 123
5.2.1 Relational Substrate .. . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 124
5.2.2 Relational Algebra as Logic .. . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 127
5.2.3 Stratification .. . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 135
5.3 Inference in a Definite Spreadsheet Theory . . . . . .. . . . . . . . . . . . . . . . . . . . 139
5.3.1 Non-recursive Definite Theories . . . . . . . .. . . . . . . . . . . . . . . . . . . . 139
5.3.2 Herbrand Models. . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 143
5.3.3 Fixpoint Characterization .. . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 144
5.3.4 Computing Fixpoints . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 145
5.3.5 Proof Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 148
Contents xv
Index . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . 401
List of Figures
xix
xx List of Figures
Envisioned in the early 1960s, born in the late 1970s and popularized during the
1980s with the personal computer [Pow03], the spreadsheet is one of the most
ubiquitous computing applications (it has only in recent years been surpassed by
email programs and web browsers). Over 50 million people—secretaries, accoun-
tants, teachers, engineers, officers, managers and many others—rely on it every
day for everything from grocery lists to multimillion dollar transactions [BABC 00].
The vast majority of these users have no or little formal computer science training,
and yet the intuitive interface and clever design of the spreadsheet let them put
together complex computations with a few mouse clicks, instantly turning them
into unaware programmers. This aspect cannot be overemphasized: in almost no
time can a novice user perform simple tasks, and just a few hours of exposure
are sufficient to acquire the skills to perform non-trivial computations over large
amounts of data.1 De facto, the spreadsheet is the tool of choice for non-scientific
numerical computations and decision-making based on numerical data.
However, a large percentage, if not the majority, of the decisions we make every
day depends on information that is not numerical, or not only numerical. Consider
the following simple example from the academic world:
Is a student who has taken ‘Operating Systems’ and ‘Theory of Computation’ qualified to
take ‘Advanced Networking’? If not, what does she need to take first? Would that allow
her to take ‘Advanced Networking’ next semester? If not, what is the earliest date she can
take it?
Answering each of these questions requires logical reasoning. The last also has a
numerical component. Students and courses are symbolic data and they participate
1
I cannot pass on the following anecdote: A friend of mine, a physician by trade, discovered the
personal computer and Excel a few years ago. Within a month, he had entered several years of
financial data for all the stocks he owned, together with various formulas to predict their trend.
He never found the silver bullet that would allow him to beat the market, but he eventually turned
his self-taught Excel skills to medicine and built a sophisticated application to track the cardiac
history of his patients. It is believed that several lives were saved in that way.
in relations that describe what courses a student has taken, what the prerequisites of
a course are, and when courses are offered. Inference rules (not shown here) describe
the reasoning processes that need to be performed to produce the answers. Similar
setups and reasoning tasks routinely take place in many professional and personal
settings: diagnosis of diseases, combat readiness of troops, legal argumentation,
even fashionable color coordination require reasoning patterns akin to the above
example.
For all their merits, spreadsheets as we know them are pretty much useless when
it comes to these forms of symbolic inference: they offer a few logical operators,
but these are designed for simple conditional tests, not deductive reasoning.
Worse, the computer applications that do support these forms of reasoning, logic
programming languages, some databases, and many domain-specific tools, require
a level of sophistication that even many trained programmers do not have. Indeed,
these applications are seldom installed in an end-user’s computing environment.
This leaves a prospective problem-solver to either undergo lengthy training or give
up on automation. This last option often leads to arbitrary, suboptimal, or incorrect
decisions.
Based on these considerations, it is clear that an application supporting sophis-
ticated logical reasoning with the same degree of usability as a spreadsheet would
fill a significant void in the end-user’s computing landscape. Following [Gun04],
we call this tool a deductive spreadsheet, a tool that (quoting)
would allow users to define logic statements and inference rules for symbolic reasoning
in the same way that current spreadsheets allow users to define mathematical formulae for
numerical calculations.
It should be emphasized that this deductive spreadsheet has the same target audience
as what we will call from now on the traditional spreadsheet: those 50C million
managers, officers, engineers, teachers, accountants, secretaries, etc., who do not
have a formal training in either computer science or logic, and yet would welcome
unintimidating automated assistance with their daily reasoning tasks. We speculate
that this enormous market represents a significant business opportunity, but most
importantly the deductive spreadsheet has the same potential to boost productivity
and help people with their daily tasks that made the traditional spreadsheet so
successful.
In this book, we propose an approach to engineering a deductive spreadsheet
that not only meets the reasoning and usability requirements outlined above,
but integrates them seamlessly into the existing spreadsheet paradigm. We postulate
that a deductive extension to the spreadsheet is superior to a separate application for
two reasons: first, many decisions have symbolic and numerical aspects; second, the
distinction between the two may be lost on an entry-level or even intermediate user,
who may never use a separate deductive spreadsheet application for this reason.
This introductory chapter motivates the deductive spreadsheet and outlines our
approach. In Sect. 1.1 we identify three useful classes of reasoning problems that
the deductive spreadsheet should support. In Sect. 1.2, we characterize the target
audience of this tool. In Sect. 1.3 we review existing deductive technology, pointing
1.1 Deductive Decision-Making 3
out drawbacks and taking note of useful features in the spreadsheet context.
We sketch our approach in Sect. 1.4 and demonstrate it on an extended example
in Sect. 1.5. We discuss related work in Sect. 1.6. The concluding Sect. 1.7 outlines
the organization of the remainder of this book.
There are several ways in which logical reasoning can participate in the process of
making a decision. If we think of an automated decision-assistant as an infallible
logical reasoner, here are three of the most useful questions with which a human
decision-maker may consult it:
Yes or no? Given a problem described in terms of facts established to be true
and inference rules that permit making logical deductions from them, determine
whether a given objective is realizable or not. Consider the following example,
adapted from above:
Assume that Sue has taken ‘Operating Systems’ and ‘Theory of Computation’. Assume
also that there is a rule that states that sitting in ‘Advanced Networking’ requires having
taken ‘Operating Systems’, ‘Computer Architecture’ and ‘Basic Networking’. When
asked the question Can Sue take ‘Advanced Networking’?, an automated reasoner will
answer ‘No’.
While this example hardly requires automated assistance in itself, it will typically
be part of an environment comprising hundreds of students, courses and rules,
where establishing course dependencies may require long chains of inference,
and where rules may have exceptions. In this broader context, an automated
decision maker may be not just useful, but necessary.
For which? In the same setting, determine what values make a given objective
realizable. Continuing with this example, when asked the question
What courses does Sue need to take before sitting in ‘Advanced Networking’?
Why? Finally, a user may not be satisfied with just an answer, but may want an
explanation of how that answer was reached:
Here Sue is asking Why do I need to take ‘Computer Architecture’ and ‘Basic
Networking’ before sitting in ‘Advanced Networking’?, and the automated reasoner will
produce the above rule.
Additionally, lawyers, doctors, students, etc., would use it in their daily decisions,
and so would many people for day-to-day activities outside of their profession.
We again agree with [Gun04] in that
If successfully developed, this tool could become a ubiquitous part of everyone’s computing
environment.
We now briefly review existing technologies that embody some of the functionalities
of a deductive spreadsheet, as outlined above. They each have significant inade-
quacies in view of supporting end-users with their logical decision-making needs.
However, some also embed ideas and techniques that are clearly useful in the
deductive spreadsheet. We will point them out as we go, anticipating some of the
aspects of the design in Sect. 1.4.
1.3.1 Spreadsheets
These functionalities and the very constituents of the traditional spreadsheet will be
examined in much greater detail in Chap. 3.
Formulas can also contain cell ranges (also known as arrays) such as “A2:A31”
in “SUM(A2:A31)”. Most commercial spreadsheets also provide a little-known
mechanism by which a formula can evaluate to an array, i.e., produce a value not just
for a single cell, but for multiple cells at once. These array formulas reside in a cell
range: groups of cells can indeed hold a formula. From a programming language
perspective, arrays introduce convenience, but no extra expressive power. Arrays
and array formulas will be examined in more detail in Chap. 4.
The traditional spreadsheet was born as an electronic incarnation of accounting
books, and as such it provides outstanding support for numerical calculation.
However, the closest it has to offer to logical reasoning are the common Boolean
operators AND, OR, NOT, which are intended to be used in the conditions of IF
statements (and even there, their prenex syntax makes for unnecessarily complex
expressions). One can hardly perform any serious reasoning with those.
Because its formulas are drawn from a simple functional language without
recursion, the traditional spreadsheet does not have the computational power to
support the forms of reasoning we are interested in. Note that this limitation is also
what makes spreadsheet calculations always terminate. As we extend the traditional
spreadsheet with support for symbolic reasoning, we shall strive to maintain this
characteristic.
Finally, a formula in a traditional spreadsheet computes a value for the cell it
resides in. We will see that in the case of the deductive spreadsheet, it is more
convenient to associate a logical statement with one or more columns, in general.
In summary, there are a number of reasons why traditional spreadsheets cannot
adequately support the kind of symbolic reasoning envisioned here. On the other
hand, many of the interface design decisions, the powerful support for numerical
calculation, and guaranteed termination are all desirable features for the deductive
spreadsheet.
In summary, Prolog embeds the expressive power we would consider for the
deductive spreadsheet, but it requires too much sophistication for a user to make
effective use of it, and its operational model is not fully compatible with a
spreadsheet environment. Making some top-down reasoning available as an option
for the advanced user is a possibility that requires further evaluation.
However, there is more to logic programming than just Prolog. In this book, we
will pay particular attention to a syntactic fragment of Prolog called Datalog [Ull88].
The example at the beginning of this section is actually written in this language.
In a way, Datalog turns Prolog on its head. Its evaluation strategy is bottom-up:
it starts with the true facts of a logical specification (the relations student,
course, hasTaken and requires in the above example) and uses them to
compute all their immediate consequences according to the given inference rules
(the relation missingReq here). It then uses these derived facts and the inference
rules to compute a second round of consequences (here canTake), and then a
third, and so on until all the logical consequences of the specification have been
discovered. The syntactic restrictions ensure termination, even in the presence of
recursive rules.
Bottom-up evaluation is a good fit for the deductive spreadsheet for several
reasons:
• Termination is guaranteed. This is a desirable property that blends well into the
spreadsheet model.
• It reports all the solutions to a query, without duplicates. It will be convenient
to display them in as many spreadsheet columns as there are variables that
participate in the query.
• Because evaluation always starts from the true facts and not from the query,
Datalog supports evaluating multiple queries at once. Bottom-up evaluation
will compute the answers to all of them simultaneously. This aspect is again
reminiscent of a spreadsheet, where, in general, numerous cells contain formulas
that will be evaluated simultaneously.
• A change in any part of the specification, either a fact or a rule, will cause
immediate re-evaluation and update of all the answers.
For these reasons, we will embrace the Datalog model, bottom-up evaluation in
particular, as one of the pillars of the deductive spreadsheet. An appropriate flavor
of Datalog (indeed, there is a whole family of Datalog languages [RU95]) for this
purpose is investigated in this book.
Datalog has been extensively studied as a foundation for deductive databases
(see next section) and is nowadays used in a broad range of applications [LM03,
GW10, LCGC 06, ARLGC 09, CARGC 12]. We are unaware of any commercial
implementation outside of this context. However, several industrial-strength deduc-
tive databases are available and will contribute to some aspects of the design of the
deductive spreadsheet.
1.3 Drawbacks of Existing Solutions 9
1.3.3 Databases
If we ignore for a moment the possibility of recursive rules, the Datalog specification
we have just described is a very simple relational database [Cod70]: the base facts
(student, course, hasTaken and requires) are tables, with one record for
each instance of the relation; the rules implement derived tables (views), or just
queries if one is interested in evaluating them only once.
The tables for our example are:
The second line gives a name (starting with an uppercase) to each attribute. It can
be observed that this tabular visualization is compatible with the layout of a typical
spreadsheet.
The view corresponding to the rule defining missingReq is given by the
following SQL statement:
CREATE VIEW missingReq(Student,Course,Required) AS
SELECT *
FROM student, requires
WHERE NOT EXISTS (SELECT *
FROM hasTaken
WHERE student.Name = hasTaken.Student
AND requires.Required = hasTaken.Course)
The statement for canTake is similar. Their values could be visualized in a tabular
form, which brings us even closer to the spreadsheet world. We may not expect an
end-user to enter, or even understand, such expressions. However, some database
management systems such as Microsoft Access provide intuitive graphical methods
to construct simple views and queries.
A deductive database extends a relational model with the possibility of defining
views recursively, which corresponds to admitting the recursive inference rules of
Datalog [RU95, Zan99]. Recursion is now part of SQL, the standard database query
language.
There is clearly much inspiration that the design of the deductive spreadsheet can
take from databases, and in particular deductive databases. It would be incorrect,
however, to think that deductive databases already implement all the requirements
of the deductive spreadsheet. Indeed, a database management system is primarily
meant to provide efficient access to large amounts of data that necessarily reside
on secondary storage. This focus forces a certain mind-set on the user of a
10 1 Introduction
database, who must think in terms of keys, indices and relationships: fine-tuning
a database is not trivial. This also imposes limitations on the database management
software itself: for example it is not realistic to update views in real-time in the same
way as changing the value of a cell propagates instantly in a spreadsheet.
In summary, operating a database requires a background and a level of sophistica-
tion that cannot be expected from the target user of the deductive spreadsheet. Some
implementations, such as Microsoft Access, do provide a graphical interface that
simplifies managing and querying the database. This is only a small step toward the
occasional end-user as menus and dialogs still refer to complex database concepts.
On the positive side, deductive databases embed techniques that can be used as a
foundation for the deductive spreadsheet. Major re-engineering is however required
to eliminate unnecessary database-specific features and to implement functionalities
expected of a spreadsheet.
1.4 Approach
• Internally, this extension takes the form of a logic programming language with a
bottom-up evaluation strategy. The deductive and traditional functionalities are
smoothly integrated, so that logical reasoning can apply to cells with calculated
values, and formulas can refer to cells produced by logical inference.
• Externally, an end-user sees an interface nearly identical to that of a tradi-
tional spreadsheet. The proposed extension is conservative, unobtrusive and yet
accessible. Indeed, a user who wants to use the tool as a traditional spreadsheet
is not penalized by the added deductive component. On the other hand, using the
logical extension is natural, even in conjunction with traditional functionalities.
We now refine this preview by anticipating salient aspects of the architecture for the
deductive spreadsheet as developed in the rest of this book.
In Sect. 1.3, we have suggested designing the deductive spreadsheet around a logic
programming environment, and more precisely using a Datalog-like language with
bottom-up evaluation. We now further elaborate on the exact choice of the language
and its execution model.
Language
In its most basic form, Datalog is a very simple fragment of first-order logic
where:
• All values are atomic symbols (e.g., sue and 12 as opposed to sister(sue)
or 12+5).2
• True facts are relations among atomic symbols (e.g., hasTaken(sue,os)).
• Rules have the form “IF a1 AND . . . AND an THEN b”, which states that b can
be deduced to be true whenever all the ai have been shown to be true. Rules can
mention variables for atomic symbols and can be recursive.
Evaluating pure Datalog always terminates, which is why this simple language
played such a prominent role in the research on deductive databases. However, pure
Datalog is so minimal that many common reasoning tasks take unintuitive forms.
For this reason, several extensions have been proposed [RU95]:
2
The language underlying Prolog differs from Datalog by removing all restrictions on the
structure of values: this enables very powerful forms of reasoning, but also the possibility of
non-termination.
12 1 Introduction
• Allow a restricted but natural form of negation in the IF part of the rules. We have
already relied on this in our example.
• Allow values to be not only atomic symbols but restricted sets of atomic symbols
(aggregates).
• Allow arithmetic and other functional operations to appear in a rule.
The first two extensions maintain termination, even when combined. The third does
not in general, but useful terminating classes have been isolated. Altogether, these
extensions are far from the deductive power of full first-order logic, but they add
natural support for several useful forms of reasoning.
In the context of the deductive spreadsheet, guaranteed termination of the
reasoning process is a necessary feature. Indeed, this behavior is consistent with the
calculation of formulas in a traditional spreadsheet, which is very important from
a cognitive point of view. Expert Prolog programmers know how to debug infinite
loops, but end-users experience non-termination only when an application hangs,
an event often followed by a reboot. For this reason, we believe that a (terminating)
idiom of Datalog should constitute the foundation of a basic interaction with the
deductive spreadsheet. Which idiom of Datalog?
We made use of negation in Sue’s example. Adopting a flavor of Datalog
that admits negation (and possibly aggregation) is technically adequate, but can
be cognitively taxing. Going back to our example, navigating through various
negations is unnatural and can be intellectually challenging for users unfamiliar with
logical reasoning. For this reason, we also look at alternative linguistic extensions
to Datalog that support more direct ways of expressing recurrent rules as in
this example. We take inspiration to some recent progress in the theory of logic
programming for this. A key factor in making this choice is the need for a transparent
and intuitive support for explanation.
Embedding numerical formulas within rules may be seen as functionally
redundant since such calculations can always be performed using the traditional
functionalities of a spreadsheet. We believe however that it is cognitively useful as
it allows a closer mapping between the deductive intent of a user and the language
of inference rules.
The benign coexistence and even integration of the traditional formula-based
and the new deduction-based languages in the same application is achieved by
carefully designing the logical extension of the spreadsheet. In our approach, this
is a special case of the problem of combining the paradigms of logic programming
and functional computation, which is the subject of a research area known as
functional-logic programming [Han94].
Execution Model
As we design the deductive spreadsheet, we must never forget that the purpose
of this technology is to assist an end-user with limited computer science and
logic training in his daily reasoning tasks. Therefore, translating these sophisticated
reasoning mechanisms into an intuitive and usable interface is paramount.
We argued above in favor of a conservative and unobtrusive extension of the
excellent interface of a traditional spreadsheet. Moreover, the added functionalities
shall be consistent with existing modalities, and accessing them shall be natural.
The major challenge is to devise elegant graphical modalities for the end-user
to comfortably define and review inference rules. Another important aspect is to
make the integration between the traditional and the deductive components of the
application as seamless as possible.
Figure 1.1 shows the base relations for an extension of Sue’s example as they
appear to a user of the deductive spreadsheet.3 Figure 1.2 simulates instead the
values resulting from executing the shown inferences in a bottom-up fashion.4 Here,
we show relations side by side, but this is not a constraint: they may reside anywhere
on the spreadsheet, even on different sheets. Requiring a relation to consist of
adjacent columns is not necessary either, although probably easier for a user to
work with.
3
This mockup screenshot was produced by inputting the displayed values in Microsoft Excel 2010.
We will base illustrations throughout the book on this and other versions of Excel, and occasionally
of other spreadsheet applications.
4
The inference rules are displayed using Prolog syntax as Excel comments. In Chap. 9, we will
develop a more polished user interface and a concrete syntax for the deductive spreadsheet.
14 1 Introduction
As we design the user interface for the deductive spreadsheet, we follow tested
methodologies to assess proposed solutions against the cognitive requirements
of the user. Techniques stemming from the theory of cognitive dimensions of
notations [GP96] and the attention investment model [Bla02] have been applied with
great success to evaluate the traditional spreadsheet interface and design extensions
of this paradigm [BADC 01, PBB03].
While we propose a design for a user interface of the deductive spreadsheet,
rigorous experimental validation is delegated to future work.
In this section, we give a brief tour of the deductive spreadsheet and the kind of
problems it can solve by means of a small case study. Chapter 6 will expand on both
aspects. This tour will also give a preview of the Datalog-inspired concrete syntax
we will present in Chap. 9.
Consider the following problem: an investor is trying to analyze his portfolio
and plan a new round of investments. He sets up a spreadsheet where he lists each
instrument he owns (stock, bonds, mutual fund, etc.) and how much each is worth
in columns A and B (several Internet tools make it easy to track this data and
even to download it to a spreadsheet). This tabular data is naturally interpreted as
a relation—call it portfolio (commercial spreadsheets allow giving mnemonic
names to cells, ranges and other spreadsheet entities). He also downloads informa-
tion about immediate instruments, specifically their name, type (stocks or bonds)
and sector in columns D, E, F , calling the resulting table immediate. He does
1.5 A More Elaborate Example 15
the same for his mutual funds, for which he records the fund name, its holdings and
the fund’s percentage of each holding in columns H , I , J , calling this third table
funds. The left part of Fig. 1.3 displays how sample data for this example could
appear in an Excel-inspired rendering of the deductive spreadsheet.
One simple thing the investor may want to know is which of his stocks are in
health care companies and how much they are worth, for example. This information
is easily retrievable from his data, yet no commercial spreadsheet supports such a
simple operation. Had he loaded his data in a database instead, a simple relational
query would return the answer, but setting up and querying a database is not as easy
as using a spreadsheet. The deductive spreadsheet gives him the means to compute
this answer directly in his spreadsheet: one way to do so is to select a two-columns
data range, say L3WM11—let us bind it to the mnemonic name healthStocks,
and enter the following Datalog clause (the syntax is an adaptation of Datalog
discussed in Chap. 9).
healthStocks(N,W) IF portfolio(N,W)
AND immediate(N,"stock","health").
Now, how much his health stocks are worth can be computed with the standard
SUM function on the right column of this range—the deductive spreadsheet blends
seamlessly the new logical formulas and the traditional spreadsheet formulas.
The right portion of Fig. 1.3 shows a crude simulation—a more sophisticated
interface is examined in Chap. 9.
A more interesting exercise for this investor is to pick apart his mutual funds and
list all industry sectors he carries in his portfolio. Now, many mutual funds hold just
stocks and bonds as instruments, but some hold shares of other mutual funds. In the
deductive spreadsheet, it is easy to write recursive Datalog clauses that unravel all
funds to their immediate holdings:
fundSector(F,S) IF fund(F,N,_)
AND immediate(N,_,S).
fundSector(F,S) IF fund(F,F’,_)
AND fundSector(F’,S).
Read aloud, fundSector contains the record .F; S / if fund contains .F; N; /
for some N and immediate contains .N; ; S / for the same N , or if fund
contains .F; F 0 ; / and fundSector contains .F 0 ; S / recursively. Here, we have
written “ ” for a field whose value is irrelevant and can therefore be arbitrary in a
record. Situations such as the above, where an entity is made of parts, those parts of
subparts, and so on up to elementary constituents is very common in a number of
industries, from banking to manufacturing, and unraveling all basic constituents is
referred to as the bill of materials problem (see also Chap. 6). Now, the investor can
find his own exposure by sector by selecting just the instruments in his portfolio,
which is achieved through the following clause:
sectorExposure(F,S) IF portfolio(F,_)
AND fundSector(F,S).
It is tempting to modify the above clauses to compute not just the sectors represented
in each fund, but also the percentage of each sector in the fund:
sectPc(F,S,P) IF fund(F,N,P)
AND immediate(N,_,S).
sectPc(F,S,P) IF fund(F,F’,P’)
AND sectPc(F’,S,P’’)
AND P = P’*P’’.
However, by doing so, we have just escaped Datalog, which does not allow
calculated values (here P = P’*P’’) in deduced relations because they under-
mine its most appealing property: necessary termination. The deductive spreadsheet
partially lifts this restriction of Datalog, thereby allowing the above clause, by stop-
ping the recursion after a user-defined bound. To find out the percentage of
his portfolio invested in each sector, the investor would modify the clause for
1.6 Related Work 17
In this section, we outline recent and not-so-recent work related to the concept of
a deductive spreadsheet proposed in this book. We then quickly examine trends in
areas that feed into our design, specifically spreadsheets, logic programming and
databases.
18 1 Introduction
Early Attempts
Surprisingly, this thread of research dried out in the late 1980s in spite of the
gigantic advances in user interfaces and the coming of age of logic programming in
the 1990s. The lone exception is Knowledgesheet [GA00], a system that explored
an alternative way of embedding logical constraints within a spreadsheet.
Recent Developments
5
This interest was evident in the Workshop on Logical Spreadsheets (WOLS’05) held at Stanford
University in the summer of 2005. The presented systems fell into two clear classes: proposals
which allowed the Prolog-style computation of new values from existing values, and systems which
provided support for bidirectional constraints. The design discussed in this book falls into the first
class.
20 1 Introduction
We conclude this section on related work with a brief review of recent developments
in three areas that are most relevant to our work: spreadsheets, logic programming,
and (deductive) databases.
1.6 Related Work 21
Spreadsheets
The spreadsheet was imagined in the early 1960s and first implemented in the late
1970s. It acquired popularity in the 1980s with the personal computer [Pow03] and
for a while it was the most commonly used application on a PC (only recently
surpassed by web browsers and email clients). It is still an indispensable tool for
the vast majority of the users of any computer system [BABC 00]. Recent releases
of commercial spreadsheets have however included relatively little innovation,
which can be seen as the sign of a mature technology. For example, the main
differences between Microsoft Excel 2003 and the previous edition was an improved
coordination within the Office suite, the addition of a few statistical functions
and, sadly, the fix of a large number of security holes. The main updates in the
next version, Excel 2007, were the adoption of an XML-based file format and the
replacement of the formula bar with a context-sensitive “ribbon”, a rather disruptive
change to a user interface that many users had become quite comfortable with.
Around the same time, Google introduced Google Docs, a cloud-based office suite
accessible through any browser. Multiple users could collaborate on a document,
in particular a spreadsheet, from any Internet-enabled computer and in real time,
without having to ever bother emailing files or with software updates. Microsoft
incorporated some of this technology in its latest version, Excel 2010, with further
cloud-integration announced for the next edition, Excel 2013.
The possibility of extending Excel and other spreadsheet applications by means
of custom-made modules called add-ons has fueled a cottage industry of sorts and
numerous extensions are now available, mainly new mathematical functions and
formatting utilities. We are not aware of any such add-on providing the extended
deductive functionalities discussed in this book.
In the shadow of this limited commercial innovation, a lively research community
is busy analyzing the way people use and misuse spreadsheets, and suggesting
improvements (see http://www.eusprig.org for the latest developments). Academic
research has mainly concentrated on measuring and improving the productivity
and usability of spreadsheets as a human-computer interaction problem. A par-
ticular focus has been the high error rate found in spreadsheets [Pan98] and
countermeasures such as auditing [Saj00].
A few researchers have investigated functional extensions to the spreadsheet
paradigm. The inclusion of user-defined functions (as opposed to programmer-coded
add-ons) is studied in great detail in [PBB03]. Other extensions, such as recursion,
floating cells and graphical values are included in the Forms/3 language [BADC 01].
Logic Programming
The main logic programming ideas underlying the proposed design for the deductive
spreadsheet took shape in the golden years of logic programming, from the late
1970s to the mid-1990s. That era brought us the theoretical research underlying
22 1 Introduction
bottom-up evaluation and Datalog, and their practical realization in the deduc-
tive database [RU95, RSS92]. Prolog, top-down evaluation and negation received
considerable attention during this period [SS94].
To a large extent, recent research has focused on broadening the definition of
logic programming [Han94, MNPS91] and then identifying expressive computable
fragments of logics different from the traditional first-order logic of Prolog and
Datalog [CP02,WCPW03]. The results of this research have just started percolating
into the Datalog model [BDM01] and may be useful in future refinements of the
deductive spreadsheet.
In the last 10 years, Datalog has had a resurgence in a variety of domains other
than databases. Indeed, it has been used to specify and enforce fine-grained user
authentication [LM03], to implement network protocols [GW10, LCGC 06], and to
program cyber-physical systems [ARLGC 09], just to cite a few. Differently from
the relatively static databases of the 1980s, these applications are characterized by a
highly dynamic fact base, which requires efficient algorithms to propagate updates
resulting from the assertion of new facts and the retraction of stale facts [ARLGC 09,
CARGC 12, GMS93, LCGC 06] and a logical understanding of the principles they
espouse [LC12, NJLS11].
Deductive Databases
Defined around 1980, Datalog and the idea of a deductive database were for a
long time little more than an academic curiosity [RU95, Zan99]. The development
of industrial-strength prototypes such as CORAL [RSSS94] and LDL [AOTC 03]
turned them into a mainstream technology. Recursive views, the trademark of
deductive databases, have been incorporated into the SQL3 standard, and later into
SQL4.
This book explores a design for the innovative concept of a deductive spreadsheet.
Chapter 2 lays out the requirements for both the underlying deductive apparatus and
the supporting user interface. Each of these two aspects is analyzed in a dedicated
group of chapters which occupy much of this book.
Part I gradually introduces the logical language underlying the deductive spread-
sheet. It starts with a model of the traditional spreadsheet and isolates the closest
these applications have to offer to symbolic reasoning. It then introduces an
extension that includes relational algebra as a bridge to the properly deductive
extension. Pure Datalog and its execution model are then integrated into the
spreadsheet model. The remaining chapters of this part explore useful extensions to
Datalog in the context of a spreadsheet: traditional operations within rules, negation,
1.7 Work Plan 23
aggregation, and native support for hypothetical reasoning. This part of the book is
mathematical in nature and brings together a number of key developments that have
taken place in the last 50 years in various areas of logic and of computer science.
Part II analyzes the alterations of the user interface of a spreadsheet to
accommodate our deductive extension. We begin with a review of the salient
aspects of the user interface of a traditional spreadsheet and immediately propose
an incremental design supporting the proposed deductive functionalities. We then
recall established cognitive methodologies for evaluating interfaces and apply them
in support of our design. We conclude this part with preliminary experiments
aimed at evaluating the reaction of a small group of users to a simulation of our
proposed interface design. This second part of the book is rooted in cognitive
psychology, and is given a less formal treatment than the first. It brings together
several threads of research in the areas of human-computer interaction, interface
design, and evaluation.
The concluding Chap. 11 outlines future development in each of these aspects
and discusses approaches to implementing an application based on this work. It is
followed by an annotated bibliography.
Chapter 2
Requirements
In this chapter, we state the principal requirements for the deductive spreadsheet.
We separate them into functional, regarding the operations supported by the tool,
and cognitive, concerning the user interactions with the tool. We will rely on these
requirements to guide the design of the deductive spreadsheet. They will also be
key in a future implementation of a deductive spreadsheet based on this design.
The former class will be primarily used in Part I where we design the inferential
engine of the tool. The latter will play an important role in Part II, where we extend
the interface of a traditional spreadsheet to provide access to the new deductive
facilities.
We give the functional requirements of the deductive spreadsheet in Sect. 2.1, and
present its cognitive requirements in Sect. 2.2. How to evaluate these requirements
is discussed in Sect. 2.3.
This class of requirements is concerned with the functionalities that the design
makes available. They concentrate on the supported operations and how they interact
among each other. They also assess abstract issues such as expressiveness and
computational cost. These requirements do not encompass the manner in which
functionalities are presented to the user. In particular, design decisions such as
concrete syntax and visual feedback are not discussed here, nor is a method for
evaluating them.
The principal functional requirements for the deductive spreadsheet are described
next.
F2. Expressiveness
The deductive spreadsheet will support yes/no queries, queries returning values, and
explanation. Specifically:
1. The user shall be able to ask for all the values that satisfy a given logical formula.
This encompasses yes/no queries as a special case.
2. Logical inference will return all solutions to these queries without duplicates.
3. The user shall be able to ask why a certain value was returned and the system will
trace the inference back to established facts, both by unfolding the reasoning one
step at a time, and by showing all inferences at once.
4. The user shall similarly be able to ask why a certain value was not returned.
2.1 Functional Requirements 27
F4. Termination
F5. Updates
2. A scalar or array formula shall be able to draw its input from cells whose value
has been deduced by means of a logical inference.
3. A logical formula may embed a scalar or array formula, subject to the constraint
that no other requirement is violated.
4. A scalar or array formula may embed a logical formula, subject to the constraint
that no other requirement is violated.
This class of requirements has to do with the general experience of the user during
his or her daily interactions with a tool. Therefore, issues that are addressed include
the manner in which the graphical interface provides access to the underlying
functionalities, the familiarity with respect to similar applications, and the effort
involved in using the tool and discovering new features.
The principal cognitive requirements of the deductive spreadsheet are listed next.
All traditional functionalities shall be accessible to the user in the exact same way as
in a traditional spreadsheet. The deductive interface shall therefore be conservative
and unobtrusive. In particular:
1. All traditional methodologies for entering data and formulas in a spreadsheet
must be supported by the deductive extension. In particular, values and formulas
can be entered in a cell as text using a keyboard. Formulas can also be entered
using menus and “wizards” in conjunction with cell range selection using the
mouse. The intelligent cut-and-paste functionality shall be available as in the
traditional spreadsheet to iterate formulas to new regions of the spreadsheet.
2. All traditional methodologies to display calculated values and other feedback
shall be supported. This includes the standard tabulated display of calculated
cells, and visual rendering using charts and other graphical methods.
3. The user shall not be penalized by the deductive extension whenever he or she is
not using it. In particular, no time overhead should be incurred when using only
the traditional functionalities of the deductive spreadsheet.
C2. Consistency
The commands supporting the deductive extensions shall be consistent with the
existing modalities of interaction and with the user’s expectation. Therefore:
2.2 Cognitive Requirements 29
1. The user shall be able to enter logical formulas as text using the keyboard.
2. He or she shall also be able to make use of the mouse to select ranges and specific
operations.
3. Menu items and “wizards” shall also be available consistently with the traditional
functionalities.
4. The intelligent cut-and-paste functionality shall be supported and operate on
logical expressions in the same way as for scalar formulas.
5. These commands shall be intuitive and easy to use.
Using the deductive capabilities shall be natural and intuitive, including when used
in conjunction with the traditional functionalities. Specifically:
1. The syntax supporting the deductive functionalities shall be chosen so as to have
an intuitive meaning even for users unfamiliar with logic.
2. The textual and graphical syntax available to access the deductive functionalities
shall be consistent with the input methods for traditional formulas, and similarly
for output.
3. There should be as few barriers as possible preventing a user from embedding
traditional formulas in a deductive expression and vice versa.
C4. Performance
C5. Discovery
The deductive extension should have a gentle learning curve, so that users can rein-
force and extend their skills by simply using the tool and minimal experimentation.
In particular:
30 2 Requirements
2.3 Evaluation
Functional requirements are assessed by checking that the design of the deductive
apparatus meets them. This can be done by inspection for a number of minor
requirements especially when they are not interdependent. Some more theoretical
requirements, such as decidability, are often established in the literature or by
extending arguments found in the literature. Verifying functional requirements that
heavily depend on each other generally involves substantial analysis.
Cognitive requirements need to be assessed empirically and experimentally.
Methodologies to do so abound in the literature. We chose to base our design on two
techniques, the theory of cognitive dimensions of notations [GP96] and the attention
investment model [Bla02], both of which had been applied with good results in other
extensions of the spreadsheet [BADC 01, PBB03]. These techniques are intended to
assist a designer who is not an human-computer interaction expert in the task of
creating a plausible preliminary user interface. An actual evaluation of our design
needs to rely on rigorous empirical assessment methodologies based on predictive
modeling and user testing.
Part I
Deductive Engine
Outline
In the first part of this work, we review a succession of languages and adapt them
to the context of the deductive spreadsheet. Our analysis closely tracks the develop-
ment of Datalog and deductive databases. At the same time, it points to aspects
that do not apply in a spreadsheet and emphasize issues that become crucially
important. For example, the notion of query plays a minor role in the deductive
spreadsheet, which makes the huge body of literature on query optimization largely
irrelevant. On the other hand, real-time update propagation acquires tremendous
importance.
In Chap. 3, we develop a simple model of the traditional spreadsheet. We outline
the structure and operational semantics of this useful tool, with particular emphasis
on the notion of update. This allows us to distill a methodology and a number of
guiding principles for the deductive spreadsheet.
In Chap. 4, we recall basic concepts of relational algebra as used in relational
databases and import them into the spreadsheet model, obtaining what we call
the relational spreadsheet. This relational extension already highlights some of the
differences between databases and spreadsheets, differences that acquire importance
in more complex languages. It also allows us to settle the issue of seamlessly
integrating our extension in the traditional paradigm.
Chapter 5 provides a logical interpretation of the resulting relational spreadsheet
as the non-recursive fragment of a suitable flavor of Datalog enriched with negation
and constraints. The theory of this language is developed into a model that
emphasizes the unique requirements of a spreadsheet. In particular, it provides
a logical account of key spreadsheet functionalities such as evaluation, update
and explanation. A spreadsheet based on this interpretation can already be called
“deductive”, for a very weak notion of deduction.
Chapter 6 defines the deductive spreadsheet proper by adding recursion to this
logical interpretation, hence turning it into a constrained form of Datalog with
negation. This step provides a substantial boost in expressiveness while requiring
32 I Deductive Engine
only small theoretical adjustments. It also enables further extensions, notably the
ability to weave simple lists into the language. The added deductive power, which
includes inferential closure, hypothetical reasoning and some form of aggregation,
is illustrated by way of examples.
Chapter 3
The Traditional Spreadsheet
A B C D E
1 Monday Friday Hours To date Weekly average
2 11/29/04 =A2 +4 8 =C2 =D2/((A2 -A2)/7 + 1)
3 =A2+7 =A3 +4 17 =D2 +C3 =D3/((A3 -A2)/7 + 1)
4 =A3 +7 =A4 +4 25 =D3 +C4 =D4/((A4-A2)/7 + 1)
5
(Entered spreadsheet)
A B C D E
1 Monday Friday Hours To date Weekly average
2 11/29/04 12/03/04 8 8 8.00
3 12/06/04 12/10/04 17 25 12.50
4 12/13/04 12/17/04 25 50 16.67
5
(Evaluated spreadsheet)
maybe), while the remaining values are given by the shown formulas. Column C
records the hours worked each week. Column D contains formulas to display the
cumulative hours worked by the employee. Finally, column E shows the average
number of hours worked weekly. Like many spreadsheets, this example is expected
to grow with time, typically by adding one row each week until employment ends.
We start with a set V of values whose elements we will denote by the letter v,
possibly sub- or superscripted. Values represent what is displayed in a spreadsheet:
strings, various types of numbers (integers, floating point, dates, etc.), error marks,
and more. Formulas are not values, but they produce a value when calculated.
In Fig. 3.1, “Monday”, “11/29/04”, and “8” are examples of values. Within V,
we distinguish the special value [, corresponding to the contents of a blank cell,
and the error value . This model could be extended with additional distinguished
values (undefined, etc.).
The cells of a spreadsheet are referenced by means of a system of locations drawn
from a set L. In Fig. 3.1, as well as in early spreadsheets, locations are simply the
column-row coordinates of a cell (e.g., A2). Nowadays, multiple sheets and external
references add new dimensions and flexibility. We write l, variously decorated,
for locations.
Operators such as “C” and “/” in Fig. 3.1 are used to calculate new values of
interest from the information in other parts of the spreadsheet. We assume a fixed
set Op of operator symbols: this is consistent with all commercial implementa-
tions, none of which provides simple means for a user to define new operators.1
1
To be more precise, a programmer can implement new operators and make them available by
means of add-on modules, something for which an end-user often lacks the know-how. There have
also been recent proposals (e.g., [PBB03]) for operators definable directly by an end-user, which
do not require programming skills, but no such extension is part of any commercial product as
of yet.
3.1 Spreadsheet Model 35
Again, n may be different from op’s arity: an expression will evaluate to in that
case. We denote the set of all expressions by E. Since every value is an expression,
we have that V E. We write e v e 0 for the subexpression relation: it holds if e
occurs within e 0 . For example, “A4 A2” v “D4=..A4 A2/=7 C 1/” in cell E4 of
our example. We write e @ e 0 if e v e 0 and e ¤ e 0 . An expression that is not a value
is called a formula. In most commercial spreadsheets and in the example in Fig. 3.1,
formulas are introduced by the symbol “D” (which is not part of the formula).
A spreadsheet has an expression in every location. It is then natural to view it as a
function s W L ! E. However, not all such functions correspond to spreadsheets as
we commonly understand them. We need to introduce some definitions to precisely
characterize well-formed spreadsheets.
Let s W L ! E be a function from the set L of locations to the set E of
expressions and let E 2 be any binary relation over expressions. The referential
closure of over s is the binary relation s E 2 defined as follows:
• s.l/ s l for all l 2 L;
• e s e 0 if e e 0 ;
• e s e 00 if e s e 0 and e 0 s e 00 .
Then, e @s e 0 simply extends the definition of e @ e 0 to encompass not just the
subexpressions of e 0 , but also the expressions contained in any location l mentioned
in e 0 , and their subexpressions, and the expressions contained in any location they
mention, and so on. In particular, l @s l 0 holds if and only if the value at location l 0
2
More precisely, Excel’s SUM takes up to 30 arguments, each of which can be a range. We ignore
the difference and assume the number of arguments to be arbitrary.
36 3 The Traditional Spreadsheet
depends on the value in cell l. We say that s contains a circular dependency if there
is any location l that depends on itself, i.e., l @s l for some l.
Finally, a well-formed spreadsheet s W L ! E is a spreadsheet subject to two
conditions:
1. Finitely many cells in the domain of s are non-blank.3
2. s does not contain any circular dependency.
The first constraint implies that only finitely many cells need to be accessed during
evaluation. The second restriction makes sure that a cell needs to be visited a finite
number of times when calculating the spreadsheet. Without it, evaluation could enter
infinite loops. Commercial products issue a warning if a user accidentally includes
a circular dependency.4
Together, these two restrictions guarantee that evaluation will always terminate.
We shall take great care not to violate them as we introduce deductive extensions
to this paradigm: the first will hold in its current form, although the evaluation of a
(logical) formula will write a potentially unbounded (but always finite) number of
cells. We will relax the second by allowing controlled forms of circular references
in formulas (by means of recursion), but in doing so we will always make sure that
the finiteness of evaluation is maintained.
All the spreadsheets we will consider will be well-formed. We will therefore drop
this qualifier. We will often write a spreadsheet s W L ! E as s D fl 7! eg.
We will enrich this model with arrays and array operations in Chap. 4 as a
jumping board to dive in the deductive spreadsheet.
3
In our model, we implicitly lift any restriction on the number of cells in a spreadsheet. All
commercial applications force spreadsheets to be finite: for example, Microsoft Excel has “IV”
as its last column (for a total of up to 256), and 65,536 rows. Other commercial products have
similar bounds.
4
More precisely, although a warning is always issued, most commercial applications allow the
advanced user to enable a restricted form of circular references: assume for example that cell A1
contains the value 600, A2 contains the formula D A3 0:2 and A3 contains D A1 C A2. There
is a circular dependency between A2 and A3. Cell A2 is initialized with the value 0, which gives
600 for A3. At this point, A2 is re-evaluated on the basis of this new value for A3, yielding 120
which is used to refine the value of A3 to 480. The values of cells A2 and A3 eventually converge
to 100 and 500, respectively. The maximum number of iterations is user-defined (100 by default
in Microsoft Excel) and the notion of convergence is taken to mean that a cell’s value is within
another user-defined constant of the value in the previous iteration (the default is 0.001 in Excel).
Note that this amounts to numerically solving the equation 600 0:2x D x.
While the model we are developing can easily accommodate such bounded iterations, we
refrain from doing so for several reasons. First, this would add a layer of complication that would
only have the effect of obscuring our deductive extensions. Second, the user base of this esoteric
technology is very small. Indeed, few users are even aware of its existence and even fewer can
competently handle it. Third, circular evaluation is disabled by default in all commercial products.
Indeed, end-users have a hard time writing correct spreadsheets in the first place (see [Pan98] for
some disturbing statistics) even without this error-prone option.
3.2 Evaluation 37
3.2 Evaluation
v@ D v
l @ D .l/
op.e1 ; : : : ; en / @ D op
b ? .e1 @ ; : : : ; en @ /
ER fl7!eg ./ D fl 7! e @ g
ER sn .?/
A B C D E A B C D E
1 ⊥ ⊥ ⊥ ⊥ ⊥ 1 Mo... Fr... Ho... To... We...
2 ⊥ ⊥ ⊥ ⊥ ⊥ 2 11/29 ⊥ 8 ⊥ ⊥
3 ⊥ ⊥ ⊥ ⊥ ⊥ 3 ⊥ ⊥ 17 ⊥ ⊥
4 ⊥ ⊥ ⊥ ⊥ ⊥ 4 ⊥ ⊥ 25 ⊥ ⊥
5 ⊥ ⊥ ⊥ ⊥ ⊥ 5
Ës0 Ës1
A B C D E A B C D E
1 Mo... Fr... Ho... To... We... 1 Mo... Fr... Ho... To... We...
2 11/29 12/03 8 8 ⊥ 2 11/29 12/03 8 8 8.00
3 12/06 ⊥ 17 ⊥ ⊥ 3 12/06 12/10 17 25 ⊥
4 ⊥ ⊥ 25 ⊥ ⊥ 4 12/13 ⊥ 25 ⊥ ⊥
5 5
Ës2 Ës3
A B C D E A B C D E
1 Mo... Fr... Ho... To... We... 1 Mo... Fr... Ho... To... We...
2 11/29 12/03 8 8 8.00 2 11/29 12/03 8 8 8.00
3 12/06 12/10 17 25 12.50 3 12/06 12/10 17 25 12.50
4 12/13 12/17 25 50 ⊥ 4 12/13 12/17 25 50 16.67
5 5
Ës4 Ës5
actual value in every cell in s that holds a value (including all the [ cells—rows 5 and
below) and ? for every formula in s. For typographic reasons, we elided the year of
every date (in cell A2 so far) and truncated the strings in row 1. At the next round,
ER s2 , the environment has grown. All the non-? values of ER s1 are retained, and a few
are added: every cell in s containing a formula that only refers to locations that have
a value in ER s1 sheds its ? mark in favor of an actual value. This trend continues for
another three iterations (ER s3 , ER s4 , and ER s5 ). This last environment does not contain
any occurrence of ?; hence it represents the final value of the spreadsheet, which
we can compare to the lower part of Fig. 3.1.
In order to better understand how and why this technique works, we will now
recall some basic elements of the theory of fixpoints, which goes back to Alfred
Tarski [Tar55]. While this is somewhat heavy machinery for the simple language we
have developed so far, it will become an indispensable tool as soon as we introduce
recursion in the deductive spreadsheet (in Chap. 6). Therefore, we believe it is
advantageous to present these notions now and provide a uniform treatment to all
40 3 The Traditional Spreadsheet
the elements of the language we are developing. Many of the definitions below are
adapted from [Llo87]. We will illustrate abstract definitions on our current setting
as well as on examples that will become important later.
A binary relation on a set S is a partial order if it satisfies the following
properties:
Reflexivity: x x for each x 2 S .
Antisymmetry: x y and y x implies x D y for each x; y 2 S .
Transitivity: x y and y z implies x z for each x; y; z 2 S .
We write < for the strict version of , where x < y iff x y and x ¤ y. A partially
ordered set, or poset, is a set S together with a partial order . This is denoted
by .S; /.
Example 3.1 (Environments). The set Env of all environments is a poset when
considered together with the relation <Env defined as follows:
(
.l/ D 0 .l/ or
<Env 0 iff for each location l
.l/ D ? and .l/ ¤ ?
0
• lub S
S ≤
• glb S
lb S
.S; / is a complete lattice. In that case, lub S is denoted by > and called the top
element of S . This is illustrated in Fig. 3.3.
Example 3.5 (Environments). The set Env of all environments is a lower
semi-lattice. Indeed, the glb of any set of environments Env0 Env is the
environment that associates the value v to any location l such that 0 .l/ D v
for every 0 2 Env0 , and maps all other locations to ?. The initial environment ?
is glb Env, the bottom element of Env. However, a set Env0 of environments may
not have an upper bound, and therefore no lub. Thus, .Env; Env/ is not a complete
lattice in general.
Example 3.6 (Powersets). .P X ; / is a complete lattice. For any subset S 0 of P X ,
glb S 0 and lub S 0 are the intersection
T and the union of all the
S elements of S 0 ,
respectively. In symbols, glb S D X 0 2S 0 X and lub S D X 0 2S 0 X . The top
0 0 0 0
situations where this set is not empty and has a smallest and/or greatest element.
If these exist, they will be called the least fixpoint and greatest fixpoint of F ,
respectively. We denote them by lfp.F / and gfp.F /, respectively.
Example 3.8 (Environments). The environment ER s5 in Fig. 3.2 is a fixpoint for ER s :
indeed, applying ER s to it produces an identical environment. We will see that the
evaluation procedure in Sect. 3.2.1 always calculates a fixpoint for ER s , and that this
fixpoint is unique.
The Knaster-Tarski theorem [Tar55] (see also [LNS82]) affirms that if .S; /
is a lattice and F is monotonic, then both lfp.F / and gfp.F / exist (actually, the
set of all fixpoints of F forms a lattice). Furthermore, lfp.F / D glb fx W F .x/ D
xg D glb fx W F .x/ xg and gfp.F / D lub fx W F .x/ D xg D lub fx W x
F .x/g. If .S; / is a lower semi-lattice, only lfp.F / is guaranteed to exist, and it is
characterized in the same way.
A function F W S ! S is continuous if for every ascending sequence S 0 S
such that lub S 0 exists, then
F0 D ?
F i C1 D F .F i /
F ! D lub fF i W i 2 Ng
Note that, in order for this notion to be well defined, .S; / needs to be at least
a lower semi-lattice. Indeed, it is easy to verify that F i F i C1 F ! for every
i 2 N.
Specializing an earlier result due to Tarski, Kleene has proved that whenever
.S; / is a lower semi-lattice and F is continuous, then F o lfp.F / for any ordinal
o in N [ f!g. Moreover, there exists an ordinal oN such that for any o > o, N it is the
case that F o D lfp.F /. This is known as Kleene’s theorem.
5
A more accurate definition of ordinal power would have cases for all limit ordinals, not just !.
However, we will not need any ordinal bigger than ! thanks to our continuity hypothesis.
3.2 Evaluation 43
Although the naı̈ve evaluation procedure presented in Sect. 3.2.1 soundly captures
the notion of evaluation of a spreadsheet on the basis of the theory in Sect. 3.2.2,
we will now re-express it in a more structured way. The basic methodology
will remain the same, but the added structure will make it easier to assess
evaluation costs, discuss optimizations, and analyze updates in Sect. 3.3. A similar
structure will also play a crucial role when introducing deductive extensions to the
spreadsheet in the next few chapters.
Given a spreadsheet s, we define the dependency graph of s, denoted by DGs , as
the oriented graph with nodes and edges defined as follows:
• The nodes of DGs is the set of locations L of s.
• There is an edge from location l to location l 0 , written l l 0 , only if l 0 contains
a formula that mentions l, i.e., iff l v s.l 0 /.
44 3 The Traditional Spreadsheet
B4 E3 D4
B3 A4 E2 D3 C4
B2 A3 D2 C3
A2 C2
We will write l 2 DGs and l l 0 2 DGs for a node and an edge in DGs ,
respectively.
When displaying a dependency graph, we will generally omit nodes without any
incoming or outgoing edge. They correspond to cells that contain values that are
never used in any other cell. In particular, this includes the vast majority of blank
cells. We will generally represent cells containing a formula, especially when it
refers to other locations. The dependency graph of our timecard example is shown
in Fig. 3.4, where we have rearranged the columns for clarity.
A path from l0 to ln in DGs is a series of locations fli gi D0::n with edges li li C1
for all i D 0; : : : ; n 1. We write l0 ln as an abbreviation for this path, and
denote its length by jl0 ln j, which here is n. A path of length 0 is called trivial.
We write jDGs j for the length of the longest path in DGs .
As its name implies, the dependency graph of a spreadsheet s provides a clear
picture of the dependencies among locations as defined in Sect. 3.1. Indeed, there
is a non-trivial path from l 0 to l in DGs if and only if l depends on l 0 in s, a fact
we wrote as l 0 @s l above. The requirement that a spreadsheet contains no circular
references implies that a dependency graph will always be acyclic: for no l 2 DGs
is there a non-trivial path l l 2 DGs .
The dependency graph of a spreadsheet serves as a useful skeleton to display
other information in the form of node annotations. In particular, we can compose
it with any function f W L ! X with domain L to display the value f .l/ 2 X
associated with each node l. In Fig. 3.5, we compose the dependency graph of our
timecard example with the spreadsheet itself (recall that s W L ! E) to display the
entered content of every cell and their dependencies.
Even more useful is composing the dependency graph with an environment so
that the nodes display the intermediate values of an evaluation. Figure 3.6 shows
the result for each step ER s0 ; : : : ; ER s5 of the evaluation trace in Fig. 3.2. For reference,
we also display the locations in ER s0 . We have enclosed each occurrence of ? in a
3.2 Evaluation 45
=D2/((A2−A2)/7+1)
11/29/04 8
Fig. 3.5 The dependency graph of the timecard example annotated with expressions
dotted circle while using a solid oval for actual values. Dotted arrows exit ? nodes:
they represent missing data for the evaluation of the target node. Solid arrows
indicate ready information: it either has been used to calculate the value of a
formula, or it can be used at the next iteration. We will call this variant of DG
the evaluation graph of a spreadsheet and we will spend the rest of this section on
its numerous applications. We write EGs ./ for the evaluation graph of spreadsheet
s at environment . Again, EGs ./ is a particular way of rendering .
Cost
The evaluation graph can be conveniently used to assess the cost of calculating a
spreadsheet. Our measure of cost will be the number of times a value is assigned
to a cell during evaluation. In the case of an iterative procedure, such as the naı̈ve
strategy outlined in Sect. 3.2.1, we simply add the number of locations evaluated at
each iteration:
X
cost D evaluated cells.i /
i 2iterations
In the case of the naı̈ve evaluation, we can obtain a simpler expression: the function
ER s updates all the cells in the spreadsheet at every iteration. In practice, it is
sufficient to consider only the finite number of locations that either contain a
formula, or are referenced by one. Our example contains 20 such interesting cells,
but any over-approximation will do. Call this number cellss . The above formula
simplifies to:
⊥ E4 ⊥
B4 ⊥ ⊥ E3 ⊥ D4 ⊥ ⊥ ⊥
B3 ⊥ A4 ⊥ ⊥ E2 ⊥ D3 ⊥ C4 ⊥ ⊥ ⊥ ⊥ 25
B2 ⊥ A3 ⊥ ⊥ D2 ⊥ C3 ⊥ ⊥ ⊥ 17
A2 ⊥ ⊥ C2 11/29/04 8
Ës0 Ës1
⊥ ⊥
⊥ ⊥ ⊥ ⊥ ⊥ ⊥
11/29/04 8 11/29/04 8
Ës2 Ës3
⊥ 16.67
11/29/04 8 11/29/04 8
Ës4 Ës5
The number of iterations is given by the length of the longest path in DGs plus
one: jDGs j C 1. Indeed, evaluation starts with a graph containing only ? (ER s0 in
Fig. 3.6); with the first iteration ER s1 , it assigns an actual value to all the nodes without
incoming arrows; in the following iterations, ER si C1 , it follows edges in the graph as
it inserts an actual value in all nodes all of whose predecessors contain actual values
3.2 Evaluation 47
(edges on the longest path are always followed). Since there are five iterations in
our example, evaluating it with ER s has cost 20 5 D 100. The maximum number
of iterations is then equal to cellss . This leaves the naı̈ve evaluation with an upper
bound of
cost D O.cells2s /
The cost can be substantial for a large spreadsheet. It should however be noticed
that ER s is very inefficient:
• It recalculates the value of every non-? location at every iteration: since the
actual value of a cell does not change once evaluated, this is wasted work, and
repeatedly so.
• It attempts to calculate the value of locations even when they depend on cells
currently valued at ?. Again this is useless work.
We will repeatedly encounter evaluation functions that behave in this way in later
chapters. A direct implementation yields the naı̈ve evaluation procedure: a great
mathematical tool, but far from optimal from a computational viewpoint.
Semi-naı̈ve Evaluation
The above analysis suggests an obvious optimization that goes by the name of
semi-naı̈ve evaluation in deductive database circles (more on this in Chap. 6): rather
than evaluating the entire spreadsheet at each iteration, calculate just the cells that
depend only on locations that have changed since the last iteration, and only if they
do not depend on any ?-valued cell. Here is how this would work on our example
in Fig. 3.6:
1. Starting from the initial environment ER s0 , calculate the value of just the
cells without an incoming arrow. If we set our interesting perimeter to the
non-blank cells of s, these are A1WA2, B1, C1WC 4 (using the range notation for
conciseness). We obtain ER s1 in this way.
2. The formulas that depend only on the cells updated in the previous iteration are
in A3, B2, and D2: we calculate their value, obtaining ER s2 .
3. The formulas depending only on cells updated in iterations 1 and 2 are in A4,
B3, D3 and E2. Evaluating them yields ER s3 .
4. We iterate on cells B4, D4 and E3 obtaining ER s4 .
5. This last iteration leaves only E4 to be evaluated, on which no other location
depends.
We will now give a mathematical representation of the semi-naı̈ve evaluation and
then assess its cost. Given a spreadsheet s and an environment , we partition into
two partial functions:
48 3 The Traditional Spreadsheet
e ⊥ ⊥
Δs ´
⊥
v
v
∇s ´ v v v
• The restriction s of to just the ?-valued cells that do not depend on any
currently unevaluated location. In symbols,
• The rest of : rs D n s ,
An intuitive representation of this partitioning is displayed in Fig. 3.7. Each step
in the semi-naı̈ve evaluation is then described by the function EP s defined as
follows:
l 7! e @ W l 2 dom.s /
EP fl7!eg ./ D
l 7! .l/ W l 2 dom.rs /
cost D cellss
Note that this cost is optimal: it is impossible to do better given our measure of
cost (additional efficiency gains can be obtained, for example, by keeping track of
subexpressions that appear in more than one cell and evaluating them once—clearly,
this is effective only if the bookkeeping overhead does not dominate the savings).
3.3 Updates 49
A B C D E
1 Monday Friday Hours To date Weekly average
2 11/29/04 =A2 +4 8 =C2 =D2/((A2 -A2)/7 + 1)
3 =A2 +7 =A3 +4 17 =D2 +C3 =D3/((A3 -A2)/7 + 1)
4 =A3 +7 =A4 +4 25 =D3 +C4 =D4/((A4 -A2)/7 + 1)
5 =A4 +7 =A5 +4 25 =D4 +C5 =D5/((A5 -A2)/7 + 1)
A B C D E
1 Monday Friday Hours To date Weekly average
2 11/29/04 =A2 +4 8 =C2 =D2/((A2 -A2)/7 + 1)
3 =A2 +7 =A3 +4 17 =D2 +C3 =D3/((A3 -A2)/7 + 1)
4 =A3 +7 =A4 +4 25 =D3 +C4 =D4/((A4 -A2)/7 + 1)
5 =A4 +7 =A5 +4 19 =D4 +C5 =D5/((A5 -A2)/7 + 1)
3.3 Updates
As mentioned at the beginning of Sect. 3.2, full evaluation is a very rare event that
takes place only when loading a spreadsheet from file. Much more common is
updating a spreadsheet, something that can take place hundred of times in each
session. Figure 3.8 demonstrates this on our timecard example: at the end of a
new week, the hours worked by the employee are recorded. We realize this in two
steps:
1. At the top of the figure, we simply copy the contents of row 4 into row 5.
The enhanced paste functionality of modern spreadsheet applications takes care
of adapting the locations mentioned in the formulas to the new row (the exception
is cell A2 in column E, which is treated as an absolute reference—for the sake of
readability, we did not display the usual syntax to indicate this).
2. In the bottom of the figure, we replace the contents of cell C5 (copied from row 4
in the first step) with the correct number of hours worked this week, 19 in this
case.
This modality of extending a spreadsheet is typical. In a highly professional setting,
an administrator may have prepared a spreadsheet for the entire year so that the user
only needs to insert “19” in the appropriate location. However, most end-users left
to their own devices will take the two-step approach just outlined, possibly with a
few more steps added to make and repair mistakes.
An update is a change in the contents of one or more cells in an already evaluated
spreadsheet. The above example shows two updates: the first involves five cells,
the second only one. After each update, the spreadsheet needs to be recalculated.
Recalculation or re-evaluation is the process of propagating the changes to all parts
of the spreadsheet that depend on the modified locations by updating the displayed
50 3 The Traditional Spreadsheet
values of the affected cells. We will spend the remainder of this section modeling
updates and analyzing re-evaluation.
Given a spreadsheet s D fl 7! eg, an update on s is a partial function s D
fl * e 0 g such that dom s is the set of updated locations. In the top part of Fig. 3.8,
s D fA5 * A4 C 7; B5 * A5 C 4; C 5 * 25; D5 * D4 C C 5; E5 *
D5=..A5 A2/=7 C 1/g. The second update is more localized: s 0 D fC 5 * 19g.
Applying an update s to a spreadsheet s simply replaces the modified locations
of s with the contents in s. This notion is defined as follows:
(
s.l/ if l 2 dom s
.s ˇ s/.l/ D
s.l/ otherwise
We will often write s 0 for s ˇ s. The results of applying the first update above to
the timecard spreadsheet in Fig. 3.1 is shown in the top part of Fig. 3.8. Applying
the second update to it produces the bottom spreadsheet in this figure.
Next, we study how updates alter the dependency graph of a spreadsheet s. First,
observe that an update does not modify the nodes of DGs : an update never creates
or destroys cells, but simply changes their contents. Instead, an update often has an
effect on the edges of DGs :
• If s.l/ is a value (possibly [) and s.l/ is a formula e referencing some
cell l 0 , the dependency graph of s will have to be modified with an added
C C
edge l 0 l. We denote this addition by l 0 l. Formally, l 0 l iff l 2
dom s and l v s.l/.
0
• If s.l/ is a formula e referencing some cell l 00 and s.l/ is a value, DGs will
have to be modified by removing the edge l 00 l. We denote this alteration by
l 00 l. Formally, l 00 l iff l 2 dom s and l 00 v s.l/.
• If both s.l/ and s.l/ contain formulas, then DGs will generally be modified
with both the addition and removal of edges.
• If s.l/ and s.l/ contain values, then DGs is left unchanged with respect to
location l.
This is summarized in the following table:
Notice that deleting a cell amounts to replacing its contents with the blank value [.
Figure 3.9 illustrates this process on the timecard example. The dotted nodes rep-
resent the locations altered after the first update. We refrained from displaying them
in Fig. 3.4 since they contained blank cells, without any incoming or outgoing edge.
The dotted arrows denote the modified edges of the original dependency graph:
3.3 Updates 51
B4 A5 E3 D4 C5
+ +
B3 A4 E2 D3 C4
B2 A3 D2 C3
A2 C2
all of them are additions and all point to updated cells. The second update does not
further alter the structure of this graph.
We can define the corresponding application of an update s to the dependency
graph of s next. The updated dependency graph DGs ˇ s is the graph such that:
• Nodes.DGs ˇ s/ D Nodes.DGs /.
C
• Edges.DGs ˇ s/ D Edges.DGs / n fl 00 l W l 00 lg [ fl 0 l W l 0 lg
It is easy to verify that this is the dependency graph of the updated spreadsheet
s ˇ s, in symbols: DGs ˇ s D DGsˇs .
We now turn to the notion of re-evaluation. A simple-minded approach to
displaying the changes resulting from an update is to evaluate the entire updated
spreadsheet from scratch. This is clearly inefficient in most cases since a minority
of cells is affected by the changes, in general. We will now study approaches that
evaluate only the locations that are directly affected by the update: the updated cells
themselves and all cells that depend on them.
Given the environment corresponding to the final value of the original
spreadsheet s, we start with a pre-evaluation environment s that differs from
simply by resetting all cells affected by the update s to ?. As mentioned above,
these locations—call them cellss —are the updated cells themselves and all cells
that depend on them, i.e., all the cells that sit on a path starting on an updated cell
of DGs 0 . In symbols,
⊥ 25.00
11/29/04 8 11/29/04 8
⊥ 23.00
11/29/04 8 11/29/04 8
The evaluation graph corresponding to this environment in the case of the first
update to the timecard example is displayed on the left-hand side of Fig. 3.10.
Recalculation simply applies any chosen evaluation strategy starting from s
rather than ?. If the semi-naı̈ve procedure is used, the number of iterations before
all occurrences of ? have been given an actual value is given by the length of the
longest path in DGsˇs starting from a node in dom s. The total cost of the update
is jcellss j, which, in general, is substantially smaller than the total number of cells
of interest of s (cellss ).
The result of the recalculation of the first update in the timecard spreadsheet
is shown as the right evaluation graph in Fig. 3.10. The cost of this update is 5.
The pre-evaluation graph for the second update and the result of recalculation are
shown in Fig. 3.11, with a cost of 3.
3.5 Summary 53
3.4 Explanation
3.5 Summary
In this section, we summarize the work done and highlight important lessons for
the design of the deductive spreadsheet. Figure 3.12 summarizes our model of a
spreadsheet.
54 3 The Traditional Spreadsheet
4.1 Arrays
A B C D E
1 Monday Friday Hours To date Weekly average
2 11/29/04 8 =C2
3 =A2 +7 =A2:A4 + 4 17 =D2 +C3 =D2:D4/((A2:A4 −A2)/7 + 1)
4 =A3 +7 25 =D3 +C4
5
1
For a reason we do not completely understand, Microsoft Excel surrounds array formulas with
braces, therefore writing our D A2WA4 C 4 as fD A2WA4 C 4g.
2
To be more precise, 4 is implicitly promoted to the three-element array .4; 4; 4/ and C is
interpreted as an array version of traditional addition: it adds its arguments component-wise and
writes the result in the cell with the same relative index. All the operands are expected to have the
same dimensions, although arrays that are not long or wide enough are automatically extended by
default values (often blank) while results that are too big for the target range are truncated.
4.1 Arrays 57
way: the subformula A2WA4 A2 subtracts the value in A2 from each cell in A2WA4.
The result is divided by 7 component-wise and then incremented by 1. The cells in
this intermediate array are finally used to divide the corresponding values in D2WD4.
Evaluating this variant of our original spreadsheet displays the exact same results
already seen at the bottom of Fig. 3.1. In a commercial spreadsheet application such
as Excel, we could have made an even more aggressive use of array formulas by
writing D A2WA3 C 7 in A3WA4, and D D2WD3 C C 3WC 4 in the range D3WD4.
Differently from the instances shown in Fig. 4.1, in both of these cases the input
array overlaps the output array. At first sight, this may appear to be a circularity.
However, individual cells never rely on their own value, either directly or indirectly.
Hence there is not circularity at the level of the elements of the array. Because
such overlaps are admitted in Excel, evaluation cannot proceed in an array-at-a-time
fashion (since the contents of A4 depend on A3, which is part of the output array),
but rather cell-at-a-time as in Chap. 3.
With our upgraded example as a guideline, we will now extend our spreadsheet
model from Chap. 3 to encompass arrays and array formulas. Some general
definitions first.
xE W I ! X
3
In the rest of this book, we will assume the bidimensional array structure commonly found in
spreadsheets. This work can however be generalized to higher dimensions, with index sets defined
as hyperintervals Œ1::j1 : : : Œ1::jd for some dimension d . Then, the geometry of these sets
would be given by the dimension d together with the tuple .j1 ; : : : ; jd /. Further generalizations
are possible.
58 4 The Relational Spreadsheet
as a j k-array. We will generally omit this prefix altogether and speak of an array
over X when the index set is unimportant or easily reconstructible from the context.
In that case, we recover the index set of xE as IxE . We denote the set of all I -arrays
on X by X I . We denote the set of all arrays on X by X I , i.e.,
[ [
XI D XI D fxE W I ! X g:
I 2I I 2I
Locations and (now scalar) values are defined as in Chap. 3. The notation A2WA4
in Fig. 4.1 is a commonly found abbreviation for the 13-array of locations
f.1; 1/ 7! A2; .1; 2/ 7! A3; .1; 3/ 7! A4g. Similarly, location array C 2WC 4
contains the array of values f.1; 1/ 7! 8; .1; 2/ 7! 17; .1; 3/ 7! 25g.
Operators can now take arrays as arguments: the classical example is SUM, which
can have up to 30 arguments, each of which can be either an array or a scalar (which
we uniformly interpret as a 11-array). Operators can also return an array: examples
are “C”, “=” and “” in Fig. 4.1. We upgrade our definition of operator from Chap. 3
to take a fixed or variable number of arrays as arguments (its arity) and return
an array as a result. We denote a generic operator by op E (we still write op when
the returned object is a scalar). Again, we liberally make use of infix notation and
common precedence rules.
Similarly to the scalar case, each operator op E of arity n is associated with
an operation opb
E that maps n argument values (possibly arrays) to a result value
(possibly an array). Note that this definition does not impose geometry constraints
on the values accepted and returned by an array operation. Indeed, in commercial
spreadsheets many operators such as “C” accept arguments of varying geometry
and therefore the corresponding operation shall return appropriate results for each
of these geometries. For example, although the operation C O is intuitively expected
to take two arrays of j k values each and returns a j k-array of values obtained
by adding the input arrays component-wise, C O is much more liberal in actuality: the
arrays given as arguments do not need to have the same geometry, nor shall they
have anything to do with the expected geometry of the result: the input arrays are
truncated or extended with default values to match the latter. Operators that are not
as foolproof return the error value, , possibly in an array form E.
Many array operators are mere component-wise extensions of familiar scalar
operators: “C” is an example. Indeed, any scalar operator op W E n ! E taking
purely scalar arguments can be promoted to an array operator op E W .I ! E/n !
.I ! E/ defined by op. E xE1 ; : : : ; xEn /Œ D op.xE1 Œ; : : : ; xEn Œ/ for each 2 I . Many
array operators do not fit into this mold however. Indeed, some scalar operators
natively work on arrays: SUM is one of them. Furthermore, some operators
returning arrays cannot be reduced to the component-wise extension of a scalar
operation: for example, Excel’s TRANSPOSE is a pure array-valued operation.
Excel also provides a seldom used way to build an array extensionally, i.e., directly
from scalars. Example operators using all possible combinations of arrays as input
to and output of operators are shown in Fig. 4.2.
60 4 The Relational Spreadsheet
Output
Input
Scalars Arrays
As in the scalar setting of Chap. 3, arrays of values, arrays of locations and array
operators are the basic ingredients for writing array expressions. These objects are
therefore defined just as in the scalar case:
Note that this subsumes scalar expressions once we identify scalars with 11-arrays.
By a conceptual extension of our conventions, we denote the -th component of an
expression eE by eEŒ. We will soon see that any such eEŒ can be simulated by a
scalar-valued expression e .
The subexpression relation is defined as in Chap. 3, with one added case: an
E v xE for every 2 I ,
array element is a subexpression of an array. Formally, xŒ
where xE is an I -array. For example, A2 is a subexpression of A2WA4. We still write
this relation as v and @ for its strict version. Both relations naturally extend to
subarrays. For example, A2WA3 is also a subexpression of A2WA4.
that contributes to it also mentions A2 and A4. In general, other operators will force
other dependencies; for example, if B3 contained SUM.A2WA4; 4/, its value would
depend on all the cells mentioned in it. Therefore the notion of dependency at the
component level becomes semantic rather than syntactic as when considering scalar
expressions (or array formulas as a whole): each operator follows its own set of
rules.
Let us formalize these ideas. Given an n-ary operator op, E we write .i / op
E to
E i -th argument (for i D 1::n) can influence the value calculated
indicate that op’s
by this operator: i is then a dependent argument of op. E An operator invariably
depends on all of its arguments.4 This changes when lowering this notion to the
individual components of an argument and/or the result. We then write .i / 0 op E
to indicate that the -th component of argument i can influence the value of the
0 -th component of op.E This relation is not always true: we have seen in the case
of addition that .1/ 0 C and .2/ 0 C iff D 0 , that is, the -th component of
an array addition depends only on the -th component of its arguments. Generally,
the returned component at index of an I -valued operator op E will depend only on a
subset of its input components, independently from the actual input values.
In a commercial spreadsheet, the use of array formulas can always be simulated
by scalar-valued operators. Indeed, for every array operator op E and every index in
the output geometry of op, E there exists a scalar operator, which we indicate as opŒ,
E
that emulates the behavior of op E at index . The arguments of opŒ
E will be all the 0
components of the each argument .i / of op E such that .i / 0 op.
E We have already
seen that the behavior of array addition at index is simply the scalar addition of
the -th component of its arguments. We can now lift this notion to the level of
expressions, obtaining a scalar formula eEŒ that emulates the behavior of eE at each
index 2 IeE:
E
lŒ D E
lŒ (the -th component of l) E
EvŒ D EvŒ (the -th component of Ev)
E e1 ; : : : ; eEn /Œ
op.E D E
opŒ.e 1 ; : : : ; em / where eij D eEi Œj and .i / j op
E
This notion is natively defined in the case of array of locations and array of values.
In passing, we can lift the component-level dependency to the level of
expressions: e is a dependent subexpression of eE at , written e eE, if the following
holds:
e lE iff E
e D lŒ
e Ev iff e D EvŒ
(
e D eEi Œ0 and .i / 0 op
E
E e1 ; : : : ; eEn /
e op.E iff
or e eE0 and eE0 op.E
E e1 ; : : : ; eEn /
4
While the laws of algebra certainly do not require this, it is a common and convenient practice:
it makes no sense to force a user to write arguments that never influence the result of an expression.
62 4 The Relational Spreadsheet
Again looking at Fig. 4.1, A3 Œ1;2 .A2WA4 C 4/—the second component returned
by D A2WA4 C 4, in location B3—but A4 6 Œ1;2 .A2WA4 C 4/. Notice that in the
scalar world, l v e implied l e. Now, although l v eE, it may not be the case that
l eE for all .
A2WA4 @ E s B2, and A2 @ A2WA4 and also A3 @ A2WA4. While a plausible basis
for defining the notion of dependency, it does not correspond to what commercial
spreadsheets implement.
Component-wise referential closure: In the same context, the second variant is
the relation s given by:
• s.L.l//Œ s l for all l 2 L, where l D L.l/Œ;
• eE s eE0 if eE eE0 ;
• eE s eE00 if eE s eE0 and eE0 s eE00 .
Differently from above, the first line relates a location l only to the portion of the
expression s.L.l// that influences the value of l. The notion of cell dependency,
l s l 0 , and circular dependency, l s l for some l 2 L, is defined as in the
previous case.
This definition is much more discriminating than the previous array-oriented
version: upon encountering a location l, it pursues the search just in that cell
rather than in the whole location array it participates in, i.e., s.L.l//. Therefore,
it will follow the scalar projection eEŒ of any expression eE appearing in that range.
Since eEŒ mentions only the dependent subexpressions of eE at , this will result
in a much more focused set of dependents.
At this point, a well-formed spreadsheet is a spreadsheet .L; s/ subject to the
same two properties as scalar spreadsheets:
1. Finitely many cells in the domain of s are non-blank.
2. s does not contain any circular dependency with respect to @s (although there
may be circularities along @E s ).
All the spreadsheets we will consider shall be well-formed. Therefore we will drop
this qualifier.
Let us now take the point of view of the individual cells. Saying that a spreadsheet
flE 7! eEg associates the partition element lE with the array expression eE simply means
E in lE is associated with the -th component of eE. We have
that every location lŒ
seen that there exists a scalar formula, eEŒ, that is equivalent to eE at index .
Viewing flE 7! eEg as a map that associates each location lŒ E to the expression
component eEŒ has the effect of recasting our upgraded notion of spreadsheet back
into the mold of our original definition from Chap. 3: fl 7! eg. This means that
we can reuse with minimal modification the entire evaluation infrastructure set up
in that chapter. The naı̈ve and semi-naı̈ve strategies apply without any alteration.
The changes to dependency graphs and related notions are limited to simply using
the component-wise referential closure of @ in its definition. As a result, the purely
scalar timecard spreadsheet in Fig. 3.1 and its re-expression using arrays in Fig. 4.1
share the same dependency graph, which we showed in Fig. 3.4. When equipping it
with the component subexpression at each location, we obtain precisely the graph
in Fig. 3.5, which means that stepwise evaluation proceeds in the exact same way
as with the original spreadsheet. This trivially explains why both versions of the
timecard spreadsheet produce the same output.
64 4 The Relational Spreadsheet
As we just saw, the use of array formulas can always be simulated by scalar-valued
operators: in most cases, their effect is achieved by copying a scalar formula over
a number of rows or columns. Indeed, the example in Fig. 4.1 is equivalent to
our original spreadsheet in Fig. 3.1. More rarely, as when using TRANSPOSE,
the transformation needs to be manual. Therefore, array formulas are essentially an
abbreviation for scalar formulas. Using array formulas has a minimal computational
advantage, mostly at the time of parsing, since each expression appears exactly
once rather than being replicated multiple times. This becomes an issue only with
very large spreadsheets, or very slow computers. Array formulas currently impose
a penalty in terms of usability: entering an array is somewhat unintuitive, but more
importantly, modifying an array is as hard as deleting it and re-entering it from
scratch. This is acceptable for archival work, but not for the typical spreadsheet that
needs to be updated frequently. We do not see any reason for this overhead and
attribute it to a design that has not reached maturity. We will propose an alternative
design in Part II.
Given this analysis of arrays, Chap. 3 characterizes rather exhaustively the
traditional spreadsheet from a programming language perspective. At its core,
a spreadsheet embeds a simple functional language without recursion.5 What is
evaluated is the individual cell, even in the presence of array formulas, and this
value is a function of the surrounding locations. A cell is indeed analogous to a
pocket calculator with nearly unlimited memories.
In spite of this humble characterization, commercial spreadsheets are one the
most useful and pervasive computing applications. They are used daily across our
society and can hold anything from a grocery list to a multi-million dollar budget.
The key to their success is the coupling of the basic framework above with a
nice user interface, a number of productivity tools, and a rich set of operators.
A particularly important aspect of the interface is its ability to display a multitude of
values at once, hence allowing extensive visual feedback and simplifying decision
making.
5
More precisely, a bounded form of recursion, disabled by default, is supported.
4.2 Relational Support in the Traditional Spreadsheet 65
(12/06/04) and the Friday (12/10/04) of a week, the number of hours worked that
week by an employee (17), the cumulative number of hours worked as of that Friday
(25), and the weekly average as of the end of that week (12.50). All the rows in
the timecard example (except row 1 that contains captions) share this interpretation.
Notice that some of these fields are input by the user (e.g., 17) while others are
calculated on the basis of other fields.
Commercial products provide a limited toolkit for supporting this relational
interpretation of a region of the spreadsheet. Microsoft Excel, for example,
recognizes this intent when the user enters textual captions in the top row of a
new worksheet and then inputs the first record. Excel then interprets this group
of columns as a “data list” and makes available a number of commands to
manipulate it:
• The user can bring up a form for inputting new records or modifying old ones.
This form shows the caption of each column in the data list next to an input box,
which either contains a preexisting value, or is blank—an example can be seen
in Fig. 7.4. This device aids the user by abstracting away all but the record he is
working on. Any change in the structure of the data list (e.g., adding, deleting or
moving a column) is automatically reflected in the form.
• The user can filter a data list in place by instructing Excel to hide from view
all records that do not satisfy a given condition. In our timecard example, a
user could ask to see only the records where the employee worked less than
8 hours, for instance. Filters are set up using a variety of methods, depending on
the complexity of the condition and the sophistication of the user. One of these
options allows saving the filtered data in a new area of the spreadsheet rather than
just hiding the tuples that do not satisfy the condition.
• The data list can be lexicographically sorted in place.
• A number of “database functions” are available to conditionally perform opera-
tions such as SUM, on a data list. For example, DSUM takes three arguments:
a relation, the column whose values should be added, and a criterion which
specifies which records should be taken into account. This last field is expressed
as a reference to a cell range containing the specification of the criterion itself.
• A set of columns can be imported from an external application, either a database
or another spreadsheet. This is the only other way of creating a new relation.
It picks columns from the external application, arranges them in some specified
order and optionally filters the resulting records. This is rather cumbersome in
that importing a relation requires defining it, saving it into a temporary index file,
and finally loading it into the spreadsheet.
Other commercial spreadsheet applications offer similar concepts and commands.
For example, relations are called “database ranges” in OpenOffice.org’s Calc, and
variants of the above actions are available to manipulate them.
Relations are an important concept in the context of the deductive spreadsheet
because they can naturally be interpreted as logical entities: simplifying our
example, the presence of the record .12/06/04; 17/ in the timecard relation can
indeed be understood as indicating that it is a true fact that the employee worked
66 4 The Relational Spreadsheet
17 hours during the week of 12/06/04. Records not appearing in the relation are
facts that are not true. Symbolic reasoning establishes new true facts on the basis of
facts that are known to be valid. This corresponds to constructing new relations
on the basis of existing relations. These new facts can themselves participate
in further deductions, i.e., contribute to further relations. We will formalize this
correspondence in Chap. 5 and extend it in Chap. 6.
As we just saw, commercial spreadsheets do provide a selection of tools to work
with relations. Among them, the support for defining new relations is very limited,
however: a relation can be built manually (possibly using a form), or it can be
the result of filtering existing data, or it can laboriously be imported from another
application. All of these options are strictly interactive: a user must initiate them.
More importantly for our purposes, neither of the two methods that create a relation
out of existing relations has the ability to propagate updates automatically: adding
or modifying the source data in an external application has no effect on previously
imported records. Similarly, changes to the records of a data list that has been used
to produce a relation by filtering are not reflected in the latter. Updates must be
propagated manually.
This is in stark contrast with the spreadsheet formulas we have considered so far.
A formula is bound to a cell or cell array even after it has been evaluated, so that
any change in a value it depends on is immediately reflected. Relational commands
are not bound to the relations they calculate: once the output has been produced,
they are forgotten. It is indeed on purpose that we referred to them as “commands”
rather than “operations”. Operations, as they appear in formulas, are first-class
entities: they are an inherent part of a spreadsheet, both during normal usage and
when saved on disk. The relational actions are instead second-class in Excel and
other commercial products: they act on a spreadsheet as would “Print” or “Save”,
but are not part of it. A consequence of this fact is that relational commands do not
participate in the evaluation process of a spreadsheet in the same way as formula
operators do. In particular, they do not fit in the evaluation model we introduced in
Chap. 3.
of relational expressions, and finally define array variants for some of them.
Altogether, this substantially extends the range of manipulations currently available
in commercial spreadsheets with useful new tools. These concepts are brought
together in Sect. 4.3.3 where we define the relational extension of the spreadsheet.
Having paralleled our work on the traditional spreadsheet, Sect. 4.3.4 stops and
reflects on the differences between this relational extension and the main application
of relational algebra: database query languages.
A B C ···
1 Students
2 First Last Student
3 Sue Smith
4 Alan Bond
5 Nick Vitter =A3:A & ” ” & B3:B
6 Sue Lee
7 ··· ···
··· H I J ···
1 Courses
2 Name Abbrv Instructor
3 Operating Systems os Mary Vaught
4 Basic Networking bn Emil Wyre
5 Advanced Networking an Judy Less
6 Computer Architecture ca Emil Wyre
7 Theory of Computation tc Mary Vaught
··· ··· ···
Generic Relations
As in the case of arrays, we start with a few general definitions that we will later
instantiate to appropriate spreadsheet entities. Given a vectorial index set I (i.e., an
index set of the form Œ1::j Œ1::1 or Œ1::1 Œ1::k), an I -relation xN over X is a
subset of X I , the set of all I -vectors over X :
xN X I
interested in nullary relations. We will however admit the empty relation which
contains no element. We denote it by ;, or ;I when the particular vectorial index
set I is important.
We write XN I for the set of all I -relations over X : therefore XN I is the powerset
of X I . The set of all relations over X , for any vectorial index set I 2 I, is then
denoted by XN I , or simply XN when I is fixed, as when working with bidimensional
spreadsheets.
We call an element xE 2 xN a record, or sometimes a tuple. For clarity, we will
alternatively indicate a record with the letter r, possibly subscripted. Each of these
objects is a vector in X I . For practical reasons that will become apparent shortly,
we will not consider a vector of blank values, E[, a record. We will frequently make
use of the list notation .x1 ; : : : ; xjEx j / introduced in Sect. 4.1. For example, .A; 4:00/
is a record in the bottom right relation in Fig. 4.3. Each of the indices i D 1; : : : ; jxj E
is called an attribute and is used to positionally identify the element xi inside a
tuple. The objects occurring at the same index throughout a relation generally have a
coherent interpretation which in a sense is the meaning of the attribute. For example,
the values in column A are first names in Fig. 4.3, while the values in column R are
semester acronyms. We use the letter a, variously adorned, to denote an attribute.
Having defined an attribute as a vectorial index a in the index set of a relation
N the extensional attribute of xN at a, denoted by xŒa,
x, N is the set of all xE Œa for all
xE 2 x,
N symbolically xŒa
N D fxŒaE W xE 2 xg. N We will drop the qualifier “extensional”
when clear from the context. The (extensional) attributes of a relation xN is then the
set of all extensional attributes of x, N i.e., Attr.x/
N D fxŒ
N W 2 IxN g.
A relation naturally lends itself to a tabular representation. This is clearly
demonstrated in the four relations in the spreadsheet shown in Fig. 4.3 once fully
evaluated. Each record occupies a separate row, with attributes corresponding to
columns. Our definition also supports the reverse orientation, i.e., relations with
vertical records and attributes along the rows, an option unavailable in commercial
products. Note that in commercial products the commonly used tabular topology of
a relation is often just a stepping stone for a more convenient rendering: numerical
relations are already displayable using a variety of charts. Additional forms of
representation are naturally associated with symbolic data: for example, a relation
describing course requirements can conveniently be displayed as a workflow graph.
We will come back to these issues in Part II of this book.
Spreadsheet Relations
Unlike with arrays, we will not need to define a notion of relational reference.
Indeed, array references served the purpose of denoting (rectangular) collections
of cells, both within formulas and as formula containers in the definition of
spreadsheets themselves. Because of the tabular interpretation of relations, this
very same mechanism can be used to denote an area of the spreadsheet to which
we want to give a relational interpretation. Indeed, we will refer to the topmost
relation in Fig. 4.3 as A3WC both within a relational expression (defined in the next
section) and for the purpose of formalizing the notion of the relational spreadsheet
(in Sect. 4.3.3). Similarly, we may refer to the second attribute of this relation as
B3WB .6
It is common practice to assign symbolic names to relations rather than refer
to them through array references. We have done so in the first row of Fig. 4.3 by
merging the appropriate number of cells for each relation (a feature supported by
all commercial spreadsheets) and writing a relevant identifier into it. In this way,
we can conveniently refer to the second relation in that figure as “Courses” rather
than through the obscure array reference H 3WJ . While this certainly makes for a
leaner discussion, it also enables us to use these symbolic names within relational
expression thanks to the existing mechanism of range names, by which a cell or cell
range can be assigned a mnemonic name which can take its place in any formula.
We will make an intuitive use of range names for the time being, but come back
to them in Part II. We rely on the same device to associate symbolic names to
attributes: this allows us to refer to the first attribute of Students in column A
as “First” rather than 1 or A3WA . The second row in the spreadsheet in Fig. 4.3
provides symbolic names for each attribute. Note that distinct attributes can have the
same name. In our example, Student is an attribute of both Students and HasTaken.
Whenever needed, we will disambiguate them by prefixing the name of the relation
to the attribute separated by a dot: Students:Student and HasTaken:Student. These
are called qualified names.
6
Properly speaking, A3WC is a reference to the relation contained in this group of cells, and
similarly B3WB is a reference to its second attribute. While it is important to keep in mind the
distinction, we will often blur it in actual discussion.
4.3 Extending Spreadsheets with First-Class Relations 71
meaningful in the examples in Fig. 4.3, but their consequences will become evident
when considering relational expressions based upon them: indeed, the order of the
records in the calculated relation will be unpredictable in general, and there will not
be duplicated records.
Another difference between relations and arrays concerns the number of objects
they contain. Arrays are sequences of a fixed finite number of rows (or dually
columns): their extension is determined at the time they are defined and is very
hard to change after that. Instead, we will think of a relation as containing a variable
but generally unbounded number of records. The extension of a relation will often
be expressed in terms of the last row of the spreadsheet (as in A3WC above) and
therefore appear unlimited for all but the most expansive computations. In general,
only an initial segment of a relation will contain actual data—the rest being blank.
For this reason, we required that a record always contain at least one non-[ element.
While unbounded relations are particularly common, nothing will prevent us from
fixing a priori the maximum number of records.
Maybe the most striking difference between relations and arrays is that the former
will be treated as a unit during evaluation. As we saw in Sect. 4.1, an array is atomic
for editing, but each component is evaluated individually. It will not be possible,
in general, to reduce the evaluation of a relational expression to the evaluation of
individual records.
Following the methodology we developed in the case of scalars and arrays, our next
step shall consist in introducing a notion of relational operator that can be used to
build relational expressions. As we do so, we shall carefully engineer the interface
between this new representational paradigm and the familiar infrastructure in order
to obtain a language that is not only consistent but also seamlessly integrated. The
resulting classes of operators and their interactions can be previewed in Fig. 4.4.
This section will be dedicated to explaining this diagram and defining the entities
that appear in it.
In Chap. 3, we adopted arithmetic functions and other operators that when
evaluated produced a scalar (e.g., C and &). In Sect. 4.1, we similarly made
available operators drawn from an algebra of arrays (e.g., component-wise addition
and TRANSPOSE). We also drew bridges to the scalar world through operators
such as SUM and COUNT. This was summarized in Fig. 4.2 and is reported in the
upper-left two-thirds of Fig. 4.4 (save for the second line of the central cell).
In order to work with relations, we draw our operators from relational algebra,
which however covers only the lower-right corner of Fig. 4.4. The remaining
quadrants of the figure, and a good part of this chapter, are occupied by mechanisms
that take a relation as input and return a scalar or an array, and dually that build
a relation from scalars and arrays. While it is conceivable to leave the set of such
bridging operators open-ended (in the same way as a potentially unbounded number
of SUM-like operators can be defined to go from arrays to scalars), we adopt a more
72 4 The Relational Spreadsheet
Output
Input
Scalars Arrays Relations
+, TRANSPOSE, ...
Arrays SUM, . . . (implicit coercion)
SORT, ∪V , ∪H , ¼a , ¾C
⇑
Relations (via arrays) (implicit choice) ∪, −, ×, ¼æ , ¾C
Fig. 4.4 Support for scalar, array and relational operations in the relational spreadsheet
disciplined approach. The passage from arrays to relations will take the form of
an implicit coercion, hence allowing relational expressions to operate on arrays.
In the reverse direction, we will define two methods for promoting a relation to
a bidimensional array. This will have the effect of making all the current array
operators available for computing with relations. Last, we will draw inspiration from
relational algebra to define a handful of new and useful array operators, displayed
on the second line of the central square of Fig. 4.4.
One of the requirements in Chap. 2 called for the seamless integration of inferential
extensions and traditional functionalities in the deductive spreadsheet. While we
have not introduced any apparatus for symbolic reasoning yet, the operations that
interface arrays and relations constitute the foundations of this integration. This
interface is schematically described by the next diagram. We will spend the next
few paragraphs formalizing the meaning of the labels.
(implicit coercion)
Arrays Relations
Non-deterministic ordering
(SORT)
In this production, we use the angled brackets to clearly mark the interface between
arrays and relations, but we will generally omit them in practical examples. We call
hE
ei a base relation. We will complete the grammar of relational expressions in the
rest of this section.
Clearly, the geometry of the provided array and the expected relation need to
match. If they do not, two courses of actions can be taken: we can either return an
error relation (N ) of the appropriate geometry, or we can use default rules to reshape
the input or the output. Which alternative is preferable, in which circumstances,
and what are appropriate default rules, are all questions that needs to be assessed
empirically.
In order to fully integrate relations into a spreadsheet, it is important to provide a
means to pipe the result of a relational expression into an array formula. We will see
concrete examples shortly. Simply reverting the previous argument and interpreting
any j 1-relation xN as a j k-array xE for an appropriate k (and similarly for the dual
orientation) leaves one issue unresolved: how should the records of xN be ordered as
rows in the array xE ? There are two possible answers:
• We can leave the issue unresolved and freeze the records of xN in whatever order
relational evaluation returns them. The resulting ordering is non-deterministic
because there is no guarantee, in general, that two evaluations of the same
relational expression will return the records in the same order. Therefore,
any subsequent computation that depends on this order will run the risk
of returning incorrect results. On the other hand, many operators are either
commutative—SUM for example—or do not rely on the relative order of their
arguments, e.g., component-wise increment.
• Alternatively, we can resolve the issue by sorting the records of xN according to
some criterion. A common approach is to specify a lexicographic order based
on an arrangement of attributes. We denote this last operator by SORTaE Œe, N
where aE lists the attributes in eN according to the desired priority. A partial list
is automatically completed according to a fixed default policy.
This second option can be reduced to the first by introducing SORTaE as an
array operator. This has a number of advantages over making it available as an
interface function. First, SORT can then be used to sort not just relations, but also
generic arrays. Commercial spreadsheets make this functionality available as
a command, as we saw in Sect. 4.2, but not as an operator. Second, a purely
74 4 The Relational Spreadsheet
relational SORT would differ from all other relational operations in that sorting
does not have a proper logical meaning.
These considerations allow us to extend the grammar of array expressions from
Sect. 4.1 as follows:
N W
op XN : : : XN ! XN
.xN 1 ; : : : ; xN n / 7! xN
Given the fact that relations are sets of records, a computation on generic relations
can be reduced to the composition of a small number of operations that work
either on the set structure of its arguments, or on the structure and quality of
the records appearing in them. Specifically, relational algebra traditionally reckons
the following five core operators, whose intuitive semantics is sketched in Fig. 4.5
(please ignore ‰ for the moment):
4.3 Extending Spreadsheets with First-Class Relations 75
Union: Given two relations xN 1 and xN 2 based on the same index set I , the union
of xN 1 and xN 2 , denoted by xN 1 [ xN 2 , returns the records appearing in either relation.
This is simply set-theoretic union. As such, records that appear both in xN 1 and xN 2
are collapsed within xN 1 [ xN 2 .
Consider our registrar example in Fig. 4.3. Assume that columns D through F
contain the first and last names of the instructors in our university, together with
their concatenation as an identifier. Call the resulting relation Instructors and
notice that it has the same structure as Students. Then, the relational expression
Students [ Instructors has a record for every person who is either a student or an
instructor, maybe identifying the members of the university who are allowed in
a classroom. Individuals who are both students and instructors appear only once.
Difference: Given again I -relations xN 1 and xN 2 , the difference of xN 1 and xN 2 ,
denoted by xN 1 xN 2 , returns the tuples occurring in xN 1 but not in xN 2 . This is
set-theoretic difference.
In the setting above, Instructors Students identifies the core faculty, i.e., the
instructors who are not students.
Cartesian product: Given a j1 -ary relation xN 1 and a j2 -ary relation xN 2 , the
Cartesian product of xN 1 and xN 2 , denoted by xN 1 xN 2 , is the .j1 C j2 /-ary relation
whose records are the concatenation .r1 ; r2 / of every record r1 2 xN 1 with every
record r2 2 xN 2 . Recall that neither r1 nor r2 can be entirely blank. This operation
is not set-theoretic but purely relational since it refers to the structure of records.
It is always a challenge to provide a convincing example involving Cartesian
product alone because it is almost always used together with other operators,
as we will see. Therefore, without even attempting to motivate its usefulness,
Students Students would produce 6-attribute records that pair up each student
with every other student in our registrar example.
Projection: Given an I -relation xN with records of length j and a list aE D
.a1 ; : : : ; ah / of attributes in the range Œ1; : : : ; j , the projection of xN onto aE ,
written aE x, N is the relation whose records consist of only the aE components
of any record in x. N The order of the attributes in the result is specified by aE . Note
that the attributes in aE are not required to be distinct. Therefore, h may be smaller,
equal, or even larger than j .
In Fig. 4.3, the expression First Students returns a unary relation consisting of
the first names of every student in the school. Duplicate entries, such as the two
“Sue”’s, would appear only once. Note how we used the attribute identifier First
rather than the index 1.
Selection: Given a relation xN and a condition C that assigns the value true or
false to any record in x, N the selection of xN according to C , denoted by C x, N
is the relation consisting of only the records of xN that satisfy C . Conditions
typically compare an attribute of a record with either a value or another attribute.
Differently from all the above operators, selection is not purely relational in that
it must refer to the domain of the relation through the condition, both for values
and for meaningful notions of comparison.
For example, the expression FirstD“Sue” Students would return a relation
consisting of a record for only the students whose first name is “Sue”.
76 4 The Relational Spreadsheet
Comparing this list with the commands available in a commercial spreadsheet, such
as Microsoft Excel, to manipulate relations reveals one exact match: filtering, which
corresponds to selection. A rudimentary form of projection is made available when
importing a data list from an external application. None of the other operators
is present. Therefore, making them available in the context of a spreadsheet
substantially enhances the expressiveness of this tool. We will further extend this
basic pool of operators shortly.
We now formalize the intuition behind each relational operator op N above by
defining the behavior of the corresponding operation opb
N when applied to relational
values of the appropriate form:
vN 1 [ O vN 2 D fEv W Ev 2 vN 1 or Ev 2 vN 2 g D vN 1 [ vN 2
vN 1 O vN 2 D fEv W Ev 2 vN 1 and Ev 62 vN 2 g D vN 1 vN 2
vN 1 O vN 2 D f.Ev1 ; Ev2 / W Ev1 2 vN 1 and Ev2 2 vN 2 g
O a1 ;:::;ah vN D f.EvŒa1 ; : : : ; EvŒah / W Ev 2 vN g fE[g
O C vN D fEv 2 vN W CO .Ev/ is trueg
The central column extensionally defines each operation in the left column by
describing how each of the resulting relations is constructed. The first two
implement set-theoretic union and difference, respectively, shown as such in the
rightmost column. As we mentioned earlier, a list consisting exclusively of blank
values is not considered a record. We will define the meaning of CO .Ev/ as soon as we
have formalized conditions.
In the same way as scalar operators allow building scalar expressions based on
values and locations, we use the above relational operators to construct relational
expressions, written e,N possibly subscripted, starting from base relations. These
entities are formally defined by the following grammar:
The first production, the order-forgetting coercion of an array into a relation, was
introduced earlier. It provides the base case for building relational expressions.
Such a base relation will typically be an array reference lE, but, by allowing generic
array expressions eE, we implicitly allow extensionally specifying relations using the
existing mechanism for arrays. We do not expect this feature to be commonly used
in practice.
Note that, differently from scalar and array formulas, relational expressions are
based on a fixed and rather small set of constructors. Indeed, the operation op b
N
associated to each operator opN is fixed by the laws of relational algebra, as we saw.
We will expand this collection with additional operators that are naturally lifted from
the spreadsheet world later in this section. We will extend it in a different direction
in the next few chapters with powerful deductive capabilities. We denote the set of
all relational expressions by R.
4.3 Extending Spreadsheets with First-Class Relations 77
CO W V I ! ftrue; falseg
where V I is the set of vector values of geometry I . Records that CO maps to true will
be selected, while those that evaluate to false will not. The formal definition of the
application CO .Ev/ is given next:
2
.a v/.Ev/ is true $ EvŒa
O v is true
3.a a /.Ev/ is true $ vEŒa
0
O EvŒa0 is true
3 ^ C /.Ev/ is true c1 .Ev/ is true and C
$ C c2 .Ev/ is true
3
.C 1 2
.C _ C /.Ev/ is true c c
$ C1 .Ev/ is true or C2 .Ev/ is true
.1
1 2
:C /.Ev/ is true $ CO .Ev/ is not true
tb
b v/ is false
rue.Ev/ is true
false.E
is more clear than 3;7 2D6 .Courses HasTaken/. There is an easy way to
reconstruct the indices of a top-level relational expression from the indices of its
base relations. In the rest of this chapter, we will use one method or the other to
refer to attributes. When relying on base relation attributes in a definition, we will
often express them as hE e i:.
A selection or projection operator can refer to attributes that do not exist in the
relation given them as input. Indeed, we can write 4 Students in our example in
Fig. 4.3 although the relation Students has only three attributes. We already observed
this problem when discussing the interface between arrays and relations, but did not
settle on the best approach to addressing it (using default completions or returning
an error relation). A similar problem derives from the fact that we can take the
union or difference of relations whose records do not have the same length, as in
Students [ Grades for example.
A number of useful derived operators can be defined on the basis of the five core
operators of relational algebra introduced earlier. Two particularly useful instances
are join and intersection:
Join: The join of two relations xN 1 and xN 2 according to a condition C , written
xN 1 ‰C xN 2 , is obtained by filtering the Cartesian product of xN 1 and xN 2 through C
and projecting away the attributes that C equates:
Join is maybe the most commonly used relational operator. It is able to construct
records with values contributed by two relations. Differently from , the
condition ensures that only records deemed interesting are retained. As a final
touch, projecting away duplicated attributes retains only essential information.
This behavior is intuitively displayed in the bottom right corner of Fig. 4.5. Note
that the Cartesian product can be defined on the basis of a primitive notion of
join: xN 1 xN 2 D xN 1 ‰true xN 2 .
The form of join whose condition only equates attributes (i.e., uses only D as
a comparison operator and only ^ as Boolean glue) is particularly common.
It is called natural join and the condition is generally omitted when it can
be unambiguously reconstructed. This is the case when attributes are specified
using symbolic names, and different relations rely on the same name to refer to
homologous attributes.
As an example, assume we are interested in correlating the grades students
received in a class with the instructor who taught it. The following relational
expression will produce records including the name of an instructor and every
grade he has ever given:
The next expression creates a relation that differs from HasTaken only by the fact
that all grades have been replaced by their numerical equivalent.
Notice that the condition on the first join is implicit as it equates the Student
attribute of relations Students and HasTaken.
The relation featuring the complementary condition contributes to an expression
that returns the students who have never received a grade lower then A:
First;Last Students
First;Last Number3:50 .Students ‰ HasTaken ‰GradeDLetter Grades/
AA
AB AC ··· ··· AE AF ···
1 Members StudentsWithAs
2 First Last Name First Last
3 = ¼ First ,Last ¾ Number >3.50
= Students ∪ Instructors ( Students / HasTaken
/
4
5
// Grade = Letter Grades )
··· AK AL AM AN ···
1 HasTakenNum
2 Student Course Semester Number
3
= ¼ Student , Course , Semester , Number
HasTaken / Grade = Letter Grades )
4 /
5
2 Names GradeInc
3
A number of extensions of the five core relational operators have been proposed to
gain in succinctness or expressive power when querying a database. Some of these
extensions are particularly relevant in the context of a spreadsheet since they tighten
the integration between the functional and the relational paradigms. We examine
two of them:
• The base conditions of the selection operation compare an attribute to either a
constant or another attribute. It is natural to generalize it to the comparison of two
“attribute expressions”, entities that differ from scalar expressions by allowing
attributes to appear in them.
For example, the following relational expression makes use of this extension
to return the name of all the students whose grades dropped (or rose) by more
than one point over the course of their studies:
where the operator abs returns the absolute value of a number, and the
superscripts allow distinguishing the two instances of HasTakenNum and their
attributes. Notice that the (highlighted) selection condition is now a complex
expression involving attributes.
4.3 Extending Spreadsheets with First-Class Relations 81
It should be observed that both of the above behaviors could have been realized
using only the core relational operators and array expressions, but not as a
single formula: intermediate tables are needed where relational and functional
computations meet. Consider the first expression above:
1. Compute the relational expression
and save it on three adjacent columns. Call them Student, Num1 and Num2,
respectively.
2. Insert the following array formula on the next column,
abs.Num1 Num2/
Call it Diff .
3. Now, interpret Student, Num1, Num2, and Diff as a relation Aux and feed it into
the following relational expression:
These three formulas achieve the same effect as the extended relational expression
shown above. Four additional columns are needed, however, and the rationale
behind it is fragmented. This is clearly displayed in Fig. 4.7, whose upper part relies
on the above extended relational expression while the central part implements the
approach just described. The bottom part of this figure shows the second extended
relational expression above and its emulation using only core relational algebra and
arrays. The difference is not as marked in this case.
Both extensions rely on the notion of attribute expression, which we denote by
the non-terminal æ, possibly subscripted, and we formalize as follows:
··· BA ···
1 BigGapStudents
2 Student
3
··· BC BD BE BF BG ···
1 Aux BigGapStudents’
2 Student Num1 Num2 Diff Student
3
4 = ¼ Student (1) ,Num (1) ,Num (2) =abs( Num1 − Num2 ) = ¼ Student ¾ Diff >1.0 Aux
5 HasTakenNum (1)
6
// Student (1) = Student (2)
(2)
7 HasTakenNum
8
We now need to extend the relational semantics introduced above to account for
these changes. So far, the operation corresponding to each operator was defined on
values of the appropriate syntactic category, the only exceptions being selection
and projection, which also mentioned attributes as place-holders for evaluated
record elements. Attribute expressions can contain attributes deeply buried within
layers of operators. The operations corresponding to the extended projection and
selection will accept an evaluated form for attribute expressions which may still
have attributes as arguments of scalar operators, but all of whose scalar expressions
will have been reduced to values. In particular, an evaluated attribute expression,
which we denote by æ, O does not contain locations:
Then, the semantics of selection does not change, at least superficially, while the
line for projection is significantly altered:
3
.æO æO 0 /.Ev/ is true $ O æO 0 .Ev/ is true
O v/
æ.E
O v/
a.E D EvŒa
vO .Ev/ D v
7
op.æ1 ; : : : ; æn /.Ev/ D op.
b æO 1 .Ev/; : : : ; æO n .Ev//
Pseudo-relational Operators
··· CA CB ···
1 StudentsWithGPA
2 Stude nt GPA
3
SUM( ¼ Number [¾ Student =CA3 :CA HasTakenNum]) /
= ¼ Student Student =
4
COUNT ( ¼ Course [¾ Student =CA3 :CA HasTakenNum])
5
An array version of this formula can then be used to automatically compute the GPA
of all students.
This formula computes the desired result. In the light of the work in this section,
it is worth observing that the same effect is obtained by providing array equivalents
of the relational operators. Consider for the time being the array projection E aE eE
that differs from relational projection by the fact that it does not collapse duplicated
records (and that the ordering of the output array is deterministic, a property we will
not use). Then, the computation of “Nick Vitter”’s GPA is given by the following
expression:
Again, this can easily be adapted to compute the GPA of every student automatically.
Figure 4.8 shows how to do precisely this.
We now go through the operators of relational algebra and comment on the
corresponding array operators.
Union: The natural array counterpart of relational union is the append operation.
Given two arrays xE1 and xE2 , the expression xE1 [ E xE2 makes a copy of xE1 and
inserts a copy of xE2 after it. Of course, there are two ways of doing so: xE2
could be appended below xE1 , or to its right. Therefore, we shall annotate [ E
with the orientation in which the fusion should take place. We obtain xE1 [ E V xE2
(for vertical append) and xE1 [E H xE2 (for horizontal).
Projection: We have already encountered E aE eE as the multiplicity and
order-conscious adaptation of relational projection. Differently from concate-
nation, the attributes aE will specify the orientation of the operation. Note that
7
More precisely, the third argument would be a reference to a range of cells containing syntax
specifying the condition.
4.3 Extending Spreadsheets with First-Class Relations 85
Given the notions of relation and relational expression defined in the previous
section, we are ready to formalize the relational extension of a spreadsheet. Each
location in our example spreadsheet either contains a scalar expression, or is the
target of an array expression or of a relational expression. Therefore, following our
steps from Sect. 4.1, we parcel out the set L of available locations and assign an
expression to each partition. Thus, a relational spreadsheet consists of the following
two components:
1. A partition L of the set L of all locations into disjoint arrays, i.e., a function
L W L ! LI that maps each location l to an array lE such that l 2 L.l/. Each
array lE has its own geometry IlE.
2. A function s W flgE ! E I [ ENI that associates either an array expression eE 2 E I
or a relational expression eN 2 ENI to each element lE in this partition.
The following schema may help visualize this definition:
⎫
L LI ⎪
⎪
⎬
s
⎪
⎪
⎭
E EI E¯I
where the case for scalars (E) is once more implicitly accounted for as 11-arrays
in the definition itself.
86 4 The Relational Spreadsheet
To
From
Arrays Relations
r
æ →
Arrays ∪ a
→
r r
→
Relations a a
→
Fig. 4.9 Choices for the notion of subexpression in the relational spreadsheet
E s/ as s, and retrieve
As with arrays alone, we generally refer to a spreadsheet .flg;
E
the partition flg from the domain of s when needed. The geometry IlE of lE must
match the geometry of the expression s.l/ E assigned to this range of cells. As in
the case of arrays, the geometry of this expression is expected to be automatically
E in practice. Similarly to traditional spreadsheets, a large number of
adjusted to fit l,
cells in L will typically be blank, i.e., contain the blank value [.
The above definition differs from the corresponding notion for arrays in
Sect. 4.1 only by the added option of having an array reference contain a relational
expression. Not surprisingly, the definitions of referential closure of a relation
with respect to s remain unchanged. For convenience, we report from Sect. 4.1 the
component-wise version of this notion, s , which is the one we will use in defining
well-formed relational spreadsheets.
The component-wise referential closure of a relation with respect to s is the
relation s given by:
• s.L.l//Œ s l for all l 2 L, where l D L.l/Œ;
• eE s eE0 if eE eE0 ;
• eE s eE00 if eE s eE0 and eE0 s eE00 .
We need to complement this definition by specifying the meaning of s.L.l//Œ when
L.l/ contains a relational expression eN and when L.l/ contains an array formula of
N This last case falls back on the first by setting ŒeŒ
the form Œe. N D eŒ.
N Now, let a
be the attribute of eN of which is a subindex. Then, we simply set eŒ
N D e:a.N
Our next task shall consist in devising an appropriate notion of subexpression,
whose referential closure will allow us to define the concept of dependency,
which will again be an important ingredient in defining well-formed spreadsheets.
The definition of subexpression for arrays, written v in Sect. 4.1, will change
minimally. Instead, there are at least two meaningful choices for its relational
counterpart: we can either follow entire relations, or we can track just their attributes
(tracking records makes little sense since a relation is a set of records—we will
however revisit this statement in Sect. 4.5 when examining updates). Figure 4.9
summarizes this situation and also accounts for the interface between the two
sublanguages. We begin by defining the two candidate notions of relation-level
subexpression and then adapt the array-level counterpart.
4.3 Extending Spreadsheets with First-Class Relations 87
Relational Subexpressions
The most intuitive notion of sub-expression for relations simply looks at the
arguments of the operators. Given two relational expression eN and eN 0 , it takes the
form eN vr eN 0 and is defined as follows:
eN vr eN
eN vr eN1 ? eN2 if eN vr eN1 or eN vr eN2 where ? 2 f[; ; g
eN vr C eN 0 if eN vr eN 0
eN vr æ E eN
0
if eN vr eN 0
We write @r for the strict variant of this relation, which we call relational
subexpression.
This purely syntactic form of subexpression will be very useful below. It should
be noted, however, that it is very coarse. Indeed, it may the case that eN vr eN 0 ,
but what eN contains has no effect on eN 0 . Consider for example the expression
Student Students Grades. Clearly, Grades vr Student Students Grades.
However, all attributes of Grades are projected away and therefore no record in
this relation can influence the result of this expression. The attribute-level notion of
subexpression will address precisely this problem.
Before introducing it, we present the natural extension of vr to the relation-array
interface. A relation eN is a subexpression of an array eE, written eN @r eE, if it
syntactically occurs within eE. Formally:
eN @r ŒeN 0 if eN vr eN 0
eN @r op.E
E e1 ; : : : ; eEn / if eN @r eEi for some i D 1::n
eN vr eN 0 :a if eN vr eN 0
Dependent Attributes
hE
e i:a va hE
e i:a
e i:a v .eN1 ? eN2 /:a0
hE a
if hE
e i:a va eNi :a0 for i D 1::2 where ? 2 f[; g
(
e i:a va eN1 :a0
hE if 1 a0 jeN1 j
hE
e i:a va .eN1 eN2 /:a0 if
e i:a va eN2 :.a0 jeN1 j/ if jeN1 jC1a0 jeN1 jCjeN2 j
hE
hE N 0
e i:a va .C e/:a if hE
e i:a va e:a
N 0
or hEei:a 2 Attr.C /
hE
e i:a va .æ1 ;:::;æh e/:a
N 0 if hE
e i:a 2 Attr.æa0 /
or hE N
ei:a 2 Attr .e/
The rationale for projection is similar: observing that a0 must be one of the
projection indices 1::h, we can simply check whether hE
e i:a is mentioned anywhere
in the attribute expression æa0 , expressed as hE
ei:a 2 Attr.æa0 /, or we can look
for hE
ei:a in any selection condition within e. N We first formalize the function
N
Attr .e/:
Attr .hEe i/ D ;
Attr .eN1 ? eN2 / D Attr .eN1 / [ Attr .eN2 / where ? 2 f[; ; g
Attr .C e/ N D N [ Attr.C /
Attr .e/
Attr .æ E e/N D N
Attr .e/
Both Attr.C / and Attr .e/N rely on the function Attr.æ/, which collects the
attributes appearing in an attribute expression æ:
Attr.e/ D ;
ei:a/
Attr.hE D fhE
ei:ag
S
Attr.op.æ1 ; : : : ; æn // D i D1::n Attr.æi /
4.3 Extending Spreadsheets with First-Class Relations 89
hE N 0
ei:a @a Œe:a if hE
ei:a @a e:a
N 0
hE
ei:a @a .op.E
E e1 ; : : : ; eEn //:a0 if hE
ei:a @a eEi :a0 for some i D 1::n
Functional Subexpression
The notion of subexpression for array and scalars is defined exactly as in Sect. 4.1:
eE v eE
E e1 ; : : : ; eEn /
eE v op.E if eE v eEi for some i D 1::n
N
eE va e:a if hE
e 0 i:a0 @a e:a
N and eE v eE0 Œa0 for some a0
where the notion of attribute eEŒa of the array formula underlying a base relation hE
ei
was defined earlier.
Simply replacing va with vr in the above definition is not sufficient to obtain
an adequate notion of dependency of a relation eN on an array eE. Indeed, eE can not
N base relations, but it can also be mentioned in one of its
only appear in one of e’s
attribute expressions. Therefore, the relation-level variant of this notion, which we
write eE @r e,
N shall be defined as follows.
eE @r eN if eE v eE0 and hE
e 0 i vr eN
or eE @ eN
æ
where the relation eE @æ eN formalizes the fact that eE occurs in an attribute expression
N
of e:
eE @æ C1 ? C2 if eE @æ C1 or eE @æ C2 for ? 2 f^; _g
eE @æ :C if eE @æ C
eE @æ æ1 æ2 if eE væ æ1 or eE væ æ2
In turn, this definition relies on the similar notion for attribute expressions, eE væ æ:
eE væ e if eE v e
eE væ op.e1 ; : : : ; en / if eE v ei for some i D 1::n
Well-Formed Spreadsheets
When chasing subexpressions across references, we have the choice of using either
vr or va to cope with relations:
• In the first case, we rely on eE v eE0 when comparing array expressions, on eN vr
eN 0 for relations, and on eN @r eE and eE @r eN at the boundary between the two
sublanguages. Let v+ r be the resulting relation. Formally but with a slight abuse
of notation, v+ r D .v [ vr /. We denote the strict version of this relation by @+ r .
As an example, consider the relation eN D Instructor;Grade .Courses
‰AbbrvDCourse HasTaken/, where the relations Courses and HasTaken occupied
cells H 3WJ and P 3WS , respectively, with the attributes Instructor and Grade
on columns J and S in Fig. 4.3. Then, H 3 v+ r e. N
• In the second case, we similarly use the attribute-centric variants of these
relations, eE v eE0 , e:a
N va eN 0 :a0 , e:a
N @a eE and eE @a e:a, N to define the relation
v as v D .v [ @ /. Again, @ is the strict variant of v+ a .
+ a + a a + a
In the setup above, it is not the case that H 3 v+ a eN because cell H 3 lies on an
attribute, Name, that is projected away in e. N
It is clear that v+ a is finer than v+ r where they are both defined: in particular,
if eE @+ a eE0 , then eE @+ r eE0 .
We can now define the referential closures @+ rs and @+ as of @+ r and @+ a , respectively,
relative to a spreadsheet s. As usual, @+ rs propagates @+ r across the cells of s appearing
in an expression, and similarly for @+ as . Again, if eE @+ as eE0 , then eE @+ rs eE0 . We say that
a location l depends on a location l 0 in s according to @+ r (or according to @+ a ) if
l @+ rs l 0 (or if l @+ as l 0 , respectively).
As an illustration, assume cells DA3WDA of the registrar’s spreadsheet contain
the relational expression Student Number>3:50 HasTakenNum. This is a variant of the
relation StudentWithAs in Fig. 4.7. Consider location DA3. Then, each location l in
4.3 Extending Spreadsheets with First-Class Relations 91
··· EA EB EC ED ···
1 Rel1 Rel2
2 A1 B1 A2 B2
3
Then, it is easy to ascertain that EA3 @+ r EA3, but EA3 6@+ a EA3.
We conclude this section by defining a well-formed relational spreadsheet
as a spreadsheet .L; s/ subject to the same two properties as scalar and array
spreadsheets:
1. Finitely many cells in the domain of s are non-blank.
2. s does not contain any circular dependency with respect to @+ as .
The second condition bases the notion of circular dependency on @+ as because, as we
just saw, it is finer than @+ r . All the spreadsheets we will consider in this chapter will
be well-formed. Thus, we will generally drop the qualifier “well-formed”.
Relations are the distinguishing aspect of the data model underlying relational
databases with relational algebra as their archetypal query language [Cod70,
O’N94]. Having just imported both in the spreadsheet paradigm, it is then important
92 4 The Relational Spreadsheet
to have a clear understanding of what sets the relational spreadsheet apart from a
relational database.
Taking a step back, the purpose of a database is to provide efficient access
to large amounts of data so that queries about these data can be answered with
acceptably small latency. Relational databases isolate the physical layout of the data
into abstract relations. This enables using relational algebra as a powerful query
language.
In contrast, the primary focus of the relational spreadsheet is to provide an aver-
age user with the means to rearrange tabular information in ways she deems useful
or interesting. The user interprets areas of the spreadsheet as relations and writes
relational expressions to combine them and persistently display derived information.
These short descriptions hint at distinct philosophies and applicative targets.
Indeed, the differences are numerous and touch facets related to engineering,
practice and theory. We will articulate them along three axes: the usage of data,
the operator’s required expertise, and the volume of the data. These differences are
summarized in Fig. 4.10.
Data Usage
The relational spreadsheet does not have a notion of query. Instead, relational
expressions (which will be given a textual form in Part II) are used to process
information present in other regions of the spreadsheet (its base relations) and
display it in a fixed cell range. Any update, by insertion, modification or removal,
to a base relation is immediately reflected in the result.
Relational expressions in a spreadsheet are therefore persistent, in the sense that
they remain there until explicitly changed by the user. The values they display is kept
up-to-date with respect to the records present in their base relations. By contrast,
a database query is ephemeral: once an answer has been returned, it takes another
query to display any intervening change. Queries are therefore akin to commands
rather than expressions. A relational spreadsheet will generally contain a small
number of relational expressions, a few dozen at most. Instead, even a small
relational database will be the target of thousands of queries, often issued by
different users.
Needed Expertise
Traditional spreadsheets owe their popularity in large part to the fact that they
enable users with very little computer literacy to perform quite complex tasks. This
key characteristic shall be maintained in the relational and soon in the deductive
spreadsheet.
It takes very little sophistication to issue queries and enter updates in a
relational database. However, the setup and the maintenance of the database itself
require substantial expertise. A database administrator is often a professional with
numerous years of training, a deep knowledge of computer science in general, and
working familiarity with the particular database management software. We will
elaborate on his tasks shortly.
Relational databases are carefully engineered to store very large quantities of data
and efficiently retrieve any portion of them. Nowadays, a database with just a few
gigabytes of data is considered small. Indeed, terabyte-size databases and sometimes
relations are commonly found in large and not-so-large organizations. Database
hardware with enough main memory to allow direct access to such volumes of data
is conceivable, especially with the widespread availability of 64-bit architectures,
but would be prohibitively expensive. For this reason, a database management
system keeps data on secondary storage and copies blocks in main memory as
needed to efficiently answer queries. For efficiency, fault-tolerance and privacy, data
are often distributed on several disks and increasingly over several servers.
Because each disk access takes several milliseconds, quite some ingenuity is
required to ensure that queries will be answered within a time acceptable to a user.
This is realized, in part, by implementing efficient algorithms and data structures in
94 4 The Relational Spreadsheet
the database software. The most critical aspect in minimizing disk access, however,
is the layout of the database itself, which is the responsibility of the database
administrator. This begins when the database is first set up with the identification of
the relevant attributes and their allocation to relations on the basis of their functional
dependencies, i.e., the expected relationships among the information they represent.
This results in optimally sized records, which can be uniquely identified by just
a few attributes (often just one) known as a key. This permits defining a system
of indices that enables retrieving records of interest with a minimum number of
disk accesses, often just one if a key is given. Relations and indices are then
stored on disk in such a way that objects that will likely be accessed together
reside on the same block or on contiguous blocks. Attribute relationships and other
properties are often retained in the form of integrity constraints which are later used
to validate updates to the relation: this permits both ensuring the logical consistency
of the data, and making sure that the effectiveness of indices and the physical layout
are retained.
The administrator’s role continues after the initial setup phase by fine-tuning
the performance of the database, and reflecting changes to the data being modeled
(for example by adding attributes). One useful tool, especially for backward
compatibility, is the view, i.e., a virtual relation implemented as a relational
expression. Because it takes so much effort to design a database, these applications
are generally multi-user.
8
Up to around 2005, personal computers had rarely more than 512 MB of main memory, that
virtual memory and swapping extended to 4 GB (on a then-common 32-bit architecture), at the
price of performance. This is also the maximum size of a sheet in current commercial spreadsheet
applications: indeed, sheets are limited to 65,536 rows and 256 columns, or about 16 million cells,
and each cell can contain a maximum of 256 characters, which means that a sheet full to the seams
would be about 4 GB. Nowadays, 64-bit architectures remove this limitation to all practical effects,
while commodity computers with RAM in excess of 4 GB allow keeping large spreadsheets in main
memory.
4.4 Evaluation 95
4.4 Evaluation
Having defined what the relational extension of a spreadsheet is, we now turn
to describing how to evaluate it. Before presenting any procedure, Sect. 4.4.1
comments on the cost of evaluating a relational expression in comparison with
traditional formulas. Following our footprints from Chap. 3, we begin in Sect. 4.4.2
with the routine extension of the naı̈ve evaluation strategy to account for relations
and their interface operators to scalars and arrays. We upgrade the definitions of
dependency graph and related concepts in Sect. 4.4.3, and revisit the semi-naı̈ve
strategy of Chap. 3 in Sect. 4.4.4. The most interesting aspect of computing with
relations has to do with devising efficient strategies for propagating updates,
an aspect we address in Sect. 4.5.
4.4.1 Cost
Since scalar operations take a fixed number of arguments, the cost of evaluating
them does not depend on the input they are given: they have constant cost, O.1/.
Things change as soon as we bring arrays into the picture. Consider component-wise
addition as a simple example: assuming that its arguments have size n, it will
perform n scalar additions, for a linear cost O.n/. As it does so, it also writes n cells,
which entails that the cost per cell of output is still constant. Reasoning similarly,
96 4 The Relational Spreadsheet
SUM has cost O.n/, and since its result is a scalar, the cost per cell is now O.n/.
These upper bounds are typical of scalar and array operations.
Because they manipulate entire relations, it may be expected that the operations
of relational algebra are extravagantly expensive. Figure 4.11 assesses their
worst-case cost along the same three dimensions used in the case of scalars and
arrays: the maximum number of elementary operations, the maximum size of their
output, and the maximum unitary cost. Although not relational, we have included
SORT since we championed it in Sect. 4.3.2 and because sorting plays a role in
determining the cost of most purely relational operations. In the figure, the unit of
data is taken to be the record rather than the individual cell. Argument relations
are assumed to have length n. For SORT, n is the number of items to be sorted.
It is assumed that the size of the condition C of a join or a selection is insignificant
compared to n, and similarly for the attribute expressions of a projection. Finally,
the input relations and the result of evaluation are required not to contain duplicates.
The rationale behind the upper bounds in Fig. 4.11 is as follows:
• Sorting is well known to have complexity O.n log n/. Since its output has always
length n, the unitary cost is therefore O.log n/.
• Implementing union as a simple append would have linear cost, but the result
may contain duplicates. Finding and removing duplicates is equivalent to sorting
either the input relations or the result of an append. Sorting has cost O.n log n/.
The result relation clearly contains O.n/ records, which yields a unitary cost of
O.log n/, just like sorting.
• The difference of two relations can be computed by sorting them, which again
has cost O.n log n/, and then performing a parallel linear scan on the two sorted
relations. Again, the maximum length of the output is O.n/. The maximum cost
per output record is however O.n log n/ because the output relations may contain
just one record independently from the value of n (it may indeed be empty,
a situation we exclude from this computation).
• Cartesian product is inherently quadratic, as both overall cost and number of
records produced. The unit cost is however constant.
4.4 Evaluation 97
• Because a join with condition true simulates a Cartesian product, join has
quadratic worst-case cost and output size. However, just like difference, its output
can also be very small, which yields a worst-case unit cost of O.n2 /.
• A selection can be implemented as a linear scan of its input relation, without any
need to sort it first, and the size of the result is clearly linear as well. Because
again all this work can retain a single record, the unitary cost can be as high
as O.n/.
• While a projection can be implemented linearly, ensuring that the output relation
is free from duplicates again costs O.n log n/. The other bounds of this case are
obtained as in the case of selection.
These bounds are higher than for the scalar and array examples at the beginning
of this section. It is important to keep in mind, however, that these costs reflect
worst-case scenarios. Average figures will indeed be substantially lower for many
of these operators. For example, join conditions will generally narrow the result
down to a sublinear number of records. Sorting the arguments of a natural join over
the common attribute will often be the dominant factor of the actual cost of this
operation.
Because relational operations are seldom used in isolation, it is useful to extend
this investigation to relational expressions. In the worst case, a relational expression
eN mentioning m base relations will have a cost that is polynomial in m, as shown in
Fig. 4.11. In practice, these costs are much lower: the output of eN will typically have
length comparable to n and the overall cost will rarely be more than quadratic.
Because of these potentially high costs, relational databases include a number
of mechanisms aimed at mitigating them. We have already encountered indices,
which provide constant-time access to specific records (note that these are disk
accesses). A complementary approach involves the gathering of numerous statistics
about attribute values, which can often help decide in which order to perform the
operations prescribed in a query. This is called query optimization. It should be
noted that, although base relations are stored on disk, it rarely takes more than a few
seconds for a database to answer a query.
Because a relational spreadsheet contains few relational expressions and because
they change frequently, the role of query optimization is not as prominent as in
a database. In fact, it may be counterproductive to collect elaborate statistics if
they will be used only once. Inexpensive optimizations, for example relational
expression normalization, are still quite welcome. Which optimizations should be
kept in the relational spreadsheet requires further analysis. The availability of fewer
optimizations is balanced by the fact that a relational spreadsheet resides in main
memory and that its relations will generally be small compared to a database.
For this reason, we expect actual evaluation time to be no worse than a typical
database query time, and in fact much better (recall that memory access is 100,000
times faster than disk access).
As we will see shortly, relational expressions need to be evaluated in full
only when loading the spreadsheet. Therefore, the overhead of full evaluation is
a one-time event. As in traditional spreadsheets, recalculation is expected to be
98 4 The Relational Spreadsheet
bE ? .Ev1 ; : : : ; Evn /
op D b
f 7! op
E ? .Ev1 ; : : : ; Evn /Œ W 2 Iop
Eg
8
<?N if r 2 vN i and rŒ D ? for some i D 1::n and 2 INvi
bN ? .Nv1 ; : : : ; vN n /
op D
:op.N
bN v1 ; : : : ; vN n / otherwise
e@ v@ D v
l @ D .l/
e1 ; : : : ; eEn / @ D
op.E b ? .E
op e1 @ ; : : : ; eEn @ /
eE @ eE @ D f 7! eEŒ @ W 2 IeEg
N @ D ŒeN @
Œe
The last case in this definition deals with the interface from relations to arrays. If eN
evaluates to the undefined relation ? N in , then its unsorted coercion into an array
will also contain ? at every index.
The evaluation of a base relation hE ei in an environment is simply the value
of this expression evaluated as an array. The evaluation of complex expressions
relies on the application of each extended relational operation to the evaluation of
its arguments.
eN @ hE
ei @ D eE @
N eN1 ; : : : ; eNn / @ D
op. b
opN ? .eN1 @ ; : : : ; eNn @ /
It is worth expanding this last line for each of the five core operators of relational
algebra, or more precisely their extension as of Sect. 4.3.2:
100 4 The Relational Spreadsheet
C @ .æ1 æ2 / @ D æ1 @ ? æ2 @
.C1 ^ C2 / @ D C1 @ ^? C2 @
.C1 _ C2 / @ D C1 @ _? C2 @
.:C / @ D :? C @
true @ D true
false @ D false
8
E 7! .s.lE/ @ /Œ W 2 IEg if s.l/
[ < flŒ E 2 EI
ER s ./ D
l
: flE 7! s.lE/ @ g E 2 EN
if s.l/
E
l2dom s
Notice that in the relational case, there is no fixed mapping between subvector in lE
and the records returned by the evaluation. Indeed, where a record will be written in
lE is unpredictable in general, and may vary between two rounds of evaluation.
In spite of the numerous additional cases, the substance of the definition of
ER s does not change from the purely scalar setting of Chap. 3: it refines its input
environment by replacing ? with a proper value whenever all the arguments of
the expression associated with a cell are fully evaluated, and leaves ? unchanged
whenever this is not the case. In particular, it is a simple exercise to verify that this
functional is still monotonic and continuous with respect to the partially ordered
set .Env; Env / of all environments under the ?-eliminating ordering Env —indeed
.Env; Env/ did not change from Chap. 3, and therefore is still a lower semi-lattice.
Thus, by Kleene’s theorem, the least fixpoint of ER s is obtained by iterating this
functional starting from the bottom of this lattice: ?. Since each application of ER s
necessarily removes some occurrence of ? and a spreadsheet contains finitely many
non-blank cells, this iterative process will terminate with a spreadsheet containing
a proper value in each of its cells. Therefore, the naı̈ve evaluation of a relational
spreadsheet s is once more given by the following formula:
evaluation.s/ D lfp ER s
cost D O.cells2s /
By observing that the number of iterations cannot be larger than the length of the
longest chain of dependencies in s (call it ds ), we can refine this result to the exact
formula
cost D ds cellss
where the cost is given in terms of the number of cells that are written in a full
evaluation. This figure is still quadratic in cellss , in the general case. As for scalar
spreadsheets, semi-naı̈ve evaluation refines ER s into a better strategy with linear cost
(which is optimal).
102 4 The Relational Spreadsheet
As in the scalar setting, the dependency graph of a relational spreadsheet and the
notions derived from it are a powerful aid for the advanced analysis of these objects.
Similarly to Chap. 3, we will use them to visualize various types of spreadsheet
information (from the raw dependencies of cells to the evaluation process), to
precisely calculate the cost of evaluation, and to refine the evaluation algorithm
outlined in the previous section into the optimal semi-naı̈ve strategy. Unfortunately,
the large number of cells participating in a typical relational expression will force
us to limit the number of examples we will present and to restrict them to fragments
of the registrar spreadsheet in Figs. 4.3 and 4.6–4.8.
The dependency graph DGs of a scalar spreadsheet s contained an edge from
a location l1 to a location l2 precisely when l1 was a subexpression of s.l2 /. With
two relational notions of subexpressions, attribute dependency @a and relational
subexpression @r , we can use either one as the basis for a relational dependency
graph.
Attribute-Dependency Graph
⎧
⎪
⎪ BQ3 BQ4 BQ5 ···
⎪
⎨
Grades5
⎪
⎪
⎪
⎩
BP 3 BP 4 BP 5 ···
⎧
⎪
⎪ Y3 Y4 Y5 ···
⎪
⎨
Grades
⎪
⎪
⎪
⎩ Z3 Z4 Z5 ···
Grades5.Num5
BQ3 BQ4 BQ5 ···
Grades5 .Letter
BP 3 BP 4 BP 5 ··· ···
= BP3 BP
Grades.Letter
Y3 Y4 Y5 ··· ···
Grades.Number
Z3 Z4 Z5 ···
Grades.Letter Grades.Number
dotted line circumscribe cells belonging to the same attribute, either in a base
relation or in a relational formula. Additionally, it replaces the field of edges from
row Y to row BP with a single dotted edge between attributes Grades:Letter and
BP 3WBP (or equivalently Grades50 :Letter).
We formalize this representation as the two-level attribute dependency graph of
a relational spreadsheet s, written DGAs . It is defined as follows:
• The nodes of DGAs consist of the set LI of location arrays:
Nodes.DGAs / D LI
104 4 The Relational Spreadsheet
The nodes of interest are any non-blank individual location mentioned in either
the domain or the range of a spreadsheet s, plus all location arrays that identify
an attribute of a base relation in any relational expression eN in s (that is, flE W
lE D eEŒa and hE
e i:a va eN for eN 2 range sg), plus any array reference hosting
E W a 2 Attr.e/
an attribute of a calculated relation eN in s (that is, flŒa N and eN 2
N is the set of attributes of relational expression e).
range sg, where Attr.e/ N
• DGAs contains an edge n1 n2 from a node n1 to a node n2 whenever n1
occurs dependently within s.n2 /, where this notion is understood as an attribute
projection whenever n2 refers to a subrange of an array in dom s. Additionally,
we have containment edges l ! lE whenever l 2 lE and lE ! l if the reverse
2 3
2
In the central part of Fig. 4.12, we have represented the containment arrows !
3
and ! by putting one node inside the other. Also, we have used a dotted edge
for attribute-level dependency.
The notion of path is defined for DGAs in the same way as for DGas . It can easily
be checked that any path na1 na2 in DGas corresponds to a unique path nA1 nA2
in DGAs . This second path contains one regular edge for every edge in na1 na2 ,
plus a number of containment edges. Therefore, when computing the length of a
path in DGAs , we will ignore any containment edge present in it. This implies that
the length jDGAs j of the longest path in DGAs is equal to jDGas j.
The bottom part of Fig. 4.12 further summarizes this information by collapsing
the dotted areas, and merging the solid arrows from Grades:Number to
Grades50 :Num5. We will occasionally use this representation at an intuitive level,
but we refrain from formalizing it.
In Chap. 3, we used the notion of dependency graph (written DGs ) as a jumping
board for displaying other useful types of information. In particular, when composed
with the underlying spreadsheet, the nodes of DGs showed each expression with the
dependencies highlighted by the edges. When composing DGs with an environment,
we obtained a graphical account of the evaluation process and could see how
values propagate along dependency paths. The same holds at the relational level.
We can compose DGAs with the spreadsheet s to visualize the dependencies among
4.4 Evaluation 105
Grades.Letter Grades.Number
A A- B + ::: 4.00 Z 3 − 0.25 Z4 − 0.25 :::
all contained expressions. Figure 4.13 demonstrates this on the fragment of the
spreadsheet examined in Fig. 4.12. The evaluation graph EGAs ./ of s relative to
an environment is similarly obtained by composing DGAs with .
Relation-Dependency Graph
All of the definitions obtained so far were based on the attribute-dependency relation
@+ a . We can follow the same recipe starting from the notion of relational dependency
@+ r , and define similar concepts, but at the coarser granularity of relations.
The relation-dependency graph of a spreadsheet s, denoted by DGrs , is therefore
given by:
• Nodes.DGrs / D L
• Edges.DGrs / D fl1 l2 W l1 @+ r l2 g
Observe that, differently from DGas , DGrs may not be acyclic for a well-formed
spreadsheet s, as in the counterexample at the end of Sect. 4.3.3.
Instead, the abstract relation-dependency graph of s, DGR s , is given by:
I
• Nodes.DGR s / D L , where the interesting portion consists of L and the set of
array references hosting a relation in s, and the array references used as base
relations in a relational expression.
• The edges of DGR A
s are defined similarly to those of DGs , but without any
reference to attributes. Formally, Edges.DGs / is the set of edges n1 n2 given
R
StudentsWithAs BP3:BP
Grades5
BQ3 BQ4 BQ5 ···
BP3 :BP
BP 3 BP 4 BP 5 ··· ···
Grades
Letter
Y3 Y4 Y5 ···
Z3 Z4 Z5 ···
As in the scalar case, the naı̈ve evaluation strategy is highly inefficient because, at
every iteration, ER s recalculates every expression in the entire spreadsheet, including
those held in locations that already have a value (hence redoing previous work) and
those in cells that depend on ?-valued locations (thus, wasting effort). As in Chap. 3,
the semi-naı̈ve evaluation functional, that we denote by EP s , eliminates this redun-
dant computation by updating only ?-valued cells containing an expression all of
whose dependent locations contain proper values: no other expression is evaluated.
The formalization of EP s is very similar to the scalar case. Given a spreadsheet s
and an environment , we partition into two partial functions:
4.4 Evaluation 107
• The restriction s of to just the ?-valued cells that do not depend on any
currently unevaluated location. In symbols,
• The rest of : rs D n s .
This is intuitively rendered in Fig. 4.16. Each step in the semi-naı̈ve evaluation is
then described by the functional EP s defined as follows:
8 9
ˆ
ˆ E 7! .s.l/
flŒ E @ /Œ W 2 IE and s.l/
E 2 E I g=
ˆ
ˆ l
if lE dom.s /
[ < ;
EP s ./ D flE 7! s.l/ E 2 ENI g
E @ W s.l/
ˆ
ˆ
E
l 2dom s ˆ
:̂ E
fl 7! .l/ W l 2 lg if lE dom.rs /
The first two lines, where lE dom.s /, coincide with the behavior of the naı̈ve
evaluation. The last line leaves every cell in dom.rs / untouched. Only the former
case contributes to the number of cells evaluated during any given application of
EP s . The semi-naı̈ve evaluation iterates this basic step a number of times equal to the
length of the longest path in DGas plus 1:
a
evaluation.s/ D EP s s .?/
jDG jC1
cost D cellss
4.5 Updates
E ! E I [ E,
Given a relational spreadsheet .L; s/, with s W flg N an update consists of
two parts, in general:
• A repartition L of the set of locations L, i.e., a partial function L W L * LI
that modifies the geometry of zero or more blocks of cells, and
• An expression update s W .range L ! E I [ E/ N [ .range L range L *
I N
E [ E/ that describes changes in the contents of location arrays. s will
contain an entry for every new item in L, and may contain additional updates
corresponding to changes in the contents of cells that were not repartitioned.
It will be convenient to extend L with all the mappings of L that contribute to s
even if they do not properly change the partitioning of L. Therefore, from now on,
we will assume that range L D dom s.
4.5 Updates 109
and
(
? if l 2 cellss
s .l/ D
.l/ otherwise
Then, we invoke semi-naı̈ve evaluation (or any other strategy) from s to
recalculate the updated spreadsheet. If semi-naı̈ve evaluation is used, exactly
jcellss j cells will be written. This cost is minimal in the sense that it corresponds
to the number of cells affected by the update.
The procedure just outlined retains optimality at the level of units of evaluation:
formulas for scalar or array valued cells, and relational expressions for
relation-valued blocks of cells. If we consider a relational value as a set of records
rather than an entire relation, it is apparent that large amounts of computation may
be wasted. Indeed, an update in a base relation of an expression eN often affects only
N leaving the rest unchanged. Consider for example
a few tuples in the evaluation of e,
the relational expression
introduced in Sect. 4.3.2 (recall that the first join is over the students’ names).
Adding a student at the beginning of the year will have no effect on the evaluated
relation since she will not have taken any course yet. Adding a course record in the
HasTaken relation will add at most one record to the calculated relation, and only if
the obtained grade is A or A and the student never received such a grade before.
While the evaluation of the above relational expression may contain hundreds of
records, the change will impact at most one of them. The effects of removing or
modifying an existing record are similarly focused.
Since recalculating a relational expression often involves a non-insignificant cost,
it is desirable to devise approaches that propagate relational updates at the record
level. Let e.hE N e1 i; : : : ; hE
en i/ denote a relational expression eN built on base relations
hE
e1 i; : : : ; hE
en i. If each hE ei i evaluates to a relational value vN i , for i D 1::n, then
4.5 Updates 111
=⊕ =
(v̄ r) ∪ v̄ (v̄ ∪ v̄ ) ⊕ r if r ∈ v̄ ∪ v̄ (v̄ ∪ v̄ )
r if r ∈ v̄ ∪ v̄
v̄ ∪ (v̄ r) (v̄ ∪ v̄ ) otherwise (v̄ ∪ v̄ ) otherwise
(v̄ − v̄ ) ⊕ r if r ∈ v̄ − v̄
(v̄ − v̄ )
r if r ∈ v̄ − v̄
(v̄ r) − v̄
(v̄ − v̄ ) otherwise (v̄ − v̄ ) otherwise
(v̄ − v̄ )
r if r ∈ v̄ − v̄ (v̄ − v̄ ) ⊕ r if r ∈ v̄ − v̄
v̄ − (v̄ r)
(v̄ − v̄ ) otherwise (v̄ − v̄ ) otherwise
(v̄ r) × v̄ (v̄ × v̄ ) (r × v̄ )
4.6 Explanation
In the scalar case, the dependency graph of a spreadsheet contains all the necessary
information to trace the value of an expression back to the value of the cells it
mentions, to the value of the cells that cater to them, and so on. This constitutes
a powerful explanation mechanism, and as such it is implemented under various
names in all commercial spreadsheets.
The same mechanisms can be extended to support array formulas. Notice that
there is now a choice as to how to proceed: we can either trace the computed array
value as a unit, or trace its individual components. In the first case, we point the
user to the locations that appear in the array formula as a whole. In particular, array
references are always identified as blocks of cells. In the second case, we only need
to trace the dependent locations of the highlighted cell. Because an array formula
can always be simulated by a collection of scalar formulas, this alternative is realized
exactly as in the purely scalar case, by using the dependency graph. Needless to say,
it allows for much more precise explanations. It is all the more surprising, then, that
commercial spreadsheets only make the first option available to the user. Although
array-level explanation can occasionally be useful, component-level tracing is likely
to be much more useful to a user. For this reason, we recommend it be implemented.
A similar analysis applies in the case of relational expressions. We have
developed two types of dependency graphs for the relational spreadsheet: DGrs traces
dependent base relations as a whole, while the finer DGas works at the level of
attributes (DGR A
s and DGs are more structured variants). While they can point to
all the locations that contribute to a relational expression, they do so only at the
level of attributes, if not of entire relations. This is not the type of question a user is
likely to ask.
Instead, a user will want to know where a particular record showing in the
output comes from. A proper answer will point her to the cells that contain records
(or individual values, e.g., within a selection condition) that cause this record to be
produced, and to the records they derive from, and so on. Another likely explanation
request is about why an expected record is not in the output of a relational
expression. Again, this requires tracing back the evaluation of the expression up
to a point where it is apparent that the requested record could not be produced
(often a selection or a base relation). A variant may inquire about the absence of any
record with a specified value for some attribute. We call the first question positive
explanation and the second negative explanation.
Our dependency graphs are powerless vis-à-vis of these inquiries because
they do not track dependencies at the record level. Some of the data structures
suggested for the purpose of achieving efficient updates incorporate promising
ideas, but developing a reliable infrastructure to answer these requests is likely to be
a demanding task. Luckily, we will not need to do so. In fact, the interpretation
of relational algebra into logic in Chap. 5 will provide us for free with general
mechanisms for answering precisely these questions, and many more.
116 4 The Relational Spreadsheet
4.7 Summary
Traditional spreadsheets make available arrays and operators that take arrays
as input and return arrays as output. We have seen that not only can they be
transformed into equivalent scalar expressions, but that dependencies are tracked
at the component level, consistently with this model. Traditional spreadsheets offer
a notion of relation and rudimentary commands to operate on them.
We have designed a relational extension of the traditional database that not
only models scalars and arrays, but also integrates a first-class notion of relation
and operations (rather than commands) on them. Operators are borrowed from
relational algebra, the mathematical formalism underlying relational database query
languages. This allows constructing relational expressions that manipulate relations
in the same way as traditional formulas operate on scalars and arrays. Functional
(scalar and array) and relational operators coexist in the same expression through
carefully crafted interface operators that allow interpreting an array eE as a relation
hE
ei and a relation eN as an array Œe.
N Figure 4.17 summarizes the syntax of relational
spreadsheet expressions.
A relational spreadsheet is a pair consisting of a partition flg E of the set of
available locations into array references and a function s that assigns each array
reference lE to either an array formula eE or a relational expression e.
N A well-formed
spreadsheet is finite and does not contain circular dependencies among locations,
where the appropriate notion of dependency tracks relational expressions at the
attribute level.
The evaluation of the relational spreadsheet is a simple extension of the
scalar case. Scalar formulas and relational expressions are units of evaluation.
The conceptually simple naı̈ve strategy evaluates them en masse through successive
iterations from the totally unevaluated environment. The semi-naı̈ve strategy
takes dependencies into account to achieve optimal evaluation cost. A number of
dependency graphs facilitate evaluation and support other tasks, such as explanation.
Processing relational updates is substantially different from the functional case
because small changes in a base relation of an expression generally result in very
limited changes in the calculated records. It is generally much more efficient to have
these changes percolate to the output than re-evaluate the whole expressions.
4.7 Summary 117
This chapter takes a transversal step toward the deductive spreadsheet by providing a
logical counterpart of the relational spreadsheet we just defined. By adapting a well-
known translation of relational algebra into first-order logic, our database-inspired
extension of the traditional spreadsheet acquires a distinct logic programming
flavor. Indeed, relational expressions are mapped to a recursion-free variant of
the popular Datalog language augmented with constraints. In this incarnation, the
spreadsheet safely mixes traditional constructs with simple logical formulas rather
than relational expressions. The expressive power of the resulting language is
unchanged, but carefully allowing recursive definitions will significantly extend
its expressiveness at nearly no cost in Chap. 6. This logical interpretation offers a
powerful change of perspective in how we view the relational spreadsheet. This
allows us not only to get a better understanding of the general characteristics of
this extension, but also provides us with a new set of tools for realizing the core
spreadsheet functionalities. Indeed, evaluation, update and explanation are each
supported by one or more fundamental logical concepts, hence further validating our
design with the long history of this field. Furthermore, it sheds additional light on
the interaction of our extensions with the functional core of a spreadsheet. Finally,
the abundant literature on logic programming and computational logic in general is
an essential resource where to start looking for answers to many of the problems
that implementing the deductive spreadsheet will inevitably expose.
This chapter is organized as follows. Section 5.1 recalls some basic notions about
first-order logic, in particular its syntax, model theory and proof theory. In Sect. 5.2,
we describe the logical interpretation of the relational fragment of our current
spreadsheet model, while accounting for its scalar and array components. The
logical language emerging from this translation is examined in the next two sections.
We begin in Sect. 5.3 by concentrating on the purely positive logic programming
language obtained when relational difference is not present in the input spreadsheet.
In particular, we develop the computational aspects of its model theory and proof
theory. Section 5.4 similarly deals with negation as introduced by the logical
translation of full relational algebra. Section 5.5 applies these results to obtain
effective logic-based evaluation techniques for an entire spreadsheet. Section 5.6
revisits updates in this logical light. Section 5.7 recasts explanation, the third major
functionality of a spreadsheet, in logical terms. Finally, Sect. 5.8 summarizes the
work done.
5.1.1 Syntax
1
Many authors fix the term language of first-order logic to be the free algebra generated by a set
of constants, an infinite set of variables, and a set of constructors. Although we will rely on a
simple instance of precisely this scheme, there is no reason not to allow more liberal languages,
for example, featuring types, equational rewriting, or binders.
5.1 A First-Order Logic Refresher 121
A predicate has the form p.t1 ; : : : ; tn /, where the predicate symbol p identifies
which of the many relationships among objects t1 ; : : : ; tn we are referring to. For
example, in a domain of natural numbers, 3 5 and 3 D 5 describe two
relationships between the terms 3 and 5, where we have used the standard infix
notation for the predicate symbols and D. Notice that predicates describe both
relationships that hold (such as 3 5) and relationships that do not hold (such as
3 D 5), where the meaning of “hold” will be discussed later.
Properties of the domain of interest are described using logical formulas obtained
by combining predicates by means of the standard constructors of first-order logic.
These are the logical constants true and false, the connectives ^ for conjunction,
_ for disjunction, for implication, and : for negation, and the two quantifiers
“for all X ” and “exists X ”, written 8X and 9X . We write ' for a logical formula.
The quantifiers bridge the logical layer of predicates and logical constructors,
and the term layer. A variable X in a formula ' is bound if it occurs within the
scope of the quantifier 8X or 9X . It is free otherwise. If ' contains a free variable
X , we can substitute every occurrence of X (that is not in the scope of a quantifier
8X or 9X ) in ' with a term t, an operation that we denote by Œt=X '. A formula
that does not contain any free variable is closed.
Properties are used either to describe the characteristics of the domain of interest,
or to represent consequences of these characteristics. Both types are expressed using
formulas. The formulas corresponding to the descriptive properties of a domain
are variously called a theory, a set of assumptions or hypotheses, a program, a
context, etc. We will generally use the first of these terms and collectively denote
them by .
Before proceeding further, we summarize the various syntactic categories intro-
duced so far in the following grammar:
Terms t WWD X j : : :
Predicate P WWD p.t; : : : ; t/
Formulas ' WWD P j true j false j :' j ' ^ ' j ' _ '
j ' ! ' j 8X:' j 9X:'
Contexts WWD j ; '
Naturally, one of the key questions in logic has to do with establishing whether
a formula ' is a consequence of a set of assumptions . We will now review two
major approaches to doing so for a particular flavor of logic known as classical first-
order logic. The first checks whether ' is a valid property in all the domains in which
each property in is valid.2 The second defines mechanical rules for establishing
logical inferences on the sole basis of the form of ' and .
2
The correspondence between a domain of interest and a logical representation is an entirely
different question.
122 5 The Logical Spreadsheet
The first approach to formalizing logical inference comes from the subfield of
mathematical logic known as model theory. It goes back to the logician Alfred
Tarski. A formula ' is a logical consequence of a set of assumptions , which we
will write ˆ ', if any domain that satisfies every formula in also satisfies '.
A domain is some set D. An interpretation, I , associates every ground term to an
object in D and every n-ary predicate to a subset of Dn . I maps a term with variables
X1 ; : : : ; Xm to a function that when given m domain objects returns a domain object.
An assignment ˛ associates every variable X with some object in D. Together, they
allow mapping any term, possibly with free variables, to an object in D. We write I ˛
for their composition. Then, the validity of a formula ' with respect to interpretation
I and variable assignment ˛, denoted by I; ˛ ˆ ', is inductively defined as follows:
I; ˛ ˆ true always
I; ˛ ˆ false never
I; ˛ ˆ p.t1 ; : : : ; tn / iff .I ˛ .t1 /; : : : ; I ˛ .tn // 2 I.p/
I; ˛ ˆ :' iff it is not the case that I; ˛ ˆ '
I; ˛ ˆ '1 ^ '2 iff I; ˛ ˆ '1 and I; ˛ ˆ '2
I; ˛ ˆ '1 _ '2 iff I; ˛ ˆ '1 or I; ˛ ˆ '2
I; ˛ ˆ '1 '2 iff I; ˛ ˆ '1 implies I; ˛ ˆ '2
I; ˛ ˆ 8X:' iff for all d 2 D it is the case that I; ˛X 7!d ˆ '
I; ˛ ˆ 9X:' iff there is d 2 D such that I; ˛X 7!d ˆ '
where ˛X 7!d is the assignment that differs from ˛ by mapping X to the domain
object d . An interpretation and variable assignment pair .I; ˛/ is a model for a
formula ' if I; ˛ ˆ '. Note that the choice of ˛ is irrelevant if ' is closed.
A formula ' is a logical consequence of formulas '1 ; : : : ; 'n , written
'1 ; : : : ; 'n ˆ ', if for every interpretation I and variable assignment ˛ such
that I; ˛ ˆ 'i for all i D 1::n, it is the case that I; ˛ ˆ '.
The second approach to determining whether a formula ' follows from a set of
assumptions ignores any domain that may be a model of ' and . Instead, it
only looks at the symbols that occur in ' and . It was pioneered by David Hilbert
and Gerhard Gentzen. The interpretation of every logical constructor is given by
a set of purely syntactic inference rules, while predicates and terms are generally
not interpreted. The notion corresponding to model-theoretic logical consequence is
now called derivability: “' is derivable from ” is written ` '. It is established
by chaining a finite number of inference rules into a derivation or proof of ` '.
5.2 The Logic of the Relational Spreadsheet 123
Here are two examples of inference rules, taken from a rule set known as the sequent
calculus:
` '1 ` '2
. ; '; / ` '
0
` '1 ^ '2
The first states that ' is derivable from any context containing '. The second says
that if both '1 and '2 are derivable from , then '1 ^ '2 is derivable from .
The form ` ' above is called a judgment and it expresses a relationship
between various syntactic entities, here and '. This particular type of judgment
is called a sequent. The derivability of a judgment is established by means of
inference rules such as the above. The judgment underneath the horizontal line is
called the rule’s conclusion. A rule also contains zero or more judgments above the
line: they are its premises. Given derivations of instances of all judgments in the
premises, the rule integrates them into a derivation for the corresponding instance
of its conclusion.
A set of inference rules aimed at establishing derivability in first-order logic is
called a proof system. Well-designed proof systems satisfy the correctness theorem,
which requires that ` ' iff ˆ ' for every ' and . There are several such
proof systems. We will not discuss them further in the general context of first-order
logic. We will however present a proof system for the fragment of this logic that is
needed to interpret relational expressions.
Proof-theoretic derivability may appear more readily mechanizable than model-
theoretic logical consequence since the former refers to a finite set of rules while
the latter makes uses of arbitrary domains and interpretations. Not necessarily so.
Establishing derivability is undecidable for full first-order logic, which puts the
apparent mechanizability of proof theory into jeopardy, in general. On the other
hand, some fragments of first-order logic are such that it is sufficient to examine a
single domain and use very specific interpretations. This will be the case below.
3
See footnote 4 for a brief description of how to incorporate scalar and array formulas in the present
discussion.
124 5 The Logical Spreadsheet
than relationally. Second, it will generalize and somewhat simplify the evaluation
methods presented so far, revisiting them within a branch of knowledge with a
much longer history and far more depth than our embryonic study of relational
spreadsheets. Third, it will pave the road for the truly deductive extension of the
spreadsheet in Chap. 6.
We identify the portion of the relational spreadsheet to which we will give a
logical interpretation in Sect. 5.2.1. We then define the translation of relations and
relational expressions in Sect. 5.2.2. Finally, we account for non-relational aspects
in Sect. 5.2.3.
Notice the use of vr since we are tracking entire relations rather than individual
attributes.
• Second, we shall consider every relational expression eN D s.El/ hosted by any
array reference El in s. It will be convenient to identify them not through the
expression eN itself but by the reference El, from which eN can be recovered. It is
formally defined by the set:
We place each of these array references in angled brackets because they are often
used as base relations in other relational expressions. This set is therefore not
disjoint from the previous one, in general.
• Finally, we must consider all relational expressions ŒeN embedded within any
array formula in s. This fragment is formally given by the following set:
N semb D fŒe
RS N vr s.El / for El 2 dom sg
N W Œe
The relational substrate graph of the portion of the registrar’s example shown in
Figs. 4.3, and 4.6–4.8 is displayed in Fig. 5.1. The added relations TAs and AStudents
will illustrate an important concept in a later section.
We write n1 Ü n2 for a path that may traverse either kind of edge. In contrast,
we write n1 ! n2 for a path from n1 to n2 that traverses only ! edges in RSs . Note
that embedded relations of the form ŒeN occur at most as the last element within such
126 5 The Logical Spreadsheet
F&L Names
TAs
CA3:CA F ig 4.8
Grades AStudents
Courses GradeInc
Grades5
BP 3:BP Grades5
a path. For most of this section, we will be primarily interested in the subgraph of
!
RSs consisting uniquely of its ! edges. We denote it by RSs .
!
Because a spreadsheet cannot contain any circular dependency, RSs is acyclic.
Note however that RSs may contain cycles through Ü edges because of its foun-
dation on vr (see Sect. 4.3.3 for a counterexample). There is a simple embedding of
RSs into the abstract relational dependency graph DGR r
s as well as in the simpler DGs .
0 R
A node n in RSs corresponds to the node n in DGs that hosts the relational object
labeling n. An edge in RSs is mapped to a path in DGR s . This path is empty if its
end-nodes are identified in DGR s : this may happen for example if an array reference
El contains a formula with hEei appearing within a subexpression Œe. N
!
We will be particularly interested in the nodes of RSs without any incoming edge.
We will call them primitive relations. They correspond to objects in the spreadsheet
that are used exclusively as base relations. In particular, they are not obtained by
evaluating a monolithic relational expression. Examples in the registrar spreadsheet
include Students, Grades, but also Grades50 and StudentsWithGPAs.
5.2 The Logic of the Relational Spreadsheet 127
Primitive Relations
!
Let p identify an n-ary primitive relation in RSs . Assume that it has been evaluated
to vN (a preliminary step we will not undertake until Sect. 5.5). We can then define
a theory in first-order logic that describes p as vN in s. We take the term language
of this logic to be the set V of all scalar values, in addition to logical variables.
We then consider an n-ary predicate symbol, which we also call p, and define the
logical theory …p associated with p as follows:
…p D fp.Ev/ W Ev 2 vN g
We will substantiate this intuition in Sect. 5.3. Notice that each attribute of the
relation p corresponds to a specific argument of the predicate p.
We can try this out on the Students relation in Fig. 4.3, which is primitive
according to the relational substrate in Fig. 5.1. Then …Students is given by:
Non-primitive Relations
Then it is clear that this judgment will hold for precisely those triples .v1 ; v2 ; v3 / 2
Students such that v1 D “Sue”. Let us collect them in a relation that we
call StudentsSue. We have seen a relational expression that computes precisely
StudentsSue in Chap. 4:
FirstD“Sue” Students
Let StudentsSue be the theory that contains just this formula; then, again appealing to
the intuition, we have that
Therefore, the theory we were looking for is simply the union .…Students ;
StudentsSue / of …Students and StudentsSue .
The above implicational formula defines the predicate StudentsSue in the same
sense as the shown relational expression defines the relation StudentsSue. We can
put them next to each other to compare their structures:
8F:8L:8I:
Student.F; L; I / ^ F D “Sue” FirstD“Sue” Students
StudentsSue.F; L; I / DW StudentsSue
where the last line on the right informally indicates that the expression above
it defines StudentsSue. First, observe that each variable in the formula captures
an attribute in the expression: F , L, and I positionally identify the attributes
First, Last, and Student of each record of the relation Students, and similarly for
StudentsSue; moreover, F is compared to “Sue” in the formula in the same way as
First is compared with this value in the expression. Second, notice that the formula
defines the predicate StudentsSue tuple by tuple while the expression operates in a
relation-at-a-time fashion. This difference in granularity is mediated by universally
quantifying the variables F , L, and I over the whole logical formula. Finally,
observe that the behavior of relational selection is emulated in the logic by taking the
conjunction of its condition with the formula that represents the relational argument,
Student.F; L; I / here.
The observation that logical variables correspond to attributes suggests a simple
way to logically emulate the projection operation of core relational algebra: simply
omit projected-away variables from the arguments of defined predicates. Indeed,
the following logical and relational expressions both describe the set of tuples of
StudentsSue deprived of its redundant first component (which invariably holds the
value “Sue”):
8F:8L:8I:
Student.F; L; I / ^ F D “Sue” Last;Student FirstD“Sue” Students
StudentsSue0 .L; I / DW StudentsSue0
The formula differs from the definition of StudentsSue by the fact that we
have dropped F as an argument to the defined predicate. Note that the
original relational expression for StudentsSue can be equivalently rewritten as
First;Last;Student FirstD“Sue” Students, which brings us even closer to the corresponding
logical formula.
This exercise can easily be continued for all the other operators of core
relational algebra as well as their extensions in Sect. 4.3.2: union then corresponds
to disjunction, difference becomes a conjunction with a negated subformula, and
Cartesian product reduces to the conjunction of two formulas that do not share any
variable. We will now formalize this interpretation by defining a translation function
from relational expressions to logical formulas.
130 5 The Logical Spreadsheet
E ; YE : peq.
8X N X/E p.X
E/
E hEe i / D phEei .X
phEeiq.X E hEei /
pR1 [ R2 q.X/E D pR1 q.X E / _ pR2 q.X
E/
E E
pR1 R2 q.X/ D pR1 q.X / ^ :pR2 q.X E/
E ; YE / D pR1 q.X
pR1 R2 q.X E / ^ pR2 q.YE /
pæE Rq.YE / D YE D æ E / ^ pRq.X
E .X E/
pC Rq.X/ E D C.X/E ^ pRq.X E/
The first line handles base relations hEe i identified in RSs by the symbol phEe i , which
we reuse as a predicate symbol representing hEei. The attributes of this relation are
mapped to the tuple of distinct variables X E hEe i , which is given as the argument of phEe i
and recorded on the left-hand side as the variables to be exported to higher levels.
The next two lines describe the rather simple translation of union and difference.
Note that the two subformulas are required to use the same variables. The treatment
of Cartesian product on the next line is similar but the variable exported by the
interpretation of the two subrelations shall be disjoint (otherwise there would be a
dependency between them) and both sets contribute to the variables exported by the
overall formula. The next line defines the translation of the generalized projection
of a relational expression eN onto a sequence æ E of attribute expressions. For the time
being, we shall assume that æ E does not mention any cell reference (or that they have
been replaced by values in advance). The notation æi .X E / indicates the term obtained
from æi by replacing each attribute it mentions by the corresponding variable in
XE . The projection as a whole assigns each term æi .X E / to a new distinct variable
E
Yi . The notation Y D æ E
E .X / is meant to indicate the conjunction of all equalities
Yi D æi .X E /. Notice that it is the YE ’s that are passed on by the overall formula, not
the XE ’s. The final line handles selection: the notation C.X E / indicates the natural
interpretation of the condition C as a logical formula with attributes replaced with
the corresponding variable in X E . Again, we assume that the embedded attribute
values do not mention cell references.
5.2 The Logic of the Relational Spreadsheet 131
Each implicational formula is called a clause and each logical variable occurring in
it is universally quantified on its outside. A clause is always closed. The consequent,
or head, of the implication is the predicate being defined (such as StudentsSue
above). Its antecedent, or body, is the formula defining it. It can mention predicates
(such as Students), conditions of the general form æ æ with variables for
attribute names, and they can be combined by means of conjunction, disjunction
and negation. Within this logical interpretation, we will refer to conditions æ æ
as constraints. In particular, the form X D æ such that X appears in the head will
be a head constraint.4
This fragment of first-order logic casts our formalism as a member of the
family of logic programming languages [Llo87, MNPS91], whose most successful
offspring is Prolog [CM87, O’K90, SS94]. The presence of constraints further
defines it as part of the constraint logic programming branch [JM94], while the
particular type of terms it uses flags it as a flavor of Datalog [CGT90], which,
not surprisingly, underlies most work on deductive databases. We will give a more
precise characterization in Chap. 6, since it will be lacking one important aspect of
logic programming languages until then.
4
This translation can easily be extended [vEOT86] to express the scalar part of a spreadsheet by
associating each cell l with a unary predicate l.vl / containing the value of l. Then, every scalar
expression e is interpreted into a pair e D .æ; B/ as follows:
X D æ ^ B l.X/
StudentsSue.F; L; I /
Student.F; L; I / ^ F D “Sue”
5.2 The Logic of the Relational Spreadsheet 133
where X E are the variables occurring in B2 that are used in other parts of
Cl. This process can be iterated if B2 contains negative subformulas. If every
comparison symbol has a negated form 6 (for example < and ), the
systematic application of this transformation results in clauses where negation
only precedes predicates. A negated predicate :P in the body of such a clause
is called a negative literal, which suggests the appellation positive literal for a
body predicate P that is not preceded by a negation.
• In the context of a relational spreadsheet s, assume that a clause Cl contains
E / and phEe i .YE / where Ee 2 depends on Ee 1 , i.e., Ee 1 @+ rs Ee 2 .
distinct predicates phEe1 i .X 2
This functional dependency is conveniently handled by replacing any occurrence
E / in Cl with aux.X
of phEe 1 i .X E /, where aux is a new predicate symbol, and by
E
adding the clause aux.X / phEe1 i .X E /.
• By distributing disjunction over conjunction, we can obtain clauses of the form
p.XE / B1 _ : : : _ Bn where each Bi is a conjunction of predicates, negated
predicates, or base conditions, for i D 1::n. Then, we can replace this clause
with the n clauses:
E / B1
p.X
E
p.X / Bn
Overall, these simplifications (all of which have a logical justification) have two
major effects. First, a non-primitive node p in the relational substrate RSs is now
associated not to a single clause defining p, but to a set of clauses, which we collect
into a clausal theory that we will call p . On the other hand, the body of each of
these clauses is much simpler than in the general translation. We will come back to
the exact structure of these clauses in Sects. 5.3 and 5.4, where we will study them
in great detail. We collect the clauses contributed in this way by every non-primitive
134 5 The Logical Spreadsheet
At this point, we can combine the factual theory …s of s and its clausal theory
s into a single theory that we denote by the symbol … s :
0 1 0 1
B C B C
B [ C B [ C
… s D …s [ s B
D B …p C B p C
C[B C
@ p 2 RS A @ p 2 RSs
A
s
p primitive p non-primitive
5.2.3 Stratification
We need to take into account the fact that there may be functional dependencies
between nodes of the relational substrate RSs of s (or equivalently in RSsN ), which
are not accounted for in … s . Indeed, the relation Grades50 defined in Fig. 4.7 is
primitive in the relational substrate graph in Fig. 5.1 (also in Fig. 5.4). However,
its values will not be available until the relation corresponding to node BP 3WBP
has been fully calculated. Any use of Grades50 in determining logical consequences
136 5 The Logical Spreadsheet
should not be allowed until then. Similar observations hold for relations Aux and
StudentsWithGPAs.
In order to handle this issue, we will partition the call graph of … s into
functionally dependent strata that are internally free from functional dependencies.
No logical consequence in one stratum should be attempted until all the logical
consequences of the strata it depends on have been made available. In order to do
so, we shall operate on RSsN , which simply imports the functional dependencies of
RSs , given by its Ü edges, into CG… s .
5.2 The Logic of the Relational Spreadsheet 137
For reasons that will be explained shortly, it is convenient to view any negated
predicate :q occurring in … s as a node :q separate from q but functionally
dependent on it. Therefore, we extend RSsN with the node :q for every predicate
symbol q such that :q occurs in … s , as if it were a primitive predicate itself. If :q
occurs in the definition of a predicate p, then the updated graph will contain the edge
:q ! p rather than q ! p (unless p also depends positively on q, in which case
both edges will be present). Finally, we add the functional dependency q Ü :q
for every such q. We call the graph obtained by this transformation the stratified
relational substrate graph, or more simply the stratified call graph, of s, and denote
fSs . Note that its nodes are literals rather than predicates. The stratified call
it by R
graph corresponding to the relational substrate in Fig. 5.1 is displayed in Fig. 5.4.
Please ignore the dotted line for the time being.
A set & of predicates in … s constitutes a stratum if no path in RfSs between any
two predicates p; p 0 2 & contains a functional dependency (i.e., an Ü edge). In
particular, if p 2 & and :q occurs in a clause defining p, then q 62 &. Let R fSs&
be the subgraph of R fSs whose nodes are the predicates in & plus all the literals
occurring in any of their defining clauses, and whose edges are the restriction of the
edges of RfSs to just those nodes. Note that RfSs& may contain functional dependency
edges. However, if n Ü n occurs in R
0 fSs& (for example if s contains the clause
138 5 The Logical Spreadsheet
&
[ [ [
…s D …p [ …q [ …q
p2& q 62 & q 62 &
P B^q.XE / 2 s& P B^:q.X E / 2 s&
&
The clausal part s is simply given by the set of clauses defining the non-primitive
&
predicates among &. Its factual component …s collects the theories of every
primitive predicate in &, as well as the theory of every predicate q that does not
belong to & but that is mentioned positively or negatively in any defining clause of a
predicate in this stratum. These are treated as if their predicates were primitive. We
will reconcile this aspect with their possible clausal nature in Sect. 5.4.
Figure 5.4 shows two strata, &0 and &1 , whose predicates are the positive literals
on each side of the dotted line. This figure also identifies the subgraphs R fSs&0 and
fSs 1 (the latter also contains the origin of every ! edge crossing into it).
R
&
A stratification is a partition &E D &0 ; : : : ; &n of the set of all predicates occurring
in … s such that &i is a stratum for i D 0::n and if pi Ü pj , for pi 2 &i and
pj 2 &j , then i < j . The functional dependencies among predicates in different
strata induce a functional dependency graph FDs .E& / among strata: its nodes are the
strata of the stratification, and it contains an edge & Ü & 0 if there are p 2 & and
p 0 2 & 0 such that p Ü p 0 in R fSs . By definition this graph is acyclic.
The theory … s is stratifiable if it has a stratification. It is easy to verify that this
is the case exactly when the relational substrate graph RSs is acyclic, which in turn
means that the relational dependency graph DGrs of s is acyclic. In this book, we will
concentrate on stratifiable theories and the spreadsheets that generate them. This
excludes pathological situations such as the one discussed at the end of Sect. 4.3.3,
although our model could be refined to accommodate them.
A stratifiable theory … s may have several stratifications, in general: in the
extreme, each predicate can belong to its own stratum. We will be interested in
stratifications with a minimal number of strata. A stratification &0 ; : : : ; &n is linear
if &i Ü &i C1 for i D 0::n 1. A theory … s has always at least one linear
stratification. A generic stratification can indeed be linearized by merging strata, as
long as functional independence is preserved. Among all the linear stratifications of
s, we will be interested in the one where each predicate occurs in the stratum with the
lowest possible index, short of violating the functional dependency constraint. This
is the least stratification of s. In Fig. 5.4, .&0 ; &1 / constitute a linear stratification
of the set of predicates in the call graph of the registrar’s example. It is its least
stratification.
Stratification is a standard approach for harnessing negation within logic pro-
gramming [CH85, ABW87, Llo87]. It is particularly effective in the context of
deductive databases [CGT90]. It is noteworthy that this very same mechanism
5.3 Inference in a Definite Spreadsheet Theory 139
In this section and the next, we will study those first-order theories stemming from
the logical interpretation of the relational spreadsheet. We first analyze definite
theories, which characterize the least stratum of any stratification. This fragment
of first-order logic, especially its constraint-free sublanguage, is at the very core of
logic programming [Llo87], and as such, it has been the subject of intense scrutiny
in the past 50 years [Rob65, Kow79, MNPS91]. Although the specific language
we are considering does not seem to have received much attention, it is at the
confluence of two important research streams: constraint logic programming [JM94]
and Datalog [CGT90].
In Sect. 5.3.1, we summarize and formalize their syntax and describe two impor-
tant types of graphs associated with them. In Sects. 5.3.2–5.3.4, we examine their
model theory by first describing sufficient interpretations for definite theories, then
characterizing models as the fixpoints of a certain operator, and finally discussing
termination issues. Section 5.3.5 investigates the proof theory of this fragment of
first-order logic.
We now summarize the syntax of definite theories and formalize the notion of call
graph, which tracks dependencies at the level of predicates. We also introduce
another useful type of graph which highlights dependencies at the predicate
argument level.
140 5 The Logical Spreadsheet
Syntax
We called a ground predicate p.Ev/ a fact, and therefore referred to the above sets as
factual theories. We wrote …p for the factual theory of a primitive predicate p.
A relational expression that did not make use of the difference operator was
instead mapped to a set of clauses whose body was a conjunction of predicates
and constraints. A clause whose body does not contain any negative literals is called
a definite clause, and a collection of only definite clauses is called a definite theory
or definite program. They are defined by the following grammar:
to any relational expression. More serious yet is the fact that the deduction methods
described below would fail if they are not enforced. For this reason, we shall
always restrict our attention to safe clauses and theories. Note that the second safety
restriction could be relaxed transitively so that the variables it constrains ultimately
get their values in a predicate in the body of the clause.
The clauses obtained by interpreting a relational spreadsheet in first-order logic
are never recursive: it is never the case that the definition of a predicate p refers
to p itself, either directly by appearing in the body of one of its clauses, or
indirectly by contributing to the definition of any of its body predicates. The main
deductive extension in Chap. 6 will stem from carefully relaxing this restriction. The
study of non-recursive theories in the present chapter will introduce us to many of
the technicalities needed for the general case, but without the additional layer of
complication brought in by recursion.
At this point, a definite theory is simply given by considering a factual theory …
together with a definite clausal theory . Formally,
We will use the symbol … , variously decorated, to denote a definite theory. We will
often factorize … as the pair (…, ) with the same decorations to indicate its factual
and clausal components, respectively.5
Call Graph
The call graph, CG… , of a theory … captures how predicates participate in the
definition of other predicates. More precisely, CG… is formalized as follows:
• Nodes.CG… / is the set of all predicate symbols appearing in … .
• Edges.CG… / is the set of all edges q ! p such that q appears in a clause
defining p:
E / q.YE / ^ B/ 2 … g
Edges.CG… / D fq ! p W .p.X
We observed that the call graph CG… s of a spreadsheet theory … s has much in
common with the relational substrate graph RSs of the spreadsheet s, which itself is
intimately related to the relational dependency graph DGrs . In particular, it is acyclic
5 E/X
It should be observed that every fact p.Ev/ is logically equivalent to the clause p.X E D Ev.
Furthermore, the transformation in Sect. 5.2.2 may itself produce clauses in this form. For these
reasons, many presentations in the literature, especially those concerned with general logic
programming [Llo87] more than Datalog, dispense with factual theories altogether by bundling
facts in the clausal component . In our context, keeping the distinction between facts derived
from primitive predicates and clauses obtained by translating complex relational expressions will
prove advantageous, both conceptually and in terms of presentation.
142 5 The Logical Spreadsheet
and it outlines the dependencies that a theory establishes among the predicates it
mentions.
It is easy to ascertain that, if … s is the theory obtained from the relational
!
substrate of a spreadsheet s that never uses relational difference, then RSs and CG… s
are the same graph.
Dataflow Graph
The dataflow graph DF… of a theory … tracks the dependencies within a definition
not at the level of predicates, but by chasing variables. Therefore, its nodes are the
individual arguments of each predicate in … and its edges relate an argument in the
head of a clause to all the variables that can influence it. It is defined as follows:
• Nodes.DF… / D fpji W p 2 Nodes.CG… / and p has arity n and 1 i ng.
• Edges.DF … / contains two types of edges: qjj ! pji indicates that the i -th
head argument of a defining clause for p contains the same logical variable as
the j -th argument of a predicate q in its body, and qjj ) pji means that the i -th
argument Xi of p is the target of a head constraint Xi D æ.Z/ E in some clause
for p where the j -th argument of q occurs among the Z’s.E In symbols:
the literature, such as [CGT90, LNS82, JM94, Llo87]. One key consequence of
this property is that every definite theory … has a least Herbrand model, I… ,
obtained by taking the intersection of all the Herbrand models of … . Its existence
is guaranteed by the fact that HBV is always a model of … .
The least Herbrand model of a definite theory captures the intended use of clauses
to define a predicate. Indeed, there are Herbrand models of the registrar’s example
containing Students.4:00; “bn”; “S04”/ even if this tuple does not correspond to any
student. Only the least Herbrand model contains facts Students.v1 ; v2 ; v3 / for exactly
those values of v1 ; v2 ; v3 corresponding to students. Similar considerations hold for
predicate symbols that are not primitive.
The definition of logical consequence in Sect. 5.1 implied that, for a definite
theory … and a goal formula B, the judgment … ˆ B holds if every model of
… is also a model of B. For definite goals, this reduces to showing that B is valid
in the least Herbrand model of … , i.e., I… ˆ B. Thus, taking B to be a predicate,
it follows that I… is the set of all atomic logical consequences of … .
If & is a definite stratum in the theory … s of a relational spreadsheet s, this
last observation entails that one way to logically emulate the evaluation of all the
relational expressions corresponding to a predicate in & is to produce the least
&
Herbrand model of … s . This was elegantly achieved by Marteen van Emden and
Robert Kowalski, who characterized the least Herbrand model of a definite theory
as the fixpoint of a useful operator on interpretations [EK76].
clauses, and so on until all the atomic logical consequences of every predicates in
… have been obtained. Notice that this corresponds to following the edges of CG…
upwards from its primitive nodes.
In order to formalize this intuition, we define InstV . / to be the set of all ground
instances of any clause in … , where … and are the factual and clausal parts
of … . We then define the following operator T…; over Herbrand interpretations
of … :
V
T…; .I / D I [ … [ fp.Ev/ W p.Ev/ i D1::m pi .Evi /
V
^ i D1::o vi i v0i 2 InstV . /
and pi .Evi / 2 I [ … for all i D 1::m
and vi O i v0i is true for all i D 1::o g
lfp.T…; / D T…;
!
.;/
We will now show that the above fixpoint characterization of the least Herbrand
model of a definite theory … can be used to effectively compute I… (after some
minor adjustments). We begin by observing that lfp.T…; / is obtained after finitely
many iterations of T…; , whose exact number is a simple function of the length of
longest path in the call graph CG… of … .
146 5 The Logical Spreadsheet
Termination
Let the level of a predicate p in CG… be the length of the longest path from a
primitive node to p. Then, define the set CG… Œi to be the set of predicates in CG…
whose level is i . Then, we have that:
j
If p 2 CG… Œi and … ˆ p.Ev/, then p.Ev/ 2 T…; .;/ iff j i C 1.
The easy proof proceeds by induction on i .
Since every predicate belongs to a finite level, a consequence of this result is that
jCG… jC1
I… D T…; .;/, where jCG… j is the length of the longest path in CG… .
The required number of iterations is only one of the possible sources of infinity
in the above characterization of I… as lfp.T…; /. Another potential problem derives
from the fact that the set InstV . / of all the instances of any clause in … is itself
infinite. We can trace this issue back to the fact that the Herbrand universe V should
abstractly be considered infinite, even if unavoidable memory limitations will bound
it in every spreadsheet implementation.
We will now show that it is sufficient to restrict the Herbrand universe to a finite
subset V… of V which is derived from … D .…; /. The key observation is that
every ground term contributing to I… must necessarily be obtained either from a
fact in … or from head constraints of the form Y D æ occurring in the body of
clauses in . Therefore, starting from the primitive predicates of … , we can walk
up the dataflow graph DF … making a note of all the values we find. This idea is
formalized in the following definitions:
S
V… D pji 2 … Vpji
8
<S
p.:::;vi ;:::/ 2 …p fvi g if p is primitive
Vpji D S
: E VXi jB if p is not primitive
.p.X/B/ 2 p
8T
< E 62 B 0
Xi DYik Vq k jik if .Xi D æ.Z//
V V k Ek D k
„ ƒ‚ … :fæ.v
Xi j k q . Y / ^ B 0 E 2 B0
O 1 ; : : : ; vn / W vj 2 VZj jB g if .Xi D æ.Z//
B
The set V… collects the values that can appear in I… . It is assembled by taking
the union of the sets Vpji for all predicate-argument pairs pji appearing in DF… .
If p is primitive, we simply gather all the values occurring in its i -th argument.
Otherwise, we take the union of the values contributed by each of its defining
clauses p.X E / B to its i -th argument Xi . This is represented by the set VXi jB . How
this set is calculated depends on whether Xi is directly contributed by one or more
predicates q k in B or if it is obtained by means of a head constraint Xi D æi .Z/ E
in B. In the first case, Xi can only assume values made available by all of these
q k in the appropriate position, say ik : hence we take the intersection of all the Vq k jik .
In the second case, we must calculate values for æi . Each variable Zji occurring
in it is instantiated with values in Vq k jjk made available by all body predicates q k
5.3 Inference in a Definite Spreadsheet Theory 147
where Zji occurs (at position jk ). Notice that VXi jB , and therefore Vpji and V… ,
are over-approximations in general since they do not take into consideration generic
constraints of the form æ æ0 possibly occurring in B.
A simple induction on the level of a predicate p suffices to prove that Vpji is
finite. Therefore, since there are only finitely many predicates, V… is finite as well.
Consequently, the set InstV… . / of all instances of clauses of … relative to V… is
finite. We can then rewrite the definition of T…; as follows:
V
T…; .I / D I [ … [ fp.Ev/ W p.Ev/ i D1::m pi .Evi /
V
^ i D1::o vi i v0i 2 InstV… . /
and pi .Evi / 2 I [ … for all i D 1::m
and vi O i vi is true for all i D 1::o g
This updated definition and the above bound on the number of iterations make the
least fixpoint of T…; an effective characterization of the least Herbrand model I…
of … . Another important consequence of the finiteness of V… is that I… itself is
finite.
The set V… may be a wild over-approximation of the set of values that can appear in
I… . This can make our latest characterization of T…; unusable in practice, although
it is theoretically effective.
A more efficient method stems from the observation that the sole reason for
considering ground instances of the clauses in … in the definition of T…; is
that body predicates can be in the right form for testing their membership in the
input Herbrand interpretation. An immediate improvement suggests itself: use this
interpretation to construct the instances of the body of the clause that it satisfies and
propagate the instantiation to the head. This is implemented in the following variant
of T…; [EK76, CGT90], which resurrects variable assignments from the definition
of validity rather than rely on ground instances of clauses:
V V
T…; .I / D I [ … [ f˛.P / W P i D1::m Pi ^ i D1::o æi i æ0i 2
and ˛.Pi / 2 I [ … for all i D 1::m
and ˛.æi /
O i ˛.æi / is true for all i D 1::o g
Observe that the first line picks clauses from rather than from the set of its ground
instances. The variable assignment ˛ is computed from the conjuncts in this clause
and the input interpretation I as well as the factual theory …. We emphasize this
computational interpretation by calling it a substitution. Its computation proceeds
as follows:
• The literals Pi in the selected clause are matched in parallel against I [ …, hence
producing a set f˛j g of candidate substitutions for the clause.
• Each of these substitution ˛ 2 f˛j g is tested against all the generic constraints
E i æ 0 .X
æi .X/ E /. Only the substitutions that validate all constraints are retained.
i
148 5 The Logical Spreadsheet
Note that there may be a multitude of substitutions ˛ validating a clause for a given
input interpretation.6
As mentioned in Sect. 5.1, proof theory offers an alternative stance on defining what
it means for a formula ' to follow from a theory . It differs from model-theoretic
approaches by relying only on the symbols mentioned in and '. We will now
develop the proof theory of definite programs, which is as simple as its model theory.
It is adapted from classical logic programming approaches such as [Llo87] to the
context of the deductive spreadsheet, and also follows a more modern understanding
of logic programming [MNPS91, Pfe].
Let … D .…; / a definite theory and p.Ev/ a ground fact. The derivability of
p.Ev/ from … , denoted by … ` p.Ev/, is defined by means of the following three
rules:
V
.P niD1 Bi / 2 p.Ev/ D ˛.P / …; ` ˛.B1 / …; ` ˛.Bn /
np
…; ` p.Ev/
p.Ev/ 2 … O æO 0 is true
æO
pr gc
…; ` p.Ev/ … ` æ æ0
Rule pr simply asserts that p.Ev/ is derivable from .…; / whenever it occurs in
…. This takes care of the simple case where p is a primitive predicate. Rule np
handles the case where p is not primitive: p.Ev/ is derivable from .…; / if there is
a substitution ˛ and a clause P B in such that p.Ev/ is precisely ˛.P / and the
(ground) instance ˛.Bi / of each conjunct Bi in B is itself derivable from .…; /.
6
This expression will be our final definition for T…; for definite programs. As mentioned in
footnote 5, it is uncommon to draw a separation between facts and clauses in a definite theory since
a fact can be seen as a particular case of a clause. The above operator assumes a slightly different
form in that case, which is commonly seen in the logic programming literature [Llo87, EK76]:
V V
T… .I / D I [ f˛.P / W P iD1::m Pi ^ iD1::o æi i æ0i 2 …
and ˛.Pi / 2 I for all i D 1::m
and ˛.æi / O i ˛.æi / is true for all i D 1::o g
There is a clear correspondence between those three rules and our last expression
for the T…; operator. Indeed, it is easy to show that … ` p.Ev/ iff p.Ev/ 2 I… .
A derivation of … ` p.Ev/ is a tree with this judgment as its root, inner
nodes given by appropriate instances of the above rules, and leaves in the form
of the premises of rules pr or gc. Such a tree constitutes a proof that p.Ev/ is
derivable from … . How this tree, and in general the proof theory of definite
programs, is used depends on the modality by which it is constructed. The
computational interpretations of the two main modalities are radically different:
starting from the leaves and using (variants of) the above rules to produce derivable
facts yields an alternative way of constructing the least Herbrand model I… ;
instead, attempting to build a derivation given only the root judgment corresponds
to answering a query. Proof-theoretically, their difference is accounted for by
the concept of polarization [NM10, LM09] within the context of focused proof
search [And92, How98, Cha06, Sim12]. Both techniques have an application in a
spreadsheet environment. We will now examine them in closer detail.
Bottom-Up Construction
… ` ˛.P1 / b
˛.Y1 / D ˛.æ/1 1
˛ .æ0 /1 1
O 1 ˛.æ00 /1
.P B/ 2 :: :: ::
b 1 1
: : :
… ` ˛.Pm / ˛.Yo / D ˛.æ/o ˛ .æ0 /o0
O o0 ˛.æ00 /o0
np#
…; ` ˛.P /
V Vo Vo0
where B D m i D1 Pi ^ i D1 .Yi D æi / ^ i D1 .æi i æi /. For readability and
0 00
typographic reasons, we have omitted the “is true” part of the constraint validation
premises.
150 5 The Logical Spreadsheet
The bottom-up construction starts with an empty set I of facts and repeatedly
uses rules pr# and np# to add new facts to it until I coincides with the least
Herbrand model I… of a given definite theory … D .…; /:
1. Because of the form of rule pr#, … can be loaded into I right away.
2. Rule np# is then repeatedly used as follows:
(a) Pick a clause P B in ;
(b) Select facts q1 .Ev1 /; : : : qm .Evm / in I that match its body predicates
Q1 ; : : : ; Qm ;
(c) Apply the resulting substitution ˛ to its generic constraints and verify their
validity;
(d) Extend ˛ to all head variables by means of the available head constraints;
(e) Add ˛.P / to I unless it was already there.
This procedure stops when no choice of P B or q1 .Ev1 /; : : : qm .Evm / adds any
new fact into I . It is clear that I is then equal to I… : indeed rules pr# and
np# are nothing but a proof-theoretic presentation of the last T…; operator of
Sect. 5.3.4. The main difference is that, while that operator worked in a set-at-a-
time fashion, the procedure we just outlined operates in a fact-at-a-time manner. A
number of (deductive) database query optimizations are based on variants of this
method [CGT90]. In the context of the relational and soon deductive spreadsheet, it
is expected to efficiently handle updates (see Sect. 5.6 for details).
Top-Down Construction
interpret the substitution as the output of the construction while … and B will be
its inputs. Indeed, properly managing substitutions is a critical aspect of the tree
construction. The rules defining this judgment are given next:
… ` B 7! ˛; ˛XE
æ O æO 0 is true
O gl"
gc" hc"
… ` æ æ0 7! ¿ … ` X D æ 7! fX 7! æg
O E : B 7! ˛
… ` 9X
Rule pr" is obtained from pr: a (primitive) predicate P that has an instance ˛.P /
in the factual theory … is derivable, and ˛ is returned to indicate which instance of
P this tree is a derivation of. Note that P may be partially instantiated. Rule np",
a clear offspring of np, handles non-primitive predicates: in order to verify whether
(some instance of) P is derivable from … , this rule looks for a clause P 0 B
in whose head P 0 is unifiable with P , i.e., such that there is a substitution ˛
with ˛.P / D ˛.P 0 /. If so, we attempt to construct a derivation for ˛.B/. Note
indeed that B may contain variables that do not occur in P 0 , and that ˛ may not
resolve all head variables if P itself mentions variables. Then, ˛ is extended with
the substitution ˛B returned by this subgoal, and reported on the right-hand side
of 7!. Rule bd" reduces the derivability of a body to the derivability of each
conjunct B1 ; : : : ; Bn appearing in it. Notice again that B2 may contain variables
that do not occur in B1 . Therefore, we shall apply the substitution ˛1 reported by
B1 to B2 before attempting this goal. Solving ˛1 .B2 / will produce a substitution ˛2
that will be applied to B3 , and so on. All these partial substitutions contribute to the
substitution returned by the rule. Rule gc" resolves generic constraints similarly
to rule gc above: it is applicable only if its arguments are ground (by the
safety requirements, all variables occurring in a generic constraint also appear in
a body predicate—it can therefore be delayed); therefore it always produces the
empty substitution. A head constraint X D æ may be handled differently: if the
variable X has been instantiated, then rule gc" applies. Otherwise, X is still a
variable and the returned substitution is fX 7! æg. O Note that, again by safety, æ
shall be ground. Rule hc" takes care of this second possibility; it is a special case of
our earlier rule gc. Finally, rule gl" extends the range of possibilities envisioned so
far by describing how to prove a goal 9X E : B. It simply tries to prove B but throws
away the part ˛XE of the returned substitution concerned with any variables among
XE . In practice, ˛ E is often a value of interest. Indeed, the main reason for asking
X
whether … ` 9X E : B has a derivation is often just to obtain ˛ E . This is achieved by
X
simply asking for a derivation of … ` B 7! ˛. Therefore, rule gl" can be ignored
for all practical purposes.
152 5 The Logical Spreadsheet
While the above rules describe very precisely how to manage substitutions, a
number of questions must be resolved before obtaining an effective procedure.
Note that the field of logic programming has been grappling with these issues for
years [Llo87, CGT90, MNPS91, Pfe]. We will now discuss the best practices in the
context of the deductive spreadsheet:
• How to manage choice points? With the exception of hc", all rules above can
fail to be applicable, hence halting the construction of the proof tree. In general,
this does not mean that the goal at hand is not provable, but simply that we tried
a possibility that did not live up to its expectations, and we shall try another
one. Indeed, rules pr" and np" are often choice points: multiple facts or clauses
may be applicable, each with a different substitution ˛. This issue is traditionally
approached by choosing one of the alternatives, according to some strategy, but
maintaining sufficient state to remember which other possibilities remain to be
considered. The order in which to consider alternatives has a non-insignificant
impact on performance.7
• How to solve subgoals? Traditional logic programming [Llo87] solves subgoals
in a depth-first manner. Rule bd" supports this strategy: B1 is completely solved,
hence reporting the substitution ˛1 ; only then is ˛1 .B2 / attempted, and so on—we
will see shortly that the order in which body conjuncts are attempted is a factor
as well (in particular rule gc" requires constraints to be ground). Depth-first
resolution is extremely efficient in most cases and does not have any drawbacks
for non-recursive theories. When recursion is thrown into the mix, as it will be in
Chap. 6, then a simple-minded application of this technique can needlessly cause
infinite loops.
The alternative breadth-first strategy pursues the solution of all subgoals at
the same time: once one step has been made toward solving subgoal Bi , it will
not be reconsidered before all other subgoals have had a chance to make a step
forward. This strategy always terminates for the type of definite programs we are
considering in this book. However, it can require maintaining exponentially more
state than depth-first resolution. This can have a negative impact on perceived
performance.
Breadth-first resolution is supported by the following variant of rule bd":
… ` P1 7! ˛1 1
˛ .æ0 /1 1
O 1 ˛.æ00 /1
:: Lm ::
˛D
1 1
: i D1 ˛i :
… ` Pm 7! ˛m ˛ .æ0 /o0
O o0 ˛.æ00 /o0
… ` B 7! ˛; fY1 b ;:::;Y
7! ˛.æ/ 1 o
bg
7! ˛.æ/ o
bd0 "
7
Another approach, embraced by a certain flavor of parallel logic programming, considers all the
choices at once. We will not investigate it further because commercial implementations still use
the more traditional sequential model and there is a substantial overhead in managing parallelism.
5.3 Inference in a Definite Spreadsheet Theory 153
V Vo Vo0
where B D m i D1 Pi ^ i D1 .Yi D æi / ^ i D1 .æi i æi / and ˛ ˚ ˛ fuses
0 00 0
In this section, we examine the full fragment of first-order logic that emerges
from simplifying the logical interpretation of a relational expression as described
in Sect. 5.2.2. The resulting theories, which are called normal, differ from definite
programs by the presence of negated predicates in the body of clauses. This
alters significantly the model and proof theory developed in Sect. 5.3. However,
stratification and the restriction to a natural interpretation of negation allows
building on most of that work.
This closely tracks major developments in logic programming, where substantial
amounts of research have been invested toward the goal of extending the elegant
solutions devised for definite theories to tame negation and the substantial increase
in expressive power that comes with it. This long-standing challenge is still open in
some respects. In this section, we specialize to the spreadsheet context some of the
solutions that proved most successful for deductive databases. The reader is invited
to consult [CGT90] for an overview of alternative approaches to importing negation
into logic programming.
We formalize (non-recursive) normal theories and related concepts in Sect. 5.4.1.
We examine their model theory in Sect. 5.4.2 and their proof theory in Sect. 5.4.3.
We now define the syntax of normal theories, extend the definitions of call and
dataflow graphs to this richer language, and adapt the notion of stratification within
a normal theory.
Syntax
In Sect. 5.2.2, set difference in the relational spreadsheet was interpreted into a for-
mula containing negation. We also showed that the product of this translation could
be simplified so that this operator would prefix at most predicates. The resulting
language defines formulas that differ from definite clauses by the possibility of
negated predicates appearing in their body. They are called normal clauses. Theories
consisting of just normal clauses are consequently normal theories. These notions
are formalized as follows:
Expanding from this grammar, normal clauses have the following form:
^ ^ ^
P Pi ^ :Qi ^ æi i æ0i
i D1::m i D1::n i D1::o
where some of the constraints on the right could be head constraints Xi D æ0i . A
body component p.X E / or :p.X
E / is called a literal: the first form is a positive literal,
the second a negative literal. For the time being, we will continue to require that a
theory be non-recursive.
Negative literals are similar to generic constraints in that they limit the values
that can be propagated to the head of a clause. Therefore, we shall extend the safety
restrictions on definite programs with the stipulation that variables in a negative
literal appear in some positive body predicate. The safety requirement for normal
clauses is therefore defined as follows:
1. A variable X occurring in the head of a clause also must occur:
E / in the body of the clause,
(a) Either in a positive literal p.X
(b) Or as the left-hand side of a head constraint X D æ.
2. Any variable X occurring within a generic constraint æ1 æ2 , or on the right-
E/
hand side of a head constraint Y D æ, must also occur in a positive literal p.X
in the body of the clause.
3. Any variable X occurring in a negative literal :Q must also occur in a positive
E / in the body of the clause.
literal p.X
The last entry is new. We will restrict our investigation to safe clauses and
theories satisfying these restrictions: as in the definite case, the methods we will
be discussing do not work for unsafe theories. Moreover, unsafe theories do not
correspond to any relational expression. As with definite clauses, condition (2) can
be relaxed transitively.
A normal theory … is a pair .…; / consisting of a factual theory … and a normal
clausal theory . We will omit the qualifiers “normal” and “definite” when the type
of theory under discussion is clear from the context.
Call Graph
The call graph, CG… , of a normal theory … D .…; / is again intended to describe
how predicates participate in each other’s definitions. Because negation will require
a special treatment, it is convenient to define its nodes not just as the predicates
occurring in … , but also to include the negated predicates found in its clauses. As
already with the relational substrate graph of Sect. 5.2.1, we relate predicate symbols
and their negations by a special type of edge. CG… is then formalized as follows:
• Nodes.CG… / is the set of all predicate symbols and negated predicate symbols
appearing in … .
156 5 The Logical Spreadsheet
• Edges.CG… / is the set of all edges .:/q ! p such that .:/q appears in a clause
defining p, and all edges p Ü :p for p; :p in Nodes.CG… /:
Edges.CG… / D E / q.YE / ^ B 2 g
fq ! p W p.X
[ f:q ! p W p.XE / :q.YE / ^ B 2 g
[ fp Ü :p W p; :p 2 Nodes.CG… /g
As for definite theories, this definition parallels the notion of relational substrate
graph RSs of the spreadsheet s. The call graph CG… s of the theory … s obtained
from s differs from RSs at most by the absence of functional dependencies.
As in Sect. 5.2.1, the Ü edges provide a mechanism to incorporate extra-logical
dependencies in a normal theory. The functional dependencies of a spreadsheet are
a prime example. Therefore, we will silently allow call graphs to contain extra Ü
edges, except where explicitly noted. The graph CG… in the above definition will
then be called the strict call graph of … . We will occasionally use the phrase
enriched call graph for its extended form.
Stratification
The notions of stratification and related concepts are readily adapted to generic
normal theories from the definitions in Sect. 5.2.3. A stratum is a set & of predicates
in … such that no path in CG… between two member predicates p and q contains
a Ü edge. This defines the following subtheory … & D .…& ; & / of … :
[
& D p
p2&
[ [ [
…& D …p [ …q [ …q
p2& q 62 & q 62 &
P B^q.XE / 2 & P B^:q.X E / 2 &
Its clausal part collects the definition of each non-primitive predicate in &. Its factual
part includes the factual theory of every primitive predicate in &, but also the factual
theories of every predicate q occurring in the body of a clause in & . Note that …q
is empty for any q that is not primitive in … . We call & a definite stratum if … & is
a definite theory, and a normal stratum if it is a normal theory.
A stratification is a partition &E D &0 ; : : : ; &n of the set of all predicates occurring
in … such that &i is a stratum for i D 0::n and if pi Ü pj in CG… for pi 2 &i and
pj 2 &j , then i < j . The Ü edges of the call graph CG… induce what we called
the functional dependency graph FD… .E& / among strata: its nodes are the strata of
the stratification, and it contains an edge & Ü & 0 if there are p 2 & and p 0 2 & 0
such that p Ü p 0 in CG… . Because we have disallowed recursive clauses, this
graph is necessarily acyclic and therefore every (non-recursive) normal theory is
5.4 Inference in a Normal Spreadsheet Theory 157
Dataflow Graph
The definition of the dataflow graph DF… of a normal theory … does not change
from the definite case. As observed earlier, negative literals have a filtering effect on
the data in a clause, in the same way generic constraints impose limitations on the
values that are propagated. Generic constraints were not included in the definition
of dataflow graph in Sect. 5.3.1 precisely because they never inject values. For the
same reason, negative literals shall be excluded.
The model theory of normal clauses is not as clean as for definite clauses. Thanks
to our safety requirements, validity can still be established by solely considering
Herbrand interpretations. However, most of the other pleasant properties of definite
programs do not hold for normal theories. In particular, a normal theory may not
have a least Herbrand model, but could have several distinct Herbrand models
each of which is minimal. This dramatically complicates the practical determination
of atomic logical consequences. A particularly natural attitude toward negation in
stratified theories allows however electing one such model as the perfect model, and
use it exactly like the least Herbrand model in Sect. 5.3.
158 5 The Logical Spreadsheet
Perfect Model
The notion of least Herbrand model is ill defined in the case of normal theories.
Consider for example a theory consisting of the normal clause
and the single fact r.a/. Then, by unfolding the definition of validity, it can be
shown that this theory has two Herbrand models that are both minimal in the sense
that removing any object from either of them jeopardizes validity: fp.a/; r.a/g and
fq.a/; r.a/g.8 Since there is more than one such model, neither is the “least” one.
Note that the model intersection property does not hold for normal programs: fr.a/g
is not a model in this example.
Of these two models, fp.a/; r.a/g is particularly natural under the interpretation
of the above clause as defining the predicate p on the basis of q and r: because
r.a/ is a true fact and there is no fact q.a/ to veto the propagation of a to the head
variable X , the fact p.a/ ought to be true. The other model, fq.a/; r.a/g, although
logically correct, is at odds with intuition: r.a/ is clearly there but there is no trace
of any q.a/. We call fp.a/; r.a/g the perfect model of the above theory, and treat
it as if it were its single least model, therefore ignoring fq.a/; r.a/g. This practice
is logically unsound, but it is effective, predictable, and corresponds to an intuitive
understanding of negation. However, it works only for stratified theories [CGT90,
Llo87].9
The general principle supporting this interpretation is known as the Closed World
Assumption (CWA) [Rei78]. It infers :p.Ev/ whenever the ground predicate p.Ev/ is
not a logical consequence of a definite theory … . When applied to normal theories,
it immediately leads to inconsistency: in the above example, it would infer both
:q.a/ and :p.a/, which is clearly inconsistent with the above clause. Stratification
allows applying the CWA in stages: the bottom stratum &0 of this example, which
defines the predicates q and r, has fr.a/g as its least Herbrand model; when
evaluating the next stratum &1 , which defines p by means of the above clause, the
CWA is applied solely with respect to the predicates in &0 , hence producing p.a/.
Stratification circumvents inconsistency. In this context, the model it produces is the
perfect model.
This immediately suggests an adaptation of the fixpoint computation of the least
Herbrand model of a definite theory to calculate the perfect model of a stratifiable
normal theory: extend the T…; operator to an individual stratum using the CWA,
8
In classical logic, this clause is logically equivalent to q.X/ :p.X/ ^ r.X/, which underlies
a further justification for the second model, and explains the symmetry between them.
9
A more general notion, local stratification [Prz87, CGT90], admits a larger class of theories by
taking into consideration the ground predicates of a theory rather than just the predicate symbols
that appear in a clause. The added class of theories is however likely to be inconsequential in the
spreadsheet context. Moreover, local stratifiability is undecidable.
5.4 Inference in a Normal Spreadsheet Theory 159
and then apply this operator one stratum at a time, using the models obtained for
lower strata as if they were factual theories of the current one.
Let & be a stratum in a (linear) stratification of a normal theory … and let … & D
.…& ; & / be the corresponding subtheory. Recall that & may mention negative
literals, but only if the corresponding predicates are primitive in …& . Then, our
last expression for the T…; operator can naturally be adapted to handle this new
situation:
V V
T…& ; & .I / D I [ …& [ f˛.P / W P i D1::m Pi ^ i D1::n :Qi
V
^ i D1::o æi i æ0i 2 &
and ˛.Pi / 2 I [ …& for all i D 1::m
and ˛.Qi / 62 …& for all i D 1::n
and ˛.æi / O i ˛.æi / is true for all i D 1::o g
By the safety constraints on variable occurrences, the negative literals :Qi do not
contribute to the calculation of potential substitutions ˛, but, similarly to generic
constraints æi i æ0i , they are used to eliminate candidates. Note that this expression
is equivalent to our last version in the case of definite theories.
Since all predicate symbols used negatively are primitive by assumption, T…& ; &
is monotonic and continuous relative to the usual lattice of Herbrand interpreta-
tions [Llo87]. Therefore, it has a least fixpoint that is computed via successive
iterations from the empty set: lfp.T…& ; & / D T…!& ; & .;/. By the same argument as
for definite theories, an interpretation I is a Herbrand model of … & D .…& ; & / if
and only if T…& ; & .I / I . Therefore, this fixpoint is a minimal model. We call it
the perfect model of … & and denote it by I… & .
Observe that these conclusions would be incorrect in general if any predicate
q occurring negatively in & were defined clausally, i.e., if q were not primitive.
Indeed, the condition ˛.Qi / 62 … would have the effect of ignoring any calculated
instance of q, which would prevent the negative literal from acting as a filter. If we
were to relax this condition so that it takes the input interpretation into account,
hence writing it ˛.Qi / 62 I [ …, monotonicity would clearly be lost.
The effectiveness of the fixpoint characterization of the perfect model I… & as
!
T…& ; & .;/ is proved exactly in the same way as in Sect. 5.3.4. In particular, the
number of needed iterations is equal to jCG… & j C 1, where jCG… & j is the length of
the longest ! path in the call graph CG… & of … & . Moreover, since we are relying
on substitutions, we do not need to worry about issues such as the finiteness of
the Herbrand universe. However, that argument can be used to prove that I… & is
finite.
160 5 The Logical Spreadsheet
We can use this extended fixpoint characterization to obtain the perfect model of a
stratifiable normal theory … as a whole. Given a linear stratification &E D &0 ; : : : ; &n
of its predicates, we use the above operator to calculate the perfect model of each
successive subtheory … &i , for i D 1::n. The set of clauses & fed to the T…& ; &
operator is simply the clausal part &i of … &i . The set of facts will be …&i extended
with the perfect model obtained for stratum i 1. This is formalized as follows:
8
< I… &0 D lfp.T…&0 ; &0 /
:I D lfp.T.…&i C1 [ I… &i /; &i C1 /
… &i C1
The basic notion of derivability in a normal theory can be defined by adding a single
rule to the corresponding system for definite programs:
Vn
.P i D1 Bi / 2 p.Ev/ D ˛.P / …; ` ˛.B1 / …; ` ˛.Bn /
np
…; ` p.Ev/
p.Ev/ 2 … æO O 0 is true
O æ … 6` q.Ev/
pr gc nl
…; ` p.Ev/ … ` æ æ 0
… ` :q.Ev/
Rules np, pr and gc do not change from the definite case. Instead, the highlighted
rule nl defines the provability of a negative literal by reducing the derivability of
… ` :q.Ev/ to the absence of a derivation for the judgment … ` q.Ev/, a state
of affairs which we indicate with … 6` q.Ev/. Operationally, this means that every
attempt at constructing a derivation for … ` q.Ev/ is unsuccessful. This approach,
known as negation-as-failure [Cla78,Llo87], is clearly based on the CWA and is the
standard treatment of negation in logic programming languages, especially Prolog.
5.4 Inference in a Normal Spreadsheet Theory 161
It does not soundly capture the logical semantics of negation, but is a sufficient
approximation for most applications.
As in the definite case, we will now specialize this system for the bottom-up
and the top-down construction of a derivation. The former can be used to logically
handle updates, the latter as an explanation facility. Note that … 6` q.Ev/ is not a
judgment in rule nl, but a meta-theoretic requirement. As we specialize the above
system, we will bring this notion to the front stage by describing effective means to
verify it.
Bottom-Up Construction
p.Ev/ 2 …&
pr#
…& ; & ` p.Ev/
b b 1
: : : :
… & ` ˛.Pm / ˛.Qn / 62 …& ˛.Yo / D ˛ .æ/o ˛.æ0 /o0
O o0 ˛ .æ00 /o0
np#
…& ; & ` ˛.P /
V Vn Vo Vo0
where B D m i D1 Pi ^ i D1 :Qi ^ i D1 .Yi D æi / ^ i D1 .æi i æi / in the
0 00
second rule.
Given a normal theory … D .…; / and a linear stratification &E D &0 ; : : : ; &n
for it, facts p.Ev/ derivable from … are computed one stratum at a time starting at
0
&0 . Let, …&i the set of facts derivable from … &0 ; : : : ; … &i . Formally,
0
…&0 D fp.Ev/ W …&0 ; &0 ` p.Ev/g
0 0
…&i C1 D fp.Ev/ W .…&i [ …&i C1 /; &i C1 ` p.Ev/g
0
It is then clear that each set …&i is the perfect model I… &i of … &i which we obtained
0
earlier. Consequently, I… D …&n . The derivability … ` p.Ev/ of a fact p.Ev/ from a
normal theory … with respect to a stratification &1 ; : : : ; &n then simply reduces to
0
p.Ev/ 2 …&n . Note that there is always a smallest index i such that:
0
… ` p.Ev/ iff p.Ev/ 2 …&j for all i j n
162 5 The Logical Spreadsheet
Top-Down Construction
0
O
æ O æ
O is true
gc" hc"
… ` æ æ0 7! ¿ … ` X D æ 7! fX 7! æg
O
… ` B 7! ˛; ˛XE … 6` Q
gl" nl"
E B!
… ` 9X: 7 ˛ … ` :Q 7! ¿
O æO 0 is false
æO … ` q.Ev/ 7! ¿
gc" ng"
… 6` æ æ0 … 6` :q.Ev/
Rule np" defines the non-provability of a ground positive literal P . First of all, P
shall not be a fact in … (otherwise, P would be immediately provable). Second, if
the head P 0 of any clause P 0 B in is unifiable with P , then the corresponding
instance of its body shall not be provable. Rule bd" defines what it means for a body
5.5 Spreadsheet Evaluation Revisited 163
We will now start applying the techniques devised in the last two sections as logical
alternatives to implementing the various functionalities of a relational spreadsheet.
We begin with evaluation, which was analyzed at length in Sect. 4.4 of the previous
chapter.
Whenever a relational expression eN appeared in a spreadsheet s, we simply relied
on the semantics of relational algebra to evaluate it, as long as it did not refer to
any still uncalculated location. We will now parallel that development, but rely
exclusively on the fixpoint semantics of the normal theory associated with s. We will
initially do so in a very coarse way, but later refine this approach so that it better suits
semi-naı̈ve evaluation. Logic-based calculation will reveal its advantages in Chap. 6
where we will allow recursive predicates, hence making our spreadsheet model truly
deductive.
[ [
.…s ; s / @ D .…p @ / [ . p @ /
…p 2 …s p 2 s
(
E
fp.?/g if p D phEei and ? 2 Ee @
…p @ D
hEe @ i otherwise
(
E
fp.?/g if Cl @ D ? for any Cl 2 p
p @ D
fCl @ W Cl 2 p g otherwise
(
Vn ? if Bi @ D ? for some i D 1::n
.P i D1 Bi / @ D Vn
P i D1 .Bi @ / otherwise
P @ D P
.:Q/ @ D :Q
(
? if æ @ D ? or æ0 @ D ?
.æ æ0 / @ D
.æ @ / .æ0 @ / otherwise
Note that the literals in a clause body are never replaced with ? since they do not
embed cell references. With these definitions in place, we need to alter the form
of our fixpoint operator so that ? does not accidentally participate in a logical
E may lead to the partial instantiation of a
inference. Otherwise, a positive literal p.?/
head predicate with ?, and a negative literal :q.?/E may fail to veto the propagation
of some values. Therefore, we define the following ?-conscious variant T…?& ; & of
the stratum-level operator T…& ; & introduced in Sect. 5.4.3:
It behaves exactly like T…& ; & for those predicates that do not depend on a pseudo-
E Indeed, it directly calls this operator in that case. It only
fact of the form p.?/.
5.5 Spreadsheet Evaluation Revisited 165
propagates predicates in uncalculated form otherwise. The operator T…?& ; & shares
the properties of T…& ; & . In particular, it has a least fixpoint lfp.T…?& ; & / obtained
by finite iteration from the empty Herbrand interpretation. It is a partial version
of the perfect model and therefore we denote it by I…? & . We can then iterate this
construction over a stratified normal theory … , obtaining an overall partial perfect
model that we denote by I…? .
If … above is the situated theory … s @ for a relational spreadsheet s and
environment , this last expression is the perfect model of … s with respect to the
environment . If peN is the predicate corresponding to relational expression eN in
s, the value appearing in I…? s @ for peN is the same as the value eN @ obtained
relationally in Chap. 4. Therefore, we can make use of it in every circumstance
where eN @ appeared.
We begin with updating the definition of evaluation of an array formula Ee with
respect to an environment (see Sect. 4.4):
Ee @ Ee @ D f 7! Ee Œ @ W 2 IEe g
N @ D ŒfEv W pŒNe .Ev/ 2 I.…
Œe ?
s @ / g
The first line remains unchanged since it does not refer to relational expressions.
Instead, we replace the second (originally Œe N @ D ŒeN @ ) with the set of tuples
reported by I…? s @ for peN .
We can then apply the same technique to update the definition of the naı̈ve
evaluation operator ER s of a relational spreadsheet s:
[
ER s ./ D fElŒ 7! .s.El/ @ /Œ W 2 IEl g
El 2 dom s
s.El/ 2 E I
[
[ fEl 7! fEv W phEli .Ev/ 2 I.…
?
s @ / gg
El 2 dom s
s.El/ 2 EN
The first part of this expression, which deals with array formulas, is defined exactly
as in Chap. 4. The second portion relies instead on the perfect model of s at to
populate the domain of a relational expression. It is easy to show that it computes
the same environment as our original definition for ER s . Therefore, we can use it for
the fixpoint evaluation of a relational spreadsheet s.
This approach to evaluating a relational spreadsheet is as inefficient as the
original naı̈ve procedure described in Chap. 4. Indeed, each iteration of ER s embeds
?
the fixpoint computation I.… s @ / which has the same cost as the relational
evaluation of all the relational expressions in s. A simple-minded adaptation of the
techniques in Chap. 4 to distilling a semi-naı̈ve refinement of ER s does not yield the
?
expected efficiency boost because it would still imply the computation of I.… s @ / at
166 5 The Logical Spreadsheet
each iteration, each time with a slightly more instantiate environment and therefore
theory … s @ .
?
Clearly, once a predicate p has been calculated in I.… s @ / , it will remain
? 0
calculated in I.… s @ 0 / for every refinement of , and hold the same value.
The above procedure does not take this property into consideration, and therefore
recalculates p at each iteration of ER s or of the corresponding semi-naı̈ve refinement.
In order to address this issue, we will now partition … s into a number of func-
tionally dependent theories … si so that at any iteration of the outer operator, which
we will call ER s0 , either all or none of its clausally defined predicates will be fully
si @ / will either contain only ? as a value, or it will not
?
calculated. Therefore, I.…
mention ? at all. Partitioning … s according to a functional dependency conscious
stratification of its predicates, for example its least stratification &E obtained from
the stratified call graph R fSs , is a step in the right direction, but it does not take into
account the fact that some functional dependencies have been artificially inserted to
handle negation. We will then construct … si by collecting the definition of all the
original predicates present in the i -th stratum of &E and all the auxiliary predicates
they have engendered. We now formalize this intuition.
Let s be a relational spreadsheet and R fSs its stratified call graph, defined in
Sect. 5.2.3. Let &E D &1 ; : : : ; &n be the least stratification of R fSs . For i D 1::n,
s
let &i be the subset of &i containing solely predicates corresponding to relational
expressions hosted in cell ranges in s:
This excludes predicates obtained from embedded relational formulas Œe N and
from base relations hEe i such that Ee is not a cell range. It also excludes all
the auxiliary predicates introduced to massage the raw logical interpretation of
relational expressions into a normal theory. Indeed, if s.El / D e, N recall that we
initially interpreted eN as the formula phEli .XE / peq.
N X;E YE /. Recall also that the
factorization of complex negative formulas out of peq. N X; E YE / may have produced
nhEli
1
a number of auxiliary predicates p E ; : : : ; p E . The same may happen because of
hli hli
functional dependency inside e. N
We will ignore the first two classes of excluded predicates for the moment, but
s
we shall account for the latter. Therefore, let the stratification &E i be the restriction
of &E to the set of predicates
j
&is [ fp E W phEli 2 &is g
hli
5.5 Spreadsheet Evaluation Revisited 167
s
The first stratum of &E i is &is and every successive stratum contains auxiliary
predicates as they appear in &E .
s
Finally, let … si be the stratified normal theory corresponding to &E i . Notice that
this theory may now mention some predicates of the form phEei where hEe i is not a
cell range. We can subject … si to the same manipulations already applied to … s .
In particular, we can situate it at any given environment as … si @ , and we can
?
compute its partial perfect model I.… si @ / .
The construction just described can be repeated (generally on a smaller scale)
for every predicate of the form pŒNe in … s , hence obtaining a theory … sŒNe that will
be used to redefine the evaluation of the array formula Œe N @ as ŒfEv W pŒNe .Ev/ 2
?
I.… s
@ / g.
ŒNe
The operators ER s0 and ER s are equivalent. In particular, they have the same least
fixpoint: the evaluation of s. They also have the exact same computational cost:
indeed, the various … si ’s are just a partition of … s , and therefore the cost of
computing the collection of the perfect models of the former and the one perfect
model of the latter is the same.
The difference emerges when refining ER s and ER s0 into semi-naı̈ve procedures, EP s
and EP s0 respectively, following our steps from Chap. 4. Indeed, the perfect model
of each … si can be computed independently of the others. Moreover, an attempt
at producing it before all the objects it functionally depends on (either embedded
cells or functionally dependent predicates) have a non-? value will result in each
of predicate p in it being evaluated to p.?/. E Therefore, the semi-naı̈ve version EP s0
R
of Es can be defined so that it calculates a perfect model for … si only once: the
0
?
first time it is applied to an environment such that the perfect model I.… si @ /
E
contains non-? predicates. The usual analysis of dependencies in Chap. 4 will point
out when this is the case. Note again that this fine-grained approach is not an option
when starting from ER s because the whole … s must be processed at each iteration.
The semi-naı̈ve operator EP s0 is as efficient as the relational semi-naı̈ve procedure
outlined in Chap. 4. It has the added advantage that it can natively handle recursive
predicates, as we will see in Chap. 6.
168 5 The Logical Spreadsheet
At the cost of repeating ourselves, we shall stress again that updates are much more
frequent than full evaluation in a spreadsheet. Therefore, although it is useful that
the initial calculation be fast, it is much more important that the myriad of small
updates resulting from normal use be propagated quickly. In Chap. 4, we have laid
out a general update infrastructure for the relational spreadsheet and observed that
most relational operations supported incremental updates. However, we remained
vague on how operation-level updates propagated to entire expressions: relational
algebra operators could be nested arbitrarily, which made it difficult to describe
a fully general approach. The logical interpretation of relational expressions have
instead a very predictable form: they are clauses whose body consists of literals,
possibly with constraints intermixed. This regularity allows us to discuss updates
and their propagation at a much finer granularity and in greater detail in this section.
It will be useful to present our approach in small incremental steps. We will
initially limit our investigation to the effect that updating a primitive predicate
q has on any clause mentioning q in its body. We start in Sect. 5.6.1 with the
simplest case, in which q has been extended with new facts, and in which it is
used only as a positive literal. In Sect. 5.6.2, we see what are the consequences of
the removal of facts from q. We consider negative and mixed occurrences of q in
a clause in Sect. 5.6.3. Finally, Sect. 5.6.4 brings these various techniques together
and addresses the general problem of propagating updates within a normal theory.
q ` q.E
… C v/ iff q.Ev/ 2 …q
q ` q .E
… C v/ iff q.Ev/ 2 …q [ …q
0
The first line is achieved by defining the set …q D fq.Ev/ W q.Ev/ 2 …q g. The
second line is then clausally defined by the theory qC given by the following two
clauses:
5.6 Updates Revisited 169
E / q.X/
q 0 .X E
0 E E
q .X / q.X/
these two clauses in the formula q 0 .XE / q.X E / _ q.X E /, which is not a clause,
but is logically equivalent to them. Note that since no other clause defines q 0 ,
we can understand this formula as a bi-implication: it then assumes the form
E / $ q.X/
q 0 .X E _ q.X/. E While not logically sound, this transformation, known
as Clark completion [Cla78, Llo87], enforces the interpretation of the set of clauses
with head p as the definition of predicate p, in the sense that these clauses should
be the only possibilities for deriving p. It is the logical justification of the notion of
negation-as-failure, which we relied upon when defining the proof theory of normal
theories in Sect. 5.4.3.
Let now p be a clausally defined predicate that depends positively on q. Then,
p contains a clause Cl of the form p.X E / q.XE ; YE / ^ B. We will initially assume
that q does not occur in B. Any addition to …q will lead to an extension of the
logical consequences of p. Following the above model, if we can express the change
to the set of logical consequence of p as a predicate p, then the clause p 0 .X E/
p.X E / _ p.XE / describes the logical consequences of p after the update. We can
also define p 0 directly by replacing q with q 0 in Cl. By expanding q 0 as q _ q, we
obtain:
E / q.X
p 0 .X E ; YE / _ q.X;E YE / ^ B
E / q.X
p 0 .X E ; YE / ^ B
0 E E YE / ^ B
p .X / q.X;
Since the body of the first is precisely the original body of Cl, we can take the
second to be the definition of p. It will be convenient to relativize this predicate to
the specific clause Cl, hence writing it as pCl . Therefore,
E / q.X;
pCl .X E YE / ^ B
This rationale is schematically captured in the following diagram, where the thick-
lined box represents the result of the update to p, the thin line delimits its original
values, and the dotted/dashed lines enclose portions of q and q that are not
validated by B.
170 5 The Logical Spreadsheet
B
⎧ ⎫ ⎫
⎪
⎪ ⎪
⎪ ⎪
⎪
⎪
⎪ ⎬ ⎪
⎪
⎪
⎪ ⎪
⎪
⎪
⎪ p(X) q(X) ⎪
⎪
⎪
⎪ ⎪
⎪ ⎪
⎪
⎪
⎨ ⎭ ⎪
⎬
p (X) .⎫ q (X)
⎪ .⎪ ⎪
⎪
⎪ .. ⎪ ⎪
⎪
⎪
⎪
⎪ .⎬ ⎪
⎪
⎪
⎪
⎪ Δp(X) .. Δq(X) ⎪
⎪
⎪
⎪ .⎪⎪ ⎪
⎪
⎪
⎩ .⎭ ⎪
⎭
.
...........
Before extending this technique any further, two observations are in order:
• First, the set of logical consequences of pCl may not be disjoint from that of
p. Consider for example the clause p.X / q.Y / ^ r.X /. Note that p does
not depend on q since there is no flow of information from the variable Y to the
variable X . The clause for pCl would have the form pCl .X / q.Y /^r.X /
in which X and Y are still unrelated so that the set of logical consequences of
pCl is identical to that of p. While updates to q cannot have any effect on p
(as long as q.Ev/ 2 …q for some Ev), the above technique recomputes p in full
with every change to q. Here, q.Y / could easily be optimized away. This is not
always possible, however, as in the following variant of this clause: p.X /
q.Y / ^ r.X / ^ X > Y . Here, updates to q with small values for Y may still lead
to a full recalculation of p.X / as pCl .X /.
The possibly large overlap between p and pCl is certainly unwelcome news
since it implies that the calculation of pCl may perform more work than strictly
necessary for the purpose of upgrading p to p 0 . While redundant, this work is not
useless: if p.Ev/ was derivable and pCl .Ev/ is produced, this means that updating
q yielded a new way to prove p.Ev/. This enables a very precise accounting of the
derivations of each fact p.Ev/, which turns out to be very useful when considering
negative updates. Indeed, we can associate each fact with a counter that tracks
its number of derivations. A logical way to achieve the same effect would be
to switch to a multiplicity-conscious refinement of the formalism we have used
so far, as done in [LC12]. Linear logic [Gir87], which is amenable to a logic
programming interpretation [HM94, LPPW05] compatible with Datalog, is the
most promising candidate. We will not explore this possibility in the present
book.
• Second, the fact that B appears in the definition of pCl may cause a significant
overhead even for small changes to q. In extreme cases, it may be as efficient to
recompute p from the updated q as to determine pCl . However, it is expected
to be advantageous in the common situation where q and B share a majority of
variables and the size of B is relatively small. Adaptive approaches that decide
5.6 Updates Revisited 171
E / q.X
pCl0 .X E 1 / ^ q.XE 2/ ^ B
E / q.X
pCl0 .X E 1 / ^ q.X
E 2/ ^ B
E / q.X
pCl0 .X E 1 / ^ q.X
E 2/ ^ B
where the last clause accounts for interactions between the two occurrences of q in
Cl0 over the update. The same idea can be iterated if q has more than two occurrences
in a clause. It also applies to situations where different positive literals have been
updated. This is schematically rendered in the following diagram, where we have
refrained from representing B for convenience:
q (X 2 )
q(X 2 ) Δq(X 2 )
⎧ ⎫ ⎫
⎪
⎪ ⎪ ⎪
⎪
⎪
⎪ ⎪
⎬ ⎪
⎪
⎪
⎪ ⎪
⎪
⎪
⎪ p(X) q(X 1 )⎪
⎪
⎪
⎪ ⎪ ⎪
⎪
⎪
⎨ ⎪
⎭ ⎪
⎬
p (X) . . . . . . . . . . .⎫ q (X 1 )
⎪ .. ⎪ ⎪
⎪
⎪ .. ⎪
⎬ ⎪
⎪
⎪
⎪ ⎪
⎪
⎪
⎪ .. Δp(X) Δq(X 1 ) ⎪
⎪
⎪
⎪ ⎪ ⎪
⎪
⎪
⎪ .. ⎪
⎭ ⎪
⎪
⎩ .. ⎭
Generalizing further, assume that p contains several clauses Cl1 ; : : : ; Cln con-
taining an updated predicate q. Then, it is clear that the overall update p to p is
given by the collection of the updates produced for each individual clause Cli for
i D 1::n:
E / pCl1 .X/
p.X E
E E/
p.X / pCln .X
172 5 The Logical Spreadsheet
We will now reiterate the above scenarios, this time assuming that the update to …q
has had the effect of removing the set of facts ı…q . Let then ıq be the predicate
characterizing ı…q .
Consider a clausally-defined predicate p which depends upon q. We can then
abstractly describe the changes that a negative update to q induces onto p by means
of the clause p 0 .X E / p.X E / ^ :ıp.X E /, where p 0 collects the values of p after
the update and ıp describes the change. As we search for a clausal definition of ıp,
we must be particularly attentive to the fact that this formula does not allow any
slack: if a fact ıp.Ev/ is derivable and p.Ev/ also has a derivation that does not rely
on q, it will be wrongly excluded from p 0 . Giving a strict definition for ıp so that
this situation does not arise is extremely complex, possibly computationally more
demanding than just recomputing p on the basis of the updated q. We will therefore
take a different approach. We will assume, as discussed in Sect. 5.6.1, that every
derivable p.Ev/ is annotated with the number of derivations it has. We will define ıp
so that it also records the number of ways to prove ıp.Ev/ on the basis of ıq, and we
will tag p 0 .Ev/ with the difference of these two values: a result of zero means that
there is no derivation of p 0 .Ev/.
Let Cl be a clause p.X E / q.XE ; YE /^B depending on q, and initially assume that
q does not occur in B. The values of p contributed by ı…q within this clause can be
characterized very precisely by using ıq to filter the values of the variables XE and YE
that are processed by B and possibly propagated to the head. These tuples are indeed
characterized by the predicate ıpCl defined by the following clause:
E / q.X
ıpCl .X E ; YE / ^ B ^ ıq.X
E ; YE /
E / ıq.X
ıpCl .X E ; YE / ^ B
As observed in Sect. 5.6.1, the computation of B may limit the efficiency of this
incremental update. However, if Cl is the only clause for p, this drawback can
be completely eliminated by observing that the first expression for ıpCl can be
rewritten as:
E / p.X
ıpCl .X E / ^ ıq.X
E ; YE /
The computed values of p are directly filtered through ıq. Moreover, it is clear that
ıp is ıpCl . This simplification is not sound if there are other defining clauses for
p since it may incorrectly mark for deletion values not contributed by ıq. These
arguments are captured in the following sketch:
5.6 Updates Revisited 173
⎧ ⎫ ⎫
⎪
⎪ ⎪ ⎪
⎪
⎪
⎪ ⎪
⎬ ⎪
⎪
⎪
⎪ ⎪
⎪
⎪
⎪ p (X) q (X) ⎪
⎪
⎪
⎪ ⎪ ⎪
⎪
⎪
⎨ ⎪
⎭ ⎪
⎬
p(X) ⎫ q(X)
⎪
⎪ ⎪
⎪ ⎪
⎪
⎪
⎪ ⎬ ⎪
⎪
⎪
⎪ ⎪
⎪
⎪
⎪ ±p(X) ±q(X) ⎪
⎪
⎪
⎪ ⎪
⎪ ⎪
⎪
⎪
⎩ ⎭ ⎪
⎭
Following the tracks we laid for positive updates, consider next a clause Cl0 for
p containing two occurrences of q: p.XE / q.XE 1 / ^ q.X
E 2 / ^ B, where X,
E XE 1 and
E may overlap. By the same rationale, we can characterize ıpCl0 by inserting either
X 2
ıq.XE 1 / or ıq.X
E 2 / as a filter:
E / q.X
ıpCl0 .X E 1 / ^ q.X
E 2 / ^ B ^ .ıq.X
E 1 / _ ıq.X
E 2 //
As before, if Cl0 is the only clause for p, this can be further simplified, with
substantial efficiency gains, into:
E / p.X
ıp.X E / ^ ıq.X
E 1/
E / p.X
ıp.X E / ^ ıq.X
E 2/
These results extend to clauses containing more than two occurrences of q, and to
clauses where different predicates have been updated. This is summarized in the
following diagram:
q(X 2 )
q (X 2 ) ±q(X 2 )
⎧ ⎫ ⎫
⎪
⎪ ⎪ ⎪
⎪
⎪
⎪ ⎪
⎬ ⎪
⎪
⎪
⎪ ⎪
⎪
⎪
⎪ p (X) (X ) ⎪
q1 ⎪
⎪
⎪
⎪
⎪ ⎪
⎪ ⎪
⎪
⎨ ⎭ ⎬
p(X) .. . . . . . . . . . . ⎫ q(X 1 )
⎪
⎪ . ⎪
⎪ ⎪
⎪
⎪
⎪ .. ⎬ ⎪
⎪
⎪
⎪ ⎪
⎪
⎪
⎪ . ±p(X)
. ±q(X 1 ) ⎪
⎪
⎪
⎪ . ⎪
⎪ ⎪
⎪
⎪
⎩ . ⎭ ⎪
⎭
..
174 5 The Logical Spreadsheet
Finally, consider a situation where two clauses Cl1 and Cl2 for p mention q or
some other updated predicate. Then, the overall update to p is given by the updates
contributed by both:
E / ıpCl1 .X/
ıp.X E
E E
ıp.X / ıpCl2 .X/
and similarly if p has more than two clauses containing updated predicates.
At this point, if all clauses for p are subject to updates, then we can safely
E / as p.X
compute p 0 .X E / ^ :ıp.X E / in a purely logical fashion. If, however, p
has other clauses, they may independently calculate values p.Ev/ accounted for by
ıp. Then, we must use the counter approach to derive p 0 .X E /, or the result may be
incorrect.
We now examine the impact of an update of some predicate q to clauses that rely
negatively on q.
Consider first the situation where …q has been extended to …q [ …q , and let
q be the characteristic predicate of …q . Initially assume that there is a clause Cl
for some other predicate p that uses q negatively: p.X E / :q.X E ; YE / ^ B (recall
that every variable to :q must also occur in a positive literal in B). Observe that
enlarging …q means that more values are filtered out, which will in general lead to
fewer derivable facts of the form p.Ev/. Therefore, the effect of the update can be
described by a clause p 0 .XE / p.XE / ^ :ıp.X/,
E as in Sect. 5.6.2. Now, we can
E / directly as
define p 0 .X
E / :q.X
p 0 .X E ; YE / ^ B ^ :q.X;
E YE /
E / q.X;
ıpCl .X E YE / ^ B
which is in line with what we obtained in Sect. 5.6.2 for negative updates to positive
literals. This same model applies to rules containing two or more occurrences of
:q, as well as the other situations we examined.
Consider next the situation where …q was shrunk by ı…q , so that the clause Cl
above will not restrict as much the set of values it contributes to p. By an argument
pattern similar to what we used already, it is easy to see that the corresponding
extension pCl to p has the form
E / ıq.X;
pCl .X E YE / ^ B
5.6 Updates Revisited 175
The development then proceeds as in the case for positive updates to positive literals
in Sect. 5.6.1.
The final situation we need to examine involves mixed clauses Cl of the form
p.XE / q.X E 1 / ^ :q.X
E 2 / ^ B, where p depends on the updated predicate q both
positively and negatively. Consider the situation where …q has been extended by
…q , which we assume is characterized by a predicate q. The net effect on p will
E 1 / will open
be both positive and negative, in general. Indeed, the positive literal q.X
the gates to new consequences of the form p.Ev/, but the negative literal :q.X E 2 / may
bar some of them from materializing. It may also remove some previously derivable
facts of this form. Pictorially, the situation is rendered as follows:
q (X 2 )
The thin solid box represents the logical consequences of Cl before the update, while
the thick box describes the values of p it derives after the update. The intuition
behind the other areas is given by their labels. By using this picture as inspiration,
E .p.X
it is clear that p 0 can be expressed by the formula p 0 .X/ E / _ pCl .X//
E ^
:ıpCl .X E / for appropriate predicates pCl and ıpCl that we will now define. We can
expand this formula into the following two clauses:
E / p.X
p 0 .X E / ^ :ıpCl .X
E/
0 E E E/
p .X / pCl .X / ^ :ıpCl .X
E q 0 .X
If p 0 .X/ E 1 / ^ :q 0 .X
E 2 / ^ B is to describe clause Cl after the update, we
can expand the occurrences of q 0 in terms of q and q, hence obtaining
E / .q.X
p 0 .X E 1 / _ q.X
E 1 // ^ :q.X
E 2 / ^ :q.X
E 2/ ^ B
E / q.X
p 0 .X E 1 / ^ :q.X
E 2 / ^ :q.X
E 2/ ^ B
E / q.X
p 0 .X E 1 / ^ :q.X
E 2 / ^ :q.X
E 2/ ^ B
176 5 The Logical Spreadsheet
E / q.X
pCl .X E 1 / ^ :q.X
E 2 / ^ :q.X
E 2/ ^ B
E / q.X
ıpCl .X E 2 / ^ q.X
E 1/ ^ B
E / q.X
ıpCl .X E / ^ q.X
2 E 1/ ^ B
p(X) ±q(X 2 ) q (X 2 )
⎧ ⎫ ⎫
⎪ ⎪ ⎪
⎪
⎪
⎨ ⎪
⎬ ⎪
⎪
⎪
⎪
p (X) Δp(X) q (X 1 ) ⎪
⎪
⎪ ⎪ ⎪
⎪
⎪
⎩ ⎪
⎭ ⎪
⎬
.. .. ⎫ q(X 1 )
. .⎪ ⎪
⎪
.. .. ⎪ ⎬ ⎪
⎪
.. ±q(X 1 ) ⎪
⎪
±p(X) .. ⎪
⎪
.. .. ⎪
⎪ ⎪
⎪
⎭ ⎪
⎭
.
. . . . . . . . . . . . . . . . . . . . ..
Following the now familiar development, the result of the update to q given by the
E / q.X
clause q 0 .X E /^:ıq.X
E /. By expanding its body for q in Cl and distributivity,
we obtain the following two clauses for the representation p 0 of p after the
update:
E / q.X
p 0 .X E 1 / ^ :ıq.X
E 1 / ^ :q.XE 2/ ^ B
0 E E E E
p .X / q.X / ^ :ıq.X / ^ ıq.X 2 / ^ B
1 1
from which we can derive the following clauses for pCl and ıpCl :
E q.X
pCl .X/ E 1 / ^ :ıq.X
E 1 / ^ ıq.X
E 2/ ^ B
E / ıq.X
ıpCl .X E 1 / ^ :q.X
E 2/ ^ B
In Chap. 4, we observed that relational algebra and the various types of dependency
graphs we designed to support relational expressions in a spreadsheet come short of
providing a satisfactory explanation mechanism at the relational level. Indeed, these
graphs help visualize which relation depends on which—even how attributes truly
influence each other—but they are incapable of answering record-level questions,
such as “why is this record in the result?”. In particular, negative requests such as
“why is this expected record not present?” are totally out of reach.
178 5 The Logical Spreadsheet
0
(b) For a negative literal :q.Ev /, we switch to negative explanation mode (see
Sect. 5.7.2).
(c) For a constraint æ æ0 , we invoke the scalar explanation mechanism if æ or
æ0 originally contained cell references. Their validity should be self-evident
otherwise.
6. At any moment, the user shall be able to expand the explanation of any other
subgoal. She shall also be able to switch to an alternative derivation tree D0 ,
hence going back to step 2. If D0 has much in common with D, steps that the
user has already undertaken for D could be pre-expanded.
This procedure can be implemented graphically in the same way as scalar explana-
tion mechanisms rely on a graphical method to display and explore the dependency
0
graph stemming from any location. For example, each positive subgoal q.Ev / at
0
step 5 identifies the record Ev in relation q, which could be highlighted and related
to p.Ev/ by means of an arrow. We will examine the graphical interface to the
explanation facility in Part II.
As an aside, observe that the top-down construction could be used for more than
just explanation. Indeed, it is conceivable that we allow the user to issue one-time
queries for an arbitrary goal B. The answer would then be a relational value with
one attribute for every variable appearing in B and as many records as there are
distinct substitutions ˛ for the top-down judgment … s ` B 7! ˛. This result is
ephemeral in the sense that it is not bound to any cell in the spreadsheet, but would
appear only within a query window. It could be made permanent by pasting B in
an appropriate range of cells. A proposal in this sense can be found in [CvEL88].
The explanation mechanism just outlined operates also with respect to one-time
queries.
The same general principle can be applied to support negative explanation. When-
ever the user observes that an expected value Ev is not computed for p, an explanation
can be obtained by issuing the top-down query … s 6` p.Ev/. If Ev is not a calculated
value for p, then this judgment is derivable. Notice that, for the most part, it will
have a single, rather large, derivation tree, the only exception being whenever a
subgoal of the form … s 6` :Q is encountered since Q may have several positive
derivations.
Displaying this tree and helping the user navigate it is not as simple as in the case
of positive explanation. Indeed, we cannot effectively pre-instantiate inapplicable
clauses so that she can “see” why a fact is not derivable. For example, assume
that the user wants … s 6` p.a; b/ explained, and … s contains the single clause
p.X; Z/ q.X; Y / ^ r.Y; Z/ for p. Then, the problem reduces to … s 6`
q.a; Y / ^ r.Y; b/: there may be values for Y that satisfy q and others that satisfy
180 5 The Logical Spreadsheet
r, but none satisfy both. A more refined explanation can be obtained by asking the
system for a value c of Y that makes q.a; Y / derivable and showing the user that
r.c; b/ has no derivation, or vice versa. Altogether, there will generally be many
more possibilities to explore than for positive explanation. While a motivated user
will sift through them until she is convinced by the explanation (for example by
discovering an error somewhere), a more lenient user may not be as persevering
unless a simple and intuitive graphical mechanism is available. This aspect will be
discussed more thoroughly in part II.
As in the case of positive derivations, it is conceivable that a user asks about the
non-derivability of an arbitrary ground goal B. This is not as useful as in Sect. 5.7.1
because B may not contain variables.
5.8 Summary
In this chapter, we have translated the relational features developed in Chap. 4 into
first-order logic. The resulting formulas circumscribed a specific instance of the
logic programming paradigm, at the confluence of Datalog and constraint logic
programming. The resulting language, which does not embed recursion at this point,
is summarized in Fig. 5.5.
5.8 Summary 181
This logical interpretation does not alter the expressive power of the relational
spreadsheet. As of this chapter, it only provides an alternative syntax for relational
expressions. In particular, the definition of spreadsheet is upgraded only to the extent
that a cell range can contain a normal theory instead of the equivalent relational
expression. The distinction is purely a matter of syntax, although different users
may prefer the relational or logical interpretation in different circumstances. Issues
relating to concrete syntax will be examined in Part II.
The logical interpretation of a relational spreadsheet makes available nearly
50 years of research in logic programming as an aid to the development of the
deductive spreadsheet. In this chapter, we have scrutinized the most promising
results of this multi-decade effort and adapted them to the idiosyncrasies of the
spreadsheet context. In particular, we have observed that goal-oriented derivation
does not play as prominent a role as in traditional logic programming. Indeed,
this computational interpretation suits well the needs for a record-level explanation
mechanism, but is inappropriate at evaluation and update time. Instead, these two
key functionalities require a reading of logic programming that computes and
maintains all the atomic logical consequences of a theory. The fixpoint semantic of
logic programming, initially developed for foundational reasons and later applied
to answer queries in deductive databases, appears to be ideally suited to the initial
evaluation of a spreadsheet. The crucial operator that realizes it has the form:
V V
T…& ; & .I / D I [ …& [ f˛.P / W P i D1::m Pi ^ i D1::n :Qi
V
^ i D1::o æi i æ0i 2 &
and ˛.Pi / 2 I [ …& for all i D 1::m
and ˛.Qi / 62 …& for all i D 1::n
and ˛.æi / O i ˛.æi / is true for i D 1::o g
182 5 The Logical Spreadsheet
Updates seem to benefit from the closely related bottom-up derivation strategy for
logic programs. In both cases, the notion of stratification, which was originally
developed as a support to effectively implement negation, provides an immediate
mechanism to handle the functional dependencies that can naturally emerge in a
spreadsheet.
It is time to assess again our progresses against the objectives set forth at the end
of Chap. 3:
• We have shown that the logic-inspired mechanisms do not only work well in
isolation, but interface transparently with the scalar and array functionalities
of a spreadsheet. Therefore, as we are transitioning toward the truly deductive
spreadsheet, we continue to have a perfect integration between our extension and
the traditional support.
• We have also shown that the logical interpretation can realize evaluation and
update as efficiently as the relational view of Chap. 4. Additionally, the vast body
of literature on logic program optimization has the potential of further reducing
the overhead of these functionalities.
• As just mentioned, top-down derivation is a well-understood mechanism that is
ideally suited to supporting record-level explanation. Recall that this was the one
aspect that relational algebra was unable to deliver.
As we read these rather positive assessments, it should be kept in mind that the
logical interpretation considered in the current chapter has the exact same expressive
power as the relational language introduced in Chap. 4. We will now extend its
expressiveness.
Chapter 6
The Deductive Spreadsheet
The present chapter completes the design of the deductive spreadsheet by adding
recursion and some of its consequences into the logical language examined in
Chap. 5. While substantially extending the class of problems that can be modeled,
a simple-minded inclusion of this construct raises the concrete possibility of
divergence. This unwanted behavior can be traced back to the presence of head
constraints within recursive clauses and therefore disallowing them in that position
ensures termination. With this restriction in place, all the techniques and results
obtained for the logical spreadsheet extend with minimal adjustments to theories
enriched with recursion. This approach to curbing divergence proves however
overly zealous as it sacrifices a range of extremely common problems. Most
of these problems can be safely rehabilitated by applying a simple behind-the-
scenes transformation bounding the number of recursions in which those clauses
can participate. The same device preempts divergence in several extensions of
the resulting language. We admit one such linguistic extension in the deductive
spreadsheet, lists, as they considerably extend the expressiveness of our formalism
and yet blend smoothly into a spreadsheet infrastructure.
By the end of this chapter, the logical language of the deductive spreadsheet
will have taken form as a version of stratified Datalog enriched with constraints
and lists. This formalism is extremely powerful and yet its disciplined construction
and logical underpinning exude simplicity and elegance. The same design principles
suggest a few avenues for further improvements. One of them is its extension with
embedded implication as a native support for hypothetical reasoning. A partial
exploration of this option makes it a promising candidate for inclusion in a future
revision of our language.
This chapter is organized as follows. Section 6.1 introduces our recursive
extension by pursuing the registrar’s spreadsheet examples of Chaps. 4 and 5 with
natural inquiries that require recursion. We formalize our language and develop its
theory in Sect. 6.2. We ease the tension between termination and expressiveness in
Sect. 6.3, admitting lists in our language in the process. We present a variety of
additional examples in Sect. 6.4, and comment on several extensions, among them
embedded implication, in Sect. 6.5. Finally, Sect. 6.6 summarizes and reflects upon
the work done.
The base predicates of the registrar’s example, introduced in Chap. 4, described the
following simple relations:
• Student.F; L; S / collects the first name F , last name L and some identifier S for
a student;
• Course.N; C; I / relates the name N of a course, an abbreviation C for it, and
the instructor I who teaches it;
• HasTaken.S; C; D; G/ describes the fact that student S has obtained grade G for
course C during semester D. Because we will never make use of the last two
parameters, we define the predicate Took that only tracks the first two variables:
Took.S; C / HasTaken.S; C; D; G/
They were introduced as relations in Fig. 4.3. A few more base relations were
defined in Chap. 4, but we will not be relying on them. Instead, for our new examples
to be significant, we need to introduce a few additional predicates that we shall
consider primitive. The first one is Prereq.C; RC/, which extensionally describes
the fact that a student must have successfully taken course RC in order to take course
C : course C has RC as a prerequisite. A few instances are rendered in columns DA
and DB in Fig. 6.1.
The requirements for a course, for example Graphics (abbreviated “gr”) in
Fig. 6.1, may be determined by its instructor, who would then communicate them
6.1 Spreadsheets with Recursive Definitions 185
··· DA DB DC DD ···
1 Prereq CourseDep
2 Course Course’ Course Course’
ic ca
3
CourseDep (C, C )
ic tc
4
Prereq (C, C )
5 ca gr
6 bn an CourseDep (C, C )
7 ca os Prereq (C, C )
... ... ∧ CourseDep (C , C )
8
. . . or . . .
CourseDep (C, C )
Prereq + (C, C )
to the registrar’s office. Here, the graphics instructor has requested Computer
Architecture (“ca”) as a requirement. Note that she may not be aware that “ca” has
Introduction to Computing (“ic”) as a prerequisite and therefore will not specify
it when communicating with the registrar. Thus, the predicate Prereq describes
individual requirements, but not necessarily all the transitive requirements. Now,
members of the registrar’s office may want to see all the course dependencies, for
example to make sure that no circular requirement was entered by mistake.
Solving specific instances of this problem in the relational (or logical) spread-
sheet is possible but awkward. For example, an employee can describe all the
indirect requirements with a single intervening course by means of the clause
Prereq2.C; C 00 / Prereq.C; C 0 / ^ Prereq.C 0 ; C 00 /; requirements three hops apart
are then given by Prereq3.C; C 00 / Prereq.C; C 0 / ^ Prereq2.C 0 ; C 00 /, and so on.
Although feasible in a university setting, where prerequisite chains have length 10
or less, this is quite tedious. This number may rise to tens of thousands in other
similar problems, making this approach totally impractical.
This problem is unsolvable in the general case using only the relational or logical
language analyzed so far. However, it has a simple and elegant solution as soon as
we allow clauses to be recursive. Indeed, the predicate CourseDep, defined next,
captures transitive requirement dependencies in their generality:
CourseDep.C; C 00 / Prereq.C; C 00 /
CourseDep.C; C 00 / Prereq.C; C 0 / ^ CourseDep.C 0 ; C 00 /
The first clause states that course C depends on C 00 if C 00 is a prerequisite for it.
The second clause specifies that C also depends on C 00 if it has a prerequisite
C 0 which depends on C 00 . Notice that this second clause is recursive as the head
predicate CourseDep also occurs in the body. We have reported these two clauses
186 6 The Deductive Spreadsheet
in columns DC and DD of Fig. 6.1 (the clause below the brace will be introduced as
an abbreviation in Sect. 6.4.1).
Recursion is a very powerful tool that substantially extends the expressive power
of the language we have been defining. We will formally include it in this language
and develop its theory in Sect. 6.2. Before doing so, we will examine a few more
examples of use.
The clauses for CourseDep are typical of a transitive closure problem: given a
finite binary relation R, determine its transitive closure RC . An alternative and even
more common formulation interprets the relation R as the edges of a graph G, hence
making RC the set of all pairs of nodes in G linked by a path. The pattern of the
above clauses can indeed be reused for this problem:
path.X; Z/ edge.X; Z/
path.X; Z/ edge.X; Y / ^ path.Y; Z/
Here, it is assumed that the edges of G are extensionally represented by the primitive
predicate edge in a factual theory …edge . If we collect the two formulas for path
in the clausal theory path , then each pair of nodes n; n0 linked by a path in G
will be acknowledged by the fact that path.n; n0 / is a logical consequence of
.…edge ; path /.
Note that the graph G may contain cycles. If G is finite, the number of distinct
nodes n; n0 connected by a path in G is finite as well (but the number of paths
themselves is clearly infinite). Because we are skirting infinity so closely, we
shall take extreme care in the design of the methods used to establish logical
consequences and make sure that they terminate in all circumstances. This will be
the subject of Sect. 6.2.
The need to take a transitive closure arises frequently when working with
relations (as we have since Chap. 4). Besides course requirements and paths in
graphs, common examples include genealogies (interpret edge as a “parent” relation
and path as “ancestor”), hierarchies (take edge to be “supervisor” and path to
be “works under”), airline connections (let edge and path be “direct flight” and
“indirect flight”), chains of command, scheduling orders, etc.
We now continue our main example and show how the predicate CourseDep just
defined can be used to draw some rather advanced inferences. Consider first the
problem of establishing what courses a student S needs to take before being able to
sit in a course C . It is solved by the following simple clause:
··· DF DG DH DI DJ DK DL ···
1 CouldTakeIf MissingReq CanTake
2 Student Course Course’ Student Course Student Course
3
CouldTakeIf (S, C, RC ) MissingReq(S, C ) CanTake(S, C )
4
Student( , , S) CouldTakeIf (S, C, ) Student( , , S)
5
∧CourseDep(C, RC ) ∧Course( , C, )
6
∧¬Took (S, RC ) ∧¬MissingReq(S, C )
7
. . . or . . .
CanTake(S, C ) Student( , , S ) ∧ Course( , C, ) ∧
FORALL RC : CourseDep(C, RC ) . Took (S, RC )
··· DM DN DO DP ···
1 MaybeHarder Easier
2 Course Course’ Course Course’
3
MaybeHarder (C1, C 2) Easier (C1, C 2)
4
Prereq(C1, ) ∧ ¬Prereq(C2, C ) ¬MaybeHarder (C2, C 1)
5
∧Course( , C 2, ) ∧ Course( , C , ) ∧Course( , C 1, )
6
MaybeHarder (C1, C 2) Prereq(C1, C1 ) ∧Course( , C 2, )
7
8
∧Prereq(C2, C2 ) ∧ MaybeHarder (C1 , C 2 )
Indeed, S can take C if she is not missing any prerequisite for it. The other two
predicates are again here to satisfy the safety restrictions. All three definitions are
reported in the top part of Fig. 6.2 (the clause below the brace is again an abbreviated
form that will be introduced in Sect. 6.4.1).
188 6 The Deductive Spreadsheet
does not yield the desired behavior: this clause answers whether S has taken any
required course RC for C . The request for all prerequisites of C has incorrectly
been rendered as a request for some prerequisite of C . Extending our language
to a fragment of first-order logic that could express the above sentence within a
single clause would compromise termination. The two negations in our original
specification however forces the use of the correct quantifier. Indeed, it asks whether
it is true that there is no dependent course RC of C that S has not taken. This is more
clear if we inline the predicates CouldTakeIf within the definition of CanTake:
By moving the implicit existential quantification behind the first negation (the
variable RC in the clause for MissingReq), we have effectively implemented the
desired form of universal quantification.
We can use this technique together with recursion as in the following example,
which a lazy student may use to select a course with the least number of
prerequisites:
which computes the pairs of people who are same generation cousins in a genealogy.
It assumes the unary predicate person as identifying people, and the parent
predicate which describes parent-sibling relations (the constraint X ¤ Y is often
added). Definitions such as sgc are often used as benchmarks for optimization
techniques [CGT90].
Assume now that our university awards various types of degrees subject
to students having taken certain key courses. Let the primitive predicate
CourseForDegree.C; D/ list the core courses C associated to each degree D. It
could state for example that having taken Graphics is mandatory in order to obtain
a Masters in Computer Aided Design. Then, the list of all courses that a student
should take in order to obtain a given degree is defined by the following two
clauses.
NeededCourse.C; D/ CourseForDegree.C; D/
NeededCourse.C; D/ NeededCourse.C 0 ; D/ ^ Prereq.C 0 ; C /
··· DS DT DU DV DW ···
1 NeededCourse CourseToDegree
2 Course Degree Student Degree Course
3
NeededCourse ( C, D ) CourseToDegree ( S , D , C )
4
CourseForDegree ( C, D ) Student ( , , S )
5
NeededCourse ( C, D ) ∧NeededCourse ( C, D )
6
NeededCourse (C , D ) ∧¬Took ( S, C )
7
8
∧Prereq (C , C )
··· DX DY DZ ···
1 nCourseToDegree
2 Student Degree Number
3
( S, D ) =COUNT([ (C )
4
Student ( , , S ) CourseToDegree ( S, D , C )
5
∧CourseForDegree ( , D ) ∧ S = DX 3: DX
6
∧ D = DY 3: DY ])
7
it. Let us first insert every student-degree pair in columns DX-DY. The anonymous
clause
achieves this. The following array formula then computes the number of courses in
CourseToDegree for every such pair:
COUNT.Œ .C / CourseToDegree.S; D; C /
^ S D DX3WDX
^ D D DY3WDY /
We put it in column DZ. For any location DZn (with n > 2), the inner anonymous
clause extracts from CourseToDegree all the courses C that the student in cell DXn
needs to take in order to qualify for the degree in cell DYn. The resulting set of
values is converted into an array by means of the Œ: : : operator and counted using
the traditional function COUNT. The combined process is reported at the bottom of
Fig. 6.3.1
1
It should be noted that this problem can also be solved in a purely functional manner by relying
on the extended array operators E and E introduced in Chap. 4. A purely clausal solution is also
possible, but requires further extensions to our language. It will be examined in Sect. 6.5.
6.1 Spreadsheets with Recursive Definitions 191
6.1.4 Limitations
Given this series of examples as motivation, we will now develop the machinery
underlying recursive spreadsheet theories along the lines of the discussion in
Chap. 5. The good news is that we have already done much of the required
work in that chapter. Indeed, this section will mostly be concerned with minor
adjustments to adequately model and mechanize recursive definitions. We will be
particularly concerned with making sure that all the procedures devised so far
remain terminating even in the presence of recursion.
We begin, in Sect. 6.2.1, by updating the safety requirements on general theories
to ensure termination. In Sect. 6.2.2, we revisit the fixpoint semantics of Chap. 5
as an evaluation procedure for recursive theories and show that it terminates also
in this extended setting. In Sect. 6.2.3, we refine our update methodology to take
recursive clauses into account. In Sect. 6.2.4 we take another look at top-down
derivability as an explanation mechanism in recursive theories. In Sect. 6.2.5, we
situate the fragment of first-order logic underlying the deductive spreadsheet within
the taxonomy of logic programming languages. Finally, in Sect. 6.2.6 we interpret
the obtained language back to relational algebra.
Judging from the examples in Sect. 6.1, the formulas underlying the deductive
spreadsheet differ from the language examined in Chap. 5 by simply lifting the ban
on recursively defined clauses. This is the case at the macroscopic level and, indeed,
the grammar defining the fragment of first-order logic we will be working with
remains the same:
Theories … WWD …;
Factual Theories … WWD j …; p.Ev/
Clausal Theories WWD j ; Cl
Clauses Cl WWD H B
Heads H WWD p.X; : : : ; X /
Bodies B WWD P j :P j æ æ j B ^ B
Predicates P WWD p.X; : : : ; X /
clause without any negative literals is called definite, otherwise normal, and we omit
these adjectives when unimportant or clear from the context. The same applies for
(sub)theories.
Since the defining grammar has not changed, the general form of a clause remains
the same:
^ ^ ^
P Pi ^ :Qi ^ æi i æ0i
i D1::m i D1::n i D1::o
This time however, the predicate symbol p of the head P may occur in one or more
body literals Pi . This form of recursion, in which p occurs in the body of a clause
defining it, is called simple. All recursive clauses in Sect. 6.1 were simple. A clause
for p may also rely on a predicate q mentioning p in one of its defining clauses.
Then, p and q are said to be mutually recursive. Needless to say, mutual recursion
can generally involve more than two predicates. No matter whether a predicate p
participates in a simple or a mutual recursion, it is often the case that some of
its defining clauses will not be recursive. Such clauses form the base cases of the
definition of p. Note that in a non-recursive theory, all clauses are base clauses.
At this point of Chap. 5, we introduced a number of safety requirements about
variable occurrences within a clause to ensure mechanizability. We recall them in
preparation of further restrictions:
1. A variable X occurring in the head of a clause also must occur:
E / in the body of the clause,
(a) Either in a positive literal p.X
(b) Or as the left-hand side of a head constraint X D æ.
2. Any variable X occurring within a generic constraint æ1 æ2 , or on the right-
E/
hand side of a head constraint Y D æ, must also occur in a positive literal p.X
in the body of the clause.
3. Any variable X occurring in a negative literal :Q must also occur in a positive
E / in the body of the clause.
literal p.X
While these local requirements still apply, the admission of recursive clauses forces
us to impose further restrictions, this time at the level of groups of clauses. They
do not properly apply to variables per se, but they affect how variables are used.
These new requirements are best formalized in terms of the dataflow graph of a
recursive theory.
Call Graph
Recall from Chap. 5 that the (strict) call graph CG… of a theory … D .…; /
tracks the dependencies among the predicates in … . It distinguishes between the
purely relational dependencies due to a predicate symbol q occurring in a clause
defining p, and dependencies arising from negation, which we labeled functional
(we temporarily ignore extra-logical dependencies arising from the underlying
194 6 The Deductive Spreadsheet
ς0 CourseDep NeededCourse 1
¬Prereq ¬Took
ς1 2 MissingReq
¬MaybeHarder ¬MissingReq
ς2 Easier CanTake
Fig. 6.4 Stratified call graph in the recursive part of the registrar’s spreadsheet
Edges.CG… / D E / q.YE / ^ B 2 g
fq ! p W p.X
[ f:q ! p W p.XE / :q.YE / ^ B 2 g
[ fp Ü :p W p; :p 2 Nodes.CG… /g
The call graph corresponding to the theory accumulated from the examples in
Sect. 6.1 is displayed in Fig. 6.4. If … is distilled from a (deductive) spreadsheet s,
a situation we denoted by … s in Chap. 5, additional functional dependencies arise
when cells in the base relation corresponding to a primitive predicate reference or
overlap cells calculated clausally. The arrow from node 1 to node 2 (which corre-
spond to the two anonymous predicates in Fig. 6.3) in Fig. 6.4 is an instance of this
phenomenon. The graph obtained by incorporating these additional dependencies
into CG… s was called the enriched call graph of s. In Chap. 5, it had the property
that there were no cycles through ! edges. Cycles through a combination of ! and
Ü edges were possible in degenerate situations that we chose to ignore.
6.2 Recursive Spreadsheet Theories 195
Cycles naturally emerge in CG… as soon as we allow the clauses of the theory
… to be recursive. Indeed, there are three cycles in Fig. 6.4. As evidenced in
the examples of Sect. 6.1, circularity is indeed inseparable from recursion, and is
actually quite beneficial in general. We shall however impose some restrictions on
recursive definitions in order to ensure termination. Specifically, we will forbid
loops involving Ü edges through stratification and prevent recursively defined
predicates from relying on head constraints (we will relax this requirement in
Sect. 6.3.1).
Note that the different forms of recursion are particularly easy to assess on the
call graph of a given theory. Indeed, simply-recursive predicates are characterized
by self-loops, i.e., ! edges whose origin and destination coincide. Instead, mutually
recursive predicates participate in cycles involving more than just one node. Such
cycles are the strongly connected components of CG… . A simple inspection of
Fig. 6.4 shows that all recursions in our ongoing example are simple.
expect few end-users to ever feel the necessity of writing non-stratifiable spreadsheet
theories. Other, less satisfactory, approaches to handling negation are discussed
in [CGT90].
As noted above, some artificial but otherwise legitimate (non-recursive) spread-
sheet theories are non-stratifiable. As in Chap. 5, we will ignore them for simplicity,
confident that they can be accommodated by appropriately extending the definition
of dataflow graph.
path|1 path|2
...................................................................................................
edge|1 edge|2 path (X, Z, C) edge(X, Z)
∧C=1
path (X, Z, C) edge(X, Y ) ∧ path (Y , Z, C )
path |1 path |2 path |3 ∧C =C +1
Its dataflow graph is given in the lower part of Fig. 6.5. If the factual theory …edge of
the edge predicate implements a graph that is itself acyclic, then evaluating path0 will
return all its paths with their respective lengths. If, however, …edge represent a graph
that has loops, for example if …edge D fedge.a; a/g, then path0 will have infinitely
many valid instantiations of growing length. In this specific example, path0 .a; a; n/
for any n 1 would be derivable. Since the set of logical consequences of this
simple theory is infinite, its evaluation is non-terminating: an undesirable behavior
in the context of a spreadsheet.
Since recursion is a highly prized feature in the deductive spreadsheet, we
will avoid this type of situation by forbidding clauses participating in a recursion
from containing head constraints. We call this the head constraint restriction and
formalize it by saying that the dataflow graph DF… of an admissible theory …
shall not contain cycles involving ) edges. Note that the base cases of a recursive
definition can rely on head constraints: only recursive clauses are affected.
As we will see shortly, the head constraint restriction is sufficient to ensure that
the set of logical consequences of a recursive theory is finite, and therefore that its
evaluation terminates. Giving up head constraints in recursive definitions is however
a high price to pay since they are often harmless and extremely useful in practice.
Consider the following alteration to the clauses for path0 that only reports paths of
length at most 5:
This theory has finitely many logical consequences no matter what …edge contains.
Moreover, it can be used as a template for useful applications such as calculating
the number of hops of an air journey, computing the total distance of a segmented
trip, reporting the cost of a composite product, etc. It however violates the head
constraint restriction and is therefore not admissible.
198 6 The Deductive Spreadsheet
Deductive Spreadsheet
The model theory of a set of recursive clauses has the same properties as the
simpler fragment studied in Chap. 5. Indeed, validity in a theory … is completely
characterized by the underlying Herbrand base HBV , which contains all the
Herbrand interpretations of … , and in particular its Herbrand models. By the very
arguments presented in Chap. 5, a (recursive) definite theory has a least Herbrand
model and a stratifiable (recursive) theory has a perfect model. We continue to write
I… for either.
Let … be a stratifiable theory. Then, for any stratum & 2 &E and corresponding
subtheory … & D .…& ; & /, the set of logical consequences of … & is constructed
on the basis of the following operator on Herbrand interpretations, reported from
Sect. 5.4.2:
V V
T…& ; & .I / D I [ …& [ f˛.P / W P i D1::m Pi ^ i D1::n :Qi
V
^ i D1::o æi i æ0i 2 &
and ˛.Pi / 2 I [ …& for all i D 1::m
and ˛.Qi / 62 …& for all i D 1::n
and ˛.æi / O i ˛.æi / is true for all i D 1::o g
This operator is monotonic and continuous over the lattice structure induced by
the subset ordering on the Herbrand base HBV . Its least fixpoint is lfp.T…& ; & / D
T…!& ; & .;/. It contributes the logical consequences of the predicates defined in … &
6.2 Recursive Spreadsheet Theories 199
Termination
In Sect. 5.3.4 of the last chapter, we proved that the computation of the least
Herbrand model I… of a non-recursive definite theory … accessed at most a finite
set V… of constants defined as follows (where pji stood for the i -th argument of
predicate p):
S
V… D pji 2 … Vpji
8
<S
p.:::;vi ;:::/ 2 …p fvi g if p is primitive
Vpji D S
: E VXi jB if p is not primitive
.p.X/B/ 2 p
8T
< E 62 B 0
Xi DYik Vq k jik if .Xi D æ.Z//
V V k Ek D k
„ ƒ‚ … :fæ.v
Xi j k q . Y / ^ B 0 E 2 B0
O 1 ; : : : ; vn / W vj 2 VZj jB g if .Xi D æ.Z//
B
An immediate consequence of this fact was that I… was bounded by HBV… , a finite
subset of the Herbrand base HBV . Therefore I… ought to be finite. Furthermore,
only finitely many iterations of T…; were necessary to produce it since the iterative
procedure stopped as soon it had reached a fixpoint. An identical argument applied
in the case of a normal theory.
200 6 The Deductive Spreadsheet
While this construction enjoys the same properties in the recursive case, it
is much more difficult to work with it. Indeed, Vpji may appear within its own
definition for a recursive p. For this reason, we will now downgrade … to a non-
recursive theory … 0 , define an approximation W… 0 (much less precise than V… )
and show that W… 0 is finite and that V… W… 0 . We begin by defining … 0 .
For every predicate p appearing in … , we define the set rec.p/ as:
rec.p/ D fq W p ! q ! p in CG… g
We now define one clause for each predicate in rec.p/, and each has Brec.p/ as its
body:
[
0
rec.p/ D E Brec.p/ g
fq.X/
q 2 rec.p/
Note that none of these clauses is recursive. Finally, we define the clausal theory 0
by removing every recursive clause from and replacing it with p.X E / Brec.p/
for each recursive predicate p:
[ [
0 D n rec.p/ [ 0
rec.p/
p in p in
Observe that 0 is not recursive. Let … 0 D .…; 0 /. Its set of logical consequence
has little to do with that of … , but the portions of the Herbrand universe they rely
on are related, as we will see shortly.
Given a theory … , we define the set W… as the following over-approximation
of the set of values that can appear in any of its logical consequences:
6.2 Recursive Spreadsheet Theories 201
8 S
ˆ
ˆ W… D Wp
ˆ
ˆ p2…
ˆ
ˆ (
ˆ
ˆ
ˆ
<W fv W v in …p g if p is primitive
p D S
ˆ .P B/2 p WP B
otherwise
ˆ
ˆ
ˆ
ˆ E / in B and Ev 2 .WB /jXE j g
ˆ
ˆ W D WB [ fæ.Ev/ W Y D æ.X
ˆ P B S
:̂
WB D q in B Wq
Cost
Having established that the fixpoint computation of the perfect model of a recursive
theory terminates, we need to determine how much it costs to produce it. Recall
from Sect. 5.3.4 that in the non-recursive (definite or in-stratum) case, the number
202 6 The Deductive Spreadsheet
of iterations of T…; was bounded by the length jCG… j of the longest path in CG… :
exactly jCG… j C 1 iterations were necessary.
There is no such bound in the presence of recursion. Indeed, the number of
iterations does not depend solely on the clausal structure of a theory … D .…; /
but also on the contents of the factual theory …, in general. Consider the familiar
example of the transitive closure path of a binary relation edge. The form we have
encountered so far (called right-recursive) has the following definition:
path.X; Z/ edge.X; Z/
path.X; Z/ edge.X; Y / ^ path.Y; Z/
Its cost is linear in the length l of the longest path in the object-level graph described
by …edge (excluding loops). Indeed, T…i .;/ will contain all the paths of length up to
i and therefore the computation will stop at T…l .;/. If we interpret as a program
and … as data, as often done for deductive databases, then the number of iterations
depends not only on the program as in the non-recursive case of Chap. 5, but also
on the data. In particular, the seemingly innocuous addition of one edge fact can
significantly alter the number of iterations needed to compute the perfect model of
this theory.
Note that this bound on the cost also depends on the way clauses are entered.
Indeed, the outcome is quite different in the case of the following quadratic (i.e.,
twice-recursive) definition of path, which is logically equivalent to the previous
one:
path.X; Z/ edge.X; Z/
path.X; Z/ path.X; Y / ^ path.Y; Z/
Here, the cost is logarithmic in l. Indeed, T…i .;/ will contain all the paths of length
dlog le
up to 2i and therefore the computation will stop at T… .;/.
Unfortunately, not all recursive definitions can be rearranged to manifest this
property. For example, the same generation problem, defined as
sg.X; X / node.X /
sg.X; Y / sg.X 0 ; Y 0 / ^ edge.X 0 ; X / ^ edge.Y 0 ; Y / ^ X ¤ Y
A direct use of the T…& ; & operator described at the beginning of this section
yields a version of the naı̈ve evaluation procedure that computes the perfect
model of a recursive theory … and forms the backbone of the homonymous
spreadsheet evaluation method (discussed below). Like every naı̈ve procedure we
have encountered so far, it is inefficient because each iteration recomputes all the
facts produced by previous iterations, and may add a few more. This drawback is
accentuated in the case of recursive theories because, as we just saw, the number
of iterations needed may be much larger than in the non-recursive case, now a
function of both the factual data and the clausal theory. Therefore, it is more
important than ever to mitigate this overhead. In the past, we refined naı̈ve evaluation
into a semi-naı̈ve method that carefully avoided computing the same values twice
(as well as prematurely trying to compute a value before all of its arguments
were available). This was easily achieved by focusing on the entities (either scalar
formulas, relational expressions, or clauses) all of whose arguments had just become
available. Then, their value was computed in a single step.
This simple approach is suboptimal in the presence of recursion. Indeed, the
evaluation of a recursive predicate p may span several iterations. Within this
interval, our current semi-naı̈ve optimization has no effect: at each such iteration
all previously computed values for p would be recomputed. Note however that
our current approach would still be effective for non-recursive predicates (which
are still evaluated in a single step) and at the boundary of groups of mutually
recursive predicates (the strongly connected components of CG… ). Therefore,
we shall concentrate on recursive predicates and extend our present semi-naı̈ve
procedure with a technique to efficiently calculate their logical consequences. We
will draw inspiration from our previous work on updates and from the abundant
literature on Datalog query optimization [CGT90,GKB87,RSS92], where the notion
of semi-naı̈ve evaluation has been scrutinized for years.2
Let p be a recursively defined predicate in a theory … D .…; / that we will
initially assume to be definite, for simplicity. We define …kp to be the set of logical
consequences of p computed up to the k-th iteration of the T…; operator:
2
It should be noted that the appellation semi-naı̈ve evaluation is usually reserved for the technique
we are about to present, which reaps benefits only for recursive definitions, rather than the general
approach we have been developing (which will include this technique as a subroutine). We justify
broadening the use of this terminology by the fact that our previous efforts are in the same spirit as
this better recognized but also more specialized application.
204 6 The Deductive Spreadsheet
E / p k .YE / ^ B
p kC1 .X
E / p k1 .YE / ^ B
p kC1 .X
p .X / p k .YE / ^ B
kC1 E
The first clause has the same body as Cl and therefore represents the contribution
of this clause to …kC1 k
p . In particular it is already accounted for in …p . The second
clause describes the additions that Cl contributes to …kC1
p , which in general are not
represented in …kp . We can take this as the definition of the predicate p kC1 . We
capture this by the clause
E / p k .YE / ^ B
p kC1 .X
6.2 Recursive Spreadsheet Theories 205
pk+1 (X)
ΔΠk+1
p Δpk (X)
E/
If p’s definition relies on a set rec.p/ of several recursive clauses Cli D p.X
p.YE / ^ Bi for i D 1::n, and all are linear, we can repeat the above argument,
obtaining the following characterization for p kC1 :
E / p k .YE / ^ B1
p kC1 .X
:::
p .X / p k .YE / ^ Bn
kC1 E
Observe that these clauses are isomorphic to the original recursive clauses of p:
indeed, if we drop the superscripts and the ’s, they are precisely the elements of
rec.p/ . This observation supports an alternate expression of …kC1 p which does not
rely on any extension to the original set of predicates in … . Indeed, …kC1p can be
obtained by a single application of the clauses in rec.p/ to just the objects in …kp .
As we do so, we must be careful to provide all the facts needed by the body of these
clauses. This idea is formalized in the following expression
…kC1
p D T.…k n…kp /; rec.p/ .…kp /
E p k .YE / ^ p k .Z/
p kC1 .X/ E ^B
kC1 E k E k E
p .X/ p .Y / ^ p .Z/ ^ B
E p k .YE / ^ p k .Z/
p kC1 .X/ E ^B
Here the computation of …kC1 p relies not only on …kp but also on …kp ; hence the
decrease in efficiency (note however that it does not amount to recomputing …kp as
the naı̈ve approach would do). Note also that these three clauses cannot be construed
as an instance of Cl.
As anticipated, we have seen that general theories enjoy the exact same model-
theoretic properties as their non-recursive counterparts examined in Chap. 5. There-
fore, we can follow the path cut-out there in order to turn this foundational work into
viable procedures for evaluating a deductive spreadsheet s. Indeed, simply adapting
the fixpoint computation to operate relative to an environment (which may contain
undefined values) yields the naı̈ve evaluation procedure ER s exactly as in Sect. 5.5.
It can be refined into a semi-naı̈ve procedure EP s using the approach discussed in
Chaps. 3 and 4, extended to handle recursion. In spite of the these efforts, this
results only in a slightly better performance for the reasons discussed in Sect. 5.5. A
significant improvement is however achieved by breaking the theory … s of s into
functionally independent portions and evaluating them separately as needed. This
yields the counterpart of the enhanced naı̈ve and semi-naı̈ve procedures, ER s0 and EP s0 ,
respectively, examined in Sect. 5.5. This last approach can be further enhanced by
enacting the optimizations we just developed.
As with model theory, the basic tenets of the proof theory of recursive clauses do not
change from what we obtained in Chap. 5. Indeed, the general notion of derivability,
defined in Sect. 5.4.3 through the judgment … ` Bi for a ground body element
Bi remains unaltered. However, adding recursion has subtle implications on the
applicability of proof-theoretic techniques to implement spreadsheet functionalities.
6.2 Recursive Spreadsheet Theories 207
We will now begin to examine them, starting with the bottom-up flavor of derivation
and updates. Top-down derivability and its application to explanation are the subject
of Sect. 6.2.4.
Bottom-Up Derivation
The last of the theoretical aspects studied in Chap. 5 that we need to discuss in
the presence of recursion is top-down derivability. In Sect. 5.4.3, we expressed this
notion by means of two judgments,
… ` B 7! ˛ and … 6` B
The first described the fact that a derivation could be constructed for the query B
in … , with the (possibly partial) substitution ˛ constraining the values of variables
appearing in it. The second, needed for handling negative literals, formalized the fact
that the ground query B was not derivable in … . Inference rules for both judgments
are reported in Fig. 6.6 from Sect. 5.4.3.
Extending our clausal language with recursion does not per se affect the theoretical
validity of that development. Indeed, neither the form of these judgments nor the
rules themselves require any change. In practice, the situation is quite different as a
simple-minded application of these rules can result in the attempted construction of
infinite derivation trees. Consider for example the standard right-recursive definition
of the path predicate:
path.X; Z/ edge.X; Z/
path.X; Z/ edge.X; Y / ^ path.Y; Z/
6.2 Recursive Spreadsheet Theories 209
.1/
Let the extension of the edge predicate initially be …edge D fedge.a; b/g and let
… .1/ be the theory consisting of those two clauses and this fact. Then, the rules
in Fig. 6.6 will return a first answer to the query … .1/ ` path.X; Y / 7! ˛ by
using rule np" followed by pr" on the first clause and producing the substitution
˛ D fX 7! a; Y 7! bg. Attempts at constructing additional answers will fail
immediately: an initial use of the second clause will invoke rule bd", whose first
subgoal, edge.X; Y /, will succeed with substitution fX 7! a; Y 7! bg, but which
will then expose the subgoal path.b; Z/, which fails right away.
Here, we adopted the depth-first left-to-right subgoal reduction strategy implicit
in rule bd". The outcome could however have been quite different had we relied on
another strategy. Consider depth-first right-to-left reduction, which can be emulated
with the rules in Fig. 6.6 by reversing the order of the literals in the body of the
second clause for path: then, once the initial answer has been produced, this strategy
would start constructing an infinitely high tree by inconclusively expanding the
subgoal path.Y; Z/, interspersing any new step up with a failed attempt at using
rule pr".
The expensive breadth-first strategy would overcome this impasse. This solution
does not solve the general problem, however: consider the two rules above with the
.2/
factual theory …edge D fedge.a; a/g. Then any of the strategies examined so far will
embark into an infinite tree construction after producing the initial answer.
Here, the blame can be put on the presence of a cycle in the graph represented by
the edge predicate. Similar behaviors are however also manifested in the absence
of cycles. Consider the quadratic definition of the path predicate encountered
earlier,
path.X; Z/ edge.X; Z/
path.X; Z/ path.X; Y / ^ path.Y; Z/
.1/
and the factual theory …edge . The same behavior emerges again: after the initial
answer is produced, any of the above strategies starts building an infinite tree.
All of the above behaviors returned the correct answer before diverging in search
of alternative derivations. This is because we were wise enough to always attempt
using the base rule for path first. Had we given the recursive rule higher priority, no
answer would be reported whatsoever.
Divergence is a problem even if all we are interested in is the first answer to
a query. Indeed, if this query has no solution, then only the divergent behavior is
manifested. This is particularly unsettling in the case of negative queries, which are
often expected not to have any solution. Negative queries are either entered by the
user or result from using rule nl" to assess the derivability of a negative literal.
All of these problems are familiar to Prolog programmers, who have learned
to cope with them by carefully ordering clauses and their bodies, by inserting
appropriate checks, and by relying on extra-logical devices to control execution.
A Prolog programmer would not see any problem with the rules in Fig. 6.6 because
she has the skills to work around potential pitfalls.
210 6 The Deductive Spreadsheet
This is clearly not the case of the expected user of the deductive spreadsheet:
an individual with no formal training in either logic or computer science, in
general. Any form of divergence (and even slow convergence) is unwelcome news.
Therefore, it is crucial to devise top-down derivation strategies that do not diverge in
any circumstance. In particular, finite derivability should be ensured independently
of the contents of the factual base … of the given recursive theory … , independently
of the ordering of clauses in , and independently of the order of the conjuncts in
the body of any clause.
Clearly, this objective must be achievable since the perfect model of any recursive
theory is computable in finite time, as we have seen in Sect. 6.2.2. We will now
briefly examine two methods to ensure the termination of top-down derivability.
The first, pioneered by David Smith, Michael Genesereth and Matthew Ginsberg
in [SGG86], observes that the height of the derivation tree of any answer to a given
query B in a theory … is bounded by a function h.… ; B/ that depends only on
… and B: there may be larger derivations, but their answers would duplicate those
of smaller trees. This observation can immediately be used to fend off the threat of
divergence. Given the query … ` B 7! ˛, we build derivation trees as described in
Sects. 5.4.3 and 5.7, but discard any tree as soon as it grows beyond height h.… ; B/.
Complete trees smaller than this bound are returned. Notice that this approach works
with both the breadth-first and depth-first strategies. Notice also that it handles both
positive and negative queries. The practicality of this approach depends the value of
h.… ; B/. The value pred .conChc convar / obtained in Sect. 6.2.2 can be used as an
upper bound on the number of applications of rule np", and therefore determines the
maximum value of h.… ; B/. As we said, that bound is often astronomical and often
bears little resemblance the actual figure for h.… ; B/. More accurate values can be
found in [SGG86], which also discusses dynamically generated halting conditions
for when to stop expanding a branch of the derivation tree. These approaches can
be easily adapted to the specific language used by the deductive spreadsheet. A
thorough investigation is beyond the scope of this book.
The second approach, proposed by David S. Warren in the XSB system [War98],
is radically different, and indeed embeds aspects of bottom-up derivability. The
basic idea is that each time a new answer for an atomic goal P involving a clausally
defined predicate p is produced, it is cached (tabled in XSB terminology), and each
time P is encountered again, previously computed answers are returned rather than
the subtree being rebuilt from scratch. If p is recursive, the discovery of a new
answer for P may trigger further requests which will eventually lead to new unique
answers. The computation stops when no new answer is produced.
Going into more detail, consider the judgment … ` P 7! ˛, where the predicate
p in P is clausally defined and some arguments may be constant while others
may be variable. Resolving P against the defining clauses of p (by the equivalent
of rule np") will yield a number of subproblems of the form … ` Bi 7! ˛i .
6.2 Recursive Spreadsheet Theories 211
As a conclusion of this section, we recall that top-down derivation was the approach
of choice for supporting explanation in the logical spreadsheet, as discussed in
Sect. 5.7. It remains so in the deductive spreadsheet, which makes termination a
paramount property. The tabled method [War98] just discussed appears to be a
good choice for this purpose. Indeed, it is efficient and can easily be adapted to our
interactive explanation needs. Experimental validation is however necessary. The
first approach above [SGG86] seems to suffer from efficiency problems, but further
investigation is needed in order to make a definitive assessment.
The above section concludes the core development of the logical infrastruc-
ture underlying the deductive spreadsheet (we will describe useful extensions in
Sects. 6.3 and 6.5). This is therefore a good point to comment on where the language
we have developed stands in the logical spectrum. We will now collect the many
references that peppered the last two chapters into a coherent account.
The fragment of first-order logic we have been working with is closely related to
a number of languages that altogether have fueled the field of logic programming
for the past 50 years. The computational value of logic was first recognized in
the field of linguistics [Col70, Gre69] in the late 1960s. The enabling technology
was the recent discovery of resolution [Rob65] in the spheres of theorem proving.
The specialized language prototype used in these efforts would soon evolve into
Prolog [CM87, O’K90, SS94], a general-purpose programming language that still
212 6 The Deductive Spreadsheet
dominates the logic programming scene. The logical core of Prolog differs from our
language in three respects:
1. It draws its terms from a freely generated language containing not only constants
and variables, like ours, but also uninterpreted function symbols. Therefore, a
predicate can have the form p.f .X /; g.f .a/; Y // rather than just p.X; a; Y /.
Including this possibility in our language leads to two problems: first and
foremost is non-termination; second, it clashes with the traditional design of
a spreadsheet, in which cells evaluate to atomic values rather than structured
objects. We will come back to this aspect in Sects. 6.3 and 6.5.
2. It does not rely on any safety restrictions.
3. It does not admit constraints. However, actual Prolog implementations do make
available “extra-logical constructs” that are akin to our constraints.
The theory of core logic programming blossomed in the 1970s and 1980s with
precise accounts of its model semantics [EK76, Kow79], its proof-theoretic seman-
tics [AvE82, Llo87, MNPS91], and especially the semantics of negation [Cla78,
Prz87, Har94].
The early 1980s saw the development of Datalog and the notion of deductive
database [GM78, Min87, CGT90, Col98]. It was observed that the fragment of core
logic programming deprived of functional symbols and recursion (and extended
with safety restrictions) had the same expressive power as relational algebra.
Adding recursion back extended this expressiveness without compromising effec-
tive computability. Negation always proved problematic in this picture, although
stratification [CH85, ABW87, CGT90] was eventually recognized by most authors
as the best way to handle it.
Constraints were prominently incorporated as first-class citizens of logic pro-
gramming in the late 1980s with the proposal of constraint logic program-
ming [JL87, JM94]. This popular extension of “traditional” logic programming
yielded a family of language known as CLP(D), where D represents a domain
(for example the real numbers), a language of constraints on them (e.g., linear
inequalities over the reals), and a constraint solver for them (e.g., the simplex
algorithm). Constraint logic programming proved very effective in tackling a
number of practical problems [JM94]. The language we have developed in this book
can be viewed as a form of CLP based on a term language deprived of function
symbols and whose constraints are inherited from the underlying spreadsheets.
Figure 6.7 summarizes the relationships among these flavors of logic program-
ming and our proposal. The fragment of first-order logic carved out in this book
can indeed be seen as an extension of Datalog with constraints, or a function-free
specialization of CLP. Traditional logic programming stands at the antipodes of
these two dimensions. Versions of Datalog enriched with constraints are not new,
and have indeed been extensively studied in relation to the notion of constrained
database [KKR95, KLP00] and more recently trust management [LM03]. Con-
straints in constraint logic programming and constraint Datalog play an important
role in the representation of data and are therefore much more general than the
purely evaluative use we make of them.
6.2 Recursive Spreadsheet Theories 213
Constraint
Logic Programming
CLP (D) [JL87; JM94]
− Constraints − Functions
− Functions − Constraints
Datalog
[CGT90]
Fig. 6.7 The language of the deductive spreadsheet within logic programming
We conclude this section by looking back at relational algebra and describing what
extension could capture the added expressive power of recursive clauses. We also
report on the relative computational expressiveness of the various languages we have
examined.
p WD eN
Under this interpretation, a relational spreadsheet s extends the basic scalar and
array infrastructure with a set of relational definitions of the above form, one
for each relational expression appearing in s. Since the relational dependency
graph of s was required to be acyclic in Chap. 4, these definitions could not be
recursive.
Once we describe the relational extension of the spreadsheet in terms of relational
definitions, lifting the ban on recursion is a natural avenue to explore, and one that
214 6 The Deductive Spreadsheet
leads to the logical language we have designed so far. Indeed, a predicate p defined
by simple recursion corresponds to a relational equation of the form
p D e.p/
N
p1 D eN1 .p1 ; : : : ; pn /
pn D eNn .p1 ; : : : ; pn /
The head constraint restriction bans the use of generalized projections within a
recursive definition. As such, it adds to the safety restrictions natively present
in relational algebra, as noted in Chap. 5. Instead, the negative literal restriction
corresponds to preventing a recursively defined relation p from occurring on the
right of a relational difference operator in its own definition. It should be noted that
it is an artifact from a purely algebraic point of view, although it yields the same
computational benefits as in our logical language.
For example, the relational definitions in Fig. 6.8 capture the fragment of our case
study examined in Sect. 6.1. For conciseness, we have used positional projection
and selection indices rather than attribute symbols. Note that the definitions for
CourseDep, MaybeHarder and NeededCourse are recursive.
6.2 Recursive Spreadsheet Theories 215
æ,rec
RA+ RAæ
+ RA+
Logrec,¬ Logrec,¬
æ Log¬
æ
RA RAæ RAæ,rec
Logrec Logrec
æ
Expressive Power
Since our initial extension of the traditional spreadsheet with relational expressions,
we have examined a number of languages, both relational and logical. We will now
discuss their relative expressive power, including that of interesting sublanguages.
Our results are summarized in Fig. 6.9. For simplicity, we did not account for the fact
that these languages are meant to be embedded within a spreadsheet in our context:
doing so has the effect of boosting their expressiveness by pairing them up with
traditional functional formulas, thanks to the availability of functional dependencies
(as we have seen in Sect. 6.1.3). This more refined analysis will be the subject of
future work. The spreadsheet-embedded variant of each language is expected to
have more expressive power than this language taken in isolation. It is also expected
that the relative strength of the embedded languages will not vary substantially, at
most merging currently distinct classes.
Each area in the upper part of Fig. 6.9 represents the class of problems that
the language that labels it can solve. Acronyms are explained and referenced in
216 6 The Deductive Spreadsheet
the bottom part of this figure. For example, the box surrounding RA expresses
all the problems that can be stated using traditional relational algebra. Formalism
A is more expressive than formalism B if it can solve more problems, which is
rendered as the area for A enclosing the area for B. Thus relational algebra (RA)
is strictly more expressive than positive relational algebra (RAC —i.e., RA deprived
of the difference operator). Two formalisms, e.g., relational algebra and our logical
formalism deprived of recursion (Logrec ), have the same expressiveness if they can
solve the same problems, which we rendered as an area enclosed by a double line.
Clearly, two languages may have incomparable expressiveness: for example each
of RA and RAæ C , positive relational algebra extended with attribute expressions,
can solve problems that the other cannot. Finally, the areas delimited by dotted
lines indicate formalisms that we have mentioned, but not yet fully examined. For
conciseness, we refer to the variants of our logical formalism relative to Datalog, as
discussed in Sect. 6.2.5.
We will now comment on the relations displayed in Fig. 6.9, most of which are
standard results in the literature (see for example [CGT90]). First notice that for the
most part, each relational language has a corresponding logical formalism with the
same expressive power. Indeed, corresponding features (e.g., attribute expressions,
recursion) yield similar expressiveness. The one exception is negation/difference:
until recursion is considered, relational languages with difference solve the same
classes of problems as the corresponding logical languages with negation. Recursion
changes this state of affairs because of our requirement that normal theories be
stratified. Indeed, there are recursive relational definitions that do not correspond
to any stratified theory. Had we allowed non-stratified theories (and accepted the
performance penalty), the two languages would have the same expressive power.
Note that in the absence of recursion, a normal theory is necessarily stratified
(although functional dependencies may alter this). See [CGT90] for an in-depth
discussion of expressiveness in the presence of negation.
Moving now left to right, it is clear that allowing attribute expressions (con-
straints in the logical setting) furthers expressiveness. Note however that the
underlying functional language of a spreadsheet can completely bridge the gap
in this case, as we saw in Sect. 4.3.2. Recursion does provide a real extension of
expressive power, even when considering the full spreadsheet context. Indeed, we
have seen several examples of this in Sect. 6.1, and more will be presented shortly.
As we saw, the head constraint restriction significantly limits the class of
problems that can be solved in the deductive spreadsheet, but also safeguards
termination. We will discuss in Sect. 6.3.1 an approach to partially lifting this
restriction and yet retaining termination. This will allow us to approach the added
expressiveness of fully permitting head constraints in recursive clauses.3 Finally,
3
To be fully precise, the theoretical expressiveness will remain the same as in our current language,
but in the majority of circumstances it will provide the illusion of a language with unrestricted head
constraints.
6.3 Bounded Termination 217
a further extension of the resulting language with lists will significantly extend the
expressive power. This will be examined shortly.
trip.F; T; D/ hop.F; T; D/
trip.F; T; D/ hop.F; M; D 0 / ^ trip.M; T; D 00 /
^ D D D 0 C D 00
218 6 The Deductive Spreadsheet
Of course, since airlines have return routes, these two clauses are bound to
divergence as any calculation will eventually start going back and forth between
already visited cities. A crude way to avoid non-termination is to put a bound
on the maximum distance that can be flown: let us place it at 24,900 miles—the
circumference of the earth (we will describe a more sensible solution in Sect. 6.3.2):
The second clause contains the head constraint D D D 0 C D 00 but also the expres-
sion D 24;900 which effectively bounds D. The bounding action of this constraint
is evident in this example. This is not always the case. Consider the following variant
of the above definition, which an airline may use for pricing an itinerary:
It considers the actual distance of any trip shorter than 24,900 miles, but assigns the
blanket value 24,900 to any longer trip. Surprising as it may be, computation always
terminate in this theory. Indeed, the maximum value of D appearing in any inferred
fact trip.F; T; D/ is 24,900 and since there are finitely many airports, only a finite
number of facts of this form will be produced.
It is in general impossible to automatically distinguish between terminating and
non-terminating recursive theories with head constraints. Indeed, an algorithmic
solution to this problem would imply a solution of the halting problem, a classical
benchmark of undecidability.
We will go down a different path: we will transform the defining clauses of any
recursive predicate that makes use of head constraints by superimposing on them
a very simple instance of this same problem, but one that is known to always
terminate. This will ensure termination if the original theory … was subject to
divergence, but impose only a negligible penalty otherwise. This transformation will
affect only recursive predicates containing a head constraint in one of their defining
clauses. It will however not touch non-recursive definitions, and recursive predicates
which do not rely on head constraints—therefore all safe theories of Sect. 6.2.1
remain unaffected. This transformation will be transparent to the user, who will
simply specify … and not the transformed theory. The user will however be able
to influence its run-time behavior by changing a single parameter (the value hcmax ,
defined below).
Before describing the transformation in its generality, we consider a simple
instance. Let p be a predicate defined by simple recursion. Assume that p contains
two clauses: the base clause Clb D p.X E / Bb and the recursive clause Clr D
p.X E / p.YE / ^ Br . Furthermore, assume that Clr mentions one or more head
constraints within Br and that it is linear in p (i.e., no instance of p occurs in Br ).
6.3 Bounded Termination 219
Then, we transform p into the predicate p and replace p with the clausal theory
p defined as follows:
Clb W E ; C / Bb ^ C D 0
p .X
Clr W E ; C / Br ^ p .YE ; C 0 / ^ C D C 0 C 1 ^ C hcmax
p .X
where the effects of the transformation have been highlighted using boxes. The
predicate p differs from p in that it takes one additional argument: the counter C .
The transformed base clause Clb in the top row is identical to Clb except that it sets
C to zero. The recursive clause Clr increments C by 1, but also tests it against
the user-defined global bound hcmax . Therefore, the application of this rule will
fail as soon as C exceeds this value. It is clear that the calculation of the logical
consequences of p will terminate since the recursion cannot unfold more than
hcmax times along any execution path.
We can extend this technique to handle arbitrary forms of recursion, including
non-linear and mutually recursive definitions. Let … be a recursive theory and p
be a recursive predicate containing one or more head constraints Xi D æi in one of
its defining recursive clauses. Recall that p is the set of clauses of p. Let rec.p/
be the set of predicates defined by mutual recursion with p, and rec.p/ be the set of
all mutually recursive clauses involving predicates in rec.p/. Then the transformed
theory … is defined as follows:
E / B, we set:
• For each base clause Cl 2 p n rec.p/ with Cl D p.X
E ; C / B ^ C D0
Cl D p .X
Base clauses are massaged as in the above instance by having them set the counter
C to 0.
• For each recursive clause Cl 2 rec.p/ \ p without head constraints, if Cl has
V
E/ Ek
the form p.X qk 2rec.p/ qk .Y / ^ B, we transform it into:
^
E C/
Cl D p .X; qk .YE k ; Ck / ^ B ^ C D max Ck
k
qk 2rec.p/
This is a situation that did not appear in our example above. The safe recursive
clauses of p simply propagate the value of the counter appearing in their body.
If this clause is non-linear, its body will contain more than one instance of p or
of a predicate mutually recursive with p. We then need to bring their counters to
a common denominator, which will be the one containing the maximum value.
Note that there is no point in inserting a test against hcmax .
• For each recursive clause Cl 2 rec.p/ \ p featuring head constraints Xi D æi ,
V V
if Cl D p.X E / i Xi D æi ^ q 2rec.p/ qk .YE k / ^ B, we have:
k
^ ^
E ;C/
Cl D p .X Xi D æ i ^ qk .YE k ; Ck / ^ B
i qk 2rec.p/
^ C D .maxk Ck / C 1 ^ C hcmax
220 6 The Deductive Spreadsheet
This situation extends the recursive case in our example with non-linearity
(achieved by taking the maximum of all body counters) and mutual recursion.
The head counter is incremented by 1 to support progress. It is also tested against
the constant hcmax to ensure termination.
• For each such predicate p, add the clause
E / p .X
Clp D p.X E; /
nNeededCourse.C; D; N / CourseForDegree.C; D/ ^ N D 1
nNeededCourse.C; D; N / nNeededCourse.C 0 ; D; N 0 / ^ Prereq.C 0 ; C /
^ N D N0 C 1
nCourses.S; D; N / Student. ; ; S / ^ nNeededCourse.C; D; N /
^ :Took.S; C /
6.3 Bounded Termination 221
These clauses differ from the ones in Fig. 6.3 only by the addition of a counter
and the elementary arithmetic to update it. Notice however that the clauses for
nNeededCourse rely on head constraints. During evaluation, it is automatically
transformed as seen earlier to a necessarily terminating theory. Clearly, unless
course requirements are circular (which could happen because of an input error), the
evaluation of this specific theory would terminate. However, a structurally identical
problem in the airline example may not.
The predicate nCourses describes the number N of courses a student S still has
to take to qualify for a degree D, along a single requirement chain. We want to
find the maximum such N over all the chains. In order to do this, we can apply
the techniques described in Sect. 6.1.2 to transform a universal question into an
existential one and two negations (one of them is implicit in the constraint N 0 > N ):
MoreCoursesThan.S; D; N / nCourses.S; D; N /
^ nCourses.S; D; N 0 / ^ N 0 > N
nSemesters.S; D; N / nCourses.S; D; N /
^ :MoreCoursesThan.S; D; N /
It should be noted that the technique we just developed is ineffective for the
problem solved in Sect. 6.1.3: counting the total number of courses that a student
still has to take, not just those on a single requirement path.
6.3.2 Lists
We adopt the usual conventions of abbreviating a list Œv1 jŒv2 jŒ: : : vn jŒ : : : as simply
Œv1 ; v2 ; : : : ; vn . Differently from Prolog, we only admit lists of values, although
more general forms, for example lists of lists, will be explored in Sect. 6.5. Unless
otherwise specified, any use of the word ‘list’ in this book will refer to lists of values
as just defined.
Lists provide natural solutions to new classes of useful problems. For example,
in Sect. 6.1.1, we presented a theory CourseDep that calculated the pairs of courses
.C; C 0 / such that course C 0 was a transitive prerequisite of C . We can now use a
list to collect all the intervening courses that allow CourseDep.C; C 0 / to hold:
222 6 The Deductive Spreadsheet
The first clause assigns the two-element list ŒC; C 0 to the argument of
CourseDepList if Prereq.C; C 0 / is true. The second extends a course dependency
list ŒC 0 jL00 to ŒC; C 0 jL00 whenever this same fact is derivable. Therefore, if
CourseDep.C; C 0 / is provable, so is CourseDepList.L/, where C and C 0 are the
first and the last element of the list L, and the intermediate items are the intervening
course requirements. Displaying the transitive prerequisites between two courses is
infeasible unless our language is augmented with lists or a similar construction.
Introducing lists considerably extends the expressive power of the language we
have considered so far, but it also raises a number of questions. We will now examine
these issues and outline solutions for them.
4
In the above examples, the syntax Œ j is also used as a destructor in the conjunct L0 D ŒY jL00 :
it does not construct L0 by combining Y and L00 , but instead checks that the first element of L0 is
Y . While such traditional usage of the list constructor has a simple formalization based on pattern-
matching, an approach more in line with our language would introduce an operation, head, which
returns the first element of its argument and express this constraint as Y D head.L0 /.
6.3 Bounded Termination 223
path000 .Œa; a/ path000 .Œa; a; a/ path000 .Œa; a; a; a/ path000 .Œa; : : : ; a/
„ ƒ‚ …
hcmax times
Indeed, the bounding transformation does not stop the recursion from visiting a loop
in the object graph over and over. While this may be the intended behavior, it often
is not: certainly not in our airline example. We will see shortly a simple way to avoid
unintended loops.
An Algebra of Lists
Up to this point, we did our best to avoid the question of what the syntax of
lists should be. A minimal syntax consisting of just Œ for the empty list and the
constructor Œ j , as traditionally found in logic programming [CM87, O’K90, SS94]
and used so far, is inadequate in a spreadsheet environment. We have already
observed in footnote 4 that it forces us to rely on pattern-matching to take a list apart:
this clashes with the typical mechanisms available in a spreadsheet. However, we
also noted that this issue can easily be solved by introducing the classical destructor
operators on lists, head.L/ to return the first element of a (non-empty) list L, and
tail.L/ to strip it off and return the rest of L.
A more serious problem is that the usual high-level operators on generic lists,
such as append or member, cannot be defined in our language because they would
violate the safety restrictions (a head variable must appear in a positive body
literal, and similarly for variables occurring in constraints—see Sect. 6.2.1). These
operators have instead simple recursive definitions not only in logic programming,
but also functional programming. Indeed, neither of the following standard logic
programming definitions is valid (variables violating a safety requirement are
highlighted in bold):
224 6 The Deductive Spreadsheet
append.L; Œ; L/
append.L1; ŒXjL2; ŒXjL3/ append.L1; L2; L3/
member.X; ŒXjL/
member.X; ŒYjL/ member.X; L/ ^ X ¤ Y
(we have folded the head constraints into the head of clauses, as typically done in
Prolog). Although it is possible to emulate specific instances of these operations in
our language, this would result in tedious and inefficient theories. We will take a
different approach.
It is theoretically possible to define natural numbers starting from just the number
0 (zero) and the successor function (succ). This is however highly impractical for
daily arithmetic, not to speak of an application such as the spreadsheet. Instead, we
avail ourselves of a number of operators (e.g., C, , etc.) and comparison operators
(e.g., D, >, etc.) which we interpret as primitive, even if they could be derived from
just 0 and succ. They define an abstract algebra that allows us to write complex
expressions such as 3 C 5 > 2 3 in a natural way.
We will follow this same approach in the case of lists, and build an algebra
collecting the most common functions opList and relations List on these objects.
We first need a proper syntax for lists themselves. A list is an ordered collection
of values of finite but unbounded length. In this, it is not too different from a one-
dimensional array (i.e., vector) in a spreadsheet, as defined in Chap. 4. Indeed, the
distinction is only given by the fact that we intend to use lists as arguments of
predicates. Therefore, it is appealing to define a list as an arbitrary one-dimensional
array, Ee , which we will enclose in brackets as ŒEe when supplied to a predicate. Note
that the comma (“,”) is syntax to construct a vector out of scalars or formulas, which
entitles us to write an extensional list as Œv1 ; : : : ; vn . Going one step further, we can
see these brackets as an operator that promotes an array expression into a list: this
is the first operation in our algebra of lists.
Lists can then be formalized by the first two lines in the following grammar
within our spreadsheet model from Chap. 4:
The first line defines a list S as either the empty list Œ, or the result of applying a
list operator opList to appropriate arguments, which could themselves be lists (as in
append, which takes two lists and returns their concatenation) but may also include
scalars (as in substitute, which takes a list and a two scalar values and returns the
list obtained by replacing the first value with the second) or even arrays (indeed,
ŒEe is such an operator). The second line shows a few common list operators: we
clearly need Œ to get off the ground. We already introduced tail to return a list
deprived of its first element as well as append. We show two other operations as
examples.
6.3 Bounded Termination 225
It should be noticed that we left list operators opList and relations List open-ended
as it may be convenient to extend them with additional entries as we gain more
experience with these objects. Note also that some of the above operators, such
as head and tail, are defined only partially as applying them to the empty list is
pointless. We rely on the standard error mechanism of the spreadsheet to handle
these cases.
We conclude this part of our discussion with two examples that make use of this
newly introduced syntax. For convenience, we will abbreviate append as the infix
symbol “j”, and write 2 and 62 instead of member and notMember, respectively.
We begin with yet another version of the path predicate, which we call
path.4/ .L/:
It differs in two ways from path000 : first it uses the syntax just introduced. Second
it embeds the check X 62 L0 which prevents the recursion from visiting a
cyclic edge more than once. Therefore, when executed against the factual theory
…edge D fedge.a; a/g, it returns just path.4/ .Œa; a/. This is particularly useful in
an adaptation of our airline example from Sect. 6.3.1, where it makes little sense to
change planes more than once in the same airport as part of an itinerary between
two cities.
As a final example, consider the problem outlined in Sect. 6.1 of calculating
the dependencies among courses, but with the twist that some courses can have
alternative requirements. We saw in Sect. 6.1.4 that this was unsolvable within the
simple language we had at that point. Lists and the termination assurance obtained
in this section permit a simple solution. First, we introduce the primitive predicate
AltPrereq.C; Cs/ which associates each course C with the list Cs of courses it
alternatively depends on. Therefore, a student needs to have taken at least one
among the courses listed in Cs before attempting C . We then update the transitive
226 6 The Deductive Spreadsheet
The first line says that CourseDep0 .C; Œ/ holds if C has no requirements. The
recursive clause for this predicate extends a requirement chain Cs0 for C 0 with any
course C having C 0 as a prerequisite. This yields a requirement chain for C . Notice
how C 0 is tested to belong to Cs00 , and Cs is constructed from C 0 and Cs0 . At this
point, a student S is missing a requirement among the chain Cs for a course C if C
depends on Cs and S did not take one of the courses among Cs. This is captured by
the clause for MissingReq0 . Finally, S can take course C if there is a dependency
chain for C for which S does not miss any requirement.
still to be overcome or that there are doubts about the expected popularity of
this solution among users. This last aspect can be attributed to several factors.
First, cells embedding complex objects constitute a substantial departure from
the traditional layout of a spreadsheet and consequently users may have a hard
time discovering this technology or even adapting to it. Second, the development
of an interface supporting it is likely to be in its infancy and therefore still
subject to intensive cognitive assessments. Third and probably most important,
one of the inherent problems of these proposals is that a user cannot see the full
contents of a cell unless he or she does something to bring it to the foreground.
This works against novice users who are unlikely to know the visualization
commands.
Allowing cells to host lists of values is admittedly a more circumscribed problem.
It can indeed be reduced to the problem of visualizing and manipulating a
tri-dimensional spreadsheet, with lists arranged along the added axis. While
tantalizing, this perspective does little to solve the issues listed above. In
particular, a user still cannot see an embedded list in its entirety unless she issues
an appropriate command.
While we do think that these approaches have potential, the described issues
suggest that this technology has not yet reached maturity. We shall keep it in
mind as a second choice.
Multi-column Predicate Arguments: An alternative approach to visually sup-
porting lists is to relax the one-to-one association between predicate arguments
and spreadsheet columns (or rows, depending on the chosen orientation). Recall
that an attribute in Chap. 4 and later a predicate argument in Chap. 5 were defined
as a one-dimensional cell range such as EA3WEA17, possibly unbounded as in
EA3WEA . The approach we are examining allows allocating a multi-column
range such as EB3WEK17 or EB3WEK to a predicate argument.
This is exemplified in Fig. 6.10 where we have entered the clauses for alternative
requirement chains presented earlier in this section. Columns EA through EK
contain the clauses for predicate CourseDep0 , which took two arguments: a single
course C and a list Cs of courses it transitively depended on. When this predicate
is calculated, the computed instances of the first argument C appear in column
EA, starting on row 3, as usual. We have instead allocated columns EB to EK for
Cs, guessing that a requirement list will contain no more than ten courses. The
course list resulting from a successful calculation of the second argument will
be installed across a row EBiWEKi in this range, starting from the leftmost cell.
If this list has less than ten elements, the unused cells will be set to the blank
value. The lower part of Fig. 6.10 shows the two other predicates participating in
this example fragment. MissingReq0 is handled similarly to CourseDep0 : its first
two arguments are scalars while the third has been assigned to a range spanning
another ten columns. Finally, the purely scalar predicate CanTake0 is displayed
as usual.
This solution raises a number of questions, which we will now attempt to
answer:
228 6 The Deductive Spreadsheet
6
CourseDep (C; Cs) CourseDep (C ; C s )
7
∧ AltPrereq(C; Cs ) ∧ C ∈ Cs ∧ Cs = [C ]|Cs
8
• How large can a list be as an argument? While there are no theoretical bounds
to how many elements a list can contain, it is limited in practice by how many
cells can be allocated to hold a fact. If predicates and therefore their arguments
are aligned along the columns of a spreadsheet, this bound is given by the
maximum number of columns of the specific implementation. The typical
value in commercial products is 256. Note however that aligning predicates
along the rows substantially extends this number (commercial spreadsheets
typically have 65,536 rows), but at the cost of reducing the maximum number
of facts that can be calculated for this relation (to 256 in this scenario).
• What if a list is too long? Consistently with the treatment of arrays and
relations in Chap. 4, lists that are too long for the allocated space will be
truncated. In this case, we call the excess items the overflow of the list.
An alternative design, which however requires experimental assessment,
would allow scrolling a list whenever it is longer than its allocated range. A
similar approach may be applicable in the case of calculated relations with
more tuples than their assigned range can hold. Note that overflow items
(or tuples) would be available for inspection, but not accessible for cross-
paradigm manipulation: assume in Fig. 6.10 that the list calculated for the
first fact of CourseDep0 has 12 elements, two more than the number of cells
in EB3WEK3. Then, any cell containing the scalar formula COUNT.EB3WEK3/
will evaluate to 10 rather than 12.
• Do lists necessarily have to be the last argument? A list can appear anywhere
among the arguments of a predicate.
• How does a user specify the length of a list argument? While a best practice
still has to emerge from experimentation, we shall adhere to the principle that
a user should not be penalized by features she does not use. Therefore, a user
6.3 Bounded Termination 229
shall never need to specify that the length of a scalar argument is 1: by default
all arguments are scalar and have therefore length 1. Whenever the user has
assigned to a predicate more cells than there are arguments, a natural default
interprets the last argument as a list and allocates the excess range to it. If
this is not what the user has in mind, she can manually rectify the range
allocation.
• Can a predicate have more than one list among its arguments? Certainly. As
per the previous question, the user must then explicitly specify the range of
the first of these arguments, and possibly the second as well.
• Can the arguments of a predicate be split among sheets? While the arguments
of a predicate are generally contiguous, it is conceivable that they are
distributed throughout different areas of a single sheet or over multiple sheets
or spreadsheets. The cognitive repercussions of this possibility have however
to be assessed and carefully evaluated.
At the moment, allowing predicate arguments to span multiple columns (or rows)
to accommodate lists appears to be the most promising solution.
While these two proposals are the strongest candidates for allowing lists in
predicate arguments, other possibilities exist. For example, it may be possible
to design external array operators that implicitly access a derivation tree and
deconstruct it into a list. While theoretically viable, solutions of this type are likely
to put excessive demands on the abilities of a typical user.
Because of the inherently cognitive nature of the question of supporting list
arguments in a predicate, a definite answer to which of these solutions shall
eventually be embedded in a product, if any, will be based on experimental evidence.
We will come back to this problem in Part II.
Consider again the definition of the predicate trip from Sect. 6.3.1:
trip.F; T; D/ hop.F; T; D/
trip.F; T; D/ hop.F; M; D 0 / ^ trip.M; T; D 00 / ^ D D D 0 C D 00
We saw that, under the common assumption that if an airline has a flight from F
to T (predicate hop) it will also have a flight back from T to F , the evaluation of
these clauses will diverge as larger and larger values will be computed for the total
distance D. This is due to the fact that the naı̈ve (and semi-naı̈ve) strategy will stop
only when no new record is computed at some iteration, but here there will always
be new records as D grows. In the case of trip, we would like the computation to
end when the first such D has been computed. We could do this if the termination
condition ignored the third argument of trip.
230 6 The Deductive Spreadsheet
A term whose actual value does not matter (as long as there is one) for the
purpose of computation is called irrelevant, a concept that has recently received
some attention in the fields of proof and type theory [LP09]. It is then tempting to
mark predicate arguments corresponding to the left-hand side of a head constraint
as irrelevant: when evaluating this predicate, the remaining arguments will be used
to decide termination, so that only the first value of irrelevant arguments is reported
to the user. Observe that this approach would work for all the examples examined
in this section: not only when the head constraint computes a number, as in trip, but
also when it builds a list as in CourseDepList and the various definitions of path.
Although intuitively appealing, additional research is required before considering
this approach as part of the deductive spreadsheet. Here are some questions that this
research would need to answer:
• How to identify irrelevant arguments? In the above example, the irrelevant value
of D was computed on the basis of the third, irrelevant, argument of trip and
of the third argument of hop, which may or may not be irrelevant. In general,
an irrelevant argument in a predicate can depend on either relevant or irrelevant
arguments in other predicates. However, a relevant argument shall clearly depend
only on relevant arguments. Now, determining which arguments are irrelevant
requires exploring the dataflow graph of the theory at hand, starting with the
head constraints present in the recursive clauses. Clearly, a definition should be
rejected if it marks all arguments of a predicate as irrelevant.
• Which irrelevant value to return? In the case of trip, the distance D of interest
is clearly the first value computed by the evaluation (nobody likes doing loops
through the same airport), and the same for CourseDepList. But is this always the
case? What about path? At this stage, we do not know: more evidence needs to be
gathered by encoding additional problems. Furthermore, there may not always be
a single “first” value that can be computed: for example, two base clauses could
seed D with different values, which would then propagate. What should happen
then? This could result in a lot of frustration unless the user can easily predict
the behavior of the system. This suggests checking that predicates are functional
with respect to their relevant argument (for each value of the relevant argument,
the irrelevant arguments can assume at most one value).
In this section, we will abandon the registrar’s example that has accompanied us
for the past three chapters. We will however further demonstrate the usefulness of
our deductive extension of the spreadsheet by examining a number of examples in
different fields. We begin in Sect. 6.4.2 by revisiting the transitive closure theory by
describing a few more common problems that fit this pattern. Section 6.4.3 solves
the classical bill of materials problem, while Sect. 6.4.4 implements a workflow
solver. Section 6.4.5 constructs a simple meeting planner. We conclude in Sect. 6.4.6
6.4 Additional Examples 231
with another classic, the anti-trust control problem. Before embarking in this
endeavor, it is convenient to introduce abbreviations for the most common reasoning
forms encountered so far. This is the subject of Sect. 6.4.1.
Up to now, we have mostly expressed our examples using the base syntax defined in
Sect. 6.2.1 and extended with lists in Sect. 6.3.2. While correct, this occasionally led
to rather clumsy representations of very common problems, such as the extensional
universal quantification of Sect. 6.1.2. This can easily be remedied by making
abbreviated forms available for the most common functionalities. Each such form is
internally expanded to our base syntax without user intervention. This has several
advantages.
• First and most obvious, this saves typing, at the cost of a larger number of
constructions to remember and choose from.
• Second and most important, it reduces the cognitive burden on users by making
pre-programmed macros available for common functionalities. This is particu-
larly useful for a user who is not well versed in logic since some of the base
constructions (for example extensional quantification) are rather intricate and
demand a good mastery of logical reasoning.
• Third, besides ensuring correctness, the target clauses to which these abbrevi-
ations translate can be chosen as to be maximally efficient. We have seen that
there are often many competing clause sets that realize the same predicate, and
that their efficiency varies.
Observe that such abbreviated forms are common in the traditional spreadsheet. For
example, all commercial products make a function AVG.El / available to compute
the average of the values in range El, although it could easily be expressed as
SUM.El/=COUNT.El/ using two other standard functions.
We will now propose abbreviations for a number of recurrent functionalities.
We have already encountered some of these, for example transitive closure and
extensional universal quantification. We will encounter several more in the rest of
this section. Figure 6.11 summarizes some common templates by highlighting the
abbreviated body form on the left-hand side of each row. The body construction
it maps to is displayed below the arrow, with supporting clauses on the right-hand
side. For succinctness, we display only one of the possible translations in our base
language: in general each construction will have a number of possible targets,
chosen on the basis of environmental considerations as to maximize efficiency.
We also limit our presentation to a small sample of recurrent abbreviations and
discuss variants only informally. The actual abbreviations to be made available in
an implementation of the deductive spreadsheet shall be established and refined
empirically.
232 6 The Deductive Spreadsheet
The top part of the figure shows a number of variations on the transitive closure
theme. The first line makes the transitive closure of a binary relation p.X; Y /
available as p C .X; Y /. With this shortcut in place, the definition for CourseDep
in Sect. 6.1.1 (see also Fig. 6.1) can more succinctly be rewritten as
or even more succinctly, PrereqC can be used wherever CourseDep appears. We can
similarly write edgeC for path.
The more general form TRANSITIVE X; Y: p.X; Y; Z/ E defines the transitive
closure of predicates that have more than two arguments, or with arguments in a
non-standard order. The abbreviation p C is clearly a special case.
Next, the form Xs D p ŒC .X; Y / accumulates the intermediate elements of the
transitive closure of p from X to Y in the list Xs, which is returned as if it were
computed using a constraint. With this abbreviation, the definition of path.4/ in
Sect. 6.3.2 can be replaced with
or omitted altogether. Although not shown in Fig. 6.11, this technique can easily
be extended to predicates with more than two arguments, for example by writing
Xs DTRANSLIST X; Y: p.X; Y; Z/. E The next two rows show variants that also
return the length of the computed list, and the sum of a third argument, throughout
the recursion. We can then give the following simplified forms for the predicates
path0 and path00 of Sect. 6.2.1, and trip and trip0 from Sect. 6.3.1:
Notice that we have liberally omitted any mention of the resulting list (written
Xs D : : : above) when unnecessary, and that we have interspersed explicit bounding
conditions as needed.
The basic form of extensional universal quantification examined in Sect. 6.1.2 is
transparently abbreviated into the body expression FORALL X W p.X; YE /: q.X; YE /:
it ascertains that for all values of X such that p.X; YE / holds, so does q.X; YE / for
given values of YE . The translation in our core language is presented in Fig. 6.11.
Notice that in order for the target theory of the transformation to be safe, the
variables YE must occur in a positive literal in the body of the clause where FORALL
appears. This abbreviation yields the following simplified form for the predicate
CanTake of Sect. 6.1.2:
This construction can be further enriched with bounds and filters, for example in
the form N 0 D FINDMAX N W q.N; YE /: p.N; YE /, which only considers values of
N such that q.N; YE / holds. Other abbreviated forms operating on numbers, such
as FINDMIN or FINDAVG, can be defined similarly. Using the same template,
the abbreviation Xs D FINDALL X: p.X; YE / collects all the values of X for
which p.X; YE / holds into the list Xs. The variables YE are again subject to safety
constraints.
Given a binary predicate p.Y; Ys/ describing a list Ys of values related to Y , the
form Xs D ACCUMULATE Y: p.Y; Ys/ generalizes the notion of transitive closure
by recursively collecting every object related to Y via p into the list Xs. We will use
and further explain this notation and some variants in the next section.
We anticipate that more abbreviated forms will emerge as more examples are
developed. While these pre-packaged reasoning units do not extend the expres-
siveness of the deductive spreadsheet in any way, they simplify the interaction for
users with limited familiarity with formal logic, in the same way as commonly
used formula patterns are made available as macros and redundant operators in the
traditional spreadsheet. We expect the net effect to be to make applications easier to
write and therefore augment productivity.
path.X; Z/ edge.X; Z/
path.X; Z/ edge.X; Y / ^ path.Y; Z/
p p+
Course prerequisite Transitive course requirements
Parent-child relation Ancestor relation
Airports with direct flights Multi-hop air itineraries
Immediate supervisor relation Indirect boss-employee relation
Military command relation Military chain-of-command
Immediate geographic enclosure Geographic containment
Department-subdepartment relation Business organization chart
Immediate oversight relation Jurisdiction relation
and reporting these nodes in a list. These techniques are clearly available for any
of the interpretation of edge and edgeC . Other useful variations of the transitive
closure clauses can be constructed, although they tend to be more specific to the
interpretation domain at hand.
Genealogies are a perfect example of transitive closures. When building one’s
family tree (a graph, really), the base relation is the parent-child relation. Its
transitive closure is then the ancestor relation. To spice up the discussion, consider
the following variant: the Mathematical Genealogy Project5 collects information
about mathematicians and computer scientists such as where they did their dis-
sertation, when they defended it, and who was their advisor. After importing this
data as a couple of relations such as “advisor” and “thesis”, it is easy to use the
deductive spreadsheet to explore one’s academic ancestry (one’s advisor, advisor’s
advisor, etc.) to find one’s oldest academic ancestor, to pinpoint to famous academic
ancestors or cousins (e.g., Gottfried Leibniz or Alan Turing), or to find oddities in
the genealogical data (e.g., a gap of 80 years or more between a person’s dissertation
and his advisor’s). Each of these questions can be answered using clauses similar
to those for path above. The graphical user interface can even support tools to
draw the resulting genealogy tree—see the discussion on connection graphs in
Chap. 9.
Finding routes between a starting location and a destination is another instance of
the transitive closure problem, a problem that Sect. 6.3.1 examined in the case of air
travel—this is an admittedly moot example since nowadays many websites offer far
better tools than what one can build at home using a deductive spreadsheet. Here is
a situation that a travel site will not be of much help with: say one’s hobby has to do
with collecting historical transportation schedules. Loading them into the deductive
spreadsheet allows answering questions such as “Was it possible to go from Lisbon
to Istanbul by train in 1905?” or “Could Phileas Fogg have actually gone around
the world in 80 days by public transportation in 1872, as claimed by Jules Verne?”.
5
See http://genealogy.math.ndsu.nodak.edu/
236 6 The Deductive Spreadsheet
In this section we will examine a simple instance of the bill of materials problem,
a classical benchmark for deductive databases [CGT90, Col98]. Assume that a
company manufactures a number of products (e.g., a car), each consisting of parts
(e.g., the engine), which in turn may be built out of subparts (e.g., the pistons),
themselves constructed out of smaller parts (e.g., the piston’s head), and so on up to
elementary subparts that cannot be further decomposed (e.g., bolts). In this context,
the simplest instance of the bill of materials problem requires producing the list of
all the elementary parts that are present in a product. Other interesting questions
include finding all the products that contain a given subpart, and computing the
cost of a product knowing the cost of the elementary subparts and the overhead of
assembling components into larger components.
We model the relationship between a component P and its immediate subparts by
means of the predicate Parts.P; Ps; C / where Ps is a list of the parts of P . This list
is empty if P is elementary. In this case, C is the cost of P . If P can be decomposed
into subparts, C is the cost of assembling it.
The following mutually recursive clauses solve the basic bill of materials
problem:
The predicate Subparts.P; Ss/ in the first clause collects the elementary subparts
of a component P into the list Ss. It does so by looking up the immediate
subparts Ps of P and invoking the auxiliary predicate Subparts0 which calculates
the elementary subparts of the list of components in its first argument. It is defined
by the last two clauses. The base case handles the empty list. The last clause for
Subparts0 .Ps; Ss/ is more interesting: a non-empty Ps will have the form ŒP jPs0
and therefore the problem can be reduced to finding the elementary subparts of P
(by invoking Subparts) and the base components of Ps0 (by relying on a recursive
call to Subparts0 ). The conjuncts on the last line ensure that P and Ps0 are indeed
related by being subparts of a common component (the function splitTail.L; P /
splits list L at some occurrence of P and returns what follows it). Although
logically unnecessary, the presence of these conjuncts results in a more efficient
6.4 Additional Examples 237
Were we interested in a list of all the subparts of a product P , not just its
elementary subparts, it would be sufficient to replace the first clause in the original
definition of Subparts with the following:
A form ACCUMULATE could be introduced to express this variant. Note that our
model implicitly takes into account the fact that a component may contain several
occurrences of the same subpart. The above theory can however easily be turned
into a more succinct and efficient model that explicitly accounts for the multiplicity
of subparts.
Given either of the above specifications, the problem of finding which products
contain a given component is solved by the following clause:
Using again the abbreviations in the spirit of Sect. 6.4.1, we can simplify this
definition into:
Cost.P; C / C D SUM C 0 : ACCUMULATE P: Parts.P; Ps; C 0 /
Start.a/ and End.b/ mark the fact that a and b are the start and end points of the
process. Furthermore, let Follows.a; L/ indicate that task a cannot take place before
each of the tasks in the list L have been completed. Finally we associate every task
a with the time t it takes to complete it by means of the predicate Time.a; t/.
The problem is solved by the mutually recursive predicates TimeTo.A; T /, which
calculates the minimum time T required to achieve task A without violating any
timing bound, and MaxTime.As; T /, which performs a similar task with respect to
all the tasks in the list As. Predicate Earliest reports the timing constraints of the
process as a whole.
TimeTo.A; T / Start.A/ ^ T D 0
TimeTo.A; T / Follows.A; As/ ^ Time.A; T 0 / ^ MaxTime.As; T 00 /
^ T D T 0 C T 00
MaxTime.As; T / As D Œ ^ T D 0
MaxTime.As; T / Time.A; T 0 / ^ MaxTime.As0 ; T 00 / ^ As D ŒAjAs0
^ T D max.T 0 ; T 00 / ^ Follows. ; L/ ^ A 2 L
^ As0 D splitTail.L; A/
Earliest.A; T / TimeTo.A; T / ^ End.A/
Note the second defining clause of MaxTime, where we rely again on the list
function splitTail to boost the speed of calculation. We already relied on this
technical device in the bill of materials problem. An abbreviated form for aspects
of this definition could be introduced, were it to be commonly found in practical
examples.
The case study we used throughout this book, a college student assembling
a course sequence on the basis of information about course availability, prereq-
uisites, etc., features several aspects that fit the pattern of a workflow problem.
Consider the following questions this student may want answered: “Can I enroll
in ‘Advanced Networking’ next semester?”, “What courses do I need to complete
before I can enroll in ‘Operating Systems’?”, “When is the earliest date I can take
‘Computer Architecture’?”, “What additional courses do I need to take to satisfy
the requirements of my major?”, “What is the least number of courses I can take to
major in CS and get a Math minor?”. Answering these questions involves solving a
workflow problem: there are a number of tasks (here courses) subject to constraints
(availability, dependencies) that have to be performed to complete a project (degree).
Here, a critical feature of the deductive spreadsheet is its support for negation.
Negation not only allows specifying that the absence of certain records matters
in calculated relations (e.g., completed classes should not be returned when the
student looks for the course he still has to take), but it is also key to expressing
concurrent enabling conditions through extensional universal quantification (e.g.,
all prerequisites of a course must have been completed before a student can enroll in
it). A large number of questions can be framed as workflow problems, especially any
time planning is involved, such as in supply-chain management. Dedicated software
packages are available, but many users, even in large companies, do not know about
6.4 Additional Examples 239
them or do not have time to learn how to use them. The deductive spreadsheet
provides a simple way to develop workflow solvers customized to one’s needs in
many situations that are not very large or complex.
Next, we implement a simple meeting planner, which will sieve through the
schedule of the potential attendees of a meeting and display the dates where at least
N participants are available. We rely on the primitive predicate Available.P; D/ to
describe each date D in which person P is available to meet. The cell symbolically
indicated as minMeetingSize (via a one-cell range name) contains the threshold
value N for the meeting to take place.
This very simple planner is specified by the clauses below. The bulk of the work
is done by the predicate AvailableOnDate0 .D; Ps/ which collects in the list Ps all the
potential participants that have expressed their availability for date D. The auxiliary
predicate Missing.D; Ps/ checks whether any of these people is missing from the
list Ps. Both are used in the predicate AvailableOnDate.D; Ps; L/, which returns
the maximal list Ps of people available on D. The last argument, L, is simply the
length of Ps. Finally PossibleMeetingDates.D; Ps/ returns the dates and parties for
which at least N people can attend the meeting (where again the cell containing N
is mnemonically specified as minMeetingSize).
This example implements a very basic meeting planner. It can however easily be
extended to a more realistic model supporting finer grained meeting times, as well
as constraints on participation (e.g., Tom will not attend unless Bill is there as well,
and certainly not if Carl shows up).
240 6 The Deductive Spreadsheet
Next we give clauses that compute the total market quota of a company C . In order
to do so, we rely on the feeder predicate Company.C; M; Q/ that describes the
fact that company C directly owns a quota of market M equal to Q%. Then, the
mutually recursive predicates Market and TotalQuota realize this objective using
the same technique already encountered in Sects. 6.4.3 and 6.4.4.
Finally, if the primitive predicate Limit.M; H / sets the threshold for market M to
H %, the predicate InViolation.M; C; T / returns the companies C that violate the
regulations of market M , together with the total quota T they actually hold.
Once more, we conclude the section by re-expressing this example using the
abbreviated forms introduced in Sect. 6.4.1. Predicate AllControlled can be defined
using FINDALL, hence eliminating the need for the auxiliary Controlled and
Missed. The predicate Market and its dependents are similarly captured by the SUM
variant of ACCUMULATE, which can be in-lined in the clause for InViolation:
The use of abbreviated forms allows an easy expression of this complex problem.
These three clauses expand to eight definitions in our base syntax.
6.5 Extensions
noticeably simplify some of our examples. We look into complex objects, a staple
of logic programming, in Sect. 6.5.2. We conclude with a brief overview of typing
in Sect. 6.5.3.
We first examine one of the most successful recent extensions of logic programming:
embedded implications [Mil89, MNPS91, Bon91, Fre92, Bon94]. This proposal
simply allows the body of a clause to contain implication subgoals such as P ! P 0 .
This may appear as a vacuous exercise in the context of the deductive spreadsheet or
even of logic programming in general since this subformula is logically equivalent
to :P _ P 0 , which can easily be recast into our current formalism as seen in
Chap. 5. This is certainly the case in the traditional interpretation of logic, known
as classical logic. This equivalence does not hold, however, in the alternative
intuitionistic interpretation of logic [TvD88]. In intuitionistic logic, solving the
implication P ! P 0 requires providing a mechanical method to transform a proof
of P into a proof of P 0 , which in general is different from showing that either :P
or P 0 is provable. Under this interpretation, embedded implications are inherently
hypothetical: P ! P 0 is provable if P 0 can be proved under the assumption that P
holds. This is tantamount to temporarily extending the theory at hand with P while
proving P 0 . It is this last characterization that has fueled the interest in embedded
implication. Having a logical device to temporarily augment a running program
suddenly provides a declarative justification for advanced programming concepts
such as modules [Mil89] and references to external routines [Fre92].
In the context of the deductive spreadsheet, embedded implication provides a
natural support for hypothetical reasoning. Whenever a user wants to know what
would happen to a calculation or a deduction if a certain cell or group of cells were
to assume certain values, he has no choice but modifying these locations and later
remembering to restore them to their original state. With embedded implication, he
can simply write a few clauses or even just a one-time query that assumes (a fact
specifying) that those cells hold the hypothetical values. This is a clearly useful tool
for many forms of what-if analysis, such as allocating budget items, deciding on
mortgage terms, scheduling task priorities, etc.
From the above discussion, it is apparent that including embedded implication in
our language amounts to much more than simply providing a new linguistic feature:
it requires shifting the entire framework we have constructed from a classical
perspective over to intuitionistic logic. This task would be Herculean in a generic
fragment of first-order logic. It is nearly trivial in our case because the language we
have developed so far has the property that the classical and intuitionistic logical
consequences of any of its theories are the same (negation does not satisfy this
property in general, although it does under our stratified interpretation). Adding
embedded implication breaks this symmetry and therefore forces us to take the fork
of the road that heads toward intuitionism.
6.5 Extensions 243
Syntax
Bodies B WWD P j :P j æ æ j B ^ B j P !B
P1 ! .P2 ! B/ .P1 ^ P2 / ! B
This
V is know as currying. It allows us to focus on hypothetical subgoals of the form
i Pi ! B where B does not start with an implication.
Another logical equivalence allows us to consider just atomic conjuncts as the
target of an embedded implication:
P ! .B1 ^ B2 / .P ! B1 / ^ .P ! B2 /
6
This simple but rather stringent restriction could be loosened by performing a form of dataflow
analysis known as mode checking [DW88, Sar10]. In order for a clause to be acceptable, the mode
analysis shall certify that X can always be instantiated before attempting to solve the embedded
implication.
244 6 The Deductive Spreadsheet
Model Theory
I W P HBV ! P HBV
In this context, the subsets of the Herbrand base are known as worlds and denoted by
w. An interpretation is then a monotonic pre-interpretation, i.e., a pre-interpretation
I such that for any w; w0 HBV it is the case that if w w0 then I.w/ I.w0 /.
6.5 Extensions 245
This corresponds to requiring that adding assumptions to a theory does not put the
provability of any fact into jeopardy. While unsound in general in the presence
of negation, this will prove adequate for stratified theories. This is a particular
case of Kripke structure, a prevailing model semantics of intuitionistic first-order
logic [TvD88].
Second, it is convenient to express the validity judgment by describing how an
interpretation defines validity with respect to each individual world. Therefore, we
update the form of the validity judgment to I; ˛; w jˆ '. It states that interpretation
I validates the formula ' in world w with respect to assignment ˛. As in Chap. 5,
this judgment is inductively defined on the structure of '. A specification of this
definition, partially specialized to our language of interest, is as follows:
I; ˛; w jˆ true always
I; ˛; w jˆ false never
I; ˛; w jˆ P iff ˛.P / 2 I.w/
I; ˛; w jˆ :P iff it is not the case that I; ˛; w jˆ P
I; ˛; w jˆ '1 ^ '2 iff I; ˛; w jˆ '1 and I; ˛; w jˆ '2
I; ˛; w jˆ '1 _ '2 iff I; ˛; w jˆ '1 or I; ˛; w jˆ '2
I; ˛; w jˆ P ' iff I; ˛; .w [ fP g/ jˆ '
I; ˛; w jˆ 8X:' iff for all v 2 V it is the case that I; ˛X 7!v ; w jˆ '
I; ˛; w jˆ 9X:' iff there is v 2 V such that I; ˛X 7!v ; w jˆ '
The main difference with respect to the classical definition in Chap. 5 is in the rule
for implication. There, I; ˛ ˆ P ! ' was reduced to I; ˛ ˆ ' under the condition
that one could show that I; ˛ ˆ P holds. Here, it is required that I validates ' in the
current world w extended with the antecedent P , in symbols I; ˛; .w [ fP g/ jˆ '.
Note that a truly intuitionistic model would handle negation and universal
quantification differently from what is shown here. In particular, it would rely on
a standard Kripke structure [TvD88]. The characteristics of our language are such
that this more general treatment is equivalent to what we are considering here.
As in Chap. 5, an interpretation I (and variable assignment ˛) is a model of a
formula ' if for every world w it can be shown that I; ˛; w jˆ '. Formula ' is a
logical consequence of '1 ; : : : ; 'n if every model of each of the 'i , for i D 1::n, is
also a model of '.
The fixpoint semantics developed for our language can be adapted to handle
embedded implications in the intuitionistic setting. For simplicity, we begin our
discussion by examining just definite theories, characterized by the absence of
negation. Given a theory … D .…; /, the immediate consequence operator T…;
still transforms interpretations. For convenience, it is customary to define it with
respect to each individual world of an interpretation. At an abstract level, it has the
following form:
246 6 The Deductive Spreadsheet
T…; extends the interpretation I.w/ of every world w with all the facts in … and
the instances of the heads of all clauses in whose bodies are valid in I at w.
We can specialize this expression to the form of a definite clause, obtaining:
V V mi
T…; .I /.w/ D I.w/ [ … [ f˛.P / W P iD1::m . j D1 Pij ! Pi /
V 0
^ iD1::o æi i æi 2
S mi
and ˛.Pi / 2 I.w [ j D1 fPij g/ [ … for all i D 1::m
and ˛.æi /
O i ˛.æi / is true for all i D 1::o g
Notice
Vmi that the validity of the consequent Pi of every embeddedSmi implication
P
j D1 ij S! P i is assessed against the interpretation I.w [ j D1 fP ij g/ of the
mi
world w [ j D1 fPij g, and …. Constraints are handled as usual.
It is easy to show that this operator is monotonic and continuous over the
lattice of interpretations with ordering I v I 0 defined as I.w/ I 0 .w/ for
all w 2 P HBV [Mil89]. Then, by Kleene’s theorem, T…; has a least fixpoint
obtained by taking successive iterations from the bottom element of this lattice,
the interpretation I? such that I? .w/ D ; for all w HBV :
lfp.T…; / D T…;
!
.I? /
This yields the least model I…; of …; , which is a function from sets of facts to
sets of facts. The logical consequences of this theory are then given by applying the
least model to the empty set (or equivalently to any subset of …): I…; .;/.
Using variations on the techniques in Sect. 6.2.2, it can be proved that this
computation terminates after finitely many iterations. It is therefore an appropriate
foundation for a naı̈ve evaluation strategy, which can be refined to a more efficient
semi-naı̈ve form.
This approach is easily extended to handle non-hypothetical negative literals
in a stratified normal theory [Fre92, Bon94]. When evaluating a stratum … & D
.…& ; & / of a theory … , we simply make sure that negative literals do not occur
in …& :
V Vmi
T…& ; & .I /.w/ D I.w/[…& [f˛.P / W P i D1::m . j D1 Pij ! Pi /
V
^ i D1::n :Qi
V 0
^ i D1::o æi i æi 2 &
Smi
and ˛.Pi / 2 I.w [ j D1 fPij g/ [ …& for all i D 1::m
and ˛.Qi / 62 …& for all i D 1::n
and ˛.æi /
O i ˛.æi / is true for all i D 1::o g
Handling hypothetical
V negative body literals is somewhat more complicated because
the assumptions m j D1 Pj of a negated predicate :Q may modify the theory of the
6.5 Extensions 247
stratum where Q is defined, hence altering the set of logical consequences exported
to stratum &. Therefore, the expression for the T operator must have access to the
least models of all the lower-level strata so that it can take the various Pj into
account in order to assess the non-validity of Q [Fre92, Bon94].
.…; P /; ` B 7! ˛ .…; P /; 6` B
ie" ie#
…; ` P ! B 7! ˛ …; 6` P ! B
Rules pr" and np# shall undergo minor alterations to account for the possibility
of facts in … containing variables. These variables can be instantiated by the
application of the first of these two rules, and this instantiation shall be propagated
in other parts of the theory. The safety restrictions introduced at the beginning of
this section somewhat mitigate this behavior.
In Chap. 5, we advocated the use of top-down evaluation as an ideally suited
mechanism for explanation, and possibly for executing one-time queries. While the
first objective is still met, the second acquires a particularly interesting dimension as
it supports a new form of hypothetical reasoning. In a spreadsheet, what-if analysis
is traditionally performed by modifying key cells and observing how these changes
are propagated. A query containing an embedded implication allows solving a goal
under the additional assumptions specified in the implication’s antecedent, without
making any change in the spreadsheet itself. For example, a student may check how
taking different courses next semester will affect his graduation date. As another
example, a home-buyer may use hypothetical subgoals to predict mortgage payment
under a number of different interest rates. This form of hypothetical reasoning is
quick, non-intrusive and logically motivated.
248 6 The Deductive Spreadsheet
Examples
Note the use of embedded implication to add hop.F 0 ; T 0 ; D 0 / as a new fact on which
to base the computation of the second instance of ShortestRoute.
As mentioned in Sect. 6.2.5 the logical formalism we have defined in the early
part of this chapter was closely related to Datalog, which was clearly manifested
by the absence of uninterpreted function symbols in its term language. We have
walked one step closer to Prolog and other logical languages supporting complex
terms in Sect. 6.3.2 with the admission of lists of values as predicate arguments.
In this section, we will briefly analyze the implications of going all the way down
that path and allowing terms freely generated from a set of constants and function
symbols.
This extension would have the effect of allowing cells to contain complex objects.
For example, an employee of a company could be described by a structured term of
the form
employee.name.Henry; C; Smith/;
contacts.address.2498 College Drive; Albuquerque; NM; 65802/;
phone.515-203-8701/;
position.chief analyst; 2=6=2011;
position.analyst; 7=12=2007;
position.tester; 9=23=2003;
new hire/////
The structure of the first version is much easier to read and navigate. Notice that we
have rendered recursively embedded position subterms by means of a list.
From a purely computational point of view, complex objects do not add any
new expressiveness to the language of the deductive spreadsheet (with value
lists). Indeed, as in this example, a complex term can always be flattened into a
combination of scalar values and lists. The practical benefits are however evident.
Complex objects suffer from the same non-terminating behavior as lists of values
in Sect. 6.3.2, which can be remedied by relying once more on the bounding
transformation. Therefore, from a purely linguistic point of view, there is no reason
to exclude them from the deductive spreadsheet.
Unfortunately, complex objects do not seem to blend well into the spreadsheet
metaphor, although various authors have suggested ideas for embedding them within
cells [BADC 01, Kri88]. The problem is once more related to their visualization. In
the case of lists, we could summon a solution that retained the property that cells
contain scalar values only, but this does not seem easily achievable in the case of
freely generated terms. Furthermore, we suspect that complex terms are too far from
250 6 The Deductive Spreadsheet
the type of objects that spreadsheet users are accustomed to, and therefore their
inclusion runs the risk of confusion if not rejection. For these reasons, we shall not
incorporate complex objects (save for lists of values—see Sect. 6.3.2) within the
language of the deductive spreadsheet at this stage.
6.5.3 Typing
Since its inception in the 1960s, types have proved enormously popular in pro-
gramming languages and their application to software engineering. Strongly typed
programs contain fewer flaws than untyped ones, which has a positive effect on
development time and reliability. There have been a number of designs of typed
logic programming languages [Pfe92], including some in which sophisticated type
theories are themselves viewed as logic programming languages [Pfe89, PS99].
Our language could easily be extended to support type annotations, and even a
type system that ensures strong typing. It is conceivable that interface functions be
devised to assign types to data values, expressions and formulas. Typing carries,
however, a cognitive price. While a trained programmer is expected to understand
(and use) types, a typical spreadsheet user is likely to not fully comprehend them,
and even find the rigid safety rules they enforce in the way of getting work done.
The strict typing discipline of modern programming languages, a blessing for
professional programmers, would be a curse for the occasional spreadsheet user,
who may give up on these applications before having sufficiently mastered typing
to reap its benefits. Not surprisingly, no commercial spreadsheet application we are
aware of relies on a typed language. We will follow the same trend and refrain from
forcing the formulas of the deductive spreadsheet to be typed. In future work, we
plan to explore offering strict typing as an option for spreadsheet programmers,
disabled by default for end-users.
6.6 Summary
This chapter concludes the development of the formal language underlying the
deductive spreadsheet. Our main achievement has been the extension of the simple
logical formalism of Chap. 5, itself a linguistic variant of the relational language of
Chap. 4, with recursion. This change, which only affects the form of clauses and not
the functional infrastructure of the spreadsheet, has furthered the expressiveness of
the logical spreadsheet with truly deductive capabilities. Indeed, recursive clauses
were shown to provide a simple solution to new classes of problems, questions that
could not be modeled in the logical language of Chap. 4.
A few syntactic restrictions had to be installed to prevent divergence during the
evaluation of these generalized theories. In particular, recursive clauses had to be
forbidden from mentioning head constraints, which could cause non-termination.
6.6 Summary 251
Outline
Having completed the abstract design of the linguistic functionalities underlying the
deductive spreadsheet, we now turn to the problem of making them available to the
user in a simple and intuitive way. This is an essential aspect of our development
since the ultimate goal of our overall endeavor is not only to augment the expressive
power of the traditional spreadsheet, but also to retain its characteristic usability.
In this part of the specification, we will propose a conservative extension to the
user interface of a typical spreadsheet application with support for the deductive
infrastructure developed in Part I. While formal logic and the theory of program-
ming languages provide tested guidelines that allowed an objective assessment of
the abstract functionalities of the deductive spreadsheet, the value of user interface
design choices is highly subjective and not as well understood. We take our guiding
principles from recent developments in the area of cognitive psychology and follow
them as we design the visual extension of the spreadsheet. Because of the subjective
nature of this task, only empirical assessment on actual users will be able to validate
(or rebuke) our choices. Indeed, while we believe that the abstract functionalities of
the deductive spreadsheet are relatively stable, we expect our proposal for the user
interface to change substantially as we expand our test base and incorporate user
feedback.
Chapter 7 begins our discussion of the visual presentation of the deductive
spreadsheet with a careful review of the most important concepts of the user
interface of the traditional spreadsheet. It isolates the points where to anchor the
deductive extensions to the existing display layout and methods for performing
tasks, which are relatively uniform among commercially available spreadsheets.
In Chap. 8, we introduce the methodology we follow as we design the user
interface of the deductive spreadsheet. Because meeting the cognitive requirements
of the user is paramount, we combine two recent proposals from cognitive science:
the attention investment model takes an abstract view of the problem solving task
254 II User Interface
Google Spreadsheet
Apple Numbers
is currently the most commonly found spreadsheet application. The specific version
we rely on is Excel 2003, which is de facto the greatest common denominator
between the more recent versions of Excel and all other spreadsheet applications
7 The Traditional Interface 257
LibreOffice Calc
KDE KSpread
on the market (the most common are Google Spreadsheet, Apple’s Numbers, and
OpenOffice and LibreOffice Calc). We refer the reader to [Har03] for a thorough
yet user-friendly treatment of the concepts touched here, and many more.
We examine the general layout of a spreadsheet in Sect. 7.1, where basic format-
ting and the static organization of cells and worksheets is discussed. Section 7.2
258 7 The Traditional Interface
Gnome Gnumeric
VisiCalc
describes the available options for entering text and especially formulas in a
cell: we first review the textual language of formulas, and then focus on the
graphical facilities that modern spreadsheets provide to simplify their construction.
Section 7.3 discusses how a user can control updates as well as the tools available to
trace the behavior of a formula. Section 7.4 elaborates on some relevant productivity
facilities, e.g., charts, available in commercial products. Finally, the salient aspects
of the user interface of the traditional spreadsheet are summarized in Sect. 7.5.
Throughout this presentation, we will highlight points that our deductive extension
shall touch, but we will not provide specific solutions until Chap. 9.
260 7 The Traditional Interface
7.1 Layout
In this section, we begin to examine the static aspects of the user interface of
the traditional spreadsheet. The question we strive to answer is “How do things
look?”. We focus on the basic organization of the workspace in Sect. 7.1.1 as
well as visual formatting of these elements, within a cell in Sect. 7.1.2 and across
cells in Sect. 7.1.3. We delay the discussion of the textual appearance of formulas,
technically another form of information that the users sees when opening an existing
spreadsheet: they will be examined in Sect. 7.2.
We rely on the user interface of Microsoft Excel 2003 for illustration—see
also [Har03]. This choice is due to the fact that, although Microsoft has recently
changed the look of Excel, all competing products still rely on a user interface that is
nearly identical to that of Excel 2003 and its predecessors. The graphical user inter-
faces of seven commercial spreadsheets are displayed in Fig. 7.1: going left-to-right
and top-down, we have Google Spreadsheet, Apple Numbers, LibreOffice Calc,
KDE KSpread, Gnome Gnumeric, Microsoft Excel 2000, and Microsoft Excel 2010.
The bottom-right image shows the text-based user interface of VisiCalc [Bri09], the
precursor of all spreadsheets in 1979.
Figure 7.2 shows an annotated enlargement of the initial screen displayed by Excel
2003 when opening a blank spreadsheet—it is representative of many current
applications. The top part of the window contains the menu bar, from which the
user can access nearly all the commands available in the system by using the
mouse. Commands performing related functionalities are grouped under the same
menu, with submenus further collecting operations acting on the same or similar
components of the spreadsheet. Clicking on an item in a menu or submenu either
directly performs the command, or opens a dialog that offers further options.
Occasionally, a wizard guides the user through the phases of a complex task. Excel
2007 introduced an alternative presentation of menu commands as a ribbon located
just below the menu bar: when clicking on a menu in the menu bar, the ribbon
gives persistent graphical access to its commands rather than displaying them in
menu form and forcing the user to select a command right away. The contents of the
ribbon are also to some extent context-sensitive. Although sensible in principle, the
ribbon has received mixed reviews from users and no other commercial spreadsheet
application has adopted it.
In the default configuration, one or more toolbars appear just below the menu
bar. Toolbars contain a number of iconic buttons or selection lists that act as
shortcuts for frequently used commands. As such, there are no sub-toolbars. Related
commands are grouped in the same toolbar. Starting with Excel 2000, toolbars can
be configured to add or remove commands, although few users ever bother changing
7.1 Layout 261
Menu bar
Toolbar
Formula bar
Column locator
Active cell
Row locator
Worksheet navigation
the default settings. Toolbars can also be relocated to other positions besides the
near top of the window. They can indeed be aligned along its left, right, or bottom
margins, and positioned before or after other toolbars. They can also be turned
into floating objects that hover anywhere on the screen where the user may care to
put them. In some other commercial products (e.g., Gnumeric and Calc) and older
versions of Excel, toolbars cannot be moved.
One toolbar that holds a special status in nearly all applications is the formula
bar, which collects a number of essential functionalities related to the currently
selected cell. In particular, it identifies it, it reports on its contents, and it allows
entering text or formulas into it. Applications generally disallow relocating it. We
will examine the formula bar more closely in Sect. 7.2.
The very bottom of the window is usually reserved for displaying information
about the status of the application and about any special mode being activated. This
is the status bar.
The central and largest area of the window displays the data contained in an
individual spreadsheet file (or the user’s newly created work). The familiar grid
characteristic of these applications is called a worksheet. It is divided into horizontal
rows and vertical columns, and expands well beyond the physical frame of the
application window. Scrolling permits exposing invisible parts of the worksheet.
Excel and most commercial applications fix the size of a worksheet to 256 columns
and 65,536 rows. Users of a traditional spreadsheet rarely exhaust all the available
262 7 The Traditional Interface
rows, but complex problems occasionally require more columns than available.
A spreadsheet file can contain more than one worksheet, which can be selected
by means of a worksheet navigation toolbar generally located at the bottom left of
the main window. Menu commands allow visualizing several worksheets at once.
All the worksheets contained in a given spreadsheet file constitute a workbook.
Workbooks are a useful way to organize one’s data, and also overcome the problem
deriving from the limited number of columns in an individual worksheet. Note that
this multiplicity of worksheets does not constitute a third dimension in which to lay
down data, but simply a way to collect multiple sheets in the same file.
The top part of the worksheet contains the column header, which reports
identifiers for the columns, while names for the rows are displayed on the left-hand
side in the row header. They define a system of coordinates that allow addressing
individual cells on the worksheet. The default system of coordinates is known as
A1: it identifies cells by giving letters for its columns (from A to IV) and numbers
for its rows (the top left column has coordinate A1). The alternative R1C1 system
presents the user with a pair of numbers, first the row and then the column (the top
left column is then R1C1, with ‘R’ and ‘C’ acting as mnemonic prefixes for the two
dimensions). Cells are internally addressed in the R1C1 format.
Most of the time, there is a single active cell, on which operations can be
performed. The active cell is marked in various ways: a border frames it, its row and
column headers are highlighted, and its coordinates are reported on the left-hand
side of the formula bar. There are several options for changing which cell is active:
clicking on a different cell (as long as we are not in formula input mode), using
the cursor keys (again unless not in input mode), or entering its coordinate in the
formula bar or a goto dialog. Not only individual cells, but any rectangular area of
the spreadsheet can be selected by highlighting a cell and moving the mouse while
keeping its left button depressed, or by using the cursor keys while pressing the
SHIFT key. One or more rows can be selected by similarly acting on the row header.
The same applies to columns. The entire worksheet can be selected by clicking on
the top left rectangle where the row and column headers meet. It is even possible to
select multiple areas by holding the CTRL key, as shown in Fig. 7.3. A number of
context-dependent commands acting on the selected cell or cells can be invoked by
clicking with the right button of the mouse (on a PC).
An alternative way to refer to cells, rectangular worksheet areas, and actually
even arbitrary regions, is to assign them a symbolic range name as shown in Fig. 7.3.
Range names can be used to find the associated area in the worksheet, but they are
especially useful as a mnemonic identifier within formulas.
Although the deductive spreadsheet constitutes a substantial extension of tradi-
tional applications such as Microsoft Excel, most of the core layout choices just
outlined do not need to be altered. Indeed, data will still be organized in workbooks
containing one or more worksheets, each of which will be a bidimensional grid of
cells, and the basic modality of interaction will remain the same. A few changes
will be visible, such as the addition of a few (sub-)menus and toolbars. Others will
be nearly invisible, such as possible support for more than 256 columns. Indeed,
7.1 Layout 263
most of the deductive extension will rest on existing interface features such as range
names and data lists (see Sect. 7.1.3).
An individual cell can contain either data or scalar formulas. A rectangular group
of cells can contain an array formula. We will further comment on the contents of
cells in Sect. 7.2. Instead, we now concentrate on the visual aspect of cells and the
options for modifying it.
By default, cells are uniform white rectangles outlined with a thin gray line.
Text entered in them is black. Commercial spreadsheets offer however a large
number of options for customizing their appearance to one’s taste. The contained
values can be formatted using different fonts, sizes, colors, alignments, etc. It is
also possible to instruct the application to display the contents according to some
intended interpretation such as dates, currencies, etc., often including fine detail
such as the number of decimal digits. The cell themselves can be decorated with
borders and a variety of backgrounds. They can also be individually protected
against modification or inspection.
The formatting commands are available from the menus, using the toolbar or
ribbon, by right-clicking on the selected cell(s), and through keyboard shortcuts.
The user interface of our deductive extension will retain all the formatting options
available within a cell. We will not need to alter them nor to introduce any new one.
264 7 The Traditional Interface
Many of the formatting options just discussed are applicable to selections spanning
multiple cells: each highlighted cell is then affected by the operation. Some
formatting operations are however specific to groups of cells. It is convenient to
classify them according to the geometry of the cell selection they apply to.
Rectangular areas of the spreadsheet can be treated as a unit when working with
array formulas (see Sect. 7.2 for more details) as well as in order to perform actions
such as selective printing. Most commercial products allow merging adjacent cells
into a single cell. This is particularly useful in order to associate a caption to an area
of the spreadsheet interpreted as a table with multiple columns (see Fig. 7.4 for an
example).
Rows and column as a whole have their own formatting operations, which
include the possibility of modifying their height and width, respectively. It also
possible to hide entire rows or columns (which corresponds to temporarily setting
their height/width to zero) and unhide them when desiring to inspect the data
contained in them. This is very useful for the purpose of managing the always
scarce area visible in a spreadsheet window. Most applications actually support
outlines, which associate a number of contiguous rows or columns with a button
to hide/unhide them as a group.
7.2 Formulas 265
7.2 Formulas
Although spreadsheets are occasionally used to format grocery lists, contacts, and
other data, the power of these applications truly emerges when using formulas.
Indeed, formulas allow extracting information that is implicit in the raw data that
populates other cells. The visualization of these derived values, for example a
currency conversion or the total of an expense list, enriches the information available
to the user by expressing it in a more usable way. Indeed, formulas raise the
spreadsheet from a simple data recording application to a powerful problem solving
tool. Calculated values can furthermore be formatted in the very same way as basic
data.
We will dedicate the rest of this chapter to this problem solving support and
especially to the interface functionalities available to the user to take advantage of
it. We begin with the most basic method for constructing a formula: entering it
266 7 The Traditional Interface
as text in a cell. We examine the syntax and structure of scalar formulas as seen
by the user in Sect. 7.2.1, while the textual method for entering array formulas is
reviewed in Sect. 7.2.1. Although many users rely on this textual form of formula
construction, many more find it clumsy if not frustrating, and happily do without
it whenever possible. For them, all commercial spreadsheets make available conve-
nient graphical methods for constructing formulas. This is examined in Sect. 7.2.3.
It should be noted that these methods are just front-ends to the textual language,
and therefore a thorough understanding of this more rudimentary formalism is
essential. Section 7.2.4 describes what is maybe the most commonly used approach
in large spreadsheets: the clever copy-and-paste mechanism characteristic of these
applications.
It is to the problem solving potential of the traditional spreadsheet that our
deductive extension attaches. Indeed, the clausal infrastructure described in Part I
enriches the notion of formula by providing logically motivated mechanisms that
operate on blocks of cells at a time. In Chap. 9, we will extend the textual syntax
of Excel and similar products to accommodate clausal theories. We will also extend
the range of its graphical formula construction methods to these new objects.
In order to enter a scalar formula in a cell, the user simply types an ‘D’ sign and
then the formula she wants to include in that cell. Cell B17 in Fig. 7.6 contains
the simple formula that converts a temperature expressed in Celsius degrees into
Fahrenheit. The formula itself, “D B16 9=5 C 32”, is displayed in the rightmost
textbox of the formula bar while cell B17 shows its result, 68, calculated from the
fact that the reference B16 contains the value 20. In general, this box holds the
contents entered in a cell: with the exception of formulas, this is also what appears
in the cell itself, modulo formatting. The appearance of the formula bar changes as
shown in Fig. 7.5 as soon as the user hints at entering a calculated expression by
pressing the ‘D’ key. Various functionalities that we will discuss in further detail in
this section become available.
We described the abstract syntax of textual formulas in Chap. 3. We will now
comment on the concrete syntax, i.e., what the user actually types into the input
box. For the most part, writing a formula from scratch is a very simple matter:
many arithmetic formulas use the notation we all learned in school, such as “D
20 9=5 C32”: operators are infix and obey the usual precedence rules which can be
overridden by including parentheses. This is pretty much what we would type into
a handheld calculator. This intuitive picture is subject to two minor complications.
First, commercial spreadsheets make available a number of functions that
exceeds by far the arithmetic operators of our youth. For them, an infix notation
is often impractical because they can take more than two arguments (sometimes a
variable number of arguments), or because it would be unrelated to our experience.
In these cases, the notation is borrowed from our calculus classes: the name of the
7.2 Formulas 267
AutoSum
different worksheet by prefixing the name of this sheet with “!” as a separator, as in
“D Sheet2ŠA3 C 1”. It is even possible to reference a cell in a different file.
The same input box that allows creating a new formula can be used to modify
an existing expression. Excel and other applications simplify this task somewhat
by outlining in different colors the cell referenced in a formula. Unfortunately, this
visual aid disappears as soon as one starts the editing process. Both while creating
and while modifying a formula, a user can make syntactic mistakes and enter an
ill-formed expression. In that case the application shows an error dialog with hints
at how to correct it.
Our deductive extension of the spreadsheet will interfere only minimally with the
concrete syntax of scalar formulas. The changes will indeed be limited to extending
the current notation to support partial rows and columns in a simple and general
way, and to providing a functionality to embed clauses within scalar formulas.
Array formulas are associated not with a single cell as scalar expressions, but with
all the cells in a range. They describe the simultaneous computation of multiple
values. For instance, Fig. 7.7 extends our last example by showing an array formula
that converts a series of Celsius measurements to Fahrenheit. This formula resides in
the range B17:AX17, while its input is located in the range B16:AX16. The formula
itself, “fD B16WAX16 9=5 C 32g”, is very similar to what we used in Fig. 7.6: the
main difference is given by the fact that the range B16:AX16 takes the place of the
reference B16, which promotes the operators , =, and C to their component-wise
versions. The braces surrounding this formula are a visual reminder that this is an
array formula.
Entering an array formula into a spreadsheet is more involved than writing a
scalar expression. Indeed, simply typing “fD B16WAX16 9=5 C 32g” in the usual
text box of the formula bar will simply insert this string in the target cell, or cause a
warning if a cell range had been selected. The proper way to create this formula in
Excel (and all other commercial products we have tried) is to type “D B16WAX16
7.2 Formulas 269
9=5C32” and then press the key combination CTRLCSHIFTCENTER. The braces
are then inserted automatically. Simply pressing ENTER, as one would do for scalar
formulas, yields a value only for the first cell in the range, here B17. We have not
been able to find a justification for this design, which appears considerably more
complicated than necessary. For lack of a better explanation, we interpret it as an
extension of the otherwise excellent user interface of the traditional spreadsheet that
has not yet reached full maturity. Indeed, this design surprisingly violates several
of the cognitive principles that we will use as guidelines in Chap. 8 for our own
extension to the spreadsheet.
In the example in Fig. 7.7, the array of values returned by the formula had
the same geometry as the range containing the formula. Whenever this is not the
case, the result is truncated, padded with default values, or marked as partially
incomplete. Besides component-wise extensions of scalar operators such as , =,
and C, commercial spreadsheets make available a few constructs that natively return
arrays. We have encountered TRANSPOSE in Chap. 4. The traditional spreadsheet
also provides support for building arrays out of scalars and smaller arrays: for
example, for inserting the constant 2 2 array with first row (1,2) and second
row (3,4), one would select a 2 2 range, enter “D f1; 2I 3; 4g”, and seal it with
CTRLCSHIFTCENTER.
Updating array formulas is even more counter-intuitive than creating them
from scratch. Indeed, simply pointing to one of its cells and typing a new
value or formula will only result in an unfriendly error message. Attempting
the CTRLCSHIFTCENTER combination will produce the same effect. The only
way to modify an array formula is to select it in its entirety, make the changes,
and seal them with CTRLCSHIFTCENTER. One can alternatively use menu
functionalities to convert it to individual scalar formulas, and then operate normally.
Again, we believe these design choices force unnecessary cognitive overhead on the
users.
The clausal definition of a predicate in the deductive spreadsheet usually spans
several cells, often an entire table. Therefore, it is conceivable that a mechanism
akin to the construction of array formulas will be selected for this purpose. We will
follow this general path in Chap. 9, but not the specific modalities outlined in this
section. Indeed, we will aspire to a simple and intuitive approach for creating and
modifying clausal formulas that naturally extends the available methodologies for
scalar expressions. We believe our approach will be naturally applicable to array
formulas, thereby removing many of the current difficulties in taking full advantage
of them.
As mentioned above, typing an expression in the formula bar is not the only option
for creating and modifying a formula. All commercial spreadsheet implementations
offer a variety of alternative methods for achieving this effect, most of which
270 7 The Traditional Interface
take advantage of and contribute to the intuitive graphical user interface of these
applications. We will now examine these alternatives to writing textual formulas. We
begin with approaches that exploit the ability to point to cells and select ranges using
the mouse to simplify the construction of formulas. Then, we examine methods that
rely on dialogs to assist the user in the task of entering functions.
Excel and other products make several graphical modalities available to the user
for working with formulas. Consider for example the expense report displayed in
Fig. 7.8. In order to add up the items in cells B2 through B7, the user can of course
type the formula “D SUM.B2WB7/” in the formula input box. She can also type
just “D SUM.” and then select the range B2:B7 with the mouse: this will have the
effect of extending this formula prefix to “D SUM.B2WB7”. She will then need
only to close the parenthesis. Any reference can be included within a formula using
this method. This approach offers several benefits over textual input: first, it is often
faster and more natural; second, it visually captures the intended reference rather
than going through their mental translation via cell coordinates. This often results
in formulas with fewer mistakes.
Traditional spreadsheets also make available graphical methods for selecting the
functions that one wants to include in a formula. This does not apply however
to infix operators such as of C, but only to functional operators. We will now
examine the most prominent options.
Because of its frequent use, SUM has been assigned to a particular button in the
default toolbar configuration: it is marked with a † and generally known as autosum
(see Fig. 7.5). Pressing the autosum button proposes a formula that adds together all
the numerical values above or to the left of the active cell. The user can then modify
this range with her mouse or keyboard.
7.2 Formulas 271
Once the user starts entering a formula in a cell, even just the ‘D’ sign, the
formula bar changes aspect as shown in Fig. 7.5. In particular, the leftmost textbox,
which normally displays the coordinates to the active cell, is replaced with a pull-
down menu containing the most common functions. Selecting any of these entries
inserts a template for the corresponding function and brings up a dialog with a
description of the function itself, as well as input boxes for each of its arguments.
The user can then either type the intended expression for each argument, or select it
using the mouse. It is not possible to use this same mechanism recursively to embed
other functions within an argument, although one can always type them manually.
Figure 7.9 shows an example of this capability by extending the formula in Fig. 7.8
with an additional component aimed at accounting for the per diem portion of the
expense report: it states that if the number of days of travel (held in cell A8) is
greater than 30, then the user receives double per diem, otherwise single. Here, the
constant “PerDiem” is a defined name for a cell, as discussed in Sect. 7.1.1.
The entire library of functions available in the spreadsheet can be retrieved by
pressing the insert function button, bearing the icon fx in the default toolbar, or
from the appropriate menu. This brings up a dialog which organizes the available
functions into categories for easy browsing and displays a brief summary of what
each does. Selecting a function brings up the same type of input dialog already seen
in the case of IF.
Several programming languages and environments offer visual methods for
constructing formulas, and actually programs. There, icons representing operations
can be chained by means of input/output connectors to visually build expressions.
272 7 The Traditional Interface
No commercial realization of the traditional spreadsheet offers any such tools. This
is not completely surprising since they have been received with mixed reviews over
the years [GP96].
Graphical methods for constructing and modifying formulas are a welcome
alternative to textual input, in particular when working with complex formulas or
with unfamiliar operations. Since our deductive extension attaches to a large extent
to the language of formulas and because clausal theories may appear unfamiliar at
first, it is important to aggressively extend the graphical input methods to these new
constructions. A good part of Chap. 9 will be dedicated precisely to this task, which
can be conducted in a fairly noninvasive manner.
The graphical construction methods just examined greatly simplify the process of
building formulas, especially complex formulas. It is, however, frequent that the
same expression needs to be applied over and over to all the data in a list. We have
seen an example in Fig. 7.6, where an array formula was used to iterate the Celsius-
to-Fahrenheit computation to a whole range of input values. An alternative approach
to achieving the same effect is to produce one instance of the desired formula and
copy it in correspondence with all the input data. This is demonstrated on the same
problem in Fig. 7.10: cell B16 simply contains the value 5; cell C16 holds the
formula “D B16 C 1” which evaluates to 4; and cell B17 contains our original
formula, “D B16 9=5 C 32”. A copy of the contents of this cell has been pasted
into cell C17. However, a close examination reveals an altered formula: “D C16
9=5C32”, which correctly computes the Fahrenheit equivalent of the temperature in
C16. When copying a formula to a new location, all contained references are indeed
relativized to the target cell. Figure 7.10 takes further advantage of this property:
column C has been selected and pasted over columns D through AX. Therefore,
cell I16 contains the formula “D H16 C 1”, for example, while I17 contains “D
I16 9=5 C 32”.
This clever copy-and-paste mechanism is enabled by the fact that formulas are
internally represented using a relativized variant of the R1C1 notation. The formula
“D B16 9=5 C 32” is actually stored in cell B17 as “D RŒ1C 9=5 C 32”.
The syntax RŒ1C identifies the cell that is one row above the active cell, and on
the same column, i.e., B16 in A1 notation. Because reference C16 in the formula
“D C16 9=5 C 32” bears the same relation to hosting cell C17, the R1C1 form of
this formula is again “D RŒ1C 9=5 C 32”. Indeed, every cell in the range
B17:AX17 contains this same formula, even it they all appear different in the
standard A1 notation. By the same argument, cells C16 through AX16 all contain
one identical formula, “D RC Œ1 C 1”, where the syntax RC Œ1 refers to the cell
to the immediate left and on the same row as the current cell.
The references we have encountered in these examples are relative since the cell
they identify depends on the location where the reference appears. It is occasionally
7.2 Formulas 273
necessary to rely on absolute references, which identify the same cell independently
from where their hosting formula is located. This is achieved in the R1C1 notation
by simply using actual R1C1 addresses rather than displacements in square brackets.
For example, using absolute references in cell F17 (i.e., R17C6) the formula “D
RŒ1C 9=5 C 32” would present itself as “D R16C 6 9=5 C 32”: copying it
elsewhere would still maintain the reference to cell F16 (i.e., R16C6). References
can be partial, with for example the column expressed as a displacement and the row
in absolute terms, or vice versa. Absolute and hybrid references are also available
in the A1 notation by prefixing each coordinate that one wants to keep fixed with a
$ character. Our last example then becomes “D $F $16 9=5 C 32”.
The intuitive simplicity of the copy-and-paste mechanism over formulas has
made it the preferred method of iterating computations over a range of data. By
contrast, the alternative approach, using array formulas, requires planning and a
sequence of actions that is not as natural. It is also not as forgiving in that it is likely
that the user will do something wrong, hence prompting an annoying error dialog.
To the further detriment of the current array formula interface, these two approaches
do not work well together. Indeed, any attempt to use the copy-and-paste method on
a region intersecting an array formula will result in an error notification. This is
particularly unfortunate as it is common practice to use the copy-and-paste method
to extend a list and the data derived from it. For example, we could easily extend
the example in Fig. 7.10 past column AX by simply copying one of its columns
and pasting it at the end of this range, possibly over several columns. This would
not work in Fig. 7.7 as the size of the array formula was fixed when we pressed
CTRLCSHIFTCENTER. To achieve the same effect, we would need to delete this
formula and reenter it in the new range.
The clever copy-and-paste mechanism of formulas we just described has been
available in spreadsheet implementations since the early days of this technology,
and is clearly here to stay since it supports an increased user productivity at nearly
no cognitive cost. The extension of the user interface required by the deductive
spreadsheet will not alter this state of affairs, and indeed avail itself of this useful
option. We will tap into this mechanism to copy-and-paste clausal definitions
around a worksheet and between worksheets, honoring relative, absolute and hybrid
references as expected. We will also allow this mechanism to extend a relation
274 7 The Traditional Interface
or predicate with new records, even when calculated predicates are involved. This
will distinguish our approach from the current treatment of array formulas, which
resemble defined predicates.
Populating a spreadsheet with data and formulas acting on them does not always
solve the problem at hand once and for all. Indeed, there are a number of reasons
for revising a spreadsheet, which includes correcting conceptual mistakes and
maintaining the data up to date. It is often the nature of a spreadsheet to be
continuously updated, as for example with the status of one’s bank account. In this
section, we examine aspects of the more general issue of how the user can interact
with the evaluation engine to develop the solution of her problem. In particular,
we look at update propagation in Sect. 7.3.1 and at the explanation or debugging
facilities available in commercial products in Sect. 7.3.2.
7.3.1 Updates
By default, each time the content of a cell is modified, any formula depending
on it is automatically recalculated, hence accurately reflecting the new state of the
spreadsheet. We have examined the details of the underlying technology in Chap. 3.
This behavior is indeed what users expect and have come to desire. However, the
overhead due to recalculation can become noticeable, if not unbearable, for very
complex spreadsheets. For this reason, commercial applications provide a number
of alternatives. The opposite end of the spectrum is given by manual updates: there,
no recalculation is performed unless the user requires it by pressing a specific
key (in Excel, CTRLCALTCF9 for the current worksheet, SHIFTCF9 for the
current workbook, and F9 for all open workbooks). Intermediate options allow the
automatic calculation of all data except for those in a particular type of table used
for what-if analysis, the so-called “data tables” (see Sect. 7.4). Further options are
available for fine-tuning recalculation; however they are not relevant to the present
discussion.
The deductive extension of the traditional spreadsheet does not per se influence
the chosen recalculation modalities. The intricate dependencies and potentially large
defined relations available in the deductive spreadsheet however require care in
implementing efficient update algorithms and in choosing the default recalculation
policy. Details of these issues have been examined in Chap. 4 and will be further
reviewed in Chap. 9.
7.3 Controlling Evaluation 275
7.3.2 Explanation
Fig. 7.12 Tracing the dependents of a cell using the audit tool
that the active cells depends on. Again looking at our expense report example,
Fig. 7.12 displays arrows from all feeder cells into cell B8. It also displays indirect
dependencies, for example the fact that the value of cell A8 is calculated on the basis
of the contents of cells A2 and A7. The audit toolbar also provides methods to trace
dependents forward, and several more options. The audit arrows are uniformly blue,
while blue borders identify embedded ranges. Color-coding is not used. Indeed, it
is unfortunate that this set of tools and the inspection facility described in the last
paragraph are not better coordinated.
The intermediate values of any functional subexpressions of a formula and
their arguments can be inspected using the function insertion dialog discussed in
Sect. 7.2.3. This is visible in the central and right parts of Fig. 7.9. Using this
feature for debugging purposes requires some dexterity and it is available only for
functional subformulas. In particular, this method is not available for verifying the
value of partial arithmetic expressions such as “D B16 9=5” in our unit conversion
example.
The traditional explanation and debugging facilities just examined are extended
in the deductive spreadsheet to permit tracing the returned values of a clausal theory.
The technical underpinnings of this feature were described in Chaps. 5 and 6. This
clause-specific facilities will be integrated seamlessly into existing support. We
should remark that the traditional debugging facilities leave room for improvement,
although it is not our task to engineer better solutions.
7.5 Summary 277
7.5 Summary
In this chapter, we have dissected the user interface of the traditional spreadsheet, or
at least the functionalities that are most relevant to our extension. As we were doing
so, we noted the principal points that required intervention to support the deductive
machinery developed here. The main extensions will concern:
• The definition and manipulation of tabular data.
• The syntax of a textual language for clausal theories.
• An efficient input mechanism for clausal theories, which will also be available
for array formulas.
• The development of effective graphical means for constructing clausal formulas.
• The extension of the traditional explanation mechanism to clausally derived data.
All of these issues and a few more will be addressed in Chap. 9.
Chapter 8
Cognitive Interface Design
Section 8.5 concludes with a summary of the notions introduced in this chapter and
relates them to the cognitive requirements given in Chap. 2.
Usability studies are an important aspect of any research and development effort that
targets end-users (as opposed to experts who are often more tolerant and adaptable).
Such investigations have thus become common practice since the 1990s [Nie93].
At the early stages of development, usability studies evaluate and quantify the
time savings and processing costs of a proposed functionality, and allow comparing
these parameters for various approaches to presenting these functionalities to a user.
At a later stage, they allow establishing the ease of learning, efficiency of use, ease
of remembering, number of errors, and subjective evaluations of a tool.
Cognitive psychology provides user interface designers with a number of tools
for assessing the usability of an individual feature or an entire prototype of a system.
We will now examine three general approaches, commenting on their advantages,
their drawbacks, and in particular the point in the design cycle of the interface in
which they apply. This book will make use of two of them, but future developments
will take advantage of all of them.
Maybe the best known approach to assessing the usability of a user interface is
testing. A representative group of real users is monitored, often using electronic
recording software, while performing predetermined tasks on the target system.
Human-computer interaction experts compound the reactions, difficulties and over-
all performance of these users into an evaluation of individual aspects of the
interface, which is then passed to the designers to revise decisions that caused
unsatisfactory results. This process is iterated until all aspects of the design are
judged acceptable.
This approach is very valuable as it provides feedback that directly captures
the experience of actual users. It has also a number of drawbacks. It is expensive
as it involves a large number of individuals to be really effective, as well as a
controlled environment. It also takes a long time to perform, often several weeks for
an individual round, which has a negative impact on the time to market of a product.
Moreover, because the experiments occur in a controlled laboratory and the tasks
are predetermined, it is somewhat artificial as users may be more self-conscious
than in their natural environment. Finally, the mediation of the human-computer
interaction expert introduces an indirection into the feedback loop to the interface
designer. Because of these rather substantial drawbacks, it is important that user
testing be performed on a solid prototype interface that is judged unlikely to require
many changes.
8.1 Interface Usability Evaluation 281
Cognitive approaches based on predictive user models do not rely on users. Instead,
they consider core tasks of the system and compile a detailed chart of all the possible
ways to achieve each of them. If time estimates are associated with actions, they
provide a quantitative measure of how long it takes for a user to perform a given task.
They also summarize the knowledge or proficiency required of a user to perform
each individual task as the chart considers all the actions involved in achieving
it. The most widely used predictive methods are heuristic evaluation [NM94] and
cognitive walkthroughs [LRB91]—both discussed in more detail next—with GOMS
(Goals, Operators, Methods, and Selection rules) [OO90], an older, time-tested
method, worth mentioning as well.
Heuristic evaluation is a relatively simple but very effective usability method—
indeed, one of the most commonly used today [NM94]. This method relies on
expert evaluators, who examine the interface or prototype and judge its compliance
with recognized usability principles called heuristics. The main heuristics [NM94]
include visibility of system status (can the user always tell the state the system is in?
are there feedback mechanisms to assess the effect of an action?), match between
the system and the real world (does the system communicate with the user through
language, concepts and layouts that the user will relate to?), user control and
freedom (if the user makes a mistake, is there an easy way to undo it?), consistency
and standards (are similar features provided in similar ways?), help diagnose and
recover from errors (are error messages precise and constructive?), error prevention
(are there situations that are particularly error-prone?), recognition rather than
recall (are commands and information needed to perform actions visible or easily
accessible? does the user have to rely on memory to perform a sequence of tasks?),
flexibility and efficiency of use (are shortcuts available to experienced users?),
aesthetic and minimalistic design (is there irrelevant information that distracts
the user from accomplishing a task?), and help and documentation (is it easy
to find precise instructions to perform complex tasks?). Several of these features
transpire in the lightweight methods discussed in Sect. 8.1.3 and apply to design the
282 8 Cognitive Interface Design
user interface of the deductive spreadsheet in Chap. 9. The evaluators’ actions are
captured using electronic recording software similar to what used for user testing—
such tools are indeed very common in psychological research. These recordings
are then evaluated in order to infer how the actions of the evaluator are related to
the usability heuristic of interface design. The output of the heuristic evaluation
method is a list of usability issues in the interface with references to those usability
principles that were violated by the design in the opinion of the evaluator. Each
usability issue is linked to the particular heuristics. This method is also used to assess
the relative severity of the individual problems, which is useful in order to allocate
resources to fix the most serious issues and also provides an estimate of the needed
efforts. The severity of a usability issue is a combination of the frequency with which
the problem occurs, the impact of the problem if it occurs, and the persistence of
the problem (if it is a one-time problem or a repeated problem).
The cognitive walkthrough [LRB91] helps evaluate a system for ease of learning,
particularly by exploration. The evaluators in this case need to have significant
experience with the system. The cognitive walkthrough of a system or part has
two phases: a preparatory phase and an analysis phase. In the preparatory phase,
an evaluator lists a set of tasks, the action sequence for each task, the interface and
the information on how to do the walkthrough. Electronic recording software is
used to record all activities. Then, the analysis phase examines each action in the
solution path and attempts to give the reasons as to why users would choose that
action. Participants evaluate the interface and select actions they think accomplish
the task. Then, they observe the interface reactions to see if their actions have
the desired effect, and determine what action to take next. Questions such as the
following are asked during the analysis phase: “Did the user try to achieve the right
effect?”, “Did the user notice that the correct action was available?”, “Did the user
associate the correct action with the effect trying to be achieved?”, “Did the user see
that progress was being made when the correct action was performed?”. A subset
of these questions has been found to be sufficient in some cases [Spe00]. The
cognitive walkthrough method identifies the problems with the design and explains
the reasons for these problems. The walkthrough can be used to identify questions
that can be answered by specific, focused user testing, such as questions about user
terminology and task description.
Predictive approaches have proved extremely successful in organizing help
systems, training programs, and user documentation. They are also a useful
decision support for comparing alternative product choices against the needs of an
organization. They have however a few drawbacks of their own. Although much
cheaper and quicker than user testing, constructing a GOMS model of a system is
still expensive and requires the supervision of a human-computer interface expert.
Furthermore, this approach is only applicable on a finished system as measurements
depend on the perceptual characteristics of the interface, especially if timing is
considered. Finally, by concentrating on the steps to achieve a task, it tends to ignore
issues such as user skills (or lack thereof), mental workload, and errors.
8.2 Cognitive Dimensions of Notation 283
names, or more properly discussion tools, for concepts that are vaguely known
but unformulated has a number of advantages [Gre96a]: it promotes a higher level
of discourse, it facilitates analysis, it helps making decisions, it creates goals and
aspirations, it provides the basis of informed critique, it allows the interrelationship
of concepts to be appreciated, and it encourages the reuse of ideas in new contexts.
Furthermore, discussion tools can be used as a checklist to make sure that no
important concept lacked the proper consideration.
Notation Environment
System
We will now review each dimension in Fig. 8.2, writing them in a slanted font for
easy identification. We will describe each of them on the basis of examples taken
286 8 Cognitive Interface Design
Abstraction Gradient What are the minimum and maximum levels of ab-
straction? Can parts of the problem be encapsualated?
Closeness to Mapping How far is the problem statement from the model
of its solution?
Premature Commitment Does the user have to make decisions before she has
all the information she needs?
from the spreadsheet world, and occasionally use it to evaluate some of the specific
choices reviewed in Chap. 7. We also briefly describe how our intended extension
to the user interface of the traditional spreadsheet will affect this dimension. In
this respect, it is important to remember that we are bound by the decisions that
were made when the traditional spreadsheet was originally designed. Not only
shall we refrain from making any change that would alter the usability of existing
functionalities (our extension shall be conservative), but any addition shall strike the
same balance of dimensions as current features. In particular, using our deductive
extension shall “feel the same”, in a certain sense, as using traditional aspects
of the spreadsheet. Therefore, we will refrain from deviating from the status quo
in any major way. Paraphrasing the important consistency dimension that will be
introduced shortly, this is a form of “meta-consistency”.
8.2 Cognitive Dimensions of Notation 287
can
increase Secondary
increase Viscosity
cost
notation
Premature can
reduce
commitment
can
increase Abstraction can
increase
can Hidden
increase dependencies
complex
Visibility
Abstraction Gradient
Any time there is a way to realize a sequence of functionalities with a single action,
we have an abstraction. For example, the possibility of selecting multiple worksheet
cells for manipulation is an abstraction over working with individual locations,
and similarly the ability of selecting rows abstracts scrolling a selection till the
last column. User-defined macros are an even more obvious example. The data list
and data form automatically generated for a group of columns in Excel abstract
these columns as a table. Spreadsheet formulas can be seen as a parametric form
of abstraction in that not only do they compound several operators, so that they can
be manipulated as a single object, for example via copy-and-paste, but also their
result varies with the value of the cells they reference. Spreadsheets support fairly
mild forms of abstraction, in particular when compared to programming languages.
More expressive forms of abstraction, e.g., user-defined functions, have recently
been proposed [PBB03, BADC 01].
Abstraction may appear to be a good thing, unconditionally. In fact, each time
we introduce an abstraction, we are asking the user to learn a new command if not a
new concept. Complex abstractions can however be overwhelming and therefore
detrimental to productivity. Whenever the abstraction is part of the notation,
as references in formulas, it can lead to added hidden dependencies (another
dimension, see below), but on the other hand it can reduce viscosity. Figure 8.3
describes further trade-offs involving abstraction.
The user interface of the deductive spreadsheet will for the most part leverage
existing abstractions. It will also extend the data list abstraction to unsorted
relations, and provide clausal theories as further abstractions similar in spirit to
scalar formulas.
288 8 Cognitive Interface Design
Closeness to Mapping
This dimension attempts to express how distant the notation is with respect to
the problems it is meant to solve. Considering that a spreadsheet is an electronic
rendering of an accountant’s book, this formalism has very high closeness to
mapping for most types of tabular data. Of course, one may use a spreadsheet
for solving problems that are not conveniently cast in this format, which shows
poor judgments rather than deficiencies of these applications in terms of closeness
to mapping. Because the deductive extension is inherently tabular, it will take
maximum advantage of the current state of affairs.
Consistency
Diffuseness/Terseness
This dimension measures the verbosity of the notation, and therefore the space it
takes to use it to solve a problem. A succinct economical interface is terse and
has the advantage of allowing a larger part of the model to be visible at any time.
A diffuse notation takes up more space, but may be more readable. Traditional
spreadsheets tend to strike a good balance between these two extremes by providing
concise notations for formulas and graphical elements, and yet maintaining good
readability. Our deductive extension will not disrupt this order.
Error-Proneness
it easy to mistype cell coordinates, which sometimes results in rather subtle errors.
Using the graphical approaches to building formulas mitigates this problem, as does
using named cells. Spreadsheets are an example of visual notation in which high
error-proneness, although undesirable as an isolated cognitive dimension, has been
judged acceptable in the system as a whole. Indeed, making spreadsheets more
resistant to errors would compromise the usability of these tools.
Our deductive extension will be neutral with respect to this dimension. It will
support all the devices listed above to reduce the error-proneness of formula
construction and make them available in the logical context, but it will not force
them on the user. It is however expected that users will find building clausal theories
graphically, or on the basis of symbolic names, easier than entering cell ranges.
The notation contains hard mental operations if some simple concepts cannot be
expressed but by relying on complicated constructions. We have encountered one
instance in Chap. 6, where the base logical language of the deductive spreadsheet
forced expressing extensional “for all” statements by means of cascaded negations.
The issue was solved by providing an abbreviation, FORALL, as an additional
syntax element (we changed the notation). This had the effect of increasing
abstraction and diffuseness.
Other hard mental operations are primitives that invariably send the user to the
help menu. For example, the “database functions” implemented in most spreadsheet
applications fall into this category as they take unintuitive arguments such as
conditional tests (they are used to selectively aggregate records in data lists). Our
deductive extension provides a simple alternative to solving these same problems
(hence increasing abstraction ).
Hard mental operations are error-prone especially if they are used frequently.
Therefore eliminating them is desirable, as long that they are not replaced by a
more damaging combination of dimensions. This is the heuristic we have followed
in Chap. 6 when introducing FORALL, and that we will continue to follow while
designing the user interface of our language.
Hidden Dependencies
This attribute considers whether the notation or interface makes it evident when
parts depend on one another. Spreadsheets have lots of hidden dependencies . By
just looking at the cell grid, it is impossible to tell which cells contain actual values
and which are calculated using formulas. Only selecting a cell will reveal its nature
and, in the latter case, show only the addresses of the cells it directly depends on: the
cells they themselves depend on are unknown, and the cells it feeds to are not shown
either. Of course, the auditing tools we examined in Chap. 7 provide simple ways
to display all this information, but most users are not aware of their existence, they
290 8 Cognitive Interface Design
work only on the active cell, and the uniform blue color for both antecedents and
consequents makes them less useful that they could be.
Hidden dependencies are generally bad as they make the notation error-prone,
a well-documented reality of spreadsheets [Pan98]. On the other hand, a spreadsheet
with all dependencies revealed would be nearly unusable, although other languages
offer this possibility with good benefits [GP96].
Our design for the interface extension of the deductive spreadsheet will attempt
to maintain the status quo, in order not to disrupt user expectations. It will indeed
make use of the very same hidden dependencies currently present in the traditional
spreadsheet. It will also extend the auditing mechanism to work with the added
language fragment.
Premature Commitment
Premature commitment , also called enforced look-ahead, allows asking whether the
user is forced to make a decision before she has, or has thought of, all the needed
information. For the most part, spreadsheet interfaces avoid imposing an order of
action on users. For example, a formula can use references that have not been filled
with data, which will generally yield some innocuous default value. One example of
premature commitment we have encountered is the construction of array formulas.
As we saw in Chap. 7, a user is forced to decide a priori how many cells the array
shall contain, and any later change will essentially force her to undo the original
work and then redo it.
Forcing occasional spreadsheet users and novices to commit prematurely to their
choices would generally be bad as the subsequent frustration is likely to discourage
them from using these tools. On the other hand, professionals may want the system
to help them anticipate problems by requiring them to think ahead. The near absence
of premature commitment required to use a spreadsheet has certainly contributed to
the popularity of these applications by making them easy to use. On the other, hand
it may also be blamed, in part, for the high number of errors found in spreadsheets
[Pan98].
In supplying notation to use the deductive features, we shall adhere to the
general philosophy of the traditional spreadsheet which spares the user premature
commitment whenever possible (except for array formulas).
Progressive Evaluation
Role Expressiveness
Secondary Notation
This dimension refers to the possibility of using the inessential aspects of the
notation to convey useful information without affecting operation. Two examples
in the spreadsheet world are cell formatting and range names. By formatting the
contents of a cell (as a currency rather than a number), we are making its intended
meaning clear. We can furthermore mark it in bold, for example to convey that
it is an important value, and use a colored background as a reminder that it is
calculated using a formula. Range names support secondary notation by allowing
the user to choose a meaningful identifier rather than anonymous A1 coordinates.
Spreadsheets provide a lot of support for secondary notation, other examples being
Post-It-looking notes that can be associated with cells, and the use of textual values
whose only purpose is to describe the meaning of adjacent cells.
The availability of secondary notation is of great convenience to users as they
tend to rely on it to convey meaning that is not part of the primary notation of cells
and formulas. It is helpful in reducing error rates, but can however promote viscosity
since it may be yet another thing to change.
The deductive spreadsheet will maintain the same secondary notations already
available in commercial products. Because predicates and relations are more
complex than individual cells, it can help the user label and manage these objects.
Viscosity
Viscosity is the amount of effort required to make a small change. Highly viscose
notations make it hard to implement small conceptual changes. One example in
292 8 Cognitive Interface Design
The visibility dimension is an attempt to verbalize the degree to which users are
able to quickly access different parts of the data they are using the notation for.
Juxtaposability , included in the same dimension, asks whether two parts can be
placed side-by-side for comparison, or whether to use one part as a model for
another. Assuming a large enough display, spreadsheets excel in both visibility
and juxtaposability. Indeed, the scrollbars and worksheet navigation icons allow
exposing any part of a worksheet in no time. A window can be split by a simple
mouse action in order to juxtapose areas of the same worksheet, horizontally or
vertically. Putting different worksheets side by side can be done using menu options.
As an illustration of a lack of juxtaposability, comparing two formulas is not
possible unless one takes advantage of a seldom-used menu option that allows the
worksheet to display formulas, rather than their results.
Visibility and juxtaposability are generally positive properties, as they tend
to increase productivity. They are less desirable when an inexpert user could do
damage if he had easy access to all parts of the system (for example if he could
tinker with the implementation of the built-in operators) or could put some parts side
by side. For example, a right-click menu item that allowed him to decide whether
individual cells should show a formula or its result would quickly lead to confusion.
8.3 Attention Investment Model 293
Our general goal in Chap. 9 will be to maintain the level of visibility and
juxtaposability already available in the traditional spreadsheet in any worksheet
extension.
Other Dimensions
While the above dimensions are fairly standard, researchers are continuously
proposing new ones with names such as “creative ambiguity”, “specificity” and
“useful awkwardness” [Bla00]. Most of these ideas appear to be rather esoteric
in the context of a spreadsheet and will not be considered further. One proposal,
permissiveness , is quite relevant as it expresses whether the notation provides
several different ways to do the same thing. Spreadsheets are advantageously
permissive, in this sense. Indeed, the most common functionalities can be invoked
from the menu bar, from toolbars, using keyboard shortcuts, from pull-down menus
and more. This is certainly a characteristic that we will strive to maintain in our
extension.
Because the deductive spreadsheet is an extension of its traditional counterpart,
our design has another constraint, a dimension that we may call conservativity : as
we make deductive features available, every aspect of the user interface that pertains
to the traditional functionalities of a spreadsheet shall remain available. Said in
another way, we shall not take anything away from a user who does not need our
extensions. This does not mean that they should be invisible, as this would defeat
the user’s ability to stumble upon new features, hence reducing consistency. Precise
requirements for these different issues were given in Chap. 2.
8.3.1 Overview
Consider for example the decision of starting to use a spreadsheet to keep track
of one’s travel expenses as opposed to writing them down on paper. The cost is
the time spent learning to use some basic features of, say, Excel. Note that this
may be substantial for users unfamiliar with personal computers, but minimal for
users who have experience with other visual applications such as word processors.
The immediate payoff is not to have to go through the error-prone process of adding
up expenses by hand. Another more remote payoff is acquiring the skills to use
a spreadsheet for other tasks in the future. The risk is that acquainting oneself
with this new application may take too much time, possibly without really solving
the problem (recall that risk is something perceived by the user, not an objective
assessment).
With these definitions in hand, let us apply the attention investment model to the
deductive spreadsheet: not to the user interface amendments that will be introduced
in Chap. 9, but to the core functionalities described in Part I of this book. Following
the steps of [PBB03], what we are trying to understand is why a user should even
bother about our deductive extension. Said in another way, is it worth making it
an integral part of the spreadsheet, a tool that has enjoyed unfaltering popularity for
over 30 years even without our extension? In order to establish this, we need to spell
out the payoffs, the costs, and the risks of embracing this extension.
Payoffs: As amply demonstrated in Chap. 6, the most important benefit of our
deductive extension is that it enlarges the class of problems that a user can
use a spreadsheet for. Considering that most home and many office computing
environments do not provide any application that could help with these new
problems, as observed in Chap. 1, the payoff is the ability to have access to
automated assistance in solving them, as opposed to handling them by hand,
8.3 Attention Investment Model 295
It is again interesting to compare this with array formulas. The first form of risk
is quite concrete here since this feature does not extend the range or problems
solvable with just scalar formulas. Learning to use array formulas will often
exceed the time needed for a purely scalar solution. The time saving once this
feature has been mastered is not evident either.
Since we are using [PBB03] as inspiration for this methodology, it is useful to
compare these conclusions with their analysis of the extension they propose: adding
infrastructure to allow users to define their own functions. A major difference lies
in the fact that our deductive extension enlarges the class of problems solvable with
a spreadsheet while providing user-defined functions does not. Because the added
benefit of the latter is mostly convenience, users are likely to be willing to sustain a
lower cost and take smaller risks. Since we are supporting a new class of problems,
it is expected that users who need to solve any of these problems will have more
perseverance in exploring our extension and be willing to take greater risks.
The attention investment model provides designers with terms for concepts for
which they have an intuitive understanding, hence making some usability concerns
explicit for analysis purpose and during discussion with others. This is similar to
the cognitive dimensions framework. The two models are complementary: again
quoting from [PBB03],
As an intellectual tool for language designers, a strength of the attention investment model
is its generality, which allows it to provide insight not produced by the more specific CD
[cognitive dimensions] framework. On the other hand, the concrete enumeration of issues
in CDs is more prescriptive of specific problems to consider, and provides sharper questions
for language designers.
For these reasons, these two techniques work well together and we use them for the
purpose of designing the user interface extension of the deductive spreadsheet in
Chap. 9. The relationship between the two models has also been investigated from
the standpoint of cognitive psychology, where [BG99] observes that the attention
investment model can act as a rationale for the choice of dimensions of the cognitive
dimensions framework.
The cost/benefit analysis derived from the above application of the attention
investment model allows us to identify rather precisely the target audience of the
deductive spreadsheet. Indeed, the total cost of embracing this extension depends of
the previous investments a user has made in learning to use various features of the
traditional spreadsheet. If she already knows how to define and manipulate a data
list, then there is no cost associated with using it. The fewer spreadsheet skills a user
8.4 Target Audience 297
has, the harder it will be for her to master the deductive extension, and therefore the
greater the risk of investing time to learn about it. The minimum skills expected
to make this investment worthy are the prerequisites of the deductive spreadsheet.
Clearly, deciding what is prerequisite is a judgment call as persevering users will
be willing to make riskier investments. A prerequisite is an asset for the users who
have it, but a barrier for those who do not possess it as it is expected that they will
not be able to carry out tasks that require them [PBB03].
The prerequisites needed of a user of the traditional spreadsheet to take advantage
of our deductive extension are as follows:
1. A target user should be familiar with organizing information in a tabular form.
2. She should be able to select cell ranges, and especially entire rows or columns.
3. A target user should be comfortable with defining scalar formulas, including
those that make use of SUM-like operators that take cell ranges as arguments.
Familiarity with array formulas is not required.
Several bonus skills will further lower the learning cost: having worked with data
lists subsumes the first prerequisite and takes the target user closer to some of
the relational manipulations available in the deductive spreadsheet. Another bonus
skill is having used defined range names, as they will substantially simplify writing
clausal theories. Note that these bonus skills are not prerequisites, but offer a head
start to those who have them.
This list of prerequisites identifies an intermediate segment of the spreadsheet
user base: individuals who understand the spreadsheet paradigm fairly thoroughly
and have been using these applications frequently and for a rather long time.
Because of this exposure, they have experienced learning new features several times
and have a feel for it. They also know where to look for additional information if
they run into difficulties.
Expert users, for example those who have used Visual Basic for Applications
for implementing functionalities that Excel does not provide natively, also benefit
from the deductive extension as it allows them to solve problems that they could not
tackle in the traditional spreadsheet. Among expert users, professional developers
build customized extensions as part of their job, whether for clients or within the IT
department of their organization. We expect them to adopt the deductive extension
as yet another tool to perform their day-to-day job. For them, the cognitive cost is
relatively low because they are already familiar with sophisticated programming
and database concepts, while the payoff may be substantial as it would provide
them with native constructs that they may need to program explicitly to perform
some tasks.
The users who are left out are those who have used spreadsheets for nothing
more than managing and printing lists of information, or little more. They may be
able to write basic formulas, but they do not possess the familiarity of intermediate
users. Switching to the deductive spreadsheet is not likely to change their use of the
application, and they will probably not know what to do with the deductive features.
Quoting from [PBB03], our extension “has little to offer to these groups, because
the payoff (approximately zero) is lower than the learning cost of the prerequisites”.
298 8 Cognitive Interface Design
8.5 Summary
In this chapter, we have reviewed some recent advances in the cognitive psychology
literature, namely the cognitive dimensions of notations framework [Gre89, GP96]
and the attention investment model [Bla02], and extracted a methodology that
will prove useful in designing the first cut of a user interface for the deductive
spreadsheet that users may be comfortable with. We will indeed apply these user-
centric guidelines in Chap. 9 each time we need to decide how to provide access
to an extended functionality. Abiding by the requirements of Chap. 2, this task
will be constrained by the necessity of being conservative with respect to the
traditional interface, so that users who do not need the deductive extensions will
not be penalized, and users who want to avail themselves of them can rely on
their experience with the traditional interface to quickly learn to use them. What
these cognitive frameworks do not do is to provide any assurance that the resulting
interface will be free of defects, or even that it will be blessed by user acceptance.
These assessments must be done a posteriori using standard techniques such as user
testing, a very limited form of which will be reported in Chap. 10. Following those
two cognitive models as guiding principles will however allow us to make informed
decisions and therefore provide us with sufficient confidence in the adequacy of the
design in Chap. 9 as a first version of the user interface of the deductive spreadsheet.
While these cognitive models provide guidelines to make educated decisions,
they do not prescribe a design, and do not even lay down the possible choices.
These issues require creativity and taste, or at least awareness of what is “out
there”, both within actual applications and in the literature. Once a choice, or set
of candidate choices, has been made, these models will provide a way to make an
early evaluation. Possible designs are also constrained by the cognitive requirements
introduced in Chap. 2, which we recall at the highest level of granularity:
Cognitive conservativity: All traditional functionalities shall be accessible to
the user in the exact same way as in a traditional spreadsheet.
Consistency: The commands supporting the deductive extensions shall be con-
sistent with the existing modalities of interaction and with the user’s expectation.
Cognitive Integration: Using deductive capabilities shall be natural and intu-
itive, including when used in conjunction with traditional functionalities.
Performance: Common deductive inferences should have a performance that is
subjectively comparable to spreadsheet operations of intermediate complexity.
Discovery: The deductive extension should have a gentle learning curve so that
users can reinforce and extend their skills by simply using the tool and minimal
experimentation.
Notice that what we called “consistency” and “discovery” in Chap. 2 spell out
different aspects of the consistency dimension discussed in Sect. 8.2.2. The other
two classes of requirements derive from the fact that we are building on top of the
user interface of the traditional spreadsheet rather than starting from scratch.
Chapter 9
Toward a Deductive Interface
The present chapter completes the design of the deductive spreadsheet by proposing
an approach to making the logical functionalities engineered in Part I available for
practical use as an extension of the user interface of the traditional spreadsheet,
which we examined in Chap. 7. As we do so, our primary concern will be to
remain conservative with respect to the choices that have sedimented in the excellent
interfaces of modern spreadsheet applications, choices to which users have become
accustomed and on which sometimes dependent. Within these necessary bounds,
our major design objective is to provide the user with a simple and intuitive access to
the enhanced expressive power of the deductive infrastructure. For the most part, this
will be realized by simply extending the current interaction modalities to the new
deductive components. For example, all the graphical approaches to constructing
a scalar or array formula will be usable when building a clausal definition. We
will occasionally extend current support in order to further simplify the user’s
experience, in particular by offering a new interactive way to assemble clauses, or
to take advantage of the deductive infrastructure, for instance by providing novel
flow graph visualization mechanisms. Some decisions break away with tradition, for
example a proposal to make two distinct but equivalent input languages available
for the deductive fragment: one closely tracking the logical syntax of clauses
of Chaps. 5 and 6, and one in line with relational algebra as used for querying
databases. This choice is made on usability grounds as some users may be more
comfortable modeling a problem logically, while others may prefer the relational
view.
We will make abundant use of the cognitive techniques of Chap. 8 as we elicit
our preliminary design for the user interface of the deductive spreadsheet. Indeed,
the attention investment model will act as an overall framework which will guide
us toward providing techniques that facilitate access to the new functionalities.
Individual decision points will often be scrutinized through the web of the cognitive
dimensions in order to reach optimal compromises. Ultimately, these decisions will
have to get user approval, which will be assessed through testing and feedback.
We start in Chap. 10. Because we are designing a graphical user interface, we
will provide illustrations for most of the visual additions we propose. For the sake
symbolic name. Even after doing so, the traditional spreadsheet does not provide
any infrastructure to work with them relationally inside a formula. Of course, this
is precisely what the deductive spreadsheet brings to the table.
In this section, we discuss a mechanism that helps in defining a relation and
making it and its fields available for use in clausal formulas. It is not meant to replace
the traditional approaches illustrated above, but to complement them. Indeed, it
conveniently bundles together a number of enabling functionalities that are currently
scattered throughout the user interface. It should also be noted that this is not a
prerequisite for writing clausal definitions as it will be possible to rely uniquely on
cell ranges, for example (see Sect. 9.2), but it makes this task substantially easier.
A relation occupies a region of the worksheet, and therefore can be identified either
by typing range coordinates or by selecting its cells using the mouse or direction
keys. Currently, this last option works well when selecting a small rectangular area
or one or more rows or columns. The only way to highlight a region comprising
columns C and D and extending from row 25 to the very bottom of the worksheet
is to select cells C25 and D25, and tediously drag the mouse till its last row is
reached, a process that can take quite some time on older machines. We call such an
area a partial unbounded column, with a similar notion applying to rows. Because
many relations are often unbounded, a user may want to leave some space above
a columnar table, or to the left of a horizontal one, to include captions, comments
and generic calculations. In order to enable this, we propose an effective method
for quickly selecting a contiguous group of rows or columns starting at an arbitrary
point in the worksheet and extending to its last column or row, respectively. Let us
illustrate it on the above example:
1. The user first scrolls the worksheet so that cell C25 and D25 are visible.
2. She selects columns C and D from the column header.
3. With the mouse button still depressed, she moves the cursor toward cells D25
(if she initially selected column C) or C25 (otherwise). The selected region
shrinks accordingly.
4. When she has reached this cell, she releases the mouse button, hence partially
selecting columns C and D from row 25 till the bottom of the worksheet.
A partial unbounded selection spanning a number of columns so large that it
does not fit on the screen is performed in the same way, except that the initial
whole-column selection will automatically scroll the display horizontally. Note that
the target starting row of the selection can be anywhere, not necessarily near the
top: the only requirement is that it appear on the screen as the selection operation is
started.
While the above description illustrated the partial unbounded selection of
columns, the same approach applies to rows. Observe that this method is con-
servative with respect to the traditional spreadsheet as selecting a row or column
302 9 Toward a Deductive Interface
and moving the cursor inside the worksheet while the mouse button is depressed
simply leaves that entire row or column selected. This is cognitively consistent
with usual selection techniques. This method can participate in the selection
of heterogeneous or non-contiguous regions by keeping the CTRL key pressed
throughout the process.
Now that we have a way to select appropriate regions of the worksheet, we will
make a dialog, or wizard in Excel parlance, available to identify a group of cells as
a relation and assign symbolic names to its attributes. It can be invoked either from
the menu bar (under “Data” for example), or by selecting a multiple-cell region of
the worksheet, right-clicking on it and choosing the menu option that reads “Define
Relation . . . ”. This possibility is illustrated in Fig. 9.1 on a potential extension of
the user interface of Microsoft Excel 2003.
The “Define Relation . . . ” dialog itself is shown in Fig. 9.2, where it has been
instantiated for an area of the worksheet meant to contain the definition of the
path predicate, which we have encountered several times in Chap. 6. When initially
invoked, only the “Range” textbox contains any data. The user can modify it and fill
9.1 Deductive Layout 303
the remaining parts of the dialog to her taste. Note that she is not forced to undertake
any of these actions. We will now examine each input field and action button in turn.
Name: This optional field allows giving a name to the cell range on which the
relation is defined. We wrote path in it in our example. This corresponds
to selecting the range and assigning a symbolic name to it using the “Define
Name . . . ” dialog examined in Chap. 7. Additionally, it places this name on the
defined predicates list, which can conveniently be used later in order to quickly
build clauses. Predicate names are required to be unique.
Range: This field, which is automatically filled when the dialog is invoked,
describes the geometry of the selected range of cells. It will typically contain
a rectangular area, possibly spanning (partial) unbounded rows or columns.
Figure 9.1 shows columns C and D selected in their entirety, but the “Range”
in Fig. 9.2 specifies that they start at column 3 and extend to the bottom of
the spreadsheet (the notation C 3WD for partial unbounded selections will be
defined in Sect. 9.2). This incongruence is due to the fact that the two “Insert . . . ”
checkboxes are checked. Their meaning will be explained below.
Non-contiguous regions, possibly over different worksheets, can constitute a
relation, and can be entered in the “Range” field as a comma-separated list of
rectangular areas. We have seen in Chap. 7 that such regions can be assigned
names in the “Define Name . . . ” dialog. The only restriction on this possibility is
304 9 Toward a Deductive Interface
that all subregions must form a rectangle if they are to be juxtaposed: otherwise,
there would be no way to ensure that each record in the relation has the same
number of elements. It is expected that a user will rarely avail herself of this
possibility.
If the relation has not been assigned a name, it is its hosting range that is entered
in the defined predicates list. The range of the relation is partitioned among its
fields in the “Fields” enclosure described below. This partition is either vertical
or horizontal depending on which of the “Fields as columns/rows” radio button
discussed next is selected.
Fields as columns/Fields as rows: Differently from commercial products, we
do not force the user to align the fields of her relations along the columns of
the worksheet. This dual radio button allows her to choose how the selected
region is to be interpreted as a relation. If “Fields as columns” is selected, the
traditional layout will be in vigor. If she clicks on “Fields as rows”, attributes
will be horizontal and records vertical. The first option could be the default.
Insert title row/column: The last word of the label is “row” if “Fields as
columns” was selected, and “column” otherwise. If this box is checked, the
relation name entered in the “Name” field will be installed across the top row
or leftmost column of the selected area once the user presses the “OK” button.
Its cells will be merged and the text will be centered and highlighted in bold, as
shown in Fig. 9.3. The user can always change this formatting later.
Checking this box has the effect of shrinking the extension of the relation that
can hold records by one row or one column. The “Range” of the relation as well
as each “Range” in the “Fields” enclosure are automatically adjusted to reflect
this effect. Unchecking it restores them to their original value.
Insert field row/column: The last word of the label is “row” if “Fields as
columns” was selected, and “column” otherwise. When checked, pressing the
“OK” button will write the “Name” values associated to the various attributes of
the relation in the “Fields” enclosure in a dedicated row or column just under or
9.1 Deductive Layout 305
right of the title if “Insert title row/column” was checked, and in the top/leftmost
row/column otherwise. Each name will be centered in its cell, as shown in
Fig. 9.3. Fields holding list of values span multiple rows or columns. In this case,
the cells where the field name is supposed to land are merged before inserting it.
Again, selecting this option will shrink the area intended for data by one record,
and this will be reflected in the various ranges of the dialog. Indeed, it is because
both “Insert title row” and “Insert field row” are checked in Fig. 9.2 that the
“Range” of path contains C 3WD rather than C WD. The same holds for the
ranges in the “Fields” enclosure.
Fields: This enclosure describes the fields of the relation being defined. Each
line corresponds to one field and contains a checkbox, a “Range” textbox and a
“Name” textbox. We will now describe these objects in turn:
Field checkbox: The purpose of this checkbox is to select fields for later
deletion using the “Delete marked fields” button. It is unchecked by default.
It is not strictly necessary as a field can always be deleted by blanking out its
“Range”. It is provided as a convenience for the user.
Field range: This entry allows specifying the extension of a field. It is
automatically filled with a single column/row when the user initially invokes
the dialog. She needs to modify the contained range if this attribute is to
correspond to a list of values, as described in Chap. 6. If she does so, overlap-
ping unnamed fields below it will be automatically removed and overlapping
named fields will be highlighted, prompting her to take action. Enlarging the
value of a field beyond the range of the relation, as specified in “Range”, will
bring up a dialog asking her if she really wants to enlarge the relation.
Field name: This entry allows the user to assign a name to a field. This is
mostly useful in conjunction with the “Insert fields row/column” option,
and when using the alternate SQL syntax for writing clausal definitions (see
Sect. 9.2). Field names need to be unique within a relation, but not necessarily
across relations.
Add fields: This button adds a new blank field line in the “Fields” enclosure.
This is useful for extending the relation with a new attribute.
Delete marked fields: This button deletes the lines in the “Fields” enclosure
whose checkbox has been checked.
OK: If all the data in the dialog are correct, pressing this button will partition the
relation as specified in the “Fields” enclosure, define its name and the name of its
attributes, and possibly insert them in the title rows or columns. The visible result
of performing this action on the contents of Fig. 9.2 is displayed in Fig. 9.3. It will
also insert this relation in the defined predicates list, either by name or by range,
for future reference. If there is any problem or potential ambiguity, it will bring
up an error dialog explaining the issues. This will flag relation names already in
use, duplicate field names, overlapping field ranges, and inconsistencies between
the range of the relation and the cumulative range of its fields. The latter can be
resolved either by editing the field ranges in the “Define Relation . . . ” dialog, or
by instructing the system to adapt the geometry of the relation to that of its fields.
306 9 Toward a Deductive Interface
Cancel: This button restores the dialog to its status when the user first invoked it.
Help: This button invokes the help facilities.
We have described the “Define Relation . . . ” dialog as a means to making the
system aware of a new relation. This is not the only use of this dialog. It can indeed
be invoked on an existing table (in which case it reads “Redefine Relation . . . ”)
to modify any aspect of this relation, as defined in the fields in Fig. 9.2. This is
particularly useful for altering the geometry of a table, and managing the addition
or deletion of attributes. Doing so brings up some non-trivial issues that will be
discussed in detail in Sect. 9.4.
It should be observed that different relations may overlap, be contained in each
other, or even be defined over the exact same worksheet cell range. In the latter case,
only symbolic names will be able to distinguish them.
As a final note, we want to stress again that one can use the deductive spreadsheet
without ever invoking the “Define Relations . . . ”. Indeed, its main function is to
manage the complexity of working with relations by providing symbolic names
for them and their attributes. However, range coordinates can be used anywhere a
symbolic predicate (or attribute) name appears. Note also that the same symbolic
association described here can be performed by repeatedly invoking the standard
“Define Name . . . ” dialog seen in Chap. 7. What the “Define Relations . . . ” dialog
provides is a convenient way to make all these definitions in one place. By inserting
relation names in the defined predicates list, it also enables quick edits of clausal
definitions, as we will see in Sect. 9.3. For these reasons, it is expected that users
will make abundant use of this feature.
In the traditional spreadsheet, formulas tend to be rather simple. They usually con-
tain just a few operators and very rarely do they extend past the size of the formula
input textbox. When they do, the contents of this box scrolls, making the initial
portion of the formula invisible. It can be put back into focus by scrolling back to the
beginning using the cursor keys. In particular, a long formula does not wrap around
to the next line: few users know that pressing ALT-ENTER can produce a new line
on which to split their input. Using a single line makes writing and especially mod-
ifying long formulas difficult and error-prone as visibility is hindered. In practice,
this is a minor problem because, as we said, users tend to write rather short formulas.
The situation changes as soon as we start using the formula input textbox to
enter clausal subtheories. As we saw in Part I, a predicate definition can consist
of multiple clauses, and each clause can be a rather complex object as soon as its
body contains more than two or three literals or constraints. For this reason, we
believe it is necessary to facilitate the entry of multi-line contents (a set of clauses, a
traditional formula, or normal text) in the formula input textbox. In fact, we enrich
the formula bar with a syntactic editor that highlights keywords, provides visual
9.1 Deductive Layout 307
feedback, autoformats complex definitions, and monitors what the user writes in
real time, recognizing potential errors and suggesting corrections. We will comment
on these features over the next several sections.
In order to retain conservativity over the traditional spreadsheet, the formula
input textbox remains unchanged when the user starts entering text (again, not
necessarily a clause). As soon as she has filled more than a certain portion of
the available space (for example 30 characters or 50 % of the available space,
whichever is shorter), a “tip” appears instructing her to press the ALT-ENTER key
combination to produce a new line. This is illustrated on a possible extension of
the user interface of Microsoft Excel in the top part of Fig. 9.4. Of course, she can
ignore this suggestion and write text on this one line only. If she chooses to make
use of the second line, she will be able to press ALT-ENTER to create new lines
up to a predefined maximum number. Once she has reached this maximum, a scroll
bar appears allowing her to make all parts of the formula visible. She should also be
given the option to vertically enlarge the formula input box so that more is visible,
up to the height of the screen. This behavior is shown in the bottom part of Fig. 9.4.
While allowing clauses to be entered over multiple line is convenient, it leaves
the burden of managing their possible complexity on the user. For this reason, a
useful complement to this approach is to offer an autoformat option. Whenever
the formula input box consists of more than one line, a push-down button appears
allowing the user to enable or disable the autoformat facility. With this button
disabled (raised), the user would be totally responsible for any formatting of the
textbox. Whenever she pushes it down, the content of the textbox is reformatted
according to predefined heuristics. Figure 9.4 shows the autoformat button just
above the right scrollbar of the worksheet. A possible layout for an autoformatted
theory is shown in the bottom part of this figure. The dialog-assisted mechanism
outlined in Sect. 9.3 always relies on the autoformat facility. Even in this case, the
user should be able to alter the proposed formatting: the system should remember
her changes and limit autoformatting to new material she inputs. Of course, this
facility could be made available also for traditional formulas. Formula autoformat
is a property of individual cells or ranges and could be enabled or disable for each
single cell (or range). The default should be to have it enabled, but the user may
change this as a global preference.
Autoformat Button
propose to increase the first figure to 2 bytes, hence supporting worksheets with
65,536 columns: in A1 coordinates, columns would be designated with letter codes
from A to BQWP. We suspect that this will satisfy the needs of the vast majority
of users without imposing undue penalty on file size and processing time. If it
becomes apparent that there is substantial demand for even larger number of
columns, both column and row coordinates may be enlarged to fit 4 bytes, or a
more economical dynamic encoding could be used.
that it is expected that users will avail themselves of this option even more than
in the traditional spreadsheet as clausal definitions tend to be more complex than
typical scalar formulas. We will return to this point in Sect. 9.3.
Independently of how exactly clausal theories are expressed, our design will be
conservative over the traditional spreadsheet, so that a user who does not need to
use the deductive functionalities can still write her formulas as she has always done.
In particular, existing workbooks will be accepted by the deductive spreadsheet and
behave as in the application it was originally written in.1 Moreover, the syntax for
the deductive extensions shall be consistent with the current external language of
scalar formulas so that a user does not have to invest too much cognitive effort in
learning how to use the extension.
In Sect. 9.2.1 we define the syntax for base relations and predicate names, as
they will be input by the user. Section 9.2.2 proposes a concrete syntax for clausal
definitions of predicates, while Sect. 9.2.3 presents an alternative notation stemming
from relational algebra. We describe what to do in case the user enters a formula
containing a syntactic error in Sect. 9.2.4. Finally, we outline the mechanisms that
allow logical formulas to be embedded in a scalar or array expression, and vice
versa, in Sect. 9.2.5.
Both clauses and relational expressions are constructed by applying various kinds
of operators to similar atomic building blocks: predicates in the former case, base
relations in the latter. Since both notions identify the same regions of the worksheet,
we will rely on a single concrete syntax to denote them in larger expressions.
As we do so, two observations are in order: first, traditional spreadsheets do not
provide a specific syntax for denoting relational entities (for example data lists in
Excel) as they are manipulated through commands rather than operators; second,
arbitrary regions of the spreadsheet can currently be identified by means of range
such as “A1WB17” for a rectangular area, or “DWH ” for a cluster of columns, or
“A1WB17; DWH ” for non-contiguous regions. Prefixing the name of the workbook
with “Š” as a separator even allows regions to be contributed from other worksheets.
Symbolic names can be associated with each of these cases, hence enabling a more
clear and intuitive notation.
For the most part, ranges and range names are perfectly adequate for the purpose
of denoting a base relation or, equivalently, a predicate. A relation (or predicate)
is often unbounded, i.e., it extends all the way to the last row of the worksheet. If
it starts on the first row, the current notation, e.g., “DWH ”, is nicely succinct. If it
1
More precisely, a deductive extension based on Microsoft Excel 2013 will be able to load any
Excel 2013 file, for example. Spreadsheets written using earlier versions of Excel or different
applications may have to be imported, as currently done.
9.2 Textual Input of Clausal Theories 311
starts on a different row, 3 for example, one has to resort to writing “D3WH 65536”,
which is a lot less practical. Note again that this is rarely an issue in the traditional
spreadsheet as relations are not first-class objects and can only be manipulated using
commands. Similar considerations would apply to tables laid out along the rows of
the spreadsheet, a possibility that is not currently supported by any commercial
products.
Because predicates are first-class objects in the deductive spreadsheet and
because they can be unbounded either vertically or horizontally (or both), we need to
provide a succinct and natural notation to denote the bottom row and the rightmost
column. We propose to use “ ” as a marker for the last row or column in a worksheet.
Therefore, “A ” denotes the last cell on column A (currently “A65536”) while “ 3”
identifies the last cell on row 3 (currently “I V 3”). The cell at the very bottom and far
right is now “ ” rather than “I V 65536”. This device can naturally be incorporated
in the current syntax for cell ranges, so that “D3WH 65536” above is now written
“D3WH ”. Here are a few more examples of use of this notation:
• A5WC : all the cells in columns A; B; C below row 4.
• B3W 4: all the cells in rows 3 and 4 right of column B (included).
• B3W : all the cells in the worksheet right and below A2.
• H W : all the cells in the last row of the worksheet right of column G.
Entire columns are still denoted by omitting the row number, so that for example
“DWH ” abbreviates “D1WH 65536” or equivalently “D1WH ”
This notational device naturally extends to cell or range coordinates in R1C1
notation.
Besides providing a more convenient way of expressing unbounded relations,
this notation has the additional advantage that it is independent from the underlying
implementation of cell coordinates. For example, if an initial version of the
deductive spreadsheet with a maximum of 256 columns is replaced by a version that
supports 65,536 columns, a predicate denoted by the range “A3W 5” will still extend
till the last column of rows 3 through 5, while “A3WI V 5” will not take advantage of
the added space (and an automatic translation may not be what the user wants).
At this point, we can describe the grammatical rules that describe A1 cell and
range coordinates in the deductive spreadsheet:
where maxRow and maxCol are the maximum number of rows and columns respec-
tively, currently 65,536 and IV. The definition is similar for R1C1 coordinates. Note
that the only addition with respect to the traditional spreadsheet is the possibility of
a row or column coordinate being “_”.
312 9 Toward a Deductive Interface
As a final note, cells and cell ranges can be assigned a symbolic name, which we
will indicate as id, exactly as in the traditional spreadsheet. This name can be entered
in the relation definition dialog introduced in Sect. 9.1.1, or by means of any of the
currently available name definition tools (in Excel, the “Define name . . . ” menu
command or by writing this name in the leftmost textbox of the formula toolbar).
Therefore, a predicate name can be entered either as a range or as a range identifier:
We will now propose a concrete syntax for our deductive extension to the traditional
spreadsheet that closely tracks the way we have been writing clauses and theories.
In order to create a clausal definition, the user will select the cell range for its
head predicate and enter the corresponding expression in the formula input textbox
exactly as for a scalar formula. The syntax has been designed so that there is no
possible clash with either scalar or array formulas, and therefore there is no need to
type a special begin-of-clause marker or to enter a particular mode.
Before describing this concrete syntax, it is worth summarizing the (logical)
abstract syntax of the formulas of the deductive spreadsheet as we have encountered
it in Chap. 6. The top five definitions in Fig. 9.5 collect the core components:
theories, clauses, heads, bodies and predicates. Note that we have included a
production for embedded implications in the body of a clause and provided an
escape for abbreviations in the same context (the non-terminal A). The last two
definitions report the examples of abbreviated forms described in Chap. 6, with the
ellipsis suggesting that this list is extensible. Within this definition, we enclose
optional syntactic elements in square brackets, so that, for example, FINDMAX
may be immediately followed by a test, written Œ æ, and the variable it binds
can itself be followed by a test, Œ æ0 , or by a filter predicate, W P 0 (or both).
The non-terminal lmod describes list modifiers, another extensible set of optional
tokens that can specialize the behavior of abbreviations that return lists, such as
some versions of the transitive closure.
With this summary in place, our task simply consists of providing an adequate
concrete notation for each of these productions. We begin by defining a syntax for
variables, continue with the core language and the abbreviations, and conclude with
a description of how to enter, update and remove a clausal definition. We also digress
on the applicability of our approach to array formulas.
Variables
and
and
If arguments in different predicates are given the same name and are not equated
in a clause, they can be differentiated by prefixing the name of the predicate they
belong to, separated by a period, as in path.To.
• Advanced and logically inclined users can use any identifier they fancy as a
variable as long as it does not lead to syntactic ambiguity or confusion. Because
variables are universally quantified at the head of a clause and the arguments
of predicates are necessarily variables, few identifiers need to be ruled out as
ambiguous. Confusion is more likely, and for this reason, it may be good practice
to impose restrictions banning reserved keywords and cell and range coordinates.
We did not include “identifiers in use” in this list because disallowing them
has the disadvantage that a later definition of one of these names will require
action by the user, forcing her either to choose a different name, or to replace
every previous use of that identifier with a new variable name—this is a form
of premature commitment. The exact language of allowable variables will be
tailored on the basis of user testing and reported feedback. In the rest of this book,
we will follow the convention adopted by most logic programming languages and
only use identifiers beginning with an uppercase letter (or _) as variables. Then,
our ongoing example may become:
Note that each of these syntaxes is interchangeable, and that they may be mixed at
leisure.
Altogether, we obtain the following grammar for variables, where productions
are listed in the same order as the informal alternatives above.
9.2 Textual Input of Clausal Theories 315
Variables X WWD R
j id
j word beginning with a capital letter
Clauses
In the first line, an empty theory is the empty string (denoted by “ ”), while
the clause separator has been chosen to be a period. If this creates confusion,
an alternative keyword, such as ALSO, could be made available. The concrete
denotation of the reverse implication separating the head of a clause from its
body is the keyword IF. In the body of a clause, the abstract symbols : (negation),
^ (conjunction) and ! (embedded implication) are mapped to the keywords NOT,
AND, and ASSUMING, the latter with its arguments reversed. The fact that NOT
and AND are reserved keyword in the traditional spreadsheet (as Boolean condition
connectives) is unimportant as their meaning can be recovered from the context (and
the Boolean equivalents always take their arguments in parentheses). Constraints
are written similarly to their abstract syntax (see Sect. 9.2.3 for a more detailed
account of attribute expressions, æ). Body items can be grouped using parentheses.
Predicates start with a predicate name and list their arguments as a comma-separated
list of variables enclosed in parentheses.
In addition to cell ranges and symbolic identifiers, we will admit array formulas
enclosed between angled brackets as per the coercion introduced in Chap. 4.
Abbreviated Forms
We follow the same principle to provide a concrete syntax for the abbreviated forms
that can appear in the body of a clause. Indeed, we simply transliterate each of the
reserved identifiers in the bottom part of Fig. 9.5 into a keyword. We add the suffix
+ to a binary predicate to denote its point-to-point transitive closure, and append ++
to represent the version of its transitive closure that collects constructed paths into a
list. The concrete syntax for abbreviated forms is as follows:
Observe that many of these abbreviations have a syntax that is more reminiscent
of constraints than predicates. Unless this leads to confusion, this similarity is
unimportant as the dedicated keywords and constructions can always disambiguate
their use.
We will now describe the processes that allow a user to enter, modify and delete
a clausal definition in the deductive spreadsheet by means of the formula input
textbox.
The first step in creating a new clausal definition consists in selecting the range
where the output of this definition should be calculated. This can be done in several
manners:
• The easiest way to define a predicate that does not contain lists as arguments is
simply to select the target range with the mouse, type “=”, and start writing its
9.2 Textual Input of Clausal Theories 317
clauses in the formula input textbox. This method can still be used for predicates
with one or more lists as arguments, but then the variables corresponding to these
arguments will later have to be entered as ranges to prevent ambiguity.
• The preferred option is however to first identify the predicate and possibly its
fields by means of the relation definition dialog discussed in Sect. 9.1.1, select
it either from the list of defined predicates or using the mouse, enter “=”,
and then start typing a clause for it. Recall that a region of the worksheet
can be tagged as a predicate by simply selecting it, and right-clicking on the
“Define Relation . . . ” entry of the pull-down menu. The main advantage of this
approach is that it is not as error-prone as direct selection, especially because
the “Define Relation . . . ” dialog allows precisely identifying the arguments of a
predicate. It involves some premature commitment, but only minimally so since
the relation can be established just prior to typing its clausal definition. The
previous method is free from premature commitment.
Once the target range has been selected, the user can simply start entering clauses
in it. As for traditional formulas, the user types “=” to indicate that the contents of
this cell will be a formula. For aesthetic reasons, we may allow (but not require) the
user to prefix “=” to each of her clauses, not just the first one. For the time being, we
will only be concerned with purely textual input, but helpful graphical alternatives
will be discussed in Sect. 9.3. As illustrated in Sect. 9.1.2, the user can now enter a
definition over multiple lines. She moves to the next line by pressing ALT-ENTER
and can use the mouse or the direction keys to revisit other parts of the definition. As
a convenience, creating a new line after the end of a clause automatically proposes
its head predicate in preparation for extending its definition with a new clause. For
example, if the user types “=path(X, Z) IF edge(X, Z).ALT-ENTER”,
she will see
where “j” indicates the cursor position. She can always delete this clause fragment
if she only wanted an empty line, or she can modify it.
The clauses entered in a cell range must define the predicate corresponding to
this cell range. Therefore, range “C WD” in Fig. 9.4 needs to contain definitions
for the predicate internally identified as “C WD” (here designated as “path”). It is
conceivable however that this entry also contains definitions for auxiliary predicates
that are only used by the target predicate of this range (“path” here). The main
advantage of this permissiveness is that a smaller region of the worksheet would be
needed to define an important predicate, hence improving visibility. The possible
disadvantages are error-proneness, confusion, and difficulties in debugging a model
since intermediate results would not be readily visible. The merits of this possibility
need to be established on the basis of user response and testing. For the moment, we
are inclined to making it available as a “use-at-your-own-risk” feature intended for
advanced users.
318 9 Toward a Deductive Interface
Once the user is finished entering a clausal definition in a cell range, she simply
presses ENTER, just as in the scalar case, to install it in these cells. Two outcomes
are possible: if this definition contains errors, a dialog will appear instructing her
on how to correct them—errors and their prevention will be examined in detail in
Sect. 9.2.4; if it is correct, its evaluated records will appear in that space, starting
from the top row and extending toward the bottom in case of a vertical table, and
stretching left to right for a horizontally specified relation. Note that the entire region
will remain blank if the clauses contained in it are unsatisfiable.
As in the traditional spreadsheet, chances are very high that the user will need to
modify a clausal definition after she has entered it. Changes can target either the
clauses themselves, or the geometry of the target relation. We will now concentrate
on the first type of modification, delaying the examination of the second until
Sect. 9.4.
In order to modify a clausal definition, a user simply needs to select any cell in
the range that contains it and click on the formula input textbox. This has the effect
of selecting the whole target range. She can now make her changes to the clausal
definition using the same methods as when she initially created the formula. When
she is done, sealing the changes with the ENTER key will have them come into
effect for the entire target range of this definition.
A clausal definition can be deleted in two ways. First, the user can select the target
range, either with the mouse or by searching for its name, and press the DELETE
key. Second, she can click on any cell in this range, then go to the formula input
textbox, which will highlight the whole range, and delete the definitions it contains.
Cell ranges can support both clausal theories and array formulas. These two types
of calculated expressions differ by the operators that can appear in them, to the
point that no confusion is possible as to whether a user is typing one or the other.
Notice also that the proposed modalities for entering and modifying clauses are
more similar to the current methods for working with scalar formulas than to the
arcane procedure that permits inserting and altering array formulas.
The same principles underlying the proposed methods for working with clausal
theories can be immediately adapted to array formulas. In particular, an array
formula can be sealed by just pressing ENTER rather than the complex CTRL-
SHIFT-ENTER combination, both when it is created and when it is modified.
For this to be the case, the extension of an array formula could advantageously
9.2 Textual Input of Clausal Theories 319
be automatically selected whenever the user embarks in editing any of its cells.
Furthermore, we will see in Sect. 9.4 that our proposal for clausal theories supports
simple and intuitive methods for modifying the geometry of the underlying cell
range as well as copy-and-paste operations: again, they can immediately be ported
to array formulas.
While we believe our approach can beneficially improve the usability of array
formulas, it is not our intention to modify the current behavior of the traditional
spreadsheet. In particular, we will not make it available in the deductive spreadsheet
for array formulas unless it is adopted by spreadsheet application manufacturers at
large, as it would violate our vow to conservativity.
We now propose a second concrete syntax for the extended expressions inherent in
the deductive spreadsheet. This time, we will adopt relational algebra as our model,
and provide a language that closely resembles its SQL incarnation [O’N94]. Before
doing so, we recall the abstract syntax of core relational algebra in the following
table, reported with minor changes from Chap. 4:
Note that we did not include the equational support for recursion discussed
in Chap. 6, nor an escape for abbreviated forms, the equivalent of embedded
implication, or lists of values. While these extensions can easily be accommodated,
massaging the abstract syntax to take them into account would be a nearly useless
exercise as SQL does not closely follow the grammatical guidelines of relational
algebra. Instead, we will incorporate them directly in the proposed concrete syntax.
We begin by extending the denotation of relations introduced in Sect. 9.2.2 to
express attributes. We then recall the syntax of core SQL, and extend it to account
for our abbreviated forms. We conclude with a description of how to enter SQL-like
expressions in the deductive spreadsheet. This discussion will build heavily on the
conventions and techniques discussed in the previous section.
Attributes
Attributes are identifiers for the fields of a relations (sometimes the two terms are
used interchangeably). They are similar to logical variables, except that they cannot
320 9 Toward a Deductive Interface
be renamed at will: their name is fixed. For us, a field is a region of the worksheet,
and more precisely a subrange of a relations that extends all the way vertically (if the
relation is columnar) or horizontally (otherwise). Therefore, in its simplest instance,
an attribute is a cell range. If the relation has been baptized using the “Define
Relation . . . ” dialog, its fields could have been given symbolic names as well. In
this case, attributes can be identified using these names. Recall however that fields
in different relations can have the same name. Whenever two such relations are used
together and there is a risk of ambiguity, a symbolic attribute name can be prefixed
by its relation’s name, with a period in between. Altogether, an attribute, denoted by
the non-terminal a, is given by the following syntax:
The SQL syntax of the core relational calculus introduced in Chap. 4 is given by the
following grammar:
Here, p stands for a base relational expression, which shares the same syntax as
predicate names discussed in Sect. 9.2.2: it can be a cell range, an identifier, or an
array expression enclosed in angle brackets. The keywords UNION and MINUS are
concrete syntax for the union and difference operators of relational algebra. The
form “SELECT æ1 ; : : : ; æn FROM p1 ; : : : ; pm WHERE C ”, a trademark of SQL,
corresponds to the projection over attribute expressions æ1 ; : : : ; æn of the Cartesian
product of relations p1 ; : : : ; pm mediated by the selection over condition C . The
projection attributes æ1 ; : : : ; æn can be replaced with the symbol “*” if all exported
fields are to be made available without any processing. The selection condition C
and the keyword WHERE can be omitted if vacuous. Note that this expression is more
restrictive than general relational algebra as it forces projections and selections to be
taken over base predicates (p1 ; : : : ; pm above). This is remedied by allowing nested
SELECT statements in the condition C , introduced by the form æ IN R. Besides
this, selection conditions have the same form as in Chap. 4, and similarly for the
attribute expressions they depend on.
It should be noted that SQL is a lot richer than the simple fragment discussed
so far. Some additional constructs will support aspects of the abbreviated forms
9.2 Textual Input of Clausal Theories 321
Abbreviated Forms
Differently from the logical syntax of Sect. 9.2.2, SQL natively embeds many
of the abbreviations introduced in Chap. 6. Moreover, rather than factoring them
neatly as a single grammatical extension, they are deeply interwoven in the fabric
of the core syntax of SQL. The resulting language is given by the following
grammar, where the extensions are marked by triangles on the right-hand side of
each affected line:
which closely corresponded to the logical syntax, where the host range corresponded
to the head of the contained clauses (except for possible auxiliary clauses).
In the SQL denotation, we follow a different approach: we omit the left-hand
side of the equation as it corresponds to the cell range hosting this expression. Note
that the recursive use to path does refer to precisely this cell range. Therefore, the
SQL rendering of this expression is as follows:
to be located in the cell range identified as path for this expression to be correct.
Note that the omission of the equational prefix path = is similar in spirit to the
fact that scalar (and array) formulas keep the location into which they are entered
implicit. Observe also that this choice prevents using named auxiliary definitions,
although they can be anonymously entered by means of the IN form of a condition.
Users make errors in the traditional spreadsheet, and there is no reason to expect
that this will change in the deductive spreadsheet. In this section we will concern
ourselves with the simple syntactic errors that can be caught by a good parser. Other
types of errors are more serious and harder to debug [BG87, Pan98]. We will come
back to them in Sect. 9.5.
Commercial spreadsheets have two ways to handle parsing errors in an input
formula. Simple mistakes, for example forgetting to close a parenthesis, are
corrected automatically without bothering the user (in some cases). Situations where
9.2 Textual Input of Clausal Theories 323
half of Fig. 9.7, she would be greeted by the dialog box in the bottom half. Observe
that, differently from Fig. 9.6, this dialog is extremely focused.
So far, our discussion of the concrete syntax of the deductive spreadsheet has
concentrated on the notation of clausal definitions as the user would enter them in
the formula input textbox. One of the requirements of Chap. 2 was however that the
deductive functionalities be seamlessly integrated into the traditional infrastructure,
and vice versa. In Chap. 4, we abstractly achieved this effect by providing two
coercions to move between the functional world of the traditional spreadsheet
and the logical (then relational) world of our extension. An array (or even scalar)
expression Ee was promoted to relational status by enclosing it in angled brackets,
as in hEe i, and dually a relational expression eN could be interpreted as an array (or
scalar) formula by putting square brackets around it, obtaining Œe. N We also added
9.3 Graphical Construction of Clausal Theories 325
some new array operators such as SORT and various order-conscious variants of
relational algebra operations (we called them “pseudo-relational”).
We will now promote these formal devices to concrete syntax. In particular,
given the concrete denotation of a clausal theory (or relational expression), we
write [ ] for its coercion into an array (or scalar) expression. We have used
this operator several times in Chaps. 4 and 5 as it extends the expressiveness of
clausal definitions by taking advantage of the functional infrastructure. Recall that
the order of tuples resulting from evaluating [ ] can be arbitrary. If we are
interested in sorting them according to some of the fields a1 ; : : : ; ai , we would write
SORT [ ] BY a1 ; : : : ; ai , where the new operator SORT. . . BY implements the
SORT operation of Chap. 4. Note that this operator can be applied to any array, not
just those obtained by coercing a relational expression. Similar syntax is provided
to represent the pseudo-relational operators.
We have already encountered the syntax <Ee>, which allows us to use an array
(or scalar) expression Ee as a predicate (or a base relation). We do not expect
this operator to be as frequently used as the reverse coercion, in the same way
as the mechanism for constructing arrays out of scalars rarely appear in actual
spreadsheets.
In the traditional spreadsheet, a user can enter the name of a function and then
use the mouse to select its arguments. We saw several examples in Chap. 7. We
will now propose a series of mouse-assisted techniques that will allow constructing
simple clausal theories with no need to use the keyboard except for marking the end
of a clause. More complex clauses, especially those making use of abbreviations,
will benefit from this approach, as it will reduce the amount of typing to just their
keywords and punctuation. Section 9.3.2 will present graphical methods to handle
them as well.
Simple clauses such as the ones encountered in Chap. 5 and in the earlier sections
of Chap. 6 are essentially a sequence of literals and constraints with some variables
identified. They can be completely built with the mouse as soon as we devise
methods for selecting predicates and constraints, and for identifying variables.
We will describe such methods in the remainder of this section.
Selecting Predicates
Recall that one of the effects of using the “Define Relation . . . ” dialog on a cell
selection was to enter its range or the associated symbolic name in the defined
predicates list. Once the “=” sign has been entered in the formula input textbox,
the predicates appearing in this list are available for immediate insertion, as long as
the parser determines that we are in the process of entering a clause as opposed to a
scalar or array formula.
We will illustrate how this can be done by entering the second clause of our path
example, partially displayed in Fig. 9.7. We assume that regions AWB and C WD have
been defined as the binary relations edge and path, respectively. Other relations
may have been registered, but this will be of no concern to us. Assume also that the
first clause for path has already been entered.
With the cursor after the period terminating this clause, right-clicking and
choosing the “Insert Predicate” entry makes the defined predicates list available as a
scrollable submenu as illustrated in the top part of Fig. 9.8. All entries but “path”
are grayed out because we are expected to enter the head of a clause and the selected
region has been associated with the predicate identifier “path”. Had we wanted to
enter an auxiliary predicate, we would have to type its name and arguments. As
soon as the mouse moves over the “path” entry of the defined predicates list, the
corresponding region of the worksheet is outlined. Clicking on it installs the head
=path(X,Z)
in the formula input box. The variable names X and Z are copied from the head of
the first clause and the user can rename them later if she is so inclined. They are
highlighted in red since they are unsafe up to this point. The result can be seen in the
bottom part of Fig. 9.8, ignoring for the moment the menu. The cursor is positioned
9.3 Graphical Construction of Clausal Theories 327
after the newly inserted text. Note that, because there is already a clause for path,
this text could also have been copied by simply pressing ALT-ENTER. Had we used
this method to enter the first clause of this definition, its head arguments would that
been the automatically generated variable names Var1 and Var2, which the user
could later rename.
At this point, the operation can be repeated to insert the first body literal,
which will be the recursive call to path. The bottom part of Fig. 9.8 displays the
result of choosing the “Insert Predicate” submenu. Note that all the entries in the
defined predicates list are now available. The cross to the left of each predicate
allows inserting its negation. It is grayed out for path because of the stratifiability
restrictions of Chap. 6. Clicking on the “path” entry inserts the line:
IF path(Var1,Var2)
328 9 Toward a Deductive Interface
as shown in the upper part of Fig. 9.9. The variable Var1 and Var2 are automati-
cally inserted. Notice that they are different from X and Z since the system has no
way of knowing how they should be related. The possible need for user intervention
is indicated by highlighting them in blue.
The process is repeated for the last line of this definition. Notice that columns
AWB are outlined when the mouse moves over the “edge” entry of the defined
predicates list. The following line is inserted:
AND edge(Var3,Var4)
as shown in Fig. 9.9. Typing a period will signal that this clause has been completed.
9.3 Graphical Construction of Clausal Theories 329
Identifying Variables
The resulting clause is shown in the bottom part of Fig. 9.9. Clearly this is not
what we want since all variables are different. In order to identify two variables,
for example X and Var1, we simply drag X onto Var1. The cursor changes shape
as we do so. Both instances of X will become black as the one in the head is not
unsafe any more and the user has paid attention to the first blue variable in the first
body literal. We can similarly drag Z onto Var4, and Var2 over Var3, which will
again have the effect of making them black. The latter operation will result in both
body literals sharing the variable Var2. Had we wanted to supply another name,
for example “Y”, we would have needed to rename Var2 before dragging it onto
Var3. We can also rename both instances after the fact.
By the end of this simple process, we have produced the desired clause, by using
the mouse exclusively, except for the period that signals the end of the clause. The
process can now be repeated with a third clause for path if we had one in mind.
Observe that we could have started renaming and identifying variables as we were
inserting literals.
Inserting Constraints
We will now extend this basic process with a mouse-oriented technique borrowed
from [SBB96] for conveniently inserting constraints. We will illustrate it again on
our ongoing example, but we modify it somewhat to make it more interesting.
Assume that edge describes direct flights between airports, so that path corresponds
to an air itinerary. We enter the three-letter code of the origin and destination airport
of each direct flight in columns AWB, the result of which is partially visible in
Fig. 9.10. As we do so, a small upside-down triangle appears next to the field names
330 9 Toward a Deductive Interface
of edge whenever we are in formula input mode. Clicking on this triangle reveals a
pull-down menu with all the entries in this field, sorted alphabetically and with any
duplicate removed. This appears on the left-hand side of Fig. 9.10.
Assume that we are only interested in itineraries that do not transit through LAX.
Then, we simply need to modify the definition of path so that the intermediate
variable Y of the second clause of Fig. 9.9 is different from the text string “LAX”.
Logically this is achieved by simply adding the constraint Y ¤ LAX’.
This can be realized in several ways in the formula input textbox. Clearly, one
can always type this constraint, which is rendered as “Y<>"LAX"” in the concrete
syntax of our language. Another possibility is to drag the variable Y past the last
literal (or between any conjunct in the body), type “<>”, move the mouse over to
one of the fields of edge and select “LAX” from the pull-down menu, as shown in
Fig. 9.10. It will be sufficient to seal the clause with a period.
An alternative way to insert this constraint would begin by clicking on an
occurrence of the variable “Y” in the clause and selecting “LAX” from the pull-down
menu (or clicking on it if it appeared in the formula input textbox). This will install
the line
AND Y = "LAX"
Complex Clauses
Consider first the problem of entering a clause from scratch. Rather than starting
to type in the formula input textbox, the user can press the fx button, which will
show the catalog displayed in the upper part of Fig. 9.11. Note that the traditional
left pane of this dialog has been extended with one new entry, “Insert a new
clause . . . ”. Clicking on it reveals the commentary at the bottom of this window,
but no function name appears on the right pane. Pressing “OK” will propose a blank
version of the dialog shown in the bottom part of this figure. If the user has already
entered a complete clause in the formula input textbox, pressing the fx button will
bring up the clause definition dialog directly since this context expects a clause and
not a traditional function. This dialog can also be triggered by entering “=” in the
formula input textbox and clicking on “Insert clause” on the simplified function
selection menu that now appears at the far left of the formula bar.
The clause definition dialog, which has been modeled after the function input dialog
of commercial spreadsheets discussed in Chap. 7, is shown in the bottom half of
Fig. 9.11. It as been partially filled as per the example in Fig. 9.10. Note that,
following the conventions of Sect. 9.3.1, variable “Z” is highlighted in red since
it is not safe, and variable “Var4” is colored in blue to suggest that the user may
want to make some changes to it.
The top text field is intended for the head of the clause and will generally have
automatically been filled, although the user can always make changes. The fields
in the “Body” enclosure are where she will specify each conjunct in the body.
Predicates and constraints are entered either using the keyboards or by means of
the graphical methods discussed in Sect. 9.3.1: in particular right-clicking brings up
the defined predicates list, constraints can be entered by clicking, and variables are
identified by dragging them over other variables. Additionally, the button labeled
fx on the right of each input field allows accessing the library of abbreviated forms,
which will be examined shortly. It can also be used to enter embedded traditional
formulas in a clause. New conjunct fields are automatically proposed once text is
entered in the last blank row, which is the way traditional multi-argument functions
such as SUM behave in dialog-assisted input mode.
Navigating among the various fields specializes the explanation at the bottom
of the windows. Clicking on any of the highlighted keywords will invoke targeted
help facilities. General help can be accessed by depressing the “Help” button, while
“Example” will display a simple example. Hovering over a portion of text marked
in red will bring up a callout describing the error, similarly to Fig. 9.7. Once the user
has finished entering a clause, pressing “OK” will validate it as if she had entered
it in the formula input textbox and pressed ENTER (see Sect. 9.2). Before doing so,
she can check the “Define another clause” checkbox to be brought back to an empty
clause definition dialog when she is done.
332 9 Toward a Deductive Interface
In the situation described by the bottom half of Fig. 9.10, assume the user wants to
specify that she only is interested in changing planes in airports such that every
outbound direct flight has a corresponding inbound direct flight from the same
city. At the logical level, this is achieved by adding the conjunct FORALL V W
edge.Y; V /: edge.V; Y /. Because of the presence of the abbreviated form FORALL,
this goes beyond what we could do so far with the mouse. It is however possible to
bring up a wizard that can help the user construct this formula step by step. In
order to access it, she simply needs to move the cursor to a blank field (as shown in
Fig. 9.10) and click on the fx button on the right-hand side of this field.
This brings up the function catalog as shown in the top part of Fig. 9.12. Notice
that it differs in several ways from what we saw in Fig. 9.10: the item “Insert new
clause . . . ” has been replaced with a proper category “Deductive”, and the right pane
lists all the available abbreviations. Notice also that all traditional functionalities are
grayed out since they cannot be entered where a body conjunct is expected. Had
we been in a scalar or array context (for example within a constraint), “Deductive”
would be disabled while all the traditional functions would be available.
Clicking on “FORALL” invokes the wizard shown at the bottom of Fig. 9.12,
which the user would fill similarly to the clause definition dialog examined earlier.
“FORALL” is particularly simple since it does not have the optional parts of other
abbreviated forms. Note also that none of the fields contains the fx button since
neither variables nor predicates can make use of any of the functionalities provided
by this dialog. Other body objects, for example embedded implication (ASSUMING
in our concrete syntax), would have this button for some of their arguments.
contained predicates. Once she has selected one of the modalities, she can also check
an option making this choice a default for future paste actions.
Because symbolic predicate names are meant to be unique, pasting a relation to
a new place forces us to remove the name from the copy. The names of its fields
will remain unchanged, and the relation as a whole will be entered in the defined
predicates list, but the user needs to explicitly enter a new name if she wants to refer
to it symbolically.
9.4 Updates
In this section, we examine the effect of a variety of common actions that the user
may perform to modify the layout of a relational entity. In particular, we discuss how
the system should behave when she alters the geometry of a relation in Sect. 9.4.1.
The consequences of inserting or deleting rows or columns across relations are
investigated in Sect. 9.4.2.
In the second part of this section, we look at update propagation and introduce
some new options the user can avail herself of for the purpose of controlling it. This
will be the subject of Sect. 9.4.3.
We begin with an investigation of what should happen when the user alters the length
of a relation, i.e., the number of records it can contain. Before describing the effect
of such a modification, we discuss the means she has at her disposal to trigger it in
the first place.
The most general way to change the length (and indeed all geometric aspects)
of a relation is to invoke the “Define Relation . . . ” dialog examined in Sect. 9.1.1
and alter its vertical extension. As the user modifies the length portion of the
“Range” text box, the common length of all of its fields are adjusted automatically
to match the height of the relation. She could similarly modify its starting row. In
336 9 Toward a Deductive Interface
order to invoke the “Define Relation . . . ” dialog for an existing relation, the user
simply needs to right-click on one of its cells and select the menu option that reads
“Redefine Relation . . . ”. If this cell belongs to more than one relation, a submenu
will appear from which she will be able to choose which of the intersecting relations
she wants to modify. This is shown in Fig. 9.13.
The height of a relation can also be modified more conveniently by using the
mouse. If the relation is not unbounded, one can select it, go to its last row and drag
the black rectangle at its bottom right corner to the desired row position. This is
practical only for small changes in height. Of course, this is particularly impractical
if one wants to make this relation unbounded. In that case, right-clicking on the
black rectangle will produce a menu with an option reading “Extend Relation To
Last Row”: selecting it will make the table unbounded. If instead the relation is
unbounded, right-clicking on any of its cells will produce the menu item “Shrink
Relation”. Selecting it will reduce the length of this relation to its last non-blank
record. If more than one unbounded relation overlaps this particular cell, the user
will have the possibility of choosing on which of them to operate by means of a
submenu. This menu item is shown in Fig. 9.13.
9.4 Updates 337
The user has now modified the height of a relation. The effect of this action
depends on whether this table was clausally defined or just identified some area of
the worksheet as a predicate, possibly used in a clause elsewhere.
In the first case, there will simply be a different amount of space to store the com-
puted records. Recall from Part I that the evaluation result of a relational expression
or clausal definition will start inserting tuples from the top of the target area down
(for a vertical table, left-to-right if it is horizontal). If this space is too small, some
records will not show (the output is truncated). If it is too large, the unused area will
be left blank. This is consistent with how traditional array formulas operate.
If the modified region did not contain a clausal definition, it will simply
encompass a different amount of data. This means that clauses that referred to this
relation as a predicate may be working with either more or fewer data tuples.
necessarily be unsafe and hence require user intervention in order to restore the
validity of this definition. A fresh variable will also appear in every clause in which
this predicate is used. This is inconsequential in the case of positive literals, but
again leads to loss of safety for negative literals. We therefore see that inserting a
new field has the potential of triggering a series of corrective actions by the user.
This leads to an increase of viscosity, although this appears to be necessary in order
to preserve the overall consistency of a deductive spreadsheet (where this word is
not used as a cognitive dimension).
Removing a field leads to similar concerns. The deletion of a head variable has
no consequence, but removing a variable in a positive body literal containing this
predicate may have the effect of making other occurrences unsafe and therefore may
require action by the user.
9.5 Debugging
The deductive spreadsheet must clearly extend all of these debugging modalities
to the added functionalities it embodies. In the proposed design, the one exception
to this rule concerns the clause definition dialog discussed in Sect. 9.3.2, for which
it is not clear how to provide usable feedback for intermediate values. The graphical
formula entry modalities described in Sect. 9.3 also help create formulas that are
correct on the first try, at least as far as cell references are concerned.
Clausally defined relations introduce a new debugging challenge as they do not
fall into existing patterns. As repeatedly observed in Part I, highlighting relational or
attribute-level dependencies is often of limited use because the typical questions that
a user will want to ask are “Why was this tuple returned?” and “Why was this tuple
not returned?”. What should be tracked is the process that leads to the inclusion
or exclusion of this particular tuple. We developed the technology to answer these
questions in Chaps. 5 and 6: top-down evaluation. We will not weave it into the
interface of the deductive spreadsheet.
We will first discuss positive explanation, i.e., the answer to the question “Why
was this tuple returned?”. The easiest way for the user to ask it is to select a suspect
record from a calculated clausal definition, and right-click on the “Explain . . . ” item,
as shown in Fig. 9.15 in the case of why .JFK; LAX/ is in the relation path. The
342 9 Toward a Deductive Interface
explanation facilities can also be invoked from the menu bar, even if no record
is selected (this is useful when one wants to ask negative questions or to issue a
one-time query). Additionally, it is possible to invoke the explanation dialog with
partial records (the omitted parts will be replaced by variables) and on several
records at once (all of them will be explained).
The explanation dialog is shown in Fig. 9.16. The textbox at the top displays the
tuple that has been selected as a query. The user can modify it to inquire about other
tuples. Indeed, we have replaced the constant “LAX” with the variable “Z” for the
sake of illustration. The left-hand side of the central part shows a derivation tree
for this query, displayed as a series of layered subgoals in a way reminiscent of
a directory browsing dialog. The node at the very top of this pane represents one
instance of the query. Other instances can be selected by clicking on the downward
triangle next to it: in this simple example, the other possibilities for the second
argument are “BWI”, “SFO”, “MSY”, “IAD”, “EWR”, and “VCE”.
The rest of this pane shows one derivation tree for the goal path("JFK",
"LAX"). Clicking on this node brings up one of the clause instances that make
it derivable on the right pane of the dialog. Positive literals are shown in different
colors, and the actual tuples are highlighted using the same color in the worksheet.
The user can request that they be brought into focus by double-clicking on them,
hence increasing visibility. These subgoals also appear on the left pane together with
their own subderivations, aligned and connected to path("JFK","LAX"). The
user can ask to see other clause instances that satisfy this goal by using the two small
black triangles on each side of the edge that extends out of it. In this case, there is
one additional possibility: taking a direct flight from “JFK” to “LAX”, which is not
displayed. The first subgoal, path("JFK","SFO") is also defined clausally and
clicking on it brings up the instantiated clause that derives it. The second subgoal,
edge("SFO","LAX"), is instead a fact. Clicking on it will simply show a color-
coded reference to the spreadsheet. In more complex examples, subderivations can
be rather large, and therefore we provide the ability to collapse them using the gray
9.6 Productivity Tools 343
triangles on the clause instance edges. Moreover, the user may want to compare
clause instances for several subgoals of a derivation. This can be done by dragging
the tabs on the right pane of the window.
Constraints are not directly represented in the derivation tree, but can be
inspected on the right pane. Any cell reference they may contain will appear in color
and the corresponding cell will be highlighted using the same color. Traditional
auditing mechanisms can be invoked if there is any reason to suspect an error in
this reference. Abbreviated forms are displayed on the derivation tree and clicking
on them will bring up dedicated explanation dialogs. Negative literals possibly
appearing in a clause will be discussed shortly.
Since the user can write any body formula in the “Query” text fields, she may
construct relations that she actually wants to save. Checking the box labeled “Save
query as relation” will prompt her to choose a target for the newly constructed
clause, to which she can assign a named predicate.
Answering a negative explanation request, “Why was this tuple not returned?”,
is more complicated as we need to “show” the user the non-existence of a record or
record template. She can enter such a request in the query box of the explanation
dialog, or it can emerge in the derivation of a positive literal. A non-derivable
goal is displayed in a grayed-out slanted font in the derivation pane. If it is a
factual predicate instance p.Ev/, it will not have any descendant and clicking on
it will display the note “No record .Ev/ in relation p” in the right-hand pane, with
a color-coded association to the extension of p in the spreadsheet. If instead it is
clausally defined, the body of one of its clauses will be displayed: its literals will be
instantiated to the extent to which the head is, and the ones that are derivable will
show a derivation below them. The user shall be able to instantiate the remaining
variables, which will have the effect of marking one or more of the remaining literals
as non-provable. She will then be able to repeat the process on one or more of them
until she is convinced of the non-derivability of the original goal.
the distance of each segment, as we had done in Chap. 6, we can use the distances as
labels for these arrows. Figure 9.17 shows a dialog for building such a connection
graph, and overlays it with an identical graph that only shows segments whose
distance is greater than 2,500 miles (those arrows are rendered in red in a color
version of this book). If the user wanted to see the cumulative distance of entire
itineraries, she may add a new query referring to path rather than edge.
Another potential accompanying tool for the deductive spreadsheet is a flow
graph generator. There, the input would be a recursive query returning a list, such as
what we used to describe the work-flow problem in Chap. 6, and the output would
align the elements of this list over all possible answers and possibly annotate them
with measures of time, cost, or effort.
The problem of visualizing tabular data, highlighting their dependencies, has
received a lot of attention in the literature, especially since the advent of the World-
Wide Web. Some of these visualization and query techniques, for example the
methods described in [SBB96], could conveniently be imported in the deductive
spreadsheet. A more detailed investigation is beyond the scope of this book.
to also offer the unpopular ClipIt office assistant). It allows searching help topics by
entering a few keywords, by using an alphabetic index, and by browsing categories
as they would be organized in a book. Help can be sought online through links to the
manufacturer’s website. On a smaller scale, just hovering the cursor over a button
shows a descriptive note explaining its function.
The deductive spreadsheet shall not only retain these various help modalities,
but include dedicated topics referring to the various extensions it offers over the
traditional spreadsheet. We have already seen throughout this chapter that the design
of the various dialogs and other facilities already contains buttons and links to the
help infrastructure.
9.8 Summary
In this chapter, we have presented a detailed tentative design touching the major
aspects of the user interface of the deductive spreadsheet. We have engineered it
as a conservative extension of the user interface of the traditional spreadsheet, and
indeed many of the illustrations have been grafted on top of screenshots of Microsoft
Excel 2003. The main effect of this conservative approach is that a user who is not
interested in the deductive extension may hardly notice the presence of the half
a dozen new commands sprinkled here and there, often within context-sensitive
right-click menus. A user who does want to avail herself of this far-reaching
extension can do so in a natural way, often by a simple mouse click. Clausal
definitions can be constructed using traditional methods such as by entering them in
the formula input textbox, by selecting arguments with the mouse and by invoking
dedicated dialogs. We proposed further extensions to ease the fact that clausal
definitions are often more complex than an average scalar or array formula. In order
to accommodate users with different backgrounds, we suggested providing two
input languages for logical formulas, one that transliterates the clausal definitions we
have used in Chaps. 5 and 6, and a relational one based on the SQL database query
language. We have enriched the auditing toolkit of the traditional spreadsheet with
convenient graphical ways to inquire about the derivability, or non-derivability, of a
record, and in general of an arbitrary clause body. We have also proposed extensions
to the array of productivity tools in order to tap into the new opportunities offered
by the deductive infrastructure.
Major and minor decisions concerning the design of the user interface of the
deductive spreadsheet have been guided by the desire to remain conservative with
respect to the traditional interface and by the cognitive principles discussed in
Chap. 8. In particular, we often framed decisions points in terms of the attention
investment model and dissected the merits of different options by bouncing
appropriate cognitive dimensions around. Ultimately, the wisdom of the tentative
choices we made will be decided by the end users of this technology through testing
and other feedback. A very preliminary effort in this direction is indeed the subject
of Chap. 10.
346 9 Toward a Deductive Interface
With this design for the deductive spreadsheet user interface in hand, we will
now review our achievement against the cognitive requirements stated in Chap. 2.
This design appears to meet or exceed each of these requirements:
Cognitive Conservativity All traditional functionalities are accessible to the user
in the exact same way as in a traditional spreadsheet. The deductive interface is
indeed conservative and unobtrusive to the point that the extensions are hardly
noticeable until she starts working with the deductive spreadsheet.
Consistency The commands supporting the deductive extensions are consistent
with the existing modalities of interaction. Indeed, the user can enter clausal
definitions using the keyboard or by means of intuitive mouse commands akin
to what she is used to for traditional formulas. Additionally, enhanced input
modalities have been made available.
Cognitive Integration Using the deductive interface additions is expected to be
natural and intuitive, including in conjunction with the traditional functionalities.
Deductive and traditional operations are fully integrated and accessible by means
of consistent commands.
Performance While the performance of the deductive spreadsheet, as experi-
enced by the user, cannot be assessed until a prototype has been developed,
preliminary experiments are encouraging. See Chap. 11 for details.
Discovery The deductive extension is expected to have a gentle learning curve,
so that users can reinforce and extend their skills by simply using the tool and
minimal experimentation. Commands operating on the deductive extension are
clearly marked and generally accessible by a single mouse click. Error messages
are generally more informative than in traditional spreadsheet implementations,
and help facilities are extended to cover every aspect of the deductive extension.
Clearly, the last two items in this list need to be established experimentally on the
basis of user testing and reported feedback.
Chapter 10
Preliminary Experiments
Our experiment consisted of three phases. We first asked our volunteers about their
backgrounds using spreadsheets in order to determine their skill levels. We then
illustrated the key concepts behind the deductive spreadsheet, mostly on the basis
of motivational material taken from Chap. 1 and by means of a simple example.
In this phase, we asked our volunteers about their experience using spreadsheets.
Its purpose was to classify them according to their skills in order to correlate the
collected results of our experiment with user segments.
The specific questions we asked include:
• For how long have you been using spreadsheets?
• How frequently do you use them now?
• Which applications do you use most?
• Do you use them for work?
• What do you use spreadsheets for?
• Which of the following activities have you performed with a spreadsheet?
1. Manage lists?
2. Perform simple calculations? (arithmetic operations, use SUM over a single
worksheet)
3. Perform complex calculations? (use complex functions, array expressions,
nested formulas, multiple worksheets)
4. Define symbolic names?
5. Work with data lists, data forms, database functions?
6. Use data tables, goal seeking, pivot tables?
7. Program new functionalities? (using Visual Basic for Applications, for
example)
• What would you like a spreadsheet to include that is not already there?
We mostly used the items under “Which of the following activities have you
performed with a spreadsheet?” to classify users in the following categories:
Beginners whose experience is mostly limited to 1 and 2.
Intermediate users who have also used 3 and maybe 4.
Advanced users who have taken advantage of 5 and 6.
Spreadsheet programmers who have done 7.
The exact form we used is shown in Fig. 10.2.
The outcome of this phase is summarized in Sect. 10.2 where we introduce our
volunteers and their backgrounds, and classify them on the basis of their skills.
10.1 Outline of the Experiment 349
In this phase, we gave our motivations for extending the traditional spreadsheet
with functionalities supporting deductive reasoning. We also outlined our approach
to incorporating deductive facilities in the spreadsheet, namely the use of clausal
statements over relational data, and illustrated it with a simple example. We also
collected feedback about our overall approach. User interface issues were not
addressed.
The purpose of this phase was to test the reaction of our volunteers to the very
idea of a deductive extension to the spreadsheet, to understand if they needed
anything like this, and to comment on our approach to realizing this objective as
described in the body of this book.
We will now go over each of the individual aspects of this phase of the protocol:
motivation, example and feedback collection. The exact phrasing of our explana-
tions and questions was tuned to the background information collected in Sect . 10.2.
We first provided motivations for the very idea of a deductive extension to the
traditional spreadsheet. We observed that current applications provide outstanding
support for working with numerical data and making decisions based on them.
However, a large percentage of the decisions we make every day depend on informa-
tion that is not numerical, or not only numerical. Therefore, it is not always possible
or obvious how to use a spreadsheet, or any office automation tool, to help making
these decisions. We illustrated this point by presenting the following example, which
is inspired by material we have repeatedly examined in Chaps. 6 and 9:
Is there a direct flight from New Orleans to Venice? To where can I fly directly from New
Orleans? Is it possible to fly from New Orleans to Venice? What is the minimum number
of connections? What would be the itinerary? How many frequent flyer miles would I
accumulate? Would it help if I waited until the new direct flight from Atlanta to Venice
starts?
We asked each volunteer if he or she knew how to model the overall problem in the
traditional spreadsheet and how to have a spreadsheet answer these questions.
Example
We then went on describing how the deductive spreadsheet could help answer these
questions. We mentioned that the origin and destination airport of each direct flight,
together with the number of miles they are apart, could be organized in the table
shown in Fig. 10.1. We then illustrated the following solutions to each of the above
questions.
• Is there a direct flight from New Orleans to Venice? This question can be
answered by simply inspecting the relation directFlight, or by using any
350 10 Preliminary Experiments
standard filter function on data lists. The airport codes for New Orleans and
Venice are MSY and VCE, respectively.
• Where can I fly directly from New Orleans? We answer this question by simply
collecting all the destinations of a directFlight record with MSY as its
origin:
fromMSY(To) IF directFlight(From,To,_)
AND From="MSY".
indirect(From,To) IF directFlight(From,To,_).
indirect(From,To) IF directFlight(From,Mid,_)
AND indirect(Mid,To).
and looking for an entry that relates New Orleans (MSY) and Venice (VCE). This
can also be abbreviated as:
indirect(From,To) IF directFlight+(From,To,_).
10.1 Outline of the Experiment 351
indirect(From,To,N) IF directFlight(From,To,_)
AND N = 0.
indirect(From,To,N) IF directFlight(From,Mid,_)
AND indirect(Mid,To,N’)
AND N=N’+1.
The entry with the minimum number of connections between New Orleans (MSY)
and Venice (VCE) can be found by inspecting the result of this definition and
picking the smallest value of the third argument for these airports. Since there
may be several entries for them, it can be refined by entering the following clause:
minConnections(From,To,Min)
IF Min = FINDMIN N. indirect(From,To,N).
If only the entries for MSY and VCE are of interest, it can further be specialized
as follows:
minConnections(From,To,Min)
IF Min = FINDMIN N. indirect(From,To,N)
AND From="MSY" AND To="VCE".
• What would be the itinerary? We extend the last definition for indirect by
accumulating the origin and intermediate airports into a list “Itin” as follows:
indirect(From,To,Itin,N) IF directFlight(From,To,_)
AND Itin = [From]
AND N = 0.
indirect(From,To,Itin,N) IF directFlight(From,Mid,_)
AND indirect(Mid,To,Itin’,N’)
AND Itin = Itin’ | [Mid]
AND N = N’+1.
Then, we select the result with the minimum number of connections and extend
it with the destination:
shortestItinerary(From,To,Itin)
IF _ = FINDMIN N. indirect(From,To,Itin’, N)
AND Itin = Itin’ | [To].
352 10 Preliminary Experiments
which we could further specialize to MSY and VCE as above, if desired. The
object “Itin” is a list containing all the airports visited in the shortest itinerary.
Using abbreviations, this same set of clauses could be more succinctly
entered as:
shortestItinerary(From,To,Itin)
IF N = COUNT.
Itin = directFlight++(From,To,_)
AND minConnections(From,To,N).
• How many frequent flyer miles would I accumulate? We can add up the distance
flown during a multi-segment itinerary by entering
indirect(From,To,D) IF directFlight(From,To,D).
indirect(From,To,D’’) IF directFlight(From,Mid,D)
AND indirect(Mid,To,D’)
AND D’’=D+D’.
shortestItinerary(From,To,Itin)
IF N = COUNT.
Itin = directFlight++(From,To,_)
AND minConnections(From,To,N)
ASSUMING directFlight("ATL","VCE",4900).
Feedback
Once we had described our example and gone through its solution, and sometimes
concurrently with this, we showed the volunteers a series of 12 snapshots of
our proposed user interface adapted from Chap. 9. Nine of them are reported in
Figs. 10.4 through 10.7 at the end of this chapter; in addition, we showed them
snapshots corresponding to Figs. 9.15–9.17. We asked for feedback and collected
their impressions about what they saw.
In this section, we provide a brief description of the background and skill level of
the users who gracefully accepted to participate in this experiment. We also report
on what they said they would like to see as additional functionalities or features in
a spreadsheet. In order to safeguard their privacy, we will refer to them by means of
randomly assigned first names.
Ben was a postdoctoral fellow at a renowned university, where he specialized
in theoretical computer science. He had used a proprietary spreadsheet program
(not Excel) some 15 years before our conversation and hardly touched any such
applications ever since. Back then, he managed and printed lists, and performed
simple calculations. By itself, this would lead us to classify him as a beginner.
However, his deep knowledge of programming languages and logic set him in
a category apart: he had a perfect understanding of the technology and could
easily make sense of our EXTENSION, but the practical aspect of working with
a spreadsheet was missing.
He could not think of a desired extension of the traditional spreadsheet when
asked.
Catherine was an analyst in a large consulting firm. She used Excel and small
spreadsheet applications embedded in statistical programs on a daily basis for
her work. She occasionally used Excel at home for budgets, lists, etc. She is an
advanced user: she worked with large formulas and used complex statistical func-
tionalities such as regressions almost every day. She also frequently performed
what-if analyses using pivot tables.
When asked what she would like to see in a spreadsheet, she mentioned the
integration of database functionalities without the complication of working
WITH a database.
Geraldyn was a department administrator at a renowned university. She had been
using Microsoft Excel, and before that Lotus 1-2-3, on a daily basis for nearly
20 years. She used it to keep track of finances, expenditures, budgets, grades, and
occasionally to type up lists. She routinely wrote complex formulas and used data
forms and database functionalities. She had not had any use for the support for
354 10 Preliminary Experiments
She could not think of new features she would like a spreadsheet to contain.
Altogether, these volunteers cover a sizable segment of the user base of the
traditional spreadsheet. The one category we were not able to cover in our informal
survey is that of spreadsheet programmers, who are comfortable with using tools
such as Visual Basic for Applications for extending the core functionalities of a
spreadsheet.
We will now report on the sometimes surprising results of our interviews. Alto-
gether, responses suggested that all users, even beginners, long for the ability to use
spreadsheets as small homegrown databases. More precisely, they expressed interest
in full relational query capabilities within the familiar spreadsheet environment, not
as a separate application, and especially of tabular views of data where changes are
automatically propagated. Our design has catered to this need as early as Chaps. 4
and 5. Interest in and understanding of the more advanced features of our proposal,
most of which were outlined in Chap. 6, varied with user sophistication. Beginners
did not seem to care much for them. Advanced users immediately pointed to
problems to which they could be applied.
The opinions that our volunteers expressed about the user interface proposed
in Chap. 9 also tracked user sophistication. Advanced users immediately felt
comfortable with the choices we made. In contrast, beginners had issues with basic
decisions such as the wording of menu items. All classes of users complimented
us for the explanation facilities and the possibility of displaying our tables as
a connection graph. Interestingly, none of our users were moved by the clause
definition dialog, which stems from the fact that they declared never to use wizards
in general.
We will now examine the reactions gathered for each individual class of users,
starting with advanced and intermediate users, who were our target audience.
Our representative advanced users, Catherine, Geraldyn and Ian, took great interest
in the added functionalities of the deductive spreadsheet. At several points during the
interview, they pointed to some feature or other that would help them solve current
problems and pointed to new applications of the technology. Both Catherine and
Ian declared that they would make heavy use of the deductive functionalities if they
were available in a commercial spreadsheet. They found recursion interesting, but
the high point was the possibility of writing relational expressions to use Excel as if
it were a database, with immediate visual feedback and without the heavy overhead
356 10 Preliminary Experiments
Our two intermediate users, Linda and Rich, were equally interested in the
extension. Linda immediately pointed to scheduling tasks such as meeting planning
and complex travel arrangements as uses she could make of the technology. Rich
saw applications in lean manufacturing processes, military logistics, and high-level
decision making in general. He said that he would probably use it if it were part of
Excel, but may not purchase it as a standalone application. Linda left us with the
same impression.
Both liked the user interface, but Rich and to a lesser extent Linda had some
problems with the choice of keywords. They suggested rewriting menus and dialogs
using less technical wording. Both appreciated the explanation and the connection
graph. Linda took great interest in the latter as a simple and intuitive scheduling
tool, and found it to provide better debugging than our explanation mechanism.
These responses are again mostly in line with our expectations. We found it
revealing that users in this class were at odds with our choice of text for menu items
and dialogs. This made us realize that users will not experiment with functionalities
if the commands to invoke them are labeled with words they do not understand.
10.3.3 Beginners
Our beginner users were Ben, Julia and Sarah. Because of his uncommon back-
ground, we will report on Ben’s comments separately.
Julia and Sarah clearly understood and manifested appreciation for the objective
of the deductive spreadsheet, but had difficulties comprehending the low-level
realization of these objectives. They had a hard time gaining an intuition about
what clauses do, their format, and the meaning of the keywords. Sarah suggested,
for example, replacing IF with BECAUSE. Both had issues with the choice of
wording used in menus and dialogs, for example “predicate”, “relation” and even
10.4 Summary 357
“clause” meant nothing to them: they referred to them as jargon and found them
not to be user-friendly. Sarah said she could not think of an immediate use for the
deductive extensions, but anticipated using some of the basic relational features if
it were made available within Excel in a user-friendly fashion. On the other hand,
Julia strongly appreciated the fact that the deductive spreadsheet offers a simple
way for non-specialists to use a spreadsheet as if it were a simple database. She
suggested a number of uses for it, both professionally and outside of work, if only
the interface to issuing queries were more user-friendly. In that respect, she was
extremely interested in the relational aspect of it, with the deductive part as a nice
curiosity.
Both expressed a rather negative view of the user interface. As we said, they
found it counterintuitive and would probably never use the added functionalities
because the wording of commands was a barrier to accessing them. On the other
hand, they both liked the possibility of building connection graphs and were curious
about the explanation facility.
Ben, the theoretical computer science expert, was extremely interested in the
technical aspects of the deductive spreadsheet, but mostly as an academic problem.
He could easily understand the technical explanation. His feedback about the
deductive spreadsheet as a user application meant to solve actual problems was
much more limited. He expressed some concern that it may involve concepts that
are too hard for beginners.
The responses gathered from this class of users came to us as a total surprise.
As they fell outside of our target audience, we expected a lack of appreciation
and even understanding for the problems we were trying to tackle and for their
solutions. Instead, these users expressed great interest in the simplest instances of
these problems, namely relational inference, and manifested almost eagerness for
simple tools to help solve them. They were very critical of the interface we provided
for this purpose, but pressed for simple, easy-to-use wizards or other mechanisms
that would allow them to build and display the results of queries on tabular data.
10.4 Summary
Our target audience, as defined in Chap. 8, comprised only advanced and inter-
mediate users. The feedback by volunteers from these classes matched expectations,
which suggests that we may have achieved the cognitive objectives stated in Chap. 2.
We write “may” because more rigorous and extensive experiments are required for
an accurate evaluation of this proposal.
Beginners were not part of our target audience, and yet they pressed for being
included as the beneficiaries of this technology. They demanded adjustments to the
user interface that would not discourage them from taking advantage of relational
queries. They also expressed interest in a set of intuitive tools that allowed them,
the unsophisticated beginners, to perform simple manipulations of tabular data
in unintimidating ways. Said differently, they wanted to be able to define useful
relational queries, without the jargon and technical mindset that our proposed
interface currently provides.
While we believe we have accomplished our goals with respect to advanced
and intermediate users, we see the keen interest of beginners for what the core
technology of the deductive spreadsheet can deliver as an unexpected niche. We
intend to improve the design of our user interface to answer their call and provide
them with intuitive tools to take advantage of basic but useful aspects of our solution.
We also intend to build on the numerous improvements suggested by the advanced
and especially intermediate users.
10.4 Summary 359
Questionnaire
– Manage lists?
– Perform simple calculations? (arithmetic operations, use SUM over a single work-
sheet)
– Perform complex calculations? (use complex functions, array expressions, nested for-
mulas, multiple worksheets)
– Program new functionalities? (using Visual Basic for Applications, for example)
• What would you like a spreadsheet to include that is not already there?
Example
fromMSY(To) IF directFlight(From,To,_)
AND From="MSY".
indirect(From,To) IF directFlight(From,To,_).
indirect(From,To) IF directFlight(From,Mid,_)
AND indirect(Mid,To).
Abbreviated as:
indirect(From,To) IF directFlight+(From,To,_).
indirect(From,To,0) IF directFlight(From,To,_).
indirect(From,To,N) IF directFlight(From,Mid,_)
AND indirect(Mid,To,N’)
AND N=N’+1.
shortestItinerary(From,To,Itin) IF N = COUNT.
Itin = directFlight++(From,To,_)
AND minConnections(From,To,N).
indirect(From,To,D) IF directFlight(From,To,D).
indirect(From,To,D’’) IF directFlight(From,Mid,D)
AND indirect(Mid,To,D’) AND D’’=D+D’.
• Would it help if I waited until the new direct flight from Atlanta to Venice starts?
shortestItinerary(From,To,Itin) IF N = COUNT.
Itin = directFlight++(From,To,_)
AND minConnections(From,To,N)
ASSUMING directFlight("ATL","VCE",4900).
Figures 9.11, 9.15, 9.16 and 9.17, on pages 332, 341, 342 and 344, respectively,
were also used.
Chapter 11
Future Developments
In this book, we have proposed a design for the deductive spreadsheet, an innovative
extension of traditional spreadsheet applications such as Microsoft Excel and
Google Spreadsheet with support for symbolic reasoning and deductive decision
making. The requirements for this tool have been set forth in Chap. 2. We have
designed the deductive apparatus underlying this logical extension in Part I of this
book, while the extension of the user interface and other cognitive issues have been
the subject of Part II.
With the bulk of the design, both functional and cognitive, behind us, we
dedicate this final chapter to outlining the next steps for the deductive spreadsheet.
The project is indeed continuing into an implementation and evaluation phase.
Accordingly, we discuss prototyping strategies and preliminary experiments in
Sect. 11.1, and we examine approaches for assessing the usability of our current
design in Sect. 11.2. We dedicate the rest of this chapter to open issues in the
current design and to opportunities for further extensions. Specifically, we look
at developments aimed at further extending the expressiveness of the deductive
spreadsheet in Sect. 11.3 and at its interface in Sect. 11.4. Both aspects will be
partially informed by the results of usability analysis.
11.1 Prototyping
11.1.1 Strategies
this sort may be a moving target as patches and new versions are periodically
released.
An orthogonal dimension to the selection of an implementation strategy involves
the choice of the platform. Traditionally, spreadsheet applications have been made
available as standalone programs to be installed on one’s computer. Classical
examples are Excel, LibreOffice and Numbers. For some of them, matching the
underlying operating system is an additional choice point. Recently, the trend has
however moved to providing spreadsheets and other traditional office utilities as rich
Web applications, downloaded to the browser each time the user opens a document.
Google Spreadsheet is the dominant example.
11.1.2 Pre-prototyping
Over the last 2 years, we experimented with some of these options for implementing
a prototype of the deductive spreadsheet. We initially opted for extending an existing
commercial spreadsheet application rather than developing a prototype from scratch
to retain layout and feature familiarity during user testing. We experimented with
three major commercial spreadsheet applications: Microsoft Excel, OpenOffice
Calc and Google Spreadsheets.
In a first phase, we looked into exploiting approach (1) above, the add-on mech-
anism, to implement some of the core functionalities of our design. Specifically,
we developed a fully functional but unoptimized evaluation procedure for deductive
formulas within Microsoft Excel 2007 using Visual Basic for Applications (VBA).
It implemented the semi-naı̈ve strategy discussed in Sect. 6.2.2 on top of some
basic data structures to support fast joins. This reassured us about performance
worries: this unoptimized code could compute the join of two relations with 10,000
entries, each in under half a second on a commodity laptop.1 These results can
easily be replicated in any spreadsheet application that supports programmatic
extensions using add-ons (e.g., LibreOffice Calc and Google Spreadsheets). Further
performance gains can be achieved through standard logic programming and
database optimizations [CGT90, RSS92].
The second phase of this experiment focused on the user interface, with an
example task of embedding a syntactic editor within the formula bar. This proved
to be a lot more complex. We soon realized that the APIs provided within many
spreadsheet applications to manipulate interface elements via add-ons are too high-
level for our needs. For example, neither Microsoft nor OpenOffice nor Google
provides API functions that allow touching the text entered in the formula bar
of their respective spreadsheet applications—consequently we could not highlight
1
It featured a 2.33 GHz Intel Core Duo processor and 2 GB of RAM.
368 11 Future Developments
keywords, for example. For this reason, we began experimenting with modifying
the source code of OpenOffice Calc and Google Spreadsheets directly (this is not an
option for Excel since it is closed-source). This is approach (3) above.
Modifying the source code of OpenOffice is theoretically straightforward, once
we have gained a good understanding of what it does. This latter task is extremely
time consuming however, as Calc is a very large piece of software (its source code
has about two million lines of code) with lots of functionalities (and just a few
comments in the code)—for example, we kept finding more and more places in
the source code that manipulate the formula bar. In spite of good communications
with the developers, we eventually gave up on our attempt at extending Calc with a
syntactic editor.
Modifying the source code for Google Spreadsheets was a totally different
challenge because this is not a standalone application: it is shipped to the browser as
JavaScript code every time a user loads Google Spreadsheets. We used the Grease
Monkey extension to the Firefox browser to modify the code on the fly once it
reaches the browser but before it is rendered. Google Spreadsheets contains few
essential functionalities, which makes its code lightweight (244 Kb). However the
JavaScript code is “minimized” (compacted) to ensure fast downloads: for example,
comments and all unnecessary white spaces are removed and mnemonic identifiers
are replaced with automatically generated strings of minimal length. Needless to
say, this complicates understanding the code, even though it has a much smaller
footprint than Calc, for example. Because of this, we eventually abandoned our
attempt to integrate a syntactic editor in Google Spreadsheet as well.
Most recently, we selected a Web-based plug-in freely available on the
Internet and started modifying its source code to incorporate basic deductive
functionalities—another instance of approach (3) above. This proved straightfor-
ward as the source code is both readable (not minimized) and relatively small. This
makes it unlikely to encounter any hurdles in implementing more functionalities of
the deductive spreadsheet, whether in the inference engine or in the interface. One
drawback is however that a limited subset of the standard spreadsheet functionalities
are supported, which forces us to implement some ourselves and to do without
others. Another drawback is that the downloaded code does not incorporate many
of the optimizations found in more polished products.
Altogether, this exercise proved useful in informing a prototyping strategy for
the deductive spreadsheet. Building on a fully fledged product, which has the
advantage of already supporting all the functionalities users are accustomed to, is
an appealing but complex option: the provided add-on mechanisms do not go to
a sufficiently low level for our needs and the code is too complex when publicly
available. Instead, working with experimental open-source code bases appears to
be a promising approach for an initial prototyping effort. Developing a deductive
spreadsheet application from scratch (approach (2) above) does not seem to be an
effective strategy in the prototyping phase.
11.2 Experimental Assessment 369
this question. These tests will include problems of growing complexity, where
complexity is measured in two ways: working from small to large tables (especially
tables that are larger than the screen), and using a combination of relational
or deductive mechanisms, first in isolation, and then in combination. Users will
eventually be asked to solve scenarios as complex as those exemplified in Chap. 10.
In all cases, it will be interesting to observe the cognitive pathways that lead a user
to forming the plan to solve a problem. They will also be interesting to monitor
how much resistance users put to using deductive mechanism, i.e., by trying to use
conventional operators to achieve the same result. This will allow us to gauge how
easy it is for different classes of users to grasp the added expressive power of the
deductive extension.
While the interface mechanisms for performing deductive reasoning are meant
to be unobtrusive and easy to use, it is important to assess how users are reacting
to individual design choices. One that we have mentioned earlier is the syntax for
inputting deductive formulas, which will be the subject of numerous scenarios.
Such tests will measure indicators such as the error rate, the number of incorrect
attempts, the time between attempts and the overall time to solve a problem. It will
also look for patterns in failed attempts. Other input modalities listed in Chap. 9
will be assessed as well, in particular the mouse-driven clausal input, wizards, the
use of cut-and-paste, and the drag-and-drop approach discussed in Sect. 9.3. For
some of these, we are interested not only in the difficulties that a user encounters
when relying on them, but also in whether they are used at all. A final object of
usability assessment is the explanation facility and the deductive productivity tools.
It should be observed that the gesture-based formula construction modalities and
the relational explanation facilities are new in the spreadsheet context and their
assessment is therefore of intrinsic scientific interest.
Usability inspection results are greatly influenced by the skill level and expe-
rience the participants have with respect to the traditional spreadsheet paradigm.
In a usability study for the deductive extension explored here, it is important to
include subjects with a diverse set of backgrounds to evaluate the different parts
of the design. Dividing users into the four classes listed in Chap. 10 (beginners,
intermediate users, advanced users, and programmers) seems an adequate first step.
Although this book has covered a large portion of the logical design of the
deductive spreadsheet, several technical challenges remain. These are engineering
and sometimes scientific quests that have not been explored yet or not at the scale
needed in an implementation of the deductive spreadsheet. We will examine some
of them in this section and also look at possible functional extensions of our design.
11.3 Functional Extensions 371
A key requirement for the deductive spreadsheet, listed in Chap. 2, is that its
performance not be overwhelmingly worse than that of a traditional spreadsheet.
This is a challenge as relational manipulations inherently operate on larger amounts
of data than typical arithmetic calculations. In Chaps. 4 and 5, we enrolled the semi-
naı̈ve strategy and a variety of graph-based data structures to achieve this effect.
While the preliminary experiments mentioned in Sect. 11.1 are encouraging, there
is room for significant performance gains by developing specialized methods. One
such method is the judicious use of indexing and other memoizing data structures.
We are unaware of attempts to specialize these techniques to a context similar to
ours. Another such method is compiling deductive formulas to gain in efficiency.
Compilation of logic programs is not new but has mostly focused on Prolog-
style top-down evaluation [Cer12], with relatively little attention dedicated to pure
bottom-up strategies [RSS92].
As mentioned in Sect. 5.6 and elsewhere, efficient techniques for propagating
positive updates (as when asserting a new base fact) have received a lot of attention
in the Datalog literature [CGT90,RSS92,GKB87]. By contrast, extending the semi-
naı̈ve evaluation strategy to support efficient propagation of negative updates (as
when the user deletes or modifies a record, or when propagating a positive update
through a negation) has only recently started to garner interest [NJLS11, LC12].
It is an open challenge to adapt these approaches to make them effective at the
scale needed for the deductive spreadsheet and to optimize them for the underlying
spreadsheet infrastructure.
We mentioned in Sect. 6.2.4 that well-behaved top-down evaluation strategies
(e.g., [War98]) can be advantageously used as an explanation mechanism for
bottom-up evaluation, which lies at the core of the deductive spreadsheet. Nobody
has done it before, however. Although few hurdles are expected, making all the
details work is likely to bring fresh scientific insight that could benefit the fields of
logic programming and databases.
Calculated values significantly extend Datalog’s expressive power, but raise the
possibility of non-termination. In Sect. 6.3, we showed an approach to support this
extension in the deductive spreadsheet through bounded recursion, a simple but
rather limiting solution. In many cases, termination can be determined through cycle
detection and other heuristics. Identifying useful problem classes where this can be
done efficiently in the spreadsheet context would shift some of the programming
burden from the user to the machine and permit flagging errors early. As mentioned
at the end of that section, term irrelevance is also a promising technology.
11.3.2 Extensions
The core logic underlying our design of the deductive spreadsheet has been
extensively studied in the past, although some of the functional extensions proposed
372 11 Future Developments
in this book are novel. As we saw, its good computational properties make it a
reasonable initial target language for the purpose of supporting symbolic reasoning
within a spreadsheet.
Assuming that our design successfully passes the empirical test in Sect. 11.2, a
number of linguistic extensions seem natural next steps. We now review some of
them:
• While termination is important for the average user, expert reasoners may want to
avail themselves of the deductive power of a fragment of first-order logic more
expressive than Datalog. Some variant of Prolog is a natural candidate for this
purpose. Because of the concrete risk of non-termination, this possible extension
would be made available on a use-at-your-own-risk manner or through add-ons.
Since bottom-up evaluation is almost invariably non-terminating on a Prolog
program, top-down search would need to be supported for formulas relying on
this larger language, although we may then want to look for a variant that is more
forgiving than the strategy commonly implemented in Prolog.
• If this extension were to successfully meet the needs of a sufficient user segment,
we may try to include an even larger fragment of first-order logic. This would
however most likely require equipping the tool with some form of theorem-
proving capabilities beyond bottom-up and top-down evaluation. A particularly
interesting instance of this goal could involve the integration of domain-specific
constraint solvers.
• Datalog and even Prolog account for only a very narrow slice of the logical
spectrum. Over the years, many logics with excellent expressiveness and com-
putational properties have been proposed. For example, linear logic can handle
resources, modal logic deals with necessity, temporal logic reasons with time,
etc. Once a solid base for the deductive spreadsheet has been established, it may
prove useful to provide support for some of these advanced languages, again
possibly in the form of add-ons.
Although the user interface of the deductive spreadsheet was designed on the
basis of well-established methodologies [GP96, Bla02], it too has several remaining
challenges, of a cognitive nature this time. Exploring ways to address them is likely
to lead to new scientific insight. We will now list some of them, concluding with a
few other suggestions for extending the interface of the deductive spreadsheet.
One open cognitive issue has to do with the syntax of deductive formulas as it
appears in the formula bar—in the examples in Chap. 9, we used a variant of
11.4 Interface Extensions 373
Datalog’s clausal syntax and a dialect of SQL. The syntax of traditional spreadsheet
formulas, although rather inflexible, has very simple ingredients: values, cells and
operations. Although it is known to be extremely error-prone [EB02, Pan98], users
seem comfortable working with it, at least for simple formulas. By contrast, the
informal experiments reported in Chap. 10 (and a few others) have hinted at the
possibility that a Datalog-style clausal syntax may belong to a different cognitive
level: understanding what clauses are and how they are constructed was not immedi-
ate for some classes of users—variables seemed particularly troublesome. The SQL
syntax appears to be equally taxing on users. Usability tests will reveal whether
this cognitive dissonance can be attributed to the novelty of the concept, or if there
is indeed something deeper. This would call for exploring alternative syntactic
means to describe logical specifications. Although, a better choice of keywords
and a more intuitive clause structure may help somewhat, we have however higher
expectations about replacing clausal forms altogether with alternative languages
of equivalent expressive power. XcelLog’s variable-free approach to specifying
deductive formulas is particularly intriguing [RRW06, RRW07]. Complementing
textual syntax with simple intuitive visual methods to building formulas (that go
beyond what traditional spreadsheets make available) is also worth exploring. Some
results from visual programming hold promises [APRS96], as do gesture-based
approaches available in products such as Microsoft Access.
Another cognitively challenging issue involves complex logical patterns. Datalog
clauses have very simple logical ingredients, most prominently conjunctions and
negation, which can however be combined in complex ways. Differently from
traditional formulas, some recurrent reasoning patterns have an inherently complex
form in Datalog: for example, an extensional universal quantification requires two
nested negations and an auxiliary clause. Users tend to find this indirection and
polarity switch hard to formulate and hard to explain [WJL72,SSFd00]. Quantitative
user testing can help identify the most common patterns that users find cognitively
taxing, suggest intuitive syntactic shortcuts, and assess their effects on users’ ability
to perform tasks.
A third open issue concerns helping users discover and explore the deductive
extensions in an unobtrusive way. Indeed, a person who wants to use the deductive
spreadsheet as a traditional spreadsheet should not be penalized, cognitively or
otherwise, by the presence of the relational infrastructure. Yet, if this user could
benefit from the deductive capabilities, she should be able to find and experiment
with them easily. Traditional spreadsheets have a mixed record on this issue: users
find some functionalities (e.g., charts) very easy to discover while others (e.g., pivot
tables) require more of an introduction. Devising the best way to help users discover
our extensions is more an art than a science, and why some functionalities are harder
to embrace than others is not well understood.
374 11 Future Developments
11.4.2 Extensions
[ABW87] Apt, K. R., Blair, H. A., & Walker, A. (1987). Towards a theory of declarative knowl-
edge. In J. Minker (Ed.), Foundations of deductive databases and logic programming [Min87]
(pp. 89–148). Los Altos: Morgan Kaufmann.
[And92] Andreoli, J. -M. (1992). Logic programming with focusing proofs in linear logic. Journal
of Logic and Computation, 2(3), 297–347.
This paper is the first systematic investigation of focusing, a proof technique that
underlies much of the recent research in logic programming. Focusing relies on the
observation that, when in a proof, some steps can be permuted without affecting the
ability to complete the proof. Focusing systematically delays some steps while eagerly
carrying out others, which results in a very efficient strategy.
[AOTC 03] Arni, F., Ong, K., Tsur, S., Wang, H., & Zaniolo, C. (2003). The deductive database
system LDL++. Theory and Practice of Logic Programming, 1, 61–94.
[APRS96] Agustı́, J., Puigsegur, J., Robertson, D., & Schorlemmer, M. (1996). Visual logic
programming through set inclusion and chaining. In CADE-13 workshop on visual reasoning,
New Brunswick.
This paper presents the design of a visual logic programming language that supports
visual representation and visual reasoning in a declarative way.
[ARLGC 09] Ashley-Rollman, M. P., Lee, P., Goldstein, S. C., Pillai, P., & Campbell, J. D.
(2009). A language for large ensembles of independently executing nodes. In Proceedings of
ICLP’09, Pasadena (Lecture notes in computer science, Vol. 5649, pp. 265–280). Springer.
[AvE82] Apt, K. R., & van Emden, M. H. (1982). Contributions to the theory of logic
programming. Journal of the ACM, 29(3), 841–862.
This paper develops the characterization of the model semantics of logic programs
consisting of Horn clauses (i.e., pure Prolog) as the least fixpoint of a continuous
operator. It also observes that some forms of finite-failure (but not all) correspond
to its greatest fixpoint.
[BABC 00] Boehm, B. W., Abts, C., Brown, A. W., Chulani, S., Horowitz, E., Madachy, R.,
Reifer, D., Clark, B. K., & Steece, B. (2000). Software cost estimation with COCOMO II.
Upper Saddle River: Prentice Hall.
This book describes the COCOMO framework for accurately estimating software cost
and schedules, and for supporting trade-off, risk, sensitivity, and business case analyses
for software decisions. It expands older versions of COCOMO to today’s software
engineering approaches, which are more evolutionary, risk-driven and collaborative,
and less focused on developing systems from the scratch.
[BADC 01] Burnett, M., Atwood, J., Djang, R. W., Reichwein, J., Gottfried, H., & Yang, S. (2001).
Forms/3: A first-order visual language to explore the boundaries of the spreadsheet paradigm.
Journal of functional programming, 11(2), 155–206.
[BB02] Blackwell, A., & Burnett, M. (2002). Applying attention investment to end-user-
programming. In IEEE conference on human-centric computing languages and environments,
Arlington (pp. 28–30). IEEE Computer Society.
This paper describes uses of the attention investment model within the Forms/3
spreadsheet system [BADC 01], finding it a useful design tool for the development
of end-user programming features.
[BBCC 01] Blackwell, A. F., Britton, C., Cox, A., Green, T. R. G., Gurr, C. A., Kadoda, G. F.,
Kutar, M., Loomes, M., Nehaniv, C. L., Petre, M., Roast, C., Roes, C., Wong, A., & Young,
R. M. (2001). Cognitive dimensions of notations: Design tools for cognitive technology. In
M. Beynon, C. L. Nehaniv, & K. Dautenhahn (Eds.), Cognitive technology 2001, Coventry
(Lecture notes in artificial intelligence, Vol. 2117, pp. 325–341). Springer
This paper looks back at developments and applications of the cognitive dimensions
of notation methodology in the ten years since it was first proposed. At the time it
was written, it had become a fairly established methodology to assist the designers of
notational systems, whether graphical or not, evaluate their design with respect to the
impact they will have on users.
[BDM01] Bozzano, M., Delzanno, G., & Martelli, M. (2001). An effective bottom-up semantics
for first order linear logic programs. In Proceedings of FLOPS 2001, Tokyo, Japan (Lecture
notes in computer science, Vol. 2024, pp. 138–152). Springer
Annotated Bibliography 377
[BG87] Brown, P., & Gould, J. (1987). Experimental study of people creating spreadsheets. ACM
Transactions on Office Information Systems, 5, 258–272.
In this early study of how people use spreadsheets, the authors monitored nine
experienced users building three predefined spreadsheets. They found that nearly half
of the spreadsheets they wrote contained errors. They also found that very little time
was dedicated to planning or to debugging.
[BG99] Blackwell, A., & Green, T. (1999). Investment of attention as an analytic approach to
cognitive dimensions. In Collected papers of the 11th annual workshop of the psychology of
programming interest group – PPIG-11, Leeds (pp. 24–35).
This paper takes a critical look at the cognitive dimensions of notations methodology.
It does not dispute its effectiveness but attempts a disciplined, scientific categorization
of the original and subsequently proposed cognitive dimensions.
[BG03] Blackwell, A., & Green, T. (2003). Notational systems – the cognitive dimensions of
notations framework. In J. M. Carroll (Ed.), HCI models, theories and frameworks: Towards
an interdisciplinary science. San Francisco: Morgan Kaufmann.
[Bla00] Blackwell, A. (2000). Dealing with new cognitive dimensions. In Workshop on cognitive
dimensions: Strengthening the cognitive dimensions research community.
This paper is concerned with the process of determining what new dimensions
should be included in the cognitive dimensions of notation framework. It does so
by recounting conversations with that method’s creator, Thomas Green, and explores
ideas for developing a methodology for evaluating candidate dimensions.
[Bla02] Blackwell, A. (2002). First steps in programming: A rationale for attention investment
models. In Conference on human-centric computing languages and environments, Arlington
(pp. 2–10). IEEE Computer Society.
This is the original paper on the attention investment model. It focuses on the initial
attitude of non-professional end-users when given tasks that have a programming
component (e.g., writing spreadsheet formulas or programming a VCR). In particular,
the attention investment model examines the first steps these users take and tries to
understand their actions based on task and system at hand.
[BM90] Bonner, A. J., & McCarty, L. T. (1990). Adding negation-as-failure to intuitionistic logic
programming. In Proceedings of the North American conference on logic programming –
NACLP’90, Austin (pp. 681–703). MIT.
This paper studies the model semantics of the Datalog-like language with embedded
clauses proposed in [BMV89]. One of the key devices is to port the classically defined
notion of perfect model to intuitionistic logic. Doing so retains the good properties of
the perfect model while accommodating embedded clauses.
378 Annotated Bibliography
[BMV89] Bonner, A. J., McCarty, L. T., & Vadaparty, K. (1989). Expressing database queries with
intuitionistic logic. In Proceedings of the North American conference on logic programming –
NACLP’89, Cleveland (pp. 831–850). MIT.
This paper is an early, and very thorough, proposal for extending a bottom-up Datalog-
like logic programming language with embedded clauses (embedded implications with
locally scoped universal quantifiers). While similar efforts were well-underway at
the time for top-down logic programming (see [Mil89] for example), this study is a
remarkable attempt at pushing the boundaries of deductive databases.
[Bon91] Bonner, A. J. (1991). Hypothetical reasoning in deductive databases. PhD thesis, Rutgers
University.
This website is about the ideas that led to the development of the first spreadsheet
application, VisiCalc, and about the people who were involved. It is a fascinating
collection of anecdotes, photographs, and early programs.
[CARGC 12] Cruz, F., Ashley-Rollman, M. P., Goldstein, S. C., Rocha, R., & Pfenning, F. (2012).
Bottom-up logic programming for multicores. In V. S. Costa (Ed.), Proceedings of 7th
international workshop on declarative aspects and applications of multicore programming –
DAMP’12, Philadelphia.
This paper applies ideas explored in [ARLGC 09] to the problem of executing
traditional algorithms in a multi-core setting. This is the first attempt at using a
Datalog-like language for this purpose.
[CC00] Chen, Y., & Chan, H. C. (2000). Visual checking of spreadsheets. In Conference of the
European spreadsheet risks interest group – EuSpRIG’00, London, UK (pp. 75–85).
This paper observes that spreadsheets, as built by regular users, contain both a
“surface” and a “deep” structure, and that many errors stem from the latter. It proposes
a method for visualizing the deep structure and therefore helping users debug their
spreadsheets.
[CGT89] Ceri, S., Gottlob, G., & Tanca, L. (1989). What you always wanted to know about datalog
(and never dared to ask). IEEE Transactions on Knowledge and Data Engineering, 1(1),
146–166.
This paper contains a thorough survey of the research on Datalog as of 1989. It mostly
takes a query-oriented view, typical of deductive databases or logic programming,
in which only a small number of consequences of the basic facts are considered
interesting. Optimization techniques and extensions (e.g., negation) are discussed. The
reference section is phenomenal.
[CGT90] Ceri, S., Gottlob, G., & Tanca, L. (1990). Logic programming and databases.
Berlin/New York: Springer.
This expanded version of [CGT89] is an excellent survey with some in-depth analysis
of important concepts, in particular semantics, optimizations and the interface with
actual databases. It covers the experimental deductive database system of the time at
length.
[CH85] Chandra, A. K., & Harel, D. (1985). Horn clause queries and generalizations. Journal of
Logic Programming, 1, 1–15.
[Cha06] Chaudhuri, K. (2006). The focused inverse method for linear logic. PhD thesis, Computer
Science Department, Carnegie Mellon University.
[Cla78] Clark, K. L. (1978). Negation as failure. In H. Gallaire & J. Minker (Eds.), Logic and data
bases (pp. 293–322). New York: Plenum.
[CM87] Clocksin, W. F., & Mellish, C. S. (1987). Programming in Prolog (3rd ed.).
Berlin/New York: Springer.
This book is a classic introductory text to Prolog. Generations of students have relied
on it to learn logic programming to build applied programs.
[Cod70] Codd, E. F. (1970). A relational model of data for large shared data banks. Communica-
tion of the ACM, 13(6), 377–387.
This is the original article on the relational data model and the use of relational algebra
as a query mechanism for databases. This article offers a rare glimpse of what it was
like to use computers in the 1960s and of a vision that is still with us today (in a very
prominent way).
380 Annotated Bibliography
This technical report is widely considered to be the first mention on what was to
become Prolog. Its original application was the processing of natural language (French,
to be precise).
This book is one of the best introductory accounts of what can be done with a deductive
database. Specifically, it explores in great depth problems that combine large sets
of data and require a truly deductive form of inference, above and beyond what the
relational data model has to offer. It targets people who will be using a deductive
database as a tool more than students interested in the underlying theory.
[CP02] Cervesato, I., & Pfenning, F. (2002). A linear logical framework. Information &
Computation, 179(1), 19–75.
This paper presents LLF, a logical framework based on the first instance of a linear
dependent type theory. Linearity enables it to represent object formalisms with state,
such as imperative programming languages. It also supports an operational semantics
in the style of top-down logic programming that allows us to execute some of these
specifications.
[CvEL88] Cheng, M. H. M., van Emden, M. H., & Lee, J. H. -M. (1988). Tables as a user interface
for logic programs. In Fifth generation computer systems, Tokyo (pp. 784–791).
This work extends [vEOT86] to tables in the sense of relational algebra. It is still
heavily based on incremental queries but now supports the display of multiple
solutions in a tabular way. The implementation is based on the recently introduced
graphical display. Several windows show different views of the system. However the
basic input mode is still essentially through the command lines, with other windows
used only for displaying results in a tabular way.
[DW88] Debray, S. K., & Warren, D. S. (1988). Automatic mode inference for logic programs.
Journal of Logic Programming, 5, 207–229.
[EB02] Erwig, M., & Burnett, M. (2002). Adding apples and oranges. In Practical aspects of
declarative languages, 4th international symposium – PADL’02, Portland (Lecture notes in
computer science, Vol. 2257, pp. 173–191). Springer.
This paper attempts to rein in the high error rate found in spreadsheets by relying
on “units” implicitly inferred from a spreadsheet rather than a rigid system of
types. Such units are classified and correlated into dependent units, multiplicities and
generalizations, with the aim to capture the user’s intention and fend off mistakes.
[EK76] Van Emden, M. H., & Kowalski, R. A. (1976). The semantics of predicate logic as a
programming language. Journal of the ACM, 23(4), 733–742.
Annotated Bibliography 381
[GA00] Gupta, G., & Akhter, S. (2000). Knowledgesheet: A graphical spreadsheet interface
for interactively developing a class of constraint programs. In Proceedings of the second
international workshop practical aspects of declarative languages – PADL’00, Boston
(Lecture notes in computer science, Vol. 1753, pp. 308–323). Springer.
[Gir87] Girard, J. -Y. (1987). Linear logic. Theoretical Computer Science, 50, 1–102.
This is the original paper on linear logic. It describes in great detail its proof-theory
and several forms of semantics for it.
[GKB87] Güntzer, U., Kiessling, W., & Bayer, R. (1987). On the evaluation of recursion in
(deductive) database systems by efficient differential fixpoint iteration. In Proceedings of
the third international conference on data engineering, Los Angeles (pp. 120–129). IEEE
Computer Society.
[GM78] Gallaire, H., & Minker, J. (Eds.). (1978). Logic and data bases. New York: Plenum.
This collection contains many of the very first papers on using logic programming
in the context of data- and knowledge-bases. The seminal work on the closed world
assumption and negation-as-failure first appeared in it.
[GM02] Ganzinger, H., & McAllester, D. (2002). Logical algorithms. In Proceedings of the 18th
international conference on logic programming – ICLP’02, London (pp. 209–223). Springer.
This paper proposes a precise model of the run-time of a logic program that supports
using logic programs for studying the execution time of algorithms.
[GMS93] Gupta, A., Mumick, I. S., & Subrahmanian, V. S. (1993). Maintaining views incremen-
tally. In Proceedings of the 1993 SIGMOD international conference on management of data –
SIGMOD’93, Washington, DC (pp. 157–166). ACM.
382 Annotated Bibliography
This paper is concerned with the problem of propagating the effect of fact updates
in a Datalog program. To this effect, it associates a counter to inferred facts, thereby
counting in how many ways a fact can be derived. Relevant counters are increased or
decreased whenever an assertion or deletion changes the provability of inferred atoms.
[GP96] Green, T., & Petre, M. (1996). Usability analysis of visual programming environ-
ments: A “cognitive dimensions” framework. Journal of Visual Languages and Computing, 7,
131–174.
This paper applies the cognitive dimensions of notation framework to the evaluation
for visual programming environments, finding it particularly effective and a good
complement for other techniques.
This is the original paper on the cognitive dimension of notations. At the time, it
focused not so much on graphical user interfaces but on interactive devices and
programming notations.
In the talk on which this extended abstract is based, Thomas Green discusses the
reasons that led him to develop the cognitive dimensions of notation framework. This
is a good first-person motivation of the origins of the methodology.
[Gre96b] Green, T. (1996). The visual vision and human cognition. Available at http://homepage.
ntlworld.com/greenery/workStuff/VL96Talk/VLTalk.html.
In this talk, Thomas Green discusses the progress in visual programming environments
as well as some limitations. At he does this, the explains how his cognitive dimensions
of notations can benefit the design of such systems as well as some usability targets
for such designs.
[Gun04] Gunning, D. (2004). DARPA SBIR 2004.3, topic sb043-040: Deductive spreadsheets.
[GW10] Grumbach, S., & Wang, F. (2010). Netlog, a rule-based language for distributed
programming. In Proceedings of 12th international symposium on practical aspects of
declarative languages – PADL’10, Madrid (Lecture notes in computer science, Vol. 5937,
pp. 88–103). Springer.
[Han94] Hanus, M. (1994). The integration of functions into logic programming: From theory to
practice. Journal of Logic Programming, 19–20, 583–628.
This paper describes Curry, a functional-logic programming language for the research,
teaching, and applications, as well as the foundations of this paradigm.
[Har93] Harland, J. (1993). Success and failure for hereditary Harrop formulae. Journal of Logic
Programming, 17(1), 1–29.
[Har94] Harland, J. (1994). Towards a sequent calculus for negation as failure. In Proceedings of
the workshop on proof-theoretical extensions of logic programming, Santa Margherita Ligure
(pp. 19–27).
[Har03] Harvey, G. (2003). Excel 2003 all-in-one desk reference for Dummies. Hoboken: Wiley.
In spite of the demeaning title, this is one of the most popular reference guide with
users. It covers very well Excel from a user’s perspective and is therefore an ideal
reference for this work. We ourselves learned quite a few “Excel tricks” while reading
it. The same author has published guides in this series for Excel 2007 and 2010.
[HM94] Hodas, J. S., & Miller, D. (1994). Logic programming in a fragment of intuitionistic linear
logic. Information and Computation, 110(2), 327–365.
This paper describes the first attempt at marrying the proof-theoretic approach to
logic programming pioneered in [MNPS91] with linear logic, a then-novel logic to
reason about resources rather than truths. The result was Lolli, the first linear logic
programming language. The paper also applies it to numerous examples in areas such
as theorem proving, natural language parsing, and data base programming, and it
explores its model theory.
[How98] Howe, J. M. (1998). Proof search issues in some non-classical logics. PhD thesis,
University of St Andrews.
This dissertation expands Andreoli’s use of focusing [And92] from linear logic to
mainstream intuitionistic logic.
[HPSBC 04] Horrocks, I., Patel-Schneider, P., Boley, H., Tabet, S., Grosof, B., & Dean, M. (2004).
SWRL: A semantic web rule language combining OWL and RuleML. Available at http://
www.w3.org/Submission/SWRL/.
This paper proposes SWRL, a semantic web rule language based on a combination of
two fragments of the OWL web ontology language with a sublanguage of RuleML,
a variant of Datalog. It gives a model-theoretic semantics of SWRL ontologies and
demonstrates it on a number of examples.
[JL87] Jaffar, J., & Lassez, J. -L. (1987). Constraint logic programming. In Proceedings of the
14th symposium on principles of programming languages – POPL’87, Munich (pp. 111–119).
384 Annotated Bibliography
This is the original paper on constraint logic programming, a paradigm that seamlessly
incorporates constraints over generic domains within logic programming in the style
of Prolog. The result is a family of languages, one for each specific domain and
accompanying constraint-solving procedures, that retain the declarative nature of logic
for programming purposes, but specializes it to domains of interest in a natural way.
[JM94] Jaffar, J., & Maher, M. J. (1994). Constraint logic programming: A survey. Journal of
Logic Programming, 19/20, 503–581.
This paper surveys the foundations, applications and developments of constraint logic
programming since its inception in [JL87].
[KG07] Kassoff, M., & Genesereth, M. (2007). PrediCalc: A logical spreadsheet management
system. The Knowledge Engineering Review, 22(03), 281–295.
[KKR95] Kanellakis, P., Kuper, G., & Revesz, P. (1995). Constraint query languages. Journal of
Computer and System Sciences, 51(1), 26–52.
This paper proposes an approach to representing and retrieving data in a database that
stores information not as facts (or tuples), but as a conjunction of simple constraints
over a given domain. This is especially useful for applications, such as geographic
databases, where objects of interest are naturally expressed as constraints, spatial
constraints in this case.
This is a classical textbook on mathematical logic by one of the masters of the field.
[KLP00] Kuper, G., Libkin, L., & Paredaens, J. (Eds.). (2000). Constraint databases.
Berlin/New York: Springer.
This collection surveys the then-nascent field of constraint databases, with contribu-
tions by many of it pioneers. Constraint databases rely on constraints to describe some
types of data, for example temporal or spatial data, and to draw inferences from them
in an efficient way.
This classic book investigates the application of logic to problem solving and computer
programming using Prolog.
[Kri82] Kriwaczek, F. (1982). Some applications of Prolog to decision support systems. Master’s
thesis, Imperial College, London.
This master’s thesis is regarded as the first attempt ever to combine spreadsheets and
logic programming. See the discussion in the polished version [Kri88].
[Kri88] Kriwaczek, F. (1988). Logicalc: A Prolog spreadsheet. Machine intelligence, 11, 193–208.
Annotated Bibliography 385
This work refines [Kri82] and implements its design as a system called LogiCalc.
Its initial goal was to “reconstruct logically, in micro-Prolog, a typical spreadsheet
program”. Besides capturing most of the functionalities of early spreadsheets, it
provides powerful extensions such as relational manipulations, integrity constraints,
bidirectional variables, symbolic reasoning, and complex objects (e.g., lists, graphics
and spreadsheets themselves). It is based on the limited teletype interface that predated
the widespread availability of graphical user interfaces with windows. LogiCalc relies
a lot on user input, even for non-essential tasks.
[LC12] Lam, E. S. L., & Cervesato, I. (2012). Modeling datalog fact assertion and retraction in
linear logic. In A. King (Ed.), Proceedings of the 14th international ACM symposium on
principles and practice of declarative programming – PPDP’12, Leuven.
This paper models the propagation of the assertion of new facts or the retraction of
old facts in the Datalog system by means of inference in linear logic. To this effect,
it translates Datalog clauses into linear logic formulas that also contain specifications
about how to propagate updates.
[LCGC 06] Loo, B. T., Condie, T., Garofalakis, M., Gay, D. E., Hellerstein, J. M., Maniatis,
P., Ramakrishnan, R., Roscoe, T., & Stoica, I. (2006). Declarative networking: Language,
execution and optimization. In Proceedings of the 2006 SIGMOD international conference
on management of data – SIGMOD’06, Chicago (pp. 97–108). ACM.
This is the classical textbook on the theory of logic programming: it collects and
unifies results on SLD-resolution, unification, model and fixpoint semantics, negation-
as-failure, that had appeared in separate papers. It does not consider any of the recent
proof-theoretic developments, but it is a valuable reference. As such, it has been used
by generations of students and scholars of logic programming.
[LM03] Li, N., & Mitchell, J. C. (2003). Datalog with constraints: A foundation for trust
management languages. In Proceedings of the fifth international symposium on practical
aspects of declarative languages (PADL’03), New Orleans.
This paper shows how Datalog can fruitfully be used to specify access control and
trust management policies in order to decide authorization and access in a distributed
system of computers. To this effect, it extends Datalog with constraints over signed
messages. The paper explores the theoretical properties of the resulting language and
relates it to other authorization and trust management languages.
[LM09] Liang, C., & Miller, D. (2009). Focusing and polarization in linear, intuitionistic, and
classical logic. Theoretical Computer Science, 410(46), 4747–4768.
This paper synthesizes in a single presentation some of the best results that have
been proposed about focusing and polarization. Focusing guides the task of executing
a logic program or searching for a proof in logic, while polarization systematically
decorates formulas to direct and enable focusing.
386 Annotated Bibliography
[LNS82] Lassez, J. -L., Nguyen, V. L., & Sonenberg, L. (1982). Fixed point theorems and
semantics: A folk tale. Information Processing Letters, 14(3), 112–116.
[LP09] Lovas, W., & Pfenning, F. (2009). Refinement types as proof irrelevance. In P. -
L. Curien (Ed.), Proceedings of the 9th international conference on typed lambda calculi and
applications – TLCA’09, Brasilia (Lecture notes in computer science, Vol. 5608, pp. 157–
171). Springer.
This paper examines proof irrelevance, a mechanism for selectively hiding the
identities of terms in type theories, and relates it to refinement types, a powerful
approach to classify terms.
[LPPW05] López, P., Pfenning, F., Polakow, J., & Watkins, K. (2005). Monadic concurrent linear
logic programming. In A. Felty (Ed.), Proceedings of the 7th international symposium on
principles and practice of declarative programming – PPDP’05, Lisbon (pp. 35–46). ACM.
[LRB91] Lewis, C., Rieman, J., & Bell, B. (1991). Problem-centered design for expressiveness and
facility in a graphical programming system. Human-Computer Interaction, 6(3–4), 319–355.
This paper advocates a design methodology for graphical systems that is driven by
concrete examples of tasks that users are expected to accomplish (problems) rather
than abstract cognitive targets. This expands the space of design alternatives and acts
as a benchmark to evaluate solutions.
[LS09] Liu, Y., & Stoller, S. (2009). From datalog rules to efficient programs with time and space
guarantees. ACM Transactions on Programming Languages and Systems – TOPLAS, 31(6),
1–38.
This paper describes a method for transforming a Datalog program into an efficient
specialized implementation with guaranteed worst-case time and space complexities.
The transformation exploits fixed-point computation, incremental maintenance of
invariants, and combinations of indexed and linked data structures.
[Mac94] MacGregor, R. (1994). A description classifier for the predicate calculus. In Proceedings
of the twelfth national conference on artificial intelligence – AAAI’94, Seattle (pp. 213–220).
This paper presents a general description classifier for first-order logic extended with
sets, equality and scalar inequality. A description classifier is a method to organize
concepts and relations into a taxonomy based on subsumption.
[McA02] McAllester, D. (2002). On the complexity analysis of static analyses. Journal of the
ACM, 49, 512–537.
This paper describes a method for computing run-time complexity bounds for Datalog
programs. More generally, it shows that specifying an algorithm using Datalog is
beneficial for reasoning about its complexity.
Annotated Bibliography 387
[Men97] Mendelson, E. (1997). Introduction to mathematical logic (4th ed.). Princeton: Van
Nostrand-Reinhold.
This is another good textbook on mathematical logic. It is notable for its breadth of
topics.
[Mil89] Miller, D. (1989). A logical analysis of modules in logic programming. Journal of Logic
Programming, 6(1–2), 79–108.
This paper explores the theory and application of a general language of Horn
clauses augmented with embedded implication and quantification (hereditary Harrop
formulas), which goes well beyond Datalog. It studies its proof theory, model theory
and fixpoint semantics in an intuitionistic setting. It shows how embedded clauses
provide a foundational justification for parametric modules in logic programming.
[Min87] Minker, J. (Ed.). (1987). Foundations of deductive databases and logic programming.
Los Altos: Morgan Kaufmann.
This book collects original articles by the main players of the then-nascent and very
fertile field of deductive databases. It grew out of a workshop by the same title held in
Washington, DC the year before.
[MNPS91] Miller, D., Nadathur, G., Pfenning, F., & Scedrov, A. (1991). Uniform proofs as a
foundation for logic programming. Annals of Pure and Applied Logic, 51, 125–157.
This now classic paper was the first to establish top-down logic programming on solid
proof-theoretic grounds. The methodology it embraced, based on the notion of uniform
proofs, identified fragments of logic larger than Prolog’s Horn clauses that could be
used for programming. Specifically, it shows that hereditary Harrop formulas, which
extend Horn clauses with embedded implication, fit into this pattern, and so do higher-
order variants of both languages.
[NJLS11] Nigam, V., Jia, L., Loo, B. T., & Scedrov, A. (2011). Maintaining distributed logic
programs incrementally. In Proceedings of the 13th international ACM symposium on
principles and practice of declarative programming – PPDP’11, Odense (pp. 125–136).
ACM.
[NM94] Nielsen, J., & Mack, R. L. (Eds.). (1994). Usability inspection methods. New York: Wiley.
This collection of essays brings together the best approaches to predictive user
modeling in use at the time, with special emphasis on various types of cognitive
walkthrough. It reports on numerous case studies and gives practical guidance to
developers interested in embedding usability inspection into the software cycle.
388 Annotated Bibliography
[NM10] Nigam, V., & Miller, D. (2010). A framework for proof systems. Journal of Automated
Reasoning, 45(2), 157–188.
This is a basic textbook on databases that rigorously links theory to the real world of
database usage, programming and administration.
[OO90] Olson, J., & Olson, G. (1990). The growth of cognitive modeling in human-computer
interaction since GOMS. Human-Computer Interaction, 5, 221–265.
This retrospective paper explores the advances of cognitive sciences and human-
computer interaction technology since the proposals of the GOMS model. It also
spells out the numerous shortcomings of methodologies of the time, for example
their inability to account for things like user fatigue, individual differences, or mental
workload. This is a very interesting read.
[Pan98] Panko, R. R. (1998). What we know about spreadsheet errors. Journal of End User
Computing (Special issue on Scaling Up End User Development), 10(2), 15–21. Available at
http://panko.shidler.hawaii.edu/ssr/Mypapers/whatknow.htm.
This very influential article carried out a systematic study of the number and type of
errors found in spreadsheets. At the outset, the results are surprisingly high, which
should limit our confidence about decisions made on the basis of spreadsheet calcu-
lations. This research also finds that this type and number is similar to programming
in general, except that software engineering has developed methods to curb this error
rate, while spreadsheet users take a more informal approach.
[PBB03] Peyton-Jones, S., Blackwell, A., & Burnett, M. (2003). A user-centred approach to
functions in Excel. In Proceedings of the eighth ACM SIGPLAN international conference
on functional programming, Uppsala (pp. 165–176). ACM.
This paper proposes a method for extending the traditional spreadsheet with user-
defined functions without the expectation that an everyday user will acquire the
sophistication of an addon programmer. This work relies on cognitive psychology
techniques such as the cognitive dimension of notations and the attention investment
model to retain the usability that characterizes the traditional spreadsheet. This work
was extremely influential in the development of the deductive spreadsheet.
than truth. Special attention is given to the computational uses of logic, with a
rigorous development of the operational aspects of logic programming out of pure
logic foundations.
[Pfe89] Pfenning, F. (1989). Elf: A language for logic definition and verified meta-programming.
In Fourth annual symposium on logic in computer science, Pacific Grove (pp. 313–322). IEEE
Computer Society Press.
This paper describes the Elf system, which provides a type-checker, type-
reconstruction support, and top-down execution in the style of Prolog to the LF type
theory.
This volume brings together the principal approaches to weaving types in logic
programming. Essays within describe specific techniques but also emphasize the
overall benefits of types, including reduced error rates, support for modularity, and
compilation assistance.
This web site gives a fascinating description of how the modern spreadsheet came
about, how it evolved from the “books” that accountants have used for millennia and
how a Harvard Business School student, Dan Bricklin, envisioned and then realized an
electronic version of it. This is a good complement to Bricklin’s own account of the
invention of the spreadsheet [Bri09].
[PS99] Pfenning, F., & Schürmann, C. (1999). System description: Twelf – A meta-logical
framework for deductive systems. In Proceedings of the 16th international conference on
automated deduction – CADE-16, Trento (Lecture notes in artificial intelligence, Vol. 1632,
pp. 202–206). Springer.
This paper describes Twelf, a reimplementation of the Elf system [Pfe89] extended
with theorem-proving capabilities for specifications written in the LF type theory.
[Rei78] Reiter, R. (1978). On closed world data bases. In H. Gallaire & J. Minker (Eds.), Logic
and data bases (pp. 55–76). New York: Plenum.
This classic paper sets the foundations of theorem proving and introduces the resolu-
tion principle, which is one of the tenets of top-down evaluation in logic programming.
This paper describes the XcelLog deductive spreadsheet system [RRW07] with
particular emphasis on using the spreadsheet metaphor for the purpose of taming the
rule interactions. It also discusses the details of its implementation as an Excel addon
powered by the XSB tabled logic programming system [War98] as a back-end.
This paper describes the design and implementation of XcelLog, an extension of the
traditional spreadsheet with deductive capabilities. Like the proposal in this book,
XcelLog is meant to retain the usability of the spreadsheet while enabling end-users
to use it to draw logical consequences. The approach treats sets as the fundamental
data type and inference rules as specifying among sets. The spreadsheet metaphor is
used to create and view the materialized sets. The implementation relies on the XSB
system [War98].
[RSS92] Ramakrishnan, R., Srivastava, D., & Sudarshan, S. (1992). Efficient bottom-up evaluation
of logic programs. In P. Dewilde & J. Vandewalle (Eds.), The state of the art in computer
systems and software engineering. Kluwer Academic.
This paper reviews the state of the art of bottom-up evaluation and proposes a
transformation on Datalog programs to speed up that semi-naı̈ve evaluation. It also
discusses extensions to negation, set terms, constraints and quantitative reasoning.
Comparisons with numerous systems are included.
[RSSS94] Ramakrishnan, R., Srivastava, D., Sudarshan, S., & Seshadri, P. (1994). The CORAL
deductive system. Journal of Very Large Databases, 3(2), 161–210.
[RU95] Ramakrishnan, R., & Ullman, J. D. (1995). A survey of deductive database systems.
Journal of Logic Programming, 23(2), 125–149.
This brief but excellent survey of the development of deductive databases up to 1993
contains very little theory, but gives a clear intuition of what deductive databases
are good for. It describes the major projects and their contributions to the field. The
references are particularly useful.
This paper explores approaches to curbing the error rate in spreadsheets observed
by [Pan98]. It does so through two auditing modalities for visualizing the flow of
information, both based on the underlying dependencies and on how people actually
use spreadsheets.
[Sar10] Sarnat, J. (2010). Syntactic finitism in the metatheory of programming languages. PhD
thesis, Department of Computer Science, Yale University.
This thesis examines in great detail, among other things, mode-checking and termina-
tion in the Twelf system, which embeds a higher-order logic programming language
with a top-down execution semantics.
[SB89] Spenke, M., & Beilken, C. (1989). A spreadsheet interface for logic programming. In
CHI’89: Proceedings of the SIGCHI conference on human factors in computing systems,
Austin (pp. 75–80). ACM.
Annotated Bibliography 391
This work proposes to combine logic programming and spreadsheets under the
umbrella of the PERPLEX system. It does so by making heavy use of integrity
constraints in a way that is clearly expressive, but likely to be unnatural for an
entry-level user. PERPLEX supports exploratory programming and the paradigm of
“query-by-example” to perform many programming tasks. While very powerful, it is
not clear that this blends smoothly in the spreadsheet mindset. This is the first logical
spreadsheet extension to make use of graphical input and not just output.
[SBB96] Spenke, M., Beilken, C., & Berlage, T. (1996). FOCUS: The interactive table for product
comparison and selection. In UIST ’96: Proceedings of the 9th annual ACM symposium on
user interface software and technology, Seattle (pp. 41–50). ACM.
This paper and the accompanying implementation include many very interesting ideas
for effectively displaying tabular information, specifying queries, and designing a new
relation on the basis of a few mouse clicks.
[SGG86] Smith, D. E., Genesereth, M. R., & Ginsberg, M. L. (1986). Controlling recursive
inference. Artificial Intelligence, 30(3), 343–389.
This paper studies in great detail to what depth it is sufficient to expand a derivation
tree for a top-down evaluation of a logic program. It also leverages properties such
as transitivity and subsumption, as well as characteristics of the domain to extend the
class of prunable programs.
This paper revisits the premises by which a generic logical derivation can be
transformed into a focused derivation, thereby replacing the “long and tedious proofs”,
which producing such a result has required so far, with a simple structural argument.
[Spe00] Spencer, R. (2000). The streamlined cognitive walkthrough method, working around
social constraints encountered in a software development company. In Proceedings of the
SIGCHI conference on human factors in computing systems – CHI’00, The Hague (pp. 353–
359).
[SS94] Sterling, L., & Shapiro, E. (1994). The art of Prolog (2nd ed.). Cambridge: MIT.
This is another classic introductory textbook on programming in Prolog that has been
used by generations of students.
[SSFd00] Schroyens, W., Schaeken, W., Fias, W., & d’Ydewalle, G. (2000). Heuristic and analytic
processes in propositional reasoning with negation. Journal of Experimental Psychology:
Learning, Memory, and Cognition, 26(6), 1713–1734
This paper describes a series of experiments aimed at analyzing the cognitive impact
on analytic process of conditional reasoning with negations and double negations.
[Tar55] Tarski, A. (1955). A lattice-theoretical fixpoint theorem and its applications. Pacific
Journal of Mathematics, 5, 255–309.
[TB08] Tallis, M., & Balzer, R. M. (2008). A functional spreadsheet framework for authoring
logic implication rules. In N. Bassiliades, G. Governatori, & A. Paschke (Eds.), Proceedings
of the seventh international symposium on rule interchange and applications – RuleML’08,
Orlando (Lecture notes in computer science, Vol. 5321, pp. 219–226). Springer.
This paper explores an extension of the traditional spreadsheet with logical reasoning
capabilities aimed at capturing the semantics of a binary relation by using spreadsheet
artifacts to specify its image. This model is internally translated into a system of
clauses. A prototype has been implemented as an Excel addon.
[TvD88] Troelstra, A. S., & van Dalen, D. (Eds.). (1988). Constructivism in mathematics: An
introduction. Amsterdam/New York: North-Holland.
This two-volume set is a now classic reference to constructive logic and its applications
in a variety of fields. It covers intuitionistic logic both at an introductory level and in
exhaustive depth.
[TWB07] Tallis, M., Waltzman, R., & Balzer, R. (2007). Adding deductive logic to a COTS
spreadsheet. The Knowledge Engineering Review, 22(03), 255–268.
This paper describes a logic-based application that extends Microsoft Excel with
mechanisms to flag a range or a cell as part of a relation. These relations are
automatically copied into a deductive logic engine implementing the OWL+SWRL
ontology language [HPSBC 04]. The extension also contains mechanisms to populate
a range with values deduced by evaluating logic rules.
[Ull88] Ullman, J. D. (1988). Principles of database and knowledge-base systems (Vol. 3).
Rockville: Computer Science Press.
This two-volume set reviews the theory and practice of databases as of the late 1980s,
with an eye towards then-emerging technologies such as object-oriented databases,
deductive databases and security issues. It also explores their application to reasoning
tasks, especially in the area of knowledge management.
[vEOT86] van Emden, M. H., Ohki, M., & Takeuchi, A. (1986). Spreadsheets with incremental
queries as a user interface for logic programming. New Generation Computing, 4(3), 287–
304.
[VvBCE07] Valente, A., van Brackle, D., Chalupsky, H., & Edwards, G. (2007). Implementing
logic spreadsheets in LESS. The Knowledge Engineering Review, 22(03), 237–253.
This paper combines the traditional spreadsheet and an expressive knowledge repre-
sentation and reasoning system into LESS, a logic-based extension of the spreadsheet.
LESS supports reasoning with arbitrary first-order logic formulas, subsumption, clas-
sifications, higher-order constructs and much more. This expressiveness is brokered to
the user by offering four modalities requiring increasing levels of sophistication for
users to interact with the system.
Annotated Bibliography 393
[War98] Warren, D. S. (1998). Programming with tabling in XSB. In D. Gries & W. P. de Roever
(Eds.), Programming concepts and methods, IFIP TC2/WG2.2,2.3 international conference
on programming concepts and methods (PROCOMET’98): Vol. 125 of IFIP conference
proceedings, Shelter Island (pp. 5–6). Chapman & Hall.
XSB is Prolog with a form of memoization called tabling. Declaratively, it does not dif-
fer substantially from Prolog. Procedurally, however, it substantially improves on the
standard top-down SLDNF resolution strategy of this language by nearly eradicating
control-induced infinite loops. In particular, an XSB query always terminates against
a Datalog program. Tabling can also have a positive effect on efficiency, although
this may depend on how the user writes his programs. This makes XSB a promising
candidate as the underlying explanation engine of a deductive spreadsheet.
[WCPW03] Watkins, K., Cervesato, I., Pfenning, F., & Walker, D. (2003). A concurrent logical
framework: The propositional fragment. In Types for proofs and programs: Proceedings of the
TYPES 2003 international workshop, Torino (Lecture notes in computer science, Vol. 3085,
pp. 355–377). Springer.
This paper describes the foundations of a language where top-down and bottom-
up execution work together toward modeling concurrent and distributed problems.
This language is based on linear logic and takes a type-theoretic approach. Distinct
fragments support top-down and bottom-up execution, and they are mediated by means
of a monad.
[WJL72] Wason, P. C., & Johnson-Laird, P. N. (1972). Psychology of reasoning: Structure and
content. Cambridge: Cambridge University Press.
This classic cognitive psychology textbook is concerned with why we reason the way
we do: we are not infallible reasoners yet certain deductions come to us naturally
while others require quite a bit of effort, and often end up being erroneous. One such
difficult pattern is negation. This book is a fascinating in-depth analysis of the often
problematic relationship between man and logic.
[Zan99] Zaniolo, C. (1999). A short overview of deductive database systems. In W. Kloesgen &
J. Zytkow (Eds.), The handbook of data mining and knowledge discovery. Oxford/New York:
Oxford University Press.
In just three pages, this precious little overview describes deductive databases, recalls
their history, and outlines the main open research problems. It is followed by a much
longer set of references to the main papers that led to their development.
Symbols in Use
Edge in graph
Path in graph
C
Added edge dependency
Deleted edge dependency
Ü Functional dependency
) Constraint dependency
jˆ Intuitionistic validity
Dependent subexpression
0 Positional dependent subexpression
v .@/ Subexpression (strict)
vr .@r / Relational subexpression
va .@a / Dependent attribute
@æ Attribute expression dependency
Env .<Env/ Environment ordering (strict)
Comparison operator
b Comparison operation
s Component referential closure
Es Array referential closure
Œ Empty list
j Append
[ Relational union
[EH;[ EV Array append
Set difference
Cartesian product
j k Spreadsheet index set
‰ Join
\ Relational intersection
;; ;I Empty relation
e@ Expression evaluation
s ˚ s Update application
? Uncalculated value
?N Uncalculated relation
? Initial environment
[ Blank value
Error value
E Error array
N Error relation
Œ1::n Index range
Œ1::j Œ1::k Spreadsheet index set
ŒEe List of values
N
Œe Relation-to-array coercion
hEei Base relation
peqN Logical interpretation of eN
.x1 ; : : : ; xn / Extensional array or record
flgE Location array partition
jxj
E Length of vector or record xE
jGj Height of DAG G
rs Next environment non-update
Theory, context
p Clausal theory of p
rec.p/ Mutually recursive clauses
s Clausal theory of s
&
s Clauses of stratum &
L Repartition
p Positive update to p
pCl Positive update to p by clause Cl
s Spreadsheet update
s Next environment update
…p Factual theory of p
…s Factual theory of s
&
…s Facts of stratum &
… Definite/normal theory
… s Definite/normal theory of s
… & Subtheory of &
… si Subtheory of &Eis
… Bounding transformation of …
˛ Substitution
ıp Negative update to p
ıpCl Negative update to p by clause Cl
Environment
s Updated part of environment
Index
' First-order formula
æE Projection
Symbols in Use 397
E æE Array projection
C Selection
EC Array election
& Stratum
&E Stratification
&Eis Sub-stratification of level i
Attr.æ/ Attributes of æ
Attr.C / Attributes of C
N
Attr.x/ Attributes of xN
N
Attr .x/ Selection attributes of xN
B Clause body
C Selection condition
b
C Selection function
CG… Call graph of …
CGs Call graph of s
CG… Œi Predicates at level i
Cl Clause
DFs Dataflow graph
DGs Dependency graph
DGas Attribute-dependency graph
DGAs Two-level attribute-dep. graph
DGrs Relation-dependency graph
DGR s Two-level relation-dep. graph
E./ Generic evaluation strategy
398 Symbols in Use
a Attribute
æ Attribute expression
æO Evaluated attribute expression
c Base selection condition
cellss Updated cells
e Scalar expression
eE Array expression
eN Relational expression
gfp Greatest fixpoint
glb Greatest lower bound
hcmax Bound on bounding transformation
Symbols in Use 399
l Location
lE Array of location
lfp Least fixpoint
lub Lower upper bound
op Scalar operator
opb Scalar operation
b
op? Scalar operation over V?
opE Array-valued operator
E
opŒ Scalar component of op
bE
b
op Array-valued operation
opE? Array-valued operation over V?
op N Relational operator
bN
b
op Relational operation
opE? Relational operation over V?
p Predicate symbol
pji Predicate argument pair
q Predicate symbol
r Record
.r; r 0 / Record concatenation
rec.p/ Predicates mutually recursive with p
s Spreadsheet
s ˇ s Update application
t Term
t Recalculation delay
v Scalar value
Ev Array value
vN Relational value
x Generic set element
xE Generic array or record
xE Œ Array or record element
xN Generic relation
N
xŒa Extensional attribute
Index