public static bool Equal(Summable <T> x, Summable <T> y)
 {
     if (object.ReferenceEquals(x, null) || object.ReferenceEquals(y, null))
     {
         return(false);
     }
     return(x.Equals(y));
 }
Exemplo n.º 2
0
    public override bool Equals(Summable <int> other)
    {
        var x = other as Int;

        if (Object.ReferenceEquals(x, null))
        {
            return(false);
        }
        return(this.n == x.n);
    }
 public static Summable <T> Sum(Summable <T> x, Summable <T> y)
 {
     if (y == y.Zero)
     {
         return(x);
     }
     if (x == y.Zero)
     {
         return(y);
     }
     else
     {
         return(Sum(x.Add1(), y.Sub1()));
     }
 }
    public static Summable <T> Multiply(Summable <T> x, Summable <T> y)
    {
        var zero = x.Zero;
        var one  = x.One;

        if (x == zero || y == zero)
        {
            return(zero);
        }
        if (y == one)
        {
            return(x);
        }
        if (x == one)
        {
            return(y);
        }
        return(Sum(x, Multiply(x, y.Sub1())));
    }
 }                                            //Identity for multiplication
 public abstract bool Equals(Summable <T> other);
Exemplo n.º 6
0
 public static Summable <T> Multiply(Summable <T> x, Summable <T> y)
 {
     //Coming soon...
 }