A library for parsing and evaluating numerical functions built from strings.
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}));
}
Please file feature requests and bugs at the issue tracker.
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.
%
operator.floor
, ceil
and round
.test/
.abs
.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}+");
}
Add this to your package's pubspec.yaml file:
dependencies:
function_tree: ^0.2.6
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.
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  
0.2.5  Aug 3, 2018  
0.2.0  Jul 30, 2018  
0.1.1  Oct 2, 2017  
0.1.0  Sep 24, 2017 
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 uptodate the package is.
[more]

100

Overall:
Weighted score of the above.
[more]

50

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter, web, other
No platform restriction found in primary library
package:function_tree/function_tree.dart
.
Package  Constraint  Resolved  Available 

Direct dependencies  
Dart SDK  >=2.0.0dev.68.0 <3.0.0 