# Need to improve a function in sage which checks trueness of expressions in an example.

Hello !

Here I have made a function in sage which checks equality between consecutive expressions in an example.

This function takes a set of examples as an argument. I want to improve my function and I really need comments and suggestions for correcting this function.

Two examples which I have used are as follows.

Example 1:

(1 - ((1 + sqrt(a))/(sqrt(a)- 1)))

=

(1 + ((1 + sqrt(a))/(-sqrt(a) + 1)))

=

(1 + ((1 + sqrt(a))* (1 + sqrt(a))/((-sqrt(a) + 1) * (sqrt(a) + 1))))

=

(1 + ((1 + 2* sqrt(a) + a)/(1 - a)))

=

(1 + ((1+a + 2* sqrt(a) )/(1-a)))

=

(((1-a)/(1-a)) + ((1+a + 2* sqrt(a))/(1-a)))

=

(1-a+1+a+ 2*sqrt(a))/(1-a)

=

(2+2*sqrt(a))/(1-a)

Example2:

x^2 + 2*x -3 == 0

<=>

x == (-2 + (2^2 -4*1*(-3))^(1/2))/(2*1) or x == (-2 - (2^2 -4*1*(-3))^(1/2))/(2*1)

<=>

x == (-2 + (4+12)^(1/2))/(2*1) or x == (-2 - (4+12)^(1/2))/(2*1)

<=>

x == (-2 + (16)^(1/2))/(2*1) or x == (-2 - (16)^(1/2))/(2*1)

<=>

x == (-2 + 4)/(2*1) or x == (-2 - 4)/(2*1)

<=>

x == (2)/(2) or x == (-6)/(2)

<=>

x == 1 or x == -3

The Problem is , following function checks first example correctly but not second example. In the second example, final answer is x == 1 or x == -3 but even if I provide wrong answer x == -1 or x == -3 it gives true. I have already received explanation about how 'or' behaves. see here

---------------Function begins ---------------

var('j,e,exprList,as1,i,lhs,rhs,r,r1,x')

def ComExpr(a):

```
r1 = [];
for j in range(0,len(a)):
forget();
e = a[ZZ(j)]
exprList = e[0]
as1 = e[1]
print len(a)
r = [];
for i in range(0,len(exprList)-1):
forget();
lhs = exprList[ZZ(i)]
rhs = exprList[ZZ(i+1)]
assume(as1 and lhs);
p1 = rhs.full_simplify()
forget();
assume(as1 and rhs);
p2 = lhs.full_simplify()
r.append(bool(p1 and p2))
r1.append(r)
return r1
```

e1 is first example containing two elements one is list of expressions and another is assumption. Same for e2.

e1 = [[(1 - ((1 + sqrt(a))/(sqrt(a)- 1))) == (1 + ((1 + sqrt(a))/(-sqrt(a) + 1))), (1 + ((1 + sqrt(a))/(-sqrt(a) + 1))) == (1 + ((1 + sqrt(a))* (1 + sqrt(a))/((-sqrt(a) + 1) * (sqrt(a) + 1)))), (1 + ((1 + sqrt(a))* (1 + sqrt(a))/((-sqrt(a) + 1) * (sqrt(a) + 1)))) == (1 + ((1 + 2* sqrt(a) + a)/(1 - a))), (1 + ((1 + 2* sqrt(a) + a)/(1 - a))) == (1 + ((1+a + 2* sqrt(a) )/(1-a))), (1 + ((1+a + 2* sqrt(a) )/(1-a))) == (((1-a)/(1-a)) + ((1+a + 2* sqrt(a) )/(1-a))), (((1-a)/(1-a)) + ((1+a + 2* sqrt(a))/(1-a))) == (1-a+1+a+ 2*sqrt(a))/(1-a)], a > 1];

sage: ComExpr([e1]) 1 [[True, True, True, True, True]]

e2=[[x^2 + 2*x -3 == 0, x == (-2 + (2^2 -4*1*(-3))^(1/2))/(2*1) or x == (-2 - (2^2 -4*1*(-3))^(1/2))/(2*1),x == (-2 ...*

You "really need comments and suggestions" about very cumbersome expressions, and in a precedent post it was "very necessary" for you "to understand this behavior of sage", please what does it mean ?

Sorry for improper English. In the preceding post I wanted to know How 'or' works in sage. But I got answer and now I know that. In this post I said I really need comments and suggestions because I want to edit this function and want to make it more reliable.

You are probably a high school student who is struggling with quadratic equations and so on, I can tell you that Sage is definitely useless for learning how to handle such computations and for acquiring the necessary skills in this domain. Sorry and good luck with a more traditional approach !

Actually I am using mathematical problems from secondary school or high school level and trying to develop a function in sage which can check whether consecutive expressions are logically true or not, and hence we can check whole example whether it is correct or not.