Giter Club home page Giter Club logo

math-expressions's People

Contributors

albertodev01 avatar alexander-zubkov avatar asturaphoenix avatar creativecreatorormaybenot avatar domesticmouse avatar dvirberlo avatar edhom avatar fkleon avatar friendly-banana avatar jpnurmi avatar kamimark avatar markhats avatar mbullington avatar pepsin avatar widavies avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

math-expressions's Issues

A problem with logarithm

I created an expression with a logarithm, but the logarithms were replaced by negative numbers.
Example:
this expression: Parser().parse('log_{10.0}({x}) - log_{10.0}({y}) / log_{10.0}({2.0})'); was changed to this: 'log_{10.0}({-x}) - log_{10.0}({-y}) / log_{10.0}({-2.0})'

Module does not work with numerical values.

According to modules rule and other calculator. Provided number should be divided by 100 to get the result.

As a example :

12% = 0.12.

But when i try to use modules on the numerical value

Code i tried :

Expression exp = p.parse('12%');
print(exp.evaluate(EvaluationType.REAL, null).toString());

RangeError (index): Invalid value: Valid value range is empty: -1

Expand on custom functions

Currently we have only the option to create custom functions and use them on manually created expressions.
If we want to use them on a parse expression, it is currently not supported.
For example, I need to add a min & max operations (IDK why they are not included by default) and I cannot use them on parsed expressions.
It would be useful if we could add custom Tokens into the lexer.

How to handle percentage?

Hi,

Thanks for the package ๐Ÿ‘

My question is how to handle percentage?

Example 50 - 10%.

The expected result is 45.

But what I got is an exception.

RangeError (index): Invalid value: Valid value range is empty: -1

Parser.parse (package:math_expressions/src/parser.dart:50:28)

Sample code

    Parser p = Parser();

    Expression exp = p.parse('50 - 10%');

    print(exp.evaluate(EvaluationType.REAL, ContextModel()));

Thanks

Custom functions

Is it possible to create expressions from string containing custom functions and evaluate them? I'm trying to introduce inverse trygonometric functions and I'd like to evaluate "1+asin(0.5)" just like I can for example "1+sin(30)"

Missing documentation for syntax (parser)

I think it is awesome that functions like Log are supported ๐Ÿ™Œ

Problem

However, I cannot seem to figure out how to use something like log_e(x).

I would expect this to use e as the base and be equivalent to ln(x), however, it throws during parsing.

FormatException: The input String is not a correct expression

Rounding Off Issue

Hi, I tried to make a simple calculator using this library. But I am facing an issue with a very simple expression. I tried to multiple 2.3 with 3 and the answer received was 6.8999999999999995. Rather it should have been simply 6.9.
I have used the below code

Expression exp = p.parse('2.3 * 3');
double val = exp.evaluate(EvaluationType.REAL, null);

The value of double returned here is 6.8999999999999995 instead of 6.9.

Another example is with the expression 2.1 * 3 which returned 6.300000000000001 instead of 6.3.

Same is the case with 52.2 % 2 which returned 0.20000000000000284 instead of 0.2

Can any one help me here?

Does not support numeric suffixes?

final ContextModel cm = ContextModel();
cm.bindVariable(Variable('name1'), Number(123));
print(Parser().parse(c.textEditingController.text).evaluate(EvaluationType.REAL, cm));

error:

E/flutter (28656): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FormatException: The input String is not a correct expression
E/flutter (28656): #0      Parser.parse (package:math_expressions/src/parser.dart:142:7)
E/flutter (28656): #1      TestHome.build.<anonymous closure>.<anonymous closure> (package:aaa/home/test/TestHome.dart:62:50)
E/flutter (28656): #2      _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1072:21)
E/flutter (28656): #3      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:253:24)
E/flutter (28656): #4      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:627:11)
E/flutter (28656): #5      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:306:5)
E/flutter (28656): #6      BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:276:7)
E/flutter (28656): #7      GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:163:27)
E/flutter (28656): #8      GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:464:20)
E/flutter (28656): #9      GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:440:22)
E/flutter (28656): #10     RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:337:11)
E/flutter (28656): #11     GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:395:7)
E/flutter (28656): #12     GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:357:5)
E/flutter (28656): #13     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:314:7)
E/flutter (28656): #14     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:295:7)
E/flutter (28656): #15     _invoke1 (dart:ui/hooks.dart:167:13)
E/flutter (28656): #16     PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:341:7)
E/flutter (28656): #17     _dispatchPointerDataPacket (dart:ui/hooks.dart:94:31)
E/flutter (28656): 

Finding variable in equation?

Is it possible to find/calculate variable from equation?

Parser pdebug = Parser();
Expression expdebug = pdebug.parse("(((x) - 32)/1.8)+273.15")

So I have that this equation is equal to 50. So for I want "50 = (((x) - 32)/1.8)+273.15. Find x?

Thank you

Suppress conversion into e function

Hi,

I have an input like

8E

After I put this into the parser for evaluation, the parser instantly converts it into

e({8.0})

Is there a way to suppress this behaviour? I expect to get an error (unparseable or something) instead.

Sign handled Incorrectly with Exponentiation

First of all: thanks for this repo โค๏ธ This is an awesome package โœจ

Problem

This is a pretty simple problem to understanding:

Say we have the following expression: -x^2.
Here is how that expression is understood:

  • In mathematics: -(x^2).
  • In math_expressions: (-x)^2.

This is a pretty big/critical mathematical error/inaccuracy.

Rephrasing

In mathematics, exponentation, i.e. powers (^n), bind stronger than signs (-x/+x). This is handled incorrectly in math_expressions.

Example

-4^2:

  • In a calculator / in mathematics: = -16.
  • In math_expressions: = 16.

Fix

I am unfortunately not familiar with the code in this library (i.e. how it is built) - otherwise, I would create a PR to fix this right away.
I really want to get this fixed because it is a rather fundamental issue. If you can solve @fkleon, that would be amazing โค๏ธ
Otherwise, I would also appreciate if you hinted me at a potential fix for this, so that I can contribute it (I just want to get it fixed).

Support for physical units?

Great package - are you planning to support physical units in this package? Like area, length, mass, etc...?
There is a great JS library which allows for quite "complex" calculations like evaluate('10km/h > 17m/3s'). And even allows the creation of custom units.
https://mathjs.org/docs/datatypes/units.html

It would be awesome to have something similar in dart.

Variables should resolve before keywords.

Great library, one small issue I'm having though. It seems like you resolve built-in keywords/functions before the variables (from the ContextModel) are resolved. This yields a couple of problems.

If I bind a variable name like score, the library seems to be trying to resolve e and subsequently doesn't properly resolve score (as I presume its then trying to resolve scor?). This happens whenever any variable name contains a built-in keyword. Other examples of invalid variable names:

variable
ceiling
resin

Basically anything that contains e or a built-in function like sin, ceil, etc.

Also, it should be noted in my use case that variables can be named anything (my users define variables).

So for example, a variable name could be something like qw%d. This is more of a special case, and not really needed, but it would be nice if your code was smart enough to tell that this is probably a variable name and not a wd and d separated by a modulus. Although, if you're resolving variables first, this actually should be a fairly trivial case to handle.

Thanks! I can also take a look at fixing this if you point me in a right direction / have any pointers.

How to combine a double and a string?

Let's say I have something like this:

double amount = 100.55;
String formula = '5/105*.5';  // normally something I would fetch from Postgres
double total = amount * formula; // I want to return 2.39

How would I do that with this library?

Possible to extract variables from Expression?

For my project, I need to parse expressions and get a list of used symbols in that expression. This would look something like this:

String input = "x+y*z+3";
Expression e = Parser().parse(input);

List<String> symbols = e.symbols; // ["x", "y", "z"]

Is that possible with the current state? I couldn't find the function on my own.

Any expression that state a literal positive number with + doesn't parse

Any mathematical expression that state a literal positive number with + doesn't parse, like:

  • 7+(+7)
  • +7
  • 7*+7
  • cos(+7)

All above throws this exception:

The following IndexError was thrown while handling a gesture:
RangeError (index): Index out of range: index must not be negative: -1

When the exception was thrown, this was the stack: 
...
packages/math_expressions/src/parser.dart 45:27                     parse
...

However, when it states a literal negative number with - does parse. This should also work with +.

Exception when define variable Number with character "e"

Having my 'e' variable exception because of same name with exponential operation

void _expression_creation_and_evaluation() { Parser p = Parser(); Expression exp = p.parse('e'); ContextModel cm = ContextModel(); cm.variables = { 'e': Number(5.0), }; double eval = exp.evaluate(EvaluationType.REAL, cm); print('Expression: $exp'); print('Evaluated expression: $eval\n (with context: $cm)'); // = 1 }

The excetion thrown:

Unhandled exception: RangeError (index): Invalid value: Valid value range is empty: -1 #0 List.[] (dart:core-patch/growable_array.dart:264:36) #1 List.removeLast (dart:core-patch/growable_array.dart:336:20) #2 Parser.parse (package:math_expressions/src/parser.dart:78:44) #3 _expression_creation_and_evaluation (package:luklak_id_mobile/ui/pages/authorized/dashboard/gadgets/count_calculate/count.dart:23:22) #4 main (package:luklak_id_mobile/ui/pages/authorized/dashboard/gadgets/count_calculate/count.dart:11:3) #5 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19) #6 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)

Cross sum and incremental cross sum

Is it possible to include the calculation of the checksum and the incremental checksum in the functionality? Or there is the possibility of triggering external function calls to calculate the function yourself.
We are already using the library, but would like to expand the range of functions.

Calculation Mistake

Mycode;

print("(0.7 / 100)");
exp = p.parse("(0.7 / 100)");
print(exp.simplify().evaluate(EvaluationType.REAL, null));

Output;

0.006999999999999999

Expected;

0.007

wtf

is there anything I'm doing wrong ?

Negative zero

math_expressions: ^2.0.0

I'm wondering if this is a bug or an expected behavior?

Expression exp = Parser().parse("-1*0");
double eval = exp.evaluate(EvaluationType.REAL, null);
print(eval);
// -0.0

Images in the Pub.dev project

At-least add some representative images in the pub dev so that we can check if they are related to oour requirements .

'double' is not a subtype of type 'bool'

Hi, I'm pretty new in Flutter, so pardon my newbie question.

The above is the error I get in my debug console when I click the '=' button.
PS; I'm building a simple calculator.

Below is my code.

` else if (text == '=') {
expression = calcText;
expression = expression.replaceAll('ร—', '*');

          Parser p = Parser();
          Expression exp = p.parse(expression);
          ContextModel cm = ContextModel();
          bool eval = exp.evaluate(EvaluationType.REAL, cm);
          result = eval.toString();
          calcText = result;

}`

Support Boolean result ?

A question.
I have a series of formulas (symbol arithmetic) that I want to check for validity.
e.g. 3+3=6
In my test there was only the exception "FormatException: The input String is not a correct expression".
Is there a way to implement this at the moment, other than manually breaking down the formula into 2 separate formulas and comparing them ?

Question about improving lexer

I wrote a Lexer for your grammar.
I did it with parser_builder.
https://github.com/mezoni/parser_builder

Below are benchmarks and source code for lexer. It needs build.
Place this script file in the tool folder and execute it.
A lexer will be generated.

Where it will be generated is specified in the script.
In our case, tool/expr_parser.dart.

Future<void> main(List<String> args) async {
  final context = Context();
  context.optimizeForSize = false;
  await fastBuild(context, [_parse], 'tool/expr_parser.dart',
      header: __header, publish: {'parse': _parse});
}

This lexer is very easy to change (improve, expand possibilities).
You can easily add support for variables like foo2. Currently, this is not supported (it seems to me).
The lexer does not remove spaces, and throws a FormatException at the location of the error.
In your case, the errors will be primitive, because it is a lexer (lexical analysis), but not a parser (grammar).

Benchmark tests
'e^(x+2) +x * 2^2.5 * log(10,100) + (-(3.0^2.0))+- (1) + 1^1^1 * ln(10) / sqrt(10) * nrt(2,10) - ceil(1.2) + foo - baz_

Time passed: 0.000, Test 'math_expressions lexer': 2193.664 ms
Time passed: 2.196, Test 'parser_builder lexer': 38.308 ms
Time passed: 2.235, Test 'math_expressions lexer': 2308.093 ms
Time passed: 4.543, Test 'parser_builder lexer': 4.19 ms
Time passed: 4.547, Test 'math_expressions lexer': 2310.533 ms
Time passed: 6.858, Test 'parser_builder lexer': 4.146 ms
Time passed: 6.862, Test 'math_expressions lexer': 2321.319 ms
Time passed: 9.184, Test 'parser_builder lexer': 4.347 ms
Time passed: 9.188, Test 'math_expressions lexer': 2306.278 ms
Time passed: 11.494, Test 'parser_builder lexer': 4.142 ms

Source cod of lexer builder:

import 'package:math_expressions/math_expressions.dart';
import 'package:parser_builder/branch.dart';
import 'package:parser_builder/bytes.dart';
import 'package:parser_builder/character.dart';
import 'package:parser_builder/combinator.dart';
import 'package:parser_builder/fast_build.dart';
import 'package:parser_builder/multi.dart';
import 'package:parser_builder/parser_builder.dart';
import 'package:parser_builder/sequence.dart';
import 'package:parser_builder/transformers.dart';

Future<void> main(List<String> args) async {
  final context = Context();
  context.optimizeForSize = false;
  await fastBuild(context, [_parse], 'tool/expr_parser.dart',
      header: __header, publish: {'parse': _parse});
}

const __header = r'''
// ignore_for_file: unused_local_variable

import 'package:math_expressions/math_expressions.dart';
import 'package:source_span/source_span.dart';
import 'package:tuple/tuple.dart';

const _source =
    'e^(x+2) +x * 2^2.5 * log(10,100) + (-(3.0^2.0))+- (1) + 1^1^1 * ln(10) / sqrt(10) * nrt(2,10) - ceil(1.2) + foo - baz_';

void main() {
  final count = 1000;
  final names = ['math_expressions lexer', 'parser_builder lexer'];
  final tests = [_test1, _test2];
  final sw = Stopwatch();
  var repeat = 5;
  sw.start();
  while (repeat-- > 0) {
    for (var i = 0; i < tests.length; i++) {
      final name = names[i];
      final test = tests[i];
      final seconds = (sw.elapsedMilliseconds / 1000).toStringAsFixed(3);
      final title = 'Time passed: $seconds, Test \'$name\'';
      _measure(title, 1, () => test(count));
    }
  }
}

void _measure(String name, int count, Function() f) {
  final sw = Stopwatch();
  sw.start();
  for (var i = 0; i < count; i++) {
    f();
  }
  sw.stop();
  final time = sw.elapsedMicroseconds / 1000;
  print('$name: $time ms');
}

void _test1(int count) {
  for (var i = 0; i < count; i++) {
    final lexer = Lexer();
    final res = lexer.tokenize(_source);
  }
}

void _test2(int count) {
  for (var i = 0; i < count; i++) {
    final res = parse(_source);
  }
}

''';

const _eof = Named('_eof', Eof<String>());

const _isIdentEnd = CharClasses([_isIdentStart, CharClass('[_]')]);

const _isIdentStart = CharClass('[a-zA-Z]');

const _number = Named(
    '_number',
    Map1(
        Recognize<String>(
          Sequence([
            Digit1(),
            Opt(Sequence([Tag('.'), Digit1()])),
          ]),
        ),
        Expr<Token>(['x'], 'Token({{x}}, TokenType.VAL)')));

const _parse = Named('_parse', Delimited(_ws, _tokenize, _eof));

const _token = Named(
    '_token',
    SwitchTag<Token>({
      '+': Skip(1, Expr.value("Token('+', TokenType.PLUS)")),
      '-': Skip(1, Expr.value("Token('-', TokenType.MINUS)")),
      '*': Skip(1, Expr.value("Token('*', TokenType.TIMES)")),
      '/': Skip(1, Expr.value("Token('/', TokenType.DIV)")),
      '%': Skip(1, Expr.value("Token('%', TokenType.MOD)")),
      '^': Skip(1, Expr.value("Token('^', TokenType.POW)")),
      '!': Skip(1, Expr.value("Token('!', TokenType.FACTORIAL)")),
      'sqrt': Skip(4, Expr.value("Token('sqrt', TokenType.SQRT)")),
      'log': Skip(3, Expr.value("Token('log', TokenType.LOG)")),
      'cos': Skip(3, Expr.value("Token('cos', TokenType.COS)")),
      'sin': Skip(3, Expr.value("Token('sin', TokenType.SIN)")),
      'tan': Skip(3, Expr.value("Token('tan', TokenType.TAN)")),
      'arccos': Skip(6, Expr.value("Token('arccos', TokenType.ACOS)")),
      'arcsin': Skip(6, Expr.value("Token('arcsin', TokenType.ASIN)")),
      'arctan': Skip(6, Expr.value("Token('arctan', TokenType.ATAN)")),
      'abs': Skip(3, Expr.value("Token('abs', TokenType.ABS)")),
      'ceil': Skip(4, Expr.value("Token('ceil', TokenType.CEIL)")),
      'floor': Skip(5, Expr.value("Token('floor', TokenType.FLOOR)")),
      'sgn': Skip(3, Expr.value("Token('sgn', TokenType.SGN)")),
      'ln': Skip(2, Expr.value("Token('ln', TokenType.LN)")),
      'e': Skip(1, Expr.value("Token('e', TokenType.EFUNC)")),
      'e^': Skip(2, Expr.value("Token('e', TokenType.EFUNC)")),
      '(': Skip(1, Expr.value("Token('(', TokenType.LBRACE)")),
      ')': Skip(1, Expr.value("Token(')', TokenType.RBRACE)")),
      '{': Skip(1, Expr.value("Token('{', TokenType.LBRACE)")),
      '}': Skip(1, Expr.value("Token('}', TokenType.RBRACE)")),
      ',': Skip(1, Expr.value("Token(',', TokenType.SEPAR)")),
      null: Alt2(_val, _var),
    }));

const _tokenize = Named(
    '_tokenize',
    Map1(ManyTill(Terminated(_token, _ws), _eof),
        Expr<List<Token>>(['x'], '{{x}}.item1')));

const _val = Named('_val', _number);

const _var = Named(
    '_var',
    Map1(
        Recognize<String>(
            Sequence([Satisfy(_isIdentStart), SkipWhile(_isIdentEnd)])),
        Expr<Token>(['x'], 'Token({{x}}, TokenType.VAR)')));

const _ws = Named('_ws', SkipWhile(CharClass('#x9 | #xA | #xD | #x20')));

typedef Expr<T> = ExprTransformer<T>;

[Bug] Wrong result for numbers more than 16 digits

Wrong result comes for numbers more than 16 digits. For example

Expression expression = Parser().parse('88888888888888888');
print(expression.toString());

Expected result should be 88888888888888888 but we get 88888888888888900.0 which is wrong.

NB: This happens for each and every number.

If possible, please provide a resolution ASAP as I'm using it in my production app.

ceil function fails to parse correctly

The ceil function is failing to parse properly. This is because when the parser gets to the 'e' in ceil it recognises it as TokenType.EFUNC. This then messes up the subsequent parsing. This issue will occur with all functions containing the 'e' character.

I guess it perhaps needs to check varBuffer or something before deciding to create the EFUNC token.

Code in question is around:

if (keywords.containsKey(si)) {

Implicit multiplication

First of all, again: I really appreciate your work on this package โœจ

Problem

In mathematics, you can usually write 2x to refer to 2 * x. This is also how e.g. calculators, TeX, etc. handle it.

math_expressions does not seem to be able to handle implicit multiplication.

Using 2x in an expression will throw an exception.

derive is inaccurate

the steps to reproduce
Parser p =Parser();
Expression exp = p.parse("x^2");
exp.derive('x'); // (e({(2.0 * ln(x))}) * ((2.0 * (1.0 / x)) + (0.0 * ln(x))))
exp.derive('x').simplify() // ((x^2.0) * (2.0 * (1.0 / x)))

Expected output
2*x

can't parse "(3/4)nrt(5)"

Parser p = new Parser();
Expression exp = p.parse('(3/4)nrt(5)');

Such code throw an error:
type 'Divide' is not a subtype of type 'Number' in type cast

Support evaluating Vector expressions of arbitrary length

Are there plans to support evaluating Vector expressions of arbitrary length?

Calling evaluate in the following example ...

ContextModel cm = new ContextModel();

Expression vector1 = new Vector([new Number(1), new Number(2), new Number(3), new Number(4), new Number(5)]);
Expression vector2 = new Vector([new Number(1), new Number(2), new Number(3), new Number(4), new Number(5)]);

Expression e = vector1 + vector2;

print(e.evaluate(EvaluationType.VECTOR, cm));

... causes UnimplementedError to be thrown:

Exception: UnimplementedError: Vector of arbitrary length (> 4) are not supported yet.
  Vector.evaluate   
  Plus.evaluate 
  ...

The expected output is "2.0,4.0,6.0,8.0,10.0". It would be great if this limit can be removed.

It seems the current implementation is 99% there. Perhaps classes Vector2, Vector3, and Vector4 can be generalized into a new class that constructs a vector of arbitrary size?

Support percentage operator in parser

It just doesn't work right, I have tried to do the calculation of various percentages but it doesn't work right, it gives wrong result.
For example if I put something as simple as:
'8%9'.interpret();
the output is: 8
when it should be: 0.72

If you could fix it please because this gives me a lot of problems and I need to make a calculator that is already ready and that error will not let me finish it.

Null safety migration

Hello!

Some packages of mine depend on math_expressions and it's working very well.
We were wondering if you were going to start the NNBD migration soon. Would you also need any help with it?

Regards,
Alberto

LaTeX lexer

A minimal TeX equation lexer would be very useful for me. I'm not sure if it's easy to add TeX subscript and fractions to the Lexer though.

Depending on github for vector_math causes conflicts

In revision 961ba77, the following change was made to pubspec.yaml:

-  vector_math: '>=1.3.5 <1.5.0'
+  vector_math:
+    git: git://github.com/google/vector_math.dart.git

The new dependency on github causes projects that depend on math-expressions to use the older version 0.1.0 if there are other packages that depend on the "normal" version of vector_math. Although the problem can be fixed with override_dependencies, the problem is subtle and painful to debug.

floor and ceil function

hi
how can i use floor and ceil in my expression
i used โŒˆxโŒ‰ and โŒŠxโŒ‹ in my expression but it doesn't work

Variable name with a combination of characters and numbers causes an error

Thank you for providing this plug-in, but when I set the variable to a combination of letters and numbers, I get an error. Is this a plug-in problem?

My code looks like this:

void test() {
  Parser p = Parser();
  Expression exp = p.parse('\$s2*5');
  ContextModel cm = ContextModel();
  Variable x = Variable('\$s2');
  cm.bindVariable(x, Number(0.5));
  var evaluate = exp.evaluate(EvaluationType.REAL, cm);
  print(evaluate.toString());
}

The plug-in version currently in use is: 2.0.1

E/flutter (10407): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FormatException: The input String is not a correct expression
E/flutter (10407): #0      Parser.parse (package:math_expressions/src/parser.dart:130:7)
E/flutter (10407): #1      test (package:test_demo/test_function3.dart:21:22)
E/flutter (10407): #2      main (package:test_demo/test_function3.dart:12:3)
E/flutter (10407): #3      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:231:25)
E/flutter (10407): #4      _rootRun (dart:async/zone.dart:1190:13)
E/flutter (10407): #5      _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (10407): #6      _runZoned (dart:async/zone.dart:1630:10)
E/flutter (10407): #7      runZonedGuarded (dart:async/zone.dart:1618:12)
E/flutter (10407): #8      _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:223:5)
E/flutter (10407): #9      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
E/flutter (10407): #10     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter (10407): 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.