NAME

parserLogb.pl - defines a logb(b, x) function for the logarithm with base b evaluated at x.

DESCRIPTION

This file defines the code necessary to add to any context a logb(b, x) function that evaluates the logarithm with base b at x. For example, Compute("logb(3, 5)") would return the equivalent of Compute("log(5)/log(3)" although it will be displayed as a logarithm with base b.

To accomplish this, put the line

loadMacros("parserLogb.pl");

at the beginning of your problem file, then set the Context to the one you wish to use in the problem. Then use the command:

Parser::Logb->Enable;

(You can also pass the Enable command a pointer to a context if you wish to alter a context other than the current one.)

Once that is done, you (and students) can enter logarithms with base b by using the logb() function. You can use logb() both within Formula() and Compute() calls, and in Perl expressions, such as

$ans = Compute("logb(3, 5)";
$n   = logb(3, 5);

to obtain the logarithm with base b. Note that by default logb() will produce an error message for logarithms evaluated at zero or negative numbers or if the base is zero or negative.

However, if you enable logb() in a context that allows complex numbers, you may want to allow logarithms of negative numbers or with negative bases. To do this, use

Parser::Logb->EnableComplex;

(again, you can pass a context to be altered, if you wish). This will force logarithms of negative values or with negative bases to be promoted to complex numbers. So

Parser::Logb->EnableComplex;
$z = logb(3, -9);
$y = logb(-3, 9);

would produce the equivalent of $z = Compute("log(-9)/log(3)"); and $y = Compute("log(9)/log(-3)"); except that they will be displayed as logarithms with base 3 or -3 respectively.

Note that if MathQuill is enabled, then students will be able to enter the logarithm with base b evaluated at x by typing log_b(x). To facilitate students entering such answers, a subscript button is present in the MathQuill toolbar for answers with the logb function enabled.