JuliaApproximation / ApproxFun.jl

Julia package for function approximation
http://juliaapproximation.github.io/ApproxFun.jl/
Other
538 stars 71 forks source link

Better DSL symbol for `Evaluation`? #590

Open jlperla opened 6 years ago

jlperla commented 6 years ago

Take http://juliaapproximation.github.io/ApproxFun.jl/latest/usage/equations.html#Boundary-conditions-1 and http://juliaapproximation.github.io/ApproxFun.jl/latest/usage/equations.html#Systems-of-equations-1 for example.

Currently the DSL for functions, operators, etc. is amazingly clear. The only wart I see is the need for the the Evaluation either on a function directly, or the function at a particular derivative for boundary conditions.

I don't have any great ideas here, other than that maybe a binary function based on a unicode symbol to emulate https://tex.stackexchange.com/questions/40160/math-symbol-question-vertical-bar-for-evaluated-at/40166 might be possible?

For example, could the boundary values in http://juliaapproximation.github.io/ApproxFun.jl/latest/usage/equations.html#Systems-of-equations-1 look something like 𝒟 │-1 which sames apply the operator and evaluate at the -1 point. WIth that, we would just need to have a symbol for the identity operator of a function, which might even be I. so

julia> x = Fun();

julia> A = [I │ -1      0;
            𝒟 │ -1    0;
            0      I │ -1;
            𝒟^2-I  2I;
            I      𝒟+I];

julia> u,v = A\[0;0;0;exp(x);cos(x)];
dlfivefifty commented 6 years ago

I’ve been using just | for similar usage of a restriction of a space to a subspace. Though overriding I | -1 would be type piracy...

jlperla commented 6 years ago

That last one looks sufficiently different that people could avoid confusion with the standard | on the keyboard?

dlfivefifty commented 6 years ago

I don't think I | 1.0 expresses the right idea, as in maths Operator | space restricts the domain of an operator, not the range.

I think the right notation is I : Chebyshev() → 1.0 to mean Evaluation(Chebyshev(), 1.0) and I → 1.0 to mean Evaluation(1.0).

This would implicitly mean combining Conversion, Evaluation, Dirichlet, and Restriction operators (the last one might not exist): these are essentially the same thing just with different spaces.

Note that a "domain" will eventually mean anything that supports in, including numbers, so 1.0 will be equivalent to the domain Point(1.0).

jlperla commented 6 years ago

OK. So then

julia> x = Fun();

julia> A = [I → -1      0;
            𝒟 → -1    0;
            0      I → -1;
            𝒟^2-I  2I;
            I      𝒟+I];

julia> u,v = A\[0;0;0;exp(x);cos(x)];

That looks pretty good to me! @ChrisRackauckas any thoughts on this? I am thinking that the same approach could be used for the DSL for finite-difference boundary conditions.

The I : Chebyshev() → 1.0 logic I can't quite reason through, or mentally parse, but I can see where you are going. I suspect that this might be useful in finite difference methods where the Domain could be the grid (i.e. a regular grid suppoting the AbstractRange interface or a irregular grid supporting the AbstractArray interface).

dlfivefifty commented 6 years ago

I : Chebyshev() → Ultraspherical(1) is the same as Conversion(Chebyshev(), Ultraspherical(1)), that is, the change of basis operator.

I see no reason why I : Chebyshev() → 1.0 should not be the same as I : Chebyshev() → ConstantSpace(1.0) which would be "the change of basis operator" but now with a lower dimensional space.

This is analogous to eye(1,n) being the identity from R^n to R^1.

jlperla commented 6 years ago

You are overestimating my: (1) intelligence; (2) knowledge of julia generic programming; and (3) knowledge of linear algebra/functional analysis.

...but... I think I love it. The more that Julia looks like a DSL for math, the happier I am. If julia ever code looks like python or matlab, it means you are doing something horribly wrong.