Question: Write a [Haskell] program: Fault Tree Evaluation Learning Outcomes: On successful completion of this assignment, a student will: -Have used different approaches to define data

Write a [Haskell] program: Fault Tree Evaluation

Learning Outcomes: On successful completion of this assignment, a student will:

-Have used different approaches to define data types in Haskell

-Have practiced how to use recursive definitions in functional programming paradigm

-Have practiced how to program using functional programming languages

In the first part of this assignment, given a list of probabilities and a list of logical operations, your program will find the probability of the top event (see Fig.1). For simplicity, we also assume that there are two types of operations on the probabilities: OR and AND gates.

Write a [Haskell] program: Fault Tree Evaluation Learning Outcomes: On successful completion

Please implement the fault tree

Sample run:

asgCode [[0.5,0.5],[0.5,0.8],[0.5,0.2],[0.2,0.4],[0.1,0.8],[0.2,1]] ["and", "and", "and", "or", "or"]

The logic is like that:

data Tree = Leaf Float | Node [Char] Tree Tree deriving (Show, Eq, Ord)

ex:

Node "or" (Leaf 0.5) (Leaf 0.4) P1 P2 P3 P4 P5 | "or" "or" "and" "and"

P3 P4 P5 P1orP2 | "or" "and" "and"

P5 P1orP2 P3orP4 | "and" "and"

P3orP4 P5and(P1orP2) | "and"

(P3orP4)and(P5and(P1orP2)) | empty

Also, there is a probability part:

To calculate the probability of the top event, you need to use the following steps: If we have an OR gate with two inputs P1 and P2, the output of the OR gate will be another probability which is calculated as:

of this assignment, a student will: -Have used different approaches to define

The output of a gate will eventually be the input of another gate. In the first part of this assignment, you are asked to implement this structure in Haskell. The inputs of your program will be two lists, where you keep the values of each leaf and the logical operators. You need to use a recursive function to build a tree. You need to select two items from the first list and one item from the second list.

Please write easy code, I want to understand the writing logic of the Haskell code. Thank you.

P, P. Fig. An example fault tree

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!