line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Math::Tutor::Util; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
15179
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
4
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
App::Math::Tutor::Util - Utilities for easier Math Tutorial Exercises generation |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=cut |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
7
|
use vars qw(); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
20
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
7
|
use Exporter; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
208
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.005'; |
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
|
|
9
|
use Scalar::Util qw/blessed/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
684
|
|
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
|
8
|
|
|
8
|
1
|
24
|
my ( $op, @terms ) = @_; |
48
|
8
|
|
|
|
|
7
|
my $str = ""; |
49
|
8
|
|
|
|
|
7
|
my $i = 0; |
50
|
|
|
|
|
|
|
|
51
|
8
|
|
|
|
|
13
|
foreach $i ( 0 .. $#terms ) |
52
|
|
|
|
|
|
|
{ |
53
|
16
|
|
|
|
|
19
|
my $term = $terms[$i]; |
54
|
16
|
50
|
|
|
|
26
|
$term or next; |
55
|
16
|
100
|
50
|
|
|
36
|
$str = "$term" and next unless $i; |
56
|
8
|
|
|
|
|
9
|
my $c_op = $op; |
57
|
8
|
100
|
|
|
|
50
|
my $sign = blessed $term ? $term->sign : $term <=> 0; |
58
|
8
|
50
|
|
|
|
16
|
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
|
8
|
|
|
|
|
18
|
$str .= "${c_op}${term}"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
8
|
|
|
|
|
12
|
$str =~ s/^\+//; |
67
|
8
|
|
|
|
|
28
|
$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
|
2
|
|
|
2
|
1
|
46
|
my ( $op, @terms ) = @_; |
84
|
2
|
|
|
|
|
3
|
my $str = ""; |
85
|
2
|
|
|
|
|
2
|
my $i = 0; |
86
|
|
|
|
|
|
|
|
87
|
2
|
|
|
|
|
5
|
foreach $i ( 0 .. $#terms ) |
88
|
|
|
|
|
|
|
{ |
89
|
4
|
50
|
0
|
|
|
9
|
my $term = $terms[$i] or return "0" if ( $op eq "*" ); |
90
|
4
|
50
|
50
|
|
|
14
|
$term = $terms[$i] or return "inf" if ( $op eq "/" ); |
91
|
4
|
100
|
50
|
|
|
13
|
$str = "$term" and next unless $i; |
92
|
2
|
|
|
|
|
5
|
my $c_op = $prod_ops{$op}; |
93
|
2
|
|
|
|
|
6
|
$str .= "${c_op}{}${term}"; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
2
|
|
|
|
|
4
|
$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; |