1 Introduction

Recent years have shown promising examples of using symbolic background knowledge in learning systems: From training classifiers with weak supervision signals (Manhaeve et al., 2018), generalizing learned classifiers to new tasks (Roychowdhury et al., 2021), compensating for a lack of good supervised data (Diligenti et al., 2017; Donadello et al., 2017), to enforcing the structure of outputs through a logical specification (Xu et al., 2018). The main idea underlying these integrations of learning and reasoning, often called neurosymbolic integration, is that background knowledge can complement the neural network when one lacks high-quality labeled data (Giunchiglia et al., 2022). Although pure deep learning approaches excel when learning over vast quantities of data with gigantic amounts of compute (Chowdhery et al., 2022; Ramesh et al., 2022), we cannot afford this luxury for most tasks.

Many neurosymbolic methods work by creating a differentiable loss function that encodes the background knowledge (Fig. 1a). However, often the logic is discarded after training, even though this background knowledge could still be helpful at test time (Roychowdhury et al., 2021; Giunchiglia et al., 2022a). Instead, we ensure we constrain the neural network with the background knowledge, both during train time and test time, by correcting its output to satisfy the background knowledge (Fig. 1b). In particular, we consider how to make such corrections while being as close as possible to the original predictions of the neural network.

We study how to effectively and efficiently correct the neural network by ensuring its predictions satisfy the symbolic background knowledge. In particular, we consider fuzzy logics formed using functions called t-norms (Klement et al., 2000; Ross, 2010). Prior work has shown how to use a gradient ascent-based optimization procedure to find a prediction that satisfies this fuzzy background knowledge (Diligenti et al., 2017; Roychowdhury et al., 2021). However, a recent model called KENN (Clarke et al., 1993; Daniele & Serafini, 2019) shows how to compute the correction analytically for a fragment of the Gödel logic.

To extend this line of work, we introduce the concept of refinement functions and derive refinement functions for many fuzzy logic operators. Refinement functions are functions that find a prediction that satisfies the background knowledge while staying close to the neural network’s original prediction. Using a new algorithm called Iterative Local Refinement (ILR), we can combine refinement functions for different fuzzy logic operators to efficiently find refinements for logical formulas of any complexity. Since refinement functions are differentiable, we can easily integrate them as a neural network layer. In our experiments, we compare ILR with an approach using gradient ascent. We find that ILR finds optimal refinements in significantly fewer iterations. Moreover, ILR often produces results that stay closer to the original predictions or better satisfy the background knowledge. Finally, we evaluate ILR on the MNIST Addition task (Manhaeve et al., 2018) and show how to combine ILR with neural networks to solve neurosymbolic tasks.

In summary, our contributions are:

  1. 1.

    We formalize the concept of minimal refinement functions in Sect. 4.

  2. 2.

    We introduce the ILR algorithm in Sect. 5, which uses the minimal refinement functions for individual fuzzy operators to find refinements for general logical formulas.

  3. 3.

    We discuss how to use ILR for neurosymbolic AI in Sect. 6, where we exploit the fact that ILR is a differentiable algorithm.

  4. 4.

    We analytically derive minimal refinement functions for individual fuzzy operators constructed from the Gödel, Łukasiewicz, and product t-norms in Sect. 7.2.

  5. 5.

    We discuss a large class of t-norms for which we can analytically derive minimal refinement functions in Sect. 7.

  6. 6.

    We compare ILR to gradient descent approaches and show it finds refinements on complex SAT formulas in significantly fewer iterations and frequently finds solutions where gradient descent can not.

  7. 7.

    We apply ILR to the MNIST Addition task (Manhaeve et al., 2018) to test how ILR behaves when injecting knowledge into neural network models.

Fig. 1
figure 1

Comparing different approaches for constraining neural networks with background knowledge. Loss-based approaches include LTN, SBR, and Semantic Loss, while KENN, CCN(h), and SBR-CC are representatives for refinement functions. \(\textbf{x}\) represents a high-dimensional input for a neural network, \({\varvec{t}}\) represents the initial predictions of this neural network and \({\hat{{\varvec{t}}}}\) represents the refined prediction that incorporates the background knowledge

2 Related work

ILR falls into a larger body of work that attempts to integrate background knowledge expressed as logical formulas into neural networks. For an overview, see (Giunchiglia et al., 2022). Figure 1 shows two categories that most methods fall in. The first only use background knowledge during training in the form of a loss function (Badreddine et al., 2022; Xu et al., 2018; Diligenti et al., 2017; Fischer et al., 2019; Yang et al., 2022; van Krieken et al., 2022). The second considers the background knowledge as part of the model and enforces the knowledge at test time (Daniele & Serafini, 2019; Wang et al., 2019; Giunchiglia & Lukasiewicz, 2021; Ahmed et al., 2022; Hoernle et al., 2022; Dragone et al., 2021). ILR is a method in the second category. We note that these approaches can be combined (Giunchiglia et al., 2022a; Roychowdhury et al., 2021).

First, we discuss approaches that construct loss functions from the logical formulas (Fig. 1a). These loss functions measure when the deep learning model violates the background knowledge, such that minimizing the loss function amounts to “correcting” such violations (van Krieken et al., 2022). While these methods show significant empirical improvement, they do not guarantee that the neural network will satisfy the formulas outside the training data. LTN and SBR (Badreddine et al., 2022; Diligenti et al., 2017) use fuzzy logic to provide compatibility with neural network learning, while Semantic Loss (Xu et al., 2018) uses probabilistic logics. It is possible to extend the formalization of refinement functions to probabilistic logics by defining a suitable notion of minimality. One example is the KL-divergence between the original and refined distributions over ground atoms.

Among the methods where knowledge is part of the model, KENN inspired ILR (Daniele & Serafini, 2019, 2022). KENN is a framework that injects knowledge into neural networks by iteratively refining its predictions. It uses a relaxed version of the Gödel t-conorm obtained through a relaxation of the argmax function, which it applies in logit space. Closely related to both ILR and KENN is CCN(h) (Giunchiglia & Lukasiewicz, 2021), which we see as computing the minimal refinement function for stratified normal logic programs under Gödel t-norm semantics. We discuss this connection in more detail in Sect. 7.2.1.

The loss-function-based method SBR also introduces a procedure for using the logical formulas at test time in the context of collective classification (Diligenti et al., 2017; Roychowdhury et al., 2021). Unlike KENN (Daniele & Serafini, 2019), these approaches do not enforce the background knowledge during training but only use it as a test time procedure. In particular, (Roychowdhury et al., 2021) shows that doing these corrections at test time improves upon just using the loss-function approach. Unlike our analytic approach to refinement functions, SBR finds new predictions using a gradient descent procedure very similar to the algorithm we discuss in Sect. 9.1.2. We show it is much slower to compute than ILR.

Another method closely related to ILR is the neural network layer SATNet (Wang et al., 2019), which has a setup closely related to ours. However, SATNet does not have a notion of minimality and uses a different underlying logic constructed from a semidefinite relaxation. DeepProbLog (Manhaeve et al., 2018) also is a probabilistic logic, but unlike Semantic Loss is used to derive new statements through proofs and cannot directly be used to correct the neural network on predictions that do not satisfy the background knowledge. Instead, ILR can be used to inject constraints on the output of a neural network, and to prove new statements starting from the neural network predictions.

Finally, some methods are limited to equality and inequality constraints rather than general symbolic background knowledge (Fischer et al., 2019; Hoernle et al., 2022). DL2 (Fischer et al., 2019) combines these constraints into a real-valued loss function, while MultiplexNet (Hoernle et al., 2022) adds the knowledge as part of the model. However, MultiplexNet requires expressing the logical formulas as a DNF formula, which is hard to scale.

3 Fuzzy operators

We will first provide the necessary background knowledge for defining and analyzing minimal refinement functions. In particular, we will consider fuzzy operators, which generalize the connectives of classical boolean logic. For formal treatments of the study of fuzzy operators, we refer the reader to (Klement et al., 2000), which discusses t-norms and t-conorms, to Jayaram and Baczynski (2008) for fuzzy implications, to Calvo et al. (2002) for aggregation functions, and to van Krieken et al. (2022) for an analysis of the derivatives of these operators.

Table 1 Some common t-norms extended to n-arity aggregation operators

Definition 1

A function \(T: [0,1]^2\rightarrow [0, 1]\) is a t-norm (triangular norm) if it is commutative, associative, increasing in both arguments, and if for all \(t\in [0,1]\), \(T(1, t) = t\).

Similarly, a function \(S: [0, 1]^2 \rightarrow [0, 1]\) is a t-conorm if the last condition instead is that for all \(t\in [0, 1]\), \(S(0, t)=t\).

Dual t-conorms are formed from a t-norm T using \(S(t_1, t_2)=1-T(1-t_1, 1-t_2)\). We list the n-arity extensions, constructed using \(T({\varvec{t}})=T(t_1, T({\varvec{t}}_{2:n}))\), \(T(t_i)=t_i\) of three basic t-norms in Table 1. Here \({\varvec{t}}=[t_1,..., t_n]^\top \in [0, 1]^n\) is a vector of fuzzy truth values, which we will often refer to as (truth) vectors. These n-arity extensions are examples of fuzzy aggregation operators (Calvo et al., 2002).

Definition 2

A function \(I: [0, 1]^2\rightarrow [0, 1]\) is a fuzzy implication if for all \(t_1, t_2\in [0, 1]\), \(I(\cdot , t_2)\) is decreasing, \(I(t_1, \cdot )\) is increasing and if \(I(0, 0) = 1\), \(I(1, 1) = 1\) and \(I(1, 0) = 0\).

Note that fuzzy implications do not have n-ary extensions as they are not associative. The so-called S-implications are formed from the t-conorm by generalizing the material implication using \(I(a, c)=S(1-a, c)\). Furthermore, every t-norm induces a unique residuum or R-implication (Jayaram & Baczynski, 2008) \(R_T(a, c)= \sup \{ z \vert T(z, a) \le c \}\).

Logical formulas \(\varphi\) can be evaluated using compositions of fuzzy operators. We assume \(\varphi\) is a propositional logic formula, but we note the evaluation procedure can be extended to grounded first-order logical formulas on finite domains. For instance, (Daniele & Serafini, 2022) introduced a technique for propositionalizing universally quantified formulas of predicate logic in the context of KENN. Moreover, this technique can be extended to existential quantification by treating it as a disjunction. We assume a set of propositions \({\mathcal {P}}= \{P_1,..., P_n\}\) and constants \({\mathcal {C}}= \{C_1,..., C_m\}\), where each constant has a fixed value \(C_i\in [0, 1]\).

Definition 3

If T is a t-norm, S a t-conorm and I a fuzzy implication, then the fuzzy evaluation operator \(f_\varphi :[0, 1]^n\rightarrow [0,1]\) of the formula \(\varphi\) with propositions \({\mathcal {P}}\) and constants \({\mathcal {C}}\) is a function of truth vectors \({\varvec{t}}\) and given as

$$\begin{aligned}&f_{P_i}({\varvec{t}}) = t_i \end{aligned}$$
(1)
$$\begin{aligned}&f_{C_j}({\varvec{t}}) = C_j \end{aligned}$$
(2)
$$\begin{aligned}&f_{\lnot \phi }({\varvec{t}}) = 1-f_{\phi }({\varvec{t}}) \end{aligned}$$
(3)
$$\begin{aligned}&f_{\bigwedge _{j=1}^m \phi _j}({\varvec{t}}) = T(f_{\phi _1}({\varvec{t}}), ..., f_{\phi _m}({\varvec{t}})) \end{aligned}$$
(4)
$$\begin{aligned}&f_{\bigvee _{j=1}^m \phi _j}({\varvec{t}}) = S(f_{\phi _1}({\varvec{t}}), ..., f_{\phi _m}({\varvec{t}})) \end{aligned}$$
(5)
$$\begin{aligned}&f_{\phi \rightarrow \psi }({\varvec{t}}) = I(f_\phi ({\varvec{t}}), f_\psi ({\varvec{t}})), \end{aligned}$$
(6)

where we match the structure of the formula \(\varphi\) in the subscript \(f_\varphi\).

4 Minimal fuzzy Refinement functions

We will next define (fuzzy) refinement functions, which consider how to change the input arguments of fuzzy operators such that the output of the operators is a given truth value. refinement functions prefer changes to the input arguments that are as small as possible. We will introduce several definitions to facilitate studying this concept. The first is an optimality criterion.

Definition 4

(Fuzzy refinement function)

Let \(f_\varphi : [0, 1]^n\rightarrow [0,1]\) be a fuzzy evaluation operator. Then \({\hat{{\varvec{t}}}}: [0, 1]^n\) is called a refined (truth) vector for the refinement value \({\hat{t}_{\varphi }}\in [0, 1]\) if \(f_\varphi ({\hat{{\varvec{t}}}}) = {\hat{t}_{\varphi }}\).

Furthermore, let \({\min _{\varphi }}=\min _{{\hat{{\varvec{t}}}}\in [0, 1]^n} f_\varphi ({\hat{{\varvec{t}}}})\) and \({\max _{\varphi }}=\max _{{\hat{{\varvec{t}}}}\in [0, 1]^n} f_\varphi ({\hat{{\varvec{t}}}})\). Then \(\rho : [0, 1]^{n}\times [0, 1]\rightarrow [0, 1]^n\) is a (fuzzy) refinement functionFootnote 1

for \(f_\varphi\) if for all \({\varvec{t}}\in [0, 1]^n\),

  1. 1.

    for all \({\hat{t}_{\varphi }}\in [{\min _{\varphi }}, {\max _{\varphi }}]\), \(\rho ({\varvec{t}}, {\hat{t}_{\varphi }})\) is a refined vector for \({\hat{t}_{\varphi }}\);

  2. 2.

    for all \({\hat{t}_{\varphi }} < {\min _{\varphi }}\), \(\rho ({\varvec{t}}, {\hat{t}_{\varphi }})=\rho ({\varvec{t}}, {\min _{\varphi }})\);

  3. 3.

    for all \({\hat{t}_{\varphi }} > {\max _{\varphi }}\), \(\rho ({\varvec{t}}, {\hat{t}_{\varphi }})=\rho ({\varvec{t}}, {\max _{\varphi }})\).

A refinement function for \(f_\varphi\) changes the input truth vector in such a way that the new output of \(f_\varphi\) will be \({\hat{t}_{\varphi }}\). Whenever \({\hat{t}_{\varphi }}\) is high, we want the refined vector to satisfy the formula \(\varphi\), while if \({\hat{t}_{\varphi }}\) is low, we want it to satisfy its negation. When \({\hat{t}_{\varphi }}=1\), the constraint created by the formula is a hard constraint, while if it is in (0, 1), this constraint is soft. We require bounding the set of possible \({\hat{t}_{\varphi }}\) by \({\min _{\varphi }}\) and \({\max _{\varphi }}\) since if there are constants \(C_i\), or if \(\varphi\) has no satisfying (discrete) solutions, there can be formulas such that there can be no refined vectors \({\hat{{\varvec{t}}}}\) for which \(f_\varphi ({\hat{{\varvec{t}}}})\) equals 1.

Next, we introduce a notion of minimality of refinement functions. The intuition behind this concept is that we prefer the new output, the refined vector \({\hat{{\varvec{t}}}}\), to stay as close as possible to the original truth vector \({\varvec{t}}\). Therefore, we assume we want to find a truth vector near the neural network’s output that satisfies the background knowledge.

Definition 5

(Minimal refinement function) Let \(\rho ^*\) be a refinement function for operator \(f_\varphi\). \(\rho ^*\) is a minimal refinement function with respect to some norm \(\Vert \cdot \Vert\) if for each \({\varvec{t}}\in [0, 1]^n\) and \({\hat{t}_{\varphi }}\in [{\min _{\varphi }}, {\max _{\varphi }}]\), there is no refined vector \({\hat{{\varvec{t}}}}'\) for \({\hat{t}_{\varphi }}\) such that \(\Vert \rho ^*({\varvec{t}}, {\hat{t}_{\varphi }}) - {\varvec{t}}\Vert > \Vert {\hat{{\varvec{t}}}}' - {\varvec{t}}\Vert\).

For a particular fuzzy evaluation operator \(f_\varphi\), finding the minimal refinement function corresponds to solving the following optimization problem:

$$\begin{aligned} \begin{aligned} \text {For all } \quad&{\varvec{t}}\in [0,1]^n, {\hat{t}_{\varphi }} \in [{\min _{\varphi }}, {\max _{\varphi }}] \\ \min _{{\hat{{\varvec{t}}}}} \quad&\Vert {\hat{{\varvec{t}}}}- {\varvec{t}}\Vert \\ \text {such that } \quad&f_\varphi ({\hat{{\varvec{t}}}}) = {\hat{t}_{\varphi }}, \\&0 \le {\hat{t}}_i \le 1 \end{aligned} \end{aligned}$$
(7)

For some \(f_\varphi\) we can solve this problem analytically using the Karush-Kuhn-Tucker (KKT) conditions. However, while \(\Vert \cdot \Vert\) is convex, \(f_\varphi\) (usually) is not. Therefore, we can not rely on efficient convex solvers. Furthermore, for strict t-norms, finding exact solutions to this problem is equivalent to solving PMaxSAT when \({\hat{t}_{\varphi }}=1\) (Diligenti et al., 2017; Giunchiglia et al., 2022a), hence this problem is NP-complete. In Sects. 7 and 8, we will derive minimal refinement functions for a large amount of individual fuzzy operators analytically. These results are the theoretical contribution of this paper. We first discuss in Sect. 5 a method called ILR for finding general solutions to the problem of finding minimal refinement functions. ILR uses the analytical minimal refinement functions of individual fuzzy operators in a forward-backward algorithm. Then, in Sect. 6, we discuss how to use this algorithm for neurosymbolic AI.

5 Iterative local refinement

Fig. 2
figure 2

Visualization of one step of ILR for the Gödel logic and formula \(\phi = \lnot A \wedge (B \vee C)\). In the forward pass (left), ILR computes the truth value of \(\phi\). In the backward pass (right), ILR traverses the computational graph of the forward step in reverse to calculate the refined vector \({\hat{{\varvec{t}}}}\). ILR substitutes each fuzzy operator of the forward pass with the corresponding refinement function. Each refinement function receives as input the initial truth values used by the fuzzy operator in the forward step (purple lines) and the target value for the corresponding subformula. The scheduler calculates the target value \(\hat{t}'_{\lnot A \wedge (B \vee C)}\) for the entire formula, which ILR calls between the forward and backward steps (Color figure online)

We introduce a fast, iterative, differentiable but approximate algorithm called Iterative local refinement (ILR) that finds minimal refinement functions for general formulas. ILR is a forward-backward algorithm acting on the computation graph of formulas. First, it traverses the graph from its leaves to its root to compute the current truth values of subformulas. Then, it traverses the graph back from its root to the leaves to compute new truth values for the subformulas. ILR makes use of analytical minimal refinement functions to perform this backward pass. ILR is a differentiable algorithm if the fuzzy operators and their corresponding minimal refinement functions are differentiable as it computes compositions of these functions.

Algorithm 1 contains the pseudocode of ILR, and Fig. 2 presents an example of a single step (lines 3 to 7 of the algorithm) for the formula \(\varphi = \lnot A \wedge (B \vee C)\) under the Gödel semantics.

First, ILR computes the truth value of the formula in the forward pass, as shown on the left side of Fig. 2. ILR saves the truth vectors of intermediate subformulas in \({\varvec{t}}_{\textsf{sub}}\), which are presented in Fig. 2 as the numbers inside the purple shapes. Then, ILR calls a scheduler to determine the right target value for the formula \(\varphi\). The target value is \(\hat{t}'_{\varphi } = \alpha \cdot (1-0.6)=0.9\) for our example. The scheduling mechanism smooths the updates ILR makes. We implement this in line 6 of Algorithm 1. It works by choosing a different refined value at each iteration: The difference between the current truth value and the refined value is multiplied by a scheduling parameter \(\alpha\), which we choose to be either 0.1 or 1 (no scheduling). While usually not necessary, for some formulas, the scheduling mechanism allowed for finding better solutions.

Following the scheduler, ILR computes the backward step in rows from 13 to 19 in Algorithm 1. It changes the input truth vector \({\varvec{t}}\) based on the formula \(\varphi\). Note that the formula \(\varphi\) in Fig. 2 is a conjunction of two subformulas (\(\varphi _1 = \lnot A\) and \(\varphi _2 = B \vee C\)). ILR applies refinement functions recursively by treating the subformulas as literals: We give the truth values of \(\varphi _1\) and \(\varphi _2\) we saved in the forward pass, as inputs to the refinement function. In the example, we use the refinement function for the Gödel t-norm.

The refinement function updates the truth values of \(\varphi _1\) and \(\varphi _2\). Then, we interpret these new values as the target truth values for the formulas \(\varphi _1\) and \(\varphi _2\). This allows us to apply the refinement proccedure recursively. For instance, in Fig. 2, the refined truth values \(\hat{t}_{\lnot A}\) and \(\hat{t}_{B \vee C}\) can be interpreted as the target truth values for \(\lnot A\) and \(B \vee C\), respectively. Then, by applying the refinement functions for negationFootnote 2 and t-conorm, we can obtain the truth values of A, B and C.

One choice in ILR is how to combine the results from different subformulas. Indeed, when a proposition appears in multiple subformulas, it can be assigned multiple different refined values. As an example, suppose the formula of Fig. 2 was \(\varphi = \lnot A \wedge (B \vee A)\), with the proposition C replaced by A. While similar to the previous formula, A is repeated twice. Consequently, the algorithm produces two different refined values for A. We found the heuristic in line 18 generally works well, which takes the \({\hat{t}}_j\) with the largest absolute value. We also explored two other heuristics. In the first, we averaged the different refined values, but this took significantly longer to converge. The second heuristic we explored was the smallest absolute value, which frequently did not find solutions. Another choice is the convergence criterion. A simple option is to stop running the algorithm whenever it has stopped getting closer to the refined value for a couple of iterations. In our experiments, we observed that ILR monotonically decreases the distance to the refined value, after which it gets stuck on a single local optimum or oscillates between two local minima.

ILR is not guaranteed to find a refined vector \({\hat{{\varvec{t}}}}\) such that \(f_\varphi ({\hat{{\varvec{t}}}})={\hat{t}_{\varphi }}\). This is easy to see theoretically because, for many fuzzy logics like the product and Gödel logics, \({\hat{t}_{\varphi }}=1\) corresponds to the PMaxSAT problem, which is NP-complete (Diligenti et al., 2017; Giunchiglia et al., 2022a), while ILR has linear time complexity. However, this is traded off by 1) being highly efficient, usually requiring only a couple of iterations for convergence, and 2) not having any hyperparameters to tune, except arguably for the combination function. Furthermore, ILR usually converges quickly in neurosymbolic settings since background knowledge is very structured, and the solution space is relatively dense. These settings are unlike the randomly generated SAT problems we study in Sect. 9.1.3. These contain little structure the ILR algorithm can exploit.

figure a

6 Neuro-symbolic AI using ILR

The ILR algorithm can be added as a module after a neural network g to create a neurosymbolic AI model. The neural network predicts (possibly some of) the initial truth values \({\varvec{t}}\). Since both the forward and backward passes of ILR are differentiable computations, we can treat ILR as a constrained output layer (Giunchiglia et al., 2022). For instance, in Fig. 2, the input \({\varvec{t}}\) could be generated by the neural network, and we provide supervision directly on the predictions \({\hat{{\varvec{t}}}}\). With ILR, the predictions, i.e., the refined vector \({\hat{{\varvec{t}}}}\), take the background knowledge into account while staying close to the original predictions made by the neural network. Loss functions like cross-entropy can use \({\hat{{\varvec{t}}}}\) as the prediction. We train the neural network g by minimizing the loss function with gradient descent and backpropagating through the ILR layer.

One strength of ILR is the flexibility of the refinement values \({\hat{t}_{\varphi _i}}\) for each formula \(\varphi _i\). These can be set to 1 to treat \(\varphi _i\) as a hard constraint that always needs to be satisfied. Alternatively, refinement values can be trained as part of a larger deep learning model. Since ILR is a differentiable layer, we can compute gradients of the refinement values. This procedure allows ILR to learn what formulas are useful for prediction. For instance, in Fig. 2, \({\hat{t}_{\lnot A \wedge (B \vee C)}}\) can either be given or act as a parameter of the model that is learned together with the neural network parameters.

We give an example of the integration of ILR with a neural network in Fig. 3, where we use ILR for the MNIST Addition task proposed by Manhaeve et al. (2018). In this task, we have access to a training set composed of triplets (xyz), where x and y are images of MNIST (LeCun, 2010) handwritten digits, and z is a label representing an integer in the range \(\{0,...,18\}\), corresponding to the sum of the digits represented by x and y. The task consists of learning the addition function and a classifier for the MNIST digits, with supervision only on the sums. To achieve this, knowledge consisting of the rules of addition is given. For instance, the rule \(Is(x, 3) \wedge Is(y, 2) \rightarrow Is(x+y, 5)\) states that the sum of 3 and 2 is 5.

The architecture of the model presented in Fig. 3 consists of a neural network (a CNN) that performs digit recognition on the inputs x and y. After this step, ILR predicts a truth value for each possible sum. Notice that we define the CNN outputs \(\varvec{C}_x,\varvec{C}_y\in [0, 1]^{10}\) as constants, i.e., ILR does not change the predictions of the digits. Moreover, the initial prediction for the truth vector of possible sums \({\varvec{t}}_{x+y}\in [0, 1]^{19}\) is the zero vector. This allows ILR to act as a proof-based method. Indeed, similarly to DeepProbLog (Manhaeve et al., 2018), the architecture proposed in Fig. 3 uses the knowledge in combination with the predictions of the neural network to derive truth values for new statements (the sum of the two digits). We apply the loss function to the final predictions \(\hat{{\varvec{t}}}_{x+y}\). During learning, the error is back-propagated through the entire model, reaching the CNN, which learns to classify the MNIST images from indirect supervision.

We present the results obtained by ILR in Sect. 9.2, and compare its performance with other neurosymbolic AI frameworks.

Fig. 3
figure 3

Neurosymbolic architecture based on ILR for the MNIST Addition task. A CNN takes two images of MNIST digits, returning their classification. The CNN predictions are concatenated with a vector of zeros, representing the initial prediction for the Addition task. We perform an ILR step to update the sum of the two numbers, which is the final output of the model

7 Analytical minimal refinement functions

Having introduced the ILR algorithm, we next study the problem of finding minimal refinement functions for individual fuzzy operators. We need these in closed form to compute the ILR algorithm, as ILR uses them during the backward pass. This section first discusses several transformations of minimal refinement functions and gives the minimal refinement functions of the basic t-norms Gödel, Łukasiewicz  and product. In Sect. 8, we investigate a large class of t-norms for which we have closed-form formulas for the minimal refinement functions.

7.1 General results

We first provide several basic results on minimal refinement functions for fuzzy operators. In particular, we will consider formulas such as \(\varphi =\bigwedge _{i=1}^n P_i \bigwedge _{i=1}^m C_i\), that is, conjunctions of propositions and constants. As an abuse of notation, from here on, we will refer to \({\min _{\varphi }}\) and \({\max _{\varphi }}\) when evaluated by the t-norm T as \({\min _{T}}\) and \({\max _{T}}\) and will do so also for other fuzzy operators. We find using Definition 1 that for some t-norm T, \({\min _{T}} = 0\) and \({\max _{T}} = T({\varvec{c}})\), where \({\varvec{c}}\) is the values of the constants \(C_1,..., C_m\) as a truth vector, while for some t-conorm S, \({\min _{S}} = S({\varvec{c}})\) and \({\max _{S}}=1\). Note that for \(m=0\), \({\max _{T}}=1\) and \({\min _{S}}=0\). Next, we find some useful transformations of minimal refinement functions to derive new results:

Proposition 1

Consider the formulas \(\phi =\bigwedge _{i=1}^n P_i\bigwedge _{i=1}^m C_i\) and \(\psi = \lnot (\bigvee _{i=1}^n P_i \bigvee _{i=1}^m C_i)\). Assume \(\rho ^*_\phi\) is a minimal refinement function for \(f_\phi\) evaluated using t-norm T. Consider \(f_{\psi }({\varvec{t}})\) evaluated using dual t-conorm S of T. Then \(\rho ^*_{\psi }({\varvec{t}}, {\hat{t}_{\psi }})=\varvec{1}-\rho ^*_{\phi }(\varvec{1}-{\varvec{t}}, {\hat{t}_{\psi }})\) is a minimal refinement function for \(f_{\psi }\).

Proof

First, note \(f_{\psi }({\varvec{t}}) = 1-S({\varvec{t}}, {\varvec{c}}) = 1-(1-T(\varvec{1}-{\varvec{t}}, \varvec{1}- {\varvec{c}}))=T(\varvec{1}-{\varvec{t}}, \varvec{1}-{\varvec{c}})\). Consider \({\varvec{t}}'=\varvec{1}-{\varvec{t}}\). By the assumption of the proposition, \(\rho ^*_\phi ({\varvec{t}}', {\hat{t}_{\phi }})\) is a minimal refinement function for \(T({\varvec{t}}', \varvec{1}-{\varvec{c}})=T(\varvec{1}-{\varvec{t}}, \varvec{1}-{\varvec{c}})=f_\psi ({\varvec{t}})\). Furthermore, note that

$$\begin{aligned} f_\psi (\rho ^*_{\psi }({\varvec{t}}, {\hat{t}_{\psi }}))=T(\varvec{1}-\rho ^*_{\psi }({\varvec{t}}, {\hat{t}_{\psi }}), \varvec{1}-{\varvec{c}}) =T(\rho ^*_\phi ({\varvec{t}}', {\hat{t}_{\psi }}), \varvec{1}-{\varvec{c}}) = {\hat{t}_{\psi }} \end{aligned}$$

\(\square\)

An analogous argument can be made for \(\phi '=\bigvee _{i=1}^n P_i\bigvee _{i=1}^m C_i\) and \(\psi =\lnot (\bigwedge _{i=1}^n P_i\bigwedge _{i=1}^m C_i)\) to show that, given minimal refinement function \(\rho ^*_{\phi '}\) of dual t-conorm S, the minimal refinement function for \(f_{\psi }({\varvec{t}})\) is \(\rho ^*_{\psi }({\varvec{t}}, {\hat{t}_{\psi }})=\varvec{1}-\rho ^*_{\phi }(\varvec{1}-{\varvec{t}}, {\hat{t}_{\psi }})\).

We will use this result to simplify the process of finding minimal refinement functions for the t-norms and dual t-conorms. For example, assume we have a minimal refinement function \(\rho ^*_T\) for \({\hat{t}_{T}}\in [T({\varvec{t}}), {\max _{T}}]\). Let S be the corresponding dual t-conorm. Then, we can change the constraint \(S({\hat{{\varvec{t}}}}, {\varvec{c}})={\hat{t}_{S}}\) in Eq. 7 to the equivalent constraint \(\varvec{1}-S({\hat{{\varvec{t}}}}, {\varvec{c}})=\varvec{1}-{\hat{t}_{S}}\). We then use Proposition 1 to find the minimal refined vector for \({\hat{t}_{S}}\in [{\min _{S}}, S({\varvec{t}})]\) as \(\varvec{1}-\rho ^*_T(\varvec{1}-{\varvec{t}}, 1-{\hat{t}_{S}})\).

Proposition 2

Consider the formulas \(\phi = P_1 \vee P_2\) and \(\psi = \lnot P_1 \vee P_2\). Assume \(\rho ^*_\phi\) is a minimal refinement function for \(f_\phi\) evaluated using the t-conorm S, and define \({\varvec{t}}'=[1-t_1, t_2]\). Then \(\rho ^*_{\psi }({\varvec{t}}, {\hat{t}_{\psi }})=\left[ 1-\rho ^*_{\phi }({\varvec{t}}', {\hat{t}_{\psi }})_1, \rho ^*_{\phi }({\varvec{t}}', {\hat{t}_{\psi }})_2\right] ^\top\) is a minimal refinement function for \(f_{\psi }\).

Proof

First, note \(f_{\psi }({\varvec{t}}) = S(1-{\varvec{t}}_1, {\varvec{t}}_2)\). By the assumption of the proposition, \(\rho ^*_\phi ({\varvec{t}}', {\hat{t}_{\psi }})\) is a minimal refinement function for \(S({\varvec{t}}')=f_\psi ({\varvec{t}})\). Furthermore, note that

$$\begin{aligned}&f_\psi (\rho ^*_{\psi }({\varvec{t}}, {\hat{t}_{\psi }})) = S(1-\rho ^*_\psi ({\varvec{t}}', {\hat{t}_{\psi }})_1, \rho ^*_\psi ({\varvec{t}}', {\hat{t}_{\psi }})_2) \\&= S(1-(1-\rho ^*_\phi ({\varvec{t}}', {\hat{t}_{\psi }})_1), \rho ^*_\phi ({\varvec{t}}', {\hat{t}_{\psi }})_2) = S(\rho ^*_\phi ({\varvec{t}}', {\hat{t}_{\psi }})) = {\hat{t}_{\psi }}. \end{aligned}$$

\(\square\)

Similar to the previous proposition, this proposition gives us a simple procedure for finding the minimal refinement functions for the S-implication of some t-conorm.

7.2 Basic T-norms

In this section, we introduce the minimal refinement functions for the t-norms and t-conorms of the three main fuzzy logics (Gödel, Łukasiewicz, and Product). In particular, we consider when these t-norms and t-conorms can act on both propositions and constants, that is, \(\varphi =\bigwedge _{i=1}^n t_i \bigwedge _{i=1}^m C_i\), which is evaluated with \(T({\varvec{t}}, {\varvec{c}})\). We present the main results with simple examples.

7.2.1 Gödel t-norm

In this section, we derive minimal refinement functions for the Gödel t-norm and t-conorm for the family of p-norms.

Proposition 3

The minimal refinement function of the Gödel t-norm for \({\hat{t}_{T_G}}\in [0, \min _{i=1}^m C_i]\) is

$$\begin{aligned} \rho ^*_{T_G}({\varvec{t}}, {\hat{t}_{T_G}})_i={\left\{ \begin{array}{ll} {\hat{t}_{T_G}} &{} \text {if } {\hat{t}_{T_G}} \ge T_G({\varvec{t}}) \text{ and } t_i< {\hat{t}_{T_G}}, \\ {\hat{t}_{T_G}} &{} \text {if } {\hat{t}_{T_G}} < T_G({\varvec{t}}) \text{ and } i=\arg \min _{j=1}^n t_j, \\ t_i &{} \text{ otherwise, } \end{array}\right. } \end{aligned}$$
(8)

The minimal refinement function of the Gödel t-conorm and \({\hat{t}_{S_G}} \in [\max _{i=1}^m C_i, 1]\) is

$$\begin{aligned} \rho ^*_{S_G}({\varvec{t}}, {\hat{t}_{S_G}})_i={\left\{ \begin{array}{ll} {\hat{t}_{S_G}} &{} \text {if } {\hat{t}_{S_G}} \ge S_G({\varvec{t}}) \text{ and } i=\arg \max _{j=1}^m t_j, \\ {\hat{t}_{S_G}} &{} \text {if } {\hat{t}_{S_G}} < S_G({\varvec{t}}) \text{ and } t_i > {\hat{t}_{S_G}}, \\ 0 &{} \text{ otherwise. } \end{array}\right. } \end{aligned}$$
(9)

Proof

Follows from Propositions 1, 10 and 11, see Appendix A.1.1 and 1. \(\square\)

Proposition 4

A minimal refinement function of the Gödel implication \(R_G(t_1, t_2)={\left\{ \begin{array}{ll}t_2 &{} \text {if } t_1 > t_2, \\ 1 &{} \text {otherwise.}\end{array}\right. }\) for \({\hat{t}_{R_G}}\in [{\min _{R_G}}, {\max _{R_G}}]\) is

$$\begin{aligned} \rho ^*_{R_G}(t_1, t_2, {\hat{t}_{R_G}}) = {\left\{ \begin{array}{ll} {[}\max ({\hat{t}_{R_G}} + \epsilon , t_1), {\hat{t}_{R_G}}]^\top &{} \text {if } {\hat{t}_{R_G}} < 1 \\ {[}t_1, \max (t_1, t_2)]^\top &{} \text {otherwise.} \end{array}\right. } \end{aligned}$$
(10)

where \(\epsilon\) is an arbitrarily small positive number.

The proof is in Appendix A.1.3.

Fig. 4
figure 4

Gödel minimal refinement functions. The grey bars represent the initial truth vectors \({\varvec{t}}\); the light blue and purple lines indicate the initial truth value of the formula and the revision value \({\hat{t}_{\varphi }}\), and the orange bars are the corresponding minimal refined vectors. a t-conorm; b t-conorm with two literals with same truth value; c t-norm (Color figure online)

The bar plot in Fig. 4a shows an example for the Gödel t-conorm with four literals. The minimal refined vector is represented with the orange boxes, while the initial and refinement values of the entire formula are represented as a blue and purple line respectively. Here, our goal is to increase the value of the t-conorm, i.e., the maximum value. Increasing other literals up to \({\hat{t}_{\varphi }}\) would require longer orange bars and bigger values for the L\(_p\) norm. Figure 4b represents when multiple literals have the largest truth value. Here, only one should be increasedFootnote 3. Finally, Fig. 4c shows the refined vector for the Gödel t-norm. Since the smallest truth value should be at least \({\hat{t}_{\varphi }}\), we simply ensure all truth values are at least \({\hat{t}_{\varphi }}\).

Our results are closely related to that of Giunchiglia and Lukasiewicz (2021), which considers hard constraints, i.e., \({\hat{t}_{\varphi }}=1\). In the hierarchical multi-label classification setting, the authors introduce an output layer that ensures predictions satisfy a set of hierarchy constraints. This layer corresponds to applications of the minimal refinement function for the Gödel implication with \({\hat{t}_{R_G}}=1\). Furthermore, (Giunchiglia & Lukasiewicz, 2021) introduces CCN(h). This method considers an output layer that ensures predictions satisfy background knowledge expressed in a stratified normal logic program. The authors introduce an iterative algorithm that computes the minimal solution for such programs. This algorithm is related to that of ILR in Sect. 5. However, their formalization differs somewhat from ours, and future work could study whether these results also hold for our formalization of minimal refinement functions and if they can be extended to any value of \({\hat{t}_{\varphi }}\). Finally, (Giunchiglia & Lukasiewicz, 2021) introduces a loss function compensating for gradient bias introduced by the constrained output layer.

7.2.2 Łukasiewicz t-norm

In this section, we derive minimal refinement functions for the Łukasiewicz t-norm and t-conorm, for the family of p-norms. We will start using the following notation here: \({\varvec{t}}^\uparrow\) refers to the truth values \(t_i\) sorted in ascending order, while \({\varvec{t}}^\downarrow\) refers to the truth values sorted in descending order.

Proposition 5

Let \({\hat{t}_{T_L}}\in [0, \max (\Vert {\varvec{c}}\Vert _1 - (m - 1), 0)]\) and define \(\lambda _K=\frac{{\hat{t}_{T_L}}+ m + K -1-\Vert {\varvec{c}}\Vert _1 - \sum _{i=1}^ Kt^\uparrow _{i}}{K}\). Let \(K^ *\) be the largest integer \(1\le K\le n\) such that \(\lambda _{K}<1-t^ \uparrow _{K}\). Then the minimal refinement vector of the Łukasiewicz t-norm is

$$\begin{aligned} \rho ^*_{T_L}({\varvec{t}}, {\hat{t}_{T_L}})_i={\left\{ \begin{array}{ll} t_i + \lambda _{K^*} &{} \text {if } {\hat{t}_{T_L}}> T_L({\varvec{t}}) \text { and } t_i \le t^\uparrow _{K^*}, \\ 1 &{} \text {if } {\hat{t}_{T_L}}> T_L({\varvec{t}}) \text { and } t_i > t^\uparrow _{K^*}, \\ t_i - \frac{\max (\Vert {\varvec{t}}\Vert _1 + \Vert {\varvec{c}}\Vert _1 + 1 - n - {\hat{t}_{T_L}}, 0)}{n} &{} \text {otherwise.} \end{array}\right. } \end{aligned}$$
(11)

Let \({\hat{t}_{S_L}} \in [\min (\Vert {\varvec{c}}\Vert _1, 1), 1]\) and define \(\lambda _K = \frac{\Vert {\varvec{t}}\Vert _1 + \Vert {\varvec{c}}\Vert _1 - {\hat{t}_{S_L}}}{K}\). Let \(K^*\) be the largest integer \(1\le K\le n\) such that \(\lambda _K < t^\downarrow _{K}\). Then the minimal refinement function of the Łukasiewicz t-conorm is

$$\begin{aligned} \rho ^*_{S_L}({\varvec{t}}, {\hat{t}_{S_L}})_i={\left\{ \begin{array}{ll} t_i + \frac{\max ({\hat{t}_{S_L}}-\Vert {\varvec{t}}\Vert _1 - \Vert {\varvec{c}}\Vert _1, 0)}{n} &{} \text {if } {\hat{t}_{S_L}} > S_L({\varvec{t}}), \\ t_i - \lambda _{K^*} &{} \text {if } {\hat{t}_{S_L}} < S_L({\varvec{t}}) \text{ and } t_i \ge t^\downarrow _{K^*}, \\ 0 &{} \text {otherwise.} \end{array}\right. } \end{aligned}$$
(12)

Proof

This follows from Propositions 1, 12 and 13, see Appendix A.2.1 and A.2.2. \(\square\)

Although slightly obfuscated, these refinement functions simply increase each of the literals equally, while properly dealing with constraints on the truth values. We explain this using Fig. 5, where the optimal solution corresponds to a vector that, from the original truth values \({\varvec{t}}\), is perpendicular to the contour line of the operator at the value \({\hat{t}_{\varphi }}\). Moreover, the figure also provides some intuition for our proofs. The stationary points of the Lagrangian correspond to the points where the constraint function (blue circumference) tangentially touches the contour line of the refined value (orange line).

Fig. 5
figure 5

Łukasiewicz minimal refinement functions. The orange line corresponds to the contour line of the \(S_L\) and \(T_L\) at the value \({\hat{t}_{\varphi }}\). The dotted blue circumference corresponds to a set of points at an equal distance from \({\varvec{t}}\). a t-conorm; b t-norm; c t-norm in the limit case

The change applied by the refinement function is proportional to the refinement value \({\hat{t}_{}}\). Computing these refinement functions requires finding \(K^*\), which can be done efficiently in log-linear time using a sort on the input truth values and a binary search.

The residuum of the Łukasiewicz t-norm is equal to its S-implication formed using \(S_L(1-a, c)\), and so its minimal refinement function can be found using Proposition 2.

The Łukasiewicz logic is unique in containing large convex and concave fragments (Giannini et al., 2019). In particular, any CNF formula interpreted using the weak conjunction (Godel t-norm) and Łukasiewicz t-conorm is concave, allowing for efficient maximization using a quadratic program of a slightly relaxed variant of the problem in Eq. 7. (Giannini et al., 2019) studies this property in a setting similar to ours in the context of collective classification. Future work could study using this convex fragment to find minimal refinement functions for more complex formulas.

7.2.3 Product t-norm

To present the three basic t-norms together, we give the closed-form refinement function for the product t-norm with the \(L_1\) norm. Our proof is a special case of the general results on a large class of t-norms we will discuss in Sect. 7. In particular, the product t-norm is a strict, Schur-concave t-norm with an additive generator. It is an example of a t-norm for which we can find a closed-form refinement function for the \(L_1\) norm using Propositions 15 and 1. First, we show the minimal refinement function for the product t-norm.

$$\begin{aligned} \rho ^*_{T_P}({\varvec{t}}, {\hat{t}_{T_P}})_i= {\left\{ \begin{array}{ll} \root n-K^* \of {\frac{{\hat{t}_{T_P}}}{\prod _{j=1}^{K^*}t_j^\downarrow \prod _{j=1}^mC_j}} &{} \text {if } T_P({\varvec{t}}, {\varvec{c}}) > {\hat{t}_{T_P}} \text { and } t_i \le t^\downarrow _{K^*+1}, \\ \sqrt{\frac{{\hat{t}_{T_P}}}{\prod _{j\ne i}t_i^\downarrow \prod _{i=1}^mC_i}} &{} \text {if } T_P({\varvec{t}}, {\varvec{c}}) < {\hat{t}_{T_P}} \text { and } i=\arg \min _{j=1}^n t_j, \\ t_i &{} \text {otherwise.} \end{array}\right. } \end{aligned}$$
(13)

Next, we present the result for the product t-conorm:

$$\begin{aligned} \rho ^*_{S_P}({\varvec{t}}, {\hat{t}_{S_P}})_i= {\left\{ \begin{array}{ll} 1-\sqrt{\frac{1-{\hat{t}_{S_P}}}{\prod _{j\ne i}1-t_i^\downarrow \prod _{i=1}^m1-C_i}} &{} \text {if } S_P({\varvec{t}}, {\varvec{c}}) < {\hat{t}_{S_P}} \text { and } i=\arg \min _{j=1}^n t_j, \\ 1-\root n-K^* \of {\frac{1-{\hat{t}_{S_P}}}{\prod _{j=1}^{K^*}1-t_j^\downarrow \prod _{j=1}^m1-C_j}} &{} \text {if } S_P({\varvec{t}}, {\varvec{c}}) > {\hat{t}_{S_P}} \text { and } t_i \le t^\downarrow _{K^*+1}, \\ t_i &{} \text {otherwise.} \end{array}\right. } \end{aligned}$$
(14)

This refined function increases all the literals smaller than a certain threshold up to the threshold itself, where we assume \({\hat{t}_{T_P}}\) is greater than the initial truth value. In fact, like the other t-norms in the class discussed in Sect. 8, it is similar to the Gödel t-norm in that it increases all literals above some threshold to the same value. Similarly, the refinement function for the t-conorm increases the highest literal. Figure 6 gives an intuition behind this behavior.

Fig. 6
figure 6

Product minimal refinement functions. The grey areas represent the truth value of the operator associated with the initial vector \({\varvec{t}}\). Red and blue areas represent the refined values when increasing a single literal. a t-conorm; b t-norm; c t-norm when multiple literals have the same truth value. The green area represents the improvement obtained by increasing both literals equally (Color figure online)

Finally, the residuum minimal refinement function can be found with \(\rho ^*_{I_P}(t_1, t_2, {\hat{t}_{I_P}}) = [t_1, \frac{{\hat{t}_{I_P}}}{t_1}]^\top\).

We also studied the minimal refinement function for the \(L_2\)-norm, but concluded that the result is a 2nth degree polynomial with no simple closed-form solutions. For details, see Appendix D

8 A general class of t-norms with analytical minimal refinement functions

In this section, we will introduce and discuss a general class of t-norms that have analytic solutions to the problem in Eq. 7 to find their corresponding minimal refinement functions. We can find those for the t-norm, the t-conorm, and the residuum.

8.1 Background on t-norms

To be able to adequately discuss this class of t-norms, we first have to provide some more background on the theory of t-norms.

Definition 6

A t-norm T is Archimedean if for all \(x, y\in (0, 1)\), there is an n such that \(T(\underbrace{x,\dots ,x}_{n\times })<y\).

A continuous t-norm T is strict if, in addition, for all \(x\in (0, 1)\), \(0< T(x, x) < x\).

8.1.1 Additive generators

The study of t-norms frequently involves the study of their additive generator (Klement et al., 2000, 2004), which are univariate functions that construct t-norms, t-conorms, and residuums.

Definition 7

A function \(g: [0, 1]\rightarrow [0, \infty ]\) such that \(g(1)=0\) is an additive generator if it is strictly decreasing, right-continuous at 0, and if for all \(t_1, t_2\in [0, 1]\), \(g(t_1)+g(t_2)\) is either in the range of \(g\) or in \([g(0^{+}), \infty ]\).

Theorem 1

If \(g\) is an additive generator, then the function \(T: [0, 1]^n\rightarrow [0, 1]\) defined as

$$\begin{aligned} T({\varvec{t}}) = g^{-1}(\min (g(0^+), \sum _{i=1}^n g(t_i))) \end{aligned}$$
(15)

is a t-norm.

Using Eq. 15, the function g acts like an invertible function. It transforms truth values into a new space that can be seen as measuring ‘untruthfulness’. \(\sum _{i=1}^n g(t_i)\) can be seen as a measure of the ‘untruth’ of the conjunction. T-norms constructed in this way are necessarily Archimedean, and each continuous Archimedean t-norm has an additive generator. \(T_P\), \(T_L\) and \(T_D\) have an additive generator, but \(T_G\) and \(T_N\) do not. Furthermore, if \(g(0^+)=\infty\), T is strict and we find \(T({\varvec{t}})=g^{-1}(\sum _{i=1}^n g(t_i))\). The residuum constructed from continuous t-norms with an additive generator can be computed using \(g^{-1}(\max (g(c)-g(a), 0))\) (Jayaram & Baczynski, 2008).

8.1.2 Schur-concave t-norms

We will frequently consider the class of Schur-concave t-norms, with their dual t-conorms and residuums formed from these Schur-concave t-norms. We denote with \({\varvec{t}}^\downarrow\) the truth vector \({\varvec{t}}\) sorted in descending order, and with \({\varvec{t}}^ \uparrow\) as \({\varvec{t}}\) sorted in ascending order.

Definition 8

A vector \({\varvec{t}}\in {\mathbb {R}}^n\) is said to majorize another vector \({\varvec{u}}\in {\mathbb {R}}^ n\), denoted \({\varvec{t}}\succ {\varvec{u}}\), if \(\sum _{i=1}^n t_{i}=\sum _{i=1}^n {u_i}\) and if for each \(i\in \{1,..., n\}\) it holds that \(\sum _{j=1}^i t_{ j}^\downarrow \ge \sum _{j=1}^i u_{j}^\downarrow\).

Definition 9

A function \([0, 1]^ n\rightarrow [0,1]\) is called Schur-convex if for all \({\varvec{t}}, {\varvec{u}}\in [0, 1]^n\), \({\varvec{t}}\succ {\varvec{u}}\) implies that \(f({\varvec{t}}) \ge f({\varvec{u}})\). Similarly, a Schur-concave function has that \({\varvec{t}}\succ {\varvec{u}}\) implies that \(f({\varvec{t}}) \le f({\varvec{u}})\).

The dual t-conorm of a Schur-concave t-norm is Schur-convex. The three basic and continuous t-norms \(T_G\), \(T_P\) and \(T_L\) are Schur-concave. There are also non-continuous Schur-concave t-norms, such as the Nilpotent minimum (Takači, 2005; van Krieken et al., 2022). The drastic t-norm is an example of a t-norm that is not Schur-concave (Takači, 2005). This class includes all quasiconcave t-norms since all symmetric quasiconcave functions are also Schur-concave (Schur-concave 2011, see p98, Prop.C.3). Therefore, this class constitutes a significant class of relevant t-norms. For a more precise characterization of Schur-concave t-norms, see (Takači, 2005; Alsina, 1984).

8.2 Minimal refinement functions for Schur-concave t-norms

We now have the background to discuss several useful and interesting results on Schur-concave t-norms. First, we present two results that characterize Schur-concave minimal refinement functions. We use the notion of “strictly cone-increasing” functions here that is discussed in Appendix B.1.

Theorem 2

Let T be a Schur-concave t-norm that is strictly cone-increasing at \({\hat{t}_{T}}\) and let \(\Vert \cdot \Vert\) be a strict norm. Then there is a minimal refined vector \({{\varvec{t}}^*}\) for \({\varvec{t}}\) and \({\hat{t}_{T}}\) such that whenever \(t_i> t_j\), then \({t^*}_i - t_i\le {t^*}_j - t_j\).

For proof, see Appendix C.1. We note that we can make this argument in the other direction to show that any Schur-convex t-conorm will have a minimal refined vector such that \(t_i> t_j\) implies \({t^*}_i \ge {t^*}_j\). Furthermore, if we know that a t-norm has a unique minimal refinement function, we can use this theorem to infer a useful ordering on how it changes the truth values.

Next, we will consider the \(L_1\) norm \(\sum _{i=1}^n\vert {\hat{t}}_i - t_i\vert\), for which we can find general solutions for the t-norm, t-conorm and R-implication when the t-norm is Schur-concave.

Proposition 6

Let \({\varvec{t}}\in [0, 1]^n\) and let T be a Schur-concave t-norm that is strictly cone-increasing at \({\hat{t}_{T}}\in [T({\varvec{t}}, {\varvec{c}}), {\max _{T}}]\). Then there is a value \(\lambda \in [0, 1]\) such that the vector \({{\varvec{t}}^*}\),

$$\begin{aligned} {t^*}_i = {\left\{ \begin{array}{ll} \lambda , &{} \text {if } t_i < \lambda , \\ t_i, &{} \text {otherwise,} \end{array}\right. } \end{aligned}$$
(16)

is a minimal refined vector for T and the \(L_1\) norm at \({\varvec{t}}\) and \({\hat{t}_{T}}\).

For proof, see Appendix C.2. We found this result rather surprising: It is optimal for a large class of t-norms and the \(L_1\) norm to increase the lower truth values to some value \(\lambda\). In this sense, these solutions are very similar to that of the Gödel refinement functions. The value of \(\lambda\) depends on the choice of t-norm and \(T({{\varvec{t}}^*}, {\varvec{c}})\) is a non-decreasing function of \(\lambda\). We show in Sect. 8.3 how to compute these.

We have a similar result, proof in the end of Appendix C.2, for the refinement functions of Schur-convex t-conorms. This proposition shows that, under the \(L_1\) norm, it is optimal to increase only the largest literal, just like with the Gödel t-norm.

Proposition 7

Let \({\varvec{t}}\in [0, 1]^n\) and let S be a Schur-convex t-conorm that is strictly cone-increasing at \({\hat{t}_{S}}\in [S({\varvec{t}}, {\varvec{c}}), 1]\). Then there is a value \(\lambda \in [0, 1]\) such that the vector \({{\varvec{t}}^*}\),

$$\begin{aligned} {t^*}_i = {\left\{ \begin{array}{ll} \lambda &{} \text {if } i={\arg \max }_{i\in D}t_i, \\ t_i, &{} \text {otherwise,} \end{array}\right. } \end{aligned}$$
(17)

is a minimal refined vector for S and the \(L_1\) norm at \({\varvec{t}}\) and \({\hat{t}_{S}}\).

8.3 Closed forms using additive generators

Where the previous section gives general results on the form or “shape” of minimal refinement functions for t-norms and t-conorms under the \(L_1\) norm, we still need to figure out what the value of \(\lambda\) is for a particular \({\hat{t}_{\varphi }}\). Luckily, additive generators will do the job here.

Proposition 8

Let T be a Schur-concave t-norm with additive generator g and let \(0<{\hat{t}_{T}}\in [T({\varvec{t}}, {\varvec{c}}), {\max _{T}}]\). Let \(K\in \{0,..., n-1\}\) denote the number of truth values such that \({t^*}_i=t_i\) in Eq. 28.

Then using

$$\begin{aligned} \lambda _K = g^ {-1}\left( \frac{1}{n-K}\left( g({\hat{t}_{T}}) -\sum _{i=1}^K g(t^\downarrow _i) - \sum _{i=1}^m g(C_i)\right) \right) \end{aligned}$$
(18)

in Eq. 28 gives \(T({{\varvec{t}}^*}, {\varvec{c}})={\hat{t}_{T}}\) if \({{\varvec{t}}^*}\in [0, 1]^n\).

See Appendix C.2 for a proof. \(g({\hat{t}_{T}})\) can be seen as the ‘untruth’-value in g-space that \({{\varvec{t}}^*}\) should attain. Since we have \(n-K\) truth values that we can move freely, we need to make sure that their ‘untruth’-value in g-space is \(g({\hat{t}_{T}})/(n-K)\). However, we also need to handle the truth values we cannot change freely, which is why those are subtracted from \(g({\hat{t}_{T}})\).

We should note that this does not yet give a procedure for computing the correct \(K\in \{0,..., n-1\}\). The intuition here is that we should find an K such that \(t_i \ge \lambda _K\) for the K largest values, and \(t_i < \lambda _K\) for the remaining \(n-K\). Like with computing the \(K^*\) for the refinement function for the Łukasiewicz t-norm (Sect. 7.2.2), we can do this in logarithmic time after sorting \({\varvec{t}}\), but we choose to compute \(\lambda _K\) for each \(K\in \{0, n-1\}\) in parallel.

We can similarly find a closed form for the t-conorms:

$$\begin{aligned} \lambda&= 1 - g^{-1}\left( g(1-{\hat{t}_{S}}) - \sum _{i\ne j}g(1-t_i) - \sum _{i=1}^m g(1-C_i)\right) \end{aligned}$$
(19)

Proposition 9

Let \(t_1, t_2\in [0,1]\) and let T be a strict Schur-concave t-norm with additive generator g. Consider its residuum \(R(t_1, t_2)=\sup \{z\vert T(t_1, z)\le t_2\}\) that is strictly cone-increasing at \(0<{\hat{t}_{R}}\in [R(t_1, t_2), {\max _{R}}]\). Then there is a value \(\lambda \in [0, 1]\) such that \({{\varvec{t}}^*}=[t_1, g^{-1}(g({\hat{t}_{R}}) + g(t_1))]^\top\) is a minimal refined vector for R and the \(L_1\) norm at \({\varvec{t}}\) and \(t\).

Here, we find that for this class of residuums, increasing the consequent (the second argument of the implication) is minimal for the \(L_1\) norm. This update reflects modus ponens reasoning: When the antecedent is true, increase the consequent. As we have argued in van Krieken et al. (2022), this could cause issues in many machine learning setups: Consider the modus tollens correction instead decreases the antecedent. For common-sense knowledge, this is more likely to reflect the true state of the world.

9 Experiments

We performed experiments on two tasks. The first one does not involve learning. Instead, we aim to solve SAT problems. This experiment allows assessing whether ILR can enforce complex and unstructured knowledge. The second experiment is on the MNIST Addition task (Manhaeve et al., 2018) to test ILR in a neurosymbolic setting and assess its ability to learn from data.

9.1 Experiments on 3SAT problems

With this experiment, we aim to determine how quickly ILR finds a refined vector and how minimal this vector is. We test this on formulas of varying complexity to analyze for what problems each algorithm performs well.Footnote 4

9.1.1 Setup

We perform experiments on SATLIB (Hoos, 2000), a library of randomly generated 3SAT problems. 3SAT problems are formulas in the form \(\bigwedge _{i=1}^c \bigvee _{j=1}^3 l_{ij}\), where \(l_{ij}\) is a literal that is either \(P_k\) or \(\lnot P_k\) and where \(P_k\in \{P_1,..., P_n\}\) is an input proposition. In particular, we consider uf20-91 of satisfiable 3SAT problems with \(n=20\) propositions and \(c=91\) disjunctive clauses. For this, we select the refined value \({\hat{t}_{\varphi }}\) to be 1. We also experiment with \({\hat{t}_{\varphi }}\in \{0.3, 0.5\}\) in Appendix E . We uniformly generate initial truth values for the propositions \({\varvec{t}}\in [0,1]^d\).Footnote 5 To allow experimenting with formulas of varying complexity, we introduce a simplified version of the task which uses only the first 20 clauses.

We use three metrics to compare ILR with a gradient descent baseline described in Sect. 9.1.2. The first is speed: How many iterations does it take for each algorithm to converge? Since both algorithms have similar computational complexities, we will use the number of iterations for this. The second is satisfaction: Is the algorithm able to find a solution with truth value \({\hat{t}_{\varphi }}\)? Finally, we consider minimality: How close to the original prediction is the refined vector \({\hat{{\varvec{t}}}}\)? Note that the refinement function for the product logic is only optimal for the \(L_1\) norm, while for Gödel and Łukasiewicz, the refinement function is optimal for all L\(_p\) norms, including \(L_1\). Moreover, the results of \(L_1\) and \(L_2\) are very similar. Therefore, we use the \(L_1\) as a metric for minimality for each t-norm.

9.1.2 Gradient descent baseline

We compare ILR to gradient descent with the following loss function

$$\begin{aligned} \mathcal {L}(\hat{\textbf{z}}, {\varvec{t}}, {\hat{t}_{\varphi }})= \Vert f_\varphi (\sigma (\hat{\textbf{z}})) - {\hat{t}_{\varphi }}\Vert _2 + \beta \Vert \sigma (\hat{\textbf{z}}) - {\varvec{t}}\Vert _p. \end{aligned}$$
(20)

Here \({\hat{{\varvec{t}}}}= \sigma (\hat{\textbf{z}})\) is a real-valued vector \(\hat{\textbf{z}}\in {\mathbb {R}}^n\) transformed to \({\hat{{\varvec{t}}}}\in [0, 1]^n\) using the sigmoid function \(\sigma\) to ensure the values of \({\hat{{\varvec{t}}}}\) remain in \([0,1]^n\) during gradient descent. The first term minimizes the distance between the current truth value of the formula \(\varphi\) and the refinement value. In contrast, the second term is a regularization term that minimizes the distance between the refined vector and the original truth value \({\varvec{t}}\) in the \(L_p\) norm. \(\beta\) is a hyperparameter that trades off the importance of this regularization term.

This method for finding refined vectors is very similar to the collective classification method introduced in SBR (Diligenti et al., 2017; Roychowdhury et al., 2021). The main difference is in the \(L_p\) norms chosen, as we use squared error for the first term instead of the \(L_1\) norm. Gradient descent is a steepest descent method that takes steps minimizing the \(L_2\) norm. Therefore, it can also be seen as a method for finding minimal refinement functions given the \(L_2\) norm. The coordinate descent algorithm is the corresponding steepest descent method for the \(L_1\) norm. Future work could compare how coordinate descent performs for finding minimal refinement functions for the \(L_1\) norm. We suspect it will be much slower than gradient descent-based methods as it can only change a single truth value each iteration.

We found that ADAM (Kingma & Ba, 2015) significantly outperformed standard gradient descent in all metrics, and we chose to use it throughout our experiments. Furthermore, inspired by the analysis of the derivatives of aggregation operators in van Krieken et al. (2022), we slightly change the formulation of the loss function for the Łukasiewicz t-norm and product t-norm. The Łukasiewicz t-norm will have precisely zero gradients for most of its domain. Therefore, we remove the \(\max\) operator when evaluating the \(\bigwedge\) in the SAT formula, so it has nonzero gradients. For the product t-norm, the gradient will also approach 0 because of the large set of numbers between [0, 1] that it multiplies. As suggested by van Krieken et al. (2022), we instead optimize the logarithm of the product t-norm:

$$\begin{aligned} \mathcal {L}_P(\hat{\textbf{z}}, {\varvec{t}}, {\hat{t}_{\varphi }})= \Vert \sum _{i=1}^c \log f_{\bigvee _{j=1}^3}(\sigma ({\varvec{t}})) - \log {\hat{t}_{\varphi }}\Vert _2 + \beta \Vert \sigma (\hat{\textbf{z}}) - {\varvec{t}}\Vert _1. \end{aligned}$$

9.1.3 Results

Fig. 7
figure 7

Comparison of ILR with ADAM on uf20-91 in SATLIB. The target Refined value is 1.0. The x-axis corresponds to the number of iterations, while the y-axis is the value of \({\hat{t}_{\varphi }}\) in the first row of the grid and the \(L_1\) norm in the second row. The number in parentheses represents the schedule parameter for ILR and the regularization parameter \(\beta\) for ADAM. Note that ADAM’s plots often almost perfectly overlap

In Fig. 7, we show the results obtained by ILR and ADAM on the three t-norms (one for each grid column). We observe that ILR with schedule parameter \(\alpha =0.1\) has a smoother plot than ILR with \(\alpha =1.0\), which converges faster: In our experiments, the number of steps until convergence was always between 2 and 5. For both values of the scheduling parameters, ILR outperforms ADAM in terms of convergence speed.

When comparing satisfaction and minimality, the behaviour differs based on the t-norm. In the case of Łukasiewicz, all methods find feasible solutions to the optimization problem. Furthermore, in terms of minimality (i.e., \(L_1\) norm), ILR finds better solutions than ADAM.

For the Gödel logic, no method can reach a feasible solution. Here, ILR with schedule parameter \(\alpha =1\) performs very poorly, obtaining worse solutions than the original truth values. On the other hand, with \(\alpha = 0.1\), it performs as well as ADAM for both metrics but with faster convergence.

Finally, for the product logic, ILR fails to increase the satisfaction of the formula to the refined value. However, ADAM can find much better solutions, getting the average truth value to around 0.5. Still, it is far from reaching a feasible solution. Nonetheless, we recommend using ADAM for complicated formulas in the product logic.

However, we argue that in the context of Neural-Symbolic Integration, the provided knowledge is usually relatively easy to satisfy. With 91 clauses, there are few satisfying solutions in this space of \(2^ {21}\) possible binary solutions. However, background knowledge usually does not constrain the space of possible solutions as heavily as this. For this reason, we propose a simplified formula, where we only use 20 out of 91 clauses. Figure 8 shows the results for this setting. We see that ILR with no scheduling (\(\alpha =1\)) finds feasible solutions for all t-norms. ILR finds solutions for the Gödel t-norm where ADAM cannot find any, while for Łukasiewicz and product, it finds solutions in much fewer iterations and with a lower \(L_1\) norm. Hence, we argue that for knowledge bases that are less constraining, ILR without scheduling is the best choice.

Fig. 8
figure 8

Comparison of ILR with ADAM on the uf20-91 with 20 clauses. Target value 1.0

9.2 Experiments on MNIST addition

The experiments on the SATLIB benchmark show how well ILR can enforce knowledge in highly constrained settings. However, as already mentioned, in neurosymbolic AI, the background knowledge is typically much simpler. SAT benchmarks often only have a few solutions, heavily limiting what predictions the neural network can make. Moreover, previous experiments only tested ILR where initial truth vectors are random, and we did not have any neural networks or learning.

To evaluate the performance of ILR in neurosymbolic settings, we implemented the architecture of Fig. 3. Here, the task is to learn a classifier for handwritten digits while only receiving supervision on the sums of pairs of digits.

9.2.1 Setup

We follow the architecture of Fig. 3. We use the neural network proposed by Manhaeve et al. (2018), which is a network composed of two convolutional layers, followed by a MaxPool layer, followed by a fully connected layer with ReLU activation function and a fully connected layer with softmax activation. We use the Gödel t-norm and corresponding minimal refinement functions. Note that Gödel implication can only increase the consequent and can never decrease the antecedents. For this reason, ILR converges in a single step.

We set both \(\alpha\) and target value \(\hat{t}\) to one, meaning that we ask ILR to satisfy the entire formula in one step. We use the ADAM optimizer and a learning rate of 0.01, with the cross-entropy loss function. However, since the outputs of the ILR step do not sum to one, we cannot directly apply it to the refined vector ILR computes. To overcome this issue, we add a logarithm followed by a softmax as the last layers of the model. If the sum of the refined vector is one, the composition of the logarithm and softmax functions corresponds to the identity function. Moreover, these two layers are monotonic increasing functions and preserve the order of the refined vector.

We use the dataset defined in Manhaeve et al. (2018) with 30000 samples, and also run the experiment using only 10% of the dataset (3000 samples). We run ILR for 5 epochs on the complete dataset, and 30 epochs on the small one. We repeat this experiment 10 times. We are interested in the accuracy obtained in the test set for the addition task. We ran the experiments on a MacBook Pro (2016) with a 3,3 GHz Dual-Core Intel Core i7.

9.2.2 Results

Table 2 Results on the MNIST addition task.

ILR can efficiently learn to predict the sum, reaching results similar to state of the art, requiring, on average, 30 s per epoch. However, sometimes ILR got stuck in a local minimum during training, where the accuracy reached was close to 50%. It is worth noticing that LTN suffers from the same problem (Badreddine et al., 2022), with results strongly dependent on the initialization of the parameters. To better understand this local minimum, we analyzed the confusion matrix. Figure 9 shows one of the confusion matrices for a model stuck in the local minimum: the CNN recognizes each digit either as the correct digit minus one or plus one. Then, our model obtains the correct prediction in close to 50% of the cases. For example, suppose the digits are a 3 and a 5. The 3 is classified as a 2 or a 4, while the 5 is classified as a 4 or a 6. If the model predicts 2 and 6 or 4 and 4, it returns the correct sum (8). Otherwise, it does not. We believe that in these local minima, there is no way for the model to change the digit predictions without increasing the loss, and the model remains stuck in the local minimum.

Fig. 9
figure 9

Confusion matrix on the MNIST classification for a local minimum

Table 2 shows the results in terms of accuracy of ILR, LTN (Badreddine et al., 2022) and DeepProblog (Manhaeve et al., 2018). To calculate the accuracy, we follow (Badreddine et al., 2022) and select only the models that do not stop in a local minimum. Notice that this problem is rare for ILR (once every 30 runs) and happens more frequently with LTN (once every 5 runs).

10 Conclusion and future work

We analytically studied a large class of minimal fuzzy refinement functions. We used refinement functions to construct ILR, an efficient algorithm for general formulas. Another benefit of these analytical results is to get a good intuition into what kind of corrections are done by each t-norm. In our experimental evaluation of this algorithm, we found that our algorithm converges much faster and often finds better solutions than the baseline ADAM, especially for less constraining problems. However, we conclude that for complicated formulas and product logic, ADAM finds better results. Finally, we assess ILR on the MNIST Addition task and show it can be combined with a neural network, providing results similar to two of the most prominent methods for neurosymbolic AI.

There is a lot of opportunity for future work on refinement functions. We will study how the refinement functions induced by different t-norms perform in practical neurosymbolic integration settings. On the theoretical side, possible future work could be considering analytical refinement functions for certain classes of complex formulas. Furthermore, there are many classes of t-norms and norms for which finding analytical refinement functions is an open problem. Another promising avenue for research is designing specialized loss functions that handle biases in the gradients arising from combining constrained output layers with cross-entropy loss functions (Giunchiglia & Lukasiewicz, 2021). We also want to highlight the possibility of extending the work on fuzzy refinement functions to probabilistic refinement functions, using a notion of minimality such as the KL-divergence.