示例#1
0
        public void Lambda()
        {
            var original = PLExpression <MyModel> .Iff(m => m.L, m => m.R1 || m.R2);

            var converted = new CNFConverter().VisitAndConvert(original, null);

            Assert.Equal(
                "m => ((IsFalse(m.L) OrElse (m.R1 OrElse m.R2)) AndAlso ((IsFalse(m.R1) OrElse m.L) AndAlso (IsFalse(m.R2) OrElse m.L)))",
                converted.ToString());
        }
示例#2
0
        public void NeedsNormalisation()
        {
            var e = new CNFExpression <MyModel>(PLExpression <MyModel> .Iff(m => m.L, m => m.R1 || m.R2));

            e.ShouldHaveState(clauseCount: 3);

            e.Clauses.ElementAt(0).ShouldHaveState(
                isDefiniteClause: false,
                isGoalClause: false,
                isHornClause: false,
                isUnitClause: false,
                literalCount: 3);
            e.Clauses.ElementAt(0).Literals.ElementAt(0).ShouldHaveState(
                atomicSentenceSymbol: "m.L",
                isNegated: true);
            e.Clauses.ElementAt(0).Literals.ElementAt(1).ShouldHaveState(
                atomicSentenceSymbol: "m.R1",
                isNegated: false);
            e.Clauses.ElementAt(0).Literals.ElementAt(2).ShouldHaveState(
                atomicSentenceSymbol: "m.R2",
                isNegated: false);

            e.Clauses.ElementAt(1).ShouldHaveState(
                isDefiniteClause: true,
                isGoalClause: false,
                isHornClause: true,
                isUnitClause: false,
                literalCount: 2);
            e.Clauses.ElementAt(1).Literals.ElementAt(0).ShouldHaveState(
                atomicSentenceSymbol: "m.R1",
                isNegated: true);
            e.Clauses.ElementAt(1).Literals.ElementAt(1).ShouldHaveState(
                atomicSentenceSymbol: "m.L",
                isNegated: false);

            e.Clauses.ElementAt(2).ShouldHaveState(
                isDefiniteClause: true,
                isGoalClause: false,
                isHornClause: true,
                isUnitClause: false,
                literalCount: 2);
            e.Clauses.ElementAt(2).Literals.ElementAt(0).ShouldHaveState(
                atomicSentenceSymbol: "m.R2",
                isNegated: true);
            e.Clauses.ElementAt(2).Literals.ElementAt(1).ShouldHaveState(
                atomicSentenceSymbol: "m.L",
                isNegated: false);
        }
示例#3
0
        public void Iff()
        {
            var predicate = PLExpression <Model> .Iff(m => m.P, m => m.Q).Compile();

            // Verify the truth table:
            Assert.True(predicate(new Model {
                P = false, Q = false
            }));
            Assert.False(predicate(new Model {
                P = false, Q = true
            }));
            Assert.False(predicate(new Model {
                P = true, Q = false
            }));
            Assert.True(predicate(new Model {
                P = true, Q = true
            }));
        }
示例#4
0
        public void Implies()
        {
            // Equivalent but less easy to read..
            //// m => !m.TodayIsSaturday || m.ItIsTheWeekend;
            // Would be nice if we could do this with Implies as an extension method, but can't apply member access operator (.) direct to lambdas - need to cast first..:
            //// (m => m.TodayIsSaturday).Implies(m => m.ItIsTheWeekend);
            // ..but casting looks like this - horrendous (though slightly nicer if you use an alias for Expression<Predicate<TModel>>)..
            //// ((Expression<Predicate<MyModel>>)(m => m.TodayIsSaturday)).Implies(m => m.ItIsTheWeekend);
            var predicate = PLExpression <Model> .Implies(m => m.P, m => m.Q).Compile();

            // Verify the truth table:
            Assert.True(predicate(new Model {
                P = false, Q = false
            }));
            Assert.True(predicate(new Model {
                P = false, Q = true
            }));
            Assert.False(predicate(new Model {
                P = true, Q = false
            }));
            Assert.True(predicate(new Model {
                P = true, Q = true
            }));
        }