Example #1
0
 // The formula used here is
 // x * y = 1 + (x - 1) + (y - 1) + ((x - 1) * (y - 1))
 // It follows like this:
 // x* y =
 // (x - 1 + 1) * (y - 1 + 1) =
 // ((x - 1) + 1) * ((y - 1) + 1) =
 // ((x - 1) * (y - 1)) + ((x - 1) * 1) + ((y - 1) * 1) + 1 * 1 =
 // ((x - 1) * (y - 1)) + (x - 1) + (y - 1) + 1
 public static INaturalNumber Multiply(
     this INaturalNumber x,
     INaturalNumber y)
 {
     return(x.Accept(new MultiplyNaturalNumberVisitor(y)));
 }
Example #2
0
 public static INaturalNumber Add(
     this INaturalNumber x,
     INaturalNumber y)
 {
     return(x.Accept(new AddNaturalNumberVisitor(y)));
 }
Example #3
0
 public IChurchBoolean VisitSucc(INaturalNumber predecessor)
 {
     // Match previous
     return(predecessor.Accept(
                new IsEvenPredecessorNaturalNumberVisitor()));
 }
Example #4
0
        // More memmbers go here...

        public static int Count(this INaturalNumber n)
        {
            return(n.Accept(new CountNaturalNumberVisitor()));
        }
Example #5
0
 public static IChurchBoolean IsEven(this INaturalNumber n)
 {
     return(n.Accept(new IsEvenNaturalNumberVisitor()));
 }