@LeonidShifrin I went for a Hold-ReleaseHold solution
@LeonidShifrin You want another weird buggy observation? Check the ordering of definitions like f[]/;la:=1;f[]:=2;g[]:=2;g[]/;la:=1;h/;la:=1;h:=2;Information /@ {"f", "g", "h"};
f, and hs buggy/weird reordering lead me to use definitions like f[] /; True := 2
g's definitions were pasted wrongly, it's supposed to say g[Blank[]]
@image_doctor I think you should stop wasting your time improving user #4988's questions. He never bothers to format them correctly and he apparently refuses to Accept any answers either.
@Rojo Yep. I was aware of this particular one, was bitten by it a few times in the past. Somehow I think that this behavior is unlikely to change, though. Too bad.
@Mr.Wizard Just as an aside note, he and his pal (user #4972) share too many interests and behaviors (including the date "they" started using the site)
In order to get more fundamental in my understanding of probability I watched mathematicalmonk's lectures involving $\sigma$-algebras etc. - good. One of my main concerns was to better understand the basis for conditional probability: $P[A|B] = P[AB]/P[B]$. My question is simple
How do we know...
@Rojo both of your examples are quite surprising to me. Your test cases are so simple that it makes me wonder why we don't encounter problems all the time.
@Ajasja this is a nice idea. Which post did you have in mind? Visual C++ or MinGW-w64? The problem with the latter is that I have to advocate modifying the Mathematica source code, which is against the licence terms and may or may not be legally enforceable depending on the user's locale. On the other hand it is a common problem with a solution that is not that easy to express in the question and answer format, and I would like to contribute something to the blog.
Anyway, usually one would expect rules with Condition attached to be ordered first. But as Rojo's example shows, whether this is actually done seems to depend on the exact pattern.
Incidentally, this behavior is the same at least since version 5.2, despite the changes in rule ordering made in version 6.
@Oleksandr Are you aware of any method to change the background of an existing SparseArray, besides extracting and substituting its parameters with replacement rules?
@Mr.Wizard yes I mean beside extracting the parameters. Since SparseArrays are atomic one would obviously prefer not to have to decompose them into an expression and then rebuild from scratch.
Hmm. Okay. Apparently just adding or subtracting a constant from a SparseArray does change the background. I had never realised this before but it does seem to work.
Of course one then has the problem that the non-background entries are also changed.
@OleksandrR. Nice work. :-) I found something that could be described as a bug, but perhaps it may be useful in some way too. Give me a couple of minutes to put my thoughts together.
Consider:
In[1]:= SparseArray[{1}, 3, 5] // Normal
Out[1]= {1, 5, 5}
So the background is 5. This can be confirmed by looking at the InputForm.
@OleksandrR. Well that too, but actually what I've found is that it does not work if the background is Real rather than Integer. The fact that these do not behave the same suggests to me that it may in fact be a bug or corner case.
It works with Reals if the array was Real to start with. But you can't change an Integer array to a Real one using this process apparently. I assume the same goes for complex arrays.
I guess this must be the result of the fact that the internal array representation is not perfectly reproduced by the InputForm--there is also type information present.
@Oleksandr when you get back, as a diversion I'd love to know if you can figure out what Internal`DenseToSparse is doing, e.g. Internal`DenseToSparse @ RandomInteger[9, {5, 5}]
@Mr.Wizard I suppose it's conceivable that SAs are passed around and manipulated in their InputForm for as long as possible until their internal representation is really needed for some linear algebra library call &c. As such, perhaps "decomposing" doesn't necessarily decompose, which may explain why it's fast.
@OleksandrR. Actually I never had the time to really dig into the kernel code, up to now at least. It's a shame, I know :)
@OleksandrR., @Mr.Wizard I usually do what @OleksandrR. suggested, changing the background via its position in the FullForm of SparseArray. So, @Mr.Wizard, are you saying this is slower then breaking all into pieces and recombining back again?
@OleksandrR. I can confirm that decomposing takes much less memory than ToString[sa, InputForm] but the time it takes is also nontrival so I assume it's still doing some kind of unpacking.
@LeonidShifrin If I understand you that is actually what I described at the very beginning of the conversation. More specifically:
sa /. f_[a_, b_, _, x__] :> f[a, b, 99, x]
That's to change the background to 99.
I'm not certain how Oleksandr does it but I assumed something similar.
It takes several times as long as the creation of the original SparseArray (by a highly optimized method). It's not slow, but I nevertheless wonder if there is a more direct way.
(I also would like to know if either of you can figure out what Internal`DenseToSparse does simply as a matter of curiosity.)
@Mr.Wizard I normally use this "API", although it may be a little fragile.
@Mr.Wizard I would have to do what anyone else here does. I probably could find the code and look into it, but it would take a while. I think people like @ruebenko may know more about sparse array internals.
@Mr.Wizard takes the items along the first non-packed dimension of the argument and returns a list of them with a decreasing value prepended... at least as near as I can tell.
@Mr.Wizard since it doesn't seem to work properly with packed arrays I would guess that either it is some sort of prehistoric cruft or has a very specific use.
@OleksandrR. I must be going too... was summoned by @Mr.Wizard, apparently to no avail, since I wasn't able to add anything meaningful :) See you later!
@ssch A lot of the low-level boxes are undocumented, mostly because they're not of much use for the end user (i.e., you almost never have to use them directly).
@jVincent Yes, also to encourage users, but I didn't say they didn't have any use...
What I meant was that there is little to no need for a user to explicitly use a low level box (instead, generate with MakeBoxes) and those who do need to manipulate them, are probably knowledgable enough to do fine without the documentation
I did use GraphicsBox in a recent application to detect which cell had an image in it
I'm using 9. And I would normally think I fell into the catagory of those who does fine without documentation, but when dealing with templatebox and trying to do interesting frontend stuff, it's just a punishing experience.
@rm-rf And when I was just starting out with mathematica many years ago, I remember thinking that things, such as the Notations package, where the underlying logic is swept under the carpet actually makes thing much harder to deal with rather than simplifying them.
@jVincent I agree with that. My first days with mma were spent figuring it out alone (my first notebook was littered with For loops =D) and I never knew the existence of the Notations package... in some ways, I'm glad I didn't stumble upon it back then
@jVincent Could you perhaps try out this package I wrote? It provides a notebook that lets you type answers inside mma and copy it to SE markdown. It's still very much in development (and I haven't pushed anything in the past 10 days), so there definitely will be stuff that breaks (and stuff not supported yet).
If you're interested, I can give you installation directions
Bitbucket looks quite nice, but it looks like it's suffering from developer sickness like github. It would be nice if the vs systems web front ends figured out that a list of files in a project or a overview the revision history isn't a good "hello there" page for anything. I get the distinct feeling that they where all made by people who also consider all their code self documenting.
@jVincent Well, the lack of an overview page is my fault... I haven't gotten around to writing it yet, as stuff is still fluid right now, but I include a documentation inside that's more thorough
If you use git, just clone it and use the developer branch. It's essentially the same as the latest master... just added a usage message and made a notebook autoopen on load
I use bitbucket because it allows me to have private repos for free (and also collaborate with upto 5 users on private repos). As a student, I find this very useful and I don't have sufficiently worthy projects or even those of general interest to use a paid github plan
I'm currently using mercurial, but i'm sampling different systems. I'm in a group that's setting up some standard coding standards stuff, and we need to figure out a VS system that can easily be used by non-terminal people without having to put them through too much.
If you're on a mac, SourceTree.app is a pretty neat GUI app for both hg and git and it lets you connect to your github and bitbucket accounts to manage repos
Your package doesn't seem to work for me. Pressing markdown does nothing.
Ok, it works if I start a new notebook, but not in the examples. Also just running the documentation notebooks returns a lot of warnings. I suppose it's the difference between the workbench / frontend syntax for inclusions.
@jVincent Also, it copies directly to the clipboard... there's no confirmation gui or such (but warnings will be seen in the messages window). A visual guide that something is being done is in the works
Works fine now. So basically when testing this out it'll spam imgur with a lot of unused images? Are they cleaned up if unposted or how does that work.
No, I don't think they're cleaned up... SE has an unlimited account, but repeated requests from a single IP will make them investigate (the image uploader really is a hack... it's not a supported API and the hole in the system might be closed anytime if they pay attention to it)
However, the intention was that you write the answer to your satisfaction in mma (no uploading yet) and when all set, click upload once. Of course, there will be a second upload for revisions, etc., but I didn't expect people to press markdown repeatedly during the course of an answer,
Might be a good addition to have a click button to not refresh image updates and image urls, if someone adds to an answer or similar, so you don't have to do mental diffs with what you already posted.
It does give me an idea though... I can probably present a markdown preview with image upload unchecked by default and when you click finished, it uploads
Here's a quick question. In PHP there is a function called array_intersect which will pick out the elements common to two arrays. And there is a function array_diff that picks out the difference between the two arrays. I need these functions but I don't think there are any built into Mathematica/I can't find one?
@OleksandrR. I had in mind the installation of the MinGW-w64 compiler. (Also being the more difficult of the two choices:). Regarding the license: Are instructions on how to modify a file in violation of the license? (then all the KeyEventTranslations.tr posts are in trouble as well:)