Centimorgans and relationship

Question: If two people share 327 centimorgans and 19 DNA segments and are first cousins 1x removed, is it possible that one of them is my 2nd cousin 1x removed if we share 353 centimorgans and 17 DNA segments.  I am trying to determine my relationship with them.
Our DNA matches came back as:
Susan and Bell share 327 centimorgans and 19 DNA segments (they are 1st cousins 1x removed).
Susan and I share 353 centimorgans and 17 DNA segments.
Bell and I share 162 centimorgans and 9 DNA segments.
Answer: I think you wrote the incorrect data. You can't have at the same time two different distances to one person ("364 centimorgans and 17 DNA" vs "353 centimorgans and 17 DNA segments"). Please correct your question.
Also as stated in Probability of Specific Relationship from AncestryDNA? you missed a lot of details. Yes, generally you and Susan may be 2nd cousin 1x removed. But you need to double check paper genealogy and use additional data. The clue may be not only in the size of overlap segments but in WHAT are these segments. You need so-called chromosome browser tool to visualize the overlapped segments. If there is no such tool on site of company where you got tests, you may upload the raw autosomal data to 3rd party service called GEDMATCH. It provides additional and very useful tools for comparing test taken from different people. Also you may find "matches" with others.
Comment: _Also, can you have a 1 cousin 1x removed share twice the centimorgans (638) than that of another 1 cousin 1x removed (327_

Unfortunately, yes, it can. It makes the research more difficult, I think.
Comment: That you for pointing out the typo - corrected.  My father was adopted and my DNA matches know very little about their family.  I think I have exhausted US records and have been on an Italian website as well.  I guess what I really want to know is, can a 2nd cousin or 2nd cousin 1x removed share the same centimorgans as a 1cousin 1x removed.  Also, can you have a 1 cousin 1x removed share twice the centimorgans (638) than that of another 1 cousin 1x removed (327).  I am trying to compare relationship with what they think they know.  Thank you for your feedback.

Centimorgans and relationship


Does a set of positive outer measure contain a measurable subset of positive measure?

Question: Is it true or false that whenever $E \subseteq \mathbb{R}$ is such that $m^*(E) > 0$, where
$$
m^*(E) = \inf\left\{\sum_{n=1}^\infty|b_n - a_n|\, :\mid\, E \subseteq \bigcup_{n = 1}^\infty(a_n,b_n)\right\}
$$
there is some Borel set $B \subseteq E$ such that $m(B) > 0$?
Comment: Is $m_*$ supposed to be $m^*$?
Comment: @ByronSchmuland: Yes, yes it does. Corrected. Thanks.
Answer: Without assuming that $E$ is measurable, this is false.
Let $E$ be a Vitali set in $[0,1]$, so that if $\oplus$ denotes addition mod 1 and $\{q_i\}$ is an enumeration of the rationals in $[0,1)$, we have that $\{E \oplus q_i\}$ are pairwise disjoint and their union is $[0,1]$.  I claim $m^*(E) > 0$.  For by countable subadditivity of $m^*$ we have
$$1 = m^*([0,1]) = m^*\left(\bigcup_{i=1}^\infty E \oplus q_i\right) \le \sum_{i=1}^\infty m^*(E \oplus q_i) = \sum_i m^*(E).$$
If $m^*(E) = 0$ then the right side would be 0.
Now suppose $B \subset E$ is Borel (or even just measurable).  Then we have that $\{B \oplus q_i\}$ are pairwise disjoint.  By monotonicity and countable additivity of $m$ we have
$$1 = m([0,1]) \ge m\left(\bigcup_{i=1}^\infty B \oplus q_i\right) = \sum_{i=1}^\infty m(B \oplus q_i) = \sum_{i=1}^\infty m(B).$$
If $m(B) > 0$ the right side would be $\infty$.  So we must have $m(B)=0$ and hence $m^*(B)=0$.
If $E$ is assumed to be measurable, this is true.  Indeed, you can find a Borel set $B \subset E$ with $m(B) = m(E)$.  There should be a proof elsewhere on this site, but I cannot find one right now.
Answer: The question of Evan Aad is not solvable within the theory $ZF+DC$. Indeed, in the theory $ZFC$ which is a consistent extension of $ZF+DC$(of course, if $ZF+DC$ is consistent) the answer is no. See, for example the answer of Nate Eldredge. On the other sense, in Solovay Model (ZF+DC+"every subset of real axis is Lebesgue measurable") which also is a consistent extension of $ZF+DC$(of course, if $ZF+DC$ is consistent) the answer is yes. Indeed, in Solovay Model each subset with positive Lebesgue outer measure same times is Lebesgue measurable with positive Lebesgue measure. Now by virtue an inner regularity  of the Lebesgue measure one can find a required Borel subset.
Answer: It is true. Given any measurable set $E$ in $\Bbb R$, given $\epsilon > 0$, exists $F \subset E$ closed such that ${\frak m}^*E < {\frak m}^*F + \epsilon$. Given any measurable set $E$ in $\Bbb R$, exists $F \in F_\sigma$ contained in $E$, such that ${\frak m}^*(E \setminus F) = 0$.
Comment: The question doesn't say anything about $E$ being measurable.
Comment: It is a proposition in Royden's Real Analysis book, in Lebesgue Measure chapter, but I don't remember right now if he proves it or if he gives hints and leave it as an exercise. But it is not hard. You first prove an analogous result with open sets and $G_\delta$s, and this one goes as a corollary by taking complements.
Comment: Thanks. Where can I find a proof of this result, please?
Comment: @EvanAad take a look at [this](http://math.stackexchange.com/q/904429/118056).


What Is the Physics principle behind dropping a stone into a cup of water?

Question: I have been doing an experiment about relationship between drop height of a stone and the loss of water in the cup it lands in. I found that after dropping the same stone into a cup with the same mass/volume of water that it gave a straight line (positive gradient) graph.
I need to include the principles behind this but I am unsure...
Is it because of the differing or same velocity that it hits the water at?
or the energy the stone has?
Comment: could you clarify your experiment and the result your getting please?
Comment: Why the downvote? This seems to me a perfectly reasonable question, and actually one to which it's hard to give a simple answer. It also seems obvious what the experiment is, though it would be nice to see some data e.g. a graph.
Comment: I wasn't the one who downvoted, but I can understand that, since the second sentence is clumsy and requires a bit of thinking on what was meant.
Answer: It is because stones dropped from a larger height have reached larger speeds when touching the water and larger speeds means more kinetic energy and momentum, and that means a larger explosion, and that means more water falling out of the cup. Every nonlinearity in some level is cancelled by another one at another level such that the relationship between height and water spilled is linear.


Why isn't the set of real numbers countably infinite?

Question: I am a bit confused about the distinction between uncountable and countable infinite. In Cantor's Diagonalization, could we not say that every time we create a new real number using diagonalization we map it to the next natural number? Isn't this sort of a method of counting/enumeration, to just continue to diagonalize one-by-one to infinity (since there are infinite natural numbers every one can be mapped)?
Comment: PS. I realize this is asking the same thing as another question but I have a different idea behind it, should I have just added mine as a comment on that post?
Comment: No, we could not say this in Cantor's diagonal argument. It already assumes that we have finished counting/enumeration, and then get a contradiction.
Comment: No.  To prove $\mathbb{R}$ is countable you would have to exhibit a *single* enumeration of every real numbers - you can't change it later.
Comment: Oh, I see, so since in our attempt to count real numbers we first need to demonstrate a bijection between R and N (which must be onto, meaning all natural numbers are mapped to some corresponding value already) there are no natural numbers left to map to the new diagonal values.
Answer: In Cantor's diagonalization, all of the natural numbers are already in use - the idea is that we begin with a mapping from the naturals to the reals, and construct a real that is not in the range of that mapping. So there is no "next" natural number.
The thing to realize is that the single diagonalization on its own doesn't prove uncountability - it's certainly the case that I can add one more element to an infinite list without changing its cardinality. The important thing about Cantor's diagonalization is that it works no matter what listing we start with. Here's the basic structure of the argument:

If the real numbers were countable, then there would be a listing of them by the naturals (i.e., a map $f$ from $\mathbb{N}$ to $\mathbb{R}$ that covers every real).
Suppose (for proof by contradiction) that the real numbers are countable. Let $f$ be a listing that proves this (so, $f$ is a map from $\mathbb{N}$ to $\mathbb{R}$ that covers every real).
We apply diagonalization to construct a real $r \in \mathbb{R}$ that is not in the range of $f$.
This contradicts our assumption about $f$ (that the range of $f$ includes every real). But $f$ was chosen arbitrarily, so this argument could be applied to any function you might suggest as a listing of the reals.
Therefore, any proposed listing of the reals is not actually a listing of all of the reals. There is therefore no listing of the reals by the naturals, so by step (1) above we know that $\mathbb{R}$ is not countable.


Would it be plausible to have someone who grew cancers to replace all his organs to achieve a pseudo-immortality?

Question: Since cancers are immortal, as long as they are 'fed', could a bunch of controlled cancers be used to create all the organs and bones needed to support a human and prevent death by old-age? That way, the 'person' lives forever and doesn't have to worry about cell apoptosis. Also, let's assume, that since the cells already mutated into a 'cancer' that they can't unmutate or mutate again to lose the 'immortality' status.
Comment: It seems that you want people with "inmortal cells" so they become inmortal. It doesn't work that way. Our cells having an expiration date is one of the things that allows us to live so long: if we still had the cells we were born with, they would be all malfunctional by now. Cells must die - and be replaced - in order to the body to keep working. Also, ageing is a complex process which is triggered by a lot of different things - merely inmortal cells won't affect the outcome much, except maybe negatively.
Answer: A cancer lacks the structure and function of the organ where it grows: a lung cancer doesn't increase the lung functional mass, a brain tumor doesn't increase the functional amount of brain and so on.
Just growing cancer everywhere in the body would slowly replace the functional body with a blob of unstructured cells whose only goal is to replicate, which cannot be a functional organism, since all vital functions have to be secured by some of those organs which have being turned into the blob.
Answer: By definition, no
Let's look at the definition of cancer:

Cancer is a group of diseases involving abnormal cell growth with the
potential to invade or spread to other parts of the body. These
contrast with benign tumors, which do not spread.

Further down in the same article:
All tumor cells show the six hallmarks of cancer. These characteristics are required to produce a malignant tumor. They include:

Cell growth and division absent the proper signals
Continuous growth and division even given contrary signals
Avoidance of programmed cell death
Limitless number of cell divisions
Promoting blood vessel construction
Invasion of tissue and formation of metastases

Put simply, a cancer is by definition uncontrolled and invading other parts of the body.  5 out of the 6 characteristics of a cancer mean that a body made up of cancers would have each part of the body fighting with every other part and burning up resources unproductively while growing uncontrollably.
If you are going to come up with a new condition that just gives one attribute of cancer while ignoring all the other characteristics then it isn't cancer.  It would be like holding up a front windscreen for a sedan with no other parts of the vehicle attached, calling it a "car" and praising its fuel efficiency.
If you want a body continue living whether or not it has signs of ageing then cancer is not the solution.
Comment: We can learn from cancers how to turn off aging mechanisms.
Answer: Cancerous tissue can't replicate the functioning of a healthy organ. This is why people die from cancer. The rampant growth disrupts the body's ability to self regulate and continue to sustain life. When someone dies dies their tumors will quickly die like every other tissue in the body.
There are exceptions to this inevitable fate, ways to cheat the reaper his due. Clonaly transmissible cancers can spread from one individual to individual. Effectively becoming an unicellular, asexual, pathogen. Similarly immortal cell lines are manually propagated for research. Each cell identical to those originally harvested from some cancer patient.
Few would consider what survives a person. Fewer still would consider its existence proof that someone is still alive. Their body will undergo funeral rites. If aware of the cancer loved ones may find some solace, but they will still grieve their passing.
Comment: I seem to remember that Henrietta Lacks's family is sueing for the rights to her cancer that's been alive for the past 70 years.
Comment: @BlueSkinandGlowingRedEyes Look at the language you're using. Her family is suing for the *rights to her cancer*. You talk about it as a possession, not a person. The suit isn't over the personhood of the cell line, but how something of Henrietta's was taken without her consent or knowledge.
Comment: i stand corrected


nikon d7100 shutter activation but no picture

Question: Recently I tried to take a photo with my Nikon D7100. The shutter activated but no picture was stored. I tried again and got the same result. I then switched the camera off and then back on and it seems to be working correctly now. The shutter count is 42,200.
Anybody have any ideas?
Cheers
Ian
Comment: I have no idea about that particular event, but it might be worth checking your firmware versions and updating if not current.
Comment: Does an image come up while buffering? My wife's mom's Nikon by default shows the taken image while it's being saved (at least, I believe it does this from the buffer). I'm trying to ascertain if the image is lost at the buffer or at the sd/cf card.
Comment: Thanks for your replies. Hueco, I switched that function off to save battery life. It's the first time that this has happened, I think?. The SD card is about two thirds full and I only use the cards once.
Comment: Is the D7100 capable of mirror lockup? Does cycling the power automatically cancel mirror lockup?
Answer: I have seen the same issue with a D7100 (& Nikkor 18-140mm ) this week. Just as described the D7100 operated as normal and it continues to increment the image numbers. Lucky for me I spotted this early. I removed the battery and removed both Sandisk SDHC cards. After replacing the battery and then the 2 SDHC cards normal operation resumed. I am on the current firmware and lens profiles. The recorded image files have a gap of about 25 frame numbers, so some aspect of the D7100 believes it is working - but it had failed to write the missing NEF file to either of the SDHC cards.
Answer: I would try to:
- Check thoroughly the integrity of the memory card. Re-format, if you think it is a healthy card;
- Update firmware if possible;


Used to be possible in Snow Leopard to move an app between `desktops` with a keyboard shortcut?

Question: You could assign a keyboard shortcut to move the app with focus to a specific desktop.  Can't find this in Lion.  Anyone know if it's still possible?
Comment: Did this shortcut really exist? I don't remember seeing it.
Comment: Same here, I was never aware of such a thing existing.
Comment: I figured it out! See answer below.  Actually never changed, still works the same way as Leopard.  Hadn't used it lately since Spaces never stuck with me.  Mission Control actually seems useful so am reinvestigating how some of it's stuff works.
Answer: I figured out how to do this.

Open System Prefs > keyboard
On Keyboard Shortcuts tab choose Mission Control
Enable the "Switch to Desktop..." shortcuts
Now when you click on a window and perform the Switch to Desktop keyboard shortcut it'll move that window to the desktop

Guess there is a mouse component to this, so it's not pure keyboard.  But I find it way easier than dragging windows around in mission control.


Java RS-232 Communication on Windows

Question: Does anyone know of a good Java API for controlling RS-232 devices in a WIN32 enviroment?
I've tried RXTX but they don't support RS232, only RS-485.
Answer: Without reservation, I recommend Java Serial Port from serialio.com. I had significant stability problems with the Sun, IBM and RxTx serial packages.  SerialPort has been rock solid in production for over 2 years 24/7.
They support the standard Java serial API, as well as their own alternative proprietary one.  I would stick with the standard API though, unless you really need something theirs has that the standard one doesn't, just to keep your options open.
Comment: word! serialio is it worth, really!
Comment: I should, in fairness, point out that my project was done a little over 2 years ago, and RxTx may have progressed since then.
Comment: The quality of the RXTX code is quite bad. Be prepared to jump through various hoops if you go down this road.
Answer: I advise you to try jSSC. This lib support Win32(Win98 - Win7) and Win64. Linux version under construction. Project page on Google code: http://code.google.com/p/java-simple-serial-connector/
Comment: Does jSSC support RS-422 as well as RS-232?
Answer: What about J/CoMM?

OS independent RS232 remote control. Java-based server (console), easy adjustable HTML GUI, local/internet use, incl. device driver API and drivers (e.g. EIKI LC-XM1/SM1/VM1!!)
Answer: I've just implemented a single-direction interface (device->computer) with Scream3r's jSSC library using Java 1.6 and Windows 7 64 bit quickly and without problems.
Hint: If you look at his additional code in jSSC-Terminal.zip you get a nice (and essential for using the lib) example how to work with the library!
Thank you Scream3r for sharing this, you made my day!
Answer: I stumbled upon scm which is another open source library for RS232 serial port communication. Project page is https://github.com/RishiGupta12/serial-communication-manager
Answer: Have you tried Javacomm from Sun?
Comment: Javacomm doesn't support Windows anymore.  On their main page, they don't even list it.  More searching reveals that Sun dropped support for it after Java 1.1.6

Java RS-232 Communication on Windows


How to add detail and grit to vector graphics?

Question: The National Poster Example http://www.dkngstudios.com/images/national.gif
Can anyone give me some tips or point me to a tutorial that can help me learn how to add details like grit and texture to vector graphics like in the above image by DKNG Studios? I assume it involves a lot of photoshop brushes and/or textures but I've been unsuccessful in finding any go-to methods.
Often with textures I find it hard to achieve the exact results I'm looking for and they can really increase my file size and make the artwork convoluted.
Brushes can be useful but I find them to work better in photoshop and it can become difficult to constantly switch between the programs, especially when trying to keep the layers straight.
I've found tutorials explaining vector halftones but still have a lot of trouble implementing them well.
Any help is greatly appreciated.
Thanks,
Pierce
Answer: Many images which use textures or "grunge" appearances in Illustrator take advantage of Opacity Masks and embedded raster images. Even though Illustrator is vector at its core, there are times where utilizing the subtle variations in a raster image can be helpful. Trying to create distressed or mottled backgrounds is certainly one such case.
First, find a raster image with a texture you like. It's easiest if it's a greyscale image (but color images work). Greyscale simply allows the raster image to adjust values rather than possibly also altering the color of (what will be) underlying objects.
So a grey scale texture image:

Open the Illustrator artwork:

Now, if I want to add the texture to the light brown background area:

Import the raster texture image
Position it above the object I want to apply it to
Select the texture image and the object below it
Click the Make Mask button on the Transparency Panel

You can then click the mask thumbnail on the Transparency Panel and move the raster image around to see how it effects the object it is applied to.
Large animated gif attached. It may take a moment to load

What the Opacity Mask does is hide portions of the light brown rectangle allowing the dark brown rectangle to show through it. Like all masks, the dark areas of the raster image hide content and the white areas show content.
You could apply an Opacity Mask to the artwork as a whole or use several varying textures and apply them to separate objects.
This is often how "grudge" appearances are achieved with Illustrator.
Be aware: This does use raster images. And with that in mind the raster mask is just as susceptible to "broken pixels" as any raster image should to overly enlarge the artwork. Unlike most vector creation, you need to pay attention to the PPI and any scaling you do if using this technique.

You could also auto-trace the raster texture and then use a standard clipping mask in Illustrator. However, often auto-tracing raster texture images results in unwieldy large files which can quickly become unworkable. Illustrator tends to get slower and slower with each new complex vector object. In addition, some subtle texture variations simply aren't possible using vector paths.

The following existing questions also refer to how to "distress" vector graphics:
Add imperfections to vector graphics / drawings
How to get a construction paper look in photoshop or illustrator
Comment: Hey thanks a lot! This is helpful. Sweet gif btw!
Answer: Similar to Photoshop, Illustrator also has blending modes.  Placing a texture over a vector and then setting the Blending mode, located on the Transparency panel, to something like Overlay may help achieve the look you are hoping for.
Answer: You can also place a bitmap TIFF file into your Illustrator document. This allows you to colorize it in Illustrator. Here's a tutorial on how to create a bitmap TIFF in Photoshop: http://knowledgejam.org/home/2014/7/31/creating-textures-with-bitmap-tiffs
Comment: This is something I never knew about. Thanks!


How to give users or group in linux sudo permission with limited permission on certain files

Question: I want to give a list of users or certain group on my CentOS 6.7 server with sudo permission but no access to just this file /root/database.yml Is that possible ? The file actually has a password which i do not want anyone to see except for me. Any suggestion or help is greatly appreciated.
Answer: Yes, the sudo program allows you to limit what a user can do.  The policy is in the file /etc/sudoers. If you want to allow certain operations only, write a script that only implements those and restrict them to only running that as the command.  To be sure that the security is what you want you probably need to understand the sudo and sudoers man pages.
Comment: thx for ur reply but Is it possible to do like  all permission but access to /root/database.yml is what i am looking for ?
Comment: If you just want to deal with access to one file, that's exactly what normal UNIX permissions do.  You create a group, put the affected accounts in it and set the file to that group and the group permissions to what you want.
Answer: No, you can't do that. If you give root permissions to someone, they can do everything, including reading and writing every file. Even if there was a way to somehow exclude /root/database.yml, root could still change the sudo configuration, replace the sudo binary, access the disk directly, etc.
If you don't trust your fellow administrators, don't store any secrets on the machine.
If you want to both store a confidential file and have administrators who can't read that file, then the file must be stored on a different machine from where those people are administrators. The different machines can of course be virtual machines or containers, they don't have to be separate physical machines.
So put all the services that you want your fellow administrators to manage in a virtual machine or container, and make them root in the VM/container. Keep the confidential file /root/database.yml on the host, and don't give out any root permission on the host.


Prove that $(n-1)! \equiv -1 \pmod{n}$ iff $n$ is prime [Wilson's Theorem]

Question: How can I show that $(n-1)!\equiv-1 \pmod{n}$ if and only if $n$ is prime?
Thanks.
Answer: $$n\text{ is prime if }(n-1)! \equiv -1 \pmod n$$
This direction is easy. If $n$ is composite, then there exists $k|n$ and $k\lt n$. So $k|(n-1)!$ and $k \equiv 1 \pmod n$. This means $k$ needs to divide $1$. So $n$ must be prime (or $1$, but we can eliminate this by substitution).
$$(n-1)! \equiv -1\text{ if }n\text{ is prime}$$
Wikipedia contains two proofs of this result known as Wilson's theorem. The first proof only uses basic abstract algebra and so should be understandable with a good knowledge of modular arithmetic. Just in case, I prove below that each element $1, 2, ... n-1$ has a unique inverse $\mod n$.
They use the fact that integers $\mod p$ form a group and hence that each element $x$ not congruent $0$ has a multiplicative inverse (a number $y$ such that $xy \equiv 1 \mod n$.
We show this as follows. Suppose $n \nmid x$, for $n$ prime. From the uniqueness of prime factorisations, $xn$ is the first product of $x$, after $0x$, divisible by $n$ (use prime factorisation theorem). If we look at the series $kn \mod n$, this cycles and must have cycle length $n$. Therefore, each element $x, 2x,... nx$ must be different modulo $n$, including one, $y$, with $xy \equiv 1 \mod n$. Furthermore, due to the cycle length being $n$, each only one of those elements will be an inverse. So every element has a unique inverse (although 1 and -1 are their own inverses).
Comment: I was satisfied with just the name of the theorem. Adding the proof certainly justifies an upvote.
Answer: Hint $\ (p\!-\!1)!\bmod p\,$ is the product of all elts of $\, {\mathbb F}_p^*.\,$ The map $\, n \mapsto n^{-1}$ is a permutation of $\:{\mathbb F}_p^*\:$ of order $\,2\,$ so it decomposes into cycles of length $1$ or $2,$ which partition the product. Each $2$-cycle $ (n, n^{-1})$ has product $1$ so is deletable, leaving only the product of $1$-cycles $ (n)$. They satisfy $\: n^{-1}\! = n \Rightarrow n^2 = 1 \Rightarrow n = \color{#0a0}{-1}\,$ or $\color{#c00}1,\,$ by ${\mathbb F}_p$ a field. So the product reduces to $\,\color{#0a0}{-1}\cdot\color{#c00}1 = -1$.
The converse is much easier: $ $ if $\,(n\!-\!1)!\equiv -1\pmod{\!n}\,$ then $\,n\,$ is coprime to $\,(n\!-\!1)!\,$ and all its factors, which include all proper factors of $\,n.\,$ So the only proper factor of $\,n\,$ is $\,1,\,$ i.e. $\,n\,$ is prime. More generally see this answer.
Remark $ $ See here for a generalization to the product of all the invertibles in $\Bbb Z_n\! = \Bbb Z\bmod n.\,$  Wilson's Theorem generalizes further: if a finite abelian group has a unique element of order $2$ then it equals the product of all the elements; otherwise the product is $1$, e.g. see here for hints (this is the group-theoretic Wilson Theorem).
Notice how we've exploited the existence of a symmetry - here an involution that induces a natural pairing of elts. Frequently involution and reflection symmetries lie at the heart of elegant proofs, e.g. see the elegant proof by Liouville, Heath-Brown and Zagier which shows every prime $\equiv 1 \pmod{\! 4}\,$ is a sum of $2$ squares, or the little-known beautiful reflective generation of the ternary tree of primitive Pythagorean triples due to Aubry.
Comment: @Buraian If you Google "math abbrev elt" you'll see it means "element"
Comment: What on earth is an elt?
Answer: Here are a couple possible proofs of Wilson's theorem for $p>2$ ($p=2$ is easily checked):

We have that $x^{p-1}-1$ has roots $1,2,\ldots,p-1$ over $\mathbb{Z}/p\mathbb{Z}$ (by Fermat's Little Theorem). But as $\mathbb{Z}/p\mathbb{Z}$ is a field, we have unique factorization of polynomials, so that $x^{p-1}-1=(x-1)(x-2)\ldots(x-(p-1))$. Comparing constant terms wields Wilson's theorem.
Let $g$ be a primitive root modulo $p$. Then $(p-1)!\equiv g\times g^2\times \ldots \times g^{p-1}=g^{p\frac{p-1}{2}}\equiv g^{\frac{p-1}{2}}\bmod{p}$ by Fermat's Little Theorem, and $g^{\frac{p-1}{2}}\equiv -1 \bmod{p}$ because if $(g^{\frac{p-1}{2}})^2=g^{p-1}\equiv 1 \bmod{p}$ and $g^{\frac{p-1}{2}}\not \equiv 1 \bmod{p}$ by the definition of primitive root.
Answer: [NOTE: it seems that there is some difference between preview and actual output, so instead if using (mod p) I stick with (p)]
to show that $(p-1)! \equiv -1 (p)$ without explicitly use group theory, maybe the simplest path is: (the following assumes $p$ is odd, but if $p=2$ then the result is immediate)

given $n \ne 0$, all values $n, 2n, ... (p-1)$ $n$ are different mod $p$. Otherwise, if $hn \equiv kn (p)$ then $(h-k)n \equiv 0 (p)$ against the hypothesis that $p$ is prime.
this means that each $n$ has an inverse mod $p$, that is for each $n$ there is a $m$ such that $mn \equiv 1 (p)$.
the equation $x^2\equiv 1 (p)$ may be written as $(x+1)(x-1) \equiv 0 (p)$; therefore its only solutions are $x \equiv 1 (p)$ and $x \equiv -1 (p)$. For each other number $n$, an inverse $m$ must exist (because of the pigeonhole principle) but $m \neq n$.
we are nearly done. Let's couple every number from $2$ to $p-2$ with its own inverse. Their product is $1 (p)$, so they don't count in the overall total. $1$ does not count either; it remains just $p-1$, that is $-1 (p)$ as requested.
Comment: if the inverse were not unique, we would have h and k such that nh ≡ 1 and nk ≡ 1, and we fall again in case 1.
Comment: For 2., it is vital that the inverse is unique. Otherwise, this is a very nice summary
Comment: Beautiful proof! Well explained!
Answer: Proof:
Let p be an odd prime number.
Consider the group $U_p=${equivalent classes of $a$|$p>a>0$, $gcd(a,p)=1$}              (equivalent relation:$a\equiv b \pmod p$, binary operation:[a][b]=[ab]).                  p is a prime,so $U_p=${[a]|$1\leq a\leq p-1$}.
Since $U_p$ is a finite abelian group, $(\prod_{1}^{p-1}[a])^2=\prod_{1}^{p-1}[a]*\prod_{1}^{p-1}[a^{-1}]=[1]$,
so $[(p-1)!]^2\equiv 1 \pmod p$,
therefore, either $(p-1)!\equiv 1\pmod p$$(!)$ or $(p-1)!\equiv -1 \pmod p(!!)$.
Now we'll show that the first statement (!) is incorrect, thus forcing the second statement to be true.
Consider $[p-1]$, we know that $o([p-1])=2$, because:
First we know that $p|p(p-2)$,
or $p|[(p-1)+1][(p-1)-1]$,
or $p|[(p-1)^2-1]$,
so $(p-1)^2\equiv 1\pmod p$,
or $[(p-1)^2]=[1]$,
or$[p-1]^2=[1]$.
Assume that there exists an element $[a],2\leq a \leq p-2$, such that $[a]^2=[1]$,
therefore $a^2\equiv 1\pmod p$,
or $p|(a-1)(a+1)$,
so $p|(a-1)$ and/or $p|(a+1).$
But $1\leq a-1 \leq p-3$,
therefore p doesn't divide $a-1$,
similarly, $p$ doesn't divide $a+1$. So the assumption is incorrect, in other words, only [1] and [p-1] are self-paired.
Therefore, consider the product: $x=[1]...[p-1]$,
Apart from $[1]$ and $[p-1]$, all other elements are paired together with their inverses,
so $x=[(p-1)!]=[p-1]\neq [1]$,
or $[(p-1)!]\neq [1]$.
So it is false that $(p-1)!\equiv 1\pmod p$.
This forces (!!)to be true,so it must be true that $(p-1)!\equiv -1\pmod p$.
This completes the proof.
Answer: I will demonstrate from left to right.
Suppose that n is a composite, then there exists a k, such that n=kq with 1<k<n, but clearly k also divides (n-2)!, so that (n-2)!=kd. Now given the congruence we have, it leaves us that
kd ≡ 1 (mod kq)
by definition we have that
kd-1=kqt (definition of congruence)
-1=kqt-kd
1=k(d-qt)
Therefore k|1 and this only occurs if k=-1 or k=1. But we had assumed that 1<k<n (contradiction), therefore n is prime.
Answer: Here is a pretty 'intuitive' proof that I thought of. Consider the set $S= \{1,2...,p-1\}$ , we can this set equipped with modulo $p$ multiplication forms a group. Suppose we multiplied all the elements in the group together by the binary operation, we have:
$$ 1 \cdot 2 \cdot 3... \cdot (p-1) \equiv p-1 \mod p$$
This is due to the fact that the group is abelian, and, the only elements which are self inverses are $\{1, p-1 \}$. All the other elements get multiplied by their inverse and sent to identity.
Proof that ${1,p-1}$ are only self inverses:
Let $k^2 \mod p =1$ for $k \in S$, then
$ \implies (k+1)(k-1) \mod p = 0$
$ \implies k+1 \mod p =0$  ,or, $k-1 \mod p =0$
meaning $k \mod p \in \{p-1,1 \}$  where the $k \mod p= -1 $ corresponds to $k = p-1$
QED
Comment: Hmm what was the downvote for..?
Comment: Not mine, but likely because it duplicates prior answers (here and elsewhere).


Compute $\int_0^{\pi /2}\frac x {\tan x} \, dx$ using contour integration

Question: How can I calculate the integral $$\int_0^{\pi /2}\frac x {\tan x} \, dx$$ with complex integration? (Contours, residue theorem, etc.) I was thinking on using the fact that $\displaystyle \tan x=\frac{e^{ix}-e^{-ix}}{i(e^{ix}+e^{-ix})}$, which implies $e^{ix}=z$. I still have not been succesful.
Comment: HI! Yes, I know. But now I am studying complex integration and I'm only interested on this method.
Comment: You can do it with real methods. Let $f(a)=\int_{0}^{0.5\pi} \frac{\arctan(a \tan(x))}{\tan x} dx$. Then $f'(a)=..$
Comment: I used the substitution x = arctan u then I represented the original integral as a double integral. Don't have time now, but thanks for your attention.
Comment: Are you sure how your statement ? Ahmed's method seems the best.
Answer: A complex-analytic solution. Here is a combination of calculus and a basic complex analysis: Perform integration by parts to sanitize the integrand:
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{\tan x} \, dx
= \underbrace{ \left[ \vphantom{\int} x \log\sin x \right]_{0}^{\frac{\pi}{2}} }_{=0}
- \int_{0}^{\frac{\pi}{2}} \log \sin x \, dx. $$
Also notice that, if $x \in (0,\frac{\pi}{2}]$ then $\log|\sin x| = -\log 2 + \operatorname{Re}\log(1 - e^{2ix})$. So
\begin{align*}
\int_{0}^{\frac{\pi}{2}} \frac{x}{\tan x} \, dx
&= - \frac{1}{2} \int_{0}^{\pi} \log |\sin x| \, dx \\
&= \frac{\pi}{2}\log 2 - \frac{1}{2} \operatorname{Re} \left( \int_{0}^{\pi} \log(1 - e^{2ix}) \, dx \right) \\
(z = e^{2ix}) \quad&= \frac{\pi}{2}\log 2 - \frac{1}{4} \operatorname{Re} \left( \oint_{|z|=1} \frac{\log(1 - z)}{iz} \, dz \right),
\end{align*}
Since $z \mapsto \frac{\log(1 - z)}{iz}$ is holomorphic in the unit disc $\mathbb{D}$ and has only logarithmic singularity on the boundary $\partial \mathbb{D}$, we can still apply the Cauchy integral theorem to conclude that the integral vanishes. Therefore we have
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{\tan x} \, dx = \frac{\pi}{2}\log 2. $$

Alternative complex-analytic solution. Use the substitution $x = \arctan u$ to write
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{\tan x} \, dx = \frac{1}{2}\int_{-\infty}^{\infty} \frac{\arctan u}{u(u^2+1)} \, du. $$
This hints us that we may use some contour integration technique, but we need to resolve the branch cut of $\arctan$. Here we give one such trick. Notice that
$$ \frac{\arctan u}{u} = \int_{0}^{1} \frac{dt}{1+u^2 t^2}. $$
Plugging this back and interchanging the order of integration, we get
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{\tan x} \, dx = \frac{1}{2}\int_{0}^{1} \left( \int_{-\infty}^{\infty} \frac{du}{(u^2 t^2+1)(u^2+1)} \right) \, dt. $$
Now we can perform contour integration to obtain that
\begin{align*}
\int_{-\infty}^{\infty} \frac{du}{(u^2 t^2+1)(u^2+1)}
&= 2\pi i \left( \underset{u = i}{\mathrm{Res}} \, \frac{1}{(u^2 t^2+1)(u^2+1)} + \underset{u = i/t}{\mathrm{Res}} \, \frac{1}{(u^2 t^2+1)(u^2+1)} \right) \\
&= \frac{\pi}{t+1}.
\end{align*}
So we have
$$ \int_{0}^{\frac{\pi}{2}} \frac{x}{\tan x} \, dx = \frac{1}{2}\int_{0}^{1} \frac{\pi}{t+1} \, dt = \frac{\pi}{2} \log 2. $$
Comment: @DavidBowman, I agree :) Solution using symmetry is certainly a thing that we would not want to miss. It is also interesting to see that this integral can be solved by Fourier series and harmonic analysis.
Comment: This might be more in line with what OP was looking for, but I'd be remiss if I didn't mention that that latter integral is solvable with real methods. https://math.stackexchange.com/questions/2381701/showing-int-limits-0-pi-log-sin-thetad-theta-pi-log2/2381711#2381711
Answer: I would like to add an alternative approach. By considering the logarithmic derivative of the Weierstrass product
$$ \sin(\theta) = \theta\prod_{n\geq 1}\left(1-\frac{\theta^2}{\pi^2 n^2 }\right) \tag{1}$$
we get:
$$ \theta\cot\theta = 1-\sum_{n\geq 1}\frac{2\theta^2}{\pi^2 n^2 -\theta^2} \tag{2}$$
from which:
$$ \int_{0}^{\pi/2}\theta\cot\theta\,d\theta = \frac{\pi}{2}+\pi\sum_{n\geq 1}\left(1-2n\,\text{arctanh}\frac{1}{2n}\right) \tag{3}$$
where the RHS of $(3)$ can be computed through summation by parts and Stirling's approximation. Indeed,
$$\begin{eqnarray*}\sum_{n=1}^{N}\left(1-n \log\frac{2n+1}{2n-1}\right) &=&N-N\log(2N+1)+\sum_{n=1}^{N-1}\log(2n+1)\\&=&N-N\log(2N+1)+\log\frac{(2N)!}{2^N N!}\\&=&\frac{\log 2-1}{2}+O\left(\frac{1}{N}\right)\tag{4}\end{eqnarray*}$$
leads to $\int_{0}^{\pi/2}\frac{x}{\tan x}\,dx = \color{blue}{\frac{\pi}{2}\log 2}$. Still another approach is to exploit Riemann sums (!!!). We have
$$ \int_{0}^{\pi/2}\theta\cot\theta\,d\theta\stackrel{IBP}{=}-\int_{0}^{\pi/2}\log\sin\theta\,d\theta=-\frac{1}{2}\int_{0}^{\pi}\log\sin\theta\,d\theta\tag{5}$$
and
$$ \prod_{k=1}^{N-1}\sin\left(\frac{\pi k}{N}\right)=\frac{2N}{2^N},\tag{6} $$
so that:
$$ \int_{0}^{\pi/2}\theta\cot\theta\,d\theta = -\frac{\pi}{2}\lim_{N\to +\infty}\frac{1}{N}\log\frac{2N}{2^N}=\color{blue}{\frac{\pi}{2}\log 2}.\tag{7}$$
At last, an efficient overkill: since $\Gamma(z)\,\Gamma(1-z)=\frac{\pi}{\sin(\pi z)}$, the equality between the RHS of $(5)$ and $\frac{\pi}{2}\log 2$ is a straightforward consequence of Raabe's Theorem on $\int\log\Gamma$.
Comment: This one is simple yet brilliant. +1
Answer: Let $z=\tan{x}$, then the integral you're looking for is $\int_{0}^{\infty}\frac{\arctan{z}}{z}\frac{1}{1+z^{2}}dz$. The integrand  is an even function of $z$. This integral is then equal to $\frac{1}{2}\int_{-\infty}^{\infty}\frac{\arctan{z}}{z}\frac{1}{1+z^{2}}dz$. Use the residue theorem to evaluate this one
Comment: How do you use the residue theorem  ? $\text{arctan}(z)$ has some branch points


Do the letters ol in a substance only indicate that the substance is an alcohol if they came at the end of the name of a substance?

Question: Do the letters ol if they are together only indicate the substance is an alcohol if they come together at the end of the name of a substance? for example,is glycerol an alcohol because the letters o and l come together at the end of its name and olives and olive oil are not alcohols because the letters o and l do not come together at the end of any words in their names?
Answer: Yes, the ending ol in a name is a good hint that the compound contains an $\ce{OH}$ group.
However, beware of trivial names:

$\alpha$-tocopherol is not an aliphatic alcohol, but a substituted phenol
mannitol does not contain one $\ce{OH}$ group, but six of them

It's getting even more confusing if you consider other languages, such as German. Benzol is the German name of benzene, which has no $\ce{OH}$ group at all. The same is true for styrol, the German word for styrene ;-)
Comment: Gotcha but one thing I do want to get clarified-if the letters o and l are together at any spot in the name of a substance other than at the end of a word in that name,that does not mean that the substance is an alcohol,right (to use my previous examples,that means olives and olive oil are definitely not alcohols,right?)
Comment: Right :) Bisab**ol**en is not an alcohol, gerani**ol** and farnes**ol** are.


Roasting Pork Butt at 215F

Question: If I wanted to roast a pork butt at 215 deg F, how long would I do this for?
In 600 pan, foiled, salt crusted on a rack.
Comment: Until it reaches the desired inner temperature. Seriously, most answers you are going to get here will point out that a good thermometer is the more valuable tool, compared to a timer. But I guess someone will be able to supply an estimate based on experience. Welcome to the site!
Comment: As @Stephie says, a good thermometer is your best way to go. However, we may be able to give you a fair estimate as a guideline if we knew the weight of the pork butt. Also, can you clarify what a "600 pan" is?
Comment: It's a six-inch hotel pan @Cindy
Answer: You want an internal temperature of at least 145°F or 63°C for rare slices up to 195°F or 91°C to get a disintegrating pulled pork.
How you get there and at what temp is very subjective. If you're oven roasting at 215°F then you're in for a 6-14 hour cook time depending on the mass of your roast. You'll get a wonderful, slow cooked meat, but prep time and temperature monitoring become vital. Sous Vide will cook at an even lower temperature; as low as 120°F over 24 hours, but I really don't like that method. Too much time for food born illness bacteria to form.
I like to make pulled pork, that's done around 195°F - 200°F internal temp, but a 7-8 lb roast will take almost 12-14 hours cooking at 215°F oven temp.
Answer: I usually cook Pork Butt (or Boston Butt) for around 20 to 25 mins per pound
This link http://m.recipetips.com/kitchen-tips/t--907/pork-cooking-times.asp has a list of suggested cooking times.
I usually do my pork at around 160f to 180f. And would worry that cooking at such a high temperature would mean the meat would be over cooked on the outer parts before the inner part was cooked, meaning some of the meat might be quite tough.
Answer: If your pork is covered in foil during cooking, you are looking at roughly between 1 and 1.5 hours per pound if you are looking to make pulled pork, 30-45 minutes per pound if you are looking to slice it.
The most important thing to note is these are just guideline times, intended to aid in planning. You should begin checking your roast as you reach the low end of the approximate time window. For example, let's say you have a 5 pound pork butt which you are going to roast in the manner you have described. This means that if you are trying to make pulled pork, you will start checking your roast at the 4.5-hour mark. You will want a skewer or similar probe to slide in and out of the meat with zero resistance. Or if you are making sliced pork butt, you will start checking your roast at the 2.5-hour mark, and your probe should be met with some slight resistance.
Answer: General food safety standards would tell you pork needs to be cooked to a internal temperature of 145F. You are probably gonna be cooking for a while if the oven only goes to 215, with the real possibility that it will not get there.
If the temprature goes up in parallel with the time going down then the temprature only needs to be adjusted to cater to the cooks patience. If you fear a dry piece of swine then some time in a brine may be great for it. Brings just typically take some of the guess work out of cooking times.
Modern pork is pretty lean, somehow lean pork has stopped being an oxymoron. So it does pretty well in a brine.

Roasting Pork Butt at 215F


Derivative of a quadratic form using the chain rule

Question: Is there a way to calculate the derivative of a quadratic form
$$
\frac{\partial x^TAx}{\partial x} = x^T(A + A^T)
$$
using the chain rule of matrix differentiation?
$$
\frac{\partial[UV]}{\partial x} = \frac{\partial U}{\partial x} V + U\frac{\partial V}{\partial x}
$$
If not, what are the cases when the chain rule for matrix differentiation is applicable?
Comment: Are you derivating with respect to a vector?
Comment: @Botond Yes, it's a vector. So basically https://math.stackexchange.com/questions/1007592/quadratic-matrix-derivation-using-chain-rule is the best we can do?
Comment: How do you define the derivation with respect to a vector?
Comment: I think the "derivative with respect to a column matrix (here, vector)" is simply the row matrix of the derivatives with respect each of the vector entries.
Is that right?
Comment: The rule you have written is not the chain rule, it is the product rule.
Answer:
Using the chain rule for matrix differentiation
  $$\frac{\partial[UV]}{\partial x} = \frac{\partial U}{\partial x}V + U\frac{\partial V}{\partial x}$$

But that is not the chain rule. That is the Leibniz (or product) rule. I assume that is what you meant. In that case the answer is yes. Here I show how to do it using index notation and Einstein summation convention.
Say our column vectors have upper indices, and our row vectors have lower indices, and our matrices have one upper and one lower index.
In this notation, matrix multiplication $AB$ is a summation over a lower index of $A$ and an upper index of $B$:
$${(AB)^{i}}_{j} = {A^{i}}_{k}{B^{k}}_{j} = {B^{k}}_{j}{A^{i}}_{k}$$
and the sum of matrices is given by
$${(A+B)^{i}}_{j} = {A^{i}}_{j} + {B^{i}}_{j}$$
Then we use the kronecker delta
$$\delta_{ij}
=\begin{cases}
0 & i \neq j \\
1 & i=j
\end{cases}$$
to define the transpose $x^{T}$ of $x$ as
$$(x^{T})_{i}=\delta_{ij}x^{j}$$
which implies
$$x^{i} = \delta^{ij}(x^{T})_{j}$$
And we define the transpose $A^{T}$ of the matrix $A$ by
$${(A^{T})^{i}}_{j} = \delta^{ik}{A^{l}}_{k}\delta_{jl}$$
Now you want
$$\frac{\partial (x^{T}Ax)}{\partial x}\tag{1}$$
which I translate to index notation
$$\left(\frac{\partial (x^{T}Ax)}{\partial x}\right)_{k} = \frac{\partial (x^{T}Ax)}{\partial x^{k}} = \frac{\partial [(x^{T})_{i}{A^{i}}_{j}x^{j}]}{\partial x^{k}}$$
and then use the product rule
$$=\frac{\partial (x^{T})_{i}}{\partial x^{k}}{A^{i}}_{j}x^{j}
+(x^{T})_{i}\frac{\partial {A^{i}}_{j}}{\partial x^{k}}x^{j}
+(x^{T})_{i}{A^{i}}_{j}\frac{\partial x^{j}}{\partial x^{k}} \tag{2}$$
The partial derivative in the first summand on the right hand side is
$$\frac{\partial (x^{T})_{i}}{\partial x^{k}}
= \frac{\partial (x^{m}\delta_{mi})}{\partial x^{k}}
= \frac{\partial x^{m}}{\partial x^{k}}\delta_{mi}
= \delta^{m}_{k}\delta_{mi}
= \delta_{ki}$$
where I used

The definition of the transpose $(x^{T})_{i} = x^{m}\delta_{mi}$
$\delta_{mi}$ is constant
$\frac{\partial x^{m}}{\partial x^{k}} = \delta^{m}_{k}$

The second summand vanishes, because $\frac{\partial {A^{i}}_{j}}{\partial x^{k}} = 0$ since $A$ does not depend on $x$.
Using all this, equation $(2)$ reduces to
$$=\delta_{ki}{A^{i}}_{j}x^{j}+(x^{T})_{i}{A^{i}}_{j}\delta^{j}_{k}\\
=\delta_{ki}{A^{i}}_{j}\delta^{jl}(x^{T})_{l}+(x^{T})_{i}{A^{i}}_{k}\\
={(A^{T})^{l}}_{k}(x^{T})_{l}+(x^{T})_{i}{A^{i}}_{k}\\
={(A^{T})^{i}}_{k}(x^{T})_{i}+(x^{T})_{i}{A^{i}}_{k}\\
=(x^{T})_{i}\left({(A^{T})^{i}}_{k}+{A^{i}}_{k}\right)\\
=(x^{T})_{i}{\left(A^{T}+A\right)^{i}}_{k}\\
=\left(x^{T}(A^{T}+A)\right)_{k}\\
$$
Where I have used (starting from the second equal sign)

$x^{i} = \delta^{ij}(x^{T})_{j}$
The definition of the transpose ${(A^{T})^{l}}_{k} = \delta^{jl}{A^{i}}_{j}\delta_{ik}$
Renaming the dummy index $l$ to $i$
Factorize $(x^{T})_{i}$
Sum of matrices
Matrix multiplication (lower index of $x$ and upper index of $A^{T}+A$)

Hence
$$\left(\frac{\partial (x^{T}Ax)}{\partial x}\right)_{k} = \left(x^{T}(A^{T}+A)\right)_{k}$$
or, without the indices
$$\frac{\partial (x^{T}Ax)}{\partial x} = x^{T}(A^{T}+A)$$

If you want to use purely matrix notation, without the indices, I guess you could say that
$$\frac{\partial x^{T}}{\partial x}$$
is an operator that transposes the column vector immediately on its right. Then  you could take equation $(1)$ and proceed as follows
$$\frac{\partial (x^{T}Ax)}{\partial x}
= \frac{\partial x^{T}}{\partial x}Ax
+ x^{T}\frac{\partial A}{\partial x}x
+ x^{T}A\frac{\partial x}{\partial x}\\
= (Ax)^{T} + x^{T}A\\
= x^{T}A^{T} + x^{T}A\\
= x^{T}(A^{T} + A)$$
But one (at least I) wouldn't have seen and understood this behaviour of $\frac{\partial x^{T}}{\partial x}$ were it not for the calculation in index notation.

I'll have to rectify: there is a way to see that behaviour of $\frac{\partial x^{T}v}{\partial x}$. If $v$ doesn't depend on $x$, we have
$$\frac{\partial x^{T}v}{\partial x}
= \frac{\partial x^{T}}{\partial x}v$$
But $x^{T}v = v^{T}x$, hence
$$\frac{\partial x^{T}v}{\partial x}
= \frac{\partial v^{T}x}{\partial x}
= v^{T}\frac{\partial x}{\partial x} = v^{T}$$
Thus, we conclude
$$\frac{\partial x^{T}}{\partial x}v = v^{T}$$
Similarly, we can check that
$$v^{T}\frac{\partial x}{\partial x^{T}} = v$$
Answer: Background info: Recall that if $f:\mathbb R^n \to \mathbb R^m$ is differentiable at $x_0 \in \mathbb R^n$, then $f'(x_0)$ is an $m \times n$ matrix which satisfies
$$
f(x) \approx f(x_0) + f'(x_0)(x - x_0).
$$
The approximation is good when $x$ is close to $x_0$.

Derivation of product rule:
Suppose that $f:\mathbb R^n \to \mathbb R^m$ and $g:\mathbb R^n \to \mathbb R^m$ are differentiable at a point $x_0 \in \mathbb R^n$, and that $h:\mathbb R^n \to \mathbb R$ is defined by
$$h(x) = \langle f(x), g(x) \rangle
$$
for all $x \in \mathbb R^n$. Let's quickly derive a product rule to compute $h'(x_0)$. If $x$ is close to $x_0$, then
\begin{align}
h(x) &= \langle f(x), g(x) \rangle \\
&\approx \langle f(x_0) + f'(x_0)(x - x_0), g(x_0) + g'(x_0)(x - x_0) \rangle \\
&\approx \langle f(x_0), g(x_0) \rangle + \langle f'(x_0)(x - x_0), g(x_0) \rangle + \langle f(x_0), g'(x_0)(x - x_0) \rangle\\
&= h(x_0) + (g(x_0)^T f'(x_0) + f(x_0)^T g'(x_0))(x - x_0).
\end{align}
Comparing this with the equation
$$
h(x) \approx h(x_0) + h'(x_0)(x - x_0),
$$
we see that
$$
\tag{1}
\bbox[yellow,5px]
{
h'(x_0) = g(x_0)^T f'(x_0) + f(x_0)^T g'(x_0).
}
$$
This is our product rule.

Solution:
Now let's consider the special case that $f(x) = x$ and $g(x) = Ax$, where $A$ is a real $n \times n$ matrix, so that
$h(x) = \langle x, Ax \rangle$. The derivatives of $f$ and $g$ are given by
$$
f'(x_0) = I, \qquad g'(x_0) = A.
$$
(Here $I$ is the $n \times n$ identity matrix.)
Using equation (1), we see that
\begin{align}
h'(x_0) &= (A x_0)^T I + x^T A \\
&= x_0^T(A^T + A).
\end{align}
This is what we wanted to show.
Comment: How do you go from $\langle f'(x_0)(x-x_0),g(x_0) \rangle$ to $g(x_0)^{T}f'(x_0)(x-x_0)$?

I get $$\langle f'(x_0)(x-x_0),g(x_0) \rangle = [f'(x_0)(x-x_0)]^{T}g(x_0) = (x-x_0)^{T}f'(x_0)^{T}g(x_0) = [g(x_0)^{T}f'(x_0)(x-x_0)]^{T}$$
but I don't know how to continue from there.
Comment: @JackozeeHakkiuz In that case I used $\langle a,b\rangle = b^Ta$ rather than $a^T b$.
Comment: Oh snap. Of course. Other way to see it is that $g(x_0)^{T}f'(x_0)(x-x_0)$ is just a scalar and hence it is equal to its transpose. But of course the commutativity of the inner product is much simpler.


Can I ask about career in industry?

Question: I want to ask about career change: going from a postdoc researcher in the field of biomedical devices into industry. Could I ask it here? This is the only place that has the tag related to biomedical devices. Please advice. Thanks.
Answer: Career and education advice is off-topic for the site.  It ends up being either primarily opinion based or of insufficient use to future visitors or both.
Thanks for asking in advance on meta.

Can I ask about career in industry?


CPU usage of a kernel module

Question: I need to know CPU usage of a particular kernel module (e.g., iptable_mangle) in Linux (Fedora). I know that top or mpstat shows system CPU usage which is actually total CPU usage in the kernel space. Is there any option to know CPU usage of a particular kernel object?
Comment: I think there is no way, unless that module starts a kernel task (or kernel thread).
Comment: I know what is kernel thread, but not sure what kernel task is, though. I do not have control on the kernel module of my interest either to start a kernel task/thread. Thanks...
Comment: Then your question might not have any sense.
Answer: Sorry to disappoint, but there is no way to accomplish what you want -- not because Linux doesn't have the capability, but by definition:
A module can "plug-in" to the kernel of two general ways: Either by installing a callback (e.g. proc or sys file, device, etc), or starting a kernel thread. In your case, iptable_mangle plugs in by setting callbacks on iptables/netfilter. This means the module code is executed as part of the network stack (in ksoftirqd context, to be more accurate).
If this had been in a kernel thread context, Linux keeps statistics. But for callbacks, that is not the case. The thread which does end up executing the module code does a lot of other things, so just isolating your module code is impractical (unless, of course, you're in possession of the source, and then you can add timing statements very easily).
One partial solution would be to use the kernel ftrace mechanism - this allows for function call tracing in the kernel - it's unbelievably powerful, and can show you statistics as per particular functions. It's not exactly what you want, but it's as close as you'll get.

CPU usage of a kernel module


Meeting friends at Heathrow in transit

Question: My Canadian cousin is travelling via London with a 5 hour stop over, landing at T3 and exiting T5.  Can I meet her for a coffee landside in T5? She won't need a visa.
Comment: thank you.  I checked the times more carefully and she has 3 hours 50 mins so that hopefully gives us 1.5 hours for coffee.
Comment: Check in first, ask how long the wait for security is (it's T5, it can be brutal!) and then have coffee. I do not think you'll have 1.5hrs but who knows.
Answer: I do not exactly see the problem here. What are you asking? Is five hours enough for your cousin to go through UK immigration, transfer between the terminals, check in again and go through security? Sure, that's plenty. Yesterday someone asked whether 2:35 is enough and I went through and showed it's tight but 5 hours is aplenty. What other concerns are there? Is she going to be allowed in the country for such a short time? As she doesn't need a visa, there really can't be a problem, just tell the truth. I have entered the UK for a similarly short period of time to run to Harrods to pick up gifts (my sister-in-law is particular to a fudge only available in the dessert hall) and noone bat an eye. What else... Are you allowed to enter the Heathrow terminals if you do not intend to fly? Sure.

Meeting friends at Heathrow in transit


Recover Firefox bookmarks after Linux Mint 16 reinstallation

Question: I had Linux Mint 16 KDE installed alongside Xubuntu 13.10. I messed up partitions and had to reinstall Mint and both the OSs were booting fine after reinstallation. Now as expected all of my Firefox bookmarks were erased. Is there any way to recover those Firefox bookmarks?
Answer: Do you have your <code>.mozilla</code> directory from your old installations home directory? If yes, just copy that directory to your new home and change its ownership by a command like this:
<code>~$ chown -R USER:root ~/.mozilla
</code>
And after this you will have all of your old Firefox configuration and also your old bookmarks.
Comment: I installed it on the same partition where I had installed it the last time
Comment: Did you removed old home directory? If yes there is no chance to retrieve that data again. Other possibility for you in such a situation is using Firefox's sync system or some backup software that upon your question I think you have not used neither of them!


Force set a string as an SELinux context of a file

Question: I wonder if it's possible to force set a given string (e.g. u:object_r:blah_blah_blah:s0) as the SELinux context of a file.
Basically I'm going to root an Android x86 installation by placing files manually on a soft boot Ubuntu. However chcon doesn't allow me to set stuffs like u:object_r:system_file:s0 because such a context is non-existent on Ubuntu. Actually I can use the --reference-file=X option but it would be better if I can manually type the string.
Answer: sudo setfattr -n security.selinux -v u:object_r:system_file:s0 'path/fileName'

you may need to install attr first and see official docs


I took Celpip General test in 2021. My scores are: Speaking 8, Reading 8, Listening 8, Writing 7. What is my overall CLB score?

Question: I'm confused about CLB scores. As, neither IRCC nor Celpip official websites do not have any information regarding my question. I cannot understand either I have CLB 7 or CLB 8 ?
Comment: What programs are you applying/interested in? There is no "overall" score for CLB and it does not matter. Different programs have different requirements, which will specify what is the minimum is for each or all competencies (e.g. CEC), or consider each competency separately (e.g. for EE points).
Comment: @xngtng I am interested in Prince Edward Island's PNP program. When filling out the application, it asks you to provide your overall CLB lvl, which confuses me.
Comment: PEI uses the lowest score of each ability.
Answer: For most federal immigration programs, the requirement is formulated as a minimum score required for each language ability (speaking, reading, listening writing).
For example, the Federal Skilled Worker Program requires CLB 7 as "minimum level for all four abilities". Thus, your score would satisfy this requirement if you are applying under FSWP stream.
Some programs do not require the same score for all abilities, as is the case for the Federal Skilled Trades Porgram. In that case, CLB 5 is required as the minimum level for speaking/listening, and CLB 4 for reading/writing.
For CRS points, each language ability obtains its own points on the grid. For your score (if you are unmarried and English is chosen as the first official language), you would get 23 points for each of speaking/reading/listening and 17 points for writing. That is, in total, 23 x 3 + 17 = 86 points would be awarded to you in the CRS based on your language test results.

I cannot understand either I have CLB 7 or CLB 8 ?

So this does not really matter for immigration. You have to verify the score for each of the abilities against the requirement as it is formulated.

Provincial programs may have different formulations of the language requirements. You will have to check how the requirement is expressed for the programs you are interested in.
Note that indeed IRCC (federal government) cannot help you with questions with provincial programs (at least not until the federal stage), questions need to be directed to the provincial department responsible.
For PEI, the instruction for Express Entry says

The lowest score achieved in the 4 skills (Reading, Writing,
Speaking, Listening) is your score. For example if you have a 7 in Reading, Writing and Speaking but a 5
in Listening your CLB will be 5.

So your score would be 7 as defined for PEI Express Entry programs.


What is the physical meaning/concept behind Legendre polynomials?

Question: In mathematical physics and other textbooks we find the Legendre polynomials are solutions of Legendre's differential equations. But I didn't understand where we encounter Legendre's differential equations (physical example). What is the basic physical concept behind the Legendre polynomials? How important are they in physics? Please explain simply and give a physical example.
Comment: http://en.wikipedia.org/wiki/Legendre_polynomials#Applications_of_Legendre_polynomials_in_physics
Comment: There is a very definite physical notion behind Legendre polynomials: a rank-$l$ Legendre polynomial corresponds to a spin-$l$ representation of the orthogonal group $SO(3)$. These are the usual traceless, symmetric tensors of rank $l$ we use in field theory all the time. If in QM you scatter two spinless particles, you measure the angular distribution and find that it is described by $P_2(\cos \theta)$ (for example), then you can be sure that the particles are exchanging a spin-2 resonance.
Comment: These polynomials are not really physics, they are simply a useful mathematical tool that appear in the solutions to many physical problems with spherical symmetries. I think the question is fine *because* they do come up a lot.
Comment: @Vibert That is a physical notion attached to the polynomials, but the math exists independently of the physics. The distinction here is that physicists must learn the math but mathematicians can know the polynomials while being ignorant of the physics.
Comment: I think the OP is really asking 'what symmetries are required of a system for the legendre polynomials to arise as the solution'. Which was what @peanut_butter (cute name) has elaborated on
Answer: The Legendre polynomials occur whenever you solve a differential equation containing the Laplace operator in spherical coordinates with a separation ansatz (there is extensive literature on all of those keywords on the internet).
Since the Laplace operator appears in many important equations (wave equation, Schrödinger equation, electrostatics, heat conductance), the Legendre polynomials are used all over physics.
There is no (inarguable) physical concept behind the Legendre polynomials, they are just mathematical objects which form a complete basis between -1 and 1 (as do the Chebyshev polynomials).
Comment: I disagree with the last statement (see my comment above). Legendre polynomials correspond to $SO(3)$ (tensor) representations that are well-known, even to undergraduates. Just look up the partial wave expansion in a QM textbook. The Chebyshev polynomials play the same role, but in two dimensions.
Comment: If you do partial wave expansion, you do that because the Legendre polynomials are eigenfunctions of the $\vartheta$ part of the Laplace operator. The connection to the $SO(3)$ representation is interesting though.
Comment: Yes, that is exactly what I mean: Legendre polynomials are eigenfunctions of the Laplacian on $S^2$, and indeed they correspond to representations of $SO(3)$ - that's not an accident. You are free to think that this fact isn't important, but it's the 3D equivalent of classifying the representations of the Lorentz group - you do agree that it's meaningful to talk about scalars, spinors, currents, tensors etc. in particle physics, right?
Comment: I know too little about particle physics to give a qualified answer. But I think we disagree on the more fundamental question of how "physically" you interpret a mathematical object, which is more of a philosophical question.
Answer: Here's my 30 seconds hand waving argument for
"Why is it that we always encounter new special functions $f_n$ with orthogonality relations??"
$$\int f^*_n\cdot f_m=\delta_{mn}$$
Super broadly speaking, in physics we dealing with the dynamics of certain degrees of freedom. These often employ smooth symmetries, that is we're dealing with Lie groups, which are also manifold in themselfs. Take e.g. the Laplacian $\Delta=\nabla\cdot\nabla$ and the associated symmetries $R$ acting as $\nabla\to R\nabla$ in such a way that that $R\nabla\cdot R\nabla=\nabla\cdot\nabla$.
Now in case one is dealing with a "rotation" in the broadest sense of the word, one often has a compact manifold, where we can savagely define things like integration on the group, and these symmetry groups also permit pretty unitary matrix representations. That is there are necessarily matrices $U$ with
$$\sum_kU_{kn}^*U_{km}=\delta_{mn},$$
and well, the matrix coefficients $U_{kn}$ must be some complex functions.
To put it short, special functions are representation theory magic.

@zonk: Yes, it's the default theory. But of course, you only see the direct relation to special functions if you take the abstract Lie group theory and actually sit down and write down the matrices in some base. E.g. for the rotation group matrices $D$, you find
$$
\begin{array}{lcl}
D^j_{m'm}(\alpha,\beta,\gamma)&=&
 e^{-im'\alpha }
[(j+m')!(j-m')!(j+m)!(j-m)!]^{1/2}
\sum\limits_s \left[\frac{(-1)^{m'-m+s}}{(j+m-s)!s!(m'-m+s)!(j-m'-s)!} \right.\\
&&\left. \cdot \left(\cos\frac{\beta}{2}\right)^{2j+m-m'-2s}\left(\sin\frac{\beta}{2}\right)^{m'-m+2s} \right]
 e^{-i m\gamma}
\end{array}.$$
Very sweet, right? Now here you have the Legendre Polynomials $P_\ell^m$
$$
D^{\ell}_{m 0}(\alpha,\beta,0) = \sqrt{\frac{4\pi}{2\ell+1}} Y_{\ell}^{m*} (\beta, \alpha ) = \sqrt{\frac{(\ell-m)!}{(\ell+m)!}}  \, P_\ell^m ( \cos{\beta} ) \, e^{-i m \alpha }
$$
so that
$$  \int_0^{2\pi} d\alpha \int_0^\pi \sin \beta d\beta \int_0^{2\pi} d\gamma \,\,
  D^{j'}_{m'k'}(\alpha,\beta,\gamma)^\ast D^j_{mk}(\alpha,\beta,\gamma) =
  \frac{8\pi^2}{2j+1} \delta_{m'm}\delta_{k'k}\delta_{j'j}.$$
Comment: That is a very interesting view/line of argument. Do you find this in standard Lie groups literature?
Comment: ...and how do the $f$'s relate to the $U$'s?
Answer: Rather than thinking about the abstract orthonormal basis of the Legendre polynomials $P_l(x)$, I find it easier to visualize these polynomials by looking at $P_l(\cos\theta)$. These are simply the Spherical Harmonics with azimuthal symmetry:
$$ Y_l^{m=0} = n_l P_l(\cos\theta)$$
where $n_l$ is a normalization factor that only depends on $l$. In this beautiful image of the spherical harmonics on Wikipedia by Inigo.quilez, the $P_l(\cos\theta)$ correspond to the center column of the image ($m=0$). Note the symmetry about the $z$-axis.

These are come up very often in physics, for example, while solving the Laplace equation ($\nabla^2\Phi = 0$) with azimuthally symmetric boundary conditions.
Answer: If you want to know why computational physicians like Legendre Polynomials, the answer is rather simple. As the other people has already pointed out, the Legendre Polynomials are orthogonal, they can be a very good basis for many applications. For example, if one tries to construct a function which fits the experiment or simulation data within the estimate error-bar and interpolates between the limited number of available data points, the Legendre Polynomials can be a very useful, so does the Chebyshev polynomials. The function constructed from the the Legendre Polynomials does not suffer the Runge's problem.


Custom solution in Docx4J for converting Docx to HTML

Question: I have this requirement to convert multiple DOCX files into HTML format and if possible into RTF
Docx4j seems to be a good java library for doing this.
Using the HtmlExporterNG2.html method is not necessarily giving out the desired result for me. So I am thinking of modifying the stylesheet that is extracted from the docx file and then using it for this conversion, as all these docx files have varying formatting and hence cannot use a standard stylesheet.
Am I correct in thinking that runtime tinkering with the stylesheet will work? and what are the important thigs I should be aware of?
I am using it as a standalone java application with java version 6.
My query might be a bit vague but am seeking for a right direction at this juncture.
Comment: What is your "desired result"? Do you want to ignore the formatting in the input docx, or override it in certain respects?
Answer: @Jason I want to ignore certain formatting in the input docx. As the converted html had some extra spacing or junk characters etc added into it.
As a solution I created a new xslt. For most, it is very similar to the one in the sample but with few minor tweaks. The new xslt now converts the input docx file into a properly formatted(as I need) html for IE8, Mozilla or Chrome.


Is D-Wave advantage a noisier hardware compared to the older D-Wave 2000?

Question: Is D-Wave Advantage noisier hardware compared to the older D-Wave 2000? There is any measure of the noise within the vendor's whitepapers, the quantum annealer analogue of e.g. decoherence time, fidelity in gate-based quantum hardware?
Answer: Because of higher qubit counts and greater connectivity, the Advantage QPU can hold
inputs that are typically between 2 and 4 times larger than those that fit on the 2000Q QPU. Chain lengths on Advantage QPUs are generally half as long as those on the 2000Q. For a problem of Random Cliques The Advantage system significantly outperforms the 2000Q system. In this test the win percentage for the Advantage QPU was 45.83 percent, over six times higher than the win percentage of 6.67 percent for the 2000Q QPU.
Overall the Advantage system performs better than the 2000Q , but on the noise front, the 2000Q is still considered as the low noise dwave's qc.
You can find the detailed report between the comparison here


unauthorized usage of power, Locating source of excessive energy use

Question: my new neighbor has had many visitors since moving and now has unwanted visitors outside bv who are loud and trespassing and i believe they had used my outside power outlet. I'm asking if it is possible to determine if power was used from that outlet
Comment: Maybe your new neighbor is doing AirBNB.  Call the city manager and ask if that's legit.
Comment: Put an interior switch on your exterior outlets. Perhaps a spiky hedge or fence between yards is justified. 6' fences are not that tough to put up if you bother reading the internet first. It'll cut down on the noise too.
Comment: Your exterior outlets are probably on a Separate Circuit Breaker , turn that breaker off. Also to answer your question - you cannot go into the past and find out if those outlets were used. You can however install a monitor in your service panel .. but in reality - turning the breaker off will stop the usage.
Answer: Without any additional equipment (a clamp-on ammeter), it's not possible to determine how much electricity was used from one specific outlet / fixture. And, even then, it won't be able to determine how much was used in the past, only what's used once the equipment is installed.
Even so, it's not likely the neighbors used a significant amount of electricity from a single receptacle. Assuming you're in the US, it's 120V 15A, which is 1800W max - run that for an hour, and that's only 1.8 kWh (anywhere from ~20 to ~50 cents, depending on your rates). 5 hours a night for 30 nights a month, and it's "only" ~$30 difference in your electric bill - probably rather insignificant with AC running during the summer. And that's a worst-case scenario; if they are actually using it it's likely not anywhere near the 15A limit and so cost is much less.
If your electric bill is unusually / unseasonably high, check your HVAC first, followed by your water heater (if electric).


What is an Intuitive example of a Gauge Symmetry?

Question: Can anyone give an intuitive example of what a gauge symmetry is? I am new to this concept and would like to understand it better!
Comment: A nice reference that ties together some of the answers below https://math.ucr.edu/home/baez/torsors.html
Comment: You might find Maldacena's economics analogy intuitive https://arxiv.org/abs/1410.6753
Comment: [Wikipedia](https://en.wikipedia.org/wiki/Introduction_to_gauge_theory#Electromagnetism)
Answer: Another example of of a Gauge Symmetry can be found in the basic $V=mgh$.
Here you can have your "ground" anywhere you want. This freedom reflects the key idea in gauge theory.
Comment: Thank you. Can you think of this symmetry as an analogy with @MrDBrane's answer?
Comment: It gets a bit messy sometimes because the gauge groups have different dimensions. The "gauge fields", which reflect the gauge freedom can be of different forms, so you can always exchange interpretations.
Comment: Yes. In the particular case of QED, the freedom to choose an electromagnetic gauge corresponds to the fact that you should come up with all the same object level predictions -- collisions of particles, for example -- no matter your path through spacetime, even if you accelerate.
Answer: A Gauge Symmetry (not talking about large gauge transformations) refers to mathematical symmetries that are not physical but rather redundancies in our formulation.
It is a quite rich subject, but I will limit myself to intuitive answers.
Consider the magnetic field. We know that it is given by the curl of a vector potential
$$\mathbf{B = \nabla \times A}$$
Now notice that if you add a curl-less to A, the magnetic field stays the same, that is the magnetic field is insensitive to curl-less terms. This means that we have a symmetry where any transformation of A in the form of $\mathbf{A} \rightarrow \mathcal{A} + \nabla f$, where f is just a scalar function, leaves our physics invariant.
In physics it is efficient and effective to describe these symmetries by gauge groups, so groups that describe these redundancies, that is groups under whose action our model stays physically the same. The standard Model is described by $SU(3)\times SU(2) \times U(1) $, which all describe different aspects of the theory.
Gauge theory is a very rich subject that has shaped the way we approach physics.
Reading Recommendations:
Large Gauge Transformation (Gauge Transformations that cannot be thought of as redundancies.
Yang Mills (Wikipedia)
Introduction to Gauge Theory for Beginners
Comment: To add to this point: note that we usually explicitly do experiments that "feel" the magnetic field, but we never seem to have direct access to the magnetic potential itself*; when we write things in terms of magnetic potential there is a redundancy in our description (this is the gauge symmetry). (*ignoring Aharanov-Bohm type subtelties)
Answer: Take a potential that only depends on the distance of an object's center from a center point. Then you can consider a rotation of your object. If this transformation acts locally, so the rotation for example is dependent o. You spacetime location, then you have a gauge symmetry and the rotations are gauge transformations.
Comment: As it's currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer).
Answer:
A toy model of a gauge theory is
$$ Z ~\propto~\int \! dx ~dy~ e^{iS(x)}, \tag{71.8}$$
cf. Ref. 1. The action $S(x)$ and the path integral $Z$ are invariant under a gauge transformation
$$y\quad\longrightarrow\quad y^{\prime}~=~y+f(x).$$
The $y$ variable is redundant/unphysical. See Ref. 1 for further details on how to gauge-fix the theory.

In more realistic gauge theories, it is more difficult (if not impossible) to cleanly separate physical and unphysical DOF, but the underlying idea is the same.

References:

M. Srednicki, QFT, 2007; chapter 71. A prepublication draft PDF file is available here.


Displaying debug line in custom raytracer implementation

Question: Not sure if I should post this here or on the Math forum, but I will try my luck.
Some background. I made my custom raytracer. The processing happens purely on the CPU for now, no GPU interaction whatsoever. It supports basic Phong shading and X levels of reflections.

I started fiddling with some ideas now and I realized that I need a way to display debug lines so that I could debug what I am doing, at least to some extent.
I thought of this solution:
Debug line is a constrained plane, which means that it is basically a rectangle, with pixels having their normal always facing the camera. The line is defined by a start point, magnitude, direction, and thickness. Based on these properties I should be able to calculate everything I need to get it displayed.
Below is some pseudocode for checking if my ray is intersecting this debug line.
Defined in the line initialization are:

startPosition (where the line starts)
magnitude (lenght of the line)
direction (line direction)
thickness (thickness of the line)

Code:
function isIntersecting(_originRay, _rayOrigin)

    ray = _originRay.Normalize(); // Ray coming from the camera
    spreadVector = direction.Cross(ray).Normalize(); // Vector showing the line width direction
    lineNormal = ray * (-1); // Debug line pixel always faces the camera directly

    // Plane intersection
    denominator = ray.Dot(lineNormal);
    if (denominator > 0) // Plane not visible
        return false;

    hitDistance = (startPosition - _rayOrigin).Dot(lineNormal) / denominator;
    hitPosition = _rayOrigin + (ray * hitDistance); // Get the intersection point in 3D space

    widthVector = spreadVector  * thickness;
    hitPositionTranslated = hitPosition - startPosition;

    if (hitPositionTranslated.Dot(widthVector) > widthVector.Length() || hitPositionTranslated.Dot(widthVector) < 0) // Ray hitting the plane outside the constrained area
        return false;

    // Code for checking height here - Not putting it cause width is not working at first place

    return true;

I get this when using pretty great width (should be ~100px), but it is thin - looks like the algorithm is not constraining the width correctly:

I am obviously doing something wrong here. Any kind of help would be much appreciated!
Answer: Found the problem. The dot product is the length of the projected vector multiplied by the length of the vector we are projecting into. That means that I needed to divide the dot product result by the length of the width vector to actually have a valid check:
hitPositionTranslated.Dot(widthVector) / widthVector.Length()


Two tags for Mahabharata?

Question: There are two tags for Mahabharata mahabharata and mahabharatha (only one post). Please suggest whether we should merge the posts related to these tags or make them synonyms to each other. I am also not sure which sounds correct.
Answer: The correct one is Mahabharata and only one question was tagged with mahabharatha and now I've edited it with the real tag, daily cron job will get rid of the invalid tag.
Comment: @TheDictator Site is just started, wait for some time, users like Ankit, Dharmaputhiran etc are editing wiki tags, will raise a question on meta soon if I don't see major tags edited :)
Comment: Do you have authority to create/Delete tags? If yes then please add tags with some sort of descriptions.
Comment: @TheDictator Sorry?
Comment: Sorry for my bad english
:D
Comment: @TheDictator yes I do have but I won't make, its like, we can make 10000 tags, so let the user create tags when they ask questions if they don't find any, if there are synonyms or useless tags, post a question on meta and I'll take care of them
Comment: But atleast we can make some of the popular ones like Mahabharata,Ramayana,shiv,krishna,vishnu,etc... so in suggestions it will come with their Some sort of description. As many times i have seens that mostly south indian users to that they are adding additional "h" or "t" in each and every word. So this will prevent from this kind of Mistakes.
Comment: @TheDictator I am not a professional so I won't be editing wiki tags, it would be better if users with accurate knowledge edit them out.
Comment: You can take help of other mods as well as jabahar and other leading users as they are masters in this. Its just an opinion. Rest is upto you.

Two tags for Mahabharata?


Is it possible to track browsing history inside a wireless network

Question: I'm using Internet, shared through wireless network. Now, is there any possibility to track me (i.e. my browsing history) from another computer of same network using "Wireshark" or other tracking software? If so, how to block this.
Comment: simple answer is yes they can track what you are browsing. also, dependent upon the level of control they have over the network gateway / your pc (e.g. via group policy on a domain) they can also break your SSL connections and read them (MiTM / SSL Intercept). Your best bet is either to tunnel out via a secure proxy / VPN or to use a hostname on your pc that can't be traced back to you individually.
Comment: Note, however, that due to the very high rate of packet loss in wifi networks, you may not get all messages, because packetx will only be retransmitted until the destination acknowledge them. If you failed to receive some of them before that, you won't see those packets.
Answer: Any other computer in the same wireless network can receive the packages you are sending out and that are sent to you. The relevant data contained in such a package is the source and the target address and the actual data. This makes it possible to see what other computers you are communicating with.
Lets take your example of the browsing history. If you enter an URL in your browser, lets say http://google.com a request is sent out via your network. Every other wireless client does can receive the package as it is sent out in all directions as radio signal. This package can be read using tools like Wireshark. The person reading it would see that the request goes to IP 184.108.40.206. It is very easy to find out what website this IP belongs to.
If you are not using SSL (https) the data of the package can also be read. In our google example it contains e.g. your search request. If you login on a site that doesn't use https, even your username and password are contained easily readable in that data. As James already stated in the comments it is even possible to attack SSL secured connections.
To avoid this you can use a tunnel (e.g. SSH, VPN). The attacker could still see you communicating with the tunnel endpoint, but all the other information will be encrypted.
Answer: To elaborate further on my comment
Wireless networks are inherently insecure - someone does not even need to be logged into the network to intercept the packets that are broadcast (think man in the parking lot with a cantenna). It's not just the people on the network to worry about.
As a side note and in addition, someone running an ethernet card in promiscuous mode on a wired connection will intercept any packets they can see (by default cards are set to ignore anything not relevant to them but this can be changed).
Dependent upon the level of control they have over the network gateway / your pc (e.g. via group policy on a domain) they can also break your SSL connections and read them (MiTM / SSL Intercept). This is traditionally used by enterprises for deep packet inspection at the firewall (sometimes using dedicated equipment) under the auspices of preventing malware / trojan communication externally through encrypted connections (e.g. using Cryptcat).
Your best bet is either to tunnel out via a secure proxy / VPN or to use a hostname on your pc that can't be traced back to you individually. Alternatively, if you are super-paranoid, only do your browsing on a network you trust and via a cabled connection.


Is there any generalised "Lorentz" transformation for a non-inertial moving frame?

Question: I am looking for a formula to calculate the coordinate transformations—let's say for an accelerated moving frame or a rotating frame.
I would be very happy if you could quote a book or PDF that contains that formula.
Comment: https://en.wikipedia.org/wiki/Rindler_coordinates
Comment: To clarify: What do you mean by frame? In this context, the word frame typically refers to a coord system that has somehow been associated with particular observer(s), but in general, coord systems have nothing to do with observers. Coord systems and observers are separate concepts, unfortunately conflated with each other in some introductions to special relativity. We can use one coord system (e.g., Minkowski) for all observers. The only reason to switch is for convenience. Are you asking which coord systems might be more convenient for scenarios involving accelerating/rotating observers?
Comment: Related: [What is the proper way to explain the twin paradox?](https://physics.stackexchange.com/q/242043/). John Rennie derives a formula for time dilation in non-inertial frames; it is not a transformation though.
Comment: @ChiralAnomaly This is the problem, I am trying to solve. We have 2 observers. There is a constant acceleration between both observers. Observer 1 sees a particle moving with a trajectory of x(t). Which trajectory will see observer 2?
Answer: To transform between coordinate systems you need to be able to express the new coordinates $(t', x', y', z')$ in terms of the original coordinates $(t, x, y, z)$. There's no general formula for this, it entirely depends on how the coordinate systems are related: that is, in general $t'$ is a function of all of $t, x, y, z$ and it need not even be a linear function (e.g. when going from Cartesian coordinates to polar coordinates).
The Lorentz transformation is a particularly simple case (it corresponds to a kind of rotation in spacetime). But if either coordinate system is non-inertial then the transformations in general become more complicated, e.g. for rotating coordinate systems you're dealing with polar coordinates that vary with time. Convenient coordinate systems have been developed for a few of these special cases (Born coordinates for rotating frames, Rindler coordinates for linearly accelerating frames) but for the general case you have to do the hard work of explicitly defining coordinates for the non-inertial frame in terms of some other easier to handle coordinate system.
Answer: There isn't one. Lorentz transformations deal with boosts and rotations of four-vectors. There is no acceleration parameter involved in defining the transformation. If such a transformation exists, it won't be called Lorentz.
However, nobody stopped us from Lorentz transforming from a frame with velocity $v$ to a frame with velocity $v+dv$ - the change is too small, we can hop. But if you keep hopping, you can reach the accelerating frame.  This is essentially what we do in a derivation of Rindler coordinates. However, even that involves successive Lorentz transformations between intermediate frames (separated differentially) to transform into the non-inertial one - there is no one big transform, to my knowledge.
Comment: In that case would it make sense to replace the ∆ with differentials, which would lead to dt'=γ(t)(dt-v(t)/c^2*dx) and dx'=γ(t)(dx-v(t)dt)??

Is there any generalised “Lorentz“ transformation for a non-inertial moving frame?


Sharepoint Organization Chart / Browser

Question: How can I remove from organization chart and from organization browser, employees with specified AD group or email address e.g. email@example.com. Right now my chart is showing everyone. As I know I can limit results by create filter in user profile service, but in this case I need to limit results only for webparts.
Sharepoint 2010
Answer: There isn't a way to limit the organizational chart web part itself.  It will display everyone who has a profile in the User Profile service application.  If a user doesn't have a manager or any listing them as their manager, they shouldn't show up in anyone else's organizational chart.  That's about the only thing you could do.

Sharepoint Organization Chart / Browser


Sandisk Extreme Class 10 SD Stopped working?

Question: I own a Sandisk Extreme 4GB Class 10 SD (30mb/s), which used to work fine in my Raspberry Pi (booted Raspbian and Raspbmc), but it has stopped working completely. I have what is known as the "red light dim green" problem, where the green light (OK) is very dim, and the red light (PWR) is on. I own a 2GB SD which works fine in my Raspberry Pi, but it isn't very fast, and I can hardly fit the images I want on it. The SD card problems seems to have started when I installed Adafruit's Occidentalis, but I'm not completely sure. I've tried burning my SD with Win32DiskImager, and Raspbian, as well as using the Raspbmc installer. None of these boot on my Raspberry Pi. It could be something to do with my power supply, but I'm not completely sure. Should the Pi have enough power from a USB 3.0 port? Before, I was using an iPad charger, but I don't have that on hand. Is my SD now dud? (it works fine in the computer)
Comment: Sounds like a power issue. All you can do is try a different charger and see if it fixes your issue.
Answer: Replacing my SD card has solved the problem.


Creating same network segment over internet

Question: How am I able to let my 2 PC over internet see one another as if they are on the same network segment?
Comment: Did any answer help you? if so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer.
Answer: You can use VPN for that. It's the best solution. Also, if you need to work into your other PC like if you were seat in front of that, you can try TeamViewer.
By the other hand, like @Ron Maupin said, if you can control the routing of your organization, or enterprise, whatever, you can create a tunnel accros the internet, eg: GRE, IPsec(this one is a VPN).
Answer: You want a VPN for this.
The traditional way to do this is to configure your router as a VPN server, then have clients connect to it over the internet using some VPN software. This lets them access hosts in the LAN as if they were on the network locally.
A quick and easy alternative is to use some VPN software like hamachi or teamviewer. Both work differently, but will allow two (or more... depending on the software) computers to connect to each other as if on the same network, over the internet.
Answer: You should be able to create a tunnel from one router to the other to make your two networks look as if they are directly connected. This has the benefit of letting the routing protocols, etc, work over the tunnel.
You need to be careful if you have overlapping network addressing at both sites, but there are ways around that which involve NAT. It should only be a temporary solution to give you time to re-address one or both sides to create a common addressing scheme.


Determine the maximum height a pump can suck up water

Question: I am working on a homework problem that presents the scenario of trying to raise water from a small reservoir of depth 8 m whose surface is 25 m below a pump that can maintain a pressure differential of 10 atm. According to the problem this is not possible, but I am charged with 1) finding the maximum height that this water could be sucked up, and 2) finding an optimal placement for the pump (instead of at the top of the hill) so that it could suck the water up. I am not given how much water is in the reservoir. I do not know where to begin. I do not really understand how the pump works (the instructor has said it does not really matter, all you need to know is that it is a "black box" that maintains this pressure differential). I would appreciate some guidance on where to begin or how to set up my equations.
Comment: Answers here should focus on the conceptual matter and not on the particulars of *this* problem in order to remain consistent with the FAQ.
Comment: @dmckee, I did not request the answer to the question, but just how to think about this. Because of my lack of intuition (and knowledge) in these things I cannot do anything with the fact that there is a 10 atm pressure differential, I do not know what that really _means_ in terms of generating a suction force upwards from a certain height.
Comment: Yes, and we appreciate it. That was a reminder for our regulars who can get excited.
Comment: @dmckee I thought our standard practice was not to allow "I don't know where to begin" questions like this one.
Answer: There's a big difference between trying to such water up from the top, and trying to push it up from the bottom.
It we first consider trying to push up water from the bottom, then the height you can raise the water simply depends on how much pressure you can produce. A quick Google will tell you that a pressure of 1 atmosphere corresponds to a height (or depth) of about ten metres. So if your pump can produce a pressure of ten atomspheres it will be able to pump the water to about 100 metres. I say "about" because your professor probably expects you to calculate this exactly and I won't spoil their fun by just giving you the answer :-)
The reason why sucking water up is different is because water boils at reduced pressure. The pressure at the surface of the pool is obviously one atmosphere. To suck water up you have to reduce the pressure at the pump. However if you reduce the pressure too much the water starts to boil and the water won't go up any further. All you do is suck steam. The maximum height you can suck water can be calculated from it's vapour pressure and density. When the pressure has reduced to less that the water vapour pressure the water starts to boil. Again, I won't spoil your professor's fun by just giving you the answer.
This should give you some clues about how to approach the problem. If you need any more info please comment.


Estimating error in NDSolve

Question: I would like to give a theoretical estimation of local truncation error (and then for the global one) for a solution to a numerical initial value problem by NDSolve.
For this estimate I need to know what method has been used and the size of the steps (or an average size for the global error, since I think it uses adaptive size step). How can I get this information?
Comment: welcome! Could you please provide any information on what you have tried already (MMA code, literature etc.) and why it did not satisfy your requirements? This would alow others to produce meaningful answers.
Answer: See this to find out the method used by NDSolve and this
sol = NDSolveValue[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}];
Differences @ First @ sol["Coordinates"]

to get magnitude of step size

Estimating error in NDSolve


Reporting Hard / Soft errors in custom activity execute (Journey Builder)

Question: I'm working on a custom activity (NodeJS) for Journey Builder that sends SMS through a third party API. The SMS is sent when the "execute" method is called for each contact.
When something goes wrong, the execute function send a response with a 500 error status (ie: return res.sendStatus(500)).
There is an inconstancy in the report shown on Journey Builder in that case:

I would expect "Successes" to be 0 and "Hard Errors" to be 1.
How do I report a hard error in my activity? Why is this report inconsistent?
Thanks.
Answer: This is a bug within SFMC. Here is the Known Issue link
https://issues.salesforce.com/issue/a028c00000uY3N4AAK/~


Linux Mint 14.1 with Cinnamon - Mouse Sensitivity not Working

Question: 64-bit if that matters. My mouse sensitivity slider does nothing, but my acceleration slider works. I'd like acceleration off and sensitivity how I like it, but it refuses to work. I have tested the option on two computers, and both do not change the sensitivity. Any help?
Comment: Tried a good ol' relogin?
Comment: What's your hardware? Is this a mouse or a touchpad? Can you adjust the sensitivity using another Desktop Environment? A live session?
Comment: A relogin and reboots do not work.
I've tried both a USB mouse and touchpad. Both don't work. Not a live session. I'll try a different desktop enviroment later.
Comment: Did one of the answers help?
Answer: You have to modify linux X Window Server settings. If you want to do it system wide (I'd highly recommend this because this way the settings will be applied to the login screen also), then you need to modify one of the xorg.conf files. For example, the following one: /etc/X11/xonrg.conf. If there is no such file, you can create one by yourself.
You need to do all the things as described here except that if you want to disable acceleration, the text to put into xorg.conf is the following:
Section "InputClass"
   Identifier      "Razer"                    # Whatever you want.
   MatchProduct    "Razer Razer DeathAdder"   # Product name from xinput list.
   Option          "AccelerationScheme"  "none"
EndSection


One liner to enable some SCLs and a python virtual environment?

Question: I'm writing a python 3.4 app on a centos box. Normally, when I have to reset my tmux session, such as after a reboot I do the following:
<code>[zippy@localhost ~]$ scl enable rh-python34 httpd24 bash
[zippy@localhost ~]$ source python34/bin/activate
(python34)[zippy@localhost ~]$
</code>
I could do it in one command, but I lose my prompt, and therefore presumably other stuff.
<code>[zippy@localhost ~]$ scl enable rh-python34 httpd24 "source ../python34/bin/activate && bash"
(python34)
</code>
I'm actually not sure why I can't just enter the virtual environment without enabling scl, but it still try to execute the default python instead of the scl one that I created the virtual environment with.
Answer: <code>scl enable rh-python34 httpd24 -- bash --rcfile <(echo '. ~/python34/bin/activate')
</code>


"debug" to show vlan of incoming frames

Question: At a remote site where I can't easily set up SPAN and do a regular packet capture, I need to see the VLAN of incoming frames on a trunk interface. Is there a debug command for a Cisco Catalyst 3560X that will show me the layer 2 header or VLAN of every incoming frame on an interface? Or another approach to identifying the VLAN of incoming frames using only what I have onboard a 3560X?
Comment: Did any answer help you? if so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer.
Answer: Unfortunately the 3560X does not support packet capture. However, you may be able to use RSPAN (Remote SPAN) to capture traffic on the link.
How this would work is you would configure the remove device with a new VLAN for remote span, and setup a monitor session to go to that remote VLAN.
Any devices in-between that remote VLAN must be trunked and configured. Because of this, RSPAN will not traverse most WAN links (Layer 2 Only).
Example Config for Remote Device:
switch(config)#vlan <#>
switch(config-if)# remote-span
switch(config-if)#exit
switch(config)#monitor session 2 source interface Gi 0/1
switch(config)monitor session 2 destination remote vlan <#>

Example Config for Device to SPAN to:
switch(config)#vlan <#>
switch(config-if)#remote-span
switch(config-if)#exit
switch(config)#monitor session 2 source remote vlan <#>
switch(config)#monitor session 2 destination interface fa 0/2

You may also be able to use the command: debug vlan packet to see any VLAN tagged packets the device is not configured for. I was not able to confirm if this was available on the 3560, and I do not have one to test.
Comment: RSPAN is not an option. I would need the capture to cross a layer 3 link.

"debug" to show vlan of incoming frames