SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Definition 6. A DeepSoftLog program  $T$  is a tuple  $(s, T_{\mathcal{F}}, T_{\mathcal{R}})$ . The soft-unification function  $s: \mathcal{U} \times \mathcal{U} \to [0,1]$  maps two embedded ground terms to the probability that they unify.  $T_{\mathcal{F}}$  is a set of ground probabilistic facts and  $T_{\mathcal{R}}$  a set of linear rules. The atoms in  $T_{\mathcal{F}}$  and  $T_{\mathcal{R}}$  can contain embedded terms.
Semantics We base the semantics of DeepSoftLog on ProbLog, by creating a source-to-source translation. The basic idea is to eliminate the embedded terms by simulating the soft-unification with a predicate  $\simeq$ . More concretely, all embedded terms in the head of a rule are replaced by a new unique variable. Next,  $\simeq$  atoms are added at the start of the body to provide the soft-unification probabilities. An example of this transformation,  $p(\sim x): -q(\sim y)$ . becomes  $p(\sim V_1): -\sim V_1 \simeq \sim x$ ,  $q(\sim y)$ .
After applying this transformation to all rules in  $T_{\mathcal{R}}$  and  $T_{\mathcal{F}}$ , we obtain a regular ProbLog program. The soft-unification function itself can also be encoded in ProbLog by adding facts for all pairs of ground terms:  $\mathfrak{p} \coloneqq \sim \mathfrak{t}_1 \simeq \sim \mathfrak{t}_2$ , where  $\mathfrak{p} = s(\mathfrak{t}_1, \mathfrak{t}_2)$ . We provide some examples of this transformation on full programs in appendix B. We note that the resulting ProbLog program can be infinite, by grounding out the soft-unification predicate  $\simeq$  on an infinite set of ground terms. However, the ProbLog semantics are still well-defined on infinite programs, due to the use of Sato's distribution semantics [30].
We note that this program transformation is only for semantics, and we still apply the soft-unification algorithm during inference. In appendix C, we prove that the soft-unification algorithm is equivalent to regular unification on the transformed program.
Non-linear rules The semantics of DeepSoftLog only allow for linear rules, but non-linear rules can be supported as syntactic sugar. Similar to Bousi~Prolog [18], we linearize rules as follows. The variable X that occurs multiple times in the head is replaced by unique variables, and  $\simeq$  predicates are added to the body to perform the soft-unification. For example, the linearization of  $\mathsf{p}(\mathbf{X},\mathbf{X}):-\mathsf{q}(\mathbf{X})$ . is  $\mathsf{p}(\mathrm{V}_1,\mathrm{V}_2): - \mathrm{V}_1\simeq \mathrm{V}_2$ $\mathsf{q}(\mathrm{V}_1)$ . This construction does entail some extra grounding work on  $\simeq$ . We need to state the  $c\simeq c$  fact for every constant  $c$ , to make sure  $\mathsf{p}(\mathbf{X},\mathbf{X})$  in this example can still succeed with non-embedded constants. Similarly, we need rules  $\mathsf{f}(\mathsf{V}_1,\dots \mathsf{V}_{\mathbf{k}})\simeq \mathsf{f}(\mathsf{W}_1,\dots \mathsf{W}_{\mathbf{k}}):-$ $\mathrm{V}_1\simeq \mathrm{W}_1,\ldots \mathrm{V}_{\mathrm{k}}\simeq \mathrm{W}_{\mathrm{k}}$  for every functor  $\mathsf{f}$  of arity  $k$ .
Inference We use proof-based inference, as described in section 2.2. Exact inference can become intractable for large experiments, so we support approximate inference techniques ( $k$ -best, maximum search depth, and maximum branching factor), similar to the Greedy NTP [26]. An important constraint we apply is that the soft-unification predicate  $\simeq$  needs to be ground upon evaluation, i.e. input mode  $(++,++)$  in Prolog. Otherwise, the number of possible unifications explodes. For example in  $a\simeq f(X)$ ,  $X$  can unify with an infinite number of ground facts:  $a\simeq f(a), a\simeq f(f(a)), a\simeq f(f(f(a))), \ldots$
During training, we can use the gradient semiring of algebraic ProbLog to make the success score end-to-end differentiable [19]. We train using the AdamW optimizer [21] with cross-entropy loss.
Structure learning As in the NTP, we can add templates to the program to do rule learning via parameter learning. For example,  $\mathbf{r}(\sim \mathbf{t}_1, \mathrm{X}, \mathrm{Y}) \coloneqq -\mathbf{r}(\sim \mathbf{t}_1, \mathrm{X}, \mathrm{Z}), \mathbf{r}(\sim \mathbf{t}_1, \mathrm{Z}, \mathrm{Y})$ . is a transitive template that could be used for the facts  $\mathbf{r}(\sim \mathbf{siblings}, \mathrm{Alice}, \mathrm{bob})$ .  $\mathbf{r}(\sim \mathbf{siblings}, \mathrm{bob}, \mathrm{charlie})$ . by learning that  $\sim \mathbf{siblings} = \sim \mathbf{t}_1$ . These templates can also parameterize the rule symbol  $\mathbf{t}_1$ , similar to the conditional theorem prover [27]:  $\mathbf{r}(\sim \mathrm{T}, \mathrm{X}, \mathrm{Y}) \coloneqq -\mathbf{r}(\sim \mathbf{f}_1(\mathrm{T}), \mathrm{X}, \mathrm{Z}), \mathbf{r}(\sim \mathbf{f}_2(\mathrm{T}), \mathrm{Z}, \mathrm{Y})$ .
We present three sets of experiments. First, we compare DeepSoftLog to the NTP on structure learning tasks, which requires learning rules from data. We show that DeepSoftLog significantly improves the performance over the NTP, and perform ablations to show that the properties introduced in section 3 are instrumental to this. The second experiment requires learning the perception, while the background knowledge is given. The last experiment is the most challenging setting, as both perception and rules need to be learned jointly. For all experiments, we report the mean and standard deviation over 10 seeds. All code is available on https://github.com/jjmoon/DeepSoftLog.
5.1 Countries
Countries is a knowledge graph with the locatedIn and neighborOf relations between the countries and continents on Earth. There are three tasks of increasing difficulty (S1, S2 and S3). For example in S2, we need to derive locatedIn(france, europe) using facts such as locatedIn(belgium, europe) and neighborOf(france, belgium). For the full experimental setup, we refer to previous work [26, 29]. To keep the comparison fair, we use the same rule templates, embedding dimensions, and training objective as the NTP. The hyperparameters can be found in appendix D.2. Table 2 reports the results and compares them with other state-of-the-art NeSy systems that support structure learning.
In figure 2, we perform ablation on the properties of DeepSoftLog, discussed in section 3. As expected, DeepSoftLog no longer properly converges when switching from probabilistic semantics to fuzzy semantics (violating property 4). Switching the soft-unification function  $s$  to a Gaussian kernel (violating property 2) also delays convergence. There is no ablation for property 3 as there is no straightforward way to violate it in DeepSoftLog.
5.2 MNIST-addition
MNIST-addition is a popular neuro-symbolic benchmark where, given two numbers as lists of MNIST images, the task is to predict the sum (e.g.  $\mathbf{52} + \mathbf{83} = 135$ ). An attractive feature of this task is
Countries	S1	S2	S3
NTP [29]	90.93 ± 15.4	87.40 ± 11.7	56.68 ± 17.6
GNTP [26]	99.98 ± 0.05	90.82 ± 0.88	87.70 ± 4.79
DeepSoftLog (Ours)	100.0 ± 0.00	97.67 ± 0.98	97.90 ± 1.00
NeuralLP [34]	100.0 ± 0.0	75.1 ± 0.3	92.2 ± 0.2
CTP [27]	100.0 ± 0.00	91.81 ± 1.07	94.78 ± 0.0
MINERVA [8]	100.0 ± 0.00	92.36 ± 2.41	95.10 ± 1.2
Table 2: AUC-PR on Countries link prediction [29]. Results are adapted from [27]. The three methods on top use templates, while the bottom ones do not.
Ablations	VP	AUC-PR
None	97.67 ± 0.98
Gödel t-norm	2, 4	23.73 ± 4.08
Gaussian kernel	2	28.33 ± 3.64
Figure 2: (Left): Ablations of DeepSoftLog on countries S2, with the corresponding properties that are violated. VP stands for violated properties. (Right): Loss curve during training of the ablations. The shaded area represents the min/max over 10 seeds, while the line is the mean.
that it allows to increase the reasoning difficulty, by increasing the number of digits. We use the same experimental setup and neural network as previous works, to which we refer for more details [22].
Existing NeSy solutions to the MNIST-addition problem typically represent all the possible sums explicitly, which means inference becomes exponential in the number of digits. DeepSoftLog allows an alternative encoding of the problem which scales linearly, by using the embeddings to represent discrete probability distributions over the digits. In each iteration, the probability distribution of the carry and the digit classifier are used to calculate the probability distribution of the sum and the next carry. This factorization of the problem is similar to the one used in A-NeSI [32], although we do not approximate and use exact inference. The program and hyperparameters are included in appendix D.1. Results are summarized in table 3.
Digits per number	1	2	4	15	100
LTN [4]	80.5 ± 23.3	77.5 ± 35.6	timeout
NeuPSL [28]	97.3 ± 0.3	93.9 ± 0.4	timeout
DeepProbLog [23]	97.2 ± 0.5	95.2 ± 1.7	timeout
NeurASP [35]	97.3 ± 0.3	93.9 ± 0.7	timeout
DeepStochLog [33]	97.9 ± 0.1	96.4 ± 0.1	92.7 ± 0.6	timeout
Embed2Sym [2]	97.6 ± 0.3	93.8 ± 1.4	91.7 ± 0.6	60.5 ± 20.4	timeout
A-NeSI [32]	97.7 ± 0.2	96.0 ± 0.4	92.6 ± 0.8	75.9 ± 2.2	overflow
DeepSoftLog (Ours)	98.4 ± 0.1	96.6 ± 0.3	93.5 ± 0.6	77.1 ± 1.6	25.6 ± 3.4
Reference	98.17	96.37	92.87	75.78	15.43
Table 3: Test accuracy of the sums on the MNIST addition problem. Results are adapted from [32]. Reference equals  $0.9907^{2d}$  where  $d$  is the number of digits per number. This is a lower bound on the performance that can be achieved when single-digit supervision is available.
The performance of DeepSoftLog is in line with previous exact systems like DeepStochLog, and we note that the improvement over other exact systems such as DeepProbLog and NeurASP is likely due to their suboptimal hyperparameters. More importantly, DeepSoftLog outperforms the more specialized systems Embed2Sym and A-NeSI, while also scaling further.
Language	(01)*	0*10*	(0 | 10*10*)*
RNN	77.63 ± 15.05	61.59 ± 10.09	50.14 ± 1.36
DeepSoftLog	83.93 ± 25.87	87.01 ± 7.18	56.12 ± 15.98
Table 4: Results for the differentiable automata experiments. We evaluate with the AUC-PR and report the average and standard deviation over 10 seeds.
5.3 Differentiable Automata
We can implement a differentiable finite state machine in DeepSoftLog by taking a regular finite state machine in Prolog and making the states and symbols embedded (see listing 1). The resulting model can be trained end-to-end, jointly learning interpretable rules and a perception network.
As an example, consider the regular language  $(01)^{*}$  represented by MNIST images. We learn from positive examples (e.g. 01 or 01) and negative examples (e.g. 01 or 00). We train on sequences of lengths up to 4 and test the generalization by evaluating on sequences of length 8 with images not seen during training. Hyperparameters are in appendix D.3.
We pre-train the perception network with 20 images, for which the ground truth image labels are given for each digit. This small amount of concept supervision prevents reasoning shortcuts [25] and eases the optimization problem. As a baseline we use an RNN, which has the same perception network and receives the same pretraining.
Results are summarized in table 4. We repeat the experiment for different regular languages. Not only does DeepSoftLog achieve a higher AUC, but it is also highly interpretable as we can inspect the learned state transitions.
There are several neuro-symbolic systems built on the principle of neural reparametrizations in a symbolic framework. DeepStochLog [33], NeurASP [35], and DeepProbLog [23] are neural extensions of stochastic grammars, answer set programming, and probabilistic logic programming respectively. Lifted Relational Neural Networks [31] and Logic Tensor Networks [4] are based on Datalog with fuzzy semantics (which cannot deal with structured terms) and use the logic program to construct the neural network. These systems make different trade-offs between expressivity and scalability, with fuzzy systems typically being more scalable and probabilistic systems being more expressive.
DeepSoftLog explores an alternative possibility, by neurally reparameterizing the matching mechanism between symbolic symbols instead of the symbols themselves. DeepSoftLog is most closely related to DeepProbLogA* [24], as they both rely on probabilistic possible worlds semantics and backward proving. Hence, it is in principle possible to convert between the two.
The Neural Theorem Prover (NTP) [29] pioneered the association of learnable embeddings with symbols in a logic prover. However, the fuzzy semantics of the NTP leads to gradient sparsity and local minima, as discussed in section 3.1. Furthermore, the NTP lacks several key features of DeepSoftLog like neural functors, recursive rules, and negation. The Greedy Neural Theorem Prover [26] improved the scalability of the NTP. The Conditional Theorem Prover [27] extended the NTP to support rule learning without templates.
The soft matching of symbols in logic is already well-studied in the fuzzy logic programming community [15]. A notable example is Bousi~Prolog [17, 18], which just like the NTP uses soft-unification and fuzzy semantics. These systems still differ considerably from DeepSoftLog as they are not differentiable, and typically rely on the user to manually specify the soft-unification function. WHIRL [6] proposed to add embeddings in DataLog for more flexible data querying. Their soft-join operation can also be seen as an early form of soft-unification, albeit not a learnable one.
Many approaches towards embedding symbols have been investigated for knowledge graphs. Recently, some of these have also been combined with symbolic methods [11, 36]. Generally, these methods are
less expressive than DeepSoftLog but far more scalable. MINERVA [8] uses reinforcement learning to predict links by walking over a knowledge graph conditional on a query.
DeepSoftLog inherits the advantages of probabilistic logic programming, but also the disadvantages. Probabilistic inference is #P-hard, so exact inference is often not tractable and we need to rely on approximate inference techniques (e.g. [1, 24]). Crucially, some approximate inference methods like  $k$ -best reintroduce the local minima problem from the NTP. So in future work, we want to consider approximate methods that incorporate a form of exploration, such as sampling methods. What still could be investigated in further work is the use of embeddings to scale up inference in NeSy as in section 5.2.
We analyzed how a more principled integration of embeddings in logic can be achieved for neuro-symbolic learning, by discussing the properties of learnable soft-unification. We discussed how previous systems do not always satisfy these, and how this can lead to optimization problems. We applied our analysis to create a framework on top of probabilistic logic programming with embeddings, called DeepSoftLog. DeepSoftLog demonstrated that two common methods to neurally extend logic, that of neural facts (as done by DeepProbLog) or neural unification (as done by the NTP) are essentially interchangeable. Lastly, we showed that DeepSoftLog can outperform existing neuro-symbolic methods on both accuracy and scalability.
This research received funding from the Flemish Government (AI Research Program), the Flanders Research Foundation (FWO) under project G097720N, the KU Leuven Research Fund (C14/18/062) and TAILOR, a project from the EU Horizon 2020 research and innovation program under GA No 952215. Luc De Raedt is also supported by the Wallenberg AI, Autonomous Systems and Software Program (WASP) funded by the Knut and Alice Wallenberg Foundation.
We thank Gabriele Venturato for giving feedback on a draft of this paper. We are also grateful to Giuseppe Marra, Victor Verreet, and Robin Manhaeve for their helpful discussions.
[1] Kareem Ahmed, Kai-Wei Chang, and Guy Van den Broeck. Semantic strengthening of neurosymbolic learning. In International Conference on Artificial Intelligence and Statistics, pages 10252–10261. PMLR, 2023.
[2] Yaniv Aspis, Krysia Broda, Jorge Lobo, and Alessandra Russo. Embed2Sym - Scalable Neuro-Symbolic Reasoning via Clustered Embeddings. Proceedings of the International Conference on Principles of Knowledge Representation and Reasoning, 19(1):421-431, July 2022.
[3] Eriq Augustine, Connor Pryor, Charles Dickens, Jay Pujara, William Yang Wang, and Lise Getoor. Visual sukoku puzzle classification: A suite of collective neuro-symbolic tasks. In Artur S. d'Avila Garcez and Ernesto Jimenez-Ruiz, editors, Proceedings of the 16th International Workshop on Neural-Symbolic Learning and Reasoning as part of the 2nd International Joint Conference on Learning & Reasoning (IJCLR 2022), Cumberland Lodge, Windsor Great Park, UK, September 28-30, 2022, volume 3212 of CEUR Workshop Proceedings, pages 15-29. CEUR-WS.org, 2022.
[4] Samy Badreddine, Artur d'Avila Garcez, Luciano Serafini, and Michael Spranger. Logic Tensor Networks. Artificial Intelligence, 303:103649, February 2022.
[5] David S. Broomhead and David Lowe. Radial Basis Functions, Multi-Variable Functional Interpolation and Adaptive Networks. Technical report, Royal Signals and Radar Establishment Malvern (United Kingdom), 1988.
[24] Robin Manhaeve, Giuseppe Marra, and Luc De Raedt. Approximate Inference for Neural Probabilistic Logic Programming. In Proceedings of the 18th International Conference on Principles of Knowledge Representation and Reasoning, pages 475-486, 2021.
[25] Emanuele Marconato, Stefano Teso, Antonio Vergari, and Andrea Passerini. Not all Neuro-Symbolic Concepts are created Equal: Analysis and Mitigation of Reasoning Shortcuts. In Advances in Neural Information Processing Systems, 2023.
[26] Pasquale Minervini, Matko Bosnjak, Tim Rocktäschel, Sebastian Riedel, and Edward Grefenstette. Differentiable Reasoning on Large Knowledge Bases and Natural Language. Proceedings of the AAAI Conference on Artificial Intelligence, 34(04):5182-5190, April 2020. Number: 04.
[27] Pasquale Minervini, Sebastian Riedel, Pontus Stenetorp, Edward Grefenstette, and Tim Rocktäschel. Learning Reasoning Strategies in End-to-End Differentiable Proving. In Proceedings of the 37th International Conference on Machine Learning, pages 6938–6949. PMLR, November 2020.
[28] Connor Pryor, Charles Dickens, Eriq Augustine, Alon Albalak, William Yang Wang, and Lise Getoor. NeuPSL: Neural Probabilistic Soft Logic. In Proceedings of the Thirty-Second International Joint Conference on Artificial Intelligence, pages 4145–4153, Macau, SAR China, August 2023. International Joint Conferences on Artificial Intelligence Organization.
[29] Tim Rocktäschel and Sebastian Riedel. End-to-end Differentiable Proving. In Advances in Neural Information Processing Systems, volume 30. Curran Associates, Inc., 2017.
[30] Taisuke Sato. A statistical learning method for logic programs with distribution semantics. In Proceedings of the 12th international conference on logic programming (ICLP'95), pages 715-729. Citeseer, 1995.
[31] Gustav Sourek, Vojtech Aschenbrenner, Filip Zelezny, Steven Schockaert, and Ondrej Kuzelka. Lifted Relational Neural Networks: Efficient Learning of Latent Relational Structures. Journal of Artificial Intelligence Research, 62:69-100, May 2018.
[32] Emile van Krieken, Thiviyan Thanapalasingam, Jakub M. Tomczak, Frank van Harmelen, and Annette ten Teije. A-NeSI: A Scalable Approximate Method for Probabilistic Neurosymbolic Inference. In Advances in Neural Information Processing Systems, 2023.
[33] Thomas Winters, Giuseppe Marra, Robin Manhaeve, and Luc De Raedt. DeepStochLog: Neural Stochastic Logic Programming. Proceedings of the AAAI Conference on Artificial Intelligence, 36(9):10090-10100, June 2022. Number: 9.
[34] Fan Yang, Zhilin Yang, and William W Cohen. Differentiable Learning of Logical Rules for Knowledge Base Reasoning. In Advances in Neural Information Processing Systems, volume 30. Curran Associates, Inc., 2017.
[35] Zhun Yang, Adam Ishay, and Joohyung Lee. NeurASP: embracing neural networks into answer set programming. In Proceedings of the Twenty-Ninth International Joint Conference on Artificial Intelligence, IJCAI'20, pages 1755-1762, Yokohama, Yokohama, Japan, January 2021.
[36] Jing Zhang, Bo Chen, Lingxi Zhang, Xinui Ke, and Haipeng Ding. Neural, symbolic and neural-symbolic reasoning on knowledge graphs. AI Open, 2:14-35, January 2021.
We first state the monotonicity of conjunction, which will be useful later.
Theorem 6. In both fuzzy and probabilistic semantics, it holds that when  $c$  is independent of both  $a$  and  $b$ , we have  $P(a) \leq P(b) \Rightarrow P(a \wedge c) \leq P(b \wedge c)$ .
Proof. In fuzzy semantics, the t-norm is monotonous by definition. Under probabilistic semantics, it follows as  $P(a \wedge c) \leq P(b \wedge c)$  reduces to  $P(a)P(c) \leq P(b)P(c)$  because of the independencies.
Proof. Suppose  $b$  is the rest of the proof, such that  $P(\pi) = P(b \wedge (t_i \simeq t_j))$  and  $P(\pi') = P(b \wedge (t_i \simeq t_k) \wedge (t_k \simeq t_j))$ . By the monotonicity of the conjunction and independence between  $b$  and the soft-unifications, it now follows that  $P(t_i \simeq t_j) \geq P((t_i \simeq t_k) \wedge (t_k \simeq t_j)) \Rightarrow P(\pi) \geq P(\pi')$ . Using the soft-unification function the first part becomes  $s(t_i, t_j) \geq s(t_i, t_k) \wedge s(t_k, t_j)$ , which is exactly the  $\wedge$ -transitivity rule.
Proof. By the monotonicity of t-norms,  $s(x,y) > s(x,z)$  and  $s(y,z) > s(x,z)$  implies  $s(x,y) \wedge s(y,z) \geq s(x,z) \wedge s(x,z)$ . Due to the idempotence of the minimum, this becomes  $s(x,y) \wedge s(y,z) \geq s(x,z)$ . On the other hand, the  $\wedge$ -transitivity of these inequalities implies  $s(x,y) \wedge s(y,z) < s(x,z)$ . This inequality is strict as  $s(x,y) = s(y,z) \leq s(x,z)$  implies either  $s(x,y) = s(x,z)$  or  $s(x,z) = s(x,z)$ .
Theorem 4. If the soft-unification function  $s$  is a  $\times$ -similarity with probabilistic semantics, we satisfy all stated properties (from Def. 1-4).
- Def. 1 follows from the well-definedness of the ProbLog semantics, by considering  $\simeq$  as a regular probabilistic fact.
- Def. 2 follows from theorem 2 as  $s$  is transitive.
- For Def. 3, we can always create a  $y$  between some symbols  $x$  and  $z$ , by taking the mean in the embedding space (see theorem 5).
- Def. 4 follows from the symmetry and differentiability of addition and multiplication. Note that we assume that  $s$  is differentiable.
Proof. We first prove that given that if  $s$  is a  $\times$ -similarity, it can be written as  $e^{-d(x,y)}$ . We do this by showing that  $d(x,y) = -\ln(s(x,y))$  is a distance.
1. As  $s(x,x) = 1$ , we have that  $d(x,x) = -\ln (s(x,x)) = -\ln (1) = 0$ .
2. The symmetry of  $d$  is implied by the symmetry of  $s$ :
$$
d (x, y) = - \ln (s (x, y)) = - \ln (s (y, x)) = d (y, x)
$$
3. The triangle inequality can be proven from the  $\times$ -transitivity, and the monotonicity of  $\ln$ :
$$
d (x, z) = - \ln (s (x, z)) \leq - \ln (s (x, y) \cdot (y, z)) = d (x, y) + d (y, z)
$$
As we do not have distinguishability (there can be a  $x \neq y$  such that  $d(x, y) = 0$ ), the embedding space is a pseudometric. The other direction can be proven in a similar fashion, by evaluating that  $e^{-d(x, y)}$  satisfies reflexivity, symmetry, and  $\times$ -transitivity.
B Example programs
We implement a variation on the alarm basian network in DeepSoftLog where the earthquake and landslide symbols are embedded. On the right, we show the translated ProbLog program.
0.2:: event(\~earthquake).
0.2:: event  $(\sim V_{1}): - \sim V_{1}\simeq \sim$  earthquake.
0.5:: hears_alarm(mary).
0.5:: hears_alarm mary).
alarm: - event(~landslide).
$calls(\mathbf{X})$  : - alarm, hears_alarm(X).
0.5::~landslide  $\simeq$  ~earthquake.
0.5::~earthquake  $\simeq$  ~landslide.
$\sim$  landslide  $\simeq$  \~ landslide.
$\sim$  earthquake  $\simeq$  \~earthquake.
Next, we also demonstrate an example with a linear rule.
$\mathbf{eq}(\mathbf{X},\mathbf{X})$
q:--eq(f(  $\sim a)$  ),f(  $\sim b$  ）).
$\mathbf{eq}(\mathrm{V}_1,\mathrm{V}_2):-\mathrm{V}_1\simeq \mathrm{V}_2.$
q: - eq(f(  $\sim$  a)),f(  $\sim$  b)).
$\mathsf{f}(\mathsf{V}_1)\simeq \mathsf{f}(\mathsf{V}_1):-\mathsf{V}_1\simeq \mathsf{V}_2.$
$\mathbf{a}\simeq \mathbf{a}.$
$\mathbf{b}\simeq \mathbf{b}$
$\sim \mathbf{a}\simeq \sim \mathbf{a}.$
0.1::  $\sim a\simeq \sim b$