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

Adding new mathematical methods to mathy #86

Open
davud2635 opened this issue Oct 11, 2022 · 1 comment
Open

Adding new mathematical methods to mathy #86

davud2635 opened this issue Oct 11, 2022 · 1 comment

Comments

@davud2635
Copy link

Hi Justin, I'am a bit confused about which file/files I have to modify, in order to add new methods like Differentiation, integration etc. Can you tell me which folder or file, I have to modify ?

@justindujardin
Copy link
Owner

Hey Davud,

If you want to add differentiation to the expression trees, you'll need to modify the expressions.py file in the mathy_core repository.

You can find the relevant files here: https://github.com/mathy/mathy_core/blob/master/mathy_core/expressions.py

The older version of mathy_core had differentiation built-in to the expressions, so here's an example of what it might look like for the MultiplyExpression:

class MultiplyExpression(BinaryExpression):
    """Multiply one and two"""

    def operate(self, one, two):
        return one * two

    #      f(x) = g(x)*h(x)
    #     f'(x) = g(x)*h'(x) + g'(x)*h(x)
    def differentiate(self, by_variable):
        return AddExpression(
            MultiplyExpression(self.left, self.right.differentiate(by_variable)),
            MultiplyExpression(self.left.differentiate(by_variable), self.right),
        )

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