Context-Sensitive Menu for Calculus 1 problems
by Karen Ranger
This application shows how easy it is to build your own non-standard context-sensitive menu. A context-sensitive menu associates expressions with specific Maple actions. Once an action is selected, not only is the action performed on the expression, but the Maple routine is also displayed to show users the corresponding Maple command. The context-sensitive menu presented in this application provides an interface to several of the routines in the Student[Calculus1] package. Specifically, users will be able to walk through differentiation problems by applying rules, asking for a hint or undoing the previous rule applied.
Definitions
To build a context-sensitive menu, you first need to define a class, called CF_CLASS, which will contain a unique name for the menu, called the Key, a Boolean statement that will test expressions for membership in this class, and an explanation of what the class contains.
Once the class has been defined, you need to define actions. These action, called CF_ACTION, will have the following entries:
MenuString The string that appears in the context-sensitive menu. HelpString The text that appears in the bubble help. CodeType The type of action, such as "complete" or a CF_CODETYPE structure. Code The Maple code that should be used to process the object.
Simple example
Since the output of buildcontext is quite long, end this expression with a colon to suppress the output.
Install the context-sensitive menu.
Let's try our simple menu.
Another example
Right click on the output and select Hint from the menu.
When right clicking on the following expression, notice that the Hint command does not appear. This is because the expression sin(x) fails to pass the Boolean test.
Procedures to reduce the amount of code displayed to users
The following procedures have been created to reduce the amount of code seen by novice users. Now when an option from the context-sensitve menu is selected, users will see
ApplyProductRule(Diff(sin(x)*x,x);
as the Maple input as opposed to
if nops([Student:-Calculus1:-Rule[product](f), Student:-Calculus1:-GetMessage()])=1 then Student:-Calculus1:-Rule[product](f); else op(1, [Student:-Calculus1:-GetMessage()]) end if:
Code for the Calculus 1 menu
The routines to build your own context-sensititve menu are located in the context package
The context-sensitive menu that we are defining here is called CMCalc. In the following example, the unique name for CF_CLASS is "Differentiate". The Boolean statement tests if an expression is in the inert differentiation form. This is required to access the routines from within the Student[Calculus1] package. A second test is performed to verify if a hint can be applied to the problem. This is needed to invoke the context-sensitive menu on expressions that are incomplete while in the single-stepping process. The description for this menu is, "Step through differentiation problems".
- Hint
- Undo
- Chain Rule
- Constant Rule
- Constantmultiple Rule
- Difference Rule
- Identity Rule
- Power Rule
- Product Rule
- Quotient Rule
- Sum Rule
- Sin Rule
- Cos Rule
- Tan Rule
Test Your Example
Now let's ensure that each possible action provides the expected results. The testactions function is used to return a table that indicates the actual command generated for each action. In particular, the command testactions[defaultcontext](e) tests against the original system default context menu.
Note: The interactive command is the last routine tested in when invoking testactions therefore the interactive maplet should appear.
### Menu -> "System_Math Functions"
"x" = ["R0 := diff(Diff(sin(x)*x,x),x);"]
"x" = ["R1 := int(Diff(sin(x)*x,x),x);"]
"Evaluate" = ["R2 := value(Diff(sin(x)*x,x));"]
"Real Part" = ["R3 := Re(Diff(sin(x)*x,x));"]
"Imaginary Part" = ["R4 := Im(Diff(sin(x)*x,x));"]
"Absolute Value" = ["R5 := abs(Diff(sin(x)*x,x));"]
"Argument" = ["R6 := argument(Diff(sin(x)*x,x));"]
"Conjugate" = ["R7 := conjugate(Diff(sin(x)*x,x));"]
"Truncate" = ["R8 := trunc(Diff(sin(x)*x,x));"]
"Round" = ["R9 := round(Diff(sin(x)*x,x));"]
"Fractional Part" = ["R10 := frac(Diff(sin(x)*x,x));"]
"Floor" = ["R11 := floor(Diff(sin(x)*x,x));"]
"Ceiling" = ["R12 := ceil(Diff(sin(x)*x,x));"]
"Assuming Real" = ["R13 := simplify(Diff(sin(x)*x,x),'assume = real');"]
"Assuming Positive" = ["R14 := simplify(Diff(sin(x)*x,x),'assume = positive');"]
"Assuming Non-negative" = ["R15 := simplify(Diff(sin(x)*x,x),'assume = nonnegative');"]
"Size" = ["R16 := simplify(Diff(sin(x)*x,x),'size');"]
"Symbolic" = ["R17 := simplify(Diff(sin(x)*x,x),'symbolic');"]
"Maple" = ["R18 := sprintf(\"%a\",Diff(sin(x)*x,x));"]
"LaTeX" = ["latex(Diff(sin(x)*x,x));"]
"MathML" = ["R19 := MathML['Export'](Diff(sin(x)*x,x));"]
"C Language" = ["R20 := CodeGeneration['C'](Diff(sin(x)*x,x),'optimize');"]
"Fortran" = ["R21 := CodeGeneration['Fortran'](Diff(sin(x)*x,x),'optimize');"]
"Java" = ["R22 := CodeGeneration['Java'](Diff(sin(x)*x,x),'optimize');"]
Initializing Java runtime environment.
"Plot Builder" = [[`ERROR: `, "insufficient parameters for algebraic format"]]
### Menu <-
Now let's test our menu
### Menu -> "Differentiate"
"Hint" = ["R23 := Student:-Calculus1:-Hint(Diff(sin(x)*x,x));"]
"Undo" = ["R24 := Student:-Calculus1:-Undo(Diff(sin(x)*x,x));"]
"Chain Rule" = ["R25 := ApplyChainRule(Diff(sin(x)*x,x));"]
"Constant Rule" = ["R26 := ApplyConstantRule(Diff(sin(x)*x,x));"]
"Constantmultiple Rule" = ["R27 := ApplyConstantMultipleRule(Diff(sin(x)*x,x));"]
"Difference Rule" = ["R28 := ApplyDifferenceRule(Diff(sin(x)*x,x));"]
"Identity Rule" = ["R29 := ApplyIdentityRule(Diff(sin(x)*x,x));"]
"Power Rule" = ["R30 := ApplyPowerRule(Diff(sin(x)*x,x));"]
"Product Rule" = ["R31 := ApplyProductRule(Diff(sin(x)*x,x));"]
"Quotient Rule" = ["R32 := ApplyQuotientRule(Diff(sin(x)*x,x));"]
"Sum Rule" = ["R33 := ApplySumRule(Diff(sin(x)*x,x));"]
"Sin Rule" = ["R34 := ApplySinRule(Diff(sin(x)*x,x));"]
"Cos Rule" = ["R35 := ApplyCosRule(Diff(sin(x)*x,x));"]
"Tan Rule" = ["R36 := ApplyTanRule(Diff(sin(x)*x,x));"]
Let's try it out. Right click on the output and select from the menu. Do this until you have walked through each stage of this problem.
Restore Default
CM will remain as the context menu system until the end of the session, or until installcontext is called with a new recognizer, or until the default configuration is recalled through the restoredefault . The syntax is simply:
The Maple restoredefault function is similar to restart in a worksheet.
The Default Configuration File
The default context-generating procedure is constructed from the configuration as illustrated on Maple's context worksheet . This configuration can be edited and reinstalled in the manner described previously.
For more information or to see the advanced options available in the context package, visit Maple's Help page by entering ?context at the Maple prompt.