[−][src]Struct fibbox::FibBox
The Fibonacci Box, or FibBox struct contains 4 members: f1, dif, ctr, f2
f1 | Mpz, Integer | Lesser Factor | f2-2*dif | ctr-dif |
dif | Mpz, Integer | Difference of Squares | |(f2-f1)/2| | f2-ctr |
ctr | Mpz, Integer | Centered value | |(f2+f1)/2| | f1+dif |
f2 | Mpz, Integer | Greater Factor | f1+2*dif | dif+ctr |
The individual members are prviate. To access the individual members, use similarly named methods..
Usage:
use fibbox::FibBox; let fb = FibBox::new(1, 1, 2, 3); let f1 = fb.f1(); let dif = fb.dif(); let ctr = fb.ctr(); let f2 = fb.f2();
Each of the access methods is a borrow from the struct's private members.
In addition, the core usage behind a Fibonacci Box is its relationship to Pythagorean Triples
use rug::Integer; use rug::ops::Pow; use fibbox::FibBox; let fb = FibBox::new(1, 1, 2, 3); let pt = fb.as_pytup(); // This is a tuple, 3 members, a pythagorean triple. assert_eq!(Integer::from(fb.f1()*fb.f2()), pt.0); let dos = Integer::from(2); let csq = Integer::pow(Integer::from(fb.ctr()), 2); let dsq = Integer::pow(Integer::from(fb.dif()), 2); let cd = Integer::from(fb.ctr()*fb.dif()); assert_eq!(Integer::from(&csq-&dsq), pt.0); assert_eq!(Integer::from(&dos*&cd), pt.1); assert_eq!(Integer::from(&csq+&dsq), pt.2);
Implementations
impl FibBox
[src]
pub fn new<T: Into<Integer>, U: Into<Integer>, V: Into<Integer>, W: Into<Integer>>(
f1: T,
dif: U,
ctr: V,
f2: W
) -> FibBox
[src]
f1: T,
dif: U,
ctr: V,
f2: W
) -> FibBox
If the gmp-mpfr-sys
library supports conversion,
this new function will support conversion from whichever types are input.
use rug::Integer; use fibbox::FibBox; let fb = FibBox::new(1i8, 1u16, 2i32, 3u64); // Works let fb = FibBox::new(1i16, 1u32, 2u64, 3i128); // Works let uno = Integer::from(1u8); let dos = Integer::from(2i32); let tres = Integer::from(3u128); let fb = FibBox::new(&uno, &uno, dos, tres); // Works
pub fn new_from_tuple<T: Into<Integer>, U: Into<Integer>, V: Into<Integer>, W: Into<Integer>>(
tuvw: (T, U, V, W)
) -> FibBox
[src]
tuvw: (T, U, V, W)
) -> FibBox
Accepts a tuple of 4 integers and returns a new instance.
Usage:
use fibbox::FibBox; let tup = (1, 2, 3, 5); let fb = FibBox::new_from_tuple(tup); println!("{:?}", fb.as_pytup()); println!("{:?}", fb.as_tuple()); println!("{:?}", fb); // Output: // (5, 12, 13) // (1, 2, 3, 5) // 1 1 2 3
pub fn new_from_pytrip<A: Into<Integer>, B: Into<Integer>, C: Into<Integer>>(
a: A,
b: B,
c: C
) -> FibBox
[src]
a: A,
b: B,
c: C
) -> FibBox
Returns a new instance from 3 integer inputs, representing a Pythagorean Triple.
Usage:
use fibbox::FibBox; let fb = FibBox::new_from_pytrip(3, 4, 5); println!("{:?}", fb); println!("{:?}", fb.as_pytup()); // Output: // 1 1 2 3 // (3, 4, 5)
pub fn new_from_pytrip_tuple<A: Into<Integer>, B: Into<Integer>, C: Into<Integer>>(
abc: (A, B, C)
) -> FibBox
[src]
abc: (A, B, C)
) -> FibBox
Accepts a tuple of 3 integers, representing a Pythagorean Triple, and returns a new instance.
Usage:
use fibbox::FibBox; let tup = (3, 4, 5); let fb = FibBox::new_from_pytrip_tuple(tup); println!("{:?}", fb.as_pytup()); println!("{:?}", fb); // Output: // (3, 4, 5) // 1 1 2 3
pub fn as_tuple(&self) -> (Integer, Integer, Integer, Integer)
[src]
Returns the struct's members as a tuple (of 4 integers)
Usage:
use fibbox::FibBox; let fb = FibBox::new(1, 1, 2, 3); let tup = fb.as_tuple(); println!("{:?}", tup); // Output: // (1, 1, 2, 3)
pub fn as_pytup(&self) -> (Integer, Integer, Integer)
[src]
Returns a 3 member tuple, (A, B, C), such that A^2+B^2==C^2
Usage:
use fibbox::FibBox; let fb = FibBox::new(1, 1, 2, 3); let pt = fb.as_pytup(); println!("{:?}", pt); // Output: // (3, 4, 5)
pub fn is_primitive(&self) -> bool
[src]
Returns true or false, whether or not the Fibonacci Box represents a primitive Pythagorean Triple or not.
Usage:
use fibbox::FibBox; let fb = FibBox::new(1, 1, 2, 3); // (3, 4, 5) println!("{:?}", fb.is_primitive()); // true assert!(fb.gcd() == 1); let np = FibBox::new(9, 3, 12, 15); // (135, 72, 153) println!("{:?}", np.is_primitive()); // true assert!(np.gcd() == 3);
pub fn gcd(&self) -> Integer
[src]
Returns the GCD; 1 if primitive, else a positive integer.
Usage:
// Same example as `is_primitive(&self)` use fibbox::FibBox; let fb = FibBox::new(1, 1, 2, 3); // (3, 4, 5) println!("{:?}", fb.is_primitive()); // true assert!(fb.gcd() == 1); let np = FibBox::new(9, 3, 12, 15); // (135, 72, 153) println!("{:?}", np.is_primitive()); // false assert!(np.gcd() == 3);
pub fn Root() -> FibBox
[src]
Returns the default base or root
use fibbox::FibBox; let a = FibBox::new(1, 1, 2, 3); let b = FibBox::Root(); assert_eq!(a, b);
pub fn f1(&self) -> &Integer
[src]
Returns the value of f1 (borrowed).
Usage:
use rug::Integer; use fibbox::FibBox; type Mpz = Integer; let fb = FibBox::new(1, 1, 2, 3); // (3, 4, 5) assert_eq!(Mpz::from(fb.f1()), 1);
pub fn dif(&self) -> &Integer
[src]
Returns the value of dif (borrowed).
Usage:
use rug::Integer; use fibbox::FibBox; type Mpz = Integer; let fb = FibBox::new(1, 1, 2, 3); // (3, 4, 5) assert_eq!(Mpz::from(fb.dif()), 1);
pub fn ctr(&self) -> &Integer
[src]
Returns the value of ctr (borrowed).
Usage:
use rug::Integer; use fibbox::FibBox; type Mpz = Integer; let fb = FibBox::new(1, 1, 2, 3); // (3, 4, 5) assert_eq!(Mpz::from(fb.ctr()), 2);
pub fn f2(&self) -> &Integer
[src]
Returns the value of f2 (borrowed).
Usage:
use rug::Integer; use fibbox::FibBox; type Mpz = Integer; let fb = FibBox::new(1, 1, 2, 3); // (3, 4, 5) assert_eq!(Mpz::from(fb.f2()), 3);
pub fn price_a(&mut self)
[src]
Mutates the struct following the Price (2008) A branch.
use fibbox::FibBox; let mut fb = FibBox::new(1, 1, 2, 3); println!("{} {:?}", fb, fb.as_pytup()); fb.price_a(); println!("{} {:?}", fb, fb.as_pytup()); fb.price_a(); println!("{} {:?}", fb, fb.as_pytup()); fb.price_a(); println!("{} {:?}", fb, fb.as_pytup()); fb.price_a(); println!("{} {:?}", fb, fb.as_pytup()); // Output: // 1 1 2 3 (3, 4, 5) // 1 2 3 5 (5, 12, 13) // 1 4 5 9 (9, 40, 41) // 1 8 9 17 (17, 144, 145) // 1 16 17 33 (33, 544, 545)
pub fn price_b(&mut self)
[src]
Mutates the struct following the Price (2008) B branch.
use fibbox::FibBox; let mut fb = FibBox::new(1, 1, 2, 3); let pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.price_b(); println!("{} {:?}", fb, pt); fb.price_b(); println!("{} {:?}", fb, pt); fb.price_b(); println!("{} {:?}", fb, pt); fb.price_b(); println!("{} {:?}", fb, pt); // Output: // 1 1 2 3 (3, 4, 5) // 3 1 4 5 (15, 8, 17) // 5 3 8 11 (55, 48, 73) // 11 5 16 21 (231, 160, 281) // 21 11 32 43 (903, 704, 1145)
pub fn price_c(&mut self)
[src]
Mutates the struct following the Price (2008) C branch.
use fibbox::FibBox; let mut fb = FibBox::Root(); let mut pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.price_c(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.price_c(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.price_c(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.price_c(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); // Output: // 1 1 2 3 (3, 4, 5) // 1 3 4 7 (7, 24, 25) // 1 7 8 15 (15, 112, 113) // 1 15 16 31 (31, 480, 481) // 1 31 32 63 (63, 1984, 1985)
pub fn price_p(&mut self)
[src]
Mutates the struct following the Price (2008) tree, becoming the parent (tree) value.
use fibbox::FibBox; let mut fb = FibBox::Root(); let mut pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.price_a(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.price_b(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.price_c(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.price_p(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.price_p(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.price_p(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); assert!(fb == FibBox::Root()); // Output: // 1 1 2 3 (3, 4, 5) // 1 3 4 7 (5, 12, 13) // 1 7 8 15 (35, 12, 37) // 5 7 12 19 (95, 168, 193) // 5 1 6 7 (35, 12, 37) // 1 2 3 5 (5, 12, 13) // 1 1 2 3 (3, 4, 5)
pub fn berggren_a(&mut self)
[src]
Mutates the struct following the B. Berggren (1934) A branch.
use fibbox::FibBox; let mut fb = FibBox::new(1, 1, 2, 3); let mut pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.berggren_a(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.berggren_a(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.berggren_a(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.berggren_a(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); // Output: // 1 1 2 3 (3, 4, 5) // 3 1 4 5 (15, 8, 17) // 5 1 6 7 (35, 12, 37) // 7 1 8 9 (63, 16, 65) // 9 1 10 11 (99, 20, 101)
pub fn berggren_b(&mut self)
[src]
Mutates the struct following the B. Berggren (1934) B branch.
use fibbox::FibBox; let mut fb = FibBox::Root(); let pt = fb.as_pytup(); println!("{} {:?}", fb, fb.as_pytup()); fb.berggren_b(); println!("{} {:?}", fb, fb.as_pytup()); fb.berggren_b(); println!("{} {:?}", fb, fb.as_pytup()); fb.berggren_b(); println!("{} {:?}", fb, fb.as_pytup()); fb.berggren_b(); println!("{} {:?}", fb, fb.as_pytup()); // Output: // 1 1 2 3 (3, 4, 5) // 3 2 5 7 (21, 20, 29) // 7 5 12 17 (119, 120, 169) // 17 12 29 41 (697, 696, 985) // 41 29 70 99 (4059, 4060, 5741)
pub fn berggren_c(&mut self)
[src]
Mutates the struct following the B. Berggren (1934) C branch.
use fibbox::FibBox; let mut fb = FibBox::new(1, 1, 2, 3); let pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.berggren_c(); println!("{} {:?}", fb, pt); fb.berggren_c(); println!("{} {:?}", fb, pt); fb.berggren_c(); println!("{} {:?}", fb, pt); fb.berggren_c(); println!("{} {:?}", fb, pt); // Output: // 1 1 2 3 (3, 4, 5) // 1 2 3 5 (5, 12, 13) // 1 3 4 7 (7, 24, 25) // 1 4 5 9 (9, 40, 41) // 1 5 6 11 (11, 60, 61)
pub fn berggren_p(&mut self)
[src]
Mutates the struct following the B. Berggren (1934) tree, becoming the parent (tree) value.
use fibbox::FibBox; let mut fb = FibBox::Root(); let mut pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.berggren_c(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.berggren_a(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.berggren_b(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.berggren_p(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.berggren_p(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); fb.berggren_p(); pt = fb.as_pytup(); println!("{} {:?}", fb, pt); assert!(fb == FibBox::Root()); // Output: // 1 1 2 3 (3, 4, 5) // 3 1 4 5 (15, 8, 17) // 5 4 9 13 (65, 72, 97) // 5 9 14 23 (115, 252, 277) // 5 4 9 13 (65, 72, 97) // 3 1 4 5 (15, 8, 17) // 1 1 2 3 (3, 4, 5)
Trait Implementations
impl Clone for FibBox
[src]
impl Debug for FibBox
[src]
impl Display for FibBox
[src]
impl PartialEq<FibBox> for FibBox
[src]
impl StructuralPartialEq for FibBox
[src]
Auto Trait Implementations
impl RefUnwindSafe for FibBox
impl Send for FibBox
impl Sync for FibBox
impl Unpin for FibBox
impl UnwindSafe for FibBox
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,