Question

There is a matrix multiplication definition in Cartesian_Euclidean_Space (in directory HOL/Multivariate_Analysis"):

definition matrix_matrix_mult :: "('a::semiring_1) ^'n^'m ⇒ 'a ^'p^'n ⇒ 'a ^ 'p ^'m"
    (infixl "**" 70)
  where "m ** m' == (χ i j. setsum (λk. ((m$i)$k) * ((m'$k)$j)) (UNIV :: 'n set)) ::'a ^ 'p ^'m"

Now the the squared matrix would be A ** A and A^3 would be A ** A ** A.

I couldn't find a powerfunction, to define A^n (i.e., A ** A ** ... ** A n times).

Is there a power function in the library? Is a manual definition needed?

Was it helpful?

Solution

I have found the following definition in HOL/Power.thy :

primrec power :: "'a ⇒ nat ⇒ 'a" (infixr "^" 80) where
    power_0: "a ^ 0 = 1"
  | power_Suc: "a ^ Suc n = a * a ^ n"

(Control + Click gets you to the respecitve definition! So I clicked on "^", I just wrote "1 ^ 1 = 1" as a lemma first.

Here is the definition for the power of a matrice. (As I only use square matrices this is fine, but a more general type of ^'n^'m would be nice.)

primrec powerM :: "(('a::semiring_1) ^'n^'n) ⇒ nat ⇒ (('a::semiring_1) ^'n^'n)" 
(infixr "^^^" 80) where
  powerM_0: "A ^^^(0::nat) = mat 1"
| powerM_Suc: "A ^^^(Suc n) = A ** (powerM A n)"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top