Basis

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

§Defining a Basis

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>

§Defining a quantum flags from a specified basis.

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 qflag_from_indicator<N, P>(self, predicate: P) -> QFlag<N, F>
where P: Fn(&F, usize) -> bool + 'static, 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.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) );
Source

pub fn qflag_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.qflag_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 duplicate 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 for Basis<F>

Source§

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 for Basis<F>

Source§

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) -> Self
where Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

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

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F: PartialOrd + Flag> PartialOrd 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

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

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

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

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

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

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

fn is_in_subset(&self) -> bool

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

unsafe fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V