Ask Your Question

A.Alharbi's profile - activity

2020-07-15 12:41:09 -0500 received badge  Nice Answer (source)
2016-12-09 05:09:57 -0500 commented question Issues with .99999999999...

I believe this is due to number of precision It might be a good idea to work with RealField

2016-11-20 16:23:02 -0500 commented answer why I can not get a numerical answer by show(integral(x^x,x,1,2))

Equivalently, feed the whole expression to $N$

sage: N(integral(x^x,x,1,2)) #2.0504462345347307

Also, the same syntax $N$ exists in SymPy and the equivalent of $f.n()$ in SymPy is $f.evalf()$

2016-11-20 16:14:53 -0500 received badge  Commentator
2016-11-20 16:14:53 -0500 commented answer Finding prime factorization of ideals in number rings

The theorem says a prime $p$ ramifies iff $p|\Delta$. However, this does NOT imply that a prime $p$ which does not ramify must inert, because there is a third case in which the prime splits.

Look at problem for section 3.4, or for detailed treatment (Kummer-Dedekind theorem) see Stevenhagen's lecture notes Number Rings

2016-10-27 12:16:44 -0500 received badge  Enthusiast
2016-10-26 13:32:50 -0500 commented answer Finding prime factorization of ideals in number rings

a is the root of definingPolynomial i.e. $f(a) = 0$

2016-10-21 10:00:48 -0500 answered a question Finding prime factorization of ideals in number rings

Define your number field $\mathbb{Q}(\alpha), \alpha = \sqrt{2} + i$ .

K.<a> = NumberField(definingPolynomial)

In your particular case

Z.<x> = ZZ[] #Makes x lives in Z[x]
K.<a> = NumberField( minpoly(sqrt(2)+i, x))
I = K.ideal(2)
#(Fractional ideal (1/12*a^3 - 1/4*a^2 - 5/12*a + 5/4))^4
#Even fancier
#(\left(\frac{1}{12} a^{3} - \frac{1}{4} a^{2} - \frac{5}{12} a + \frac{5}{4}\right))^{4}
2016-08-13 09:51:01 -0500 commented question Can I test that a Cayley table represents a group?

The problem with Light's algorithm is that one needs to find generators before applying it, otherwise it would be more expensive than usual exhaustive search (from a memory point of view). That being said, I think it worth to implement those tests in sage. I might write a function in python which performs two tests based on arguments given.

2016-08-12 16:26:29 -0500 commented question Can I test that a Cayley table represents a group?

As mentioned here, there is a probabilistic algorithm which has running time close to $O(n^2)$. I wonder if there is a deterministic algorithm with running time less than $O(n^3)$.

2016-08-03 12:01:54 -0500 answered a question Installing Cryptominisat

Similar question has been asked but without a solution

I installed sage through ubuntu PPA's and found an ad-hoc solution to " 'all-toolchain'" problem. It should work in your case since Mint is essentially an Ubuntu.

Step 0: Problem

me@myLaptop:~$ sage -i cryptominisat 
make: *** No rule to make target 'all-toolchain'.  Stop.

Step 1: Installing sufficient dependencies:

According to cryptominitsat's page on github, you need to install some packages

$ sudo apt-get install build-essential cmake
$ sudo apt-get install valgrind libm4ri-dev libmysqlclient-dev libsqlite3-dev

Note: I am not sure if it necessary to apply above steps, but it does not solve the problem

Also, install all packages which have in their name sagemath in Synaptic package manager

image description

Check point

Now, if you try:

me@myLaptop:~$ sage -i cryptominisat

you will get a premission error. Even worse, trying sudo it would give you a root user error!

configure: error: You cannot build Sage as root, switch to an unpriviledged user If you would like to try to build Sage anyway (to help porting)

Step 2: Change /usr/ib/sage and its subfolders' owner to you standard user

$\color{red}{It\ is\ safer\ to\ revert\ ownership\ to\ the\ root}$


sudo chown -R `whoami`:`whoami` /usr/lib/sagemath/


 sage -i cryptominisat

Ta da

2016-06-07 04:57:43 -0500 received badge  Nice Answer (source)
2016-05-28 13:24:04 -0500 received badge  Teacher (source)
2016-05-26 15:18:07 -0500 commented answer How to install seaborn in sagemath cloud?

Not necessarily, you can install it locally. For this particular case, upload seaborn files into your cloud manually, then open terminal and run python install --user $whoami in the seaborn's folder. Similarly, you can install Ubuntu's packages but using different commands.

2016-05-26 15:04:06 -0500 commented question Simply trying to understand these lines of code

I'll try to come back and read your post thoroughly. Meanwhile, this could be of interest

2016-05-26 14:31:19 -0500 answered a question How make Kummer extensions

Note: I have NOT studied cyclotomic fields.

I believe the problem lies in minpoly() function. It has been reported that minpoly sometimes doesn not return an irreducible polynomial.

Also, if you check where f belongs, you will see that it is not in $\mathbb{Q}(\xi)_5[x]$ !.

sage: K.<b>=CyclotomicField(5);
sage: alpha=1+3*b^2;
sage: f=(1+3*b^2).minpoly()
sage: f.parent()
Univariate Polynomial Ring in x over Rational Field
sage: factor(f)
x^4 - x^3 + 6*x^2 + 14*x + 61
sage: G.<x> = K[] #Define a polynomial ring over K
sage: f = G(f) #Coerce f into G
sage: f.parent()
Univariate Polynomial Ring in x over Cyclotomic Field of order 5 and degree 4
sage: factor(f)
(x - 3*b - 1) * (x - 3*b^2 - 1) * (x - 3*b^3 - 1) * (x + 3*b^3 + 3*b^2 + 3*b + 2)
sage: f.is_irreducible()

Update: Could you please elaborate which element would you like to append it to $\mathbb{Q}(\xi)_5$? It seems to me that $\alpha$ is already in $\mathbb{Q}(\xi)_5$ but $\sqrt[5]{\alpha}$ is not. If you use fractional expontiation or the function nth_root in minpoly, it will gives you an error. I am afraid that you have to hardcode the equation $x^5 - \alpha$

sage: alpha in K
sage: alpha^(1/5) in K 
sage: L.<a> = K.extension(x^5 - alpha)
sage: L
Number Field in a with defining polynomial x^5 - 3*b^2 - 1 over its base field

Second update

If you use fractional exponentiation or the function nth_root in minpoly, it will gives you an error.

It seems an issue need to be solved.

by the way, what f = G(f) means?

$f$ was living in $\mathbb{Q}$,i.e. arithmetic on $f$ would be carry over $\mathbb{Q}$, writing f = G(f) tells sage $f$ is an element of $G$


sage: a = 7
sage: a^2


sage: R = IntegerModRing(13)
sage: a = R(a)
sage: a
sage: a^2
sage: a + 6

For more information see

2016-04-27 13:07:54 -0500 commented question Coercion on continued fractions

@mirgee Of course, you need to take of each case. I will try to implement this solution and post it here. I think if you manage to find an old version of sage then it is matter of copying and pasting.

2016-04-21 05:57:08 -0500 commented question Coercion on continued fractions

It might be interesting that an older version of sage supports addition and multiplication of continued fraction with each other as well with rational numbers. See William Stein's book Elementary Number Theory: Primes, Congruences, and Secrets. Another quick solution(as you mentioned) is to add sage's magical functions _add_ , _mul_, etc. to the class continued_fraction. It might goes as (for sure it is not an optimal solution): def _add_(self, other): check both types return continued_fraction(self.value + other)

2016-01-10 08:53:04 -0500 commented answer Running Sage inside Python

@gilieve I'd recommend Jupyter.

2016-01-09 09:59:25 -0500 answered a question How to evaluate the infinite sum of 1/(2^n-1) over all positive integers?

Another way to do that is by using SymPy:

from sympy import Sum, Symbol
x = Symbol('x')
s = Sum( 1/(x**2-1), (x, 1, 00))

Give the result[1]:


I remember seeing a way to convert SymPy expression to SAGE format, but I don't know how exactly.

[1] I apologize I typed another function in the command line which is $\frac{1}{x^2 -1}$. After realizing that, I tried to evaluate your function but ipython always crash.

2016-01-09 04:13:28 -0500 received badge  Famous Question (source)
2016-01-06 05:08:52 -0500 received badge  Popular Question (source)
2016-01-06 05:08:52 -0500 received badge  Notable Question (source)
2016-01-04 13:13:58 -0500 marked best answer OverflowError: Python int too large to convert to C long in computing discrete logarithm

I was trying to compute Discrete logarithm using sage built in method (Don't worry I am not breaking anyone encryption :))

Firstly I defined:

sage: K = IntegerModRing(170105614024288730080534932284438889283915362533105079405708531244397007382373065644323359440168891115028688155796209240525852365277829421681328386791392246695036645057638022446250013789591527999940334485768929906363644007315425771754703250375664803466636053933683807019651127293211599350458256866324942160707)

sage: bet = K(299196491040445553241951165617051874716829217278833896612973261174009330283715758515678905940210529602777565330455982982515099414428556955210176266584330790683846384281907046378906396818048462302829007217996998618862125614365444917802988738452913630023327621067471115458034040074393242514516474485808146482025)

Then tried to compute:

sage: %time discrete_log_rho(bet, K(2), K(2).order())

After that this irritating error appeared:

sage: %time discrete_log_rho(bet, K(2), K(2).order())
OverflowError Traceback (most recent call last)
<ipython-input-16-02136e0a9c28> in <module>()
----> 1 get_ipython().magic(u'time discrete_log_rho(bet, K(2), K(2).order())')

    /home/PRIVATE/sage-6.9-x86_64-Linux/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)    
       2334         magic_name, _, magic_arg_s = arg_s.partition(' ')    
       2335         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)    
    -> 2336         return self.run_line_magic(magic_name, magic_arg_s)    
       2338     #-------------------------------------------------------------------------    

    /home/PRIVATE/sage-6.9-x86_64-Linux/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)    
       2255                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals    
       2256             with self.builtin_trap:    
    -> 2257                 result = fn(*args,**kwargs)    
       2258             return result    

    /home/PRIVATE/sage-6.9-x86_64-Linux/local/lib/python2.7/site-packages/IPython/core/magics/execution.pyc in time(self, line, cell, local_ns)    

    /home/PRIVATE/sage-6.9-x86_64-Linux/local/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)    
        191     # but it's overkill for just that one bit of state.    
        192     def magic_deco(arg):    
    --> 193         call = lambda f, *a, **k: f(*a, **k)    
        195         if callable(arg):    

    /home/PRIVATE/sage-6.9-x86_64-Linux/local/lib/python2.7/site-packages/IPython/core/magics/execution.pyc in time(self, line, cell, local_ns)    
       1161         if mode=='eval':    
       1162             st = clock2()    
    -> 1163             out = eval(code, glob, local_ns)    
       1164             end = clock2()    
       1165         else:    

    <timed eval> in <module>()    

    /home/PRIVATE/sage-6.9-x86_64-Linux/local/lib/python2.7/site-packages/sage/groups/generic.pyc in discrete_log_rho(a, base, ord, operation, hash_function)    
        627         i0=0    
        628         nextsigma = 0    
    --> 629         for i in xrange(reset_bound):    
        630                     #random walk, we need an efficient hash    
        631             s=hash_function(x) % partition_size    

    OverflowError: Python int too large to convert to C long

I can't get my head around this problem, I've tried to edit replacing xrange by itertools as suggested in hxxp:// but the same problem still there!

Detailed solution: to be written here soon.

First of all as error suggests that xrange function cause some problem, the file /home/your_home/sage-6.9-x86_64-Linux/local/lib/python2.7/site-packages/sage/groups/ need to be edited.

add the line import itertools in the beginning of that file, then go direct to the function discrete_log_rho, look up for the last loop for, its location should be in line 631.Next, Define a new variable iterator = 1, replace "xrange(reset_bound):" by "itertools.count(1):" Finally, make sure to increase iterator by with each iteration, and to terminate for loop if the condition is satisfied. In the end you will have something like:

    itereator = 1 #By Triviality
    for i in itertools.count(1):
                #random walk, we need an efficient hash
        s=hash_function(x) % partition_size
        (x,ax,bx) = (mult(M[s],x), ax+m[s], bx ...
2016-01-04 13:13:58 -0500 received badge  Supporter (source)
2016-01-04 08:23:48 -0500 received badge  Nice Question (source)