text:
# How to limit the width of a nested table?

The inner table (that is the 'very long description') goes outside of the page limits:

\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage{array}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\usepackage{tabularx}

\begin{document}

\newenvironment{messageWithProperties}[1]
{
\noindent
\tabularx{\textwidth}{>{\bfseries}lX}
\toprule
\midrule
$\left\{\tabular{>{\bfseries}l l >{\sffamily}p{\dimexpr\textwidth-12\tabcolsep-5\fboxsep-7.5cm\relax}} \toprule id & integer & desc \\ key & integer & desc \\ \bottomrule \endtabular\right\}$ \\[4ex]
\midrule
#1 &
$\left\{\tabular{>{\bfseries}l l >{\sffamily}p{\dimexpr\textwidth-12\tabcolsep-5\fboxsep-7.5cm\relax}} \toprule } { \bottomrule \endtabular\right\}$ \\[4ex]
\midrule
\bottomrule
\endtabularx
}

\begin{messageWithProperties}{someVeryLongName}
userId & string & desc \\
propertyName & veryLongStringType & a very very long description of the field \\
\end{messageWithProperties}

\end{document}

How to force it to be inside?

It would be nice to limit its size to \textwidth - \widthof{#1} and also allow to fill all available space. How to do that?

• Welcome to TeX.SE! How did you arrive at the adjustment factor 7.5cm? Incidentally, which page size do you use: A4, US Letter, or something else? – Mico Nov 18 '16 at 18:54
• @Mico, it's from the tex.stackexchange.com/a/177078/118353 answer. More tables become too thin or too wide if these values are changed. The page size is A4. – Velkan Nov 21 '16 at 13:31

I'd use environ for avoiding nesting tabularx in a clumsy way:

\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage{array}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\usepackage{tabularx,environ}

\newlength{\bracewidth}
\settowidth{\bracewidth}{$\left\{\vbox to 1in{}\right.\kern-\nulldelimiterspace$}

\newcommand{\innerMWP}[1]{%
$\left\{\begin{tabularx}{\dimexpr\hsize-2\bracewidth}{ >{\bfseries}l l >{\sffamily}X } #1 \end{tabularx}\right\}$%
}
\NewEnviron{messageWithProperties}[1]
{\noindent
\begin{tabularx}{\textwidth}{>{\bfseries}lX}
\toprule
\midrule
\toprule
id & integer & desc \\
key & integer & desc \\
\bottomrule
}%
\\[4ex]
\midrule
#1 & \innerMWP{\toprule\BODY\bottomrule} \\[4ex]
\midrule
\bottomrule
\end{tabularx}%
}

\begin{document}

\begin{messageWithProperties}{someVeryLongName}
userId & string & desc \\
propertyName & veryLongStringType & a very very long description of the field \\
\end{messageWithProperties}

\end{document}

Without the useless braces:

\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage{array}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\usepackage{tabularx,environ}

\newcommand{\innerMWP}[1]{%
\begin{tabularx}{\hsize}{ >{\bfseries}l l >{\sffamily}X }
#1
\end{tabularx}%
}
\NewEnviron{messageWithProperties}[1]
{\noindent
\begin{tabularx}{\textwidth}{>{\bfseries}lX}
\toprule
id & integer & desc \\
key & integer & desc \\
\bottomrule
}%
\midrule
#1 & \innerMWP{\toprule\BODY\bottomrule} \\
\bottomrule
\end{tabularx}%
}

\begin{document}

\begin{messageWithProperties}{someVeryLongName}
userId & string & desc \\
propertyName & veryLongStringType & a very very long description of the field \\
\end{messageWithProperties}

\end{document}

• That additionally solves (hopefully; need to test on the whole doc) another problem: inability to compose the table from smaller commands. I've got a dozen of variations of the header and a structure, so had to copy-paste the newenvironment for each of them. P. S. braces are not useless. – Velkan Nov 25 '16 at 22:05
• Great! You have solved a couple of issues I was wondering: 1) how to find the width of the braces 2) how to nest a tabularx within the main tabularx (I tried but without success). Moreover I see that \cellwidth is not necessary because \hsize is equivalent. – CarLaTeX Nov 26 '16 at 5:53

I don't know if this is a suitable solution but I've found here the way to have the cell width and I've used this width to set the width of the nested table columns:

\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage{array}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\usepackage{tabularx}
% These code lines are from: https://tex.stackexchange.com/a/30673/101651
\makeatletter
\newcommand\cellwidth{\TX@col@width}
\makeatother

\begin{document}

\newenvironment{messageWithProperties}[1]
{
\noindent
\tabularx{\textwidth}{>{\bfseries}lX}
\toprule
\midrule
$\left\{\tabular{>{\bfseries}p{.24\cellwidth} p{.27\cellwidth} >{\sffamily}p{.34\cellwidth}} \toprule id & integer & desc \\ key & integer & desc \\ \bottomrule \endtabular\right\}$ \\[4ex]
\midrule
#1 &
$\left\{\tabular{>{\bfseries}p{.24\cellwidth} p{.27\cellwidth} >{\sffamily}p{.34\cellwidth}} \toprule } { \bottomrule \endtabular\right\}$ \\[4ex]
\midrule
\bottomrule
\endtabularx
}

\begin{messageWithProperties}{someVeryLongName}
userId & string & desc \\
propertyName & veryLongStringType & a very very long description of the field \\
\end{messageWithProperties}

\end{document}

P.S. = I've never done a nested table before, nor created a new environment, hence I've answered as an exercise.


text:
# Properties

 Label 1911.2.c.d Level $1911$ Weight $2$ Character orbit 1911.c Analytic conductor $15.259$ Analytic rank $0$ Dimension $2$ CM no Inner twists $2$

# Related objects

## Newspace parameters

 Level: $$N$$ $$=$$ $$1911 = 3 \cdot 7^{2} \cdot 13$$ Weight: $$k$$ $$=$$ $$2$$ Character orbit: $$[\chi]$$ $$=$$ 1911.c (of order $$2$$, degree $$1$$, minimal)

## Newform invariants

 Self dual: no Analytic conductor: $$15.2594118263$$ Analytic rank: $$0$$ Dimension: $$2$$ Coefficient field: $$\Q(\sqrt{-3})$$ Defining polynomial: $$x^{2} - x + 1$$ Coefficient ring: $$\Z[a_1, a_2]$$ Coefficient ring index: $$2$$ Twist minimal: no (minimal twist has level 39) Sato-Tate group: $\mathrm{SU}(2)[C_{2}]$

## $q$-expansion

Coefficients of the $$q$$-expansion are expressed in terms of a primitive root of unity $$\zeta_{6}$$. We also show the integral $$q$$-expansion of the trace form.

 $$f(q)$$ $$=$$ $$q + ( 1 - 2 \zeta_{6} ) q^{2} + q^{3} - q^{4} + ( 1 - 2 \zeta_{6} ) q^{6} + ( 1 - 2 \zeta_{6} ) q^{8} + q^{9} +O(q^{10})$$ $$q + ( 1 - 2 \zeta_{6} ) q^{2} + q^{3} - q^{4} + ( 1 - 2 \zeta_{6} ) q^{6} + ( 1 - 2 \zeta_{6} ) q^{8} + q^{9} + ( -2 + 4 \zeta_{6} ) q^{11} - q^{12} + ( -1 + 4 \zeta_{6} ) q^{13} -5 q^{16} + 6 q^{17} + ( 1 - 2 \zeta_{6} ) q^{18} + ( -2 + 4 \zeta_{6} ) q^{19} + 6 q^{22} + ( 1 - 2 \zeta_{6} ) q^{24} + 5 q^{25} + ( 7 - 2 \zeta_{6} ) q^{26} + q^{27} + 6 q^{29} + ( 2 - 4 \zeta_{6} ) q^{31} + ( -3 + 6 \zeta_{6} ) q^{32} + ( -2 + 4 \zeta_{6} ) q^{33} + ( 6 - 12 \zeta_{6} ) q^{34} - q^{36} + ( 4 - 8 \zeta_{6} ) q^{37} + 6 q^{38} + ( -1 + 4 \zeta_{6} ) q^{39} + ( 4 - 8 \zeta_{6} ) q^{41} -4 q^{43} + ( 2 - 4 \zeta_{6} ) q^{44} + ( -2 + 4 \zeta_{6} ) q^{47} -5 q^{48} + ( 5 - 10 \zeta_{6} ) q^{50} + 6 q^{51} + ( 1 - 4 \zeta_{6} ) q^{52} + 6 q^{53} + ( 1 - 2 \zeta_{6} ) q^{54} + ( -2 + 4 \zeta_{6} ) q^{57} + ( 6 - 12 \zeta_{6} ) q^{58} + ( -6 + 12 \zeta_{6} ) q^{59} + 2 q^{61} -6 q^{62} - q^{64} + 6 q^{66} + ( -6 + 12 \zeta_{6} ) q^{67} -6 q^{68} + ( 2 - 4 \zeta_{6} ) q^{71} + ( 1 - 2 \zeta_{6} ) q^{72} -12 q^{74} + 5 q^{75} + ( 2 - 4 \zeta_{6} ) q^{76} + ( 7 - 2 \zeta_{6} ) q^{78} -8 q^{79} + q^{81} -12 q^{82} + ( 2 - 4 \zeta_{6} ) q^{83} + ( -4 + 8 \zeta_{6} ) q^{86} + 6 q^{87} + 6 q^{88} + ( 4 - 8 \zeta_{6} ) q^{89} + ( 2 - 4 \zeta_{6} ) q^{93} + 6 q^{94} + ( -3 + 6 \zeta_{6} ) q^{96} + ( 8 - 16 \zeta_{6} ) q^{97} + ( -2 + 4 \zeta_{6} ) q^{99} +O(q^{100})$$ $$\operatorname{Tr}(f)(q)$$ $$=$$ $$2q + 2q^{3} - 2q^{4} + 2q^{9} + O(q^{10})$$ $$2q + 2q^{3} - 2q^{4} + 2q^{9} - 2q^{12} + 2q^{13} - 10q^{16} + 12q^{17} + 12q^{22} + 10q^{25} + 12q^{26} + 2q^{27} + 12q^{29} - 2q^{36} + 12q^{38} + 2q^{39} - 8q^{43} - 10q^{48} + 12q^{51} - 2q^{52} + 12q^{53} + 4q^{61} - 12q^{62} - 2q^{64} + 12q^{66} - 12q^{68} - 24q^{74} + 10q^{75} + 12q^{78} - 16q^{79} + 2q^{81} - 24q^{82} + 12q^{87} + 12q^{88} + 12q^{94} + O(q^{100})$$

## Character values

We give the values of $$\chi$$ on generators for $$\left(\mathbb{Z}/1911\mathbb{Z}\right)^\times$$.

 $$n$$ $$638$$ $$1471$$ $$1522$$ $$\chi(n)$$ $$1$$ $$-1$$ $$1$$

## Embeddings

For each embedding $$\iota_m$$ of the coefficient field, the values $$\iota_m(a_n)$$ are shown below.

For more information on an embedded modular form you can click on its label.

Label $$\iota_m(\nu)$$ $$a_{2}$$ $$a_{3}$$ $$a_{4}$$ $$a_{5}$$ $$a_{6}$$ $$a_{7}$$ $$a_{8}$$ $$a_{9}$$ $$a_{10}$$
883.1
 0.5 + 0.866025i 0.5 − 0.866025i
1.73205i 1.00000 −1.00000 0 1.73205i 0 1.73205i 1.00000 0
883.2 1.73205i 1.00000 −1.00000 0 1.73205i 0 1.73205i 1.00000 0
 $$n$$: e.g. 2-40 or 990-1000 Significant digits: Format: Complex embeddings Normalized embeddings Satake parameters Satake angles

## Inner twists

Char Parity Ord Mult Type
1.a even 1 1 trivial
13.b even 2 1 inner

## Twists

By twisting character orbit
Char Parity Ord Mult Type Twist Min Dim
1.a even 1 1 trivial 1911.2.c.d 2
7.b odd 2 1 39.2.b.a 2
13.b even 2 1 inner 1911.2.c.d 2
21.c even 2 1 117.2.b.a 2
28.d even 2 1 624.2.c.e 2
35.c odd 2 1 975.2.b.d 2
35.f even 4 2 975.2.h.f 4
56.e even 2 1 2496.2.c.d 2
56.h odd 2 1 2496.2.c.k 2
84.h odd 2 1 1872.2.c.e 2
91.b odd 2 1 39.2.b.a 2
91.i even 4 2 507.2.a.f 2
91.n odd 6 1 507.2.j.a 2
91.n odd 6 1 507.2.j.c 2
91.t odd 6 1 507.2.j.a 2
91.t odd 6 1 507.2.j.c 2
91.bc even 12 4 507.2.e.e 4
273.g even 2 1 117.2.b.a 2
273.o odd 4 2 1521.2.a.l 2
364.h even 2 1 624.2.c.e 2
364.p odd 4 2 8112.2.a.bv 2
455.h odd 2 1 975.2.b.d 2
455.s even 4 2 975.2.h.f 4
728.b even 2 1 2496.2.c.d 2
728.l odd 2 1 2496.2.c.k 2
1092.d odd 2 1 1872.2.c.e 2

By twisted newform orbit
Twist Min Dim Char Parity Ord Mult Type
39.2.b.a 2 7.b odd 2 1
39.2.b.a 2 91.b odd 2 1
117.2.b.a 2 21.c even 2 1
117.2.b.a 2 273.g even 2 1
507.2.a.f 2 91.i even 4 2
507.2.e.e 4 91.bc even 12 4
507.2.j.a 2 91.n odd 6 1
507.2.j.a 2 91.t odd 6 1
507.2.j.c 2 91.n odd 6 1
507.2.j.c 2 91.t odd 6 1
624.2.c.e 2 28.d even 2 1
624.2.c.e 2 364.h even 2 1
975.2.b.d 2 35.c odd 2 1
975.2.b.d 2 455.h odd 2 1
975.2.h.f 4 35.f even 4 2
975.2.h.f 4 455.s even 4 2
1521.2.a.l 2 273.o odd 4 2
1872.2.c.e 2 84.h odd 2 1
1872.2.c.e 2 1092.d odd 2 1
1911.2.c.d 2 1.a even 1 1 trivial
1911.2.c.d 2 13.b even 2 1 inner
2496.2.c.d 2 56.e even 2 1
2496.2.c.d 2 728.b even 2 1
2496.2.c.k 2 56.h odd 2 1
2496.2.c.k 2 728.l odd 2 1
8112.2.a.bv 2 364.p odd 4 2

## Hecke kernels

This newform subspace can be constructed as the intersection of the kernels of the following linear operators acting on $$S_{2}^{\mathrm{new}}(1911, [\chi])$$:

 $$T_{2}^{2} + 3$$ $$T_{5}$$ $$T_{17} - 6$$

## Hecke characteristic polynomials

$p$ $F_p(T)$
$2$ $$3 + T^{2}$$
$3$ $$( -1 + T )^{2}$$
$5$ $$T^{2}$$
$7$ $$T^{2}$$
$11$ $$12 + T^{2}$$
$13$ $$13 - 2 T + T^{2}$$
$17$ $$( -6 + T )^{2}$$
$19$ $$12 + T^{2}$$
$23$ $$T^{2}$$
$29$ $$( -6 + T )^{2}$$
$31$ $$12 + T^{2}$$
$37$ $$48 + T^{2}$$
$41$ $$48 + T^{2}$$
$43$ $$( 4 + T )^{2}$$
$47$ $$12 + T^{2}$$
$53$ $$( -6 + T )^{2}$$
$59$ $$108 + T^{2}$$
$61$ $$( -2 + T )^{2}$$
$67$ $$108 + T^{2}$$
$71$ $$12 + T^{2}$$
$73$ $$T^{2}$$
$79$ $$( 8 + T )^{2}$$
$83$ $$12 + T^{2}$$
$89$ $$48 + T^{2}$$
$97$ $$192 + T^{2}$$

format: plain


text:
### Home > CC4 > Chapter 11 > Lesson 11.2.3 > Problem11-71

11-71.
1. Kelly is an engineer for a non-profit company that drills wells for impoverished villages in Africa. The cost of drilling a new water well is determined from the amount of drilling needed to find water, plus the fixed costs of the pump. Kelly has collected data on cost versus well depth for a sample of 12 projects: Homework Help ✎

1. Discuss the form, strength, direction, and outliers.

2. Interpret the slope of the least squares regression line in the context of this study.

3. Calculate and interpret R-squared in context.

4. What does the y‑intercept represent in this analysis?

5. Using the LSRL model, estimate the cost of wells that are 80, 150, and 200 feet.

6. The 80-foot well Kelly measured has a residual of $363. What was the actual cost of the well? 7. Is a linear model the best choice for predicting well cost using well depth? Support your answer. Is the data in a line, a curve, or has no pattern? Does it go up, or does is go down? Do most of the point fall close to the pattern? Are there any outliers? $\text{Recall that slope is }\frac{\Delta y}{\Delta x}. \text{ What does the }x\text{-axis represent? What about the }y\text{-axis?}$ R-squared: 0.864 (Note that r is given.) What does this mean in the context of the situation? The y-intercept is the point where x = 0. What is the cost to drill 0 feet? Substitute 80, 150, and 200 for x in the equation of the line. 1395 + 14.65(80) =$2567
1395 + 14.65(150) = $3593 1395 + 14.65(200) =$4325

Take the predicted cost of an 80 foot well, then add \$363.

Does the residual plot have a pattern? If so, another model might be better.


text:
Statement - Maple Programming Help

Home : Support : Online Help : Connectivity : Database Package : Statement : Database/Statement/NextResult

Statement

 NextResult
 retrieve the next result of a multiple statement execute

 Calling Sequence statement:-NextResult( )

Parameters

 statement - Statement module

Description

 • NextResult tries to retrieve the next result from statement. If no results are available, it returns NULL.
 • If a result is available, it will either be an integer corresponding to an update statement, or a Result module corresponding to a query statement.
 • To issue a multi-statement SQL string, the Execute command must be used.
 • Some databases may require that the processing of the current result be completed before the next result is returned by NextResult.

Examples

 > $\mathrm{driver}≔\mathrm{Database}[\mathrm{LoadDriver}]\left(\right):$
 > $\mathrm{conn}≔\mathrm{driver}:-\mathrm{OpenConnection}\left(\mathrm{url},\mathrm{name},\mathrm{pass}\right):$$\mathrm{stat}≔\mathrm{conn}:-\mathrm{CreateStatement}\left(\right):$

Execute some statements.

 > $\mathrm{res}≔\mathrm{stat}:-\mathrm{Execute}\left("SELECT name FROM animals WHERE id = 1; INSERT INTO animals\left( id, name, number, mass \right) VALUES\left( 14, \text{'}boar\text{'}, 10, 60.67 \right); SELECT name FROM animals WHERE id = 3;"\right):$

Check the value.

 > $\mathrm{res}:-\mathrm{Next}\left(\right);$$\mathrm{res}:-\mathrm{GetData}\left("name"\right)$
 ${"fish"}$ (1)

Get the next result.

 > $\mathrm{stat}:-\mathrm{NextResult}\left(\right)$
 ${1}$ (2)

Now the last result.

 > $\mathrm{res}≔\mathrm{stat}:-\mathrm{NextResult}\left(\right):$$\mathrm{res}:-\mathrm{Next}\left(\right):$$\mathrm{res}:-\mathrm{GetData}\left("name"\right)$
 ${"cat"}$ (3)

Check for more results.

 > $\mathrm{stat}:-\mathrm{NextResult}\left(\right)$

NULL returned, no more results in this Statement Module.

 Please add your Comment (Optional) E-mail Address (Optional) What is ? This question helps us to combat spam


text:
Often, hairy ball theorem is mentioned as an application of degree theory derived from singular homology in algebraic topology or from de Rham cohomology in differential topology; we also mentionned it as an application of Brouwer’s degree in Brouwer’s Topological Degree (III): First Applications. Here we describe an argument due to Milnor, exposed in Gallot, Hullin and Lafontaine’s book Riemannian Geometry, using only integration of differential forms.

For convenience, we begin by exposing some basic definitions and first properties about integration on manifolds.

If $M$ is a smooth manifold, let $TM$ and $\Omega^k(M)$ denote respectively its tangent bundle and its space of differential forms of degree $k$ (ie. the vector space $\Gamma( \Lambda^k T^*M)$ of sections of the $k$-th extorior power of the cotangent bundle).  We say that $M$ is orientable if there exists an atlas $(U_i,\varphi_i)$, said oriented, such that $\varphi_i \circ \varphi_j^{-1}$ is orientation-preserving for all $i,j$.

Property: A smooth manifold $M$ is orientable if and only if there exists $\omega \in \Omega^n(M)$ satisfying $\omega_m \neq 0$ for all $m \in M$. Such a differential form is a volume form.

Sketch of proof. Let $\omega \in \Omega^n(M)$ be a volume form and let $(U_i,\varphi_i)$ be a family of charts covering $M$. Because $(\varphi_i)_* \omega_{|U_i} \in \Omega^n (\varphi_i(U_i))$ is a volume form, we can write

$(\varphi_i)_* \omega_{|U_i} = f_i ~ dx_1 \wedge \cdots \wedge dx_n$

where $f_i \in C(\varphi_i(U_i), \mathbb{R})$ does not vanish. Without loss of generality, we may suppose that $f_i > 0$ (otherwise, switch two coordinates of the chart). Then $(U_i, \varphi_i)$ is an oriented atlas.

Conversely, let $(U_i, \varphi_i)$ be an oriented atlas and $(\chi_i)$ be an associated partition of unity. Then

$\displaystyle \omega = \sum\limits_i \chi_i \varphi_i^* (dx_1 \wedge \cdots \wedge dx_n)$

is a volume form. $\square$

As an example, we may mention the differential form

$\displaystyle \omega = \sum\limits_{i=0}^n (-1)^i x^i dx_0 \wedge \cdots \wedge \widehat{dx_i} \wedge \cdots \wedge dx_n \in \Omega^n(\mathbb{R}^{n+1})$.

Then $\omega$ induces a volume form on $\mathbb{S}^n$ viewed as the unit sphere in $\mathbb{R}^{n+1}$. [In fact, $\omega$ is the canonical volum form of $\mathbb{S}^n$ as a Riemannian manifold. In particular, we define $\displaystyle \mathrm{Vol}(\mathbb{S}^n) = \int_{\mathbb{S}^n} \omega$.]

An interesting property of volum forms is that, if $\omega \in \Omega^n(M)$ is a volume form and $\alpha \in \Omega^n(M)$, then there exists $f \in C(M, \mathbb{R})$ such that $\alpha= f \omega$. It is clear locally, and then it is sufficient to extend it globally using a partition of unity.

Definition: Let $M$ be an orientable compact $n$-dimensional smooth manifold. There exists one and only one linear map $\int_{M} : \Omega^n(M) \to \mathbb{R}$ such that for every $\omega \in \Omega^n(M)$ supported in an open chart $(U,\varphi)$,

$\displaystyle \int_M \alpha = \int_{\varphi(U)} (\varphi^{-1})^* \alpha$.

[Where the right-hand side is the usual integral of a differential form defined on an open subspace in $\mathbb{R}^n$.]

Sketch of proof. First, suppose that such a linear map exists. Let $(U_i, \varphi_i)$ be a finite family of charts covering $M$ (such a family exists by compactness) and $(\chi_i)$ be an associated partition of unity. Then necessarily:

$\displaystyle \int_M \omega= \int_M \sum\limits_{i} \chi_i \omega_{|U_i} = \sum\limits_{i} \int_M \chi_i \omega_{|U_i} = \sum\limits_{i} \int_{\varphi(U_i)} (\varphi_i^{-1})^* \chi_i \omega_{|U_i}$,

hence $\int_M$ is uniquely defined by the mentionned properties. Conversely, it is sufficient to show that the above equality does not depend on the family of charts and on the partition of unity chosen. An argument for that is to notice that if $\varphi : U \to V$ is a diffeomorphism between two open subsets $U,V \subset \mathbb{R}^n$, and $\omega \in \Omega^n(\mathbb{R}^n)$, then

$\displaystyle \int_U \varphi^* \omega= \epsilon \int_V \omega$,

where $\epsilon=1$ if $\varphi$ is orientation-preserving and $-1$ otherwise. We can write $\omega= f dx_1 \wedge \cdots \wedge dx_n$ for some $f \in C(M, \mathbb{R})$, and

$\begin{array}{lcl} \displaystyle \int_U \varphi^* \omega & = & \displaystyle \int_U f \circ \varphi ~ \varphi^* (dx_1 \wedge \cdots \wedge dx_n) \\ \\ & = & \displaystyle \int_U f \circ \varphi ~ \mathrm{Jac} (\varphi) ~ dx_1 \wedge \cdots \wedge dx_n \\ \\ & = & \displaystyle \epsilon \int_U f \circ \varphi ~ | \mathrm{Jac} ( \varphi ) | ~ dx_1 \wedge \cdots \wedge dx_n \\ \\ & = & \displaystyle \epsilon \int_{\varphi(U)} f = \epsilon \int_V \omega \hspace{1cm} \square \end{array}$

Using the proof above, we may notice:

Property: Let $M,N$ be two compact orientable $n$-dimensional smooth manifolds and $\omega \in \Omega^n(N)$. If $f : M \to N$ is a diffeomorphism then

$\displaystyle \int_N \omega= \epsilon \int_M f^*\omega$,

where $\epsilon=1$ if $f$ is orientation-preserving and $\epsilon=-1$ otherwise.

Theorem: (Hairy ball theorem) If $n$ is even, any continuous vector field on $\mathbb{S}^n$ has a zero.

Proof. Let $X$ be a continuous vector field on $\mathbb{S}^n$, that is $X : \mathbb{S}^n \to \mathbb{R}^{n+1}$ is a map satisfying $X(p) \cdot p =0$ for every $p \in \mathbb{S}^n$. By contradiction, suppose that $X$ does not vanish.

According to Stone-Weierstrass theorem, it is possible to approximate $X$ by a sequence of smooth maps $X_k : \mathbb{S}^n \to \mathbb{R}^{n+1}$. Then, if $X_k(p)^{\top}$ denotes the orthogonal projection of $X_k(p)$ on $T_p \mathbb{S}^n$, $X_k^{\top}$ is a sequence of smooth vector fields on $\mathbb{S}^n$ converging uniformely to $X$. Therefore, we may suppose without loss of generality that $X$ is smooth.

[Such an argument may be generalized to other manifolds; see Tubular neighborhood.]

Let $\omega \in \Omega^n(\mathbb{S}^n)$ be the volume form as defined above by the restriction on $\mathbb{S}^n$ of

$\displaystyle \omega = \sum\limits_{i=0}^n (-1)^i x^i \underset{ := \omega_i }{ \underbrace{ dx_0 \wedge \cdots \wedge \widehat{dx_i} \wedge \cdots \wedge dx_n }} \in \Omega^n ( \mathbb{R}^{n+1})$

and let $f_{\epsilon} : S(1) \to S( \sqrt{1+\epsilon^2}), \ x \mapsto x + \epsilon X(x)$. For every $p \in S(1)$ and $v_0, \dots, v_n \in \mathbb{R}^{n+1}$, we may write

$\begin{array}{lcl} ( f_{\epsilon}^* \omega)_p(v_0, \dots, v_n) & = & \sum\limits_{i=0}^n (-1)^i (p^i+ \epsilon X(p)^i) \omega_i (v_0+ \epsilon dX(p) \cdot v_0, \dots, v_n+ \epsilon dX(p) \cdot v_n) \\ & = & \sum\limits_{i=0}^n \sum\limits_{k=0}^{n+1} (-1)^i (p^i+ \epsilon X(p)^i) \epsilon^k \omega_{ik} (v_0, \dots, v_n) \end{array}$

where $\omega_{ik} \in \Omega^n(\mathbb{R}^{n+1})$ is such that $\omega_{i0}=\omega_i$ and $\omega_{ik}(v_0, \dots, v_n)= \omega_i (\tilde{v_0}, \dots, \tilde{v_n})$ with $\tilde{v_j} = v_j$ or $dX(p) \cdot v_j$. Therefore, there exist $\alpha_k \in \Omega^n (\mathbb{R}^{n+1})$ such that

$\displaystyle f_{\epsilon}^* \omega= \omega+ \sum\limits_{k=1}^{n+2} \epsilon^k \alpha_k \hspace{1cm} (1)$.

First, let us show how conclude the proof if $f_{\epsilon}$ is a diffeomorphism:

Let $r= \sqrt{1+ \epsilon^2}$ for convenience, $\psi : x \mapsto rx$ be a diffeomorphism from $S(1)$ to $S(r)$ and  as mentioned above $\displaystyle \mathrm{Vol}(\mathbb{S}^n)= \int_{\mathbb{S}^n} \omega$. Then

$\displaystyle \mathrm{Vol}(\mathbb{S}^n) (1+ \epsilon^2)^{\frac{n+1}{2}} = r^{n+1} \int_{\mathbb{S}^n} \omega = \int_{S(1)} \psi^* \omega= \int_{S(r)} \omega= \int_{S(1)} f_{\epsilon}^* \omega$,

so according to $(1)$, the expression $\displaystyle (1+\epsilon^2)^{\frac{n+1}{2}}$ is a polynomial in $\epsilon$. Of course, it is only possible when $n$ is odd.

To conclude the proof, we shall see that $f_{\epsilon}$ is a diffeomorphism when $\epsilon$ is sufficiently small. From $(1)$, if $g_k \in C(\mathbb{S}^n,\mathbb{R})$ is such that $\alpha_k = g_k \omega$,

$\displaystyle f_{\epsilon}^* \omega= \left( 1+ \sum\limits_{k=1}^{n+1} \epsilon^k g_k \right) \omega$.

By compactness, the $g_k$ are bounded so the quantity $1+ \sum\limits_{k=1}^{n+1} \epsilon^k g_k$ does not vanish when $\epsilon$ is small enough. Therefore, $f_{\epsilon}^*\omega$ is a volume form and $f_{\epsilon}$ is an immersion.

Moreover, if $f_{\epsilon}$ were not injective for $\epsilon$ small enough, there would exist sequences $(\epsilon_k)$, $(x_k)$ and $(y_k)$ such that $\epsilon_k \to 0$, $x_k \neq y_k$ and $f_{\epsilon_k}(x_k)= f_{\epsilon_k}(y_k)$, hence

$\displaystyle \frac{x_k-y_k}{\| x_k-y_k \|} = - \epsilon_k \frac{X(x_k)-X(y_k)}{ \| x_k-y_k \| }$.

The first term has norm one, $\epsilon_k \to 0$ and the last term is bounded according to mean value theorem: a contradiction.

Therefore, for $\epsilon$ small enough, $f_{\epsilon}$ is an injective immersion, and consequently a local diffeomorphism according to inverse function theorem. In particular, $\mathrm{Im}(f_{\epsilon})$ is open but also closed by compactness of $S(1)$; by connectedness, $\mathrm{Im}(f_{\epsilon})= S(r)$ and $f_{\epsilon}$ is a diffeomorphism. $\square$


text:
### Home > CC2 > Chapter Ch1 > Lesson 1.2.1 > Problem1-58

1-58.

Copy the number line below and place the following probabilities on it.

1. A $\frac{1}{4}$ chance that you will be the team member who gets supplies tomorrow.

2. A $25\%$ chance of snow tomorrow.

3. A $0.8$ probability of eating vegetables with dinner.

4. P(blue marble) = $\frac { 5 } { 8 }$.

5. A $0.01$ probability that it will be $85^{\large \circ }$F on Saturday.

Convert every decimal and percent to a fraction. Review the Math Notes box in Lesson 1.1.5 or review your Toolkit entry for representations of portions.


text:
# How do you calculate log_6 5 with a calculator?

Aug 12, 2016

${\log}_{6} 5 = \log \frac{5}{\log} 6 \approx 0.8982444$

#### Explanation:

Use the change of base formula:

${\log}_{a} b = \frac{{\log}_{c} b}{{\log}_{c} a}$

So you can use natural or common logs:

${\log}_{6} 5 = \ln \frac{5}{\ln} 6$

${\log}_{6} 5 = \log \frac{5}{\log} 6$

In fact, if you know $\log 2 \approx 0.30103$ and $\log 3 \approx 0.47712$ then you can get a reasonable approximation with basic arithmetic operations:

${\log}_{6} 5 = \log \frac{5}{\log} 6 = \frac{\log 10 - \log 2}{\log 2 + \log 3}$

$\approx \frac{1 - 0.30103}{0.30103 + 0.47712} = \frac{0.69897}{0.77815} \approx 0.89825$

Actually the true value is closer to $0.8982444$


text:
# State vector for a Quad-copter?

Whatever literature I've read on quad-copter dynamics, the state of a quad copter is define as a 12x1 vector, containing the coordinate positions (x,y,z) and velocity (xdot, ydot, zdot) in Earth frame, euler angles (theta, phi, psi) and euler angle derivatives (thetadot, phidot, psidot). However, this code that I am reading seems to have modeled the state vector as a 13x1 vector. It's modeled as : [x,y,z,xdot,ydot,zdot,qw,qx,qy,qz,p,q,r]. I am lost at these last 7 variables. In the initialization module, (qw,qx,qy,qz) are initialized as Quat(1),Quat(2),Quat(3),Quat(4) respectively, and (p,q,r) are all zero. I'm guessing the (p,q,r) are derivatives hence are set to zero during initialization. The Quat() is supposed to be the vector of quaternions, which is again something I haven't found in most literature on modeling of quad-copter dynamics. What is this and why is it needed? I have no prior background in robotics or control systems!

Representing the orientation through Euler angles limits the maneuvers (essentially angle of rotation). For example: won't be able to execute a 360-degree flip. Using quaternions to represent the dynamics avoids that. A better alternative is to use rotational matrices (known also as direction cosine matrices). Rotational matrices are 3x3 matrices that uniquely represent the orientation.

Also, note that the relation between quaternion $Q =[q_v, q_0]$ and the "angular velocity" is given by

$$\frac{d}{dt}[q_v,q_0] = \frac{1}{2}[q_0 \omega + q_v\times\omega, - q_v\cdot \omega]$$

Here $q_v, \omega$ are three-dimensional vectors and $q_0$ is a scalar.

Quaternions are just another way of modelling space orientation of a body. They are used in the same way you would use Euler angles. You can find algorithms (check Wikipedia, I found some there written in several programming languages) to go from quaternions to Euler and reverse. There is no real reason to use them instead of Euler angles, I prefer using the latter, but in some projects I encountered quaternions and simply made the conversion.

• The base of your answer is correct but there are very good reason's to use quaternions: they avoid gimbal lock and are less ambiguous than Euler angles. While not unique, given a quaternion you know exactly what orientation the body is in (the reverse is not true). Given Euler angles, you also need to know what order to apply the rotations in (roll then pitch then yaw? is that about local axes or global axes?) It's very common to use quaternions for control/state purposes and then just convert to Euler angles for presentation to humans. – ryan0270 Sep 18 '17 at 12:02
• Quaternions can also be interpolated much easier and nicer, which can be an advantage when generating reference trajectories. – fibonatic Sep 19 '17 at 6:48

Quaternion are used to avoid gimbal Lock. As Euler-angle suffer from singularity configuration and the gimbal lock needs to be treated explicitly in your algorithm. Quaternion only suffer from a slight singularity in the sense that you express the rotation by a vector (3d) and a rotation around this vector (1d), so one rotation can also be represented by the opposite vector and the opposite angle (ie kind of multiplying the quaternion by -1) . The best is to use rotation matrices to be on the clean side, but it's usually heavier to implement. Using rotation matrices a nice paper is DOI: 0.1109/CDC.2010.5717652

Another point in favor of rotation matrices or quaternion is that the number of convention is sensibly lower from more than 12 for Euler-angles, to 2 for quaternions and 1 for matrices. This is especially good when you work with other people/other software to be sure to be easily interfaced. See more on rotation in general https://www.astro.rug.nl/software/kapteyn/_downloads/attitude.pdf

A last remark, in general for quadrotors the translational dynamics is expressed in world frame and the rotational dynamic is expressed in body frame, which simplifies expression of the control matrix. So naturally [p,q,r] are the angular velocities along the main axis of the body frame.


text:
# Solve two-point boundary value problems in Ruby with spitzy

A few days ago I programmed a numerical method for the solution for two-point boundary value problems, and today I discovered that I can use MathJax to display mathematical formulas in here (although there are some inconveniences related to the use of underscores). So, here goes another blog post!

# Solve ODEs in Ruby with spitzy

Over the weekend I have written a couple of numerical solvers for one-dimensional initial value problems in Ruby, and added them to my project spitzy.

# Solve an advection equation in Ruby with spitzy

A couple of days ago I started working on a collection of numerical methods for differential equations, wirtten in pure Ruby (I have conviced the professor of my numerical DE class that thats a good idea for my final project in said class).

Recently I got surprised by the behaviour of #permute_columns` in the Ruby gem NMatrix.


text:
Chemistry Practice Problems Entropy Practice Problems Solution: Without doing any calculations, determine the sign...

⚠Our tutors found the solution shown to be helpful for the problem you're searching for. We don't have the exact solution yet.

# Solution: Without doing any calculations, determine the sign of ΔSsys and ΔSsurr for each of the chemical reactions below.2 NO2(g) → 2 NO(g) + O2(g), ΔH˚rxn = +113.1 kJ

###### Problem

Without doing any calculations, determine the sign of ΔSsys and ΔSsurr for each of the chemical reactions below.

2 NO2(g) → 2 NO(g) + O2(g), ΔH˚rxn = +113.1 kJ

Entropy

Entropy

#### Q. Without doing any calculations, determine the sign of ΔSsys for each of the following chemical reactions.a. Mg(s) + Cl2(g) → MgCl2(s)b. 2 H2S(g) + 3 O...

Solved • Thu Jan 03 2019 09:31:14 GMT-0500 (EST)

Entropy

#### Q. Rank the following substances in order of decreasing standard molar entropy (S˚).a. I2(g); F2(g); Br2(g); Cl2(g)b. H2O(g); H2O2(g); H2S(g)c. C(s, grap...

Solved • Thu Jan 03 2019 09:31:14 GMT-0500 (EST)

Entropy

#### Q. Without doing any calculations, determine the sign of ΔSsys and ΔSsurr for each of the chemical reactions below.2 CO(g) + O2(g) ⇌ 2 CO2(g), ΔH˚rxn = –...

Solved • Thu Jan 03 2019 09:31:08 GMT-0500 (EST)

Entropy

#### Q. Without doing any calculations, determine the sign of ΔSsys and ΔSsurr for each of the chemical reactions below. In addition, predict under what tempe...

Solved • Thu Jan 03 2019 09:31:08 GMT-0500 (EST)


text:
Assumptions behind simple linear regression model [duplicate]

Let's say we have a simple linear regression model, that is, $y = X\beta + r$ where $y$ is a vector of size n x 1, $X$ a matrix of size n x p, $\beta$ the regression coefficient vector of size p x 1 and $r$ is a residual error of size n x 1.

Most of papers I read consider that $y$ follows a multivariate normal distribution. My question is whether $y$ can follow a distribution different from normal, for example elliptical, etc. Is it necessary that in linear regression, for $y$ to be assumed Gaussian?

I discussed with a researcher and he told me that linear regression models are only suitable (or efficient) for Gaussian assumption. Is this true?

• – Tim
Jun 30, 2015 at 13:53
• If your errors are iid normal, then yes, linear regression will give efficient estimates. But it's not necessary to have normality to use ordinary least squares linear regression. Jul 5, 2015 at 9:05
• Thank you so much for your answer, so OLS is efficient and robust? so OLS can be considered distribution free? Jul 5, 2015 at 9:36

1 Answer

When error-terms are non-normal, you still get many nice properties. The biggest of which is the Gauss-Markov theorem that tells you that the Ordinary Least Square (OLS) estimator, $\hat{\beta}_{OLS} = (X^TX)^{-1}X^TY$, is the best linear unbiased estimator (BLUE).

However, it is only due to the Normality of the error terms that $\hat{\beta}_{OLS}$ is also the Maximum Likelihood Estimator (MLE). That means, you cannot use the asymptotic properties of the MLE. In layman's terms, this means that you cannot use p-values and confidence intervals for $\hat{\beta}_{OLS}$ when the error terms are grossly non-Normal.

In summary, if the error terms are some non-Normal distribution you can use the point estimates for $\hat{\beta}_{OLS}$ but cannot interpret the p-values and confidence intervals that come from MLE theory.

• thank you for your answer. So using OLS estimator is robust under all assumptions? does OLS is only preferred in Gaussian hypothesis? Jun 30, 2015 at 22:53
• The OLS estimator is the best unbiased, linear, estimator. That is, you can interpret it's value but, depending on how non-Normal the error terms are, I would caution against interpeting any p-values or confidence intervals associated with it. Jul 1, 2015 at 0:26


text:
# Application of SU(2) in physics

How can we interpret the representations of SU(2) and $\mathfrak{su}(2)$ in physics?

I have studied a lot of mathematics including representation theory and differential geometry, so I understand SU(2) and $\mathfrak{su}(2)$ from a mathematical background, however I have not studied any physics. So when I look to understanding these (and other Lie groups) in the context of physics I quickly get confused about the standard model and so on. Nevertheless, there seems to be an interesting story between mathematics and physics here.

Could anyone please provide , from a mathematicians point of view, how do the representations SU(2) and $\mathfrak{su}(2)$ works in the world of physics? Similarly, any information regarding SU(3) and $\mathfrak{su}(3)$ would be interesting. Any useful sources would also be greatly appreciated.

• In quantum mechanics angular momentum (spin) $k\in\Bbb Z/2$ corresponds to (or is) the irreducible representation of $SU(2)$ of dimension $2k+1$. You will find representations of $SO(3)$ (and thus of $SU(2)$) also in classical physics under the name multipole expansion. – user8268 May 1 '17 at 12:43


text:
CS 537 Spring 2020, Project 4a: MapReduce

NEW

• Deadline extended to April 3
• Minor edit in spec to rename CombinerGetter to CombineGetter.
• Minor change in Reducer definition to include ReduceStateGetter
• Functions added in spec to make Eager mode easier. Please read the section on Eager mode carefully!

Teaming up!

For this project, you have the option to work with a partner. Read more details in Submitting Your Implementation and Collaboration.

• Due Date by Apr 2, 2020 April 3, 2020 at 10:00 PM
• Questions: We will be using Piazza for all questions.
• This project is best to be done on the lab machines. Alternatively, you can create Virtual Machine and work locally (installation video). You learn more about programming in C on a typical UNIX-based platform (Linux).
• Please take the quiz on Canvas that will be posted on Piazza shortly. It will check if you have read the spec closely. NOTE: The quiz does not work in groups and will have to be taken individually on Canvas.
• Your group (i.e., you and your partner) will have 2 slip days for the rest of the semester. If you are changing partners please talk to the instructor about it.

In 2004, engineers at Google introduced a new paradigm for large-scale parallel data processing known as MapReduce (see the original paper here, and make sure to look in the citations at the end!). One key aspect of MapReduce is that it makes programming tasks on large-scale clusters easy for developers; instead of worrying about how to manage parallelism, handle machine crashes, and many other complexities common within clusters of machines, the developer can instead just focus on writing little bits of code (described below) and the infrastructure handles the rest.

In this project, you’ll be building a simplified version of MapReduce for just a single machine. While it is somewhat easier to build MapReduce for a single machine, there are still numerous challenges, mostly in building the correct concurrency support. Thus, you’ll have to think a bit about how to build the MapReduce implementation, and then build it to work efficiently and correctly.

There are three specific objectives to this assignment:

• To implement a correct and efficient MapReduce framework using threads and related functions.
• To gain more experience writing concurrent code.

Background

To understand how to make progress on any project that involves concurrency, you should understand the basics of thread creation, mutual exclusion (with locks), and signaling/waiting (with condition variables). These are described in the following book chapters:

Read these chapters carefully in order to prepare yourself for this project.

General Idea

Let’s now get into the exact code you’ll have to build. The MapReduce infrastructure you will build supports the execution of user-defined Map() and Reduce() functions.

As from the original paper: “Map(), written by the user, takes an input pair and produces a set of intermediate key/value pairs. The MapReduce library groups together all intermediate values associated with the same intermediate key K and passes them to the Reduce() function.”

“The Reduce() function, also written by the user, accepts an intermediate key K and a set of values for that key. It merges together these values to form a possibly smaller set of values; typically just zero or one output value is produced per Reduce() invocation. The intermediate values are supplied to the user’s reduce function via an iterator.”

A classic example, written here in pseudocode, shows how to count the number of occurrences of each word in a set of documents:

map(String key, String value):
// key: document name
// value: document contents
for each word w in value:
EmitIntermediate(w, "1");

reduce(String key, Iterator values):
// key: a word
// values: a list of counts
int result = 0;
for each v in values:
result += ParseInt(v);
print key, value;

Apart from the Map() and Reduce() functions, there is an option to provide a third user-defined Combine() function, if the Reduce() function is commutative and associative.

The Combine() function does partial merging of the data emitted by a single Mapper(), before it is sent to the Reduce() function. More specifically, a Combine() function is executed as many times as the number of unique keys that its respective Map() function will produce.

Typically the functionality of Combine() and Reduce() functions can be very similar. The main difference between a Combine() and a Reduce() function, is that the former merges data from a single Map() function before it is forwarded to a reducer, while the latter from multiple mappers.

We can extend the previous example, by adding a Combine() function, as follows:

map(String key, String value):
// key: document name
// value: document contents
for each word w in value:
EmitPrepare(w, "1");

combine(String key, Iterator values):
// key: a word
// values: list of counts
int result = 0;
for each v in values:
result += ParseInt(v);
EmitIntermediate(w, result);

reduce(String key, Iterator values):
// key: a word
// values: a list of counts
int result = 0;
for each v in values:
result += ParseInt(v);
print key, value;

What’s fascinating about MapReduce is that so many different kinds of relevant computations can be mapped onto this framework. The original paper lists many examples, including word counting (as above), a distributed grep, a URL frequency access counters, a reverse web-link graph application, a term-vector per host analysis, and others.

What’s also quite interesting is how easy it is to parallelize: many mappers can be running at the same time, and, many reducers can be running at the same time. Users don’t have to worry about how to parallelize their application; rather, they just write Map(), Combine() and Reduce() functions and the infrastructure does the rest.

Code Overview

We give you here the mapreduce.h header file that specifies exactly what you must build in your MapReduce library:

#ifndef __mapreduce_h__
#define __mapreduce_h__

// Different function pointer types used by MR
typedef char *(*CombineGetter)(char *key);
typedef char *(*ReduceGetter)(char *key, int partition_number);
typedef char *(*ReduceStateGetter)(char* key, int partition_number);

typedef void (*Mapper)(char *file_name);
typedef void (*Combiner)(char *key, CombineGetter get_next);
// Simple mode: get_state is NULL and get_next can be called until you get NULL
// Eager mode: get_state and get_next will only be called once inside the reducer
// More details on the modes are provided later
typedef void (*Reducer)(char *key, ReduceStateGetter get_state,
ReduceGetter get_next, int partition_number);
typedef unsigned long (*Partitioner)(char *key, int num_partitions);

// External functions: these are what *you must implement*
void MR_EmitToCombiner(char *key, char *value);
void MR_EmitToReducer(char *key, char *value);
// NOTE: Needs to be implemented ONLY for the Eager mode
void MR_EmitReducerState(char* key, char* state, int partition_number);

unsigned long MR_DefaultHashPartition(char *key, int num_partitions);

void MR_Run(int argc, char *argv[],
Mapper map, int num_mappers,
Reducer reduce, int num_reducers,
Combiner combine,
Partitioner partition);

#endif // __mapreduce_h__

The most important function is MR_Run, which takes the command line parameters of a given program, a pointer to a Map function (type Mapper, called map), the number of mapper threads your library should create (num_mappers), a pointer to a Reduce function (type Reducer, called reduce), the number of reducers (num_reducers), a pointer to a Combine function (type Combiner, called combine), and finally, a pointer to a Partition function (partition, described below).

Thus, when a user is writing a MapReduce computation with your library, they will implement a Map function, a Reduce function, and possibly a Combine or Partition function (or both), and then call MR_Run(). The infrastructure will then create threads as appropriate and run the computation. If we do not wish to use a Combine() function, then NULL is passed instead as the value of combine argument. Note that your code should work in both cases (i.e. use the Combine function if a valid function pointer is passed, or entirely skip the combine step if NULL is passed).

One basic assumption is that the library will create num_mappers threads (in a thread pool) that perform the map tasks. Another is that your library will create num_reducers threads to perform the reduction tasks. Finally, your library will create some kind of internal data structure to pass keys and values from mappers to combiners and from combiners to reducers; more on this below.

Simple Example: Wordcount

Here is a simple (but functional) wordcount program, written to use this infrastructure:

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mapreduce.h"

void Map(char *file_name) {
FILE *fp = fopen(file_name, "r");
assert(fp != NULL);

char *line = NULL;
size_t size = 0;
while (getline(&line, &size, fp) != -1) {
char *token, *dummy = line;
while ((token = strsep(&dummy, " \t\n\r")) != NULL) {
MR_EmitToCombiner(token, "1");
}
}
free(line);
fclose(fp);
}

void Combine(char *key, CombineGetter get_next) {
int count = 0;
char *value;
while ((value = get_next(key)) != NULL) {
count ++; // Emmited Map values are "1"s
}
// Convert integer (count) to string (value)
value = (char*)malloc(10 * sizeof(char));
sprintf(value, "%d", count);

MR_EmitToReducer(key, value);
free(value);
}

void Reduce(char *key, ReduceStateGetter get_state,
ReduceGetter get_next, int partition_number) {
// get_state is only being used for "eager mode" (explained later)
assert(get_state == NULL);

int count = 0;

char *value;
while ((value = get_next(key, partition_number)) != NULL) {
count += atoi(value);
}

// Convert integer (count) to string (value)
value = (char*)malloc(10 * sizeof(char));
sprintf(value, "%d", count);

printf("%s %s\n", key, value);
free(value);
}

int main(int argc, char *argv[]) {
MR_Run(argc, argv, Map, 10,
Reduce, 10, Combine, MR_DefaultHashPartition);
}

Let’s walk through this code, in order to see what it is doing. First, notice that Map() is called with a file name. In general, we assume that this type of computation is being run over many files; each invocation of Map() is thus handed one file name and is expected to process that file in its entirety.

In this example, the code above just reads through the file, one line at a time, and uses strsep() to chop the line into tokens. Each token is then emitted using the MR_EmitToCombiner() function, which takes two strings as input: a key and a value. The key here is the word itself, and the token is just a count, in this case, 1 (as a string). It then closes the file.

The MR_EmitToCombiner() function is used to propagate data from a mapper to its respective combiner; it takes key/values pairs from a single mapper and temporarily stores them so that the the subsequent Combine() calls (i.e. one for each unique emitted key from its mapper), can retrieve and merge its values for each key.

The Combine() function is invoked for each unique key produced by the respective invocation of Map() function. It first goes through all the values for a specific key using the provided get_next function, which returns a pointer to the value passed by MR_EmitToCombiner() or NULL if all values have been processed. It then merges these values to produce exactly one key/value pair. This pair is emmited to the reducers using the MR_EmitToReducer() function.

Finally, the MR_EmitToReducer() function is another key part of your library; it needs to take key/value pairs from the many different combiners and store them in a way that reducers can access them, given constraints described below. Designing and implementing this data structure is thus a central challenge of the project.

The Reduce() function is invoked once per intermediate key, and is passed the key along with a function that enables iteration over all of the values that produced that same key. To iterate, the code just calls get_next() repeatedly until a NULL value is returned; get_next returns a pointer to the value passed in by the MR_EmitToReducer() function above, or NULL when the key’s values have been processed. The output, in the example, is just a count of how many times a given word has appeared, which is just printed in the standard output.

All of this computation is started off by a call to MR_Run() in the main() routine of the user program. This function is passed the argv array, and assumes that argv[1]argv[n-1] (with argc equal to n) all contain file names that will be passed to the mappers.

One interesting function that you also need to pass to MR_Run() is the partitioning function. In most cases, programs will use the default function (MR_DefaultHashPartition), which should be implemented by your code. Here is its implementation:

unsigned long MR_DefaultHashPartition(char *key, int num_partitions) {
unsigned long hash = 5381;
int c;
while ((c = *key++) != '\0')
hash = hash * 33 + c;
return hash % num_partitions;
}

The function’s role is to take a given key and map it to a number, from 0 to num_partitions - 1. Its use is internal to the MapReduce library, but critical. Specifically, your MR library should use this function to decide which partition (and hence, which reducer thread) gets a particular key/list of values to process. For some applications, which reducer thread processes a particular key is not important (and thus the default function above should be passed in to MR_Run()); for others, it is, and this is why the user can pass in their own partitioning function as need be.

Considerations

Here are a few things to consider in your implementation:

• Thread Management This part is fairly straightforward. You should create num_mappers mapping threads, and assign a file to each Map() invocation in some manner you think is best (e.g., Round Robin, Shortest-File-First, etc.). Which way might lead to best performance? You should also create num_reducers reducer threads at some point, to work on the map’d output (more details below).
• Memory Management Another concern is memory management. The MR_Emit*() functions are passed a key/value pair; it is the responsibility of the MR library to make copies of each of these. However, avoid making too many copies of them since the goal is to design an efficient concurrent data processing engine. Then, when the entire mapping and reduction is complete, it is the responsibility of the MR library to free everything.

• API You are allowed to use data structures and APIs only from stdio.h, stdlib.h, pthread.h, string.h, sys/stat.h, and semaphore.h. If you want to implement some other data structures you can add that as a part of your submissions.

Partitioning

Assuming that a valid combine function is passed, there are two places where it is necessary to store intermediate results in order to allow different functions to access them: (a) store mappers output to be accessed by combiners, and (b) store combiners output to be accessed by reducers. You should think which data structure is appropriate for each scenario, and what properties you need to guarantee in your implementation. For example, can you re-use the same data structure for both cases? Should both data structures support concurrent access? It is essential to have clearly answered the above questions before you start writing any code.

Depending on whether you are working alone or in a group, there are different requirements regarding the functionality of reducers:

• One person group: You should launch the reducer threads once all the combiners have finished (i.e. simple mode). Waiting for all combiners (and thus mappers) to finish means that the mappers output data would be available in your intermediate data structure. Then, each reducer thread should start invoking Reduce() functions, where each one will process the data for a single intermediate key. In this case the get_state (of type ReduceStateGetter) should always be NULL. For the simple mode, you do not need to implement the MR_EmitReducerState() function.

• Two person group: You should implement additional functionality (i.e. eager mode) that will allow reducers to process output from combiners “on-the-fly”. This means that mapper and reduce threads should be running simultaneously, and thus be launched from the beginning. Recall that each reducer thread is responsible for a set of keys that are assigned to it (i.e. partition number). Therefore, each reducer thread should wait until data becomes available (for any key that belongs into that set) in the intermediate data structure. This data is “pushed” by the combiners using the MR_EmitToReducer() function. When that occurs, the reducer thread must (wake up if it sleeps and) remove the newly arrived data from the data structure. Then, it should immediately process it by running the appropriate Reduce() function. Finally, it will get the merged partial result from the ReduceStateGetter and store the updated partial result using the MR_EmitReduceState(). If no data is available at a certain point, it should go to sleep again, in order to yield resources to the mappers. Note that it is entirely possible to run the Reduce() multiple times for the same key, as data from different mappers will keep being inserted into the intermediate data structure. When the mappers (or combiners) finish, and there are no more values to merge, the get_next() should return NULL. This can be used to “notify” the reducer that the final result is ready, and therefore can be printed.

Below is an example of how the word count Reduce() function might look like specifically for the eager mode:

void Reduce(char *key, ReduceStateGetter get_state,
ReduceGetter get_next, int partition_number) {
char *state = get_state(key, partition_number);
int count = (state != NULL) ? atoi(state) : 0;

char *value = get_next(key, partition_number);
if (value != NULL) {
count += atoi(value);

// Convert integer (count) to string (value)
value = (char*)malloc(10 * sizeof(char));
sprintf(value, "%d", count);

MR_EmitReducerState(key, value, partition_number);
free(value);
}
else {
printf("%s %d\n", key, count);
}
}

At first, get_state is called to retrieve the state (result) of potential previous Reduce invocations. If no state for the specified key exists, get_state should return NULL. Next, the get_next function retrieves the newly arrived data from a mapper. Then, the two values are merged, and finally the new state (result) is emitted (call to MR_EmitReducerState). Once the last value is received (i.e. get_next returns NULL), the Reducer prints the final count using printf.

Testing

We will soon provide few test applications to test the correctness of your implementation. We will post on Piazza when they become available.

Your code should turn in mapreduce.c which implements the following functions correctly and efficiently: MR_EmitToCombiner(), MR_EmitToReducer(), MR_EmitReducerState() (if working in groups) and MR_Run(). You should also have implemented two versions of get_next() function (one for the Combiner() and one for the Reducer()), as well as a single version of get_state() function.

Your program will be compiled using the following command, where test.c is a test program that contains a main function and the Mapper/Reducer (and potentially the Combiner) as shown in the wordcount example above:

gcc -o mapreduce test.c mapreduce.c mapreduce.h -Wall -Werror -pthread -O

It will also be valgrinded to check for memory errors.

Your code will first be measured for correctness, ensuring that it performs the maps and reductions correctly. If you pass the correctness tests, your code will be tested for performance to see if it runs within suggested time limits.

If you choose to work in pairs, only one of you needs to submit the source code. But, both of you need to submit an additional partner.login file, which contains one line that has the CS login of your partner (and nothing else). If there is no such file, we are assuming you are working alone. If both of you turn in your codes, we will just randomly choose one to grade.

To submit your solution, copy your files into ~cs537-1/handin/<cs-login>/p4a/. One way to do this is to navigate to your solution’s working directory and execute the following command:

cp -r . ~cs537-1/handin/\$USER/p4a/

Consider the following when you submit your project:

• If you use any slip days you have to create a SLIP_DAYS file in the /<cs-login>/p4a/ directory otherwise we use the submission on the due date.
• Your files should be directly copied to ~cs537-1/handin/<cs-login>/p4a/ directory. Having subdirectories in handin/<cs-login>/p4a/ is not acceptable.

Collaboration

This project is to be done in groups of size one or two (not three or more). Now, within a group, you can share as much as you like. However, copying code across groups is considered cheating.

If you are planning to use git or other version control systems (which are highly recommended for this project), just be careful not to put your codes in a public repository.


text:
CoCalc Shared Fileswww / papers / nonsquaresha / junk
Author: William A. Stein
1\edit{{\bf Idea!} If I can give conditions under which $\Sha(J/\Q)[p]=\{0\}$
2(equivalently, $\Sha(E/K)[p]=\{0\}$) then I will know
3{\em automatically} that if there is something in
4$\Sha(A/\Q)[p]$, then that something is {\em visible}, hence
5$E(\Q)/p E(\Q)\neq 0$!!!!  That is, a strong form of finiteness
6of $\Sha$ of~$E$'', Conjecture~\ref{conj:nonvanishing}, and
7the rank-$0$ BSD lower bound on $\#\Sha$ together imply the
8following statement: $L(E,1)=0$ implies $E(\Q)$ is infinite.
9The strong finiteness'' is that there exists prime(s) $p$
10such that $\Sha(E/K)[p]=\{0\}$, where $K/\Q$ is appropriate
11cyclic of degree~$p$.}
12
13
14
15\comment{\section{Old Stuff}
16\noindent{\bf Outline of proof:}
17\begin{enumerate}
18
19\item There should be a twist $E'$ of~$E$ by a quadratic character
20unramified at~$p$ such that $E'(\Q)$ has rank exactly~$1$.  This
21should follow from Waldspurger, Kolyvagin, Gross-Zagier, and the other
22standard results.  Without loss, replace~$E$ by~$E'$ (need to show
23still that Tamagawa numbers don't change too much under a quadratic
24twist; should be easy?)
25
26
27
28\item (*) Use Conjecture~\ref{thm:nonvanishing} and surjective of
29$\rho_{E,p}$ to find an~$\ell$ such that $a_\ell\not\equiv \ell+1 30\pmod{p}$ (or $a_\ell\not\equiv 2\pmod{p}$)
31and $L(E,\chi_{p,\ell},1)\neq 0$.
32
33\item
34Let $K$ be the degree~$p$ and totally ramified at~$\ell$ extension
35of~$\Q$ corresponding to~$\chi_{p,\ell}$,
36let $J=\Res_{K/\Q}(E_K)$, and let~$B$ be the kernel of $\Tr : J \ra E$.
37
38\item The map $E\hookrightarrow J \ra E$ is multiplication by $[K:\Q]=p$,
39so $E[p]\subset B$.
40
41\item Use the irreducible assumption on $\rho_{E,p}$ to prove that
42$B(\Q)$ has no $p$-torsion.
43
44\item The bad reduction of~$B$ is $\ell\cdot N$.  For each prime~$q$
45dividing~$N$, the extension $K/\Q$ is unramified at~$q$ and
46$B_K \isom E^{\oplus (p-1)}$, so, because the formation of N\'eron models commutes
47with unramified base change, $c_{B,q}$ divides $\overline{c}_{E,q}^{(p-1)}$.
48In particular, the rigid hypothesis on~$p$ implies that
49$p\nmid c_{B,q}$.
50
51\item The only thing left to prove is that $p\nmid c_{B,\ell}$.
52This is Conjecture~\ref{conj:nonvanishing}.
53
54\item We conclude that $E(\Q)/p E(\Q)\hookrightarrow \Sha(A)$.
55Since $E(\Q)$ has rank~$1$, this concludes the proof.
56
57\end{enumerate}
58
59}
60
61
62
63
64
65
66
67\comment{
70If~$E$ is an elliptic curve over~$\Q$, then
71there is a (quadratic) twist $E'$ of~$E$ that has rank
72greater than~$0$.
73\end{proposition}
74\begin{proof}
75By the work of many people (see the introduction of
76Ono-Skinner \cite{}), there is a twist $E'$ of $E$ such
77that $L(E',1)\neq0$.  By, e.g., Murty-Murty \cite{}, there is
78a quadratic twist $E''$ of $E'$ such that
79$\ord_{s=1} L(E'',s) = 1$, then by Kolyvagin Theorem (see, e.g.,
80\cite{}), $E''$ has rank~$1$.
81\end{proof}
82\subsection{Twists of Prime Order}
83}
84


text:
## New preprint « Estimates on elliptic equations that hold only where the gradient is large »

A new preprint entitled Estimates on elliptic equations that hold only where the gradient is large written in collaboration with Luis Silvestre (Univ. Chicago) was uploaded to HAL and arXiv.

Abstract: We consider a function which is a viscosity solution of a uniformly elliptic equation only at those points where the gradient is large. We prove that the Hölder estimates and the Harnack inequality, as in the theory of Krylov and Safonov, apply to these functions..


text:
# Math Help - Is there a systematic way to solve trig equations for all zero crossings?

1. ## Is there a systematic way to solve trig equations for all zero crossings?

I'm taking far too long to solve these trig equations. I can't seem to find anything that gives me a systematic way to finding all solutions to a trig equation.

For example, I have $f(x) = \sin (2\pi x)$

It's not particularly difficult differentiate and solve this for x, and end up with:

$x = \frac {\cos^{-1}(0)}{2\pi} = \frac {1}{4}$

I can figure that another zero crossing occurs at $-\frac {1}{4}$, and observe that it is zero every $\frac {1}{2}$. But I find myself lacking a more systematic way of approaching these kinds of problems and solving them more efficiently that I do, currently.

Another short example of one I did yesterday. $f(x) = x + 2 \sin x \implies f'(x) = cos (2\pi x) \implies x = \cos^{-1}(-\frac {1}{2})$. After much bashing of head against wall, I worked out that the solutions are all described by $(1 + 2n)\pi \pm \frac {\pi}{3}~ for ~n \in \mathbb{Z}$. But I can't help but think there's a better way to figure this stuff out. It took a lot of head scratching to figure that one out exactly.

So is there some way I can more easily and quickly find every point at which trig equations make a zero crossing, no matter the period and such?

Hope so, because they are becoming a bit of a pain.

Any help or pointers to this information extremely appreciated, and would save me much time and annoyance.

2. Hello Grep

I think what you need is to study the following equations. They do provide general solutions to the sort of problems you've identified:

For all integer values of $n$:

• $\sin A = \sin B \Rightarrow A = n\pi + (-1)^nB$

• $\cos A = \cos B \Rightarrow A = 2n\pi \pm B$

Check them out for various values of $n$.

The first one gives:

$n = 0: A = B$

$n = 1: A = \pi - B$

$n = 2: A = 2\pi + B$

$n = -1: A = -\pi - B$

... and so on.

The second one is easier:

$n = 0: A = \pm B$

$n = 1: A = 2\pi \pm B$

$n = -1: A = -2\pi \pm B$

... and so on.

Does that help?

3. It does help, sort of. The knowledge that there's a general solution makes me very happy.

Just trying this out a bit, and not 100% sure I get it. But I'm actually really tired right now. Not the best time to figure things out... lol

Let me see if I can apply this. Say, with this equation: $f'(x) = \cos (2\pi x)$.

Ok, so I have $\cos A = \cos B \implies A = 2n \pi \pm B$.

So if I get this right, I solve for B and get $\frac {1}{4}$. So
$n = 0: A = 2(0)\pi \pm \frac {1}{4} = \pm \frac {1}{4}$

$n = 1: A = 2(1)\pi \pm \frac {1}{4} = 2\pi \pm \frac {1}{4}$
etc...
But I also know that $\pm \frac {3}{4}$ is a solution, and I don't see that. So still a bit confused.

Am I close, here? lol I really should get some sleep, then tackle this, but it's bugging me.

Thanks a million for helping me, it's always very appreciated!

Edit: Yeah, I really don't think I got it right. For one, B should be $2\pi x$, I think.

4. Eureka, I think I've got it.

So $cos (2\pi x) = cos (2\pi \frac {1}{4}) = cos (\frac {\pi}{2})$. And $\frac {\pi}{2}$ is my angle B.

Thus,
$n = 0: x = \pm \frac {\frac {\pi}{2}}{2\pi} = \pm \frac {1}{4}$

$n = 1: x = \frac {2\pi - \frac {\pi}{2}}{2\pi} = \frac {3}{4}$ and $x = \frac {2\pi + \frac {\pi}{2}}{2\pi} = \frac {5}{4}$

Having to divide by $2\pi$ because my angle B was $2\pi x$ not just x, and I want to isolate the x.

Thankyouthankyouthankyou!

Now I can sleep... lol

5. Excellent. You've got it!


text:
Sunday, September 23, 2018

Machine learning: Prediction suicidal behaviour based on drug abuse and mental health

There is some well-known correlation between certain mental disorders and suicidal ideation or suicidal behaviour. I was interested in wh...

Monday, July 23, 2018

Zero knowledge AI for Tic-tac-toe and Gomoku (Five in a row) games

Starting from zero When building AI for games, zero knowledge simply means that when the system starts learning the game it only understa...

Thursday, May 17, 2018

Generating APA 6 formatting and references with LaTeX and BibLaTeX

What is LaTeX It's a toolset that is able to transform the documents written in TeX language into something beautifully rendered, l...