(*******************************************************************
This file was generated automatically by the Mathematica front end.
It contains Initialization cells from a Notebook file, which
typically will have the same name as this file except ending in
".nb" instead of ".m".

This file is intended to be loaded into the Mathematica kernel using
the package loading commands Get or Needs.  Doing so is equivalent
to using the Evaluate Initialization Cells menu command in the front
end.

DO NOT EDIT THIS FILE.  This entire file is regenerated
automatically each time the parent Notebook file is saved in the
Mathematica front end.  Any changes you make to this file will be
overwritten.
***********************************************************************)



Needs["Graphics`"]
Needs["Calculus`"]





wasSpellCheckOn=Head[General::spell1]=!=$Off;

Off[General::spell1]

Clear[d];



WalkD::usage = \
"WalkD[expression, x] prints each of the steps in finding the derivative of the expression with respect to x, using d to represent differentiation. It prints the differentiation rule that is used at each step. The function outputs D[f, x].";\
 

RunD::usage = \
"RunD[expression, x] prints each of the steps in finding the derivative of the expression with respect to x, using d to represent differentiation. The function outputs D[f, x].";\
 



\!\(\(SpecificRules = {d[x_, x_] \[RuleDelayed] 1, d[f_[x_], x_] \[RuleDelayed] \[PartialD]\_x f[x], d[a_\^x_, x_] \[RuleDelayed] \[PartialD]\_x a\^x /; FreeQ[a, x]};\)\)

ConstantRule=d[c_,x_]\[RuleDelayed]0/;FreeQ[c,x];

LinearityRule={d[f_+g_,x_]\[RuleDelayed]d[f,x]+d[g,x],
      d[c_ f_,x_]\[RuleDelayed]c d[f,x]/;FreeQ[c,x]};



\!\(\(PowerRule = {d[x_, x_] \[RuleDelayed] 1, d[x_\^a_, x_] \[RuleDelayed] a\ x\^\(a - 1\) /; FreeQ[a, x]};\)\)

ProductRule=d[f_ g_,x_]\[RuleDelayed]d[f,x] g+f d[g,x];

\!\(\(QuotientRule = d[f_\/g_, x_] \[RuleDelayed] \(d[f, x]\ g - f\ d[g, x]\)\/g\^2;\)\)

\!\(\*
  RowBox[{
    RowBox[{"InverseFunctionRule", "=", 
      RowBox[{
        RowBox[{"d", "[", 
          RowBox[{
            RowBox[{
              TagBox[\(f\^\((\(-1\))\)\),
                InverseFunction,
                Editable->False], "[", "x", "]"}], ",", "x"}], "]"}], "\[RuleDelayed]", 
        FractionBox["1", 
          RowBox[{
            SuperscriptBox["f", "\[Prime]",
              MultilineFunction->None], "[", 
            RowBox[{
              TagBox[\(f\^\((\(-1\))\)\),
                InverseFunction,
                Editable->False], "[", "x", "]"}], "]"}]]}]}], ";"}]\)

\!\(\(ChainRule = {d[f_\^a_, x_] \[RuleDelayed] a\ f\^\(a - 1\)\ d[f, x] /; FreeQ[a, x], d[a_\^f_, x_] \[RuleDelayed] Log[a]\ a\^f\ d[f, x] /; FreeQ[a, x], d[f_[g_], x_] \[RuleDelayed] \((\[PartialD]\_x f[x] /. x \[Rule] g)\)\ d[g, x], d[f_\^g_, x_] \[RuleDelayed] f\^g\ d[g\ Log[f], x]};\)\)

RuleNames={
		"SpecificRules",
		"ConstantRule",
		"LinearityRule",
		"PowerRule",
		"ProductRule",
		"QuotientRule",
		"InverseFunctionRule",
		"ChainRule"
			};



GeneralRules=Flatten[ToExpression[Drop[RuleNames,1]]];



AllRules=Flatten[ToExpression[RotateLeft[RuleNames]]];



ListRules = ToExpression[RuleNames];

PrintRules := CellPrint[Cell[BoxData[GridBox[Transpose[{
	Prepend[{"GeneralRules ="<>#1, ##2}& @@ 
                    Map["\[AlignmentMarker]"<> #&,RuleNames],
						 "AllRules     =\[AlignmentMarker] SpecificRules + GeneralRules"]}],
	ColumnAlignments\[Rule]"\[AlignmentMarker]",
	RowSpacings\[Rule]{2,0.8}]], "Output"]];

\!\(WalkD[f_, x_] := Module[{derivative}, derivative = d[f, x]; \n\t\tdisplayStart[derivative]; \n\t\tWhile[\[InvisibleSpace]\(! \((FreeQ[derivative, d])\)\), \n\t\t\toldderivative = derivative; k = 0; \n\t\t\tWhile[oldderivative == derivative, \n\t\t\t\t\(k++\); \n\t\t\t\tderivative = derivative /. ListRules\[LeftDoubleBracket]k\[RightDoubleBracket]]; displayRuleUsed[RuleNames\[LeftDoubleBracket]k\[RightDoubleBracket]]; \n\t\t\tdisplayDerivative[derivative]]; \n\t\t\[PartialD]\_x f]\)

\!\(RunD[f_, x_] := Module[{derivative}, \n\t\tderivative = d[f, x]; \n\t\tdisplayStart[derivative]; While[\(\(\[InvisibleSpace]\)\(! \((FreeQ[derivative, d])\)\)\), derivative = derivative /. AllRules; \n\t\t\tdisplayDerivative[derivative]]; \[PartialD]\_x f]\)

displayStart[expr_] :=
	StylePrint[expr,"Output",
			CellFrame\[Rule]{{0,0},{0,3}},
			Background \[Rule]RGBColor[0.8, 1., 0.8],
			CellGroupingRules\[Rule]"OutputGrouping",
			CellMargins \[Rule] {{Inherited, Inherited},{0,Inherited}},
		CellEditDuplicate\[Rule]False,
		FontWeight\[Rule]Bold]

displayRuleUsed[expr_String] :=
	CellPrint[Cell[BoxData[expr], "Output",
			Background \[Rule]RGBColor[0.8, 1., 0.8], 
      FontColor \[Rule] RGBColor[0.6, 0, 0.6],
			FontSlant \[Rule] "Italic",
			  CellFrame\[Rule] False,
				CellMargins\[Rule]{{Inherited,Inherited},{0,0}},
      CellFrameMargins \[Rule] {{100, Inherited},{0, 0}},
		CellEditDuplicate\[Rule]False,
		FontWeight\[Rule]Bold]]

displayDerivative[expr_]:=
	
  CellPrint[
    Cell[BoxData[
        RowBox[{InterpretationBox["=",Sequence[]],"    ",
            MakeBoxes[expr, StandardForm] }]], "Output",
			Background \[Rule]RGBColor[0.8, 1., 0.8], Evaluatable \[Rule]False,
				CellMargins\[Rule]{{Inherited,Inherited},{0,0}},CellFrame\[Rule]False,
		CellEditDuplicate\[Rule]False,
		FontWeight\[Rule]Bold]]

If[wasSpellCheckOn,On[General::spell1]]



















