Sunday, August 23, 2009

Algebra

I'm studying algebra with some friends, and i will try to write here what subjects are we studying right now.

We start with Abstract Algebra using Hungerford book, but i want to follow the MITOpenCourseWare about Algebra I (http://ocw.mit.edu/OcwWeb/Mathematics/18-701Fall-2007/Readings/index.htm).

Composition Law:
A composition law $f$ select a pair of elements on a set $S$ and return an element of $S$, ie:
$f : S \times S \rightarrow S$, I will write $f(a,b)$ as $a*b$ for seek of simplicity.

If $*$ holds that $(a*b)*c = a*(b*c) \quad \forall a,b,c \in S$ then we say that is an associative law.

If $*$ holds that $a*b=b*a \quad \forall a,b \in S$ we say that is a commutative law.

Semigroups

Let $S$ be a set and $*$ be a composition law on $S$, if $*$ is associative then $(S,*)$ is a semigroup.

Monoids

Let $(S,*)$ be a semigroup if $S$ has an identity element $e$ such that:

$\forall x \in S$ $x*e = x = e*x$,

then $(S,*)$ is a Monoid.

Groups

Let $(S,*)$ be a Monoid if:

$\forall x \in S$ $\exists x^{-1} \in S$ s.t. $x*x^{-1} = e = x^{-1}*x$,

then $(S,*)$ is a Group.

if $*$ is commutative then $(S,*)$ is a commutative or Abelian group.

Subgroups

Let $(G,*)$ be a group, if a proper subset $H$ of $G$ is also a group with $*$ then $H$ is a subgroup of $G$

Theorem

If $(G,*)$ is a group and $H$ is a nonempty subset of $G$:

$(H,*)$ is a subgroup of $(G,*)$ if and only if $a*b^{-1} \in H \quad \forall a,b \in H$

Relation

Let $A$ and $B$ be sets and $R$ a map from $A$ to $B$ s.t.:

$R : A \rightarrow B$
with $a\in A$ and $b=R(a) \in B$ and
$(a,b) = (a,R(a)) \in A \times B$
for seek of simplicity we write $(a,R(a)) \in A \times B$ as $aRb$.

Equivalence Relations

Let $S$ be a set and $R$ a relation in $S \times S$, if:

i) $aRa \quad \forall a \in S$ (Reflexive)

ii) $aRb \implies bRa$ (Symmetric)

iii) $aRb \wedge bRc \implies aRc$ (Transitive)

then $R$ is an Equivalence Relation on $S$. (When we speak of an equivalence relation we'll use the symbol $=$)

Partial Order Relations

A partial order relation is a relation $R$ in a set $S$ with a equivalence relation $=$ if $R$ is reflexive and transitive and:

$aRb \wedge bRa \implies a=b$ (antisymmetric)

We write a partial order relation as $\leq$. The above oreder is a non-strict relation.

A strict partial relation order $R$ in $S$ is:

i) $a\not R a \quad \forall a \in S$ (irreflexive)

ii) $aRb \wedge bRa \implies a=b$ (antisymmetric)

iii) $aRb \wedge bRc \implies aRc$ (Transitive)

We write a strict partial order relation as $<$.

Complete Order Relations

The above partial relations don't hold $\forall a,b \in S$, if they do then the order is a complete order.

Congruence Relation

Let $(G,*)$ be a Monoid, if a equivalence relation $=$ on $G$ also holds that:

$a_1=a_2 \wedge b_1 = b_2 \implies a_1*b_1 = a_2*b_2$,

then $=$ is also congruence relation.

Equivalence Classes

Let $S$ be a set with an equivalence relations $=$, the equivalence class $\bar{a}$ (or $[a]$) of an element $a \in S$ is:

$\bar{a} = \{ x \in S | x = a \}$

The class of all the equivalence classes on $S$ is denoted as $(S/=)$, and is called the quotient class of $S$ by $=$.

The union of all the equivalence classes is $S$, i.e.

$\bigcup_{a \in S} \bar{a} = A = \bigcup_{\bar{a} \in (S/=)} \bar{a}$ or $\bar{a} = \bar{b}$

If $a,b \in S$ either $\bar{a} \cap \bar{b} = \emptyset$

Theorem:
Let $(G,*)$ be a Monoid and $=$ a congruence relation on $G$, then:

$((G/=), *)$ is a Monoid with

$* : (G/=) \times (G/=) \rightarrow (G/=)$ and $[a]*[b] = [a*b] \quad [a],[b] \in G/=$ (sorry for the change on notation but the bar don't expand enough in the a*b)

If $(G,*)$ is Abelian then $(G/=,*)$ is Abelian too.

Group Homomorphism

Let $(G,\circ)$ and $(H,\diamond)$ be two groups and a function $f : G \rightarrow H$ such that:

$f(x \circ y ) = f(x) \diamond f(y) \quad \forall x,y \in G$,

then $f$ is a Group homomorphism.

If $f$ is injective then $f$ is a Group Monomorphism.

If $f$ is surjective then $f$ is a Group Epimorphism.

If $f$ is bijective then $f$ is a Group Isomorphism.

If a Group Homomorphism is $f: G \rightarrow G$ then $f$ is a Group Endomorphism of $G$.

If a Group Isomorphism is $f: G \rightarrow G$ then $f$ is a Group Automorphism of $G$.

Kernel

Let $(G,\circ)$ and $(H,\diamond)$ be two groups and a homomorphism $f : G \rightarrow H$. $e_G$ and $e_H$ are the ideintity element of each group, then, the kernel of $f$ is:

$Ker f = \{a \in G | f(a) = e_H\}$,

The kernel is a subset of $G$ that maps to the identity element on $H$ with the homomorphism $f$.

Theorem:
If $f : G \rightarrow H$ is a monomorphism $\Longleftrightarrow$ $Ker f = \{e_G\}$

Theorem:
If $f : G \rightarrow H$ is a isomorphism $\Longleftrightarrow$ $f^{-1} : H \rightarrow G$ is a homomorphism and $f(f^{-1}(a)) = a \quad \forall a \in H$ and $f^{-1}(f(a)) = a \quad \forall a \in G$

Cyclic groups

Let $(G,*)$ be a group and $X$ a subset of $G$.

Let $\{ H_i | i \in I \}$ be the family of all the subgroups ($H_i$) of $G$ that contains $X$ i.e. $X \subset H_i \forall i \in I$

$\bigcap_{i \in I} H_i$ is a subgroup of $G$ generated by $X$ and denoted $\langle X\rangle$

The elements of $X$ are the generators of $\langle X\rangle$.

Several different subsets on $G$ can generate the same $\langle X\rangle$, so, in general $\langle X\rangle = \langle Y \rangle$ with $X \neq Y$.

If $X$ is a finite set such that $X = \{a_1, a_2, \cdots , a_n \}$, we write $\langle a_1, a_2, \cdots, a_n \rangle$ instead of $\langle X\rangle$.

If $G = \langle a_1,a_2, \cdots, a_n \rangle$ with $a_i \in G$, then $G$ is said to be finitely generated.

If $a \in G$, then the subgroup $\langle a\rangle$ is the Cyclic Group or Cyclic Subgroup generaterd by a.

Theorem

Let $(G,*)$ be a group and $X$ a nonempty subset of $G$, then the subgroup $\langle X \rangle$ generated by $X$ consists of all finite products $a_1^{n_1}a_2^{n_2}\cdots a_1t^{n_t} \quad a_i \in X; \quad n_i \in \mathbb{Z}$.

And $\forall a \in G, \langle a \rangle = \{ a^n | n \in \mathbb{Z}\}$

Theorem

Let $H$ be a cycli subgroup of $(\mathbb{Z},+)$, either $H=\langle 0 \rangle$ or $H=\langle m \rangle$, with $m$ the least positive integer in $H$, then if $H \neq \langle 0 \rangle$, then $H$ is infinite.

Theorem

Every infinite cyclic group is isomorphic to $(\mathbb{Z},+)$ and every finite cyclic group of order $m$ is isomorphic to $(\mathbb{Z}_m,+)$ (¿¿¿$\langle m \rangle$???).

Cosets

First we define that $a \equiv b (mod m) \Longleftrightarrow m | a - b \Longleftrightarrow a-b \in \langle m \rangle$.

Let $(G,*)$ be a group, and $(H,*)$ a subgroup of $(G,*)$ and $a,b \in G$.

a is right congruent to $b$ modulo $H$, denoted as $a \equiv_r b (mod H)$ if $a*b^{-1} \in H$.

a is left congruent to $b$ modulo $H$, denoted as $a \equiv_l b (mod H)$ if $a^{-1}*b \in H$.

If $G$ is abelian then if one of the congruencies hold then the other does:

$a*b^{-1} \in H \Longleftrightarrow (a*b^{-1})^{-1} \in H$

$(a*b^{-1})^{-1} = b*a^{-1} = a^{-1}*b$

and

$a^{-1}*b \in H \Longleftrightarrow (a^{-1}*b)^{-1} \in H$

$(a^{-1}*b)^{-1} = b^{-1}*a = a*b^{-1}$

Theorem

Let $(H,*)$ be a subgroup of $(G,*)$, then

i) Right(Left) congruence modulo $H$ is an equivalence relation on $G$.

ii) The equivalence class of $a \in G$ with the right (left) congruence is the set $Ha = \{h*a | h \in H\} ($aH = \{a*h | h \in H\})

iii) $|Ha| = |H| = |aH| \quad \forall a \in G$

$Ha$ is called a right coset of $H$ in $G$.
$aH$ is called a left coset of $H$ in $G$.


Corollary

i) $G$ is the union of the right(left) cosets of $H$ on $G$.

ii) Two right(left) cosets of $H$ on $G$ are either disjoint or equal.

iii) $\forall a,b \in G, \quad Ha = Hb \Longleftrightarrow a*b^{-1} \in H$ and $aH = bH \Longleftrightarrow a^{-1}*b \in H$

iv) If $R$ is the set of distinct right(left) cosets of $H$ in $G$, and $L$ is the set of distinct left cosets of $H$ in $G$, then

Definition

Let $(G,*)$ be a group, and $(H,*)$ a subgroup of $(G,*)$ the index of $H$ in $G$, denoted as $[G : H]$ is the cardinal number of the set of distinct right(left) cosets. of $H$ in $G$.

Saturday, August 22, 2009

Runge Kutta in Haskell

Well, Runge-Kutta is a better solver that Euler so:


-- Runge-Kutta method (t_o, t_f,h, x_o, function(t,x))
runge t_o t_f h x_o f = case t_o < t_f of
True ->
do
let k_1 = f t_o x_o
let k_2 = f (t_o + h/2) (x_o + h * k_1 / 2)
let k_3 = f (t_o + h/2) (x_o + h * k_2 / 2)
let k_4 = f (t_o + h) (x_o + h * k_3)
[(t_o,x_o)] ++ ( runge (t_o + h) t_f h (x_o + h * (k_1 + 2*k_2 + 2*k_3 + k_4) / 6) f)
False ->
[]


-- Function
f :: Double -> Double -> Double
f t x = - x

-- Print in column
show_col :: [(Double, Double)] -> String
show_col x = case x of
(a:b) ->
do
let (t, v) = a
(show t) ++ " , " ++ (show v) ++ "\n" ++ (show_col b)
[] ->
""

main = putStrLn(show_col(runge 0 5 0.01 10 f))

Friday, August 21, 2009

Euler Method in Haskell

I decide today to learn haskell, but i can't get out of my head how could it be used in simulation, so, i will try with several basic solvers, starting with Euler Method to solve: y'(t) = f(t, y(t))


--Euler method (t_o, t_f,h, x_o, function(t,x))
euler1 :: Double -> Double -> Double -> Double -> (Double -> Double -> Double) -> [(Double, Double)]
euler1 t_o t_f h x_o f = case t_o < t_f of
True ->
[(t_o,x_o)] ++ (euler1 (t_o+h) t_f h (x_o+(h * f t_o x_o)) f)
False ->
[]



--Euler method (t_o, t_f,steps, x_o, function(t,x))
euler2 :: Double -> Double -> Integer -> Double -> (Double -> Double -> Double) -> [(Double, Double)]
euler2 t_o t_f steps x_o f = case steps > 0 of
True ->
do
let h = (t_f - t_o) / (fromIntegral steps)
[(t_o, x_o)] ++ euler2 (t_o + h) t_f (steps - 1) (x_o + (h * f t_o x_o)) f
False ->
[]



-- Function
f :: Double -> Double -> Double
f t x = - x

-- Print in column
show_col :: [(Double, Double)] -> String
show_col x = case x of
(a:b) ->
do
let (t, v) = a
(show t) ++ " , " ++ (show v) ++ "\n" ++ (show_col b)
[] ->
""

--main = putStrLn(show_col(euler1 0 1 0.00001 10 f))
main = putStrLn(show_col(euler2 0 1 100000 10 f))

Thursday, August 13, 2009

Qucs

Mmmm, Creo que por fin encontre un buen programa para simular circuitos, trabaja con SPICE y ademas es libre.

http://qucs.sourceforge.net/
http://qucs.sourceforge.net/docs.html
http://qucs.sourceforge.net/download.html

Wednesday, August 12, 2009

Symbolic Integration (Manuel Bronstein)

Well, now that i have a new book, Symbolic Integration I of Manuel Bronstein, i will implement some of the code examples on the initial chapter: polydivide, euclidean algorithm, square free factorization, all of them using GiNaC library.

PolyDivide

This one find the unique q and r in a field K[z] that holds a = b*q + r


lst PolyDivide(ex A, ex B, symbol x)
{
ex Q = 0;
ex R = A;

int d = R.degree(x) - B.degree(x);

while ((not R.is_zero()) and (d >=0))
{
ex T = R.lcoeff(x) / B.lcoeff(x) * pow(x,d);
Q = expand(Q + T);
R = expand(R - B*T);
d = R.degree(x) - B.degree(x);
}
return lst(Q,R);
}


PolyPseudoDivide
Same that last, but in a integral domain, like Z.


lst PolyPseudoDivide(ex A, ex B, symbol x)
{
ex b = B.lcoeff(x);
int N = A.degree(x) - B.degree(x) + 1;
ex Q = 0;
ex R = A;

int d = R.degree(x) - B.degree(x);

while ((not R.is_zero()) and (d >=0))
{
ex T = R.lcoeff(x) * pow(x,d);
N -= 1;
Q = expand(b * Q + T);
R = expand(b * R - T * B);
d = R.degree(x) - B.degree(x);
}

b = pow(b, N);
return lst( b * Q, b * R);
}


Well, testing both algorithm against the quo and rem that do the same computation in GiNaC, we have this:



The test is a division between two polynomials of the same n degree randomly generated, in x-axis is n and in y-axis is ellapsed time of the compute code in sec.


int main()
{
symbol x("x");
int i = 0;
ex a=0, b=0;

clock_t s, e;
double t1,t2, t3, t4, t5;

for(int n = 1; n < 100000 ; n += 1000)
{
srand ( time(NULL) );

for(; i < n; i++)
{
a += (rand() % 200 - 100) * pow(x,i);
b += (rand() % 200 - 100) * pow(x,i);
}

s = clock();
PolyDivide(a,b,x);
e = clock();
t1 = (e-s);

s = clock();
PolyPseudoDivide(a,b,x);
e = clock();
t2 = (e-s);

s = clock();
quo(a,b,x); rem(a,b,x);
e = clock();
t3 = (e-s);

ex q;
s = clock();
q = quo(a,b,x);a - b*q;
e = clock();
t4 = (e-s);

ex r;
s = clock();
r = rem(a,b,x);(a-r)/b;
e = clock();
t5 = (e-s);


t1 /= CLOCKS_PER_SEC;
t2 /= CLOCKS_PER_SEC;
t3 /= CLOCKS_PER_SEC;
t4 /= CLOCKS_PER_SEC;
t5 /= CLOCKS_PER_SEC;

cout << n << " " << t1 << " " << t2 << " " << t3 << " " << t4 << " " << t5 << endl;
}

return 0;
}