Basic abstract temperament translation code: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Wikispaces>spt3125
**Imported revision 505938090 - Original comment: **
Wikispaces>FREEZE
No edit summary
Line 1: Line 1:
<h2>IMPORTED REVISION FROM WIKISPACES</h2>
(code language: [http://en.wikipedia.org/wiki/Maple_%28software%29 Maple])
This is an imported revision from Wikispaces. The revision metadata is included below for reference:<br>
: This revision was by author [[User:spt3125|spt3125]] and made on <tt>2014-05-01 22:30:57 UTC</tt>.<br>
: The original revision id was <tt>505938090</tt>.<br>
: The revision comment was: <tt></tt><br>
The revision contents are below, presented both in the original Wikispaces Wikitext format, and in HTML exactly as Wikispaces rendered it.<br>
<h4>Original Wikitext content:</h4>
<div style="width:100%; max-height:400pt; overflow:auto; background-color:#f8f9fa; border: 1px solid #eaecf0; padding:0em"><pre style="margin:0px;border:none;background:none;word-wrap:break-word;white-space: pre-wrap ! important" class="old-revision-html">(code language: [[http://en.wikipedia.org/wiki/Maple_%28software%29|Maple]])


----
-----


ech := proc(l)
<ol><li>reduced row echelon form of listlist l</li></ol>local M;


ech := proc(l)
# reduced row echelon form of listlist l
local M;
M := Matrix(l);
M := Matrix(l);
convert(LinearAlgebra[ReducedRowEchelonForm](M), listlist) end:
convert(LinearAlgebra[ReducedRowEchelonForm](M), listlist) end:


relpar := proc(u, v)
relpar := proc(u, v)
# relative parity of two permutations
 
local t;
<ol><li>relative parity of two permutations</li></ol>local t;
 
t := table('antisymmetric');
t := table('antisymmetric');
t[op(u)] := 1;
t[op(u)] := 1;
t[op(v)];
t[op(v)];
end:
end:


pari := proc(u)
pari := proc(u)
# parity of permutation u
 
local v;
<ol><li>parity of permutation u</li></ol>local v;
 
v := sort(u);
v := sort(u);
relpar(u, v) end:
relpar(u, v) end:


zerlist := proc(n)
zerlist := proc(n)
# list of n 0s
 
local i, u;
<ol><li>list of n 0s</li></ol>local i, u;
 
u := NULL;
u := NULL;
for i from 1 to n do
for i from 1 to n do
u := u,0 od;
u := u,0 od;
[u] end:
[u] end:


denomlist := proc(w)
denomlist := proc(w)
map(denom, w) end:
map(denom, w) end:


cleardenom := proc(w)
cleardenom := proc(w)
local n;
local n;
n := ilcm(op(denomlist(w)));
n := ilcm(op(denomlist(w)));
n * w end:
n * w end:


vec2e := proc(w)
vec2e := proc(w)
# rref temperament identifier from val list or projection matrix w
 
local i, u, v, z;
<ol><li>rref temperament identifier from val list or projection matrix w</li></ol>local i, u, v, z;
 
u := ech(w);
u := ech(w);
z := NULL;
z := NULL;
for i from 1 to nops(u) do
for i from 1 to nops(u) do
v := u[i];
v := u[i];
if not convert(v, set)={0} then
if not convert(v, set)={0} then
z := z,v fi od:
z := z,v fi od:
[z] end:
[z] end:


wedgie := proc(w)
wedgie := proc(w)
# reduction of multivector w to wedgie
 
local i, n, u;
<ol><li>reduction of multivector w to wedgie</li></ol>local i, n, u;
 
u := cleardenom(w);
u := cleardenom(w);
n := igcd(op(u));
n := igcd(op(u));
if n=0 then RETURN(w) fi;
if n=0 then RETURN(w) fi;
u := u/n;
u := u/n;
for i from 1 to nops(w) do
for i from 1 to nops(w) do
if not u[i]=0 then
if not u[i]=0 then
if u[i]&gt;0 then RETURN(u) fi;
if u[i]&gt;0 then RETURN(u) fi;
RETURN(-u) fi od end:
RETURN(-u) fi od end:


mvec := proc(l)
mvec := proc(l)
# multivector wedge product of vector list l
 
local c, i, j, k, q, r, t, u, v, w;
<ol><li>multivector wedge product of vector list l</li></ol>local c, i, j, k, q, r, t, u, v, w;
 
u := combinat[permute](nops(l));
u := combinat[permute](nops(l));
c := combinat[choose](nops(l[1]), nops(l));
c := combinat[choose](nops(l[1]), nops(l));
w := zerlist(nops(c));
w := zerlist(nops(c));
for i from 1 to nops(c) do
for i from 1 to nops(c) do
t := c[i];
t := c[i];
r := 0;
r := 0;
for j from 1 to nops(u) do
for j from 1 to nops(u) do
v := u[j];
v := u[j];
q := pari(v);
q := pari(v);
for k from 1 to nops(v) do
for k from 1 to nops(v) do
q := q * l[v[k], t[k]] od;
q := q * l[v[k], t[k]] od;
r := r+q od;
r := r+q od;
w[i] := w[i]+r od;
w[i] := w[i]+r od;
w end:
w end:


wedgie2e := proc(w, n, p)
wedgie2e := proc(w, n, p)
# rank n p-limit multival to rref
 
local b, c, i, j, k, m, u, v, x, y, z;
<ol><li>rank n p-limit multival to rref</li></ol>local b, c, i, j, k, m, u, v, x, y, z;
 
m := numtheory[pi](p);
m := numtheory[pi](p);
b := combinat[choose](m, n);
b := combinat[choose](m, n);
c := combinat[choose](m, n-1);
c := combinat[choose](m, n-1);
z := NULL;
z := NULL;
for i from 1 to nops(c) do
for i from 1 to nops(c) do
u := c[i];
u := c[i];
v := NULL;
v := NULL;
for j from 1 to m do
for j from 1 to m do
y := [op(u), j];
y := [op(u), j];
if nops(convert(y, set))&lt;n then v:=v,0 fi;
if nops(convert(y, set))&lt;n then v:=v,0 fi;
x := sort(y);
x := sort(y);
for k from 1 to nops(b) do
for k from 1 to nops(b) do
if x=b[k] then v := v,relpar(b[k], y)*w[k] fi od od;
if x=b[k] then v := v,relpar(b[k], y)*w[k] fi od od;
v := [v];
v := [v];
z := z,v od;
z := z,v od;
vec2e([z]) end:
vec2e([z]) end:


e2wedgie := proc(l)
e2wedgie := proc(l)
# rref l to wedgie
 
wedgie(mvec(l)) end:
<ol><li>rref l to wedgie</li></ol>wedgie(mvec(l)) end:


e2frob := proc(l)
e2frob := proc(l)
# rref or normal val list to Frobenius projection map
 
local U, V;
<ol><li>rref or normal val list to Frobenius projection map</li></ol>local U, V;
 
U := Matrix(l);
U := Matrix(l);
V := LinearAlgebra[Transpose](U);
V := LinearAlgebra[Transpose](U);
convert(V.(U.V)^(-1).U, listlist) end:
convert(V.(U.V)^(-1).U, listlist) end:


dualproj := proc(w)
dualproj := proc(w)
# dual projection map
 
convert(LinearAlgebra[IdentityMatrix](nops(w[1])), listlist)-w end:
<ol><li>dual projection map</li></ol>convert(LinearAlgebra[IdentityMatrix](nops(w[1])), listlist)-w end:


norc2e := proc(l)
norc2e := proc(l)
# normal comma list to rref
 
local M, N;
<ol><li>normal comma list to rref</li></ol>local M, N;
 
M := Matrix(l);
M := Matrix(l);
N := LinearAlgebra[NullSpace](M);
N := LinearAlgebra[NullSpace](M);
N := convert(N, list);
N := convert(N, list);
N := Matrix(N);
N := Matrix(N);
N := LinearAlgebra[Transpose](N);
N := LinearAlgebra[Transpose](N);
ech(convert(N, listlist)) end:</pre></div>
 
<h4>Original HTML content:</h4>
ech(convert(N, listlist)) end:
<div style="width:100%; max-height:400pt; overflow:auto; background-color:#f8f9fa; border: 1px solid #eaecf0; padding:0em"><pre style="margin:0px;border:none;background:none;word-wrap:break-word;width:200%;white-space: pre-wrap ! important" class="old-revision-html">&lt;html&gt;&lt;head&gt;&lt;title&gt;Basic abstract temperament translation code&lt;/title&gt;&lt;/head&gt;&lt;body&gt;(code language: &lt;a class="wiki_link_ext" href="http://en.wikipedia.org/wiki/Maple_%28software%29" rel="nofollow"&gt;Maple&lt;/a&gt;)&lt;br /&gt;
[[Category:algorithm]]
&lt;br /&gt;
[[Category:code]]
&lt;hr /&gt;
[[Category:maple]]
&lt;br /&gt;
&lt;br /&gt;
ech := proc(l)&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;reduced row echelon form of listlist l&lt;/li&gt;&lt;/ol&gt;local M;&lt;br /&gt;
M := Matrix(l);&lt;br /&gt;
convert(LinearAlgebra[ReducedRowEchelonForm](M), listlist) end:&lt;br /&gt;
&lt;br /&gt;
relpar := proc(u, v)&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;relative parity of two permutations&lt;/li&gt;&lt;/ol&gt;local t;&lt;br /&gt;
t := table('antisymmetric');&lt;br /&gt;
t[op(u)] := 1;&lt;br /&gt;
t[op(v)];&lt;br /&gt;
end:&lt;br /&gt;
&lt;br /&gt;
pari := proc(u)&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;parity of permutation u&lt;/li&gt;&lt;/ol&gt;local v;&lt;br /&gt;
v := sort(u);&lt;br /&gt;
relpar(u, v) end:&lt;br /&gt;
&lt;br /&gt;
zerlist := proc(n)&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;list of n 0s&lt;/li&gt;&lt;/ol&gt;local i, u;&lt;br /&gt;
u := NULL;&lt;br /&gt;
for i from 1 to n do&lt;br /&gt;
u := u,0 od;&lt;br /&gt;
[u] end:&lt;br /&gt;
&lt;br /&gt;
denomlist := proc(w)&lt;br /&gt;
map(denom, w) end:&lt;br /&gt;
&lt;br /&gt;
cleardenom := proc(w)&lt;br /&gt;
local n;&lt;br /&gt;
n := ilcm(op(denomlist(w)));&lt;br /&gt;
n * w end:&lt;br /&gt;
&lt;br /&gt;
vec2e := proc(w)&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;rref temperament identifier from val list or projection matrix w&lt;/li&gt;&lt;/ol&gt;local i, u, v, z;&lt;br /&gt;
u := ech(w);&lt;br /&gt;
z := NULL;&lt;br /&gt;
for i from 1 to nops(u) do&lt;br /&gt;
v := u[i];&lt;br /&gt;
if not convert(v, set)={0} then&lt;br /&gt;
z := z,v fi od:&lt;br /&gt;
[z] end:&lt;br /&gt;
&lt;br /&gt;
wedgie := proc(w)&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;reduction of multivector w to wedgie&lt;/li&gt;&lt;/ol&gt;local i, n, u;&lt;br /&gt;
u := cleardenom(w);&lt;br /&gt;
n := igcd(op(u));&lt;br /&gt;
if n=0 then RETURN(w) fi;&lt;br /&gt;
u := u/n;&lt;br /&gt;
for i from 1 to nops(w) do&lt;br /&gt;
if not u[i]=0 then&lt;br /&gt;
if u[i]&amp;gt;0 then RETURN(u) fi;&lt;br /&gt;
RETURN(-u) fi od end:&lt;br /&gt;
&lt;br /&gt;
mvec := proc(l)&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;multivector wedge product of vector list l&lt;/li&gt;&lt;/ol&gt;local c, i, j, k, q, r, t, u, v, w;&lt;br /&gt;
u := combinat[permute](nops(l));&lt;br /&gt;
c := combinat[choose](nops(l[1]), nops(l));&lt;br /&gt;
w := zerlist(nops(c));&lt;br /&gt;
for i from 1 to nops(c) do&lt;br /&gt;
t := c[i];&lt;br /&gt;
r := 0;&lt;br /&gt;
for j from 1 to nops(u) do&lt;br /&gt;
v := u[j];&lt;br /&gt;
q := pari(v);&lt;br /&gt;
for k from 1 to nops(v) do&lt;br /&gt;
q := q * l[v[k], t[k]] od;&lt;br /&gt;
r := r+q od;&lt;br /&gt;
w[i] := w[i]+r od;&lt;br /&gt;
w end:&lt;br /&gt;
&lt;br /&gt;
wedgie2e := proc(w, n, p)&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;rank n p-limit multival to rref&lt;/li&gt;&lt;/ol&gt;local b, c, i, j, k, m, u, v, x, y, z;&lt;br /&gt;
m := numtheory[pi](p);&lt;br /&gt;
b := combinat[choose](m, n);&lt;br /&gt;
c := combinat[choose](m, n-1);&lt;br /&gt;
z := NULL;&lt;br /&gt;
for i from 1 to nops(c) do&lt;br /&gt;
u := c[i];&lt;br /&gt;
v := NULL;&lt;br /&gt;
for j from 1 to m do&lt;br /&gt;
y := [op(u), j];&lt;br /&gt;
if nops(convert(y, set))&amp;lt;n then v:=v,0 fi;&lt;br /&gt;
x := sort(y);&lt;br /&gt;
for k from 1 to nops(b) do&lt;br /&gt;
if x=b[k] then v := v,relpar(b[k], y)*w[k] fi od od;&lt;br /&gt;
v := [v];&lt;br /&gt;
z := z,v od;&lt;br /&gt;
vec2e([z]) end:&lt;br /&gt;
&lt;br /&gt;
e2wedgie := proc(l)&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;rref l to wedgie&lt;/li&gt;&lt;/ol&gt;wedgie(mvec(l)) end:&lt;br /&gt;
&lt;br /&gt;
e2frob := proc(l)&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;rref or normal val list to Frobenius projection map&lt;/li&gt;&lt;/ol&gt;local U, V;&lt;br /&gt;
U := Matrix(l);&lt;br /&gt;
V := LinearAlgebra[Transpose](U);&lt;br /&gt;
convert(V.(U.V)^(-1).U, listlist) end:&lt;br /&gt;
&lt;br /&gt;
dualproj := proc(w)&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;dual projection map&lt;/li&gt;&lt;/ol&gt;convert(LinearAlgebra[IdentityMatrix](nops(w[1])), listlist)-w end:&lt;br /&gt;
&lt;br /&gt;
norc2e := proc(l)&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;normal comma list to rref&lt;/li&gt;&lt;/ol&gt;local M, N;&lt;br /&gt;
M := Matrix(l);&lt;br /&gt;
N := LinearAlgebra[NullSpace](M);&lt;br /&gt;
N := convert(N, list);&lt;br /&gt;
N := Matrix(N);&lt;br /&gt;
N := LinearAlgebra[Transpose](N);&lt;br /&gt;
ech(convert(N, listlist)) end:&lt;/body&gt;&lt;/html&gt;</pre></div>

Revision as of 00:00, 17 July 2018

(code language: Maple)


ech := proc(l)

  1. reduced row echelon form of listlist l

local M;

M := Matrix(l);

convert(LinearAlgebra[ReducedRowEchelonForm](M), listlist) end:

relpar := proc(u, v)

  1. relative parity of two permutations

local t;

t := table('antisymmetric');

t[op(u)] := 1;

t[op(v)];

end:

pari := proc(u)

  1. parity of permutation u

local v;

v := sort(u);

relpar(u, v) end:

zerlist := proc(n)

  1. list of n 0s

local i, u;

u := NULL;

for i from 1 to n do

u := u,0 od;

[u] end:

denomlist := proc(w)

map(denom, w) end:

cleardenom := proc(w)

local n;

n := ilcm(op(denomlist(w)));

n * w end:

vec2e := proc(w)

  1. rref temperament identifier from val list or projection matrix w

local i, u, v, z;

u := ech(w);

z := NULL;

for i from 1 to nops(u) do

v := u[i];

if not convert(v, set)={0} then

z := z,v fi od:

[z] end:

wedgie := proc(w)

  1. reduction of multivector w to wedgie

local i, n, u;

u := cleardenom(w);

n := igcd(op(u));

if n=0 then RETURN(w) fi;

u := u/n;

for i from 1 to nops(w) do

if not u[i]=0 then

if u[i]>0 then RETURN(u) fi;

RETURN(-u) fi od end:

mvec := proc(l)

  1. multivector wedge product of vector list l

local c, i, j, k, q, r, t, u, v, w;

u := combinat[permute](nops(l));

c := combinat[choose](nops(l[1]), nops(l));

w := zerlist(nops(c));

for i from 1 to nops(c) do

t := c[i];

r := 0;

for j from 1 to nops(u) do

v := u[j];

q := pari(v);

for k from 1 to nops(v) do

q := q * l[v[k], t[k]] od;

r := r+q od;

w[i] := w[i]+r od;

w end:

wedgie2e := proc(w, n, p)

  1. rank n p-limit multival to rref

local b, c, i, j, k, m, u, v, x, y, z;

m := numtheory[pi](p);

b := combinat[choose](m, n);

c := combinat[choose](m, n-1);

z := NULL;

for i from 1 to nops(c) do

u := c[i];

v := NULL;

for j from 1 to m do

y := [op(u), j];

if nops(convert(y, set))<n then v:=v,0 fi;

x := sort(y);

for k from 1 to nops(b) do

if x=b[k] then v := v,relpar(b[k], y)*w[k] fi od od;

v := [v];

z := z,v od;

vec2e([z]) end:

e2wedgie := proc(l)

  1. rref l to wedgie

wedgie(mvec(l)) end:

e2frob := proc(l)

  1. rref or normal val list to Frobenius projection map

local U, V;

U := Matrix(l);

V := LinearAlgebra[Transpose](U);

convert(V.(U.V)^(-1).U, listlist) end:

dualproj := proc(w)

  1. dual projection map

convert(LinearAlgebra[IdentityMatrix](nops(w[1])), listlist)-w end:

norc2e := proc(l)

  1. normal comma list to rref

local M, N;

M := Matrix(l);

N := LinearAlgebra[NullSpace](M);

N := convert(N, list);

N := Matrix(N);

N := LinearAlgebra[Transpose](N);

ech(convert(N, listlist)) end: