httpd returns "SSLCertificateFile: file '/var/iwww/certs/msdfw/c.pem' does not exist or is empty"

Question: So recently, I had to reset my server because of some issues and stuff. And now, I've been trying to set it up again and it's just not working out for me. I've installed httpd successfully and it works with my websites. But when I try to add an SSL Certificate, CentOS dares to lie to me that it doesn't exist. Here's the output of journalctl -xe;
Sep 26 17:00:11 localhost systemd[1]: Starting The Apache HTTP Server...
-- Subject: Unit httpd.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit httpd.service has begun starting up.
Sep 26 17:00:11 localhost httpd[5579]: AH00526: Syntax error on line 15 of
/etc/httpd/enabled/msdfw.conf:
Sep 26 17:00:11 localhost httpd[5579]: SSLCertificateFile: file
'/var/iwww/certs/msdfw/c.pem' does not exist or is empty
Sep 26 17:00:11 localhost systemd[1]: httpd.service: main process exited,
code=exited, status=1/FAILURE
Sep 26 17:00:11 localhost kill[5581]: kill: cannot find process ""
Sep 26 17:00:11 localhost systemd[1]: httpd.service: control process exited,
code=exited status=1
Sep 26 17:00:11 localhost systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: Unit httpd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit httpd.service has failed.
--
-- The result is failed.
Sep 26 17:00:11 localhost systemd[1]: Unit httpd.service entered failed state.
Sep 26 17:00:11 localhost systemd[1]: httpd.service failed.

I've checked the file and it's there. I've already tried giving all ownership to user apache, I've gaven it to group apache and changed all permissions to 777. None of it worked (and reverted permissions). I've tried lsof c.pem, but no output. This is the the VirtualHost;
<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com
    RewriteEngine on
    RewriteRule ^/?(.*) https://example.com/$1 [R,L]
</VirtualHost>
<VirtualHost *:443>
    ServerName example.com
    DocumentRoot /var/www/msdfw
    ErrorLog /var/iwww/logs/e-msdfw
    CustomLog /var/iwww/logs/c-msdfw combined
    DirectoryIndex index.php
    SSLEngine on
    SSLCertificateFile /var/iwww/certs/msdfw/c.pem
    SSLCertificateKeyFile /var/iwww/certs/msdfw/p.key
    SSLCertificateChainFile /var/iwww/certs/msdfw/b.pem
    <Directory /var/www/msdfw/>
            Require all granted
    </Directory>
</VirtualHost>

I've already install mod_ssl so I don't think that's it. I've done sudo -u apache cat /var/iwww/certs/msdfw/c.pem to check if it can read it, and it can. The certificate can be properly parsed by OpenSSL. So, I'm not sure what the problem is. Anyone that can help, please give out a hand. Thanks!
Additional Information:

OS: CentOS Linux release 7.4.1708
Not sure what category this falls in, but its Minimal.
Comment: Is SELinux blocking it (look at your system logs)?
Comment: @yoonix How do I check system logs? Google answers can't seem to help me.
Comment: Did you check the second part of error message (or empty)? You might check the cert file using `openssl x509 -inform PEM -in /var/iwww/certs/msdfw/c.pem -noout -text`
Comment: @TomTomTom As I've said already, OpenSSL parses it correctly without error.
Answer: It seems I was wrong. It has to do with the certificates labeled system_u or unconfined_u. They have to be labeled system_u to be read by httpd.
Find out how to change labels here.
Answer: I know this is an old thread, but I had a similar issue on my system. I am using OL8 with Apache as a web server. Nothing I did will work. Until I ran the this command:
sudo chcon -R -t httpd_config_t letsencrypt/

My issue was that SELinux was blocking the request.
The learning is that anything that need to be run by Apache must have httpd_config_t set at a minimum.
Answer: So... I've sort of fixed the problem, but not completely. I tried to remove the c.pem to see if it still recognizes the directory and give me some error that says;
/var/iwww/certs/msdfw/: Is a directory
But it didn't. Still same error. So I was being stupid and put in;
SSLCertificateFile whoami
Yeah, I don't know what I was thinking. But it said no file in /etc/httpd/whoami or is empty. Anyways, I moved it all to /etc/httpd/certs/msdfw/ and reconfigured the VirtualHost.
And it worked...
TL;DR: If you're getting this and nothing else is working, move it to /etc/httpd.
Comment: Which leads me to my next question. [Why doesn't it accept absolute paths?](https://serverfault.com/questions/875840)


Interesting closed form for $\int_0^{\frac{\pi}{2}}\frac{1}{\left(\frac{1}{3}+\sin^2{\theta}\right)^{\frac{1}{3}}}\;d\theta$

Question: Some time ago I used a formal approach to derive the following identity:

$$\int_0^{\frac{\pi}{2}}\frac{1}{\left(\frac{1}{3}+\sin^2{\theta}\right)^{\frac{1}{3}}}\;d\theta=\frac{3^{\frac{1}{12}}\pi\sqrt{2}}{AGM(1+\sqrt{3},\sqrt{8})}\tag{1}$$

where $AGM$ is the arithmetic-geometric mean. Wolfram Alpha does not tell me whether this is correct, but it does appear to be accurate to many decimal places. I have three questions:

Can anyone verify whether $(1)$ is in fact correct?
Is there a way of generalizing $(1)$ to integrals of the form $\int_0^{\frac{\pi}{2}}\left(a+\sin^2{\theta}\right)^{-\frac{1}{3}}\;d\theta$ or is this integral more special? My derivation (see below) appears to only work for $a=\frac{1}{3}$.
There is a superficial similarity between $(1)$ and elliptic integrals (e.g. the $AGM$ evaluation); is there a way to transform this integral into an elliptic integral that I have missed, or is it merely a coincidence that an integral of this form is the reciprocal of an $AGM$?

Derivation: I have put this here in case it helps to see where I am coming from; I apologize for its length. I began by using a multiple integration trick of squaring the integral and converting to polar coordinates to evaluate $\int_0^\infty e^{-x^6}dx=\frac{1}{6}\Gamma(\frac{1}{6})$ as follows:
$$\left[\int_0^\infty e^{-x^6}\;dx\right]^2=\int_0^\infty\int_0^{\frac{\pi}{2}}re^{-r^6(\cos^6\theta\;+\;\sin^6\theta)}\;d\theta\;dx={\int_0^\infty re^{-r^6}\int_0^{\frac{\pi}{2}}e^{3r^6\cos^2\theta\sin^2\theta}\;d\theta\;dx}$$
$$=\int_0^\infty re^{-r^6}\int_0^{\frac{\pi}{2}}e^{\frac{3r^6}{4}\sin^22\theta}\;d\theta\;dx={\int_0^\infty re^{-r^6}\int_0^{\frac{\pi}{2}}e^{\frac{3r^6}{4}\cos^2\theta}\;d\theta\;dx}$$
I then made use of the following formula (see here):
$$\sum_{n=0}^{\infty}\frac{(2n)!}{(n!)^3}x^n=\frac{2}{\pi}\int_0^{\frac{\pi}{2}}e^{4x\cos^2\theta}\;d\theta\tag{2}$$
Using $(2)$ and formally interchanging integration and summation we get:
$$\frac{\Gamma(\frac{1}{6})^2}{36}=\int_0^\infty re^{-r^6}\int_0^{\frac{\pi}{2}}e^{4\left(\frac{3r^6}{16}\right)\cos^2\theta}\;d\theta\;dx=\frac{\pi}{2}\int_0^\infty re^{-r^6}\sum_{n=0}^{\infty}\frac{(2n)!}{(n!)^3}\left(\frac{3r^6}{16}\right)^n\;dx$$
$$=\frac{\pi}{2}\sum_{n=0}^{\infty}\frac{(2n)!}{(n!)^3}\left(\frac{3}{16}\right)^n \int_0^\infty r^{6n+1}e^{-r^6}\;dx=\frac{\pi}{12}\sum_{n=0}^{\infty}\frac{(2n)!}{(n!)^3}\left(\frac{3}{16}\right)^n \Gamma\left(n+\frac{1}{3}\right)$$
I then used Laplace transform identities and $(2)$, freely interchanging integrals and sums, to write:
$$\sum_{n=0}^{\infty}\frac{(2n)!}{(n!)^3}\frac{\Gamma\left(n+\frac{1}{3}\right)}{s^{n+\frac{1}{3}}}=L\left[\sum_{n=0}^\infty \frac{(2n)!}{(n!)^3}t^{n-\frac{2}{3}}\right](s)={\frac{2}{\pi}L\left[t^{-\frac{2}{3}}\int_0^\frac{\pi}{2}e^{4t\cos^2\theta}\;d\theta\right](s)}={\frac{2}{\pi}\int_0^\frac{\pi}{2}L\left[t^{-\frac{2}{3}}e^{4t\cos^2\theta}\right](s)\;d\theta}={\frac{2}{\pi}\int_0^\frac{\pi}{2}\frac{\Gamma(\frac{1}{3})}{(s-4\cos^2\theta)^{\frac{1}{3}}}\;d\theta}$$
Accordingly, since $\frac{4}{3}-\cos^2\theta=\frac{1}{3}+\sin^2{\theta}$ we can deduce that:
$$\frac{\Gamma(\frac{1}{6})^2}{36}=\frac{\Gamma(\frac{1}{3})}{6}\left(\frac{4}{3}\right)^\frac{1}{3}\int_0^\frac{\pi}{2}\frac{1}{(\frac{1}{3}+\sin^2\theta)^{\frac{1}{3}}}\;d\theta$$
Reflection and duplication give $\Gamma(\frac{1}{6})=2^{-\frac{1}{3}}\sqrt{\frac{3}{\pi}}\Gamma(\frac{1}{3})^2$ and hence we have the following identity:

$$\int_0^{\frac{\pi}{2}}\frac{1}{\left(\frac{1}{3}+\sin^2{\theta}\right)^{\frac{1}{3}}}\;d\theta=\frac{3^\frac{1}{3}\Gamma(\frac{1}{3})^3}{2^\frac{7}{3}\pi}\tag{3}$$

while $(1)$ may be obtained by using the following identity (see here):
$$\Gamma\left(\frac{1}{6}\right)=\frac{2^\frac{14}{9}3^\frac{1}{3}\pi^\frac{5}{6}}{AGM(1+\sqrt{3},\sqrt{8})^\frac{2}{3}}$$
This completes the derivation; I cannot see how a method like this (especially with the conversion to polar coordinates) could be used to give results more general than $(1)$ and $(3)$.
Comment: It and others can be expressed as,$$\int_0^{\pi/2}\frac1{\sqrt[3]{\tfrac13+\sin^2 x}}dx=3^{1/12}\,K(k_3)$$ $$\int_0^{\pi/2}\frac1{\sqrt[3]{4+\sin^2 x}}dx=\frac{3^{3/4}}{5^{5/6}}\,K(k_3)$$ $$\int_0^{\pi/2}\frac1{\sqrt[3]{27+\sin^2 x}}dx=\frac{3^{3/4}}7\,K(k_3)$$ with [elliptic integral singular value](http://mathworld.wolfram.com/EllipticIntegralSingularValue.html) $\displaystyle K(k_3) = \frac{3^{1/4}\,\Gamma^3\big(\tfrac13\big)}{2^{7/3}\,\pi}$. See answer below.
Comment: Testing your result numerically in Maple, it's correct to 100 decimal places.
Comment: @J.M.isn'tamathematician: It turns out this integral is connected to [another integral](http://math.stackexchange.com/a/2107512/4781) I asked about before.
Comment: A partial result: your integral is equivalent to $$3\sqrt[3]\frac34\int_{\sqrt[3]\frac43}^{\infty }\frac{\mathrm d w}{\sqrt[3]{w^3-1} \sqrt{3 w^3-4}}$$
Comment: $$\int_{0}^{+\infty}\frac{dx}{\sqrt{(x^2+a^2)(x^2+b^2)}}=\frac{\pi}{2\,\text{AGM}(a,b)}.$$
Comment: My original approach was to express $\int_{1}^{+\infty}\frac{dx}{\sqrt{x^3-1}}$ as a value of the Beta function and as an elliptic integral of the first kind, too. That gives $\Gamma\left(\frac{1}{3}\right)\Gamma\left(\frac{1}{6}\right)$ can be computed through the AGM, and by exploiting the properties of the AGM and Legendre's duplication formula we get the wanted result.
Answer: Making the substitution $\displaystyle \,\, \cos x = \operatorname{sech} t,$ the integral is transformed into
$$I=\int_0^{\pi/2} \left(\frac{4}{3}-\cos^2 x\right)^{-1/3} \, dx
 = \int_0^\infty \left(\frac{4}{3}-\operatorname{sech}^2 t\right)^{-1/3} \, \operatorname{sech} t \, dt.$$
Now, using the triple-angle formula $\displaystyle \, \, \cosh(3 z) =4 \, \cosh^3 z -3 \, \cosh z,$ we can simplify it to
$$I= \int_0^\infty  \left( \dfrac{\cosh(3 t)}{3 \, \cosh^3 t} \right)^{-1/3} \, \operatorname{sech} t \, dt
\\\\= 3^{1/3} \int_0^{\infty} (\operatorname{sech} 3 t)^{1/3} \, dt.$$
See for example here how we can easily show that
$$\int_0^{\infty} (\operatorname{sech} t)^{s} dt = \frac12 B\left(\frac{s}{2},\frac12\right).$$
This gives your integral as
$$ I = 3^{-2/3} \cdot  \frac12 B\left(\frac16,\frac12\right)$$
which you can bring to your equivalent representation using the functional equations of the Gamma function.
Comment: @Nemo I understood his questions as seeking both a generalization, and a verifciation of this specific case.
Comment: Thank you for this answer +1. I am interested to see that the integral can be converted to a similar representation to that which Jack D'Aurizio used to derive the $\Gamma(\frac{1}{6})$ identity I quoted in my answer.
Answer: This is answer to question 3.
Expanding into the powers of $\frac{\cos^2x}{s+4}$ and integrating termwise one obtains
$$
\int_0^{\pi/2}\frac{1}{\sqrt[3]{s+4 \sin ^2x}}dx=\int_0^{\pi/2}\frac{1}{\sqrt[3]{s+4 -4\cos ^2x}}dx=\frac{\pi  \, _2F_1\left(\frac{1}{2},\frac{1}{3};1;\frac{4}{s+4}\right)}{2 \sqrt[3]{s+4}}.
$$
Use Pfaff's transformation to write
$$
{}_2F_1\left(\frac{1}{2},\frac{1}{3};1;\frac{4}{s+4}\right)=\sqrt{\frac{s+4}{s}} \, _2F_1\left(\frac{1}{2},\frac{2}{3};1;-\frac{4}{s}\right).
$$
By transformation 2.11(5) from Erdelyi, Higher transcendental functions
$$
_2F_1\left(\frac{1}{2},\frac{2}{3};1;-\frac{4}{s}\right)=\left(\frac{2}{\sqrt{\frac{4}{s}+1}+1}\right)^{4/3} \, _2F_1\left(\frac{2}{3},\frac{2}{3};1;\left(\frac{1-\sqrt{1+\frac{4}{s}}}{\sqrt{1+\frac{4}{s}}+1}\right)^2\right)
$$
Now apply Pfaff's transformation
$$
{}_2F_1\left(\frac{2}{3},\frac{2}{3};1;\left(\tfrac{1-\sqrt{1+\frac{4}{s}}}{\sqrt{1+\frac{4}{s}}+1}\right)^2\right)=\left(\tfrac{4 \sqrt{\frac{4}{s}+1}}{\left(\sqrt{\frac{4}{s}+1}+1\right)^2}\right)^{-2/3} \, _2F_1\left(\frac{1}{3},\frac{2}{3};1;-\tfrac{\left(\sqrt{\frac{s+4}{s}}-1\right)^2}{4 \sqrt{\frac{s+4}{s}}}\right)
$$
It is known that this last hypergeometric function is elliptic integral. Introduce the following parametrization from Ramanujan's Notebooks, PART V, formula 5.17
$$
s=-2+\frac{2i}{3 \sqrt{3}}\frac{\left(2+2p-p^2\right) \left(1+4p+p^2\right) \left(1-2p-2 p^2\right)}{p \left(1-p^2\right) (p+2) (2 p+1)},\tag{1}
$$
then
$$
\sqrt{2 p+1} \, _2F_1\left(\frac{1}{3},\frac{2}{3};1;-\frac{\left(\sqrt{\frac{s+4}{s}}-1\right)^2}{4 \sqrt{\frac{s+4}{s}}}\right)=\left(p^2+p+1\right) \, _2F_1\left(\frac{1}{2},\frac{1}{2};1;\frac{p^3 (p+2)}{2 p+1}\right),
$$
and after combining all the formulas

$$
\int_0^{\pi/2}\frac{1}{\sqrt[3]{s+4 \sin ^2x}}dx=\frac{\pi  \left(p^2+p+1\right) \, _2F_1\left(\frac{1}{2},\frac{1}{2};1;\frac{p^3 (p+2)}{2 p+1}\right)}{2\sqrt{2 p+1}  \sqrt[6]{s (s+4)}}
$$
  with parametrization (1).

As an example $p=-\frac{1}{2}+\frac{3}{\sqrt[3]{2}}-\frac{3}{2^{2/3}}+\frac{i}{2} \sqrt{3 \left(13-4 \sqrt[3]{2}-5\cdot 2^{2/3}\right)}$, then $s=\frac43$ and
$$
\int_0^{\pi/2}\frac{1}{\sqrt[3]{\frac13+\sin ^2x}}dx=\frac{3^{1/3} \pi \left(p^2+p+1\right) \, _2F_1\left(\frac{1}{2},\frac{1}{2};1;\frac{p^3 (p+2)}{2 p+1}\right)}{2^{4/3}\sqrt{2 p+1} }
$$
A more convenient parametrization in terms of eta-quotients can be obtained similar to this question:

Define $\tau=\frac{1+n\sqrt{-3}}{2}$,$~w=-\frac{1}{\tau+1}$,$~\alpha=\frac{1}{4\sqrt{27}}\left(e^{\frac{\pi i}{4}} \sqrt{27} \left(\frac{\eta (3 w)}{\eta (w)}\right)^3-e^{-\frac{\pi i}{4} }\left(\frac{\eta (3 w)}{\eta (w)}\right)^{-3}\right)^2$, and $~r=\alpha(\alpha+1),$ then
  $$
\begin{aligned}\int_0^{\pi/2}\frac{1}{\sqrt[3]{\alpha+\sin ^2x}}dx
&=-\frac{\pi w\sqrt{3} ~i }{2\sqrt[6]{r}}\left(\frac{\eta (2 w) \eta^6 (3 w)}{\eta^2 (w) \eta^3 (6 w)}+4\frac{\eta (w)\eta^6 (6 w) }{\eta^2 (2 w) \eta^3 (3 w)}\right)\\[2.5mm]
&=-\frac{\pi w\sqrt{3} ~i }{2\sqrt[6]{r}}\left(\frac{\big(\vartheta_4(0,q^6)\big)^3}{\vartheta_4(0,q^2)}+\frac{\big(\vartheta_2(0,q^3)\big)^3}{\vartheta_2(0,q)}\right)\\[2.5mm]
&=-\frac{\pi w\sqrt{3} ~i }{2\sqrt[6]{r}}\;_2F_1\large\left(\tfrac13,\tfrac23;1;\tfrac{2r\,+\,(1+2\alpha)\sqrt{r}}{4r}\right)\end{aligned}
$$
  with Jacobi theta functions $\vartheta_n(0,q)$ and nome $q=e^{\pi i\, w}$.

For example $n=3$ gives $\alpha=\frac{1}{3}$.
Comment: For the conclusion, I added some equivalent forms as Jacobi thetas and $_2F_1$. I hope it's ok. By the way, I like how the form $r=\alpha(1+\alpha)$ always turns up.
Comment: The ratio of the integral of this post and the other post, if $\alpha$ is used, turns out to be a simple algebraic form dependent on $\tau$.
Comment: @TitoPiezasIII , yes, it is no surprize because both are proportional to the same elliptic integral $K\Big(\sqrt{\tfrac{p^3 (2+p)}{1+2 p}}\Big)$.
Comment: Many thanks for this awesome answer to my third question; the elliptic integral transformation certainly doesn't seem simple. I'm not sure which answer to mark correct since my questions have been answered in different answers. I'm certainly very grateful for the work that's gone into the answers.
Answer: (Too long for a comment.)
Expanding on a concluding remark by Nemo, there is an interesting connection between the OP's,
$$\int_0^{\pi/2}\frac1{\sqrt[3]{\color{blue}{\alpha}+\sin^2 x}}dx=\frac{\pi}{2\,\sqrt[3]{\alpha+1}}\,_2F_1\Big(\frac12,\frac13;1;\,\frac1{\color{blue}{\alpha}+1}\Big)\tag1$$
and the integral involved in this post,
$$\int_0^{\infty}\frac1{\sqrt[3]{\color{blue}{1+2\alpha}+\cosh x}}dx=2^{2/3}\,3^{1/4}K(k_3)\;_2F_1\Big(\frac13,\frac13;\frac56;-\color{blue}{\alpha}\Big)\tag2$$
Equations $(1),(2)$ are valid for arbitrary $\alpha$. But if it is chosen such that,
$$\color{blue}{\alpha} =\alpha(\tau)= \frac1{4\sqrt{27}}\big(\lambda^3-\sqrt{27}\lambda^{-3}\big)^2$$
where,
$$\lambda =\frac{\eta\big(\frac{\tau+1}3\big)}{\eta(\tau)},\quad \tau=\frac{1+N\sqrt{-3}}2$$
then there is a beautifully simple relationship between $(1),(2)$ as,

$$\frac{N+1}{2^{1/3}\,3^{1/2}}\,\int_0^{\pi/2}\frac1{\sqrt[3]{\color{blue}{\alpha}+\sin^2 x}}dx=\int_0^{\infty}\frac1{\sqrt[3]{\color{blue}{1+2\alpha}+\cosh x}}dx\tag3$$

The closed-form for the RHS (via its hypergeometric equivalent) is already given in this answer, so that automatically leads to the form for the LHS as well. Some rational values are,
$$\alpha\big(\tfrac{1+3\sqrt{-3}}2\big)=\large\tfrac13$$
$$\alpha\big(\tfrac{1+5\sqrt{-3}}2\big)=4$$
$$\alpha\big(\tfrac{1+7\sqrt{-3}}2\big)=27$$
which will be algebraic for integer $N>1$. The first one was re-discovered by the OP and lead to the nice evaluations,
$$\int_0^{\pi/2}\frac1{\sqrt[3]{\tfrac13+\sin^2 x}}dx=3^{1/12}\,K(k_3)$$
$$\int_0^{\pi/2}\frac1{\sqrt[3]{4+\sin^2 x}}dx=\frac{3^{3/4}}{5^{5/6}}\,K(k_3)$$
$$\int_0^{\pi/2}\frac1{\sqrt[3]{27+\sin^2 x}}dx=\frac{3^{3/4}}7\,K(k_3)$$
Comment: This is a really good answer. I had no idea what I was getting into when I posted my question (I hadn't studied the hypergeometric function much) but there is some very beautiful theory here and in the linked post.
Comment: +1. Thank you for this nice answer. This was the sort of nice connection to existing theory I was looking for. It seems $\alpha=\frac{1}{3}$ is not alone in having a nice answer of this form. I'll take a while to go through everything here!


mdadm and RAID-5 recovery

Question: I am encountering some problems with my RAID-5 array, using mdadm and Debian.
First of all, I lost a drive (completely, it is not even recognized by the BIOS), then I replaced it with a new one; rebuilding has started but has been interrupted by a read error on the second disk (and this one has been removed):
raid5:md0: read error not correctable (sector 1398118536 on sdd)

I suppose that this one will die in the next few days, but I want to re-add it to work with a degraded array to perform some backups (only few sectors are broken and I hope to save a maximum of data before it fails).
Here are my disks, in the RAID order:

sdc - OK
sdd - (the one with read errors, removed from array while rebuilding)
sde - (the one that died, replaced by a spare, but obviously interrupted while rebuilding => I'm not convinced about its data integrity)
sdf - OK

The fact is that I can't re-add sdd to the array, using this command:
# mdadm --assemble /dev/md0 /dev/sdc1 /dev/sdd1 /dev/sdf1 --force --run
mdadm: failed to RUN_ARRAY /dev/md0: Input/output error
mdadm: Not enough devices to start the array.
# mdadm -D /dev/md0
/dev/md0:
        Version : 0.90
  Creation Time : Tue Aug 24 14:20:39 2010
     Raid Level : raid5
  Used Dev Size : 1465039488 (1397.17 GiB 1500.20 GB)
   Raid Devices : 4
  Total Devices : 3
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Sun Oct 23 01:57:22 2011
          State : active, FAILED, Not Started
 Active Devices : 2
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 1

         Layout : left-symmetric
     Chunk Size : 128K

           UUID : 01017848:84926c43:1751c931:a76e1cde (local to host tryphon)
         Events : 0.131544

    Number   Major   Minor   RaidDevice State
       0       8       33        0      active sync   /dev/sdc1
       1       0        0        1      removed
       2       0        0        2      removed
       3       8       81        3      active sync   /dev/sdf1

       4       8       49        -      spare   /dev/sdd1

As you can see, sdd is recognized as a spare instead of being in sync as RAID device #1.
And I have no idea how to tell mdadm that sdd is RAID device #1.
If anyone has any idea, it would be so great!
Thanks.

PS: if this helps, here is the output of mdadm disk examination:
# mdadm -E /dev/sd[cdef]1
/dev/sdc1:
          Magic : a92b4efc
        Version : 0.90.00
           UUID : 01017848:84926c43:1751c931:a76e1cde (local to host tryphon)
  Creation Time : Tue Aug 24 14:20:39 2010
     Raid Level : raid5
  Used Dev Size : 1465039488 (1397.17 GiB 1500.20 GB)
     Array Size : 4395118464 (4191.51 GiB 4500.60 GB)
   Raid Devices : 4
  Total Devices : 3
Preferred Minor : 0

    Update Time : Sun Oct 23 01:57:22 2011
          State : clean
 Active Devices : 2
Working Devices : 3
     Failed Devices : 2
  Spare Devices : 1
       Checksum : dfeeeace - correct
         Events : 131544

         Layout : left-symmetric
     Chunk Size : 128K

      Number   Major   Minor   RaidDevice State
this     0       8       33        0      active sync   /dev/sdc1

   0     0       8       33        0      active sync   /dev/sdc1
   1     1       0        0        1      faulty removed
   2     2       0        0        2      faulty removed
   3     3       8       81        3      active sync   /dev/sdf1
   4     4       8       49        4      spare   /dev/sdd1
/dev/sdd1:
          Magic : a92b4efc
        Version : 0.90.00
           UUID : 01017848:84926c43:1751c931:a76e1cde (local to host tryphon)
  Creation Time : Tue Aug 24 14:20:39 2010
     Raid Level : raid5
  Used Dev Size : 1465039488 (1397.17 GiB 1500.20 GB)
     Array Size : 4395118464 (4191.51 GiB 4500.60 GB)
   Raid Devices : 4
  Total Devices : 3
Preferred Minor : 0

    Update Time : Sun Oct 23 01:57:22 2011
          State : clean
 Active Devices : 2
Working Devices : 3
 Failed Devices : 2
  Spare Devices : 1
       Checksum : dfeeeae0 - correct
         Events : 131544

         Layout : left-symmetric
     Chunk Size : 128K

      Number   Major   Minor   RaidDevice State
this     4       8       49        4      spare   /dev/sdd1

   0     0       8       33        0      active sync   /dev/sdc1
   1     1       0        0        1      faulty removed
   2     2       0        0        2      faulty removed
   3     3       8       81        3      active sync   /dev/sdf1
   4     4       8       49        4      spare   /dev/sdd1
/dev/sde1:
          Magic : a92b4efc
        Version : 0.90.00
           UUID : 01017848:84926c43:1751c931:a76e1cde (local to host tryphon)
  Creation Time : Tue Aug 24 14:20:39 2010
     Raid Level : raid5
  Used Dev Size : 1465039488 (1397.17 GiB 1500.20 GB)
     Array Size : 4395118464 (4191.51 GiB 4500.60 GB)
   Raid Devices : 4
  Total Devices : 4
Preferred Minor : 0

    Update Time : Sat Oct 22 22:11:52 2011
          State : clean
 Active Devices : 2
Working Devices : 3
 Failed Devices : 2
  Spare Devices : 1
       Checksum : dfeeb657 - correct
         Events : 131534

         Layout : left-symmetric
     Chunk Size : 128K

      Number   Major   Minor   RaidDevice State
this     4       8       65        4      spare   /dev/sde1

   0     0       8       33        0      active sync   /dev/sdc1
   1     1       0        0        1      faulty removed
   2     2       0        0        2      faulty removed
   3     3       8       81        3      active sync   /dev/sdf1
   4     4       8       65        4      spare   /dev/sde1
/dev/sdf1:
          Magic : a92b4efc
        Version : 0.90.00
           UUID : 01017848:84926c43:1751c931:a76e1cde (local to host tryphon)
  Creation Time : Tue Aug 24 14:20:39 2010
     Raid Level : raid5
  Used Dev Size : 1465039488 (1397.17 GiB 1500.20 GB)
     Array Size : 4395118464 (4191.51 GiB 4500.60 GB)
   Raid Devices : 4
  Total Devices : 3
Preferred Minor : 0

    Update Time : Sun Oct 23 01:57:22 2011
          State : clean
 Active Devices : 2
Working Devices : 3
 Failed Devices : 2
  Spare Devices : 1
       Checksum : dfeeeb04 - correct
         Events : 131544

         Layout : left-symmetric
     Chunk Size : 128K

      Number   Major   Minor   RaidDevice State
this     3       8       81        3      active sync   /dev/sdf1

   0     0       8       33        0      active sync   /dev/sdc1
   1     1       0        0        1      faulty removed
       2     2       0        0        2      faulty removed
   3     3       8       81        3      active sync   /dev/sdf1
   4     4       8       49        4      spare   /dev/sdd1

Answer: What you need first is off-RAID copy of sdD. Use dd_rescue, for e. g.. Don't use this disk in that RAID while recovering it.
When you have this copy, use it to start the array w/o sdE — put instead of it keyword missing. Two hints how this can be done, even if direct way with --force fails:
1) You can re-create your RAID with --assume-clean. (Don't forget this option since with it only superblocks will be updated, not parity).
2) You can -A assemble array.
In both cases you have to provide absolutley the same config options (layout, chunk size, disk order, …) as your broken RAID has. In fact I'd recommend starting with -A-ssembling, since it even doesn't update superblock, while letting you access your data. Only when you're sure it's properly assembling, you can make it persistent with assume-clean re-creation.
As soon as you would have running RAID with 3 disks, just put your sdE instead of missing one.

mdadm and RAID-5 recovery


proving $(\mathbb{B}^2 \times \{0 \}) \bigcup (\mathbb{S}^1 \times [0, \infty))$ is a retract of $\mathbb{R}^3$

Question: I don't know how to solve this. I tried constructing a retraction but nothing comes to mind. Can someone guide me through this and if possible explain the intuition behind solving this kind of problem? Thank you.
Comment: Is $\mathbb B^2$ the unit disk?
Comment: The closed unit disk.
Answer: My intuition here would be that $(\mathbb B^2 \times \{0\}) \cup (\mathbb S^1 \times [0,\infty))$ is homeomorphic to $\mathbb R^2 \times \{0\}$ via a homeomorphism $f: (\mathbb B^2 \times \{0\}) \cup (\mathbb S^1 \times [0,\infty)) \to \mathbb R^2 \times \{0\}$ fixing $\mathbb B^2 \times \{0\}$. If we can extend $f$ to a homeomorphism $f: \mathbb R^3 \to \mathbb R^3$, then the desired retraction can be achieved as $f^{-1} \circ p \circ f$, where $p: \mathbb R^3 \to \mathbb R^2 \times \{0\}$ is the projection retraction. It may be somewhat tedious to construct this extension of $f$ explicitly, but it seems intuitive that it can be done.


Why is the subgroup generated by a subset $U$ defined as the set of *finite* combinations of elements of $U$? Why discard the infinite ones?

Question: From Wikipedia:

a generating set of a group is a subset such that every element of the group can be expressed as a combination (under the group operation) of finitely many elements of the subset and their inverses.

I'm confused because there are examples of combinations of infinitely many elements of a subset which converge to an element that cannot be represented as a finite combination, and I feel like that element should be in the generated subgroup. Why shouldn't it?
As an example of what I mean, take $(\Bbb R, +)$ and its subset $\{\frac 1{n!} \mid n \in \Bbb N \}$. Why shouldn't $e$ be in the generated subgroup?
Comment: the rules specify "finite combinations".  Infinite sums don't have much  meaning in a general group.  $e$ is not rational so it can't be obtained as a finite sum of rationals.
Comment: You would need to involve topology to make sense of this. For instance $e$ would be in the closed subgroup generated by your subset.
Comment: How would you define an infinite product (or sum in the abelian case) abstractly? You are not always in a metric space or more generally a topological space where you can consider notions like convergence. If you take an arbitrary set together with an operation you just get finite combinations. This is all that makes sense without having more structure.
Comment: It is defined, but not in the realm of groups. It exists in the realm of topological groups.
Comment: @ThorWittich I thought that $e$ should really be in the generated subgroup $Û$ because $e=\sum_0^{+\infty} 1/n!$ and each partial sum is in $Û$, so this countably infinite sum should be too. It is certainly a real number. It feels like the closure of $Û$ implies this. Why should that sum be undefined?
Comment: @CaptainLama I feel like I can talk about a countably infinite iteration of the group operation without defining it, in this case, because it is already defined in $\Bbb R$. Like isn't the group $(\Bbb R, +)$ automatically a topological group, by virtue of the properties of $\Bbb R$? Can we even define $\Bbb R$ without the least upper bound property?
Comment: @TheFootprint: As an abstract group, the additive group of real numbers is $\oplus_{\alpha\in A} {\mathbb Q}$, where $A$ has the cardinality of continuum (abstractly defined as the set of all subsets of ${\mathbb N}$).
Comment: A group itself consists only of finite products of elements. People do study something resembling the set of infinite products of discrete groups (that is, groups without topology), which is the "boundary" of the group. In certain cases, the boundary is invariant of the group (as in, changing generating set does not alter the boundary). I don't know if this is always true though.
Answer: Here are two reasons the group generated by $U$ is defined as the set of finite products, which I will denote by $\Pi(U)$:
1.)  The group generated by $U$ is usually taken to be the smallest group containing $U$; it is evident the set $\Pi(U)$ satisfies this criterion, since it is clearly closed under the group operation (finite products of finite products of elements of $U$ are, after all, themselves finite products of elements of $U$) and the taking of inverses, and contains the identity element $e$ since
$e = xx^{-1}, \; x \in  U; \tag 1$
thus $\Pi(U)$ is a group; and any group containing $U$ must contain $\Pi(U)$ if it is to be closed under the group operation and inversation.  Indeed, $\Pi(U)$ is often though of as he intersection of all groups containing $U$; in this sense it is the smallest group containing $U$.
2.)  We really can't define infinite products of elements of $U$ anyway, in a purely algebraic sense; to do so generally requires some notion of $convergence$ of a sequence of products such as
$x_1x_2, x_1x_2x_3, x_1x_2x_3x_4, \ldots; \tag 2$
but convergence lies in the realm of topology, so we would have to adopt some appropriate topological structure to give meaning to such infinite products.
Well, there are two of my main reasons for accepting the definition of the group generated by $U$ as $\Pi(U)$.  The comment stream attached to the question itself contains more useful insights, cf. the remarks of ThorWitch and Captain Lama.
Comment: I thought that, in my example, the topology is "inherited" naturally from the topology of $\Bbb R$, so that the infinite series which converges to $e$ is defined and is in the generated subgroup because each partial sum is in the generated subgroup, and therefore every subgroup which contains $U$ also contains $e$. But I see now that this is not so; it just follows from the definition of *closure* of a group, which is intrinsically finite. Is it correct? This, combined with your argument of "smallest subgroup" makes perfect sense. Thank you
Comment: So it is not that the infinite series is not defined, it's just that it wouldn't be the *smallest* subgroup.
Comment: @TheFootprint:  it strikes me that you are asking the right questions.  It is a subtle issue with $\Bbb R$, since it is usually constructed by using order properties of $\Bbb Q$, and this is damn close to topology.
Comment: @TheFootprint:  I think your comments express the right idea!  Cheers!


MPMoviePlayerView fade in/out of overlay

Question: I've got a MPMoviePlayerViewController, and I've added an overlay as a subview to the MPMoviePlayerController.view that it controls.  Does anyone know if there's an easy way to make my added overlay fade in and out with the rest of the controls?
My code to initialize and present the player is:
<code>LandscapeMPVC * theMovieViewController = [[LandscapeMPVC alloc] initWithContentURL:sourceURL];
MPMoviePlayerController * theMoviePlayer = [theMovieViewController moviePlayer];

[theMoviePlayer setRepeatMode:MPMovieRepeatModeOne];
[theMoviePlayer setScalingMode:MPMovieScalingModeAspectFit];
[theMoviePlayer setFullscreen:YES];

// Attemps at overlays
MPViewOverlayController * overlayCont = [[MPViewOverlayController alloc] init];

[[theMovieViewController view] addSubview:overlayCont.view];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(resetToolbar:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:theMoviePlayer];

[self presentMoviePlayerViewControllerAnimated:theMovieViewController];
</code>
LandscapeMPVC is just a subclass of MoviePlayerViewController where I overwrite the orientation code.
When the rest of the controls fade in the movie player, my custom overlay does not.  Is there some code in the controller that I need to add, or some notification that is sent?
Any input would be greatly appreciated.
Answer: You need to add the controls to the view of the moviePlayer property of the view controller to get them to appear.  This will cause the controls to show all the time, but they won't fade.
Like this:
<code>[[theMovieViewController.moviePlayer view] addSubview:overlayCont.view];
</code>


How to show $M_n = X_n^2-n$ is a martingale?

Question: Let $X_n, n = 0, 1, 2, . . .$ denote an unbiased Normal Random Walk.
$X_0 = 10$, and $X_{n+1} = X_n + Y_{n+1}$, with $\{Y_n\}$ are i.i.d. $N(0, 1)$.
Then how can I show that:
A) $M_n = X_n^2-n$ is a martingale
Find the value of:
B) $\mathbb{E}M_{20}$
Does the answer lie in reformulation $X_n = X_{n+1} - Y_{n+1}$ ?
And then:
$$X_n = X_{n+1} - Y_{n+1} \implies X_n^2 = (X_{n+1})^2 - 2X_{n+1}Y_{n+1} + (Y_{n+1})^2$$
And then we proceed with
$$\mathbb{E}[(X_{n+1})^2 - 2X_{n+1}Y_{n+1} + (Y_{n+1})^2 -n| \mathcal{F}_s], s \leq n+1$$
$$\mathbb{E}[(X_{n+1})^2 | \mathcal{F}_s] - 2\mathbb{E}[X_{n+1}Y_{n+1}|\mathcal{F}_s] + \mathbb{E}[(Y_{n+1})^2|\mathcal{F}_s] - \mathbb{E}[n | \mathcal{F}_s]$$
Is this right so far? if not, where I have I made a mistake, and how should I proceed?
Comment: I believe this should  carry the `self-study` tag (and follow the guidelines there).
Answer: $\mathbb{E} [X_{n+1}^2-(n+1) \space | \space \mathcal{F}_n \space] =\mathbb{E} [X_{n}^2+2X_n Y_{n+1}+Y_{n+1}^2-(n+1) \space | \space \mathcal{F}_n \space] $
This gives $X_n^2 + 2 X_n\mathbb{E} [Y_{n+1} \space | \space \mathcal{F}_n \space]+\mathbb{E} [Y_{n+1}^2 \space | \space \mathcal{F}_n \space]-n-1$.
Because ${\{Y_n\}}$ is iid standard normal, $\mathbb{E} [Y_{n+1}^2 \space | \space \mathcal{F}_n \space]$ and $\mathbb{E} [Y_{n+1} \space | \space \mathcal{F}_n \space]$ are 1 and 0 respectively.
Finally, we have $\mathbb{E} [M_{n+1} \space | \space \mathcal{F}_n \space] =X^2_n-n=M_n$
Therefore, we have $\{M_n\}$ being a martigale.
Second question,
$\mathbb{E} M_{20}=M_0=100 $
Comment: @elbarto $M_n$ is measurable with respect to $\mathcal{F}_n$ and, thus $$\mathbb{E}[M_n|\mathcal{F}_n] = M_n$$ automatically (and this would hold for any $\mathcal{F}_n$-measurable process, regardless of whether it is a martingale).  The idea with a martingale is that *future* values given the observed information are equal in expectation to what you see *now*, i.e. what yawning lion wrote.
Comment: $\mathbb{E}[M_n|\mathcal{F}_{n-1}]=M_{n-1}$ is the definition of martingales.

And, $\mathbb{E}[M_n|\mathcal{F}_{n-4}]=M_{n-4}$ can be derived from this definition and the tower expectation rule.
Comment: Thanks lion, just one question.
If I want to show $M_n$ is a martingale, doesn't that mean showing $$\mathbb{E}(M_n | \mathcal{F}_n) = M_n$$ ?

Yet here you have shown that $$\mathbb{E}(M_{n+1} | \mathcal{F}_n) = M_n$$

How does this work
Comment: Yep, shortly realised this after the fact!

One additional question, would it also be fair to say $$\mathbb{E}[M_n | \mathcal{F}_{n-1}] = M_{n-1}$$ satisfies martingale property?

or

$$\mathbb{E}[M_n | \mathcal{F}_{n-4}] = M_{n-4}$$
Answer: There is no mistake, your demo is right, but you must to go more deeply in the demo. If you want to demonstrate that your expression is a martingale you must express $X_{n}$ as a sum of the $Y_{n}$. After that, you would show the martingale property of your expression.
Comment: But $X_n$ is in $\mathcal{F}_n$, I believe $X_n$ can be treated as if it is constant. Am I right?
Comment: Sorry for the delay, Yawning Lion May. In this particular case, you get chance that your proof works, but rigorously, you can't say directy that $X_n$ is $\mathcal{F}_n$ measurable. Explictly, nothing says that $X_n$ is $\mathcal{F}_n$ measurable, perhaps $X_n$ is $\mathcal{F}_{n+1}$ measurable. I suggest you check that $X_n$ is $\mathcal{F}_n$ measurable. For instance, if my prof sees your demo, you'll have false to the question. Greetings
Answer: The another answer isn't quite rigorous because you can't write that
$\mathbb{E}[X_nY_{n+1}]=X_n\mathbb{E}[Y_{n+1}]$ directly.Firstly, you must to write that
$X_n=X_0+\sum_{k=0}^{n-1}Y_{k}$. As a result, you can use the independance between the $Y_k$ w.r.t to the filtration $\mathcal{F}_n$.
Comment: This is not something that the other answer writes, is it?


blending mode formula for hard-light, soft-light, color-dodge, color-burn?

Question: I'm trying to implement poor-man's blending modes for CSS, in anticipation of browsers rolling out support. (The CSS preprocessor I'm using is Stylus, which isn't important to the discussion.) I've found a source for blending mode calculations from the W3C SVG spec, but some of the equations give wildly different results from what's expected - specifically, hard-light, soft-light, color-dodge, and color-burn.
Does anyone know of more correct, reliable formulae for the blending modes in question? I'm premultiplying the RGB channels of each colour by their alpha.
Here's what I've got so far.
https://github.com/pdaoust/stylus-helpers/blob/master/blend.styl
Comment: See my answer [here](http://stackoverflow.com/questions/10713120/alpha-blending-layers-for-linear-light-mode/10713364#10713364) which points to Adobe's spec on how alpha blending works. It includes the above modes.
Comment: @user1118321 Thank you for the link! However, the spec seems to merely describe the effects of the above modes, rather than giving formulae for them.
Comment: Weird, they seem to have some of them, but not all. I thought they had them all. Dang.
Comment: Oh, I see - those ones describe how they work in terms of the other ones. You should be able to work them out from there. See pages 414-417.
Comment: Hm, interesting. I re-read those descriptions, and it does seem the HardLight and SoftLight are quite explicitly described, and it'll allow me to DRY a bit of my code. The ColorDodge and ColorBurn (which SoftLight relies on) are more ambiguously described -- I'm not sure what 'brighten' and 'reflect the source colour' mean in mathematical terms. Any ideas?
Comment: See the [Wikipedia page on blend modes for dodge and burn](http://en.wikipedia.org/wiki/Blend_modes#Dodge_and_burn). Dodge is basically bg / (1 - fg), and burn is basically [1 - (fg / (1 - bg))].
Answer: https://mouaif.wordpress.com/2009/01/05/photoshop-math-with-glsl-shaders/
Download the PhotoShopMathFp.hlsl all the equations are dont there for OPengl es
Answer: Follow this link. The formulas are very straightforward.
http://en.wikipedia.org/wiki/Blend_modes

Soft Light has the complete description.
HardLight is the same of Overlay, but with the images inverted. Follow the Overlay formula.
"The Color Dodge blend mode divides the bottom layer by the inverted top layer"
Comment: Hey, thank you for your answer! However, the term "images inverted" might be a bit misleading, as it implies a unitary operation over the image. Inverting images and then applying Overlay wouldn't actually result in HardLight. I think what you meant to say is that HardLight is similar to Overlay, but with the roles of the layers switched. This difference in layer roles is what distinguishes the two blending modes.


FreeBSD Ports: How can I see all dependencies for a port, and all subdependencies for those dependencies?

Question: I'm trying to build a port which depends on apache-ant.
I thought I could run make build-depends-list to see all dependencies required by this port:
# make build-depends-list
/usr/ports/devel/apache-ant
/usr/ports/java/jdk16
/usr/ports/math/gmp

But after installing everything, the port had a dependency list which was a mile long:
apache-ant-1.8.1 desktop-file-utils-0.15_2 gamin-0.1.10_4 gettext-0.18.1.1 gio-fam-backend-2.26.1 glib-2.26.1_1 gmp-5.0.1 inputproto-2.0 javavmwrapper-2.3.5 kbproto-1.0.4 libX11-1.3.3_1,1 libXau-1.0.5 libXdmcp-1.0.3 libXext-1.1.1,1 libXi-1.3,1 libXtst-1.1.0 libiconv-1.13.1_1 libpthread-stubs-0.3_3 libxcb-1.7 pcre-8.12 perl-5.10.1_3 pkg-config-0.25_1 python26-2.6.6 recordproto-1.14 unzip-6.0 xextproto-7.1.1 xproto

This dependency list is a rude surprise, and I would like to know about it before I commit to installing a port.
How can I see all dependencies, and all subdependencies for a port?
Answer: You are very close.  Try this instead:
make all-depends-list

That will recurse through all dependencies and print them for you.  To test different build scenarios and how they affect the dependency list, try things like:
make NOPORTDOCS=yes NOPORTEXAMPLES=yes all-depends-list

make WITHOUT_X11=yes all-depends-list

Here is the full set of dependency print targets:
all-depends-list
build-depends-list
run-depends-list
package-depends-list
pretty-print-build-depends-list
pretty-print-run-depends-list

Cheers,
Greg
Comment: Nevermind. They are documented in `man ports`.
Comment: Hi Greg, do you know where the dependency print targets are documented? Is there a specific man file? I don't have a question ... It's just for a deeper understanding. Thanks.
Answer: To list ports on which  depends:
pkg_info -rx "port-name"

To list ports which require :
pkg_info -Rx "port-name"

-- Answer from this website:http://daemon-notes.com/tips (thanks to Ross)
Comment: The command works; in pkgng you only have to remove the underscore: `pkg info -Rx 'port-name'`
Comment: Thanks for the response. However, I need to point out that the `pkg_*` tools were deprecated and replaced with [pkgng](https://wiki.freebsd.org/pkgng)
Answer: You would have to recursively get all subdependencies as well. There probably are some tools for that in the ports-mgmt category...
I use portmaster(8) for port management. It always gathers (sub)dependencies before compiling and installing a port:
~> portmaster --show-work devel/apache-ant
===>>> Port directory: /usr/ports/devel/apache-ant
===>>> Starting check for all dependencies
===>>> Gathering dependency list for devel/apache-ant from ports

===>>> Installed converters/libiconv
===>>> Installed devel/gettext
===>>> NOT INSTALLED            devel/gmake
===>>> Installed devel/libcheck
...

Answer: Most dependency lists are hard to parse at a glance.  I prefer using this wrapper script by firstname.lastname@example.com, because it displays a nice, nested list with both upward and downward dependencies:
$ pkg_depends.pl ruby18-bdb-0.6.5_1
Package ruby18-bdb-0.6.5_1 depends on:
    db41-4.1.25_4
    ruby-22.214.171.124_5,1
Package ruby18-bdb-0.6.5_1 is required by:
    portupgrade-2.4.7,2

Running it without arguments can produce a very long list, because it shows all dependency chains for all files, so I usually only recommend running it for a particular port.
Answer: few years after ...
my solution for get packages installed (for backup purpose)
I have solution for FreeBSD 12+ (bash)
for i in $( cd /usr/ports/databases/mysql80-server/ && make run-depends-list); do pkg create -o /root/packages $( echo $i | rev | cut -d '/' -f1 | rev ); done

but U can change pkg command from create to install and change run to build
for i in $( cd /usr/ports/databases/mysql80-server/ && make build-depends-list); do pkg install $( echo $i | rev | cut -d '/' -f1 | rev ); done


Accessing hreflang in a preprocessor or twig layer

Question: How do I access this link in either the twig layer or a preprocessor in Drupal 8. I need to modify to edit the hreflang.  Thanks
<link href="http://www.drupal.com/au" rel="alternate" hreflang="au" />

Answer: function MODULE_page_attachments_alter(array &$attachments) {
 foreach ($attachments['#attached']['html_head'] as $can_key => $can_value) {
       foreach ($can_value as $low_value) {
          if (isset($low_value['#attributes']['rel']) && $low_value['#attributes']['rel'] == 'alternate') {
             // Unset canonical tags if present there.
             $attachments['#attached']['html_head'][$can_key]['#attributes']['hreflang'] = 'your value';
           }
        }
     }
}


Extension theorem of twice continuously differentiable functions?

Question: Is there a theorem which guarantees me that any function $f$ with bounded first and second order derivatives defined over a compact interval of $\mathbb{R}^2$ can be extended to a twice continuously differentiable function $F$ on the whole space $\mathbb{R}^3$?
Answer: I think your condition is not enough. Since initially you only require the function have bounded second derivative on a compact subset, since differentiable doesn't imply continuous differentiable, it may not be continuous differentiable on the compact set, so it can't be extended to $\mathbb{R}^3$.
An example is
$$f(x) = x^{4} \cdot \sin\left(\frac{1}{x}\right)$$
$$f(0) = 0$$
The $2$nd derivative of $f(x)$ exists for each value of $x$, bounded at the neighborhood of $0$ but not continuous at  $x = 0$.
Comment: Good point! Thank you.  If you add continously differentiable, does there then exist such a theorem?
(I dont know if this is somehow important, but in my particular case I have a symmetric function f(x,y))


ML Estimator parameter of bimodal, polynomial distribution

Question: Let $X_1, \ldots X_n$ i.i.d with density of (using the indicator function $\mathbf 1$)
$$f(x|\mu) = \frac 3 2 (x-\mu)^2 \cdot \mathbf 1_{[\mu-1, \mu+1]}(x)
  = \left\{
        \begin{array}{ll}
            \frac{3}{2}(x-\mu)^2 & \quad \mu-1 \le x \le \mu+1 \\
            0 & \quad \textrm{otherwise}
        \end{array}
    \right.$$
The moment method estimator is easy to find, $\hat \mu_{MM} = \bar X_n$. I also want to find the maximum-likelihood estimator $\hat \mu_{ML}$, but I'm a bit stumped.
My thought process:

Disregarding the $x \in [\mu - 1, \mu+1]$ constraint gives non-sensical results, suggesting that $\hat \mu_{ML} \rightarrow \pm \infty$
The $|x-\mu| \le 1$ enforces that $\hat \mu_{ML} \in [\max_i(X_i)-1, \min_i(X_i)+1]$. That is a tight bound with increasing $n$, especially, as the distribution is weighted so heavily towards the edges. The problem is that "a tight bound" is not the estimator itself.
Combining the two approaches, I find
$$\hat \mu_{ML} = \operatorname{argmax}_{\mu} \left (\mathbf 1_{[\max_i(X_i)-1, \min_i(X_i)+1]}(\mu) \cdot \prod_i (X_i - \mu)^2\right)$$
Sadly, I can't simplify this further, or leverage it to calculate a value for $\hat \mu_{ML}$.
Clearly, $\hat \mu^* = \frac 1 2 (\max_i(X_i) + \min_i(X_i))$ is a fairly reasonable estimator, but it does not seem to be the ML estimator, since it disregards the information contained in the $\prod$-term above.

Am I missing something, or is there really no closed-form expression for $\hat \mu_{ML}$? Any pointers would be appreciated.
Edit: Following @whuber's suggestion, I plotted $L(\mu | X_1 = 0, X_2 = 0.15, X_3=1.7, X_4=1.8)$:

As you can see, the maximum is not at the edges, but in the interior. It can be at the edges for different choices of the observed $X_i$. The same plot without the $|X_i - \mu| \le 1$ restriction with a slightly wider $\mu$ axis:

It's an 8th order polynomial for n=4. $\hat \mu$ would correspond to the maximum around ~0.9, but there are other maxima (one between each consecutive pairs of $X_i$).
Differentiating w.r.t. $\mu$ gives a sum-of-($2n-1$)-order polynomials, that I don't see how to solve. I'm a bit lost here, to be honest.
Comment: I think the situation might become obvious were you to graph the likelihood for a particular value (or values) of the $x_i$ and consider how to find its maximum.
Comment: @whuber: I plotted $L(\mu | X_1)$ for various $X_1$, and $L(\mu | X_1=0, X_2=1.7)$. The last was interesting, because it showed a maximum. For $n=2$, this gives a 4th order polynomial $L(\mu)$, order 3 after $d/d\mu$. No idea how to solve this for larger $n$. I got to $2\sum_i (x_i-\mu) \prod_{j \ne i} (x_j-\mu)^2 = 0$ but don't understand how to progress from here.
Comment: @StubbornAtom: I considered your $\hat \mu$, but all I can think of is plugging that into the argmax-$\prod$ above, and I don't see how that helps me. I guess I don't see where I have to start to turn your $c$-interpolation approach into a solution.
Comment: Hmm. Following whuber's suggestion, I guess the maximum occurs at the endpoints of the domain of the likelihood.
Comment: @StubbornAtom: That doesn't appear to be true, see the edit in my question. There can be one or more internal maxima. Each observation $x_i$ zero to the $f(\mu)$ polynomial, with maxima between the $\mu=x_i$ zeros.

If the $x_i$ all lie close together (e.g. all in the left lobe of the distribution), then the maximum is not at any $\frac{\partial f}{\partial \mu}=0$ point, but at the edge of the domain, as you mention.

Multiple maxima, or maxima at non-critical-points: I don't know how to tackle that analytically.
Comment: @StubbornAtom is not far off.  Using simulations for sample sizes between 3 and 30 the maximum likelihood estimate will be one of the endpoints of the domain around 80% of the time.  Also with a sample size of 30 only about 0.23% of such samples will have any observations between those the two domain endpoints.  And for large sample sizes the width of the domain will be pretty small so one can't help being very near one of the endpoints.
Answer: This is quite a tricky problem, and I think it will require a difficult optimisation of a function that will have multiple local maxima in general.  Given an observed sample vector $\mathbf{x} = (x_1,...,x_n)$, your likelihood function is:
$$\begin{align}
L_\mathbf{x}(\mu)
&= \prod_{i=1}^n f(x_i|\mu) \\[6pt]
&= \text{const.} \times \prod_{i=1}^n (\mu-x_i)^2 \cdot \mathbb{I}(\mu-1 \leqslant x_i \leqslant \mu+1) \\[6pt]
&= \text{const.} \times \mathbb{I}(\max x_i-1 \leqslant \mu \leqslant \min x_i+1) \prod_{i=1}^n (\mu-x_i)^2. \\[6pt]
\end{align}$$
If $\max x_i - \min x_i > 2$ you have a problem with your model specification --- we leave this case aside.  Assuming your sample vector satisfies the requirement $\max x_i - \min x_i \leqslant 2$, the corresponding log-likelihood function over this range (removing the previous constant) is:
$$\begin{align}
\ell_\mathbf{x}(\mu)
&= 2 \sum_{i=1}^n \log|\mu-x_i|, \\[6pt]
\end{align}$$
and at all values $\mu \notin \{ x_1,...,x_n \}$ the score and information functions are given respectively by:
$$\begin{align}
s_\mathbf{x}(\mu)
\equiv \frac{d \ell_\mathbb{x}}{d \mu}(\mu)
&= \sum_{i=1}^n \frac{2}{\mu-x_i}, \\[6pt]
I_\mathbf{x}(\mu)
\equiv - \frac{d^2 \ell_\mathbb{x}}{d \mu^2}(\mu)
&= \sum_{i=1}^n \frac{2}{(\mu-x_i)^2} >0. \\[6pt]
\end{align}$$
We can also find the score values at the extremes of the allowable parameter range, which are:
$$\begin{align}
s_{\mathbf{x}, \text{lower}}
\equiv s_\mathbf{x}(\max x_i - 1)
&= \sum_{i=1}^n \frac{2}{\max x_i - x_i - 1}, \\[6pt]
s_{\mathbf{x}, \text{upper}}
\equiv s_\mathbf{x}(\min x_i + 1)
&= \sum_{i=1}^n \frac{2}{\min x_i - x_i + 1}. \\[6pt]
\end{align}$$
The log-likelihood function has poles (with negitive infinte value) at all points $\mu \in \{ x_1,...,x_n \}$ so you need to examine the function on a piecewise basis in the regions between the points:
$$\max x_i-1 \leqslant x_{(1)} \leqslant \cdots \leqslant x_{(n)} \leqslant \min x_i+1.$$
Between each of its poles (occurring at the data values) the function is strictly concave so it will have a number of local maxima.  Between the endpoints of the allowable parameter range and the nearest poles it is also strictly concave and may be monotonic.  It is simple to compute the values $s_{\mathbf{x}, \text{lower}}$ and $s_{\mathbf{x}, \text{upper}}$ to see if the log-likelihood is monotonic in the end regions, which allows you to determine whether the local maximising point in that region is at a boundary.  For all other regions the local maximum will be in the interior at the unique critical point.
Now, so far as I can see, the only way I can see to find the MLE is to compute each of the local maxima in the pieces separated by the values above and then compare them to see which is the biggest.  In each region (except possibly the end regions) the MLE will be in the interior of the region at the unique critical point defined by the score equation $s_\mathbf{x}(\hat{\mu}) = 0$.  This can be written more clearly as:
$$0 = \frac{1}{\hat{\mu}-x_{(1)}} + \cdots + \frac{1}{\hat{\mu}-x_{(n)}}.$$
This equation gives the local maximising point in each region; it  will need to be solved numerically with the range constraint for each region.  Once you compute all the local maxima you can compare them to see which is the biggest, which will give you the MLE.
Comment: Thank you for your answer! I see some problems: $\sum_i |\hat\mu-x_i|^{-1}$ is a sum of strictly positive values if $x_i, \hat \mu$ are finite, and thus can't be zero, numerical or not. More generally, the log-likelihood approach confuses things *a lot* because it introduces infinities. Yes, $I(x) > 0$, so one assumes $\mathcal l$ is concave - but that's wrong, since there is pole/negative infinity at every $\hat \mu=x_i$. Thus we can't assert monotony on $\mathcal l$ and -- as described in my comments on the question -- there can be multiple maxima within the lower/upper bound.
Comment: Sorry about that --- I had a mathematical error.  I have now edited to correct this.


How to practice singing

Question: So I've been practicing singing for about 4 months now about 4 hr a week doing 30min sessions when I have time. I've started recording myself over the past month to see what I sound like in recordings. I sound fairly decent but I feel like I'm still missing a clear voice a little and that I'm somewhat flat and lifeless on some recordings.
So what I wanted to ask is how to practice/what a good routine is. I plan on practicing 1hr a day soon. My current routine is 5-min warm-up exercises like scales, humming, and lip roles. Then I practice singing songs that I like that have clear vocals. I've been focusing on 5 different songs and been taking them apart trying to learn each.
I've search online but I'm still unclear what actual vocalists and even established artist do for practice. I'm 20 now I started in Dec, I have been wanting to practice now regularly for about 2 years just from thinking my voice is somewhat decent and I really love music and I want to create some amazing music.
I've also been practicing guitar a little after I sing. I'm not totally sure how musically gifted I am but I played sax in elementary school for about 5 years and never grasped musical concepts since I seemed to be more concerned with just playing what sounded cool to me and ignored all that stuff.
My plan is to keep practicing and then post to youtube/soundcloud when I feel my voice is at an adequate level and start writing some of my own music.
The songs I have been practicing are: I'll be, Reason, Everlong, If you could only see, Drive
If requested I'll make some non-phone voice memo recordings to share.
Thanks.
Comment: Welcome to Music SE.  Be sure to take the tour at https://music.stackexchange.com/Tour and earn the "Informed" badge.
Comment: Get yourself along to a kareoke, or better still, an open mic night, and try out a couple of your songs. The oft chanted mantra of 'find a teacher' needs mentioning, if even for a couple of what should be very productive sessions.
Answer: I sound fairly decent but I feel like I'm still missing a clear voice a little and that I'm somewhat flat and lifeless on some recordings.[...]My current routine is 5-min warm-up exercises like scales, humming, and lip roles. Then I practice singing songs that I like that have clear vocals.
You are not satisfied with your tone.  So you'll work 5 minutes on your tone and 55 minutes on your interpretation.  On songs that you like, that you feel good about already because of the song rather than your singing.
I think you severely underestimate what you call "warmup exercises".  Even when used as a mere warmup, 5 minutes would be an emergency measure.  But the purpose of a warmup is to warm up and to quickly realign your voice and vocal production to its proper form rather than having to jump start it.
To realign to your proper form, you need to have it in the first place.  If you spend an hour, it would be more typical to do 25 minutes of what you call warmup exercises (which are only partly warmup), 25 minutes on one to three song-like singing exercises in the order of 16 measure length, like that of Vaccai or Sieber (those are for classical singing/voice training, there might be something else for pop/musical and similar but it's not like the fundamental fitness and production should be much different), and 10 minutes on stuff you like, assuming that you like it because you pretty much already know how you want it to sound.
Spending much less on the first two categories is a bit of a waste of time.  Also you should seriously consider taking vocal lessons until you are reasonably confident to know what and how and whereto to work on in the 25/25 parts, and occasionally afterwards.  At least get some reasonably recommended/qualified training material/CD.  That will not match your current requirements at a given time like a good teacher does but it's at least a reference point.
Comment: If I could upvote you twice I would.  Excellent advice, Mr. user28900.
Answer: Remember the old joke about the guy who gets into a taxi in New York? He asks the driver which way is it to Carnegie Hall? And the driver replies, "Practice, man, practice."
Whatever routine you can stick with is good. Every bit helps.
It is very very good that you are taking the step of listening to yourself recorded. That can give you excellent feedback on sections and techniques you need to focus on.
Don't forget that aA huge part of practice is developing the muscle memory so your vocal tract can do what your brain asks for, without you having to micromanage each muscle. In that sense it is like typing.
The only way for it to be ingrained is for it to be second nature.
So keep up what your doing, and take Mr. user28900's advice, too.  Your recordings will help you with your development.
I wish you the best.  You're on the right track.

How to practice singing


When will the quadratic equation $z^2+z_1z+z_0=0$ have a root lie on the unit circle

Question: Very similar to this question, but what if the coefficients are complex?
Is there a necessary and sufficient condition to guarentee that there is at least a root on unit circle for $z^2+z_1z+z_0=0$ where $z_{0,1} \in \mathbb{C}$ ?
Comment: A useful sufficient but not necessary condition: if $z_0 = 1$ and $z_1 \in [-2, 2] \subseteq \mathbb{R}$.
Answer: If $\,z_0=0\,$ the roots are $\,\{0, -z_1\}\,$, therefore the condition for a root on the unit circle is $\,|z_1|=1\,$. The following will assume $\,z_0 \ne 0\,$.
Let $\,z_1 = -2b, \,z_0 = c, \,b^2 - c = \delta^2\,$, then the equation is $\,z^2 - 2bz+c=0\,$ and the roots $\,b \pm \delta\,$ are the diagonals of the parallelogram with sides $\,b, \delta\,$. By the parallelogram law:
$$
|b-\delta|^2 + |b+\delta|^2 = 2\left(|b|^2 + |\delta|^2\right)
$$
One of $\,b \pm \delta\,$ has magnitude $\,1\,$ iff the other one has magnitude $\,|c| \ne 0\,$ by Vieta's relations, so:
$$
1 + |c|^2 = 2\left(|b|^2 + |\delta|^2\right) \quad\iff\quad 2\,|b^2 - c| = 1 + |c|^2 - 2\,|b|^2
$$
Written in terms of $\,z_1, z_0\,$, the condition is:
$$
|z_1^2 - 4 z_0| \,=\, 2 + 2 |z_0|^2 -  |z_1|^2 \tag{1}
$$

[ EDIT ] $\;$ The following translates $\,(1)\,$ into equivalent conditions $\,(2.a), (2.b)\,$ in terms of $\,z_1, z_0\,$ alone, without involving the magnitude of the discriminant $\,|z_1^2-4z_0|\,$.
The RHS of $\,(1)\,$ must be non-negative:
$$
|z_1|^2 \le 2 + 2 |z_0|^2 \tag{2.a}
$$
The squared magnitudes must match:
$$
\require{cancel}
\begin{align}
|z_1^2 - 4 z_0|^2 &\,=\, (2 + 2 |z_0|^2 -  |z_1|^2)^2
\\ (z_1^2 - 4 z_0)(\bar z_1^2 - 4 \bar z_0) &\,=\, (2 + 2 |z_0|^2 -  |z_1|^2)^2
\\ \cancel{|z_1|^4} + 16 |z_0|^2 - 8 \text{Re}(z_1^2 \bar z_0) &\,=\, 4 + 4|z_0|^4+\cancel{|z_1|^4} + 8 |z_0|^2 - 4 |z_1|^2 - 4 |z_1|^2|z_0|^2
\end{align}
$$
$$
\\ 2 |z_0|^2 - 2 \text{Re}(z_1^2 \bar z_0) \,=\, 1 + |z_0|^4 - |z_1|^2 - |z_1|^2 |z_0|^2 \tag{2.b}
$$
$\,(2.b)\,$ is equivalent to the last equality in @eyeballfrog's answer. When $\,|z_0|=1\,$, $\,(2.a)\,$ reduces to $\,|z_1| \le 2\,$, and $\,(2.b)\,$ to $\,\text{Re}(z_1^2 \bar z_0) \,=\, |z_1|^2\,$, or $\,z_1^2 \bar z_0 = |z_1|^2\,$ because the magnitudes are equal on the two sides, which again matches the other answer.

[ EDIT #2 ] $\;-\;$ For reference, this is the purely algebraic proof of $\,(1)\,$ as previously posted.
With the same notations, a root is on the unit circle iff for (at least) one choice of the $\,\pm\,$ signs:
$$
\begin{align}
1 = |b \pm \delta|^2 &= (b \pm \delta)(\bar b \pm \bar \delta)
\\ &= |b|^2 + |\delta|^2 \pm (b \bar \delta + \bar b \delta)
\\ \iff\quad \pm (b \bar \delta + \bar b \delta) &= 1 - |b|^2 - |\delta|^2
\\ \iff\quad (b \bar \delta + \bar b \delta)^2 &= (1 - |b|^2 - |\delta|^2)^2
\end{align}
$$
Moving everything to one side, expanding and collecting:
$$
\begin{align}
0 &= (1 - |b|^2 - |\delta|^2)^2 - (b \bar \delta + \bar b \delta)^2
\\ &= 1 + |b|^4 + |\delta|^4 - 2|b|^2 - 2|\delta|^2+\cancel{2|b|^2|\delta|^2} - b^2 \bar\delta^2 - \bar b^2 \delta^2 -\cancel{ 2 |b|^2|\delta|^2 }
\\ &=1 + |b|^4 + (b^2 - c)(\bar b^2 - \bar c) - 2 |b|^2 - 2 |\delta|^2 - b^2(\bar b^2 - \bar c) - \bar b^2(b^2-c)
\\ &= 1 + \cancel{|b|^4} + \cancel{|b|^4} + |c|^2 - \bcancel{b^2 \bar c} - \bcancel{\bar b^2 c} -2 |b|^2 - 2 |\delta|^2 - \cancel{|b|^4} + \bcancel{b^2 \bar c} - \cancel{|b|^4} + \bcancel{\bar b^2 c}
\\ &= 1 + |c|^2 - 2 |b|^2 - 2 |\delta|^2
\end{align}
$$
$$
\begin{align*}
&\iff\quad 2\, |b^2 - c| \,=\, 1 + |c|^2 -  2\, |b|^2 \quad\quad\quad\quad
\end{align*}
$$
Comment: Interesting. Is your condition here equivalent to mine?
Comment: That looks like it should factor somehow, and yet it doesn't seem to.
Comment: @eyeballfrog You can (re)group the terms a few ways, but I don't think you can get any nice factorization.
Comment: @eyeballfrog My first answer was incomplete, and fixing it would have made it too close to yours (+1), so I reworked it along a different path.
Comment: @eyeballfrog Yes, indeed, see the edit.
Answer: $z^2 + z_1z + z_0$ has solutions with $|z| = 1$ if and only if the following equation does:
$$
z + z_1 + z_0z^* = 0.
$$
Taking complex conjugates and doing some linear algebra on them gives
$$
(|z_0|^2-1)z = z_1 - z_0z_1^*.
$$
If $|z_0| =  1$, we immediately see that $z_1 = z_1^* z_0$, or equivalently $z_1 = \pm|z_1|z_0^{1/2}$. Putting this into the original equation and simplifying gives
$$
2\mathrm{Re}[zz_0^{-1/2}] \pm |z_1| = 0,
$$
which has solutions when $|z_1| \le 2$.
For $|z_0|\ne 1$, we can just solve for $z$ to get
$$
z = \frac{z_1-z_0z_1^*}{|z_0|^2 - 1}.
$$
This will give $|z| = 1$ provided that
$$
(z_1-z_0z_1^*)(z_1^* - z_0^*z_1) = |z_1|^2(1+|z_0
|^2)-2\mathrm{Re}[z_0^*z_1^2] = (1-|z_0|^2)^2.
$$
Thus, there are two categories of equations $z^2 + z_1z + z_0 = 0$ that have solutions on the unit circle. The first is of the form
$$
z^2 + 2\cos\theta e^{i\phi}z + e^{2i\phi} = 0
$$
for real $\theta,\phi$, which has both solutions on the unit circle: $z = e^{i(\phi\pm\theta)}$. Second is those whose coefficients satisfy
$$
(1-|z_0|^2)^2 + 2\mathrm{Re}[z_0^*z_1^2] = |z_1|^2(1+|z_0|^2)
$$
with $|z_0| \ne 1$, which have only one solution on the unit circle: $z = (z_1-z_0z_1^*)/(|z_0|^2 - 1)$.
Comment: Amazing! Thanks for such a quick and elegant solution!


Calculus - limit calculate

Question: Calculate the limit not using L'Hospitale rule:
$\lim\limits _{x \to 2} \frac{\sqrt{x^2+12}-4}{2-\sqrt{x^3-4}}$
I tried multiplying for both conjugates but I got nothing. I think I have to make something with $\sqrt{x^3-4}\cdot \sqrt{x^2+12}$, but I don't know what to do.
Answer: \begin{align}
\lim_{x\to2}\frac{\sqrt{x^2+12}-4}{2-\sqrt{x^3-4}}&=\lim_{x\to2}\frac{\sqrt{x^2+12}-4}{2-\sqrt{x^3-4}}\color{blue}{\cdot\frac{\sqrt{x^2+12}+4}{\sqrt{x^2+12}+4}\cdot\frac{2+\sqrt{x^3-4}}{2+\sqrt{x^3-4}}}\\
&=\lim_{x\to2}\frac{2+\sqrt{x^3-4}}{\sqrt{x^2+12}+4}\cdot\frac{(x^2+12)-(16)}{(4)-(x^3-4)}\\
&=\frac12\cdot\lim_{x\to2}\frac{x^2-4}{8-x^3}
\end{align}
Can you take it from here?
Comment: Thanks! I did what you did, but I didn't multiply for both conjugates at the same time. I did each time with one, the I restarted and did with the another one ant didn't get anywhere, that was my mistake.

Calculus - limit calculate


Variable number of elements in 2d array

Question: I want to initialize a 2d array which its elements number in each row is not constant.
Something like:
int a[][] = {{1,2,3}, {4,5}};
How do I achieve that?
Comment: In C, You can't!!!!!!!!
Comment: You just did. Those values can be changed, since you declared them as not `const`. If you want the number of elements to change, then you must use another data structure, such as `vector`.
Comment: try [std::vector of std::vector of nt](http://ideone.com/oMT48x)
Answer: You can't achieve this using a raw 2d array. What you can do is use a vector that holds other vectors. For instance in your case you could do:
std::vector<std::vector<int>> a = { {1, 2, 3}, {4, 5} };

Variable number of elements in 2d array


How to prove that the g.c.d is equal to the prime factorization raised to the minimum of two powers

Question: for the prime factorization of $a$ and $b$ as $$a = p_1^{\alpha_1}p_2^{\alpha_2}\cdots{p_t}^{\alpha_t}$$ and $$b = p_1^{\beta_1} p_2^{\beta_2} \cdots p_s^{\beta_s}.$$ I want to prove that $d = gcd(a,b)$ is equal to $${p_1}^{\min(\alpha_1, \beta_1)}{p_2}^{\min(\alpha_2, \beta_2)}\cdots {p_r}^{\min(\alpha_r\beta_r)}$$ so I begin by proving that $d$ is a common divisor of $a$ and $b$.
$$\frac{a}{d} = \frac{p_1^{\alpha_1} p_2^{\alpha_2} \cdots p_t^{\alpha_t}}{p_1^{\min(\alpha_1\beta_1)}p_2^{\min(\alpha_2\beta_2)} \cdots {p_s}^{\min(\alpha_s\beta_s)}}$$ and
$$\frac{b}{d} = \frac{p_1^{\beta_1}p_2^{\beta_2} \cdots p_s^{\beta_s}}{p_1^{\min(\alpha_1\beta_1)}{p_2}^{\min(\alpha_2\beta_2)} \cdots p_s^{\min(\alpha_s\beta_s)}}$$
I don't know if $a$ is always divisible by $d$ in $\mathbb{Z^+}$ I'm also very new to proofs can I have some guidance?
Comment: assuming the fundamental theorem of arithmetic ? or would you like to prove it too ? :-)  and you'll need to use something like $\forall$, $\exists$ or a proof by induction or apply some theorem..
Comment: You can see that $a$ is divisible by $d$ because all of the prime factors in $d$ appear in $a$, and the powers of those factors are less than those in $a$. So you will end up with $a/d = p_1^{\alpha_1 - min(\alpha_1,\beta_1)}\ldots p_t^{\alpha_t - \min(\alpha_t,\beta_t)} \in\mathbb{Z}$
Comment: There isn't much to prove beyond definition.  If p^n divides both a and b then p^n divides (a,b) so as p^min divides a and b p^min divides (a,b).  If p^m doesn't divide both (or divides neither) then p^m doesn't divide (a,b) as p^greater than min doesn't divide both, the factorization is just the product of the min.  It's almost by definition.  But what I suggest you work on is the notation and indexing.  p_1... p_s and p_1...p_t implies a has only the same prime factors as b.  I'd say something to the effect of: ... to be continued.
Comment: ... cont.  To be clearer that a and b's prime factors may differ, or may share to unknown degrees, I've say something like: "let p_1....p_t be the distinct prime factors of a and b (some p_i may be a factor of both a and be,, some of a only, and some of b only)  so that a = $p_1^{a_1}...p_t^{a_t} $ (although some of the a_i might be 0 if that p_i is not a factor of a) and b=$p_1^{b_1}...p_t^{b_t} $ (ditto)"
Answer: Remember what divisibility means: $d$ divides $a$ if I can find some integer $c$ such that $dc = a$.
Let's look at one term of your $\frac{a}{d}$ fraction: $\frac{p_1^{\alpha_1}}{p_1^{min(\alpha_1, \beta_1)}}$.
Since $min(\alpha_1, \beta_1) \le \alpha_1$, this fraction has an integer value of $p_1^{\alpha_1 - min(\alpha_1, \beta_1)}$
You can then do this for every prime $p$ in your expansions of both $\frac{a}{d}$ and $\frac{b}{d}$
You're not quite done, though: you've only shown that $d$ is a common divisor of $a$ and $b$ after you're done with these steps. You still need to show that it's the greatest common divisor: this is true if a common divisor of $a$ and $b$, call it $z$, divides $d$. If every common divisor divides $d$ then you can be sure that $d$ is your greatest common divisor. I'll leave this step to you.
Let me know in a comment if you have any questions!
Comment: Okay let me know if this is correct: let $z | a$ and $z | b$ so $z$ is a common divisor of $a$ and $b$. $z$ must not divide $d$ to be the g.c.d. $z = \prod{p_i}^{\delta_i}$. So, $\frac{a}{z} = \frac{\prod p_i^{\alpha_i}}{\prod p_i^{\delta_i}}$ and $\frac{a}{z} = \frac{\prod p_i^{\beta_i}}{\prod p_i^{\delta_i}}$ so if $z$ were to be the g.c.d it should try to be as large as possible without being greater than $\alpha_i$ when dividing $a$ or $\beta_i$ when dividing $b$ so it should be the minimum of the two. That would make it equal to $d$. It makes sense now :D
Answer: In $a / d$ you have factors
$$
F_i = \frac{p_i^{\alpha_i}}{p_i^{\min(\alpha_i, \beta_i)}}
$$
and two cases:

$\min(\alpha_i, \beta_i) = \alpha_i$ then $F_i = 1$ and
$\min(\alpha_i, \beta_i) = \beta_i$ then $\alpha_i \ge \beta_i$ and
$\alpha_i - \beta_i \ge 0$ so $F_i = p_i^{\alpha_i - \beta_i} \in \mathbb{Z}$.

This gives $F_i \in \mathbb{Z}$ and for the product $a/d \in \mathbb{Z}$.
A similar argument yields $b/d \in \mathbb{Z}$ and we see that $d$ is a common divisor of $a$ and $b$.
Comment: I think you mean $\alpha_i > \beta_i$ since the above case covers when they're equal. Thank you though this is useful.
Comment: actually maybe not. The above case covers $\alpha_i < \beta_i$
Answer: You have the right idea but perhaps a nicer way to put it would the this.
The $\gcd(a,b)$ has a prime factorization.  Let $p$ be a prime factor of $gcd(a,b)$.  Then $p$ is a prime factor of both $a$ and $b$.  So if we write the prime factor of $\gcd(a,b)$ as $\gcd(a,b) = \prod p_i^{c_i}$ then we can write the prime factor of $a$ as $a = \prod q_k^{d_k} \prod p_i^{\alpha_i}$ where $p_i|\gcd(a,b)$ (i.e. $p_i$ divides both $a$ and $b$) and $q_k$ does not (ie. $q_k$ divides $a$ but not $b$). And likewise we can write the prime factor of $b$ as $b = \prod r_k^{e_k}\prod p_i^{\beta_i}$ (where $r_k$ divides $b$ but not $a$ and $p_i$ divides both $a$ and $b$).
Okay... so $\gcd(a,b)|a$ so each $p_i^{c_i}|a$ so $c_i \le \alpha_i$ and likewise $p_i^{c_i}|b$ so $c_i \le \beta_i$ so $c_i \le \min(\alpha_i, \beta_i)$.
But $\min(\alpha_i, \beta_i)\le \alpha_i$ so $p^{\min(\alpha_i, \beta_i)}$ divides $p^{\alpha_i}$ which divides $a$ so $p^{\min(\alpha_i, \beta_i)}$ divides $a$.  And likewise $\min(\alpha_i, \beta_i)\le \beta_i$ so $p^{\min(\alpha_i, \beta_i)}$ divides $p^{\beta_i}$ which divides $b$ so $p^{\min(\alpha_i, \beta_i)}$ divides $b$.  So $p^{\min(\alpha_i, \beta_i)}|\gcd(a,b)$.
So $\min(\alpha_i, \beta_i) \le c_i$.
So $c_i = \min(\alpha_i, \beta_i)$ and $\gcd(a,b) = \prod p_i^{\min(\alpha_i,\beta_i)}$.


How so I sample from a subset?

Question: So my problem is that I have a distribution and a population.
My population is: [1, 2, 3, 4, 5]
The distribution is: [0.1, 0, 0.3, 0.6, 0], for each corresponding element.
So for example 1 has a 0.1 chance occurring.
Now my problem is that at any time I am given a subset of the population.
So for example I can have: [2,4]. But I want to keep the same distribution.
So that means the distribution would be [0, 0.6], but this doesn't make sense.. It doesn't add up to one.
Is there a way to keep the same probabilities ? I hope I am making sense.
Answer: One option would be to sample according to the distribution. Then you have no chance to sample [2] because it has 0 probability to be sampled.
Also, you should think about sample size. You cannot have the same distribution if you will sample only one element. The more elements you have in subsample, the more your distribution will be similar to the initial one.
Answer: If my understanding is correct, you may need to check the definition of conditional probability.
Suppose your new sample is chosen from a subset like A={2,4}, then the probability of A=2 would be
$$
Pr = \frac{0}{0+0.6} = 0.
$$
Hope this could help you.
Comment: @test I won't call it bayes here, although bayesian formula is indeed from the conditional probability :) Here it is just a frequentist problem.
Comment: is this the bayes rule you shared ?

How so I sample from a subset?


Partial derivative reciprocal theorem

Question: Is the reciprocal of a partial derivative always equal to 1 divided by that partial derivative? I.e. Is it true that;
$$\frac{1}{\frac{\partial x_1}{\partial x_2}} = \frac{\partial x_2}{\partial x_1} $$
Answer: Not always. E.g. if $x \equiv x(r,\theta)=r\cos \theta$ and $y \equiv y(r,\theta)= r\sin \theta$ (polar coordinates), then $r \equiv r(x,y)= \sqrt{x^2+y^2}$, so $$\frac{\partial x}{\partial r} = \cos \theta = \frac{x}{r}$$ and also $$\frac{\partial r}{\partial x} = \frac{x}{\sqrt{x^2+y^2}} = \frac{x}{r} = \frac{\partial x}{\partial r}.$$
Comment: I see... in general is there a rule that you know of for switching between $\frac{\partial x_1}{\partial x_2}$ and $\frac{\partial x_2}{\partial x_1}$
Comment: Do you know, when does the reciprocal rule hold/not hold?

Partial derivative reciprocal theorem


How to derive this conditional distribution function for a Restricted Boltzmann Machine?

Question: I am following along Ian Goodfellow's new Deep Learning book and, reading the last chapter, I am confused about equations 20.7-20.9.
We have a joint distribution function, $P(v,h)$, and we are interested in finding the conditional distribution function, $P(h|v)$. If, from the definition of the Restricted Boltzmann Machine,
$$
P(v, h) = \frac{1}{Z} \exp(b^Tv +c^Th + v^TWh)
$$
where $Z$ is the normalizing constant,
$$
Z = \sum_v \sum_h \exp(b^Tv +c^Th + v^TWh).
$$
$P(h|v)$ is then (copied from the chapter):
\begin{align}
P(h|v) &= \frac{P(h,v)}{P(v)} \tag{20.7}\\[5pt]
&= \frac{1}{P(v)}\frac{1}{Z}\exp(b^Tv +c^Th + v^TWh) \tag{20.8}\\[5pt]
&= \frac{1}{Z'}\exp(c^Th + v^TWh) \tag{20.9}
\end{align}
That last step is where I am confused. What is $Z'$ -- there is nothing about that in the text? Is it some other constant that serves as a new normalizing constant or is it actually a derivative with respect to either $v$ or $h$? Could someone fill in some missing steps?
Answer: P(h/v) implies v is given/known. So 1/Z' should lump together all the constant terms i.e. exp(b'v)/(P(v) * Z)
Answer: In my opinion, what happens here is treating P(h|v) as a "function of h, knowing v". Everything what has not a h in itself is treated as a constant part and put in a new normalizing constant - Z'.
Intuitively - computations of a partition constant - Z or Z' - are intractable. That's why you use e.g. a Monte Carlo method to approximate it. That's why - in my opinion - author wasn't concentrated on full scrutiny during writing this set of equations.


Newton method implementation in matlab

Question: I wanted to implement the newton method. My code is so far:
f is a function-handle, df the differentiate f (also a function-handle) and x is the start value.
It works for some functions, but for example when I ask for
newton(@(x) x^2,@(x) 2*x,1)

it comes in an infinite loop. How to fix this?
Answer: The usual check for termination for Newton's method is to see if the result of another iteration is "very close" to the previous answer, but you're using the check:
if abs(xn) == abs(x)

which basically requires the two values to be identical (except you've used abs, which is a bug since it would accept an answer that's so wrong that an iteration flips the sign).  For some problems, this might work, but this is very likely to lead to an infinite loop with the iterations cycling through a set of very close values.
Change your termination test to:
if abs(xn-x) < 0.0000001    (or something else very small)

which tests to see if xn and x differ by no more than the very small value given, and that should work.
Comment: Since the root of x^2=0 is 0, that *is* the root to within 0.0000001.
Comment: You can use the `round` function to round to a fixed number of decimal places.  Will that do what you want?
Comment: Okay, thanks! Is there any way to make MATLAB give back 0 when the number is very small?
Comment: Is there any way to calculate the exact roots (to compute the divisions)?
Comment: What do you mean by "to compute the divisions"?
Comment: For example when I ask for newton(@(x) x^2 - 2, @(x) 2*x, 1), I get 886731088897/627013566048, which is ~1.14. But I want MATLAB to show 1.14 instead of the division.

Newton method implementation in matlab


How to keep Protein ID when retrieving coding sequences with rentrez

Question: I have a bunch of protein IDs and I need to retrieve the corresponding coding sequences (CDSs). I have managed to retrieve the CDSs but the names of each sequence change from XP* to XM*, and I need to retain the XP* header for each sequence.
Basically it looks like this:
library(renters)
search1 <- entrez_search(db="protein", term="XP_012370245[Accn]")
links <- entrez_link(dbfrom="protein", db="nuccore", id=search1$ids)
rec <- entrez_fetch(db="nuccore", rettype="fasta", id=links$links$protein_nuccore_mrna[1])

And the output looks like this:
> rec
[1] ">XM_012514791.1 PREDICTED: Octodon degus Hermansky-Pudlak syndrome 6 (Hps6), mRNA
\nATGCAGAGGAAAAACTTTATGTCATTCTTCACAGGCTTCCTGGAGAAGCGGGCCTGGCCGGAGGCCCGCG\nCCGCGCCGCTGGACGCCTTCTTCCTGGCGTGGCCGGCGCAGCCCGCGGTGGCGCTGGTGTGGGAGAGCGG (...)

Is there a way to keep the protein id (XP_012370245) instead of the nucleotide id (XM_012514791.1)? Something like:
> rec
[1] ">XP_012370245
 \nATGCAGAGGAAAAACTTTATGTCATTCTTCACAGGCTTCCTGGAGAAGCGGGCCTGGCCGGAGGCCCGCG\nCCGCGCCGCTGGACGCCTTCTTCCTGGCGTGGCCGGCGCAGCCCGCGGTGGCGCTGGTGTGGGAGAGCGG (...)

I have done this with BioMart R package (biomaRt) but with rentrez seems to be more difficult.
Any suggestion is very welcome, thanks!
Comment: Is there a typo in library name rentrez?
Answer: This is an answer from David Winter from the rentrez github repository:
I don't think there is any way to do this on the NCBI end (nucleotide records have nucleotide IDs).
You can probably cook something up to replace the IDs through stringr or the base string manipulation functions. This works for your example (though you probably want to add some checks to make sure you are actually findings CDS sequences etc):
fetch_cds <- function(prot_acc){
    search1 <- entrez_search(db="protein", term=paste0(prot_acc, "[Accn]"))
    links <- entrez_link(dbfrom="protein", db="nuccore", id=search1$ids)
    rec <- entrez_fetch(db="nuccore", rettype="fasta", id=links$links$protein_nuccore_mrna[1])
    sub("XM_\\d+\\.\\d", prot_acc, rec)
}

cat(substr(fetch_cds("XP_012370245"), 1, 500), "\n")

>XP_012370245 PREDICTED: Octodon degus Hermansky-Pudlak syndrome 6 (Hps6), mRNA
ATGCAGAGGAAAAACTTTATGTCATTCTTCACAGGCTTCCTGGAGAAGCGGGCCTGGCCGGAGGCCCGCG
CCGCGCCGCTGGACGCCTTCTTCCTGGCGTGGCCGGCGCAGCCCGCGGTGGCGCTGGTGTGGGAGAGCGG
CCTGGCGGAGCTCTGGGGTGCCGACCTGGGGTCCGCCTGGAGGCGGCTTCACGCCACCGAACTGTGTCCG
CGCGGCGCAGTCCGCGTGGTGGCAGCGGTGGCGCCGCGGGGCCGCCTGGTGTGGTGCGAGGAGCGCCCGG
GCGCGGGCGGACGCCGCGTGTGCGTCCGCACCCTAGAGCCTGGCGGCGAGACTGGTGCCCGCCTGGGCCG
CACGCACGTCCTGCTGCACCACTGCCCGCCCTTCCACCTGCTGGCCTCGCGCAAGGACGTCTTCC


Does a p-value of 1 for an interaction where the plot has crossing lines signal something is wrong in a 3-way ANOVA?

Question: I have run a 3-way ANOVA and the interaction between two of the factors looks significant when plotted (i.e. the two lines cross). However the p-value is 1.
Should I be worried about this? In particular:

Is a p-value of 1 in a 3-way ANOVA weird?
If the lines cross in a plot of a 2-way interaction, does this mean that there is definitely an interaction between the two factors or can the lines cross without there being an interaction?

The data comes from a yoked study on two different datasets and in the other dataset, there was a similar looking plot and the interaction was highly significant. If I were to interpret these results as the data is trending in that direction, but there is no significant interaction, would that be a not-completely false conclusion?
What I'm worried about is someone saying either 'oh well the p-value is 1 and that always means x, y, z' or 'oh well the lines might cross, but crossing lines isn't always a sign of an interaction, it can just be a result of x, y, z'. The p-value of 1 feels weird to me, as does the crossing lines without a significant p-value. Should it, or do p-values of 1 occur often and crossing lines without significant p-values occur often?
This is the graph:
Answer: I'll begin briefly with the headline news before addressing other parts of your question. There is nothing necessarily wrong with your model. A p value of approximately 1 suggests that there is almost certainly no significant three-way interaction in your model.
That being said, there are a few components of your question worth unpacking. First, to borrow from your example, an interaction model is not testing whether two lines cross. It is testing whether two lines are different. There are several ways in which two lines may not cross but still differ in their slopes. This is all to say that two lines crossing over is not an appropriate criteria to use when evaluating the presence of an interaction. However, if there is an interaction, plotting the effects is useful for interpretation.
The second aspect of your example that deserves consideration is what it is the lines represent. Whether testing a continuous or categorical interaction, the lines plotted invariably represent mean differences or associations or change. While knowing these sorts of average estimates is useful, inferential statistics require that we also think about and model the error associated with our sample-based statistics. Though we may be able to calculate the average differences for subgroups in our analyses for instance, we also have to admit to some degree of uncertainty in those estimates when we want to make inferences about populations. What is missing from your plots in a sense then are confidence intervals. For an example from some of my own work see below:

The inclusion of error bars provides some sense of the degree to which we are uncertain about our estimates. It also lets us know where significant differences do and do not exist (which again is only really useful when there is a significant interaction that requires probing).
Finally, one last aspect of your question worth noting is that three-way interactions are particularly hard to detect and often most analyses that attempt such analyses are wildly under-powered. I would be sure that your analysis has sufficient statistical power before attempting the inclusion of a three-way interaction.
Answer: If two lines are not exactly parallel, they will inevitably cross at some point. Without loss of generality let's simplify your question. Say that you were using one sample $t$-test and wanted to test $H_0 : \bar X = 0$. Obviously, you could say that if $\bar X \ne 0$, then the hypothesis is false, but we use hypothesis tests to account for the uncertainty of your results. $p$-values tell you how "likely" would such result be if the $H_0$ was true. So basically what your test tells you is "you could, as well, observe such result if there wouldn't be any interaction".


Why SNMP or SSH prevents the while to loop from iterating?

Question: I'm writing a code in order to capture information about routers thanks to SSH and SNMP. I work on network with 4 different router configurations. In my script bash, a while loop read line by line the IP address of routers then try to know the configuration and finally capture information about my router.
To do so, I use a while loop but it only run for one IP address...
I assume that the problem comes from SNMP or SSH.
I tried the while loop just with
echo $line

The while loop :
while IFS= read -r line
do
    echo
    echo "line : $line"
    echo

    typeRouter=""
    version=""

    # type multitech V4.1
    type=$(snmpget -v3 -u Ai -l authpriv -a SHA -A "pass" -x AES -X "pass" "$line" 184.108.40.206.4.1.922.214.171.124.8.3.0 | cut -d\" -f2 | cut -d. -f1 )
    if  [[ "$type" == "4" ]]; then
        typeRouter=2
        version=4
    fi

    # type sierra
    type=$(snmpget -v3 -u Ai -l authpriv -a SHA -A "pass" -x AES -X "pass" "$line" iso.188.8.131.52.1.20518.104.22.168.9.7.0 | cut -d\" -f2  )
    if [[ "$type" == "LX40" ]]; then
        typeRouter=3
    fi

    case $typeRouter in
    2)
            echo "Mutlitech"

            # version 4.1 et ultérieur
            MultiV4 "$line" "$txtfile" "pass" "pass"
            ;;

    3) # TODO PASSWORD
        echo "Sierra"

        Sierra "$line" "$txtfile" "pass" "pass"
        ;;

    *)
        echo
        echo "Unknown router model, IP : $line"
        echo
        ;;

    esac

done < "file"

The function called
MultiV4 () {
    # "$1" : @IP
    # $2 : txtfile
    # "$3" : mdp snmp
    # $4 : mdp ssh

    # Files
    txtfile=$2
    model="Multitech"
    MACtxt="ephemere/mac.txt"

    MacAddressRouter=$(snmpget -v3 -u Ai -l authpriv -a SHA -A "$3" -x AES -X "$3" "$1" iso.18.104.22.168.1.9188.8.131.52.5.1.0 | cut -d\" -f2)
    echo "Router MAC address : $MacAddressRouter"

    sshpass -p "$4" ssh -o StrictHostKeyChecking=no admin@"$1"  "cat /proc/net/arp" > "$MACtxt"

    rssiPacket=$(snmpget -v3 -u Ai -l authpriv -a SHA -A "$3" -x AES -X "$3" "$1" iso.126.96.36.199.1.9188.8.131.52.3.5.0 | cut -d: -f2 | cut -d\" -f2 | tr -d dBm)
    echo "RSSI packet : $rssiPacket"

    firmware=$(snmpget -v3 -u Ai -l authpriv -a SHA -A "$3" -x AES -X "$3" "$1" iso.220.127.116.11.1.9126.96.36.199.3.4.0 | cut -d: -f2 | cut -d\" -f2)
    echo "Firmware version : $firmware"

    echo "$MacAddressRouter", "$MacAddressPlayer", "$rssiPacket", "$model", "$firmware", "$imei", "$SIMStatus", "$operator", "$connectionType", "$IPaddress", "$SINR", "$RSRP", "$RSRQ" >> "$txtfile"
}

My file
10.252.144.138
10.252.144.140
10.252.144.23
10.252.144.15
10.252.144.134

Can you help me why the loop running only one time ?
Comment: Try to run with -vx to see what was actually executed.
Comment: Did you have any output? Please add to the question. Can you make the problem easier? What happens when you remove the call to `MultiV4()` ?
Comment: Possible duplicate of https://stackoverflow.com/questions/13800225/shell-script-while-read-line-loop-stops-after-the-first-line
Comment: in your MultiV4 func, I think you can figure out a way to call `snmpget` one time, and use an `awk` script to output multiple words that could be assigned to a shell array. Agree with both comments above. Good luck.
Comment: Thanks for your redirection @tripleee ! The problem is solved
Answer: I solved the problem using
ssh -n

Go see this answer for more explanation : Shell script while read line loop stops after the first line


Create a load of button images from .jpg files

Question: I have a folder containing a number of .jpg files (each of them are 100x100 pixels).
I would like to create a wxPython panel showing all these .jpg (with a mosaic layout) as wx.BitmapButton.
I tried with the wxPython's demo called BitmapButton.py but this loads images from embedded image only, here I don't know what's the canonical way to do it with JPEGs.
Moreover, I would like this panel to automatically give a good disposition of the buttons.
Example : let's assume I have 10 buttons.

If window's width is large enough to fit 5 buttons per row, 2 rows of 5 buttons should be displayed,
If the window is resized to a smaller width, then 2 rows of 4 buttons + 1 row of 2 buttons should be displayed, etc.

How to deal with JPEGs in wx.BitmapButton, and if many buttons, how to make that they have automatically a good layout in the panel (auto alignement in rows) ?
Comment: All of my wxPython experience tells me that re-arranging the buttons based on the size is going to be a massive pain
Comment: Thanks for your answer @wnnmaw. My question was indeed : is there a `BoxSizer` widget (or whatever other name) that could handle the *automatic*-arranging of the buttons in the panel ?
Answer: Yes, there is a new sizer that can do what you want in wxPython 2.9+ called WrapSizer. There is an example of its usage in the wxPython demo. You can also read about it at the following:

http://wxpython.org/Phoenix/docs/html/WrapSizer.html

As for the BitmapButton, I am pretty sure you can pass it a jpg file if you do it properly. You will probably need to do something like this:
img = wx.Image(filepath, wx.BITMAP_TYPE_ANY)
bmp = wx.BitmapFromImage(img)
b = wx.BitmapButton(self, -1, bmp, (20, 20),
                   (bmp.GetWidth()+10, bmp.GetHeight()+10))

Comment: Great! I did not expected it was so simple... Two small little things : what's the simpler way to add shadow to the bitmaps (like the ablum art here : http://static.pcinpact.com/images/bd/news/119801.jpeg)  and how to add text below the image *which would be part of the button (ie clickable) too* ?
Comment: I don't know about the shadow...you may have to add that to the image itself somehow. Or maybe create a shadow image and combine it with the bitmap before applying it to the button. As for adding text, the BitmapButton doesn't appear to support that. You might be able to get that to work with the GenBitmapButton though.
Comment: Thank you @MikeDriscoll. When the buttons don't fit in the current window, the last buttons are resized to smaller (which I don't want, I would prefer that a scrollbar is added then) : http://pastebin.com/Jq5Sp296
Do you have an idea on that ?
Comment: Moreover, I noticed, when making 10 `BitmapButtons` (size 150x150) + `WrapSizer`, there is lots of flickering when I resize the window. Any idea for this @MikeDriscoll ?
Comment: Maybe use a ScrolledPanel or ScrolledWindow, although that might prevent the wrapping you want. For removing flickering, I would look at the Freeze/Thaw methods for the panel.


Set theory - functions: Given that $|A|=|B|$, how to prove that $|A^C|=|B^C|$?

Question: Given that $|A|=|B|$ (the cardinality of set $A$ is equal to the cardinality of $B$).
How can I prove that $|A^C|=|B^C|$ (the cardinality of the set of all functions from $C \longrightarrow A$ is equal to the cardinality of  the set of all function from $C \longrightarrow B$).
I understand that I have to find a bijection $h: A^C \longrightarrow B^C$, means that $g$ receives a function $f: C\longrightarrow A$, and return a function $g: C\longrightarrow B$.
I am not sure how to approach finding such a bijection and therefore asking here for help. Much appreciated!
Comment: We know there is a bijection $\varphi:A\to B$. So now, given a function $f:C\to A$, how can we obtain a function $C\to B$? Think of it, there is really just one (natural) way.
Comment: Oh... I see, compose the 2 functions, that way we get a function from $C$ to $B$. And then all is left is to prove that it's a bijection.
Comment: Maybe a function $g: C \longrightarrow B$, such that it's entire image is all $f(a)'s$ for every $a$ that is in the image of $f$? Tell me if i'm in the right direction.
Comment: @natitati that's overly complicated.
Comment: I'm afraid that I need another hint then :(
Comment: @natitati No need to overcomplicate. We have two functions: $f:C\to A$ and $\varphi:A\to B$. From these two functions, what is a way to get a function from $C$ to $B$? You didn't use $\varphi$ at all in your comment.
Comment: @natitati Indeed, the required map takes $f$ to $\varphi\circ f$.
Comment: Thanks. And how do I properly say that it's a bijection? Let's start with one-to-one, can I just say that for every $h_1, h_2 \in A^C$, if $h1 \neq h2$, then $\varphi \circ h_1 \neq \varphi \circ h_2$? And what about on-to?
Answer: I did something like this:
Let  $\psi$:$A\longrightarrow B$ be a bijection since A and B are equinumerous.Then; define a function such that; $\phi$:$A^C\longrightarrow B^C$ as $\phi(f)=\psi$$\circ$$f$ then observe that
$\psi$$\circ$$f$:$C\longrightarrow$$B$.Since all functions in $A^C$ is different they generate
all different functions(hence it's an injection)from C to B(so the output is definitely in $B^C$
). Also, all the functions in $B^C$ are covered since $\psi$ is an surjection $\forall$x$\in$$B$ $\exists$$b\in A$ such that $\psi(b)=x$
Thus, the $\phi$ generates all functions from B to C.


Why is my picture link extending beneath the image?

Question: I'm working on a photo page for a site I'm creating, however it seems that the link is extending into the whitespace beneath the image. The problem disappears when I remove the surrounding
 but I'm not sure why.
Here's a Jsfiddle better showcasing my code and the problem

.photo {
  text-align: center;
  float: left;
  width: 70%;
  margin-left: 8%;
  margin-top: 5%;
  margin-bottom: 5%;
}
.photo a {
  border: 1px solid red;
}
.photo img {
  margin: 1%;
}

I added a border to the problem area. Any help is much appreciated!
Comment: float: left is making it... try add display: block; to the .photo a {} part
Answer: because a and img are inline elements, so

make a a block level element by display:block, to the border appear around the image
set display:block to img to remove underneath whitespace caused by being an inline element. (other solution would be setting vertical-align-bottom, given img by default is vertical-align:baseline)

Note:  I gave the img a max-width:100% to be responsive, and if you give the border to img instead of a, the a being display:block isn't necessary anymore, although is good to have it.
See more about inline elements here on w3

.photo {
  text-align: center;
  float: left;
  width: 70%;
  margin-left: 8%;
  margin-top: 5%;
  margin-bottom: 5%;
}
.photo a {
  display: block;
}
.photo img {
  display: block;
  border: 1px solid red;
  max-width: 100%;
  margin: 1%
}


Python Comprehensions

Question: I've got a list of tuples, each tuple looks like (i,x).

i = index

x = value

I need to return a new list (using a comprehension only) that each value will be in the "right" index. If index is missing, we'll put the value -1000 to fill the gap.
For example:
Input: [(4,9), (0,2), (1,4), (3,2)]
Output should be: [2, 4, -1000, 2, 9]
I was trying to use index function, I'm trying to get the index of the tuple (1,2), while I "know" only the first element, the second can be anything.
I want to get the index of the tuple (1,2) by search (1,___), is that possible?

___ is a positive integer

    return [sorted(L)[sorted(L).index((i,))][1] if i in [sorted(L)[j][0] for j in range(0,len(L))] else -1000 for i in range(sorted(L)[len(L)-1][0]+1)]

I can use list/dict/set comprehension, single line.

Thank you all for help!
Comment: Why do you necessarily need comprehension only?\
Comment: Why do you need the index? You just need to know if the current index of the iteration is in the first element of any of the tuples. `t[1] if i in {t[0] for t in tuples)} else 1000`
Comment: I know, But I can't figure out how to write it in a runnable comprehension (this is my lecturer orders... of course it's simpler to do it with two for loops)
Answer: With the help of a dictionary that maps indices to values, so we can easily and efficiently get the value for an index:
[g(i, -1000) for g in [dict(L).get] for i in range(max(L)[0] + 1)]

Try it online!

Python Comprehensions