Name for programming functions , i think

In summary, the conversation is about finding a name for the class of techniques used to manipulate functions, particularly for cycling between odd and even numbers or outputting only odd numbers. The solution proposed involves using a variable and modulo operations. The conversation also mentions a simplified solution using a mathematical function and a possible name for it as a "cyclic function".
  • #1
trancefishy
75
0
name for "programming functions", i think...

I'm looking for the name of the class of techniques you use to get functions to do what you want. for example, if you wanted to cycle between odd and even, you would use [tex] -1^n [/tex]. In particular, I want to cycle between 1 and 2, and also be able to output just odd numbers. A couple other things as well, but, this is for a problem I'm working on, and I'd like to just solve it myself. I'm just trying to find a resource that has perhaps a list of little tricks for functions. thanks.
 
Mathematics news on Phys.org
  • #2
if it is a computer program, why not just have a variable, start at 0, increment by one and every n mod2 ==0 make your cycling variable 2, and when n mod2 == 1, set the variable to 1.

it is not as elegant as a simple mathematical function, but it is a nice solution.

to output just odd numbers, set it up simmilarly, but only output the incremented variable when n mod2 ==1.
 
  • #3
If my problem were to be solved using a computer, it wouldn't even be a problem, simply an exercise. nope, this needs to be the good ol' f(n) form.

oh, and I've managed to simplify it, i no longer need to cycle 1 and 2 or get only odds, but, I've still got more complicated stuff than that, so, the question still stands.
 
  • #4
oh, well I was confused then because you said "programming" in there.
 
  • #5
[tex]f(n) = \frac{(-1)^n + 3}{2} [/tex]

Cycles between 1 and 2.

Cyclic function is the only name that I can think of for this kind of function.


[tex]f(n) = 2n -1[/tex]

maps the natutral numbers onto the odd numbers.
 
Last edited:

FAQ: Name for programming functions , i think

What is the purpose of a programming function?

A programming function is a block of code that performs a specific task. Its purpose is to help organize and modularize code, making it easier to read, reuse, and maintain.

How do you name a programming function?

When naming a programming function, it is important to choose a descriptive and concise name that accurately reflects its purpose. This can include using verbs to indicate what the function does, as well as any relevant parameters or return values.

What are the best practices for writing a programming function?

Some best practices for writing a programming function include keeping it short and simple, using meaningful variable names, commenting your code, and avoiding side effects (unexpected changes to variables outside of the function).

Can a programming function be called multiple times?

Yes, a programming function can be called multiple times within a program. This allows for code reuse and reduces the need for writing repetitive code.

How do you test a programming function?

To test a programming function, you can write unit tests that check the function's output for different inputs. This can help ensure that the function is working as intended and can catch any errors or bugs before they affect the rest of the code.

Similar threads

Replies
1
Views
943
Replies
7
Views
1K
Replies
16
Views
2K
Replies
13
Views
2K
Replies
7
Views
1K
Replies
2
Views
1K
Back
Top