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

parse derivatives instead of just relying on tree #887

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

drdrew42
Copy link
Member

@drdrew42 drdrew42 commented Jul 26, 2023

Taking derivatives using the D method ends up creating formulas that refuse to reduce (e.g. constant products appearing in the derivative of a polynomial).

This PR modifies the behavior of the D method -- preserving the existing tree structure of the derivative, but now processing the result of that process (respecting the existing context flags for free).

@@ -39,7 +39,11 @@ sub Parser::D {
return (0 * $self)->reduce('0*x' => 1) unless defined $self->{variables}{$x};
$f = $f->D($x);
}
return $self->new($f);
my $deriv = $self->new($f);
$deriv->{string} = $deriv->{tree}->string;
Copy link
Member

Choose a reason for hiding this comment

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

This line means that any constants are clipped to 6 significant digits (the default number format), so the result may have different from the original.

You may also want to add a new reduction rule that controls doing this doing this, so it can be turned off, if desired.

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