Parent Directory
|
Revision Log
Movified the copying of functions from Complex1:: into main:: to avoid
conflicts with the PGcommonFunctions.pl versions (these errors were
trapped, but still show up in the error log unnecessarily).
Also commented out some code that was not doing anything other than
producing error messages in the error log. (It was left over from a
syntax check on the professor's answer, but the actual check was
removed, leaving a portion that tries to process the answer, but
usually fails (because things like "1+4i" need to be converted to
"1+4*i" before they can be used in PG_answer_eval, but that was not
being done).
Because of this, it is not possible currently to do cplx_cmp("1+4i"),
and instead you must to cplx_cmp(new Complex(1,4)).
To fix this, you would need to call check_syntax (and the other
filters that are called on the student's answer) before calling
PG_answer_eval. Of course, you should only do this when the
professor's answer isn't already a Complex object.
I am going to work on a Legacy module like the ones for num_cmp and
fun_cmp to replace cplx_cmp, which should avoid these problems and
make the changes suggested above unnecessary.
1 ############################################## 2 # 3 # Implements functions that are common to 4 # the new Parser.pm and the old PGauxiliaryFunctions.pl 5 # 6 7 sub _PGcommonFunctions_init {} 8 9 # 10 # Make these interact nicely with Parser.pm 11 # 12 package CommonFunction; 13 14 # 15 # Either call Parser (if it has been loaded) or 16 # the functions below. (If it's ever the case 17 # that both the Parser and PGauxiliaryFunctions.pl are 18 # both preloaded, then there will be no need for 19 # this, as you can always use the Parser versions. 20 # We only need this because Parser might not be loaded.) 21 # 22 23 sub Call { 24 my $self = shift; 25 my $fn = shift; 26 if ($main::_parser_loaded) { 27 return Parser::Function->call($fn,@_) 28 if Parser::Context->current->{functions}{$fn}; 29 } 30 return &{$CommonFunction::function{$fn}}(@_) if $CommonFunction::function{$fn}; 31 return $self->$fn(@_); 32 } 33 34 sub log {CORE::log($_[1])} 35 sub ln {CORE::log($_[1])} 36 sub logten {CORE::log($_[1])/CORE::log(10)} 37 38 sub tan {CORE::sin($_[1])/CORE::cos($_[1])} 39 sub cot {CORE::cos($_[1])/CORE::sin($_[1])} 40 sub sec {1/CORE::cos($_[1])} 41 sub csc {1/CORE::sin($_[1])} 42 43 sub asin {CORE::atan2($_[1],CORE::sqrt(1-$_[1]*$_[1]))} 44 sub acos {CORE::atan2(CORE::sqrt(1-$_[1]*$_[1]),$_[1])} 45 sub atan {CORE::atan2($_[1],1)} 46 sub acot {CORE::atan2(1,$_[1])} 47 sub asec {acos($_[0],1.0/$_[1])} 48 sub acsc {asin($_[0],1.0/$_[1])} 49 50 sub sinh {(CORE::exp($_[1])-CORE::exp(-$_[1]))/2} 51 sub cosh {(CORE::CORE::exp($_[1])+CORE::CORE::exp(-$_[1]))/2} 52 sub tanh {(CORE::exp($_[1])-CORE::exp(-$_[1]))/(CORE::exp($_[1])+CORE::exp(-$_[1]))} 53 sub sech {2/(CORE::exp($_[1])+CORE::exp(-$_[1]))} 54 sub csch {2.0/(CORE::exp($_[1])-CORE::exp(-$_[1]))} 55 sub coth {(CORE::exp($_[1])+CORE::exp(-$_[1]))/(CORE::exp($_[1])-CORE::exp(-$_[1]))} 56 57 sub asinh {CORE::log($_[1]+CORE::sqrt($_[1]*$_[1]+1.0))} 58 sub acosh {CORE::log($_[1]+CORE::sqrt($_[1]*$_[1]-1.0))} 59 sub atanh {CORE::log((1.0+$_[1])/(1.0-$_[1]))/2.0} 60 sub asech {CORE::log((1.0+CORE::sqrt(1-$_[1]*$_[1]))/$_[1])} 61 sub acsch {CORE::log((1.0+CORE::sqrt(1+$_[1]*$_[1]))/$_[1])} 62 sub acoth {CORE::log(($_[1]+1.0)/($_[1]-1.0))/2.0} 63 64 sub sgn {$_[1] <=> 0} 65 66 sub C { 67 shift; my ($n,$r) = @_; my $C = 1; 68 return(0) if ($r>$n); 69 $r = $n-$r if ($r > $n-$r); # find the smaller of the two 70 for (1..$r) {$C = ($C*($n-$_+1))/$_} 71 return $C; 72 } 73 74 sub P { 75 shift; my ($n,$r) = @_; my $P = 1; 76 return(0) if ($r>$n); 77 for (1..$r) {$P *= ($n-$_+1)} 78 return $P; 79 } 80 81 82 # 83 # Back to main package 84 # 85 package main; 86 87 # 88 # Make main versions call the checker to see 89 # which package-specific version to call 90 # 91 92 sub ln {CommonFunction->Call('log',@_)} 93 sub logten {CommonFunction->Call('logten',@_)} 94 95 sub tan {CommonFunction->Call('tan',@_)} 96 sub cot {CommonFunction->Call('cot',@_)} 97 sub sec {CommonFunction->Call('sec',@_)} 98 sub csc {CommonFunction->Call('csc',@_)} 99 100 sub arcsin {CommonFunction->Call('asin',@_)}; sub asin {CommonFunction->Call('asin',@_)} 101 sub arccos {CommonFunction->Call('acos',@_)}; sub acos {CommonFunction->Call('acos',@_)} 102 sub arctan {CommonFunction->Call('atan',@_)}; sub atan {CommonFunction->Call('atan',@_)} 103 sub arccot {CommonFunction->Call('acot',@_)}; sub acot {CommonFunction->Call('acot',@_)} 104 sub arcsec {CommonFunction->Call('asec',@_)}; sub asec {CommonFunction->Call('asec',@_)} 105 sub arccsc {CommonFunction->Call('acsc',@_)}; sub acsc {CommonFunction->Call('acsc',@_)} 106 107 sub sinh {CommonFunction->Call('sinh',@_)} 108 sub cosh {CommonFunction->Call('cosh',@_)} 109 sub tanh {CommonFunction->Call('tanh',@_)} 110 sub sech {CommonFunction->Call('sech',@_)} 111 sub csch {CommonFunction->Call('csch',@_)} 112 sub coth {CommonFunction->Call('coth',@_)} 113 114 sub arcsinh {CommonFunction->Call('asinh',@_)}; sub asinh {CommonFunction->Call('asinh',@_)} 115 sub arccosh {CommonFunction->Call('acosh',@_)}; sub acosh {CommonFunction->Call('acosh',@_)} 116 sub arctanh {CommonFunction->Call('atanh',@_)}; sub atanh {CommonFunction->Call('atanh',@_)} 117 sub arcsech {CommonFunction->Call('asech',@_)}; sub asech {CommonFunction->Call('asech',@_)} 118 sub arccsch {CommonFunction->Call('acsch',@_)}; sub acsch {CommonFunction->Call('acsch',@_)} 119 sub arccoth {CommonFunction->Call('acoth',@_)}; sub acoth {CommonFunction->Call('acoth',@_)} 120 121 sub sgn {CommonFunction->Call('sgn',@_)} 122 123 sub C {CommonFunction->Call('C', @_)} 124 sub P {CommonFunction->Call('P', @_)} 125 sub Comb {CommonFunction->Call('C', @_)} 126 sub Perm {CommonFunction->Call('P', @_)} 127 128 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |