Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of == in Graphs #2262

Open
pzinn opened this issue Oct 21, 2021 · 2 comments
Open

Use of == in Graphs #2262

pzinn opened this issue Oct 21, 2021 · 2 comments

Comments

@pzinn
Copy link
Contributor

pzinn commented Oct 21, 2021

Example of a problem with the Graphs package:

i1 : needsPackage "Graphs"

o1 = Graphs

o1 : Package

i2 : G=graph{{a,1}};

i3 : H=graph{{b,2}};

i4 : cartesianProduct(G,H)
stdio:4:1:(3): error: no method for binary operator == applied to objects:
--            1 (of class ZZ)
--     ==     a (of class Symbol)

The issue is, cartesianProduct tries to compare vertex labels with ==. This is problematic since vertex labels can be anything (in the help, both symbols like a,b,c and numbers 1,2,3 are used).
I suspect === should be used. There are I believe quite a few other functions defined in Graphs that suffer from the same problem.

@fchapoton
Copy link
Contributor

fchapoton commented Aug 22, 2022

This may be because the vertex set is build using

    V := toList(set vertexSet G ** set vertexSet H);

Could someone propose another way to build the cartesian product of two vertexSet ?

@DanGrayson
Copy link
Member

You could use V := vertexSet G ** vertexSet H.

By the way, it's strange that vertexSet returns a list, not a set.

Also, the illegal use of == is later in the function:

cartesianProduct(Graph, Graph) := Graph => (G, H) -> (
    V := toList(set vertexSet G ** set vertexSet H);
    E := flatten for u in V list for v in V list
        if (u_0 == v_0 and member(set {u_1, v_1}, edges H))
        or (u_1 == v_1 and member(set {u_0, v_0}, edges G))
        then {u, v} else continue;
    graph(V, E, EntryMode => "edges")
    )

fchapoton added a commit to fchapoton/M2 that referenced this issue Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants