*
PRECALCULUS TUTORIAL
*
Orientation
5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5012 5013
Inequalities
4222 4223 4225
Basic Geometry Formulas
4220 4013 4208 4221
Coordinates, Distance Formula, Midpoints, Circles
4020 4022 4024 4025
Lines
4027 4028 4029 4026 4030 
Functions, Domains, Ranges
4032 4033 4034 4035 4038 
Graphs of Functions, Symmetry, Shifts and Reflections
4043 4044 4050 4051 4052 4042
Combinations of Functions, Compositions
4045 4046 4047
Linear Functions: Applications
4048 4049 4209
Quadratic Functions
4007 4070 4071 4072 4206 4210
Setting Up Functions I
4211 4016 4017 4019 4001 4002 4003
Setting Up Functions II 
4008 4009 4012 4059 4064 4065 4068  
Quadratic Functions: Applications
4053 4054 4060 4061 4073
Inverse Functions
4074 4075 4076 4077 4217 4218
Logs and Exponential Functions I
4079 4080 4083 4084 4087 4091 4092 4216 
Logs and Exponential Functions II
4095 4097 4099 4102 4212 4214 4215 4219
Compound Interest
4104 4105 4107 4108 4109 
Exponential Growth and Decay
4111 4112 4114 4115 
Trig Functions 
4119 4121 4122 4124 4141 4142
Right Triangles 
4130 4131 4128 4126 4132 4135 4138 4139
Radian Measure, Arc Length
4151 4146 4147 4149 4145
Trig Functions, Domain, Range, Graphs
4154 4155 4157 4158 4160 
Periodic Functions, Amplitude, Phase Shifts
4163 4164 
Addition Formulas
4165 4167 4168 4169
Inverse Trig Functions 
4184 4187 4173 4177 4179 4180 4183 4189 4190 
Laws of Sines and Cosines 
4191 4192 4194 4197 4201 4203
 




procedure p4001;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,dgm1,dgm2,header:string;
begin
  x.a:=rand([2,3,5,6,8]);
  x.b:=x.a*x.a;
  x.c:=2*x.b;
  x.d:=2*x.a;
  header:='\red{Answer both parts before grading.}';
  dgm:=#127'500,500,1200,10;I,250,100,50;L,-5,0,5,0;L,0,-1,0,6;B,2;'+
       'G,\sqrt{16-x^2},-4,4;B,0;L,1,0,1,3.873;'+
       'L,1,0,4,0;L,1,3.783,4,0;B,3;F,2,2;B,0;G,3.873,D1,1;C,1,4.1,P(x,y);'+
       'C,1.8,-.5,\a;D,0,-.3,1.5,-.3,4;D,2.3,-.3,4,-.3,4;'#127;
  text1::=header+dgm+#13'The point P(x,y) is on the circle of radius \a  centered at '+
  	  '(0,0).\nl '+
	  '\red{a:}  Express the area A(x) of the shaded triangle as a function of '+
	  'x, -\a  < x < \a.\nl\nl '+
	  '\red{b:}  Express the perimeter P(x) of the shaded triangle as a function '+
	  'of x, -\a  < x < \a.\nl\nl\nl\nl ';
  prompt::=#133'a: A(x) = '#134#13+
    	   #133'b: P(x) = '#134;
  text3:=text1+#13#142'Message:'#142#13+
  	'Express the sides of the triangle in terms of x and y. Then use '+
	'the fact that P(x,y) lies on the circle.';
  header::=header;
  replace(header,'',text3);
  help::='\red{Area of a Triangle:}\nl '+
         '\ \ {1\over 2}\cdot base\cdot height.\nl\nl '+
	 '\red{Perimeter of a Triangle:}\nl '+
	 '\ \ sum of lengths of all three sides';
  ans:=#134'$${(\a-x)\sqrt{\b-x^2}\over 2}$$'#133+
       #134'$$\a-x+\sqrt{\b-x^2}+\sqrt{\c-\d x}$$';
  answer::=ans;
  separate(ans,a1,a2);
  dgm1:=#127'500,500,1200,0;I,150,200,50;L,1,0,1,3.873;L,1,0,4,0;L,1,3.873,4,0;B,3;F,2,2;B,0;G,3.783,D1,1;'+
        'C,1,4.1,P(x,y);C,-1.5,1.5,\sqrt{\b-x^2};C,2,-.6,\a-x;B,2;G,\sqrt{16-x^2},-1,3;B,0;'+
	'C,3,3,x^2+y^2=\b;C,4.1,-.3,(\a,0);C,-.8,-.3,(x,0);'#127;
  solution::='\nl\red{Solution to part a:}\nl '+
  	  dgm1+'The horizontal leg of the right triangle has length $$\a-x$$.\pause  '+
          '\nl Since P(x,y) is on the circle $$x^2+y^2=\b$$, the vertical leg of '+
	  'the right triangle has length $$\sqrt{\b-x^2}$$.\pause\nl Thus the '+
	  'area of the shaded triangle is $${1\over 2}\cdot (\a-x)\cdot '+
	  '\sqrt{\b-x^2}$$ = '+a1+'.\nl ';
  dgm2:=#127'600,500,1200,0;I,100,200,50;L,1,0,1,3.873;L,1,0,4,0;L,1,3.873,4,0;B,3;F,2,2;B,0;G,3.783,D1,1;'+
        'C,1,4.1,P(x,y);C,-1.5,1.5,\sqrt{\b-x^2};C,2,-.6,\a-x;B,2;G,\sqrt{16-x^2},-1,3;B,0;'+
	'C,3,3,x^2+y^2=\b;C,4.1,-.3,(\a,0);C,-.8,-.3,(x,0);C,2.6,2,\sqrt{\c-\d x};'#127;
  solution2::='\nl\red{Solution to part b:}\nl '+
  	  dgm2+'The hypotenuse of the shaded triangle is\nl '+
  	  '$$\sqrt{(\a-x)^2+\b-x^2}$$\nl '+
	  '= $$\sqrt{\b-\d x+x^2+\b-x^2}$$\nl '+
	  '= $$\sqrt{\c-\d x}$$.\pause\nl '+
	  'Thus the perimeter of the shaded triangle is \nl '+a2+'.';
  type:='R';
  key:=4001;
end;

procedure s4001;
var
  res,mess,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2,undef,notwff:boolean;
  x1,x2,y1,y2:real;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  x1:=evaluate(r1,'x=1.8',undef,notwff);
  x2:=evaluate(r2,'x=1.8',undef,notwff);
  y1:=evaluate(a1,'x=1.8',undef,notwff);
  y2:=evaluate(a2,'x=1.8',undef,notwff);
  check1:=sameexpres(a1,r1) and (abs(x1-y1)<.00001);
  check2:=sameexpres(a2,r2) and (abs(x2-y2)<.00001);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4002;
var
  x:paramtype;
  undef,notwff:boolean;
  text,ans,a1,a2,dgm,dgm2:string;
begin
  x.a:=rand([3,4,6,10]);
  x.b:=x.a+rand([2,5,7,9]);
  x.c:=x.a^2;
  x.d:=x.b^2;
  x.e:=2*x.b;
  x.f:=x.d+x.c;
  dgm:=#127'800,500,1000,0;I,250,100,50;G,\sqrt{16-x^2},-4,4;B,2;L,3,2.646,9,0;'+
       'B,0;G,2.646,D3,3;B,0;C,3,2.9,P(x,y);B,2;C,8.3,-.6,(\b,0);B,0;G,0,D9,9;'+
       'L,-5,0,11,0;L,0,-1,0,7;B,4;C,1.8,-.6,\a;B,0;D,0,-.4,1.5,-.4,4;D,2.5,-.4,4,-.4,4;'+
       'C,6.6,1.3,D;'#127;
  dgm2:=#127'800,500,1100,0;I,250,150,50;G,\sqrt{16-x^2},-4,4;L,3,2.646,9,0;'+
  	'G,2.646,D3,3;C,3,2.9,P(x,y);C,8.3,-.6,(\b,0);G,0,D9,9;'+
	'L,-5,0,11,0;L,0,-1,0,7;C,3.8,-.6,\a;C,6.5,1.2,D;D,3,2.61,3,0,5;'+
	'D,3,-1,9,-1,10;C,5.6,-1.5,\b-x;'+
	'C,1.56,4.67,x^2+y^2=\c;D,.81,4,1.5,4.6,3;'+
	'C,.4,1.39,\sqrt{\c-x^2};'#127;
  text:='The point P(x,y) lies on the circle of radius \a  centered '+
          'at (0,0). Express the distance D from P(x,y) to (\b,0) as a function '+
	  'of x for -\a  < x < \a.\nl ';
  text1::=dgm+text+'\nl\nl\nl\nl\nl\nl ';
  prompt::=#133'D = '#134;
  text3::=dgm+text+#13#142'Message'#142#13+
  	'Use the distance formula and the fact that P(x,y) satisfies the '+
	'equation of the circle of radius \a  centered at (0,0).';
  help::='\red{Distance Formula}:\nl '+
  	'The distance between points (a,b) and (c,d) is given by '+
        '\sqrt{$$(c-a)^2+(d-b)^2$$}.\nl\nl '+#10#12+
	'\red{Equation of a Circle:}\nl '+
	'The circle of radius r with center (h,k) is given by '+
	'$$(x-h)^2+(y-k)^2=r^2$$.\nl\nl '+#10#12+
	#127'400,500,700,0;I,200,300,50;L,0,0,0,4;L,0,4,2,0;L,0,0,2,0;'+
	'C,-.5,1.8,a;C,.8,-.6,b;C,1.4,1.8,c;'#127+
	'\red{Pythagorean Theorem:}\nl '+
	'$$a^2+b^2=c^2$$';
  ans:='$$\sqrt{\f-\e x}$$';
  answer::=ans;
  solution::='\nl\red{Solution:}\nl '+
  	'From the distance formula we have\nl '+
        'D = \sqrt{(\b  - x)^2 + (0 - y)^2} = \sqrt{(\b  - x)^2 + y^2}\pause\nl '+
	'The equation of the circle is x^2 + y^2 = \c.\pause\nl '+
	'Thus $$y^2=\c-x^2$$ and so \nl '+
	'D = $$\sqrt{(\b-x)^2+y^2}=\sqrt{(\b-x)^2+\c-x^2}$$\pause\nl '+
	'= $$\sqrt{\d-\e x+x^2+\c-x^2}$$\pause\nl '+
	'= '+ans+'.';
  type:='R';
  key:=4002;
end;

procedure s4002;
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4003;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,a3,header,text:string;
begin
  x.a:=rand([10,12,15,20,24,32]);
  header:='\red{Answer all parts before grading.}';
  text:='The sum of two numbers is \a. Let x denote one of the numbers.\nl '+
          '\red{a:}  Express the product of the two numbers as a function of x. (30%)\nl '+
	  '\red{b:}  Express the sums of the squares of the two numbers as a function of '+
	  'x. (30%)\nl '+
	  '\red{c:}  Express the difference of the cubes of the two numbers as a function of '+
	  'x. (40%)\nl '; 
  text1::=header+nl+nl+text;
  prompt::=#133'a: product:'#134#13+
    	   #133'b: sum of squares:'#134#13+
	   #133'c: difference of cubes:'#134;
  help::='$$x+y=a$$ => $$y=a-x$$.\nl '+
  	 '$$xy=a$$ => $$y={a\over x}$$.';
  text3::=text+#13+'\nl\blue{Hint:}\nl '+
  	'Let y denote the second number. Use the fact that the sum of the '+
	'two numbers is \a  to express y in terms of x.'; 
  ans:=#134'$$x(\a-x)$$'#133+
       #134'$$x^2+(\a-x)^2$$'#133+
       #134'$$x^3-(\a-x)^3$$';
  text6::='$$(\a-x)^3-x^3$$';
  answer::=ans;
  separate(ans,a1,a2,a3);
  solution::='\nl\red{Solution to part a:}\nl '+
  	'Let y denote the second number. Then $$x+y=\a$$ => $$y=\a-x$$.\pause\nl '+
        'Thus the procuct of the two numbers is x\cdot y = '+a1+'.\pause\nl ';
  solution2::='\red{Solution to part b:}\nl '+
  	'Let y denote the second number. Then $$x+y=\a$$ => $$y=\a-x$$.\pause\nl '+
   	'Thus the sum of the squares of the two numbers is $$x^2+y^2$$ = '+
	a2+'.\pause';
  solution3::='\nl\red{Solution to part c:}\nl '+
	'Let y denote the second number. Then $$x+y=\a$$ => $$y=\a-x$$.\pause\nl '+
   	'Thus the difference of the cubes of the two numbers is '+
	'$$x^3-y^3$$ = '+a3+'. The difference of the cubes of the two '+
	'numbers could also be\nl $$y^3-x^3$$ = $$(\a-x)^3-x^3$$.';
  type:='R';
  key:=4003;
end;

procedure s4003;
var
  r1,r2,r3,r4,a1,a2,a3:string;
  r:integer;
  check1,check2,check3,undef,notwff:boolean;
begin
  message:='';
  separate(response,r1,r2,r3);
  check1:=false;
  check2:=false;
  check3:=false;
  separate(answer,a1,a2,a3);
  check1:=sameexpres(a1,r1);
  check2:=sameexpres(a2,r2);
  check3:=sameexpres(a3,r3) or sameexpres(text6,r3);
    if check1 and check2 and check3 then begin
    result:='T';
    message:=#141'Correct'#141;
  end else begin
    if check1 then begin
      r:=r+3;
      message:='a: '+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:='a: '+r1+' is '#140'incorrect'#140'.'+#13+nl;
      end;
    end;
    if check2 then begin
      r:=r+3;
      message:=message+'b: '+r2+' is '#141'correct.'#141+nl;
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+'b: '+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check3 then begin
      r:=r+4;
      message:=message+'c: '+r3+' is '#141'correct'#141'.'+nl;
    end else begin
      if r3 = '' then begin
        message:=message+#140'c: Incorrect.'#140+nl;
      end else begin
        message:=message+'c: '+r3+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+text3;
  end;
end;

procedure p4007;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm:string;
begin
  x.d:=rand([4,6,8,9,12]);
  x.b:=x.d-1;
  x.c:=x.b^2;
  text1::='Find the point (a,b) on the curve $$y=x^2$$ such that the '+
  	'slope of the line through (1,1) and (a,b) is \d.\nl ';
  prompt::=#133'(a,b) = '#134;
  help::='\red{Slopes:}\nl '+
  	'The slope of the line through (x_1,y_1) and (x_2,y_2) is '+
  	'given by\nl $${y_2-y_1\over x_2-x_1}$$\nl '+
	'\red{Quadratic Formula:}\nl '+
  	'\ \ Roots of $$ax^2+bx+c$$:\nl '+
	'\ \ $$x={-b\pm\sqrt{b^2-4ac}\over 2a}$$';
  text3::=text1+'\nl\blue{Hint:}\nl '+
  	'Let (a,b) denote a point on the curve and express the slope of '+
	'the line through (1,1) and (a,b) in terms of a and b. Then use '+
	'the fact that (a,b) lies on $$y=x^2$$ to express b in terms of a. '+
	'Solve the resulting equation for a.';
  ans:='(\b,\c)';
  answer::=ans;
  solution::='\nl\red{Solution:}\nl '+
  	'Let (a,b) denote the desired point. Then the slope of the '+
  	'line through (a,b) and (1,1) is given by $${b-1\over a-1}$$.\pause\nl '+
	'Since (a,b) is on the curve $$y=x^2$$, we have b = a^2.\pause\nl '+
	'Thus the slope is $${a^2-1\over a-1}$$ and so\nl '+
	'$${a^2-1\over a-1}$$ = \d\pause\nl '+
	'=> $$a^2-1=\d(a-1)$$ => $$a^2-\d a+\b=0$$\pause\nl '+
	'=> $$(a-\b)(a-1)=0$$ => $$a=\b$$ or $$a=1$$.\pause\nl '+
	'Since (a,b) \ne  (1,1), the only possibility is a = \b  and so\nl '+
	'(a,b) = '+ans+'.';
  type:='R';
  key:=4007;
end;

procedure s4007;
var
mes:string;
begin
  if samepoints(answer,response) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    mes::='The co-ordinates of a point must be enclosed in parentheses.\nl ';
    if (pos('(',response) = -1) then 
      mes::='The co-ordinates of a point must be enclosed in parentheses.\nl '
    else mes:='';  
    if response = prompt then message:=#140'Incorrect'#140+#13+mes+text3
    else message:=response+' is '#140'incorrect'#140'. '+#13+mes+text3;
  end;
end;

procedure p4008;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm:string;
begin
  x.a:=rand([2,3,5,6,7]);
  x.b:=rand([-5,-3,-2,4,5,8,9]);
  text1::='A function f(x) is defined on the real numbers as follows:\nl '+
  	'Start with a number x and add \a. Then square the result and '+
	'subtract \b. Then multiply the result by the number you started '+
	'with. Write a formula for f(x).\nl ';
  prompt::=#133'f(x) = '#134;
  help::='\red{Functions:}\nl '+
  	'A function from the reals to the reals is a rule which assigns '+
  	'to each real number a unique real number.';
  text3::=text1+'\nl\blue{Hint:}\nl '+text3+
  	'Start with a real number and carefully decide what each step does '+
	'to the expression you have.';
  ans:='$$x((x+\a)^2-\b)$$';
  answer::=ans;
  solution::='\nl\red{Solution:}\nl '+
  	'Start with x and add \a :\nl x -> $$x+\a$$\pause\nl '+
  	'Then square the result and subtract \b :\nl $$x+\a$$ -> $$(x+\a)^2-\b$$\pause\nl '+
	'Then multiply the result by the original number:\nl '+
	'$$(x+\a)^2-\b$$ -> $$x((x+\a)^2-\b)$$\pause\nl '+
	'Thus f(x) = '+ans+'.';
  type:='R';
  key:=4008;
end;

procedure s4008;
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4009;
var
  a,k : integer;
  sol,dgm,dgm2,text: string;
  v:valuetype;
begin
  a := randint(10,40);v.a:=a;
  dgm:=#127'500,500,1200,0;I,150,275,25;L,0,0,0,8;L,0,0,6,0;L,0,0,-2,-2;L,-2,-2,4,-2;L,4,-2,6,0;'+
    'L,-2,-2,-2,6;L,-2,6,4,6;L,4,6,4,-2;L,-2,6,0,8;L,0,8,6,8;L,6,8,4,6;'+
    'L,6,8,6,0;B,2;C,1,-3,x;C,5.5,-1.5,x;B,4;F,-1,0;F,1,-1;F,1,1;F,5,-.5;F,5,1;'#127;
  text::='A box has a square base with no top. The surface area is '+
  	st(a)+' square inches. Express the volume V of the box as a  '+
	'function of x, the edge of the base.';
  text1::=dgm+text+nl+nl+nl+nl+nl+nl;
  prompt:=#133'V(x) = '#134;
  answer :=makeformula('[x(a-x^2)]/[4]',['a'],v);
  text3::=text1+'\nl\nl\blue{Hint:}\nl '+
    'Let x denote the length of the edge of the base and let y denote '+
    'the height of the box. Express both the volume of the box and the '+
    'surface area in terms of x and y.';
  help::='\red{Rectangular Box:}\nl '+#127'600,600,700,10;I,100,150,40;'+
  	'R,0,0,6,4;R,2,2,8,6;L,0,0,2,2;L,0,4,2,6;L,6,0,8,2;L,6,4,8,6;'+
	'B,2;C,2.8,-.5,l; C,7.3,.87,w;C,-.6,2,h;'#127+
	'Volume = l\cdot w\cdot h\nl '+
	'Surface area = 2(lw + lh + hw). This assumes the box has a top and '+
	'bottom.';
  replace(nl+nl+nl,'',text3);
  dgm2:=#127'500,500,1200,0;I,150,275,25;L,0,0,0,8;L,0,0,6,0;L,0,0,-2,-2;L,-2,-2,4,-2;L,4,-2,6,0;'+
    'L,-2,-2,-2,6;L,-2,6,4,6;L,4,6,4,-2;L,-2,6,0,8;L,0,8,6,8;L,6,8,4,6;'+
    'L,6,8,6,0;B,4;F,-1,0;F,1,-1;F,1,1;F,5,-.5;F,5,1;B,2;C,1,-3,x;'+
    'C,5.5,-1.5,x;C,-3,2,y;'#127;
  solution::='\nl\red{Solution:}\nl '+dgm2+nl+
    'V = x'#30'2'#31'y, and S = x'#30'2'#31' + 4xy.'+#10+nl+
    'Thus '+st(a)+' = x'#30'2'#31' + 4xy => '+nl+
    'y = '+makeformula('[a-x^2]/[4x]',
    ['a'],v)+'.'+#10+nl+nl+
    'Hence V = x'#30'2'#31'y = '+makeformula('[x^2(a-x^2)]/[4x]',['a'],v)+
    ' => '+nl+'V(x) = '+answer+'.';
  type := 'R';
  key :=4009;
end;

procedure s4009;
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4012;
var
  a,k : integer;
  sol,dgm,dgm2,text:string;
  v:valuetype;
begin
  a := randint(10,40);v.a:=a;
  dgm:=#127'300,300,1200,0;I,200,80,20;E,4,1,-4,-1;L -4,0,-4,8;'+
     'L,4,0,4,8;E,4,9,-4,7;B,3;F,0,0;F,3.7,.9;F,-3.7,.9;F,3.7,7.5;F.-3.7,7.5;'+
     'F,0,8;B,2;L,0,0,4,0;C,1.5,-2,r;';
  text:='A can with top and bottom is in the form of a right circular '+
    'cylinder. The total surface area is '+st(a)+' square inches. Express '+
    'the volume V of the can as a function of r, the radius of its '+
    'base.';
  text1::=dgm+#127+text+'\nl\nl ';
  prompt:=#133'V(r) = '#134;
  help::='\red{Formulas for a Cylinder:}\nl '+
  	'Volume = $$\pi r^2h$$\nl\nl '+
	'Lateral Surface Area = $$2\pi rh$$\nl\nl '+
	'Lateral Surface Area plus Top and Bottom =$$2\pi r h+2\pi r^2$$';
  text3::=text1+#13+#13+'\nl\blue{Hint:}\nl '+
    'Let r denote the radius of the base and let h denote the '+
    'height of the cylinder. Express both the volume and total surface '+
    'area of the cylinder in terms of r and h.\nl ';
  replace(nl+nl+nl,'',text3);
  dgm2:=dgm+'C,-5.5,4,h;';
  answer:=fraction(a,'-',2)+'r - ~r'#30'3'#31;
  solution::='\nl\red{Solution:}\nl '+dgm2+#127+nl+
    'V = ~r'#30'2'#31'h, and S = 2~r'#30'2'#31' + 2~rh.'+#10+nl+
    'Thus '+st(a)+' = 2~r'#30'2'#31' + 2~rh => h = '+makeformula('[a-2~r^2]'+
    '/[2~r]',['a'],v)+'.'+#10+nl+nl+
    'Hence V = ~r'#30'2'#31'h = '+makeformula('[~r^2(a-2~r^2)]/[2~r]',['a'],v)+
    ' => '+nl+'V(r) = '+answer+'.';
  type := 'R';
  key :=4012;
end;

procedure s4012;
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4013;           {old 269}
var
  vals:valuetype;
  x:paramtype;
  txt,ans,dgm,text:string;
begin
  vals.t := randint(1,6);
  repeat
    vals.s := randint(vals.t+1,7);
    vals.x := 2*vals.s*vals.t;
    vals.y := vals.s*vals.s-vals.t*vals.t;
    vals.c := vals.s*vals.s+vals.t*vals.t;
    vals.a := vals.c-vals.x;x.a:=vals.a;
  until (GCD(vals.s,vals.t)=1) and (((vals.s-vals.t) mod 2) <> 0);
  vals.b := vals.c-vals.y;x.b:=vals.b;
  vals.d := (vals.a*vals.a+vals.b*vals.b) div vals.c;
  dgm:=#127'500,500,1250,0;I,150,200,25;L;0,0,0,10;L,0,10,12,0;L,12,0,0,0;'+
  	'L,1,0,1,1;L,0,1,1,1;B,2;C,6.5,5,h;';
  text:='In a certain right triangle the hypotenuse is '+
  	st(vals.a) +' inches larger than the first leg and '+st(vals.b)+
	' xxx larger than the second leg. Find the length h of the  '+
	'hypotenuse.';
  replace('xxx','inches',text);
  if vals.a=1 then replace('inches','inch',text);
  text1::= dgm+#127+text+nl+nl+nl;
  text3::=text1+#13+'\nl\blue{Hint:}\nl '+ 
    'Express each side in terms of h and then apply the Pythagorean '+
    'Theorem.';
  replace(nl+nl+nl,'',text3);
  prompt::=#133'h = '#134;
  help::=#127'500,500,700,0;I,250,250,50;L,0,0,0,4;L,0,4,2,0;L,0,0,2,0;'+
	'B,2;C,-.5,1.8,a;C,.8,-.6,b;C,1.4,1.8,c;'#127+
	'\red{Pythagorean Theorem:}\nl '+
	'$$a^2+b^2=c^2$$';
  answer := st(vals.c);
  solution::='\nl\red{Solution:}\nl '+
    #127'500,500,1200,180;I,150,250,25;L;0,0,0,10;L,0,10,12,0;'+
    'L,12,0,0,0;B,2;C,-3.8,4,h-'+st(vals.b)+';C,5,-1,h-'+st(vals.a)+';C,6,6,h;'#127+nl+
    'If h denotes the hypotenuse, then one leg is\nl $$h-\a$$ and the other '+
    'is $$h-\b$$.\pause\nl '+
    'By the Pythagorean Theorem we have\nl '+
    '$$(h-\a)^2+(h-\b)^2=h^2$$\pause\nl '+
    '=> '+makeformula('h^2-'+st(2*vals.a)+'h+a^2+h^2-'+st(2*vals.b)+'h+b^2=h^2',['a','b'],vals)+nl+#10+
    '=>	'+makeformula('h^2-'+st(2*vals.a+2*vals.b)+'h+'+st(vals.a*vals.a+vals.b*vals.b)+'=0',[],vals)+nl+#10+
    '=>	'+makeformula('(h-c)(h-d)=0',['c','d'],vals)+nl+#10+
    'So h = '+st(vals.c)+' or '+st(vals.d)+nl+#10+
    'Notice that '+st(vals.d)+' is too small.\pause\nl '+
    'Thus h = '+answer+'.';
  key := 4013;
  type := 'R';
  result := 'F'
end;

procedure s4013;             
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4016;
var
  a,b,c,d,e,f,k:integer;
  v:valuetype;
  x:paramtype;
  dgm,text:string;
begin
  k:=randint(1,3);
  a:=randint(2,8);x.a:=a;
  c:=2*(1+a); v.a:=a;
  v.c:=c;
  d:=3*(a*a);
  v.d:=d;
  e:=2+4*a;
  v.e:=e;
  f:=(a*a)-1;
  v.f:=f;
  case k of
  1:begin
    dgm:=#127'300,300,1200,0;I,150,100,20;E,4,1,-4,-1;'+
      'L,0,0,4,0;B,2;C,.5,3,h;C,1,.1,r;B,0;L,4,.4,0,8;'+
      'L,-4,.4,0,8;L,0,0,0,8;'#127;
    text:='If the height h of a right circular cone is '+
      st(a)+' times the radius r of its base, express the volume V '+
      'of the cone as a function of h.';
    text1::=dgm+'If the height h of a right circular cone is '+
      st(a)+' times the radius r of its base, express the volume V '+
      'of the cone as a function of h.\nl\nl\nl ';
    help::='Volume of a Cone: {\pi\over 3}r^2h';
    prompt::=#133'V(h) = '#134;
    text3::=text1+nl+#142'Hint:'#142+nl+
      'The radius r of the cone is '+fraction(1,'/',a)+' times the height. '+
      'Substitute for r in the formula expressing the volume of a cone in terms '+
      'of its radius and height.\nl ';
    replace(#13#13,'',text3);
    answer:=makeformula('[~h^3]/[d]',['d'],v);
    solution::= '\nl\red{Solution:}\nl '+
      #127'300,300,1200,0;I,150,100,20;E,4,1,-4,-1;'+
      'B,2;C,.5,3,h;B,0;L,0,0,4,0;B,2;C,1,-2,r={h\over \a};B,0;L,4,0,0,8;'+
      'L,-4,.4,0,8;L,0,0,0,8;'#127+nl;
    solution2::='$$V={\pi\over 3}r^2h$$\pause\nl '+
    	'=$${\pi\over 3}({h\over \a})^2h$$\pause\nl '+
	'= '+answer+'.';
    end;{case}
  2:begin
    dgm::=#127'500,500,1200,0;I,150,225,25;L,0,0,0,8;L,0,0,6,0;L,0,0,-2,-2;L,-2,-2,4,-2;L,4,-2,6,0;'+
      'L,-2,-2,-2,6;L,-2,6,4,6;L,4,6,4,-2;L,-2,6,0,8;L,0,8,6,8;L,6,8,4,6;'+
      'L,6,8,6,0;B,2;C,1,-3,x;C,6.5,3,y;'#127;
    text:='A rectangular box has a square top and bottom. '+
      'The height y of the box is \a  times the edge x of the bottom. '+
      'Express the surface area A of the box as a function of x.';
    text1::=dgm+'A rectangular box has a square top and bottom. '+
      'The height y of the box is \a  times the edge x of the bottom. '+
      'Express the surface area A of the box as a function of x.\nl\nl\nl\nl ';
    text3:=text1+nl+#142'Hint:'#142+nl+
      'Express A in terms of x and y and then substitute '+st(a)+'x for '+
      'y.';
    replace(#13#13#13,'',text3);      	
    help::='Volume of a Rectangular Box:\nl '+
    	'length\cdot width\cdot height\nl '+
	'Area of a Rectangle: length\cdot width';
    prompt::=#133'A(x) = '+#134;
    answer:=makeformula('ex^2',['e'],v);
    solution::='\nl\red{Solution:}\nl '+
      #127'500,500,1200,0;I,150,175,25;L,0,0,0,8;L,0,0,6,0;L,0,0,-2,-2;L,-2,-2,4,-2;L,4,-2,6,0;'+
      'L,-2,-2,-2,6;L,-2,6,4,6;L,4,6,4,-2;L,-2,6,0,8;L,0,8,6,8;L,6,8,4,6;'+
      'L,6,8,6,0;B,2;C,1,-3,x;C,6.5,3,y='+st(a)+'x;'#127+nl;
    solution2::=makeformula('A=2x^2+4xy',[],v)+#10+' = '+
       makeformula('2x^2+4x('+st(a)+'x)',[],v)+nl+#10+' = '+
       answer;
    end;{case}
  3:begin
    dgm::=#127'500,500,1200,0;I,250,300,100;E,1.5,1.5,-1.5,-1.5;'+
      'L,0,0,1.05,1.05;B,2;C,.5,.7,R;B,0;E,.8,.8,-.8,-.8;L,0,0,.8,0;B,2;C,.4,.05,r;'#127;
    text:='Two circles have the same center. If r is the '
      +'radius of the smaller circle, and the radius R of the larger circle '
      +'is '+st(a)+' times the radius of the smaller circle, express the '
      +'area A between the circles as a function of r.';
    text1::=dgm+'Two circles have the same center. If r is the '
      +'radius of the smaller circle, and the radius R of the larger circle '
      +'is '+st(a)+' times the radius of the smaller circle, express the '
      +'area A between the circles as a function of r.\nl\nl\nl ';
    help::='Area of a Circle of Radius r: \pi r^2\nl '+
      'Circumference of a Circle of Radius r: 2\pi r';
    prompt::=#133'A(r) = '#134;
    text3:=text1+nl+#142'Hint:'#142+nl+
      'If R denotes the radius of the larger circle and r denotes the '+
      'radius of the smaller circle, express the area between the circles '+
      'in terms of r and R. Then substitute '+st(a)+'r for R.';
    replace(#13#13,'',text3);
    answer:=makeformula('f~r^2',['f'],v);
    solution::='\nl\red{Solution:}\nl '+dgm+nl+
       makeformula('A=~R^2-~r^2',[],v)+#10+' = '+
       makeformula('~('+st(a)+'r)^2-~r^2',[],v)+nl+#10+' = '+
       answer;
    end;{case}
  end;
  type:='R';
  key := 4016;
end;

procedure s4016;
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4017;
var
  a,b:integer;
  v:valuetype;
  dgm,dgm1:string;
begin
  case randint(1,2) of
  1:begin
      dgm:=#127'400,400,1200,0;I,160,160,40;L,0,0,5,0;L,5,0,5,5;'+
           'L,5,5,0,5;L,0,0,0,5;B,2;C,2.5,-1,x;C,-1,2,x;'#127;
      text1::= dgm+'Express the area A of a square as a function '+
               'of its perimeter P.\nl\nl\nl\nl ';
      text3:=text1+nl+#142'Hint:'#142+nl+
      	'Express both the area and perimeter of the square in terms of '+
             'x the edge length. Then eliminate the variable x to get A in terms of P.';
      replace(#13#13#13,'',text3);
      prompt::= #133'A(P) = '#134;
      dgm1::=#127'400,400,800,0;I,70,70,40;R,0,0,6,6;C,-.5,3,x;C,3,-.6,x;'#127;
      help::=dgm1+'Area of Square: x^2\nl '+
      	     'Perimeter of Square: 4x';
      answer := makeformula('[P^2]/[16]',[],v);
      solution::='\nl\red{Solution:}\nl '+dgm+'Express the area A of a square as a function '+
                 'of its perimeter P.'+nl+
                 'A = x'#30'2'#31#10+nl+
                 'P = 4x.'+#10+nl+
                 ' => '+makeformula('x=[P]/[4]',[],v)+#10+nl+
                 ' => '+makeformula('A=x^2=([P]/[4])^2=[P^2]/[16]',[],v)+#10+nl+
                 'Thus the area A(P) = '+answer+'.';
    end;
  2:begin
      dgm:=#127'400,400,1200,0;I,200,200,40;P,4,0,6.29;L,0,0,4,0;B,2;C,2,-.6,r;'#127;
      text1 := dgm+'Express the circumference C of a circle as a '+
               'function of its area A.'+nl+nl+nl+nl+nl+nl;
      text3:=text1+nl+#142'Hint:'#142+nl+
      	'Express both the area and circumference of the circle in terms of '+
        'r, the radius. Then eliminate the variable r to get C in terms of A.';
      replace(#13#13#13#13#13,'',text3);
      prompt::= #133'C(A) = '#134;
      dgm1:=#127'400,400,800,0;I,200,200,40;P,4,0,6.29;L,0,0,4,0;C,2,-.6,r;'#127;
      help::=dgm1+'Area of Circle: \pi r^2\nl '+
      	     'Circumference of Circle: 2\pi r';
      answer := '2@'#251'~A'#253;
      solution ::='\nl\red{Solution:}\nl '+dgm+
      	'Express the circumference C of a circle as a'+
        'function of its area A.'+#10+nl+
        'A = ~r'#30'2'#31#10+nl+
        'C = 2~r'+#10+nl+
        ' => '+makeformula('r={[A]/[~]}',[],v)+#10+nl+
        ' => '+makeformula('C=2~r=2~{[A]/[~]}=2{~A}',[],v)+#10+nl+
        'Thus the circumference C(A) = '+answer+'.';
    end;
  end;
  key := 4017;
  type := 'R';
end;

procedure s4017;
var
  res:string;
begin
  replace(prompt,'',response);
  res:=response;
  toupper(res);
  if sameexpres(answer,res) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4019;
var
  a,b:integer;
  v:valuetype;
  dgm,dgm1,text:string;
begin
  case randint(1,2) of
    1:begin
      a := 5*randint(10,20);v.a:=a;
      dgm:=#127'400,400,1200,10;I,200,260,40;L,3,-2,3,2;L,3,2,-3,2;'+
           'L,-3,2,-3,-2;L,-3,-2,3,-2;B,2;C,0,-2.6,x;';
      text:='A rectangle has area '+st(a)+'. Express its '+
      	      'perimeter P as a function of the length x of its base.';
      text1 :=dgm+#127+'A rectangle has area '+st(a)+'. Express its '+
      	      'perimeter P as a function of the length x of its base.'+
	      +nl+nl+nl+nl;
      text3:=text1+nl+#142'Hint:'#142+nl+
      	'Let y denote the length of the other side. Express '+
        'the area and perimeter P in terms of x and y. Then '+
        'eliminate y to obtain P in terms of x.';
      replace(nl+nl+nl,'',text3);
      prompt ::=#133'P(x) = '#134;
      dgm1:=#127'400,400,800,0;I,80,80,40;R,0,0,6,4;C,3,-.6,L;C,-.5,2,W;'#127;
      answer := makeformula('2x+['+st(2*a)+']/[x]',['a'],v);
      solution::='\nl\red{Solution:}\nl '+dgm+'C,3.2,-.2,y;'#127+nl+
        'P = 2x + 2y'+#10+nl+
        'Area = xy = '+st(a)+#10+nl+
        ' => '+makeformula('y=[a]/[x]',['a'],v)+#10+nl+
        ' => '+makeformula('P=2x+2\cdot[a]/[x]=2x+['+st(2*a)+']/[x]',['a'],v)+#10+nl+
        'Thus the perimeter P(x) = '+answer+'.';
    end;
  2:begin
      a := 10*randint(5,15);v.a:=a;
      dgm:=#127'400,400,1200,1;I,200,200,40;L,3,2,-3,2;L,-3,2,-3,-2;'+
           'L,-3,-2,3,-2;L,3,-2,3,2;B,2;C,0,-2.7,x;';
      text:='A rectangular plot will be fenced in with '+st(a)+
             ' feet of fencing. Express the area A of the plot '+
             'as a function of one side, x, of the rectangle.';
      text1:=dgm+#127+'A rectangular plot will be fenced in with '+st(a)+
             ' feet of fencing. Express the area A of the plot '+
             'as a function of one side, x, of the rectangle.'+nl+nl+nl+nl;
      text3:=text1+nl+#142'Hint:'#142+nl+
      	'Let y denote the other side. Express both the perimeter P and '+
        'area A in terms of x and y. Then eliminate y to express A in '+
        'terms of x.';
      replace(nl+nl+nl,'',text3);
      prompt :=#133'A(x) = '#134;
      answer := st(a div 2)+'x - x'#30'2'#31;
      solution ::='\nl\red{Solution:}\nl '+
      	dgm+'C,3.2,-.2,y;'#127+nl+
	'The plot is enclosed with '+st(a)+' feet of fencing.'+#10+nl+
        'P = 2x + 2y = '+st(a)+#10+nl+
        ' => '+makeformula('y=[a-2x]/[2]='+st(a div 2)+'-x',['a'],v)+#10+nl+
        ' => A = '+makeformula('xy=x\cdot('+st(a div 2)+'-x)',[],v)+nl+' = '+answer+#10+nl+
        'Thus the area A(x) = '+answer+'.';
    end;
  end;
  help::=#127'400,400,700,0;I,100,200,40;R,0,0,6,4;B,2;C,-.5,1.8,x;C,2.8,-.5,y;'#127+
	'\red{Formulas for Rectangles:}\nl '+
	'Area = xy\nl '+
	'Perimeter = 2x + 2y';
  key := 4019;
  type := 'R';
end;

procedure s4019;
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4020;
var
  a,b,c,d:integer;
  x:real;
  dgm,text,p,t:string;
  v:valuetype;
begin
  a := rand([5,6,7,8]);v.a:=a;
  b := randint(4,8);v.b:=b;
  c := rand([-7,-6,-8,3,4]);v.c:=c;
  d := randint(-6,-2);v.d:=d;
  x := sqrt(sqr(a-c)+sqr(b-d));
  str(a-.2:3:2,p);
  str(c-.2:3:2,t);
  str(x:8:6,answer);
  dgm:=#127'560,560,1200,10;A,280,280,20;B,2;C,'+p+','+st(b)+',.;C,'+t+','+st(d)+',.;'+
           'C,'+st(a)+'.4,'+st(b+1)+',('+st(a)+','+st(b)+');'+
           'C,'+st(c-1)+','+st(d-2)+',('+st(c)+','+st(d)+');'+
           'B,0;D,'+st(a)+','+st(b)+','+st(c)+','+st(d)+',10;'+
	   'G,'+st(b)+',D'+st(a)+','+st(a)+';G,'+st(d)+',D'+st(c)+','+st(c)+';';
  text:= 'Find the distance D between ('+st(a)+','+st(b)+') and '+
           '('+st(c)+','+st(d)+').';
  text1:=dgm+#127+text+nl+nl+nl+nl+nl+nl+nl+nl+nl+nl+nl;
  prompt::=#133'D = '#134;
  help::='\red{Distance Formula:}\nl '+
  	'The distance between (x_1,y_1) and (x_2,y_2) is given by \nl '+
  	'$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$';
  text3::=dgm+#127+text+#13+'\nl\blue{Hint:}\nl '+
  	'Use the distance formula which states that the distance between '+
        '(x'#31'1'#30',y'#31'1'#30') and (x'#31'2'#30',y'#31'2'#30') is given by '+
        makeformula('{(x'#31'2'#30'-x'#31'1'#30')^2+(y'#31'2'#30'-y'#31'1'#30')^2}',[],v)+'.';
  solution::='\nl\red{Solution:}\nl '+
         'The distance between ('+st(a)+','+st(b)+') and ('+st(c)+','+st(d)+') '+
	 'equals '+nl+
         makeformula('{(a-c)^2+(b-d)^2}',['a'..'d'],v)+#10+nl+
         ' = '+makeformula('{('+st(a-c)+')^2+('+st(b-d)+')^2}',[],v)+#10+nl+
         ' = '+makeformula('{'+st((a-c)*(a-c))+'+'+st((d-b)*(d-b))+'}',[],v)+#10+nl+
         ' = '+makeformula('{'+st((a-c)*(a-c)+(d-b)*(d-b))+'}',[],v)+
         ' '#163' '+answer+'.';
  replace('000000','0',solution);
  key := 4020;
  type := 'R';
end;

procedure s4020;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4022;{old48}
var
  a,b,c,d,f:integer;
  dgm,h,k,l,q,r,u,w,y,z,text:string;
  v:valuetype;
begin
  a := randint(2,6);v.a:=a;
  b := randint(3,6);v.b:=b;
  c := randint(-6,-4);v.c:=c;
  d := randint(-6,-4);v.d:=d;
  f:=(a-c)*(a-c)+(b-d)*(b-d);v.f:=f;
  str(300+25.0*(a+c)/2,h);
  str(250+25.0*(b+d)/2,k);
  str(0.5*sqrt((a-c)*(a-c)+(b-d)*(b-d)),r);
  str(d-1.5,u);
  str(c-5.5,w);
  y:=fraction(a+c,'-',2);
  z:=fraction(b+d,'-',2);
  q:=fraction(f,'-',4);
  dgm:=#127'600,500,1200,10;I,300,250,25;L,-10,0,10,0;L,0,-10,0,10;'+
       'D,'+st(a)+','+st(b)+','+st(c)+','+st(d)+',10;'+
       'B,4;C,'+st(a+1)+','+st(b)+','+makeformula('(a,b)',['a','b'],v)+';'+
       'C,'+w+','+u+','+makeformula('(c,d)',['c','d'],v)+';'+
       'B,0;G,'+st(b)+',D'+st(a)+','+st(a)+';G,'+st(d)+',D'+st(c)+','+st(c)+';'+
       'I,'+h+','+k+',25;B,2;P,'+r+',0,6.28;';
  text:='The segment from ('+st(a)+','+st(b)+') to '+
  	'('+st(c)+','+st(d)+') is a diameter of a certain circle. Find an '+
	'equation in x and y for the circle.';
  text1 := dgm+#127+'The segment from ('+st(a)+','+st(b)+') to '+
  	'('+st(c)+','+st(d)+') is a diameter of a certain circle. Find an '+
	'equation in x and y for the circle.'+nl+nl+nl+nl+nl+nl+nl+nl;
  text3:=dgm+#127+text+nl+nl+#142'Hint:'#142+nl+
  	'The equation of the circle of radius r with center (h,k) is '+
        makeformula('(x-h)^2+(y-k)^2=r^2',[],v)+'. The center is the '+
	'midpoint of the segment and the radius is half the distance '+
        'between the endpoints of the diameter.'+nl;
  prompt::=#133'Equation of Circle:'#134;
  help::='\red{Equation of Circle with Center (h,k) and Radius r:}\nl '+
  	 '$$(x-h)^2+(y-k)^2=r^2$$\nl\nl '+
	 '\red{Midpoints:}\nl '+
	 'The midpoint of the line segment from (a,b) to (c,d) is\nl '+
	 '$$({a+c\over 2},{b+d\over 2})$$.\nl\nl '+
	 '\red{Distance Formula:}\nl '+
	 'The distance from (a,b) to (c,d) is given by\nl '+
	 '$$\sqrt{(a-c)^2+(b-d)^2}$$.';
  answer:=makeformula('(x-'+y+')^2+(y-'+z+')^2='+q,[],v);
  replace('1200,10','1200,200',dgm);
  solution::='\nl\red{Solution:}\nl '+dgm+#127+nl+
	'The midpoint of the line segment between ('+st(a)+','+st(b)+')'+
	'and ('+st(c)+','+st(d)+') is '+
	makeformula('([a+c]/[2],[b+d]/[2])=('+y+','+z+')',['a'..'d'],v)+'\pause\nl '+
        'Thus the center is ('+y+','+z+').\pause\nl '+
        'The length of the diameter is '+makeformula('{(a-c)^2+(b-d)^2}={f}',['a'..'f'],v)+#10+nl+
        'The radius is '+makeformula('[{f}]/[2]',['f'],v)+'.'+#10+nl+nl+
        'An equation of the circle is '+nl+answer+'.';
  key := 4022;
  type := 'R';
end;

procedure s4022;
var
  res,ans:string;
  i:integer;
begin
  replace(prompt,'',response);
  res := response;
  ans := answer;
  i := pos('=',ans);
  delete(ans,i,1); insert('-(',ans,i); ans := ans + ')';
  i := pos('=',res);
  delete(res,i,1); insert('-(',res,i); res := res + ')';
  if sameexpres(ans,res) or sameexpres(ans,'-'+res) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+nl+text3
    else message:=response+' is '#140'incorrect'#140'. '+nl+text3;
  end;
end;

procedure p4024;  {old 39}
var
  a,b,c,d,r,s : integer;
  v:valuetype;
  q,u,w,y,z,dgm,ans:string;
begin  
  a:=randint(4,8);v.a:=a;
  b:=randint(4,8);v.b:=b;
  c:=randint(-8,-4);v.c:=c;
  d:=randint(-8,-4);v.d:=d;
  r:=a+c;v.r:=r;
  s:=b+d;v.s:=s;
  str(1.0*(a+c)/2,w);
  str(1.0*(b+d)/2,z);
  str(1.0*(a+c)/2+.7,u);
  str(1.0*(b+d)/2-.3,y);
  str(d-1.5,q);
  dgm:=#127'500,400,1200,10;I,200,200,20;L,'+st(a)+','+st(b)+','+st(c)+','+st(d)+';'+
       'L,-10,0,10,0;L,0,-10,0,10;B,2;'+
       'C,'+st(a)+','+st(b)+','+makeformula('(a,b)',['a','b'],v)+';'+
       'C,'+st(c-1)+','+q+','+makeformula('(c,d)',['c','d'],v)+';'+
       'B,4;G,'+z+',D'+w+','+w+';';
  text1:=dgm+#127+'Find the midpoint M of the '+
         'segment joining ('+st(a)+','+st(b)+') '+
         'and ('+st(c)+','+st(d)+').'+nl+nl+nl+nl+nl+nl+nl;
  help::='Midpoint of Line Segment from (a,b) to (c,d):\nl '+
  	 '({a+c\over 2},{b+d\over 2})';
  prompt::=#133'M = '#134;
  text3:=text1+nl+#142'Hint:'#142+nl+'The midpoint of the line '+
         'segment joining (a,b) '+
         'and (c,d) is given by '+
         makeformula('([a+c]/[2],[b+d]/[2])',[],v)+'.';
  replace(nl+nl+nl+nl+nl+nl,'',text3);
  answer:='('+fraction(r,'-',2)+','+fraction(s,'-',2)+')';
  ans:='('+fraction(r,'/',2)+','+fraction(s,'/',2)+')';
  solution::='\nl \red{Solution:}\nl Thus the midpoint is given by '+
            makeformula('([a+(c)]/[2],[b+(d)]/[2]',['a'..'d'],v)+#10+nl+
            ' = '+answer+'.';
  key:=4024;
  type := 'R';
end;

procedure s4024;
begin
  if samepoints(answer,response) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    if response = prompt then message:=#140'Incorrect'#140+#13+text3
    else message:=response+' is '#140'incorrect.'#140+#13+text3;
  end;
end;

procedure p4025; {old 1032}
var
  t:integer;
  v:valuetype;
  header,part1,part2,ans,a1,a2,s,text:string;
begin
  v.a := randint(-5,5);
  v.b := randint(-5,5);
  v.d := randint(1,4);
  v.c := randint(1,3)*v.d;
  v.e := sqr(v.d);
  v.f := sqr(v.d)*v.a*2;
  v.g := sqr(v.d)*v.b*2;
  v.h := v.e*sqr(v.a)+v.e*sqr(v.b)-sqr(v.c);
  v.i := sqr(v.c); v.j := sqr(v.c div v.d);
  s := makeformula('ex^2+ey^2-fx-gy+h=0',['e'..'h'],v);
  header:='\red{Answer both parts before grading.}\nl\nl ';
  text:='The equation of a circle is '+s;
  part1:='\red{a:}  Find the center (h,k) of the circle. (50%)';
  part2:='\red{b:}  Find the radius r of the circle. (50%)';
  text1::=header+text+#13+part1+#13+part2+#13;
  text:=text+#13+part1+#13+part2+#13;
  text3::=text+'\nl\blue{Hint:}\nl '+
  	'Put the equation in standard form '+
         makeformula('(x-h)^2+(y-k)^2=r^2',[],v)+' by '+
         'completing the square. The center is (h,k).';
  prompt::=#133'a: (h,k) = '#134#13+
  	   #133'b: r = '#134;
  help::='\red{Completion of the Square:}\nl '+
  	'$$x^2+ax+b=x^2+ax+({a\over 2})^2-({a\over 2})^2+b=(x+{a\over 2})^2+b-({a\over 2})^2$$\nl\nl '+
	'\red{Equation of Circle with center (h,k) and radius r:}\nl '+
	'$$(x-h)^2+(y-k)^2=r^2$$';
  ans:=#134'('+st(v.a)+','+st(v.b)+')'#133#134+st(v.c div v.d);
  answer::=ans;
  separate(answer,a1,a2);
  solution::='\nl\red{Solution:}\nl '+ s+nl+#10+
            ' => '+makeformula('e(x^2+'+st(-2*v.a)+'x)+e(y^2+'+st(-2*v.b)+'y)=-h',['e','h'],v)+#10+nl+
            ' => '+makeformula('e(x^2+'+st(-2*v.a)+'x+'+st(v.a*v.a)+')+e(y^2+'+st(-2*v.b)+'y+'+st(v.b*v.b)+')=-h+'+st(v.e*v.a*v.a)+'+'+st(v.e*v.b*v.b),['e','h'],v)+#10+nl+
            ' => '+makeformula('e(x-a)^2+e(y-b)^2='+st(v.c*v.c),['a','b','e'],v)+#10+nl+
            ' => '+makeformula('(x-a)^2+(y-b)^2='+fraction(v.c*v.c,'-',v.e),['a','b'],v)+#10+nl+
            'Thus the center is '+a1+' and the radius is '+a2+'.';
  key := 4025;
  type := 'R';
end;

procedure s4025;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  replace(prompt,'',response);
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=samepoints(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+text3;
  end;
end;

procedure p4026;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,text:string;
begin
  x.a:=rand([2,3,4,6]);
  x.b:=x.a+rand([1,2,3]);
  x.m:=rand([-2,-3,-5,-7]);
  x.c:=x.m*x.a-x.b;
  x.d:=-x.c;
  x.e:=x.c^2;
  x.f:=2*x.m;
  dgm::=#127'600,500,1200,10;I,150,100,50;L,-2,0,8,0;L,0,-2,0,8;L,0,6,4,0;'+
  	'G,3.67,D1.58,1.58;C,1.94,3.83,(\a,\b);C,4.44,1.67,slope = \m;'+
	'D,3.19,1.17,4.31,1.61,4;B,2;F,1,1;';
  text:='A line passes through (\a,\b) and has slope \m. Find the '+
  	'area A of the triangle in the first quadrant bounded by this line '+
	'and the co-ordinate axes.';
  text1::=dgm+#127+text+'\nl\nl\nl\nl\nl\nl\nl ';
  text3::=text+#13+'\nl\blue{Hint:}\nl '+
  	'Find the equation of the line through (\a,\b) with slope \m, and '+
        'and then find the intercepts with each of the axes.';
  prompt::=#133'A = '#134;
  help::='\red{Point Slope Equation of a Line:}\nl '+
  	'$$y-a=m(x-b)$$\nl\nl '+
	'\red{Area of a Triangle:}\nl '+
	'{1\over 2}\cdot base\cdot height';
  ans:='{$\e\over -\f$}';
  answer::=ans;
  dgm:=dgm+'B,0;C,-2.5,5.9,(0,\d);C,3,-.5,({$-\d\over \m$},0);G,6,D0,0;'+
  	'G,0,D4,4;';
  solution::='\nl\red{Solution:}'+dgm+#127+nl+
  	'The equation of the line is $$y-\b=\m(x-\a)$$ or $$y=\m x+\d$$.\pause\nl '+
	'Now y = 0 => x = {$-\d\over \m$} so the base of the triangle is {$-\d\over \m$}.\pause\nl '+
	'Also x = 0 => y = \d  so the height of the triangle is \d.\pause\nl '+
	'Thus the area of the triangle is {1\over 2}\cdot base\cdot height = '+
	'{1\over 2}\cdot {$-\d\over \m$}\cdot \d  = '+ans+'.'; 	   
  type:='R';
  key:=4026;
end;

procedure s4026;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4027; {old 37}
var
  a,b,c,d,r,s : integer;
  v:valuetype;
  q,u,w,y,z,dgm,ans:string;
begin
  a:=randint(4,8);v.a:=a;
  repeat b:=randint(-5,5);v.b:=b; until b<>0;
  c:=randint(-7,-3);v.c:=c;
  repeat
    d:=randint(-8,8);v.d:=d;
  until (abs(b-d)>2) and (abs(d)>1);
  dgm:=#127'600,400,1200,10;I,300,200,20;G,'+st(b)+',D'+st(a)+','+st(a)+';'+
       'G,'+st(d)+',D'+st(c)+','+st(c)+';'+	
       'B,2;L,'+st(a)+','+st(b)+','+st(c)+','+st(d)+';'+
       'B,0;L,-10,0,10,0;L,0,-10,0,10;B,4;'+
       'C,'+st(a+1)+','+st(b)+','+makeformula('(a,b)',['a','b'],v)+';'+
       'C,'+st(c-7)+','+st(d)+','+makeformula('(c,d)',['c','d'],v)+';';
  text1:=dgm+#127+'Find the slope m of the line containing the points '+
  	'('+st(a)+','+st(b)+') and ('+st(c)+','+st(d)+')'+
         nl+nl+nl+nl+nl+nl+nl;
  text3::=text1+#13+'\nl\blue{Hint:}\nl '+
  	'The slope of the line passing through (a,b) and (c,d) is given by '+
         makeformula('m=[d-b]/[c-a]',[],v)+'.';
  replace(nl+nl+nl+nl+nl,'',text3);
  prompt:=#133'm = '#134;
  help::='The slope of the line passing through (a,b) and (c,d) is given by '+
	 '$${d-b\over c-a}$$.';
  answer:=fraction(d-b,'-',c-a);
  solution::='\nl\red{Solution:}\nl '+
  	    'The slope of the line containing ('+st(a)+','+st(b)+') and '+
            '('+st(c)+','+st(d)+') is '+nl+
            makeformula('m=[b-d]/[a-c]',['a'..'d'],v)+' = '+answer+'.';
  key:=4027;
  type := 'R';
end;

procedure s4027;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4028; {old 38}
var
  a,b,c,d,r,s : integer;
  v:valuetype;
  x:paramtype;
  m,dgm:string;
begin
  a:=randint(4,8);v.a:=a;x.a:=a;
  repeat b:=randint(-5,5);v.b:=b; until abs(b)>1;x.b:=b;
  c:=randint(-7,-3);v.c:=c;x.c:=c;
  repeat
    d:=randint(-8,8);v.d:=d;
  until (abs(b-d)>2) and (abs(d)>1);x.d:=d;
  m:=fraction(b-d,'-',a-c);x.m:=(x.b-x.d)/(x.a-x.c);
  x.p:=-x.m*x.a+x.b;
  x.t:=x.a+1;
  if x.m>0.0 then x.q:=x.b-1 else x.q:=x.b+1;
  if x.m>0.0 then x.r:=x.c-7 else x.r:=x.c;
  x.s:=x.d+1;
  dgm:=#127'600,500,1200,10;I,300,250,20;B,2;G,\m:4 x+\p:4,-10,10;B,0;G,\b,D\a,a;'+
  	'G,\d,D\c,\c;B,0;L,-10,0,10,0;L,0,-10,0,10;'+
	'B,4;C,\t,\q,(\a,\b);C,\r,\s,(\c,\d);';
  text1::=dgm+#127+'Find an equation of the line passing through the two points '+
  	'('+st(a)+','+st(b)+') and ('+st(c)+','+st(d)+')'+
         nl+nl+nl+nl+nl+nl+nl+nl;
  text3::=text1+#13+'\nl\blue{Hint:}\nl '+
  	'First find the slope m of the line and then use the point-slope '+
  	'form of the equation of a line:'+nl+
         makeformula('y-b=m(x-a)',[],v)+nl+
         'where (a,b) is any point on the line.';
  replace(nl+nl+nl+nl+nl+nl+nl+nl,'',text3);
  prompt:=#133'equation: '#134;
  help::='\red{Equations of Lines:}\nl '+
  	'The slope of the line passing through (a,b) and (c,d) is given by '+
	 '$${d-b\over c-a}$$ \nl\nl '+
	 'Point-Slope Equation of Line through (a,b) having slope m:\nl '+
	 '$$y-b=m(x-a)$$\nl\nl '+
	 'Slope-Intercept Equation of Line through (0,b) having slope m:\nl '+
	 '$$y=mx+b$$.';
  answer := makeformula('y-b='+m+'(x-a)',['a','b'],v);
  solution::='\nl\red{Solution:}\nl '+dgm+#127+
  	'Find an equation of the line passing through the two points '+
  	'('+st(a)+','+st(b)+') and ('+st(c)+','+st(d)+')\nl\nl '+
  	'The slope of the line is '+nl+
        makeformula('m=[b-d]/[a-c]='+m,['a'..'d'],v)+nl+
        'Thus an equation of the line is given by\nl '+answer+'.';
  key :=4028;
  type := 'R';
end;

procedure s4028;
begin
replace(prompt,'',response);
  if samelinequat(response,answer) then begin
    message := #141'Correct'#141;
    result := 'T';
  end else begin
    if response = '' then message := #140'Incorrect'#140+#13+text3
    else message := response+' is '#140'incorrect'#140'. '+#13+text3;
    result := 'F';
  end;
end;

procedure p4029; {old 42}
var
  v:valuetype;
  a,b,d,m,n,g:integer;
  f0,f1 : string;
begin
  a:=randint(-6,6);
  b:=randint(-6,6);
  d:=randint(-6,6);
  m:=randint(1,7);
  n:=randint(1,7);
  v.m := m; v.n := n; v.d := d;
  f1 := makeformula('mx+ny+d=0',['m','n','d'],v);
  text1:='Find an equation of the line passing through the point '+
         '('+st(a)+','+st(b)+') and perpendicular to the line having '+
         'equation '+f1+'.'+nl;
  text3:=text1+nl+#142'Hint:'#142+nl+
  	'Perpendicular lines have negative reciprocal slopes. Use this '+
         'to find the slope m of the desired line and then use the point-'+
         'slope form of the equation of a line:'+nl+makeformula('y-b=m(x-a)',[],v)+'.';
  help::='If line L has slope m, and line M is perpendicular to L, then M '+
  	'has slope {-1\over m}.\nl '+
	'Point-Slope Equation of Line through (a,b) having slope m:\nl '+
	'$$y-b=m(x-a)$$\nl '+
	'Slope-Intercept Equation of Line through (0,b) having slope m:\nl '+
	'$$y=mx+b$$ .';
  f0 := fraction(n,'-',m);
  v.a := a; v.b := b;
  answer := makeformula('y-b ='+f0+'(x-a)',['b','a'],v);
  solution:=#13#140'Solution:'#140+nl+
            makeformula('mx+ny+d=0',['m','n','d'],v)+#10+nl+
            ' => '+makeformula('y=[-m]/[n]x+[-d]/[n]',['m','n','d'],v)+#10+nl+
            'The slope of the line '+f1+' is '+fraction(-m,'-',n)+
            ' so the slope m of the desired line is '+f0+'.'+#10+nl+
            'Thus an equation of the desired line is '+
            answer+'.';
  replace('+ '#29#219'-','- '#29#219,solution);
  key:=4029;
  type := 'R';
end;

procedure s4029;
begin
replace(prompt,'',response);
  if samelinequat(response,answer) then begin
    message := #141'Correct'#141;
    result := 'T';
  end else begin
    if response = '' then message := #140'Incorrect'#140+#13+text3
    else message := response+' is '#140'incorrect'#140'. '+#13+text3;
    result := 'F';
  end;
end;

procedure p4030;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm:string;
begin
  x.c:=rand([1,2,3]);
  x.r:=rand([2,3,5,6,8]);
  x.d:=x.c^2;
  x.a:=x.r*x.c;
  x.b:=x.a^2;
  x.m:=x.c*(x.r+1);
  dgm:=#127'500,500,1200,0;I,100,100,50;L,-2,0,8,0;L,0,-2,0,8;B,2;G,.2x^2,0,8;'+
  	'B,0;L,-.44,-1.67,6.25,6.22;B,2;G,.33,D1.27,1.27;G,4.5,D4.77,4.77;'+
	'B,4;C,5.06,4.06,(a,b);C,1.81,.08,(\c,\d);C,.38,3.11,slope \m;'+
	'D,1.81,3.17,2.25,1.61,5;'#127;
  text1::=dgm+'Find a point (a,b) on y = x^2 such that the line through '+
  	'(a,b) and (\c,\d) has slope \m.\nl\nl\nl\nl\nl\nl\nl\nl\nl ';
  text3::=dgm+text1+nl+#142'Hint:'#142+nl+'Set up a formula for the slope of the line through (a,b) and '+
  	'(\c,\d) and set it equal to \m. Use the fact that b = a^2.';  
  replace(#13#13#13#13#13#13#13#13,'',text3);
  prompt::=#133'(a,b) = '#134;
  help::='The slope of the line passing through (a,b) and (c,d) is given by '+
	'$${d-b\over c-a}$$.\nl '+
	'Roots of $$ax^2+bx+c$$:\nl '+
	'$$x={-b\pm\sqrt{b^2-4ac}\over 2a}$$.\nl '+
	'$$a^2-b^2=(a-b)(a+b)$$';
  ans:='(\a,\b)';
  answer::=ans;
  solution::='\nl\red{Solution:}\nl '+
  	'The slope of the line through (a,b) and (\c,\d) is $${b-\d\over a-\c}$$.\pause\nl '+
	'Since (a,b) is on $$y=x^2$$, b = a^2. Thus we have\nl '+
	'$${a^2-\d\over a-\c}=\m$$ or $$a+\c=\m$$.\pause\nl '+
	'Thus $$a=\m-\c=\a$$ and $$b=a^2=\b$$.\pause\nl '+
	'So the point (a,b) is '+ans+'.';
  type:='R';
  key:=4030;
end;

procedure s4030;
begin
  if samepoints(answer,response) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    if response = prompt then message:=#140'Incorrect'#140+#13+text3
    else message:=response+' is '#140'incorrect.'#140+#13+text3;
  end;
end;

procedure p4032; {old 207}
var
  a,b:integer;
  v:valuetype;
  ans,endpt:string;
begin
  repeat a:=randint(-9,9) until a <> 0;
  repeat b:=randint(-9,9) until (b <> 0) and (b <> a);
  v.a := a; v.b := b;
  text1 := 'Find the domain of f(x) = '+
    makeformula('{ax+b}',['a','b'],v)+'.  '+
    'Use interval notation to write your answer. '+nl;
  endpt:='{$'+st(-b)+'\over '+st(a)+'$}';
  if a<0 then
    ans:='(-\inf,'+endpt+']'
  else
    ans:='['+endpt+',\inf)';
  answer::=ans;
  text3 := text1+nl+#142'Hint:'#142+nl+
    makeformula('{ax+b}',['a','b'],v)+' is defined only if '+
    makeformula('ax+b&0',['a','b'],v)+'.';
  prompt::=#133'Domain: '#134;
  help::='\red{Domains:}\nl '+
  	'Expressions inside square root signs must be \ge  0.\nl '+
  	'Division by zero is not allowed.';
  solution :=#13#140'Solution:'#140+nl+
  	makeformula('ax+b & 0',['a','b'],v)+#10+nl+
        ' => '+makeformula('ax & -b',['a','b'],v)+#10+nl;
  if v.a > 0 then solution := solution +
    ' => '+makeformula('x & [-b]/[a]',['a','b'],v)
  else solution:= solution +
    ' => '+makeformula('x![-b]/[a]',['a','b'],v);
  if (gcd(a,b) > 1) or ((b>0) and (a<0)) then solution:=solution+' = '+fraction(-b,'-',a);
  solution := solution + #10+nl+'In interval notation, the domain is '+answer+'.';
  key := 4032;
  type := 'R';
end;

procedure s4032;
var
mes,res,res1,res2,res3,insrt:string;
check1,check2:boolean;
begin
  check1:=false;
  check2:=false;
  res3:=response;
  replace('(','[',res3);
  check1:=sameintervals(answer,res3);
  res3:=response;
  replace(')',']',res3);
  check2:=sameintervals(answer,res3);
  if check1 or check2 then mes:='You must include the endpoint.';
  if sameintervals(answer,response) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    if response = prompt then message:=#140'Incorrect. '#140+#13+text3
    else message:=response+' is '+#140'incorrect. '#140+#13+mes+#13+text3;
  end;
end;

procedure p4033;  {old 208}
var
  i,k:integer;
  rstr:string;
  v:valuetype;
begin
  i:=randint(2,8);
  repeat k := randint(-6,i-1) until k <> 0;
  v.b:=i+k;
  v.c:=i*k;
  v.k := k; v.i := i;
  rstr:=makeformula('{x^2+bx+c}',['b','c'],v);
  text1 :='Find the domain of f(x) = '+rstr+'.  '+
    'Express your answer as a collection of intervals separated by commas.'+nl;
  answer :='(-\,'+st(-i)+'] , ['+st(-k)+',\)';
  buff3:='(-\,'+st(-i)+') , ('+st(-k)+',\)';
  prompt::=#133'Domain: '#134;
  text3 := text1+nl+#142'Hint:'#142+nl+'The function is defined where '+nl+
    makeformula('x^2+bx+c&0',['b','c'],v)+'.';
  help::='Expressions inside square root signs must be \ge  0.\nl '+
  	'Division by zero is not allowed.';
  solution := #13#140'Solution:'#140#13'Factor:'+nl+
    makeformula('(x+i)(x+k)&0',['i','k'],v)+#10+nl+
    'Both are positive or both are negative:'+#10+nl+
    makeformula('x+i&0,@x+k&0',['i','k'],v)+
    ' => '+makeformula('x&-i@and@x&-k',['i','k'],v)+#10+nl+
    ' => '+makeformula('x&-k',['k'],v)+#10+nl+
    makeformula('x+i!0,@x+k!0',['i','k'],v)+
    ' => '+makeformula('x!-i@and@x!-k',['i','k'],v)+#10+nl+
    ' => '+makeformula('x!-i',['i'],v)+'.'+#10+nl+
    'Thus the domain of '+makeformula('x^2+bx+c',['b','c'],v)+' in '+
    'interval form is '+answer+'.';
  key := 4033;
  type := 'R';
end;

procedure s4033;
var
mes,res:string;
check1:boolean;
begin
  res:=response;
  replace(prompt,'',res);
  replace('\','\inf',res);
  mes:='';
  check1:=false;
  check1:=sameintervals(buff3,response);
  if check1 then mes::='You must include the endpoints since \sqrt{0} is '+
  	'defined and equals 0.';    
  if sameintervals(answer,response) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    if response = prompt then message:=#140'Incorrect. '#140+#13+text3
    else message:=response+' is '#140'incorrect. '#140+#13+mes+#13+text3;
  end;
end;

procedure p4034;  {old 209}
var
  i,j:integer;
  fstr,den:string;
  v:valuetype;
begin
  repeat i:=randint(-7,7) until i <> 0;
  repeat j:=randint(-7,7) until j <> 0;
  v.i:=i;v.j:=j;
  v.b:=i+j;
  v.c:=i*j;
  fstr:=makeformula('[1]/[x^2+bx+c]',['b','c'],v);
  den:=makeformula('x^2+bx+c',['b','c'],v);
  text1 :='Find the Domain of g(x) = '+fstr+'.  '+nl+
    'Express your answer as a collection of intervals separated by commas.'+nl;
  prompt := #133'Domain:  '#134;
  text3:=text1+nl+#142'Hint:'#142+nl+
    'g(x) = '+fstr+' is defined for all real values of x for which the denominator '+
    'is non-zero. Determine the values of x for which the denominator is '+
    'zero and then exclude these values.';
  help::='\red{Domain Information:}\nl '+
	'\ \ Expressions inside square root signs must be \ge  0.\nl '+
  	'\ \ Division by zero is not allowed.';
  i:= -i;  { (x+i) is a factor ->> -i is a root }
  j:= -j;
  if i < j then begin
    answer:='(-\,'+st(i)+'),('+st(i)+','+st(j)+'),('+st(j)+',\)';
    solution:=#13+#140'Solution:'#140#13+den+' = 0'+nl+makeformula('(x + i)(x + j) = 0',['i','j'],v)+
      nl+#10+'x = '+st(i)+' or x = '+st(j)+nl+#10+'Thus g(x) is defined when '+
      'x < '+st(i)+' or '+st(i)+' < x < '+st(j)+' or x > '+st(j)+'.'+nl+#10+
      'In terms of intervals, this is '+answer+'.';
  end else if i=j then begin
    answer:='(-\,'+st(i)+'),('+st(j)+',\)';
    solution:=#13+#140'Solution:'#140#13+den+' = 0'+nl+makeformula('(x + i)^2 = 0',['i','j'],v)+#10+
      nl+'x = '+st(i)+nl+#10+'Thus g(x) is defined when '+
      'x < '+st(i)+' or x > '+st(i)+'.'+nl+#10+'In terms of intervals, '+
      'this is '+ answer+'.';
  end else begin
    answer:='(-\,'+st(j)+'),('+st(j)+','+st(i)+'),('+st(i)+',\)';
    solution:=#13+#140'Solution:'#140#13+den+' = 0'+nl+makeformula('(x + i)(x + j) = 0',['i','j'],v)+#10+
    nl+'x = '+st(i)+' or x = '+st(j)+nl+#10+'Thus g(x) is defined when '+
    'x < '+st(j)+' or '+st(j)+' < x < '+st(i)+' or x > '+st(i)+'.'+nl+#10+
    'In terms of intervals, this is '+answer+'.';
  end;
  key := 4034;
  type := 'R';
end;

procedure s4034;
var
mes:string;
begin
  mes:='';
  if (pos('[',response)>-1) or (pos(']',response)>-1) then
    mes:='Endpoints are not included.';
  if sameintervals(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = prompt then message:=#140'Incorrect. '#140+#13+text3 else
    message := response+' is '#140'incorrect. '#140+#13+mes+#13+text3;
  end;
end;

procedure p4035;
var
  x:paramtype;
  undef,notwff:boolean;
  f,ans,a1,a2,dgm,header,text,part1,part2,sol:string;
  k:integer;
  answ:array[1..3,1..2] of string;
begin
  k:=randint(1,3);
  x.a:=rand([-2,-3,-5,2,4,6]);
  repeat x.b:=x.a+rand([-1,-2,2,3,4]) until x.b<>0.0;
  if k = 1 then begin
    f:='$$\a x+\b$$';
    answ[1,1]:='$${\a\over x}+\b$$';
    answ[1,2]:='$${1\over \a x+\b}$$';
    sol:=text+part1+part2+nl+'\red{Solution:}\nl '+
    	'f(x) = $$\a x+\b$$ => f({1\over x}) = $$\a({1\over x})+\b$$ = '+answ[1,1]+'.\pause\nl '+
    	'On the other hand, {1\over f(x)} = '+answ[1,2]+'.';
  end;
  if k = 2 then begin 
    f:='$${\a\over x}+\b$$';
    answ[2,1]:='$$\a x+\b$$';
    answ[2,2]:='$${x\over \a+\b x}$$';
    sol:=text+part1+part2+nl+'\red{Solution:}\nl '+
    	'f(x) = $${\a\over x}+\b$$ => f({1\over x}) = $${\a\over {1\over x}}+\b$$ '+
	'= '+answ[2,1]+'.\pause\nl '+
	'On the other hand, {1\over f(x)} = $${1\over {\a\over x}+\b}$$ = '+answ[2,2]+'.';
  end;
  if k = 3 then begin
    f:='$${\a\over x+\b}$$';
    answ[3,1]:='$${\a x\over 1+\b x}$$';
    answ[3,2]:='$${x+\b\over \a}$$';
    sol:=text+part1+part2+nl+'\red{Solution:}\nl '+
    	'f(x) = $${\a\over x+\b}$$ => f({1\over x}) = $${\a\over {1\over x}+\b}$$ '+
	'= '+answ[3,1]+'.\pause\nl '+
	'On the other hand, {1\over f(x)} = $${1\over {\a\over x+\b}}$$ = '+
	answ[3,2]+'.';
  end;
  header:='\red{Answer both parts before grading.}\nl\nl ';
  text:='Let f(x) = '+f+'. Give expressions for each of the following:\nl ';
  part1:='\red{a:}  f({1\over x}) (50%)\nl';
  part2:='\red{b:}  {1\over f(x)} (50%)\nl';
  text1:=header+text+part1+part2;
  text1::=text1;
  solution::=sol;
  prompt::=#133'a: f({1\over x}) = '#134#13+
    	   #133'b: {1\over f(x)} = '#134;
  help::='f({1\over x}): First divide 1 by x and then substitute this value '+
  	'into the formula for f(x).\nl '+
	'{1\over f(x)}: First substitute x into the formula for f(x) and then '+
	'divide 1 by the result.';
  text3::=text1+nl+#142'Hint:'#142+nl+
  	'Start with a number x and carefully consider the order of operations '+
  	'performed on x in each case.';
  ans:=#134+answ[k,1]+#133+
       #134+answ[k,2];
  answer::=ans;
  separate(ans,a1,a2);
  type:='R';
  key:=4035;
end;	   

procedure s4035;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameexpres(a1,r1);
  check2:=sameexpres(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;
	       
procedure p4038;
var
  x:paramtype;
  undef,notwff:boolean;
  header,text,part1,part2,ans,a1,a2,dgm:string;
begin
  x.a:=rand([-5,-4,-3]);
  x.b:=rand([-5,-4,-3]);
  x.c:=rand([3,4,5]);
  x.d:=rand([3,4,5]);
  dgm:=#127'480,480,1250,10;A,240,240,40;B,2;L,\a,\b,-1,2;L,-1,2,1,-1;'+
  	'L,1,-1,\c,\d;G,\b,D\a,\a;G,\d,D\c,\c;'#127;
  header::='\red{Answer both parts before grading.}';
  text::='The graph of a function is shown to the right. The scale on '+
	'each axis is 1. Express your answers in interval form.';  
  part1::='\red{a:}  Determine the domain of the function. (50%)';
  part2::='\red{b:}  Determine the range of the function. (50%)';
  text1::=dgm+header+#13+#13+text+#13+#13+part1+#13+part2+'\nl\nl\nl ';
  text3::=text1+nl+#142'Hint:'#142+nl+
  	'Use the vertical line test to determine the domain and the '+
  	'horizontal line test to determine the range.';
  replace(#13#13,'',text3);
  prompt::=#133'a: Domain:'#134#13+
    	   #133'b: Range:'#134;
  help::='The domain of a function consists of all x-values to which '+
  	'y-values have been assigned. The range consists of all y-values '+
	'assigned as x varies over the domain.';
  ans:=#134'[\a,\c]'#133+
       #134'[\b,\d]';
  answer::=ans;
  separate(ans,a1,a2);
  solution::='\nl\red{Solution:}\nl '+
  	'Vertical lines from x = \a  to x = \b  intersect the graph so by '+
	'the vertical line test the domain of this function is '+a1+'.\pause\nl '+
	'Horizontal lines from y = \b  to y = \d  intersect the graph so by '+
	'the horizontal line test the range of this function is '+a2+'.';
  type:='R';
  key:=4038;
end;	     

procedure s4038;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameintervals(a1,r1);
  check2:=sameintervals(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4042;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,fctn,sol,w:string;
  k:integer;
begin
  x.a:=rand([2,3,5,8]);
  x.b:=rand([10,12,14,16,18]);
  x.r:=rand([-2,-4,-5,1,2,3]);
  x.c:=rand([1,2,3,5]);
  x.d:=x.c+rand([1,2,3,4]);
  x.h:=x.d-x.c;
  k:=randint(1,3);
  if k = 1 then begin
    x.e:=x.a*x.c^2+x.b*x.c+x.r;
    x.f:=x.a*x.d^2+x.b*x.d+x.r;
    x.g:=x.f-x.e;
    fctn:='$$\a x^2+\b x+\r$$';
    ans:='{$\g\over \h$}';
    sol:='$${\f-\e\over \h}$$ = '+ans+'.';
  end;
  if k=2 then begin
    x.e:=x.c+x.a;
    x.f:=x.d+x.a;
    x.g:=x.e-x.f;
    x.k:=x.h*x.f*x.e;
    x.i:=x.f*x.e;
    fctn:='$${1\over x+\a}$$';
    ans:='{$\g\over \k$}';
    sol:='$${{1\over \f}-{1\over \e}\over\h}={\e-\f\over \h\cdot\i}$$ = '+ans+'.';
  end;
  if k = 3 then begin
    x.e:=x.a*x.c+x.b;
    x.f:=x.a*x.d+x.b;
    str((sqrt(x.f)-sqrt(x.e))/x.h:8:4,w);
    fctn:='$$\sqrt{\a x+\b}$$';
    ans:='{\sqrt{\f}-\sqrt{\e}\over \h}';
    sol:='$${\sqrt{\f}-\sqrt{\e}\over \h}\doteq '+w+'$$.';
  end;
  text1::='Find the average rate of change of f(x) = '+fctn+' over the '+
  	'interval [\c,\d].\nl';
  prompt::=#133'Avg. Rate of Change = '#134;
  help::='The average rate of change of f(x) over [a,b] is given by\nl'+
  	'$${f(b)-f(a)\over b-a}$$.';
  text3:=text1+nl+#142'Hint:'#142+nl+help;
  help::='\red{Average Rate of Change:}\nl '+help;
  answer::=ans;
  solution::=#140'Solution:'#140'\nl '+
  	'The average rate of change of f(x) = '+fctn+' over [\c,\d] is\nl '+
	'$${f(\d)-f(\c)\over \d-\c}$$ = '+sol;
  type:='R';
  key:=4042;
end;

procedure s4042;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4043;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,drctn:string;
  text:array[1..5] of string;
  mat:array[1..5] of integer;
begin
  x.a:=rand([-1,1]);
  x.b:=rand([-3,-2,-1,1,2,3]);
  x.c:=rand([-3,-2]);
  x.d:=rand([-3,-2,0,1,2,3]);
  x.e:=rand([1,2]);
  x.f:=x.d+rand([-1,1]);
  x.g:=x.a*(x.c-x.b);x.h:=x.d;
  x.i:=x.a*(x.e-x.b);x.j:=x.f;
  x.k:=-x.h;x.m:=-x.j;
  x.p:=-x.g;x.s:=x.g+x.a;
  x.r:=-x.i;x.t:=x.i+x.a;
  x.v:=-x.c;
  x.w:=-x.e;
  x.y:=x.v+x.b;
  x.z:=x.w+x.b;
  if x.b < 0 then x.u:=-x.b else x.u:=x.b;
  if x.b < 0 then drctn:='left' else drctn:='right';
  text2::=#127'700,700,1100,250;A,350,350,50;B,2;L,\g,\h,\i,\j;G,\h,D\g,\g;G,\j,D\i,\i;'#127;
  text3::=#127'700,700,1100,250;A,350,350,50;B,2;L,\g,\k,\i,\m;G,\k,D\g,\g;G,\m,D\i,\i;'#127;
  text4::=#127'700,700,1100,250;A,350,350,50;B,2;L,\p,\h,\r,\j;G,\h,D\p,\p;G,\j,D\r,\r;'#127;
  text5::=#127'700,700,1100,250;A,350,350,50;B,2;L,\s,\h,\t,\j;G,\h,D\s,\s;G,\j,D\t,\t;'#127;
  text6::=#127'700,700,1100,250;A,350,350,50;B,2;L,\s,\k,\t,\m;G,\k,D\s,\s;G,\m,D\t,\t;'#127;
  text1::=#133'Answer Y for yes N for no.'#134+#13#13+
  	'The graph of a function f(x) is shown below. The scale on '+
  	'each axis is 1. Which of the following is the graph of '+
	'$$f(\a x+\b)$$?\nl'#127'700,700,100,0;A,350,350,50;'+
	'L,\c,\d,\e,\f;G,\d,D\c,\c;G,\f,D\e,\e;'#127;
  help::='The graph of f(-x) is the graph of f(x) reflected across the '+
  	'y-axis.\nl '+
	'The graph of -f(x) is the graph of f(x) reflected across the '+
	'x-axis.\nl '+
	'The graph of $$f(x-h)$$ is the graph of f(x) shifted |h| units to  '+
	'the right if h > 0 and to the left if h < 0.\nl '+
	'The graph of $$f(x)+h$$ is the graph of f(x) shifted |h| units '+
	'upwards if h > 0 and downwards if h < 0.';
  if x.a>0 then buff2::=#142'Hint:'#142+nl+
  	'The graph of $$f(\a x+\b)$$ is a horizontal shift '+
  	'of the graph of f(x).';
  if x.a<0 then buff2::=#142'Hint:'#142+nl+
  	'The graph of $$f(\a x+\b)$$ is a reflection of the '+
  	'graph of f(x) followed by a horizontal shift.';	  
  ans:='1';
  answer::=ans;
  if x.a<0 then begin
    if x.b < 0 then drctn:='left' else drctn:='right';
    solution::=#12#140'Solution:'#140'\nl '+
    	 'To get $$f(\a x+\b)$$ starting with f(x), first replace x by -x '+
	 'and then replace x by $$x-\b$$: f(x) -> f(-x) -> $$f(-(x-\b))$$ '+
	 '= $$f(-x+\b)$$.\pause\nl '+
	 'Thus one first reflects the graph across the y-axis and then '+
	 'shifts the graph \u  units to the '+drctn+'.\pause\nl '+
	 #127'350,350,50,0;A,175,175,25;B,2;L,\c,\d,\e,\f;G,\d,D\c,\c;G,\f,D\e,\e;'+
	 	'C,-6,-6,f(x);'#127#10+
	 #127'350,350,650,0;A,175,175,25;B,2;L,\v,\d,\w,\f;G,\d,D\v,\v;G,\f,D\w,\w;'+
	 	'C,-6,-6,f(-x);'#127#10+
	 #127'350,350,1250,0;A,175,175,25;B,2;L,\y,\d,\z,\f;G,\d,D\y,\y;G,\f,D\z,\z;'+
	 	'C,-7,-6,$$f(-x+\b)$$;'#127;
  end;
  if x.a>0 then begin
    if x.b < 0 then drctn:='right' else drctn:='left';
    x.v:=x.c-x.b;
    x.w:=x.e-x.b;
    solution::=#12#140'Solution:'#140'\nl '+
    	'$$f(x+\b)$$ is a horizontal shift of f(x) \u  units to the '+
	drctn+'.\pause\nl '+
	#127'350,350,50,0;A,175,175,25;B,2;L,\c,\d,\e,\f;G,\d,D\c,\c;G,\f,D\e,\e;'+
	 	'C,-6,-6,f(x);'#127#10+
        #127'350,350,650,0;A,175,175,25;B,2;L,\v,\d,\w,\f;G,\d,D\v,\v;G,\f,D\w,\w;'+
	 	'C,-6,-6,$$f(x+\b)$$;#127';
  end;
  replace('1 units','1 unit',solution);
  type:='M';
  key:=4043;
end;

procedure s4043;
begin
  if sameconstants(answer,response) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    message:=#140'Incorrect '#140+#13+buff2;
  end;
end;

procedure p4044;
var
  x:paramtype;
  undef,notwff:boolean;
  a1,a2,dgm,drctn,fctn:string;
  text:array[1..5] of string;
  mat:array[1..5] of integer;
  j:integer;
begin
  x.a:=rand([-5,-4]);x.p:=-x.a;
  x.b:=rand([-4,-3,-2]);
  x.m:=rand([2,3,4]);
  x.n:=rand([-2,-3]);
  x.o:=rand([2,3]);
  x.c:=x.a+2;x.q:=-x.c;
  x.d:=x.b+2*x.m;
  x.r:=x.b-x.m*x.a;
  x.e:=x.c+3;x.u:=-x.e;
  x.f:=x.d+3*x.n;
  x.s:=x.d-x.n*x.c;
  x.g:=x.e+2;x.v:=-x.g;
  x.h:=x.f+2*x.o;
  x.t:=x.h-x.o*x.g;
  x.k:=rand([-1,1]);
  permute(mat,5);
  text[mat[1]]::=#127'600,600,1100,250;A,300,300,30;B,2;G,-\m x+\r,D\q,D\p;'+
  	'G,-\n x+\s,D\u,D\q;G,-\o x+\t,D\v,D\u;'#127;
  text[mat[2]]::=#127'600,600,1100,250;A,300,300,30;B,2;G,-\m x-\r,D\a,D\c;'+
  	'G,-\n x-\s,D\c,D\e;G,-\o x-\t,D\e,D\g;'#127;
  text[mat[3]]::=#127'600,600,1100,250;A,300,300,30;B,2;G,\m x-\r,D\q,D\p;'+
  	'G,\n x-\s,D\u,D\q;G,\o x-\t,D\v,D\u;'#127;
  text[mat[4]]::=#127'600,600,1100,250;A,300,300,30;B,2;G,-\m x-\r+\k,D\a,D\c;'+
  	'G,-\n x-\s+\k,D\c,D\e;G,-\o x-\t+\k,D\e,D\g;'#127;
  text[mat[5]]::=#127'600,600,1100,250;A,300,300,30;B,2;G,-\m x+\r+\k,D\q,D\p;'+
  	'G,-\n x+\s+\k,D\u,D\q;G,-\o x+\t+\k,D\v,D\u;'#127;
  text2:=text[1];
  text3:=text[2];
  text4:=text[3];
  text5:=text[4];
  text6:=text[5];
  case rand([1,2,3]) of 
    1:begin
      fctn:='$$f(-x)$$';
      answer:=st(mat[1]);
      solution::=#12#140'Solution:'#140'\nl '+
      	'The graph of f(-x) is the graph of f(x) reflected across the '+
	'y-axis.\pause\nl '+
	#127'400,400,100,20;A,200,200,20;B,2;G,\m x+\r,D\a,D\c;'+
  	'G,\n x+\s,D\c,D\e;G,\o x+\t,D\e,D\g;C,-9,-9,f(x);'#127'\pause '+
	#127'400,400,700,20;A,200,200,20;B,2;G,-\m x+\r,D\q,D\p;'+
  	'G,-\n x+\s,D\u,D\q;G,-\o x+\t,D\v,D\u;C,-9,-9,f(-x);'#127;
      buff3::=#142'Hint:'#142+nl+
        'The graph of f(-x) is the graph of f(x) reflected across the '+
	'y-axis.';
      end;
    2:begin
      fctn:='$$-f(-x)$$';
      answer:=st(mat[3]);
      solution::=#12#140'Solution:'#140'\nl '+
      	'The graph of -f(-x) is the graph of f(x) reflected across the '+
	'y-axis and then reflected across the x-axis.\pause\nl '+
	#127'400,400,100,20;A,200,200,20;B,2;G,\m x+\r,D\a,D\c;'+
  	'G,\n x+\s,D\c,D\e;G,\o x+\t,D\e,D\g;C,-9,-9,f(x);'#127'\pause '+
	#127'400,400,700,20;A,200,200,20;B,2;G,-\m x+\r,D\q,D\p;'+
  	'G,-\n x+\s,D\u,D\q;G,-\o x+\t,D\v,D\u;C,-9,-9,f(-x);'#127'\pause '+
	#127'400,400,1300,20;A,200,200,20;B,2;G,\m x-\r,D\q,D\p;'+
  	'G,\n x-\s,D\u,D\q;G,\o x-\t,D\v,D\u;C,-9,-9,-f(-x);'#127;
      buff3::=#142'Hint:'#142+nl+
        'The graph of -f(-x) is the graph of f(x) reflected across the '+
	'y-axis and then reflected across the x-axis.';
      end;
    3:begin
      fctn:='$$-f(x)$$';
      answer:=st(mat[2]);
      solution::=#12#140'Solution:'#140'\nl '+
      	'The graph of -f(x) is the graph of f(x) reflected across the '+
	'x-axis. \pause\nl '+
	#127'400,400,100,20;A,200,200,20;B,2;G,\m x+\r,D\a,D\c;'+
  	'G,\n x+\s,D\c,D\e;G,\o x+\t,D\e,D\g;C,-9,-9,f(x);'#127'\pause '+
	#127'400,400,700,20;A,200,200,20;B,2;G,-\m x-\r,D\a,D\c;'+
  	'G,-\n x-\s,D\c,D\e;G,-\o x-\t,D\e,D\g;C,-9,-9,-f(x);'#127;
      buff3::=#142'Hint:'#142+nl+
        'The graph of -f(x) is the graph of f(x) reflected across the '+
	'x-axis.';
      end;
    end;{case}
  text1::=#133'Answer Y for select N for next.'#134+#13#13+
  	'The graph of a function f(x) is shown below. The scale on '+
  	'each axis is 1. Which of the following is the graph of '+
	fctn+'\nl'#127'600,600,100,0;A,300,300,30;G,\m x+\r,D\a,D\c;'+
  	'G,\n x+\s,D\c,D\e;G,\o x+\t,D\e,D\g;'#127;
  help::='The graph of f(-x) is the graph of f(x) reflected across the '+
  	'y-axis.\nl '+
	'The graph of -f(x) is the graph of f(x) reflected across the '+
	'x-axis.\nl '+
	'The graph of -f(-x) is the graph of f(x) reflected across the '+
	'y-axis and then across the x-axis or vice-versa.\nl '+
	'The graph of $$f(x-h)$$ is the graph of f(x) shifted |h| units to  '+
	'the right if h > 0 and to the left if h < 0.\nl '+
	'The graph of $$f(x)+h$$ is the graph of f(x) shifted |h| units '+
	'upwards if h > 0 and downwards if h < 0.';
  type:='M';
  key:=4044;
end;

procedure s4044;
begin
  if sameconstants(answer,response) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    message:=#140'Incorrect '#140+#13+buff3;
  end;
end;

procedure p4045;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2,w,z:string;
begin
  x.a:=rand([2,4,8,10,12]);
  x.b:=rand([15,18,21]);
  x.c:=rand([-5,-7,3,4,8,10]);
  x.d:=x.c+rand([-3,-2,2,3]);
  x.e:=rand([-2,-1,-4,4,3,6,7]);
  x.h:=x.c*x.e+x.d;
  x.i:=x.a*x.e^2+x.b;
  x.j:=x.a*x.h^2+x.b;
  str(x.c*sqrt(x.i)+x.d:8:4,w);
  str(sqrt(x.a*x.h^2+x.b):8:4,z);
  header::='\red{Answer both parts before grading.}';
  text:='Let $$f(x)=\sqrt{\a x^2+\b}$$ and let $$g(x)=\c x+\d$$';
  part1:='\red{a:}  Find $$(f\circ g)(\e). (50%)$$';
  part2:='\red{b:}  Find $$(g\circ f)(\e). (50%)$$';
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13;
  prompt::=#133'a: $$(f\circ g)(\e)$$ = '#134#13+
    	   #133'b: $$(g\circ f)(\e)$$ = '#134;
  help:='(f\circ g)(x) = f(g(x)) providing x is in the domain of g(x) '+
  	'and g(x) is in the domain of f(x).';
  text3::=text+nl+part1+nl+part2+nl+nl+#142'Hint:'#142+nl+help;
  help::='\red{Compositions:}\nl '+help;
  ans::=#134'\sqrt{\j}'#133+
       #134'$$\c\sqrt{\i}+\d$$';
  answer::=ans;
  separate(ans,a1,a2);
  solution::=#13#140'Solution:'#140'\nl '+
  	'$$(f\circ g)(\e)=f(g(\e))=f(\h)='+a1+'$$ \doteq  '+z+'.\pause\nl '+
	'$$(g\circ f)(\e)=g(f(\e))=g(\sqrt{\i})='+a2+'$$ \doteq  '+w+'.';
  type:='R';
  key:=4045;
end;	   

procedure s4045;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4046;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2,w,z:string;
begin
  x.a:=rand([2,4,8,10,12]);
  x.b:=rand([15,18,21]);
  x.c:=rand([-5,-7,3,4,8,10]);
  x.d:=x.c+rand([-3,-2,2,3]);
  x.e:=x.a*x.c;
  x.f:=x.a*x.d+x.b;
  x.g:=x.a^2;
  x.h:=2*x.a*x.b;
  x.i:=x.b^2;
  x.k:=x.c*x.g;
  x.l:=x.c*x.h;
  x.m:=x.c*x.b^2+x.d;
  header::='\red{Answer both parts before grading.}';
  text:='Let $$f(x)=\a x+\b$$ and let $$g(x)=\c x^2+\d$$';
  part1:='\red{a}: Find $$(f\circ g)(x). (50%)$$';
  part2:='\red{b}: Find $$(g\circ f)(x). (50%)$$';
  text1::=header+#13+text+#13+part1+#13+part2+#13;
  prompt::=#133'a: $$(f\circ g)(x)$$ = '#134#13+
    	   #133'b: $$(g\circ f)(x)$$ = '#134;
  help:='(f\circ g)(x) = f(g(x)) providing x is in the domain of g(x) '+
  	'and g(x) is in the domain of f(x).';
  text3::=text+nl+part1+nl+part2+nl+nl+#142'Hint:'#142+nl+help;
  help::='\red{Compositions:}\nl '+help;
  ans:=#134'$$\e x^2+\f$$'#133+
       #134'$$\k x^2+\l x+\m$$';
  answer::=ans;
  separate(ans,a1,a2);
  solution::=nl+#140'Solution:'#140'\nl '+
  	'$$(f\circ g)(x)=f(g(x))$$\pause\nl '+
	'= $$f(\c x^2+\d)$$\pause\nl '+
	'= $$\a(\c x^2+\d)+\b$$\pause\nl '+
	'= '+a1+'.\pause\nl\nl '+
	'$$(g\circ f)(x)=g(f(x))$$\pause\nl '+
	'= $$\c(\a x+\b)^2+\d$$\pause\nl '+
	'= $$\c(\g x^2+\h x+\i)+\d$$\pause\nl '+
	'= '+a2+'.';
  type:='R';
  key:=4046;
end;	   

procedure s4046;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameexpres(a1,r1);
  check2:=sameexpres(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4047;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2:string;
begin
  x.b:=rand([1,2,4,6,7,9]);
  x.a:=x.b+rand([-3,-5,-8]);
  x.c:=x.b+rand([1,2,3,6]);
  x.d:=-(x.a+x.c);
  x.e:=x.a*x.c;
  header::='\red{Answer both parts before grading.}';
  text::='Let f(x) = $$\sqrt{x-\b}$$ and g(x) = $$x^2+\d x+\e$$.';
  part1::='\red{a:}  Give the formula for ({f\over g})(x). (50%)';
  part2::='\red{b:}  State the domain of ({f\over g})(x) in interval form. (50%)';
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13;
  prompt::=#133'a: ({f\over g})(x) = '#134#13+
    	   #133'b: Domain:'#134;
  help:='$$(f\pm g)(x) = f(x)\pm g(x)$$\nl '+
	 '$$(f\cdot g)(x)=f(x)\cdot g(x)$$\nl '+
	 '$$({f\over g})(x)={f(x)\over g(x)}$$\nl '+
	 'Expressions inside square root signs must be \ge  0.\nl '+
  	 'Division by zero is not allowed.';
  text3::=text+nl+part1+nl+part2+nl+nl+#142'Hint:'#142+nl+help;
  help::=help;
  ans:=#134'$${\sqrt{x-\b}\over x^2+\d x+\e}$$'#133+
       #134'[\b,\c),(\c,\inf)';
  answer::=ans;
  separate(ans,a1,a2);
  solution::=nl+#140'Solution:'#140'\nl '+
  	'$$({f\over g})(x)={f(x)\over g(x)}$$ = '+a1+'\pause\nl '+
	'Note that $$({f\over g})(x)={\sqrt{x-\b}\over (x-\a)(x-\c)}$$\pause\nl '+
	'Because of the square root in the numerator we must have '+
	'x \ge  \b.\pause  In order to avoid division by 0 we must have '+
	'x \ne  \a  and x \ne  \c.\pause\nl '+
	'Thus we must have x \ge  \b  and \ne  \c.\pause\nl In interval notation this '+
	'is '+a2+'.';
  type:='R';
  key:=4047;
end;	   

procedure s4047;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameexpres(a1,r1);
  check2:=sameintervals(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4048;  {old p1036}
var
  t,n,m:integer;
  x,y,z,w:real;
  sx,sy,sz,sw,sa,sb,sc,sd:string;
begin
  t := randint(1,3);
  case t of
  1:begin
      n := randint(3,9);
      x := randint(30,75)*1000.0;
      y := x + randint(3,10)*1000.0;
      str(x:3:2,sx);
      str(y:3:2,sy);
      str((y-x)/n:3:2,sz);
      text1 := st(n)+' years ago a house was worth $'+sx+'. '+
        'Now it is worth $'+sy+'.  Assume a linear '+
        'relationship between time and value and find a '+
        'formula for the value, V(t), at time t '+
        '(t = 0 refers to now).'+nl;
      answer := sz+'t + '+sy;
      prompt::=#133'V(t) = '#134;
      help::='The slope m of the line passing through (a,b) and (c,d) is given by '+
	'$${d-b\over c-a}$$\nl '+
	'Point-Slope Equation of Line through (a,b) and (c,d):\nl '+
	'$$y-a=m(x-b)$$\nl '+
	'Slope-Intercept Equation of Line through (0,b):\nl '+
	'$$y=mx+b$$';
      text3 := text1+nl+#142'Hint:'#142+nl+
      	'Find the slope of the line, then use the point-slope form.';
      solution ::=#127+'500,500,1200,10;L,0,100,500,100;'+
        'L,250,0,250,500;L,0,100,500,500;L,100,110,100,90;'+
        'L,240,180,260,180;L,240,300,260,300;B,2;C,80,50,'+st(-n)+';'+
        'B,2;C,270,170,'+sx+';C,270,290,'+sy+';G,180,100,D100;'#127+
	#140'\nl Solution:'#140'\nl '+
        'The house increased in value by '+st(round(y-x))+
        ' in '+st(n)+' years.'+#10+' So the slope of the line is {'+st(round(y-x))+'\over '+st(n)+'} '+
        '= '+sz+#10+nl+'Using the point-slope form, an equation for the line is'+
        #10+nl+'V - '+sy+' = '+sz+'(t - 0)'+#10+nl+'=> V(t) = '+answer+#13;
    end;
  2:begin
      m := randint(5,25);
      n := randint(1000,2000);
      text1 := 'The cost of labor and materials to make one widget '+
        'is $'+st(m)+' and the fixed costs for one month are '+
        '$'+st(n)+'.  Find a formula for the total monthly '+
        'cost C(x) for manufacturing x widgets.'+nl;
      answer := st(m)+'x + '+st(n);
      prompt:=#133'C(x)= '#134;
      help::='The slope m of the line passing through (a,b) and (c,d) is given by '+
	'$${d-b\over c-a}$$\nl '+
	'Point-Slope Equation of Line through (a,b) and (c,d):\nl '+
	'$$y-a=m(x-b)$$\nl '+
	'Slope-Intercept Equation of Line through (0,b):\nl '+
	'$$y=mx+b$$';
      text3 := text1+nl+#142'Hint:'#142+nl+
      	'Total cost is variable cost (cost per unit times the number '+
        'of units) plus fixed cost.';
      solution ::= #13'\nl\red{Solution:}\nl '+
        'Variable cost is '+st(m)+'x while the fixed cost is '+st(n)+'.'+#10+nl+
        'So total cost C(x) is '+
        answer+'.';
    end;
  3:begin
      x := randint(75,200)*0.01;
      y := randint(30,90)*10.0;
      z := x + randint(10,20)*0.01;
      w := y - randint(20,50);
      str(x:3:2,sx); str(y:3:0,sy);
      str(z:3:2,sz); str(w:3:0,sw);
      str(z-x:3:2,sc); str(y-w:1:0,sd);
      str( (w-y)/(z-x):3:2,sa);
      str( y-(w-y)/(z-x)*x:3:2,sb);
      text1 := 'At $'+sx+' per gallon you can sell '+sy+' gallons '+
        'of milk per week, and at $'+sz+', '+sw+' gallons will sell. '+
        'Assume a linear relationship between price and '+
        'demand and give a formula for the number of gallons G(x) '+
        'that will sell at a price of $x per gallon.'+nl;
      prompt:=#133'G(x) = '#134;
      answer := sa+'x + '+sb;
      help:='The slope m of the line passing through (a,b) and (c,d) is given by '+
	'$${d-b\over c-a}$$\nl '+
	'Point-Slope Equation of Line through (a,b) and (c,d):\nl '+
	'$$y-a=m(x-b)$$\nl '+
	'Slope-Intercept Equation of Line through (0,b):\nl '+
	'$$y=mx+b$$';
      text3 := text1+nl+#142'Hint:'#142+nl+
      	'Find the slope of the line, then use the point-slope form.';
      solution::=#13#140'Solution:'#140'\nl '+#127+'500,500,1200,10;L,0,100,500,100;'+
        'L,100,0,100,500;L,0,400,500,100;'+
        'L,90,160,110,160;L,200,90,200,110;L,400,90,400,110;'+
        'L,90,280,110,280;B,2;C,0,270,'+sy+';C,180,50,'+sx+';C,380,50,'+sz+';'+
	'C,0,150,'+sw+';C,450,80,x;C,110,450,G(x);G,280,200,D200;G,160,400,D400;'#127+
        'Increasing the price by '+sc+' results in a drop '+
        'of '+sd+' gallons in sales.'+#10+' This means that the slope '+
        'is '+sa+'.'+#10+nl+'The point-slope form gives the equation'+nl+
        'G(x) - '+sy+' = '+sa+'(x - '+sx+')'+#10+nl+'or G(x) = '+answer;
    end;
  end;
  key := 4048;
  type := 'R';
end;

procedure s4048;
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4049;  {old 214}
var
  a,b,i,j,k:integer;
  monthk,monthi:string;
  tx:integer;
  pop,home,func:array[1..3] of string;
  popdisp:string;
begin
  a:=randint(3,15);
  repeat b:=randint(3,15) until b <> a;
  i:=randint(1,12);
  j:=randint(3,10);
  k:= (i+j) mod 12;
  if k = 0 then k := 12;
  case k of
  1:monthk := 'January'; 2:monthk := 'February'; 3:monthk := 'March';
  4:monthk := 'April'; 5:monthk := 'May'; 6:monthk := 'June';
  7:monthk := 'July'; 8:monthk := 'August'; 9:monthk := 'September';
  10:monthk := 'October'; 11:monthk := 'November'; 12:monthk := 'December';
  end;
  case i of
  1:monthi := 'January'; 2:monthi := 'February'; 3:monthi := 'March';
  4:monthi := 'April'; 5:monthi := 'May'; 6:monthi := 'June';
  7:monthi := 'July'; 8:monthi := 'August'; 9:monthi := 'September';
  10:monthi := 'October'; 11:monthi := 'November'; 12:monthi := 'December';
  end;
  tx:=randint(1,3);
  pop[1]:='ants';
  pop[2]:='fish';
  pop[3]:='bats';
  home[1]:='an anthill';
  home[2]:='a lake';
  home[3]:='a cave';
  func[1]:='A';
  func[2]:='F';
  func[3]:='B';
  popdisp:=pop[tx];
  text1 :='If the population of '+popdisp+' in '+home[tx]+' is '+
                 func[tx]+'(x) = '+st(a*100)+'x + '+ st(b*100)+', where '+
                 func[tx]+'(x) represents the number of '+popdisp+
                 ' present at the end of month x, find'
                 +' the number N of '+popdisp+' present at the end of '+
                 monthk+' if x=0 represents the end of the '+
                 'the previous '+monthi+'.'+nl;
  prompt::=#133'N = '#134;
  text3:=text1+nl+#142'Hint:'#142+nl+
    'Determine how many months have lapsed since the end of the previous '+
    monthi+'.';
  help::='Determine how many months have lapsed since the end of the previous '+
    monthi+'.';
  answer := st( a*100 * j + b*100 );
  solution::='\nl\red{Solution:}\nl '+
    'Between the end of the previous '+monthi+' and the end of '+
    monthk+', '+st(j)+' months have lapsed.'+#10+' Substituting x = '+
    st(j)+' in the population formula '+
    '     '+func[tx]+'(x) = '+st(a*100)+'x + '+ st(b*100)+nl+
    'we find N = '+func[tx]+'('+st(j)+') = ('+st(a*100)+')('+st(j)+')'+
    ' + '+st(b*100)+' = '+answer+' '+popdisp+' are present at the end of '+
    monthi+'.';
  key := 4049;
  type := 'R';
end;

procedure s4049;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;


procedure p4050;  {old 1333}
var
v:valuetype;
a,b,j,k:integer;
header:string;
eqt,gph,ans,sol:array[1..8] of string;
mat:array[1..8] of integer;
begin
  v.a:=rand([-3,-2,2,3]);
  v.b:=rand([-2,-1,1,2]);
  for k:=1 to 8 do mat[k]:=k;
  permute(mat,8);
  header:='\red{Answer Y or N for each question.}'#13#13;
  text1::=header+'Determine whether each of the following graphs is the graph of an '+
    'even function of x?.';
  eqt[1]:=#127'500,500,1200,100;A,250,250,50;G,'+makeformula('ax^2+b',['a','b'],v)+',-5,5;'#127;ans[1]:='Y';
  eqt[2]:=#127'500,500,1200,100;A,250,250,50;G,'+makeformula('ax^3+b',['a','b'],v)+',-5,5;'#127;ans[2]:='N';
  eqt[3]:=#127'500,500,1200,100;A,250,250,50;G,'+makeformula('|x|+b',['b'],v)+',-5,5;'#127;ans[3]:='Y';
  eqt[4]:=#127'500,500,1200,100;A,250,250,50;G,'+makeformula('{x}',[],v)+',0,5;'+
    'G,'+makeformula('-{x}',[],v)+',0,5;'#127;ans[4]:='N';
  eqt[5]:=#127'500,500,1200,100;A,250,250,50;G,'+makeformula('|x|+1',[],v)+',-5,5;'+
    'G,'+makeformula('-|x|-1',[],v)+',-5,5;'#127;ans[5]:='N';
  eqt[6]:=#127'500,500,1200,100;A,250,250,50;G,'+makeformula('arctan(x)',[],v)+',-5,5;#127';ans[6]:='N';
  eqt[7]:=#127'500,500,1200,100;A,250,250,50;G,'+makeformula('3e^(-x^2/16)',[],v)+',-5,5;'#127;ans[7]:='Y';
  eqt[8]:=#127'500,500,1200,100;A,250,250,50;G,'+makeformula('{9-x^2}',[],v)+',-3,3;'+
    'G,'+makeformula('-{9-x^2}',[],v)+',-3,3;'#127;ans[8]:='N';
  text2:=eqt[mat[1]];
  text3:=eqt[mat[2]];
  text4:=eqt[mat[3]];
  text5:=eqt[mat[4]];
  text6:=eqt[mat[5]];
  buff3::='A function is even if and only if its graph is symmetric with '+
	'respect to the y-axis.';
  help::='\red{Even Functions:}\nl '+
	'A function is even if f(-x) = f(x) for all x in the domain of f(x).\nl '+
	'A function is even when its graph is symmetric with respect to the '+
	'y-axis.\nl '+#10#12+
	'\red{Vertical Line Test for Functions:}\nl '+
	'For a curve in the plane to be a function, it must pass the vertical '+
	'line test:\nl no vertical line can intersect the curve more than once.';
  gph[1]:=makeformula('ax^2+b',['a','b'],v)+',-5,5;';
  sol[1]:=#127'300,300,900,0;A,150,150,30;G,'+gph[1]+';'#127+
	  'This function has symmetry '+nl+
	  'about the y-axis and '+nl+
	  'therefore is even.\nl\nl\nl\nl\nl\nl\nl';
  gph[2]:=makeformula('ax^3+b',['a','b'],v)+',-5,5;';
  sol[2]:=#127'300,300,900,0;A,150,150,30;G,'+gph[2]+';'#127+
	  'This function is not symmetric '+nl+
	  'about the y-axis and therefore '+nl+
	  'is not even.\nl\nl\nl\nl\nl\nl\nl';
  gph[3]:=makeformula('|x|+b',['b'],v)+',-5,5;';
  sol[3]:=#127'300,300,900,0;A,150,150,30;G,'+gph[3]+';'#127+
	  'This function has symmetry '+nl+
	  'about the y-axis and '+nl+
	  'therefore is even.\nl\nl\nl\nl\nl\nl\nl';
  gph[4]:=makeformula('{x}',[],v)+',0,5;G,'+makeformula('-{x}',[],v)+',0,5;';
  sol[4]:=#127'300,300,900,0;A,150,150,30;G,'+gph[4]+';'#127+
	  'This graph is not a '+nl+
	  'function of x.\nl\nl\nl\nl\nl\nl\nl';
  gph[5]:=makeformula('|x|+1',[],v)+',-5,5;G,'+makeformula('-|x|-1',[],v)+',-5,5;';
  sol[5]:=#127'300,300,900,0;A,150,150,30;G,'+gph[5]+';'#127+
	  'This graph is not a '+nl+
	  'function of x.\nl\nl\nl\nl\nl\nl\nl';
  gph[6]:=makeformula('arctan(x)',[],v)+',-5,5;';
  sol[6]:=#127'300,300,900,0;A,150,150,30;G,'+gph[6]+';'#127+
	  'This function is not symmetric '+nl+
	  'about the y-axis and therefore '+nl+
	  'is not even.\nl\nl\nl\nl\nl\nl\nl';
  gph[7]:=makeformula('3e^(-x^2/16)',[],v)+',-5,5;';
  sol[7]:=#127'300,300,900,0;A,150,150,30;G,'+gph[7]+';'#127+
	  'This function has symmetry '+nl+
	  'about the y-axis and '+nl+
	  'therefore is even.\nl\nl\nl\nl\nl\nl\nl';
  gph[8]:=makeformula('{9-x^2}',[],v)+',-3,3;G,'+makeformula('-{9-x^2}',[],v)+',-3,3;';
  sol[8]:=#127'300,300,900,0;A,150,150,30;G,'+gph[8]+';'#127+
	  'This graph is not a '+nl+
	  'function of x.\nl\nl\nl\nl\nl\nl\nl';
  answer:=ans[mat[1]]+ans[mat[2]]+ans[mat[3]]+ans[mat[4]]+ans[mat[5]];
  replace('900,100','900,300',sol[mat[1]]);
  solution::='\red{Solution:}'+
	#12'\red{Choice 1}'+nl+'You got this one \green{right}.'+nl+sol[mat[1]];
  solution2::=#10#12'\red{Choice 2}'+nl+'You got this one \green{right}.'+nl+sol[mat[2]];
  solution3::=#10#12'\red{Choice 3}'+nl+'You got this one \green{right}.'+nl+sol[mat[3]];
  solution4::=#10#12'\red{Choice 4}'+nl+'You got this one \green{right}.'+nl+sol[mat[4]];
  solution5::=#10#12'\red{Choice 5}'+nl+'You got this one \green{right}.'+nl+sol[mat[5]];
  type:='S';
  key:=4050;
end;

procedure s4050;
var
  j,n:integer;
  res,w,z:string;
begin
  z:='';
  n := 10;
  for j:=1 to 5 do begin
    if answer[j-1] <> response[j-1] then begin
      z:=z+st(j)+',';
      n := n - 2;
    end;
  end;
  result := chr(48+n);
  if response='     ' then message:=#140'Incorrect'#140#13#142'Hint:'#142+buff3
  else begin
    if answer=response then begin
      message:=#141'Correct.'#141;
    end else begin
      w := '';
      if pos('1',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution) else
	 replace(#140'wrong'#140,#141'right'#141,solution);
      if pos('2',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution2) else
	 replace(#140'wrong'#140,#141'right'#141,solution2);
      if pos('3',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution3) else
	 replace(#140'wrong'#140,#141'right'#141,solution3);
      if pos('4',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution4) else
	 replace(#140'wrong'#140,#141'right'#141,solution4);
      if pos('5',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution5) else
	 replace(#140'wrong'#140,#141'right'#141,solution5);
      message:=response+' is '#140'incorrect'#140'.'+#13+
      #142'Message:'#142#13+buff3;
    end;
  end;
end;

procedure p4051;   {old 1334}
var
  v:valuetype;
  a,b,j,k:integer;
  header:string;
  eqt,gph,ans,sol:array[1..8] of string;
  mat:array[1..8] of integer;
begin
  v.a:=rand([-3,-2,2,3]);
  v.b:=rand([-2,-1,1,2]);
  for k:=1 to 8 do mat[k]:=k;
  permute(mat,8);
  header::='\red{Answer Y or N for each choice.}';
  text1:=header+#13+#13+'Which of the following graphs are graphs of odd functions?.';
  eqt[1]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('ax^2+b',['a','b'],v)+',-5,5;'#127;ans[1]:='N';
  eqt[2]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('ax^3',['a','b'],v)+',-5,5;'#127;ans[2]:='Y';
  eqt[3]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('|x|+b',['b'],v)+',-5,5;'#127;ans[3]:='N';
  eqt[4]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('{x}',[],v)+',0,5;'+
    'G,'+makeformula('-{x}',[],v)+',0,5;'#127;ans[4]:='N';
  eqt[5]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('[4x]/[1+x^2]',[],v)+',-5,5;'#127;ans[5]:='Y';
  eqt[6]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('2arctan(x)',[],v)+',-5,5;'#127;ans[6]:='Y';
  eqt[7]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('[1]/[x]',[],v)+',-5,5;'#127;ans[7]:='Y';
  eqt[8]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('{9-x^2}',[],v)+',-3,3;'+
    'G,'+makeformula('-{9-x^2}',[],v)+',-3,3;'#127;ans[8]:='N';
  text2:=eqt[mat[1]];
  text3:=eqt[mat[2]];
  text4:=eqt[mat[3]];
  text5:=eqt[mat[4]];
  text6:=eqt[mat[5]];
  buff3::='A function is odd if and only if its graph is symmetric with '+
	  'respect to the origin.';
  help::='A function is even if and only if f(-x) = f(x) or its graph is '+
	  'symmetric with respect to the y-axis.\nl '+
	  'A function is odd if and only if f(-x) = -f(x) or its graph is '+
	  'symmetric with respect to the x-axis.\nl '+
	  'A curve in the x-y plane is the graph of a function of x if and '+
	  'only every vertical line intersects the graph at most once.';
  gph[1]:=makeformula('ax^2+b',['a','b'],v)+',-5,5;';
  sol[1]:=#127'300,300,1200,10;A,150,150,30;B,2;G,'+gph[1]+';'#127+
	  'This function has symmetry about the y-axis but not about '+
	  'the origin. Therefore it is not an odd function.\nl\nl\nl\nl\nl\nl\nl';
  gph[2]:=makeformula('ax^3',['a'],v)+',-5,5;';
  sol[2]:=#127'300,300,1200,10;A,150,150,30;B,2;G,'+gph[2]+';'#127+
	  'This function does  have symmetry about the origin. '+
	  'Therefore it is an odd function.\nl\nl\nl\nl\nl\nl\nl';
  gph[3]:=makeformula('|x|+b',['b'],v)+',-5,5;';
  sol[3]:=#127'300,300,1200,10;A,150,150,30;B,2;G,'+gph[3]+';'#127+
	  'This function has symmetry about the y-axis but not about '+
	  'the origin. Therefore it is not an odd function.\nl\nl\nl\nl\nl\nl\nl';
  gph[4]:=makeformula('{x}',[],v)+',0,5;G,'+makeformula('-{x}',[],v)+',0,5;';
  sol[4]:=#127'300,300,1200,10;A,150,150,30;B,2;G,'+gph[4]+';'#127+
	  'This graph is not a function of x.\nl\nl\nl\nl\nl\nl\nl';
  gph[5]:=makeformula('[4x]/[1+x^2]',[],v)+',-5,5;';
  sol[5]:=#127'300,300,1200,10;A,150,150,30;B,2;G,'+gph[5]+';'#127+
	  'This function does  have symmetry about the origin. '+
	  'Therefore it is an odd function.\nl\nl\nl\nl\nl\nl\nl';
  gph[6]:=makeformula('2arctan(x)',[],v)+',-5,5;';
  sol[6]:=#127'300,300,1200,10;A,150,150,30;B,2;G,'+gph[6]+';'#127+
	  'This function does  have symmetry about the origin. '+
	  'Therefore it is an odd function.\nl\nl\nl\nl\nl\nl\nl';
  gph[7]:=makeformula('[1]/[x]',[],v)+',-5,5;';
  sol[7]:=#127'300,300,1200,10;A,150,150,30;B,2;G,'+gph[7]+';'#127+
	  'This function does have symmetry about the origin. '+
	  'Therefore it is an odd function.\nl\nl\nl\nl\nl\nl\nl';
  gph[8]:=makeformula('{9-x^2}',[],v)+',-3,3;B,2;G,'+makeformula('-{9-x^2}',[],v)+',-3,3;';
  sol[8]:=#127'300,300,1200,10;A,150,150,30;B,2;G,'+gph[8]+';'#127+
	  'This graph is not a function of x.\nl\nl\nl\nl\nl\nl\nl';
  answer:=ans[mat[1]]+ans[mat[2]]+ans[mat[3]]+ans[mat[4]]+ans[mat[5]];
  solution::='\nl\red{Solution:}'+
	  #12'\red{Choice 1}'+nl+'You got this one \green{right}.'+nl+sol[mat[1]];
  solution2::=#10#12'\red{Choice 2}'+nl+'You got this one \green{right}.'+nl+sol[mat[2]];
  solution3::=#10#12'\red{Choice 3}'+nl+'You got this one \green{right}.'+nl+sol[mat[3]];
  solution4::=#10#12'\red{Choice 4}'+nl+'You got this one \green{right}.'+nl+sol[mat[4]];
  solution5::=#10#12'\red{Choice 5}'+nl+'You got this one \green{right}.'+nl+sol[mat[5]];
  response:='';
  type:='S';
  key:=4051;
end;

procedure s4051;
var
  j,n:integer;
  res,w,z:string;
begin
  z:='';
  n := 10;
  for j:=1 to 5 do begin
    if answer[j-1] <> response[j-1] then begin
      z:=z+st(j)+',';
      n := n - 2;
    end;
  end;
  result := chr(48+n);
  if answer=response then begin
	message:=#141'Correct.'#141;
    end else begin
      w := '';
      if pos('1',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution) else
	 replace(#140'wrong'#140,#141'right'#141,solution);
      if pos('2',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution2) else
	 replace(#140'wrong'#140,#141'right'#141,solution2);
      if pos('3',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution3) else
	 replace(#140'wrong'#140,#141'right'#141,solution3);
      if pos('4',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution4) else
	 replace(#140'wrong'#140,#141'right'#141,solution4);
      if pos('5',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution5) else
	 replace(#140'wrong'#140,#141'right'#141,solution5);
      message:=response+' is '#140'incorrect'#140'.'+#13+
      #142'Message:'#142#13+buff3;
  end;
end;    

procedure p4052;
var
  v:valuetype;
  a,b,j,k:integer;
  poss,negg,header:string;
  eqt,ans,sol:array[1..10] of string;
  mat:array[1..10] of integer;
begin
  v.a:=rand([-3,-2,2,3]);
  v.b:=rand([-2,-1,1,2]);
  for k:=1 to 10 do mat[k]:=k;
  permute(mat,10);
  header::='\red{Answer Y or N for each choice.}';
  text1:=header+#13+#13+'Which of the following curves are graphs of '+
	  'functions of x?.';
  eqt[1]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('ax^2+b',['a','b'],v)+',-5,5;'#127;ans[1]:='Y';
  eqt[2]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('ax^3',['a'],v)+',-5,5;'#127;ans[2]:='Y';
  eqt[3]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('-|x|+4',[],v)+',-4,4;'+
    'G,'+makeformula('|x|-4',[],v)+',-4,4;'#127;ans[3]:='N';
  eqt[4]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('{x}',[],v)+',0,5;'+
    'G,'+makeformula('-{x}',[],v)+',0,5;'#127;ans[4]:='N';
  eqt[5]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('(x^2)/8',[],v)+',0,5;'+
    'G,'+makeformula('(-x^2)/8',[],v)+',0,5;#127';ans[5]:='N';
  eqt[6]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('{x+2}',[],v)+',D-2,5;'+
    'G,'+makeformula('-{-x+2}',[],v)+',-5,O2;#127';ans[6]:='N';
  eqt[7]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('[6]/[x]',[],v)+',D-4,D-2;'+
    'G,'+makeformula('[6]/[x]',[],v)+',D2,D4;'#127;ans[7]:='Y';
  eqt[8]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('{9-x^2}',[],v)+',-3,3;'+
    'G,'+makeformula('-{9-x^2}',[],v)+',-3,3;'#127;ans[8]:='N';
  eqt[9]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('{9-x^2}',[],v)+',O0,D3;'+
    'G,'+makeformula('-{9-x^2}',[],v)+',D-3,D0;'#127;ans[9]:='Y';
  eqt[10]:=#127'500,500,1200,10;A,250,250,50;B,2;G,'+makeformula('x^2-2',[],v)+',-5,O0;'+
    'G,'+makeformula('-x^2+2',[],v)+',D0,5;'#127;ans[10]:='Y';
  text2:=eqt[mat[1]];
  text3:=eqt[mat[2]];
  text4:=eqt[mat[3]];
  text5:=eqt[mat[4]];
  text6:=eqt[mat[5]];
  buff1::=#142'Hint:'#142#13+
	'A curve in the x-y plane is the graph of a function of x if the '+
	  'curve assigns at most one y-value to any given x-value.';
  help::='A curve in the x-y plane is the graph of a function of x if the '+
	  'curve assigns at most one y-value to any given x-value.\nl\nl '+
	  'In particular every vertical line must intersect the curve at '+
	  'most once.';
  poss:='This curve is a function'+nl+
       'since every vertical line'+nl+
       'intersects the curve at '+nl+
       'most once.';
  negg:='This curve is not a function'+nl+
       'of x. For example, the vertical '+nl+
       'line x = 1 intersects the curve '+nl+
       'twice.';
  sol[1]:=eqt[1]+poss+'\nl\nl\nl\nl\nl\nl\nl';
  sol[2]:=+eqt[2]+poss+'\nl\nl\nl\nl\nl\nl\nl';
  sol[3]:=eqt[3]+#127'500,500,1200,10;A,250,250,50;B,4;D,1,-5,1,5,10;'#127+negg+
	'\nl\nl\nl\nl\nl\nl\nl';
  sol[4]:=eqt[4]+#127'500,500,1200,10;A,250,250,50;B,4;D,1,-5,1,5,10;'#127+negg+
	'\nl\nl\nl\nl\nl\nl\nl';
  sol[5]:=eqt[5]+#127'500,500,1200,10;A,250,250,50;B,4;D,2,-5,2,5,10;'#127+negg+
	'\nl\nl\nl\nl\nl\nl\nl';
  sol[6]:=eqt[6]+#127'500,500,1200,10;A,250,250,50;B,4;D,1,-5,1,5,10;'#127+negg+
	'\nl\nl\nl\nl\nl\nl\nl';
  sol[7]:=eqt[7]+poss+'\nl\nl\nl\nl\nl\nl\nl';
  sol[8]:=eqt[8]+#127'500,500,1200,10;A,250,250,50;B,4;D,1,-5,1,5,10;'#127+negg+
	'\nl\nl\nl\nl\nl\nl\nl';
  sol[9]:=eqt[9]+poss+'\nl\nl\nl\nl\nl\nl\nl';
  sol[10]:=eqt[10]+poss+'\nl\nl\nl\nl\nl\nl\nl';
  replace('x = 1','x = 2',sol[5]);
  answer:=ans[mat[1]]+ans[mat[2]]+ans[mat[3]]+ans[mat[4]]+ans[mat[5]];
  solution::='\nl\red{Solution:}'+
	#12'\red{Choice 1}'+nl+'You got this one \green{right}.'+nl+sol[mat[1]];
  solution2::=#10#12'\red{Choice 2}'+nl+'You got this one \green{right}.'+nl+sol[mat[2]];
  solution3::=#10#12'\red{Choice 3}'+nl+'You got this one \green{right}.'+nl+sol[mat[3]];
  solution4::=#10#12'\red{Choice 4}'+nl+'You got this one \green{right}.'+nl+sol[mat[4]];
  solution5::=#10#12'\red{Choice 5}'+nl+'You got this one \green{right}.'+nl+sol[mat[5]];
  type:='S';
  key:=4052;
end;

procedure s4052;
var
  j,n:integer;
  res,w,z:string;
begin
  z:='';
  n := 10;
  for j:=1 to 5 do begin
    if answer[j-1] <> response[j-1] then begin
      z:=z+st(j)+',';
      n := n - 2;
    end;
  end;
  result := chr(48+n);
  if answer=response then message:=#141'Correct.'#141
  else begin
    w := '';
    if pos('1',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution) else
       replace(#140'wrong'#140,#141'right'#141,solution);
    if pos('2',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution2) else
       replace(#140'wrong'#140,#141'right'#141,solution2);
    if pos('3',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution3) else
       replace(#140'wrong'#140,#141'right'#141,solution3);
    if pos('4',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution4) else
       replace(#140'wrong'#140,#141'right'#141,solution4);
    if pos('5',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution5) else
       replace(#140'wrong'#140,#141'right'#141,solution5);
    message:=response+' is '#140'incorrect'#140'.'+#13+buff1;
  end;
end;

procedure p4053;
var
  x:paramtype;
  undef,notwff:boolean;
  header,part1,part2,ans1,ans2,dgm,text,w,z:string;
begin
  x.b:=rand([3,6,9,12,15]);
  x.c:=x.b*100;
  x.d:=x.c^2;
  x.e:=x.b/3;
  x.f:=x.e*100;
  x.g:=x.f^2/4;
  x.h:=3*x.g/2;
  dgm::=#127'500,500,1200,0;I,100,100,50;R,0,0,6,4;L,3,0,3,4;B,2;C,.25,1.8,x;'+
	'C,3.25,1.8,x;C,6.25,1.8,x;C,3,-.5,y;B,4;D,0,-.3,2.7,-.3,6;'+
	'D,3.5,-.3,6,-.3,6;'#127;
  header:='\red{Part A must be either correct or have been graded twice before '+
	'starting Part B. Page down to begin Part B.}';
  text:='You have \b 00 ft. of fencing to enclose a rectangular pen with a '+
	'partition in the middle as shown. Let A denote the total area enclosed.';
  part1:='\red{Part A:} Express A in terms of x.';
  part2:='\red{Part B:} Find the value of x for which the area A is maximal.';
  part:='A';
    text1::=dgm+header+#13+#13+text+#13+part1+#13+part2+#13;
    buff1:=dgm+text+#13+part1+#13+part2+#13;
    prompt::=#133'Part A:\nl A(x) = '#134;
    ans1:='$${$\c\over 2$}x-{3\over 2}x^2$$';
    answer::=ans1;
    help::='Area of Rectangle: length\cdot width';
    text3::=buff1+#13+'\blue{Hint:}\nl The area of the pen is xy. Now use the total amount of '+
	'fencing to express y in terms of x.';
    solution::=nl+'\red{Solution to Part A:}\nl '+
	'The total amount of fencing used is $$3x+2y$$ and this must equal '+
	'\b 00.\pause\nl '+
	'Thus $$3x+2y=\b 00$$\pause\nl '+
	'Solving for y we have $$y={\b 00-3x\over 2}$$.\pause\nl '+
	'Thus A = xy = x({\b 00-3x\over 2}) = '+ans1+'.';
    type:='R';
    key:=4053;
  eject;
  part:='B';
    header:='\red{This is part B of a two part question.}';
    text1::=dgm+header+#13+#13+text+#13+part1+#13'\ \ \  Answer:  = '+ans1+#13+part2+#13;
    buff1:=dgm+text+#13+part1+#13'\ \ \  Answer:  = '+ans1+#13+part2+#13;
    prompt::=#133'Part B:\nl x = '#134;
    ans2:='{$\c\over 6$}';
    answer::=ans2;
    help::='The parabola $$y=a(x-h)^2+k$$ has its vertex at (h,k). If '+
	'a > 0 the parabola opens upwards while if a < 0 the parabola '+
	'opens downwards.\nl '+
	'A parabola in the form $$ax^2+bx+c$$ can be put into the above '+
	'form by completing the square.';
    text3::=buff1+#13+'\blue{Hint:}\nl Put the parabola in the form $$y=a(x-h)^2+k$$ by completing '+
	'the square.';
    solution::='\nl \red{Solution to Part B:}\nl '+
	'A(x) = '+ans1+' = $${$-3\over 2$}x^2+{$\c\over 2$}x$$ = '+
	'$${-3\over 2}(x^2-\f x)$$.\pause\nl '+
	'Completing the square we find\nl '+
	'$$A(x) = {-3\over 2}(x^2-\f x+\g-\g)$$ '+
	'= $${-3\over 2}(x-{$\c\over 6$})^2+\h$$.\pause\nl '+
	'Thus A(x) is a parabola opening downwards with vertex at ({$\c\over 6$},\h).\pause\nl '+
	'Thus the maximum area occurs when x = '+ans2+'.';
    type:='R';
    key:=4053;
end;                   

procedure s4053;
var
  res,res1,res2,r1,r2,t1,t2,insrt,ans1,ans2:string;
  undef,notwff:boolean;
  x,y:real;
begin
  if part = 'A' then begin
    if sameexpres(answer,response) then begin
      result := 'T';
      message:=#141'Correct'#141;
    end else begin
      result := 'F';
      replace(prompt,'',response);
      if response = '' then message:=#140'Incorrect'#140+#13+text3
      else message:=response+' is '#140'incorrect'#140'. '+#13+text3;
    end;
  end;
  if part ='B' then begin
    if sameconstants(answer,response) then begin
      result := 'T';
      message:=#141'Correct'#141;
    end else begin
      result:='F';
      replace(prompt,'',response);
      if response = '' then message:=#140'Incorrect'#140+#13
      +text3
      else message:=response+' is '#140'incorrect'#140'. '+#13+text3;
    end;
  end;
end;

procedure p4054;
var
  x:paramtype;
  undef,notwff:boolean;
  header,part1,part2,ans1,ans2,dgm,text,w,z:string;
begin
  x.a:=rand([8..14]);
  x.b:=x.a+rand([-4..-1]);
  x.c:=x.b^2;
  x.d:=x.a*x.c;
  x.e:=4*x.b;
  dgm::=#127'550,500,1200,10;I,150,100,50;L,-2,0,8,0;L,0,-2,0,8;'+
	'G,-1.5x+6,D0,D4;G,3,D0,D2;L,2,3,2,0;G,0,D2,2;'+
	'B,2;F,.1,.1;B,4;C,2.2,3.2,(x,y);C,4,-.5,(\b,0);C,-2.5,5.8,(0,\a);'#127;
  header::='\red{Part A must be either correct or have been graded twice before '+
	'starting Part B. Page down to begin Part B.}';
  text:='A rectangle has one vertex at (0,0) and the opposite vertex lies '+
	'in the first quadrant on the line passing through (0,\a) and  '+
	'(\b,0). ';
  part1:='\red{Part A:} Express the area A of the rectangle as a function of x.';
  part2:='\red{Part B:} Find the area A_{max} of the largest such rectangle.';
  part:='A';
    text1::=dgm+header+#13+#13+text+#13+part1+#13+part2+#13;
    buff1:=dgm+text+#13+part1+#13+part2+#13;
    prompt::=#133'Part A:\nl A(x) = '#134;
    ans1:='$${$-\a\over \b$}x^2+\a x$$';
    answer::=ans1;
    help::='Slope Intercept Equation of a Line: $$y=mx+b$$ where '+
	'm is the slope and (0,b) is the y-intercept.\nl '+
	'Area of Rectangle: length\cdot width';
    text3::=buff1+#13+'\blue{Message:}\nl Find the equation of the line through (0,\a) and '+
	'(\b,0) use it to express y in terms of x.';
    solution::='\nl\red{Solution to Part A:}\nl '+
	'The slope of the line is {-\a\over \b} and the equation of the '+
	'line is \nl $$y={$-\a\over \b$}x+\a$$.\pause\nl '+
	'The area of the rectangle is A = xy = $$x({$-\a\over \b$}x+\a)$$ '+
	'= '+ans1+'.';
    type:='R';
    key:=4054;
  eject;
  part:='B';
    header:='\red{This is part B of a two part problem.}';
    text1::=dgm+header+#13+#13+text+#13+part1+#13'\ \ \  Answer:  = '+ans1+#13+part2+#13;
    buff1::=dgm+text+#13+part1+#13'\ \ \  Answer:  = '+ans1+#13+part2+#13;
    prompt::=#133'Part B:\nl A_{max} = '#134;
    ans2:='{$\d\over \e$}';
    answer::=ans2;
    help::='The parabola $$y=a(x-h)^2+k$$ has its vertex at (h,k). If '+
	'a > 0 the parabola opens upwards while if a < 0 the parabola '+
	'opens downwards.\nl '+
	'A parabola in the form $$ax^2+bx+c$$ can be put into the above '+
	'form by completing the square.';
    text3::=buff1+#13+'\blue{Message:}\nl The area function is a quadratic and its vertex '+
	'can be found by completing the square.';
    solution::='\nl \red{Solution to Part B:}\nl '+
	'A(x) = '+ans1+' = $${$-\a\over \b$}(x^2-\b x)$$ '+
	'= $${$-\a\over \b$}(x^2-\b x+{$\c\over 4$}-{$\c\over 4$})$$\nl '+
	'= $${$-\a\over \b$}(x-{$\b\over 2$})^2+{$\d\over \e$}$$\pause\nl '+
	'Thus A(x) is a parabola opening downwards with vertex at '+
	'({$\b\over 2$},{$\d\over \e$}) so the maximum area is '+ans2+'.';
    type:='R';
    key:=4054;
end;                   

procedure s4054;
var
  res,res1,res2,r1,r2,t1,t2,insrt,ans1,ans2:string;
  undef,notwff:boolean;
  x,y:real;
begin
  if part = 'A' then begin
    if sameexpres(answer,response) then begin
      result := 'T';
      message::='\green{Correct}';
    end else begin
      result := 'F';
      replace(prompt,'',response);
      if response = '' then message:=#140'Incorrect'#140+#13+text3
      else message:=response+' is '#140'incorrect'#140'. '+#13+text3;
    end;
  end;
  if part ='B' then begin
    if sameconstants(answer,response) then begin
      result := 'T';
      message::='\green{Correct}';
    end else begin
      result:='F';
      replace(prompt,'',response);
      if response = '' then message:=#140'Incorrect'#140+#13+text3
      else message:=response+' is '#140'incorrect'#140'. '+#13+text3;
    end;
  end;
end;

procedure p4059;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm:string;
begin
  x.a:=rand([24,36,40,56,64,72]);
  x.b:=2*x.a;
  x.c:=x.a^2;
  dgm::=#127'500,500,1200,10;I,250,100,50;B,4;R,-4,0,-2,2;E,0,0,3,3;L,-5,6,5,6;'+
	'L,-1,5.6,-1,6.4;B,2;C,-3,6.2,x;B,0;D,-5,6.4,-3.1,6.4,4;D,-2.5,6.4,-1,6.4,4;'+
	'B,2;C,-.3,7,\a;B,0;D,-5,7.2,-.5,7.2,8;D,.5,7.2,5,7.2,8;'#127;
  text1::=dgm+'A piece of wire \a  inches long is cut into two pieces. '+
	'One piece is bent into a square while the other piece is bent into a '+
	'circle. Let x denote the length (in inches) of the piece bent into '+
	'the square. Express the total area A enclosed (in sq.in.) by both '+
	'the square and the circle in terms of x.\nl\nl\nl ';
  buff1:=dgm+'A piece of wire \a  inches long is cut into two pieces. '+
	'One piece is bent into a square while the other piece is bent into a '+
	'circle. Let x denote the length (in inches) of the piece bent into '+
	'the square. Express the total area enclosed (in sq.in.) by both '+
	'the square and the circle in terms of x.\nl';
  prompt::=#133'A(x) = '#134;
  help::='\red{Squares:}\nl '+
	#127'400,400,700,0;I,100,200,40;R,0,0,4,4;B,2;C,-.5,1.8,x;C,1.9,-.5,x;'#127+
	'Area of a Square: x^2\nl '+
	'Perimeter of a Square: 4x'+nl+nl+nl+nl+
	#127'400,400,700,0;I,100,200,40;E,0,0,4,4;L,2,2,4,2;B,2;C,2.8,2.2,r;'#127+
	'\red{Circles:}\nl '+
	'Area of a Circle: \pi r^2\nl '+
	'Circumference of a Circle: 2\pi r';
  text3::=buff1+#13+'\blue{Hint:}\nl Determine the edge-length of the square and the '+
	'circumference of the circle. Then find the radius of the circle and '+
	'finally its area.';
  ans:='$${x^2\over 16}+{(\a-x)^2\over 4\pi}$$';
  answer::=ans;
  solution::='\nl \red{Solution:}\nl '+
	'The second piece of wire is $$\a-x$$ inches long.\pause\nl '+
	'The length of the edge of the square is {x\over 4} inches '+
	'while the circumference of the circle is $$\a-x$$ '+
	'inches.\pause\nl ';
  solution2::='The area enclosed by the square is {x^2\over 16}.\pause\nl '+
	'We have $$2\pi r=\a-x$$ or $$r={\a-x\over 2\pi}$$.\pause\nl '+
	'So the area enclosed by the circle is $$\pi r^2 = \pi({\a-x\over 2\pi})^2$$ '+
	'= $${(\a-x)^2\over 4\pi}$$.\pause\nl '+
	'Hence the total area enclosed is A(x) = '+ans+'.';
  type:='R';
  key:=4059;
end;

procedure s4059;
var
res,res1,res2,insrt:string;
begin
  if sameexpres(answer,response) then begin
    result := 'T';
    message::='\green{Correct}';
  end else begin
    result := 'F';
    replace(prompt,'',response);
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else message:=response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4060;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2:string;
begin
  x.a:=rand([15,16,20,24,28,31,35]);
  x.b:=2*x.a;
  x.c:=x.a^2;
  x.d:=x.b^2;
  x.e:=8*x.c-x.d;
  x.f:=4*x.a-x.b;
  header:='\red{Answer both parts before grading.}';
  text:='The sum of two numbers x and y is \a.';
  part1:='\red{a:}  Express the sum of the squares of both numbers S in terms of x.';
  part2:='\red{b:}  Determine the two numbers x and y whose sum is \a  and '+
	'for which the sum of the two squares is minimal.';
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13;
  buff1:=text+#13+part1+#13+part2+#13;
  prompt::=#133'a: S(x) = '#134#13+
	   #133'b: x,y = '#134;
  help:='The parabola $$y=a(x-h)^2+k$$ has its vertex at (h,k). If '+
	'a > 0 the parabola opens upwards while if a < 0 the parabola '+
	'opens downwards.\nl '+
	'A parabola in the form $$ax^2+bx+c$$ can be put into the above '+
	'form by completing the square.';
  ans:=#134'$$2x^2-\b x+\c$$'#133+
       #134'{$\b\over 4$},{$\f\over 4$}';
  text3::='\blue{Hint:}\nl '+help;
  help::=help;
  answer::=ans;
  separate(ans,a1,a2);
  solution::='\nl\red{Solution:}\nl '+
	'If x is one of the numbers, $$\a-x$$ is the other. Thus the sum '+
	'of the squares is $$x^2+(\a-x)^2$$ = '+a1+'.\pause\nl '+
	'Hence S(x) = '+a1+'.\pause\nl '+
	'We now minimize S(x) by completing the square:\pause\nl '+
	a1+' = $$2(x^2-{$\b\over 2$}x+{$\d\over 16$})-{$\d\over 8$}+\c$$ '+
	'= $$2(x-{$\b\over 4$})^2+{$\e\over 8$}$$.\pause\nl '+
	'Thus S(x) is minimal when x = {$\b\over 4$}.\pause\nl '+
	'Since $$x+y=\a$$, it follows that y = {$\f\over 4$}.\pause\nl '+
	'Hence the two numbers are {$\b\over 4$} and {$\f\over 4$}.';
  type:='R';
  key:=4060;
end;       

procedure s4060;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  separate(response,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameexpres(a1,r1);
  check2:=sameconstants(a2,r2) or samepoints(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message:='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message::=#140'a: '#140+r1+' is \green{correct}.'+nl;
    end else begin
      if r1 = '' then begin
	message:=#140'a: Incorrect'#140'.'+nl;
      end else begin
	message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message::=message+#140'b: '#140+r2+' is \green{correct}.';
    end else begin
      if r2 = '' then begin
	message:=message+#140'b: Incorrect'#140'.'+nl;
      end else begin
	message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;
	       
procedure p4061;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2:string;
begin
  x.a:=rand([2,3,4]);
  x.b:=rand([5,10,12,14]);
  x.c:=rand([5,7,11]);
  x.d:=x.b^2;
  x.e:=x.b^2+x.a^2;
  x.f:=2*x.a*x.c;
  x.g:=x.c^2;
  x.p:=x.f^2;
  x.h:=4*x.e^2;
  x.i:=4*x.e*x.d;
  x.j:=2*x.e;
  x.k:=4*x.e*x.d*x.g-x.d*x.f^2;
  x.m:=4*x.e*x.d^2;
  x.n:=x.c*x.j-x.a*x.f;
  x.q:=x.j*x.b;
  header:='\red{Answer both parts before grading.}';
  text:='Let (x,y) denote a point on the line $$\a x+\b y=\c$$.';
  part1:='\red{a:} Let S denote the square of the distance from (x,y) to '+
	'(0,0). Express S in terms of x.';
  part2:='\red{b:} Find the point (x,y) for which S is minimal - i.e. the '+
	'point which is closest to (0,0).';
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13;
  buff1:=text+#13+part1+#13+part2+#13;
  prompt::=#133'a: S(x) = '#134#13+
	   #133'b: (x,y) = '#134;
  help::='Distance between points (a,b) and (c,d):\nl '+
	'$$\sqrt{(c-a)^2+(d-b)^2}$$\nl\nl '+
	'The vertex of a parabola $$y = ax^2+bx+c$$ occurs at x = {-b\over 2a}';
  ans:=#134'$${$\e\over \d$}x^2-{$\f\over \d$}x+{$\g\over \d$}$$'#133+
       #134'({$\f\over \j$},{$\n\over \q$})';
  text3::=buff1+#13'\blue{Hint:}\nl Use the distance formula to find S and then minimize S by finding '+
	'the x-coordinate of the vertex.';
  answer::=ans;
  separate(ans,a1,a2);
  solution::='\nl\red{Solution:}\nl '+
	'Since $$\a x+\b y=\c$$, it follows that $$y={\c-\a x\over \b}$$.\pause\nl '+
	'Thus $$S=x^2+y^2=x^2+({\c-\a x\over \b})^2$$ = '+a1+'.\pause\nl '+
	'For a parabola $$ax^2+bx+c$$ opening upwards, the minimum value '+
	'occurs when x = {-b\over 2a}.\pause\nl '+
	'Thus the minimum of S occurs when x = {{$\f\over \d$}\over 2\cdot{$\e\over \d$}} = {$\f\over \j$}.\pause\nl '+
	'Now x = {$\f\over \j$} => $$y={\c-\a({$\f\over \j$})\over \b}$$ = '+
	'{$\n\over \q$}.\pause\nl '+
	'Hence the closest point is '+a2+'.';
  type:='R';
  key:=4061;
end;       

procedure s4061;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  separate(response,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameexpres(a1,r1);
  check2:=samepoints(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message::=#140'a: '#140+r1+' is \green{correct}.'+nl;
    end else begin
      if r1 = '' then begin
	message:=#140'a: Incorrect.'#140+nl;
      end else begin
	message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message::=message+#140'b: '#140+r2+' is \green{correct}.';
    end else begin
      if r2 = '' then begin
	message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
	message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;
	       
procedure p4064;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm:string;
begin
  x.a:=rand([72,76,84,90,96]);
  dgm::=#127'500,500,1200,10;I,250,100,50;B,2;R,-3,0,3,4;G,\sqrt{9-x^2}+4,-3,3;'+
	'B,0;D,0,4,2.06,6.14,5;B,2;C,1.4,4.9,r;'#127;
  text1::=dgm+'A Norman window is in the shape of a rectangle surmounted '+
	'by a semicircle. The total distance around the window is \a  inches. '+
	'Express the area of the window A in terms of the radius r of the '+
	'semicircle.\nl\nl\nl\nl\nl\nl ';
  buff1:=dgm+'A Norman window is in the shape of a rectangle surmounted '+
	'by a semicircle. The total distance around the window is \a  inches. '+
	'Express the area of the window A in terms of the radius of the '+
	'semicircle.\nl';
  prompt::=#133'A(r) = '#134;
  help::='\red{Circles:}\nl '+
	#127'400,400,700,0;I,100,220,40;E,0,0,4,4;L,2,2,4,2;C,2.8,2.2,r;'#127+
	'Area of a Circle: \pi r^2\nl '+
	'Circumference of a Circle: 2\pi r \nl\nl '+
	#127'400,400,700,0;I,100,200,40;R,0,0,6,4;C,-.5,1.8,x;C,2.8,-.5,y;'#127+
	'\red{Rectangles:}\nl '+
	'Area of a Rectangle: xy\nl '+
	'Perimeter of a Rectangle: 2x + 2y';
  replace('4.9,r;','4.9,r;C,-3.5,1.8,x;C,-.3,-.5,2r;',buff1);
  replace('4.9,r;','4.9,r;C,-3.5,1.8,x;C,-.3,-.5,2r;',dgm);
  text3::=buff1+#13+'\blue{Hint:}\nl Let x denote the height of the rectangle. The base of '+
	'the rectangle is 2r. Express the total area of the window in terms '+
	'of x and r. Then use the information about the perimeter of the '+
	'window to get x in terms of r.';
  ans:='$$\a r-(2+{\pi\over 2})r^2$$';
  answer::=ans;
  solution::='\nl \red{Solution:}\nl '+dgm+
	'The area of the window is (area of rectangle) + (area of '+
	'semicircle)\nl = x\cdot 2r + {1\over 2}\pi r^2.\pause\nl '+
	'The total perimeter of the window is 2x + 2r +\pi r.\pause\nl '+
	'Thus $$\a=2x + 2r +\pi r$$ => $$x={\a-r(2+\pi)\over 2}$$.\pause\nl '+
	'Substituting for x in the area formula we find\nl '+
	'A(r) = $${\a-2r-\pi r\over 2}\cdot 2r + {1\over 2}\pi r^2$$ '+
	'= '+ans+'.';
  type:='R';
  key:=4064;
end;

procedure s4064;
var
res,res1,res2,insrt:string;
begin
  if sameexpres(answer,response) then begin
    result := 'T';
    message::='\green{Correct}';
  end else begin
    result := 'F';
    replace(prompt,'',response);
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else message:=response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;
	       
procedure p4065;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm:string;
begin
  x.a:=rand([10,12,14,15,16,20]);
  x.b:=rand([4,6,8,9]);
  x.c:=x.a^2;
  x.d:=x.b^2;
  dgm::=#127'500,500,1200,0;I,250,100,50;E,-3,4,3,6;L,0,0,-3,5;L,0,0,3,5;'+
	'L,0,5,3,5;B,2;C,1,5.1,\b;D,-4,0,-4,5,10;C,-5,2.5,\a;B,0;E,-1.63,2.37,1.65,2.97;'+
	'F,.1,1;F,-.2,1;L,0,2.67,1.65,2.67;B,4;D,3,0,3,2.67,6;C,3.2,1.3,h;'#127;
  text1:=dgm+'Water is being poured into a tank in the shape of a right '+
	'circular cone. The cone has a radius of \b  ft. and is \a  ft. deep. '+
	'Let h denote the depth of water in the tank. Express the surface area '+
	'A of the top of the water (in sq.ft.) in terms of h.\nl';
  buff1:=text1;
  text1::=text1+'\nl\nl\nl';
  prompt::=#133'A(h) = '#134;
  help::=#127'400,400,700,0;I,100,200,40;E,0,0,4,4;L,2,2,4,2;C,2.8,2.2,r;'#127+
	'\red{Formulas for Circles:}\nl '+ 
	'Area = \pi r^2\nl '+
	'Circumference = 2\pi r'+#10#12+
	#127'400,400,700,0;I,200,80,40;E,-3,4,3,6;L,0,0,-3,5;L,0,0,3,5;'+
	'D,0,0,0,5,8;D,0,5,3,5,4;B,2;C,-.5,2.3,h;C,1.4,5.2,r;'#127+
	'\red{Volume of a Cone:}\nl '+
	'{\pi\over 3}r^2h';
  replace('1.3,h;','1.3,h;C,.4,2.7,r;',buff1);
  text3::=buff1+#13+'\blue{Hint:}\nl The surface area of the top of the water is a circle. '+
	'Express the area of the circle in terms of its radius and then use '+
	'similar triangles to express r in terms of h.';
  ans:='{$\d\over \c$}\pi h^2';
  answer::=ans;
  solution::=#127'500,500,1200,100;I,100,100,50;L,0,0,0,3;L,0,3,1.5,3;'+
	'L,0,0,1.5,3;L,3,0,3,6;L,3,6,6,6;L,6,6,3,0;B,2;C,-.5,1.3,h;'+
	'C,.6,3.2,r;C,2.3,2.8,\a;C,4.2,6.2,\b;'#127+
	'\nl \red{Solution:}\nl '+
	'Let r denote the radius (in ft.) of the top of the water in the '+
	'tank. Then A = \pi r^2.\pause\nl '+
	'To express r in terms of h we use similar triangles. We have '+
	'$${r\over h}={\b\over \a}$$ => $$r={$\b\over \a$}h$$.\pause\nl '+
	'Thus A = \pi r^2 = \pi({$\b\over \a$}h)^2 = '+ans+'.';
  type:='R';
  key:=4065
end;

procedure s4065;
var
res,res1,res2,insrt:string;
begin
  if sameexpres(answer,response) then begin
    result := 'T';
    message::='\green{Correct}';
  end else begin
    result := 'F';
    replace(prompt,'',response);
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else message:=response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4068;   {old 1166b}
var
  a,b,c,d,e,f,g,h,k:integer;
  v:valuetype;
  dgm,dgm2,text:string;
begin
  a:=randint(4,9);
  b:=randint(40,50);
  c:=randint(25,35);
  e:=a*a;v.e:=e;
  f:=b+c;v.f:=f;
  dgm:=#127'500,500,1200,10;I,150,300,25;L,0,0,0,8;L,0,0,8,0;L,8,0,8,-8;'+
      'L,0,8,8,-8;B,4;C,-5,3.8,train;C,9,-3.8,truck;B,2;C,2,-1,'+st(a)+';'+
      'D,0,-.5,1.7,-.5,3;D,2.8,-.5,8,-.5,7;C,3.5,2,S;'+
      'B,0;L,-.5,3.5,0,4;L,0,4,.5,3.5;L,7.5,-3.5,8,-4;L,8,-4,8.5,-3.5;';
  text:='At t = 0 a train is '+st(a)+' miles west of a truck. The '+
	'train is traveling north at '+st(b)+' mph. while the truck '+
	'is traveling south at '+st(c)+' mph. If t is '+
	'measured in hours, express the distance S between the train and '+
	'the truck as a function of t.'+nl;
  text1::=dgm+#127+text+'\nl\nl\nl ';
  help::=#127'400,500,700,0;I,200,300,50;L,0,0,0,4;L,0,4,2,0;L,0,0,2,0;'+
	'C,-.5,1.8,a;C,.8,-.6,b;C,1.4,1.8,c;'#127+
	'\red{Pythagorean Theorem:}\nl '+
	'$$a^2+b^2=c^2$$\nl\nl '+
	'Distance = Rate\cdot Time';
  prompt::=#133'S(t) = '#134;
  answer:=makeformula('{e+(ft)^2}',['e','f'],v);
  text3::=dgm+#127+text+nl+'\blue{Hint:} \nl Express the distances traveled by the train and by the truck '+
    'in terms of t and then apply the Pythagorean theorem.';
  dgm2:=#127'500,500,1200,10;I,150,300,25;L,0,0,0,8;L,0,0,8,0;L,8,0,8,-8;'+
      'L,0,8,8,-8;B,4;C,.6,7.4,train;C,8.4,-8.2,truck;B,2;C,2,-1,'+st(a)+';'+
      'D,0,-.5,1.7,-.5,3;D,2.8,-.5,8,-.5,7;C,3.5,2,S;C,-2,3.8,'+st(b)+'t;'+
      'C,8.2,-4.2,'+st(c)+'t;D,0,0,0,-8,10;D,0,-8,8,-8,10;C,-2,-4.2,'+st(c)+'t;'+
      'C,3.8,-9,'+st(a)+';B,0;C,-1,-9,A;C,-1,7,B;C,8,-9,C;'#127;
  solution::=dgm2+'\nl \red{Solution:}\nl '+
      'Distance equals Rate\cdot Time.\pause\nl '+
      st(b)+'t represents the distance traveled by the train while '+st(c)+'t '+
      'represents the distance traveled by the truck.  \pause\nl '+
      'Applying the Pythagorean Theorem in the big triangle ABC we have\nl '+
      makeformula('S^2=('+st(a)+')^2+('+st(c)+'t+'+st(b)+'t)^2',[],v)+nl+#10+
      '=> S(t) = '+answer+'.';
  type:='R';
  key := 4068;
end;

procedure s4068;
var
res,res1,res2,insrt:string;
begin
  if sameexpres(answer,response) then begin
    result := 'T';
    message::='\green{Correct}';
  end else begin
    result := 'F';
    replace(prompt,'',response);
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else message:=response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4070;  {old 1328}
var
v:valuetype;
a,b,k:integer;
begin
help::='\red{Quadratic Formula:}\nl '+
	'Roots of $$ax^2+bx+c$$:\nl '+
	'$$x={-b\pm\sqrt{b^2-4ac}\over 2a}$$';
k:=randint(1,3);
case k of
  1:
    begin
    repeat
     repeat
       v.a:=rand([3,5,6,7]);
       v.b:=rand([2,4,5]);
      until v.a > v.b;
      v.c:=v.a*v.a+v.b*v.b;
      v.d:=v.a*v.b;
    until gcd(v.c,v.d)=1;
    v.e:=v.c*v.c;
    v.f:=4*v.d*v.d;
    v.g:=2*v.d;
    v.h:=v.a*v.a-v.b*v.b;
    text1:='The sum of a number x and its reciprocal is '+fraction(v.c,'/',v.d)+'. '+
      'Find one such number x.'+nl;
    buff1:=text1;
    prompt::=#133'x = '#134;
    text3::=buff1+#13+'\blue{Hint:}\nl x must satisfy the equation '+makeformula('x+[1]/[x]=[c]/[d]',['c','d'],v)+'.'+
      ' Solve this equation for x.';
    answer:=fraction(v.a,'/',v.b)+','+fraction(v.b,'/',v.a);
    solution::='\nl \red{Solution:}\nl '+
      makeformula('x+[1]/[x]=[c]/[d]',['c','d'],v)+nl+
      '=> '+makeformula('dx^2+d=cx',['d','c'],v)+nl+#10+
      '=> '+makeformula('dx^2-cx+d=0',['d','c'],v)+nl+#10+
      'Applying the quadratic formula yields\nl '+
      makeformula('x=[c+{e-f}]/[g]',['c','e','f','g'],v)+' or '+
      makeformula('x=[c-{e-f}]/[g]',['c','e','f','g'],v)+nl+#10+
      '=> '+makeformula('x=[c+h]/[g]',['c','h','g'],v)+' or '+
      makeformula('x=[c-h]/[g]',['c','h','g'],v)+nl+#10+
      '=> x = '+fraction(v.a,'/',v.b)+' or x = '+fraction(v.b,'/',v.a)+'.';
    text6:=fraction(v.a,'/',v.b);
    text5:=fraction(v.b,'/',v.a);
  end;
  2:
  begin
    repeat
      v.a:=rand([3,5,6,7]);
      v.b:=rand([2,4,5]);
      v.c:=v.a*v.a+2*v.b*v.b;
      v.d:=v.a*v.b;
    until gcd(v.c,v.d)=1;
    v.g:=2*v.d;
    v.e:=v.c*v.c;
    v.f:=4*v.d*v.g;
    v.h:=abs(v.a*v.a-2*v.b*v.b);
    text1:='The sum of a number x and twice its reciprocal is '+fraction(v.c,'/',v.d)+'. '+
      'Find such a number.'+nl;
    buff1:=text1;
    prompt::=#133'x = '#134;
    text3::=buff1+nl+'\blue{Hint:}\nl x must satisfy the equation '+makeformula('x+[2]/[x]=[c]/[d]',['c','d'],v)+'.'+
      ' Solve this equation for x.';
    answer:=fraction(v.c+v.h,'/',v.g)+','+fraction(v.c-v.h,'/',v.g);
    solution::='\nl \red{Solution:}\nl '+
      makeformula('x+[2]/[x]=[c]/[d]',['c','d'],v)+nl+
      '=> '+makeformula('dx^2+g=cx',['d','c','g'],v)+nl+#10+
      '=> '+makeformula('dx^2-cx+g=0',['d','c','g'],v)+nl+#10+
      'Applying the quadratic formula yields\nl '+
      makeformula('x=[c+{e-f}]/[g]',['c','e','f','g'],v)+' or '+
      makeformula('x=[c-{e-f}]/[g]',['c','e','f','g'],v)+nl+#10+
      'Thus '+makeformula('x=[c+h]/[g]',['c','g','h'],v)+' or '+
      makeformula('x=[c-h]/[g]',['c','g','h'],v)+nl+#10+
      ' => x = '+fraction(v.c+v.h,'/',v.g)+' or x = '+fraction(v.c-v.h,'/',v.g);
    text6:=fraction(v.c+v.h,'/',v.g);
    text5:=fraction(v.c-v.h,'/',v.g); 
  end;
  3:
  begin
    repeat
      v.a:=rand([3,5,6,7]);
      v.b:=rand([2,4,5]);
      v.c:=v.a*v.a-2*v.b*v.b;
      v.d:=v.a*v.b;
    until gcd(v.c,v.d)=1;
    v.g:=2*v.d;
    v.e:=v.c*v.c;
    v.f:=4*v.d*v.g;
    v.h:=abs(v.a*v.a+2*v.b*v.b);
    text1:='A number x minus twice its reciprocal is '+fraction(v.c,'/',v.d)+'. '+
      'Find such a number.'+nl;
    buff1:=text1;
    prompt::=#133'x = '#134;
    text3::=buff1+#13+'\blue{Hint:}\nl The number x must satisfy the equation '+
      makeformula('x-[2]/[x]=[c]/[d]',['c','d'],v)+'.'+nl+
      'Solve this equation for x.';
    answer:=fraction(v.c+v.h,'/',v.g)+','+fraction(v.c-v.h,'/',v.g);
    solution::='\nl\red{Solution:}\nl '+
      makeformula('dx^2-g=cx',['d','c','g'],v)+nl+#10+
      ' => '+makeformula('dx^2-cx-g=0',['d','c','g'],v)+nl+#10+
      'Applying the quadratic formula yields\nl '+
      makeformula('x=[c+{e+f}]/[g]',['c','e','f','g'],v)+' or '+
      makeformula('x=[c-{e+f}]/[g]',['c','e','f','g'],v)+nl+#10+
      'Thus '+makeformula('x=[c+h]/[g]',['c','g','h'],v)+' or '+
      makeformula('x=[c-h]/[g]',['c','g','h'],v)+nl+#10+
      ' => x = '+fraction(v.c+v.h,'/',v.g)+' or x = '+fraction(v.c-v.h,'/',v.g);
    text6:=fraction(v.c+v.h,'/',v.g);
    text5:=fraction(v.c-v.h,'/',v.g);
  end;
end;{case}
response:='';
type:='R';
key:=4070;
end;

procedure s4070;
begin
  if sameconstants(answer,response) or sameconstants(text5,response) or
    sameconstants(text6,response) then begin
    result := 'T';
    message::='\green{Correct}';
  end else begin
    result := 'F';
    replace(prompt,'',response);
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else message:=response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4071;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,a3,dgm,header,text,part1,part2,part3,comment:string;
begin
  x.a:=rand([-4,-5,-2,3,4,7]);
  x.c:=rand([10,12,14,15,17]);
  x.d:=4*x.a*x.c;
  header:='\red{Answer all parts before grading.}';
  text:='Let f(x) = $$\a x^2+bx+\c$$. For what values of b does f(x) '+
	'have';
  part1:='\red{a:} 2 real roots: (40%)';
  part2:='\red{b:} 1 real root:(30%)';
  part3:='\red{c:} no real roots:(30%)';
  comment:='Use interval notation or "none" when appropriate. Separate '+
	'individual numbers by commas.';
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13+part3+#13+comment+#13;
  buff1::=text+#13+part1+#13+part2+#13+part3+#13+comment+#13;
  prompt::=#133'a: 2 real roots: '#134#13+
	   #133'b: 1 real root: '#134#13+
	   #133'c: no real roots: '#134;
  help::='\red{Quadratic Formula:}\nl '+
	'Roots of $$ax^2+bx+c$$:\nl '+
	'$$x={-b\pm\sqrt{b^2-4ac}\over 2a}$$\nl\nl '+
	'The equation has 2 real roots if $$b^2-4ac>0$$\nl '+
	'The equation has 1 real root if $$b^2-4ac=0$$\nl '+
	'The equation has no real roots if $$b^2-4ac<0$$';
  text3::=buff1+#13+'\blue{Hint:}\nl Determine conditions on b which makes the '+
	'discriminant positive, zero, or negative.';
  solution::='\red{Solution:}\nl '+
       'For a general quadratic equation $$ax^2+bx+c=0$$, the equation '+
       'the nature of the roots depends on the discriminant $$D=b^2-4ac$$.\pause\nl '+
       'If D > 0, the equation has two real roots. If D = 0, the equation has '+
       '1 real root, and if D < 0, the equation has no real roots.\pause\nl '+
       'For the equation $$\a x^2+bx+\c=0$$, D = $$b^2-\d$$.';
  if x.d<0 then begin
    ans:=#134'(-\inf,\inf)'#133+
	 #134'none'#133+
	 #134'none';
    answer::=ans;
    separate(ans,a1,a2,a3);
    solution2::='Since D > 0 for all b, f(x) has two real roots for all b and '+
	'so the answer is\nl '+
	'\red{a:}  2 real roots: '+a1+'\nl '+
	'\red{b:}  1 real root: '+a2+'\nl '+
	'\red{c:}  no real roots '+a3;
  end else begin
    ans:=#134'(-\inf,-\sqrt{\d}),(\sqrt{\d},\inf)'#133+
	 #134'\sqrt{\d},-\sqrt{\d}'#133+
	 #134'(-\sqrt{\d},\sqrt{\d})';
    answer::=ans;
    separate(ans,a1,a2,a3);
    solution2::='It follows that D > 0 when $$b^2>\sqrt{\d}$$. This '+
	'holds when b > \sqrt{\d} or b < -\sqrt{\d}.\pause\nl '+
	'Thus f(x) has two real roots for b in '+a1+'\pause\nl '+
	'D = 0 => b = \pm\sqrt{\d}. Thus f(x) has 1 real root when '+
	'b = \sqrt{\d} or -\sqrt{\d}.\pause\nl '+
	'Finally, D < 0 holds when $$b^2<\d$$ or $$-\sqrt{\d}<b<\sqrt{\d}$$.\pause\nl '+
	'Thus f(x) has no real roots when b is in (-\sqrt{\d},\sqrt{\d}).\pause\nl '+
	'So the answer is\nl '+
	'\red{a:}  2 real roots: '+a1+'\nl '+
	'\red{b:}  1 real root: '+a2+'\nl '+
	'\red{c:}  no real roots '+a3;
  end;
  type:='R';
  key:=4071;
end;      

procedure s4071;
var
  insrt,insrt1,insrt2,insrt3,res,res1a,res1b,res1c,res2a,res2b,res2c:string;
  r1,r2,r3,r4,a1,a2,a3,a4,t1,t2,t3,t4:string;
  r:integer;
  check1,check2,check3,undef,notwff:boolean;
begin
  res:=response;
  message:='';
  check1:=false;
  check2:=false;
  check3:=false;
  separate(res,r1,r2,r3);
  clean(answer);clean(r2);clean(r3);
  toupper(answer);toupper(r2);toupper(r3);
  separate(answer,a1,a2,a3);
  check1:=sameintervals(a1,r1);
  check2:=sameconstants(a2,r2) or (sameintervals(a2,r2) and (r2 <>''))or
	  ((pos('NONE',a2)>-1) and (pos('NONE',r2)>-1));
  check3:=((length(r3)>0) and sameintervals(a3,r3)) or ((pos('NONE',a3)>-1) and (pos('NONE',r3)>-1));
  if check1 and check2 and check3 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+4;
      message:=#140'a: '#150+r1+' is '#141'correct.'#141+nl;
    end else begin
      if r1 = '' then begin
	message:=#140'a: Incorrect.'#140+#13
      end else begin
	message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+3;
      message:=message+#140'b: '#140+r2+' is '#141'correct.'#141+nl;
    end else begin
      if r2 = '' then begin
	message:=message+#140'b: Incorrect'#140'.'+nl;
      end else begin
	message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check3 then begin
      r:=r+3;
      message:=message+#140'c: '#140+r3+' is '#141'correct.'#141+nl;
    end else begin
      if r3 = '' then begin
	message:=message+#140'c: Incorrect'#140'.'+nl;
      end else begin
	message:=message+#140'c: '#140+r3+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4072;   {old 32}
var
   formula0,formula1 : string;
   v:valuetype;
begin
  v.a:=randint(2,5);
  v.p:=randint(1,5);
  v.r:=randint(-5,-2);
  v.b:= - (v.p + v.r*v.a);
  v.c:= v.p*v.r;
  text1:='Find the vertex (h,k) of the parabola with equation '+
	 makeformula('y=ax^2+bx+c',['a'..'c'],v)+'.'+nl;
  buff1:=text1;
  text3::=buff1+#13+'\blue{Hint:}\nl Rewrite the equation in the form '+nl+makeformula('y=a(x-h)^2+k',[],v)+
	 ' by completing the square.';
  help::='\red{Completing the Square:}\nl '+
	 '$$ax^2+bx+c=a(x^2+{b\over a}x+{b^2\over 4a^2})-{b^2\over 4a}+c$$\nl '+
	 '= $$(x+{b\over 2a})^2+(c-{b^2\over 4a})$$';
  formula0 := fraction(-v.b,'-',2*v.a);
  formula1 := fraction(4*v.a*v.c - v.b*v.b,'-',4*v.a);
  answer:='('+formula0+','+formula1+')';
  solution::='\nl \red{Solution:} \nl '+
	    makeformula('y=ax^2+bx+c',['a'..'c'],v)+nl+
	    ' = '+makeformula('a(x^2+[b]/[a]x)+c',['a'..'c'],v)+#10+nl+
	    ' = '+makeformula('a(x^2+'+fraction(v.b,'-',v.a)+'x+('+fraction(v.b,'-',2*v.a)+')^2)+c-a('+fraction(v.b,'-',2*v.a)+')^2',['a','b','c'],v)+nl+#10+
	    ' = '+makeformula('a(x+'+fraction(v.b,'-',2*v.a)+')^2+(c-'+fraction(v.b*v.b,'-',4*v.a),['a','b','c'],v)+nl+#10+
	    ' = '+makeformula('a(x-'+formula0+')^2+'+formula1,['a'],v)+#10+nl+
	    ' = '+makeformula('a(x-h)^2+k',[],v)+#10+nl+
	    'Thus h = '+formula0+' and k = '+formula1+nl+
	    'so the vertex (h,k) = '+answer+'.';
  prompt:=#133'(h,k) = '#134;
  key:=4072;
  type := 'R';
end;

procedure s4072;
var
res,res1,res2,insrt:string;
begin
  if samepoints(answer,response) then begin
    result := 'T';
    message::='\green{Correct}';
  end else begin
    result := 'F';
    replace(prompt,'',response);
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else message:=response+' is '#140'incorrect'#140'. '+text3;
  end;
end;

procedure p4073;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2:string;
begin
  x.c:=rand([6,7,8,9,10,12]);
  x.a:=4*x.c;
  x.d:=x.a^2;
  x.e:=x.c^2;
  header:='\red{Answer both parts before grading.}';
  text:='A ball is thrown straight upwards and its height (in feet) as a '+
	'function of time t (in seconds) is given by h(t) = $$-16t^2+\a t$$.';
  part1:='\red{a: } Find the time t_{max} at which the ball reaches its maximum '+
	'height.';
  part2:='\red{b: } Find the maximum height h_{max} attained by the ball.';
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13;
  buff1:=text+#13+part1+#13+part2+#13;
  prompt::=#133'a: t_{max}  = '#134#13+
	   #133'b: h_{max}  = '#134;
  help::='The parabola $$y=a(x-h)^2+k$$ has its vertex at (h,k). If '+
	'a > 0 the parabola opens upwards while if a < 0 the parabola '+
	'opens downwards.\nl '+
	'A parabola in the form $$ax^2+bx+c$$ can be put into the above '+
	'form by completing the square.\nl '+
	'\red{Completing the Square:}\nl '+
	'$$ax^2+bx+c=a(x^2+{b\over a}x+{b^2\over 4a^2})-{b^2\over 4a}+c$$\nl '+
	'= $$(x+{b\over 2a})^2+(c-{b^2\over 4a})$$';
  text3::=buff1+#13+'\blue{Hint:}\nl Find the vertex of h(t) by completing the square.';
  ans:=#134'{$\c\over 8$}'#133+
       #134'{$\e\over 4$}';
  answer::=ans;
  separate(ans,a1,a2);
  solution::='\nl \red{Solution:}\nl '+
	'$$h(t)=-16t^{2}+\a t$$. To maximize h(t) we complete the square:\nl '+
	'$$h(t)=-16(t^2-{$\a\over 16$}t+{$\e\over 64$})+{$\e\over 4$}$$'+
	' = $$-16(t-{$\c\over 8$})^2+{$\e\over 4$}$$.\pause\nl '+
	'Thus the ball attains its maximum height of {$\e\over 4$} ft. at '+
	'time t = {$\c\over 8$} sec.\pause\nl '+
	'Thus t_{max}  = '+a1+' and h_{max} = '+a2+'.';
  type:='R';
  key:=4073;
end;       

procedure s4073;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  separate(response,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2) or samepoints(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message::=#140'a: '#140+r1+' is \green{correct}.'+nl;
    end else begin
      if r1 = '' then begin
	message:=#140'a: Incorrect'#140'.'+nl;
      end else begin
	message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message::=message+#140'b: '#140+r2+' is \green{correct}.';
    end else begin
      if r2 = '' then begin
	message:=message+#140'b: Incorrect'#140'.'+nl;
      end else begin
	message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;
	       
procedure p4074;
var
  a,b,c,d,e,f,k,j:integer;
  v:valuetype;
  fct,sgn,con,rcp:string;
begin
  k:=randint(1,2);
  fct:='f'#30'-1'#31'(x)';
  case k of
  1:
    begin
      text1:='Which is the graph of y = '+fct+' if the graph of y = '+
	'f(x) is '+#127'400,400,100,200;A,200,200,40;B,2;G,'+makeformula('[x^2]/[4]',[],v)+',0,5;'#127;
      text2:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('2{x}',[],v)+',0,5;#127';
      text3:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('[-x^2]/[4]',[],v)+',-5,0;'#127;
      text4:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('2{x}-2',[],v)+',0,5;'#127;
      text5:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('[-x^2]/[4]',[],v)+',0,5;'#127;
      text6:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('-2{x}',['b'],v)+',0,5;'#127;
      answer:='1';
      solution::=nl+'\red{Solution:}\nl'+#127'400,400,50,50;A,200,200,40;B,2;G,'+makeformula('[x^2]/[4]',[],v)+
		',0,5;'#127#127'400,400,650,50;A,200,200,40;B,2;G,'+makeformula('2{x}',[],v)+',0,5;'+
		'D,-5,-5,5,5,20;C,-4,-5,$$y=x$$;'#127;
      solution3::='\nl\nl\nl\nl\nl\nl\nl\nl'#127'400,200,50,50;C,150,100,$$y=f(x)$$;'#127+
		#127'400,200,650,50;C,150,100,$$y=f^{-1}(x)$$;'#127+
		#127'400,200,1250,50;C,150,100,Your Choice;'#127;
    end;
  2:
    begin 
      text1:='Which is the graph of y = '+fct+' if the graph of y = '+
	'f(x) is '+#127'400,400,100,200;A,200,200,40;B,2;G,'+makeformula('[4arctan(x)]/[~]',[],v)+',-5,5;'#127;
      text2:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('tan(~x/4',[],v)+',-2,2;'#127;
      text3:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('cot(~x/4)',[],v)+',0,4;'#127;
      text4:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('|tan(~x/4)|',[],v)+',-2,2;'#127;
      text5:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('[-4arctan(x)]/[~]',[],v)+',-5,5;'#127;
      text6:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('[1]/[x]',[],v)+',-5,5;'#127;
      answer:='1';
      solution::=nl+'\red{Solution:}\nl '#127'400,400,50,50;A,200,200,40;B,2;G,'+makeformula('[4arctan(x)]/[~]',[],v)+',-5,5;'#127+
		#127'400,400,650,50;A,200,200,40;B,2;G,'+makeformula('tan(~x/4',[],v)+',-2,2;'+
		'D,-5,-5,5,5,20;C,-4,-5,$$y=x$$;'#127;
      solution3::='\nl\nl\nl\nl\nl\nl\nl\nl'+#127'400,200,50,50;C,150,100,$$y=f(x)$$;'#127+
		#127'400,200,650,50;C,150,100,$$y=f^{-1}(x)$$;'#127+
		#127'400,200,1250,50;C,150,100,Your Choice;'#127;
    end;
  end;{case}
  buff1:=#13'\blue{Hint:}\nl The graphs of y = f(x) and y = f'#30'-1'#31'(x) are symmetric to '+
      'the line y = x.';
  help::='\red{Inverse Functions:}\nl '+
	'A function must be one-to-one in order to have an inverse function.\nl '+
	'Given y = f(x), solving for x in terms of y gives the formula '+
	'for f^{-1}(y). Interchange the variables x and y to get the '+
	'formula for f^{-1}(x).\nl\nl '+
	'(f^{-1}\circ f)(x) = (f\circ f^{-1})(x) = x'+nl+nl+
	'\red{Graphs of Inverse functions:}\nl '+
	'The graphs of f(x) and f^{-1}(x) are symmetric with respect to the '+
	'line y = x.';
  type:='M';
  key :=4074;
end;

procedure s4074;
var
  hold,prob:string;
begin
  if response='2' then solution2:=text3;
  if response='3' then solution2:=text4;
  if response='4' then solution2:=text5;
  if response='5' then solution2:=text6;
  replace('400,400,1200,200;A,200,200,40','400,400,1250,50;A,200,200,40',solution2);
  if response = '1' then begin
    result:= 'T';
    message::='\green{Correct}';
  end
  else begin
    result := 'F';
    message::=#140'Incorrect'#140'.'+#13+buff1;
  end;
end;

procedure p4075;
var
  a,b,c,d,e,f,k,j:integer;
  v:valuetype;
  fct,sgn,con,rcp:string;
begin
  k:=randint(1,2);
  fct:='f'#30'-1'#31'(x)';
  case k of
  1:
    begin
      v.a:=rand([-3,-2,2]);
      v.b:=rand([-6,-4,2,5]);
      text1:='Which is the graph of y = '+fct+' if the graph of y = '+
	'f(x) is '+#127'400,400,100,200;A,200,200,40;B,2;G,'+makeformula('ax+b',['a','b'],v)+',-5,5;'#127;
      text2:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('[x-b]/[a]',['a','b'],v)+',-5,5;'#127;
      text3:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('-(ax+b)',['a','b'],v)+',-5,5;'#127;
      text4:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('[x+b+2]/[a]',['a','b'],v)+',-5,5;'#127;
      text5:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('2(ax+b)',['a','b'],v)+',-5,5;'#127;
      text6:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('[1]/[ax+b]',['a','b'],v)+',-5,5;'#127;
      answer:='1';
      solution::=nl+'\red{Solution:}\nl '+#127'400,400,50,50;A,200,200,40B,2;;G,'+makeformula('ax+b',['a','b'],v)+',-5,5;'#127+
		#127'400,400,650,50;A,200,200,40;B,2;G,'+makeformula('[x-b]/[a]',['a','b'],v)+',-5,5;'+
		'B,0;D,-5,-5,5,5,20;B,4;C,-4,-5,$$y=x$$;'#127;
      solution3::='\nl\nl\nl\nl\nl\nl\nl\nl'#127'400,200,50,50;C,150,100,$$y=f(x)$$;'#127+
		#127'400,200,650,50;C,150,100,$$y=f^{-1}(x)$$;'#127+
		#127'400,200,1250,50;C,150,100,Your Choice;'#127;
    end;
  2:
    begin 
      if rand([-1,1]) >0 then sgn:='' else sgn:='-';
      text1:='Which is the graph of y = '+fct+' if the graph of y = '+
	'f(x) is '+#127'400,400,100,200;A,200,200,40;B,2;'+
	'G,'+makeformula(sgn+'4[arccos(x/3)]/[~]',[],v)+',-3,3;'#127;
      if sgn='' then
      text2:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('3cos(~x/4)',[],v)+',0,4;'#127;
      if sgn='-' then
      text2:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('3cos(~x/4)',[],v)+',-4,0;'#127;
      text3:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('(-3cos(~x/4))',[],v)+',0,4;'#127;
      text4:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('-4[arccos(-x/3)]/[~]',[],v)+',-3,3;'#127;
      text5:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('4[arcsin(x/3)]/[~]',[],v)+',-3,3;'#127;
      text6:=#127'400,400,1200,200;A,200,200,40;B,2;G,'+makeformula('-2+4[arccos(x/3)]/[~]',[],v)+',-3,3;'#127;
      answer:='1';
      if sgn='-' then
        solution::=nl+'\red{Solution:}\nl '+#127'400,400,50,50;A,200,200,40;'+
      	          'B,2;G,'+makeformula(sgn+'4[arccos(x/3)]/[~]',[],v)+',-3,3;'#127+
		  #127'400,400,650,50;A,200,200,40;B,2;G,'+makeformula('3cos(~x/4)',[],v)+',-4,0;'+
		  'B,0;D,-5,-5,5,5,20;B,4;C,-4,-5,$$y=x$$;'#127
      else
        solution::=nl+'\red{Solution:}\nl '+#127'400,400,50,50;A,200,200,40;'+
      	          'B,2;G,'+makeformula(sgn+'4[arccos(x/3)]/[~]',[],v)+',-3,3;'#127+
		  #127'400,400,650,50;A,200,200,40;B,2;G,'+makeformula('3cos(~x/4)',[],v)+',0,4;'+
		  'B,0;D,-5,-5,5,5,20;B,4;C,-4,-5,$$y=x$$;'#127;
      solution3::='\nl\nl\nl\nl\nl\nl\nl\nl'+#127'400,200,50,50;C,150,100,$$y=f(x)$$;'#127+
		#127'400,200,650,50;C,150,100,$$y=f^{-1}(x)$$;'#127+
		#127'400,200,1250,50;C,150,100,Your Choice;'#127
    end;
  end;{case}
  buff1:=nl+'\blue{Hint:}\nl The graphs of y = f(x) and y = f'#30'-1'#31'(x) are symmetric to '+
    'the line y = x.';
  help::='\red{Inverse Functions:}\nl '+
	'A function must be one-to-one in order to have an inverse function.\nl '+
	'Given y = f(x), solving for x in terms of y gives the formula '+
	'for f^{-1}(y). Interchange the variables x and y to get the '+
	'formula for f^{-1}(x).\nl\nl '+
	'(f^{-1}\circ f)(x) = (f\circ f^{-1})(x) = x'+nl+nl+
	'\red{Graphs of Inverse functions:}\nl '+
	'The graphs of f(x) and f^{-1}(x) are symmetric with respect to the '+
	'line y = x.';
  type:='M';
  key :=4075;
end;

procedure s4075;
var
hold,prob:string;
begin
  if response='2' then solution2:=text3;
  if response='3' then solution2:=text4;
  if response='4' then solution2:=text5;
  if response='5' then solution2:=text6;
  replace('400,400,1200,200;A,200,200,40','400,400,1250,50;A,200,200,40',solution2);
  if response = '1' then begin
    result:= 'T';
    message::='\green{Correct}';
  end
  else begin
    result := 'F';
    message::=#140'Incorrect'#140'.'+#13+buff1;
  end;
end;

procedure p4076;
var
  mfstr:string;
  v:valuetype;
begin
  repeat v.a:=randint(-9,9) until v.a <>0;
  repeat v.b:=randint(-9,9) until v.b <>0;
  repeat v.c:=randint(-9,9) until (v.c <>0) and (v.a*v.c <> v.b);
  mfstr:='[ax+b]/[x+c]';
  mfstr:=makeformula(mfstr,['a','b','c'],v);
  text1 := 'Let f(x) = '+mfstr+' . Find f'#30'-1'#31'(x) .'+nl;
  text3::=text1+#13+'\blue{Hint:}\nl '+
    'Solve the equation y = f(x) for x in terms of y. This gives '+
    'the formula for f'#30'-1'#31'(y). Interchange x and y to obtain the '+
    'formula for f'#30'-1'#31'(x).';
  prompt::=#133'f^{-1}(x) = '#134;
  help::='\red{Inverse Functions:}\nl '+
	'A function must be one-to-one in order to have an inverse function.\nl '+
	'Given y = f(x), solving for x in terms of y gives the formula '+
	'for f^{-1}(y). Interchange the variables x and y to get the '+
	'formula for f^{-1}(x).\nl\nl '+
	'(f^{-1}\circ f)(x) = (f\circ f^{-1})(x) = x';
  answer := '[cx-b]/[a-x]';
  answer:=makeformula(answer,['a','b','c'],v);
  solution::='\nl\red{Solution:}\nl '+ 
    'y = '+mfstr+nl+makeformula('xy + cy = ax + b',['a','b','c'],v)+#10+#13+
    '=> '++makeformula('x(y - a) = -cy + b',['a','b','c'],v)+nl+#10+
    '=> '+makeformula('x = [-cy + b]/[y - a] = [cy - b]/[a - y]',['a','b','c'],v)+
    '= f'#30'-1'#31'(y)'+nl+#10+'Interchanging x and y yields f'#30'-1'#31'(x) '+
    '= '+answer+'.';
  type := 'R';
  key := 4076;
end;

procedure s4076;
begin
  if sameexpres(answer,response) then begin
    result := 'T';
    message::='\green{Correct}';
  end else begin
    result := 'F';
    replace(prompt,'',response);
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else message:=response+' is '#140'incorrect'#140'.'+#13+text3;
  end;
end;

procedure p4077;
var
  m,n:integer;
  v:valuetype;
  error:boolean;
  text:string;
begin
  repeat v.a:=randint(-9,9) until v.a <> 0;
  repeat v.b:=randint(-9,9) until (v.b <> 0) and (v.b <> v.a);
  repeat n:=randint(-15,15) until n <> 0;
  text:='If g(x) = '+makeformula('ax+b',['a','b'],v)+', find '+
	'g^{-1}('+st(n)+').\nl ';
  text1::=text;
  text3::=text+#13+'\blue{Hint:}\nl '+
    'g'#30'-1'#31'('+st(n)+')  is the value of x for which '+
    'g(x) = '+st(n)+'. Set g(x) equal to '+st(n)+' and solve for x.';
  prompt::=#133'g^{-1}('+st(n)+') = '#134;
  help::='\red{Inverse Functions:}\nl '+
	'A function must be one-to-one in order to have an inverse function.\nl '+
	'Given y = f(x), solving for x in terms of y gives the formula '+
	'for f^{-1}(y). Interchange the variables x and y to get the '+
	'formula for f^{-1}(x).\nl\nl '+
	'(f^{-1}\circ f)(x) = (f\circ f^{-1})(x) = x ';
  m:=n-v.b;
  answer :=fraction(m,'/',v.a);
  solution::='\nl\red{Solution:}\nl '+ 
    'g(x) = '+makeformula('ax+b',['a','b'],v)+nl+#10+
    makeformula('ax+b',['a','b'],v)+' = '+st(n)+nl+#10
    +'x = '+answer+nl+#10+'Therefore g'#30'-1'#31'('+st(n)+') = '+
    answer+'.';
  type := 'R';
  key := 4077;
end;

procedure s4077;
begin
  if sameconstants(answer,response) then begin
    result := 'T';
    message::='\green{Correct}';
  end else begin
    result := 'F';
    replace(prompt,'',response);
    if response = '' then message:=text1+#13+#13+#140'Incorrect'#140+#13+text3
    else message:=text1+#13+response+' is '#140'incorrect'#140'. '+#13+#13+text3;
  end;
end;

procedure p4079;
var
  a,b,c,d,e,f,k:integer;
  v:valuetype;
  ans,funct,u,z,w:string;
begin
  b:=rand([1,5])-3;v.b:=b;
  d:=rand([-4,4]);v.d:=d;
    c:=rand([3,4,5]);v.c:=c;
    str(ln(c):3:2,w);
    str(ln(c+.1):8:6,u);
    str(ln(c-1):3:2,z);
    funct:=makeformula('{e^(x)-c}',['c'],v);
    text1:='Determine the domain of the function f(x) = '+funct+nl+
    'Express your answer as a collection of intervals separated by commas.'+nl;
    help::='Expressions inside square root signs must be \ge  0.\nl '+
	'Division by zero is not allowed.';
    text3::=text1+'\nl\blue{Hint:}\nl '+
	'The expression within the radical must be \ge  0.';
    prompt::=#133'Domain: '#134;
    ans:='['+makeformula('ln(c)',['c'],v)+',\inf)';
    answer::=ans;
    solution::='\nl\red{Solution:}\nl '+
      #127'500,500,1200,0;A,250,100,50;B,2;G,'+makeformula('exp(x)',[],v)+',-5,5;'+
      'D,0,'+st(c)+','+w+','+st(c)+',3;L,'+w+',0,'+w+','+st(c)+';'+
      'B,0;C,'+z+',-.8,ln('+st(c)+');C,-.5,'+st(c)+','+st(c)+';'+
      'B,4;C,-4,7,y = e^x;'#127+
      'Thus e'#30'x'#31' - '+st(c)+' \ge  0'+nl+
      ' => e'#30'x'#31' \ge  '+st(c)+'.'+#10+nl+
      'Now e'#30'x'#31' = '+st(c)+' when '+nl+
      'x = ln('+st(c)+').'+#10+nl+
      'From the graph we see that e'#30'x'#31' \ge  '+st(c)+' when '+
      'x \ge  ln('+st(c)+').'+nl+
      'Thus the domain of f(x) = '+funct+' is '+ans+'.';
  type:='R';
  key := 4079;
end;

procedure s4079;
begin
  replace(prompt,'',response);
  if sameintervals(answer,response) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect.'#140+#13+text3
    else message:=response+' is '+#140'incorrect'#140+'. '#13+text3;
  end;
end;

procedure p4080;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text,w:string;
begin
  x.a:=rand([-3,-2,-1,2,3,4]);
  x.b:=rand([-8,-7,6,9,12]);
  x.c:=rand([7,15,18,24,30]);
  text:='Solve the equation $$e^{\a x+\b}=\c$$ for x.';
  text1::=text+#13;
  prompt::=#133'x = '#134;
  help::='\red{Inverse Identities for Logs and Exponentials:}\nl '+
	'$$e^{ln(x)}=x$$\nl '+
	'$$ln(e^{x})=x$$';
  text3::=text+nl+'\nl\blue{Hint:}\nl '+
	'Take natural logs of both sides of the equation and use one of '+
	'the inverse identities for logs and exponentials.';
  ans:='$${ln(\c)-\b\over \a}$$';
  answer::=ans;
  str((ln(x.c)-x.b)/x.a:6:4,w);
  solution::='\nl\red{Solution:}\nl '+
	'$$e^{\a x+\b}=\c$$\nl '+
	'=> $$ln(e^{\a x+\b})=ln(\c)$$\pause\nl '+
	'=> $$\a x+\b=ln(\c)$$ (by the inverse identity for logs and '+
	'exponentials)\pause\nl '+
	'=> x = '+ans+' \doteq  '+w+'.';
  type:='R';
  key:=4080;
end;

procedure s4080;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect.'#140+#13+text3
    else message:=response+' is '+#140'incorrect'#140+'. '#13+text3;
  end;
end;

procedure p4083;
var
  vals:valuetype;
  t,s:integer;
  w:string;
begin
  t := randint(1,2);
  case t of
  1:begin
      vals.a := randint(2,6);
      vals.b := randint(-6,6);
      vals.c := randint(2,4);
      text1 := 'Solve  '+makeformula('log'#31'a'#30'(x-b)=c',['a','b','c'],vals)+
	'  for x.'+nl;
      prompt::=#133'x = '#134;
      help::='\red{Properties of Logarithms:}\nl '+
	'$$log_a(xy)=log_ax+log_ay$$\nl '+
	'$$log_a({x\over y})=log_ax-log_ay$$\nl '+
	'$$log_a(x^r)=r\cdot log_ax$$';
      text3::=text1+'\nl\blue{Hint:}\nl '+
	'Use the fact that log'+#31'a'#30+'z = y <=> a'+#30'y'#31+' = z.';
      answer := st(round(exp(vals.c*ln(vals.a))+vals.b));
      solution::='\nl\red{Solution:}\nl '+
	makeformula('log'#31'a'#30'(x-b)=c',['a','b','c'],vals)+
	' <=> '+makeformula('a^c=x-b',['a'..'c'],vals)+'.'+nl+#10+
	'Thus x = '+answer+'.';
    end;
  2:begin
      vals.a := randint(2,9);
      vals.b := randint(2,8);
      vals.c := rand([0..9,11..20]) - 10;
      repeat vals.d := rand([1..9]) until gcd(vals.c,vals.d) = 1;
      text1 := 'Solve  log'#31+st(vals.a)+#30+st(vals.b)+' = '+
	fraction(vals.c,'-',vals.d)+
	'log'#31+st(vals.a)+#30'x   for x.'+nl;
      text3::=text1+'\nl\blue{Hint:}\nl '+
	'Bring '+fraction(vals.c,'/',vals.d)+' inside the logarithm '+
	'and then use the fact that\nl log'#31'a'#30'z = log'#31'a'#30'w <=> '+
	'z = w.';
      help::='\red{Properties of Logarithms:}\nl '+
	'$$log_a(xy)=log_ax+log_ay$$\nl '+
	'$$log_a({x\over y})=log_ax-log_ay$$\nl '+
	'$$log_a(x^r)=r\cdot log_ax$$';
      prompt::=#133'x = '#134;  
      answer := st(vals.b)+#30+fraction(vals.d,'/',vals.c)+#31;
      str(exp(vals.d*ln(vals.b)/vals.c):6:4,w);
      solution::='\nl\red{Solution:}\nl '+
	'log'#31+st(vals.a)+#30+st(vals.b)+' = '+fraction(vals.c,'-',vals.d)+
	'log'#31+st(vals.a)+#30'x = '+makeformula('log'#31'a'#30'x^(c/d)',['a'..'d'],vals)+
	'.'+#10+nl+'Thus '+makeformula('b=x^(c/d)',['a'..'d'],vals)+nl+#10+
	'=> x = '+answer+' \doteq  '+w+'.';
    end;
  end;
  key := 4083;
  type := 'R';
end;

procedure s4083;
var
res:string;
begin
res:=response;
replace(prompt,'',res);
  if sameconstants(answer,res) then begin
    result := 'T';
    message::= '\green{Correct}';
  end else begin
    result := 'F';
    if res = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := res+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4084;  {old 1078}
var
  d,i:integer;
  v:valuetype;
  x:paramtype;
  f,ff,df:string;
begin
  v.a := randint(2,10);x.a:=v.a;
  v.b := randint(2,10);x.b:=v.b;
  v.c := randint(1,5) + v.a;x.c:=v.c;
  v.d := v.a*v.b; v.e := v.c - v.a;x.e:=v.e;x.g:=v.d;
  d := randint(2,9);
  df := #31+st(d)+#30;x.d:=d;
  f := makeformula('log'+df+'(cx)-log'+df+'(x+b)=log'+df+'(a)',['a'..'c'],v);
  answer := fraction(v.a*v.b,'-',v.c-v.a);
  text1 := 'Find all solutions to the equation'+nl+f+nl;
  text3 ::=text1+'\nl\blue{Hint:}\nl '+ 
	'Use the properties of logarithms to combine the terms involving x. '+
	'Then use the fact that log_a(u) = log_a(v) => u = v.';
  help::='\red{Properties of Logarithms:}\nl '+
	'$$log_a(xy)=log_ax+log_ay$$\nl '+
	'$$log_a({x\over y})=log_ax-log_ay$$\nl '+
	'$$log_a(x^r)=r\cdot log_ax$$\nl '+
	'$$log_a(x)=log_a(y)$$ => x = y.';
  prompt::=#133'x = '#134;
  solution ::='\nl\red{Solution:}\nl '+
	f+nl+#10+
	'=> $$log_{\d}({\c x\over x+\b})=log_{\d}(\a)$$\nl '+
	'=> $${\c x\over x+\b}=\a$$\nl '+
	'=> $$\c x=(x+\b)(\a)$$\pause\nl '+
	'=> $$\e x=\g$$';
  if x.e<>1.0 then solution:=solution+nl+
	'=> x = '+answer+'.'
  else solution:=solution+'.';
  key := 4084;
  type := 'R';
end;

procedure s4084;       
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4087;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text,insrt:string;
begin
  x.a:=rand([-8..-2,2..8]);
  x.b:=rand([9..15]);
  x.c:=-x.a-x.b;
  x.d:=x.a*x.b;
  text:='Find all solutions of the equation $$e^{2x}+\c e^{x}+\d=0$$.\nl '+
	'Separate multiple answers by commas.\nl ';
  text1::=text;
  prompt::=#133'x = '#134;
  help::='\red{Quadratic Formula:}\nl '+
	'Roots of $$ax^2+bx+c$$:\nl '+
	'$$x={-b\pm\sqrt{b^2-4ac}\over 2a}$$\nl\nl '+
	'\red{Inverse Identities:}\nl '+
	'$$e^{ln(x)}=x$$\nl '+
	'$$ln(e^{x})=x$$';
  text3::=text+'\nl\blue{Hint:}\nl '+
	'This is a quadratic in the variable e^{x}. Solve the quadratic for '+
	'e^x and then solve for x.';
  if x.a < 0.0 then begin 
    ans:='ln(\b)';
    insrt:='Since e^x > 0 for all x the only possibility is e^x = \b  or '+
	'x = '+ans+'.';
  end else begin
    ans:='ln(\a),ln(\b)';
    buff1::='(ln(\a),ln(\b))';
    insrt:='Thus the solution is x = '+ans+'.';
  end;
  answer::=ans;
  solution::='\nl\red{Solution:}\nl '+
	'$$e^{2x}+\c e^{x}+\d=0$$\nl '+
	'=> $$(e^x-\a)(e^x-\b)=0$$\pause\nl '+
	'=> e^x = \a  or e^x = \b.\pause\nl '+
	insrt;
  type:='R';                                               
  key:=4087;
end;

procedure s4087;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) or (samepoints(buff1,response) and
  (buff1 <> ''))then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4091;
var
  a,b,c,d,e,f,i,j,k,g,h:integer;
  v:valuetype;
  err:boolean;
  sgn:string;
begin
  a:=rand([-2,-1,1,2]);
  b:=randint(2,6);
  c:=randint(1,4);
  d:=b*b;
  f:=2*a;
  g:=2*b;
  v.a:=a;
  v.b:=b;
  v.c:=c;
  v.d:=d;v.f:=f;v.g:=g;
  e := round(b^c);
  v.e:=e;
  case randint(1,2) of
  1:begin
    a:=rand([1,2,6,7])-4;v.a:=a;
    d:=b*b*b;v.d:=d;
    e:=3*b*b*c;v.e:=e;
    f:=3*b*c*c;v.f:=f;
    g:=c*c*c;v.g:=g;
    h:=b*b;v.h:=h;
    i:=2*b*c;v.i:=i;
    j:=c*c;v.j:=j;
    text1:='Express f(x) = '+st(b)+#30#30+st(a)+'log'#31+st(b)+#30'('+
      makeformula('bx+c',['b','c'],v)+')'#31#31+' without using logarithms.'+nl;
    text3::=text1+#13+'\nl\blue{Hint:}\nl '+
      'Use properties of logarithms to '+
      'write the exponent as a single logarithm and then use the '+
      'identity b'#30#30'log'#31'b'#30'(x)'#31#31' = x.';
    help::='\red{Properties of Logarithms:}\nl '+
	'$$log_a(xy)=log_ax+log_ay$$\nl '+
	'$$log_a({x\over y})=log_ax-log_ay$$\nl '+
	'$$log_a(x^r)=r\cdot log_ax$$';
    prompt::=#133'f(x) = '#134;
    if a = -3 then
    answer:=makeformula('[1]/[(dx^3+ex^2+fx+g)]',['f','g','e','d'],v);
    if a = -2 then
    answer:=makeformula('[1]/[(hx^2+ix+j)]',['h','i','j'],v);
    if a = 2 then
    answer:=makeformula('hx^2+ix+j',['h','i','j'],v);
    if a = 3 then
    answer:=makeformula('dx^3+ex^2+fx+g',['f','g','e','d'],v);
    solution::='\nl\red{Solution:}\nl '+
      st(b)+#30#30+st(a)+'log'#31+st(b)+#30'('+makeformula('bx+c',['b','c'],v)+')'#31#31+nl+
      ' = '+st(b)+#30#30'log'#31+st(b)+#30'('+makeformula('(bx+c)^a',['a'..'c'],v)+')'#31#31#10+nl+
      ' = '+makeformula('(bx+c)^a',['a'..'c'],v)+#10+nl+
      ' = '+answer+'.';
    text6:='1';
  end;
  2:begin
    a:=rand([1,7])-4;v.a:=a;   {-3,3}
    c:=rand([1,5])-3;v.c:=c;   {-2,2}
    if c>0 then
    text1:='Express f(x) = '+st(b)+#30#30+st(a)+'log'#31+st(b)+#30'(x)'+
      ' + '+st(c)+'log'#31+st(b)+#30'(x+1)'+#31#31' without using logarithms.'+nl;
    if c<0 then
    text1:='Express '+st(b)+#30#30+st(a)+'log'#31+st(b)+#30'(x)'+
      st(c)+'log'#31+st(b)+#30'(x+1)'+#31#31' without using logarithms.'+nl;
    text3::=text1+#13+'\nl\blue{Hint:}\nl '+
      'Use properties of logarithms to '+
      'write the exponent as a single logarithm and then use the '+
      'identity b'#30#30'log'#31'b'#30'(x)'#31#31' = x.';
    prompt::=#133'f(x) = '#134;
    if a = 3 then
      if c = 2 then
	answer:=makeformula('x^5+2x^4+x^3',[],v)
      else
	answer:=makeformula('[x^3]/[(x^2+2x+1)]',[],v);
    if a = -3 then
      if c = 2 then
	answer:=makeformula('[(x^2+2x+1)]/[x^3]',[],v)
      else
	answer:=makeformula('[1]/[(x^5+2x^4+x^3)]',[],v);
    if c>0 then solution::='\nl\red{Solution:}\nl '+
      st(b)+#30#30+st(a)+'log'#31+st(b)+#30'(x) + '+st(c)+'log'#31+st(b)+#30'(x+1)'+#31#31+nl+
      ' = '+st(b)+#30#30'log'#31+st(b)+#30'(x'#30+st(a)+#31') + log'#31+st(b)+#30'((x+1)'#30+st(c)+#31')'#31#31#10+nl+
      ' = '+st(b)+#30#30'log'#31+st(b)+#30+makeformula('((x^a)((x+1)^c))',['a','c'],v)+#31#31#10+nl+
      ' = '+makeformula('x^a(x+1)^c',['a','c'],v)+#10+nl+
      ' = '+answer+'.';
    if c<0 then solution::='\nl\red{Solution:}\nl '+
      st(b)+#30#30+st(a)+'log'#31+st(b)+#30'(x) - '+st(-c)+'log'#31+st(b)+#30'(x+1)'+#31#31+nl+
      ' = '+st(b)+#30#30'(log'#31+st(b)+#30'(x'#30+st(a)+#31') + log'#31+st(b)+#30'((x+1)'#30+st(c)+#31'))'#31#31#10+nl+
      ' = '+st(b)+#30#30'log'#31+st(b)+#30+makeformula('((x^a)((x+1)^c))',['a','c'],v)+#31#31#10+nl+
      ' = '+makeformula('x^a(x+1)^c',['a','c'],v)+#10+nl+
      ' = '+answer+'.';
    text6:='1';
  end;
  end; {case}
  help::='\red{Properties of Logarithms:}\nl '+
      '\ \ $$log_a(xy)=log_ax+log_ay$$\nl '+
      '\ \ $$log_a({x\over y})=log_ax-log_ay$$\nl '+
      '\ \ $$log_a(x^r)=r\cdot log_ax$$\nl '+
      '\red{Inverse Identities:}\nl '+
      '\ \ $$a^{log_a(x)}=x$$\nl '+
      '\ \ $$log_a(a^{x})=x$$';
  type:='R';
  key := 4091;
end;

procedure s4091;
var
  answer1:string;
  correct:boolean;
begin
  replace(prompt,'',response);
  if text6 = '' then
    correct := sameconstants(answer,response)
  else begin
    answer1:=response;
    toupper(answer1);
    correct := pos('LOG',answer1) = -1;
    correct := (pos('LN',answer1) = -1) and correct;
    correct := sameexpres(answer,response) and correct;
  end;
  if correct then begin
    result :='T';
    message::='\green{Correct}';
  end
  else begin
    result :='F';
    if response = '' then message:=#140'Incorrect'#140#13+text3
    else
    message:=response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4092;
var
  a,b,c,d,e,f,i,j,k,g,h:integer;
  v:valuetype;
  err:boolean;
  sgn:string;
begin
  a:=rand([-2,-1,1,2]);
  b:=randint(2,6);
  c:=randint(1,4);
  d:=b*b;
  f:=2*a;
  g:=2*b;
  v.a:=a;
  v.b:=b;
  v.c:=c;
  v.d:=d;v.f:=f;v.g:=g;
  e := round(b^c);
  v.e:=e;
  case randint(1,2) of
  1:begin
    a:=rand([1,2,6,7])-4;v.a:=a;
    d:=randint(4,8);v.d:=d;
    e:=rand([1,2,4,5,6])-3;v.e:=e;
    f:=3*a+2*d;v.f:=f;
    j:=3*c+2*e;v.j:=j;
    h:=b*b*b;v.h:=h;
    i:=b*b;v.i:=i;
    if e>0 then
    text1:='Express f(x) = log'#31+st(b)+#30'[('+st(h)+')'+#30+
      st(a)+'x+'+st(c)+#31'('+st(i)+')'+#30+st(d)+'x+'+st(e)+#31+']'+
      ' without using logarithms.'+nl;
    if e<0 then
    text1:='Express log'#31+st(b)+#30'[('+st(h)+')'+#30+
      +st(a)+'x+'+st(c)+#31'('+st(i)+')'+#30+st(d)+'x'+st(e)+#31+']'+
      ' without using logarithms.'+nl;
    text3::=text1+#13+'\nl\blue{Hint:}\nl '+'Use the identity '+
      'log'#31'b'#30'(b'#30'x'#31') = x and properties '+
      'of exponents.';
    prompt::=#133'f(x) = '#134;
    answer:=makeformula('fx+j',['f','j'],v);
    solution::='\nl\red{Solution:}\nl '+
      makeformula('log'#31+st(b)+#30'(h^((ax+c))i^((dx+e)))',['a'..'e','h','i'],v)+#10+nl+
      ' = '+makeformula('log'#31+st(b)+#30'((b^3)^(ax+c)(b^2)^(dx+e))',['a'..'e','h','i'],v)+#10+nl+
      ' = '+makeformula('log'#31+st(b)+#30'(b^(3(ax+c))b^(2(dx+e)))',['a'..'e','h','i'],v)+#10+nl+
      ' = '+makeformula('log'#31+st(b)+#30'(b^('+st(3*a)+'x+'+st(3*c)+')b^('+st(2*d)+'x+'+st(2*e)+'))',['a'..'e','h','i'],v)+#10+nl+
      ' = '+makeformula('log'#31+st(b)+#30'(b^('+st(3*a)+'x+'+st(3*c)+'+'+st(2*d)+'x+'+st(2*e)+'))',['b'],v)+#10+nl+
      ' = '+makeformula('log'#31+st(b)+#30'(b^(fx+j))',['b','f','j'],v)+#10+nl+
      ' = '+answer+'.';
    text6:='1';
  end;
  2:begin
    a:=rand([1,2,6,7])-4;v.a:=a;
    d:=randint(4,8);v.d:=d;
    e:=randint(1,6);v.e:=e;
    v.m:=2*a;v.p:=2*v.c;v.q:=3*v.e;
    h:=3*d;v.h:=h;
    i:=2*c-3*e;v.i:=i;
    j:=b*b;v.j:=j;
    k:=b*j;v.k:=k;
    text1:='Express f(x) = log'#31+st(b)+#30+
      makeformula('([j^(ax^2+c)]/[k^(dx+e)])',['a','c','d','e','j','k'],v)+
      ' without'+nl+nl+'using logarithms.'+nl;
    text3::=text1+#13+'\nl\blue{Hint:}\nl '+'Use the identity log'#31'b'#30'(b'#30'x'#31') = x and properties '+
      'of exponents.';
    prompt::=#133'f(x) = '#134;
    answer:=makeformula('mx^2-hx+i',['m','h','i'],v);
    solution::='\nl\red{Solution:}\nl '+
      makeformula('log'#31+st(b)+#30'([j^(ax^2+c)]/[k^(dx+e)])',['a','c','d','e','j','k'],v)+#10+
      ' = '+makeformula('log'#31+st(b)+#30'([(b^2)^(ax^2+c)]/[(b^3)^(dx+e)])',['a','b','c','d','e','j','k'],v)+#10+nl+
      ' = '+makeformula('log'#31+st(b)+#30'([b^(mx^2+p)]/[b^(hx+q)])',['b','h','m','p','q'],v)+#10+nl+
      ' = '+makeformula('log'#31+st(b)+#30'(b^((mx^2+p)-(hx+q))',['b','h','m','p','q'],v)+#10+nl+
      ' = '+makeformula('log'#31+st(b)+#30'(b^(mx^2-hx+i)',['b','h','i','m'],v)+#10+nl+
      ' = '+answer+'.';
    text6:='1';
  end;
  end; {case}
  help::='\red{Properties of Exponents:}\nl '+
      '\ \ $$a^{x+y}=a^{x}a^{y}$$\nl '+
      '\ \ $$a^{x-y}={a^{x}\over a^{y}}$$\nl '+
      '\ \ $$(a^{x})^{y}=a^{xy}$$\nl\nl '+
      '\red{Properties of Logarithms:}\nl '+
      '\ \ $$log_a(xy)=log_ax+log_ay$$\nl '+
      '\ \ $$log_a({x\over y})=log_ax-log_ay$$\nl '+
      '\ \ $$log_a(x^r)=r\cdot log_ax$$\nl '+
      '\red{Inverse Identities:}\nl\nl '+
      '\ \ $$a^{log_a(x)}=x$$\ \ '+
      '\ \ $$log_a(a^{x})=x$$';
  type:='R';
  key := 4092;
end;

procedure s4092;
var
  answer1:string;
  correct:boolean;
begin
  replace(prompt,'',response);
  if text6 = '' then
    correct := sameconstants(answer,response)
  else begin
    answer1:=response;
    toupper(answer1);
    correct := pos('LOG',answer1) = -1;
    correct := (pos('LN',answer1) = -1) and correct;
    correct := sameexpres(answer,response) and correct;
  end;
  if correct then begin
    result :='T';
    message::='\green{Correct}';
  end
  else begin
    result :='F';
    if response = '' then message:=#140'Incorrect'#140#13+text3
    else
    message:=response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4095;
var
  a,b,c,d,e,f,g,h,j,k,m:integer;
  v:valuetype;
  fctn:array[1..3] of string;
  ans,sol:array[1..3,2..3] of string;
begin
  a:=randint(2,4);v.a:=a;
  b:=randint(2,4);v.b:=b;
  c:=rand([2,3]);v.c:=c;
  d:=a*b;
  f:=b*b;
  g:=2;
  j:=1;
  repeat
    g:=2*g;
    j:=j+1;
  until j=b;v.p:=g; {g=2**b}
  h:=2;
  m:=1;
  repeat
    h:=2*h;
    m:=m+1;
  until m=c*b;v.h:=h; {h=2**bc}
  k:=randint(1,3);
  fctn[1]:='log(x'+#30'2'#31+' - 16) - '+st(c)+'log(x + 4) + '+st(b)+
    'log(2)';
  fctn[2]:='log(x'+#30'2'#31+' + 16) - '+st(c)+'[log(x - 4) + '+st(b)+
    'log(2)]';
  fctn[3]:='log('+st(a)+') + '+st(c)+'[log(1 + x) - 2log(1 - x)]';
  text1:='Write the expression '+nl+'     '+fctn[k]+nl+'as a '+
    'single logarithm with a coefficient of 1.'+nl;
  text3::=text1+#13+'\nl\blue{Hint:}\nl '+
    'Use the fundamental properties of logarithms:'+nl+
    'log(uv) = log(u) + log(v)'+nl+'log(u/v) = log(u) - log(v)'+nl+
    'rlog(u) = log(u'#30'r'#31').';
  prompt::=#133+fctn[k]+' = '#134;
  help::='\red{Properties of Logarithms:}\nl '+
	'\ \ $$log_a(xy)=log_ax+log_ay$$\nl '+
	'\ \ $$log_a({x\over y})=log_ax-log_ay$$\nl '+
	'\ \ $$log_a(x^r)=r\cdot log_ax$$\nl '+nl+nl+
	'\red{Properties of Exponents:}\nl '+
	'\ \ $$a^{x+y}=a^{x}a^{y}$$\nl '+
	'\ \ $$a^{x-y}={a^{x}\over a^{y}}$$\nl '+
	'\ \ $$(a^{x})^{y}=a^{xy}$$';
  ans[1,2]:='log('+#29#219+st(g)+'(x - 4)'+#221'/'#219+'(x + 4)'+#221+')';
  sol[1,2]:=fctn[1]+nl+
	    ' = '+makeformula('log(x^2-16)-log((x+4)^2)+log(2^b)',['b'],v)+#10+nl+
	    ' = '+makeformula('log([x^2-16]/[(x+4)^2])+log(p)',['p'],v)+#10+nl+
	    ' = '+makeformula('log([p(x^2-16)]/[(x+4)^2]',['p'],v)+#10+nl+
	    ' = '+makeformula('log([p(x-4)(x+4)]/[(x+4)^2]',['p'],v)+#10+nl+
	    ' = '+ans[1,2]+'.';
  ans[1,3]:='log('+#29#219+st(g)+'(x - 4)'+#221'/'#219+'(x + 4)'+#30'2'+
    #31#221+')';
  sol[1,3]:=fctn[1]+nl+
	    '   = '+makeformula('log(x^2-16)-log((x+4)^3)+log(2^b)',['b'],v)+#10+nl+
	    '   = '+makeformula('log([x^2-16]/[(x+4)^3])+log(p)',['p'],v)+#10+nl+
	    '   = '+makeformula('log([p(x^2-16)]/[(x+4)^3]',['p'],v)+#10+nl+
	    '   = '+makeformula('log([p(x-4)(x+4)]/[(x+4)^3]',['p'],v)+#10+nl+
	    '   = '+ans[1,3]+'.';
  ans[2,2]:='log('#29#219+'x'+#30'2'#31+' + 16'#221'/'#219+st(h)+'(x - 4)'+
    #30'2'#31#221+')';
  sol[2,2]:=fctn[2]+nl+
	    '   = '+makeformula('log(x^2+16)-log((x-4)^2)-'+st(2*b)+'log(2)',['b'],v)+#10+nl+
	    '   = '+makeformula('log([x^2+16]/[(x-4)^2])-log(h)',['h'],v)+#10+nl+
	    '   = '+ans[2,2]+'.';
  ans[2,3]:='log('#29#219+'x'+#30'2'#31+' + 16'#221'/'#219+
    st(h)+'(x - 4)'+#30'3'#31#221+')';
  sol[2,3]:=fctn[2]+nl+
	    '   = '+makeformula('log(x^2+16)-log((x-4)^3)-'+st(3*b)+'log(2)',['b'],v)+#10+nl+
	    '   = '+makeformula('log([x^2+16]/[(x-4)^3])-log(h)',['h'],v)+#10+nl+
	    '   = '+ans[2,3]+'.';
  ans[3,2]:='log('#29#219+st(a)+'(1 + x)'+#30'2'#31#221'/'#219+'(1 - x)'+
    #30'4'#31#221+')';
  sol[3,2]:=fctn[3]+nl+
	    '   = '+makeformula('log(a)+clog(1+x)-'+st(2*c)+'log(1-x)',['a','c'],v)+#10+nl+
	    '   = '+makeformula('log(a)+log((1+x)^c)-log((1-x)^('+st(2*c)+')',['a','c'],v)+#10+nl+
	    '   = '+makeformula('log(a(1+x)^c)-log((1-x)^('+st(2*c)+')',['a','c'],v)+#10+nl+
	    '   = '+ans[3,2]+'.';
  ans[3,3]:='log('#29#219+st(a)+'(1 + x)'+#30'3'#31#221+
	    '/'#219+'(1 - x)'+#30'6'#31#221+')';
  sol[3,3]:=fctn[3]+nl+
	    '   = '+makeformula('log(a)+clog(1+x)-'+st(2*c)+'log(1-x)',['a','c'],v)+#10+nl+
	    '   = '+makeformula('log(a)+log((1+x)^c)-log((1-x)^('+st(2*c)+')',['a','c'],v)+#10+nl+
	    '   = '+makeformula('log(a(1+x)^c)-log((1-x)^('+st(2*c)+')',['a','c'],v)+#10+nl+
	    '   = '+ans[3,3]+'.';
  answer:=ans[k,c];
  solution::='\nl\red{Solution:}\nl '+sol[k,c];
  type:='R';
  key := 4095;
end;

procedure s4095;
var
  resp:string;
  check1,check2,check3:boolean;
begin
  check1:= false;
  check2:=false;
  check3:=false;
  replace(prompt,'',response);
  resp:=response;
  clean(resp); toupper(resp);
  if pos('1',resp)=0 then
  delete(resp,0,1);
  if (pos('LN',resp) =0) or (pos('LOG',resp)=0) then check3:=true;
  if pos('LN',resp)>-1 then
    begin
      delete(resp,pos('LN',resp),2);
      if pos('LN',resp)>-1 then result:='F'
      else check1:=true
    end;
  if pos('LOG',resp)>-1 then
    begin
      delete(resp,pos('LOG',resp),3);
      if pos('LOG',resp)>-1 then result:='F'
      else check2:=true;
    end;
  if result = 'F' then
      if response = '' then message:=#140'Incorrect'#140#13+text3
      else message:=response+' is '#140'incorrect'#140'. '+text3;
  if (check3 and (check1 or check2)) or (answer = 'ln(1)')
    or (answer = 'log(1)') or (response = '') or
    ((pos('LN',resp)=-1) and (pos('LOG',resp)=-1)) then begin
    if sameexpres(answer,response) then begin
      result := 'T';
      message:=#141'Correct'#141;
      end
    else begin
      result := 'F';
      if response = '' then message:=#140'Incorrect'#140#13+text3
      else message:=response+' is '#140'incorrect'#140'. '+#13+text3;
    end;
  end;
end;

procedure p4097;
var
v:valuetype;
a,b,j,k:integer;
header:string;
eqt,ans,sol:array[1..10] of string;
mat:array[1..10] of integer;
begin
  v.a:=rand([2,3,6,7]);
  v.b:=rand([4,5,8]);
  v.c:=v.a*v.b;
  v.d:=v.c*v.c;
  for k:=1 to 8 do mat[k]:=k;
  permute(mat,8);
  header:='\red{Answer Y or N for each question.}'#13#13;
  text1::=header+'Determine whether each of the following are valid for all '+
    'x and y assuming all terms make sense.';
  eqt[1]:=makeformula('a^x+a^y=a^(xy)',['a'],v);ans[1]:='N';
  eqt[2]:=makeformula('a^xa^y=a^(x+y)',['a'],v);ans[2]:='Y';
  eqt[3]:=makeformula('a^x-a^y=a^(x/y)',['a'],v);ans[3]:='N';
  eqt[4]:=makeformula('[a^x]/[a^y]=a^(x-y)',['a'],v);ans[4]:='Y';
  eqt[5]:=makeformula('(a^x)^y=a^(x+y)',['a'],v);ans[5]:='N';
  eqt[6]:=makeformula('(a^x)^y=a^(xy)',['a'],v);ans[6]:='Y';
  eqt[7]:=makeformula('(e^x)^2=e^((x^2))',[],v);ans[7]:='N';
  eqt[8]:=makeformula('e^(-x)=-e^x',[],v);ans[8]:='N';
  eqt[9]:=makeformula('a^(-x)=[1]/[a^x]',['a'],v);ans[9]:='Y';
  eqt[10]:=makeformula('a^xb^x=c^(2x)',['a','b','c'],v);ans[10]:='N';
  text2::=eqt[mat[1]];
  text3::=eqt[mat[2]];
  text4::=eqt[mat[3]];
  text5::=eqt[mat[4]];
  text6::=eqt[mat[5]];
  buff3::='Use the fundamental properties of logarithms.';
  help::='\red{Properties of Logarithms:}\nl '+
	'\ \ $$log_a(xy)=log_ax+log_ay$$\nl '+
	'\ \ $$log_a({x\over y})=log_ax-log_ay$$\nl '+
	'\ \ $$log_a(x^r)=r\cdot log_ax$$\nl '+
	'\ \ $$log_a(1)=0$$\ \ \ $$log_a(a)=1$$\nl '+nl+nl+
	'\red{Properties of Exponents:}\nl '+
	'\ \ $$a^{x+y}=a^{x}a^{y}$$\nl '+
	'\ \ $$a^{x-y}={a^{x}\over a^{y}}$$\nl '+
	'\ \ $$(a^{x})^{y}=a^{xy}$$\nl '+
	'\ \ a^{0} = 1\ \ \ $$a^{1}=a$$';
  sol[1]:=eqt[1]+' fails. Letting both x and y equal 0, the formula would '+
    'give 2 = 1.';
  sol[2]:=eqt[2]+' holds. This is one of the fundamental properties of '+
    'exponential functions.';
  sol[3]:=eqt[3]+' fails. If x = 0 and y = 1, the formula would give '+
    st(1-v.a)+' = 1.';
  sol[4]:=eqt[4]+' holds. This is one of the fundamental properties of '+
    'exponential functions.';
  sol[5]:=eqt[5]+' fails. If x = 1 and y = 1, the formula would give  '+
    st(v.a)+' = '+st(v.a*v.a)+'.';
  sol[6]:=eqt[6]+' holds. This is one of the fundamental properties of '+
    'exponential functions.';
  sol[7]:=eqt[7]+' fails. If x = 1, the equation would give '+
    makeformula('e^2=e',[],v)+'.';
  sol[8]:=eqt[8]+' fails. If x = 0, the equation would give 1 = -1.';
  sol[9]:=eqt[9]+' holds. This is one of the fundamental properties of '+
    'exponential functions.';
  sol[10]:=eqt[10]+' fails. If x = 1, the equation would give '+
    makeformula('c=d',['c','d'],v)+'.';
  answer:=ans[mat[1]]+ans[mat[2]]+ans[mat[3]]+ans[mat[4]]+ans[mat[5]];
  solution::='\red{Solution:}'+
	'\nl\nl\red{Choice 1}'+nl+'You got this one \green{right}.'+nl+sol[mat[1]]+nl+nl;
  solution2::='\red{Choice 2}'+nl+'You got this one \green{right}.'+nl+sol[mat[2]]+nl+nl;
  solution3::='\red{Choice 3}'+nl+'You got this one \green{right}.'+nl+sol[mat[3]]+nl+nl;
  solution4::='\red{Choice 4}'+nl+'You got this one \green{right}.'+nl+sol[mat[4]]+nl+nl;
  solution5::='\red{Choice 5}'+nl+'You got this one \green{right}.'+nl+sol[mat[5]]+nl+nl;
  type:='S';
  key:=4097;
end;

procedure s4097;
var
  j,n:integer;
  res,w,z:string;
begin
  z:='';
  n := 10;
  for j:=1 to 5 do begin
    if answer[j-1] <> response[j-1] then begin
      z:=z+st(j)+',';
      n := n - 2;
    end;
  end;
  result := chr(48+n);
  if response='     ' then message:=#140'Incorrect'#140#13#142'Message:'#142+buff3
  else begin
    if answer=response then begin
      message:=#141'Correct.'#141;
    end else begin
      w := '';
      if pos('1',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution) else
	 replace(#140'wrong'#140,#141'right'#141,solution);
      if pos('2',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution2) else
	 replace(#140'wrong'#140,#141'right'#141,solution2);
      if pos('3',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution3) else
	 replace(#140'wrong'#140,#141'right'#141,solution3);
      if pos('4',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution4) else
	 replace(#140'wrong'#140,#141'right'#141,solution4);
      if pos('5',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution5) else
	 replace(#140'wrong'#140,#141'right'#141,solution5);
      message:=response+' is '#140'incorrect'#140'.'+#13+
      #142'Message:'#142#13+buff3;
    end;
  end;
end;

procedure p4099;
var
  a,b,c,d,e,f,j,k:integer;
  p,q,r,s,t:real;
  v:valuetype;
  ans1,ans2,deg:string;
  functn,ans,sol:array[1..6] of string;
begin
  k:=randint(1,6);
  a:=rand([1,5,6])-3;v.a:=a;{-2,2,3}
  d:=1;b:=rand([4,3,5,7]);v.b:=b;v.d:=d;
  functn[1]:=makeformula('a+ln(bx)',['a','b'],v);
  functn[2]:=makeformula('a+bln(x)',['a','b'],v);
  functn[3]:=makeformula('[b]/[1+ln(x)]',['b'],v);
  functn[4]:=makeformula('ln(x-a)',['a'],v);
  functn[5]:=makeformula('a+ln(x-b)',['a','b'],v);
  functn[6]:=makeformula('ln([a]/[x+b])',['a','b'],v);
  text1:='Find a formula for f'#30'-1'#31'(x) if '+nl+
    '     f(x) = '+functn[k]+'.'+nl+
    'You may assume the given function is one-to-one.'+nl;
  text3::=text1+'\nl\blue{Hint:}\nl '+
    'Solve the equation y = f(x) for x in terms of y. Then interchange '+
    'x and y.';
  help::='\red{Inverse Functions:}\nl '+
    'A function must be one-to-one in order to have an inverse function.\nl '+
    'Given y = f(x), solving for x in terms of y gives the formula '+
	  'for f^{-1}(y). Interchange the variables x and y to get the '+
	  'formula for f^{-1}(x).\nl\nl '+
	  '(f^{-1}\circ f)(x) = (f\circ f^{-1})(x) = x';
  prompt::=#133'f^{-1}(x) = '#134;
  ans[1]:=makeformula('[e^((x-a))]/[b]',['a','b'],v);
  ans[2]:=makeformula('e^([x-a]/[b])',['a','b'],v);
  ans[3]:=makeformula('e^([b-x]/[x])',['b'],v);
  ans[4]:=makeformula('a+e^x',['a'],v);
  ans[5]:=makeformula('b+e^(x-a)',['a','b'],v);
  ans[6]:=makeformula('ae^(-x)-b',['a','b'],v);
  answer:=ans[k];
  sol[1]:=makeformula('y=a+ln(bx)',['a','b'],v)+nl+#10+
    ' => '+makeformula('y-a=ln(bx)',['a','b'],v)+nl+#10+
    ' => '+makeformula('e^((y-a))=bx',['a','b'],v)+nl+#10+
    ' => '+makeformula('x=[e^((y-a))]/[b]',['a','b'],v)+nl+#10+
    'Interchanging x and y we get '+nl+
    makeformula('f^(-1)(x)='+answer,[],v)+'.';
  sol[2]:=makeformula('y=a+bln(x)',['a','b'],v)+nl+#10+
    ' => '+makeformula('y-a=bln(x)',['a','b'],v)+nl+#10+
    ' => '+makeformula('[y-a]/[b]=ln(x)',['a','b'],v)+nl+#10+
    ' => '+makeformula('x=e^([y-a]/[b])',['a','b'],v)+nl+#10+
    'Interchanging x and y we get '+nl+
    makeformula('f^(-1)(x)='+answer,[],v)+'.';
  sol[3]:=makeformula('y=[b]/[1+ln(x)]',['b'],v)+nl+#10+
    ' => '+makeformula('[1]/[y]=[1+ln(x)]/[b]',['b'],v)+nl+#10+
    ' => '+makeformula('[b]/[y]=1+ln(x)',['b'],v)+nl+#10+
    ' => '+makeformula('[b]/[y]-1=ln(x)',['b'],v)+nl+#10+
    ' => '+makeformula('x=e^([b-y]/[y])',['b'],v)+nl+#10+
    'Interchanging x and y we get '+nl+
    makeformula('f^(-1)(x)='+answer,[],v)+'.';
  sol[4]:=makeformula('y=ln(x-a)',['a'],v)+nl+#10+
    ' => '+makeformula('e^y=x-a',['a'],v)+nl+#10+
    ' => '+makeformula('x=a+e^y',['a'],v)+nl+#10+
    'Interchanging x and y we get '+nl+
    makeformula('f^(-1)(x)='+answer,[],v)+'.';
  sol[5]:=makeformula('y=a+ln(x-b)',['a','b'],v)+nl+#10+
    ' => '+makeformula('y-a=ln(x-b)',['a','b'],v)+nl+#10+
    ' => '+makeformula('e^(y-a)=x-b',['a','b'],v)+nl+#10+
    ' => '+makeformula('x=b+e^(y-a)',['a','b'],v)+nl+#10+
    'Interchanging x and y we get '+nl+
    makeformula('f^(-1)(x)='+answer,[],v)+'.';
  sol[6]:=makeformula('y=ln([a]/[x+b])',['a','b'],v)+nl+#10+
    ' => '+makeformula('e^y=[a]/[x+b]',['a','b'],v)+nl+#10+
    ' => '+makeformula('e^(-y)=[x+b]/[a]',['a','b'],v)+nl+#10+
    ' => '+makeformula('ae^(-y)=x+b',['a','b'],v)+nl+#10+
    ' => '+makeformula('x=ae^(-y)-b',['a','b'],v)+nl+#10+
    'Interchanging x and y we get '+nl+
    makeformula('f^(-1)(x)='+answer,[],v)+'.';
  solution::='\nl\red{Solution:}\nl '+sol[k];
  type:='R';
  key := 4099;
end;

procedure s4099;             
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;
procedure p4102;
var
  v : valuetype;
  f:string;
begin
  repeat
    v.a:=randint(3,10); v.d:=randint(3,10)
  until (GCD(v.a,v.d)=1);
  v.b:=randint(1,9);
  v.c:=randint(-9,9);
  v.e:=randint(-9,-1);
  v.f:=randint(-9,9);
  f := makeformula('a^(bx+c)=d^(ex+f)',['a'..'f'],v);
  text1 := 'Solve the equation '+nl+'   '+f+nl;
  str( (v.f*ln(v.d)-v.c*ln(v.a))/(v.b*ln(v.a)-v.e*ln(v.d)),answer);
  text3::=text1+'\nl\blue{Hint:}\nl '+ 
    'Apply the natural logarithm function to both sides.';
  help::='\red{Properties of Logarithms:}\nl '+
      	'\ \ $$log_a(xy)=log_ax+log_ay$$\nl '+
	'\ \ $$log_a({x\over y})=log_ax-log_ay$$\nl '+
	'\ \ $$log_a(x^r)=r\cdot log_ax$$\nl '+nl+nl+
	'\red{Properties of Exponents:}\nl '+
        '\ \ $$a^{x+y}=a^{x}a^{y}$$\nl '+
        '\ \ $$a^{x-y}={a^{x}\over a^{y}}$$\nl '+
        '\ \ $$(a^{x})^{y}=a^{xy}$$';
  prompt::=#133'x = '#134;
  solution::='\nl\red{Solution:}\nl '+ 
    f+nl+#10+
    makeformula('ln(a^(bx+c))=ln(d^(ex+f))',['a'..'f'],v)+nl+#10+
    makeformula('(bx+c)lna=(ex+f)lnd',['a'..'f'],v)+nl+#10+
    makeformula('bxlna+clna=exlnd+flnd',['a'..'f'],v)+nl+#10+
    makeformula('(blna-elnd)x=flnd-clna',['a'..'f'],v)+nl+#10+
    makeformula('x=[flnd-clna]/[blna-elnd]',['a'..'f'],v)+nl+#10+
    '\doteq  '+answer;
  key := 4102;
  type := 'R';
end;

procedure s4102;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4104;
var
  x:paramtype;
  undef,notwff:boolean;
  period,ans,dgm,text,w:string;
  k:integer;
begin
  x.a:=rand([1..4]);
  x.a:=x.a*1000;
  x.b:=rand([2..5]);
  x.r:=rand([60,65,74,75,80,85]);
  x.s:=x.r/10;
  x.v:=x.r/1000;
  case randint(1,3) of
  1:begin
    period:='quarterly';
    x.p:=4;
    x.j:=4*x.b;
    end;
  2:begin
    period:='semi-annually';
    x.p:=2;
    x.j:=2*x.b;
    end;
  3:begin
    period:='monthly';
    x.p:=12;
    x.j:=12*x.b;
    end;
  end;{case}
  k:=round(x.j);
  text:='Suppose \$\a  is invested at a nominal rate of \s:1 % compounded '+
    period+'. Determine the value P of the investment after \b  years. Your '+
    'answer must be correct to the nearest cent.\nl ';
  text1::=text;
  prompt::=#133'P = '#134;
  help::='\red{Compound Interest Formula:}\nl '+
    '\ \ $$P=P_O(1+{r\over n})^{nt}$$\nl '+
    '\ \ P_O = initial investment\nl '+
    '\ \ r = nominal rate\nl '+
    '\ \ n = number of compoundings\nl '+
    '\ \ t = number of years';
  text3::=text+'\nl\blue{Hint:}\nl '+
    'Use the compound interest formula $$P=P_O(1+{r\over n})^{nt}$$.';
  str(x.a*(1+x.v/x.p)^k:8:6,w);
  x.w:=x.a*(1+x.v/x.p)^k;
  ans:='\$'+w;
  answer:=w;
  solution::='\nl\red{Solution:}\nl '+
    '$$P=P_O(1+{r\over n})^{nt}$$.\nl '+
    'Since interest is being compounded '+period+', nt = \p\cdot\b  = \j.\pause\nl '+
    'Thus the value of the investment is\nl '+
    '$$\a(1+{\v:3\over \p})^{\j}$$ \doteq  \$\w:2.';
  type:='R';
  key:=4104;
end;

procedure s4104;
var
  check1,undef,notwff:boolean;
  res:string;
  w,z:real;
begin
  check1:=false;
  response:=response;
  answer:=answer;
  replace(prompt,'',response);
  response:=response;
  res:=response;
  replace('$','',res);
  w:=evaluate(answer,'',undef,notwff);
  z:=evaluate(res,'',undef,notwff);
  check1:=(abs(z-w)<.005);
  if check1 then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4105;
var
  x:paramtype;
  undef,notwff:boolean;
  period,ans,dgm,text,w:string;
begin
  x.a:=rand([1..4]);
  x.a:=x.a*1000;
  x.b:=(1+randint(2,5)/10)*x.a;
  x.c:=x.b/x.a;
  x.r:=rand([60,65,74,75,80,85]);
  x.s:=x.r/10;
  x.v:=x.r/1000;
  text:='If you invest \$\a  at \s:1 % per annum compounded quarterly, determine the '+
    'number of quarters N required for your investment to exceed \$\b. Round '+
    'the number of quarters up to the next quarter.\nl ';
  text1::=text;
  prompt::=#133'N = '#134;
  help::='\red{Compound Interest Formula:}\nl '+
    '\ \ $$P=P_O(1+{r\over n})^{nt}$$\nl '+
    '\ \ P_O = initial investment\nl '+
    '\ \ r = nominal rate\nl '+
    '\ \ n = number of compoundings per year\nl '+
    '\ \ t = number of years';
  text3::=text+'\nl\blue{Hint:}\nl '+
    'Use the compound interest formula $$P=P_O(1+{r\over n})^{nt}$$.';
  str(ln(x.c)/(ln(1+x.v/4)):8:6,w);
  answer:=st(round(int(ln(x.c)/ln(1+x.v/4)))+1);
  solution::='\nl\red{Solution:}\nl '+
    'The value of the investment after N quarters is $$\a(1+{\v:3\over 4})^{N}$$.\pause\nl '+
    'We set $$\b=\a(1+{\v:3\over 4})^N$$ and solve for N.\pause\nl '+
    '$$\c:1=(1+{\v:3\over 4})^N$$. Taking natural logs of both sides we have\nl '+
    '$$ln(\c:1)=N\cdot ln(1+{\v:3\over 4})$$.\pause  '+
    'Thus N = $${ln(\c:1)\over ln(1+{\v:3\over 4})}$$ \doteq  '+w+'.\pause\nl '+
    'Hence the number of required quarters is '+answer+'.';
  type:='R';
  key:=4105;
end;

procedure s4105;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4107;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,a3,dgm,header,text,part1,part2,part3,comment:string;
  w,z:real;
begin
  x.a:=rand([6,7,8]);
  x.b:=rand([2,3,4,6,7]);
  x.c:=x.a+x.b/100;
  dgm::=#127''#127;
  header:='\red{Answer all 3 parts before grading.}';
  text:='Consider two investment options:\nl '+
  	'Option A: interest compounded quarterly at \c:3 % per annum.\nl '+
	'Option B: interest compounded continuously at \a %per annum.';
  part1:='\red{a: } Determine the effective rate for Option A. \red{(40%)}';
  part2:='\red{b: } Determine the effective rate for Option B. \red{(40%)}';
  part3:='\red{c: } Determine which option is better. (Enter A or B.) \red{(20%)}';
  comment:='\red{Answers to a: and b: must be accurate to 5 decimal '+
   	'places.}';
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13+part3+#13+comment+#13;
  buff1:=text+#13+part1+#13+part2+#13+part3+#13+comment+#13;
  prompt::=#133'a: Effective rate for A: '#134#13+
    	   #133'b: Effective rate for B: '#134#13+
	   #133'c: Better Option: '#134;
  help::='\red{Effective Rates:}\nl '+
  	'Compound interest at r% with n compoundings per year:\nl '+
  	'\ \ $$(1+{r\over n})^{n}-1$$\nl\nl '+
	'Compound interest at r% compounded continuously:\nl '+
	'\ \ $$e^{r}-1$$ ';
  text3::=buff1+'\nl\blue{Hint:}\nl '+
   	'The effective rate for compound interest at r% with n compoundings '+
	'per year is $$(1+{r\over n})^{n}-1$$ While the effective rate for '+
	'continuous compound interest at r% is $$e^{r}-1$$.';
  x.a:=x.a/100;
  x.c:=x.c/100;
  str((1+x.c/4)^4-1:8:6,a1);
  str(exp(x.a)-1:8:6,a2);
  w:=evaluate(a1,'',undef,notwff);
  z:=evaluate(a2,'',undef,notwff);
  if w > z then a3:='A' else a3:='B';
  ans:=#134+a1+#133+
       #134+a2+#133+
       #134+a3;
  answer::=ans;
  separate(ans,a1,a2,a3);
  solution::='\nl\red{Solution to part a: }\nl '+
  	'The effective rate for Option A is $$(1+{\c:5\over 4})^{4}-1$$ = '+
	a1+'.\pause\nl ';
  solution2::='\nl\red{Solution to part b: }\nl '+
   	'The effective rate for Option B is $$e^{\a:2}-1$$ = '+a2+'.\pause\nl ';
  solution3::='\nl\red{Solution to part c: }\nl '+
  	'Thus Option '+a3+' is the better option.';
  type:='R';
  key:=4107;
end;	   

procedure s4107;
var
  r1,r2,r3,r4,s1,s2,a1,a2,a3,a4:string;
  r:integer;
  check1,check2,check3,undef,notwff:boolean;
  u,v,w,z:real;
begin
  message:='';
  separate(response,r1,r2,r3);
  s1:=r1;
  s2:=r2;
  replace('%','',r1);
  replace('%','',r2);
  check1:=false;
  check2:=false;
  check3:=false;
  separate(answer,a1,a2,a3);
  w:=evaluate(a1,'',undef,notwff);
  z:=evaluate(a2,'',undef,notwff);
  u:=evaluate(r1,'',undef,notwff);
  v:=evaluate(r2,'',undef,notwff);
  if (pos('%',s1)>-1) then u:=u/100;
  if (pos('%',s2)>-1) then v:=v/100;
  check1:=(abs(w-u)<.00005);
  check2:=(abs(v-z)<.00005);
  toupper(r3);
  if a3 = 'A' then a4:='B' else a4:='A';
  r1:=s1;
  r2:=s2;
  check3:=((pos(a3,r3)>-1) and (pos(a4,r3)=-1));
    if check1 and check2 and check3 then begin
    result:='T';
    message:=#141'Correct'#141;
  end else begin
    if check1 then begin
      r:=r+4;
      message:='a: '+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:='a: '+r1+' is '#140'incorrect'#140'.'+#13+nl;
      end;
    end;
    if check2 then begin
      r:=r+4;
      message:=message+'b: '+r2+' is '#141'correct.'#141+nl;
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+'b: '+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check3 then begin
      r:=r+2;
      message:=message+'c: '+r3+' is '#141'correct'#141'.'+nl;
    end else begin
      if r3 = '' then begin
        message:=message+#140'c: Incorrect.'#140+nl;
      end else begin
        message:=message+'c: '+r3+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+text3;
  end;
end;

procedure p4108;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text,f:string;
begin
  x.r:=rand([55,60,67,70,74,82])/10;
  text:='A investment is made at \r:1 % per annum compounded continuously. Determine '+
  	'the time T (in years) required for the investment to double.\nl ';
  text1::=text;
  prompt::=#133'T = '#134;
  help::='\red{Continuous Compound Interest:}\nl '+
  	 '$$P=P_Oe^{rt}$$ where\nl '+
	 'P_O is the initial investment\nl '+
	 'r is the interest rate\nl '+
	 't is time in years';
  text3::=text+'\nl\blue{Hint:}\nl '+
  	'Use the continuous compound interest formula $$P=P_Oe^{rt}$$.';
  x.r:=x.r/100;
  str(ln(2)/x.r:8:6,answer);
  solution::='\nl\red{Solution:}\nl '+
  	'$$P=P_Oe^{rt}=P_Oe^{\r:3 t}$$. We want to find the time when '+
	'P = 2P_O.\pause\nl '+
	'Thus $$2P_O=P_Oe^{\r:3 t}$$ => $$2=e^{\r:3 t}$$\pause\nl '+
	'Taking natural logs of both sides we find\nl '+
	'$$ln(2)=ln(e^{\r:3 t})=\r:3 t$$.\pause\nl '+
	'So t = $${ln(2)\over \r:3}$$ = '+answer+'.\pause\nl '+
	'Thus the time required for the investment to double is '+answer+
	' years.';
  type:='R';
  key:=4108;
end;

procedure s4108;
var
w,z:real;
undef,notwff:boolean;
begin
  replace(prompt,'',response);
  z:=evaluate(answer,'',undef,notwff);
  w:=evaluate(response,'',undef,notwff);
  if (abs(w-z) < .005) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect '#140+#13+text3
    else message:=response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4109;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text,f:string;
begin
  x.r:=rand([55,60,67,70,74,82])/10;
  case randint(2,3) of
  2:
  begin
    f:='triple';
    x.c:=3;
  end;
  3:
  begin
    f:='quadruple';
    x.c:=4;
  end;
  end;{case}
  text:='A investment is made at \r:1 % per annum compounded continuously. Determine '+
  	'the time T required for the investment to '+f+'.\nl ';
  text1::=text;
  prompt::=#133'T = '#134;
  help::='\red{Continuous Compound Interest:}\nl '+
  	 '$$P=P_Oe^{rt}$$ where\nl '+
	 'P_O is the initial investment\nl '+
	 'r is the interest rate\nl '+
	 't is time in years';
  text3::=text+'\nl\blue{Hint:}\nl '+
  	'Use the continuous compound interest formula $$P=P_Oe^{rt}$$.';
  x.r:=x.r/100;
  str(ln(x.c)/x.r:8:6,answer);
  solution::='\nl\red{Solution:}\nl '+
  	'$$P=P_Oe^{rt}=P_Oe^{\r:3 t}$$. We want to find the time when '+
	'P = \c P_O.\pause\nl '+
	'Thus $$\c P_O=P_Oe^{\r:3 t}$$ => $$\c=e^{\r:3 t}$$\pause\nl '+
	'Taking natural logs of both sides we find\nl '+
	'$$ln(\c)=ln(e^{\r:3 t})=\r:3 t$$.\pause\nl '+
	'So t = $${ln(\c)\over \r:3}$$ = '+answer+'.\pause\nl '+
	'Thus the time required for the investment to '+f+' is '+answer+
	' years.';
  type:='R';
  key:=4109;
end;

procedure s4109;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4111;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,a3,dgm,header,text,part1,part2:string;
  q,r:real;
begin
  x.a:=100*rand([17,19,21,27]);
  x.b:=10*rand([5,10,15,20]);
  header:='\red{Answer both parts before grading.}';
  text:='The half-life of a radioactive material is \a  years.';
  part1:='\red{a: } Find the decay constant k. \red{(50%)}';
  part2:='\red{b: } What percent of the material will remain after \b  years? '+
  	'You may give your anwer either as a decimal or as a percent.\nl '+
	'Your answer should be correct to the nearest tenth of a percent. \red{(50%)}\nl '; 
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13;
  buff1:=text+#13+part1+#13+part2;
  text3::=buff1+#13+'\nl\blue{Hint:}\nl '+
    'Use the radioactive decay law $$P=P_Oe^{kt}$$, k < 0.';
  prompt::=#133'a: k = '#134#13+
    	   #133'b: % remaining: '#134;
  help::='\red{Exponential Growth and Decay:}\nl '+
  	'\ \ $$P=P_Oe^{kt}$$\nl '+
	'\ \ P_O is the initial amount\nl '+
	'\ \ k is the growth or decay constant\nl\nl '+
	'k is > 0 for exponential growth and k is < 0 for '+
	'exponential decay.\nl\nl '+
	'The half-life is the time required for P to reach half of '+
	'its original amount in exponential decay.';
  str(ln(.5)/x.a,a1);
  str(exp(ln(.5)*x.b/x.a):8:6,a2);
  x.z:=100*evaluate(a2,'',undef,notwff);
  str(exp(r):8:6,a3);
  text6:=a3;
  ans:=#134+a1+#133+
       #134+a2;
  answer::=ans;
  solution::='\nl\red{Solution to part a:}\nl '+
  	'P = $$P_Oe^{kt}$$. When t = \a  years, P = .5P_O.\pause\nl '+
	'Thus $$.5P_O=P_Oe^{\a k}$$ => $$.5=e^{\a k}$$.\pause\nl '+
	'Taking natural logs of both sides we obtain\nl '+
	'$$ln(.5)=ln(e^{\a k})=\a k$$. Thus k = {ln(.5)\over \a} = '+a1+'.\pause\nl ';	
  solution2::='\nl\red{Solution to part b:}\nl '+
	'Returning to the decay law we have $$P=P_Oe^{kt}$$.\pause\nl When t = \b, '+
	'we have $$P=P_Oe^{\b k}$$ or $${P\over P_O}=e^{\b k}$$. Substituting '+
	'for k => $${P\over P_O}=e^{\b('+a1+')}$$ = '+a2+'.\pause\nl '+
	'Thus \z:2 % of the material will remain.';
  type:='R';
  key:=4111;
end;
		       
procedure s4111;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check,check1,check2,undef,notwff:boolean;
  u,v,w,y,z:real;
begin
  r:=0;
  message:='';
  check:=false;
  res:=response;
  separate(answer,a1,a2);
  separate(res,r1,r2);
  replace('%','',r2);
  u:=evaluate(a1,'',undef,notwff);
  v:=evaluate(a2,'',undef,notwff);
  w:=evaluate(r1,'',undef,notwff);
  z:=evaluate(r2,'',undef,notwff);
  y:=z/100;
  check1:=false;
  check2:=false;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=(abs(z-v)<.0005) or (abs(y-v)<.0005);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4112;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,a3,dgm,header,text,part1,part2:string;
  q,r:real;
begin
  x.a:=100*rand([17,19,21,27]);
  x.b:=rand([5,10,15,20]);
  header:='\red{Answer both parts before grading.}';
  text:='A certain radioactive substance with a half life of \a  years '+
    	'is used in estimating the age of relics. ';
  part1:='\red{a: } Find the decay constant k. \red{(50%)}';
  part2:='\red{b: } If a certain relic contains \b % of the substance, '+
  	'determine the age of the relic in years. \red{(50%)}\nl '; 
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13;
  buff1:=text+#13+part1+#13+part2;
  text3::=buff1+#13+'\nl\blue{Hint:}\nl '+
    'Use the radioactive decay law $$P=P_Oe^{kt}$$, k < 0.';
  prompt::=#133'a: k = '#134#13+
    	   #133'b: Age of relic: '#134;
  help::='\red{Exponential Growth and Decay:}\nl '+
  	'\ \ $$P=P_Oe^{kt}$$\nl '+
	'\ \ P_O is the initial amount\nl '+
	'\ \ k is the growth or decay constant\nl\nl '+
	'k is > 0 for exponential growth and k is < 0 for '+
	'exponential decay.\nl\nl '+
	'The half-life is the time required for P to reach half of '+
	'its original amount in exponential decay.';
  str(ln(.5)/x.a:8:6,a1);
  solution::='\nl\red{Solution to part a:}\nl '+
	'When t = \a  years, P = .5P_O. Thus we have '+
	'$$.5P_O=P_Oe^{k(\a)}$$\nl => $$.5=e^{\a\cdot k}$$.\pause\nl '+
	'Taking natural logs of both sides, we obtain \nl '+
	'$$ln(.5)=ln(e^{\a\cdot k})=\a\cdot k$$.\pause\nl '+
	'Thus k = {ln(.5)\over \a} = '+a1+'.\pause\nl ';
  x.b:=x.b/100;
  str(ln(x.b)/evaluate(a1,'',undef,notwff):8:2,a2);
  answer:=#134+a1+#133+
	#134+a2;
  solution2::='\nl\red{Solution to part b:}\nl '+
	'Let t = 0 at the time the relic started to decay. At the present '+
	'time t,\nl P = \b:2 P_O.\pause  Thus we have $$\b:2 P_O=P_Oe^{k\cdot t}$$ or '+
	'$$\b:2 = e^{kt}$$. Taking natural logs of both sides gives\nl '+
	'$$ln(\b:2)=ln(e^{kt})=kt$$\nl '+
	'Thus t = {ln(\b:2)\over k} = {ln(\b:2)\over '+a1+'} = '+a2+'.\pause\nl '+
	'Hence the relic is '+a2+' years old.';
  type:='R';
  key:=4112;
end;	   
	       
procedure s4112;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message:='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4114;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2:string;
begin
  x.a:=1000*rand([1,2,3]);
  x.b:=1000*rand([4,5,6]);
  x.c:=rand([2,3,5]);
  x.d:=x.c+rand([2,4,6]);
  x.f:=x.c-x.d;
  dgm::=#127'500,500,1200,10;I,100,100,50;L,-2,0,8,0;L,0,-2,0,8;'+
  	'B,2;G,exp(.3x),0,8;B,0;G,2.45,D3,3;D,3,0,3,2.45,5;D,0,2.45,3,2.45,6;'+
	'C,2.8,-.5,\c;C,-1.8,2.45,\a;G,5.35,D5.7,5.7;D,5.7,0,5.7,5.35,10;'+
	'D,0,5.35,5.7,5.35,10;C,5.5,-.5,\d;C,-1.8,5.35,\b;C,7.6,-.5,t;'+
	'C,-.5,7.5,P;'#127;
  header:='\red{Answer both parts before grading.}';
  text:='The graph to the right is the graph of an exponential growth curve '+
  	'$$P=P_Oe^{kt}$$.';
  part1:='\red{a: } Find the growth constant k. \red{(50%)}';
  part2:='\red{b: } Find P_O. \red{(50%)}';
  text1::=dgm+header+#13+#13+text+#13+part1+#13+part2+#13#13#13#13;
  buff1:=text+#13+part1+#13+part2;
  prompt::=#133'a: k = '#134#13+
    	   #133'b: P_O = '#134;
  help::='\red{Exponential Growth and Decay:}\nl '+
  	'\ \ $$P=P_Oe^{kt}$$\nl '+
	'\ \ P_O is the initial amount\nl '+
	'\ \ k is the growth or decay constant\nl\nl '+
	'k is > 0 for exponential growth and k is < 0 for '+
	'exponential decay.\nl\nl '+
	'The half-life is the time required for P to reach half of '+
	'its original amount in exponential decay.';
  text3::=buff1+'\nl\blue{Hint:}\nl '+
  	'Two points on the graph are given. Substitute these values '+
	'into the exponential growth formula and solve the resulting '+
	'two equations for k and P_O.';
  str(ln(x.a/x.b)/x.f,a1);
  str(x.a*exp(-x.c*evaluate(a1,'',undef,notwff)),a2);
  x.w:=evaluate(a2,'',undef,notwff);
  ans:=#134+a1+#133+
       #134+a2;
  answer::=ans;
  solution::=+'\nl\red{Solution to Part a: }\nl '+
  	'From the graph	we see that the points (\c,\a) and (\d,\b) are on '+
	'the curve. Thus\nl $$\a=P_Oe^{k\cdot\c}$$ and $$\b=P_Oe^{k\cdot\d}$$.\pause\nl '+
	'So we have two equations in two unknowns.\pause  Dividing the first '+
	'equation by the second implies\nl '+
	'$${\a\over \b}={P_Oe^{\c\cdot k}\over P_Oe^{\d\cdot k}}$$ = '+
	'$$e^{\f\cdot k}$$.\pause  Taking natural logs of both sides, we '+
	'obtain\nl '+
	'$$ln({$\a\over \b$})=ln(e^{\f\cdot k})=\f\cdot k$$.\nl '+
	'Thus $$k={1\over \f}ln({$\a\over \b$})$$ = '+a1+'.\pause\nl ';
  solution2::='\nl\red{Solution to Part b: }\nl '+
  	'To find P_O we solve the equation $$\a=P_Oe^{\c\cdot k}$$ for P_O '+
	'and substitute for k:\nl '+
	'$$P_O=\a e^{-\c\cdot k}=\a e^{-\c\cdot '+a1+'}=\w:2 $$.';
  type:='R';
  key:=4114;
end;	   
	       
procedure s4114;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4115;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,header,text,part1,part2,a1,a2:string;
begin
  x.a:=rand([12,15,20,25]);
  x.b:=100*rand([1,2,5,7]);
  x.c:=100-x.a;
  x.d:=x.c/100;
  header:='\red{Answer both parts before grading.}';
  text:='\a % of a certain radioactive substance disappears in \b  years.';
  part1:='\red{a:} Find the decay constant k. \red{(50%)}';
  part2:='\red{b:} Find the half-life of the substance. \red{(50%)}';
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13;
  text3::=text+nl+part1+nl+part2+nl+'\nl\blue{Hint:}\nl '+
    	'Use the exponential decay law $$P=P_Oe^{k\cdot t}$$, k < 0.';
  prompt::=#133'a: k = '#134#13+
    	   #133'b: half-life = '#134;
  help::='\red{Exponential Growth and Decay:}\nl '+
  	'\ \ $$P=P_Oe^{kt}$$\nl '+
	'\ \ P_O is the initial amount\nl '+
	'\ \ k is the growth or decay constant\nl\nl '+
	'k is > 0 for exponential growth and k is < 0 for '+
	'exponential decay.\nl\nl '+
	'The half-life is the time required for P to reach half of '+
	'its original amount in exponential decay.';
  str(ln(x.d)/x.b,a1);
  str(ln(.5)/evaluate(a1,'',undef,notwff),a2);
  x.z:=evaluate(a2,'',undef,notwff);
  answer:=#134+a1+#133+
          #134+a2;
  solution::='\nl\red{Solution to part a: }\nl '+
  	'Let t be measured in years. Then $$P=P_Oe^{k\cdot t}$$. When t = \b, '+
	'\c % of the material remains. Thus t = \b  => P = \d:2\cdot P_O and so we have\nl '+
	'$$\d:2\cdot P_O=P_Oe^{k\cdot \b}$$ => $$\d:2=e^{\b\cdot k}$$\pause\nl '+
	'Taking natural logs of both sides, we obtain\nl '+
	'$$ln(\d:2)=ln(e^{\b\cdot k})=\b\cdot k$$.\pause\nl '+
	'Thus k = {ln(\d:2)\over\b} = '+a1+'.\pause\nl ';
  solution2::='\nl\red{Solution to part b:}\nl '+
  	'Let h denote the half-life. Then h is the time when P = .5P_O.\pause\nl '+
	'Substituting into the exponential decay law we have\nl '+
	'$$.5P_O=P_Oe^{k\cdot h}$$ => $$.5=e^{'+a1+'\cdot h}$$.\pause\nl '+
	'Taking natural logs of both sides, we obtain\nl '+
	'$$ln(.5)=ln(e^{'+a1+'\cdot h})='+a1+'\cdot h$$.\pause\nl '+
	'Thus $$h={ln(.5)\over '+a1+'}$$ = '+a2+'.\nl '+
	'Therefore the half-life of the material is \z:2  years.';
  type:='R';
  key:=4115;
end;

procedure s4115;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4119;
var
  x:paramtype;
  undef,notwff:boolean;
  f,g,ans,a1,a2,dgm,header,text,part1,part2,sola,solb,w,z:string;
begin
  x.a:=rand([2..9]);
  x.b:=x.a+rand([2..5]);
  x.c:=x.a^2+x.b^2;
  if gcd(round(x.a),round(x.b))>1 then begin
    w:='{\a\over \b} = ';
    z:='{\b\over \a} = ';
  end else begin
    w:='';
    z:='';
  end;
  case rand([1..3]) of
  1:begin
      f:='sin';a1:='{\b\over \sqrt{\c}}';
      g:='tan';a2:='{$\a\over\b$}';
      sola:='sin(\alpha) = {opposite\over hypotenuse} = '+a1+'.';
      solb:='tan(\beta) = {opposite\over adjacent} = '+w+a2+'.';
    end;
  2:begin
      f:='cos';a1:='{\a\over \sqrt{\c}}';
      g:='cot';a2:='{$\b\over \a$}';
      sola:='cos(\alpha) = {adjacent\over hypotenuse} = '+a1+'.';
      solb:='cot(\beta) = {adjacent\over opposite} = '+z+a2+'.';
    end;
  3:begin
      f:='sec';a1:='{\sqrt{\c}\over \a}';
      g:='csc';a2:=a1;
      sola:='sec(\alpha) = {hypotenuse\over adjacent} = '+a1+'.';
      solb:='csc(\beta) = {hypotenuse\over opposite} = '+a2+'.';
    end;
  end;{case}
  dgm:=#127'500,500,1200,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'B,4;C,2,-.5,\a;C,4.2,3,\b;B,2;C,.8,.4,\alpha;C,3.44,4.31,\beta;'+
	'L,3.5,0,3.5,.5;L,3.5,.5,4,.5;';
  header:='\red{Answer both parts before grading.}';
  text:='A right triangle is shown to the right:';
  part1:='\red{a: } Evaluate '+f+'(\alpha). \red{(50%)}';
  part2:='\red{b: } Evaluate '+g+'(\beta). \red{(50%)}';
  text1::=dgm+#127+header+#13+#13+text+#13+part1+#13+part2+#13+#13+#13+#13+#13;
  prompt::=#133'a: '+f+'(\alpha) = '#134#13+
    	   #133'b: '+g+'(\beta) = '#134;
  help::='\red{Definitions of Trig Frunctions:}\nl '+
  	#127'500,500,800,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'C,2,-.5,x;C,4.2,3,y;C,.8,.25,\theta;C,1.2,3,r;'#127+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$';
  text3::=dgm+#127+text+#13+part1+#13+part2+#13+'\nl\blue{Hint:}\nl '+
  	'Use the Pythagorean Theorem to compute the hypotenuse and then '+
	'use the definitions of the trig functions.';
  ans:=#134+a1+#133+
       #134+a2;
  answer::=ans;
  solution::=dgm+'C,.5,3,\sqrt{\c};'#127+
  	'\nl\nl\red{Solution to part a:}\nl '+
  	'By the Pythagorean theorem the hypotenuse is \sqrt{\c}.\pause\nl '+
	sola+'\pause\nl ';
  solution2::='\nl\red{Solution to part b:}\nl '+solb;
  type:='R';
  key:=4119;
end;	   

procedure s4119;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4121;   {old 1084}
var
  x:array[1..4,1..3] of integer;
  trig,def:array[1..6] of string;
  i,j,k:integer;
  f,g,dgm:string;
begin
  x[1,1] := 3; x[1,2] := 4; x[1,3] := 5;
  x[2,1] := 5; x[2,2] := 12; x[2,3] := 13;
  x[3,1] := 7; x[3,2] := 24; x[3,3] := 25;
  x[4,1] := 8; x[4,2] := 15; x[4,3] := 17;
  trig[1] := 'sin';def[1]:='{opposite\over hypotenuse}'; 
  trig[2] := 'cos';def[2]:='{adjacent\over hypotenuse}';
  trig[3] := 'sec';def[3]:='{hypotenuse\over adjacent}'; 
  trig[4] := 'csc';def[4]:='{hypotenuse\over opposite}';
  trig[5] := 'tan';def[5]:='{opposite\over adjacent}';
  trig[6] := 'cot';def[6]:='{adjacent\over opposite}';
  i := randint(1,4);
  j := randint(1,6);
  k := (randint(1,5) + j - 1) mod 6 + 1;
  dgm:=#127'300,300,1200,10;I,50,50,50;L,0,.5,.5,.5;L,.5,.5,.5,0;'+
       'L,0,0,4,0;L,0,0,0,3;B,2;C,-.5,-.5,A;C,-.5,3,B;C,4.5,-.5,C;B,0;L,0,3,4,0;'+
       'B,4;C,-.5,1,'+st(x[i,1])+';C,2,1.7,'+st(x[i,3])+';C,2,-.5,'+st(x[i,2])+';'+
       'B,0;C,2.8,.1,x;'#127;
  case j of
  1:begin  {sin}
     f := fraction(x[i,1],'-',x[i,3]);
     solution::='\nl\red{Solution:}\nl '+ 
       dgm+'Let x be the angle at C. Since sin(x) = '+f+' we set '+
       'AB = '+st(x[i,1])+' and BC = '+st(x[i,3])+'. By the '+
       'Pythagorean Theorem AC = '+st(x[i,2])+'.';
    end;
  2:begin  {cos}
     f := fraction(x[i,2],'-',x[i,3]);
     solution::='\nl\red{Solution:}\nl '+ 
       dgm+'Let x be the angle at C. Since cos(x) = '+f+' we set '+
       'AC = '+st(x[i,2])+' and BC = '+st(x[i,3])+'. By the '+
       'Pythagorean Theorem AB = '+st(x[i,1])+'.';
    end;
  3:begin  {sec}
     f := fraction(x[i,3],'-',x[i,2]);
     solution::='\nl\red{Solution:}\nl '+ 
       dgm+'Let x be the angle at C. Since sec(x) = '+f+' we set '+
       'AC = '+st(x[i,2])+' and BC = '+st(x[i,3])+'. By the '+
       'Pythagorean Theorem AB = '+st(x[i,1])+'.';
    end;
  4:begin  {csc}
     f := fraction(x[i,3],'-',x[i,1]);
     solution::='\nl\red{Solution:}\nl '+ 
       dgm+'Let x be the angle at C. Since sec(x) = '+f+' we set '+
       'AB = '+st(x[i,1])+' and BC = '+st(x[i,3])+'. By the '+
       'Pythagorean Theorem AC = '+st(x[i,2])+'.';
    end;
  5:begin  {tan}
     f := fraction(x[i,1],'-',x[i,2]);
     solution::='\nl\red{Solution:}\nl '+ 
       dgm+'Let x be the angle at C. Since tan(x) = '+f+' we set '+
       'AB = '+st(x[i,1])+' and AC = '+st(x[i,2])+'. By the '+
       'Pythagorean Theorem BC = '+st(x[i,3])+'.';
   end;
  6:begin  {cot}
     f := fraction(x[i,2],'-',x[i,1]);
     solution::='\nl\red{Solution:}\nl '+ 
       dgm+'Let x be the angle at C. Since cot(x) = '+f+' we set '+
       'AB = '+st(x[i,1])+' and AC = '+st(x[i,2])+'. By the '+
       'Pythagorean Theorem BC = '+st(x[i,3])+'.';
    end;
  end;
  case k of
  1:g := fraction(x[i,1],'-',x[i,3]);
  2:g := fraction(x[i,2],'-',x[i,3]);
  3:g := fraction(x[i,3],'-',x[i,2]);
  4:g := fraction(x[i,3],'-',x[i,1]);
  5:g := fraction(x[i,1],'-',x[i,2]);
  6:g := fraction(x[i,2],'-',x[i,1]);
  end;
  text1 := 'Assume 0 ! x ! '#29#219'~'#221'/'#219'2'#221'(0'+
    #30+'`'+#31+' ! x ! 90'+#30+'`'+#31+') and '+trig[j]+
    '(x) = '+f+'.  Find '+trig[k]+'(x).'+nl;
  text3::=text1+#13+'\nl\blue{Hint:}\nl '+
    'Draw a right triangle in which one of the acute angles satisfies '+
    trig[j]+'(x) = '+f+'.';
  help::='\red{Definitions of Trig Frunctions:}\nl '+
  	#127'500,500,800,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'C,2,-.5,x;C,4.2,3,y;C,.8,.25,\theta;C,1.2,3,r;'#127+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$';
  prompt::=#133+trig[k]+'(x) = '#134;
  answer :=g;
  solution2::= #10+nl+'Therefore '+trig[k]+'(x) = '+def[k]+' = '+answer+'.';
  key := 4121;
  type := 'R';
end;

procedure s4121;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4122;	{old 1063}
var
  t1x,t2x,bx:integer;
  v:valuetype;
  trig:array[1..4] of string;
  astr,ans1,ans2,den1,den2,num1,num2:string;
  bstr:array[1..2] of string;
begin
  t1x:=randint(1,4);
  repeat t2x:=randint(1,4) until t2x <> t1x;
  bx:=randint(1,2);
  trig[1]:='tan';
  trig[2]:='cot';
  trig[3]:='sec';
  trig[4]:='csc';
  bstr[1]:='sin x';
  bstr[2]:='cos x';
  repeat v.r:=randint(-4,4) until v.r <> 0;
  repeat v.q:=randint(-4,4) until v.q <> 0;
  astr:=makeformula('r'+trig[t1x]+'^2x + q'+trig[t2x]+'^2x',['r','q'],v);
  text1 :='Rewrite f(x) = '+astr+' in terms of '+bstr[bx]+'.'+nl+
    'Assume 0 ! x ! ~/2 (0'+#30+'`'+#31+' ! x ! 90'+#30+'`'+#31+').  '+nl;

  {first rewrite r trig1^2 x }
  if bx = 1 then
    begin  { in terms of sin x }
      case t1x of
        1: begin
            ans1:=makeformula('[rsin^2x]/[1-sin^2x]',['r'],v);    {tan x}
            solution:='We have '+makeformula('rtan^2x=[rsin^2x]/[cos^2x]',['r'],v)+' = '+ans1;
           end;
        2: begin
            ans1:=makeformula('[r(1-sin^2x)]/[sin^2x]',['r'],v);  {cot x}
            solution:='We have '+makeformula('rcot^2x=[rcos^2x]/[sin^2x]',['r'],v)+' = '+ans1;
           end;
        3: begin
            ans1:=makeformula('[r]/[1-sin^2x]',['r'],v);          {sec x}
            solution:='We have '+makeformula('rsec^2x=[r]/[cos^2x]',['r'],v)+' = '+ans1;
           end;
        4: begin
            ans1:=makeformula('[r]/[sin^2x]',['r'],v);            {csc x}
            solution:='We have '+makeformula('rcsc^2x',['r'],v)+' = '+ans1;
           end;
      end; {case}
    end
  else     { in terms of cos x }
    begin
      case t1x of
        1: begin
            ans1:=makeformula('[r(1-cos^2x)]/[cos^2x]',['r'],v);  {tan x}
            solution:='We have '+makeformula('rtan^2x=[rsin^2x]/[cos^2x]',['r'],v)+' = '+ans1;
           end;
        2: begin
            ans1:=makeformula('[rcos^2x]/[1-cos^2x]',['r'],v);    {cot x}
            solution:='We have '+makeformula('rcot^2x=[rcos^2x]/[sin^2x]',['r'],v)+' = '+ans1;
           end;
        3: begin
            ans1:=makeformula('[r]/[cos^2x]',['r'],v);            {sec x}
            solution:='We have '+makeformula('rsec^2x',['r'],v)+' = '+ans1;
           end;
        4: begin
            ans1:=makeformula('[r]/[1-cos^2x]',['r'],v);          {csc x}
            solution:='We have '+makeformula('rtan^2x=[r]/[sin^2x]',['r'],v)+' = '+ans1;
           end;
      end; {case}
    end;
  solution := solution+nl;

  {second rewrite r trig2^2 x }
  if bx = 1 then
    begin  { in terms of sin x }
      case t2x of
        1: begin
             ans2:=makeformula('[qsin^2x]/[1-sin^2x]',['q'],v);    {tan x}
             solution := solution+'and '+
               makeformula('qtan^2x=[qsin^2x]/[cos^2x]',['q'],v)+' = '+ans2;
           end;
        2: begin
             ans2:=makeformula('[q(1-sin^2x)]/[sin^2x]',['q'],v);  {cot x}
             solution := solution +'and '+
               makeformula('qcot^2x=[qcos^2x]/[sin^2x]',['q'],v)+' = '+ans2;
           end;
        3: begin
             ans2:=makeformula('[q]/[1-sin^2x]',['q'],v);          {sec x}
             solution := solution +'and '+
               makeformula('qsec^2x=[q]/[cos^2x]',['q'],v)+' = '+ans2;
           end;
        4: begin
             ans2:=makeformula('[q]/[sin^2x]',['q'],v);            {csc x}
             solution := solution +'and '+
               makeformula('qcsc^2x',['q'],v)+' = '+ans2;
           end;
      end; {case}
    end
  else     { in terms of cos x }
    begin
      case t2x of
        1: begin
             ans2:=makeformula('[q(1-cos^2x)]/[cos^2x]',['q'],v);  {tan x}
             solution := solution +'and '+
               makeformula('[qsin^2x]/[cos^2x]',['q'],v)+' = '+ans2;
           end;
        2: begin
             ans2:=makeformula('[qcos^2x]/[1-cos^2x]',['q'],v);    {cot x}
             solution := solution +'and '+
               makeformula('[qcos^2x]/[sin^2x]',['q'],v)+' = '+ans2;
           end;
        3: begin
             ans2:=makeformula('[q]/[cos^2x]',['q'],v);            {sec x}
             solution := solution +'and '+
               makeformula('[q]/[cos^2x]',['q'],v)+' = '+ans2;
           end;
        4: begin
             ans2:=makeformula('[q]/[1-cos^2x]',['q'],v);          {csc x}
             solution := solution +'and '+
               makeformula('[q]/[sin^2x]',['q'],v)+' = '+ans2;
           end;
      end; {case}
    end;
  answer :=ans1+' + '+ans2;
  solution:=nl+#140'Solution:'#140+nl+ 
  	solution+'.'#10+nl+'Thus f(x) = '+astr+' = '+answer+'.';
  if bx = 1 then text6:='COS'
  else text6:='SIN';
  prompt::=#133'f(x) = '#134;
  text3::=text1+'\nl\blue{Hint:}\nl '+ 
  	'Use the fundamental identities.';
  help::='\red{Basic Trig Identities:}\nl '+
  	'\ \ $$sin^2(x)+cos^2(x)=1$$\nl '+
	'\ \ $$tan^2(x)+1=sec^2(x)$$\nl '+
	'\ \ $$sec(x)={1\over cos(x)}$$\nl '+
	'\ \ $$csc(x)={1\over sin(x)}$$\nl '+
	'\ \ $$cot(x)={1\over tan(x)}$$\nl '+
	'\ \ $$tan(x)={sin(x)\over cos(x)}$$';
  key := 4122;
  type := 'R';
end;

procedure s4122;
var
  correct:boolean;
  f:string;
begin
  f := response;
  toupper(f);
  if pos(text6,f) > 0 then correct := false
  else if pos('COT',f) > 0 then correct := false
  else if pos('CSC',f) > 0 then correct := false
  else if pos('TAN',f) > 0 then correct := false
  else if pos('SEC',f) > 0 then correct := false
  else correct := sameexpres(answer,response);
  if correct then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = prompt then message := #140'Incorrect'#140+#13+text3
    else message := response+' is '#140'incorrect.'#140+#13+text3;
  end;
end;

procedure p4124;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text,f:string;
begin
    case randint(1,2) of
  1:begin
    x.b:=5;
    x.a:=rand([3,4]);
    x.r:=round(sqrt(25-x.a*x.a));
    x.s:=x.a-x.r;
    x.t:=x.a+x.r;
  end;
  2:begin
    x.b:=13;
    x.a:=rand([12,5]);
    x.r:=round(sqrt(169-x.a*x.a));
    x.s:=x.a-x.r;
    x.t:=x.a+x.r;
  end;
  end;{case}
  x.c:=x.a+x.b;
  x.d:=x.b-x.a;
  x.e:=x.a*x.b;
  x.f:=2*x.e;
  x.g:=2*x.a;
  x.h:=2*x.r;
  case rand([1..4]) of
  1:begin
    f:='tan(x)';
    answer:='{$\a\over \r$}';
    solution2::='Now $$tan(x)={sin(x)\over cos(x)}='+
    	'{{$\a\over \b$}\over {$\r\over \b$}}$$ = '+answer+'.';
    end;
  2:begin
    f:='cot(x)';
    answer:='{$\r\over \a$}';
    solution2::='Now $$cot(x)={cos(x)\over sin(x)}='+
    	'{{$\r\over \b$}\over {$\a\over \b$}}$$ = '+answer+'.';
    end;
  3:begin
    f:='sec(x)';
    answer:='{$\b\over \r$}';
    solution2::='Now $$sec(x)={1\over cos(x)}='+
    	'{1\over {$\r\over \b$}}$$ = '+answer+'.';
    end;  	
  4:begin
    f:='csc(x)';
    answer:='{$\b\over \a$}';
    solution2::='Now $$csc(x)={1\over sin(x)}='+
    	'{1\over {$\a\over \b$}}$$ = '+answer+'.';
    end;
  end;{case}
  text:='Assume $$sin(x)+cos(x)={$\t\over \b$}$$ and $$sin(x)-cos(x)={$\s\over \b$}$$. Find the '+
  	'numerical value of '+f+'.\nl ';
  text1::=text;
  prompt::=#133+f+' = '#134;
  help::='\red{Basic Trig Identities:}\nl '+
  	'\ \ $$sin^2(x)+cos^2(x)=1$$\nl '+
	'\ \ $$tan^2(x)+1=sec^2(x)$$\nl '+
	'\ \ $$sec(x)={1\over cos(x)}$$\nl '+
	'\ \ $$csc(x)={1\over sin(x)}$$\nl '+
	'\ \ $$cot(x)={1\over tan(x)}$$\nl ';
  text3::=text+'\nl\blue{Hint:}\nl '+
  	'Solve the pair of equations for sin(x) and cos(x) and then use '+
	'the basic trig identities.';
  answer::=answer;
  solution::='\nl\red{Solution:}\nl '+
  	'Adding the two equations => $$2sin(x)={$\t\over \b$}+{$\s\over \b$}'+
	'={$\g\over \b$}$$ => $$sin(x)={$\a\over \b$}$$\pause\nl '+
	'Subtracting the second equation from the first =>\nl '+
	'$$2cos(x)={$\t\over \b$}-{$\s\over \b$}={$\h\over \b$}$$'+
	' => $$cos(x)={$\r\over \b$}$$.\nl ';
  type:='R';
  key:=4124;
end;

procedure s4124;
var
  check1,check2:boolean;
  res:string;
begin
  res := response;
  replace(prompt,'',res);
  toupper(res);
  check1:=true;
  if pos('SIN',res) > -1 then check1 := false;
  if pos('COS',res) > -1 then check1 := false;
  if pos('COT',res) > -1 then check1 := false;
  if pos('CSC',res) > -1 then check1 := false;
  if pos('TAN',res) > -1 then check1 := false;
  if pos('SEC',res) > -1 then check1 := false;
  check2:= sameconstants(answer,response);
  if (check1 and check2) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    replace(prompt,'',response);
    if response = '' then message := #140'Incorrect'#140+#13+text3
    else message := response+' is '#140'incorrect.'#140+#13+text3;
  end;
end;

procedure p4126;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,a3,dgm,header,text,part1,part2,part3:string;
begin
  x.a:=rand([10,12,14,16,18]);
  dgm::=#127'500,500,1200,10;I,250,250,50;L,3,0,.93,2.85;'+
  	'L,.93,2.85,-2.43,1.76;L,-2.43,1.76,-2.43,-1.76;'+
	'L,-2.43,-1.76,.93,-2.85;L,.93,-2.85,3,0;L,0,0,.93,2.85;'+
	'L,0,0,-2.43,1.76;B,2;E,-3,-3,3,3;'+
	'B,4;C,0,-.3,O;C,-2.88,1.87,A;'+
	'C,.94,3.09,B;B,0;C,.7,1,\a;';
  header:='\red{Answer both parts before grading.}';
  text:='A regular pentagon is inscribed in a circle of radius '+
  	'\a. \nl ';
  part1:='\red{a: } Find the angle OAB in degrees. \red{(30%)}';
  part2:='\red{b: } Find the area of triangle OAB. \red{(40%)}';
  part3:='\red{c: } Find the area of the pentagon. \red{(30%)}';
  text1::=dgm+#127+header+#13+#13+text+#13+part1+#13+part2+#13+part3+#13+#13;
  buff1:=dgm+#127+text+#13+part1+#13+part2+#13+part3+#13;
  prompt::=#133'a: Angle OAB: '#134#13+
  	   #133'b: Area of \dif OAB: '#134#13+
    	   #133'c: Area of pentagon: '#134;
  help::=#127'300,300,700,10;I,100,100,50;L,0,0,2,0;L,2,0,2,4;L,0,0,2,4;'+
  	'B,2;C,.5,.1,\theta;'#127+
	'sin(\theta) = {opposite\over hypotenuse}\nl '+
	'cos(\theta) = {adjacent\over hypotenuse}\nl\nl '+
	'Alternate interior angles of an isosceles triangle are equal.';
  text3::='\nl\blue{Hint:}\nl '+
  	'The angle AOB is one fifth of a complete revolution, and the '+
	'remaining two angles of \dif OAB are equal. Use the definitions '+
	'of the trig functions to compute the height and base of \dif OAB. '+
	'Then use the fact that the area of a triangle is {1\over 2}\cdot '+
	'base\cdot height.';
  str(x.a^2*cos(54*pi/180)*sin(54*pi/180),a2);
  x.w:=evaluate(a2,'',undef,notwff);
  str(5*x.w,a3);
  x.z:=evaluate(a3,'',undef,notwff);
  ans:=#134'54^{\circ}'#133+
       #134+a2+#133+
       #134+a3;
  answer::=ans;
  separate(ans,a1,a2,a3);
  solution::='\nl\red{Solution to part a:}\nl '+
  	'By symmetry the angle AOB is {360\over 5} = 72^{\circ}. Since '+
	'angles OAB and OBA are equal and the sum of the angles in a '+
	'triangle add to 180^{\circ}, we find that angle OAB = '+a1+'.\pause\nl';
  solution2::=#127'900,600,1000,100;I,300,300,75;C,-.1,2.25,54^{\circ};'+
  	'C,-1.04,2.47,D;L,0,0,.93,2.85;L,0,0,-2.43,1.76;'+
	'L,.93,2.85,-2.43,1.76;B,4;C,0,-.3,O;C,-2.88,1.87,A;'+
	'C,.94,3.09,B;B,0;L,0,0,-.88,2.24;C,-.85,1.28,h;C,.6,1.4,\a;'+
	'C,2,1.7,h=\a sin(54^{\circ});C,2,1,DB=\a cos(54^{\circ});'#127+
  	'\nl\red{Solution to part b:}\nl '+
  	'The area of \dif OAB is {1\over 2}\cdot base\cdot height = '+
	'{1\over 2}\cdot (2\cdot\a cos(54^{\circ}))\cdot (\a sin(54^{\circ})\pause\nl '+
	'\doteq  \w:2.\pause\nl';
  solution3::='\nl\red{Solution to part c:}\nl '+
	'The area of the pentagon is 5\cdot area of \dif OAB = 5\cdot \w:2 '+
	' \doteq  \z:2.';
  type:='R';
  key:=4126;
end;
		       
procedure s4126;
var
  r1,r2,r3,r4,a1,a2,a3:string;
  r:integer;
  check1,check2,check3,undef,notwff:boolean;
begin
  message:='';
  separate(response,r1,r2,r3);
  check1:=false;
  check2:=false;
  check3:=false;
  separate(answer,a1,a2,a3);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  check3:=sameconstants(a3,r3);
    if check1 and check2 and check3 then begin
    result:='T';
    message:=#141'Correct'#141;
  end else begin
    if check1 then begin
      r:=r+3;
      message:='a: '+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:='a: '+r1+' is '#140'incorrect'#140'.'+#13+nl;
      end;
    end;
    if check2 then begin
      r:=r+4;
      message:=message+'b: '+r2+' is '#141'correct.'#141+nl;
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+'b: '+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check3 then begin
      r:=r+4;
      message:=message+'c: '+r3+' is '#141'correct'#141'.'+nl;
    end else begin
      if r3 = '' then begin
        message:=message+#140'c: Incorrect.'#140+nl;
      end else begin
        message:=message+'c: '+r3+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+text3;
  end;
end;

procedure p4128;	{old 1213}
var
  a,b,c,d,e,f,j,k:integer;
  p,q,r,s,t:real;
  v:valuetype;
  x:paramtype;
  ans1,ans2,funct,dgm:string;
  undef,notwff:boolean;
  begin
  a:=rand([30,35,36,42]);v.a:=a;
  b:=rand([12,14,16,17,19]);
  dgm::=#127'500,400,1200,10;I,100,240,50;L,0,0,6,0;L,0,0,6,2;L,6,0,6,2;'+
       'B,2;C,3,-.5,'+st(a)+'00;C,6.3,1,h;C,1.8,.4,'+st(b)+'^{\circ};';
  text1:=dgm+#127+'A person is standing '+st(a)+'00 feet from the bottom '+
         'of a building. If the angle of elevation from the observer to '+
	 'the top of the building is '+st(b)+#30+'`'+#31', '+
         'determine the height h of the building. Express your answer in '+
	 'feet.'+nl;
  text3::=text1+#13+'\nl\blue{Hint:}\nl '+
  	'The tangent of the angle of elevation is h/'+st(a)+'00.';
  help::='\red{Definitions of Trig Frunctions:}\nl '+
  	#127'500,500,800,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'C,2,-.5,x;C,4.2,3,y;C,.8,.25,\theta;C,1.2,3,r;'#127+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$';
  str((1.0*100*a*sin(b*pi/180))/cos(b*pi/180):8:6,answer);
  x.z:=evaluate(answer,'',undef,notwff);
  str((sin(b*pi/180))/(cos(b*pi/180)),ans2);
  prompt:=#133'h = '#134;
  solution::=dgm+#127'\nl\red{Solution:}\nl '+
  	'From the triangle we have tan('+st(b)+#30'`'#31') = '+
        makeformula('[h]/[a00]',['a'],v)+nl+#10+
        '=> h = '+st(a)+'00\cdot tan('+st(b)+#30'`'#31')'+nl+#10+
        '     '#163' '+st(a)+'00\cdot ('+ans2+')'+nl+#10+
        '     '#163' \z:2  feet.';
type:='R';
key :=4128;
end;

procedure s4128;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4130;
var
  a,b:integer;
  v:valuetype;
  x:paramtype;
  undef,notwff:boolean;
  ans1,ans2,dgm:string;
begin
  a:=randint(4,6);v.a:=a;
  b:=rand([56,58,65,68,72]);
  dgm::=#127'500,400,1200,10;I,200,160,35;L,0,0,3,0;L,0,0,3,6;L,3,0,3,6;'+
       'B,2;C,.6,.5,'+st(b)+'^{\circ};C,1.5,-.7,'+st(a)+';C,.8,3,L;';
  text1:=dgm+#127+
  	'A ladder leans against the side of a building making an angle  '+
  	'of '+st(b)+#30+'`'+#31+' with the ground. If the base '+
        'of the ladder is '+st(a)+' feet from the building, determine '+
	'the length L of ladder. Express your answer in feet.'+nl+nl;
  text3::=text1+'\blue{Hint:}\nl '+
  	'The cosine of the angle the ladder makes with the ground is '+
        st(a)+'/L.';
  help::='\red{Definitions of Trig Frunctions:}\nl '+
  	#127'500,500,800,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'C,2,-.5,x;C,4.2,3,y;C,.8,.25,\theta;C,1.2,3,r;'#127+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$';
  str(1.0*a/cos(b*pi/180):8:6,answer);
  x.z:=evaluate(answer,'',undef,notwff);
  str(cos(b*pi/180),ans2);
  prompt:=#133'L = '#134;
  solution::=dgm+#127+'\nl\red{Solution:}\nl '+
  	'From the triangle we have cos('+st(b)+#30'`'#31') = '+
	makeformula('[a]/[L]',['a'],v)+nl+#10+
        ' => L = '#29#219+st(a)+#221'/'#219'cos('+st(b)+#30'`'#31')'#221+nl+#10+
        '      '#163' '#29#219+st(a)+#221'/'#219+ans2+#221+nl+#10+
        '      '#163' \z:2.';

  type:='R';
  key:=4130;
end;

procedure s4130;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4131;
var
  a,b:integer;
  v:valuetype;
  x:paramtype;
  undef,notwff:boolean;
  ans1,ans2,dgm:string;
begin
  a:=rand([12,15,18,24,32]);v.a:=a;
  b:=rand([56,58,62,65,68]);
  dgm::=#127'500,400,1200,10;I,250,200,30;L,0,0,0,6;L,0,0,4,0;L,0,6,4,0;'+
       'D,0,6,4,6,4;B,2;C,-1.3,3,'+st(a)+';C,2,-.8,d;C,1.2,5,'+st(b)+'^{\circ};';
  text1:=dgm+#127+'From a point '+st(a)+' meters above level ground an '+
  	'observer measures the angle of depression of an object on the '+
	'ground as '+st(b)+#30+'`'+#31+'. Determine the distance d in '+
	'meters from the object to the point on the ground directly '+
	'beneath the observer.'+nl;
  text3::=text1+'\nl\blue{Hint:}\nl '+
  	'Express the tangent of the angle of depression in terms of d.';
  help::='\red{Definitions of Trig Frunctions:}\nl '+
  	#127'500,500,800,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'C,2,-.5,x;C,4.2,3,y;C,.8,.25,\theta;C,1.2,3,r;'#127+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$';
  dgm:=dgm+'C,2.3,.5,'#225';';
  replace('700,100','700,200',dgm);
  str(1.0*a*cos(b*pi/180)/sin(b*pi/180),answer);
  x.z:=evaluate(answer,'',undef,notwff);
  prompt:=#133'd = '#134;
  str(sin(b*pi/180)/cos(b*pi/180),ans2);
  solution::=dgm+#127'\nl\red{Solution:}\nl '+
  	'By alternate interior angles we have the angle of depression '+
	' = '#225' = '+st(b)+#30'`'#31'.'+nl+
        'Now tan(\alpha) = tan('+st(b)+#30'`'#31') = {opposite\over adjacent} '+
	' = {'+st(a)+'\over d}\pause\nl '+
	'=> d = {'+st(a)+'\over tan('+st(b)+'^{\circ})}\pause\nl '+
	'\doteq  {'+st(a)+'\over '+ans2+'}\pause\nl '+
	'\doteq  \z:2  meters.';
type:='R';
key :=4131;
end;

procedure s4131;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4132;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,a3,dgm,header,text,part1,part2,part3:string;
begin
  dgm::=#127'500,500,1200,10;I,100,100,50;L,-2,0,8,0;L,0,-2,0,8;B,2;'+
  	'P,4,0,1.57;B,0;L,0,0,4,5;L,4,5,4,0;L,2.5,3.09,2.5,0;'+
	'L,2.5,3.09,4,0;L,2.2,0,2.2,.3;L,2.2,.3,2.5,.3;B,4;'+
	'C,-.5,-.5,O;C,2.47,-.5,A;C,2.31,3.59,B;C,3.97,-.5,C;'+
	'C,3.94,5.37,D;B,2;C,.7,.26,x;'#127;
  header:='\red{Answer all three parts before grading.}';
  text:='In the diagram to the right the circular arc is part of the unit '+
  	'circle (the circle of radius 1 with center (0,0)).';
  part1:='\red{a: } Express OA in terms of x. (30%)';
  part2:='\red{b: } Express AB in terms of x. (30%)';
  part3:='\red{c: } Express BC in terms of x. (40%)';
  text1::=dgm+header+#13+#13+text+#13+part1+#13+part2+#13+part3+#13+#13+#13+#13;
  buff1:=dgm+text+#13+part1+#13+part2+#13+part3+#13;
  prompt::=#133'a: OA = '#134#13+
    	   #133'b: AB = '#134#13+
	   #133'c: BC = '#134#;
  help::='\red{Definitions of Trig Frunctions:}\nl '+
  	#127'500,500,800,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'C,2,-.5,x;C,4.2,3,y;C,.8,.25,\theta;C,1.2,3,r;'#127+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$';
  text3::=buff1+'\nl\blue{Message:}\nl '+
  	'Use the definitions of the trig functions to find OA and AB. To '+
	'find BC, use the fact that BC is the hypotenuse of the right '+
	'triangle ABC.';
  ans:=#134'cos(x)'#133+
       #134'sin(x)'#133+
       #134'\sqrt{2-2cos(x)}';
  answer::=ans;
  separate(ans,a1,a2,a3);
  solution::='\nl\red{Solution to part a: }\nl '+
  	'We use the right triangle OAB.\nl By definition cos(x) = '+
	'{adjacent\over hypotenuse} = {OA\over 1} = OA.\nl '+
	'Thus OA = cos(x).\pause\nl ';
  solution2::='\nl\red{Solution to part b: }\nl '+
        'We use the right triangle OAB.\nl By definition sin(x) = '+
	'{opposite\over hypotenuse} = {AB\over 1} = AB.\nl '+
	'Thus AB = sin(x).\pause\nl ';
  solution3::=dgm+'\nl\red{Solution to part c: }\nl '+
  	'We use the right triangle CAB. Now OA = cos(x) => AC = $$1-cos(x)$$.\pause\nl '+
	'By the Pythagorean Theorem\nl BC = $$\sqrt{AC^2+AB^2}\nl ='+
	'\sqrt{(1-cos(x))^2+(sin(x))^2}\nl=\sqrt{1-2cos(x)+cos^2(x)+sin^2(x)}\nl='+
	'\sqrt{2-2cos(x)}$$. The last equality made use of the Pythagorean '+
	'identity $$sin^2(x)+cos^2(x)=1$$.';
  type:='R';
  key:=4132;
end;	   

procedure s4132;
var
  r1,r2,r3,r4,a1,a2,a3:string;
  r:integer;
  check1,check2,check3,undef,notwff:boolean;
begin
  message:='';
  separate(response,r1,r2,r3);
  check1:=false;
  check2:=false;
  check3:=false;
  separate(answer,a1,a2,a3);
  check1:=sameexpres(a1,r1);
  check2:=sameexpres(a2,r2);
  check3:=sameexpres(a3,r3);
    if check1 and check2 and check3 then begin
    result:='T';
    message:=#141'Correct'#141;
  end else begin
    if check1 then begin
      r:=r+3;
      message:='a: '+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:='a: '+r1+' is '#140'incorrect'#140'.'+#13+nl;
      end;
    end;
    if check2 then begin
      r:=r+3;
      message:=message+'b: '+r2+' is '#141'correct.'#141+nl;
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+'b: '+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check3 then begin
      r:=r+4;
      message:=message+'c: '+r3+' is '#141'correct'#141'.'+nl;
    end else begin
      if r3 = '' then begin
        message:=message+#140'c: Incorrect.'#140+nl;
      end else begin
        message:=message+'c: '+r3+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  buff1::=buff1;
  message:=message+text3;
  end;
end;

procedure p4135;	{old 1216}
var
a,b,c,d,f,k:integer;
a1,a2,dgm,text,header,part1,part2,u,w:string;
notwff,undef:boolean;
v:valuetype;
x:paramtype;
p,q,r:real;
begin
  x.a:=rand([8,9,11,12,13,14])+rand([1..9])/10;
  x.b:=rand([31,34,41,44])+rand([1..9])/10;
  x.f:=rand([10,11,12,14])+rand([1..9])/10;
  dgm:=#127'600,500,1200,10;I,150,150,50;L,0,0,8,0;L,1,0,1,2;L,6,0,6,6;'+
       'L,7,0,7,6;L,1,2,6,0;L,1,2,6,6;L,6,6,7,6;D,1,2,6,2,6;B,2;C,.5,2,A;'+
       'C,5.5,2.1,B;C,5.7,-.5,C;C,5.7,6.3,P;C,7.4,2.6,h;B,0;L,7.5,3.4,7.5,6;'+
       'L,7.5,2.2,7.5,0;B,4;C,2.2,2.4,\b:1^{\circ};C,2.8,1.6,\f:1^{\circ};B,0;F,6.8,1;'+
       'B,4;C,-.7,.7,\a:1;';
  header:='\red{Answer both parts before grading.}';
  text:='From a point A that is \a:1  meters above '+
  	 'level ground, the angle of elevation of the top of a '+
	 'building is \b:1^{\circ}  while the angle of '+
	 'depression of the base of the building is '+
         '\f:1^{\circ}.';
  part1:='\red{a: } Determine the distance AB in meters. (40%)';
  part2:='\red{b: } Determine the height h of the building in meters. (60%)';
  text1::=dgm+#127+header+#13+#13+text+#13+part1+#13+part2+#13;
  buff1:=dgm+#127+text+#13+part1+#13+part2+#13;
  text3::=text+nl+part1+nl+part2+nl+'\nl\blue{Hint:}\nl '+
  	'Use \dif ABC and an appropriate trig function to compute AB. Then '+
	'use \dif ABP and an appropriate trig function to compute BP. Then '+
	'determine h.';
  help::='\red{Definitions of Trig Frunctions:}\nl '+
  	#127'500,500,800,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'C,2,-.5,x;C,4.2,3,y;C,.8,.25,\theta;C,1.2,3,r;'#127+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$';
  prompt::=#133'AB = '#134#13+
  	   #133'h = '#134;
  x.t:=1/tan(x.f*pi/180);
  x.u:=tan(x.b*pi/180);
  str(x.a/tan(x.f*pi/180),a1);
  x.w:=evaluate(a1,'',undef,notwff);
  x.y:=x.w*tan(x.b*pi/180);
  str(x.a+x.y,a2);
  answer:=#134+a1+#133#134+a2;
  x.z:=evaluate(a2,'',undef,notwff);
  solution::='\nl\red{Solution to part a:}\nl '+dgm+#127+
  	'Note that CB = \a:1. Now using \dif ABC we have\nl '+ 
	'$$AB=CB\cdot cot(\f:1^{\circ})=\a:1\cdot (\t:6)$$ \doteq  \w:4  meters.\pause\nl ';
  solution2::='\nl\red{Solution to part b:}\nl '+
  	'$$BP=AB\cdot tan(\b:1^{\circ})=\w:4\cdot (\u:6)$$ \doteq  \y:4  meters.\pause\nl '+
	'Now h = CB + BP = \a:1  +  \y:4  \doteq  \z:4  meters.';
  type:='R';
  key:=4135;
end;

procedure s4135;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4138;	{old 1281}
var
  x:paramtype;
  undef,notwff:boolean;
  a1,a2,ans,dgm,header,text,part1,part2:string;
begin
  x.a:=100*rand([52,55,60,64,72]);
  x.b:=rand([38,39,41,43])+rand([1..9])/10;
  x.c:=rand([31,32])+rand([1..9])/10;
  x.f:=rand([12,14,16,18,20]);
  header:='\red{Answer both parts before grading.}';
  dgm::=#127'500,500,1200,10;I,200,200,30;B,4;C,4.2,1.7,\alpha;'+
	'C,2.1,.3,\gamma;B,0;L,0,0,8,0;L,6,4,6,8;L,1,0,6,4;'+
        'L,1,0,6,8;D,6,0,6,4,4;B,2;C,1,-.8,A;C,6,-.8,B;C,6.2,4,C;C,6.2,8,P;'+
        'B,0;C,-1,7,\alpha=\b:1^{\circ};'+
        'C,-1,5.5,\gamma=\c:1^{\circ};'+
        'C,3,-.8,\a;I,230,200,30;P,3.5,0,1.05;P,2,0,.6;';
  text:='An observer is at a point A \a  meters horizontally across '+ 
         'from a point B where a hot air balloon begins rising at constant '+ 
         'speed. The angle of elevation of the balloon changes '+
	 'from \c:1^{\circ}  to \b:1^{\circ}  in \f  seconds.';
  part1:='\red{a: } Determine CP the distance from C to P in meters. (60%)';
  part2:='\red{b: } Determine the velocity v of the balloon in meters '+
  	'per second. (40%)'; 
  text1::=dgm+#127+header+nl+nl+text+nl+part1+nl+part2+nl;
  buff1:=dgm+#127+text+nl+part1+nl+part2+nl;
  prompt::=#133'a: CP = '#134#13+
  	   #133'b: v = '#134;
  help::='\red{Definitions of Trig Frunctions:}\nl '+
  	#127'500,500,800,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'C,2,-.5,x;C,4.2,3,y;C,.8,.25,\theta;C,1.2,3,r;'#127+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$\nl '+
	'velocity = {distance\over time}';
  text3::=buff1+'\nl\blue{Hint:}\nl '+
  	'The balloon moved through the distance from C to P in \f  seconds.\nl '+
	'Velocity equals {distance\over time}.';
  x.p:=tan(x.c*pi/180);
  x.q:=tan(x.b*pi/180);
  x.r:=x.a*x.p;
  x.s:=x.a*x.q;
  str(x.s-x.r,a1);
  x.u:=evaluate(a1,'',undef,notwff);
  x.v:=x.u/x.f;
  str(x.v,a2);
  ans:=#134+a1+#133#134+a2;
  answer::=ans;
  solution::='\nl\red{Solution to part a:}\nl '+
  	'CP = BP - BC.\pause\nl '+
	'From \dif ABC we have $$BC=AB\cdot tan(\gamma)\nl=AB\cdot tan(\c:1^{\circ})'+
	'\nl\doteq\a\cdot\p:4\doteq\r:2$$.\pause\nl '+
	'From \dif ABP we have $$BP=AB\cdot tan(\alpha)\nl=AB\cdot tan(\b:1^{\circ})'+
	'\nl\doteq\a\cdot\q:4\doteq\s:2$$.\pause\nl '+
	'Now $$CP=BP-BC=\s:2-\r:2\doteq\u:2$$  meters.\pause\nl';
  solution2::='\nl\red{Solution to part b:}\nl '+#10+dgm+#127+
  	'The balloon covered \u:2  meters in \f  seconds. Thus the velocity '+
	'of the balloon is $${\u:2\over \f}\doteq\v:2$$  meters per second.';
  type:='R';
  key:=4138;
end;

procedure s4138;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+6;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+4;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4139;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text:string;
begin
  x.a:=rand([46..59])+rand([1..9])/10;
  x.b:=rand([2..9]);
  dgm::=#127'600,500,1200,10;I,150,100,50;B,4;C,2.2,.7,\a:1^{\circ};B,0;'+
  	'L,-2,0,8,0;L,0,-2,0,8;L,0,0,5,7;B,2;G,7x^2/25,0,6;'+
	'C,3,2.1,y=\b x^2;B,0;P,2,0,1;L,5,0,5,7;C,-.5,-.5,O;C,4.9,-.5,B;'+
	'C,5.2,7,P=(x,y);';
  text:='Find the point P(x,y) on the parabola $$y=\b x^2$$ such that the '+
  	'angle between the line OP and the positive x-axis is \a:1^{\circ}.';
  text1::=dgm+#127+text+nl+nl+nl+nl+nl+nl+nl;
  prompt::=#133'P = '#134;
  help::='\red{Definitions of Trig Frunctions:}\nl '+
  	#127'500,500,800,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'C,2,-.5,x;C,4.2,3,y;C,.8,.25,\theta;C,1.2,3,r;'#127+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$';
  text3::=dgm+#127+text+nl+'\nl\blue{Hint:}\nl '+
  	'Use \dif OBP to express tan(\a:1^{\circ}) in terms of x and y. '+
	'Then use the fact that (x,y) is on the parabola.';
  x.r:=tan(x.a*pi/180);
  x.s:=x.r/x.b;
  x.y:=x.b*x.s^2;
  answer::='(\s:6,\y:6)';
  solution::='\nl\red{Solution:}\nl '+
  	'From the right triangle \dif OBP we have tan(\a:1^{\circ}) = '+
	'{y\over x}. Since (x,y) lies on the parabola $$y=\b x^2$$, we '+
	'have $$tan(\a:1^{\circ})={\b x^2\over x}=\b x$$.\pause\nl '+
	'Thus $$x={tan(\a:1^{\circ})\over \b}\doteq{\r:6\over \b}\doteq\s:6$$.\pause\nl '+
	'Now $$y=\b x^2\doteq\b(\s:6)^2\doteq\y:6$$.\pause\nl '+
	'Thus P = (x,y) = '+answer+'.';
  type:='R';
  key:=4139;
end;

procedure s4139;
var
  mes:string;
begin
  replace(prompt,'',response);
  mes:='';
  if pos('(',response)=-1 then
    mes:='The co-ordinates of a point must be enclosed with parentheses,';
  if samepoints(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+mes+#13+text3;
  end;
end;

procedure p4141;	{old 1089}
var
  i:integer;
  astr,bstr,dgm:string;
  q1,q2:set of integer;
begin
  dgm:=#127'500,500,700,10;I,250,250,50;L,-4,0,4,0;L,0,-4,0,4;'+
  	'E,-4,-4,4,4;B,2;C,-2.8,2.4,cos\theta<0;C,-2.8,1.5,sin\theta>0;'+
	'C,.7,2.4,cos\theta>0;C,.7,1.5,sin\theta>0;C,-2.8,-1.5,cos\theta<0;'+
	'C,-2.8,-2.4,sin\theta<0;C,.7,-1.5,cos\theta>0;C,.7,-2.4,sin\theta<0;'+
	'B,4;C,.5,.5,1;C,-.8,.5,2;C,-.8,-.7,3;C,.5,-.7,4;'#127;
  case randint(1,6) of
  1:begin
      astr ::= 'sin \theta  > 0';
      solution2 ::= 'sin \theta  > 0 '+
      	'when \theta  is in'+nl+'quadrants 1 or 2.'+#10+nl;
      q1 := [1,2];
    end;
  2:begin
      astr ::= 'sin \theta  < 0';
      solution2 ::= astr+' when \theta  is in'+nl+'quadrants 3 or 4.'+#10+nl;
      q1 := [3,4];
    end;
  3:begin
      astr ::= 'cos \theta  > 0';
      solution2 ::= astr+' when \theta  is in'+nl+'quadrants 1 or 4.'+#10+nl;
      q1 := [1,4];
    end;
  4:begin
      astr ::= 'cos \theta  < 0';
      solution2 ::= astr+' when \theta  is in'+nl+'quadrants 2 or 3.'+#10+nl;
      q1 := [2,3];
    end;
  5:begin
      astr ::= 'tan \theta  > 0';
      solution2 ::= 'tan \theta = {sin \theta\over cos \theta}  > 0 '+
      	'when \theta  is in'+nl+'quadrants 1 or 3.'+#10+nl;
      q1 := [1,3];
    end;
  6:begin
      astr ::= 'tan \theta  < 0';
      solution2 ::= 'tan \theta = {sin \theta\over cos \theta}  < 0 '+
      	'when  \theta  is in'+nl+'quadrants 2 or 4.'+#10+nl;
      q1 := [2,4];
    end;
  end;
  case randint(1,6) of
  1:begin
      bstr ::= 'csc \theta  > 0';
      solution3 ::= 'csc \theta  = {1\over sin \theta}  > 0 '+
      	'when \theta  is in'+nl+'quadrants 1 or 2.'+#10+nl;
      q2 := [1,2];
    end;
  2:begin
      bstr ::= 'csc \theta  < 0';
      solution3 ::= 'csc \theta  = {1\over sin \theta}  < 0 '+
      	'when \theta  is in'+nl+'quadrants 3 or 4.'+#10+nl;
      q2 := [3,4];
    end;
  3:begin
      bstr ::= 'sec \theta  > 0';
      solution3 ::= 'sec \theta  = {1\over cos \theta}  > 0 '+
       	'when \theta  is in'+nl+'quadrants 1 or 4.'+#10+nl;
      q2 := [1,4];
    end;
  4:begin
      bstr ::= 'sec \theta  < 0';
      solution3 ::= 'sec \theta  = {1\over cos \theta}  < 0 '+
      	'when \theta  is in'+nl+'quadrants 2 or 3.'+#10+nl;
      q2 := [2,3];
    end;
  5:begin
      bstr ::= 'cot \theta  > 0';
      solution3 ::= 'cot \theta  = {cos \theta\over sin \theta}  > 0 '+
      	'when \theta  is in'+nl+'quadrants 1 or 3.'+#10+nl;
      q2 := [1,3];
    end;
  6:begin
      bstr ::= 'cot \theta  < 0';
      solution3 ::= 'cot \theta  = {cos \theta\over sin \theta}  > 0 '+ 
      	'when \theta  is in'+nl+'quadrants 2 or 4.'+#10+nl;
      q2 := [2,4];
    end;
  end;
  text1::='Determine the quadrant(s) (1,2,3,4) in which '+
    'both '+astr+' and '+bstr+'. If there are none, '+
    'answer 0. Separate multiple answers with a comma.'+nl;
  help::=dgm+'\red{Signs of Trig Functions:}\nl '+
  	'\ \ $$tan\theta={sin\theta\over cos\theta}$$\nl '+
	'\ \ $$cot\theta={cos\theta\over sin\theta}$$\nl '+
	'\ \ $$sec\theta={1\over cos\theta}$$\nl '+
	'\ \ $$csc\theta={1\over sin\theta}$$';
  replace('700,10','1200,10',dgm);
  text3::=text1+'\nl\blue{Hint:}\nl '+dgm+
    'Determine the sign of sin \theta  and cos \theta  in each quadrant '+
    'from the unit circle. Relate the remaining trig functions to sin \theta  '+
    'and/or\nl cos \theta.';
  prompt::=#133'Quadrants with '+astr+' and '+bstr+': '#134;
  for i := 1 to 4 do
    if (i in q1) and (i in q2) then answer := answer+','+chr(48+i);
  if length(answer) = 0 then begin
    answer := '0';
    solution4 := 'Together they are true'+nl+'in no quadrant.';
  end else begin
    delete(answer,0,1);
    solution4 := 'Together they are true'+nl+'true in quadrant '+answer+'.';
  end;
  if length(answer) > 1 then insert('s',solution4,39);
  solution::='\nl\red{Solution:}\nl '; 
  key := 4141;
  type := 'R';
end;

procedure s4141;
var
  notfound:boolean;
  i:integer;
  newchar:char;
  re,an:string;
begin
  re:=response;
  replace('IV','4',re);
  replace('III','3',re);
  replace('II','2',re);
  replace('I','1',re);
  an:=answer;
  if sameconstants(an,re) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    replace(prompt,'',re);
    if re = '' then message :=#140'Incorrect'#140
    else message := response+' is '#140'incorrect'#140'.';
    message := message +nl+text3;
  end;
end;

procedure p4142;	{old 1289}
var
  a,b,c,d,e,f,j,k,l,m,n:integer;
  v:valuetype;
  x:paramtype;
  dgm,p,q,r,s,t,u,w,z,temp:string;
  trig,ratio,mes,sym:array[1..6] of string;
  undef,notwff:boolean;
begin
  trig[1]:='sin '+#244;sym[1]:='{b\over r}';
  trig[2]:='cos '+#244;sym[2]:='{a\over r}';
  trig[3]:='tan '+#244;sym[3]:=sym[1];
  trig[4]:='cot '+#244;sym[4]:='{a\over b}';
  trig[5]:='sec '+#244;sym[5]:='{r\over a}';
  trig[6]:='csc '+#244;sym[6]:='{r\over b}';
  b:=rand([2,3,4,5,6]);v.b:=b;x.b:=b;
  e:=rand([-3,-2,-1,2,3]);v.e:=e;x.e:=e;
  k:=randint(1,6);
  c:=1+b*b;v.c:=c;x.c:=c;
  ratio[1]:='$${$\b\over \sqrt{\c}$}$$';
  ratio[2]:='$${$-1\over \sqrt{\c}$}$$';
  ratio[3]:='-\b';
  ratio[4]:='$${$-1\over \b$}$$';
  ratio[5]:='$$-\sqrt{\c}$$';
  ratio[6]:='$${\sqrt{\c}\over \b}$$';
  answer::=ratio[k];
  str(arctan(-b)+pi,z);
  str(2.5*cos(evaluate(z,'',undef,notwff)/2),p);
  str(2.5*sin(evaluate(z,'',undef,notwff)/2),q);
  dgm:=#127'300,300,1350,10;A,150,150,30;B,2;G,-\b x,-5,0;B,4;P,2,0,'+z+';'+
  	 'C,'+p+','+q+','#244';'#127#127'300,300,900,10;A,150,150,30;'+
	 'B,2;G,-\b x+\e,-5,5;'+
         'B,0;C,.2,4,y=-\b x+\e;'#127;
  text1::=dgm+'Find the value of '+trig[k]+' if \theta  lies in '+
         'quadrant 2, and the terminal side of \theta  is '+
         'parallel to the line $$y=-\b x+\e$$.'+nl+nl+nl+nl;
  help::='\red{Definitions of Trig Frunctions:}\nl '+
  	#127'500,500,800,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'C,2,-.5,x;C,4.2,3,y;C,.8,.25,\theta;C,1.2,3,r;'#127+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$\nl '+
	'The slope of a line is the tangent of the angle from the x-axis to '+
	'the line going counter-clockwise.';
  replace('+-','-',text1);
  prompt::=#133+trig[k]+' = '#134;
  mes[1]:='Then if r denotes the distance from (a,b) to (0,0) then '+
  	'sin \theta  = {b\over r}.';
  mes[2]:='Then if r denotes the distance from (a,b) to (0,0) then '+
  	'cos \theta  = {a\over r}.';
  mes[3]:='Then tan \theta  = {b\over a}.';
  mes[4]:='Then cot \theta  = {a\over b}.';
  mes[5]:='Then if r denotes the distance from (a,b) to (0,0) then '+
  	'sec \theta  = {r\over a}.';
  mes[6]:='Then if r denotes the distance from (a,b) to (0,0) then '+
  	'csc \theta  = {r\over b}.';
  text3::=text1+#13+'\nl\blue{Hint:}\nl '+
	'Find the equation of the line containing the terminal side of \theta  '+
    	'and then find a point (a,b) on the terminal side of \theta. '+mes[k];
  replace(+#13+#13+#13,'',text3);
  solution::=#127'300,300,1350,10;A,150,90,30;B,2;G,-\b x,-5,5;B,0;C,-4.8,\b,(-1,\b);'+
	'G,\b,D-1,-1;C,.5,4,y=-\b x;B,4;P,2,0,'+z+';C,'+p+','+q+',\theta;'#127+
  	#127'300,300,900,10;A,150,150,30;B,2;G,-\b x+\e,-5,5;'+
        'B,0;C,.5,4,y=-\b x+\e;'#127+
  	'\nl\red{Solution:}\nl '+
	'Since the terminal side of \theta  is parallel to $$y=-\b x+\e$$, '+
	'the slope of the terminal side is -\b.\pause  Thus the terminal side '+
	'is on the line\nl $$y=-\b x$$.\pause  Letting x = -1 we find $$y=\b$$, '+
	'and so the point (a,b) = (-1,\b) is on the terminal side of \theta.\pause\nl';
  replace('+-','-',solution2);
  if k in [1,2,5,6] then
    solution2::='Now $$r=\sqrt{(-1)^2+(\b)^2}=\sqrt{\c}$$.\pause\nl '+
  	  'Thus '+trig[k]+' = '+sym[k]+' = '+ratio[k]+'.'
  else
    solution2::='Thus '+trig[k]+' = '+sym[k]+' = '+ratio[k]+'.';
type:='R';
key := 4142;
end;

procedure s4142;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4145;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,a3,dgm,header,text,part1,part2,part3:string;
begin
  x.a:=rand([10..20]);
  x.b:=2*x.a^2;
  x.c:=x.a^2;
  dgm::=#127'500,500,1200,10;I,250,250,50;L,3,0,.93,2.85;'+
  	'L,.93,2.85,-2.43,1.76;L,-2.43,1.76,-2.43,-1.76;'+
	'L,-2.43,-1.76,.93,-2.85;L,.93,-2.85,3,0;E,-3,-3,3,3;'+
	'C,1.4,-.5,\a;B,2;F,2,1.7;F,-2.75,-.13;F,2.13,-1.8;B,0;L,0,0,3,0;'+
	'L,0,0,.93,2.85;B,4;C,-.5,-.4,O;C,.93,3,B;C,3.2,-.13,A;';
  header:='\red{Answer all three parts begore grading}';
  text:='A regular pentagon is inscribed in a circle of radius \a.';
  part1:='\red{a: } Find the area of the circular sector OAB. (33.3%)';
  part2:='\red{b: } Find the area of triangle OAB. (33.3%)';
  part3:='\red{c: } Find the area of the shaded region. (33.3%)';
  text1::=dgm+#127+header+#13+#13+text+#13+part1+#13+part2+#13+part3+#13+#13;
  buff1:=dgm+#127+text+#13+part1+#13+part2+#13+part3+#13;
  prompt::=#133'a: area of sector OAB: '#134#13+
    	   #133'b: area of \dif OAB: '#134#13+
	   #133'c: area of shaded region: '#134#;
  help::=#127'400,400,800,10;I,80,200,40;L,0,0,5,0;L,0,0,4.3,2.5;P,5,0,.53;'+
  	'B,2;C,2.4,-.5,r;C,2.2,1.8,r;C,5,1.2,s;B,4;C,1.4,.2,\theta;'#127+
  	'\red{Circular Sectors:}\nl '+
	'\ \ A = {1\over 2}r^2\theta\nl '+
	'\ \ s = r\cdot\theta\nl\nl '+
	#127'500,500,800,10;I,100,300,50;L,0,0,4,0;L,0,0,3,2;L,4,0,3,2;'+
  	'B,4;C,.8,.1,\theta;B,2;C,2,-.5,a;C,1.5,1.5,b;'#127+
	'\red{Area of Triangle:}\nl '+
	'\ \ {1\over 2}\cdot base\cdot height\nl '+
	'\ \ {1\over 2}\cdot a\cdot b\cdot sin(\theta)';
  text3::=buff1+#13+'\nl\blue{Hint:}\nl '+
  	'Use the formula for the area of a circular sector: A = {1\over 2}r^2'+
	'\theta  and the formula for the area of a triangle: A = {1\over 2}'+
	'absin(\theta) where \theta  is the angle between a and b. Then '+
	'find the area of one piece of the shaded region.';
  x.w:=x.a^2*pi/5;
  x.r:=sin(2*pi/5);
  x.y:=.5*x.c*x.r;
  x.z:=3*(x.w-x.y);
  ans:=#134'\w:6'#133+ 
       #134'\y:6'#133+
       #134'\z:6';
  answer::=ans;
  replace('1200,10','1200,-300',dgm);
  solution::='\nl\red{Solution to part a: }\nl '+
  	'The angle AOB is {2\pi\over 5} radians and the radius of the '+
	'circular sector is \a.\pause\nl '+
	'Thus the area of the circular sector is\nl '+
	'{1\over 2}\cdot r^2\cdot\theta\nl '+
	'= {1\over 2}\cdot(\a)^2\cdot{2\pi\over 5}\pause\nl '+
	'= {$\b\pi\over 5$}\nl '+
	'\doteq  \w:6.'+dgm+
  	'B,4;C,.8,.8,{2\pi\over 5};P,1,0,1.25;'#127'\pause\nl';
  solution2::='\nl\red{Solution to part b: }\nl '+
  	'The triangle OAB is an isosceles triangle and the angle between '+
	'the equal sides is {2\pi\over 5}.\pause  Thus the area of \dif OAB is '+
	'{1\over 2}\cdot\a\cdot\a\cdot sin({2\pi\over 5})\pause\nl '+
	'\doteq  {$\c\over 2$}\cdot\r:6\pause\nl '+
	'\doteq  \y:6.\pause\nl';
  solution3::='\nl\red{Solution to part c: }\nl '+
  	'The area of the shaded region is\nl '+
	'3\cdot(area of sector AOB - area of \dif AOB)\nl '+
	'= 3\cdot(\w:6-\y:6)\pause\nl '+
	'\doteq  \z:6.';
  type:='R';
  key:=4145;
end;		       

procedure s4145;
var
  r1,r2,r3,r4,a1,a2,a3:string;
  r:integer;
  check1,check2,check3,undef,notwff:boolean;
  score:real;
begin
  message:='';
  score:=0.0;
  separate(response,r1,r2,r3);
  check1:=false;
  check2:=false;
  check3:=false;
  separate(answer,a1,a2,a3);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  check3:=sameconstants(a3,r3);
    if check1 and check2 and check3 then begin
    result:='T';
    message:=#141'Correct'#141;
  end else begin
    if check1 then begin
      score:=score+3.33;
      message:='a: '+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:='a: '+r1+' is '#140'incorrect'#140'.'+#13+nl;
      end;
    end;
    if check2 then begin
      score:=score+3.33;
      message:=message+'b: '+r2+' is '#141'correct.'#141+nl;
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+'b: '+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check3 then begin
      score:=score+3.33;
      message:=message+'c: '+r3+' is '#141'correct'#141'.'+nl;
    end else begin
      if r3 = '' then begin
        message:=message+#140'c: Incorrect.'#140+nl;
      end else begin
        message:=message+'c: '+r3+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  r:=round(score);
  result:=chr(48+r);
  message:=message+text3;
  end;
end;

procedure p4146;	{old 1080}
var
  a,b,t:integer;
  ss:string;
  x:paramtype;
begin
  t := randint(1,2);
  case t of
  1:begin
      a := rand([0..7,9..16]) - 8;x.a:=a;
      b := randint(1,10);x.b:=b;
      x.c:=180*x.a/x.b;
      text1::= 'Convert {$\a\pi\over \b$} radians to degrees.'+nl;
      answer::= '\c:6^{\circ}';
      text3::= text1+'\nl\blue{Hint:}\nl '+
        'Use the fact that $$360^{\circ}=2\pi$$ radians.';
      prompt::=#133'{$\a\pi\over \b$} radians = '#134;
      solution::= '\nl\red{Solution:}\nl '+
        '$$360^{\circ}=2\pi$$ radians\pause\nl '+
	'=> 1 radian = {180\over \pi} degrees\pause\nl '+
	'=> {$\a\pi\over \b$} = {$\a\pi\over \b$}\cdot {180\over \pi} = '+
	+answer+'.';
    end;
  2:begin
      a := randint(1,360);x.a:=a;
      x.c:=x.a*pi/180;
      text1::= 'Convert \a^{\circ}  to radians.'+nl;
      answer::= '\c:6  radians';
      text3::= text1+'\nl\blue{Hint:}\nl '+
        'Use the fact that $$360^{\circ}=2\pi$$ radians.';
      prompt::=#133'\a^{\circ} = '#134;
      solution::= '\nl\red{Solution:}\nl '+
        '$$360^{\circ}=2\pi$$ radians\pause\nl '+
	'=> 1^{\circ} = {\pi\over 180} radians\pause\nl '+
	'=> \a^{\circ} = {\a\pi\over 180} = '+answer+'.';
    end;
  end;
  help::='\red{Radians and Degrees:}\nl '+
  	'\ \ $$360^{\circ}=2\pi$$ radians\nl '+
	'\ \ $$1^{\circ}={\pi\over 180}$$ radians\nl '+
	'\ \ $$1\ radian={180\over \pi} degrees$$';
  key := 4146;
  type := 'R';
end;

procedure s4146;
var
  dummy:string;
begin
  dummy := response;
  cleanc(dummy);
  if (pos('`',answer) > -1) and (pos('`',dummy) = -1) then
    dummy := dummy + #30'`'#31;
  if sameconstants(answer,dummy) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    replace(prompt,'',response);
    result := 'F';
    if response = '' then message := #140'Incorrect '#140+nl+text3
    else message := response+' is '#140'incorrect'#140'. '+nl+text3;
  end;
end;

procedure p4147;
var
  ang,a,b,c,n,t:integer;
  units:array[1..4] of string;
  ss,ss2:string;
begin
  t := randint(1,3);
  ang := randint(1,2);
  n := randint(1,4);
  units[1] := 'inches'; units[2] := 'mm';
  units[3] := 'feet'; units[4] := 'cm';
  case t of
  1:begin
      a := randint(3,20);
      if ang = 1 then begin
        b := randint(10,200);
        ss := st(b)+' degrees';
        str(a*180/(b*Pi):7:4,ss2);
        solution := st(a)+' = r\cdot{\pi\over 180}\cdot '+st(b)+#10+nl+
          'so r = '+st(a)+'\cdot 180/('+st(b)+'~) = ';
      end else begin
        b := randint(1,20);
        ss := fraction(b,'-',6)+'~ radians';
        str(a*6/(b*Pi):7:4,ss2);
        solution := st(a)+' = r\cdot '+fraction(b,'-',6)+'~'+#10+nl+
          'so r = '+st(a)+fraction(6,'-',b)+'/~ = ';
      end;
      text1 := 'If an arc of length '+st(a)+' '+units[n]+' subtends an angle '+
          'of '+ss+', determine the radius r of the circle'+nl;
      prompt::=#133'r = '#134;	
      answer := ss2+' '+units[n];
      solution::='\nl\red{Solution:}\nl '+ solution + answer;
    end;
  2:begin
      a := randint(3,20);
      c := randint(2,6)*a;
      str(a/c:7:4,ss); ss := ss + ' radians';
      str(a/c*180/Pi:6:2,ss2); ss2 := ss2 + ' degrees';
      text1::= 'What size angle \theta  does an arc of '+st(a)+' '+units[n]+
        ' subtend in a circle of radius '+st(c)+' '+units[n]+'? '+
        'Specify the units of your answer.'+nl;
      prompt::=#133'\theta  = '#134;
      answer := ss+' or '+ss2;
      solution::='\nl\red{Solution:}\nl '+ 
        st(a)+' = '+st(c)+'\cdot\theta'+#10+nl+
        'so \theta = '+st(a)+'/'+st(c)+'\nl = '+answer;
    end;
  3:begin
      c := randint(5,30);
      if ang = 1 then begin
        b := randint(10,200);
        ss := st(b)+' degrees';
        str(b*c*Pi/180:5:2,ss2);
        solution := 's = '+st(c)+'\cdot '+st(b)+'(~/180)'+#10+' = ';
      end else begin
        b := randint(1,20);
        ss := fraction(b,'-',6)+'~ radians';
        str(b*c*Pi/6:5:3,ss2);
        solution := 's = '+st(c)+'\cdot '+fraction(b,'-',6)+'~'+#10+' = ';
      end;
      text1 := 'If a circle has a radius of '+st(c)+' '+units[n]+', '+
        'determine the length of an arc s subtended by an angle of '+ss+'.'+nl;
      prompt::=#133's = '#134;
      answer := ss2+' '+units[n];
      solution::= '\nl\red{Solution:}\nl '+solution+answer;
    end;
  end;
  text3::=text1+'\nl\blue{Hint:}\nl '+
  	#127'400,400,1000,10;I,80,200,40;L,0,0,5,0;L,0,0,4.3,2.5;P,5,0,.53;'+
  	'B,2;C,2.4,-.5,r;C,2.2,1.8,r;C,5,1.2,s;B,4;C,1.4,.2,\theta;'#127+
	'$$s=r\theta$$ where \theta  is an angle measured in radians.';
  help::=#127'400,400,800,10;I,80,200,40;L,0,0,5,0;L,0,0,4.3,2.5;P,5,0,.53;'+
  	'B,2;C,2.4,-.5,r;C,2.2,1.8,r;C,5,1.2,s;B,4;C,1.4,.2,\theta;'#127+
  	'\red{Circular Sectors:}\nl '+
	'\ \ \theta  denotes an angle in radians\nl '+
	'\ \ A = {1\over 2}r^2\theta\nl '+
	'\ \ s = r\cdot\theta\nl\nl '+
	'\red{Radians and Degrees:}\nl '+
  	'\ \ $$360^{\circ}=2\pi$$ radians\nl '+
	'\ \ $$1^{\circ}={\pi\over 180}$$ radians\nl '+
	'\ \ $$1\ radian={180\over \pi} degrees$$';
  key := 4147;
  type := 'R';
end;

procedure s4147;
var
  correct:boolean;
  f,fd,fr,text:string;
  a:integer;
begin
  correct := true;
  f := response;
  toupper(f);
  a := pos(#30'`'#31,f);
  if a > -1 then begin
    delete(f,a,3);
    f := f + ' DEG';
  end;
  a := pos('or',answer);
  if a > -1 then begin
    fr := copy(answer,1,a);
    fd := copy(answer,a,10);
    correct := (sameconstants(fd,f) and (pos('DEG',f) > 0)) or
               (sameconstants(fr,f) and (pos('RAD',f) > 0));
  end else
    correct := sameconstants(answer,f);
  if correct then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    replace(prompt,'',response);
    result := 'F';
    if response = '' then message :=#140'Incorrect'#140+#13+text3 
    else message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4149;
var
  a,b,c,k,n : integer;
  ans,dgm : string;
  x:paramtype;
  undef,notwff:boolean;
begin
  case randint(1,4) of
    1 : begin
      a := randint(10,18);
      dgm:=#127'500,500,1200,10;I,250,250,50;E,-3,-3,3,3;L,0,0,0,-3;L,-3,-3,3,-3;'+
        'B,2;C,.1,-1.5,'+st(a)+';';
      text1 := dgm+#127'A bicycle tire has radius ' + st(a) + ' inches. How many '+
        'revolutions does it make in one mile? (1 mile = 5280 ft.)'+nl+
        nl+nl+nl+nl+nl+nl+nl;
      prompt::=#133'rev/mi = '#134;
      str(10084.057/a:6:2,answer);
      solution::='\nl\red{Solution:}\nl '+ 
      	'r = '+st(a)+' in.'+#10+nl+
        's = distance (in inches)'+#10+
        '= 5280\cdot 12 = 63360 in.'+#10+nl+
        'so '#244' = {s\over r} = 63360/'+st(a)+'.'#10+nl+
        'Thus the number of revolutions is '#244'/(2~) '+
	'= {63360\over '+st(2*a)+'\pi}\doteq  '+answer+'.';
    end;
    2 : begin
      n := randint(250,500);
      dgm:=#127'500,500,1200,10;I,250,250,50;E,-3,-3,3,3;L,0,0,0,-3;L,-3,-3,3,-3;'+
        'B,2;C,.2,-1.5,r;';
      text1 :=dgm+#127'A bicycle tire makes ' + st(n) + ' revolutions in one ' +
        'mile. What is its radius r in inches? (1 mile = 5280 ft.)'+nl+
        nl+nl+nl+nl+nl+nl+nl;
      prompt::=#133'r = '#134;
      str(10084.057/n:4:3,answer);
      solution::= '\nl\red{Solution:}\nl '+
        's = distance (in inches) = 5280\cdot 12 = 63360 in.'#10+nl+
        '1 revolution = 2~, so '#244' = 2~\cdot '+st(n)+' = '+st(2*n)+'~.'#10+nl+
        'Then r = s/'#244' = {63360\over '+st(2*n)+'\pi} \doteq  '+answer+' inches.';
    end;
    3 : begin
      a := randint(10,50);
      repeat b := randint(3,8) until 2*b<a;
      dgm:=#127'320,400,1200,10;I,160,400,50;B,2;C,-.1,-6.7,'+st(b)+';B,0;P,6,4.2,5.3;'+
        'L,0,0,3,-5.1;L,0,0,-3,-5.1;G,-5.1,D3,3;G,-5.1,D-3,-3;'+
        'B,2;C,2.3,-3,'+st(a)+';C,-.1,-1.5,\theta;';
      text1::=dgm+#127'A pendulum of length '+ st(a) + ' cm. travels through an ' +
        'arc of '+st(b)+' cm. What is the angle \theta  (in radians) '+
        'between its extreme positions?'+nl+nl+nl+nl+nl+nl+nl+nl;
      prompt::=#133'\theta  = '#134;
      str(b/a,answer);
      x.z:=evaluate(answer,'',undef,notwff);
      solution::='\nl\red{Solution:}\nl '+ 
        'r = '+st(a)+#10+nl+
        's = '+st(b)+#10+nl+
        'so '#244' = {s\over r} = {'+st(b)+'\over '+st(a)+'} \doteq  '+answer+'.';
    end;
    4 : begin
      a := randint(5,30); b := randint(65,85);
      dgm:=#127'600,300,1200,10;I,150,150,50;E,-1,-1,1,1;E,3,-3,9,3;'+
        'L,-.2,1,5.2,2.9;L,-.2,-1,5.2,-2.8;L,0,0,.7,.7;L,6,0,8.1,2.1;'+
	'B,2;C,-.6,.3,'+st(a)+';C,7.2,.8,'+st(b)+';';
      text1 :=dgm+#127'Two pulleys are connected by a belt.'+
        ' The radius of one pulley is '+st(a)+
        ' cm. and the radius of the other is '+st(b)+
        ' cm. If the larger one rotates once, how many times N'+
        ' does the smaller one rotate?'+nl+nl+nl+nl+nl;
      prompt::=#133'N = '#134;
      str(b/a,answer);
      x.z:=2*pi*b/a;
      solution::= '\nl\red{Solution:}\nl '+
        'If the larger one rotates once, the belt moves 2~\cdot '+
        st(b)+' cm.'+#10+nl+
        'A point on the rim of the smaller pulley must move through '+
	'the same distance. So s = 2~\cdot '+st(b)+' and r = '+st(a)+'.'#10+nl+
        'So '#244' = s/r = {2~\cdot '+st(b)+'\over '+st(a)+'} \doteq  \z:4.'#10+nl+
        'The number of revolutions N is '#244'/(2~) \doteq  '+
	'{\z:4\over 2\pi} \doteq   '+answer;
    end;
  end; { case }
  text3::=text1+#13+'\nl\blue{Hint:}\nl '+ 	
        'Use the fact that if s denotes the arc length of a circular arc '+
	'with central angle \theta, then s = r\cdot\theta.';
  replace(+nl+nl+nl+nl+nl,'',text3);
  replace(+nl+nl+nl,'',text3);
  help::=#127'400,400,800,10;I,80,200,40;L,0,0,5,0;L,0,0,4.3,2.5;P,5,0,.53;'+
  	'B,2;C,2.4,-.5,r;C,2.2,1.8,r;C,5,1.2,s;B,4;C,1.4,.2,\theta;'#127+
  	'\red{Circular Sectors:}\nl '+
	'\ \ \theta  denotes an angle in radians.\nl '+
	'\ \ A denotes the area of the sector.\nl '+
	'\ \ A = {1\over 2}r^2\theta\nl '+
	'\ \ s = r\cdot\theta\nl\nl '+ 
	'\ \ 1 revolution = 2\pi  radians\nl '+
	'\ \ 1 ft. = 12 inches\nl '+
	'\ \ 1 mile = 5280 ft.';
  key := 4149;
  type := 'R';
end;

procedure s4149;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;
procedure p4151;
var
  a,b,c,d,e,f,j,k,m:integer;
  p,q:real;
  v:valuetype;
  ang1,ang2,label,r,s,t,u,w,y,z:string;
begin
  a:=rand([2..6,8..13,15..20,22,23,25,26,27]); v.a:=a;
  b:=a mod 14;v.b:=b;
  ang1:=fraction(a,'-',7);
  ang2:=ang1+'~';
  text1::='Determine the quadrant containing the angle '+ang2+
    ' in standard position. Use \red{1,2,3, or 4}  to express '+
   +'your answer.'+nl;
  text3::=text1+#13+'\nl\blue{Hint:}\nl '+
  	'If '+ang2+' is between 0 and 2~, let '#244' = '+ang2+'. If not, '+
        'write '+ang2+' as 2~k + '#244' where k is an integer and '+
        #244' is between 0 and 2~. Then decide whether '+#244+' is between '+
        '0 and ~/2, between ~/2 and ~, between ~ and 3~/2, or between '+
        '3~/2 and 2~.';
  prompt::=#133'Quadrant containing '+ang2+': '#134;
  help::='Let \theta  denote an angle in radians and let $$\theta=2\pi\cdot k'+
  	'+\alpha$$ where 0 \le  \alpha < 2\pi. Then\nl '+
	'if $$0\le\alpha<{\pi\over 2}$$, \theta is in quadrant 1\nl '+
	'if $${\pi\over 2}\le\alpha<\pi$$, \theta is in quadrant 2\nl '+
	'if $$\pi\le\alpha<{3\pi\over 2}$$, \theta is in quadrant 3\nl '+
	'if $${3\pi\over 2}\le\alpha<2\pi$$, \theta is in quadrant 4.\nl ';
  if a in [2,3] then begin
    answer:='1';
    solution:='Note that 0 < '+ang1+' < '+#29#219'1'#221'/'#219'2'#221#10+nl+
              ' => 0 < '+ang2+' < '#29#219'~'#221'/'#219'2'#221#10+nl+
              ' => '+ang2+' is in quadrant 1.';
  end;
  if a in [15,16,17] then begin
    answer:='1';
    solution:='Note that '+ang2+' = ('+fraction(14,'-',7)+' + '+fraction(b,'-',7)+')~ '+nl+
               ' = 2~ + '+fraction(b,'-',7)+'~.'#10+nl+
               'Now 0 < '+fraction(b,'-',7)+' < '#29#219'1'#221'/'#219'2'#221#10+nl+
               ' => 0 < '+fraction(b,'-',7)+'~ < '#29#219'~'#221'/'#219'2'#221#10+nl+
               ' => '+ang2+' is in quadrant 1.';
  end;
  if a in [4,5,6] then begin
    answer:='2';
    solution:='Note that '#29#219'1'#221'/'#219'2'#221' < '+ang1+' < 1'#10+nl+
              ' => '#29#219'~'#221'/'#219'2'#221' < '+ang2+' < ~'#10+nl+
              ' => '+ang2+' is in quadrant 2.';
  end;
  if a in [18,19,20] then begin
    answer:='2';
    solution:='Note that '+ang2+' = ('+fraction(14,'-',7)+' + '+fraction(b,'-',7)+')~ '+nl+
               ' = 2~ + '+fraction(b,'-',7)+'~.'#10+nl+
               'Now '#29#219'1'#221'/'#219'2'#221' < '+fraction(b,'-',7)+' < 1'#10+nl+
               ' => '#29#219'~'#221'/'#219'2'#221' < '+fraction(b,'-',7)+'~ < ~'#10+nl+
               ' => '+ang2+' is in quadrant 2.';
  end;
  if a in [8,9,10] then begin
    answer:='3';
    solution:='Note that 1 < '+ang1+' < '#29#219'3'#221'/'#219'2'#221#10+nl+
              ' => ~ < '+ang2+' < '#29#219'3~'#221'/'#219'2'#221#10+nl+
              ' => '+ang2+' is in quadrant 3.';
  end;
  if a in [22,23] then begin
    answer:='3';
    solution:='Note that '+ang2+' = ('+fraction(14,'-',7)+' + '+fraction(b,'-',7)+')~ '+nl+
               ' = 2~ + '+fraction(b,'-',7)+'~.'#10+nl+
               'Now 1 < '+fraction(b,'-',7)+' < '+fraction(3,'-',2)+#10+nl+
               ' => ~ < '+fraction(b,'-',7)+'~ < '#29#219'3~'#221'/'#219'2'#221+nl+
               ' => '+ang2+' is in quadrant 3.';
  end;
  if a in [11,12,13] then begin
    answer:='4';
    solution:='Note that '+fraction(3,'-',2)+' < '+ang1+' < 2'#10+nl+
              ' => '#29#219'3~'#221'/'#219'2'#221' < '+ang2+' < 2~'#10+nl+
              ' => '+ang2+' is in quadrant 4.';
  end;
  if a in [25,26,27] then begin
    answer:='4';
    solution:='Note that '+ang2+' = ('+fraction(14,'-',7)+' + '+fraction(b,'-',7)+')~ '+nl+
               ' = 2~ + '+fraction(b,'-',7)+'~.'#10+nl+
               'Now '+fraction(3,'-',2)+' < '+fraction(b,'-',7)+' < 2'#10+nl+
               ' => '#29#219'3~'#221'/'#219'2'#221' < '+fraction(b,'-',7)+'~ < 2~'#10+nl+
               ' => '+ang2+' is in quadrant 4.';
  end;
  if answer<>'2' then label:='C,-4,4,'#244' = '+st(a)+'~/7';
  if answer='2' then label:='C,1,4,'#244' = '+st(a)+'~/7';
  str(a*pi/7:3:2,w);
  str(7*cos(a*pi/7):3:2,y);
  str(7*sin(a*pi/7):3:2,z);
  solution::=#127'500,500,1200,10;A,250,250,50;B,2;P,1+x/6,0,'+w+';B,4;L,0,0,'+y+','+z+';B,2;'+label+';'#127+
	  '\nl\red{Solution:}\nl '+solution;
type:='R';
key := 4151;
end;

procedure s4151;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4154;
var
  a,b,c,d,e,f,j,k:integer;
  p,q,r,s,t:real;
  v:valuetype;
  ans1,ans2:string;
  trig,ratio:array[1..6] of string;
  functn,ans:array[1..6] of string;
begin
  trig[1]:='sin(x)';
  trig[2]:='cos(x)';
  trig[3]:='tan(x)';
  trig[4]:='cot(x)';
  trig[5]:='sec(x)';
  trig[6]:='csc(x)';
  k:=randint(1,6);
  text1:='For which values of x in the interval [0,2~]'+
    ' is the function f(x) = '+trig[k]+' defined? Express your answer '+
    'as a collection of intervals separated by commas.'+nl;
  prompt::=#133'Domain of '+trig[k]+',$$0\le x\le 2\pi$$: '#134;
  text3::=text1+'\nl\blue{Hint:}\nl '+
    'Draw the graph of '+trig[k]+'. The trig functions are defined '+
    'everywhere except those values of x for which the graph has a '+
    'vertical asymptote.';
  help::='\red{Graph of '+trig[k]+':}'+
    #127'314,300,800,10;A,0,150,50;B,2;G,'+trig[k]+',0,6.28;'+
    'B,4;C,.2,-.5,0;C,5.5,.2,2\pi;'#127;
    ans[1]:='[0,2~]';
    ans[2]:='[0,2~]';
    ans[3]:='[0,~/2),(~/2,3~/2),(3~/2,2~]';
    ans[4]:='(0,~),(~,2~)';
    ans[5]:='[0,~/2),(~/2,3~/2),(3~/2,2~]';
    ans[6]:='(0,~),(~,2~)';
  answer:=ans[k];
  solution::='\nl\red{Solution:}\nl '+
    #127'314,300,1200,10;A,0,150,50;B,2;G,'+trig[k]+',0,6.28;'+
    'B,4;C,.2,-.5,0;C,5.5,.2,2\pi;'#127+
    'Within [0,2~] '+trig[k]+' is defined on '+nl+answer+'.';
  type:='R';
  key :=4154;
end;

procedure s4154;
begin
  replace(prompt,'',response);
  if sameintervals(answer,response) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect.'#140+#13+text3
    else message:=response+' is '+#140'incorrect'#140+'. '#13+text3;
  end;
end;

procedure p4155;
var
  a,b,c,d,e,f,j,k:integer;
  p,q,r,s,t:real;
  v:valuetype;
  answer1,answer2:string;
  fct,functn,mes,intvl,sol:string;
begin
  case randint(1,7) of
  1:begin
    functn:='$${1\over 2sin(x)-1}$$';intvl:='[0,2~]';
    fct:='sin(x)';
    mes:='The denominator must be non-zero.';
    answer:='[0,~/6),(~/6,5~/6),(5~/6,2~]';
    sol:='f(x) = '+functn+', x in '+intvl+'\pause\nl '+
      '=> sin(x) \ne  {1\over 2}\pause\nl '+
      '=> x \ne {\pi\over 6}, {5\pi\over 6}\pause\nl '+
      'Thus f(x) is defined on '+answer+'.';
    end;
  2:begin
    functn:=makeformula('{sin(x)}',[],v);intvl:='[0,2~)';
    fct:='sin(x)';
    mes:='The expression inside the radical must be & 0.';
    answer:='[0,~]';
    sol:= makeformula('sin(x)&0',[],v)+', x in '+intvl+#10+nl+
      '=> x ! ~'#10+nl+
      'Thus f(x) is defined on '+answer+'.';
    end;
  3:begin
    functn:=makeformula('ln(sin(x))',[],v);intvl:='[0,2~]';
    fct:='sin(x)';
    mes:='The expression inside the logarithm must be > 0.';
    answer:='(0,~)';
    sol:= makeformula('sin(x)>0',[],v)+', x in '+intvl+#10+nl+
      '=> x < ~,'#10+nl+
      'Thus f(x) is defined on '+answer+'.';
    end;
  4:begin
    functn:=makeformula('ln(tan(x))',[],v);intvl:='[0,2~]';
    fct:='tan(x)';
    mes:='The expression inside the logarithm must be > 0.';
    answer:='(0,~/2),(~,3~/2)';
    sol:= makeformula('tan(x)>0',[],v)+', x in '+intvl+#10+nl+
      '=>0 < x < ~/2, ~ < x < 3~/2.'#10+nl+
      'Thus f(x) is defined on '+answer+'.';
    end;
  5:begin
    functn:='$${1\over 1+sin(x)}$$';intvl:='[0,2~]';
    fct:='sin(x)';
    mes:='The denominator must be non-zero.';
    answer:='[0,3~/2),(3~/2,2~]';
    sol:= makeformula('sin(x)+1'#162'0',[],v)+', x in '+intvl+#10+nl+
      '=> sin(x) '#162' -1'#10+nl+
      '=> x '#162' 3~/2'#10+nl+
      'thus f(x) is defined on '+answer+'.';
    end;
  6:begin
    functn:='$${1\over 2-sec(x)}$$';intvl:='[0,~/2]';
    fct:='sec(x)';
    mes:='The denominator must be non-zero and sec(x) must be defined.';
    answer:='[0,~/3),(~/3,~/2)';
    sol:= 'In [0,2\pi] sec(x) is undefined at\nl '+
      'x = {\pi\over 2}, {3\pi\over 2}\pause\nl '+
      makeformula('2-sec(x)'#162'0',[],v)+', x in '+intvl+#10+nl+
      '=> sec(x) '#162' 2'#10+nl+
      '=> x '#162' ~/3, ~/2'#10+nl+
      'Thus f(x) is defined on '+answer+'.';
    end;
  7:begin
    functn:='$${1\over 2+sec(x)}$$';intvl:='[~,2~]';
    fct:='sec(x)';
    mes:='The denominator must be non-zero and sec(x) must be defined.';
    answer:='[~,4~/3),(4~/3,3~/2),(3~/2,2~]';
    sol:= 'In [~,2~] sec(x) is undefined at x = {3\pi\over 2}\pause\nl '+
      makeformula('2+sec(x)'#162'0',[],v)+', x in '+intvl+#10+nl+
      '=> sec(x) '#162' -2'#10+nl+
      '=> x '#162' 4~/3, 3~/2'#10+nl+
      'Thus f(x) is defined on '+answer+'.';
    end;
  end;
  text1::='For which values of x in the interval '+intvl+
    ' is the function f(x) = '+functn+' defined? Express your answer '+
    'as a collection of intervals separated by commas.'+nl;
  text3::=text1+'\nl\blue{Hint:}\nl '+mes;
  help::='\red{Domain Information:}\nl '+
	'\ \ Expressions inside square root signs must be \ge  0.\nl '+
  	'\ \ Division by zero is not allowed.'+nl+
	#127'628,500,50,10;A,314,250,50;B,2;G,'+fct+',-6.28,6.28;'+
	'B,4;C,5.5,.3,2\pi;C,-6,.2,-2\pi;B,0;C,.3,4,f(x)='+fct+';'#127;
  prompt::=#133'Domain of '+functn+', x in '+intvl+': '#134;
  solution::='\nl\red{Solution:}\nl '+
  	#127'700,500,1000,10;A,350,250,50;B,2;G,'+fct+',-6.28,6.28;'+
	'B,4;C,5.8,.3,2\pi;C,-6.8,-.5,-2\pi;C,3.1,.3,\pi;C,-3.7,-.5,-\pi;'+
	'B,0;C,.3,4,f(x)='+fct+';'#127+
	sol;
  type:='R';
  key := 4155;
end;

procedure s4155;
begin
  replace(prompt,'',response);
  if sameintervals(answer,response) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect.'#140+#13+text3
    else message:=response+' is '+#140'incorrect'#140+'. '#13+text3;
  end;
end;

procedure p4157;
var
  v:valuetype;
  f:string;
begin
  case randint(1,13) of
  1:begin
      f:='(f`g)(1)';
      text1:='If f(x) = '+makeformula('1/(1 + x^2)',[],v)+' and g(x) '+
        '= sin(~x), determine '+f+'.'+nl;
      text3:='(f`g)(x) = f(g(x)).';
      answer:='1';
      solution := 'f(x) = '+makeformula('1/(1 + x^2)',[],v)+#10+nl+
        'g(x) = sin(~x)'+#10+nl+
        'f(g(x)) = '+makeformula('1/(1+sin^2(~x)',[],v)+#10+nl+
        'f(g(1)) = '+makeformula('1/(1+sin^2(~)',[],v)+#10+nl+
        '= '+answer+'.';
      text6:='';
    end;
  2:begin
      f:='(g`f)(1)';
      text1:='If f(x) = '+makeformula('1/(1 + x^2)',[],v)+' and g(x) '+
        '= sin(~x), determine '+f+'.'+nl;
      text3:='(g`f)(x) = g(f(x)).';
      answer:='1';
      solution := 'f(x) = '+makeformula('1/(1 + x^2)',[],v)+#10+nl+
        'g(x) = sin(~x)'+#10+nl+
        'g(f(x)) = '+makeformula('sin(~/(1+x^2))',[],v)+#10+nl+
        'g(f(1)) = '+makeformula('sin(~/(1+1^2))',[],v)+#10+nl+
        '= '+answer+'.';
      text6:='';
    end;
  3:begin
      f:='(f`g)(x)';
      text1:='If f(x) = '+makeformula('1/(1 + x^2)',[],v)+' and g(x) '+
        '= sin(~x), determine '+f+'.'+nl;
      text3:='(f`g)(x) = f(g(x)).';
      answer:=makeformula('1/(1 + sin^2(~x))',[],v);
      solution := 'f(x) = '+makeformula('1/(1 + x^2)',[],v)+#10+nl+
        'g(x) = sin(~x)'+#10+nl+
        'f(g(x)) = '+makeformula('1/(1+sin^2(~x)',[],v)+'.';
      text6:='1';
    end;
  4:begin
      f:='(g`f)(x)';
      text1:='If f(x) = '+makeformula('1/(1 + x^2)',[],v)+' and g(x) '+
        '= sin(~x), determine '+f+'.'+nl;
      text3:='(g`f)(x) = g(f(x)).';
      answer:=makeformula('sin(~/(1 + x^2))',[],v);
      solution := 'f(x) = '+makeformula('1/(1 + x^2)',[],v)+#10+nl+
        'g(x) = sin(~x)'+#10+nl+
        'g(f(x)) = '+makeformula('sin(~/(1+x^2))',[],v)+'.';
      text6:='1';
    end;
  5:begin
      f:='(g`f)(@'#251'5'#253')';
      text1:='If f(x) = '+makeformula('1/(1 + x^2)',[],v)+' and g(x) '+
        '= sin(~x), determine '+f+'.'+nl;
      text3:='(g`f)(x) = g(f(x)).';
      answer:='1/2';
      solution := 'f(x) = '+makeformula('1/(1 + x^2)',[],v)+#10+nl+
        'g(x) = sin(~x)'+#10+nl+
        'g(f(x)) = '+makeformula('sin(~/(1+x^2))',[],v)+#10+nl+
        'f(g(@'#251'5'#253')) = '+makeformula('sin(~/(1+5))',[],v)+#10+nl+
        '= '+answer+'.';
      text6:='';
    end;
  6:begin
      f:='(g`f)(@'#251'5'#253')';
      text1:='If f(x) = '+makeformula('1/(1 + x^2)',[],v)+' and g(x) '+
        '= cos(~x), determine '+f+'.'+nl;
      text3:='(g`f)(x) = g(f(x)).';
      answer:='@'#251'3'#253'/2';
      solution := 'f(x) = '+makeformula('1/(1 + x^2)',[],v)+#10+nl+
        'g(x) = cos(~x)'+#10+nl+
        'g(f(x)) = '+makeformula('cos(~/(1+x^2))',[],v)+#10+nl+
        'f(g(@'#251'5'#253')) = '+makeformula('cos(~/(1+5))',[],v)+#10+nl+
        '= '+answer+'.';
      text6:='';
    end;
  7:begin
      f:='(f`g)('+fraction(1,'/',3)+')';
      text1:='If f(x) = '+makeformula('1/(1 + x^2)',[],v)+' and g(x) '+
        '= sin(~x), determine '+f+'.'+nl;
      text3:='(f`g)(x) = f(g(x)).';
      answer:='4/7';
      solution := 'f(x) = '+makeformula('1/(1 + x^2)',[],v)+#10+nl+
        'g(x) = sin(~x)'+#10+nl+
        'f(g(x)) = '+makeformula('1/(1+sin^2(~x)',[],v)+#10+nl+
        'f(g('+fraction(1,'/',3)+')) = '+makeformula('1/(1+sin^2(~/3)',[],v)+#10+nl+
        '= '+makeformula('1/(1+({3}/2)^2',[],v)+#10+nl+
        '= '+answer+'.';
      text6:='';
    end;
  8:begin
      f:='(f`g)('+fraction(1,'/',4)+')';
      text1:='If f(x) = '+makeformula('1/(1 + x^2)',[],v)+' and g(x) '+
        '= cos(~x), determine '+f+'.'+nl;
      text3:='(f`g)(x) = f(g(x)).';
      answer:='2/3';
      solution := 'f(x) = '+makeformula('1/(1 + x^2)',[],v)+#10+nl+
        'g(x) = cos(~x)'+#10+nl+
        'f(g(x)) = '+makeformula('1/(1+cos^2(~x)',[],v)+#10+nl+
        'f(g('+fraction(1,'/',4)+')) = '+makeformula('1/(1+cos^2(~/4)',[],v)+#10+nl+
        '= '+makeformula('1/(1+({2}/2)^2',[],v)+#10+nl+
        '= '+answer+'.';
      text6:='';
    end;
  9:begin
      f:='(f`g)('+fraction(1,'/',6)+')';
      text1:='If f(x) = '+makeformula('1/(1 + x^2)',[],v)+' and g(x) '+
        '= tan(~x), determine '+f+'.'+nl;
      text3:='(f`g)(x) = f(g(x)).';
      answer:='3/4';
      solution := 'f(x) = '+makeformula('1/(1 + x^2)',[],v)+#10+nl+
        'g(x) = tan(~x)'+#10+nl+
        'f(g(x)) = '+makeformula('1/(1+tan^2(~x)',[],v)+#10+nl+
        'f(g('+fraction(1,'/',6)+')) = '+makeformula('1/(1+tan^2(~/6)',[],v)+#10+nl+
        '= '+makeformula('1/(1+(1/{3})^2',[],v)+#10+nl+
        '= '+answer+'.';
      text6:='';
    end;
  10:begin
      f:='(f`g)(1)';
      text1:='If f(x) = '+makeformula('1/(1 + x^2)',[],v)+' and g(x) '+
        '= cos(~x), determine '+f+'.'+nl;
      text3:='(f`g)(x) = f(g(x)).';
      answer:='1/2';
      solution := 'f(x) = '+makeformula('1/(1 + x^2)',[],v)+#10+nl+
        'g(x) = cos(~x)'+#10+nl+
        'f(g(x)) = '+makeformula('1/(1+cos^2(~x)',[],v)+#10+nl+
        'f(g(1)) = '+makeformula('1/(1+cos^2(~)',[],v)+#10+nl+
        '= '+answer+'.';
      text6:='';
    end;
  11:begin
      f:='(g`f)(1)';
      text1:='If f(x) = '+makeformula('1/(1 + x^2)',[],v)+' and g(x) '+
        '= cos(~x), determine '+f+'.'+nl;
      text3:='(g`f)(x) = g(f(x)).';
      answer:='0';
      solution := 'f(x) = '+makeformula('1/(1 + x^2)',[],v)+#10+nl+
        'g(x) = cos(~x)'+#10+nl+
        'g(f(x)) = '+makeformula('cos(~/(1+x^2))',[],v)+#10+nl+
        'g(f(1)) = '+makeformula('cos(~/(1+1^2))',[],v)+#10+nl+
        '= '+answer+'.';
      text6:='';
    end;
  12:begin
      f:='(f`g)(x)';
      text1:='If f(x) = '+makeformula('1/(1 + x^2)',[],v)+' and g(x) '+
        '= cos(~x), determine '+f+'.'+nl;
      text3:='(f`g)(x) = f(g(x)).';
      answer:=makeformula('1/(1 + cos^2(~x))',[],v);
      solution := 'f(x) = '+makeformula('1/(1 + x^2)',[],v)+#10+nl+
        'g(x) = cos(~x)'+#10+nl+
        'f(g(x)) = '+makeformula('1/(1+cos^2(~x)',[],v)+'.';
      text6:='1';
    end;
  13:begin
      f:='(g`f)(x)';
      text1:='If f(x) = '+makeformula('1/(1 + x^2)',[],v)+' and g(x) '+
        '= cos(~x), determine '+f+'.'+nl;
      text3:='(g`f)(x) = g(f(x)).';
      answer:=makeformula('cos(~/(1 + x^2))',[],v);
      solution := 'f(x) = '+makeformula('1/(1 + x^2)',[],v)+#10+nl+
        'g(x) = cos(~x)'+#10+nl+
        'g(f(x)) = '+makeformula('cos(~/(1+x^2))',[],v)+'.';
      text6:='1';
    end;
  end;
  prompt:=#133+f+' = '#134;
  help::='\red{Rules for Combining Functions:}\nl'+	
	'\ \ $$(f\pm g)(x) = f(x)\pm g(x)$$\nl '+
	'\ \ $$(f\cdot g)(x)=f(x)\cdot g(x)$$\nl '+
	'\ \ $${f\over g}(x)={f(x)\over g(x)}$$\nl '+
	'\ \ $$(f\circ g)(x)=f(g(x))$$';
  solution::='\nl\red{Solution:}\nl '+solution;
  text3::=text1+'\nl\blue{Hint:}\nl '+text3;
  type:='R';
  key:=4157;
end;

procedure s4157;             
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4158;
var
v:valuetype;
x:paramtype;
undef,notwff:boolean;
a,b,j,k:integer;
f,h,value,ans,sol:array[1..6] of string;
ineq,adj:array[1..2] of string;
dgm,dgm2:string;
begin
  k:=randint(1,6);
  if k=4 then j:=1 else
  j:=randint(1,2);
  f[1]:='sec(x)';value[1]:='2';
  if j=1 then
    sol[1]:='sec(x) = 2 <=> cos(x) = {1\over 2}\nl '+
      'In [0,2\pi] this occurs when x = {\pi\over 3} or x ={5\pi\over 3}.\pause\nl '+
      'Note that sec(x) is undefined when x = {\pi\over 2} or {3\pi\over 2}.'
  else sol[1]:='sec(x) = -2 <=> cos(x) = {-1\over 2}\nl '+
      'In [0,2\pi] this occurs when x = {2\pi\over 3} or x ={4\pi\over 3}.\pause\nl '+
      'Note that sec(x) is undefined when x = {\pi\over 2} or {3\pi\over 2}.';
  f[2]:='tan(x)';value[2]:=makeformula('[1]/[{3}]',[],v);
  if j=1 then
    sol[2]:='tan(x) ={1\over \sqrt{3}} when x = {\pi\over 6} or {7\pi\over 6}.\pause\nl '+
      'Note that tan(x) is undefined when x = {\pi\over 2} or {3\pi\over 2}.'
  else
    sol[2]:='tan(x) ={-1\over \sqrt{3}} when x = {5\pi\over 6} or {11\pi\over 6}\pause\nl '+
      'Note that tan(x) is undefined when x = {\pi\over 2} or {3\pi\over 2}.';
  f[3]:='sin(x)';value[3]:=makeformula('[1]/[2]',[],v);
  if j=1 then
    sol[3]:='sin(x) ={1\over 2} when x = {\pi\over 6} or {5\pi\over 6}.'
  else sol[3]:='sin(x) ={-1\over 2} when x = {7\pi\over 6} or {11\pi\over 6}.';
  f[4]:='|sin(x)|';value[4]:=makeformula('[1]/[2]',[],v);
  sol[4]:='|sin(x)| = {1\over 2} when x = {\pi\over 6}, {5\pi\over 6}, '+
    '{7\pi\over 6} and {11\pi\over 6}.';
  f[5]:='cos(x)';value[5]:=makeformula('[{2}]/[2]',[],v);
  if j=1 then
    sol[5]:='cos(x) = {\sqrt{2}\over 2} when x = {\pi\over 4} or{7\pi\over 4}'
  else
    sol[5]:='cos(x) = {-\sqrt{2}\over 2} when x = {3\pi\over 4} or {5\pi\over 4}';
  f[6]:='cot(x)';value[6]:=makeformula('{3}',[],v);
  if j=1 then
    sol[6]:='cot(x) = \sqrt{3} when x = {\pi\over 6} or {7\pi\over 6}.\nl '+
      'Note that cot(x) is undefined when x = 0, \pi, or 2\pi.'
  else
    sol[6]:='cot(x) = -\sqrt{3} when x = {5\pi\over 6} or {11\pi\over 6}.\nl '+
      'Note that cot(x) is undefined when x = 0, \pi, or 2\pi.';
  ineq[1]:='>';adj[1]:='above';
  ineq[2]:='< ';adj[2]:='below';
  if j = 2 then value[k]:='-'+value[k];
  x.w:=evaluate(value[k],'',undef,notwff)+.1;
  text1:='Find all values of x in [0,2~] for which '+nl+f[k]+' '+ineq[j]+' '+value[k]+
    '. Express your answer as a collection of intervals separated by commas.'+
    ' If the inequality is never satisfied enter ''nowhere''.'+nl;
  prompt:=#133+f[k]+' '+ineq[j]+' '+value[k]+': '#134;
  dgm:=#127'800,500,100,10;A,50,250,100;B,2;G,'+f[k]+',0,6.28;'+
    'B,3;G,'+value[k]+',0,6.28;B,4;C,6,.1,2\pi;C,1.4,.1,\pi/2;C,4.6,.1,3\pi/2;'+
    'C,3.1,.1,\pi;B,2;C,.3,2,y='+f[k]+';B,4;C,6.4,\w:2,y='+value[k]+';';
  if k =1 then replace('.3,2,y','.3,.5,y',dgm);
  help::=sol[k]+nl+dgm+#127;
  text6::=text1+'\nl\blue{Hint:}\nl '+
    'Sketch the graph of '+f[k]+' on [0,2\pi] and determine where the graph is '+adj[j]+
    ' the line y = '+value[k]+'.';
  if j=1 then begin
    ans[1]:='(~/3,~/2),(3~/2,5~/3)';
    ans[2]:='(~/6,~/2),(7~/6,3~/2)';
    ans[3]:='(~/6,5~/6)';
    ans[4]:='(~/6,5~/6),(7~/6,11~/6)';
    ans[5]:='[0,~/4),(7~/4,2~]';
    ans[6]:='(0,~/6),(~,7~/6)';
  end;
  if j=2 then begin
    ans[1]:='(~/2,2~/3),(4~/3,3~/2)';
    ans[2]:='(~/2,5~/6),(3~/2,11~/6)';
    ans[3]:='(7~/6,11~/6)';
    ans[5]:='(3~/4,5~/4)';
    ans[6]:='(5~/6,~),(11~/6,2~)';
  end;
  answer:=ans[k];
  replace('100,10','1000,10',dgm);
  solution::=dgm+#127+'\nl\red{Solution:}\nl '+sol[k]+nl+
    'From the graph we see '+f[k]+' '+ineq[j]+' '+value[k]+
    ' for x in '+answer+'.';
  type:='R';
  key:=4158
end;

procedure s4158;
var
res,ans:string;
begin
replace(prompt,'',response);
res:=response;
clean(res);
toupper(res);
replace('NOWHERE','(1,0)',res);
if sameintervals(res,answer) then begin
  result:='T';
  message:=#141'Correct.'#141;
  end
  else begin
  result:='F';
  if response = '' then message:=#140'Incorrect. '#140+nl+text6 else
  message:=response+' is '#140'incorrect'#140+'. '+nl+text6;
  end;
end;

procedure p4160;
var
  j,k:integer;
  v:valuetype;
  fct,funct,sol:string;
  ans,intvl:array[1..2] of string;
begin
  k:=randint(1,4);
  j:=randint(1,2);
  case k of
  1:begin
      fct:='tan(x)';
      funct:='tan('+#29#219'x'#221'/'#219'3'#221+')';ans[1]:='3~/2';
      ans[2]:='NONE';
      sol:='tan(x) has vertical asymptotes when x = \pm {\pi\over 2}, '+
        '\pm {3\pi\over 2}, \pm {5\pi\over 2}....\pause\nl '+
	'So '+funct+' will have vertical asymptotes when\nl '+
	'{x\over 3} = \pm {\pi\over 2}, \pm {3\pi\over 2}, \pm {5\pi\over 2}...\nl '+
        'or x = \pm{3\pi\over 2}, \pm{9\pi\over 2}, \pm{15\pi\over 2}.';
      intvl[1]:='[0,2~]';
      intvl[2]:='[-~,~]';
    end;
  2:begin
      fct:='cot(x)';
      funct:='cot('+#29#219'x'#221'/'#219'2'#221+')';ans[1]:='0,2~';
      ans[2]:='0';
      sol:='cot(x) has vertical asymptotes when x = 0, \pm\pi, \pm 2\pi.... \pause\nl '+
	'So '+funct+' will have vertical asymptotes when\nl '+
	'{x\over 2} = 0, \pm\pi, \pm 2\pi....\nl '+
        'or x = 0, \pm 2\pi, \pm 4\pi...';
      intvl[1]:='[0,2~]';
      intvl[2]:='[-~,~]';
    end;
  3:begin
      fct:='sec(x)';
      funct:='sec('+#29#219'x'#221'/'#219'2'#221+')';ans[1]:='~';
      ans[2]:='-~,~';
      sol:='sec(x) has vertical asymptotes when x = \pm {\pi\over 2}, '+
        '\pm{3\pi\over 2}, \pm{5\pi\over 2}....\pause\nl '+
	'So '+funct+' will have vertical asymptotes when\nl '+
	'{x\over 2} = \pm{\pi\over 2}, \pm{3\pi\over 2}, \pm{5\pi\over 2}...\nl '+
        'or x = \pm\pi, \pm 3\pi, \pm 5\pi...';
      intvl[1]:='[0,2~]';
      intvl[2]:='[-~,~]';
    end;
  4:begin
      fct:='csc(x)';
      funct:='csc('+#29#219'x'#221'/'#219'3'#221+')';ans[1]:='0';
      ans[2]:='0';
      sol:='csc(x) has vertical asymptotes when x = 0, \pi, 2\pi.... \pause\nl '+
	'So '+funct+' will have vertical asymptotes when\nl '+
	'{x\over 3} = 0, \pm\pi, \pm 2\pi....\nl '+
        'or x = 0, \pm 3\pi, \pm 6\pi...';
      intvl[1]:='[0,2~]';
      intvl[2]:='[-~,~]';
    end;
  end;
  text1:='Find all values of c in the interval '+intvl[j]+
    ' for which the function '+nl+'   f(x) = '+funct+nl+
    'has the line x = c as a vertical asymptote. Separate your answers '+
    ' by commas. If there are no such values of c enter the word NONE.'+
    nl;
  text3::=text1+'\nl\blue{Hint:}\nl '+
    'f(x) -> f(ax), a > 0, compresses the graph of f(x) horizontally '+
    'towards the y-axis if a > 1 and stretches the graph of f(x) '+
    'horizontally away from the y-axis if 0 < a < 1.\nl '+
    'Sketch the graph of y = '+funct+'.';
  answer:=ans[j];
  if ((k = 1) and (j = 2))then
    solution::=#127'700,600,1000,10;A,350,300,50;B,2;G,'+funct+',-6.28,6.28;'+
      'B,3;G,'+fct+',-6.28,6.28;'+
      'B,4;C,5.8,.3,2\pi;C,-6.8,-.5,-2\pi;C,3.1,.3,\pi;C,-3.7,-.5,-\pi;'+
      'B,2;C,.3,4,'+funct+';B,3;C,.3,-.6,'+fct+';'#127+
      '\nl\red{Solution:}\nl '+sol+nl+
      'So '+funct+' has no vertical'+nl+
      'asymptotes in '+intvl[j]+'.'
  else
    solution::=#127'700,600,1000,10;A,350,300,50;B,2;G,'+funct+',-6.28,6.28;'+
      'B,3;G,'+fct+',-6.28,6.28;'+
      'B,4;C,5.8,.3,2\pi;C,-6.8,-.5,-2\pi;C,3.1,.3,\pi;C,-3.7,-.5,-\pi;'+
      'B,2;C,.3,4,'+funct+';B,3;C,.3,-.6,'+fct+';'#127+
      '\nl\red{Solution:}\nl '+sol+nl+
      'Hence on '+intvl[j]+' y = '+funct+' has vertical asymptotes '+
      'at c = '+answer+'.';
  help::=#127'700,600,600,10;A,350,350,50;B,2;G,'+funct+',-6.28,6.28;'+
      'B,3;G,'+fct+',-6.28,6.28;'+
      'B,4;C,5.8,.3,2\pi;C,-6.8,-.5,-2\pi;C,3.1,.3,\pi;C,-3.7,-.5,-\pi;'+
      'B,2;C,.3,4,'+funct+';B,3;C,.3,-.6,'+fct+';'#127+
      'f(x) -> f(ax), a > 0, compresses the graph of f(x) horizontally '+
      'towards the y-axis if a > 1 and stretches the graph of f(x) '+
      'horizontally away from the y-axis if 0 < a < 1.\nl ';
  prompt:=#133'c = '#134;
  text6 :='';
  if ((k = 1) and (j = 2)) then text6:='1';
  type:='R';
  key := 4160;
end;

procedure s4160;
var
  temp:string;
begin
  replace(prompt,'',response);
  if text6 = '1' then begin
    temp:=response;
    clean(temp);
    toupper(temp);
    if temp = 'NONE' then begin
      result:='T';
      message:=#141'Correct'#141;
    end else begin
      result:='F';
      if response = '' then message:=#140'Incorrect'#140+nl+text3
      else message:=response+' is '#140'incorrect'#140'. '+text3;
    end;
  end;
  if text6 = '' then begin
    if sameconstants(answer,response) then begin
      result:='T';
      message:=#141'Correct'#141;
    end else begin
      result:='F';
      if response = '' then message:=#140'Incorrect'#140+nl+text3
      else message:=response+' is '#140'incorrect'#140'. '+text3;
    end;
  end;
end;

procedure p4163;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2:string;
begin
  x.a:=rand([-2,-3,2,3]);
  x.b:=rand([2,3,4]);
  x.c:=rand([-1,-1,1,2]);
  x.d:=rand([-1,1]);
  dgm::=#127'500,500,1200,10;A,250,250,50;B,2;G,\a sin({2\pi x\over \b})'+
  	'+\d,-10,10;B,4;C,.3,4,y=f(x);'#127;
  header:='\red{Answer both parts before grading.}';
  text:='The graph of a periodic function f(x) is shown to the right. Each '+
  	'mark on either axis represents 1 unit.';
  part1:='\red{a: } Determine the period of f(x). (50%)';
  part2:='\red{b: } determine the amplitude of f(x). (50%)';
  text1::=dgm+header+#13+#13+text+#13+part1+#13+part2+#13+nl+nl+nl;
  buff1:=text+#13+part1+#13+part2+nl;
  prompt::=#133'a: period of f(x): '#134#13+
    	   #133'b: amplitude of f(x): '#134;
  help::='The period of a periodic function f(x) is the smallest '+
  	'number \theta  such that f(x + \theta) = f(x) for all '+
	'x.\nl '+
	'The amplitude of a periodic function is $${M-m\over 2}$$ where '+
	'M and m are the maximum and minimum values of the function over '+
	'one complete period. ';
  text3::=buff1+dgm+'\nl\blue{Hint:}\nl '+help;
  if x.a>0 then a2:='\a' else a2:='$$-\a$$';
  ans:=#134'\b'#133+
       #134+a2;
  answer::=ans;
  separate(ans,a1,a2);
  solution::='\nl\red{Solution to part a:}\nl '+
  	'The period is '+a1+'. This can be seen for example by checking the '+
	'distance between successive maximum points or minimum points on the '+
	'graph.\pause\nl ';
  x.f:=abs(x.a);
  x.y:=x.f+x.d;
  x.z:=-x.f+x.d;
  solution2::='\nl\red{Solution to part b:}\nl '+
  	'The maximum value M of f(x) is \y  and the minimum value m of f(x) is '+
	'\z.\pause\nl '+
	'Thus the amplitude is $${M-m\over 2}={\y-\z\over 2}$$ = '+a2+'.';
  type:='R';
  key:=4163;
end;	   
	       
procedure s4163;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4164;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2:string;
  k:integer;
begin
  k:=rand([1..4]);
  case k of
  1:
  begin
    x.a:=rand([-1,-2,-3,-4,1,2]);
    x.b:=x.a+4;
    repeat x.c:=x.a+rand([1,2,3]) until x.c<>0.0;
    dgm::=#127'640,640,1000,10;A,320,320,40;B,2;'+
  	  'L,-8,\a,-7,\b;L,-7,\b,-6,\c;L,-6,\c,-5,\c;L,-5,\c,-4,\a;'+
  	  'L,-4,\a,-3,\b;L,-3,\b,-2,\c;L,-2,\c,-1,\c;L,-1,\c,0,\a;'+
  	  'L,0,\a,1,\b;L,1,\b,2,\c;L,2,\c,3,\c;L,3,\c,4,\a;'+
  	  'L,4,\a,5,\b;L,5,\b,6,\c;L,6,\c,7,\c;L,7,\c,8,\a;';
    a1:='4';
    a2:='2';
    x.y:=x.a+4;
    x.z:=x.a;
  end;
  2:
  begin
  x.a:=rand([-3..1]);
  x.b:=x.a+rand([4..6]);
  x.c:=x.a+rand([1..3]);
  x.d:=x.b-x.a;
    dgm::=#127'640,640,1000,10;A,320,320,40;B,2;'+
  	  'L,-8,\a,-7,\b;L,-7,\b,-5,\a;L,-5,\a,-4,\c;L,-4,\c,-3,\a;'+
  	  'L,-3,\a,-2,\b;L,-2,\b,0,\a;L,0,\a,1,\c;L,1,\c,2,\a;'+
  	  'L,2,\a,3,\b;L,3,\b,5,\a;L,5,\a,6,\c;L,6,\c,7,\a;'+
  	  'L,7,\a,8,\b;';
    a1:='5';
    a2:='{$\d\over \2$}';
    x.y:=x.b;
    x.z:=x.a;
  end;
  3:
  begin
    x.a:=rand([-3..1]);
    x.b:=x.a+rand([4..6]);
    x.c:=x.a+rand([-3..-1]);
    x.d:=x.b-x.c;
    x.e:=x.b+rand([-1,-2]);
    dgm::=#127'640,640,1000,10;A,320,320,40;B,2;'+
  	  'L,-8,\a,-7,\b;L,-7,\b,-5,\e;L,-5,\e,-4,\c;L,-4,\c,-3,\a;'+
  	  'L,-3,\a,-2,\b;L,-2,\b,0,\e;L,0,\e,1,\c;L,1,\c,2,\a;'+
  	  'L,2,\a,3,\b;L,3,\b,5,\e;L,5,\e,6,\c;L,6,\c,7,\a;'+
  	  'L,7,\a,8,\b;';
    a1:='5';
    a2:='{$\d\over \2$}';
    x.y:=x.b;
    x.z:=x.c;
  end;
  4:
  begin
    x.a:=rand([-1,1]);
    x.b:=x.a-rand([1..3]);
    x.c:=x.a+rand([2..4]);
    x.d:=x.c+rand([1,2]);
    x.e:=x.d-x.b;
    dgm::=#127'640,640,1000,10;A,320,320,40;B,2;'+
  	  'L,-8,\a,-7,\b;L,-7,\b,-4,\c;L,-4,\c,-2,\d;L,-2,\d,-1,\a;'+
  	  'L,-1,\a,0,\b;L,0,\b,3,\c;L,3,\c,5,\d;L,5,\d,6,\a;'+
  	  'L,6,\a,7,\b;L,7,\b,10,\c;';
    a1:='7';
    a2:='{$\e\over 2$}';
    x.y:=x.d;
    x.z:=x.b;
    end;
  end;{case}
  dgm:=dgm+'B,4;C,.3,7,y=f(x);'#127;
  header:='\red{Answer both parts before grading.}';
  text:='The graph of a periodic function f(x) is shown to the right. Each '+
  	'mark on either axis represents 1 unit.';
  part1:='\red{a: } Determine the period of f(x). (50%)';
  part2:='\red{b: } Determine the amplitude of f(x). (50%)';
  text1::=dgm+header+#13+#13+text+#13+part1+#13+part2+#13+nl+nl+nl+nl+nl+nl;
  buff1:=dgm+text+#13+part1+#13+part2+nl;
  prompt::=#133'a: period of f(x): '#134#13+
    	   #133'b: amplitude of f(x): '#134;
  help:='The period of a periodic function f(x) is the smallest '+
  	'number \theta  such that f(x + \theta) = f(x) for all '+
	'x.\nl '+
	'The amplitude of a periodic function is $${M-m\over 2}$$ where '+
	'M and m are the maximum and minimum values of the function over '+
	'one complete period. ';
  text3::=buff1+'\nl\blue{Hint:}\nl '+help;
  help::='\red{Periodic Functions:}\nl '+help;
  ans:=#134+a1+#133+
       #134+a2;
  answer::=ans;
  solution::=nl+'\nl\red{Solution to part a:}\nl '+
  	'The period is '+a1+'. This can be seen for example by checking the '+
	'distance between successive maximum points or minimum points on the '+
	'graph.\pause\nl ';
  solution2::='\nl\red{Solution to part b:}\nl '+
  	'The maximum value M of f(x) is \y  and the minimum value m of f(x) is '+
	'\z.\pause\nl '+
	'Thus the amplitude is $${M-m\over 2}={\y-\z\over 2}$$ = '+a2+'.';
  type:='R';
  key:=4164;
end;	   

procedure s4164;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4165;
var
  k:integer;
  v:valuetype;
  deg:string;
  functn,ans,sol:array[1..6] of string;
begin
  k:=rand([1,3,4,5]);
  deg:=#30+'`'+#31;
  functn[1]:='sin(75'+deg+')';
  functn[2]:='tan(165'+deg+')';
  functn[3]:='sec(75'+deg+')';
  functn[4]:='sin(5~/12)';
  functn[5]:='csc(5~/12)';
  functn[6]:='tan(7~/12)';
  text1:='Find the exact value of '+functn[k]+'. Neither a decimal '+
    'approximation from the calculator nor an answer involving a trig function '+
    'will be accepted.'+nl;
  text3::=text1+'\nl\blue{Hint:}\nl '+
    'Write the angle as a sum or difference of standard '+
    'angles and then use one of the addition formulas.';
  prompt:=#133+functn[k]+' = '#134;
  ans[1]:=#29#219+makeformula('{2}+{6}',[],v)+#221'/'#219'4'#221;
  ans[2]:=#29#219'1 - @'#251'3'#253#221'/'#219'1 + @'#251'3'#253#221;
  ans[3]:=makeformula('[4]/[{6}-{2}]',[],v);
  ans[4]:=#29#219'@'#251'2'#253' + @'#251'6'#253#221'/'#219'4'#221;
  ans[5]:=makeformula('[4]/[{6}+{2}]',[],v);
  ans[6]:=makeformula('[1+{3}]/[1-{3}]',[],v);
  sol[1]:='sin(75'+deg+') = sin(45'+deg+' + 30'+deg+')'+#10+nl+nl+
    '= sin(45'+deg+')cos(30'+deg+') + sin(30'+deg+')cos(45'+deg+')'+#10+nl+nl+
    '= '+makeformula('([{2}]/[2])([{3}]/[2])+([1]/[2])([{2}]/[2])',[],v)+#10+nl+nl+
    '= '+makeformula('[{6}]/[4]+[{2}]/[4]',[],v)+' = '+ans[1]+'.';
  sol[2]:='tan(165'+deg+') = tan(120'+deg+' + 45'+deg+')'+#10+nl+
    '= '+makeformula('[tan(120'+deg+')+tan(45'+deg+')]/'+
        '[1-tan(120'+deg+')tan(45'+deg+')]',[],v)+#10+nl+nl+
    '= '+makeformula('[(-{3})+1]/[1-(-{3})(1)]',[],v)+#10+nl+nl+
    '= '+ans[2]+'.';
  sol[3]:='sec(75'+deg+') = '#29#219'1'#221'/'#219'cos(75'+deg+')'#221+
    ' = '+#29#219'1'#221'/'#219'cos(45'+deg+' + 30'+deg+')'#221+#10+nl+nl+
    '= '+#29#219'1'#221'/'#219'cos(45'+deg+')cos(30'+deg+')'+
       ' - sin(45'+deg+')sin(30'+deg+')'#221+#10+nl+nl+
    '= '+makeformula('[1]/[([{2}]/[2])([{3}]/[2])-([{2}]/[2])([1]/[2])]',[],v)+
    #10+nl+'= '+makeformula('[1]/[[{6}-{2}]/[4]]',[],v)+' = '+ans[3]+'.';
  sol[4]:='sin(5~/12) = sin(~/6 + /4~)' +#10+nl+nl+
    '= sin(~/6)cos(~/4) + sin(~/4)cos(~/6)'+#10+nl+nl+
    '= '+makeformula('([1]/[2])([{2}]/[2])+([{2}]/[2])([{3}]/[2])',[],v)+#10+nl+nl+
    '= '+makeformula('[{2}]/[4]+[{6}]/[4]',[],v)+' = '+ans[4]+'.';
  sol[5]:='csc(5~/12) = '#29#219'1'#221'/'#219'sin(5~/12)'#221+
    ' = '+#29#219'1'#221'/'#219'sin(~/4 + ~/6)'#221+#10+nl+nl+
    '= '+#29#219'1'#221'/'#219'sin(~/4)cos(~/6)'+
       ' + sin(~/6)cos(~/4)'#221+#10+nl+nl+
    '= '+makeformula('[1]/[([{2}]/[2])([{3}]/[2])+([1]/[2])([{2}]/[2])]',[],v)+
    #10+nl+'= '+makeformula('[1]/[[{6}+{2}]/[4]]',[],v)+' = '+ans[5]+'.';
  sol[6]:='tan(7~/12) = tan(~/3 + ~/4)'+#10+nl+
    '= '+makeformula('[tan(~/3)+tan(~/4)]/'+
        '[1-tan(~/3)tan(~/4)]',[],v)+#10+nl+nl+
    '= '+makeformula('[({3})+1]/[1-({3})(1)]',[],v)+#10+nl+nl+
    '= '+ans[6]+'.';
  answer:=ans[k];
  help::='\red{Addition Formulas:}\nl '+
    '\ \ $$sin(\alpha+\beta)=sin(\alpha)\cdot cos(\beta)+sin(\beta)\cdot cos(\alpha)$$\nl '+
    '\ \ $$sin(\alpha-\beta)=sin(\alpha)\cdot cos(\beta)-sin(\beta)\cdot cos(\alpha)$$\nl '+
    '\ \ $$cos(\alpha+\beta)=cos(\alpha)\cdot cos(\beta)-sin(\beta)\cdot sin(\alpha)$$\nl '+
    '\ \ $$cos(\alpha-\beta)=cos(\alpha)\cdot cos(\beta)+sin(\beta)\cdot sin(\alpha)$$\nl ';
  solution::='\nl\red{Solution:}\nl '+sol[k];
  type:='R';
  key := 4165;
end;

procedure s4165;
var
  res:string;
  p:integer;
begin
  replace(prompt,'',response);
  res:=response;
  p:=pos('=',res);
  delete(res,0,p+1);
  res:=res;
  if pos('.',res)>0 then begin
    result:='F' ;
    message:='A decimal answer is unacceptable.';
    end
  else
  if (pos('sin',res)>0 ) or ( pos('cos',res)>0) or
     (pos('cot',res)>0) or (pos('sec',res)>0) or
     (pos('tan',res)>0) or (pos('csc',res)>0) then begin
       result:='F';
       message:='An answer with a trig function is unacceptable.';
     end
  else
  if sameconstants(answer,res) then begin
     result := 'T';
     message:=#141'Correct'#141;
  end else begin
     result:='F';
     if res = '' then message:=#140'Incorrect'#140+nl+text3
     else
     message:=response+' is '#140'incorrect'#140'. '+text3;
  end;
end;

procedure p4167;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,a3,dgm,header,text,part1,part2,part3,fctn,sol:string;
  k:integer;
begin
  x.a:=rand([2..5]);
  x.b:=rand([6..10]);
  x.r:=x.a+rand([2,3]);
  x.s:=x.b+rand([3..5]);
  x.c:=x.r^2-x.a^2;
  x.d:=x.s^2-x.b^2;
  x.e:=x.c*x.d;
  x.f:=x.a*x.b;
  x.t:=x.r*x.s;
  k:=rand([1..4]);
  case k of
  1:begin
    fctn:='$$sin(\alpha+\beta)$$';
    a3:='$${\a\sqrt{\d}+\b\sqrt{\c}\over \t}$$';
    sol:='The addition formula for the sine states that '+
    	'$$sin(\alpha+\beta)=sin(\alpha)cos(\beta)+sin(\beta)cos(\alpha)$$.\pause\nl '+
	'Thus $$sin(\alpha+\beta)=({\a\over \r})({\sqrt{\d}\over \s})+'+
	'({\b\over \s})({\sqrt{\c}\over \r})='+a3+'$$';
    end;
  2:begin
    fctn:='$$sin(\alpha-\beta)$$';
    a3:='$${\a\sqrt{\d}-\b\sqrt{\c}\over \t}$$';
    sol:='The addition formula for the sine states that '+
    	'$$sin(\alpha-\beta)=sin(\alpha)cos(\beta)-sin(\beta)cos(\alpha)$$.\pause\nl '+
	'Thus $$sin(\alpha-\beta)=({\a\over \r})({\sqrt{\d}\over \s})-'+
	'({\b\over \s})({\sqrt{\c}\over \r})='+a3+'$$';
    end;
  3:begin
    fctn:='$$cos(\alpha-\beta)$$';
    a3:='$${\sqrt{\e}+\f\over \t}$$';
    sol:='The addition formula for the sine states that '+
    	'$$cos(\alpha-\beta)=cos(\alpha)cos(\beta)+sin(\alpha)sin(\beta)$$.\pause\nl '+
	'Thus $$sin(\alpha-\beta)=({\sqrt{\c}\over \r})({\sqrt{\d}\over \s})+'+
	'({\a\over \r})({\b\over \s})='+a3+'$$';
    end;
  4:begin
    fctn:='$$cos(\alpha+\beta)$$';
    a3:='$${\sqrt{\e}-\f\over \t}$$';
    sol:='The addition formula for the sine states that '+
    	'$$cos(\alpha+\beta)=cos(\alpha)cos(\beta)-sin(\alpha)sin(\beta)$$.\pause\nl '+
	'Thus $$sin(\alpha-\beta)=({\sqrt{\c}\over \r})({\sqrt{\d}\over \s})-'+
	'({\a\over \r})({\b\over \s})='+a3+'$$';
    end;
  end;{case}
  dgm::=#127'500,500,1200,10;I,250,250,50;L,-4,0,-1,0;L,-4,0,-1,3;'+
  	'L,-1,0,-1,3;L,0,0,4,0;L,4,0,4,5;L,0,0,4,5;B,2;C,-3.2,.3,\alpha;'+
	'C,.8,.3,\beta;B,0;C,-.8,1.3,\a;C,-3,1.8,\r;C,4.2,2.3,\b;'+
	'C,1.6,2.9,\s;';
  header:='\red{Answer all three parts before grading.}';
  text:='Two angles \alpha  and \beta  are described by the following '+
  	'two right triangles.';
  part1:='\red{a: } Determine sin(\alpha). (20%)';
  part2:='\red{b: } Determine cos(\beta). (20%)';
  part3:='\red{c: } Determine '+fctn+'. (60%)';
  text1::=dgm+#127+header+#13+#13+text+#13+part1+#13+part2+#13+part3+#13;
  buff1:=dgm+#127+text+#13+part1+#13+part2+#13+part3+#13;
  prompt::=#133'a: sin(\alpha) = '#134#13+
    	   #133'b: cos(\beta) = '#134#13+
	   #133'c: '+fctn+' = '#134;
  help::='\red{Addition Formulas:}\nl '+
    '\ \ $$sin(\alpha+\beta)=sin(\alpha)\cdot cos(\beta)+sin(\beta)\cdot cos(\alpha)$$\nl '+
    '\ \ $$sin(\alpha-\beta)=sin(\alpha)\cdot cos(\beta)-sin(\beta)\cdot cos(\alpha)$$\nl '+
    '\ \ $$cos(\alpha+\beta)=cos(\alpha)\cdot cos(\beta)-sin(\alpha)\cdot sin(\beta)$$\nl '+
    '\ \ $$cos(\alpha-\beta)=cos(\alpha)\cdot cos(\beta)+sin(\alpha)\cdot sin(\beta)$$\nl ';
  text3::=buff1+'\nl\blue{Hint:}\nl '+
  	'Use one of the addition formulas for the sine or cosine function.';
  ans:=#134'{\a\over \r}'#133+
       #134'{\sqrt{\d}\over \s}'#133+
       #134+a3;
  answer::=ans;
  separate(ans,a1,a2,a3);
  dgm:=dgm+'C,-3,-.5,\sqrt{\c};C,1.7,-.5,\sqrt{\d};';
  solution::=dgm+#127+'\nl\red{Solution to part a: }\nl '+
  	'From the left triangle we have sin(\alpha) = {opposite\over hypotenuse} '+
	'= '+a1+'.\pause\nl';
  solution2::='\nl\red{Solution to part b: }\nl '+
  	'From the right triangle we have cos(\beta) = {adjacent\over hypotenuse} '+
	'= '+a2+'.\pause\nl';
  solution3::='\nl\red{Solution to part c: }\nl '+sol;
  type:='R';
  key:=4167;
end;	   

procedure s4167;
var
  r1,r2,r3,r4,a1,a2,a3:string;
  r:integer;
  check1,check2,check3,undef,notwff:boolean;
begin
  message:='';
  separate(response,r1,r2,r3);
  check1:=false;
  check2:=false;
  check3:=false;
  separate(answer,a1,a2,a3);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  check3:=sameconstants(a3,r3);
    if check1 and check2 and check3 then begin
    result:='T';
    message:=#141'Correct'#141;
  end else begin
    if check1 then begin
      r:=r+2;
      message:='a: '+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:='a: '+r1+' is '#140'incorrect'#140'.'+#13+nl;
      end;
    end;
    if check2 then begin
      r:=r+2;
      message:=message+'b: '+r2+' is '#141'correct.'#141+nl;
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+'b: '+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check3 then begin
      r:=r+6;
      message:=message+'c: '+r3+' is '#141'correct'#141'.'+nl;
    end else begin
      if r3 = '' then begin
        message:=message+#140'c: Incorrect.'#140+nl;
      end else begin
        message:=message+'c: '+r3+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+text3;
  end;
end;

procedure p4168;	{old 1340}
var
  v:valuetype;
  a,b,j,k:integer;
  eqt,ans,sol:array[1..10] of string;
  mat:array[1..10] of integer;
begin
  v.a:=rand([2,3,6,7]);
  v.b:=rand([4,5,8]);
  v.c:=v.a*v.b;
  v.d:=v.c*v.c;
  for k:=1 to 10 do mat[k]:=k;
  permute(mat,10);
  text1:='Which of the following formulas are valid whenever both sides of '+
    'the equation are defined?';
  eqt[1]:=makeformula('sin(x+y)=sin(x)+sin(y)',[],v);ans[1]:='N';
  eqt[2]:=makeformula('sin(x+y)=sin(x)cos(y)+cos(x)sin(y)',[],v);ans[2]:='Y';
  eqt[3]:=makeformula('sin(x-y)=sin(x)-sin(y)',[],v);ans[3]:='N';
  eqt[4]:=makeformula('sin(x+y)=sin(x)cos(y)-cos(x)sin(y)',[],v);ans[4]:='N';
  eqt[5]:=makeformula('cos(x-y)=cos(x)sin(y)+sin(x)cos(y)',[],v);ans[5]:='N';
  eqt[6]:=makeformula('cos(x-y)=cos(x)cos(y)-sin(x)sin(y)',[],v);ans[6]:='N';
  eqt[7]:=makeformula('cos(x+y)=cos(x)cos(y)-sin(x)sin(y)',[],v);ans[7]:='Y';
  eqt[8]:=makeformula('cos(x-y)=cos(x)cos(y)+sin(x)sin(y)',[],v);ans[8]:='Y';
  eqt[9]:=makeformula('sin(x-y)=sin(x)cos(y)-cos(x)sin(y)',[],v);ans[9]:='Y';
  eqt[10]:=makeformula('sin(x-y)=sin(y)cos(x)-sin(x)cos(y)',[],v);ans[10]:='N';
  text2:=eqt[mat[1]];
  text3:=eqt[mat[2]];
  text4:=eqt[mat[3]];
  text5:=eqt[mat[4]];
  text6:=eqt[mat[5]];
  for j:=1 to 5 do replace('+nl+','',eqt[mat[j]]);
  answer:=ans[mat[1]]+ans[mat[2]]+ans[mat[3]]+ans[mat[4]]+ans[mat[5]];
  sol[1]:=eqt[1]+' fails. Letting both x and y equal ~/2, the formula would '+
    'give 0 = 2. The addition formula for the sine function states that '+
    '$$sin(x+y)=sin(x)cos(y)+cos(x)sin(y)$$.';
  sol[2]:=eqt[2]+' holds. This is the addition formula for the sine '+
    'function.';
  sol[3]:=eqt[3]+' fails. Letting x = ~ and y equal ~/2, the formula would '+
    'give 1 = -1. The subtraction formula for the sine function states that '+
    '$$sin(x-y)=sin(x)cos(y)-cos(x)sin(y)$$.';
  sol[4]:=eqt[4]+' fails. Letting x = 0 and y equal ~/2, the formula would '+
    'give 1 = -1. The addition formula for the sine function states that '+
    '$$sin(x+y)=sin(x)cos(y)+cos(x)sin(y)$$.';
  sol[5]:=eqt[5]+' fails. Letting x = ~ and y equal ~/2, the formula would '+
    'give 0 = -1. The subtraction formula for the cosine function states that '+
    '$$cos(x-y)=cos(x)cos(y)+sin(x)sin(y)$$.';
  sol[6]:=eqt[6]+' fails. Letting x = ~/2 and y equal ~/2, the formula would '+
    'give 1 = -1. The subtraction formula for the cosine function states that '+
    '$$cos(x-y)=cos(x)cos(y)+sin(x)sin(y)$$.';
  sol[7]:=eqt[7]+' holds. This is the addition formula for the cosine function.';
  sol[8]:=eqt[8]+' holds. This is the subtraction formula for the cosine '+
    'function.';
  sol[9]:=eqt[9]+' holds. This is the subtraction formula for the sine function.';
  sol[10]:=eqt[10]+' fails. Letting x = 0 and y equal ~/2, the formula would '+
    'give -1 = 1. The subtraction formula for the sine function states that '+
    '$$sin(x-y)=sin(x)cos(y)-cos(x)sin(y)$$.';
  solution::=#12'\red{Solution:}'+nl+
  	  '\red{Choice 1}'+nl+'You got this one \green{right}.'+nl+sol[mat[1]]+nl+nl;
  solution2::='\red{Choice 2}'+nl+'You got this one \green{right}.'+nl+sol[mat[2]]+nl+nl;
  solution3::='\red{Choice 3}'+nl+'You got this one \green{right}.'+nl+sol[mat[3]]+nl+nl;
  solution4::='\red{Choice 4}'+nl+'You got this one \green{right}.'+nl+sol[mat[4]]+nl+nl;
  solution5::='\red{Choice 5}'+nl+'You got this one \green{right}.'+nl+sol[mat[5]]+nl+nl;
  buff3:='Consider the addition and subtraction formulas for the sine and '+
	  'cosine functions.';
  help::='\red{Addition Formulas:}\nl '+
      '\ \ $$sin(\alpha+\beta)=sin(\alpha)\cdot cos(\beta)+sin(\beta)\cdot cos(\alpha)$$\nl '+
      '\ \ $$sin(\alpha-\beta)=sin(\alpha)\cdot cos(\beta)-sin(\beta)\cdot cos(\alpha)$$\nl '+
      '\ \ $$cos(\alpha+\beta)=cos(\alpha)\cdot cos(\beta)-sin(\alpha)\cdot sin(\beta)$$\nl '+
      '\ \ $$cos(\alpha-\beta)=cos(\alpha)\cdot cos(\beta)+sin(\alpha)\cdot sin(\beta)$$\nl ';
  type:='S';
  key:=4168;
end;

procedure s4168;
var
  j,n:integer;
  res,w,z:string;
begin
  z:='';
  n := 10;
  for j:=1 to 5 do begin
    if answer[j-1] <> response[j-1] then begin
      z:=z+st(j)+',';
      n := n - 2;
    end;
  end;
  result := chr(48+n);
  if response='     ' then message:=#140'Incorrect'#140#13#142'Hint:'#142+buff3
  else begin
    if answer=response then begin
      message:=#141'Correct.'#141;
    end else begin
      w := '';
      if pos('1',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution) else
         replace(#140'wrong'#140,#141'right'#141,solution);
      if pos('2',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution2) else
         replace(#140'wrong'#140,#141'right'#141,solution2);
      if pos('3',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution3) else
         replace(#140'wrong'#140,#141'right'#141,solution3);
      if pos('4',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution4) else
         replace(#140'wrong'#140,#141'right'#141,solution4);
      if pos('5',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution5) else
         replace(#140'wrong'#140,#141'right'#141,solution5);
      message:=response+' is '#140'incorrect'#140'.'+#13+
      #142'Hint:'#142#13+buff3;
    end;
  end;
end;

procedure p4169;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,a3,dgm,fctn,sol,header,text,part1,part2,part3:string;
  k:integer;
begin
  x.a:=rand([-10..-2]);
  x.b:=-x.a+rand([2..4]);
  x.r:=x.a^2+x.b^2;
  x.d:=2*x.a*x.b;
  x.e:=x.a^2-x.b^2;
  k:=randint(1,2);
  case k of
  1:begin
    fctn:='sin(2\theta)';
    a3:='{$\d\over \r$}';
    sol:='By the double angle formula we have '+
    	'$$sin(2\theta)=2sin(\theta)cos(\theta)$$\pause\nl '+
	'= $$2\cdot({\b\over \sqrt{\r}})\cdot({\a\over \sqrt{\r}})$$\pause\nl '+
	'= '+a3+'.';
    end;
  2:begin
    fctn:='cos(2\theta)';
    a3:='{$\e\over \r$}';
    sol:='By the double angle formula we have '+
    	'$$cos(2\theta)=cos^2(\theta)-sin^2(\theta)$$\pause\nl '+
	'= $$({\a\over \sqrt{\r}})^2-({\b\over \sqrt{\r}})^2$$\pause\nl '+
	'= '+a3+'.';
    end;
  end;{case}
  dgm::=#127'500,500,1200,10;I,250,250,50;E,-4,-4,4,4;L,0,0,4,0;'+
  	'L,0,0,-2.38,3.2;G,3.2,D-2.38,-2.38;P,1.5,0,2.2;B,2;C,.7,1.6,\theta;C,-4.8,3.6,(\a,\b);'+
	'C,1.8,-.6,\sqrt{\r};'#127;
  header:='\red{Answer all three parts before grading.}';
  text:='Let \theta  denote an angle in standard position as indicated '+
  	'to the right. The point (\a,\b) lies on the terminal side of \theta.';
  part1:='\red{a: } Determine cos(\theta). (20%)';
  part2:='\red{b: } Determine sin(\theta). (20%)';
  part3:='\red{c: } Determine '+fctn+'. (60%)';
  text1::=dgm+header+#13+#13+text+#13+part1+#13+part2+#13+part3+#13+nl+nl+nl+nl;
  buff1:=dgm+text+#13+part1+#13+part2+#13+part3+#13;
  prompt::=#133'a: cos(\theta) = '#134#13+
    	   #133'b: sin(\theta) = '#134#13+
	   #133'c: '+fctn+' = '#134#;
  help::='\red{Double Angle Formulas:}\nl '+
  	'\ \ $$sin(2\theta)=2sin(\theta)cos(\theta)$$\nl '+
	'\ \ $$cos(2\theta)=cos^2(\theta)-sin^2(\theta)$$\nl\nl\nl'+
  	#127'500,500,800,10;I,250,250,50;E,-4,-4,4,4;L,0,0,4,0;'+
  	'L,0,0,-2.38,3.2;P,1.5,0,2.2;B,2;C,.7,1.6,\theta;C,-4.6,3.4,(x,y);'+
	'C,1.8,-.6,r;'#127+
	'\red{Definitions of Trig Frunctions:}\nl '+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$';
  text3::=buff1+'\nl\blue{Hint:}\nl '+
  	'Use the circular definition of the trig functions to find cos(\theta) '+
	'and sin(\theta). Then use one of the double angle formulas.';
  ans:=#134'{\a\over \sqrt{\r}}'#133+
       #134'{\b\over \sqrt{\r}}'#133+
       #134+a3;
  answer::=ans;
  separate(ans,a1,a2,a3);
  solution::='\nl\red{Solution to part a: }\nl '+
  	'If (x,y) is on the circle of radius r and on the terminal side of '+
	'an angle \theta  in standard position, cos(\theta) = {x\over r}.\pause\nl '+
	'Thus cos(\theta) = {\a\over \sqrt{\r}}.\pause\nl ';
  solution2::='\nl\red{Solution to part b: }\nl '+
  	'If (x,y) is on the circle of radius r and on the terminal side of '+
	'an angle \theta  in standard position, sin(\theta) = {y\over r}.\pause\nl '+
	'Thus sin(\theta) = {\b\over \sqrt{\r}}.\pause\nl ';
  solution3::='\nl\red{Solution to part c: }\nl '+sol;
  type:='R';
  key:=4169;
end;	   

procedure s4169;
var
  r1,r2,r3,r4,a1,a2,a3:string;
  r:integer;
  check1,check2,check3,undef,notwff:boolean;
begin
  message:='';
  separate(response,r1,r2,r3);
  check1:=false;
  check2:=false;
  check3:=false;
  separate(answer,a1,a2,a3);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  check3:=sameconstants(a3,r3);
    if check1 and check2 and check3 then begin
    result:='T';
    message:=#141'Correct'#141;
  end else begin
    if check1 then begin
      r:=r+2;
      message:='a: '+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:='a: '+r1+' is '#140'incorrect'#140'.'+#13+nl;
      end;
    end;
    if check2 then begin
      r:=r+2;
      message:=message+'b: '+r2+' is '#141'correct.'#141+nl;
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+'b: '+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check3 then begin
      r:=r+6;
      message:=message+'c: '+r3+' is '#141'correct'#141'.'+nl;
    end else begin
      if r3 = '' then begin
        message:=message+#140'c: Incorrect.'#140+nl;
      end else begin
        message:=message+'c: '+r3+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+text3;
  end;
end;

procedure p4173;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2:string;
begin
  x.a:=rand([2..10]);
  x.b:=x.a+rand([2..5]);
  dgm::=#127'500,500,1200,10;I,250,150,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'L,3.7,0,3.7,.3;L,3.7,.3,4,.3;C,1.8,-.5,\a;C,4.2,2.8,\b;B,2;C,.8,.3,\theta;'#127;
  header:='\red{Answer both parts before grading.}';
  text:='Determine the angle \theta  in the following right triangle.';
  part1:='\red{a: } Express \theta  in radians. (50%)';
  part2:='\red{b: } Express \theta  in degrees. (50%)';
  text1::=dgm+header+#13+#13+text+#13+part1+#13+part2+#13+#13+#13;
  buff1:=dgm+text+#13+part1+#13+part2+nl;
  prompt::=#133'a: \theta  in radians:'#134#13+
    	   #133'b: \theta  in degrees: '#134;
  help::='\red{Inverse Trig Functions:}\nl '+
   	 '\ \ sin(x) = y <=> arcsin(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl '+
	 '\ \ cos(x) = y <=> arccos(y) = x if $$0<\theta<\pi$$.\nl '+
  	 '\ \ tan(x) = y <=> arctan(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl\nl '+
  	 '360^{\circ} = 2\pi  radians\nl\nl '+
  	#127'500,500,800,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'C,2,-.5,x;C,4.2,3,y;C,.8,.25,\theta;C,1.2,3,r;'#127+
	'\red{Definitions of Trig Frunctions:}\nl '+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$';
  text3::=buff1+'\nl\blue{Hint:}\nl '+
  	'Use the arctan function to express \theta  in radians. Then '+
	'convert to degrees.';
  x.z:=arctan(x.b/x.a);
  x.w:=x.z*180/pi;  	
  ans:=#134'\z:6'#133+
       #134'\w:6^{\circ}';
  answer::=ans;
  separate(ans,a1,a2);
  solution::='\nl\red{Solution to part a:}\nl '+
  	'From the triangle we have tan(\theta) = {\b\over \a}.\pause\nl '+
	'Since $$0<\theta<{\pi\over 2}$$, it follows that\nl '+
	'$$\theta=arctan({$\b\over \a$})\doteq\z:6$$.\nl '+
	'This gives \theta  in radians.'#10;
  solution2::='\nl\red{Solution to part b:}\nl '+
  	'To convert \theta  to degrees, we multiply by {180\over \pi}: '+
	'$$\theta=\z:6\cdot{180\over \pi}\doteq\w:6^{\circ}$$.';
  type:='R';
  key:=4173;
end;		       

procedure s4173;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2) or (sameconstants(a1,r2) and (pos('`',r2)>-1));
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4177;
var
  a,b,c,d,e,f,j,k:integer;
  p,q,r,s,t:real;
  v:valuetype;
  ans1,ans2,deg:string;
  functn,intvl:string;
begin
  k:=randint(1,6);
  b:=rand([3,5,7]);v.b:=b;
  c:=2*b;
  d:=randint(2,6);v.d:=d;
  f:=randint(3,7);v.f:=f;
  case randint(1,6) of
  1:begin
      functn:=st(d)+' + sin('+st(b)+'x)';
      intvl:='[-~/'+st(2*b)+',~/'+st(2*b)+']';
      answer:=makeformula(fraction(1,'-',b)+'arcsin(x-d)',['b','d'],v);
      solution := 'y = '+functn+#10+nl+
        makeformula('y-d=sin(bx)',['b','d'],v)+#10+nl+
        makeformula('arcsin(y-d)=bx',['b','d'],v)+#10+nl+
        makeformula('[arcsin(y-d)]/[b]=x',['b','d'],v)+#10+nl+
        'Interchange x and y:'#10+nl+
        'y = '+answer+'.';
    end;
  2:begin
      functn:=st(f)+' + '+st(d)+'arctan('+st(b)+'x)';
      intvl:='(-\,\)';
      answer:=makeformula('[1]/[b]tan([x - f]/[d])',['b','d','f'],v);
      solution := 'y = '+functn+#10+nl+
        makeformula('y-f=darctan(bx)',['b','d','f'],v)+#10+nl+
        makeformula('[y-f]/[d]=arctan(bx)',['b','d','f'],v)+#10+nl+
        makeformula('tan[y-f]/[d]=bx',['b','d','f'],v)+#10+nl+
        makeformula('[1]/[b]tan[y-f]/[d]=x',['b','d','f'],v)+#10+nl+
        'Interchange x and y:'#10+nl+
        'y = '+answer+'.';
    end;
  3:begin
      functn:=st(f)+' + '+st(d)+'tan('+st(b)+'x)';
      intvl:='(-~/'+st(2*b)+',~/'+st(2*b)+')';
      answer:=makeformula('[1]/[b]arctan([x - f]/[d])',['b','d','f'],v);
      solution := 'y = '+functn+#10+nl+
        makeformula('y-f=dtan(bx)',['b','d','f'],v)+#10+nl+
        makeformula('[y-f]/[d]=tan(bx)',['b','d','f'],v)+#10+nl+
        makeformula('arctan([y-f]/[d])=bx',['b','d','f'],v)+#10+nl+
        makeformula('[1]/[b]arctan([y-f]/[d])=x',['b','d','f'],v)+#10+nl+
        'Interchange x and y:'#10+nl+
        'y = '+answer+'.';
    end;
  4:begin
      functn:=st(f)+' + '+st(d)+'arccos('+st(b)+'x)';
      intvl:='['+fraction(-1,'-',b)+','+fraction(1,'-',b)+']';
      answer:=fraction(1,'-',b)+'cos('#29#219'x - '+st(f)+#221'/'#219+st(d)+#221+
        ')';
      solution := 'y = '+functn+#10+nl+
        makeformula('y-f=darccos(bx)',['b','d','f'],v)+#10+nl+
        makeformula('[y-f]/[d]=arccos(bx)',['b','d','f'],v)+#10+nl+
        makeformula('cos([y-f]/[d])=bx',['b','d','f'],v)+#10+nl+
        makeformula('[1]/[b]cos([y-f]/[d])=x',['b','d','f'],v)+#10+nl+
        'Interchange x and y:'#10+nl+
        'y = '+answer+'.';
    end;
  5:begin
      functn:=st(f)+' - '+st(d)+'arcsin('+st(b)+'x)';
      intvl:='['+fraction(-1,'-',b)+','+fraction(1,'-',b)+']';
      answer:=fraction(1,'-',b)+'sin('#29#219+st(f)+' - x'#221'/'#219+st(d)+
        #221')';
      solution := 'y = '+functn+#10+nl+
        makeformula('f-y=darcsin(bx)',['b','d','f'],v)+#10+nl+
        makeformula('[f-y]/[d]=arcsin(bx)',['b','d','f'],v)+#10+nl+
        makeformula('sin([f-y]/[d])=bx',['b','d','f'],v)+#10+nl+
        makeformula('[1]/[b]sin([f-y]/[d])=x',['b','d','f'],v)+#10+nl+
        'Interchange x and y:'#10+nl+
        'y = '+answer+'.';
    end;
  6:begin
      functn:=st(d)+'cos('+st(b)+'x) + '+st(f);
      intvl:='['+makeformula('0,[~]/[b]',['b'],v)+']';
      answer:=fraction(1,'-',b)+'arccos('#29#219'x - '+st(f)+#221'/'#219+st(d)+
        #221')';
      solution := 'y = '+functn+#10+nl+
        makeformula('y-f=dcos(bx)',['b','d','f'],v)+#10+nl+
        makeformula('[y-f]/[d]=cos(bx)',['b','d','f'],v)+#10+nl+
        makeformula('arccos([y-f]/[d])=bx',['b','d','f'],v)+#10+nl+
        makeformula('[1]/[b]arccos([y-f]/[d])=x',['b','d','f'],v)+#10+nl+
        'Interchange x and y:'#10+nl+
        'y = '+answer+'.';
    end;
  end;
  text1:='Find a formula for f'#30'-1'#31'(x) if '+nl+
    '     f(x) = '+functn+' on '+intvl+'.'+nl+
    'You may assume the given function is one-to-one.'+nl;
  text3::=text1+'\nl\blue{Hint:}\nl '+
    'Solve for x in terms of y and then interchange x and y.';
  prompt:=#133'f'#30'-1'#31+'(x) = '#134;
  solution::='\nl\red{Solution:}\nl '+solution;
  help::='\red{Inverse Functions:}\nl '+
   	'A function must be one-to-one in order to have an inverse function.\nl '+
  	'Given y = f(x), solving for x in terms of y gives the formula '+
  	'for f^{-1}(y). Interchange the variables x and y to get the '+
	'formula for f^{-1}(x).\nl\nl '+
	'(f^{-1}\circ f)(x) = (f\circ f^{-1})(x) = x\nl\nl '+
	'\red{Inverse Trig Functions:}\nl '+
   	'\ \ sin(x) = y <=> arcsin(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl '+
	'\ \ cos(x) = y <=> arccos(y) = x if $$0<\theta<\pi$$.\nl '+
  	'\ \ tan(x) = y <=> arctan(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl\nl ';
  type:='R';
  key := 4177;
end;

procedure s4177;             
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4179;	{old 1226}
var
  a,b,c,d,e,f,j,k:integer;
  p,q,r,s,t:real;
  functn,ans,mess,sol:array[1..9] of string;
  dgm1,dgm2,dgm3:string;
begin
  k:=randint(1,9);
  a:=rand([2,3,5,6]);
  b:=rand([2,4,6,7]);
  c:=randint(1,5);
  dgm1:=#127'500,500,1200,10;A,250,250,100;B,2;G,arcsin(x),-1,1;B,4;'+
	'C,.2,1.7,y=arcsin(x);B,0;D,-1,-1.57,0,-1.57,4;C,.2,-1.57,-{\pi\over 2};'+
	'D,0,1.57,1,1.57,3;C,-.8,1.6,{\pi\over 2};'#127	;
  dgm2:=#127'500,500,1200,10;A,250,100,100;B,2;G,arccos(x),-1,1;B,4;'+
	'C,.2,3.5,y=arccos(x);B,0;D,-1,3.14,0,3.14,3;C,.2,3,\pi;'#127;
  dgm3:=#127'500,500,1200,10;A,250,250,50;B,2;G,arctan(x),-5,5;'+
	'B,0;D,-5,1.57,5,1.57,20;D,-5,-1.57,5,-1.57,20;C,-4,2.2,y={\pi\over 2};'+
	'C,3,-1.1,y=-{\pi\over 2};'+
	'B,4;C,.2,2.2,y=arctan(x);'#127;
  functn[1]:=#29#219'1'#221'/'#219'arccos('+st(a)+'x)'#221;
  mess[1]:=st(a)+'x must be in [-1,1] and the arccosine function must be '+
    'non-zero.';
  sol[1]:=dgm2;
  functn[2]:=#29#219'1'#221'/'#219'arcsin('+st(a)+'x)'#221;
  mess[2]:=st(a)+'x must be in [-1,1] and the arcsine function must be '+
    'non-zero.';
  sol[2]:=dgm1;
  functn[3]:='arcsin('#29#219'1'#221'/'#219'x'#221')';
  mess[3]:='1/x must be within [-1,1].';
  sol[3]:=#127'500,500,1200,10;A,250,250,50;B,2;G,1/x,-5,5;B,0;'+
  	'D,-5,1,5,1,20;D,-5,-1,5,-1,20;B,4;C,.5,4,y={1\over x};'#127;
  functn[4]:=#29#219'arcsin(x)'#221'/'#219'x'#221;
  mess[4]:='x must be within [-1,1] and must be non-zero.';
  sol[4]:=dgm1;
  functn[5]:=#29#219'arctan(x)'#221'/'#219'x - '+st(a)+#221;
  mess[5]:='Arctan(x) is defined for all x.\pause\nl '+
    'However, x - '+st(a)+' must be non-zero.';
  sol[5]:=dgm3;
  functn[6]:=#29#219'arcsin(x)'#221'/'#219+st(a)+'x + 1'#221;
  mess[6]:='x must be within [-1,1] and '+st(a)+'x + 1 must be non-zero.';
  sol[6]:=dgm1;
  functn[7]:='@'#251'arcsin(x)'#253;
  mess[7]:='x must be within [-1,1] and arcsin(x) must be \ge  0.';
  sol[7]:=dgm1;
  functn[8]:='@'#251'arccos(x)'#253;
  mess[8]:='x must be within [-1,1] and arccos(x) must be \ge  0.';
  sol[8]:=dgm2;
  functn[9]:='@'#251'arctan(x)'#253;
  mess[9]:='x can be any real number for which arctan(x) \ge  0.';
  sol[9]:=dgm3;
  text1:='Determine the domain of the function '+nl+
    '       f(x) = '+functn[k]+'.'+nl+
    'Express your answer as a collection of intervals separated by commas.'+
    nl;
  text3::=text1+#13+'\nl\blue{Hint:}\nl '+mess[k];
  prompt::=#133'domain of '+functn[k]+':'#134;
  help::='\red{Domain Information:}\nl '+
	'\ \ Expressions inside square root signs must be \ge  0.\nl '+
  	'\ \ Division by zero is not allowed.\nl '+#10#12+
	#127'500,500,100,10;A,250,250,100;B,2;G,arcsin(x),-1,1;B,4;'+
	'C,.2,1.7,y=arcsin(x);B,0;D,-1,-1.57,0,-1.57,4;C,.2,-1.57,-{\pi\over 2};'+
	'D,0,1.57,1,1.57,3;C,-.8,1.6,{\pi\over 2};'#127+
	#127'500,500,700,10;A,250,100,100;B,2;G,arccos(x),-1,1;B,4;'+
	'C,.2,3.5,y=arccos(x);B,0;D,-1,3.14,0,3.14,3;C,.2,3,\pi;'#127+
	nl+nl+nl+nl+nl+nl+nl+nl+nl+nl+nl+
	#127'500,500,100,10;A,250,250,50;B,2;G,arctan(x),-5,5;'+
	'B,0;D,-5,1.57,5,1.57,20;D,-5,-1.57,5,-1.57,20;C,-4,2.2,y={\pi\over 2};'+
	'C,3,-1.1,y=-{\pi\over 2};'+
	'B,4;C,.2,2.2,y=arctan(x);'#127+nl;
  ans[1]:='['+fraction(-1,'-',a)+','+fraction(1,'-',a)+')';
  ans[2]:='['+fraction(-1,'-',a)+',0),(0,'+fraction(1,'-',a)+']';
  ans[3]:='(-\inf,-1],[1,\inf)';
  ans[4]:='[-1,0),(0,1]';
  ans[5]:='(-\inf,'+st(a)+'),('+st(a)+',\inf)';
  ans[6]:='[-1,'+fraction(-1,'-',a)+'),('+fraction(-1,'-',a)+',1]';
  ans[7]:='[0,1]';
  ans[8]:='[-1,1]';
  ans[9]:='[0,\inf)';
  answer::=ans[k];
  solution::='\nl\red{Solution:}\nl '+sol[k]+nl+
    'The domain of the function '+functn[k]+' is '+ans[k]+'.';
  type:='R';
  key := 4179;
end;

procedure s4179;             
begin
  replace(prompt,'',response);
  if sameintervals(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4180;
var
  b,d,k:integer;
  functn,ans,dgm:array[1..4] of string;
  x:paramtype;
begin
  k:=randint(1,4);
  if k<4 then
  b:=rand([-3,-2,2,3])
  else b:=rand([-2,-4,-5,2]);x.b:=b;
  x.c:=-x.b+1;
  x.d:=-x.b-1;
  x.e:=pi/2+x.b;
  if x.b=-2.0 then x.g:=x.e-.6 else x.g:=x.e+.8;
  x.f:=-pi/2+x.b;
  if x.b=2.0 then x.h:=x.f+.8 else x.h:=x.f-.5;
  functn[1]:='arcsin(x + '+st(b)+')'; 
  dgm[1]::=#127'500,500,1200,-100;A,250,250,50;B,2;G,'+functn[1]+',\d:2,\c:2;'+
  	'B,0;D,-5,1.57,5,1.57,20;D,-5,-1.57,5,-1.57,20;B,4;C,2,2.2,y={\pi\over 2};'+
	'C,-3,-2.2,y=-{\pi\over 2};C,.2,4,y=arcsin(x+'+st(b)+');'#127;
  functn[2]:='arccos(x + '+st(b)+')';
  dgm[2]::=#127'500,500,1200,-100;A,250,250,50;B,2;G,'+functn[2]+',\d:2,\c:2;'+
  	'B,0;D,-5,3.14,5,3.14,20;B,4;C,2,3.3,y=\pi;'+
	'C,.2,4,y=arccos(x+'+st(b)+');'#127;
  functn[3]:='arcsin(x) + '+st(b);
  dgm[3]::=#127'560,560,1200,-100;A,280,280,40;B,2;G,'+functn[3]+',-1,1;'+
  	'B,0;D,-7,\e:2,7,\e:2,20;D,-7,\f:2,7,\f:2,20;B,4;C,2,\g:2,y=\b+{\pi\over 2};'+
	'C,-6,\h:2,y=\b-{\pi\over 2};C,.2,6,y=arcsin(x)+\b;'#127;
  functn[4]:='arccos(x) + '+st(b);
  x.m:=x.b+pi;
  x.n:=x.m+.3;
  x.p:=x.b-.5;
  dgm[4]::=#127'560,560,1200,-100;A,280,160,40;B,2;G,'+functn[4]+',-1,1;'+
  	'B,0;D,-7,\m:2,7,\m:2,20;D,-7,\b:2,7,\b:2,20;B,4;C,2,\n:2,y=\b+\pi;'+
	'C,-4,\p:2,y=\b;C,.2,7,y=arccos(x)+\b;'#127;
  if x.b<.0 then replace('160','400',dgm[4]);
  if x.b<.0 then replace('.2,7','.2,3',dgm[4]);
  replace('+ -','- ',functn[k]);
  replace('+-','-',dgm[k]);
  text1:='Determine the range of the function '+nl+
    '       f(x) = '+functn[k]+'.'+nl+
    'Express your answer as a collection of intervals separated by commas.'+
    nl;
  text3:='Sketch the graph. A number c is in the range if the horizontal '+
         'line y = c intersects the graph.';
  ans[1]:='[-~/2,~/2]';
  ans[2]:='[0,~]';
  ans[3]:='['+st(b)+'-'#29#219'~'#221'/'#219'2'#221','+st(b)+'+'#29#219+
           '~'#221'/'#219'2'#221']';
  ans[4]:='['+st(b)+','+st(b)+'+~]';
  answer:=ans[k];
  solution::=nl+'\nl\red{Solution:}\nl '+dgm[k]+
  	'The range of f(x) = '+functn[k]+' is '+ans[k]+'.';
  text3::=text1+'\nl\blue{Hint:}\nl '+text3;
  prompt::=#133'range:'#134;
  help::='\red{Vertical and Horizontal Shifts:}\nl '+
  	'f(x) -> f(x - a) shifts the graph of f(x) a units to the right '+
	'if a > 0 and |a| units to the left if a < 0.\nl\nl '+
	'f(x) -> f(x) + a shifts the graph of f(x) a units upwards if '+
	'a > 0 and |a| units downwards if a < 0.\nl\nl '+
	'\red{Inverse Trig Functions:}\nl '+
	#127'500,500,100,10;A,250,250,100;B,2;G,arcsin(x),-1,1;B,4;'+
	'C,.2,1.7,y=arcsin(x);B,0;D,-1,-1.57,0,-1.57,4;C,.2,-1.57,-{\pi\over 2};'+
	'D,0,1.57,1,1.57,3;C,-.8,1.6,{\pi\over 2};'#127+
	#127'500,500,700,10;A,250,100,100;B,2;G,arccos(x),-1,1;B,4;'+
	'C,.2,3.5,y=arccos(x);B,0;D,-1,3.14,0,3.14,3;C,.2,3,\pi;'#127+
	nl+nl+nl+nl+nl+nl+nl+nl+nl+nl+nl+
	#127'500,500,100,10;A,250,250,50;B,2;G,arctan(x),-5,5;'+
	'B,0;D,-5,1.57,5,1.57,20;D,-5,-1.57,5,-1.57,20;C,-4,2.2,y={\pi\over 2};'+
	'C,3,-1.1,y=-{\pi\over 2};'+
	'B,4;C,.2,2.2,y=arctan(x);'#127;
  type:='R';
  key := 4180;
end;

procedure s4180;
begin
  replace(prompt,'',response);
  if sameintervals(answer,response) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect.'#140+#13+text3
    else message:=response+' is '+#140'incorrect'#140+'. '#13+text3;
  end;
end;

procedure p4183;
var
  a,b,c,d,e,f,j,k:integer;
  p,q,r,s,t:real;
  v:valuetype;
  functn,ans,intvl:string;
begin
  k:=randint(1,3);
  b:=rand([3,5,7]);v.b:=b;
  d:=randint(2,6);v.d:=d;
  f:=randint(3,7);v.f:=f;
  if k=1 then begin
    functn:=makeformula('e^(ftan(x))',['f'],v);
    intvl:='(-~/2,~/2)';
    answer:=makeformula('arctan([ln(x)]/[f])',['f'],v);
    solution:=makeformula('y='+functn,[],v)+#10+nl+
             ' => '+makeformula('ln(y)=ln(e^(ftan(x)))=ftan(x)',['f'],v)+#10+nl+
             ' => '+makeformula('[ln(y)]/[f]=tan(x)',['f'],v)+#10+nl+
             ' => '+makeformula('arctan([ln(y)]/[f])=arctan(tan(x))=x.',['f'],v)+#10+nl+
             'Interchanging x and y, we obtain '+nl+
             makeformula('y=arctan([ln(x)]/[f])',['f'],v)+#10+nl+
             ' => '+makeformula('f^(-1)(x) = '+answer+'.',[],v);
  end;
  if k=2 then begin
    functn:=makeformula('ln(tan(bx))',['b'],v);
    intvl:='(0,~/'+st(2*b)+')';
    answer:=makeformula('[arctan(e^x)]/[b]',['b'],v);
    solution:=makeformula('y='+functn,[],v)+#10+nl+
             ' => '+makeformula('e^y=e^(ln(tan(bx)))=tan(bx)',['b'],v)+#10+nl+
             ' => '+makeformula('arctan(e^y)=arctan(tan(bx))=bx',['b'],v)+#10+nl+
             ' => '+makeformula('[arctan(e^y)]/[b]=x',['b'],v)+#10+nl+
             'Interchanging x and y, we obtain '+nl+
             makeformula('y=[arctan(e^x)]/[b]',['b'],v)+#10+nl+
             ' => '+makeformula('f^(-1)(x) = '+answer+'.',[],v);
  end;
  if k=3 then begin
    functn:=makeformula('fe^(arctan(x))',['f'],v);
    intvl:='(-\,\)';
    answer:=makeformula('tan(ln([x]/[f]))',['f'],v);
    solution:=makeformula('y='+functn,[],v)+#10+nl+
             ' => '+makeformula('[y]/[f]=e^(arctan(x))',['f'],v)+#10+nl+
             ' => '+makeformula('ln([y]/[f])=ln(e^(arctan(x)))=arctan(x)',['f'],v)+#10+nl+
             ' => '+makeformula('tan(ln([y]/[f]))=tan(arctan(x))=x',['f'],v)+#10+nl+
             'Interchanging x and y, we obtain '+nl+
             makeformula('y=tan(ln([x]/[f]))',['f'],v)+#10+nl+
             ' => '+makeformula('f^(-1)(x) = '+answer+'.',[],v);
  end;
  text1:='Find a formula for f'#30'-1'#31'(x) if '+nl+
    '     f(x) = '+functn+' on '+intvl+'.'+nl+
    'You may assume the given function is one-to-one.'+nl;
  prompt:=#133'f'#30'-1'#31+'(x) = '#134;
  text3::=text1+'\nl\blue{Hint:}\nl '+
  	'Solve for x in terms of y and then interchange x and y.';
  solution::='\nl\red{Solution:}\nl '+solution;
  help::='\red{Inverse Functions:}\nl '+
  'A function must be one-to-one in order to have an inverse function.\nl '+
  'Given y = f(x), solving for x in terms of y gives the formula '+
  	'for f^{-1}(y). Interchange the variables x and y to get the '+
	'formula for f^{-1}(x).\nl\nl '+
	'(f^{-1}\circ f)(x) = (f\circ f^{-1})(x) = x\nl\nl '+
  	'\red{Inverse Trig Functions:}\nl '+
   	'\ \ sin(x) = y <=> arcsin(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl '+
	'\ \ cos(x) = y <=> arccos(y) = x if $$0<\theta<\pi$$.\nl '+
  	'\ \ tan(x) = y <=> arctan(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl\nl '+
	'\red{Logs and Exponentials:}\nl '+
	'ln(e^x) = x\ \ \ e^{ln(x)} = x';
  type:='R';
  key := 4183;
end;

procedure s4183;             
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4184;	{old 1381}
var
  k:integer;
  functn:string;
  v:valuetype;
  x:paramtype;
begin
  case randint(1,6) of
  1:
  begin
    functn:='arcsin(-'#29#219'1'#221'/'#219'2'#221')';
    answer:='-{\pi\over 6}';
    x.a:=pi/6;
    solution:=#127'600,600,1200,10;A,300,300,100;B,2;G,arcsin(x),-1,1;'+
    	'L,0,-\a:2,-.5,-\a:2;L,-.5,-\a:2,-.5,0;B,4;C,.1,-.5,{-\pi\over 6};'+
	'C,-.85,.35,{-1\over 2};C,.2,2,y=arcsin(x);'#127+
	nl+#140'Solution:'#140+nl+
	'The range of the function f(x) = arcsin(x) is [{-\pi\over 2},{\pi\over 2}].\pause\nl '+
	'Now '+functn+' is the angle \theta  between -{\pi\over 2} and {\pi\over 2} '+
	'where sin(\theta) = -{1\over 2}.\pause\nl '+
	'From our knowledge of special values we know sin({\pi\over 6}) = {1\over 2}.\pause\nl '+
	'Since the sine function is odd, we have sin(-{\pi\over 6}) = -{1\over 2}.\pause\nl '+
	'Thus '+functn+' = '+answer+'.';
  end;
  2:
  begin
    functn:=makeformula('arcsin([{3}]/[2]',[],v);
    answer:='{\pi\over 3}';
    x.a:=pi/3;
    solution:=#127'600,600,1200,10;A,300,300,100;B,2;G,arcsin(x),-1,1;'+
    	'L,0,\a:2,.87,\a:2;L,.87,\a:2,.87,0;B,4;C,-.7,1.1,{\pi\over 3};'+
	'C,.6,-.5,{\sqrt{3}\over 2};C,.2,2,y=arcsin(x);'#127+
	nl+#140'Solution:'#140+nl+
	'The range of the function f(x) = arcsin(x) is [{-\pi\over 2},{\pi\over 2}].\pause\nl '+
	'Now '+functn+' is the angle \theta  between -{\pi\over 2} and {\pi\over 2} '+
	'where sin(\theta) = {\sqrt{3}\over 2}.\pause\nl '+
	'From our knowledge of special values we know sin({\pi\over 3}) = {\sqrt{3}\over 2}.\pause\nl '+
	'Thus '+functn+' = '+answer+'.';
  end;
  3:
  begin
    functn:=makeformula('arcsin([-{2}]/[2]',[],v);
    answer:='-{\pi\over 4}';
    x.a:=pi/4;
    solution:=#127'600,600,1200,10;A,300,300,100;B,2;G,arcsin(x),-1,1;'+
    	'L,0,-\a:2,-.71,-\a:2;L,-.71,-\a:2,-.71,0;B,4;C,.1,-.7,{-\pi\over 4};'+
	'C,-1.3,.35,{-\sqrt{2}\over 2};C,.2,2,y=arcsin(x);'#127+
	nl+#140'Solution:'#140+nl+
	'The range of the function f(x) = arcsin(x) is [{-\pi\over 2},{\pi\over 2}].\pause\nl '+
	'Now '+functn+' is the angle \theta  between -{\pi\over 2} and {\pi\over 2} '+
	'where sin(\theta) = -{\sqrt{2}\over 2}.\pause\nl '+
	'From our knowledge of special values we know sin({\pi\over 4}) = {\sqrt{2}\over 2}.\pause\nl '+
	'Since the sine function is odd, we have sin(-{\pi\over 4}) = -{\sqrt{2}\over 2}.\pause\nl '+
	'Thus '+functn+' = '+answer+'.';
  end;
  4:
  begin
    functn:=makeformula('arcsin([{2}]/[2]',[],v);
    answer:='{\pi\over 4}';
    x.a:=pi/4;
    solution:=#127'600,600,1200,10;A,300,300,100;B,2;G,arcsin(x),-1,1;'+
    	'L,0,\a:2,.71,\a:2;L,.71,\a:2,.71,0;B,4;C,-.5,.9,{\pi\over 4};'+
	'C,.4,-.4,{\sqrt{2}\over 2};C,.2,2,y=arcsin(x);'#127+
	nl+#140'Solution:'#140+nl+
	'The range of the function f(x) = arcsin(x) is [{-\pi\over 2},{\pi\over 2}].\pause\nl '+
	'Now '+functn+' is the angle \theta  between -{\pi\over 2} and {\pi\over 2} '+
	'where sin(\theta) = {\sqrt{2}\over 2}.\pause\nl '+
	'From our knowledge of special values we know sin({\pi\over 4}) = {\sqrt{2}\over 2}.\pause\nl '+
	'Thus '+functn+' = '+answer+'.';
  end;
  5:
  begin
    functn:=makeformula('arcsin([1]/[2]',[],v);
    answer:='{\pi\over 6}';
    x.a:=pi/6;
    solution:=#127'600,600,1200,10;A,300,300,100;B,2;G,arcsin(x),-1,1;'+
    	'L,0,\a:2,.5,\a:2;L,.5,\a:2,.5,0;B,4;C,-.6,.55,{\pi\over 6};'+
	'C,.33,-.3,{1\over 2};C,.2,2,y=arcsin(x);'#127+
	nl+#140'Solution:'#140+nl+
	'The range of the function f(x) = arcsin(x) is [{-\pi\over 2},{\pi\over 2}].\pause\nl '+
	'Now '+functn+' is the angle \theta  between -{\pi\over 2} and {\pi\over 2} '+
	'where sin(\theta) = {1\over 2}.\pause\nl '+
	'From our knowledge of special values we know sin({\pi\over 6}) = {1\over 2}.\pause\nl '+
	'Thus '+functn+' = '+answer+'.';
  end;
  6:
  begin
    functn:='arcsin(-1)';
    answer:='-~/2';
    solution:=#127'600,600,1200,10;A,300,300,100;B,2;G,arcsin(x),-1,1;'+
    	'L,-1,0,-1,-1.57;L,-1,-1.57,0,-1.57;B,4;C,-1.2,.2,-1;C,.2,-1.5,{-\pi\over 2};'+
	'C,.33,-.3,{1\over 2};C,.2,2,y=arcsin(x);'#127+
	nl+#140'Solution:'#140+nl+
	'The range of the function f(x) = arcsin(x) is [{-\pi\over 2},{\pi\over 2}].\pause\nl '+
	'Now '+functn+' is the angle \theta  between -{\pi\over 2} and {\pi\over 2} '+
	'where sin(\theta) = -1.\pause\nl '+
	'From our knowledge of special values we know sin({\pi\over 2}) = 1.\pause\nl '+
	'Since the sine function is odd, we have sin(-1) = {-\pi\over 2}.\pause\nl '+
	'Thus '+functn+' = '+answer+'.';
  end;
end;{case}
  text1:='Find the exact value of '+functn+'in radians. Neither '+
    'a decimal approximation from the calculator nor an answer involving an '+
    'inverse trig function will be accepted.'+nl;
  text3:='To find '+functn+' use your knowledge about the special values of the trig functions. '+
    'You also need to know the range of the inverse trig functions. Also '+
    'remember to express your answer in radians.';
  prompt:=#133+functn+' = '#134;
  text3::=text1+'\nl\blue{Hint:}\nl '+text3;
  answer::=answer;
  solution::=solution;
  help::='\red{Inverse Trig Functions:}\nl '+
   	'\ \ sin(x) = y <=> arcsin(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl '+
	'\ \ cos(x) = y <=> arccos(y) = x if $$0<\theta<\pi$$.\nl '+
  	'\ \ tan(x) = y <=> arctan(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl\nl '+
	#127'500,500,100,10;A,250,250,100;B,2;G,arcsin(x),-1,1;B,4;'+
	'C,.2,1.7,y=arcsin(x);B,0;D,-1,-1.57,0,-1.57,4;C,.2,-1.57,-{\pi\over 2};'+
	'D,0,1.57,1,1.57,3;C,-.8,1.6,{\pi\over 2};'#127+
	#127'500,500,700,10;A,250,100,100;B,2;G,arccos(x),-1,1;B,4;'+
	'C,.2,3.5,y=arccos(x);B,0;D,-1,3.14,0,3.14,3;C,.2,3,\pi;'#127+
	nl+nl+nl+nl+nl+nl+nl+nl+nl+nl+nl+
	#127'500,500,700,10;A,250,250,50;B,2;G,arctan(x),-5,5;'+
	'B,0;D,-5,1.57,5,1.57,20;D,-5,-1.57,5,-1.57,20;C,-4,2.2,y={\pi\over 2};'+
	'C,3,-1.1,y=-{\pi\over 2};'+
	'B,4;C,.2,2.2,y=arctan(x);'#127+
	nl+nl+nl+nl+nl+nl+nl+nl+nl+nl+nl+
	#127'500,500,100,10;I,100,200,50;B,4;C,1.1,.4,60^{\circ};B,0;L,0,0,4,0;L,0,0,4,2;L,4,0,4,2;'+
	'B,2;C,2,-.5,\sqrt{3};C,4.1,.8,1;,C,2,1.4,2;'#127+
	#127'500,500,700,10;I,100,200,50;L,0,0,3,0;L,3,0,3,3;L,0,0,3,3;'+
	'B,2;C,1.4,-.5,1;C,3.1,1.4,1;C,.5,1.7,\sqrt{2};B,4;C,.8,.5,45^{\circ};'#127'\nl';
  type:='R';
  key := 4184;
end;

procedure s4184;
var
check1,check2,check3:boolean;
begin
  replace(prompt,'',response);
  check1:=true;
  check2:=true;
  check3:=true;
  if (pos('.',response)>-1) then check1:=false;
    if (pos('sin',response)>-1) then check2:=false else
      if (pos('cos',response)>-1) then check2:=false else
        if (pos('tan',response)>-1) then check2:=false else
          if (pos('cot',response)>-1) then check2:=false else
            if (pos('sec',response)>-1) then check2:=false else
              if (pos('csc',response)>-1) then check2:=false;
  if (pos('`',response)>-1) then check3:=false;
  if sameconstants(answer,response) then begin
    if check1 and check2 and check3 then begin
      result := 'T';
      message:=#141'Correct'#141;
    end else begin
      if not check1 then begin
        result:='F';
        message := #140'Incorrect.'#140' Your answer contains decimal. ';
      end;
      if not check2 then begin
        result:='F';
        message := #140'Incorrect.'#140' Your answer contains a trig or '+
          'inverse trig function.';
      end;
      if not check3 then begin
        result:='F';
        message := #140'Incorrect.'#140' Your answer contains degrees.';
      end;
    end;
  end else begin
    result:='F';
    if response = '' then message:=#140'Incorrect.'#140+nl+text3
    else message:=response+' is '#140'incorrect'#140'. '+text3;
  end;
end;

procedure p4187;	{old 1362}
var
  j,k: integer;
  funct,mes,sgn,rsgn:string;
  v:valuetype;
begin
  k:=randint(1,4);
  j:=randint(1,2);
  if j=1 then begin
    sgn:='';
    rsgn:='-';
  end;
  if j=2 then begin
    sgn:='-';
    rsgn:='';
  end;
  if k=1 then begin
    funct:=makeformula('cos(arctan('+sgn+'[1]/[{3}]))',[],v);
    if j=1 then
      mes:='Use the definition of the inverse trig functions.'
    else
      mes:='Use the facts that the arctan function is odd and the cosine '+
           'function is even. Also use the definition of the inverse trig '+
           'functions.';
    answer:=makeformula('[{3}]/[2]',[],v);
    if j=1 then solution:='' else
    solution:='Since the arctangent function is odd and the cosine '+
              'function is even, we have '+nl+
             funct+nl+
             ' = '+makeformula('cos(-arctan([1]/[{3}]))',[],v)+#10+nl+
             ' = '+makeformula('cos(arctan([1]/[{3}])).',[],v)+#10+nl;
    solution:=solution+
             'Since '+makeformula('arctan([1]/[{3}]',[],v)+' = '#29#219'~'#221'/'#219'6'#221+', we have'+nl+
             funct+nl+
             ' = cos(~/6)'+#10+nl+
             ' = '+answer+'.';
  end;
  if k=2 then begin
    funct:=makeformula('tan(arcsin('+sgn+'[1]/[2]))',[],v);
    if j=1 then
      mes:='Use the definition of the inverse trig functions.'
    else
      mes:='Use the fact that both the arcsin and tangent functions are '+
           'odd. Also use the definition of the inverse trig functions.';
    answer:=sgn+makeformula('[1]/[{3}]',[],v);
    if j=1 then solution:='' else
    solution:='Since the arctangent function is odd and the cosine '+
              'function is even, we have '+nl+
             funct+nl+
             ' = '+makeformula('tan(-arcsin([1]/[2]))',[],v)+#10+nl+
             ' = '+makeformula('-tan(arcsin([1]/[2])).',[],v)+#10+nl;
    solution:=solution+
             'Since '+makeformula('arcsin([1]/[2]',[],v)+' = '#29#219'~'#221'/'#219'6'#221+', we have'+nl+
             funct+nl+
             ' = '+sgn+'tan(~/6)'+#10+nl+
             ' = '+answer+'.';
  end;
  if k=3 then begin
    funct:=makeformula('tan(arcsin('+sgn+'[{3}]/[2]))',[],v);
    if j=1 then
      mes:='Use the definition of the inverse trig functions.'
    else
      mes:='Use the fact that both the arcsin and tangent functions are '+
           'odd. Also use the definition of the inverse trig functions.';
    answer:=sgn+makeformula('{3}',[],v);
    if j=1 then solution:='' else
    solution:='Since the arctangent function is odd and the cosine '+
              'function is even, we have '+nl+
             funct+nl+
             ' = '+makeformula('tan(-arcsin([{3}]/[2]))',[],v)+#10+nl+
             ' = '+makeformula('-tan(arcsin([{3}]/[2])).',[],v)+#10+nl;
    solution:=solution+
             'Since '+makeformula('arcsin([{3}]/[2]',[],v)+' = '#29#219'~'#221'/'#219'3'#221+', we have'+nl+
             funct+nl+
             ' = '+sgn+'tan(~/3)'+#10+nl+
             ' = '+answer+'.';
  end;
  if k=4 then begin
    funct:=makeformula('cos(arcsin('+sgn+'[1]/[2]))',[],v);
    if j=1 then
      mes:='Use the definition of the inverse trig functions.'
    else
      mes:='Use the fact that both the arcsine function is odd and '+
           'the cosine function is even. Also use the definition of '+
           'the inverse trig functions.';
    answer:=+makeformula('[{3}]/[2]',[],v);
    if j=1 then solution:='' else
    solution:='Since the arcsine function is odd and the cosine '+
              'function is even, we have '+nl+
             funct+nl+
             ' = '+makeformula('cos(-arcsin([1]/[2]))',[],v)+#10+nl+
             ' = '+makeformula('cos(arcsin([1]/[2])).',[],v)+#10+nl;
    solution:=solution+
             'Since '+makeformula('arcsin([1]/[2]',[],v)+' = '#29#219'~'#221'/'#219'6'#221+', we have'+nl+
             funct+nl+
             ' = cos(~/6)'+#10+nl+
             ' = '+answer+'.';
  end;
      text1:='Find the exact value of '+funct+'. '+
    'Neither a decimal approximation from the calculator nor an answer '+
    'involving a trig or inverse trig function will be accepted.'+nl;
  text3::=text1+'\nl\blue{Hint:}\nl '+funct+'. '+mes;
  prompt:=#133+funct+' = '#134;
  solution::='\nl\red{Solution:}\nl '+solution;
  help::='\red{Inverse Trig Functions:}\nl '+
   	'\ \ sin(x) = y <=> arcsin(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl '+
	'\ \ cos(x) = y <=> arccos(y) = x if $$0<\theta<\pi$$.\nl '+
  	'\ \ tan(x) = y <=> arctan(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl\nl '+
	'\red{30^{\circ}-60^{\circ}-90^{\circ} Triangle:}\nl '+
	#127'500,300,700,10;I,100,200,50;B,4;C,1.1,.4,60^{\circ};B,0;L,0,0,4,0;L,0,0,4,2;L,4,0,4,2;'+
	'B,2;C,2,-.5,\sqrt{3};C,4.1,.8,1;,C,2,1.4,2;'#127+nl+nl+nl+nl+nl+nl+nl+nl+nl+
	'\red{45^{\circ}-45^{\circ}-90^{\circ} Triangle:}\nl '+
	#127'500,300,700,10;I,100,100,50;L,0,0,3,0;L,3,0,3,3;L,0,0,3,3;'+
	'B,2;C,1.4,-.5,1;C,3.1,1.4,1;C,.5,1.7,\sqrt{2};B,4;C,.8,.5,45^{\circ};'#127'\nl';
  type:='R';
  key:=4187;
end;

procedure s4187;
var
  x,y:real;
  undef,notwff:boolean;
begin
    replace(prompt,'',response);
    x := evaluate(answer,'',undef,notwff);
    y := evaluate(response,'',undef,notwff);
    if undef or notwff or (abs(x-y) > 0.00000000001) then begin
      result := 'F';
      if response = '' then message:=#140'Incorrect'#140+nl+text3
      else message:=response+' is '#140'incorrect'#140'.'+nl+text3;
    end else
      if pos('arc',response)>0 then result:='F' else
        if pos('sin',response)>0 then result:='F' else
          if pos('cos',response)>0 then result:='F' else
            if pos('tan',response)>0 then result:='F' else
              if pos('cot',response)>0 then result:='F' else
                if pos('sec',response)>0 then result:='F' else
                  if pos('csc',response)>0 then result:='F' else
  if sameconstants(answer,response) then begin
     result := 'T';
     message:=#141'Correct'#141;
  end else begin
     result:='F';
     if response = '' then message:=#140'Incorrect'#140+nl+text3
     else message:=response+' is '#140'incorrect'#140'.'+nl+text3;
  end;
end;

procedure p4189;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,dgm2,text:string;
begin
  x.a:=rand([4..7]);
  x.b:=rand([12..18]);
  dgm::=#127'500,500,1200,10;I,100,150,50;L,0,0,4,0;L,0,0,4,6;L,4,0,4,6;'+
  	'L,0,0,4,1.8;B,2;C,1.8,-.5,\a;C,4.2,.8,x;C,4.2,4,\b;B,4;'+
	'C,.9,.8,\theta;'#127;
  dgm2::=#127'500,500,1200,10;I,100,100,50;L,0,0,4,0;L,0,0,4,6;'+
  	'L,4,0,4,6;L,0,0,4,1.8;B,2;C,1.8,-.5,\a;C,4.2,.8,x;C,4.2,4,\b;B,4;'+
	'C,.9,.8,\theta;B,2;C,1.3,.2,\alpha;P,1.8,0,.47;P,2.2,0,1;'+
	'C,2.1,1.26,\beta;B,4;C,-.5,-.5,O;C,4.2,-.5,A;C,4.2,6.2,C;'+
	'C,4.2,1.8,B;'#127;
  text:='The angle \theta  is shown in the following diagram. Use '+
  	'inverse trig functions to express \theta  in terms of x.\nl ';
  text1::=dgm+text+nl+nl+nl+nl;
  prompt::=#133'\theta(x) = '#134;
  help::='\red{Inverse Trig Functions:}\nl '+
   	'\ \ sin(x) = y <=> arcsin(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl '+
	'\ \ cos(x) = y <=> arccos(y) = x if $$0<\theta<\pi$$.\nl '+
  	'\ \ tan(x) = y <=> arctan(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl\nl '+
  	#127'500,500,800,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'C,2,-.5,x;C,4.2,3,y;C,.8,.25,\theta;C,1.2,3,r;'#127+
	'\red{Definitions of Trig Frunctions:}\nl '+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$';
  text3::=text+'\nl\blue{Hint:}\nl '+
  	'Write \theta  as the difference of two angles and use inverse trig '+
	'functions to express these angles in terms of x.';
  ans:='arctan({x+\b\over \a})-arctan({x\over \a})';
  answer::=ans;
  solution::=dgm2+'\nl\red{Solution:}\nl '+
  	'We have \theta  = \beta - \alpha.\pause\nl '+
	'From \dif OAB we have $$tan(\alpha)={x\over \a}$$ => '+
	'$$\alpha=arctan({x\over \a})$$.\pause\nl '+
	'From \dif OAC we have $$tan(\beta)={x+\b\over \a}$$ => '+
	'$$\beta=arctan({x+\b\over \a})$$.\pause\nl '+
	'Thus $$\theta=\beta-\alpha=arctan({x+\b\over \a})-arctan({x\over \a})$$.';
  type:='R';
  key:=4189;
end;

procedure s4189;             
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4190;	{old 1276}
var
  a,b,c,d,e,f,j,k,l,m,n:integer;
  p,q,r,s,t:real;
  v:valuetype;
  ans1,ans2,funct,drctn,box,box2,text,u,w,z:string;
  undef,notwff:boolean;
begin
  a:=randint(3,4);v.a:=a;
  b:=randint(5,6);v.b:=b;v.e:=v.a*v.a+v.b*v.b;
  c:=randint(7,10);v.c:=c;
  box:=#127'560,560,1200,10;I,140,140,70;B,2;C,3.7,3.8,'#244';B,0;L,0,0,3,0;L,0,0,0,2;L,0,2,3,2;'+
        'L,3,2,3,0;D,0,0,2,3.46,4;D,2,3.46,2,5.46,4;L,3,0,5,3.46;'+
        'D,2,3.46,5,3.46,4;L,0,2,2,5.46;L,2,5.46,5,5.46;L,3,2,5,5.46;'+
        'L,5,3.46,5,5.46;L,0,0,5,5.46;B,2;C,-.5,1,'+st(a)+';C,1.3,-.6,'+st(b)+';'+
        'C,.4,3.8,'+st(c)+';';
  box2:=box+'L,0,0,3,2;B,4;C,-.5,-.6,A;C,3.2,1.8,B;C,5.1,5.46,C;'+
        'C,3.1,-.6,D;';
  text:='If a rectangular box has edges of lengths '+st(a)+','+st(b)+
  	', and '+st(c)+' inches, determine the angle '+#244+' between '+
         'a diagonal of the box and one of the longest edges. Express '+
         'your answer in degrees.'+nl;
  text1::=box+#127+text+nl+nl+nl+nl+nl+nl;
  text3::=box2+#127+text+#13+'\nl\blue{Hint:}\nl '+
  	'Compute the length of the diagonal AB. Then '+nl+
         'tan'#244' = '+#29#219'AB'#221'/'#219'BC'#221+'.';
  str(arctan(sqrt(a*a+b*b)/c)*180/pi:8:6,answer);
  str(arctan(sqrt(a*a+b*b)/c):8:6,z);
  answer:=answer +' degrees';
  text6:=z;
  replace('700,20','700,100',box);
  prompt:=#133#244' = '#134;
  solution::=box2+#127+nl+'\nl\red{Solution:}\nl '+
  	'By the Pythagorean theorem AB = '+makeformula('{a^2+b^2}={e}.',['a','b','e'],v)+#10+nl+
        'Thus tan'#244' = {AB\over BC} = '#29#219'@'#251+st(v.e)+#253#221'/'#219+st(c)+#221+#10+nl+
        ' => '#244' = arctan('#29#219'@'#251+st(v.e)+#253#221'/'#219+st(c)+#221+')'#10+nl+
        '      '#163' '+z+' radians'+#10+nl+
        '      '#163' '+z+'\cdot'+#29#219'180'#221'/'#219'~'#221+' degrees'#10+nl+
        '      '#163' '+answer+'.';
  help::='\red{Definitions of Trig Frunctions:}\nl '+
  	#127'500,500,800,10;I,150,100,50;L,0,0,4,0;L,4,0,4,6;L,0,0,4,6;'+
  	'C,2,-.5,x;C,4.2,3,y;C,.8,.25,\theta;C,1.2,3,r;'#127+
 	'sin(\theta) = {y\over r}\ \ \ cos(\theta) = {x\over r}\nl '+
	'tan(\theta) = {y\over x}\ \ \ cot(\theta) = {x\over y}\nl '+
	'sec(\theta) = {r\over x}\ \ \ csc(\theta) = {r\over y}\nl '+
	'$$r=\sqrt{x^2+y^2}$$\nl\nl\nl\nl '+
	'\red{Inverse Trig Functions:}\nl '+
   	'\ \ sin(x) = y <=> arcsin(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl '+
	'\ \ cos(x) = y <=> arccos(y) = x if $$0<\theta<\pi$$.\nl '+
  	'\ \ tan(x) = y <=> arctan(y) = x if $$-{\pi\over 2}<\theta<{\pi\over 2}$$.\nl\nl '+
	'\red{Radians and Degrees:}\nl '+
  	'360^{\circ} = 2\pi  radians\nl\nl ';
  type:='R';
  key := 4190;
end;

procedure s4190;
begin
  replace(prompt,'',response);
  if text6 = '' then
    if sameconstants(answer,response) then begin
       result := 'T';
       message:=#141'Correct'#141;
       end
    else begin
      result:='F';
      if response = '' then message:=#140'Incorrect'#140+nl+text3
      else
      message:=response+' is '#140'incorrect'#140'. '+text3;
    end
  else
    if (pos('`',response)>-1) and (pos('arc',response)=-1) then
      if sameconstants(text6,response) then begin
        result:='T';
        message:=#141'Correct'#141;
        end
      else begin
        result:='F';
        if response = '' then message:=#140'Incorrect'#140+nl+text3
        else
        message:=response+' is '#140'incorrect'#140'. '+text3;
      end
  else
    if sameconstants(answer,response) then begin
     result:='T';
     message:=#141'Correct'#141;
     end
  else begin
    result:='F';
    if response = '' then message:=#140'Incorrect'#140+nl+text3
    else
    message:=response+' is '#140'incorrect'#140'. '+text3;
  end;
end;

procedure p4191;
var
  a,b,n:integer;
  ans,nrad:real;
  v:valuetype;
  x:paramtype;
begin
  case randint(1,3) of
  1:begin
    b:=randint(10,80);x.b:=b;
    a:=b+randint(1,10);x.a:=a;
    n:=randint(5,75);x.n:=n;
    x.t:=cos(n*pi/180);
    x.z:=sqrt(x.a^2+x.b^2-2*x.a*x.b*x.t);
    text1 :=#127'400,300,1200,10;I,50,50,50;L,0,0,6,0;L,6,0,4,4;L,4,4,0,0;'+
         'B,4;C,-.4,-.6,B;C,6.2,-.6,C;C,4,4.2,A;B,2;C,1,.5,'+st(n)+#30'`'#31';'+
         'C,1.3,2.3,'+st(a)+';C,3,-.8,'+st(b)+';'#127+
         'Let ABC be a triangle with BA = '+st(a)+', BC = '+st(b)+
         ', and angle B = '+st(n)+#30'`'#31+'. Find AC.'+nl+nl+nl+nl+nl+nl;
    solution:='By the law of cosines\nl '+
      	 '$$AC^2=AB^2+BC^2-2\cdot AB\cdot BC\cdot cos(\n^{\circ})$$\pause\nl '+
	 '=> $$AC=\sqrt{AB^2+BC^2-2AB\cdot BC\cdot cos(\n^{\circ})}$$\pause\nl '+
	 '$$\doteq\sqrt{\a^2+\b^2-2\cdot\a\cdot\b\cdot\t:6}$$\pause\nl '+
	 '$$\doteq\z:6$$.';
    prompt:=#133'AC = '#134;
    end;
  2:begin
    x.a:=rand([20..50]);
    x.b:=x.a+rand([5..15]);
    x.n:=10*(rand([12..15])+rand([1..9])/10);
    x.t:=cos(x.n*pi/180);
    x.z:=sqrt(x.a^2+x.b^2-2*x.a*x.b*x.t);
    text1::=#127'500,500,1200,10;I,250,250,50;C,0,.5,\n^{\circ};L,0,0,4,0;'+
    	'L,0,0,-4,3;L,4,0,-4,3;B,4;C,-.5,-.5,A;C,4.2,-.5,B;C,-4.3,3.2,C;'+
	'B,2;C,1.8,-.5,\a;C,-2.8,1,\b;B,0;'#127+
	'Let ABC be a triangle with AB = \a, AC = \b  and angle BAC = '+
	'\n^{\circ}. Determine BC.\nl\nl\nl\nl\nl ';
    solution:='By the law of cosines\nl '+
      	'$$BC^2=AB^2+AC^2-2\cdot AB\cdot AC\cdot cos(\n^{\circ})$$\pause\nl '+
	'=> $$BC=\sqrt{AB^2+AC^2-2AB\cdot AC\cdot cos(\n^{\circ})}$$\pause\nl '+
	'$$\doteq\sqrt{\a^2+\b^2-2\cdot\a\cdot\b\cdot(\t:6)}$$\pause\nl '+
	'$$\doteq\z:6$$.';
    prompt:=#133'BC = '#134;
  end;
  3:begin
    x.a:=rand([20..50]);
    x.b:=x.a+rand([15..35]);
    x.n:=rand([15..35]);
    x.t:=cos(x.n*pi/180);
    x.z:=sqrt(x.a^2+x.b^2-2*x.a*x.b*x.t);
    text1::=#127'500,500,1200,10;I,250,250,50;C,1.3,.4,\n^{\circ};L,0,0,4,0;'+
    	'L,0,0,-4,3;L,4,0,-4,3;B,4;C,-.5,-.5,A;C,4.2,-.5,B;C,-4.3,3.2,C;'+
	'B,2;C,1.8,-.5,\a;C,0,2,\b;B,0;'#127+
	'Let ABC be a triangle with AB = \a, BC = \b  and angle ABC = '+
	'\n^{\circ}. Determine AC.\nl\nl\nl\nl\nl ';
    solution:='By the law of cosines\nl '+
      	'$$AC^2=AB^2+BC^2-2\cdot AB\cdot BC\cdot cos(\n^{\circ})$$\pause\nl '+
	'=> $$AC=\sqrt{AB^2+BC^2-2\cdot AB\cdot BC\cdot cos(\n^{\circ})}$$\pause\nl '+
	'$$\doteq\sqrt{\a^2+\b^2+2\cdot\a\cdot\b\cdot\t:6}$$\pause\nl '+
	'$$\doteq\z:6$$.';
    prompt:=#133'AC = '#134;
    end;
  end;
  answer::='\z:6';
  text3::=text1+'\nl\blue{Hint:}\nl '+
  	'Use the law of cosines.';
  replace(#13#13#13#13#13,'',text3);
  solution::='\nl\red{Solution:}\nl '+solution;
  help::='\red{Law of Cosines:}\nl '+
	'$$BC^2=AB^2+AC^2-2\cdot AB\cdot AC\cdot cos(\theta)$$'+#13+
        #127'400,300,700,10;I,50,50,50;L,0,0,6,0;L,6,0,4,4;L,4,4,0,0;'+
        'B,4;C,-.4,-.6,A;C,6.2,-.6,B;C,4,4.2,C;B,2;C,1,.3,\theta;'#127+
	nl+nl+nl+nl+nl+nl+nl+nl+nl+
	#127'400,300,700,10;I,50,50,50;L,0,0,6,0;L,6,0,4,4;L,4,4,0,0;'+
        'B,4;C,-.4,-.6,A;C,6.2,-.6,B;C,4,4.2,C;B,2;C,1,.3,\alpha;'+
	'C,5,.3,\beta;C,3.8,3,\gamma;'#127+
	'\red{Law of Sines:}\nl '+
	'$${sin(\alpha)\over BC}={sin(\beta)\over AC}={sin(\gamma)\over AB}$$';
  key :=4191;
  type := 'R';
end;

procedure s4191;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4192;
var
  a,b,c,d,e,k:integer;
  p,r:real;
  v:valuetype;
  x:paramtype;
  ans1,ans2,dgm,gr,theta:string;
begin
  a:=rand([45,50,55,57]);x.a:=a;
  b:=a+rand([5,8,9,10]);;x.b:=b;
  c:=rand([18,19,21,23,28]);x.c:=c;
  d:=rand([25,35,50,62]);x.d:=d;
  dgm:=#127'500,500,1200,10;I,250,250,50;B,2;C,-.4,.4,\theta;B,0;'+
    	'L,0,0,4,0;L,0,0,-4,3;G,0,D4,4;G,3,D-4,-4;D,4,0,-4,3,16;D,0,0,0,4,10;'+
	'B,2;C,.5,1.5,D;B,0;P,1,1.57,2.5;B,4;C,.2,3,\theta=\d^{\circ};';
  text1::=dgm+#127+
    'A car and truck leave an intersection at time '+nl+'t = 0. '+
    'The car travels east at '+st(a)+' mph while the truck travels N'+st(d)+
    #30'`'#31'W at '+st(b)+' mph. Find the distance D in miles between the '+
    'car and the truck '+st(c)+' minutes after they leave the intersection.'+
     nl;
  text3:='Compute the distances traveled by the car and truck in \c  '+
    	'minutes. Then apply the law of cosines.';	
  str(c*sqrt(a*a+b*b-2*a*b*cos((90+d)*pi/180))/60:8:2,ans1);
  answer:=ans1;
  x.p:=x.a*x.c/60;
  x.q:=x.b*x.c/60;
  x.e:=90+x.d;
  x.f:=x.p^2+x.q^2-2*x.p*x.q*cos(x.e*pi/180);
  solution::=dgm+'B,0;C,1,-.5,\p:2;C,-4,1,\q:2;B,4;C,-.5,-.5,A;'+
    	'C,4.2,-.5,B;C,-4.2,3.3,C;'#127+
	nl+#140'Solution:'#140+nl+
    	'In \c  minutes the car has traveled {\a\cdot\c\over60} '+
    	'\doteq  \p:2  miles while the truck has traveled y = {\b\cdot\c\over60} '+
	'\doteq  \q:2  miles.\pause\nl '+
	'In triangle ABC, the angle opposite D is\nl 90^{\circ} + \d^{\circ} = '+
	'\e^{\circ}.\pause\nl '+
	'Thus by the law of cosines we have\nl '+
	'$$D^2=(\p:2)^2+(\q:2)^2-2\cdot(\p:2)\cdot(\q:2)\cdot cos(\e^{\circ})\doteq\f:2$$\nl '+
	'=> $$D=\sqrt{\f:2}\doteq'+ans1+'$$ miles.';
  prompt:=#133'D = '#134;
  text3::=text1+'\nl\blue{Hint:}\nl '+text3;
  help::='Distance = velocity\cdot time\nl\nl '+
        '\red{Law of Cosines:}\nl '+
	'$$BC^2=AB^2+AC^2-2\cdot AB\cdot AC\cdot cos(\theta)$$'+#13+
        #127'400,300,700,10;I,50,50,50;L,0,0,6,0;L,6,0,4,4;L,4,4,0,0;'+
        'B,4;C,-.4,-.6,A;C,6.2,-.6,B;C,4,4.2,C;B,2;C,1,.3,\theta;'#127+
	nl+nl+nl+nl+nl+nl+nl+nl+nl+
	#127'400,300,700,10;I,50,50,50;L,0,0,6,0;L,6,0,4,4;L,4,4,0,0;'+
        'B,4;C,-.4,-.6,A;C,6.2,-.6,B;C,4,4.2,C;B,2;C,1,.3,\alpha;'+
	'C,5,.3,\beta;C,3.8,3,\gamma;'#127+
	'\red{Law of Sines:}\nl '+
	'$${sin(\alpha)\over BC}={sin(\beta)\over AC}={sin(\gamma)\over AB}$$';
  type:='R';
  key := 4192;
end;

procedure s4192;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4194;
var
  a,b,c,d,e,f,j,k,l,m,n:integer;
  p,q,r,s,t:real;
  v:valuetype;
  x:paramtype;
  ans,a1,a2,dgm,header,text,part1,part2:string;
begin
  a:=rand([4,6,8,9]);v.a:=a;x.a:=a;
  b:=rand([2,3,4]);x.b:=b;
  f:=a+b;v.f:=f;x.f:=f;
  d:=rand([20,25,32,35,42]);x.d:=d;
  dgm:=#127'500,500,1200,10;I,100,250,50;L,0,0,4,0;L,4,0,6,3;L,0,0,2,3;'+
       'L,2,3,6,3;D,0,0,6,3,15;B,2;C,.3,1.5,'+st(f)+';C,2,-.6,'+st(a)+';'+
       'C,2.7,1.6,L;P,1,0,1;B,0;B,0;C,1.1,.4,'+st(d)+'^{\circ};'+
       'B,4;C,-.5,-.5,A;C,4.2,-.5,B;C,6.2,3.2,C;C,1.7,3.2,D;';
  header:='\red{Answer both parts before grading.}';
  text:='Two adjacent sides of a parallelogram are '+st(a)+
       ' and '+st(f)+' respectively. The angle DAB between these '+
       'sides is '+st(d)+#30+'`'#31'.';
  part1:='\red{a: } Determine angle ABC in degrees. (40%)';
  part2:='\red{b: } Determine the length L of the longer diagonal of the '+
  	'parallelogram. (60%)';
  text1::=dgm+#127+header+#13+#13+text+#13+part1+#13+part2+#13;
  dgm:=dgm+'B,0;D,4,0,6,0,4;C,4.5,.2,\theta;';
  buff1:=text+#13+part1+#13+part2+nl;
  prompt::=#133'a: angle ABC (in degrees):'#134#13+
    	   #133'b: L = '#134;
  text3::=dgm+#127+buff1+'\nl\blue{Hint:}\nl '+
	  'Use the fact that angle DAB = \theta  to determine angle ABC. Then '+
	  'use the law of cosines.';
  x.e:=180-x.d;
  str(x.e,buff2);
  x.g:=cos(x.e*pi/180);
  str(sqrt(a*a+f*f-2*a*f*cos((180-d)*pi/180)):8:6,a2);
  ans:=#134'\e^{\circ}'#133+
       #134+a2;
  answer::=ans;
  separate(answer,a1,a2);
  solution::=dgm+'B,0;C,2.5,.9,'+st(180-d)+'^{\circ};I,300,250,50;P,.5,1,3.14;'#127+
  	'\nl\red{Solution to part a:}\nl '+
	'Note that angle $$ABC=180^{\circ}-\theta=180^{\circ}-\d^{\circ}='+
	a1+'$$.\pause\nl ';
  solution2::='\nl\red{Solution to part b:}\nl '+
  	'By the law of cosines applied to \dif ABC we have\nl '+
	'$$L=\sqrt{AB^2+BC^2-2\cdot AB\cdot BC\cdot cos(\e^{\circ})}$$\pause\nl '+
	'$$\doteq\sqrt{\a^2+\f^2-2\cdot\a\cdot\f\cdot(\g:4)}$$\pause\nl '+
	'$$\doteq'+a2+'$$.';
help::='Adjacent angles of a parallelogram are supplementary -i.e. their '+
      '\alpha  + \beta  = 180^{\circ}.\nl '+
      #127'500,300,100,10;I,100,50,50;L,0,0,4,0;L,4,0,6,3;L,0,0,2,3;'+
      'L,2,3,6,3;P,1,0,1;B,2;C,.4,.2,\alpha;C,3.5,.2,\beta;'+
      'B,4;C,-.5,-.5,A;C,4.2,-.5,B;C,6.2,3.2,C;C,1.7,3.2,D;I,300,50,50;'+
      'B,0;P,.8,1,3.14;'#127+
      nl+nl+nl+nl+nl+nl+nl+nl+nl+
      '\red{Law of Cosines:}\nl '+
      '$$BC^2=AB^2+AC^2-2\cdot AB\cdot AC\cdot cos(\theta)$$'+#13+
      #127'400,300,100,10;I,50,50,50;L,0,0,6,0;L,6,0,4,4;L,4,4,0,0;'+
      'B,4;C,-.4,-.6,A;C,6.2,-.6,B;C,4,4.2,C;B,2;C,1,.3,\theta;'#127;
type:='R';
key := 4194;
end;

procedure s4194;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1) or (sameconstants(buff2,r1) and (pos('`',r1)=-1));
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+4;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+6;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4197;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,dgm2,header,text,part1,part2:string;
begin
  x.a:=rand([8..15]);
  dgm::=#127'500,500,1200,10;I,250,250,50;L,3,0,.93,2.85;'+
  	'L,.93,2.85,-2.43,1.76;L,-2.43,1.76,-2.43,-1.76;'+
	'L,-2.43,-1.76,.93,-2.85;L,.93,-2.85,3,0;B,2;L,3,0,-2.43,1.76;'+
	'B,4;C,3.2,0,A;C,.94,3.14,B;C,-3.06,1.81,C;B,2;C,.56,2.37,\theta;'+
	'B,0;C,-.13,.53,L;B,0;C,2.13,1.64,\a;'#127;
  header:='\red{Answer both parts before grading.}';
  text:='Each side of a regular pentagon is \a.';
  part1:='\red{a: } Determine the angle \theta  in degrees. (40%)';
  part2:='\red{b: } Determine the distance L between two non-adjacent '+
  	'vertices. (60%)';
  text1::=dgm+header+#13+#13+text+#13+part1+#13+part2+#13+#13+#13+#13;
  buff1:=text+#13+part1+#13+part2+nl;
  prompt::=#133'a: \theta(in degrees) = '#134#13+
    	   #133'b: L = '#134;
  help::='';
  dgm2:=#127'500,500,1200,100;I,250,250,50;L,3,0,.93,2.85;'+
  	'L,.93,2.85,-2.43,1.76;L,-2.43,1.76,-2.43,-1.76;'+
	'L,-2.43,-1.76,.93,-2.85;L,.93,-2.85,3,0;L,0,0,3,0;'+
	'L,0,0,.93,2.85;B,2;C,.5,.26,\alpha;C,.83,2.03,\beta;'+
	'C,2.13,.31,\beta;C,.19,2.2,\beta;B,4;C,3.2,0,A;C,.94,3.14,B;'+
	'C,-3.06,1.87,C;C,-.5,-.5,O;B,0;I,296.5,392.5,50;P,1.1,3.5,5.4;I,250,250,50;'+
	'C,-.08,1.48,\theta;C,2.13,1.64,\a;'#127;
  text3::=buff1+'\nl\blue{Hint:}\nl '+
	'Use symmetry to calculate the angles \alpha  and \beta. Note that '+
	'\theta = 2\beta. Then use the law of cosines to calculate L = AC.'+dgm2;
  x.b:=2*x.a^2;
  x.d:=cos(108*pi/180);
  x.e:=x.b-x.b*x.d;
  str(sqrt(x.b-x.b*x.d),a2);
  ans:=#134'108^{\circ}'#133+
       #134+a2;
  answer::=ans;
  separate(ans,a1,a2);
  buff2:='108';
  replace('1200,10','1200,100',dgm);
  solution::='\nl\red{Solution to part a:}\nl '+
 	'By symmetry $$\alpha={360^{\circ}\over 5}=72^{\circ}$$.\pause\nl '+
	'Now using \dif OAB we have\nl '+
	'$$2\beta+\alpha=180^{\circ}$$ => $$\beta=54^{\circ}$$.\pause\nl '+
	'Thus $$\theta=2\beta=108^{\circ}$$.\pause\nl ';
  solution2::=dgm+'\nl\red{Solution to part b:}\nl '+
  	'By the law of cosines we have\nl '+
	'$$L^2=\a^2+\a^2-2(\a)(\a)cos(108^{\circ})$$\pause\nl '+
	'=> $$L\doteq\sqrt{\b-\b\cdot (\d:6)}\doteq\sqrt{\e:4}\doteq'+present(a2)+'$$.';
  help::='The sum of all three angles in a triangle is 180^{\circ}.\nl\nl '+
  	'\red{Law of Cosines:}\nl '+
	'$$BC^2=AB^2+AC^2-2\cdot AB\cdot AC\cdot cos(\theta)$$'+#13+
	#127'400,300,100,10;I,50,50,50;L,0,0,6,0;L,6,0,4,4;L,4,4,0,0;'+
        'B,4;C,-.4,-.6,A;C,6.2,-.6,B;C,4,4.2,C;B,2;C,1,.3,\theta;'#127;
  type:='R';
  key:=4197;
end;	   

procedure s4197;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1) or (sameconstants(buff2,r1) and (pos('`',r1)=-1));
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+4;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+6;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4201;
var
  a,b,c,d,e,f,j,k,l,m,n:integer;
  p,q,r:real;
  s:valuetype;
  x:paramtype;
  ans,a1,a2,dgm,header,text,part1,part2:string;
begin
  a:=rand([22,24,25,26,28]);s.a:=a;x.a:=10*a;
  b:=rand([32..55]);s.b:=b;x.b:=b;
  c:=a+rand([4..8]);s.d:=c;x.c:=10*c;
  dgm::=#127'600,500,1200,10;I,200,100,50;L,-3,-1,7,-1;L,-2,-1,2,2;L,2,2,6,-1;'+
       'L,2,2,2,6;L,-1.25,-.5,2,6;B,2;C,2.2,4,\a;C,-.5,.6,\theta;'+
       'C,-.8,3,\c;C,-1.2,-.6,'+st(b)+'^{\circ};B,4;C,-2,-.4,A;'+
       'C,2.2,2.1,B;C,2,6.2,C;';
  header:='\red{Answer both parts before grading.}';
  text:='A tower \a  ft. tall is on top of a hill whose sides are inclined '+
          'at \b^{\circ}  with the horizontal. A cable \c  feet long goes from '+
          'the top of the tower to the point A on the side of the hill.\nl';
  part1:='\red{a: } Determine angle ABC in degrees. (40%)';
  part2:='\red{b: } Determine the angle \theta  in degrees. (60%)';
  text1::=dgm+#127+header+#13+#13+text+#13+part1+#13+part2+#13;
  buff1:=dgm+#127+text+#13+part1+#13+part2+nl;
  text3::=buff1+'\nl\blue{Hint:}\nl '+
          'Compute the angle ABC and apply the law of sines.';
  replace(nl+nl+nl+nl,'',text3);
  x.p:=90+x.b;
  str(x.p,buff2);
  x.r:=sin(x.p*pi/180);
  x.s:=x.a*x.r/x.c;
  x.t:=arcsin(x.s);
  x.u:=x.t*180/pi;
  str(x.u,buff3);
  ans:=#134'\p^{\circ}'#133+
       #134'\u:6^{\circ}';
  answer::=ans;
  separate(ans,a1,a2);
  solution::=dgm+'B,0;D,-0.6,2,2,2,8;B,4;C,-.9,1.9,D;'#127+
          '\nl\red{Solution to part a:}\nl '+
	  'Drawing a horizontal line BD at the base of the tower, we '+
          'observe that angle ABD = \b^{\circ}.\pause\nl '+
          'Thus angle ABC = \b^{\circ}  + 90^{\circ} = '+a1+'.\pause\nl ';
  solution2::='\nl\red{Solution to part b:}\nl '+
          'By the law of sines we have\nl '+
          '$${sin(\p^{\circ})\over \c}={sin(\theta)\over \a}$$\pause\nl '+
          '=> $$sin(\theta)={\a\cdot sin(\p^{\circ})\over \c}\doteq\s:6$$\pause\nl '+
          '=> $$\theta\doteq arcsin(\s:6)=\t:6$$ radians.\pause\nl '+
          'Multiplying by {180\over \pi} we have '+
          '$$\theta\doteq\t:6\cdot{180\over \pi}='+a2+'$$.';
  prompt::=#133'a: angle ABC(in degrees):'#134#13+
             #133'b: \theta(in degrees) = '#134;
  help::=#127'400,300,900,10;I,50,50,50;L,0,0,6,0;L,6,0,4,4;L,4,4,0,0;'+
        'B,4;C,-.4,-.6,A;C,6.2,-.6,B;C,4,4.2,C;B,2;C,1,.3,\theta;'#127+
	'\red{Law of Cosines:}\nl '+
	'$$BC^2=AB^2+AC^2-2\cdot AB\cdot AC\cdot cos(\theta)$$'+#13+nl+nl+nl+
	#127'400,300,900,10;I,50,50,50;L,0,0,6,0;L,6,0,4,4;L,4,4,0,0;'+
        'B,4;C,-.4,-.6,A;C,6.2,-.6,B;C,4,4.2,C;B,2;C,1,.3,\alpha;'+
	'C,5,.3,\beta;C,3.8,3,\gamma;'#127+
	'\red{Law of Sines:}\nl '+
	'$${sin(\alpha)\over BC}={sin(\beta)\over AC}={sin(\gamma)\over AB}$$';
  type:='R';
  key :=4201;
end;

procedure s4201;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1) or (sameconstants(buff2,r1) and (pos('`',r1)=-1));
  check2:=sameconstants(a2,r2) or (sameconstants(buff3,r2) and (pos('`',r2)=-1));
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+4;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+6;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4203;
var
  a,b,c,d,e,f,j,k,l,m,n:integer;
  p,q,r:real;
  s:valuetype;
  x:paramtype;
  ans,a1,a2,dgm,header,text,part1,part2:string;
begin
  a:=rand([22,24,25,26,28]);s.a:=a;x.a:=10*a;
  b:=rand([35..47]);s.b:=b;x.b:=b;
  c:=rand([28..38]);s.d:=c;x.c:=c;
  dgm::=#127'600,500,1200,10;I,200,100,50;B,2;C,-.25,1.31,\c^{\circ};B,0;L,-3,-1,7,-1;L,-2,-1,2,2;'+
          'L,2,2,6,-1;L,2,2,2,6;L,-1.25,-.5,2,6;B,2;C,2.2,4,\a;'+
          'C,.5,.3,L;C,-1.2,-.56,\b^{\circ};'+
          'B,4;C,-2,-.4,A;C,2.2,2.1,B;C,2,6.2,C;';
  header:='\red{Answer both parts before grading.}';
  text:='A tower \a  ft. tall is on top of a hill whose sides are inclined '+
          'at \b^{\circ}  with the horizontal. The cable makes an angle of '+
          '\c^{\circ} with the hill.';
  part1:='\red{a: } Determine angle ACB in degrees. (40%)';
  part2:='\red{b: } Determine the distance L = AB in feet from the base of the '+
          'tower to the point at which the cable is secured. (60%)';
  text1::=dgm+#127+header+#13+#13+text+#13+part1+#13+part2+#13;
  buff1:=dgm+#127+text+#13+part1+#13+part2+nl;
  text3::=buff1+#13+'\nl\blue{Hint:}\nl '+
          'Compute the angle ABC and use the fact that the sum of the '+
          'angles of a triangle is 180^{\circ}. Then apply the law of sines.';
  replace(nl+nl+nl+nl,'',text3);
  x.p:=90+x.b;
  x.d:=180-x.p-x.c;
  str(x.p,buff2);
  x.r:=sin(x.d*pi/180);
  x.s:=sin(x.c*pi/180);
  x.u:=x.a*x.r/x.s;
  ans:=#134'\d^{\circ}'#133+
       #134'\u:6';
  answer::=ans;
  separate(ans,a1,a2);
  solution::=#12+text+nl+part1+nl+part2+nl;
  solution2::='\nl\red{Solution to part a:}\nl '+
          dgm+'B,0;D,-0.6,2,2,2,8;B,4;C,-.9,1.9,D;I,300,200,50;B,0;P,.7,1.57,3.9;'+
          'I,200,100,50;C,.6,3,\p^{\circ};'#127+
          'Drawing a horizontal line BD at the base of the tower, we '+
          'observe that angle ABD = \b^{\circ}.\pause\nl '+
          'Thus angle ABC = \p^{\circ}.\pause\nl '+
          'Now using the fact that the sum of the angles of a triangle is 180^{\circ}, '+
          'we find\nl angle ACB = 180^{\circ} - \p^{\circ} - \c^{\circ} = \d^{\circ}.\pause\nl ';
  solution3::='\nl\red{Solution to part b:}\nl '+
          'By the law of sines we have\nl '+
          '$${sin(\d^{\circ})\over L}={sin(\c^{\circ})\over \a}$$\pause\nl '+
          '=> $$L={\a\cdot sin(\d^{\circ})\over sin(\c^{\circ})}$$\pause\nl '+
          '$$\doteq{\a\cdot\r:6\over \s:6}\doteq'+a2+'$$ feet.';
  prompt::=#133'a: angle ACB(in degrees):'#134#13+
             #133'b: L(in feet) = '#134;
  help::='\red{Law of Cosines:}\nl '+
          'The sum of the angles of a triangle is 180^{\circ}.\nl '+
          '$$BC^2=AB^2+AC^2-2\cdot AB\cdot AC\cdot cos(\theta)$$'+#13+
          #127'400,300,100,10;I,50,50,50;L,0,0,6,0;L,6,0,4,4;L,4,4,0,0;'+
        'B,4;C,-.4,-.6,A;C,6.2,-.6,B;C,4,4.2,C;B,2;C,1,.3,\theta;'#127+
          nl+nl+nl+nl+nl+nl+nl+#10#12+
          '\red{Law of Sines:}\nl '+
          '$${sin(\alpha)\over BC}={sin(\beta)\over AC}={sin(\gamma)\over AB}$$'+nl+
          #127'400,300,100,10;I,50,50,50;L,0,0,6,0;L,6,0,4,4;L,4,4,0,0;'+
        'B,4;C,-.4,-.6,A;C,6.2,-.6,B;C,4,4.2,C;B,2;C,1,.3,\alpha;'+
          'C,5.6,.3,\beta;C,3.8,3,\gamma;'#127;
  type:='R';
  key :=4203;
end;

procedure s4203;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1) or (sameconstants(buff2,r1) and (pos('`',r1)=-1));
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+4;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+6;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4206;
var
  a,b,c:integer;
  v:valuetype;
  f1:string;
begin
  repeat
    repeat a := randint(-10,10) until a<>0;
    repeat b := randint(-10,10) until ((b<>0) and (b<>a));
    repeat c := randint(-10,10) until ((c<>0) and (c<>a));
    v.d := a - c;
    v.e := b + c;
    v.f := c*a -c*b -c*c;
  until v.f <> 0;
  f1 := makeformula('(x-d)(x-e)=f',['d','e','f'],v);
  text1::= 'Find all real roots of'+nl+'   '+f1+nl+
    'Separate your answers by commas. If there are no real roots, enter '+
    '\red{none}.\nl ';
  answer := st(a)+', '+st(b);
  prompt :=#133'x = '#134;
  help::='\red{Quadratic Formula:}\nl '+
          '\ \ Roots of $$ax^2+bx+c=0$$:\nl '+
          '\ \ $$x={-b\pm\sqrt{b^2-4ac}\over 2a}$$';
  v.g := -v.d-v.e; v.h := v.d*v.e; v.k := v.h-v.f; v.a := a; v.b := b;
  text3 :=text1+#142+nl+'Hint:'#142+nl+ 
    'Multiply, combine terms and factor the resulting quadratic.';
  solution:=nl+#140'Solution:'#140+nl+ 
    f1+#10+nl+makeformula('x^2+gx+h=f',['f','g','h'],v)+#10+nl+
    '=> '+makeformula('x^2+gx+k=0',['g','k'],v)+#10+nl+
    '=> '+makeformula('(x-a)(x-b)=0',['a','b'],v)+'.'#10+nl+
    'Thus x = '+answer+'.';
  key := 4206;
  type := 'R';
end;

procedure s4206;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4208;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,dgm2,header,text,part1,part2:string;
begin
  x.r:=rand([2,5,10,12,14,15,21]);
  x.b:=2*x.r;
  x.e:=x.b^2;
  x.c:=sqrt(x.b^2/2);
  x.d:=x.b^2/2;
  dgm:=#127'500,500,1200,10;I,250,250,50;B,2;R,-3,-3,3,3;B,0;'+
          'E,-4.28,-4.28,4.28,4.28;D,0,0,3,3,6;B,4;C,1.63,1.09,\r;'+
          'C,3.2,-.3,s;'#127;
  dgm2:=#127'500,500,1200,10;I,250,250,50;B,2;R,-3,-3,3,3;B,0;'+
          'E,-4.28,-4.28,4.28,4.28;L,-3,-3,3,3;B,4;C,-1,0,\b;'+
          'C,3.2,-.3,s;C,0,-3.5,s;C,-3.56,-3.41,A;C,3.25,-3.41,B;C,3.25,3.26,C;'#127;
  header:='\red{Answer both parts before grading.}';
  text:='A square is inscribed in a circle of radius \r.';
  part1:='\red{a: } Determine the edge length s of the square. (60%)';
  part2:='\red{b: } Determine tha area of the square. (40%)';
  text1::=dgm+header+#13+#13+text+#13+part1+#13+part2+#13+nl+nl+nl+nl;
  buff1:=text+#13+part1+#13+part2+nl;
  prompt::=#133'a: s = '#134#13+
             #133'b: A = '#134;
  help::=#127'400,500,500,0;I,200,300,50;L,0,0,0,4;L,0,4,2,0;L,0,0,2,0;'+
          'C,-.5,1.8,a;C,.8,-.6,b;C,1.4,1.8,c;'#127+
          '\red{Pythagorean Theorem:}\nl '+
          '$$a^2+b^2=c^2$$'+nl+nl+
          #127'400,400,700,0;I,100,200,40;E,0,0,4,4;L,2,2,4,2;C,2.8,2.2,r;'#127+
          '\red{Formulas for Circles:}\nl '+ 
          'Area = \pi r^2\nl '+
          'Circumference = 2\pi r'+nl+nl+
          #127'400,400,700,0;I,100,200,40;R,0,0,4,4;C,-.5,1.8,x;C,1.9,-.5,x;'#127+
          '\red{Area of a Square:}\nl '+ 
          'x^2\nl '+
          '\red{Perimeter of a Square:}\nl '+ 
          '4x';
  text3::=dgm2+buff1+'\nl\blue{Hint:}\nl '+
          'Consider the diameter of the circle and apply the Pythagorean Theorem.';
  ans:=#134'\c:6'#133+
       #134'\d:6';
  answer::=ans;
  solution::='\nl\red{Solution to part a:}\nl '+
          'The diameter of the circle is \b.\pause\nl '+
          'Apply the Pythagorean Theorem to triangle ABC:\nl '+
          '$$s^2+s^2=\b^2$$\pause\nl '+
          '$$2s^2=\e$$\pause\nl '+
          '$$s^2={\e\over 2}$$\pause\nl '+
          '$$s=\sqrt{{$\e\over 2$}}\doteq\c:3$$.\pause\nl ';
  solution2::='\nl\red{Solution to part b:}\nl '+
          'The area A of the square is $$s^2=(\sqrt{{$\e\over 2$}})^2={$\e\over 2$}$$.';
  type:='R';
  key:=4208;
end;                       

procedure s4208;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+6;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+4;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4209;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text,item,items,w,z:string;
begin
  case randint(1,3) of
  1:begin
    item:='toy';
    items:='toys';
  end;
  2:begin
    item:='dress';
    items:='dresses';
  end;
  3:begin
    item:='precalculus text';
    items:='precalculus texts';
  end;
  end;{case}
  x.a:=rand([12,14,16,17,18]);
  x.b:=100*rand([2,3,4]);
  x.c:=x.a*x.b+1000*rand([2,3])+100*rand([1..9])+10*rand([1..9]);
  x.d:=x.b+50*rand([6..12]);
  x.e:=rand([25,75]);
  x.f:=x.a+.01*x.e;
  x.g:=x.d-x.b;
  x.h:=x.f*x.g;
  str(x.h:6:2,w);
  x.j:=x.c+x.h;
  str(x.j:6:2,z);
  text:='Suppose the marginal cost of producing a particular '+item+' is '+
          '\$\a.\e. If the total cost of producing \b  '+items+' is \$\c, '+
          'determine the cost C of producing \d  '+items+'. Your answer must be '+
          'correct to the \red{nearest cent.}';
  text1::=text+nl;
  prompt::=#133'C = '#134;
  help::='\red{Marginal Cost}\nl\nl '+
          'The marginal cost is the cost of producing one additional '+item+'.\nl\nl '+
          'When the marginal cost is a constant, the cost function is a linear function '+
          'and the marginal cost is the slope of the cost function.';
  text3::=text+nl+'\nl\blue{Hint:}\nl '+
          'Compute the additional cost by using the marginal cost. How many '+
          'additional '+items+' are being produced?';
  ans:='\j:2';
  answer::=ans;
  solution::='\nl\red{Solution:}\nl '+
          'Starting with \b  '+items+' we must produce an additional \d  - \b  = '+
          '\g  '+items+'.\pause  The cost of producing each additional '+item+' is the '+
          'marginal cost \$\a.\e.\pause  Thus the additional cost is\nl '+
          '\g\cdot(\$\a.\e) = \$'+w+' \pause\nl '+
          'Thus the total cost C of producing \d  '+items+' is '+
          '$$\$\c.00+\$'+w+'=\$'+z+'$$.';
  type:='R';
  key:=4209;
end;

procedure s4209;
var
undef,notwff:boolean;
res:string;
w,z:real;
begin
  replace(prompt,'',response);
  res:=response;
  toupper(res);
  replace('$','',res);
  replace('DOLLARS','',res);
  replace('DOLLAR','',res);
  w:=evaluate(res,'',undef,notwff);
  z:=evaluate(answer,'',undef,notwff);
  if abs(z-w) < .005 then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4210;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text,ineq,ineq1:string;
begin
  x.a:=rand([-10..-1,1,10]);
  x.b:=rand([-15..-5,5..15]);
  x.c:=x.b^2;
  x.d:=4*x.a;
  x.e:=x.c/x.d;
  text:='For what values of k does the equation $$\a x^2+\b x+k=0$$ have '+
          'two distinct real roots. Express your answer as a collection of '+
          'intervals separated by commas.';
  text1::=text+nl;
  prompt::=#133'Values of k with two real roots: '#134;
  help::='\red{Quadratic Formula:}\nl '+
          '\ \ Roots of $$ax^2+bx+c=0$$:\nl '+
          '\ \ $$x={-b\pm\sqrt{b^2-4ac}\over 2a}$$\nl\nl '+
          '$$b^2-4ac>0$$ => two distinct real roots\nl '+
          '$$b^2-4ac=0$$ => one real root\nl '+
          '$$b^2-4ac<0$$ => two distinct complex roots';
  text3::=text+nl+'\nl\blue{Hint:}\nl '+
          'Consider the discriminant $$b^2-4ac$$ in the quadratic formula.';
  if x.a>0.0 then ineq:='<' else ineq:='>';
  if x.a>0.0 then ans:='(-\inf,{$\c\over \d$})' else ans:='({$\c\over \d$},\inf)';
  answer::=ans;
  if x.d<0.0 then ineq1:='$$-\d k>-\c$$' else ineq1:='$$\d k<\c$$';
  solution::='\nl\red{Solution:}\nl '+
          'The roots of the quadratic equation $$ax^2+bx+c=0$$ are given by '+
          '$$x={-b\pm\sqrt{b^2-4ac}\over 2a}$$.\pause\nl '+
          'For the general quadratic equation $$ax^2+bx+c=0$$, the sign of the '+
          'discriminant $$b^2-4ac$$ determines the nature of the roots.\pause\nl '+
          'In order for the equation to have two distinct real roots the discriminant '+
          'must be positive.\pause\nl '+
          'Thus we must have $$(\b)^2-4(\a)(k)>0$$ '+nl+
          '=> $$\c-\d k>0$$\nl '+
          '=> '+ineq1+'.\pause\nl '+
          'So k '+ineq+'{$\c\over \d$}.\pause\nl '+
          'Hence $$ax^2+bx+c=0$$ has distinct real roots when k is in the interval '+
          ans+'.';
  type:='R';
  key:=4210;
end;

procedure s4210;
begin
  replace(prompt,'',response);
  if sameintervals(answer,response) then begin
    result := 'T';
    message:=#141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect.'#140+#13+text3
    else message:=response+' is '+#140'incorrect'#140+'. '#13+text3;
  end;
end;

procedure p4211;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,dgm1,dgm2,text:string;
begin
  x.a:=rand([8,10,12,14,16]);
  dgm:=#127'500,500,1200,10;I,250,250,50;R,-4,-4,4,4;R,-2,-2,2,2;'+
          'L,2,2,4,4;L,-2,4,-2,2;B,3;F,0,3;B,2;C,-.2,1.5,x;C,-.2,-4.5,\a;'+
          'C,-4.8,0,\a;D,-4.4,-.2,-4.4,-4,6;D,-4.4,.53,-4.4,4,6;C,1.6,0,x;'+
          'B,2;D,.75,-4.4,4,-4.4,6;D,-4,-4.4,-.5,-4.4,6;'#127;
  dgm1:=#127'500,500,700,10;I,150,200,50;L,-1,0,0,2;L,0,2,3,2;L,3,2,5,0;'+
          'L,-1,0,5,0;B,4;D,3,0,3,2,4;B,2;C,1.2,-.4,b_1;C,1.06,2.48,b_2;'+
          'C,2.56,.98,h;'#127;
  text:=dgm+'Two squares of edge-lengths \a  and x respectively are '+
          'concentric. Express the area A of the shaded region as a function '+
          'of x.';
  text1::=text+nl+nl+nl+nl+nl+nl+nl+nl+nl;
  prompt::=#133'A(x) = '#134;
  help::='\red{Area of a Trapezoid:}\nl\nl '+dgm1+
          'A trapezoid is a 4 sided figure with two parallel sides.\nl '+
          'Area = {h(b_1+b_2)\over 2}';
  text3::=text+nl+'\nl\blue{Hint:}\nl '+
          'The area of a trapezoid is $${h(b_1+b_2)\over 2}$$ where b_1  and '+
          'b_2  are the lengths of the parallel sides and h is the altitude. '+
          'Express b_1, b_2  and h in terms of x.';
  dgm2:=#127'500,550,1200,100;I,250,250,50;R,-4,-4,4,4;R,-2,-2,2,2;L,2,2,4,4;'+
          'L,-2,4,-2,2;B,3;F,0,3;B,2;C,-.2,1.5,x;C,-.2,-4.5,\a;C,-4.8,0,\a;'+
          'D,-4.4,-.2,-4.4,-4,6;D,-4.4,.53,-4.4,4,6;C,1.6,0,x;B,2;'+
          'D,.75,-4.4,4,-4.4,6;D,-4,-4.4,-.5,-4.4,6;B,0;D,2,-2,4,-2,4; '+
          'D,2,-2,2,-4,4;C,2,-1.3,{\a-x\over2};C,0,-2.97,{\a-x\over2}; '+
          'C,-1.06,4.8,x+{\a-x\over2};'#127;
  x.c:=2*x.a;
  x.b:=x.a^2;
  ans:='{\b+\c x-3x^2\over 8}';
  answer::=ans;
  solution::=dgm2+'\nl\red{Solution:}\nl '+
          'Since the squares are concentric the distance between adjacent '+
          'edges of the two squares is $${\a-x\over 2}$$.\pause\nl '+
          'The lower base of the trapezoid is x while the upper base is '+
          '$$x+{\a-x\over 2}={x+\a\over 2}$$.\pause\nl '+
          'The altitude of the trapezoid is $${\a-x\over 2}$$.\pause\nl '+
          'Using the formula for the area of a trapezoid\nl '+
          '$$A={h(b_1+b_2)\over 2}$$ we find \nl '+
          'A(x) = $${1\over 2}\cdot({\a-x\over 2})\cdot(x+{x+\a\over 2})$$\pause\nl '+
          '= $$({\a-x\over 4})\cdot({3x+\a\over 2})$$\pause\nl '+
          '= $${\b+\c x-3x^2\over 8}$$.';
  type:='R';
  key:=4211;
end;

procedure s4211;             
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4212;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2:string;
begin
  x.a:=rand([-3,-5,4,6,10,12]);
  header:='\red{Answer both parts before grading.}';
  text:='Express the domain of each of the following functions. Express '+ 
        'your answer as a collection of intervals separated by commas.';
  part1:='\red{a: }  $$(ln(x+\a))^2$$   (50%)';
  part2:='\red{b: }  $$ln((x+\a)^2)$$   (50%)';
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13;
  buff1:=text+#13+part1+#13+part2+nl;
  prompt::=#133'a: domain $$(ln(x+\a))^2$$:'#134#13+
           #133'b: domain $$ln((x+\a)^2)$$:'#134;
  help::=#127'500,500,700,10;A,100,250,50;G,ln(x),0,8;B,2;C,.2,4,y=ln(x);'#127+
        '\red{$$y=ln(x):$$}\nl '+
        'Domain: x > 0 or (0,\inf)\nl '+
        'Range: all x or (-\inf,\inf)';
  text3::=buff1+'\nl\blue{Hint:}\nl '+
        'The domain of the function f(x) = ln(x) is all x > 0.Note that 0 is '+
        'not in the domain of f(x) = ln(x). Pay attention to the order in which '+
        'the operations are performed starting with x in each case.';
  ans:=#134'($-\a$,\inf)'#133+
       #134'(-\inf,$-\a$),($-\a$,\inf)';
  answer::=ans;
  separate(ans,a1,a2);
  solution::=#127'500,500,1200,10;A,100,250,50;G,ln(x),0,8;B,2;C,.2,4,y=ln(x);'#127+
  	'\nl\red{Solution to part a:}\nl '+
        'The domain of $$f(x)=ln(x)$$ is (0,\inf).\pause\nl '+
        'Thus the expression inside the ln function must be strictly positive.\pause\nl '+
        'So we must have $$x+\a>0$$ => $$x>-\a$$.\pause\nl '+
        'In interval notation this is (-\a,\inf).\pause\nl '+
        'Thus the domain of $$(ln(x+\a))^2$$ is '+a1+'.\pause\nl';
  solution2::='\nl\red{Solution to part b:}\nl '+
        'Here we must have $$(x+\a)^2>0$$.\pause\nl '+
        'This is true for all x \ne  $$-\a$$.\pause\nl '+
        'Thus the domain of $$ln((x+\a)^2)$$ is '+a2+'.';
  type:='R';
  key:=4212;
end;       

procedure s4212;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameintervals(a1,r1);
  check2:=sameintervals(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4214;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,a3,dgm,header,text,part1,part2,part3:string;
begin
  x.c:=rand([-5..-2,1..5]);
  x.b:=rand([-12..-6,6..12]);
  x.d:=x.c+1;
  header:='\red{Answer all 3 parts before grading}';
  text:='Let $$f(x)=e^{\b x}+\c$$';
  part1:='\red{a: } Determine the range of f(x). Use \red{interval}  notation. '+
         '   (40%)';
  part2:='\red{b: } Determine the x-intercepts of f(x).   (30%) ';
  part3:='\red{c: } Determine the y-intercepts of f(x).   (30%) \nl '+
        'In \red{a:}  and \red{b:}  separate multiple answers with commas or '+
        'enter \red{none}  if appropriate.\nl';
  text1::=dgm+header+#13+#13+text+#13+part1+#13+part2+#13+part3+#13;
  buff1:=text+#13+part1+#13+part2+#13+part3;
  prompt::=#133'a: range:'#134#13+
           #133'b: x-intercepts: x = '#134#13+
           #133'c: y-intercepts: y = '#134;
  help::='\red{Domain, Range, Intercepts:}\nl\nl '+
          'The \red{domain}  of a function is the set of all input values x for '+
          'which the function is defined.\nl\nl '+
          'The \red{range}  of a function is the set of all output values y as '+
          'x ranges over the domain.\nl\nl '+
          'The \red{x}-intercepts are the values of x for which the output '+
          'y = 0.\nl\nl '+
          'The \red{y}-intercept of a function is the output value when x = 0 '+
          'providing x = 0 is in the domain of the function.\nl\nl '+
          #127'500,500,700,10;A,250,200,50;G,exp(x),-5,5;B,2;G,exp(-x),-5,5;B,0;'+
          'C,1.75,4.7,y=e^x;B,2;C,-4,4.75,y=e^{-x};'#127+
          '\nl Graphs of $$y=e^x$$ and $$y=e^{-x}$$';
  text3::=buff1+'\nl\blue{Hint:}\nl '+
          'The range of a function y = f(x)is the set of all output '+
          'values of the function as x varies over the domain. The '+
          'x-intercepts of y = f(x) occur when y = 0 and the y-intercepts '+
          'y-intercepts occur when x = 0.';
  if x.c > 0.0 then a2:='NONE' 
  else begin
    a2:='$${1\over\b}ln(-\c)$$';          
    buff2::='('+a2+',0)';   {allow answer in form of a point}
  end;
  ans:=#134'(\c,\inf)'#133+
       #134+a2+#133+
       #134'\d';
  buff3::='(0,\d)';
  answer::=ans;
  separate(ans,a1,a2,a3);
  if x.c<0.0 then x.w:=ln(-x.c)/x.b;
  solution::='\nl\red{Solution to part a: }\nl '+
          'The output values of e^{\b x} are all positive reals or (0,\inf).\pause\nl '+
          'When \c  is added to these numbers, the set of output '+
          'values becomes the set of all reals from \c  to \inf.\pause\nl '+
          'So the range of f(x) = $$e^{\b x}+\c$$ is '+a1+'.\pause\nl ';
  if x.c>0.0 then 
    solution2::='\nl\red{Solution to part b: }\nl '+
          'Let y = $$e^{\b x}+\c$$. To find the x-intercepts we set '+
          'y = 0 and obtain $$e^{\b x}=-\c$$.\pause\nl '+
          'There are no solutions to this equation since the exponential '+
          'function $$y=e^{\b x}$$ is always positive.\pause\nl '+
          'Thus the answer to part b: is none.\pause\nl '
  else
    solution2::='\nl\red{Solution to part b: }\nl '+
          'Let y = $$e^{\b x}+\c$$. To find the x-intercepts we set '+
          'y = 0 and obtain $$e^{\b x}=-\c$$.\pause\nl '+ 
          'Taking natural logs of both sides yields $$\b x=ln(-\c)$$ or '+
          '$$x={1\over\b}ln(-\c)$$.\pause\nl '+
          'Thus the  only x-intercept is $$x={1\over\b}ln(-\c)\doteq\w:6$$\pause\nl ';
  solution3::='\nl\red{Solution to part c: }\nl '+
          'Let y = $$e^{\b x}+\c$$. To find the y-intercept we set x = 0 and '+
          'obtain y = $$e^{\pi} +\c$$ = $$1+\c=\d$$.\pause\nl '+
          'Thus the y-intercept is \d.';  
  replace('~','0',solution3);
  type:='R';
  key:=4214;
end;
                   
procedure s4214;
var
  r1,r2,r3,r4,a1,a2,a3,s2,s3:string;
  r:integer;
  check1,check2,check3,undef,notwff:boolean;
begin
  message:='';
  separate(response,r1,r2,r3);
  s2:=r2;
  s3:=r3;
  clean(r2);toupper(r2);
  clean(r3);toupper(r3);
  check1:=false;
  check2:=false;
  check3:=false;
  separate(answer,a1,a2,a3);
  check1:=sameintervals(a1,r1);
  check2:=sameconstants(a2,s2) or
    ((pos('NONE',a2)>-1) and (pos('NONE',r2)>-1)) or
    samepoints(s2,buff2);
  check3:=sameconstants(a3,s3) or
    ((pos('NONE',a3)>-1) and (pos('NONE',r3)>-1)) or
    samepoints(s3,buff3);
  if check1 and check2 and check3 then begin
    result:='T';
    message:=#141'Correct'#141;
  end else begin
    if check1 then begin
      r:=r+4;
      message:='a: '+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:='a: '+r1+' is '#140'incorrect'#140'.'+#13+nl;
      end;
    end;
    if check2 then begin
      r:=r+3;
      message:=message+'b: '+s2+' is '#141'correct.'#141+nl;
    end else begin
      if s2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+'b: '+s2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check3 then begin
      r:=r+3;
      message:=message+'c: '+s3+' is '#141'correct'#141'.'+nl;
    end else begin
      if s3 = '' then begin
        message:=message+#140'c: Incorrect.'#140+nl;
      end else begin
        message:=message+'c: '+s3+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+text3;
  end;
end;

procedure p4215;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2:string;
begin
  x.a:=rand([20..75]);
  header:='\red{Answer both parts before grading.}';
  text:='Solve each of the following equations for \red{all}  solutions x.\nl '+
          'Separate multiple solutions by commas.';
  part1:='\red{a: } $$e^{(x^{2})}=\a$$\ \ \ (50%)';
  part2:='\red{b: } $$(e^{x})^{2}=\a$$\ \ \ (50%)';
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13;
  buff1:=text+#13+part1+#13+part2+nl;
  prompt::=#133'a: x =  '#134#13+
             #133'b: x =  '#134;
  help::='\red{Inverse Identities:}\nl '+
          '$$a^{log_a(x)}=x$$\nl '+
          '$$log_a(a^{x})=x$$\nl '+
          '$$ln(e^{x})=x$$\nl '+
          '$$e^{ln(x)}=x$$';
  text3::=buff1+'\nl\blue{Hint:}\nl '+
          'Use the inverse identities\nl '+
          '$$ln(e^{x})=x$$ and $$e^{ln(x)}=x$$\nl '+
          'Take into account the order in which operations are performed.\nl '+
          'Remember to find all solutions.';
  ans:=#134'\sqrt{ln(\a)},-\sqrt{ln(\a)}'#133+
       #134'ln(\sqrt{\a})';                                             
  answer::=ans;
  separate(ans,a1,a2);
  x.w:=sqrt(ln(x.a));
  x.z:=ln(sqrt(x.a));
  solution::='\nl\red{Solution to part a:}\nl '+
          '$$e^{(x^{2})}=\a$$\nl '+
          'Taking natural logs of each side we obtain\nl '+
          '$$ln(e^{(x^{2})}=ln(\a)$$\pause\nl '+
          '=> $$x^{2}=ln(\a)$$\pause\nl '+
          '=> $$x=\pm\sqrt{ln(\a)}\doteq\pm\w:6$$\pause\nl '+
          'Thus the solutions to \red{a:}  are \sqrt{ln(\a)},-\sqrt{ln(\a)}.\pause\nl ';
  solution2::='\nl\red{Solution to part b:}\nl '+
          '$$(e^{x})^{2}=\a$$\nl '+
          'Taking square roots of each side we obtain\nl '+
          '$$\sqrt{(e^{x})^{2}}=\sqrt{\a}$$\pause\nl '+
          '=> $$e^{x}=\sqrt{\a}$$\pause\nl '+
          'Taking natural logs of each side we obtain\nl '+
          '$$ln(e^{x})=ln(\sqrt{\a})$$\pause\nl '+
          '=> $$x=ln(\sqrt{\a})\doteq\z:6$$\pause\nl '+
          'Thus the only solution to \red{b:}  is x = ln(\sqrt{\a}).';
  type:='R';
  key:=4215;
end;       
         
procedure s4215;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4216;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text:string;
begin
  x.a:=rand([-3..-1,1..3]);
  x.b:=rand([1,2]);
  x.c:=x.b+rand([2,3]);
  text:='Determine the average rate of change of the function\nl '+
          '\ \ \ $$f(x)=e^{\a x}$$\nl '+
          'over the interval [\b,\c].';
  text1::=text+nl;
  prompt::=#133'Average rate of change: '#134;
  help::='\red{Average Rate of Change:}\nl '+
          'The average rate of change of y = f(x) on [a,b] is defined as '+
          '$${f(b)-f(a)\over b-a}$$.\nl\nl '+
          'The average rate of change of y = f(x) on [a,b] is the slope '+
          'of the secant line through the points (a,f(a)) and (b,f(b)) '+
          'on the graph of y = f(x).';
  text3::=text+nl+'\nl\blue{Hint:}\nl '+
          'The average rate of change of y = f(x) on [a,b] is defined as '+
          '$${f(b)-f(a)\over b-a}$$.';
  x.d:=x.a*x.c;
  x.e:=x.a*x.b;
  x.f:=x.c-x.b;
  x.g:=exp(x.d);
  x.h:=exp(x.e);
  x.i:=x.g-x.h;
  str(x.i/x.f,ans);
  x.w:=evaluate(ans,'',undef,notwff);          
  answer::=ans;
  solution::='\nl\red{Solution:}\nl '+
          'The average rate of change of $$f(x)=e^{\a x}$$ over the interval '+
          '[\b,\c] is $${e^{\a\cdot \c}-e^{\a\cdot \b}\over \c-\b}\nl='+
          '{e^{\d}-e^{\e}\over \f}\nl={\g:6-\h:6\over \f}\doteq\w:6$$';
  type:='R';
  key:=4216;
end;

procedure s4216;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4217;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2,f1,f2,sol1,sol2:string;
  k:integer;
begin
  x.a:=rand([-10..-2,2..8]);
  x.b:=rand([-5..-1,1..5]);
  case randint(1,2) of
    1: begin
      f1:='{1\over f(x)}';
      f2:='f^{-1}(x)';
      a1:='$${1\over \a x+\b}$$';
      if x.a>0.0 then a2:='$${$x-\b\over \a$}$$' else
        a2:= '$$-{$x-\b\over -\a$}$$';
      sol1:='{1\over f(x)} denotes the reciprocal of f(x).\pause\nl '+
          'This is simply $${1\over \a x+\b}$$.\pause\nl ';
      sol2:='f^{-1}(x) denotes the inverse function.\pause\nl '+
          'Let y = $$\a x+\b$$. Solving for x in terms of y we find\nl '+
          '$$x={y-\b\over \a}$$.\pause\nl '+
          'Interchanging x and y we have $$y={x-\b\over \a}$$.\pause\nl '+
          'Thus f^{-1}(x) = '+a2+'.';
    end;
    2:begin
      f2:='{1\over f(x)}';
      f1:='f^{-1}(x)';
      a2:='$${1\over \a x+\b}$$';
      if x.a>0.0 then a1:='$${$x-\b\over \a$}$$' else
        a1:= '$$-{$x-\b\over -\a$}$$';
      sol2:='{1\over f(x)} denotes the reciprocal of f(x).\pause\nl '+
          'This is simply $${1\over \a x+\b}$$.\pause\nl ';
      sol1:='f^{-1}(x) denotes the inverse function.\pause\nl '+
          'Let y = $$\a x+\b$$. Solving for x in terms of y we find\nl '+
          '$$x={y-\b\over \a}$$.\pause\nl '+
          'Interchanging x and y we have $$y={x-\b\over \a}$$.\pause\nl '+
          'Thus f^{-1}(x) = '+a1+'.';
    end;
  end;{case}              
  header:='\red{Answer both parts before grading.}';
  text:='Let f(x) = $$\a x+\b$$';
  part1:='\red{a: } Express '+f1+'. (50%)';
  part2:='\red{b: } Express '+f2+'. (50%)';
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13;
  buff1:=text+#13+part1+#13+part2+nl;
  prompt::=#133'a: '+f1+' = '#134#13+
           #133'b: '+f2+' = '#134;
  help::='\red{Inverse Functions:}\nl '+
          'A function must be one-to-one in order to have an inverse function.\nl '+
          'Given y = f(x), solving for x in terms of y gives the formula '+
          'for f^{-1}(y). Interchange the variables x and y to get the '+
          'formula for f^{-1}(x).\nl\nl '+
          '(f^{-1}\circ f)(x) = (f\circ f^{-1})(x) = x';
  text3::=buff1+'\nl\blue{Hint:}\nl '+
          'One is the reciprocal and the other is the inverse function.';
  ans:=#134+a1+#133+
       #134+a2;
  answer::=ans;
  separate(ans,a1,a2);
  solution::='\nl\red{Solution to part a:}\nl '+sol1;
  solution2::='\nl\red{Solution to part b:}\nl '+sol2;
  type:='R';
  key:=4217;
end;       
                
procedure s4217;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameexpres(a1,r1);
  check2:=sameexpres(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+5;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+5;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4218;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text:string;
  k:integer;
begin
  case randint(1,2) of
  1:begin
    x.a:=rand([-5,-4]);                                         
    x.b:=rand([-4,-3]);                                         
    x.c:=x.a+2;                                                 
    x.d:=x.b+5;                                                 
    x.e:=x.a+8;                                                 
    x.f:=x.b+7;                                                 
    x.g:=6-x.b;                                                 
    k:=round(x.g);                                              
    if randint(0,1)=0 then x.h:=x.b+rand([0,5,7]) else x.h:=6;  
    if x.h=x.b then ans:='\a';                                  
    if x.h=x.d then ans:='\c';                                  
    if x.h=x.f then ans:='\e';                                  
    if x.h=6.0 then ans:='5';
    x.i:=6;
  end;
  2:begin
    x.a:=rand([-5,-4]);                                         
    x.b:=rand([4,3]);                                         
    x.c:=x.a+2;                                                 
    x.d:=x.b-5;                                                 
    x.e:=x.a+8;                                                 
    x.f:=x.b-7;                                                 
    x.g:=-6+x.b;                                                 
    k:=round(x.g);                                              
    if randint(0,1)=0 then x.h:=x.b+rand([0,-5,-7]) else x.h:=-6;  
    if x.h=x.b then ans:='\a';                                  
    if x.h=x.d then ans:='\c';                                  
    if x.h=x.f then ans:='\e';                                  
    if x.h=-6.0 then ans:='5';
    x.i:=-6;
  end;
  end;{case}         
  dgm::=#127'360,420,1200,10;A,180,210,30;B,2;L,\a,\b,\c,\d;'+
          'L,\c,\d,\e,\f;L,\e,\f,5,\i;G,\b,D\a,\a;G,\d,D\c,\c;'+
          'G,\f,D\e,\e;G,\i,D5,5;';
  text:=dgm+#127+'The graph of a one-one function is shown to the right. '+
          'Determine f^{-1}(\h).\nl ';
  text1::=text+nl+nl+nl+nl+nl+nl+nl+nl+nl;
  prompt::=#133'f^{-1}(\h) = '#134;
  help::='\red{Inverse Functions:}\nl '+
          'A function must be one-to-one in order to have an inverse function.\nl '+
          'Given y = f(x), solving for x in terms of y gives the formula '+
          'for f^{-1}(y). Interchange the variables x and y to get the '+
          'formula for f^{-1}(x).\nl\nl '+
          '(f^{-1}\circ f)(x) = (f\circ f^{-1})(x) = x';
  text3::=text+'\nl\blue{Hint:}\nl '+
          'y = f(x) <=> x = f^{-1}(y) providing f(x) has an inverse '+
          'function.';
  answer::=ans;
  dgm:=dgm+'B,4;L,'+ans+',\h,0,\h;L,'+ans+',\h,'+ans+',0;';
  solution::='\nl\red{Solution:}\nl '+dgm+#127+
          'f^{-1}(\h) is the input value x such that f(x) = \h.\pause\nl '+
          'From the graph, we see that this is '+ans+'.'; 
  type:='R';
  key:=4218
end;

procedure s4218;
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4219;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text:string;
begin
  x.a:=rand([-5..-2,1..5]);
  x.b:=rand([6..12]);
  x.c:=rand([14,16,20,24]);
  text:='Let f(x) = $$\c e^{\a x+\b}$$. Find a formula for f^{-1}(x). '+
          'You may assume the given function is one-one.';
  text1::=text+nl;
  prompt::=#133'f^{-1}(x) = '#134;
  help::='\red{Inverse Functions:}\nl '+
          'A function must be one-to-one in order to have an inverse function.\nl '+
          'Given y = f(x), solving for x in terms of y gives the formula '+
          'for f^{-1}(y). Interchange the variables x and y to get the '+
          'formula for f^{-1}(x).\nl\nl '+
          '(f^{-1}\circ f)(x) = (f\circ f^{-1})(x) = x\nl '+
          '$$ln(e^x)=x$$\nl '+
          '$$e^{ln(x)}=x$$';
  text3::=text+nl+'\nl\blue{Hint:}\nl '+
          'Let y = f(x). Solve for x in terms of y and then interchange x and y.';
  ans:='$${$1\over \a$}(ln({x\over \c})-\b)$$';
  answer::=ans;
  solution::='\nl\red{Solution:}\nl '+
          'Let y = $$\c e^{\a x+\b}$$\pause\nl '+
          '=> $${y\over \c}=e^{\a x+\b}$$\pause\nl '+
          'Taking natural logs of both sides \nl '+
          '=> $$ln({y\over \c})=\a x+\b$$\pause\nl '+
          '=> $$\a x=ln({y\over \c})-\b$$\pause\nl '+
          '=> $$x={$1\over \a$}(ln({y\over \c})-\b)$$\pause\nl '+
          'Interchanging x and y '+
          '=> $$y={$1\over \a$}(ln({x\over \c})-\b)$$\pause\nl '+
          'Thus f^{-1}(x) = $${$1\over \a$}(ln({x\over \c})-\b)$$.';
  type:='R';
  key:=4219;
end;

procedure s4219;
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4220;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,text,part1,part2:string;
begin
  x.a:=rand([5..12]);
  x.b:=x.a+rand([2..6]);
  x.h:=.5*(x.b-x.a);
  x.d:=x.h*(x.a+x.b);
  x.e:=x.d/2;
  x.f:=x.b-x.a;
  x.g:=x.a+x.b;
  x.i:=x.h*(x.a+x.g);
  x.j:=.5*x.g;
  x.i:=.5*x.h*(x.a+x.j);
  dgm::=#127'500,500,1200,10;I,250,250,50;R,-4,-4,4,4;R,-2,-2,2,2;'+
          'L,-2,2,-2,4;L,2,2,4,4;B,3;F,0,3;B,2;C,-.3,-2.4,\a;'+
          'C,.-3,-4.5,\b;C,-2.5,2.9,h;';
  header:='\red{Answer both parts before grading.}';
  text:=dgm+#127+'Two concentric squares are shown to the right. The edge-length '+
          'of the outer square is \b  while the edge-length of the '+
          'inner square is \a.';
  part1:='\red{a: } Determine h.  (30%)';
  part2:='\red{b: } Determine the area of the shaded region. (70%)';
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13+#13+#13+#13+#13+#13;
  buff1:=text+#13+part1+#13+part2+nl;
  prompt::=#133'a: h = '#134#13+
           #133'b: Area = '#134;
  help::='\red{Area of a Trapezoid:}\nl\nl '+
          #127'500,500,700,10;I,150,200,50;L,-1,0,0,2;L,0,2,3,2;L,3,2,5,0;'+
          'L,-1,0,5,0;B,4;D,3,0,3,2,4;B,2;C,1.2,-.4,b_1;C,1.06,2.48,b_2;'+
          'C,2.56,.98,h;'#127+
          'A trapezoid is a 4 sided figure with two parallel sides.\nl '+
          'Area = $${h(b_1+b_2)\over 2}$$';
  text3::=buff1+'\nl\blue{Hint:}\nl The area of a trapezoid is '+
          '$${h(b_1+b_2)\over 2}$$.';
  ans:=#134'\h:1'#133+
       #134'\i:4';
  answer::=ans;
  separate(ans,a1,a2);
  solution::=dgm+
          'B,0;D,-2,-2,-2,-4,3;B,2;C,-2.5,-3,h;C,-1.8,.2,\a;'+
          'C,-3.2,4.2,h;L,-4,4.2,-3.4,4.2;L,-2.8,4.2,-2,4.2;C,-4.8,.2,\b;'#127+
          '\nl\red{Solution to part a:}\nl '+
	  'From the diagram it follows that\nl '+
          '$$h+\a+h=\b$$.\pause\nl '+
          '=> $$2h+\a=\b$$\pause\nl '+
          '=> $$h={\b-\a\over 2}=\h:1$$\pause\nl '; 
  solution2::='\nl\red{Solution to part b:}\nl '+
          'The shaded region is a trapezoid.\pause\nl '+
          'The area of a trapezoid is $${h(b_1+b_2)\over 2}$$.\pause\nl '+
          'The length of the top of the trapezoid is $$\b-{$\f\over 2$}'+
          '={$\g\over 2$}$$.\pause\nl '+
          'So the area of the shaded region is $${\h:1(\a+\j:1)\over2}$$ '+
          '= \i:4.';
  type:='R';
  key:=4220;
end;       

procedure s4220;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+3;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+7;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4221;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,dgm1,header,text,part1,part2:string;
begin
  x.a:=rand([12,14,16,22,24,28]);
  x.b:=rand([5,6,8,9]);
  dgm::=#127'500,500,1200,10;I,250,250,60;L,-3,0,3,0;P,3,0,3.16;'+
          'R,-2.19,0,2.19,2.03;B,2;C,1.3,-.5,\a;C,2.31,0.92,\b;B,4;F,0,1;'+
          'B,0;L,0,-.3,1.1,-.3;L,2.15,-.3,3,-.3;'#127;
  header:='\red{Answer both parts before grading.}';
  text:='A rectangle whose width is \b  is inscribed in a semicircle of '+
          'radius \a.';
  part1:='\red{a: }  Determine the area of the rectangle. (60%)';
  part2:='\red{b: }  Determine the perimeter of the rectangle. (40%)';
  text1::=header+dgm+#13+#13+text+#13+part1+#13+part2+#13+#13;
  buff1:=dgm+text+#13+part1+#13+part2+nl;
  prompt::=#133'a: area = '#134#13+
           #133'b: perimeter = '#134;
  help::= #127'400,400,700,0;I,100,200,40;R,0,0,6,4;C,-.5,1.8,x;C,2.8,-.5,y;'#127+
          '\red{Formulas for Rectangles:}\nl '+
          'Area = xy\nl '+
          'Perimeter = 2x + 2y\pause\nl\nl\nl '+
          #127'400,400,700,0;I,100,200,40;E,0,0,4,4;L,2,2,4,2;C,2.8,2.2,r;'#127+
          '\red{Formulas for Circles:}\nl '+ 
          'Area = \pi r^2\nl '+
          'Circumference = 2\pi r\pause\nl\nl\nl '+
          #127'400,500,500,0;I,200,300,50;L,0,0,0,4;L,0,4,2,0;L,0,0,2,0;'+
          'C,-.5,1.8,a;C,.8,-.6,b;C,1.4,1.8,c;'#127+
          '\red{Pythagorean Theorem:}\nl '+
          '$$a^2+b^2=c^2$$';
  text3::=buff1+'\nl\blue{Hint:}\nl '+
          'Let x denote half the length of the rectangle and use the '+
          'Pythagorean Theorem.';
  dgm1:=#127'500,500,1200,10;I,250,250,60;L,-3,0,3,0;P,3,0,3.16;'+
          'R,-2.19,0,2.19,2.03;B,2;C,1.3,-.5,\a;C,2.31,0.92,\b;B,0;'+
          'L,0,-.3,1.1,-.3;L,2.15,-.3,3,-.3;L,0,0,2.19,2.03;B,4;'+
          'C,1.19,.2,x;B,2;C,.4,1.14,\a;'#127;
  x.c:=x.b^2;
  x.d:=x.a^2;          
  x.e:=x.d-x.c;
  x.f:=2*x.b;
  x.g:=2*x.b;
  x.w:=x.f*sqrt(x.e);
  x.z:=4*sqrt(x.e)+x.g;
  ans:=#134'\w:6'#133+
       #134'\z:6';
  answer::=ans;
  separate(ans,a1,a2);
  solution::=dgm1+'\nl\red{Solution to part a:}\nl '+
          'Let x denote half the length of the rectangle and draw a radius '+
          'of the semicircle from the center to a corner of the rectangle as '+
          'indicated.\pause\nl '+
          'By the Pythagorean theorem $$x^{2}+\b^2=\a^2$$ or $$x^2+\c=\d$$.\pause\nl '+
          'Thus $$x^2=\d-\c=\e$$ or x = \sqrt{\e}.\pause\nl '+
          'Note that x must be positive so we ignore the negative square '+
          'root.\pause\nl '+
          'So length = 2\cdot x = 2\sqrt{\e}.\pause\nl '+
          'The area of the rectangle is length\cdot width = '+
          '2\sqrt{\e}\cdot \b = \f\sqrt{\e} \doteq  \w:6.\pause\nl ';
  solution2::='\nl\red{Solution to part b:}\nl '+
          'The perimeter of the rectangle is 2\cdot length + 2\cdot width\nl '+
          '= 2(2\sqrt{\e})+2\cdot \b = $$4\sqrt{\e}+\g\doteq\z:6$$';
  type:='R';
  key:=4221;
end;       

procedure s4221;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+6;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+4;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p4222; {old 123}   
var
  i,j,k,m,n:integer;
  f0:string;
  v:valuetype;
begin
  repeat i := randint(-7,7) until i<>0;
  repeat j := randint(-7,7) until (j<>0) and (j<>i);
  if (j < i) then begin m := i; i := j; j := m; end;   {now have i < j}
  repeat k := randint(-10,10) until (k<>0) and (k<>-i*j);
  v.a := -i-j;
  v.d := k;
  v.c := i*j + k;
  v.e := i*j;
  v.i := i;
  v.j := j;
  m := randint(1,2);
  case m of
    1:begin
        f0 := makeformula('x^2 + ax + c < d',['a'..'d'],v);
        answer := st(i)+' < x < '+st(j);
        solution := f0+#10+nl+
          makeformula('x^2+ax+e<0',['a'..'e'],v)+#10+nl+
          'Factor the quadratic:'+#10+nl+
          makeformula('(x-i)(x-j)<0',['a'..'j'],v)+#10+nl+
          'Since the product is negative, the factors have opposite signs:'+#10+nl+
          'One possibility is'+#10+nl+
          makeformula('(x-i)>0',['i'..'j'],v)+' and '+
          makeformula('(x-j)<0',['i'..'j'],v)+#10+nl+
          '=> '+makeformula('x>i@and@x<j',['i'..'j'],v)+'.'#10+nl+
          'This is equivalent to '+makeformula('i<x<j',['i'..'j'],v)+'.'#10+nl+
          'The other possibility is'+#10+nl+
          makeformula('(x-i)<0',['i'..'j'],v)+' and '+
          makeformula('(x-j)>0',['i'..'j'],v)+#10+nl+
          '=> '+makeformula('x<i@and@x>j',['i'..'j'],v)+'which has no solution.'+#10+nl+
          'Thus the answer is '+answer+'.';
      end;
    2:begin
        f0 := makeformula('x^2 + ax + c > d',['a'..'d'],v);
        answer := 'x < '+st(i)+' or '+st(j)+' < x';
        solution := f0+#10+nl+
          makeformula('x^2+ax+e>0',['a'..'e'],v)+#10+nl+
          'Factor the quadratic:'+#10+nl+
          makeformula('(x-i)(x-j)>0',['a'..'j'],v)+#10+nl+
          'Since the product is positive, the factors have the same signs:'+#10+nl+
          'One possibility is'+#10+nl+
          makeformula('(x-i)>0',['i'..'j'],v)+' and '+
          makeformula('(x-j)>0',['i'..'j'],v)+#10+nl+
          '=> '+makeformula('x>i@and@x>j',['i'..'j'],v)+#10+nl+
          'This is equivalent to '+makeformula('x>j',['i'..'j'],v)+'.'#10+nl+
          'The other possibility is'+#10+nl+
          makeformula('(x-i)<0',['i'..'j'],v)+' and '+
          makeformula('(x-j)<0',['i'..'j'],v)+#10+nl+
          '=> '+makeformula('x<i@and@x<j',['i'..'j'],v)+#10+nl+
          'This is equivalent to '+makeformula('x<i',['i'..'j'],v)+'.'#10+nl+
          'Thus the answer is '+answer+'.';
      end;
  end;
  text1 ::= 'Solve the following inequality for x:'+nl+'   '+f0+'.\nl '+
    'Write your answer as a single inequality, a continued '+
    'inequality such as\nl\red{-1 < x < 1}, or two inequalities connected by \red{or}  '+
    'such as \red{x < 3 or 5 < x}. Use \red{all}  to indicate the inequality holds for '+
    'all x.'+nl;
  text3 :=text1+nl+#142'Hint:'#142+nl+ 
    'Rearrange so that 0 is on one side of the inequality, then '+
    'factor the quadratic.';
  prompt::=#133'x such that '+f0+':'#134;
  help::='\red{Inequalities:}\nl '+
  	'$$a<b$$ => $$a+c<b+c$$\nl '+
	'If c > 0 then $$a<b$$ => $$a\cdot c<b\cdot c$$\nl '+
	'If c < 0 then $$a<b$$ => $$a\cdot c>b\cdot c$$\nl '+
	'If $$a<b$$ and $$c<d$$ then $$a+c<d+c$$\nl\nl '+
	'a\cdot b > 0 => a and b have same sign\nl '+
	'a\cdot b < 0 => a and b have opposite sign';
  solution:=nl+#140'Solution:'#140+nl+solution;
  key := 4222;
  type := 'R';
end;

procedure s4222;
begin
  replace(prompt,'',response);
  if sameinequal(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4223;  {old 160}
var
  a,b,c,d,e,f,m,p,t:integer;
  f1,f2,f3,s1:string;
  v:valuetype;
begin
  a := randint(2,9);
  b := randint(-8,8);
  c := randint(-9,-2);
  d := randint(-8,8);
  e := randint(2,9);
  f := randint(-8,8);
  repeat m := randint(-10,10) until m <> 0;
  p := randint(2,9);
  t := randint(1,3);
  v.a := a; v.b := b; v.c := c; v.d := d; v.e := e; v.f := f;
  f1 := makeformula('ax+b',['a','b'],v);
  f2 := makeformula('cx+d',['c','d'],v);
  f3 := makeformula('ex+f',['e','f'],v);
  case t of
  1:begin
      s1 := #29#219+st(m)+#221'/'#219+f1+#221' < 0';
      if m > 0 then begin
        answer := 'x < '+fraction(-b,'-',a);
        text3 := 'Since '+st(m)+' is positive, the fraction is negative '+
          'when the denominator is negative.';
        solution := s1+nl+#10+
          'Solve '+f1+' < 0'+nl+#10+
	  '=> '+makeformula('ax<-b',['a','b'],v)+nl+
          '=> '+answer+'.';
      end else begin
        answer := 'x > '+fraction(-b,'-',a);
        text3 := 'Since '+st(m)+' is negative, the fraction is negative '+
          'when the denominator is positive.';
        solution := s1+nl+#10+
          'Solve '+f1+' > 0'+nl+#10+
	  '=> '+makeformula('ax>-b',['a','b'],v)+nl+
          '=> '+answer+'.';
      end;
    end;
  2:begin
      s1 := #29#219+st(m)+#221'/'#219+f2+#221' > 0';
      if m > 0 then begin
        answer := 'x < '+fraction(-d,'-',c);
        text3 := 'Since '+st(m)+' is positive, the fraction is positive '+
          'when the denominator is positive.';
        solution := s1+nl+#10+
          'Solve '+f2+' > 0'+nl+#10+
	  '=> '+makeformula('cx>-d',['c','d'],v)+nl+
          '=> '+answer+'.';
      end else begin
        answer := 'x > '+fraction(-d,'-',c);
        text3 := 'Since '+st(m)+' is negative, the fraction is positive '+
          'when the denominator is negative.';
        solution := s1+nl+#10+
          'Solve '+f2+' < 0'+nl+#10+
	  '=> '+makeformula('cx<-d',['c','d'],v)+nl+
          '=> '+answer+'.';
      end;
    end;
  3:begin
      s1 := #29#219+st(m)+#221'/'#219+f2+#221' < 0';
      if m > 0 then begin
        answer := 'x > '+fraction(-d,'-',c);
        text3 := 'Since '+st(m)+' is positive, the fraction is negative '+
          'when the denominator is negative.';
        solution := s1+nl+#10+
          'Solve '+f2+' < 0'+nl+#10+
	  '=> '+makeformula('cx<-d',['c','d'],v)+nl+
          '=> '+answer+'.';
      end else begin
        answer := 'x < '+fraction(-d,'-',c);
        text3 := 'Since '+st(m)+' is negative, the fraction is negative '+
          'when the denominator is positive.';
        solution := s1+nl+#10+
          'Solve '+f2+' > 0'+nl+#10+
	  '=> '+makeformula('cx>-d',['c','d'],v)+nl+
          '=> '+answer+'.';
      end;
    end;
  end;
  text1::= 'Solve the following inequality for x:'+nl+'\ \ \  '+s1+nl+
    'Give your answer as a single or a continued '+
    'inequality.  Use \red{null}  if there is no solution, '+
    '\red{all}  if the answer is all real numbers.'+nl;
  text3:=text1+nl+#142'Hint:'#142+nl+text3+
  	' Remember to reverse an inequality when multiplying or dividing by '+
	'a negative number.';
  prompt::=#133+s1+': '#134;
  solution::=nl+#140'Solution:'#140+nl+solution;
  help::='\red{Inequalities:}\nl '+
  	'$$a<b$$ => $$a+c<b+c$$\nl '+
	'If c > 0 then $$a<b$$ => $$a\cdot c<b\cdot c$$\nl '+
	'If c < 0 then $$a<b$$ => $$a\cdot c>b\cdot c$$\nl '+
	'If $$a<b$$ and $$c<d$$ then $$a+c<d+c$$\nl\nl '+
	'{a\over b} > 0 => a and b have same sign\nl '+
	'{a\over b} < 0 => a and b have opposite sign';
  key := 4223;
  type := 'R';
end;

procedure s4223;
var
  res:string;
begin
  replace(prompt,'',response);
  if sameinequal(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
end;

procedure p4225;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,a1,a2,dgm,header,ineq,text,part1,part2,sol:string;
begin
  x.a:=rand([-9..-2,2..9]);
  x.b:=randint(-8,8);
  x.m:=rand([-19..-1,1..20]);
  x.p:=rand([2..9]);
  x.q:=x.m+x.p;
  x.r:=x.m-x.b;
  x.s:=x.q-x.b;
  case randint(1,4) of
  1:begin
    ineq:='$$\m <\a x+\b\le\q$$';
    if x.a>0.0 then begin 
      a1:='$${$\r\over \a$}<x\le{$\s\over \a$}$$';
      a2:='({$\r\over \a$},{$\s\over \a$}]';
    end else begin
      a1:='$${$\r\over \a$}>x\ge{$\s\over \a$}$$';
      a2:='[{$\s\over \a$},{$\r\over \a$})';
    end;
    sol:='$$\m<\a x+\b\le\q$$\nl '+
	'=> $$\m-\b<\a x\le\q-\b$$\nl '+
	'=> $$\r<\a x\le\s$$\nl '+
	'=> '+a1+'.';
  end;
  2:begin
    ineq:='$$\m\le\a x+\b\le\q$$';
    if x.a>0.0 then begin 
      a1:='$${$\r\over \a$}\le x\le{$\s\over \a$}$$';
      a2:='[{$\r\over \a$},{$\s\over \a$}]';
    end else begin
      a1:='$${$\r\over \a$}\ge x\ge{$\s\over \a$}$$';
      a2:='[{$\s\over \a$},{$\r\over \a$}]';
    end;
    sol:='$$\m\le\a x+\b\le\q$$\nl '+
	'=> $$\m-\b\le\a x\le\q-\b$$\nl '+
	'=> $$\r\le\a x\le\s$$\nl '+
	'=> '+a1+'.';
  end;
  3:begin
    ineq:='$$\m<\a x+\b<\q$$';
    if x.a>0.0 then begin 
      a1:='$${$\r\over \a$}< x<{$\s\over \a$}$$';
      a2:='({$\r\over \a$},{$\s\over \a$})';
    end else begin
      a1:='$${$\r\over \a$}>x>{$\s\over \a$}$$';
      a2:='({$\s\over \a$},{$\r\over \a$})';
    end;
    sol:='$$\m<\a x+\b<\q$$\nl '+
	'=> $$\m-\b<\a x<\q-\b$$\nl '+
	'=> $$\r<\a x<\s$$\nl '+
	'=> '+a1+'.';
  end;
  4:begin
    ineq:='$$\m\le\a x+\b<\q$$';
    if x.a>0.0 then begin 
      a1:='$${$\r\over \a$}\le x<{$\s\over \a$}$$';
      a2:='[{$\r\over \a$},{$\s\over \a$})';
    end else begin
      a1:='$${$\r\over \a$}\ge x>{$\s\over \a$}$$';
      a2:='({$\s\over \a$},{$\r\over \a$}]';
    end;
    sol:='$$\m\le\a x+\b<\q$$\nl '+
	'=> $$\m-\b\le\a x<\q-\b$$\nl '+
	'=> $$\r\le\a x<\s$$\nl '+
	'=> '+a1+'.';
  end;
  end;{case}
  header:='\red{Answer both parts before grading.}';
  text:='Solve the inequality\nl '+
  	'\ \ \ '+ineq+'\nl ';
  part1:='\red{a: } Express the solution as an inequality of the form '+
  	'$$a<x<b$$ or\nl $$a>x>b$$ for appropriate values of a and b. \red{(60%)}';
  part2:='\red{b: } Express the solution in interval form. Separate intervals '+
  	'by commas. \red{(40%)}';
  text1::=header+#13+#13+text+#13+part1+#13+part2+#13;
  buff1:=text+#13+part1+#13+part2+nl;
  prompt::=#133'a: Inequality form:'#134#13+
    	   #133'b: Interval form:'#134;
  help::='\red{Inequalities:}\nl '+
  	'$$a<b$$ => $$a+c<b+c$$\nl '+
	'If c > 0 then $$a<b$$ => $$a\cdot c<b\cdot c$$\nl '+
	'If c < 0 then $$a<b$$ => $$a\cdot c>b\cdot c$$\nl '+
	'If $$a<b$$ and $$c<d$$ then $$a+c<d+c$$\nl\nl '+
	'a\cdot b > 0 => a and b have same sign\nl '+
	'a\cdot b < 0 => a and b have opposite sign\nl\nl '+
	'\red{Interval Notation:}\nl '+
	'(a,b) <=> a < x < b\nl '+
	'[a,b] <=> a \le  x  \le  b\nl '+
	'(a,b] <=> a < x \le  b\nl '+
	'[a,b) <=> a \le  x < b\nl '+
	'In interval notation a is \red{always}  \le  b.';
  text3::=buff1+'\nl\blue{Hint:}\nl '+
  	'Use the basic properties of inequalities to isolate x between two '+
	'inequality signs. Remember to distinguish between including or '+
	'excluding endpoints in interval notation.';
  ans:=#134+a1+#133+
       #134+a2;
  answer::=ans;
  separate(ans,a1,a2);
  solution::='\nl\red{Solution to part a:}\nl '+sol+nl;
  solution2::='\nl\red{Solution to part b:}\nl '+
  	'In interval notation this is '+a2+'.';
  type:='R';
  key:=4225;
end;	   

procedure s4225;
var
 res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
 r:integer;
 check1,check2:boolean;
begin
 message:='';
 res:=response;
 separate(res,r1,r2);
 check1:=false;
 check2:=false;
 r:=0;
 separate(answer,a1,a2);
 check1:=sameinequal(a1,r1);
 check2:=sameintervals(a2,r2);
 if check1 and check2 then begin
   result:='T';
   message::='\green{Correct}';
 end else begin
   if check1 then begin
     r:=r+6;
     message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
   end else begin
     if r1 = '' then begin
       message:=#140'a: Incorrect.'#140+nl;
     end else begin
       message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
     end;
   end;
   if check2 then begin
     r:=r+4;
     message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
   end else begin
     if r2 = '' then begin
       message:=message+#140'b: Incorrect.'#140+nl;
     end else begin
       message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
     end;
   end;
 result:=chr(48+r);
 message:=message+#13+text3;
 end;
end;
procedure p5000;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text:string;
begin
  text1::='\red{Activity 1 - Typing}\nl\nl '+
  	'Use the keys on the keyboard to practice typing. Notice that the '+
  	'left and right arrow keys on the keyboard move the cursor around in '+
	'your text. You can also move the cursor with the mouse by moving '+
	'the arrow to the position you want and then clicking the left mouse '+
	'button. Use the \red{delete}  and \red{backspace}  keys to delete entries. Use the '+
	'\red{Esc}  key to erase all your text.\nl '+
	'After typing some letters and numbers for practice, hit the \red{page down}  key '+
	'to go on to the next activity.\nl ';
  type:='R';
  key:=1;
end;

procedure s5000;
begin
result:='T';
end;

procedure p5001;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text:string;
begin
  text1::='\red{Activity 2 - Buttons}\nl\nl '+
	'Just above where you are reading is a row of "buttons". When a '+
	'button is clicked on with the mouse, a special command is executed. '+
	'For example clicking on the red \red{"stop sign"}  button terminates the '+
	'tutorial or test. Clicking on one of the arrow buttons takes you to '+
	'the previous (up) or next (down) problem or activity. The last group '+
	'of buttons are for entering special characters. Click on the \red{\pi}  '+
	'button and you will see the character \pi  appear. Click on the '+
	'\red{\inf}  button and you will see the character \inf  appear. Such '+
	'special characters can also be entered with special key strokes. For '+
	'example, hit the \red{backslash}  key and you will see \inf  appear. Click on '+
	'the \red{down arrow}  button to go on to the next activity.';  	
  type:='R';
  key:=5001;
end;

procedure s5001;
begin
result:='T';
end;

procedure p5002;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text:string;
begin
  text1::='\red{Activity 3 - More Typing and Grading}\nl\nl '+
  	'Suppose you have worked on a problem and the answer you want '+
	'to give for the problem is the interval (-\inf,4\pi]. '+
  	'Move the cursor below the line and enter your response '+
	'\red{(-\inf,4\pi]}. Notice that the cursor skips the prompt '+
	'below the line. Now you want to grade your response. '+
	'Click on the \red{check}  button to grade your response.\nl ';
  text3::=#13+'\nl\blue{Hint:}\nl '+
  	'If your answer is incorrect, you will be shown a hint about '+
	'doing the problem and told to try again. If your answer is correct, '+
	'you will be told so. To return to the problem, click on the '+
	'\red{quit}  button at the lower right corner of the screen.';
  text5::='If your response was incorrect, you will be given a second chance '+
  	'to work the problem. After entering your new answer, you may grade '+
	'the problem a second time. On a tutorial, if your second answer is '+
	'still incorrect, you will be shown how to work the problem. On a '+
	'test you must return to the problem window and click on the '+
	'\red{down-arrow}  button to go on to the next activity.\nl\nl '+
	'Click on the \red{down-arrow}  button to go on to the next activity.\nl ';
  prompt::=#133'answer:'#134;
  answer::='(-\inf,4\pi]';
  type:='R';
  key:=5002;
end;

procedure s5002;
begin
  replace(prompt,'',response);
  if sameintervals(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141+nl+text3;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
  text1:=text5;
end;

procedure p5003;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text:string;
begin
  text1::='\red{Activity 4 - Exponents}\nl\nl '+
  	'To create an exponent click on the \red{x^{'+#28+'}}  button. '+
	'For example to create x^{2}, first type x, click on the '+
	'\red{x^{'+#28+'}}  button and then type 2. Use either the mouse '+
	'or the \red{right-arrow}  key to return the cursor to the main '+
	'line.\nl\nl '+
	'Now enter the expression $$4x^{3}+2x^{2}-7$$ below the line and '+
	'check your answer.\nl ';
  buff1:=text1;
  text3::='Click on the \red{quit}  button at the lower right corner to return to '+
  	'the problem window.';
  text5::='You are getting the hang of it! Click on the \red{quit}  button at the '+
  	'lower right corner to return to the problem window.';
  prompt::=#133'answer:'#134;
  answer::='$$4x^{3}+2x^{2}-7$$';

  type:='R';
  key:=5003;
end;

procedure s5003;
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141+nl+text5;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
  text1::=buff1+nl+'If your result was incorrect, you may try again. '+
  	'Otherwise click on the '#140'down-arrow'#140'  button to go on '+
	'to the next activity.\nl ';
end;

procedure p5004;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text:string;
begin
  text1::='\red{Activity 5 - Fractions}\nl '+
  	'To create a fraction click on the \red{{'+#28+'\over'+#28+'}}  button. '+
	'For example to create {2\over 3}, first click on the '+
	'\red{{'+#28+'\over'+#28+'}}  button and then type 2. To enter the '+
	'denominator press the \red{down-arrow}  key or move the cursor with '+
	'the mouse. Then type 3. Use either the mouse or the '+
	'\red{right-arrow}  key to return the cursor to the main line.\nl '+
	'Practice by entering the fraction {5\over 6} above the line.\nl '+
	'Now enter the expression $${3x+4\over x^{2}-\pi}$$ below the line and '+
	'check your answer.\nl ';
  buff1:=text1;
  text3::='Click on the \red{quit}  button at the lower right corner to return to '+
  	'the problem window.';
  text5::='See how easy this is. Click on the \red{quit}  button at the '+
  	'lower right corner to return to the problem window.';
  prompt::=#133'answer:'#134;
  answer::='$${3x+4\over x^{2}-\pi}$$';
  type:='R';
  key:=5004;
end;

procedure s5004;
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141+nl+text5;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
  text1::=buff1+'If your result was incorrect, you may try again. '+
  	'Otherwise click on the '#140'down-arrow'#140'  button to go on '+
	'to the next activity.\nl ';
end;

procedure p5005;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text:string;
begin
  text1::='\red{Activity 6 - Square Roots}\nl\nl '+
  	'To create a square root click on the \red{\sqrt{'+#28+'}}  button. '+
	'For example to create \sqrt{3}, first click on the '+
	'\red{\sqrt{'+#28+'}}  button and then type 3. Use either the mouse or the '+
	'\red{right-arrow}  key to move the cursor outside of the radical sign.\nl '+
	'Practice by entering \sqrt{6} above the line.\nl\nl '+
	'Now enter the expression $$\sqrt{{x\over x^{2}+9}}+3\pi$$ below the line and '+
	'check your answer.\nl ';
  buff1:=text1;
  text3::='Click on the \red{quit}  button at the lower right corner to return to '+
  	'the problem window.';
  text5::='You''re becoming an expert. Click on the \red{quit}  button at the '+
  	'lower right corner to return to the problem window.';
  prompt::=#133'answer:'#134;
  answer::='$$\sqrt{{x\over x^{2}+9}}+3\pi$$';
  type:='R';
  key:=5005;
end;

procedure s5005;
begin
  replace(prompt,'',response);
  if sameexpres(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141+nl+text5;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text3
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text3;
  end;
  text1::=buff1+'If your result was incorrect, you may try again. '+
  	'Otherwise click on the '#140'down-arrow'#140'  button to go on '+
	'to the next activity.\nl ';
end;

procedure p5006;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text:string;
begin
  text1::='\red{Activity 7 - Numerical Calculator}\nl\nl '+
  	'To evaluate an expression in decimal form click the '+
	'\red{(\matrix{+&X\cr\div&-})}  button. Enter a numerical expression '+
	'in the calculator and click on the \red{Execute}  button. The '+
	'decimal form of the expression will appear. To return to the problem '+
	'window click on the \red{quit}  button. The result from the calculator '+
	'can be pasted in the problem window by clicking on the word \red{Edit}  '+
	'in the menu above the button bar and then clicking on the expression '+
	'\red{Calc Result}. The result from the calculator will appear at the '+
	'position of the cursor.\nl '+
	'Evaluate $$\sqrt{374+20\pi}$$ in the calculator and then paste the '+
  	'result below the line.\nl ';
  buff1:=text1;
  text4::='Click on the \red{quit}  button at the lower right corner to return to '+
  	'the problem window.';
  text6::='You''re becoming an expert. Click on the \red{quit}  button at the '+
  	'lower right corner to return to the problem window.';
  prompt::=#133'$$\sqrt{374+20\pi}$$ = '#134;
  answer::='$$\sqrt{374+20\pi}$$';
  type:='R';
  key:=5006;
end;

procedure s5006;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) and(pos('.',response)>-1) then begin
    result := 'T';
    message := #141'Correct'#141+nl+text6;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text4
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text4;
  end;
  text1::=buff1+'If your result was incorrect, you may try again. '+
  	'Otherwise click on the '#140'down-arrow'#140'  button to go on '+
	'to the next activity.\nl ';
end;

procedure p5007;
var
  x:paramtype;
  undef,notwff:boolean;
  a1,a2,ans,dgm,text:string;
begin
  str(sqrt(2)+1,a1);
  str(3+2*sqrt(2),a2);
  answer::='('+a1+','+a2+')';
  text1::='\red{Activity 8 - Graphing Calculator}\nl '+
  	'To graph several functions on a single co-ordinate system, click on '+
	'the button to the right of the \red{(\matrix{+&X\cr\div&-})}  button. '+
	'Enter expressions in the variable x separated by commas and then click '+
	'on the \red{Execute}  button. To move the display area, click on one '+
	'of the arrow buttons. To find the co-ordinates of any point in '+
	'the graphic display area, move the arrow to the point you want and click '+
	'with the mouse. The co-ordinates will appear. You can zoom in or out by '+
	'clicking the appropriate zoom button. You can also set the x and y ranges '+
	'of the display area after clicking on the \red{Range}  button.\nl '+
	'Graph the functions x^2 and 2x+1 in the graphing calculator. Estimate '+
	'the point where these curves cross in the first quadrant by clicking '+
	'on the point of intersection. Enter your result below the line.\nl ';
  buff1:=text1;
  text4::='Both co-ordinates must be accurate to 3 decimal places. You can '+
  	'generally get better accuracy by zooming into the point you are '+
	'trying to find. The correct answer is '+answer+'. '+
  	'Click on the \red{quit}  button at the lower right corner to return to '+
  	'the problem window.';
  text6::='You''re becoming an expert. Click on the \red{quit}  button at the '+
  	'lower right corner to return to the problem window.';
  prompt::=#133'(x,y) = '#134;
  type:='R';
  key:=5007;
end;

procedure s5007;
begin
  replace(prompt,'',response);
  if samepoints(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141+nl+text6;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text4
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text4;
  end;
  text1:=buff1+'If your result was incorrect, you may try again. '+
  	'Otherwise click on the '#140'down-arrow'#140'  button to go on '+
	'to the next activity.'+nl;
end;

procedure p5008;
var
  x:paramtype;
  undef,notwff:boolean;
  a1,a2,ans,dgm,text:string;
begin
  x.a:=rand([30..45]);
  answer::='\a';
  text1::='\red{Activity 9 - Help}\nl\nl '+
  	'On tutorials a help window is provided which contains information '+
	'relevant to the problem at hand. Generally, the help window is not '+
	'available during testing. To open the help window click on the word '+
	'\red{Help}  in the menu above the button bar and then click on '+
	'\red{Math Help}. The help window may be expanded to full screen by '+
	'clicking on the button in the upper right hand corner. To close the '+
	'help window, simply click on the \red{Quit}  button.\nl '+
	'Open the help window and enter the result below the line after closing '+
	'the help window.\nl ';
  buff1:=text1;
  help::='The result is \a. Close this window and then enter this number below '+
  	'the line in the problem window.';
  buff1:=text1;
  text4::='Click on the \red{quit}  button at the lower right corner to return to '+
  	'the problem window.';
  text6::='Great. Click on the \red{quit}  button at the '+
  	'lower right corner to return to the problem window.';
  prompt::=#133'number from help screen = '#134;
  type:='R';
  key:=5008;
end;

procedure s5008;
begin
  replace(prompt,'',response);
  if sameconstants(answer,response) then begin
    result := 'T';
    message := #141'Correct'#141+nl+text6;
  end else begin
    result := 'F';
    if response = '' then message:=#140'Incorrect'#140+#13+text4
    else
    message := response+' is '#140'incorrect'#140'. '+#13+text4;
  end;
  text1:=buff1+nl+'When you are finished, click on the '#140'down-arrow'#140 +
  	' button to go on to the next activity.';
end;

procedure p5009;
var
  x:paramtype;
  undef,notwff:boolean;
  a1,a2,ans,dgm,text:string;
begin
  x.a:=rand([30..45]);
  x.b:=x.a-rand([4..8]);
  x.c:=x.a+x.b;
  x.d:=x.a*x.b;
  text1::='\red{Activity 10 - Multi-Response Questions}\nl\nl '+
  	'Some problems have several sub-questions each of which requires a '+
  'response. To receive full credit, all parts should be answered '+
	'before grading the problem for the first time. The percentages '+
	'indicate how much each part is worth.\nl\nl Here is an example of '+
	'a 2-response problem. After entering your responses below the line, '+
	'grade yourself by clicking the \red{Check}  button. You may use '+
	'the calculator if you wish. \nl '+
	'Let a = \a  and b = \b.\nl '+
	'\red{a:}  Determine the sum a + b. (40%)\nl '+
	'\red{b:}  Determine the product a\cdot b. (60%)\nl ';
  buff1::='Let a = \a  and b = \b.\nl '+
	'\red{a:}  Determine the sum a + b. (40%)\nl '+
	'\red{b:}  Determine the product a\cdot b. (60%)\nl ';
  help::='Example: $$3+4=7$$\nl '+
  	'$$3\cdot 4=12$$.';
  text3:=buff1+#13+#13+#142+'Hint:'#142+nl+help;
  prompt::=#133'a: a + b = '#134#13#133'b: a\cdot b = '#134;
  answer:=#134'\c'#133#134'\d\';
  answer::=answer;
  solution::='\nl\red{Solution to part a:}\nl '+
  	'$$a+b=\a+\b=\c$$.\nl ';
  solution2::='\nl\red{Solution to part b:}\nl '+
  	'$$a\cdot b=\a\cdot\b=\d$$.\nl '+
	'Return to the problem window and click on the \red{Down-Arrow}  '+
	'button to go on to the next activity.';
  type:='R';
  key:=5009;
end;

procedure s5009;
var
  res,insrt1,insrt2,mess,res1a,res1b,res2b,res2a,r1,r2,a1,a2,t1,t2:string;
  r:integer;
  check1,check2:boolean;
begin
  message:='';
  res:=response;
  separate(res,r1,r2);
  check1:=false;
  check2:=false;
  r:=0;
  separate(answer,a1,a2);
  check1:=sameconstants(a1,r1);
  check2:=sameconstants(a2,r2);
  if check1 and check2 then begin
    result:='T';
    message::='\green{Correct}';
  end else begin
    if check1 then begin
      r:=r+4;
      message:=#140'a: '#140+r1+' is '#141'correct'#141'.'+nl;
    end else begin
      if r1 = '' then begin
        message:=#140'a: Incorrect.'#140+nl;
      end else begin
        message:=#140'a: '#140+r1+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
    if check2 then begin
      r:=r+6;
      message:=message+#140'b: '#140+r2+' is '#141'correct'#141'.';
    end else begin
      if r2 = '' then begin
        message:=message+#140'b: Incorrect.'#140+nl;
      end else begin
        message:=message+#140'b: '#140+r2+' is '#140'incorrect'#140'.'+nl;
      end;
    end;
  result:=chr(48+r);
  message:=message+#13+text3;
  end;
end;

procedure p5010;
var
  x:paramtype;
  undef,notwff:boolean;
  header,part1,part2,ans1,ans2,dgm,text,tex,w,z:string;
begin
  dgm::=#127'500,500,1200,10;I,250,250,50;E,-2,-2,2,2;R,-3,-3,3,3;B,2;'+
  	'F,2.2,0;L,0,0,2,0;C,.8,.3,2;B,4;C,-.1,-3.5,6;C,3.2,.2,6;'+
	'D,-3,-3.3,-.5,-3.3,5;D,.5,-3.3,3,-3.3,5;D,3.4,-3,3.4,-.3,5;'+
	'D,3.4,1,3.4,3,5;'#127;
  header:='\red{Activity 11 - Multipart Problems}';
  text:='In some cases two or three problems may be linked together in what '+
  	'is called a multi-part problem. In such problems each part must '+
	'either correct or have been graded twice before starting the '+
	'next part. When beginning a latter part of such a question, the '+
	'answers to the earlier parts will be given.'+
	'Here is an example of a two part problem:\nl '+
        '\red{This is Part A of a two part question.}'+nl;
  tex:='A circle of radius 2 is inside a 6 x 6 square.';  
  part1:='\red{Part A:}  Determine the area of the white circle.';
  part2:='\red{Part B:}  Determine the area of the red region.';
  part:='A';
    text1::=dgm+header+#13+#13+text+tex+#13+part1+#13+part2+#13;
    buff1:=dgm+tex+#13+part1+#13+part2;
    prompt::=#133'Part A:\nl Area of white circle = '#134;
    ans1:='4\pi';
    answer::=ans1;
    help::=#127'400,400,700,0;I,100,200,40;E,0,0,4,4;L,2,2,4,2;C,2.8,2.2,r;'#127+
	'\red{Formulas for Circles:}\nl '+ 
	'Area = \pi r^2\nl '+
	'Circumference = 2\pi r';
    text3::=buff1+#13+'\nl\blue{Hint:}\nl '+
    	'The area of a circle is \pi r^{2}.';
    solution::='\nl\red{Solution to Part A:}\nl '+
    	'The area of the circle is $$\pi r^2=\pi\cdot 2^2=4\pi$$.\nl\nl '+
	'Return to the problem window and click on the \red{Down-Arrow}  '+
	'button to go on to part B which is treated as the next problem.';
    type:='R';
    key:=5010;
  eject;
  part:='B';
    header:='\red{This is Part B of a two part question.}';
    text:='Notice how the answer to Part A is now displayed.\nl\nl '+
	'A circle of radius 2 is inside a 6 x 6 square.';  
    text1::=dgm+header+#13+#13+text+#13+part1+#13'\ \ \  Answer:  = '+ans1+#13+part2+#13;
    buff1:=dgm+text+#13+part1+#13'\ \ \  Answer:  = '+ans1+#13+part2;
    prompt::=#133'Part B:\nl Area of red region = '#134;
    ans2:='36-4\pi';
    answer::=ans2;
    help::=#127'400,400,700,0;I,100,200,40;R,0,0,4,4;C,-.5,1.8,x;C,1.9,-.5,x;'#127+
  	'\red{Area of a Square:}\nl '+ 
  	'x^2\nl '+
  	'\red{Perimeter of a Square:}\nl '+ 
  	'4x';
    text3::=buff1+#13+'\nl\blue{Hint:}\nl '+
    	'The area of a b x b square is b^2. Compute the area of the square '+
	'and subtract the area of the circle.';
    solution::='\nl\red{Solution to Part B:}\nl '+
    	'The area of the square is 6\cdot6 = 36.\nl '+
	'Thus the area of the red region is 36 - 4\pi.'+nl+nl+
	'Return to the problem window and click on the \red{Down-Arrow}  '+
	'button to go on to the next activity.';
    type:='R';
    key:=5010;
end;	     

procedure s5010;
var
  res,res1:string;
  undef,notwff:boolean;
  x,y:real;
begin
  if part = 'A' then begin
    if sameconstants(answer,response) then begin
      result := 'T';
      message:=#141'Correct'#141+nl+
      'Return to the problem and click on the '#140'Down-Arrow'#140' button '+
      'to go on to part B which is treated as the next problem.';
    end else begin
      result := 'F';
      replace(prompt,'',response);
      if response = '' then message:=#140'Incorrect '#140+#13+text3
      else message:=response+' is '#140'incorrect'#140'. '+#13+text3;
    end;
  end;
  if part ='B' then begin
    if sameconstants(answer,response) then begin
      result := 'T';
      message:=#141'Correct'#141+nl+
      'Return to the problem window and click on the '#140'Down-Arrow'#140+
      ' button to go on to the next activity.';
    end else begin
      result:='F';
      replace(prompt,'',response);
      if response = '' then message:=#140'Incorrect '#140+#13+text3
      else message:=response+' is '#140'incorrect'#140'. '+#13+text3;
    end;
  end;
end;

procedure p5012;
var
v:valuetype;
a,b,j,k:integer;
header:string;
eqt,gph,ans,sol:array[1..8] of string;
mat:array[1..8] of integer;
begin
  for k:=1 to 5 do mat[k]:=k;
  permute(mat,5);
  header:='\red{Activity 12 - Selective Choice Question}'#13#13;
  text1::=header+'In such a question you will be asked a question about 5 '+
    'different things. Each question can be answered by \red{yes}  or '+
    '\red{no}. Any combination of answers is possible. Here is an example:\nl\nl '+
    'Determine whether each of the following statements is valid '+
    'or not. Click the \red{Y}  button to register a yes. Click the \red{N}  '+
    'button to register a no. '+
    'Click the \red{Check}  button when you are ready to have your response '+
    'graded.';
  eqt[1]:='$$2+3=5$$';ans[1]:='Y';
  eqt[2]:='$$9-5=3$$';ans[2]:='N';
  eqt[3]:='$$5\cdot3=16$$';ans[3]:='N';
  eqt[4]:='15 \div  3 = 5';ans[4]:='Y';
  eqt[5]:='$$2^3=3^2$$';ans[5]:='N';
  text2::=eqt[mat[1]];
  text3::=eqt[mat[2]];
  text4::=eqt[mat[3]];
  text5::=eqt[mat[4]];
  text6::=eqt[mat[5]];
  sol[1]:='2 + 3 does indeed equal 5.'+
  	  '\nl\nl ';
  sol[2]:='9 - 5 does not equal 5. 9 - 5 = 4.'+
  	  '\nl\nl ';
  sol[3]:='5\cdot3 does not equal 16. 5\cdot3 = 15.'+
  	  '\nl\nl ';
  sol[4]:='15\div3 does indeed equal 5.'+
  	  '\nl\nl ';
  sol[5]:='2^3 does not equal 3^2. 2^3 = 8 while 3^2 = 9.'+
  	  '\nl\nl ';
  answer:=ans[mat[1]]+ans[mat[2]]+ans[mat[3]]+ans[mat[4]]+ans[mat[5]];
  solution::='\nl\red{Solution:}'+
  	#12'\red{Choice 1}'+nl+'You got this one \green{right}.'+nl+sol[mat[1]];
  solution2::=#10#12'\red{Choice 2}'+nl+'You got this one \green{right}.'+nl+sol[mat[2]];
  solution3::=#10#12'\red{Choice 3}'+nl+'You got this one \green{right}.'+nl+sol[mat[3]];
  solution4::=#10#12'\red{Choice 4}'+nl+'You got this one \green{right}.'+nl+sol[mat[4]];
  solution5::=#10#12'\red{Choice 5}'+nl+'You got this one \green{right}.'+nl+sol[mat[5]];
  help::='Count on your fingers or use the calculator.';
  type:='S';
  key:=5012;
end;

procedure s5012;
var
  j,n:integer;
  res,w,z:string;
begin
  z:='';
  n := 10;
  for j:=1 to 5 do begin
    if answer[j-1] <> response[j-1] then begin
      z:=z+st(j)+',';
      n := n - 2;
    end;
  end;
  result := chr(48+n);
  if response='     ' then message:=#140'Incorrect'#140#13#142'Message:'#142+buff3
  else begin
    if answer=response then begin
      message:=#141'Correct.'#141+nl+
      'Return to the problem window and click on the '#140'Down Arrow'#140 +
      'button to go on to the next activity.';
    end else begin
      w := '';
      if pos('1',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution) else
         replace(#140'wrong'#140,#141'right'#141,solution);
      if pos('2',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution2) else
         replace(#140'wrong'#140,#141'right'#141,solution2);
      if pos('3',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution3) else
         replace(#140'wrong'#140,#141'right'#141,solution3);
      if pos('4',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution4) else
         replace(#140'wrong'#140,#141'right'#141,solution4);
      if pos('5',z)>-1 then replace(#141'right'#141,#140'wrong'#140,solution5) else
         replace(#140'wrong'#140,#141'right'#141,solution5);
      message:=response+' is '#140'incorrect'#140'.'+#13+#13+
      #142'Hint:'#142#13+'Check your arithmetic. You can use the calculator '+
      'if necessary.';
    end;
  end;
end;

procedure p5013;
var
  x:paramtype;
  undef,notwff:boolean;
  ans,dgm,text:string;
begin
  text1::='\red{Activity 14 - Summing Up}\nl '+
  	'This covers the basics in using the windows testing/tutorial system. '+
	'There are several enhancements which are not essential and have not '+
	'been covered in this orientation - special keystrokes for fractions, '+
	'radicals, etc, highlighting expressions to copy and paste, moving windows '+
	'with the mouse - just to name a few. If you are interested in these '+
	'features you can learn about them during a tutorial session. Specifics '+
	'on such topics can be obtained by opening up the \red{Help}  menu and clicking on '+
	'\red{Help}.\nl '+
	'To conclude a test or tutorial session click on the \red{Red Stop '+
	'Sign}  button. On a tutorial you will be given a summary of your '+
	'work. On a test you can see a summary of your results and your grade '+
	'by clicking on the \red{File}  button and then the '+  
	'\red{Tutorial Results}  button.\nl '+
	'Click on the \red{Red Stop Sign}  button to end this session.\nl ';
  type:='R';
  key:=5013;
end;

procedure s5013;
begin
  message::=#141'Correct'#141+nl+
  	'Return to the problem window and click on the \red{Red Stop Sign}  '+
	'button to end the orientation session.';
  result:='T';
end;








