RosettaCodeData/Task/Arithmetic-derivative/CLU/arithmetic-derivative.clu

45 lines
1.3 KiB
Plaintext

factors = iter (n: bigint) yields (bigint)
own zero: bigint := bigint$i2bi(0)
own two: bigint := bigint$i2bi(2)
own three: bigint := bigint$i2bi(3)
while n>zero cand n//two = zero do yield(two) n := n/two end
fac: bigint := three
while fac<=n do
while n//fac = zero do yield(fac) n := n/fac end
fac := fac + two
end
end factors
lagarias = proc (n: bigint) returns (bigint)
own zero: bigint := bigint$i2bi(0)
if n < zero then return(-lagarias(-n)) end
sum: bigint := zero
for fac: bigint in factors(n) do
sum := sum + n / fac
end
return(sum)
end lagarias
start_up = proc ()
own po: stream := stream$primary_output()
own seven: bigint := bigint$i2bi(7)
own ten: bigint := bigint$i2bi(10)
for n: int in int$from_to(-99, 100) do
stream$putright(po, bigint$unparse(lagarias(bigint$i2bi(n))), 7)
if (n + 100)//10 = 0 then stream$putl(po, "") end
end
for m: int in int$from_to(1, 20) do
d: bigint := lagarias(ten ** bigint$i2bi(m)) / seven
stream$puts(po, "D(10^")
stream$putright(po, int$unparse(m), 2)
stream$puts(po, ") / 7 = ")
stream$putright(po, bigint$unparse(d), 25)
stream$putl(po, "")
end
end start_up