How to represent this with math notatation

  • Context: Undergrad 
  • Thread starter Thread starter moni94
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around representing a pseudocode algorithm mathematically, specifically in the context of a sequence defined by a loop that modifies a variable based on a multiplier. Participants explore various mathematical representations and clarify the intended behavior of the pseudocode.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant presents pseudocode and asks how to express it mathematically, suggesting a summation approach.
  • Another participant critiques the pseudocode for not initializing the variable n and proposes that it might compute a^{k-1} instead.
  • Some participants clarify that n is arbitrary and that the pseudocode serves to illustrate a concept rather than being functional code.
  • A participant proposes a sequence definition, {ni}, where ni+1 = ni + ni * a, and introduces a condition for finding the first number ni that exceeds k.
  • There is a mention of a formula involving the floor function and logarithms, specifically \left\lfloor \frac k {n_0 \ln(1 + a)} \right\rfloor, as a potential representation.
  • Participants express curiosity about the application of the mathematical representation, revealing it relates to a game mechanic involving increasing prices.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the initial pseudocode's correctness or its intended purpose, with multiple interpretations and clarifications presented throughout the discussion.

Contextual Notes

Some assumptions about the initial values of n and k are not explicitly stated, and the mathematical steps leading to the proposed formulas are not fully resolved.

Who May Find This Useful

This discussion may be useful for individuals interested in mathematical modeling, algorithm representation, or those exploring game mechanics involving exponential growth in pricing.

moni94
Messages
8
Reaction score
0
Hi. I have the following pseudocode:

while(n < k)
n = n*a

How do I represent this with mathematical notation (e.g with summation)?
 
Mathematics news on Phys.org
That's not good code. It didn't initialize n.
Maybe it was intended to compute [tex]a^{k-1}[/tex]
 
n is arbitrary. We're not writing a program here, I was just using pseudocode to demonstrate the concept.

Oh, and the code is supposed to be:

while(n < k)
n = n + n*a
 
Last edited:
kaloyan5 said:
n is arbitrary. We're not writing a program here, I was just using pseudocode to demonstrate the concept.

Well, if the arbitrary n starts out greater than the arbitrary k, that would be a simple concept.
 
Ok n < k.
 
Let {ni} be the sequence given by ni+1=ni + ni * a.
Let N be the first number ni such that ni-1 ≤ k and ni > k.

Or:

[tex]\left\lfloor \frac k {n_0 \ln(1 + a)} \right\rfloor[/tex]
 
I like Serena said:
Let {ni} be the sequence given by ni+1=ni + ni * a.
Let N be the first number ni such that ni-1 ≤ k and ni > k.

Or:

[tex]\left\lfloor \frac k {n_0 \ln(1 + a)} \right\rfloor[/tex]

Thanks, that's what I needed!
 
moni94 said:
Thanks, that's what I needed!

Just out of curiosity - what did you need it for?
 
Well there's this game where you can spend your money on buildings and each time you buy one the price of that building goes up by 10%. So I wanted to know how you can calculate the total price of the buildings you can buy with a certain amount of money.
 
  • #10
moni94 said:
Well there's this game where you can spend your money on buildings and each time you buy one the price of that building goes up by 10%. So I wanted to know how you can calculate the total price of the buildings you can buy with a certain amount of money.

Ah, so you mostly needed the final formula?
Please note, that this is the total price of the buildings which is one more than you can buy :wink:.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K