File: permutation.hweb

package info (click to toggle)
dynare 4.5.7-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 49,408 kB
  • sloc: cpp: 84,998; ansic: 29,058; pascal: 13,843; sh: 4,833; objc: 4,236; yacc: 3,622; makefile: 2,278; lex: 1,541; python: 236; lisp: 69; xml: 8
file content (147 lines) | stat: -rw-r--r-- 5,118 bytes parent folder | download | duplicates (5)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
@q $Id: permutation.hweb 148 2005-04-19 15:12:26Z kamenik $ @>
@q Copyright 2004, Ondra Kamenik @>

@*2 Permutations. Start of {\tt permutation.h} file.

The permutation class is useful when describing a permutation of
indices in permuted symmetry tensor. This tensor comes to existence,
for instance, as a result of the following tensor multiplication:
$$\left[g_{y^3}\right]_{\gamma_1\gamma_2\gamma_3}
\left[g_{yu}\right]^{\gamma_1}_{\alpha_1\beta_3}
\left[g_{yu}\right]^{\gamma_2}_{\alpha_2\beta_1}
\left[g_u\right]^{\gamma_3}_{\beta_2}
$$
If this operation is done by a Kronecker product of unfolded tensors,
the resulting tensor has permuted indices. So, in this case the
permutation is implied by the equivalence:
$\{\{0,4\},\{1,3\},\{2\}\}$. This results in a permutation which maps
indices $(0,1,2,3,4)\mapsto(0,2,4,3,1)$.

The other application of |Permutation| class is to permute indices
with the same permutation as done during sorting.

Here we only define an abstraction for the permutation defined by an
equivalence. Its basic operation is to apply the permutation to the
integer sequence. The application is right (or inner), in sense that
it works on indices of the sequence not items of the sequence. More
formally $s\circ m \not=m\circ s$. In here, the application of the
permutation defined by map $m$ is $s\circ m$.

Also, we need |PermutationSet| class which contains all permutations
of $n$ element set, and a bundle of permutations |PermutationBundle|
which contains all permutation sets up to a given number.

@s Permutation int
@s PermutationSet int
@s PermutationBundle int

@c
#ifndef PERMUTATION_H
#define PERMUTATION_H

#include "int_sequence.h"
#include "equivalence.h"

#include <vector>

@<|Permutation| class declaration@>;
@<|PermutationSet| class declaration@>;
@<|PermutationBundle| class declaration@>;

#endif

@ The permutation object will have a map, which defines mapping of
indices $(0,1,\ldots,n-1)\mapsto(m_0,m_1,\ldots, m_{n-1})$. The map is
the sequence $(m_0,m_1,\ldots, m_{n-1}$. When the permutation with the
map $m$ is applied on sequence $s$, it permutes its indices:
$s\circ\hbox{id}\mapsto s\circ m$.

So we have one constructor from equivalence, then a method |apply|,
and finally a method |tailIdentity| which returns a number of trailing
indices which yield identity. Also we have a constructor calculating
map, which corresponds to permutation in sort. This is, we want
$(\hbox{sorted }s)\circ m = s$.

@<|Permutation| class declaration@>=
class Permutation {
protected:@;
	IntSequence permap;
public:@;
	Permutation(int len)
		: permap(len) {@+ for (int i = 0; i < len; i++) permap[i] = i;@+}
	Permutation(const Equivalence& e)
		: permap(e.getN()) {@+ e.trace(permap);@+}
	Permutation(const Equivalence& e, const Permutation& per)
		: permap(e.getN()) {@+ e.trace(permap, per);@+}
	Permutation(const IntSequence& s)
		: permap(s.size()) {@+ computeSortingMap(s);@+};
	Permutation(const Permutation& p)
		: permap(p.permap)@+ {}
	Permutation(const Permutation& p1, const Permutation& p2)
		: permap(p2.permap) {@+ p1.apply(permap);@+}
	Permutation(const Permutation& p, int i)
		: permap(p.size(), p.permap, i)@+ {}
	const Permutation& operator=(const Permutation& p)
		{@+ permap = p.permap;@+ return *this;@+}
	bool operator==(const Permutation& p)
		{@+ return permap == p.permap;@+}
	int size() const
		{@+ return permap.size();@+}
	void print() const
		{@+ permap.print();@+}
	void apply(const IntSequence& src, IntSequence& tar) const;
	void apply(IntSequence& tar) const;
	void inverse();
	int tailIdentity() const;
	const IntSequence& getMap() const
		{@+ return permap;@+}
	IntSequence& getMap()
		{@+ return permap;@+}
protected:@;
	void computeSortingMap(const IntSequence& s);
};


@ The |PermutationSet| maintains an array of of all permutations. The
default constructor constructs one element permutation set of one
element sets. The second constructor constructs a new permutation set
over $n$ from all permutations over $n-1$. The parameter $n$ need not
to be provided, but it serves to distinguish the constructor from copy
constructor, which is not provided.

The method |getPreserving| returns a factor subgroup of permutations,
which are invariants with respect to the given sequence. This are all
permutations $p$ yielding $p\circ s = s$, where $s$ is the given
sequence.

@<|PermutationSet| class declaration@>=
class PermutationSet {
	int order;
	int size;
	const Permutation** const pers;
public:@;
	PermutationSet();
	PermutationSet(const PermutationSet& ps, int n);
	~PermutationSet();
	int getNum() const
		{@+ return size;@+}
	const Permutation& get(int i) const
		{@+ return *(pers[i]);@+}
	vector<const Permutation*> getPreserving(const IntSequence& s) const;
};


@ The permutation bundle encapsulates all permutations sets up to some
given dimension.

@<|PermutationBundle| class declaration@>=
class PermutationBundle {
	vector<PermutationSet*> bundle;
public:@;
	PermutationBundle(int nmax);
	~PermutationBundle(); 
	const PermutationSet& get(int n) const;
	void generateUpTo(int nmax);
};

@ End of {\tt permutation.h} file.