Listing all available functions/members

Questions and problems about using polymake go here.
SimonKing
Posts: 14
Joined: 01 Mar 2017, 12:36

Listing all available functions/members

Postby SimonKing » 01 Mar 2017, 12:49

Hi!
I have originally asked this question to Michael Joswig off-list. He requested me to ask here, so that other people can benefit. So, let me both formulate my question and summarise Michael's answer.

My aim is to use Polymake via a pseudo-tty interface (more precisely: It is going to be a pexpect interface from Sage to Polymake). Polymake has tab-completion, but for the pexpect interface it would be better to have functions that return
1. a list of all functions available in the current application, respectively
2. a list of all members of a given object.

Michael gave me solutions to 2. The first would work in future (resp. in current beta releases), I can not test it currently:

Code: Select all

$c=cube(4); print join(" ", uniq(sort(map { $_->name." ".$_->type->full_name."\n" } grep {!$_->type->abstract && !($_->flags & $Core::Property::is_permutation) && $_->name !~ /\.pure$/ } map { values %{$_->properties} } {$c->type->linear_isa})));
The following works in the current 3.0 release:

Code: Select all

polytope > $c = cube(4); polytope > $t = typeof $c; polytope > print join(", ", sorted_uniq(sort { $a cmp $b } map { keys %{$_->properties} }$t, @{$t->super})); AFFINE_HULL, ALTSHULER_DET, BALANCE, BALANCED, ..., WEAKLY_CENTERED, ZONOTOPE_INPUT_POINTS
That's exactly what I need for 2., and I'd appreciate a solution to 1. as well.

Best regards,
Simon

SimonKing
Posts: 14
Joined: 01 Mar 2017, 12:36

Re: Listing all available functions/members

Postby SimonKing » 01 Mar 2017, 21:56

Off-list, Ewgenij Gawrilow gave me the following answer (summarised in English):

One can use the function "apropos" to get a list of all functions whose name matches a given perl regular expression:

Code: Select all

polytope > apropos 'assoc'; /functions/Producing a polytope from scratch/rss_associahedron /functions/Producing a polytope from scratch/associahedron polytope > apropos '^assoc'; /functions/Producing a polytope from scratch/associahedron polytope > apropos 'VISUAL_G'; /objects/Polytope/methods/Visualization/VISUAL_GRAPH /objects/SimplicialComplex/methods/Visualization/VISUAL_GRAPH
Since my aim is to process the output further with some script, he recommended to look at the implementation in InteractiveCommands.pm.

Best regards,
Simon King

paffenholz
Developer
Posts: 211
Joined: 24 Dec 2010, 13:47

Re: Listing all available functions/members

Postby paffenholz » 02 Mar 2017, 00:00

There is a jupyter kernel for polymake using pexpect that has tab completion already implemented. This is essentially done by using the tab completion method of polymake, so that we only need very litte code and directly have the full power of polymake's tab completion. Maybe you can just reuse this for sage?

We can also discuss this next week.

SimonKing
Posts: 14
Joined: 01 Mar 2017, 12:36

Re: Listing all available functions/members

Postby SimonKing » 02 Mar 2017, 17:11

Note that the above way to get members of an object doesn't always work. For instance:

(edit: in the following code I added the second line, that I accidentally omitted in my original post)

Code: Select all

polytope > $c = cube(4); polytope > $v = $c->VERTICES; polytope > $t = typeof $v; polytope > print join(", ", sorted_uniq(sort { $a cmp $b } map { keys %{$_->properties} }$t, @{$t->super})); polymake: ERROR: Can't locate object method "properties" via package "Polymake::Core::PropertyParamedType" at input line 1.
Last edited by SimonKing on 02 Mar 2017, 21:58, edited 1 time in total.

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

Re: Listing all available functions/members

Postby joswig » 02 Mar 2017, 19:51

The "$v" in your second line is a typo?

SimonKing
Posts: 14
Joined: 01 Mar 2017, 12:36

Re: Listing all available functions/members

Postby SimonKing » 02 Mar 2017, 21:59

The "$v" in your second line is a typo?
It was a typo, in the sense that I omitted one line when copy-and-pasting. I have now edited my post.

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

Re: Listing all available functions/members

Postby joswig » 02 Mar 2017, 22:08

A Polytope is a "big object" which has properties which are listed by the code given. The VERTICES form a "small object" of type Matrix. They do not have properties, so the code does not apply.

SimonKing
Posts: 14
Joined: 01 Mar 2017, 12:36

Re: Listing all available functions/members

Postby SimonKing » 02 Mar 2017, 22:19

A Polytope is a "big object" which has properties which are listed by the code given. The VERTICES form a "small object" of type Matrix. They do not have properties, so the code does not apply.
OK, I had expected to get an empty list in that case. But catching the error is of course fine for me.

Thank you!
Simon

User avatar
gawrilow
Main Author
Posts: 423
Joined: 25 Dec 2010, 17:40

Re: Listing all available functions/members

Postby gawrilow » 02 Mar 2017, 22:40

I've got an uneasy feeling that you'll spend a lot of time and efforts duplicating the polymake completion capabilities but at the end still not be able to offer an adequate user experience; there are simply too many edge cases you'd have to consider. But weirdly enough, I can't find the script file with jupiter support functions in our repository. Andreas: I remember how we wrote it together at the polymake workshop in 2016. Does it still sit in some private extension?

SimonKing
Posts: 14
Joined: 01 Mar 2017, 12:36

Re: Listing all available functions/members

Postby SimonKing » 02 Mar 2017, 22:45

I've got an uneasy feeling that you'll spend a lot of time and efforts duplicating the polymake completion capabilities but at the end still not be able to offer an adequate user experience; there are simply too many edge cases you'd have to consider. But weirdly enough, I can't find the script file with jupiter support functions in our repository. Andreas: I remember how we wrote it together at the polymake workshop in 2016. Does it still sit in some private extension?
Well, the tab completion is so that for now I am happy with it, and currently I work on different stuff. Next week Andreas can show me how things are done in jupyter.

Best regards,
Simon


Return to “Helpdesk”