上值定义的问题“too deep for an assigned rule to be found.“
mathematica吧
全部回复
仅看楼主
level 9
0577216 楼主
FormTimes[facs___] := 0 /; MemberQ[{facs}, 0]
FormTimes[facs___] := FormTimes @@ DeleteCases[{facs}, 1]
FormTimes /: D[FormTimes[facs___], any__] :=
Plus @@ FormTimes @@@ (MapAt[D[
#, any] &, facs, #
] & /@ Range[Length[facs]])
其中第三条语句运行后出现
TagSetDelayed::tagpos : "\"Tag FormTimes in ‘™˜SubscriptBox[™∂, \
™any__]™Hold[FormTimes[facs___]] is too deep for an assigned rule to be \
found. \""
从表面看,FormTimes并没有隐藏得很深,但它莫名其妙被Hold住了,结果就。。。
但是Attributes[D]给出{Protected, ReadProtected},并没有Hold族属性啊
怎么办怎么办~~~~[撞墙至死][撞墙至死][撞墙至死][撞墙至死]
喵呜~~~~~嗷嗷嗷嗷~~~~~~~~~[无聊][在笼子里][在笼子里][在笼子里][在笼子里]
2013年05月26日 06点05分 1
level 9
0577216 楼主
啊~~~问题好像在第二条语句上~~~~~[晕厥][晕厥][晕厥][晕厥]
FormTimes[1, 2, 3]给出Hold[FormTimes[2, 3]]及
$IterationLimit::itlim : "Iteration limit of \!\(4096\) exceeded. \
\!\(\*ButtonBox[\"\", ButtonStyle->\"Link\", ButtonFrame->None, ButtonData\
:>\"paclet:ref/message/$IterationLimit/itlim\", ButtonNote -> \
\"$IterationLimit::itlim\"]\)"
可是为什么会这样~~~
2013年05月26日 06点05分 2
level 10
定义上值的模式只能有一层。在这里,模式 D[FormTimes[facs___], any__] 显然有两层.
2013年05月26日 06点05分 3
FormTimes在第一层啊~~~tutorial/AssociatingDefinitionsWithDifferentSymbols里的In[13]不就是这么用的吗?[揉脸][揉脸]
2013年05月26日 06点05分
回复 0577216 :[汗]
2013年05月26日 06点05分
回复 mm_酱 :肿么了[郁闷]
2013年05月26日 06点05分
回复 0577216 :我大概已经搞清楚为什么了。首先前两个定义会导致无限计算的风险。然后在第三个定义里由于D没有Hold属性,FormTimes[facs___]被计算了(这里具体的计算细节我还得仔细看看),由于前面两个定义,这会导致无限计算,无限计算的结果是被Hold住,而这又会导致上值定义的层次过深。
2013年05月26日 07点05分
level 9
0577216 楼主
把第二条改成FormTimes[facs___] /; MemberQ[{facs}, 1] := FormTimes @@ DeleteCases[{facs}, 1]问题就消失了[汗][汗][汗]
2013年05月26日 07点05分 4
level 10
第三个定义加个Unevaluated能使定义成功,但是不是你想要的?
FormTimes /: D[Unevaluated@FormTimes[facs___], any__] := Plus @@ FormTimes @@@ (MapAt[D[
#, any] &, facs, #
] & /@ Range[Length[facs]]);
2013年05月26日 07点05分 5
咦?加Unevaluated不就“too deep”了吗?怎么还能成功?[揉脸][揉脸]
2013年05月26日 07点05分
不过Unevaluated确实大赞啊~~~
2013年05月26日 07点05分
回复 0577216 :Unevaluated在限制了计算之后会自动消失。
2013年05月26日 07点05分
一个模式匹配的问题,这里用HoldPattern也行的
2013年05月26日 08点05分
1