Talk:Function composition: Difference between revisions

(→‎Limitation of First-class functions: first section needed title.)
 
(11 intermediate revisions by 3 users not shown)
Line 32:
|-
! Composition: <tt>∘</tt>
! Unary interpretation: <tt>'''f'''∘'''g''' &nbsp;y</tt>
! Binary interpretation: <tt>x &nbsp;'''f'''∘'''g''' &nbsp;y</tt>
! Notes
|-
Line 77:
|-
|<tt>..</tt>
|<tt>(('''f''' &nbsp;y) &nbsp;+ ('''g''' ''x'')&nbsp;'''f'''('''g''' &nbsp;''y''))/2</tt>
|<tt>((x&nbsp;'''f'''&nbsp;y)&nbsp;+&nbsp;('''g'''&nbsp;''x'')'''f'''('''g'''&nbsp;''y''))/2</tt>
|<tt>N/A</tt>
|Given <tt>'''h'''←'''f'''..'''g'''</tt>, the resulting function, <tt>'''h'''</tt>, is ''even'' in the sense that <tt>('''h''' ''y'') = ('''h''' -''y'')</tt> for any <tt>''y''</tt> ; its graph is reflected in the vertical axis.
|-
|<tt>.:</tt>
|<tt>(('''f''' y) - ('''g''' ''x'')'''f'''('''g''' ''y''))/2</tt>
|<tt>((x&nbsp;'''f'''&nbsp;y)&nbsp;-&nbsp;('''g'''&nbsp;''x'')'''f'''('''g'''&nbsp;''y''))/2</tt>
|<tt>N/A</tt>
|Given <tt>'''h'''←'''f'''.:'''g'''</tt>, the resulting function, <tt>'''h'''</tt>, is ''odd'' in the sense that <tt>('''h''' ''y'') = (-'''h''' -''y'')</tt> for any <tt>''y''</tt> ; its graph is reflected in the origin.
|-
Line 102:
|-
|<tt>''hook''</tt>
|<tt>('''f''' '''g''')''y''</tt> <big>→</big> <tt>''y'' '''f''' '''g''' ''y''</tt>
|
|<tt>''x''('''f''' '''g''')''y''</tt> <big>→</big> <tt>''x'' '''f''' '''g''' ''y''</tt>
|
| To be discussed
|-
|<tt>''fork''</tt>
| composition of <tt>('''h''' '''f''' '''g''')</tt>
|
|
| To be discussed
Line 115:
===Still to discuss===
::<tt>@.</tt> = functional selection (<tt>'''f'''`'''g'''@.'''h'''</tt>)
::<tt>&.</tt> = ''under'', thisf&.g is a(g_obverse@f)&g ''good''where g_obverse is the inverse of g if one has been defined.
::<tt>&.:</tt> = <tt>&.:</tt> is to <tt>&.</tt> as <tt>&:</tt> is to <tt>&.</tt>
::<tt>.</tt> = <tt>'''f'''.'''g'''</tt> is defined in terms of a recursive expansion by minors along the first column when unary, and as a generalized inner product when binary.
::<tt>:.</tt> = related to <tt>&.</tt>, another-- goodg one:. G defines a new verb that behaves like g except that its obverse (defined inverse) is G.
::hook = an implicit composition of 2 functions -- in contexts which take only one argument it's structurally similar to the S combinator in much the way [ is similar to the K combinator and ([ [) y is y. ((u v) y) in J is equivalent to (y u v y) in J if u and v are verbs and y is a noun. Here, u is a combining verb (which takes a left and right argument and v gets only a single argument. For example (* -) 3 is 3 * - 3 or negative nine. Meanwhile x (u v) y is simply x u v y. For example 4 (* -) 3 is negative 12.
::hook = an implicit composition of 2 functions
::fork = an implicit composition of 3 functions. (u v w) y is (u y) v (w y) for example (! * -) 4 is (!4) * (-4) or 24 * _4 or _96. Similarly x (u v w) y is (x u y) v (x w y) so for example 5 (* - +) 4 is (5*4) - (5+4) which is 20-9 which is 11. Trains of verbs longer than 3 are organized by grouping the rightmost three verbs as a fork which in turn is a single verb.
::fork = an implicit composition of 3 functions
 
==VBScript problem==
Line 148:
-0.43030121700009226697L0
CL-USER> </pre> --[[User:Lhignight|Larry Hignight]] 06:18, 14 June 2012 (UTC)
 
: Hi Larry, some might say that the comparison of LOC (Lines Of Code) to do this task is a good way of comparing the languages, and a new task to accept a list/array of functions, compose them in some order, then show the results of applying the composition to a number might be a good task to create. --[[User:Paddy3118|Paddy3118]] 07:04, 14 June 2012 (UTC)
 
: It's probably sufficient here to show that the composition of two functions is a function which can be composed like any other function? --[[User:Rdm|Rdm]] 13:11, 14 June 2012 (UTC)
 
:: Brilliant. No need for another task. --[[User:Paddy3118|Paddy3118]] 19:18, 14 June 2012 (UTC)
 
:: Agreed. Although it is less elegant than composing multiple functions with a single call, it does demonstrate that a language supports function composition without having to resort to additional functional programming language features. I would still prefer to see the task defined more precisely because I'm afraid we'll end up with several (sin (asin (sin x))) implementations. I haven't come up with a good example (yet), but I think that changing the task description to include the following output should separate most of the wheat from the chaff.
<pre>;;Example Usage:
;CL-USER> (compose f #'ceiling #'sin #'sqrt)
;F
CL-USER> (compose g #'1+ #'abs #'cos)
G
CL-USER> (compose h #'f #'g)
H
CL-USER> (values (f pi) (g pi) (h pi))
1
2.0L0
1
CL-USER> </pre> --[[User:Lhignight|Larry Hignight]] 23:00, 20 June 2012 (UTC)
::: Not sure I agree with you about elegance -- the syntax you have in your illustration here favors composing lists of functions but that's an implementation detail, it's not universal. For example, in J, composing f g and h looks like f@g@h and composing them as a list looks like <nowiki>(4 :'(x`:6)@(y`:6)`'''''/f`g`h)`:6</nowiki> -- I could define a '''compose''' word that encapsulates that complexity, but it would never beat f@g@h for directness. That said, I added an implementation of your examples to the J implementation on the main page. ----[[User:Rdm|Rdm]] 23:21, 20 June 2012 (UTC)
:::: I didn't mean to suggest that the task or implementation should favor composing lists of functions. I find implementations that allow you to compose multiple functions in a straight-forward manner [eg (compose f #'1+ #'abs #'cos), Mathematica's Compose[f1,f2,f3...] and the J example that you provided] to be more elegant than nesting multiple calls to a composition function [eg (setf f (compose #'1+ (compose #'abs #'cos)))]. --[[User:Lhignight|Larry Hignight]] 09:56, 21 June 2012 (UTC)
: Rdm -- The example looks good. Given your experience with J, are there more advanced examples of function composition that you think should be included in the task description? I think it would be desirable to have easy, moderate and hard example problems. --[[User:Lhignight|Larry Hignight]] 09:56, 21 June 2012 (UTC)
:: There's now a section on this talk page which partially explores this topic. It's a bit sloppy, because the mechanisms are only similar to each other with details which vary between different mechanisms. --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 15:23, 4 July 2022 (UTC)
6,951

edits