4: Simplification

Example number 4.1, Page number 4.7

In [2]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=10+(1/2);
b=8+(1/2);
c=6;
d=7;
e=6;
f=4;

#Calculation
result=a-(b+(c-(d-(e-f))));

#Result
print "result is",result
result is 1.0

Example number 4.2, Page number 4.8

In [3]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=0.75;
b=0.25;

#Calculation
#given question is (a*a)+(b*b)+(2*a*b) which can be solved using (a+b)**2
result=(a+b)**2;

#Result
print "result is",result
result is 1.0

Example number 4.3, Page number 4.8

In [4]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=0.87;
b=0.13;

#Calculation
Nr=(a**3)+(b**3);
Dr=(a**2)+(b**2)-(a*b);
result=Nr/Dr;

#Result
print "result is",result
result is 1.0

Example number 4.4, Page number 4.8

In [5]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=9840;
b=410;

#Calculation
result=(a/b)**2;

#Result
print "result is",result
result is 576.0

Example number 4.5, Page number 4.8

In [6]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=40;
b=30;
c=10;

#Calculation
x=((a**2)-(b**2))/c;   #required number

#Result
print "required number is",x
required number is 70.0

Example number 4.6, Page number 4.8

In [7]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=3;
b=4;
c=6;
d=9;

#Calculation
p=b+c-d;
x=a**p;       #required number

#Result
print "required number is",x
required number is 3

Example number 4.7, Page number 4.8

In [8]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=2;
b=math.sqrt(2);

#Calculation
c=1/(a+b);
d=1/(b-a);
result=a+b+c+d;

#Result
print "result is",result
result is 2.0

Example number 4.8, Page number 4.9

In [9]:
#importing modules
import math
from __future__ import division

#Variable declaration
x=7;
y=5;
z=2;

#Calculation
xstary=((x+z)**2)*(y-z);

#Result
print "result is",xstary    
result is 243

Example number 4.9, Page number 4.9

In [10]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=121;

#Calculation
m=math.sqrt(a);
#since we are considering square root, value of n will be 2
n=2;
result=(m-1)**(n+1);    

#Result
print "result is",result
result is 1000.0

Example number 4.10, Page number 4.9

In [11]:
#importing modules
import math
from __future__ import division

#Variable declaration
k=1;
x=3*k;
y=4*k;

#Calculation
result=(6/7)+((y-x)/(y+x));

#Result
print "result is",result
result is 1.0

Example number 4.11, Page number 4.9

In [12]:
#importing modules
import math
from __future__ import division

#Variable declaration
rootxminusrooty=1;
rootxplusrooty=17;

#Calculation
#we get value of rootx and rooty by adding and subtracting the 2 equations
rootx=(rootxminusrooty+rootxplusrooty)/2;
rooty=(rootxplusrooty-rootxminusrooty)/2;
result=rootx*rooty;

#Result
print "result is",result
result is 72.0

Example number 4.12, Page number 4.9

In [13]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=12;
b=0.2;
c=3.6;
d=2;

#Calculation
x=a*b*c*d;

#Result
print "result is",x
result is 17.28

Example number 4.13, Page number 4.9

In [15]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=7;
b=18;
c=84;

#Calculation
x=((c/b)**2)/7;    

#Result
print "result is",round(x,2)
result is 3.11

Example number 4.15, Page number 4.10

In [16]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=256;
b=2;

#Calculation
c=math.log(a)/math.log(b);
x=math.log(c)/math.log(b);

#Result
print "result is",x
result is 3.0

Example number 4.16, Page number 4.10

In [17]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=13;
b=2;
c=4;

#Calculation
d=math.log(c)/math.log(b);
e=d*b;
x=(a-e);     

#Result
print "result is",x
result is 9.0

Example number 4.17, Page number 4.10

In [18]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=3*math.sqrt(27);
b=math.sqrt(75);
c=math.sqrt(12);

#Calculation
x=a-b+c;      

#Result
print "result is",x/math.sqrt(3),"*math.sqrt(3)"
result is 6.0 *math.sqrt(3)

Example number 4.19, Page number 4.11

In [20]:
#importing modules
import math
from __future__ import division
from fractions import Fraction

#Variable declaration
a=8+(1/4);
b=8+(1/2);
c=20+(1/8);

#Calculation
x=c-(a+b);
y=x-int(x);

#Result
print "result is",int(x),Fraction(y)
result is 3 3/8

Example number 4.20, Page number 4.11

In [21]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=math.sqrt(1296);
b=2.25;

#Calculation
c=a*b;
x=math.sqrt(c);

#Result
print "result is",x
result is 9.0

Example number 4.21, Page number 4.11

In [22]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=124.9;
b=63.15;
c=65/100;

#Calculation
d=a-b;
x=d/c;

#Result
print "result is",x
result is 95.0

Example number 4.22, Page number 4.11

In [25]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=17;
aplusb=23;

#Calculation
b=aplusb-a;
result=aplusb/(a-b);

#Result
print "result is",result
result is 2.09090909091

Example number 4.23, Page number 4.12

In [26]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=math.sqrt(24);
b=math.sqrt(216);
c=math.sqrt(96);

#Calculation
x=(a+b)/c;

#Result
print "result is",x
result is 2.0

Example number 4.25, Page number 4.12

In [29]:
#importing modules
import math
from __future__ import division

#Variable declaration
x=5;
y=-2;

#Calculation
result=(x-(2*y))**(1/y);

#Result
print "result is",result
result is 0.333333333333

Example number 4.26, Page number 4.12

In [30]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=2+(2/3);
b=4/5;
c=1/6;

#Calculation
result=a/(b*c);  

#Result
print "result is",result
result is 20.0

Example number 4.27, Page number 4.12

In [32]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=5/6;
b=1/20;
c=24;
d=4/7;
e=14;
f=2+(1/4);

#Calculation
r1=a*b*c;     #value of 5/6 of 1/20 of 24 rupees(rupee)
r2=d*e*f;     #value of 4/7 of 14 of 2 1/4 kg(kg)

#Result
print "value of 5/6 of 1/20 of 24 rupees is",r1,"rupee"
print "value of 4/7 of 14 of 2 1/4 kg is",r2,"kg"
print "answer given in the book is wrong"
value of 5/6 of 1/20 of 24 rupees is 1.0 rupee
value of 4/7 of 14 of 2 1/4 kg is 18.0 kg
answer given in the book is wrong

Example number 4.28, Page number 4.12

In [35]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=11;
b=2+(1/5);
c=11/5;
d=2+(1/2);
e=2;

#Calculation
r1=a/b;
r2=r1/c;
result=(r2*d)-e;

#Result
print "result is",result
result is 3.68181818182

Example number 4.29, Page number 4.13

In [36]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=2/3;
b=1/5;
c=1/10;
d=4/5;
e=1/8;
f=1/2;

#Calculation
Nr=a+b-c;
Dr=(d*e)+f;
result=Nr/Dr;

#Result
print "result is",result
result is 1.27777777778

Example number 4.30, Page number 4.13

In [37]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=18;
b=162;
c=1;

#Calculation
x2=a*b*c;
x=math.sqrt(x2);

#Result
print "result is",x
result is 54.0

Example number 4.31, Page number 4.13

In [38]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=0.55;
b=0.07;
c=0.027;
d=0.01;

#Calculation
Nr=(a**2)+(b**2)+(c**2);
Dr=d*Nr;
result=Nr/Dr;

#Result
print "result is",result
result is 100.0

Example number 4.32, Page number 4.13

In [39]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=137;
b=133;

#Calculation
Nr=(a**3)+(b**3);
Dr=(a**2)-(a*b)+(b**2);
result=Nr/Dr;

#Result
print "result is",result
result is 270.0

Example number 4.33, Page number 4.14

In [40]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=20.25;
b=2.8;
c=28.35;

#Calculation
result=a*b/c;

#Result
print "result is",result
result is 2.0

Example number 4.34, Page number 4.14

In [41]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=54;
b=66;
c=33;

#Calculation
r=a/b;
result=r/c;

#Result
print "result is",result
result is 0.0247933884298

Example number 4.35, Page number 4.14

In [43]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=916;
b=16;
c=4;

#Calculation
r=a*c/b;

#Result
print "result is",r
print "hence middle digit is 2"
result is 229.0
hence middle digit is 2

Example number 4.36, Page number 4.14

In [44]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=0.011;
b=10;

#Calculation
x=b*(a**2);

#Result
print "result is",x
result is 0.00121

Example number 4.37, Page number 4.14

In [45]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=67.6;
b=0.26;

#Calculation
x=a/(b**2);   

#Result
print "result is",x
result is 1000.0

Example number 4.38, Page number 4.15

In [46]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=0.324;
b=10;

#Calculation
x=math.sqrt(a/b);

#Result
print "result is",x
result is 0.18

Example number 4.39, Page number 4.15

In [47]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=63;
b=36;

#Calculation
r1=(a+b)**2;
r2=(a-b)**2;
Nr=r1+r2;
Dr=(a**2)+(b**2)
x=Nr/Dr;

#Result
print "result is",x
result is 2.0

Example number 4.40, Page number 4.15

In [48]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=44.6;
b=2.5;

#Calculation
x=a*b;

#Result
print "result is",x
result is 111.5

Example number 4.41, Page number 4.15

In [49]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=14;
b=46;
c=11;
d=6;
e=4;

#Calculation
Nr=(a**2)-b;
Dr=(c*d)-(e**2);
x=Nr/Dr;

#Result
print "result is",x
result is 3.0

Example number 4.42, Page number 4.15

In [52]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=2002;
b=10.10;

#Calculation
x=a-(a/b);

#Result
print "result is",int(x)
print "answer given in the book varies due to rounding off errors"
result is 1803
answer given in the book varies due to rounding off errors

Example number 4.43, Page number 4.16

In [56]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=8;
b=3;
c=4;
d=2;
e=6;
f=5;
g=8;

#Calculation
Nr=a-(b*c)+d;
Dr=-(e*f)+(b*g);
x=Nr/Dr;

#Result
print "result is",x
result is 0.333333333333

Example number 4.45, Page number 4.16

In [61]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=4;
b=3;
c=2;
d=5;
e=0;

#Calculation
p=(a*b)-(b*c)+(d*e);    #power is calculated using indices
x=a**p;
y=math.log(x)/math.log(a);

#Result
print "result is",x,"or",a,"**",int(y)
result is 4096 or 4 ** 6

Example number 4.46, Page number 4.16

In [62]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=1;
b=25/144;
c=12;

#Calculation
r=math.sqrt(a+b);
x=(r-a)*c;

#Result
print "result is",x
result is 1.0

Example number 4.47, Page number 4.16

In [63]:
#importing modules
import math
from __future__ import division

#Variable declaration
b=1;
a=2;

#Calculation
x1=a-b;
x2=a+b;
result=(x1/x2)+(2/3);

#Result
print "result is",result
result is 1.0

Example number 4.48, Page number 4.17

In [64]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=18;
b=14;
c=84;

#Calculation
x=(c**2)/(a*b);

#Result
print "result is",x
result is 28.0

Example number 4.49, Page number 4.17

In [65]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=243;
b=0.8;
c=0.4;

#Calculation
p=b-c;
x=a**p;

#Result
print "result is",x
result is 9.0

Example number 4.50, Page number 4.17

In [66]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=1.2;
b=0.8;

#Calculation
x=(a**2)+(b**2)+(2*a*b);

#Result
print "result is",x
result is 4.0

Example number 4.51, Page number 4.17

In [67]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=64/121;
b=9/64;
c=8/11;
d=3/8;

#Calculation
x=(a-b)/(c+d);

#Result
print "result is",x
result is 0.352272727273

Example number 4.52, Page number 4.17

In [68]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=0.1;
b=0.75;
c=2.5;
d=0.05;
e=0.125;
f=1/4.8;

#Calculation
r1=(a+b)/(c+d);
x=r1/(e+f);

#Result
print "result is",x
result is 1.0

Example number 4.53, Page number 4.18

In [70]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=1/246;
b=2/3;
c=1/27;
d=4/3;

#Calculation
r1=a**(-b);
r2=c**(-d);
x=r1/r2;

#Result
print "result is",x
result is 8731552810114645/18014398509481984

Example number 4.54, Page number 4.18

In [71]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=8;
b=5/3;
c=125;
d=2/3;

#Calculation
r1=a**b;
r2=c**(-d);
x=r1/r2;

#Result
print "result is",x
result is 800.0

Example number 4.55, Page number 4.18

In [74]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=6;
b=-2;
c=81;
d=-3/4;

#Calculation
r1=1/(a**b);
r2=c**d;
x=r1*r2;

#Result
print "result is",x
result is 1.33333333333

Example number 4.56, Page number 4.18

In [75]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=math.sqrt(147);
b=math.sqrt(27);
c=math.sqrt(3);

#Calculation
x=(a+b)/c;

#Result
print "result is",x
result is 10.0

Example number 4.57, Page number 4.19

In [77]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=math.sqrt(98);
b=math.sqrt(50);
c=math.sqrt(2);

#Calculation
x=(a-b)/c;

#Result
print "result is",x
result is 2.0

Example number 4.58, Page number 4.19

In [78]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=math.sqrt(9/25);
b=3+(1/16);
c=math.sqrt(b);

#Calculation
x=a+c;

#Result
print "result is",x
result is 2.35

Example number 4.59, Page number 4.19

In [80]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=math.sqrt(0.01);
b=math.sqrt(0.0064);

#Calculation
x=a+b;

#Result
print "result is",x
print "answer given in the book is wrong"
result is 0.18
answer given in the book is wrong

Example number 4.60, Page number 4.19

In [81]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=25.6;
b=36.1;
c=12.1;
d=81;
e=0.1;

#Calculation
r1=math.sqrt(a/b);
r2=math.sqrt(c/(d*e));
x=r1/r2;

#Result
print "result is",x
result is 0.688995215311

Example number 4.61, Page number 4.19

In [83]:
#importing modules
import math
from __future__ import division

#Variable declaration
N=51;

#Calculation
#to express a number as the difference of squares of 2 numbers, we use the formula N=((N+1)/2)**2-((N-1)/2)**2
a=(N+1)/2;
b=(N-1)/2;
#N can be expressed as (a**2)-(b**2)

#Result
print "51 can be expressed as",int(a),"**2 - ",int(b),"**2"
51 can be expressed as 26 **2 -  25 **2

Example number 4.62, Page number 4.19

In [84]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=7;
b=11;
c=1232;

#Calculation
x2=a*b*c;
x=math.sqrt(x2);

#Result
print "result is",x
result is 308.0

Example number 4.63, Page number 4.20

In [85]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=3+(1/4);
b=4+(1/3);

#Calculation
Nr=(a**4)-(b**4);
Dr=(a**2)-(b**2);
result=math.sqrt(Nr/Dr);

#Result
print "result is",result
result is 5.41666666667

Example number 4.64, Page number 4.20

In [86]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=2/9;
b=8;

#Calculation
x=b/(a**2);    #total score in innings

#Result
print "total score in innings is",x
total score in innings is 162.0

Example number 4.65, Page number 4.20

In [90]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=64;
b=32;
c=-1/2;
d=4/5;

#Calculation
r1=(1/a)**0;
r2=a**c;
r3=b**d;
result=r1+r2+r3;

#Result
print "result is",result
result is 17.125

Example number 4.66, Page number 4.21

In [91]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=243;
b=0.12;
c=0.08;

#Calculation
p=b+c;
result=a**p;

#Result
print "result is",result
result is 3.0

Example number 4.67, Page number 4.21

In [92]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=2;
b=64;

#Calculation
c=math.log(b)/math.log(a);
n=c*a;

#Result
print "result is",n
result is 12.0

Example number 4.68, Page number 4.21

In [96]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=1/216;
b=2/3;

#Calculation
x=1/(a**b);

#Result
print "result is",x
result is 36.0

Example number 4.69, Page number 4.21

In [97]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=-2;

#Calculation
b=a**a;
x=b**a;

#Result
print "result is",x
result is 16.0

Example number 4.70, Page number 4.21

In [98]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=11+(1/3);
b=4+(8/10);
c=22+(2/3);

#Calculation
x=a*b/c;

#Result
print "result is",x
result is 2.4

Example number 4.71, Page number 4.22

In [99]:
#importing modules
import math
from __future__ import division

#Variable declaration
a=1.06;
b=0.04;
c=4;

#Calculation
r1=(a+b)**2;
x=r1-(4*a*b);

#Result
print "result is",x
result is 1.0404

Example number 4.72, Page number 4.22

In [102]:
#importing modules
import math
from __future__ import division
from fractions import Fraction

#Variable declaration
a2plusb2=45;
ab=18;

#Calculation
Nr=math.sqrt(a2plusb2+(2*ab));
result=Nr/ab;

#Result
print "result is +/-",Fraction(result)
result is +/- 1/2

Example number 4.75, Page number 4.23

In [103]:
#importing modules
import math
from __future__ import division

#Variable declaration
#by comparing the equations we get
rootx=2;

#Calculation
x=rootx**2;

#Result
print "result is",x
result is 4