-
-
Notifications
You must be signed in to change notification settings - Fork 452
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
Fully-featured math expression parser and calculator #2026
Comments
I'm interested in this issue. I'm a bit new, but I hope to do my best and make progress in this field. |
@abueno19 that would be great, thanks for volunteering! We'd ideally like to get a reasonably functional version of this working in the next month or so, with progress towards the full functionality outlined here over the next couple months. My plan was to post this issue on /r/rust to find interested collaborators. Multiple people could probably work on it together, like writing tests, figuring out the correct formal grammar, handling the AST, working with the dimensional analysis, calculating the values, implementing the functions, etc. What's your level of experience with software engineering or computer science in general, and grammar parsing in particular, and would you like to work with others on this? |
Hello, As for grammar analysis, I don’t think I’d have any issues with parsing. Regarding your question about working with others, I would love to! What I’m looking to gain from this is learning how to structure code, work in a community, and learn new methodologies. Just let me know, and I’ll start with the basics (character parsing system). |
This issue seems interesting, I'm working on a parser for desmos expressions and the syntax is very similar, so maybe some of the code can be reused. |
Thanks for the introduction, @abueno19! Could you join our Discord (https://discord.graphite.rs) and work with @urisinger in the new channel I created for this library project, which I've tentatively called |
This should be built as a library (in our
/libraries
directory) that uses a parsing framework such as nom or pest that takes a string at runtime and calculates its result, including units and dimensional analysis.This would make a great solo contribution for somebody interested in developing a robust solution for this problem without needing to learn any of Graphite's code base. It would also make a good university team/solo "capstone" project, which our organization can serve as an "industry sponsor" for.
Here's the spec:
Operators
+
-
*
/
%
^
+
-
√
!
(
and)
Constants
inf
,INF
,infinity
,INFINITY
,∞
i
,I
pi
,PI
,π
tau
,TAU
,τ
e
phi
,PHI
,φ
G
Variables
x
,y
,z
)theta
,alpha
,beta
,gamma
)λ
,あ
,👍
)Functions
sin()
,cos()
,tan()
csc()
,sec()
,cot()
ar-
andarc-
prefixes):asin()
,acos()
,atan()
,atan2()
acsc()
,asec()
,acot()
sinh()
,cosh()
,tanh()
csch()
,sech()
,coth()
ar-
andarc-
prefixes):asinh()
,acosh()
,atanh()
acsch()
,asech()
,acoth()
ln()
log()
log2()
logN()
(alias:log_N()
)log5()
,log3.25()
,log_8()
log(x, b)
exp()
exp2()
sqrt()
(alias:root()
,root2()
,root_2()
)cbrt()
(alias:root3()
,root_3()
)rootN()
(alias:root_N()
)root3()
,root5.237()
,root_27.72()
root(n, x)
root(27, 3)
is equivalent tocbrt(27)
Hypotenuse equation sqrt(a^2 + b^2):
hypot()
abs()
(magnitude of a real or complex number)floor()
ceil()
round()
clamp(x, min, max)
lerp(a, b, t)
trunc()
frac()
sign()
isnan()
(returns 1 if the operand is NaN, 0 otherwise)eq()
(returns 1 if both operands and units are equal, 0 otherwise)greater()
(returns 1 if the left operand is greater than the right operand and units are equal, 0 otherwise)greatereq()
(returns 1 if the left operand is greater than or equal to the right operand and units are equal, 0 otherwise)lesser()
(returns 1 if the left operand is less than the right operand and units are equal, 0 otherwise)lessereq()
(returns 1 if the left operand is less than or equal to the right operand and units are equal, 0 otherwise)not()
(returns 1 if the operand is zero, 0 otherwise)and()
(returns 1 if both operands are non-zero, 0 otherwise)or()
(returns 1 if either operand is non-zero, 0 otherwise)xor()
(returns 1 if exactly one operand is non-zero, 0 otherwise)if(cond, a, b)
(returnsa
ifcond
is non-zero,b
otherwise)true
andfalse
as units with either no value, a value of 0, or a value of 1real()
imag()
arg()
(alias:angle()
)Number representations
0
,42
,-42
)0.5
,3.14159
,-2.71828
)1e-6
,2.5E3
)3i
,-2.5i
,1.5e-3i
,2.5e3 + 2.1e-2i
)5m
,5 m
,3.5kg
,3.5 kg
,2.5m/s^2
,2.5 m/s^2
)Units
5m + 3m -> 8m
5ft + 3ft -> 8ft
5m + 3ft -> 5.9144m
(meters are chosen because 1ft = 0.3048m exactly, while its inverse can't be represented exactly)Unit list
px
m
and its prefixesthou
,pc
,pt
,in
/"
,ft
/'
,yd
,mi
,nmi
acre
,are
,hectare
A0
,A1
,A2
,A3
,A4
,A5
,A6
,A7
,A8
,A9
,A10
floz
,cup
,pint
,qt
,gal
l
and its prefixeskg
and its prefixesgr
,oz
,lb
,ton
,tonne
s
and its prefixesmin
,hr
,day
deg
/°
rad
(unitless is not an angle)turn
m/s
,km/h
,mph
,knot
m/s^2
,ft/s^2
,g
deg/s
,rad/s
,rpm
,rps
deg/s^2
,rad/s^2
Unit metric prefixes
n
)µ
,u
)m
)c
)d
)da
)h
)k
)M
)G
)T
)Implicit multiplication
*
operator3x
,2pi
)4sin(90deg)
)xy
,pi r^2
)API features
The text was updated successfully, but these errors were encountered: