37,977 reputation
3102193
bio website mathprogramming-intro.org
location St. Petersburg, Russia
age 36
visits member for 1 year, 4 months
seen 5 hours ago
stats profile views 3,082

Ok, an obligatory note: opinions expressed here are mine and not those of my employer.


15h
comment At what point should MLSetMessageHandler() be called?
Actually, the most economical way would be to define the macro as #define MLSetMessageHandler(link, handler) MLSetMessageHandler(link, (MLMessageHandlerObject) msghandler), and then you don't need to set it yourself - as long as this #define is included when you compile your files, it will automatically replace the call to MLSetMessageHandler that is present in generated MLMain(). This should answer both of your concerns at the same time.
1d
revised Can one identify the design patterns of Mathematica?
Added a link, fixed some link names
1d
answered Can one identify the design patterns of Mathematica?
1d
comment At what point should MLSetMessageHandler() be called?
You could also use a hack and define a MLSetMessageHandler macro using the C preprocessor, to effectively disable the code generated by mprep. Something like #define MLSetMessageHandler(x,y) and then #define MLSetMessageHandler(x,y,flag) MLSetMessageHandler(x,y) . The point is that you will use the second version with a (spurios) flag - say 0, and since the macro expansion is not recursive, the first version won't be used on the expanded result.
1d
comment At what point should MLSetMessageHandler() be called?
Why can't you have a custom function to set your message handler and call it as a part of installing your function, after MlMain does this?
1d
awarded  Enlightened
1d
awarded  Nice Answer
1d
comment Recursion depth exceeded
@J.M. In this case, conversion to iterative version is made trivial via memoization, see my answer.
1d
answered Recursion depth exceeded
1d
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).
1d
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 :-).
1d
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.
1d
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.
2d
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.