"det" in pdl and "det" in polymake

Questions and problems about using polymake go here.
MattLarson
Posts: 11
Joined: 03 Jun 2018, 22:57

"det" in pdl and "det" in polymake

Postby MattLarson » 09 Aug 2020, 04:17

Hi,

I have written a script that uses pdl to do some linear algebra computations. In the same script, I'm trying to do a linear algebra computation using the matrix class in polymake.

The issue I'm encountering is that when I apply det to a polymake matrix, it does the pdl det and gives an error. I want to use the polymake det function because I'm running into numerical precision issues with the pdl det (if I replace all the matrices by pdl matrices).

Is there a way to tell polymake to use the polymake det function? If not, is there is an efficient way to compute the multiplicity of a set of integer vectors (i.e., the index of the subgroup of lattice points they generate in the group of lattice points in the vector space they span) in polymake?

Thank you!

User avatar
joswig
Main Author
Posts: 234
Joined: 24 Dec 2010, 11:10

Re: "det" in pdl and "det" in polymake

Postby joswig » 11 Aug 2020, 16:51

Is there a way to tell polymake to use the polymake det function?
This is impossible to answer without seeing your script. I do not know about pdl. That is, if you would post that script, it might require a bit of explanation.
If not, is there is an efficient way to compute the multiplicity of a set of integer vectors (i.e., the index of the subgroup of lattice points they generate in the group of lattice points in the vector space they span) in polymake?
Well, that's clearly a determinant computation.

MattLarson
Posts: 11
Joined: 03 Jun 2018, 22:57

Re: "det" in pdl and "det" in polymake

Postby MattLarson » 12 Aug 2020, 02:08

I guess my question is: Is there a way to give the "det" function in polymake an alias so that I can call it, even though "det" in pdl has the same name?

That said, here is (the relevant pieces) of my code.
First I have a function that computes multiplicity using polymake's "det" function

Code: Select all

sub multiplicityArray{ my @input = @{shift @_}; my @vecs = map(latticePointToArray($_), @input); my $num = scalar(@vecs); my @minors = subsets([0..scalar(@{$vecs[0]})-1], $num); my @minorsDets; for my $sub(@minors){ my @matrixAoa = (); for my $i(0..($num - 1)){ my @row = (); for my $j (0..($num - 1)){ push(@row, $vecs[$i]->[$sub->[$j]]); } push(@matrixAoa, \@row); } my $a = new Matrix<Int>(\@matrixAoa); my $d = det($a); push(@minorsDets, $d); } my $v = new Vector<Int>(\@minorsDets); return $gcd($v); }
In various other places, I use pdl to do things like compute the inverse of a matrix. For example, I have the following function.

Code: Select all

use PDL; sub returnLinearExpression{ my $diagram = shift; my $facet = shift; my $dim = scalar(@{$facet}) - 1; my @coords = (); for my $i (0..$dim){ push(@coords, $diagram->[$facet->[$i]]); } my @row = (1) x ($dim + 1); my $r = pdl[\@row]; my $target = $r->transpose; #now creates the matrix of the coords my $tpose = pdl[\@coords]; my $mat = $tpose->transpose; my $inv = inv($mat); my $res = $inv x $target; my @res = $res->list; return \@res; }

MattLarson
Posts: 11
Joined: 03 Jun 2018, 22:57

Re: "det" in pdl and "det" in polymake

Postby MattLarson » 12 Aug 2020, 02:27

Of course I could write my own function to compute the determinant of a polymake matrix, I was just wondering if there is an easy way around this.

MattLarson
Posts: 11
Joined: 03 Jun 2018, 22:57

Re: "det" in pdl and "det" in polymake

Postby MattLarson » 12 Aug 2020, 03:22

Now I see that the function "pluecker" does exactly what I want. So that provides a (better) work around.

Thank you!

User avatar
joswig
Main Author
Posts: 234
Joined: 24 Dec 2010, 11:10

Re: "det" in pdl and "det" in polymake

Postby joswig » 12 Aug 2020, 09:22

I am glad you found something useful in polymake.

Let me point out that polymake scripts differ slightly from general perl scripts. They should start out with something like

Code: Select all

use application "polytope";
to set the scope (i.e., the active application). polymake's determinant function lives in the application common. So you can force calling this function by

Code: Select all

my $d = common::det($a);
which might solve your problem.

By the way, the PDL functions in your script should be present in polymake, too.


Return to “Helpdesk”

cron