Here is a bit of power with types... ;-)
---rhxBEGIN m.spad
)abbrev package MYEXP MyExp
MyExp(F: Ring): with
myexp: F -> F
myexp: (F, PositiveInteger) -> F
== add
myexp(x: F, n: PositiveInteger): F ==
y: F := 1
z: F := 1
for i in 1..n repeat
z := z * x
y := y + z
y
myexp(x: F): F == myexp(x, 10)
---rhxEND m.spad
That's generic code and has to be compiled. Look at the types of the result.
Ralf
(3) -> )clear all
All user variables and function definitions have been cleared.
(1) -> )compile m.spad
(1) -> myexp(0.1)
(1) 1.1111111111
Type: Float
(2) -> myexp(0.1,4)
(2) 1.1111
Type: Float
(3) -> myexp(2,4)
(3) 31
Type: PositiveInteger
(4) -> myexp(2/3,4)
211
(4) ---
81
Type: Fraction(Integer)
--
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.