Ask Your Question

burcin's profile - activity

2019-11-06 14:23:41 -0500 received badge  Taxonomist
2016-07-31 16:46:32 -0500 received badge  Good Answer (source)
2016-07-07 17:50:37 -0500 received badge  Good Answer (source)
2016-01-18 09:46:06 -0500 received badge  Nice Answer (source)
2015-04-15 08:28:49 -0500 received badge  Nice Answer (source)
2014-02-02 00:22:15 -0500 received badge  Good Answer (source)
2013-09-03 05:14:48 -0500 received badge  Nice Answer (source)
2013-07-12 02:10:02 -0500 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 01:32:32 -0500 received badge  Good Answer (source)
2013-06-30 01:24:16 -0500 received badge  Nice Answer (source)
2013-06-07 02:29:32 -0500 edited question spam please close

Spam link is in the answer.

2013-06-07 02:27:16 -0500 received badge  Citizen Patrol (source)
2013-05-22 00:12:29 -0500 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-17 19:20:03 -0500 received badge  Good Answer (source)
2013-05-15 03:48:31 -0500 received badge  Nice Answer (source)
2013-05-15 01:29:20 -0500 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 02:36:02 -0500 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 12:56:52 -0500 received badge  Nice Answer (source)
2013-03-07 07:19:21 -0500 commented question polynomial digits of pi

This seems like a homework question.

2013-03-04 23:50:12 -0500 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-04 21:20:18 -0500 answered a question Solving simultaneous boolean algebraic equations

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

2013-02-19 14:12:28 -0500 received badge  Good Answer (source)
2013-02-19 10:08:59 -0500 received badge  Nice Answer (source)
2013-02-19 03:17:14 -0500 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 02:30:12 -0500 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 01:17:29 -0500 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-25 17:41:37 -0500 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 03:49:09 -0500 received badge  Nice Answer (source)
2013-01-16 22:39:20 -0500 commented question sage sample

This sounds a lot like homework.

2013-01-16 04:46:03 -0500 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-14 22:53:21 -0500 received badge  Organizer (source)
2013-01-14 22:52:56 -0500 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 05:06:40 -0500 received badge  Good Answer (source)
2013-01-14 02:44:33 -0500 received badge  Nice Answer (source)
2013-01-13 21:58:50 -0500 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 10:03:17 -0500 received badge  Nice Answer (source)
2013-01-12 11:41:21 -0500 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 10:00:00 -0500 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 03:19:09 -0500 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-02 22:22:59 -0500 received badge  Nice Answer (source)
2013-01-02 01:55:52 -0500 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 12:58:11 -0500 received badge  Nice Answer (source)
2012-12-18 22:06:16 -0500 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 00:29:57 -0500 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-02 21:15:56 -0500 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-29 18:27:37 -0500 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 00:09:20 -0500 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-23 21:00:07 -0500 received badge  Good Answer (source)
2012-11-23 12:18:46 -0500 received badge  Nice Answer (source)
2012-11-22 21:11:55 -0500 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