RosettaCodeData/Task/Arithmetic-derivative/Maxima/arithmetic-derivative.maxima
2026-04-30 12:34:36 -04:00

17 lines
605 B
Text

arith_deriv(x) := if member(x, [0, 1, -1]) then 0 else block(
n: abs(x),
facs: flatten(map(lambda([l], apply(makelist, l)), ifactors(n))),
nfacs: length(facs),
if nfacs=1 then signum(x) else block(
d: first(facs)+second(facs),
if nfacs>2 then block(
c_prod: makelist(product(facs[i], i, 1, n), n, 1, nfacs),
for i from 3 thru nfacs do d: facs[i]*d+c_prod[i-1]
),
signum(x)*d
)
)$
genmatrix(lambda([i, j], arith_deriv(10*(i-1)+j-100)), 20, 10);
for i from 1 thru 20 do print(sconcat("D(", 10^i, ")/7 = ", arith_deriv(10^i)/7));