Skip to content

Commit

Permalink
Merge pull request #1 from Waigo01/dev
Browse files Browse the repository at this point in the history
merge dev to main in prep for v0.1.1
  • Loading branch information
Waigo01 committed Apr 14, 2024
2 parents 4d3fb53 + 8a7c6a1 commit 533487a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 65 deletions.
49 changes: 28 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "math_repl"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
description = "Simple REPL for all different kinds of math."
license-file = "LICENSE.txt"
Expand All @@ -22,4 +22,4 @@ features = ["doc-images"]
[dependencies]
console = "0.15.8"
embed-doc-image = "0.1.4"
math_utils_lib = "0.1.8"
math_utils_lib = "^0.2.0"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
![math_repl banner](./images/banner.png)

[![crates.io](https://img.shields.io/badge/crates.io-orange?style=for-the-badge&logo=rust)](https://crates.io/crates/math_repl)
[![docs.rs](https://img.shields.io/badge/docs.rs-gray?style=for-the-badge&logo=docs.rs)]()

math_repl is a CLI REPL that allows a user to quickly calculate expressions, save the results in variables and use those variables in another expression or equation. It additionally allows a user to solve equations, save its results in variables and use them anywhere. All steps that are taken are recorded and can be exported to LaTeX (see Usage below).

Expand Down Expand Up @@ -38,8 +39,9 @@ Usage:
A matrix: [[<1:1>, <1:2>, ..., <1:n>], [<2:1>, <2:2>, ..., <2:n>], ..., [<n:1>, <n:2>, ..., <n:n>]]
A Variable: Any previously defined variable.
You can also use all common operations (see https://docs.rs/math_utils_lib/latest/math_utils_lib/parser/enum.OpType.html)
You can also use all common operations (see https://docs.rs/math_utils_lib/0.2.0/math_utils_lib/parser/enum.SimpleOpType.html)
between all different types (It will tell you, when it can't calculate something).
And more advanced operations such as integrals and derivatives (see https://docs.rs/math_utils_lib/0.2.0/math_utils_lib/parser/enum.AdvancedOpType.html)
Additional commands:
clear: Clears the screen, the history for LaTeX export and all vars except pi and e.
clearvars: Clears all vars except pi and e.
Expand Down
Binary file added export.pdf
Binary file not shown.
Binary file added images/socials.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 4 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ doc = "**Doc images not enabled**. Compile with feature `doc-images` and Rust ve
//! A matrix: [[<1:1>, <1:2>, ..., <1:n>], [<2:1>, <2:2>, ..., <2:n>], ..., [<n:1>, <n:2>, ..., <n:n>]]
//! A Variable: Any previously defined variable.
//!
//! You can also use all common operations (see https://docs.rs/math_utils_lib/latest/math_utils_lib/parser/enum.OpType.html)
//! You can also use all common operations (see https://docs.rs/math_utils_lib/0.2.0/math_utils_lib/parser/enum.SimpleOpType.html)
//! between all different types (It will tell you, when it can't calculate something).
//! And more advanced operations such as integrals and derivatives (see https://docs.rs/math_utils_lib/0.2.0/math_utils_lib/parser/enum.AdvancedOpType.html)
//! Additional commands:
//! clear: Clears the screen, the history for LaTeX export and all vars except pi and e.
//! clearvars: Clears all vars except pi and e.
Expand All @@ -71,14 +72,8 @@ pub use crate::repl::Repl;

pub fn main() {
let initial_state = (vec![
Variable {
name: "pi".to_string(),
value: Value::Scalar(std::f64::consts::PI)
},
Variable {
name: "e".to_string(),
value: Value::Scalar(std::f64::consts::E)
}
Variable::new("pi".to_string(), Value::Scalar(std::f64::consts::PI)),
Variable::new("e".to_string(), Value::Scalar(std::f64::consts::E)),
], vec![]);
let mut repl = Repl::new("├ ".to_string(), "│ ".to_string(), initial_state, handle_message);

Expand Down
50 changes: 18 additions & 32 deletions src/message_handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use math_utils_lib::{eval, export, find_roots, parse, parser::{Binary, OpType, Operation}, ExportType, MathLibError, StepType, Value, Variable};
use math_utils_lib::{eval, export, find_roots, parse, parser::{Binary, SimpleOpType, Operation}, ExportType, MathLibError, StepType, Value, Variable};

use crate::repl::{Exec, Action, HandlerError};

Expand Down Expand Up @@ -53,7 +53,7 @@ fn save_calc_expr(msg: String, var: String, global_state: &mut (Vec<Variable>, V
}
}
if !found {
global_state.0.push(Variable { name: var.clone(), value: res.clone() });
global_state.0.push(Variable::new(var.clone(), res.clone()));
}
let output_msg = res.pretty_print(Some(var.clone()));
global_state.1.push(StepType::Calc((parsed, res, Some(var))));
Expand All @@ -74,13 +74,13 @@ fn solve_eq(msg: String, global_state: &mut (Vec<Variable>, Vec<StepType>)) -> R
right_b = parse(left)?;
}

let root_b = Binary::Operation(Box::new(Operation {
op_type: OpType::Sub,
let root_b = Binary::from_operation(Operation::SimpleOperation {
op_type: SimpleOpType::Sub,
left: left_b.clone(),
right: right_b.clone()
}));
});

let roots = find_roots(root_b, global_state.clone().0, "x")?;
let roots = find_roots(root_b, global_state.clone().0, "x".to_string())?;

let output_string;

Expand Down Expand Up @@ -114,15 +114,15 @@ fn save_solved_eq(msg: String, var: String, global_state: &mut (Vec<Variable>, V
right_b = parse(left)?;
}

let root_b = Binary::Operation(Box::new(Operation {
op_type: OpType::Sub,
let root_b = Binary::from_operation(Operation::SimpleOperation {
op_type: SimpleOpType::Sub,
left: left_b.clone(),
right: right_b.clone()
}));
});

global_state.0 = global_state.0.clone().into_iter().filter(|x| x.name != var).collect();

let roots = find_roots(root_b, global_state.clone().0, &var)?;
let roots = find_roots(root_b, global_state.clone().0, var.clone())?;

let output_string;

Expand All @@ -135,13 +135,10 @@ fn save_solved_eq(msg: String, var: String, global_state: &mut (Vec<Variable>, V
}

if roots.len() == 1 {
global_state.0.push(Variable { name: var.clone(), value: roots[0].clone() });
global_state.0.push(Variable::new(var.clone(), roots[0].clone()));
} else {
for i in 0..roots.len() {
global_state.0.push(Variable {
name: format!("{}_{}", var, i),
value: roots[i].clone()
})
global_state.0.push(Variable::new(format!("{}_{}", var, i), roots[i].clone()));
}
}

Expand All @@ -161,8 +158,9 @@ const HELP_MESSAGE: &str = "You can do 4 basic operations:
A matrix: [[<1:1>, <1:2>, ..., <1:n>], [<2:1>, <2:2>, ..., <2:n>], ..., [<n:1>, <n:2>, ..., <n:n>]]
A Variable: Any previously defined variable.
You can also use all common operations (see https://docs.rs/math_utils_lib/latest/math_utils_lib/parser/enum.OpType.html)
You can also use all common operations (see https://docs.rs/math_utils_lib/0.2.0/math_utils_lib/parser/enum.SimpleOpType.html)
between all different types (It will tell you, when it can't calculate something).
And more advanced operations such as integrals and derivatives (see https://docs.rs/math_utils_lib/0.2.0/math_utils_lib/parser/enum.AdvancedOpType.html)
Additional commands:
clear: Clears the screen, the history for LaTeX export and all vars except pi and e.
clearvars: Clears all vars except pi and e.
Expand All @@ -183,14 +181,8 @@ pub fn handle_message(msg: String, global_state: &mut (Vec<Variable>, Vec<StepTy
}
if msg.len() == 5 && msg[0..=4].to_string().to_uppercase() == "CLEAR" {
global_state.0 = vec![
Variable {
name: "pi".to_string(),
value: Value::Scalar(std::f64::consts::PI)
},
Variable {
name: "e".to_string(),
value: Value::Scalar(std::f64::consts::E)
}
Variable::new("pi".to_string(), Value::Scalar(std::f64::consts::PI)),
Variable::new("e".to_string(), Value::Scalar(std::f64::consts::E))
];
global_state.1.clear();
return Ok(Action::Exec(Exec::Clear));
Expand Down Expand Up @@ -220,14 +212,8 @@ pub fn handle_message(msg: String, global_state: &mut (Vec<Variable>, Vec<StepTy
}
if msg.len() == 9 && msg[0..=8].to_string().to_uppercase() == "CLEARVARS" {
global_state.0 = vec![
Variable {
name: "pi".to_string(),
value: Value::Scalar(std::f64::consts::PI)
},
Variable {
name: "e".to_string(),
value: Value::Scalar(std::f64::consts::E)
}
Variable::new("pi".to_string(), Value::Scalar(std::f64::consts::PI)),
Variable::new("e".to_string(), Value::Scalar(std::f64::consts::E))
];
let output_buffer = global_state.0.iter().map(|x| x.value.pretty_print(Some(x.name.clone()))).collect::<Vec<String>>().join("\n");
return Ok(Action::Print(output_buffer));
Expand Down

0 comments on commit 533487a

Please sign in to comment.