In Isabelle, I have defined a function f:'a -> nat
where 'a
is some algebraic structure that extends a monoid (i.e. a group, semiring, ring, integral domain, field, ...).
I would like to use the output of this function as "coefficients" for my type 'a
in other constructs. That is, if x:'a
and n:nat
, I would like to be able to use some operation ·:'a -> nat -> 'a
that allows me to tell Isabelle that n·x = x + x + ... + x
.
By searching a bit, I found the "Power.thy" theory and, in a sense, it does what I want. However, it does it for the "multiplicative version" of my problem. This is an issue if I want to change 'a
for e.g. the integers. Using it would mean that instead of computing n·x
, Isabelle would do x^n
. Is there an analogous version to "Power.thy" that does what I want? Or are there any other ways to circumvent this problem?
I do not know of any predefined constant that implements such an operation, but it can easily be implemented by iterating addition, e.g., using comppow
on nat
:
definition scale :: "nat => 'a => 'a" where
"scale a n = ((plus a) ^^ n) 0"
where plus
refers to the addition operation of your structure and 0
is the neutral element. If you are using the arithmetic type classes from Isabelle/HOL, you should add the sort constraint 'a :: monoid
to scale
's type.
There is also a type class operation scaleR
in Complex_Main
that implements such a coefficient scaling operation, but it allows real
numbers, not only nat
s, so your structure might not satisfy all the required axioms (type class real_vector
).