FelixBot is a discord bot designed to help students visualize spaces and vectors in 2D and 3D using matplotlib. Also, solve optimization problems using CVXPY.
The bot is capable of many things. To make the bot listen to your messages, start the message with f::
followed by the desired command.
Here are the available commands:
-
f::show ... var ...
: This is used to display written equation in a better way. -
f::imagine
: This is used to display vector, a set of vectors, or an equation. You have multiple options to draw as follows:f::imagine vector
: displays a single vector.f::imagine vectors
: displays a set of vectors with#
to separate vectors apart.f::imagine equation ... var ... with constraints ... , ...
: displays an equation with some constraints.
-
f::optimize
: This is used to solve some optimization problems. Define the problem using the following commands:f::optimize func ... var ... with constraints ...
: solves general optimization problemsf::optimize linear A = [...] # b = [...] # c = [...]
: solves LP optimization problemsf::optimize quadratic P = [...] # q = [...] # ...
: solves quadratic optimization problemsf::optimize ls A = [...] # b = [...]
: solves least squares problems
-
f::check dt [ [...] , [...] ]
: This is used to check the definite type of a matrix and returns its eigenvalues.
- Easy to set up and use.
- Plot spaces and vectors.
- Can solve linear program, quadratic program and general functions optimization problems.
- Showing an equation in a mathematical form:
f::show sin(2*x_1*pi) / sqrt(x_2) var x_1 x_2
Response:
- Plotting a set of vectors:
f::imagine vectors [2, 3] # [1, 0] # [6,4]
Response:
- Plotting equation:
f::imagine equation x**2 + y**2 var x y with constraints x > 0
- Solving an optimization problem:
f::optimize linear c=[5, 1, 2, 0, -5, 6 ,0.5] # constraints= [x >= 0, sum(x) == 3]
You can use this link to make the bot join your server. Also, note that the bot needs a #bot-help
channel to be in the server before it arrives.
The link above will take you to this screen, where you get to choose which of the servers you mange you want to add the bot to.
NOTE: currently the bot is not hosted on any online server, therefore, sadly it's down
The project has an architecture of multiple modules that can be classified as follows:
- Bot entry point
- Taking the input
- Executing the input
main.py is the main entry point of running the bot. It only calls run_discord_bot()
from bot module.
bot.py contains 3 functions:
run_discord_bot()
which is responsible for running the bot. It also defines the behavior of the bot. Among receiving a message that starts withf::
it callsprocess_message
to process the input message.process_message(user, channel, user_message, client)
which calls theprocess
function from thehandle_responses
module to understand and analyze the input message.send_message_to_channel(user_id, channel, response)
which mentions the user that messaged the bot and sends the response of the bot to the channel.
handle_responses.py has one main function process
which extracts what command the user entered and calls the corresponding response function.
input_commands.py introduces 3 main classes that will be used to define and change the string input message into numeric values and equations. The classes are:
InputParser
: parses the input messages into an equation, variables, and constraints.VectorsParser
: parses the input into a vector or multiple vectors.OptimizationMatriciesParser
: this is used to parse the matricies and vectors used as optimization parameters.
validation.py works hand in hand with input_commands module. It makes sure that the input being fed into the input_command classes is valid.
help.py has one main function; show_general_guide()
which returns a general guide about the about and the functionality of it. Also, there are other functions that returns specific, more detailed message about each functionality of the bot.
write_latex.py has a main function which is show_latex
. Internal function __save_latex_png
uses latex.codecogs to convert the latex into PNG transparent images. After the image is saved, show_latex
returns the path to the PNG file.
See the documentation of the package here.
optimize.py has a main function which is solve
which analyzes the input command and calls the corresponding the solver functions; which are:
__optimize_general_functions
which solves a general function optimization problem.__optimize_linear_program
which solves LP optimization problem.__optimize_least_squares
which solves a least squares optimization problem.__optimize_quadratic
which solves a quadratic optimization problem.
check.py contains the main function; inspect
which chooses the function being executed depending on the user input.
Currently, the only check function is __check_definite_type
which checks the definite type of a matrix whether it's positive-definite, positive-semi-definite, negative-definite, ... etc.