## Diagram: Code Snippets from Three Neural-Symbolic Programming Frameworks
### Overview
The image displays three distinct code snippets, each contained within a colored box, representing different programming frameworks or languages for defining probabilistic logical models, likely for a digit recognition and addition task. The frameworks are labeled as **DomiKnowS**, **DeepProbLog**, and **Scallop**. The layout is asymmetrical, with the DomiKnowS box occupying the left half, and the DeepProbLog and Scallop boxes stacked vertically on the right half.
### Components/Axes
The image is a technical diagram composed of three primary components:
1. **Left Box (Light Beige Background):** Titled "DomiKnowS". Contains Python-like code defining concepts and logical relationships.
2. **Top-Right Box (Light Pink Background):** Titled "DeepProbLog". Contains Prolog-style syntax with neural network integration.
3. **Bottom-Right Box (Light Green Background):** Titled "Scallop". Contains Python code using a context object to define relations and rules.
### Detailed Analysis / Content Details
#### **1. DomiKnowS (Left Box)**
This section contains Python code defining a model structure.
* **Line 1:** `image = Concept()`
* **Line 2-3:** `digit = image(ConceptClass=NumericalConcept)`
* **Line 5:** `image_pair = Concept()`
* **Line 6-9:** `(pair_d0, pair_d1) = image_pair.has_a(digit0=image, digit1=image)`
* **Line 11-13:** `s = image_pair(ConceptClass=EnumConcept, values=summations)`
* **Line 15:** `...` (Ellipsis indicating omitted code)
* **Line 16-22:** A multi-line statement beginning with `sum_combinations.append(` and containing an `andL` function call with nested `getattr` calls specifying paths `('x', pair_d0)` and `('x', pair_d1)`.
* **Line 23:** `...` (Ellipsis indicating omitted code)
#### **2. DeepProbLog (Top-Right Box)**
This section contains logic programming syntax.
* **Line 1-2:** `nn(m_digit, [X], Y, [0....9]):: digit(X,Y).` - Defines a neural network predicate `digit(X,Y)` where `Y` is a digit from 0 to 9, inferred from input `X` by network `m_digit`.
* **Line 4-6:** `addition(X,Y,Z) :- digit(X,X2), digit(Y,Y2), Z is X2+Y2.` - Defines an `addition` rule: `Z` is the sum of `X2` and `Y2`, where `X2` and `Y2` are the digit values of inputs `X` and `Y`.
#### **3. Scallop (Bottom-Right Box)**
This section contains Python code interacting with a Scallop context (`scl_ctx`).
* **Line 1-4:** `scl_ctx.add_relation("digit_1", int, input_mapping=list(range(10)))` - Adds a relation named "digit_1" of type integer, with an input mapping over the list of integers from 0 to 9.
* **Line 5-8:** `self.scl_ctx.add_relation("digit_2", int, input_mapping=list(range(10)))` - Adds a second relation named "digit_2" with the same structure.
* **Line 9-11:** `self.scl_ctx.add_rule("sum_2(a + b) :- digit_1(a), digit_2(b)")` - Adds a logical rule defining `sum_2` as the sum of `a` and `b`, where `a` and `b` come from the `digit_1` and `digit_2` relations.
* **Line 12-14:** `self.sum_2 = self.scl_ctx.forward_function("sum_2", output_mapping=[(i,) for i in range(19)])` - Creates a forward function for the `sum_2` rule, with an output mapping over tuples for integers from 0 to 18 (the possible range of summing two single-digit numbers).
### Key Observations
1. **Common Task:** All three snippets model the same fundamental problem: recognizing digits from images and computing their sum.
2. **Divergent Paradigms:**
* **DomiKnowS:** Uses an object-oriented, concept-based approach with explicit class definitions (`Concept`, `NumericalConcept`, `EnumConcept`) and relationship mapping (`has_a`).
* **DeepProbLog:** Uses a logic programming (Prolog) paradigm extended with neural network predicates (`nn/4`) and standard logical rules.
* **Scallop:** Uses a Python API to declaratively add relations and rules to a context, then compiles them into a differentiable forward function.
3. **Abstraction Level:** DomiKnowS and Scallop operate at a higher level of abstraction within Python, while DeepProbLog uses a distinct logic syntax.
4. **Output Specification:** The Scallop snippet explicitly defines the output range (0-18) for the sum, which is implicit in the other two frameworks.
### Interpretation
This diagram serves as a comparative technical illustration, showcasing the syntactic and conceptual differences between three prominent frameworks for neuro-symbolic AI. It demonstrates how each framework approaches the integration of neural perception (digit recognition) with symbolic reasoning (addition).
* **DomiKnowS** emphasizes a structured, ontological view of the problem domain, defining concepts and their relationships explicitly. Its code reads like a domain model definition.
* **DeepProbLog** stays closest to traditional logic programming, seamlessly embedding a neural network as a probabilistic predicate within a Prolog-like knowledge base. The logic is concise and declarative.
* **Scallop** provides a hybrid Pythonic interface that blends relational database-style declarations (`add_relation`) with logic rules, ultimately producing a differentiable program. The explicit `output_mapping` suggests a focus on compile-time optimization for execution.
The side-by-side presentation allows a technical viewer to quickly contrast the programming models, verbosity, and underlying philosophies of these systems for solving an identical, simple task. The choice of framework would depend on factors like the developer's preferred paradigm (logic vs. OO vs. declarative Python), the need for explicit type/range definitions, and the desired level of integration with existing Python codebases.