1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
|
# Copyright (c) 1997-2024
# Ewgenij Gawrilow, Michael Joswig, and the polymake team
# Technische Universität Berlin, Germany
# https://polymake.org
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version: http://www.gnu.org/licenses/gpl.txt.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#-------------------------------------------------------------------------------
# persisted polynomial variable names by package
custom %polynomial_var_names=();
function polynomial_type($) { undef }
# @category Algebraic Types
# @tparam Coefficient default: [[Rational]]
# @tparam Exponent default: [[Int]]
declare property_type Polynomial<Coefficient=Rational, Exponent=Int> \
: upgrades(Coefficient) : c++ (include => "polymake/Polynomial.h", default_constructor => 'Deserializing') {
method construct(Int) : c++;
# coefficients as vector, exponents as sparse matrix =>
method construct(*,*) : c++;
type_method parse { &parse_polynomial }
# with explicitly given number of variables
method construct(String, Int) { &parse_polynomial; }
operator neg @arith ^ ^= @compare : c++;
method pow(*) : operator ** : c++;
# The degree of the polynomial
# @return Int
user_method deg() : c++;
# Check if the polynomial is homogeneous
# @return Bool
user_method homogeneous() : c++;
# The exponent of the leading monomial.
# @return Int
user_method lm() : c++;
# The __leading coefficient__.
# @return Int
user_method lc() : c++;
# The __constant coefficient__.
# @return Int
user_method constant_coefficient() : c++;
# Print a polynomial with terms sorted according to a given [[Matrix]] //m//.
# @param Matrix m
user_method print_ordered(Matrix<Exponent>) : c++;
# The initial form with respect to a weight-vector //v//
# @param Vector<Exponent> v weights
# @return Polynomial
user_method initial_form(Vector<Exponent>) : c++;
# The matrix of all exponent vectors (row-wise).
# The sorting agrees with [[coefficients_as_vector]].
# @return SparseMatrix<Exponent>
user_method monomials_as_matrix() : c++;
# Number of variables
# @return Int
user_method n_vars() : c++;
# The polynomial is zero.
# @return Bool
user_method trivial() : c++;
# The vector of all coefficients.
# The sorting agrees with [[monomials_as_matrix]].
# @return Vector<Coefficient>
user_method coefficients_as_vector() : c++;
# Substitute a list of values in a [[Polynomial]] with [[Int]] exponents.
# Either with an array of values, or with a [[Map]] mapping variable indices
# to values.
# @example
# > $pm = new Polynomial("1+x_0^2*x_3+x_1+3*x_3");
# > print $pm->substitute([0,11,2,3]);
# | 21
# > $map = new Map<Int,Rational>([0,5/2],[1,1/5],[2,new Rational(7/3)]);
# > print $pm->substitute($map);
# | 37/4*x_3 + 6/5
user_method substitute(*) : c++;
# Project the [[Polynomial]] to the given list of variables.
# The number of variables will be reduced to the number of indices,
# i.e. the variables will be renamed.
# Keeping the names of the variables is possible by using [[substitute]]
# with a [[Map]].
# @return Polynomial
# @example
# > $pm = new Polynomial("1+x_0^2*x_3+x_1+3*x_3");
# > print $pm->project([1,3]);
# | x_0 + 4*x_1 + 1
user_method project(*) : c++;
# Map the variables of the [[Polynomial]] to the given indices.
# The same index may bei given multiple times and also some may be omitted
# for embedding with a higher number of variables.
# The length of the given [[Array]] must be the same as the number of variables
# of the original polynomial.
# @param Array<Int> indices indices of the target variables
# @param Int nvars new number of variables, default: maximal index
# @return Polynomial
# @example
# > $pm = new Polynomial("1+x_0^2*x_3+x_1+3*x_3");
# > print $pm->mapvars([0,1,1,4],6);
# | x_0^2*x_4 + x_1 + 3*x_4 + 1
user_method mapvars(*;$=-1) : c++;
# Embed the [[Polynomial]] in a polynomial ring with the given
# number of variables.
# The old variables will be put at the beginning, for more control use [[mapvars]].
# @param Int nvars new number of variables
# @return Polynomial
# @example
# > $pm = new Polynomial("1+x_0^2*x_3+x_1+3*x_3");
# > print $pm->project([1,3]);
# | x_0 + 4*x_1 + 1
user_method embed($) {
my ($this, $n) = @_;
croak("embed: number of variables must be at least the current n_vars")
if ($n < $this->n_vars);
return $this->mapvars(sequence(0,$this->n_vars),$n);
}
# construct a monomial of degree 1 with a given variable
# @param Int var_index index of the variable
# @param Int n_vars number of variables
user_method monomial(:static, Int, Int) : c++;
# set the variable names
user_method get_var_names(:static) : c++;
# set the variable names
user_method set_var_names(:static, $) : c++;
# reset the variable names according to the default naming scheme
user_method reset_var_names(:static) : c++;
type_method init {
my ($proto) = @_;
if (defined(my $names = $polynomial_var_names{$proto->pkg})) {
set_var_names($proto, $names);
}
}
}
function polynomial_type(Polynomial) { $_[0]->type }
# @category Algebraic Types
# A class for __univariate__ polynomials.
# @tparam Coefficient default: [[Rational]]
# @tparam Exponent default: [[Int]]
declare property_type UniPolynomial<Coefficient=Rational, Exponent=Int> \
: upgrades(Coefficient) : c++ (include => "polymake/RationalFunction.h") {
method construct(type_upgrades_to<Coefficient>) : c++;
# coefficients, exponents =>
method construct(*,*) : c++;
type_method parse { &parse_polynomial }
operator neg @arith ^ ^= % %= @compare : c++;
method pow(*) : operator ** : c++;
# The highest degree occurring in the polynomial.
# @return Exponent
user_method deg() : c++;
# The lowest degree occurring in the polynomial.
# @return Exponent
user_method lower_deg() : c++;
# The __leading coefficient__.
# @return Int
user_method lc() : c++;
# The __constant coefficient__.
# @return Int
user_method constant_coefficient() : c++;
# Number of variables
user_method n_vars() {
return 1;
}
# Print a polynomial with terms sorted according to //exponent*x//.
# @param Exponent x
user_method print_ordered($) : c++;
# Approximate evaluation of the polynomial at a [[Float]] //x//.
# @param Float x
# @return Float
user_method evaluate_float($) : c++;
# Evaluate a [[UniPolynomial]] at a number (//x^exp//).
# Note that for non-integral exponents this may require intermediate floating point
# computations depending on the input:
# Let //explcm// be the lcm of the denominators of all exponents.
# If there are no denominators or //explcm// divides //exp//, then the evaluation
# is computed exactly.
# Otherwise, some rational number close to the root //(x^exp)^-explcm// will be chosen
# via an intermediate floating point number.
# @param Coefficient x
# @param Exponent exp (default: 1)
# @return Coefficient
user_method evaluate(*;$=1) : c++;
# Substitute some //value// in a [[UniPolynomial]] with [[Int]] exponents.
# When all exponents are positive the argument can be any scalar, matrix or polynomial type.
# With negative exponents, polynomials are not supported (use [[RationalFunction]] instead)
# and any given matrix must be invertible
user_method substitute(*) : c++;
# The vector of all coefficients.
# The sorting agrees with [[monomials_as_vector]].
# @return Vector<Coefficient>
user_method coefficients_as_vector() : c++;
# The vector of all exponents.
# The order agrees with [[coefficients_as_vector]].
# @return Vector<Exponent>
user_method monomials_as_vector() : c++;
# create a monomial of degree 1
user_method monomial(:static) : c++;
# get the variable name
user_method get_var_names(:static) : c++;
# set the variable name
user_method set_var_names(:static, $) : c++;
# reset the variable name according to the default naming scheme
user_method reset_var_names(:static) : c++;
type_method init {
my ($proto) = @_;
if (defined(my $names = $polynomial_var_names{$proto->pkg})) {
set_var_names($proto, $names);
}
}
}
function polynomial_type(UniPolynomial) { $_[0]->type }
# @category Data Conversion
# Explicit conversion to a different coefficient type.
# @param Polynomial m
# @tparam Target
# @return Polynomial<Target>
user_function convert_to<Coefficient>(Polynomial) : c++ {
if ($_[0]->type->params->[0]==typeof Coefficient) {
return $_[0];
}
}
# @category Data Conversion
# Explicit conversion to a different coefficient type.
# @param UniPolynomial m
# @tparam Target
# @return UniPolynomial<Target>
user_function convert_to<Coefficient>(UniPolynomial) : c++ {
if ($_[0]->type->params->[0]==typeof Coefficient) {
return $_[0];
}
}
# @category Arithmetic
# Get the current list of variable names used for pretty printing and string parsing of the given polynomial class
# @return Array<String>
user_function get_var_names<PolynomialType>[ polynomial_type(PolynomialType) ]() {
polynomial_type(typeof PolynomialType)->pkg->get_var_names;
}
# @category Arithmetic
# Set the list of variable names used for pretty printing and string parsing of the given polynomial class
#
# When the number of variables in a polynomial is greater than the size of the name list, the excess variable names
# are produced from a template "${last_var_name}_{EXCESS}", where EXCESS starts at 0 for the variable corresponding
# to the last name in the list. If the last name already has a form "{Name}_{Number}", the following variables are enumerated
# starting from that Number plus 1.
#
# The default naming scheme consists of a single letter "x", "y", "z", "u", "v", or "w" chosen according to the nesting depth
# of polynomial types in the coefficient type. That is, variables of simple polynomials (those with pure numerical coefficients)
# are named x_0, x_1, ..., variables of polynomials with simple polynomial coefficients are named y_0, y_1, etc.
#
# @param String names ... variable names; may also be bundled in an array
# an empty list resets to the default naming scheme
user_function set_var_names<PolynomialType>[ polynomial_type(PolynomialType) ](@) {
my $pkg = polynomial_type(typeof PolynomialType)->pkg;
if (@_ == 0) {
delete $polynomial_var_names{$pkg};
$pkg->reset_var_names;
return;
}
my $names = prepare_var_names(@_, $pkg);
$polynomial_var_names{$pkg} = $names;
$pkg->set_var_names($names);
}
package VarNameSaver;
use Polymake::Struct(
[ new => '$@' ],
[ '$pkg' => '#1' ],
[ '@names' => '@' ],
);
sub DESTROY {
my ($self)=@_;
if (@{$self->names}) {
$self->pkg->set_var_names($self->names);
} else {
$self->pkg->reset_var_names;
}
}
package application;
my $var_name_saver;
# @category Arithmetic
# Set the list of variable names for given polynomial class temporarily.
# The existing name list or the default scheme is restored at the end of the current user cycle,
# similarly to [[prefer_now]].
# @param String names ... variable names, see [[set_var_names]].
user_function local_var_names<PolynomialType>[ polynomial_type(PolynomialType) ](@) {
my $pkg = polynomial_type(typeof PolynomialType)->pkg;
my $names = prepare_var_names(@_, $pkg);
local with($Scope->locals) {
local scalar $var_name_saver = new VarNameSaver($pkg, exists $polynomial_var_names{$pkg} ? @{ $pkg->get_var_names } : ());
local $polynomial_var_names{$pkg} = $names;
}
if (@$names) {
$pkg->set_var_names($names);
} else {
$pkg->reset_var_names;
}
}
sub prepare_var_names {
my $pkg=pop;
my $names;
if (@_>1 || is_string($_[0])) {
$names=[ @_ ];
} else {
$names=shift;
}
if (instanceof Polynomial($pkg)) {
# sanity checks for duplicates and conflicts with the trailing pattern
my %seen;
my $excess_pattern=qr/^$names->[-1]_\d+$/;
my $cnt=@$names;
foreach (@$names) {
/^($id_re)(?<!_)$/o or croak( "invalid variable name $_: must be an ID without trailing underscore" );
$seen{$_}++ and croak( "duplicate variable name $_" );
--$cnt && /$excess_pattern/ and croak( "variable name $_ conflicts with the trailing name pattern" );
}
} elsif (@$names != 1) {
croak( "more than one variable name specified for a univariate polynomial class" );
}
$names
}
# @category Arithmetic
# Create degree one monomials of the desired polynomial type.
# @param Int n The number of variables
# @tparam Coefficient The polynomial coefficient type. Rational by default.
# @tparam Exponent The exponent type. Int by default.
# @return UniPolynomial<Coefficient,Exponent> when //n// == 1, Polynomial<Coefficient,Exponent> when //n// > 1
user_function monomials<Coefficient=Rational, Exponent=Int>($) {
my ($n)=@_;
if ($n <= 0) {
croak("Number of variables needs to be at least 1");
} elsif ($n == 1) {
(typeof UniPolynomial<Coefficient, Exponent>)->pkg->monomial;
} else {
my $p=typeof Polynomial<Coefficient, Exponent>;
map { $p->pkg->monomial($_, $n) } (0 .. $n-1);
}
}
# Parse a polynomial-like expression and produce a Polynomial or UniPolynomial object of the desired type.
#
# All ID-like names occurring in the string are interpreted as variable names; they must match the current
# variable name lists establshed for the polynomial type itself and, recursively, its coefficient type(s)
#
# The following syntactical sloppiness is allowed:
# - omitted multiplication operator '*' is inserted in subexpressions like "5x", "5 x", "x y", "x (u-w)" etc.
# - omitted power operator '**' is inserted in subexpressions like "x5", "x 5", "(x+y)2" etc.
# - alternative power operator '^' is assumed to bind stronger than multiplicative operators, unlike in C++ or perl
# - free term given as a numeric literal is converted to the coefficient type even when the implicit conversion
# in general is not allowed, like for [[TropicalNumber]].
sub parse_polynomial {
my ($proto, $string, $prescribed_num_vars)=@_;
# first, descend through coefficient types and collect all variable names;
# no conflicts should arise
my (%all_varnames, %patterns, @num_vars, @monoms);
do {
my $layer=@num_vars;
my $varnames=get_var_names<$proto>();
my $index=0;
foreach (@$varnames) {
($all_varnames{$_} &&= croak( "variable name $_ occur in different polynomial types, unambiguous parsing not possible" )) //= [ $layer, $index ];
} continue { ++$index }
if (instanceof Polynomial($proto->pkg)) {
$patterns{$varnames->[-1]}=[ $layer, $index-1 ];
}
push @num_vars, [ $proto, 0 ];
$proto=$proto->params->[0];
} while (polynomial_type($proto));
# recognize agglutinated monomials like x5y3 if they do not occur as variable names on their own
pos($string)=0;
while ($string =~ /\G .*? (([a-zA-Z]+)(\d+)(?:$id_re)?)/gxo) {
if (!exists $all_varnames{$1}) {
my ($monomial, $added);
if (exists $all_varnames{"$2$3"}) {
$monomial="$2$3 ";
$added=1;
} elsif (exists $all_varnames{$2}) {
$monomial="$2**$3";
$added=2;
}
if ($added) {
substr($string, $-[2], $+[3]-$-[2])=$monomial;
pos($string)=$+[3]+$added;
}
}
}
# insert omitted * and ** operators
$string =~ s{(?: [\w\)]) \s* \K (?= [a-zA-Z\(])}{*}gx;
$string =~ s{(?: [a-zA-Z\)]) \s* \K (?= \d)}{**}gx;
# replace ^ with ** because of preference rules, embrace rational exponents
$string =~ s{\^}{**}g;
$string =~ s{\*\*\s* \K (-?\d+/\d+)}{($1)}gx;
# replace every ID-like word with a reference to @monoms, update the number of variables
$string =~ s{$id_re}{
my $name=$&;
my ($layer, $index);
if (defined (my $var=$all_varnames{$name})) {
($layer, $index)=@$var;
} elsif ($name =~ /_(\d+)$/ && defined ($var=$patterns{$`})) {
($layer, $index)=@$var;
$index+=$1;
} else {
croak( "invalid variable name $name" );
}
if ($layer==0 && defined($prescribed_num_vars) && $index >= $prescribed_num_vars) {
croak( "variable $name exceeds the prescribed number of variables for type ", $num_vars[$layer]->[0]->full_name );
}
assign_max($num_vars[$layer]->[1], $index+1);
"\$monoms[$layer]->[$index]"
}goe;
# create the monomials
if (defined($prescribed_num_vars) && $num_vars[0]->[1] > 0) {
$num_vars[0]->[1]=$prescribed_num_vars;
}
@monoms=map { my @coeff_exp_types=@{$_->[0]->params}; $_->[1]>0 ? [ monomials<@coeff_exp_types>($_->[1]) ] : undef } @num_vars;
# recognize the constant free term and insert the explicit constructor call if the coeffificient type
my $simplest_coeff_type=$num_vars[-1]->[0]->params->[0];
if ($simplest_coeff_type->upgrades->{typeof Rational} > 0) {
$string =~ s{(?: [-+] | ^ ) \s* \K (\d+ (?:/\d+)?) (?= \s* (?: [-+] | $))}
{\$simplest_coeff_type->construct->($1)}xsg;
}
# now the string should contain a valid perl expression and can be evaluated directly
my $result=eval $string;
die $@ if $@;
defined($monoms[0])
? # the expression contains monomials of the target type
$result
: # the expression is a coefficient of the degree zero monomial
$_[0]->construct->($result, defined($prescribed_num_vars) ? $prescribed_num_vars : ());
}
# @category Arithmetic
# Returns the __greatest common divisor__ of two univariate polynomials.
# @param UniPolynomial p
# @param UniPolynomial q
# @return UniPolynomial
# @example We create two UniPolynomials with said coefficient and exponent type:
# > $p = new UniPolynomial<Rational,Int>([2,2],[3,2]);
# > $q = new UniPolynomial<Rational,Int>([6,4],[4,2]);
# Printing them reveals what the constructor does:
# > print $p;
# | 2*x^3 + 2*x^2
# > print $q;
# | 6*x^4 + 4*x^2
# Now we can calculate their gcd:
# > print gcd($p,$q);
# | x^2
user_function gcd(UniPolynomial, UniPolynomial) : c++;
# @category Algebraic Types
# @tparam Coefficient default: [[Rational]]
# @tparam Exponent default: [[Int]]
declare property_type RationalFunction<Coefficient=Rational, Exponent=Int> \
: upgrades( UniPolynomial<Coefficient, Exponent> ) : c++ (include => "polymake/RationalFunction.h") {
method construct() : c++;
method construct(type_upgrades_to<Coefficient>) : c++;
method construct(*,*) : c++;
operator neg @arith @eq : c++;
}
function polynomial_type<Coefficient, Exponent>(RationalFunction<Coefficient, Exponent>) { typeof UniPolynomial<Coefficient, Exponent> }
# @category Arithmetic
# Returns the __numerator__ of a [[RationalFunction]] //f//.
# @param RationalFunction f
# @return Polynomial
user_function numerator(RationalFunction:anchor) : c++;
# @category Arithmetic
# Returns the __denominator__ of a [[RationalFunction]] //f//.
# @param RationalFunction f
# @return Polynomial
user_function denominator(RationalFunction:anchor) : c++;
# @category Algebraic Types
# @tparam MinMax type of tropical addition: either [[Min]] or [[Max]]
# @tparam Coefficient default: [[Rational]]
# @tparam Exponent default: [[Rational]]
declare property_type PuiseuxFraction<MinMax, Coefficient=Rational, Exponent=Rational> \
: upgrades( Coefficient ) : c++ (include => "polymake/PuiseuxFraction.h") {
method construct(type_upgrades_to< RationalFunction<Coefficient,Exponent> >) : c++;
method construct(type_upgrades_to< UniPolynomial<Coefficient,Exponent> >, type_upgrades_to< UniPolynomial<Coefficient,Exponent> >) : c++;
operator neg @arith @compare : c++;
# The __valuation__.
# @return TropicalNumber<MinMax>
# @example
# > $x = monomials<Rational,Rational>(1);
# > print new PuiseuxFraction<Max>(2*$x*$x-$x+2)->val;
# | 2
# @example [application polytope]
# The valuation can also be applied to Containers via convert_to
# > $m = long_and_winding(3)->FACETS;
# > print convert_to<TropicalNumber<Max>>($m);
# | (7) (0 2) (1 0)
# | (7) (0 1) (2 0)
# | (7) (1 1) (3 0)
# | (7) (2 1) (3 0)
# | (7) (1 1/2) (2 1/2) (4 0)
# | (7) (3 1) (5 0)
# | (7) (4 1) (5 0)
# | (7) (3 3/4) (4 3/4) (6 0)
# | (7) (5 0)
# | (7) (6 0)
user_method val() : c++;
}
# Evaluate a [[PuiseuxFraction]] at a [[Rational]] number (//x^exp//).
# Let //explcm// be the lcm of the denominators of all exponents.
# If there are no denominators or //explcm// divides //exp//, then the evaluation
# is computed exactly.
# Otherwise, some rational number close to the root //(x^exp)^-explcm// will be chosen
# via an intermediate floating point number.
# @param PuiseuxFraction f
# @param __Coefficient__ x
# @param Int exp (default: 1)
# @return __Coefficient__
user_function evaluate(PuiseuxFraction, *; $=1) : c++;
# Evaluate all [[PuiseuxFraction]]s in a [[Matrix]] at a [[Rational]] number (//x^exp//).
# Let //explcm// be the lcm of the denominators of all exponents.
# If there are no denominators or //explcm// divides //exp//, then the evaluation
# is computed exactly.
# Otherwise, some rational number close to the root //(x^exp)^-explcm// will be chosen
# via an intermediate floating point number.
# @param Matrix m
# @param Coefficient x
# @param Int exp (default: 1)
# @return Matrix<Coefficient>
# @example [application polytope]
# > $m = long_and_winding(2)->FACETS;
# > print evaluate($m,2,4);
# | (5) (0 256) (1 -1)
# | (5) (0 16) (2 -1)
# | (5) (1 16) (3 -1)
# | (5) (2 16) (3 -1)
# | 0 4 4 0 -1
# | (5) (3 1)
# | (5) (4 1)
user_function evaluate<Coefficient=_, Exponent=_>(Matrix<PuiseuxFraction<Coefficient, Exponent>>, *; $=1) : c++;
# Evaluate all [[PuiseuxFraction]]s in a [[Vector]] at a [[Rational]] number (//x^exp//).
# Let //explcm// be the lcm of the denominators of all exponents.
# If there are no denominators or //explcm// divides //exp//, then the evaluation
# is computed exactly.
# Otherwise, some rational number close to the root //(x^exp)^-explcm// will be chosen
# via an intermediate floating point number.
# @param Vector v
# @param Coefficient x
# @param Int exp (default: 1)
# @return Vector<Coefficient>
user_function evaluate<Coefficient=_, Exponent=_>(Vector<PuiseuxFraction<Coefficient, Exponent>>, *; $=1) : c++;
# Approximate evaluation at //x//
# @param PuiseuxFraction f
# @param Float x
# @return Float
user_function evaluate_float(PuiseuxFraction, $) : c++;
# Approximate evaluation of a [[Matrix]] at //x//
# @param Matrix m
# @param Float x
# @return Float
user_function evaluate_float<Coefficient=_, Exponent=_>(Matrix<PuiseuxFraction<Coefficient, Exponent>>, *) : c++;
# Approximate evaluation of a [[Vector]] at //x//
# @param Vector v
# @param Float x
# @return Float
user_function evaluate_float<Coefficient=_, Exponent=_>(Vector<PuiseuxFraction<Coefficient, Exponent>>, *) : c++;
function polynomial_type<Coefficient, Exponent>(PuiseuxFraction<Coefficient, Exponent>) { typeof UniPolynomial<Coefficient, Exponent> }
function is_ordered_field_with_unlimited_precision(PuiseuxFraction) { 1 }
# @category Arithmetic
# Returns the __numerator__ of a [[PuiseuxFraction]] //f//.
# @param PuiseuxFraction f
# @return Polynomial
user_function numerator(PuiseuxFraction:anchor) : c++;
# @category Arithmetic
# Returns the __denominator__ of a [[PuiseuxFraction]] //f//.
# @param PuiseuxFraction f
# @return Polynomial
user_function denominator(PuiseuxFraction:anchor) : c++;
# Local Variables:
# mode: perl
# cperl-indent-level: 3
# indent-tabs-mode:nil
# End:
|