Skip to content

Program Documentation

Jackson Huse edited this page Aug 4, 2022 · 7 revisions

Quick Sections:

This is where explanations of what methods and algorithms will be.

Main classes and utility methods

gui.py

relative_to_assets(path: str) -> Path

      Description: Takes a string and appends the correct path to the assets folder (containing images) to the string input.
      Variables: str ASSETS_PATH (global)
      General Algorithm (if applicable): N/A
      Returns (if anything): Str, path relative to assets.

updateVariables()

      Description: Receives input from the fields of the GUI and updates the global variables associated with them.
      Variables: str functionStr (global), str variable (global), int point (global), int power (global), str lExpress (global), lambdaFunction lFunc (global)
      General Algorithm (if applicable): Assigns each variable and prints the result in console log. lExpress is assigned as "lambda " + variable + ": " + functionStr, then eval(lExpress) is used to generate a lambda function for the input function.
      Returns (if anything): N/A

calculate()

      Description: Calculates polynomials and generates graph and CRN.
      Variables: TODO
      General Algorithm (if applicable):
        1.   Updates global variables.
        2.   Determines FuncTypes value.
        3.   Sets global Function class variable.
        4.   Generates Polynomial and Rearrangement Coefficients.
        4.   Generates Circuit Diagram (NetworkX).
        4.   Generates the Chemical Reaction Network (CRN).
        5.   Determines the Maclaurin Series and Rearrangement Strings and displays them on GUI.
        6.   Traces the function to find the expected value and displays it on the GUI.
        7.   Displays the Chemical Reaction Network (CRN) on the GUI.
        8.   Displays the Circuit Diagram on the GUI.
      Returns (if anything): N/A, everything is done through global variables.

clearEq()

      Description: Clears the equation field in the GUI (button press).
      Variables: Tkinter Entry entry_4 (global)
      General Algorithm (if applicable): Delete from position 0 to end of input string.
      Returns (if anything): N/A

insertVar()

      Description: Insert a variable into the equation field in the GUI (button press).
      Variables: Tkinter Entry entry_4 (global), str variable (global)
      General Algorithm (if applicable): Insert at current cursor position.
      Returns (if anything): N/A

insertButton(button)

      Description: Inserts something into the equation field in the GUI (button press).
      Variables: Object button (pass by value), Tkinter Entry entry_4 (global)
      General Algorithm (if applicable): button variable is validated to a corresponding button on the GUI. When pressed, it will add what that button says into the equation field in the GUI.
      Returns (if anything): N/A

Misc Algorithms/Programming

      Description: Back-bone generation of the GUI.
      Variables: Tkinter Window window (global), Tkinter Canvas canvas (global), Tkinter Button button_{1-33} (global), PhotoImage button_image_{1-33} (global), Tkinter Entry entry_{1-8} (global), PhotoImage entry_image_{1-8} (global), PhotoImage image_{1-3} (global), PhotoImage image_image_3 (global)
      General Algorithm (if applicable):
        1.   Initialize Tkinter window.
        2.   Initialize Tkinter canvas and attach to window.
        3.   Initialize and position buttons, entries, labels, and images.
        4.   Make window resizeable.
        5.   Begin GUI loop.
      Returns (if anything): N/A

Function.py

Class Variables (Global)

      Description: Global variables initialized in self.init().
      Variables: NoneType->Graph circuit, NoneType->Dict horner_coeffs, NoneType->Dict doubleNAND_coeffs, NoneType->Dict poli_coeffs, NoneType->Dict taylor_coeffs, NoneType->str taylorString, NoneType->str rearrangeString, NoneType->str CRN, NoneType->str traceString, float traceValue, NoneType->RearrangeType rearrangeType, Lambda Function function, int point, int order, FuncType functype, str title, str `variable
      General Algorithm (if applicable): Set defaults in initialization, then as coefficients, graphs, and CRNs are generated, they'll be set to their correct values.
      Returns (if anything): N/A, global variables

generateCoeffs()

      Description: Generates taylor series, polynomial, and rearrangement coefficients and prints its findings. This step determines type of rearrangement.
      Variables: Dict taylor_coeffs (global), Dict poli_coeffs (global), str taylorString (global), RearrangementType rearrangementType (global), str rearrangementString (global), Dict horner_coeffs (global), Dict doubleNAND_coeffs (global)
      General Algorithm (if applicable):
        1.   Determine Taylor Coefficients, print findings.
        2.   Determine Polynomial Coefficients, print findings.
        3.   Generate polynomial string (taylorString).
        4.   Determine Rearrangement Type.
        5.   Generate rearrangement coefficients (either Horner's or Double-NAND), print findings.
        6.   Generate rearrangement string.
      Returns (if anything): N/A, sets global variables.

determineRearrangement()

      Description: Determines which rearrangement conditions the given function satisfies.
      Variables: Dict fixedPoliCoeffs (local), int (acting as bool) alternatingSign (local), int (acting as bool) decreasingCoeffs (local), int (acting as bool) decreasingCoeffs (local), int (acting as bool) allPositive (local), float poli_total (local), float lastValue (local)
      General Algorithm (if applicable):
        1.   Determine total of all polynomial coefficients.
        2.   Determine if the polynomial is all positive.
        3.   Determine if the polynomial coefficients are decreasing.
        4.   Determine if the polynomial is alternating signs (skips test if all positive).
        5.   If 0 <= coefficient total <= 1 and all coefficients are positive, assign Double NAND Replacement. if the coefficients are decreasing and alternating signs, assign Horner's Expansion.
        6.   Otherwise send Unknown error through gui.py.
      Returns (if anything): RearrangementType.DOUBLE_NAND, RearrangementType.HORNER, or RearrangementType.UNKNOWN

generateCircuit()

      Description: Generates a circuit diagram for the given function.
      Variables: RearrangeType rearrangeType (global), Graph circuit (global)
      General Algorithm (if applicable):
        1.   If Double-NAND rearrangement, calculate Util.doubleNAND_to_circuit(). If Horner's Expansion, calculate Util.horner_to_circuit(). (The GUI uses the self.circuit = ... to store and function.circuit to load the circuit diagram)
        2.   If rearrangement type is known (i.e., not unknown), display the generated graph to the user (this is NOT done through the GUI).
      Returns (if anything): Produces the generated graph to the user. No value is returned, however.

generateReactions()

      Description: Using the generated circuit diagram, generate a chemical reaction network (sequence).
      Variables: RearrangementType rearrangementType (global), str CRN (global)
      General Algorithm (if applicable): If rearrangement type is known (i.e., not unknown), generate the CRN using Util.make_reactions().
      Returns (if anything): N/A, sets a global variable.

generateTrace()

      Description: Find an estimated value for the function at the given point.
      Variables: RearrangementType rearrangementType (global), str traceString (global), int x (local), int point (global), float traceValue (global)
      General Algorithm (if applicable):
        1.   Determine traceString (rearrangementString, but forcing "x" to be the variable).
        2.   Set x to the value of the function's point specification and evaluate the string to generate the trace.
      Returns (if anything): N/A, sets a global variable.

isSinusoidal()

      Description: Checks if the function's type is Sinusoidal.
      Variables: FuncTypes functype (global)
      General Algorithm (if applicable): If the function type is SINE, COSINE, or SINUSOIDAL, return true.
      Returns (if anything): int either 1 (true) or 0 (false).

isExponential()

      Description: Checks if the function's type is Exponential.
      Variables: FuncTypes functype (global)
      General Algorithm (if applicable): If the function type is EXPONENTIAL, return true.
      Returns (if anything): int either 1 (true) or 0 (false).

isLogarithmic()

      Description: Checks if the function's type is Logarithmic.
      Variables: FuncTypes functype (global)
      General Algorithm (if applicable): If the function type is LOGARITHMIC, return true.
      Returns (if anything): int either 1 (true) or 0 (false).

isPolynomial()

      Description: Checks if the function's type is a polynomial.
      Variables: FuncTypes functype (global)
      General Algorithm (if applicable): If the function type is POLYNOMIAL, return true.
      Returns (if anything): int either 1 (true) or 0 (false).

Util.py

Polynomial Strings

taylorToPolyStr(func, forceX)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

doubleNANDFunctionToStr(func, forceX)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

hornerFunctionToStr(func, forceX)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

Coefficient Generators

make_taylor_coeffs(func)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

expand_binomial(point, n)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

make_polynomial(func)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

ignore_small_coeffs(coeffs, ignore_th=1e-4)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

make_horner(func)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

make_doubleNAND(func)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

Create NetworkX "gates"

AddBaseGate(graph, gateIndex, gateType, val1Type, value1, val2Type, val2)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

AddGateFromGate(graph, prevGateType, prevGateIndex, newGateIndex, gateType, valType, value)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

Generating Circuits

doubleNAND_to_circuit(func)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

horner_to_circuit(func)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

Misc Circuits

removeFrivolous(graph)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

show_graph(func)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

Generating Chemical Reaction Networks (CRNs)

make_reactions(graph)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

make_reaction(gate_type, input_substances, output_substances, gateName)

      Description:
      Variables:
      General Algorithm (if applicable):
      Returns (if anything):

Useful Enums

FuncTypes.py

      Description: This enum class houses types of polynomial rearrangement such as FuncTypes.SINUSOIDAL and FuncTypes.EXPONENTIAL
      Variables: SINE, COSINE, SINUSOIDAL, EXPONENTIAL, LOGARITHMIC, POLYNOMIAL

FuncTypes.isIn(self):

      General Algorithm (if applicable): If the input is a member of the enum class, return 1 (true); otherwise return 0 (false).
      Returns (if anything): int, 1 (true) or 0 (false).

GateTypes.py

      Description: This enum class houses types of polynomial rearrangement such as GateTypes.NAND and GateTypes.AND
      Variables: NAND, AND, BNAND, BAND, MUX (implementation of BNAND, BAND, and MUX are todo in the future)

GateTypes.isIn(self):

      General Algorithm (if applicable): If the input is a member of the enum class, return 1 (true); otherwise return 0 (false).
      Returns (if anything): int, 1 (true) or 0 (false).

NotGateTypes.py

      Description: This enum class houses types of polynomial rearrangement such as NotGateTypes.INPUT and NotGateTypes.CONSTANT
      Variables: INPUT, OUTPUT, CONSTANT, INTERMEDIATE

NotGateTypes.isIn(self):

      General Algorithm (if applicable): If the input is a member of the enum class, return 1 (true); otherwise return 0 (false).
      Returns (if anything): int, 1 (true) or 0 (false).

RearrangeType.py

      Description: This enum class houses types of polynomial rearrangement such as RearrangeType.HORNER and RearrangeType.DOUBLE_NAND
      Variables: HORNER, DOUBLE_NAND, UNKNOWN

RearrangeType.isIn(self):

      General Algorithm (if applicable): If the input is a member of the enum class, return 1 (true); otherwise return 0 (false).
      Returns (if anything): int, 1 (true) or 0 (false).

Clone this wiki locally