"Que buen idioma el mío, qué buena lengua heredamos de los conquistadores torvos..Éstos andaban a zancadas por las tremendas cordilleras, por las Américas encrespadas buscando patatas, butifarras, frijolitos, tabaco negro, oro, maíz, huevos fritos, con aquel apetito voraz que nunca más se ha visto en el mundo...Todo se lo tragaban, con religiones, pirámides, tribus, idolatrías iguales a las que ellos traían en sus grandes bolsas...Por donde pasaban quedaba arrasada la tierra...Pero a los bárbaros se les caían de las botas, de las barbas, de los yelmos, de las herraduras, como piedrecitas las palabras luminosas que se quedaron aquí resplandecientes...el idioma. Salimos perdiendo...Salimos ganando...Se llevaron el oro y nos dejaron el oro...Se lo llevaron todo y nos dejaron todo...Nos dejaron las palabras.”
Pablo Neruda
Monday, April 18, 2011
Monday, September 27, 2010
Introducción al psicoanalisis.
Ultimamente me he estado leyendo "Introducción al psicoanalisis", intentare plasmar aqui un poco lo que he aprendido y tambien las dudas que me ha traido esta lectura.
Primero que todo el Psicoanalisis según Freud es un tratramiento para tratar neurosis, es decir enfermedades psiquicas. Se basa en el lenguaje entre el paciente y el psicoanalista. Es método cientifico, y como tal debe pararse en los pilares de este (aunque en ocasiones me parece que cojea).
El primer tema a tratar son los actos fallidos. Los actos fallidos son una serie de equivocaciones que son normalmente pasables, como olvidar un nombre, cambiar una palabra por otra, mezclarlas, perder objetos. Son separadas ppalmente en: Equivocaciones orales, equivocaciones escritas, de aprehension, olvidos de compromisos o nombres, olvido de objetos.
La mas tratada es la equivocacion oral. En esta el psicoanalisis propone una explicacion en la cual intervienen dos tendencias, una perturbada y otra perturbadora. La perturbada es la tendencia natural de construccion del discurso, en la cual el sujeto pone su energia, la tendencia perturbadora es aquella que modifica el discurso sin ser advertida por el sujeto. Una cita buena al filosofo Wundt es que en estas ocasiones el poder del discurso es vencido por el poder de la asociacion. Para esta explicacion Freud trae una serie de ejemplos, uno que me causo mucho interes es el de un personaje que tiene por encargo abrir una sesión, pero en el acto dice "Se levanta la sesión", cuando deberia decir: "Se abre la sesión". En el cerebro del sujeto ocurrio algo que le hace modificar el discurso, y cambiar la palabra abrir, por levantar. Inicialmente la explicacion de Freud es que "claramente" la unica interpretacion posible es que el personaje no queria abrir la sesión, y que "cualquier otra explicacion resulta ser superflua" (condenar al fracaso un argumento en contra no parece ser muy acorde al metodo cientifico). Otro caso, es el de un amigo de Freud que tenia un perro enfermo, en este caso el amigo le comenta que "drurara asi un mes mas", a lo cual Freud lo corrige y el amigo responde diciendo que pensaba decir "tristemente durara así un mes", pero combino las palabras.
En esencia todas estas equivocaciones tienen una tendencia original y otra que tiende a perturbarla, la cual suele ser una tendencia escondida y toca analisar al sujeto para encontrar y explicar el porque de la equivocacion.
Primero que todo el Psicoanalisis según Freud es un tratramiento para tratar neurosis, es decir enfermedades psiquicas. Se basa en el lenguaje entre el paciente y el psicoanalista. Es método cientifico, y como tal debe pararse en los pilares de este (aunque en ocasiones me parece que cojea).
El primer tema a tratar son los actos fallidos. Los actos fallidos son una serie de equivocaciones que son normalmente pasables, como olvidar un nombre, cambiar una palabra por otra, mezclarlas, perder objetos. Son separadas ppalmente en: Equivocaciones orales, equivocaciones escritas, de aprehension, olvidos de compromisos o nombres, olvido de objetos.
La mas tratada es la equivocacion oral. En esta el psicoanalisis propone una explicacion en la cual intervienen dos tendencias, una perturbada y otra perturbadora. La perturbada es la tendencia natural de construccion del discurso, en la cual el sujeto pone su energia, la tendencia perturbadora es aquella que modifica el discurso sin ser advertida por el sujeto. Una cita buena al filosofo Wundt es que en estas ocasiones el poder del discurso es vencido por el poder de la asociacion. Para esta explicacion Freud trae una serie de ejemplos, uno que me causo mucho interes es el de un personaje que tiene por encargo abrir una sesión, pero en el acto dice "Se levanta la sesión", cuando deberia decir: "Se abre la sesión". En el cerebro del sujeto ocurrio algo que le hace modificar el discurso, y cambiar la palabra abrir, por levantar. Inicialmente la explicacion de Freud es que "claramente" la unica interpretacion posible es que el personaje no queria abrir la sesión, y que "cualquier otra explicacion resulta ser superflua" (condenar al fracaso un argumento en contra no parece ser muy acorde al metodo cientifico). Otro caso, es el de un amigo de Freud que tenia un perro enfermo, en este caso el amigo le comenta que "drurara asi un mes mas", a lo cual Freud lo corrige y el amigo responde diciendo que pensaba decir "tristemente durara así un mes", pero combino las palabras.
En esencia todas estas equivocaciones tienen una tendencia original y otra que tiende a perturbarla, la cual suele ser una tendencia escondida y toca analisar al sujeto para encontrar y explicar el porque de la equivocacion.
Django nonrel + MongoDB.
I want to setup a basic virtualenv environment with a working version of django-nonrel with MongoDB.
From http://www.allbuttonspressed.com/projects/django-nonrel we can read a blog entry that explains everything about the integration: http://www.allbuttonspressed.com/blog/django/2010/05/MongoDB-backend-for-Django-nonrel-released
With requirements.txt:
Type:
Define your database as:
Pretty easy.
From http://www.allbuttonspressed.com/projects/django-nonrel we can read a blog entry that explains everything about the integration: http://www.allbuttonspressed.com/blog/django/2010/05/MongoDB-backend-for-Django-nonrel-released
With requirements.txt:
pymongo
-e git+http://github.com/aparo/django-mongodb-engine.git#egg=django_mongodb_engine
-e hg+http://bitbucket.org/wkornewald/django-nonrel#egg=Django
-e hg+http://bitbucket.org/wkornewald/djangotoolbox#egg=djangotoolbox
Type:
aptitude install python-pip
pip install virtualenv
virtualenv --no-site-packages --distribute nonrel
cd norel
. bin/activate
pip -r ../requirements.txt
bin/django-admin.py startproject myproject
Define your database as:
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine.mongodb',
'NAME': 'test',
'USER': 'test',
'PASSWORD': 'test',
'HOST': 'flame.mongohq.com',
'PORT': 99999,
'SUPPORTS_TRANSACTIONS': False,
}
}
Pretty easy.
Friday, July 02, 2010
Identity, Authentication, Authorization and Multitenancy
There it should somewhere in the web an application to correctly build a Django site with those concepts.
Saturday, June 05, 2010
Un poco de genealogia.
Ayer en un bar un personaje dijo, hablando de Juan Manuel Santos: "No solo nos roban la plata sino tambien la opinion", me surgio la duda de conocer bien las relaciones familiares de los Santos.
Eduardo Santos Montejo (Presidente de Colombia 1938-1942) hermano de Enrique Santos Montejo, este ultimo padre de Enrique Santos Castillo y Hernando Santos Castillos. Tambien es hijo Enrique Santos Molano, con una tal Blanca Molano, de la cual poco encuentro.
Ahora, Enrique Santos Castillo y Hernando Santos Castillo se casaron con dos hermanas de apellido Calderon, y fueron traidas al mundo cuatro criaturas: Juan Manuel Santos Calderon(ex-ministro de Defensa) y Enrique Santos Calderon (director de El Tiempo hasta el 2009) son hijos de Enrique Santos Calderon. Francisco Santos Calderon (Vicepresidente) y Rafael Santos Castillo (director de El Tiempo hasta el 2009) hijos de Hernando Santos Castillo.
Encontre un documento en: http://www.interconexioncolombia.com/documentos/genealogia/que%20esta%20pasando%20en%20colombia/Los%20Santos%20y%20los%20Lopez%20nos%20gobiernan%20desde%201930.pdf
En donde se pueden ver diagramas de Genealogias, es interesante ver en un solo diagrama nombres como: Alvaro Uribe Velez, Jose Obdulio Gaviria, Pablo Escobar Gaviria, Fabio Ochoa, Noemi Sanin.
Basicamente el documento relaciona a todos los actores de este gran teatro llamado Colombia.
Como dicen por ahi: Todo queda en Familia.
Eduardo Santos Montejo (Presidente de Colombia 1938-1942) hermano de Enrique Santos Montejo, este ultimo padre de Enrique Santos Castillo y Hernando Santos Castillos. Tambien es hijo Enrique Santos Molano, con una tal Blanca Molano, de la cual poco encuentro.
Ahora, Enrique Santos Castillo y Hernando Santos Castillo se casaron con dos hermanas de apellido Calderon, y fueron traidas al mundo cuatro criaturas: Juan Manuel Santos Calderon(ex-ministro de Defensa) y Enrique Santos Calderon (director de El Tiempo hasta el 2009) son hijos de Enrique Santos Calderon. Francisco Santos Calderon (Vicepresidente) y Rafael Santos Castillo (director de El Tiempo hasta el 2009) hijos de Hernando Santos Castillo.
Encontre un documento en: http://www.interconexioncolombia.com/documentos/genealogia/que%20esta%20pasando%20en%20colombia/Los%20Santos%20y%20los%20Lopez%20nos%20gobiernan%20desde%201930.pdf
En donde se pueden ver diagramas de Genealogias, es interesante ver en un solo diagrama nombres como: Alvaro Uribe Velez, Jose Obdulio Gaviria, Pablo Escobar Gaviria, Fabio Ochoa, Noemi Sanin.
Basicamente el documento relaciona a todos los actores de este gran teatro llamado Colombia.
Como dicen por ahi: Todo queda en Familia.
Sunday, April 11, 2010
Thursday, March 25, 2010
Antanas Mockus Presidente de Colombia 2010 - 2014
En este pequeño espacio posiblemente con pocas visitas intentare ayudar a una justa causa por mi país.
Partido Verde.
Partido Verde.
Sunday, January 31, 2010
Latex + Inline spell check
Well, after 3 days of trying to activate a good inline spell check on Kile, which is impossible right now, and after trying to compile the hello world plugin for Kate to create a plugin that highlight that misspelled words, which is almost impossible too because of some mistakes on the example, and trying to use emacs for latex + flyspell (it works, but is not very nice), I found that Gedit with its plugin for latex is now really great and has inline spell check!!!, also it list all the structure of the document in a side panel, and has more features, and the best is that is a Gnome app.
http://projects.gnome.org/gedit/
http://live.gnome.org/Gedit/LaTeXPlugin
http://projects.gnome.org/gedit/
http://live.gnome.org/Gedit/LaTeXPlugin
Monday, January 04, 2010
I love my Linux Kernel.
Well, I just love it.
Right now I'm working in a driver for a couple of circuits with a DAC, ADC and a encoder to connect my old Gumstix Connex to a PLC Unitronics, and two Variable speed driver Altivar ATV31.
The driver basically read through SPI the data that the ADC get from a current loop. And through SPI the resulting data is send to the drivers. The encoder work with three GPIO interrupt.
I'll try to write later on this. For now, a couple of pages that are really helpful:
http://www.linuxjournal.com/article/5833
http://tomoyo.sourceforge.jp/cgi-bin/lxr/source/
http://www.linuxgrill.com/anonymous/fire/netfilter/kernel-hacking-HOWTO-5.html
http://people.nl.linux.org/ftp/pub/anoncvs/kernelnewbies/documents/kdoc/kernel-api/adt.html#AEN475
http://docs.huihoo.com/linux/kernel/2.6.26/kernel-api/ch25.html
http://docwiki.gumstix.org/index.php/Robostix_spi.c
http://www.makelinux.net/ldd3/ (The chapters with locking techniques, procfs, and deferred work are great!!!)
http://tldp.org/LDP/lkmpg/2.6/html/x1256.html
Right now I'm working in a driver for a couple of circuits with a DAC, ADC and a encoder to connect my old Gumstix Connex to a PLC Unitronics, and two Variable speed driver Altivar ATV31.
The driver basically read through SPI the data that the ADC get from a current loop. And through SPI the resulting data is send to the drivers. The encoder work with three GPIO interrupt.
I'll try to write later on this. For now, a couple of pages that are really helpful:
http://www.linuxjournal.com/article/5833
http://tomoyo.sourceforge.jp/cgi-bin/lxr/source/
http://www.linuxgrill.com/anonymous/fire/netfilter/kernel-hacking-HOWTO-5.html
http://people.nl.linux.org/ftp/pub/anoncvs/kernelnewbies/documents/kdoc/kernel-api/adt.html#AEN475
http://docs.huihoo.com/linux/kernel/2.6.26/kernel-api/ch25.html
http://docwiki.gumstix.org/index.php/Robostix_spi.c
http://www.makelinux.net/ldd3/ (The chapters with locking techniques, procfs, and deferred work are great!!!)
http://tldp.org/LDP/lkmpg/2.6/html/x1256.html
Monday, December 28, 2009
Corrupted Git
Well, I have a directory with all my undergraduate project and I use git to ease my work, but recently I was not able to create a backup in a external disk because a error:
I have files of almost 500MB on this repo, I suppose that the problem. I try to repack but it was useless, I also can check the hash of the object (with fsck), but I can't find where is that file, or what commit it belongs to.
This code will help in this case:
It works (al least for my problem!!!), and now i want to rebase master:
That's all.
remote: Counting objects: 313, done.
remote: Compressing objects: 100% (116/116), done.
fatal: pack has bad object at offset 11893474: inflate returned 1
fatal: index-pack failed
I have files of almost 500MB on this repo, I suppose that the problem. I try to repack but it was useless, I also can check the hash of the object (with fsck), but I can't find where is that file, or what commit it belongs to.
This code will help in this case:
git checkout master
git branch new_master
git checkout new_master
for i in $!$(seq 1 100); do git checkout new_master~$!$i || break; done
for j in $!$(seq $!$i 100); do git checkout new_master~$!$j && break; done
# The error is between new_master~$!$j and new_master~($!$i-2)
git checkout master
git branch -D new_master
git branch new_master
git checkout new_master
git rebase --onto new_master~$!$j new_master~$!$((i-2)) new_master
It works (al least for my problem!!!), and now i want to rebase master:
git checkout master
git rebase new_master
git branch -d new_master
That's all.
Thursday, December 03, 2009
Compute the normal vector of a hyperplane in $R^n$
Well, basically any vector $N$ that holds $N \dot (p_i - p_j) = 0$ for for any vector $p_i, p_j \in H$ $H$ is the hyperplane.
Only $n$ different points are needed, call $P$ the set of $n$ points in $H$, and define $P^* = \{ p^*_i = p_i - p_{i+1} : p_i,p_{i+1} \in H , i \in [1,n-1]\}$.
$P^*$ is the set of vectors on $H$.
Any normal vector $N$ that holds that $N \dot p^*_i , i \in [1,n-1]$ is a normal vector.
$N$ has $n$ components, so we got here $n$ unknowns. And with the $n_1$ $p^*_i$ vectors we got $n-1$ equations.
An extra equation could be defined if we want a normalized vector, but this add a quadratic term in the systems, as the vector with all zero components can't be a normal vector of any hyperplane at least one of its components has a non-zero value, suppose that the $j$ component of $N$ has value $1$. and we have then a Ax = B, with n-1 equations and unknowns. we just have to try which j makes the systm non singular and solve it.
The system of equations:
$\begin{pmatrix}
p^*_{1,1} & p^*_{1,2} & \cdots & p^*_{1,j-1} & p^*_{1,j+1} & \cdots & p^*_{1,n} \\ p^*_{2,1} & p^*_{2,2} & \cdots & p^*_{2,j-1} & p^*_{2,j+1} & \cdots & p^*_{2,n} \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\
p^*_{n,1} & p^*_{n,2} & \cdots & p^*_{n,j-1} & p^*_{n,j+1} & \cdots & p^*_{n,n} \\
\end{pmatrix} \begin{pmatrix} N_1 \\ N_2 \\ \vdots \\ N_{j-1} \\ N_{j+1} \\ \vdots \\ N_n \end{pmatrix} = - \begin{pmatrix} p^*_{1,j} \\ p^*_{2,j} \\ \vdots \\ p^*_{(j-1),j} \\ p^*_{(j-1),j} \\ \vdots \\ p^*_{n,j} \end{pmatrix}
$
Start checking for $j \in [1,n]$ and you will get at much $n$ and at least 1 normal vector.
Python:
Only $n$ different points are needed, call $P$ the set of $n$ points in $H$, and define $P^* = \{ p^*_i = p_i - p_{i+1} : p_i,p_{i+1} \in H , i \in [1,n-1]\}$.
$P^*$ is the set of vectors on $H$.
Any normal vector $N$ that holds that $N \dot p^*_i , i \in [1,n-1]$ is a normal vector.
$N$ has $n$ components, so we got here $n$ unknowns. And with the $n_1$ $p^*_i$ vectors we got $n-1$ equations.
An extra equation could be defined if we want a normalized vector, but this add a quadratic term in the systems, as the vector with all zero components can't be a normal vector of any hyperplane at least one of its components has a non-zero value, suppose that the $j$ component of $N$ has value $1$. and we have then a Ax = B, with n-1 equations and unknowns. we just have to try which j makes the systm non singular and solve it.
The system of equations:
$\begin{pmatrix}
p^*_{1,1} & p^*_{1,2} & \cdots & p^*_{1,j-1} & p^*_{1,j+1} & \cdots & p^*_{1,n} \\ p^*_{2,1} & p^*_{2,2} & \cdots & p^*_{2,j-1} & p^*_{2,j+1} & \cdots & p^*_{2,n} \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\
p^*_{n,1} & p^*_{n,2} & \cdots & p^*_{n,j-1} & p^*_{n,j+1} & \cdots & p^*_{n,n} \\
\end{pmatrix} \begin{pmatrix} N_1 \\ N_2 \\ \vdots \\ N_{j-1} \\ N_{j+1} \\ \vdots \\ N_n \end{pmatrix} = - \begin{pmatrix} p^*_{1,j} \\ p^*_{2,j} \\ \vdots \\ p^*_{(j-1),j} \\ p^*_{(j-1),j} \\ \vdots \\ p^*_{n,j} \end{pmatrix}
$
Start checking for $j \in [1,n]$ and you will get at much $n$ and at least 1 normal vector.
Python:
from numpy import array, dot
from numpy.linalg import solve, norm
def normal(P):
n = len(P)
if n < 1:
raise Exception, "O-size list."
m = len(P[0])
if array([len(p) != m for p in P]).any():
raise Exception, "Inconsistent set of points."
if n != m:
raise Exception
P_ = [p-q for p,q in zip(P[:-1],P[1:])]
N = []
for i in range(n):
try:
x = solve(
array([list(p)[:i] + list(p)[i+1:] for p in P_]),
array([-p[i] for p in P_])
)
x = array(list(x)[:i] + [1] + list(x)[i:])
N.append(x)
except:
pass
n = N[array([(dot(n,n)-1)**2 for n in N]).argmin()]
return n / norm(n)
if __name__ == '__main__':
print normal([array([1,0,0]), array([0,1,0]), array([1,1,0])])
print normal([array([1,123,0123]), array([0345,1,034]), array([132,134,034])])
print normal([array([1,0,0]), array([0,1,0]), array([1,123,1123])])
I'm gonna create a image with Debian and Django to upload it to AWS.
dd if=/dev/zero of=debian-ami count=1000 bs=1m
sudo mkfs.ext3 -F debian-ami
mkdir /tmp/chroot
sudo mount -o loop debian-ami /tmp/chroot
sudo debootstrap --arch i386 lenny /tmp/chroot/ http://ftp.debian.org
sudo chroot /tmp/chroot/
# Inside the chroot
mount -t proc none /proc
cd /dev
MAKEDEV console
MAKEDEV std
echo -e 'auto lo\niface lo inet loopback\nauto eth0\niface eth0 inet dhcp' >> /etc/network/interfaces
echo -e 'proc /proc proc defaults 0 0\n/dev/sda1 / reiserfs defaults 0 1\n/dev/sda2 swap swap defaults 0 0' > /etc/fstab
aptitude update
aptitude install locales-all
aptitude install ssh
exit
# In your machine
sudo umount -l /tmp/chroot
export EC2_PRIVATE_KEY=xxxxxxx.pem
export EC2_CERT=xxxxxxxxxxxxxxxxxx.pem
export EC2_ACCNO=xxxxxxxxxx
export ACCESS_KEY=xxxxxxxxxxxxxxxx
export SECRET_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ec2-bundle-image -i debian-ami --cert EC2_CERT --privatekey EC2_PRIVATE_KEY -u EC2_ACCNO
ec2-upload-bundle -b 20091203-linux-debian-lenny -m /tmp/debian-ami.manifest.xml -a ACCESS_KEY -s SECRET_KEY
ec2-register -n 20091203-linux-debian-lenny 20091203-linux-debian-lenny/debian-ami.manifest.xml
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$.
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
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
PolyPseudoDivide
Same that last, but in a integral domain, like Z.
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.
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;
}
Wednesday, July 22, 2009
Create a new toolbox for Scilab (II)
Now i gonna follow the instructions at: http://www.scilab.org/contrib/index_contrib.php?page=toolbox_guide
1) First i need to create all the files needed to the toolbox:
2) Macros, well, basically i only have one macro at the symbolic module, but i gonna test the macro at the instructions, so:
3) We're going to create some primitives now, basically is like the module, so, there is a sci_gateway path and a src path, in the first we define the gateways to our functions, and in the second we write the main code of the primitives.
The builder for the primitives, we need a buildsrc.sce and a buildsci_gateway.sce, in the respective path. The first one creates a shared library that is linked to the second shared library (the one of the gateway).
4) The help files are located at the help path with a xml format, and a dtd defined by scilab, we only add a template for the files:
5) Finally we set the global builder and loader:
6) Build it at scilab:
We have then a brand new toolbox enjoy summing.
1) First i need to create all the files needed to the toolbox:
toolbox$ cd scilab/scilab/contrib/
toolbox/scilab/scilab/contrib$ mkdir symbolic
toolbox/scilab/scilab/contrib$ cd symbolic/
toolbox/scilab/scilab/contrib/symbolic$ mkdir macros src sci_gateway help etc unit_tests demos includes
toolbox/scilab/scilab/contrib/symbolic$ touch readme.txt builder.sce loader.sce license.txt
2) Macros, well, basically i only have one macro at the symbolic module, but i gonna test the macro at the instructions, so:
toolbox/scilab/scilab/contrib/symbolic$ cd macros/
toolbox/scilab/scilab/contrib/symbolic/macros$ cat << EOF > foo1.sci
function [X]=foo1(A)
// This function returns the positive components of the A diagonal
// Check the type and the size of A
if type(A)<>1 then
error("type of input argument must be a double");
end
if size(A,1)<>size(A,2) then
error("input argument must be a square matrix");
end
//Extraction of the positive components
X=[];
for i=1:size(A,1)
if A(i,i)>0 then
X($+1)=A(i,i);
end
end
endfunction
EOF
toolbox/scilab/scilab/contrib/symbolic/macros$ cat << EOF > buildmacros.sce
mode(-1)
toolboxname='symbolic'
pathB=get_absolute_file_path('buildmacros.sce')
disp('Building macros in ' +pathB)
genlib(toolboxname+'lib',pathB,%t)
clear pathB genlib toolboxname
EOF
toolbox/scilab/scilab/contrib/symbolic/macros$ cat << EOF > loadmacros.sce
mode(-1)
pathL=get_absolute_file_path('loadmacros.sce')
disp('Loading macros in ' +pathL)
load(pathL+'/lib')
clear pathL
EOF
3) We're going to create some primitives now, basically is like the module, so, there is a sci_gateway path and a src path, in the first we define the gateways to our functions, and in the second we write the main code of the primitives.
toolbox/scilab/scilab/contrib/symbolic$ cd src/
toolbox/scilab/scilab/contrib/symbolic/src$ cat << EOF > vectsum.c
void vectsum(int n, double * a, double * b, double * y)
{
int k;
for (k = 0; k < n; ++k)
y[k] = a[k] + b[k];
}
EOF
jcardona@terminus:~/stuff/personal/symbolic/main/toolbox/scilab/scilab/contrib/symbolic/src$ cd ..
toolbox/scilab/scilab/contrib/symbolic$ cd sci_gateway/
toolbox/scilab/scilab/contrib/symbolic/sci_gateway$ cat << EOF > sci_sumab.c
#include "stack-c.h"
extern int vectsum(int n, double * a, double * b, double * y);
void sci_sumab(char *fname){
int l1, m1, n1, l2, m2, n2, l3, n;
/* 1 - Check the number of inputs/outputs arguments */
int minlhs=1, maxlhs=1, minrhs=2, maxrhs=2;
CheckRhs(minrhs,maxrhs) ;
CheckLhs(minlhs,maxlhs) ;
/* 2 - Check inputs arguments type, and get the size
and the address in the Scilab stack of the inputs
arguments
*/
GetRhsVar(1, "d", &m1, &n1, &l1);
GetRhsVar(2, "d", &m2, &n2, &l2);
/* 3 - Check that the inputs arguments have the same size */
/* it's possible to use the chekdims and getscalar
functions to make these checks
*/
n=m2*n2;
if( n1!=n2 || m1!=m2)
{
cerro("inputs arguments must have the same size");
return 0;
}
if(n1!=0 && m1!=0)
if(n1!=1 && m1!=1)
{
cerro("inputs arguments must be vectors");
return(0);
}
/* 4 - Create a new variable corresponding to the output argument */
CreateVar(3,"d",&m2,&n2,&l3);
/* 5 -call vectsum routine: returns in stk(l3) the sum of a and b*/
vectsum(n,stk(l1),stk(l2),stk(l3));
/* 6 - Specif ouput argument */
LhsVar(1) = 3;
return 0;
}
EOF
The builder for the primitives, we need a buildsrc.sce and a buildsci_gateway.sce, in the respective path. The first one creates a shared library that is linked to the second shared library (the one of the gateway).
toolbox/scilab/scilab/contrib/symbolic/src$ cat << EOF > buildsrc.sce
//ilib_for_link('symbolicsrc',['fun1.o','fun2.o','vectsum.o'],[],"c")
ilib_for_link('symbolicsrc',['vectsum.o'],[],"c")
EOF
toolbox/scilab/scilab/contrib/symbolic/sci_gateway$ cat << EOF >buildsci_gateway.sce
// must be run from this directory
ilib_name = 'libsymbolic' // interface library name
//files = ['sci_fun.o','sci_sumab.o']; // objects files
files = ['sci_sumab.o']; // objects files
libs = ["../src/libsymbolicsrc"] // other libs needed for linking
//table = [ /*'fun', 'sci_fun';*/
table = ['sumab','sci_sumab']; // table of (scilab_name,interface-name)
// do not modify below
ilib_build(ilib_name,table,files,libs)
EOF
4) The help files are located at the help path with a xml format, and a dtd defined by scilab, we only add a template for the files:
toolbox/scilab/scilab/contrib/symbolic/help$ cat << EOF > sumab.xml
<?xml version="1.0" encoding="UTF-8"?>
<refentry version="5.0-subset Scilab" xml:id="sumab" xml:lang="en"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:ns3="http://www.w3.org/1999/xhtml"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:db="http://docbook.org/ns/docbook">
<info>
<pubdate>$LastChangedDate: 2008-03-26 09:50:39 +0100 (mer., 26 mars 2008)$</pubdate>
</info>
<refnamediv>
<refname>sumab</refname>
<refpurpose>Purpose</refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Calling Sequence</title>
<synopsis>sequence</synopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Do something</para>
<para>Add here a paragraph of the function description </para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting role="example">exmaple</programlisting>
</refsection>
<refsection>
<title>Authors</title>
<simplelist type="vert">
<member>YOUR NAME</member>
</simplelist>
</refsection>
</refentry>
EOF
toolbox/scilab/scilab/contrib/symbolic/help$ cat sumab.xml | sed -e 's?sumab?foo1?' > foo1.xml
toolbox/scilab/scilab/contrib/symbolic/help$ cat << EOF > buildhelp.sce
mode(-1) //force silent execution
path=get_absolute_file_path('buildhelp.sce');//get the absolute path of this file
add_help_chapter("Symbolic",path);//add help chapter
xmltohtml(path,"Symbolic")
//clear the variable stack
clear path add_help_chapter get_absolute_file_path
EOF
toolbox/scilab/scilab/contrib/symbolic/help$ cat << EOF > loadhelp.sce
mode(-1) //force silent execution
path=get_absolute_file_path('loadhelp.sce');//get the absolute path of this file
add_help_chapter("Symbolic",path);//add help chapter
clear path add_help_chapter get_absolute_file_
EOF
5) Finally we set the global builder and loader:
toolbox/scilab/scilab/contrib/symbolic$ cat << EOF > builder.sce
mode(-1);
mainpathB=get_absolute_file_path('builder.sce');
chdir(mainpathB);
if isdir('src') then
chdir('src');
exec('buildsrc.sce');
chdir('..');
end
if isdir('sci_gateway') then
chdir('sci_gateway');
exec('buildsci_gateway.sce');
chdir('..');
end
if isdir('macros') then
chdir('macros');
exec('buildmacros.sce');
chdir('..');
end
if isdir('help') then
chdir('help');
exec('buildhelp.sce');
chdir('..');
end
clear mainpathB
EOF
toolbox/scilab/scilab/contrib/symbolic$ cat << EOF > loader.sce
mode(-1);
mainpathL=get_absolute_file_path('loader.sce');
chdir(mainpathL);
if isdir('sci_gateway') then
chdir('sci_gateway');
exec('loader.sce');
chdir('..');
end
if isdir('macros') then
chdir('macros');
exec('loadmacros.sce');
chdir('..');
end
if isdir('help') then
chdir('help');
exec('loadhelp.sce');
chdir('..');
end
clear mainpathL
EOF
6) Build it at scilab:
toolbox/scilab/scilab$ bin/scilab
-->exec("contrib/symbolic/builder.sce")
-->mode(-1);
Generate a loader file
Generate a Makefile
ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
ilib_gen_Make: Copy vectsum.c to TMPDIR
ilib_gen_Make: Modification of the Makefile in TMPDIR.
Running the Makefile
Generate a cleaner file
ans =
libsymbolicsrc.so
ilib_name =
libsymbolic
libs =
../src/libsymbolicsrc
Generate a gateway file
Generate a loader file
Generate a Makefile
ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
ilib_gen_Make: Copy sci_sumab.c to TMPDIR
ilib_gen_Make: Copy libsymbolic.c to TMPDIR
ilib_gen_Make: Modification of the Makefile in TMPDIR.
Running the makefile
Generate a cleaner file
Building macros in /home/jcardona/stuff/personal/symbolic/main/toolbox/scilab/scilab/contrib/symbolic/macros/
Building the master document:
SCI/contrib/symbolic/help
Building the manual file [html] in SCI/contrib/symbolic/help. (Please wait building ... this can take a while)
Warning : redefining function: get_absolute_file_path . Use funcprot(0) to avoid this message
-->exec("contrib/symbolic/loader.sce")
-->mode(-1);
Shared archive loaded.
Link done.
Shared archive loaded.
Link done.
Loading macros in /home/jcardona/stuff/personal/symbolic/main/toolbox/scilab/scilab/contrib/symbolic/macros/
-->sumab(1,2)
ans =
3.
-->sumab(2,2)
ans =
4.
We have then a brand new toolbox enjoy summing.
Etiquetas:
sci_gateway,
scilab,
toolbox
Tuesday, July 21, 2009
Create a new toolbox for Scilab (I)
As i have to change my symbolic module to a symbolic toolbox, i want to write this to use as a future reference.
1) Get Scilab:
2) First compilation:
3) HDF5 Headers:
4) Installing JHDF5 :
5) Configuring again:
Well, we now have our scilab base.
We have to set all the toolboxes files, but that will be tonight.
1) Get Scilab:
$ mkdir toolbox
$ cd toolbox/
toolbox$ git clone git://git.scilab.org/scilab
2) First compilation:
toolbox$ cd scilab/scilab
toolbox/scilab/scilab$ ./configure
...
checking hdf5.h usability... no
checking hdf5.h presence... no
checking for hdf5.h... no
configure: error: Cannot find headers (hdf5.h) of the library HDF5. Please install the dev package
3) HDF5 Headers:
sudo aptitude install libhdf5-serial-dev
4) Installing JHDF5 :
wget http://www.hdfgroup.org/ftp/HDF5/hdf-java/src/hdf-java-2.5-src.tar
tar -xvf hdf-java-2.5-src.tar
cd hdf-java/
./configure --with-jdk=/usr/lib/jvm/java-6-sun-1.6.0.14/include/,/usr/lib/jvm/java-6-sun-1.6.0.14/lib/
make
sudo mkdir -p /usr/share/java/jar
sudo cp lib/jhdf5.jar /usr/share/java/jar
5) Configuring again:
toolbox/scilab/scilab$ ./configure
toolbox/scilab/scilab$ make
toolbox/scilab/scilab$ bin/scilab
Well, we now have our scilab base.
We have to set all the toolboxes files, but that will be tonight.
Wednesday, May 13, 2009
Lock free programming
http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms
http://en.wikipedia.org/wiki/Compare-and-swap
http://www.google.com/search?hl=en&client=iceweasel-a&rls=org.debian%3Aen-US%3Aunofficial&q=lock+free+&btnG=Search
http://en.wikipedia.org/wiki/Compare-and-swap
http://www.google.com/search?hl=en&client=iceweasel-a&rls=org.debian%3Aen-US%3Aunofficial&q=lock+free+&btnG=Search
Subscribe to:
Posts (Atom)