Skip to main content
Commonmark migration
Source Link

#Know your variable assignment costs

Know your variable assignment costs

If you use a B-byte expression N times, should you assign it to a variable?

Ans costs 1+N bytes to use (one for the linebreak and one for each time it's used, so use Ans when (B-1)*(N-1)>2. There can be only one Ans per line, so try all values for Ans that might be useful.

Real variables (e.g. X) cost 3+N bytes, so use them when (B-1)*(N-1)>4.

List variables cost 3+2N bytes, so use them when (B-2)*(N-1)>5.

Equation variables are the least useful: they need 4+2N bytes. Use them when (B-2)*(N-1)>6.

Min. bytes in an expression to save N \ var. | Ans | Real | List | Eqn ------------------------------------ 2 4 5 8 9 3 3 4 5 6 4 2 3 4 5 

When a function evaluates to a list, store it to a list rather than an equation variable like u; this saves one byte.

Keep in mind that the presence or absence of close parentheses can often cause storing expressions to be advantageous if they're rearranged.

Now I'll contradict myself and say that one should write code on one line as much as possible. Why? Usually when there's a long repeated expression on a line, it can be simplified.

#Know your variable assignment costs

If you use a B-byte expression N times, should you assign it to a variable?

Ans costs 1+N bytes to use (one for the linebreak and one for each time it's used, so use Ans when (B-1)*(N-1)>2. There can be only one Ans per line, so try all values for Ans that might be useful.

Real variables (e.g. X) cost 3+N bytes, so use them when (B-1)*(N-1)>4.

List variables cost 3+2N bytes, so use them when (B-2)*(N-1)>5.

Equation variables are the least useful: they need 4+2N bytes. Use them when (B-2)*(N-1)>6.

Min. bytes in an expression to save N \ var. | Ans | Real | List | Eqn ------------------------------------ 2 4 5 8 9 3 3 4 5 6 4 2 3 4 5 

When a function evaluates to a list, store it to a list rather than an equation variable like u; this saves one byte.

Keep in mind that the presence or absence of close parentheses can often cause storing expressions to be advantageous if they're rearranged.

Now I'll contradict myself and say that one should write code on one line as much as possible. Why? Usually when there's a long repeated expression on a line, it can be simplified.

Know your variable assignment costs

If you use a B-byte expression N times, should you assign it to a variable?

Ans costs 1+N bytes to use (one for the linebreak and one for each time it's used, so use Ans when (B-1)*(N-1)>2. There can be only one Ans per line, so try all values for Ans that might be useful.

Real variables (e.g. X) cost 3+N bytes, so use them when (B-1)*(N-1)>4.

List variables cost 3+2N bytes, so use them when (B-2)*(N-1)>5.

Equation variables are the least useful: they need 4+2N bytes. Use them when (B-2)*(N-1)>6.

Min. bytes in an expression to save N \ var. | Ans | Real | List | Eqn ------------------------------------ 2 4 5 8 9 3 3 4 5 6 4 2 3 4 5 

When a function evaluates to a list, store it to a list rather than an equation variable like u; this saves one byte.

Keep in mind that the presence or absence of close parentheses can often cause storing expressions to be advantageous if they're rearranged.

Now I'll contradict myself and say that one should write code on one line as much as possible. Why? Usually when there's a long repeated expression on a line, it can be simplified.

Source Link
lirtosiast
  • 21.7k
  • 5
  • 53
  • 127

#Know your variable assignment costs

If you use a B-byte expression N times, should you assign it to a variable?

Ans costs 1+N bytes to use (one for the linebreak and one for each time it's used, so use Ans when (B-1)*(N-1)>2. There can be only one Ans per line, so try all values for Ans that might be useful.

Real variables (e.g. X) cost 3+N bytes, so use them when (B-1)*(N-1)>4.

List variables cost 3+2N bytes, so use them when (B-2)*(N-1)>5.

Equation variables are the least useful: they need 4+2N bytes. Use them when (B-2)*(N-1)>6.

Min. bytes in an expression to save N \ var. | Ans | Real | List | Eqn ------------------------------------ 2 4 5 8 9 3 3 4 5 6 4 2 3 4 5 

When a function evaluates to a list, store it to a list rather than an equation variable like u; this saves one byte.

Keep in mind that the presence or absence of close parentheses can often cause storing expressions to be advantageous if they're rearranged.

Now I'll contradict myself and say that one should write code on one line as much as possible. Why? Usually when there's a long repeated expression on a line, it can be simplified.