पैकेज, रिपॉज़िटरी और ऐप श्रेणियाँ खोजें

पैकेज विवरणv0.9.1

function_tree

एक सरल पुस्तकालय जो अंकगणितीय व्यंजकों को फ़ंक्शन-ट्री में बदलता है।

AndroidiOSWebmacOSWindowsLinux
30-दिन डाउनलोड
12.3 हज़ार
लाइक
78
Pub अंक
150

पैकेज इंस्टॉल करें

flutter pub add function_tree

पैकेज अवलोकन

सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।

FunctionTree एक हल्का Dart पुस्तकालय है जो स्ट्रिंग में गणितीय अभिव्यक्तियों को निष्पाद्य फ़ंक्शन ट्री में पार्स करने की अनुमति देता है। यह उन्हें संरचित, कॉल करने योग्य संचालन में बदलकर अभिव्यक्तियों का सुरक्षित मूल्यांकन करता है, जिसमें मूल गणित, चर और कस्टम फ़ंक्शन शामिल हैं। ऐप में उपयोगकर्ता-निर्धारित गणनाओं के लिए डायनामिक सूत्र मूल्यांकन के लिए आदर्श है, जैसे कैलकुलेटर, वैज्ञानिक उपकरण या डेटा प्रसंस्करण इंटरफ़ेस। पुस्तकालय प्लेटफॉर्म-अनासक्त है, जो Android, iOS, Web, macOS, Windows और Linux पर काम करता है।

उपयोग

  • गतिशील सूत्र मूल्यांकन
  • कैलकुलेटर एप्लिकेशन्स
  • वैज्ञानिक गणना
  • डेटा रूपांतरण स्क्रिप्ट
  • उपयोगकर्ता-परिभाषित एक्सप्रेशन पार्सिंग

मुख्य विशेषताएँ

  • स्ट्रिंग से फंक्शन तक का वृक्ष पार्सिंग
  • सुरक्षित एक्सप्रेशन मूल्यांकन
  • चर और कस्टम फ़ंक्शन का समर्थन
  • क्रॉस-प्लेटफॉर्म संगतता
  • न्यूनतम रनटाइम ओवरहेड

इनके लिए उपयुक्त

  • गणना-भारी एप्लिकेशन फीचर्स
  • इंटरैक्टिव कैलकुलेटर
  • कॉन्फ़िगरेबल डेटा प्रोसेसिंग
  • शैक्षिक उपकरण
  • बैकएंड एक्सप्रेशन इंजीन

विचार योग्य बातें

  • जटिल गणित पुस्तकालयों (उदाहरण के लिए, त्रिकोणमिति) का समर्थन बॉक्स में नहीं है
  • आइन्जेक्शन जोखिम को रोकथाम के लिए सावधानीपूर्वक इनपुट वैलिडेशन की आवश्यकता होती है
  • अतिरिक्त सेटअप के बिना मूल गणित तक सीमित
  • उच्च आवृत्ति के बार-बार मूल्यांकन के लिए अनअनुकूलित
  • कोई बिल्ट-इन त्रुटि पुनर्स्थापन या विस्तृत निदान नहीं है

मूल README

संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।

Function Tree

Welcome to function_tree, a simple library for parsing strings into callable function-trees.

Parsing strings as mathematical expressions

At the simplest (and least efficient) level, we can interpret strings as mathematical expressions:

final expressions = [
  "2 + 2",
  "(3 + 2)^3",
  "3 * pi / 4",
  "3 * sin(5 * pi / 6)",
  "e^(-1)"
];
for (final expression in expressions) {
  print("'$expression' -> ${expression.interpret()}");
}

'2 + 2' -> 4.0
'(3 + 2)^3' -> 125.0
'3 * pi / 4' -> 2.356194490192345
'3 * sin(5 * pi / 6)' -> 1.5000000000000009
'e^(-1)' -> 0.36787944117144233

Function Trees

The library supports two types of callable, function-trees, namely SingleVariableFunction and MultiVariableFunction.

Single variable functions

We can create a single variable function from a string either by constructing a SingleVariableFunction instance or by calling the toSingleVariableFunction string extension directly on a string, as in the following example.

final f = "20 * (sin(x) + 1)".toSingleVariableFunction(),
    pi = "pi".interpret();
for (var x = 0.0; x < 2 * pi; x += pi / 20) {
  print("|" + " " * f(x).round() + "*");
}

|                    *
|                       *
|                          *
|                             *
|                                *
|                                  *
|                                    *
|                                      *
|                                       *
|                                        *
|                                        *
|                                        *
|                                       *
|                                      *
|                                    *
|                                  *
|                                *
|                             *
|                          *
|                       *
|                    *
|                 *
|              *
|           *
|        *
|      *
|    *
|  *
| *
|*
|*
|*
| *
|  *
|    *
|      *
|        *
|           *
|              *
|                 *
Multi-variable functions

Similarly, we can construct a MultiVariableFunction instance or call the toMultiVariableFunction string extension to create a multi-variable function tree, as in the following example.

final times = "a * b".toMultiVariableFunction(["a", "b"]),
    values = [1, 2, 3, 4, 5];
for (final a in values) {
  final sb = StringBuffer();
  for (final b in values) {
    sb
      ..write(times({"a": a, "b": b}).floor())
      ..write("\t");
  }
  print(sb);
}

1	2	3	4	5	
2	4	6	8	10	
3	6	9	12	15	
4	8	12	16	20	
5	10	15	20	25	

TeX expressions

Function tree instances have a tex property for TeX expressions:

final f = "x * cos(y) + y * sin(x)".toMultiVariableFunction(["x", "y"]);
print(f.tex);

x cdot \cos\left( y \right) + y cdot \sin\left( x \right)

Derivatives

Derivative trees can be constructed through the SingleVariableFunction.derivative and MultiVariableFunction.partial methods.

final f = "(2 * x) ^ (1 / (x ^ 2))".toSingleVariableFunction(), 
    fDash = f.derivative("x");
print("x      y      y'");
for (var x = 0.5; x < 3.0; x += 0.25) {
  print(
    "${x.toStringAsFixed(4)} "
    "${f(x).toStringAsFixed(4)} "
    "${fDash(x).toStringAsFixed(4)}");
}
x      y      y'
0.5000 1.0000 8.0000
0.7500 2.0561 0.9215
1.0000 2.0000 -0.7726
1.2500 1.7976 -0.7663
1.5000 1.6295 -0.5780
1.7500 1.5054 -0.4229
2.0000 1.4142 -0.3134
2.2500 1.3460 -0.2373
2.5000 1.2937 -0.1837
2.7500 1.2529 -0.1452
final f = "sin(u ^ 2 + 2 * v)".toMultiVariableFunction(["u", "v"]), 
  fu = f.partial("u"), 
  fv = f.partial("v"),
  pi = "pi".interpret(),
  u = pi / 3,
  v = pi / 4;
  for (final fun in [f, fu, fv]) {
    print("${fun({"u": u, "v": v})}");
  }
0.4566033934365143
-1.8633212348878314
-1.779340710602958

Interpreter

The interpreter has support for the following:

Functions
One-parameter functions
abs     acos    asin    atan    ceil
cos     cosh    cot     coth    csc
csch    exp     fact    floor   ln      
log     round   sec     sech    sin
sinh    sqrt    tan     tanh
Two-parameter functions
log     nrt     pow
Constants
e       pi      ln2     ln10    log2e
log10e  sqrt1_2 sqrt2
Operations
+  -  *  /  %  ^

Thanks

Thanks for your interest in this library. Please file any bugs or requests here.

श्रेणियाँ

सोर्स रिपॉज़िटरी

इस पैकेज का उपयोग करने वाले प्रोजेक्ट