# Math Help - Help with mathematical expressions and functions.

1. ## Help with mathematical expressions and functions.

Hi

Although I can babble a bit, I'll try and make this as short as I know how.

I do have a interest in maths and a highschool maths background, but regret that I haven't applied myself in this area and so... here I am although I am trying to learn from khanacademy and other sources.

I've taken on a little programming project for myself in the Python programming language. Chances are some of you have encountered a programming language called Mathematica. If not that's ok as this is a maths questions. Basically Mathematica has a function(a programming tool) called FindSequenceFunction() which attempts to find the mathematical function/expression for a given sequence of numbers, and I'm trying to do the same thing in Python.

I've made a prototype and it works... not entirely though, it is just a prototype. I'm now trying re-factoring it for a final elegant and fully working program. The thing is I'm not really sure what fully working means because for that I need to know maths.

So far I've managed to learn that there are certain expressions which have to conform to certain rules. For example, you can't have a number to the power of x in one of the types of expressions I'm talking about. Or you can't divide by x. Etc. From some tests I can see why too, as these can cause errors. But I've been sifting through wikipedia and I'm just not getting it. Can somebody that actually knows maths help please? You don't have to know programming, I just need to develop a good layout of:

• Types of expressions that are valid (and their form).
• Types of expressions that are feasible (and their form).
• Should constants only be integers?
• Is there a range I can use for any constant(a limit).
• Is there a max length/depth I can use for a valid/feasible expression.

To try and clarify further, as I have it now, part of the program returns random expression form in prefix notation (as it's easier to code)
eg.
rand_expr(max_depth=0)
...returns something like...
(+ c x)

where c is a placeholder for a constant. Remember this is just the form, the constants are changed in different parts of the program but that's not important.

rand_expr(max_depth=1)
...returns something like...
(+ c (^ c x))

Which I know should be illegal because x is not supposed to be to the power of anything... I think.

Let me stop, can you help with the design?

--edit--

I think this might help explain my location in the land of the lost.

In BNF form:

Code:
<expression form>   ->  (<operator> <operand> <operand>)
<operand>           ->  <expression form> | c | x
<operator>          ->  + | - | * | / | ^
That is the just of how random expressions are created. But it can return null expressions like (x - x) or expressions which don't have x, or evil expression that try to divide by zero or ones which simply bring that machine to knees. So I need to codify some valid base expressions.

These are all of the possible base expression forms using the basic arithmetic operators and x and c operands. Can you help me scratch some of them off completely. I'll use infix notation.

x + c
x - c
x * c
x / c
x ^ c

c + x because it's the same as x + c
c - x
c * x because it's the same as x * c
c / x Because it's bad... I think
c ^ x That too maybe

That might be half the work done, assuming it's correct.

Can you think of anything else?

current range for any constant is between 0 and 100.

I thought maybe 1 and 100 would be better, but since it's using only positive integers, and might need to make use of negative integers then a way for it to get a negative integer would be to use the expression (c - x) where c is 0 or (c - c) where the first c is 0 and the second some positive integer meant to be negative.. As for a 100 I have no idea.