tr2vecK_JPH {lazy.symbolic}R Documentation

複数行列の積のトレースを vec 演算子とクロネッカー積で変換

Description

英語のヘルプファイルは: tr2vecK

Arguments

A

最初の行列、または単位行列

B

2 番目の行列、または単位行列

C

3 番目の行列、または単位行列

D

4 番目の行列、または単位行列

method

= 1 または 2

Details

この関数は tr(A%*%B%*%C%*%D) を変換します。
method=1 の場合、結果は
t(vec(D)) %*% (A %@% t(C)) %*% vec(t(B)) となります。
method=2 の場合、結果は
t(vec(t(D))) %*% (t(C) %@% A) %*% vec(B) となります。

入力行列は数値行列、半記号行列、完全記号行列のいずれでも構いません。

入力行列の数が 4 未満の場合、I(単位行列)を設定することで 様々な結果を得ることが可能です。

Value

変換結果としての式を返します。

Examples

# 完全記号行列を用いた一般形
tr2vecK("A", "B", "C", "D", method=1)
tr2vecK("A", "B", "C", "D", method=2)

# 簡単な例
tr00 <- "tr(A%*%B)"
tr01 <- tr2vecK("A", "B",,, method=1)
tr02 <- tr2vecK("A",, "B",, method=1)

## Not run: 
# 記号行列で結果を確認
A <- demomat(2,2,root="a")
B <- demomat(2,2,root="b")

dim(tr00) <- c(1,1); attributes(tr00)$fullsymb <- 1
dim(tr01) <- c(1,1); attributes(tr01)$fullsymb <- 1
dim(tr02) <- c(1,1); attributes(tr02)$fullsymb <- 1
matReplace(tr00, A=A, B=B, I=diag(2))
matReplace(tr01, A=A, B=B, I=diag(2))
matReplace(tr02, A=A, B=B, I=diag(2))

C <- demomat(2,2,root="c")
D <- demomat(2,2,root="d")

tr1 <- tr(A%*%B%*%C%*%D)
tr1 <- Expand(tr1, all=1)

tr2 <- tr2vecK(A,B,C,D, method=1)
tr2 <- Expand(tr2, all=1)

res1 <- analyze_expr(c(tr1))$tab
res2 <- analyze_expr(c(tr2))$tab

# 乗算因子の並び替え
od <- order(res1[,"factor_1"], res1[,"factor_2"], res1[,"factor_3"], res1[,"factor_4"])
res1 <- res1[od,]
res11 <- paste(apply(res1, 1, function(x){paste(x, collapse="")}), collapse=" ")
od <- order(res2[,"factor_2"], res2[,"factor_4"], res2[,"factor_3"], res2[,"factor_1"])
res2 <- res2[od, c("topers", "factor_2", "o2",  "factor_4", "o2",  "factor_3", "o2",  "factor_1")]
res22 <- paste(apply(res2,1,function(x){paste(x,collapse="")}), collapse=" ")
Print(res11,res22)
identical(res11,res22)

# method=2 の完全版
tr3 <- tr2vecK(A,B,C,D, method=2)
tr3 <- Expand(tr3, all=1)

res3 <- analyze_expr(tr3)$tab

od <- order(res3[,"factor_3"], res3[,"factor_4"], res3[,"factor_2"], res3[,"factor_1"])
res3 <- res3[od, c("topers", "factor_3", "o2", "factor_4", "o2", "factor_2", "o2", "factor_1")]
res33 <- paste(apply(res3,1,function(x){paste(x,collapse="")}), collapse=" ")
Print(res11,res33)
identical(res11,res33)

## End(Not run)


[Package lazy.symbolic version 1.0.0.20250830 ]