1: # The LearningOnline Network with CAPA
2: # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
3: #
4: # $Id: default_homework.lcpm,v 1.73 2004/03/16 15:31:52 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: # Guy Albertelli
30: #
31: # 05/25/2001 H. K. Ng
32: # 05/31/2001 H. K. Ng
33: # 12/21/2001 Matthew
34: #
35: #init some globals
36: $hidden::RANDOMINIT=0;
37: $pi=atan2(1,1)*4;
38: $rad2deg=180.0/$pi;
39: $deg2rad=$pi/180.0;
40: $"=' ';
41:
42: sub caparesponse_check {
43: #not properly used yet: calc
44: #not to be used: $ans_fmt
45: my ($type,$tol,$sig,$ans_fmt,$unit,$calc,$samples) =
46: eval $_[2].
47: ';return ($__LC__type,$__LC__tol,$__LC__sig,$__LC__ans_fmt,$__LC__unit,$__LC__calc,$__LC__samples);';
48:
49: my $tol_type=''; # gets it's value from whether tol has a % or not done
50: my $sig_lbound=''; #done
51: my $sig_ubound=''; #done
52: my ($answer,$response,$expr)=@_;
53:
54:
55: #type's definitons come from capaParser.h
56: my $message='';
57: #remove leading and trailing whitespace
58: if (!defined($response)) {
59: $response='';
60: }
61: if ($response=~ /^\s|\s$/) {
62: $response=~ s:^\s+|\s+$::g;
63: $message .="Removed ws now :$response:\n";
64: } else {
65: $message .="no ws in :$response:\n";
66: }
67:
68: if (length($response) > 500) { return "TOO_LONG: Answer too long"; }
69:
70: if ($type eq '' ) {
71: $message .= "Didn't find a type :$type:$expr: defaulting\n";
72: if ( $answer eq ($answer *1.0)) { $type = 2;
73: } else { $type = 3; }
74: } else {
75: if ($type eq 'cs') { $type = 4; }
76: elsif ($type eq 'ci') { $type = 3 }
77: elsif ($type eq 'mc') { $type = 5; }
78: elsif ($type eq 'fml') { $type = 8; }
79: elsif ($type eq 'subj') { $type = 7; }
80: elsif ($type eq 'float') { $type = 2; }
81: elsif ($type eq 'int') { $type = 1; }
82: else { return "ERROR: Unknown type of answer: $type" }
83: }
84:
85: my $points;
86: my $id_list;
87: #formula type setup the sample points
88: if ($type eq '8') {
89: ($id_list,$points)=split(/@/,$samples);
90: $message.="Found :$id_list:$points: points in $samples\n";
91: }
92: if ($tol eq '') {
93: $tol=0.0;
94: $tol_type=1; #TOL_ABSOLUTE
95: } else {
96: if ($tol =~ /%$/) {
97: chop $tol;
98: $tol_type=2; #TOL_PERCENTAGE
99: } else {
100: $tol_type=1; #TOL_ABSOLUTE
101: }
102: }
103:
104: if ($sig eq '') {
105: $sig_lbound = 0; #SIG_LB_DEFAULT
106: $sig_ubound =15; #SIG_UB_DEFAULT
107: } else {
108: ($sig_lbound,$sig_ubound) = split /,/,$sig;
109: if (!defined($sig_lbound)) {
110: $sig_lbound = 0; #SIG_LB_DEFAULT
111: $sig_ubound =15; #SIG_UB_DEFAULT
112: }
113: if (!defined($sig_ubound)) { $sig_ubound=$sig_lbound; }
114: }
115: my $reterror="";
116: my $result = &caparesponse_capa_check_answer($response,$answer,$type,
117: $tol_type,$tol,
118: $sig_lbound,$sig_ubound,
119: $ans_fmt,$unit,$calc,$id_list,
120: $points,$external::randomseed,
121: \$reterror);
122:
123: if ($result == '1') { $result='EXACT_ANS'; }
124: elsif ($result == '2') { $result='APPROX_ANS'; }
125: elsif ($result == '3') { $result='SIG_FAIL'; }
126: elsif ($result == '4') { $result='UNIT_FAIL'; }
127: elsif ($result == '5') { $result='NO_UNIT'; }
128: elsif ($result == '6') { $result='UNIT_OK'; }
129: elsif ($result == '7') { $result='INCORRECT'; }
130: elsif ($result == '8') { $result='UNIT_NOTNEEDED'; }
131: elsif ($result == '9') { $result='ANS_CNT_NOT_MATCH'; }
132: elsif ($result =='10') { $result='SUB_RECORDED'; }
133: elsif ($result =='11') { $result='BAD_FORMULA'; }
134: elsif ($result =='12') { $result='WANTED_NUMERIC'; }
135: else {$result = "ERROR: Unknown Result:$result:$@:";}
136:
137: return ("$result:\nRetError $reterror:\nError $error:\nAnswer $answer:\nResponse $response:\n type-$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$unit|\n$message$expr",$reterror);
138: }
139:
140:
141: sub caparesponse_check_list {
142: my ($response,$expr)=@_;
143: my ($result,@list);
144: @list=@CAPARESPONSE_CHECK_LIST_answer;
145: my $aresult='';
146: my $current_answer;
147: my $answers=join(':',@list);
148: $result.="Got response :$answers:\n";
149: my @responselist;
150: my $type =eval $expr.';return $__LC__type;';
151: $result.="Got type :$type:\n";
152: if ($type ne '' && $#list > 0) {
153: (@responselist)=split /,/,$response;
154: } else {
155: (@responselist)=($response);
156: }
157: my $unit='';
158: $result.="Initial final response :$responselist['-1']:\n";
159: if ($type eq '' || $type eq 'float') {
160: #for numerical problems split off the unit
161: if ( $responselist['-1']=~ /(.*[^\s])\s+([^\s]+)/ ) {
162: $responselist['-1']=$1;
163: $unit=$2;
164: }
165: }
166: $result.="Final final response :$responselist['-1']:\n";
167: $result.=":$#list: answers\n";
168: $unit=~s/\s//;
169: my $i=0;
170: my $awards='';
171: my @msgs;
172: for ($i=0; $i<@list;$i++) {
173: my $msg;
174: $result.="trying answer :$list[$i]:\n";
175: my $thisanswer=$list[$i];
176: $result.="trying answer :$thisanswer:\n";
177: if ($unit eq '') {
178: ($aresult,$msg)=&caparesponse_check($thisanswer,$responselist[$i],
179: $expr);
180: } else {
181: ($aresult,$msg)=&caparesponse_check($thisanswer,
182: $responselist[$i]." $unit",
183: $expr);
184: }
185: my ($temp)=split /:/, $aresult;
186: $awards.="$temp,";
187: $result.=$aresult;
188: push(@msgs,$msg);
189: }
190: chop $awards;
191: return ("$awards:\n$result",@msgs);
192: }
193:
194: sub tex {
195: if ( $external::target eq "tex" ) {
196: return $_[0];
197: } else {
198: return $_[1];
199: }
200: }
201:
202: sub var_in_tex {
203: if ( $external::target eq "tex" ) {
204: return $_[0];
205: } else {
206: return "";
207: }
208: }
209:
210: sub web {
211: if ( $external::target eq "tex" ) {
212: return $_[1];
213: } else {
214: if ( $external::target eq "web" || $external::target eq "answer") {
215: return $_[2];
216: } else {
217: return $_[0];
218: }
219: }
220: }
221:
222: sub html {
223: if ( $external::target eq "web" ) {
224: return shift;
225: }
226: }
227:
228: sub hinton {
229: return 0;
230: }
231:
232: sub random {
233: my ($start,$end,$step)=@_;
234: if ( ! $hidden::RANDOMINIT ) {
235: if ($external::randomseed == 0) { $external::randomseed=1; }
236: if ($external::randomseed =~/,/) {
237: my ($num1,$num2)=split(/,/,$seed);
238: &random_set_seed(abs($num1),abs($num2));
239: } else {
240: &random_set_seed(1,int(abs($external::randomseed)));
241: }
242: &math_random_uniform();
243: $hidden::RANDOMINIT=1;
244: }
245: if (!defined($step)) { $step=1; }
246: my $num=1+int(($end-$start)/$step);
247: my $result=$start + int(&math_random_uniform() * $num)*$step;
248: return $result;
249: }
250:
251: sub random_normal {
252: my ($item_cnt,$seed,$av,$std_dev) = @_;
253: my @oldseed=&random_get_seed();
254: my @retArray;
255: &random_set_seed_from_phrase($seed);
256: @retArray=&math_random_normal($item_cnt,$av,$std_dev);
257: &random_set_seed(@oldseed);
258: return @retArray;
259: }
260:
261: sub random_beta {
262: my ($item_cnt,$seed,$aa,$bb) = @_;
263: my @oldseed=&random_get_seed();
264: my @retArray;
265: &random_set_seed_from_phrase($seed);
266: @retArray=&math_random_beta($item_cnt,$aa,$bb);
267: &random_set_seed(@oldseed);
268: return @retArray;
269: }
270:
271: sub random_gamma {
272: my ($item_cnt,$seed,$a,$r) = @_;
273: my @oldseed=&random_get_seed();
274: my @retArray;
275: &random_set_seed_from_phrase($seed);
276: @retArray=&math_random_gamma($item_cnt,$a,$r);
277: &random_set_seed(@oldseed);
278: return @retArray;
279: }
280:
281: sub random_exponential {
282: my ($item_cnt,$seed,$av) = @_;
283: my @oldseed=&random_get_seed();
284: my @retArray;
285: &random_set_seed_from_phrase($seed);
286: @retArray=&math_random_exponential($item_cnt,$av);
287: &random_set_seed(@oldseed);
288: return @retArray;
289: }
290:
291: sub random_poisson {
292: my ($item_cnt,$seed,$mu) = @_;
293: my @oldseed=&random_get_seed();
294: my @retArray;
295: &random_set_seed_from_phrase($seed);
296: @retArray=&math_random_poisson($item_cnt,$mu);
297: &random_set_seed(@oldseed);
298: return @retArray;
299: }
300:
301: sub random_chi {
302: my ($item_cnt,$seed,$df) = @_;
303: my @oldseed=&random_get_seed();
304: my @retArray;
305: &random_set_seed_from_phrase($seed);
306: @retArray=&math_random_chi_square($item_cnt,$df);
307: &random_set_seed(@oldseed);
308: return @retArray;
309: }
310:
311: sub random_noncentral_chi {
312: my ($item_cnt,$seed,$df,$nonc) = @_;
313: my @oldseed=&random_get_seed();
314: my @retArray;
315: &random_set_seed_from_phrase($seed);
316: @retArray=&math_random_noncentral_chi_square($item_cnt,$df,$nonc);
317: &random_set_seed(@oldseed);
318: return @retArray;
319: }
320:
321: sub random_f {
322: my ($item_cnt,$seed,$dfn,$dfd) = @_;
323: my @oldseed=&random_get_seed();
324: my @retArray;
325: &random_set_seed_from_phrase($seed);
326: @retArray=&math_random_f($item_cnt,$dfn,$dfd);
327: &random_set_seed(@oldseed);
328: return @retArray;
329: }
330:
331: sub random_noncentral_f {
332: my ($item_cnt,$seed,$dfn,$dfd,$nonc) = @_;
333: my @oldseed=&random_get_seed();
334: my @retArray;
335: &random_set_seed_from_phrase($seed);
336: @retArray=&math_random_noncentral_f($item_cnt,$dfn,$dfd,$nonc);
337: &random_set_seed(@oldseed);
338: return @retArray;
339: }
340:
341: sub random_multivariate_normal {
342: my ($item_cnt,$seed,$mean,$covar) = @_;
343: my @oldseed=&random_get_seed();
344: &random_set_seed_from_phrase($seed);
345: @retArray=&math_random_multivariate_normal($item_cnt,@$mean,@$covar);
346: &random_set_seed(@oldseed);
347: return @retArray;
348: }
349:
350: sub random_multinomial {
351: my ($item_cnt,$seed,@p) = @_;
352: my @oldseed=&random_get_seed();
353: my @retArray;
354: &random_set_seed_from_phrase($seed);
355: @retArray=&math_random_multinomial($item_cnt,@p);
356: &random_set_seed(@oldseed);
357: return @retArray;
358: }
359:
360: sub random_permutation {
361: my ($seed,@inArray) = @_;
362: my @oldseed=&random_get_seed();
363: my @retArray;
364: &random_set_seed_from_phrase($seed);
365: @retArray=&math_random_permutation(@inArray);
366: &random_set_seed(@oldseed);
367: return @retArray;
368: }
369:
370: sub random_uniform {
371: my ($item_cnt,$seed,$low,$high) = @_;
372: my @oldseed=&random_get_seed();
373: my @retArray;
374: &random_set_seed_from_phrase($seed);
375: @retArray=&math_random_uniform($item_cnt,$low,$high);
376: &random_set_seed(@oldseed);
377: return @retArray;
378: }
379:
380: sub random_uniform_integer {
381: my ($item_cnt,$seed,$low,$high) = @_;
382: my @oldseed=&random_get_seed();
383: my @retArray;
384: &random_set_seed_from_phrase($seed);
385: @retArray=&math_random_uniform_integer($item_cnt,$low,$high);
386: &random_set_seed(@oldseed);
387: return @retArray;
388: }
389:
390: sub random_binomial {
391: my ($item_cnt,$seed,$nt,$p) = @_;
392: my @oldseed=&random_get_seed();
393: my @retArray;
394: &random_set_seed_from_phrase($seed);
395: @retArray=&math_random_binomial($item_cnt,$nt,$p);
396: &random_set_seed(@oldseed);
397: return @retArray;
398: }
399:
400: sub random_negative_binomial {
401: my ($item_cnt,$seed,$ne,$p) = @_;
402: my @oldseed=&random_get_seed();
403: my @retArray;
404: &random_set_seed_from_phrase($seed);
405: @retArray=&math_random_negative_binomial($item_cnt,$ne,$p);
406: &random_set_seed(@oldseed);
407: return @retArray;
408: }
409:
410: sub abs { abs(shift) }
411: sub sin { sin(shift) }
412: sub cos { cos(shift) }
413: sub exp { exp(shift) }
414: sub int { int(shift) }
415: sub log { log(shift) }
416: sub atan2 { atan2($_[0],$_[1]) }
417: sub sqrt { sqrt(shift) }
418:
419: sub tan { CORE::sin($_[0]) / CORE::cos($_[0]) }
420: #sub atan { atan2($_[0], 1); }
421: #sub acos { atan2(sqrt(1 - $_[0] * $_[0]), $_[0] ); }
422: #sub asin { atan2($_[0], sqrt(1- $_[0] * $_[0]) ); }
423:
424: sub log10 { CORE::log($_[0])/CORE::log(10); }
425:
426: sub factorial {
427: my $input = CORE::int(shift);
428: return "Error - unable to take factorial of an negative number ($input)" if $input < 0;
429: return "Error - factorial result is greater than system limit ($input)" if $input > 170;
430: return 1 if $input == 0;
431: my $result = 1;
432: for (my $i=2; $i<=$input; $i++) { $result *= $i }
433: return $result;
434: }
435:
436: sub sgn {
437: return -1 if $_[0] < 0;
438: return 0 if $_[0] == 0;
439: return 1 if $_[0] > 0;
440: }
441:
442: sub min {
443: my @sorted = sort { $a <=> $b || $a cmp $b } @_;
444: return shift @sorted;
445: }
446:
447: sub max {
448: my @sorted = sort { $a <=> $b || $a cmp $b } @_;
449: return pop @sorted;
450: }
451:
452: sub roundto {
453: my ($input,$n) = @_;
454: return sprintf('%.'.$n.'f',$input);
455: }
456:
457: sub to_string {
458: my ($input,$n) = @_;
459: return sprintf($input) if $n eq "";
460: $n = '.'.$n if $n !~ /^\./;
461: return sprintf('%'.$n,$input) if $n ne "";
462: }
463:
464: sub sub_string {
465: my ($str,$start,$len) = @_;
466: return substr($str,$start-1,$len);
467: }
468:
469: sub pow {return $_[0] ** $_[1]; }
470: sub ceil {return (($_[0]-CORE::int($_[0]))== 0.0) ? $_[0] : (($_[0] > 0) ? (CORE::int($_[0])+ 1) : CORE::int($_[0])); }
471: sub floor {return (($_[0]-CORE::int($_[0]))== 0.0) ? $_[0] : (($_[0] > 0) ? CORE::int($_[0]) : (CORE::int($_[0])-1)); }
472: #sub floor {return int($_[0]); }
473:
474: sub format {
475: my ($value,$fmt)=@_;
476: my $dollarmode;
477: if ($fmt =~ /^\$(.*)/) { $fmt=$1; $dollarmode=1; }
478: $fmt=~s/e/E/g;
479: my $result=sprintf('%.'.$fmt,$value);
480: $result=~s/(E[+-]*)0/$1/;
481: if ($dollarmode) {$result=&dollarmode($result);}
482: return $result;
483: }
484:
485: sub prettyprint {
486: my ($value,$fmt,$target)=@_;
487: my $result;
488: my $dollarmode;
489: if (!$target) { $target = $external::target; }
490: if ($fmt =~ /^\$(.*)/) { $fmt=$1; $dollarmode=1; }
491: if ($fmt) { $value=sprintf('%.'.$fmt,$value); }
492: if ($value =~ /([0-9\.\-\+]+)E([0-9\-\+]+)/i ) {
493: my $frac=$1;
494: if ($dollarmode) { $frac=&dollarformat($frac); }
495: my $exponent=$2;
496: $exponent=~s/^\+0*//;
497: $exponent=~s/^-0*/-/;
498: $exponent=~s/^-0*/-/;
499: if ($exponent eq '-') { undef($exponent); }
500: if ($exponent) {
501: if ($target eq 'web') {
502: $result=$frac.'×10<sup>'.$exponent.'</sup>';
503: } elsif ($target eq 'tex') {
504: $result='\ensuremath{'.$frac.'\times 10^{'.$exponent.'}}';
505: } else {
506: $result=$value;
507: }
508: } else {
509: $result=$frac;
510: }
511: } else {
512: $result=$value;
513: if ($dollarmode) { $result=&dollarformat($result,$target); }
514: }
515: return $result;
516: }
517:
518: sub dollarformat {
519: my ($number,$target) = @_;
520: if (!$target) { $target = $external::target; }
521: if ($number =~ /\./) {
522: while ($number =~ /([^\.,]+)([^\.,][^\.,][^\.,])([,0-9]*\.[0-9]*)$/) {
523: $number = $1.','.$2.$3;
524: }
525: } else {
526: while ($number =~ /([^,]+)([^,][^,][^,])([,0-9]*)$/) {
527: $number = $1.','.$2.$3;
528: }
529: }
530: if ($target eq 'tex') {
531: $number='\$'.$number; #' stupid emacs
532: } else {
533: $number='$'.$number; #' stupid emacs
534: }
535: return $number;
536: }
537:
538: sub map {
539: my ($phrase,$dest,$source)=@_;
540: my @oldseed=&random_get_seed();
541: my @seed = &random_seed_from_phrase($phrase);
542: &random_set_seed(@seed);
543: my $destct = scalar(@$dest);
544: if (!$source) {
545: my @output;
546: my @idx = &math_random_permuted_index($destct);
547: my $ctr = 0;
548: while ($ctr < $destct) {
549: $output[$ctr] = $$dest[$idx[$ctr]];
550: $ctr++;
551: }
552: &random_set_seed(@oldseed);
553: return @output;
554: } else {
555: my $num = scalar(@$source);
556: my @idx = &math_random_permuted_index($num);
557: my $ctr = 0;
558: my $tot = $num;
559: $tot = $destct if $destct < $num;
560: if (ref($$dest[0])) {
561: while ($ctr < $tot) {
562: ${$$dest[$ctr]} = $$source[$idx[$ctr]];
563: $ctr++;
564: }
565: } else {
566: while ($ctr < $tot) {
567: $$dest[$ctr] = $$source[$idx[$ctr]];
568: $ctr++;
569: }
570: }
571: }
572: &random_set_seed(@oldseed);
573: return '';
574: }
575:
576: sub rmap {
577: my ($phrase,$dest,$source)=@_;
578: my @oldseed=&random_get_seed();
579: my @seed = &random_seed_from_phrase($phrase);
580: &random_set_seed(@seed);
581: my $destct = scalar(@$dest);
582: if (!$source) {
583: my @idx = &math_random_permuted_index($destct);
584: my $ctr = 0;
585: my @r_idx;
586: while ($ctr < $destct) {
587: $r_idx[$idx[$ctr]] = $ctr;
588: $ctr++;
589: }
590: my @output;
591: $ctr = 0;
592: while ($ctr < $destct) {
593: $output[$ctr] = $$dest[$r_idx[$ctr]];
594: $ctr++;
595: }
596: &random_set_seed(@oldseed);
597: return @output;
598: } else {
599: my $num = scalar(@$source);
600: my @idx = &math_random_permuted_index($num);
601: my $ctr = 0;
602: my $tot = $num;
603: $tot = $destct if $destct < $num;
604: my @r_idx;
605: while ($ctr < $tot) {
606: $r_idx[$idx[$ctr]] = $ctr;
607: $ctr++;
608: }
609: $ctr = 0;
610: if (ref($$dest[0])) {
611: while ($ctr < $tot) {
612: ${$$dest[$ctr]} = $$source[$r_idx[$ctr]];
613: $ctr++;
614: }
615: } else {
616: while ($ctr < $tot) {
617: $$dest[$ctr] = $$source[$r_idx[$ctr]];
618: $ctr++;
619: }
620: }
621: }
622: &random_set_seed(@oldseed);
623: return '';
624: }
625:
626: sub capa_id { return }
627:
628: sub problem { return }
629:
630: sub name{
631: my $fullname = &EXT('environment.lastname').', '.&EXT('environment.firstname').' '.&EXT('environment.middlename');
632: $fullname = "" if $fullname eq ", ";
633: $fullname =~ s/\%2d/-/g;
634: return $fullname;
635: }
636:
637: sub student_number {
638: my $id = &EXT('environment.id');
639: $id = '' if $id eq "";
640: return $id;
641: }
642:
643: sub class {
644: my $course = &EXT('course.description');
645: $course = '' if $course eq "";
646: return $course;
647: }
648:
649: sub sec {
650: my $sec = &EXT('request.course.sec');
651: $sec = '' if $sec eq "";
652: return $sec;
653: }
654:
655: sub open_date {
656: my @dc = split(/\s+/,localtime(&EXT('resource.0.opendate')));
657: return '' if ($dc[0] eq "Wed" and $dc[2] == 31 and $dc[4] == 1969);
658: my @hm = split(/:/,$dc[3]);
659: my $ampm = " am";
660: if ($hm[0] > 12) {
661: $hm[0]-=12;
662: $ampm = " pm";
663: }
664: return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$hm[0].':'.$hm[1].$ampm;
665: }
666:
667: sub due_date {
668: my @dc = split(/\s+/,localtime(&EXT('resource.0.duedate')));
669: return '' if ($dc[0] eq "Wed" and $dc[2] == 31 and $dc[4] == 1969);
670: my @hm = split(/:/,$dc[3]);
671: my $ampm = " am";
672: if ($hm[0] > 12) {
673: $hm[0]-=12;
674: $ampm = " pm";
675: }
676: return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$hm[0].':'.$hm[1].$ampm;
677: }
678:
679: sub answer_date {
680: my @dc = split(/\s+/,localtime(&EXT('resource.0.answerdate')));
681: return '' if ($dc[0] eq "Wed" and $dc[2] == 31 and $dc[4] == 1969);
682: my @hm = split(/:/,$dc[3]);
683: my $ampm = " am";
684: if ($hm[0] > 12) {
685: $hm[0]-=12;
686: $ampm = " pm";
687: }
688: return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$hm[0].':'.$hm[1].$ampm;
689: }
690:
691: sub array_moments {
692: my @input=@_;
693: my (@output,$N);
694: $N=scalar (@input);
695: $output[0]=$N;
696: if ($N <= 1) {
697: $output[1]=$input[0];
698: $output[1]="Input array not defined" if ($N == 0);
699: $output[2]="variance undefined for N<=1";
700: $output[3]="skewness undefined for N<=1";
701: $output[4]="kurtosis undefined for N<=1";
702: return @output;
703: }
704: my $sum=0;
705: foreach my $line (@input) {
706: $sum+=$line;
707: }
708: $output[1] = $sum/$N;
709: my ($x,$sdev,$var,$skew,$kurt) = 0;
710: foreach my $line (@input) {
711: $x=$line-$output[1];
712: $var+=$x**2;
713: $skew+=$x**3;
714: $kurt+=$x**4;
715: }
716: $output[2]=$var/($N-1);
717: $sdev=CORE::sqrt($output[2]);
718: if ($sdev == 0) {
719: $output[3]="inf-variance=0";
720: $output[4]="inf-variance=0";
721: return @output;
722: }
723: $output[3]=$skew/($sdev**3*$N);
724: $output[4]=$kurt/($sdev**4*$N)-3;
725: return @output;
726: }
727:
728: sub choose {
729: my $num = $_[0];
730: return $_[$num];
731: }
732:
733: # expiremental idea
734: sub proper_path {
735: my ($path)=@_;
736: if ( $external::target eq "tex" ) {
737: return '/home/httpd/html'.$path;
738: } else {
739: return $path;
740: }
741: }
742:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>