diff --git a/src/bin/flat.rs b/src/bin/flat.rs index 8c7b3f5..1f2115b 100644 --- a/src/bin/flat.rs +++ b/src/bin/flat.rs @@ -7,9 +7,20 @@ fn main() { + (3 * ((var!("x", 1, 9) ^ 5) * (var!("x", 1, 2) ^ 5) * (var!("x", 2, 5) ^ 1))); let x = var!("x"); - let y = var!("y"); + let y = var!("x\u{0304}"); + let z = var!("z"); let other = -3 * ((&x ^ 2) * (&y ^ 4)); + let mono = (&x^2)*(&y^4); + + let inside = (&x^2)*(&y^2)*(&z^1); + + if mono.contains(&inside){ + println!("{inside}\u{2286}{mono}"); + }else{ + println!("{inside}\u{2284}{mono}"); + } + println!("{poly}"); let z = poly - other; diff --git a/src/fmt.rs b/src/fmt.rs new file mode 100644 index 0000000..b48c5d0 --- /dev/null +++ b/src/fmt.rs @@ -0,0 +1,34 @@ + +pub fn num_to_subscript(s:String)->String{ + s.chars().map(|c| match c{ + '0'=>'\u{2080}', + '1'=>'\u{2081}', + '2'=>'\u{2082}', + '3'=>'\u{2083}', + '4'=>'\u{2084}', + '5'=>'\u{2085}', + '6'=>'\u{2086}', + '7'=>'\u{2087}', + '8'=>'\u{2088}', + '9'=>'\u{2089}', + _=>c + }).collect() +} + +pub fn num_to_superscript(s:String)->String{ + s.chars().map(|c| match c{ + '0'=>'\u{2070}', + '1'=>'\u{20B9}', + '2'=>'\u{00B2}', + '3'=>'\u{00B3}', + '4'=>'\u{2074}', + '5'=>'\u{2075}', + '6'=>'\u{2076}', + '7'=>'\u{2077}', + '8'=>'\u{2078}', + '9'=>'\u{2079}', + _=>c + }).collect() +} + + diff --git a/src/lib.rs b/src/lib.rs index 0fc1585..e37ef5d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1 +1,2 @@ pub mod poly; +pub mod fmt; diff --git a/src/poly/flat.rs b/src/poly/flat.rs index 9b7d214..16f7ac0 100644 --- a/src/poly/flat.rs +++ b/src/poly/flat.rs @@ -3,6 +3,7 @@ use std::fmt::{self, Display}; use std::ops::{Add, Sub, BitXor, Mul}; +use crate::fmt::num_to_superscript; use super::var::{StaticVar, Var}; use std::collections::HashMap; @@ -57,6 +58,33 @@ pub struct Mono { pub term: Vec<(V, u32)>, } +impl Mono{ + pub fn contains(&self, other:&Mono)->bool{ + let mut self_it=self.term.iter().peekable(); + let mut other_it=other.term.iter().peekable(); + + while let Some((o_term,o_exp))=other_it.peek(){ + if let Some((s_term,s_exp))=self_it.peek(){ + if s_termo_term{ + return false; + }else if o_exp<=s_exp{ + self_it.next(); + other_it.next(); + }else{ + return false; + } + }else{ + return false; + } + } + + true + } +} + impl From for Mono where Mono: FromIterator<::Item>, @@ -94,7 +122,7 @@ impl Display for Mono { .iter() .map(|(t, p)| match p { 1 => format!("{t}"), - _ => format!("{t}^{p}"), + _ => format!("{t}{}",num_to_superscript(p.to_string())), }) .join("") ) @@ -194,3 +222,4 @@ impl Sub for Poly { self } } + diff --git a/src/poly/var.rs b/src/poly/var.rs index eaa57d4..b7d4095 100644 --- a/src/poly/var.rs +++ b/src/poly/var.rs @@ -2,6 +2,8 @@ use itertools::Itertools; use std::fmt::{self, Debug, Display, Formatter}; use std::hash::Hash; +use crate::fmt::num_to_subscript; + #[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct StaticVar { name: &'static str, @@ -15,7 +17,7 @@ impl Display for StaticVar { let num_indices = self.indices.len(); match num_indices { 0 => write!(fmt, "{}", self.name), - _ => write!(fmt, "{}_{{{}}}", self.name, self.indices.iter().join(",")), + _ => write!(fmt, "{}{}", self.name, self.indices.iter().map(|x| num_to_subscript(x.to_string())).join(",")), } } }