Skip to content

Conversation

@ChrisRackauckas
Copy link
Member

@ChrisRackauckas ChrisRackauckas commented Sep 19, 2024

This fixes an odd bug that can occur when a constant can match, like Differential(2)(2x) == x, when it should obviously be zero. This fixes Differential(number) == ZeroOperator which acts like a hard zero. You need ZeroOperator instead of 0 because otherwise you codegen to stuff like 0(2x) and get an error that 0 does not have a call, and zero the function does not do things like zero * zero appropriately, so constructing a simple operator that acts like a true zero is the simplest solution that enforces the safety.

Edit: Differential(1) => error.

@karlwessel
Copy link
Contributor

Since I also stumbled about this: does it even make sense to derive with respect to a constant? Shouldn't it be considered an error?

See for example this answer for an arguments why those derivatives shouldn't exist.

@ChrisRackauckas
Copy link
Member Author

Yeah, it shouldn't be zero it should just be an error. We should add that error.

This fixes an odd bug that can occur when a constant can match, like `Differential(2)(2x) == x`, when it should obviously be zero. This fixes Differential(number) == ZeroOperator which acts like a hard zero. You need ZeroOperator instead of 0 because otherwise you codegen to stuff like 0(2x) and get an error that 0 does not have a call, and `zero` the function does not do things like `zero * zero` appropriately, so constructing a simple operator that acts like a true zero is the simplest solution that enforces the safety.
@karlwessel
Copy link
Contributor

We should add that error.

Yes. An error would probably have helped me to find the reason for the failing MWE from PR #1511 earlier.

@karlwessel
Copy link
Contributor

If it makes sense to you I can add that check to PR #1511.

@ChrisRackauckas ChrisRackauckas changed the title Create ZeroOperator and make D(const) a hard zero Make D(const) error Apr 1, 2025
@ChrisRackauckas
Copy link
Member Author

I just rebased this PR to add an error for it. We could also error earlier, we might need to in some cases error in the derivative expansion.

@ChrisRackauckas ChrisRackauckas merged commit 0b90807 into master Apr 1, 2025
17 checks passed
@ChrisRackauckas ChrisRackauckas deleted the hardzero branch April 1, 2025 16:23
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.

3 participants