line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Math::Tutor::Util; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
30030
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
22
|
|
|
2
|
|
|
|
|
62
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
App::Math::Tutor::Util - Utilities for easier Math Tutorial Exercises generation |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=cut |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
9
|
use vars qw(); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
27
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
8
|
use Exporter; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
253
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.004'; |
17
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
18
|
|
|
|
|
|
|
our @EXPORT = qw(); |
19
|
|
|
|
|
|
|
our @EXPORT_OK = qw(sumcat_terms prodcat_terms); |
20
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
12
|
use Scalar::Util qw/blessed/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1479
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my %sum_opposites = ( |
25
|
|
|
|
|
|
|
'+' => '-', |
26
|
|
|
|
|
|
|
'-' => '+', |
27
|
|
|
|
|
|
|
'\pm' => '\mp', |
28
|
|
|
|
|
|
|
'\mp' => '\pm', |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 EXPORTS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 sumcat_terms |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $formatted = sumcat_terms( "-", VulFrac->new( num => $p, denum => 2, sign => -1 ), |
36
|
|
|
|
|
|
|
Power->new( mode => 1, basis => $d, exponent => |
37
|
|
|
|
|
|
|
VulFrac->new( num => 1, denum => 2 ) ) ); |
38
|
|
|
|
|
|
|
say $formatted; |
39
|
|
|
|
|
|
|
# \frac{\frac{7}{4}}{2}\pm\sqrt{-\left(\frac{\frac{7}{4}}{2}\right)-\frac{3}{4}} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Concatenates terms using specified kind of addition operation |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub sumcat_terms |
46
|
|
|
|
|
|
|
{ |
47
|
168
|
|
|
168
|
1
|
322
|
my ( $op, @terms ) = @_; |
48
|
168
|
|
|
|
|
274
|
my $str = ""; |
49
|
168
|
|
|
|
|
185
|
my $i = 0; |
50
|
|
|
|
|
|
|
|
51
|
168
|
|
|
|
|
426
|
foreach $i ( 0 .. $#terms ) |
52
|
|
|
|
|
|
|
{ |
53
|
336
|
|
|
|
|
473
|
my $term = $terms[$i]; |
54
|
336
|
50
|
|
|
|
922
|
$term or next; |
55
|
336
|
100
|
50
|
|
|
1504
|
$str = "$term" and next unless $i; |
56
|
168
|
|
|
|
|
269
|
my $c_op = $op; |
57
|
168
|
100
|
|
|
|
665
|
my $sign = blessed $term ? $term->sign : $term <=> 0; |
58
|
168
|
50
|
|
|
|
437
|
if ( $sign < 0 ) |
59
|
|
|
|
|
|
|
{ |
60
|
0
|
0
|
|
|
|
0
|
$term = blessed $term ? $term->_abs() : abs($term); |
61
|
0
|
|
|
|
|
0
|
$c_op = $sum_opposites{$op}; |
62
|
|
|
|
|
|
|
} |
63
|
168
|
|
|
|
|
541
|
$str .= "${c_op}${term}"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
168
|
|
|
|
|
362
|
$str =~ s/^\+//; |
67
|
168
|
|
|
|
|
1327
|
$str; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my %prod_ops = ( |
71
|
|
|
|
|
|
|
'*' => '\cdot', |
72
|
|
|
|
|
|
|
'/' => '\div', |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 prodcat_terms |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $formatted = prodcat_terms( "/", VulFrac->new( num => $p, denum => 2 ), ... |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub prodcat_terms |
82
|
|
|
|
|
|
|
{ |
83
|
271
|
|
|
271
|
1
|
597
|
my ( $op, @terms ) = @_; |
84
|
271
|
|
|
|
|
295
|
my $str = ""; |
85
|
271
|
|
|
|
|
257
|
my $i = 0; |
86
|
|
|
|
|
|
|
|
87
|
271
|
|
|
|
|
492
|
foreach $i ( 0 .. $#terms ) |
88
|
|
|
|
|
|
|
{ |
89
|
542
|
100
|
50
|
|
|
1812
|
my $term = $terms[$i] or return "0" if ( $op eq "*" ); |
90
|
542
|
100
|
50
|
|
|
1249
|
$term = $terms[$i] or return "inf" if ( $op eq "/" ); |
91
|
542
|
100
|
50
|
|
|
1534
|
$str = "$term" and next unless $i; |
92
|
271
|
|
|
|
|
526
|
my $c_op = $prod_ops{$op}; |
93
|
271
|
|
|
|
|
1060
|
$str .= "${c_op}{}${term}"; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
271
|
|
|
|
|
1274
|
$str; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Copyright 2010-2014 Jens Rehsack. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
104
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
105
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |