user93353
user93353

Reputation: 14049

sagemath: How to find the right import library names for writing a python prog to load from sage

Newbie to SageMath. Tried out different things from the Console & it worked fine. Now I want to automate into Python Program.

The same function which I call from the sage console is giving a NameError: name '<xxxx>' is not defined. I am assuming I have to import some modules in my python program. But there doesn't seem to be an easy way to figure out which one to import.

For e.g. in Java, let's say I want to use HashMap, I just google HashMap java & the first hit I get is https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html

Which clearly tells me that I have to import it from java.util.

I can't find something similar for sagemath.

Now this is the code I want to call from my sagemath python program

c = <somenumber>
n = <somenumber>

r = Modular(c, n).sqrt()

I obviously get the error NameError: name 'Modular' is not defined

How do I find out what I have to import to fix this error?

I googled for sagemath Modular and went through a couple of pages of results & I couldn't find what I have to import in an easy way.

Obviously, my first priority here is to figure out what to import for calling Modular & sqrt but the bigger question is how to do this everytime.

How is this done by sagemath users?

Upvotes: 1

Views: 257

Answers (1)

Samuel Leli&#232;vre
Samuel Leli&#232;vre

Reputation: 3453

I think you want Mod and not Modular.

To get the correct import statements, in a Sage session, try:

sage: import_statements(Mod)

which will suggest:

from sage.rings.finite_rings.integer_mod import Mod

Upvotes: 2

Related Questions