Open mechvel opened 1 year ago
I'm afraid I don't quite understand what your question is. Please could you state it explicitly?
The `?' symbol meant ``What people think of this?''.
Exponentiation x ^ n in Monoid can be optimized to work faster at run time.
i suggest this optimization.
This is by converting n to binary nB : ℕᵇ
and applying x ^ᵇ nB
,
where _^ᵇ_ : Carrier → ℕᵇ → Carrier
is implemented as shown above (the binary method for exponentiation).
This is shown above.
The computation takes O(log(n)) operations, while the naive method takes O(n) operations.
The property proofs for this _^_
are implemented as shown above.
And the whole design is simple.
Further, exponentiation ^ in Semiring R can be implemented as ^ of its monoid Semiring.*-monoid R
-- I have an impression that this is already in lib-2.0-rc1.
The `?' symbol meant ``What people think of this?''.
Thanks. In general, it'll definitely go faster if you explicitly state the question you wanted answered, rather than sticking a ?
at the end of a long block of text.
Yup, if you want to add the optimised version of exponentiation then there's no problem with that. However, I think I would recommend doing it using the standard ℕ
rather than ℕᵇ
.
lib-2.0-rc1 has Algebra/Properties/Semiring/Exp
I undertsand it so that it defines
_^_
for a semiring via importing_^_
from `*-monoid'.If so, than this has sense, because most of the properties of
^
can be proved for Monoid, and one has not to prove them twice. Then, there follows TailRecursiveOptimised.agda, which gives a certain optimization for^
-- which I do not understand, so far.But it is possible optimization of
_^_
via the binary method for exponentiation.For Monoid :
And all the properties for
_^_
are proved by porting the proofs for_^'_
by using^≗^'
. ?