# Is it possible to define a variable with a conditional statement and then simplify an expression with it?

I have two real-valued variables, `A`

and `E`

. I want to define a third variable `D`

such that:

```
if 0 <= E: D = A
elif E < 0: D = A + E
```

These variables are part of an extremely long expression (over 1200 characters) that I am trying to simplify. Working with a shorter related expression (around 100 characters), I found that a lot of the `D`

and `E`

instances either canceled out or reduced to `A`

s that could be combined with other `A`

s in the same parts of the expression, regardless of if `E`

is assumed to be positive or negative. Working through the long expression by hand in the same way would be the height of tedium, so I'm trying to see if Sage can help out.

Is this possible? Is there a better way to get the desired result? I've tried a few different syntaxes, but all give the error "SyntaxError: multiple statements found while compiling a single statement". I am brand-new to Sage, so forgive me if this should be obvious. I've browsed the documentation but didn't see a clear answer one way or the other.

It unclear what is your actual question. Please elaborate. As a side note, you don't need

`elif E < 0:`

in your code, a simple`else:`

will be enough.Is it possible to define a variable

`D`

equal to [the variable`A`

] if [the variable`E`

is positive] and equal to [`A + E`

] if [the variable`E`

is negative], and have Sage simplify an expression containing those three variables first with the assumption that`E`

is positive and then with the assumption that`E`

is negative?What is the type of value of

`E`

? An example would really be helpful.As I said in the first sentence of my question,

`E`

is a real-valued number. It may be positive, zero, or negative. Its exact value, and that of`A`

, is determined outside the scope of the expressions I'm working with. The only other constraint is that`0 <= A + E`

.