This is an automated email from the git hooks/post-receive script.

ppm-guest pushed a commit to annotated tag v0.26
in repository libmath-prime-util-perl.

commit 72a23f42eaa40d9985e773084554850d7cab9205
Author: Dana Jacobsen <d...@acm.org>
Date:   Sat Apr 20 23:34:26 2013 -0700

    Allow factor.pl to parse many MPU functions
---
 bin/factor.pl | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/bin/factor.pl b/bin/factor.pl
index f7293dd..5cefe90 100755
--- a/bin/factor.pl
+++ b/bin/factor.pl
@@ -7,6 +7,14 @@ use Math::Prime::Util qw/factor nth_prime/;
 $| = 1;
 no bigint;
 
+# Allow execution of any of these functions in the command line
+my @mpu_funcs = (qw/next_prime prev_prime prime_count nth_prime random_prime
+                    random_ndigit_prime random_nbit_prime random_strong_prime
+                    random_maurer_prime primorial pn_primorial moebius mertens
+                    euler_phi jordan_totient exp_mangoldt divisor_sum
+                    consecutive_integer_lcm/);
+my %mpu_func_map;
+
 my %opts;
 GetOptions(\%opts,
            'version',   # turn off MPU::GMP for debugging
@@ -42,11 +50,21 @@ if (@ARGV) {
 sub eval_expr {
   my $expr = shift;
   die "$expr cannot be evaluated" if $expr =~ /:/;  # Use : for escape
-  $expr =~ s/nth_prime\(/:1(/g;
-  $expr =~ s/log\(/:2(/g;
+  if (scalar(keys %mpu_func_map) == 0) {
+    my $n = 10;
+    foreach my $func (@mpu_funcs) {
+      $mpu_func_map{$func} = sprintf("%03d", $n++);
+    }
+  }
+  $expr =~ s/\blog\(/:001(/g;
+  foreach my $func (@mpu_funcs) {
+    $expr =~ s/\b$func\(/:$mpu_func_map{$func}(/g;
+  }
   die "$expr cannot be evaluated" if $expr =~ tr|-0123456789+*/() :||c;
-  $expr =~ s/:1/nth_prime/g;
-  $expr =~ s/:2/log/g;
+  $expr =~ s/:001/log/g;
+  foreach my $func (@mpu_funcs) {
+    $expr =~ s/:$mpu_func_map{$func}\(/Math::Prime::Util::$func(/g;
+  }
   $expr =~ s/(\d+)/ Math::BigInt->new("$1") /g;
   my $res = eval $expr; ## no critic
   die "Cannot eval: $expr\n" if !defined $res;
@@ -62,6 +80,10 @@ Usage: $0 [options] [number] ...
 Print the prime factors of each positive integer given on the command line,
 or reads numbers from standard input if called without arguments.
 
+Math expressions may be given as arguments, which will be evaluated before
+factoring.  This includes most Math::Prime::Util functions including things
+like prime_count(#), nth_prime(#), primorial(#), random_nbit_prime(#), etc.
+
   --help       displays this help message
   --version    displays the version information
 

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to