FnOio / fno-specification

Repository for https://w3id.org/function/spec
6 stars 1 forks source link

Function composition definition #11

Open robbe0x00 opened 1 year ago

robbe0x00 commented 1 year ago

A function composition isn't directly linked to a function. There also isn't specified what should happen if more than one functions output is affected. Example (prefixes omitted for brevity):

fns:function1 a fno:Function;
    fno:expects (ex:int1);
    fno:returns (ex:intOut).

fns:function2 a fno:Function;
    fno:expects (ex:int1);
    fno:returns (ex:intOut).

fns:composition a fnoc:Composition;
    fnoc:composedOf [
        fnoc:mapFrom [
            fnoc:constituentFunction fns:function1 ;
            fnoc:functionParameter ex:int1
        ];
        fnoc:mapTo [
            fnoc:constituentFunction fns:function1 ;
            fnoc:functionOutput ex:intOut
        ]
    ],
    [
        fnoc:mapFrom [
            fnoc:constituentFunction fns:function1 ;
            fnoc:functionParameter ex:int1
        ];
        fnoc:mapTo [
            fnoc:constituentFunction fns:function2 ;
            fnoc:functionOutput ex:intOut
        ]
    ]

Here there are 2 functions and 1 composition. The spec doesn't specify what should happen in this case, as there are 2 possible output of one composition.

bjdmeest commented 1 year ago

@gertjandemulder what do you think about this? What should be good behavior? We could just state that this is invalid, i.e., checking that ex:intOut can only be referred from mapTo once. I can't really come up with a better alternative at this point @robbe0x00 if you would have a suggestion, feel free to state!)

robbe0x00 commented 1 year ago

If it would be considered invalid, that each parameter can only be referenced once in a mapTo predicate, it could also be enforced on all parameters and not just output parameters. This would also solve the problem that the current spec doesn't specify what happens if multiple values are mapped on 1 parameter. The validation should however happen not just on parameter predicate value, but in combination with the function id, because parameters can be reused between functions. For function outputs an additional rule can be made that in a mapTo predicate only outputs of one function can be referenced. In this case parameter predicates would be unique for the outputs.

gertjandemulder commented 1 year ago

A function composition isn't directly linked to a function.

Indeed, we might want to enforce that a fnoc:Composition must explicitly refer to the description of the composed function, and that each (output)parameter of the composed function must be mapped.

Regarding the restrictions on the CompositionMappings

Unless we want to be able to define an identity function, we could enforce that a parameter cannot be mapped to an output of the same function, this basically happens in the first compositionmapping of the example above:

fnoc:composedOf [
        fnoc:mapFrom [
            fnoc:constituentFunction fns:function1 ;
            fnoc:functionParameter ex:int1
        ];
        fnoc:mapTo [
            fnoc:constituentFunction fns:function1 ;
            fnoc:functionOutput ex:intOut
        ]
    ],

However, enforcing that an output parameter can only be mapped once, prevents the possibility of describing a composed function that takes a list of input parameters that are reused and combined from multiple other function outputs. It would render the following (pseudo)composition invalid

# pseudo function descriptions
f0(inA) -> outA
f1(inA) -> outA
f2([inX, inY]) -> outZ

# pseudo composition mappings
map f0.outA to f1.inA
map f0.outA to f2.inX
map f1.out1 to f2.inY
bjdmeest commented 1 year ago

@gertjandemulder

enforcing that an output parameter can only be mapped once, prevents the possibility of describing a composed function that takes a list of input parameters that are reused and combined from multiple other function outputs.

isn't that why @robbe0x00 said

The validation should however happen not just on parameter predicate value, but in combination with the function id, because parameters can be reused between functions.

gertjandemulder commented 1 year ago

@bjdmeest , ah yeah indeed! Looked over it 😅