패키지, 저장소 및 앱 카테고리 검색

패키지 상세v3.2.0

math_expressions

실수, 벡터 및 기본 구간 산술을 지원하는 수학식 파싱 및 평가를 위한 라이브러리입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
10.1만
좋아요
382
Pub 점수
160

패키지 설치

flutter pub add math_expressions

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

수학식을 분석하고 평가하기 위한 플러터/다트 패키지로, 실수, 벡터 및 기본적인 간격 연산을 지원합니다. 문자열에서 수학 공식을 동적으로 계산할 수 있어 계산기, 과학 앱, 데이터 분석 도구에 적합합니다. 라이브러리는 가볍고 크로스플랫폼이며 플러터 프로젝트에 쉽게 통합됩니다. 표준 연산자, 함수, 사용자 정의 변수를 지원하며 잘못된 입력에 대한 명확한 오류 처리 기능을 제공합니다. 파서를 처음부터 구축하지 않고도 유연한 수학식 평가가 필요한 개발자에게 이상적입니다.

사용 사례

  • 과학 계산기
  • 동적 수식 평가
  • 앱에서의 데이터 분석
  • 교육용 수학 도구
  • 물리 시뮬레이션

주요 기능

  • 실수 및 벡터를 지원합니다
  • 기본 구간 산술
  • 사용자 정의 변수 및 함수 정의
  • 크로스 플랫폼 호환성
  • 강력한 오류 처리
  • 문자열 기반 표현식 파싱

적합한 대상

  • 수학 중심 애플리케이션
  • 교육 소프트웨어
  • 공학 및 물리 응용 프로그램
  • 계산기 앱
  • 데이터 기반 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

순위