WeBWorK Main Forum

Adjusting definition of inverse secant function

Adjusting definition of inverse secant function

by Sean Fitzpatrick -
Number of replies: 9
I came across what I thought was a good problem for the derivative of the inverse secant function, but ran into an issue: the code (provided below) uses the built-in derivative operation instead of specifying a formula for the derivative, and the definition of the inverse secant function does not match the one we use.

If you take the "trig-friendly" definition that maps negative inputs to second quadrant angles, the derivative involves an absolute value.
If you take the "calculus-friendly" definition, with negative inputs mapped to the third quadrant, the absolute value disappears.

WeBWorK seems to use the first definition, while we use the second, so students won't know that they have to put the absolute value in. I was able to work around this by simply hard-coding the answer instead of using the built-in derivative calculator, but I was curious if there's somewhere that we can choose between the two definitions of the inverse secant function.

## DESCRIPTION
## Calculus
## ENDDESCRIPTION

## Tagged by tda2d

## DBsubject(Calculus - single variable)
## DBchapter(Differentiation)
## DBsection(Derivatives of inverse trigonometric functions)
## Date(8/23/07)
## Institution(Union College)
## MLT(DerivInvTrig-FuncOfConstMult)
## MLTleader(1)
## Level(2)
## MO(1)
## TitleText1('Calculus: Early Transcendentals')
## AuthorText1('Rogawski')
## EditionText1('1')
## Section1('3.9')
## Problem1('25')
## KEYWORDS('derivative' 'inverse trig')


DOCUMENT(); # This should be the first executable line in the problem.

loadMacros(
"PGstandard.pl",
"PGunion.pl", # Union College utilities
"MathObjects.pl",
"PGcourse.pl", # Customization file for the course
);

TEXT(beginproblem());

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

$a = random(2,8,1);
$b = random(2,8,1);
$point = random(1,5,1);

$f=Formula("$b arcsec($a x)");

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

Context()->texStrings;
BEGIN_TEXT
Let \( f(x) = \displaystyle $f \). Find \(f'(x)\).
$PAR
\(f'(x) =\) \{ans_rule(50) \}
$PAR
Find \( f'( $point ) \).
$PAR
\( f'( $point ) = \)\{ans_rule(50) \}
END_TEXT
Context()->normalStrings;

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

$showPartialCorrectAnswers = 1;

$fprime=$f->D('x');
$fprimeatpoint=Real($fprime->eval(x=>$point));

ANS($fprime->with(limits => [-2,-1], tolerance => .001)->cmp);
ANS($fprimeatpoint->cmp);

###################################

;
ENDDOCUMENT();

In reply to Sean Fitzpatrick

Re: Adjusting definition of inverse secant function

by Davide Cervone -
OK, I've made a macro file that you can use to implement your alternative version of the inverse secant. The file is attached.

To use it, put the file in your courses templates/macros folder, and create another file in the same folder, and name it parserCustomization.pl. That file should contain:

loadMacros("parserAltSecant.pl");
$main::context{Numeric} = parser::AltSecant::Enable(Parser::Context->getCopy("Numeric"));
Context("Numeric");
This will load the alternative secant definition, make a copy of the Numeric context, and modify it to use the alternative secant. It also sets things up so that if a problem file does
Context("Numeric");
it will get your modified copy, so your modifications will not be lost. The parserCustomization.pl file is loaded whenever MathObjects.pl, so that should make it work for all problems using MathObjects (which are the only ones that have automatic differentiation anyway).
In reply to Davide Cervone

Re: Adjusting definition of inverse secant function

by Arnold Pizer -
Thanks Davide.

At some point how difficult would it be to implement this similar to the way pg{ansEvalDefaults}{useBaseTenLog} works? Otherwise this solution might get overlooked in the future.

Arnie

In reply to Arnold Pizer

Re: Adjusting definition of inverse secant function

by Davide Cervone -
That should not be hard to do, and is a good idea. Are there any other choices like that that need to be considered for other functions?
In reply to Davide Cervone

Re: Adjusting definition of inverse secant function

by Louis Zulli -
Hi Davide,

Not really familiar with the Complex class or WeBWorK's handling of branch cuts, but I see the following:

arg($c) or $c->arg Returns the argument of $c (i.e., the angle in radians counterclockwise from the x" role="presentation" style="display: inline; line-height: normal; font-size: 12.7px; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">x-axis) as a Real MathObject

Often the branch cut is placed on the negative real axis, with -pi < Arg < pi. In theory, the choice made with Arg should also be reflected in the calculation of roots and logarithms, where principal values should be derived from the principal argument. But again, I haven't investigated how the common functions handle complex arguments.

Louis
In reply to Louis Zulli

Re: Adjusting definition of inverse secant function

by Davide Cervone -
Hi Louis:

The arg() function uses perl's atan2() function internally, and so the results are in the range -pi to pi, as you indicate. And yes, logs and roots use arg() internally, so they use that same branch cut.

I suppose it would be possible to make a configuration parameter for the branch cut (say by specifying an angle, theta), and make arg() return values between theta and theta+2pi. Would that be sufficient?
In reply to Davide Cervone

Re: Adjusting definition of inverse secant function

by Louis Zulli -
Hi Davide,

I am not sure that any change is necessary. When you asked about other functions for which domain choices matter, the issue of branch cuts for arg came to mind. If the angle at which the cut is made were configurable, one would presumably want the various root functions and the log to use that angle too. Might be more trouble than it's worth.

Louis
In reply to Louis Zulli

Re: Adjusting definition of inverse secant function

by Davide Cervone -
Sorry, I tried to say that since log() and roots use arg() internally, the branch cut used for arg() would carry over to them as well. So one configuration would be sufficient, and not all that hard.
In reply to Davide Cervone

Re: Adjusting definition of inverse secant function

by Louis Zulli -
Davide,

No need to apologize. I see now that you said it very clearly. It was I who read poorly.

In that case, it seems like it might be useful to have a configurable "branch cut angle" theta, so that arg returns a value in the interval ( theta, theta + 2 pi ] (or something similar).

Louis
In reply to Davide Cervone

Re: Adjusting definition of inverse secant function

by Sean Fitzpatrick -
Thank you!
This is perfect. I'll make this customization available to our faculty teaching calculus -- I think everyone here follows this convention. (None of us teach from Stewart's Calculus any more because of the price, but all of us have learned/taught from his books in the past, and it's the definition used there.)

I agree it would be great if this made it into the official version as an option.