Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/jlpolymake/containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,8 @@ struct WrapPolynomialBase
wrapped.method("set_var_names", [](const WrappedT& a, const Array<std::string>& 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);
Expand All @@ -645,6 +647,7 @@ struct WrapUniPolynomial
using coeffT = typename TypeWrapperT::type::coefficient_type;
using expT = typename TypeWrapperT::type::monomial_type;

wrapped.template constructor<const coeffT&>();
wrapped.template constructor<const pm::Vector<coeffT>&, const pm::Vector<expT>&>();

wrapped.module().set_override_module(pmwrappers::instance().module());
Expand Down
3 changes: 2 additions & 1 deletion include/jlpolymake/jlpolymake.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <polymake/TropicalNumber.h>
#include <polymake/IncidenceMatrix.h>
#include <polymake/Polynomial.h>
#include <polymake/PuiseuxFraction.h>
#include <polymake/polytope/solve_LP.h>
#include <polymake/SparseVector.h>
#include <polymake/Map.h>
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/jlpolymake/type_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/jlpolymake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
32 changes: 26 additions & 6 deletions src/polymake/type_setup.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down Expand Up @@ -84,6 +89,9 @@ sub QuadraticExtension {
sub TropicalNumber {
return template("TropicalNumber", @_);
}
sub PuiseuxFraction {
return template("PuiseuxFraction", @_);
}

sub Vector {
return () if @_ == 0;
Expand Down Expand Up @@ -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, ];
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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),
Expand Down
86 changes: 86 additions & 0 deletions src/type_puiseuxfraction.cpp
Original file line number Diff line number Diff line change
@@ -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<Rational,Rational>;
jlpolymake
.add_type<jlcxx::Parametric<jlcxx::TypeVar<1>,jlcxx::TypeVar<2>,jlcxx::TypeVar<3>>>("PuiseuxFraction")
.apply_combination<pm::PuiseuxFraction, jlcxx::ParameterList<pm::Min,pm::Max>, jlcxx::ParameterList<pm::Rational>, jlcxx::ParameterList<pm::Rational>>([&jlpolymake](auto wrapped){
using pf = typename decltype(wrapped)::type;
wrapped.template constructor<const unipoly&, const unipoly&>();
wrapped.template constructor<const unipoly&>();
wrapped.template constructor<const Rational&>();

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<pf>(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<std::string>& names) { a.set_var_names(names); });
wrapped.method("get_var_names", [](const pf& a) { return a.get_var_names(); });
});

}

}
Loading