Вы находитесь на странице: 1из 6

# Intelligent

Systems
Group 3: Question 7.3

7.3a)WritearecursivealgorithmPLTRUE?(s,m)thatreturnstrueifandonlyifthesentence
sistrueinthemodelm(wheremassignsatruthvalueforeverysymbolins).Thealgorithm
shouldrunintimelinearinthesizeofthesentence.
Assumptions:
The sentence s is made unambiguous by the use of parentheses.
For brevity, we only include the symbols , , and
We use m[a] to denote the true/false value of a in model m
function PL-TRUE?(s, m) returns true or false:
1) Let LHS = , RHS=, logic_operator =
2) Scan s from left to right, looking for a , left parenthesis, or symbol.
3) If symbol found, LHS = symbol, and goto line 11
4) If found, logic_operator = . Goto line 2.
5) If left parenthesis found:
6)
Let n = 1
7)
While n > 0:
8)
LHS += next character
9)
if next character == right parenthesis: n = n -1
10)
if next character == left parenthesis: n = n +1
11) If logic_operator == , logic_operator = next character.
12) Repeat lines 3 - 11, replacing LHS with RHS
13) If LHS or RHS is not a symbol, LHS = PL_TRUE?(LHS, m), RHS = PL_TRUE?(RHS,
m) as needed
14) If logic_operator == :
15) return true if LHS is false, false otherwise.
16) else If logic_operator == :
17) return true if LHS and RHS are both true, false otherwise
18) else If logic_operator == :
19) return true if either LHS or RHS are equal to true, false otherwise

7.3b)Givethreeexamplesofsentencesthatcanbedeterminedtobetrueorfalsein
apartialmodelthatdoesnotspecifyatruthvalueforsomeofthesymbols.

true
false
A true

7.3c)Showthatthetruthvalue(ifany)ofasentenceinapartialmodelcannotbe
determinedefficientlyingeneral.

## appear in the partial model m.

Some sentences are always true or always

## false, no matter the truth-table assignment of

the symbols in the sentence.
The only way to be sure is to evaluate the 2k

## rows of the truth table one-by-one, waiting to

see one true and one false evaluation, to
determine if the sentence has indeterminate
truth value.
However, due to the existence of always true

## and always false sentences, it is in the worst

case a O(2k) operation determining the truth
value of a sentence.

7.3c)ModifyyourPLTRUE?algorithmsothatitcansometimesjudgetruthfrom
partialmodels,whileretainingitsrecursivestructureandlinearruntime.Givethree
examplesofsentenceswhosetruthinapartialmodelisnotdetectedbyyouralgorithm.

## The modification occurs when evaluating ,

logical operations
In line 13,
(If LHS or RHS is not a symbol, LHS = PL_TRUE?(LHS, m), RHS = PL_TRUE?(RHS, m)
as needed)

## the LHS and RHS come back as variables, or

sentences containing symbols not included in the
partial model.
When evaluating , if either the LHS or RHS
are true values, PL-TRUE? can return true
When evaluating , if either of LHS or RHS
values are false, PL-TRUE? can return false
Example of sentences modified PL-TRUE?
cannot determine as true or false, if Q is not
defined in the model
Q Q
Q Q
Q

7.3c)InvestigatewhetherthemodifiedalgorithmmakesTT
ENTAILS?moreefficient.
Yes, because in many cases involving the and
operators, the value of the truth assignment can
be returned without needing to evaluate both
sides of the operator. This may further mean that
there is no need to recurse.