pub struct Basis<F: Flag> {
pub size: usize,
pub t: Type<F>,
}Expand description
Identifier for the set of flags with given size and type (in the sense of a labeled subgraph).
The kind of flag is determined by the associated Rust datatype.
For instance Basis<Graph> is the Rust type for a basis of graphs.
basis.get() returns an ordered vector containing all corresponding flags.
Fields§
§size: usizeNumber of vertices in the flags of the basis.
t: Type<F>Type of the flags of the basis.
Implementations§
Source§impl<F: Flag> Basis<F>
§Defining a Basis
impl<F: Flag> Basis<F>
§Defining a Basis
Sourcepub fn new(size: usize) -> Self
pub fn new(size: usize) -> Self
Basis of flag with size vertices and without type.
use flag_algebra::*;
use flag_algebra::flags::Graph;
// Set of graphs of size 3
// (the kind of flag -Graph- is deduced by type inference)
let basis = Basis::new(3);
let size_3_graphs: Vec<Graph> = basis.get();
assert_eq!(size_3_graphs.len(), 4);
// With explicit type annotation
let same_basis: Basis<Graph> = Basis::new(3);Sourcepub fn with_type(self, t: Type<F>) -> Self
pub fn with_type(self, t: Type<F>) -> Self
Basis of flag with same size as self and type t.
use flag_algebra::*;
use flag_algebra::flags::Graph;
// Basis of graphs of size 4 rooted on an edge
let edge = Graph::new(2, &[(0, 1)]);
let t = Type::from_flag(&edge);
let basis: Basis<Graph> = Basis::new(4).with_type(t);Sourcepub fn without_type(self) -> Self
pub fn without_type(self) -> Self
Basis of flag with same size as self without type t.
Sourcepub fn with_size(self, size: usize) -> Self
pub fn with_size(self, size: usize) -> Self
Basis of flag with size vertices and same type as self.
Sourcepub fn print_concise(self) -> String
pub fn print_concise(self) -> String
Print the basis information in a short way.
Source§impl<F: Flag> Basis<F>
§Defining a quantum flags from a specified basis.
impl<F: Flag> Basis<F>
§Defining a quantum flags from a specified basis.
Sourcepub fn one<N>(self) -> QFlag<N, F>
pub fn one<N>(self) -> QFlag<N, F>
Sum of all flags of the basis. This is an expression of the 1 of the flag algebra.
use flag_algebra::*;
use flag_algebra::flags::Graph;
let b = Basis::new(2);
let one = b.one();
let other: QFlag<i64, Graph> = b.random();
assert_eq!(&one * &other, other.expand(Basis::new(4)));Sourcepub fn zero<N>(self) -> QFlag<N, F>
pub fn zero<N>(self) -> QFlag<N, F>
The zero vector in the specified basis.
use flag_algebra::*;
use flag_algebra::flags::Graph;
let basis = Basis::new(3);
let x: QFlag<i64, Graph> = basis.random();
assert_eq!(basis.zero() + &x, x);Sourcepub fn qflag_from_indicator<N, P>(self, predicate: P) -> QFlag<N, F>
pub fn qflag_from_indicator<N, P>(self, predicate: P) -> QFlag<N, F>
Return the formal sum of the flags of the basis self
that satisfies some predicate f.
The predicate f takes two arguments g and sigma, where g is a reference to
the flag and sigma is the size of the labeled part.
use flag_algebra::*;
use flag_algebra::flags::Graph;
// Sum of graphs of size 3 with an even number of edges
let b = Basis::<Graph>::new(3);
let sum = b.qflag_from_indicator(|g, _| g.edges().count() % 2 == 0 );
let e3: QFlag<f64, Graph> = flag(&Graph::new(3, &[]));
let p3 = flag(&Graph::new(3, &[(0, 1), (1, 2)]));
assert_eq!(sum, e3 + &p3);
/// Sum of the graphs of size 3 rooted on one vertex v
/// where v has degree at least 1
let t: Type<Graph> = Type::from_flag(&Graph::new(1, &[])); // Type for one vertex
let basis = Basis::new(3).with_type(t);
let sum: QFlag<f64, Graph> = basis.qflag_from_indicator(move |g, _| g.edge(0, 1) || g.edge(0, 2) );Sourcepub fn qflag_from_coeff<N, M, P>(self, f: P) -> QFlag<N, F>
pub fn qflag_from_coeff<N, M, P>(self, f: P) -> QFlag<N, F>
Return the formal sum of f(g)*g on the flags g of the basis self.
The second parameter of f is the size of the type of g.
use flag_algebra::*;
use flag_algebra::flags::Graph;
// Sum of graphs of size 3 weighted by their number of edges
let b = Basis::<Graph>::new(3);
let sum: QFlag<f64, Graph> = b.qflag_from_coeff(|g, _| g.edges().count() as f64 );pub fn random<N>(self) -> QFlag<N, F>
Sourcepub fn all_cs(&self) -> Vec<MulAndUnlabel<F>>
pub fn all_cs(&self) -> Vec<MulAndUnlabel<F>>
Returns the list of identifiers of all Square-and-unlabel operators
that can be used in Cauchy-Schwarz inequalities for a problem on the basis self.
Trait Implementations§
Source§impl<F: Ord + Flag> Ord for Basis<F>
impl<F: Ord + Flag> Ord for Basis<F>
Source§impl<F: PartialOrd + Flag> PartialOrd for Basis<F>
impl<F: PartialOrd + Flag> PartialOrd for Basis<F>
Source§impl<F: Flag> Savable<Vec<F>, F> for Basis<F>
impl<F: Flag> Savable<Vec<F>, F> for Basis<F>
impl<F: Flag> Copy for Basis<F>
impl<F: Eq + Flag> Eq for Basis<F>
impl<F: Flag> StructuralPartialEq for Basis<F>
Auto Trait Implementations§
impl<F> Freeze for Basis<F>
impl<F> RefUnwindSafe for Basis<F>where
F: RefUnwindSafe,
impl<F> Send for Basis<F>where
F: Send,
impl<F> Sync for Basis<F>where
F: Sync,
impl<F> Unpin for Basis<F>where
F: Unpin,
impl<F> UnwindSafe for Basis<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.