text:
# The collapsing map and its coarse inverse are $32 \delta$-coarse Lipschitz to each other

## TL,DR: Why do we have $$d(\overline{\kappa} \circ \kappa, Id) \leq 32 \delta?$$

I am reading Chapter 11 from the book "Geometric group theory" by Cornelia Druţu and Michael Kapovich (freely available here: https://www.math.ucdavis.edu/%7Ekapovich/EPR/ggt.pdf) and I have trouble understanding the end of section 11.8.

The setting is the following, we work in a $$\delta$$-hyperbolic geodesic space $$X$$ (in the sense of Rips), and we want to study geodesic triangles in $$X$$. For this, the authors define a collapsing map $$\kappa$$ that allows us to compare these triangles with geodesic triangles in a real tree, i.e. tripods (like one would do to study $$CAT(\kappa)$$ spaces).

The authors define $$\kappa$$ as follows: "Now, given a geodesic triangle $$T = T (x_1 , x_2 , x_3 )$$ with side-lengths $$a_i$$, $$i = 1, 2, 3$$ in a metric space $$X$$, there exists a unique (possibly up to postcomposition with an isometry $$\tilde{T}\to \tilde{T}$$ ) map $$\kappa$$ to the comparison tripod $$\tilde{T}$$, $$\kappa : T \to \tilde{T} = \mathcal{T}_{a_1 ,a_2 ,a_3} ,$$ which restricts to an isometry on every edge of T : The map $$\kappa$$ sends the vertices $$x_i$$ of $$T$$ to the leaves $$\tilde{x_i}$$ of the tripod $$\tilde{T}$$. The map $$\kappa$$ is called the collapsing map for $$T$$ . We say that the points $$x, y \in T$$ are dual to each other if $$\kappa(x) = \kappa(y)$$."

Question 1: From the book, p.385: "Let $$p_3 \in \gamma_{12} = x_1x_2$$ be a point closest to $$x_3$$. Taking $$R = 2\delta$$ and combining Lemma 11.22 with Lemma 11.52, we obtain:
Corollary 11.62: $$d(p_3, x_{12}) \leq 2(2\delta + 2\delta) = 6\delta$$"

• First of all, it should be $$8 \delta$$ and not $$6 \delta$$.
• Moreover, I can't prove $$6 \delta$$ or $$8 \delta$$. The best I can do is $$16 \delta$$. Can anyone prove the previous corollary?

Still from the book, p.385: "We now can define a continuous coarse inverse $$\overline{\kappa}$$ to $$\kappa$$ as follows : We map the geodesic segment $$\tilde{x_1}\tilde{x_2} \subset \tilde{T}$$ isometrically to a geodesic $$x_1x_2$$. We send $$o\tilde{x_3}$$ onto a geodesic $$x_{12}x_3$$ by an affine map. Since $$d(x_{12},x_{32}) \leq 6\delta$$ and $$d(x_3, x_{32}) = d(\tilde{x_3},o),$$ we conclude that the map $$\overline{\kappa}$$ is \$(1, 6\delta)-Lipschitz.
Exercise 11.63:$$d(\overline{\kappa} \circ \kappa, Id) \leq 32 \delta.$$

Question 2:

1. Why do they say "We send $$o\tilde{x_3}$$ onto a geodesic $$x_{12}x_3$$ by an affine map.", and what do they mean by "affine map"?
2. What about the other sides of the original triangle? Do we get a map like the first picture below (which is how I understand the construction), or like the second picture (which would make more sense)?
3. Again, I can't solve the exercise. I can prove that there exists some $$N$$ such that this is smaller than $$N \delta$$, but I can't prove that $$N = 32$$. Any idea?

Let me know if I need to provide more information, and thanks in advance for any help.

Regarding your questions about constant multiples of the hyperbolicity constant $$\delta$$, what's usually important in these proofs is existence of some $$C$$ such that a certain inequality of the form $$\ldots \le C\delta$$ is true. It's an interesting game to try to get a better and better value of $$C$$, and for certain situations the optimal value of $$C$$ might be important or at least useful. But that kind of situation is rarer than you think. I would say that if the best you can do is $$16\delta$$ then that's just fine.
Regarding your question about affine maps, if one is given two geodesics $$\gamma : [a,b] \to X$$ and $$\delta : [c,d] \to Y$$ in two spaces, an affine map from the subset $$\gamma[a,b] \subset X$$ to the subset $$\delta[c,d] \subset Y$$ is a homeomorphism $$F : \gamma[a,b] \to \delta[c,d]$$ which can be expressed in the form $$F(\delta(t)) = \gamma(f(t))$$ where $$f : [a,b] \to [c,d]$$ is affine in the ordinary sense, meaning $$f(t)=\alpha t + \beta$$ for appropriately chosen constant $$\alpha,\beta$$. An equivalent way to put this is that the map $$F$$ stretches distance by constant factor: $$F(\delta(s),\delta(t)) = K |s-t|$$ for some constant $$K>0$$ independent of $$s,t$$.


text:
# Number System Aptitude Questions and Solutions:

#### Overview:

 Questions and Answers Type: MCQ (Multiple Choice Questions). Main Topic: Quantitative Aptitude. Quantitative Aptitude Sub-topic: Number System Aptitude Questions and Answers. Number of Questions: 10 Questions with Solutions.

1. Find the maximum number of children among whom 150 pieces of chocolates and 225 pieces of fruits can be equally distributed?

1. 85
2. 75
3. 65
4. 55

Solution: To find the maximum number of children to distribute chocolates and fruits equally, we can find out the HCF of the number of chocolates and fruits. Hence HCF of 150 and 225.

Factorize the numbers into their prime numbers. $$150 = 2 \times 3 \times 5^2$$ $$225 = 3^2 \times 5^2$$ collect all the common factors with their minimum available power. $$= 3 \times 5^2$$ $$HCF = 75$$ Hence the maximum of 75 children will get equal pieces of chocolates and fruits.

1. Four bells start to ring at intervals 5, 8, 10, and 12 seconds respectively. Find after what interval of time will they ring together?

1. 100 seconds
2. 110 seconds
3. 120 seconds
4. 125 seconds

Solution: To find the interval of time of four bells to ring together, we can find the LCM of 5, 8, 10, and 12. Here the LCM of 5, 8, 10, and 12 is 120. Hence after 120 seconds, the bells will ring together.

1. What is the largest size of tile which could be used for a rectangular terrace of 2.24 meters long and 3.12 meters wide?

1. 5 cm.
2. 6 cm.
3. 7 cm.
4. 8 cm.

Solution: First, we need to convert length into centimeters. So multiply 100 with the meter to convert it into cm. Hence the terrace is 224 cm long and 312 cm wide.

The HCF of 224 and 312 will be the maximum size of the tile.

HCF of 224 and 312.

Factorize the numbers into their prime numbers. $$224 = 2^5 \times 7$$ $$312 = 2^3 \times 3 \times 13$$ collect all the common factors with their minimum available power. $$= 2^3 = 8$$ $$HCF = 8$$ Hence 8 cm is the largest size of the tile.

1. Find the least number of tiles required for a square room of 14 meters long and 10.20 meters wide?

1. 3570
2. 2270
3. 3230
4. 4128

Solution: If the size of the tiles will be maximum then the required number of tiles will be least. First, we need to convert length into centimeters. So multiply 100 with the meter to convert it into cm. Hence the terrace is 1400 cm long and 1020 cm wide.

The HCF of 1400 and 1020 will be the maximum size of the tile.

HCF of 1400 and 1020.

Factorize the numbers into their prime numbers. $$1400 = 2^3 \times 5^2 \times 7$$ $$1020 = 2^2 \times 3 \times 5 \times 17$$ collect all the common factors with their minimum available power. $$= 2^2 \times 5$$ $$HCF = 20$$ Hence the maximum size of the tile will be 20 cm.

Now the least number of tiles required for a square room. $$= \frac{1400 \times 1020}{20^2}$$ $$= 3570$$ Hence at least 3570 tiles required.

1. Find the number between 300 and 400, which is exactly divisible by 6, 7, and 8?

1. 312
2. 322
3. 336
4. 345

Factorize the numbers into their prime factors. $$6 = 2 \times 3$$ $$7 = 1 \times 7$$ $$8 = 2^3$$ collect all the distinct factors with their highest power. $$LCM = 2^3 \times 3 \times 7$$ $$LCM = 168$$ The multiple of 168 will also be exactly divisible by 6, 7, and 8. Hence the number 336 lies in between 300 and 400, which is exactly divisible by 6, 7, and 8.

format: plain


text:
# Why can a Venn layout for 4+ establishes not be created making use of circles?

This page offers a couple of instances of Venn layouts for 4 collections. Some instances:

Thinking of it for a little, it is difficult to dividing the aircraft right into the $16$ sectors needed for a full $4$- set Venn layout making use of just circles as we can provide for $<4$ collections. Yet it is practical with ellipses or rectangular shapes, so we do not call for non-convex forms as Edwards usages.

So what buildings of a form establish its viability for $n$- set Venn layouts? Especially, why are circles unsatisfactory for the instance $n=4$?

0
2019-05-05 00:52:08
Source Share

The brief solution, from a paper by Frank Ruskey, Carla D. Savage, and also Stan Wagon is as adheres to :

... it is difficult to attract a Venn layout with circles that will certainly stand for all the feasible junctions of 4 (or even more) collections. This is a straightforward effect of the reality that circles can finitely converge in at the majority of 2 factors and also Euler’s relation F − E+V = 2 for the variety of faces, sides, and also vertices in an aircraft chart.

The very same paper takes place in fairly some information concerning the procedure of developing Venn layouts for greater values of n , specifically for straightforward layouts with rotational proportion.

For a straightforward recap, the most effective solution I can locate got on WikiAnswers :

Two circles converge in at the majority of 2 factors, and also each junction develops one new area. (Going clockwise around the circle, the contour from each junction to the next separates a present area right into 2.)

Given that the 4th circle converges the first 3 in at the majority of 6 areas, it develops at the majority of 6 new areas ; that's 14 complete, yet you require 2 ^ 4 = 16 areas to stand for all feasible partnerships in between 4 collections.

Yet you can create a Venn layout for 4 collections with 4 ellipses, due to the fact that 2 ellipses can converge in greater than 2 factors.

Both of these resources show that the essential building of a form that would certainly make it ideal or improper for greater - order Venn layouts is the variety of feasible junctions (and also consequently, below - areas) that can be used 2 of the very same form.

To highlight better, take into consideration several of the intricate forms made use of for n = 5, n = 7 and also n = 11 (from Wolfram Mathworld) :

The framework of these forms is picked such that they can converge with each - various other in as several means as called for to generate the variety of one-of-a-kind areas needed for an offered n .

See additionally : Are Venn Diagrams Limited to Three or Fewer Sets?

0
2019-05-08 19:22:02
Source


text:
# How to compute one-parameter group and corresponding vector fields

I have two related questions to ask -

$1)$ Let $\rho : \mathbb{R} \rightarrow G$ be a one-parameter group. ($\mathbb{R}$ and $G$ are Lie groups). If we take $G = S^1$ then the left invariant vector fields form a $1-$D vector space generated by $X = x \frac{\partial}{\partial y} - y \frac{\partial}{\partial x}$ .

Now the image of $\frac{d}{dt}$ under the map $t \mapsto (\cos at , \sin at)$ is compued to be $aX$. Hence it is the one-parameter group of the vector field $aX$. Can someone please help me in understanding how did we landed on $aX$ here? In general, how do we compute one-parameter groups?

I have taken the fist example from the book - Global Calculus by S.Ramanan. It's given in Remark $3.16$. And second example from same book - Example $3.1$

$2)$ Given a one-parameter group of diffeomorphims, how do we compute the vector fields associated with it? Say for example, $\phi_t(x) = x+t , (t \in \mathbb{R})$ be a one-parameter group of diffeomorphims. What is the vector field associated with it?

• I really can't make much sense of your terminology. Which might be due to the fact that I'm a physicist, NO mathematician by education. I've always thought that $\mathbb{R}$ are the reals, while you say it's a Lie group. What does $S^1$ mean? Is $X = x \frac{\partial}{\partial y} - y \frac{\partial}{\partial x}$ not just an operator, instead of an "1-D vector space"? It might be that your terminology comes from the nowadays standard books on the subject. In that case I'm giving up. – Han de Bruijn Feb 10 '17 at 16:20
• @HandeBruijn $S^1 = \{ (x,y) \in \mathbb{R^2} : x^2 + y^2 = 1 \}$. For more reference - en.wikipedia.org/wiki/N-sphere . Yes, $X$ is an operator which generates vector space. – Dark_Knight Feb 12 '17 at 6:03
• Existing Mathematics Stack Exchange answers + chain references are in here, starting with : Advanced beginners textbook on Lie theory from a geometric viewpoint . – Han de Bruijn Feb 28 '17 at 12:54

The two question are very much related; I hope this goes some way to help you. I have been suitably vague at points to hopefully get the ideas across but happy to try and answer any further concerns (to the best of my ability!).

1) Given a vector field $X$, the question arises: does this give rise to a family of curves? That is, can we find a family of curves whose tangent vectors are precisely $X$.

Let $X=\xi^{1}(x,y)\frac{\partial}{\partial x} + \xi^{2}(x,y)\frac{\partial}{\partial y}$ for some smooth functions $\xi^{i}(x,y)$ and define a curve on $\mathbb{R}^{2}$ by:

\begin{align} \gamma:[a,b] &\longrightarrow \mathbb{R}^{2} \\ t &\longmapsto (x,y) = (\gamma^{1}(t), \gamma^{2}(t)). \end{align}

The vector field along $\gamma$ is then

$$V^{\gamma} = \gamma_{*}\frac{d}{dt} = \frac{d\gamma^{1}}{dt}\frac{\partial}{\partial x}+ \frac{d\gamma^{2}}{dt}\frac{\partial}{\partial y}$$

where $\gamma_{*}$ denotes the push-forward or tangent map. Thus $X$ is a tangent vector to the curve if the components of $X$ and $V^{\gamma}$ coincide on $\gamma$:

$$\frac{d\gamma^{1}}{dt} = \xi^{1}(\gamma(t)), \quad \frac{d\gamma^{2}}{dt} = \xi^{2}(\gamma(t)).$$ From the theory of ordinary differential equations, solutions to this system always exist and are uniquely determined by initial conditions: $\gamma^{1}(0)=x_{0}$ and $\gamma^{2}(0)=y_{0}$. The curve is then said to start at the point $p=(x_{0},y_{0})$. With the map $\gamma$ starting at $p=\gamma(0)$ defined (the integral curves of the vector field $X$), we may then define

\begin{align} \varphi_{t}:\mathbb{R}^{2} &\longrightarrow \mathbb{R}^{2} \\ p &\longmapsto \varphi_{t}(p) = \gamma(t) \end{align}

which can be shown to be a local one-parameter family of diffeomorphisms with the group structure you are asking for.

If you try this with your vector field $aX=ax\frac{\partial}{\partial y} - ay\frac{\partial}{\partial x}$, you get precisely the map $\rho:t\mapsto (\cos(at),\sin(at))$ provided the initial conditions $\rho^{1}(0)=1, \rho^{2}(0)=0$ are used. This then leads to a one-parameter family of diffeomorphisms $\varphi_{t}$ (a one-parameter group) as outlined above.

2) The second question is now the converse of the first: given a one-parameter family of diffeomorphisms, how do you find its associated vector field?

In your example, you are working purely on $\mathbb{R}$, so let us stay there (hopefully extensions to higher dimensions should be obvious). We have a one-parameter family of diffeomorphisms:

\begin{align} \varphi_{t}: \mathbb{R} &\longrightarrow \mathbb{R} \\ x &\longmapsto y = \varphi_{t}(x) \end{align}

This induces a curve $\varphi_{x}$ on $\mathbb{R}$:

\begin{align} \varphi_{x}: [0,a] &\longrightarrow \mathbb{R} \\ t &\longmapsto y = \varphi_{x}(t) = \varphi_{t}(x) \end{align}

which starts at $x$ (i.e. $\varphi_{x}(0)=\varphi_{0}(x)=x$). Thus, we may define a curve starting at every $p\in\mathbb{R}$. Given the set of all such curves we may then define a tangent vector at each point in $\mathbb{R}$. The tangent vector to $\varphi_{x}$ is simply

$$X = \varphi_{x*}\frac{d}{dt} = \left.\frac{d\varphi_{x}}{dt}\frac{\partial}{\partial x}\right|_{t=0}$$

Notice that the result is restricted to $t=0$ as this is where the curve is defined to start.

Using this method with $\varphi_{x}(t)=x+t$ yields the vector $X=\frac{\partial}{\partial x}$.

Let me respond to your second question first (since it is easier). Let $\xi_a$ be a one-parameter family of diffeomorphisms (so, for each value of the real parameter $a$, $\xi_a$ is a diffeomorphism), say, on some manifold $M$. Let $f:M \to \mathbb{R}$ be any smooth function on $M$. Then consider $f$ (composed with) $\xi_a$. For each $a$, this is also a smooth function on $M$. So (since $a$ can be varied) it is a one-paramter family of smooth functions. Call it $f_a$. Now consider $d f_a/da|$ (at $a = 0$). This, again, is a smooth function on $M$. We thus acquire a mapping from smooth functions to smooth functions. One checks that it:

Hence, there is some tangent vector field, $\psi$, on $M$ such that that $\psi(f)$ is this function. This is the vector field associated with the family $\xi_a$ of diffeomorphisms.
As for the first question, I'm not quite sure what you are asking. We have the Lie groups $\mathbb{R}$ (additive reals) and $G$ (circle group); and we have this mapping $\rho$ from $\mathbb{R}$ to $G$ ("wrap the line around the circle"). Further, the $X$ that you give is indeed a left-invariant vector field on $G$; and every left-invariant vector field is a constant multiple of this $X$. We also have the vector field $d/dt$ on $\mathbb{R}$; and its image, under $\rho$, is indeed $X$. Now (I believe$\ldots$) you want to consider a new map $\mathbb{R} \to G$. Fix a number $a$, and let the map send $t$ in $\mathbb{R}$ to $(\cos at, \sin at)$ in $G$. Now, you want to take the image of this same old vector field, $d/dt$, under this new map. This image is indeed the vector field $aX$ on $G$. There are a number of ways to see this. One (which you may not find very satisfying) is to invoke the following fact. For $\gamma(t)$ a curve on a manifold $M$ (so $t$ in reals; $\gamma(t)$ in $M$), then the tangent vector to the curve $\gamma(at)$ (where $a$ is a number) is precisely $a$ times the tangent vector to the original curve. Probably, this is not what you are asking for$\ldots$


text:
# solving equation with natural log

#### wik_chick88

i need to solve this equation:
$$\displaystyle e^{-2.3t} = 0.454 - 0.1638t$$

how do i do this?! i tried to use $$\displaystyle ln$$ but i keep going around in circles?!?!

#### ques

i need to solve this equation:
$$\displaystyle e^{-2.3t} = 0.454 - 0.1638t$$

how do i do this?! i tried to use $$\displaystyle ln$$ but i keep going around in circles?!?!

This is an implicit equation. That is why you keep going round in circles.
You need to study Ordinary Differential Equations to deal with the above equation.


text:
from panda3d.core import PStatThread

class PStatThread

A lightweight class that represents a single thread of execution to PStats. It corresponds one-to-one with Panda’s Thread instance.

Inheritance diagram

__init__(client: PStatClient, index: int) → None

Normally, this constructor is called only from PStatClient. Use one of the constructors below to create your own Thread.

__init__(copy: PStatThread) → None
__init__(thread: Thread, client: PStatClient) → None

addFrame(frame_data: PStatFrameData) → None

This is a slightly lower-level version of new_frame that also specifies the data to send for this frame.

assign(copy: PStatThread) → PStatThread
Return type

getIndex() → int

Returns the index number of this particular thread within the PStatClient.

getThread() → Thread

Return type

property index

Returns the index number of this particular thread within the PStatClient.

Return type

int

newFrame() → None

This must be called at the start of every “frame”, whatever a frame may be deemed to be, to accumulate all the stats that have collected so far for the thread and ship them off to the server.

Calling PStatClient.threadTick() will automatically call this for any threads with the indicated sync name.

property thread


text:
const aiScene* AssimpScene = this->AssimpImporter.ReadFile("C:/cube.obj",  aiProcess_CalcTangentSpace);

• My first guess was that the file was missing an LF at the end, causing the last line to be ignored, but after examining it that doesn't seem to be the case. It appears to be a well formed OBJ; loads in Maya and has correct face normals, so it's not a matter of back face culling. On the other hand it's hard to believe there would be a bug in Assimp's OBJ loader, given it's ubiquity. Is it possible your local copy has been corrupted somehow? – bcrist Oct 14 '14 at 23:29
• Also, when you say "the model viewer provided by assimp" are you referring to the old assimpview or the new open3mod? The file loads fine for me in the latter. – bcrist Oct 14 '14 at 23:38


text:
The inverse cosine function and the inverse sine function are easily understood by anyone who has taken trigonometry. However, some people struggle with the arctangent (or arctan) function and how to use it. If you’re one of those people, this blog post is for you. Read on to find out more about the arctangent and how to use arccosine in your own math calculations. Arctan (also known as reverse tangent or the inverse tangent) is a trigonometric function that finds a number in relation to another value when given an angle. In other words, it tells us how much we need to change our angle in order to double or halve its output. As with many other mathematical functions, there are two different types of Arctangent: Radian Arctangent

## How to Use Arctan in Calculus

When solving for a variable in a calculus equation, the first thing we do is find an expression for that variable that can be manipulated mathematically. Then, we plug that expression into the original equation and substitute it for the variable we’re trying to find. Arctan is especially helpful in trigonometric equations, as it converts an angle’s value into an inverse tangent. This allows us to solve for the trigonometric functions within the equation.

## Arctan Equation

The arctan equation is written as follows:

y = tan^{-1}(x)

## Arctan and Cosine Together

When we’re trying to solve for the inverse of one trigonometric function, we may want to find the cosine value of another trigonometric function within the same equation. In this case, we can use arctan to find the inverse cosine function and vice versa. Arctan can be used with the cosine function to solve for inverse cosine. This can be helpful when solving trigonometric equations with multiple variables that rely on the inverse cosine and cosine function of each other.

## Arccosine Function in Calculus

We can also convert the cosine function into an arccosine function by taking the inverse cosine of the cosine value. We can then plug this into our original equation and solve for the variable that the equation is trying to find.

When solving for a variable in a trigonometric equation, we can use arccosine to find the inverse cosine function, which helps us solve for the other trigonometric functions within the equation.

## How to Solve for Arctan Using Calculus

We can use calculus to solve for arctan, which allows us to substitute an arctan expression into an equation. The best way to do this is to use the following steps:

• Identify the trigonometric functions within the equation – Find the derivative of the equation – Solve for the trigonometric functions in the equation – Use the derivative to find the inverse functions within the solution

## Summary

Arctan can be used to solve for many different trigonometric functions by using the inverse tangent function. This allows us to simplify many trigonometric equations and find unique solutions to the problems at hand.

However, you should remember that even if you understand how to use arctan in your equations, you shouldn’t overuse it. That is, you should use the inverse tangent function sparingly, as it can sometimes be easier to solve trigonometric equations with other functions.

## FAQ

What is arctan?

Arctan is the inverse of the tangent function.

When do you use arctan?

You can use the arctan to determine an angle measure when the side opposite and the side adjacent to the angle are known.

What is arcsin?

Arcsin is the inverse of the sine function.


text:
Diffraction pattern

1. Feb 27, 2005

Steph

I'm stuck on the following question:

the diffraction patterns produced when Xrays of wavelength 46.8pm or electrons of energy 688eV are scattered from the same specimen of aluminium are found to be essentially identical. Use this information to determine the value of Planck's constant, h.

I'll let L = wavelength, p = momentum

So far I've calculated the momentum of the electrons using E = (p^2)/2m. I also have converted the Xray wavelength to SI units.

So I know L = h/p thus h = Lp = constant. But I'm not sure what to do from here. Does the fact they have the same diffraction pattern mean that the wavelength of the X-rays is equal to that of the electron beam?

Thanks for any hints you can give me

2. Feb 27, 2005

Steph

Sorry - I've just found the mistakes in my working and have managed to complete the question


text:
# Product of binary matrices with binary eigenvalues

Consider two binary matrices with obvious patterns: $$C= \begin{bmatrix} 1 &0 &0 &0 &0 &0 &0\\ 1 &0 &0 &0 &0 &0 &0\\ 0 &1 &0 &0 &0 &0 &0\\ 0 &1 &0 &0 &0 &0 &0\\ 0 &0 &1 &0 &0 &0 &0\\ 0 &0 &1 &0 &0 &0 &0\\ 0 &0 &0 &1 &0 &0 &0 \end{bmatrix}$$ and $$T= \begin{bmatrix} 1 &1 &0 &0 &0 &0 &0\\ 0 &1 &1 &0 &0 &0 &0\\ 0 &0 &1 &1 &0 &0 &0\\ 0 &0 &0 &1 &1 &0 &0\\ 0 &0 &0 &0 &1 &1 &0\\ 0 &0 &0 &0 &0 &1 &1\\ 0 &0 &0 &0 &0 &0 &1 \end{bmatrix}$$

The eigenvalues of the matrices $$T^n C,n=0,1,2,3$$ are zeros and consecutive powers of $$2$$ equal to $$0,1,2,4$$. I'd like to have a proof of the generalization of this fact for matrices of larger size with the same patterns.

Note, the entries of $$T^n C$$ in the left upper corner are zeros and binomial coefficients for the power $$n+1$$.

A motivation for this question is in Binary eigenvalues matrices and continued fractions

Some thoughts:

Note that $T = I + N$, where $I$ is the identity matrix and $$N = \pmatrix{0&1\\&0&1\\&&0&1\\&&&0&1\\&&&&0&1\\&&&&&0&1\\&&&&&&0}$$ Notably, $N^7 = 0$. Because $NI = IN$, we can compute $T^n = (I + N)^n$ by binomial expansion. That is, we have $$T^n = \binom n0 I + \binom n1 N + \cdots + \binom n6 N^6$$ We can verify that $T^n$ is therefore the upper triangular Toeplitz matrix for which, in the notation of the linked wiki page, we have $a_{-k} = \binom nk$ whenever $0 \leq k \leq n$ and all other entries are $0$.

With that, we may compute $$T^n C = \pmatrix{\binom n0 + \binom n1 & \binom n2 + \binom n3 & \binom n4 + \binom n5 & \binom n6 &0&0&0\\ \binom n0 & \binom n1 + \binom n2 & \binom n3 + \binom n4 & \binom n5 & 0&0&0\\ 0 & \binom n0 + \binom n1 & \binom n2 + \binom n3 & \binom n4 & 0&0&0\\ 0 & \binom n0 & \binom n1 + \binom n2 & \binom n3 & 0&0&0\\ 0 & 0 & \binom n0 + \binom n1 & \binom n2 & 0&0&0\\ 0 & 0 & \binom n0 & \binom n1 & 0&0&0\\ 0 & 0 & 0 & \binom n0 & 0&0&0\\}$$

• Note that the characteristic polynomial of $T^n C$ does not factor into linear terms for $n = 4$. I suspect that for $N \times N$-matrices, we only should expect powers of $2$ and zeros for $n \leq \left\lfloor N/2 \right\rfloor$. – darij grinberg Aug 18 '18 at 21:31
• An approach that seems promising is to compute the characteristic polynomial of $T^n C$ as $\det \left(X I_N - T^n C\right)$. The matrix $X I_N - T^n C$ is block-triangular, so we only need to find the determinant of its northwestern $4\times 4$-block. The corresponding block of $T^n C$ has $\left(i, j\right)$-th entry $\dbinom{n}{2j-i} + \dbinom{n}{2j-i-1} = \dbinom{n+1}{2j-i}$; I recall such a matrix appear in the work of Christian Krattenthaler, possibly even on MathOverflow. – darij grinberg Aug 18 '18 at 21:41
• Note that the only matrices we need to study are the $n \times n$-matrices $B_n$ whose $\left(i,j\right)$-th entry is $\dbinom{n+1}{2j-i}$ for all $i, j \in \left\{1,2,\ldots,n\right\}$. Once we know the characteristic polynomial of this $B_n$ (which I conjecture to be $\left(X-2^1\right)\left(X-2^2\right)\cdots\left(X-2^n\right)$), we'll obtain those of $T^n C$ for all $N \geq 2n$ using their block-triangular structure. Note that the product of the eigenvalues reminds me of the Aztec diamond. – darij grinberg Aug 18 '18 at 23:05
• Okay, it is definitely true that $\det\left(B_n\right) = 2^{1+2+\cdots+n}$ (so the product of the eigenvalues is correct). This follows from considering $B_n$ as the matrix in the Jacobi-Trudi formula for the skew Schur polynomial $s_{\left(n,n,\ldots,n\right) / \left(n-1,n-2,\ldots,1,0\right)}\left(1,1,\ldots,1\right)$ in $n+1$ variables all set to $1$ (written in terms of the elementary symmetric functions). But this is probably a dead end; I have never heard anything about characteristic polynomials of Jacobi-Trudi matrices. – darij grinberg Aug 18 '18 at 23:17
• Okay, the first eigenvalue ($2$) stands: Let $v_n$ be the column vector whose $i$-th entry (for $i = 1, 2, \ldots, n$) is $\left(-1\right)^{i-1} \dbinom{n-1}{i-1}$. Then, $B_n v = 2 v$. The other eigenvectors look less simple, however. – darij grinberg Aug 18 '18 at 23:51

The left upper block of the matrix $T^n C$ can be conjugated to upper triangular one with the eigenvalues on diagonal by Pascal triangle matrix.


text:
# What is the difference between neural networks and other ways of curve fitting?

For simplicity, let's assume we want to solve a regression problem, where we have one independent variable and one dependent variable, which we want to predict. Let's also assume that there is a nonlinear relationship between the independent and dependent variables.

No matter the way we do it, we just need to build a proper curved line based on existing observations, such that the prediction is the best.

I know we can solve this problem with neural networks, but I also know other ways to create such curves. For example:

1. splines

2. kriging

3. lowess

4. Something I think would also work (do not know if exists): fitting curve using a series of Fourier sine waves, and so on

My questions are:

1. Is it true that neural networks are just one of the ways to fit a non-linear curve to the data?

2. What are the advantages and disadvantages of choosing a neural network over other approaches? (maybe it becomes better when I have many independent variables, and another little guess: maybe the neural network is better in omitting the effect of linear dependent input variables?)

1. In some sense, you're right that a neural net is just another tool to fit data. However, it's quite the tool! There's this universal approximation theorem saying that, under decent conditions, a neural network can get as close as you want to a wide class of functions. This means that you can get the network to give you complicated shapes with squiggles all over if that's the right trend.

2. The universal approximation theorem is a big upside. You don't have to specify that you want to model with sine curves or a particular type of spline. You just let the computer figure that out for you. The result is the ability to model complex patterns and make accurate predictions. The drawback is that the modeling can pick up on coincidences in the data that look like a trend but are not. This causes overfitting. When your goal is to make accurate predictions, a model that has overfit does nothing for you. A second drawback is that neural networks are hard to interpret. A third drawback is that they can take a long time to train, while a linear regression is just a matrix inversion and a couple of matrix products (the $$\hat{\beta}=(X^TX)^{-1}X^Ty$$).

1. It is indeed true that neural networks are just another ways of curve fitting. In fact, as I learned regression after I learned neural networks, I shout out "neural networks are just more sophisticated curve fitting!". However, as Dave said, it can approximate any function in practice. See Google's neural net playground for an interesting animation. You can see how the curve is fitted to the data you have there.

2. The main advantage of neural networks, and one of the primary reasons why they are favored in industry, is that they can predict highly abstract-structured and nonlinear data. The mathematics of this is explained clearly by Dave. I do not think they are any better than other models though, as they do have the same cons of other distance-based models:

• They are prone to converging to local minima if your training data implies a non-convex function.
• The data should be carefully labeled. You might even need to mislabel some data points to reduce overfitting.
• The time you train a neural networks can be awfully long. Most real-life applications require advanced computers. Although this is a practical problem, it is important as it reduces the effect of theoretical advances.
• Feature selection and feature engineering are still two of the most important processes as with any ML problem. More features does not mean better performance in neural networks. The model still is subject to multicollinearity, for example.
• The selection of hyperparameters depend on the nature of the data you have. Therefore, there aren't "one fits all" solutions. This is not a mathematical disadvantage but a practical one.
• Neural nets are scale variant. This takes us back to the fourth point.

However, the fact that it can approximate almost every function compensates for all these disadvantages.

neural networks can solve all taylor series polynomials meaning a NN is an generalized linear model. Most function f(y) can be solved with neural networks. However, many matrix operations can not be generalized for a neural network to solve like determinants. Operations like rotation, scale, and transform also can not be generalized.

you can solve all ordinary least square formulas and general linear model formulas using a neural network. There most n order polynomial curve fitting can be solved by a neural network: spline, b-splines, nurbs can be solved by a neural network.


text:
C. Pattern
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.

In this task, a pattern will be a string consisting of small English letters and question marks ('?'). The question mark in the pattern is a metacharacter that denotes an arbitrary small letter of the English alphabet. We will assume that a string matches the pattern if we can transform the string into the pattern by replacing the question marks by the appropriate characters. For example, string aba matches patterns: ???, ??a, a?a, aba.

Programmers that work for the R1 company love puzzling each other (and themselves) with riddles. One of them is as follows: you are given n patterns of the same length, you need to find a pattern that contains as few question marks as possible, and intersects with each of the given patterns. Two patterns intersect if there is a string that matches both the first and the second pattern. Can you solve this riddle?

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of patterns. Next n lines contain the patterns.

It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed 105 characters.

Output

In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them.

Examples
Input
2?ab??b
Output
xab
Input
2ab
Output
?
Input
1?a?b
Output
cacb
Note

Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of other optimal answers, for example: aab, bab, cab, dab and so on.


text:
# zbMATH — the first resource for mathematics

Functional independence of the singularities of a class of Dirichlet series. (English) Zbl 0905.11036
The authors deal with the algebraic independence and, more generally, with the functional independence of the singularities of $$\log F_j(s)$$, $$j=1,\dots,N$$, and of $${F'_j\over F_j}(s)$$, $$j=1,\dots,N$$, where $$F_j(s)$$ are functions in the Selberg class of axiomatically defined zeta functions. In particular, the following interesting results are proved.
(i) If $$\log F_1(s),\dots,\log F_N(s)$$ are linearly independent over $$\mathbb Q$$, then
$$P(\log F_1(s),\dots,\log F_N(s),s)$$ has infinitely many singularities in the half plane $$\sigma \geq {1\over 2}$$, provided $$P\in \mathbb C[X_1,\dots,X_N,s]$$ with $$\text{deg }P >0$$ as a polynomial in the first $$N$$ variables.
(ii) If $$P\in \mathbb C[X_1,\dots,X_N]$$ with $$\text{deg }P>0$$, then $$P({F'_1\over F_1}(s),\dots,{F'_N\over F_N}(s))$$ is either constant or has infinitely many singularities in the half plane $$\sigma \geq 0$$.
The authors give an arithmetic application of the above results, proving an $$\Omega$$-result for the remainder term of the counting function arising from a factorization problem in algebraic number fields.
 11M41 Other Dirichlet series and zeta functions 11M06 $$\zeta (s)$$ and $$L(s, \chi)$$


text:
# Chaotic spiking oscillators

 Toshimichi Saito (2007), Scholarpedia, 2(9):1831. doi:10.4249/scholarpedia.1831 revision #137443 [link to/cite this article]
Post-publication activity

Curator: Toshimichi Saito

Chaotic Spiking Oscillators (CSOs) are continuous-time autonomous circuits including an integrate-and-fire (IAF) switch and have the following properties.

• 1. The IAF switch is the key element to generate chaos. The IAF is suitable for hardware implementation and chaotic dynamics can be confirmed experimentally.
• 2. In a class of piecewise linear CSOs, return map is described using exact piecewise solution and chaos generation is guaranteed mathematically.
• 3. The CSO can be a building block of pulse-coupled neural networks (PCNNs) that has rich synchronous phenomena. The PCNN has some potential applications including image processing.
Figure 1: Circuits with integrate-and-fire switching

## Integrate-and-Fire Switching in Circuits

Chaotic circuits do not imply just a realization method of existing mathematical models but important real physical systems to investigate interesting nonlinear phenomena (Matsumoto, Chua and Komuro 1985; Maggio G. M., Feo O. D., Kennedy M. P. 1999; Ekwakil A. S., Kennedy M. P. 2001 ). A variety of nonlinear elements are used in existing chaotic circuits and the IAF switch is used in the CSO. In Fig. 1, $$N$$ is a linear sub-circuit and $$S$$ is the IAF switch. If the capacitor voltage $$v_1$$ reaches a threshold voltage $$V_T\ ,$$ $$v_1$$ is reset to the base voltage $$E\ ,$$ instantaneously. If the sub-circuit $$N$$ consists of resistors and dependent sources, it can be replaced with the Thevenin equivalent sub-circuit and the circuit can exhibit periodic waveforms as shown in Fig. 1 (b). This periodic behavior is basic for an integrate-and-fire neuron model which can be a building block of PCNN (Mirollo and Strogatz 1990; Hopfield and Herz 1995). Applications of PCNNs include image processing (Campbell, Wang and Jayaprakash 1999), associative memory (Izhikevich 1999) and Spike-based communication (M. Maggio, Rulkov and Reggiani 2001).

If the sub-circuit $$N$$ includes one memory element (inductor or capacitor) as shown in Fig.1 (c), the circuit can become a CSO. In this case the IAF switch causes vibrate-and-fire dynamics that relates deeply to resonant-and-fire neuron models (Izhikevich 2001).

Figure 2: Simple example of chaotic spiking oscillator

## A Simple Circuit

If $$N$$ includes 1 or more memory elements, $$v_1$$ can vibrate below the threshold and the IAF switch can cause chaotic behavior. Fig. 2 shows a simple example of the CSO. In the figure $$-R$$ is a linear negative resistor. If the capacitor voltage $$v$$ is below the threshold $$V_T\ ,$$ the switch $$S$$ is opened and the circuit dynamics is described by

$$C\frac{dv_1}{dt} = i, \ \ L\frac{di}{dt} = - v_1 + R i, \ \ \mbox{ for } v_1 < V_T. \ \ \ (1)$$

$$v_1$$ is assumed to vibrate divergently. As $$v_1$$ reaches $$V_T\ ,$$ the comparator COMP triggers the monostable multivibrator MM to output an impulse $$v_o\ .$$ The impulse $$v_o$$ closes the IAF switch $$S$$ and $$v_1$$ is reset to the base $$E$$ instantaneously holding the continuity property of $$i\ :$$

$$( v_1(t^+), i(t^+) ) = ( E, i(t) ), \quad \mbox{ if } v_1(t) = V_T. \ \ \ (2)$$

Repeating IAF switching the circuit generate chaos. Using discrete elements such as op-amps, this circuit can be fabricated easily and chaotic behavior can be confirmed experimentally as shown in Fig. 3.

Figure 3: Chaotic attractor for C=22nF, L=300mH, $$V_T$$=1v, -R=-1.2k$$\Omega$$ and E=-0.2V. i is in mA.

Note that there exist various CSOs with two memory elements: applying the IAF switch to some oscillator (e.g., Wien bridge oscillator ), we obtain a CSO.

## Chaotic dynamics

We assume that Equation (1) has unstable complex characteristic root $$\delta \omega \pm j \omega\ :$$

$$\omega^2=\frac{1}{LC}-\left(\frac{R}{2L}\right)^2>0, \;\; \delta = \frac{R}{2 \omega L}>0. \ \ \ (3)$$

In this case $$v_1$$ can vibrate divergently below the threshold $$V_T\ .$$ The divergent vibration and the IAF switching correspond to stretching and folding mechanisms, respectively, which are fundamental for chaos generation. Using the following dimensionless variables and parameters$\tau=\omega t,\ q=\frac{E}{V_T}, \ x=\frac{v_1}{V_T} \ y=-\frac{\delta}{V_T}v+\frac{1}{\omega C V_T}i, \ \ \ (4)$

Equations (1) and (2) are transformed into the following.

$$\begin{array}{c} \left( \begin{array}{c} \dot{x}\\ \dot{y} \end{array} \right) = \left( \begin{array}{cc} \delta & 1\\ -1 & \delta \end{array} \right) \left( \begin{array}{c} x\\ y \end{array} \right) \mbox{ for } x < 1 \ \ \ (5)\\ \\ \mbox{SW: } (x(\tau^+), y(\tau^+))=(q, y(\tau)-\delta(1-q)) \mbox{ if } x_1(\tau)=1 \end{array}$$

where $$\dot{x} \equiv dx/d\tau$$ and $$p=\delta\ .$$ This dimensionless equation is characterized by two parameters $$\delta$$ and $$q$$ which can be controlled by $$-R$$ and $$E\ ,$$ respectively. This equation can reproduce chaotic attractor as shown in Fig. 4.

Figure 4: Chaotic attractor of dimensionless equation for $$\delta=0.05$$ and $$q=-0.2\ .$$

Note that the case $$p \ne \delta$$ governs wider class of CSOs (Mitsubori and Saito 2000).

### 1D return map

The circuit dynamics can be analyzed using 1-D return map. Some objects of the map are shown in Fig. 5: the domain of the map $$L_d=\{(x,y)\;|\;x=0,\; y\ge0\}\ ,$$ the threshold line $$L_T=\{(x,y)|\;x=1 \}\ ,$$ and the base line $$L_q=\{(x,y)|\;x=q \}\ .$$ Let a point on these objects be represented by their $$y$$-coordinate. Also let $$D$$ be a point on $$L_d$$ such that a trajectory started from $$D$$ touches $$L_T$$ within half period.

For the case $$q>0$$ let a trajectory start from a point $$y_0$$ on $$L_d$$ at $$\tau=0\ .$$ If $$0<y_0<D\ ,$$ the trajectory return to $$L_d$$ at $$\tau=2\pi$$ without reaching $$L_T\ .$$ If $$D \le y_0\ ,$$ the trajectory hits the threshold $$L_T$$ and is reset to the base $$L_q\ .$$ Then the trajectory re-starts from $$L_q$$ and returns to $$L_d\ .$$ Since any trajectory started from $$y_0$$ on $$L$$ must return to $$L_d\ ,$$ a 1-D return map can be defined$y_1 = f(y_0), \ f: L_d \rightarrow L_d \ \ \ (6)$

where $$y_1$$ is the return point on $$L_d\ .$$ That is, the circuit dynamics can be integrated into the iteration $$y_{n+1} = f(y_n)$$ as shown in Fig. 5.

Figure 5: Return Map. The orbit enters eventially into the interval $$[a, b]$$ and behaves chaotically.

Using exact piecewise solution of Equation (3), the return map can be described and chaos generation can be guaranteed theoretically (Nakano and Saito 2002) in the sense of ergodic and positive Lyapunov exponent (Lasota and Mackey). The theoretical results can be extended for the case $$q<0$$ and other CSO examples (Mitsubori and Saito 2000).

### Further development

The CSO can be developed into a variety of interesting systems:

• 1. If periodic spike-train input is applied, the CSO exhibits rich synchronous/asynchronous phenomena (Miyach, Nakano and Saito 2003)
• 2. If the sub-circuit has two or more memory elements, the IAF switch can cause hyperchaos and rich bifurcation phenomena (Takahashi, Nakano and Saito 2005)
• 3. The PCNN of CSO can exhibits rich periodic/chaotic synchronous phenomena.

Prospective engineering applications include flexible image processing and spike-based communications (Nakano and Saito 2004).

## References

• Campbell, S. R.; Wang, D. L. and Jayaprakash, C. (1999). Synchrony and Desynchrony in Integrate-and-Fire Oscillators. Neural Computation 11 (7): 1595-1619. doi:10.1162/089976699300016160.
• Elwakil, A. and Kennedy, M. (2001). Construction of classes of circuit-independent chaotic oscillators using passive-only nonlinear devices. IEEE Transactions on Circuits and Systems I: Fundamental Theory and Applications 48 (3): 289-307. doi:10.1109/81.915386.
• Hopfield, J. J. and Herz, A. V. (1995). Rapid local synchronization of action potentials: toward computation with coupled integrate-and-fire neurons.. Proceedings of the National Academy of Sciences 92 (15): 6655-6662. doi:10.1073/pnas.92.15.6655.
• Lasota A., Mackey M. C. (1994) Chaos, Fractals, and Noise - Second Edition, Springer-Verlag.
• Matsumoto, T.; Chua, L. and Komuro, M. (1985). The double scroll. IEEE Transactions on Circuits and Systems 32 (8): 797-818. doi:10.1109/TCS.1985.1085791.
• Maggio, G.; De Feo, O. and Kennedy, M. (1999). Nonlinear analysis of the Colpitts oscillator and applications to design. IEEE Transactions on Circuits and Systems I: Fundamental Theory and Applications 46 (9): 1118-1130. doi:10.1109/81.788813.
• Maggio, G.; Rulkov, N. and Reggiani, L. (2001). Pseudo-chaotic time hopping for UWB impulse radio. IEEE Transactions on Circuits and Systems I: Fundamental Theory and Applications 48 (12): 1424-1435. doi:10.1109/TCSI.2001.972849.
• Mirollo, R. E. and Strogatz, S. H. (1990). Synchronization of Pulse-Coupled Biological Oscillators. SIAM Journal on Applied Mathematics 50 (6): 1645-1662. doi:10.1137/0150098.
• Saito, T. and Mitsubori, K. (2000). Mutually pulse-coupled chaotic circuits by using dependent switched capacitors. IEEE Transactions on Circuits and Systems I: Fundamental Theory and Applications 47 (10): 1469-1478. doi:10.1109/81.886977.
• Miyachi, K.; Nakano, H. and Saito, T. (2003). Response of a simple dependent switched capacitor circuit to a pulse-train input. IEEE Transactions on Circuits and Systems I: Fundamental Theory and Applications 50 (9): 1180-1187. doi:10.1109/TCSI.2003.816335.
• Nakano, H. and Saito, T. (2002). Basic dynamics from a pulse-coupled network of autonomous integrate-and-fire chaotic circuits. IEEE Transactions on Neural Networks 13 (1): 92-100. doi:10.1109/72.977276.
• Nakano, H. and Saito, T. (2004). Grouping Synchronization in a Pulse-Coupled Network of Chaotic Spiking Oscillators. IEEE Transactions on Neural Networks 15 (5): 1018-1026. doi:10.1109/TNN.2004.832807.
• Takahashi, Y.; Nakano, H. and Saito, T. (2005). Hyperchaotic spiking oscillators with periodic pulse-train input. IEEE Transactions on Circuits and Systems II: Express Briefs 52 (6): 344-348. doi:10.1109/TCSII.2005.849002.

Internal references


text:
# Force on a Magnetized Body in a Non-Uniform Magnetic Field

In Griffith's Electrodynamics, it is shown that when a magnetic moment, $$\mathbf{m}$$, is subjected to a non-uniform magnetic field, then it experiences a net force given by $$\mathbf{F}=\mathbf{\nabla} (\mathbf{m} \cdot\mathbf{B})$$.

Now suppose we have a magnetized body of volume, $$V$$, with a magnetization $$\mathbf{M}\equiv \frac{\mathbf{m}}{V}$$. Is it correct to say that the force the body experiences is given by $$\mathbf{F}= \int \mathbf{\nabla} (\mathbf{M} \cdot\mathbf{B}) dV$$ ? If yes, would this force be uniform throughout the magnetized body?

• Note that integrand is singular on the body surface. Do you include that surface contribution or not? Why? Some derivation of the integral formula is needed. – Ján Lalinský Aug 21 '19 at 13:56
• Ján, thanks for the comment. Would it be correct to say the surface contributions can be added using the Maxwell Stress Tensor? Perhaps I am not really sure of the implications of the force equation I've presented in the question, can you shed some light onto this? Thanks! – Dave Aug 21 '19 at 15:55
• @JánLalinský If I understood the derivation of the $\mathbf{F} = \nabla\left(\mathbf{m}\cdot\mathbf{B}\right)$ force in Jackson §5, the gradient is not singular at the surface because it acts on a different variable than the integration variable. To be precise, the gradient comes from a linearized Taylor expansion of $\mathbf{B}(\mathbf{x})$ at $\mathbf{x} = \mathbf{0}$. The $\mathbf{m}$ is a function of $\mathbf{x}'$ in interior of body. So $\nabla\left(\mathbf{m}\cdot\mathbf{B}\right) = \left(\mathbf{m}\cdot\nabla\right)\mathbf{B}$, and discontinuity of $\mathbf{m}$ at surface plays no role. – Tob Ernack Aug 22 '19 at 4:01

Assuming the magnetic field is linear (i.e. we can Taylor expand $$\mathbf{B}$$ around the origin and truncate all terms of order higher than $$1$$), then you are correct. The formula is also approximately true for more general $$\mathbf{B}$$ as long as the dimensions of the extended body are small compared to the region over which $$\mathbf{B}$$ is approximately linear.

The proof is almost exactly the same as the proof for the force on a magnetic moment $$\mathbf{m}$$, but we use the definition of magnetization $$\mathbf{M}$$ to rewrite it as an integral over the volume.

The relevant step for the OP is the last step in the derivation I gave in next section, which I reproduce here:

The definition of magnetic moment in terms of magnetization is $$\mathbf{m} = \iiint_V\mathbf{M}(\mathbf{x}')\mathrm{d}^3x'$$. From Griffiths' formula for the force on the magnetic moment we have $$\mathbf{F} = \left[\nabla(\mathbf{m}\cdot\mathbf{B}(\mathbf{x}))\right](\mathbf{0})$$

Now we can rewrite $$\mathbf{m}$$ in terms of $$\mathbf{M}$$ to obtain the desired formula by the OP:

$$\mathbf{F} = \left[\nabla\left(\iiint_V \mathbf{M}(\mathbf{x}')\mathrm{d}^3x'\cdot\mathbf{B}(\mathbf{x})\right)\right](\mathbf{0}) = \iiint_V \left[\nabla(\mathbf{M}(\mathbf{x}')\cdot\mathbf{B}(\mathbf{x}))\right](\mathbf{0})\mathrm{d}^3x'$$

So the force per unit volume is $$\mathbf{f}(\mathbf{x}') = \left[\nabla(\mathbf{M}(\mathbf{x}')\cdot\mathbf{B}(\mathbf{x}))\right](\mathbf{0})$$ and if the magnetization is uniform, this force density is also uniform.

Just for completeness, here is a full derivation based on Jackson, Chapter 5. I tried being explicit which variables we differentiate and evaluate against. The steps get a bit tedious, but I wanted to organize it so that all details are explained.

Write $$\mathbf{B}(\mathbf{x'})$$ as a Taylor expansion around $$\mathbf{0}$$: $$\mathbf{B}(\mathbf{x'}) = \mathbf{B}(\mathbf{0}) + \left[\left(\mathbf{x'}\cdot\nabla\right)\mathbf{B}(\mathbf{x})\right](\mathbf{0}) + \ldots \tag{1}\label{1}$$

We assume we can neglect higher order terms (so if $$\mathbf{B}$$ is linear over space, this is exactly true). Also the $$\nabla$$ and evaluation operators do not act on $$\mathbf{x}'$$, but on $$\mathbf{x}$$.

The total force on the body due to the external magnetic field $$\mathbf{B}$$ is given (exactly) by $$\mathbf{F} = \iiint_V \mathbf{J}(\mathbf{x}')\times\mathbf{B}(\mathbf{x}')\mathrm{d}^3x' \tag{2}\label{2}$$

The current $$\mathbf{J}$$ is assumed to be zero outside of the finite volume of the body. We may take $$V$$ to be a volume enclosing the body, with some slight empty space included to avoid having discontinuities on the surface of $$V$$ (this is important in ($$\ref{15}$$) below). We can include the slight empty space because it does not affect the volume integral for the force.

Combining ($$\ref{1}$$) and ($$\ref{2}$$) we obtain: $$\mathbf{F} = -\mathbf{B}(\mathbf{0})\times\iiint_V \mathbf{J}(\mathbf{x}')\mathrm{d}^3x' + \iiint_V\mathbf{J}(\mathbf{x}')\times\left[\left(\mathbf{x'}\cdot\nabla\right)\mathbf{B}(\mathbf{x})\right](\mathbf{0})\mathrm{d}^3x' \tag{3}\label{3}$$

The first term is zero in the magnetostatic case where $$\nabla'\cdot\mathbf{J}(\mathbf{x}') = 0$$ (see for example here for a proof).

We have the general vector calculus identities: $$\nabla(\mathbf{A}\cdot\mathbf{B}) = (\mathbf{A}\cdot\nabla)\mathbf{B} + (\mathbf{B}\cdot\nabla)\mathbf{A} + \mathbf{A}\times(\nabla\times\mathbf{B}) + \mathbf{B}\times(\nabla\times\mathbf{A}) \tag{4}\label{4}$$ $$\nabla\times(\psi\mathbf{A}) = \psi(\nabla\times\mathbf{A}) + (\nabla\psi)\times\mathbf{A} \tag{5}\label{5}$$

Using ($$\ref{4}$$) with $$\mathbf{A} = \mathbf{x}'$$ and $$\mathbf{B} = \mathbf{B}(\mathbf{x})$$ we have:

$$\mathbf{J}(\mathbf{x}')\times\nabla(\mathbf{x}'\cdot\mathbf{B}(\mathbf{x})) = \mathbf{J}(\mathbf{x}')\times\left[(\mathbf{x}'\cdot\nabla)\mathbf{B}(\mathbf{x})\right] \tag{6}\label{6}$$

because $$\nabla$$ acts on $$\mathbf{x}$$, not on $$\mathbf{x}'$$ and because $$\nabla\times\mathbf{B} = \mathbf{0}$$ (since $$\mathbf{B}$$ is an external magnetic field, the sources are not inside the volume $$V$$ and Ampere's Law implies zero curl in that case).

Using ($$\ref{5}$$) with $$\psi = \mathbf{x}'\cdot\mathbf{B}(\mathbf{x})$$ and $$\mathbf{A} = \mathbf{J}(\mathbf{x}')$$ we have: $$\nabla\times\left[(\mathbf{x}'\cdot\mathbf{B}(\mathbf{x}))\mathbf{J}(\mathbf{x}')\right] = \nabla(\mathbf{x}'\cdot\mathbf{B}(\mathbf{x}))\times\mathbf{J}(\mathbf{x}') \tag{7}\label{7}$$

Combining ($$\ref{6}$$) and ($$\ref{7}$$) we obtain: $$\mathbf{J}(\mathbf{x}')\times\left[\left(\mathbf{x'}\cdot\nabla\right)\mathbf{B}(\mathbf{x})\right] \stackrel{(\ref{6})}{=} \mathbf{J}(\mathbf{x}')\times\nabla(\mathbf{x}'\cdot\mathbf{B}(\mathbf{x})) \stackrel{(\ref{7})}{=} -\nabla\times\left[(\mathbf{x}'\cdot\mathbf{B}(\mathbf{x}))\mathbf{J}(\mathbf{x}')\right] \tag{8}\label{8}$$

Using this in ($$\ref{3}$$) we get: $$\mathbf{F} = -\iiint_V \nabla\times\left[(\mathbf{x}'\cdot\mathbf{B}(\mathbf{x}))\mathbf{J}(\mathbf{x}')\right](\mathbf{0})\mathrm{d}^3x' = -\left\{\nabla\times\iiint_V\left[\mathbf{x}'\cdot\mathbf{B}(\mathbf{x})\right]\mathbf{J}(\mathbf{x}')\mathrm{d}^3x'\right\}\bigg\vert_{\mathbf{x}=\mathbf{0}} \tag{9}\label{9}$$

Now we use another vector calculus identity: $$\mathbf{A}\times(\mathbf{B}\times\mathbf{C}) = (\mathbf{A}\cdot\mathbf{C})\mathbf{B} - (\mathbf{A}\cdot\mathbf{B})\mathbf{C} \tag{10}\label{10}$$

Use ($$\ref{10}$$) with $$\mathbf{A} = \mathbf{B}(\mathbf{x})$$ and $$\mathbf{B} = \mathbf{x}'$$ and $$\mathbf{C} = \mathbf{J}(\mathbf{x}')$$ to obtain: $$\mathbf{B}(\mathbf{x})\times(\mathbf{x}'\times\mathbf{J}(\mathbf{x}')) = \left[\mathbf{B}(\mathbf{x})\cdot\mathbf{J}(\mathbf{x}')\right]\mathbf{x}' - \left[\mathbf{x}'\cdot\mathbf{B}(\mathbf{x})\right]\mathbf{J}(\mathbf{x}') \tag{11}\label{11}$$

We want to calculate $$\iiint_V \left[\mathbf{B}(\mathbf{x})\cdot\mathbf{J}(\mathbf{x}')\right]\mathbf{x}'\mathrm{d}^3x' = \sum\limits_{i=1}^3B_i(\mathbf{x})\iiint_V J_i(\mathbf{x}')\mathbf{x}'\mathrm{d}^3x' \tag{12}\label{12}$$

We now have vector calculus identity: $$\nabla'\cdot(\psi\mathbf{A}) = (\nabla'\psi)\cdot\mathbf{A} + \psi(\nabla'\cdot\mathbf{A}) \tag{13}\label{13}$$

Use ($$\ref{13}$$) with $$\psi = \mathbf{x}'\cdot\hat{\mathbf{e}}_i = x_i'$$ and $$\mathbf{A} = \mathbf{J}(\mathbf{x}')$$: $$\nabla'\cdot(x_i'\mathbf{J}(\mathbf{x}')) = (\nabla'x_i')\cdot\mathbf{J}(\mathbf{x}') + x_i'(\nabla'\cdot\mathbf{J}(\mathbf{x}')) = J_i(\mathbf{x}') \tag{14}\label{14}$$

Here we used $$\nabla'x_i' = \hat{\mathbf{e}}_i$$ and $$\nabla'\cdot\mathbf{J}(\mathbf{x}') = 0$$ (because we work in magnetostatic case).

So using ($$\ref{14}$$) and then integration by parts we have: $$\iiint_V J_i(\mathbf{x}')\mathbf{x}'\mathrm{d}^3x' = \iiint_V\nabla'\cdot(x_i'\mathbf{J}(\mathbf{x}'))\mathbf{x}'\mathrm{d}^3x' = \sum\limits_{j=1}^3\iiint_V\nabla'\cdot(x_i'\mathbf{J}(\mathbf{x}'))x_j'\mathrm{d}^3x'\hat{\mathbf{e}}_j$$$$= \sum\limits_{j=1}^3\iiint_V\left[\nabla'\cdot(x_i'\mathbf{J}(\mathbf{x}')x_j') - x_i'\mathbf{J}(\mathbf{x}')\cdot\nabla'x_j'\right]\mathrm{d}^3x'\hat{\mathbf{e}}_j = \sum\limits_{j=1}^3\left[\mathop{\LARGE\unicode{x222f}}_{\partial V}x_i'x_j'\mathbf{J}(\mathbf{x}')\cdot\hat{\mathbf{n}}'da' - \iiint_V x_i'J_j(\mathbf{x}')\mathrm{d}^3x'\right]\hat{\mathbf{e}}_j$$$$=-\iiint_V x_i'\mathbf{J}(\mathbf{x}')\mathrm{d}^3x'\tag{15}\label{15}$$

To move from the second to the third equality, we used ($$\ref{13}$$) again with $$\psi = x_j'$$ and $$\mathbf{A} = x_i'\mathbf{J}(\mathbf{x}')$$. To move from the third to the fourth equality, we used the divergence theorem and the result $$\nabla'x_j' = \hat{\mathbf{e}}_j$$. To move from the fourth to the fifth equality, we used $$\mathbf{J} = \mathbf{0}$$ on the boundary of $$V$$ because we chose $$V$$ slightly larger than the region where the current density is nonzero. We also recombined the components of $$\mathbf{J}$$.

After all this mess, we see that ($$\ref{12}$$) becomes: $$\iiint_V \left[\mathbf{B}(\mathbf{x})\cdot\mathbf{J}(\mathbf{x}')\right]\mathbf{x}'\mathrm{d}^3x' = -\sum\limits_{i=1}^3B_i(\mathbf{x})\iiint_V x_i'\mathbf{J}(\mathbf{x}')\mathrm{d}^3x' = -\iiint_V \left[\mathbf{x}'\cdot\mathbf{B}(\mathbf{x})\right]\mathbf{J}(\mathbf{x}')\mathrm{d}^3x' \tag{16}\label{16}$$

Therefore, after taking integrals of ($$\ref{11}$$) we obtain: $$\iiint_V \left[\mathbf{x}'\cdot\mathbf{B}(\mathbf{x})\right]\mathbf{J}(\mathbf{x}')\mathrm{d}^3x' = -\frac{1}{2}\mathbf{B}(\mathbf{x})\times\iiint_V\mathbf{x}'\times\mathbf{J}(\mathbf{x}')\mathrm{d}^3x' \tag{17}\label{17}$$

The magnetization is defined by $$\mathbf{M}(\mathbf{x}') = \frac{1}{2}\mathbf{x}'\times\mathbf{J}(\mathbf{x}')$$ and the magnetic moment is defined by $$\mathbf{m} = \iiint_V \mathbf{M}(\mathbf{x}')\mathrm{d}^3x'$$ so we conclude from ($$\ref{9}$$) and ($$\ref{17}$$): $$\mathbf{F} = \frac{1}{2}\left\{\nabla\times\left[\mathbf{B}(\mathbf{x})\times\iiint_V\mathbf{x}'\times\mathbf{J}(\mathbf{x}')\mathrm{d}^3x'\right]\right\}\bigg\vert_{\mathbf{x}=\mathbf{0}} = \left\{\nabla\times\left[\mathbf{B}(\mathbf{x})\times\iiint_V\mathbf{M}(\mathbf{x}')\mathrm{d}^3x'\right]\right\}\bigg\vert_{\mathbf{x}=\mathbf{0}} = \left\{\nabla\times(\mathbf{B}(\mathbf{x})\times\mathbf{m})\right\}\big\vert_{\mathbf{x}=\mathbf{0}} \tag{18}\label{18}$$

We have yet another vector calculus identity: $$\nabla\times(\mathbf{A}\times\mathbf{B}) = \mathbf{A}(\nabla\cdot\mathbf{B}) - \mathbf{B}(\nabla\cdot\mathbf{A}) + (\mathbf{B}\cdot\nabla)\mathbf{A} - (\mathbf{A}\cdot\nabla)\mathbf{B} \tag{19}\label{19}$$

Use ($$\ref{19}$$) with $$\mathbf{A} = \mathbf{B}(\mathbf{x})$$ and $$\mathbf{B} = \mathbf{m}$$. We conclude that:

$$\mathbf{F} = \left[(\mathbf{m}\cdot\nabla)\mathbf{B}(\mathbf{x})\right](\mathbf{0})$$

because $$\nabla$$ does not act on $$\mathbf{m}$$ and Gauss' law of magnetism implies $$\nabla\cdot\mathbf{B} = 0$$.

We now use ($$\ref{4}$$) with $$\mathbf{A} = \mathbf{m}$$ and $$\mathbf{B} = \mathbf{B}(\mathbf{x})$$, and again $$\nabla\times\mathbf{B} = \mathbf{0}$$ (external field) to obtain the formula from Griffiths for the force on magnetic moment $$\mathbf{m}$$: $$\mathbf{F} = \left[\nabla(\mathbf{m}\cdot\mathbf{B}(\mathbf{x}))\right](\mathbf{0}) \tag{20}\label{20}$$

Now we can rewrite $$\mathbf{m}$$ in terms of $$\mathbf{M}$$ to obtain the desired formula by the OP:

$$\mathbf{F} = \left[\nabla\left(\iiint_V \mathbf{M}(\mathbf{x}')\mathrm{d}^3x'\cdot\mathbf{B}(\mathbf{x})\right)\right](\mathbf{0}) = \iiint_V \left[\nabla(\mathbf{M}(\mathbf{x}')\cdot\mathbf{B}(\mathbf{x}))\right](\mathbf{0})\mathrm{d}^3x' \tag{21}\label{21}$$

The force density is then given by $$\mathbf{f}(\mathbf{x}') = \left[\nabla(\mathbf{M}(\mathbf{x}')\cdot\mathbf{B}(\mathbf{x}))\right](\mathbf{0}) \tag{22}\label{22}$$


text:
# Why Can't My Computer Do Simple Arithmetic? - Comments

• Insights
Until now, nothing I could find in the C and C++ standard libraries can do correct computation with floats. I don't understand why the committee have done nothing about this even though there are already external libraries to do this, some of which are for free online.
I also don't know why Microsoft only includes part of their solution in a Decimal class (System.Decimal) that can be used for only 28-29 significant digits as the number's precision even though I believe they can extend it to 1 zillion digits (can a string length be that long to verify its output accuracy anyway ?).

jim mcnamara
Mentor
As a guess, how about ROI? The Fujitsu Sparc64 M10 (has 16 cores), according to my friendly local Oracle peddler, supports it by writing the library onto the chip itself. Anyway one chip costs more than you and I make in a month, so it definitely is not a commodity chip. The z9 cpu like the ones in Power PC's supports decimal, too.

So in a sense some companies "decimalized" in hardware. Other companies saw it as a way to lose money - my opinion. BTW this problem has been around forever. Hence other formats: Oracle internal math is BCD with 32? decimals, MicroFocus COBOL is packed decimals with decimals = 18 per their website
http://supportline.microfocus.com/documentation/books/sx20books/prlimi.htm

Mentor
As an addendum - somebody may want to consider how to compare as equal 2 floating point numbers. Not just FLT_EPSILON or DBL_EPSILON which are nothing like a general solution.
This isn't anything I've ever given a lot of thought to, but it wouldn't be difficult to compare two floating point numbers in memory (32 bits, 64 bits, or more), as their bit patterns would be identical if they were equal. I'm not including unusual cases like NAN, denormals, and such. The trick is in the step going from a literal such as 0.1, to its representation as a bit pattern.

Maybe it's time to review/modify/improve the IEEE-754 standard for floating-point arithmetic (IEEE floating point).

jim mcnamara
Mentor
This is from code by Doug Gwyn mostly. FP compare is a PITA because you cannot do a bitwise compare like you do with int datatypes.
You also cannot do this reliably either:
Code:
  if (float_datatype_variable==double_datatype_variable)
where you can otherwise test equality for most int datatypes: char, int, long with each other.

Code:
#include <stdlib.h>
#include <stdio.h>
#include <fenv.h>
// compile with gcc -std=c99 for fpclassify
inline int classify(double x) // filter out bad numbers correct for inexact, INT_MIN is the error return;
{
switch(fpclassify(x))
{
case FP_INFINITE:
errno=ERANGE;
return INT_MIN;
case FP_NAN:
errno=EINVAL;
return INT_MIN;
case FP_NORMAL:
return 2;
case FP_SUBNORMAL:
case FP_ZERO:
return 0;
}
return FP_NORMAL;  //default
}

// doug gwyn's reldif function
//    usage:  if(reldif(a, b) <= TOLERANCE) ...
#define Abs(x)  ((x) < 0 ? -(x) : (x))
#define Max(a, b) ((a) > (b) ? (a) : (b))
double maxulp=0;  // tweek this into TOLERANCE
inline double reldif(double a, double b)
{
double c = Abs(a);
double d = Abs(b);
int rc=0;

d = Max(c, d);
d = (d == 0.0) ? 0.0 : Abs(a - b) / d;
rc=classify(d);
if(!rc) // correct almost zeroes to zero
d=0.;
if(rc == INT_MIN )
{                            // error return
errno=ERANGE;
d=DBL_MAX;
perror("Error comparing values");
}
return d;
}
//    usage:  if(reldif(a, b) <= TOLERANCE) ...

Remember the Pentium FDIV bug?
That was half my life ago! No I don't remember it specifically... nor do I remember using anything that might have had it, once windows 95 came out I went through several older computers before buying a new dell 10 years ago (P4 2.4ghz), and haven't programmed much since...

Mentor
Remember the Pentium FDIV bug?
I definitely do! I wrote a small x86 assembly program that checked your CPU to see if it was a Pentium, and, if so, used the FDIV instruction to do one of the division operations that was broken. It then compared the computed result against the correct answer to see if they were the same.

I sent it to Jeff Duntemann, Editor in Chief of PC Techniques magazine. He published it in the Feb/Mar 1995 issue. I thought he would publish it as a small article (and send me some $). Instead he published in their HAX page, as if it had been just some random code that someone had sent in. That wouldn't have been so bad, but he put a big blurb on the cover of that issue, "Detect Faulty Pentiums! Simple ASM Test" vela Staff Emeritus Science Advisor Homework Helper Education Advisor The Pentium would have been 80586, but I guess the marketing people got involved and changed to Pentium. If it was the first model, that was the one that had the division problem where some divisions gave an incorrect answer out in the 6th or so decimal place. It cost Intel about$1 billion to recall and replace those bad chips. I think that was in '94, not sure.
There was a joke that Intel changed the name to Pentium because they used the first Pentium to add 100 to 486 and got the answer 585.9963427...

Last edited:
Ibix and Silicon Waffle
Mentor
There was a joke that Intel changed the name to Pentium because they used the first Pentium to add 100 to 486 and got the answer 485.9963427...
That cracked me up!

Silicon Waffle
Maybe it's time to review/modify/improve the IEEE-754 standard for floating-point arithmetic (IEEE floating point).
It's not a problem with the standard, it's a limitation of how accurate you can represent arbitrary floating point numbers (no matter the representation). I believe that the common implementations can exactly represent powers of 2 correct?

One application where I used this, is when using the additive blending through the GPU pipeline, to compute a reduction. Integers were not supported in OpenGL for this, so I instead chose a very small power of 2, and relied on the fact that it and it's multiples could be exactly represented using IEEE floating point specification, allowing me to effectively do an exact summation/reduction purely through GPU hardware.

Silicon Waffle
Mentor
It's not a problem with the standard, it's a limitation of how accurate you can represent arbitrary floating point numbers (no matter the representation). I believe that the common implementations can exactly represent powers of 2 correct?
If the fractional part is the sum of negative powers of 2, and the smallest power of 2 can be represented in the mantissa, then yes, the representation is exact. So, for example, 7/8 = 1/2 + 1/4 + 1/8 is represented exactly.

The simplest example of a malfunction I can think of is 1/3+1/3+1/3=0.99999999. The main thing I remember from way back when (in my early teens) was that my computer had 8 decimal digits similar to a calculator, and the exponential 10 times for the number of decimal places followed by "E". The oddity that sticks out is that I remember trying to comprehend a 5 byte scheme that it used.

But regardless you have to compromise in some direction giving up speed in favor of accuracy or does the library system "skim" through easier values to increase efficiency? (I mean the newest system(s)) I'm guessing there are different implementations of the newest standards? I'm almost clueless how it works!
Another is sine tables, had to devise my own system to increase precision there, too! (nevermind found this:)
"The standard also includes extensive recommendations for advanced exception handling, additional operations (such as trigonometric functions), expression evaluation, and for achieving reproducible results."
from here: https://en.wikipedia.org/wiki/IEEE_floating_point

Last edited:
Mark Harder
Gold Member
Mathematica does rational arithmetic, so it gets it exact: Sum[1/10,{i,10} ] = 1
;-)

Mathematica does rational arithmetic, so it gets it exact: Sum[1/10,{i,10} ] = 1
;-)
Mathematica is written in Wolfram Language, C/C++ and Java.
As the link states, Wolfram only deals with symbolic computation, functional programming, and rule-based programming. So arithmetic and other computational math problem solvers are computed and handled in C or C++, whose main aim is also to boost the software performance.

PHP:
float a = 1.0 / 10;
float sum = 0;
for (int i = 0; i < 10; i++)
{
sum += a;
}
std::cout << sum << std::endl;//Output 1

D H
Staff Emeritus
Until now, nothing I could find in the C and C++ standard libraries can do correct computation with floats. I don't understand why the committee have done nothing about this even though there are already external libraries to do this, some of which are for free online.
What, exactly, do you mean by "correct computation with floats"?

Strictly speaking, no computer can ever do correct computations with the reals. The number of things a Turing machine (which has infinite memory) can do is limited by various theories of computation. On the other hand, almost all of the real numbers are not computable. The best that can be done with a Turing machine is to represent the computable numbers. The best that can be done with a realistic computer (which has finite memory and a finite amount of time in which to perform computations) is to represent a finite subset of the computable numbers.

As for why the C and C++ committees haven't made an arbitrary precision this part of the standard,
YAGNI: You Ain't Gonna Need It.

Silicon Waffle
vela
Staff Emeritus
Homework Helper
Mathematica is written in Wolfram Language, C/C++ and Java.
Mathematica is an implementation of the Wolfram Language. It's not written in the language it implements.

Depending on how you enter an expression, Mathematica may use machine representation of numbers. For example, if you enter Sum[0.1, {i, 1, 10}] - 1 into Mathematica, you'll get ##-1.11022\times10^{-16}##, but if you enter the sum the way Mark did, Sum[1/10, {i, 1, 10}] - 1, the result will be 0.

Mathematica is an implementation of the Wolfram Language. It's not written in the language it implements.

Depending on how you enter an expression, Mathematica may use machine representation of numbers. For example, if you enter Sum[0.1, {i, 1, 10}] - 1 into Mathematica, you'll get ##-1.11022\times10^{-16}##, but if you enter the sum the way Mark did, Sum[1/10, {i, 1, 10}] - 1, the result will be 0.
I assume the symbols you enter e.g "Sum[...]" is manipulated by Wolfram which will call its already implemented methods done in C/C++ to compute the "sum" as requested. The result will be sent back to Wolfram to be displayed as an output.

I assume the symbols you enter e.g "Sum[...]" is manipulated by Wolfram which will call its already implemented methods done in C/C++ to compute the "sum" as requested. The result will be sent back to Wolfram to be displayed as an output.
That wouldn't necessarily imply that the C/C++ code is using primitive floating point types. I don't know about Wolfram, but I think a good Math package would allow you to choose.

rcgldr
Homework Helper
Early computers used BCD (binary coded decimal), including the first digital computer, the Eniac. IBM 1400 series were also decimal based. IBM mainframes since the 360 include support for variable length fixed point BCD, and variable length BCD (packed or unpacked) is a native type in COBOL. Intel processors have just enough support for BCD instructions to allow programs to work with variable length BCD fields (the software would have to take care of fixed point issues).

As for binary floating point compares, APL (A Programming Language), created in the 1960's, has a program adjustable "fuzz" variable used to set the compare tolerance for floating point "equal".

There are fractional libraries that represent rational numbers as integer fractions, maintaining separate values for the numerator and denominator . Some calculators include fractional support. Finding common divisors to reduce the fractions after an operation is probably done using Euclid algorithm, so this type of math is significantly slower.

Last edited:
Possibly it can, I am trying to figure out just what your question is about. If it is a PC( maybe a MAC also) then click the START button in the lower left, then ALL PROGRAMS, next ACCESSORIES and there should be a "Calculator" choice. Within it a choice probably called VIEW will show several different models of hand calculators that you click thru to run.

Mentor
Possibly it can, I am trying to figure out just what your question is about. If it is a PC( maybe a MAC also) then click the START button in the lower left, then ALL PROGRAMS, next ACCESSORIES and there should be a "Calculator" choice. Within it a choice probably called VIEW will show several different models of hand calculators that you click thru to run.
You missed the point of my article, which is this -- if you write a program in one of many programming languages (such as C or its derivative languages, or Fortran, or whatever) to do some simple arithmetic, you are likely to get an answer that is a little off. It doesn't matter whether you use a PC or a Mac. The article discusses why this happens, based on the way that floating point numbers are stored in the computer's memory.

Silicon Waffle


text:
# System of partial DE's

1. Apr 23, 2013

### menco

1. The problem statement, all variables and given/known data

Solve the following system of partial differential equations for u(x,y)

2. Relevant equations

$$du/dy = 2xyu$$

$$du/dx = (y^2 + 5)u$$

3. The attempt at a solution

I am honestly not sure where to start, my lectures and tutorials this week have not been helpful at all. My guess is to take the derivative of the first equation and sub that into the second equation for y and then take the derivative of the second equation to get my final answer. But I am probably completely wrong. Any help or advice would be appreciated!

Last edited: Apr 23, 2013
2. Apr 23, 2013

### ehild

You can show that d(ln(u))=(y2+5)dx+2xy dy is an exact differential.

ehild

3. Apr 25, 2013

### ehild

Try to integrate both equations keeping the other variable as parameter, and include it also into the integration constant. You get the solutions in the form u(xy)=F(x,y) +f(x), u(xy)=G(x,y)+g(x). The two functions must be identical: you find the relation between f and g from this requirement.

ehild


text:
# Using Ruby Blocks And Rolling Your Own Iterators

I recently covered Ruby block basics in my post, More Advanced Ruby Method Arguments – Hashes And Block Basics. I mentioned that blocks are not really method arguments and also covered the two different types of block syntax. Towards the end of that post I promised to examine Ruby blocks more deeply and I am going to try and do that here.

In my opinion there are several interesting things about blocks:

• is there any other difference between the two different types of block syntax besides the fact that one is predominantly used for single line blocks and the other for multi-line?
• in what context are blocks normally used and how does it look from the perspective of the methods that take blocks as ‘parameters’?
• is passing parameters to blocks similar to passing parameters to a method (i.e. is the syntax just as rich, can you have default values etc.) and what scope do those parameters have?
• can a block be a first class parameter and can you pass it around easily as opposed to just using it as a quasi-parameter like we normally do?

Examining each one of those in turn can give one a reasonably solid understanding of blocks, so that’s what we’re gonna do.

### The Two Different Block Notations

As we know there are two different types of block syntax, the curly brace syntax e.g.:

[1,2,3,4,5].each {|i| print "#{i} "}

and the do..end syntax e.g.:

[1,2,3,4,5].each do |i|
print "#{i} "
end

Aside from looking different and being used for single or multi-line blocks, there is one major difference between the two types of syntax – precedence. As we know all expressions in Ruby return a value, this is no different when we execute an iterator. So if we want to use a value that is returned by an iterator that takes a block (e.g. print it out) we can normally do so. When we use curly brace notation this is not a problem e.g.:

print [1,2,3,4,5].each {|i| i}

this will print out:

12345

as we would expect. But if we try to do the same with the do..end syntax e.g.:

print [1,2,3,4,5].each do |i| i end

we get the following error:

each': no block given (LocalJumpError)

this is due to the fact that the method call to print has higher precedence over the do..end block syntax so that what we actually have happening is the following:

print([1,2,3,4,5].each) do |i| i end

to get this to work correctly we need to wrap the whole thing in braces e.g.:

print([1,2,3,4,5].each do |i|
i
end)

It is not a major difference but something to be aware of.

### Learn About Blocks By Implementing Our Own Iterator

The best way I have found to learn how blocks and iterators work together is to implement some of your own starting with a really simple case. Lets implement an infinite loop iterator of our own:

def infinite_loop
while true
yield
end
end

We can call it in the following way, notice that we pass a simple block:

infinite_loop {puts 'Looping Infinitely'}

this will print out ‘Looping Infinitely’ forever since the loop inside out iterator method has no exit condition and just keeps yielding to the block. So far so easy, so lets move on to something more complex. Let’s say we need to add another iterator to the array class that can work with the array elements in reverse (I am aware that Array has a method to reverse itself). We could do this by opening up the Array class and putting our new iterator in:

class Array
def reverse_iterate
current_index = self.size-1
while current_index >= 0
yield self[current_index]
current_index -= 1
end
end
end

We now have an exit condition for the loop in our iterator which means we won’t yield to the block more times than there are values in the array. We can then call our new iterator method in the following fashion:

[2,4,6,8].reverse_iterate { |i| print "#{i} "}

This is all pretty simple, a couple of things to note, the call to yield inside out new method, this is what causes the method to accept a block in the first place. The second thing is the parameter we pass to the yield method. By passing one parameter to yield we cause the block that the iterator takes to also take one parameter. If we passed two values to yield then our block would need to take two parameters as well. So, the above prints out the array because we yield each of the array values to the block (in reverse order) and just output it:

8 6 4 2

But what if we want our new method to not only take a block but also have some sort of default behavior when no block is provided? This is fairly simple to do, we just need to use the Kernel.block_given? method:

class Array
def reverse_iterate
if block_given?
current_index = self.size-1
while current_index >= 0
yield self[current_index]
current_index -= 1
end
else
print self.reverse
end
end
end

we can now call our iterator with no block at all:

[2,4,6,8].reverse_iterate

Our default behavior just prints out all the array values in reverse, concatenated together:

8642

The last thing to note is the fact that yield can actually return a value from the block back to the iterator. The value yield returns is the result of the last expression executed in the block. We can take advantage of this to, for example, collect the values that the block returns on every iteration and return a new array with all the new values as the result of the iterator method call, e.g.:

class Array
def reverse_iterate
if block_given?
new_array=[]
current_index = self.size-1
while current_index >= 0
new_array << yield(self[current_index])
current_index -= 1
end
else
print self.reverse
end
new_array
end
end

If we then call out iterator method with a block that squares all the values it receives:

puts [2,4,6,8].reverse_iterate { |i| i*i}

the result returned from the method call will be an array with the values of our original array but reversed and squared. We can print this out:

64
36
16
4

This can be pretty handy and is incidentally similar to how the more complex Ruby iterator methods (such as map) work.

### Block Parameters

Using block parameters is very similar to using method parameters, the rules are pretty much identical. If you're using Ruby 1.9 you've got all the features like default arguments and optional arguments which you can mix and match pretty much any way you like. If you're on Ruby 1.8, you can still have optional and default arguments but you're a little more limited in how you can mix and match them. So to give an example, you could create an iterator that yields 4 parameters to the block in the following way:

class Array
def reverse_iterate
current_index = self.size-1
while current_index >= 0
yield self[current_index], 'Value', current_index, 'Index'
current_index -= 1
end
end
end

You can then call this iterator with a block but rather than using 4 parameters, you can use two with the second being a catch-all (remember the * notation):

[2,4,6,8].reverse_iterate do |value, *others|
puts "#{others[0]} = #{value}, #{others[2]} = #{others[1]}"
end

You use the values from the catch-all parameter just like you would an array, so our iterator call would output:

Value = 8, Index = 3
Value = 6, Index = 2
Value = 4, Index = 1
Value = 2, Index = 0

Fairly straight forward. What is more interesting is the scope that variables have once we are inside the block. In the simplest case we may call an iterator with a block from another method, which may already have some variables defined:

def some_crazy_method
random_variable=5
[1,2,3].each do |i|
puts "Array value=#{i}, Random variable=#{random_variable}"
end
end

It is curious that in this case we actually have access to these variables from within the block. Calling the above method prints out the following:

Array value=1, Random variable=5
Array value=2, Random variable=5
Array value=3, Random variable=5

As you can see we are able to print out random_variable from within the block and it is set to the same value as it was outside the block. But, what happens when we have a variable outside the block and use a variable with the same name as a block parameter e.g.:

def some_crazy_method
i=5
puts "Before block i=#{i}"

[1,2,3].each do |i|
puts "In block i=#{i}"
end

puts "After block i=#{i}"
end

The behavior here depends on whether you're using Ruby 1.8 or 1.9. With Ruby 1.8 it is still the same variable as the one defined outside the scope of the block, so if we assign a new value to that variable within the block this value will be available outside of the block. So calling the above method in Ruby 1.8 would produce:

Before block i=5
In block i=1
In block i=2
In block i=3
After block i=3

Notice that i now retains the last value it had within the block. In Ruby 1.9 however, the variable within the block is not the same as the one outside of the block so the output in 1.9 would be:

Before block i=5
In block i=1
In block i=2
In block i=3
After block i=5

As you can see the variable retains it's old value after the block completes. Ruby 1.9 also provides another feature to do with variable scope. If you want to pass a variable to the block that is not automatically assigned to, but you don't want to accidentally pass in a variable which has already been initialized (prior to the block and is therefore in scope within the block) you can do the following:

def some_crazy_method
some_variable=5

puts "Before block some_variable=#{some_variable}"

[1,2,3].each do |i;some_variable|
puts "In block i=#{i}"
some_variable = i
end

puts "After block some_variable=#{some_variable}"
end

By passing a variable to the block after the semicolon, we essentially say that we want to have a variable with that name local to the block and unrelated to a variable with the same name outside the block e.g.:

Before block some_variable=5
In block i=1
In block i=2
In block i=3
After block some_variable=5

This seems to be of limited utility and is not available in Ruby 1.8 (it will produce a compilation error).

### Block As Closures

That's right, you can use a block as a closure and pass it around and call it whenever you like. It is a reasonably advanced feature, but essentially you can do the following:

def method_with_block_as_closure(&block)
another_method block
end

def another_method(variable)
x=25
variable.call x
end

method_with_block_as_closure {|i| print "I am happy block #{i}"}

By prepending the method parameter with the & symbol you tell the method to treat the block it gets as a closure and assign it to that parameter. We can then pass this parameter around to other methods just like we would any other. When we actually want to call the block we simply need to use the call method on the variable that currently contains the block, passing in any parameters that the block expects. In our case the result of the above code would be to execute the print method that was called inside the block e.g.:

I am happy block 25`

This is a very basic, surface view of how to use blocks as first class parameters (closures). At this stage, this is really all we need to know, but I do plan to dig more deeply into how and why this works in a later post (i.e. Procs etc.). If you're interested in that, then make sure you grab my feed so you don't miss it. That's all I wanted to cover regarding blocks, hope you found it interesting.

Image by Holger Zscheyge

• http:[email protected] Mark Wilden

“to get this to work correctly we need to wrap the whole thing in braces” should be “parentheses”. But good explanation – I’ll never forget the difference between {} and do/end again.

• http://www.skorks.com Alan Skorkin

I always get those two mixed up :). It’s usually ok since most people can contextually get what you mean, but it does sometimes make for a confusing few minutes of conversation :).

• dan

Um. Squared, not doubled, Right?

If we then call out iterator method with a block that doubles all the values it receives:

puts [2,4,6,8].reverse_iterate { |i| i*i}
the result returned from the method call will be an array with the values of our original array but reversed and doubled. We can print this out:

64
36
16
4

• http://www.skorks.com Alan Skorkin

Oops, yeah you’re of course correct, it should be squares, nice pick-up. Thanks for letting me know, I will update.

• dan

“By passing a variable to the block after the semicolon, we essentially say that we want to have a variable with that name local to the block and unrelated to a variable with the same name outside the block e.g.:”

Isn’t this the standard 1.9 behaviour (with either a comma or a semi-colon)?

• http://www.skorks.com Alan Skorkin

The distinction is pretty fine and as I said the semicolon feature seems to be pretty useless, so perhaps my example was a little unclear about this one.

Here is the way I think about it. A block can have arguments, when you call an iterator and give it a block, the iterator will automatically assign values to these arguments. The block also has access to variables in the scope it was defined without having to pass them in that don’t conflict in name with the block arguments (in 1.9). So, if you’re using a coma you would be expecting the iterator to assign some values to the arguments that you pass in.

When you use the semicolon, you’re essentially creating a variable with block scope. It will not be automatically assigned to and it will not have a value set even if it has the same name as a variable in scope when the block was defined. So, you will essentially be shadowing a variable with the same name that is already in scope or creating a whole new variable with block scope.

The only place that I can see where this is useful would be if you coded an iterator that expects a block with a certain number of parameters and you want to pass in more parameters (that you would like to use within the block), you could do this with the semicolon, but you could not do this with the coma.

What this really means is if you want to have a variable with a particular name inside the block which is distinct from the variables that the iterator will automatically assign to (i.e. you really like the name ‘foobar’ but you already have a ‘foobar’ variable in scope when you define the block) then you will be able to write the block pass in whatever variables the block already expects and then pass in your ‘foobar’ variable which will shadow the one already in scope and thereby protect it from being modified within your block.

• Pingback: Functional Programming in Ruby | Yellow™ Lab Blog()

• http://blog.mostof.it/ Ochronus

Thanks for the post! I’ve also written an article aboutRuby blocks and closures with code examples.

• http://offirmo.posterous.com/ Offirmo

Man, you’re good !

• Pingback: Procs and lambdas « Adam Jonas()

• yongle

woo, I love this tutorial!!!


text:
# Java Implementation of Sieve of Eratosthenes algorithm

I previously asked about my implementation of the Sieve of Eratosthenes algorithm here.

After looking at all of the feedback, I have reworked the code to make it significantly more efficient. However, I'd like to know whether it can be made more efficient still.

I have tried to follow pesudocode for my implementation, which I have provided below:

Input: an integer n > 1

Let A be an array of Boolean values, indexed by integers 2 to n,
initially all set to true.

for i = 2, 3, 4, ..., not exceeding √n:
if A[i] is true:
for j = i2, i2+i, i2+2i, i2+3i, ..., not exceeding n :
A[j] := false

Output: all i such that A[i] is true.

Pseudocode sourced from here.

My implementation:

import java.util.Arrays;
import java.util.Scanner;
public class sieveOfEratosthenes {
public static void main (String [] args) {
int maxPrime;
try (Scanner sc = new Scanner(System.in);) {
System.out.print("Enter an integer greater than 1: ");
maxPrime = sc.nextInt();
sc.close();
}
long start = System.nanoTime();
boolean [] primeNumbers = new boolean [maxPrime];
int maxNumToTest = (int) (Math.floor(Math.sqrt(maxPrime)));
for(int i = 2; i <= maxNumToTest; i++) {
for (int j = i * i; j < maxPrime; j += i) {
}
}
}
long stop = System.nanoTime();
for(int i = 2; i < primeNumbers.length; i++) {
System.out.print((i) + ", ");
}
}

System.out.println("\nExecution time: " + ((stop - start) / 1e+6) + "ms.");
}
}

I have tested my implementation to find that it is capable of calculating all primes below 10,000,000 in ~110ms on an i5 processor.

My question: Is this as fast as is physically possible in Java, or can I make further improvements?

• FYI, class names in Java start with a capital letter as per convention, so the class should be named SieveOfEratosthenes. – Ingo Bürk Aug 19 '15 at 4:57

• Using vertical spaces (new line) to group related code will help to easier read your code.

• if(primeNumbers[i] == true) the checking with == true is superfluous because the condition of the if is a boolean one, so you can simplify this to if(primeNumbers[i])

- instead of using maxPrime here

    boolean [] primeNumbers = new boolean [maxPrime];

you should take advantage of the computed int maxNumToTest like you did in the first loop. You should also add this computed value as the end of the inner loop and the result loop like so

    int maxNumToTest = (int) (Math.floor(Math.sqrt(maxPrime)));
boolean [] primeNumbers = new boolean [maxNumToTest];

for(int i = 2; i <= maxNumToTest; i++) {
for (int j = i * i; j <= maxNumToTest; j += i) {
}
}
}
long stop = System.nanoTime();
for(int i = 2; i <= maxNumToTest; i++) {
System.out.print((i) + ", ");
}
}

- putting everything int main() should be avoided. The current code could be divided into 3 methods:

• computing the primes
• writing the output

In this way each method has a single responsibility and is easier to read and to maintain.

• Thank you, I have worked to improve the organisation of my code (you can see the new code here: dropbox.com/s/wvruqag29lyhwej/sieveOfEratosthenes.java?dl=0) although, I am not sure what you mean about taking advantage of maxNumToTest as placing it in other loops will cause it to print the wrong output? – James Aug 18 '15 at 13:57
• I have updated my answer but be aware I didn't test this. – Heslacher Aug 18 '15 at 14:02
• I see what you have tried, although I have tried implementing this in my code and it does not give the correct output! If we look at an example, if we inputted 10, the maxNumToTest would be 3, so if, in our inner loop we only tested upto maxNumToTest, we would never have tested 4, 5, 6, ..., 10. Likewise, in the output loop, some of the numbers above 3 are also prime, and would not be printed! – James Aug 18 '15 at 14:06
• striked through – Heslacher Aug 18 '15 at 14:08

# Skip even numbers

If you do 2 as a special case, you can skip all even numbers later on. This helps in 2 places:

1. You can only check odd numbers for primes.
2. After you find a prime number and you are doing the sieve, you can increment by 2*i instead of just i.

Here is what your code would look like:

    int maxNumToTest = (int) (Math.floor(Math.sqrt(maxPrime)));
// Special case for prime number 2:
for(int i = 4; i < maxPrime; i += 2) {
}
// Now the normal case can skip all even numbers.
for(int i = 3; i <= maxNumToTest; i += 2) {
int increment = i+i;
for (int j = i * i; j < maxPrime; j += increment) {
}
}
}

I tested this change and it was faster than the original code by 20-25%.

# Memory usage

I extended your program to search for larger and larger prime numbers but at a certain point I ran out of memory. Currently, your program is using 1 byte per number. One thing you could do to use less memory would be to allocate half the number of booleans (only for the odd numbers). For even lower memory usage, you could use 1 bit per odd number. These changes would reduce your memory usage by 16x, and could potentially speed things up.

Here is an example of using 1 bit per odd number:

    // Each bit is an odd number.  Bit 0 = 1, bit 1 = 3, bit 2 = 5, etc.
int [] primeNumbers = new int[(maxPrime+63)/64 + 1];
// Clear the bit for any number >= maxPrime:
int lastNumber = primeNumbers.length * 64 - 1;
for (int i = maxPrime; i < lastNumber; i++) {
int iIndex = i >> 6;
int iBit   = (1 << ((i >> 1) & 31));
}
// 1 is not a prime.
int maxNumToTest = (int) (Math.floor(Math.sqrt(maxPrime)));
for(int i = 3; i <= maxNumToTest; i += 2) {
int iIndex = i >> 6;
int iBit   = (1 << ((i >> 1) & 31));
if ((primeNumbers[iIndex] & iBit) != 0) {
int increment = i+i;
for (int j = i * i; j < maxPrime; j += increment) {
int jIndex = j >> 6;
int jBit   = (1 << ((j >> 1) & 31));
}
}
}
long stop = System.nanoTime();
System.out.print("2, ");
for(int i = 3; i < maxPrime; i+=2) {
int iIndex = i >> 6;
int iBit   = (1 << ((i >> 1) & 31));
if((primeNumbers[iIndex] & iBit) != 0) {
System.out.print((i) + ", ");
}
}

On my machine, this appears to run faster than using an array of booleans. But you should test it yourself because the size of your cache matters a lot when doing this.

• I agree with your first comment about skipping even numbers, although, in terms of the trade off between memory useage and efficency, would the impact overall on time taken outweight the benifits of using less memory? – James Aug 18 '15 at 19:56
• @JamesZafar I updated my answer to give an example using 1 bit per odd number. You should try it out and see if it is faster on your machine. – JS1 Aug 18 '15 at 20:46
• You should use BitSet for this. Then you don't have to calculate everything and the code could be cleaner. – Obenland Aug 19 '15 at 17:57
• @Xean I tried a BitSet just now but it was 3x slower than using the array of int. – JS1 Aug 19 '15 at 18:09
• @JS1 this is strange. A BitSet is doing the same with an array of long. No much extra stuff. Did you use the right constructor to set the length, so it doesn't have to expand? – Obenland Aug 19 '15 at 18:15