Ask Your Question

burcin's profile - activity

2019-11-06 21:23:41 +0200 received badge  Taxonomist
2016-07-31 23:46:32 +0200 received badge  Good Answer (source)
2016-07-08 00:50:37 +0200 received badge  Good Answer (source)
2016-01-18 16:46:06 +0200 received badge  Nice Answer (source)
2015-04-15 15:28:49 +0200 received badge  Nice Answer (source)
2014-02-02 07:22:15 +0200 received badge  Good Answer (source)
2013-09-03 12:14:48 +0200 received badge  Nice Answer (source)
2013-07-12 09:10:02 +0200 answered a question PolyBoRi Version in Sage 5.9

There is probably a better way to find out if you have Sage 5.9 installed, but here is a quick answer. You'll see that the polybori package in the standard Sage distribution has version 0.8.3 here:

http://sage.math.washington.edu/home/...

2013-07-01 08:32:32 +0200 received badge  Good Answer (source)
2013-06-30 08:24:16 +0200 received badge  Nice Answer (source)
2013-06-07 09:29:32 +0200 edited question spam please close

Spam link is in the answer.

2013-06-07 09:27:16 +0200 received badge  Citizen Patrol (source)
2013-05-22 07:12:29 +0200 answered a question substitution in expression

The substitute command is a generic interface to the rewrite engine in Pynac/GiNaC. You can replace an arbitrary subexpression, also containing wildcards (see the documentation of the match() method of symbolic expressions), with another expression.

Consider the case where a subexpression occurs in several places and you have a better formula or value for it derived from other sources. You can just replace the existing subexpression with the new formula using the substitute() function.

2013-05-18 02:20:03 +0200 received badge  Good Answer (source)
2013-05-15 10:48:31 +0200 received badge  Nice Answer (source)
2013-05-15 08:29:20 +0200 answered a question simplify and latex_name

This is a bug. I opened a ticket on trac, see #14590.

Thanks for the feedback.

2013-05-05 09:36:02 +0200 answered a question Conversion of Differential Forms to a manipulable symbolic expression

It's a terrible hack, but perhaps this will help you as a workaround:

sage: x, y, z = var('x, y, z')
sage: U = CoordinatePatch((x, y, z))
sage: F = DifferentialForms(U)
sage: f = F(x^2 + y + sin(z)); f
(x^2 + y + sin(z))
sage: g = f.diff(); g 
cos(z)*dz + 2*x*dx + dy

That's what you have already. Now, we convert g to a string and parse it as a new symbolic expression:

sage: t = SR(str(g))
sage: t.operands()
[2*dx*x, dz*cos(z), dy]
sage: t.variables()
(dx, dy, dz, x, z)
2013-03-29 18:56:52 +0200 received badge  Nice Answer (source)
2013-03-07 14:19:21 +0200 commented question polynomial digits of pi

This seems like a homework question.

2013-03-05 06:50:12 +0200 answered a question How to print out Maxima commands being used by Sage?

Sage sets the domain of all variables to complex when initializing Maxima. You can get the same result as Sage by doing this manually on the Maxima prompt:

$ ./sage -maxima
;;; Loading #P"/home/burcin/sage/sage-5.5.rc0/local/lib/ecl/sb-bsd-sockets.fas"
;;; Loading #P"/home/burcin/sage/sage-5.5.rc0/local/lib/ecl/sockets.fas"
;;; Loading #P"/home/burcin/sage/sage-5.5.rc0/local/lib/ecl/defsystem.fas"
;;; Loading #P"/home/burcin/sage/sage-5.5.rc0/local/lib/ecl/cmp.fas"
Maxima 5.26.0 http://maxima.sourceforge.net
using Lisp ECL 11.1.1
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) domain: complex;
(%o1)                               complex
(%i2) load(fourier_elim);
(%o2) /home/burcin/sage/sage-5.5.rc0/local/share/maxima/5.26.0/share/contrib/f\
ourier_elim/fourier_elim.lisp
(%i3) fourier_elim([x^2*y^2 <= x^2*y, x^2*y^2 > x^2*y],[x,y]);
(%o3)           [x = 0, 1 < y, 0 # 0] or [x = 0, y < 0, 0 # 0]

If you want to take a look at the code, Maxima initialization is done at the beginning of sage/interfaces/maxima_lib.py. Line 141 has the default options set by Sage.

2013-03-05 04:20:18 +0200 answered a question Solving simultaneous boolean algebraic equations

Looking into the PolyBoRi interface, especially the variety() function might help.

2013-02-19 21:12:28 +0200 received badge  Good Answer (source)
2013-02-19 17:08:59 +0200 received badge  Nice Answer (source)
2013-02-19 10:17:14 +0200 answered a question Evaluate expression with unknowns

You need the ._convert() method:

sage: f = (x* 2* pi* log(5)* 6^1.5)/(3^4*pi^2+x)
sage: f._convert(RR)
148.621271129886*x/(x + 799.437956488238)
2013-02-10 09:30:12 +0200 answered a question variables vs arguments

For symbolic expressions, variables() and arguments() methods return the same result. You can observe this by adding ?? at the end of the function name and taking a look at the code.

sage: var('a,b')
(a, b)
sage: t = a*x^2
sage: t.arguments??
    def arguments(self):
...
        try:
            return self._parent.arguments()
        except AttributeError:
            return self.variables()

For callable expressions, they differ:

sage: t.arguments()
(x,)
sage: t.variables()
(a, x)
2013-02-10 08:17:29 +0200 answered a question Using pyglet in sage?

Sage installs its own version of Python and many other mathematics packages independent of the host operating system. You would need to install pyglet in this environment. You can do this with

sage: !easy_install pyglet

on the Sage ipython prompt.

This was also answered here.

2013-01-26 00:41:37 +0200 answered a question Passing params to cythonized ode_system()

I guess you mean the example at the end of the Solving ODE numerically by GSL section.

You can add a constructor to your class which takes params as an argument and stores it in the instance created. The code to use this would be (mostly copied from the reference manual)

sage: params = [<value>, <value>, <value>]
sage: T = ode_solver()
sage: T.algorithm = "bsimp"
sage: osc = duffing_osc(params) # note the argument
sage: T.function = osc
sage: T.ode_solve(...)

The new class would look like:

cdef class duffing_osc(sage.gsl.ode.ode_system):
    def __init__(self, params):
        self.params = params

    cdef int c_f(self,double t, double *y,double *dydt):
        dydt[0]=y[1]
        dydt[1]=y[0]-self.params[0]*y[1]-y[0]*y[0]*y[0]+\
                self.params[1]*cos(self.params[2]*t)
        return GSL_SUCCESS
    cdef int c_j(self, double t,double *y,double *dfdy,double *dfdt):
        dfdy[0]=0
        dfdy[1]=1.0
        dfdy[2]=-3*y[0]*y[0]+1
        dfdy[3]=-self.params[0]*y[1]
        dfdt[0]=0
        dfdt[1]=-self.params[1]*self.params[2]*sin(self.params[2]*t)
        return GSL_SUCCESS

In terms of performance, there is a problem with this code.

The elements of params are Sage types, either Python floats, RDF elements, or even multiprecision floats (backed by MPFR). Whenever these are multiplied by a double, Sage will automatically convert this value to a Sage/Python object, do the arithmetic, and convert the result back to a double. This is very slow, compared to a simple float multiplication.

To work around this, you can convert params to a vector of doubles in the constructor. Assuming params has 3 elements, then the first lines of the class would be

cdef class duffing_osc(sage.gsl.ode.ode_system):
    cdef double params[3]
    def __init__(self, params):
        for i in range(3):
            self.params[i] = params[i] # type conversion is automatic
2013-01-17 10:49:09 +0200 received badge  Nice Answer (source)
2013-01-17 05:39:20 +0200 commented question sage sample

This sounds a lot like homework.

2013-01-16 11:46:03 +0200 answered a question subs(_expr) not working properly?

When asked to replace P1^2+P2^2+P3^2 by P, GiNaC (symbolics back-end for Sage) looks for an exact match. If this sum is part of an expression, such as P1^2 + P2^2 + P3^2 + sqrt(P)*P0 there will be no substitution.

Try this instead:

sage: denominator.substitute({P1^2: P- P2^2 - P3^2}) 
-1/2*((P3 - sqrt(P))*(P1*m/(sqrt(P)*P0 + P) - I*P2*m/(sqrt(P)*P0 + P) + 2*P1 - 2*I*P2) - (P1 - I*P2)*(P3*m/(sqrt(P)*P0 + P) + 2*P0 + 2*P3 - sqrt(P)*m/(sqrt(P)*P0 + P)))/sqrt(1/2*P3*m/(sqrt(P)*P0 + P) + P0 + P3 - 1/2*sqrt(P)*m/(sqrt(P)*P0 + P))

More information available in the relevant section of the GiNaC tutorial.

2013-01-15 05:53:21 +0200 received badge  Organizer (source)
2013-01-15 05:52:56 +0200 answered a question How can I use turtle module?

This looks like a generic Python question. In this case, Google might be more helpful than this site. Here is the first hit.

2013-01-14 12:06:40 +0200 received badge  Good Answer (source)
2013-01-14 09:44:33 +0200 received badge  Nice Answer (source)
2013-01-14 04:58:50 +0200 commented question definition of gcd for(x,y)

I guess the context here is given by http://en.wikipedia.org/wiki/GCD_test. This is off-topic.

2013-01-13 17:03:17 +0200 received badge  Nice Answer (source)
2013-01-12 18:41:21 +0200 answered a question Defining Clifford Algebras

GiNaC, the C++ library used as the backend for symbolic expressions in Sage, supports Clifford algebras. See this article for more details. Using this implementation might be easier than starting from scratch in Python/Cython. I expect the performance of GiNaC to be quite competitive, thanks to Pynac we can also use arbitrary coefficient domains from Sage.

After a brief look at the article mentioned above, I can say that it would be fairly straightforward to wrap those C++ functions and provide access to these data structures from Sage. I would be happy to do this and create a prototype implementation if somebody is willing to take over the polish. :)

2013-01-12 17:00:00 +0200 answered a question How to use cython functions from other cython cells in notbook?

This works for me:

%cython
from __main__ import test

def test3(int m):
    return test(m)

The function name test is making things more confusing in this case. Python has a module named test, so if you just use import test, the module masks the previously defined function.

2013-01-04 10:19:09 +0200 commented answer Express domain membership

Then you can mark my answer as the accepted one. This will prevent this question from getting in the way if someone searches for the list of unanswered questions on this site.

2013-01-03 05:22:59 +0200 received badge  Nice Answer (source)
2013-01-02 08:55:52 +0200 answered a question Express domain membership

assume() is a wrapper for the function with the same name in Maxima. You can find out about the syntax with the usual method of adding a ? after the function name:

sage: assume?

In this case, to indicate that the variable x is in ZZ, you need to type:

sage: assume(x, 'integer')

Unfortunately, Sage relies on two different backends for symbolic computations, Maxima and Pynac. Each of these uses a different method to indicate domains. We haven't reconciled these through the same interface yet. In order to indicate that a variable is real to Pynac, you can do:

sage: var('x', domain=RR)

At this moment, Pynac does not have different domains for ZZ or QQ. It only knows about RR, CC and NN.

2012-12-19 19:58:11 +0200 received badge  Nice Answer (source)
2012-12-19 05:06:16 +0200 answered a question Does a subtraction symbolic expression actually exist?

We only use add, mul and pow operations in the expression tree. Subtraction is represented as addition with an appropriate coefficient and division is multiplication with an appropriate exponent. This makes it easier to handle expressions since you don't need to worry about handling these cases separately.

For example:

sage: var('x,y')
(x, y)
sage: ex = x+y-1
sage: ex.operator()
<built-in function add>
sage: ex.operands()
[x, y, -1]

You can read more about the internal representation of expressions in the relevant part of the GiNaC tutorial.

The patch attached to ticket #13738 wraps some internal GiNaC functions to view the expression tree.

2012-12-03 07:29:57 +0200 answered a question Object Persistence db_save error

Python does not know how to save the state of the generator object. You need to define methods to "pickle" and "unpickle" your object, i.e., save a persistent state and read it back.

There is some documentation for this in the pickle section of the Python documentation. Especially this section on pickling normal class instances is relevant.

Essentially, you need to define two methods __getstate__() and __setstate__(state).

2012-12-03 04:15:56 +0200 answered a question System of polynomial inequalities

You can use the cylindirical algebraic decomposition (CAD) method to solve a system of polynomials with inequalities. Sage has an optional package for QEPCAD. See the output of

sage: qepcad?

and try

./sage -i qepcad

from the command line to install QEPCAD. Note that the version we have (1.50) is quite old. The latest version on the web site is 1.69.

2012-11-30 01:27:37 +0200 edited question creating a matrix from blocks

I am new to SAGE. I need to create a matrix by using matrices of different sizes. For example:

Abar= [(A + B), C]
      [  D ,    E]

where A and B are 2x2's, C is a 2x1, D is a 1x2, and E is a 1x1. I do not need Abar to be a partitioned matrix. Thanks much.

2012-11-26 07:09:20 +0200 answered a question Forcing Prime Notation

You can try the patch attached to issue #6344. It is more than 3 years old, so some work might be needed to make it apply to a recent Sage version, but it essentially does exactly what you need. See this comment for some examples.

2012-11-24 04:00:07 +0200 received badge  Good Answer (source)
2012-11-23 19:18:46 +0200 received badge  Nice Answer (source)
2012-11-23 04:11:55 +0200 answered a question Why simplify doesn't work?

simplify_full() just runs the specialized simplify_*() routines one by one. You can call them individually and see if they give you better results.

sage: x.sim<tab>
x.simplify            x.simplify_full       x.simplify_rational
x.simplify_exp        x.simplify_log        x.simplify_trig
x.simplify_factorial  x.simplify_radical