パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v3.2.0

math_expressions

実数、ベクトル、および基本的な区間演算をサポートする数学式の解析および評価用ライブラリ。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
10.1万
いいね数
382
Pub ポイント
160

パッケージをインストール

flutter pub add math_expressions

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

数学式の解析および評価を行うためのFlutter/Dartパッケージで、実数、ベクトル、基本的な区間演算をサポートしています。文字列から数式を動的に計算できるため、電卓、科学アプリ、データ分析ツールに最適です。ライブラリは軽量でクロスプラットフォームであり、Flutterプロジェクトにスムーズに統合できます。標準的な演算子、関数、カスタム変数をサポートし、無効な入力に対して明確なエラー処理を行います。パーサーをゼロから作成せずに柔軟な数式評価が必要な開発者にとって理想的です。

用途

  • 科学計算機
  • 動的数式評価
  • アプリにおけるデータ分析
  • 教育用数学ツール
  • 物理シミュレーション

主な機能

  • 実数およびベクトルをサポートしています
  • 基本的な区間演算
  • カスタム変数および関数の定義
  • クロスプラットフォーム互換性
  • 堅牢なエラー処理
  • 文字列ベースの式パース

適している対象

  • 数学的に重いアプリケーション
  • 教育ソフトウェア
  • エンジニアリングおよび物理学アプリ
  • 電卓アプリ
  • データ駆動型 UI

注意事項

  • 高性能な数値計算向けに最適化されていない
  • 基本的な区間演算に制限される
  • インジェクションのような問題を防ぐために、入力の検証に注意が必要です
  • 複素数の組み込みサポートなし

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

math_expressions

A library for parsing and evaluating mathematical expressions.

  • Performs evaluations in real, vector, and interval contexts.
  • Supports expression simplification and differentiation.

math_expressions is inspired by mathExpr for Java and distributed under the MIT license.

Features

  • Evaluation of expressions in various modes: Real, Vector and Interval.
  • Parsing, simplification and differentiation of mathematical expressions.
  • Supporting most basic math functions out of the box.
  • Extensible through custom function definitions in code.
  • Well documented and tested.

This package contains a very simple command-line interpreter for real numbers:

dart pub run math_expressions:interpreter
What's not working yet?
  • Some evaluations in vector and interval space (especially functions).
  • N-dimensional vectors. Curently no more than four dimensions are supported.
  • The parser only works for real numbers.
  • Complex numbers.

Suggestions and pull requests are always welcome!

Usage

Below are two basic examples of how to use this library. There also is some additional example code available.

1. Expression creation and evaluation

This example shows how to evaluate

$\frac{(x^2+\cos y)}{3}$

for $x=2, y=\pi$

Build the expression

You can either create an mathematical expression programmatically or parse a string.

  • Create the expression programmatically:
  var x = Variable('x'), y = Variable('y');
  var xSquare = Power(x, 2);
  var yCos = Cos(y);
  var three = Number(3.0);
  Expression exp = (xSquare + yCos) / three;
  • Create the expression via the parser:
  ExpressionParser p = GrammarParser();
  Expression exp = p.parse("(x^2 + cos(y)) / 3");
Evaluate the expression
  • Bind variables and evaluate the expression as real number:
  // Bind variables:
  var context = ContextModel()
    ..bindVariableName('x', Number(2.0));
    ..bindVariableName('y', Number(math.pi));

  // Evaluate expression:
  var evaluator = RealEvaluator(context);
  num eval = evaluator.evaluate(exp);

  print(eval) // = 1.0
2. Expression simplification and differentiation

This example shows how to simplify and differentiate

$x \cdot 1 - (-5)$

  • Expressions can be simplified and differentiated with respect to a given variable:
  Expression exp = p.parse("x*1 - (-5)");

  print(exp);            // = ((x * 1.0) - -(5.0))
  print(exp.simplify()); // = (x + 5.0)

  Expression expDerived = exp.derive('x');

  print(expDerived);            // = (((x * 0.0) + (1.0 * 1.0)) - -(0.0))
  print(expDerived.simplify()); // = 1.0

Alternatives

Here are some other Dart libraries that implement similar functionality to math_expression: parsing and evaluating mathematical expressions.

  • expressions: an elegant and small library to parse and evaluate simple expressions.
  • function_tree: a library for parsing, evaluating and plotting single- and multi-variables numerical functions.

To the author's knowledge math_expressions is currently the only library supporting interval arithmetics.

カテゴリー

依存関係

依存関係一覧 2 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

ランキング