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

No mechanism to define functions restricted to a domain #654

Closed
dpsanders opened this issue May 26, 2024 · 2 comments
Closed

No mechanism to define functions restricted to a domain #654

dpsanders opened this issue May 26, 2024 · 2 comments

Comments

@dpsanders
Copy link
Member

Suppose I want to define a function

f(x) = "sqrt(x) for x > 0,  and 0 for x < 0". 

I believe that currently we have no mechanism for a user to do this in terms of interval objects. (They would have to manually define it using inf, sup, if etc.)

A natural way would be to define Heaviside as in #653 and then

f(x) = Heaviside(x) * sqrt(x)

But this will give empty for x < 0, instead of 0, since sqrt(x) gives empty.

We either need a "strong 0" that gives 0 when multiplied by empty, or a general function

restrict_to_domain(f, D)

that does this in the interval context.

@dpsanders
Copy link
Member Author

This can be implemented using piecewise from this comment:

julia> f(x) = piecewise((-Inf..0 => x -> 0..0, 0..Inf => x -> sqrt(x)), x)
f (generic function with 1 method)

julia> f(1..2)
[0.0, 1.41422]_trv

julia> f(-1..1)
[0.0, 1.0]_trv

julia> f(-1..(-1))
[0.0, 0.0]_trv

@dpsanders
Copy link
Member Author

Superseded by #655

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

1 participant