Axiom solves this problem by separating the category
information from the specific domain information.

Thus you can have a categorical implementation that works for
every domain in the category but you can supply a specific
implementation for a given domain.

So a dense matrix and a sparse matrix are both matrices
but each can override the default multiply routine for
efficiency reasons.

Domains can take parameters that specify information.
Polynomials are represented by a domain that supplies the
coefficient ring R so that you can create a polynomial over
integers, a polynomial over fractions, a polynomial over
the roman numerals, etc. Thus you say you want a
Polynomial(Fraction(Integer)), a polynomial with fraction coefficients.
Fraction(Polynomial(Integer)), a fraction with polynomials in the
numerator and denomiator where the coefficients of the polynomials
are integers.

So if p is a polynomial with fractional coefficients
(that is, Polynomial(Fraction(Integer))

 1  3   1  2
 - x  + - x
 7      3

we can ask for the same thiing as a fraction of polynomials
(that is, Fraction(Polynomial(Integer))

   3       2
3x  + 7x
---------
     21

which is known as rearranging the "type tower"

Sage can use a similar scheme to separate the category information
from the domain information and from the domain representation.
From a mathematical point of view this has been a very successful
way to separate concerns.

Tim Daly

Johan S. R. Nielsen wrote:
On Aug 11, 1:28 pm, koffie <[email protected]> wrote:
Hej Johan,

It indeed seems to be at the core of a wider problem. The core of the
problem seems that sometimes you can represent various objects in
different ways.

- So in the coding theory example you can represent a general linear
code by a generator matrix. While you can represent a cyclic linear
code by a generator polynomial.
- In real_lazy you represent sqrt(2) as an algebraic element. But you
want to execute functions on it's binary representation (1.011010100
etc.).
- In linear algebra you can represent a matrix as a sparse or a dense
matrix.
- In commutative algebra you can represent a polynomial in a sparse or
a dense way.
- More suggestions are welcome :)

In all these cases you might sometimes want to execute functions as
implemented for the other representation. The big question of this
topic was how to nicely make these functions available as attributes
without breaking class inheritance and docstrings. I guess the best
solution suggested is Robert Bradshaw's solution. It would be nice to
have a working example of it's suggestion to be able to test it. And
maybe also add a section to the "structuring code in Sage" part in the
sage developers guide.

This is exactly it, and it crops up more or less everywhere in
mathematics. What I want to do for the error-correcting codes case
(exemplified via the one question posed above), is to begin with the
representation which is "mostly" used (or the representation most
tightly encompassing the object in question), so for a cyclical code,
I would use the generator polynomial. Whenever one wants to access it
as a linear code, this should be seamlessly (or close to) allowed, and
should generate the generator matrix in the background and cache it
for later use. Unfortunately, inheritance seems to me to be at the
same time too rigid and too weak, so I would sidestep that entirely
and rely on ducktyping (and manual implementing of "inherited"
attributes -- perhaps using solutions inspired by Robert's here).

Problems like this and the one of this thread arise all the time, but
I have yet to see an "agreed" or standardised solution ideology in
Sage. Has it ever been decided? Or is it empirically defined through
the current Sage code? I would very much like to see it in a section
called "Structuring code in Sage" -- just as much as I would like to
see such a section. The existing documentation in "Writing code for
Sage" is only concerned with micro-level problems such as doc-strings
and naming conventions; there is no discussion on macro-level stuff
like structuring. I guess this is also to encourage taking these
discussions on this board but sometimes general stuff is agreed on
such discussion which could be written down. I guess; I am new here,
so I might easily have missed something fundamental.

@Johan, is the problem I describe here the only one that was mentioned
in the other google thread or are there more?

There are several more, and some of them less specific. More or less
my entire first post is a discussion of how to solve the general case
of your example problem for the codes as well as related problems
regarding how to encode and decode. I invite everyone (also those not
familiar with error-correcting codes) with an opinion on these
structuring issues to join the discussion.

Cheers,
Johan


--
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to