Hypergraphs in logic programming? Medina Juan Carlos Díaz-Moreno1[0000−0001−7673−2046] , Jesús , and José R. Portillo2,3[0000−0002−0940−068X] 1[0000−0002−3931−5873] Department of Mathematics. University of Cádiz, Spain {juancarlos.diaz,jesus.medina}@uca.es https://www.uca.es 2 Departamento de Matemática Aplicada 1, Universidad de Sevilla, Spain https://ma1.us.es Instituto Universitario de Investigación de Matemáticas de la Universidad de Sevilla (IMUS), Spain. https://imus.us.es josera@us.es 1 3 Abstract. Heterogeneous data is a significant topic in today’s context, necessitating the development of AI tools. Logic programming is a powerful approach for extracting information from datasets, enabling the interpretation of natural language as logical rules. This paper introduces a novel representation of logic normal programs, which include negated variables, using labeled hypergraphs. This representation provides a comprehensive characterization of the program, capturing all available information and relationships among variables in a specific hypergraph. Such characterization is highly advantageous, particularly for computing program consequences and models through hypergraph theory. Keywords: Logic Programming · hypergraphs · negation operator. 1 Introduction When resolving real problems, it is common to have access to large amounts of heterogeneous data that need to be handled in order to correctly solve these problems. To achieve this goal, Artificial Intelligence (AI) provides essential tools and advancements [11, 20, 21, 23, 24]. One of these tools is logic programming, which has widely been developed from a theoretical point of view and an applied point of view [2, 4, 5, 12, 13, 17]. ? Partially supported by the 2014–2020 ERDF Operational Programme in collaboration with the State Research Agency (AEI) in project PID2019-108991GB-I00, with the Ecological and Digital Transition Projects 2021 of the Ministry of Science and Innovation in project TED2021-129748B-I00, and with the Department of Economy, Knowledge, Business and University of the Regional Government of Andalusia in project FEDER-UCA18-108612, and by the European Cooperation in Science & Technology (COST) Action CA1712 2 J. C. Díaz-Moreno et al. Natural language can be interpreted in logic rules, from which the diverse logic programming approaches can obtain information of the dataset being considered [14, 18, 19]. In natural language, the negation of linguistic variables is common, making it important to be able to handle logic programs with negation operators [15, 22, 25]. However, the computation of consequences (models) from these programs is more complex. The utilization of graph theory has proven to be remarkably advantageous [6] as it facilitates a better understanding of the relationships among variables within the program. However, the traditional representation of these programs using “dependency graphs” fails to capture the complete information of the logic program. To overcome this limitation, recent research has successfully employed hypergraphs [1] as an alternative representation for logic programs, addressing this drawback [7, 8]. In this paper, we introduce a novel representation for logic normal programs using labeled hypergraphs. This representation enables us to incorporate the details of the rules (operators, negation, propositional symbols) into labeled hyperarcs, graphically capturing the comprehensive information of a general logic normal program, including those within the multi-adjoint framework [3, 4]. Consequently, the termination results obtained for “positive” logic programs can be extended to encompass general logic normal programs, even within the multi-adjoint framework. Additionally, a notable feature is that strongly pathconnected components can identify subprograms where efficient procedural semantics, developed for computing the least model of "positive" logic programs, can be applied. This allows translating the consequences to its neighboring strongly path-connected components, resulting in a more efficient mechanism for obtaining stable models in logic normal programs. 2 Preliminaries Some basic notions, necessary for the development of this paper, are recalled. 2.1 Multi-adjoint normal logic programming First, the notion of adjoint pair, the basic operator on this framework, which generalizes left-continuous t-norm and their residuated implication. Definition 1. Given a partially ordered set (P, ≤), the pair (& , ←) is an adjoint pair with respect to (P, ≤) if the mappings & , ← : P × P → P satisfy that: 1. & is order-preserving in both arguments. 2. ← is order-preserving in the first argument (the consequent) and orderreversing in the second argument (the antecedent). 3. The equivalence x ≤ z ← y if and only if x & y ≤ z holds, for all x, y, z ∈ P . The considered algebraic structures are recalled next. Hypergraphs in logic programming 3 Definition 2. A multi-adjoint normal lattice is a tuple (L, , ←1 , &1 , . . . , ←n , &n , ¬) verifying the following properties: 1. 2. 3. 4. (L, ) is bounded lattice (i.e., it has bottom (⊥) and top (>) elements); (&i , ←i ) is an adjoint pair in (L, ), for all i ∈ {1, . . . , n}; > &i ϑ = ϑ &i > = ϑ, for all ϑ ∈ L and i ∈ {1, . . . , n}; ¬ : L → L is a decreasing mapping whith ¬(>) = ⊥, ¬(⊥) = >. Definition 3. A local multi-adjoint normal Σ-algebra L is a multi-adjoint normal lattice (L, , ←1 , &1 , . . . , ←n , &n , ¬) on which other operators are defined, such as conjunctors ∧1 , . . . , ∧k , disjunctors ∨1 , . . . , ∨l and general aggregators @1 , . . . , @h . The set of those monotonic operators (aggregator operators, in particular) in the Σ-algebra will be denoted as A; that is, A = {&1 , . . . , &n , ∧1 , . . . , ∧k , ∨1 , . . . , ∨l , @1 , . . . , @h , ¬} and each operator @ : Lm → L in A satisfies the boundary condition with the top element: @(>, . . . , >, x, >, . . . , >) x (1) | {z } | {z } s m−s−1 for all x ∈ L. Considering a local multi-adjoint normal Σ-algebra L, a set of propositional symbols Π and a language denoted as F, we introduce the definition of multiadjoint normal logic program (a set of rules). Definition 4. A multi-adjoint normal logic program is a set of rules of the form hA ←i B, ϑi such that: The rule A ←i B is a formula of F. The confidence factor ϑ is an element (a truth-value) of L. The head of the rule A is a propositional symbol of Π. The body formula B is a formula of F of the form @[B1 , . . . , Bs , ¬Bs+1 , . . . , ¬Br ] built from propositional symbols B1 , . . . , Br (r ≥ 0, Bi 6= Bj , for i 6= j ) by the use of conjunctors &1 , . . . , &n and ∧1 , . . . , ∧k , disjunctors ∨1 , . . . , ∨l , aggregators @1 , . . . , @m and elements of L (which composition is represented by @). 5. Facts are rules with the body >. 1. 2. 3. 4. Example 1. In this example, the adjoint pairs corresponding to the product Gödel and Lukasiewicz t-norms, (&P , ←P ), (&G , ←G ), (&Ł , ←Ł ) are considered, together with the weighted sums @(3,1) and @(1,2) defined as @(3,1) (x, y) = 3x + y x + 2y and @(1,2) (x, y) = , for every (x, y) ∈ [0, 1]2 . Moreover, the nega4 3 tion ¬, defined as ¬(x) = 1 − x for x ∈ [0, 1], will also be taken into account in the program. Specifically, the following normal program P will be analyzed in the rest of the paper: 4 J. C. Díaz-Moreno et al. hc ←P n &P ¬u, 0.8i hn ←P c, 0.8i hn ←P @(1,2) (¬h, ¬f), 0.6i hh ←P f, 0.7i hu ←G h &Ł f, 0.7i hf ←P u, 0.9i ha ←P @(3,1) (¬u, ¬f), 1.0i hf ←P 1.0, 0.1i hn ←P 1.0, 0.5i hu ←P 1.0, 0.2i Now, we recall the notions of interpretation and induced ordering on the interpretations set. Definition 5. An interpretation is a mapping I : Π → L. The set of all interpretations is denoted as IL . Each of these interpretations, I, is uniquely extended to the set of formulae ˆ by the unique homomorphic extension theorem. The F, getting the function I, ordering on the truth-values lattice L induces an ordering v on the set of interpretations IL , which is a bounded lattice. Following, the notions of satisfiability and model, in which is based the semantic of multi-adjoint logic normal programming, are recalled. Definition 6. Given an interpretation I ∈ IL , a weighted rule hA ←i B, ϑi is ˆ ←i B). An interpretation I ∈ IL is a model of a satisfied by I, if ϑ I(A multi-adjoint normal logic program P if all weighted rules in P are satisfied by I. The immediate consequences operator, given by van Emden and Kowalski [9], is defined in this framework as follows. Definition 7. Given a multi-adjoint normal logic program P, the immediate consequences operator TP maps interpretations to interpretations, and for an interpretation I and an arbitrary propositional symbol A is defined as ˆ TP (I)(A) = sup{ϑ&i I(B) | hA ←i B, ϑi ∈ P} One of the most important properties of TP , when P is a “positive” program (no negation appear in the program) is that its least fixed-point lfp(TP ) coincides with the least model of the program P [16] and is obtained iterating the TP operator from the least interpretation M. However, this is not true on logic normal programs and other semantics need to be considered, such as the computation of answer sets and stable models [15, 22, 25]. Other necessary notions for our purpose, in the topic of termination results, are the following. Definition 8. Let P be a multi-adjoint normal logic program, and A ∈ Π. The set RPI (A) of relevant values for A with respect to an interpretation I is the set ˆ of maximal values of the set {ϑ&i I(B) | hA ←i B, ϑi ∈ P}. Definition 9. Let P be a multi-adjoint normal logic program with respect to a multi-adjoint Σ-algebra L and a set of propositional symbols Π. We say that TP terminates for every query if for every propositional symbol A, there is a finite n such that TPn (M)(A) is identical to lfp(TP )(A). For the program introduced in Example 1, a stable model is obtained from the iteration of the immediate consequence operator TP from the least interpretation M. In Table 1 we show the results of the iterations of this program. However, this iteration could not converge to a stable model in general [3, 15]. Hypergraphs in logic programming 5 Table 1. Iteration of the TP operator from the least interpretation M. f M TP (M) TP2 (M) TP3 (M) TP4 (M) TP5 (M) TP6 (M) 2.2 0 0.1 0.18 0.18 0.18 0.18 0.18 h 0 0 0.07 0.126 0.126 0.126 0.126 u 0 0.2 0.2 0.2 0.2 0.2 0.2 c 0 0 0.3840 0.3584 0.32896 0.321792 0.321792 n 0 0.6 0.56 0.514 0.5028 0.5028 0.5028 a 0 1 0.825 0.805 0.805 0.805 0.805 Basic definitions of hypergraphs Basic notions of (hyper)graph theory can be seen in [1]. A directed hypergraph is a pair of sets (V, E), where the elements of E are called directed hyperedges or hyperarcs and each of them is an ordered pair, e = (T (e), H(e)), of disjoint subsets of vertices [10]. We denote T (e) as the tail of e and H(e) as its head. In the following, when no confusion arises, directed hypergraphs will simply be called hypergraphs. See [8] for definitions of sub(directed)hypergraph and directed hypergraph induced by the subset of vertices V 0 ⊆ V . An edge labeling is a function from E to a set of labels and we say that a hypergraph with an edge labeling is an edge-labeled hypergraph. A B-graph is a hypergraph in which all the heads of its hyperarcs have only one element [10]. This paper will only consider these kinds of directed hypergraph, namely labeled B-graphs, as a natural representation of rules in a multi-adjoint normal logic program. Every directed hypergraph is associated with a digraph [1]. Note that the correspondence is not injective because multiple directed hypergraphs can be associated with the same digraph. 3 Logic normal programs through hypergraphs This section will illustrate how a flexible multi-adjoint normal logic program can be represented by a specific edge-labeled directed B-graph. Given a multi-adjoint normal logic program P, we will compute a B-graph HP as follows: 1. Vertices: every propositional symbol in the program (Π) will determine a vertex of the hypergraph. For instance, in Example 1, we obtain that V (HP ) = {a, c, f, h, n, u}. 2. Hyperarcs: A hyperarc e will be computed from every rule in the program P. Specifically, given a rule hA ←i @[B1 , . . . , Bs , ¬Bs+1 , . . . , ¬Br ], ϑi 6 J. C. Díaz-Moreno et al. the tail T (e) will be composed by the propositional symbols of the body of the rule, that is, T (e) = {B1 , . . . , Bs , Bs+1 , . . . , Br }. The head H(e) of the hyperarc is the propositional symbol of the head of the rule, that is, H(e) = {A}. 3. Labels: The hyperarc is labeled with a 4-vector (i, @, {Bs+1 , . . . , Br }, ϑ). If only one propositional symbol appears in the body (no operator appears in the body), no symbol is included. Figure 1 shows the B-graph HP associated with the program P given in Example 1. Notice that the resulting hypergraph obtained from this procedure is an (P, @(1,2) , {h, f }, 0.6) ) .7 ,0 ,∅ ,∅ (P h ( G ,& L (P, &P ,{u},0.8) ,∅ ,0 f (P, ∅, ∅, 0.9) (P, ∅, ∅, 0.8) n (P, @(3,1) , {u, f }, 1) a .7 ) c u Fig. 1. Edge-labeled B-graph associated with the program given in Example 1. The facts of the program (rules 8, 9 and 10 of Example 1) are not shown by simplicity. edge-labeled directed B-graph. Moreover, the original logic normal program can be reconstructed from this hypergraph, thereby obtaining a hypergraph-based characterization of the given program. It is worth mentioning that the transformation complexity of a program into a B-graph is linear, dependent on the number of variables and clauses involved. Consequently, this characterization enables us to leverage existing results and algorithmic developments related to directed hypergraphs for the analysis of fuzzy logic normal programs. Notably, the computation of connected components is one of the essential research topics in graph theory. In our study, we will utilize the concept of strongly path-connected components in hypergraphs, which provides a vertex set partition. Definition 10. Given a hypergraph H. – A vertex u is weakly reachable from v if there is a directed path of hyperarcs from v to u. A directed path of hyperarcs from v to u will be denoted as Pvu . – A pair of vertices u and v of a directed hypergraph are said to be strongly path-connected if u is weakly reachable from v and v is weakly reachable from u. – A strongly path-connected component, spc-component in short, is one of the equivalence classes associated with the equivalence relation R defined as R = {(u, v) ∈ V × V | u and v are strongly path-connected in H} Hypergraphs in logic programming 7 As a consequence of the definition, we have that the vertices in each cycle in a hypergraph belong to the same strongly path-connected component. Moreover, it is possible that a strongly path connected component be composed of only one vertex. In Example 1, the hypergraph associated with the given program has three spc-components, which are depicted in Figure 2. One of them is the singleton {a}, and the other two are {f, h, u} and {c, n}. The spc-components of a hypergraph provide an interesting partition of the hyperarcs into two subsets. Definition 11. Given a hypergraph H, a d-hyperarcs is a hyperarc satisfying that every vertex of its tail belongs to a different spc-component from the one containing the vertex of its head; that is, no vertex of its tail belongs to the spccomponent of its head. A s-hyperarc is a hyperarc verifying that at least a vertex of its tail belongs to the same spc-component as the vertex of its head. Figure 2 shows the edge-labeled B-graph associated with the multi-adjoint normal logic program P in Example 1, in which the spc-components are highlighted: the d-hyperarcs ({f, h}, {n}) and ({f, u}, {a}) are shown with dashed lines, and the s-hyperarcs ({f}, {h}) ({f, h}, {u}), ({n, u}, {c}), ({c}, {n}) and ({u}, {f}) are represented in continuous lines. Moreover, the labels of each hyperarc are included. Notice that, the labels of the d-hyperarcs include the aggregator symbols @3,1 and @1,2 , which do not verifying the boundary condition of Equation (1). Moreover, the negation operators only appear (the labels have the third component non empty) in the d-hyperarcs. (P, @(1,2) , {h, f }, 0.6) ) .7 ,0 ,∅ ,∅ (P h ( G , & L (P, &P ,{u},0.8) c ,∅ ,0 f (P, ∅, ∅, 0.9) (P, ∅, ∅, 0.8) n (P, @(3,1) , {u, f }, 1) a .7 ) u Fig. 2. spc-components of the edge-labeled B-graph associated with the program given in Example 1. The d-hyperarcs are shown with dashed lines. 4 Applications of hypergraph representation The previous representation of a normal logic program is a very useful tool for handling a program and obtain information from it. For example, one important 8 J. C. Díaz-Moreno et al. problem in logic programming is to know whether the iteration of the immediate consequences operator terminates in a finite number of iterations [6–8]. Taking into account the framework considered in [8], we obtain the following theorem. Theorem 1. Given a multi-adjoint normal Σ-algebra L and a multi-adjoint normal logic program P with finite dependences, where the s-hyperarcs of the associated B-graph correspond to rules with an aggregator in the body satisfying Equation (1) and no negation operator. If for every iteration n and propositional symbol A the set of relevant values for A with respect to TPn (M) is a singleton, then TP terminates for every query. Clearly, the hypotheses of Theorem 1 hold, and so we can ensure that TP terminates, as it happens and it is shown in Table 1. As Example 2 shows, hypothesis in Theorem 1 may not be satisfied, but the iteration in the computation of the least fixed point of the immediate consequence operator can terminate. Example 2. In the framework of Example 1, the following program is considered. hc ←P n &P ¬u, 0.8i ha ←P @(3,1) (¬u, ¬f), 1.0i hn ←P @(1,2) (¬h, ¬f), 0.6i hu ←G h &Ł f, 0.7i hf ←P 1.0, 0.1i hn ←P 1.0, 0.5i hu ←P 1.0, 0.2i hh ←P ¬f, 0.7i hn ←P c, 0.8i hf ←P ¬u, 0.9i Table 2 presents the results of the iterations of this program and Figure 3 shows the asociated edge-labeled hypergraph. Another application is that the results Table 2. Iteration of TP operator from the least interpretation M. M TP (M) TP2 (M) TP3 (M) TP4 (M) TP5 (M) TP6 (M) f 0 0.9 0.72 0.36 0.72 0.72 0.72 h 0 0.7 0.07 0.196 0.448 0.196 0.196 u 0 0.2 0.6 0.2 0.2 0.2 0.2 c 0 0 0.384 0.16 0.32 0.32 0.32 n 0 0.6 0.5 0.5 0.5 0.5 0.5 a 0 1 0.625 0.37 0.76 0.67 0.67 in different papers on fuzzy normal programs can be applied locally. Theorem 2. Given a multi-adjoint normal Σ-algebra L, a multi-adjoint normal logic program P with finite dependences. If the s-hyperarcs of the associated Bgraph correspond to rules with no negation operator in the body, then P has a stable model if and only if the subprograms associated with each spc-component has a stable model. Hence, this theorem split the complexity of the computation of the stable models and, for example, the results in [3, 15] can be applied to each obtained subprogram. Hypergraphs in logic programming (P, @(1,2) , {h, f }, 0.6) 7) 0. }, f ,{ ,∅ (P h ( G ,& L (P, &P ,{u},0.8) c ,∅ ,0 f (P, ∅, {u}, 0.9) (P, ∅, ∅, 0.8) n 9 (P, @(3,1) , {u, f }, 1) a .7 ) u Fig. 3. Edge-labeled B-graph associated with the programa given in Example 2 and its spc-components. d-hyperarcs are shown with dashed lines. 5 Conclusions and future work This paper has introduced a hypergraph based representation of a logic normal program considering an edge-labeled directed B-graph, which characterizes the whole logic program. For example, this representation allows to detect quickly the relationships among the variables, apply graph theory on hypegraphs on the given program and determined consequences/properties. In the future, these applications will be analyzed in-depth and considered in real cases. References 1. C. Berge. Graphs and Hypergraphs. Elsevier Science Ltd, 1985. 2. M. E. Cornejo, D. Lobo, and J. Medina. Characterizing fuzzy y-models in multiadjoint normal logic programming. Communications in Computer and Information Science, 855:541–552, 2018. 3. M. E. Cornejo, D. Lobo, and J. Medina. Syntax and semantics of multi-adjoint normal logic programming. Fuzzy Sets and Systems, 345:41 – 62, 2018. 4. M. E. Cornejo, D. Lobo, and J. Medina. Extended multi-adjoint logic programming. Fuzzy Sets and Systems, 388:124–145, 2020. Logic. 5. M. E. Cornejo, D. Lobo, and J. Medina. Relating multi-adjoint normal logic programs to core fuzzy answer set programs from a semantical approach. Mathematics, 8(6):1–18, 2020. Paper 881. 6. C. Damásio, J. Medina, and M. Ojeda-Aciego. Termination of logic programs with imperfect information: applications and query procedure. Journal of Applied Logic, 5:435–458, 2007. 7. J. C. Díaz-Moreno, J. Medina, and J. R. Portillo. Towards the use of hypergraphs in multi-adjoint logic programming. Studies in Computational Intelligence, 796:53– 59, 2019. 8. J. C. Díaz-Moreno, J. Medina, and J. R. Portillo. Fuzzy logic programs as hypergraphs. termination results. Fuzzy Sets and Systems, 445:22–42, 2022. Logic and Databases. 10 J. C. Díaz-Moreno et al. 9. M. v. Emden and R. Kowalski. The semantics of predicate logic as a programming language. Journal of the ACM, 23(4):733–742, 1976. 10. G. Gallo, G. Longo, S. Pallottino, and S. Nguyen. Directed hypergraphs and applications. Discrete Appl. Math., 42(2-3):177–201, apr 1993. 11. H. Halpin and F. McNeill. Discovering meaning on the go in large heterogenous data. Artificial Intelligence Review, 40:107–126, 2013. 12. P. Julián-Iranzo, G. Moreno, and J. A. Riaza. Some properties of substitutions in the framework of similarity relations. Fuzzy Sets and Systems, 2023. 13. P. Julián-Iranzo and F. Sáenz-Pérez. Bousi?prolog: Design and implementation of a proximity-based fuzzy logic programming language. Expert Systems with Applications, 213:118858, 2023. 14. K. Kulagin, M. Salikhov, and R. Burnashev. Designing an educational intelligent system with natural language processing based on fuzzy logic. In 2023 International Russian Smart Industry Conference (SmartIndustryCon), pages 690–694, 2023. 15. N. Madrid and M. Ojeda-Aciego. On the existence and unicity of stable models in normal residuated logic programs. International Journal of Computer Mathematics, 89(3):310–324, 2012. 16. J. Medina, M. Ojeda-Aciego, and P. Vojtáš. Multi-adjoint logic programming with continuous semantics. volume 2173, pages 351–364, 2001. 17. J. Medina and J. A. Torné-Zambrano. Immediate consequences operator on generalized quantifiers. Fuzzy Sets and Systems, 456:72–91, 2022. 18. R. J. Mooney. Inductive logic programming for natural language processing. In S. Muggleton, editor, Inductive Logic Programming, pages 1–22, Berlin, Heidelberg, 1997. Springer Berlin Heidelberg. 19. K. Nakamura and T. Ando. A taboo-not in open world assumption for a natural language based logic programming. In 2022 IEEE International Conference on Big Data (Big Data), pages 5140–5144, 2022. 20. R. Regaieg, M. Koubàa, E. Osei-Opoku, and T. Aguili. A two objective linear programming model for vm placement in heterogenous data centers. In N. Boudriga, M.-S. Alouini, S. Rekhis, E. Sabir, and S. Pollin, editors, Ubiquitous Networking, pages 167–178, Cham, 2018. Springer International Publishing. 21. M. Ren, Z. Zhang, J. Zhang, and L. Mora. Understanding the use of heterogenous data in tackling urban flooding: An integrative literature review. Water, 14(14):2160, Jul 2022. 22. E. Salazar and G. Gupta. Proof-Theoretic Foundations of Normal Logic Programs, pages 233–252. Springer Nature Switzerland, Cham, 2023. 23. S. A. Scherr, S. Hupp, and F. Elberzhager. Establishing continuous app improvement by considering heterogenous data sources. International Journal of Interactive Mobile Technologies (iJIM), 15(10):pp. 66?86, May 2021. 24. A. Wachtel, D. Fuchß, M. Przybylla, and W. F. Tichy. Natural language data queries on multiple heterogenous data sources. In A. Malizia, S. Valtolina, A. Morch, A. Serrano, and A. Stratton, editors, End-User Development, pages 174–182, Cham, 2019. Springer International Publishing. 25. Y. Wang, T. Eiter, Y. Zhang, and F. Lin. Witnesses for answer sets of logic programs. ACM Trans. Comput. Logic, 24(2), jan 2023.