Reputation
76,578
Next tag badge:
283/100 score
18/20 answers
Badges
8 227 320
Newest
 Nice Answer
Impact
~513k people reached

May
18
awarded  Nice Answer
May
18
comment Recursion depth exceeded
@J.M. In this case, conversion to iterative version is made trivial via memoization, see my answer.
May
18
answered Recursion depth exceeded
May
18
comment Recursion depth exceeded
@J.M. It also depends on how recursion is used. If one uses it for algorithm which is deeply recursive (high recursion depth), then the right way to do this in Mathematica is to perform some form of tail call optimization. Note that tail call - optimized functions in Mathematica require modifications of $IterationLimit rather than $RecursionLimit, and the former are safe (it is safe to set $IterationLimit to Infinity).
May
18
comment Recursion depth exceeded
@J.M. Sure, I just wanted to reinforce your comment. Re- Block - this is better, but IMO not enough. Actually, presence of absence of Block is irrelevant for my main argument. My point is that even with Block, setting $RecursionLimit = Infinity can easily overflow the stack which leads to a kernel crash. Happened to me more than once :-).
May
18
comment Recursion depth exceeded
@J.M. Actually, I think that setting $RecursionLimit = Infinity is never appropriate. I realize that I may be biased by my software development (rather than problem - solving) perspective, but it is all too easy to lose unsaved data by using this setting.
May
18
comment Can one identify the design patterns of Mathematica?
@rcollyer Yes, that's a good point. Somehow I didn't trust Internal`InheritedBlock for user-defined symbols (don't remember why - I think something went wrong a few times), so in such cases I use the technique which can be sketched as f[x_]:=With[{dv = DownValues[f]},Block[{f},DownValues[f]=dv; new-defs;code]]. But whatever the implementation, this version of technique is useful. Since I plan to have a separate post on self-blocking, which wasn't the main topic here, I did not provide all these details.
May
17
answered Applying a function with the HoldAll attribute inside NestList
May
16
comment Variable scoping problem when mapping over delayed replacement
Ok, I see. You want to generate rules programmatically. I think this is going to be tough no matter how you slice it. One thing that comes to mind: Cases[Hold[y, y^2, y^3], el_ :> RuleDelayed @@ Hold[{x_, y_}, {x, el}]], but this is not exactly simple.
May
16
comment Variable scoping problem when mapping over delayed replacement
This is a precedence problem. Use {x_, y_} :> ({x, #} & /@ {y, y^2, y^3}) instead.
May
15
comment Solving homogeneous Fredholm Equation of the second kind
@Mark Since your value of k is so large, I would still start with a stationary phase, and then perhaps use some iterative scheme. The scheme I linked to will be very hard to apply directly, given the highly oscillatory kernel of your equation - one would need to discretize on a very fine grid, and likely also use extended precision arithmetic - and even then I don't think this will be robust. To my mind, you first have to factor out the highly oscillatory part, which stationary phase should do for you - and then you could perhaps apply some finite difference scheme to the corrections.
May
15
awarded  Nice Answer
May
14
comment Solving homogeneous Fredholm Equation of the second kind
If k is large, one obvious thing that comes to mind is to use the saddle point approximation. The general equation does not look like the one you can solve exactly. Numerically, you can try some finite difference scheme, or may be something similar to what I described here.
May
14
comment How to compare power towers in Mathematica?
@VladimirReshetnikov Thanks, I do appreciate. I am not currently registered on math.stackexchange though, and converting it into math notation and making the post would take some time, which I may not have today or tomorrow. Besides, I left Maths and Physics behind, at least for the immediately foreseeable future :). I might add a post there at some later point, or feel free to self-answer there based on this post.
May
14
awarded  Nice Answer
May
14
comment Partitioning with varying partition size
@rcollyer Yes, I agree. I first saa this, IIRC, in the book of Roman Maeder long time ago, and I had the same feeling back then.
May
14
comment Partitioning with varying partition size
@rcollyer It may seem odd only because we are used to think of function definitions as if they are similar to other languages. Once we recall that they are rules, this is no more odd than the usual ones. I use this construct (_f:=...) from time to time too.
May
13
comment Can one identify the design patterns of Mathematica?
@DavidMcHarg Thanks! One thing I dislike about how this post ended up is that it is too long. If we make many posts like this here, this pages will become slow to load and hard to navigate. I think I will eventually move some part of this answer to the page on memoization I linked to here, and here will only keep the very minimal description and the links. But ultimately this has to be decided by the community, so I would appreciate comments on this from you and others.
May
13
revised Can one identify the design patterns of Mathematica?
Added a link to memoization of functions with options
May
13
answered Can one identify the design patterns of Mathematica?