Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #622 from jiggzson/dev
Browse files Browse the repository at this point in the history
v1.1.12
  • Loading branch information
jiggzson authored Jul 6, 2021
2 parents efd745b + 2eff8cf commit 926e12d
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 18 deletions.
2 changes: 1 addition & 1 deletion all.min.js

Large diffs are not rendered by default.

26 changes: 18 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ return _.multiply(sum, product)
* nerdamer('x').eq('y')
* // false
*/
eq(value: number | string | Expression): Expression
eq(value: number | string | Expression): boolean

/**
* Checks if a value is less than another
Expand All @@ -321,7 +321,7 @@ return _.multiply(sum, product)
* nerdamer('8').lt(100)
* // true
*/
lt(value: number | string | Expression): Expression
lt(value: number | string | Expression): boolean

/**
* Checks if a value is less than or equal to another
Expand All @@ -332,9 +332,9 @@ return _.multiply(sum, product)
* nerdamer('x').lte(100)
* // false
*/
lte(value: number | string | Expression): Expression
lte(value: number | string | Expression): boolean

/**
/**
* Checks if a value is greater than another
* @param value The value being tested
* @example
Expand All @@ -343,9 +343,9 @@ return _.multiply(sum, product)
* nerdamer('800').gt(100)
* // true
*/
gt(value: number | string | Expression): Expression
gt(value: number | string | Expression): boolean

/**
/**
* Checks if a value is greater than or equal to another
* @param value The value being tested
* @example
Expand All @@ -354,7 +354,17 @@ return _.multiply(sum, product)
* nerdamer('x').gte(100)
* // false
*/
gte(value: number | string | Expression): Expression
gte(value: number | string | Expression): boolean

/**
* Expands a function or expression.
* @example
* nerdamer('x*(x+1)').expand();
* // x+x^2
* nerdamer('(x+y)*(x-5)*x').expand();
* // -5*x*y-5*x^2+x^3+x^2*y
*/
expand(): Expression
}

////////// CALCULUS
Expand Down Expand Up @@ -411,4 +421,4 @@ return _.multiply(sum, product)
* @param expression
*/
export function factor(expression: ExpressionParam): Expression
}
}
69 changes: 63 additions & 6 deletions nerdamer.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var nerdamer = (function (imports) {
"use strict";

//version ======================================================================
var version = '1.1.11';
var version = '1.1.12';

//inits ========================================================================
var _ = new Parser(); //nerdamer's parser
Expand Down Expand Up @@ -10858,6 +10858,68 @@ var nerdamer = (function (imports) {
dx = get(dx.substring(1, dx.length));
retval += 'integrate' + inBrackets(f + ',' + dx);
}
else if(token.value === 'int_') {
var l = parse_next(); // lower
i++; // skip the ^
var u = next().value; // upper
// if it is in brackets
if (u === undefined) {
i--;
var u = parse_next();
}
var f = parse_next(); // function

// get the variable of integration
var dx = next().value;
// skip the comma
if (dx === ',') {
var dx = next().value;
}
// if 'd', skip
if (dx === 'differentialD') {
// skip the *
i++;
var dx = next().value;
}
if (dx === 'mathrm') {
// skip the mathrm{d}
i++;
var dx = next().value;
}
retval += 'defint' + inBrackets(f + ',' + l + ',' + u + ',' + dx);
}
else if(token.value && token.value.startsWith('int_')) {
// var l = parse_next(); // lower
var l = token.value.replace('int_', '')
console.log('uppernow')
i++; // skip the ^
var u = next().value; // upper
// if it is in brackets
if (u === undefined) {
i--;
var u = parse_next();
}
var f = parse_next(); // function

// get the variable of integration
var dx = next().value;
// skip the comma
if (dx === ',') {
var dx = next().value;
}
// if 'd', skip
if (dx === 'differentialD') {
// skip the *
i++;
var dx = next().value;
}
if (dx === 'mathrm') {
// skip the mathrm{d}
i++;
var dx = next().value;
}
retval += 'defint' + inBrackets(f + ',' + l + ',' + u + ',' + dx);
}
else if(token.value === 'mathrm') {
var f = tokens[++i][0].value;
retval += f + parse_next();
Expand Down Expand Up @@ -12549,8 +12611,3 @@ var nerdamer = (function (imports) {
if((typeof module) !== 'undefined') {
module.exports = nerdamer;
};



var ans = nerdamer('sqrt(3^x)');
console.log(ans.toString())
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "javascript light-weight symbolic math expression evaluator",
"name": "nerdamer",
"license": "MIT",
"version": "1.1.11",
"version": "1.1.12",
"homepage": "http://nerdamer.com/",
"directory": {
"lib": "./"
Expand Down
5 changes: 3 additions & 2 deletions spec/TeXConvert.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var nerdamer = require('../nerdamer.core.js');
it('should convert from TeX', function () {
it('Should convert from TeX', function () {
expect(nerdamer.convertFromLaTeX('x^6 \\cdot cos(\\frac{1}{2})').toString()).toEqual('cos(1/2)*x^6');
expect(nerdamer.convertFromLaTeX('\\sqrt[3]{1+a}+1').toString()).toEqual('(1+a)^(1/3)+1');
expect(nerdamer.convertFromLaTeX('\\begin{matrix} \\begin{matrix}1 & 2 \\\\ 7 & 8\\end{matrix} & 2+9 \\\\ 7 & 8\\end{matrix}').toString())
.toEqual('matrix([matrix([1,2],[7,8]),11],[7,8])');
.toEqual('matrix([matrix([1,2],[7,8]),11],[7,8])');
expect(nerdamer.convertFromLaTeX('\\int_{0}^{\\pi}(\\sin(y)),y').toString()).toEqual('defint(sin(y),0,pi,y)');
});

0 comments on commit 926e12d

Please sign in to comment.