Skip to content
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

Derivatives #16

Open
kevinbarabash opened this issue Jun 16, 2017 · 7 comments
Open

Derivatives #16

kevinbarabash opened this issue Jun 16, 2017 · 7 comments

Comments

@kevinbarabash
Copy link
Member

Derivatives can be taken multiple times, this is usually referred to as the "order" of the derivative, e.g. 1st order, 2nd order, etc.

Derivatives can be take of different variables if the expression contains multiple variables, e.g. d^2/dxdy (x^2 + y^2).

There are also lots of way to specify the notation, but since we only care about semantics let's ignore representation for now.

Here are some expressions and possible AST representations:

f' --> { type: 'Apply': op: 'diff', args: [ f, _ ] },
f'' --> { type: 'Apply': op: 'diff', args: [ f, _, _ ] },
dy/dx --> { type: 'Apply': op: 'diff', args: [ y, x ] },
d/dx x^2 --> { type: 'Apply': op: 'diff', args: [ x^2, x ] },
d^2/(dxdy) (x^2 + y^2) --> { type: 'Apply': op, 'diff', args: [x^2 + y^2, x, y] },

The reason for going with diff instead of Derivative for the op specifier is that I'd like to continue to use MathML as an inspiration and they use diff.

@aliang8
Copy link

aliang8 commented Jun 16, 2017

What is the _ supposed to represented? I was thinking the expression would be f'(x^2) and the _ would be the polynomial.

@kevinbarabash
Copy link
Member Author

The derivative is supposed to be a placeholder... maybe that doesn't make sense. Maybe we could pass an natural number for the order of the derivatives when we're not specifying which variable we're differentiating, e.g.

f' --> { type: 'Apply', op: 'diff', args: [ f, 1 ] },
f'' --> { type: 'Apply', op: 'diff', args: [ f, 2 ] }

@aliang8
Copy link

aliang8 commented Jun 16, 2017

So when we do specify the polynomial (e.g. f'(x^2)), the ast would be
{ type : 'Apply', op: 'diff', args: [ f , 1, x^2] }.

And if we also specify the variable with which we are differentiating (e.g f''(x^2) dx) then the ast would be:
{ type: 'Apply', op: 'diff', args: [ f, 2, x^2 , [x] ] }

It would also help if we called them Lagrange and Leibniz notation.

@aliang8
Copy link

aliang8 commented Jun 16, 2017

I think the way I'm approaching this is to create a regex expression to match the fraction form for derivatives. By doing this, we will be assuming that dy/dx and similar notation will always refer to derivatives and not individual variables.

@kevinbarabash
Copy link
Member Author

I would parse f'(x^2) as evaluating f' at x^2 which would result in a AST like:

{ 
   type: 'Apply', 
   op: { type: 'Apply', op: 'diff', args: [ f, 1 ] },
   args: [ x^2 ],
}

I haven't seen f''(x^2) dx used as notation before. What does it mean?

It would also help if we called them Lagrange and Leibniz notation.

What would be the benefit of explicitly labelling the notation? There's lots of other notation that people could use to specify differentials e.g. Euler notation and Newton notation.

@aliang8
Copy link

aliang8 commented Jun 17, 2017

Got it. For the f''(x^2)dx notation, I was trying to specify which variable we are taking the derivative with respect to. If given a different expression like f''(x^2y^2), how should we handle it?

@kevinbarabash
Copy link
Member Author

I think what you're trying to describe might one of the following:

// 2nd derivative of x^2y^2
// doesn't make sense without saying which variable we're differentiating with respect to
(x^2y^2)'' --> { type: 'Apply', op: 'diff', args: [ 'x^2y^2', 2 ] }

f(x, y) = x^2y^2
f'' --> { type: 'Apply', op: 'diff', args: [ f, 2 ] }  // again, doesn't make sense given the definition of f

f(x) = x^2
f'' --> { type: 'Apply', op: 'diff', args: [ f, 2 ] }  // does make sense

That begs the question, why not require that derivatives always specify which variable the operation is with respect to? If there are multiple statements, we'd have to have the parser remember previous statements, e.g. f(x) = ..., now when it sees f'' it would know that is a derivative in 'x'. I'd like to avoid mixing semantics of know what variable f takes with parsing of the syntax. Once a number of statements have been parsed, we can do a second pass to change a derivative for which we don't know what it's with respect to, to one where we do know. This will keep the parser simpler.

There's also the question of representing differential equations where no variables are present, e.g.

f'' + 2f' - f = 0

The AST is one layer is a system. In addition to the AST there is also:

  • math properties which may induce constraints, e.g. division by 0 is undefined so this limits the values that a divisor can be
  • constraints due to previous statements, e.g. f(x) was defined to be a function so we can take it's derivative with respect to a single variable, but g(x, y) was defined to be a function in multiple variables so we have to take partial derivatives of it

Eventually, we'll need a way to describe and enforce these semantics.

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

No branches or pull requests

2 participants