Giter Club home page Giter Club logo

Comments (3)

PBrdng avatar PBrdng commented on August 18, 2024

I don't think there is a direct way so far. Sorry!

from homotopycontinuation.jl.

saschatimme avatar saschatimme commented on August 18, 2024

There seems to be a way to extract the exponent vectors and coefficient of the polynomial (see https://nemocas.github.io/AbstractAlgebra.jl/stable/mpolynomial/#Basic-manipulation).

If you have the exponents and the coefficients in Matrix and vector form you can rebuild the polynomial.
Here is an example.

julia> @var x y z
(x, y, z)

julia> E = [1 2 3; 0 2 1; 3 5 6; 1 0 2]
4×3 Matrix{Int64}:
 1  2  3
 0  2  1
 3  5  6
 1  0  2

julia> c = [5, -3, 2, 3]
4-element Vector{Int64}:
  5
 -3
  2
  3

julia> sum(coeff * prod([x,y,z] .^ row) for (row, coeff) in zip(eachrow(E), c))
3*x*z^2 - 3*y^2*z + 5*x*y^2*z^3 + 2*x^3*y^5*z^6

A little bit clumsy but should get the job done

from homotopycontinuation.jl.

iliailmer avatar iliailmer commented on August 18, 2024

Thank you, @saschatimme @PBrdng! I also found another way using Meta:

function nemo2hc(expr_tree::Union{Expr,Symbol})
    #traverse expr_tree
    if typeof(expr_tree) == Symbol
        return HomotopyContinuation.variables(expr_tree)[1]
    end
    if typeof(expr_tree) == Expr
        if expr_tree.head == :call
            if expr_tree.args[1] in [:+, :-, :*, :/, :^]
                return reduce(eval(expr_tree.args[1]), map(nemo2hc, expr_tree.args[2:end]))
            end
        end
    end
end

called as

nemo2hc(Meta.parse(string(poly)))

I wonder which way will be faster.

from homotopycontinuation.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.