Negation as Failure

Negation as failure (NAF) is an inference rule that takes a statement to be false when every attempt to prove it from the available facts and rules fails.

Status
Published, version 1.0.1
Last reviewed
21 Nov 2026, by Dr Darrin Baines
Report a problem
Tell us if something is wrong or out of date

Concept Architecture

Negation as Failure in Logic Programming and Data Queries

Negation as failure is the way a rule engine or query answers "not P", by searching for a proof of P and treating the failure of that search as a proof of the negation. Prolog and the negation tests of SPARQL work this way, so the conclusion says only that nothing in the data supports P, which is weaker than knowing that P is false. Health economists meet the rule whenever a query selects patients with no record of a condition or a treatment, as in the exclusion criteria of a cohort drawn from claims data. Such a selection is sound only for the period and the sources in which the record would have appeared.

Origin of the term and who uses it

Keith Clark named and analysed the rule in his 1978 paper "Negation as Failure", published in Logic and Data Bases, edited by Gallaire and Minker. He described a query evaluator for a logic data base as a Horn clause theorem prover with one added inference rule, under which the negation of P is inferred when every possible proof of P fails, and he noted that PLANNER and PROLOG already handled negation this way. In the same volume Reiter tied his closed world assumption to the negation operators of those languages, where negation means "not provable".

The World Wide Web Consortium (W3C) keeps the term in its rule standards. The RIF Framework for Logic Dialects (RIF-FLD) uses the symbol Naf for default negation in rule languages with logic programming and deductive database semantics, says the name comes from negation-as-failure, and lets it cover other kinds of default negation, such as well-founded and stable-model negation. The SPARQL 1.1 recommendation notes that a query testing whether a variable introduced by an optional pattern remains unbound is called negation as failure in logic programming. The SWI-Prolog manual calls it weak or default negation, and the wiki label is the standard term.

How the rule draws its conclusion

Clark wrote the rule as an inference from unprovability. The proof that P is unprovable is an exhaustive search for a proof of P that has failed.

FFDB(P)  ⇒  DB⊢NAF¬P\mathrm{FF}_{DB}(P) \;\Rightarrow\; DB \vdash_{\mathrm{NAF}} \neg P

where DBDB is the data base of facts and rules, PP is a statement with no free variables, FFDB(P)\mathrm{FF}_{DB}(P) means that every attempt to prove PP from DBDB has ended in failure after finitely many steps, which is narrower than PP merely not being provable, ¬\neg is negation, and ⊢NAF\vdash_{\mathrm{NAF}} marks a conclusion reached with the negation as failure rule.

Two conditions limit the rule in Clark's evaluator. The search must end, since a path that never terminates returns no answer, and the SWI-Prolog manual likewise says that its negation operator succeeds only if the attempt to prove the goal fails in finite time. A negated statement is selected only when it contains no variables, so a query first identifies the patient or record and only then tests what is absent.

Clark also showed what the rule assumes. He read the clauses for each relation as the "if" halves of complete definitions, added equality schemas making explicit that different names denote different objects, and proved that the rule yields only negations that follow from this completed data base. Clark offered the completion as a way to make the closed world assumption explicit in logic, a different construction from Reiter's added negative facts. The equality schemas amount to a unique name assumption, the subject of the nonunique naming assumption page.

Default negation versus classical negation

RIF-FLD calls default negation asymmetric, because completely different inference rules derive p and its default negation, and sets it against symmetric negation such as classical negation. Its example is the rule that p holds if q cannot be established. Read classically, the rule only says that p or q is true, while a rule system derives p because nothing establishes q. Adding the fact q withdraws that conclusion, so reasoning with negation as failure is non-monotonic.

In health data, a record stating a negative screening result is an explicit negative, while a record with no diagnosis code supports only a negation as failure. The SWI-Prolog manual discourages the alternative name not/1 for the same reason, since it reads as "known to be false" when it means "not known to be true". The RIF Basic Logic Dialect allows no negation at all, and its text notes that a full mapping of SPARQL would need non-monotonic negation.

Negation as failure in SPARQL and RHEO record rules

SPARQL 1.1 offers two forms of negation. A NOT EXISTS filter tests whether a pattern fails to match the dataset for the values already bound, while MINUS removes the solutions that share a variable with, and are compatible with, a solution of a second pattern. Either way the result reflects only the dataset queried. Over RDF data that are read under the open world assumption, such a test finds gaps in the data and says nothing about the world.

The Real Health Economics Ontology (RHEO), at healtheconomics.wiki/ontologies/rheo, uses the test in this way. Its release 0.4.0 record rules, written in the Shapes Constraint Language, contain a SPARQL-based constraint with two NOT EXISTS filters that reports an estimate holding neither a numeric value nor a missingness reason, one of not reported, not applicable or not yet extracted. The constraint's message says this is so that a missing value is never read as zero.

Worked example with a look-back window

Cohort definitions for real-world data apply negation as failure to time windows. The Book of OHDSI explains that its tools express an exclusion as an inclusion criterion with zero occurrences, and its worked cohort requires 365 days of continuous observation before the index date, because a patient with a short observation period may have had an exposure elsewhere that the data do not show. The numbers below are illustrative.

Step 1. Candidates. A new-user cohort for a drug starts with 10,000 patients and excludes anyone with a prior heart failure record. Of these, 8,000 have at least 365 days of observation before the index date and 2,000 have less.

Step 2. Records found. Heart failure records are found for 640 of the 8,000 patients, which is 640 / 8,000 = 0.080, or 8.0%, and for 60 of the 2,000, which is 60 / 2,000 = 0.030, or 3.0%.

Step 3. Without the look-back rule. Negation as failure admits everyone with no record, so 10,000 − 640 − 60 = 9,300 patients enter the cohort.

Step 4. Hidden cases. If the short-history group had the same underlying prior heart failure rate as the well-observed group, about 0.08 × 2,000 = 160 of them would have had heart failure, so about 160 − 60 = 100 cases go unseen. Among the 2,000 − 60 = 1,940 short-history patients admitted, that is 100 / 1,940 = 0.052, or about 5.2%.

Step 5. With the look-back rule. Requiring 365 days of observation leaves 8,000 − 640 = 7,360 patients, for whom an absent record is a better guide to absent disease. The rule trades sample size for confidence that "no record" means no event.

Misreadings of a failed search

A failed search shows that the data searched hold no proof, and the conclusion holds only as far as those data are complete. Merging the records with another source, or extending the observation window, can turn a negation into a positive finding, so results built on absence should carry the source, the window and the extract date. Where a record exists but a value in it is unknown, the gap belongs in the missing data analysis and not in a negation test.

Sources

Frequently Asked Questions (6)

  • What is Negation as Failure?

    Negation as failure (NAF) is an inference rule that takes a statement to be false when every attempt to prove it from the available facts and rules fails.

    Source: Clark 1978

  • Who named and analysed Negation as Failure?

    The name comes from a 1978 paper by Keith Clark in Logic and Data Bases, edited by Gallaire and Minker. He described a query evaluator for a logic data base as a Horn clause theorem prover with one added inference rule, under which the negation of a statement is inferred when every possible proof of that statement fails. He noted that the programming languages PLANNER and PROLOG already handled negation in this way, so the procedure is older than the name. His contribution was to show what Negation as Failure assumes about the data and when its conclusions are logically justified.

    Source: Clark 1978

  • How does Negation as Failure relate to the closed world assumption?

    Negation as Failure is the procedure and the closed world assumption is the belief about the data that justifies it. Clark pointed out that treating a fact as false because it cannot be proved assumes that the data base gives complete information about its relations, which is the closed world assumption described by Reiter. He then showed that the rule only yields negations that follow from a completed data base, in which the stored clauses are read as full definitions and different names denote different objects. Where the data are not complete, the rule can return a negation that later data overturn.

    Source: Clark 1978

  • How does Negation as Failure differ from classical negation?

    Negation as Failure treats a statement as false because nothing establishes it, while classical negation needs a proof that the statement is false. The W3C RIF Framework for Logic Dialects calls the first default negation and gives a rule saying that p holds if q cannot be established. Read classically, that rule only says that p or q is true, but a rule system derives p because nothing establishes q. Adding q later withdraws the conclusion, so reasoning with default negation is non-monotonic, which classical logic is not.

    Source: Boley and Kifer 2013

  • How is Negation as Failure used in SPARQL queries?

    SPARQL 1.1 applies Negation as Failure when a query asks for something that is absent from an RDF dataset. A NOT EXISTS filter tests whether a pattern fails to match the dataset for the values already bound, and the recommendation notes that testing for an unbound variable after an optional pattern is called negation as failure in logic programming. The result reflects only the dataset queried. In a merged graph of trial or costing records, a missing statement therefore shows a gap in the data and says nothing about the world.

    Source: Harris and Seaborne 2013

  • Why does Negation as Failure matter when cohort exclusion criteria are applied to real-world data?

    An exclusion such as no prior heart failure record is a Negation as Failure test, since a patient passes because no record is found. The Book of OHDSI explains that its tools write such exclusions as inclusion criteria with zero occurrences. Its worked cohort also requires 365 days of continuous observation before the index date, because a patient with a short observation period may have had an exposure elsewhere that the data do not show. A look-back window of this kind makes an absent record a better guide to absent disease in the patients who remain.

    Source: OHDSI 2021

Trust Record

Verified by Dr Darrin Baines

British health economist

Professional identity: darrinbaines.org

Verification date: 21 Nov 2026

Content version: 1.0.1

Canonical Identity

Term code
HS-HP-DH-159

Stable URI · Machine-readable · Resolvable · CC BY 4.0

This article is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).

Author: Dr Darrin Baines · Publisher: Intelligent Parameters Ltd · Identifier: https://healtheconomics.wiki/concept/negation-as-failure