Feeds:
Posts

## Posts Tagged ‘IRC’

Hi everyone, today I start to write a new class for dealing with non-Abelian forms, i.e., forms with values in a certain Lie-algebra. This could be really useful when computing Yang-Mills theories in physics.

So, I started by defining a new object which have two entries, a differential form and a matrix, and call it nAform. The code I wrote was,

class nAform(object):
def __init__(self, a, b):
self._form = a
self._matrix = b
if isinstance(other, nAform):
if (self._matrix == other._matrix):
return nAform(self._form + other._form, self._matrix)
else:
return NotImplemented
return NotImplemented
def __mul__(self, other):
if isinstance(other, nAform):
return nAform(self._form.wedge(other._form), self._matrix.commutator(other._matrix))
return NotImplemented
def diff(self):
return nAform(self._form.diff(), self._matrix)
def __repr__(self):
return str((self._form, self._matrix))
def __str__(self):
return self.__repr__()

## Explanation

One should enter a couple of arguments when defining the nAform object. The __init__ attribute recognize them.

Then an addition attribute is defined, this is incomplete!!!

Another attribute is the multiplication, which take the wedge product of the forms and the commutator of the matrices.

I also implement the exterior derivative on nAform objects.

Finally the __repr__ and __str__ are attributes for returning the data.

## TO-DO

• I couldn’t implement the addition of nAform’s if the matrices are different. As
Nicolas M. Thiery note, this objects should define a Monoid (or something quit close to it). But my programming skills are not so developed.
• It would be great if one could define the multiplication by a constant or function.
• The show attribute is not implemented, but one can show either forms of matrices by themselves… I think that is someone knows how they work, would be easy to do that! ðŸ˜‰
• One could try to implement the simplification attributes on differential forms.
• I don’t remember exactly why I was looking for it, but I think could be useful to define and attribute on forms which show the generator, like .gens(), but for a given differential form, say
sage: x, y, z = var('x, y, z')
sage: U = CoordinatePatch((x, y, z)); U
Open subset of R^3 with coordinates x, y, z
sage: F = DifferentialForms(U); F
Algebra of differential forms in the variables x, y, z
sage: F.gens()
(dx, dy, dz)
sage: F.ngens()
3

I’d like one which do like this,

sage: form1 = DifferentialForm(F, 1); form1.ngens()
3
sage: form1 = DifferentialForm(F, 1); form1.gens()
(dx, dy, dz)
form2 = DifferentialForm(F, 2); form2.ngens()
3
sage: form1 = DifferentialForm(F, 1); form1.gens()
(dx/\dy, dy/\dz, dz/\dx)
• ## Simple SAGE sheet

Worksheet

Hope you can help me with these plenty tasks.

Enjoy!

Dox

As I’ve mention before, actually I’m dealing with some messy supergravity calculations. ðŸ˜› Unlike most of my colleges, I don’t use Mathematica but their open source SAGE (applauses).

# Declaring (weird) Variables

Through the calculations I should care about 10 dimensions, with a 5 dimensional restriction parametrized by Â five different angles, which I call $(\theta,\phi,\bar{\psi},\bar{\theta},\bar{\phi})$… thus, naturally the question of whether a variable can be declared in a way s.t., when using the function show for printing the results, the latex equivalent to my expression is shown, appears!

The answer came a few minutes ago! Thanks to Niels Bruin via sage-devel google group. ðŸ˜‰

sage: var("bps", latex_name=r"\hat{\psi}") bps sage: expr = sin(bps) sage: show(expr)

returns $\sin(\hat{\psi})$. ðŸ˜€

Really neat!!!

# Adding equations in the text

Recently I re-discover the “office”-like functionality of sage notebook. Have you notice the thin blue line that appears when the cursor is about to reach the calculation window by above?

If you click on the blue line, an intermediate calculation line will appear. Whilst, if you click on the line while holding the Shift key, a sort of office suite environment is opened!!!

There you can write in a LibreOffice style!!!

That’s not all. Jason Grout has pointed out to me that one can insert LaTeX equations in this environment just by using the dollar-dollar ($<your code>$) for inline equations, or doubledollar-doubledollar ($$<your code>$$) for centered-nonumbered equations.

Fabulous, Isn’t it?!

That’s all for now! ðŸ˜‰

Enjoy.

DOX

## SAGE tip: rewriting expressions

Today I was calculating some stuff with the help of SAGE, and realize that the expressions got a lot (really, a lot) simpler if they where written in terms of Â hyperbolic functions instead of exponentials.

$e^x = \cosh(x)+\sinh(x)$

$e^{-x} = \cosh(x)-\sinh(x)$

So I enter the sage-devel channel of IRC (freenode), but there was a lazy day around… Sunday. Therefore I decided to write to the sage-dev group on Google groups.

Francois Maltey answer my question on how to do the transformation… He has written a package that does it!

• Go to page http://wiki.sagemath.org/symbolics/rewrite
look at the second line the “attachement” (in smaller characters)
and get the most recent file.
• Then put this file in your Sage directory
In Sage, type : load “/the/good/file/in/the/good/directory’
Then call the rewrite function.
• Thank you Francois

#### Example

Suppose the path to the file is “/home/me/rewrite-xxx.sage”

sage: load "/home/me/rewrite-xxx.sage" sage: A = exp(x) + exp(-x) sage: rewrite(A, 'exp2sinhconh') 2*cosh(x)

If you go to http://wiki.sagemath.org/symbolics/rewrite, will find all possible commands which perform such transformations.

Enjoy!

Dox

Last week I was trying to integrate a power of the Hyperbolic TangentÂ  (tanh) in sage, so I first try,

sage: n,x = var('n,x')
sage: integrate(tanh(x)^n, x)


but Sage didn’t integrate it. So I impose $n$ to be an integer,


sage: n,x = var('n,x')
sage: assume(n, 'integer')
sage: integrate(tanh(x)^n, x)

and still nothing. However, for specific values of $n$ it worked,

sage: for n in range(1,6):
...  integrate(tanh(x)^n, x)
...

the results were shown.
In the other hand, Mathematica could solve the integration in general,

Integrate[Tanh[x]^n, x]

in terms of Hyperbolic Functions (which Maxima does not manages). Even in the case of specific values of $n$, the given results were much nicer because the answer were given in term of hyperbolic functions instead of exponential.
Then, I decide to try the Sage-Mathematica synapses.
What do we need?

Mathematica installed in the computer.
The License information of Mathematica (even if you have already registered it)
A working Sage installation.

Proceed…
Open a terminal and call a sage subshell,

$sage -sh and call the mathematica kernel,$ math

Here you will be asked to provide the license information. NOTE: It is possible that if runs without the information of the license, in that case you are ready to use Mathematica within Sage.
After provide the information you are ready.
Using it!
The way of using is a bit weird, at the beginning,Â  for integrate the sine function, use this,

sage: mathematica.Integrate(sin(x), x)

Explaination:
Since we are welling to use Mathematica kernel, the first word would be mathematica, followed by a Mathematica command separated by a point. Then, using Sage notation the argument.
This would work! However, the answer is presented in Mathematica notation. If you’d like to have the answer in Sage notation, use something like

sage: eq = mathematica.Integrate(sin(x), x); eq._sage_()

That’s it.
I’d like to thank to schilly for his help.


I’ve been trying Sage(math) for the last three weeks, and I can say it’s a charming piece of software. Works very well, the IRC channel is really, really helpful, the interface is simple, the Python platform is rather natural to manage, evolves quickly… and so on.

However, there are some weak points I’d like to comment…

• Documentation: Since Sage(math) use about 70 different applications, the documentation is FAR of being complete. It would be useful if the documentation is improved, at least if it refers to, say, Maxima documentation… or Numpy… etc.
• Hypergeometric Functions: Besides the confluent one, the hypergeometric functions are left behind. I guess the problem is the maxima support of Special Functions.
• Browser Integration: There are still some weak points in browsers other than firefox… like Chromium-browser. A.f.a. I know, Chromium has problems opening new worksheets, and with some permissions settings.

So, I recomend using firefox as the main browser for Sage(math) and if possible integrate it with other calculation programs like Maple or Mathematica. And finally look up further into Maxima, and other pieces of Sage documentation, as well as using the IRC channel (#sage-devel) an google groups for asking questions.

## Installing and Using SageTeX.

A few minuted ago I could install and use the sagetex package for Sage(math). I’d like to thank ElMonkey for helping me via the IRC channel #sage-devel.

## Pre-requisites.

It is assumed that you have installed

• A LaTeX compiler,
• A LaTeX editor,
• and Sage(math)

all of them configured and working properly.

Get the last version of the package in http://www.sagemath.org/packages/optional/.

## Installing the Package.

My Sage script is located in a sub/sub/sub/subfolder/Sage-4.3.1 (from my HOME folder), so when I want to running it, I should type

$sub/sub/sub/subfolder/Sage-4.3.1/./sage It isn’t nice to repeat this one and again, every day. Thus, I created an alias. Open the .bashrc file in your editor (gedit for example) $ gedit .bashrc


add (at the end of the file) the line

alias sage='/path/to/your/sage/folder/./sage'


which in my example would be,

alias sage='/home/doxdrum/sub/sub/sub/subfolder/Sage-4.3.1/./sage'


Save and close the editor. Now in the terminal,

$source .bashrc  and from now on I just type $ sage

for running the program.

### The real installation.

Now, type in the terminal

$sage -i sagetex-2.2.1.spkg and that’s it. ## Configuration. After the installation, a new folder is placed into the Sage folder. Look into local/share/texmf. All files (and folders) inside it must be copied to the LaTeX tree. In a Linux distribution the LaTeX tree should be placed in /usr/share/texmf/tex/latex $ sudo cp -r /path/to/Sage-4.3.1/local/share/texmf \
Â /usr/share/texmf/tex/latex
$sudo mktexlsr /usr/share/texmf/tex/latex This should work. However, if it doesn’t… the desperate method is to copy the sagetex.sty from /path/to/Sage-4.3.1/local/share/texmf to the folder of the TEX file. ## The TeX File. It is time to create a file.tex, just as any other TEX file. Add the line \usepackage{sagetex} to the preable. ### Compiling the TeX file. When you run $ pdflatex file.tex

the compilator exits with errors… but you get a file.sage, sage-compile it and run pdflatex again,

$sage file.sage$ pdflatex file.tex


There it is!!!

A resume compilation line could be

\$ pdflatex file.tex && sage file.sage && pdflatex file.tex

Enjoy it!

For adding a calculation line between other two lines, pass the pointer between them and click the narrow line that appears close to the bottom line.

# Text in the Notebook.

When you call the notebook from the terminal, it appear as a calculation line. If you’d like to add text, press the Shift-key when adding a new line where the text would be placed. NOTE: you can add math LaTeX symbols as usual surrounded by dollar symbols.

# LaTeX Text.

When you add text in the work-sheet, It look more like OOfice than LaTeX. If in the calculation line you introduce the text precede by a line containing

%latex


when you `evaluate’ the line, the LaTeX text would appear as result.

I do not know if it’s possible to drop the text in the command line after its evaluation.

# Editing a Work-Sheet.

For editing a worksheet,

1. Click theÂ  button Edit in the Upper-Right corner of the notebook page.
2. In the text-like mode appearing erase the lines you’d like to drop.
3. Save the changes (in the button over the first text line).