I think I like this implementation much better. It's reduced to the
essential, namely the implementation of the ring structure, and it's
easy to coerce any arithmetic function into it. Eg:
(1) -> m: DIRRING INT := (n: PI):INT +-> moebiusMu n
(1) [1,- 1,- 1,0,- 1,1,- 1,0,0,1,...]
Type: DirichletRing(Integer)
(2) -> e: DIRRING INT := (n: PI):INT +-> eulerPhi n
(2) [1,1,2,2,4,2,6,4,6,4,...]
Type: DirichletRing(Integer)
(3) -> recip m
(3) [1,1,1,1,1,1,1,1,1,1,...]
Type: Union(DirichletRing(Integer),...)
(4) -> recip m * e
(4) [1,2,3,4,5,6,7,8,9,10,...]
Type: DirichletRing(Integer)
Anybody knows of any additional structure this ring carries? I guess I
should make it an Algebra Coef, right?
Martin
)abbrev domain DIRRING DirichletRing
DirichletRing(Coef: Algebra Integer):
Exports == Implementation where
PI ==> PositiveInteger
FUN ==> PositiveInteger -> Coef
Exports ==> Join(Ring, Eltable(PI, Coef)) with
coerce: Stream Coef -> %
coerce: FUN -> %
coerce: % -> Stream Coef
if Coef has Field then
quotients: % -> %
Implementation ==> add
Rep := Record(function: FUN)
per(f: Rep): % == f pretend %
rep(a: %): Rep == a pretend Rep
elt(a: %, n: PI): Coef ==
f: FUN := (rep a).function
f n
indices: Stream Integer
:= integers(1)$StreamTaylorSeriesOperations(Integer)
coerce(a: %): Stream Coef ==
f: FUN := (rep a).function
map((n: Integer): Coef +-> f(n::PI), indices)
$StreamFunctions2(Integer, Coef)
coerce(f: %): OutputForm == f::Stream Coef::OutputForm
coerce(f: FUN): % == per [f]
coerce(f: Stream Coef): % ==
((n: PI): Coef +-> f.(n::Integer))::%
1: % ==
((n: PI): Coef +-> (if one? n then 1$Coef else 0$Coef))::%
0: % ==
((n: PI): Coef +-> 0$Coef)::%
-- if Coef has Field then
-- quotients f ==
-- map((num: Coef, den: Coef): Coef +-> num / den, _
-- rest f::Stream(Coef), f::Stream(Coef))
-- $StreamFunctions3(Coef, Coef, Coef)
--
(f: %) + (g: %) ==
((n: PI): Coef +-> f(n)+g(n))::%
- (f: %) ==
((n: PI): Coef +-> -f(n))::%
import IntegerNumberTheoryFunctions
(f: %) * (g: %) ==
conv := (n: PI): Coef +-> _
reduce((a: Coef, b: Coef): Coef +-> a + b, _
[f(d::PI) * g((n quo d)::PI) for d in
divisors(n::Integer)], 0)
$ListFunctions2(Coef, Coef)
conv::%
qrecip: (%, Coef, PI) -> Coef
qrecip(f: %, f1inv: Coef, n: PI): Coef ==
if one? n then f1inv
else
-f1inv * reduce(_+, [f(d::PI) * qrecip(f, f1inv, (n quo d)::PI)
_
for d in rest divisors(n)], 0) _
$ListFunctions2(Coef, Coef)
recip f ==
if (f1inv := recip(f(1$PI))$Coef) case "failed" then "failed"
else
mp := (n: PI): Coef +-> qrecip(f, f1inv, n)
mp::%::Union(%, "failed")
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en.