Ask Your Question

PatrickSurry's profile - activity

2019-12-13 06:42:58 -0500 received badge  Notable Question (source)
2018-12-15 09:03:10 -0500 received badge  Self-Learner (source)
2018-12-15 05:50:41 -0500 received badge  Nice Question (source)
2018-03-17 12:10:22 -0500 received badge  Popular Question (source)
2016-05-22 13:09:55 -0500 received badge  Popular Question (source)
2015-11-16 07:07:05 -0500 received badge  Famous Question (source)
2015-10-22 18:48:12 -0500 received badge  Popular Question (source)
2014-08-28 15:54:32 -0500 received badge  Famous Question (source)
2013-10-20 09:50:05 -0500 received badge  Notable Question (source)
2013-09-16 07:30:51 -0500 received badge  Notable Question (source)
2013-06-20 07:58:45 -0500 received badge  Popular Question (source)
2013-06-01 03:19:39 -0500 received badge  Popular Question (source)
2012-12-12 02:49:26 -0500 commented answer Can I show equations in black rather than blue?

Great, thanks. You can also do it locally within a worksheet cell via: %html <style>div.cell_div_output_wrap { color: #000 }<style>

2012-12-06 14:29:50 -0500 received badge  Student (source)
2012-12-06 08:24:27 -0500 commented answer Eliminating variables from a system of equations?

My actual system of equations was a bit more complicated, but this seems to reproduce my issue. I guess I see what you're getting at. If I have m equations containing m+n free variables, then I need to "solve()" for at least m variables and, for each solution set, each variable will appear once on the left hand side, expressed in terms of the remaining n variables on the right hand side? So if I want to eliminate k variables from my system of m equations (in m+n unknowns), I should just "solve" for those k along with an arbitrary k-m other variables, and if I get a unique solution then I can replace my original system with the k-m equations corresponding to the non-eliminated variables?? Is there a way to ask Sage what variables are mentioned in an equation?

2012-12-06 08:14:53 -0500 asked a question Can I show equations in black rather than blue?

When I show() or view() an equation, it displays in blue. But when I refer to the same equation with a <sage> tag inside an html environment, it displays in black. Can I change the default color to black? I've tried passing various color options to show() but it doesn't seem to work.

2012-12-06 05:05:27 -0500 answered a question How can hide %hide?

You can also hide input cells using CSS styling. If you want to hide input cells in the interactive worksheet, add a cell at the start of the worksheet like this:

textarea.cell_input {display : none}

But then you need to edit the worksheet source to change none to inline to see your input again. The other option is to hide all your input just in the print view, e.g. if you're producing a nicely formatted PDF of all your results. To do that:

.cell_input_print {display : none}
2012-12-06 05:01:01 -0500 answered a question css print stylesheet

Using Google Chrome, you can look at the document source for the window you get via the 'print' button, and it seems to use the same stylesheets as the editable worksheet. It's not clear to me in either case where the user-provided notebook.css gets included. Both interactive and print versions respect style commands embedded directly in the notebook with a %html directive, for example to make my aligned equations (output with 3-column html.table() calls), I include a cell with:

table.table_form * tr.row-a { background: #ffffff; }
table.table_form * tr.row-b { background: #ffffff; }
table.table_form * td { padding-top: 5px; padding-bottom: 5px; padding-left: 2px; padding-right: 2px; }
table.table_form tr td:first-child { text-align: right; }

One thing I have noticed though, is that many of the elements are displayed with different CSS classes in the printed version. For example an input cell is class .cell_input in the editable worksheet, but .cell_input_print in the printed one.

This is actually handy - as noted above I've been using the worksheet to write a technical note with various graphs and equations in it, so using lots of %html sections with embedded <sage> tags. I don't want to have to cut & paste stuff to another document, I just wanted to use all my output cells as the document itself, so was using a trick I saw somewhere else to hide input cells using a style like this:

textarea.cell_input {display : none}

which makes all your input cells disappear. But it's a bit painful to have to keep editing the source for the worksheet to make them display: inline again whenever I want to change something (not to mention it didn't effect the print view!). So now I'm instead just using the print view as the final document by using this style:

.cell_input_print {display : none}

I also get it to center images (like plots) in the print view by adding:

.cell_output_box {width : 100%}
.cell_output_print_wrap * img { display: block; margin-left: auto; margin-right: auto }

I can print to PDF and I'm all set - the quality is actually pretty impressive!

2012-12-06 04:43:37 -0500 commented question embed sage vars in html notebook cell

Another interesting directive that I just stumbled on and didn't see documented is %hide, which seems to hide the remainder of your input cell text

2012-12-05 17:11:14 -0500 received badge  Good Answer (source)
2012-12-05 16:55:58 -0500 asked a question Public servers where I can publish (share) a notebook?

I've spent some time preparing a notebook I planned to share with others, but it seems like publishing (or at least viewing published notebooks?) is disabled at Is this a deprecated feature?

I thought it would be a great way to share a "living" version of a document that keen readers could then experiment further with. I guess I could just share my .sws file but that would mean extra steps of setting up a Sage account and uploading it before messing with it. But I suppose that is a workable alternative.

2012-12-05 16:44:30 -0500 commented question css print stylesheet

I'd like to know the answer to this too. I've been using a trick from another question to hide all my input cells, with my html and chart outputs forming something that looks a bit like a discussion paper. But when I use print, all my input reappears! (It would also be cool to have a button or special mouseclick to be able to hide/unhide input cells one by one as you're working to produce the commentary and displayed equations/derivations etc)

2012-12-04 15:46:22 -0500 commented answer Can I display a list of equations aligned like latex eqnarray?

Makes sense. Tho I've started doing all my text as %html so I can use the <sage> tags and avoid the pre-formatted (fixed width) text I seem to get with html()

2012-12-03 23:50:28 -0500 commented answer Can I display a list of equations aligned like latex eqnarray?

That's a good idea. If you add a %html cell you can improve the styling: avoid the alternating grey rows, tighten up the spacing, and right-align the leftmost column. I used this: %html <style> table.table_form * tr.row-a { background: #ffffff; } table.table_form * tr.row-b { background: #ffffff; } table.table_form * td { padding-top: 5px; padding-bottom: 5px; padding-left: 2px; padding-right: 2px; } table.table_form tr td:first-child { text-align: right; } </style>

2012-12-03 09:30:07 -0500 asked a question Can I display a list of equations aligned like latex eqnarray?

I have several sage equations stored in a python list (for use in solve() etc). I'd like to display them one per line, aligned on equal signs if possible. This is in the notebook.

Most things I've tried - view(), show(), pretty_print() just print something that looks like a python list of formatted equations, all on one line (although the documentation for view() claims it will print each element of a list on a separate line, that doesn't seem to be the case).

The only things I've come up with are to explicitly loop, like: for eqn in eqns: view(eqn) or to pass eqns to html.table() which does one per line with alternating line shading.

2012-12-03 06:25:22 -0500 received badge  Nice Answer (source)
2012-12-01 13:15:24 -0500 received badge  Teacher (source)
2012-12-01 13:15:24 -0500 received badge  Self-Learner (source)
2012-12-01 07:28:09 -0500 answered a question embed sage vars in html notebook cell

Aha! I did some code exploration of sage/misc/ and discovered the <sage> tag, so you can just write something like this in a a cell:

We can see that <sage>x</sage> is the key result

and it will do sage_eval() and format the result in math mode, so you get nice inline math display of the formula contained in x. That is exactly what I need - is that <sage> tag documented anywhere?

2012-12-01 00:53:18 -0500 asked a question embed sage vars in html notebook cell

Again I feel like I'm missing something. I'm trying to add some mostly text content to a notebook cell, but I want to include an equation contained in a notebook variable. For example I have defined

var('u, v, w')
x = u * v * w^2

And then I want to write a few paragraphs that includes the formula contained in x.

If I use the HTML editor and put something in dollar signs, it formats as math but doesn't eval the content, i.e. if I say $x$ then I just get a literal x in italics.

If I call the html() function, I can do something like html('testing $'+latex(x)+'$') to manually substitute myself, but this gets formatted in fixed-width font for reasons I don't understand.

If I start a cell with %html, then I can't figure out how to get the latex/html representation of the formula in x, but otherwise it formats it nicely. (I guess like an HTML editor cell)

Also, is there some documentation of how the different cell tags like %latex, %html, etc work?

2012-11-30 08:54:23 -0500 commented answer workaround for graphics_array needing prior show?

The save('/tmp/file.png') works perfectly, though I'm not sure I understand why it displays the first case but not the second (when it obviously can 'see' both files since it wrote them) - what logic does it use to decide whether to show it or not? I will have to take a look at the code.

2012-11-30 08:52:58 -0500 received badge  Supporter (source)
2012-11-30 06:52:41 -0500 asked a question workaround for graphics_array needing prior show?

I'm trying to use graphics_array to show a list of four simple plots. when I create the plots and display them straightaway in the graphics_array() it messes up the axis labeling and so on. I discovered via google that you can workaround that by first calling show() or save() on each of the graphs (I guess that finalizes their layout etc), and then call graphics array to combine them. But this results in each of the charts being shown individually before being shown in an array, which defeats the purpose.

The closest I've found is calling save('foo.pdf') on each of the charts, since it doesn't know how to display a PDF file you only get a link to 'foo.pdf'. I guess what I'd really like is save(filename, display=False) or something? (Of course ultimately I'd like graphics_array() to do the right thing in the first place and prepare each chart individually before compositing them)

Any ideas?

2012-11-28 12:14:18 -0500 received badge  Editor (source)
2012-11-28 12:13:42 -0500 answered a question Eliminating variables from a system of equations?

The best approach I've found so far is to define an eliminate(vars, eqns) procedure (see below) which attempts to remove all the listed vars from the system, so that:

var('x, y, z')
eqns = [ x^2 + y^2 == z, x == y]
view(eliminate([x], eqns))

gives [2y^2 == z] and solve(eliminate([x], eqns), z) gives me what I was after originally. But I figure I must be missing something obvious.

def eliminate(vars, eqns):
    """Eliminate the listed variables from the system of equations"""
    if type(vars) is not list: vars = [vars]
    if type(eqns) is not list: eqns = [eqns]

    # for each variable to be eliminated, 
    # look for an equation that contains it
    # and that we can solve uniquely for it
    for var in vars:
        soln = None
        for eqn in eqns:
            if var in eqn.args():
                soln = solve(eqn,var)
                if len(soln) == 1: break

        # if we found an equation determining the variable to be eliminated
        # substitute its value throughout, and omit the defining equation     
        if soln:
            val = soln[0].rhs()
            eqns = [e.subs({var : val}) for e in eqns if e is not eqn]

    # give back whatever we ended up with
    return eqns
2012-11-28 12:10:00 -0500 asked a question Eliminating variables from a system of equations?

I'm (very) new to Sage, but am confused about why I can't get it to solve a simple system like this:

var('x, y, z')
eqns = [ x^2 + y^2 == z, x == y]

but solve(eqns, z) gives an empty list back instead of my desired z = 2y^2