Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346#include "polymake_tropical.h"123Obj REAL_TROPICAL_HYPERSURFACE_BY_MONOMS_AND_COEFFICIENTS( Polymake_Data* data, Obj monomials, Obj coefficients ){45#ifdef MORE_TESTS6if( ! IS_PLIST( monomials ) ){7ErrorMayQuit( "not a plain list", 0, 0);8return NULL;9}10#endif1112int len = LEN_PLIST( monomials );13Obj akt = ELM_PLIST( monomials, 1 );14Obj elem;1516#ifdef MORE_TESTS17if( !IS_PLIST( akt ) ){18ErrorMayQuit( "not a plain list", 0, 0);19return NULL;20}21#endif2223#ifdef MORE_TESTS24if( !IS_PLIST( coefficients ) ){25ErrorMayQuit( "coefficients not a plain list", 0, 0);26return NULL;27}28#endif29303132int len_elem = LEN_PLIST( akt );33data->main_polymake_session->set_application("tropical");3435pm::Integer* ratarray;36ratarray = new pm::Integer[(len)*(len_elem)];3738pm::Integer* coeffarray;39coeffarray = new pm::Integer[len];4041for(int i=1;i<=len;i++){42akt = ELM_PLIST( monomials, i );43#ifdef MORE_TESTS44if( !IS_PLIST( akt ) ){45delete [] ratarray;46delete [] coeffarray;47ErrorMayQuit( "not a plain list", 0, 0);48return NULL;49}50if( LEN_PLIST( akt ) != len_elem ){51delete [] ratarray;52delete [] coeffarray;53ErrorMayQuit( "monomials are not of the same lenght", 0, 0);54return NULL;55}56#endif5758for(int j = 1; j <= len_elem; j++){59elem = ELM_PLIST( akt, j);6061#ifdef MORE_TESTS62if( ! IS_INTOBJ( elem ) ){63delete [] ratarray;64delete [] coeffarray;65ErrorMayQuit( "some entries are not integers", 0, 0);66return NULL;67}68#endif6970ratarray[(i-1)*(len_elem)+j-1] = INT_INTOBJ( elem );71}7273elem = ELM_PLIST( coefficients, i );7475#ifdef MORE_TESTS76if( ! IS_INTOBJ( elem ) ){77delete [] ratarray;78delete [] coeffarray;79ErrorMayQuit( "some entries are not integers", 0, 0);80return NULL;81}82#endif8384coeffarray[ i - 1 ] = INT_INTOBJ( elem );8586}8788pm::Matrix<pm::Integer>* matr = new pm::Matrix<pm::Integer>(len,len_elem,ratarray);89delete [] ratarray;90pm::Vector<pm::Integer>* coeff = new pm::Vector<pm::Integer>(len,coeffarray);91delete [] coeffarray;92perlobj* p = new perlobj("TropicalHypersurface");93p->take("MONOMIALS") << *matr;94p->take("COEFFICIENTS") << *coeff;95delete matr;96delete coeff;97elem = NewPolymakeExternalObject( T_POLYMAKE_EXTERNAL_TROPICAL_HYPERSURFACE );98POLYMAKEOBJ_SET_PERLOBJ( elem, p );99return elem;100}101102103Obj REAL_MONOMIALS_OF_HYPERSURFACE( Polymake_Data* data, Obj hypersurf){104105#ifdef MORE_TESTS106if(! IS_POLYMAKE_TROPICAL_HYPERSURFACE(hypersurf) ){107ErrorMayQuit(" parameter is not a hypersurface.",0,0);108return NULL;109}110#endif111112perlobj* polyobj = PERLOBJ_POLYMAKEOBJ( hypersurf );113data->main_polymake_session->set_application_of(*polyobj);114pm::Matrix<pm::Rational> matr;115try{116pm::Matrix<pm::Rational> matr_temp = polyobj->give("MONOMIALS");117matr = matr_temp;118}119120POLYMAKE_GAP_CATCH121122UInt l = 10;123Obj RETLI = NEW_PLIST( T_PLIST , l );124SET_LEN_PLIST(RETLI, l );125UInt k = 0;126Obj LIZeil;127UInt matr_cols = matr.cols();128for(int i = 0;i<matr.rows();i++){129if( ++k > l){130GROW_PLIST(RETLI,l*=2);131SET_LEN_PLIST(RETLI, l );132}133LIZeil = NEW_PLIST( T_PLIST, matr.cols());134SET_LEN_PLIST( LIZeil , matr_cols );135for(int j = 0;j<matr.cols();j++){136SET_ELM_PLIST(LIZeil,j+1,INTOBJ_INT((matr(i,j)).to_int()));137}138SET_ELM_PLIST(RETLI,k,LIZeil);139CHANGED_BAG(RETLI);140}141SHRINK_PLIST(RETLI,k);142SET_LEN_PLIST(RETLI, k );143return RETLI;144145}146147Obj REAL_TROPICAL_POLYTOPE_BY_POINTS( Polymake_Data* data, Obj points ){148if( ! IS_PLIST( points ) ){149ErrorMayQuit( "not a plain list", 0, 0);150return NULL;151}152153int len = LEN_PLIST( points );154Obj akt = ELM_PLIST( points, 1 );155Obj elem;156157#ifdef MORE_TESTS158if( !IS_PLIST( akt ) ){159ErrorMayQuit( "first ray is not a plain list", 0, 0);160return NULL;161}162#endif163164int len_elem = LEN_PLIST( akt );165data->main_polymake_session->set_application("tropical");166167pm::Integer* ratarray;168ratarray = new pm::Integer[(len)*(len_elem)];169170for(int i=0;i<len;i++){171akt = ELM_PLIST( points, i+1 );172#ifdef MORE_TESTS173if( !IS_PLIST( akt ) ){174delete [] ratarray;175ErrorMayQuit( "one point is not a plain list", 0, 0);176return NULL;177}178if( LEN_PLIST( akt ) != len_elem ){179delete [] ratarray;180ErrorMayQuit( "points are not of the same lenght", 0, 0);181return NULL;182}183#endif184for(int j = 0; j < len_elem; j++){185elem = ELM_PLIST( akt, j+1);186#ifdef MORE_TESTS187if( ! IS_INTOBJ( elem) ){188delete [] ratarray;189ErrorMayQuit( "some entries are not integers", 0, 0);190return NULL;191}192#endif193ratarray[ ( i * len_elem ) + j] = INT_INTOBJ( elem );194}195196}197198pm::Matrix<pm::Integer>* matr = new pm::Matrix<pm::Integer>(len,len_elem,ratarray);199delete [] ratarray;200perlobj* p = new perlobj("TropicalPolytope");201p->take("POINTS") << *matr;202delete matr;203elem = NewPolymakeExternalObject(T_POLYMAKE_EXTERNAL_POLYTOPE);204205POLYMAKEOBJ_SET_PERLOBJ(elem, p);206207return elem;208}209210211212