## DESCRIPTION
## Differential calculus: difference quotients
## ENDDESCRIPTION

## KEYWORDS('differential calculus', 'difference quotients')

## DBsubject('WeBWorK')
## DBchapter('WeBWorK Tutorial')
## DBsection('Fort Lewis Tutorial 2011')
## Date('01/30/2011')
## Author('Paul Pearson')
## Institution('Fort Lewis College')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')


##############################
#  Initialization

DOCUMENT(); 

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"unionLists.pl",
);

TEXT(beginproblem());


#############################
#  Setup

Context("Numeric")->variables->add(k=>"Real");
Context()->flags->set(
  reduceConstants=>0, # no decimals
  reduceConstantFunctions=>1, # combine 4+5*2?
  formatStudentAnswer=>'parsed', # no decimals
);

$a = random(6,9,1);
$k = random(3,5,1);

$f = Formula("k x^2");
$fx = $f->D('x');

@answer = ();
$answer[0] = $fx;

$answer[1] = $fx->substitute(k=>$k); # formula
# $answer[1] = $fx->eval(k=>$k); # gives errors, must eval to real

$answer[2] = $fx->substitute(x=>$a*pi,k=>$k); # formula
#$answer[2] = $fx->eval(x=>$a*pi,k=>$k); # real


#############################
#  Main text

Context()->texStrings;
BEGIN_TEXT
Suppose \( f(x) = $f \) where \( k \) is a 
constant.
\{ BeginList("OL",type=>"a") \}

$ITEM \( f'(x) = \) 
\{ ans_rule(20) \}
\{ AnswerFormatHelp("formulas") \}

$ITEMSEP
$ITEM If \( k = $k \) then \( f'(x) = \)
\{ ans_rule(20) \}
\{ AnswerFormatHelp("formulas") \}

$ITEMSEP
$ITEM If \( k = $k \) then \( f'($a\pi) = \)
\{ ans_rule(20) \}
\{ AnswerFormatHelp("formulas") \}

\{ EndList("OL") \}
END_TEXT
Context()->normalStrings;


############################
#  Answers

$showPartialCorrectAnswers = 1;

foreach my $i (0..2) {
  ANS( $answer[$i]->cmp() );
}

############################
#  Solution

Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT("MathObject version.");

ENDDOCUMENT();





###########################
#  Initialization


DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserDifferenceQuotient.pl",
);

TEXT(beginproblem());


###########################
#  Setup

Context("Numeric");

$limit = DifferenceQuotient("2*x+h","h");

$fp = Compute("2 x");


###########################
#  Main text

Context()->texStrings;
BEGIN_TEXT
Simplify and then evaluate the limit.
$BR
$BR
\( \displaystyle 
\frac{d}{dx} \big( x^2 \big) 
=
\lim_{h \to 0} \frac{(x+h)^2-x^2}{h} 
= 
\lim_{h \to 0} 
\big(
\)
\{ ans_rule(15) \}
\( \big) = \)
\{ ans_rule(15) \}
END_TEXT
Context()->normalStrings;


############################
#  Answer evaluation

$showPartialCorrectAnswers = 1;

ANS( $limit->cmp() );
ANS( $fp->cmp() );


############################
#  Solution

Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();