Ask Your Question
2

How define a graph where edges are defined using a condition?

asked 2024-02-29 11:46:13 +0100

sunilpasupulati gravatar image

I would like to define a graph where I want my vertices set to $\mathbb{F}_5^2$. I won't define there is an edge between $(A_0,B_0)$ and $(A,B)$ if $A\neq A_0$ and $F_{B-B_0}(A,B))=0$ Where $F_{A,B}(X)=X^3+AX+B$. Any help or reference is appreciated.

edit retag flag offensive close merge delete

Comments

What is $F_{B-B_0}(A,B)$? Do you mean $F_{A,B}(B-B_0)$?

rburing gravatar imagerburing ( 2024-02-29 14:53:34 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2024-02-29 17:43:02 +0100

updated 2024-02-29 17:43:32 +0100

Here is a simple example: the vertices are elements of $\mathbb{F}_5$, and there is an edge from $a$ to $b$ if $a^2 = b^2$.

sage: from itertools import product
sage: vertices = list(GF(5))
sage: edges = [(a,b) for (a,b) in product(vertices, vertices) if a**2 == b**2 and a != b]

In the previous line, product(vertices, vertices) is an iterator consisting of all pairs (v,w) of vertices. I impose the condition a != b to avoid loops in the graph. Now construct the graph:

sage: Graph([vertices, edges])
Graph on 5 vertices
edit flag offensive delete link more

Comments

You can use for a,b in Combinations(vertices,2) instead. No itertools is needed. Also, using product you are essentially adding each edge twice.

Max Alekseyev gravatar imageMax Alekseyev ( 2024-02-29 18:10:53 +0100 )edit

Sure, even better!

John Palmieri gravatar imageJohn Palmieri ( 2024-02-29 19:57:04 +0100 )edit
0

answered 2024-02-29 19:46:03 +0100

Max Alekseyev gravatar image

updated 2024-02-29 19:50:53 +0100

This is a straighforward way to contruct the same graph as in John's code:

Graph( [ GF(5), lambda a,b: a^2 == b^2 ] )

Correspondingly, the graph in question can be constructed as

F = lambda X, A, B: X^3 + A*X + B
Graph( [ Tuples(GF(5),2), lambda AB0, AB: AB[0]!=AB0[0] and F(AB[1]-AB0[1],AB[0],AB[1])==0] )
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-02-29 11:46:13 +0100

Seen: 313 times

Last updated: Feb 29