polynomial.add
(polynomial::AddOp) ¶
Addition operation between polynomials.
Syntax:
operation ::= `polynomial.add` operands attr-dict `:` type($result)
Performs polynomial addition on the operands. The operands may be single polynomials or containers of identically-typed polynomials, i.e., polynomials from the same underlying ring with the same coefficient types.
Addition is defined to occur in the ring defined by the ring attribute of the two operands, meaning the addition is taken modulo the coefficientModulus and the polynomialModulus of the ring.
Example:
// add two polynomials modulo x^1024 - 1
#poly = #polynomial.polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, coefficientModulus=65536, polynomialModulus=#poly>
%0 = polynomial.constant #polynomial.polynomial<1 + x**2> : !polynomial.polynomial<#ring>
%1 = polynomial.constant #polynomial.polynomial<x**5 - x + 1> : !polynomial.polynomial<#ring>
%2 = polynomial.add %0, %1 : !polynomial.polynomial<#ring>
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands: ¶
Operand | Description |
---|---|
lhs | polynomial-like |
rhs | polynomial-like |
Results: ¶
Result | Description |
---|---|
result | polynomial-like |
polynomial.constant
(polynomial::ConstantOp) ¶
Define a constant polynomial via an attribute.
Syntax:
operation ::= `polynomial.constant` $input attr-dict `:` type($output)
Example:
#poly = #polynomial.polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, coefficientModulus=65536, polynomialModulus=#poly>
%0 = polynomial.constant #polynomial.polynomial<1 + x**2> : !polynomial.polynomial<#ring>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes: ¶
Attribute | MLIR Type | Description |
---|---|---|
input | ::mlir::polynomial::PolynomialAttr | An attribute containing a single-variable polynomial.
|
Results: ¶
Result | Description |
---|---|
output | An element of a polynomial ring. |
polynomial.from_tensor
(polynomial::FromTensorOp) ¶
Creates a polynomial from integer coefficients stored in a tensor.
Syntax:
operation ::= `polynomial.from_tensor` $input attr-dict `:` type($input) `->` type($output)
polynomial.from_tensor
creates a polynomial value from a tensor of coefficients.
The input tensor must list the coefficients in degree-increasing order.
The input one-dimensional tensor may have size at most the degree of the ring’s polynomialModulus generator polynomial, with smaller dimension implying that all higher-degree terms have coefficient zero.
Example:
#poly = #polynomial.polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, coefficientModulus=65536, polynomialModulus=#poly>
%two = arith.constant 2 : i32
%five = arith.constant 5 : i32
%coeffs = tensor.from_elements %two, %two, %five : tensor<3xi32>
%poly = polynomial.from_tensor %coeffs : tensor<3xi32> -> !polynomial.polynomial<#ring>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands: ¶
Operand | Description |
---|---|
input | ranked tensor of integer values |
Results: ¶
Result | Description |
---|---|
output | An element of a polynomial ring. |
polynomial.leading_term
(polynomial::LeadingTermOp) ¶
Compute the leading term of the polynomial.
Syntax:
operation ::= `polynomial.leading_term` operands attr-dict `:` type($input) `->` `(` type($degree) `,` type($coefficient) `)`
The degree of a polynomial is the largest $k$ for which the coefficient
a_k
of x^k
is nonzero. The leading term is the term a_k * x^k
, which
this op represents as a pair of results. The first is the degree k
as an
index, and the second is the coefficient, whose type matches the
coefficient type of the polynomial’s ring attribute.
Example:
#poly = #polynomial.polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, coefficientModulus=65536, polynomialModulus=#poly>
%0 = polynomial.constant #polynomial.polynomial<1 + x**2> : !polynomial.polynomial<#ring>
%1, %2 = polynomial.leading_term %0 : !polynomial.polynomial<#ring> -> (index, i32)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands: ¶
Operand | Description |
---|---|
input | An element of a polynomial ring. |
Results: ¶
Result | Description |
---|---|
degree | index |
coefficient | integer |
polynomial.monic_monomial_mul
(polynomial::MonicMonomialMulOp) ¶
Multiply a polynomial by a monic monomial.
Syntax:
operation ::= `polynomial.monic_monomial_mul` operands attr-dict `:` functional-type(operands, results)
Multiply a polynomial by a monic monomial, meaning a polynomial of the form
1 * x^k
for an index operand k
.
In some special rings of polynomials, such as a ring of polynomials
modulo x^n - 1
, monomial_mul
can be interpreted as a cyclic shift of
the coefficients of the polynomial. For some rings, this results in
optimized lowerings that involve rotations and rescaling of the
coefficients of the input.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands: ¶
Operand | Description |
---|---|
input | polynomial-like |
monomialDegree | index |
Results: ¶
Result | Description |
---|---|
output | polynomial-like |
polynomial.monomial
(polynomial::MonomialOp) ¶
Create a polynomial that consists of a single monomial.
Syntax:
operation ::= `polynomial.monomial` operands attr-dict `:` functional-type(operands, results)
Construct a polynomial that consists of a single monomial term, from its degree and coefficient as dynamic inputs.
The coefficient type of the output polynomial’s ring attribute must match
the coefficient
input type.
Example:
#poly = #polynomial.polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, coefficientModulus=65536, polynomialModulus=#poly>
%deg = arith.constant 1023 : index
%five = arith.constant 5 : i32
%0 = polynomial.monomial %five, %deg : (i32, index) -> !polynomial.polynomial<#ring>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands: ¶
Operand | Description |
---|---|
coefficient | integer |
degree | index |
Results: ¶
Result | Description |
---|---|
output | An element of a polynomial ring. |
polynomial.mul
(polynomial::MulOp) ¶
Multiplication operation between polynomials.
Syntax:
operation ::= `polynomial.mul` operands attr-dict `:` type($result)
Performs polynomial multiplication on the operands. The operands may be single polynomials or containers of identically-typed polynomials, i.e., polynomials from the same underlying ring with the same coefficient types.
Multiplication is defined to occur in the ring defined by the ring attribute of the two operands, meaning the multiplication is taken modulo the coefficientModulus and the polynomialModulus of the ring.
Example:
// multiply two polynomials modulo x^1024 - 1
#poly = #polynomial.polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, coefficientModulus=65536, polynomialModulus=#poly>
%0 = polynomial.constant #polynomial.polynomial<1 + x**2> : !polynomial.polynomial<#ring>
%1 = polynomial.constant #polynomial.polynomial<x**5 - x + 1> : !polynomial.polynomial<#ring>
%2 = polynomial.mul %0, %1 : !polynomial.polynomial<#ring>
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands: ¶
Operand | Description |
---|---|
lhs | polynomial-like |
rhs | polynomial-like |
Results: ¶
Result | Description |
---|---|
result | polynomial-like |
polynomial.mul_scalar
(polynomial::MulScalarOp) ¶
Multiplication by a scalar of the field.
Syntax:
operation ::= `polynomial.mul_scalar` operands attr-dict `:` type($polynomial) `,` type($scalar)
Multiplies the polynomial operand’s coefficients by a given scalar value. The operation is defined to occur in the ring defined by the ring attribute of the two operands, meaning the multiplication is taken modulo the coefficientModulus of the ring.
The scalar
input must have the same type as the polynomial ring’s
coefficientType.
Example:
// multiply two polynomials modulo x^1024 - 1
#poly = #polynomial.polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, coefficientModulus=65536, polynomialModulus=#poly>
%0 = polynomial.constant #polynomial.polynomial<1 + x**2> : !polynomial.polynomial<#ring>
%1 = arith.constant 3 : i32
%2 = polynomial.mul_scalar %0, %1 : !polynomial.polynomial<#ring>, i32
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands: ¶
Operand | Description |
---|---|
polynomial | polynomial-like |
scalar | integer |
Results: ¶
Result | Description |
---|---|
output | polynomial-like |
polynomial.sub
(polynomial::SubOp) ¶
Subtraction operation between polynomials.
Syntax:
operation ::= `polynomial.sub` operands attr-dict `:` type($result)
Performs polynomial subtraction on the operands. The operands may be single polynomials or containers of identically-typed polynomials, i.e., polynomials from the same underlying ring with the same coefficient types.
Subtraction is defined to occur in the ring defined by the ring attribute of the two operands, meaning the subtraction is taken modulo the coefficientModulus and the polynomialModulus of the ring.
Example:
// subtract two polynomials modulo x^1024 - 1
#poly = #polynomial.polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, coefficientModulus=65536, polynomialModulus=#poly>
%0 = polynomial.constant #polynomial.polynomial<1 + x**2> : !polynomial.polynomial<#ring>
%1 = polynomial.constant #polynomial.polynomial<x**5 - x + 1> : !polynomial.polynomial<#ring>
%2 = polynomial.sub %0, %1 : !polynomial.polynomial<#ring>
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands: ¶
Operand | Description |
---|---|
lhs | polynomial-like |
rhs | polynomial-like |
Results: ¶
Result | Description |
---|---|
result | polynomial-like |
polynomial.to_tensor
(polynomial::ToTensorOp) ¶
Creates a tensor containing the coefficients of a polynomial.
Syntax:
operation ::= `polynomial.to_tensor` $input attr-dict `:` type($input) `->` type($output)
polynomial.to_tensor
creates a dense tensor value containing the
coefficients of the input polynomial. The output tensor contains the
coefficients in degree-increasing order.
Operations that act on the coefficients of a polynomial, such as extracting
a specific coefficient or extracting a range of coefficients, should be
implemented by composing to_tensor
with the relevant tensor
dialect
ops.
The output tensor has shape equal to the degree of the polynomial ring attribute’s polynomialModulus, including zeroes.
Example:
#poly = #polynomial.polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, coefficientModulus=65536, polynomialModulus=#poly>
%two = arith.constant 2 : i32
%five = arith.constant 5 : i32
%coeffs = tensor.from_elements %two, %two, %five : tensor<3xi32>
%poly = polynomial.from_tensor %coeffs : tensor<3xi32> -> !polynomial.polynomial<#ring>
%tensor = polynomial.to_tensor %poly : !polynomial.polynomial<#ring> -> tensor<1024xi32>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands: ¶
Operand | Description |
---|---|
input | An element of a polynomial ring. |
Results: ¶
Result | Description |
---|---|
output | ranked tensor of integer values |