Skip to content

Reification of a mathematical function as an object. Allows function arithmetics and function composition.

License

Notifications You must be signed in to change notification settings

olekscode/Function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Function

Build Status Build status Coverage Status License Pharo version Pharo version

Reification of a mathematical function as an object. Allows function arithmetics and function composition.

Installation

To install Functon, go to the Playground (Ctrl+OW) in your Pharo image and execute the following Metacello script (select it and press Do-it button or Ctrl+D):

Metacello new
  baseline: 'Function';
  repository: 'github://olekscode/Function/src';
  load.

How to use?

Functions can be defined using block closures:

f := [ :x | x sin ] asFunction.
g := [ :x | x cos ] asFunction.
h := [ :x | x + 1 ] asFunction.

alpha := Float pi / 2.

Adding Two Functions

In the following example, f + g is a new function (f+g)(x) = sin(x) + cos(x):

(f + g) value: alpha. "1.0"

Composition of Functions

Composition of two functions f(x) and h(x) is a new function (f@h)(x) = f(h(x)). In our example, (f@h)(x) = sin(x+1) and (h@f)(x) = sin(x) + 1:

(f @ h) value: alpha. "0.54"
(h @ f) value: alpha. "2.0"

About

Reification of a mathematical function as an object. Allows function arithmetics and function composition.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published