## scripting

Questions and problems about using polymake go here.
nbela
Posts: 2
Joined: 12 Jul 2019, 00:01

### scripting

Hello Everyone,

I would like to use Polymake called from a script.
For example, if I copy-paste the following "script-snipplet"

Code: Select all

$p1=new Polytope(POINTS=>[[1, 0, 0, 0], [1, 2, 0, 0], [1, 0, 2, 0], [1, 0, 0, 2],[1,0,0,0]]);$p2=new Polytope(POINTS=>[[1, 0, 0, 0], [1, 0, 0, 1], [1, 0, 1, 0], [1, 1, 0, 0], [1, 0, 1, 1], [1, 1, 0, 1], [1, 1, 1, 0], [1, 1, 1, 1]]); $cp=conv([$p1,$p2]); print$cp->VOLUME; print $cp->N_LATTICE_POINTS;$w=rows($cp->LATTICE_POINTS); @strs={}; foreach(@$w){ @arr1=@{$_}; shift(@arr1);$str1= "{" . join(",",@arr1) . "}" ; push( @strs, $str1 ) ; }; shift(@strs); declare$fh; open($fh, '>', 'result.txt'); print$fh "{" . join(",", @strs) . "}" ; close $fh;  it works fine. I would need that something like polymake - <TEXTFILE instead of copy-paste. I tried to rewrite the above code, but Code: Select all use application 'Polymake'; use Polymake; use Polymake::User; use Polymake::Core::CPlusPlus; declare$p1, $p2,$cp; $p1=new Polytope(POINTS=>[[1, 0, 0, 0], [1, 2, 0, 0], [1, 0, 2, 0], [1, 0, 0, 2],[1,0,0,0]]);$p2=new Polytope(POINTS=>[[1, 0, 0, 0], [1, 0, 0, 1], [1, 0, 1, 0], [1, 1, 0, 0], [1, 0, 1, 1], [1, 1, 0, 1], [1, 1, 1, 0], [1, 1, 1, 1]]); $cp=conv([$p1,$p2]); print$cp->N_LATTICE_POINTS; print \$cp->VOLUME; exit();
does not work.
As you see I am new to Polymake, and Perl too and sorry if it is very simple.
What would be the correct Polymake script?

Thanks for any help in advance!
Bela

gawrilow
Main Author
Posts: 373
Joined: 25 Dec 2010, 17:40

### Re: scripting

You should not try to call polymake from a script, rather let it execute your script. The only change you need to give to your initial code snippet is to insert the line at the very beginning:

Code: Select all

use application "polytope";
and to introduce local variables with "my" or "declare" at the places of their first occurrence. Then you can run the script from the UNIX shell command line:

Code: Select all

polymake --script YOUR_SCRIPT_FILE
or from the polymake interactive shell:

Code: Select all

script("YOUR_SCRIPT_FILE");
I have a question to you in return: Apparently, you haven't found the documentation at https://polymake.org/doku.php/user_guid ... /scripting. Most probably it's our fault that it's hidden too far away or looks too scary for the beginners. Please help us to improve this and tell us how have you tried to obtain the information - did you navigate through menus (where?), try the site search (which keywords?) or anything else?

nbela
Posts: 2
Joined: 12 Jul 2019, 00:01

### Re: scripting

Thank you very much for your help.
I rewrote the script following your remarks and now it works (--script instead of -).

Documentation: actually, I found it, this is why I tried to insert use application 'Polymake'; in the beginning.
I did not read it from the beginning to the end, I just tried to copy the code from appropriate paragraphs,
but this, with no knowledge about Perl, was useless.
Speaking for myself, I would find some (complete) examples very useful (google found nothing).