Forum archive 2000-2006

Mark Schmitt - Factorials, Combinations, and Permuations

Mark Schmitt - Factorials, Combinations, and Permuations

by Arnold Pizer -
Number of replies: 0
inactiveTopicFactorials, Combinations, and Permuations topic started 5/9/2001; 11:18:44 AM
last post 5/10/2001; 2:37:27 PM
userMark Schmitt - Factorials, Combinations, and Permuations  blueArrow
5/9/2001; 11:18:44 AM (reads: 2606, responses: 5)
Does WeBWorK have any scripts to deal with computing factorials, combinations, and permutations? If so, where can I find documentation. I'm working on a problem set for the Binomial Theorem, and those functions would be very helpful. Thanks.

Mark

<| Post or View Comments |>


userMichael Gage - Re: Factorials, Combinations, and Permuations  blueArrow
5/10/2001; 9:24:07 AM (reads: 2764, responses: 0)
Hi Mark,

I don't believe that these functions have been defined. Look through the file PGauxiliaryFunctions.pl (in courseScripts directory) to see how similar functions have been defined. You can add combinatorial functions to that file if you wish (and send them to us if you would like them included in the general distribution) or, for more esoteric functions you can put them in a file such as "myEsotericFunctions.pl", place it either in the .../templates/macros/ directory of your course or in the system/courseScripts directory of webwork, and call the file from your problem:

 

....
loadMacros(
....
"myEsotericFunctions.pl",
.....,
);





......

(If you place macro files in the ../templates/macros directory, make sure that the definition of $macroDirectory in the file webworkCourse.ph has been UNcommented. )

-- Mike

<| Post or View Comments |>


userMichael Gage - Re: Factorials, Combinations, and Permuations  blueArrow
5/10/2001; 9:43:37 AM (reads: 2764, responses: 0)
Hi Mark,

I don't believe that these functions have been defined. Look through the file PGauxiliaryFunctions.pl (in courseScripts directory) to see how similar functions have been defined. You can add combinatorial functions to that file if you wish (and send them to us if you would like them included in the general distribution) or, for more esoteric functions you can put them in a file such as "myEsotericFunctions.pl", place it either in the .../templates/macros/ directory of your course or in the system/courseScripts directory of webwork, and call the file from your problem:

 

....
loadMacros(
....
"myEsotericFunctions.pl",
.....,
);





......

(If you place macro files in the ../templates/macros directory, make sure that the definition of $macroDirectory in the file webworkCourse.ph has been UNcommented. )

-- Mike

<| Post or View Comments |>


userArnold K. Pizer - Re: Factorials, Combinations, and Permuations  blueArrow
5/10/2001; 11:49:26 AM (reads: 2832, responses: 0)
Hi Mark,

If you also want students to be able to use your new function(s), you have to make additional changes to AlgParser.pm . This is a tiny bit technical --- let us know if this is what you have in mind. If all you want is to be able to use your new functions when writing problems, Mike's instructions suffice.

Arnie

<| Post or View Comments |>


userMark Schmitt - Re: Factorials, Combinations, and Permuations  blueArrow
5/10/2001; 1:51:35 PM (reads: 2841, responses: 0)
Thanks for the help. I just wrote some macros that appear to work nicely. The code is below. I added them to a file called PGprobabilityFunctions.pl so that they will be available when necessary, but not otherwise. I don't claim it's the most efficient code, but it works.

I would like to be able to have students type in fact(n) or Perm(n,k) or Comb(n,k) and have WeBWorK recognize it. If you could help walk me through editing AlgParser.pm, I would appreciate it. Thanks again for all the help.

Mark

 

 



sub fact {
$s=1; for ($i=2;$i<=$_[0];$i++) {$s*=$i;} return $s;
}



sub Perm {
my $n = $_[0];
my $k = $_[1];
my $ans = fact($n)/(fact($n-$k));
return $ans;
}



sub Comb {
my $n = $_[0];
my $k = $_[1];
my $ans = Perm($n,$k)/fact($k);
return $ans;
}

<| Post or View Comments |>


userArnold K. Pizer - Re: Factorials, Combinations, and Permuations  blueArrow
5/10/2001; 2:37:27 PM (reads: 2919, responses: 0)
Hi Mark,

First, we can not yet handle functions of two variables such as Perm(5,4). This is something we want to be able to handle, but it will require more extensive changes to AlgParser.pm than we want to attempt quickly. We may want to ask the original author of AlgParser.pm, Dan Martin, for help with this. For example, at this point, a coma "," is an illegal character in a student's answer.

If you want students to be able to use thje function "fact", all you need to do is to edit AlgParser.pm in two places. The easiest thing to do is to search for "logten" in AlgParser.pm, and add "fact" to the list of functions you will find in those two places.

Arnie

<| Post or View Comments |>