Post Reply 
Testing xCAS version 1.2.3-9 (2017)
01-19-2017, 02:01 PM (This post was last modified: 01-19-2017 03:48 PM by compsystems.)
Post: #10
RE: Testing xCAS version 1.2.3-9 (2017)
I would like with the help of you all, create a similar tutorial to CAS sympy for Python
TUTORIAL
http://docs.sympy.org/latest/tutorial/gotchas.html

There are many undocumented commands and functions, for example

regroup(x+3*x+(5*4/x)) -> 4*x+20/x =)

Quote:Equals signs
Another very important consequence of the fact that CAS SymPy does not extend Python syntax is that = does not represent equality in SymPy. Rather it is Python variable assignment. This is hard-coded into the Python language, and SymPy makes no attempts to change that.

You may think, however, that ==, which is used for equality testing in Python, is used for SymPy as equality. This is not quite correct either. Let us see what happens when we use ==.

Run code block in SymPy Live
>>> x + 1 == 4
False
Instead of treating x + 1 == 4 symbolically, we just got False. In SymPy, == represents exact structural equality testing. This means that a == b means that we are asking if a=ba=b. We always get a bool as the result of ==. There is a separate object, called Eq, which can be used to create symbolic equalities

Run code block in SymPy Live
>>> Eq(x + 1, 4)
Eq(x + 1, 4)
There is one additional caveat about == as well. Suppose we want to know if (x+1)2=x2+2x+1(x+1)2=x2+2x+1. We might try something like this:

Run code block in SymPy Live
>>> (x + 1)**2 == x**2 + 2*x + 1
False
We got False again. However, (x+1)2(x+1)2 does equal x2+2x+1x2+2x+1. What is going on here? Did we find a bug in SymPy, or is it just not powerful enough to recognize this basic algebraic fact?

Recall from above that == represents exact structural equality testing. “Exact” here means that two expressions will compare equal with == only if they are exactly equal structurally. Here, (x+1)2(x+1)2 and x2+2x+1x2+2x+1 are not the same symbolically. One is the power of an addition of two terms, and the other is the addition of three terms.

It turns out that when using SymPy as a library, having == test for exact symbolic equality is far more useful than having it represent symbolic equality, or having it test for mathematical equality. However, as a new user, you will probably care more about the latter two. We have already seen an alternative to representing equalities symbolically, Eq. To test if two things are equal, it is best to recall the basic fact that if a=ba=b, then a−b=0a−b=0. Thus, the best way to check if a=ba=b is to take a−ba−b and simplify it, and see if it goes to 0. We will learn later that the function to do this is called simplify. This method is not infallible—in fact, it can be theoretically proven that it is impossible to determine if two symbolic expressions are identically equal in general—but for most common expressions, it works quite well.

Run code block in SymPy Live
>>> a = (x + 1)**2
>>> b = x**2 + 2*x + 1
>>> simplify(a - b)
0
>>> c = x**2 - 2*x + 1
>>> simplify(a - c)
4*x
There is also a method called equals that tests if two expressions are equal by evaluating them numerically at random points.

Run code block in SymPy Live
>>> a = cos(x)**2 - sin(x)**2
>>> b = cos(2*x)
>>> a.equals(b)
True
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Testing xCAS version 1.2.3-9 (2017) - compsystems - 01-19-2017 02:01 PM



User(s) browsing this thread: 1 Guest(s)