ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 08 Oct 2018 15:07:28 -0500Disable modules at compile-time or runtimehttp://ask.sagemath.org/question/43878/disable-modules-at-compile-time-or-runtime/ I'm building SAGE for a humble Raspberry Pi platform (although I'm currently experimenting compilation on a good computer), and given the power of the Pi target I'd like to build and use only a reduced part of SageMath's modules. Anything too far above the level of a high-school student can be cut off, I only plan to use exact calculus and basic analysis tools.
So far I've looked at the installation guide and tried a few things with the configure script, but I found no option to disable modules.
Is there anything planned for this purpose? Or do I have to build SageMath entirely no matter what?
I considered loading only part of the Python modules at runtime, but I figure SageMath will load the others when it sees fit.
Is there a way to disable part of SageMath at runtime?LepheMon, 08 Oct 2018 15:07:28 -0500http://ask.sagemath.org/question/43878/Load module from remote serverhttp://ask.sagemath.org/question/43778/load-module-from-remote-server/Hi, I am using a remote sage notebook public server (such as http://sage.math.canterbury.ac.nz/).
I would like to be able to load my own python modules, but I don't know how can I access local files, such as
import sys
sys.path.append('path-to-file-in-my-local-drive')
import module-name
Is there any way to do that?jllbThu, 27 Sep 2018 03:38:06 -0500http://ask.sagemath.org/question/43778/Power set with group operation as symmetric differencehttp://ask.sagemath.org/question/43507/power-set-with-group-operation-as-symmetric-difference/ My apologies for the novice question but I know that for a set X the powerset P(X) along with the symmetric difference (denoted by D) forms a group (P(X), D). I would like to form this group with sage and then build up a module over F = {0,1}. I've googled everywhere on how to go about this but I am having trouble. I can show these by hand and I would love to be able to formulate them in Sage. Thanks for your help. Samsam nazariTue, 28 Aug 2018 18:36:14 -0500http://ask.sagemath.org/question/43507/Rewriting number field related Magma code in Sagehttp://ask.sagemath.org/question/41224/rewriting-number-field-related-magma-code-in-sage/I have the following Magma code, which I want to rewrite in Sage:
G := Sz(8);
T := CharacterTable(G);
M := GModule(T[2]:SparseCyclo := false);
N := AbsoluteModuleOverMinimalField(M);
Currently, I have something like this:
from sage.all import *
proof.arithmetic(False)
G = SuzukiGroup(8)
T = gap(G).CharacterTable()
print(gap.eval("Display(%s)"%T.name()))
Though, I do not know how to rewrite the rest in Sage. `Sz` in Magma is Suzuki group. The result of `M` here is `GModule M of dimension 14 over Cyclotomic Field of order 52 and degree 24`. Also, the result of `T[2]` in Magma is `T[2] = ( 14, -2, 2*zeta(4)_4, -2*zeta(4)_4, -1, 0, 0, 0, 1, 1, 1 )`. `AbsoluteModuleOverMinimalField` is defined [here](https://magma.maths.usyd.edu.au/magma/handbook/text/1038#11747).ninhoWed, 21 Feb 2018 14:39:53 -0600http://ask.sagemath.org/question/41224/Loading a module causes the __name__ == '__main__' block to executehttp://ask.sagemath.org/question/38164/loading-a-module-causes-the-__name__-__main__-block-to-execute/I have a module that can also be run from the command line:
def func()
print('Hello!')
if __name__ == '__main__':
func()
When I try to load it in Sage, the main block is executed:
sage: load('module.sage')
Hello!
sage:
The bigger problem is that the main block parses command line arguments and Sage aborts the load with an error because it didn't receive any command line arguments. Is there any way to handle this? I can preparse `module.sage` and import it as a Python module, but its so much easier to `attach('module.sage')` than having to `reload(module)` every time I change it when I'm editing.
jaebondSun, 02 Jul 2017 09:44:02 -0500http://ask.sagemath.org/question/38164/How to compute syzygy module of an ideal in a quotient ring?http://ask.sagemath.org/question/37320/how-to-compute-syzygy-module-of-an-ideal-in-a-quotient-ring/I am trying to compute the syzygy module of an ideal generated by two polynomials `<p,q>` modulo `I`, where `I` is another ideal. This means to compute a generating set `[(p1,q1),...,(ps,qs)]` of the module `{(g,h): gp+hq is in I}`. I know that in Sage, we can use singular command to compute syzygy module:
R.<x,y> = PolynomialRing(QQ, order='lex')
f=2*x^2+y
g=y
h=2*f+g
I=ideal(f,g,h)
M = I.syzygy_module();M
[ -2 -1 1]
[ -y 2*x^2 + y 0]
But this does not work with modulo `I`:
R.<x,y> = PolynomialRing(QQ, order='lex')
S.<a,b>=R.quo(x^2+y^2)
I=ideal(a^2,b^2);I
M = I.syzygy_module();M
Ideal (-b^2, b^2) of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2)
Error in lines 4-4
Traceback (most recent call last):
Is there a way to do that?KittyLTue, 18 Apr 2017 04:34:27 -0500http://ask.sagemath.org/question/37320/How to treat a vector space as a group?http://ask.sagemath.org/question/33990/how-to-treat-a-vector-space-as-a-group/
I need to use a module as a group, so that I can define a group algebra over this module.
Essentially, I want to take the group of 2-dimensional complex vector space and define a group algebra over this. I cannot find appropriate direction on the internet and sage gives me the ridiculous "False" as below.
sage: V=FreeModule(CC,2)
sage: V in Groups()
False
Nihar GargavaFri, 01 Jul 2016 12:27:43 -0500http://ask.sagemath.org/question/33990/Can I make a module out of a worksheet?http://ask.sagemath.org/question/33017/can-i-make-a-module-out-of-a-worksheet/ I have been using save_session and load_session to re-use symbolic expressions and dictionaries across worksheets, but I still need to re-type all sorts of python functions (e.g. def fun()...), which cannot be pickled. Now I am wondering whether there is a way to automatically create a .py file out of a worksheet, i.e. a module that contains all code from a worksheet, excluding html comments. This could then be loaded as a module in other worksheets, allowing also to keep the namespaces separate, which would be awesome. Does anyone know of a script/method to do this?stanWed, 06 Apr 2016 07:24:54 -0500http://ask.sagemath.org/question/33017/Executing python modules from packagehttp://ask.sagemath.org/question/25041/executing-python-modules-from-package/I have a project that is primarily written in python but uses sage for some specific operations. In order to facilitate this I have only .py files and use `from sage.all import *` at the top of all modules that make use of sage functionalities. To execute I always used `sage -python path/to/file.py`.
This approach worked fine until it became necessary to split my project into multiple sub-packages. I now want to execute my modules with `python -m package.subpackage.module` for modules that do not use sage (which works) and correspondingly `sage -python -m package.subpackage.module` for modules that do. Unfortunately the latter only returns an error message of the form `~/sage/local/bin/python: No module named package.subpackage`
In order to be able to use package relative imports I am kind of dependent on the -m syntax, so I would like to get it to work. Any ideas what I am doing wrong? Or is this simply not possible with the python that is bundled with sage for internal reasons? Any help is apreciated!kekxFri, 28 Nov 2014 13:24:51 -0600http://ask.sagemath.org/question/25041/Adding Code To My SageMath Notebookhttp://ask.sagemath.org/question/11052/adding-code-to-my-sagemath-notebook/I have written a class, LRC, using the Sage Notebook which works just fine. Now I would like to put it into my sage environment without including it on each worksheet.
Before I go on I should describe my environment a bit. I am running a windows 7 machine with Virtual Box. I imported a Sage Notebook virtual machine and run it. The virtual box shares some of the drive space with the windows machine, in particular a spot called D:\unixshare
So I extracted the code from the cell to a file and placed it at D:\unixshare\forLRC\LRC.py which at least in theory available to the virtual box machine.
In a new worksheet I put this in a cell.
import sys
sys.path.append('/media/sf_D_DRIVE//unixshare/forLRC') # move your python files here
import LRC
lrc = LRC()
.-.-.-.-.-.-.-.-.-.-
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_4.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("aW1wb3J0IHN5cwpzeXMucGF0aC5hcHBlbmQoJy9tZWRpYS9zZl9EX0RSSVZFLy91bml4c2hhcmUvZm9yTFJDJykgIyBtb3ZlIHlvdXIgcHl0aG9uIGZpbGVzIGhlcmUKCmltcG9ydCBMUkMKCmxyYyAgICA9IExSQygp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpMF8IdA/___code___.py", line 5, in <module>
import LRC
File "/media/sf_D_DRIVE//unixshare/forLRC/LRC.py", line 22, in <module>
class LRC( object ):
File "/media/sf_D_DRIVE//unixshare/forLRC/LRC.py", line 31, in LRC
var( "myOmega" ) # sometimes used as the angular frequency
NameError: name 'var' is not defined
I did get a new file: D:\unixshare\forLRC\LRC.pyc
So I have a problem that does not let me go any farther. I am not a particularly experienced python programmer, but have programmed in various languages for some time. Some help? Thanks.
russ_henselMon, 17 Feb 2014 14:11:05 -0600http://ask.sagemath.org/question/11052/Use memory profile (python module) in SAGEhttp://ask.sagemath.org/question/10460/use-memory-profile-python-module-in-sage/Hi experts.
I want to use memory profile (decoretor module) for see a RAM memory porfile of my scipt:
https://pypi.python.org/pypi/memory_profiler
in sage.
Following the web page instructions and the post
http://ask.sagemath.org/question/1382/how-do-i-install-python-modules-or-use-a-different
I installed doing:
$ sudo sage --python setup.py install
When I run the scrip with @profile decorator, I obtain
Filename: <string>
ERROR: Could not find file <string>
What am I doing wrong?
Please explain this to me step by step (i'm a totally newby linux and python user).
Thanks a lot!mresimulatorTue, 20 Aug 2013 11:43:29 -0500http://ask.sagemath.org/question/10460/Internal Python: `No module named all`http://ask.sagemath.org/question/7517/internal-python-no-module-named-all/## Please Note
This is not a duplicate because the other people who've got that error message all were using an external python installation instead of `sage -python /path/to.py`
## My Situation
I'm **not able to** execute scripts the following ways:
- `sage /path/to.sage` (preprocessed)
- `sage /path/to.spyx`
- `sage /path/to.py`
- `sage -python /path/to.py`
But I'm able to run correctly **without problems**:
- `sage $ load 'file'`
## The Traceback
When `cython` compiles an `.spyx` file:
Traceback (most recent call last):
[...]
File "_home_user_Dokumente_oak_code_sage_spyx_0.pyx", line 14, in init _home_user_Dokumente_oak_code_sage_spyx_0 (_home_user_Dokumente_oak_code_sage_spyx_0.c:754)
sg.var('a b c')
AttributeError: 'module' object has no attribute 'var'
The statement that there's no `var` in the loaded module seems to be true because `dir(sg)` wasn't able to find anything else than `__doc__` and other "underscored items".
When `python` tries to execute file (normal handwritten `.py` or a `sage` preprocessed `.sage`):
Traceback (most recent call last):
File "sage2.py", line 2, in <module>
from sage.all_cmdline import * # import sage library
File "/home/user/Dokumente/oak/code/sage.py", line 4, in <module>
import sage.all as sg
ImportError: No module named all
## The Source
#!/usr/bin/env sage -python
import sys
import sage.all as sg
print '== TESTOUTPUT =='
sg.var('a b c')
## The Environment
My system setup:
Ubuntu 12.4 LTS
743,6 MiB64
AMD Athlon(tm) II X4 620 Processor
64 Bit
My environment variables:
[...]
declare -x LD_LIBRARY_PATH="/opt/sage/local/lib"
declare -x LESSCLOSE="/usr/bin/lesspipe %s %s"
declare -x LESSOPEN="| /usr/bin/lesspipe %s"
declare -x LIBRARY_PATH="/opt/sage/local/lib/"
[...]
declare -x PATH="/opt/sage:/opt/sage/local/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
declare -x PWD="/home/jk/Dokumente/oak/code"
declare -x PYTHONHOME="/opt/sage/local"
declare -x PYTHONPATH="/opt/sage/local/lib/python"
declare -x RANLIB="ranlib"
declare -x RHOME="/opt/sage/local/lib/R"
declare -x RM="rm"
declare -x SAGE64="no"
declare -x SAGE_DATA="/opt/sage/data"
declare -x SAGE_DOC="/opt/sage/devel/sage/doc"
declare -x SAGE_EXTCODE="/opt/sage/spkg/installed/extcode-5.7"
declare -x SAGE_LOCAL="/opt/sage/local"
declare -x SAGE_ORIG_LD_LIBRARY_PATH="/opt/sage//local/lib"
declare -x SAGE_ORIG_LD_LIBRARY_PATH_SET="True"
declare -x SAGE_PACKAGES="/opt/sage/spkg"
declare -x SAGE_ROOT="/opt/sage"
declare -x SAGE_SERVER="http://www.sagemath.org/"
declare -x SAGE_SHARE="/opt/sage/local/share"
declare -x SAGE_STARTUP_FILE="/home/user/.sage//init.sage"
declare -x SAGE_TESTDIR="/home/user/.sage//tmp"
[...]
declare -x __sage__=""
## The Question
How can I get `sage -python` (`sage`'s internal `python`) to **execute** the files specified as command line argument **correctly**? How can I get `sage.all`'s members to get `import`ed correctly?
Thanks - if anything's unclear concerning my question, please leave a comment. fdj815Tue, 05 Mar 2013 07:43:39 -0600http://ask.sagemath.org/question/7517/Programming with Sage: defining modulehttp://ask.sagemath.org/question/8585/programming-with-sage-defining-module/Let's say I want to write two modules 'addition.sage' and 'result.sage'.
I would like to import 'addition.sage' in 'result.sage'. How can I do this?
I've try the following, but it doesn't seem to work.
'addition.sage' file:
`from sage.all import *`
`add(x,y)=x+y`
'result.sage' file:
`from addition import add`
`print add(1,2)`
my sage session:
`sage: load('myPath/result.sage')`
This gives me the error 'ImportError: No module named addition'.
Although, my PYTHONPATH contains the directory where my two modules are located.Nicolas Essis-BretonWed, 21 Dec 2011 08:52:47 -0600http://ask.sagemath.org/question/8585/How can I re-code a function into a method?http://ask.sagemath.org/question/8482/how-can-i-re-code-a-function-into-a-method/I have the following simple function 'add4' stored in a file 'foo.sage':
def add4(x):
"""Adds 4 to x"""
return x + 4
I can use this in sage by:
sage: attach 'foo.sage'
sage: add4?
Type: function
Base Class: <type 'function'>
String Form: <function add4 at 0x4f332a8>
Namespace: Interactive
File: Dynamically generated function. No source code available.
Definition: add4(x)
Docstring:
Adds 4 to x
sage: var('x')
x
sage: add4(x)
x + 4
How can I change my function to a method so that I can call it using the x.add4() syntax? I still want the method to reside in an external file.
rtrwalkerWed, 16 Nov 2011 11:57:28 -0600http://ask.sagemath.org/question/8482/SAGE moduleshttp://ask.sagemath.org/question/8214/sage-modules/Hello!
I am new to sage, how do you install new Python modules in Sage? This module can't be installed by easy_install and you need to do the following in the downloaded package
python setup.py install
But how do you install and use it in Sage?riemannWed, 06 Jul 2011 10:10:45 -0500http://ask.sagemath.org/question/8214/[sagenb] load moduleshttp://ask.sagemath.org/question/7893/sagenb-load-modules/How do you add existing Sage/Python Scripts as a module to the sagenb such that it loads automatically every it starts?
Thanks!riemannThu, 30 Jun 2011 05:02:41 -0500http://ask.sagemath.org/question/7893/Sage relation to Pythonhttp://ask.sagemath.org/question/8045/sage-relation-to-python/Bear with me here..
I'm still struggling to use regular Python with Idle Ipython and the like.. And also Sage.
What I'm not real clear on is if I can treat Sage Notebook as another Python Development environment?
If so how do I save and recall, execute and edit plain .py files in Sage.. I've probably just missed it?dartdogFri, 29 Apr 2011 19:35:54 -0500http://ask.sagemath.org/question/8045/How do instantiate a new class properly?http://ask.sagemath.org/question/8013/how-do-instantiate-a-new-class-properly/## Background ##
I have created a new class `FeynmanGraph` that is a subclass of `Graph`. It has some extra methods, and the module in which it lives also has some extra functions. The most important method for my purposes searches for possible colorings of the vertices that satisfy certain combinatorial criteria that have to do with spanning trees. (The details are not important here.)
The code works. I should mention that I'm editing `feynman.sage` in a text editor and attaching it to a sage session in a terminal. Once a I create an instance of the class via
> `G = FeynmanGraph(...)`
everything seems to work.
Now, I created a module in which I would like to define specific graphs, with specific labeling of the vertices and edges, as well as plot positioning information. Shouldn't I be able to import the module `feynman` and make definitions such as the following?
> `from feynman import *`<br>
> `def FatY(): # a particular graph`<br>
> `G = FeynmanGraph(...)`<br>
> `...`<br>
> `return G`
When I do this, the methods for `FeynmanGraph` raise all kinds of errors of the type where they don't recognize various functions, such as `max` or `partitions_set`.
## Question ##
How do I structure the modules and classes so that I can instantiate the class properly?Sammy BlackFri, 18 Mar 2011 21:23:26 -0500http://ask.sagemath.org/question/8013/Writing portable Sage modulehttp://ask.sagemath.org/question/7811/writing-portable-sage-module/I've been working on a bit of code that is of interest to a bunch of people but far too specific to even be considered for inclusion in Sage. Is it possible to package my code as an spkg, put the binary on a server somewhere, and then have interested parties install it by typing `./sage -t url-to-package`? Or should I just stick to distributing my `.sage` files as tarball?
Sorry if this is already in the developer manual! However, when I checked, most of the instructions dealt with preparing an spkg and submitting it to the trac server, which is not what I want to do.jvkerschSun, 12 Dec 2010 15:43:36 -0600http://ask.sagemath.org/question/7811/Import sage python modulehttp://ask.sagemath.org/question/7824/import-sage-python-module/Hi!
I've been trying to setup sagemath in order to use the sage python module by importing it in an other python project. I'm trying to get the same thing that i get when calling:
./sage -python
Is there a deployment script/python egg that install the module in dist-package? Is there a folder i can add to my python path?
So far I downloaded the "sage-4.6-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux.tar.lzma" version and unpacked it to "/opt/sage" while changing sure to update the "SAGE_ROOT" in /opt/sage.
I know there must be a way to do so because [FAQ](http://wiki.sagemath.org/faq#HowdoIimportSageintoaPythonscript.3F) mentions it. Python 2.6 is already bundled with my machine so i guess all I have to do is add a folder to my python path?charettesSun, 19 Dec 2010 06:51:53 -0600http://ask.sagemath.org/question/7824/