Mod
范例
打开所有单元 关闭所有单元基本范例 (4)
范围 (13)
数值运算 (6)
Mod[17, 5]Mod[17, 5, 1]Mod 适用于整数:
Mod[17, 5]Mod[5 / 2, 2]Mod[Sqrt[28], 3]Mod[5 + 3I, 2]Mod[Pi, 2]Mod[3.14, 2.]Mod[10 ^ 10000, 10007]Mod 作用于列表的各项:
Mod[{1, 2, 3, 4, 5}, 3]TraditionalForm 格式:
Mod[a, n]//TraditionalForm符号运算 (7)
Reduce[Mod[2x + 1, 5] == Mod[x, 7] && 0 < x < 50, x]在求和时使用 Mod:
Sum[Mod[n ^ 2, 2], n]Product[Sin[(1/1 + Mod[i ^ 2, 3])], i]FullSimplify[Mod[a, -b] + Mod[-a, b] == 0]识别 Mod 序列:
FindSequenceFunction[{1, 2, 3, 4, 0, 1, 2, 3, 4, 0}, n]DifferenceRootReduce[Mod[k, 3], k]DirichletTransform[Mod[n, 2], n, s]GeneratingFunction[Mod[n, 4], n, x]ExponentialGeneratingFunction[Mod[n, 4], n, x]//FullSimplify应用 (19)
基本应用 (3)
Mod 的前 20 个值:
Grid[{Prepend[Range[20], "n"], Prepend[Table[CarmichaelLambda[n], {n, 20}], "TraditionalFormλ(n)"]}, Background -> {None, {LightYellow, White}}, Dividers -> Lighter[Gray, .5], Spacings -> {Automatic, .8}]DiscretePlot[Mod[n, 8], {n, 50}]DiscretePlot[Mod[100, m], {m, 50}]Mod[n,8] 的母函数:
ModGF[z_] = GeneratingFunction[Mod[n, 8], n, z]GraphicsRow[{Plot[ModGF[x], {x, 0, 1}], ContourPlot[Re[ModGF[x + I * y]], {x, -1, 1}, {y, -1, 1}, ContourStyle -> None]}]ModEGF[z_] = ExponentialGeneratingFunction[Mod[n, 8], n, z];GraphicsRow[{Plot[ModEGF[x], {x, 0, 16}], ContourPlot[Re[ModEGF[x + I * y]], {x, -1, 1}, {y, -1, 1}, ContourStyle -> None]}]ModL[s_] = Sum[Mod[n, 8] / n ^ s, {n, 1, Infinity}]GraphicsRow[{Plot[ModL[x], {x, 0, 16}], ContourPlot[Re[ModL[x + I * y]], {x, -1, 1}, {y, -1, 1}, ContourStyle -> None]}]数字标识符 (1)
给出 International Standard Book Number (ISBN),查看是否有效:
ISBNs = {"0394380495", "1092312213", "0821801236", "9781944183"};如果
,则为有效的 ISBN,其中每个
是 ISBN 的第
位数:
ValidISBNQ[str_] := Module[
{l}, l = ToExpression[StringPartition[str, 1]];
If[Mod[Sum[l[[i]]i, {i, 10}], 11] == 0, True, False]
];ValidISBNQ /@ ISBNs加密 (2)
{p, q} = Prime[RandomInteger[{10 ^ 4, 10 ^ 5}, {2}]];
n = p qλ = CarmichaelLambda[n]d = NestWhile[#1 + 1& , Round[n / 3], GCD[λ, #1] =!= 1&]e = ModularInverse[d, λ]PowerMod[ToCharacterCode["RSA in Mathematica"], e, n]FromCharacterCode[PowerMod[%, d, n]]用 Mod 创建凯撒密码,通过对字母表进行移位来加密消息:
EncryptCaesar[msg_, key_] := Module[
{encr, decr, x, n, nums, res},
encr = Transpose[{Alphabet[], Range[0, 25]}] /. {x_String, n_Integer} -> (x -> n);
decr = Reverse[encr, 2];
nums = StringPartition[ToLowerCase[msg], 1] /. encr;
res = (Mod[nums + key, 26]) /. decr//StringJoin
];
DecryptCaesar[msg_, key_] := EncryptCaesar[msg, -key];key = 315;
msg = "bewaretheidesofmarch";
EncryptCaesar[msg, key]DecryptCaesar[%, key]数论 (6)
MersennePrimeQ[n_] := TrueQ[Last[NestList[Mod[# ^ 2 - 2, 2 ^ n - 1]&, 4, n - 2]] == 0];Select[Range[3, 100], MersennePrimeQ]Select[Array[Prime, PrimePi[100]], Mod[#, 6] == 1&]GCD[7, 11]Mod[7 ^ (11 - 1), 11]GCD[7, 12]Mod[7 ^ EulerPhi[12], 12]FunctionExpand[Mod[(p - 1)!, p], p∈Primes]x_⊕y_ := Mod[x + y, 2](1⊕0)⊕1用 Mod 求解线性同余方程组:
r = {3, 5, 7};
m = {2, 3, 5};
M = (Times@@m/m);
Mod[Dot[r, #^EulerPhi[#]& /@ M], Times@@m]ChineseRemainder[r, m]计算机科学 (3)
x[0] = UnixTime[]
x[k_] := Mod[a^kx[0], m];m = 2147483647;
a = 16807;Histogram[Table[x[i] / m, {i, 0, 1000}], 10]{a, b, c}[[Mod[Range[10], 3, 1]]]A = {{3, 4}, {2, 5}};MinorMatrix[Mat_List ? MatrixQ] := Map[Reverse, Minors[Mat], {0, 1}]
CofactorMatrix[Mat_List ? MatrixQ] := MapIndexed[#1 (-1) ^ (Plus@@#2)&, MinorMatrix[Mat], {2}]
MatrixAdjoint[Mat_] := Transpose[CofactorMatrix[Mat]];ModularInverseMatrix[Mat_, m_] := Mod[ModularInverse[Det[Mat], m]MatrixAdjoint[Mat], m];
ModularInverseMatrix[A, 13]Mod[A.%, 13]政治、经济和社会科学 (2)
socials = {344401659, 325510778, 212228844, 329938157, 047900151, 372500191, 034367980, 546332190, 509496993, 132489973};AssignSingle[social_, locations_] := Module[
{i = 0},
While[MemberQ[locations[[ ;; , 2]], h[i, social]], i++];
Append[locations, {social, h[i, social]}]
];
AssignAll[socials_] := Module[
{l = Length[socials], locations = {}},
For[i = 1, i ≤ l, i++, locations = AssignSingle[socials[[i]], locations]];
locations
];AssignAll[socials]m = 4969;
num = 10 ^ 3 + 1;
g[k_] := Mod[k + 1, m - 2];
hash[k_] := Mod[k + num g[k], m];
social = 344401659;hash[social]其他应用 (2)
Graphics[Line[Table[Mod[t, {Sqrt[2], 1}], {t, 0, 15, .001}]]]Needs["Music`"]Sound[SoundNote[{"CSharp", "DFlat"}, 1, "Piano"]]Mod[HertzToCents[{Csharp1, Csharp2}], 1200]属性和关系 (7)
Mod 是周期函数:
FunctionPeriod[Mod[n, 3], n]Mod 对所有复数有定义:
FunctionDomain[Mod[n, 3], n]FunctionRange[Mod[n, 3], n, m]Mod 具有传递性. 如果
和
,则
:
Mod[5, 3] == Mod[2, 3]Mod[2, 3] == Mod[8, 3]Mod[8, 3] == Mod[5, 3]Divisible[8, 2]Mod[8, 2]QuotientRemainder[a,n] 与 Mod[a,n] 相同:
QuotientRemainder[17, 6]//LastMod[17, 6]用 PowerMod 计算模逆:
PowerMod[3, -1, 7]Mod[3 5, 7]Mod[{5, -5}, 3]Mod[{5, -5}, -3]对于正实数 x,Mod[x,1] 给出 x 的小数部分:
Mod[3.14, 1]FractionalPart[3.14]可能存在的问题 (1)
Mod[GoldenRatio ^ 1000, 1]重置 $MaxExtraPrecision 的值:
Block[{$MaxExtraPrecision = Infinity}, Mod[GoldenRatio ^ 1000, 1]]巧妙范例 (4)
ArrayPlot[Table[Mod[Binomial[i, j], 2], {i, 0, 63}, {j, 0, 63}]]ArrayPlot[CellularAutomaton[{Mod[Total[#], 4]&, {}, 1}, {{1}, 0}, 50]]绘制 Ulam 螺旋,其中根据它们的同余模 49 对数字着色:
ulam[n_] := Partition[Permute[Range[n ^ 2], Accumulate[Take[Flatten[{{n ^ 2 + 1} / 2, Table
[(-1) ^ j i, {j, n}, {i, {-1, n}}, {j}]}], n ^ 2]]], n]ArrayPlot[Mod[ulam[109], 109], ColorFunction -> "TemperatureMap"]ArrayPlot[Table[Mod[a + b, 4], {a, 0, 8}, {b, 0, 8}], ColorFunction -> "Rainbow"]历史
1988年引入 (1.0) | 在以下年份被更新:1996 (3.0) ▪ 1999 (4.0) ▪ 2000 (4.1) ▪ 2002 (4.2)
文本
Wolfram Research (1988),Mod,Wolfram 语言函数,https://reference.wolfram.com/language/ref/Mod.html (更新于 2002 年).
CMS
Wolfram 语言. 1988. "Mod." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2002. https://reference.wolfram.com/language/ref/Mod.html.
APA
Wolfram 语言. (1988). Mod. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/Mod.html 年
BibTeX
@misc{reference.wolfram_2026_mod, author="Wolfram Research", title="{Mod}", year="2002", howpublished="\url{https://reference.wolfram.com/language/ref/Mod.html}", note=[Accessed: 11-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_mod, organization={Wolfram Research}, title={Mod}, year={2002}, url={https://reference.wolfram.com/language/ref/Mod.html}, note=[Accessed: 11-September-2026]}