Ask Your Question

Rolandb's profile - activity

2023-04-19 14:47:06 +0200 received badge  Notable Question (source)
2022-07-20 11:51:55 +0200 received badge  Famous Question (source)
2021-06-04 23:57:44 +0200 received badge  Famous Question (source)
2021-01-11 10:38:48 +0200 received badge  Famous Question (source)
2018-06-27 18:54:55 +0200 received badge  Notable Question (source)
2018-02-26 12:36:23 +0200 received badge  Notable Question (source)
2018-02-26 12:36:23 +0200 received badge  Popular Question (source)
2017-08-14 10:55:37 +0200 received badge  Taxonomist
2017-05-28 00:26:33 +0200 received badge  Popular Question (source)
2016-06-11 18:37:13 +0200 received badge  Popular Question (source)
2016-04-23 05:29:51 +0200 received badge  Famous Question (source)
2016-04-08 09:34:02 +0200 received badge  Popular Question (source)
2016-04-08 09:34:02 +0200 received badge  Notable Question (source)
2016-01-27 15:12:30 +0200 received badge  Popular Question (source)
2016-01-27 15:12:30 +0200 received badge  Notable Question (source)
2016-01-27 15:12:28 +0200 received badge  Popular Question (source)
2016-01-27 09:07:12 +0200 asked a question VM Virtualbox & sage-7.0.ova: how to start?

Hi,

I downloaded sage-7.0.ova and I imported it in VM Virtualbox. What are the next steps?

Using http://localhost:8000/home/admin within my browser doesn't work, as it did up to sage-6.10.ova.
The information on https://wiki.sagemath.org/SageAppliance isn't helpful.
Also https://groups.google.com/forum/#!top... didn't give much information.

Are these the steps for Sage-7.0 for Windows / VM Virtualbox?
1) load sage-7.0.ova as normal in VM Virtualbox
2) Go to http://localhost:8000/tree within your browser
3) On the top right select New and than SageMath 7.0
4) You see at the top Jupyter Notebook Untitled
5) You have to select Run instead of pressing Enter to perform a command

If so, how to upload my *.sws files?

Thanks for answering.

2016-01-18 22:37:00 +0200 commented question Smart set (database?)

Yes, the examples behave different. In general if [A[B[C]]] and [X[Y[Z]]] are element of the structure, I want to define what A+X, B+Y and C+Z are. It can be concatenating a list or the addition of numbers. The structure therefor must be defined including the addition operators.

2016-01-16 22:55:50 +0200 commented question Smart set (database?)

For me [1,2] + [3,4] yields [1,2,3,4].

2016-01-15 21:46:28 +0200 asked a question Smart set (database?)

Hi,

What I would like is to define a smart hierarchical set (or database) like:

 example_set={(0,0,0):[4,[7,11,0]], (0,0,1):[-5,[8,-3,6]], (0,1,0):[4,[7,11,-1]]}

The lefthand side is an hierarchy (a,b,c,d,e,...); the righthand side is some structure [, [,,,...]] consisting of nested lists. How can I quickly -via a smart design- determine for instance the sum for a higher level? For instance example_set.sum[(0,0)] would yield [4-5, [7,11,0] + [8,-3,6]] and example_set.sum[(0,)] yields [4-5+4, [7,11,0] + [8,-3,6] + [7,11,-1]].

The setting is that we have a few thousand hierarchical elements with unknown depth, but always the same structure on the righthand side. The structure could contain many nested lists with in total several hunderd values (flattened). I like to have (fast) basic operators for the lists within the structure such as addition and index.

Another example.

next_example={(0,0,0):[(5,6)], (0,0,1):[(8,9),(3,4)], (0,1,0):[(2,6)], (0,1,1):[(8,16)]} 
(wanted) print next_example.sum[(0, 0)]
[(5, 6), (8, 9), (3, 4)]

I considered to define a class and I looked at database. But that didn't help me much :(

To complicate matters, I would also like to connect hierarchical levels (one-direction). For instance in the first example assume (0,0,0) is connected to (0,1,1). How to store and display such a connection? For connections I looked for instance at igraph. But it isn't clear to me whether it would be helpful in combination with the above mentioned set design.

To summarize: it would be awesome if a routine 'smart_set(n, structure)' would define a n-level hierarchy whereby operations like .sum(input) and .sum.connected(input) and .show_graph() would work.

Suggestions how to move forward in Sage are much appreciated!

Roland

2015-03-07 14:14:51 +0200 answered a question solve 2 equations in terms of other variables

Hint: please avoid 'sqrt' within equations.

eq1=wo==Q*(C*RL*Rs+L)/(C*L*RL)
eq2=wo^2==(RL+Rs)/(C*L*RL)
sol=solve([eq1,eq2],C,L)
print sol 

[
[C == -2*(Q*RL + Q*Rs)/(sqrt(-4*Q^2*Rs + RL + Rs)*sqrt(RL + Rs)*RL*wo - RL^2*wo - RL*Rs*wo), 
L == 1/2*(RL + Rs -   sqrt(-4*Q^2*Rs^2 - 2*(2*Q^2*Rs - Rs)*RL + RL^2 + Rs^2))/(Q*wo)],
[C == 2*(Q*RL + Q*Rs)/(sqrt(-4*Q^2*Rs + RL + Rs)*sqrt(RL + Rs)*RL*wo + RL^2*wo + RL*Rs*wo), 
L == 1/2*(RL + Rs + sqrt(-4*Q^2*Rs^2 - 2*(2*Q^2*Rs - Rs)*RL + RL^2 + Rs^2))/(Q*wo)]
]
2015-01-20 23:57:21 +0200 answered a question About roots of a certain polynomial equation

I assume you are wondering why Sage is not recognizing that $(x^2 - 6)x^2 - 4x(e^{\frac{2}{5}i\pi} + e^{\frac{-2}{5}i\pi}) - e^{\frac{4}{5}i\pi} - e^{\frac{-4}{5}i\pi} - 1=(x^2 - 6)x^2 - 8xcos(\frac{2}{5}\pi) - 2*cos(\frac{4}{5}\pi) - 1$, and thereafter doesn't find the four real roots: $x=-2.1755705045849463, -0.618033988749891, 0.17557050458494627, 2.618033988749895$.

Mixing the world of solving algebraic equations - which are exact - with the world of finding roots - which are approximations - is seldom a good idea. If you would split both worlds, it goes fluently.

var('x')
f(x)=(x^2 - 6)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1
g(x)=real_part(f(x)).simplify()
print g
x |--> x^4 - 6*x^2 - 2*sqrt(5)*x + 2*x + 1/2*sqrt(5) - 1/2

print [find_root(g,-3,-2), find_root(g,-1,0), find_root(g,0,1), find_root(g,2,3)]
[-2.1755705045849463, -0.6180339887498911, 0.17557050458494627, 2.618033988749895]

Stated differently, always simplify your function (= exact) before going into a numerical process such as root finding. Any system - thus also Sage - hangs up because it is impossible to determine the simplification numerically.

2014-12-03 19:08:39 +0200 answered a question Generate a conditional list of integers

Hi,

Generating a long list takes time. If speed is an issue too, you could consider defining your own squarefree test.

sage: %cython
sage: cimport cython
sage: @cython.cdivision(True)
sage: #Fast up to 5*10^8
sage: cpdef bint is_csquarefree(long long n, unsigned long long priem=10**6):
...       cdef unsigned long p
...       cdef unsigned int* eerste=[2,3,5]
...       cdef unsigned int i=1,k
...       cdef unsigned int* diff=[6,4,2,4,2,4,6,2]     
...       if not n: return 0
...       if n<0: n=-n     
...       for k in xrange(3):
...           if not n%eerste[k]: 
...               n//=eerste[k]    #In 539 of 900 cases a number not dividable by 4,9,25
...               if not n%eerste[k]: return False
...      
...       p=7
...       while p<=priem and p*p<=n:
...           if not n%p: 
...               e=1 ; n//=p
...               if not n%p: return False
...               
...           p+=diff[i%8]
...           if not p%7: i+=1 ; p+=diff[i%8]                     #Small lost of time
...           i+=1       
...       return True

Test it:

sage: for k in xsrange(1,1000):
...       if is_csquarefree(k)!=is_squarefree(k): print k

Enjoy speed:

sage: timeit('for k in xrange(10^8,10^8+10^3): is_squarefree(k)==True')
sage: timeit('for k in xrange(10^8,10^8+10^3): is_csquarefree(k)==True')
25 loops, best of 3: 29.2 ms per loop
125 loops, best of 3: 4.86 ms per loop
2014-11-25 13:44:22 +0200 received badge  Nice Answer (source)
2014-11-24 17:54:19 +0200 answered a question Lower prime divisor

There a two ways to avoid calculating all prime divisors. Firstly, look at "trial_division". It gives the first prime divisor.

trial_division(13*97)
13

Secondly, you can use n.factor(limit=yoursearchlimit).

(13*97*191).factor(limit=50)
13 * 18527
2014-08-08 22:04:49 +0200 asked a question TimeSeries & cython: why cimport yellow?

I get the following information from cython:

Raw output

6: from sage.finance.time_series cimport TimeSeries
7: 
8:   cpdef csnelregres(self,int periode):
9:       cdef int aantal=len(self)-periode
10:   
11:     cpdef a = TimeSeries(aantal)

I wasn't expecting a yellow color for cpdef a = TimeSeries(aantal).

Any suggestions?

2014-08-03 07:35:22 +0200 received badge  Enthusiast
2014-07-10 00:17:08 +0200 answered a question How to do an "if" block in Sage?

Maybe you get confused by the fact that gcd(0,3) equals 3. If I print each step, it works as expected.

for n in range(9):
    print "n=",n
    if gcd(n,3)==3:
        print "?"
        n=n/3
        n=n+1
    print "*",n

n= 0
?
* 1
n= 1
* 1
n= 2
* 2
n= 3
?
* 2
n= 4
* 4
n= 5
* 5
n= 6
?
* 3
n= 7
* 7
n= 8
* 8
2014-06-29 22:45:18 +0200 answered a question Solving ax^2+bxy+cy^2=n fast?

Thanks for all replies! Yes, I'm looking at integers. A few months ago Thilina Rathnayake implemented routines in Sympy (http://thilinaatsympy.wordpress.com/2013/09/14/status-of-the-diophantine-module-2/). This seems to me a good start as Sympy is a standard package. I'll have a 2nd look at my routines and I'll provide a link within a few days (if that's still wanted). Roland

2014-06-29 22:29:24 +0200 received badge  Nice Question (source)
2014-06-29 21:25:57 +0200 received badge  Notable Question (source)
2014-06-29 21:25:57 +0200 received badge  Popular Question (source)
2014-06-29 21:25:57 +0200 received badge  Famous Question (source)
2014-06-29 21:20:18 +0200 received badge  Famous Question (source)
2014-06-29 21:20:18 +0200 received badge  Notable Question (source)
2014-06-29 21:20:18 +0200 received badge  Popular Question (source)
2013-12-23 03:43:39 +0200 asked a question Dividing by 2 fast: how?

Please consider the following example:

tt=1200
ss=tt>>2
print ss
300

The division by 4 goes fast. But how can I divide by 2?

The expression tt>2 yields a boolean. And the options ss=tt//2 and ss=tt; ss/=2 seem not optimal.

timeit("tt=1200;ss=tt>>2")    625 loops, best of 3: 152 ns per loop
timeit("tt=1200;ss=tt//2")      625 loops, best of 3: 323 ns per loop
timeit("tt=1200;ss=tt;ss/=2") 625 loops, best of 3: 552 ns per loop

Thanks for you kind consideration.

2013-12-17 12:10:37 +0200 received badge  Teacher (source)
2013-12-17 00:26:34 +0200 answered a question Load data when running Sage from a VM in Windows

It isn't easy. In fact it is a daunting task. Why? You have the overcome the difficulties of matching two operating systems.

If files are small <<1Mb, I use the "Data" option which you find at the top. For larger sizes, I found this commend helpfull to understand the issues, and you find detailed instructions here.

If it works, it works, but it took me months ... Success!

2013-11-19 02:29:11 +0200 received badge  Supporter (source)
2013-10-25 05:42:32 +0200 asked a question How to translate text (easily)?

Dear community,

More and more interesting *.sws examples are posted on various sites. For instance on this site. Although the Dutch education system supports English, French, German, Latin and Greek, I still would appreciate if I could (easily) translate text via a 'similar to Google Translate'-facility. From "X" to English would be perfect as a start.

Has someone any suggestions? Thanks in advance for your kind reply! (I'm using Win7-64 + VM Virtualbox + 5.12 + Google Chrome)

Roland

2013-06-19 05:10:33 +0200 commented answer PySDE: How to import this Python package?

Hi, Thanks for yor swift reply! I got an error when applying step 4: sde_wrap.cpp does not exist.. :(

2013-06-18 16:56:53 +0200 asked a question PySDE: How to import this Python package?

Hi, how can I add PySDE [https://github.com/hobu/pysde/blob/ma...] to Sage? I use version 5.9 Win64 VBox.

I want to run: """ add required Python packages """ from pysde import * from sympy import * """ Variables acclaimed """ x,dx=symbols('x dx') r,G,e,d=symbols('r G epsilon delta') """ Solve Kolmogorov Forward Equation """ l=sde.KolmogorovFE_Spdf(r(G-x),ex(1-x),0,1) sol=l.subs({e:rd})

pprint(sol)

Thanks! Roland

2013-03-19 13:32:01 +0200 answered a question Radical Sign in answer?

Use variables to solve the equation symbolically:

var('a','b','c','t')

S = solve([at^2 + bt + c], t)

print S

[t == -1/2(b + sqrt(-4ac + b^2))/a,t == -1/2(b - sqrt(-4ac + b^2))/a]

Then define g:

g(a,b,c,t)=S[0].rhs()

show(g)

$\newcommand{\Bold}[1]{\mathbf{#1}}\left( a, b, c, t \right) \ {\mapsto} \ -\frac{b + \sqrt{-4 \ a c + b^{2}}}{2 \ a}$

That is how I would write it by hand.

Proof of concept:

g(-16,48,5)

1/4*sqrt(41) + 3/2

I hope it helps.

2013-01-19 10:04:51 +0200 asked a question How to use E.T.E. a Python tree package within Sage?

Hi, ETE is a Python based tree building package with nice graphical support. Can I use it within Sage? Thanks, Roland

2013-01-14 00:06:48 +0200 answered a question definition of gcd for(x,y)

Hi, you can always define your own gcd function with the properties you need. There are various equivalent definitions of gcd as these websites show: Paper, Wolfram and Wiki Roland

2013-01-11 17:08:57 +0200 answered a question sage recursive functions programming

Hi, I have used a Boolean to distinguish the states: 'a'=True and 'b'=False.

@cached_function def recur(string,initial_state):

if string=='': return ''
else: 
    start=eval(string[0])
    return str((initial_state+start)%2)+recur(string[1:],start)

Does this answer your question? Roland