...
 
Commits (2)
......@@ -5,6 +5,7 @@
using DotNetTransformer.Extensions;
using DotNetTransformer.Math.Group;
using DotNetTransformer.Math.Permutation;
using DotNetTransformer.Math.Set;
namespace DotNetTransformer.Math.Transform {
using T = FlipRotate16D;
......@@ -41,59 +42,91 @@ public struct FlipRotate16D : IFlipRotate<T, P>
return new T(p, 1 << dimTo);
}
public static IEnumerable<T> GetReflections(int dimensions) {
if(dimensions < 0 || dimensions > _dimCount)
throw new ArgumentOutOfRangeException(
);
return FlipRotateExtension.GetValues<T, P>(
dimensions, (p, v) => new T(p, v),
p => p.SwapsCount & 1 ^ 1, v => v + 2
);
}
public static FiniteGroup<T> GetRotations(int dimensions) {
return GetValues(dimensions,
c => dimensions > 0 ? c >> 1 : c,
p => p.SwapsCount & 1, v => v + 2
);
}
public static FiniteGroup<T> GetValues(int dimensions) {
return GetValues(dimensions, c => c, _ => 0, v => v + 1);
}
private static FiniteGroup<T> GetValues(int dimensions,
Generator<int> count,
Converter<P, int> startVertex,
Generator<int> nextVertex
) {
if(dimensions < 0 || dimensions > _dimCount)
throw new ArgumentOutOfRangeException(
);
int f = 1, i = 1;
while(i < dimensions) f *= ++i;
return new InternalGroup(
FlipRotateExtension.GetValues<T, P>(
dimensions, (p, v) => new T(p, v),
startVertex, nextVertex
),
count(f << dimensions)
);
private abstract class FlipRotateSet : FiniteSet<T>
{
protected readonly byte _dim;
protected FlipRotateSet(byte dimensions) {
_dim = dimensions;
}
protected bool IsRotational(int swaps, int vertex) {
for(int i = 1; i < _dim; i <<= 1)
vertex ^= vertex >> i;
return ((swaps ^ vertex) & 1) == 0;
}
public override long Count {
get {
long c = 1L;
for(byte i = 1; i < _dim; c *= ++i) ;
return c << _dim;
}
}
public override bool Contains(T item) {
return item.Vertex >> _dim == 0 &&
item.Permutation.ReducibleTo(_dim);
}
public override IEnumerator<T> GetEnumerator() {
int c = 1 << _dim;
P i = new P();
foreach(P p in i.GetRange<P>(i, _dim))
for(int v = 0; v < c; ++v)
yield return new T(p, v);
}
}
private class FlipRotateGroup : FlipRotateSet, IFiniteGroup<T>
{
public FlipRotateGroup(byte dimensions) : base(dimensions) { }
private sealed class InternalGroup : FiniteGroup<T>
public T IdentityElement { get { return None; } }
}
private sealed class ReflectionsSet : FlipRotateSet
{
private IEnumerable<T> _collection;
private int _count;
public ReflectionsSet(byte dimensions) : base(dimensions) { }
public InternalGroup(IEnumerable<T> collection, int count) {
_collection = collection;
_count = count;
public override long Count {
get {
return base.Count >> 1;
}
}
public override bool Contains(T item) {
return base.Contains(item) && item.IsReflection;
}
public override IEnumerator<T> GetEnumerator() {
int c = 1 << _dim;
P i = new P();
foreach(P p in i.GetRange<P>(i, _dim)) {
int s = p.SwapsCount;
for(int v = 0; v < c; ++v) {
while(IsRotational(s, v)) ++v;
yield return new T(p, v);
}
}
}
}
private sealed class RotationsGroup : FlipRotateGroup
{
public RotationsGroup(byte dimensions) : base(dimensions) { }
public override T IdentityElement { get { return None; } }
public override int Count { get { return _count; } }
public override long Count {
get {
long c = base.Count;
return c - (c >> 1);
}
}
public override bool Contains(T item) {
return base.Contains(item) && item.IsRotation;
}
public override IEnumerator<T> GetEnumerator() {
return _collection.GetEnumerator();
int c = 1 << _dim;
P i = new P();
foreach(P p in i.GetRange<P>(i, _dim)) {
int s = p.SwapsCount;
for(int v = 0; v < c; ++v) {
while(!IsRotational(s, v)) ++v;
yield return new T(p, v);
}
}
}
public override int GetHashCode() { return Count; }
}
private const byte _dimCount = 16;
......
......@@ -96,61 +96,6 @@ public struct FlipRotate2D : IFlipRotate<T, P>
return new T(p._value, 1 << dimTo);
}
public static IEnumerable<T> GetReflections(int dimensions) {
if(dimensions < 0 || dimensions > _dimCount)
throw new ArgumentOutOfRangeException(
);
return FlipRotateExtension.GetValues<T, P>(
dimensions, (p, v) => new T(p, v),
p => p.SwapsCount & 1 ^ 1, v => v + 2
);
}
public static FiniteGroup<T> GetRotations(int dimensions) {
return GetValues(dimensions,
c => dimensions > 0 ? c >> 1 : c,
p => p.SwapsCount & 1, v => v + 2
);
}
public static FiniteGroup<T> GetValues(int dimensions) {
return GetValues(dimensions, c => c, _ => 0, v => v + 1);
}
private static FiniteGroup<T> GetValues(int dimensions,
Generator<int> count,
Converter<P, int> startVertex,
Generator<int> nextVertex
) {
if(dimensions < 0 || dimensions > _dimCount)
throw new ArgumentOutOfRangeException(
);
int f = 1, i = 1;
while(i < dimensions) f *= ++i;
return new InternalGroup(
FlipRotateExtension.GetValues<T, P>(
dimensions, (p, v) => new T(p, v),
startVertex, nextVertex
),
count(f << dimensions)
);
}
private sealed class InternalGroup : FiniteGroup<T>
{
private IEnumerable<T> _collection;
private byte _count;
public InternalGroup(IEnumerable<T> collection, int count) {
_collection = collection;
_count = count;
}
public override T IdentityElement { get { return None; } }
public override long Count { get { return _count; } }
public override IEnumerator<T> GetEnumerator() {
return _collection.GetEnumerator();
}
public override int GetHashCode() { return _count; }
}
private const byte _dimCount = 2;
private const byte _count = 8;
private static readonly string[] _names;
......
......@@ -5,6 +5,7 @@
using DotNetTransformer.Extensions;
using DotNetTransformer.Math.Group;
using DotNetTransformer.Math.Permutation;
using DotNetTransformer.Math.Set;
namespace DotNetTransformer.Math.Transform {
using T = FlipRotate3D;
......@@ -57,59 +58,91 @@ public struct FlipRotate3D : IFlipRotate<T, P>
return new T(p, 1 << dimTo);
}
public static IEnumerable<T> GetReflections(int dimensions) {
if(dimensions < 0 || dimensions > _dimCount)
throw new ArgumentOutOfRangeException(
);
return FlipRotateExtension.GetValues<T, P>(
dimensions, (p, v) => new T(p, v),
p => p.SwapsCount & 1 ^ 1, v => v + 2
);
}
public static FiniteGroup<T> GetRotations(int dimensions) {
return GetValues(dimensions,
c => dimensions > 0 ? c >> 1 : c,
p => p.SwapsCount & 1, v => v + 2
);
}
public static FiniteGroup<T> GetValues(int dimensions) {
return GetValues(dimensions, c => c, _ => 0, v => v + 1);
}
private static FiniteGroup<T> GetValues(int dimensions,
Generator<int> count,
Converter<P, int> startVertex,
Generator<int> nextVertex
) {
if(dimensions < 0 || dimensions > _dimCount)
throw new ArgumentOutOfRangeException(
);
int f = 1, i = 1;
while(i < dimensions) f *= ++i;
return new InternalGroup(
FlipRotateExtension.GetValues<T, P>(
dimensions, (p, v) => new T(p, v),
startVertex, nextVertex
),
count(f << dimensions)
);
private abstract class FlipRotateSet : FiniteSet<T>
{
protected readonly byte _dim;
protected FlipRotateSet(byte dimensions) {
_dim = dimensions;
}
protected bool IsRotational(int swaps, int vertex) {
for(int i = 1; i < _dim; i <<= 1)
vertex ^= vertex >> i;
return ((swaps ^ vertex) & 1) == 0;
}
public override long Count {
get {
long c = 1L;
for(byte i = 1; i < _dim; c *= ++i) ;
return c << _dim;
}
}
public override bool Contains(T item) {
return item.Vertex >> _dim == 0 &&
item.Permutation.ReducibleTo(_dim);
}
public override IEnumerator<T> GetEnumerator() {
int c = 1 << _dim;
P i = new P();
foreach(P p in i.GetRange<P>(i, _dim))
for(int v = 0; v < c; ++v)
yield return new T(p, v);
}
}
private class FlipRotateGroup : FlipRotateSet, IFiniteGroup<T>
{
public FlipRotateGroup(byte dimensions) : base(dimensions) { }
private sealed class InternalGroup : FiniteGroup<T>
public T IdentityElement { get { return None; } }
}
private sealed class ReflectionsSet : FlipRotateSet
{
private IEnumerable<T> _collection;
private byte _count;
public ReflectionsSet(byte dimensions) : base(dimensions) { }
public InternalGroup(IEnumerable<T> collection, int count) {
_collection = collection;
_count = count;
public override long Count {
get {
return base.Count >> 1;
}
}
public override bool Contains(T item) {
return base.Contains(item) && item.IsReflection;
}
public override IEnumerator<T> GetEnumerator() {
int c = 1 << _dim;
P i = new P();
foreach(P p in i.GetRange<P>(i, _dim)) {
int s = p.SwapsCount;
for(int v = 0; v < c; ++v) {
while(IsRotational(s, v)) ++v;
yield return new T(p, v);
}
}
}
}
private sealed class RotationsGroup : FlipRotateGroup
{
public RotationsGroup(byte dimensions) : base(dimensions) { }
public override T IdentityElement { get { return None; } }
public override long Count { get { return _count; } }
public override long Count {
get {
long c = base.Count;
return c - (c >> 1);
}
}
public override bool Contains(T item) {
return base.Contains(item) && item.IsRotation;
}
public override IEnumerator<T> GetEnumerator() {
return _collection.GetEnumerator();
int c = 1 << _dim;
P i = new P();
foreach(P p in i.GetRange<P>(i, _dim)) {
int s = p.SwapsCount;
for(int v = 0; v < c; ++v) {
while(!IsRotational(s, v)) ++v;
yield return new T(p, v);
}
}
}
public override int GetHashCode() { return _count; }
}
private const byte _dimCount = 3;
......
......@@ -5,6 +5,7 @@
using DotNetTransformer.Extensions;
using DotNetTransformer.Math.Group;
using DotNetTransformer.Math.Permutation;
using DotNetTransformer.Math.Set;
namespace DotNetTransformer.Math.Transform {
using T = FlipRotate4D;
......@@ -40,59 +41,91 @@ public struct FlipRotate4D : IFlipRotate<T, P>
return new T(p, 1 << dimTo);
}
public static IEnumerable<T> GetReflections(int dimensions) {
if(dimensions < 0 || dimensions > _dimCount)
throw new ArgumentOutOfRangeException(
);
return FlipRotateExtension.GetValues<T, P>(
dimensions, (p, v) => new T(p, v),
p => p.SwapsCount & 1 ^ 1, v => v + 2
);
}
public static FiniteGroup<T> GetRotations(int dimensions) {
return GetValues(dimensions,
c => dimensions > 0 ? c >> 1 : c,
p => p.SwapsCount & 1, v => v + 2
);
}
public static FiniteGroup<T> GetValues(int dimensions) {
return GetValues(dimensions, c => c, _ => 0, v => v + 1);
}
private static FiniteGroup<T> GetValues(int dimensions,
Generator<int> count,
Converter<P, int> startVertex,
Generator<int> nextVertex
) {
if(dimensions < 0 || dimensions > _dimCount)
throw new ArgumentOutOfRangeException(
);
int f = 1, i = 1;
while(i < dimensions) f *= ++i;
return new InternalGroup(
FlipRotateExtension.GetValues<T, P>(
dimensions, (p, v) => new T(p, v),
startVertex, nextVertex
),
count(f << dimensions)
);
private abstract class FlipRotateSet : FiniteSet<T>
{
protected readonly byte _dim;
protected FlipRotateSet(byte dimensions) {
_dim = dimensions;
}
protected bool IsRotational(int swaps, int vertex) {
for(int i = 1; i < _dim; i <<= 1)
vertex ^= vertex >> i;
return ((swaps ^ vertex) & 1) == 0;
}
public override long Count {
get {
long c = 1L;
for(byte i = 1; i < _dim; c *= ++i) ;
return c << _dim;
}
}
public override bool Contains(T item) {
return item.Vertex >> _dim == 0 &&
item.Permutation.ReducibleTo(_dim);
}
public override IEnumerator<T> GetEnumerator() {
int c = 1 << _dim;
P i = new P();
foreach(P p in i.GetRange<P>(i, _dim))
for(int v = 0; v < c; ++v)
yield return new T(p, v);
}
}
private class FlipRotateGroup : FlipRotateSet, IFiniteGroup<T>
{
public FlipRotateGroup(byte dimensions) : base(dimensions) { }
private sealed class InternalGroup : FiniteGroup<T>
public T IdentityElement { get { return None; } }
}
private sealed class ReflectionsSet : FlipRotateSet
{
private IEnumerable<T> _collection;
private short _count;
public ReflectionsSet(byte dimensions) : base(dimensions) { }
public InternalGroup(IEnumerable<T> collection, short count) {
_collection = collection;
_count = count;
public override long Count {
get {
return base.Count >> 1;
}
}
public override bool Contains(T item) {
return base.Contains(item) && item.IsReflection;
}
public override IEnumerator<T> GetEnumerator() {
int c = 1 << _dim;
P i = new P();
foreach(P p in i.GetRange<P>(i, _dim)) {
int s = p.SwapsCount;
for(int v = 0; v < c; ++v) {
while(IsRotational(s, v)) ++v;
yield return new T(p, v);
}
}
}
}
private sealed class RotationsGroup : FlipRotateGroup
{
public RotationsGroup(byte dimensions) : base(dimensions) { }
public override T IdentityElement { get { return None; } }
public override long Count { get { return _count; } }
public override long Count {
get {
long c = base.Count;
return c - (c >> 1);
}
}
public override bool Contains(T item) {
return base.Contains(item) && item.IsRotation;
}
public override IEnumerator<T> GetEnumerator() {
return _collection.GetEnumerator();
int c = 1 << _dim;
P i = new P();
foreach(P p in i.GetRange<P>(i, _dim)) {
int s = p.SwapsCount;
for(int v = 0; v < c; ++v) {
while(!IsRotational(s, v)) ++v;
yield return new T(p, v);
}
}
}
public override int GetHashCode() { return _count; }
}
private const byte _dimCount = 4;
......
......@@ -5,6 +5,7 @@
using DotNetTransformer.Extensions;
using DotNetTransformer.Math.Group;
using DotNetTransformer.Math.Permutation;
using DotNetTransformer.Math.Set;
namespace DotNetTransformer.Math.Transform {
using T = FlipRotate8D;
......@@ -43,59 +44,91 @@ public struct FlipRotate8D : IFlipRotate<T, P>
return new T(p, 1 << dimTo);
}
public static IEnumerable<T> GetReflections(int dimensions) {
if(dimensions < 0 || dimensions > _dimCount)
throw new ArgumentOutOfRangeException(
);
return FlipRotateExtension.GetValues<T, P>(
dimensions, (p, v) => new T(p, v),
p => p.SwapsCount & 1 ^ 1, v => v + 2
);
}
public static FiniteGroup<T> GetRotations(int dimensions) {
return GetValues(dimensions,
c => dimensions > 0 ? c >> 1 : c,
p => p.SwapsCount & 1, v => v + 2
);
}
public static FiniteGroup<T> GetValues(int dimensions) {
return GetValues(dimensions, c => c, _ => 0, v => v + 1);
}
private static FiniteGroup<T> GetValues(int dimensions,
Generator<int> count,
Converter<P, int> startVertex,
Generator<int> nextVertex
) {
if(dimensions < 0 || dimensions > _dimCount)
throw new ArgumentOutOfRangeException(
);
int f = 1, i = 1;
while(i < dimensions) f *= ++i;
return new InternalGroup(
FlipRotateExtension.GetValues<T, P>(
dimensions, (p, v) => new T(p, v),
startVertex, nextVertex
),
count(f << dimensions)
);
private abstract class FlipRotateSet : FiniteSet<T>
{
protected readonly byte _dim;
protected FlipRotateSet(byte dimensions) {
_dim = dimensions;
}
protected bool IsRotational(int swaps, int vertex) {
for(int i = 1; i < _dim; i <<= 1)
vertex ^= vertex >> i;
return ((swaps ^ vertex) & 1) == 0;
}
public override long Count {
get {
long c = 1L;
for(byte i = 1; i < _dim; c *= ++i) ;
return c << _dim;
}
}
public override bool Contains(T item) {
return (item._value & (_vert << (_dim << 2))) == 0 &&
item.Permutation.ReducibleTo(_dim);
}
public override IEnumerator<T> GetEnumerator() {
int c = 1 << _dim;
P i = new P();
foreach(P p in i.GetRange<P>(i, _dim))
for(int v = 0; v < c; ++v)
yield return new T(p, v);
}
}
private class FlipRotateGroup : FlipRotateSet, IFiniteGroup<T>
{
public FlipRotateGroup(byte dimensions) : base(dimensions) { }
private sealed class InternalGroup : FiniteGroup<T>
public T IdentityElement { get { return None; } }
}
private sealed class ReflectionsSet : FlipRotateSet
{
private IEnumerable<T> _collection;
private int _count;
public ReflectionsSet(byte dimensions) : base(dimensions) { }
public InternalGroup(IEnumerable<T> collection, int count) {
_collection = collection;
_count = count;
public override long Count {
get {
return base.Count >> 1;
}
}
public override bool Contains(T item) {
return base.Contains(item) && item.IsReflection;
}
public override IEnumerator<T> GetEnumerator() {
int c = 1 << _dim;
P i = new P();
foreach(P p in i.GetRange<P>(i, _dim)) {
int s = p.SwapsCount;
for(int v = 0; v < c; ++v) {
while(IsRotational(s, v)) ++v;
yield return new T(p, v);
}
}
}
}
private sealed class RotationsGroup : FlipRotateGroup
{
public RotationsGroup(byte dimensions) : base(dimensions) { }
public override T IdentityElement { get { return None; } }
public override long Count { get { return _count; } }
public override long Count {
get {
long c = base.Count;
return c - (c >> 1);
}
}
public override bool Contains(T item) {
return base.Contains(item) && item.IsRotation;
}
public override IEnumerator<T> GetEnumerator() {
return _collection.GetEnumerator();
int c = 1 << _dim;
P i = new P();
foreach(P p in i.GetRange<P>(i, _dim)) {
int s = p.SwapsCount;
for(int v = 0; v < c; ++v) {
while(!IsRotational(s, v)) ++v;
yield return new T(p, v);
}
}
}
public override int GetHashCode() { return _count; }
}
private const byte _dimCount = 8;
......