Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Integers.cs
1using System;
2using System.Numerics;
5
7{
11 public sealed class Integers : EuclidianDomain
12 {
13 internal static readonly Integer zero = new Integer(BigInteger.Zero);
14 internal static readonly Integer one = new Integer(BigInteger.One);
15 private static readonly int hashCode = typeof(Integers).FullName.GetHashCode();
16
20 public Integers()
21 {
22 }
23
28 {
29 get { return one; }
30 }
31
35 public override IAbelianGroupElement Zero
36 {
37 get { return zero; }
38 }
39
45 public override bool Contains(IElement Element)
46 {
47 object Obj = Element.AssociatedObjectValue;
48 return (Obj is BigInteger) || (Obj is double d && Math.Truncate(d) == d);
49 }
50
52 public override bool Equals(object obj)
53 {
54 return obj is Integers;
55 }
56
58 public override int GetHashCode()
59 {
60 return hashCode;
61 }
62
66 public static readonly Integers Instance = new Integers();
67
69 public override string ToString()
70 {
71 return "ℤ";
72 }
73
82 {
83 if (Left.AssociatedObjectValue is BigInteger l &&
84 Right.AssociatedObjectValue is BigInteger r)
85 {
86 BigInteger Result = BigInteger.DivRem(l, r, out BigInteger Residue);
87 Remainder = new Integer(Residue);
88 return new Integer(Result);
89 }
90 else
91 {
92 Remainder = null;
93 return null;
94 }
95 }
96 }
97}
Base class for all types of elements.
Definition: Element.cs:13
abstract object AssociatedObjectValue
Associated object value.
Definition: Element.cs:46
Base class for all types of euclidian domains.
Integer-valued number.
Definition: Integer.cs:13
Euclidian domain of integers.
Definition: Integers.cs:12
override bool Contains(IElement Element)
Checks if the set contains an element.
Definition: Integers.cs:45
static readonly Integers Instance
Instance of the set of integers.
Definition: Integers.cs:66
override string ToString()
Definition: Integers.cs:69
override ICommutativeRingWithIdentityElement One
Returns the identity element of the commutative ring with identity.
Definition: Integers.cs:28
override int GetHashCode()
Calculates a hash code of the element. Hash code.
Definition: Integers.cs:58
Integers()
Euclidian domain of integers.
Definition: Integers.cs:20
override bool Equals(object obj)
Compares the element to another. If elements are equal.
Definition: Integers.cs:52
override IEuclidianDomainElement Divide(IEuclidianDomainElement Left, IEuclidianDomainElement Right, out IEuclidianDomainElement Remainder)
Divides the right ring element from the left one: Left/Right
Definition: Integers.cs:81
override IAbelianGroupElement Zero
Returns the zero element of the group.
Definition: Integers.cs:36
Basic interface for all types of abelian group elements.
Basic interface for all types of commutative ring with identity elements.
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
Basic interface for all types of Euclidian domain elements.