E.g. let $f(x) = $ some function. Now define $h(x) = f(g(x))$. Now suppose the definition of $g(x)$ changes around in a discussion. Do we still refer to $h(x)$ as the original $h(x)$ or only when we do something like $h(g)(x) = f(g(x))$ ?
Reason: I'm writing a math lib that uses lazy expression eval. Now if I say (in D code):
Var x, y; Function f = new Function; Function g = new Function; f = x^2 + y^2; // f is defined as f(x,y) = x^2 + y^2 g = x^3 + y^3; // g similarly Function h = f(x,y) + g(x,y); // I've decided to let f(x,y) return the expression x^2 + y^2 // Now if I did f = x^4 + y^5; //h would not be affected since h's expr points to the old f expr still // to make a copy of the expression, in case f, g change later, you'd do: h = h.dup; // or earlier do: h = (f(x,y) + g(x,y)).dup; // dup means duplicate or make an exact memory copy of an object // Now if the internal expression of f is changed, h will not change, again //But if I said: h = f + g; // That could mean that h(x,y) = (f + g)(x,y) -AND- that h changes when f and g are re-assigned
I might have answered my own question in there. The expressions will be coded as trees with operators at the nodes and edges going down to operands or more operators, and so on. Are my concerns making sense to anyone? I'm going to go ahead and post this, in case my little brainstorm helps others.
Came up with some answers. Let's work in d code, and assume that our types are all classes, so this means A a; will mean a is a reference type (like an address where the data of A is stored). When we decide how to design something, sometimes we see that certain things would happen if we chose one way and we then apply the "K.I.S.S." principle. So let's look at the use of the library:
If Function has a setDomain() or setCodomain() method, then functions built from other functions:
h = f + g; (where references to f obj and g obj are stored in h's expression tree)
may become invalid. On the other hand, we would like the ability of a functions domain to change, so instead resolving all such h functions that are dependent, let's return a new function with the new domain.
So, for Function objects declared as from Z and on R, we'll allow their definition to change in all places except their domain and codomain. While still retaining this use case:
"hmm.. let's define $e(x)$ = (some infinite sum)" "I wonder what this function does to matrices if it were defined on them, let's see..." "Create matrix M over the reals and" auto e2 = new Function(e(M));
$e(x)$ which was declared in code as from R to R will substitute a matrix in and make sure every operation we have in R can be done on M's space, and return a new Function with new domain if it does.
The setDomain(), setCodomain() functions will be replaced with factories that return the new function between new sets.
I think I got now. If we say h = f + g, do we mean that h is a function of two functions, or that h is a function on the same domain(s) as f and g? So what would calling h(a,b) produce? The first way would produce h(a,b) = a + b, and the second h(a,b) = (f + g)(a,b). But the second way is already handled by this syntax: h = f(x,y) + g(x,y). So h = f + g should mean function space addition and you'd have to call h(f,g)(a,b) to get (f+g)(a,b). I might run into some other issues by not specifying the input variables of h, as in h(x,y) = f(x,y) + g(x,y); But I can't do that directly in D code the way I have it now and with my limited understanding of the language - i.e. h(x,y) returns h's expression, and h is what I need to assign to. But if I overload Expression's assign operator, I could do it that way. One question is then is that how I want the whole library to work?
All right. EDIT 2, didn't work either. h = f + g implying h is the function space addition operator, doesn't mesh with math unless I have multiple D classes that interpret that statement in different ways. I think h = f + g most comonly means h is an element of the same function space as f and g, and h(f,g) = f + g means h is a binary function on the space of f and g. And the notation f = x^2 + y^3 could be interpreted that f is in the same space as x and y. So I'm going to need something that specifies that f is a function of x and y. Last edit.