crunch_this! has asked for the wisdom of the Perl Monks concerning the following question:
Here's the relevant stuff that I've done so far:
UPDATE: Like I said in the comment below, I've gone with an ordinry hash, so I've changed hdb's code a bit to simply sayuse Math::Polynomial::Solve qw!poly_derivative poly_roots!; my %haystack; my $rep = int 5; # $rep means right endpoint of the interval [0, $rep] foreach ( $a = 1; $a <= $rep; $a++ ) { foreach ( $b = 1; $b <= $rep; $b++ ) { foreach ( $c = 1; $c <= $rep; $c++ ) { if ( $a == $b || $b == $c || $c == $a ){ next; } else { # expanded form of (x^2)*(x - a)*(x - b)*(x - c) # coeffs are in an array my @quintic = (1, -$a - $b - $c, $a*$b + $a*$c + $b*$c +, -$a*$b*$c, 0, 0); my @derivative = poly_derivative(@quintic); my @zeros = poly_roots(@derivative); $haystack{@quintic}{@derivative} = @zeros; } } } }
Part of the problem is I don't think I know how to make sure that grep will look for the zero sets whose elements ALL have the form indicated, or that it will look for solution sets that just have at least one (which would be all of them in this case & not very interesting). Something else that caught my eye at the bottom of the Dumper manpage is a subroutine that filters keys out of a hash; I wonder if that could be adapted here because that module is really cool.# the arrays of zeros are now the keys %haystack = reverse %haystack; # supposed to search the keys for zero sets that only contain numbers +within 0.0001 of an integer my @wants = grep { / (.*\.0000.*)|(.*\.9999.*) / } keys %haystack; # supposed to print out the corresponding values from %haystack print Dumper{ values of a, b, c corresponding to the elements of @want +s };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Issue with hash definition & possibly some other stuff
by BrowserUk (Patriarch) on Apr 08, 2013 at 18:44 UTC | |
|
Re: Issue with hash definition & possibly some other stuff
by hdb (Monsignor) on Apr 08, 2013 at 21:27 UTC | |
by crunch_this! (Acolyte) on Apr 08, 2013 at 23:30 UTC | |
by crunch_this! (Acolyte) on Apr 09, 2013 at 01:56 UTC | |
|
Re: Issue with hash definition & possibly some other stuff
by locked_user sundialsvc4 (Abbot) on Apr 08, 2013 at 21:39 UTC |