Ejemplo n.º 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());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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
            }));
        }