{'fraction_non_alphanumeric': 0.03276569022200879, 'fraction_numerical': 0.009973772671862878, 'mean_word_length': 4.54640442532268, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A Formally Verified HOL4 Algebra for Event Trees

Event Tree (ET) analysis is widely used as a forward deductive safety analysis technique for decision-making at the critical-system design stage. ET is a schematic diagram representing all possible operating states and external events in a system so that one of these possible scenarios can occur. In this report, we propose to use the HOL4 theorem prover for the formal modeling and step-analysis of ET diagrams. To this end, we developed a formalization of ETs in higher-order logic, which is based on a generic list datatype that can: (i) construct an arbitrary level of ET diagrams; (ii) reduce the irrelevant ET branches; (iii) partition ET paths; and (iv) perform the probabilistic analysis based on the occurrence of certain events. For illustration purposes, we conduct the formal ET stepwise analysis of an electrical power grid and also determine its System Average Interruption Frequency Index (SAIFI), which is an important indicator for system reliability.


Introduction
Nowadays, the fulfillment of stringent safety requirements for critical-systems, which are prevalent, e.g., in smart grids and automotive industry, has been encouraging safety design engineers to use formal techniques as per recommendations of safety standards, such as IEC 61850 [1] and ISO 26262 [2]. Therefore, it is required to build necessary formal support for rigorous reliability analysis so that they become an essential step in the design process and ensure the delivery of a trusted service without failures [3]. Several reliability modeling techniques have been developed, such as Fault Trees (FT) [4], Reliability Block Diagrams (RBD) [5] and Event Trees (ET) [6], that describe the behavior of components for a given system. FTs mainly provide a graphical model for analyzing the factors causing a system failure upon their occurrences. On the other hand, RBDs allow us to model the success relationships of complex systems. ETs enumerate all possible operating states and external events in a system in the form of a tree structure represented by an initiating node and branches [6]. The results of the ET analysis are extremely useful for safety analysts as it provide a more detailed system view compared to FTs and RBDs.
Papazoglou [6] was the first researcher to lay down the mathematical foundations of ET in the late 90s. He described the ET analysis in four main steps: (1) Generation: construct a complete ET model; (2) Reduction: removal of unnecessary ET branches; (3) Partitioning: extract a collection of ET paths according to the system failure and success events; and lastly (4) Probabilistic analysis: evaluate the probabilities of ET paths based on the occurrence of a certain event. But the analysis of ET proposed in [6] is done purely manually using a paper-and-pencil approach. On the other hand, there exist several commercial tools based on Monte-Carlo Simulation for ET analysis, such as ITEM [7], Isograph [8], and EC Tree [9], which have been widely used to determine sequentially failure and success scenarios of real-world systems, like electrical power grids [10], nuclear power plants [11] and railways [12]. Prior to utilizing these tools for ET analysis, the users must draw a given system actual ET diagram manually, maybe on paper. Both of these approaches may introduce inaccuracies in the ET analysis due to human infallibility and analysis approximations caused by the numerical methods in the simulation tools, respectively. A more efficient and practical way is to define functions describing the pattern of modeling ETs as well as ET probabilistic properties.
In this report, we propose to use HOL theorem proving [13], which provides us the ability to accurately model and also rigorously verify the essential ET properties. For this purpose, we endeavor to formalize the four steps of ET analysis using the HOL4 proof assistant, i.e., generation, reduction, partitioning and probabilistic analysis, as described by Papazoglou [6]. We present two syntactically different, but semantically equivalent formalizations for ET analysis, using set and list-datatypes, respectively. The former set-datatype ET formalization is described by Papazoglou, however, it cannot mimic the graphical model of an ET consisting of an initiating node and branches since the elements in sets are orderless. The ordering is important in Steps 3 and 4 (reduction and partitioning processes) of the ET analysis. In the latter approach, the list-datatype inherently preserves the index of its member elements and naturally captures the graphical structure of ETs. Also, from our experience, the reasoning about ET reduction and partitioning properties using the set-datatype is quite cumbersome and significantly slow compared to the list-datatype especially when the ET diagram becomes tremendously large. Therefore, we use the list-datatype to formalize all four steps of ET analysis in HOL4. For that purpose, we propose to use the list-datatype that inherently preserves the index of its member elements and naturally captures the graphical structure of ETs. For illustration purposes, we conduct the formal ET analysis of a practical power grid system consisting of N transmission lines and M customers. Subsequently, we also formally determine the System Average Interruption Frequency Index (SAIFI) [14], which is an important reliability index describing the average frequency of interruptions in an electrical power systems.
The rest of the report is organized as follows: In Section 2, we present the related literature review. Section 3 briefly summarize the fundamentals of ETs. In Section 4, we present the details of our HOL4 formalization of ETs using the set-datatype. Section 5 describes the formalization of ETs by developing a new recursive datatype EVENT TREE.
In Section 7, we present the formalization of ETs reduction and partitioning. Section 6 describes the formal probabilistic analysis of ETs. In Section 8, we present the formal ET analysis-based of a power grid system and the assessment of its reliability index SAIFI. Lastly, Section 9 concludes the report.

Related Work
Only a few work have previously considered using formal methods to model and analyze ETs. For instance, Nỳvlt et al. in [15] used Petri nets to model the cascading failure of sub-systems and their effect on the entire system using the standard FT and ET modeling techniques. The authors proposed a new method based on P-invariants to obtain a model of cascading dependencies in ETs [15]. However, according to the authors, they are not able to obtain verified equations from that model [15]. HOL4 [13] has been previously used by Ahmad et al. in [16] to formalize FTs and RBDs. The FT formalization includes a new datatype consisting of AND, OR and NOT FT constructors [4] to analyze the factors causing a system failure. Similarly, Ahmad et al. in [17] defined a new RBD datatype to model and analyze the success relationships of a system using different RBD configurations [5], such as series, parallel and combination of series and parallel. However, both of these formalizations are limited to analyzing either a system failure or its success only. On the other hand, ETs have the superior ability to analyze both failure and success scenarios in a system. For the formalization of ET in HOL4, the existing treeTheory in the standard library of HOL4 only allows drawing a specific tree with leaves and nodes manually. To the best of our knowledge, this is the first work, which develops a formal modeling and step-analysis of ETs using HOL4 theorem prover.

Event Trees
An ET diagram is a graphical model that enumerate all possible combinations of component states and external events in a system in the form of a tree structure. ETs utilize the forward logic [18] starting by an Initiating Event (IE) called node and then all possible scenarios of an event are drawn as branches. For instance, consider a system consist of three components C 1 , C 2 and C 3 , each has two operational states, i.e., operating or failing. The ET four step-analysis defined by Papazoglou [6] are as follows: 1. Generation: Construct a complete ET diagram that draws all possible scenarios, which is well-known as paths. Each path consists of a unique sequence of events. Fig. 1 depicts 8 paths (0-7) with all possible scenarios that can occur.

2.
Reduction: Model the accurate functional behavior of the system in the sense that the irrelevant branches should be removed from a complete ET. This can be done by deleting some specific branches corresponding to the occurrence of certain events, which are known as Complete Cylinders (CCs) [19]. These cylinders are ET paths consisting of N events and they are conditional on the occurrence of K Conditional Events (CEs) in their respective paths and they are referred to as CCs with respect to K [19]. For instance, if the critical-component C 1 fails then the whole system fails regardless of the status of the rest of the components, i.e., C 2 and C 3 , as shown in Fig. 1. Therefore, paths 4-7 are CCs with respect to C 1F .
3. Partitioning: partition of an ET diagram is essential as we are only interested in the occurrence of certain events according to the system failure and success events. For instance, suppose we are only focusing on the failure of the system in Fig. 1, then ET paths 3 and 4 are obtained from the reduced ET.
4. Probabilistic analysis: Lastly, evaluate the probabilities of ET paths based on the occurrence of a certain event. These probabilities represent the likelihood of each scenario that is possible to occur in a system so that only one can occur [6]. This implies that all paths connected to a node are disjoint (mutually exclusive) [6]. Assuming that all events in an ET are mutually independent that the probability of any ET path can be computed by simply multiplying the individual probabilities of all the events associated with it [6]. For example, the probability of the system failure in Fig. 1, i.e., paths 3 and 4, is expressed mathematically as: where P(C XF ) is the unreliability function or the probability of failure for a component X and P(C XS ) is the reliability function or the probability of operating.
In the next sections, we present, in detail, the formalization of ETs using the set and the list data-types, respectively. The reason for using the set theory is that most of the mathematical foundations of ETs from the work of Papazoglou [6] are built on sets. However, ordering of events in ET paths is important during Steps 2 and 3 of the ET analysis. Therefore, a sequence-preserving formalization of ETs in the list theory should be adopted. In order to ensure the correspondence of the set and list theory based ET formalizations, we formally verify the equivalence between them.

Complete Event Tree Reduced Event Tree
(3)

ET Formalization using Sets
An event outcome space (W) is referred to a set of all possible scenarios of an IE or modes of operation of a system critical-component, which must satisfy the following constraints according to Papazoglou [6]: a) Distinct: All outcomes in an event outcome space must be unique.
b) Disjoint (mutually exclusive): Any pair of events from a set of events outcome space cannot occur at the same time.
c) Complete: An event outcome space must contain all possible events that can occur. d) Finite: An event outcome space must consist of a finite number of elements.
We formalize the above-mentioned event outcome space (W) constraints in HOL4 as follows: where W is a set of events representing the possibilities resulting from an IE or modes of operation of a system component in HOL4. The elements in a set are intrinsically distinct and thus ensuring the constraint (a). The function disjoint ensures that each pair of elements in a given set is mutually exclusive satisfying constraint (b). The completeness of an event outcome space, constraint (c), means containing all possible events or modes of a system component that can occur. In many practical systems, some components are redundant for improving system reliability and they are only used when required, i.e., in a hold state meaning neither success nor fail. This completeness of the event outcome space can be ensured by adding an empty set ∅ representing the default (not in-use) case, i.e., a component is neither in success nor in failure state. The HOL4 function FINITE guarantees that the set of event outcome space must consist of a finite number of elements, as indicated by constraint (d).
Consider a system having two events, say E 1 and E 2 , with two event outcome spaces W 1 and W 2 , respectively. The Cartesian product ( ) of these event outcome spaces returns a set of (N 1 × N 2 ) pairs containing all possible outcome pairs for the occurrence of E 1 and E 2 together (i.e., W 1 W 2 ). In ET, an intersection operation is performed on each member of these pairs to obtain a valid event outcome space. In other words, the resulting event outcome space from the Cartesian product of two event outcome spaces also satisfies the above-mentioned constraints. We formalize this concept in HOL4 as follows: We first construct a set by taking each element from the event outcome spaces W 1 and W 2 and then performing an intersection operation on these elements as: Next, we ensure that the obtained duets from Definition 2 are mutually exclusive. For instance, consider two arbitrary outcomes (ω 1m ∩ ω 2n ) and (ω 1k ∩ ω 2l ) at least (m = k) or (n = l) must be true.
To ensure the validity of an event outcome space, as described in Eq. 2, we define a predicate function in HOL4 as follows: Using the above definitions, we formally verify that the function forms a valid event outcome space.
Theorem 1: (Cartesian product fulfilling the event outcome space constraints) Now, we can define a generic function as defined by Papazoglou [6] that can take an arbitrary set of event outcome spaces and generate the corresponding ET diagram (i.e., W 1 W 2 · · · W N ). For this purpose, we use the HOL4 function ITSET that can recursively apply on a given set of event outcome spaces as follows: where S is a set containing all event outcome spaces till N −1 (i.e., S = {W 1 ; W 2 ; . . . ; W N −1 }) and W N represents the last event outcome space. In order to reason about essential properties of above-mentioned ET model, we formally verify the following properties, by utilizing the properties of the HOL4 function ITSET, on a given set of event outcome spaces as: The order of events in a path is irrelevant when evaluating the probabilities of a given path [19], i.e., the probability of path (C 1S , C 2F , C 3F ) in Eq. 1 is exactly equivalent to the probability of path (C 3F , C 2F , C 1S ) due to the commutative property of intersection and the events independence. However, it is important to preserve the order of events in ET paths during Steps 2 and 3 (reduction and partitioning) of the ET analysis [6] while the elements in sets are orderless. A possible way to resolve the problem of ordering in the set-datatype is by assigning a unique number to each set element representing a branch during the ET modeling. However, when the ET diagram becomes tremendously large, the set-based reasoning is quite cumbersome and significantly slow compared to the list-datatype. For that purpose, in the next three sections, we present the formalization of all four ET analysis steps using the list datatype, which inherently preserves the order of elements.

ET Formalization using Lists
We start the formalization of ETs by developing a new recursive datatype EVENT TREE in HOL4 as follows: Hol datatype EVENT TREE = ATOMIC of (α event) | NODE of EVENT TREE list | BRANCH of (α event) ⇒ EVENT TREE list The type constructors NODE and BRANCH are recursive functions on EVENT TREE-typed lists. A semantic function is then defined over the EVENT TREE datatype that can yield a corresponding ET diagram as: Definition 6: ETREE (ATOMIC X) = X ∧ ETREE (NODE (h::t)) = ETREE h ∪ (ETREE (NODE t)) ∧ ETREE (BRANCH X (h::t)) = X ∩ (ETREE h ∪ ETREE (BRANCH X t)) The function ETREE takes a set X, identified by a type constructor ATOMIC and returns the given set X. If the function ETREE takes a list of type EVENT TREE, identified by a type constructor NODE, then it returns the union of all elements after applying the function ETREE on each element of the given list. Similarly, if the function ETREE takes a set X and a list of type EVENT TREE, identified by a type constructor BRANCH, then it performs the intersection of the set X with the union of the head of the given list after applying the function ETREE and the recursive call of the BRANCH constructor.
To formally define a function that can model a complete ET for N lists, similar to Definition 5, we start by defining a function that can model an ET for two lists, say L 1 and L 2 , in HOL4 as:

Definition 7:
(h::t) L L 2 = BRANCH h L 2 ::t L L 2 where the function L takes two different EVENT TREE-typed lists and returns an EVENT TREE-typed list by recursively applying the BRANCH constructor on each element of the first list paired with the entire second list. Now, we can define a generic function that takes an arbitrary list of event outcome spaces and generates a corresponding complete ET diagram, i.e., Step 1 (Generation) of ET analysis [6]. For this purpose, we utilize the HOL4 function FOLDR that recursively applies L on a given list of event outcome spaces as: In order to ensure the correspondence of the list and set theory based ET formalizations, we formally verify the equivalence between Definitions 3 and 7 and Definitions 5 and 8, in HOL4 as: Theorem 5: where the predicate function Ω L covers all constraints of event outcome spaces (distinct, disjoint, complete and finite) on the given lists.

ET Reduction and Partitioning Formalization
In ET analysis [6], Step 2 (Reduction) is used to model the accurate functional behavior of systems in the sense that the irrelevant branches should be removed from a complete ET of a system. To perform the reduction process, we first need to extract all possible paths from a given ET and then apply the deletion operation. For this purpose, we define the following functions in HOL4: Definition 9: L N paths L N = FOLDR (λL 1 L 2 . L 1 paths L 2 ) L N L where the function paths takes two different lists and returns a list containing all possible ET paths in a list. To ensure consistency, we also formally verify the equivalence between Definitions 8 and 9, i.e., complete ET paths, in HOL4 as: where the function EVENT TREE LIST is used to type-cast the normal list to EVEN TREE-typed list. Now, we define a reduction function in HOL4 on event outcome spaces that takes a list L, which is the output of Definition 9, a list of ET path numbers N to be reduced and their K conditional events CE and returns a reduced ET list as: where the functions LUPDATE, LAST, and TAKE are the HOL4 list theory functions to update an element, extract the last element and take a collection of elements, respectively. The function PATH takes a list of events from a probability space p and extracts an intersection between the elements of the list. The function DELETE N recursively deletes N elements from a given list corresponding to the branches that should be removed from a complete ET of a system in order to model the accurate functional behavior of systems. To ensure that the reduced ET is consistent, we formally verify the following reduction properties: We first ensure that the length of ET after reduction is equal to the length of complete ET minus the number of paths that were deleted, in HOL4 as: where the function INDEX LT LEN ensure that each index in the given list N is less than the length of the reduced ET list, respectively.
Next, we ensure that the paths that were not reduced still exist in the reduced ET, in HOL4 as: where the function EL, from the list theory, extracts a specific element from a list. The function SORTED ensure that the index list N is sorted in descending order.
To perform multiple reduction operations on a given ET model, we define the following recursive function, using Definition 10, in HOL4 as: After the ET reduction process, the next step is the partitioning of the reduced ET paths space according to the system failure and success events [6]. Since the output of the function N is a list, we can define a partitioning function to extract a collection of ET paths specified in the index list N, in HOL4 as: where the HOL4 function REVERSE returns a list in reverse order.

ET Probabilistic Analysis Formalization
The last step in the ET analysis [19] is to determine the probability of each path occurrence in the whole ET diagram. For that purpose, we formally verify generic probabilistic properties for NODE, BRANCH, PATH and N L as follows: Theorem 6: prob space p ∧ Ω L L ∧ (∀y. y ∈ L ⇒ y ∈ events p) ⇒ prob p (ETREE (NODE L)) = P p L The first assumption in the above theorem ensures that p is a valid probability space. The next assumption is quite similar to the one described in Theorem 4. The last assumption ensures that all component states list belongs to the events space. The function P is defined to sum the probabilities of events for a given list.
Similarly, the probability of events in branches is the multiplication of each branch event probability with the sum of the probabilities for the next events. This can be verified in HOL4 as: Also, the probability of an ET path can be verified as the multiplication of the individual probabilities of all the events associated with it, in HOL4 as: where the function takes a list and extracts the multiplication of the list elements while the function PROB LIST returns a list of probabilities associated with the elements of the list.
Additionally, we can formally verify a generic probabilistic property for the function N L , in HOL4 as: where the function 2D P is used to recursively apply the function P on a given two dimensional list.
Using the above theorems, we can formally verify in HOL4 that the probability of the function N L is equal to 1, which returns a complete space of failure and success events: where the function ↑↓ takes a list of components and assigns both ↑ and ↓ events to each component in the given list representing operating and failing events, respectively.
The prime purpose of the above-mentioned formalization of ETs is to build a reasoning support for the formal analysis of reliability aspects of real-world safety-critical systems within the sound environment of HOL4. In the next section, we present the formal ET analysis of an electrical power grid and determine its reliability index to illustrate the applicability of our proposed approach.

Electrical Power Grid System
An electrical power grid is an interconnected network for delivering electricity from producers to consumers. The power grid system [20] mainly consists of: (i) generating stations that produce electric power; (ii) electrical substations for stepping voltage up for transmission or down for distribution; (iii) high voltage transmission lines that carry power from distant sources to demand-centers; and (iv) distribution lines that connect individual customers. With respect to the power-outage-causes study domain, the majority of the outages in the power grid are the result of events that occur on the grid transmission and distribution sides [21]. Therefore, a rigorous formal ET step-analysis of the power grid is essential in order to reduce the risk situation of a blackout and back-up decisions to be taken. Using our proposed ET formalization, we can model the ET for any power grid consisting of N transmission lines and M customers. Also, we can determine the System Average Interruption Frequency Index (SAIFI), which is used by design engineers to indicate the average frequency of customers experience a sustained outage. SAIFI is defined as the total number of customer interruptions over the total number of customers served [22]: where CN X is the number of customers for a certain location X . We define a generic function SAIFI in HOL4 by dividing the sum of multiplying the probabilities of a collection of ET paths after reduction with the number of customers that are affected by them over the total number of customers served as: For instance, consider a power grid consisting of three main transmission lines (M), two lateral transmission lines (L), two generators (G), three (two step-up and one step-down) substations (S/S) and three different loads A, B and C with the number of customers served X, Y and Z, respectively, as shown in Fig. 2. Assume that each TL (M/L) has two operational states, i.e., operating or failing. Using our ET formalization, we can formally verify the complete ET model (32 paths) for the 5 TLs that mainly affect the reliability of the power grid, in HOL4 as: The complete ET, obtained above, can be reduced from 32 paths (0-31) to 14 paths (0-13), in the sense that the irrelevant nodes and branches are removed to model the exact logical behavior of the power grid. For instance, the paths from 31 to 24, where both M1 and M2 fail, then the likelihood of occurrence of these paths is equal to the probabilities of M1 and M2 failures only regardless of the status of other TLs. We formally verify the following reduction property to obtain the actual ET of TLs, as shown in Fig. 3, in HOL4 as:  Typically, we are only interested in the occurrence of certain events in ET that affect certain paths. For instance, if we consider the failure of load A, then paths 11, 12 and 13 are obtained. Similarly, a different set of paths can be obtained by observing different failures in the power grid as: (i) P(A F ail ) = P(paths11,12,13) ; (ii) P(B F ail ) = P(paths6,7,13) ; and (iii) P(C F ail ) = P(paths2,5,7, 10,12,13) . Therefore, the assessment of SAIFI can be done informally as: In this work, we assumed that the failure and success states of each TL is exponentially distributed. This can be formalized in HOL4 as: where the cumulative distribution function (CDF) is defined as the probability of the event where a random variable X has a value less or equal to a value t, i.e., P(X ≤ t).

Conclusions
In this report, we described the HOL4 formalization of ETs step-analysis using a generic list data-type. We defined the NODE and BRANCH concepts, which can be used to model an arbitrary level of ET diagram consisting of N system components. We developed a formal approach to reduce ET branches, partition ET paths, and perform the probabilistic analysis based on the occurrence of certain events. For illustration purposes, we conducted the formal ET analysis of a power grid and also verified its system reliability index SAIFI. As a future work, we plan to formalize the cascading dependencies in ETs [15], which will enable us to analyze hierarchical systems with many sub-system levels, based on our proposed ET formalization in the HOL4 theorem prover.