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: usize

Number 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>

source

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);
source

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);
source

pub fn without_type(self) -> Self

Basis of flag with same size as self without type t.

source

pub fn with_size(self, size: usize) -> Self

Basis of flag with size vertices and same type as self.

source

pub fn print_concise(self) -> String

Print the basis information in a short way.

source§

impl<F: Flag> Basis<F>

source

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)));
source

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);
source

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) );
source

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 );
source

pub fn random<N>(self) -> QFlag<N, F>where N: From<i16>,

source

pub fn flag<N>(self, f: &F) -> QFlag<N, F>where N: Num + Clone,

Create a quantum flag containing exactly one flag.

source

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: Clone + Flag> Clone for Basis<F>

source§

fn clone(&self) -> Basis<F>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<F: Debug + Flag> Debug for Basis<F>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<F: Flag> Display for Basis<F>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<F: Flag> Div<Basis<F>> for Basis<F>

§

type Output = Basis<F>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Self) -> Self

Performs the / operation. Read more
source§

impl<F: Hash + Flag> Hash for Basis<F>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<F> Html for Basis<F>where F: Flag + Draw,

source§

const LATEX: bool = false

source§

fn print_html<W: Write>(&self, w: &mut W) -> Result<()>

source§

fn html(&self, name: &str) -> Result<()>

True if Mathjax need to be loaded
source§

impl<F: Flag> Mul<Basis<F>> for Basis<F>

§

type Output = Basis<F>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
source§

impl<F: Ord + Flag> Ord for Basis<F>

source§

fn cmp(&self, other: &Basis<F>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<F: PartialEq + Flag> PartialEq<Basis<F>> for Basis<F>

source§

fn eq(&self, other: &Basis<F>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<F: PartialOrd + Flag> PartialOrd<Basis<F>> for Basis<F>

source§

fn partial_cmp(&self, other: &Basis<F>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<F: Flag> Savable<Vec<F, Global>, F> for Basis<F>

source§

fn filename(&self) -> String

Name of the file where the operator can be saved.
source§

fn create(&self) -> Vec<F>

Compute the object.
source§

fn file_path(&self) -> PathBuf

Path to the corresponding file.
source§

fn create_and_save(&self, path: &Path) -> A

(Re)create the object, save it in the corresponding file and return it.
source§

fn load(&self, path: &Path) -> Result<A, Box<dyn Error>>

Load the object if the file exists and is valid.
source§

fn get(&self) -> A

Function to automatically load the object if the file exists and is valid, or create and save it otherwise.
source§

impl<F: Flag> Copy for Basis<F>

source§

impl<F: Eq + Flag> Eq for Basis<F>

source§

impl<F: Flag> StructuralEq for Basis<F>

source§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V