Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
2

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

asked 0 years ago

sunilpasupulati gravatar image

I would like to define a graph where I want my vertices set to F25. I won't define there is an edge between (A0,B0) and (A,B) if AA0 and FBB0(A,B))=0 Where FA,B(X)=X3+AX+B. Any help or reference is appreciated.

Preview: (hide)

Comments

What is FBB0(A,B)? Do you mean FA,B(BB0)?

rburing gravatar imagerburing ( 0 years ago )

2 Answers

Sort by » oldest newest most voted
0

answered 0 years ago

updated 0 years ago

Here is a simple example: the vertices are elements of F5, and there is an edge from a to b if a2=b2.

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
Preview: (hide)
link

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 ( 0 years ago )

Sure, even better!

John Palmieri gravatar imageJohn Palmieri ( 0 years ago )
0

answered 0 years ago

Max Alekseyev gravatar image

updated 0 years ago

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] )
Preview: (hide)
link

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: 0 years ago

Seen: 339 times

Last updated: Feb 29 '24