diff --git a/include/jlpolymake/containers.h b/include/jlpolymake/containers.h index f9d9a32..2ee6e5e 100644 --- a/include/jlpolymake/containers.h +++ b/include/jlpolymake/containers.h @@ -630,6 +630,8 @@ struct WrapPolynomialBase wrapped.method("set_var_names", [](const WrappedT& a, const Array& names) { a.set_var_names(names); }); wrapped.method("get_var_names", [](const WrappedT& a) { return a.get_var_names(); }); wrapped.method("nvars", [] (const WrappedT& a) -> pm::Int { return a.n_vars(); }); + wrapped.method("deg", [] (const WrappedT& a) { return a.deg(); }); + wrapped.method("lower_deg", [] (const WrappedT& a) { return a.lower_deg(); }); wrapped.module().unset_override_module(); wrap_common(wrapped); @@ -645,6 +647,7 @@ struct WrapUniPolynomial using coeffT = typename TypeWrapperT::type::coefficient_type; using expT = typename TypeWrapperT::type::monomial_type; + wrapped.template constructor(); wrapped.template constructor&, const pm::Vector&>(); wrapped.module().set_override_module(pmwrappers::instance().module()); diff --git a/include/jlpolymake/jlpolymake.h b/include/jlpolymake/jlpolymake.h index 0675617..90f44aa 100644 --- a/include/jlpolymake/jlpolymake.h +++ b/include/jlpolymake/jlpolymake.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,7 @@ #define JLPOLYMAKE_VERSION_MAJOR 0 #define JLPOLYMAKE_VERSION_MINOR 14 -#define JLPOLYMAKE_VERSION_PATCH 5 +#define JLPOLYMAKE_VERSION_PATCH 6 #define __JLPOLYMAKE_STR_HELPER(x) #x #define __JLPOLYMAKE_STR(x) __JLPOLYMAKE_STR_HELPER(x) diff --git a/include/jlpolymake/type_modules.h b/include/jlpolymake/type_modules.h index e966321..ce99f8d 100644 --- a/include/jlpolymake/type_modules.h +++ b/include/jlpolymake/type_modules.h @@ -24,6 +24,8 @@ void add_rational(jlcxx::Module& jlpolymake); void add_tropicalnumber(jlcxx::Module& jlpolymake); void add_quadraticextension(jlcxx::Module& jlpolymake); +void add_puiseuxfraction(jlcxx::Module& jlpolymake); + void add_homologygroup(jlcxx::Module& jlpolymake); void add_incidencematrix(jlcxx::Module& jlpolymake); void add_switchtable(jlcxx::Module& jlpolymake); diff --git a/src/jlpolymake.cpp b/src/jlpolymake.cpp index cb0a2e1..12b3b20 100644 --- a/src/jlpolymake.cpp +++ b/src/jlpolymake.cpp @@ -74,6 +74,8 @@ JLCXX_MODULE define_module_polymake(jlcxx::Module& jlpolymake) add_decoration(jlpolymake); + add_puiseuxfraction(jlpolymake); + // contains nodemap for decoration (depends on set and decoration) wrap_types_extra(jlpolymake); diff --git a/src/polymake/type_setup.pl b/src/polymake/type_setup.pl index c1a6e76..a2108bc 100644 --- a/src/polymake/type_setup.pl +++ b/src/polymake/type_setup.pl @@ -44,10 +44,15 @@ sub joincxxt { sub jointo { return lc(join("_",@_)); } sub template { - my ($name, $arr1, $arr2) = @_; - check_type($arr1, $arr2); + my ($name, $arr1, $arr2, $arr3) = @_; + check_type($arr1, $arr2, $arr3); my @names = ref($name) eq "ARRAY" ? @$name : (($name) x 4); - if (defined($arr2)) { + if (defined($arr3)) { + return [ joinname($names[0],$arr1->[0],$arr2->[0],$arr3->[0]), + joincxxt($names[1],$arr1->[1],$arr2->[1],$arr3->[1]), + joinjlt ($names[2],$arr1->[2],$arr2->[2],$arr3->[2]), + jointo ($names[3],$arr1->[3],$arr2->[3],$arr3->[3])]; + } elsif (defined($arr2)) { return [ joinname($names[0],$arr1->[0],$arr2->[0]), joincxxt($names[1],$arr1->[1],$arr2->[1]), joinjlt ($names[2],$arr1->[2],$arr2->[2]), @@ -84,6 +89,9 @@ sub QuadraticExtension { sub TropicalNumber { return template("TropicalNumber", @_); } +sub PuiseuxFraction { + return template("PuiseuxFraction", @_); +} sub Vector { return () if @_ == 0; @@ -180,7 +188,7 @@ sub EdgeMap { my $scalars = [ Int, Integer, Rational, double, QuadraticExtension(Rational), TropicalNumber(Min,Rational), - TropicalNumber(Max,Rational) + TropicalNumber(Max,Rational), ]; my $simplecontainers = [ \&Matrix, \&Vector, \&Array, ]; @@ -256,14 +264,18 @@ sub EdgeMap { UniPolynomial(Int,Int), UniPolynomial(Integer,Int), UniPolynomial(Rational,Int), - UniPolynomial(Rational,Rational), + UniPolynomial(double,Int), UniPolynomial(QuadraticExtension(Rational),Int), + UniPolynomial(Rational,Rational), Polynomial(Int,Int), Polynomial(Integer,Int), Polynomial(Rational,Int), - Polynomial(Rational,Rational), Polynomial(double,Int), Polynomial(QuadraticExtension(Rational),Int), + Polynomial(Rational,Rational), + + PuiseuxFraction(Min,Rational,Rational), + PuiseuxFraction(Max,Rational,Rational), Matrix(Polynomial(Rational,Int)), Vector(Polynomial(Rational,Int)), @@ -353,6 +365,14 @@ sub EdgeMap { $core_calls = $wrap_calls; $wrap_calls = []; +my @pft = map {PuiseuxFraction($_,Rational,Rational)} (Min,Max); +for my $c (@$simplecontainers) { + add_types(map {$c->($_)} @pft); +} +add_types(map { Matrix("Sparse", $_) } @pft); +add_types(map { Vector("Sparse", $_) } @pft); + + add_types( BasicDecoration, NodeMap(BasicDecoration), diff --git a/src/type_puiseuxfraction.cpp b/src/type_puiseuxfraction.cpp new file mode 100644 index 0000000..ec86a17 --- /dev/null +++ b/src/type_puiseuxfraction.cpp @@ -0,0 +1,86 @@ +#include "jlpolymake/jlpolymake.h" + +#include "jlpolymake/tools.h" + +#include "jlpolymake/functions.h" + +#include "jlpolymake/type_modules.h" + +namespace jlpolymake { + +void add_puiseuxfraction(jlcxx::Module& jlpolymake) +{ + + using unipoly = pm::UniPolynomial; + jlpolymake + .add_type,jlcxx::TypeVar<2>,jlcxx::TypeVar<3>>>("PuiseuxFraction") + .apply_combination, jlcxx::ParameterList, jlcxx::ParameterList>([&jlpolymake](auto wrapped){ + using pf = typename decltype(wrapped)::type; + wrapped.template constructor(); + wrapped.template constructor(); + wrapped.template constructor(); + + wrapped.method( + "numerator", + [](const pf& r) { return unipoly(numerator(r)); }); + wrapped.method( + "denominator", + [](const pf& r) { return unipoly(denominator(r)); }); + wrapped.method("show_small_obj", + [](const pf& r) { + return show_small_object(r, true); + }); + wrapped.method("take", + [](pm::perl::BigObject& p, const std::string& s, const pf& r) { + p.take(s) << r; + }); + jlpolymake.set_override_module(jlpolymake.julia_module()); + wrapped.method("<", [](const pf& a, const pf& b) { return a < b; }); + wrapped.method("<", [](const pm::Rational& a, const pf& b) { return a < b; }); + wrapped.method("<", [](const pf& a, const pm::Rational& b) { return a < b; }); + wrapped.method("<=", [](const pf& a, const pf& b) { return a <= b; }); + wrapped.method("<=", [](const pf& a, const pm::Rational& b) { return a <= b; }); + wrapped.method("<=", [](const pm::Rational& a, const pf& b) { return a <= b; }); + wrapped.method("-", [](const pf& a, const pf& b) { return a - b; }); + wrapped.method("-", [](const pm::Rational& a, const pf& b) { return a - b; }); + wrapped.method("-", [](const pf& a, const pm::Rational& b) { return a - b; }); + // unary minus + wrapped.method("-", [](const pf& a) { return -a; }); + + wrapped.method("//", [](const pf& a, const pf& b) { return a / b; }); + + wrapped.method("==", [](const pf& a, const pf& b) { + return a == b; }); + wrapped.method("==", [](const pf& a, const pm::Rational& b) { + return a == b; }); + wrapped.method("==", [](const pm::Rational& a, const pf& b) { + return a == b; }); + // the symmetric definitions are on the julia side + wrapped.method("+", [](const pf& a, const pf& b) { + return a + b; }); + wrapped.method("+", [](const pf& a, const pm::Rational& b) { + return a + b; }); + wrapped.method("+", [](const pm::Rational& a, const pf& b) { + return a + b; }); + wrapped.method("*", [](const pf& a, const pf& b) { + return a * b; }); + wrapped.method("*", [](const pf& a, const pm::Rational& b) { + return a * b; }); + wrapped.method("*", [](const pm::Rational& a, const pf& b) { + return a * b; }); + jlpolymake.unset_override_module(); + wrapped.method("cmp", [](const pf& a, const pf& b) { + return a.compare(b); }); + wrapped.method("val", [](const pf& a) { + return a.val(); + }); + wrapped.method("get_hash", [](const pf& a) { + return a.get_hash(); + }); + wrapped.method("set_var_names", [](const pf& a, const Array& names) { a.set_var_names(names); }); + wrapped.method("get_var_names", [](const pf& a) { return a.get_var_names(); }); + }); + +} + +}