]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
Initial commit.
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 10 May 2012 13:29:56 +0000 (09:29 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 10 May 2012 13:29:56 +0000 (09:29 -0400)
README [new file with mode: 0644]
init.sage [new file with mode: 0644]
mjo/__init__.py [new file with mode: 0644]
mjo/all.py [new file with mode: 0644]
mjo/plot.py [new file with mode: 0644]
mjo/symbolic.py [new file with mode: 0644]

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..47ccc9f
--- /dev/null
+++ b/README
@@ -0,0 +1,9 @@
+My own personal library of Sage[1] code.
+
+It is intended to be loaded into every Sage session, or Python script
+which imports the Sage library. Sage loads ~/.sage/init.sage upon
+startup, so I've supplied a sample init.sage file which will load this
+code from ~/src/sage/.
+
+
+[1] http://www.sagemath.org/
diff --git a/init.sage b/init.sage
new file mode 100644 (file)
index 0000000..3f3905c
--- /dev/null
+++ b/init.sage
@@ -0,0 +1,9 @@
+import sys
+import os
+import site
+
+# Add '~/src/sage' to our path.
+sitedir = os.path.expanduser('~/src/sage')
+site.addsitedir(sitedir)
+
+from mjo.all import *
diff --git a/mjo/__init__.py b/mjo/__init__.py
new file mode 100644 (file)
index 0000000..8076a85
--- /dev/null
@@ -0,0 +1 @@
+# <3 git
diff --git a/mjo/all.py b/mjo/all.py
new file mode 100644 (file)
index 0000000..c3f0ef8
--- /dev/null
@@ -0,0 +1,7 @@
+"""
+Import all of the other code, so that the user doesn't have to do it
+in his script. Instead, he can just `from mjo.all import *`.
+"""
+
+from plot import *
+from symbolic import *
diff --git a/mjo/plot.py b/mjo/plot.py
new file mode 100644 (file)
index 0000000..d330123
--- /dev/null
@@ -0,0 +1,32 @@
+from sage.all import *
+
+# Save the default so that we can call it within mjo_plot.
+sage_plot = plot
+
+def mjo_plot(*args, **kwargs):
+    """
+    Replacement for the default plot function.
+
+     - Use the 'latex' tick formatter.
+
+     - If there's a legend, set the background color to 'white' and
+       give it a drop shadow.
+
+    """
+    plot_opts = { 'tick_formatter': 'latex' }
+    
+    legend_opts = { 'back_color': 'white',
+                    'shadow': True }
+
+    # Merge the user's plot options with mine. The ones given as
+    # kwargs should override the defaults!
+    plot_opts.update(kwargs)
+    kwargs = plot_opts
+    p = sage_plot(*args, **kwargs)
+    p.set_legend_options(**legend_opts)
+    return p
+
+# Replace both the global `plot` and the one in the module. I am
+# unclear about why this is necessary, and don't care too much.
+sage.plot.plot.plot = mjo_plot
+plot = mjo_plot
diff --git a/mjo/symbolic.py b/mjo/symbolic.py
new file mode 100644 (file)
index 0000000..e4c6d23
--- /dev/null
@@ -0,0 +1,45 @@
+from sage.all import *
+from sage.interfaces.maxima_lib import maxima_lib
+from sage.symbolic.expression import Expression
+
+
+def set_simplification_domain(d):
+    """
+    Set Maxima's simplification domain.
+
+    INPUT:
+
+      - d -- The domain, either 'real' or 'complex'.
+
+    """
+    cmd = 'domain: %s;' % d
+    result = maxima_lib._eval_line(cmd)
+    return result
+
+
+def safe_simplify(expr):
+    """
+    What should be a totally safe simplification operation that works
+    a little better than the plain simplify().
+
+    Uses a top-level function because we can't monkey-patch Cython
+    classes.
+    """
+    expr = expr.simplify_factorial()
+    expr = expr.simplify_log()
+    return expr
+
+
+def medium_simplify(expr):
+    """
+    A reasonably-safe set of simplifications, much better than
+    simplify() and safer than simplify_full()
+
+    Uses a top-level function because we can't monkey-patch Cython
+    classes.
+    """
+    expr = expr.simplify_factorial()
+    expr = expr.simplify_trig()
+    expr = expr.simplify_rational()
+    expr = expr.simplify_log()
+    return expr