Skip to content

Commit

Permalink
Euclid: new Euclid class with mod/rem and all that used to be in inte…
Browse files Browse the repository at this point in the history
…ger theory #175
  • Loading branch information
cdrnet committed Dec 14, 2013
1 parent 520a327 commit 59e375a
Show file tree
Hide file tree
Showing 17 changed files with 1,181 additions and 1,102 deletions.
18 changes: 9 additions & 9 deletions src/Examples/NumberTheory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// </copyright>

using System;
using MathNet.Numerics.NumberTheory;
using MathNet.Numerics;

namespace Examples
{
Expand Down Expand Up @@ -63,17 +63,17 @@ public void Run()
{
// 1. Find out whether the provided number is an even number
Console.WriteLine(@"1. Find out whether the provided number is an even number");
Console.WriteLine(@"{0} is even = {1}. {2} is even = {3}", 1, IntegerTheory.IsEven(1), 2, 2.IsEven());
Console.WriteLine(@"{0} is even = {1}. {2} is even = {3}", 1, Euclid.IsEven(1), 2, 2.IsEven());
Console.WriteLine();

// 2. Find out whether the provided number is an odd number
Console.WriteLine(@"2. Find out whether the provided number is an odd number");
Console.WriteLine(@"{0} is odd = {1}. {2} is odd = {3}", 1, 1.IsOdd(), 2, IntegerTheory.IsOdd(2));
Console.WriteLine(@"{0} is odd = {1}. {2} is odd = {3}", 1, 1.IsOdd(), 2, Euclid.IsOdd(2));
Console.WriteLine();

// 3. Find out whether the provided number is a perfect power of two
Console.WriteLine(@"2. Find out whether the provided number is a perfect power of two");
Console.WriteLine(@"{0} is power of two = {1}. {2} is power of two = {3}", 5, 5.IsPowerOfTwo(), 16, IntegerTheory.IsPowerOfTwo(16));
Console.WriteLine(@"{0} is power of two = {1}. {2} is power of two = {3}", 5, 5.IsPowerOfTwo(), 16, Euclid.IsPowerOfTwo(16));
Console.WriteLine();

// 4. Find the closest perfect power of two that is larger or equal to 97
Expand All @@ -88,29 +88,29 @@ public void Run()

// 6. Find out whether the number is a perfect square
Console.WriteLine(@"6. Find out whether the number is a perfect square");
Console.WriteLine(@"{0} is perfect square = {1}. {2} is perfect square = {3}", 37, 37.IsPerfectSquare(), 81, IntegerTheory.IsPerfectSquare(81));
Console.WriteLine(@"{0} is perfect square = {1}. {2} is perfect square = {3}", 37, 37.IsPerfectSquare(), 81, Euclid.IsPerfectSquare(81));
Console.WriteLine();

// 7. Compute the greatest common divisor of 32 and 36
Console.WriteLine(@"7. Returns the greatest common divisor of 32 and 36");
Console.WriteLine(IntegerTheory.GreatestCommonDivisor(32, 36));
Console.WriteLine(Euclid.GreatestCommonDivisor(32, 36));
Console.WriteLine();

// 8. Compute the greatest common divisor of 492, -984, 123, 246
Console.WriteLine(@"8. Returns the greatest common divisor of 492, -984, 123, 246");
Console.WriteLine(IntegerTheory.GreatestCommonDivisor(492, -984, 123, 246));
Console.WriteLine(Euclid.GreatestCommonDivisor(492, -984, 123, 246));
Console.WriteLine();

// 9. Compute the extended greatest common divisor "z", such that 45*x + 18*y = z
Console.WriteLine(@"9. Compute the extended greatest common divisor Z, such that 45*x + 18*y = Z");
long x, y;
var z = IntegerTheory.ExtendedGreatestCommonDivisor(45, 18, out x, out y);
var z = Euclid.ExtendedGreatestCommonDivisor(45, 18, out x, out y);
Console.WriteLine(@"z = {0}, x = {1}, y = {2}. 45*{1} + 18*{2} = {0}", z, x, y);
Console.WriteLine();

// 10. Compute the least common multiple of 16 and 12
Console.WriteLine(@"10. Compute the least common multiple of 16 and 12");
Console.WriteLine(IntegerTheory.LeastCommonMultiple(16, 12));
Console.WriteLine(Euclid.LeastCommonMultiple(16, 12));
Console.WriteLine();
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/Examples/Signals/Chebyshev.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// </copyright>

using System;
using MathNet.Numerics.Signals;
using MathNet.Numerics;

namespace Examples.SignalsExamples
{
Expand Down Expand Up @@ -62,7 +62,8 @@ public string Description
public void Run()
{
// 1. Get 20 samples of f(x) = (x * x) / 2 at the roots of the Chebyshev polynomial of the first kind within interval [0, 10]
var result = SignalGenerator.ChebyshevNodesFirstKind(Function, 0, 10, 20);
var roots = FindRoots.ChebychevPolynomialFirstKind(20, 0, 10);
var result = Generate.Map(roots, Function);
Console.WriteLine(@"1. Get 20 samples of f(x) = (x * x) / 2 at the roots of the Chebyshev polynomial of the first kind within interval [0, 10]");
for (var i = 0; i < result.Length; i++)
{
Expand All @@ -73,7 +74,8 @@ public void Run()
Console.WriteLine();

// 2. Get 20 samples of f(x) = (x * x) / 2 at the roots of the Chebyshev polynomial of the second kind within interval [0, 10]
result = SignalGenerator.ChebyshevNodesSecondKind(Function, 0, 10, 20);
roots = FindRoots.ChebychevPolynomialSecondKind(20, 0, 10);
result = Generate.Map(roots, Function);
Console.WriteLine(@"2. Get 20 samples of f(x) = (x * x) / 2 at the roots of the Chebyshev polynomial of the second kind within interval [0, 10]");
for (var i = 0; i < result.Length; i++)
{
Expand Down
Loading

0 comments on commit 59e375a

Please sign in to comment.