Git Product home page Git Product logo

amitygxmod-calculator's Introduction

Amity GX - Calculator

A browser extension designed for Opera GX, made for helping with algebra.

The extension currently has two sections:

  1. The notes section
  2. The calculator section

The notes section

image

The notes section is a textarea for users to type notes into. Its only notable qualities are:

  • Being vertically resizeable.
  • Horizontally scaling to fit the width of the entire panel.
  • Using a monospace font so that text can be aligned across multiple lines through the use of whitespace characters like space.

The calculator section

image

The calculator section is used for quickly performing all operations on a combination of numbers simultaneously, giving the user insights about how the numbers may relate to each other.

The calculator section is made up of three elements:

  1. Parameters
  2. Run calculations (ƒ) button
  3. Results section

Parameters

image

The parameters are a set of up to three numeric inputs. The number of parameters available is dependent on how many are filled in, or active. The number of active parameters also determines what operations are available in the Results section.

  1. Zero parameters:
    image

  2. One parameter (unary):
    image

  3. Two parameters (binary):
    image

  4. Three parameters (ternary):
    image

Entering a value into a parameter activates it, and makes the next parameter available. An available but inactive parameter has a grayed-out label and the ∅ (empty set) placeholder.
image image image

Run calculations (ƒ) button

image (enabled)
image (disabled)

When there is a change to the parameters, the ƒ button is enabled. Clicking it will refresh the results.

The ƒ button is only enabled when the current parameters are not identical to what they when used to calculate the currently-displayed results.

Calculations can also be run by pressing enter while focusing any of the parameters.

Results section

image image image

The results section shows the results of each operation for the parameters simultaneously.

Wherever a parameter appeares in the results section, it is colored to match that parameter's label. Results are shown in bold.
By default, the colors are as follow:

  • A: 🟥 Red
  • B: 🟦 Blue
  • C: 🟩 Green
  • [result]: 🟧 Orange

When a parameter changes, all instances of references to it in the results section are boxed in a gray, dashed outline to show what inputs of the calculation will be affected by the change. If it changes back to what it was when used to calculate the currently-displayed results, the outline disappears.

Unary results

image

Unary results disply all operations which can be performed on a single integer. Currently included are the following operations:

  • Quick Insights (name isn't final)

    • Whether the number is even or odd
    • Whether the number is prime or composite
  • Square $(A^{2})$

  • Square root $(\sqrt{A})$ — Simplifies radical to exact value

  • Factors

    factor $A$
    $1$ $\large\frac{A}{1} \therefore A$
    ... ...
    $n$ $\large\frac{A}{n}$

    $\forall n \in \{1,...,A\} : \frac{A}{n} \in \Bbb{Z}^+$

image

Binary results

image

Binary results disply all operations which can be performed on a pair of integers. Currently included are the following operations:

  • Comparison $(A \lt=\gt B)$ $((A\lt{B};A=B;A\gt{B}))$

  • Sum $(A+B)$

  • Difference $(A-B)$

  • Product $(AB)$

  • Quotient $(\frac{A}{B})$ — Simplifies fraction to exact value

  • Remainder $(A\bmod{B})$

  • Power $(A^{B})$

  • Log $(\log_{A}B)$

  • GCF (Greatest Common Factor)

  • LCM (Least Common Multiple)

  • Common factors

    factor $A$ $B$
    $1$ $\large\frac{A}{1} \therefore A$ $\large\frac{B}{1} \therefore B$
    ... ... ...
    $n$ $\large\frac{A}{n}$ $\large\frac{B}{n}$

    $\forall n \in \{1,...,\displaystyle\min_{\{A,B\}}\} : \{\frac{A}{n}, \frac{B}{n}\} \subset \Bbb{Z}^+$

image

Ternary results

image

Ternary results disply all operations which can be performed on a triplet of integers. Currently included are the following operations:

  • Quick Insights (name isn't final)

    • Whether the parameters are normalized or not
    • Whether the parameters compose a Pythagorean Triple $(A^{2}+B^{2}=C^{2})$ or not
  • Vector definition $(\underline{v}=(A,B,C))$

  • Vector length $(|\underline{v}|)$ $((\sqrt{A^{2}+B^{2}+C^{2}}))$

  • Vector normal $(\underline{\hat v})$ $((\frac{\underline{v}}{|\underline{v}|}))$ $(((\frac{(A,B,C)}{\sqrt{A^{2}+B^{2}+C^{2}}})))$

  • Sum $(A+B+C)$

  • Product $(ABC)$

  • GCF (Greatest Common Factor)

  • LCM (Least Common Multiple)

  • Quadratic formula $(\frac{-B\pm\sqrt{B^{2}-4AC}}{2A})$not yet implemented

  • Common factors

    factor $A$ $B$ $C$
    $1$ $\large\frac{A}{1} \therefore A$ $\large\frac{B}{1} \therefore B$ $\large\frac{C}{1} \therefore C$
    ... ... ... ...
    $n$ $\large\frac{A}{n}$ $\large\frac{B}{n}$ $\large\frac{C}{n}$

    $\forall n \in \{1,...,\displaystyle\min_{\{A,B,C\}}\} : \{\frac{A}{n}, \frac{B}{n}, \frac{C}{n}\} \subset \Bbb{Z}^+$

image

amitygxmod-calculator's People

Contributors

henrywilder avatar

Stargazers

 avatar

Watchers

 avatar

amitygxmod-calculator's Issues

Results need more separation

  • The lines of results are very close together and can be difficult to read. There should be at least a little more separation between lines; which shouldn't be difficult considering the results are already divs.
  • Additionally, there should also be a setting for modifying the size of the gap.

Macros

UI Elements needed:

  • Macro bar

Macros to add:

  • Symbol - List of math symbols for easy copy-paste in the notes section.
  • FOIL - Converter from "(a+b)(c+d)" to "ac+ad+bc+bd".
  • Factor - Converter from "a𝓍²+b𝓍+c" to "(𝓍±…)(𝓍±…)"

At the time of writing, these are all macros that currently exist in AlgebraBalancer.

Customization options

Certain parts of the extension's CSS should be configured through custom properties by the user's extension settings.

Options suggested:

  • Font colors
    • Implement one (or both) of the following:
      a) Let the user manually pick light/dark theme colors
      b) Automatically generate shades for whichever theme the user isn't using, based on their selection's distance from 50% gray
    • Parameters
    • Results
  • Font sizes
    • Notes section
    • Calculator inputs
    • Calculator results section
    • Macros section - Dependent on #1
    • Factors table
  • Font weight
    • Parameters
    • Results
  • Results gap size - Dependent on #8

System of equations

The calculator (or macro) section should have an option to solve for $n$ variables in a systems of $n$ equations.

Quotient should include mixed number

In addition to displaying the improper fraction result of the quotient operation, a mixed number should be displayed as well.
image

Example:
Instead of
$26 \div 8 = \frac{13}{4}$
Show
$26 \div 8 = \frac{13}{4} = 3\frac{1}{4}$

MathJax/LaTeX sidepanel

The notes section could have a preview tab/panel to display math using something more suited for math input.

The complexity of this depends on whether such a library exists in Node and how easy it is to implement the user input.

Quadratic result should communicate that x is being solved for

The quadratic placeholder currently shows
$$\large Ax^2+Bx+C=?$$
This is misleading. The right side of the equals sign should be 0. The functionality is to show what $x$ is.

It should instead show:
$$\large Ax^2+Bx+C=0; x=?$$

Or, if possible:
$$\large \frac{-B\pm\sqrt{B^2-4AC}}{2A}=?$$

Intermediate calculations

The AlgebraBalancer application has a feature which shows intermediate calculations for radical simplifications.

image

The extension should similarly mirror this feature, possibly for fractions as well.

The feature is useful because, as a learning tool, obfuscating steps in calculation should be avoided.
While some steps like "factor" and "gcf" should be hidden and treated more as atomic operations than as multi-step procedures, other steps like using the gcf should be explicitly shown when possible so that the user can better understand the math and learn to do it on their own instead of growing a reliance on the extension.

Parameter expressions

Parameter expressions

A highly useful feature currently implemented in AlgebraBalancer is the ability to write expressions in the parameter inputs, which are evaluated before being passed to calculations.
image
In AlgebraBalancer, this feature is safe because it uses DataTable, which evaluates specifically math and not code. I'm unsure whether a similar feature exists in Node, and I definitely want to avoid giving the user access to potentially dangerous options like eval().

In order to enforce the desired safety, it may be necessary to write a custom math evaluation function which sanitizes inputs before passing them to Function().

The sanitized inputs might be checked by matching them against a regex pattern. There could also be a second pattern (breaking them up to simplify the overall pattern) for checking that parentheses are balanced, if any are detected in the pattern.

// Tests whether the expression uses only whitelisted operations, and is therefore safe to pass to Function()
const isMathExpressionSafe = (expr: string): boolean => {
    // Any instance of open or close parentheses
    const parentheses = /\(|\)/g;
    // The string is safe if it:
    // 1. Has at least one integer
    //   1.1. Which may be preceded with a + or -
    // 2. Optionally followed by exactly one of the following:
    //   a)
    //     2a1. One of the following operations:
    //       - Exponentiation
    //     2a2. Which, if an operation exists, must always be followed by another integer
    //       2a2.1. Which may be preceded with a +
    //   b)
    //     2b1. One of the following operations:
    //       - Multiplication
    //       - Addition
    //       - Subtraction
    //     2b2. Which, if an operation exists, must always be followed by another integer
    //       2b2.1. Which may be preceded with a + or -
    // 3. Repeating section 2 for as many operations as are necessary
    const whitelistedMath = /^[+-]?[0-9]+(?:(?:\^\+?[0-9]+)|(?:[*+-](?:[+-]?[0-9]+)))*$/;
    let isExpressionValid = expr.replace(parentheses, '').match(whitelistedMath);
    
    if (expr.includes(parentheses)) {
        // For the cases where parentheses are encountered, they must either
        // A) Contain no instance of parentheses within them
        // B) Contain only parentheses which also follow this pattern, recursively
        const balancedParentheses = /\((?:[^)(]+|(?R))*+\)/;
        isExpressionValid &&= expr.match(balancedParentheses);
    }

    return isExpressionValid;
}

While exponents in parameter expressions are not supported in AlgebraBalancer, I believe they should be in this project considering the evaluator will be custom and can be made to map operations to their respective functions.

Negative exponents in parameter expressions should be disallowed. At the time of writing, it is an unwritten guideline for this project that parameters may not contain fractions nor radicals; only integers and math which simplifies to integers.

Division is not currently an expectation of the feature. Testing to confirm that the result doesn't resolve to a fraction nor undefined may be more effort than it is worth. It would also be frustrating to users for rule-following expressions to simply not evaluate sometimes.

Normized vectors are not in simplest form

Ternary results are displaying normalized vectors not in their simplest-form.

Example:
image

Current behavior

Vectors simplify per-element.
$$\large \hat{\underline{v}} = (\frac{\underline{v}_x}{|\underline{v}|},\frac{\underline{v}_y}{|\underline{v}|},\frac{\underline{v}_z}{|\underline{v}|})$$

Example:
$$\large \widehat{(3,4,5)} = (\frac{3}{\sqrt{50}},\frac{4}{\sqrt{50}},\frac{5}{\sqrt{50}}) = (\frac{3\sqrt{2}}{10},\frac{2\sqrt{2}}{5},\frac{\sqrt{2}}{2})$$

This is undesirable for readability and redundancy.

Expected behavior

Vectors should simplify as a complete whole.
$$\large \underline{\hat{v}} = \underline{v}\frac{1}{|\underline{v}|}$$

Example:
$$\large \widehat{(3,4,5)} = \frac{(3,4,5)}{\sqrt{50}} = \frac{(3,4,5)\sqrt{2}}{10}$$

Easter Egg 1

Have a bat fly across the panel when the user enters the Konami code
↑↑↓↓←→←→ba<enter>

Dark mode: fruit bat
Light mode: microbat

Log operation produces decimal

The binary log operation returns its non-integral results in the form of an irrational decimal.
image

I'm not sure how to display an irrational number better, but the program should always produce exact values.

Collapsible calculator section

Collapse Button

The calculator section has a lot of colors and text that can be distracting for a user trying to focus on working in the notes section. There should be a button for toggling the visibility of the calculator section at will.

Alternative: Clear Button

The calculator section is already very clean and free of distractions when no inputs are filled.
image
An alternative implementation could be to have a button that quickly clears all three ABC-parameter inputs instead of collapsing the section out of visibility.

Pros

  • Reduced number of clicks to begin using the calculator section; Instead of expanding the section before typing, the user can skip straight to typing.
  • Layout doesn't shift around as much.
    • Note: This may not be particularly valuable, as the layout already changes every time the number of filled inputs change.

Cons

  • An easily-pressed "clear" button can be destructive and potentially more frustrating than deleting all three inputs manually.
  • A clear button that requires extra effort to press can also be frustrating, depending on how frequently a user needs to perform the "clear" operation.

Quadratic Formula solving

One of the features of AlgebraBalancer is resolution of ternary parameters as quadratic formulas.

image

While this feature is not fully complete in the application, it should still be included in the extension.


At the time of writing, this feature currently exists in the extension in a placeholder state.

The feature was initially planned in commit 04a4679, before being added as a placeholder in commit 98557b2.

image

Active calculation refresh

There could be a toggle switch for enabling/disabling active refresh. This would mean that the calculation updates as the user types the inputs, without waiting for the ƒ button to be pressed.

This could be implemented as either a toggle in the panel or an extension setting.

The main reason to make calculations not refresh automatically is because it could cause typing to feel sluggish if the user is entering relatively complicated inputs. Also, it may just be user preference to click the button.

Add "unknown" inputs for solving equations with missing variables

When an input holds a value of ?, it could be used as a "for what value of this produces the result?"

For example: the parameters ${\color{red}A=5}, {\color{blue}B=?}, {\color{green}C=25}$ would result in the binary operations of:
$$\large \displaylines{ {\color{red}5} &amp;+&amp; {\color{darkorange} 20} &amp;= {\color{green}25} \\ {\color{red}5} &amp;-&amp; {\color{darkorange}-20} &amp;= {\color{green}25} \\ {\color{red}5} &amp;\times&amp; {\color{darkorange}5} &amp;= {\color{green}25} \\ {\color{red}5} &amp;\div&amp; {\color{darkorange}\frac{1}{5}} &amp;= {\color{green}25}}$$

and so on.

Factors: Sum and difference

Another feature of AlgebraBalancer which deserves to be ported to the extension is the sum/difference calculations on unary factors.

image

This feature provides users with information which can be helpful when factoring FOILed polynomials ( $(x+?_1)(x+?_2)$ ).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.