« first day (1153 days earlier)      last day (3290 days later) » 

8:06 AM
@babou You mean in the sense that it could fit the reference question? If so, sure, just post an answer there? Or did you want feedback whether I agree?
@DavidRicherby Parameterized complecity resp. kernelization methods kind of go into that direction, don't they? (cc @babou)
For the funs:
34
Q: I want to expose my 5-year-old daughter to boys and girls toys equally, but she just turned her nose up at Star Wars. What do I do?

hawkeyeMy aspiration is to give my daughter experiences of boys and girls toys. My background is that I work as a software engineer and had experiences of LEGO, Meccano, programming and sci-fi movies. I don't want to hold that stuff back from my daughter. She has decided at an early age (2) that she i...

Some of the comments are golden. :D
 
 
2 hours later…
9:59 AM
@Raphael Yes, I was asking whether you consider it worth it as reference answer. Actually, I am still working on this question, to get some more general techniques out of it. So I will do more. But I thought it could fit a new reference question: How do I build a CF grammar for xxx? ... The same could exist also for constructing a PDA. Would it be OK to have a new reference question?
BTW, it is also an interesting example of Curry-Howard isomorphism (to be checked for details with logic experts). The point is that, except in a very small number of cases (I know only two, about FA) the results we use in proving that a language is CF are all constructive. Hence, from (nearly) any proof that a language is CF or regular, we can mechanically extract the grammar or the automaton that will recognize the language.
I wonder whether there is an implemented system that does that. It would be a good educational tool, both for understanding that there is little magic in formal languages and automata, for making general properties (closure) more interesting than direct construction with matchsticks, and also for getting hands-on experience with Curry-Howard. And also to show how pervasive CS concepts can be, and that both a grammar or an automaton may be considered programs.
Possibly an undergraduate project, but it has to be done well.
Nevertheless, Curry-Howard will work well, but may give unpalatable results. There may be simplification techniques, but direct development such as proposed in the answer I submitted to you are still interesting as they may give nicer results. These are all the thoughts that came to me while seeing the same questions repeated over and over (some of them of very limited educational interest imho). This might be more useful than writing yet another textbook.
 
@babou I don't think one specific example qualifies as reference.
@babou I agree. I have more than half a mind to write a (free) book collecting all mechanic and semi-mechanic constructions/proofs you meet in undergrad TCS. It's the time I lack.
@babou I'll leave that tab open for later reading.
Essentially, you want to match closure properties to automata/grammar constructions?
 
10:28 AM
@Raphael Well, that is true, but my guess is that it is not the only question about constructing a CF grammar. So there may be more to collect from. And asking it as a reference question may attract more interesting answers. Maybe I (or someone else) could just ask it as a question, providing also one or two answers. The only problem is that such a question, intended as a reference, is by nature very open, too open, so that it is usually quickly closed by the site police.
 
@babou What is wrong with the current question?
I think answers discussing how to come up with CF grammars fit there perfectly.
(And then point to the L=L(G) question, if creative steps were involved.)
I would appreciate such. I recall that Rick Decker had a similar answer with some "gadgets". I'd rather close all these "help me build a grammar" questions (without own attempts) as duplicate of a comprehensive reference question.
 
@Raphael If you have that feeling. That is fine with me. We can always do that. And possibly split in two questions later, if there are many answers that are more centered on actually exhibiting the grammar (without mechanical assistance).
 
@babou Let's do that, then. I think "How to show L is CF?" in one place, and "How to come up with a CFG for L?" in another would be redundant, but maybe I'm wrong.
I was thinking of this one:
1
Q: Converting to CFG from a CFL?

setu basakI am trying to learn CFG. Now to make a CFG from a CFL it is really difficult for me. Is there any simple rule or steps so that I can easily find a CFG for a CFL. I am trying to solve one problem for generating a CFG. The Problem statement is to find a CFG that generates the following CFL: $$\{...

So if you start writing something up, you may want to incorporate the stuff from there. (Don't hesitate to use Rick's material as well, he as had plenty of time to do so himself.)
 
10:46 AM
@Raphael Thanks for the reminder. I wanted to do it, but could not recall where it was.
 
@babou I've read your answer now. It's nice, for the given question, but I think it's too specific to be useful as reference. Well, the numbered list is general enough, but maybe a bit too "fuzzy". The general technique you are proposing is, in essence: since all (?) the proofs of closure properties are constructive, work along closure properties!
 
@Raphael Well. My feeling is that we should not write books, but symbolic computation systems decorated with educational material. Or possibly have crosslinks between the symbolic system, and an hypertext document explaining the corresponding math. It may actually be a hard task, as one may want smart algorithmics hidden in the system (or both smart and trivial, since students learn the trivial stuff first). But my idea is also how to understand the logic of these proofs.
In that sense, the Curry-Howard aspect should be important.
 
10:59 AM
As such, it should certainly be an answer on the reference question (currently we have "use nesting structure" (similar to what you plan, but not near as comprehensive) and Chomsky-Schützenberger, which can be seen as "ultimate" but harder to use version of your concept.)
@babou I don't know what you mean by "Curry-Howard aspect", sorry. Was that in your discussion with David Richerby above?
@babou My goal would be a book going down to pseudocode for the algorithms, in a building-blocks fashion. Companion implementations might be nice, but also every (at least average) student should be able to implement the algorithm themselves as an exercise.
I don't think, as far as undergrad education goes, much is earned by giving students a full system.
Once you have mastered the material, you want something like that, of course: "here's my language representation derived with smarts; now give me a grammar/automaton/parser". And we have tools like that (mostly from grammars to parsers).
But students should go the long road, because usually their representation will be wrong. And only in doing the mechanical stuff themselves can they see/feel where they went wrong, and iterate.
 
11:36 AM
@Raphael No relation to my discussion with David Richerby.
The idea is that a system should be organized around a proof assistant for doing proofs about formal automata and languages. Of course, this entails some kind of formalization of a logic for such proof - most likely an incomplete one (according to Gödel). I never used Coq, but I suspect it should be usable for the purpose.
The proof would then be interpreted as steps for constructing the grammar or the automaton for whatever language has been proved to belong to some family. Trios and AFLs would become very natural concepts to use, and closure properties in general. Extracting mechanically the CF grammar or PDA from a proof of CF-ness of the language is just a fairly simple instance of the Curry-Howard isomorphism paradigm. One that is easy to understand intuitively.
This probably extends to many much more sophisticated aspects of computability and complexity. There is a possibility that such a system already exists. How this is then embedded in a proper educational framework is another issue. But I think it is what things should look like in the end.
 
@babou There are multiple concerns. 1) You'll only ever be able to automate the "boring" parts (fully). We want to teach exactly the other parts. Maybe such a system can help teaching the intersting parts, if it's usable enough.
2) Such systems tend to be highly specialised and hard to use. I, too, have never used Coq but I have used Isabelle/HOL. Learning how to use this for proving something non-trivial (and still elementary) took upwards of three months. That's way too much for a tool in teaching.
3) If not useful for teaching (of maybe even if), such a tool will only be built if a) it's an interesting research project in itself (doubtful here, but maybe I lack vision) or b) it promises applications for people with money (don't see that either).
 
11:56 AM
@Raphael I am aware of your objections. I still think it might be worth spending some time investigating it. Possibly just trying to develop a bit the (possibly elementary) logic for conducting many of the proofs we see here ... just to see how much is required. In a way, that is what is done in the reference questions, but only very informally.
I feel that the paradigm should be usable more simply, if we manage the ergonomic aspects, for simpler contexts than what is aimed at in Coq or Isabelle. Much of the complexity of a system comes from the complexity of the problem space it addresses. Maybe that would only deal with the boring parts ... but the boring parts are precisely what is initially taught, and comes to us as questions.
 
12:57 PM
@babou Hmm, not quite. The boring steps -- transform A to B, simulate set operation x by construction y, ... -- are given in lecture or textbooks. The interesting part is what makes questions end up on Computer Science, namely finding the right sequence of operations. (In particular, this is not computable in general.)
If you can not only implement the "boring" parts in an easy-to-use (and -combine) fashion but also assist in finding this sequence, then you may get somewhere. (Note that that's also what Coq et al. do; they can find simple proofs on their own by enumeration and heuristics.)
That said, a presentation along the lines of "use the toolbox, all you need is such a sequence!" is probably missing from many books/lectures; we can fill a gap there. (I tried to do the same with that algorithm analysis question.)
 
1:43 PM
@Raphael Finding the right sequence is doint the proof (whether it is CF or Regular). My point is precisely that providing the grammar or the automaton is often not very interesting. But is is often the question being asked. I had only prrof checking in mind, but assisting the proof is another game.
I am always reminded of one thing that impressed me from someone you seem to like, Philippe Flajolet, and his group. He has this small language, such that if you could state your algorithm within the language (obviously not Turing complete), then he would give you the average complexity for free. It is a different context, but always with this idea of compiling sone description into a related piece of information.
 
@babou Yea, Flajolet was all about transfer theorems. Definitely nice, but usually limited.
@babou You mistake me. Finding the grammar is interesting, because it contains non-trivial, creative steps. In the question you linked at the beginning of this conversation, the tool you use is finding a suitable representation so that the grammar follows by construction. So the sequence is not only the proof, it's also essential for getting the grammar. (There are probably easier proofs, too, if you compare with the "unfolded" version of the sequence.)
 
2:23 PM
@Raphael Actually, in this example, proving it is context-free is a bit simpler than getting to the grammar. However, the grammar I can produce is probably nicer that what I would get by brute force extraction from a simpler CF-ness proof (I think). Not all proofs give the same result.
And one could also consider computing attributes on proof trees that might say something about the appropriateness for extracting a (nice) grammar. I once made a nice example of something similar about bootstrapping compilers, but the details escape me now. The idea was to extract the bootstrap process from a (mechanically produced) proof that it was possible.
 
@babou True. I for one appreciate the conceptual neatness of "construction" proofs; I regularly advocate them. (Mostly for regular languages where you can transform in all directions more freely.)
@babou I think that's a tautology; you can always get a solution/certificate from a constructive proof. (Can't you?) Quantifying "niceness" sounds nice (be-dum-dum-tzz) but daunting.
 
 
3 hours later…
5:26 PM
4
Q: Algorithm to generate two diffuse, deranged permutations of a multiset at random

hftfBackground $\newcommand\ms[1]{\mathsf #1}\def\msD{\ms D}\def\msS{\ms S}\def\mfS{\mathfrak S}\newcommand\mfm[1]{#1}\def\po{\color{#f63}{\mfm{1}}}\def\pc{\color{#6c0}{\mfm{c}}}\def\pt{\color{#08d}{\mfm{2}}}\def\pth{\color{#6c0}{\mfm{3}}}\def\pf{4}\def\pv{\color{#999}5}\def\gr{\color{#ccc}}\let\ss\...

 
5:38 PM
Oh, a pretty one! Colors!
 
5:57 PM
And a great question, too!
 
vzn
+1 (herd/ peer pressure) but feel it is "all over the place" (as the expr goes in english) & not too cleanly stated/ presented....
 
 
1 hour later…
7:00 PM
Hi @Raphael and @vzn
I didn't think this chat was very active (I'm used to the activity of the tex.sx chat) but since @vzn suggested, I decided to join here
Should I respond to all the concerns from your comments in my own comments? Or should I work to incorporate those into the question?
 
7:18 PM
Hi @hftf!
@hftf The latter, as a general rule on SE. That is, if you consider the questions valid and think your answers improve the question. Refutations or answers of the form "you did not read correctly" don't have to go into the question.
If you anticipate a longer conversation, you can open a new chatroom, but you are welcome to use this one here, too.
 
@Raphael Okay, I will get to work on that, but it might take a bit of time. Clearly I haven't thought too hard about the details of the question, especially other kinds of multisets. Yes, one can easily come up with a multiset that isn't feasible.
 
8:01 PM
@hftf No worries, few people have time to follow many edits in a short time. Better to take your time, and then push one meaningful edit.
 
@Raphael Could you please explain your first comment about the sentinel?
 
vzn
@hftf hi. think there is some real question here but it seems mixed up. think it would be helpful to say why you are "rejecting rejection" so to speak.
the algorithms in many math systems eg sage are generally some of the best (known) around.
 
vzn
8:21 PM
the general question is something like "how to generate random values from a distribution"... in statistics, algorithms that do this with rejection are somewhat standard. eg even saw one yrs ago (iirc) merely for gaussian distributions.
does anyone follow DWs construction? had a similar idea but cant quite nail it down...
 
8:39 PM
@hftf You current definition would say that (1, 2, 2, 2, 2) is "diffuse".
I thought that what you would want is (2,2,1,1,2,2) which can be implemented as I suggested: add leading and trailing 1 and consider the gaps to those, too.
That is, (1)(1,2,2,2,2)(1) is clearly bad, whereas (1)(2,2,1,2,2)(1) is clearly optimal.
These additional, virtual elements (used only for defining diffuseness) I called "sentinels"; use whichever word you like.
 
 
1 hour later…
9:46 PM
Hi @vzn, I don't think the specific Sage approach that I found scales well. For example, to represent a single permutation requires n lg c bits. So just enumerating all derangements requires multinomial(n; n_1, …, n_c) n lg c bits ~ O(n!) bits.
 
vzn
9:59 PM
@hftf my guess, the sage algorithm came from a paper somewhere. which is a good place to start. its probably documented. right?
 
Hi @vzn, in my question I link directly to the source code of the function
 
vzn
dont quite follow the theory yet but it appears derangements are related to permutations and one would expect exponential-like runtime algorithms associated with them.
> [Martinez08]
> http://www.siam.org/proceedings/analco/2008/anl08_022martinezc.pdf
 
@vzn Yes, I believe that's correct. In fact there is a non-randomized O(n) algorithm for generating a random derangement of a set due to Martinez based on Fisher-Yates/Sattolo algorithms.
 
vzn
(rats that link is 404)
do you have some application in mind?
3
Q: Generating a random derangement

MythioI'm having a problem about derangements that I'm trying to solve. Given a set $S = \{1,\ldots,n\}$, I want to generate a random derangement. I've considered generating a permutation and checking whether or not this is a derangement, but since the ratio of derangements to permutations is quite lo...

> The algorithm that joriki linked to is described in more detail in Martínez, Conrado, Alois Panholzer, and Helmut Prodinger. "Generating Random Derangements." ANALCO. 2008. epubs.siam.org/doi/pdf/10.1137/1.9781611972986.7
 
@vzn Here I believe is the same paper, non-404 version: epubs.siam.org/doi/pdf/10.1137/1.9781611972986.7
 
vzn
10:06 PM
at this pt, this is nearly a research question to try to outdo a published algorithm.
 
@vzn You want to know the specific application of my question I have in mind?
 
vzn
@hftf yes
acc to the Mathematics answer, there is a non-rejection based algorithm (given in the question). not sure if it is the same one implemented in Sage. dont see why not.
 
@vzn Yes that algorithm works for sets of unique elements, not multisets. The documentation of the function mentions this.
 
vzn
a multiset is a set with multiple occurrences of same element? aka "bag"? ok, so yeah there may be a way to optimize the algorithm for multisets.
think this question could be much better constructed. did you have that ref already, or just notice it as we looked here in chat?
 
@vzn, the Martinez paper?
 
vzn
10:11 PM
@hftf yes
 
@vzn, I agree that the question can be better constructed as well. I tried to give enough detail to explain why the algorithms near the bottom wouldn't be "efficient".
 
vzn
suggest this is more a Theoretical Computer Science question. not saying they will upvote it. its a tough crowd over there. think the way to go is to just cite the martinez paper, say its for sets, and then ask if there is a better algorithm for multisets.
 
@vzn, I had seen the paper in doing research for a few weeks before posting the question.
 
vzn
suggest even attempting to contact martinez et al.
so do you have an application?
 
@vzn, an algorithm to generate a derangement of a multiset would fulfill one of the two criteria.
@vzn, yes I have been typing that up as you have asked me other questions faster :)
 
vzn
10:13 PM
are you at a university? undergrad/ grad?
 
@vzn, I am an undergrad, CS major
 
vzn
so answer faster :p
(quick/ initial/ early impression) this seems at least graduate level research to me.
 
@vzn, My application: There is a competitive activity called quizbowl in which players use a buzzer to score points by answering questions on academic topics. A match is played on a packet of 20 tossup questions and 20 bonus questions. The distribution of a packet refers to how many questions it contains per topic. We can represent the distribution by a multiset.
The two constraints (diffuse, deranged) come from the aesthetic requirements in producing a packet of questions.
 
vzn
so you want to write code that finds optimized aesthetic orderings?
 
@vzn, In general the author of a packet picks a good enough permutation and then it is published, so in that sense there is no real need for a fast algorithm. But for a more dynamic application (generating a random packet from a database of millions of questions) there is more of a need to do so.
@vzn, I also have been thinking it is a graduate level research question.
 
vzn
10:19 PM
if you are trying to optimize something out of many possibilities, this is sounding more like a genetic algorithm problem to me.
another idea might be to try to exclude some of the analysis done so far, write up the "requirements" of the computational problem wrt the application (which are not so simple) & post that to Computer Science & see what comes up.
 
The smartest solution would probably be to run some program for a while to precompute a few thousand pairs of permutations (P, Q). Then the dynamic application can just pick one pair.
while practical it didn't seem very elegant ;)
 
vzn
lol
did you understand DWs answer?
> This might be shooting a flea with a cannon...
(what a coincidence, the question might have started out that way too...)
another strategy, if you can write this all up as a challenge, the Programming Puzzles & Code Golf site can be sometimes useful for (collective intelligence vs) algorithmic challenges.
 
@vzn I understood some of the parts of DW's answer but not how to tie it together in an actual program
 
vzn
have worked with SAT quite a bit & still couldnt quite follow his idea. think DW used a little too much shorthand.
 
@vzn, my one experience with the code golf site doesn't lend me to believe that they'd give a crap :)
 
vzn
10:26 PM
lol that can happen too :(
 
My impression of code golf is they like "cute" and "lulz" kind of questions
My HS CS teacher also recommended a genetic algorithm, yet I have no experience with them, but since you also suggested it I will try that out
 
vzn
re codegolf, cant disagree. there is some more serious stuff scattered in the low-level mishmash. eg a sophisticated GA challenge etc.
GAs are not actually that hard to implement and can be done in a few hundred lines.
or even few dozen sometimes.
 
While my requirement of "uniformly distributed" isn't actually too strict (this answers @Raphael's comment's question), my worry with GA is that it will be far from such.
 
vzn
personally would like to see more of a writeup of the basic reqs starting from the quizbowl formulation/ problem statement
what year are you in the university? US?
 
@vzn, I put together a short write up here if it helps ophir.li/quizbowl/ocpocmaq/report.pdf
@vzn, US, technically a junior
 
vzn
10:32 PM
@hftf ok nice
 
@vzn, let me know if this write up helps at all
@vzn, it seems not so for my professor ;) (direct quote: "Ah, I need to read 2 pages!")
 
vzn
it does. the feng shui concept is quite like a GA fitness fn.
unf the last paragraph has a huge leap. it refers to diffuse/ derangements without any defn or analysis/ thought process etc.
it appears the fitness fn would measure diffusion of derangements.
it really looks like more a problem of applying a fitness fn to permutations of multisets.
 
@vzn, sorry I am not too keen on GA terminology, but would s(P) be considered a "fitness function" for the diffuse constraint?
 
vzn
ok, it has defns in that paragraph, but still seems it jumps.
a fitness fn is quite simple, it just gives a numerical score to a "candidate" that is roughly proportional to its "quality"
a "very simple" GA just examines random candidates, scores them, & picks best candidate.
 
What about the mutation procedure? swap around two positions at random?
I've got to head out briefly
 
vzn
10:42 PM
you dont introduce/ explain what the numbers are in the multisets at the end of the paper.
you seem to name 8 "topics".
> Refer to the quizbowl wiki entry on “packet feng shui” for a list of such constraints
plz cite it!
packet feng shui / quizbowl wiki
so you derive derangements and diffusion from these constraints/ aesthetic criteria.
> The search is currently underway for an algorithm that can create pseudo-random question ordering while following the rules of packet feng shui.
 
@vzn, that's right
 
vzn
> Many music players thus have a non-random shuffle algorithm; see “How to shuffle songs?”
& what is that citing?
oh!
 
@vzn, can you click on the link?
 
vzn
ok there are hyperlinks in that pdf. they do not fmt any differently for me. do they for you? ie completely hidden.
 
@vzn, My apologies, they are indeed outlined for me. I'll see if i can fix it at some point. Sorry about the quality of the paper, it was very hastily written and mostly for me to organize my own thinking.
A few shower thoughts: suppose I use a GA. Then how can I test if the distribution is uniform? i.e. suppose there are 1 trillion possibilities, if I run the algorithm 10 trillion times and each possibility occurs about 10 times then it's probably uniform. But it's possible to prove mathematically that e.g. Fisher–Yates produces a uniformly distributed random permutation
 
vzn
11:00 PM
its a sort of strange question. optimization is all about "nonuniformity".
maybe what you are saying is if an optimal solution exists, one wants the algorithm to potentially find it, but also not find the "same-looking" optimal solutions.
but in a sense the fitness function hones/ produces "same-looking" solutions wrt its criteria.
read some basic theory see what you think
In the field of artificial intelligence, a genetic algorithm (GA) is a search heuristic that mimics the process of natural selection. This heuristic (also sometimes called a metaheuristic) is routinely used to generate useful solutions to optimization and search problems. Genetic algorithms belong to the larger class of evolutionary algorithms (EA), which generate solutions to optimization problems using techniques inspired by natural evolution, such as inheritance, mutation, selection, and crossover. Genetic algorithms find application in bioinformatics, phylogenetics, computational scienc...
 
But it's possible there exists 100 "same looking" optimal solutions but the algorithm only ends up finding a few of them?
 
vzn
just opened your writeup in pdf viewer & can see the links. something about chrome pdf viewer is losing them.
 
Sorry, I just haven't optimized my pdf yet ;) ;)
 
vzn
@hftf sounds sort of like wanting a "diversity" of solutions.
there is some connection of this to "local minima" in search problems.
GAs may or may not have good performance wrt "local minima" but that can usually be tuned wrt fitness fn, combination ("crossover") / randomizing ("mutation") fns, etc
 
Another shower thought: Is there a kind of tradeoff between effort in coming up with an "elegant" algorithm and how much work (time complexity? bits of entropy?) an inelegant algorithm requires?
i.e. it should require only lg( number of permutations ) bits of entropy to pick a permutation at random.
 
vzn
11:10 PM
obviously try the inelegant ("easy") algorithms 1st & see how far they get you :)
 
Maybe I'm not making any sense
brb
 
vzn
@hftf have done some GAs involving permutations. they are indeed a bit trickier to deal with wrt GAs.
ok, so derangements are defined formally, but what about "diffusion"? there seems to be no formal defn.
 
11:31 PM
@vzn, right
@vzn, In the analogous pinwheel scheduling problem (which is mentioned in the diffuse section), the idea is that item i must appear at least once in every subsequence of length n_i.
@vzn, but if the density (∑ n_i/n) is 1 and any n/n_i is not an integer, then such a schedule is not feasible.
@vzn, for the multiset D of size 20 from the question, there is an item with multiplicity 3. Since 20/3 isn't an integer and the density is 1, it is clear there is no ("feasible") schedule P, i.e. s(P) = 0.
 

« first day (1153 days earlier)      last day (3290 days later) »