[Aimmath-commit] AIM/WEB-INF/maple/aim Number.mpl,1.1,1.2
Brought to you by:
gustav_delius,
npstrick
From: <mo...@us...> - 2003-10-26 04:07:13
|
Update of /cvsroot/aimmath/AIM/WEB-INF/maple/aim In directory sc8-pr-cvs1:/tmp/cvs-serv19719 Modified Files: Number.mpl Log Message: added several prime factorization utilities Index: Number.mpl =================================================================== RCS file: /cvsroot/aimmath/AIM/WEB-INF/maple/aim/Number.mpl,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Number.mpl 1 Sep 2003 05:55:59 -0000 1.1 --- Number.mpl 26 Oct 2003 04:03:58 -0000 1.2 *************** *** 207,209 **** --- 207,274 ---- ): + `Package/Assign`( + `Number/PrimeFactorizationPlain`, + "Returns a string containing the prime factorization of the positive integer @n@ in a plain format, e.g. \"2^3*5\". See #`Number/PrimeFactorization`# for a proc that returns a LaTeX string that contains the prime factorization.", + proc(n::posint) + local s,pf,i; + if n=1 then return "1" fi: + s:=""; pf:=ifactors(n)[2]; + for i to nops(pf) do + if pf[i][2]=1 then s:=s,pf[i][1]; + else s:=s,pf[i][1],"^",pf[i][2]; fi; + if i<nops(pf) then s:=s,"*" fi: + od: + cat(s); + end + ): + + `Package/Assign`( + `type/PosintString`::type, + "Matches strings consisting entirely of one or more digits 0-9", + proc(s) return StringTools:-RegMatch("^[0-9]+$",s) end + ): + + `Package/Assign`( + `type/PowerString`, + "Matches strings of the form \"m^n\" where @m@ and @n@ are nonnegative integers", + proc(s) return StringTools:-RegMatch("^[0-9]+\\^[0-9]+$",s) end + ): + + `Package/Assign`( + `type/PrimeString`, + "Matches a string that represents a positive prime integer, e.g. \"11\"", + proc(s) return type(s,PosintString) and isprime(parse(s)) end + ): + + `Package/Assign`( + `type/PrimePowerString`, + "Matches a string of the form \"p^n\" where @p@ is a prime and @n@ is a nonnegative integer.", + proc(s) + return type(s,PowerString) and + isprime(parse(StringTools:-Split(s,"^")[1])); + end + ): + + `Package/Assign`( + `type/PrimeFactorizationString`, + "A utility used by #type/PrimeFactorization#", + proc(s) + local S,L; + if type(s,string) then + S:=`Util/RemoveWhiteSpace`(s): + if S="1" then return true fi: + L:=StringTools:-Split(S,"*"); + return type(L,list(Or(PrimeString,PrimePowerString))) + else + false + fi: + end + ): + + `Package/Assign`( + `type/PrimeFactorization`, + "Matches strings which are the prime factorization of a positive integer, e.g. \"2*3^2**7^2*11\". Whitespace is ignored. The factors can be entered in any order and a power of the same prime can occur more than once, e.g. \"2*2*3*3^2\". Zero exponents are also allowed, e.g. \"2*3^0*5^2\". This type is useful when asking the students to enter the prime factorization of a number.", + And(string,PrimeFactorizationString) + ): + EndPackage(): |