Why is $\emptyset$ a subset of every set?

Question: Please read the details of this question before answering.
I am reading a book in which they say $\emptyset \subseteq S$ for any set $S$.  One justification they give for this is that if $\emptyset \not \subseteq S$, then there must be some element in $\emptyset$ that is not in $S$.  And we conclude that this cannot happen since $\emptyset$ has no elements.
.....But to prove $\emptyset \subseteq S$, we need to show every element of $\emptyset$ is in $S$.  But this is impossible too, since $\emptyset$ has no elements.
I don't get it.  By the way, I am familiar with vacuous truth (i.e., that $\mathrm{false} \implies \mathrm{true}$ is a true statement).  But if we reason the above statements in the way I did, then something isn't right.  The question is, what isn't right?
Comment: Every element of the empty set IS in any set
Comment: @Joao Why can't I say the following: We know $\emptyset \not \subseteq S$ because since $\emptyset$ has no elements, surely one of them is not in $S$.  This seems like the *same* statement as saying "empty set has no elements, so every element is in $S$".
Comment: Saying "every element of the empty set IS in any set" is vacuously true. It would be more precise to say that since $\emptyset$ has no elements it is vacuously true that $a \in \emptyset \implies a \in S$. Similarly, it is also vacuously true that $a \in \emptyset \implies a \notin S$.
Comment: $\emptyset$ has no elements, surely one of them is not in $S$. But it has no elements! All of its elements are in $S$.
Comment: @Joao I have no idea what you just said.
Comment: Yeah I don't really know what I'm saying either.
Answer: If $\varnothing$ has no elements, then we don't have to do any work to show that all of them are elements of $S$!
Anyways, you say that we need to show
$$ \forall x: x \in \varnothing \implies x \in E$$
but you say you can't do this, because $x \in \varnothing$ is identically false. Can you articulate why you think that's a valid argument?
Comment: @Math: Yes: you used the hypothesis "there is some element in $\varnothing$" to derive a contradiction. That should not be surprising, because you started with a false hypothesis. The implication $\forall x \in S: P(S) \implies \exists x\in S: P(S)$ is only valid when $S \neq \varnothing$.
Comment: Why can't I say the following: We know $\emptyset \not \subseteq S$ because since $\emptyset$ has no elements, surely one of them is not in $S$.  This seems like the *same* statement as saying "empty set has no elements, so every element is in $S$".
Comment: Every element of $\varnothing$ is indeed not an element of $S$. But that's not what $\varnothing \not\subseteq S$ means: $\varnothing \not\subseteq S$ means that there is an element of $\varnothing$ that is not in $S$. If $\varnothing$ had an element, we could conclude the latter from the former, but it doesn't, so we can't! We could conclude, however, that $\varnothing \subseteq \bar{S}$, where I've used $\bar{S}$ to mean the complement of $S$ (which is a proper class, not a set). In fact, $\varnothing = S \cap \bar{S}$, so it is the largest set that is a subclass of both!
Comment: If every element in $\emptyset$ is not in $S$, then there is some element in $\emptyset$ that is not in $S$ since every element of $\emptyset$ is not in $S$.  See what I did there?
Comment: The proof that  $U \subseteq E$ becomes easier if we make $U$ smaller: we have less work to do.  In the extreme situation when we make $U$ as small as possible (empty), we have no work at all to do in our proof.
Comment: Note that one popular variation of first-order logic does include $\forall x: P \implies \exists x: P$ as one of the rules of inference: this variation is *incapable* of reasoning correctly with an empty domain. Maybe this is the source of your confusion?
Comment: errata: two comments up should have $P(x)$, not $P(S)$
Comment: I think that is exactly what I was asserting was true.  But it was because I was being naive, rather than because I have seen that before.
Answer: The difference between $\emptyset \subseteq S$ and $\emptyset \nsubseteq S$ is that the former states that "every element in $\emptyset$ is also an element in $S$" while the latter states that "some element $\emptyset$ is not in $S$".
The second statement is clearly false, since if it were true then you should be able to exhibit some element from the empty set which is not in $S$. Of course, you can't do that since there are no elements in the empty set.
The first statement is true, since it were false, then you should be able to exhibit some element from the empty set which is not in $S$. Of course, you can't do that since there are no elements in the empty set.
So, I guess your confusion stems from wrongly appealing to 'vacuously true' without paying enough attention to the details. A correct application of vacuous implication would be to conclude that by the same argument it holds that $\emptyset \subseteq S^c$, where $S^c$ is the complement of $S$ relative to some universe. This is of course correct, and essentially the same argument.
I hope this helps.
Comment: It definitely does.  And it also goes along with what @Hurkyl was saying in the comments of his/her post.  Thanks to both of you paying attention to the details of my post, now I know that *I* wasn't paying enough attention to details in the first place. Thanks!
Comment: Well its negation is $\forall x(x \in \emptyset \land x \in S)$.  But is this statement equivalent to $\forall x(x \in \emptyset \implies x \in S)$?  If so, then the argument is done.  But I'm not sure.
Comment: I just want to add the following remark to this answer: For $\emptyset \subseteq S$, we need the following statement to be true: $\forall x(x \in \emptyset \implies x \in S)$.  But, for any $\, x$, the implication is *always* vacuously true because $x \not \in \emptyset$ to begin with.  Thus, the statement is true for all $x$, and so $\emptyset \subseteq S$.  On the other hand, in order for $\, \emptyset \not \subseteq S$, we need the following statement to be true: $\exists x(x \in \emptyset \implies x \not \in S)$.  ...Why is this statement false?  Because its negation...
Comment: Here is the correct explanation of my remark after I've done some thinking about it.  As I said above, $\, \emptyset \subseteq S$ is always true because the statement $\forall x(x \in \emptyset \implies x \in S)$ is true (vacuously).  But the statement $\, \emptyset \not \subseteq S$ is true precisely when $\exists x(x \in \emptyset \land x \not \in S)$ is true.  But this statement is $\,$*never*$\,$ true because for an "and" statement to be true, both pieces have to be true, and $x \in \emptyset$ is **always** false.  Thus, $\, \emptyset \not \subseteq S$ is always false.
Answer: The rules of logic say a false statement implies anything. Hence $x\in \emptyset\implies x\in E$ for any set $E$.
Comment: OP was asking what is wrong with his argument for what seems to use the same logic rule, but yields something incorrect. OP said to be aware of vacuous proofs, and not to have any issues with that. The current answer simply restates the logical rule of vacuous implication. It does not address the question OP posed.
Comment: It answers. The fact is: you are in fact not familiar with what you said you were.
Comment: @IttayWeiss Thank you for not making me feel crazy.
Comment: Did you even read my question?
Comment: I did. Still, $P\implies Q \iff \sim P\vee Q$.
Comment: I'm not happy with your answer.  It doesn't answer my question.  Sorry.
Comment: @AloizioMacedo So the solution is to just restate what I am not familiar with? Rather than delve into what I don't understand?
Comment: @MathIsHardNoItsNot You said you are familiar with vacuous truth. That's all that's at play here.
Comment: That's a complete different question. Your question is: "Why is ∅ a subset of every set?" and "But if we reason the above statements in the way I did, then something isn't right. The question is, what isn't right?". He answered both of them. The question you are posing here is a complete different one: "Can you help me understand why (false implies true) is true?"


What is the difference between $\det(zI - A)$ and $\det(A - zI)$?

Question: When computing the characteristic polynomial of matrix $A$, is it the case that $$\det(zI - A) = \det(A - zI)$$ and that one should choose the construction that is best on a case-by-case basis? If so, is one of these preferred over the other? If they are not equal, which one represents the characteristic polynomial of matrix $A$?
Comment: $$\operatorname{det}(zI-A)=\operatorname{det}(-(A-zI))=(-1)^n\operatorname{det}(A-zI)$$where $A$ and $I$ are matrices of dimension $n\times n$. By convention, I generally define the monic characteristic polynomial as the characteristic polynomial, but it doesn't matter.
Comment: Since $A-zI = -(zI-A)$, if $A$ is $n\times n$ then $\det(zI-A) = (-1)^n\det(A-zI)$. So they are equal if and only if $n$ is even. Since the characteristic polynomial is used mainly in order to finds its roots, both have the same roots so the difference is immaterial. Generally, when doing things by hand, $A-zI$ involves fewer modifications to $A$, so a lower chance of transcription errors. $\det(zI-A)$ is always monic (which some people want their characteristic polynomials to be), while $\det(A-zI)$ has leading coefficient $(-1)^n$.
Comment: Thank you both. That makes perfect sense.
Answer: Answering my own question (with reference to the great comments that were left):
It is the case that $\det(zI - A)$ is not necessarily equal to $\det(A - zI)$. Specifically, one can obtain matrix $A - zI$ from matrix $zI - A$ by pulling a factor of $-1$ out of each row of matrix $zI - A$. Therefore, $\det(zI - A) = (-1)^n \det (A - zI)$. As a result, when $n$ is odd, $\det(zI - A) \neq \det(A - zI)$.
To determine which form correctly represents the characteristic polynomial of $A$, consider that $\det(A - zI) = (\lambda_1 - z)\cdots(\lambda_n - z)$ where $\lambda_1, \dots, \lambda_n$ are the eigenvalues of $A$, repeated per their algebraic multiplicities. Hence, you can see that the leading term of $\det(A - zI)$ will be $(-1)^n z^n$, which will be negative if $n$ is odd. So, the form $\det(A - zI)$ will not produce a monic polynomial when $n$ is odd, and therefore, $\det(A - zI)$ should not be used to represent the characteristic polynomial. By contrast, $\det(zI - A) = (z - \lambda_1) \cdots (z - \lambda_n)$ so that the leading term is $z^n$, and the polynomial produced from $\det(zI - A)$ is monic, and therefore $\det(zI - a)$ correctly represents the characteristic polynomial of $A$.
All that said, the most common use of the characteristic polynomial is to find the eigenvalues of $A$. And for this application, recognize that the roots of $\det(zI - A)$ are the same as the roots of $\det(A - zI)$, these roots being the eigenvalues of $A$. Therefore, when computing the eigenvalues of $A$, the equation $\det(A - \lambda I) = 0$ will produce the same eigenvalues as the equation $\det(\lambda I - A) = 0$. Moreover, when computing these eigenvalues by hand, the matrix $A - \lambda I$ requires fewer modifications to the original matrix $A$, and therefore is less likely to result in bookkeeping errors (i.e. dropping a minus sign). So, the equation $\det(A - \lambda I) = 0$ is actually preferred when doing hand computations.
To summarize, you will often see $\det(A - \lambda I) = 0$ used for computing eigenvalues. But if you want to correctly represent the characteristic polynomial, you should write $\det(zI - A)$.
Comment: Note that not everyone defines the characteristic polynomial to be *monic*. All your comments about "correctly representing" the characteristic polynomial, or what "should" or "should not" be used to represent the characteristic polynomial are predicated on the assumption that the characteristic polynomial *must* be monic. That is simply not true, and depends on your definitional preference. This is not a matter of "correct" and "incorrect", but of pure and simple convention.


How to center XHTML (and/or HTML4) TABLE columns by colgroup?

Question: How to align all columns by colgroup?  It works with colspan?
Example
This HTML here was tested with Firefox and Chrome, but no browser renderize the center for all expected columns.

    <colgroup>
      <col style="text-align:center;background-color:red"/>
      <col align="center" valign="bottom" style="background-color:blue"/>
      <col align="center" valign="top" style="background-color:yellow"/>
    </colgroup>

      ISBN
      Title
      Price

      3476896
      My first HTML
      $53

      <big>5869207</big>
      My first CSS
      $49

Use this example (copy/paste to) at w3schools.com/tags.
PS: What is wrong with align and valign attributes?  Style (by text-align) also not responding.

EDIT
As I said above, I need a solution "by colgroup". It can be also "by colgroup or col tags with style attribute".
My template system need to use colgroup (!), not is valid a solution without colgroup.
My system not need to compatiple with HTML5, it uses something like "XHTML module" (see ex.  DTD).
Related questions

Is html <COL align> deprecated? : not the same, because my problem is about XHTML, not about HTML5 (that is not XML and is a "plan for future standard").
Comment: Ops, perhaps this is the problem, [not supported](http://www.w3schools.com/tags/att_colgroup_align.asp) except by Opera... But and about use of CSS styling? There are another "HTML setup", like DOCTYPE, that changes table behaviour?
Comment: I hate to be a debbie downer but you can see the same thing repeated here http://stackoverflow.com/questions/5261514/is-html-col-align-deprecated . As you may know google chrome auto updates itself, firefox has been supporting it for several years now, and IE has recently hopped on the bus. The support for colgroups is practically gone. I cant imagine the situation you would be required to use these for but best of luck!
Comment: OK, I add "Related questions": my problem is about XHTML, not non-XML HTML5.
Comment: where you able to test it in IE7? I wouldnt be surprised if FireFox and Chrome never allowed these attributes in the first place (the only w3c allowed attributes are background-color, border, width, visibility)
Comment: why does it need to be on colgroup? are you injecting it in some legacy code? you know u can use css without dropping colgroups
Comment: @Ayyash, can you do `colgroup char="character"` align? With CSS2?  XHTML standard use it, and my XML application use table module of XHTML.
Answer: If you take a look at http://www.w3schools.com/tags/tag_colgroup.asp you will see that the  tag is essentially being phased out as of html5. It is likely that your aligns arent working because your doctype is set to HTML5. In practice it would be not good to use a tag that is going out the door but if you have to use it try setting your doctype to html 4, otherwise I would recommend what Kontakt has said and use the CSS selector :nth-child.
Edit: I looked into it further and did some tests. Set doctype
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Then run it in IE7. You will see it works! It seems many browsers don't support it even if your doctype is set to  lower than 4. However good'ol IE7 still renders it. All that can be said is that it is a deprecated tag that doesn't work properly because it became unsupported long ago.
Comment: About HTML5: v5 have some taste of fork version, not the "next HTML"... My template and problems are with XHTML,  transforming (rendering) by  table module  rules of [XHTML 1.1 modularization](http://www.w3.org/TR/xhtml-modularization/), that is a W3C Recommendation of July 2010.
Comment: About DOCTYPE: I tried my HTML example with [all DOCTYPEs](http://www.w3schools.com/tags/tag_doctype.asp), but no one changes the behaviour of the "no DOCTYPE" test. It was with recent Firefox and Mozilla browsers... Do you try?
Comment: Thanks -- you find that it works with MS-IE7! confirming my comment that DOCTYPE is a "HTML setup" for colgroup works in some browser --, I done 1 up vote to your question... But not destinate all the bounty. [Only 0.8% uses MS-IE7](http://www.w3schools.com/browsers/browsers_explorer.asp) ([Opera, that I indicated, is 1.6 %](http://www.w3schools.com/browsers/browsers_stats.asp)), so it not add a real (100%) issue... Sorry, I add [my conclusion](http://stackoverflow.com/a/16951053/287948) that it was not a good question.
Answer: Why not use :nth-child(x) on td elements?
Add following code to your example in HEAD section:

and see changes to your third column.
Comment: Ok, it is the "normal way" to do the thing with CSS, but it is without any use of `colgroup`... I will reinforce this point in the question.
Answer: Well, thanks for all answers and clues. My conclusion, about colgroup, is

The HTML must be standard (XHTML1.0, XHTML1.1 or HTML4.X) compliant;
... but only one browser (Opera) is standard compliant. (MS-IE have no "standard compliant" tradiction, we can ignore IE7 surprising case)

"How to center the columns by colgroup?": following the standards instructions... So, my HTML code (at this question introduction)  was right all the time!  My mistake was wanting to see it at any web-browser!

Some "correct questions" are (examples):

Why another browsers not implemented the colgroup standard behaviour? At @ns47731's answer we see some clues. Perhaps web-browswer developer are expecting HTML5 and not XHTML2. See also @Alohci comment below.
Why HTML5 and XHTML2 proposals diverge about colgroup?  No clues at answers... My supposition: XHTML2 and HTML5 will be not 100% compatible.
Can I negociate with my "template system developer" (a XSLT developer) to add this "XHTML1 standard compliant feature"?  :-)  Please help me in a lobby for PMC Article Previewer.
Comment: Yup, that's more or less it. One of the reasons why new standards get written, is to supersede the bits of existing standards that are not worth the effort of implementation. Alignment by colgroup is one of those features. Note that Opera will almost certainly stop supporting it when it changes to the Blink rendering engine.
Answer:

 <colgroup>
      <col style="text-align:center;background-color:red"/>
      <col align="center" valign="bottom" style="background-color:blue"/>
      <col align="center" valign="top" style="background-color:yellow"/>
 </colgroup>

      ISBN
      Title
      Price

      3476896
      My first HTML
      $53

      <big>5869207</big>
      My first CSS
      $49

This at least centers your text in the cells, but like ns47731 its a deprecated tag so can't expect too much.
Comment: No, your solution was not "by colgroup", was "by replacing all td tags by th tags"... And semantic consistent with the "question title", is not the same as "with the full-question". Title is a synopsis.
Comment: Ops1: you changed all TD tags to TH tags (!)... It is not a solution, the cels are not cel-headers (semantic and layout error).
Comment: Ops2: HTML5 is not a standard today, and my problem is about XHTML (see DTD link, etc. there when you edited) or "old HTML 4.X".
Comment: As per the question asked, "How to align all columns by colgroup?" this whether semantically correct or not reaches your resolve


Reason for only national teams in some Olympic sports

Question: I am wondering on why the structures for some sports are completely different to others. Especially, why it is that in most winter sports, like downhill skiing, cross-country skiing or bobsleigh athletes always compete internationally for their respective country. In most other sports like football or cycling you do have individual teams or clubs competing on a national and international level and also additional national teams.
Is this based on historical reasons or why don't we have something like a team or club structure in some sports, mostly Olympic sports probably.
Answer: This comes down to money more than anything else.
Winter sports are typically funded by national organisations, who understandably fund their national athletes. To a very real extent, this is because outside a few Nordic and Alpine countries, winter sports aren't capable of generating enough independent money to fund a professional team.
Men's football obviously generates vast amounts of independent income, whether that be from television rights, direct ticket sales or sponsorship. Women's football is in a slightly different position, and it is notable that the Olympic women's football tournament is a fully open and highly prestigious tournament as opposed to the men's tournament which is an under 23s tournament and not a top concern for professionals. Similarly, cycling is capable of generating its own independent sponsorship so ends up with international teams.
Similarly, cycling generates its own independent sponsorship so features multi-national teams.


Forma mais eficiente de comparar duas variáveis tipo List

Question: Possuo duas variáveis do tipo List que precisam ser comparadas entre si para verificar possíveis duplicatas.
Exemplo de Conteúdo das Variáveis
Variável 01:
[01, Teste, Ativo]
Variável 02:
[01, Teste, Ativo]
No momento estou utilizando o seguinte script em Groovy para verificar:
for (TransportadoraPostgreSQL transportadorasBDM : transportadorasBanco){
    for(List transportadoraAVerificar : listaTransportadora){
        if (transportadorasBDM.getCodigo().toString().equals(transportadoraAVerificar.get(0).toString())){
            //logger.info("Iguais")
        }
    }
}

Porém desse modo quando as duas variáveis tiverem, por exemplo, 100 registros cada uma, serão 10.000 verificações no Loop, há alguma forma de ser mais eficiente essa verificação?
Comment: É isso mesmo, a não ser que tivesse algum critério que permite omitir algumas verificação é o que tem que fazer. Por exemplo, vamos dizer que seja garantido que a transportadora aparece só uma vez na lista e você quer apenas saber se existe pelo menos uma coincidência não precisa saber quantas ou quais, aí é possível parar a busca daquele item quando acha o primeiro, mas se só tiver zero ou uma ocorrência em tudo não haverá ganho.
Comment: @bigown E tem como eu deletar o registro repetido, para que na hora de exibir não haja registros repetidos?
Comment: Se voce nao quer que seu array fique duplicado e que seja unico, use `unique()`. por exemplo:

    def a = [1,2,3,4,5]
    def b = [1,2,3,4,5, 6]
    def c = (a + b).unique()
Comment: Ou voce pode tirar a diferenca e somar o array, por exemplo: def a = [1,2,3, 4]
def b = [1,2,3]
def c = a + (b - a), isto se seu "a" for o array principal.
Answer: Use Except
var firstNotSecond = list1.Except(list2).ToList();
var secondNotFirst = list2.Except(list1).ToList();

Esse método é bastante rápido.
return !firstNotSecond.Any() && !secondNotFirst.Any();

Maiores informações
Comment: Isso é Groovy? Parece C#. Além disto o que está sendo feito aí internamente na verdade reproduz o que o código dele faz, com grande chance de menor eficiência, mesmo que pequena diferença. Só tem a otimização que eu comentei ali em cima.


Using a concurrent hashmap to reduce memory usage with threadpool?

Question: I'm working with a program that runs lengthy SQL queries and stores the processed results in a HashMap. Currently, to get around the slow execution time of each of the 20-200 queries, I am using a fixed thread pool and a custom callable to do the searching. As a result, each callable is creating a local copy of the data which it then returns to the main program to be included in the report.
I've noticed that 100 query reports, which used to run without issue, now cause me to run out of memory. My speculation is that because these callables are creating their own copy of the data, I'm doubling memory usage when I join them into another large HashMap. I realize I could try to coax the garbage collector to run by attempting to reduce the scope of the callable's table, but that level of restructuring is not really what I want to do if it's possible to avoid.
Could I improve memory usage by replacing the callables with runnables that instead of storing the data, write it to a concurrent HashMap? Or does it sound like I have some other problem here?
Comment: I think I may have found a simpler way to cut it to begin with, but I'm still very interested in further optimization like I described above. I notice that when I'm writing the report, my xml writer creates a File with another copy of the map. By removing map entries as they are written to the File, I should be able to reduce some more. It's interesting how little things like that can slip by.
Answer: Don't create copy of data, just pass references around, ensuring thread safety if needed. If without data copying you still have OOM, consider increasing max available heap for application.
Drawback of above approach not using copy of data is that thread safety is harder to achieve, though.
Comment: I agree.  @William does not say why his custom Callable returns a copy of the retrieved data, but it seems quite odd.
Comment: There is no synchronization to take care of since he's using a Callable.
Answer: Do you really need all 100-200 reports at the same time?
May be it's worth to limit the 1st level of caching by just 50 reports and introduce a 2nd level based on WeakHashMap?
When 1st level exceeds its size LRU will be pushed to the 2nd level which will depend on the amount of available memory (with use of WeakHashMap).
Then to search for reports you will first need to query 1st level, if value is not there query 2nd level and if value is not there then report was reclaimed by GC when there was not enough memory and you have to query DB again for this report.
Comment: +1 for introducing me to another data structure that may be helpful. I don't think that will work for this project though.
Answer: Do the results of the queries depend on other query results? If not, whenever you discover the results in another thread, just use a ConcurrentHashMap like you are implying. Do you really need to ask if creating several unnecessary copies of data is causing your program to run out of memory? This should almost be obvious.


Display SVG while only setting parent height

Question: I have an SVG set in a container like so:

  <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <rect x="0" y="0" width="100%" height="50%" fill="blue"/>
    <rect x="0" y="50%" width="100%" height="50%" fill="green"/>
  </svg>

As you can see the SVG ignores the height set by the container. If I only set a width on the container - it's fine...
The container must only have a height set as the SVG can have a variable width. With display: flex it seems to work, but with other display types it doesn't - so I'm trying to understand why the different display properties work.
Comment: `svg { height:100%; }`?
Comment: I suppose display: flex works because it sets the child's height to be 100%
Answer: This CSS will make the SVG respect the container's height:
svg {
    height: 100%;
    width: auto;
}

Comment: @daggett Not quite. The point of `viewBox` is to say what part of the SVG is the important part. Thus, *when the SVG is given a width and height*, the renderer fills that area with the elements within the `viewBox`. That way, the SVG can be scaled like any other image, always displaying the same content.
Comment: I wonder why this isn't the default option
Comment: @daggett why should it be? Just because you want it to stretch to the height of the container in this particular instance, doesn't mean that is what everyone everywhere would need all the time.
Comment: I thought the whole point of viewBox was to control height and scaling, but it doesn't really in practice - be default the SVG looks to scale to the max width/height. Just seems more logical for SVGs to have a fixed size by default
Comment: ...and if you want to give the SVG a default size, use its `width` and `height` attributes.
Comment: Gotcha. I guess I'm still wondering why setting a width reacts differently, feels inconsistent
Comment: Historical reasons :) HTML layout always started with **width**. Either an element has a specified width, or it gets all the available width of its container (as in your case). Then, when the width is taken care of, each element claims as much vertical space (*height*) as it needs (even if that is taller than the container, again as in your case). The newer `flexbox` and `grid` layouts are more clever in how they work and give you more control.


About Zariski closure

Question: Let $A=\left\{\left(a^{2}+1, a^{3}+a\right) \mid a \in \mathbb{R}\right\} \subset \mathbb{R}^{2}$.

Find Zariski closure of $A$ .

I think Zariski closure of $A$ is $\mathbb{R}^{2}$ because let $ u=a^{2}+1$   and $ v= a^{3}+a  $ and let $ f(x,y) \in \mathbb{R}[x,y]$ then $f(u,v) =0$ now we must show $f$ is zero polynomial .
Comment: What if $f(x,y)=x^3-x^2-y^2$?
Comment: @JoséCarlosSantosv. So $cl(A) \neq \mathbb{R^2}$
Comment: Indeed, it is not.
Answer: Note that for any $a \in \Bbb R$:
$$(a^2 + 1)^3 - (a^2+1)^2 - (a^3+a)^2 = \\
a^6 + 3a^4 + 3a^2 + 1 - (a^4 + 2a^2 +1) - (a^6+ 2a^4 + a^2) = 0$$ so $A \subseteq \{(x,y)\mid x^3 - x^2 - y^2 = 0\}$ which is a Zariski closed subset by definition.
So the closure is at most $Z(x^3 - x^2- y^2)$, maybe even equal to it, thought I cannot show it yet. It probably is, though.
Comment: I think now we must use dimension for $A$ dimension is not $0$ so , $dim( cl(A))= 1 or 2$
Comment: @1200785626 How is $\dim$ defined for $A$? Not topological dimension, I suppose.
Answer: Not sure about my solution, but here's what I thought:
As others already mentioned, if we set $A(k) = \{(a^{2} + 1, a^{3} + a) | a \in k\}$ and $B(k) = \{(x, y)| y^{2} - x^{3} -x^{2} =0, (x, y) \in k^{2}\}$ for a field $k$, then we have $A(\mathbb{R}) \subset B(\mathbb{R})$. Unfortunately, two sets aren't the same since $(0, 0) \in B(\mathbb{R}) \backslash A(\mathbb{R})$. However, we can show $A(\mathbb{C}) = B(\mathbb{C})$: if $(x, y) \in B(\mathbb{C})$, then for $x\neq 0$, we have $(x, y) = (t^{2} + 1, t^{3}+ t)$ when $t = y/x$. For $x =0$, we can treat some cases by hands. What this shows is that the Zariski closure of $A(\mathbb{C})$ in $\mathbb{A}_{\mathbb{C}}^{2}$ is indeed $Z(y^{2} - x^{3} - x^{2})$. From this, we obtain that (which is the part that I'm not convinced enough) any polynomial $f(x, y) \in \mathbb{C}[x, y]$ with $f(t^{2} +1, t^{3} + t)=0$ for all $t\in \mathbb{C}$ can be divided by $y^{2} - x^{3} - x^{2}$, i.e. $f(x, y) = (y^{2}- x^{3} - x^{2})g(x, y)$ for some $g \in \mathbb{C}[x, y]$. *Now if $f(x, y) \in \mathbb{R}[x, y]$, then $f = \bar{f}$ (take conjugation of all coefficients) gives $g = \bar{g}$ and so $g \in \mathbb{R}[x, y]$, which concludes that the similar statement for real polynomial is also true.
Comment: So what is closure of $A$ ?
Comment: @1200785626 $Z(y^{2}- x^{3}-x^{2})$.

About Zariski closure


Law of Large Numbers

Question: Suppose X is uniform discrete distribution from a set of (1,2,3,...,m). How do i investigate the law of large numbers for this? I thought of doing this by maybe setting m as 10 and having sample of distributions from 1 to 10 using R. By running the program multiple times I would have multiple distributions for X being (1:10). Suppose I run the program for 20 times, i would have 20 sample distributions from (1 to 10). I can calculate the mean of each distribution. Then i would gather up the means and find the average of the means. For example, for the first 5 distributions, i would have 5 means and i sum those up divide it by 5. I do the same for 10, 15 and 20. As I increase the number of times i do it i would approach the population mean of (1+10)/2 = 5.5 Is my approach correct or is there a better way to do this?
Answer: The Law of Large Numbers concerns the sample average, whereby as the sample size increases, the sample average converges towards the expected value.
So in your case you would sample from the distribution and take the mean. Then as you repeat the sampling, each time increasing the sample size, the mean of the samples will approach the expected value.
I have often explained this to students with a simple example of rolling a fair 6-sided dice. The expected value is 3.5 obviously. First, note that we can never obtain 3.5 in a single roll. With 1 roll we would obtain any of the 6 possibilities with probability 1/6. As we increase the sample size, the sample mean will approach 3.5.
We can show this in R as follows:
We will sample from a uniform discrete distribution on the integers 1 to 6, starting with a sample size of 1 and increaseing the sample size to 1000. Each time we will compute the sample mean, and finally we will plot the means vs the sample size:
<code>set.seed(15)
N <- 1000
m <- 6
vec.mean <- numeric(N)

for (i in 1:N) {
  vec.mean[i] <- mean(sample(1:m, i, replace = TRUE))
}
plot(vec.mean)
</code>
Comment: so i would have more than 1 theoretical mean since for different sample sizes i would have different means? The mean in this case would be (sample size +1) /2 right?
Comment: Each sample mean will be the sum of all the samples divided by the sample size. Since you seem to be working in R, if the sample was `x` then you can just use `mean(x)`. Would it help if I showed a fuller example in R ?
Comment: that would be really helpful because i can't seem to understand how i would show the law of large numbers applies to a uniform discrete distribution.
Comment: This was really useful, by the way, what's the function of the (set.seed). Because i simulated a sample for my discrete uniform distribution using the sample function. I was still able to visualise the LLN without the 'set.seed' function. Just wanna get an idea of what its about.
Comment: You're welcome. `set.seed` just guarantees *exactly* the same output. Indeed, you would see almost the same output without it, from the plot (the furst few points would be noticeably different) and if you look at the the values in `vec.mean` you will also see the differences. Using `set.seed` is a good habit because it is essential for reproducibility.
Comment: Hi there, can I ask why the >set.seed is set to equal 15 and how would you go about adding a horizontal line to this graph.
Comment: @TaylorS. sure, I set the seed simply to make the results reproducible exaclty. 15 is my "default" but it doesn't really matter what you choose - the pattern will be the same. As for the horizontal line, you can use `abline(h = 3.5, col = "red")`
Answer: Stated precisely, the Central Limit Theorem (often referred to as "the Law of Large Numbers") says that given an underlying distribution with a finite standard deviation (which the uniform distribution does), for any range around the distribution's mean and target probability less than 1, there is some sample size for which the probability that the same mean is within the range is greater than the target probability.
So, for instance, if you want there to be a more than 99% probability that the sample mean is within 0.1 of the distribution mean, there is some sample size that satisfies that.
The CLT is a theorem about probability, so we can't say for certain what the sample means will do. It's not quite true that the sample means will get closer and closer to the distribution mean. The sample means will jump around, but they will probably jump around less and less.

For example, for the first 5 distributions, i would have 5 means and i sum those up divide it by 5.

That's a bit more complicated than it has to be. The expected value of a mean of means is just the mean of the underlying distribution. If you have twenty samples of ten observations each, the mean of the means will be the same as the mean what would get from just taking the mean of those 200 observations together.
Answer: Assuming that by "sample of distributions" you mean drawing m samples from the same uniform distribution between 1 and 10, then yes your approach is correct. As m increases, the sample mean will 'jump' less and less around the true (population) mean 5.5 (convergence in probability = LLN).
However, you will hardly notice the difference with m = 20. I'd suggest progressively taking m from 1 to 1000 and plotting the means like so:
<code># Sim LLN
m     = 500 #no of iterations
means = 0   #vector to store means
for(i in 1:m){
  means[i] = mean(runif(i,1,10)) #drawing i samples from ~unif(1,10)
}
plot(means,type='l')    #plot sample means
abline(h=5.5,col='red') #plot population mean
</code>
Note that for the (weak) LLN to work, all random variables need to be identically distributed and independent (which in this case they are).

Law of Large Numbers


Listas encadeadas - adicionar no final da lista

Question: to tendo problema na hora de executar esse código, cujo objetivo é adicionar um elemento no final da lista, o programa fica aguardando algo que não sei o que é, então o programa da erro. Alguma luz?
To começando agora listas, então a possibilidade de ser um erro besta é grande hehe.
typedef struct evento_t {
double tempo;
char descricao[50];
int id_origem, id_destino;
struct evento_t *prox;
} evento_t;

bool eventos_adicionar_fim (evento_t **lista, double tempo, char descricao[], int   id_origem, int id_destino) {

evento_t *novoelemento = (evento_t*)malloc(sizeof(evento_t));
evento_t *auxiliar = *lista, *anterior = NULL;

if (novoelemento!=NULL) {
    novoelemento->tempo = tempo;
    strcpy (novoelemento->descricao, descricao);
    novoelemento->id_origem = id_origem;
    novoelemento->id_destino = id_destino;
    novoelemento->prox = NULL;

    while (auxiliar!=NULL) {
        anterior = auxiliar;
        auxiliar = auxiliar->prox;
    }

    anterior->prox = novoelemento;

    return true;
}

else {
    exit(1);
    return false;
}

}
Comment: Note que você não previu o caso de a lista ter zero elementos (o while não executará e `anterior` será NULL). Nessa situação faça `*lista = novoelemento;`. Qual é exatamente o erro que você está observando? Crash?
Comment: Cade a definição da função main? Seu código parece estar incompleto. poste aqui pra gente dar uma olhada: http://pastebin.com/
Comment: Poste na própria pergunta, não tem porque por em um local externo.
Comment: Como estou executando pelo cmd, o cmd para de responder.

Já verifiquei o erro do NULL e ainda dá no mesmo. Acho que o main ta correto, porque tenho uma função pra adicionar no inicio e ela ta funcionando normal.
Comment: modifiquei o código
Comment: Execute em um debugger. Se seu compilador for o gcc, compile com `-g` e execute com `gdb prog.exe`. dê o comando `run` e `backtrace` para exibir o local do erro. (Dali você pode também explorar o valor das variáveis)
Comment: Ah, agora foi. Era exatamente o problema do NULL, tinha fechado o bloco do if no lugar errado ^^
Comment: Kay, se você encontrou a solução sozinho, adicione uma resposta a sua própria pergunta, assim completamos o ciclo :)
Comment: Não encontrei sozinho, tinha errado o negócio do NULL que você havia dito
Answer: O problema está em tentar inserir algo no fim de uma lista vazia. Nesse caso tanto o auxiliar quanto o anterior sejam NULL. O crash acontecerá ao fazer anterior->prox = novoelemento;. Em vez disso adicione uma checagem:
if (*lista == NULL) {
    *lista = novoelemento;
} else {
    // código anterior
}


How can a set with only two elements have 8 symmetric relations?

Question: In the question thread "how many symmetric relations are there on a set with 5 elements", user MJD offers the following answer:
$$
\begin{array}{rclrrl}
\text{A set with} & 0 & \text{elements has} & 2^{(0^2+0)/2} = & 1 & \text{symmetric relation}\\
\text{A set with} & 1 & \text{element  has} & 2^{(1^2+1)/2} = & 2 & \text{symmetric relations}\\
\text{A set with} & 2 & \text{elements has} & 2^{(2^2+2)/2} = & 8 & \text{symmetric relations}\\
\text{A set with} & 3 & \text{elements has} & 2^{(3^2+3)/2} = & 64 & \text{symmetric relations}\\
\end{array}
$$
What I'm wondering is, could you show me the symmetric relations for the sets with 0, 1, and 2 elements?
I get that $\text{R={(1,1),(2,1),(1,2),(2,2)}}$ is symmetric, as $\text{R(a,b) = R(b,a)}$ what I don't get is how a set with zero elements can have 1 symmetric relation, and a set with 1 have 2? Here is my guess:
$$\text{Set with 0 elements:  } \text{{∅} = 1 relation}$$
$$\text{Set with 1 element:  } \text{{∅,(1,1)} = 2 relations}$$
$$\text{Set with 2 elements:  } \text{{∅,(1,1),(1,2),(2,1)(2,2)} $\ne$ 8 relations }$$
Am I misunderstanding the concept of relations here? Help is much appreciated.
Answer: You're working one level down from the question. A relation is a description across the whole set of which elements are related. The possible symmetric relations for $\{A,B\}$ are:
$
\{\} \\
\{(A,A)\} \\
\{(B,B)\} \\
\{(A,A),(B,B)\} \\
\{(A,B), (B,A)\} \\
\{(A,A),(A,B), (B,A)\} \\
\{(A,B), (B,A),(B,B)\} \\
\{(A,A),(A,B), (B,A),(B,B)\} \\
$
characterized by whether or not to include or exclude the reflexives $(A,A)$ ,  $(B,B)$ and the symmetric pair $(A,B)$ and $(B,A)$
Answer: A relation on an set $X$ is a collection of ordered pairs $R \subset X \times X$. A symmetric relation is one that satisfies $(x,y) \in R \implies (y,x)\in R$.
If $X = \{1,2\}$ there are four ordered pairs in $X\times X$ namely $(1,1),(1,2),(2,1),$ and $(2,2)$.  So the total number of relations is $2^4 = 16$ since for each ordered pair we can independently choose whether to include it or not.
However for a symmetric relation if we put $(1,2)$ in $R$ we must also put in $(2,1)$ and vice-versa.  So now we get $2^3=8$ symmetric relations corresponding to the independent choices of whether or not to include $(1,1)$, whether or not to include $(2,2)$, and whether or not to include both $(1,2)$ and $(2,1).$
Answer: A relation is not a pair, but a set of pairs.
In particular:

Set with 0 elements: 1 relation

$\emptyset$

Set with 1 elements: 2 relations

$R_0 = \emptyset$
$R_1 = \{(1,1)\}$ (note: not $(1,1)$)

Set with 2 elements: 8 relations

$R_0 = \emptyset$
$R_1 = \{(1,1)\}$
$R_2 = \{(2,2)\}$
$R_3 = R_1\cup R_2 = \{(1,1), (2,2)\}$
$R_4 = \{(1,2),(2,1)\}$
$R_5 = R_1\cup R_4 = \{(1,1), (1,2), (2,1)\}$
$R_6 = R_2\cup R_4 = \{(1,2), (2,1), (2,2)\}$
$R_7 = R_1\cup R_2\cup R_4 = \{(1,1), (1,2), (2,1), (2,2)\}$

Note that there are $3=\frac{2\cdot 3}{2}$ minimal non-empty symmetric relations that are pairwise disjoint (namely $R_1$, $R_2$ and $R_4$), and all other are unions of sets of those "elementary" symmetric relations.

Note that this principle holds for any size: There is a set of minimal non-empty symmetric relations, which are all of the form $\{(a,b),(b,a)\}$ (note that for $a=b$ this is just the set $\{(a,a)\}$). For $n$-element sets, there are $N={n\choose 2}=\frac{n(n+1)}{2}$ such "basic" relations.
Each basic relation may or may not be a subset of a symmetric relation, therefore if there are $N$ such basic relations, there are $2^N$ symmetric relations in total. Therefore the total number of symmetric relations is $2^{n(n+1)/2} = 2^{(n^2+n)/2}$.


Determine the sample's variance

Question: Ok so I have a problem which I'm not sure how to resolve, it is probably something simple but I can't seem to get it, anyway here's what the problem says.
There is a population with an unknown variance $\sigma^2$. A confidence interval for $\mu$ with a 95% confidence and a sample size of 16 is $]42.7,49.3[$. Determine the variance for this sample.
This is where things don't add up. Basically $s^2$ = 38.3529, according to the answer. I'm doing this:
$\frac{(10 - 1)s^2}{\chi^2_{0.025,15}} = 49.3$
Where  $\chi^2_{0.025,15} = 6.26214 $
Nonetheless, it does not give me the answer and if I try it with the other side of the interval it gives me an even stranger number. Can someone help me, or give me a hint as to what I'm doing wrong?
Comment: Depending on the sample size one works with the $t$-distribution or $\chi^2-$ distribution. As a rule, if $n < 30$ then one uses the $t$-distribution. The confidence interval for the mean $\overline{X}$ is then $\overline{X}  \pm t_{\alpha/2} s/\sqrt{n}$. This is under the assumption of normality.
Answer: It's really a lot simpler than that.  Assuming that the sample was drawn from a normal distribution with unknown mean and variance, the Wald $100(1-\alpha)\%$ CI is of the form $$\bar x \pm \frac{s}{\sqrt{n}} t_{n-1,\alpha/2},$$ where $t_{n-1,\alpha/2}$ is the critical value for a Student's $t$ distribution with $n-1$ degrees of freedom at a two-sided significance level of $\alpha$; i.e., it is the upper $\alpha/2$ quantile satisfying $$\Pr[T > t_{n-1,\alpha/2}] = \alpha/2.$$
Since $\alpha = 0.05$ for a $95\%$ confidence level, and $n = 16$, we have $$t_{15,0.025} = 2.13145.$$  Then the midpoint of the CI is $$\bar x = \frac{42.7 + 49.3}{2} = 46,$$ hence $$s = \frac{(49.3 - 46)\sqrt{16}}{2.13145} \approx 6.19297.$$  This is the sample standard deviation, so the sample variance is $s^2 = 38.3529$, as claimed.
Comment: Yes, I see, much simpler than I thought. Thanks for the help.

Determine the sample's variance


Create list of {x,f(x)} pairs

Question: How can I do this in Mathematica:
r=Range[0,20,0.13];
fr = HeavisideTheta[r];
data = somecoolfunctionsinmathematica[r,fr]

So that data now is in the form useful to Fit: {{r_1,fr_1},{r_2,fr_2},...}
Thanks!
Answer: This is the correct way to use Table if you prefer it to Map:
Table[{i, HeavisideTheta[10 - i]}, {i, 0, 20, 0.013}]

Answer: I've found it, albeit syntactically a bit... involved (but I've seen a lot worse):
data = Table[{r[i], HeavisideTheta[10-r[i]]}, {r[i], Range[0, 20, 0.013]}]

Comment: `Map` will do it: `{#,HeavisideTheta[10-#]}&/@Range[0,20,0.013]`
Comment: Also `Transpose[{#, HeavisideTheta[10 - #]}]&[Range[0, 20, 0.013]]`...
Comment: Funny how the (IMHO) much worse pops up in comments under my answer :)
Comment: That's alright. IMHO taking a procedural approach when functional methods are available is a bit of a step backwards, but whatever, right?

Create list of {x,f(x)} pairs


Exercise: Limits and Probability Measure

Question: Let $\mu$ be a probability measure on $X$ (closed but unbounded), so that $\int_X \mu(dx) = 1$.
Let functions $f_i:X \rightarrow \mathbb{R}_{\geq 0}$,  $i = 1,2,...$, be Uniformly Integrable.
Prove that
$$ \limsup_{i\rightarrow \infty} \int_X  f_i(x) \mu(dx) \ - \  \lim_{n \rightarrow \infty} \limsup_{i \rightarrow \infty} \int_{X_n} f_i(x) \mu(dx) \ \ = \ \ 0   $$
for some sequence of compact sets $\{X_n\}_{n=1}^{\infty}$ converging to $X$ ($\lim_{n \rightarrow \infty} X_n = X$).
Comment: A $\lim_{n\to\infty}$ is missing, otherwise if $f_i=f$ integrable the result may be not true.
Answer: We have $\int_{X_n}f_i(x)\mu(dx)=\int_Xf_i(x)\mu(dx)-\int_{X\setminus X_n}f_i(x)\mu(dx)$. Fix $\varepsilon>0$; thanks to the uniform integrability we can find $R>0$ such that for all $i$, $\int_{f_i\geq R}f_i(x)\mu(dx)\leq \varepsilon$. We get
$$\int_{X\setminus X_n}f_i(x)\mu(dx)=\int_{X\setminus X_n\cap\{f_i\geq R\}}f_i(x)\mu(dx)+\int_{X\setminus X_n\cap\{f_i<R\}}f_i(x)\mu(dx)\leq \varepsilon+R\mu(X\setminus X_n)$$
so
$$\int_{X_n}f_i(x)\mu(dx)\geq \int_{X}f_i(x)\mu(dx)-\varepsilon-R\mu(X\setminus X_n)$$
and taking the $\limsup$:
$$\limsup_i\int_{X_n}f_i(x)\mu(dx)\geq \limsup_i\int_{X}f_i(x)\mu(dx)-\varepsilon-R\mu(X\setminus X_n),$$
so for all $n$ and all $\varepsilon$
$$0\leq \limsup_i\int_{X}f_i(x)\mu(dx)-\limsup_i\int_{X_n}f_i(x)\mu(dx)\leq \varepsilon+R\mu(X\setminus X_n).$$
Letting $n\to +\infty$ it gives that for all $\varepsilon>0$:
$$0\leq \limsup_i\int_{X}f_i(x)\mu(dx)-\limsup_i\int_{X_n}f_i(x)\mu(dx)\leq \varepsilon,$$
so
$$\lim_{n\to\infty}\left(\limsup_i\int_{X}f_i(x)\mu(dx)-\limsup_i\int_{X_n}f_i(x)\mu(dx)\right)=0.$$
Comment: Looking at the result, say if we can also claim the following (again $\{f_i\}$ UI, $X_n \rightarrow X$.

For any $\epsilon > 0$, the fact that

$$ \int_{X_n} f_i(x) \mu(dx) \leq \epsilon \ \text{ for any compact set } X_n $$

implies

$$ \int_{X} f_i(x) \mu(dx) \leq \epsilon $$


How to make a Web Application run under a particular IP

Question: I have created a .Net Web Application. Now i need to run my application under my machine IP instead of local host.
Can anybody give me the solution?
Comment: Are you wanting to access the site under your internal network IP such as 192.168.1.xxx, your external IP address, or just the localhost equivalent (127.0.0.1)?
Comment: `This type of question is better addressed on serverfault.com`  It's unclear from the question if you need help with setting up IIS to respond at a particular IP, or if you need help in figuring out how to assign one of your public IPs to the server itself.  For the former, look into IIS Management Console, under "Properties" for a given site, the "Web Site" tab of this control provides a way to add/remove IPs ("Web Site Identification").  For the latter, the conection Manager will do.  At any rate, contributors to ServerFault.com will have all these details for you...
Comment: very basic question dudes: @Srikanth, try what I posted bellow. It is development related issue; which I solved after googling..
Answer: Substitute your local IP for localhost should do it.
Answer: This happens normally on windows vista - where HOSTS file contains the IP V6 entry for local host which is not resolved.
Edit your HOSTS file;
C:\Windows\System32\drivers\etc\hosts
Find following line:
<code>::1             localhost
</code>
comment it by adding # at line start
<code>#::1             localhost
</code>
and add following:
<code>127.0.0.1 localhost
</code>
Restart your machine - now http://localhost will start working
Answer: Right click Web Site (Default Web Site in our case) and click on Properties
Click Advanced… button in the Web Site tab
Click on Default and click Edit…
Under IP address: click on the drop down list and select the machine ip
Now, when you try to access the Web site using http://localhost or http://machine_name it will give 404.You will need to access the web site using http://ip_address and that would work.
HTH


Netlify deployment - 500 Internal Server Error. on one pages

Question: Im trying to deploy my app with Netlify and Heroku.
Deployment works just fine - this is the URL:
https://fahrzeugliste-t5-kfz-neumayer.netlify.app/
Start page is working as intended, while clicking on "Fahrzeugliste" gets an 500 Internal Server Error.
This is the git repo for it:
https://github.com/TimoScheiler/fahrzeugliste
Answer: Your function log here: https://app.netlify.com/sites/fahrzeugliste-t5-kfz-neumayer/functions/___netlify-handler, shows the problem. It says:
<code>FetchError: invalid json response body at https://fahrzeugliste-t5.herokuapp.com/api/fahrzeug reason: Unexpected token < in JSON at position 0
    at /var/task/node_modules/node-fetch/lib/index.js:273:32
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async getServerSideProps (/var/task/.next/server/pages/fahrzeuge.js:234:34)
    at async Object.renderToHTML (/var/task/node_modules/next/dist/server/render.js:428:24)
    at async doRender (/var/task/node_modules/next/dist/server/next-server.js:1149:38)
    at async /var/task/node_modules/next/dist/server/next-server.js:1241:28
    at async /var/task/node_modules/next/dist/server/response-cache.js:64:36 {
  type: 'invalid-json'
}
</code>
If you go here: https://fahrzeugliste-t5.herokuapp.com/api/fahrzeug, you can indeed see that you don't get an expected response from your Heroku backend. You get a HTML page instead of a JSON response. You need to sort that out.
Comment: Thank you for your answer. I'm trying to figure it out but it isnt working so far.
Comment: @FRBT Debugging your Heroku app's problem is unrelated to this thread. Please open a new thread for people to help with that.


L2 norm of vector samples drawn from uniform distribution [-1,1] and standard normal distribution

Question: I was given a problem to make a guess about the expected values of "l2-norm square" of random vectors of size n which are drawn from a uniform distribution of [-1,1] and standard normal distribution. One of the things I noticed is, since the variance of standard normal distribution > variance of uniform distribution [-1,1] (var=1/3), we have more spread in the data drawn from normal distribution most of the time compared to uniform. So the value of norms will be larger in case of the vectors when drawn from standard normal case compared to uniform as we square the result. Correct me if I am wrong and please let me know if there is anything to decipher? I am happy to know further are there anything interesting observation hidden behind this problem.
Answer: By linearity of expectation, $\mathbb{E}(||x||_2^2) = \sum_i \mathbb{E}(x_i^2)$ and $\mathbb{E}(x_i^2) = \operatorname{Var}(x_i)$ if $\mathbb{E}(x_i) = 0$, which is the case for both the standard normal and the uniform distribution supported on $[-1, 1]$. If $x_1, \dots, x_n$ are iid with mean $0$ and variance $\sigma^2$ then $\mathbb{E}(||x||_2^2) = n \sigma^2$.


Do the elements of sample space constitute disjoint events?

Question: Let, we be given a sample space $\Omega=\{x_1, x_2, x_3\}$. Now, from the axioms of probability we know $P(\Omega)=1$. Also, from the definition of union of sets, we know, $\Omega=\{x_1\}\cup\{x_1\}\cup\{x_1\}$. Thus, $P(\Omega) = P(\{x_1\}\cup\{x_1\}\cup\{x_1\})=1$. Now, my question is, does this imply $$P(\{x_1\})+P(\{x_2\})+P(\{x_3\})=1?$$
Also, if yes, does this extend to sample spaces with countably infinite number of elements?
Answer: That depends on what the event space of your probability space is. If your event space is just $\{\{\}, \{x_1\}, \{x_2, x_3\}, \{x_1, x_2, x_3\}\}$ then it does not even make sense to talk about $P(\{x_2\})$ and $P(\{x_3\})$ since the probability measure is a function from your event space (usually denoted $\mathcal{F}$) to $[0,1]$. Now if your event space consists of all subsets of $\Omega$ then you are correct. This is because one of the axioms of a probability space is that the probability measure is countably additive. This means that if you have a countable collection of pairwise disjoint events: $\{A_{i}\}_{i=1}^{\infty }\subseteq {\mathcal {F}} $, then $P(\bigcup _{i=1}^{\infty }A_{i})=\sum _{i=1}^{\infty }P(A_{i})$.
Comment: Should that be $\{x_2,x_3\}$ instead of $\{x_1,x_2\}$?  Right now that isn't a $\sigma$-algebra.
Comment: Yes that is a typo. Thanks for catching it!


com topo fixo table

Question: Eu tenho uma
, e gostaria de deixar o
 dela com topo fixo:

            Código
            Descrição
            Qtd
            Preço Un.
            Desc %
            Desc R$
            Total
            ICMS
            Alíquota
            V.ICMS
            %ISS
            V.ISS
            %IPI
            V.IPI

        @foreach (var item in Model.PedidosProdutosF)
        {

                <input type="checkbox" class="link-check" onclick="PegaID(@item.Id);" onchange="cbChange(this);" />
                @item.CodigoProduto
                @item.Produto.nome
                @item.Qtd
                @item.PrecoUnitario.ToString("N2")
                @item.DescontoP.ToString("N2")
                @item.DescontoV.ToString("N2")
                @item.Total.ToString("N2")
                @item.ICMS
                @item.Aliquota.ToString("N2")
                @item.VICMS.ToString("N2")
                @item.ISS.ToString("N2")
                @item.VISS.ToString("N2")
                @item.IPI.ToString("N2")
                @item.VIPI.ToString("N2")

        }

Porém de toda forma que eu tento, ele cria uma scroll dentro da tabela, os campos ficam desalinhados, tem alguma configuração do bootstrap pra fazer isso, ou alguma outra forma que funcione?
Comment: E busque fazer sempre um [mcve]. Postar o HTML com a estrutura do seu template não facilita muito. Tente gerar um HTML que possua os dados reais reproduzindo o problema que você citou. E, neste caso, você pode utilizar o snippet.
Comment: Relacionada: [É possível adicionar um comportamento de overflow com scroll somente no tbody de uma table?](https://pt.stackoverflow.com/q/32304/5878)
Comment: Outra: [Fixar thead ao rolar a tabela](https://pt.stackoverflow.com/q/271288/5878)
Comment: @AndersonCarlosWoss já tentei esta primeiro, porém ficam desalinhados, vou verificar os outros.
Comment: https://pt.stackoverflow.com/questions/141185/tag-thead-fixada-no-topo-e-tbody-com-barra-de-scroll-em-tabela-no-html
Comment: Todas as formas que eu tento fazer de exemplo, o campo não fica responsive, ele fica fixo, e eu preciso que ele siga o padrão do bootstrap.
Comment: Mariana como o seu problema em questão era exclusivamente no Bootstrap eu preferir te responder aqui do que na nas outras respostas citadas aqui. Mas vou votar para fechar como duplicada ok, pois entendo ela como parte do escopo das outras perguntas tudo bem.
Answer: Cheguei em uma solução que funciona bem com o Bootstrap 3, testei aqui e não tive problema. Só tem um inconveniente... Não funciona no IE, pois utiliza o position:sticky, consulte aqui o suporte dos Browsers: https://caniuse.com/#feat=css-sticky . Tb precisei fazer um ajuste utilizando box-shadow para garantir que o texto que passa por traz do topo não vai aparecer
Veja como ficou o resultado:

.tabela {
  height: 200px;
  overflow: scroll;
}
.tabela th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  box-shadow: 0 1px 0 0 #ddd, 0 -5px 0 0 #fff;
}
  <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />

               Código
               Descrição
               Qtd
               Preço Un.
               Desc %
               Desc R$
               Total
               ICMS
               Alíquota
               V.ICMS
               %ISS
               V.ISS
               %IPI
               V.IPI

                   <input type="checkbox" class="link-check" onclick="PegaID(@item.Id);" onchange="cbChange(this);" />
                   @item.CodigoProduto
                   @item.Produto.nome
                   @item.Qtd
                   @item.PrecoUnitario.ToString("N2")
                   @item.DescontoP.ToString("N2")
                   @item.DescontoV.ToString("N2")
                   @item.Total.ToString("N2")
                   @item.ICMS
                   @item.Aliquota.ToString("N2")
                   @item.VICMS.ToString("N2")
                   @item.ISS.ToString("N2")
                   @item.VISS.ToString("N2")
                   @item.IPI.ToString("N2")
                   @item.VIPI.ToString("N2")

                   <input type="checkbox" class="link-check" onclick="PegaID(@item.Id);" onchange="cbChange(this);" />
                   @item.CodigoProduto
                   @item.Produto.nome
                   @item.Qtd
                   @item.PrecoUnitario.ToString("N2")
                   @item.DescontoP.ToString("N2")
                   @item.DescontoV.ToString("N2")
                   @item.Total.ToString("N2")
                   @item.ICMS
                   @item.Aliquota.ToString("N2")
                   @item.VICMS.ToString("N2")
                   @item.ISS.ToString("N2")
                   @item.VISS.ToString("N2")
                   @item.IPI.ToString("N2")
                   @item.VIPI.ToString("N2")

                   <input type="checkbox" class="link-check" onclick="PegaID(@item.Id);" onchange="cbChange(this);" />
                   @item.CodigoProduto
                   @item.Produto.nome
                   @item.Qtd
                   @item.PrecoUnitario.ToString("N2")
                   @item.DescontoP.ToString("N2")
                   @item.DescontoV.ToString("N2")
                   @item.Total.ToString("N2")
                   @item.ICMS
                   @item.Aliquota.ToString("N2")
                   @item.VICMS.ToString("N2")
                   @item.ISS.ToString("N2")
                   @item.VISS.ToString("N2")
                   @item.IPI.ToString("N2")
                   @item.VIPI.ToString("N2")

                   <input type="checkbox" class="link-check" onclick="PegaID(@item.Id);" onchange="cbChange(this);" />
                   @item.CodigoProduto
                   @item.Produto.nome
                   @item.Qtd
                   @item.PrecoUnitario.ToString("N2")
                   @item.DescontoP.ToString("N2")
                   @item.DescontoV.ToString("N2")
                   @item.Total.ToString("N2")
                   @item.ICMS
                   @item.Aliquota.ToString("N2")
                   @item.VICMS.ToString("N2")
                   @item.ISS.ToString("N2")
                   @item.VISS.ToString("N2")
                   @item.IPI.ToString("N2")
                   @item.VIPI.ToString("N2")

                   <input type="checkbox" class="link-check" onclick="PegaID(@item.Id);" onchange="cbChange(this);" />
                   @item.CodigoProduto
                   @item.Produto.nome
                   @item.Qtd
                   @item.PrecoUnitario.ToString("N2")
                   @item.DescontoP.ToString("N2")
                   @item.DescontoV.ToString("N2")
                   @item.Total.ToString("N2")
                   @item.ICMS
                   @item.Aliquota.ToString("N2")
                   @item.VICMS.ToString("N2")
                   @item.ISS.ToString("N2")
                   @item.VISS.ToString("N2")
                   @item.IPI.ToString("N2")
                   @item.VIPI.ToString("N2")

                   <input type="checkbox" class="link-check" onclick="PegaID(@item.Id);" onchange="cbChange(this);" />
                   @item.CodigoProduto
                   @item.Produto.nome
                   @item.Qtd
                   @item.PrecoUnitario.ToString("N2")
                   @item.DescontoP.ToString("N2")
                   @item.DescontoV.ToString("N2")
                   @item.Total.ToString("N2")
                   @item.ICMS
                   @item.Aliquota.ToString("N2")
                   @item.VICMS.ToString("N2")
                   @item.ISS.ToString("N2")
                   @item.VISS.ToString("N2")
                   @item.IPI.ToString("N2")
                   @item.VIPI.ToString("N2")

                   <input type="checkbox" class="link-check" onclick="PegaID(@item.Id);" onchange="cbChange(this);" />
                   @item.CodigoProduto
                   @item.Produto.nome
                   @item.Qtd
                   @item.PrecoUnitario.ToString("N2")
                   @item.DescontoP.ToString("N2")
                   @item.DescontoV.ToString("N2")
                   @item.Total.ToString("N2")
                   @item.ICMS
                   @item.Aliquota.ToString("N2")
                   @item.VICMS.ToString("N2")
                   @item.ISS.ToString("N2")
                   @item.VISS.ToString("N2")
                   @item.IPI.ToString("N2")
                   @item.VIPI.ToString("N2")

Comment: Obrigado, era isso mesmo, toda forma que eu tentava, ficava desproporcional, por ser responsive. Muito útil.
Comment: @marianac_costa massa! Essa opção vai funcionar em 95% dos navegadores, só não vai ficar fixo no IE infelizmente.

com topo fixo table


Optimizing Python logging code

Question: I have a Python application written on the Pyramid framework.
We really take advantage of logging on this ( for debugging ) , using the standard import library.
As we profile stuff on production, it seems that there is quite a bit of overhead from our logging activity.  All the string formatting and loops add up.  I'd love to remove it, but we can't -- we do actually need to keep it in for testing and will sometimes need to debug on the production environment.
I'm wondering if anyone has effective strategies for minimizing logging as needed , so this code could get "optimized away" during execution on our production environment and simply not run .
For example, under mod_perl, the compiler would "optimize away" statements run under False constants
in psuedocode...  ( i haven't touched perl in a long time! )
use constant DEBUG => False ;
if ( DEBUG ) {
      log.debug("stuff here " + string );
}

or
use constant DEBUG => False ;
DEBUG && log.debug("stuff here " + string );

Under those scenarios, the call to log.debug and even the string interpolation would never happen.
Can anyone recommend an effective method of mimicking that behavior under Python ?
Comment: thanks Martijn, that's a great tip.  You should repost it as an answer.
Comment: Posted with some expansion.
Answer: Use __debug__.  This flag is set to False when Python is run with the -O command line flag, and Python will furthermore optimize out debug code at compile time. I wrote a blog post on it a couple months ago.
Comment: Thanks, @kindall - that's a great trick.  you have no idea how much i'm smiling right now.
Answer: Don't use concatenation when you can use log.debug('stuff here %s', string); the logging module postpones interpolation until actually formatting the string when logging. If the DEBUG log level has been disabled, no interpolation takes place.
You can also test the logging level to avoid gathering expensive logging information unless needed:
if logger.isEnabledFor(logging.DEBUG):
    logger.debug('Message with %s, %s', expensive_func1(),
                                        expensive_func2())

See the optimization section of the Logging HOWTO.
Comment: It's sad that you have to use an `if` in your code. It would have been possible for `logger` to have been made smart enough to accept `logger.debug('Message with %s, %s', expensive_func1, expensive_func2)` and only call the func if needed. I guess you could do that with a wrapper, but I hate how much boilerplate there is for logging. It causes people to avoid logging or do it poorly.
Comment: It is actually not strictly necessary to use an explicit if to completely deactivate execution of the logging code in optimized mode (see my answer below). I wonder if my answer has any drawbacks that I cannot see (except for an obvious abuse of `assert`).
Comment: @peschü: well, the abuse itself is already one such drawback; readability definitely suffers.
Answer: I suggest to use assert for that purpose, as it nicely is optimized away in optimized mode.
In this case, it is not necessary to manually check if the logging level is enabled. This is especially useful when doing expensive formatting operations that can be useful for logging (like with the pprint module).
An example:
Instead of
logging.debug('my message %s', pprint.pformat(mycomplexdata))
you would write
assert(logging.debug('my message %s', pprint.pformat(mycomplexdata)) or True)
(The part or True makes sure the assertion does not fail.)
It is even possible to use .format in this case without performance penalty when running with -O.
assert(logging.debug('my message {}'.format(pprint.pformat(mycomplexdata))) or True)
Everything in assert() is optimized away when running python with -O.
Comment: Rather than abuse `assert`, use the [`__debug__` constant](https://docs.python.org/3/library/constants.html#__debug__), so use `if __debug__:`. The compiler will either include the block under `if` or omit it entirely (so **no actual `if` test is included**).
Comment: `assert` is a statement, not a function: `assert logging.debug('my message %s', pprint.pformat(mycomplexdata)) or True`
Comment: In other words, using `assert` is the ugly ugly version of using the accepted answer.
Comment: Thank you, I was not aware that the `if __debug__` statements are actually removed by the optimizer.

Optimizing Python logging code


interpreting Q-Q plot of a GWAS

Question: In the attached q-q plot obtained from a genome-wide case/control study, the negative log of the p-values are plotted on the x (observed) and y (expected) axis.
Few SNPs at the extreme distribution deviates from the expected null distribution. But, since the observed p-values for these SNPs in the extreme distribution is HIGHER (i.e. less significant) than the expected p-values, how should this be interpreted? as opposed to a situation if the observed p-values were more significant compared to the expected values?
Thanks
Comment: Is there any possibility that the $p$-values are being restricted by the characteristics of the test you are using to generate them? For instance some non-parametric tests can only take on a finite number of values.
Comment: Looking at the data for the smallest p-value would be informative, but I think @mdewey is probably right. For logistic regression, complete separation and premature convergence can both give lower limits on p-values.
Comment: Hi, thank you for your comments. I dont think so. The p-values were obtained from a logistic regression analysis in plink.
Comment: There is something wrong with the data. This can commonly stem from misread files.
Answer: All points on the dotted line represent data (p-values in this case) that occur as frequently as you'd expect by chance given the null hypothesis. Off-diagonal data represents p-values that are

lower than expected if the point lies above the line.
higher than expected if the point lies below the line.

In the context of GWAS/SNPs, points above the line are SNPs and points below the line mean your p-values are being poorly calibrated. This is usually from using misspecified models (especially mixed models).
(I'm very late I know)

interpreting Q-Q plot of a GWAS


loglinear analysis, assumptions met?

Question: We've data from a large ongoing project at a big science museum. We are showing people plates of food where we vary the plate shape (round or square; 0,1), food arrangement (polygonal or vertical arrangement; 0,1) and the number of items on the plate (3 scallops or 4). For each pair of plates+food, we ask the individual which they prefer. A person will only ever get trials where there are 3 vs 4 items on a plate. Below are our frequencies.
edit:

I have added 'test' which details which item x plate x arrangement
was tested with which other such grouping.
where 'weight' is the number of times the people decided one grouping (item x plate x arrangement) was preferred over another in a given text.

items,plate,arrangement,test,weight
3,1,1,1,249
3,1,0,1,177
3,0,1,2,282
3,0,0,2,184
4,1,1,3,243
4,1,0,3,297
4,0,1,4,185
4,0,0,4,281

I originally used loglinear analysis. I have a doubt though about this study. It feels as if some assumption has not been met. My question is: do you think this data is valid for such an analysis? Our criteria of only showing participants plates where there were 3 vs 4 items of food is bothersome.
For the curious, here is the loglinear model output (pdf).
Comment: a couple questions - are all the predictors (plate, arrangement, number of items) included as independent categorical variables? are interactions included? the outcome variable is prefer/don't prefer?
Comment: Dear Nick. Yes, all predictors are included. Log-linear stepwise analysis is including all possible interactions. Thanks.
Comment: Is your research question focused on the contribution of each variable (+ interactions)? I wouldn't collapse plate preferences into the weight variable for this design if that's the case. If this seems like an appropriate position, I'd be happy to amend my answer and write a quick R script to implement my suggestion so you can see concretely what I mean
Comment: Dear Ghonke, yes, we are keen on testing whether 3 is preferred over 4 scallops, and whether plate shape influences this. What about the absence of round plate vs square plate tests? Must admit this is quite a brain buster!
Answer: edit: this answer needs to be updated given new information provided in the question
I say you're meeting the assumptions of the test. Your intuition about 3 vs 4 scallops as a predictor variable might come from this:
As I've read it, you've got a series of categorical variables predicting a binomial preference  dependent variable (preferring a plate or not).
This design doesn't violate assumptions (as long as you're treating number scallops as categorical) but it might end up being under-powered (depending on n) as compared to a design that had integer predictors (like if you had 1-2-3-4-5 as number-of-scallops sub-conditions). I think that's what might be bothering you, but not much to do about it now, as these are the sub-conditions chosen for the experiment.
You might argue that the number-of-scallops predictor could be included as a numeric variable but consider that baked into that is the assumption that 0, 10, 50 100 scallops are possible values for the number-of-scallops predictor variable.
So if my read is correct, it's a logistic regression predicting plate preference with 3 categorical variables and I'd say you're using the technique appropriately.
Comment: Please follow orthodox spelling and punctuation. Your writing is unnecessarily difficult to read.
Comment: I understand weight to mean frequency of choices.
Comment: not sure i follow, @NickCox, but i gave it a shot

loglinear analysis, assumptions met?


In an arrangement, what rules/heuristics do you use to determine when it's okay for notes to stack on one another?

Question: For example, say you have a piano playing chords whose top notes are between middle C and the C above - in what situations would you say it's okay for some melody line to cross over those top notes? Should we always strive for separation? I assume it's context-dependent - but can you give some examples to help me wrap my head around when it tends to be acceptable and when you think it just sounds bad?
Another example might be countermelodies - how do we know when it's okay for two lines to step on each other/cross in music? What effect do you get by doing that?
For me personally, I'm always trying to isolate at least melody lines and chord top notes in ranges, but that seems restrictive to me... Thanks much for the help.
edit for clarity: I don't mean to suggest that there's some sort of rule for this and some rule against playing many lines close together/overlapping, but I suppose in terms of "typical" arrangements - such as classical music, or popular music and electronic music (if that even means anything!) I know that there's often at least some attempt at keeping some balance between clarity and density between lines in these styles and this is a relevant question for that.
Comment: It would be very helpful to know which instruments/voices you are considering,  and what style of music you are working on.
Answer: The core issue in both ranges and countermelodies is keeping the main melody clear and easy to follow.
For example, if a piano is accompanying a bass, it will tend to play in its middle or high register, but when accompanying a soprano, the piano will stay in a relatively lower register.
Timbre also plays a role. A trumpet is so comparatively loud and brassy, that it's easier to "safely" have overlapping ranges with a piano or other "softer" instrument.
Rhythm can help clarify roles in an arrangement as well. If all of the saxophones are playing in rhythmic unison, then even if other instruments are in overlapping pitch ranges, the contrasting rhythms can help differentiate the parts.


understanding of p-value in multiple linear regression

Question: Regarding the p-value of multiple linear regression analysis, the introduction from Minitab's website is shown below.

The p-value for each term tests the null hypothesis that the coefficient is equal to zero (no effect). A low p-value (< 0.05) indicates that you can reject the null hypothesis. In other words, a predictor that has a low p-value is likely to be a meaningful addition to your model because changes in the predictor's value are related to changes in the response variable.

For example, I have a resultant MLR model as
$
y=0.46753{{X}_{1}}-0.2668{{X}_{2}}+1.6193{{X}_{3}}+4.5424{{X}_{4}}+14.48
$. and the out put is shown below. Then a $y$ can be calculated using this equation.
<code>            Estimate      SE        tStat       pValue
               ________    ______    _________    _________

(Intercept)      14.48     5.0127       2.8886    0.0097836
x1             0.46753     1.2824      0.36458      0.71967
x2             -0.2668     3.3352    -0.079995      0.93712
x3              1.6193     9.0581      0.17877      0.86011
x4              4.5424     2.8565       1.5902       0.1292
</code>
Based on the introduction above, the null hypothesis is that the coefficient equals 0. My understanding is that the coefficient, for example the coefficient of $X_{4}$, will be set as 0 and another y will be calculated as $y_{2}=0.46753{{X}_{1}}-0.2668{{X}_{2}}+1.6193{{X}_{3}}+0{{X}_{4}}+14.48$.
Then a paired t-test is conducted for $y$ and $y_{2}$, but the p-value of this t-test is 6.9e-12 which does not equal to 0.1292 (p-value of coefficient of $X_{4}$.
Can anyone help on the correct understanding? Many thanks!
Comment: Check the answers to these two questions: - https://stats.stackexchange.com/questions/5135/interpretation-of-rs-lm-output and - https://stats.stackexchange.com/questions/126179/how-to-interpret-standardized-regression-coefficients-and-p-values-in-multiple-r They helped me understand how p-values are calculated, hope you'll find them helpful as well.
Comment: According to that introduction, you have only one "significant" variable--the "intercept"--, because only its p-value is small. To go beyond the naive and misleading practice in the quotation, you need to learn more about multiple regression. To see what can be learned in this regard, consider [exploring relevant threads on our site](http://stats.stackexchange.com/search?tab=votes&q=model%20selection%20multiple%20regression).
Comment: can you show the output of regression routine?
Comment: Your description of p-value computation is non-standard. Why do you think it should be computed the way you describe? p-value in the output is computed from the Var-Cov matrix of parameters. If you want to run the restriction test, like Wald, then it's not the way you describe. You'd have to re-estimate the model with 3 variables, get loglikelihood etc.
Answer: This is incorrect for a couple reasons:

The model "without" X4 will not necessarily have the same coefficient estimates for the other values. Fit the reduced model and see for yourself.
The statistical test for the coefficient does not concern the "mean" values of Y obtained from 2 predictions. The predicted $Y$ will always have the same grand mean, thus have a p-value from the t-test equal to 0.5. The same holds for the residuals. Your t-test had the wrong value per the point above.
The statistical test which is conducted for the statistical significance of the coefficient is a one sample t-test. This is confusing since we do not have a "sample" of multiple coefficients for X4, but we have an estimate of the distributional properties of such a sample using the central limit theorem. The mean and standard error describe the location and shape of such a limiting distribution. If you take the column "Est" and divide by "SE" and compare to a standard normal distribution, this gives you the p-values in the 4th column.
A fourth point: a criticism of minitab's help page. Such a help file could not, in a paragraph, summarize years of statistical training, so I need not contend with the whole thing. But, to say that a "predictor" is "an important contribution" is vague and probably incorrect. The rationale for choosing which variables to include in a multivariate model is subtle and relies on scientific reasoning and not statistical inference.
Comment: Can I know what we should do if the p-value of intercept in a linear regression is small? Should we remove it, and re-calculate the linear regression? Can we remove variables based on P-value?
Comment: @Katatonia these questions are asked throughout CV. In general you do not add/remove variables based on p-values. Removing the intercept makes the other variables non-interpretable.
Answer: Your initial interpretation of p-values appears correct, which is that only the intercept has a coefficient that's significantly different from 0. You'll notice that the estimate of the coefficient for x4 is still quite high, but there's enough error that it's not significantly different from 0.
Your paired t test of y1 and y2 suggests that the models are different from one another. That's to be expected, in one model you included a large but imprecise coefficient that's contributing quite a bit to your model. There's no reason to think that the p-value of these models being different from one another should be the same as the p-value of the coefficient of x4 being different from 0.


Git repository split - total repository size increased in comparison to original

Question: The big project, consisting of several modules, was split using
git filter-branch -f --index-filter "git rm -r -f --cached \
--ignore-unmatch $(ls -w 100500 -xd ^(editor|shared|thirdparty) )" \
--prune-empty -- --all

and similar command for rest modules into 2 projects A and B
The size of .git repository for original (unsplit) copy is 100Mb, size of .git in A is 89Mb and size of .git in B is 110Mb
For both projects A and B I used cleanup as
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

I don't really understand why original repo, being split into 2 copies, is ~2 times less in size than sum of it's splits.
I tried to perform lookups for several files from A in B and realized that there are no such files in A but are matches in B. So it looks like files (at least those ones) are not duplicated. I used the command like
git log --all -- **/CryptoInterface.java

in order to lok for the files.
So the question - if original project was 100mb, I assume that A should be like 30mb, B should be like 70mb or at least sum of sizes A and B shound't be as much as 2 times bigger than original 100mb.
Are there something wrong with my assumptions? Perhaps we do have duplicates in projects A and B? How can we check that and find duplicate objects?
Thanks in advance!
Answer: Have you tried to repack your packages? Every time I need to delete dangling objects in git, I use the following commands
rm -rf .git/refs/original/*
git reflog expire --all --expire-unreachable=0
git repack -A -d
git prune


How do manage your Perl application development, build, and deployment?

Question: I have yet to come up with a satisfactory way to manage the development, build, and deployment of my Perl applications.   I'd like to hear how you have solved this problem and/or what you would like to have in an application build system that you don't have now.
Please describe your application type (is it a web app, does it run on a server, or do you bundle it using PAR or PerlApp so that you can run on perlless systems).
Key things a build system should provide:

Control of libraries.

It should be possible to check a library distribution out into my dev directory to use it in my build.
It should be easy to execute perl with an @INC value that will use the appropriate directories.
It should be possible to get a list of modules that are being sourced from the system perl install.

Makefile/Build integration

It should be easy to do a global test across the entire application by issuing only one make test or similar command.

Version control friendly

structure should not interfere with normal usage of CVS, SVN and other version
control systems.

Cross platform

System should operate on Win32 and Unix derived systems at minimum.
Ideally, tools should function identically in all places where perl operates.

Single Perl install

It should not be necessary to install perl into a special directory as part of setting up the environment.

Easy start up

Starting an application should be a mostly automated process.  Something along the lines of Module::Starter or h2xs should be available to layout a basic structure and create any standard files.

Cross-posted at Perlmonks.
Answer: There's a lot that I could write about this

Control of libraries - I create my own versions of CPAN with just the modules I want. The latest versions of App::Cpan has several features, such as the -j option to load one-time configurations, to help with this. Once you have this, you can distribute it on a thumb-drive or CD which has all of the modules, the CPAN.pm configuration, and everything else you need. With a little programming you create a run_me script that make it all happen.
Makefile/Build integration - I don't integrate the Makefiles. That's the road to disaster. Instead, I do integration testing with the top-level application module, which automatically tests all of its dependencies too. The -t switch to the cpan command is useful to test the module in the current working directory:
cpan -t .

There are various intergation testing frameworks that you can use too. You set PERL5LIB to something empty (with only have the core modules in the hard-coded @INC directories) so cpan has to install everything from scratch.

Version control friendly - it doesn't much matter what you use. Most things have some sort of export where you can get everything without the source control stuff. Git is very nice because it only has a minimum of pollution in the normal cases.
Cross platform - everything I've mentioned works just fine on Windows and Unix.
Single Perl install - this part is more tricky, and I think you're going in the wrong way. Any time multiple things have to depend on the same perl, someone is going to mess it up for the others. I definitely recommend not using the system Perl for application development just so you don't mess up the operation of the system. At the minimum, every application should install all non-core modules into their own directories so they don't compete with other applications.
Easy start up - that's just a simple matter of programming.

BONUS: I don't use Module::Starter. It's the wrong way to go since you have to depend what Module::Starter thinks you should do. I use Distribution::Cooker which simply takes a directory of Template Toolkit templates and processes them to give them your distribution directory. You can do anything that you like. How you get the initial templates is up to you.
Comment: Great response, thanks.  A system that will work for me must not install things into site, and must be able to coexist with a single system perl.  My work with older versions of ActivePerl makes this an absolute requirement.  Where possible, I agree that it is best to use a separate perl.
Answer: I work on a pretty small website application, and we're just working on improving our deployment (improving it from "spend a day setting up all the modules we need on Windows and then throw files at it until everything works", so that's some improvement).
We've got three things which we need doing to set up our website:

A Perl module made using Module::Starter, containing a Config module which holds the site-wide configuration options. On installation, this module (using MakeMaker's PREREQ_PM to check that all the modules we require have already been installed). Any modules which haven't need to be installed before this module can be installed.
A few SQL files which need to be executed to set up the database.
The Perl CGI files which make up the website. As long as Apache is pointed to them, the website "just works". This includes the common code modules used by all Perl files.

Deployment consists in me pulling from everybody's Git branches and packaging a version. We can then hand this over for testing, either locally or on an Amazon EC2 instance. Once we're good to release, we either install it over the last version, or move the database over to the testing instance and make that the new instance.
Comparing this to your criteria:

Control of libraries: Somewhat. We use CPAN modules quite extensively. To try a new version, we upgrade our own version of a module before doing that upgrade on the production server. We manually maintain a list, but since our codebase is fairly small, it's not hard to figure out which modules are being used (via greping for lines starting with use, for instance).
Makefile/Build integration: Yes. Any Makefile related stuff is done by our EU::MM setup. We don't have global tests, but since our entire test suite recently ended up in one folder, hopefully we'll soon have something you can run prove on directly.
Version control friendly: Yes. Our entire source code is contained in a single folder, without too much duplication.
Cross platform: Yes. We've got lots of weird stuff happening in MakeMaker to allow us to do this, but as a startup, having cross-platform code gives us valuable flexibility. We try to use Perl's core modules and tools, and Pure Perl modules from the CPAN, as much as possible.
Single Perl install: Yes. We can handle Perl being anywhere, and installed under any settings, as long as all of Perl's own module tools can work - there's been a lot of effort put into getting CPAN, EU::MM and others working well across all systems, and it seems a shame to waste it.
Easy start up: Not really. This system evolved (ie: was not intelligently designed) from a single folder of all the source files and a text file with a list of modules which need to be installed. While formalizing testing for installed modules is a huge improvement, it still takes us something like a day to set this up, mainly spent installing our prerequisite modules (not all of them are easy to install on Windows). I'm hoping to use the Perl Win32 community to try and get issues with problematic CPAN modules ironed out.

Mind you, it's a really simple website, no XS, complicated web framework, or any such. We've also only supported this setup through about two versions, so we don't have enough experience as to how this is going to work as the code gets more complicated and our deployment platforms become more varied. I'd really appreciate any suggestions or comments on our system.
Comment: I'm doing similar things, and it all strikes me as too manual and error prone.  I've evolved things a bit over time, but I have to support multiple applications, so I am unwilling to make too many changes.


hyperbolic cosines inverse and derivative

Question: Show that cosh:$[0, \infty) \to [1, \infty)$ is strictly increasing bijection and that cosh: $(-\infty, 0] \to [1, \infty)$ is strictly decreasing bijection. Show that by inverse functions differentiability cosh has branches that differentiate: arcosh: $[1, \infty) \to [0, \infty)$ and arcosh: $[1, \infty) \to (-\infty, 0]$ and that depending on the branch,
$D(arcosh y) = {1 \over \sqrt {y^2-1}}$ for all $y \in [1, \infty)$ or
$D(arcosh y) = -{1 \over \sqrt {y^2-1}}$ for all $y \in [1, \infty)$
My work: I've proven the increasing and decreasing part, but how do I use the rule, I cant really get through $1 \over f´(x)$ (= $ 1 \over sinh(x)$)
Answer: This  is because $\;\DeclareMathOperator{\argch}{Argcosh}u=\argch y\iff \cosh u =y$ and $y\ge 0$ in the first case, $y\le 0$ in the second case.
Thus, in the second case:
$$(\argch)'(y)=\frac1{\sinh y}=\frac 1{-\sqrt{\cosh^2y-1}}=-\frac 1{\sqrt{y^2-1}}$$
since $\sinh y\le 0$ if $y\le 0$.
Comment: @H. Ergül: I'm fairly old-style. `Arg` stands for (and reads as) `'Argument'`. Actually, the truely old-style notation should be `Argch`, but since the notations are now `cosh, sinh`, not `ch, sh`, this is a compromise.
Comment: $\text{Argcosh}$ or $\text{Arccosh}$?
Comment: I'm also a little bit greenhorn :)


how to specify the file directory in drush config:status

Question: drush config:import has the --source flag to specify where the import should come from.
drush config:export has the --destination flag to specify where the import should go.
I am trying to automate a system for determining if update hooks have modified configuration, to avoid the problem documented in #3110362 If an update hook modifies configuration, then old configuration is imported, the changes made by the update hook are forever lost.
To do so I will export the config to a temporary directory, like:
drush config:export --destination=/tmp/check-issue-3110362

Then I will run the updates
drush updb -y

Then I want to run a diff between the database config and the config in /tmp/check-issue-3110362, but the following does not work:
drush config:status --source=/tmp/check-issue-3110362
# The "--source" option does not exist.
drush config:status --destination=/tmp/check-issue-3110362
# The "--destination" option does not exist.

How can I tell drush config:status to use a specific directory to check against the database?
My version of Drush is 10.3.6
Answer: You can use the config:export command with the --no parameter to prevent the actual export.
drush config:export --destination=/tmp/check-issue-3110362 --diff --no

The return value $? of Drush will tell you if there are differences between the database and the directory containing YAML files:

0 means no differences
1 means differences

Therefore, you can combine this into an if statement:
if ! drush config:export --destination=/tmp/check-issue-3110362 --no; then
  # Act on the change here.
  echo "Something in the config was changed."
fi

Answer: There's no option to do this with drush config:status. See the drush 10 documentation for config:status.
Presumably, you want to check if the config has changed so you can export it to your sync directories. Why not export it to them directly? If there are no changes, there will be no changes. But if there are changes, you'll see them in your repository, e.g. with git status.
I've always used Moshe's recommendation from comment #7 in your linked issue:

You must get your configuration right before you run a config import. Specifically, the config in the import must represent the values AFTER hook_updated_n runs. The developer workflow I advocate is to run the hook_update_n() locally, run drush config:export, and and then commit the results. Only then is the saved config ready to be imported.

I.e., start with a site in a clean state in your local environment:

Update your project(s) with composer.
Run drush updb to perform the db updates
Run drush cex to export any config changes made during those updates
Add any changes to your repo, commit, and push.
Pull the changes on your new environment
Run drush deploy


Finding placeholders and put then in an array

Question: In my string I have place holders like: ##NEWSLETTER## , ##FOOTER# ##GOOGLEANALYTICS## etc.
Each of those placeholders is delimited by: ##
I want to find each of thos placeholders and put them in an array.
The tricky part is that what's inside the ## delimiters can be anything.
Answer: Try this:
<?php

$s = "asdff ##HI## asdsad ##TEST## asdsadsadad";

preg_match_all("~##([^#]+)##~", $s, $result);

var_dump($result[1]);

prints:
array(2) {
  [0]=>
  string(2) "HI"
  [1]=>
  string(4) "TEST"
}

Comment: Please note, that if you want to be able to match a single '#' within a placeholder (eg. "##TE#ST##"), then you should change the regexp to
##([^#]|#[^#])+##
Answer: you can use preg_match_all():
$str = '##NEWSLETTER## , some more text ##FOOTER## test 123 ##GOOGLEANALYTICS## aaa';
preg_match_all('/##([^#]+?)##/', $str, $matches);
var_dump($matches);

$matches[1] will have all your placeholders


Como fazer busca pelo Id no mongodb Com condição

Question: Como fazer uma busca no mongo com parâmetros de condição, tipo:
Collection.find({userId}, {done: true}).fetch();

Desse jeito que eu escrevi quero retornar todos os documentos que tem o
done igual a true, fazendo uma busca no id do Usuario.
Eu tenho na collection um userID, _id da Collection, e o campo done
Estou usando Meteor e grahql, essa é meu resolver
 Query: {
    async taskCompleted(obj, args, {userId}) {
        return await Tasks.find({userId}).fetch();
    }
}

Nesse trecho de código, ele retorna todas as tarefas do usuario em questão
Answer: A denotação correcta seria.
var user_id = "as23df56hg";

//retorna um array de Tasks do respectivo query
var tasks = Tasks.find({ "userId" : user_id, "done" : true }).fetch();

Podes tambem usar o findOne
var user_id = "as23df56hg";

//retorna a primeira Task do respectivo query
var task = Tasks.findOne({ "userId" : user_id, "done" : true });

Importante
Como usar selectores de organização
Como usar selectores de campo


Excel mover valores não duplicados entre duas colunas para uma terceira

Question: Estou com uma dúvida e não consigo uma resposta plausível.
Tenho uma planilha na qual eu gostaria de fazer uma comparação entre duas colunas e dizer para a mesma que se houver um valor que não seja duplicado, que esse mesmo valor seja movido para uma nova coluna. Por exemplo:
Tenho a Coluna "A" e "B", nessas colunas existe um sequência de números de 6 dígitos, por exemplo:
<code>   A       B

519294  519522
519364  519499
519365  519501
519366  519500
519381  519494
519382  519492
519389  519493
519422  519491
519428  519483
</code>
Eu quero fazer uma comparação da coluna "A" utilizando a coluna "B", se o valor da coluna "A" não for encontrado na coluna "B" esse mesmo valor deve ser movido para uma nova coluna "C" por exemplo.
Se possível gostaria de usar uma formula ou um VBA que fizesse essa consulta e caso fosse um valor falso onde o referido valor não fosse encontrado na coluna "B" ele pudesse ser movido.
Fico muito grato se alguém puder me ajudar com um VBA ou Formula mesmo.
Comment: alguma coisa como em C4 pôr  `=IF(A4==B4; ; A4)`?
Comment: Não está claro o que você quer fazer. Você quer mover o valor da coluna A para C apenas se ele existir em B? A célula em A deve ficar vazia ou manter o valor? E as células de C que não receberem um valor? Além disso, seu exemplo não é bom, todos números são diferentes, não tem nenhuma match. Seria melhor você mudar seu exemplo e apresentar também o resultado esperado com a fórmula ou com VBA.
Answer: Se entendi seu problema, o código abaixo faz o que você precisa. Faça as adaptações necessárias caso use colunas além da "Z" ou pegue automaticamente o número da última linha da coluna, por exemplo.
Dica: coloque um valor na coluna "A" que exista na coluna "B" para se certificar que o código funciona.
<code>Dim i, j, LinhaInicial, LinhaFinal, ColunaResultado   As Integer

Dim ColunaBase, ColunaComparacao As String

LinhaInicial = 1
LinhaFinal = 9
ColunaBase = "A"
ColunaComparacao = "B"
ColunaResultado = 3 'Corresponde a coluna "C"

For j = LinhaInicial To LinhaFinal

 For i = LinhaInicial To LinhaFinal

  If Range(ColunaBase & j).Value = Range(ColunaComparacao & i).Value Then

   'Encontrou o mesmo valor, deve comparar o próximo valor
   GoTo AchouMesmoValor

  End If

 Next i

 'Se chegou aqui é por que não encontrou o mesmo valor
 'Coloca o valor em uma nova coluna
 'Calcula o código ASCII para a coluna (67 = "C")
 Range(Chr(64 + ColunaResultado) &     LinhaInicial).Value = Range(ColunaBase & j).Value

 'Prepara para próxima coluna a copiar valor encontrado
 ColunaResultado = ColunaResultado + 1

AchouMesmoValor:

Next j
</code>
Answer: Será que um PROCV combinado com SE e SEERRO não te resolve?
<code>=SE(SEERRO(PROCV(A1;B:B;1;FALSO);0)=0;A1;"")
</code>
Explicação: se o PROCV retornar um erro, indicando que o valor em A não foi encontrado em B, a fórmula retornara o valor de A. Se o valor em A for encontrado em B, a fórmula retornará vazia ("").