Take the 2-minute tour ×
Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. It's 100% free, no registration required.

I always calculate things by hand, but now my comrades are getting nasty and making a lot of repetitive exercises involving just plugging things in like the expression above. I am particularly interested in open-source software such as Python or R to simplify these kinds of equations. I tried using Wolfram Alpha, but I was unsuccessful. What open-source software packages are able to substitute the expression $x=\sqrt{2}t-1$ into the equation $x^{2}+2x+3$ and simplify the result? Specifically, I am looking for a software package that has something like a simplify command.

share|improve this question
add comment

7 Answers 7

up vote 24 down vote accepted

You may want to look into SymPy, which is a Python library with your desired simplify command.

>>> from sympy.abc import t
>>> import sympy
>>> x = t*2**(1/2) - 1
>>> x**2 + 2*x + 3
2*t + (t - 1)**2 + 1
>>> sympy.simplify(x**2 + 2*x + 3)
t**2 + 2
share|improve this answer
2  
I was going to suggest Sage, but it appears not to have symbolic capabilities yet, although one would think that it'd eventually incorporate a symbolic capability because it aims to become an open-source alternative to Maple and Mathematica. –  Geoff Oxberry Jan 31 '12 at 2:21
    
Sage does have symbolic capabilities (I've used it to do symbolic integrals), but it's not especially clear how to do so unless you look for it. If you want to use a as a symbol, you have to declare it beforehand, as in var('a'). At least this was true when I was last using sage frequently 3 or 4 years ago. In general, mathematica assumes that you want a symbolic result and sage assumes you want a numerical result. –  Dan Jan 31 '12 at 8:11
    
@hhh: Unless I'm mistaken, your code fragment doesn't correspond to the expression you wish to evaluate and simplify. –  Geoff Oxberry Jan 31 '12 at 19:52
    
@GeoffOxberry: I tried to fix that problem, as well as one in the LaTeX in the original question. –  Jack Poulson Jan 31 '12 at 20:11
    
My understanding is that Sage actually incorporates much of the SymPy codebase. –  MRocklin Feb 1 '12 at 0:26
add comment

You got several good answers already with high quality advanced open source packages.

I'd like to point to http://www.mathics.net/ (http://mathics.org/ if you want to download it), which is an open source CAS using the Mathematica syntax (which you may be familiar with a little bit if you're used WolramAlpha). It is not nearly as complete as any of the other suggestions you got. But it can do the (very simple) operations you talked about in your question.

What you are talking about in your question is not really simplification, but substitution and expansion (which, unlike more complex simplification, are very easy to implement operations available even in the most basic CAS):

In Mathics it would look like this:

eq = x^2 + 2x + 3

eq /. x -> Sqrt[2] t - 1

Expand[%]

In case you need a simplification function, it's called Simplify[], and would also work in place of Expand[] in the example above.

share|improve this answer
add comment

Sage can do that (you're going to have to scroll pretty far down the page to get to the simplification part).

Also, make sure you read the general introduction to symbolic math in Sage. It's semantics and syntax are quite different from Mathematica, which is what most people are familiar with.

Here's an example from the documentation I linked you to:

sage: var('x,y,z,a,b,c,d,e,f')
(x, y, z, a, b, c, d, e, f)
sage: t = a^2 + b^2 + (x+y)^3
# substitute with keyword arguments (works only with symbols)
sage: t.subs(a=c)
(x + y)^3 + b^2 + c^2

For your case, this should work:

var(f,x,t)
f=x^2+2*x+3
f.subs(x=(sqrt(2)*t-1))
f.simplify()
share|improve this answer
    
Their documentation search engine needs to improve, then. I typed in "simplify" and didn't get that page at all. Nice find! –  Geoff Oxberry Jan 31 '12 at 3:57
    
I just typed "sage simplify" into google. –  Dan Jan 31 '12 at 5:49
add comment

As akid suggested, wxMaxima is a great graphical front end to the venerable lisp based Computer Algebra System called Maxima.

Using your example, you would get something like:

(%i1) eq1: x=t*2**(1/2)-1;
(%o1) $x=\sqrt{2}t-1$
(%i2) eq2: x**2+2*x+3;
(%o2) $x^{2}+2x+3$
(%i3) eq3: subst(eq1, eq2);
(%o3) $(\sqrt{2}t-1)^2+2(\sqrt{2}t-1)+3$
(%i4) ratsimp(eq3);
(%o4) $2t^2+2$

or you could just do it directly:

(%i5) ratsimp(subst(x=t*2**(1/2)-1, x**2+2*x+3));
(%o5) $2t^2+2$

Maxima has a number of different ways of simplifying, but ratsimp is a good first step.

share|improve this answer
add comment

wxMaxima can simplify expressions. I believe it's supposed to be a substitute for Maple.

share|improve this answer
add comment

I think I was able to get Wolfram Alpha to work. Maybe I'm wrong about what you're looking for.

share|improve this answer
add comment

open source: maxima. And check Wikipedia for an overview.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.