Perfect numbers: Difference between revisions

Content added Content deleted
m (Added translation from Mathematica)
(Add Spad code)
Line 89: Line 89:
=={{header|Axiom}}==
=={{header|Axiom}}==
{{trans|Mathematica}}
{{trans|Mathematica}}
Using the interpreter, we can define the function:
Custom function:
<lang Axiom>perfect?(n:Integer):Boolean == reduce(+,divisors n) = 2*n</lang>
<lang Axiom>perfect?(n:Integer):Boolean == reduce(+,divisors n) = 2*n</lang>
Alternatively, using the Spad compiler:
<lang Axiom>)abbrev package TESTP TestPackage
TestPackage() : with
perfect?: Integer -> Boolean
==
add
import IntegerNumberTheoryFunctions
perfect? n == reduce("+",divisors n) = 2*n</lang>

Examples (testing 496, testing 128, finding all perfect numbers in 1...10000):
Examples (testing 496, testing 128, finding all perfect numbers in 1...10000):
<lang Axiom>perfect? 496
<lang Axiom>perfect? 496