Skip to content

Derivative #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Derivative #53

wants to merge 23 commits into from

Conversation

aliang8
Copy link
Contributor

@aliang8 aliang8 commented Jun 17, 2017

Working on derivative parsing.

@kevinbarabash
Copy link
Member

Leibniz notation is going to be hard to handle within the parser. I would suggest parsing d/dx x^2 as

{ type: 'Apply', op: 'mul', args: [
   { type: 'Apply': op: 'div', args: [d, dx] },
   { type: 'Apply': op: 'pow', args: [x, 2] },
]}

And then performing a transform on the AST that converts fractions that look like d/dx etc. to differentials.

suite('nthRoot', [
'nthRoot(x)',
'nthRoot(x, 3)',
'nthRoot(8, 3)',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup

@@ -211,7 +220,7 @@ class Parser {

if (args.length > 1) {
return build.applyNode('add', args.map(term =>
term.addParens ? build.parensNode(term) : term))
term.addParens ? build.parensNode(term) : term))
Copy link
Member

@kevinbarabash kevinbarabash Jun 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this formatting change adds anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

@@ -272,7 +280,7 @@ class Parser {

return factors.length > 1
? build.applyNode('mul', factors, {implicit: true})
: factors[0];
: factors[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry! It's an issue with my text edit and the auto configs I have. Will fix


// Lagrange notation
// e.g. f', f'', f'(x)
if (node.name === 'f' && matches(this.currentToken(), `'`)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty restrictive. We should be able to parse the derivative of any function (or expression). This is so we can handle things like (af + bg)'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants