Depth[expr]
式 expr の任意の部分を指定するために必要な指標の最大数に1を加算した数を返す.
Depth
Depth[expr]
式 expr の任意の部分を指定するために必要な指標の最大数に1を加算した数を返す.
例題
すべて開く すべて閉じる例 (3)
Depth[a]Depth[{a}]Depth[{{a}}]Depth[{{{a}}}]Depth[{{{a}, b}}]Depthは任意の式に使うことができる:
Depth[1 + x ^ 2]TreeFormを使って深さを式のレベル数として可視化する:
TreeForm[1 + x ^ 2]スコープ (10)
一般的な式の深さ (5)
Depthはリストだけでなく,どのような式にも使うことができる:
Depth[f[f[f[x]]]]Depthは頭部を認識しない:
Depth[f[g[h[x]]]]Depth[symbol]Depth["string"]Depth[12345]Depth[3 + I]Depth[(1/2)]NumberQではない数式はより深い:
Depth[Sqrt[2]]デフォルトで,Depthは頭部の深さは数えない:
Depth[h[{{{a}}}][x, y]]オプション設定HeadsTrueを使って頭部も含むようにする:
Depth[h[{{{a}}}][x, y], Heads -> True]特別な式の深さ (5)
Depth[<|1 -> a|>]Depth[<|f[g[x]] -> a|>]Depth[{a}]Depth[<|1 -> x|>]Depth[<|1 -> x + y|>]Depth[<|1 -> <|2 -> 3|>|>]DepthはSparseArrayオブジェクトおよび構造配列オブジェクトを対応する通常のリストのように扱う:
Depth[SparseArray[Automatic, {1, 1, 1, 1}, 0, {1, {{0, 1}, {{1, 1, 1}}}, {x}}]]Depth[SymmetrizedArray[StructuredArray`StructuredData[{4, 4}, {{{1, 2} -> a, {2, 3} -> b},
Symmetric[{1, 2}]}]]]Depth[Graph[{1 -> 2, 3 -> 4}]]Depth[MeshRegion[{{0}, {1}, {2}, {3}}, {Line[{1, 2}], Line[{3, 4}]}]]オプション (1)
アプリケーション (2)
Table[Depth[Integrate[1 / (x ^ n - 1), x]], {n, 10}]組合せの式の深さを求める [詳細]:
combs = NestList[# /. s[x_][y_][z_] -> x[z][y[z]]&, s[s][s][s[s]][s][s], 4]Depth /@ combsDepth[#, Heads -> True]& /@ combsmoreCombs = NestList[# /. s[x_][y_][z_] -> x[z][y[z]]&, s[s][s][s[s]][s][s], 30];Depth /@ moreCombsDepth[#, Heads -> True]& /@ moreCombs特性と関係 (5)
Depthは,一般に,指数の最大数に1加えた長さを返す:
Position[(1 + x)(2 + y ^ 3), _]Depth[(1 + x)(2 + y ^ 3)]% == Max[Length /@ %%] + 1Depthは式の最も深い部分を考慮する:
{Depth[{{a}, {b}}], Depth[{{a}, {f[b]}}]}ArrayDepthは式が完全に矩形となるレベルしか考慮しない:
{ArrayDepth[{{a}, {b}}], ArrayDepth[{{a}, {f[b]}}]}Depthは,完全に矩形の式についてはArrayDepthより1つ大きい結果を与える:
{Depth[{a, b}], ArrayDepth[{a, b}]}{Depth[{{a}, {b}}], ArrayDepth[{{a}, {b}}]}Depth[expr]はLevel[expr,{k}]が空リストを返す最小の正のレベル k である:
expr = a + f[x, y ^ n];Table[Level[expr, {k}], {k, 0, Depth[expr]}]長さが0の関数または複合頭部が存在するなら,DepthとLevelの両方にHeadsTrueを使わなければならない:
expr = a + f[];Table[Level[expr, {k}], {k, 0, Depth[expr]}]Table[Level[expr, {k}, Heads -> True], {k, 0, Depth[expr, Heads -> True]}]NestListによる連続した要素はより深い:
NestList[f, x, 5]Depth /@ %考えられる問題 (3)
DepthはArrayDepthが返すより1大きい深さを返す:
{Depth[1], ArrayDepth[1]}{Depth[{1, 2, 3}], ArrayDepth[{1, 2, 3}]}Depthは連想を単一のレベルとして数える:
Depth[<|a -> x, b -> y|>]Depth[{a -> x, b -> y}]複合頭部が存在する場合はDepthとPositionの関係が壊れる可能性がある:
Depth[f[][]] == 1 + Max[Length /@ Position[f[][], _]]Depth[f[][], Heads -> True] == 1 + Max[Length /@ Position[f[][], _]]関連項目
関連するガイド
-
▪
- 式の構造 ▪
- メモリの計測と最適化 ▪
- 式
履歴
1988 で導入 (1.0) | 2003 で更新 (5.0) ▪ 2010 (8.0) ▪ 2018 (11.3)
テキスト
Wolfram Research (1988), Depth, Wolfram言語関数, https://reference.wolfram.com/language/ref/Depth.html (2018年に更新).
CMS
Wolfram Language. 1988. "Depth." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2018. https://reference.wolfram.com/language/ref/Depth.html.
APA
Wolfram Language. (1988). Depth. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Depth.html
BibTeX
@misc{reference.wolfram_2026_depth, author="Wolfram Research", title="{Depth}", year="2018", howpublished="\url{https://reference.wolfram.com/language/ref/Depth.html}", note=[Accessed: 04-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_depth, organization={Wolfram Research}, title={Depth}, year={2018}, url={https://reference.wolfram.com/language/ref/Depth.html}, note=[Accessed: 04-September-2026]}