-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
80 lines (72 loc) · 3.12 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.ComponentModel;
public class SuccessorCardinal
{
private int k;
private bool isfinite;//If finite then k is just number, if not then it denotes alephs notation N_{k}
public SuccessorCardinal(int k, bool isfinite)
{
if (k < 0)
throw new Exception("Invalid input");
this.k = k;
this.isfinite = isfinite;
}
public int K
{
get { return k; }
set { k = value; }
}
public bool Isfinite {
get { return isfinite; }
set { isfinite = value; }
}
public SuccessorCardinal Add(SuccessorCardinal other)
{
if (isfinite == true && other.isfinite == true)//finite addition
return new SuccessorCardinal(k + other.k, true);
else if (isfinite == false && other.isfinite == true)//One of them infinite
return new SuccessorCardinal(k, false);
else if (isfinite == true && other.isfinite == false)
return new SuccessorCardinal(other.k, false);
else if (k >= other.k)//Both infinite
return new SuccessorCardinal(k, false);
else
return new SuccessorCardinal(other.k, false);
}
public SuccessorCardinal Multiply(SuccessorCardinal other)
{
if (isfinite == true && other.isfinite == true)//finite multiplication
return new SuccessorCardinal(k * other.k, true);
else if ((isfinite == true && k == 0)|| (other.isfinite == true && other.k == 0))//multiply by 0 case
return new SuccessorCardinal(0, true);
else if (isfinite == false && other.isfinite == true)//One of them infinite
return new SuccessorCardinal(k, false);
else if (isfinite == true && other.isfinite == false)
return new SuccessorCardinal(other.k, false);
else if (k >= other.k)//Both infinite
return new SuccessorCardinal(k, false);
else
return new SuccessorCardinal(other.k, false);
}
public SuccessorCardinal Pow(SuccessorCardinal other)//Exponentiation assume GCH
{
if (isfinite == true && other.isfinite == true)//finite exponentiation
return new SuccessorCardinal( (int)Math.Pow(k, other.k), true);
else if ((isfinite == true && k == 0))//0 to any power is 0
return new SuccessorCardinal(0, true);
else if ((isfinite == true && k == 1))//1 to any power is 1
return new SuccessorCardinal(1, true);
else if ((other.isfinite == true && other.k == 0))//anything to 0th power is 1
return new SuccessorCardinal(1, true);
else if ((other.isfinite == true && other.k == 1))//anything to power 1 is itself
return new SuccessorCardinal(k, isfinite);
else if (isfinite == false && other.isfinite == true)
return new SuccessorCardinal(k, false);
else if (isfinite == true && other.isfinite == false)
return new SuccessorCardinal(other.k + 1, false);
else if (k > other.k)//Both infinite
return new SuccessorCardinal(k, false);
else
return new SuccessorCardinal(other.k + 1, false);
}
}