-
Notifications
You must be signed in to change notification settings - Fork 140
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
[WIP] Add symbolic integral #240
Changes from all commits
b3401bf
9ada0ec
0ed131b
4ac71b3
0f2fe53
0dae216
76871b3
59c7fae
53b3227
4c7bd4e
98efa55
73b3d54
3b2cb3c
530f3d5
061043c
a508dbf
29ff905
7f4d43f
60c1323
153463a
d96f248
320a71d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# basic integral struct with upper bound and lower bound. | ||
struct Integral{X, T <: Domain} <: Function | ||
x | ||
domain::T | ||
Integral(x,domain) = new{typeof(x),typeof(domain)}(Symbolics.value(x), domain) | ||
end | ||
|
||
(I::Integral)(x) = Term{SymbolicUtils.symtype(x)}(I, [x]) | ||
(I::Integral)(x::Num) = Num(I(Symbolics.value(x))) | ||
SymbolicUtils.promote_symtype(::Integral, x) = x | ||
|
||
function Base.show(io::IO, I::Integral) | ||
print(io, "Integral(", I.x, ", ", I.domain, ")") | ||
end | ||
|
||
Base.:(==)(I1::Integral, I2::Integral) = convert(Bool, simplify(isequal(I1.x, I2.x) && isequal(I1.domain, I2.domain))) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Symbolics, Test | ||
using DomainSets | ||
@variables x y | ||
|
||
I1 = Integral(x, ClosedInterval(1, 5)) | ||
I2 = Integral(x, ClosedInterval(1, 5)) | ||
@test I1 == I2 | ||
|
||
@variables v(..) u(..) x y | ||
D = Differential(x) | ||
Dxx = Differential(x)^2 | ||
I = Integral(y, ClosedInterval(1, 5)) | ||
eq = D(I(u(x,y))) ~ 0 | ||
eq_test = I(D(u(x,y))) | ||
@test isequal(expand_derivatives(eq.lhs), Symbolics.value(eq_test)) | ||
|
||
eq = Dxx((I(u(x,y)))) + I(D(u(x,y))) ~ 0 | ||
eq_test = I(D(u(x,y))) + I(D(D(u(x,y)))) | ||
@test isequal(expand_derivatives(eq.lhs), Symbolics.value(eq_test)) | ||
|
||
I = Integral(y, ClosedInterval(1, v(x))) | ||
eq = D((I(u(x,y)))) ~ 0 | ||
eq_test = I(D(u(x,y))) + D(v(x))*u(x, v(x)) | ||
@test isequal(expand_derivatives(eq.lhs), Symbolics.value(eq_test)) | ||
|
||
I = Integral(y, ClosedInterval(1, v(x))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if you test an integral with the integrand There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it does expand. Should I add this as a test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did, in the last commit. |
||
eq = Dxx((I(u(x,y)))) ~ 0 | ||
eq_test = D(I(D(u(x,y))) + D(v(x))*u(x, v(x))) | ||
eq_test_ = I(D(D(u(x,y)))) + D(D(v(x)))*u(x, v(x)) + 2D(u(x,v(x)))*D(v(x)) | ||
@test isequal(expand_derivatives(eq.lhs), Symbolics.value(eq_test_)) | ||
@test isequal(expand_derivatives(eq.lhs), expand_derivatives(eq_test)) | ||
|
||
eq = D((I(u(x,y)^2))) ~ 0 | ||
eq_test = I(2D(u(x,y))*u(x,y)) + D(v(x))*u(x, v(x))^2 | ||
@test isequal(expand_derivatives(eq.lhs), Symbolics.value(eq_test)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just using
Symbolics.derivative
could be fine.