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

Store variable images globally #31

Closed
MasonProtter opened this issue Aug 15, 2018 · 3 comments · Fixed by #45
Closed

Store variable images globally #31

MasonProtter opened this issue Aug 15, 2018 · 3 comments · Fixed by #45
Labels
improvement Improvement to existing feature

Comments

@MasonProtter
Copy link
Contributor

MasonProtter commented Aug 15, 2018

In the examples we have:

julia> x, y = Variable.([:x, :y], Ref(TypeSet(Int)));

julia> normalize(@term(diff(sin(2*$x) - log($x+$y), $x)))
@term(2 * cos(2x) - 1 / (x + y))

It'd be nice if one could instead just declare that x and y are integers and then not have to worry about interpolating later.

@HarrisonGrodin HarrisonGrodin changed the title There should be a way to attach properties to variables such that they don't need to be interpolated. Store variable images on full term Aug 15, 2018
@HarrisonGrodin
Copy link
Owner

Agreed. This is a window into the major design flaw that currently exists with image storage, where variable images are stored only on each specific instance in the term tree. This leads to a number of confusing behaviors, especially in the context of displaying:

julia> x1 = Variable(:x, TypeSet(Int));
       x2 = Variable(:x, TypeSet(String));

julia> @term $x2 ^ (x + $x1)
@term(x ^ (x + x))

julia> x1
@term(x)

julia> x2
@term(x)

julia> x1 == x2
false

Since each term should have exactly one interpretation of what image set a variable is in, this is something we should definitely have. In an upcoming iteration of Term storage, I'm hoping to have each object store a dictionary mapping variables (terms in general? see #35) to image sets.

As far as visual representation goes, it might be nice to use a where clause to indicate image sets (with easy copy-paste in mind) - for example, @term(((a ^ 2) + b) where {a > 3, b ∈ Odd}). It would be even better to include variable image in a local context and only show the where clause when it's not already implied (similarly to how Julia will show A.B as a type name until B is accessible in the local scope) - however, that might be getting beyond the scope of this issue.

@MasonProtter
Copy link
Contributor Author

I don't have a good handle on how your term objects work, but perhaps one solution would be to have a central dict that stores mappings from variables to images and then whenever a new term is made, we can check the dict to see if there is already an image for each variable? Or is this what you were saying in your comment?

@HarrisonGrodin
Copy link
Owner

Yep, that's the goal! (But maybe the Dict would be local to a specific Term object, rather than being app-global.) When a new image set is gained about a specific variable, it would register it in the Dict by intersecting it with the existing image set (defaulting to TypeSet(Any)). In pseudocode:

GLOBAL x = Variable(:x, Nonnegative)

ex = @term(x + y)
  -> Dict(x => Nonnegative, y => TypeSet(Any))

ex = @term(1 / x)
  -> Dict(x => Positive)  # since denominators are nonzero

@HarrisonGrodin HarrisonGrodin added the improvement Improvement to existing feature label Aug 15, 2018
@HarrisonGrodin HarrisonGrodin changed the title Store variable images on full term Store variable images globally Aug 27, 2018
@HarrisonGrodin HarrisonGrodin mentioned this issue Aug 27, 2018
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement to existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants