AI Final Labtask

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Q.1 Consider the following statements. Use Propositional Logic to Represent in PROLOG.

 Afridi is a good player of T20.


 Trump is the most powerful president of America in last decade.
 Hashim born in 1995.

Answer:

a) good_player(afridi, t20).

b) powerful_president(trump).

last_decade(2020, 2029).

c) born(hashim, 1995).

Q.2 Consider the following statements. Convert into FOPL resolution and re-write to CNF form.
And convert it into Resolution Graph.
 Gita likes all kinds of food
 Mango and chapatti are food.
 Gita eats almond and is still alive.
 Anything eaten by anyone and is still alive is food

Answer:

1. Gita likes all kinds of food.

FOPL: ∀x (food(x) → likes(gita, x))

CNF: ¬food(x) ∨ likes(gita, x)

2. Mango and chapatti are food.

FOPL: food(mango) ∧ food(chapatti)

CNF: food(mango) ∧ food(chapatti)

3. Gita eats almond and is still alive.

FOPL: eats(gita, almond) ∧ alive(gita)

CNF: eats(gita, almond) ∧ alive(gita)

4. Anything eaten by anyone and is still alive is food.

FOPL: ∀x ∀y ((eats(y, x) ∧ alive(y)) → food(x))


CNF: ¬eats(y, x) ∨ ¬alive(y) ∨ food(x)

Now, let's create a resolution graph based on these converted statements:

1. ¬food(x) ∨ likes(gita, x)
2. food(mango)
3. food(chapatti)
4. eats(gita, almond)
5. alive(gita)
6. ¬eats(y, x) ∨ ¬alive(y) ∨ food(x)

Resolution Graph:

(2) food(mango)
/
(6) (3) food(chapatti)
/ \
(1) - food(x) (6) - eats(y, x)
\ /
(6) (5) alive(gita)
\
(4) eats(gita, almond)

Q.3 Convert the following English sentences to FOL (First Order Logic).
 Every student loves some other students.
 All students are smart.
 There exists a smart student
 Some students are obedient.
 Hashim and Ayesha took the bus.
 Some peoples are aggressive in nature
 Some students are obedient.
 Hashim and Ayesha took the bus.

Answer:
To convert the given English sentences into First-Order Logic (FOL), we need to assign predicates, variables, and
quantifiers to represent the different elements in the sentences. Here's the conversion:

1. Every student loves some other students.

FOL: ∀x ∃y (student(x) ∧ student(y) ∧ x ≠ y → loves(x, y))


2. All students are smart.

FOL: ∀x (student(x) → smart(x))

3. There exists a smart student.

FOL: ∃x (student(x) ∧ smart(x))

4. Some students are obedient.

FOL: ∃x (student(x) ∧ obedient(x))

5. Hashim and Ayesha took the bus.

FOL: tookBus(hashim, bus) ∧ tookBus(ayesha, bus)

6. Some people are aggressive in nature.

FOL: ∃x (person(x) ∧ aggressive(x))

Q.4 Consider the following statements. Use Propositional Logic & apply Resolution Method to
prove that the goal is derivable from the given knowledge base. Also draw a Graph.
 The humidity is high or the sky is cloudy.
 If the sky is cloudy, then it will rain.
 If the humidity is high, then it is hot.
 It is not hot.

Answer:
To apply the Resolution Method to prove that the goal is derivable from the given knowledge base, we need to
represent the statements in Propositional Logic and perform resolution steps. Here's the representation:
1. The humidity is high or the sky is cloudy.

P: humidity_high ∨ sky_cloudy

2. If the sky is cloudy, then it will rain.

P: sky_cloudy → rain

3. If the humidity is high, then it is hot.

P: humidity_high → hot

4. It is not hot.

P: ¬hot

Goal: rain

To prove that the goal "rain" is derivable from the given knowledge base, we can use the Resolution Method.
We start by converting the statements into CNF (Conjunctive Normal Form) and perform resolution steps:

CNF Conversion:

1. humidity_high ∨ sky_cloudy

2. ¬sky_cloudy ∨ rain

3. ¬humidity_high ∨ hot

4. ¬hot

Resolution Steps:
Step 1: Resolve clauses 1 and 2 on "sky_cloudy":

(humidity_high ∨ sky_cloudy) (¬sky_cloudy ∨ rain)

-------------------------------------

humidity_high ∨ rain

Step 2: Resolve clauses 3 and 4 on "¬hot":

(¬humidity_high ∨ hot) (¬hot)

-------------------------------------

¬humidity_high

Step 3: Resolve clauses from Step 1 and Step 2 on "humidity_high":

(humidity_high ∨ rain) (¬humidity_high)

-------------------------------------

rain

Since "rain" is derived, the goal is proven to be derivable from the given knowledge base.
Resolution Graph:

(1) humidity_high ∨ sky_cloudy

(3) (2) ¬sky_cloudy ∨ rain

/ \

(4) (5) ¬humidity_high ∨ hot

\ /

(6) (7) ¬hot

(8) rain

Q.5 Write a Python Program to generate the following Series by using Functions up to ‘N’
numbers. Number is entered by User.
 Fibonacci
 Factorial of Number
 Table of N Number

Answer:

def fibonacci_series(n):

series = []

if n <= 0:

return series

elif n == 1:

series.append(0)

return series

else:

series = [0, 1]

while len(series) < n:

series.append(series[-1] + series[-2])

return series
def factorial(n):

if n == 0:

return 1

else:

return n * factorial(n - 1)

def table_of_n(n):

for i in range(1, 11):

print(f"{n} x {i} = {n * i}")

# Get input from the user

number = int(input("Enter a number: "))

# Generate and print the Fibonacci series

fibonacci = fibonacci_series(number)

print("Fibonacci series:")

print(fibonacci)

# Calculate and print the factorial of the number

factorial_result = factorial(number)

print("Factorial of the number:")

print(factorial_result)

# Print the table of the number

print(f"Table of {number}:")

table_of_n(number)

```

You might also like