Skip to content

Lazy multiplication of polynomials #55

Open
@mforets

Description

@mforets

When computing with intervals (ref. IntervalArithmetic), the order in which an evaluation is performed matters. A simple example is

julia> using IntervalArithmetic

julia> a, b = -1..1, 2..3
[-1, 1]

julia> (a+b)*b
[2, 12]

julia> a*b + b*b
[1, 12]

The example shows that evaluating the factored expression gives a better (tighter) result than using the expanded expression.

Have you considered a "lazy" multiplication of polynomials within this package, such that the expression is hold until asked to be evaluated (i mean expanded symbolically)? A "factor" function would also help, but if it exists, i didn't see it. There is this related issue, but it hasn't received much attention.

To illustrate my use case in a concrete example, consider:

julia> using DynamicPolynomials

julia> @polyvar M[1:2, 1:2]
(PolyVar{true}[M₁₋₁ M₁₋₂; M₂₋₁ M₂₋₂],)

julia> first(M^3) # expands everything
M₁₋₁³ + 2M₁₋₁M₂₋₁M₁₋₂ + M₂₋₁M₁₋₂M₂₋₂

julia> using SymEngine

julia> M = convert(Matrix{SymEngine.Basic}, ["M₁₁" "M₁₂"; "M₂₁" "M₂₂"])
2×2 Array{Basic,2}:
 M₁₁  M₁₂
 M₂₁  M₂₂

julia> first(M^3) # keeps the terms factored
(M₂₁*M₁₂ + M₁₁^2)*M₁₁ + (M₂₁*M₁₁ + M₂₂*M₂₁)*M₁₂

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions