Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbolic relex #42

Merged
merged 68 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
9af2dbe
WIP started symbolic simplification
vanilla-extracts Apr 28, 2024
ee7816d
move in exact math
vanilla-extracts Apr 28, 2024
2690630
change to be more rust-y
vanilla-extracts Apr 28, 2024
eaa057b
change rust test to be on every branch
vanilla-extracts Apr 28, 2024
b025bf4
WIP
vanilla-extracts Apr 29, 2024
acc4c9e
reimplementing vars
vanilla-extracts Apr 29, 2024
74886f9
WIP
vanilla-extracts Apr 29, 2024
069f5d0
Plus
vanilla-extracts Apr 30, 2024
efda9ed
Var 1/2
vanilla-extracts Apr 30, 2024
fcfac54
fix test
vanilla-extracts Apr 30, 2024
7b9556d
Var 2/2
vanilla-extracts Apr 30, 2024
e815b28
remove Mul
vanilla-extracts Apr 30, 2024
cf4fca3
minus
vanilla-extracts Apr 30, 2024
983b4fc
replace all minus by plus
vanilla-extracts Apr 30, 2024
7cf7775
finish add to minus
vanilla-extracts Apr 30, 2024
f26dd6e
add mul
vanilla-extracts May 2, 2024
182ae94
implements multiplications 1/2
vanilla-extracts May 2, 2024
0e9dc86
split functions in different files
vanilla-extracts May 3, 2024
ec473b9
fix tests
vanilla-extracts May 3, 2024
d38680f
bump to 2.14.0
vanilla-extracts May 4, 2024
6339cb3
fix main.rs
vanilla-extracts May 4, 2024
b53fd7f
implements plus,var operations for mult
vanilla-extracts May 5, 2024
d751794
implements operations for mult
vanilla-extracts May 5, 2024
d247736
implements mul for add
vanilla-extracts May 5, 2024
a60efae
implements mult ops for minus
vanilla-extracts May 5, 2024
cd7d2a9
delete unnecessary imports
vanilla-extracts May 5, 2024
c1ec0cf
correct errors in add,minus and mult
vanilla-extracts May 6, 2024
2b4ae6c
fix errors in mult
vanilla-extracts May 6, 2024
a26231c
remove unnecessary import
vanilla-extracts May 6, 2024
b74dec7
add div
vanilla-extracts May 7, 2024
ca12ef0
add invert operation to rationals
vanilla-extracts May 7, 2024
82415fa
WIP add div operations
vanilla-extracts May 7, 2024
b761dbf
add basic operators for div
vanilla-extracts May 12, 2024
3cee0d4
add even more parenthesis (for more clarification, so we can be reall…
vanilla-extracts May 12, 2024
e7bff4d
ok that was too much parenthesis, now it's a bit better, but we're le…
vanilla-extracts May 12, 2024
9ae9555
WIP add mul/plus/var to div
vanilla-extracts May 13, 2024
f627753
WIP add mul/plus/var to div 2/n
vanilla-extracts May 14, 2024
df4187e
WIP add mul/plus/var to div 3/4
vanilla-extracts May 14, 2024
216b375
implements add mul/plus/var to div 4/4
vanilla-extracts May 14, 2024
047f001
Merge branch 'mistress' into symbolic_relex
vanilla-extracts May 14, 2024
d5b5315
WIP add div operations to div
vanilla-extracts May 15, 2024
cad85bc
remove comments
vanilla-extracts May 15, 2024
89b8e0b
remove unnecessary clones
vanilla-extracts May 15, 2024
c5b038b
add div operations to div
vanilla-extracts May 15, 2024
769d074
fix mathematical error on div
vanilla-extracts May 15, 2024
bf63564
simplify expressions
vanilla-extracts May 15, 2024
c3b6fa7
simplify rationals
vanilla-extracts May 15, 2024
6226d17
remove unnecessary clone
vanilla-extracts May 15, 2024
feee0a6
correct div to avoid stack overflow and correctness
vanilla-extracts May 16, 2024
e094922
implements div for mult operations
vanilla-extracts May 16, 2024
030d4d2
pretty print superscript to be printed as a fraction
vanilla-extracts May 16, 2024
e62c0ec
replace superscript 1 by nothing
vanilla-extracts May 16, 2024
7f146d6
WIP add div operations to add
vanilla-extracts May 18, 2024
18096c1
bump to 3.0.0
vanilla-extracts May 18, 2024
5010215
change changelog for 3.0.0
vanilla-extracts May 18, 2024
a31d58a
implements div operations for minus
vanilla-extracts May 19, 2024
a5cb008
remove stack overflow on exponentiation
vanilla-extracts May 19, 2024
03efbde
simplify expo
vanilla-extracts May 19, 2024
16bacb5
simplify functions
vanilla-extracts May 19, 2024
48ab4ea
remove stack overflow on greater
vanilla-extracts May 19, 2024
d6c4657
remove stack overflow on lesser
vanilla-extracts May 19, 2024
fee75dc
remove stack overflow on greater or equal
vanilla-extracts May 19, 2024
e1daa0c
remove stack overflow on lesser or equal
vanilla-extracts May 19, 2024
0512049
fix test
vanilla-extracts May 19, 2024
8eef0c5
remove stack overflow for equal
vanilla-extracts May 19, 2024
523f923
remove unnessary clones
vanilla-extracts May 19, 2024
cb2610a
remove stack overflow on other functions
vanilla-extracts May 19, 2024
307875b
change makefile
vanilla-extracts May 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/rust-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Rust

on:
push:
branches: [ "mistress" ]
pull_request:
branches: [ "mistress" ]

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Version 3.0.0 : Symbolic calculation!
Version 3.0.0, at last! (if you've seen the PR for it it's been sitting for more
than three weeks!)

Symbolic computation was added you can compute expressions with symbols (such as
x,y,whatever) and more !

# Version 2.13.2 : Bug fix
Fix #43

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mini-calc"
version = "2.13.2"
version = "3.0.0"
license = "GPL-3.0-or-later"
description = "A fully-featured minimalistic configurable rust calculator"
homepage = "https://calc.nwa2coco.fr"
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ release:
cargo build --release
test:
cargo test
publish:
cargo publish
2 changes: 1 addition & 1 deletion src/configuration/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub fn load_color(string: String) -> Color {

pub fn replace_variable(str: String) -> String {
str.replace("%author%", "Charlotte Thomas")
.replace("%version%", "v2.13.2")
.replace("%version%", "v3.0.0")
.to_string()
}

Expand Down
1 change: 1 addition & 0 deletions src/exact_math/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod rationals;
pub mod symbolic;
15 changes: 13 additions & 2 deletions src/exact_math/rationals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fmt::Display, ops};

use crate::utils::integer_utils::gcd;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy)]
pub struct Rationals {
pub under: i64,
pub over: i64,
Expand Down Expand Up @@ -32,6 +32,17 @@ impl Rationals {
return self.over == 0;
}

pub fn opposite(self) -> Self {
Rationals::new(self.under, -1 * self.over)
}

pub fn invert(self) -> Result<Rationals, Rationals> {
match self.over {
0 => Err(Rationals::new(0, 1)),
_ => Ok(Rationals::new(self.over, self.under).reduce()),
}
}

pub fn reduce(self) -> Self {
let minus;
let i1;
Expand Down Expand Up @@ -84,7 +95,7 @@ impl Rationals {

impl Display for Rationals {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let fs = self.clone().reduce();
let fs = self.reduce();
if fs.under == 1 {
write!(f, "{}", fs.over)
} else {
Expand Down
121 changes: 121 additions & 0 deletions src/exact_math/symbolic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
use crate::parsing::ast::Parameters;
use crate::parsing::ast::Parameters::*;

pub fn size(p: &Parameters) -> i32 {
match p {
Null
| Int(_)
| Str(_)
| Float(_)
| Identifier(_)
| PlusOperation
| MinusOperation
| MultiplicationOperation
| DivideOperation
| Assign
| ExpoOperation
| GreaterOperation
| GreaterOrEqualOperation
| LesserOperation
| LesserOrEqualOperation
| Equal
| Bool(_)
| Rational(_)
| OrOperation
| AndOperation
| Not
| Vector(_)
| InterpreterVector(_) => 0,
Plus(x, y) => 1 + size(x) + size(y),
Var(x, _, _) => 1 + size(x),
Mul(x, y) => 1 + size(x) + size(y),
Div(x, y) => 1 + size(x) + size(y),
}
}

#[cfg(test)]
mod test {

use crate::{
exact_math::rationals::Rationals,
parsing::ast::{
Ast,
Parameters::{self, *},
},
};

use super::size;
#[test]
fn test_leaf() {
let v = vec![
Null,
Int(1),
Str("".to_string()),
Float(1.0),
Identifier("".to_string()),
PlusOperation,
MinusOperation,
MultiplicationOperation,
DivideOperation,
Assign,
ExpoOperation,
GreaterOperation,
GreaterOrEqualOperation,
LesserOperation,
LesserOrEqualOperation,
Equal,
Bool(false),
Rational(Rationals::new(10, 10)),
OrOperation,
AndOperation,
Not,
Vector(Box::from(vec![Ast::Nil])),
InterpreterVector(Box::from(vec![Null])),
];

let should = vec![
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
];

let _ = v
.into_iter()
.map(|f| size(&f))
.zip(should)
.for_each(|(x, y)| assert_eq!(x, y));
}

#[test]
fn test_size() {
let should = 2;
let tree = Plus(
Box::from(Plus(
Box::from(Parameters::Int(1)),
Box::from(Parameters::Int(2)),
)),
Box::from(Parameters::Int(3)),
);
let result = size(&tree);
assert_eq!(result, should);
}
#[test]
fn test_size_mul() {
let should = 2;
let tree = Mul(
Box::from(Plus(
Box::from(Parameters::Int(1)),
Box::from(Parameters::Int(2)),
)),
Box::from(Parameters::Int(3)),
);
let result = size(&tree);
assert_eq!(result, should);
}
#[test]
fn test_size_var() {
let should = 1;
let tree = Var(Box::from(Parameters::Int(1)), 1, "s".to_string());
let result = size(&tree);
assert_eq!(result, should);
}
}
Loading
Loading