How Aggregate Functions Expand Real Logic for AI

Peter Bubenik · Sony AI · · Source

After studying this material, you should be able to:

  1. Define Real Logic and its core properties
  2. Explain how fuzzy truth values work in [0,1]
  3. Describe Logic Tensor Networks (LTN) and their applications
  4. Understand what aggregate functions are and why they're useful
  5. Explain how aggregate functions extend Real Logic
  6. Connect this framework to real-world database applications

Step-by-Step Teaching

Step 1: Foundation — What is Classical Logic?

Before Real Logic, you need to understand classical (Boolean) logic:

StatementTruth Value
"The sky is blue"TRUE (1)
"The sky is green"FALSE (0)

⚠️ Problem: Classical logic is binary — everything is either true or false. But reality is often gradual.

Example:

  • Is coffee a healthy food?
  • Classical logic forces: YES or NO
  • Reality says: somewhat healthy

Step 2: Introducing Fuzzy Logic

Fuzzy Logic solves the binary problem by allowing degrees of truth:

Truth Value ∈ [0, 1]

0 = completely false
0.5 = half true
1 = completely true

Example:

"Coffee is healthy" → truth value = 0.6
"Arsenic is healthy" → truth value = 0.02
"Broccoli is healthy" → truth value = 0.95

💡 Key Insight: Fuzzy logic captures gradual, real-world uncertainty better than binary logic.


Step 3: What is Real Logic?

Real Logic combines:

  • ✅ Fuzzy truth values (from fuzzy logic)
  • ✅ First-Order Logic (FOL) structure
  • Real-number domains as concrete semantics

Key Properties of Real Logic:

1. First-Order Language It uses FOL constructs:

∀x P(x)        → "For all x, P(x) is true"
∃x P(x)        → "There exists x where P(x) is true"
P(x) ∧ Q(x)   → "P(x) AND Q(x)"
P(x) → Q(x)   → "If P(x) then Q(x)"

2. Fuzzy Predicates Instead of TRUE/FALSE, predicates return values in [0,1]:

Healthy(broccoli) = 0.95
Healthy(candy) = 0.15

3. Real Domains Variables map to actual real-world objects (numbers, food items, chemicals, etc.)


Step 4: Logic Tensor Networks (LTN)

LTN is the computational framework that implements Real Logic using neural networks.

How LTN Works:

Real World Data
      ↓
[Tensor Representations]  ← objects become vectors/tensors
      ↓
[Neural Network Predicates]  ← learn fuzzy truth values
      ↓
[Real Logic Formulas]  ← combine predicates with FOL
      ↓
[Truth Value in [0,1]]  ← output

Three Core Capabilities:

CapabilityWhat it meansExample
QueryingAsk questions about data"Which foods are high in vitamin C?"
LearningTrain predicates from dataLearn what "healthy" means
ReasoningDerive new knowledgeIf food has nutrients A and B → it's balanced

Why "Tensor Networks"?

  • Objects are represented as tensors (multi-dimensional arrays)
  • This makes the framework end-to-end differentiable
  • Meaning: you can use gradient descent to learn everything!
End-to-End Differentiable = 
Every component can be optimized through backpropagation

Step 5: The Problem — What's Missing?

Real Logic (before this paper) could handle:

  • ✅ Individual facts: "Apple contains Vitamin C"
  • ✅ Universal statements: "All citrus fruits have Vitamin C"
  • ✅ Logical combinations: "If food has iron AND vitamin C → better absorption"

But it could NOT handle:

  • ❌ "What is the average vitamin C content across all fruits?"
  • ❌ "What is the total calorie count of this meal?"
  • ❌ "How many foods contain more than 50mg of iron?"

⚠️ Gap: Real Logic lacked aggregate functions — operations that summarize collections of data.


Step 6: What Are Aggregate Functions?

Aggregate functions summarize a set of values into a single value.

Common Aggregate Functions:

FunctionSymbolWhat it doesExample
AverageAVGMean of valuesAVG(vitamin_C) = 45mg
SumSUMTotal of valuesSUM(calories) = 2000
CountCOUNTNumber of itemsCOUNT(fruits) = 15
MaximumMAXHighest valueMAX(sugar) = 95g
MinimumMINLowest valueMIN(fat) = 0.1g

You Already Know These From SQL!

SELECT AVG(vitamin_c), MAX(calories)
FROM foods
WHERE category = 'fruit'

💡 Key Insight: This paper brings SQL-like aggregation into Real Logic.


Step 7: The Key Contribution — Formalizing Aggregates in Real Logic

The paper's main contribution is formally defining how aggregate functions fit into Real Logic.

The Challenge:

Real Logic formulas produce truth values in [0,1]. Aggregate functions produce numerical summaries. How do you combine them?

The Solution Framework:

Step 1: Define aggregate functions over relation tables
        AVG_x [NutrientAmount(food, x)]
        
Step 2: Use results as arguments in fuzzy predicates  
        HighVitaminC(AVG_x [VitaminC(food, x)])
        
Step 3: Combine with FOL formulas
        ∀food: HighVitaminC(AVG_x[VitaminC(food,x)]) → Healthy(food)

Why It Fits Coherently:

Real Logic is end-to-end differentiable
         +
Aggregate functions are differentiable operations
         ↓
Aggregates slot naturally into the framework!

Example — Averaging is differentiable:

AVG(x₁, x₂, x₃) = (x₁ + x₂ + x₃) / 3

Gradient with respect to x₁ = 1/3  ✅ (can backpropagate!)

Step 8: Real-World Application — FooDB

The paper demonstrates this on FooDB, a food chemistry database.

What is FooDB?

  • A real relational database
  • Contains foods and their nutrient compositions
  • Example data:
Food Table:
| food_id | name    | category |
|---------|---------|----------|
| 001     | Apple   | Fruit    |
| 002     | Spinach | Vegetable|

Nutrient Table:
| food_id | nutrient    | amount_mg |
|---------|-------------|-----------|
| 001     | Vitamin_C   | 8.4       |
| 001     | Iron        | 0.12      |
| 002     | Vitamin_C   | 28.1      |
| 002     | Iron        | 2.71      |

Example Queries Using Extended Real Logic:

Query 1: "Find foods with above-average Vitamin C"

∃food: VitaminC(food) > AVG_f[VitaminC(f)]

Query 2: "Is this food nutritionally balanced?"

Balanced(food) ← 
  HighProtein(AVG[protein(food)]) ∧ 
  AdequateVitamins(AVG[vitamins(food)]) ∧
  LowSugar(MAX[sugar(food)])

Query 3: "Rank foods by nutrient density"

NutrientDense(food) = 
  SUM[beneficial_nutrients(food)] / Calories(food)

Step 9: The Combined Framework — Three Strengths United

This extended Real Logic combines three powerful paradigms:

┌─────────────────────────────────────────────────────┐
│           Extended Real Logic Framework              │
├─────────────────┬──────────────┬────────────────────┤
│  Fuzzy          │    FOL       │   SQL-like         │
│  Predicates     │  Formulas    │   Aggregates       │
├─────────────────┼──────────────┼────────────────────┤
│ Descriptive     │ Complex      │ Summarize          │
│ statistics      │ logical      │ insights from      │
│ with degrees    │ queries &    │ data tables        │
│ of truth        │ reasoning    │                    │
├─────────────────┼──────────────┼────────────────────┤
│ "Broccoli is    │ "If food     │ "Average iron      │
│ 0.95 healthy"   │ has iron AND │ content = 2.3mg"   │
│                 │ Vit C →      │                    │
│                 │ better       │                    │
│                 │ absorption"  │                    │
└─────────────────┴──────────────┴────────────────────┘

Step 10: Summary & Big Picture

What Was Achieved:

BEFORE this paper:
Real Logic → Good at individual facts + logical reasoning
           → Could NOT aggregate over tables

AFTER this paper:
Extended Real Logic → Individual facts ✅
                   → Logical reasoning ✅  
                   → Aggregate functions ✅
                   → Database queries ✅
                   → Still fully differentiable ✅

Why This Matters:

ApplicationHow Extended Real Logic Helps
Healthcare"Average patient with condition X has nutrient Y deficiency"
Recommendation"Foods with highest average nutrient scores"
Research"Statistical patterns + logical rules combined"
DatabasesNatural language queries over relational data

Quick Review Questions

Test your understanding:

  1. What range do truth values take in Real Logic?

    Answer: [0, 1]

  2. What are the three capabilities of LTN?

    Answer: Querying, Learning, Reasoning

  3. Why couldn't original Real Logic handle "average vitamin C content"?

    Answer: It lacked aggregate functions to summarize collections

  4. Why do aggregate functions fit naturally into Real Logic?

    Answer: They are differentiable, preserving the end-to-end differentiable property

  5. Name the three paradigms combined in the extended framework:

    Answer: Fuzzy predicates, FOL formulas, SQL-like aggregates


🎯 Core Takeaway: This paper extends Real Logic by adding aggregate functions (like AVG, SUM, COUNT), enabling it to handle database-style summarization while maintaining its fuzzy reasoning and logical expressiveness — all within a fully differentiable framework suitable for machine learning.

More to study