You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# In random matrix theory one often encounters expressions of the form
45
46
#
46
-
#X = trace(Q * A * Q' * B)
47
+
#X = Q * A * Q' * B
47
48
#
48
-
#where A and B are deterministic matrices with fixed numerical matrix entries and Q is a random matrix that does not have explicitly defined matrix elements. Instead, one takes an expectation over of expressions of this form and this "integrates out" the Qs to produce a numeric result.
49
+
#where A and B are deterministic matrices with fixed numerical matrix entries
50
+
#and Q is a random matrix that does not have explicitly defined matrix
51
+
#elements. Instead, one takes an expectation over of expressions of this form
52
+
#and this "integrates out" the Qs to produce a numeric result.
49
53
#
50
54
#expectation(X) #= some number
51
55
#
52
-
#I'm curious how far one can implement, in Julia, a data type for Q and expectation() method for which expressions of this form can be written natively as code. This probably strays into the larger question of how much symbolic algebra can be written and handled in Julia, but I think this would be have real payoffs for making possible extremely elegant manipulations of random matrices that doesn't exist in any known computer language.
53
-
#
54
-
#Any thoughts on how feasible this is? Perhaps to begin with, it would be nice to have an expectation() that would work on arbitrary strings of products of matrices. Probably this would involve taking an input expression argument Would like to hear some stuff on t would be nice to start with just how one can write arbitrary products of matrices My initial thoughts are to declare Q::MyRandomMatrix with the type MyRandomMatrix<:AbstractMatrix and to write an expectation(Ex::Expr) function that at first blush traverses the expression Ex, finds a * that takes at least one MyRandomMatrix in its arguments and applies the appropriate substitution.
55
-
#
56
-
#So... 1) How feasible is this and 2) How do I traverse the expression in the way described in the previous paragraph? The "Metaprogramming" manual is somewhat sparse on this other than saying .args[], but that doesn't quite help
57
-
56
+
#Here is a function that symbolically calculates the expectation of a product
57
+
#of matrices over the symmetric group that Q is uniform Haar over.
58
+
#It takes an expression consisting of a product of matrices and replaces it
59
+
#with an evaluated symbolic expression which is the expectation.
58
60
functionExpectation(X::Expr)
59
61
if X.head !=:call
60
62
error(string("Unexpected type of expression: ", X.head))
@@ -75,20 +77,18 @@ function Expectation(X::Expr)
75
77
MyQ=None
76
78
for i=1:n
77
79
thingy=X.args[i+1]
78
-
iftypeof(thingy)==Symbol
79
-
matrixtype =typeof(eval(thingy))
80
-
if matrixtype == HaarMatrix
80
+
ifisa(thingy, Symbol)
81
+
ifisa(eval(thingy), HaarMatrix)
81
82
if MyQ==None MyQ=thingy end
82
83
if MyQ == thingy
83
84
Qidx=[Qidx; i]
84
85
else
85
-
println(string("only one instance of HaarMatrix supported, skipping the other guy ", thingy))
86
-
end
86
+
warning("only one instance of HaarMatrix supported, skipping the other guy ", thingy) end
0 commit comments