Esempio n. 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)));
 }
Esempio n. 2
0
 public static INaturalNumber Add(
     this INaturalNumber x,
     INaturalNumber y)
 {
     return(x.Accept(new AddNaturalNumberVisitor(y)));
 }
Esempio n. 3
0
 public IChurchBoolean VisitSucc(INaturalNumber predecessor)
 {
     // Match previous
     return(predecessor.Accept(
                new IsEvenPredecessorNaturalNumberVisitor()));
 }
Esempio n. 4
0
        // More memmbers go here...

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