text:
# User:Michiexile/MATH198/Lecture 7

(Difference between revisions)
 Revision as of 21:13, 2 November 2009 (edit)← Previous diff Current revision (19:16, 4 November 2009) (edit) (undo) (7 intermediate revisions not shown.) Line 1: Line 1: - IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ. - Last week we saw what an adjunction was. Here's one thing we can do Last week we saw what an adjunction was. Here's one thing we can do with adjunctions. with adjunctions. Line 6: Line 4: Now, let $U$ be a left adjoint to $F$. We set $T = UF$. Then we have natural transformations Now, let $U$ be a left adjoint to $F$. We set $T = UF$. Then we have natural transformations - $\mu: UFUF -> UF$ + :$\mu: UFUF -> UF$ - $\mu_X = U \epsilon_{FX}$ + :$\mu_X = U \epsilon_{FX}$ - $\iota: 1 -> UF$ + :$\iota: 1 -> UF$ - $\iota_X = \eta_X$ + :$\iota_X = \eta_X$ such that $\mu$ is associative and $\iota$ is the unit of $\mu$. such that $\mu$ is associative and $\iota$ is the unit of $\mu$. Line 18: Line 16: ===Algebraic objects in categories=== ===Algebraic objects in categories=== - \$THEORY objects in Categories. + We recall the definition of a monoid: - Now, we call something a monad in a category if it is a monoid object + '''Definition''' A ''monoid'' is a set $M$ equipped with an operation $\mu: M\times M\to M$ that we call ''composition'' and an operation $e: 1\to M$ that we call the identity, such that - in the category of endofunctors of that category. + * $M \circ 1_M \times M = M \circ M \times 1_M$ (associativity) + * $M \circ 1_M \times e = M \circ e\times 1_M = 1_M$ (unity) + + If we have a ''monoidal category'' - a category $C$ with a bifunctor $\otimes: C\times C\to C$ called the ''tensor product'' which is associative (up to natural isomorphisms) and has an object $I$ acting as a unit (up to natural isomorphisms) for the tensor product. + + The product in a category certainly works as a tensor product, with a terminal object acting as a unit. However, there is often reason to have a non-commutative tensor product for the monoidal structure of a category. This makes the category a ''cartesian monoidal category''. + + For, say, abelian groups, or for vector spaces, we have the ''tensor product'' forming a non-cartesian monoidal category structure. And it is important that we do. + + And for the category of endofunctors on a category, we have a monoidal structure induced by composition of endofunctors: $F\otimes G = F\circ G$. The unit is the identity functor. + + Now, we can move the definition of a monoid out of the category of sets, and define a generic ''monoid object'' in a monoidal category: + + '''Definition''' A ''monoid object'' in a monoidal category $C$ is an object $M$ equipped with morphisms $\mu: M\otimes M\to M$ and $e: 1\to M$ such that + * $M \circ 1_M \otimes M = M \circ M\otimes 1_M$ (associativity) + * $M \circ 1_M \otimes e = M \circ e\otimes 1_M = 1_M$ (unity) + + As an example, a monoid object in the cartesian monoidal category $Set$ is just a monoid. A monoid object in the category of abelian groups is a ring. + + A monoid object in the category of abelian groups, with the tensor product for the monoidal structure is a ''ring''. + + And the composition $UF$ for an adjoint pair is a monoid object in the category of endofunctors on the category. + + The same kind of construction can be made translating familiar algebraic definitions into categorical constructions with many different groups of definitions. For ''groups'', the corresponding definition introduces a diagonal map $\Delta: G\to G\times G$, and an inversion map $i: M\to M$ to codify the entire definition. + + One framework that formalizes the whole thing, in such a way that the definitions themselves form a category is the theory of Sketches by Charles Wells. In one formulation we get the following definition: + + '''Definition''' A ''sketch'' $S = (G, D, L, K)$ consists of a graph $G$, a set of diagrams $D$, a set $L$ of cones in $G$ and a set $K$ of cocones in $G$. + + A ''model'' of a sketch ''S'' in a category $C$ is a graph homomorphism $G\to C$ such that the image of each diagram in $D$ is commutative, each of the cones is a limit cone and each of the cocones is a colimit cocone. + + A ''homomorphism of models'' is just a natural transformation between the models. ---- ---- - We thus define a ''monad in a category $C$'' to be a monoid in that category. + We thus define a ''monad in a category $C$'' to be a monoid object in the category of endofunctors on that category. + + Specifically, this means: + + '''Definition''' A ''monad'' in a category $C$ is an endofunctor $T: C\to C$ equipped with natural transformations $\mu: T^2\to T$ and $\eta: 1\to T$ such that the following diagrams commute: + + [[Image:MonadAssociative.png]] + [[Image:MonadUnit.png]] - Thus: a monad with this definition in Haskell is: + We can take this definition and write it out in Haskell code, as: - * a type of kind m :: * -> *. + - * equipped with functions + - ** return :: a -> m a + - ** join :: m m a -> m a + - * examples: + - List: + class Functor m => MathematicalMonad m where - return x = [x] + return :: a -> m a - join (l:lsts) = l ++ join lsts + join :: m (m a) -> m a - Maybe: + -- such that - return x = Just x + join . fmap return = id :: m a -> m a - join (Just (Just x)) = Just x + join . return = id :: m a -> m a - join _ = Nothing + join . join = join . fmap join :: m (m (m a)) -> m a - Note: not quite what Haskell claims a monad to be. Other related + Those of you used to Haskell will notice that this is not the same as the Monad typeclass. That type class calls for a natural transformation (>>=) :: m a -> (a -> m b) -> m b (or bind). - concepts: + - * Kleisli category & factorization of monads: if we start with T a + The secret of the connection between the two lies in the Kleisli category, and a way to build adjunctions out of monads as well as monads out of adjunctions. - monad, then can we find an adjunction U -| F to _somewhere_ such + - that T = UF? And the monoidal structure is given by U e_FX and + - eta_X? + - * From the Kleisli Category to monadic bind. + ===Kleisli category=== - * Monads and sequencing. + We know that an adjoint pair will give us a monad. But what about getting an adjoint pair out of a monad? Can we reverse the process that got us the monad in the first place? + There are several different ways to do this. Awodey uses the ''Eilenberg-Moore category'' which has as objects the ''algebras of the monad $T$'': morphisms $h: Tx \to x$. A morphism $f: (\alpha: TA\to A)\to (\beta: TB\to B)$ is just some morphism $f:A\to B$ in the category $C$ such that $f\circ\alpha = \beta\circ T(f)$. + We require of $T$-algebras two additional conditions: + * $1_A = h\circ\eta_A$ (unity) + * $h\circ\mu_A = h \circ Th$ (associativity) + There is a forgetful functor that takes some $h$ to $t(h)$, picking up the object of the $T$-algebra. Thus $U(h:TA\to A) = A$, and $U(f) = f$. + We shall construct a left adjoint $F$ to this from the data of the monad $T$ by setting $FC = (\mu_C: T^2C\to TC)$, making $TC$ the corresponding object. And plugging the corresponding data into the equations, we get: + * $1_{TC} = \mu_C\circ\eta_{TC}$ + * $\mu_C\circ\mu_{TC} = \mu_C\circ T\mu_C$ + which we recognize as the axioms of unity and associativity for the monad. + [[Image:MonadAssociative.png]] + [[Image:MonadUnit.png]] + By working through the details of proving this to be an adjunction, and examining the resulting composition, it becomes clear that this is in fact the original monad $T$. However - while the Eilenberg-Moore construction is highly enlightening for constructing formal systems for algebraic theories, and even for the fixpoint definitions of data types, it is less enlightening to understand Haskell's monad definition. + To get to terms with the Haskell approach, we instead look to a different construction aiming to fulfill the same aim: the ''Kleisli category'': + Given a monad $T$ over a category $C$, equipped with unit $\eta$ and concatenation $\mu$, we shall construct a new category $K(T)$, and an adjoint pair of functors $U,F$ factorizing the monad into $T=UF$. + We first define $K(T)_0 = C_0$, keeping the objects from the original category. + Then, we set $K(T)_1$ to be the collection of arrows, in $C$, on the form $A\to TB$. + The composition of $f: A\to TB$ with $g: B\to TC$ is given by the sequence + $A\to^f TB\to^{Tg} T^2C\to^{\mu_C} TC$ + The identity is the arrow $\eta_A: A\to TA$. The identity property follows directly from the unity axiom for the monad, since $\eta_A$ composing with $\mu_A$ is the identity. + Given this category, we next define the functors: + * $U(A) = TA$ + * $U(f: A\to TB) = TA\to^{Tf} T^2B\to^{\mu_B} TB$ + * $F(A) = A$ + * $F(g: A\to B) = A\to^{\eta_A} TA\to^{Tg} TB$ + This definition makes $U, F$ an adjoint pair. Furthermore, we get + * $UF(A) = U(A) = TA$ + * $UF(g: A\to B) = U(Tg\circ\eta_A) = \mu_B\circ T(Tg\circ\eta_A)$ + : $=\mu_B\circ T^2g \circ T\eta_A$, and by naturality of $\mu$, we can rewrite this as + : $=Tg \circ \mu_A\circ T\eta_A = Tg\circ 1_{TA} = Tg$ by unitality of $\eta$. + We've really just chased through this commutative diagram: + :[[Image:KleisliFactorizationDiagram.png]] + Hence, the composite $UF$ really is just the original monad functor $T$. + But what's the big deal with this? you may ask. The big deal is that we now have a monad specification with a different signature. Indeed, the Kleisli arrow for an arrow f :: a -> b and a monad Monad m is something on the shape fk :: a -> m b. And the Kleisli factorization tells us that the Haskell monad specification and the Haskell monad laws are equivalent to their categorical counterparts. + And the composition of Kleisli arrows is easy to write in Haskell: + + f :: a -> m b + g :: b -> m c + (>>=) :: m a -> (a -> m b) -> m b -- Monadic bind, the Haskell definition + kleisliCompose f g :: a -> m c + kleisliCompose f g = (>>= g) . f + - ===Some adjunctions we already know=== + ===Examples=== - * initial/terminal are adjunctions. + Some monads in Haskell are: - * (co)-products are adjunctions. + - * Actually, all (co)limits are adjunctions. + + ====The List monad==== + Lists form a monad, with the following (redundant) definition: + + instance Monad [] where + return x = [x] - ===Some adjunctions we don't know yet=== + [] >>= _ = [] + (x:xs) >>= f = f x : xs >>= f - * Existential and universal qualifiers as adjunctions. + join [] = [] - * Powersets and im(f) -| f^\inv + join (l:ls) = l ++ join ls + - ===Properties of adjoints=== + As it turns out, the lists monad can be found by considering the free and forgetful functors between sets and monoids. Indeed, the lists are what we get from the Kleene star operation, which is the monad we acquire by composing the free monoid functor with the forgetful functor. + + ====Error handling==== + + We can put a monadic structure on a coproduct $A+B$ so that the monadic bind operation performs computations $A+B\to A'+B$ until some computation fails, returning an error, typed $B$, after which we bypass any further computations, just carrying the error out of the entire computation. + + The endofunctor here is $+B$. So the monad is given from a way to go from $A+B+B\to A+B$. Doing this is easy: in Haskell terms, we just remove the constructor differences between the two copies of $B$ floating around. Mathematically, this is just using the functoriality of the coproduct construction on the inclusion maps into $A+B$. + + For our example, we shall return the first value of $B$ to ever occur, thus making our join operator look like this: + + join :: (Either b (Either b a)) -> Either b a + join (Left y) = Left y + join (Right (Left y)) = Left y + join (Right (Right x)) = Right x + + + This gives us a Haskell monad defined by: + + instance Monad (Either b) where + return x = Right x + + Left y >>= _ = Left y + Right x >>= f = f x + - ====RAPL: Right Adjoints Preserve Limits==== - ====Recognizing adjoints==== + ===Additional reading=== - '''Theorem''' (Freyd: The Adjoint Functor Theorem) + * http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html (one of the least dramatic monads tutorials out there) + * http://www.disi.unige.it/person/MoggiE/ftp/lc88.ps.gz (Moggi: ''Computational lambda-calculus and monads'', one of the papers that started the interest in monads. Logic, dense reading.) + * http://www.haskell.org/haskellwiki/Research_papers/Monads_and_arrows (good catalogue over further reading on monads) + ===Homework=== - ===Why should we care in CS?=== + Full marks will be given for 4 out of the 7 questions. - ====Monads==== + # Prove that the Kleisli category adjunction is an adjunction. + # Prove that the Eilenberg-Moore category adjunction is an adjunction. + # Given monad structures on $S$ and $T$, + # The ''writer'' monad W is defined by + #* data Monoid m => W m x = W (x, m) + #* fmap f (W (x, m)) = W (f x, m) + #* return x = W (x, mempty) + #* join (W (W (x, m), n)) = W (x, m mappend n) + ## (2pt) Prove that this yields a monad. + ## (2pt) Give the Kleisli factorization of the writer monad. + ## (2pt) Give the Eilenberg-Moore factorization of the writer monad. + ## (2pt) Is there a nice, 'natural' adjunction factorizing the writer monad?

## Current revision

Last week we saw what an adjunction was. Here's one thing we can do with adjunctions.

Now, let U be a left adjoint to F. We set T = UF. Then we have natural transformations

μ:UFUF − > UF
μX = UεFX
ι:1 − > UF
ιX = ηX

such that μ is associative and ι is the unit of μ.

These requirements remind us of the definition of a monoid - and this is not that much of a surprise. To see the exact connection, and to garner a wider spread of definitions.

## Contents

### 1 Algebraic objects in categories

We recall the definition of a monoid:

Definition A monoid is a set M equipped with an operation $\mu: M\times M\to M$ that we call composition and an operation $e: 1\to M$ that we call the identity, such that

• $M \circ 1_M \times M = M \circ M \times 1_M$ (associativity)
• $M \circ 1_M \times e = M \circ e\times 1_M = 1_M$ (unity)

If we have a monoidal category - a category C with a bifunctor $\otimes: C\times C\to C$ called the tensor product which is associative (up to natural isomorphisms) and has an object I acting as a unit (up to natural isomorphisms) for the tensor product.

The product in a category certainly works as a tensor product, with a terminal object acting as a unit. However, there is often reason to have a non-commutative tensor product for the monoidal structure of a category. This makes the category a cartesian monoidal category.

For, say, abelian groups, or for vector spaces, we have the tensor product forming a non-cartesian monoidal category structure. And it is important that we do.

And for the category of endofunctors on a category, we have a monoidal structure induced by composition of endofunctors: $F\otimes G = F\circ G$. The unit is the identity functor.

Now, we can move the definition of a monoid out of the category of sets, and define a generic monoid object in a monoidal category:

Definition A monoid object in a monoidal category C is an object M equipped with morphisms $\mu: M\otimes M\to M$ and $e: 1\to M$ such that

• $M \circ 1_M \otimes M = M \circ M\otimes 1_M$ (associativity)
• $M \circ 1_M \otimes e = M \circ e\otimes 1_M = 1_M$ (unity)

As an example, a monoid object in the cartesian monoidal category Set is just a monoid. A monoid object in the category of abelian groups is a ring.

A monoid object in the category of abelian groups, with the tensor product for the monoidal structure is a ring.

And the composition UF for an adjoint pair is a monoid object in the category of endofunctors on the category.

The same kind of construction can be made translating familiar algebraic definitions into categorical constructions with many different groups of definitions. For groups, the corresponding definition introduces a diagonal map $\Delta: G\to G\times G$, and an inversion map $i: M\to M$ to codify the entire definition.

One framework that formalizes the whole thing, in such a way that the definitions themselves form a category is the theory of Sketches by Charles Wells. In one formulation we get the following definition:

Definition A sketch S = (G,D,L,K) consists of a graph G, a set of diagrams D, a set L of cones in G and a set K of cocones in G.

A model of a sketch S in a category C is a graph homomorphism $G\to C$ such that the image of each diagram in D is commutative, each of the cones is a limit cone and each of the cocones is a colimit cocone.

A homomorphism of models is just a natural transformation between the models.

We thus define a monad in a category C to be a monoid object in the category of endofunctors on that category.

Specifically, this means:

Definition A monad in a category C is an endofunctor $T: C\to C$ equipped with natural transformations $\mu: T^2\to T$ and $\eta: 1\to T$ such that the following diagrams commute:

We can take this definition and write it out in Haskell code, as:

class Functor m => MathematicalMonad m where
return :: a -> m a
join   :: m (m a) -> m a

-- such that
join . fmap return = id               :: m a -> m a
join . return      = id               :: m a -> m a
join . join        = join . fmap join :: m (m (m a)) -> m a
Those of you used to Haskell will notice that this is not the same as the
typeclass. That type class calls for a natural transformation
(>>=) :: m a -> (a -> m b) -> m b
(or
bind
).

The secret of the connection between the two lies in the Kleisli category, and a way to build adjunctions out of monads as well as monads out of adjunctions.

### 2 Kleisli category

We know that an adjoint pair will give us a monad. But what about getting an adjoint pair out of a monad? Can we reverse the process that got us the monad in the first place?

There are several different ways to do this. Awodey uses the Eilenberg-Moore category which has as objects the algebras of the monad T: morphisms $h: Tx \to x$. A morphism $f: (\alpha: TA\to A)\to (\beta: TB\to B)$ is just some morphism $f:A\to B$ in the category C such that $f\circ\alpha = \beta\circ T(f)$.

We require of T-algebras two additional conditions:

• $1_A = h\circ\eta_A$ (unity)
• $h\circ\mu_A = h \circ Th$ (associativity)

There is a forgetful functor that takes some h to t(h), picking up the object of the T-algebra. Thus $U(h:TA\to A) = A$, and U(f) = f.

We shall construct a left adjoint F to this from the data of the monad T by setting $FC = (\mu_C: T^2C\to TC)$, making TC the corresponding object. And plugging the corresponding data into the equations, we get:

• $1_{TC} = \mu_C\circ\eta_{TC}$
• $\mu_C\circ\mu_{TC} = \mu_C\circ T\mu_C$

which we recognize as the axioms of unity and associativity for the monad.

By working through the details of proving this to be an adjunction, and examining the resulting composition, it becomes clear that this is in fact the original monad T. However - while the Eilenberg-Moore construction is highly enlightening for constructing formal systems for algebraic theories, and even for the fixpoint definitions of data types, it is less enlightening to understand Haskell's monad definition.

To get to terms with the Haskell approach, we instead look to a different construction aiming to fulfill the same aim: the Kleisli category:

Given a monad T over a category C, equipped with unit η and concatenation μ, we shall construct a new category K(T), and an adjoint pair of functors U,F factorizing the monad into T = UF.

We first define K(T)0 = C0, keeping the objects from the original category.

Then, we set K(T)1 to be the collection of arrows, in C, on the form $A\to TB$.

The composition of $f: A\to TB$ with $g: B\to TC$ is given by the sequence $A\to^f TB\to^{Tg} T^2C\to^{\mu_C} TC$

The identity is the arrow $\eta_A: A\to TA$. The identity property follows directly from the unity axiom for the monad, since ηA composing with μA is the identity.

Given this category, we next define the functors:

• U(A) = TA
• $U(f: A\to TB) = TA\to^{Tf} T^2B\to^{\mu_B} TB$
• F(A) = A
• $F(g: A\to B) = A\to^{\eta_A} TA\to^{Tg} TB$

This definition makes U,F an adjoint pair. Furthermore, we get

• UF(A) = U(A) = TA
• $UF(g: A\to B) = U(Tg\circ\eta_A) = \mu_B\circ T(Tg\circ\eta_A)$
$=\mu_B\circ T^2g \circ T\eta_A$, and by naturality of μ, we can rewrite this as
$=Tg \circ \mu_A\circ T\eta_A = Tg\circ 1_{TA} = Tg$ by unitality of η.

We've really just chased through this commutative diagram:

Hence, the composite UF really is just the original monad functor T.

But what's the big deal with this? you may ask. The big deal is that we now have a monad specification with a different signature. Indeed, the Kleisli arrow for an arrow
f :: a -> b
is something on the shape
fk :: a -> m b
. And the Kleisli factorization tells us that the Haskell monad specification and the Haskell monad laws are equivalent to their categorical counterparts.

And the composition of Kleisli arrows is easy to write in Haskell:

f :: a -> m b
g :: b -> m c

(>>=) :: m a -> (a -> m b) -> m b -- Monadic bind, the Haskell definition

kleisliCompose f g :: a -> m c
kleisliCompose f g = (>>= g) . f

### 3 Examples

Lists form a monad, with the following (redundant) definition:

instance Monad [] where
return x     = [x]

[] >>= _     = []
(x:xs) >>= f = f x : xs >>= f

join [] = []
join (l:ls) = l ++ join ls

As it turns out, the lists monad can be found by considering the free and forgetful functors between sets and monoids. Indeed, the lists are what we get from the Kleene star operation, which is the monad we acquire by composing the free monoid functor with the forgetful functor.

#### 3.2 Error handling

We can put a monadic structure on a coproduct A + B so that the monadic bind operation performs computations $A+B\to A'+B$ until some computation fails, returning an error, typed B, after which we bypass any further computations, just carrying the error out of the entire computation.

The endofunctor here is + B. So the monad is given from a way to go from $A+B+B\to A+B$. Doing this is easy: in Haskell terms, we just remove the constructor differences between the two copies of B floating around. Mathematically, this is just using the functoriality of the coproduct construction on the inclusion maps into A + B.

For our example, we shall return the first value of B to ever occur, thus making our join operator look like this:

join :: (Either b (Either b a)) -> Either b a
join (Left y) = Left y
join (Right (Left y)) = Left y
join (Right (Right x)) = Right x

instance Monad (Either b) where
return x = Right x

Left y  >>= _ = Left y
Right x >>= f = f x

### 5 Homework

Full marks will be given for 4 out of the 7 questions.

3. Given monad structures on S and T,
• join (W (W (x, m), n)) = W (x, m mappend n)


text:
# Arithmetic Progressions : Basic Concept, Formula and Problems for class 11

In this post we will study the basic concept of Arithmetic Progression which is relevant for Grade 11 Mathematics syllabus. Apart from the concept we will also study the formulas and solved problems which are important part of CBSE/NCERT syllabus.

## Arithmetic Progression Concept

If the elements are arranged in following sequence:

a, a + d, a + 2d, a + d, a + 4d, a + 5d, . . . . . . . a + (n-1)d

then the sequence is in the form of Arithmetic Progression (AP).

Here,
a is the first term
d is the common difference

In Arithmetic Progression
(a) The difference of consecutive numbers is always same (i.e. d)
(b) this common difference can help us to find other unknown numbers in the series

Example 01
2, 4, 6, 8, 10, 12, . . . . . .

This sequence is in the form of arithmetic progression because:

(a) the common difference between consecutive term is same (d = 2)

(b) The sequence can also be represented in AP form
a, a + d, a + 2d, a + 3d, a + 4d, a + 5d, . . . . . . . a + (n-1)d
2, 2+2, 2 +(2.2), 2+ (3.2), 2+ (4.2), 2+ (5.2) . . . . . . . 2 + (n-1)2

Example 02
7, 14, 21, 28, 35, 42, . . . . . . . . . . . . .

The sequence is in the form of Arithmetic Progression because the difference between consecutive numbers is same

Example 03
4, 0, -4, -8, -12, -16, -20, -24, -28, . . . . . . . . . . . .

The sequence is Arithmetic Progression because common difference between elements is same

## Formula for Arithmetic Progression

1. nth term of Arithmetic Progression

Tn = a + (n – 1) d

Tn = Value of nth term of the AP
a = First Term of AP
d = Common difference of AP

2. Sum to nth term of AP

Sn\ =\ \frac{n}{2} \ [ 2a\ +\ ( n-1) d]

Sn = Sum to nth terms of AP
a = First term of AP
d = common difference

3. Sum to nth term when the last term is given

Sn\ =\ \frac{n}{2} \ [ a+l]

Sn = Sum to nth terms of AP
a = First term of AP
l = last term of AP

4. Arithmetic Mean

Given two numbers a & b, we can calculate the arithmetic mean of numbers using the formula:
A = (a + b)/2
The calculated Arithmetic mean (A) is such that the sequence a, A, b is in Arithmetic Progression

Example
Let there are two number 2 and 10.

Arithmetic Mean = (2 + 10)/2
Arithmetic Mean = 12/2 = 6

Now the sequence 2, 6, 10 forms Arithmetic Progression as they have same common difference.
6 – 2 = 4
10 – 6 = 4
You can see that common difference is 4

## Arithmetic Progression Questions

(01) The income of a person is $3,00,000 in the first year and he receives an increase of$10,000 to his income per year for the next 19 years. Find the total amount, he received in 20 years

Solution
Income First year = 3,00,000
Income Second Year = 3,00,000 +10,000 =3,10,000
Income Third Year = 3,10,000 +10,000 = 3,20,000
Income Fourth Year = 3,20,000 + 10,000 = 3,3000

You can see that the sequence is forming Arithmetic Progression with common difference of 10,000

The sequence is like
300000, 310000, 320000, 330000, 340000, . . . . . . . . . . . . . . . . . . . .

Let us find the amount the person received in 20th year
The 20th term in the above series is:
Tn = a + (n – 1)d
T20 = 300000 + (20-1) * 10,000
T20 = 300000 + 19 * 10,000
T20 = 300000 + 190000
T20 = $4,90,000 The person will receive$4,90,000 in the 20th year

So the sequence becomes
300000, 310000, 320000, 330000, 340000, . . . . . . . . . . . . . . . . . . .490000

Sum of all the amount is calculated using formula:
Sn = n/2 (a + l)

Here,
n= 20
a = 3,00,000
l = 4,90,000

Putting the values
S20 = 20/2 * (3,00,000 + 4,90,000)
S20 = 10 * (7,90,000)
S20 = $79,00,000 Hence the total sum till 20th years is$79,00,000

(02) The 6th and 20th terms of an AP are 8 and −20 respectively. Find the 30th term

Solution
Formula for nth term of AP is:
Tn = a + ( n – 1)d

Using the above formula, 6th Term of AP can be represented as ==> a + 5d
and 20th term can be represented as ==> a+19d

As given in the question:
a + 5d = 8 —– eq (1)
a + 19d = -20 —— eq (2)

Equating eq(2) – eq(1), we get
a + 19d – a – 5d= – 20 – 8
14 d = -28
d = – 2

Putting the value of d in eq(1), we get
a + 5 (-2) = 8
a – 10 = 8
a = 18

Now the 30th term will be
T30 = a + 29 (d)
T30 = 18 + 29 (-2)
T30 = 18 – 58
T30 = – 40

Hence the 30th term is -40

(03) There is an AP 11, 13, 15…. Which term of this AP is 65?

Solution
The following sequence is in Arithmetic Progression
11, 13, 15, 17, 19 . . . . .65 . . . . .

Here
First Term (a) = 11
Common Difference (d) = 13 – 11 = 2

We have to find the term whose value is 65

Using formula
Tn = a + (n – 1)d
65 = 11 + (n – 1)*2
54/2 = n -1
27 = n – 1
n = 28

Hence the 28th term of above AP is 65

format: plain


text:
Browse Questions

# Prove the rule of exponents $(ab)^n=a^nb^n$ by using principle of mathematical induction for every natural number.

Let $P(n)$ be the given statement
i.e., $P(n) : (ab)^n=a^nb^n$
We note that $P(n)$ is true for $n=1$ since $(ab)^1=a^1b^1$.
Let $P(k)$ be true, i.e.,
$\qquad (ab)^k=a^kb^k$----------(1)
We shall now prove that $P(k+1)$ is true whenever $P(k)$ is true.
Now, we have
$\qquad = (ab)^{k+1} =(ab)^k(ab)$
$\qquad = (a^kb^k) (ab)\qquad$ [ by (1) ]
$\qquad = (a^k.a^1) (b^k.b^1)=a^{k+1}.b^{k+1}$
Therefore, $P(k+1)$ is also true whenever $P(k)$ is true. Hence by principle of mathematical induction, $P(n)$ is true for all $n \in N$.


text:
## Algebra 1

$30 ^\circ$
Consider $p$ be the measure of the angle with equal measure for two angles. Thus, $120 ^\circ +p+p=180 ^\circ$ $120 ^\circ +2p=180 ^\circ$ $2p=180 ^\circ-120 ^\circ$ $2p=60^\circ$ $p=30 ^\circ$


text:
# Perfect pixels and anti-aliasing

## Anti-aliasing

The process of converting precise graphic shapes to a grid of pixels is automatically performed by Luxor when you save the drawing as a PNG file. If you make an SVG or PDF drawing, this process is carried out at a later stage, by the application you use to view or display the file.

It's usually better to defer this conversion as long as possible. Of course, eventually - unless you're using a pen plotter or laser cutter - your smooth outlines will have to be converted ("rasterized") to a grid of colored pixels for their final journey to the analogue world.

The conversion to PNG includes "anti-aliasing", which gradually changes the colors of pixels along a boundary so as to avoid the grid-like "staircase" effect. You can, to some extent, adjust the amount of anti-aliasing used when you make drawings in Luxor.

The setantialias function lets you specify the anti-aliasing amount as an integer constant between 0 and 6 to be used for rendering subsequent paths. The Cairo documentation describes the different values as follows:

ValueNameDescription
0CAIRO_ANTIALIAS_DEFAULTUse the default anti-aliasing for the subsystem and target device
1CAIRO_ANTIALIAS_NONEUse a bilevel alpha mask
2CAIRO_ANTIALIAS_GRAYPerform single-color anti-aliasing (using shades of gray for black text on a white background, for example)
3CAIRO_ANTIALIAS_SUBPIXELPerform anti-aliasing by taking advantage of the order of subpixel elements on devices such as LCD panels
4CAIRO_ANTIALIAS_FASTHint that the backend should perform some anti-aliasing but prefer speed over quality
5CAIRO_ANTIALIAS_GOODThe backend should balance quality against performance
6CAIRO_ANTIALIAS_BESTHint that the backend should render at the highest quality, sacrificing speed if necessary

To show the anti-aliasing in action, the following code generates a red circle:

Drawing(20, 20, :image)
setantialias(0)
origin()
setcolor("red")
circle(Point(0, 0), 5, :fill)
mat = image_as_matrix()
finish()

This matrix is now redrawn larger to show the effects of anti-aliasing better. Here's the default anti-aliasing value of 0:

and you can see that Luxor used 18 different shades of red to add some smoothness to this circle.

Here’s the result of the bilevel mask or “none” setting (setantialias(1)):

Here Luxor used just two colors to draw the circle.

The other values produce the same effects as the default (0), apart from 4 ("speed over quality"):

which uses 12 rather than 16 colors.

The anti-aliasing process can vary according to the OS and device you're using. The Cairo documentation stresses this more than once:

The value is a hint, and a particular backend may or may not support a particular value. [...] The values make no guarantee on how the backend will perform its rasterisation (if it even rasterises!) [...] The interpretation of CAIRO_ANTIALIAS_DEFAULT is left entirely up to the backend [...]

## Text

The anti-aliasing described above does not apply to text.

Text rendering is much more platform-dependent than graphics; Windows, MacOS, and Linux all have their own methods for rendering and rasterizing fonts, and currently there is no interface to the underlying font rendering APIs in Luxor.

Consider the following code, which makes an image of the letter "a" and redraws it larger:

using Luxor

function make_matrix()
Drawing(40, 40, :image)
background(1, 1, 1, 1)
setantialias(0)
origin()
setcolor(0, 0, 0, 1)
fontsize(40)
text("a", halign=:center, valign=:middle)
matrix = image_as_matrix()
finish()
return matrix
end

function draw()
matrix = make_matrix()
@png begin
background(0, 0, 0, 1)
table = Table(size(matrix)..., (15, 15))
for i in CartesianIndices(matrix)
r, c = Tuple(i)
setcolor(matrix[r, c])
box(table, r, c, :fillstroke)
end
end 400 400 "alias-test.png"
end

The output varies depending on the computer, operating system, and rendering settings.

Here’s the MacOS standard rendering:

Here’s Linux Gnome’s standard anti-aliasing:

On Windows systems, and on some Linux desktops, text can be displayed using a subpixel rendering process, which switches the red, green, and blue components of pixels on or off where they meet the edges of text in an attempt to provide a “smoother” appearance.

Here’s Linux KDE RGB anti-aliasing:

Windows Cleartype anti-aliasing:

In addition, Windows and some Linux systems use font hinting, a process in which the outlines of text glyphs are shifted so as to align better on the rectangular grid of pixels.

If you want text to be rendered precisely (and in a specified color) it might be worth investigating Luxor’s textoutlines function, which converts text to vector-based outlines. These are then rendered with the anti-aliasing settings described above for graphics.


text:
# generating

1. ### generating functions

How can I continue this problem. my aim is to write a closed form. ( the first line is the original question given, the rest is I have written )
2. ### Problem with generating safe primes

So I'm using the Lucas primality test to generate large primes. The factorization of N-1 is known of course and in this case I'm just using randomized powers 2 and 3. That part works fine and it produces plenty of primes. Now what I really want is "safe primes". Since I've already verified that...
3. ### Joint Moment Generating Function from Conditional and Marginal Distribution

Suppose that that random variable $N$ follows a Poisson distribution with mean $\lambda=6$. Suppose that the conditional distribution of the random variable $X$, given that $N=n$, follows that of a $Binomial(n,0.6)$. Find the Joint Moment Generating Function of $(N, X)$. Initially I just...
4. ### Problems finding the Moment Generating Function

Let the random variable X equal the number of flips of a fair coin that are required to observe heads - tails on consecutive flips. Find the pmf of X and find the moment generating function of X. The PMF is straightforward since there are always two desired outcomes divided by 2^n (where n...
5. ### Moment generating function for a random variable described by a piecewise pdf

Part e) is the problem in question here; I'm not exactly sure how to find the moment generating function, specifically when 1 <= y < 2. I know that M(t) = the integral from -infinity to infinity of e^(tx)*f(x)*dx, but do I simply use 2-y for f(x) on that interval? I'm not exactly sure, I think...
6. ### Generating a linear system for popularity calculation

This is a half mathematical half computer science question. I am working on matlab on a mathematical problem. I want to generate a linear system for the calculation of popularity of people (a vector x) in a generic social network, given a simple matrix of friendship F. If user 1 and user 2 are...
7. ### Moment generating function

If I have a sequence of independent random variables having a standard normal distribution. Suppose N has a poisson distribution with mean \lambda and is independent of this sequence. Define a new random variable W = sum of Xi from i=0 to N. Show moment generating function of W is...
8. ### Generating a discrete curve over n interval with a set sum value (under curve)

Hello all, I am trying to figure out how to generate a bunch of different curves that all fall into the same category. They take place over n (96 to 144) discrete intervals or discrete iterations (these represent months) and need to always sum up to 100,000 (dollars). So I am trying to figure...
9. ### Moment generating function

Some variable Z has a poisson distribution where a > 0 Pz(i) = e^{-a}\frac{a^i}{i!} Mz(t) = e^{-a(1-e^t)} <- Moment generating function of Z Y = \frac{Z -a }{\sqrt{a}} I need to calculate the natural logarithm of the moment generating function of Y.Is my working below correct? Y =...
10. ### Find the generating function for the following sequence

Hello I need to find generating function for sequence : 1,1,1,1,1,1,0,0,0,0 .... G(x) = 1 + x + x^2 + x^3 + x^4 + x^5 + 0x^6 + 0x^7 + 0x^8 + 0x^9 ..... = 1 + x + x^2 + x^3 + x^4 + x^5 and then G(x) = \frac{1 - x^6}{1 - x} Why is There 1 - x^6? Can somebody help me to...
11. ### question in regards of generating a set of random triangles

Hi. I hope this is the right forum and the right section. :) Let's assume I have the following given: - a rectangle with a given length and height - a number of triangles I want to place in it - a value specifying how random the size of the triangles should be (for example from 0 to 1, where 0...
12. ### How many ways you can make change for an amount N using A and B monets.

I encountered a quite interesting problem. The question is: How many ways you can make change for an amount N using monets of value A and B, knowing that GCD(A,B)=1. Any idea how to solve this? It reminds me combinatorial class and generating functions. So i know that when we are given an...

15. ### Calculating moment generating function

I know how to calculate a moment generating function if the distribution looks like X ~ U(0,1), for instance. But if I have a uniform distribution looking like X_n \tilde \ U(0, \frac{1}{n}, ..., \frac{n-1}{n}, 1), how do I calculate M_{X_n}(t)?
16. ### generating expressions instead of deriving solutions

generating expressions instead of deriving solutions All possible expressions could be generated and each one tried out as a possible solution of a given problem. Once in a while we would find it to be an actual solution. This process of generating expressions as mere combinations of symbols...
17. ### Probability generating function

Hello! I have an exercise of this type that I just can not solve "Are X and Y be independent random variables, X-Poisson(a), Y-Poisson(b). Find the probability generating function of the random variable Z = 2x+3y+4 " The only thing I could do is to put into practice a property of the...
18. ### Methods of generating even numbers

I have uploaded this video and I would like to share with a pro maths to verify my findings, please let me know your thoughts: https://www.youtube.com/watch?v=7jG4Y7BWGaU
19. ### Homework help - Generating random variable

Hi, I have a problem on the following homework assignment: Suppose that X and Y are discrete random variables with a joint probability mass function p_XY (x, y). Procedure is the following: a. Generate X ? p_X (x). b. Accept X with probability p(y|X). c. If X is accepted, terminate and return...
20. ### Generating functions

Hi forum! If anyone can help me with this it would be a tremendous help. The answer to this problem is C(6+3-1,6) - C(3+3-1,3) - C(2+3-1,2). Here is the problem: How many ways are there to split six copies of one book, seven copies of a second book, and eleven copies of a third book between...


text:
FREE lectures this September + October | HSC Head Start + Exam Revision: book here | QCE Head Start: book here | VCE Exam Revision: book here

September 17, 2019, 08:19:56 pm

### AuthorTopic: "Challenge" Math Qs - Can You Figure It Out?  (Read 3469 times) Tweet Share

0 Members and 1 Guest are viewing this topic.

#### RuiAce

• ATAR Notes Lecturer
• Honorary Moderator
• Great Wonder of ATAR Notes
• Posts: 8493
• "All models are wrong, but some are useful."
• Respect: +2347
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #45 on: December 28, 2018, 04:03:00 pm »
+3
Quote tags intentionally removed, but for the sake of reference this is basically from the post immediately above.
\begin{align*}\sin{5x}&=\text{Im}[\cos{5x}+i\sin{5x}]\\&=\text{Im}[(\cos{x}+i\sin{x})^5]\\&=\text{Im}[(\cos{x})^5+5(\cos{x})^4i(\sin{x})+10(\cos{x})^3i^2(\sin{x})^2+10(\cos{x})^2i^3(\sin{x})^3+5(\cos{x})i^4(\sin{x})^4+i^5(\sin{x})^5]\\&=5(\cos{x})^4(\sin{x})-10(\cos{x})^2(\sin{x})^3+(\sin{x})^5\\&=5(1-(\sin{x})^2)^2(\sin{x})-10((\sin{x}))(\sin{x})^3+(\sin{x})^5\\&=5(\sin{x})-10(\sin{x})^3+5(\sin{x})^4+10(\sin{x})^5-10(\sin{x})^3+(\sin{x})^5\\&=16(\sin{x})^5-20(\sin{x})^3+5(\sin{x})\end{align*} \text{Subbing in} \ \frac{2\pi}{5} \ \text{into the left hand side, we have the sine of} \ 2\pi \ \text{which is zero, which means we are essentially solving for the roots of the right hand side.} \\ 16\left(\sin{\frac{2\pi}{5}}\right)^5 20\left(\sin{\frac{2\pi}{5}}\right)^3+5\left(\sin{\frac{2\pi}{5}}\right)=0 \\ \left(\sin\left({\frac{2\pi}{5}}\right)\right)\left(16\left(\sin{\frac{2\pi}{5}}\right)^4 20\left(\sin{\frac{2\pi}{5}}\right)^2+5\left(\sin{\frac{2\pi}{5}}\right)\right)=0 \\ \text{Knowing that the sine function only has roots at} \ n\times\pi \ \text{we can rule out} \ \left(\sin{\frac{2\pi}{5}}\right)=0 \ \text{as a solution.} \\ $\left(16\left(\sin{\frac{2\pi}{5}}\right)^4-20\left(\sin{\frac{2\pi {5}}\right)^2+5\left(\sin{\frac{2\pi}{5}}\right)\right)=0$\\ $\text{Let} \ \left(\sin^2{\frac{2\pi}{5}}\right) = a \\ 16a^2-20a+5=0 \\ a=\frac{20\pm\sqrt{400-320}}{32}$\\$a=\frac{20\pm4\sqrt{5}}{32} \left(\sin^2{\frac{2\pi}{5}})= \frac{5\pm\sqrt{5}}{8}$ \\$\left(\sin{\frac{2\pi}{5}}) = \sqrt{\frac{5\pm\sqrt{5}}{8}}$

The derivation derivation is coming, this question just seemed a lot friendlier.

EDIT: working on that right now, but also if you guys have time can you try and find the mistakes in the code? I've been trying for about 45 minutes (15 minutes typing, 45 minutes looking for errors) and I can't find them, super frustrating
end quote

The enter keys in the align* environment damaged most of the code. Once I took all of them out a lot of it fixed itself automatically. Following that I've chopped your code up into bits and pieces (you can use Ctrl+F and search tex) to find where the chopping up occurred. From what I can see, some \right) 's are missing!

Also a set of newline \\ characters are missing after your align* environment I think

#### fun_jirachi

• MOTM: AUG 18
• Forum Obsessive
• Posts: 484
• All doom and Gloom.
• Respect: +260
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #46 on: December 28, 2018, 04:23:01 pm »
+2
Okay, thanks so much Rui! I'll edit that right now, it looks awful.

I'm going to drop the solutions for the derivation of the sum of squares. I panicked a little bit for about the first half hour, but once I realised the end result was a polynomial, and the intuition behind plugging a number into a function and getting a number back, it wasn't that much harder than the induction proof.
Hope you guys can read my handwriting, haven't posted a picture in a while.
Page 1
Page 2
Failing everything, but I'm still Flareon up.

HSC 2018: Modern History [88] | 2U Maths [98]
HSC 2019: Physics | Chemistry | English Advanced | Maths Extension 1 | Maths Extension 2

#### RuiAce

• ATAR Notes Lecturer
• Honorary Moderator
• Great Wonder of ATAR Notes
• Posts: 8493
• "All models are wrong, but some are useful."
• Respect: +2347
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #47 on: December 28, 2018, 04:41:13 pm »
+3
Okay, thanks so much Rui! I'll edit that right now, it looks awful.

I'm going to drop the solutions for the derivation of the sum of squares. I panicked a little bit for about the first half hour, but once I realised the end result was a polynomial, and the intuition behind plugging a number into a function and getting a number back, it wasn't that much harder than the induction proof.
Hope you guys can read my handwriting, haven't posted a picture in a while.
Page 1
Page 2
Nice solution! To make the pattern you identified in part iii) appear a bit more obvious to the reader, you can argue it like this.
\text{Claim: Given a sequence defined by a quadratic function, the common difference of }\textit{those}\text{ terms form an A.P.}\\ \text{Proof: Let }T_k = f(k)\text{ where }f(x) = ax^2+bx+c.\text{ Then,}\\ \begin{align*}T_{k+1} - T_k &= f(k+1) - f(k)\\ &= a(k+1)^2 + b(k+1) + c - ak^2 - bk - c\\ &= 2ak + (1+b) \end{align*}\\ \text{hence the differences form an arithmetic progression with common difference }2a.
You can then replicate this proof to make your claim about the common difference with sequences defined by cubic equations. That's enough to suggest that $T_k = \text{some cubic function in terms of }k$ can be used to model the scenario you have right there! And of course, nothing else to comment on with the simultaneous equations.

The usual method is to consider the expression $\sum_{k=1}^n (k+1)^3 + \sum_{k=1}^n (k-1)^3$. On one hand,
\begin{align*} \sum_{k=1}^n (k+1)^3 - \sum_{k=1}^n (k-1)^3 &= \sum_{k=1}^n [(k+1)^3 - (k-1)^3]\\ &\vdots\\ &= 2\sum_{k=1}^n k^2 + 2\sum_{k=1}^n1 \end{align*}
And on the other hand,
\begin{align*}\sum_{k=1}^n (k+1)^3 - \sum_{k=1}^n (k-1)^3 &=[2^3 + \dots + (n-1)^3+ n^3 + (n+1)^3] - [0^3 + 1^3 + 2^3 + \dots + (n-1)^3]\\ &= n^3 + (n+1)^3 - 1^3\end{align*}
You can fill in the details of this proof if you want to or someone else can

#### AlphaZero

• MOTM: DEC 18
• Forum Obsessive
• Posts: 319
• $[\mathcal{L}f](s)=\int_0^\infty\!e^{-st}f(t)dt$
• Respect: +131
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #48 on: December 28, 2018, 04:52:27 pm »
+3
Fixing code (and condensing it) for @fun_jirachi. Few closing brackets missing and random returns in align environment where there shouldn't be one.
________________________________________________________________
\begin{align*}\sin(5x)&=\text{Im}\Big[\cos(5x)+i\sin(5x)\Big]\\
&=\text{Im}\Big[\big(\cos(x)+i\sin(x)\big)^5\Big]\\
&=\text{Im}\Big[\cos^5(x)+5\cos^4(x)\cdot i\sin(x)+10\cos^3(x)\cdot i^2\sin^2(x)+10\cos^2(x)\cdot i^3\sin^3(x)+5\cos(x)\cdot i^4\sin^4(x)+i^5\sin^5(x)\Big]\\
&\vdots\\
&=16\sin^5(x)-20\sin^3(x)+5\sin(x)\end{align*}
Subbing in $x=\dfrac{2\pi}{5}$ gives $0=16\sin^5\left(\frac{2\pi}{5}\right)-20\sin^3\left(\frac{2\pi}{5}\right)+5\sin\left(\frac{2\pi}{5}\right).$ Since $\sin\left(\dfrac{2\pi}{5}\right)\neq0$, we have $0=16\sin^4\left(\frac{2\pi}{5}\right)-20\sin^2\left(\frac{2\pi}{5}\right)+5.$
\begin{align*}\sin^2\left(\frac{2\pi}{5}\right)&=\frac{20\pm\sqrt{400-320}}{32}\\
&=\frac{5\pm\sqrt{5}}{8}\\
&\vdots\\
&\vdots\ \ (\text{more work required.}) \end{align*}
_______________________________________________________________

I'm going to stop it here since your solution isn't complete.
$\sin^2\left(\dfrac{2\pi}{5}\right)$ can't be two values at the same time and you also need to justify taking the positive root both times.
2015$-$2017:  VCE
2018$-$2021:  Bachelor of Biomedicine and Concurrent Diploma in Mathematical Sciences, University of Melbourne

#### fun_jirachi

• MOTM: AUG 18
• Forum Obsessive
• Posts: 484
• All doom and Gloom.
• Respect: +260
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #49 on: December 28, 2018, 06:05:50 pm »
+3
2. Fully expand $\sin(5x)$ in terms of powers of $\sin(x)$. Use this result to find $\sin\left(\frac{2\pi}{5}\right)$. You may encounter a quintic equation. One of the solutions, which you should be able to show isn't $\sin\left(\frac{2\pi}{y}\right)$, should be easy to find/guess. Factorise that, and the resulting quartic should be easily solvable.

Sorry for the repost, but this is the full solution (given that Dan kindly pointed out that I'm missing a few things at the end (oops, totally uncharacteristic of me to overlook such obvious things)). Also, it's a lot neater than the pile of trash I posted a few hours ago

\begin{align*}\sin(5x)
&=\text{Im}[\cos(5x)+i\sin(5x)]
\\&=\text{Im}\left[(\cos(x)+i\sin(x))^5\right]
\\&=\text{Im}\left[(\cos(x))^5+5(\cos(x))^4i(\sin(x))+10(\cos(x))^3i^2(\sin(x))^2+10(\cos(x))^2i^3(\sin(x))^3+5(\cos(x))i^4(\sin(x))^4+i^5(\sin(x))^5\right]
\\&=5(\cos(x))^4(\sin(x))-10(\cos(x))^2(\sin(x))^3+(\sin(x))^5
\\&=5\left(1-(\sin(x))^2\right)^2(\sin(x))-10(\sin(x))(\sin(x))^3+(\sin(x))^5
\\&=5(\sin(x))-10(\sin(x))^3+5(\sin(x))^4+10(\sin(x))^5-10(\sin(x))^3+(\sin(x))^5
\\&=16(\sin(x))^5-20(\sin(x))^3+5(\sin(x))
\end{align*}
\\ \text{Subbing in} \ x=\frac{2\pi}{5} \ \text{we have} \ 16\left(\sin\left(\frac{2\pi}{5}\right)\right)^5-20\left(\sin\left(\frac{2\pi}{5}\right)\right)^3+5\left(\sin\left(\frac{2\pi}{5}\right)\right)=0
\\ \left(\sin\left(\frac{2\pi}{5}\right)\right)\left(16\left(\sin\left(\frac{2\pi}{5}\right)\right)^4-20\left(\sin\left(\frac{2\pi}{5}\right)\right)^2+5\right)
\\ \left(\sin\left(\frac{2\pi}{5}\right)\right)=0 \ \text{is not a solution since the sine curve only has solutions at multiples of pi, so then we have}
\\ \left(16\left(\sin\left(\frac{2\pi}{5}\right)\right)^4-20\left(\sin\left(\frac{2\pi}{5}\right)\right)^2+5\right)=0
\\ \text{Let} \ a=\sin^2\left(\frac{2\pi}{5}\right)
\\ 16a^2-20a+5=0
\\ a = \frac{20\pm\sqrt{400-320}}{32}
\\ a = \frac{5\pm\sqrt{5}}{8}
\\ \text{So basically you verify that both solutions are between 0 and 1 (the range of} \ \sin^2x \text{), which they are.}
\\ \text{Noting that} \ \frac{2\pi}{5} < \ \frac{\pi}{2} \ \text{and that} \ \sin^2x \ \text{is monotonic increasing over the same domain basically just pick the bigger one, which is the positive root because} \ \frac{2\pi}{5} \ \text{is closer to} \ \frac{\pi}{2} \ \text{than} \ 0.
\\ \text{(Intuitively this is just true)}
\\ \text{Then} \ \sin^2\left(\frac{2\pi}{5}\right) = \frac{5+\sqrt{5}}{8}
\\ \sin\left(\frac{2\pi}{5}\right) = \pm\sqrt{\frac{5+\sqrt{5}}{8}}
\\ \text{And you take the positive root because} \ \sin\left(\frac{2\pi}{5}\right) \ \text{is a first quadrant angle and must be positive.}
\\ \sin\left(\frac{2\pi}{5}\right)=\sqrt{\frac{5+\sqrt{5}}{8}}

EDIT:
You can fill in the details of this proof if you want to or someone else can

After today's frustration both at my lack of coding skill and intuition, I literally can't be bothered.

« Last Edit: December 28, 2018, 06:08:28 pm by fun_jirachi »
Failing everything, but I'm still Flareon up.

HSC 2018: Modern History [88] | 2U Maths [98]
HSC 2019: Physics | Chemistry | English Advanced | Maths Extension 1 | Maths Extension 2

#### RuiAce

• ATAR Notes Lecturer
• Honorary Moderator
• Great Wonder of ATAR Notes
• Posts: 8493
• "All models are wrong, but some are useful."
• Respect: +2347
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #50 on: December 28, 2018, 06:14:28 pm »
+3
snip
To argue the choice of the positive root you're okay to assume that $y = \sin^2 x$ is monotonic increasing for all $0 < x < \frac\pi2$, however you haven't used that to convince me about anything. You're just saying that $\sin^2 \frac{2\pi}{5}$ is closer to $\sin^2\frac\pi2$ than $\sin^2 0$, but it doesn't tell us any information of "by how much is it closer".

One way to work around this issue is to note furthermore that $\sin^2 \frac{\pi}{4} = \frac12$. Note that $\frac{5-\sqrt5}{8} < \frac12 < \frac{5 + \sqrt5}{8}$, and also because $\sin^2x$ is monotonic increasing, we also have $\sin^2 \frac{\pi}{4} < \sin^2 \frac{2\pi}{5}$. Thus by pairing it off we end up with $\sin^2 \frac{2\pi}{5} = \frac{5+\sqrt5}{8}$

Man, you have so much time on your hands with these questions! You must be done with all two of your TuteSmart assignments already!

#### fun_jirachi

• MOTM: AUG 18
• Forum Obsessive
• Posts: 484
• All doom and Gloom.
• Respect: +260
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #51 on: December 28, 2018, 06:28:09 pm »
+1
To argue the choice of the positive root you're okay to assume that $y = \sin^2 x$ is monotonic increasing for all $0 < x < \frac\pi2$, however you haven't used that to convince me about anything. You're just saying that $\sin^2 \frac{2\pi}{5}$ is closer to $\sin^2\frac\pi2$ than $\sin^2 0$, but it doesn't tell us any information of "by how much is it closer".

One way to work around this issue is to note furthermore that $\sin^2 \frac{\pi}{4} = \frac12$. Note that $\frac{5-\sqrt5}{8} < \frac12 < \frac{5 + \sqrt5}{8}$, and also because $\sin^2x$ is monotonic increasing, we also have $\sin^2 \frac{\pi}{4} < \sin^2 \frac{2\pi}{5}$. Thus by pairing it off we end up with $\sin^2 \frac{2\pi}{5} = \frac{5+\sqrt5}{8}$

Huh, I really don't know why that didn't occur to me. Every time I read what I wrote, I feel more and more stupid, but I'll keep inequalities in mind when doing stuff like this in the future.

Man, you have so much time on your hands with these questions! You must be done with all two of your TuteSmart assignments already!

Nope, just a fat cbbs
Failing everything, but I'm still Flareon up.

HSC 2018: Modern History [88] | 2U Maths [98]
HSC 2019: Physics | Chemistry | English Advanced | Maths Extension 1 | Maths Extension 2

#### RuiAce

• ATAR Notes Lecturer
• Honorary Moderator
• Great Wonder of ATAR Notes
• Posts: 8493
• "All models are wrong, but some are useful."
• Respect: +2347
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #52 on: December 30, 2018, 04:04:49 pm »
+2
And yeah non-uniform convergence works. I would've just used this guy:
$f(x,y) = \frac{x^2}{x^2+y^2}\text{ with limits as }x\to 0, \, y\to 0$
Alternatively just use the example in the previous question:
$f(x,y) = 2\arctan \left(e^x \tan \frac{y}{2} \right)\text{ with limits as }y\to 0, x\to \infty$
High school questions: Well firstly there's still this one which I will leave alone.
1. Prove the cosine rule in trigonometry using properties of the vector dot product
Otherwise this is a relatively straightforward matrix question provided you know what induction is.
$\text{Let }D\text{ be a diagonal matrix. Use mathematical induction to prove that for }n\in \mathbb{Z}_+\\ \text{the terms of }D^n\text{ are just the individual components raised to the }n\text{-th power.}$
First year university: Another straightforward one.
$\text{Let }A\text{ be a square matrix with eigenvalue }\lambda \text{ and eigenvector }\mathbf{v}.\\ \text{Prove by induction that }\mathbf{v}\text{ is an eigenvalue of }A^n\text{ where }n \in \mathbb{Z}_+\\ \text{and find the corresponding eigenvalue.}$
First year university:
$\text{Show that if }\lambda\text{ is an eigenvalue of }A\in \mathbb{R}^{n\times n}\\ \text{then it is also an eigenvalue of }A^T$

#### lzxnl

• Victorian
• ATAR Notes Legend
• Posts: 3430
• Respect: +207
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #53 on: December 30, 2018, 06:43:56 pm »
+1
And yeah non-uniform convergence works. I would've just used this guy:
$f(x,y) = \frac{x^2}{x^2+y^2}\text{ with limits as }x\to 0, \, y\to 0$
Alternatively just use the example in the previous question:
$f(x,y) = 2\arctan \left(e^x \tan \frac{y}{2} \right)\text{ with limits as }y\to 0, x\to \infty$
High school questions: Well firstly there's still this one which I will leave alone.Otherwise this is a relatively straightforward matrix question provided you know what induction is.
$\text{Let }D\text{ be a diagonal matrix. Use mathematical induction to prove that for }n\in \mathbb{Z}_+\\ \text{the terms of }D^n\text{ are just the individual components raised to the }n\text{-th power.}$
First year university: Another straightforward one.
$\text{Let }A\text{ be a square matrix with eigenvalue }\lambda \text{ and eigenvector }\mathbf{v}.\\ \text{Prove by induction that }\mathbf{v}\text{ is an eigenvalue of }A^n\text{ where }n \in \mathbb{Z}_+\\ \text{and find the corresponding eigenvalue.}$
First year university:
$\text{Show that if }\lambda\text{ is an eigenvalue of }A\in \mathbb{R}^{n\times n}\\ \text{then it is also an eigenvalue of }A^T$
Ah yes, multivariate calc 101. I should know this, I taught a tutorial for that subject last semester. So many of those 0/0 limits that don't exist.

I love writing diagonal matrices using Kronecker deltas and using Einstein summation; makes all the working so pleasant to read.
2012
Mathematical Methods (50) Chinese SL (45~52)

2013
English Language (50) Chemistry (50) Specialist Mathematics (49~54.9) Physics (49) UMEP Physics (96%) ATAR 99.95

2014-2016: University of Melbourne, Bachelor of Science, Diploma in Mathematical Sciences (Applied Maths)

2017-2018: Master of Science (Applied Mathematics)

2019-:

Accepting students for  VCE tutoring in Maths Methods, Specialist Maths and Physics! PM for more details

#### redpanda83

• Trailblazer
• Posts: 48
• Respect: +2
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #54 on: December 31, 2018, 05:09:21 pm »
0
Hi
can someone help me out  with these two questions.
What is required to do them? I would like to learn.
I got them from here 2018 melb uni maths comp senior division
Thanks!

#### FelixHarvey

• Forum Regular
• Posts: 56
• Respect: +9
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #55 on: December 31, 2018, 05:43:47 pm »
+1
Hi
can someone help me out  with these two questions.
What is required to do them? I would like to learn.
I got them from here 2018 melb uni maths comp senior division
Thanks!

Hey redpanda83,

I am going to be absolutely no help at all explaining the solution. But have you had a look at the solutions provided by Melbourne Uni?

For anyone interested, all past papers & solutions for each division and year can be found here.
« Last Edit: December 31, 2018, 05:48:00 pm by FelixHarvey »
2018: Methods 45 | Specialist 41 | English 41 | Physics 44 | Software Development 48

ATAR: 99.40

Tutoring! PM me for details.

#### redpanda83

• Trailblazer
• Posts: 48
• Respect: +2
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #56 on: December 31, 2018, 05:52:14 pm »
0
Hey redpanda83,

I am going to be absolutely no help at all explaining the solution. But have you had a look at the solutions provided by Melbourne Uni?

For anyone interested, all past papers & solutions for each division and year can be found here.
I looked at the solutions before but i dont completely understand them. The techniques they use, i dont know what they are. I was able to get other questions done without no issue but question 2 and 6 doesnt work out for me. I thought someone here might be able to explain them.
« Last Edit: December 31, 2018, 05:59:44 pm by redpanda83 »

#### FelixHarvey

• Forum Regular
• Posts: 56
• Respect: +9
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #57 on: December 31, 2018, 06:23:16 pm »
+1
I looked at the solutions before but i dont completely understand them. The techniques they use, i dont know what they are. I was able to get other questions done without no issue but question 2 and 6 doesnt work out for me. I thought someone here might be able to explain them.

Ok, I've had a look at question 6 and I'll have a crack. No guarantee on the accuracy though...

Each number in the sequence has the form:
$101010101...1010101=10^0+10^2+10^4+...+10^{2n} \quad where \: n>1$
$\text{If we divide by 99 we get } \frac{1}{99}(99(10^0+10^2+10^4+...+10^{2n})) \\ =\frac{1}{99}(10^2-1)(10^0+10^2+10^4+...+10^{2n})$
$\text{"Expanding" the brackets we get: } \frac{1}{99}(10^{2+0}+10^{2+2}+10^{4+2}...+10^{2n+2} - (10^0+10^2+10^4+...+10^{2n}))$
$\text{Then cancelling, leaves us with: }\frac{1}{99}(10^{2(n+1)}-1)$
$\text{Using difference of two squares we can obtain: }\frac{1}{99}(10^{n+1}-1)(10^{n+1}+1)$
$\text{As }n>1\text{ both the factors } 10^{n+1}-1 \quad \& \quad 10^{n+1}+1 \text{ are greater than 99. Therefore, all numbers excluding 101 are not prime.}$
2018: Methods 45 | Specialist 41 | English 41 | Physics 44 | Software Development 48

ATAR: 99.40

Tutoring! PM me for details.

#### AlphaZero

• MOTM: DEC 18
• Forum Obsessive
• Posts: 319
• $[\mathcal{L}f](s)=\int_0^\infty\!e^{-st}f(t)dt$
• Respect: +131
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #58 on: May 25, 2019, 01:02:35 am »
0
I feel like reviving this thread.

For highschool students

a)     Where $a>0$, show that $\displaystyle \int_{0}^a \!\Big(f(x)+f(-x)\Big)dx=\int_{-a}^a f(x)\,dx$.

b)     Hence, find $\displaystyle \int_{-1}^1 \frac{x^n}{e^x+1}dx$, in terms of $n$, where $n>0$.

For university students

Let $C$ be the curve given by  $3x^2+y^2=1$  oriented anticlockwise, and let $\mathbf{F}(x,y)=\left(\frac{-y}{x^2+y^2},\ \frac{x}{x^2+y^2}\right).$ Evaluate  $\displaystyle \int_C \mathbf{F}\cdot d\mathbf{s}$.
2015$-$2017:  VCE
2018$-$2021:  Bachelor of Biomedicine and Concurrent Diploma in Mathematical Sciences, University of Melbourne

#### RuiAce

• ATAR Notes Lecturer
• Honorary Moderator
• Great Wonder of ATAR Notes
• Posts: 8493
• "All models are wrong, but some are useful."
• Respect: +2347
##### Re: "Challenge" Math Qs - Can You Figure It Out?
« Reply #59 on: May 25, 2019, 09:03:01 am »
0
For university students

Let $C$ be the curve given by  $3x^2+y^2=1$  oriented anticlockwise, and let $\mathbf{F}(x,y)=\left(\frac{-y}{x^2+y^2},\ \frac{x}{x^2+y^2}\right).$ Evaluate  $\displaystyle \int_C \mathbf{F}\cdot d\mathbf{s}$.
Isn't this just a regular path integral? Or are you trying to throw off the people who think the answer is 0


text:
## formal languages - Is it correct: whether or not a type 3 grammar generates \$ Sigma ^ * \$ is not c.e

An example from Sipser's book, Introduction to Computational Theory, shows that it is not decidable $$TM$$ recognize if a $$CFG$$ (or a type 2 grammar) generates $$Sigma ^ *$$, or $$Sigma$$ is the alphabet. Call this language $$CFG_ {all}$$

But the above language is also not computable. There may be a reduction of $$CFG_ {all}$$ at $$bar {A_ {TM}}$$, or $$bar {A_ {TM}}$$ is the language s.t. the entry $$TM$$ accepts no entry. $$bar {A_ {TM}}$$ is not computable.

But could we say that if a type 3 grammar generates or not $$Sigma ^ *$$ also isn't c.e. ? (since type 3 grammars are a subset of grammars without context). If it is true that a finite automaton can recognize $$Sigma ^ *$$, this language is different from the fact that a type 3 grammar generates $$Sigma ^ *$$?

Just to clarify the source of my confusion, in summary, it is decidable for a $$TM$$ to decide if a pushdown controller recognizes $$Sigma ^ *$$ or accepts any input, but it is not decidable or even calculable for a $$TM$$ recognize that a CFG generates $$Sigma ^ *$$. Likewise, it is decidable $$TM$$ check if a finite automaton accepts $$Sigma ^ *$$, but it may not be decidable for a $$TM$$ to check if a type 3 grammar generates $$Sigma ^ *$$. It's sort of the difference between recognizing and generating.

## SALE: Generalie.com is an easy-to-remember general domain that generates traffic on autopilot

This traffic seems suspicious to me.

Mostly American traffic, but it arrives at your site when most people in the United States are sleeping – and on a desktop device.

What would make an American go to his desktop in the middle of the name and type your URL (full of Arabic) in his browser?

This traffic is more than likely false.

## javascript – How to increase the scalability of the method that generates each file while changing several conditions?

I have a common style (common.scss) and a text direction options file (RTL, LTR) (option-document-direction-rtl.scss, option-document-direction-ltr.scss). And by changing the reading of these files, the css file with modified RTL / LTR is output by a method like gulp.

_common.scss

body {
max-width: 1120px;
background-color: black;
color: white;
text-align: \$direction;
}

_option-document-management-rtl.scss

\$direction: right;

_option-document-management-ltr.scss

\$direction: left;

style.scss

@import "option-document-direction-rtl";
// switch to @import "option-document-direction-rtl";

@import "common.scss"

And I can go down below two css files at the same time by a method (in fact, the style of these scss files is more complex):

joe-style.css

body {
max-width: 1120px;
background-color: black;
color: white;
text-align: right;
}

ltr-style.css

body {
max-width: 1120px;
background-color: black;
color: white;
text-align: left;
}

### Main subject

So I have to change these style conditions different from the direction of the text. For example, the size of the screen without multimedia queries. In this case, I think I need a new options SCSS file, such as _computer.scss and _smartphone.scss. Here I had a question.

The number of configuration files with new conditions may increase in the future. In the current method, in short, the css file to be output is modified according to that of the "configuration files which describe the parameters used in each condition" which is read.

I'm afraid my configuration files will grow and become more difficult to manage. What tools and mechanisms on SCSS can be used to increase the scalability of many configuration files?

I have considered a method to dynamically modify the output file based on the argument at generation time, but I have not been able to determine if this is a way to improve scalability.

I asked a question about Stack Overflow earlier, where I suggested other SE sites, such as Code Review SE. So I checked the list of SE sites. Then, according to each help center, I realized that the content could be published both on the following site and on Sofrware Engineering. Because I don't know which one is best for my topic, I published content similar to Code Review SE.

## Although you can't make it a macro, it works if you save it as an ability

&{template:simple} ?{Save|STR, {{rname=Strength}} {{mod=@{selected|strength_save_bonus}}} {{r1=((1d20+@{selected|strength_save_bonus}))}} {{r2=((1d20+@{selected|strength_save_bonus}))}}{{always=1}}|DEX, {{rname=Dexterity}} {{mod=@{selected|dexterity_save_bonus}}} {{r1=((1d20+@{selected|dexterity_save_bonus}))}} {{r2=((1d20+@{selected|dexterity_save_bonus}))}} {{always=1}}|CON, {{rname=Constitution}} {{mod=@{selected|constitution_save_bonus}}} {{r1=((1d20+@{selected|constitution_save_bonus}))}} {{r2=((1d20+@{selected|constitution_save_bonus}))}}{{always=1}}|INT, {{rname=Intelligence}} {{mod=@{selected|intelligence_save_bonus}}} {{r1=((1d20+@{selected|intelligence_save_bonus}))}} {{r2=((1d20+@{selected|intelligence_save_bonus}))}} {{always=1}}|WIS, {{rname=Wisdom}} {{mod=@{selected|wisdom_save_bonus}}} {{r1=((1d20+@{selected|wisdom_save_bonus}))}} {{r2=((1d20+@{selected|wisdom_save_bonus}))}} {{always=1}}|CHA, {{rname=Charisma}} {{mod=@{selected|charisma_save_bonus}}} {{r1=((1d20+@{selected|charisma_save_bonus}))}} {{r2=((1d20+@{selected|charisma_save_bonus}))}}{{always=1}}} {{charname=@{selected|token_name}}}

It will ask the user for the backup type, then launch a backup of the selected type for the currently selected token, then output it in the same format as if you had rolled it directly from the character sheet .

It should be recorded as an ability (on a character sheet, under the "Attributes and Abilities" tab) rather than as a global macro, because if you save it as a macro global, each instance of } (HTML replacement for } ) converts by breaking everything.

## Where is the string that generates the hash with 18-20 zeros?

When Bitcoin miners mine, they must solve a difficult and extremely repetitive mathematical problem using the SHA256 algorithm. Miners try (mainly to play the lottery and almost always work in large groups) to get a hash with (currently) at least ~ 18.81 zeros. (I put a decimal / floating point number because the value is inconsistent.) But, I want to put the hash in a hash function and get that super hard number to calculate for a story I have where a superhero calculates this number. How do I get this string (nonce) that calculates this hash set to zero and where can I find it on a block explorer, such as blockchain.com, or on bitcoin-cli?

## root access – Individual commands work fine, but shell script generates errors

I am trying to create a shell script to configure iptables and add some routes to my device running Android 10. I have root access.

Here is the script. I called him script.sh:

#!/system/bin/sh
iptables -t filter -F FORWARD
iptables -t nat -F POSTROUTING
iptables -t filter -I FORWARD -j ACCEPT
iptables -t nat -I POSTROUTING -j MASQUERADE
ip rule add from 192.168.43.0/24 lookup 61

sysctl -w net.ipv6.conf.wlan1.disable_ipv6=1

I have a root console open via ADB, and I can execute each individual command from the script manually in the console, as follows:

… etc.

But this happens when I run my script:

and I don't really understand why.

I have limited skills with Android and Linux, so I tried to follow and combine a few examples, but I was unlucky.
https://www.pctips4u.com/2016/03/writing-shell-scripts-in-android.html
https://gist.github.com/LouWii/9626480

## rendering – Unity generates a bad mipmap, which makes voxel terrains bad

It's just a dirty ground with grass blocks on the High. (which are just blocks of earth with green tops.)

I sampled the height map of a Unity terrain, and built a voxel terrain based on it, and I divided it into pieces, the meshes of which were then combined.

Unfortunately, the the generated mipmaps are bad, the change of mipmap is easily noticeable: shade of green changes, then he becomes completely dirt color.

## magento2 – The CSV uploader generates random errors for identical entries

I get random errors for identical data.

For example: each cell of the attribute_set_column has a 9, but I get this error

Invalid value for Attribute Set column (set doesn't exist?) in row(s): 575, 577

Is there a way to fix inconsistencies like this, or at least get less vague error messages?

Thank you

## python – PySide2 generates an error, "QPaintDevice: unable to destroy the painting device while painting"

After experimenting, it seems that the painter must clean before pixmap done, otherwise you get the error. For example, it works without error.

from PySide2.QtGui import QPixmap, QPainter
from PySide2.QtWidgets import QApplication

app = QApplication()
width = 200
height = 100
pixmap = QPixmap(width, height)
painter = QPainter(pixmap)
painter.drawLine(0, 0, 100, 100)
print('Done.')

del painter
del pixmap

You can also tell painter clean without destroying it. Just tell him that you're done painting by calling end().

from PySide2.QtGui import QPixmap, QPainter
from PySide2.QtWidgets import QApplication

app = QApplication()
width = 200
height = 100
pixmap = QPixmap(width, height)
painter = QPainter(pixmap)
painter.drawLine(0, 0, 100, 100)
print('Done.')

painter.end()

There are other things that avoid error for mysterious reasons. For example, this avoids error.

from PySide2.QtGui import QPixmap, QPainter
from PySide2.QtWidgets import QApplication

app = QApplication()
width = 200
height = 100
pixmap = QPixmap(width, height)
painter = QPainter(pixmap)
painter.device()  # <-- No idea why this helps!
painter.drawLine(0, 0, 100, 100)
print('Done.')

In summary, just make sure the painter cleans up before the pixmap. I would recommend using the painter in a smaller scope than the pixmap or calling explicitly painter.end().

## ssh – dpkg generates an error when regenerating certificates for my instance on AWS

I am trying to regenerate certificates for my instance on AWS via Docker-Machine as I have to do it often enough for some reason. Suddenly I get this error after running docker-machine regenerate-certs [instance]:

Error running "DEBIAN_FRONTEND=noninteractive sudo -E apt-get install -y  curl": ssh command error:
command : DEBIAN_FRONTEND=noninteractive sudo -E apt-get install -y  curl
err     : exit status 100
output  : E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

Execution sudo dpkg --configure -a will not make the problem go away.

Why am I getting this all of a sudden and how can I fix it?


text:
Linear Regression

December 25, 2017

Written by Boutros El-Gamil

1. Idea

[watch video]
Suppose we have a set of observations represented by two variables $$x$$ and $$y$$. Let’s assume that our observations are group of persons, and the $$2$$ variables are persons’ heights ($$x$$ axis) and weights ($$y$$ axis). If we plot heights and weights in a scatter plot (see below), we can easily find a kind of correlation between them (i.e. as height increase, weight increase as well, and vice versa)

Let’s also assume that we want to find a linear relationship (i.e. linear function) between heights and weights, such that if we have the value of a new person height, we can predict her/his corresponding weight. In this case, we call variable height the independent variable or predictor, and variable weight the dependent variable or target variable.

As a reminder, the linear function is defined by $$2$$ coefficients ($$m$$ is the slope, which reflects the change of $$y$$ divided by the change of $$x$$), and $$b$$ (the point at which the line intersects with $$y$$ axis). In the below figure, $$m = 4.13$$ and $$b = -152.43$$

Back to our goal, we need to find a linear function between $$x$$ and $$y$$, but, which linear function? As you can imagine, there are endless number of lines that can represent such function (see the below figure). So the question would be, which line is the best?

Let’s go to the theory of linear regression, to be able to answer this question.

2. Theory

If we have a set of observations (like below left figure), the best line between variables $$x$$ and $$y$$  (right figure) would be the one that minimizes the distances between the observations (red dots) and their corresponded predicted values (blue linear function). This approach is called the Least Squares approach, since it minimizes the square of these distances (vertical green lines).

According to least square approach, and in order to find the best linear function between $$x$$ and $$y$$, we need to find a vector of coefficients $$\vec{w}$$ that minimizes the following function:

$$E(\mathbf{w}) = \frac{1}{N}\sum \limits_{i=1}^N [y^{(i)}-f(x^{(i)},\mathbf{w})]^2 \tag{1}$$

Notations:

• $$x^{(i)}$$ and $$y^{(i)}$$ are values of variables $$x$$ and $$y$$ of observation $$i$$
• $$N$$ is number of observations
• $$\mathbf{w}$$ is vector of coefficients to identify linear regression function

Function (1) is called error function, objective function, or cost function. In this post, a form of error function called Mean-Square-Error (MSE) is used, where squaring differences between true and predicted values allows us to consider positive and negative differences the same, and division by $$N$$ allows us to compare different sizes of data using same coefficients’ values.

The function $$f(x^{(i)},\mathbf{w})$$ is called linear regression function or hypothesis function, and is defined as:

f(x^{(i)},\mathbf{w}) = w_0 + w_1x^{(i)}\tag{2}

where $$w_1$$ is the slope and $$w_0$$ is $$y$$ intercept at $$x= 0$$.

We know from Calculus, that minimizing (or maximizing) a function can be done, by equalizing it’s first derivative to zero, and solving the generated equations to find the corresponded coefficients. As an example, in the below graph, we have a function $$f(x)$$ (green). If we want to find the maximum value of $$f(x)$$ (Point $$A$$) or the minimum value (Point $$B$$), we compute the function’s derivative $$f'(x)$$ (blue), and find the points where $$f'(x)$$ intersects with $$x$$ axis.

Let’s try to differentiate Equation (1) with respect to $$\mathbf{w}$$ and find the values of $$w_0$$ and $$w_1$$.

• compute $$w_0$$ ($$y$$ intercept at $$x=0$$)

\frac{\partial E(\mathbf{w})}{\partial w_0}= \frac{1}{N} \sum\limits_{i=1}^N \frac{\partial [y^{(i)} – (w_0 + w_1 x^{(i)})]^2}{\partial w_0}\tag{3}

\frac{\partial E(\mathbf{w})}{\partial w_0}= \frac{1}{N} \sum\limits_{i=1}^N \frac{\partial [{y^{(i)}}^2 -2y^{(i)}(w_0 + w_1 x^{(i)}) + (w_0 + w_1 x^{(i)})^2 ]}{\partial w_0}\tag{4}

\frac{\partial E(\mathbf{w})}{\partial w_0}= \frac{1}{N} \sum\limits_{i=1}^N \frac{\partial [{y^{(i)}}^2 – 2w_0 y^{(i)} – 2 w_1 x^{(i)} y^{(i)} + w_0^2 + 2w_0 w_1 x^{(i)} + w_1^2 {x^{(i)}}^2] }{\partial w_0}\tag{5}

\frac{\partial E(\mathbf{w})}{\partial w_0}= \frac{1}{N} \sum\limits_{i=1}^N -2 y^{(i)} +2 w_0 + 2 w_1 x^{(i)}\tag{6}

\frac{\partial E(\mathbf{w})}{\partial w_0}= \frac{-2}{N} \sum\limits_{i=1}^N y^{(i)} – (w_0 + w_1 x^{(i)}) \tag{7}

• compute $$w_1$$ (slope)

for this part, we will differentiate Equation (5) with respect to $$w_1$$, as follows:

\frac{\partial E(\mathbf{w})}{\partial w_1}= \frac{1}{N} \sum\limits_{i=1}^N \frac{\partial [{y^{(i)}}^2 – 2w_0 y^{(i)} – 2 w_1 x^{(i)} y^{(i)} + w_0^2 + 2w_0 w_1 x^{(i)} + w_1^2 {x^{(i)}}^2] }{\partial w_1}\tag{8}

\frac{\partial E(\mathbf{w})}{\partial w_1}= \frac{1}{N} \sum\limits_{i=1}^N -2 x^{(i)} y^{(i)} +2 w_0 x^{(i)} + 2 w_1 {x^{(i)}}^2\tag{9}

\frac{\partial E(\mathbf{w})}{\partial w_1}= \frac{-2}{N} \sum\limits_{i=1}^N x^{(i)}[y^{(i)} – (w_0 + w_1 x^{(i)})] \tag{10}

Please note, that the only difference between equations (7) and (10), is that when we differentiate the error function with respect to the second coefficient $$w_1$$, we multiply the right side inside the sigma by $$x^{(i)}$$.

Now, we put both (7) and (10) equations to zero:

\frac{-2}{N} \sum\limits_{i=1}^N y^{(i)} – (w_0 + w_1 x^{(i)}) = 0\tag{11}

\frac{-2}{N} \sum\limits_{i=1}^N x^{(i)}[y^{(i)} – (w_0 + w_1 x^{(i)})] = 0\tag{12}

There are two ways to solve this equations system and obtain $$\mathbf{w}$$: a closed form approach, and the gradient descent algorithm.

3. Closed Form Approach

[watch video]
Let us remove the $$N$$ fraction and re-order equations (11), (12):

\sum\limits_{i=1}^N y^{(i)} = w_0 N + w_1 \sum\limits_{i=1}^N x^{(i)}\tag{13}

\sum\limits_{i=1}^N x^{(i)}y^{(i)} = w_0 \sum\limits_{i=1}^N x^{(i)} + w_1 \sum\limits_{i=1}^N {x^{(i)}}^2\tag{14}

Now, we have 2 equations in 2 missing variables, which can be solved if we re-write equations (13) and (14) in matrix form:
\begin{gather}
\begin{bmatrix} \sum\limits_{i=1}^N y^{(i)} \\ \sum\limits_{i=1}^N x^{(i)}y^{(i)} \end{bmatrix}
=
\begin{bmatrix} w_0 \\ w_1 \end{bmatrix}
\begin{bmatrix}
N &
\sum\limits_{i=1}^N x^{(i)} \\
\sum\limits_{i=1}^N x^{(i)} &
\sum\limits_{i=1}^N {x^{(i)}}^2
\end{bmatrix}\tag{15}
\end{gather}

which simulates the form:

\mathbf{B} = \mathbf{wA}\tag{16}

then the vector $$\mathbf{w}$$ is computed as:

\mathbf{w} = \mathbf{A}^{-1} \mathbf{B}\tag{17}

4. Gradient Descent Algorithm

We can imagine the gradient descent algorithm for linear regression as a $$3$$d graph (see below). We start at random values of $$\mathbf{w}$$, compute the corresponded error function $$E(\mathbf{w})$$, and iteratively updating $$\mathbf{w}$$ in the direction of lowering $$E(\mathbf{w})$$, until either $$\nabla E(\mathbf{w})= 0$$, or a satisfied converge is reached.

Gradient descent algorithm (listed below) require three input parameters: the cost function $$E(\mathbf{w})$$ to be differentiated, initial values of linear coefficients vector $$\mathbf{w}$$, and a third parameter called the learning rate. The role of learning rate is to control the algorithm speed while minimizing the error function. On the one hand, if learning rate take high values, the algorithm will converge quickly, but it can fall into a local minima. On the other hand, if learning rate is small, the algorithm may take considerable running time to converge. Different values of $$\eta$$ should be tested to select the most probable value for data in hand.

Algorithm1 GradientDescent($$E(\mathbf{w}),\mathbf{w},\eta$$)

1. Input:
2. $$E(\mathbf{w})$$: cost function
3. $$\mathbf{w}$$: initial values of coefficients vector
4. $$\eta$$: learning rate
5. Output:
6. $$\mathbf{w}$$: updated values of coefficients vector
7. Procedure:
8. repeat
1. $$w_p=w_p – \eta \frac{\partial E(\mathbf{w})}{\partial w_p}, \forall w_p \in \mathbf{w}$$
9.  until $$\nabla E(\mathbf{w})= 0$$
10. return $$\mathbf{w}$$

Coefficients ($$w_p$$) in the gradient descent algorithm are updated as follows:

w_0= w_0 – \eta \frac{-2}{N} \sum\limits_{i=1}^N y^{(i)} – (w_0 + w_1 x^{(i)}) \tag{18}

w_1= w_1 – \eta \frac{-2}{N} \sum\limits_{i=1}^N [y^{(i)} – (w_0 + w_1 x^{(i)})] x^{(i)}\tag{19}

5. Multivariate Linear Regression

In the above discussion, we considered one independent variable $$x$$ (heights) to learn from. Now, suppose that we have multiple independent variables $$\mathbf{x}=[x_1, x_2 …,x_M]$$. As an example, let’s assume we have heights, ages and blood pressures of a group of persons, and we want to use all these predictors to predict the weight variable. In this case, our linear regression function (equation 2), will be expanded to:

f(\mathbf{x}^{(i)},\mathbf{w}) = w_0 x_0^{(i)} + w_1 x_1^{(i)} + w_2 x_2^{(i)} + … + w_M x_M^{(i)}\tag{20}

or in more compact form:

f(\mathbf{x}^{(i)},\mathbf{w}) = \sum\limits_{j=0}^M w_j x_j^{(i)}\tag{21}

Notations:
$$x_j^{(i)}$$ is the value of independent variable $$x_j$$ at observation $$i$$
$$M$$ is number of independent variables (i.e. predictors)
$$\mathbf{w}$$ is vector of coefficients to identify linear regression function

5.1 Computing Coefficients Vector $$\mathbf{w}$$

In order to compute $$\mathbf{w}$$, we re-formulate equations (7) and (10) in one equation as follows:

\begin{gather}
\begin{aligned}
\frac{\partial E(\mathbf{w})}{\partial w_j}= \frac{-2}{N} \sum\limits_{i=1}^N x_j^{(i)}[y^{(i)} – f(\mathbf{x}^{(i)},\mathbf{w})],
\\
\forall j \in [0:M], x_0^{(i)} = 1
\end{aligned}\tag{22}
\end{gather}

As an example, suppose we have $$2$$ independent variables (i.e. $$M=2$$). This means we need to compute $$3$$ coefficients $$w_0$$, $$w_1$$ and $$w_2$$. Our regression (i.e. hypothesis) function would be:

f(\mathbf{x}^{(i)},\mathbf{w}) = w_0 x_0^{(i)} + w_1 x_1^{(i)} + w_2 x_2^{(i)}\tag{23}

by setting $$x_0^{(i)} = 1$$, the equation will be:

f(\mathbf{x}^{(i)},\mathbf{w}) = w_0 + w_1 x_1^{(i)} + w_2 x_2^{(i)}\tag{24}

The corresponded error function derivatives will be:

\frac{\partial E(\mathbf{w})}{\partial \mathbf{w}}= \frac{-2}{N} \sum\limits_{i=1}^N x_j^{(i)}[y^{(i)} – (w_0 + w_1 x_1^{(i)} + w_2 x_2^{(i)})]\tag{25}

5.2 Closed Form Approach

In order to apply the closed-form approach on multivariate linear regression, we build two matrices: the following $$N \times (M+1)$$ matrix $$\mathbf{X}$$ represents the matrix of independent variables. please note that the first column set to 1’s is corresponded to $$x_0^{(i)}$$ is equation (22).

\begin{gather}
\mathbf{X}
= \begin{bmatrix}
1 & x_1^{(1)} & x_2^{(1)} & … & & x_M^{(1)} \\\\
1 & x_1^{(2)} & x_2^{(2)} & … & & x_M^{(2)} \\\\
\vdots \\\\
1 & x_1^{(N)} & x_2^{(N)} & … & & x_M^{(N)}
\end{bmatrix}
\end{gather}

and the following $$N \times 1$$ matrix $$\mathbf{Y}$$ represents the dependent variable $$y$$:

\begin{gather}
\mathbf{Y}
= \begin{bmatrix}
y^{(1)} \\\\
y^{(2)} \\\\
\vdots \\\\
y^{(N)}
\end{bmatrix}
\end{gather}

After building these two matrices, the vector of coefficients $$\mathbf{w}$$ is calculated as:

\mathbf{w} = (\mathbf{X}^T \mathbf{X})^{-1} \mathbf{X}^T \mathbf{Y}\tag{26}

5.3 Gradient Descent Algorithm

The gradient descent algorithm for 1 independent variable is still valid for multi independent variables. The sole change will be in definitions of error function derivatives according to equation (22). As an example, the following updates are valid in the case of 2 independent variables:

w_0= w_0 – \eta\frac{-2}{N} \sum\limits_{i=1}^N y^{(i)} – (w_0 + w_1 x_1^{(i)} + w_2 x_2^{(i)})

w_1= w_1 – \eta\frac{-2}{N} \sum\limits_{i=1}^N x_1^{(i)} [y^{(i)} – (w_0 + w_1 x_1^{(i)} + w_2 x_2^{(i)})]

w_2= w_2 – \eta\frac{-2}{N} \sum\limits_{i=1}^N x_2^{(i)} [y^{(i)} – (w_0 + w_1 x_1^{(i)} + w_2 x_2^{(i)})]

Please note that in order to compute each coefficient $$w_j$$, you need the previous values for all other coefficients, including $$w_j$$.

6. Closed Form or Gradient Descent?

There is no doubt that closed form solution is the most convenient way to calculate the vector of coefficients $$\mathbf{w}$$, as long as your computer can compute matrix $$(\mathbf{X}^T \mathbf{X})^{-1}$$ in feasible time. Please note that this is a $$M \times M$$ matrix, which can take long running time if number of predictors $$M$$ is large. In addition, gradient descent algorithm is efficient for data with large number of predictors $$M$$, but you must take care of selecting suitable value for learning rate $$\eta$$.

7. Implementation in Python

You can find python implementations of the above algorithms on my GitHub.

This Post Has 13 Comments

1. It’s hard to find educated people for this topic, however, you sound like you know what you’re talking about! Thanks

1. Thank you! You are also invited to watch the corresponded YouTube vedios

2. “Thank you ever so for you article post.Much thanks again. Will read on…”

1. I hope you find the material useful for you. For more explanation, you are invited to watch the attached YouTube Videos

3. Hmm it seems like your blog ate my first comment (it was super long) so I guess I’ll just sum
it up what I had written and say, I’m thoroughly enjoying your blog.
I as well am an aspiring blog blogger but I’m still new
to the whole thing. Do you have any recommendations for novice blog writers?

I’d certainly appreciate it.

1. Hi!
I think the first thing you should prepare is the valuable material for your readers. The rest can be easily learned from the Web.
All the best for your Blogging.

4. Hi there to all, the contents present at this site are genuinely awesome
for people knowledge, well, keep up the nice work fellows.

5. Nice post thanks for sharing

1. Thanks!

6. Have you ever considered about adding a little bit more
than just your articles? I mean, what you say is important and all.
But think of if you added some great pictures or videos to give your posts more,
“pop”! Your content is excellent but with pics and clips, this
blog could certainly be one of the very best in its field.
Good blog!

1. Thanks for your hints! I will take this into account

7. Thanks for sharing !

1. You’re welcome!


text:
• # question_answer Which of the following condition is used to find atomic $C{{l}_{2}}$ from molecular $C{{l}_{2}}$ [CPMT 1996] A) High temperature, high pressure B) Low temperature, high pressure C) High temperature, low pressure D) Low temperature, low pressure

$\underbrace{C{{l}_{2}}\to }_{\text{1}\,\text{mole}}$$\underbrace{2Cl\,\Delta H}_{\text{2}\,\,\text{mole}}$$=+\,ve$ High temperature and low pressure is favourable.


text:
## For a function g(x), the difference quotient is StartFraction 6 Superscript x + h minus 3 Baseline minus 6 Superscript x + 3 Baseline Over h

Question

For a function g(x), the difference quotient is StartFraction 6 Superscript x + h minus 3 Baseline minus 6 Superscript x + 3 Baseline Over h EndFraction. What is the average rate of change of g(x) on the interval from x = –2 to x = 1?

in progress 0
5 months 2021-08-30T09:35:47+00:00 1 Answers 0 views 0

The average rate of change in that interval is 1.99

Step-by-step explanation:

Here we have that the difference quotient for g(x) is:

Remember that for a general function f(x), the difference quotient is:

So if we look at the difference quotient for g(x), we can conclude that:

Also remember that the average rate of change in an interval (a, b) is just:

So here we want the average rate of change of g(x) in the interval from x = -2 to x = 1, this is:

The average rate of change in that interval is 1.99


text:
# How to delete a DB2 table TAB1?

DB2DatabaseBig Data Analytics

#### Learn Azure Cosmos DB basics this weekend in 3 hour

36 Lectures 4.5 hours

We can delete the unused tables in the DB2. However, we must keep in mind that if we delete a table then all the indexes associated with the table are also dropped. Moreover, the triggers and views for the deleted table will become inaccessible. To delete any table in DB2, we can issue below command.

DROP TABLE DBSET1.TAB1

The DROP TABLE reserved word will be followed by the name of the table qualified by the database. The mentioned table will be deleted from the DB2 permanently.

Updated on 12-Sep-2020 14:20:28


text:
# Freeing a binary tree data structure in C

I have this function that I hope to be a good alternative to the recursive (thus performance expensive) approach.

#define _free_all(node, yes_no) \
do { \
Tree *__i;
for (__i = node; __i; __i = __i->yes_no); \
free(; node != __i; __i = __i->parent) { \
free(__i->value); \
free(__i); \
} \
} while (0)

void Tree_destroy(tree)
Tree *tree;
{ /* Destroys a Tree object - Non Recursive */
if (!tree)
return;
_free_all(tree, yes);
_free_all(tree, no);

if (tree->parent) {
if (tree->parent->no == info)
tree->parent->no = NULL;
else
tree->parent->yes = NULL;
}
free(tree);
}

The two children of each parent are no and yes.

Are there any issues with this approach ?

• How are Info and Tree defined? – Olaf Dietsche Nov 14 '14 at 22:45
• @OlafDietsche: Nothing, I just forgot to rename it. I corrected that. – Amr Ayman Nov 14 '14 at 22:59
• Names starting with _ and __ are reserved and best if avoided. – glampert Nov 15 '14 at 1:30
• Have you actually tested this code? It doesn't free the whole tree. The free_all macro either frees only left nodes or only right nodes, which means that any node in your tree that isn't on the left edge or right edge won't be freed. – JS1 Nov 15 '14 at 10:50
• JS1's comment is exactly the kind of thing I was going to warn about; binary trees and recursion are so intimately tied that any iterative function to do the same work will probably be horrendously complicated, which could lead to missed edge cases, leading to segfaults and memory leaks. – tsleyson Nov 15 '14 at 19:00

### 1. Bug

JS1 is quite correct to point out that this does not work: it never visits or frees tree->yes->no (among other nodes).

### 2. Correct algorithm

Consider a finite state machine with three states:

1. If tree has a left child, set tree to its left child and go to state 1. Otherwise, go to state 2.

2. If tree has a right child, set tree to its right child and go to state 1. Otherwise, go to state 3.

3. (In this state tree has no children.) Destroy tree. If tree had no parent, stop. Otherwise, delete whichever of parent's children is equal to tree, set tree to parent and go to state 1.

This state machine walks the tree in post-order, destroying each node after destroying all of its descendant nodes. Here's one way of translating this into C:

void TreeDestroy(Tree *tree)
{
for (;;) {
if (tree->left) {
tree = tree->left;
} else if (tree->right) {
tree = tree->right;
} else {
Tree *parent = tree->parent;
free(tree->value);
free(tree);
if (!parent)
break;
else if (parent->left == tree)
parent->left = NULL;
else if (!parent->left && parent->right == tree)
parent->right = NULL;
else
assert(0); /* can't happen if tree is well-formed */
tree = parent;
}
}
}

(I've used "left" and "right" here because these are the more usual names for the two children of a node in a binary tree.)

### 3. What if there are no parent pointers?

To iteratively destroy a binary tree with no parent pointers, start with the rotate right operation:

void TreeRotateRight(Tree **tree)
{
Tree *left = (*tree)->left;
(*tree)->left = left->right;
left->right = *tree;
*tree = left;
}

By repeatedly applying the rotate right operation, you can turn a tree into a vine. (A vine is a degenerate tree in which nodes only have right children.)

void TreeToVine(Tree **tree)
{
while (*tree) {
while ((*tree)->left)
TreeRotateRight(tree);
tree = &((*tree)->right);
}
}

And then a vine is easy to destroy iteratively:

void TreeDestroy(Tree *tree)
{
TreeToVine(&tree);
while (tree) {
assert(!tree->left);
Tree *right = tree->right;
free(tree->value);
free(tree);
tree = right;
}
}