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.
- 7,599
- 32
- 40
8 Answers
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
- 30,394
- 9
- 64
- 127
- 7,599
- 32
- 40
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()
- 3,355
- 3
- 21
- 47
-
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 03:57
-
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.
- 2,620
- 2
- 19
- 34
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.
- 2,426
- 19
- 31
wxMaxima can simplify expressions. I believe it's supposed to be a substitute for Maple.
- 719
- 4
- 15
I think I was able to get Wolfram Alpha to work. Maybe I'm wrong about what you're looking for.
- 30,394
- 9
- 64
- 127
- 151
- 1
You can do it with Axiom (or OpenAxiom or Fricas):
(1) -> eval( x^2 + 2*x + 3, x=sqrt(2)*t-1)
(1) ->
2
(1) 2t + 2
Type: Polynomial(AlgebraicNumber)
(2) ->
- 131
- 3
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 08:11