Giter Site home page Giter Site logo

randomtools's Introduction

randomtools

randomtools

Just to specify, these aren't RNG tools. They're tools that are random

So far, it includes:

  • Pipe function, similar to F#'s pipe operator
  • Existential quantifiers for first order logic
  • A numerical integration function
  • A graph class using adjacency lists

Documentation/Instructions:

---PIPE FUNCTION---

What does it do? It takes a variable or object, and 'pipes' it through a bunch of functions. It calls the first function on the data, then feeds the result to the next, and keeps doing that until it's been fed through the last function. Then it returns the result.

Syntax:

  • pipe (data, *functions)
  • Example: pipe (8, lambda x: x / 3, lambda x: x + 1) -> Output: [4, 5]

Params:

  • data: Can be any non-iterable variable. See notes for info about how to chain over an iterable.
  • functions: A bunch of functions. Include as many as you want, just make sure they're after 'data'

Notes:

  • Data is 'piped' through the functions in the order they're listed.
  • As of 14.12.21, you cannot chain an iterable without allowing for the functions passed into it to handle iterables.
  • Instead, you can use pipe_iterable (data, *functions). It's the same syntax, except data is an iterable object.
  • pipe pipes a single var, and returns the result. pipe_iterable basically just does that for each item in an iterable. It DOESN'T pass the iterable into any of the functions.

---QUANTIFIERS---

What does it do? It checks if a condition is true for any or for all items in a set. 'existential' returns true if at least one item in a collection returns true for the condition, and 'universal' returns true if all items in a collection return true for the condition.

Syntax:

  • universal (condition, collection)
  • existential (condition, collection)
  • Example: existential (lambda x: x == 5, {6, 3, 5, 7, 8}) -> Output: True

Params:

  • condition: Any function that returns either true or false
  • collection: A set, list, tuple or dictionary

---INTEGRATION---

Syntax:

  • integrate (lower, upper, func, accuracy = 500)
  • Example: print (integrate (2, 8, func = lambda n : (n ** 2) + (5 * n) + 6)) -> Output: 352.68165513598973

Params:

  • lower: The lower bound of the integral
  • upper: The upper bound of the integral
  • func: The function to integrate
  • accuracy: The amount of 'slices' to split the area to find into

Notes:

  • The higher the accuracy, the better the approximation will be
  • Using a multi-variable function will break the program, I haven't added error handling yet lol

--GRAPH CLASS METHODS--

Constructor

Syntax:

  • G = Graph (AdjDict)
  • Example:

adjDict = {'A': ['B', 'C'], 'B': ['A', 'D'], 'C': ['A', 'D'], 'D': ['E'], 'E': ['D']} G = Graph (adjDict)

Params:

  • AdjDict: A dictionary containing the vertices as keys, and the values as a list of vertices that vertex is adjacent to

GetVertices ()

An instance method that returns a list of vertices. Literally just list (self.adj.keys ()) lol ;)

Syntax:

  • object.GetVertices ()
  • Example: print (G.GetVertices ()) -> Output: ['A', 'B', 'C', 'D', 'E']

Params:

  • None

GetEdges ()

An instance method that returns a list of edges, which are represented as sets. A set contains two vertices that have an edge between them.

Syntax:

  • object.GetEdges ()
  • Example: print (G.GetEdges ()) -> Output: [{'B', 'A'}, {'C', 'A'}, {'B', 'D'}, {'D', 'C'}. {'E', 'D'}]

Params:

  • None

AddVertex ()

Instance method that adds a vertex to the adjacency list.

Syntax:

  • object.AddVertex (vertex)
  • Example:

G.AddVertex ('F') print (g.GetVertices ()) -> Output: ['A', 'B', 'C', 'D', 'E', 'F']

Params: = vertex: the name of the vertex.

AddEdge ()

Instance method that adds an edge to the adjacency dict.

Syntax:

  • object.AddEdge (edge)
  • Example:

G.AddEdge ({'E', 'F'}) G.AddEdge ({'D', 'F'}) print (G.GetEdges ()) -> Output: [{'B', 'A'}, {'C', 'A'}, {'B', 'D'}, {'D', 'C'}, {'E', 'D'}, {'E', 'F'}, {'F', 'D'}]

Params:

  • edge (set): a set containing the two vertices the edge connects.

randomtools's People

Contributors

v0idzdev avatar

Watchers

 avatar

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.