-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
195 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
|
||
extern crate num; | ||
|
||
pub mod ops; | ||
mod terms; | ||
|
||
pub use self::terms::*; | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use std::rc::Rc; | ||
|
||
use num::Num; | ||
|
||
/// Trait for every symbolic expression. | ||
pub trait Expression<T: Num> { | ||
} | ||
|
||
/// Wrapper class for reference counting pointer to an expression. | ||
pub type Expr<T> = Rc<dyn Expression<T>>; | ||
|
||
// TODO (Add `Hash` and `Eq` trait to `Expr<T>`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use num::Num; | ||
|
||
use super::expression::{Expr, Expression}; | ||
|
||
/// Represents a function with single input argument. | ||
pub struct SingleArgFunc<T: Num> { | ||
name: &'static str, | ||
arg: Expr<T>, | ||
} | ||
|
||
impl<T: Num> Expression<T> for SingleArgFunc<T> { | ||
// TODO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use std::hash::Hash; | ||
|
||
use num::Num; | ||
|
||
use super::expression::Expression; | ||
|
||
/// Implement the Expression trait for all numbers | ||
impl<T: Num + Hash> Expression<T> for T { | ||
// TODO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::collections::HashMap; | ||
|
||
use num::Num; | ||
|
||
use super::expression::{Expr, Expression}; | ||
|
||
/// Represents the operation `coeff + c0 * x0 + c1 * x1 + c2 * x2 + ...`, | ||
/// where `coeff`, `c0`, `c1`, `c2`, ... are number constants. | ||
pub struct Add<T: Num> { | ||
/// Number coefficient of the expression. | ||
coeff: T, | ||
/// Dictionary that maps terms (x0, x1, x2, ...) to their coefficients (c0, c1, c2, ...) | ||
dict: HashMap<Expr<T>, T>, | ||
} | ||
|
||
impl<T: Num> Expression<T> for Add<T> { | ||
// TODO | ||
} | ||
|
||
/// Represents the operation `coeff * x0 ^ c0 * x1 ^ c1 * x2 ^ c2 * ...`, | ||
/// where `coeff`, `c0`, `c1`, `c2`, ... are number constants. | ||
pub struct Mul<T: Num> { | ||
/// Number coefficient of the expression. | ||
coeff: T, | ||
/// Dictionary that maps terms (x0, x1, x2, ...) to their coefficients (c0, c1, c2, ...) | ||
dict: HashMap<Expr<T>, T>, | ||
} | ||
|
||
impl<T: Num> Expression<T> for Mul<T> { | ||
// TODO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::hash::Hash; | ||
|
||
use num::Num; | ||
|
||
use super::expression::Expression; | ||
|
||
pub struct Symbol { | ||
name: &'static str, | ||
} | ||
|
||
impl Hash for Symbol { | ||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { | ||
todo!() | ||
} | ||
} | ||
|
||
impl<T: Num> Expression<T> for Symbol { | ||
// TODO | ||
} |
Oops, something went wrong.