-
Notifications
You must be signed in to change notification settings - Fork 1
/
GroupExtension.cs
51 lines (48 loc) · 1.24 KB
/
GroupExtension.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
using System.Collections.Generic;
using DotNetTransformer.Extensions;
namespace DotNetTransformer.Math.Group {
public static class GroupExtension
{
public static T Compose<T>(this T _this, T other)
where T : IGroupElement<T>, new()
{
return other.Add(_this);
}
public static T Subtract<T>(this T _this, T other)
where T : IGroupElement<T>, new()
{
return _this.Add(other.InverseElement);
}
public static T Conjugate<T>(this T t, T o)
where T : IGroupElement<T>, new()
{
return o.InverseElement.Add(t).Add(o);
}
public static T GetCommutatorWith<T>(this T t, T o)
where T : IGroupElement<T>, new()
{
return o.Add(t).InverseElement.Add(t.Add(o));
}
public static T AddAll<T>(this IEnumerable<T> collection)
where T : IGroupElement<T>, new()
{
return collection.CollectAll<T>((l, r) => l.Add(r));
}
public static T ComposeAll<T>(this IEnumerable<T> collection)
where T : IGroupElement<T>, new()
{
return collection.CollectAll<T>(Compose<T>);
}
public static T Times<T>(this T t, int count)
where T : IGroupElement<T>, new()
{
T r = (count & 1) != 0 ? t : new T();
while((count >>= 1) != 0) {
t = t.Add(t);
if((count & 1) != 0)
r = r.Add(t);
}
return r;
}
}
}