Optimizing/reducing pure functions with same in/out types to combine them in a simpler pure function?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















Disclaimer: I have almost no mathematics notions, so this question could be very basic for some of you.



I'm searching for the name of a concept which consists in combining pure functions together (say, functions with the same input and output types and number of parameters) to make them simpler.



Suppose I have these 3 methods with the same signature:



addOne(param: number): number {
return param + 1;
}

addTwo(param: number): number {
return param + 2;
}

multiplyByThree(param: number): number {
return param * 3;
}


Now I know that I'll always use these functions in the same order and same param.



Ex: I will process a sound or an image.



I want to avoid uselessly applying coefficient or offsets that could be computed together (optimization/regression).



Let's say I have this imaginary library with a method called computeOptimizedFunction that applies this concept to my functions. It takes any number of functions with the same signature as input.



var optimized = computeOptimizedFunction(addOne, addTwo, multiplyByThree);


Actually equals to:



var optimized = (param: number) => 3 * (param + 3);


Anyone here has an idea of how this concept or pattern is called, if it exists?










share|improve this question




















  • 1





    This is not a simple topic, if it were that simple all compilers would be doing it. Restricted to math expressions, you could try something like this: stackoverflow.com/questions/7540227/…

    – juvian
    Jan 3 at 16:58











  • Indeed, at the end, I realize that there is a requirement to combine all expressions and to follow operator/operation priorities. And if there are conditions inside functions, I lose optimization opportunities. At the strict minimum, I want to reduce at least the number of function entry points. I'll read that linked question throughfully, thanks! I feel like I'll need a code analyzer to separate code in blocks before combining and optimizing functions. Funny side-project, isn't it!

    – Léon Pelletier
    Jan 3 at 17:16








  • 1





    Many compilers inline functions to avoid the calls, feel free to play around with it but these things are usually left for the compiler

    – juvian
    Jan 3 at 17:39


















1















Disclaimer: I have almost no mathematics notions, so this question could be very basic for some of you.



I'm searching for the name of a concept which consists in combining pure functions together (say, functions with the same input and output types and number of parameters) to make them simpler.



Suppose I have these 3 methods with the same signature:



addOne(param: number): number {
return param + 1;
}

addTwo(param: number): number {
return param + 2;
}

multiplyByThree(param: number): number {
return param * 3;
}


Now I know that I'll always use these functions in the same order and same param.



Ex: I will process a sound or an image.



I want to avoid uselessly applying coefficient or offsets that could be computed together (optimization/regression).



Let's say I have this imaginary library with a method called computeOptimizedFunction that applies this concept to my functions. It takes any number of functions with the same signature as input.



var optimized = computeOptimizedFunction(addOne, addTwo, multiplyByThree);


Actually equals to:



var optimized = (param: number) => 3 * (param + 3);


Anyone here has an idea of how this concept or pattern is called, if it exists?










share|improve this question




















  • 1





    This is not a simple topic, if it were that simple all compilers would be doing it. Restricted to math expressions, you could try something like this: stackoverflow.com/questions/7540227/…

    – juvian
    Jan 3 at 16:58











  • Indeed, at the end, I realize that there is a requirement to combine all expressions and to follow operator/operation priorities. And if there are conditions inside functions, I lose optimization opportunities. At the strict minimum, I want to reduce at least the number of function entry points. I'll read that linked question throughfully, thanks! I feel like I'll need a code analyzer to separate code in blocks before combining and optimizing functions. Funny side-project, isn't it!

    – Léon Pelletier
    Jan 3 at 17:16








  • 1





    Many compilers inline functions to avoid the calls, feel free to play around with it but these things are usually left for the compiler

    – juvian
    Jan 3 at 17:39














1












1








1








Disclaimer: I have almost no mathematics notions, so this question could be very basic for some of you.



I'm searching for the name of a concept which consists in combining pure functions together (say, functions with the same input and output types and number of parameters) to make them simpler.



Suppose I have these 3 methods with the same signature:



addOne(param: number): number {
return param + 1;
}

addTwo(param: number): number {
return param + 2;
}

multiplyByThree(param: number): number {
return param * 3;
}


Now I know that I'll always use these functions in the same order and same param.



Ex: I will process a sound or an image.



I want to avoid uselessly applying coefficient or offsets that could be computed together (optimization/regression).



Let's say I have this imaginary library with a method called computeOptimizedFunction that applies this concept to my functions. It takes any number of functions with the same signature as input.



var optimized = computeOptimizedFunction(addOne, addTwo, multiplyByThree);


Actually equals to:



var optimized = (param: number) => 3 * (param + 3);


Anyone here has an idea of how this concept or pattern is called, if it exists?










share|improve this question
















Disclaimer: I have almost no mathematics notions, so this question could be very basic for some of you.



I'm searching for the name of a concept which consists in combining pure functions together (say, functions with the same input and output types and number of parameters) to make them simpler.



Suppose I have these 3 methods with the same signature:



addOne(param: number): number {
return param + 1;
}

addTwo(param: number): number {
return param + 2;
}

multiplyByThree(param: number): number {
return param * 3;
}


Now I know that I'll always use these functions in the same order and same param.



Ex: I will process a sound or an image.



I want to avoid uselessly applying coefficient or offsets that could be computed together (optimization/regression).



Let's say I have this imaginary library with a method called computeOptimizedFunction that applies this concept to my functions. It takes any number of functions with the same signature as input.



var optimized = computeOptimizedFunction(addOne, addTwo, multiplyByThree);


Actually equals to:



var optimized = (param: number) => 3 * (param + 3);


Anyone here has an idea of how this concept or pattern is called, if it exists?







function optimization design-patterns






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 16:29







Léon Pelletier

















asked Jan 3 at 16:21









Léon PelletierLéon Pelletier

1,55522756




1,55522756








  • 1





    This is not a simple topic, if it were that simple all compilers would be doing it. Restricted to math expressions, you could try something like this: stackoverflow.com/questions/7540227/…

    – juvian
    Jan 3 at 16:58











  • Indeed, at the end, I realize that there is a requirement to combine all expressions and to follow operator/operation priorities. And if there are conditions inside functions, I lose optimization opportunities. At the strict minimum, I want to reduce at least the number of function entry points. I'll read that linked question throughfully, thanks! I feel like I'll need a code analyzer to separate code in blocks before combining and optimizing functions. Funny side-project, isn't it!

    – Léon Pelletier
    Jan 3 at 17:16








  • 1





    Many compilers inline functions to avoid the calls, feel free to play around with it but these things are usually left for the compiler

    – juvian
    Jan 3 at 17:39














  • 1





    This is not a simple topic, if it were that simple all compilers would be doing it. Restricted to math expressions, you could try something like this: stackoverflow.com/questions/7540227/…

    – juvian
    Jan 3 at 16:58











  • Indeed, at the end, I realize that there is a requirement to combine all expressions and to follow operator/operation priorities. And if there are conditions inside functions, I lose optimization opportunities. At the strict minimum, I want to reduce at least the number of function entry points. I'll read that linked question throughfully, thanks! I feel like I'll need a code analyzer to separate code in blocks before combining and optimizing functions. Funny side-project, isn't it!

    – Léon Pelletier
    Jan 3 at 17:16








  • 1





    Many compilers inline functions to avoid the calls, feel free to play around with it but these things are usually left for the compiler

    – juvian
    Jan 3 at 17:39








1




1





This is not a simple topic, if it were that simple all compilers would be doing it. Restricted to math expressions, you could try something like this: stackoverflow.com/questions/7540227/…

– juvian
Jan 3 at 16:58





This is not a simple topic, if it were that simple all compilers would be doing it. Restricted to math expressions, you could try something like this: stackoverflow.com/questions/7540227/…

– juvian
Jan 3 at 16:58













Indeed, at the end, I realize that there is a requirement to combine all expressions and to follow operator/operation priorities. And if there are conditions inside functions, I lose optimization opportunities. At the strict minimum, I want to reduce at least the number of function entry points. I'll read that linked question throughfully, thanks! I feel like I'll need a code analyzer to separate code in blocks before combining and optimizing functions. Funny side-project, isn't it!

– Léon Pelletier
Jan 3 at 17:16







Indeed, at the end, I realize that there is a requirement to combine all expressions and to follow operator/operation priorities. And if there are conditions inside functions, I lose optimization opportunities. At the strict minimum, I want to reduce at least the number of function entry points. I'll read that linked question throughfully, thanks! I feel like I'll need a code analyzer to separate code in blocks before combining and optimizing functions. Funny side-project, isn't it!

– Léon Pelletier
Jan 3 at 17:16






1




1





Many compilers inline functions to avoid the calls, feel free to play around with it but these things are usually left for the compiler

– juvian
Jan 3 at 17:39





Many compilers inline functions to avoid the calls, feel free to play around with it but these things are usually left for the compiler

– juvian
Jan 3 at 17:39












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026110%2foptimizing-reducing-pure-functions-with-same-in-out-types-to-combine-them-in-a-s%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026110%2foptimizing-reducing-pure-functions-with-same-in-out-types-to-combine-them-in-a-s%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

'app-layout' is not a known element: how to share Component with different Modules

SQL update select statement