Documente Academic
Documente Profesional
Documente Cultură
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.
7.3c)ModifyyourPLTRUE?algorithmsothatitcansometimesjudgetruthfrom
partialmodels,whileretainingitsrecursivestructureandlinearruntime.Givethree
examplesofsentenceswhosetruthinapartialmodelisnotdetectedbyyouralgorithm.
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)
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.