[Jprogramming] Implicit functions

'Pascal Jasmin' via Programming programming at jsoftware.com
Thu Nov 5 16:46:53 UTC 2020


My approach that suits J ways of solving a much wider class than just this type of problem.  Relies on 2 pretty simple independent concepts.

1. I define a  "perfect function" as simply a function that returns all of its arguments.  This is suitable to processing by many J techniques such as ^: to repeat sequences/application of the function, or provide delayed/sharable computations by gerundifying arguments with function, and using `:6

2. A "default argument resolution" framework, where function arguments are coded for missing argument value ('' is simplest universal code when arguments are passed in boxed format), and then missing values are computed.  The simplest form of such frameworks present in most scripting/modern languages is value substitution for missing arguments.  But a "computed record field" is a common concept from database systems.


So, in the context of your problem description,

f a b  --> a b c (c is computed)
f a b c --> simple return of all 3 arguments
f a;;c --> computes b, and as before returns arguments/result a b c

What the perfect function framework provides is consistency of result format such that any further processing of any of the parameters or "computed result" is fully available from an independently defined function.  One big power of J is ease of composition for independent concepts.

A composition approach can be done with an adverb, but as a design pattern for a pythagoran triples perfect function

 f =: 3 : 0

NULLCODE =. 0

'a b c' =. 3 {.!.NULLCODE y

if. NULLCODE -: c do. a, b, a %:@+&*: b end.

if. NULLCODE -: b do. a, (a %:@|@-&*: c), c end.

if. NULLCODE -: a do. (b %:@|@-&*: c), b, c end.

)



   f 3 4 
3 4 5

  f 3 0 5
3 4 5

f 0 0 5  NB. potential nonsense but no crash

5 0 5


On Wednesday, November 4, 2020, 10:58:24 p.m. EST, Piet de Jong <pietdion at gmail.com> wrote: 





I was hoping for more of  a “J” type solution.

For example if f(x,y) = (x^2 + log y)^{-1} = c
Then given c and say x, I can solve for y. (ie write J function)
Or given c and y I can solve for x. (ie write a J function)
(I’m assuming domains etc are ok. — this is just an example.)

So instead of following this long process of finding the two functions I was hoping in J there would be a “clean and tidy” way of doing things.

Probably impossible even for simple functions f.

> On 5 Nov 2020, at 2:24 pm, Raul Miller <rauldmiller at gmail.com> wrote:
> 
> The answer is: sometimes yes, sometimes no.
> 
> See https://en.wikipedia.org/wiki/Equation_solving for some of the issues.
> 
> If f can be expressed as a polynomial, you might want to consider
> using https://www.jsoftware.com/help/dictionary/dpdot.htm
> 
> Thanks,
> 
> -- 
> Raul
> 
> On Wed, Nov 4, 2020 at 7:27 PM Piet de Jong <pietdion at gmail.com> wrote:
>> 
>> Still trying to learn/improve my J after 25 years.
>> 
>> Here is the issue.  I’m probably having a pipe dream.
>> 
>> Suppose you have an implicit function f(x,y)=0  which is relatively “clean” (ie simple to specify)
>> 
>> Is there a “clean/efficient” way in J to solve for y given x or vice versa.
>> 
>> I know I can write a function g  such that g x  gives y and g^:_1 y gives x.
>> But is there a cleaner way?  The g and its inverse may be complicated even if f is relatively simple.
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm

> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


More information about the Programming mailing list