funkoff 1.0.0 copy "funkoff: ^1.0.0" to clipboard
funkoff: ^1.0.0 copied to clipboard

discontinued
outdated

An over-powered engine to evaluate mathematical graph functions.

FUNK OFF 📈 #

Build Status

An over-powered engine to evaluate mathematical graph functions. 📈

About 📚 #

The other day, I wanted to compute a number of values for a function formula. I wondered how I could implement a function that handles cubes, squares and linear functions fed into a function as a string and produce a list of values as Ys from a given list of Xs. Funk Off is that library. It supports linear functions, quadratic functions and cubic functions!

Installation 📥 #

Adding to your project #

To add Funk Off to your project's dependencies, add this line to your project's pubspec.yaml:

From GitHub

depdencies:
  ...
  funkoff:
    git: git://github.com/iamtheblackunicorn/FunkOff.git

From Pub.dev

depdencies:
  ...
  funkoff: ^1.0.0

The three dots represent anything else that you might have in the dependencies section. Having done that, re-fetch your project's dependencies by running this in the project's root directory:

$ dart pub get

Usage 🔨 #

Importing #

Import the engine-API like this:

import 'package:funkoff/funkoff.dart';

Import the API for linear functions like this:

import 'package:funkoff/linearFunctions.dart';

Import the API for quadratic functions like this:

import 'package:funkoff/quadraticFunctions.dart';

Import the API for cube functions like this:

import 'package:funkoff/cubeFunctions.dart';

API #

Engine API

Map<String, dynamic> enginePatterns()

This method returns the lexing patterns needed for matching formulas.

Map<String, dynamic> engineAST()

This method returns the AST patterns needed for matching formulas.

Map<String, dynamic> cosmeticStatements()

Returns a map of the non-essential parser elements.

List

Generates a list of the schema [TOKEN_TYPE, TOKEN] and returns it.

String astParser(String formula)

Returns which type of function is being fed in as a string.

bool statementLinter(String formula)

Returns a Boolean value of whether the formula fed-in, is valid.

List

Returns a list of double values, containing, a,b, and c, if present.

void makeVisualTree(String formula)

This function logs a visual tree of the formula to the console.

void testEngine()

Tests the functions above.

Linear Functions API

double computeLinear(String formula, double value)

Computes Y from a given X and function formula and returns it as a double for linear functions.

List

Computes Ys from a given Xs and function formula and returns it as a List of doubles for linear functions.

void testLinears()

Tests the above methods for linear functions.

Quadratic Functions API

double computeQuadratic(String formula, double value)

Computes Y from a given X and function formula and returns it as a double for quadratic functions.

List

Computes Ys from a given Xs and function formula and returns it as a List of doubles for quadratic functions.

void testQuadratics()

Tests the above methods for quadratic functions.

Cube Functions API

double computeCube(String formula, double value)

Computes Y from a given X and function formula and returns it as a double for cubic functions.

List

Computes Ys from a given Xs and function formula and returns it as a List of doubles for cubic functions.

void testCubes()

Tests the above methods for cubic functions.

Example 📲 #

This is what a minimal example using Funk Off would look like.

/*
FUNK OFF by Alexander Abraham a.k.a. "The Black Unicorn".
Licensed under the MIT license.
*/

import 'package:funkoff/funkoff.dart'; // If you want to use the engine itself, use this!
import 'package:funkoff/linearFunctions.dart'; // If you want to use linear functions, import this!
import 'package:funkoff/quadraticFunctions.dart'; // If you want to use quadratic functions, import this!
import 'package:funkoff/cubeFunctions.dart'; // If you want to use cube functions, import this!

void main(){

  String linearFunction = '300.0 + ( 25.0 * t )';
  String quadraticFunction = '300.0 + ( 25.0 * t * t ) + ( 24.0 * t )';
  String cubeFunction = '300.0 + ( 25.0 * t * t * t ) + ( 26.0 * t * t ) + ( 24.0 * t )';
  List<double> testSet = [4.5, 4.6, 4.7, 4.8];
  double testX = 2;

  print(patternParser(linearFunction));
  print(astParser(linearFunction));
  print(statementLinter(linearFunction));
  print(irParser(linearFunction));
  makeVisualTree(linearFunction);

  print(patternParser(quadraticFunction));
  print(astParser(quadraticFunction));
  print(statementLinter(quadraticFunction));
  print(irParser(quadraticFunction));
  makeVisualTree(quadraticFunction);

  print(patternParser(cubeFunction));
  print(astParser(cubeFunction));
  print(statementLinter(cubeFunction));
  print(irParser(cubeFunction));
  makeVisualTree(cubeFunction);

  print(computeLinear(linearFunction,testX));
  print(computeQuadratic(quadraticFunction,testX));
  print(computeCube(cubeFunction,testX));

  print(computeLinearSet(linearFunction,testSet));
  print(computeQuadraticSet(quadraticFunction,testSet));
  print(computeCubeSet(cubeFunction,testSet));

  testEngine();
  testCubes();
  testQuadratics();
  testLinears();
}

Note 📜 #

  • Funk Off by Alexander Abraham a.k.a. The Black Unicorn
  • licensed under the MIT license
5
likes
0
pub points
0%
popularity

Publisher

verified publisherblckunicorn.art

An over-powered engine to evaluate mathematical graph functions.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

dartdoc, pedantic

More

Packages that depend on funkoff