Ask Your Question

ml9nn's profile - activity

2023-07-15 04:50:49 +0200 received badge  Notable Question (source)
2023-07-15 04:50:49 +0200 received badge  Popular Question (source)
2022-04-23 16:17:13 +0200 received badge  Famous Question (source)
2020-09-08 18:32:56 +0200 received badge  Notable Question (source)
2020-02-27 10:04:13 +0200 received badge  Famous Question (source)
2020-01-31 00:01:22 +0200 received badge  Popular Question (source)
2019-03-15 15:20:28 +0200 received badge  Notable Question (source)
2018-09-12 00:33:20 +0200 received badge  Popular Question (source)
2018-06-25 21:12:25 +0200 asked a question codomain could not be determined

I created an InfiniteDimensionalFreeAlgebra using CombinatorialFreeModule. It looks something like this:

class InfiniteDimensionalFreeAlgebra(CombinatorialFreeModule):
    r""" The algebra generated by ``a[0], a[1], a[2], ...`` over the integers. """
    def __init__(self,
            base_ring=IntegerRing(),
            prefix='a',
            index_set=NonNegativeIntegerSemiring()):
        self._base_ring = base_ring
        self._basis_monoid = FreeMonoid(index_set=index_set, commutative=True, prefix=prefix)
        # category
        category = Algebras(self._base_ring.category()).WithBasis().Commutative()
        category = category.or_subcategory(category)
        # init
        CombinatorialFreeModule.__init__(
            self,
            self._base_ring,
            self._basis_monoid,
            category=category,
            prefix='',
            bracket=False)

Now I want to view it as a ring and take symmetric polynomials over the ring. For example, in 2 variables, the following is one such symmetric polynomial:

2a[7] * x[1] + 2a[7] * x[2] + x[1]x[2] + 5

In my code, I attempt to initialize some Schur symmetric functions over this ring with something like:

a = InfiniteDimensionalFreeAlgebra()
sym = SymmetricFunctions(a)
s = sym.s()
one = s.one()
one_poly = one.expand(2)

at which point I run into the error codomain could not be determined when it attempts to apply some sort of morphism to the Schur function one. The full stacktrace is

Traceback (most recent call last):
  File "./test_all.py", line 1162, in <module>
    h = double_homogeneous(1, 1)
  File "/Users/Matthew/programming/sage/morse-code/k_combinat_for_sage/all.py", line 664, in double_homogeneous
    one_poly = one.expand(n)
  File "/Users/Matthew/programming/sage/official-git-repo/local/lib/python2.7/site-packages/sage/combinat/sf/schur.py", line 537, in expand
    return self._expand(condition, n, alphabet)
  File "/Users/Matthew/programming/sage/official-git-repo/local/lib/python2.7/site-packages/sage/combinat/sf/sfa.py", line 4986, in _expand
    return parent._apply_module_morphism(self, f)
  File "/Users/Matthew/programming/sage/official-git-repo/local/lib/python2.7/site-packages/sage/categories/modules_with_basis.py", line 1096, in _apply_module_morphism
    raise ValueError('codomain could not be determined')
ValueError: codomain could not be determined

and the full code can be found at k_combinat_for_sage.

Thank you, your help is greatly appreciated.

2018-02-21 14:19:49 +0200 received badge  Nice Answer (source)
2018-02-21 11:24:06 +0200 received badge  Teacher (source)
2018-02-21 11:24:06 +0200 received badge  Self-Learner (source)
2018-02-21 01:20:22 +0200 answered a question testing sage code

When working with sage, the recommended test environment is to use sage's built-in test runner. In this system you write your tests for a function into its docstring. For example, consider myfile.sage:

def my_function(n): 
   r""" Regular old docstring stuff, explaining what the function does.  And then...

    TESTS::

        sage: my_function(1)
        23
        sage: my_function(2)
        91
    """
    do stuff
    return result

To run the tests, use the sage command but with the -t option. So in this example, execute sage -t path/to/myfile.sage. Sage will run the tests, verifying that the code my_function(1) outputs 23. There is a small nuance to be aware of here. It basically tries to simulate the interactive sage shell. So even though my_function(1) outputs the number 23, the string 23 is what is outputted to the interactive sage shell for printing. Whatever string representation would appear in the interactive sage shell is checked against what you type.

If one of your tests fail, this environment will tell you the output that your code generated so that you can compare it to the output you expected!

2018-02-03 23:52:02 +0200 commented answer testing sage code

Thank you for your responses, Dan. I appreciate your time and effort. I will get back to this thread in a few days.

2018-02-03 18:09:44 +0200 commented answer import sage packages in python

But this suggestion results in ImportError: cannot import name ZZ.

2018-02-03 17:58:17 +0200 commented question Error importing ZZ

This is a very good question and could really use an answer from an expert!

2018-02-03 17:44:16 +0200 commented answer Error importing ZZ

For me, it takes about 3.5 seconds to from sage.all import * and about 3.5 seconds to import sage.all and about 3.5 seconds to from sage.all import ZZ, which makes this suggested strategy defeat the purpose of loading modules individually as-needed in order to save time.

2018-02-03 04:52:41 +0200 commented question Best way to convert Maple to sage

This question is much more specific than the title suggests. Perhaps the title should be altered. People who are interested in translating Maple code to sage in general will fall upon this page. Those people might benefit from visiting https://doc.sagemath.org/html/en/refe... instead.

2018-02-03 04:47:32 +0200 commented question line number of error in .sage file

My original file is called file.sage (the ".sage file"). When I execute it via the terminal command sage file.sage, then the file file.sage.py (the ".py file") is automatically generated. I hope this clarifies the issue for you.

2018-02-03 04:20:40 +0200 commented answer testing sage code

Yes, Iguananaut is right. Perhaps the IDE's were recommended because they have some debugging capabilities. But really I just want pytest or similar "unit testing" capabilities. The part of this answer about pytest seems relevant, with the exception that it doesn't import any code written by the programmer. Could I add import myfile.sage or load('myfile.sage') to the top of this pytest_sagetest.py file? I have tried that already to no avail. How can I import my code?

2018-02-03 00:02:14 +0200 received badge  Editor (source)
2018-02-02 23:57:55 +0200 commented question testing sage code

@Iguananaut I am talking about writing my own code in the Sage language. I currently write code and save it in .sage files. Perhaps there is another recommended way to write Sage code in a convenient way that I don't know of.

2018-02-01 16:21:34 +0200 received badge  Nice Question (source)
2018-01-30 23:47:45 +0200 asked a question line number of error in .sage file

When sage reports an error, it reports the line number of the .py file where the error occured. I am wondering if there is a way to configure sage so that it instead reports the line number of the code in the .sage file that ultimately generated that problematic line in the .py file.

This would be useful because it is the .sage file that I am actually editing.

This is theoretically possible: other languages and transpilers use sourcemaps to solve this same issue.

2018-01-30 23:39:06 +0200 received badge  Scholar (source)
2018-01-30 23:39:00 +0200 received badge  Supporter (source)
2018-01-30 20:48:10 +0200 asked a question testing sage code

I am having difficulty creating a convenient environment for testing. I typically use pytest when programming in python. One of the nice features of pytest is that on an assertion error

assert a == b

it will tell you what the values of a and b were. I can't seem to get pytest to work with sage. Is it possible to make pytest work with sage? If not, are there other recommended testing/debugging tools to use while writing sage code? (In particular, I want to write unit tests for my code.)

2016-08-09 21:54:20 +0200 received badge  Student (source)
2016-08-05 23:22:31 +0200 asked a question Where is sage installed?

This seems like a simple question, but I am looking for an in-depth answer.

I did a manual installation on OSX by downloading the sage tar file and running make. I now have a sage-7.2 folder which seems to contain all of sage.

For example, sage doesn't seem to use any python libraries on my computer, but instead installs all python libraries locally in sage-7.2/local/lib/python2.7.

Are there any large libraries/files that sage installs that are NOT in the sage-7.2 folder? About how much space do these external files take up?