First time here? Check out the FAQ!

Ask Your Question
1

pipe into stdin vs attach -- differences?

asked 10 years ago

Kevin Buzzard gravatar image

Here's some code, called slopes.sage:

def classical_slopes(N,p,r,k,i):
    assert p>2
    assert r>1 ## wild
    G=DirichletGroup(p^r) ## cyclic
    alpha=G[1]
    alpha_tame=alpha^(p^(r-1))
    alpha_wild=alpha^(p-1)
    K=alpha.base_ring() ## cyclotomic
    chi=alpha_tame^i*alpha_wild
    C=CuspForms(chi.extend(N*p^r),k)
    f=C.hecke_polynomial(p).base_extend(K)
    R=K.maximal_order()
    primroot=primitive_root(p) ## p>2
    X=R.ideal(p,alpha_tame(primroot)-primroot).factor()
    assert len(X)==1 ## ideal should be a prime power
    Qt = PolynomialRing(QQ, 't')
    P,e=X[0]
    c2=[2^(a.valuation(P)) if a!=0 else 0 for a in f.coefficients()]
    return (e,Qt(c2).newton_slopes(2))

# off we go. The import sys bit is to flush stdout.
import sys
N=3
p=5
for k in range(2,10):
    i=4-(k%4)
    print N,p,3,k,i,classical_slopes(N,p,3,k,i)
    sys.stdout.flush()

If I pipe it into sage like this:

sage < slopes.sage

I get the following output:

$ sage < slopes.sage 
┌────────────────────────────────────────────────────────────────────┐
 Sage Version 6.5, Release Date: 2015-02-17                         
 Type "notebook()" for the browser-based notebook interface.        
 Type "help()" for help.                                            
└────────────────────────────────────────────────────────────────────┘
sage: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: ....: sage: sage: sage: sage: sage: ....: ....: ....: ....: 
Exiting Sage (CPU time 0m0.03s, Wall time 0m0.20s).

But if I attach the file, within a sage console session, it runs as I expect it to run. Is this something to do with the pre-parser? If I've made a slip then that's great, but if it's harder than I think to pipe sage script into sage then I'd appreciate some tips as I would like to start a large sage job on a remote machine via ssh.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 10 years ago

nbruin gravatar image

You can do

sage slopes.sage

to run the file from the command line. The bad interaction is probably between the ipython readline interface and a non-tty stdin, not with the preparser. Note that IPython does some undesirable things for file input. For one thing, it uses auto-indent, which makes it hard or impossible to input some more complicated loops (unless you use %cpaste).

Sage or Ipython could check if stdin is a tty and revert to "file processing" (i.e., not use readline etc.) if it's not, but apparently (judging from your example) it doesn't.

In any case, the preparser does apply a few more efficient tricks (such as factoring out constants) when you use sage <file>, so it's better to use that if you can, rather than redirect the input. It has the side-effect of writing slopes.sage.py into the current directory, though.

Preview: (hide)
link

Comments

For what its' worth: this did not work for me initially, but then I realised why -- I had mis-installed sage in a silly way (and slopes.sage was not actually being passed to sage at all). Thanks as ever Nils.

Kevin Buzzard gravatar imageKevin Buzzard ( 10 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 10 years ago

Seen: 643 times

Last updated: Mar 14 '15