64,277 reputation
6191283
bio website mathprogramming-intro.org
location St. Petersburg, Russia
age 38
visits member for 3 years, 2 months
seen 1 hour ago

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


2d
comment How do I get my equation to have the form $(x-a)^2 + (y-b)^2 + (z-c)^2-d = 0$?
@Kuba In general, it is. The first form relegates the default value to the function where you use the pattern, the second one specifies it explicitly.
Mar
27
comment DatePlus and DayPlus perform much worse than my user-defined-function
Have you seen some of the past questions / answers on this topic, involving Java, like this discussion for instance? I found that for date functions, and when you need to perform operations in a bulk, this approach works well.
Mar
27
comment Ordered associations
Apparently, this seems to not be mentioned in the docs explicitly, at least not on the main Association doc page. One can sort of figure this out by the fact that one can use Part with numerical indices on associations, but such fundamental property should be mentioned explicitly. I will file a suggestion report.
Mar
27
comment Ordered associations
Associations are ordered.
Mar
24
comment Why can I not replace a Dataset using a rule?
+1. Apparently, more complex solutions are always late.
Mar
24
comment How to find out where an error occurs?
I wrote a function, debug, which implements some of the suggestions given to you in comments. You can try using it, it has been one of the best debugging tools for me. I have also included it in RLink, so you can call Needs["RLink`"], and then call RLink`Developer`debug[your-code].
Mar
22
comment Dynamic arrays and lists with compile (Append, Linked lists etc.)
There is also this question
Mar
22
comment Match opening and closing parentheses?
Not to diminish this answer (I upvoted it), but just for future visitors who might not know it: this one will in general have a quadratic complexity in the size of the list with parentheses (which was the main reason I discarded this version myself, when answering).
Mar
21
comment How to convert a notebook to an association and back?
@rcollyer I'd agree with this. The problem of denormalization is more important either when this leads to excessive memory usage (less important issue), or when the database is writeable and the data may become corrupted if it exists in several places and goes out of sync. For read-only databases this is much less critical.
Mar
20
comment Dataset: sort rows in descending order of first column
dataset[SortBy[-#a &]].
Mar
20
comment Resource management in Mathematica
Somehow I missed this answer, and only discovered it by accident when looking at the old SO question on this, and seeing your more recent comment there. I've been using your CleanUp function from that old post extensively, but this seems a better alternative. Big +1.
Mar
19
comment Does Mathematica support out-of-core Associations?
It does not yet, but the support for it mau be added in the future (I am not speaking in any official capacity here, so this is just a guess).
Mar
19
comment Does Mathematica support an unordered set (e.g. hashset) data structure?
I think that for all practical purposes, you can consider Association to have O(1) complexity for all those operations. The point is that, implementing on the top-level any such structure would lead to constant factors far greater that log n for any sensible size of the set. You can also try System`Utilities`HashTable, described in e.g. this answer.
Mar
15
comment Why do functions defined with SetDelayed and Function behave differently in callbacks?
Some more information on strong types in Mathematica is in this discussion. An interesting discussion of differences between Mathematica and traditional languages (the high-level view on them) is inside this answer.
Mar
15
comment Why do functions defined with SetDelayed and Function behave differently in callbacks?
@ibeatty [2/2] ... pass f[1,2] as a function. There may be other similar constructs. I seem to remember some discussions about checks for functions, but I can't find them now. The other way would be to use an inert wrapper, e.g. Fun[...], and then place inside this wrapper the function. So then, your definition would look like g[Fun[ff_],y_]:=..., and the caller is responsible for wrapping a function in Fun when passing arguments to g. This, of course, does not prevent the caller from passing a wrong thing inside Fun, but at least it will probably rule out accidental mistakes.
Mar
15
comment Why do functions defined with SetDelayed and Function behave differently in callbacks?
@ibeatty [1/2] I am not aware of a fully robust way to differentiate between functions and other things in Mathematica. Partly this is because for the core evaluator, what we consider functions are no different from other expressions. In other languages, calling a function which evaluator knows nothing about, is an error. In Mathematica, it is not, and the call (expression) is simply returned back. One way I was using before was to use the pattern _Symbol | _Function, but this isn't robust either. For example, people may define SubValues of the form f[a_,b_][x_,y_]:=a+b+x+y, and then ...
Mar
14
comment Why do functions defined with SetDelayed and Function behave differently in callbacks?
@Pickett Re: retracted close vote - thanks. Re: answer - done.
Mar
14
comment Why do functions defined with SetDelayed and Function behave differently in callbacks?
Why the close votes? This is a legitimate question, even if the answer is rather simple.
Mar
14
comment Why do functions defined with SetDelayed and Function behave differently in callbacks?
Well, you get what you ordered. By using the pattern _Function in your first argument in g, you only allow the first argument to be a Function - otherwise the definitiion does not apply. Use g[ff_, y_]:=..., and you get what you want in both cases.
Mar
13
comment What is the “Origin” rule for in a Dataset?
I think, part of the problem here is that Dataset, being a new functionality, should have the most general design to match the generality of the language. Later, it will likely grow to have more specialized implementations / backends. The other approach would be to start with more narrow / specialized functionality, but then there is a higher risk of the initial design to be too narrow, and that would result in deprecation / backwards incompatibility - which is what the developers / designers are trying to avoid, given that Dataset is a core component.