
(*This file contains the code which does the main
  computation in Chapter 2 and also the main
  computation in Chapter 7. *)

(*1. The Cross Ratio*)
CR[a_,b_,c_,d_]:=(a-b) (c-d)/(a-c)/(b-d);

Clear[z1,z2,z3,z4,z5,z6];
Clear[w0,w1,w2,w3,w4,w5,w6];

w0=0

w1 = 1
 
w2 = (1-z1)^(-1)
 
w3 = (-1+z2)/(-1+z1+z2)
 
w4 = (1-z2-z3)/(1-z1-z2-z3+z1*z3)

w5 = (1-z2-z3-z4+z2*z4)/
   (1-z1-z2-z3+z1*z3-z4+z1*z4+z2*z4)
 
w6 = (-1+z2+z3+z4-z2*z4+z5-z2*z5-z3*z5)/
   (-1+z1+z2+z3-z1*z3+z4-z1*z4-z2*z4+z5-z1*z5-z2*z5-z3*z5+z1*z3*z5)

(*This routine checks that the w's are correct.*)
CrossCheck1[]:=Simplify[{CR[w0,w1,w2,w3],
                         CR[w1,w2,w3,w4],
                         CR[w2,w3,w4,w5],
                         CR[w3,w4,w5,w6]}]

q0 = 1/(1+Sqrt[z1]);
 
q1 = (1+Sqrt[z2])/(1-z1+Sqrt[z2]);
 
q2 = (-1+z2-Sqrt[z3])/
     (-1+z1+z2-Sqrt[z3]+z1*Sqrt[z3]);

q3 = (-1+z2+z3-Sqrt[z4]+z2*Sqrt[z4])/
     (-1+z1+z2+z3-z1*z3-Sqrt[z4]+z1*Sqrt[z4]+z2*Sqrt[z4])

(*This routine checks that the points q0,q1,q2,q3 indeed
are the correct points.   The output should be {0,0,0}.
the very first cross ratio is different because w(-1)=infty.*)

CrossCheck2[]:=
Simplify[{(q0-w1)/(w0-w1)-CR[w0,q0,w1,w2],
          CR[w0,w1,q1,w2]-CR[w1,q1,w2,w3],
          CR[w1,w2,q2,w3]-CR[w2,q2,w3,w4],
          CR[w2,w3,q3,w4]-CR[w3,q3,w4,w5]}];


(*Here is the final answer for chapter 2*)
FinalAnswer1=Factor[Simplify[CR[q0,q1,q2,q3]]]


(*Here is the main computation for Chapter 7.
We leave some of the checks, like the ones 
above, to the user.*)


s1 = -2/(-2 + z1)
 
s2 = (-2 + z2)/(-2 + 2*z1 + z2)
 
s3 = (-2 + 2*z2 + z3)/(-2 + 2*z1 + 2*z2 + z3 - z1*z3)
 
s4 = (2 - 2*z2 - 2*z3 - z4 + z2*z4)/(2 - 2*z1 - 2*z2 - 2*z3 + 2*z1*z3 - z4 + 
      z1*z4 + z2*z4)

FinalAnswer2=Simplify[CR[s1,s2,s3,s4]]

DcF = (1 + a)/(-b^2 + (1 + a)*(1 + c)) - (-2*c + 2*(1 + c))/
      (-c^2 + (1 + c)^2) - (2*c)/(-c^2 + (1 + b)*(1 + d)) + 
     (1 + e)/(-d^2 + (1 + c)*(1 + e))
