function_tree 0.2.6

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 50

function_tree

A library for parsing and evaluating numerical functions built from strings.

Usage

A simple usage example:

import 'package:function_tree/function_tree.dart';
import 'dart:math' show pi;

main() {
  var f = FunctionOfX("1.5 * sin(2 * (x - pi / 3)) + 2");
  print(f(pi));

  var ft = FunctionTree(
    fromExpression: "1.5 * sin(2 * (x - pi / 3)^2) + y",
    withVariableNames: ["x", "y"]);

  print(ft({"x": 1, "y": 2}));
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

Change log

0.2.6

Fixed ambiguity issue: if the user chooses a variable name in an expression that happens to be a special constant name (such as 'e'), the parser will take occurrences in the expression to mean that the variable.

0.2.5

  • Marked as ready for Dart 2.
  • dartfmt-ed some of the files.
  • Added support for the % operator.
  • Added support for floor, ceil and round.
  • Added come timing comparisons between evaluating native Dart functions, function tree instances and repeated string parsing in test/.

0.2.0

  • Re-wrote the parsing engine: code much cleaner and easier to read.
  • Cleared out deprecated dart:math constants.
  • Updated code for Dart 2.
  • Added support for abs.

0.1.1

  • Basic numerical differentiation.
  • Basic numerical integration (Simpson).
  • Basic zero-finding (Newton).
  • Very much proof of concept.

0.1.0

  • Initial version, proof of concept.
  • Very little checking of input at this stage.

example/example.dart

import 'package:function_tree/function_tree.dart';
import 'dart:math' show pi;

void main() {
  // FunctionOfX...
  var f = FunctionOfX("abs(sin(x)) + cos(abs(x)) / 2"),
      n = 50,
      xs = List.generate(n + 1, (i) => -pi + i * 2 * pi / n),
      ys = xs.map(f);

  // A rough sketch of the graph of this function over [-π, π].
  ys.map((y) => "|${" " * (y * 50).round()}+").forEach(print);

  // FunctionTree
  var tree = FunctionTree(
      fromExpression: "abs(sin(a) + cos(b))", withVariableNames: ["a", "b"]);

  print("+${"-" * xs.length}+");
  for (var a in xs) {
    print("|${xs.map((b) {
      var value = tree({"a": a, "b": b});
      if (value < 0.5) return " ";
      if (value < 1) return ":";
      if (value < 1.5) return "o";
      return "*";
    }).join()}|");
  }
  print("+${"-" * xs.length}+");
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  function_tree: ^0.2.6

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:function_tree/function_tree.dart';
  
Version Uploaded Documentation Archive
0.2.6 Aug 4, 2018 Go to the documentation of function_tree 0.2.6 Download function_tree 0.2.6 archive
0.2.5 Aug 3, 2018 Go to the documentation of function_tree 0.2.5 Download function_tree 0.2.5 archive
0.2.0 Jul 30, 2018 Go to the documentation of function_tree 0.2.0 Download function_tree 0.2.0 archive
0.1.1 Oct 2, 2017 Go to the documentation of function_tree 0.1.1 Download function_tree 0.1.1 archive
0.1.0 Sep 24, 2017 Go to the documentation of function_tree 0.1.0 Download function_tree 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
1
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:function_tree/function_tree.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0