Ask Your Question

mathochist's profile - activity

2023-07-15 00:28:38 +0100 received badge  Famous Question (source)
2022-06-16 18:32:21 +0100 received badge  Notable Question (source)
2021-08-20 01:33:44 +0100 received badge  Nice Question (source)
2021-05-21 19:49:45 +0100 received badge  Notable Question (source)
2021-01-19 06:48:51 +0100 received badge  Notable Question (source)
2020-12-10 08:03:02 +0100 received badge  Notable Question (source)
2020-10-14 06:50:04 +0100 received badge  Famous Question (source)
2020-09-06 21:33:39 +0100 received badge  Popular Question (source)
2020-06-23 04:17:59 +0100 received badge  Popular Question (source)
2020-04-19 08:14:53 +0100 received badge  Popular Question (source)
2020-03-14 08:51:06 +0100 received badge  Famous Question (source)
2019-11-25 11:08:48 +0100 received badge  Popular Question (source)
2019-11-25 11:08:48 +0100 received badge  Notable Question (source)
2019-01-14 02:26:13 +0100 received badge  Popular Question (source)
2019-01-14 02:26:13 +0100 received badge  Notable Question (source)
2017-04-11 04:38:13 +0100 received badge  Famous Question (source)
2017-03-16 10:27:46 +0100 received badge  Popular Question (source)
2017-01-03 21:49:08 +0100 received badge  Nice Question (source)
2016-12-02 21:31:02 +0100 commented answer 'object is not callable' error in sagetex (that doesn't occur in a worksheet)

Yes, thank you! I think I may have imported random in the worksheet on a different occasion, but I didn't think about that since I thought cells were only executed when you run them. If I import a package in a worksheet, I wonder if it should linger through subsequent sessions? But, yes, that worked; thanks again.

2016-11-28 20:00:55 +0100 asked a question 'object is not callable' error in sagetex (that doesn't occur in a worksheet)

I'm generating random numbers to be presented in scientific notation for a quiz I'm typing. In testing this code works fine in a worksheet, but gives an error in a sagesilent block of my .tex document. Here's the code:

sci = {}
for index in range(1, 14):     # Picks random coeffs for sci not.
    places = ZZ.random_element(0, 4)
    sci["co{0}".format(index)] = round(10*random(), places)
powe = {}
for index in range(1, 14):     # Picks random powers for use.
    powe["r{0}".format(index)] = ZZ.random_element(5, 10)
sci['co1']
sci['co2']
powe['r1']
powe['r2']

In the worksheet, those last four lines generate output like

3.0
5.566
7
8

But when I use that same code in the .tex document (without the last four lines), Sage returns this error before I can even call my numbers:

'module' object is not callable

My best guess is that rounding needs some package that the worksheet imports automatically but sagetex does not, but I'm afraid I don't know enough about what's really going on. Thank you for any help!

2016-11-28 19:32:19 +0100 marked best answer "showing" both input and output

Is there a way to get Sage to show the "pretty" versions of both the input and the output of a calculation, instead of just the output? (sort of like the TI-89 and such)

For example, when I enter as input "integrate(x^2, x, 0, 3)" it correctly returns 9. But can I get it to return something like (the typeset version of) \int_0^3 x^2 dx = 9 ? It's obvious enough in this example what I'm asking for but some queries get complicated and seeing them as they would be printed helps make sure I'm asking Sage for what I mean to ask for.

2016-11-28 19:19:34 +0100 received badge  Popular Question (source)
2016-11-28 19:19:34 +0100 received badge  Notable Question (source)
2016-11-28 19:16:59 +0100 commented answer Getting the leading term from random polynomials

Thanks very much, for that <tab> hint especially!

2016-11-24 16:24:30 +0100 received badge  Nice Question (source)
2016-11-22 19:45:34 +0100 asked a question Getting the leading term from random polynomials

Hi there. I'm writing self generating algebra tests for a class I teach. I'm using this code to generate random polynomials of various degrees up to 8 with single digit integer coefficients:

R.<x> = PolynomialRing(ZZ)
po = {}
for index in range(1, 10):          # Picks random polynomials for use.
    deg = ZZ.random_element(0, 8)
    po["ly{0}".format(index)] = R.random_element(deg, -9, 10)

To make the answer key, I'm attempting to show the polynomial, its degree, its leading term, and its leading coefficient of each polynomial. My code for that looks like:

po['ly1']
po['ly1'].degree(x)
po['ly1'].lt(x)
po['ly1'].lc(x)

Getting the degree works, but not the leading term or the leading coefficient. The errors I get are:

AttributeError: 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint' object has no attribute 'lt'

and

AttributeError: 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint' object has no attribute 'lc'

respectively.

I have been unable to ascertain from the documentation what the correct commands should actually look like. I have tried both ".lt()" and ".lt(x)" and similar for .lc. Please let me know, if you can, what my error is. Thank you.

2016-10-14 21:50:12 +0100 received badge  Famous Question (source)
2016-08-08 02:42:35 +0100 commented question Can I show ordered sets in order?

A better solution I found is to just LaTeX the parts I want. This makes the answer key look like an answer the student should give. After converting the Set X to the list X, I then put the code below in the answer key.

$\{\sage{X[0]}, \sage{X[1]},\sage{X[2]},... , \sage{X[len(X)-1]}\}$

I'm still curious about whether one can show sets in order, so for now I'll leave the question open.

2016-08-08 02:31:39 +0100 commented question Can I show ordered sets in order?

A less than 100% satisfactory workaround is to convert the Set to a list, sort the list, then show the list. This works for me ok, but it defeats my purpose if I share an answer key with my students and the answer key has the wrong notation (namely the square brackets of lists instead of the curly braces of sets).

2016-08-08 02:13:27 +0100 asked a question Can I show ordered sets in order?

I'm using SageTex to generate random algebra tests, with an answer key at the end. To have my students show they understand roster notation for sets, I'm having them write the set of all two-digit multiples of n for some number n in {2, 3, 4, ... 9}. Asking the question isn't hard. But in generating the answer key, the set shows up in random order. I know it's still the same set, of course, but it's less intuitive to interpret. It seems like Sage is going out of it's way to randomize the set. Here's some minimal working code:

n = Set(range(2, 10)).random_element()
X = Set()
for i in range(10, 100):
    if i % n == 0:
        X = X.union(Set([i]))
show(n)
show(X)

This shows, for example:

8

{32, 64, 48, 40, 80, 96, 16, 24, 56, 72, 88}

Is there some way to have Sage show the elements of the set in order?

2016-02-18 22:09:14 +0100 received badge  Notable Question (source)
2016-02-18 22:09:14 +0100 received badge  Popular Question (source)
2015-03-27 04:09:41 +0100 marked best answer Can I get a matrix to show with brackets instead of parentheses?

I'm using Sage and SageTeX to make worksheets and quizzes for my Linear Algebra course. I'd like my presentation to match the book's, and the book uses brackets around its matrices instead of parentheses. Is that doable? Is there a way, for example, to get latex(A) to generate

\left[\begin{array}{rrr} 6 & 6 & 1 \\ 7 & 0 & 6 \\ 4 & -7 & -7 \end{array}\right]

instead of

\left(\begin{array}{rrr} 6 & 6 & 1 \\ 7 & 0 & 6 \\ 4 & -7 & -7 \end{array}\right)

for some matrix A.

2015-03-27 04:09:34 +0100 marked best answer axis_thickness ?

I would like to like to increase the thickness of my axes on my plots. How might I do this?

Background: I am a teacher who uses sage to make my own graph paper. The axes look good on paper (although I'd like to have arrows on them), but when I project the pdf onto my white board (to draw on) the axes don't look much thicker than the gridlines (I'm using greyed instead of dashed gridlines). Here's my code:

k = 8
p = plot(k, (x, -k, k), 
     thickness = 0, 
     aspect_ratio = 1, 
     gridlines = True, 
     axes_labels=['$x$','$y$'], 
     ticks=[[-k..k],[-k..k]],
     tick_formatter = [['$-8$', '', '$-6$', '', '$-4$', '', '$-2$', '', '', '', '$2$', '', '$4$', '', '$6$', '', '$8$'], ['$-8$', '', '$-6$', '', '$-4$', '', '$-2$', '', '', '', '$2$', '', '$4$', '', '$6$', '', '$8$']], 
     gridlinesstyle = dict(color = "gray", linestyle = "-")
)
p += plot(0, (x, -k, k), thickness = 0) #to establish graph width
p += plot(-k, (x, -k, k), thickness = 0) #to establish graph height

show(p)

p.save('graph8l.pdf')
2014-12-10 20:22:46 +0100 asked a question LaTeX in plot not showing Greek letter

Hello. I'm using the following code to generate an image of a triangle for a trigonometry quiz.

p = polygon2d([[0,0], [0,3], [4,0]], fill = False, axes = False)
p += text("$\theta$", (3, 0.2), fontsize = 22)
show(p)

The issue is that Sage doesn't seem to recognise $\theta$ as LaTeX, even though it's in dollar signs. In the corner of the triangle, it puts "heta". Why isn't this typesetting correctly? How can I fix it?

Thank you.

2014-11-28 20:12:13 +0100 commented answer How can I recover the command to generate an object already created randomly?

The other answer helps me better, but I'm glad to know now how I might use the random seeds to my advantage. Thank you.

2014-11-28 20:11:21 +0100 marked best answer How can I recover the command to generate an object already created randomly?

I'm working in Sage side by side with a linear algebra test I'm writing in LaTeX (using sagetex). I'm generating random matrices until I find one I really like. Say I get this in Sage:

B = random_matrix(ZZ, 3, 3, algorithm='echelonizable', rank=3, upper_bound=10); B 
[ 1 -2  1]
[ 0  1 -2]
[-1 -2  8]

Is there a way to get Sage to generate the command to generate this matrix nonrandomly, i.e, return the command

B = matrix(QQ, [[1, -2 ,1], [0, 1, -2], [-1, -2, 8]])

so that I can copy and paste it into a sagesilent environment in my .tex file?

I can't think of what I might search for in the Sage documentation for such a command so I must ask here. Many thanks.