public void TestRec() { var step = n + one; var rec = new RecNumExpression(two, zero, "x", "n", step); Assert.AreEqual("2", testAsync(rec, 200).Result); rec = new RecNumExpression(two, two, "x", "n", step); Assert.AreEqual("4", testAsync(rec, 200).Result); var logStep = x & logicTrue; var logRec = new RecLogicExpression(two, logicTrue, "n", "x", logStep); Assert.AreEqual(True, testAsync(logRec, 200).Result); logStep = x | logicTrue; logRec = new RecLogicExpression(two, logicFalse, "n", "x", logStep); Assert.AreEqual(True, testAsync(logRec, 200).Result); logStep = x | logicTrue; logRec = new RecLogicExpression(zero, logicFalse, "n", "x", logStep); Assert.AreEqual(False, testAsync(logRec, 200).Result); // Something a bit more complicated: 6 is the smallest number greater than 5 // i.e 6 is the n such that n > 5 and forall m < n we have m <=5 var step2 = x & m <= new NumConstant(5); var rec2 = new RecLogicExpression(n, logicTrue, "m", "x", step2); var testLog = new NumConstant(6) == new NumThe("n", n > new NumConstant(5) & rec2); Assert.AreEqual(True, testAsync(testLog, 10000).Result); }
public void TestString() { var step2 = x & m <= new NumConstant(5); var rec2 = new RecLogicExpression(n, logicTrue, "m", "x", step2); var testLog = new NumConstant(6) == new NumThe("n", n > new NumConstant(5) & rec2); Assert.AreEqual("(6 == The n. ((n > 5) & Rec(n, True, m.x. (x & (m <= 5)))))", testLog.ToString()); var test5 = new Apply(new LambdaExpression("x", x | logicTrue), logicLoop); Assert.AreEqual("(Lambda x. (x | True) @ Exists n. (n < n))", test5.ToString()); var loopTest = new PairExpression <LogicExpression, LogicExpression>(logicLoop, logicTrue); var pairLoop = new LogicProjR(loopTest); Assert.AreEqual("Snd <Exists n. (n < n), True>", pairLoop.ToString()); }