Skip to content

Commit

Permalink
python stuff
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.macaulay2.com/Macaulay2/trunk@8546 a8012f80-5f13-0410-8dc0-eb77bd940c0d
  • Loading branch information
DanGrayson committed Mar 14, 2009
1 parent d23183c commit 4b63a32
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions M2/Macaulay2/packages/Sage.m2
@@ -1,22 +1,12 @@
needsPackage "Python"
newPackage "Sage"
needsPackage "Python"
export { "sage", "plot", "plot3d", "implicitPlot" }
python0 = s -> (
if debugLevel > 1 then stderr << "python command: " << s << endl;
runSimpleString s)
python0 "sagedict = {}"
python1 = s -> python0 concatenate(
"eval(compile(", s, ",'dummyfile','single'),sagedict)")
python = s -> python1 format s
python "from sage.all import *"
python "x,y=var('x,y')"
sage = context("from sage.all import *", Preprocessor => "preparse");
sage.stmt "x,y=var('x,y')"
x := local x
y := local y
sageRing := QQ[x,y]
sage = s -> (
python concatenate("s = preparse(",format s,")");
python1 "sagedict['s']";
)
toSageRing := (f,n) -> (
R := ring f;
if not instance(R,PolynomialRing) then error "expected an element of a polynomial ring";
Expand All @@ -25,11 +15,11 @@ toSageRing := (f,n) -> (
p := map(sageRing,R,take({x,y},n));
p f)
plot = method()
plot String := s -> sage concatenate ("plot(",s,")")
plot String := s -> sage.stmt concatenate ("plot(",s,")")
plot RingElement := f -> plot toString toSageRing(f,1)
plot3d = method()
plot3d String := s -> sage concatenate ("plot3d(",s,", (x,-4,4),(y,-4,4))")
plot3d String := s -> sage.stmt concatenate ("plot3d(",s,", (x,-4,4),(y,-4,4))")
plot3d RingElement := f -> plot3d toString toSageRing(f,2)
implicitPlot = method()
implicitPlot String := s -> sage concatenate( "implicit_plot(",s,",plot_points=100)" )
implicitPlot String := s -> sage.stmt concatenate( "implicit_plot(",s,",plot_points=100)" )
implicitPlot RingElement := f -> implicitPlot concatenate( toString toSageRing(f,2), ",(x,-1.5,3),(y,-5,5)" )

0 comments on commit 4b63a32

Please sign in to comment.