3 ms·
> It is completely impossible to implement something like "under" in matlab. I’m a little curious about this. Does J have a notion of the relationship between
by henrikeh 6y ago
> It is completely impossible to implement something like "under" in matlab.
I’m a little curious about this. Does J have a notion of the relationship between certain functions and their inverse? What is it that enables “under” in J which makes it impossible in Matlab?
- klibertp 6y ago> Does J have a notion of the relationship between certain functions and their inverse? Yes. Many built-in words have inverses assigned, and you can assign inverse functions to your own words with :. https://code.jsoftware.com/wiki/Vocabulary/codot https://code.jsoftware.com/wiki/Vocabulary/codot EDIT: and here's a table with predefined inverses: https://code.jsoftware.com/wiki/Vocabulary/Inverses https://code.jsoftware.com/wiki/Vocabulary/Inverses
- henrikeh 6y agoThat can definitely be implemented in Matlab with the symbolic math toolbox. But interesting nonetheless.
- patrec 6y agoI have used matlab quite a bit in the past, but not the symbolic math toolbox: can you make a "normal" function definition symbolic retroactively? I thought you need to define the function explicitly as symbolic to start with, or am I wrong?
- henrikeh 6y agoYes, the symbolic functions can be made "retroactively". The various conventional functions are overloaded with the symbolic input. >> syms x >> f = @(x) log(sqrt(x)).^2 f = function_handle with value: @(x)log(sqrt(x)).^2 >> f(x) ans = log(x^(1/2))^2 >> finverse(f(x)) ans = exp(2*x^(1/2)) And to implement under: function u = under(f, g) syms x g_inv = matlabFunction(finverse(g(x))); u = @(x) g_inv(f(g(x))); end
- patrec 6y agoSo if you have odddouble.m with function y=odddouble(a,b) y=2*x+1 endfunction you can do >>> h = under(@(x) 1/x, odddouble) >>> h(3) ? If so, yeah, I agree you can implement under in matlab (as long as you have the symbolic toolbox as well); in which case it's probably one of very few non-CAS systems where you can define it.
- henrikeh 6y agoJust tested it and it worked fine. Note that your function takes too many parameters in its definition and that functions can't be passed as parameters by name. It is definitely not as elegant as the built-in facility in J, but definitely doable and usable in Matlab. In fact, I think any language with flexible enough function overloading should be able to implement such a feature.
- patrec 6y agoHere is toy example: I define a function f(x):=1+x2. J will automatically work out the inverse for me, as you can see below: f=:(1+*&2) f 1 2 3 4 3 5 7 9 (f^:_1)f 1 2 3 4 1 2 3 4 (f^:_1) 1 2 3 4 0 0.5 1 1.5 Now obviously not every function is bijective or even if bijective, trivial to invert -- and J doesn't (or at least didn't) have a super well specified way of computing those generalized inverses. But still: "under" is actually pretty cool, even just conceptually I find it quite valuable.