Talk:Function composition: Difference between revisions

No edit summary
 
(6 intermediate revisions by 2 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 155:
:: 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. --[[User:Lhignight|Larry Hignight]] 23:00, 20 June 2012 (UTC)
<pre>;;Example Usage:
;CL-USER> (compose f #'ceiling #'sin #'sqrt)
Line 167:
2.0L0
1
CL-USER> </pre> --[[User:Lhignight|Larry Hignight]] 23:00, 20 June 2012 (UTC)
CL-USER> </pre>
::: 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