Struct flag_algebra::operator::Basis
source · 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>
impl<F: Flag> Basis<F>
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>
impl<F: Flag> Basis<F>
sourcepub fn one<N>(self) -> QFlag<N, F>where
N: Num + Clone,
pub fn one<N>(self) -> QFlag<N, F>where N: Num + Clone,
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>where
N: Num + Clone,
pub fn zero<N>(self) -> QFlag<N, F>where N: Num + Clone,
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 from_indicator<N>(self, f: fn(_: &F, _: usize) -> bool) -> QFlag<N, F>where
N: One + Zero,
pub fn from_indicator<N>(self, f: fn(_: &F, _: usize) -> bool) -> QFlag<N, F>where N: One + Zero,
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.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::from_flag(&Graph::new(1, &[])); // Type for one vertex
let basis = Basis::new(3).with_type(t);
let sum: QFlag<f64, Graph> = basis.from_indicator(|g, _| g.edge(0, 1) || g.edge(0, 2) );sourcepub fn from_coeff<N, M, P>(self, f: P) -> QFlag<N, F>where
P: Fn(&F, usize) -> M + 'static,
M: Into<N>,
pub fn from_coeff<N, M, P>(self, f: P) -> QFlag<N, F>where P: Fn(&F, usize) -> M + 'static, M: Into<N>,
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.from_coeff(|g, _| g.edges().count() as f64 );pub fn random<N>(self) -> QFlag<N, F>where N: From<i16>,
sourcepub fn flag<N>(self, f: &F) -> QFlag<N, F>where
N: Num + Clone,
pub fn flag<N>(self, f: &F) -> QFlag<N, F>where N: Num + Clone,
Create a quantum flag containing exactly one flag.
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: PartialEq + Flag> PartialEq<Basis<F>> for Basis<F>
impl<F: PartialEq + Flag> PartialEq<Basis<F>> for Basis<F>
source§impl<F: PartialOrd + Flag> PartialOrd<Basis<F>> for Basis<F>
impl<F: PartialOrd + Flag> PartialOrd<Basis<F>> for Basis<F>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<F: Flag> Savable<Vec<F, Global>, F> for Basis<F>
impl<F: Flag> Savable<Vec<F, Global>, F> for Basis<F>
impl<F: Flag> Copy for Basis<F>
impl<F: Eq + Flag> Eq for Basis<F>
impl<F: Flag> StructuralEq for Basis<F>
impl<F: Flag> StructuralPartialEq for Basis<F>
Auto Trait Implementations§
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
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§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).§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.