Coming from a software engineering background, I am quite used to using conditional statements in my everyday mathematics. I know there are some higher math symbols to represent conditional statements, but what I'm looking for is a way to define the basic "if" in a problem.

The example inspiring this question is 'defining the cost-per-watt of a solar battery'. The solar battery, at 3.333...kWh, is priced at \$2,727.80. The larger model, at 10.0kWh, is priced at \$6,029.59. Therefore, the cost-per-watt changes depending on the batteries used (for now we can ignore the hours)

If we are using one small battery, our cost-per-watt is approximately \$0.82. Using 2, it would be the same. When using 3, however, we would instead use the larger battery, and the cost-per-watt would be reduced to approximately \$0.60.

Is there a way to make a single formula to algebraically determine cost-per-watt for 2 possible scenarios, or would something like this absolutely require the use of arrow notation or the word "if"?

Note: I've looked online for an answer to this question and all I can find is what a conditional statement is; very not helpful for someone like myself.

Note 2: Alternatively, I would be open to seeing an example of a functional conditional statement, where it effectively functions as one without necessarily being one.

  • $\begingroup$ So, you want a single formula which simultaneously produces multiple output values for each input? $\endgroup$ Apr 30, 2022 at 21:14

1 Answer 1


So here is a way of thinking about this.

Suppose I have a requirement $R$ which I need to supply using $L$ large batteries and $S$ small ones.

First I know that I will use large batteries where I can so the integer part (or "floor") of $\frac R{10}$. I will also use large batteries if I must - I will never use three small ones - so the transition from small to large happens when the "left over" part gets higher than $6.66 \dots$

I do this by $$L=\lfloor\frac {R+\frac {10}3}{10}\rfloor=\lfloor\frac {3R+10}{30}\rfloor$$ which nudges the count at the right place, and the brackets indicate the floor function.

Then I supply the remainder of the capacity $R-10L$ with enough (zero, one or two) small batteries by dividing by $\frac {10}3$ (the capacity of the battery) or equivalently multiplying by $\frac 3{10}$. Here I want to round up, and use the ceiling function. This comes out as $$S=\lceil\frac 3{10}\cdot(R-10L)\rceil=\lceil\frac {3R-30L}{10}\rceil$$

You can check that if the large batteries give surplus capacity, $S$ comes out as zero.

Once you know the number of batteries of each kind, the cost is easy to compute.

  • $\begingroup$ I've upvoted this reply, but I have no reputation yet, having just joined this particular community. This is what I thought would get me the closest, and was pleasantly surprised to see some verification here. I'll leave the question open for a little bit before marking as answered to encourage others to give additional input. $\endgroup$
    – Blue Dev
    Apr 30, 2022 at 21:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .