[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Axiom-math] Re: [Axiom-mail] Lexicographic order
From: |
Martin Rubey |
Subject: |
[Axiom-math] Re: [Axiom-mail] Lexicographic order |
Date: |
Tue, 30 Aug 2005 11:46:49 +0200 |
Dear Jens,
Jens Axel Søgaard writes:
> Part of my problem was that I had to polynomials, which might be belong
> to polynomial rings over different variables. [...]
> Lexorder examines the difference of exponent vectors of the multivariate
> polynomials p and q. If the leftmost non-zero entry is positive, then p>q.
>
> lexorder?(p,q) ==
> if empty?(variables(p))
> then return ~empty?(variables(q))
> else
> vars := sort(members(union(set(variables(p)),
> set(variables(q))))::List Symbol)
> a := vector(members(degree( p::DMP(vars,?) )))
> b := vector(members(degree( q::DMP(vars,?) )))
> n := select( x +-> ~zero?(x), members(a-b))
> if empty?(n)
> then return false
> else return positive?(first(n))
You probably get a better understanding if you declare your functions. For
example, instead of
lexorder?(p,q) ==
write
lexorder?(p: POLY INT, q: POLY INT): Boolean ==
This also helps the reader to get a fealing what your code is about.
I do admit tht there is an unfortunate restriction about declared functions: it
is not possible to define "generic" declared functions in the interpreter, you
have to use packages for that. For example, if you want to have a function
lexorder? that works for polynomials over an arbitrary ring, you have only two
choices: not declare your function at all, as you did it in the first place, or
write a package, i.e., a file with extension .spad containing
)abbrev package TEST Test
Test(R: Ring): with
lexorder?: (Polynomial R, Polynomial R) -> Boolean
== add
lexorder?(p, q) == code comes here
Note that spad code is indentation sensitive and abbreviations like POLY for
Polynomial are not allowed. If you prefer, aldor provides a non-indentation
sensitive syntax...
Martin